feat(ai-feature): AI ①面入口页 + api/ai.ts(auto-develop,恒 READY_FOR_HUMAN_REVIEW 人审)
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
33
src/api/ai.test.ts
Normal file
33
src/api/ai.test.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { extractPageSchemaTemplateId } from './ai';
|
||||
import type { AiAutoDevelopRun } from './ai';
|
||||
|
||||
describe('extractPageSchemaTemplateId', () => {
|
||||
it('从 PAGE_SCHEMA draft 取 targetId', () => {
|
||||
const run: AiAutoDevelopRun = {
|
||||
taskId: 't1',
|
||||
status: 'READY_FOR_HUMAN_REVIEW',
|
||||
development: {
|
||||
drafts: [
|
||||
{ artifactType: 'FLOW', targetId: 'OA_X_ADD' },
|
||||
{ artifactType: 'PAGE_SCHEMA', targetId: 'TPL-AI-9' },
|
||||
],
|
||||
},
|
||||
};
|
||||
expect(extractPageSchemaTemplateId(run)).toBe('TPL-AI-9');
|
||||
});
|
||||
|
||||
it('无 PAGE_SCHEMA draft 时返回 undefined', () => {
|
||||
const run: AiAutoDevelopRun = {
|
||||
taskId: 't2',
|
||||
status: 'READY_FOR_HUMAN_REVIEW',
|
||||
development: { drafts: [{ artifactType: 'FLOW', targetId: 'X' }] },
|
||||
};
|
||||
expect(extractPageSchemaTemplateId(run)).toBeUndefined();
|
||||
});
|
||||
|
||||
it('development 缺失时安全返回 undefined', () => {
|
||||
const run: AiAutoDevelopRun = { taskId: 't3', status: 'FAILED' };
|
||||
expect(extractPageSchemaTemplateId(run)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
67
src/api/ai.ts
Normal file
67
src/api/ai.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
// AI ①面加速器入口 —— POST /api/ai/features/auto-develop(admin)。
|
||||
// 平台进程内不内置生成 LLM:实际起草由外部 agent + Skills 完成,本接口只是确定性编排+人审门禁。
|
||||
// 终端良态 status === 'READY_FOR_HUMAN_REVIEW'(红线:永不自动发布)。
|
||||
//
|
||||
// ⚠️ 端口约束:后端 auto-develop 会以 baseUrl 回调写后端。dev 默认 8084 已死,
|
||||
// 本前端透传 baseUrl = window.location.origin(经 vite 代理 /api → 8093)。
|
||||
// 若省略 baseUrl,则要求后端 dev profile 自身的 baseUrl 指向 8093(根因修在后端 Section)。
|
||||
import { http } from './http';
|
||||
|
||||
export interface AiFeatureField {
|
||||
column: string;
|
||||
label: string;
|
||||
type: string;
|
||||
length?: number;
|
||||
required?: boolean;
|
||||
}
|
||||
|
||||
export interface AiAutoDevelopBody {
|
||||
feature: {
|
||||
objective: string;
|
||||
featureName: string;
|
||||
tableName: string;
|
||||
entityName: string;
|
||||
templateId?: string;
|
||||
menuName?: string;
|
||||
fields: AiFeatureField[];
|
||||
pageRecipe: 'maintenance-crud-v1' | 'tree-crud-v1';
|
||||
};
|
||||
baseUrl?: string;
|
||||
generateDeploymentPackage?: boolean;
|
||||
maxRepairAttempts?: number;
|
||||
}
|
||||
|
||||
export interface AiDraft {
|
||||
artifactType: string; // 'PAGE_SCHEMA' | 'FLOW' | ...
|
||||
targetId: string;
|
||||
payload?: unknown;
|
||||
}
|
||||
|
||||
export interface AiAutoDevelopRun {
|
||||
taskId: string;
|
||||
status: string; // 'READY_FOR_HUMAN_REVIEW' = 终端良态
|
||||
development?: { drafts?: AiDraft[] };
|
||||
applyRun?: unknown;
|
||||
deploymentPackage?: unknown;
|
||||
messages?: string[];
|
||||
}
|
||||
|
||||
/** 终端良态判定(红线:AI 入口产物恒此状态才可人审进设计器)。 */
|
||||
export const READY_STATUS = 'READY_FOR_HUMAN_REVIEW';
|
||||
|
||||
/** 从 run 提取 PAGE_SCHEMA draft 的 targetId(即写入 standard 层的 templateId)。 */
|
||||
export function extractPageSchemaTemplateId(run: AiAutoDevelopRun): string | undefined {
|
||||
return run.development?.drafts?.find((d) => d.artifactType === 'PAGE_SCHEMA')?.targetId;
|
||||
}
|
||||
|
||||
export async function autoDevelop(body: AiAutoDevelopBody): Promise<AiAutoDevelopRun> {
|
||||
// §B.9-10:默认值放后、用 ?? 兜底,避免显式传入的 undefined 覆盖默认;
|
||||
// 透传 baseUrl=当前前端 origin,让后端回调经 vite 代理打到正在跑的 8093(而非死的 8084)。
|
||||
const payload: AiAutoDevelopBody = {
|
||||
...body,
|
||||
baseUrl: body.baseUrl ?? window.location.origin,
|
||||
generateDeploymentPackage: body.generateDeploymentPackage ?? true,
|
||||
};
|
||||
const { data } = await http.post<AiAutoDevelopRun>('/api/ai/features/auto-develop', payload);
|
||||
return data;
|
||||
}
|
||||
Reference in New Issue
Block a user