@dsh-workbench/shared 1.5.3 → 1.5.4-beta.1

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.
Files changed (37) hide show
  1. package/dist/components/card/ApprovalDetail.d.ts +1 -0
  2. package/dist/components/card/ApprovalDetail.js +16 -2
  3. package/dist/components/card/LongTaskRow.css +62 -0
  4. package/dist/components/card/LongTaskRow.d.ts +17 -6
  5. package/dist/components/card/LongTaskRow.js +88 -46
  6. package/dist/components/card/board-module.d.ts +1 -0
  7. package/dist/contract/long-task.d.ts +20 -0
  8. package/dist/contract/long-task.js +2 -0
  9. package/dist/contract/protocol/long-tasks.d.ts +3 -1
  10. package/dist/host/flow/run.js +8 -2
  11. package/dist/host/flow/step.d.ts +1 -1
  12. package/dist/host/flow/step.js +8 -5
  13. package/dist/host/flow/task.js +12 -6
  14. package/dist/host/flow/types.d.ts +3 -2
  15. package/dist/host/unit/long-task.d.ts +13 -1
  16. package/dist/host/unit/long-task.js +56 -3
  17. package/dist/i18n/en.js +12 -0
  18. package/dist/i18n/index.d.ts +13 -1
  19. package/dist/i18n/zh.d.ts +12 -0
  20. package/dist/i18n/zh.js +12 -0
  21. package/package.json +1 -1
  22. package/src/components/card/ApprovalDetail.tsx +16 -2
  23. package/src/components/card/LongTaskRow.css +62 -0
  24. package/src/components/card/LongTaskRow.tsx +203 -110
  25. package/src/components/card/__tests__/long-task-row.test.ts +69 -15
  26. package/src/components/card/board-module.ts +1 -0
  27. package/src/contract/long-task.ts +24 -0
  28. package/src/contract/protocol/long-tasks.ts +8 -1
  29. package/src/host/flow/__tests__/step.test.ts +20 -0
  30. package/src/host/flow/run.ts +8 -2
  31. package/src/host/flow/step.ts +9 -5
  32. package/src/host/flow/task.ts +13 -5
  33. package/src/host/flow/types.ts +3 -2
  34. package/src/host/unit/__tests__/long-task.test.ts +79 -0
  35. package/src/host/unit/long-task.ts +70 -2
  36. package/src/i18n/en.ts +12 -0
  37. package/src/i18n/zh.ts +12 -0
@@ -7,6 +7,7 @@ interface ToolCallRoot {
7
7
  readonly name?: string;
8
8
  readonly phase?: string;
9
9
  readonly argsRaw?: string;
10
+ readonly subCalls?: readonly ToolCallRoot[];
10
11
  }
