@deepseek-ai/dsh-workflow 0.0.1-rc.1 → 0.0.1-rc.5
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/README.i18n.yaml +2 -2
- package/README.md +6 -4
- package/README.zh.md +10 -8
- package/lib/index.js +3 -3
- package/lib/types/index.d.ts +8 -6
- package/lib/types/index.js +80 -0
- package/lib/types/invariant.js +118 -0
- package/lib/types/runtime-types.d.ts +45 -0
- package/lib/types/runtime-types.js +9 -0
- package/lib/types/types.d.ts +2 -50
- package/lib/types/types.js +16 -0
- package/package.json +19 -14
package/README.i18n.yaml
CHANGED
|
@@ -2,5 +2,5 @@
|
|
|
2
2
|
# side as of the last confirmed-consistent state. Both languages carry equal authority;
|
|
3
3
|
# after editing either side, bring the other along and re-record with:
|
|
4
4
|
# pnpm run verify-translation-pairing --write packages/workflow/workflow/README.md
|
|
5
|
-
README.md:
|
|
6
|
-
README.zh.md:
|
|
5
|
+
README.md: cc2c24f62512273ea1657542d0d904b0b870e236
|
|
6
|
+
README.zh.md: 22bda1bd33bc6350c8ff51f27538258bee872fdb
|
package/README.md
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
English | [中文](README.zh.md)
|
|
4
4
|
|
|
5
|
-
The workflow seam (`ctx.
|
|
5
|
+
The workflow seam (`ctx.workflowEngine`) executes a model-written orchestration script that can fan out subagents. The seam defines the script, run, result, error, and event contracts; an engine decides how to isolate and execute the script.
|
|
6
6
|
|
|
7
|
-
`@deepseek-ai/dsh-workflow-
|
|
7
|
+
`@deepseek-ai/dsh-workflow-worker-thread` is the current engine and `@deepseek-ai/dsh-tool-workflow` is the model-facing consumer. A future process or sandbox engine can replace the implementation without changing the tool.
|
|
8
|
+
|
|
9
|
+
The package root is the Host face. The browser-safe `@deepseek-ai/dsh-workflow/types` subpath contains run identities, metadata, results, and observe-only lifecycle payloads without importing `Agent`, Cordis services, or Host context declarations; Host-only `WorkflowStartRequest` and `WorkflowRun` live behind the package root.
|
|
8
10
|
|
|
9
11
|
## Service and run contract
|
|
10
12
|
|
|
11
|
-
`
|
|
13
|
+
`WorkflowEngine.start(request): WorkflowRun` validates enough synchronously to reject a malformed meta block, unparseable script, unavailable provider route, or unsupported per-run limit before a run exists. Once returned, `WorkflowRun.result` never rejects: execution failures resolve with `stopReason: 'error'`, and cancellation resolves with `cancelled` within the engine's bounded grace.
|
|
12
14
|
|
|
13
15
|
A run is holder-owned. Engine-plugin unload prevents new starts but does not revoke accepted runs. The holder must call `dispose()` on every path; disposal cancels remaining work and reaches or abandons quiescence within the documented bound.
|
|
14
16
|
|
|
@@ -56,4 +58,4 @@ No direct invalidation; the named consumer owns any request-prefix changes.
|
|
|
56
58
|
- **No token-budget vocabulary** — engines cap concurrency, items, and children, but neither the request nor result accounts for model tokens across children.
|
|
57
59
|
- **Runs are holder-owned, not service-tracked** — unloading the engine does not discover independent live handles; every consumer must dispose the run it started.
|
|
58
60
|
|
|
59
|
-
See the [dynamic-workflows Agent Note](../../../.agents/notes/implemented/feature/2026-07-05-dynamic-workflows.md) for the deferred workflow
|
|
61
|
+
See the [dynamic-workflows Agent Note](../../../.agents/notes/implemented/feature/2026-07-05-dynamic-workflows.md) for the deferred workflow API.
|
package/README.zh.md
CHANGED
|
@@ -2,13 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
[English](README.md) | 中文
|
|
4
4
|
|
|
5
|
-
工作流 seam
|
|
5
|
+
工作流 seam(扩展点,`ctx.workflowEngine`)执行由模型编写、可扇出 subagent 的编排脚本。该 seam 定义脚本、运行、结果、错误和事件契约;引擎负责决定如何隔离并执行脚本。
|
|
6
6
|
|
|
7
|
-
`@deepseek-ai/dsh-workflow-
|
|
7
|
+
`@deepseek-ai/dsh-workflow-worker-thread` 是当前引擎,`@deepseek-ai/dsh-tool-workflow` 是面向模型的消费方。未来的进程或沙箱引擎可以替换实现,而无需更改工具。
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
包根是 Host face。浏览器安全的 `@deepseek-ai/dsh-workflow/types` 子路径包含运行身份、元数据、结果和仅供观察的生命周期 payload,不导入 `Agent`、Cordis service 或 Host Context 声明;Host 专用的 `WorkflowStartRequest` 与 `WorkflowRun` 只从包根提供。
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## 服务与运行契约
|
|
12
|
+
|
|
13
|
+
`WorkflowEngine.start(request): WorkflowRun` 会同步完成足够多的校验,在运行创建前拒绝格式错误的 meta 块、无法解析的脚本、不可用的提供方路由或不受支持的单次运行限制。返回后,`WorkflowRun.result` 绝不拒绝:执行失败以 `stopReason: 'error'` 兑现,取消则在引擎有限的宽限时间内以 `cancelled` 兑现。
|
|
12
14
|
|
|
13
15
|
运行由持有方负责。引擎插件卸载会阻止新的启动,但不会撤销已接受的运行。持有方必须在每条路径上调用 `dispose()`;dispose(资源释放)会取消剩余工作,并在文档规定的期限内达到或放弃完全停稳。
|
|
14
16
|
|
|
@@ -24,19 +26,19 @@
|
|
|
24
26
|
- `workflow/phase` 和 `workflow/log` 公开脚本叙述;
|
|
25
27
|
- `workflow/agent-start` / `workflow/agent-end` 按 `seq` 为每次子 agent 调用配对;提供方的异步启动调用被拒绝时,该子 agent 不会发出其中任何一个事件。
|
|
26
28
|
|
|
27
|
-
同进程事件 payload
|
|
29
|
+
同进程事件 payload 是以不可变方式借用的值。每个监听器都独立隔离:同步抛出异常或返回的 promise 被拒绝时,只会记录日志,不会阻塞同级监听器或改变执行。
|
|
28
30
|
|
|
29
31
|
## 失败纪律
|
|
30
32
|
|
|
31
33
|
`WorkflowError` 携带一个代码和 `fatal` 标志。致命错误总会逸出 `parallel()` 和 `pipeline()`,而不会变成普通的逐项 `null`:
|
|
32
34
|
|
|
33
35
|
- `SCRIPT_PARSE` / `META_INVALID`:工作流无法启动;
|
|
34
|
-
- `INVALID_ARGUMENT` / `UNSUPPORTED_OPTION` / `UNSUPPORTED_SCHEMA
|
|
36
|
+
- `INVALID_ARGUMENT` / `UNSUPPORTED_OPTION` / `UNSUPPORTED_SCHEMA`:钩子调用违反引擎契约;
|
|
35
37
|
- `AGENT_CAP` / `ITEM_CAP`:超过已配置的安全上限;
|
|
36
38
|
- `AGENT_START`:提供方的异步启动调用被拒绝;
|
|
37
39
|
- `AGENT_RESULT`:已发布子 agent 的结果因基础设施故障而被拒绝;
|
|
38
40
|
- `RESULT_UNSERIALIZABLE`:脚本/worker 值不是普通 JSON 数据;
|
|
39
|
-
- `CANCELLED
|
|
41
|
+
- `CANCELLED`:取消会接管该运行,待处理和未来的钩子都会拒绝。
|
|
40
42
|
|
|
41
43
|
子 agent 若以非完成的结束原因正常兑现,并不属于基础设施异常:`agent()` 返回 `null`,使脚本可以处理普通的子 agent 失败。
|
|
42
44
|
|
|
@@ -56,4 +58,4 @@
|
|
|
56
58
|
- **没有 token 预算词汇**:引擎会限制并发、条目和子 agent,但请求与结果都不会统计跨子 agent 的模型 token。
|
|
57
59
|
- **运行由持有方负责,不由服务跟踪**:卸载引擎不会发现独立的活动句柄;每个消费方都必须 dispose 自己启动的运行。
|
|
58
60
|
|
|
59
|
-
暂缓实现的工作流接口见[动态工作流 Agent Note](../../../.agents/notes/implemented/feature/2026-07-05-dynamic-workflows.md)。
|
|
61
|
+
暂缓实现的工作流接口见[动态工作流 Agent Note(agent 决策记录)](../../../.agents/notes/implemented/feature/2026-07-05-dynamic-workflows.md)。
|
package/lib/index.js
CHANGED
|
@@ -56,9 +56,9 @@ function isFatalWorkflowError(error) {
|
|
|
56
56
|
* listener failures are contained, and `workflow/end` fires exactly once as the
|
|
57
57
|
* result settles.
|
|
58
58
|
*/
|
|
59
|
-
var
|
|
59
|
+
var WorkflowEngine = class extends Service {
|
|
60
60
|
constructor(ctx) {
|
|
61
|
-
super(ctx, "
|
|
61
|
+
super(ctx, "workflowEngine");
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Emit a lifecycle event while containing and logging each listener failure.
|
|
@@ -89,4 +89,4 @@ function renderListenerError(error) {
|
|
|
89
89
|
}
|
|
90
90
|
}
|
|
91
91
|
//#endregion
|
|
92
|
-
export {
|
|
92
|
+
export { WorkflowEngine, WorkflowEngine as default, WorkflowError, WorkflowRunId, isFatalWorkflowError };
|
package/lib/types/index.d.ts
CHANGED
|
@@ -5,12 +5,14 @@
|
|
|
5
5
|
*/
|
|
6
6
|
import { Context, Service } from '@deepseek-ai/cordis';
|
|
7
7
|
import { HarnessError } from '@deepseek-ai/dsh-llm';
|
|
8
|
-
import type { WorkflowAgentEndInfo, WorkflowAgentInfo, WorkflowResultInfo,
|
|
8
|
+
import type { WorkflowAgentEndInfo, WorkflowAgentInfo, WorkflowResultInfo, WorkflowRunInfo } from './types.ts';
|
|
9
|
+
import type { WorkflowRun, WorkflowStartRequest } from './runtime-types.ts';
|
|
9
10
|
export { WorkflowRunId } from './types.ts';
|
|
10
|
-
export type { WorkflowAgentEndInfo, WorkflowAgentInfo, WorkflowAgentOutcome, WorkflowMeta, WorkflowPhase, WorkflowResult, WorkflowResultInfo,
|
|
11
|
+
export type { WorkflowAgentEndInfo, WorkflowAgentInfo, WorkflowAgentOutcome, WorkflowMeta, WorkflowPhase, WorkflowResult, WorkflowResultInfo, WorkflowRunInfo, WorkflowStopReason, } from './types.ts';
|
|
12
|
+
export type { WorkflowRun, WorkflowStartRequest } from './runtime-types.ts';
|
|
11
13
|
declare module '@deepseek-ai/cordis' {
|
|
12
14
|
interface Context {
|
|
13
|
-
|
|
15
|
+
workflowEngine: WorkflowEngine;
|
|
14
16
|
}
|
|
15
17
|
interface Events {
|
|
16
18
|
/**
|
|
@@ -68,7 +70,7 @@ declare module '@deepseek-ai/cordis' {
|
|
|
68
70
|
'workflow/end'(info: WorkflowRunInfo, result: WorkflowResultInfo): void;
|
|
69
71
|
}
|
|
70
72
|
}
|
|
71
|
-
/** The full set of `workflow/*` event names {@link
|
|
73
|
+
/** The full set of `workflow/*` event names {@link WorkflowEngine.emitWorkflowEvent} dispatches. */
|
|
72
74
|
export type WorkflowEventName = 'workflow/start' | 'workflow/phase' | 'workflow/log' | 'workflow/agent-start' | 'workflow/agent-end' | 'workflow/end';
|
|
73
75
|
/**
|
|
74
76
|
* Machine-routable fatal workflow failures: parse/meta/argument/schema errors,
|
|
@@ -106,7 +108,7 @@ export declare function isFatalWorkflowError(error: unknown): boolean;
|
|
|
106
108
|
* listener failures are contained, and `workflow/end` fires exactly once as the
|
|
107
109
|
* result settles.
|
|
108
110
|
*/
|
|
109
|
-
export declare abstract class
|
|
111
|
+
export declare abstract class WorkflowEngine extends Service {
|
|
110
112
|
constructor(ctx: Context);
|
|
111
113
|
/**
|
|
112
114
|
* Parse and execute a workflow script.
|
|
@@ -122,5 +124,5 @@ export declare abstract class WorkflowService extends Service {
|
|
|
122
124
|
*/
|
|
123
125
|
protected emitWorkflowEvent(name: WorkflowEventName, ...args: unknown[]): void;
|
|
124
126
|
}
|
|
125
|
-
export default
|
|
127
|
+
export default WorkflowEngine;
|
|
126
128
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Service Definition for the workflow capability seam. Service providers execute orchestration scripts;
|
|
3
|
+
* observe-only lifecycle events never expose run control.
|
|
4
|
+
* @module @deepseek-ai/dsh-workflow
|
|
5
|
+
*/
|
|
6
|
+
import { Service } from '@deepseek-ai/cordis';
|
|
7
|
+
import { HarnessError } from '@deepseek-ai/dsh-llm';
|
|
8
|
+
export { WorkflowRunId } from "./types.js";
|
|
9
|
+
/**
|
|
10
|
+
* Typed error for workflow-seam failures. Extends {@link HarnessError}, so the
|
|
11
|
+
* `code` is machine-routable taxonomy. `fatal` drives the combinator
|
|
12
|
+
* discipline: `parallel()`/`pipeline()` re-throw a fatal error (a typo'd
|
|
13
|
+
* option or a tripped cap must kill the script loudly), and reserve the
|
|
14
|
+
* per-item `null` for child-run failures and ordinary in-stage script errors.
|
|
15
|
+
* Every {@link WorkflowErrorCode} is fatal; the flag exists so the
|
|
16
|
+
* distinction is explicit at every catch site rather than implied.
|
|
17
|
+
*/
|
|
18
|
+
export class WorkflowError extends HarnessError {
|
|
19
|
+
/** Whether combinators must propagate this error instead of nulling the item. */
|
|
20
|
+
fatal;
|
|
21
|
+
constructor(message, code, options) {
|
|
22
|
+
super(message, code, options);
|
|
23
|
+
this.name = 'WorkflowError';
|
|
24
|
+
this.fatal = options?.fatal ?? true;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Whether combinators must re-throw `error` instead of mapping the item to `null`.
|
|
29
|
+
* @param error - any thrown value; fatality is host `instanceof` (unforgeable from a script realm).
|
|
30
|
+
* @returns true iff `error` is a {@link WorkflowError} whose `fatal` flag is set.
|
|
31
|
+
*/
|
|
32
|
+
export function isFatalWorkflowError(error) {
|
|
33
|
+
return error instanceof WorkflowError && error.fatal;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Workflow Service Definition contract. Invalid requests throw before publication; a live
|
|
37
|
+
* run is holder-owned, its result never rejects, cancellation and disposal are
|
|
38
|
+
* bounded, and disposal waits for child cleanup within that bound. Lifecycle
|
|
39
|
+
* listener failures are contained, and `workflow/end` fires exactly once as the
|
|
40
|
+
* result settles.
|
|
41
|
+
*/
|
|
42
|
+
export class WorkflowEngine extends Service {
|
|
43
|
+
constructor(ctx) {
|
|
44
|
+
super(ctx, 'workflowEngine');
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Emit a lifecycle event while containing and logging each listener failure.
|
|
48
|
+
* @param name - the `workflow/*` event to dispatch.
|
|
49
|
+
* @param args - the event's payload, matching its declared signature.
|
|
50
|
+
*/
|
|
51
|
+
emitWorkflowEvent(name, ...args) {
|
|
52
|
+
for (const callback of this.ctx.events.dispatch('emit', [name, ...args])) {
|
|
53
|
+
try {
|
|
54
|
+
const returned = callback(...args);
|
|
55
|
+
void Promise.resolve(returned).catch((error) => {
|
|
56
|
+
this.ctx.logger.warn(`workflow: ${name} listener rejected: ${renderListenerError(error)}`);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
this.ctx.logger.warn(`workflow: ${name} listener threw: ${renderListenerError(error)}`);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Render any thrown value without violating listener containment.
|
|
67
|
+
* @param error - any thrown value.
|
|
68
|
+
* @returns `String(error)`, or a fixed label when even coercion throws.
|
|
69
|
+
*/
|
|
70
|
+
function renderListenerError(error) {
|
|
71
|
+
try {
|
|
72
|
+
return String(error);
|
|
73
|
+
}
|
|
74
|
+
catch {
|
|
75
|
+
// String coercion itself may throw.
|
|
76
|
+
return '[unrenderable thrown value]';
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export default WorkflowEngine;
|
|
80
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
/** Package-owned workflow lifecycle invariants. @module @deepseek-ai/dsh-workflow/invariant */
|
|
2
|
+
const PACKAGE_NAME = '@deepseek-ai/dsh-workflow';
|
|
3
|
+
/** Cordis companion plugin name. */
|
|
4
|
+
export const name = 'workflow-invariant';
|
|
5
|
+
/** Service required before the companion can reserve package ownership. */
|
|
6
|
+
export const inject = ['invariants'];
|
|
7
|
+
/** Require every event for a run to retain its validated identity snapshot. */
|
|
8
|
+
function traceFor(traces, info, fail) {
|
|
9
|
+
const trace = traces.get(info.id);
|
|
10
|
+
if (trace === undefined)
|
|
11
|
+
fail(`workflow event has no matching workflow/start for run ${JSON.stringify(info.id)}`);
|
|
12
|
+
if (trace.meta !== JSON.stringify(info.meta)) {
|
|
13
|
+
fail(`workflow event meta diverges from workflow/start for run ${JSON.stringify(info.id)}`);
|
|
14
|
+
}
|
|
15
|
+
return trace;
|
|
16
|
+
}
|
|
17
|
+
/** Assert the immutable identity fields shared by an agent pair. */
|
|
18
|
+
function validateAgentEnd(start, end, fail) {
|
|
19
|
+
if (start.label !== end.label || start.phase !== end.phase || start.childId !== end.childId) {
|
|
20
|
+
fail(`workflow/agent-end identity diverges from workflow/agent-start for seq ${end.seq}`);
|
|
21
|
+
}
|
|
22
|
+
const outcome = end.outcome;
|
|
23
|
+
if (outcome !== 'completed' && outcome !== 'failed' && outcome !== 'cancelled') {
|
|
24
|
+
fail(`workflow/agent-end carries unknown outcome ${JSON.stringify(outcome)}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/** Validate a terminal result against the accumulated run trace. */
|
|
28
|
+
function validateWorkflowEnd(trace, result, fail) {
|
|
29
|
+
if (trace.agents.size > 0)
|
|
30
|
+
fail(`workflow/end has ${trace.agents.size} agent call(s) without workflow/agent-end`);
|
|
31
|
+
if (!Number.isSafeInteger(result.agentsStarted) || result.agentsStarted < trace.starts) {
|
|
32
|
+
fail('workflow/end agentsStarted must be a safe integer covering every observed agent start');
|
|
33
|
+
}
|
|
34
|
+
if (result.stopReason === 'completed' ? result.error !== undefined : typeof result.error !== 'string') {
|
|
35
|
+
fail('workflow/end error must be absent exactly for completed runs');
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
/** Install workflow start/end and child-call pairing checks. */
|
|
39
|
+
const install = (ctx, fail) => {
|
|
40
|
+
const traces = new Map();
|
|
41
|
+
const stagedStarts = new WeakSet();
|
|
42
|
+
const stagedAgentStarts = new WeakSet();
|
|
43
|
+
const stagedAgentEnds = new WeakSet();
|
|
44
|
+
const stagedEnds = new WeakSet();
|
|
45
|
+
ctx.on('internal/dispatch', (_mode, eventName, args) => {
|
|
46
|
+
if (eventName === 'workflow/start') {
|
|
47
|
+
const info = args[0];
|
|
48
|
+
if (String(info.id).length === 0 || info.meta.name.length === 0 || info.meta.description.length === 0) {
|
|
49
|
+
fail('workflow/start id, meta.name, and meta.description must be non-empty');
|
|
50
|
+
}
|
|
51
|
+
if (traces.has(info.id))
|
|
52
|
+
fail(`workflow/start repeated run id ${JSON.stringify(info.id)}`);
|
|
53
|
+
stagedStarts.add(info);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
if (!eventName.startsWith('workflow/'))
|
|
57
|
+
return;
|
|
58
|
+
const info = args[0];
|
|
59
|
+
const trace = traceFor(traces, info, fail);
|
|
60
|
+
if (eventName === 'workflow/agent-start') {
|
|
61
|
+
const agent = args[1];
|
|
62
|
+
if (!Number.isSafeInteger(agent.seq) || agent.seq < 1 || String(agent.childId).length === 0) {
|
|
63
|
+
fail('workflow/agent-start seq must be positive and childId must be non-empty');
|
|
64
|
+
}
|
|
65
|
+
if (trace.agents.has(agent.seq))
|
|
66
|
+
fail(`workflow/agent-start repeated seq ${agent.seq}`);
|
|
67
|
+
stagedAgentStarts.add(agent);
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (eventName === 'workflow/agent-end') {
|
|
71
|
+
const agent = args[1];
|
|
72
|
+
const start = trace.agents.get(agent.seq);
|
|
73
|
+
if (start === undefined)
|
|
74
|
+
return fail(`workflow/agent-end has no matching start for seq ${agent.seq}`);
|
|
75
|
+
validateAgentEnd(start, agent, fail);
|
|
76
|
+
stagedAgentEnds.add(agent);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (eventName === 'workflow/end') {
|
|
80
|
+
const result = args[1];
|
|
81
|
+
validateWorkflowEnd(trace, result, fail);
|
|
82
|
+
stagedEnds.add(result);
|
|
83
|
+
}
|
|
84
|
+
}, { global: true });
|
|
85
|
+
ctx.on('workflow/start', (info) => {
|
|
86
|
+
/* v8 ignore next -- internal/dispatch stages the same run-info object */
|
|
87
|
+
if (!stagedStarts.delete(info))
|
|
88
|
+
return;
|
|
89
|
+
traces.set(info.id, { meta: JSON.stringify(info.meta), agents: new Map(), starts: 0 });
|
|
90
|
+
}, { global: true });
|
|
91
|
+
ctx.on('workflow/agent-start', (info, agent) => {
|
|
92
|
+
/* v8 ignore next -- internal/dispatch stages the same agent object */
|
|
93
|
+
if (!stagedAgentStarts.delete(agent))
|
|
94
|
+
return;
|
|
95
|
+
const trace = traceFor(traces, info, fail);
|
|
96
|
+
trace.agents.set(agent.seq, agent);
|
|
97
|
+
trace.starts += 1;
|
|
98
|
+
}, { global: true });
|
|
99
|
+
ctx.on('workflow/agent-end', (info, agent) => {
|
|
100
|
+
/* v8 ignore next -- internal/dispatch stages the same agent object */
|
|
101
|
+
if (!stagedAgentEnds.delete(agent))
|
|
102
|
+
return;
|
|
103
|
+
traceFor(traces, info, fail).agents.delete(agent.seq);
|
|
104
|
+
}, { global: true });
|
|
105
|
+
ctx.on('workflow/end', (info, result) => {
|
|
106
|
+
/* v8 ignore next -- internal/dispatch stages the same result object */
|
|
107
|
+
if (!stagedEnds.delete(result))
|
|
108
|
+
return;
|
|
109
|
+
traces.delete(info.id);
|
|
110
|
+
}, { global: true });
|
|
111
|
+
};
|
|
112
|
+
/**
|
|
113
|
+
* Register the workflow invariant companion.
|
|
114
|
+
* @param ctx - Cordis context carrying the invariant service.
|
|
115
|
+
* @returns the installed registration's disposer after setup succeeds.
|
|
116
|
+
*/
|
|
117
|
+
export const apply = (ctx) => Promise.resolve(ctx.invariants.register(PACKAGE_NAME, install));
|
|
118
|
+
//# sourceMappingURL=invariant.js.map
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-only workflow request and live-run handles. The browser-safe durable
|
|
3
|
+
* vocabulary remains in `./types` so Client programs never import Agent or
|
|
4
|
+
* host Cordis context declarations.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-workflow
|
|
7
|
+
*/
|
|
8
|
+
import type { Agent } from '@deepseek-ai/dsh-agent';
|
|
9
|
+
import type { WorkflowMeta, WorkflowResult, WorkflowRunId } from './types.ts';
|
|
10
|
+
/**
|
|
11
|
+
* What a caller asks for when starting a workflow run. `meta` and `args` are
|
|
12
|
+
* plain JSON data by the seam contract. `parent` is required because every
|
|
13
|
+
* `agent()` spawned by the script is attributed to that live Agent.
|
|
14
|
+
*/
|
|
15
|
+
export interface WorkflowStartRequest {
|
|
16
|
+
/** The plain-JS script body (top-level await allowed; ends with `return <json-value>`). */
|
|
17
|
+
script: string;
|
|
18
|
+
/** The workflow's identity block, as plain JSON data (shape-validated by the engine). */
|
|
19
|
+
meta: WorkflowMeta;
|
|
20
|
+
/** Optional input exposed verbatim to the script as the `args` global. */
|
|
21
|
+
args?: unknown;
|
|
22
|
+
/** Optional engine-wide child-provider override for this run. */
|
|
23
|
+
subagentProvider?: string;
|
|
24
|
+
/** Optional per-run total-child ceiling. */
|
|
25
|
+
maxTotalAgents?: number;
|
|
26
|
+
/** The agent on whose behalf the run executes (parent of every child). */
|
|
27
|
+
parent: Agent;
|
|
28
|
+
/** Cancels the run when aborted. */
|
|
29
|
+
signal?: AbortSignal;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Holder-owned live workflow. `result` never rejects; consumers may cancel
|
|
33
|
+
* and must call idempotent `dispose()` to await script and child quiescence.
|
|
34
|
+
*/
|
|
35
|
+
export interface WorkflowRun {
|
|
36
|
+
readonly id: WorkflowRunId;
|
|
37
|
+
/** The validated meta block available before the script body runs. */
|
|
38
|
+
readonly meta: WorkflowMeta;
|
|
39
|
+
readonly result: Promise<WorkflowResult>;
|
|
40
|
+
/** Cancel the run and its children. */
|
|
41
|
+
cancel(reason?: string): void;
|
|
42
|
+
/** Cancel if needed and await bounded settlement and cleanup. */
|
|
43
|
+
dispose(): Promise<void>;
|
|
44
|
+
}
|
|
45
|
+
//# sourceMappingURL=runtime-types.d.ts.map
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Host-only workflow request and live-run handles. The browser-safe durable
|
|
3
|
+
* vocabulary remains in `./types` so Client programs never import Agent or
|
|
4
|
+
* host Cordis context declarations.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-workflow
|
|
7
|
+
*/
|
|
8
|
+
export {};
|
|
9
|
+
//# sourceMappingURL=runtime-types.js.map
|
package/lib/types/types.d.ts
CHANGED
|
@@ -6,8 +6,7 @@
|
|
|
6
6
|
* @module @deepseek-ai/dsh-workflow/types
|
|
7
7
|
*/
|
|
8
8
|
import type { Branded } from '@deepseek-ai/dsh-brand';
|
|
9
|
-
import type {
|
|
10
|
-
import type { SessionId } from '@deepseek-ai/dsh-session';
|
|
9
|
+
import type { SessionId } from '@deepseek-ai/dsh-session/types';
|
|
11
10
|
/** Identifies one workflow run. */
|
|
12
11
|
export type WorkflowRunId = Branded<'WorkflowRunId'>;
|
|
13
12
|
/**
|
|
@@ -47,37 +46,6 @@ export interface WorkflowMeta {
|
|
|
47
46
|
/** Optional phase declarations matched by `phase()` calls. */
|
|
48
47
|
phases?: WorkflowPhase[];
|
|
49
48
|
}
|
|
50
|
-
/**
|
|
51
|
-
* What a caller asks for when starting a workflow run. `meta` and `args` are
|
|
52
|
-
* plain JSON DATA by the seam contract (the tool builds both from the model's schema-validated call;
|
|
53
|
-
* the engine validates `meta` against its schema and rejects loud
|
|
54
|
-
* before anything runs) — an engine never evaluates script text to obtain
|
|
55
|
-
* them. `parent` is REQUIRED — every `agent()` the script spawns is
|
|
56
|
-
* attributed to it (cwd, lineage, depth flow through the subagent seam).
|
|
57
|
-
*/
|
|
58
|
-
export interface WorkflowStartRequest {
|
|
59
|
-
/** The plain-JS script body (top-level await allowed; ends with `return <json-value>`). */
|
|
60
|
-
script: string;
|
|
61
|
-
/** The workflow's identity fields as plain JSON data, validated by the engine. */
|
|
62
|
-
meta: WorkflowMeta;
|
|
63
|
-
/** Optional input exposed verbatim to the script as the `args` global. */
|
|
64
|
-
args?: unknown;
|
|
65
|
-
/**
|
|
66
|
-
* Optional engine-wide child-provider override for this run. The workflow
|
|
67
|
-
* script cannot observe or replace it; omission uses the engine's configured
|
|
68
|
-
* provider.
|
|
69
|
-
*/
|
|
70
|
-
subagentProvider?: string;
|
|
71
|
-
/**
|
|
72
|
-
* Optional per-run total-child ceiling. Implementations reject values above
|
|
73
|
-
* their deployment ceiling before publishing the run.
|
|
74
|
-
*/
|
|
75
|
-
maxTotalAgents?: number;
|
|
76
|
-
/** The agent on whose behalf the run executes (parent of every child). */
|
|
77
|
-
parent: Agent;
|
|
78
|
-
/** Cancels the run when aborted (the tool's `exec.signal`). */
|
|
79
|
-
signal?: AbortSignal;
|
|
80
|
-
}
|
|
81
49
|
/**
|
|
82
50
|
* Why a run settled. CLOSED union (engine-owned, consumers may exhaust):
|
|
83
51
|
* `completed` = the script ran to its final `return`; `cancelled` = the run
|
|
@@ -86,7 +54,7 @@ export interface WorkflowStartRequest {
|
|
|
86
54
|
*/
|
|
87
55
|
export type WorkflowStopReason = 'completed' | 'cancelled' | 'error';
|
|
88
56
|
/**
|
|
89
|
-
* The outcome
|
|
57
|
+
* The outcome resolved by a live workflow run. `value` is
|
|
90
58
|
* the script's materialized return value (plain host-realm JSON data; `null`
|
|
91
59
|
* when the script returned `undefined`) — meaningful only for `completed`.
|
|
92
60
|
* A non-`completed` reason carries the failure in `error`; the consumer maps
|
|
@@ -108,22 +76,6 @@ export interface WorkflowResult {
|
|
|
108
76
|
*/
|
|
109
77
|
agentsStarted: number;
|
|
110
78
|
}
|
|
111
|
-
/**
|
|
112
|
-
* Holder-owned live workflow. `result` never rejects and settles within the
|
|
113
|
-
* engine's cancellation grace; failures resolve through `stopReason`. Consumers
|
|
114
|
-
* may cancel and must call idempotent `dispose()` on every path to await bounded
|
|
115
|
-
* script settlement and child quiescence.
|
|
116
|
-
*/
|
|
117
|
-
export interface WorkflowRun {
|
|
118
|
-
readonly id: WorkflowRunId;
|
|
119
|
-
/** The validated meta block (available before the body runs). */
|
|
120
|
-
readonly meta: WorkflowMeta;
|
|
121
|
-
readonly result: Promise<WorkflowResult>;
|
|
122
|
-
/** Cancel the run: children abort, pending hooks reject, the script dies at its next await (or is force-settled at the grace). */
|
|
123
|
-
cancel(reason?: string): void;
|
|
124
|
-
/** Cancel + bounded-grace settle; safe to call on every path (idempotent). */
|
|
125
|
-
dispose(): Promise<void>;
|
|
126
|
-
}
|
|
127
79
|
/** Identifying detail for a run, carried by every `workflow/*` event as borrowed immutable data, never the live run. */
|
|
128
80
|
export interface WorkflowRunInfo {
|
|
129
81
|
/** The run's id. */
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Workflow seam vocabulary: the request/run/result types a workflow engine
|
|
3
|
+
* consumes and produces, plus the fields in the `workflow/*` event payloads.
|
|
4
|
+
* Types only (plus the id-brand factory), per the package convention.
|
|
5
|
+
*
|
|
6
|
+
* @module @deepseek-ai/dsh-workflow/types
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Brand a string as a {@link WorkflowRunId}.
|
|
10
|
+
* @param id - the raw id string (the engine mints UUIDs; tests may pass fixtures).
|
|
11
|
+
* @returns the same string, branded.
|
|
12
|
+
*/
|
|
13
|
+
export function WorkflowRunId(id) {
|
|
14
|
+
return id;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=types.js.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@deepseek-ai/dsh-workflow",
|
|
3
|
-
"description": "Workflow capability seam: ctx.
|
|
4
|
-
"version": "0.0.1-rc.
|
|
3
|
+
"description": "Workflow capability seam: ctx.workflowEngine service, run vocabulary, and workflow/* events",
|
|
4
|
+
"version": "0.0.1-rc.5",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "restricted"
|
|
7
7
|
},
|
|
@@ -22,29 +22,34 @@
|
|
|
22
22
|
"types": "./lib/types/invariant.d.ts",
|
|
23
23
|
"default": "./lib/invariant.js"
|
|
24
24
|
},
|
|
25
|
+
"./types": {
|
|
26
|
+
"types": "./lib/types/types.d.ts",
|
|
27
|
+
"default": "./lib/types/types.js"
|
|
28
|
+
},
|
|
25
29
|
"./src/*": "./src/*",
|
|
26
30
|
"./package.json": "./package.json"
|
|
27
31
|
},
|
|
28
32
|
"files": [
|
|
29
33
|
"lib/index.js",
|
|
30
34
|
"lib/invariant.js",
|
|
35
|
+
"lib/types/**/*.js",
|
|
31
36
|
"lib/types/**/*.d.ts"
|
|
32
37
|
],
|
|
33
38
|
"license": "BSD-3-Clause",
|
|
34
39
|
"peerDependencies": {
|
|
35
|
-
"@deepseek-ai/dsh-agent": "^0.0.1-rc.
|
|
36
|
-
"@deepseek-ai/dsh-brand": "^0.0.1-rc.
|
|
37
|
-
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.
|
|
38
|
-
"@deepseek-ai/dsh-llm": "^0.0.1-rc.
|
|
39
|
-
"@deepseek-ai/dsh-session": "^0.0.1-rc.
|
|
40
|
-
"@deepseek-ai/cordis": "^4.0.1-rc.
|
|
40
|
+
"@deepseek-ai/dsh-agent": "^0.0.1-rc.5",
|
|
41
|
+
"@deepseek-ai/dsh-brand": "^0.0.1-rc.5",
|
|
42
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.5",
|
|
43
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.5",
|
|
44
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.5",
|
|
45
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.4"
|
|
41
46
|
},
|
|
42
47
|
"devDependencies": {
|
|
43
|
-
"@deepseek-ai/dsh-agent": "^0.0.1-rc.
|
|
44
|
-
"@deepseek-ai/dsh-brand": "^0.0.1-rc.
|
|
45
|
-
"@deepseek-ai/dsh-
|
|
46
|
-
"@deepseek-ai/dsh-
|
|
47
|
-
"@deepseek-ai/
|
|
48
|
-
"@deepseek-ai/
|
|
48
|
+
"@deepseek-ai/dsh-agent": "^0.0.1-rc.5",
|
|
49
|
+
"@deepseek-ai/dsh-brand": "^0.0.1-rc.5",
|
|
50
|
+
"@deepseek-ai/dsh-invariants": "^0.0.1-rc.5",
|
|
51
|
+
"@deepseek-ai/dsh-llm": "^0.0.1-rc.5",
|
|
52
|
+
"@deepseek-ai/dsh-session": "^0.0.1-rc.5",
|
|
53
|
+
"@deepseek-ai/cordis": "^4.0.1-rc.4"
|
|
49
54
|
}
|
|
50
55
|
}
|