@dsh-workbench/shared 1.5.5 → 1.5.6
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/dist/api/dsh.d.ts +9 -1
- package/dist/components/card/ApprovalPlan.css +3 -0
- package/dist/components/card/ApprovalPlan.js +7 -2
- package/dist/components/card/LongTaskRow.css +32 -0
- package/dist/components/card/LongTaskRow.d.ts +8 -2
- package/dist/components/card/LongTaskRow.js +26 -5
- package/dist/components/card/board-module.d.ts +35 -4
- package/dist/components/card/use-text-marquee.d.ts +15 -0
- package/dist/components/card/use-text-marquee.js +66 -0
- package/dist/components/feedback/ProgressBar.css +56 -0
- package/dist/components/feedback/ProgressBar.d.ts +25 -0
- package/dist/components/feedback/ProgressBar.js +22 -0
- package/dist/config/constants.d.ts +2 -0
- package/dist/config/constants.js +2 -0
- package/dist/contract/guards.d.ts +1 -0
- package/dist/contract/guards.js +3 -0
- package/dist/contract/long-task.d.ts +56 -0
- package/dist/contract/long-task.js +41 -0
- package/dist/contract/protocol/long-tasks.d.ts +8 -2
- package/dist/contract/unit.d.ts +1 -0
- package/dist/host/diy/diy-preset.d.ts +1 -1
- package/dist/host/diy/diy-preset.js +3 -3
- package/dist/host/flow/create.d.ts +2 -1
- package/dist/host/flow/create.js +6 -0
- package/dist/host/flow/dsh-journal.d.ts +3 -0
- package/dist/host/flow/dsh-journal.js +55 -0
- package/dist/host/flow/journal.d.ts +20 -0
- package/dist/host/flow/journal.js +30 -0
- package/dist/host/flow/open.js +43 -26
- package/dist/host/flow/task.js +12 -1
- package/dist/host/flow/types.d.ts +5 -0
- package/dist/host/platform/integration/browser-launch.d.ts +1 -0
- package/dist/host/platform/integration/browser-launch.js +9 -2
- package/dist/host/profile/bundle-manager.js +4 -6
- package/dist/host/unit/long-task-host.d.ts +18 -0
- package/dist/host/unit/long-task-host.js +44 -0
- package/dist/host/unit/long-task-progress.d.ts +3 -0
- package/dist/host/unit/long-task-progress.js +32 -0
- package/dist/host/unit/long-task.d.ts +14 -38
- package/dist/host/unit/long-task.js +95 -94
- package/dist/host/unit/unit-face.d.ts +2 -1
- package/dist/host/unit/with-intervention-retry.d.ts +20 -0
- package/dist/host/unit/with-intervention-retry.js +45 -0
- package/dist/host.d.ts +30 -19
- package/dist/host.js +30 -19
- package/dist/i18n/en.js +33 -7
- package/dist/i18n/index.d.ts +33 -7
- package/dist/i18n/zh.d.ts +32 -6
- package/dist/i18n/zh.js +32 -6
- package/dist/index.d.ts +4 -2
- package/dist/index.js +4 -2
- package/package.json +2 -1
- package/src/api/dsh.ts +12 -1
- package/src/components/card/ApprovalPlan.css +3 -0
- package/src/components/card/ApprovalPlan.tsx +9 -2
- package/src/components/card/LongTaskRow.css +32 -0
- package/src/components/card/LongTaskRow.tsx +51 -4
- package/src/components/card/__tests__/ApprovalPlan.test.tsx +50 -0
- package/src/components/card/__tests__/long-task-row.test.ts +64 -2
- package/src/components/card/board-module.ts +36 -4
- package/src/components/card/use-text-marquee.ts +79 -0
- package/src/components/feedback/ProgressBar.css +56 -0
- package/src/components/feedback/ProgressBar.tsx +60 -0
- package/src/config/constants.ts +3 -0
- package/src/contract/__tests__/long-task.test.ts +43 -1
- package/src/contract/guards.ts +4 -0
- package/src/contract/long-task.ts +75 -0
- package/src/contract/protocol/long-tasks.ts +9 -1
- package/src/contract/unit.ts +1 -0
- package/src/host/diy/__tests__/diy-preset.test.ts +2 -0
- package/src/host/diy/diy-preset.ts +3 -2
- package/src/host/flow/__tests__/dsh-journal.test.ts +56 -0
- package/src/host/flow/__tests__/flow-create.test.ts +41 -1
- package/src/host/flow/__tests__/flow-open.test.ts +32 -0
- package/src/host/flow/create.ts +8 -5
- package/src/host/flow/dsh-journal.ts +74 -0
- package/src/host/flow/journal.ts +46 -0
- package/src/host/flow/open.ts +41 -26
- package/src/host/flow/task.ts +11 -1
- package/src/host/flow/types.ts +6 -0
- package/src/host/platform/integration/__tests__/browser-launch.test.ts +27 -0
- package/src/host/platform/integration/browser-launch.ts +15 -3
- package/src/host/profile/bundle-manager.ts +4 -7
- package/src/host/unit/__tests__/long-task.test.ts +203 -2
- package/src/host/unit/long-task-host.ts +64 -0
- package/src/host/unit/long-task-progress.ts +37 -0
- package/src/host/unit/long-task.ts +112 -126
- package/src/host/unit/unit-face.ts +2 -1
- package/src/host/unit/with-intervention-retry.ts +55 -0
- package/src/host.ts +31 -20
- package/src/i18n/en.ts +33 -7
- package/src/i18n/zh.ts +32 -6
- package/src/index.ts +4 -2
|
@@ -129,7 +129,7 @@ export function diyPresetSourcesOf(entries) {
|
|
|
129
129
|
const rows = [];
|
|
130
130
|
for (const config of configRowsOf(entries)) {
|
|
131
131
|
const id = config.id;
|
|
132
|
-
if (id === DIY_PRESET_ID || seen.has(id))
|
|
132
|
+
if (id === DIY_PRESET_ID || id === 'cordis' || seen.has(id))
|
|
133
133
|
continue;
|
|
134
134
|
seen.add(id);
|
|
135
135
|
rows.push({
|
|
@@ -152,7 +152,7 @@ export function diyPresetSourcesOf(entries) {
|
|
|
152
152
|
* @param skillsDir 工作台的 `skills/` 绝对路径。
|
|
153
153
|
* @param sourceId 来源模式的 id,报错时点名用。
|
|
154
154
|
*/
|
|
155
|
-
export function diyPresetFrom(source, skillsDir, sourceId = DIY_PRESET_SOURCE_DEFAULT) {
|
|
155
|
+
export function diyPresetFrom(source, skillsDir, sourceId = DIY_PRESET_SOURCE_DEFAULT, sourceName = sourceId) {
|
|
156
156
|
const plugins = clonedPluginsOf(sourceConfigOf(source, sourceId), sourceId);
|
|
157
157
|
const skillFilesystem = takeRow(plugins, 'skill-filesystem', sourceId);
|
|
158
158
|
const toolSkill = takeRow(plugins, 'tool-skill', sourceId);
|
|
@@ -179,7 +179,7 @@ export function diyPresetFrom(source, skillsDir, sourceId = DIY_PRESET_SOURCE_DE
|
|
|
179
179
|
return {
|
|
180
180
|
id: DIY_PRESET_ID,
|
|
181
181
|
name: DIY_PRESET_NAME,
|
|
182
|
-
description: DIY_PRESET_DESCRIPTION
|
|
182
|
+
description: `${DIY_PRESET_DESCRIPTION}(基于「${sourceName}」)`,
|
|
183
183
|
order: DIY_PRESET_ORDER,
|
|
184
184
|
plugins: plugins,
|
|
185
185
|
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { ToolDefinition, ToolRunContext } from '../../contract/module-context.js';
|
|
2
2
|
import type { FlowHost } from './kit.js';
|
|
3
3
|
import type { FlowActionRegistry, FlowDefinition } from './types.js';
|
|
4
|
-
import type { LongTaskBase,
|
|
4
|
+
import type { LongTaskBase, LongTaskRegistry } from '../unit/long-task.js';
|
|
5
|
+
import type { LongTaskHost } from '../unit/long-task-host.js';
|
|
5
6
|
/** 起一条流程任务:工作区必填,`input` 给流程,`session` 可选。 */
|
|
6
7
|
export interface FlowTaskStartOptions {
|
|
7
8
|
readonly workspace: string;
|
package/dist/host/flow/create.js
CHANGED
|
@@ -12,6 +12,12 @@ export function createFlowTask(options) {
|
|
|
12
12
|
}
|
|
13
13
|
const runs = options.longTasks.create({
|
|
14
14
|
key: options.key,
|
|
15
|
+
plan: {
|
|
16
|
+
steps: options.flow.steps.map((step) => ({
|
|
17
|
+
id: step.id,
|
|
18
|
+
...(step.title === undefined ? {} : { title: step.title }),
|
|
19
|
+
})),
|
|
20
|
+
},
|
|
15
21
|
...flowTaskDeps(options.actions, options.flowHost),
|
|
16
22
|
});
|
|
17
23
|
return {
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { appendPluginRecord } from '@deepseek-ai/dsh-session';
|
|
2
|
+
import { SESSION_PROJECTIONS_SERVICE, SESSION_STORE_SERVICE } from '../../config/constants.js';
|
|
3
|
+
import { DIY_FLOW_PROJECTION, DIY_FLOW_RECORD, parseDiyFlowSnapshot, } from './journal.js';
|
|
4
|
+
const snapshotSchema = {
|
|
5
|
+
parse: (value) => parseDiyFlowSnapshot(value),
|
|
6
|
+
};
|
|
7
|
+
export function createDshFlowJournal(ctx) {
|
|
8
|
+
const projections = ctx.get(SESSION_PROJECTIONS_SERVICE);
|
|
9
|
+
const sessions = ctx.get(SESSION_STORE_SERVICE);
|
|
10
|
+
if (projections === undefined || sessions === undefined) {
|
|
11
|
+
return { read: () => null, write: () => { } };
|
|
12
|
+
}
|
|
13
|
+
let handle;
|
|
14
|
+
void projections
|
|
15
|
+
.register({
|
|
16
|
+
key: DIY_FLOW_PROJECTION,
|
|
17
|
+
stateSchema: snapshotSchema,
|
|
18
|
+
init: () => null,
|
|
19
|
+
apply: (state, event) => {
|
|
20
|
+
if (event.type !== DIY_FLOW_RECORD)
|
|
21
|
+
return state;
|
|
22
|
+
const parsed = parseDiyFlowSnapshot(event.data);
|
|
23
|
+
return parsed ?? state;
|
|
24
|
+
},
|
|
25
|
+
stateVersion: 1,
|
|
26
|
+
})
|
|
27
|
+
.then((next) => {
|
|
28
|
+
handle = next;
|
|
29
|
+
})
|
|
30
|
+
.catch((error) => {
|
|
31
|
+
ctx.logger?.warn?.(`[dsh-workbench] 注册流程状态 projection 失败:${String(error)}`);
|
|
32
|
+
});
|
|
33
|
+
ctx.effect?.(() => () => {
|
|
34
|
+
const now = handle;
|
|
35
|
+
handle = undefined;
|
|
36
|
+
if (now !== undefined)
|
|
37
|
+
void now.dispose();
|
|
38
|
+
}, 'dsh-workbench: 流程状态 projection 随宿主卸载');
|
|
39
|
+
const sessionOf = (session) => sessions.get(session);
|
|
40
|
+
return {
|
|
41
|
+
read(session) {
|
|
42
|
+
const handleNow = handle;
|
|
43
|
+
const current = sessionOf(session);
|
|
44
|
+
if (handleNow === undefined || current === undefined)
|
|
45
|
+
return null;
|
|
46
|
+
return handleNow.stateOf(current);
|
|
47
|
+
},
|
|
48
|
+
write(session, snapshot) {
|
|
49
|
+
const current = sessionOf(session);
|
|
50
|
+
if (current === undefined)
|
|
51
|
+
return;
|
|
52
|
+
appendPluginRecord(current, DIY_FLOW_RECORD, snapshot);
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
export declare const DIY_FLOW_RECORD: "plugin:workbench/diy-flow";
|
|
2
|
+
export declare const DIY_FLOW_PROJECTION: "workbenchDiyFlow";
|
|
3
|
+
export interface DiyFlowSnapshot {
|
|
4
|
+
readonly version: 1;
|
|
5
|
+
readonly flow: string;
|
|
6
|
+
readonly input: Readonly<Record<string, unknown>>;
|
|
7
|
+
readonly step: string | null;
|
|
8
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
9
|
+
readonly status: 'running' | 'done' | 'stopped';
|
|
10
|
+
}
|
|
11
|
+
export interface DiyFlowJournal {
|
|
12
|
+
read(session: string): DiyFlowSnapshot | null;
|
|
13
|
+
write(session: string, snapshot: DiyFlowSnapshot): void;
|
|
14
|
+
}
|
|
15
|
+
export declare function parseDiyFlowSnapshot(value: unknown): DiyFlowSnapshot | null;
|
|
16
|
+
declare module '@deepseek-ai/dsh-session' {
|
|
17
|
+
interface PluginRecordMap {
|
|
18
|
+
'plugin:workbench/diy-flow': DiyFlowSnapshot;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export const DIY_FLOW_RECORD = 'plugin:workbench/diy-flow';
|
|
2
|
+
export const DIY_FLOW_PROJECTION = 'workbenchDiyFlow';
|
|
3
|
+
function isRecord(value) {
|
|
4
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
5
|
+
}
|
|
6
|
+
export function parseDiyFlowSnapshot(value) {
|
|
7
|
+
if (!isRecord(value))
|
|
8
|
+
return null;
|
|
9
|
+
if (value['version'] !== 1)
|
|
10
|
+
return null;
|
|
11
|
+
const flow = value['flow'];
|
|
12
|
+
const step = value['step'];
|
|
13
|
+
const status = value['status'];
|
|
14
|
+
if (typeof flow !== 'string' || flow === '')
|
|
15
|
+
return null;
|
|
16
|
+
if (step !== null && (typeof step !== 'string' || step === ''))
|
|
17
|
+
return null;
|
|
18
|
+
if (status !== 'running' && status !== 'done' && status !== 'stopped')
|
|
19
|
+
return null;
|
|
20
|
+
if (!isRecord(value['input']) || !isRecord(value['values']))
|
|
21
|
+
return null;
|
|
22
|
+
return {
|
|
23
|
+
version: 1,
|
|
24
|
+
flow,
|
|
25
|
+
input: value['input'],
|
|
26
|
+
step,
|
|
27
|
+
values: value['values'],
|
|
28
|
+
status,
|
|
29
|
+
};
|
|
30
|
+
}
|
package/dist/host/flow/open.js
CHANGED
|
@@ -2,7 +2,7 @@ import { evalPredicate } from './expr.js';
|
|
|
2
2
|
import { targetOf } from './run.js';
|
|
3
3
|
import { schemaProblem } from './schema.js';
|
|
4
4
|
export function openFlow(options) {
|
|
5
|
-
const steps = {};
|
|
5
|
+
const steps = { ...(options.resume?.values ?? {}) };
|
|
6
6
|
let current = null;
|
|
7
7
|
let schemaOfCurrent;
|
|
8
8
|
let pending = null;
|
|
@@ -21,35 +21,52 @@ export function openFlow(options) {
|
|
|
21
21
|
const wait = (stepId) => new Promise((resolve) => {
|
|
22
22
|
pending = { stepId, resolve };
|
|
23
23
|
});
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const title = step.title ?? step.id;
|
|
29
|
-
if (step.when !== undefined && !evalPredicate(step.when, { in: options.input, steps })) {
|
|
30
|
-
emit({ stepId: step.id, title, status: 'skipped' });
|
|
31
|
-
continue;
|
|
32
|
-
}
|
|
33
|
-
if (options.flow.stopWhen !== undefined &&
|
|
34
|
-
evalPredicate(options.flow.stopWhen, { in: options.input, steps })) {
|
|
35
|
-
break;
|
|
36
|
-
}
|
|
37
|
-
current = { index, stepId: step.id, title };
|
|
38
|
-
schemaOfCurrent = 'schema' in step ? step.schema : undefined;
|
|
39
|
-
emit({ stepId: step.id, title, status: 'running' });
|
|
40
|
-
const value = await wait(step.id);
|
|
41
|
-
pending = null;
|
|
42
|
-
if (stopped)
|
|
43
|
-
break;
|
|
44
|
-
steps[step.id] = value;
|
|
45
|
-
current = null;
|
|
46
|
-
}
|
|
24
|
+
const resumeIndex = options.resume === undefined
|
|
25
|
+
? 0
|
|
26
|
+
: options.flow.steps.findIndex((step) => step.id === options.resume?.stepId);
|
|
27
|
+
if (resumeIndex < 0) {
|
|
47
28
|
settle({
|
|
48
|
-
status:
|
|
29
|
+
status: 'failed',
|
|
49
30
|
target: targetOf(options.flow, { in: options.input, steps }),
|
|
50
31
|
steps,
|
|
32
|
+
failedStep: options.resume?.stepId,
|
|
33
|
+
error: `流程定义里没有步骤 ${String(options.resume?.stepId)}`,
|
|
51
34
|
});
|
|
52
|
-
}
|
|
35
|
+
}
|
|
36
|
+
else {
|
|
37
|
+
void (async () => {
|
|
38
|
+
for (let index = resumeIndex; index < options.flow.steps.length; index += 1) {
|
|
39
|
+
const step = options.flow.steps[index];
|
|
40
|
+
if (step === undefined)
|
|
41
|
+
continue;
|
|
42
|
+
if (stopped)
|
|
43
|
+
break;
|
|
44
|
+
const title = step.title ?? step.id;
|
|
45
|
+
if (step.when !== undefined && !evalPredicate(step.when, { in: options.input, steps })) {
|
|
46
|
+
emit({ stepId: step.id, title, status: 'skipped' });
|
|
47
|
+
continue;
|
|
48
|
+
}
|
|
49
|
+
if (options.flow.stopWhen !== undefined &&
|
|
50
|
+
evalPredicate(options.flow.stopWhen, { in: options.input, steps })) {
|
|
51
|
+
break;
|
|
52
|
+
}
|
|
53
|
+
current = { index, stepId: step.id, title };
|
|
54
|
+
schemaOfCurrent = 'schema' in step ? step.schema : undefined;
|
|
55
|
+
emit({ stepId: step.id, title, status: 'running' });
|
|
56
|
+
const value = await wait(step.id);
|
|
57
|
+
pending = null;
|
|
58
|
+
if (stopped)
|
|
59
|
+
break;
|
|
60
|
+
steps[step.id] = value;
|
|
61
|
+
current = null;
|
|
62
|
+
}
|
|
63
|
+
settle({
|
|
64
|
+
status: stopped ? 'stopped' : 'ok',
|
|
65
|
+
target: targetOf(options.flow, { in: options.input, steps }),
|
|
66
|
+
steps,
|
|
67
|
+
});
|
|
68
|
+
})();
|
|
69
|
+
}
|
|
53
70
|
return {
|
|
54
71
|
result,
|
|
55
72
|
current: () => current,
|
package/dist/host/flow/task.js
CHANGED
|
@@ -66,10 +66,17 @@ function targetOf(flow, input) {
|
|
|
66
66
|
/** 把流程跑成长任务:run / outcome / view / stopped 四条默认实现。 */
|
|
67
67
|
export function flowTaskDeps(actions, flowHost) {
|
|
68
68
|
return {
|
|
69
|
-
run: async ({ payload, onStep, signal }) => {
|
|
69
|
+
run: async ({ payload, onStep, onProgress, signal }) => {
|
|
70
70
|
const parsed = payloadOf(payload);
|
|
71
71
|
if (parsed === null)
|
|
72
72
|
throw new Error('流程 run 的 payload 不对');
|
|
73
|
+
const total = parsed.flow.steps.length;
|
|
74
|
+
const finished = new Set();
|
|
75
|
+
const report = () => {
|
|
76
|
+
if (total > 0)
|
|
77
|
+
onProgress({ done: finished.size, total });
|
|
78
|
+
};
|
|
79
|
+
report();
|
|
73
80
|
const runOptions = {
|
|
74
81
|
flow: parsed.flow,
|
|
75
82
|
input: parsed.input,
|
|
@@ -79,6 +86,10 @@ export function flowTaskDeps(actions, flowHost) {
|
|
|
79
86
|
workspace: parsed.workspace,
|
|
80
87
|
...(parsed.session === undefined ? {} : { sessionId: parsed.session }),
|
|
81
88
|
onStep: (event) => {
|
|
89
|
+
if (event.status === 'ok' || event.status === 'skipped') {
|
|
90
|
+
finished.add(event.stepId);
|
|
91
|
+
report();
|
|
92
|
+
}
|
|
82
93
|
onStep(longStepOf(event));
|
|
83
94
|
},
|
|
84
95
|
};
|
|
@@ -248,10 +248,15 @@ export interface FlowStepEvent {
|
|
|
248
248
|
/**
|
|
249
249
|
* 开一条由外部推进的流程:引擎不执行任何步骤,只算条件、报当前步、等外部递结果。
|
|
250
250
|
*/
|
|
251
|
+
export interface FlowResume {
|
|
252
|
+
readonly stepId: string;
|
|
253
|
+
readonly values: Readonly<Record<string, unknown>>;
|
|
254
|
+
}
|
|
251
255
|
export interface FlowOpenOptions {
|
|
252
256
|
readonly flow: FlowDefinition;
|
|
253
257
|
readonly input: unknown;
|
|
254
258
|
readonly onStep: (event: FlowStepEvent) => void;
|
|
259
|
+
readonly resume?: FlowResume | undefined;
|
|
255
260
|
readonly now?: (() => number) | undefined;
|
|
256
261
|
}
|
|
257
262
|
/** 现在停在哪一步:位置、步骤标识与人看的标题。 */
|
|
@@ -8,6 +8,7 @@ export declare function browserLaunchOf(id: DesktopBrowserId, platform: HostOs,
|
|
|
8
8
|
readonly appPath: string;
|
|
9
9
|
readonly executable: string | undefined;
|
|
10
10
|
readonly linuxBinary: string;
|
|
11
|
+
readonly url?: string;
|
|
11
12
|
}): BrowserLaunchSpec | undefined;
|
|
12
13
|
export declare function browserWakeSupportedOf(platform: HostOs): boolean;
|
|
13
14
|
export declare function browserExecutableOf(id: DesktopBrowserId, platform: HostOs, options: {
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { quoteShellArgFor } from '../ops/shell.js';
|
|
2
2
|
import { browserInstallCandidates } from './browsers.js';
|
|
3
3
|
export function browserLaunchOf(id, platform, target) {
|
|
4
|
+
const page = target.url === undefined ? '' : ` ${quoteShellArgFor(target.url, platform)}`;
|
|
4
5
|
if (platform === 'darwin') {
|
|
5
|
-
return { command: `open -g -j -a ${quoteShellArgFor(target.appPath, 'darwin')}` };
|
|
6
|
+
return { command: `open -g -j -a ${quoteShellArgFor(target.appPath, 'darwin')}${page}` };
|
|
6
7
|
}
|
|
7
8
|
if (platform === 'linux') {
|
|
9
|
+
if (target.url !== undefined) {
|
|
10
|
+
return {
|
|
11
|
+
probe: `command -v ${quoteShellArgFor('setsid', 'linux')}`,
|
|
12
|
+
command: `setsid ${quoteShellArgFor(target.linuxBinary, 'linux')} ${quoteShellArgFor(target.url, 'linux')} >/dev/null 2>&1 < /dev/null &`,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
8
15
|
return {
|
|
9
16
|
probe: `command -v ${quoteShellArgFor('setsid', 'linux')}`,
|
|
10
17
|
command: `setsid ${quoteShellArgFor(target.linuxBinary, 'linux')} --no-startup-window >/dev/null 2>&1 < /dev/null &`,
|
|
@@ -13,7 +20,7 @@ export function browserLaunchOf(id, platform, target) {
|
|
|
13
20
|
if (platform === 'win32') {
|
|
14
21
|
if (target.executable === undefined)
|
|
15
22
|
return undefined;
|
|
16
|
-
return { command: `cmd /d /s /c start "" ${quoteShellArgFor(target.executable, 'win32')}` };
|
|
23
|
+
return { command: `cmd /d /s /c start "" ${quoteShellArgFor(target.executable, 'win32')}${page}` };
|
|
17
24
|
}
|
|
18
25
|
return undefined;
|
|
19
26
|
}
|
|
@@ -2,6 +2,7 @@ import { profileDirOf } from '../supply/installed-module.js';
|
|
|
2
2
|
import { generationDirOf } from '../supply/module-root.js';
|
|
3
3
|
import { reconcileWorkbenchLinks } from '../supply/workbench-links.js';
|
|
4
4
|
import { RESTART_REASONS } from '../../contract/protocol/bundle-install.js';
|
|
5
|
+
import { texts } from '../../contract/guards.js';
|
|
5
6
|
export const PLUGIN_MANAGER_SERVICE = 'pluginManager';
|
|
6
7
|
const APPLICATIONS = ['applied', 'restart-required', 'overridden', 'failed', 'cancelled'];
|
|
7
8
|
const STAGES = ['install', 'enable', 'remove'];
|
|
@@ -43,9 +44,6 @@ function asRegistry(value) {
|
|
|
43
44
|
return null;
|
|
44
45
|
return typeof value === 'string' ? value : undefined;
|
|
45
46
|
}
|
|
46
|
-
function asTextArray(value) {
|
|
47
|
-
return Array.isArray(value) ? value.filter((item) => typeof item === 'string') : [];
|
|
48
|
-
}
|
|
49
47
|
function asRegistries(raw) {
|
|
50
48
|
const record = asRecord(raw);
|
|
51
49
|
if (record === undefined)
|
|
@@ -55,7 +53,7 @@ function asRegistries(raw) {
|
|
|
55
53
|
return null;
|
|
56
54
|
return {
|
|
57
55
|
registry,
|
|
58
|
-
fallbackRegistries:
|
|
56
|
+
fallbackRegistries: texts(record.fallbackRegistries),
|
|
59
57
|
resolved: typeof record.resolved === 'string' ? record.resolved : null,
|
|
60
58
|
};
|
|
61
59
|
}
|
|
@@ -82,7 +80,7 @@ function asChange(raw) {
|
|
|
82
80
|
return null;
|
|
83
81
|
const error = asRecord(record.error);
|
|
84
82
|
const packageResult = asPackageResult(record.packageResult);
|
|
85
|
-
const pendingBuilds =
|
|
83
|
+
const pendingBuilds = texts(record.pendingBuilds);
|
|
86
84
|
const restartReason = pick(RESTART_REASONS, record.restartReason);
|
|
87
85
|
const failedAt = pick(['registry', 'spec-host'], record.failedAt);
|
|
88
86
|
const bundle = asText(record.bundle);
|
|
@@ -217,7 +215,7 @@ function asVersionEntry(raw) {
|
|
|
217
215
|
const incompatible = asIncompatible(record.incompatible);
|
|
218
216
|
return {
|
|
219
217
|
version,
|
|
220
|
-
tags:
|
|
218
|
+
tags: texts(record.tags),
|
|
221
219
|
prerelease: record.prerelease === true,
|
|
222
220
|
bundle: record.bundle === true,
|
|
223
221
|
...(publishedAt === '' ? {} : { publishedAt }),
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { type LongTaskBase, type LongTaskChange, type LongTaskDeps, type LongTaskRegistry } from './long-task.js';
|
|
2
|
+
export declare function sharedLongTaskRegistry<S extends LongTaskBase>(scope: string, key: string, deps: LongTaskDeps<S>): LongTaskRegistry<S>;
|
|
3
|
+
/** 一个单元的长任务入口:按 key 建注册表。 */
|
|
4
|
+
export interface LongTaskHost {
|
|
5
|
+
/** key 是模块内稳定的标识;run / view 必给,recheck / answer 决定行上有没有恢复与回执。 */
|
|
6
|
+
create<S extends LongTaskBase>(options: {
|
|
7
|
+
readonly key: string;
|
|
8
|
+
} & LongTaskDeps<S>): LongTaskRegistry<S>;
|
|
9
|
+
}
|
|
10
|
+
export declare function createLongTaskHost(options: {
|
|
11
|
+
readonly scope: string;
|
|
12
|
+
readonly unit: string;
|
|
13
|
+
readonly bump: (facts: readonly string[]) => void;
|
|
14
|
+
readonly notify?: ((change: LongTaskChange<LongTaskBase>) => void) | undefined;
|
|
15
|
+
}): {
|
|
16
|
+
readonly host: LongTaskHost;
|
|
17
|
+
dispose(): void;
|
|
18
|
+
};
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { runsRouteOf } from '../../contract/long-task.js';
|
|
2
|
+
import { createLongTaskRegistry } from './long-task.js';
|
|
3
|
+
function isRegistry(value) {
|
|
4
|
+
if (typeof value !== 'object' || value === null)
|
|
5
|
+
return false;
|
|
6
|
+
const candidate = value;
|
|
7
|
+
return (typeof candidate.start === 'function' &&
|
|
8
|
+
typeof candidate.current === 'function' &&
|
|
9
|
+
typeof candidate.snapshot === 'function' &&
|
|
10
|
+
typeof candidate.onChange === 'function');
|
|
11
|
+
}
|
|
12
|
+
export function sharedLongTaskRegistry(scope, key, deps) {
|
|
13
|
+
const store = globalThis;
|
|
14
|
+
const slot = Symbol.for(`dsh-workbench:long-task:${scope}:${key}`);
|
|
15
|
+
const existing = store[slot];
|
|
16
|
+
if (existing !== undefined && isRegistry(existing)) {
|
|
17
|
+
existing.rebind?.(deps);
|
|
18
|
+
return existing;
|
|
19
|
+
}
|
|
20
|
+
const created = createLongTaskRegistry(deps);
|
|
21
|
+
store[slot] = created;
|
|
22
|
+
return created;
|
|
23
|
+
}
|
|
24
|
+
export function createLongTaskHost(options) {
|
|
25
|
+
const offs = [];
|
|
26
|
+
return {
|
|
27
|
+
host: {
|
|
28
|
+
create(createOptions) {
|
|
29
|
+
const { key, facts, ...deps } = createOptions;
|
|
30
|
+
const registry = sharedLongTaskRegistry(options.scope, `${options.unit}:${key}`, deps);
|
|
31
|
+
offs.push(registry.onChange((change) => {
|
|
32
|
+
const named = [runsRouteOf(options.unit), ...(facts?.(change) ?? [])];
|
|
33
|
+
options.bump([...new Set(named)]);
|
|
34
|
+
options.notify?.(change);
|
|
35
|
+
}));
|
|
36
|
+
return registry;
|
|
37
|
+
},
|
|
38
|
+
},
|
|
39
|
+
dispose() {
|
|
40
|
+
for (const off of offs.splice(0))
|
|
41
|
+
off();
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { type LongTaskPlanStep, type LongTaskProgress, type LongTaskStepRow } from '../../contract/long-task.js';
|
|
2
|
+
export declare function nextLongTaskProgress(next: LongTaskProgress, current: LongTaskProgress | undefined): LongTaskProgress | null;
|
|
3
|
+
export declare function derivedLongTaskProgress(history: readonly LongTaskStepRow[], total: number, plan: readonly LongTaskPlanStep[]): LongTaskProgress | undefined;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { longTaskProgressIsValid, } from '../../contract/long-task.js';
|
|
2
|
+
export function nextLongTaskProgress(next, current) {
|
|
3
|
+
if (!longTaskProgressIsValid(next))
|
|
4
|
+
return null;
|
|
5
|
+
if (current === undefined)
|
|
6
|
+
return { done: next.done, total: next.total };
|
|
7
|
+
if (current.total !== next.total)
|
|
8
|
+
return { done: next.done, total: next.total };
|
|
9
|
+
if (next.done < current.done)
|
|
10
|
+
return current;
|
|
11
|
+
return { done: next.done, total: next.total };
|
|
12
|
+
}
|
|
13
|
+
export function derivedLongTaskProgress(history, total, plan) {
|
|
14
|
+
if (total <= 0)
|
|
15
|
+
return undefined;
|
|
16
|
+
const wanted = new Set(plan.map((step) => step.id));
|
|
17
|
+
const done = new Set();
|
|
18
|
+
for (const row of history) {
|
|
19
|
+
if (row.stepId === undefined)
|
|
20
|
+
continue;
|
|
21
|
+
if (wanted.size === 0) {
|
|
22
|
+
if (row.kind === 'succeed')
|
|
23
|
+
done.add(row.stepId);
|
|
24
|
+
continue;
|
|
25
|
+
}
|
|
26
|
+
if (row.kind !== 'succeed' && row.kind !== 'info')
|
|
27
|
+
continue;
|
|
28
|
+
if (wanted.has(row.stepId))
|
|
29
|
+
done.add(row.stepId);
|
|
30
|
+
}
|
|
31
|
+
return { done: Math.min(done.size, total), total };
|
|
32
|
+
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type LongTaskIntervention, type LongTaskLink, type LongTaskStatus, type LongTaskStep, type LongTaskStepRow } from '../../contract/long-task.js';
|
|
1
|
+
import { type LongTaskIntervention, type LongTaskLink, type LongTaskPlan, type LongTaskPlanStep, type LongTaskProgress, 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;
|
|
@@ -15,6 +15,9 @@ export interface LongTaskBase {
|
|
|
15
15
|
readonly startedAt: string;
|
|
16
16
|
readonly at: string;
|
|
17
17
|
readonly session?: string | undefined;
|
|
18
|
+
readonly seen?: boolean | undefined;
|
|
19
|
+
readonly progress?: LongTaskProgress | undefined;
|
|
20
|
+
readonly plan?: readonly LongTaskPlanStep[] | undefined;
|
|
18
21
|
}
|
|
19
22
|
export interface LongTaskStart {
|
|
20
23
|
readonly workspace: string;
|
|
@@ -23,17 +26,20 @@ export interface LongTaskStart {
|
|
|
23
26
|
readonly session?: string | undefined;
|
|
24
27
|
}
|
|
25
28
|
export interface LongTaskChange<S extends LongTaskBase> {
|
|
26
|
-
readonly kind: 'start' | 'step' | 'settle';
|
|
29
|
+
readonly kind: 'start' | 'step' | 'progress' | 'settle' | 'seen';
|
|
27
30
|
readonly snapshot: S;
|
|
28
31
|
readonly step?: LongTaskStep | undefined;
|
|
29
32
|
readonly by?: string | undefined;
|
|
30
33
|
}
|
|
31
34
|
/** 长任务怎么跑、怎么投影成面板那一行。 */
|
|
32
35
|
export interface LongTaskDeps<S extends LongTaskBase> {
|
|
33
|
-
/**
|
|
36
|
+
/** 这一趟打算走几步;给了就有进度条(外壳从步骤事件自己数),没给就不画。 */
|
|
37
|
+
readonly plan?: LongTaskPlan | undefined;
|
|
38
|
+
/** 真正执行任务:payload 来自 start,onStep 报步骤,onProgress 报走到哪了,signal 被 abort 时尽快退出。 */
|
|
34
39
|
readonly run: (options: {
|
|
35
40
|
readonly payload: unknown;
|
|
36
41
|
readonly onStep: (step: LongTaskStep) => void;
|
|
42
|
+
readonly onProgress: (progress: LongTaskProgress) => void;
|
|
37
43
|
readonly signal: AbortSignal;
|
|
38
44
|
}) => Promise<unknown>;
|
|
39
45
|
readonly step?: ((step: LongTaskStep, current: S) => Partial<S>) | undefined;
|
|
@@ -69,8 +75,12 @@ export interface LongTaskRegistry<S extends LongTaskBase> {
|
|
|
69
75
|
current(workspace: string): readonly Readonly<Record<string, unknown>>[];
|
|
70
76
|
/** 现在活着的每一趟,不分工作区 / 目标;给侧栏状态点用。 */
|
|
71
77
|
live(): readonly S[];
|
|
78
|
+
/** 现在活着的,加上最近 `recentMs` 内刚收尾的每一趟;给左栏那张全局长任务列表用。 */
|
|
79
|
+
recent(): readonly S[];
|
|
72
80
|
/** 请求停止:把中断信号转给生产方;没有这趟或已经结束回 false。 */
|
|
73
81
|
stop(id: string, by?: string): boolean;
|
|
82
|
+
/** 把已收尾的一趟标成「看过」;活着 / 不认识回 false。不刷新 `at`。 */
|
|
83
|
+
seen(id: string): boolean;
|
|
74
84
|
recheck(id: string): boolean;
|
|
75
85
|
/** 交回执:只认 intervention.fields 里的 key,必填缺失回 false。 */
|
|
76
86
|
answer(id: string, values: Readonly<Record<string, string>>): boolean;
|
|
@@ -88,38 +98,4 @@ export type LongTaskRowBase = Omit<LongTaskBase, 'id' | 'workspace'>;
|
|
|
88
98
|
*/
|
|
89
99
|
export declare function longTaskRowBase(snapshot: LongTaskBase): LongTaskRowBase;
|
|
90
100
|
export declare function createLongTaskRegistry<S extends LongTaskBase>(deps: LongTaskDeps<S>): LongTaskRegistry<S>;
|
|
91
|
-
|
|
92
|
-
* `withInterventionRetry` 的口径:最多试几次、每轮先等多久(也可按轮次算)、怎么等。
|
|
93
|
-
*/
|
|
94
|
-
export interface InterventionRetryOptions {
|
|
95
|
-
readonly attempts?: number | undefined;
|
|
96
|
-
readonly delayMs?: number | ((attempt: number) => number) | undefined;
|
|
97
|
-
readonly sleep?: ((ms: number) => Promise<void>) | undefined;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* 把「看一眼接上没有」包成能交给 `longTasks.create({ recheck })` 的 handler:
|
|
101
|
-
* 用户在人工干预节点上按「我处理完了」时先立刻试一次,没接上就有界地再试(第 2 轮起每轮先等)。
|
|
102
|
-
* `check` 返回 true = 已经接上,不用再试;抛错算没接上、继续下一轮。
|
|
103
|
-
* 同一 id 上一轮还在飞时再按直接忽略;成功 / 用尽都清单飞;**永不抛错**(fire-and-forget)。
|
|
104
|
-
* @param check 看一眼接上没有,可同步可异步。
|
|
105
|
-
* @param options 轮次上限(默认 5)、第几次等待等多久(默认 1500ms,可给函数,从第 1 次等待起算)、怎么等(默认真等,测试可注入假的)。
|
|
106
|
-
* @returns 一条同签名的 handler,直接交给 `const longTasks = create({ recheck })`。
|
|
107
|
-
*/
|
|
108
|
-
export declare function withInterventionRetry<S extends LongTaskBase>(check: (current: S) => boolean | Promise<boolean>, options?: InterventionRetryOptions): (current: S) => void;
|
|
109
|
-
export declare function sharedLongTaskRegistry<S extends LongTaskBase>(scope: string, key: string, deps: LongTaskDeps<S>): LongTaskRegistry<S>;
|
|
110
|
-
/** 一个单元的长任务入口:按 key 建注册表。 */
|
|
111
|
-
export interface LongTaskHost {
|
|
112
|
-
/** key 是模块内稳定的标识;run / view 必给,recheck / answer 决定行上有没有恢复与回执。 */
|
|
113
|
-
create<S extends LongTaskBase>(options: {
|
|
114
|
-
readonly key: string;
|
|
115
|
-
} & LongTaskDeps<S>): LongTaskRegistry<S>;
|
|
116
|
-
}
|
|
117
|
-
export declare function createLongTaskHost(options: {
|
|
118
|
-
readonly scope: string;
|
|
119
|
-
readonly unit: string;
|
|
120
|
-
readonly bump: (facts: readonly string[]) => void;
|
|
121
|
-
readonly notify?: ((change: LongTaskChange<LongTaskBase>) => void) | undefined;
|
|
122
|
-
}): {
|
|
123
|
-
readonly host: LongTaskHost;
|
|
124
|
-
dispose(): void;
|
|
125
|
-
};
|
|
101
|
+
export { withInterventionRetry, type InterventionRetryOptions } from './with-intervention-retry.js';
|