@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
@@ -59,6 +59,7 @@ var __disposeResources = (this && this.__disposeResources) || (function (Suppres
59
59
  });
60
60
  import { randomUUID } from 'node:crypto';
61
61
  import { isAbsolute, resolve } from 'node:path';
62
+ import { isDeepStrictEqual } from 'node:util';
62
63
  import { brandString } from '@deepseek-ai/dsh-brand';
63
64
  import { contentHasImage, createUserMessage, errorChain } from '@deepseek-ai/dsh-llm';
64
65
  import { SessionLogOffset } from '@deepseek-ai/dsh-session';
@@ -68,9 +69,11 @@ import { installSubagentArchiveAdmission } from "./archive-admission.js";
68
69
  import { foldSubagentDescriptor, snapshotSubagentDescriptor } from "./descriptor.js";
69
70
  import { catalogNames, establishCatalogChild, establishExternalCatalogChild } from "./catalog.js";
70
71
  import { SubagentError } from "./error.js";
72
+ import { requireInitialModel, restorationOptions } from "./model-selection.js";
71
73
  import { ROOT_AGENT_NAME, SiblingNameReservations, agentAddress, joinAgentPath, parentAgentPath } from "./names.js";
72
74
  import { attachStructuredRuntime } from "./structured.js";
73
- import { ActivationPool, ChildLock, activationAgent, captureLocalResult, observeLocalFailure, requireLocalActivation } from "./activation.js";
75
+ import { ActivationPool, ChildLock, activationAgent, captureLocalResult, foldLocalResult, observeLocalFailure, requireLocalActivation } from "./activation.js";
76
+ import { AssistantOutputFold } from "./assistant-output.js";
74
77
  /** Render only the safe outer message from execution or teardown failures. */
