ralphflow-dsh 0.1.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 +196 -0
- package/lib/actions.d.ts +37 -0
- package/lib/actions.js +55 -0
- package/lib/check-voting.d.ts +54 -0
- package/lib/check-voting.js +289 -0
- package/lib/check.d.ts +64 -0
- package/lib/check.js +329 -0
- package/lib/client/CommandCard.d.ts +24 -0
- package/lib/client/CommandCard.js +69 -0
- package/lib/client/HeaderAction.d.ts +39 -0
- package/lib/client/HeaderAction.js +509 -0
- package/lib/client/RunCard.d.ts +27 -0
- package/lib/client/RunCard.js +375 -0
- package/lib/client/client.d.ts +3 -0
- package/lib/client/client.js +275 -0
- package/lib/client/definition.d.ts +126 -0
- package/lib/client/definition.js +259 -0
- package/lib/client/hidden-runs.d.ts +6 -0
- package/lib/client/hidden-runs.js +52 -0
- package/lib/client/http-state.d.ts +67 -0
- package/lib/client/http-state.js +81 -0
- package/lib/client/markdown.d.ts +26 -0
- package/lib/client/markdown.js +174 -0
- package/lib/client/notify-watch.d.ts +38 -0
- package/lib/client/notify-watch.js +98 -0
- package/lib/client/notify.d.ts +21 -0
- package/lib/client/notify.js +168 -0
- package/lib/client/snapshots.d.ts +8 -0
- package/lib/client/snapshots.js +101 -0
- package/lib/client.js +2361 -0
- package/lib/commands.d.ts +41 -0
- package/lib/commands.js +223 -0
- package/lib/create.d.ts +14 -0
- package/lib/create.js +98 -0
- package/lib/deps.d.ts +17 -0
- package/lib/deps.js +19 -0
- package/lib/done-detect.d.ts +2 -0
- package/lib/done-detect.js +28 -0
- package/lib/driver.d.ts +32 -0
- package/lib/driver.js +248 -0
- package/lib/engine.d.ts +306 -0
- package/lib/engine.js +2851 -0
- package/lib/events.d.ts +35 -0
- package/lib/events.js +52 -0
- package/lib/index.d.ts +11 -0
- package/lib/index.js +201 -0
- package/lib/jobs.d.ts +56 -0
- package/lib/jobs.js +355 -0
- package/lib/mutex.d.ts +9 -0
- package/lib/mutex.js +21 -0
- package/lib/session-hygiene.d.ts +25 -0
- package/lib/session-hygiene.js +205 -0
- package/lib/tools.d.ts +24 -0
- package/lib/tools.js +716 -0
- package/lib/voting-progress.d.ts +37 -0
- package/lib/voting-progress.js +89 -0
- package/package.json +73 -0
- package/workflows/loop.yaml +27 -0
- package/workflows/spec.yaml +105 -0
|
@@ -0,0 +1,509 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
|
+
/**
|
|
3
|
+
* Ralph Flow for dsh — 页头入口 + 控制中心抽屉
|
|
4
|
+
*
|
|
5
|
+
* 注册进 conversation.session.header.actions(list 槽)。三层结构:
|
|
6
|
+
* 1) trigger:状态点 + 活跃计数 + 当前活跃 run 的「步骤 · 阶段」微缩——
|
|
7
|
+
* 不点开也能瞄到跑到哪了(mini pipeline 的页头形态);
|
|
8
|
+
* 2) 抽屉「进行中」区:每个 run 一行(pipeline 步骤条 desc 版 + 状态),
|
|
9
|
+
* 点击滚动定位到对话里的卡,旁有 status 按钮;
|
|
10
|
+
* 3) 抽屉「已结束」区:本会话 done/cancelled 的历史(可回看定位)。
|
|
11
|
+
* 无任务时保留冷启动上手卡。样式全部消费 dsh 官方主题 token。
|
|
12
|
+
*/
|
|
13
|
+
import * as React from "react";
|
|
14
|
+
import { RALPHFLOW_RUN_KIND } from "./definition.js";
|
|
15
|
+
import { loadRunSnapshots, isRunHiddenSnap } from "./snapshots.js";
|
|
16
|
+
import { useRalphHttpState, checkTimeLeft } from "./http-state.js";
|
|
17
|
+
/** locale 兜底:t 缺省或键缺失时回落中文 */
|
|
18
|
+
function tr(t, key, fallback) {
|
|
19
|
+
try {
|
|
20
|
+
const v = t?.(key);
|
|
21
|
+
return typeof v === "string" && v ? v : fallback;
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
return fallback;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
const NUM = { fontVariantNumeric: "tabular-nums" };
|
|
28
|
+
/** 从守护 job(label/output)解析 run 摘要——官方 JobListAction 同源的 jobs store */
|
|
29
|
+
function runFromJob(job) {
|
|
30
|
+
try {
|
|
31
|
+
const label = String(job?.label ?? "");
|
|
32
|
+
if (!label.startsWith("ralphflow"))
|
|
33
|
+
return null;
|
|
34
|
+
const parts = label.split(/\s+/);
|
|
35
|
+
const instId = parts[2] ?? "";
|
|
36
|
+
if (!instId)
|
|
37
|
+
return null;
|
|
38
|
+
// readOutput: "ralphflow <workflow> <step> <DO|CHECK> fail=<n>[ paused]"
|
|
39
|
+
const m = /^ralphflow\s+\S+\s+(\S+)\s+(\S+)\s+fail=(\d+)( paused)?/.exec(String(job?.output ?? ""));
|
|
40
|
+
const step = m?.[1] ?? "";
|
|
41
|
+
const phase = m?.[2] === "CHECK" ? "check" : "do";
|
|
42
|
+
const paused = !!m?.[4];
|
|
43
|
+
const live = job.status === "running" || job.status === "stopping";
|
|
44
|
+
const status = !live ? "done" : paused ? "failed" : phase === "check" ? "check" : "do";
|
|
45
|
+
return {
|
|
46
|
+
key: `job-${instId}`,
|
|
47
|
+
runId: instId,
|
|
48
|
+
workflow: parts[1] ?? "",
|
|
49
|
+
task: "",
|
|
50
|
+
steps: [],
|
|
51
|
+
current: step ? { step, phase, failCount: Number(m?.[3] ?? 0) } : null,
|
|
52
|
+
gate: null,
|
|
53
|
+
stopReason: undefined,
|
|
54
|
+
stepStartedAt: typeof job.startedAt === "number" ? job.startedAt : undefined,
|
|
55
|
+
status,
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
return null;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/** HTTP 状态通道(全局、最新)→ RunSummary */
|
|
63
|
+
function runFromHttp(r) {
|
|
64
|
+
const phase = r.current?.phase ?? "do";
|
|
65
|
+
const status = r.paused ? "failed"
|
|
66
|
+
: r.gate ? "gate"
|
|
67
|
+
: phase === "check" ? "check"
|
|
68
|
+
: "do";
|
|
69
|
+
return {
|
|
70
|
+
key: `http-${r.runId}`,
|
|
71
|
+
runId: r.runId,
|
|
72
|
+
workflow: r.workflow ?? "",
|
|
73
|
+
task: r.task ?? "",
|
|
74
|
+
steps: Array.isArray(r.steps) ? r.steps : [],
|
|
75
|
+
current: r.current ? { step: r.current.step, phase: (phase === "check" ? "check" : "do"), failCount: r.current.failCount ?? 0 } : null,
|
|
76
|
+
gate: r.gate ?? null,
|
|
77
|
+
stopReason: r.paused ? "failed" : undefined,
|
|
78
|
+
stepStartedAt: r.startedAt ? Date.parse(String(r.startedAt)) : undefined,
|
|
79
|
+
status,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/** 三源合并:HTTP 全局状态(最新)→ 已结束历史(recentEnded)→ chat.nodes(实时补充)→ 快照(离线兜底) */
|
|
83
|
+
function collectRuns(nodes, jobs, http, ended) {
|
|
84
|
+
const out = [];
|
|
85
|
+
const seen = new Set();
|
|
86
|
+
try {
|
|
87
|
+
for (const r of Array.isArray(http) ? http : []) {
|
|
88
|
+
if (!r?.runId)
|
|
89
|
+
continue;
|
|
90
|
+
seen.add(r.runId);
|
|
91
|
+
out.push(runFromHttp(r));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch { }
|
|
95
|
+
try {
|
|
96
|
+
// 已结束实例(host history 尾部):报告按钮 + 结束后仍可定位
|
|
97
|
+
for (const e of Array.isArray(ended) ? ended : []) {
|
|
98
|
+
const runId = String(e?.instId ?? "");
|
|
99
|
+
if (!runId || seen.has(runId))
|
|
100
|
+
continue;
|
|
101
|
+
const completed = e?.status === "completed";
|
|
102
|
+
if (e?.status !== "completed" && e?.status !== "cancelled")
|
|
103
|
+
continue;
|
|
104
|
+
seen.add(runId);
|
|
105
|
+
out.push({
|
|
106
|
+
key: `end-${runId}`,
|
|
107
|
+
runId,
|
|
108
|
+
workflow: String(e?.workflow ?? ""),
|
|
109
|
+
task: String(e?.task ?? ""),
|
|
110
|
+
steps: [],
|
|
111
|
+
current: null,
|
|
112
|
+
gate: null,
|
|
113
|
+
stopReason: completed ? "done" : "cancelled",
|
|
114
|
+
status: completed ? "done" : "cancelled",
|
|
115
|
+
reportPath: typeof e?.reportPath === "string" && e.reportPath ? e.reportPath : undefined,
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
catch { }
|
|
120
|
+
try {
|
|
121
|
+
if (nodes) {
|
|
122
|
+
const values = typeof nodes.values === "function" ? nodes.values() : [];
|
|
123
|
+
for (const node of values) {
|
|
124
|
+
if (!node || node.kind !== RALPHFLOW_RUN_KIND)
|
|
125
|
+
continue;
|
|
126
|
+
const d = node.data ?? {};
|
|
127
|
+
const runId = String(d.runId ?? node.id ?? "");
|
|
128
|
+
if (!runId || seen.has(runId))
|
|
129
|
+
continue;
|
|
130
|
+
seen.add(runId);
|
|
131
|
+
const status = d.detached ? "detached"
|
|
132
|
+
: d.stopReason === "done" ? "done"
|
|
133
|
+
: d.stopReason === "cancelled" ? "cancelled"
|
|
134
|
+
: d.stopReason === "failed" ? "failed"
|
|
135
|
+
: d.gate ? "gate"
|
|
136
|
+
: d.current?.phase === "check" ? "check" : "do";
|
|
137
|
+
out.push({
|
|
138
|
+
key: String(node.key ?? node.id ?? ""),
|
|
139
|
+
runId,
|
|
140
|
+
workflow: d.workflow ?? "",
|
|
141
|
+
task: d.task ?? "",
|
|
142
|
+
steps: Array.isArray(d.steps) ? d.steps : [],
|
|
143
|
+
current: d.current ?? null,
|
|
144
|
+
gate: d.gate,
|
|
145
|
+
stopReason: d.stopReason,
|
|
146
|
+
stepStartedAt: typeof d.stepStartedAt === "number" ? d.stepStartedAt : undefined,
|
|
147
|
+
status,
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
catch { }
|
|
153
|
+
try {
|
|
154
|
+
for (const job of Array.isArray(jobs) ? jobs : []) {
|
|
155
|
+
const r = runFromJob(job);
|
|
156
|
+
if (!r || seen.has(r.runId))
|
|
157
|
+
continue;
|
|
158
|
+
seen.add(r.runId);
|
|
159
|
+
out.push(r);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
catch { }
|
|
163
|
+
// 快照兜底:无 HTTP 通道/离线时仍有可导航的历史
|
|
164
|
+
try {
|
|
165
|
+
const snaps = loadRunSnapshots();
|
|
166
|
+
for (const [runId, s] of Object.entries(snaps)) {
|
|
167
|
+
if (seen.has(runId) || isRunHiddenSnap(runId))
|
|
168
|
+
continue;
|
|
169
|
+
const status = s.detached ? "detached"
|
|
170
|
+
: s.stopReason === "done" ? "done"
|
|
171
|
+
: s.stopReason === "cancelled" ? "cancelled"
|
|
172
|
+
: s.stopReason === "failed" ? "failed"
|
|
173
|
+
: s.gate ? "gate"
|
|
174
|
+
: s.current?.phase === "check" ? "check" : "do";
|
|
175
|
+
out.push({
|
|
176
|
+
key: `snap-${runId}`,
|
|
177
|
+
runId,
|
|
178
|
+
workflow: String(s.workflow ?? ""),
|
|
179
|
+
task: String(s.task ?? ""),
|
|
180
|
+
steps: Array.isArray(s.steps) ? s.steps : [],
|
|
181
|
+
current: s.current ?? null,
|
|
182
|
+
gate: s.gate,
|
|
183
|
+
stopReason: s.stopReason,
|
|
184
|
+
stepStartedAt: typeof s.stepStartedAt === "number" ? s.stepStartedAt : undefined,
|
|
185
|
+
status,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
catch { }
|
|
190
|
+
return out;
|
|
191
|
+
}
|
|
192
|
+
/** 状态 → 语义色 token(全插件统一:卡片徽标/页头/步骤条同一套) */
|
|
193
|
+
export function statusColorOf(s) {
|
|
194
|
+
return s === "done" ? "var(--dsw-alias-state-success-primary)"
|
|
195
|
+
: s === "failed" ? "var(--dsw-alias-state-warn-primary)"
|
|
196
|
+
: s === "gate" ? "var(--dsw-alias-state-warn-primary)"
|
|
197
|
+
: s === "check" ? "var(--dsw-alias-state-business-primary)"
|
|
198
|
+
: s === "cancelled" || s === "detached" ? "var(--dsw-alias-label-tertiary)"
|
|
199
|
+
: "var(--dsw-alias-state-business-tertiary)";
|
|
200
|
+
}
|
|
201
|
+
const STATUS_KEY = {
|
|
202
|
+
done: "status.done", cancelled: "status.cancelled", failed: "status.failed",
|
|
203
|
+
gate: "status.gate", check: "status.check", do: "status.do", detached: "status.detached",
|
|
204
|
+
};
|
|
205
|
+
const STATUS_FALLBACK = {
|
|
206
|
+
done: "已完成", cancelled: "已取消", failed: "已暂停",
|
|
207
|
+
gate: "待审查", check: "验证中", do: "进行中", detached: "已转交",
|
|
208
|
+
};
|
|
209
|
+
const statusLabelOf = (t, s) => tr(t, STATUS_KEY[s] ?? "status.do", STATUS_FALLBACK[s] ?? STATUS_FALLBACK.do);
|
|
210
|
+
/** 带参数的翻译兜底({n} 插值) */
|
|
211
|
+
function trf2(t, key, fallback, params) {
|
|
212
|
+
return tr(t, key, fallback).replace(/\{(\w+)\}/g, (_, k) => (params[k] != null ? String(params[k]) : `{${k}}`));
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* 动作直连通道:POST → host 的 /ralphflow/instances 动作端点(webServer 路由,
|
|
216
|
+
* 与状态轮询同源同通道)。不再依赖「往输入框填命令 + 合成 Enter」的脆弱链路:
|
|
217
|
+
* 通过/打回/恢复都可从抽屉一键直达,host 侧按白名单动作 + sessionId 解析 agent
|
|
218
|
+
* 执行工具并(需要时)followup 注入模型。POST 失败时调用方回退到命令注入。
|
|
219
|
+
*/
|
|
220
|
+
export async function postAction(sessionId, payload) {
|
|
221
|
+
try {
|
|
222
|
+
const res = await fetch("/ralphflow/instances", {
|
|
223
|
+
method: "POST",
|
|
224
|
+
headers: { "Content-Type": "application/json" },
|
|
225
|
+
body: JSON.stringify({ ...payload, sessionId: sessionId ?? "" }),
|
|
226
|
+
});
|
|
227
|
+
let data = {};
|
|
228
|
+
try {
|
|
229
|
+
data = (await res.json());
|
|
230
|
+
}
|
|
231
|
+
catch { }
|
|
232
|
+
if (res.ok && data?.ok)
|
|
233
|
+
return { ok: true, text: String(data.text ?? "已提交。") };
|
|
234
|
+
return { ok: false, text: String(data?.text ?? data?.error ?? (res.ok ? "请求未确认。" : `HTTP ${res.status}`)) };
|
|
235
|
+
}
|
|
236
|
+
catch (e) {
|
|
237
|
+
return { ok: false, text: e instanceof Error ? e.message : String(e) };
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
function formatElapsed(ms) {
|
|
241
|
+
const s = Math.max(0, Math.floor(ms / 1000));
|
|
242
|
+
if (s < 90)
|
|
243
|
+
return `${s}s`;
|
|
244
|
+
const m = Math.floor(s / 60);
|
|
245
|
+
if (m < 60)
|
|
246
|
+
return `${m}m`;
|
|
247
|
+
return `${Math.floor(m / 60)}h${m % 60}m`;
|
|
248
|
+
}
|
|
249
|
+
/** 步骤节点的人话标签:desc 截断优先,id 兜底 */
|
|
250
|
+
function stepLabel(s) {
|
|
251
|
+
const d = String(s?.desc ?? "").trim();
|
|
252
|
+
return d.length > 0 ? (d.length > 10 ? `${d.slice(0, 10)}…` : d) : String(s?.id ?? "?");
|
|
253
|
+
}
|
|
254
|
+
/** mini pipeline:一行步骤节点(✓ 已过 / ● 当前 / ○ 待做),当前节点带呼吸 */
|
|
255
|
+
function MiniPipeline({ steps, current, status }) {
|
|
256
|
+
if (!Array.isArray(steps) || steps.length === 0)
|
|
257
|
+
return null;
|
|
258
|
+
const curIdx = steps.findIndex((s) => current && s.id === current.step);
|
|
259
|
+
return (_jsx("span", { style: { display: "inline-flex", alignItems: "center", gap: "4px", minWidth: 0, overflow: "hidden" }, children: steps.slice(0, 6).map((s, i) => {
|
|
260
|
+
const active = !!(current && s.id === current.step);
|
|
261
|
+
const done = !active && curIdx >= 0 && i < curIdx;
|
|
262
|
+
const color = done ? "var(--dsw-alias-state-success-primary)" : active ? statusColorOf(status) : "var(--dsw-alias-label-tertiary)";
|
|
263
|
+
return (_jsxs("span", { title: `${s.id ?? ""}${s.desc ? ` — ${s.desc}` : ""}`, style: { display: "inline-flex", alignItems: "center", gap: "3px", flexShrink: i > 2 ? 1 : 0, minWidth: 0 }, children: [_jsx("span", { "aria-hidden": "true", style: { fontSize: "10.5px", color }, children: done ? "✓" : active ? "●" : "○" }), active ? (_jsx("span", { style: { fontSize: "11px", color, overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap" }, children: stepLabel(s) })) : null] }, s.id ?? i));
|
|
264
|
+
}) }));
|
|
265
|
+
}
|
|
266
|
+
const style = {
|
|
267
|
+
root: { position: "relative", display: "inline-block" },
|
|
268
|
+
trigger: {
|
|
269
|
+
display: "inline-flex",
|
|
270
|
+
alignItems: "center",
|
|
271
|
+
gap: "6px",
|
|
272
|
+
padding: "4px 10px",
|
|
273
|
+
borderRadius: "8px",
|
|
274
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
275
|
+
background: "transparent",
|
|
276
|
+
color: "var(--dsw-alias-label-primary)",
|
|
277
|
+
fontSize: "12.5px",
|
|
278
|
+
cursor: "pointer",
|
|
279
|
+
maxWidth: "420px",
|
|
280
|
+
},
|
|
281
|
+
menu: {
|
|
282
|
+
position: "absolute",
|
|
283
|
+
right: 0,
|
|
284
|
+
top: "calc(100% + 6px)",
|
|
285
|
+
width: "340px",
|
|
286
|
+
maxHeight: "70vh",
|
|
287
|
+
overflowY: "auto",
|
|
288
|
+
background: "var(--dsw-alias-bg-layer-3)",
|
|
289
|
+
border: "1px solid var(--dsw-alias-border-l2)",
|
|
290
|
+
borderRadius: "10px",
|
|
291
|
+
padding: "8px",
|
|
292
|
+
zIndex: 50,
|
|
293
|
+
boxShadow: "var(--dsw-shadow-lv2)",
|
|
294
|
+
},
|
|
295
|
+
row: {
|
|
296
|
+
display: "flex",
|
|
297
|
+
alignItems: "center",
|
|
298
|
+
gap: "8px",
|
|
299
|
+
padding: "7px 8px",
|
|
300
|
+
borderRadius: "6px",
|
|
301
|
+
fontSize: "12.5px",
|
|
302
|
+
cursor: "pointer",
|
|
303
|
+
border: "none",
|
|
304
|
+
width: "100%",
|
|
305
|
+
textAlign: "left",
|
|
306
|
+
background: "transparent",
|
|
307
|
+
},
|
|
308
|
+
};
|
|
309
|
+
const badgeWarn = {
|
|
310
|
+
fontSize: "11px", lineHeight: 1, padding: "2px 8px", borderRadius: "999px",
|
|
311
|
+
background: "var(--dsw-alias-state-warn-tertiary)", color: "var(--dsw-alias-state-warn-primary)",
|
|
312
|
+
fontWeight: 600,
|
|
313
|
+
};
|
|
314
|
+
const badgeFail = {
|
|
315
|
+
fontSize: "11px", lineHeight: 1, padding: "2px 8px", borderRadius: "999px",
|
|
316
|
+
background: "var(--dsw-alias-state-error-secondary)", color: "var(--dsw-alias-state-error-primary)",
|
|
317
|
+
fontWeight: 600,
|
|
318
|
+
};
|
|
319
|
+
/** 滚动定位到对话里对应 run 卡(导航的落点;找不到时降级为 status 命令) */
|
|
320
|
+
function scrollToRun(runId) {
|
|
321
|
+
try {
|
|
322
|
+
const el = document.querySelector(`[data-ralphflow-run][data-runid="${CSS.escape(runId)}"]`);
|
|
323
|
+
if (el) {
|
|
324
|
+
el.scrollIntoView({ behavior: "smooth", block: "center" });
|
|
325
|
+
el.style.transition = "box-shadow .3s ease";
|
|
326
|
+
el.style.boxShadow = "0 0 0 2px var(--dsw-alias-state-business-primary)";
|
|
327
|
+
setTimeout(() => { try {
|
|
328
|
+
el.style.boxShadow = "";
|
|
329
|
+
}
|
|
330
|
+
catch { } }, 1600);
|
|
331
|
+
return true;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
catch { }
|
|
335
|
+
return false;
|
|
336
|
+
}
|
|
337
|
+
export function HeaderAction({ sessionId, useSession, useSessions, t }) {
|
|
338
|
+
const [open, setOpen] = React.useState(false);
|
|
339
|
+
const rootRef = React.useRef(null);
|
|
340
|
+
// hooks 必须在组件顶层无条件调用(不得包进条件分支——违反 hooks 规则会
|
|
341
|
+
// 导致 React 状态错乱崩溃)。prop 缺省时传恒空实现保持 hooks 数量稳定。
|
|
342
|
+
// 数据源(官方 JobListAction 同款契约):
|
|
343
|
+
// - useSessions = sessions store(含 jobsBySession)——本会话守护 job 列表
|
|
344
|
+
// - useSession = 当前会话 chat store(实时卡数据;框架 scope=session 时注入)
|
|
345
|
+
const useSessionsSafe = useSessions ?? ((_sel) => undefined);
|
|
346
|
+
const useSessionSafe = useSession ?? ((_sel) => undefined);
|
|
347
|
+
const jobs = useSessionsSafe((s) => (sessionId && s?.jobsBySession ? s.jobsBySession[sessionId] : undefined));
|
|
348
|
+
const nodes = useSessionSafe((s) => s?.chat?.nodes);
|
|
349
|
+
const http = useRalphHttpState();
|
|
350
|
+
const runs = React.useMemo(() => collectRuns(nodes, jobs, http.instances, http.recentEnded), [nodes, jobs, http.instances, http.recentEnded]);
|
|
351
|
+
// ── 动作状态:抽屉内审批/打回/恢复/取消的进行中与反馈 ───────────────────
|
|
352
|
+
const [busyRun, setBusyRun] = React.useState(null);
|
|
353
|
+
const [actionMsg, setActionMsg] = React.useState(null);
|
|
354
|
+
const [returnFor, setReturnFor] = React.useState(null);
|
|
355
|
+
const [returnText, setReturnText] = React.useState("");
|
|
356
|
+
const [expanded, setExpanded] = React.useState(null);
|
|
357
|
+
const [confirmCancel, setConfirmCancel] = React.useState(null);
|
|
358
|
+
const returnRef = React.useRef(null);
|
|
359
|
+
// 动作反馈自动消隐(成功/失败可见 8 秒,不占位)
|
|
360
|
+
const msgTimer = React.useRef(null);
|
|
361
|
+
// 注:通知/快照由全局监视器(notify-watch.ts)负责——组件只挂会话页头,
|
|
362
|
+
// 空态页/其它会话时审查门到达也得提醒。组件这里只做展示与动作。
|
|
363
|
+
// 抽屉内计时刷新(运行中的 run 显示已用时)
|
|
364
|
+
const [, tick] = React.useReducer((n) => n + 1, 0);
|
|
365
|
+
React.useEffect(() => {
|
|
366
|
+
if (!open)
|
|
367
|
+
return;
|
|
368
|
+
const h = setInterval(tick, 5000);
|
|
369
|
+
return () => clearInterval(h);
|
|
370
|
+
}, [open]);
|
|
371
|
+
React.useEffect(() => {
|
|
372
|
+
if (!open)
|
|
373
|
+
return;
|
|
374
|
+
const onDown = (e) => {
|
|
375
|
+
if (rootRef.current && !rootRef.current.contains(e.target))
|
|
376
|
+
setOpen(false);
|
|
377
|
+
};
|
|
378
|
+
const onKey = (e) => {
|
|
379
|
+
if (e.key === "Escape") {
|
|
380
|
+
setOpen(false);
|
|
381
|
+
setReturnFor(null);
|
|
382
|
+
setExpanded(null);
|
|
383
|
+
}
|
|
384
|
+
};
|
|
385
|
+
document.addEventListener("mousedown", onDown);
|
|
386
|
+
document.addEventListener("keydown", onKey);
|
|
387
|
+
return () => {
|
|
388
|
+
document.removeEventListener("mousedown", onDown);
|
|
389
|
+
document.removeEventListener("keydown", onKey);
|
|
390
|
+
};
|
|
391
|
+
}, [open]);
|
|
392
|
+
// 返回(打回)意见输入框打开时聚焦
|
|
393
|
+
React.useEffect(() => {
|
|
394
|
+
if (returnFor) {
|
|
395
|
+
try {
|
|
396
|
+
returnRef.current?.focus();
|
|
397
|
+
}
|
|
398
|
+
catch { }
|
|
399
|
+
}
|
|
400
|
+
}, [returnFor]);
|
|
401
|
+
// 动作执行(POST 直连;失败退回命令注入)
|
|
402
|
+
const runAction = async (runId, action, reason) => {
|
|
403
|
+
if (busyRun)
|
|
404
|
+
return;
|
|
405
|
+
setBusyRun(runId);
|
|
406
|
+
setActionMsg(null);
|
|
407
|
+
const res = await postAction(sessionId, { action, runId, reason });
|
|
408
|
+
setBusyRun(null);
|
|
409
|
+
setActionMsg({ runId, ok: res.ok, text: res.text });
|
|
410
|
+
if (msgTimer.current)
|
|
411
|
+
window.clearTimeout(msgTimer.current);
|
|
412
|
+
msgTimer.current = window.setTimeout(() => setActionMsg(null), 8000);
|
|
413
|
+
if (res.ok) {
|
|
414
|
+
setReturnFor(null);
|
|
415
|
+
setReturnText("");
|
|
416
|
+
setExpanded(null);
|
|
417
|
+
setConfirmCancel(null);
|
|
418
|
+
}
|
|
419
|
+
else if (action === "approve" || action === "resume") {
|
|
420
|
+
// 直连失败(如 headless 形态无 webServer):退回旧链路——填命令进输入框
|
|
421
|
+
window.dispatchEvent(new CustomEvent("ralphflow:command", {
|
|
422
|
+
detail: { command: action === "approve" ? "/ralphflow-continue" : "/ralphflow-continue", autoSubmit: true },
|
|
423
|
+
}));
|
|
424
|
+
}
|
|
425
|
+
};
|
|
426
|
+
const toggleDetail = (r) => {
|
|
427
|
+
setExpanded((cur) => (cur === r.runId ? null : r.runId));
|
|
428
|
+
setReturnFor(null);
|
|
429
|
+
};
|
|
430
|
+
// 计数语义收紧:live 只指真正在跑的(do/check)。「已暂停」是等你处理,
|
|
431
|
+
// 走自己的徽标;「已转交」既不在跑也无需处理,两者都不该叫「运行中」。
|
|
432
|
+
const live = runs.filter((r) => r.status === "do" || r.status === "check");
|
|
433
|
+
const waiting = runs.filter((r) => r.status === "gate" || r.status === "failed");
|
|
434
|
+
const ended = runs.filter((r) => r.status === "done" || r.status === "cancelled" || r.status === "detached");
|
|
435
|
+
const liveCount = live.length;
|
|
436
|
+
const gateCount = waiting.filter((r) => r.status === "gate").length;
|
|
437
|
+
const failCount = waiting.filter((r) => r.status === "failed").length;
|
|
438
|
+
// trigger 微缩:第一个活跃 run 的当前步(多数场景只有一个活跃实例)
|
|
439
|
+
const primary = live[0] ?? waiting[0];
|
|
440
|
+
const locateRun = (r) => {
|
|
441
|
+
if (!scrollToRun(r.runId)) {
|
|
442
|
+
// 卡不在 DOM(已被折叠回收等):退化为 status 文本查询,信息不丢
|
|
443
|
+
window.dispatchEvent(new CustomEvent("ralphflow:command", { detail: { command: `/ralphflow-status ${r.runId || r.workflow}` } }));
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
/** 验证票状态 → 本地化标签(引擎枚举是中英词典的键) */
|
|
447
|
+
const VOTER_STATUS_KEYS = {
|
|
448
|
+
pending: "voter.status.pending", running: "voter.status.running", passed: "voter.status.passed",
|
|
449
|
+
failed: "voter.status.failed", infra_pending: "voter.status.infra_pending", infra_failed: "voter.status.infra_failed",
|
|
450
|
+
cancelled: "voter.status.cancelled",
|
|
451
|
+
};
|
|
452
|
+
const VOTER_STATUS_FALLBACK = {
|
|
453
|
+
pending: "排队中", running: "运行中", passed: "通过", failed: "未通过",
|
|
454
|
+
infra_pending: "环境重试", infra_failed: "环境故障", cancelled: "已取消",
|
|
455
|
+
};
|
|
456
|
+
const voterLabel = (t, status) => tr(t, VOTER_STATUS_KEYS[status] ?? "voter.status.pending", VOTER_STATUS_FALLBACK[status] ?? status);
|
|
457
|
+
/** 验证票状态 → 语义色(通过绿/失败红/运行蓝/等) */
|
|
458
|
+
function voterColor(status) {
|
|
459
|
+
return status === "passed" ? "var(--dsw-alias-state-success-primary)"
|
|
460
|
+
: status === "failed" || status === "infra_failed" ? "var(--dsw-alias-state-error-primary)"
|
|
461
|
+
: status === "running" || status === "infra_pending" ? "var(--dsw-alias-state-business-primary)"
|
|
462
|
+
: "var(--dsw-alias-label-tertiary)";
|
|
463
|
+
}
|
|
464
|
+
const renderRow = (r) => {
|
|
465
|
+
// 详情面板数据源:HTTP 快照为该 run 的富字段(失败原因全文/暂停原因/票)
|
|
466
|
+
const detail = Array.isArray(http.instances) ? http.instances.find((i) => String(i.runId) === r.runId) : undefined;
|
|
467
|
+
const isExpanded = expanded === r.runId;
|
|
468
|
+
const isBusy = busyRun === r.runId;
|
|
469
|
+
const showMsg = actionMsg && actionMsg.runId === r.runId ? actionMsg : null;
|
|
470
|
+
return (_jsxs("div", { style: { borderBottom: "1px solid var(--dsw-alias-border-l1)", paddingBottom: "4px", marginBottom: "4px" }, children: [_jsxs("div", { style: { ...style.row, cursor: "default", flexWrap: "wrap" }, children: [_jsx("span", { "aria-hidden": "true", style: { width: 8, height: 8, borderRadius: "50%", background: statusColorOf(r.status), flexShrink: 0 } }), _jsxs("span", { style: { color: "var(--dsw-alias-label-primary)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", minWidth: 0 }, children: [r.workflow, r.runId ? `·${r.runId.slice(-4)}` : ""] }), _jsx("span", { style: { marginLeft: "auto", fontSize: "11px", color: statusColorOf(r.status), flexShrink: 0 }, children: statusLabelOf(t, r.status) }), r.current && !r.stopReason ? (_jsxs("span", { style: { fontSize: "11px", color: "var(--dsw-alias-label-tertiary)", width: "100%", ...NUM }, title: String(r.task ?? ""), children: [tr(t, "drawer.step.prefix", "▸"), stepLabel(r.steps.find((s) => s.id === r.current.step) ?? { id: r.current.step }), typeof r.stepStartedAt === "number" ? ` · ${formatElapsed(Date.now() - r.stepStartedAt)}` : ""] })) : null, _jsx(MiniPipeline, { steps: r.steps, current: r.current, status: r.status })] }), _jsxs("div", { style: { display: "flex", gap: "6px", paddingLeft: "16px", paddingBottom: "2px", flexWrap: "wrap" }, children: [_jsx("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-secondary)", cursor: "pointer" }, onClick: () => { setOpen(false); locateRun(r); }, children: tr(t, "drawer.locate", "定位到对话") }), _jsx("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-secondary)", cursor: "pointer" }, onClick: () => toggleDetail(r), children: isExpanded ? tr(t, "drawer.collapse", "收起详情") : tr(t, "drawer.detail", "状态详情") }), r.status === "failed" && r.runId ? (_jsxs("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-button-primary-fill)", color: "var(--dsw-alias-label-primary-foreground)", cursor: isBusy ? "wait" : "pointer", opacity: isBusy ? 0.6 : 1 }, onClick: () => void runAction(r.runId, "resume"), children: ["\u25B6 ", tr(t, "run.resume", "继续")] })) : null, r.status === "gate" && r.runId ? (_jsxs(_Fragment, { children: [_jsxs("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-button-primary-fill)", color: "var(--dsw-alias-label-primary-foreground)", cursor: isBusy ? "wait" : "pointer", opacity: isBusy ? 0.6 : 1 }, onClick: () => void runAction(r.runId, "approve"), children: ["\u2713 ", tr(t, "run.approve", "通过")] }), _jsxs("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-secondary)", cursor: "pointer" }, onClick: () => { setReturnFor((cur) => (cur === r.runId ? null : r.runId)); setExpanded(null); setConfirmCancel(null); }, children: ["\u2717 ", tr(t, "run.return", "打回")] })] })) : null, r.status !== "done" && r.status !== "cancelled" && r.status !== "detached" && r.runId ? (confirmCancel === r.runId ? (_jsxs(_Fragment, { children: [_jsx("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-state-error-secondary)", background: "var(--dsw-alias-state-error-secondary)", color: "var(--dsw-alias-state-error-primary)", cursor: isBusy ? "wait" : "pointer", fontWeight: 600, opacity: isBusy ? 0.6 : 1 }, onClick: () => void runAction(r.runId, "cancel"), children: tr(t, "drawer.cancel.confirm", "确认取消?") }), _jsx("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-secondary)", cursor: "pointer" }, onClick: () => setConfirmCancel(null), children: tr(t, "drawer.cancel.back", "返回") })] })) : (_jsxs("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-secondary)", cursor: "pointer" }, onClick: () => { setConfirmCancel(r.runId); setReturnFor(null); }, children: ["\u2715 ", tr(t, "run.cancel.action", "取消")] }))) : null] }), returnFor === r.runId ? (_jsxs("div", { style: { padding: "0 6px 6px 16px" }, children: [_jsx("textarea", { ref: returnRef, rows: 2, value: returnText, onChange: (e) => setReturnText(e.target.value), "aria-label": tr(t, "run.return.opinion", "打回意见(会随命令发给模型)"), placeholder: tr(t, "run.return.placeholder", "例如:边界情况没覆盖,测试全挂了,请先修 CI 再交付…"), style: { width: "100%", boxSizing: "border-box", fontSize: "12px", padding: "6px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-bg-layer-2)", color: "var(--dsw-alias-label-primary)", resize: "vertical" } }), _jsxs("div", { style: { display: "flex", gap: "6px", alignItems: "center", marginTop: "6px" }, children: [_jsx("button", { type: "button", style: { fontSize: "11px", padding: "2px 10px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "var(--dsw-alias-state-error-secondary)", color: "var(--dsw-alias-state-error-primary)", cursor: isBusy ? "wait" : "pointer", opacity: isBusy ? 0.6 : 1 }, disabled: isBusy || !returnText.trim(), onClick: () => void runAction(r.runId, "return", returnText.trim()), children: tr(t, "run.return.send", "发送打回") }), _jsx("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-label-secondary)", cursor: "pointer" }, onClick: () => { setReturnFor(null); setReturnText(""); }, children: tr(t, "run.cancel.action", "取消") })] })] })) : null, showMsg ? (_jsx("div", { style: { padding: "2px 6px 4px 16px", fontSize: "11.5px", color: showMsg.ok ? "var(--dsw-alias-state-success-primary)" : "var(--dsw-alias-state-error-primary)" }, children: showMsg.ok ? `✓ ${tr(t, "run.hint.approved", "已提交,进度将实时更新。")}` : `⚠ ${showMsg.text}` })) : null, isExpanded ? (_jsxs("div", { style: { padding: "4px 8px 6px 16px", fontSize: "12px", color: "var(--dsw-alias-label-secondary)", lineHeight: 1.6 }, children: [detail?.owner ? (_jsxs("div", { style: { marginBottom: "4px" }, children: [_jsxs("strong", { style: { color: "var(--dsw-alias-label-primary)" }, children: [tr(t, "drawer.owner", "属主"), "\uFF1A"] }), detail.owner === sessionId ? tr(t, "drawer.owner.me", "本会话") : String(detail.owner).slice(0, 8)] })) : null, r.task ? _jsxs("div", { style: { marginBottom: "4px" }, children: [_jsxs("strong", { style: { color: "var(--dsw-alias-label-primary)" }, children: [tr(t, "drawer.task", "任务"), "\uFF1A"] }), " ", String(r.task)] }) : null, r.status === "gate" && detail?.gate ? (_jsxs("div", { style: { marginBottom: "4px", padding: "4px 8px", borderRadius: "6px", background: "var(--dsw-alias-state-warn-tertiary)" }, children: [_jsxs("strong", { style: { color: "var(--dsw-alias-label-primary)" }, children: [tr(t, "drawer.gate.todo", "审查要求"), "\uFF1A"] }), " ", String(detail.gate.title ?? r.current?.step ?? ""), detail.gate.reason ? _jsx("div", { style: { marginTop: "2px" }, children: String(detail.gate.reason) }) : null, detail.gate.taskExcerpt ? (_jsx("div", { style: { marginTop: "4px", whiteSpace: "pre-wrap", wordBreak: "break-word", maxHeight: "120px", overflowY: "auto", background: "var(--dsw-alias-bg-layer-2)", padding: "4px 6px", borderRadius: "4px" }, children: String(detail.gate.taskExcerpt) })) : null] })) : null, detail?.pauseReason ? (_jsxs("div", { style: { marginBottom: "4px" }, children: [_jsxs("strong", { style: { color: "var(--dsw-alias-label-primary)" }, children: [tr(t, "drawer.pausereason", "暂停原因"), "\uFF1A"] }), " ", String(detail.pauseReason)] })) : null, detail?.lastFailureReason ? (_jsxs("div", { style: { marginBottom: "4px", maxHeight: "150px", overflowY: "auto" }, children: [_jsxs("strong", { style: { color: "var(--dsw-alias-label-primary)" }, children: [tr(t, "drawer.failreason", "失败原因"), "\uFF1A"] }), _jsx("div", { style: { whiteSpace: "pre-wrap", wordBreak: "break-word" }, children: String(detail.lastFailureReason) })] })) : null, detail?.current?.phase === "check" && !detail?.paused
|
|
471
|
+
? (() => {
|
|
472
|
+
const tl = checkTimeLeft(detail.checkStartedAt, detail.timeoutMs);
|
|
473
|
+
if (!tl)
|
|
474
|
+
return null;
|
|
475
|
+
const minutes = Math.max(1, Math.round((detail.timeoutMs ?? 0) / 60000));
|
|
476
|
+
return (_jsxs("div", { style: { marginBottom: "6px" }, children: [_jsxs("div", { style: { display: "flex", justifyContent: "space-between", gap: "8px", fontSize: "11px", marginBottom: "2px" }, children: [_jsx("span", { style: { color: tl.over ? "var(--dsw-alias-state-error-primary)" : tl.ratio > 0.85 ? "var(--dsw-alias-state-warn-primary)" : "var(--dsw-alias-label-tertiary)" }, children: tl.over
|
|
477
|
+
? tr(t, "drawer.timeout", "已超时,等待自动暂停")
|
|
478
|
+
: trf2(t, "drawer.timeleft", "剩余 {t}", { t: formatElapsed(tl.leftMs) }) }), _jsx("span", { style: { color: "var(--dsw-alias-label-tertiary)" }, children: trf2(t, "run.timeout.left", "超时上限 {min} 分钟", { min: minutes }) })] }), _jsx("div", { style: { height: 4, borderRadius: 2, background: "var(--dsw-alias-bg-layer-2)", overflow: "hidden" }, children: _jsx("div", { style: {
|
|
479
|
+
height: "100%",
|
|
480
|
+
width: `${Math.round(tl.ratio * 100)}%`,
|
|
481
|
+
background: tl.over || tl.ratio > 0.85
|
|
482
|
+
? "var(--dsw-alias-state-error-primary)"
|
|
483
|
+
: tl.ratio > 0.6
|
|
484
|
+
? "var(--dsw-alias-state-warn-primary)"
|
|
485
|
+
: "var(--dsw-alias-state-business-primary)",
|
|
486
|
+
transition: "width .6s ease",
|
|
487
|
+
} }) })] }));
|
|
488
|
+
})()
|
|
489
|
+
: null, Array.isArray(detail?.voterProgress) && detail.voterProgress.length > 0 ? (_jsxs("div", { style: { marginBottom: "4px" }, children: [_jsxs("strong", { style: { color: "var(--dsw-alias-label-primary)" }, children: [tr(t, "drawer.voters", "验证者"), "\uFF1A"] }), _jsx("ul", { style: { margin: "2px 0 0", paddingLeft: "16px" }, children: detail.voterProgress.map((v, i) => (_jsxs("li", { style: { margin: "1px 0" }, children: [trf2(t, "run.verifier", "验证者 {v}/{count}", { v: v.voter, count: detail.voterProgress.length }), " ", _jsx("span", { style: { color: voterColor(v.status), fontWeight: 600 }, children: voterLabel(t, v.status) }), typeof v.startedAt === "number" && (v.status === "running" || v.status === "infra_pending")
|
|
490
|
+
? ` · ${formatElapsed(Date.now() - v.startedAt)}`
|
|
491
|
+
: "", v.model ? ` · ${v.model}` : "", v.check ? ` — ${v.check}` : ""] }, i))) })] })) : null] })) : null] }, r.key || r.runId));
|
|
492
|
+
};
|
|
493
|
+
// 冷启动:无任务时灰态入口 + 迷你上手卡(发现路径)
|
|
494
|
+
if (runs.length === 0) {
|
|
495
|
+
return (_jsxs("div", { ref: rootRef, style: style.root, children: [_jsxs("button", { type: "button", style: { ...style.trigger, color: "var(--dsw-alias-label-tertiary)", borderColor: "var(--dsw-alias-border-l1)", maxWidth: "220px" }, "aria-expanded": open, "aria-haspopup": "dialog", "aria-label": tr(t, "coldstart.aria", "Ralph Flow:工作流引擎(点击查看上手引导)"), onClick: () => setOpen((v) => !v), children: [_jsx("span", { "aria-hidden": "true", style: { width: "8px", height: "8px", borderRadius: "50%", flexShrink: 0, background: "var(--dsw-alias-border-l2)" } }), _jsx("span", { children: "Ralph Flow" })] }), open ? (_jsxs("div", { id: "ralphflow-header-menu", role: "dialog", "aria-label": tr(t, "coldstart.title", "开始使用 Ralph Flow"), style: { ...style.menu, width: "300px" }, children: [_jsxs("div", { style: { fontSize: "12.5px", fontWeight: 600, color: "var(--dsw-alias-label-primary)", padding: "4px 6px" }, children: ["\uD83C\uDF00 ", tr(t, "coldstart.title", "开始使用 Ralph Flow")] }), _jsx("div", { style: { fontSize: "12px", color: "var(--dsw-alias-label-secondary)", padding: "0 6px 8px", lineHeight: 1.55 }, children: tr(t, "coldstart.desc", "DO→CHECK 状态机工作流:模型执行任务,独立验证者对抗检查,失败自动返工,关键步骤停下等你审查。") }), [
|
|
496
|
+
{ cmd: "/loop ", label: tr(t, "coldstart.try.loop", "/loop <任务描述> — 迭代执行直到验证通过"), autosubmit: false },
|
|
497
|
+
{ cmd: "/ralphflow-list", label: tr(t, "coldstart.try.list", "/ralphflow-list — 查看可用工作流"), autosubmit: true },
|
|
498
|
+
].map((item) => (_jsxs("button", { type: "button", style: style.row, onClick: () => {
|
|
499
|
+
setOpen(false);
|
|
500
|
+
window.dispatchEvent(new CustomEvent("ralphflow:command", { detail: { command: item.cmd, autoSubmit: item.autosubmit } }));
|
|
501
|
+
}, children: [_jsx("span", { "aria-hidden": "true", style: { color: "var(--dsw-alias-state-business-primary)", flexShrink: 0 }, children: "\u25B6" }), _jsx("span", { style: { overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", minWidth: 0, color: "var(--dsw-alias-label-primary)" }, children: item.label })] }, item.cmd)))] })) : null] }));
|
|
502
|
+
}
|
|
503
|
+
return (_jsxs("div", { ref: rootRef, style: style.root, children: [_jsxs("button", { type: "button", style: { ...style.trigger, maxWidth: "300px" }, "aria-expanded": open, "aria-haspopup": "dialog", "aria-controls": "ralphflow-header-menu", "aria-label": tr(t, "header.aria", `Ralph Flow:{live} 运行中,{gate} 待审查,{fail} 已暂停`)
|
|
504
|
+
.replace("{live}", String(liveCount)).replace("{gate}", String(gateCount)).replace("{fail}", String(failCount)), onClick: () => setOpen((v) => !v), children: [_jsx("span", { "aria-hidden": "true", style: { width: "8px", height: "8px", borderRadius: "50%", flexShrink: 0, background: statusColorOf(primary ? primary.status : "do") } }), _jsx("span", { style: { flexShrink: 0 }, children: "Ralph Flow" }), primary && (primary.status === "do" || primary.status === "check") ? (_jsxs(_Fragment, { children: [_jsx(MiniPipeline, { steps: primary.steps, current: primary.current, status: primary.status }), typeof primary.stepStartedAt === "number" ? (_jsx("span", { style: { fontSize: "11px", color: "var(--dsw-alias-label-tertiary)", ...NUM }, children: formatElapsed(Date.now() - primary.stepStartedAt) })) : null] })) : null, liveCount > 1 ? _jsx("span", { style: NUM, children: liveCount }) : null, gateCount > 0 ? _jsx("span", { style: badgeWarn, children: gateCount }) : null, failCount > 0 ? _jsx("span", { style: badgeFail, children: failCount }) : null] }), open ? (_jsxs("div", { id: "ralphflow-header-menu", role: "dialog", "aria-label": tr(t, "header.list", "Ralph Flow 任务列表"), style: style.menu, children: [waiting.length + live.length > 0 ? (_jsxs("div", { children: [waiting.length > 0 ? (_jsxs(_Fragment, { children: [_jsxs("div", { style: { fontSize: "11px", fontWeight: 600, color: "var(--dsw-alias-state-warn-primary)", textTransform: "uppercase", letterSpacing: ".04em", padding: "2px 6px 6px" }, children: [tr(t, "drawer.todo", "待处理"), waiting.length > 1 ? ` · ${waiting.length}` : ""] }), waiting.map(renderRow)] })) : null, live.length > 0 ? (_jsxs(_Fragment, { children: [_jsxs("div", { style: { fontSize: "11px", fontWeight: 600, color: "var(--dsw-alias-label-tertiary)", textTransform: "uppercase", letterSpacing: ".04em", padding: waiting.length > 0 ? "10px 6px 6px" : "2px 6px 6px" }, children: [tr(t, "drawer.live", "运行中"), live.length > 1 ? ` · ${live.length}` : ""] }), live.map(renderRow)] })) : null] })) : null, ended.length > 0 ? (_jsxs("div", { style: { marginTop: live.length > 0 || waiting.length > 0 ? "10px" : 0 }, children: [_jsx("div", { style: { fontSize: "11px", fontWeight: 600, color: "var(--dsw-alias-label-tertiary)", textTransform: "uppercase", letterSpacing: ".04em", padding: "2px 6px 6px" }, children: tr(t, "drawer.ended", "已结束(本会话)") }), ended.slice(-6).map((r) => (_jsxs("div", { children: [_jsxs("button", { type: "button", style: style.row, title: r.status === "detached" ? tr(t, "status.detached", "已转交") : r.task, onClick: () => { setOpen(false); locateRun(r); }, children: [_jsx("span", { "aria-hidden": "true", style: { width: 8, height: 8, borderRadius: "50%", background: statusColorOf(r.status), flexShrink: 0 } }), _jsxs("span", { style: { color: "var(--dsw-alias-label-primary)", overflow: "hidden", textOverflow: "ellipsis", whiteSpace: "nowrap", minWidth: 0 }, children: [r.workflow, r.runId ? `·${r.runId.slice(-4)}` : ""] }), _jsx("span", { style: { marginLeft: "auto", fontSize: "11px", color: "var(--dsw-alias-label-tertiary)", flexShrink: 0 }, children: statusLabelOf(t, r.status) })] }), r.reportPath ? (_jsx("div", { style: { paddingLeft: "16px", paddingBottom: "4px" }, children: _jsxs("button", { type: "button", style: { fontSize: "11px", padding: "2px 8px", borderRadius: "6px", border: "1px solid var(--dsw-alias-border-l2)", background: "transparent", color: "var(--dsw-alias-state-business-primary)", cursor: "pointer" }, onClick: () => { try {
|
|
505
|
+
window.open(r.reportPath, "_blank");
|
|
506
|
+
}
|
|
507
|
+
catch { } }, children: ["\uD83D\uDCC4 ", tr(t, "drawer.report", "报告")] }) })) : null] }, r.key || r.runId))), ended.length > 6 ? (_jsx("div", { style: { fontSize: "11px", color: "var(--dsw-alias-label-tertiary)", padding: "0 8px 4px" }, children: trf2(t, "drawer.ended.more", "…以及更早的 {n} 条", { n: ended.length - 6 }) })) : null] })) : null] })) : null] }));
|
|
508
|
+
}
|
|
509
|
+
export default HeaderAction;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Ralph Flow for dsh — 对话内嵌 run 卡片(进度/验证/审批/报告)
|
|
3
|
+
*
|
|
4
|
+
* 注册进 conversation.chat.node(keyed kind 'ralphflow-run')。按数据分支渲染:
|
|
5
|
+
* 步骤条 / 验证者活体面板 / 审查门(含审批材料与内联打回意见)/ 报告(Markdown
|
|
6
|
+
* 渲染)/ 回退历史。全部消费 dsh 官方主题 token。
|
|
7
|
+
*
|
|
8
|
+
* 设计要点:
|
|
9
|
+
* - 可观测等待:验证者逐个「排队→运行中(计时)→已判定」点亮,超时进度条给
|
|
10
|
+
* 等待一个终点——「在跑」和「死了」从此长得不一样。
|
|
11
|
+
* - 判断支持:审查门内嵌该步任务要求摘要;打回意见在卡内写好后随命令提交
|
|
12
|
+
* (非空意见才代提交,空意见仍只填不代发)。
|
|
13
|
+
* - 诚实状态语言:failed = ⏸ 已暂停(可恢复),不是死亡。
|
|
14
|
+
*/
|
|
15
|
+
import * as React from "react";
|
|
16
|
+
export interface RalphRunCardProps {
|
|
17
|
+
/** chat.node 槽组件签名:数据在 node.data(与官方 ChatNodeView 一致) */
|
|
18
|
+
node?: {
|
|
19
|
+
data?: any;
|
|
20
|
+
};
|
|
21
|
+
/** 打开会话中的文件(来自 slot owner 注入) */
|
|
22
|
+
openFile?: (path: string) => void;
|
|
23
|
+
/** locale 翻译函数(slot locale 注入;可能缺省,缺省用内置中文兜底) */
|
|
24
|
+
t?: (key: string, params?: Record<string, unknown>) => string;
|
|
25
|
+
}
|
|
26
|
+
export declare function RalphRunCard({ node, t }: RalphRunCardProps): React.JSX.Element | null;
|
|
27
|
+
export default RalphRunCard;
|