feat(ai): implement unified prompt management UX/UI (ADR-037)
- Add context config endpoints (GET/PUT /api/ai/prompts/:type/:version/context-config) - Add execution profile endpoints (CRUD /api/ai/execution-profiles) - Add sandbox RAG Prep endpoint (POST /api/ai/admin/sandbox/rag-prep) - Create Prompt Management UI with multi-type support - Add ContextConfigEditor, PromptEditor, RuntimeParametersPanel components - Add SandboxTabs for 3-step workflow (OCR, Extract, RAG Prep) - Add database deltas for ai_execution_profiles and additional prompt types - Update quickstart.md with production backend URLs - Add comprehensive test coverage for new features
This commit is contained in:
@@ -64,7 +64,7 @@ describe('rfaService', () => {
|
||||
it('ควรส่ง RFA เข้า workflow', async () => {
|
||||
const mockResponse = { data: { publicId: 'uuid-1', status: 'SUBMITTED' } };
|
||||
vi.mocked(apiClient.post).mockResolvedValue(mockResponse);
|
||||
const submitDto = { templateId: 1, reviewTeamPublicId: 'uuid-team' };
|
||||
const submitDto = { reviewTeamPublicId: 'uuid-team' };
|
||||
const result = await rfaService.submit('uuid-1', submitDto);
|
||||
expect(apiClient.post).toHaveBeenCalledWith('/rfas/uuid-1/submit', submitDto);
|
||||
expect(result).toEqual(mockResponse.data);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
// File: lib/services/admin-ai.service.ts
|
||||
// Change Log
|
||||
// - 2026-06-14: เพิ่ม methods สำหรับจัดการ Prompt Versions และ RAG Prep Sandbox (T020, T030, T039)
|
||||
// - 2026-05-21: เพิ่ม service สำหรับ AI Admin Console toggle API.
|
||||
// - 2026-05-21: เพิ่ม service method `getHealth` สำหรับดึงข้อมูลสุขภาพของระบบ AI (T028).
|
||||
// - 2026-05-21: เพิ่ม API service สำหรับ Superadmin Sandbox RAG (T037).
|
||||
@@ -20,6 +21,7 @@
|
||||
|
||||
import api from '../api/client';
|
||||
import { AiJobResponse } from '../../types/ai';
|
||||
import { PromptType, PromptVersion, ContextConfig } from '../types/ai-prompts';
|
||||
|
||||
export interface AiAdminSettings {
|
||||
aiFeaturesEnabled: boolean;
|
||||
@@ -403,6 +405,59 @@ export const adminAiService = {
|
||||
});
|
||||
return extractData<AiJobResponse>(data);
|
||||
},
|
||||
|
||||
listPrompts: async (type: PromptType): Promise<PromptVersion[]> => {
|
||||
const { data } = await api.get(`/ai/prompts/${type}`);
|
||||
return extractData<PromptVersion[]>(data);
|
||||
},
|
||||
|
||||
createPrompt: async (
|
||||
type: PromptType,
|
||||
updates: { template: string; contextConfig?: ContextConfig | null; manualNote?: string }
|
||||
): Promise<PromptVersion> => {
|
||||
const { data } = await api.post(`/ai/prompts/${type}`, updates);
|
||||
return extractData<PromptVersion>(data);
|
||||
},
|
||||
|
||||
deletePrompt: async (type: PromptType, versionNumber: number): Promise<void> => {
|
||||
await api.delete(`/ai/prompts/${type}/${versionNumber}`);
|
||||
},
|
||||
|
||||
activatePrompt: async (type: PromptType, versionNumber: number): Promise<PromptVersion> => {
|
||||
const { data } = await api.post(`/ai/prompts/${type}/${versionNumber}/activate`);
|
||||
return extractData<PromptVersion>(data);
|
||||
},
|
||||
|
||||
updatePromptNote: async (
|
||||
type: PromptType,
|
||||
versionNumber: number,
|
||||
manualNote: string
|
||||
): Promise<PromptVersion> => {
|
||||
const { data } = await api.patch(`/ai/prompts/${type}/${versionNumber}/note`, { manualNote });
|
||||
return extractData<PromptVersion>(data);
|
||||
},
|
||||
|
||||
getContextConfig: async (type: PromptType, versionNumber: number): Promise<ContextConfig> => {
|
||||
const { data } = await api.get(`/ai/prompts/${type}/${versionNumber}/context-config`);
|
||||
return extractData<ContextConfig>(data);
|
||||
},
|
||||
|
||||
updateContextConfig: async (
|
||||
type: PromptType,
|
||||
versionNumber: number,
|
||||
contextConfig: ContextConfig
|
||||
): Promise<ContextConfig> => {
|
||||
const { data } = await api.put(`/ai/prompts/${type}/${versionNumber}/context-config`, contextConfig);
|
||||
return extractData<ContextConfig>(data);
|
||||
},
|
||||
|
||||
submitSandboxRagPrep: async (
|
||||
text: string,
|
||||
profileId?: string | null
|
||||
): Promise<{ jobId: string; status: string }> => {
|
||||
const { data } = await api.post('/ai/admin/sandbox/rag-prep', { text, profileId });
|
||||
return extractData<{ jobId: string; status: string }>(data);
|
||||
},
|
||||
};
|
||||
|
||||
export interface OcrEngineResponse {
|
||||
|
||||
@@ -10,7 +10,6 @@ export interface WorkflowActionDto {
|
||||
}
|
||||
|
||||
export interface SubmitRfaDto {
|
||||
templateId: number;
|
||||
reviewTeamPublicId?: string;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
// File: frontend/lib/types/ai-prompts.ts
|
||||
// Change Log:
|
||||
// - 2026-06-14: Created frontend types for AI prompt management (conforming to task T010)
|
||||
|
||||
export type PromptType = 'ocr_extraction' | 'rag_query_prompt' | 'rag_prep_prompt' | 'classification_prompt';
|
||||
|
||||
export interface ContextConfig {
|
||||
filter: {
|
||||
projectId: string | null;
|
||||
contractId: string | null;
|
||||
} | null;
|
||||
pageSize: number;
|
||||
language: string;
|
||||
outputLanguage: string;
|
||||
}
|
||||
|
||||
export interface PromptVersion {
|
||||
publicId: string;
|
||||
promptType: PromptType;
|
||||
versionNumber: number;
|
||||
template: string;
|
||||
contextConfig: ContextConfig | null;
|
||||
isActive: boolean;
|
||||
manualNote: string | null;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
export interface RuntimeParameters {
|
||||
temperature: number;
|
||||
topP: number;
|
||||
repeatPenalty: number;
|
||||
maxTokens: number;
|
||||
ctxSize: number;
|
||||
keepAlive: number;
|
||||
}
|
||||
|
||||
export interface ExecutionProfile {
|
||||
publicId: string;
|
||||
profileName: string;
|
||||
canonicalModel: 'np-dms-ai' | 'np-dms-ocr';
|
||||
temperature: number;
|
||||
topP: number;
|
||||
repeatPenalty: number;
|
||||
maxTokens: number | null;
|
||||
ctxSize: number | null;
|
||||
keepAlive: number;
|
||||
isDefault?: boolean;
|
||||
}
|
||||
|
||||
export type SandboxJobType = 'ocr' | 'ai-extract' | 'rag-prep';
|
||||
|
||||
export type SandboxJobStatus = 'pending' | 'processing' | 'completed' | 'failed';
|
||||
|
||||
export interface SandboxJobResult {
|
||||
ocrText?: string;
|
||||
extractedMetadata?: Record<string, unknown>;
|
||||
ragChunks?: Array<{
|
||||
text: string;
|
||||
summary: string;
|
||||
}>;
|
||||
ragVectors?: number[][];
|
||||
error?: string | null;
|
||||
}
|
||||
|
||||
export interface SandboxJob {
|
||||
jobId: string;
|
||||
jobType: SandboxJobType;
|
||||
status: SandboxJobStatus;
|
||||
result: SandboxJobResult;
|
||||
createdAt: string;
|
||||
completedAt?: string;
|
||||
}
|
||||
Reference in New Issue
Block a user