75
78
  function failureMessage(error) {
76
79
  return error instanceof Error ? error.message : 'unknown teardown failure';
@@ -108,6 +111,14 @@ export class SubagentManager {
108
111
  // Drain managed instances before Cordis releases their owning scope.
109
112
  const scope = ctx.plugin(function activationOwner() { });
110
113
  this.ownerCtx = scope.ctx;
114
+ // This scope outlives every activation, including one whose child was
115
+ // disposed by another owner and has already released its own listeners.
116
+ // Global, because a child may run under a scope this manager is not in.
117
+ scope.ctx.on('session/event', (session, event) => {
118
+ const activation = this.resident.get(session.id);
119
+ if (activation?.kind === 'local' && activation.handle.agent.session === session)
120
+ foldLocalResult(activation, event);
121
+ }, { global: true });
111
122
  installSubagentArchiveAdmission(ctx, (agent) => {
112
123
  const activation = this.resident.get(agent.id);
113
124
  return activation !== undefined && activationAgent(activation) === agent ? activation.ancestors : undefined;
@@ -123,7 +134,16 @@ export class SubagentManager {
123
134
  });
124
135
  ctx.effect(function* () {
125
136
  yield scope.dispose;
126
- yield () => this.drain();
137
+ // A rejected drain skips the disposers yielded before it, which would
138
+ // leave the scope's global listener on the session/event dispatch.
139
+ yield async () => {
140
+ try {
141
+ await this.drain();
142
+ }
143
+ finally {
144
+ await scope.dispose();
145
+ }
146
+ };
127
147
  }.bind(this), 'subagents.manager()');
128
148
  }
129
149
  /**
@@ -260,23 +280,20 @@ export class SubagentManager {
260
280
  const childId = spec.childId ?? brandString(randomUUID());
261
281
  this.assertChildIdAvailable(childId);
262
282
  const childDepth = resolveChildDepth(parent, spec.maxDepth);
263
- // Snapshot before any await: invalid descriptor JSON rejects the call
264
- // before a child exists, and the detached value is what reaches the log.
265
283
  const agentOptions = resolveChildAgentOptions(parent, spec.agentOptions, childDepth);
266
- const agentProvider = agentOptions.provider;
267
- const agentModel = agentOptions.model;
268
- const agentReasoningEffort = agentOptions.reasoningEffort;
284
+ const initialModel = requireInitialModel(agentOptions);
269
285
  const descriptor = snapshotSubagentDescriptor({
270
286
  mode: 'continuable',
271
287
  provider: spec.provider,
272
288
  label: spec.label,
273
- ...agentProvider !== undefined ? { agentProvider } : {},
274
- ...agentModel !== undefined ? { agentModel } : {},
275
- ...agentReasoningEffort !== undefined ? { agentReasoningEffort } : {},
276
289
  });
277
290
  // Capture before the first await: a later parent switch belongs to the
278
291
  // parent's future, not to this child.
279
292
  const delegatedPolicies = captureDelegatedPolicyOverrides(parent);
293
+ if (spec.agentOptions?.provider !== undefined || spec.agentOptions?.model !== undefined
294
+ || spec.agentOptions?.reasoningEffort !== undefined) {
295
+ await this.validateModelSelection(parent.ctx, initialModel, signal);
296
+ }
280
297
  const cwd = await this.resolveDirectory(spec, signal);
281
298
  const prepared = await prepare({
282
299
  sessionId: childId,
@@ -316,6 +333,7 @@ export class SubagentManager {
316
333
  inheritedEventCount,
317
334
  delegatedPolicies,
318
335
  descriptor,
336
+ initialModel,
319
337
  },
320
338
  agentOptions,
321
339
  composition: { agentPreset: spec.agentPreset },
@@ -560,9 +578,179 @@ export class SubagentManager {
560
578
  }
561
579
  return this.deliverToMember(root, childId, content, options);
562
580
  }
581
+ /**
582
+ * Record a child's next selection without running it or changing user defaults.
583
+ * A cold child is restored for maintenance only: it holds no capacity slot,
584
+ * publishes no lifecycle events, admits no input, and closes before return.
585
+ * @param childId - durable continuable child Session id.
586
+ * @param selection - complete selection; omitted effort follows adapter defaults.
587
+ * @param authority - trusted user operation or exact live creation ancestor.
588
+ * @param signal - cancellation before selection is recorded.
589
+ * @returns the recorded selection after its durability barrier completes.
590
+ */
591
+ async selectModel(childId, selection, authority, signal) {
592
+ signal.throwIfAborted();
593
+ const selected = { ...selection };
594
+ const ancestry = this.resident.get(childId);
595
+ let root;
596
+ let ancestors;
597
+ if (ancestry !== undefined) {
598
+ ;
599
+ ({ root, ancestors } = ancestry);
600
+ }
601
+ else {
602
+ const env_3 = { stack: [], error: void 0, hasError: false };
603
+ try {
604
+ const source = __addDisposableResource(env_3, await this.observeContinuation(childId, signal), false);
605
+ ({ root, ancestors } = await this.resolveCreationAncestry(source, signal));
606
+ }
607
+ catch (e_3) {
608
+ env_3.error = e_3;
609
+ env_3.hasError = true;
610
+ }
611
+ finally {
612
+ __disposeResources(env_3);
613
+ }
614
+ }
615
+ this.authorizeSelection(childId, root, ancestors, authority);
616
+ return this.trackStartup(root, signal, async (signal) => {
617
+ while (true) {
618
+ const result = await this.locks.run(childId, async () => {
619
+ signal.throwIfAborted();
620
+ this.authorizeSelection(childId, root, ancestors, authority);
621
+ const activation = this.resident.get(childId);
622
+ if (activation === undefined) {
623
+ await this.validateModelSelection(this.ctx, selected, signal);
624
+ const restored = await this.restoreTarget(root, childId, signal, selected);
625
+ await this.selectWhileMaintained(restored, selected, root, authority);
626
+ return { selected };
627
+ }
628
+ if (activation.root !== root)
629
+ throw new SubagentError('target belongs to another subagent tree', 'UNAUTHORIZED');
630
+ const { handle } = requireLocalActivation(activation);
631
+ await this.validateModelSelection(this.ctx, selected, signal);
632
+ signal.throwIfAborted();
633
+ this.authorizeSelection(childId, root, activation.ancestors, authority);
634
+ if (activation.closing !== undefined)
635
+ return { closing: activation.closing };
636
+ await this.recordSelection(handle.agent, selected);
637
+ return { selected };
638
+ });
639
+ if ('selected' in result)
640
+ return result.selected;
641
+ await Promise.allSettled([result.closing]);
642
+ }
643
+ });
644
+ }
645
+ /** Recheck exact caller identities after asynchronous validation and storage work. */
646
+ authorizeSelection(childId, root, ancestors, authority) {
647
+ this.assertAdmitting(root);
648
+ if (authority.kind === 'user')
649
+ return;
650
+ const caller = authority.agent;
651
+ if (caller.id === childId || this.rootOf(caller) !== root || !ancestors.includes(caller.id)) {
652
+ throw new SubagentError(`subagent "${childId}" is not a descendant of the selecting agent`, 'UNAUTHORIZED');
653
+ }
654
+ this.assertAdmitting(caller);
655
+ }
656
+ /** Validate a choice without persisting adapter-defaulted controls; LLM failures keep their class and code. */
657
+ async validateModelSelection(ctx, selection, signal) {
658
+ const llm = ctx.get('llm');
659
+ if (llm === undefined) {
660
+ throw new SubagentError('cannot validate the selected subagent model because the LLM service is unavailable', 'MODEL_UNAVAILABLE');
661
+ }
662
+ try {
663
+ await llm.resolveCallConfig(selection, signal);
664
+ }
665
+ catch (error) {
666
+ signal.throwIfAborted();
667
+ throw error;
668
+ }
669
+ }
670
+ /**
671
+ * Record a choice through a maintenance restoration and begin its release
672
+ * from the idle phase it owns. Input that reaches the Agent meanwhile cannot
673
+ * start a turn, and the release cancels it. A restored Agent that an
674
+ * `agent/created` listener already woke rejects the choice with
675
+ * `CONTINUATION_UNAVAILABLE`, and the release cancels the started turn.
676
+ */
677
+ async selectWhileMaintained(activation, selection, root, authority) {
678
+ let closed;
679
+ const close = () => closed ??= this.close(activation, () => this.finishDisposal(activation, false));
680
+ try {
681
+ const { agent } = requireLocalActivation(activation).handle;
682
+ let maintained;
683
+ try {
684
+ maintained = agent.runMaintenance(async () => {
685
+ try {
686
+ this.authorizeSelection(activation.childId, root, activation.ancestors, authority);
687
+ await this.recordSelection(agent, selection);
688
+ }
689
+ finally {
690
+ // Begin release while this task owns the idle phase; the outer finally observes its outcome.
691
+ void close().catch(() => undefined);
692
+ }
693
+ });
694
+ }
695
+ catch (error) {
696
+ // Restoration ends its own maintenance first, so a wake requested during `agent/created` starts a turn.
697
+ throw new SubagentError(`subagent "${activation.childId}" received input while restored for model selection; continue it before changing its model`, 'CONTINUATION_UNAVAILABLE', { cause: error });
698
+ }
699
+ await maintained;
700
+ }
701
+ finally {
702
+ try {
703
+ await close();
704
+ }
705
+ catch (error) {
706
+ // The selection outcome is already settled; release failure is reported separately.
707
+ this.reportTeardownFailure(activation, error);
708
+ }
709
+ }
710
+ }
711
+ /** Append a choice through the child's live Session and confirm it in the durable log. */
712
+ async recordSelection(agent, selection) {
713
+ const persistence = this.requirePersistence();
714
+ const session = agent.session;
715
+ const before = session.seq;
716
+ try {
717
+ const env_4 = { stack: [], error: void 0, hasError: false };
718
+ try {
719
+ agent.model.select(selection);
720
+ const appended = session.seq > before;
721
+ const recordedSeq = appended ? before : session.seq - 1;
722
+ if (!await agent.ctx.sessions.flush(session)) {
723
+ throw new Error('no Session durability listener participated');
724
+ }
725
+ const stored = __addDisposableResource(env_4, await persistence.open(agent.id, 'read'), true);
726
+ const { events } = await stored.read(recordedSeq, 1);
727
+ const event = events[0];
728
+ if (!isDeepStrictEqual(stored.header, session.header) || event?.seq !== recordedSeq
729
+ || (appended && (event.type !== 'model/selection' || !isDeepStrictEqual(event.data, selection)))) {
730
+ throw new Error('the recorded selection is not present in the durable child log');
731
+ }
732
+ }
733
+ catch (e_4) {
734
+ env_4.error = e_4;
735
+ env_4.hasError = true;
736
+ }
737
+ finally {
738
+ const result_1 = __disposeResources(env_4);
739
+ if (result_1)
740
+ await result_1;
741
+ }
742
+ }
743
+ catch (error) {
744
+ throw this.selectionPersistenceFailure(agent.id, error);
745
+ }
746
+ }
747
+ /** Preserve an uncertain durable outcome instead of reporting that no change occurred. */
748
+ selectionPersistenceFailure(childId, error) {
749
+ return new SubagentError(`model selection for subagent "${childId}" may have changed, but persistence could not be confirmed; reload its state before retrying`, 'PERSISTENCE_UNCONFIRMED', { cause: error });
750
+ }
563
751
  /** Admit local input synchronously before any teardown can begin. */
564
752
  deliver(activation, message, delivery) {
565
- if (activation.closing !== undefined) {
753
+ if (activation.closing !== undefined || activation.maintenance) {
566
754
  throw new SubagentError('subagent activation is being disposed; the message was not accepted', 'ACTIVATION_CLOSING');
567
755
  }
568
756
  const local = requireLocalActivation(activation);
@@ -629,8 +817,10 @@ export class SubagentManager {
629
817
  materialize(inputs) {
630
818
  this.assertAdmitting(inputs.root);
631
819
  inputs.signal.throwIfAborted();
632
- const pool = this.rootPool(inputs.root);
633
- const releaseSlot = pool.reserve(this.maxActiveSubagents());
820
+ // Maintenance runs no work, so it does not compete for execution capacity.
821
+ const releaseSlot = inputs.kind === 'local' && inputs.maintenance === true
822
+ ? () => { }
823
+ : this.rootPool(inputs.root).reserve(this.maxActiveSubagents());
634
824
  return this.materializeTracked(inputs, releaseSlot).catch((error) => {
635
825
  releaseSlot();
636
826
  throw error;
@@ -753,6 +943,7 @@ export class SubagentManager {
753
943
  child.session.append('agent-preset/selected', { agentPreset: inputs.composition.agentPreset });
754
944
  }
755
945
  child.session.append('subagent/descriptor', create.descriptor);
946
+ child.session.append('model/selection', create.initialModel);
756
947
  appendDelegatedPolicyOverrides(child.session, create.delegatedPolicies);
757
948
  const workingDirectory = childCtx.get('workingDirectory');
758
949
  if (workingDirectory === undefined) {
@@ -788,7 +979,10 @@ export class SubagentManager {
788
979
  resource = {
789
980
  kind: 'local',
790
981
  handle,
791
- outputStart: handle.agent.session.seq,
982
+ output: new AssistantOutputFold(),
983
+ work: undefined,
984
+ outputFailure: undefined,
985
+ workFailure: undefined,
792
986
  structured,
793
987
  failureAt: undefined,
794
988
  poke: Promise.withResolvers(),
@@ -809,6 +1003,7 @@ export class SubagentManager {
809
1003
  result: Promise.withResolvers(),
810
1004
  closing: undefined,
811
1005
  accepted: false,
1006
+ maintenance: inputs.kind === 'local' && inputs.maintenance === true,
812
1007
  };
813
1008
  void activation.result.promise.catch(() => undefined);
814
1009
  this.resident.set(childId, activation);
@@ -836,7 +1031,8 @@ export class SubagentManager {
836
1031
  }
837
1032
  // Listeners may read the resident Agent or drain it immediately. Publish
838
1033
  // after residency and inbox listeners, as the last rollback-protected step.
839
- this.host.emitLifecycle('subagent/start', this.runInfo(activation), root);
1034
+ if (!activation.maintenance)
1035
+ this.host.emitLifecycle('subagent/start', this.runInfo(activation), root);
840
1036
  }
841
1037
  catch (error) {
842
1038
  /* v8 ignore next -- rollback failure must not mask the admission failure
@@ -1019,11 +1215,13 @@ export class SubagentManager {
1019
1215
  this.notifySettlement(activation, result);
1020
1216
  // The sole end publication follows resource release and parent notification,
1021
1217
  // before result delivery.
1022
- this.host.emitLifecycle('subagent/end', {
1023
- ...this.runInfo(activation),
1024
- stopReason: terminal.stopReason,
1025
- ...terminal.output.length === 0 ? {} : { lastAssistantMessage: terminal.output },
1026
- }, activation.root);
1218
+ if (!activation.maintenance) {
1219
+ this.host.emitLifecycle('subagent/end', {
1220
+ ...this.runInfo(activation),
1221
+ stopReason: terminal.stopReason,
1222
+ ...terminal.output.length === 0 ? {} : { lastAssistantMessage: terminal.output },
1223
+ }, activation.root);
1224
+ }
1027
1225
  if (resultFailure === undefined)
1028
1226
  activation.result.resolve(result);
1029
1227
  else
@@ -1121,12 +1319,20 @@ export class SubagentManager {
1121
1319
  throw new SubagentError(`subagent "${childId}" is unavailable`, 'NOT_RESUMABLE', { cause: error });
1122
1320
  }
1123
1321
  }
1124
- /** Reconstruct only the target under its subagent tree root; the caller owns acceptance or rollback. */
1125
- async restoreTarget(root, childId, signal) {
1322
+ /**
1323
+ * Reconstruct only the target under its subagent tree root; the caller owns
1324
+ * acceptance or rollback. A selection restores it for maintenance instead.
1325
+ * @param root - exact live subagent tree root that owns the child.
1326
+ * @param childId - durable continuable child Session id.
1327
+ * @param signal - cancellation through publication.
1328
+ * @param maintenanceSelection - choice being recorded; it also supplies the route of a child that has none.
1329
+ * @returns the published Activation.
1330
+ */
1331
+ async restoreTarget(root, childId, signal, maintenanceSelection) {
1126
1332
  return this.trackStartup(root, signal, async (signal) => {
1127
- const env_3 = { stack: [], error: void 0, hasError: false };
1333
+ const env_5 = { stack: [], error: void 0, hasError: false };
1128
1334
  try {
1129
- const source = __addDisposableResource(env_3, await this.observeContinuation(childId, signal), false);
1335
+ const source = __addDisposableResource(env_5, await this.observeContinuation(childId, signal), false);
1130
1336
  this.assertAdmitting(root);
1131
1337
  const ownEvents = source.events.slice(source.inheritedEventCount);
1132
1338
  let descriptor;
@@ -1140,6 +1346,13 @@ export class SubagentManager {
1140
1346
  throw new SubagentError(`subagent "${childId}" has no supported continuation state and cannot be resumed; choose a different target`, 'NOT_RESUMABLE');
1141
1347
  }
1142
1348
  const { ancestors, path } = await this.resolveCreationAncestry(source, signal, root);
1349
+ // Releasing a maintenance restoration cancels queued input, so leave pending input to an execution.
1350
+ const pending = source.projections?.values.inbox;
1351
+ if (maintenanceSelection !== undefined && pending !== undefined
1352
+ && pending['next-turn'].length + pending['next-step'].length > 0) {
1353
+ throw new SubagentError(`subagent "${childId}" has pending input; continue it before changing its model`, 'CONTINUATION_UNAVAILABLE');
1354
+ }
1355
+ const agentOptions = restorationOptions(descriptor, source.projections?.values.modelSelection?.next, maintenanceSelection);
1143
1356
  let activation;
1144
1357
  try {
1145
1358
  const projectedPreset = source.projections?.values.agentPreset;
@@ -1154,19 +1367,14 @@ export class SubagentManager {
1154
1367
  root,
1155
1368
  ancestors,
1156
1369
  path,
1157
- agentOptions: {
1158
- ...descriptor.agentProvider !== undefined ? { provider: descriptor.agentProvider } : {},
1159
- ...descriptor.agentModel !== undefined ? { model: descriptor.agentModel } : {},
1160
- ...descriptor.agentReasoningEffort !== undefined
1161
- ? { reasoningEffort: brandString(descriptor.agentReasoningEffort) }
1162
- : {},
1163
- },
1370
+ agentOptions,
1164
1371
  composition: {
1165
1372
  agentPreset: agentPreset ?? undefined,
1166
1373
  persona: descriptor.persona,
1167
1374
  toolFilter: descriptor.toolFilter,
1168
1375
  },
1169
1376
  signal,
1377
+ maintenance: maintenanceSelection !== undefined,
1170
1378
  });
1171
1379
  }
1172
1380
  catch (error) {
@@ -1177,12 +1385,12 @@ export class SubagentManager {
1177
1385
  }
1178
1386
  return activation;
1179
1387
  }
1180
- catch (e_3) {
1181
- env_3.error = e_3;
1182
- env_3.hasError = true;
1388
+ catch (e_5) {
1389
+ env_5.error = e_5;
1390
+ env_5.hasError = true;
1183
1391
  }
1184
1392
  finally {
1185
- __disposeResources(env_3);
1393
+ __disposeResources(env_5);
1186
1394
  }
1187
1395
  });
1188
1396
  }
@@ -1225,11 +1433,12 @@ export class SubagentManager {
1225
1433
  options.onAccepted?.();
1226
1434
  return message.id;
1227
1435
  }
1228
- /** Refuse image content for a child whose fixed model accepts text only. */
1436
+ /** Refuse image content for the selection held through inbox admission. */
1229
1437
  async assertImageCapable(agent, signal) {
1230
- const { provider, model } = agent.options;
1231
- if (provider === undefined || model === undefined)
1438
+ const selection = agent.model.current();
1439
+ if (selection === undefined)
1232
1440
  return;
1441
+ const { provider, model } = selection;
1233
1442
  const llm = this.ctx.get('llm');
1234
1443
  /* v8 ignore next -- without an LLM registry, delivery defers to projection. */
1235
1444
  if (llm === undefined)