11
12
  interface ChatSnapshot {
12
13
  readonly nodes?: {
@@ -3,14 +3,28 @@ import { CodeBlock } from '@deepseek-ai/dsh-client-ui-primitives';
3
3
  import { ApprovalPlan } from './ApprovalPlan.js';
4
4
  import { CardBoundary } from './CardBoundary.js';
5
5
  import './ApprovalDetail.css';
6
+ const MAX_CALL_DEPTH = 64;
7
+ function findCall(root, callId, depth) {
8
+ if (root === undefined || depth > MAX_CALL_DEPTH)
9
+ return undefined;
10
+ if (root.callId === callId && root.phase === 'start')
11
+ return root;
12
+ for (const child of root.subCalls ?? []) {
13
+ const found = findCall(child, callId, depth + 1);
14
+ if (found !== undefined)
15
+ return found;
16
+ }
17
+ return undefined;
18
+ }
6
19
  function callOf(snapshot, callId) {
7
20
  if (callId === undefined)
8
21
  return undefined;
9
22
  for (const node of snapshot.nodes?.values() ?? []) {
10
23
  const root = node.kind === 'tool-call' ? node.data?.root : undefined;
11
- if (root?.callId !== callId || root.phase !== 'start')
24
+ const call = findCall(root, callId, 0);
25
+ if (call === undefined)
12
26
  continue;
13
- return { ...(root.name === undefined ? {} : { name: root.name }), argsRaw: root.argsRaw ?? '' };
27
+ return { ...(call.name === undefined ? {} : { name: call.name }), argsRaw: call.argsRaw ?? '' };
14
28
  }
15
29
  return undefined;
16
30
  }
@@ -169,3 +169,65 @@
169
169
  border-color: var(--dsw-alias-state-business-primary);
170
170
  box-shadow: inset 0 0 0 0.5px var(--dsw-alias-state-business-primary);
171
171
  }
172
+
173
+ .wb-longTaskStep {
174
+ margin: 0;
175
+ font-size: var(--dsw-font-xxs-12-font-size);
176
+ line-height: var(--wb-line-18);
177
+ color: var(--dsw-alias-label-secondary);
178
+ white-space: nowrap;
179
+ overflow: hidden;
180
+ text-overflow: ellipsis;
181
+ }
182
+
183
+ .wb-longTaskMeta {
184
+ margin: 0;
185
+ font-size: var(--dsw-font-xxxs-11-font-size);
186
+ line-height: var(--wb-line-16);
187
+ color: var(--dsw-alias-label-tertiary);
188
+ white-space: nowrap;
189
+ overflow: hidden;
190
+ text-overflow: ellipsis;
191
+ }
192
+
193
+ .wb-longTaskStopPending {
194
+ margin: 0;
195
+ font-size: var(--dsw-font-xxxs-11-font-size);
196
+ line-height: var(--wb-line-16);
197
+ color: var(--dsw-alias-label-tertiary);
198
+ overflow-wrap: anywhere;
199
+ }
200
+
201
+ .wb-longTaskSteps {
202
+ display: flex;
203
+ flex-direction: column;
204
+ gap: var(--wb-len-2);
205
+ margin: var(--wb-len-4) 0 0;
206
+ padding: 0;
207
+ list-style: none;
208
+ max-height: var(--wb-len-220);
209
+ overflow: auto;
210
+ }
211
+
212
+ .wb-longTaskStepRow {
213
+ display: flex;
214
+ align-items: center;
215
+ gap: var(--wb-len-6);
216
+ font-size: var(--dsw-font-xxxs-11-font-size);
217
+ line-height: var(--wb-line-16);
218
+ color: var(--dsw-alias-label-tertiary);
219
+ }
220
+
221
+ .wb-longTaskStepText {
222
+ flex: 1;
223
+ min-width: 0;
224
+ overflow-wrap: anywhere;
225
+ }
226
+
227
+ .wb-longTaskStepRow[data-kind='fail'] .wb-longTaskStepText {
228
+ color: var(--dsw-alias-state-error-primary);
229
+ }
230
+
231
+ .wb-longTaskStepLink {
232
+ flex: none;
233
+ }
@@ -1,4 +1,4 @@
1
- import { type LongTaskInterventionField, type LongTaskStatus } from '../../contract/long-task.js';
1
+ import { type LongTaskInterventionField, type LongTaskStatus, type LongTaskStepRow } from '../../contract/long-task.js';
2
2
  import './LongTaskRow.css';
3
3
  /**
4
4
  * 长任务行尾的一个链接:地址与文字。
@@ -20,6 +20,7 @@ export interface LongTaskRowStop {
20
20
  readonly armedLabel?: string | undefined;
21
21
  readonly busy?: boolean | undefined;
22
22
  readonly failed?: string | null | undefined;
23
+ readonly pending?: string | undefined;
23
24
  }
24
25
  /**
25
26
  * 跑在 `needs-login` 时那颗「去登录」:文案与点击。
@@ -62,9 +63,14 @@ export interface LongTaskRowIntervention {
62
63
  export interface LongTaskRowProps {
63
64
  readonly status: LongTaskStatus;
64
65
  readonly headline: string;
66
+ readonly step?: string | undefined;
67
+ readonly meta?: string | undefined;
68
+ readonly dot?: 'done' | 'ongoing' | 'error' | 'idle' | 'warning' | undefined;
69
+ readonly dotLabel?: string | undefined;
65
70
  readonly problem?: string | undefined;
66
71
  readonly links?: readonly LongTaskRowLink[] | undefined;
67
72
  readonly steps?: readonly string[] | undefined;
73
+ readonly history?: readonly LongTaskStepRow[] | undefined;
68
74
  readonly raw?: string | undefined;
69
75
  readonly stepsTitle?: string | undefined;
70
76
  readonly rawTitle?: string | undefined;
@@ -75,19 +81,24 @@ export interface LongTaskRowProps {
75
81
  readonly stop?: LongTaskRowStop | undefined;
76
82
  }
77
83
  /**
78
- * 长任务那一行:状态点 + 标题 + 链接,跑失败时把步骤与原始输出收在两处可展开里。
84
+ * 长任务那一行:点 + 标题 + 链接,可选一行当前步骤与一行状态 · 耗时;步骤收在可展开里。
79
85
  * 发布、扫描、迁移这类跑得久的事都用它,别自己画进度。
80
- * @param props.status - `longTaskDot` 认的五态之一,决定状态点颜色与要不要画"失败"那两块。
86
+ * @param props.status - 六态之一,决定默认的点与「失败」那一块。
81
87
  * @param props.headline - 这一行在干什么(一句话)。
88
+ * @param props.step - 当前步骤;运行中 / 停止后给,不给不画。
89
+ * @param props.meta - 状态词 · 耗时那一行;不给不画。
90
+ * @param props.dot - 点的档位覆盖;不给就用 `longTaskDot(status)`。
91
+ * @param props.dotLabel - 点的读屏文案;不给就不挂 `aria-label`。
82
92
  * @param props.problem - 失败原因;不给不画。
83
93
  * @param props.links - 行尾的链接,通常指向产物或日志。
84
- * @param props.steps - 步骤文本;只在失败时画,且要同时给 `stepsTitle` 才成一块可展开。
85
- * @param props.raw - 原始输出;只在失败时画,且要同时给 `rawTitle` 才成一块可展开。
94
+ * @param props.steps - 旧的纯文本步骤;只在没有 `history` 时作为回退画。
95
+ * @param props.history - 结构化步骤;有它就一行一步,每步的链接挂在行尾。
96
+ * @param props.raw - 原始输出;给了 `rawTitle` 才成一块可展开。
86
97
  * @param props.stepsTitle - 步骤那块展开行的标题;`rawTitle` 同理是原始输出那块。
87
98
  * @param props.copyLabel - 复制钮文案:给了才画复制钮;`copiedLabel` 是复制成功后那句。
88
99
  * @param props.login - `needs-login` 时那颗「去登录」;不给不画。
89
100
  * @param props.intervention - `needs-human` 时的「要人做什么」那一行与动作;不给不画。
90
- * @param props.stop - 给了才在最右边画那颗两按停止钮;**不给就一个像素都不变**。只在生产方认 `signal` 时给。
101
+ * @param props.stop - 给了才在最右边画那颗两按停止钮;**不给就一个像素都不变**。`pending` 是「已请求停止,等模块确认」那句。
91
102
  * @returns 一行长任务。
92
103
  */
93
104
  export declare function LongTaskRow(props: LongTaskRowProps): JSX.Element;
@@ -1,4 +1,4 @@
1
- import { longTaskDot, longTaskStopPress, longTaskStopStage, LONG_TASK_STOP_ARM_MS, } from '../../contract/long-task.js';
1
+ import { LONG_TASK_LINK_MAX, longTaskDot, longTaskIsLive, longTaskStopPress, longTaskStopStage, LONG_TASK_STOP_ARM_MS, } from '../../contract/long-task.js';
2
2
  import { Link } from '../layout/Link.js';
3
3
  import { Fragment, h, useEffect, useState } from '../../lib/react.js';
4
4
  import { Button, CodeBlock, DisclosureRow, IconCodeOutlineRegular, IconFlatListOutlineRegular, IconStopFillRegular, StateDot, } from '@deepseek-ai/dsh-client-ui-primitives';
@@ -6,6 +6,26 @@ import './LongTaskRow.css';
6
6
  function RowLink({ href, text }) {
7
7
  return (h(Link, { href: href, className: "wb-longTaskLink" }, text));
8
8
  }
9
+ const STEP_DOT = {
10
+ start: 'ongoing',
11
+ succeed: 'done',
12
+ fail: 'error',
13
+ warn: 'warning',
14
+ info: 'idle',
15
+ };
16
+ const HTTP_PATTERN = /^https?:\/\//i;
17
+ function StepRow({ row }) {
18
+ const links = (row.links ?? [])
19
+ .filter((link) => HTTP_PATTERN.test(link.href))
20
+ .slice(0, LONG_TASK_LINK_MAX);
21
+ return (h("li", { className: "wb-longTaskStepRow", "data-kind": row.kind },
22
+ h(StateDot, { state: STEP_DOT[row.kind], size: 8 }),
23
+ h("span", { className: "wb-longTaskStepText" }, row.text),
24
+ links.map((link) => (h(Link, { className: "wb-longTaskStepLink", href: link.href, key: `${link.href}@${link.text}` }, link.text)))));
25
+ }
26
+ function DumpBlock(props) {
27
+ return (h(DisclosureRow, { className: "wb-longTaskDump", icon: props.icon, title: props.title, open: props.open, expandable: true, expandOnRowClick: true, previewChevron: true, onToggle: props.onToggle }, props.children));
28
+ }
9
29
  function InterventionForm({ fields, submit }) {
10
30
  const [values, setValues] = useState({});
11
31
  const submitBusy = submit.busy === true;
@@ -27,77 +47,99 @@ function InterventionForm({ fields, submit }) {
27
47
  h(Button, { type: "submit", size: "sm", variant: "primary", disabled: submitBusy || requiredMissing }, submit.label)),
28
48
  submitFailed === '' ? null : h("p", { className: "wb-longTaskNeedWhy" }, submitFailed)));
