@deepseek-ai/dsh-workflow 0.2.2-rc.1 → 0.2.2-rc.3

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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAA;AACnD,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EACjB,kBAAkB,EAClB,eAAe,EAChB,MAAM,YAAY,CAAA;AACnB,OAAO,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE3E,OAAO,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAC1C,YAAY,EACV,oBAAoB,EACpB,iBAAiB,EACjB,oBAAoB,EACpB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,kBAAkB,EAClB,eAAe,EACf,kBAAkB,GACnB,MAAM,YAAY,CAAA;AACnB,YAAY,EAAE,WAAW,EAAE,oBAAoB,EAAE,MAAM,oBAAoB,CAAA;AAE3E,OAAO,QAAQ,qBAAqB,CAAC;IACnC,UAAU,OAAO;QACf,cAAc,EAAE,cAAc,CAAA;KAC/B;IAED,UAAU,MAAM;QACd;;;;;WAKG;QACH,gBAAgB,CAAC,IAAI,EAAE,eAAe,GAAG,IAAI,CAAA;QAC7C;;;;;;WAMG;QACH,gBAAgB,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;QAC5D;;;;;WAKG;QACH,cAAc,CAAC,IAAI,EAAE,eAAe,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAAA;QAC5D;;;;;;;;WAQG;QACH,sBAAsB,CAAC,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,iBAAi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AAQ,CAAC,IAAI,EAAE,YAAY,CAAA;IAC3B,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IACxC,uCAAuC;IACvC,MAAM,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAA;IAC7B,2DAA2D;IAC3D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,CAAA;CACzB"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"runtime-types.js","sourceRoot":"","sources":["../../src/runtime-types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAA;AACrD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gCAAgC,CAAA;AAE/D,mCAAmC;AACnC,MAAM,MAAM,aAAa,GAAG,OAAO,CAAC,eAAe,CAAC,CAAA;AAEpD;;;;GAIG;AACH,wBAAgB,aAAa,CAAC,EAAE,EAAE,MAAM,GAAG,aAAa,CAEvD;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,yEAAyE;IACzE,KAAK,EAAE,MAAM,CAAA;IACb,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,6EAA6E;IAC7E,KAAK,CAAC,EAAE,MAAM,CAAA;CACf;AAED;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,kEAAkE;IAClE,IAAI,EAAE,MAAM,CAAA;IACZ,sDAAsD;IACtD,WAAW,EAAE,MAAM,CAAA;IACnB,2EAA2E;IAC3E,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,8DAA8D;IAC9D,MAAM,CAAC,EAAE,aAAa,EAAE,CAAA;CACzB;AAED;;;;;GAKG;AACH,M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B,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@deepseek-ai/dsh-workflow",
3
3
  "description": "Workflow capability seam: ctx.workflowEngine service, run vocabulary, and workflow/* events",
4
- "version": "0.2.2-rc.1",
4
+ "version": "0.2.2-rc.3",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -28,21 +28,24 @@
28
28
  "files": [
29
29
  "lib/index.js",
30
30
  "lib/types/**/*.js",
31
- "lib/types/**/*.d.ts"
31
+ "lib/types/**/*.d.ts",
32
+ "lib/types/**/*.d.ts.map",
33
+ "lib/**/*.js.map",
34
+ "src"
32
35
  ],
33
36
  "license": "MIT",
34
37
  "peerDependencies": {
35
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
36
- "@deepseek-ai/dsh-brand": "0.2.2-rc.1",
37
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
38
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
38
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
39
+ "@deepseek-ai/dsh-brand": "0.2.2-rc.3",
40
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.3",
41
+ "@deepseek-ai/dsh-session": "0.2.2-rc.3",
39
42
  "@deepseek-ai/cordis": "~4.1.0"
40
43
  },
41
44
  "devDependencies": {
42
- "@deepseek-ai/dsh-agent": "0.2.2-rc.1",
43
- "@deepseek-ai/dsh-brand": "0.2.2-rc.1",
44
- "@deepseek-ai/dsh-llm": "0.2.2-rc.1",
45
- "@deepseek-ai/dsh-session": "0.2.2-rc.1",
45
+ "@deepseek-ai/dsh-agent": "0.2.2-rc.3",
46
+ "@deepseek-ai/dsh-brand": "0.2.2-rc.3",
47
+ "@deepseek-ai/dsh-llm": "0.2.2-rc.3",
48
+ "@deepseek-ai/dsh-session": "0.2.2-rc.3",
46
49
  "@deepseek-ai/cordis": "~4.1.0"
47
50
  }
