@deepseek-ai/dsh-subagent 0.2.3-alpha.2 → 0.2.3-alpha.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.
Files changed (63) hide show
  1. package/README.i18n.yaml +15 -12
  2. package/README.md +19 -5
  3. package/README.zh.md +19 -5
  4. package/lib/index.js +480 -162
  5. package/lib/typert.host.js +90 -5
  6. package/lib/typert.remote-client.d.ts +4 -1
  7. package/lib/typert.remote-client.d.ts.map +1 -1
  8. package/lib/typert.remote-client.js +57 -2
  9. package/lib/types/activation.d.ts +31 -4
  10. package/lib/types/activation.d.ts.map +1 -1
  11. package/lib/types/activation.js +35 -6
  12. package/lib/types/activation.js.map +1 -1
  13. package/lib/types/assistant-output.d.ts +4 -2
  14. package/lib/types/assistant-output.d.ts.map +1 -1
  15. package/lib/types/assistant-output.js +8 -8
  16. package/lib/types/assistant-output.js.map +1 -1
  17. package/lib/types/child-agent.d.ts +3 -4
  18. package/lib/types/child-agent.d.ts.map +1 -1
  19. package/lib/types/child-agent.js +4 -12
  20. package/lib/types/child-agent.js.map +1 -1
  21. package/lib/types/control-types.d.ts +26 -2
  22. package/lib/types/control-types.d.ts.map +1 -1
  23. package/lib/types/control.d.ts +16 -2
  24. package/lib/types/control.d.ts.map +1 -1
  25. package/lib/types/control.js +49 -2
  26. package/lib/types/control.js.map +1 -1
  27. package/lib/types/descriptor.d.ts +19 -15
  28. package/lib/types/descriptor.d.ts.map +1 -1
  29. package/lib/types/descriptor.js +10 -21
  30. package/lib/types/descriptor.js.map +1 -1
  31. package/lib/types/error.d.ts +4 -0
  32. package/lib/types/error.d.ts.map +1 -1
  33. package/lib/types/error.js.map +1 -1
  34. package/lib/types/index.d.ts +30 -2
  35. package/lib/types/index.d.ts.map +1 -1
  36. package/lib/types/index.js +58 -2
  37. package/lib/types/index.js.map +1 -1
  38. package/lib/types/lifecycle.d.ts +4 -4
  39. package/lib/types/lifecycle.d.ts.map +1 -1
  40. package/lib/types/lifecycle.js +4 -5
  41. package/lib/types/lifecycle.js.map +1 -1
  42. package/lib/types/manager.d.ts +38 -3
  43. package/lib/types/manager.d.ts.map +1 -1
  44. package/lib/types/manager.js +247 -38
  45. package/lib/types/manager.js.map +1 -1
  46. package/lib/types/model-selection.d.ts +22 -0
  47. package/lib/types/model-selection.d.ts.map +1 -0
  48. package/lib/types/model-selection.js +39 -0
  49. package/lib/types/model-selection.js.map +1 -0
  50. package/lib/types/types.d.ts +3 -3
  51. package/package.json +54 -54
  52. package/src/activation.ts +48 -9
  53. package/src/assistant-output.ts +9 -8
  54. package/src/child-agent.ts +4 -11
  55. package/src/control-types.ts +22 -2
  56. package/src/control.ts +67 -2
  57. package/src/descriptor.ts +20 -27
  58. package/src/error.ts +4 -0
  59. package/src/index.ts +67 -4
  60. package/src/lifecycle.ts +5 -6
  61. package/src/manager.ts +238 -34
  62. package/src/model-selection.ts +52 -0
  63. package/src/types.ts +3 -3
@@ -58,16 +58,13 @@ export function resolveChildDepth(parent: Agent, maxDepth: number | undefined):
58
58
  }
59
59
 
