feat(平台): 补齐服务端持久化和AI拆解契约
This commit is contained in:
167
packages/shared/src/agent.ts
Normal file
167
packages/shared/src/agent.ts
Normal file
@@ -0,0 +1,167 @@
|
||||
export type AgentRole = 'frontend' | 'backend' | 'ui' | 'testing';
|
||||
|
||||
export type AgentTaskCategoryCode =
|
||||
| 'frontend_development'
|
||||
| 'frontend_interaction'
|
||||
| 'backend_development'
|
||||
| 'backend_api'
|
||||
| 'database_schema'
|
||||
| 'api_integration'
|
||||
| 'test_functional'
|
||||
| 'test_api'
|
||||
| 'test_exception'
|
||||
| 'test_compatibility'
|
||||
| 'data_processing'
|
||||
| 'implementation_support'
|
||||
| 'documentation';
|
||||
|
||||
export type AgentReferenceType = 'requirement' | 'prototype_note';
|
||||
|
||||
export interface AgentReference {
|
||||
type: AgentReferenceType;
|
||||
id: string;
|
||||
label: string;
|
||||
}
|
||||
|
||||
export interface AgentDevTaskDraft {
|
||||
title: string;
|
||||
description?: string;
|
||||
categoryCode: AgentTaskCategoryCode;
|
||||
priority: 'P0' | 'P1' | 'P2' | 'P3';
|
||||
estimateHours: number;
|
||||
references: AgentReference[];
|
||||
}
|
||||
|
||||
export interface AgentTestCaseDraft {
|
||||
title: string;
|
||||
description: string;
|
||||
categoryCode: AgentTaskCategoryCode;
|
||||
priority: 'P0' | 'P1' | 'P2' | 'P3';
|
||||
estimateHours: number;
|
||||
references: AgentReference[];
|
||||
}
|
||||
|
||||
export interface AgentDecomposeReport {
|
||||
matched: Array<{ reqId: string; noteIds: string[]; taskCount: number }>;
|
||||
reqOnly: string[];
|
||||
noteOnly: string[];
|
||||
ambiguous: Array<{ noteId: string; reason: string }>;
|
||||
}
|
||||
|
||||
export interface AgentDecomposeResult {
|
||||
report: AgentDecomposeReport;
|
||||
devTaskDrafts: AgentDevTaskDraft[];
|
||||
testCaseDrafts: AgentTestCaseDraft[];
|
||||
}
|
||||
|
||||
export interface AgentDecomposeRequirement {
|
||||
id: string;
|
||||
code: string;
|
||||
title: string;
|
||||
description?: string;
|
||||
}
|
||||
|
||||
export interface AgentDecomposeMember {
|
||||
name: string;
|
||||
role: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 前端发往后端的请求体
|
||||
*/
|
||||
export interface AgentDecomposeRequest {
|
||||
prototypeUrl: string;
|
||||
requirements: AgentDecomposeRequirement[];
|
||||
members: AgentDecomposeMember[];
|
||||
versionId: string;
|
||||
planId: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端响应体(成功)
|
||||
*/
|
||||
export interface AgentDecomposeResponse {
|
||||
ok: true;
|
||||
result: AgentDecomposeResult;
|
||||
meta: {
|
||||
model: string;
|
||||
inputTokens: number;
|
||||
outputTokens: number;
|
||||
durationMs: number;
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* 后端响应体(失败)
|
||||
*/
|
||||
export interface AgentDecomposeError {
|
||||
ok: false;
|
||||
error: string;
|
||||
code: 'PROTOTYPE_FETCH_FAILED' | 'EMPTY_REQUIREMENTS' | 'API_ERROR' | 'PARSE_ERROR' | 'NO_PROVIDER' | 'UNKNOWN';
|
||||
}
|
||||
|
||||
/* ───────────────────────── AI Provider 配置 ─────────────────────────── */
|
||||
|
||||
export type AiProviderFormat = 'anthropic' | 'openai';
|
||||
|
||||
/**
|
||||
* 单个提供商配置(写入侧,含完整 apiKey)
|
||||
*/
|
||||
export interface AiProviderConfig {
|
||||
id: string; // 用户给的唯一 id(如 'anthropic-official' / 'ikuncode')
|
||||
name: string; // 显示名("Anthropic 官方" / "ikuncode")
|
||||
format: AiProviderFormat;
|
||||
baseURL: string; // 'https://api.anthropic.com' 或中转站 URL
|
||||
apiKey: string; // 完整 Key(仅服务端持有)
|
||||
model: string; // 该提供商上使用的模型 ID
|
||||
remark?: string;
|
||||
createdAt: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 提供商公开视图(前端只能拿到这个,apiKey 已脱敏)
|
||||
*/
|
||||
export interface AiProviderPublic {
|
||||
id: string;
|
||||
name: string;
|
||||
format: AiProviderFormat;
|
||||
baseURL: string;
|
||||
keyMask: string; // 脱敏后的 key(如 sk-ant...xxxx)
|
||||
model: string;
|
||||
remark?: string;
|
||||
createdAt: string;
|
||||
isActive: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 配置整体(写入侧)
|
||||
*/
|
||||
export interface AiConfigStored {
|
||||
providers: AiProviderConfig[];
|
||||
activeProviderId?: string;
|
||||
updatedAt?: string;
|
||||
updatedBy?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* AI 配置公开视图(前端用)
|
||||
*/
|
||||
export interface AiConfigPublic {
|
||||
providers: AiProviderPublic[];
|
||||
activeProviderId?: string;
|
||||
updatedAt?: string;
|
||||
updatedBy?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建 / 更新 提供商 入参
|
||||
*/
|
||||
export interface AiProviderUpsertInput {
|
||||
id: string;
|
||||
name: string;
|
||||
format: AiProviderFormat;
|
||||
baseURL: string;
|
||||
apiKey?: string; // 编辑时若不传则保留原 key
|
||||
model: string;
|
||||
remark?: string;
|
||||
}
|
||||
@@ -1,2 +1,3 @@
|
||||
export * from './enums';
|
||||
export * from './types';
|
||||
export * from './agent';
|
||||
|
||||
Reference in New Issue
Block a user