48
51
  }
package/src/index.ts ADDED
@@ -0,0 +1,203 @@
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
+
7
+ import { Context, Service } from '@deepseek-ai/cordis'
8
+ import { HarnessError } from '@deepseek-ai/dsh-llm'
9
+ import type {
10
+ WorkflowAgentEndInfo,
11
+ WorkflowAgentInfo,
12
+ WorkflowResultInfo,
13
+ WorkflowRunInfo,
14
+ } from './types.ts'
15
+ import type { WorkflowRun, WorkflowStartRequest } from './runtime-types.ts'
16
+
17
+ export { WorkflowRunId } from './types.ts'
18
+ export type {
19
+ WorkflowAgentEndInfo,
20
+ WorkflowAgentInfo,
21
+ WorkflowAgentOutcome,
22
+ WorkflowMeta,
23
+ WorkflowPhase,
24
+ WorkflowResult,
25
+ WorkflowResultInfo,
26
+ WorkflowRunInfo,
27
+ WorkflowStopReason,
28
+ } from './types.ts'
29
+ export type { WorkflowRun, WorkflowStartRequest } from './runtime-types.ts'
30
+
31
+ declare module '@deepseek-ai/cordis' {
32
+ interface Context {
33
+ workflowEngine: WorkflowEngine
34
+ }
35
+
36
+ interface Events {
37
+ /**
38
+ * A workflow run started — the script's meta block validated, the body
39
+ * about to execute. Paired with {@link Events['workflow/end']}.
40
+ * @param info - the run's identity snapshot (id + meta).
41
+ * @mode emit
42
+ */
43
+ 'workflow/start'(info: WorkflowRunInfo): void
44
+ /**
45
+ * The script entered a phase (a `phase(title)` call) — progress grouping
46
+ * for observers; no execution semantics.
47
+ * @param info - the run's identity snapshot.
48
+ * @param title - the phase title, verbatim.
49
+ * @mode emit
50
+ */
51
+ 'workflow/phase'(info: WorkflowRunInfo, title: string): void
52
+ /**
53
+ * The script emitted a narration line (a `log(message)` call).
54
+ * @param info - the run's identity snapshot.
55
+ * @param message - the logged message, verbatim.
56
+ * @mode emit
57
+ */
58
+ 'workflow/log'(info: WorkflowRunInfo, message: string): void
59
+ /**
60
+ * One `agent()` call established a published child run. Paired with
61
+ * {@link Events['workflow/agent-end']} by `agent.seq`. A call that never
62
+ * receives a published run from the provider emits neither
63
+ * event in this pair.
64
+ * @param info - the run's identity snapshot.
65
+ * @param agent - the call's sequence number, label, phase, and child id.
66
+ * @mode emit
67
+ */
68
+ 'workflow/agent-start'(info: WorkflowRunInfo, agent: WorkflowAgentInfo): void
69
+ /**
70
+ * One `agent()` call settled (clean result, child failure, or run
71
+ * cancellation). Paired with {@link Events['workflow/agent-start']} by
72
+ * `agent.seq`, exactly once per started call on every stop path — on an
73
+ * engine termination path the end is
74
+ * engine-synthesized with outcome `'cancelled'`.
75
+ * @param info - the run's identity snapshot.
76
+ * @param agent - the call identity plus its outcome.
77
+ * @mode emit
78
+ */
79
+ 'workflow/agent-end'(info: WorkflowRunInfo, agent: WorkflowAgentEndInfo): void
80
+ /**
81
+ * A workflow run settled (any stop reason). Fired when
82
+ * {@link WorkflowRun.result} resolves. Paired with
83
+ * {@link Events['workflow/start']}.
84
+ * @param info - the run's identity snapshot.
85
+ * @param result - the outcome data (stop reason, error, agent count) —
86
+ * deliberately WITHOUT the result value (see {@link WorkflowResultInfo}).
87
+ * @mode emit
88
+ */
89
+ 'workflow/end'(info: WorkflowRunInfo, result: WorkflowResultInfo): void
90
+ }
91
+ }
92
+
93
+ /** The full set of `workflow/*` event names {@link WorkflowEngine.emitWorkflowEvent} dispatches. */
94
+ export type WorkflowEventName =
95
+ | 'workflow/start'
96
+ | 'workflow/phase'
97
+ | 'workflow/log'
98
+ | 'workflow/agent-start'
99
+ | 'workflow/agent-end'
100
+ | 'workflow/end'
101
+
102
+ /**
103
+ * Machine-routable fatal workflow failures: parse/meta/argument/schema errors,
104
+ * resource caps, subagent infrastructure failures, unserializable boundary
105
+ * values, and cancellation. An ordinary child failure resolves its item to
106
+ * `null` and is not one of these fatal codes.
107
+ */
108
+ export type WorkflowErrorCode =
109
+ | 'SCRIPT_PARSE'
110
+ | 'META_INVALID'
111
+ | 'INVALID_ARGUMENT'
112
+ | 'UNSUPPORTED_OPTION'
113
+ | 'UNSUPPORTED_SCHEMA'
114
+ | 'AGENT_CAP'
115
+ | 'ITEM_CAP'
116
+ | 'AGENT_START'
117
+ | 'AGENT_RESULT'
118
+ | 'RESULT_UNSERIALIZABLE'
119
+ | 'CANCELLED'
120
+
121
+ /**
122
+ * Typed error for workflow-seam failures. Extends {@link HarnessError}, so the
123
+ * `code` is machine-routable taxonomy. `fatal` drives the combinator
124
+ * discipline: `parallel()`/`pipeline()` re-throw a fatal error (a typo'd
125
+ * option or a tripped cap must kill the script loudly), and reserve the
126
+ * per-item `null` for child-run failures and ordinary in-stage script errors.
127
+ * Every {@link WorkflowErrorCode} is fatal; the flag exists so the
128
+ * distinction is explicit at every catch site rather than implied.
129
+ */
130
+ export class WorkflowError extends HarnessError {
131
+ /** Whether combinators must propagate this error instead of nulling the item. */
132
+ readonly fatal: boolean
133
+
134
+ constructor(message: string, code: WorkflowErrorCode, options?: ErrorOptions & { fatal?: boolean }) {
135
+ super(message, code, options)
136
+ this.name = 'WorkflowError'
137
+ this.fatal = options?.fatal ?? true
138
+ }
139
+ }
140
+
141
+ /**
142
+ * Whether combinators must re-throw `error` instead of mapping the item to `null`.
143
+ * @param error - any thrown value; fatality is host `instanceof` (unforgeable from a script realm).
144
+ * @returns true iff `error` is a {@link WorkflowError} whose `fatal` flag is set.
145
+ */
146
+ export function isFatalWorkflowError(error: unknown): boolean {
147
+ return error instanceof WorkflowError && error.fatal
148
+ }
149
+
150
+ /**
151
+ * Workflow Service Definition contract. Invalid requests throw before publication; a live
152
+ * run is holder-owned, its result never rejects, and disposal waits for script
153
+ * and child cleanup. Lifecycle
154
+ * listener failures are contained, and `workflow/end` fires exactly once as the
155
+ * result settles.
156
+ */
157
+ export abstract class WorkflowEngine extends Service {
158
+ constructor(ctx: Context) {
159
+ super(ctx, 'workflowEngine')
160
+ }
161
+
162
+ /**
163
+ * Parse and execute a workflow script.
164
+ * @param request - the script, its `args`, the parent agent, and an
165
+ * optional cancel signal.
166
+ * @returns the live run; its `result` resolves when the script settles.
167
+ */
168
+ abstract start(request: WorkflowStartRequest): WorkflowRun
169
+
170
+ /**
171
+ * Emit a lifecycle event while containing and logging each listener failure.
172
+ * @param name - the `workflow/*` event to dispatch.
173
+ * @param args - the event's payload, matching its declared signature.
174
+ */
175
+ protected emitWorkflowEvent(name: WorkflowEventName, ...args: unknown[]): void {
176
+ for (const callback of this.ctx.events.dispatch('emit', [name, ...args])) {
177
+ try {
178
+ const returned: unknown = (callback as (...payload: unknown[]) => unknown)(...args)
179
+ void Promise.resolve(returned).catch((error: unknown) => {
180
+ this.ctx.logger.warn(`workflow: ${name} listener rejected: ${renderListenerError(error)}`)
181
+ })
182
+ } catch (error: unknown) {
183
+ this.ctx.logger.warn(`workflow: ${name} listener threw: ${renderListenerError(error)}`)
184
+ }
185
+ }
186
+ }
187
+ }
188
+
189
+ /**
190
+ * Render any thrown value without violating listener containment.
191
+ * @param error - any thrown value.
192
+ * @returns `String(error)`, or a fixed label when even coercion throws.
193
+ */
194
+ function renderListenerError(error: unknown): string {
195
+ try {
196
+ return String(error)
197
+ } catch {
198
+ // String coercion itself may throw.
199
+ return '[unrenderable thrown value]'
200
+ }
201
+ }
202
+
203
+ export default WorkflowEngine
@@ -0,0 +1,49 @@
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
+
9
+ import type { Agent } from '@deepseek-ai/dsh-agent'
10
+ import type {
11
+ WorkflowMeta, WorkflowResult, WorkflowRunId,
12
+ } from './types.ts'
13
+
14
+ /**
15
+ * What a caller asks for when starting a workflow run. `meta` and `args` are
16
+ * plain JSON data by the seam contract. `parent` is required because every
17
+ * `agent()` spawned by the script is attributed to that live Agent.
18
+ */
19
+ export interface WorkflowStartRequest {
20
+ /** The plain-JS script body (top-level await allowed; ends with `return <json-value>`). */
21
+ script: string
22
+ /** The workflow's identity block, as plain JSON data (shape-validated by the engine). */
23
+ meta: WorkflowMeta
24
+ /** Optional input exposed verbatim to the script as the `args` global. */
25
+ args?: unknown
26
+ /** Optional engine-wide child-provider override for this run. */
27
+ subagentProvider?: string
28
+ /** Optional per-run total-child ceiling. */
29
+ maxTotalAgents?: number
30
+ /** The agent on whose behalf the run executes (parent of every child). */
31
+ parent: Agent
32
+ /** Cancels the run when aborted. */
33
+ signal?: AbortSignal
34
+ }
35
+
36
+ /**
37
+ * Holder-owned live workflow. `result` never rejects; consumers may cancel
38
+ * and must call idempotent `dispose()` to await script and child quiescence.
39
+ */
40
+ export interface WorkflowRun {
41
+ readonly id: WorkflowRunId
42
+ /** The validated meta block available before the script body runs. */
43
+ readonly meta: WorkflowMeta
44
+ readonly result: Promise<WorkflowResult>
45
+ /** Cancel the run and its children. */
46
+ cancel(reason?: string): void
47
+ /** Cancel if needed and await script and child cleanup. */
48
+ dispose(): Promise<void>
49
+ }
package/src/types.ts ADDED
@@ -0,0 +1,131 @@
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
+ import type { Branded } from '@deepseek-ai/dsh-brand'
10
+ import type { SessionId } from '@deepseek-ai/dsh-session/types'
11
+
12
+ /** Identifies one workflow run. */
13
+ export type WorkflowRunId = Branded<'WorkflowRunId'>
14
+
15
+ /**
16
+ * Brand a string as a {@link WorkflowRunId}.
17
+ * @param id - the raw id string (the engine mints UUIDs; tests may pass fixtures).
18
+ * @returns the same string, branded.
19
+ */
20
+ export function WorkflowRunId(id: string): WorkflowRunId {
21
+ return id as WorkflowRunId
22
+ }
23
+
24
+ /**
25
+ * One phase declared in a script's `meta.phases` (progress vocabulary only —
26
+ * phases group agents in observers/UIs; they impose no execution structure).
27
+ */
28
+ export interface WorkflowPhase {
29
+ /** The phase title; `phase()` calls match against it by exact string. */
30
+ title: string
31
+ /** Optional one-line description of what the phase does. */
32
+ detail?: string
33
+ /** Optional provider override this phase is expected to use (informational). */
34
+ provider?: string
35
+ /** Optional model override this phase is expected to use (informational). */
36
+ model?: string
37
+ }
38
+
39
+ /**
40
+ * The script's identity block, provided as plain JSON data alongside the
41
+ * script body (the model-facing tool carries it as its `meta` parameter) and
42
+ * validated by the engine before the body runs. `name`/`description` are
43
+ * required; the rest is optional annotation. The field vocabulary matches the
44
+ * Claude Code dynamic-workflows meta block.
45
+ */
46
+ export interface WorkflowMeta {
47
+ /** Short kebab-case workflow name (display + persistence key). */
48
+ name: string
49
+ /** One-line description of what the workflow does. */
50
+ description: string
51
+ /** Optional guidance on when this workflow applies (shown in listings). */
52
+ whenToUse?: string
53
+ /** Optional phase declarations matched by `phase()` calls. */
54
+ phases?: WorkflowPhase[]
55
+ }
56
+
57
+ /**
58
+ * Why a run settled. CLOSED union (engine-owned, consumers may exhaust):
59
+ * `completed` = the script ran to its final `return`; `cancelled` = the run
60
+ * was cancelled (caller `cancel()`/signal); `error` = the script threw, a
61
+ * fatal `WorkflowError` propagated, or the result failed materialization.
62
+ */
63
+ export type WorkflowStopReason = 'completed' | 'cancelled' | 'error'
64
+
65
+ /**
66
+ * The outcome resolved by a live workflow run. `value` is
67
+ * the script's materialized return value (plain host-realm JSON data; `null`
68
+ * when the script returned `undefined`) — meaningful only for `completed`.
69
+ * A non-`completed` reason carries the failure in `error`; the consumer maps
70
+ * it to an `isError` tool result rather than reporting partial output.
71
+ */
72
+ export interface WorkflowResult {
73
+ /** The script's return value (host JSON data; `null` for no return). */
74
+ value: unknown
75
+ /** Why the run settled. */
76
+ stopReason: WorkflowStopReason
77
+ /** The failure message (present iff `stopReason` is not `completed`). */
78
+ error?: string
79
+ /**
80
+ * How many `agent()` calls the run accepted over its whole lifetime. On a
81
+ * graceful settlement this is the script-side count (calls still queued for
82
+ * a concurrency slot included); on a termination path (cancellation or
83
+ * process failure) it degrades to the host-observed count — calls queued
84
+ * inside a terminated script are unknowable then.
85
+ */
86
+ agentsStarted: number
87
+ }
88
+
89
+ /** Identifying detail for a run, carried by every `workflow/*` event as borrowed immutable data, never the live run. */
90
+ export interface WorkflowRunInfo {
91
+ /** The run's id. */
92
+ id: WorkflowRunId
93
+ /** The run's validated meta block. */
94
+ meta: WorkflowMeta
95
+ }
96
+
97
+ /** One `agent()` call's identity within a run (the `workflow/agent-start` payload). */
98
+ export interface WorkflowAgentInfo {
99
+ /** 1-based sequence number of this `agent()` call within the run. */
100
+ seq: number
101
+ /** The display label (the `label` option, or a prompt snippet). */
102
+ label: string
103
+ /** The phase this agent belongs to (the `phase` option, else the current `phase()` title). */
104
+ phase?: string
105
+ /** The child agent's id on the subagent seam. */
106
+ childId: SessionId
107
+ }
108
+
109
+ /** How one `agent()` call settled: clean result, child failure (script sees `null`), or run cancellation. */
110
+ export type WorkflowAgentOutcome = 'completed' | 'failed' | 'cancelled'
111
+
112
+ /** One `agent()` call's settlement (the `workflow/agent-end` payload). */
113
+ export interface WorkflowAgentEndInfo extends WorkflowAgentInfo {
114
+ /** How the call settled. */
115
+ outcome: WorkflowAgentOutcome
116
+ }
117
+
118
+ /**
119
+ * A settled run's outcome as event data (the `workflow/end` payload): the
120
+ * {@link WorkflowResult} minus `value` (a listener observing outcomes must not
121
+ * receive a mutable alias of the caller's result value; a consumer that needs
122
+ * the value holds the run and awaits `result`).
123
+ */
124
+ export interface WorkflowResultInfo {
125
+ /** Why the run settled. */
126
+ stopReason: WorkflowStopReason
127
+ /** The failure message (present iff `stopReason` is not `completed`). */
128
+ error?: string
129
+ /** How many `agent()` calls the run accepted (see {@link WorkflowResult.agentsStarted}). */
130
+ agentsStarted: number
131
+ }