60
60
  /**
61
- * Resolve the parent values inherited by a child. The latest request header
62
- * owns provider, model, and reasoning effort after request-time selection;
63
- * creation options remain the fallback before the first request and retain
64
- * the configured output-token limit.
61
+ * Capture the parent's current model choice and configured output controls.
62
+ * A recorded choice applies even before the parent uses it in a request;
63
+ * adapter-defaulted effort remains unselected.
65
64
  * @param parent - delegating parent Agent.
66
65
  * @returns detached Agent options for child-option merging.
67
66
  */
68
67
  export function parentAgentOptionsForDelegation(parent: Agent): AgentOptions {
69
- const requestConfig = parent.session.requestHeader()?.config
70
- if (requestConfig === undefined) return { ...parent.options }
71
68
  const {
72
69
  provider: _createdProvider,
73
70
  model: _createdModel,
@@ -76,11 +73,7 @@ export function parentAgentOptionsForDelegation(parent: Agent): AgentOptions {
76
73
  } = parent.options
77
74
  return {
78
75
  ...createdOptions,
79
- provider: requestConfig.provider,
80
- model: requestConfig.model,
81
- ...requestConfig.reasoningEffort === undefined
82
- ? {}
83
- : { reasoningEffort: requestConfig.reasoningEffort },
76
+ ...parent.model.current(),
84
77
  }
85
78
  }
86
79
 
@@ -5,6 +5,7 @@
5
5
  * @module @deepseek-ai/dsh-subagent/control-types
6
6
  */
7
7
 
8
+ import type { ModelSelection } from '@deepseek-ai/dsh-agent/types'
8
9
  import type { PromptContentPart } from '@deepseek-ai/dsh-attachment/types'
9
10
  import type { Branded } from '@deepseek-ai/dsh-brand'
10
11
  import type { MessageId } from '@deepseek-ai/dsh-llm/types'
@@ -100,9 +101,22 @@ export interface SubagentInterruptReceipt {
100
101
  readonly accepted: true
101
102
  }
102
103
 
104
+ /** Complete human-selected model choice for a continuable child. */
105
+ export interface SubagentSelectModelRequest {
106
+ readonly childSessionId: SessionId
107
+ readonly provider: string
108
+ readonly model: string
109
+ /** Omission clears an explicit effort and uses the selected model's default. */
110
+ readonly reasoningEffort?: string
111
+ }
112
+
113
+ /** Choice returned after the child's persistence barrier confirms it. */
114
+ export interface SubagentSelectModelReceipt {
115
+ readonly selected: ModelSelection
116
+ }
117
+
103
118
  /**
104
- * Failure details the control surface answers with. Prompts and interrupts
105
- * share these failures with the Client Remote result.
119
+ * Subagent activity reported to Workspace archive admission.
106
120
  */
107
121
  declare module '@deepseek-ai/dsh-workspace/types' {
108
122
  interface SessionActivityKindMap {
@@ -123,5 +137,11 @@ declare module '@deepseek-ai/dsh-typert-protocol' {
123
137
  'subagent/attachment-invalid': { readonly reason: string }
124
138
  /** The child exists but its inbox cannot admit the message now. */
125
139
  'subagent/delivery-unavailable': { readonly childSessionId: SessionId }
140
+ /** The requested route or effort is unavailable; the previous choice is unchanged. */
141
+ 'subagent/model-unavailable': { readonly childSessionId: SessionId }
142
+ /** The child cannot accept a model selection now. */
143
+ 'subagent/model-selection-unavailable': { readonly childSessionId: SessionId }
144
+ /** Selection may have changed; reload child state before deciding whether to retry. */
145
+ 'subagent/model-selection-unconfirmed': { readonly childSessionId: SessionId }
126
146
  }
127
147
  }
package/src/control.ts CHANGED
@@ -1,11 +1,11 @@
1
1
  /**
2
- * Browser-facing subagent prompt and interrupt request validation plus the
3
- * stable prompt failure codes returned by the Remote surface.
2
+ * Browser-facing subagent request validation and stable control failures.
4
3
  *
5
4
  * @module @deepseek-ai/dsh-subagent
6
5
  */
7
6
 
8
7
  import { AttachmentError } from '@deepseek-ai/dsh-attachment'
8
+ import { LlmError } from '@deepseek-ai/dsh-llm'
9
9
  import type { SessionId } from '@deepseek-ai/dsh-session'
10
10
  import { RemoteError } from '@deepseek-ai/dsh-typert-protocol'
11
11
  import { z } from 'zod'
@@ -20,6 +20,12 @@ const CONTROL_ID_SCHEMAS = {
20
20
  'subagent.interrupt': z.object({
21
21
  childSessionId: SESSION_ID_SCHEMA,
22
22
  }),
23
+ 'subagent.selectModel': z.object({
24
+ childSessionId: SESSION_ID_SCHEMA,
25
+ provider: z.string().min(1),
26
+ model: z.string().min(1),
27
+ reasoningEffort: z.string().min(1).optional(),
28
+ }),
23
29
  } as const
24
30
 
25
31
  /**
@@ -101,3 +107,62 @@ export function rejectPrompt(error: unknown, childSessionId: SessionId, signal:
101
107
  function isCancellation(error: unknown, signal: AbortSignal): boolean {
102
108
  return signal.aborted || (error instanceof SubagentError && error.code === 'CANCELLED')
103
109
  }
110
+
111
+ /**
112
+ * Report selection failures while preserving an uncertain persistence outcome.
113
+ * @param error - failure from model selection or its durability barrier.
114
+ * @param childSessionId - addressed child.
115
+ * @param signal - caller cancellation before recording.
116
+ * @returns Never — the refusal is thrown.
117
+ * @throws {RemoteError} always; persistence uncertainty takes precedence over cancellation.
118
+ */
119
+ export function rejectModelSelection(error: unknown, childSessionId: SessionId, signal: AbortSignal): never {
120
+ if (error instanceof SubagentError && error.code === 'PERSISTENCE_UNCONFIRMED') {
121
+ throw new RemoteError(
122
+ 'subagent/model-selection-unconfirmed',
123
+ 'the child model choice may have changed, but persistence is unconfirmed; reload its state before retrying',
124
+ { childSessionId },
125
+ { cause: error },
126
+ )
127
+ }
128
+ if (isCancellation(error, signal)) {
129
+ throw new RemoteError('gateway/cancelled', 'subagent model selection was cancelled', {}, { cause: error })
130
+ }
131
+ // LLM validation names the rejected provider, model, or effort.
132
+ if (error instanceof LlmError) {
133
+ throw new RemoteError('subagent/model-unavailable', error.message, { childSessionId }, { cause: error })
134
+ }
135
+ if (error instanceof SubagentError) {
136
+ switch (error.code) {
137
+ case 'MODEL_UNAVAILABLE':
138
+ throw new RemoteError(
139
+ 'subagent/model-unavailable', 'the selected subagent model is unavailable; choose another model or retry',
140
+ { childSessionId }, { cause: error },
141
+ )
142
+ case 'UNAUTHORIZED':
143
+ throw new RemoteError(
144
+ 'subagent/unauthorized', 'subagent model selection is not authorized',
145
+ { childSessionId }, { cause: error },
146
+ )
147
+ case 'NOT_RESUMABLE':
148
+ case 'UNSUPPORTED_CAPABILITY':
149
+ case 'NOT_CONTINUABLE':
150
+ throw new RemoteError(
151
+ 'subagent/not-resumable', 'subagent does not support model selection',
152
+ { childSessionId }, { cause: error },
153
+ )
154
+ case 'DRAINING':
155
+ case 'ACTIVATION_CLOSING':
156
+ case 'CONTINUATION_UNAVAILABLE':
157
+ case 'PERSISTENCE_UNAVAILABLE':
158
+ throw new RemoteError(
159
+ 'subagent/model-selection-unavailable', 'subagent model selection is temporarily unavailable',
160
+ { childSessionId }, { cause: error },
161
+ )
162
+ // Other backend failures do not expose provider details through Remote.
163
+ default:
164
+ break
165
+ }
166
+ }
167
+ throw new RemoteError('gateway/internal', 'subagent model selection failed', {}, { cause: error })
168
+ }
package/src/descriptor.ts CHANGED
@@ -2,8 +2,10 @@
2
2
  * The durable subagent-child descriptor: the versioned, model-hidden
3
3
  * `subagent/descriptor` session event that identifies every session-backed
4
4
  * subagent, including historical one-shot records. The manager appends each
5
- * continuable child's descriptor inside its initial turn, preserving the
6
- * declared composition required for cold resume.
5
+ * continuable child's descriptor during unpublished setup. Current records
6
+ * contain identity fields; model choices belong to the child's own
7
+ * `model/selection` events. Historical continuable records may also carry an
8
+ * initial route, persona, and tool restriction that cold resume reapplies.
7
9
  *
8
10
  * The descriptor deliberately snapshots explicit fields rather than the
9
11
  * merge-extensible `AgentOptions` object: an unrelated extension value cannot
@@ -14,14 +16,12 @@
14
16
  * to one activation's result contract rather than durable child composition.
15
17
  * Per-activation knobs such as `maxTokens` are omitted for the same reason as
16
18
  * `outputSchema`: they budget one activation. Cold resume requires the exact
17
- * live subagent tree root for authorization but reconstructs child options only from the
18
- * durable descriptor, so it neither restores the prior budget nor inherits
19
- * the parent's current one; the resumed route's defaults apply instead.
19
+ * live subagent tree root for authorization. It neither restores the prior budget
20
+ * nor inherits the parent's current one; the resumed route's defaults apply instead.
20
21
  *
21
22
  * @module @deepseek-ai/dsh-subagent/descriptor
22
23
  */
23
24
 
24
- import { snapshotJsonValue } from '@deepseek-ai/dsh-util-values'
25
25
  import type { SessionEvent } from '@deepseek-ai/dsh-session'
26
26
  import type { ReasoningEffortId } from '@deepseek-ai/dsh-llm'
27
27
  import type { ToolRestriction } from '@deepseek-ai/dsh-tools'
@@ -30,9 +30,9 @@ declare module '@deepseek-ai/dsh-session/types' {
30
30
  interface SessionEventMap {
31
31
  /**
32
32
  * Durable identity and lifecycle mode of a session-backed subagent child,
33
- * appended once inside the child's initial turn, before its first
34
- * request. Continuable records also carry their
35
- * resumable composition. Log-only: it carries no `surfaceOp`, never enters
33
+ * appended once when the child is established, before its first
34
+ * request. Historical continuable records may also carry their initial
35
+ * composition. Log-only: it carries no `surfaceOp`, never enters
36
36
  * model history, and survives compaction.
37
37
  */
38
38
  'subagent/descriptor': SubagentDescriptorData
@@ -68,7 +68,11 @@ export interface OneShotSubagentDescriptorData extends SubagentDescriptorBase {
68
68
  readonly label?: string
69
69
  }
70
70
 
71
- /** A session-backed subagent whose declared composition supports cold resume. */
71
+ /**
72
+ * A session-backed subagent that supports cold resume. Current writers record
73
+ * only the identity fields; the optional composition fields come from
74
+ * historical records and are reapplied on resume.
75
+ */
72
76
  export interface ContinuableSubagentDescriptorData extends SubagentDescriptorBase {
73
77
  readonly mode: 'continuable'
74
78
  /** The initial delegation's short `description`, used for durable enumeration. */
@@ -90,8 +94,8 @@ export type SubagentDescriptorData =
90
94
  | OneShotSubagentDescriptorData
91
95
  | ContinuableSubagentDescriptorData
92
96
 
93
- /** Continuable composition fields before the snapshot stamps their format version. */
94
- export type ContinuableSubagentDescriptorInput = Omit<ContinuableSubagentDescriptorData, 'version'>
97
+ /** Continuable identity fields before the writer stamps their format version. */
98
+ export type ContinuableSubagentDescriptorInput = Pick<ContinuableSubagentDescriptorData, 'mode' | 'provider' | 'label'>
95
99
 
96
100
  const DESCRIPTOR_BASE_KEYS = [
97
101
  'version',
@@ -222,30 +226,19 @@ function parseSubagentDescriptor(value: unknown): SubagentDescriptorData | undef
222
226
  }
223
227
 
224
228
  /**
225
- * Validate and detach a continuable descriptor input.
226
- * @param input - the caller-collected continuable composition fields.
227
- * @returns the versioned, detached continuable descriptor payload.
228
- * @throws when a field is not losslessly JSON-serializable.
229
+ * Build the current continuable child identity record.
230
+ * @param input - the caller-collected continuable identity fields.
231
+ * @returns the versioned continuable descriptor payload.
229
232
  */
230
233
  export function snapshotSubagentDescriptor(
231
234
  input: ContinuableSubagentDescriptorInput,
232
235
  ): ContinuableSubagentDescriptorData {
233
- const candidate: ContinuableSubagentDescriptorData = {
236
+ return {
234
237
  version: SUBAGENT_DESCRIPTOR_VERSION,
235
238
  mode: input.mode,
236
239
  provider: input.provider,
237
240
  label: input.label,
238
- ...input.agentProvider !== undefined ? { agentProvider: input.agentProvider } : {},
239
- ...input.agentModel !== undefined ? { agentModel: input.agentModel } : {},
240
- ...input.agentReasoningEffort !== undefined ? { agentReasoningEffort: input.agentReasoningEffort } : {},
241
- ...input.persona !== undefined ? { persona: input.persona } : {},
242
- ...input.toolFilter !== undefined ? { toolFilter: input.toolFilter } : {},
243
- }
244
- const snapshot = snapshotJsonValue(candidate)
245
- if (snapshot === undefined) {
246
- throw new Error('subagent descriptor is not losslessly JSON-serializable')
247
241
  }
248
- return snapshot
249
242
  }
250
243
 
251
244
  /**
package/src/error.ts CHANGED
@@ -31,6 +31,8 @@ export type SubagentErrorCode =
31
31
  | 'INVALID_MODEL_SELECTION_SETTINGS'
32
32
  /** The current Host model-selection setting does not authorize the requested child provider or route. */
33
33
  | 'MODEL_ROUTE_NOT_ALLOWED'
34
+ /** The child model choice is incomplete, or no LLM service can validate it; LLM validation failures keep their `LlmError` code. */
35
+ | 'MODEL_UNAVAILABLE'
34
36
  /** The requested LLM provider is not registered with the LLM runtime. */
35
37
  | 'LLM_PROVIDER_NOT_FOUND'
36
38
  /** The child's target model cannot accept image input. */
@@ -69,6 +71,8 @@ export type SubagentErrorCode =
69
71
  | 'CONTINUATION_UNAVAILABLE'
70
72
  /** Continuation needs Session persistence that is absent or failed. */
71
73
  | 'PERSISTENCE_UNAVAILABLE'
74
+ /** The selection may have changed. Reload the child before retrying. */
75
+ | 'PERSISTENCE_UNCONFIRMED'
72
76
  /** A requested agent name does not satisfy the naming rule. */
73
77
  | 'INVALID_AGENT_NAME'
74
78
  /** A requested agent name is already used by a sibling. */
package/src/index.ts CHANGED
@@ -37,19 +37,21 @@ import { brandString } from '@deepseek-ai/dsh-brand'
37
37
  import { scopeTarget } from '@deepseek-ai/dsh-scope'
38
38
  import type { Scoped } from '@deepseek-ai/dsh-scope'
39
39
  import { assertObjectJsonSchema } from '@deepseek-ai/dsh-tools'
40
- import type { ContentBlock, MessageId } from '@deepseek-ai/dsh-llm'
41
- import type { Agent } from '@deepseek-ai/dsh-agent'
40
+ import type { ContentBlock, MessageId, ReasoningEffortId } from '@deepseek-ai/dsh-llm'
41
+ import type { Agent, ModelSelection } from '@deepseek-ai/dsh-agent'
42
42
  import type { SessionId } from '@deepseek-ai/dsh-session'
43
43
  import { canonicalClientTimeZone } from '@deepseek-ai/dsh-util-time'
44
44
  import { Remote, RemoteError, TypertRemoteService, principalOf, type Principal } from '@deepseek-ai/dsh-typert-protocol'
45
45
  import {
46
- rejectPrompt, validateControlRequest,
46
+ rejectModelSelection, rejectPrompt, validateControlRequest,
47
47
  } from './control.ts'
48
48
  import type {
49
49
  SubagentInterruptReceipt,
50
50
  SubagentPromptReceipt,
51
51
  SubagentPromptRequest,
52
52
  SubagentPromptRequestId,
53
+ SubagentSelectModelReceipt,
54
+ SubagentSelectModelRequest,
53
55
  } from './control-types.ts'
54
56
  import type {
55
57
  SubagentCapabilities,
@@ -409,6 +411,28 @@ export class SubagentRuntime extends TypertRemoteService {
409
411
  this.manager?.interrupt(targetSessionId, authority)
410
412
  }
411
413
 
414
+ /**
415
+ * Record a local child's complete model choice for future steps without
416
+ * adding a message or changing user defaults. Selection and image admission
417
+ * share the child's operation order; an already prepared step retains its model.
418
+ * @param childId - durable continuable child Session id.
419
+ * @param selection - complete choice; omitted effort follows adapter defaults.
420
+ * @param authority - trusted user operation or exact live creation ancestor.
421
+ * @param signal - cancellation before selection is recorded.
422
+ * @returns the recorded choice after its durability barrier completes.
423
+ * @throws {LlmError} when the LLM runtime rejects the selected route or effort.
424
+ * @throws {SubagentError} when access or child availability fails;
425
+ * PERSISTENCE_UNCONFIRMED means the choice may have changed but durability is unknown.
426
+ */
427
+ async selectModel(
428
+ childId: SessionId,
429
+ selection: Readonly<ModelSelection>,
430
+ authority: SubagentInterruptAuthority,
431
+ signal: AbortSignal,
432
+ ): Promise<ModelSelection> {
433
+ return this.requireManager().selectModel(childId, selection, authority, signal)
434
+ }
435
+
412
436
  /**
413
437
  * Close admission and stop all instances in the selected subagent trees, then await
414
438
  * pending startup and cleanup. Ordinary members are ignored. The cutoff lasts
@@ -522,11 +546,50 @@ export class SubagentRuntime extends TypertRemoteService {
522
546
  try {
523
547
  this.interrupt(childSessionId, { kind: 'user' })
524
548
  } catch (error: unknown) {
525
- throw new RemoteError('gateway/internal', 'subagent interrupt failed', {}, { cause: error })
549
+ throw new RemoteError('gateway/internal', `subagent interrupt failed: ${String(error)}`, {}, { cause: error })
526
550
  }
527
551
  return { accepted: true }
528
552
  }
529
553
 
554
+ /**
555
+ * Select a local child's model under the caller's target-Session permission.
556
+ * Like Session model selection, it accepts only a model its provider lists in the
557
+ * current catalog. No message or global default is changed. A successful receipt
558
+ * confirms the child's persistence barrier; an unconfirmed failure may follow a live change.
559
+ * @param request - target and complete model choice; omitted effort uses adapter defaults.
560
+ * @param signal - caller cancellation before selection is recorded.
561
+ * @returns the recorded choice after confirmed persistence.
562
+ * @throws {RemoteError} validation, authorization, availability, cancellation,
563
+ * or subagent/model-selection-unconfirmed when the durable outcome is unknown.
564
+ */
565
+ @Remote({ name: 'selectModelByUser', resources: { session: request => request.childSessionId } })
566
+ async selectModelByUser(request: SubagentSelectModelRequest, signal: AbortSignal): Promise<SubagentSelectModelReceipt> {
567
+ validateControlRequest('subagent.selectModel', request)
568
+ const selection: ModelSelection = {
569
+ provider: request.provider,
570
+ model: request.model,
571
+ ...request.reasoningEffort === undefined ? {} : { reasoningEffort: brandString<ReasoningEffortId>(request.reasoningEffort) },
572
+ }
573
+ try {
574
+ await this.assertListedModel(selection)
575
+ const selected = await this.selectModel(request.childSessionId, selection, { kind: 'user' }, signal)
576
+ return { selected }
577
+ } catch (error: unknown) {
578
+ return rejectModelSelection(error, request.childSessionId, signal)
579
+ }
580
+ }
581
+
582
+ /** Refuse a user choice that the provider catalog does not list. */
583
+ private async assertListedModel(selection: ModelSelection): Promise<void> {
584
+ const llm = this.ctx.get('llm')
585
+ if (llm === undefined) {
586
+ throw new SubagentError('cannot validate the selected subagent model because the LLM service is unavailable', 'MODEL_UNAVAILABLE')
587
+ }
588
+ if (!await llm.isModelInCatalog(selection.provider, selection.model)) {
589
+ throw new SubagentError(`provider "${selection.provider}" does not list model "${selection.model}"`, 'MODEL_UNAVAILABLE')
590
+ }
591
+ }
592
+
530
593
  /**
531
594
  * Register a provider under its name. Registration is effect-scoped and HMR
532
595
  * safe; removing a provider blocks new starts but does not revoke runs that
package/src/lifecycle.ts CHANGED
@@ -9,8 +9,7 @@
9
9
 
10
10
  import type { Context } from '@deepseek-ai/cordis'
11
11
  import type { Agent } from '@deepseek-ai/dsh-agent'
12
- import { foldConsumedWork } from '@deepseek-ai/dsh-agent'
13
- import type { SessionEvent } from '@deepseek-ai/dsh-session'
12
+ import type { ConsumedWork } from '@deepseek-ai/dsh-agent'
14
13
  import type { SubagentResult, SubagentRunEndInfo, SubagentRunInfo } from './types.ts'
15
14
 
16
15
  /**
@@ -69,17 +68,17 @@ export function createLifecycleEmitter(
69
68
  * token ceiling, or was cancelled, so deriving the reason from disposal would
70
69
  * report failed work as completed.
71
70
  *
72
- * {@link foldConsumedWork} supplies both halves the raw turn sequence cannot:
71
+ * `foldConsumedWork` supplies both halves the raw turn sequence cannot:
73
72
  * which turn accounts for the work this epoch consumed, and whether accepted
74
73
  * work was cancelled after it without any turn opening over it. A recorded
75
74
  * failure still wins over a cancellation — stopping a child that had already
76
75
  * failed does not turn its failure into a cancellation.
77
- * @param events - this epoch's own event suffix.
76
+ * @param work - the consumed-work account of this epoch's own events.
78
77
  * @returns its terminal stop reason; `completed` only for an epoch that both
79
78
  * closed cleanly and had nothing left to run.
80
79
  */
81
- export function epochStopReason(events: readonly SessionEvent[]): SubagentResult['stopReason'] {
82
- const { end, droppedUnrun } = foldConsumedWork(events)
80
+ export function epochStopReason(work: ConsumedWork): SubagentResult['stopReason'] {
81
+ const { end, droppedUnrun } = work
83
82
  switch (end?.data.reason.kind) {
84
83
  case 'max-tokens':
85
84
  return 'max-tokens'