29
49
  }
50
+ function StopControl({ stop, onFired }) {
51
+ const [armed, setArmed] = useState(false);
52
+ const busy = stop.busy === true;
53
+ useEffect(() => {
54
+ if (!armed)
55
+ return undefined;
56
+ const timer = setTimeout(() => setArmed(false), LONG_TASK_STOP_ARM_MS);
57
+ return () => clearTimeout(timer);
58
+ }, [armed]);
59
+ const onPress = () => {
60
+ const press = longTaskStopPress(longTaskStopStage({ armed, busy }));
61
+ if (press === 'ignore')
62
+ return;
63
+ if (press === 'arm') {
64
+ setArmed(true);
65
+ return;
66
+ }
67
+ setArmed(false);
68
+ onFired();
69
+ stop.onStop();
70
+ };
71
+ return (h("button", { type: "button", className: `wb-longTaskStop${armed ? ' wb-longTaskStopArmed' : ''}`, "data-stop-state": longTaskStopStage({ armed, busy }), "aria-label": armed ? stop.armedLabel ?? stop.askLabel : stop.label, disabled: busy, onClick: onPress, onBlur: () => setArmed(false) },
72
+ h(IconStopFillRegular, { size: 12 }),
73
+ armed ? h("span", { className: "wb-longTaskStopLabel" }, stop.askLabel) : null));
74
+ }
75
+ function InterventionNeed({ intervention }) {
76
+ const fields = intervention.fields ?? [];
77
+ const submit = intervention.submit;
78
+ return (h(Fragment, null,
79
+ h("p", { className: "wb-longTaskNeed" },
80
+ h("span", { className: "wb-longTaskNeedTitle" }, intervention.title),
81
+ intervention.hint === undefined ? null : (h("span", { className: "wb-longTaskNeedHint" }, intervention.hint)),
82
+ (intervention.actions ?? []).map((action) => (h(Button, { key: action.key, type: "button", size: "sm", variant: action.primary === true ? 'primary' : 'outline', disabled: action.busy === true, onClick: action.onPress }, action.label)))),
83
+ fields.length === 0 || submit === undefined ? null : (h(InterventionForm, { fields: fields, submit: submit })),
84
+ intervention.failed === undefined || intervention.failed === null || intervention.failed === '' ? null : (h("p", { className: "wb-longTaskNeedWhy" }, intervention.failed))));
85
+ }
30
86
  /**
31
- * 长任务那一行:状态点 + 标题 + 链接,跑失败时把步骤与原始输出收在两处可展开里。
87
+ * 长任务那一行:点 + 标题 + 链接,可选一行当前步骤与一行状态 · 耗时;步骤收在可展开里。
32
88
  * 发布、扫描、迁移这类跑得久的事都用它,别自己画进度。
33
- * @param props.status - `longTaskDot` 认的五态之一,决定状态点颜色与要不要画"失败"那两块。
89
+ * @param props.status - 六态之一,决定默认的点与「失败」那一块。
34
90
  * @param props.headline - 这一行在干什么(一句话)。
91
+ * @param props.step - 当前步骤;运行中 / 停止后给,不给不画。
92
+ * @param props.meta - 状态词 · 耗时那一行;不给不画。
93
+ * @param props.dot - 点的档位覆盖;不给就用 `longTaskDot(status)`。
94
+ * @param props.dotLabel - 点的读屏文案;不给就不挂 `aria-label`。
35
95
  * @param props.problem - 失败原因;不给不画。
36
96
  * @param props.links - 行尾的链接,通常指向产物或日志。
37
- * @param props.steps - 步骤文本;只在失败时画,且要同时给 `stepsTitle` 才成一块可展开。
38
- * @param props.raw - 原始输出;只在失败时画,且要同时给 `rawTitle` 才成一块可展开。
97
+ * @param props.steps - 旧的纯文本步骤;只在没有 `history` 时作为回退画。
98
+ * @param props.history - 结构化步骤;有它就一行一步,每步的链接挂在行尾。
99
+ * @param props.raw - 原始输出;给了 `rawTitle` 才成一块可展开。
39
100
  * @param props.stepsTitle - 步骤那块展开行的标题;`rawTitle` 同理是原始输出那块。
40
101
  * @param props.copyLabel - 复制钮文案:给了才画复制钮;`copiedLabel` 是复制成功后那句。
41
102
  * @param props.login - `needs-login` 时那颗「去登录」;不给不画。
42
103
  * @param props.intervention - `needs-human` 时的「要人做什么」那一行与动作;不给不画。
43
- * @param props.stop - 给了才在最右边画那颗两按停止钮;**不给就一个像素都不变**。只在生产方认 `signal` 时给。
104
+ * @param props.stop - 给了才在最右边画那颗两按停止钮;**不给就一个像素都不变**。`pending` 是「已请求停止,等模块确认」那句。
44
105
  * @returns 一行长任务。
45
106
  */
