From e341beb1cbccd61321279064bab01325bbc805de Mon Sep 17 00:00:00 2001 From: ThearchyHelios Date: Wed, 14 Oct 2026 20:05:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BA=94=E7=94=A8=E5=B9=B3=E5=8F=B0=20FE-6=20?= =?UTF-8?q?=E6=90=AD=E5=BB=BA=E9=9D=A2=EF=BC=9A=E5=BA=94=E7=94=A8=E7=BC=96?= =?UTF-8?q?=E8=BE=91=E5=99=A8=EF=BC=88=E5=9B=BA=E5=AE=9A=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E3=80=81=E6=B4=BE=E7=94=9F=E3=80=81=E9=A1=B5=E9=9D=A2=E6=A0=91?= =?UTF-8?q?=E4=B8=8E=E5=B1=9E=E6=80=A7=E9=9D=A2=E6=9D=BF=E3=80=81=E9=A2=84?= =?UTF-8?q?=E8=A7=88=E3=80=81=E6=A3=80=E6=9F=A5=E3=80=81=E5=8F=91=E5=B8=83?= =?UTF-8?q?=E6=97=B6=E9=80=89=E5=A4=84=E7=BD=AE=E3=80=81=E5=B2=97=E4=BD=8D?= =?UTF-8?q?=E4=B8=8E=E6=8E=88=E6=9D=83=E3=80=81=E9=92=A9=E5=AD=90=E3=80=81?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=80=81=E5=8A=A9=E6=89=8B=E9=9D=A2=E6=9D=BF?= =?UTF-8?q?=EF=BC=89=EF=BC=8C=E4=BA=BA=E5=B7=A5=E8=8A=82=E7=82=B9=E6=96=B0?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E4=B8=8E=E5=86=99=E5=85=A5=E5=8A=A8=E4=BD=9C?= =?UTF-8?q?=E8=AF=B4=E6=98=8E=EF=BC=8C=E5=8F=91=E5=B8=83=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E4=B8=8E=E7=89=88=E6=9C=AC=E9=A1=B5=E7=9A=84=E9=80=80=E5=BD=B9?= =?UTF-8?q?=E5=92=8C=E4=BD=BF=E7=94=A8=E6=83=85=E5=86=B5=EF=BC=8C=E8=AE=B0?= =?UTF-8?q?=E5=BD=95=E9=A1=B5=E7=9A=84=E6=9D=A5=E6=BA=90=E3=80=81=E5=BE=85?= =?UTF-8?q?=E5=8A=9E=E4=B8=8E=E5=8A=A8=E4=BD=9C=E4=BA=8B=E4=BB=B6=E3=80=81?= =?UTF-8?q?=E7=94=9F=E6=95=88=E8=AE=B0=E5=BD=95=EF=BC=8C=E5=8F=91=E8=B5=B7?= =?UTF-8?q?=E8=A1=A8=E5=8D=95=E6=8D=A2=E6=88=90=E8=A1=A8=E5=8D=95=E6=B8=B2?= =?UTF-8?q?=E6=9F=93=E5=99=A8=E5=B9=B6=E5=B8=A6=E6=9D=A5=E6=BA=90=EF=BC=8C?= =?UTF-8?q?=E9=97=AE=E6=95=B0=E6=8D=AE=E3=80=8C=E5=81=9A=E6=88=90=E5=BA=94?= =?UTF-8?q?=E7=94=A8=E3=80=8D=EF=BC=8Clook=20=E7=9A=84=E7=95=8C=E9=9D=A2?= =?UTF-8?q?=E4=B8=8E=20meta.looks=EF=BC=8C=E5=B7=A5=E5=85=B7=E9=A1=B5?= =?UTF-8?q?=E7=9A=84=E8=83=BD=E5=8A=9B=E4=B8=8E=E7=AB=AF=E7=82=B9=EF=BC=8C?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E9=A1=B5=E7=9A=84=E8=BA=AB=E4=BB=BD=E3=80=81?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=80=81=E5=AE=A1=E8=AE=A1=EF=BC=9B=E6=A3=80?= =?UTF-8?q?=E6=9F=A5=E8=84=9A=E6=9C=AC=E7=9A=84=E6=9B=B4=E6=96=B0=E4=B8=8E?= =?UTF-8?q?=E6=96=B0=E5=A2=9E=EF=BC=88=E5=90=AB=E7=BB=9F=E4=B8=80=E5=A4=8D?= =?UTF-8?q?=E6=A0=B8=E5=90=8E=E7=9A=84=E4=BF=AE=E5=A4=8D=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/api/appCopilot.ts | 91 +++ frontend/src/api/client.ts | 13 +- frontend/src/canvas/Inspector.tsx | 49 +- frontend/src/canvas/PublishDialog.tsx | 43 +- frontend/src/canvas/VersionsSheet.tsx | 52 +- frontend/src/canvas/humanFields.tsx | 152 +++++ frontend/src/canvas/nodeDefs.ts | 5 + frontend/src/canvas/versionUsage.tsx | 95 +++ frontend/src/lib/terms.ts | 589 +++++++++++++++++- frontend/src/pages/ChatPage.tsx | 42 +- frontend/src/pages/RunsPage.tsx | 58 +- frontend/src/pages/SettingsPage.tsx | 14 +- frontend/src/pages/ToolsPage.tsx | 11 +- .../src/pages/apps/edit/AccessSections.tsx | 219 +++++++ frontend/src/pages/apps/edit/AppAssistant.tsx | 110 ++++ frontend/src/pages/apps/edit/AppEditor.tsx | 254 +++++++- frontend/src/pages/apps/edit/PagesSection.tsx | 439 +++++++++++++ frontend/src/pages/apps/edit/PinsSection.tsx | 187 ++++++ .../src/pages/apps/edit/ReviewSections.tsx | 277 ++++++++ frontend/src/pages/apps/edit/appOps.ts | 177 ++++++ frontend/src/pages/apps/edit/context.ts | 28 + frontend/src/pages/runs/RunDetailView.tsx | 56 +- frontend/src/pages/runs/RunList.tsx | 130 ++-- frontend/src/pages/runs/RunTasks.tsx | 122 ++++ frontend/src/pages/runs/model.ts | 8 +- frontend/src/pages/runs/useRunsData.ts | 46 ++ frontend/src/pages/settings/AuditTab.tsx | 61 ++ frontend/src/pages/settings/IdentityTab.tsx | 359 +++++++++++ frontend/src/pages/settings/NotifyTab.tsx | 217 +++++++ frontend/src/pages/tools/CapabilitiesTab.tsx | 318 ++++++++++ frontend/src/pages/tools/EndpointsTab.tsx | 266 ++++++++ frontend/src/run/RunControl.tsx | 119 ++-- frontend/src/run/RunPanel.tsx | 284 ++------- frontend/src/run/__tests__/synthetic.ts | 78 ++- frontend/src/run/decode.ts | 446 +++++++++---- frontend/src/run/inputSchema.ts | 69 ++ frontend/src/store/chat.ts | 25 +- frontend/src/store/studio.ts | 36 +- frontend/src/types.ts | 33 + scripts/check-all.mjs | 8 + scripts/check-app-editor.mjs | 292 +++++++++ scripts/check-capabilities.mjs | 210 +++++++ scripts/check-chat.mjs | 23 +- scripts/check-copy.mjs | 4 +- scripts/check-decode.mjs | 169 ++--- scripts/check-publish.mjs | 85 +++ scripts/check-runs.mjs | 108 +++- scripts/check-stream.mjs | 45 +- scripts/check-studio.mjs | 90 ++- 49 files changed, 5918 insertions(+), 694 deletions(-) create mode 100644 frontend/src/api/appCopilot.ts create mode 100644 frontend/src/canvas/humanFields.tsx create mode 100644 frontend/src/canvas/versionUsage.tsx create mode 100644 frontend/src/pages/apps/edit/AccessSections.tsx create mode 100644 frontend/src/pages/apps/edit/AppAssistant.tsx create mode 100644 frontend/src/pages/apps/edit/PagesSection.tsx create mode 100644 frontend/src/pages/apps/edit/PinsSection.tsx create mode 100644 frontend/src/pages/apps/edit/ReviewSections.tsx create mode 100644 frontend/src/pages/apps/edit/appOps.ts create mode 100644 frontend/src/pages/apps/edit/context.ts create mode 100644 frontend/src/pages/runs/RunTasks.tsx create mode 100644 frontend/src/pages/settings/AuditTab.tsx create mode 100644 frontend/src/pages/settings/IdentityTab.tsx create mode 100644 frontend/src/pages/settings/NotifyTab.tsx create mode 100644 frontend/src/pages/tools/CapabilitiesTab.tsx create mode 100644 frontend/src/pages/tools/EndpointsTab.tsx create mode 100644 frontend/src/run/inputSchema.ts create mode 100644 scripts/check-app-editor.mjs create mode 100644 scripts/check-capabilities.mjs diff --git a/frontend/src/api/appCopilot.ts b/frontend/src/api/appCopilot.ts new file mode 100644 index 00000000..096ec778 --- /dev/null +++ b/frontend/src/api/appCopilot.ts @@ -0,0 +1,91 @@ +/** + * 应用润色的助手(POST /api/copilot/app-stream,SSE):应用编辑器右侧的助手面板用它。 + * + * 和 streamCopilot(画布生成)同一种帧:一帧一行 `data: `,空行分隔。操作有三类(§3.11): + * - 应用操作:app_add / app_update / app_remove / app_move / app_page / app_set,形状同服务端 app/apps/ops.py, + * 编辑器按到达顺序落到草稿上(pages/apps/edit/appOps.ts 的 applyAppOp); + * - look(查看了哪些工作流版本、能力)、ask(问回来一句,这一轮到此结束)、thinking、heartbeat、check、reply、error; + * - final:{spec, issues, explanation},服务端落地后的整份 spec(以它为准,替换前面边收边改的草稿)。 + * + * 系统先代为查看固定的版本(look 的 by=system),模型可以再查看;岗位绑定只能由人做,助手只留空并提示。 + * 请求函数从 ./http 导入,不要从 ./client 导入(循环导入,见 http.ts 开头)。 + */ +import type { AppBindings, AppSpec } from '../typesApp' +import { ApiError, BASE, NETWORK_MESSAGE, actorHeader, codeOf, describeDetail, isGatewayFailure, parseBody, report } from './http' + +/** 请求体同服务端 api/copilot.AppStreamIn */ +export interface AppCopilotRequest { + app_id: string + instruction: string + /** 编辑器里此刻的草稿(可能还没保存):助手在它上面改 */ + spec: AppSpec + /** 草稿里的岗位绑定(不进 spec):服务端的应用检查按它判断岗位绑没绑 */ + bindings?: AppBindings + /** 应用编辑时的助手对话(conversations.app_id 归属这个应用),带上它这一轮才接得上前面聊过的 */ + conversation_id?: string | null + model?: string | null +} + +/** 返回取消函数。开流之前就被拒(4xx/5xx)时 onEnd 带服务端那句话、状态码和机读码 */ +export function streamAppCopilot( + body: AppCopilotRequest, + onOp: (op: any) => void, + onEnd: (error?: string, info?: { status?: number; code?: string }) => void, +): () => void { + const controller = new AbortController() + const path = '/copilot/app-stream' + void (async () => { + try { + const res = await fetch(`${BASE}${path}`, { + method: 'POST', + headers: { 'Content-Type': 'application/json', Accept: 'text/event-stream', ...actorHeader() }, + body: JSON.stringify(body), + signal: controller.signal, + }) + if (!res.ok || !res.body) { + const text = await res.text().catch(() => '') + let parsed: any + let isJson = false + try { parsed = JSON.parse(text); isJson = true } catch { /* 响应体不是 JSON */ } + if (isGatewayFailure(res.status, text, isJson)) { + report(false, new ApiError(res.status, NETWORK_MESSAGE, { kind: 'network' })) + onEnd(NETWORK_MESSAGE) + return + } + report(true) + onEnd(isJson ? describeDetail(parsed?.detail ?? parsed, path) + : res.status >= 500 ? `服务端错误(${res.status}),详情请查看服务日志` + : `请求失败(HTTP ${res.status})`, { status: res.status, code: isJson ? codeOf(parsed) : undefined }) + return + } + report(true) + const reader = res.body.getReader() + const decoder = new TextDecoder() + let buffer = '' + for (;;) { + const { done, value } = await reader.read() + if (done) break + buffer += decoder.decode(value, { stream: true }) + let idx: number + while ((idx = buffer.indexOf('\n\n')) >= 0) { + const frame = buffer.slice(0, idx) + buffer = buffer.slice(idx + 2) + if (!frame.startsWith('data: ')) continue + try { + onOp(parseBody(frame.slice(6))) + } catch { /* 半截帧,忽略 */ } + } + } + onEnd() + } catch (e: any) { + if (e?.name === 'AbortError') { onEnd(); return } + if (e instanceof TypeError) { + report(false, new ApiError(0, NETWORK_MESSAGE, { kind: 'network', raw: String(e) })) + onEnd(NETWORK_MESSAGE) + return + } + onEnd(e?.message ?? '连接中断,请重试') + } + })() + return () => controller.abort() +} diff --git a/frontend/src/api/client.ts b/frontend/src/api/client.ts index 3e40b162..1db565fd 100644 --- a/frontend/src/api/client.ts +++ b/frontend/src/api/client.ts @@ -232,6 +232,10 @@ export const api = { /** 某个版本的完整快照(含 graph)。正式运行的输入字段要从已发布版本取,不能取画布 */ version: (id: string, v: number) => get(`/workflows/${id}/versions/${v}`), restore: (id: string, v: number) => post(`/workflows/${id}/versions/${v}/restore`), + /** 退役一个已发布的版本(A1):当前发布版 409;返回受影响的应用。只有管理员(关登录时所有人) */ + retire: (id: string, v: number, note?: string) => + post<{ retired: boolean; affected_apps: { app_id: string; name: string; app_version: number }[] }>( + `/workflows/${id}/versions/${v}/retire`, { note: note ?? null }), publish: (id: string, level: 'published' | 'governed', version?: number) => post<{ ok: boolean; level?: string; version?: number; issues: any[] }>( `/workflows/${id}/publish`, { level, version }), @@ -513,6 +517,8 @@ export const api = { list: (params?: { workflow_id?: string; status?: RunStatus | RunStatus[] | string; run_class?: 'formal' | 'exploratory' q?: string; limit?: number; before?: string + /** 按运行来源筛(X3);none 是来源未记录的老运行 */ + origin_kind?: string }) => get(`/runs${qs(params)}`), get: (id: string) => get(`/runs/${id}`), /** 这次运行实际跑的那张图(运行时的快照),不是工作流现在的样子 */ @@ -522,6 +528,8 @@ export const api = { workflow_id?: string; graph?: GraphSpec; input?: Record memory_scope?: string; collection?: string run_class?: 'formal' | 'exploratory'; version?: number + /** 运行来源(X3):客户端只能声明 chat、canvas、launcher、api(不传按 api 记),其余由服务端写 */ + origin?: 'chat' | 'canvas' | 'launcher' | 'api' }) => post('/runs', body), artifacts: (id: string) => get(`/runs/${id}/artifacts`), /** 从失败的节点接着跑。graph 只能带改过配置的同一张图,结构必须一致 */ @@ -813,8 +821,9 @@ export const api = { }>('/copilot/generate', body), explain: (graph: GraphSpec) => post<{ explanation: string }>('/copilot/explain', { graph }), layout: (graph: GraphSpec) => post('/copilot/layout', { graph }), - fromRun: (runId: string, name?: string) => - post('/copilot/from-run', { run_id: runId, name }), + /** from:问数据回答上点「做成应用」时带上这次运行出自哪段对话的哪一轮,记进新工作流的来源 */ + fromRun: (runId: string, name?: string, from?: { conversation_id?: string | null; turn_id?: string | null }) => + post('/copilot/from-run', { run_id: runId, name, ...(from ?? {}) }), getModel: () => get('/copilot/model'), setModel: (body: { provider?: string | null; model?: string | null }) => put('/copilot/model', body), diff --git a/frontend/src/canvas/Inspector.tsx b/frontend/src/canvas/Inspector.tsx index ca9ace96..aed3b0d4 100644 --- a/frontend/src/canvas/Inspector.tsx +++ b/frontend/src/canvas/Inspector.tsx @@ -12,7 +12,7 @@ import { datasourceTools, modelOptions, providerOfModel, useCatalog, useDatasour import { api } from '../api/client' import { IconButton, JsonInput, Modal, isComposing, useRadioGroup } from '../components/ui' import { formatShortcut } from '../lib/keys' -import { JUDGE_FIELD_LABEL, JUDGE_ON_UNSUPPORTED_HINT, JUDGE_ON_UNSUPPORTED_LABEL, JUDGE_SETTING_TEXT, MERGE_TEXT, CATALOG_UI_TEXT, NODE_TYPE_LABEL, PROVIDER_REF_TEXT, SUBGRAPH_UPGRADE_HELP, judgeByModelText, upgradeNewerText } from '../lib/terms' +import { INPUT_FIELD_TEXT, JUDGE_FIELD_LABEL, JUDGE_ON_UNSUPPORTED_HINT, JUDGE_ON_UNSUPPORTED_LABEL, JUDGE_SETTING_TEXT, MERGE_TEXT, CATALOG_UI_TEXT, NODE_TYPE_LABEL, PROVIDER_REF_TEXT, SUBGRAPH_UPGRADE_HELP, judgeByModelText, upgradeNewerText } from '../lib/terms' import { TemplateText } from './TemplateText' import { MERGE_ALIAS, isQueryNode, mergeAlias } from './mergeInputs' import type { NodeType, Provider, ValidationIssue, WorkflowVersion } from '../types' @@ -1360,6 +1360,7 @@ function IoFieldList({ nodeId, value, issues, onChange }: { onChange={(e) => update(i, { default: e.target.value })} /> + update(i, patch)} /> )} {own.map((x, k) => )} @@ -1374,6 +1375,52 @@ function IoFieldList({ nodeId, value, issues, onChange }: { ) } +/** + * 入口字段的类型、格式、可选值(X2):服务端按它们把入口字段转成发起表单(agentlab.form/1),正式运行、画布试运行、 + * 应用入口的表单都照它画。没写类型的按文本处理,老图照常运行;写回时空的键删掉,不在配置里留空值 + */ +function InputFieldType({ uid, field, onChange }: { + uid: string; field: Record; onChange: (patch: Record) => void +}) { + const type = typeof field.type === 'string' ? field.type : 'string' + const options: string[] = Array.isArray(field.enum) ? field.enum.map(String) : [] + const [enumText, setEnumText] = useState(options.join('\n')) + useEffect(() => { setEnumText(options.join('\n')) }, [options.join('\n')]) // eslint-disable-line react-hooks/exhaustive-deps + return ( +
+
+ + + + {type === 'string' && ( + + + + )} +
+ {type !== 'boolean' && ( + +