dsh-workflow-execute 0.0.0-stage → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +36 -2
- package/client/bundle.js +3647 -0
- package/client/index.js +3360 -0
- package/cordis.patch.yml +13 -0
- package/package.json +62 -4
- package/scripts/build-client.mjs +85 -0
- package/scripts/fix-tests.mjs +71 -0
- package/scripts/make-yaml-bundle.mjs +21 -0
- package/scripts/patch-client-comp.mjs +196 -0
- package/scripts/patch-client-exec.mjs +147 -0
- package/scripts/patch-client-i18n.mjs +43 -0
- package/scripts/patch-flow.mjs +205 -0
- package/scripts/yaml-bundle.js +139 -0
- package/src/archive.js +81 -0
- package/src/artifacts.js +263 -0
- package/src/execution.js +746 -0
- package/src/index.js +212 -0
- package/src/prompt.js +24 -0
- package/src/routes.js +324 -0
- package/src/runs.js +237 -0
- package/src/store.js +482 -0
- package/src/tools.js +197 -0
- package/src/validate.js +258 -0
- package/src/zip.js +85 -0
package/client/index.js
ADDED
|
@@ -0,0 +1,3360 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dsh-workflow-execute — Browser half(工作流管理)。
|
|
3
|
+
*
|
|
4
|
+
* 三个挂载面:
|
|
5
|
+
* - 侧栏入口行(DOM 注入「新会话」下方,与任务看板同一家族块;滚动数字 = 我的 | 内置)。
|
|
6
|
+
* - 主页面:中栏接管视图(taskboard 同款,容器挂会话列末尾、html[data-dswfe-active] 驱动开合,
|
|
7
|
+
* 盖会话列不盖侧栏;列表+详情/编辑器工作台;Esc / 点会话行 / 与其他面板互斥时关闭)。
|
|
8
|
+
* - 兜底:会话列缺席的退化壳层下,开面板 450ms 后容器强制挂 body 退回全屏浮层。
|
|
9
|
+
*
|
|
10
|
+
* 数据流:EventSource /dsh-workflow-execute/events 变更帧 → 全量 refetch + revision 追赶
|
|
11
|
+
* (taskboard S16 同款);编辑走 baseHash 乐观锁,409 给「重新加载 / 仍然覆盖」。
|
|
12
|
+
*
|
|
13
|
+
* React 是 loader 平台模块;plain Node(契约测试)下降级为最小 shim。
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
let __React = null
|
|
17
|
+
try { __React = require('react') } catch {}
|
|
18
|
+
if (!__React || typeof __React.createElement !== 'function') {
|
|
19
|
+
__React = {
|
|
20
|
+
createElement(type, props, ...kids) {
|
|
21
|
+
return { type, props: props || {}, kids: kids.flat(9).filter(k => k !== null && k !== undefined && k !== false && k !== true) }
|
|
22
|
+
},
|
|
23
|
+
useState(init) { const v = [typeof init === 'function' ? init() : init]; return [v[0], x => { v[0] = typeof x === 'function' ? x(v[0]) : x }] },
|
|
24
|
+
useEffect() {}, useMemo(fn) { return fn() }, useRef(v = null) { return { current: v } },
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const { createElement: h, useState, useEffect, useMemo, useRef, useCallback } = __React
|
|
28
|
+
const useLayoutEffect = __React.useLayoutEffect || useEffect // React shim 兜底
|
|
29
|
+
|
|
30
|
+
const CLIENT_NAME = 'dsh-workflow-execute'
|
|
31
|
+
// API 基址随页面走:子路径反代(如 https://host/app/dsh/)下,绝对路径 /dsh-workflow-execute
|
|
32
|
+
// 会打到站点根而 404。与宿主官方客户端一致,用 document.baseURI 推导(dsh-sync#14 同款)。
|
|
33
|
+
const API = (() => {
|
|
34
|
+
try {
|
|
35
|
+
const base = (typeof document !== 'undefined' && document.baseURI) || (typeof location !== 'undefined' ? location.href : '/')
|
|
36
|
+
return new URL('dsh-workflow-execute', new URL('.', base)).pathname.replace(/\/+$/, '')
|
|
37
|
+
} catch { return '/dsh-workflow-execute' }
|
|
38
|
+
})()
|
|
39
|
+
const NS = 'dshProcess'
|
|
40
|
+
const PANEL_NAME = 'dsh-workflow-execute'
|
|
41
|
+
const ACTIVATE_EVENT = 'dsh-panel-activate'
|
|
42
|
+
const ENTRY_ATTR = 'data-dswfe-entry'
|
|
43
|
+
// 中栏接管(taskboard 同款)开合属性 + 兄弟面板属性表
|
|
44
|
+
const PRC_ACTIVE_ATTR = 'data-dswfe-active'
|
|
45
|
+
const PRC_OTHER_ACTIVE_ATTRS = ['data-dsh-atb-active', 'data-dsh-taskboard-active', 'data-dsh-ssh-active', 'data-dsh-git-active', 'data-dsh-kb-active']
|
|
46
|
+
const PRC_SIDEBAR_ROW_SELECTOR = '[class*="sessionRow"], [class*="projectRow"], [class*="searchResultRow"], [class*="newSession"]'
|
|
47
|
+
// 侧栏整列:点「文档管理/插件/记忆系统」这类导航项也要退出中栏接管,否则 html[data-dswfe-active]
|
|
48
|
+
// 会把壳层渲染在中栏的其他视图一起隐藏,看起来像切不回去。
|
|
49
|
+
const PRC_SIDEBAR_COLUMN_SELECTOR = '[data-pane="sidebar"], [class*="sidebarCol"], .dshDesktopUpstreamSidebar, .dshDesktopSidebarSurface'
|
|
50
|
+
const PREFS_KEY = 'dswfe:prefs'
|
|
51
|
+
|
|
52
|
+
// ── i18n ─────────────────────────────────────────────────────────────────
|
|
53
|
+
|
|
54
|
+
const ZH = {
|
|
55
|
+
title: '工作流',
|
|
56
|
+
entryAria: '打开工作流',
|
|
57
|
+
entryTitle: '工作流 — 我的 {user} · 内置 {bundled}',
|
|
58
|
+
count: '我的 {user} · 内置 {bundled}',
|
|
59
|
+
searchPlaceholder: '搜索名称 / 描述…',
|
|
60
|
+
filterAll: '全部来源', filterUser: '我的', filterBundled: '内置',
|
|
61
|
+
categoryAll: '全部分类', complexityAll: '全部复杂度',
|
|
62
|
+
sortDefault: '按名称', sortUpdated: '按更新时间', sortComplexity: '按复杂度', sortLinks: '按环节数',
|
|
63
|
+
newTask: '新建', newBlank: '空白工作流', newFromExisting: '复制现有…',
|
|
64
|
+
importBtn: '导入', exportBtn: '导出', exportAll: '全部(zip)', exportUser: '我的库(zip)', exportOne: '本工作流(yaml)',
|
|
65
|
+
settingsBtn: '设置', aiBtn: 'AI 生成',
|
|
66
|
+
close: '关闭', cancel: '取消', save: '保存', confirm: '确认', delete: '删除', edit: '编辑', copy: '复制', rename: '重命名',
|
|
67
|
+
copyToMine: '复制到我的库', reload: '重新加载', overwrite: '仍然覆盖', discard: '放弃修改', keepEditing: '继续编辑',
|
|
68
|
+
tabOverview: '概览', tabStructure: '结构', tabYaml: 'YAML',
|
|
69
|
+
loading: '加载中…', emptyList: '没有匹配的工作流', emptyListHint: '试试清空筛选,或「新建 / 导入」一个工作流',
|
|
70
|
+
emptyDetail: '从左侧选择一个工作流', selectFirst: '左侧选择工作流后在这里看概览、结构与 YAML',
|
|
71
|
+
errOne: '处错误', warnOne: '处警告',
|
|
72
|
+
readOnly: '内置 · 只读', mine: '我的', bundled: '内置',
|
|
73
|
+
limits: '限额', steps: '环节执行上限', tokens: 'token 上限', unlimited: '不限',
|
|
74
|
+
abnormal: '异常触发', phases: '阶段', links: '环节',
|
|
75
|
+
diagnostics: '诊断', noIssues: '结构正常 · 没有发现错误或警告',
|
|
76
|
+
name: '名称', displayName: '显示名', guid: 'GUID', version: '版本', category: '分类', complexity: '复杂度',
|
|
77
|
+
prompt: '指令 prompt', executor: '执行器', expert: '专家', skills: '技能', model: '模型',
|
|
78
|
+
artifacts: '期望产物', gates: '门禁', flow: '流转', rework: '返工上限', acceptance: '验收标准', reviewPrompt: '复核提示词', reviewType: '复核方式',
|
|
79
|
+
onSuccess: '成功后', onGateFail: '门禁不过', onRatingFail: '评级不过',
|
|
80
|
+
flowNext: '下一环节', flowEnd: '结束', flowBreak: '中止(询问用户)',
|
|
81
|
+
flowBreakStop: '中止(停下问我)', flowJumpTo: '跳到「环节{no} · {name}」',
|
|
82
|
+
editorTitle: '编辑', editorCreate: '新建工作流', editorCopy: '复制工作流',
|
|
83
|
+
unsaved: '未保存', saved: '已保存', validating: '校验中…',
|
|
84
|
+
saveConflict: '文件已被外部修改(可能是其他编辑器)。', forcedHint: '覆盖将丢弃外部改动。',
|
|
85
|
+
dirtyGuard: '有未保存的修改,确定放弃吗?',
|
|
86
|
+
deleteConfirm: '删除后移入回收站(.trash),确定删除',
|
|
87
|
+
createName: '工作流名(文件名,不含 .yaml)', createDir: '子目录(可选,如 software)', createDisplayName: '显示名(可选)',
|
|
88
|
+
copyName: '新工作流名', importTitle: '导入工作流', importHint: '选择或拖入 .yaml / .yml(可多选),导入到我的库',
|
|
89
|
+
importOverwrite: '覆盖同名文件', importPick: '选择文件', importResults: '导入结果',
|
|
90
|
+
importCreated: '已导入', importOverwritten: '已覆盖', importExists: '同名已存在(未导入)', importInvalid: '校验未通过',
|
|
91
|
+
settingsTitle: '工作流库设置', settingsUserRoot: '我的库根目录', settingsBundledRoot: '内置库根目录(只读)',
|
|
92
|
+
settingsMaxDepth: '扫描深度', settingsSaved: '设置已保存,正在重扫',
|
|
93
|
+
renameTitle: '重命名显示名', newName: '新显示名', renameHint: '只改界面显示的名称,文件名与标识不变',
|
|
94
|
+
aiTitle: 'AI 生成工作流', aiHint: '描述要解决的需求,AI 会产出一版工作流 YAML;生成后可校验并写入我的库',
|
|
95
|
+
aiRequirement: '要做什么(需求描述)', aiComplexity: '复杂度(低 / 中 / 高)', aiReference: '参考工作流(可选)',
|
|
96
|
+
aiPreviewTitle: '生成结果预览', aiSaveName: '写入名称', aiSave: '写入我的库', aiParseFail: '输出里没有找到 YAML 代码块',
|
|
97
|
+
copied: '已复制', copyYaml: '复制 YAML',
|
|
98
|
+
openSession: '打开会话', aiRunning: '生成中…', aiDone: '生成完成',
|
|
99
|
+
openLib: '打开工作流库', settingsSectionHint: '工作流 = 多阶段 agent 工作流模板;此处配置工作流库根目录。',
|
|
100
|
+
validate: '校验', linesCount: '{n} 行',
|
|
101
|
+
validateOk: '校验通过:0 错误 0 警告', validateResult: '校验完成:{e} 个错误 · {w} 个警告',
|
|
102
|
+
toastSaved: '已保存', toastForceSaved: '已覆盖保存', toastCopied: '已复制到我的库', toastRenamed: '已重命名',
|
|
103
|
+
toastTrashed: '已移入回收站(.trash)', toastImported: '{n} 个工作流已导入', toastAiSaved: '已写入我的库',
|
|
104
|
+
copyPrompt: '复制 Prompt', aiOutput: '输出', aiFailed: '失败', aiRequirementPh: '例如:把口头需求整理成 PRD 并拆解成开发任务',
|
|
105
|
+
kitMissing: 'dsh-plugin-kit 未内联(构建问题)', nameRule: '名称不能为空、不能含 / 或 \\、不能以点开头',
|
|
106
|
+
sessionUnavailable: '当前页面拿不到会话服务,无法跳转',
|
|
107
|
+
atAgent: '给 agent', atAgentTitle: '@ 进对话框,让 agent 帮你修改这个工作流(输入你的修改要求后发送)',
|
|
108
|
+
atAgentBundledTitle: '@ 进对话框(内置只读,agent 会改完存成你的新工作流)',
|
|
109
|
+
atAgentBundledHint: '(这是内置只读工作流——请改完用 workflow_save 存成我的库里的新工作流)',
|
|
110
|
+
atInserted: '已 @ 进对话框:输入你的修改要求后发送', atCopied: '没找到输入框,已复制引用到剪贴板',
|
|
111
|
+
viewLib: '工作流', viewExec: '执行记录',
|
|
112
|
+
runCreate: '▶ 按工作流执行', runWorkspace: '工作区(可选)', runStarted: '运行已发起',
|
|
113
|
+
workspaceDefault: '默认(不绑定)',
|
|
114
|
+
statusQueued: '排队中', statusRunning: '运行中', statusPaused: '已暂停', statusAwaiting: '等待裁决', statusAwaitingReview: '等待人工审核',
|
|
115
|
+
statusDone: '已完成', statusStopped: '已停止', statusFailed: '失败',
|
|
116
|
+
pause: '暂停', resume: '继续', stopRun: '停止运行', stopConfirm: '停止后当前环节结果作废,确定停止?',
|
|
117
|
+
noRuns: '还没有运行记录', noRunsHint: '到「工作流」打开一个工作流,点「▶ 按工作流执行」发起一次运行',
|
|
118
|
+
emptyRun: '左侧选择一次运行查看看板',
|
|
119
|
+
runLoadFailed: '运行详情加载失败',
|
|
120
|
+
retryLoad: '重试',
|
|
121
|
+
progress: '{done}/{total} 环节', attemptN: '第 {n} 次尝试', reworkN: '返工 ×{n}',
|
|
122
|
+
usageTitle: '输入 {input} · 输出 {output} · {calls} 次调用(含门禁评审)', usageTotal: 'Token',
|
|
123
|
+
artifactsTitle: '产物', artifactMissing: '未生成',
|
|
124
|
+
artifactsNone: '还没有观察到文件写入:执行中用 write / edit / str-replace-editor 改动的文件会出现在这里',
|
|
125
|
+
fileViewTitle: '产物预览', fileBinary: '二进制文件,暂不支持预览', fileTruncated: '文件较大,仅显示前 {size},完整内容请在工作区打开',
|
|
126
|
+
viewFiles: '查看输出物', linkFilesTitle: '环节产物', diffLabel: '变更', contentLabel: '内容', noFiles: '本环节没有声明产物,也没有观察到文件写入', pickFile: '选择左侧文件后在这里查看内容',
|
|
127
|
+
gateLabel: '门禁', gateScore: '{score} 分(线 {min})',
|
|
128
|
+
openSession: '打开会话', outputLabel: '实时输出', retryLink: '从本环节重新运行', skipLink: '跳过本环节',
|
|
129
|
+
breakTitle: '门禁未过,等待你的裁决', decisionRetry: '重试本环节', decisionSkip: '跳过本环节', decisionStop: '中止运行',
|
|
130
|
+
humanReviewTitle: '人工审核,等待你的验收', decisionApprove: '审核通过,继续下一步', decisionReject: '打回重做',
|
|
131
|
+
gateReasonLabel: '评审理由', linkAwaitingReviewHint: '该环节已执行完毕,请查看产物与执行报告后裁决',
|
|
132
|
+
linkPending: '待跑', linkDone: '完成', linkRunning: '进行中', linkGateFailed: '门禁未过', linkSkipped: '跳过', linkFailed: '失败', linkAbandoned: '中断', linkAwaitingReview: '待人工审核', linkApproved: '审核通过', linkRejected: '打回重做',
|
|
133
|
+
currentStep: '当前', runError: '运行异常',
|
|
134
|
+
runUserInput: '需求 / 要处理的问题(必填,只注入第一个环节)', runUserInputPh: '例如:把「XX」这条口头需求整理成 PRD 并拆解任务',
|
|
135
|
+
formMode: '画布', yamlMode: 'YAML', formUnparseable: '当前 YAML 有语法错误,请切到 YAML 模式修复后再用画布',
|
|
136
|
+
canvasHint: '点击节点在右侧编辑属性;点空白处看工作流属性', canvasEmpty: '还没有任何阶段,点「+ 添加阶段」开始',
|
|
137
|
+
propGlobal: '工作流属性', propPhase: '阶段属性', propLink: '环节属性',
|
|
138
|
+
canvasDelPhase: '删除阶段「{name}」及其下 {n} 个环节?', canvasDelLink: '删除环节「{name}」?',
|
|
139
|
+
formProvider: '供应商', modelDefault: '(默认)', modelProvDefault: '(供应商默认)',
|
|
140
|
+
skillsPick: '点选技能…', skillsNone: '无可用技能', skillsClear: '清空已选({n})',
|
|
141
|
+
formBasic: '基本信息', formLimits: '限额', formPhases: '阶段', formAddPhase: '+ 添加阶段', formAddLink: '+ 添加环节',
|
|
142
|
+
formDelPhase: '删除阶段', formDelLink: '删除环节', formAddGate: '+ 添加门禁', formGateName: '门禁名(如 证据齐全)', formGateMin: '分数线',
|
|
143
|
+
formName: '环节名', formGates: '门禁', formGateType: '门禁类型', formGateArtifact: '产物名',
|
|
144
|
+
formSkillsPh: '技能1, 技能2',
|
|
145
|
+
formDisplayName: '显示名', formVersion: '版本', formCategory: '分类', formComplexity: '复杂度', formDescription: '描述',
|
|
146
|
+
cxLow: '低', cxMid: '中', cxHigh: '高',
|
|
147
|
+
formMaxSteps: '环节执行上限(空=不限)', formMaxTokens: 'token 上限(空=不限)', formPrompt: '指令 prompt',
|
|
148
|
+
formAcceptance: '验收标准', formPhaseName: '阶段名', formPhaseSpec: '阶段说明', formExecutor: '执行器', formExpert: '专家',
|
|
149
|
+
formModel: '模型', formReviewType: '复核方式', formMaxRework: '返工上限', formOnSuccess: '成功后',
|
|
150
|
+
formOnGateFail: '门禁不过', formOnRatingFail: '评级不过', formNewLinkName: '新环节',
|
|
151
|
+
tabFlow: '流程图',
|
|
152
|
+
flowGate: '门禁 ≥{min}', flowRework: '返工≤{n}', flowNoGate: '无门禁',
|
|
153
|
+
flowLegendForward: '正常流转', flowLegendJump: '跳转', flowLegendFail: '门禁未过回跳', flowLegendBreak: '中止(不连线)',
|
|
154
|
+
flowRunCurrent: '当前环节', flowRunDone: '已完成', flowRunGateFailed: '门禁未过', flowRunSkipped: '跳过', flowRunFailed: '失败',
|
|
155
|
+
flowNoParsed: '工作流无法解析,无法绘制流程图',
|
|
156
|
+
flowReviewAi: 'AI评审', flowReviewHuman: '人工评审', flowReviewNone: '无需评审',
|
|
157
|
+
flowScore: '得分:{score}',
|
|
158
|
+
flowStartLabel: '开始', flowEndLabel: '结束',
|
|
159
|
+
linkNo: '环节{n}', phaseNo: '阶段{n}',
|
|
160
|
+
execAI: 'AI 评审', execHuman: '人工评审', execNone: '无需评审',
|
|
161
|
+
reviewAi: 'AI 评审', reviewHuman: '人工评审', reviewNone: '无需评审',
|
|
162
|
+
overviewTitle: '概述', overviewEmpty: '这个工作流还没有环节',
|
|
163
|
+
helpReviewType: '环节由谁判定是否通过:AI = 评审会话按门禁分数自动判定;人工 = 执行完停下等人审核;无需 = 直接进入下一环节。',
|
|
164
|
+
helpPrompt: '发给执行会话的指令正文。写清要做什么、产物写到哪个文件、执行报告要写什么。',
|
|
165
|
+
helpAcceptance: '本环节的验收标准,门禁评审时按它打分。',
|
|
166
|
+
helpGates: '门禁是一组评审规则:评审分数低于分数线即判不通过,按「门禁不过」流转。',
|
|
167
|
+
helpGateMin: '门禁分数线(0-100)。评审分数达到该值才算通过。',
|
|
168
|
+
helpCanvas: '点击节点在右侧编辑属性;点空白处看工作流属性。',
|
|
169
|
+
helpSessionMode: '多会话:每个环节开一个新会话,门禁单独开会话,上下文互不干扰。单会话:整条流程共用一个会话(门禁也在其中),省 token 但上下文会累积。',
|
|
170
|
+
sessionMode: '对话模式', sessionMulti: '多会话(每环节一个)', sessionSingle: '单会话(全流程一个)', requestLabel: '需求',
|
|
171
|
+
startedAt: '开始', endedAt: '结束', durationTotal: '总耗时', tokenLabel: 'TOKEN',
|
|
172
|
+
durationUnknown: '—',
|
|
173
|
+
viewArtifacts: '查看输出物', deleteRun: '删除', deleteRunConfirm: '删除这条运行记录?',
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const EN = {
|
|
177
|
+
title: 'Workflows', entryAria: 'Open workflow library', entryTitle: 'Workflows — mine {user} · bundled {bundled}',
|
|
178
|
+
count: 'mine {user} · bundled {bundled}', searchPlaceholder: 'Search name / description…',
|
|
179
|
+
filterAll: 'All sources', filterUser: 'Mine', filterBundled: 'Bundled',
|
|
180
|
+
categoryAll: 'All categories', complexityAll: 'All complexities',
|
|
181
|
+
sortDefault: 'By name', sortUpdated: 'By updated', sortComplexity: 'By complexity', sortLinks: 'By links',
|
|
182
|
+
newTask: 'New', newBlank: 'Blank workflow', newFromExisting: 'Duplicate existing…',
|
|
183
|
+
importBtn: 'Import', exportBtn: 'Export', exportAll: 'All (zip)', exportUser: 'Mine (zip)', exportOne: 'This one (yaml)',
|
|
184
|
+
settingsBtn: 'Settings', aiBtn: 'AI generate',
|
|
185
|
+
close: 'Close', cancel: 'Cancel', save: 'Save', confirm: 'OK', delete: 'Delete', edit: 'Edit', copy: 'Duplicate', rename: 'Rename',
|
|
186
|
+
copyToMine: 'Copy to my library', reload: 'Reload', overwrite: 'Overwrite anyway', discard: 'Discard', keepEditing: 'Keep editing',
|
|
187
|
+
tabOverview: 'Overview', tabStructure: 'Structure', tabYaml: 'YAML',
|
|
188
|
+
loading: 'Loading…', emptyList: 'No matching workflows', emptyListHint: 'Try clearing filters, or create / import one',
|
|
189
|
+
emptyDetail: 'Pick a workflow on the left', selectFirst: 'Overview, structure and YAML show up here after you select one',
|
|
190
|
+
errOne: ' error(s)', warnOne: ' warning(s)',
|
|
191
|
+
readOnly: 'Bundled · read-only', mine: 'Mine', bundled: 'Bundled',
|
|
192
|
+
limits: 'Limits', steps: 'max step runs', tokens: 'max tokens', unlimited: 'unlimited',
|
|
193
|
+
abnormal: 'Abnormal trigger', phases: 'phases', links: 'links',
|
|
194
|
+
diagnostics: 'Diagnostics', noIssues: 'Structure looks fine · no errors or warnings',
|
|
195
|
+
name: 'Name', displayName: 'Display name', guid: 'GUID', version: 'Version', category: 'Category', complexity: 'Complexity',
|
|
196
|
+
prompt: 'Prompt', executor: 'Executor', expert: 'Expert', skills: 'Skills', model: 'Model',
|
|
197
|
+
artifacts: 'Expected artifacts', gates: 'Gates', flow: 'Flow', rework: 'Max rework', acceptance: 'Acceptance', reviewPrompt: 'Review prompt', reviewType: 'Review',
|
|
198
|
+
onSuccess: 'On success', onGateFail: 'On gate fail', onRatingFail: 'On rating fail',
|
|
199
|
+
flowNext: 'next link', flowEnd: 'end', flowBreak: 'break (ask user)',
|
|
200
|
+
flowBreakStop: 'break (stop and ask me)', flowJumpTo: 'Jump to link {no} · {name}',
|
|
201
|
+
editorTitle: 'Edit', editorCreate: 'New workflow', editorCopy: 'Duplicate workflow',
|
|
202
|
+
unsaved: 'Unsaved', saved: 'Saved', validating: 'Validating…',
|
|
203
|
+
saveConflict: 'The file was changed externally (another editor).', forcedHint: 'Overwriting discards those changes.',
|
|
204
|
+
dirtyGuard: 'Discard unsaved changes?',
|
|
205
|
+
deleteConfirm: 'Delete moves the file into .trash. Delete',
|
|
206
|
+
createName: 'Workflow name (file name, no .yaml)', createDir: 'Sub-directory (optional, e.g. software)', createDisplayName: 'Display name (optional)',
|
|
207
|
+
copyName: 'New workflow name', importTitle: 'Import workflows', importHint: 'Pick or drop .yaml / .yml files (multi-select) into MY library',
|
|
208
|
+
importOverwrite: 'Overwrite existing files', importPick: 'Choose files', importResults: 'Results',
|
|
209
|
+
importCreated: 'imported', importOverwritten: 'overwritten', importExists: 'skipped (exists)', importInvalid: 'invalid',
|
|
210
|
+
settingsTitle: 'Workflow library settings', settingsUserRoot: 'My library root', settingsBundledRoot: 'Bundled library root (read-only)',
|
|
211
|
+
settingsMaxDepth: 'Scan depth', settingsSaved: 'Settings saved; rescanning',
|
|
212
|
+
renameTitle: 'Rename display name', newName: 'New display name', renameHint: 'Only the shown name changes; file name and id stay.',
|
|
213
|
+
aiTitle: 'AI generate workflow', aiHint: 'Describe the need; AI drafts a workflow YAML you can validate and save into MY library',
|
|
214
|
+
aiRequirement: 'What should it do', aiComplexity: 'Complexity (low / medium / high)', aiReference: 'Reference workflow (optional)',
|
|
215
|
+
aiPreviewTitle: 'Generated preview', aiSaveName: 'Save as', aiSave: 'Save to my library', aiParseFail: 'No YAML code block found in the output',
|
|
216
|
+
copied: 'Copied', copyYaml: 'Copy YAML',
|
|
217
|
+
openSession: 'Open chat', aiRunning: 'Generating…', aiDone: 'Generated',
|
|
218
|
+
openLib: 'Open workflow library', settingsSectionHint: 'A workflow is a multi-phase agent workflow template; configure library roots here.',
|
|
219
|
+
validate: 'Validate', linesCount: '{n} lines',
|
|
220
|
+
validateOk: 'Validated: 0 errors, 0 warnings', validateResult: 'Validated: {e} errors · {w} warnings',
|
|
221
|
+
toastSaved: 'Saved', toastForceSaved: 'Overwritten and saved', toastCopied: 'Copied to my library', toastRenamed: 'Renamed',
|
|
222
|
+
toastTrashed: 'Moved to .trash', toastImported: '{n} workflow(es) imported', toastAiSaved: 'Saved to my library',
|
|
223
|
+
copyPrompt: 'Copy prompt', aiOutput: 'Output', aiFailed: 'Failed', aiRequirementPh: 'e.g. turn a verbal requirement into a PRD and split it into dev tasks',
|
|
224
|
+
kitMissing: 'dsh-plugin-kit not inlined (build issue)', nameRule: 'Name must be non-empty, without / or \\, and not start with a dot',
|
|
225
|
+
sessionUnavailable: 'Session service unavailable on this page',
|
|
226
|
+
atAgent: 'Ask agent', atAgentTitle: '@-reference into the composer and let an agent modify this workflow',
|
|
227
|
+
atAgentBundledTitle: '@-reference (bundled is read-only; the agent will save a new workflow into your library)',
|
|
228
|
+
atAgentBundledHint: '(this is a read-only bundled workflow — save your edited version as a new workflow in MY library via workflow_save)',
|
|
229
|
+
atInserted: '@-referenced in the composer: type your change request and send', atCopied: 'Composer not found — reference copied to clipboard',
|
|
230
|
+
viewLib: 'Library', viewExec: 'Runs',
|
|
231
|
+
runCreate: '▶ Run workflow', runWorkspace: 'Workspace (optional)', runStarted: 'Run started',
|
|
232
|
+
workspaceDefault: 'Default (unbound)',
|
|
233
|
+
statusQueued: 'Queued', statusRunning: 'Running', statusPaused: 'Paused', statusAwaiting: 'Awaiting decision', statusAwaitingReview: 'Awaiting manual review',
|
|
234
|
+
statusDone: 'Done', statusStopped: 'Stopped', statusFailed: 'Failed',
|
|
235
|
+
pause: 'Pause', resume: 'Resume', stopRun: 'Stop run', stopConfirm: 'The running link result will be discarded. Stop?',
|
|
236
|
+
noRuns: 'No runs yet', noRunsHint: 'Open a workflow in "Library" and click "▶ Run workflow"',
|
|
237
|
+
emptyRun: 'Pick a run on the left to see its board',
|
|
238
|
+
runLoadFailed: 'Failed to load this run',
|
|
239
|
+
retryLoad: 'Retry',
|
|
240
|
+
progress: '{done}/{total} links', attemptN: 'attempt {n}', reworkN: 'rework ×{n}',
|
|
241
|
+
usageTitle: 'in {input} · out {output} · {calls} calls (incl. gate review)', usageTotal: 'Tokens',
|
|
242
|
+
artifactsTitle: 'Artifacts', artifactMissing: 'missing',
|
|
243
|
+
artifactsNone: 'No file writes observed: files changed via write / edit / str-replace-editor during execution appear here',
|
|
244
|
+
fileViewTitle: 'Artifact preview', fileBinary: 'Binary file — preview not supported', fileTruncated: 'File is large; showing the first {size}. Open it in the workspace for the full content.',
|
|
245
|
+
viewFiles: 'Artifacts', linkFilesTitle: 'Link artifacts', diffLabel: 'Diff', contentLabel: 'Content', noFiles: 'No artifacts declared or observed for this link', pickFile: 'Pick a file on the left to see its content',
|
|
246
|
+
gateLabel: 'Gate', gateScore: '{score} (min {min})',
|
|
247
|
+
openSession: 'Open chat', outputLabel: 'Live output', retryLink: 'Rerun from this link', skipLink: 'Skip link',
|
|
248
|
+
breakTitle: 'Gate failed — awaiting your decision', decisionRetry: 'Retry this link', decisionSkip: 'Skip this link', decisionStop: 'Stop run',
|
|
249
|
+
humanReviewTitle: 'Manual review — awaiting your approval', decisionApprove: 'Approve and continue', decisionReject: 'Reject and redo',
|
|
250
|
+
gateReasonLabel: 'Reason', linkAwaitingReviewHint: 'This link finished; check the artifacts and report, then decide',
|
|
251
|
+
linkPending: 'pending', linkDone: 'done', linkRunning: 'running', linkGateFailed: 'gate failed', linkSkipped: 'skipped', linkFailed: 'failed', linkAbandoned: 'abandoned', linkAwaitingReview: 'awaiting review', linkApproved: 'approved', linkRejected: 'rejected',
|
|
252
|
+
currentStep: 'current', runError: 'run error',
|
|
253
|
+
runUserInput: 'Requirement / what to work on (required, injected into the first link only)', runUserInputPh: 'e.g. turn requirement XX into a PRD and split tasks',
|
|
254
|
+
formMode: 'Canvas', yamlMode: 'YAML', formUnparseable: 'YAML has syntax errors — fix them in YAML mode before using the canvas',
|
|
255
|
+
canvasHint: 'Click a node to edit its properties on the right; click empty space for workflow properties', canvasEmpty: 'No phases yet — click "+ Add phase" to start',
|
|
256
|
+
propGlobal: 'Workflow properties', propPhase: 'Phase properties', propLink: 'Link properties',
|
|
257
|
+
canvasDelPhase: 'Delete phase "{name}" and its {n} link(s)?', canvasDelLink: 'Delete link "{name}"?',
|
|
258
|
+
formProvider: 'Provider', modelDefault: '(default)', modelProvDefault: '(provider default)',
|
|
259
|
+
skillsPick: 'Pick skills…', skillsNone: 'No skills available', skillsClear: 'Clear selection ({n})',
|
|
260
|
+
formBasic: 'Basics', formLimits: 'Limits', formPhases: 'Phases', formAddPhase: '+ Add phase', formAddLink: '+ Add link',
|
|
261
|
+
formDelPhase: 'Delete phase', formDelLink: 'Delete link', formAddGate: '+ Add gate', formGateName: 'Gate name (e.g. evidence provided)', formGateMin: 'Min score',
|
|
262
|
+
formName: 'Link name', formGates: 'Gates', formGateType: 'Gate type', formGateArtifact: 'Artifact',
|
|
263
|
+
formSkillsPh: 'skill1, skill2',
|
|
264
|
+
formDisplayName: 'Display name', formVersion: 'Version', formCategory: 'Category', formComplexity: 'Complexity', formDescription: 'Description',
|
|
265
|
+
cxLow: 'Low', cxMid: 'Medium', cxHigh: 'High',
|
|
266
|
+
formMaxSteps: 'Max step runs (empty = unlimited)', formMaxTokens: 'Max tokens (empty = unlimited)', formPrompt: 'Prompt',
|
|
267
|
+
formAcceptance: 'Acceptance', formPhaseName: 'Phase name', formPhaseSpec: 'Phase spec', formExecutor: 'Executor', formExpert: 'Expert',
|
|
268
|
+
formModel: 'Model', formReviewType: 'Review', formMaxRework: 'Max rework', formOnSuccess: 'On success',
|
|
269
|
+
formOnGateFail: 'On gate fail', formOnRatingFail: 'On rating fail', formNewLinkName: 'New link',
|
|
270
|
+
tabFlow: 'Flow',
|
|
271
|
+
flowGate: 'gate ≥{min}', flowRework: 'rework≤{n}', flowNoGate: 'no gate',
|
|
272
|
+
flowLegendForward: 'forward', flowLegendJump: 'jump', flowLegendFail: 'gate-fail back', flowLegendBreak: 'break (no edge)',
|
|
273
|
+
flowRunCurrent: 'current', flowRunDone: 'done', flowRunGateFailed: 'gate failed', flowRunSkipped: 'skipped', flowRunFailed: 'failed',
|
|
274
|
+
flowNoParsed: 'Workflow cannot be parsed — cannot draw flow',
|
|
275
|
+
flowReviewAi: 'AI', flowReviewHuman: 'Human', flowReviewNone: 'No review',
|
|
276
|
+
flowScore: 'Score: {score}',
|
|
277
|
+
flowStartLabel: 'Start', flowEndLabel: 'End',
|
|
278
|
+
linkNo: 'Link {n}', phaseNo: 'Phase {n}',
|
|
279
|
+
execAI: 'AI review', execHuman: 'Human review', execNone: 'No review',
|
|
280
|
+
reviewAi: 'AI review', reviewHuman: 'Human review', reviewNone: 'No review',
|
|
281
|
+
overviewTitle: 'Overview', overviewEmpty: 'This workflow has no links yet',
|
|
282
|
+
helpReviewType: 'Who decides whether the link passed: AI = a review session scores against the gate; Human = execution pauses for your approval; None = continue directly.',
|
|
283
|
+
helpPrompt: 'The instruction sent to the execution session. State what to do, which file to write, and what the report must contain.',
|
|
284
|
+
helpAcceptance: 'Acceptance criteria for this link; the gate review scores against it.',
|
|
285
|
+
helpGates: 'A gate is a review rule: a score below the threshold means failed, and the flow follows "on gate fail".',
|
|
286
|
+
helpGateMin: 'Gate threshold (0-100). The review score must reach it to pass.',
|
|
287
|
+
helpCanvas: 'Click a node to edit its properties on the right; click empty space for workflow properties.',
|
|
288
|
+
helpSessionMode: 'Multi-session: one fresh session per link, gates get their own session, contexts stay isolated. Single-session: the whole run shares one session (gates included) — fewer tokens, but context accumulates.',
|
|
289
|
+
sessionMode: 'Conversation mode', sessionMulti: 'Multi-session (one per link)', sessionSingle: 'Single-session (one for the run)', requestLabel: 'Request',
|
|
290
|
+
startedAt: 'Start', endedAt: 'End', durationTotal: 'Total', tokenLabel: 'TOKEN',
|
|
291
|
+
durationUnknown: '—',
|
|
292
|
+
viewArtifacts: 'Artifacts', deleteRun: 'Delete', deleteRunConfirm: 'Delete this run record?',
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
function makeT(bound) {
|
|
296
|
+
return (key, vars) => {
|
|
297
|
+
let out = (bound && bound(key)) || EN[key] || ZH[key] || key
|
|
298
|
+
if (vars) for (const [k, v] of Object.entries(vars)) out = out.split('{' + k + '}').join(String(v))
|
|
299
|
+
return out
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
// ── 样式 ─────────────────────────────────────────────────────────────────
|
|
304
|
+
|
|
305
|
+
const STYLE = `
|
|
306
|
+
.dswfe-entry { display:flex; align-items:center; gap:8px; position:relative; width:calc(100% - 8px); margin:2px 4px; padding:6px 10px; border:none; border-radius:8px; background:transparent; color:var(--dsw-text-secondary, inherit); font:inherit; font-size:13px; cursor:pointer; text-align:left; }
|
|
307
|
+
.dswfe-entry:hover { background:var(--dsw-hover, rgba(128,128,128,.12)); color:var(--dsw-text-primary, inherit); }
|
|
308
|
+
.dswfe-entry[data-active="true"] { background:var(--dsw-active, rgba(128,128,128,.18)); color:var(--dsw-text-primary, inherit); font-weight:500; }
|
|
309
|
+
.dswfe-entry svg { flex:none; }
|
|
310
|
+
.dswfe-entry-stats { margin-left:auto; display:inline-flex; align-items:center; gap:3px; font-size:11px; line-height:1; color:var(--dsw-text-secondary, gray); font-variant-numeric:tabular-nums; white-space:nowrap; }
|
|
311
|
+
.dswfe-entry-sep { opacity:.5; }
|
|
312
|
+
.dswfe-roll { position:relative; display:inline-block; overflow:hidden; height:12px; min-width:1ch; text-align:center; vertical-align:middle; }
|
|
313
|
+
.dswfe-roll[data-stat="user"] { color:#3e63dd; }
|
|
314
|
+
.dswfe-roll[data-stat="bundled"] { color:#8e8e93; }
|
|
315
|
+
.dswfe-rn { display:block; height:12px; line-height:12px; text-align:center; }
|
|
316
|
+
.dswfe-rn-next { position:absolute; left:0; right:0; top:100%; }
|
|
317
|
+
.dswfe-roll[data-dir="down"] .dswfe-rn-next { top:auto; bottom:100%; }
|
|
318
|
+
.dswfe-roll .dswfe-rn { transition:transform .3s cubic-bezier(.25,.1,.25,1); }
|
|
319
|
+
.dswfe-roll[data-anim="1"][data-dir="up"] .dswfe-rn { transform:translateY(-100%); }
|
|
320
|
+
.dswfe-roll[data-anim="1"][data-dir="down"] .dswfe-rn { transform:translateY(100%); }
|
|
321
|
+
@media (prefers-reduced-motion: reduce) { .dswfe-roll .dswfe-rn { transition:none; } }
|
|
322
|
+
[data-sidebar-collapsed] [data-dswfe-entry], [class*="_collapsed"] [data-dswfe-entry] { width:36px; height:36px; min-width:36px; margin:0 0 12px; padding:0; justify-content:center; gap:0; text-align:center; }
|
|
323
|
+
[data-sidebar-collapsed] [data-dswfe-entry] .dswfe-entry-label, [data-sidebar-collapsed] [data-dswfe-entry] .dswfe-entry-stats,
|
|
324
|
+
[class*="_collapsed"] [data-dswfe-entry] .dswfe-entry-label, [class*="_collapsed"] [data-dswfe-entry] .dswfe-entry-stats { display:none; }
|
|
325
|
+
|
|
326
|
+
/* 中栏接管视图(taskboard 同款):容器挂进会话列末尾,html 属性驱动开合,只隐藏列内兄弟。
|
|
327
|
+
* 三代壳层选择器:dev shell data-pane / 官方 CSS-Module centerCol / Desktop 扩展框。 */
|
|
328
|
+
.dswfe-view { display:none; }
|
|
329
|
+
html[data-dswfe-active] [data-pane="conversation"] > *:not([data-dswfe-view]),
|
|
330
|
+
html[data-dswfe-active] [class*="centerCol"] > *:not([data-dswfe-view]),
|
|
331
|
+
html[data-dswfe-active] .dshDesktopConversationSurface > *:not([data-dswfe-view]) { display:none !important; }
|
|
332
|
+
html[data-dswfe-active] .dswfe-view { display:flex; flex-direction:column; height:100%; overflow:hidden; }
|
|
333
|
+
/* 壳层退化(会话列缺席):容器兜底挂 body 时退回全屏浮层,保证入口点击永远有响应 */
|
|
334
|
+
.dswfe-view[data-dswfe-fallback] { position:fixed; inset:0; z-index:2147483000; display:flex; }
|
|
335
|
+
.dswfe-panel { position:relative; flex:1; min-height:0; display:flex; flex-direction:column; overflow:hidden; pointer-events:auto; background:var(--dsw-alias-bg-base, var(--dsw-bg, #fff)); color:var(--dsw-alias-label-primary, var(--dsw-text-primary, inherit)); font:var(--dsw-font-family, inherit); font-size:13px; }
|
|
336
|
+
.dswfe-toolbar { display:flex; align-items:center; gap:8px; flex-wrap:wrap; padding:10px 14px; border-bottom:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35)); background:var(--dsw-alias-bg-layer-1, transparent); }
|
|
337
|
+
.dswfe-title { font-size:15px; font-weight:600; margin:0; }
|
|
338
|
+
.dswfe-count { font-size:12px; color:var(--dsw-text-secondary, gray); }
|
|
339
|
+
.dswfe-spacer { flex:1; }
|
|
340
|
+
.dswfe-btn { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35)); background:transparent; color:inherit; border-radius:8px; padding:5px 10px; font:inherit; font-size:13px; cursor:pointer; white-space:nowrap; }
|
|
341
|
+
.dswfe-btn:hover { background:var(--dsw-hover, rgba(128,128,128,.12)); }
|
|
342
|
+
.dswfe-btn[data-primary="true"] { background:var(--dsw-alias-button-primary-fill, var(--dsw-alias-brand-primary, #1f2328)); border-color:transparent; color:var(--dsw-alias-label-primary-inverted, #fff); }
|
|
343
|
+
.dswfe-btn[data-danger="true"] { color:var(--dsw-alias-state-error, #c75050); border-color:var(--dsw-alias-state-error, #c75050); }
|
|
344
|
+
.dswfe-btn:disabled { opacity:.5; cursor:default; }
|
|
345
|
+
.dswfe-input, .dswfe-select { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35)) !important; background:var(--dsw-alias-bg-layer-2, transparent); color:inherit; border-radius:8px; padding:5px 8px; font:inherit; font-size:13px; }
|
|
346
|
+
.dswfe-input:focus, .dswfe-select:focus, .dswfe-textarea:focus { border-color:var(--dsw-alias-accent, rgba(77,107,254,.85)) !important; outline:2px solid rgba(77,107,254,.35); outline-offset:1px; }
|
|
347
|
+
.dswfe-search { width:170px; }
|
|
348
|
+
.dswfe-body { flex:1; display:flex; min-height:0; }
|
|
349
|
+
.dswfe-list { width:300px; min-width:240px; overflow-y:auto; border-right:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35)); padding:6px; box-sizing:border-box; }
|
|
350
|
+
.dswfe-group { margin:8px 2px 4px; font-size:11px; color:var(--dsw-text-secondary, gray); display:flex; align-items:center; gap:6px; }
|
|
351
|
+
.dswfe-row { display:flex; flex-direction:column; gap:3px; width:100%; text-align:left; border:1px solid transparent; border-left-width:3px; border-radius:8px; background:transparent; color:inherit; padding:7px 9px; margin:2px 0; cursor:pointer; font:inherit; font-size:13px; position:relative; box-sizing:border-box; }
|
|
352
|
+
.dswfe-row:hover { background:var(--dsw-hover, rgba(128,128,128,.1)); }
|
|
353
|
+
.dswfe-row[data-selected="true"] { background:var(--dsw-active, rgba(128,128,128,.16)); border-color:var(--dsw-alias-border-l2, rgba(128,128,128,.3)); }
|
|
354
|
+
.dswfe-row[data-source="bundled"] { border-left-style:dashed; }
|
|
355
|
+
.dswfe-row[data-complexity="low"] { border-left-color:#3e63dd; }
|
|
356
|
+
.dswfe-row[data-complexity="medium"] { border-left-color:#8e8e93; }
|
|
357
|
+
.dswfe-row[data-complexity="high"] { border-left-color:#8e4ec6; }
|
|
358
|
+
.dswfe-row-name { font-weight:500; display:flex; align-items:center; gap:6px; min-width:0; }
|
|
359
|
+
.dswfe-row-name span.lbl { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
360
|
+
.dswfe-row-meta { display:flex; gap:6px; align-items:center; font-size:11px; color:var(--dsw-text-secondary, gray); flex-wrap:wrap; }
|
|
361
|
+
.dswfe-badge { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:6px; padding:0 5px; font-size:10px; line-height:16px; white-space:nowrap; }
|
|
362
|
+
.dswfe-badge[data-kind="err"] { color:var(--dsw-alias-state-error, #c75050); border-color:var(--dsw-alias-state-error, #c75050); }
|
|
363
|
+
.dswfe-badge[data-kind="warn"] { color:#b8860b; border-color:#b8860b; }
|
|
364
|
+
.dswfe-dot { width:6px; height:6px; border-radius:6px; display:inline-block; }
|
|
365
|
+
.dswfe-dot[data-kind="err"] { background:var(--dsw-alias-state-error, #c75050); }
|
|
366
|
+
.dswfe-dot[data-kind="warn"] { background:#d9a514; }
|
|
367
|
+
.dswfe-detail { flex:1; min-width:0; overflow-y:auto; padding:14px 18px; box-sizing:border-box; }
|
|
368
|
+
.dswfe-detail-head { display:flex; align-items:flex-start; gap:10px; flex-wrap:wrap; margin-bottom:10px; }
|
|
369
|
+
.dswfe-detail-title { font-size:17px; font-weight:700; margin:0; letter-spacing:-.01em; }
|
|
370
|
+
.dswfe-chips { display:flex; gap:8px; align-items:center; flex-wrap:wrap; margin:8px 0 14px; }
|
|
371
|
+
.dswfe-chip { display:inline-flex; align-items:center; gap:4px; border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:999px; padding:2px 10px; font-size:11px; line-height:18px; white-space:nowrap; color:var(--dsw-text-secondary, gray); font-variant-numeric:tabular-nums; background:var(--dsw-alias-bg-layer-2, transparent); }
|
|
372
|
+
.dswfe-actions { margin-left:auto; display:flex; gap:6px; flex-wrap:wrap; }
|
|
373
|
+
.dswfe-tabs { display:flex; gap:2px; border-bottom:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); margin-bottom:12px; }
|
|
374
|
+
.dswfe-tab { border:none; background:transparent; color:var(--dsw-text-secondary, inherit); padding:7px 12px; font:inherit; font-size:13px; cursor:pointer; border-bottom:2px solid transparent; }
|
|
375
|
+
.dswfe-tab[data-on="true"] { color:var(--dsw-text-primary, inherit); font-weight:600; border-bottom-color:var(--dsw-alias-brand-primary, currentColor); }
|
|
376
|
+
.dswfe-desc { white-space:pre-wrap; line-height:1.65; margin:0 0 12px; }
|
|
377
|
+
.dswfe-kv { display:flex; gap:8px; font-size:12px; margin:3px 0; flex-wrap:wrap; }
|
|
378
|
+
.dswfe-kv b { opacity:.7; font-weight:500; }
|
|
379
|
+
.dswfe-diag { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:8px; padding:8px 10px; margin:6px 0; display:flex; flex-direction:column; gap:4px; }
|
|
380
|
+
.dswfe-diag-item { display:flex; gap:8px; align-items:baseline; cursor:pointer; font-size:12px; border:none; background:transparent; color:inherit; padding:2px 4px; border-radius:6px; text-align:left; font:inherit; width:100%; box-sizing:border-box; }
|
|
381
|
+
.dswfe-diag-item:hover { background:var(--dsw-hover, rgba(128,128,128,.1)); }
|
|
382
|
+
.dswfe-diag-item[data-kind="err"] .dswfe-diag-code { color:var(--dsw-alias-state-error, #c75050); }
|
|
383
|
+
.dswfe-diag-item[data-kind="warn"] .dswfe-diag-code { color:#b8860b; }
|
|
384
|
+
.dswfe-diag-code { font-weight:600; flex:none; }
|
|
385
|
+
.dswfe-diag-line { opacity:.6; flex:none; min-width:34px; }
|
|
386
|
+
.dswfe-phase { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:11px; padding:12px 14px; margin:10px 0; }
|
|
387
|
+
.dswfe-phase-head { display:flex; align-items:baseline; gap:8px; font-weight:700; font-size:13px; }
|
|
388
|
+
.dswfe-phase-spec { white-space:pre-wrap; font-size:12px; opacity:.8; margin:6px 0; }
|
|
389
|
+
.dswfe-link { border-top:1px dashed var(--dsw-alias-border-l1, rgba(128,128,128,.2)); margin-top:6px; padding-top:6px; }
|
|
390
|
+
.dswfe-link-row { display:flex; align-items:baseline; gap:8px; width:100%; border:none; background:transparent; color:inherit; font:inherit; font-size:13px; cursor:pointer; padding:4px 2px; border-radius:6px; text-align:left; box-sizing:border-box; }
|
|
391
|
+
.dswfe-link-row:hover { background:var(--dsw-hover, rgba(128,128,128,.1)); }
|
|
392
|
+
.dswfe-link-id { font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:11px; opacity:.75; flex:none; }
|
|
393
|
+
.dswfe-link-meta { font-size:11px; color:var(--dsw-text-secondary, gray); margin-left:auto; display:flex; gap:6px; flex-wrap:wrap; }
|
|
394
|
+
.dswfe-link-body { padding:6px 8px 2px; display:flex; flex-direction:column; gap:6px; }
|
|
395
|
+
.dswfe-pre { white-space:pre-wrap; line-height:1.6; font-size:12px; background:var(--dsw-alias-bg-layer-2, rgba(128,128,128,.07)); border:1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.2)); border-radius:8px; padding:8px 10px; margin:0; overflow-x:auto; }
|
|
396
|
+
.dswfe-code { font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:12px; line-height:1.55; border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:10px; overflow:auto; max-height:calc(100vh - 260px); background:var(--dsw-alias-bg-layer-2, rgba(128,128,128,.05)); }
|
|
397
|
+
.dswfe-code-line { display:flex; }
|
|
398
|
+
.dswfe-code-line[data-hl="true"] { background:rgba(217,130,43,.18); }
|
|
399
|
+
.dswfe-code-no { flex:none; width:44px; text-align:right; padding-right:10px; color:var(--dsw-text-secondary, gray); user-select:none; opacity:.7; }
|
|
400
|
+
.dswfe-code-tx { white-space:pre; padding-right:16px; }
|
|
401
|
+
.dswfe-cm { color:var(--dsw-text-secondary, gray); font-style:italic; }
|
|
402
|
+
.dswfe-key { color:#3e63dd; }
|
|
403
|
+
.dswfe-editor { display:flex; flex-direction:column; gap:8px; flex:1; min-height:0; }
|
|
404
|
+
.dswfe-editor-wrap { display:flex; flex:1; min-height:0; border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35)); border-radius:10px; overflow:hidden; background:var(--dsw-alias-bg-layer-2, rgba(128,128,128,.05)); }
|
|
405
|
+
.dswfe-gutter { flex:none; width:46px; text-align:right; padding:8px 10px 8px 0; font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:12px; line-height:19px; color:var(--dsw-text-secondary, gray); overflow:hidden; user-select:none; opacity:.7; box-sizing:border-box; }
|
|
406
|
+
.dswfe-textarea { flex:1; border:none; outline:none; resize:none; background:transparent; color:inherit; font-family:ui-monospace, SFMono-Regular, Menlo, monospace; font-size:12px; line-height:19px; padding:8px 12px; white-space:pre; overflow:auto; tab-size:2; }
|
|
407
|
+
.dswfe-status { display:flex; gap:10px; align-items:center; font-size:12px; color:var(--dsw-text-secondary, gray); flex-wrap:wrap; }
|
|
408
|
+
.dswfe-conflict { border:1px solid var(--dsw-alias-state-error, #c75050); border-radius:8px; padding:8px 10px; display:flex; gap:8px; align-items:center; flex-wrap:wrap; font-size:12px; }
|
|
409
|
+
.dswfe-modal-backdrop { position:fixed; inset:0; z-index:2147482900; background:rgba(0,0,0,.45); display:flex; align-items:center; justify-content:center; }
|
|
410
|
+
html[data-windows-titlebar] .dswfe-modal-backdrop { top:var(--dsh-windows-titlebar-height, 38px); }
|
|
411
|
+
html[data-windows-titlebar][data-fullscreen] .dswfe-modal-backdrop { top:0; }
|
|
412
|
+
.dswfe-modal { width:min(560px, 92vw); max-height:86vh; overflow:auto; background:var(--dsw-alias-bg-layer-1, #fff); color:var(--dsw-alias-label-primary, inherit); border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:14px; padding:18px; display:flex; flex-direction:column; gap:12px; font:var(--dsw-font-family, inherit); }
|
|
413
|
+
.dswfe-modal h3 { margin:0; font-size:16px; }
|
|
414
|
+
.dswfe-field { display:flex; flex-direction:column; gap:6px; font-size:12px; }
|
|
415
|
+
.dswfe-field input, .dswfe-field select, .dswfe-field textarea { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); background:var(--dsw-alias-bg-layer-2, transparent); color:inherit; border-radius:8px; padding:6px 10px; font:inherit; font-size:13px; }
|
|
416
|
+
.dswfe-field textarea { resize:vertical; min-height:52px; width:100%; box-sizing:border-box; line-height:1.5; }
|
|
417
|
+
.dswfe-menuback { position:fixed; inset:0; z-index:2147482800; }
|
|
418
|
+
.dswfe-menu { position:fixed; z-index:2147482850; background:var(--dsw-alias-bg-overlay, var(--dsw-alias-bg-layer-1, #252830)); color:var(--dsw-alias-label-primary, inherit); border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:10px; padding:4px; display:flex; flex-direction:column; min-width:150px; box-shadow:0 8px 30px rgba(0,0,0,.25); }
|
|
419
|
+
.dswfe-menu button { border:none; background:transparent; color:inherit; text-align:left; padding:7px 10px; border-radius:7px; font:inherit; font-size:13px; cursor:pointer; white-space:nowrap; }
|
|
420
|
+
.dswfe-menu button:hover { background:var(--dsw-hover, rgba(128,128,128,.15)); }
|
|
421
|
+
.dswfe-toast { position:fixed; left:50%; bottom:26px; transform:translateX(-50%); z-index:2147483000; background:var(--dsw-alias-bg-overlay, #252830); color:var(--dsw-alias-label-primary, #fff); border-radius:10px; padding:8px 14px; font-size:13px; box-shadow:0 6px 24px rgba(0,0,0,.3); max-width:70vw; }
|
|
422
|
+
.dswfe-toast[data-kind="err"] { outline:1px solid var(--dsw-alias-state-error, #c75050); }
|
|
423
|
+
.dswfe-empty { flex:1; display:flex; flex-direction:column; align-items:center; justify-content:center; gap:8px; color:var(--dsw-text-secondary, gray); text-align:center; padding:20px; }
|
|
424
|
+
.dswfe-error { margin:8px 14px 0; border:1px solid var(--dsw-alias-state-error, #c75050); color:var(--dsw-alias-state-error, #c75050); border-radius:8px; padding:6px 10px; font-size:12px; }
|
|
425
|
+
.dswfe-drop { border:2px dashed var(--dsw-alias-border-l2, rgba(128,128,128,.4)); border-radius:10px; padding:22px; text-align:center; font-size:12px; color:var(--dsw-text-secondary, gray); }
|
|
426
|
+
.dswfe-drop[data-over="true"] { border-color:var(--dsw-alias-brand-primary, #3e63dd); }
|
|
427
|
+
.dswfe-sec { margin:10px 0; }
|
|
428
|
+
.dswfe-sec h4 { margin:0 0 8px; font-size:12.5px; font-weight:700; letter-spacing:.04em; color:var(--dsw-alias-label-secondary, inherit); }
|
|
429
|
+
|
|
430
|
+
.dswfe-runlist { width:296px; min-width:230px; overflow-y:auto; border-right:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35)); padding:8px; box-sizing:border-box; }
|
|
431
|
+
.dswfe-runrow { display:flex; flex-direction:column; gap:4px; width:100%; text-align:left; border:1px solid transparent; border-radius:9px; background:transparent; color:inherit; padding:9px 10px; margin:3px 0; cursor:pointer; font:inherit; font-size:12px; box-sizing:border-box; }
|
|
432
|
+
.dswfe-runrow:hover { background:var(--dsw-hover, rgba(128,128,128,.1)); }
|
|
433
|
+
.dswfe-runrow[data-selected="true"] { background:var(--dsw-active, rgba(128,128,128,.16)); border-color:var(--dsw-alias-border-l2, rgba(128,128,128,.3)); }
|
|
434
|
+
.dswfe-runrow-top { display:flex; align-items:center; gap:6px; min-width:0; }
|
|
435
|
+
.dswfe-runrow-name { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:600; }
|
|
436
|
+
.dswfe-runrow-meta { display:flex; flex-wrap:wrap; gap:8px; color:var(--dsw-text-secondary, gray); font-size:11px; font-variant-numeric:tabular-nums; }
|
|
437
|
+
.dswfe-runrow-req { min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; color:var(--dsw-text-secondary, gray); font-size:11px; line-height:1.5; opacity:.9; }
|
|
438
|
+
.dswfe-runrow[data-selected="true"] .dswfe-runrow-req { opacity:1; }
|
|
439
|
+
.dswfe-rundel { opacity:0; transition:opacity .12s; }
|
|
440
|
+
.dswfe-runrow:hover .dswfe-rundel, .dswfe-runrow:focus-within .dswfe-rundel { opacity:1; }
|
|
441
|
+
.dswfe-linkdur { flex:none; font-size:11px; opacity:.8; font-variant-numeric:tabular-nums; margin-left:6px; padding-left:8px; border-left:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.25)); }
|
|
442
|
+
.dswfe-help { position:relative; display:inline-flex; align-items:center; justify-content:center; width:14px; height:14px; margin-left:6px; border-radius:50%; border:1px solid currentColor; opacity:.45; font-size:9.5px; line-height:1; cursor:help; vertical-align:middle; user-select:none; flex:none; }
|
|
443
|
+
.dswfe-help:hover, .dswfe-help:focus-visible { opacity:.9; }
|
|
444
|
+
.dswfe-tip { position:fixed; z-index:2147483100; padding:8px 10px; border-radius:9px; background:#000 !important; background-color:#000 !important; color:#fff !important; border:1px solid rgba(255,255,255,.16); font-size:12px; line-height:18px; font-weight:400; text-align:left; white-space:normal; word-break:break-word; box-shadow:0 10px 28px rgba(0,0,0,.35); pointer-events:none; }
|
|
445
|
+
.dswfe-field-label { display:inline-flex; align-items:center; margin:10px 0 0; font-size:11px; opacity:.75; }
|
|
446
|
+
.dswfe-check { display:flex; flex-direction:row; align-items:center; gap:6px; font-size:12px; }
|
|
447
|
+
.dswfe-check input { margin:0; }
|
|
448
|
+
.dswfe-outline { display:flex; flex-direction:column; gap:2px; }
|
|
449
|
+
.dswfe-ovphase { display:flex; align-items:center; gap:6px; margin-top:8px; font-size:12px; font-weight:600; }
|
|
450
|
+
.dswfe-ovlink { display:flex; align-items:center; gap:8px; padding:2px 0 2px 10px; font-size:12.5px; }
|
|
451
|
+
.dswfe-ovno { flex:none; min-width:52px; color:var(--dsw-text-secondary, gray); font-variant-numeric:tabular-nums; }
|
|
452
|
+
.dswfe-ovname { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
453
|
+
.dswfe-ovkind { flex:none; margin-left:auto; font-size:11px; color:var(--dsw-text-secondary, gray); font-variant-numeric:tabular-nums; }
|
|
454
|
+
.dswfe-ovno { flex:none; min-width:56px; opacity:.6; font-size:11px; }
|
|
455
|
+
.dswfe-ovname { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
456
|
+
.dswfe-ovkind { flex:none; margin-left:auto; font-size:11px; color:var(--dsw-text-secondary, gray); font-variant-numeric:tabular-nums; }
|
|
457
|
+
.dswfe-artgroup { margin-bottom:4px; }
|
|
458
|
+
.dswfe-artrow { display:flex; gap:8px; align-items:center; width:100%; text-align:left; border:1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.2)); border-radius:8px; background:transparent; color:inherit; padding:6px 10px; margin:3px 0; cursor:pointer; font:inherit; font-size:12px; box-sizing:border-box; }
|
|
459
|
+
.dswfe-artrow:hover { background:var(--dsw-hover, rgba(128,128,128,.1)); border-color:var(--dsw-alias-border-l2, rgba(128,128,128,.35)); }
|
|
460
|
+
.dswfe-artrow[data-selected="true"] { background:var(--dsw-active, rgba(128,128,128,.16)); border-color:var(--dsw-alias-border-l2, rgba(128,128,128,.35)); }
|
|
461
|
+
.dswfe-mini[data-active="true"] { background:var(--dsw-active, rgba(128,128,128,.16)); }
|
|
462
|
+
.dswfe-pill { border-radius:999px; padding:2px 9px; font-size:10.5px; line-height:15px; white-space:nowrap; border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); }
|
|
463
|
+
.dswfe-pill[data-status="running"] { color:#d9822b; border-color:#d9822b; }
|
|
464
|
+
.dswfe-pill[data-status="queued"] { color:#3e63dd; border-color:#3e63dd; }
|
|
465
|
+
.dswfe-pill[data-status="awaiting"] { color:#c75050; border-color:#c75050; }
|
|
466
|
+
.dswfe-pill[data-status="paused"] { color:#b8860b; border-color:#b8860b; }
|
|
467
|
+
.dswfe-pill[data-status="done"] { color:#2e9e5b; border-color:#2e9e5b; }
|
|
468
|
+
.dswfe-pill[data-status="stopped"] { color:var(--dsw-text-secondary, gray); }
|
|
469
|
+
.dswfe-pill[data-status="failed"] { color:var(--dsw-alias-state-error, #c75050); border-color:var(--dsw-alias-state-error, #c75050); }
|
|
470
|
+
.dswfe-board { flex:1; min-width:0; overflow-y:auto; padding:16px 20px; box-sizing:border-box; }
|
|
471
|
+
.dswfe-runhead { display:flex; align-items:center; gap:10px; flex-wrap:wrap; margin-bottom:10px; }
|
|
472
|
+
.dswfe-break { border:1px solid var(--dsw-alias-state-error, #c75050); border-radius:10px; padding:10px 12px; margin:8px 0; display:flex; gap:8px; align-items:center; flex-wrap:wrap; }
|
|
473
|
+
.dswfe-linkcard { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:9px; padding:9px 11px; margin:6px 0; display:flex; flex-direction:column; gap:6px; }
|
|
474
|
+
.dswfe-linkcard[data-state="running"] { border-color:#d9822b; }
|
|
475
|
+
.dswfe-linkcard[data-state="done"] { opacity:.82; }
|
|
476
|
+
.dswfe-linkcard[data-state="gate_failed"] { border-color:var(--dsw-alias-state-error, #c75050); }
|
|
477
|
+
.dswfe-linktop { display:flex; align-items:center; gap:10px; flex-wrap:wrap; }
|
|
478
|
+
.dswfe-linktop .grow { flex:1; }
|
|
479
|
+
.dswfe-mini { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); background:transparent; color:inherit; border-radius:6px; padding:2px 7px; font:inherit; font-size:11px; cursor:pointer; white-space:nowrap; }
|
|
480
|
+
.dswfe-mini:hover { background:var(--dsw-hover, rgba(128,128,128,.12)); }
|
|
481
|
+
.dswfe-tail { max-height:180px; overflow:auto; margin:0; }
|
|
482
|
+
.dswfe-flowwrap { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:10px; background:var(--dsw-alias-bg-layer-2, rgba(128,128,128,.05)); overflow:auto; max-height:min(64vh, 640px); }
|
|
483
|
+
.dswfe-flowlegend { display:flex; gap:14px; flex-wrap:wrap; font-size:11px; color:var(--dsw-text-secondary, gray); margin:6px 2px 10px; align-items:center; }
|
|
484
|
+
.dswfe-flowlegend .sw { display:inline-block; width:26px; height:0; border-top:2px solid; margin-right:5px; vertical-align:middle; }
|
|
485
|
+
.dswfe-flowlegend .sw.fwd { border-color:var(--dsw-text-secondary, #94a3b8); }
|
|
486
|
+
.dswfe-flowlegend .sw.jump { border-color:#22c55e; }
|
|
487
|
+
.dswfe-flowlegend .sw.fail { border-color:var(--dsw-alias-state-error, #ef4444); border-top-width:2px; border-top-style:dashed; }
|
|
488
|
+
.dswfe-form { flex:1; min-height:0; overflow-y:auto; padding:12px 16px; box-sizing:border-box; }
|
|
489
|
+
/* 画布编辑器:左画布(阶段泳道+环节节点)+ 右属性面板 */
|
|
490
|
+
.dswfe-canvas { flex:1; min-height:0; display:flex; overflow:hidden; }
|
|
491
|
+
.dswfe-canvas-left { flex:1; min-width:0; overflow:auto; padding:14px; box-sizing:border-box; }
|
|
492
|
+
.dswfe-canvas-bar { display:flex; align-items:center; gap:10px; margin-bottom:12px; position:sticky; top:0; z-index:2; background:var(--dsw-alias-bg-base, inherit); padding:4px 0; }
|
|
493
|
+
.dswfe-canvas-hint { font-size:11px; opacity:.55; }
|
|
494
|
+
.dswfe-canvas-empty { border:1px dashed var(--dsw-alias-border-l2, rgba(128,128,128,.35)); border-radius:12px; padding:32px; text-align:center; opacity:.6; }
|
|
495
|
+
.dswfe-lane { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:12px; margin:0 0 12px; background:var(--dsw-alias-bg-layer-1, transparent); overflow:hidden; }
|
|
496
|
+
.dswfe-lane[data-sel="true"] { border-color:var(--dsw-alias-brand-primary, #d9822b); box-shadow:0 0 0 1px var(--dsw-alias-brand-primary, #d9822b); }
|
|
497
|
+
.dswfe-lane-head { display:flex; align-items:center; gap:8px; padding:8px 12px; cursor:pointer; background:var(--dsw-alias-bg-layer-2, rgba(128,128,128,.06)); user-select:none; }
|
|
498
|
+
.dswfe-lane-no { color:#fff; font-size:10px; font-weight:700; border-radius:8px; padding:2px 7px; font-family:ui-monospace, monospace; }
|
|
499
|
+
.dswfe-lane-name { font-weight:600; font-size:13px; }
|
|
500
|
+
.dswfe-lane-id { font-family:ui-monospace, monospace; font-size:11px; opacity:.5; }
|
|
501
|
+
.dswfe-lane-count { margin-left:auto; font-size:11px; opacity:.55; }
|
|
502
|
+
.dswfe-lane-body { display:flex; flex-wrap:wrap; gap:10px; align-items:center; padding:12px; }
|
|
503
|
+
.dswfe-node { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.35)); border-radius:10px; padding:8px 12px; cursor:pointer; min-width:130px; max-width:210px; background:var(--dsw-alias-bg-base, transparent); user-select:none; }
|
|
504
|
+
.dswfe-node:hover { border-color:var(--dsw-alias-brand-primary, #d9822b); }
|
|
505
|
+
.dswfe-node[data-sel="true"] { border-color:var(--dsw-alias-brand-primary, #d9822b); box-shadow:0 0 0 1px var(--dsw-alias-brand-primary, #d9822b); }
|
|
506
|
+
.dswfe-node-name { font-weight:600; font-size:12.5px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
507
|
+
.dswfe-node-meta { display:flex; gap:6px; align-items:center; margin-top:3px; }
|
|
508
|
+
.dswfe-node-id { font-family:ui-monospace, monospace; font-size:10.5px; opacity:.5; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
509
|
+
.dswfe-node-badge { font-size:10.5px; color:#b8860b; white-space:nowrap; }
|
|
510
|
+
.dswfe-node-arrow { opacity:.45; font-size:14px; }
|
|
511
|
+
.dswfe-node-add { border:1px dashed var(--dsw-alias-border-l2, rgba(128,128,128,.4)); background:transparent; color:inherit; border-radius:10px; min-width:34px; height:38px; font-size:16px; cursor:pointer; opacity:.65; }
|
|
512
|
+
.dswfe-node-add:hover { opacity:1; border-color:var(--dsw-alias-brand-primary, #d9822b); }
|
|
513
|
+
.dswfe-props { width:400px; min-width:340px; flex:none; border-left:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); overflow-y:auto; padding:12px 16px; box-sizing:border-box; }
|
|
514
|
+
/* 模型两极下拉 + 技能多选下拉 */
|
|
515
|
+
.dswfe-modelrow { display:flex; gap:6px; }
|
|
516
|
+
.dswfe-native-sel { flex:1; min-width:0; border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); background:var(--dsw-alias-bg-layer-2, transparent); color:inherit; border-radius:8px; padding:6px 8px; font:inherit; font-size:12.5px; }
|
|
517
|
+
.dswfe-native-sel:disabled { opacity:.45; }
|
|
518
|
+
.dswfe-selbtn { width:100%; display:flex; align-items:center; gap:6px; text-align:left; border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); background:var(--dsw-alias-bg-layer-2, transparent); color:inherit; border-radius:8px; padding:6px 10px; font:inherit; font-size:12.5px; cursor:pointer; }
|
|
519
|
+
.dswfe-selbtn .dswfe-selph { opacity:.45; }
|
|
520
|
+
.dswfe-selbtn span:first-child { flex:1; min-width:0; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
521
|
+
.dswfe-selcar { opacity:.5; }
|
|
522
|
+
.dswfe-skillpick { position:relative; }
|
|
523
|
+
.dswfe-skillpop { position:absolute; left:0; right:0; top:calc(100% + 4px); z-index:30; background:var(--dsw-alias-bg-overlay, var(--dsw-alias-bg-layer-1, #252830)); color:var(--dsw-alias-label-primary, inherit); border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:10px; box-shadow:0 8px 30px rgba(0,0,0,.25); max-height:260px; overflow-y:auto; padding:4px; }
|
|
524
|
+
.dswfe-skillrow { display:flex; align-items:center; gap:8px; padding:6px 8px; border-radius:6px; cursor:pointer; font-size:12.5px; }
|
|
525
|
+
.dswfe-skillrow:hover { background:var(--dsw-alias-bg-layer-2, rgba(128,128,128,.12)); }
|
|
526
|
+
.dswfe-skillrow input { flex:none; }
|
|
527
|
+
.dswfe-skillname { font-weight:600; white-space:nowrap; }
|
|
528
|
+
.dswfe-skilldesc { opacity:.55; font-size:11px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
|
|
529
|
+
.dswfe-skillnone { padding:10px; opacity:.55; font-size:12px; text-align:center; }
|
|
530
|
+
.dswfe-skillclear { width:100%; border:none; border-top:1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.2)); background:transparent; color:inherit; padding:7px; font:inherit; font-size:12px; cursor:pointer; opacity:.7; }
|
|
531
|
+
.dswfe-skillclear:hover { opacity:1; }
|
|
532
|
+
.dswfe-fsec { margin:0 0 14px; }
|
|
533
|
+
.dswfe-fsec h4 { margin:0 0 8px; font-size:13px; }
|
|
534
|
+
.dswfe-fgrid { display:grid; grid-template-columns:repeat(auto-fit, minmax(180px, 1fr)); gap:8px 12px; }
|
|
535
|
+
.dswfe-fphase { border:1px solid var(--dsw-alias-border-l2, rgba(128,128,128,.3)); border-radius:10px; padding:10px 12px; margin:8px 0; background:var(--dsw-alias-bg-layer-1, transparent); }
|
|
536
|
+
.dswfe-flink { border:1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.2)); border-radius:8px; padding:8px 10px; margin:8px 0; background:var(--dsw-alias-bg-layer-2, rgba(128,128,128,.04)); }
|
|
537
|
+
.dswfe-flink .dswfe-field { margin:6px 0; }
|
|
538
|
+
.dswfe-fgates { border-top:1px dashed var(--dsw-alias-border-l1, rgba(128,128,128,.2)); padding-top:6px; }
|
|
539
|
+
`
|
|
540
|
+
|
|
541
|
+
let stylesInjected = false
|
|
542
|
+
function ensureStyles() {
|
|
543
|
+
if (stylesInjected || typeof document === 'undefined') return
|
|
544
|
+
const el = document.createElement('style')
|
|
545
|
+
el.id = 'dswfe-styles'
|
|
546
|
+
el.textContent = STYLE
|
|
547
|
+
document.head.appendChild(el)
|
|
548
|
+
stylesInjected = true
|
|
549
|
+
}
|
|
550
|
+
|
|
551
|
+
// ── API 帮手 ─────────────────────────────────────────────────────────────
|
|
552
|
+
|
|
553
|
+
async function api(path, opts) {
|
|
554
|
+
const res = await fetch(API + path, {
|
|
555
|
+
method: (opts && opts.method) || 'GET',
|
|
556
|
+
headers: opts && opts.body ? { 'content-type': 'application/json' } : undefined,
|
|
557
|
+
body: opts && opts.body ? JSON.stringify(opts.body) : undefined,
|
|
558
|
+
signal: AbortSignal.timeout ? AbortSignal.timeout(30000) : undefined,
|
|
559
|
+
})
|
|
560
|
+
let data = {}
|
|
561
|
+
try { data = await res.json() } catch { /* 空响应 */ }
|
|
562
|
+
if (!res.ok) {
|
|
563
|
+
const e = new Error(data.error || (res.statusText + ' (' + res.status + ')'))
|
|
564
|
+
e.code = data.code
|
|
565
|
+
e.status = res.status
|
|
566
|
+
e.data = data
|
|
567
|
+
throw e
|
|
568
|
+
}
|
|
569
|
+
return data
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// 旧包名时代的面板偏好存在 dsh-prc:prefs:新键缺失时读一次旧键并写回新键
|
|
573
|
+
function loadPrefs() {
|
|
574
|
+
let raw = null
|
|
575
|
+
try { raw = localStorage.getItem(PREFS_KEY) } catch { /* 隐身模式等 */ }
|
|
576
|
+
if (!raw) {
|
|
577
|
+
try {
|
|
578
|
+
const legacy = localStorage.getItem('dsh-prc:prefs')
|
|
579
|
+
if (legacy) { raw = legacy; localStorage.setItem(PREFS_KEY, legacy) }
|
|
580
|
+
} catch { /* 同上 */ }
|
|
581
|
+
}
|
|
582
|
+
try { return JSON.parse(raw) || {} } catch { return {} }
|
|
583
|
+
}
|
|
584
|
+
function savePrefs(prefs) {
|
|
585
|
+
try { localStorage.setItem(PREFS_KEY, JSON.stringify(prefs)) } catch { /* 隐身模式等 */ }
|
|
586
|
+
}
|
|
587
|
+
|
|
588
|
+
// ── Controller ───────────────────────────────────────────────────────────
|
|
589
|
+
|
|
590
|
+
function initialState() {
|
|
591
|
+
const prefs = loadPrefs()
|
|
592
|
+
return {
|
|
593
|
+
loaded: false, revision: 0, roots: { user: '', bundled: '' }, processes: [], lastError: undefined, error: undefined,
|
|
594
|
+
panelOpen: false,
|
|
595
|
+
selectedId: prefs.selectedId, tab: prefs.tab || 'overview',
|
|
596
|
+
item: undefined, itemLoading: false, highlightLine: undefined,
|
|
597
|
+
search: '', filters: Object.assign({ source: 'all', category: '', complexity: '' }, prefs.filters || {}),
|
|
598
|
+
sortBy: prefs.sortBy || 'default',
|
|
599
|
+
editor: null,
|
|
600
|
+
dialog: null,
|
|
601
|
+
toast: null,
|
|
602
|
+
settings: undefined,
|
|
603
|
+
view: prefs.view || 'lib',
|
|
604
|
+
runs: { revision: -1, list: [] },
|
|
605
|
+
runId: prefs.runId, run: undefined, runLoading: false, runError: null,
|
|
606
|
+
}
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
class Controller {
|
|
610
|
+
constructor() {
|
|
611
|
+
this.state = initialState()
|
|
612
|
+
this.subs = new Set()
|
|
613
|
+
this.es = null
|
|
614
|
+
this.seenRevision = undefined
|
|
615
|
+
this.seenRunsRevision = undefined
|
|
616
|
+
this.refreshInFlight = null
|
|
617
|
+
this.validateTimer = null
|
|
618
|
+
this.toastTimer = null
|
|
619
|
+
this.disposed = false
|
|
620
|
+
}
|
|
621
|
+
getSnapshot() { return this.state }
|
|
622
|
+
subscribe(fn) { this.subs.add(fn); return () => { this.subs.delete(fn) } }
|
|
623
|
+
setState(patch) { this.state = { ...this.state, ...patch }; this.emit() }
|
|
624
|
+
emit() { if (this.disposed) return; for (const fn of this.subs) { try { fn() } catch {} } }
|
|
625
|
+
persist() {
|
|
626
|
+
const s = this.state
|
|
627
|
+
savePrefs({ selectedId: s.selectedId, tab: s.tab, filters: s.filters, sortBy: s.sortBy, view: s.view, runId: s.runId })
|
|
628
|
+
}
|
|
629
|
+
toast(text, kind) {
|
|
630
|
+
this.setState({ toast: { text, kind: kind || 'ok' } })
|
|
631
|
+
if (this.toastTimer) clearTimeout(this.toastTimer)
|
|
632
|
+
this.toastTimer = setTimeout(() => { if (!this.disposed) this.setState({ toast: null }) }, 2600)
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
start() {
|
|
636
|
+
void this.refresh()
|
|
637
|
+
try { this.connectStream() } catch { /* 实时通道不可用:仅手动刷新 */ }
|
|
638
|
+
}
|
|
639
|
+
connectStream() {
|
|
640
|
+
const onEvent = (event, payload) => {
|
|
641
|
+
if (event !== 'hello' && event !== 'change') return
|
|
642
|
+
try { this.seenRevision = payload.revision; this.seenRunsRevision = payload.runsRevision } catch (e) {}
|
|
643
|
+
void this.refresh()
|
|
644
|
+
}
|
|
645
|
+
// 枢纽优先(dsh-plugin-kit ≥0.4 的共享单连接);帧形状 {event, data}
|
|
646
|
+
if (typeof PluginKit !== 'undefined' && typeof PluginKit.connectEvents === 'function') {
|
|
647
|
+
this.hubOff = PluginKit.connectEvents('dsh-workflow-execute', (data) => {
|
|
648
|
+
if (data && typeof data.event === 'string') onEvent(data.event, data.data)
|
|
649
|
+
}, () => {})
|
|
650
|
+
if (this.hubOff) return
|
|
651
|
+
}
|
|
652
|
+
const es = new EventSource(API + '/events')
|
|
653
|
+
this.es = es
|
|
654
|
+
es.addEventListener('hello', (e) => {
|
|
655
|
+
let d; try { d = JSON.parse(e.data) } catch (err) { return }
|
|
656
|
+
onEvent('hello', d)
|
|
657
|
+
})
|
|
658
|
+
es.addEventListener('change', (e) => {
|
|
659
|
+
let d; try { d = JSON.parse(e.data) } catch (err) { return }
|
|
660
|
+
onEvent('change', d)
|
|
661
|
+
})
|
|
662
|
+
es.onerror = () => { /* EventSource 自动重连;hello 里对齐 gap */ }
|
|
663
|
+
}
|
|
664
|
+
async refresh() {
|
|
665
|
+
if (this.refreshInFlight) return this.refreshInFlight
|
|
666
|
+
this.refreshInFlight = (async () => {
|
|
667
|
+
try {
|
|
668
|
+
let snap
|
|
669
|
+
// revision 追赶:变更帧落在请求飞行中时,旧响应可能落后(taskboard S16)
|
|
670
|
+
for (let round = 0; round < 3; round++) {
|
|
671
|
+
const [stateRsp, runsRsp] = await Promise.all([api('/state'), api('/runs')])
|
|
672
|
+
snap = stateRsp
|
|
673
|
+
const keep = this.state.selectedId && snap.processes.some((p) => p.id === this.state.selectedId)
|
|
674
|
+
? this.state.selectedId : undefined
|
|
675
|
+
this.setState({
|
|
676
|
+
loaded: true, revision: snap.revision, roots: snap.roots, processes: snap.processes,
|
|
677
|
+
lastError: snap.lastError, error: undefined, selectedId: keep,
|
|
678
|
+
runs: { revision: runsRsp.revision, list: runsRsp.runs },
|
|
679
|
+
})
|
|
680
|
+
const libCaughtUp = this.seenRevision === undefined || snap.revision >= this.seenRevision
|
|
681
|
+
const runsCaughtUp = this.seenRunsRevision === undefined || runsRsp.revision >= this.seenRunsRevision
|
|
682
|
+
if (libCaughtUp && runsCaughtUp) break
|
|
683
|
+
}
|
|
684
|
+
// 选中的运行已不在台账里 → 清选中,避免看板停留在「加载中」
|
|
685
|
+
if (this.state.runId && !this.state.runs.list.some((r) => r.id === this.state.runId)) {
|
|
686
|
+
this.setState({ runId: null, run: undefined, runLoading: false, runError: null })
|
|
687
|
+
this.persist()
|
|
688
|
+
}
|
|
689
|
+
// 运行看板:活跃运行随帧刷新;静态运行只取一次
|
|
690
|
+
if (this.state.view === 'exec' && this.state.runId) {
|
|
691
|
+
const active = ['queued', 'running', 'awaiting'].includes((this.state.run && this.state.run.status) || '')
|
|
692
|
+
if (active || !this.state.run) void this.loadRun(this.state.runId)
|
|
693
|
+
}
|
|
694
|
+
// 选中项跟随外部改动:非编辑态自动刷新;编辑态不打断(保存时乐观锁兜底)
|
|
695
|
+
if (this.state.selectedId && !this.state.itemLoading) {
|
|
696
|
+
if (this.state.editor && this.state.editor.id === this.state.selectedId) { /* 编辑中:跳过 */ }
|
|
697
|
+
else if (this.state.item && this.state.item.meta.id === this.state.selectedId) {
|
|
698
|
+
const fresh = snap.processes.find((p) => p.id === this.state.selectedId)
|
|
699
|
+
if (fresh && this.state.item.meta.hash !== fresh.hash) void this.loadItem(this.state.selectedId)
|
|
700
|
+
} else void this.loadItem(this.state.selectedId)
|
|
701
|
+
}
|
|
702
|
+
} catch (error) {
|
|
703
|
+
this.setState({ error: String(error && error.message || error) })
|
|
704
|
+
} finally {
|
|
705
|
+
this.refreshInFlight = null
|
|
706
|
+
}
|
|
707
|
+
})()
|
|
708
|
+
return this.refreshInFlight
|
|
709
|
+
}
|
|
710
|
+
dispose() {
|
|
711
|
+
this.disposed = true
|
|
712
|
+
if (this.hubOff) { try { this.hubOff() } catch {} }
|
|
713
|
+
if (this.es) { try { this.es.close() } catch {} }
|
|
714
|
+
if (this.validateTimer) clearTimeout(this.validateTimer)
|
|
715
|
+
if (this.toastTimer) clearTimeout(this.toastTimer)
|
|
716
|
+
this.subs.clear()
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// ── 面板 ──
|
|
720
|
+
openPanel() {
|
|
721
|
+
this.setState({ panelOpen: true })
|
|
722
|
+
try { document.dispatchEvent(new CustomEvent(ACTIVATE_EVENT, { detail: PANEL_NAME })) } catch {}
|
|
723
|
+
if (!this.state.loaded) void this.refresh()
|
|
724
|
+
// 兜底:视图容器未能在中栏放置(壳层退化)→ 450ms 后强制挂 body 全屏,
|
|
725
|
+
// 保证侧栏入口点击永远有响应
|
|
726
|
+
setTimeout(() => {
|
|
727
|
+
if (this.disposed) return
|
|
728
|
+
const s = this.getSnapshot()
|
|
729
|
+
if (s.panelOpen && typeof document !== 'undefined' && !document.querySelector('[data-dswfe-panel]')) {
|
|
730
|
+
if (prcView) prcView.ensure(true)
|
|
731
|
+
}
|
|
732
|
+
}, 450)
|
|
733
|
+
}
|
|
734
|
+
closePanel() { this.setState({ panelOpen: false, dialog: null }) }
|
|
735
|
+
togglePanel() { if (this.state.panelOpen) this.closePanel(); else this.openPanel() }
|
|
736
|
+
|
|
737
|
+
// ── 选择 / 筛选 ──
|
|
738
|
+
select(id) {
|
|
739
|
+
if (!id) return
|
|
740
|
+
const ed = this.state.editor
|
|
741
|
+
if (ed && ed.id !== id) {
|
|
742
|
+
// 编辑中切换:脏了先确认,干净直接关编辑器
|
|
743
|
+
if (ed.dirty) {
|
|
744
|
+
this.setState({ dialog: { type: 'confirm', message: this.tr('dirtyGuard'), danger: true, yes: 'discard', onYes: () => { this.setState({ editor: null, dialog: null }); this.select(id) } } })
|
|
745
|
+
return
|
|
746
|
+
}
|
|
747
|
+
this.setState({ editor: null })
|
|
748
|
+
}
|
|
749
|
+
this.setState({ selectedId: id, item: undefined, itemLoading: true, highlightLine: undefined })
|
|
750
|
+
this.persist()
|
|
751
|
+
void this.loadItem(id)
|
|
752
|
+
}
|
|
753
|
+
async loadItem(id) {
|
|
754
|
+
try {
|
|
755
|
+
const item = await api('/item?id=' + encodeURIComponent(id))
|
|
756
|
+
if (this.state.selectedId !== id) return
|
|
757
|
+
this.setState({ item, itemLoading: false })
|
|
758
|
+
} catch (error) {
|
|
759
|
+
if (this.state.selectedId === id) this.setState({ itemLoading: false, error: String(error && error.message || error) })
|
|
760
|
+
}
|
|
761
|
+
}
|
|
762
|
+
/** 跳到某个会话(AI 生成任务的会话):客户端 sessions 服务 open(id),逐次懒解析。 */
|
|
763
|
+
openSession(sessionId) {
|
|
764
|
+
const svc = this.sessionsSvc
|
|
765
|
+
if (!svc || typeof svc.open !== 'function') { this.toast(this.tr('sessionUnavailable'), 'err'); return }
|
|
766
|
+
try { svc.open(sessionId); this.closePanel() } catch (error) { this.toast(String(error && error.message || error), 'err') }
|
|
767
|
+
}
|
|
768
|
+
tr(key, vars) { return this.t ? this.t(key, vars) : (ZH[key] || key) }
|
|
769
|
+
setTab(tab) { this.setState({ tab }); this.persist() }
|
|
770
|
+
setSearch(search) { this.setState({ search }) }
|
|
771
|
+
setFilter(key, value) {
|
|
772
|
+
const filters = { ...this.state.filters, [key]: value }
|
|
773
|
+
this.setState({ filters }); this.persist()
|
|
774
|
+
}
|
|
775
|
+
setSortBy(sortBy) { this.setState({ sortBy }); this.persist() }
|
|
776
|
+
|
|
777
|
+
// ── 编辑器 ──
|
|
778
|
+
openEditor(payload) {
|
|
779
|
+
this.setState({
|
|
780
|
+
editor: {
|
|
781
|
+
mode: payload.mode, id: payload.id || null, name: payload.name || '', dir: payload.dir || '',
|
|
782
|
+
text: payload.text || '', baseHash: payload.baseHash || null, original: payload.text || '',
|
|
783
|
+
dirty: false, diagnostics: payload.diagnostics || null, busy: false, conflict: null, error: null,
|
|
784
|
+
},
|
|
785
|
+
})
|
|
786
|
+
this.scheduleValidate(50)
|
|
787
|
+
}
|
|
788
|
+
async editSelected() {
|
|
789
|
+
const item = this.state.item
|
|
790
|
+
if (!item) return
|
|
791
|
+
const t0 = Date.now()
|
|
792
|
+
this.openEditor({ mode: 'update', id: item.meta.id, text: item.yaml, baseHash: item.hash, diagnostics: item.diagnostics })
|
|
793
|
+
}
|
|
794
|
+
async createBlank(name, dir, displayName) {
|
|
795
|
+
try {
|
|
796
|
+
const q = '?name=' + encodeURIComponent(name) + (displayName ? '&displayName=' + encodeURIComponent(displayName) : '')
|
|
797
|
+
const { yaml } = await api('/skeleton' + q)
|
|
798
|
+
this.setState({ dialog: null })
|
|
799
|
+
this.openEditor({ mode: 'create', name, dir, text: yaml })
|
|
800
|
+
} catch (error) { this.toast(String(error && error.message || error), 'err') }
|
|
801
|
+
}
|
|
802
|
+
setEditorText(text) {
|
|
803
|
+
const ed = this.state.editor
|
|
804
|
+
if (!ed) return
|
|
805
|
+
this.setState({ editor: { ...ed, text, dirty: text !== ed.original, conflict: null, validatedAt: null } })
|
|
806
|
+
this.scheduleValidate()
|
|
807
|
+
}
|
|
808
|
+
scheduleValidate(delay) {
|
|
809
|
+
if (this.validateTimer) clearTimeout(this.validateTimer)
|
|
810
|
+
this.validateTimer = setTimeout(() => { this.validateTimer = null; void this.validateEditor(true) }, delay === undefined ? 400 : delay)
|
|
811
|
+
}
|
|
812
|
+
async validateEditor(silent) {
|
|
813
|
+
const ed = this.state.editor
|
|
814
|
+
if (!ed || ed.text.trim() === '') return
|
|
815
|
+
try {
|
|
816
|
+
const d = await api('/validate', { method: 'POST', body: { yaml: ed.text } })
|
|
817
|
+
const cur = this.state.editor
|
|
818
|
+
if (cur && cur.text === ed.text) {
|
|
819
|
+
this.setState({ editor: { ...cur, diagnostics: { errors: d.errors, warnings: d.warnings }, validatedAt: Date.now() } })
|
|
820
|
+
}
|
|
821
|
+
// 自动校验(防抖后逐字触发)不弹提示,结果只体现在状态栏与诊断区;
|
|
822
|
+
// 只有手动点「校验」才 toast,避免每输入一个字就冒一个气泡。
|
|
823
|
+
if (!silent) {
|
|
824
|
+
const errors = (d.errors || []).length
|
|
825
|
+
const warnings = (d.warnings || []).length
|
|
826
|
+
this.toast(errors === 0 && warnings === 0
|
|
827
|
+
? this.tr('validateOk')
|
|
828
|
+
: this.tr('validateResult', { e: errors, w: warnings }), errors > 0 ? 'err' : undefined)
|
|
829
|
+
}
|
|
830
|
+
} catch (error) {
|
|
831
|
+
if (!silent) this.toast(String((error && error.message) || error), 'err')
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
async saveEditor(force) {
|
|
835
|
+
const ed = this.state.editor
|
|
836
|
+
if (!ed || ed.busy) return
|
|
837
|
+
this.setState({ editor: { ...ed, busy: true, error: null } })
|
|
838
|
+
try {
|
|
839
|
+
let body
|
|
840
|
+
if (ed.mode === 'create') body = { mode: 'create', name: ed.name, dir: ed.dir, yaml: ed.text }
|
|
841
|
+
else body = { mode: 'update', id: ed.id, yaml: ed.text, baseHash: force && ed.conflict ? ed.conflict.currentHash : ed.baseHash }
|
|
842
|
+
const result = await api('/save', { method: 'POST', body })
|
|
843
|
+
// 保存后留在编辑器:用落盘内容刷新文本与基线,清脏标、保留画布选中与 form/yaml 子模式
|
|
844
|
+
let item = null
|
|
845
|
+
try { item = await api('/item?id=' + encodeURIComponent(result.id)) } catch {}
|
|
846
|
+
const cur = this.state.editor || ed
|
|
847
|
+
this.setState({
|
|
848
|
+
dialog: null,
|
|
849
|
+
selectedId: result.id,
|
|
850
|
+
item: item || this.state.item,
|
|
851
|
+
itemLoading: false,
|
|
852
|
+
editor: Object.assign({}, cur, {
|
|
853
|
+
mode: 'update', id: result.id, name: ed.name, dir: ed.dir,
|
|
854
|
+
text: item ? item.yaml : cur.text,
|
|
855
|
+
original: item ? item.yaml : cur.text,
|
|
856
|
+
baseHash: item ? item.hash : cur.baseHash,
|
|
857
|
+
dirty: false, busy: false, conflict: null, error: null,
|
|
858
|
+
diagnostics: item ? item.diagnostics : cur.diagnostics,
|
|
859
|
+
}),
|
|
860
|
+
})
|
|
861
|
+
void this.refresh()
|
|
862
|
+
this.toast(force ? this.tr('toastForceSaved') : this.tr('toastSaved'))
|
|
863
|
+
} catch (error) {
|
|
864
|
+
const cur = this.state.editor
|
|
865
|
+
if (!cur) return
|
|
866
|
+
if (error.code === 'conflict') this.setState({ editor: { ...cur, busy: false, conflict: { currentHash: error.data && error.data.currentHash }, error: null } })
|
|
867
|
+
else if (error.data && error.data.diagnostics) this.setState({ editor: { ...cur, busy: false, diagnostics: error.data.diagnostics, error: String(error.message) } })
|
|
868
|
+
else this.setState({ editor: { ...cur, busy: false, error: String(error && error.message || error) } })
|
|
869
|
+
}
|
|
870
|
+
}
|
|
871
|
+
async reloadEditor() {
|
|
872
|
+
const ed = this.state.editor
|
|
873
|
+
if (!ed || !ed.id) return
|
|
874
|
+
try {
|
|
875
|
+
const item = await api('/item?id=' + encodeURIComponent(ed.id))
|
|
876
|
+
this.setState({ editor: { ...ed, text: item.yaml, original: item.yaml, baseHash: item.hash, dirty: false, conflict: null, diagnostics: item.diagnostics, error: null } })
|
|
877
|
+
} catch (error) { this.toast(String(error && error.message || error), 'err') }
|
|
878
|
+
}
|
|
879
|
+
requestCloseEditor() {
|
|
880
|
+
const ed = this.state.editor
|
|
881
|
+
if (ed && ed.dirty) this.setState({ dialog: { type: 'confirm', message: this.tr('dirtyGuard'), danger: true, yes: 'discard', onYes: () => this.setState({ editor: null, dialog: null }) } })
|
|
882
|
+
else this.setState({ editor: null })
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
// ── 动作 ──
|
|
886
|
+
async copyProcess(fromId, name, dir) {
|
|
887
|
+
try {
|
|
888
|
+
const result = await api('/save', { method: 'POST', body: { mode: 'copy', fromId, name, dir } })
|
|
889
|
+
this.setState({ dialog: null })
|
|
890
|
+
this.select(result.id)
|
|
891
|
+
void this.refresh()
|
|
892
|
+
this.toast(this.tr('toastCopied'))
|
|
893
|
+
} catch (error) { this.toast(String(error && error.message || error), 'err') }
|
|
894
|
+
}
|
|
895
|
+
async renameProcess(id, newName) {
|
|
896
|
+
try {
|
|
897
|
+
const result = await api('/rename', { method: 'POST', body: { id, newName } })
|
|
898
|
+
this.setState({ dialog: null })
|
|
899
|
+
this.select(result.id || id)
|
|
900
|
+
void this.refresh()
|
|
901
|
+
this.toast(this.tr('toastRenamed'))
|
|
902
|
+
} catch (error) { this.toast(String(error && error.message || error), 'err') }
|
|
903
|
+
}
|
|
904
|
+
async removeProcess(id) {
|
|
905
|
+
try {
|
|
906
|
+
await api('/delete', { method: 'POST', body: { id } })
|
|
907
|
+
this.setState({ dialog: null, selectedId: undefined, item: undefined, editor: null })
|
|
908
|
+
await this.refresh()
|
|
909
|
+
this.toast(this.tr('toastTrashed'))
|
|
910
|
+
} catch (error) { this.toast(String(error && error.message || error), 'err') }
|
|
911
|
+
}
|
|
912
|
+
async importFiles(files, overwrite) {
|
|
913
|
+
const results = await api('/import', { method: 'POST', body: { files, overwrite } }).then((d) => d.results)
|
|
914
|
+
await this.refresh()
|
|
915
|
+
return results
|
|
916
|
+
}
|
|
917
|
+
async loadSettings() {
|
|
918
|
+
const d = await api('/settings')
|
|
919
|
+
this.setState({ settings: d.settings })
|
|
920
|
+
return d.settings
|
|
921
|
+
}
|
|
922
|
+
async saveSettings(patch) {
|
|
923
|
+
const d = await api('/settings', { method: 'POST', body: patch })
|
|
924
|
+
this.setState({ settings: d.settings })
|
|
925
|
+
await this.refresh()
|
|
926
|
+
return d.settings
|
|
927
|
+
}
|
|
928
|
+
aiRun(prompt) { return api('/ai-generate', { method: 'POST', body: { prompt } }).then((d) => d.jobId) }
|
|
929
|
+
aiPoll(jobId) { return api('/jobs?id=' + encodeURIComponent(jobId)) }
|
|
930
|
+
|
|
931
|
+
/**
|
|
932
|
+
* @ 给 agent:把工作流文件以 @绝对路径 引用进当前会话的 composer(file-share 同款
|
|
933
|
+
* 双形态写入 + 剪贴板兜底),用户接着输入修改要求发送即可——agent 会用
|
|
934
|
+
* workflow_get/workflow_validate/workflow_save 工具完成修改。
|
|
935
|
+
*/
|
|
936
|
+
atAgent(meta) {
|
|
937
|
+
const root = meta.source === 'user' ? this.state.roots.user : this.state.roots.bundled
|
|
938
|
+
const abs = (root || '').replace(/\/+$/, '') + '/' + meta.relPath
|
|
939
|
+
const hint = meta.source === 'bundled' ? this.tr('atAgentBundledHint') : ''
|
|
940
|
+
const text = '@' + abs + ' ' + hint
|
|
941
|
+
const result = insertComposerText(text)
|
|
942
|
+
this.closePanel()
|
|
943
|
+
if (result === 'ok') this.toast(this.tr('atInserted'))
|
|
944
|
+
else this.toast(this.tr('atCopied'), 'err')
|
|
945
|
+
}
|
|
946
|
+
|
|
947
|
+
// ── 执行视图(v0.2)──
|
|
948
|
+
setView(view) { this.setState({ view }); this.persist() }
|
|
949
|
+
selectRun(id) {
|
|
950
|
+
if (!id) return
|
|
951
|
+
this.setState({ runId: id, run: undefined, runLoading: true })
|
|
952
|
+
this.persist()
|
|
953
|
+
void this.loadRun(id)
|
|
954
|
+
}
|
|
955
|
+
async loadRun(id) {
|
|
956
|
+
try {
|
|
957
|
+
const d = await api('/run?id=' + encodeURIComponent(id))
|
|
958
|
+
if (this.state.runId !== id) return
|
|
959
|
+
this.setState({ run: d.run, runLoading: false, runError: null })
|
|
960
|
+
} catch (error) {
|
|
961
|
+
if (this.state.runId !== id) return
|
|
962
|
+
const msg = String(error && error.message || error)
|
|
963
|
+
// 台账里已经没有这条运行(已删除/被清理):清掉选中,别让看板永远停在「加载中」
|
|
964
|
+
if (error && error.code === 'not_found') {
|
|
965
|
+
this.setState({ runId: null, run: undefined, runLoading: false, runError: null })
|
|
966
|
+
this.persist()
|
|
967
|
+
this.toast(msg, 'err')
|
|
968
|
+
return
|
|
969
|
+
}
|
|
970
|
+
this.setState({ runLoading: false, runError: msg, error: msg })
|
|
971
|
+
}
|
|
972
|
+
}
|
|
973
|
+
async loadLinkFiles(runId, linkId) {
|
|
974
|
+
const d = await api('/run-link-files?run=' + encodeURIComponent(runId) + '&link=' + encodeURIComponent(linkId))
|
|
975
|
+
return d.files || []
|
|
976
|
+
}
|
|
977
|
+
async loadArtifact(runId, path) {
|
|
978
|
+
const d = await api('/run-file?run=' + encodeURIComponent(runId) + '&path=' + encodeURIComponent(path))
|
|
979
|
+
return d.file
|
|
980
|
+
}
|
|
981
|
+
async runAction(action, body) {
|
|
982
|
+
const d = await api('/run-action', { method: 'POST', body: { action, ...body } })
|
|
983
|
+
if (this.state.runId === d.run.id) void this.loadRun(d.run.id)
|
|
984
|
+
void this.refresh()
|
|
985
|
+
return d.run
|
|
986
|
+
}
|
|
987
|
+
/** 删除一条已结束的运行台账(服务端只允许删除终态)。 */
|
|
988
|
+
async deleteRun(id) {
|
|
989
|
+
try {
|
|
990
|
+
await api('/run-delete', { method: 'POST', body: { id } })
|
|
991
|
+
if (this.state.runId === id) this.setState({ runId: null, run: undefined })
|
|
992
|
+
this.persist()
|
|
993
|
+
this.toast(this.tr('delete'))
|
|
994
|
+
void this.refresh()
|
|
995
|
+
} catch (error) {
|
|
996
|
+
// 以前静默吞掉:接口报错时按钮看着像没生效,这里把原因显出来
|
|
997
|
+
this.toast(String((error && error.message) || error), 'err')
|
|
998
|
+
}
|
|
999
|
+
}
|
|
1000
|
+
async createRun(body) {
|
|
1001
|
+
const d = await api('/run-create', { method: 'POST', body })
|
|
1002
|
+
this.setState({ dialog: null, view: 'exec', runId: d.run.id, run: undefined, runLoading: true })
|
|
1003
|
+
this.persist()
|
|
1004
|
+
void this.loadRun(d.run.id)
|
|
1005
|
+
this.toast(this.tr('runStarted'))
|
|
1006
|
+
return d.run
|
|
1007
|
+
}
|
|
1008
|
+
}
|
|
1009
|
+
|
|
1010
|
+
// ── 侧栏入口行(DOM 注入,taskboard 家族同款) ─────────────────────────────
|
|
1011
|
+
|
|
1012
|
+
/** 把文本写进当前会话的 composer(file-share 同款双形态 + 剪贴板兜底)。
|
|
1013
|
+
* 返回 'ok'(已写入输入框)或 'copied'(退化为剪贴板)。 */
|
|
1014
|
+
function insertComposerText(text) {
|
|
1015
|
+
try {
|
|
1016
|
+
const card = document.querySelector('[data-composer-card]')
|
|
1017
|
+
const ta = card && card.querySelector('textarea')
|
|
1018
|
+
const ce = card && (card.querySelector('[contenteditable="true"]') || card.querySelector('[contenteditable=""]'))
|
|
1019
|
+
if (typeof document.execCommand === 'function' && (ta || ce)) {
|
|
1020
|
+
if (ta) {
|
|
1021
|
+
ta.focus()
|
|
1022
|
+
const len = ta.value ? ta.value.length : 0
|
|
1023
|
+
try { ta.setSelectionRange(len, len) } catch {}
|
|
1024
|
+
} else if (ce) {
|
|
1025
|
+
ce.focus()
|
|
1026
|
+
const sel = window.getSelection()
|
|
1027
|
+
const range = document.createRange()
|
|
1028
|
+
range.selectNodeContents(ce)
|
|
1029
|
+
range.collapse(false)
|
|
1030
|
+
sel.removeAllRanges()
|
|
1031
|
+
sel.addRange(range)
|
|
1032
|
+
}
|
|
1033
|
+
if (document.execCommand('insertText', false, text)) return 'ok'
|
|
1034
|
+
}
|
|
1035
|
+
} catch {}
|
|
1036
|
+
try { navigator.clipboard.writeText(text) } catch {}
|
|
1037
|
+
return 'copied'
|
|
1038
|
+
}
|
|
1039
|
+
|
|
1040
|
+
|
|
1041
|
+
// ── 表单编辑:Document API 双向同步(v0.4)──────────────────────────────
|
|
1042
|
+
|
|
1043
|
+
/** yaml 库:bundle 内 YamlLibSrc 源经 new Function 隔离构造(懒加载,避开其他插件
|
|
1044
|
+
* 加载期的全局污染窗口);plain Node(单测)退回 require('yaml')。 */
|
|
1045
|
+
function getYamlLib() {
|
|
1046
|
+
try { if (typeof YamlLib !== 'undefined' && YamlLib) return YamlLib } catch {}
|
|
1047
|
+
try { if (typeof makeYamlLibIsolated === 'function') { YamlLib = makeYamlLibIsolated(); return YamlLib } } catch {}
|
|
1048
|
+
try { return require('yaml') } catch { return null }
|
|
1049
|
+
}
|
|
1050
|
+
|
|
1051
|
+
/** 解析编辑器文本为 Document;语法错误返回 null(表单不可用)。 */
|
|
1052
|
+
function fmDoc(text) {
|
|
1053
|
+
const lib = getYamlLib()
|
|
1054
|
+
if (!lib) return null
|
|
1055
|
+
try {
|
|
1056
|
+
const doc = lib.parseDocument(String(text || ''), { keepSourceTokens: true })
|
|
1057
|
+
return doc.errors.length === 0 ? doc : null
|
|
1058
|
+
} catch { return null }
|
|
1059
|
+
}
|
|
1060
|
+
|
|
1061
|
+
/** setIn:写标量/对象;中间节点缺失自动创建。返回新文本。 */
|
|
1062
|
+
function fmSet(text, path, value) {
|
|
1063
|
+
const doc = fmDoc(text)
|
|
1064
|
+
if (!doc) return text
|
|
1065
|
+
try { doc.setIn(path, value) } catch { return text }
|
|
1066
|
+
return doc.toString()
|
|
1067
|
+
}
|
|
1068
|
+
|
|
1069
|
+
/** deleteIn:删除键或序列项。返回新文本。 */
|
|
1070
|
+
function fmDel(text, path) {
|
|
1071
|
+
const doc = fmDoc(text)
|
|
1072
|
+
if (!doc) return text
|
|
1073
|
+
try { doc.deleteIn(path) } catch { return text }
|
|
1074
|
+
return doc.toString()
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
/** 向序列(如 phases / links / gates)追加一个普通对象。 */
|
|
1078
|
+
function fmAppend(text, path, value) {
|
|
1079
|
+
const doc = fmDoc(text)
|
|
1080
|
+
if (!doc) return text
|
|
1081
|
+
try {
|
|
1082
|
+
const seq = doc.getIn(path, true)
|
|
1083
|
+
if (seq && typeof seq.add === 'function') seq.add(value)
|
|
1084
|
+
else doc.setIn(path, [value])
|
|
1085
|
+
} catch { return text }
|
|
1086
|
+
return doc.toString()
|
|
1087
|
+
}
|
|
1088
|
+
|
|
1089
|
+
/** 读路径上的 JS 值(缺失 → dflt)。 */
|
|
1090
|
+
function fmGet(text, path, dflt) {
|
|
1091
|
+
const doc = fmDoc(text)
|
|
1092
|
+
if (!doc) return dflt
|
|
1093
|
+
const v = doc.getIn(path)
|
|
1094
|
+
return v === undefined || v === null ? dflt : v
|
|
1095
|
+
}
|
|
1096
|
+
|
|
1097
|
+
const fmSeqLen = (doc, path) => { const s = doc.getIn(path, true); return s && s.items ? s.items.length : 0 }
|
|
1098
|
+
|
|
1099
|
+
/** 删除环节 + 级联:所有指向被删 id 的 on_success/on_gate_fail 重置(next/break)。 */
|
|
1100
|
+
function fmDeleteLink(text, phaseIndex, linkIndex) {
|
|
1101
|
+
const doc = fmDoc(text)
|
|
1102
|
+
if (!doc) return text
|
|
1103
|
+
const linksPath = ['phases', phaseIndex, 'links']
|
|
1104
|
+
const deletedId = String(doc.getIn([...linksPath, linkIndex, 'id']) ?? '')
|
|
1105
|
+
try { doc.getIn(linksPath, true).delete(linkIndex) } catch { return text }
|
|
1106
|
+
if (deletedId) {
|
|
1107
|
+
const pc = fmSeqLen(doc, ['phases'])
|
|
1108
|
+
for (let pi = 0; pi < pc; pi++) {
|
|
1109
|
+
const lc = fmSeqLen(doc, ['phases', pi, 'links'])
|
|
1110
|
+
for (let li = 0; li < lc; li++) {
|
|
1111
|
+
for (const field of ['on_success', 'on_gate_fail']) {
|
|
1112
|
+
const v = doc.getIn(['phases', pi, 'links', li, field])
|
|
1113
|
+
if (v === deletedId || v === 'goto:' + deletedId) {
|
|
1114
|
+
doc.setIn(['phases', pi, 'links', li, field], field === 'on_success' ? 'next' : 'break')
|
|
1115
|
+
}
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
}
|
|
1119
|
+
}
|
|
1120
|
+
return doc.toString()
|
|
1121
|
+
}
|
|
1122
|
+
|
|
1123
|
+
/** 删除阶段 + 级联重置其下所有环节 id 的引用。 */
|
|
1124
|
+
function fmDeletePhase(text, phaseIndex) {
|
|
1125
|
+
const doc = fmDoc(text)
|
|
1126
|
+
if (!doc) return text
|
|
1127
|
+
const deletedIds = []
|
|
1128
|
+
const lc0 = fmSeqLen(doc, ['phases', phaseIndex, 'links'])
|
|
1129
|
+
for (let li = 0; li < lc0; li++) {
|
|
1130
|
+
const id = doc.getIn(['phases', phaseIndex, 'links', li, 'id'])
|
|
1131
|
+
if (id) deletedIds.push(String(id))
|
|
1132
|
+
}
|
|
1133
|
+
try { doc.getIn(['phases'], true).delete(phaseIndex) } catch { return text }
|
|
1134
|
+
const pc = fmSeqLen(doc, ['phases'])
|
|
1135
|
+
for (let pi = 0; pi < pc; pi++) {
|
|
1136
|
+
const lc = fmSeqLen(doc, ['phases', pi, 'links'])
|
|
1137
|
+
for (let li = 0; li < lc; li++) {
|
|
1138
|
+
for (const field of ['on_success', 'on_gate_fail']) {
|
|
1139
|
+
const v = doc.getIn(['phases', pi, 'links', li, field])
|
|
1140
|
+
if (v && (deletedIds.includes(v) || deletedIds.includes(String(v).replace(/^goto:/, '')))) {
|
|
1141
|
+
doc.setIn(['phases', pi, 'links', li, field], field === 'on_success' ? 'next' : 'break')
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
return doc.toString()
|
|
1147
|
+
}
|
|
1148
|
+
|
|
1149
|
+
/** 环节改 id + 级联:所有引用旧 id 的流转值同步替换(含 goto: 前缀)。 */
|
|
1150
|
+
function fmSetLinkId(text, phaseIndex, linkIndex, newId) {
|
|
1151
|
+
const doc = fmDoc(text)
|
|
1152
|
+
if (!doc) return text
|
|
1153
|
+
const oldId = String(doc.getIn(['phases', phaseIndex, 'links', linkIndex, 'id']) ?? '')
|
|
1154
|
+
doc.setIn(['phases', phaseIndex, 'links', linkIndex, 'id'], newId)
|
|
1155
|
+
if (!oldId || oldId === newId) return doc.toString()
|
|
1156
|
+
const pc = fmSeqLen(doc, ['phases'])
|
|
1157
|
+
for (let pi = 0; pi < pc; pi++) {
|
|
1158
|
+
const lc = fmSeqLen(doc, ['phases', pi, 'links'])
|
|
1159
|
+
for (let li = 0; li < lc; li++) {
|
|
1160
|
+
for (const field of ['on_success', 'on_gate_fail']) {
|
|
1161
|
+
const v = doc.getIn(['phases', pi, 'links', li, field])
|
|
1162
|
+
if (v === oldId) doc.setIn(['phases', pi, 'links', li, field], newId)
|
|
1163
|
+
else if (v === 'goto:' + oldId) doc.setIn(['phases', pi, 'links', li, field], 'goto:' + newId)
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
}
|
|
1167
|
+
return doc.toString()
|
|
1168
|
+
}
|
|
1169
|
+
|
|
1170
|
+
const ICON = '<svg viewBox="0 0 16 16" width="14" height="14" fill="none" stroke="currentColor" stroke-width="1.3" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><rect x="1.5" y="1.5" width="5" height="4.5" rx="1"/><rect x="9.5" y="10" width="5" height="4.5" rx="1"/><path d="M4 6v3.5A1.5 1.5 0 0 0 5.5 11h4"/></svg>'
|
|
1171
|
+
|
|
1172
|
+
function sidebarRoot() {
|
|
1173
|
+
const column = document.querySelector(PRC_SIDEBAR_COLUMN_SELECTOR)
|
|
1174
|
+
if (column === null) return undefined
|
|
1175
|
+
const logoOwner = column.querySelector('[class*="logoRow"]') && column.querySelector('[class*="logoRow"]').parentElement
|
|
1176
|
+
return logoOwner || (column.firstElementChild || undefined)
|
|
1177
|
+
}
|
|
1178
|
+
|
|
1179
|
+
function newSessionButton(root) {
|
|
1180
|
+
const nested = root.querySelector('button[class*="newSession"]')
|
|
1181
|
+
if (nested) return nested
|
|
1182
|
+
for (const child of root.children) {
|
|
1183
|
+
if (child instanceof HTMLButtonElement && !child.matches('[' + ENTRY_ATTR + ']')) return child
|
|
1184
|
+
}
|
|
1185
|
+
const byAria = root.querySelector('button[aria-label="新建会话"], button[aria-label="New Session"], button[aria-label*="新会话"], button[aria-label*="new session" i]')
|
|
1186
|
+
if (byAria) return byAria
|
|
1187
|
+
const buttons = Array.from(root.querySelectorAll('button'))
|
|
1188
|
+
return buttons.find((b) => !b.matches('[' + ENTRY_ATTR + ']') && /新会话|新建会话|new session/i.test(b.textContent || ''))
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1191
|
+
function createEntry(controller, t) {
|
|
1192
|
+
const entry = document.createElement('button')
|
|
1193
|
+
entry.type = 'button'
|
|
1194
|
+
entry.setAttribute(ENTRY_ATTR, '')
|
|
1195
|
+
entry.className = 'dswfe-entry'
|
|
1196
|
+
entry.setAttribute('aria-label', t('entryAria'))
|
|
1197
|
+
entry.innerHTML = '<span class="dswfe-entry-icon">' + ICON + '</span><span class="dswfe-entry-label"></span><span class="dswfe-entry-stats"></span>'
|
|
1198
|
+
entry.addEventListener('click', () => controller.togglePanel())
|
|
1199
|
+
return entry
|
|
1200
|
+
}
|
|
1201
|
+
|
|
1202
|
+
function setRollValue(slot, value) {
|
|
1203
|
+
const text = String(value)
|
|
1204
|
+
if (slot.dataset.value === text) return
|
|
1205
|
+
const previous = slot.dataset.value
|
|
1206
|
+
slot.dataset.value = text
|
|
1207
|
+
slot.style.minWidth = text.length + 'ch'
|
|
1208
|
+
if (previous === undefined) { slot.textContent = text; return }
|
|
1209
|
+
if (slot.dataset.busy === '1') { slot.dataset.busy = ''; slot.dataset.anim = '' }
|
|
1210
|
+
const oldEl = document.createElement('span'); oldEl.className = 'dswfe-rn'; oldEl.textContent = previous
|
|
1211
|
+
const newEl = document.createElement('span'); newEl.className = 'dswfe-rn dswfe-rn-next'; newEl.textContent = text
|
|
1212
|
+
slot.replaceChildren(oldEl, newEl)
|
|
1213
|
+
slot.dataset.dir = value > Number(previous) ? 'up' : 'down'
|
|
1214
|
+
slot.dataset.busy = '1'
|
|
1215
|
+
requestAnimationFrame(() => { slot.dataset.anim = '1' })
|
|
1216
|
+
const finish = () => {
|
|
1217
|
+
if (slot.dataset.busy !== '1') return
|
|
1218
|
+
slot.dataset.busy = ''; slot.dataset.anim = ''
|
|
1219
|
+
slot.textContent = slot.dataset.value || ''
|
|
1220
|
+
}
|
|
1221
|
+
slot.addEventListener('transitionend', finish, { once: true })
|
|
1222
|
+
setTimeout(finish, 400)
|
|
1223
|
+
}
|
|
1224
|
+
|
|
1225
|
+
function wireEntrySync(entry, controller, t) {
|
|
1226
|
+
const stats = entry.querySelector('.dswfe-entry-stats')
|
|
1227
|
+
const label = entry.querySelector('.dswfe-entry-label')
|
|
1228
|
+
const slots = []
|
|
1229
|
+
if (stats) {
|
|
1230
|
+
for (let i = 0; i < 2; i++) {
|
|
1231
|
+
if (i > 0) { const sep = document.createElement('span'); sep.className = 'dswfe-entry-sep'; sep.textContent = '|'; stats.append(sep) }
|
|
1232
|
+
const slot = document.createElement('span')
|
|
1233
|
+
slot.className = 'dswfe-roll'
|
|
1234
|
+
slot.dataset.stat = i === 0 ? 'user' : 'bundled'
|
|
1235
|
+
stats.append(slot); slots.push(slot)
|
|
1236
|
+
}
|
|
1237
|
+
}
|
|
1238
|
+
const sync = () => {
|
|
1239
|
+
const s = controller.getSnapshot()
|
|
1240
|
+
if (s.panelOpen) entry.dataset.active = 'true'; else delete entry.dataset.active
|
|
1241
|
+
const user = s.processes.filter((p) => p.source === 'user').length
|
|
1242
|
+
const bundled = s.processes.filter((p) => p.source === 'bundled').length
|
|
1243
|
+
if (slots[0]) setRollValue(slots[0], user)
|
|
1244
|
+
if (slots[1]) setRollValue(slots[1], bundled)
|
|
1245
|
+
if (label) label.textContent = t('title')
|
|
1246
|
+
entry.setAttribute('aria-label', t('entryAria'))
|
|
1247
|
+
entry.title = t('entryTitle', { user, bundled })
|
|
1248
|
+
}
|
|
1249
|
+
return sync
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
function placeEntry(root, entry) {
|
|
1253
|
+
const button = newSessionButton(root)
|
|
1254
|
+
if (!button) return false
|
|
1255
|
+
if (entry.parentElement !== root) {
|
|
1256
|
+
const family = Array.from(root.children).filter((el) => el instanceof HTMLElement
|
|
1257
|
+
&& el.matches('[' + ENTRY_ATTR + '], [data-dsh-atb-entry], [data-dsh-taskboard-entry], [data-dsh-ssh-entry]'))
|
|
1258
|
+
if (family.length > 0) {
|
|
1259
|
+
const last = family[family.length - 1]
|
|
1260
|
+
last.parentElement.insertBefore(entry, last.nextSibling)
|
|
1261
|
+
} else {
|
|
1262
|
+
const row = button.closest('[class*="logoRow"]')
|
|
1263
|
+
const base = (row && row.parentElement === root) ? row : button
|
|
1264
|
+
root.insertBefore(entry, base.nextSibling)
|
|
1265
|
+
}
|
|
1266
|
+
}
|
|
1267
|
+
return true
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
function mountSidebarEntry(controller, t) {
|
|
1271
|
+
const entry = createEntry(controller, t)
|
|
1272
|
+
const debug = { attempts: 0, found: false, placed: false }
|
|
1273
|
+
try {
|
|
1274
|
+
const host = globalThis.location && globalThis.location.hostname
|
|
1275
|
+
if (host === 'localhost' || host === '127.0.0.1') window.__prcDebug = debug
|
|
1276
|
+
} catch {}
|
|
1277
|
+
let root
|
|
1278
|
+
let placed = false
|
|
1279
|
+
const tryPlace = () => {
|
|
1280
|
+
debug.attempts++
|
|
1281
|
+
if (root && !root.isConnected) { rootObserver.disconnect(); root = undefined; placed = false }
|
|
1282
|
+
if (placed) {
|
|
1283
|
+
if (document.body.contains(entry)) return
|
|
1284
|
+
rootObserver.disconnect(); root = undefined; placed = false
|
|
1285
|
+
}
|
|
1286
|
+
root = root || sidebarRoot()
|
|
1287
|
+
if (!root) return
|
|
1288
|
+
debug.found = !!newSessionButton(root)
|
|
1289
|
+
placed = placeEntry(root, entry)
|
|
1290
|
+
debug.placed = placed
|
|
1291
|
+
if (placed) rootObserver.observe(root, { childList: true, subtree: true })
|
|
1292
|
+
}
|
|
1293
|
+
const waitObserver = new MutationObserver(() => tryPlace())
|
|
1294
|
+
waitObserver.observe(document.body, { childList: true, subtree: true })
|
|
1295
|
+
const rootObserver = new MutationObserver(() => {
|
|
1296
|
+
if (!root || !root.isConnected) { placed = false; tryPlace(); return }
|
|
1297
|
+
if (!root.contains(entry)) placed = placeEntry(root, entry)
|
|
1298
|
+
})
|
|
1299
|
+
const retry = setInterval(() => tryPlace(), 2000)
|
|
1300
|
+
const sync = wireEntrySync(entry, controller, t)
|
|
1301
|
+
const unsubscribe = controller.subscribe(sync)
|
|
1302
|
+
sync()
|
|
1303
|
+
tryPlace()
|
|
1304
|
+
return () => {
|
|
1305
|
+
clearInterval(retry)
|
|
1306
|
+
waitObserver.disconnect()
|
|
1307
|
+
rootObserver.disconnect()
|
|
1308
|
+
unsubscribe()
|
|
1309
|
+
entry.remove()
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
|
|
1313
|
+
// ── 工具函数 ─────────────────────────────────────────────────────────────
|
|
1314
|
+
|
|
1315
|
+
function complexityLabel(t, v) {
|
|
1316
|
+
const key = { low: 'cxLow', medium: 'cxMid', high: 'cxHigh' }[v]
|
|
1317
|
+
return key ? t(key) : String(v)
|
|
1318
|
+
}
|
|
1319
|
+
|
|
1320
|
+
function filterProcesses(state) {
|
|
1321
|
+
const q = state.search.trim().toLowerCase()
|
|
1322
|
+
const rows = state.processes.filter((p) =>
|
|
1323
|
+
(state.filters.source === 'all' || p.source === state.filters.source)
|
|
1324
|
+
&& (state.filters.category === '' || p.category === state.filters.category)
|
|
1325
|
+
&& (state.filters.complexity === '' || p.complexity === state.filters.complexity)
|
|
1326
|
+
&& (q === '' || (p.name + ' ' + (p.display_name || '') + ' ' + (p.description || '')).toLowerCase().includes(q)))
|
|
1327
|
+
const rank = { low: 0, medium: 1, high: 2 }
|
|
1328
|
+
const sorted = [...rows]
|
|
1329
|
+
if (state.sortBy === 'updated') sorted.sort((a, b) => b.mtime - a.mtime)
|
|
1330
|
+
else if (state.sortBy === 'complexity') sorted.sort((a, b) => (rank[a.complexity] ?? 9) - (rank[b.complexity] ?? 9) || a.relPath.localeCompare(b.relPath))
|
|
1331
|
+
else if (state.sortBy === 'links') sorted.sort((a, b) => b.linkCount - a.linkCount)
|
|
1332
|
+
else sorted.sort((a, b) => a.relPath.localeCompare(b.relPath))
|
|
1333
|
+
return sorted
|
|
1334
|
+
}
|
|
1335
|
+
|
|
1336
|
+
function flowLabel(t, v) {
|
|
1337
|
+
if (v === 'next') return t('flowNext')
|
|
1338
|
+
if (v === 'end') return t('flowEnd')
|
|
1339
|
+
if (v === 'break') return t('flowBreak')
|
|
1340
|
+
return String(v)
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
function linkExpert(ln) { return (ln && (ln.expert_name || ln.expert)) || undefined }
|
|
1344
|
+
|
|
1345
|
+
/** 极轻量 YAML 着色:注释灰、键蓝、其余默认。 */
|
|
1346
|
+
function colorizeLine(line) {
|
|
1347
|
+
const trimmed = line.trimStart()
|
|
1348
|
+
if (trimmed.startsWith('#')) return [h('span', { className: 'dswfe-cm' }, line)]
|
|
1349
|
+
const m = line.match(/^(\s*(?:-\s+)?)([A-Za-z_][\w.-]*)(:)(.*)$/)
|
|
1350
|
+
if (m) {
|
|
1351
|
+
return [m[1], h('span', { className: 'dswfe-key' }, m[2] + ':'), m[4] ? colorizeScalar(m[4]) : '']
|
|
1352
|
+
}
|
|
1353
|
+
return [line]
|
|
1354
|
+
}
|
|
1355
|
+
function colorizeScalar(rest) {
|
|
1356
|
+
const t = rest.trim()
|
|
1357
|
+
if (t === '' || t === '|' || t === '>' || t === '|-' || t === '>-') return rest
|
|
1358
|
+
if (t.startsWith('#')) return [h('span', { className: 'dswfe-cm' }, rest)]
|
|
1359
|
+
return rest
|
|
1360
|
+
}
|
|
1361
|
+
|
|
1362
|
+
// ── 组件 ─────────────────────────────────────────────────────────────────
|
|
1363
|
+
|
|
1364
|
+
function useControllerState(controller) {
|
|
1365
|
+
const getSnap = useCallback(() => controller.getSnapshot(), [controller])
|
|
1366
|
+
const subscribe = useCallback((cb) => controller.subscribe(cb), [controller])
|
|
1367
|
+
return useSyncExternalStore(subscribe, getSnap)
|
|
1368
|
+
}
|
|
1369
|
+
let useSyncExternalStore = __React.useSyncExternalStore
|
|
1370
|
+
|| ((subscribe, getSnap) => {
|
|
1371
|
+
const [v, setV] = useState(getSnap)
|
|
1372
|
+
useEffect(() => subscribe(() => setV(getSnap())), [subscribe, getSnap])
|
|
1373
|
+
return v
|
|
1374
|
+
})
|
|
1375
|
+
|
|
1376
|
+
function Menu({ x, y, items, onClose }) {
|
|
1377
|
+
return h('div', null,
|
|
1378
|
+
h('div', { className: 'dswfe-menuback', onClick: onClose, onContextMenu: (e) => { e.preventDefault(); onClose() } }),
|
|
1379
|
+
h('div', { className: 'dswfe-menu', style: { left: Math.max(4, x) + 'px', top: Math.max(4, y) + 'px' } },
|
|
1380
|
+
items.map((it, i) => h('button', { key: i, onClick: () => { onClose(); it.onClick() } }, it.label))))
|
|
1381
|
+
}
|
|
1382
|
+
|
|
1383
|
+
function anchorMenu(btn, items, onClose) {
|
|
1384
|
+
let pos = { x: 100, y: 100 }
|
|
1385
|
+
try { const r = btn.getBoundingClientRect(); pos = { x: r.left, y: r.bottom + 4 } } catch {}
|
|
1386
|
+
return h(Menu, { x: pos.x, y: pos.y, items, onClose })
|
|
1387
|
+
}
|
|
1388
|
+
|
|
1389
|
+
function Toolbar({ state, controller, t }) {
|
|
1390
|
+
const [menu, setMenu] = useState(null) // {kind, btn}
|
|
1391
|
+
const categories = useMemo(() => [...new Set(state.processes.map((p) => p.category).filter(Boolean))].sort(), [state.processes])
|
|
1392
|
+
const user = state.processes.filter((p) => p.source === 'user').length
|
|
1393
|
+
const bundled = state.processes.filter((p) => p.source === 'bundled').length
|
|
1394
|
+
const sel = state.item && state.item.meta
|
|
1395
|
+
const openMenu = (kind) => (e) => setMenu(menu && menu.kind === kind ? null : { kind, btn: e.currentTarget })
|
|
1396
|
+
return h('div', { className: 'dswfe-toolbar' },
|
|
1397
|
+
h('h2', { className: 'dswfe-title' }, t('title')),
|
|
1398
|
+
h('span', { className: 'dswfe-count' }, t('count', { user, bundled })),
|
|
1399
|
+
h('div', { className: 'dswfe-tabs', style: { borderBottom: 'none', margin: '0 4px' } },
|
|
1400
|
+
h('button', { className: 'dswfe-tab', 'data-on': state.view === 'lib' ? 'true' : undefined, onClick: () => controller.setView('lib') }, t('viewLib')),
|
|
1401
|
+
h('button', { className: 'dswfe-tab', 'data-on': state.view === 'exec' ? 'true' : undefined, onClick: () => controller.setView('exec') }, t('viewExec'))),
|
|
1402
|
+
h('input', { className: 'dswfe-input dswfe-search', value: state.search, placeholder: t('searchPlaceholder'), spellCheck: false, onChange: (e) => controller.setSearch(e.target.value) }),
|
|
1403
|
+
h('select', { className: 'dswfe-select', value: state.filters.source, onChange: (e) => controller.setFilter('source', e.target.value) },
|
|
1404
|
+
h('option', { value: 'all' }, t('filterAll')), h('option', { value: 'user' }, t('filterUser')), h('option', { value: 'bundled' }, t('filterBundled'))),
|
|
1405
|
+
h('select', { className: 'dswfe-select', value: state.filters.category, onChange: (e) => controller.setFilter('category', e.target.value) },
|
|
1406
|
+
h('option', { value: '' }, t('categoryAll')), categories.map((c) => h('option', { key: c, value: c }, c))),
|
|
1407
|
+
h('select', { className: 'dswfe-select', value: state.filters.complexity, onChange: (e) => controller.setFilter('complexity', e.target.value) },
|
|
1408
|
+
h('option', { value: '' }, t('complexityAll')), [['low', t('cxLow')], ['medium', t('cxMid')], ['high', t('cxHigh')]].map(([v, label]) => h('option', { key: v, value: v }, label))),
|
|
1409
|
+
h('select', { className: 'dswfe-select', value: state.sortBy, title: t('sortDefault'), onChange: (e) => controller.setSortBy(e.target.value) },
|
|
1410
|
+
h('option', { value: 'default' }, t('sortDefault')), h('option', { value: 'updated' }, t('sortUpdated')),
|
|
1411
|
+
h('option', { value: 'complexity' }, t('sortComplexity')), h('option', { value: 'links' }, t('sortLinks'))),
|
|
1412
|
+
h('div', { className: 'dswfe-spacer' }),
|
|
1413
|
+
h('button', { className: 'dswfe-btn', title: t('aiBtn'), onClick: () => controller.setState({ dialog: { type: 'ai' } }) }, '⚡ ' + t('aiBtn')),
|
|
1414
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', onClick: openMenu('new') }, '+ ' + t('newTask')),
|
|
1415
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ dialog: { type: 'import' } }) }, t('importBtn')),
|
|
1416
|
+
h('button', { className: 'dswfe-btn', onClick: openMenu('export') }, t('exportBtn')),
|
|
1417
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ dialog: { type: 'settings' } }) }, t('settingsBtn')),
|
|
1418
|
+
h('button', { className: 'dswfe-btn', title: t('close'), onClick: () => controller.closePanel() }, '✕'),
|
|
1419
|
+
menu === null ? null
|
|
1420
|
+
: menu.kind === 'new'
|
|
1421
|
+
? anchorMenu(menu.btn, [
|
|
1422
|
+
{ label: t('newBlank'), onClick: () => controller.setState({ dialog: { type: 'create' } }) },
|
|
1423
|
+
{ label: t('newFromExisting'), onClick: () => controller.setState({ dialog: { type: 'copy', fromId: sel ? sel.id : undefined } }) },
|
|
1424
|
+
], () => setMenu(null))
|
|
1425
|
+
: anchorMenu(menu.btn, [
|
|
1426
|
+
{ label: t('exportAll'), onClick: () => download(API + '/export?all=1') },
|
|
1427
|
+
{ label: t('exportUser'), onClick: () => download(API + '/export?source=user') },
|
|
1428
|
+
{ label: t('exportOne'), onClick: () => { if (sel) download(API + '/export?id=' + encodeURIComponent(sel.id)) } },
|
|
1429
|
+
], () => setMenu(null)))
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
function download(url) {
|
|
1433
|
+
const a = document.createElement('a')
|
|
1434
|
+
a.href = url
|
|
1435
|
+
a.rel = 'noopener'
|
|
1436
|
+
document.body.appendChild(a)
|
|
1437
|
+
a.click()
|
|
1438
|
+
a.remove()
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
function ListPane({ state, controller, t }) {
|
|
1442
|
+
const rows = filterProcesses(state)
|
|
1443
|
+
const userRows = rows.filter((p) => p.source === 'user')
|
|
1444
|
+
const bundledRows = rows.filter((p) => p.source === 'bundled')
|
|
1445
|
+
const onKey = (e) => {
|
|
1446
|
+
if (e.key !== 'ArrowDown' && e.key !== 'ArrowUp') return
|
|
1447
|
+
e.preventDefault()
|
|
1448
|
+
const ids = rows.map((p) => p.id)
|
|
1449
|
+
if (ids.length === 0) return
|
|
1450
|
+
const idx = ids.indexOf(state.selectedId)
|
|
1451
|
+
const next = e.key === 'ArrowDown' ? ids[Math.min(ids.length - 1, idx + 1)] || ids[0] : ids[Math.max(0, idx - 1)]
|
|
1452
|
+
controller.select(next)
|
|
1453
|
+
}
|
|
1454
|
+
const row = (p) => h('button', {
|
|
1455
|
+
key: p.id, className: 'dswfe-row', role: 'button', tabIndex: 0,
|
|
1456
|
+
'data-selected': state.selectedId === p.id ? 'true' : undefined,
|
|
1457
|
+
'data-source': p.source, 'data-complexity': p.complexity || 'medium',
|
|
1458
|
+
onClick: () => controller.select(p.id),
|
|
1459
|
+
onKeyDown: (e) => { if ((e.key === 'Enter' || e.key === ' ') && e.target === e.currentTarget) { e.preventDefault(); controller.select(p.id) } },
|
|
1460
|
+
},
|
|
1461
|
+
h('div', { className: 'dswfe-row-name' },
|
|
1462
|
+
h('span', { className: 'lbl' }, p.display_name || p.name),
|
|
1463
|
+
p.errors > 0 ? h('span', { className: 'dswfe-dot', 'data-kind': 'err', title: p.errors + t('errOne') }) : null,
|
|
1464
|
+
p.warnings > 0 ? h('span', { className: 'dswfe-dot', 'data-kind': 'warn', title: p.warnings + t('warnOne') }) : null),
|
|
1465
|
+
h('div', { className: 'dswfe-row-meta' },
|
|
1466
|
+
h('span', null, p.name),
|
|
1467
|
+
p.complexity ? h('span', { className: 'dswfe-badge' }, complexityLabel(t, p.complexity)) : null,
|
|
1468
|
+
p.version ? h('span', null, 'v' + p.version) : null,
|
|
1469
|
+
h('span', null, p.phaseCount + t('phases') + ' · ' + p.linkCount + t('links'))))
|
|
1470
|
+
const group = (label, items) => h('div', null,
|
|
1471
|
+
h('div', { className: 'dswfe-group' }, label, h('span', null, items.length)),
|
|
1472
|
+
items.map(row))
|
|
1473
|
+
return h('div', { className: 'dswfe-list', onKeyDown: onKey, tabIndex: 0 },
|
|
1474
|
+
rows.length === 0
|
|
1475
|
+
? h('div', { style: { padding: '18px 8px', color: 'var(--dsw-text-secondary, gray)', fontSize: 12 } }, t('emptyList'), h('div', { style: { marginTop: 4, opacity: .8 } }, t('emptyListHint')))
|
|
1476
|
+
: [group(t('mine'), userRows), group(t('bundled'), bundledRows)])
|
|
1477
|
+
}
|
|
1478
|
+
|
|
1479
|
+
function DiagList({ diagnostics, t, onJump }) {
|
|
1480
|
+
const items = [...(diagnostics.errors || []).map((d) => ({ ...d, kind: 'err' })), ...(diagnostics.warnings || []).map((d) => ({ ...d, kind: 'warn' }))]
|
|
1481
|
+
if (items.length === 0) return h('div', { className: 'dswfe-diag', style: { opacity: .75 } }, t('noIssues'))
|
|
1482
|
+
return h('div', { className: 'dswfe-diag' }, items.map((d, i) => h('button', {
|
|
1483
|
+
key: i, className: 'dswfe-diag-item', 'data-kind': d.kind,
|
|
1484
|
+
onClick: () => onJump && d.line && onJump(d.line),
|
|
1485
|
+
},
|
|
1486
|
+
h('span', { className: 'dswfe-diag-line' }, d.line ? 'L' + d.line : ''),
|
|
1487
|
+
h('span', { className: 'dswfe-diag-code' }, d.kind === 'err' ? '✗' : '⚠'),
|
|
1488
|
+
h('span', null, d.message),
|
|
1489
|
+
h('span', { style: { opacity: .5, marginLeft: 'auto', flex: 'none' } }, d.code))))
|
|
1490
|
+
}
|
|
1491
|
+
|
|
1492
|
+
function StructureLinkCard({ t, ln, phaseId, index }) {
|
|
1493
|
+
const [open, setOpen] = useState(false)
|
|
1494
|
+
const meta = []
|
|
1495
|
+
// 环节级 model 运行时不被读取(execution.js 只用 run.model),不展示也不配置
|
|
1496
|
+
meta.push(execLabel(t, { reviewType: ln.review_type || 'ai' }))
|
|
1497
|
+
if (Array.isArray(ln.gates) && ln.gates.length) meta.push(t('flowGate', { min: ln.gates.map((g) => (g && g.min_score != null ? g.min_score : '?')).join('/') }))
|
|
1498
|
+
if (ln.max_rework !== undefined && ln.max_rework !== null) meta.push(t('flowRework', { n: ln.max_rework }))
|
|
1499
|
+
return h('div', { className: 'dswfe-link' },
|
|
1500
|
+
h('button', { className: 'dswfe-link-row', onClick: () => setOpen(!open), 'aria-expanded': open },
|
|
1501
|
+
h('span', { className: 'dswfe-link-id' }, t('linkNo', { n: index })),
|
|
1502
|
+
h('span', null, ln.name || ''),
|
|
1503
|
+
h('span', { className: 'dswfe-link-meta' }, meta.join(' · '))),
|
|
1504
|
+
!open ? null : h('div', { className: 'dswfe-link-body' },
|
|
1505
|
+
ln.prompt ? h('div', null, h('div', { style: { fontSize: 11, opacity: .65, marginBottom: 3 } }, t('prompt')), h('pre', { className: 'dswfe-pre' }, ln.prompt)) : null,
|
|
1506
|
+
h('div', { className: 'dswfe-kv' }, h('b', null, t('onSuccess') + ':'), flowLabel(t, ln.on_success || '—')),
|
|
1507
|
+
h('div', { className: 'dswfe-kv' }, h('b', null, t('onGateFail') + ':'), flowLabel(t, ln.on_gate_fail || '—')),
|
|
1508
|
+
ln.review_type ? h('div', { className: 'dswfe-kv' }, h('b', null, t('reviewType') + ':'), t(ln.review_type === 'human' ? 'reviewHuman' : ln.review_type === 'none' ? 'reviewNone' : 'reviewAi')) : null,
|
|
1509
|
+
ln.review_prompt ? h('div', { className: 'dswfe-kv' }, h('b', null, t('reviewPrompt') + ':'), h('span', { style: { whiteSpace: 'pre-wrap' } }, ln.review_prompt)) : null,
|
|
1510
|
+
ln.acceptance_criteria ? h('div', { className: 'dswfe-kv' }, h('b', null, t('acceptance') + ':'), h('span', { style: { whiteSpace: 'pre-wrap' } }, ln.acceptance_criteria)) : null,
|
|
1511
|
+
Array.isArray(ln.expected_artifacts) && ln.expected_artifacts.length > 0 ? h('div', { className: 'dswfe-kv' },
|
|
1512
|
+
h('b', null, t('artifacts') + ':'),
|
|
1513
|
+
h('span', null, ln.expected_artifacts.map((a) => (a && (a.path || a.name)) || '').filter(Boolean).join(' · '))) : null,
|
|
1514
|
+
Array.isArray(ln.gates) && ln.gates.length > 0 ? h('div', { className: 'dswfe-kv' },
|
|
1515
|
+
h('b', null, t('gates') + ':'),
|
|
1516
|
+
h('span', null, ln.gates.map((g) => (g ? (g.name || '?') + (g.min_score !== undefined && g.min_score !== null ? ' ≥' + g.min_score : '') : '')).join(' · '))) : null,
|
|
1517
|
+
h('div', { style: { fontSize: 11, opacity: .55 } }, phaseId)))
|
|
1518
|
+
}
|
|
1519
|
+
|
|
1520
|
+
function StructureTab({ t, parsed }) {
|
|
1521
|
+
const phases = parsed && Array.isArray(parsed.phases) ? parsed.phases : []
|
|
1522
|
+
if (phases.length === 0) return h('div', { className: 'dswfe-empty' }, '—')
|
|
1523
|
+
let seq = 0
|
|
1524
|
+
return h('div', null, phases.map((ph, i) => {
|
|
1525
|
+
const links = Array.isArray(ph.links) ? ph.links : []
|
|
1526
|
+
return h('div', { className: 'dswfe-phase', key: ph.id || i },
|
|
1527
|
+
h('div', { className: 'dswfe-phase-head' },
|
|
1528
|
+
h('span', { className: 'dswfe-badge' }, t('phaseNo', { n: i + 1 })),
|
|
1529
|
+
h('span', null, ph.name || ''),
|
|
1530
|
+
h('span', { className: 'dswfe-link-meta' }, links.length + ' ' + t('links'))),
|
|
1531
|
+
ph.spec ? h('div', { className: 'dswfe-phase-spec' }, ph.spec) : null,
|
|
1532
|
+
ph.acceptance_criteria ? h('div', { className: 'dswfe-kv' }, h('b', null, t('acceptance') + ':'), h('span', { style: { whiteSpace: 'pre-wrap' } }, ph.acceptance_criteria)) : null,
|
|
1533
|
+
links.map((ln, j) => { seq += 1; return h(StructureLinkCard, { key: ln.id || j, t, ln, phaseId: ph.id, index: seq }) }))
|
|
1534
|
+
}))
|
|
1535
|
+
}
|
|
1536
|
+
|
|
1537
|
+
function YamlView({ yaml, highlightLine }) {
|
|
1538
|
+
const boxRef = useRef(null)
|
|
1539
|
+
const lines = useMemo(() => String(yaml || '').split('\n'), [yaml])
|
|
1540
|
+
useEffect(() => {
|
|
1541
|
+
if (!highlightLine || !boxRef.current) return
|
|
1542
|
+
const el = boxRef.current.querySelector('[data-line="' + highlightLine + '"]')
|
|
1543
|
+
if (el) el.scrollIntoView({ block: 'center' })
|
|
1544
|
+
}, [highlightLine, yaml])
|
|
1545
|
+
return h('div', { className: 'dswfe-code', ref: boxRef },
|
|
1546
|
+
lines.map((line, i) => h('div', { key: i, className: 'dswfe-code-line', 'data-line': i + 1, 'data-hl': highlightLine === i + 1 ? 'true' : undefined },
|
|
1547
|
+
h('span', { className: 'dswfe-code-no' }, i + 1),
|
|
1548
|
+
h('span', { className: 'dswfe-code-tx' }, colorizeLine(line)))))
|
|
1549
|
+
}
|
|
1550
|
+
|
|
1551
|
+
function OverviewTab({ t, meta, parsed, diagnostics, onJump }) {
|
|
1552
|
+
const limits = parsed && parsed.limits
|
|
1553
|
+
const abnormal = parsed && parsed.abnormal_handler
|
|
1554
|
+
const phases = parsed && Array.isArray(parsed.phases) ? parsed.phases : []
|
|
1555
|
+
let seq = 0
|
|
1556
|
+
const outline = []
|
|
1557
|
+
phases.forEach((ph, pi) => {
|
|
1558
|
+
const links = Array.isArray(ph.links) ? ph.links : []
|
|
1559
|
+
outline.push(h('div', { className: 'dswfe-ovphase', key: 'ph' + pi },
|
|
1560
|
+
h('span', { className: 'dswfe-badge' }, t('phaseNo', { n: pi + 1 })),
|
|
1561
|
+
h('span', null, ph.name || '')))
|
|
1562
|
+
links.forEach((ln, li) => {
|
|
1563
|
+
seq += 1
|
|
1564
|
+
outline.push(h('div', { className: 'dswfe-ovlink', key: 'ln' + pi + '-' + li },
|
|
1565
|
+
h('span', { className: 'dswfe-ovno' }, t('linkNo', { n: seq })),
|
|
1566
|
+
h('span', { className: 'dswfe-ovname' }, ln.name || ln.id || ''),
|
|
1567
|
+
h('span', { className: 'dswfe-ovkind' }, [
|
|
1568
|
+
execLabel(t, { reviewType: ln.review_type || 'ai' }),
|
|
1569
|
+
(Array.isArray(ln.gates) && ln.gates.length > 0)
|
|
1570
|
+
? t('flowGate', { min: Math.min(...ln.gates.map((g) => Number(g && g.min_score) || 0)) })
|
|
1571
|
+
: t('flowNoGate'),
|
|
1572
|
+
ln.max_rework === null || ln.max_rework === undefined ? null : t('flowRework', { n: ln.max_rework }),
|
|
1573
|
+
].filter(Boolean).join(' · '))))
|
|
1574
|
+
})
|
|
1575
|
+
})
|
|
1576
|
+
return h('div', null,
|
|
1577
|
+
h('div', { className: 'dswfe-kv' }, h('b', null, t('name') + ':'), meta.name),
|
|
1578
|
+
limits ? h('div', { className: 'dswfe-kv' }, h('b', null, t('limits') + ':'),
|
|
1579
|
+
(limits.max_step_executions == null ? t('unlimited') : limits.max_step_executions + ' ' + t('steps')) + ' · '
|
|
1580
|
+
+ (limits.max_total_tokens == null ? t('unlimited') : limits.max_total_tokens + ' ' + t('tokens'))) : null,
|
|
1581
|
+
abnormal && Array.isArray(abnormal.trigger_on) ? h('div', { className: 'dswfe-kv' }, h('b', null, t('abnormal') + ':'), abnormal.trigger_on.join(', ')) : null,
|
|
1582
|
+
h('div', { className: 'dswfe-sec' },
|
|
1583
|
+
h('h4', null, t('overviewTitle')),
|
|
1584
|
+
meta.description ? h('p', { className: 'dswfe-desc' }, meta.description) : null,
|
|
1585
|
+
outline.length === 0 ? h('div', { className: 'dswfe-diag', style: { opacity: .75 } }, t('overviewEmpty')) : h('div', { className: 'dswfe-outline' }, outline)),
|
|
1586
|
+
h('div', { className: 'dswfe-sec' }, h('h4', null, t('diagnostics')), h(DiagList, { t, diagnostics, onJump })))
|
|
1587
|
+
}
|
|
1588
|
+
|
|
1589
|
+
function DetailPane({ state, controller, t }) {
|
|
1590
|
+
const item = state.item
|
|
1591
|
+
const meta = item && item.meta
|
|
1592
|
+
const isUser = meta && meta.source === 'user'
|
|
1593
|
+
const [confirmDelete, setConfirmDelete] = useState(false)
|
|
1594
|
+
const jump = (line) => { controller.setState({ highlightLine: line }); controller.setTab('yaml') }
|
|
1595
|
+
const copyYaml = () => {
|
|
1596
|
+
if (navigator.clipboard && navigator.clipboard.writeText) navigator.clipboard.writeText(item.yaml).then(() => controller.toast(t('copied'))).catch(() => {})
|
|
1597
|
+
}
|
|
1598
|
+
const atAgent = () => controller.atAgent(meta)
|
|
1599
|
+
if (state.itemLoading) return h('div', { className: 'dswfe-detail' }, t('loading'))
|
|
1600
|
+
if (!item || !meta) return h('div', { className: 'dswfe-empty' }, h('div', null, t('emptyDetail')), h('div', { style: { fontSize: 12, opacity: .8 } }, t('selectFirst')))
|
|
1601
|
+
return h('div', { className: 'dswfe-detail' },
|
|
1602
|
+
h('div', { className: 'dswfe-detail-head' },
|
|
1603
|
+
h('h3', { className: 'dswfe-detail-title' }, meta.display_name || meta.name),
|
|
1604
|
+
h('div', { className: 'dswfe-actions' },
|
|
1605
|
+
isUser ? [
|
|
1606
|
+
h('button', { key: 'e', className: 'dswfe-btn', 'data-primary': 'true', onClick: () => controller.editSelected() }, '✎ ' + t('edit')),
|
|
1607
|
+
h('button', { key: 'r', className: 'dswfe-btn', onClick: () => controller.setState({ dialog: { type: 'rename', id: meta.id, name: meta.display_name || meta.name } }) }, t('rename')),
|
|
1608
|
+
!confirmDelete
|
|
1609
|
+
? h('button', { key: 'd', className: 'dswfe-btn', onClick: () => setConfirmDelete(true) }, '🗑 ' + t('delete'))
|
|
1610
|
+
: h('span', { key: 'dc', style: { display: 'inline-flex', gap: 6, alignItems: 'center' } },
|
|
1611
|
+
h('span', { style: { fontSize: 12 } }, t('deleteConfirm') + '?'),
|
|
1612
|
+
h('button', { className: 'dswfe-btn', 'data-danger': 'true', onClick: () => { setConfirmDelete(false); controller.removeProcess(meta.id) } }, t('confirm')),
|
|
1613
|
+
h('button', { className: 'dswfe-btn', onClick: () => setConfirmDelete(false) }, t('cancel'))),
|
|
1614
|
+
] : [
|
|
1615
|
+
h('button', { key: 'c', className: 'dswfe-btn', 'data-primary': 'true', onClick: () => controller.setState({ dialog: { type: 'copy', fromId: meta.id } }) }, '⧉ ' + t('copyToMine')),
|
|
1616
|
+
],
|
|
1617
|
+
h('button', { key: 'run', className: 'dswfe-btn', 'data-primary': 'true', title: t('runCreate'), onClick: () => controller.setState({ dialog: { type: 'newrun', processId: meta.id } }) }, t('runCreate')),
|
|
1618
|
+
h('button', { key: 'x', className: 'dswfe-btn', onClick: copyYaml }, t('copyYaml')))),
|
|
1619
|
+
h('div', { className: 'dswfe-chips' },
|
|
1620
|
+
h('span', { className: 'dswfe-chip' }, isUser ? t('mine') : t('readOnly')),
|
|
1621
|
+
meta.category ? h('span', { className: 'dswfe-chip' }, t('category') + ': ' + meta.category) : null,
|
|
1622
|
+
meta.complexity ? h('span', { className: 'dswfe-chip' }, t('complexity') + ': ' + complexityLabel(t, meta.complexity)) : null,
|
|
1623
|
+
meta.version ? h('span', { className: 'dswfe-chip' }, 'v' + meta.version) : null,
|
|
1624
|
+
h('span', { className: 'dswfe-chip' }, meta.phaseCount + ' ' + t('phases') + ' · ' + meta.linkCount + ' ' + t('links')),
|
|
1625
|
+
item.diagnostics && item.diagnostics.errors.length > 0 ? h('span', { className: 'dswfe-badge', 'data-kind': 'err' }, item.diagnostics.errors.length + t('errOne')) : null,
|
|
1626
|
+
item.diagnostics && item.diagnostics.warnings.length > 0 ? h('span', { className: 'dswfe-badge', 'data-kind': 'warn' }, item.diagnostics.warnings.length + t('warnOne')) : null),
|
|
1627
|
+
h('div', { className: 'dswfe-tabs' },
|
|
1628
|
+
['overview', 'flow', 'structure', 'yaml'].map((tab) => h('button', { key: tab, className: 'dswfe-tab', 'data-on': state.tab === tab ? 'true' : undefined, onClick: () => controller.setTab(tab) },
|
|
1629
|
+
t('tab' + tab[0].toUpperCase() + tab.slice(1))))),
|
|
1630
|
+
state.tab === 'overview' ? h(OverviewTab, { t, meta, parsed: item.parsed, diagnostics: item.diagnostics, onJump: jump })
|
|
1631
|
+
: state.tab === 'flow' ? h(FlowGraph, { t, parsed: item.parsed })
|
|
1632
|
+
: state.tab === 'structure' ? h(StructureTab, { t, parsed: item.parsed })
|
|
1633
|
+
: h(YamlView, { yaml: item.yaml, highlightLine: state.highlightLine }))
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
// ── 编辑器 ───────────────────────────────────────────────────────────────
|
|
1637
|
+
|
|
1638
|
+
// ── 表单编辑器(v0.4):与 YAML 实时双向同步 ───────────────────────────
|
|
1639
|
+
// 单一数据源 = 编辑器文本(ed.text)。表单字段修改:解析当前文本 →
|
|
1640
|
+
// Document setIn/deleteIn/append → toString 写回 ed.text;YAML 子模式
|
|
1641
|
+
// 的每次输入同样写回 ed.text——两个视图天然互相同步。
|
|
1642
|
+
|
|
1643
|
+
function FormField({ label, children, help }) {
|
|
1644
|
+
return h('label', { className: 'dswfe-field' },
|
|
1645
|
+
h('span', { className: 'dswfe-field-label' }, label, help ? h(Help, { text: help }) : null),
|
|
1646
|
+
children)
|
|
1647
|
+
}
|
|
1648
|
+
|
|
1649
|
+
function FormText({ value, onChange, placeholder, multiline, rows, type }) {
|
|
1650
|
+
const style = { width: '100%', fontFamily: type === 'mono' ? 'ui-monospace, Menlo, monospace' : 'var(--dsw-font-family, inherit)', fontSize: 12.5, lineHeight: multiline ? 1.55 : 1.4, border: '1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.3))', borderRadius: 8, padding: multiline ? '7px 9px' : '5px 9px', background: 'var(--dsw-alias-bg-layer-2,transparent)', color: 'inherit', boxSizing: 'border-box', whiteSpace: multiline ? 'pre-wrap' : undefined }
|
|
1651
|
+
return multiline
|
|
1652
|
+
? h('textarea', { value, placeholder: placeholder || '', spellCheck: false, rows: rows || 2, style: Object.assign({ resize: 'vertical' }, style), onChange: (e) => onChange(e.target.value) })
|
|
1653
|
+
: h('input', { value, type: type || 'text', placeholder: placeholder || '', spellCheck: false, style, onChange: (e) => onChange(e.target.value) })
|
|
1654
|
+
}
|
|
1655
|
+
|
|
1656
|
+
function FormSelect({ value, onChange, options }) {
|
|
1657
|
+
return h('select', { value, onChange: (e) => onChange(e.target.value), style: { width: '100%', border: '1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.3))', background: 'var(--dsw-alias-bg-layer-2,transparent)', color: 'inherit', borderRadius: 8, padding: '5px 8px', font: 'inherit', fontSize: 12.5 } },
|
|
1658
|
+
options.map((o) => h('option', { key: o[0], value: o[0] }, o[1])))
|
|
1659
|
+
}
|
|
1660
|
+
|
|
1661
|
+
// ── FormEditor(可视化表单,与 YAML 双向实时同步)─────────────────────────
|
|
1662
|
+
// 单一数据源 = ed.text:表单改动经 Document API(fmSet 等,注释/未知字段不丢)
|
|
1663
|
+
// 写回 ed.text;YAML 手改后表单随 useMemo 重新解析实时反映。
|
|
1664
|
+
|
|
1665
|
+
function FormField({ label, children, help }) {
|
|
1666
|
+
return h('label', { className: 'dswfe-field' },
|
|
1667
|
+
h('span', { className: 'dswfe-field-label' }, label, help ? h(Help, { text: help }) : null),
|
|
1668
|
+
children)
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
function FormText({ value, onChange, placeholder, mono }) {
|
|
1672
|
+
return h('input', { value: String(value ?? ''), spellCheck: false, placeholder,
|
|
1673
|
+
style: mono ? { fontFamily: 'ui-monospace, monospace' } : undefined,
|
|
1674
|
+
onChange: (e) => onChange(e.target.value) })
|
|
1675
|
+
}
|
|
1676
|
+
|
|
1677
|
+
function FormNum({ value, onChange, placeholder, min }) {
|
|
1678
|
+
return h('input', { type: 'number', value: value === null || value === undefined || value === '' ? '' : String(value), min, placeholder, spellCheck: false,
|
|
1679
|
+
onChange: (e) => onChange(e.target.value === '' ? null : Number(e.target.value)) })
|
|
1680
|
+
}
|
|
1681
|
+
|
|
1682
|
+
function FormArea({ value, onChange, rows, placeholder }) {
|
|
1683
|
+
return h('textarea', { value: String(value ?? ''), rows: rows || 3, spellCheck: false, placeholder,
|
|
1684
|
+
onChange: (e) => onChange(e.target.value) })
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1687
|
+
function FormSelect({ value, options, onChange }) {
|
|
1688
|
+
const cur = String(value ?? '')
|
|
1689
|
+
// 选项既可以是字符串,也可以是 [值, 显示文案]——后者用来把英文枚举显示成中文
|
|
1690
|
+
const pairs = options.map((o) => (Array.isArray(o) ? [String(o[0]), o[1]] : [String(o), o]))
|
|
1691
|
+
const list = pairs.some((p) => p[0] === cur) ? pairs : [[cur, cur]].concat(pairs)
|
|
1692
|
+
return h('select', { value: cur, onChange: (e) => onChange(e.target.value) },
|
|
1693
|
+
list.map((p) => h('option', { key: p[0], value: p[0] }, p[1])))
|
|
1694
|
+
}
|
|
1695
|
+
|
|
1696
|
+
// 模型目录 + 技能目录的模块级缓存(跨 form↔yaml 切换、跨编辑器开关复用,不设过期)
|
|
1697
|
+
const catalogCache = { loaded: false, models: { providers: [] }, skills: [] }
|
|
1698
|
+
// 画布选中态的模块级记忆:form↔yaml 切换重挂载后按 id 恢复(id 对不上自动回落 global)
|
|
1699
|
+
let canvasSelMemory = { kind: 'global' }
|
|
1700
|
+
|
|
1701
|
+
/** 模型两极下拉:供应商 → 模型(不让手填)。YAML 值 = 'provider/model';空 = 跟随运行模型。 */
|
|
1702
|
+
function ModelPicker({ value, catalog, onChange, t }) {
|
|
1703
|
+
const raw = String(value ?? '')
|
|
1704
|
+
const slash = raw.indexOf('/')
|
|
1705
|
+
const curProvider = slash >= 0 ? raw.slice(0, slash) : raw
|
|
1706
|
+
const curModel = slash >= 0 ? raw.slice(slash + 1) : ''
|
|
1707
|
+
const providers = (catalog.models && catalog.models.providers) || []
|
|
1708
|
+
const prov = providers.find((p) => p.id === curProvider)
|
|
1709
|
+
const models = prov ? prov.models : []
|
|
1710
|
+
const opts = [h('option', { key: '', value: '' }, t('modelDefault'))].concat(
|
|
1711
|
+
providers.map((p) => h('option', { key: p.id, value: p.id }, p.name)),
|
|
1712
|
+
(curProvider && !prov) ? [h('option', { key: curProvider, value: curProvider }, curProvider)] : [])
|
|
1713
|
+
const mopts = [h('option', { key: '', value: '' }, curProvider ? t('modelProvDefault') : t('modelDefault'))].concat(
|
|
1714
|
+
models.map((m) => h('option', { key: m.id, value: m.id }, m.name)),
|
|
1715
|
+
(curModel && (!prov || !models.some((m) => m.id === curModel))) ? [h('option', { key: curModel, value: curModel }, curModel)] : [])
|
|
1716
|
+
return h('div', { className: 'dswfe-modelrow' },
|
|
1717
|
+
h('select', {
|
|
1718
|
+
className: 'dswfe-native-sel', value: curProvider, title: t('formProvider'),
|
|
1719
|
+
onChange: (e) => { const p = e.target.value; onChange(p === '' ? null : (models.some((m) => m.id === curModel) ? p + '/' + curModel : p)) },
|
|
1720
|
+
}, opts),
|
|
1721
|
+
h('select', {
|
|
1722
|
+
className: 'dswfe-native-sel', value: curModel, title: '模型', disabled: curProvider === '',
|
|
1723
|
+
onChange: (e) => { const m = e.target.value; onChange(curProvider === '' ? null : (m === '' ? curProvider : curProvider + '/' + m)) },
|
|
1724
|
+
}, mopts))
|
|
1725
|
+
}
|
|
1726
|
+
|
|
1727
|
+
/** 技能多选下拉:dsh 技能目录(/skills),勾选写回 skills 数组。 */
|
|
1728
|
+
function SkillPicker({ value, skills, onChange, t }) {
|
|
1729
|
+
const [open, setOpen] = useState(false)
|
|
1730
|
+
const wrapRef = useRef(null)
|
|
1731
|
+
useEffect(() => {
|
|
1732
|
+
if (!open) return undefined
|
|
1733
|
+
const onDown = (e) => { if (wrapRef.current && !wrapRef.current.contains(e.target)) setOpen(false) }
|
|
1734
|
+
document.addEventListener('mousedown', onDown)
|
|
1735
|
+
return () => document.removeEventListener('mousedown', onDown)
|
|
1736
|
+
}, [open])
|
|
1737
|
+
const arr = Array.isArray(value) ? value.map(String)
|
|
1738
|
+
: (value && Array.isArray(value.items)) ? value.items.map((n) => String(n && n.value !== undefined ? n.value : n))
|
|
1739
|
+
: []
|
|
1740
|
+
const toggle = (name) => onChange(arr.includes(name) ? arr.filter((x) => x !== name) : arr.concat(name))
|
|
1741
|
+
return h('div', { className: 'dswfe-skillpick', ref: wrapRef },
|
|
1742
|
+
h('button', { type: 'button', className: 'dswfe-selbtn', onClick: () => setOpen(!open), 'data-open': open ? 'true' : undefined },
|
|
1743
|
+
h('span', { className: arr.length ? '' : 'dswfe-selph' }, arr.length ? arr.join(', ') : t('skillsPick')),
|
|
1744
|
+
h('span', { className: 'dswfe-selcar' }, open ? '▴' : '▾')),
|
|
1745
|
+
!open ? null : h('div', { className: 'dswfe-skillpop' },
|
|
1746
|
+
(!skills || skills.length === 0) ? h('div', { className: 'dswfe-skillnone' }, t('skillsNone')) :
|
|
1747
|
+
skills.map((s) => h('label', { key: s.name, className: 'dswfe-skillrow' },
|
|
1748
|
+
h('input', { type: 'checkbox', checked: arr.includes(s.name), onChange: () => toggle(s.name) }),
|
|
1749
|
+
h('span', { className: 'dswfe-skillname' }, s.name),
|
|
1750
|
+
s.description ? h('span', { className: 'dswfe-skilldesc', title: s.description }, s.description) : null)),
|
|
1751
|
+
arr.length ? h('button', { type: 'button', className: 'dswfe-skillclear', onClick: () => onChange([]) }, t('skillsClear', { n: arr.length })) : null))
|
|
1752
|
+
}
|
|
1753
|
+
|
|
1754
|
+
function FormEditor({ state, controller, t, ed }) {
|
|
1755
|
+
const doc = useMemo(() => fmDoc(ed.text), [ed.text])
|
|
1756
|
+
// 画布选中态:{kind:'global'} | {kind:'phase', id} | {kind:'link', id}。
|
|
1757
|
+
// 只存 id:编辑导致索引漂移时按 id 重扫,找不到(刚删掉)回落 global。
|
|
1758
|
+
const [sel, setSelState] = useState(() => canvasSelMemory)
|
|
1759
|
+
const setSel = (s) => { canvasSelMemory = s; setSelState(s) }
|
|
1760
|
+
// 模型目录 + dsh 技能目录(模块级缓存,编辑器每次挂载只拉一次)
|
|
1761
|
+
const [catalog, setCatalog] = useState(() => catalogCache)
|
|
1762
|
+
useEffect(() => {
|
|
1763
|
+
if (catalogCache.loaded) return
|
|
1764
|
+
let live = true
|
|
1765
|
+
Promise.all([api('/models').catch(() => null), api('/skills').catch(() => null)]).then(([m, s]) => {
|
|
1766
|
+
catalogCache.models = m || { providers: [] }
|
|
1767
|
+
catalogCache.skills = s && Array.isArray(s.skills) ? s.skills : []
|
|
1768
|
+
catalogCache.loaded = true
|
|
1769
|
+
if (live) setCatalog({ ...catalogCache })
|
|
1770
|
+
})
|
|
1771
|
+
return () => { live = false }
|
|
1772
|
+
}, [])
|
|
1773
|
+
if (!doc) {
|
|
1774
|
+
return h('div', { className: 'dswfe-form' },
|
|
1775
|
+
h('div', { className: 'dswfe-error' }, t('formUnparseable')))
|
|
1776
|
+
}
|
|
1777
|
+
const P = (path, dflt) => { const v = doc.getIn(path); return v === undefined || v === null ? dflt : v }
|
|
1778
|
+
const set = (path, value) => controller.setEditorText(fmSet(ed.text, path, value))
|
|
1779
|
+
|
|
1780
|
+
const phaseCount = fmSeqLen(doc, ['phases'])
|
|
1781
|
+
const allLinkIds = []
|
|
1782
|
+
for (let pi = 0; pi < phaseCount; pi++) {
|
|
1783
|
+
const lc = fmSeqLen(doc, ['phases', pi, 'links'])
|
|
1784
|
+
for (let li = 0; li < lc; li++) {
|
|
1785
|
+
const id = P(['phases', pi, 'links', li, 'id'], '')
|
|
1786
|
+
if (id) allLinkIds.push(String(id))
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
// 流转下拉:关键字显示中文;目标只列 goto:<id> 一种写法——引擎里 parseFlow 会剥掉 goto: 前缀,
|
|
1790
|
+
// 裸 <id> 与 goto:<id> 完全等价,之前两种都列出来才让人看不懂。当前值若是裸 id,就地补一条
|
|
1791
|
+
// 本地化文案(不静默改用户数据)。
|
|
1792
|
+
const linkMeta = []
|
|
1793
|
+
for (let pi = 0; pi < phaseCount; pi++) {
|
|
1794
|
+
const lc = fmSeqLen(doc, ['phases', pi, 'links'])
|
|
1795
|
+
for (let li = 0; li < lc; li++) {
|
|
1796
|
+
const id = String(P(['phases', pi, 'links', li, 'id'], '') || '')
|
|
1797
|
+
if (!id) continue
|
|
1798
|
+
linkMeta.push({ id, no: linkMeta.length + 1, name: String(P(['phases', pi, 'links', li, 'name'], '') || '') })
|
|
1799
|
+
}
|
|
1800
|
+
}
|
|
1801
|
+
const jumpLabel = (id) => {
|
|
1802
|
+
const m = linkMeta.find((x) => x.id === id)
|
|
1803
|
+
return m ? t('flowJumpTo', { no: m.no, name: m.name || m.id }) : t('flowJumpTo', { no: linkMeta.length + 1, name: id })
|
|
1804
|
+
}
|
|
1805
|
+
const flowOptions = (fixed, cur) => {
|
|
1806
|
+
const head = fixed.map((v) => [v, v === 'next' ? t('flowNext') : v === 'end' ? t('flowEnd') : v === 'break' ? t('flowBreakStop') : v])
|
|
1807
|
+
const raw = String(cur == null ? '' : cur)
|
|
1808
|
+
// 同一条目标只出现一次:当前值本来就是裸 id 时,这条目标就用裸 id 作值(不静默改用户数据也不重复列)
|
|
1809
|
+
const jumps = linkMeta.map((m) => [raw === m.id ? m.id : 'goto:' + m.id, jumpLabel(m.id)])
|
|
1810
|
+
if (raw && !head.some((p) => p[0] === raw) && !jumps.some((p) => p[0] === raw)) jumps.push([raw, jumpLabel(raw.replace(/^goto:/, ''))])
|
|
1811
|
+
return head.concat(jumps)
|
|
1812
|
+
}
|
|
1813
|
+
|
|
1814
|
+
// ── 选中解析:按 id 重扫定位索引 ──
|
|
1815
|
+
const linkIdAt = (pi, li) => String(P(['phases', pi, 'links', li, 'id'], '') || '')
|
|
1816
|
+
const phaseIdAt = (pi) => String(P(['phases', pi, 'id'], '') || '')
|
|
1817
|
+
const R = (() => {
|
|
1818
|
+
if (sel.kind === 'global') return { kind: 'global' }
|
|
1819
|
+
for (let pi = 0; pi < phaseCount; pi++) {
|
|
1820
|
+
if (sel.kind === 'phase' && phaseIdAt(pi) === sel.id) return { kind: 'phase', pi }
|
|
1821
|
+
const lc = fmSeqLen(doc, ['phases', pi, 'links'])
|
|
1822
|
+
for (let li = 0; li < lc; li++) {
|
|
1823
|
+
if (sel.kind === 'link' && linkIdAt(pi, li) === sel.id) return { kind: 'link', pi, li }
|
|
1824
|
+
}
|
|
1825
|
+
}
|
|
1826
|
+
return { kind: 'global' }
|
|
1827
|
+
})()
|
|
1828
|
+
|
|
1829
|
+
const addPhase = () => {
|
|
1830
|
+
let n = phaseCount + 1
|
|
1831
|
+
let pid = 'phase-' + n
|
|
1832
|
+
while (allLinkIds.some((id) => id.startsWith(pid))) { n += 1; pid = 'phase-' + n }
|
|
1833
|
+
controller.setEditorText(fmAppend(ed.text, ['phases'], { id: pid, name: '', spec: '', links: [] }))
|
|
1834
|
+
setSel({ kind: 'phase', id: pid })
|
|
1835
|
+
}
|
|
1836
|
+
const addLink = (pi) => {
|
|
1837
|
+
let n = allLinkIds.length + 1
|
|
1838
|
+
let lid = 'link-' + n
|
|
1839
|
+
while (allLinkIds.includes(lid)) { n += 1; lid = 'link-' + n }
|
|
1840
|
+
controller.setEditorText(fmAppend(ed.text, ['phases', pi, 'links'], {
|
|
1841
|
+
id: lid, name: t('formNewLinkName'), prompt: '', executor: null, expert: null, skills: [],
|
|
1842
|
+
model: null, review_type: 'ai', gates: [], on_success: 'next', on_gate_fail: 'break',
|
|
1843
|
+
on_rating_fail: 'break', max_rework: null,
|
|
1844
|
+
}))
|
|
1845
|
+
setSel({ kind: 'link', id: lid })
|
|
1846
|
+
}
|
|
1847
|
+
const delPhase = (pi) => {
|
|
1848
|
+
const name = String(P(['phases', pi, 'name'], '') || phaseIdAt(pi) || '#' + (pi + 1))
|
|
1849
|
+
const n = fmSeqLen(doc, ['phases', pi, 'links'])
|
|
1850
|
+
if (!window.confirm(t('canvasDelPhase', { name, n }))) return
|
|
1851
|
+
controller.setEditorText(fmDeletePhase(ed.text, pi))
|
|
1852
|
+
setSel({ kind: 'global' })
|
|
1853
|
+
}
|
|
1854
|
+
const delLink = (pi, li) => {
|
|
1855
|
+
const name = String(P(['phases', pi, 'links', li, 'name'], '') || linkIdAt(pi, li))
|
|
1856
|
+
if (!window.confirm(t('canvasDelLink', { name }))) return
|
|
1857
|
+
controller.setEditorText(fmDeleteLink(ed.text, pi, li))
|
|
1858
|
+
setSel({ kind: 'global' })
|
|
1859
|
+
}
|
|
1860
|
+
|
|
1861
|
+
// ── 左:画布 ──
|
|
1862
|
+
const lane = (pi) => {
|
|
1863
|
+
const pid = phaseIdAt(pi)
|
|
1864
|
+
const pname = String(P(['phases', pi, 'name'], '') || pid)
|
|
1865
|
+
const lc = fmSeqLen(doc, ['phases', pi, 'links'])
|
|
1866
|
+
const phaseSel = R.kind === 'phase' && R.pi === pi
|
|
1867
|
+
const chipKids = []
|
|
1868
|
+
for (let li = 0; li < lc; li++) {
|
|
1869
|
+
const lid = linkIdAt(pi, li)
|
|
1870
|
+
const lname = String(P(['phases', pi, 'links', li, 'name'], '') || lid)
|
|
1871
|
+
const gateCount = fmSeqLen(doc, ['phases', pi, 'links', li, 'gates'])
|
|
1872
|
+
const isSel = R.kind === 'link' && R.pi === pi && R.li === li
|
|
1873
|
+
if (li > 0) chipKids.push(h('span', { className: 'dswfe-node-arrow', key: 'ar' + li }, '→'))
|
|
1874
|
+
chipKids.push(h('div', {
|
|
1875
|
+
key: 'nd' + li, className: 'dswfe-node', 'data-sel': isSel ? 'true' : undefined,
|
|
1876
|
+
onClick: (e) => { e.stopPropagation(); setSel({ kind: 'link', id: lid }) },
|
|
1877
|
+
},
|
|
1878
|
+
h('div', { className: 'dswfe-node-name' }, lname),
|
|
1879
|
+
h('div', { className: 'dswfe-node-meta' },
|
|
1880
|
+
h('span', { className: 'dswfe-node-id' }, lid),
|
|
1881
|
+
gateCount > 0 ? h('span', { className: 'dswfe-node-badge' }, '🔒' + gateCount) : null)),
|
|
1882
|
+
)
|
|
1883
|
+
}
|
|
1884
|
+
chipKids.push(h('button', {
|
|
1885
|
+
key: 'addlk', className: 'dswfe-node-add', title: t('formAddLink'),
|
|
1886
|
+
onClick: (e) => { e.stopPropagation(); addLink(pi) },
|
|
1887
|
+
}, '+'))
|
|
1888
|
+
return h('div', { className: 'dswfe-lane', key: 'ph' + pi, 'data-sel': phaseSel ? 'true' : undefined },
|
|
1889
|
+
h('div', { className: 'dswfe-lane-head', onClick: () => setSel({ kind: 'phase', id: pid }) },
|
|
1890
|
+
h('span', { className: 'dswfe-lane-no', style: { background: flowPhaseColor(pid) } }, '#' + (pi + 1)),
|
|
1891
|
+
h('span', { className: 'dswfe-lane-name' }, pname),
|
|
1892
|
+
h('span', { className: 'dswfe-lane-id' }, pid),
|
|
1893
|
+
h('span', { className: 'dswfe-lane-count' }, lc + t('links'))),
|
|
1894
|
+
h('div', { className: 'dswfe-lane-body' }, chipKids))
|
|
1895
|
+
}
|
|
1896
|
+
|
|
1897
|
+
const laneKids = []
|
|
1898
|
+
for (let pi = 0; pi < phaseCount; pi++) laneKids.push(lane(pi))
|
|
1899
|
+
|
|
1900
|
+
const canvas = h('div', {
|
|
1901
|
+
className: 'dswfe-canvas-left',
|
|
1902
|
+
onClick: (e) => { if (e.target === e.currentTarget) setSel({ kind: 'global' }) },
|
|
1903
|
+
},
|
|
1904
|
+
h('div', { className: 'dswfe-canvas-bar' },
|
|
1905
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', onClick: addPhase }, t('formAddPhase')),
|
|
1906
|
+
h('span', { className: 'dswfe-canvas-hint' }, h(Help, { text: t('helpCanvas') }))),
|
|
1907
|
+
phaseCount === 0 ? h('div', { className: 'dswfe-canvas-empty' }, t('canvasEmpty')) : null,
|
|
1908
|
+
h('div', null, laneKids))
|
|
1909
|
+
|
|
1910
|
+
// ── 右:属性面板 ──
|
|
1911
|
+
const sec = (title, extra) => h('div', { className: 'dswfe-fsec' },
|
|
1912
|
+
h('h4', null, title), extra || null)
|
|
1913
|
+
|
|
1914
|
+
const propsGlobal = [
|
|
1915
|
+
sec(t('propGlobal')),
|
|
1916
|
+
h('div', { className: 'dswfe-fsec', key: 'basic' },
|
|
1917
|
+
h('div', { className: 'dswfe-fgrid' },
|
|
1918
|
+
h(FormField, { label: t('formDisplayName') }, h(FormText, { value: P(['process', 'display_name'], ''), onChange: (v) => set(['process', 'display_name'], v) })),
|
|
1919
|
+
h(FormField, { label: t('formVersion') }, h(FormText, { value: P(['process', 'version'], ''), onChange: (v) => set(['process', 'version'], v) })),
|
|
1920
|
+
h(FormField, { label: t('formCategory') }, h(FormText, { value: P(['process', 'category'], ''), onChange: (v) => set(['process', 'category'], v) })),
|
|
1921
|
+
h(FormField, { label: t('formComplexity') }, h(FormSelect, { value: P(['process', 'complexity'], 'medium'), options: [['low', t('cxLow')], ['medium', t('cxMid')], ['high', t('cxHigh')]], onChange: (v) => set(['process', 'complexity'], v) }))),
|
|
1922
|
+
h('div', { style: { height: 8 } }),
|
|
1923
|
+
h(FormField, { label: t('formDescription') }, h(FormArea, { value: P(['process', 'description'], ''), rows: 5, onChange: (v) => set(['process', 'description'], v) }))),
|
|
1924
|
+
sec(t('formLimits')),
|
|
1925
|
+
h('div', { className: 'dswfe-fsec', key: 'limits' },
|
|
1926
|
+
h('div', { className: 'dswfe-fgrid' },
|
|
1927
|
+
h(FormField, { label: t('formMaxSteps') }, h(FormNum, { value: P(['limits', 'max_step_executions'], null), min: 1, onChange: (v) => set(['limits', 'max_step_executions'], v) })),
|
|
1928
|
+
h(FormField, { label: t('formMaxTokens') }, h(FormNum, { value: P(['limits', 'max_total_tokens'], null), min: 1, onChange: (v) => set(['limits', 'max_total_tokens'], v) }))))
|
|
1929
|
+
]
|
|
1930
|
+
|
|
1931
|
+
const propsPhase = (pi) => [
|
|
1932
|
+
sec(t('propPhase') + ' · #' + (pi + 1),
|
|
1933
|
+
h('button', { className: 'dswfe-btn', 'data-danger': 'true', style: { marginLeft: 'auto' }, onClick: () => delPhase(pi) }, t('formDelPhase'))),
|
|
1934
|
+
h('div', { className: 'dswfe-fsec', key: 'meta' },
|
|
1935
|
+
h('div', { className: 'dswfe-fgrid' },
|
|
1936
|
+
h(FormField, { label: 'id' }, h(FormText, { value: phaseIdAt(pi), mono: true, onChange: (v) => { if (v.trim() !== '') { set(['phases', pi, 'id'], v.trim()); setSel({ kind: 'phase', id: v.trim() }) } } })),
|
|
1937
|
+
h(FormField, { label: t('formPhaseName') }, h(FormText, { value: P(['phases', pi, 'name'], ''), placeholder: t('formPhaseName'), onChange: (v) => set(['phases', pi, 'name'], v) }))),
|
|
1938
|
+
h(FormField, { label: t('formPhaseSpec'), style: { marginTop: 6 } }, h(FormArea, { value: P(['phases', pi, 'spec'], ''), rows: 4, onChange: (v) => set(['phases', pi, 'spec'], v) })))
|
|
1939
|
+
]
|
|
1940
|
+
|
|
1941
|
+
const propsLink = (pi, li) => {
|
|
1942
|
+
const lp = ['phases', pi, 'links', li]
|
|
1943
|
+
const gatesPath = [...lp, 'gates']
|
|
1944
|
+
const gateCount = fmSeqLen(doc, gatesPath)
|
|
1945
|
+
// 执行器/专家:运行时都不读(只影响 prompt 措辞),面板已隐藏;YAML 里的旧字段仍能解析
|
|
1946
|
+
const metaFields = [
|
|
1947
|
+
['id', 'id', true], [t('formName'), 'name', false],
|
|
1948
|
+
]
|
|
1949
|
+
const gridKids = metaFields.map(([label, key, mono], i) => h(FormField, { label, key: 'm' + i },
|
|
1950
|
+
h(FormText, {
|
|
1951
|
+
value: key === 'id' ? linkIdAt(pi, li) : P([...lp, key], ''),
|
|
1952
|
+
mono,
|
|
1953
|
+
placeholder: key === 'id' ? 'req-01' : undefined,
|
|
1954
|
+
onChange: (v) => {
|
|
1955
|
+
if (key === 'id') {
|
|
1956
|
+
if (v.trim() !== '') { controller.setEditorText(fmSetLinkId(ed.text, pi, li, v.trim())); setSel({ kind: 'link', id: v.trim() }) }
|
|
1957
|
+
}
|
|
1958
|
+
else set([...lp, key], v === '' ? null : v)
|
|
1959
|
+
},
|
|
1960
|
+
})))
|
|
1961
|
+
gridKids.push(h(FormField, { label: t('formReviewType'), key: 'rt', help: t('helpReviewType') },
|
|
1962
|
+
h(FormSelect, { value: P([...lp, 'review_type'], 'ai'), options: [['ai', t('reviewAi')], ['human', t('reviewHuman')], ['none', t('reviewNone')]], onChange: (v) => set([...lp, 'review_type'], v) })))
|
|
1963
|
+
gridKids.push(h(FormField, { label: t('formMaxRework'), key: 'mr' },
|
|
1964
|
+
h(FormNum, { value: P([...lp, 'max_rework'], null), min: 0, onChange: (v) => set([...lp, 'max_rework'], v) })))
|
|
1965
|
+
|
|
1966
|
+
const gateKids = []
|
|
1967
|
+
gateKids.push(h('div', { style: { display: 'flex', alignItems: 'center', margin: '6px 0' }, key: 'ghd' },
|
|
1968
|
+
h('b', { style: { fontSize: 12, letterSpacing: '.02em' } }, t('formGates'), h(Help, { text: t('helpGates') })),
|
|
1969
|
+
h('button', { className: 'dswfe-btn', style: { marginLeft: 'auto' }, onClick: () => controller.setEditorText(fmAppend(ed.text, gatesPath, { name: '', type: 'ai_criteria_review', min_score: 80 })) }, t('formAddGate'))))
|
|
1970
|
+
for (let gi = 0; gi < gateCount; gi++) {
|
|
1971
|
+
const gp = [...gatesPath, gi]
|
|
1972
|
+
gateKids.push(h('div', { className: 'dswfe-fgrid', key: 'g' + gi, style: { alignItems: 'end' } },
|
|
1973
|
+
h(FormField, { label: t('formGateName') }, h(FormText, { value: P([...gp, 'name'], ''), onChange: (v) => set([...gp, 'name'], v) })),
|
|
1974
|
+
h(FormField, { label: t('formGateMin'), help: t('helpGateMin') }, h(FormNum, { value: P([...gp, 'min_score'], null), min: 0, onChange: (v) => set([...gp, 'min_score'], v) })),
|
|
1975
|
+
h('button', { className: 'dswfe-btn', 'data-danger': 'true', onClick: () => controller.setEditorText(fmDel(ed.text, gp)) }, '✕')))
|
|
1976
|
+
}
|
|
1977
|
+
|
|
1978
|
+
return [
|
|
1979
|
+
sec(t('propLink'),
|
|
1980
|
+
h('button', { className: 'dswfe-btn', 'data-danger': 'true', style: { marginLeft: 'auto' }, onClick: () => delLink(pi, li) }, t('formDelLink'))),
|
|
1981
|
+
h('div', { className: 'dswfe-fgrid', key: 'meta' }, gridKids),
|
|
1982
|
+
h(FormField, { label: t('formPrompt'), key: 'prompt', help: t('helpPrompt') },
|
|
1983
|
+
h(FormArea, { value: P([...lp, 'prompt'], ''), rows: 6, onChange: (v) => set([...lp, 'prompt'], v) })),
|
|
1984
|
+
h(FormField, { label: t('formAcceptance'), key: 'acc', help: t('helpAcceptance') },
|
|
1985
|
+
h(FormArea, { value: P([...lp, 'acceptance_criteria'], ''), rows: 2, onChange: (v) => set([...lp, 'acceptance_criteria'], v) })),
|
|
1986
|
+
h('div', { className: 'dswfe-fgrid', style: { marginTop: 6 }, key: 'flow' },
|
|
1987
|
+
h(FormField, { label: t('formOnSuccess') }, h(FormSelect, { value: P([...lp, 'on_success'], 'next'), options: flowOptions(['next', 'end'], P([...lp, 'on_success'], 'next')), onChange: (v) => set([...lp, 'on_success'], v) })),
|
|
1988
|
+
h(FormField, { label: t('formOnGateFail') }, h(FormSelect, { value: P([...lp, 'on_gate_fail'], 'break'), options: flowOptions(['break'], P([...lp, 'on_gate_fail'], 'break')), onChange: (v) => set([...lp, 'on_gate_fail'], v) }))),
|
|
1989
|
+
h('div', { className: 'dswfe-fgates', key: 'gates' }, gateKids),
|
|
1990
|
+
]
|
|
1991
|
+
}
|
|
1992
|
+
|
|
1993
|
+
const propsKids = R.kind === 'phase' ? propsPhase(R.pi)
|
|
1994
|
+
: R.kind === 'link' ? propsLink(R.pi, R.li)
|
|
1995
|
+
: propsGlobal
|
|
1996
|
+
|
|
1997
|
+
return h('div', { className: 'dswfe-canvas' },
|
|
1998
|
+
canvas,
|
|
1999
|
+
h('div', { className: 'dswfe-props' }, propsKids))
|
|
2000
|
+
}
|
|
2001
|
+
|
|
2002
|
+
|
|
2003
|
+
function EditorPane({ state, controller, t }) {
|
|
2004
|
+
const ed = state.editor
|
|
2005
|
+
const taRef = useRef(null)
|
|
2006
|
+
const gutterRef = useRef(null)
|
|
2007
|
+
// 子模式:'form'(画布:左节点图+右属性面板)| 'yaml'(YAML 文本)——同一份 ed.text 双向实时同步
|
|
2008
|
+
const [subMode, setSubMode] = useState('form')
|
|
2009
|
+
const docOk = useMemo(() => !!fmDoc(ed ? ed.text : ''), [ed && ed.text])
|
|
2010
|
+
const mode = subMode === 'form' && !docOk ? 'yaml' : subMode
|
|
2011
|
+
if (!ed) return null
|
|
2012
|
+
const lines = ed.text.split('\n')
|
|
2013
|
+
const diag = ed.diagnostics || { errors: [], warnings: [] }
|
|
2014
|
+
const errCount = diag.errors.length
|
|
2015
|
+
const warnCount = diag.warnings.length
|
|
2016
|
+
const onScroll = () => { if (gutterRef.current && taRef.current) gutterRef.current.scrollTop = taRef.current.scrollTop }
|
|
2017
|
+
const jump = (line) => {
|
|
2018
|
+
const ta = taRef.current
|
|
2019
|
+
if (!ta) return
|
|
2020
|
+
const pos = lines.slice(0, line - 1).reduce((acc, l) => acc + l.length + 1, 0)
|
|
2021
|
+
ta.focus()
|
|
2022
|
+
ta.setSelectionRange(pos, pos)
|
|
2023
|
+
ta.scrollTop = Math.max(0, (line - 6) * 19)
|
|
2024
|
+
}
|
|
2025
|
+
const onKeyDown = (e) => {
|
|
2026
|
+
const ta = taRef.current
|
|
2027
|
+
if (!ta) return
|
|
2028
|
+
if (e.key === 'Tab') {
|
|
2029
|
+
e.preventDefault()
|
|
2030
|
+
const s = ta.selectionStart
|
|
2031
|
+
const next = ed.text.slice(0, s) + ' ' + ed.text.slice(ta.selectionEnd)
|
|
2032
|
+
controller.setEditorText(next)
|
|
2033
|
+
requestAnimationFrame(() => { ta.setSelectionRange(s + 2, s + 2) })
|
|
2034
|
+
} else if ((e.metaKey || e.ctrlKey) && (e.key === 's' || e.key === 'S')) {
|
|
2035
|
+
e.preventDefault()
|
|
2036
|
+
void controller.saveEditor(false)
|
|
2037
|
+
}
|
|
2038
|
+
}
|
|
2039
|
+
return h('div', { className: 'dswfe-detail dswfe-editor' },
|
|
2040
|
+
h('div', { className: 'dswfe-detail-head' },
|
|
2041
|
+
h('h3', { className: 'dswfe-detail-title' }, (ed.mode === 'create' ? t('editorCreate') : t('editorTitle')) + (ed.name ? ':' + ed.name : '')),
|
|
2042
|
+
h('div', { className: 'dswfe-tabs', style: { borderBottom: 'none', margin: '0 6px 0 0' } },
|
|
2043
|
+
h('button', { className: 'dswfe-tab', 'data-on': mode === 'form' ? 'true' : undefined, onClick: () => setSubMode('form'), disabled: !docOk, title: !docOk ? t('formUnparseable') : undefined }, t('formMode')),
|
|
2044
|
+
h('button', { className: 'dswfe-tab', 'data-on': mode === 'yaml' ? 'true' : undefined, onClick: () => setSubMode('yaml') }, t('yamlMode'))),
|
|
2045
|
+
h('div', { className: 'dswfe-actions' },
|
|
2046
|
+
ed.dirty ? h('span', { className: 'dswfe-badge', 'data-kind': 'warn' }, t('unsaved')) : null,
|
|
2047
|
+
h('button', { className: 'dswfe-btn', onClick: () => void controller.validateEditor(), disabled: ed.busy }, '✓ ' + t('validate')),
|
|
2048
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', onClick: () => void controller.saveEditor(false), disabled: ed.busy || errCount > 0 }, '💾 ' + t('save')),
|
|
2049
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.requestCloseEditor() }, t('cancel')))),
|
|
2050
|
+
ed.conflict ? h('div', { className: 'dswfe-conflict' },
|
|
2051
|
+
h('span', null, '⚠ ' + t('saveConflict') + ' ' + t('forcedHint')),
|
|
2052
|
+
h('button', { className: 'dswfe-btn', onClick: () => void controller.reloadEditor() }, t('reload')),
|
|
2053
|
+
h('button', { className: 'dswfe-btn', 'data-danger': 'true', onClick: () => void controller.saveEditor(true) }, t('overwrite'))) : null,
|
|
2054
|
+
ed.error ? h('div', { className: 'dswfe-error' }, ed.error) : null,
|
|
2055
|
+
mode === 'form'
|
|
2056
|
+
? h(FormEditor, { state, controller, t, ed })
|
|
2057
|
+
: h('div', { className: 'dswfe-editor-wrap' },
|
|
2058
|
+
h('div', { className: 'dswfe-gutter', ref: gutterRef }, lines.map((_, i) => h('div', { key: i }, i + 1))),
|
|
2059
|
+
h('textarea', {
|
|
2060
|
+
className: 'dswfe-textarea', ref: taRef, value: ed.text, spellCheck: false,
|
|
2061
|
+
onChange: (e) => controller.setEditorText(e.target.value),
|
|
2062
|
+
onScroll, onKeyDown,
|
|
2063
|
+
})),
|
|
2064
|
+
h('div', { className: 'dswfe-status' },
|
|
2065
|
+
h('span', null, t('linesCount', { n: lines.length })),
|
|
2066
|
+
ed.dirty ? null : h('span', null, t('saved')),
|
|
2067
|
+
ed.validatedAt ? h('span', { style: { opacity: .6 } }, '✓ ' + new Date(ed.validatedAt).toLocaleTimeString()) : null,
|
|
2068
|
+
errCount > 0 ? h('span', { className: 'dswfe-badge', 'data-kind': 'err' }, errCount + t('errOne')) : null,
|
|
2069
|
+
warnCount > 0 ? h('span', { className: 'dswfe-badge', 'data-kind': 'warn' }, warnCount + t('warnOne')) : null,
|
|
2070
|
+
errCount === 0 && warnCount === 0 && !ed.dirty ? h('span', { style: { opacity: .7 } }, t('noIssues')) : null),
|
|
2071
|
+
(errCount > 0 || warnCount > 0) ? h(DiagList, { t, diagnostics: diag, onJump: jump }) : null)
|
|
2072
|
+
}
|
|
2073
|
+
|
|
2074
|
+
// ── 弹窗 ─────────────────────────────────────────────────────────────────
|
|
2075
|
+
|
|
2076
|
+
function Modal({ title, onClose, children, width }) {
|
|
2077
|
+
useEffect(() => {
|
|
2078
|
+
const onKey = (e) => { if (e.key === 'Escape') onClose() }
|
|
2079
|
+
document.addEventListener('keydown', onKey)
|
|
2080
|
+
return () => document.removeEventListener('keydown', onKey)
|
|
2081
|
+
}, [onClose])
|
|
2082
|
+
return h('div', { className: 'dswfe-modal-backdrop', onMouseDown: (e) => { if (e.target === e.currentTarget) onClose() } },
|
|
2083
|
+
h('div', { className: 'dswfe-modal', style: width ? { width: 'min(' + width + 'px, 94vw)' } : undefined, role: 'dialog', 'aria-modal': 'true' },
|
|
2084
|
+
h('div', { style: { display: 'flex', alignItems: 'center' } },
|
|
2085
|
+
h('h3', null, title),
|
|
2086
|
+
h('button', { className: 'dswfe-btn', style: { marginLeft: 'auto', width: 28, height: 28, padding: 0, borderRadius: 28 }, onClick: onClose }, '✕')),
|
|
2087
|
+
children))
|
|
2088
|
+
}
|
|
2089
|
+
|
|
2090
|
+
function FieldInput({ label, value, onChange, placeholder, type }) {
|
|
2091
|
+
return h('label', { className: 'dswfe-field' }, label,
|
|
2092
|
+
h('input', { value, type: type || 'text', placeholder, spellCheck: false, onChange: (e) => onChange(e.target.value) }))
|
|
2093
|
+
}
|
|
2094
|
+
|
|
2095
|
+
function CreateDialog({ state, controller, t }) {
|
|
2096
|
+
const [name, setName] = useState('')
|
|
2097
|
+
const [dir, setDir] = useState('')
|
|
2098
|
+
const [display, setDisplay] = useState('')
|
|
2099
|
+
const ok = /^[^\\/\0\r\n.][^\\/\0\r\n]{0,79}$/.test(name.trim())
|
|
2100
|
+
return h(Modal, { title: t('editorCreate'), onClose: () => controller.setState({ dialog: null }) },
|
|
2101
|
+
h(FieldInput, { label: t('createName'), value: name, onChange: setName, placeholder: 'my-process' }),
|
|
2102
|
+
h(FieldInput, { label: t('createDir'), value: dir, onChange: setDir, placeholder: 'software' }),
|
|
2103
|
+
h(FieldInput, { label: t('createDisplayName'), value: display, onChange: setDisplay }),
|
|
2104
|
+
h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end' } },
|
|
2105
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ dialog: null }) }, t('cancel')),
|
|
2106
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', disabled: !ok || name.trim() === '', onClick: () => void controller.createBlank(name.trim(), dir.trim(), display.trim()) }, t('confirm'))),
|
|
2107
|
+
!ok && name.trim() !== '' ? h('div', { className: 'dswfe-error' }, t('nameRule')) : null)
|
|
2108
|
+
}
|
|
2109
|
+
|
|
2110
|
+
function CopyDialog({ state, controller, t }) {
|
|
2111
|
+
const dlg = state.dialog
|
|
2112
|
+
const from = dlg && dlg.fromId ? state.processes.find((p) => p.id === dlg.fromId) : undefined
|
|
2113
|
+
const [name, setName] = useState(from ? from.fileName + '-copy' : '')
|
|
2114
|
+
const [dir, setDir] = useState(from && from.source === 'user' ? (from.relPath.includes('/') ? from.relPath.split('/').slice(0, -1).join('/') : '') : '')
|
|
2115
|
+
return h(Modal, { title: t('editorCopy'), onClose: () => controller.setState({ dialog: null }) },
|
|
2116
|
+
h('div', { className: 'dswfe-kv' }, h('b', null, t('name') + ':'), from ? (from.display_name || from.name) + '(' + from.relPath + ')' : '—'),
|
|
2117
|
+
h(FieldInput, { label: t('copyName'), value: name, onChange: setName, placeholder: 'my-process' }),
|
|
2118
|
+
h(FieldInput, { label: t('createDir'), value: dir, onChange: setDir }),
|
|
2119
|
+
h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end' } },
|
|
2120
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ dialog: null }) }, t('cancel')),
|
|
2121
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', disabled: !from || name.trim() === '', onClick: () => void controller.copyProcess(from.id, name.trim(), dir.trim()) }, t('copy'))))
|
|
2122
|
+
}
|
|
2123
|
+
|
|
2124
|
+
function RenameDialog({ state, controller, t }) {
|
|
2125
|
+
const dlg = state.dialog
|
|
2126
|
+
const [name, setName] = useState(dlg ? dlg.name : '')
|
|
2127
|
+
return h(Modal, { title: t('renameTitle'), onClose: () => controller.setState({ dialog: null }) },
|
|
2128
|
+
h(FieldInput, { label: t('newName'), value: name, onChange: setName }),
|
|
2129
|
+
h('div', { style: { fontSize: 12, opacity: .7 } }, t('renameHint')),
|
|
2130
|
+
h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end' } },
|
|
2131
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ dialog: null }) }, t('cancel')),
|
|
2132
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', disabled: name.trim() === '', onClick: () => void controller.renameProcess(dlg.id, name.trim()) }, t('confirm'))))
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
function ConfirmDialog({ state, controller, t }) {
|
|
2136
|
+
const dlg = state.dialog
|
|
2137
|
+
return h(Modal, { title: t('confirm'), onClose: () => controller.setState({ dialog: null }) },
|
|
2138
|
+
h('div', null, dlg.message),
|
|
2139
|
+
h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end' } },
|
|
2140
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ dialog: null }) }, dlg.yes === 'discard' ? t('keepEditing') : t('cancel')),
|
|
2141
|
+
h('button', { className: 'dswfe-btn', 'data-danger': dlg.danger ? 'true' : undefined, onClick: () => dlg.onYes() }, dlg.yes === 'discard' ? t('discard') : t('confirm'))))
|
|
2142
|
+
}
|
|
2143
|
+
|
|
2144
|
+
function ImportDialog({ state, controller, t }) {
|
|
2145
|
+
const [over, setOver] = useState(false)
|
|
2146
|
+
const [dragOver, setDragOver] = useState(false)
|
|
2147
|
+
const [results, setResults] = useState(null)
|
|
2148
|
+
const [busy, setBusy] = useState(false)
|
|
2149
|
+
const doImport = async (fileList) => {
|
|
2150
|
+
const files = []
|
|
2151
|
+
for (const f of fileList) {
|
|
2152
|
+
if (f.size > 1024 * 1024) { files.push({ name: f.name, content: '' }); continue }
|
|
2153
|
+
// eslint-disable-next-line no-await-in-loop
|
|
2154
|
+
files.push({ name: f.name, content: await f.text() })
|
|
2155
|
+
}
|
|
2156
|
+
setBusy(true)
|
|
2157
|
+
try {
|
|
2158
|
+
const r = await controller.importFiles(files, over)
|
|
2159
|
+
setResults(r)
|
|
2160
|
+
controller.toast(t('toastImported', { n: r.filter((x) => x.status === 'created' || x.status === 'overwritten').length }))
|
|
2161
|
+
} catch (error) { controller.toast(String(error && error.message || error), 'err') } finally { setBusy(false) }
|
|
2162
|
+
}
|
|
2163
|
+
const statusLabel = { created: t('importCreated'), overwritten: t('importOverwritten'), exists: t('importExists'), invalid: t('importInvalid') }
|
|
2164
|
+
return h(Modal, { title: t('importTitle'), onClose: () => controller.setState({ dialog: null }), width: 620 },
|
|
2165
|
+
h('div', null, t('importHint')),
|
|
2166
|
+
h('label', { style: { display: 'flex', gap: 6, alignItems: 'center', fontSize: 12 } },
|
|
2167
|
+
h('input', { type: 'checkbox', checked: over, onChange: (e) => setOver(e.target.checked) }), t('importOverwrite')),
|
|
2168
|
+
h('div', {
|
|
2169
|
+
className: 'dswfe-drop', 'data-over': dragOver ? 'true' : undefined,
|
|
2170
|
+
onDragOver: (e) => { e.preventDefault(); setDragOver(true) },
|
|
2171
|
+
onDragLeave: () => setDragOver(false),
|
|
2172
|
+
onDrop: (e) => { e.preventDefault(); setDragOver(false); if (!busy) void doImport(Array.from(e.dataTransfer.files)) },
|
|
2173
|
+
},
|
|
2174
|
+
t('importHint'),
|
|
2175
|
+
h('div', { style: { marginTop: 10 } },
|
|
2176
|
+
h('input', { type: 'file', accept: '.yaml,.yml', multiple: true, disabled: busy, onChange: (e) => { const list = Array.from(e.target.files || []); e.target.value = ''; if (!busy) void doImport(list) } }))),
|
|
2177
|
+
busy ? h('div', null, t('loading')) : null,
|
|
2178
|
+
results ? h('div', { className: 'dswfe-diag' },
|
|
2179
|
+
h('div', { style: { fontWeight: 600 } }, t('importResults')),
|
|
2180
|
+
results.map((r, i) => h('div', { key: i, style: { display: 'flex', gap: 8, fontSize: 12 } },
|
|
2181
|
+
h('span', { style: { flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, r.name),
|
|
2182
|
+
h('span', { style: { color: r.status === 'created' || r.status === 'overwritten' ? 'var(--dsw-alias-state-success, #2e9e5b)' : r.status === 'invalid' ? 'var(--dsw-alias-state-error, #c75050)' : 'inherit' } },
|
|
2183
|
+
statusLabel[r.status] || r.status),
|
|
2184
|
+
r.errors && r.errors.length ? h('span', { style: { opacity: .7 } }, r.errors[0].message) : null))) : null)
|
|
2185
|
+
}
|
|
2186
|
+
|
|
2187
|
+
function SettingsDialog({ state, controller, t }) {
|
|
2188
|
+
const [form, setForm] = useState(state.settings)
|
|
2189
|
+
const [busy, setBusy] = useState(false)
|
|
2190
|
+
useEffect(() => { if (!state.settings) void controller.loadSettings() }, [])
|
|
2191
|
+
useEffect(() => { if (state.settings && !form) setForm(state.settings) }, [state.settings])
|
|
2192
|
+
if (!form) return h(Modal, { title: t('settingsTitle'), onClose: () => controller.setState({ dialog: null }) }, t('loading'))
|
|
2193
|
+
const set = (k) => (v) => setForm({ ...form, [k]: v })
|
|
2194
|
+
return h(Modal, { title: t('settingsTitle'), onClose: () => controller.setState({ dialog: null }) },
|
|
2195
|
+
h(FieldInput, { label: t('settingsUserRoot'), value: form.userRoot, onChange: set('userRoot') }),
|
|
2196
|
+
h(FieldInput, { label: t('settingsBundledRoot'), value: form.bundledRoot, onChange: set('bundledRoot') }),
|
|
2197
|
+
h('label', { className: 'dswfe-field' }, t('settingsMaxDepth'),
|
|
2198
|
+
h('select', { value: String(form.maxDepth), onChange: (e) => set('maxDepth')(Number(e.target.value)) },
|
|
2199
|
+
[1, 2, 3, 4, 5, 6].map((n) => h('option', { key: n, value: n }, n)))),
|
|
2200
|
+
h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end' } },
|
|
2201
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ dialog: null }) }, t('cancel')),
|
|
2202
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', disabled: busy, onClick: async () => {
|
|
2203
|
+
setBusy(true)
|
|
2204
|
+
try { await controller.saveSettings(form); controller.toast(t('settingsSaved')); controller.setState({ dialog: null }) }
|
|
2205
|
+
catch (error) { controller.toast(String(error && error.message || error), 'err') } finally { setBusy(false) }
|
|
2206
|
+
} }, t('save'))))
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
// ── ⚡ AI 生成(kit ActionShareDialog + completedView 预览确认) ────────────
|
|
2210
|
+
|
|
2211
|
+
const AI_PROMPT = `请为下面的需求设计一个工作流(Process:多阶段 phase、多环节 link 的 agent 工作流模板),输出严格的 YAML。
|
|
2212
|
+
|
|
2213
|
+
需求:{{requirement}}
|
|
2214
|
+
复杂度:{{complexity}}
|
|
2215
|
+
{{reference}}
|
|
2216
|
+
|
|
2217
|
+
硬性要求:
|
|
2218
|
+
1. 只输出一个 \`\`\`yaml 代码块,不要任何其他解释文字。
|
|
2219
|
+
2. 顶层结构:process(name / guid:生成一个 uuid v4 / display_name / description / category: software / complexity / version: 1.0.0)+ limits(max_step_executions / max_total_tokens,可为 null)+ abnormal_handler(可为 null)+ phases 列表。
|
|
2220
|
+
3. 每个 phase:id、name、spec、acceptance_criteria、links 列表。每个 link:id(全工作流唯一,建议简短助记如 req-01)、name、prompt(明确可执行的指令,含产物落点)、executor、expert(专家库里的名字,不确定就 null)、skills(列表)、expected_artifacts([{name, type: file, path}])、gates([{name, type: ai_criteria_review, min_score}],可选)、on_success(next / end / <环节id>)、on_gate_fail(break / <环节id> / goto:<环节id>)、on_rating_fail: break、max_rework(0-3)。
|
|
2221
|
+
4. on_success / on_gate_fail 引用的环节 id 必须真实存在;最后一步用 on_success: end。
|
|
2222
|
+
5. 阶段数量与环节粒度贴合复杂度:轻需求 1-2 阶段 3-6 环节;复杂需求 3+ 阶段。`
|
|
2223
|
+
|
|
2224
|
+
function AiPreview({ controller, t, output, close }) {
|
|
2225
|
+
const parsedBlock = useMemo(() => {
|
|
2226
|
+
const blocks = [...String(output || '').matchAll(/```(?:yaml|yml)?\s*\n([\s\S]*?)```/g)]
|
|
2227
|
+
if (blocks.length > 0) return blocks[blocks.length - 1][1].trim()
|
|
2228
|
+
const s = String(output || '').trim()
|
|
2229
|
+
return s.startsWith('process:') || s.startsWith('#') ? s : ''
|
|
2230
|
+
}, [output])
|
|
2231
|
+
const [yaml, setYaml] = useState(parsedBlock)
|
|
2232
|
+
const [diag, setDiag] = useState(null)
|
|
2233
|
+
const [name, setName] = useState('')
|
|
2234
|
+
const [busy, setBusy] = useState(false)
|
|
2235
|
+
useEffect(() => {
|
|
2236
|
+
if (!yaml) { setDiag(null); return }
|
|
2237
|
+
let live = true
|
|
2238
|
+
api('/validate', { method: 'POST', body: { yaml } }).then((d) => { if (live) setDiag({ errors: d.errors, warnings: d.warnings, meta: d.meta }) }).catch(() => {})
|
|
2239
|
+
return () => { live = false }
|
|
2240
|
+
}, [yaml])
|
|
2241
|
+
useEffect(() => {
|
|
2242
|
+
if (diag && diag.meta && diag.meta.name && !name) setName(diag.meta.name)
|
|
2243
|
+
}, [diag])
|
|
2244
|
+
if (!parsedBlock) {
|
|
2245
|
+
return h('div', null, h('div', { className: 'dswfe-error' }, t('aiParseFail')), h('pre', { className: 'dswfe-pre', style: { maxHeight: 200 } }, String(output || '')))
|
|
2246
|
+
}
|
|
2247
|
+
const errCount = diag ? diag.errors.length : 0
|
|
2248
|
+
return h('div', { style: { display: 'flex', flexDirection: 'column', gap: 10, minWidth: 'min(680px, 80vw)' } },
|
|
2249
|
+
h('div', { style: { fontWeight: 600 } }, t('aiPreviewTitle')),
|
|
2250
|
+
h('textarea', { value: yaml, onChange: (e) => setYaml(e.target.value), spellCheck: false, style: { minHeight: 260, fontFamily: 'ui-monospace, Menlo, monospace', fontSize: 12, lineHeight: 1.5, border: '1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.3))', borderRadius: 8, padding: 8, background: 'var(--dsw-alias-bg-layer-2,transparent)', color: 'inherit', whiteSpace: 'pre' } }),
|
|
2251
|
+
diag ? h(DiagList, { t, diagnostics: diag, onJump: () => {} }) : h('div', { style: { fontSize: 12, opacity: .7 } }, t('validating')),
|
|
2252
|
+
h('div', { style: { display: 'flex', gap: 8, alignItems: 'center' } },
|
|
2253
|
+
h('input', { value: name, onChange: (e) => setName(e.target.value), placeholder: t('aiSaveName'), spellCheck: false, style: { flex: 1, border: '1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.3))', background: 'var(--dsw-alias-bg-layer-2,transparent)', color: 'inherit', borderRadius: 8, padding: '6px 10px', font: 'inherit' } }),
|
|
2254
|
+
h('button', {
|
|
2255
|
+
className: 'dswfe-btn', 'data-primary': 'true', disabled: busy || errCount > 0 || name.trim() === '',
|
|
2256
|
+
onClick: async () => {
|
|
2257
|
+
setBusy(true)
|
|
2258
|
+
try {
|
|
2259
|
+
const result = await api('/save', { method: 'POST', body: { mode: 'create', name: name.trim(), yaml } })
|
|
2260
|
+
await controller.refresh()
|
|
2261
|
+
controller.select(result.id)
|
|
2262
|
+
controller.toast(t('toastAiSaved'))
|
|
2263
|
+
close()
|
|
2264
|
+
} catch (error) { controller.toast(String(error && error.message || error), 'err') } finally { setBusy(false) }
|
|
2265
|
+
},
|
|
2266
|
+
}, t('aiSave'))))
|
|
2267
|
+
}
|
|
2268
|
+
|
|
2269
|
+
function AiDialog({ state, controller, t }) {
|
|
2270
|
+
const Dialog = useMemo(() => { const kit = getKit(); return kit ? kit.makeActionShareDialog(ReactGlobal || __React, {}) : null }, [])
|
|
2271
|
+
if (!Dialog) return h(Modal, { title: t('aiTitle'), onClose: () => controller.setState({ dialog: null }) }, h('div', { className: 'dswfe-error' }, t('kitMissing')))
|
|
2272
|
+
return h(Dialog, {
|
|
2273
|
+
title: '⚡ ' + t('aiTitle'),
|
|
2274
|
+
hint: t('aiHint'),
|
|
2275
|
+
params: [
|
|
2276
|
+
{ key: 'requirement', label: t('aiRequirement'), multiline: true, placeholder: t('aiRequirementPh') },
|
|
2277
|
+
{ key: 'complexity', label: t('aiComplexity'), placeholder: 'medium' },
|
|
2278
|
+
{ key: 'reference', label: t('aiReference'), placeholder: '' },
|
|
2279
|
+
],
|
|
2280
|
+
initialPrompt: AI_PROMPT,
|
|
2281
|
+
run: (prompt) => controller.aiRun(prompt).then((jobId) => ({ jobId })),
|
|
2282
|
+
poll: (jobId) => controller.aiPoll(jobId),
|
|
2283
|
+
labels: { run: t('aiBtn'), running: t('aiRunning'), done: t('aiDone'), failed: t('aiFailed'), copy: t('copyPrompt'), copied: t('copied'), outputLabel: t('aiOutput'), openSession: t('openSession') },
|
|
2284
|
+
onOpenSession: (sessionId) => controller.openSession(sessionId),
|
|
2285
|
+
completedView: ({ job, output, close }) => h(AiPreview, { controller, t, output, close }),
|
|
2286
|
+
onClose: () => controller.setState({ dialog: null }),
|
|
2287
|
+
})
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
// ── 面板根 ───────────────────────────────────────────────────────────────
|
|
2291
|
+
|
|
2292
|
+
function ProcessPanel({ controller, t, slotProps }) {
|
|
2293
|
+
const state = useControllerState(controller)
|
|
2294
|
+
// 当前会话变化(点侧栏会话行/新会话)→ 关面板
|
|
2295
|
+
const useSess = slotProps && slotProps.useSessions
|
|
2296
|
+
const current = useSess ? useSess((s) => s.current) : undefined
|
|
2297
|
+
const prevCurrent = useRef(current)
|
|
2298
|
+
useEffect(() => {
|
|
2299
|
+
if (prevCurrent.current !== current && prevCurrent.current !== undefined && controller.getSnapshot().panelOpen) controller.closePanel()
|
|
2300
|
+
prevCurrent.current = current
|
|
2301
|
+
}, [current])
|
|
2302
|
+
// Esc 关面板(弹窗自己处理 Esc,开着弹窗时不抢)
|
|
2303
|
+
useEffect(() => {
|
|
2304
|
+
if (!state.panelOpen) return
|
|
2305
|
+
const onKey = (e) => {
|
|
2306
|
+
if (e.key !== 'Escape') return
|
|
2307
|
+
const s = controller.getSnapshot()
|
|
2308
|
+
if (s.dialog) return
|
|
2309
|
+
// 编辑器里按 Esc 先离开文本框(再按一次才关面板);其他地方直接关
|
|
2310
|
+
if (e.target && e.target.tagName === 'TEXTAREA') { e.target.blur(); return }
|
|
2311
|
+
controller.closePanel()
|
|
2312
|
+
}
|
|
2313
|
+
document.addEventListener('keydown', onKey)
|
|
2314
|
+
return () => document.removeEventListener('keydown', onKey)
|
|
2315
|
+
}, [state.panelOpen])
|
|
2316
|
+
// 中栏接管开合:panelOpen ↔ html[data-dswfe-active](useLayoutEffect:开/关都在绘制前生效)
|
|
2317
|
+
useLayoutEffect(() => {
|
|
2318
|
+
try {
|
|
2319
|
+
if (state.panelOpen) {
|
|
2320
|
+
for (const attr of PRC_OTHER_ACTIVE_ATTRS) document.documentElement.removeAttribute(attr)
|
|
2321
|
+
document.documentElement.setAttribute(PRC_ACTIVE_ATTR, '')
|
|
2322
|
+
document.dispatchEvent(new CustomEvent(ACTIVATE_EVENT, { detail: PANEL_NAME }))
|
|
2323
|
+
} else {
|
|
2324
|
+
document.documentElement.removeAttribute(PRC_ACTIVE_ATTR)
|
|
2325
|
+
}
|
|
2326
|
+
} catch {}
|
|
2327
|
+
}, [state.panelOpen])
|
|
2328
|
+
// 点侧栏会话行自动关面板(自家入口子树豁免)
|
|
2329
|
+
useEffect(() => {
|
|
2330
|
+
const onClickRow = (e) => {
|
|
2331
|
+
if (!controller.getSnapshot().panelOpen) return
|
|
2332
|
+
const target = e.target
|
|
2333
|
+
if (!(target instanceof Element)) return
|
|
2334
|
+
if (target.closest('[' + ENTRY_ATTR + ']')) return
|
|
2335
|
+
if (target.closest(PRC_SIDEBAR_ROW_SELECTOR) || target.closest(PRC_SIDEBAR_COLUMN_SELECTOR)) controller.closePanel()
|
|
2336
|
+
}
|
|
2337
|
+
document.addEventListener('click', onClickRow, true)
|
|
2338
|
+
return () => document.removeEventListener('click', onClickRow, true)
|
|
2339
|
+
}, [controller])
|
|
2340
|
+
if (!state.panelOpen) return null
|
|
2341
|
+
const detail = state.editor ? h(EditorPane, { state, controller, t }) : h(DetailPane, { state, controller, t })
|
|
2342
|
+
return h('div', { className: 'dswfe-panel', 'data-dswfe-panel': '' },
|
|
2343
|
+
h(Toolbar, { state, controller, t }),
|
|
2344
|
+
state.error ? h('div', { className: 'dswfe-error' }, state.error) : null,
|
|
2345
|
+
state.lastError ? h('div', { className: 'dswfe-error' }, 'store: ' + state.lastError) : null,
|
|
2346
|
+
h('div', { className: 'dswfe-body' },
|
|
2347
|
+
state.view === 'exec' ? h(ExecView, { state, controller, t }) : h('div', { style: { display: 'contents' } }, h(ListPane, { state, controller, t }), detail)),
|
|
2348
|
+
state.dialog && state.dialog.type === 'create' ? h(CreateDialog, { state, controller, t }) : null,
|
|
2349
|
+
state.dialog && state.dialog.type === 'copy' ? h(CopyDialog, { state, controller, t }) : null,
|
|
2350
|
+
state.dialog && state.dialog.type === 'rename' ? h(RenameDialog, { state, controller, t }) : null,
|
|
2351
|
+
state.dialog && state.dialog.type === 'confirm' ? h(ConfirmDialog, { state, controller, t }) : null,
|
|
2352
|
+
state.dialog && state.dialog.type === 'import' ? h(ImportDialog, { state, controller, t }) : null,
|
|
2353
|
+
state.dialog && state.dialog.type === 'settings' ? h(SettingsDialog, { state, controller, t }) : null,
|
|
2354
|
+
state.dialog && state.dialog.type === 'ai' ? h(AiDialog, { state, controller, t }) : null,
|
|
2355
|
+
state.dialog && state.dialog.type === 'newrun' ? h(NewRunDialog, { state, controller, t }) : null,
|
|
2356
|
+
state.dialog && state.dialog.type === 'fileview' ? h(FileViewDialog, { state, controller, t }) : null,
|
|
2357
|
+
state.dialog && state.dialog.type === 'linkfiles' ? h(LinkFilesDialog, { state, controller, t }) : null,
|
|
2358
|
+
state.toast ? h('div', { className: 'dswfe-toast', 'data-kind': state.toast.kind }, state.toast.text) : null)
|
|
2359
|
+
}
|
|
2360
|
+
|
|
2361
|
+
// ── 执行视图(v0.2)─────────────────────────────────────────────────────
|
|
2362
|
+
|
|
2363
|
+
const LINK_STATE_KEY = { running: 'linkRunning', done: 'linkDone', gate_failed: 'linkGateFailed', skipped: 'linkSkipped', failed: 'linkFailed', abandoned: 'linkAbandoned', awaiting_review: 'linkAwaitingReview', approved: 'linkApproved', rejected: 'linkRejected' }
|
|
2364
|
+
|
|
2365
|
+
const STATUS_KEY = { queued: 'statusQueued', running: 'statusRunning', paused: 'statusPaused', awaiting: 'statusAwaiting', awaiting_review: 'statusAwaitingReview', done: 'statusDone', stopped: 'statusStopped', failed: 'statusFailed' }
|
|
2366
|
+
|
|
2367
|
+
function StatusPill({ t, status }) {
|
|
2368
|
+
const key = STATUS_KEY[status] || 'status' + String(status || '')[0].toUpperCase() + String(status || '').slice(1)
|
|
2369
|
+
return h('span', { className: 'dswfe-pill', 'data-status': status }, t(key))
|
|
2370
|
+
}
|
|
2371
|
+
|
|
2372
|
+
/** 每个环节的最新一次执行记录。 */
|
|
2373
|
+
function latestAttempts(run) {
|
|
2374
|
+
const map = new Map()
|
|
2375
|
+
for (const t of run.trail || []) {
|
|
2376
|
+
const prev = map.get(t.linkId)
|
|
2377
|
+
if (!prev || t.startedAt >= prev.startedAt) {
|
|
2378
|
+
// 最新记录缺 sessionId(如 skip 记录)时继承上一次的,跳转会话不丢
|
|
2379
|
+
map.set(t.linkId, !t.sessionId && prev && prev.sessionId ? { ...t, sessionId: prev.sessionId } : t)
|
|
2380
|
+
}
|
|
2381
|
+
}
|
|
2382
|
+
return map
|
|
2383
|
+
}
|
|
2384
|
+
|
|
2385
|
+
function runProgress(run) {
|
|
2386
|
+
const latest = latestAttempts(run)
|
|
2387
|
+
const total = new Set([...indexLinksOf(run).keys()]).size
|
|
2388
|
+
let done = 0
|
|
2389
|
+
for (const [linkId] of indexLinksOf(run)) {
|
|
2390
|
+
const st = latest.get(linkId) && latest.get(linkId).status
|
|
2391
|
+
if (st === 'done' || st === 'skipped') done++
|
|
2392
|
+
}
|
|
2393
|
+
return { done, total }
|
|
2394
|
+
}
|
|
2395
|
+
function indexLinksOf(run) {
|
|
2396
|
+
const phases = run.snapshot && Array.isArray(run.snapshot.phases) ? run.snapshot.phases : []
|
|
2397
|
+
const map = new Map()
|
|
2398
|
+
for (const ph of phases) for (const ln of (Array.isArray(ph.links) ? ph.links : [])) if (ln.id) map.set(ln.id, { phase: ph, link: ln })
|
|
2399
|
+
return map
|
|
2400
|
+
}
|
|
2401
|
+
|
|
2402
|
+
// ── token 用量展示(v0.5.2)──────────────────────────────────────────────
|
|
2403
|
+
|
|
2404
|
+
/** 环节卡用量 = 环节执行 + 门禁评审两份合并(都缺返回 null)。 */
|
|
2405
|
+
function linkUsage(attempt) {
|
|
2406
|
+
if (!attempt || (!attempt.usage && !attempt.gateUsage)) return null
|
|
2407
|
+
const sum = (a, b) => (a || 0) + (b || 0)
|
|
2408
|
+
const u = attempt.usage, g = attempt.gateUsage
|
|
2409
|
+
return {
|
|
2410
|
+
inputTokens: sum(u && u.inputTokens, g && g.inputTokens),
|
|
2411
|
+
outputTokens: sum(u && u.outputTokens, g && g.outputTokens),
|
|
2412
|
+
totalTokens: sum(u && u.totalTokens, g && g.totalTokens),
|
|
2413
|
+
calls: sum(u && u.calls, g && g.calls),
|
|
2414
|
+
}
|
|
2415
|
+
}
|
|
2416
|
+
|
|
2417
|
+
/** 优先用宿主上报的 totalTokens,缺失时退回 input+output。 */
|
|
2418
|
+
function usageTotalOf(u) {
|
|
2419
|
+
if (!u) return 0
|
|
2420
|
+
return u.totalTokens > 0 ? u.totalTokens : (u.inputTokens || 0) + (u.outputTokens || 0)
|
|
2421
|
+
}
|
|
2422
|
+
|
|
2423
|
+
/** 1234 → 1.2k;670 → 670(去尾零)。 */
|
|
2424
|
+
function fmtTokens(n) {
|
|
2425
|
+
if (!Number.isFinite(n) || n <= 0) return '0'
|
|
2426
|
+
if (n >= 1e6) return (n / 1e6).toFixed(1).replace(/\.0$/, '') + 'M'
|
|
2427
|
+
if (n >= 1e3) return (n / 1e3).toFixed(1).replace(/\.0$/, '') + 'k'
|
|
2428
|
+
return String(Math.round(n))
|
|
2429
|
+
}
|
|
2430
|
+
|
|
2431
|
+
/** react-dom:只为把问号气泡挂到 body(祖先带 opacity,就地渲染必然是半透明浅灰底)。 */
|
|
2432
|
+
let __ReactDOM = null
|
|
2433
|
+
try { __ReactDOM = require('react-dom') } catch {}
|
|
2434
|
+
function portalHost() { return __ReactDOM && typeof __ReactDOM.createPortal === 'function' ? __ReactDOM : null }
|
|
2435
|
+
|
|
2436
|
+
/**
|
|
2437
|
+
* 字段说明问号:自绘气泡(原生 title 在这套壳里常被重渲染吞掉),
|
|
2438
|
+
* 提示用 position:fixed 的浮层按图标坐标定位:属性栏/画布栏都是滚动容器,::after 会被裁切或挤压。
|
|
2439
|
+
*/
|
|
2440
|
+
function Help({ text }) {
|
|
2441
|
+
const ref = useRef(null)
|
|
2442
|
+
const [pos, setPos] = useState(null)
|
|
2443
|
+
if (!text) return null
|
|
2444
|
+
const W = 260
|
|
2445
|
+
const show = () => {
|
|
2446
|
+
const el = ref.current
|
|
2447
|
+
if (!el) return
|
|
2448
|
+
const r = el.getBoundingClientRect()
|
|
2449
|
+
const vw = window.innerWidth || 1280
|
|
2450
|
+
const vh = window.innerHeight || 800
|
|
2451
|
+
const estH = Math.max(1, Math.ceil([...String(text)].reduce((n, ch) => n + (/[\u2E80-\u9FFF\uF900-\uFAFF\uFF00-\uFFEF\u3000-\u303F]/.test(ch) ? 11.5 : 6.4), 0) / (W - 20))) * 17 + 16
|
|
2452
|
+
// 弹窗里的气泡必须留在弹窗内:弹窗遮罩的 z-index 是 2147482900,气泡落在外层会被压暗、被弹窗切掉上半截。
|
|
2453
|
+
const dlgEl = el.closest('[role="dialog"], dialog, [class*="modal"]')
|
|
2454
|
+
const dlg = dlgEl ? dlgEl.getBoundingClientRect() : null
|
|
2455
|
+
const minL = dlg ? dlg.left + 10 : 8
|
|
2456
|
+
const maxR = dlg ? dlg.right - 10 : vw - 8
|
|
2457
|
+
const minT = dlg ? dlg.top + 10 : 8
|
|
2458
|
+
const maxB = dlg ? dlg.bottom - 10 : vh - 8
|
|
2459
|
+
let left
|
|
2460
|
+
let top
|
|
2461
|
+
if (dlg && r.right + 14 + W <= maxR) {
|
|
2462
|
+
// 右侧有地方就放右侧,不去盖下方的按钮和诊断区
|
|
2463
|
+
left = r.right + 14
|
|
2464
|
+
top = Math.max(minT, Math.min(r.top + r.height / 2 - estH / 2, maxB - estH))
|
|
2465
|
+
} else {
|
|
2466
|
+
left = Math.max(minL, Math.min(r.left - 6, maxR - W))
|
|
2467
|
+
top = r.bottom + 8
|
|
2468
|
+
if (top + estH > maxB) top = Math.max(minT, r.top - estH - 8)
|
|
2469
|
+
}
|
|
2470
|
+
setPos({ left, top })
|
|
2471
|
+
}
|
|
2472
|
+
const hide = () => setPos(null)
|
|
2473
|
+
const tip = pos ? h('span', { className: 'dswfe-tip', style: { left: pos.left + 'px', top: pos.top + 'px', width: W + 'px' } }, text) : null
|
|
2474
|
+
const host = tip ? portalHost() : null
|
|
2475
|
+
return h('span', {
|
|
2476
|
+
className: 'dswfe-help', ref, tabIndex: 0, role: 'note', 'aria-label': text,
|
|
2477
|
+
onMouseEnter: show, onMouseLeave: hide, onFocus: show, onBlur: hide,
|
|
2478
|
+
}, '?', tip ? (host ? host.createPortal(tip, document.body) : tip) : null)
|
|
2479
|
+
}
|
|
2480
|
+
|
|
2481
|
+
/** 毫秒 → 「12 分 30 秒」;缺值/未知返回 unknown(默认 —)。 */
|
|
2482
|
+
function fmtDuration(ms, unknown) {
|
|
2483
|
+
if (!Number.isFinite(ms) || ms < 0) return unknown || '—'
|
|
2484
|
+
const total = Math.round(ms / 1000)
|
|
2485
|
+
const hrs = Math.floor(total / 3600)
|
|
2486
|
+
const min = Math.floor((total % 3600) / 60)
|
|
2487
|
+
const sec = total % 60
|
|
2488
|
+
if (hrs > 0) return hrs + ' 小时 ' + min + ' 分'
|
|
2489
|
+
if (min > 0) return min + ' 分 ' + sec + ' 秒'
|
|
2490
|
+
return sec + ' 秒'
|
|
2491
|
+
}
|
|
2492
|
+
|
|
2493
|
+
/** 环节耗时:结束时间 - 开始时间(老记录没有 finishedAt 时给 null)。 */
|
|
2494
|
+
function attemptDuration(attempt) {
|
|
2495
|
+
if (!attempt || !attempt.startedAt) return null
|
|
2496
|
+
const end = attempt.finishedAt || (attempt.status === 'running' ? Date.now() : null)
|
|
2497
|
+
return end ? Math.max(0, end - attempt.startedAt) : null
|
|
2498
|
+
}
|
|
2499
|
+
|
|
2500
|
+
/** 执行方式文案:AI 评审 / 人工评审 / 无需评审(结构页与概览共用)。 */
|
|
2501
|
+
function execLabel(t, node) {
|
|
2502
|
+
const rt = (node && node.reviewType) || 'ai'
|
|
2503
|
+
if (rt === 'human') return t('execHuman')
|
|
2504
|
+
if (rt === 'none') return t('execNone')
|
|
2505
|
+
return t('execAI')
|
|
2506
|
+
}
|
|
2507
|
+
|
|
2508
|
+
function UsageBadge({ t, usage }) {
|
|
2509
|
+
if (!usage || usage.calls <= 0) return null
|
|
2510
|
+
return h('span', {
|
|
2511
|
+
className: 'dswfe-badge',
|
|
2512
|
+
title: t('usageTitle', { input: fmtTokens(usage.inputTokens), output: fmtTokens(usage.outputTokens), calls: usage.calls }),
|
|
2513
|
+
}, '⚡ ' + fmtTokens(usageTotalOf(usage)))
|
|
2514
|
+
}
|
|
2515
|
+
|
|
2516
|
+
function RunList({ state, controller, t }) {
|
|
2517
|
+
const runs = state.runs.list
|
|
2518
|
+
const running = (r) => ['queued', 'running', 'paused', 'awaiting'].includes(r.status)
|
|
2519
|
+
const elapsed = (r) => fmtDuration((r.finishedAt || (running(r) ? Date.now() : r.updatedAt)) - r.createdAt, t('durationUnknown'))
|
|
2520
|
+
const tokens = (r) => (r.usage && r.usage.calls > 0 ? fmtTokens(usageTotalOf(r.usage)) : '—')
|
|
2521
|
+
return h('div', { className: 'dswfe-runlist' },
|
|
2522
|
+
runs.length === 0
|
|
2523
|
+
? h('div', { style: { padding: '16px 8px', color: 'var(--dsw-text-secondary, gray)', fontSize: 12 } }, t('noRuns'), h('div', { style: { marginTop: 4, opacity: .8 } }, t('noRunsHint')))
|
|
2524
|
+
: runs.map((r) => h('div', {
|
|
2525
|
+
key: r.id, className: 'dswfe-runrow', role: 'button', tabIndex: 0,
|
|
2526
|
+
'data-selected': state.runId === r.id ? 'true' : undefined,
|
|
2527
|
+
onClick: () => controller.selectRun(r.id),
|
|
2528
|
+
onKeyDown: (e) => { if (e.key === 'Enter') { e.preventDefault(); controller.selectRun(r.id) } },
|
|
2529
|
+
},
|
|
2530
|
+
h('div', { className: 'dswfe-runrow-top' },
|
|
2531
|
+
h('span', { className: 'dswfe-pill', 'data-status': r.status }, t('status' + r.status[0].toUpperCase() + r.status.slice(1))),
|
|
2532
|
+
h('span', { className: 'dswfe-runrow-name', title: r.displayName || r.processName }, r.displayName || r.processName || r.runName),
|
|
2533
|
+
h('button', {
|
|
2534
|
+
className: 'dswfe-mini dswfe-rundel', title: t('deleteRun'), 'aria-label': t('deleteRun'),
|
|
2535
|
+
onClick: (e) => {
|
|
2536
|
+
e.stopPropagation()
|
|
2537
|
+
// 壳层里 window.confirm 常被吞掉 → 用面板自己的确认框
|
|
2538
|
+
controller.setState({ dialog: { type: 'confirm', message: t('deleteRunConfirm'), danger: true, onYes: () => { controller.setState({ dialog: null }); void controller.deleteRun(r.id) } } })
|
|
2539
|
+
},
|
|
2540
|
+
}, '🗑')),
|
|
2541
|
+
r.request
|
|
2542
|
+
? h('div', { className: 'dswfe-runrow-req', title: r.request }, '📝 ' + t('requestLabel') + ': ' + r.request)
|
|
2543
|
+
: null,
|
|
2544
|
+
h('div', { className: 'dswfe-runrow-meta' },
|
|
2545
|
+
h('span', null, t('progress', { done: r.doneLinks, total: r.totalLinks })),
|
|
2546
|
+
h('span', null, '⚡ ' + tokens(r)),
|
|
2547
|
+
h('span', null, t('durationTotal') + ':' + elapsed(r))))))
|
|
2548
|
+
}
|
|
2549
|
+
|
|
2550
|
+
function RunLinkCard({ t, run, phase, link, attempt, controller, index }) {
|
|
2551
|
+
const st = attempt ? attempt.status : 'pending'
|
|
2552
|
+
const isCurrent = run.current && run.current.linkId === link.id && ['running', 'queued', 'awaiting'].includes(run.status)
|
|
2553
|
+
const rework = (run.rework && run.rework[link.id]) || 0
|
|
2554
|
+
const active = ['queued', 'running', 'awaiting', 'paused'].includes(run.status)
|
|
2555
|
+
const dur = attemptDuration(attempt)
|
|
2556
|
+
return h('div', { className: 'dswfe-linkcard', 'data-state': st },
|
|
2557
|
+
h('div', { className: 'dswfe-linktop' },
|
|
2558
|
+
h('span', { className: 'dswfe-badge' }, t('linkNo', { n: index })),
|
|
2559
|
+
h('span', { style: { fontWeight: 600 } }, link.name || ''),
|
|
2560
|
+
isCurrent ? h('span', { className: 'dswfe-badge', 'data-kind': 'warn' }, t('currentStep')) : null,
|
|
2561
|
+
h('span', { className: 'grow' }),
|
|
2562
|
+
attempt && attempt.attempt > 1 ? h('span', { style: { fontSize: 11, opacity: .7 } }, t('attemptN', { n: attempt.attempt })) : null,
|
|
2563
|
+
rework > 0 ? h('span', { style: { fontSize: 11, color: '#b8860b' } }, t('reworkN', { n: rework })) : null,
|
|
2564
|
+
attempt && attempt.gate && attempt.gate.score !== null && attempt.gate.score !== undefined
|
|
2565
|
+
? h('span', { className: 'dswfe-badge', 'data-kind': attempt.gate.score >= (attempt.gate.minScore || 0) ? 'ok' : 'err', title: attempt.gate.reason },
|
|
2566
|
+
t('gateLabel') + ' ' + attempt.gate.score + ' / ' + (attempt.gate.minScore || 0)) : null,
|
|
2567
|
+
attempt && attempt.gate && attempt.gate.reason
|
|
2568
|
+
? h('span', { style: { fontSize: 11, opacity: .65, maxWidth: 420, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } },
|
|
2569
|
+
'↳ ' + attempt.gate.reason) : null,
|
|
2570
|
+
h(UsageBadge, { t, usage: linkUsage(attempt) }),
|
|
2571
|
+
h('span', { style: { fontSize: 11, opacity: .75 } }, t(LINK_STATE_KEY[st] || 'linkPending')),
|
|
2572
|
+
h('span', { className: 'dswfe-linkdur', title: t('durationTotal') }, fmtDuration(dur, t('durationUnknown')))),
|
|
2573
|
+
h('div', { style: { display: 'flex', gap: 6, flexWrap: 'wrap' } },
|
|
2574
|
+
attempt && attempt.sessionId ? h('button', { className: 'dswfe-mini', onClick: () => controller.openSession(attempt.sessionId) }, t('openSession')) : null,
|
|
2575
|
+
h('button', { className: 'dswfe-mini', onClick: () => controller.setState({ dialog: { type: 'linkfiles', runId: run.id, linkId: link.id, name: link.name || link.id } }) }, t('viewFiles')),
|
|
2576
|
+
!active && attempt ? h('button', { className: 'dswfe-mini', onClick: () => void controller.runAction('retry-link', { id: run.id, linkId: link.id }) }, t('retryLink')) : null,
|
|
2577
|
+
!active && st !== 'pending' ? h('button', { className: 'dswfe-mini', onClick: () => void controller.runAction('skip-link', { id: run.id, linkId: link.id }) }, t('skipLink')) : null))
|
|
2578
|
+
}
|
|
2579
|
+
|
|
2580
|
+
/** 字节数可读化(产物大小)。 */
|
|
2581
|
+
function fmtBytes(n) {
|
|
2582
|
+
if (!Number.isFinite(n) || n <= 0) return '0 B'
|
|
2583
|
+
if (n >= 1e6) return (n / 1e6).toFixed(1).replace(/\.0$/, '') + ' MB'
|
|
2584
|
+
if (n >= 1e3) return (n / 1e3).toFixed(1).replace(/\.0$/, '') + ' KB'
|
|
2585
|
+
return Math.round(n) + ' B'
|
|
2586
|
+
}
|
|
2587
|
+
|
|
2588
|
+
/** 文件修改时间 → HH:MM(产物列表用,区分是哪一轮写的)。 */
|
|
2589
|
+
function fmtClock(ms) {
|
|
2590
|
+
if (!Number.isFinite(ms) || ms <= 0) return ''
|
|
2591
|
+
const d = new Date(ms)
|
|
2592
|
+
const p = (n) => String(n).padStart(2, '0')
|
|
2593
|
+
return p(d.getHours()) + ':' + p(d.getMinutes())
|
|
2594
|
+
}
|
|
2595
|
+
|
|
2596
|
+
/** diffstat:+12 −3(git 风格带色)。 */
|
|
2597
|
+
function DiffStat({ additions, deletions }) {
|
|
2598
|
+
if (!additions && !deletions) return null
|
|
2599
|
+
return h('span', { style: { fontFamily: 'var(--dsw-font-family-mono, monospace)', fontSize: 11, whiteSpace: 'nowrap' } },
|
|
2600
|
+
additions > 0 ? h('span', { style: { color: '#4a9a4a' } }, '+' + additions) : null,
|
|
2601
|
+
additions > 0 && deletions > 0 ? ' ' : null,
|
|
2602
|
+
deletions > 0 ? h('span', { style: { color: '#c75050' } }, '−' + deletions) : null)
|
|
2603
|
+
}
|
|
2604
|
+
|
|
2605
|
+
/** diff 文本 → 按行着色(+/−/@@)。 */
|
|
2606
|
+
function DiffView({ text }) {
|
|
2607
|
+
if (!text) return h('div', { style: { fontSize: 12, opacity: .6, padding: 8 } }, '—')
|
|
2608
|
+
return h('pre', { className: 'dswfe-pre', style: { margin: 0, fontSize: 12, lineHeight: 1.55, overflow: 'auto' } },
|
|
2609
|
+
text.split('\n').map((l, i) => {
|
|
2610
|
+
const kind = l.startsWith('+') ? 'add' : l.startsWith('-') ? 'del' : l.startsWith('@@') ? 'hunk' : 'ctx'
|
|
2611
|
+
return h('span', { key: i, style: {
|
|
2612
|
+
display: 'block',
|
|
2613
|
+
whiteSpace: 'pre-wrap', wordBreak: 'break-all',
|
|
2614
|
+
color: kind === 'add' ? '#4a9a4a' : kind === 'del' ? '#c75050' : kind === 'hunk' ? '#8080c0' : undefined,
|
|
2615
|
+
background: kind === 'add' ? 'rgba(74,154,74,.08)' : kind === 'del' ? 'rgba(199,80,80,.08)' : undefined,
|
|
2616
|
+
} }, l === '' ? ' ' : l)
|
|
2617
|
+
}))
|
|
2618
|
+
}
|
|
2619
|
+
|
|
2620
|
+
/** 产物查看器:拉 /run-file(content 与 diff 一次拿全),变更/内容两个 tab。 */
|
|
2621
|
+
function ArtifactViewer({ t, controller, runId, path }) {
|
|
2622
|
+
const [file, setFile] = useState(null)
|
|
2623
|
+
const [error, setError] = useState(null)
|
|
2624
|
+
const [tab, setTab] = useState('diff')
|
|
2625
|
+
useEffect(() => {
|
|
2626
|
+
let alive = true
|
|
2627
|
+
setFile(null)
|
|
2628
|
+
setError(null)
|
|
2629
|
+
setTab('diff')
|
|
2630
|
+
controller.loadArtifact(runId, path)
|
|
2631
|
+
.then((f) => { if (alive) setFile(f) })
|
|
2632
|
+
.catch((e) => { if (alive) setError(String(e && e.message || e)) })
|
|
2633
|
+
return () => { alive = false }
|
|
2634
|
+
}, [runId, path])
|
|
2635
|
+
if (error) return h('div', { className: 'dswfe-empty' }, error)
|
|
2636
|
+
if (!file) return h('div', { className: 'dswfe-empty' }, t('loading'))
|
|
2637
|
+
const showTab = file.diff ? tab : 'content'
|
|
2638
|
+
return h('div', null,
|
|
2639
|
+
h('div', { style: { display: 'flex', gap: 6, alignItems: 'center', flexWrap: 'wrap', margin: '6px 0' } },
|
|
2640
|
+
h('span', { className: 'dswfe-chip' }, file.path),
|
|
2641
|
+
file.size != null ? h('span', { className: 'dswfe-chip' }, fmtBytes(file.size)) : null,
|
|
2642
|
+
h(DiffStat, { additions: file.additions, deletions: file.deletions }),
|
|
2643
|
+
file.truncated ? h('span', { className: 'dswfe-badge', 'data-kind': 'warn' }, t('fileTruncated', { size: fmtBytes(1048576) })) : null,
|
|
2644
|
+
h('span', { style: { flex: 1 } }),
|
|
2645
|
+
h('button', { className: 'dswfe-mini', 'data-active': showTab === 'diff' || undefined, onClick: () => setTab('diff') }, t('diffLabel')),
|
|
2646
|
+
h('button', { className: 'dswfe-mini', 'data-active': showTab === 'content' || undefined, onClick: () => setTab('content') }, t('contentLabel'))),
|
|
2647
|
+
file.binary ? h('div', { className: 'dswfe-empty' }, t('fileBinary'))
|
|
2648
|
+
: showTab === 'diff' ? h(DiffView, { text: file.diff })
|
|
2649
|
+
: h('pre', { className: 'dswfe-pre', style: { margin: 0, maxHeight: '58vh', overflow: 'auto' } }, file.content))
|
|
2650
|
+
}
|
|
2651
|
+
|
|
2652
|
+
/** 产物列表(看板):按环节分组,同一路径跨尝试取最新一条记录。 */
|
|
2653
|
+
function ArtifactList({ t, run, controller }) {
|
|
2654
|
+
const linkName = new Map()
|
|
2655
|
+
for (const ph of (run.snapshot && run.snapshot.phases) || []) {
|
|
2656
|
+
for (const ln of (ph && Array.isArray(ph.links) ? ph.links : [])) {
|
|
2657
|
+
if (ln && ln.id) linkName.set(ln.id, (ph.name ? ph.name + ' / ' : '') + (ln.name || ln.id))
|
|
2658
|
+
}
|
|
2659
|
+
}
|
|
2660
|
+
const latest = new Map() // path → { art, linkId }(trail 按时间序,后者覆盖)
|
|
2661
|
+
for (const a of run.trail || []) for (const art of a.artifacts || []) latest.set(art.path, { art, linkId: a.linkId })
|
|
2662
|
+
if (latest.size === 0) return h('div', { style: { fontSize: 12, opacity: .7, padding: '4px 2px' } }, t('artifactsNone'))
|
|
2663
|
+
const groups = new Map()
|
|
2664
|
+
for (const linkId of indexLinksOf(run).keys()) groups.set(linkId, [])
|
|
2665
|
+
for (const [path, v] of latest) {
|
|
2666
|
+
if (!groups.has(v.linkId)) groups.set(v.linkId, [])
|
|
2667
|
+
groups.get(v.linkId).push({ ...v.art, path })
|
|
2668
|
+
}
|
|
2669
|
+
const children = []
|
|
2670
|
+
for (const [linkId, arts] of groups) {
|
|
2671
|
+
if (!arts || arts.length === 0) continue
|
|
2672
|
+
children.push(h('div', { key: linkId, className: 'dswfe-artgroup' },
|
|
2673
|
+
h('div', { style: { fontSize: 11, opacity: .65, margin: '8px 0 2px' } }, linkName.get(linkId) || linkId),
|
|
2674
|
+
arts.map((a) => h('button', {
|
|
2675
|
+
key: a.path, className: 'dswfe-artrow', title: a.path,
|
|
2676
|
+
onClick: () => controller.setState({ dialog: { type: 'fileview', runId: run.id, path: a.path, name: a.name } }),
|
|
2677
|
+
},
|
|
2678
|
+
h('span', { style: { fontWeight: 500, whiteSpace: 'nowrap' } }, a.name),
|
|
2679
|
+
h('span', { style: { flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap', opacity: .7, fontSize: 12 } }, a.path),
|
|
2680
|
+
!a.exists ? h('span', { className: 'dswfe-badge', 'data-kind': 'err' }, t('artifactMissing')) : null,
|
|
2681
|
+
h(DiffStat, { additions: a.additions, deletions: a.deletions }),
|
|
2682
|
+
a.mtime ? h('span', { style: { fontSize: 11, opacity: .6, whiteSpace: 'nowrap' } }, fmtClock(a.mtime)) : null,
|
|
2683
|
+
a.exists && a.size != null ? h('span', { style: { fontSize: 11, opacity: .6, whiteSpace: 'nowrap' } }, fmtBytes(a.size)) : null))))
|
|
2684
|
+
}
|
|
2685
|
+
return h('div', { className: 'dswfe-artifacts' }, children)
|
|
2686
|
+
}
|
|
2687
|
+
|
|
2688
|
+
/** 产物预览弹窗(看板产物列表点开)。 */
|
|
2689
|
+
function FileViewDialog({ state, controller, t }) {
|
|
2690
|
+
const dlg = state.dialog
|
|
2691
|
+
return h(Modal, { title: t('fileViewTitle') + ':' + (dlg.name || dlg.path), onClose: () => controller.setState({ dialog: null }), width: 860 },
|
|
2692
|
+
h(ArtifactViewer, { t, controller, runId: dlg.runId, path: dlg.path }))
|
|
2693
|
+
}
|
|
2694
|
+
|
|
2695
|
+
/** 路径 → 树:{ dirs: Map, files: [] }。 */
|
|
2696
|
+
function buildFileTree(entries) {
|
|
2697
|
+
const root = { dirs: new Map(), files: [] }
|
|
2698
|
+
for (const e of entries) {
|
|
2699
|
+
const parts = String(e.path).split('/')
|
|
2700
|
+
let node = root
|
|
2701
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
2702
|
+
const seg = parts[i]
|
|
2703
|
+
if (seg === '') continue
|
|
2704
|
+
if (!node.dirs.has(seg)) node.dirs.set(seg, { dirs: new Map(), files: [] })
|
|
2705
|
+
node = node.dirs.get(seg)
|
|
2706
|
+
}
|
|
2707
|
+
node.files.push(e)
|
|
2708
|
+
}
|
|
2709
|
+
return root
|
|
2710
|
+
}
|
|
2711
|
+
|
|
2712
|
+
/** 文件树渲染:目录恒展开,文件行带 diffstat,点击选中。 */
|
|
2713
|
+
function FileTree({ t, entries, sel, onSelect }) {
|
|
2714
|
+
const render = (node, depth) => {
|
|
2715
|
+
const out = []
|
|
2716
|
+
for (const [name, child] of [...node.dirs.entries()].sort((a, b) => a[0].localeCompare(b[0]))) {
|
|
2717
|
+
out.push(h('div', { key: 'd:' + name, style: { padding: '3px 4px', fontSize: 12, opacity: .75, paddingLeft: 4 + depth * 14 } }, '📁 ' + name))
|
|
2718
|
+
out.push(...render(child, depth + 1))
|
|
2719
|
+
}
|
|
2720
|
+
for (const f of [...node.files].sort((a, b) => a.name.localeCompare(b.name))) {
|
|
2721
|
+
out.push(h('button', {
|
|
2722
|
+
key: f.path, className: 'dswfe-artrow', 'data-selected': sel === f.path || undefined,
|
|
2723
|
+
style: { paddingLeft: 4 + depth * 14, gap: 6 }, title: f.path, onClick: () => onSelect(f.path),
|
|
2724
|
+
},
|
|
2725
|
+
h('span', { style: { flex: 1, overflow: 'hidden', textOverflow: 'ellipsis', whiteSpace: 'nowrap' } }, f.name),
|
|
2726
|
+
f.mtime ? h('span', { style: { fontSize: 11, opacity: .6, whiteSpace: 'nowrap' } }, fmtClock(f.mtime)) : null,
|
|
2727
|
+
h(DiffStat, { additions: f.additions, deletions: f.deletions }),
|
|
2728
|
+
!f.exists ? h('span', { className: 'dswfe-badge', 'data-kind': 'err' }, t('artifactMissing')) : null))
|
|
2729
|
+
}
|
|
2730
|
+
return out
|
|
2731
|
+
}
|
|
2732
|
+
return h('div', null, render(buildFileTree(entries), 0))
|
|
2733
|
+
}
|
|
2734
|
+
|
|
2735
|
+
/** 环节产物弹窗:左侧该环节的文件树(同路径取最新一次尝试),右侧查看器。 */
|
|
2736
|
+
function LinkFilesDialog({ state, controller, t }) {
|
|
2737
|
+
const dlg = state.dialog
|
|
2738
|
+
const [files, setFiles] = useState(null)
|
|
2739
|
+
const [sel, setSel] = useState(null)
|
|
2740
|
+
const [err, setErr] = useState(null)
|
|
2741
|
+
useEffect(() => {
|
|
2742
|
+
let alive = true
|
|
2743
|
+
setFiles(null)
|
|
2744
|
+
setSel(null)
|
|
2745
|
+
setErr(null)
|
|
2746
|
+
controller.loadLinkFiles(dlg.runId, dlg.linkId)
|
|
2747
|
+
.then((list) => {
|
|
2748
|
+
if (!alive) return
|
|
2749
|
+
setFiles(list)
|
|
2750
|
+
const first = list.filter((f) => f.exists !== false)[0] || list[0]
|
|
2751
|
+
setSel(first ? first.path : null)
|
|
2752
|
+
})
|
|
2753
|
+
.catch((e) => { if (alive) { setErr(String(e && e.message || e)); setFiles([]) } })
|
|
2754
|
+
return () => { alive = false }
|
|
2755
|
+
}, [dlg.runId, dlg.linkId])
|
|
2756
|
+
const entries = files || []
|
|
2757
|
+
return h(Modal, { title: t('linkFilesTitle') + ':' + (dlg.name || dlg.linkId), onClose: () => controller.setState({ dialog: null }), width: 960 },
|
|
2758
|
+
h('div', { style: { display: 'flex', gap: 12, minHeight: 320 } },
|
|
2759
|
+
h('div', { style: { width: 280, flexShrink: 0, overflowY: 'auto', maxHeight: '62vh', borderRight: '1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.2))', paddingRight: 8 } },
|
|
2760
|
+
files === null && !err ? h('div', { style: { fontSize: 12, opacity: .7, padding: 4 } }, t('loading'))
|
|
2761
|
+
: entries.length === 0 ? h('div', { style: { fontSize: 12, opacity: .7, padding: 4 } }, err || t('noFiles'))
|
|
2762
|
+
: h(FileTree, { t, entries, sel, onSelect: setSel })),
|
|
2763
|
+
h('div', { style: { flex: 1, minWidth: 0, overflowY: 'auto', maxHeight: '62vh' } },
|
|
2764
|
+
sel ? h(ArtifactViewer, { t, controller, runId: dlg.runId, path: sel })
|
|
2765
|
+
: h('div', { className: 'dswfe-empty' }, err || t('pickFile')))))
|
|
2766
|
+
}
|
|
2767
|
+
|
|
2768
|
+
function RunBoard({ state, controller, t }) {
|
|
2769
|
+
const run = state.run
|
|
2770
|
+
if (state.runLoading) return h('div', { className: 'dswfe-board' }, t('loading'))
|
|
2771
|
+
if (!run) return h('div', { className: 'dswfe-empty' }, t('emptyRun'))
|
|
2772
|
+
const latest = latestAttempts(run)
|
|
2773
|
+
const phases = Array.isArray(run.snapshot && run.snapshot.phases) ? run.snapshot.phases : []
|
|
2774
|
+
const { done, total } = runProgress(run)
|
|
2775
|
+
const active = ['queued', 'running', 'awaiting', 'paused'].includes(run.status)
|
|
2776
|
+
const wfName = run.displayName || run.processName || run.processId
|
|
2777
|
+
const spanMs = (run.finishedAt || (active ? Date.now() : run.updatedAt)) - run.createdAt
|
|
2778
|
+
const children = [
|
|
2779
|
+
h('div', { className: 'dswfe-runhead' },
|
|
2780
|
+
h('h3', { className: 'dswfe-detail-title' }, wfName),
|
|
2781
|
+
h(StatusPill, { t, status: run.status }),
|
|
2782
|
+
h('span', { className: 'dswfe-count' }, t('progress', { done, total })),
|
|
2783
|
+
h('div', { className: 'dswfe-actions' },
|
|
2784
|
+
run.status === 'running' || run.status === 'queued' ? h('button', { className: 'dswfe-btn', onClick: () => void controller.runAction('pause', { id: run.id }) }, t('pause')) : null,
|
|
2785
|
+
run.status === 'paused' ? h('button', { className: 'dswfe-btn', 'data-primary': 'true', onClick: () => void controller.runAction('resume', { id: run.id }) }, t('resume')) : null,
|
|
2786
|
+
active ? h('button', { className: 'dswfe-btn', 'data-danger': 'true', onClick: () => void controller.runAction('stop', { id: run.id }) }, t('stopRun')) : null)),
|
|
2787
|
+
h('div', { className: 'dswfe-chips' },
|
|
2788
|
+
h('span', { className: 'dswfe-chip' }, '⚡ ' + (run.usage && run.usage.calls > 0 ? fmtTokens(usageTotalOf(run.usage)) : '—')),
|
|
2789
|
+
h('span', { className: 'dswfe-chip' }, '▶ ' + t('startedAt') + ' ' + (run.createdAt ? new Date(run.createdAt).toLocaleString() : '—')),
|
|
2790
|
+
h('span', { className: 'dswfe-chip' }, '⏹ ' + t('endedAt') + ' ' + (run.finishedAt ? new Date(run.finishedAt).toLocaleString() : active ? '…' : '—')),
|
|
2791
|
+
h('span', { className: 'dswfe-chip' }, '⏱ ' + t('durationTotal') + ' ' + fmtDuration(spanMs, t('durationUnknown'))),
|
|
2792
|
+
h('span', { className: 'dswfe-chip' }, '💬 ' + t('sessionMode') + ':' + t(run.sessionMode === 'single' ? 'sessionSingle' : 'sessionMulti')),
|
|
2793
|
+
run.error ? h('span', { className: 'dswfe-badge', 'data-kind': 'err' }, t('runError') + ': ' + run.error) : null),
|
|
2794
|
+
]
|
|
2795
|
+
if (run.userInput) children.push(h('div', { className: 'dswfe-kv', style: { background: 'var(--dsw-alias-bg-layer-2, rgba(128,128,128,.06))', border: '1px solid var(--dsw-alias-border-l1, rgba(128,128,128,.2))', borderRadius: 8, padding: '6px 10px' } }, h('b', null, '📌 ' + t('runUserInput') + ':'), h('span', { style: { whiteSpace: 'pre-wrap' } }, run.userInput)))
|
|
2796
|
+
children.push(h('div', { className: 'dswfe-sec' }, h(FlowGraph, { t, parsed: run.snapshot, run })))
|
|
2797
|
+
if (run.pendingBreak) {
|
|
2798
|
+
const humanBreak = run.pendingBreak.kind === 'human'
|
|
2799
|
+
children.push(h('div', { className: 'dswfe-break' },
|
|
2800
|
+
h('span', { style: { fontWeight: 600 } }, '⚠ ' + t(humanBreak ? 'humanReviewTitle' : 'breakTitle')),
|
|
2801
|
+
h('span', { style: { fontSize: 12 } },
|
|
2802
|
+
run.pendingBreak.linkId
|
|
2803
|
+
+ (run.pendingBreak.gate && run.pendingBreak.gate.score !== null && run.pendingBreak.gate.score !== undefined
|
|
2804
|
+
? ' · ' + t('gateLabel') + ' ' + run.pendingBreak.gate.score + ' / ' + (run.pendingBreak.gate.minScore || 0) : '')
|
|
2805
|
+
+ ' · ' + (run.pendingBreak.reason || '')),
|
|
2806
|
+
h('div', { className: 'dswfe-actions' },
|
|
2807
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', onClick: () => void controller.runAction('resolve-break', { id: run.id, decision: 'retry' }) }, t(humanBreak ? 'decisionReject' : 'decisionRetry')),
|
|
2808
|
+
h('button', { className: 'dswfe-btn', onClick: () => void controller.runAction('resolve-break', { id: run.id, decision: 'skip' }) }, t(humanBreak ? 'decisionApprove' : 'decisionSkip')),
|
|
2809
|
+
h('button', { className: 'dswfe-btn', 'data-danger': 'true', onClick: () => void controller.runAction('resolve-break', { id: run.id, decision: 'stop' }) }, t('decisionStop')))))
|
|
2810
|
+
}
|
|
2811
|
+
let seq = 0
|
|
2812
|
+
for (let i = 0; i < phases.length; i++) {
|
|
2813
|
+
const ph = phases[i]
|
|
2814
|
+
const links = Array.isArray(ph.links) ? ph.links : []
|
|
2815
|
+
children.push(h('div', { className: 'dswfe-phase', key: ph.id || i },
|
|
2816
|
+
h('div', { className: 'dswfe-phase-head' },
|
|
2817
|
+
h('span', { className: 'dswfe-badge' }, t('phaseNo', { n: i + 1 })),
|
|
2818
|
+
h('span', null, ph.name || ''),
|
|
2819
|
+
h('span', { className: 'dswfe-link-meta' }, links.length + ' ' + t('links'))),
|
|
2820
|
+
links.map((ln) => { seq += 1; return h(RunLinkCard, { key: ln.id, t, run, phase: ph, link: ln, attempt: latest.get(ln.id), controller, index: seq }) })))
|
|
2821
|
+
}
|
|
2822
|
+
return h('div', { className: 'dswfe-board' }, children)
|
|
2823
|
+
}
|
|
2824
|
+
|
|
2825
|
+
function ExecView({ state, controller, t }) {
|
|
2826
|
+
return h('div', { style: { display: 'contents' } },
|
|
2827
|
+
h(RunList, { state, controller, t }),
|
|
2828
|
+
state.runId && (state.runLoading || state.run) ? h(RunBoard, { state, controller, t })
|
|
2829
|
+
: state.runId && state.runError
|
|
2830
|
+
? h('div', { className: 'dswfe-board' },
|
|
2831
|
+
h('div', { className: 'dswfe-error' }, t('runLoadFailed') + ':' + state.runError),
|
|
2832
|
+
h('div', { className: 'dswfe-actions', style: { marginTop: 10 } },
|
|
2833
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', onClick: () => void controller.loadRun(state.runId) }, t('retryLoad')),
|
|
2834
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ runId: null, run: undefined, runError: null }) }, t('cancel'))))
|
|
2835
|
+
: state.runId ? h('div', { className: 'dswfe-empty' }, t('loading')) : h('div', { className: 'dswfe-empty' }, t('emptyRun')))
|
|
2836
|
+
}
|
|
2837
|
+
|
|
2838
|
+
function NewRunDialog({ state, controller, t }) {
|
|
2839
|
+
const dlg = state.dialog
|
|
2840
|
+
const [workspaces, setWorkspaces] = useState(null)
|
|
2841
|
+
const [ws, setWs] = useState('')
|
|
2842
|
+
const [req, setReq] = useState('')
|
|
2843
|
+
const [mode, setMode] = useState('single')
|
|
2844
|
+
useEffect(() => {
|
|
2845
|
+
api('/workspaces').then((d) => setWorkspaces(d.workspaces || [])).catch(() => setWorkspaces([]))
|
|
2846
|
+
}, [])
|
|
2847
|
+
useEffect(() => { if (!state.settings) void controller.loadSettings() }, [])
|
|
2848
|
+
const proc = state.processes.find((p) => p.id === dlg.processId)
|
|
2849
|
+
const [busy, setBusy] = useState(false)
|
|
2850
|
+
const reqOk = req.trim() !== ''
|
|
2851
|
+
return h(Modal, { title: t('runCreate') + ':' + (proc ? (proc.display_name || proc.name) : ''), onClose: () => controller.setState({ dialog: null }) },
|
|
2852
|
+
h('div', { className: 'dswfe-kv' }, h('b', null, t('name') + ':'), proc ? proc.relPath : '—'),
|
|
2853
|
+
h('label', { className: 'dswfe-field' }, t('runUserInput'),
|
|
2854
|
+
h('textarea', {
|
|
2855
|
+
value: req, placeholder: t('runUserInputPh'), spellCheck: false, rows: 4,
|
|
2856
|
+
style: { width: '100%', resize: 'vertical', fontFamily: 'var(--dsw-font-family, inherit)', fontSize: 13, lineHeight: 1.6, border: '1px solid var(--dsw-alias-border-l2,rgba(128,128,128,.3))', borderRadius: 8, padding: '8px 10px', background: 'var(--dsw-alias-bg-layer-2,transparent)', color: 'inherit', boxSizing: 'border-box' },
|
|
2857
|
+
onChange: (e) => setReq(e.target.value),
|
|
2858
|
+
})),
|
|
2859
|
+
h('label', { className: 'dswfe-field' }, t('runWorkspace'),
|
|
2860
|
+
h('select', { value: ws, onChange: (e) => setWs(e.target.value) },
|
|
2861
|
+
workspaces === null ? h('option', { value: '' }, t('loading')) : [
|
|
2862
|
+
h('option', { key: '_', value: '' }, t('workspaceDefault')),
|
|
2863
|
+
workspaces.map((w) => h('option', { key: w.id, value: w.id }, w.title)),
|
|
2864
|
+
])),
|
|
2865
|
+
h('label', { className: 'dswfe-field' }, h('span', { className: 'dswfe-field-label' }, t('sessionMode'), h(Help, { text: t('helpSessionMode') })),
|
|
2866
|
+
h('select', { value: mode, onChange: (e) => setMode(e.target.value) },
|
|
2867
|
+
h('option', { key: 'multi', value: 'multi' }, t('sessionMulti')),
|
|
2868
|
+
h('option', { key: 'single', value: 'single' }, t('sessionSingle')))),
|
|
2869
|
+
h('div', { style: { fontSize: 12, opacity: .7 } }, mode === 'single'
|
|
2870
|
+
? '整条流程共用一个会话(门禁也在其中):省 token,但上下文会持续累积。'
|
|
2871
|
+
: '每个环节开一个全新会话执行;用户需求只注入第一个环节,后续环节读上游产出文件;门禁由评审会话打分,不过按 on_gate_fail 流转,返工不超过 max_rework。'),
|
|
2872
|
+
h('div', { style: { display: 'flex', gap: 8, justifyContent: 'flex-end' } },
|
|
2873
|
+
h('button', { className: 'dswfe-btn', onClick: () => controller.setState({ dialog: null }) }, t('cancel')),
|
|
2874
|
+
h('button', { className: 'dswfe-btn', 'data-primary': 'true', disabled: busy || !proc || !reqOk, onClick: async () => {
|
|
2875
|
+
setBusy(true)
|
|
2876
|
+
try { await controller.createRun({ processId: dlg.processId, workspaceId: ws || undefined, userInput: req.trim(), sessionMode: mode }) } catch (error) { controller.toast(String(error && error.message || error), 'err') } finally { setBusy(false) }
|
|
2877
|
+
} }, t('runCreate'))))
|
|
2878
|
+
}
|
|
2879
|
+
|
|
2880
|
+
/**
|
|
2881
|
+
* 流程图可视化(v0.3):工作流 YAML → 有向图 → 零依赖分层布局 → SVG 渲染。
|
|
2882
|
+
*
|
|
2883
|
+
* 建模对齐 ProcessFlowGraph 的视觉语言:
|
|
2884
|
+
* - START → 第一个环节 → … → END;on_success 实线(forward 灰 / goto 跳转绿),
|
|
2885
|
+
* on_gate_fail 红色虚线 + 「门禁未过 → <id>」标签,break 不连线只在节点上标注,
|
|
2886
|
+
* 回边(指向更早环节)从节点上沿绕行,自环画右侧小环。
|
|
2887
|
+
* - 节点卡:序号徽标、环节名、executor/expert、门禁徽标(最低分数线)、返工上限。
|
|
2888
|
+
* - 运行态叠加:attempt 状态映射节点描边/徽标(当前橙、完成绿+实际门禁得分、
|
|
2889
|
+
* 门禁未过红、跳过灰虚、中断深灰)。
|
|
2890
|
+
*
|
|
2891
|
+
* 布局是纯函数(rank 用 forward 边最长路径,层内按声明序),可在 plain Node 下单测。
|
|
2892
|
+
*/
|
|
2893
|
+
|
|
2894
|
+
|
|
2895
|
+
const START_ID = '__start'
|
|
2896
|
+
const END_ID = '__end'
|
|
2897
|
+
|
|
2898
|
+
/** 解析流转值(host validate.flowTarget 的客户端镜像):'next'|'end'|'break'|{jump}。 */
|
|
2899
|
+
function clientFlowTarget(value) {
|
|
2900
|
+
if (value === undefined || value === null || value === '') return null
|
|
2901
|
+
const v = String(value).trim()
|
|
2902
|
+
if (v === 'next' || v === 'end' || v === 'break') return v
|
|
2903
|
+
if (v.startsWith('goto:')) return { jump: v.slice(5).trim() }
|
|
2904
|
+
return { jump: v }
|
|
2905
|
+
}
|
|
2906
|
+
|
|
2907
|
+
/**
|
|
2908
|
+
* 解析后的工作流对象 → 流程图模型。
|
|
2909
|
+
* @returns {{ nodes: Array, edges: Array, breaks: Array, warnings: string[] } | null}
|
|
2910
|
+
* nodes: { id, no, name, phaseId, phaseName, executor, expert, gateMin, gateCount, maxRework, skills }
|
|
2911
|
+
* edges: { from, to, kind: 'forward'|'jump'|'fail', label }
|
|
2912
|
+
* breaks: { linkId, field, value }(break 不连线,节点上标注)
|
|
2913
|
+
*/
|
|
2914
|
+
function buildFlowModel(parsed) {
|
|
2915
|
+
if (!parsed || typeof parsed !== 'object' || !Array.isArray(parsed.phases)) return null
|
|
2916
|
+
const nodes = []
|
|
2917
|
+
const byId = new Map()
|
|
2918
|
+
for (const ph of parsed.phases) {
|
|
2919
|
+
if (!ph || typeof ph !== 'object') continue
|
|
2920
|
+
const links = Array.isArray(ph.links) ? ph.links : []
|
|
2921
|
+
for (const ln of links) {
|
|
2922
|
+
if (!ln || typeof ln !== 'object' || !ln.id) continue
|
|
2923
|
+
const gates = Array.isArray(ln.gates) ? ln.gates.filter((g) => g && typeof g === 'object') : []
|
|
2924
|
+
const gateMin = gates.reduce((min, g) => (typeof g.min_score === 'number' ? Math.min(min, g.min_score) : min), Infinity)
|
|
2925
|
+
const node = {
|
|
2926
|
+
id: String(ln.id),
|
|
2927
|
+
no: nodes.length + 1,
|
|
2928
|
+
name: ln.name || ln.id,
|
|
2929
|
+
phaseId: ph.id || '',
|
|
2930
|
+
phaseName: ph.name || ph.id || '',
|
|
2931
|
+
executor: ln.executor || null,
|
|
2932
|
+
reviewType: ln.review_type || 'ai',
|
|
2933
|
+
expert: (ln.expert_name || ln.expert) || null,
|
|
2934
|
+
gateCount: gates.length,
|
|
2935
|
+
gateMin: Number.isFinite(gateMin) ? gateMin : null,
|
|
2936
|
+
maxRework: Number.isInteger(ln.max_rework) ? ln.max_rework : null,
|
|
2937
|
+
skills: Array.isArray(ln.skills) ? ln.skills : [],
|
|
2938
|
+
onSuccess: ln.on_success || 'next',
|
|
2939
|
+
onGateFail: ln.on_gate_fail == null ? null : String(ln.on_gate_fail),
|
|
2940
|
+
}
|
|
2941
|
+
nodes.push(node)
|
|
2942
|
+
byId.set(node.id, node)
|
|
2943
|
+
}
|
|
2944
|
+
}
|
|
2945
|
+
if (nodes.length === 0) return null
|
|
2946
|
+
|
|
2947
|
+
const edges = []
|
|
2948
|
+
const breaks = []
|
|
2949
|
+
const warnings = []
|
|
2950
|
+
if (nodes.length > 0) edges.push({ from: START_ID, to: nodes[0].id, kind: 'forward', label: '' })
|
|
2951
|
+
const resolve = (value, fromNode) => {
|
|
2952
|
+
const t = clientFlowTarget(value)
|
|
2953
|
+
if (t === null) return null
|
|
2954
|
+
if (t === 'next' || t === 'end' || t === 'break') return t
|
|
2955
|
+
return byId.has(t.jump) ? t.jump : null
|
|
2956
|
+
}
|
|
2957
|
+
nodes.forEach((node, i) => {
|
|
2958
|
+
// on_success
|
|
2959
|
+
const ok = resolve(node.onSuccess)
|
|
2960
|
+
if (ok === 'next') {
|
|
2961
|
+
const nextNode = nodes[i + 1]
|
|
2962
|
+
if (nextNode) edges.push({ from: node.id, to: nextNode.id, kind: 'forward', label: '' })
|
|
2963
|
+
else edges.push({ from: node.id, to: END_ID, kind: 'forward', label: '' })
|
|
2964
|
+
} else if (ok === 'end') {
|
|
2965
|
+
edges.push({ from: node.id, to: END_ID, kind: 'forward', label: '' })
|
|
2966
|
+
} else if (typeof ok === 'string') {
|
|
2967
|
+
edges.push({ from: node.id, to: ok, kind: 'jump', label: node.onSuccess })
|
|
2968
|
+
} else {
|
|
2969
|
+
warnings.push(`环节 "${node.id}" 的 on_success 无法解析`)
|
|
2970
|
+
}
|
|
2971
|
+
// on_gate_fail(与成功策略不同才画;显式 break 才记标注,缺省不标)
|
|
2972
|
+
const gf = node.onGateFail == null ? null : resolve(node.onGateFail)
|
|
2973
|
+
if (node.onGateFail === 'break') {
|
|
2974
|
+
breaks.push({ linkId: node.id, field: 'on_gate_fail', value: 'break' })
|
|
2975
|
+
} else if (typeof gf === 'string' && gf !== ok) {
|
|
2976
|
+
edges.push({ from: node.id, to: gf, kind: 'fail', label: `门禁未过 → ${gf}` })
|
|
2977
|
+
}
|
|
2978
|
+
})
|
|
2979
|
+
return { nodes, edges, breaks, warnings }
|
|
2980
|
+
}
|
|
2981
|
+
|
|
2982
|
+
// ── 布局(纯函数)────────────────────────────────────────────────────────
|
|
2983
|
+
|
|
2984
|
+
const FLOW_NODE_W = 196
|
|
2985
|
+
const FLOW_NODE_H = 74
|
|
2986
|
+
const FLOW_GAP_X = 80
|
|
2987
|
+
const FLOW_GAP_Y = 42
|
|
2988
|
+
const FLOW_PAD = 26
|
|
2989
|
+
const LOOP_BACK_PAD = 64
|
|
2990
|
+
|
|
2991
|
+
/**
|
|
2992
|
+
* 分层布局:START=rank0;沿 forward/jump 前向边做最长路径分层;回边(to.rank≤from.rank)
|
|
2993
|
+
* 不参与分层、渲染为顶部绕行弧线。层内按声明序排布。
|
|
2994
|
+
* @returns {{ positions: Map, width: number, height: number, backEdges: Set<string>, loops: Set<string> }}
|
|
2995
|
+
* positions: id → {x, y}(节点左上角;含 START/END 虚拟节点)
|
|
2996
|
+
*/
|
|
2997
|
+
function layoutFlowGraph(model) {
|
|
2998
|
+
const { nodes, edges } = model
|
|
2999
|
+
const positions = new Map()
|
|
3000
|
+
const backEdges = new Set()
|
|
3001
|
+
const loops = new Set()
|
|
3002
|
+
const meta = new Map() // id → { row, col, dir }(蛇形排布信息,边路由用)
|
|
3003
|
+
const n = nodes.length
|
|
3004
|
+
if (n === 0) return { positions, width: 200, height: 120, backEdges, loops, meta }
|
|
3005
|
+
|
|
3006
|
+
// 蛇形排布:每行 K 个(3-5,按 n 取平方根级别),奇数行反向,图变紧凑可读
|
|
3007
|
+
const K = Math.max(3, Math.min(5, Math.ceil(Math.sqrt(n))))
|
|
3008
|
+
const rowH = FLOW_NODE_H + FLOW_GAP_Y * 2
|
|
3009
|
+
nodes.forEach((nd, i) => {
|
|
3010
|
+
const row = Math.floor(i / K)
|
|
3011
|
+
const colInRow = i % K
|
|
3012
|
+
const dir = row % 2 === 0 ? 1 : -1
|
|
3013
|
+
const col = dir === 1 ? colInRow : K - 1 - colInRow
|
|
3014
|
+
positions.set(nd.id, {
|
|
3015
|
+
x: FLOW_PAD + col * (FLOW_NODE_W + FLOW_GAP_X),
|
|
3016
|
+
y: FLOW_PAD + LOOP_BACK_PAD + row * rowH,
|
|
3017
|
+
})
|
|
3018
|
+
meta.set(nd.id, { row, col, dir })
|
|
3019
|
+
})
|
|
3020
|
+
const rows = Math.ceil(n / K)
|
|
3021
|
+
const first = nodes[0].id, last = nodes[n - 1].id
|
|
3022
|
+
const firstPos = positions.get(first), lastPos = positions.get(last)
|
|
3023
|
+
positions.set(START_ID, { x: firstPos.x, y: firstPos.y - 78 })
|
|
3024
|
+
positions.set(END_ID, { x: lastPos.x, y: lastPos.y + FLOW_NODE_H + 34 })
|
|
3025
|
+
for (const e of edges) {
|
|
3026
|
+
const key = e.from + '→' + e.to
|
|
3027
|
+
if (e.from === e.to) loops.add(key)
|
|
3028
|
+
}
|
|
3029
|
+
const width = FLOW_PAD * 2 + K * (FLOW_NODE_W + FLOW_GAP_X) - FLOW_GAP_X
|
|
3030
|
+
const height = FLOW_PAD * 2 + LOOP_BACK_PAD + rows * rowH + 60
|
|
3031
|
+
return { positions, width, height, backEdges, loops, meta }
|
|
3032
|
+
}
|
|
3033
|
+
|
|
3034
|
+
|
|
3035
|
+
// ── 流程图 SVG 组件(v0.3)──────────────────────────────────────────────
|
|
3036
|
+
|
|
3037
|
+
function flowPhaseColor(phaseId) {
|
|
3038
|
+
let h = 0
|
|
3039
|
+
for (let i = 0; i < String(phaseId || '').length; i++) h = (h * 31 + String(phaseId).charCodeAt(i)) >>> 0
|
|
3040
|
+
return 'hsl(' + (h % 360) + ' 45% 55%)'
|
|
3041
|
+
}
|
|
3042
|
+
|
|
3043
|
+
function escXml(text) {
|
|
3044
|
+
return String(text).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"')
|
|
3045
|
+
}
|
|
3046
|
+
|
|
3047
|
+
/**
|
|
3048
|
+
* SVG 文本按估算宽度截断,超出补「…」。卡片宽度固定、角标文案随语言变长时用。
|
|
3049
|
+
*/
|
|
3050
|
+
function fitFlowText(text, maxPx, fontPx) {
|
|
3051
|
+
const src = String(text == null ? '' : text)
|
|
3052
|
+
const chWidth = (ch) => (ch.charCodeAt(0) > 0x2e80 ? fontPx : fontPx * 0.56)
|
|
3053
|
+
let total = 0
|
|
3054
|
+
for (const ch of src) total += chWidth(ch)
|
|
3055
|
+
if (total <= maxPx) return src
|
|
3056
|
+
let out = ''
|
|
3057
|
+
let acc = fontPx * 0.56
|
|
3058
|
+
for (const ch of src) {
|
|
3059
|
+
const w = chWidth(ch)
|
|
3060
|
+
if (acc + w > maxPx) break
|
|
3061
|
+
out += ch
|
|
3062
|
+
acc += w
|
|
3063
|
+
}
|
|
3064
|
+
return out + '…'
|
|
3065
|
+
}
|
|
3066
|
+
|
|
3067
|
+
/**
|
|
3068
|
+
* 流程图 SVG。model/layout 来自 flow-model;runState 可选(运行态高亮):
|
|
3069
|
+
* { latestByLink: Map<linkId, attempt>, currentLinkId, pendingLinkId }
|
|
3070
|
+
*/
|
|
3071
|
+
function FlowGraph({ t, parsed, run }) {
|
|
3072
|
+
const [zoom, setZoom] = useState(1)
|
|
3073
|
+
const wrapRef = useRef(null)
|
|
3074
|
+
const fittedRef = useRef(false)
|
|
3075
|
+
const model = useMemo(() => buildFlowModel(parsed), [parsed])
|
|
3076
|
+
const layout = useMemo(() => (model ? layoutFlowGraph(model) : null), [model])
|
|
3077
|
+
// 首屏自适应:整图铺满容器宽度(最多放大到 100%),之后用户手动缩放不被覆盖
|
|
3078
|
+
useEffect(() => {
|
|
3079
|
+
if (!layout || fittedRef.current || !wrapRef.current) return
|
|
3080
|
+
fittedRef.current = true
|
|
3081
|
+
const avail = wrapRef.current.clientWidth - 4
|
|
3082
|
+
if (layout.width > avail && avail > 100) setZoom(Math.max(0.3, avail / layout.width))
|
|
3083
|
+
}, [layout])
|
|
3084
|
+
const latest = useMemo(() => (run ? latestAttempts(run) : null), [run])
|
|
3085
|
+
if (!model || !layout) return h('div', { className: 'dswfe-empty' }, t('flowNoParsed'))
|
|
3086
|
+
|
|
3087
|
+
const pos = layout.positions
|
|
3088
|
+
const nodeById = new Map([[START_ID, { id: START_ID, name: 'START', phaseName: '' }], [END_ID, { id: END_ID, name: 'END', phaseName: '' }], ...model.nodes.map((n) => [n.id, n])])
|
|
3089
|
+
const currentLinkId = run && run.current && run.current.linkId
|
|
3090
|
+
const stateOf = (linkId) => {
|
|
3091
|
+
if (!run) return null
|
|
3092
|
+
if (run.pendingBreak && run.pendingBreak.linkId === linkId) return 'awaiting'
|
|
3093
|
+
if (currentLinkId === linkId && ['running', 'queued', 'awaiting'].includes(run.status)) return 'current'
|
|
3094
|
+
const a = latest && latest.get(linkId)
|
|
3095
|
+
return a ? a.status : null
|
|
3096
|
+
}
|
|
3097
|
+
const STROKE = { forward: 'var(--dsw-text-secondary, #94a3b8)', jump: '#22c55e', fail: 'var(--dsw-alias-state-error, #ef4444)' }
|
|
3098
|
+
const edgePath = (e) => {
|
|
3099
|
+
const from = pos.get(e.from)
|
|
3100
|
+
const to = pos.get(e.to)
|
|
3101
|
+
if (!from || !to) return null
|
|
3102
|
+
const isLoop = layout.loops.has(e.from + '→' + e.to)
|
|
3103
|
+
if (e.from === START_ID) return { d: 'M' + (from.x + FLOW_NODE_W / 2) + ' ' + (from.y + 30) + ' L' + (to.x + FLOW_NODE_W / 2) + ' ' + to.y, label: null }
|
|
3104
|
+
if (e.to === END_ID) return { d: 'M' + (from.x + FLOW_NODE_W / 2) + ' ' + (from.y + FLOW_NODE_H) + ' L' + (to.x + FLOW_NODE_W / 2) + ' ' + to.y, label: null }
|
|
3105
|
+
if (isLoop) {
|
|
3106
|
+
const sx = from.x + FLOW_NODE_W, sy = from.y + 18
|
|
3107
|
+
return { d: 'M' + sx + ' ' + sy + ' C' + (sx + 46) + ' ' + sy + ' ' + (sx + 46) + ' ' + (sy + 30) + ' ' + sx + ' ' + (sy + 34), label: null }
|
|
3108
|
+
}
|
|
3109
|
+
const mf = layout.meta.get(e.from), mt = layout.meta.get(e.to)
|
|
3110
|
+
if (!mf || !mt) return null
|
|
3111
|
+
// 同行:顺向直线;逆向/跨列走节点上方弧线(含 fail 回边)
|
|
3112
|
+
if (mf.row === mt.row) {
|
|
3113
|
+
const toRight = mt.col > mf.col
|
|
3114
|
+
const inFlowDir = toRight === (mf.dir === 1)
|
|
3115
|
+
const sx = toRight ? from.x + FLOW_NODE_W : from.x
|
|
3116
|
+
const tx = toRight ? to.x : to.x + FLOW_NODE_W
|
|
3117
|
+
const y = from.y + FLOW_NODE_H / 2
|
|
3118
|
+
if (Math.abs(mt.col - mf.col) === 1 && inFlowDir) return { d: 'M' + sx + ' ' + y + ' L' + tx + ' ' + y, label: e.label || null }
|
|
3119
|
+
const ax = (sx + tx) / 2
|
|
3120
|
+
const asx = toRight ? sx - 12 : sx + 12
|
|
3121
|
+
const atx = toRight ? tx + 12 : tx - 12
|
|
3122
|
+
return { d: 'M' + asx + ' ' + (from.y) + ' C' + asx + ' ' + (from.y - 34) + ' ' + atx + ' ' + (to.y - 34) + ' ' + atx + ' ' + to.y, label: e.label || null, arcY: Math.min(from.y, to.y) - 24, ax }
|
|
3123
|
+
}
|
|
3124
|
+
// 相邻行的同列:垂直直落
|
|
3125
|
+
if (mt.row === mf.row + 1 && mt.col === mf.col) {
|
|
3126
|
+
return { d: 'M' + (from.x + FLOW_NODE_W / 2) + ' ' + (from.y + FLOW_NODE_H) + ' L' + (to.x + FLOW_NODE_W / 2) + ' ' + to.y, label: e.label || null }
|
|
3127
|
+
}
|
|
3128
|
+
// 跨行任意:走两行之间走廊的正交折线(出边 → 横移 → 进边),不斜穿、不压节点
|
|
3129
|
+
const sx = from.x + FLOW_NODE_W / 2
|
|
3130
|
+
const tx = to.x + FLOW_NODE_W / 2
|
|
3131
|
+
if (mt.row > mf.row) {
|
|
3132
|
+
const sy = from.y + FLOW_NODE_H
|
|
3133
|
+
const laneY = from.y + FLOW_NODE_H + FLOW_GAP_Y
|
|
3134
|
+
return { d: 'M' + sx + ' ' + sy + ' L' + sx + ' ' + laneY + ' L' + tx + ' ' + laneY + ' L' + tx + ' ' + to.y, label: e.label || null }
|
|
3135
|
+
}
|
|
3136
|
+
// 回边(回到更早的行):从源顶边偏左出线、走走廊横移、进目标底边偏右,避免与同列垂直前向边重叠
|
|
3137
|
+
const bx = from.x + 26
|
|
3138
|
+
const btx = to.x + 40
|
|
3139
|
+
const laneY = from.y - FLOW_GAP_Y
|
|
3140
|
+
return { d: 'M' + bx + ' ' + from.y + ' L' + bx + ' ' + laneY + ' L' + btx + ' ' + laneY + ' L' + btx + ' ' + (to.y + FLOW_NODE_H), label: e.label || null }
|
|
3141
|
+
}
|
|
3142
|
+
|
|
3143
|
+
const nodeSvg = (id) => {
|
|
3144
|
+
const p = pos.get(id)
|
|
3145
|
+
if (!p) return null
|
|
3146
|
+
if (id === START_ID || id === END_ID) {
|
|
3147
|
+
const isStart = id === START_ID
|
|
3148
|
+
return h('g', { key: id },
|
|
3149
|
+
h('rect', { x: p.x, y: p.y, width: FLOW_NODE_W, height: 30, rx: 15, fill: 'var(--dsw-alias-bg-layer-1, transparent)', stroke: 'var(--dsw-alias-border-l2, rgba(128,128,128,.4))' }),
|
|
3150
|
+
h('text', { x: p.x + FLOW_NODE_W / 2, y: p.y + 20, textAnchor: 'middle', fontSize: 12, fontWeight: 700, fill: 'var(--dsw-text-secondary, gray)', style: { fontFamily: 'monospace', letterSpacing: 2 } }, isStart ? '▶ ' + t('flowStartLabel') : '■ ' + t('flowEndLabel')))
|
|
3151
|
+
}
|
|
3152
|
+
const node = nodeById.get(id)
|
|
3153
|
+
const st = stateOf(id)
|
|
3154
|
+
const att = run && latest && latest.get(id)
|
|
3155
|
+
const border = st === 'current' ? '#d9822b'
|
|
3156
|
+
: st === 'done' || st === 'skipped' ? '#2e9e5b'
|
|
3157
|
+
: st === 'gate_failed' || st === 'awaiting' ? 'var(--dsw-alias-state-error, #ef4444)'
|
|
3158
|
+
: st === 'failed' ? 'var(--dsw-alias-state-error, #ef4444)' : 'var(--dsw-alias-border-l2, rgba(128,128,128,.35))'
|
|
3159
|
+
// 复核方式放在「门禁」左边(三选一:AI 评审 / 人工评审 / 无需评审)
|
|
3160
|
+
const reviewLabel = node.reviewType === 'human' ? t('flowReviewHuman')
|
|
3161
|
+
: node.reviewType === 'none' ? t('flowReviewNone') : t('flowReviewAi')
|
|
3162
|
+
const badge = [reviewLabel]
|
|
3163
|
+
if (node.gateCount > 0) badge.push(t('flowGate', { min: node.gateMin === null ? '?' : node.gateMin }))
|
|
3164
|
+
else badge.push(t('flowNoGate'))
|
|
3165
|
+
if (node.maxRework !== null) badge.push(t('flowRework', { n: node.maxRework }))
|
|
3166
|
+
let runBadge = null
|
|
3167
|
+
let runBadgeW = 0
|
|
3168
|
+
if (att && att.gate && att.gate.score !== null && att.gate.score !== undefined) {
|
|
3169
|
+
runBadge = t('flowScore', { score: String(att.gate.score) })
|
|
3170
|
+
// 角标占位宽度:中文/全角按字号 10px,西文数字按 5.6px(与 fitFlowText 的估算口径一致)
|
|
3171
|
+
for (const ch of runBadge) runBadgeW += ch.charCodeAt(0) > 0xff ? 10 : 5.6
|
|
3172
|
+
}
|
|
3173
|
+
// executor 恒为 agent,不再是可读信息(早前明确要求不在图上显示),只留专家名
|
|
3174
|
+
const meta = [node.expert].filter(Boolean).join(' · ')
|
|
3175
|
+
const w = FLOW_NODE_W, hgt = FLOW_NODE_H
|
|
3176
|
+
return h('g', { key: id },
|
|
3177
|
+
h('rect', { x: p.x + 3, y: p.y + 6, width: 6, height: hgt - 12, rx: 3, fill: flowPhaseColor(node.phaseId) }),
|
|
3178
|
+
h('rect', { x: p.x, y: p.y, width: w, height: hgt, rx: 10, fill: 'var(--dsw-alias-bg-layer-1, #fff)', stroke: border, strokeWidth: st === 'current' ? 2.5 : 1.2 }),
|
|
3179
|
+
h('rect', { x: p.x - 9, y: p.y - 9, width: 22, height: 18, rx: 9, fill: 'var(--dsw-alias-bg-layer-2, #f1f5f9)', stroke: 'var(--dsw-alias-border-l1, rgba(128,128,128,.2))' }),
|
|
3180
|
+
h('text', { x: p.x + 2, y: p.y + 4, textAnchor: 'middle', fontSize: 10, fontWeight: 700, fill: 'var(--dsw-text-secondary, gray)', style: { fontFamily: 'monospace' } }, String(node.no).padStart(2, '0')),
|
|
3181
|
+
h('text', { x: p.x + 14, y: p.y + 24, fontSize: 13, fontWeight: 600, fill: 'var(--dsw-alias-label-primary, currentColor)' }, escXml(node.name.slice(0, 16))),
|
|
3182
|
+
h('text', { x: p.x + 14, y: p.y + 41, fontSize: 10, fill: 'var(--dsw-text-secondary, gray)' }, escXml((meta || node.phaseName || '').slice(0, 26))),
|
|
3183
|
+
h('text', { x: p.x + 14, y: p.y + hgt - 10, fontSize: 10, fill: node.gateCount > 0 ? '#b8860b' : 'var(--dsw-text-secondary, gray)' }, escXml(fitFlowText(badge.join('·'), w - 14 - (runBadge ? runBadgeW + 22 : 12), 10))),
|
|
3184
|
+
runBadge ? h('text', { x: p.x + w - 12, y: p.y + hgt - 10, textAnchor: 'end', fontSize: 10, fontWeight: 700, fill: '#2e9e5b' }, runBadge) : null,
|
|
3185
|
+
st === 'current' ? h('circle', { cx: p.x + w - 12, cy: p.y + 12, r: 5, fill: '#d9822b' }) : null,
|
|
3186
|
+
st === 'done' ? h('circle', { cx: p.x + w - 12, cy: p.y + 12, r: 5, fill: '#2e9e5b' }) : null,
|
|
3187
|
+
(st === 'gate_failed' || st === 'awaiting' || st === 'failed') ? h('circle', { cx: p.x + w - 12, cy: p.y + 12, r: 5, fill: 'var(--dsw-alias-state-error, #ef4444)' }) : null)
|
|
3188
|
+
}
|
|
3189
|
+
|
|
3190
|
+
const edgeSvgs = []
|
|
3191
|
+
for (const e of model.edges) {
|
|
3192
|
+
const path = edgePath(e)
|
|
3193
|
+
if (!path) continue
|
|
3194
|
+
const color = e.kind === 'fail' ? STROKE.fail : e.kind === 'jump' ? STROKE.jump : STROKE.forward
|
|
3195
|
+
const dashed = e.kind === 'fail' ? '6,4' : undefined
|
|
3196
|
+
edgeSvgs.push(h('path', { key: e.from + '→' + e.to + e.kind, d: path.d, fill: 'none', stroke: color, strokeWidth: e.kind === 'fail' ? 1.8 : 1.4, strokeDasharray: dashed, markerEnd: 'url(#dswfe-arrow-' + (e.kind === 'fail' ? 'f' : e.kind === 'jump' ? 'j' : 'n') + ')' }))
|
|
3197
|
+
}
|
|
3198
|
+
|
|
3199
|
+
return h('div', null,
|
|
3200
|
+
h('div', { className: 'dswfe-flowlegend' },
|
|
3201
|
+
h('span', null, h('span', { className: 'sw fwd' }), t('flowLegendForward')),
|
|
3202
|
+
h('span', null, h('span', { className: 'sw jump' }), t('flowLegendJump')),
|
|
3203
|
+
h('span', null, h('span', { className: 'sw fail' }), t('flowLegendFail')),
|
|
3204
|
+
h('span', null, t('flowLegendBreak')),
|
|
3205
|
+
h('span', { style: { marginLeft: 'auto' } },
|
|
3206
|
+
h('button', { className: 'dswfe-mini', onClick: () => setZoom(Math.max(0.5, zoom - 0.2)) }, '−'),
|
|
3207
|
+
h('span', { style: { margin: '0 6px' } }, Math.round(zoom * 100) + '%'),
|
|
3208
|
+
h('button', { className: 'dswfe-mini', onClick: () => setZoom(Math.min(2, zoom + 0.2)) }, '+'))),
|
|
3209
|
+
h('div', { className: 'dswfe-flowwrap', ref: wrapRef },
|
|
3210
|
+
h('svg', { width: layout.width * zoom, height: layout.height * zoom, viewBox: '0 0 ' + layout.width + ' ' + layout.height },
|
|
3211
|
+
h('defs', null,
|
|
3212
|
+
h('marker', { id: 'dswfe-arrow-n', viewBox: '0 0 10 10', refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse' }, h('path', { d: 'M0 0L10 5L0 10z', fill: 'var(--dsw-text-secondary, #94a3b8)' })),
|
|
3213
|
+
h('marker', { id: 'dswfe-arrow-j', viewBox: '0 0 10 10', refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse' }, h('path', { d: 'M0 0L10 5L0 10z', fill: '#22c55e' })),
|
|
3214
|
+
h('marker', { id: 'dswfe-arrow-f', viewBox: '0 0 10 10', refX: 9, refY: 5, markerWidth: 7, markerHeight: 7, orient: 'auto-start-reverse' }, h('path', { d: 'M0 0L10 5L0 10z', fill: 'var(--dsw-alias-state-error, #ef4444)' }))),
|
|
3215
|
+
edgeSvgs,
|
|
3216
|
+
[START_ID, ...model.nodes.map((n) => n.id), END_ID].map((id) => nodeSvg(id)))))
|
|
3217
|
+
}
|
|
3218
|
+
|
|
3219
|
+
function FlowTab({ t, parsed }) {
|
|
3220
|
+
return h('div', null, h(FlowGraph, { t, parsed }))
|
|
3221
|
+
}
|
|
3222
|
+
|
|
3223
|
+
// ── 挂载 ─────────────────────────────────────────────────────────────────
|
|
3224
|
+
|
|
3225
|
+
const name = CLIENT_NAME
|
|
3226
|
+
const inject = ['slots', 'locale']
|
|
3227
|
+
|
|
3228
|
+
// (v0.4 起 shell.overlay slot 已移除:全屏 overlay 盖住侧栏观感差,改走 mountPrcView 中栏接管。)
|
|
3229
|
+
|
|
3230
|
+
let ReactGlobal = null
|
|
3231
|
+
try { ReactGlobal = require('react') } catch {}
|
|
3232
|
+
|
|
3233
|
+
/** 同页重复 apply 防护:上一次挂载的 teardown(apply 内赋值)。 */
|
|
3234
|
+
let activeApplyTeardown = null
|
|
3235
|
+
|
|
3236
|
+
/** 中栏接管视图(apply 内赋值;openPanel 的兜底 ensure 也会用到)。 */
|
|
3237
|
+
let prcView = null
|
|
3238
|
+
|
|
3239
|
+
/**
|
|
3240
|
+
* 中栏接管视图(taskboard board-mount 同款):容器 div 追加为会话列末尾子节点
|
|
3241
|
+
* (React shell 不管理它),ProcessPanel 常驻其中、关闭时渲染 null;开合由
|
|
3242
|
+
* html[data-dswfe-active] 属性驱动(CSS 隐藏列内兄弟,侧栏保持可见)。
|
|
3243
|
+
* ensure(force):force=true 时壳层退化兜底——容器挂 body 退回全屏浮层。
|
|
3244
|
+
*/
|
|
3245
|
+
function mountPrcView(controller, t) {
|
|
3246
|
+
const COLUMN_SELECTOR = '[data-pane="conversation"], [class*="centerCol"], .dshDesktopConversationSurface'
|
|
3247
|
+
let container = null
|
|
3248
|
+
let root = null
|
|
3249
|
+
const unplace = () => {
|
|
3250
|
+
try { if (root) root.unmount() } catch {}
|
|
3251
|
+
try { if (container) container.remove() } catch {}
|
|
3252
|
+
root = null; container = null
|
|
3253
|
+
}
|
|
3254
|
+
const place = (host, fallback) => {
|
|
3255
|
+
container = document.createElement('div')
|
|
3256
|
+
container.className = 'dswfe-view'
|
|
3257
|
+
container.setAttribute('data-dswfe-view', '')
|
|
3258
|
+
if (fallback) container.setAttribute('data-dswfe-fallback', '')
|
|
3259
|
+
host.appendChild(container)
|
|
3260
|
+
root = require('react-dom/client').createRoot(container)
|
|
3261
|
+
root.render(h(ProcessPanel, { controller, t, slotProps: null }))
|
|
3262
|
+
}
|
|
3263
|
+
const ensure = (force) => {
|
|
3264
|
+
if (container && container.isConnected) return
|
|
3265
|
+
const column = document.querySelector(COLUMN_SELECTOR)
|
|
3266
|
+
if (column) { unplace(); place(column, false) }
|
|
3267
|
+
else if (force && document.body) { unplace(); place(document.body, true) }
|
|
3268
|
+
}
|
|
3269
|
+
const tryPlace = () => { ensure(false) }
|
|
3270
|
+
const waitObserver = new MutationObserver(tryPlace)
|
|
3271
|
+
waitObserver.observe(document.body, { childList: true, subtree: true })
|
|
3272
|
+
const retry = setInterval(tryPlace, 2000)
|
|
3273
|
+
tryPlace()
|
|
3274
|
+
return {
|
|
3275
|
+
ensure,
|
|
3276
|
+
dispose() {
|
|
3277
|
+
clearInterval(retry)
|
|
3278
|
+
waitObserver.disconnect()
|
|
3279
|
+
unplace()
|
|
3280
|
+
try { document.documentElement.removeAttribute(PRC_ACTIVE_ATTR) } catch {}
|
|
3281
|
+
},
|
|
3282
|
+
}
|
|
3283
|
+
}
|
|
3284
|
+
|
|
3285
|
+
const moduleExports = {
|
|
3286
|
+
name,
|
|
3287
|
+
inject,
|
|
3288
|
+
__internals: { Controller, filterProcesses, ZH, EN, AI_PROMPT, colorizeLine, buildFlowModel, layoutFlowGraph, clientFlowTarget },
|
|
3289
|
+
__boot(container, opts = {}) {
|
|
3290
|
+
ensureStyles()
|
|
3291
|
+
const t = makeT(null)
|
|
3292
|
+
const controller = new Controller()
|
|
3293
|
+
controller.t = t
|
|
3294
|
+
if (opts.autostart !== false) controller.start()
|
|
3295
|
+
if (opts.open !== false) controller.openPanel()
|
|
3296
|
+
const root = require('react-dom/client').createRoot(container)
|
|
3297
|
+
root.render(h(ProcessPanel, { controller, t, slotProps: null }))
|
|
3298
|
+
return { controller, root }
|
|
3299
|
+
},
|
|
3300
|
+
apply(ctx) {
|
|
3301
|
+
ensureStyles()
|
|
3302
|
+
let t = makeT(null)
|
|
3303
|
+
try {
|
|
3304
|
+
if (ctx.locale && typeof ctx.locale.register === 'function') {
|
|
3305
|
+
ctx.locale.register(NS, 'zh', ZH)
|
|
3306
|
+
ctx.locale.register(NS, 'en', EN)
|
|
3307
|
+
const bound = typeof ctx.locale.bind === 'function' ? ctx.locale.bind(NS) : null
|
|
3308
|
+
if (bound) t = makeT(bound)
|
|
3309
|
+
}
|
|
3310
|
+
} catch (e) { try { console.error('[dsh-workflow-execute] locale init:', e) } catch {} }
|
|
3311
|
+
const controller = new Controller()
|
|
3312
|
+
controller.t = t
|
|
3313
|
+
controller.start()
|
|
3314
|
+
try {
|
|
3315
|
+
const host = globalThis.location && globalThis.location.hostname
|
|
3316
|
+
if (host === 'localhost' || host === '127.0.0.1') window.__prc = controller
|
|
3317
|
+
} catch {}
|
|
3318
|
+
// 会话服务:动态 inject(客户端 ctx 支持;缺席时「打开会话」降级提示)
|
|
3319
|
+
try {
|
|
3320
|
+
if (typeof ctx.inject === 'function') {
|
|
3321
|
+
ctx.inject(['sessions'], (scope) => {
|
|
3322
|
+
const svc = scope && scope.sessions
|
|
3323
|
+
if (svc && typeof svc.open === 'function') controller.sessionsSvc = svc
|
|
3324
|
+
})
|
|
3325
|
+
// dsh 0.1.7+: sessions.open() 被移除,会话导航改走
|
|
3326
|
+
// uiWorkspace.openSession()。归一成 { open(id) } 面孔,调用点不变。
|
|
3327
|
+
ctx.inject(['uiWorkspace'], (scope) => {
|
|
3328
|
+
const svc = scope && scope.uiWorkspace
|
|
3329
|
+
const cur = controller.sessionsSvc
|
|
3330
|
+
if (svc && typeof svc.openSession === 'function' && !(cur && typeof cur.open === 'function')) {
|
|
3331
|
+
controller.sessionsSvc = { open: (id) => svc.openSession(id) }
|
|
3332
|
+
}
|
|
3333
|
+
})
|
|
3334
|
+
}
|
|
3335
|
+
} catch (e) { console.error('[dsh-workflow-execute] sessions inject:', e) }
|
|
3336
|
+
// 同页重复 apply(重建/热重载):先拆掉上一次挂载,避免残留失效的入口行
|
|
3337
|
+
if (typeof activeApplyTeardown === 'function') { try { activeApplyTeardown() } catch {} activeApplyTeardown = null }
|
|
3338
|
+
const disposers = []
|
|
3339
|
+
try { disposers.push(mountSidebarEntry(controller, t)) } catch (e) { console.error('[dsh-workflow-execute] sidebar mount:', e) }
|
|
3340
|
+
try { prcView = mountPrcView(controller, t); disposers.push(() => prcView && prcView.dispose()) } catch (e) { console.error('[dsh-workflow-execute] view mount:', e) }
|
|
3341
|
+
// 与其他面板互斥
|
|
3342
|
+
const onActivate = (event) => { if (event.detail !== PANEL_NAME && controller.getSnapshot().panelOpen) controller.closePanel() }
|
|
3343
|
+
document.addEventListener(ACTIVATE_EVENT, onActivate)
|
|
3344
|
+
const teardown = () => {
|
|
3345
|
+
document.removeEventListener(ACTIVATE_EVENT, onActivate)
|
|
3346
|
+
if (prcView) { try { prcView.dispose() } catch {} prcView = null }
|
|
3347
|
+
for (const d of disposers) { try { d() } catch {} }
|
|
3348
|
+
controller.dispose()
|
|
3349
|
+
}
|
|
3350
|
+
activeApplyTeardown = teardown
|
|
3351
|
+
ctx.effect(() => teardown, 'dsh-workflow-execute: client mount')
|
|
3352
|
+
},
|
|
3353
|
+
}
|
|
3354
|
+
|
|
3355
|
+
// kit 内联(构建期注入到同一 factory 作用域的 var PluginKit;plain Node 测试下缺失 → AI 对话框降级提示)
|
|
3356
|
+
function getKit() {
|
|
3357
|
+
try { return typeof PluginKit !== 'undefined' ? PluginKit : null } catch { return null }
|
|
3358
|
+
}
|
|
3359
|
+
|
|
3360
|
+
module.exports = moduleExports
|