46
107
  export function LongTaskRow(props) {
47
- const [stepsOpen, setStepsOpen] = useState(false);
108
+ const [stepsOpen, setStepsOpen] = useState(props.status === 'failed');
48
109
  const [rawOpen, setRawOpen] = useState(false);
49
- const [armed, setArmed] = useState(false);
110
+ const [stopFired, setStopFired] = useState(false);
50
111
  const failed = props.status === 'failed';
112
+ const live = longTaskIsLive(props.status);
113
+ const dot = props.dot ?? longTaskDot(props.status);
114
+ const step = props.step ?? '';
115
+ const meta = props.meta ?? '';
116
+ const history = props.history ?? [];
51
117
  const problem = props.problem ?? '';
52
118
  const raw = (props.raw ?? '').trim();
53
119
  const steps = props.steps ?? [];
54
120
  const stop = props.stop;
55
121
  const busy = stop?.busy === true;
56
122
  const stopWhy = stop?.failed ?? '';
57
- const fields = props.intervention?.fields ?? [];
58
- const submit = props.intervention?.submit;
123
+ const stopPending = stopFired && live && !busy && stopWhy === '' ? stop?.pending ?? '' : '';
59
124
  useEffect(() => {
60
- if (!armed)
61
- return undefined;
62
- const timer = setTimeout(() => setArmed(false), LONG_TASK_STOP_ARM_MS);
63
- return () => clearTimeout(timer);
64
- }, [armed]);
65
- const onStopPress = () => {
66
- if (stop === undefined)
67
- return;
68
- const press = longTaskStopPress(longTaskStopStage({ armed, busy }));
69
- if (press === 'ignore')
70
- return;
71
- if (press === 'arm') {
72
- setArmed(true);
73
- return;
74
- }
75
- setArmed(false);
76
- stop.onStop();
77
- };
125
+ if (failed)
126
+ setStepsOpen(true);
127
+ }, [failed]);
78
128
  return (h("div", { className: "wb-longTask" },
79
129
  h("p", { className: "wb-longTaskHead" },
80
- h(StateDot, { state: longTaskDot(props.status), size: 10 }),
130
+ props.dotLabel === undefined ? (h(StateDot, { state: dot, size: 10 })) : (h("span", { role: "img", "aria-label": props.dotLabel },
131
+ h(StateDot, { state: dot, size: 10 }))),
81
132
  h("span", { className: "wb-longTaskHeadline" }, props.headline),
82
133
  (props.links ?? []).map((link) => (h(RowLink, { href: link.href, key: `${link.text}@${link.href}`, text: link.text }))),
83
134
  props.login === undefined ? null : (h(Button, { type: "button", size: "sm", variant: "outline", onClick: props.login.onOpen }, props.login.label)),
84
- stop === undefined ? null : (h("button", { type: "button", className: `wb-longTaskStop${armed ? ' wb-longTaskStopArmed' : ''}`, "data-stop-state": longTaskStopStage({ armed, busy }), "aria-label": armed ? stop.armedLabel ?? stop.askLabel : stop.label, disabled: busy, onClick: onStopPress, onBlur: () => setArmed(false) },
85
- h(IconStopFillRegular, { size: 12 }),
86
- armed ? h("span", { className: "wb-longTaskStopLabel" }, stop.askLabel) : null))),
87
- props.intervention === undefined ? null : (h(Fragment, null,
88
- h("p", { className: "wb-longTaskNeed" },
89
- h("span", { className: "wb-longTaskNeedTitle" }, props.intervention.title),
90
- props.intervention.hint === undefined ? null : (h("span", { className: "wb-longTaskNeedHint" }, props.intervention.hint)),
91
- (props.intervention.actions ?? []).map((action) => (h(Button, { key: action.key, type: "button", size: "sm", variant: action.primary === true ? 'primary' : 'outline', disabled: action.busy === true, onClick: action.onPress }, action.label)))),
92
- fields.length === 0 || submit === undefined ? null : (h(InterventionForm, { fields: fields, submit: submit })),
93
- props.intervention.failed === undefined ||
94
- props.intervention.failed === null ||
95
- props.intervention.failed === '' ? null : (h("p", { className: "wb-longTaskNeedWhy" }, props.intervention.failed)))),
135
+ stop === undefined ? null : h(StopControl, { stop: stop, onFired: () => setStopFired(true) })),
136
+ step === '' ? null : h("p", { className: "wb-longTaskStep" }, step),
137
+ meta === '' ? null : h("p", { className: "wb-longTaskMeta" }, meta),
138
+ stopPending === '' ? null : h("p", { className: "wb-longTaskStopPending" }, stopPending),
139
+ props.intervention === undefined ? null : (h(InterventionNeed, { intervention: props.intervention })),
96
140
  problem === '' ? null : h("p", { className: "wb-longTaskProblem" }, problem),
97
141
  stopWhy === '' ? null : h("p", { className: "wb-longTaskStopWhy" }, stopWhy),
98
- !failed ? null : (h(Fragment, null,
99
- steps.length === 0 || props.stepsTitle === undefined ? null : (h(DisclosureRow, { className: "wb-longTaskDump", icon: h(IconFlatListOutlineRegular, { size: 14 }), title: props.stepsTitle, open: stepsOpen, expandable: true, expandOnRowClick: true, previewChevron: true, onToggle: () => setStepsOpen(!stepsOpen) },
100
- h(CodeBlock, { code: steps.join('\n'), className: "wb-longTaskDump", showHeader: props.copyLabel !== undefined, copyLabel: props.copyLabel ?? '', copiedLabel: props.copiedLabel ?? '' }))),
101
- raw === '' || props.rawTitle === undefined ? null : (h(DisclosureRow, { className: "wb-longTaskDump", icon: h(IconCodeOutlineRegular, { size: 14 }), title: props.rawTitle, open: rawOpen, expandable: true, expandOnRowClick: true, previewChevron: true, onToggle: () => setRawOpen(!rawOpen) },
102
- h(CodeBlock, { code: raw, className: "wb-longTaskDump", showHeader: props.copyLabel !== undefined, copyLabel: props.copyLabel ?? '', copiedLabel: props.copiedLabel ?? '' })))))));
142
+ props.stepsTitle === undefined || (history.length === 0 && steps.length === 0) ? null : (h(DumpBlock, { icon: h(IconFlatListOutlineRegular, { size: 14 }), title: props.stepsTitle, open: stepsOpen, onToggle: () => setStepsOpen(!stepsOpen) }, history.length === 0 ? (h(CodeBlock, { code: steps.join('\n'), className: "wb-longTaskDump", showHeader: props.copyLabel !== undefined, copyLabel: props.copyLabel ?? '', copiedLabel: props.copiedLabel ?? '' })) : (h("ul", { className: "wb-longTaskSteps" }, history.map((row, index) => (h(StepRow, { key: `${String(index)}:${row.text}`, row: row }))))))),
143
+ raw === '' || props.rawTitle === undefined ? null : (h(DumpBlock, { icon: h(IconCodeOutlineRegular, { size: 14 }), title: props.rawTitle, open: rawOpen, onToggle: () => setRawOpen(!rawOpen) },
144
+ h(CodeBlock, { code: raw, className: "wb-longTaskDump", showHeader: props.copyLabel !== undefined, copyLabel: props.copyLabel ?? '', copiedLabel: props.copiedLabel ?? '' })))));
103
145
  }
