From 4abf13d33d156f908053dbda11db2c0d7c30520a Mon Sep 17 00:00:00 2001 From: weichen Date: Wed, 30 Sep 2026 10:35:13 +0000 Subject: [PATCH] Mirror the prompt module contract and add the library API Why: the backend prompt library ships new contract shapes and an endpoint; the frontend mirror and api binding keep the TS side in sync for upcoming management UI. Evidence: tsc + vite build green as part of composite make test. Impact: contracts.ts gains PromptModule/Trigger and AgentProfile.promptModules; api gains listPromptModules. No UI change yet. Refs: feature/prompt-library task card. --- src/api.ts | 3 ++- src/contracts.ts | 21 +++++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/api.ts b/src/api.ts index f423d10..a1c3189 100644 --- a/src/api.ts +++ b/src/api.ts @@ -3,7 +3,7 @@ import { auth } from './auth' import type { Project, Conversation, Message, Run, Artifact, HITLCard, HITLResponse, - AgentProfile, SettingDesc, StreamEvent, PlanSnapshot, TodoList, UploadInfo, + AgentProfile, SettingDesc, StreamEvent, PlanSnapshot, TodoList, UploadInfo, PromptModule, ActivityCard, } from './contracts' @@ -67,6 +67,7 @@ export const api = { getTodos: (convId: string) => auth.fetch(`${BASE}/api/conversations/${convId}/todos`).then(r => r.ok ? r.json() : null) as Promise, listProfiles: () => auth.fetch(`${BASE}/api/profiles`).then(r => json(r)), + listPromptModules: () => auth.fetch(`${BASE}/api/prompts`).then(r => json(r)), saveProfile: (p: AgentProfile) => auth.fetch(`${BASE}/api/profiles`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(p) }).then(r => { if (!r.ok) throw new Error(r.statusText); return r.json() }), deleteProfile: (id: string) => auth.fetch(`${BASE}/api/profiles/${id}`, { method: 'DELETE' }), diff --git a/src/contracts.ts b/src/contracts.ts index 7a04dcd..fe3a488 100644 --- a/src/contracts.ts +++ b/src/contracts.ts @@ -192,11 +192,32 @@ export interface UIField { options?: string[]; required?: boolean; placeholder?: string; help?: string; default?: string; } +// ---- 提示词库(prompt-library)---- + +export interface PromptTrigger { + kind: 'intent' | 'command' | 'attachment' | 'manual'; + keywords?: string[]; command?: string; +} + +export interface PromptModule { + id: string; layer: 'base' | 'env' | 'task' | 'agent' | 'tool' | 'aux' | 'style'; + version: number; title: string; description?: string; priority?: number; + triggers?: PromptTrigger[]; requiresAttachments?: boolean; + body: string; outputContract?: string; + source?: 'builtin' | 'plugin' | 'user'; owner?: string; + basedOnVersion?: number; drifted?: boolean; disabled?: boolean; +} + +export interface PromptBlock { moduleId: string; version: number; layer: string; body: string; } +export interface PromptHitRecord { moduleId: string; layer: string; reason: string; injected: boolean; } + // ---- 画像 / 设置 ---- export interface AgentProfile { id: string; owner?: string; name: string; description?: string; builtin?: boolean; source?: string; systemPrompt: string; + /** 提示词库模块引用(有序;空 = 默认 base+env 全集)。 */ + promptModules?: string[]; model: { chat?: string; lightweight?: string; embedding?: string; rerank?: string }; tools: { allow: string[]; deny?: string[]; confirm?: string[] }; context: { -- 2.54.0