@@ -128,6 +128,7 @@ export interface CardViewRow {
128
128
  readonly atTitle?: string | undefined;
129
129
  readonly tone?: CardViewTone | undefined;
130
130
  readonly href?: string | undefined;
131
+ readonly longTaskTarget?: string | undefined;
131
132
  readonly action?: {
132
133
  readonly labelKey: string;
133
134
  readonly href: string;
@@ -16,6 +16,16 @@ export type LongTaskInterventionAction = {
16
16
  readonly text: string;
17
17
  readonly label?: string | undefined;
18
18
  };
19
+ /**
20
+ * 一条「去哪看」的链接:步骤行尾或行进尾部。
21
+ * `text` 是模块写好的字(宿主侧没有 `t`),外壳只放行 `http(s)`。
22
+ */
23
+ export interface LongTaskLink {
24
+ readonly href: string;
25
+ readonly text: string;
26
+ }
27
+ export declare const LONG_TASK_LINK_MAX = 3;
28
+ export declare const LONG_TASK_HISTORY_MAX = 20;
19
29
  /**
20
30
  * 回执字段的输入类型:`text` 明文,`secret` 密码框(值同样只回给模块)。
21
31
  */
@@ -50,9 +60,19 @@ export interface LongTaskIntervention {
50
60
  export interface LongTaskStep {
51
61
  readonly kind: 'start' | 'succeed' | 'fail' | 'info' | 'warn';
52
62
  readonly text: string;
63
+ readonly links?: readonly LongTaskLink[] | undefined;
53
64
  readonly intervention?: LongTaskIntervention | undefined;
54
65
  readonly loginUrl?: string | undefined;
55
66
  }
67
+ /**
68
+ * 快照里的结构化步骤行:`kind` 定颜色、`text` 是文案、`links` 是这条记录的去处。
69
+ * 与 `steps: string[]` 同源、同去重、同上限;旧消费者照旧读 `steps`。
70
+ */
71
+ export interface LongTaskStepRow {
72
+ readonly kind: LongTaskStep['kind'];
73
+ readonly text: string;
74
+ readonly links?: readonly LongTaskLink[] | undefined;
75
+ }
56
76
  /**
57
77
  * 单元的长任务读口路由。
58
78
  * @param unit 单元 id。
@@ -1,3 +1,5 @@
1
+ export const LONG_TASK_LINK_MAX = 3;
2
+ export const LONG_TASK_HISTORY_MAX = 20;
1
3
  /**
2
4
  * 单元的长任务读口路由。
3
5
  * @param unit 单元 id。
@@ -1,4 +1,4 @@
1
- import type { LongTaskIntervention, LongTaskStatus } from '../long-task.js';
1
+ import type { LongTaskIntervention, LongTaskLink, LongTaskStatus, LongTaskStepRow } from '../long-task.js';
2
2
  export declare const LONG_TASKS_ROUTE = "long-tasks";
3
3
  export interface ShellLongTaskRow {
4
4
  readonly unit: string;
@@ -9,6 +9,8 @@ export interface ShellLongTaskRow {
9
9
  readonly status: LongTaskStatus;
10
10
  readonly step?: string | undefined;
11
11
  readonly steps?: readonly string[] | undefined;
12
+ readonly history?: readonly LongTaskStepRow[] | undefined;
13
+ readonly links?: readonly LongTaskLink[] | undefined;
12
14
  readonly intervention?: LongTaskIntervention | undefined;
13
15
  readonly resumable?: boolean | undefined;
14
16
  readonly answerable?: boolean | undefined;
@@ -199,8 +199,14 @@ async function runOneInner(options) {
199
199
  runId,
200
200
  workspace,
201
201
  stepId,
202
- log: (text) => {
203
- emit({ stepId, title, status: 'running', message: text });
202
+ log: (text, links) => {
203
+ emit({
204
+ stepId,
205
+ title,
206
+ status: 'running',
207
+ message: text,
208
+ ...(links === undefined || links.length === 0 ? {} : { links }),
209
+ });
204
210
  },
205
211
  login: (url) => {
206
212
  emit({ stepId, title, status: 'needs-login', loginUrl: url });
@@ -4,7 +4,7 @@ import type { FlowStepEvent } from './types.js';
4
4
  * 把流程的一步事件翻成长任务步骤流的默认一行。
5
5
  * `running` → `start`、`ok` → `succeed`、`skipped` → `info`、`failed` → `fail`、
6
6
  * `needs-login` → `info`(带 `loginUrl`)、`needs-human` → `info`(带 `intervention`);
7
- * 文字取 `message ?? title`(人工干预节点取 `intervention.title`)。
7
+ * 文字取 `message ?? title`(人工干预节点取 `intervention.title`);事件带 `links` 时每一行都跟着带。
8
8
  * 要改文案或过滤步骤,就在模块里自己映射 —— 这只是默认值。
9
9
  * @param event `flow.run({ onStep })` 收到的那条事件。
10
10
  * @returns 能直接交给长任务 `run({ onStep })` 的一行。
@@ -2,20 +2,22 @@
2
2
  * 把流程的一步事件翻成长任务步骤流的默认一行。
3
3
  * `running` → `start`、`ok` → `succeed`、`skipped` → `info`、`failed` → `fail`、
4
4
  * `needs-login` → `info`(带 `loginUrl`)、`needs-human` → `info`(带 `intervention`);
5
- * 文字取 `message ?? title`(人工干预节点取 `intervention.title`)。
5
+ * 文字取 `message ?? title`(人工干预节点取 `intervention.title`);事件带 `links` 时每一行都跟着带。
6
6
  * 要改文案或过滤步骤,就在模块里自己映射 —— 这只是默认值。
7
7
  * @param event `flow.run({ onStep })` 收到的那条事件。
8
8
  * @returns 能直接交给长任务 `run({ onStep })` 的一行。
9
9
  */
10
10
  export function longTaskStepOf(event) {
11
11
  const text = event.message ?? event.title;
12
+ const links = event.links === undefined || event.links.length === 0 ? {} : { links: event.links };
12
13
  if (event.status === 'failed')
13
- return { kind: 'fail', text };
14
+ return { kind: 'fail', text, ...links };
14
15
  if (event.status === 'needs-human') {
15
16
  return {
16
17
  kind: 'info',
17
18
  text: event.intervention?.title ?? text,
18
19
  ...(event.intervention === undefined ? {} : { intervention: event.intervention }),
20
+ ...links,
19
21
  };
20
22
  }
21
23
  if (event.status === 'needs-login') {
@@ -25,11 +27,12 @@ export function longTaskStepOf(event) {
25
27
  ...(event.loginUrl === undefined || event.loginUrl === ''
26
28
  ? {}
27
29
  : { loginUrl: event.loginUrl }),
30
+ ...links,
28
31
  };
29
32
  }
30
33
  if (event.status === 'ok')
31
- return { kind: 'succeed', text };
34
+ return { kind: 'succeed', text, ...links };
32
35
  if (event.status === 'skipped')
33
- return { kind: 'info', text };
34
- return { kind: 'start', text };
36
+ return { kind: 'info', text, ...links };
37
+ return { kind: 'start', text, ...links };
35
38
  }
@@ -19,21 +19,24 @@ function payloadOf(value) {
19
19
  };
20
20
  }
21
21
  function longStepOf(event) {
22
+ const links = event.links === undefined || event.links.length === 0 ? {} : { links: event.links };
22
23
  if (event.status === 'failed') {
23
24
  return {
24
25
  kind: 'fail',
25
26
  text: event.message === undefined ? event.title : `${event.title}:${event.message}`,
27
+ ...links,
26
28
  };
27
29
  }
28
30
  if (event.status === 'skipped')
29
- return { kind: 'info', text: `${event.title}(跳过)` };
31
+ return { kind: 'info', text: `${event.title}(跳过)`, ...links };
30
32
  if (event.status === 'ok')
31
- return { kind: 'succeed', text: event.title };
33
+ return { kind: 'succeed', text: event.title, ...links };
32
34
  if (event.status === 'needs-human') {
33
35
  return {
34
36
  kind: 'info',
35
37
  text: event.intervention?.title ?? event.message ?? event.title,
36
38
  ...(event.intervention === undefined ? {} : { intervention: event.intervention }),
39
+ ...links,
37
40
  };
38
41
  }
39
42
  if (event.status === 'needs-login') {
@@ -43,14 +46,16 @@ function longStepOf(event) {
43
46
  ...(event.loginUrl === undefined || event.loginUrl === ''
44
47
  ? {}
45
48
  : { loginUrl: event.loginUrl }),
49
+ ...links,
46
50
  };
47
51
  }
48
- if (event.message !== undefined)
49
- return { kind: 'info', text: `${event.title}:${event.message}` };
52
+ if (event.message !== undefined) {
53
+ return { kind: 'info', text: `${event.title}:${event.message}`, ...links };
54
+ }
50
55
  if (event.attempt !== undefined && event.attempt > 1) {
51
- return { kind: 'info', text: `${event.title}(第 ${event.attempt} 次)` };
56
+ return { kind: 'info', text: `${event.title}(第 ${event.attempt} 次)`, ...links };
52
57
  }
53
- return { kind: 'start', text: event.title };
58
+ return { kind: 'start', text: event.title, ...links };
54
59
  }
55
60
  function targetOf(flow, input) {
56
61
  if (flow.target === undefined)
@@ -97,6 +102,7 @@ export function flowTaskDeps(actions, flowHost) {
97
102
  status: snapshot.status,
98
103
  step: snapshot.step,
99
104
  steps: snapshot.steps,
105
+ ...(snapshot.links === undefined ? {} : { links: snapshot.links }),
100
106
  intervention: snapshot.intervention,
101
107
  loginUrl: snapshot.loginUrl,
102
108
  why: snapshot.why,
@@ -1,5 +1,5 @@
1
1
  import type { DataCallOptions, PlanResults, RequestPlan } from '../../contract/data.js';
2
- import type { LongTaskIntervention } from '../../contract/long-task.js';
2
+ import type { LongTaskIntervention, LongTaskLink } from '../../contract/long-task.js';
3
3
  import type { ImageLike } from '../ai/types.js';
4
4
  import type { AiPort } from '../ai/port.js';
5
5
  /**
@@ -197,7 +197,7 @@ export interface FlowActionContext {
197
197
  readonly runId: string;
198
198
  readonly workspace: string;
199
199
  readonly stepId: string;
200
- log(text: string): void;
200
+ log(text: string, links?: readonly LongTaskLink[]): void;
201
201
  login(url: string): void;
202
202
  need(intervention: LongTaskIntervention): void;
203
203
  }
@@ -243,6 +243,7 @@ export interface FlowStepEvent {
243
243
  readonly message?: string | undefined;
244
244
  readonly loginUrl?: string | undefined;
245
245
  readonly intervention?: LongTaskIntervention | undefined;
246
+ readonly links?: readonly LongTaskLink[] | undefined;
246
247
  }
247
248
  /**
248
249
  * 开一条由外部推进的流程:引擎不执行任何步骤,只算条件、报当前步、等外部递结果。
@@ -1,4 +1,4 @@
1
- import { type LongTaskIntervention, type LongTaskStatus, type LongTaskStep } from '../../contract/long-task.js';
1
+ import { type LongTaskIntervention, type LongTaskLink, type LongTaskStatus, type LongTaskStep, type LongTaskStepRow } from '../../contract/long-task.js';
2
2
  export interface LongTaskBase {
3
3
  readonly id: string;
4
4
  readonly workspace: string;
@@ -7,6 +7,8 @@ export interface LongTaskBase {
7
7
  readonly status: LongTaskStatus;
8
8
  readonly step: string;
9
9
  readonly steps: readonly string[];
10
+ readonly history?: readonly LongTaskStepRow[] | undefined;
11
+ readonly links?: readonly LongTaskLink[] | undefined;
10
12
  readonly intervention?: LongTaskIntervention | undefined;
11
13
  readonly loginUrl?: string | undefined;
12
14
  readonly why?: string | undefined;
@@ -61,6 +63,16 @@ export interface LongTaskRegistry<S extends LongTaskBase> {
61
63
  onChange(listener: (change: LongTaskChange<S>) => void): () => void;
62
64
  rebind?(deps: LongTaskDeps<S>): void;
63
65
  }
66
+ /**
67
+ * 长任务行里那一层通用字段:去掉身份(`id` / `workspace`)之后的全套快照。
68
+ */
69
+ export type LongTaskRowBase = Omit<LongTaskBase, 'id' | 'workspace'>;
70
+ /**
71
+ * 长任务快照的通用字段:外壳先铺这一层,模块的 `view()` 只覆盖、不遗漏。
72
+ * @param snapshot 这一趟的快照。
73
+ * @returns `target` / `status` / `step` / `steps` / `startedAt` / `at` 与快照里存在的可选字段。
74
+ */
75
+ export declare function longTaskRowBase(snapshot: LongTaskBase): LongTaskRowBase;
64
76
  export declare function createLongTaskRegistry<S extends LongTaskBase>(deps: LongTaskDeps<S>): LongTaskRegistry<S>;
65
77
  /**
66
78
  * `withInterventionRetry` 的口径:最多试几次、每轮先等多久(也可按轮次算)、怎么等。