@dsmm/dsmm 0.3.21 → 0.3.23

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 (95) hide show
  1. package/README.md +4 -4
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +1 -7
  3. package/agent-presets/dsmm-clarifier/agent.cordis.yml +1 -7
  4. package/agent-presets/dsmm-code-search/agent.cordis.yml +1 -7
  5. package/agent-presets/dsmm-coding/agent.cordis.yml +1 -7
  6. package/agent-presets/dsmm-complex/agent.cordis.yml +1 -7
  7. package/agent-presets/dsmm-creative/agent.cordis.yml +1 -7
  8. package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +1 -7
  9. package/agent-presets/dsmm-deep/agent.cordis.yml +1 -7
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +1 -7
  11. package/agent-presets/dsmm-documenting/agent.cordis.yml +1 -7
  12. package/agent-presets/dsmm-frontend/agent.cordis.yml +1 -7
  13. package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +1 -7
  14. package/agent-presets/dsmm-media-reader/agent.cordis.yml +1 -7
  15. package/agent-presets/dsmm-normal-task/agent.cordis.yml +1 -7
  16. package/agent-presets/dsmm-oracle/agent.cordis.yml +1 -7
  17. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +1 -7
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +1 -7
  19. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +1 -7
  20. package/agent-presets/dsmm-planner/agent.cordis.yml +1 -7
  21. package/agent-presets/dsmm-quick/agent.cordis.yml +1 -7
  22. package/agent-presets/dsmm-research/agent.cordis.yml +1 -7
  23. package/agent-presets/dsmm-reviewer/agent.cordis.yml +1 -7
  24. package/cordis.patch.yml +3 -0
  25. package/docs/compatibility.md +13 -1
  26. package/docs/maintenance.md +26 -7
  27. package/docs/model-routing.md +25 -3
  28. package/docs/native-permissions.md +20 -4
  29. package/docs/releasing.md +3 -3
  30. package/docs/roadmap.md +40 -8
  31. package/docs/runtime-recovery.md +5 -3
  32. package/docs/testing.md +10 -0
  33. package/docs/web-fetch-fakeip.md +8 -2
  34. package/dsh-plugin.json +1 -1
  35. package/lib/agent-prompt-scope.d.ts +6 -0
  36. package/lib/agent-prompt-scope.js +66 -0
  37. package/lib/client/RoleToolView-data.d.ts +4 -2
  38. package/lib/client/RoleToolView-data.js +18 -4
  39. package/lib/client/RoleToolView-locales.d.ts +4 -0
  40. package/lib/client/RoleToolView-locales.js +2 -0
  41. package/lib/client/RoleToolView.d.ts +9 -3
  42. package/lib/client/RoleToolView.js +27 -8
  43. package/lib/client/children-locales.d.ts +4 -4
  44. package/lib/client/index.js +6 -1
  45. package/lib/client/role-call-observations.d.ts +21 -0
  46. package/lib/client/role-call-observations.js +150 -0
  47. package/lib/client.js +401 -96
  48. package/lib/dsh-types.d.ts +15 -0
  49. package/lib/index.js +4 -1
  50. package/lib/live-pi-ai-owner.d.ts +1 -2
  51. package/lib/live-pi-ai-owner.js +10 -7
  52. package/lib/locale-guidance.d.ts +3 -0
  53. package/lib/locale-guidance.js +12 -0
  54. package/lib/model-family.d.ts +14 -0
  55. package/lib/model-family.js +138 -35
  56. package/lib/model-routing.d.ts +23 -2
  57. package/lib/model-routing.js +145 -7
  58. package/lib/native-admission.d.ts +36 -1
  59. package/lib/native-admission.js +408 -24
  60. package/lib/native-pi-ai-wire.js +17 -4
  61. package/lib/profile-remote.d.ts +2 -0
  62. package/lib/profile-remote.js +12 -3
  63. package/lib/profile-types.d.ts +5 -0
  64. package/lib/prompts.d.ts +3 -2
  65. package/lib/prompts.js +20 -38
  66. package/lib/role-control-remote.d.ts +5 -2
  67. package/lib/role-control-remote.js +84 -4
  68. package/lib/role-control-rpc.d.ts +8 -1
  69. package/lib/role-control-rpc.js +122 -50
  70. package/lib/role-control-types.d.ts +62 -1
  71. package/lib/role-control-types.js +3 -0
  72. package/lib/role-invocation.js +1 -1
  73. package/lib/role-llm-runtime.js +2 -2
  74. package/lib/role-routing.d.ts +27 -7
  75. package/lib/role-routing.js +129 -16
  76. package/lib/role-subagents.js +8 -23
  77. package/lib/runtime-recovery.js +23 -6
  78. package/lib/session-metadata.d.ts +13 -1
  79. package/lib/session-metadata.js +21 -1
  80. package/lib/web-fetch-address-policy.d.ts +6 -2
  81. package/lib/web-fetch-fakeip.d.ts +6 -0
  82. package/lib/web-fetch-fakeip.js +29 -2
  83. package/package.json +2 -2
  84. package/prompts/deepwork.md +0 -1
  85. package/prompts/source/deepwork/claude-opus-5.md +2 -8
  86. package/prompts/source/deepwork/codex.md +2 -8
  87. package/prompts/source/deepwork/gemini-4.md +1 -7
  88. package/prompts/source/deepwork/gemini.md +0 -6
  89. package/prompts/source/deepwork/glm.md +3 -10
  90. package/prompts/source/deepwork/gpt.md +16 -15
  91. package/prompts/source/deepwork/kimi.md +1 -7
  92. package/prompts/source/deepwork/planner.md +0 -4
  93. package/prompts/source/deepwork/swe-2.md +2 -8
  94. package/prompts/source/shared/dsh-host-contract.md +0 -1
  95. package/prompts/source/shared/locale.md +1 -6
package/lib/client.js CHANGED
@@ -2859,10 +2859,11 @@ function integer2(value, field, maximum = Number.MAX_SAFE_INTEGER) {
2859
2859
  if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0 || value > maximum) fail2(field);
2860
2860
  return value;
2861
2861
  }
2862
- function role2(value) {
2862
+ function parseDsmmRoleId(value) {
2863
2863
  if (typeof value !== "string" || !rolePattern.test(value)) fail2("role");
2864
2864
  return value;
2865
2865
  }
2866
+ var role2 = parseDsmmRoleId;
2866
2867
  function object(value, required, optional2 = []) {
2867
2868
  if (value === null || typeof value !== "object" || Array.isArray(value)) fail2("object");
2868
2869
  if (Object.getPrototypeOf(value) !== Object.prototype && Object.getPrototypeOf(value) !== null || Object.getOwnPropertySymbols(value).length || Object.values(Object.getOwnPropertyDescriptors(value)).some((property2) => !Object.hasOwn(property2, "value") || !property2.enumerable)) fail2("object");
@@ -3040,13 +3041,28 @@ function parseDsmmRoleRouteComparison(value) {
3040
3041
  return { childId: sessionId(row.childId), initialRoute: initialRoleRoute(row.initialRoute), liveRoute: liveRoleRoute(row.liveRoute) };
3041
3042
  }
3042
3043
  function parseDsmmInvocationView(value) {
3043
- const row = object(jsonData(value), ["role", "label", "level", "routeSource", "mode"], ["route", "runId", "childId", "jobId", "routeComparison"]);
3044
+ const row = object(jsonData(value), ["role", "label", "level", "routeSource", "mode"], ["route", "runId", "childId", "jobId", "routeComparison", "delivery", "phase", "stopReason"]);
3044
3045
  if (typeof row.level !== "string" || !["normal", "low", "high", "max"].includes(row.level) || !DSMM_ROUTE_SOURCES.includes(row.routeSource) || typeof row.mode !== "string" || !["one-shot", "continuable"].includes(row.mode)) fail2("invocation");
3046
+ if (Object.hasOwn(row, "delivery") && !["caller", "parent"].includes(row.delivery) || Object.hasOwn(row, "phase") && !["reserved", "active", "settled"].includes(row.phase) || Object.hasOwn(row, "stopReason") && !["completed", "aborted", "error", "max-tokens", "refusal"].includes(row.stopReason) || Object.hasOwn(row, "stopReason") && row.phase !== "settled") fail2("invocation lifecycle");
3045
3047
  const target = role2(row.role);
3046
3048
  if (target === "dsmm-orchestrator") fail2("invocation target");
3047
3049
  const routeComparison = Object.hasOwn(row, "routeComparison") ? parseDsmmRoleRouteComparison(row.routeComparison) : void 0;
3048
3050
  if (routeComparison !== void 0 && (!Object.hasOwn(row, "childId") || routeComparison.childId !== row.childId)) fail2("invocation routeComparison childId");
3049
- return { role: target, label: text2(row.label, "label", 120), level: row.level, routeSource: row.routeSource, mode: row.mode, ...optional(row, "route", modelRoute), ...optional(row, "runId", sessionId), ...optional(row, "childId", sessionId), ...optional(row, "jobId", sessionId), ...routeComparison === void 0 ? {} : { routeComparison } };
3051
+ return {
3052
+ role: target,
3053
+ label: text2(row.label, "label", 120),
3054
+ level: row.level,
3055
+ routeSource: row.routeSource,
3056
+ mode: row.mode,
3057
+ ...optional(row, "route", modelRoute),
3058
+ ...optional(row, "runId", sessionId),
3059
+ ...optional(row, "childId", sessionId),
3060
+ ...optional(row, "jobId", sessionId),
3061
+ ...routeComparison === void 0 ? {} : { routeComparison },
3062
+ ...Object.hasOwn(row, "delivery") ? { delivery: row.delivery } : {},
3063
+ ...Object.hasOwn(row, "phase") ? { phase: row.phase } : {},
3064
+ ...Object.hasOwn(row, "stopReason") ? { stopReason: row.stopReason } : {}
3065
+ };
3050
3066
  }
3051
3067
  function selectionState(value) {
3052
3068
  const item = object(value, ["selectedId", "appliedRevision", "selectionRevision"], ["sourceRevision", "refreshRequired"]);
@@ -9757,6 +9773,9 @@ function DeploymentPage(props) {
9757
9773
  }
9758
9774
 
9759
9775
  // src/role-control-types.ts
9776
+ var ROLE_CALL_PHASES = ["reserved", "active", "settled"];
9777
+ var ROLE_CALL_DELIVERIES = ["caller", "parent"];
9778
+ var ROLE_CALL_STOP_REASONS = ["completed", "aborted", "error", "max-tokens", "refusal"];
9760
9779
  var ROLE_CONTROL_DISABLED_REASONS = [
9761
9780
  "module-off",
9762
9781
  "role-disabled",
@@ -9860,6 +9879,84 @@ function child(value) {
9860
9879
  ...routeComparison === void 0 ? {} : { routeComparison }
9861
9880
  };
9862
9881
  }
9882
+ function callIdentity(value) {
9883
+ const valueText = text4(value, 512);
9884
+ if (valueText.length === 0) fail4();
9885
+ return valueText;
9886
+ }
9887
+ function observedRoute(value) {
9888
+ const row = object2(value, ["provider", "model"], ["reasoningEffort"]);
9889
+ const provider = text4(row.provider, 1024), model = text4(row.model, 4096);
9890
+ const reasoningEffort = Object.hasOwn(row, "reasoningEffort") ? text4(row.reasoningEffort, 128) : void 0;
9891
+ if (provider.length === 0 || model.length === 0 || reasoningEffort === "") fail4();
9892
+ return { provider, model, ...reasoningEffort === void 0 ? {} : { reasoningEffort } };
9893
+ }
9894
+ function observedInitialRoute(value) {
9895
+ const row = object2(value, ["status"], ["source", "route", "reason"]);
9896
+ if (row.status === "known") {
9897
+ object2(row, ["status", "source", "route"]);
9898
+ if (row.source !== "invocation-capture") fail4();
9899
+ return { status: "known", source: "invocation-capture", route: observedRoute(row.route) };
9900
+ }
9901
+ object2(row, ["status", "reason"]);
9902
+ if (row.status !== "unknown" || row.reason !== "missing-invocation-capture") fail4();
9903
+ return { status: "unknown", reason: "missing-invocation-capture" };
9904
+ }
9905
+ function observedActualRoute(value) {
9906
+ const row = object2(value, ["status"], ["source", "route", "reason"]);
9907
+ if (row.status === "known") {
9908
+ object2(row, ["status", "source", "route"]);
9909
+ if (row.source !== "own-native-request-header") fail4();
9910
+ return { status: "known", source: "own-native-request-header", route: observedRoute(row.route) };
9911
+ }
9912
+ object2(row, ["status", "reason"]);
9913
+ if (row.status !== "unknown" || !["no-own-request-header", "invalid-own-request-header", "not-observed"].includes(row.reason)) fail4();
9914
+ return { status: "unknown", reason: row.reason };
9915
+ }
9916
+ function roleCall(value) {
9917
+ const row = object2(value, ["parentSessionId", "parentAdmissionEpoch", "callId", "rootCallId", "childId", "role", "level", "routeSource", "initialRoute", "actualRoute", "phase", "delivery"], ["childAdmissionEpoch", "runId", "stopReason"]);
9918
+ const role3 = parseDsmmRoleId(row.role);
9919
+ if (role3 === "dsmm-orchestrator") fail4();
9920
+ const childId = identity(row.childId), initialRoute = observedInitialRoute(row.initialRoute), actualRoute = observedActualRoute(row.actualRoute);
9921
+ const phase = choice(row.phase, ROLE_CALL_PHASES), delivery = choice(row.delivery, ROLE_CALL_DELIVERIES);
9922
+ const stopReason = Object.hasOwn(row, "stopReason") ? choice(row.stopReason, ROLE_CALL_STOP_REASONS) : void 0;
9923
+ if (stopReason !== void 0 && phase !== "settled") fail4();
9924
+ return {
9925
+ parentSessionId: identity(row.parentSessionId),
9926
+ parentAdmissionEpoch: epoch2(row.parentAdmissionEpoch),
9927
+ ...Object.hasOwn(row, "childAdmissionEpoch") ? { childAdmissionEpoch: epoch2(row.childAdmissionEpoch) } : {},
9928
+ callId: callIdentity(row.callId),
9929
+ rootCallId: callIdentity(row.rootCallId),
9930
+ childId,
9931
+ ...Object.hasOwn(row, "runId") ? { runId: identity(row.runId) } : {},
9932
+ role: role3,
9933
+ level: choice(row.level, ["normal", "low", "high", "max"]),
9934
+ routeSource: choice(row.routeSource, DSMM_ROUTE_SOURCES),
9935
+ initialRoute,
9936
+ actualRoute,
9937
+ phase,
9938
+ delivery,
9939
+ ...stopReason === void 0 ? {} : { stopReason }
9940
+ };
9941
+ }
9942
+ function observationFrame(value) {
9943
+ const row = object2(value, ["type", "sessionId", "admissionEpoch"], ["calls", "call", "callId"]), sessionId2 = identity(row.sessionId), admissionEpoch = epoch2(row.admissionEpoch);
9944
+ if (row.type === "snapshot") {
9945
+ object2(row, ["type", "sessionId", "admissionEpoch", "calls"]);
9946
+ const calls = array(row.calls).map(roleCall);
9947
+ if (calls.some((call) => call.parentSessionId !== sessionId2 || call.parentAdmissionEpoch !== admissionEpoch) || new Set(calls.map((call) => call.callId)).size !== calls.length) fail4();
9948
+ return { type: "snapshot", sessionId: sessionId2, admissionEpoch, calls };
9949
+ }
9950
+ if (row.type === "update") {
9951
+ object2(row, ["type", "sessionId", "admissionEpoch", "call"]);
9952
+ const call = roleCall(row.call);
9953
+ if (call.parentSessionId !== sessionId2 || call.parentAdmissionEpoch !== admissionEpoch) fail4();
9954
+ return { type: "update", sessionId: sessionId2, admissionEpoch, call };
9955
+ }
9956
+ object2(row, ["type", "sessionId", "admissionEpoch", "callId"]);
9957
+ if (row.type !== "remove") fail4();
9958
+ return { type: "remove", sessionId: sessionId2, admissionEpoch, callId: callIdentity(row.callId) };
9959
+ }
9863
9960
  function snapshot3(value) {
9864
9961
  const row = object2(value, ["sessionId", "admissionEpoch", "children", "capabilities"]);
9865
9962
  const sessionId2 = identity(row.sessionId), admissionEpoch = epoch2(row.admissionEpoch), children = array(row.children).map(child);
@@ -9946,12 +10043,13 @@ var parseRoleControlPromptRequest = (value) => promptRequest(json(value));
9946
10043
  function codec3(symbol, parse3) {
9947
10044
  return { mode: "strict", typeSymbol: `@dsmm/dsmm#${symbol}`, create: () => ({ parse: (value) => parse3(json(value)) }) };
9948
10045
  }
9949
- function descriptor3(method, result, request) {
10046
+ function descriptor3(method, result, request, stream = false) {
9950
10047
  return {
9951
10048
  id: `@dsmm/dsmm-children#dsmmChildren/${method}`,
9952
10049
  service: "dsmmChildren",
9953
10050
  namespace: "dsmmChildren",
9954
10051
  method,
10052
+ ...stream ? { mode: "stream", cancellation: { parameter: "signal" } } : {},
9955
10053
  invocation: { kind: "direct" },
9956
10054
  parameters: [
9957
10055
  { name: "sessionId", wire: "sessionId", source: "json", codec: codec3("ChildControlSessionId", identity) },
@@ -9961,6 +10059,7 @@ function descriptor3(method, result, request) {
9961
10059
  };
9962
10060
  }
9963
10061
  var ROLE_CONTROL_REMOTE = { package: "@dsmm/dsmm-children", descriptors: [
10062
+ descriptor3("observe", codec3("RoleCallObservationFrame", observationFrame), void 0, true),
9964
10063
  descriptor3("describe", codec3("ChildSessionSnapshot", snapshot3)),
9965
10064
  descriptor3("descendants", codec3("RoleControlDescendantsSnapshot", descendants)),
9966
10065
  descriptor3("prompt", codec3("SubagentPromptReceipt", promptReceipt), codec3("SubagentPromptRequest", promptRequest)),
@@ -10053,10 +10152,27 @@ function actualRoleTool(toolName, meta, failed) {
10053
10152
  return void 0;
10054
10153
  }
10055
10154
  }
10155
+ function observedRoleTool(toolName, observation) {
10156
+ if (!(toolName === "dsmm_category" ? categories : roles).has(observation.role)) return void 0;
10157
+ return {
10158
+ role: observation.role,
10159
+ label: roleToolDisplay(observation.role),
10160
+ level: observation.level,
10161
+ routeSource: observation.routeSource,
10162
+ mode: "continuable",
10163
+ childId: observation.childId,
10164
+ ...observation.runId === void 0 ? {} : { runId: observation.runId },
10165
+ ...observation.initialRoute.status === "known" ? { route: { ...observation.initialRoute.route } } : {},
10166
+ routeComparison: { childId: observation.childId, initialRoute: observation.initialRoute, liveRoute: observation.actualRoute },
10167
+ delivery: observation.delivery,
10168
+ phase: observation.phase,
10169
+ ...observation.stopReason === void 0 ? {} : { stopReason: observation.stopReason }
10170
+ };
10171
+ }
10056
10172
  function roleToolDisplay(target) {
10057
10173
  return target.slice("dsmm-".length).split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
10058
10174
  }
10059
- function technicalTableRows(toolName, callId, rawArgs, meta, routeSource) {
10175
+ function technicalTableRows(toolName, callId, rawArgs, meta, routeSource, observation) {
10060
10176
  const rows = [];
10061
10177
  rows.push({ property: "toolName", value: toolName, isComplex: false });
10062
10178
  rows.push({ property: "callId", value: callId, isComplex: false });
@@ -10082,9 +10198,10 @@ function technicalTableRows(toolName, callId, rawArgs, meta, routeSource) {
10082
10198
  rows.push({ property: "meta", value: meta, isComplex: typeof meta === "object" });
10083
10199
  }
10084
10200
  }
10201
+ if (observation !== void 0) rows.push({ property: "observation", value: observation, isComplex: true });
10085
10202
  return rows;
10086
10203
  }
10087
- function technicalJsonData(toolName, callId, rawArgs, meta, routeSource) {
10204
+ function technicalJsonData(toolName, callId, rawArgs, meta, routeSource, observation) {
10088
10205
  const parsedArgs = roleToolArguments(rawArgs);
10089
10206
  const data = {
10090
10207
  toolName,
@@ -10094,9 +10211,8 @@ function technicalJsonData(toolName, callId, rawArgs, meta, routeSource) {
10094
10211
  data.routeSource = routeSource;
10095
10212
  }
10096
10213
  data.args = parsedArgs !== void 0 ? parsedArgs : rawArgs;
10097
- if (meta !== void 0 && meta !== null) {
10098
- data.meta = meta;
10099
- }
10214
+ if (meta !== void 0 && meta !== null) data.meta = meta;
10215
+ if (observation !== void 0) data.observation = observation;
10100
10216
  return data;
10101
10217
  }
10102
10218
 
@@ -10132,6 +10248,10 @@ var roleToolEn = {
10132
10248
  level: "Level",
10133
10249
  route: "Reported route",
10134
10250
  routeSource: "Route source",
10251
+ initialRoute: "Initial",
10252
+ actualRoute: "Actual",
10253
+ routeUnknown: "unknown",
10254
+ effortUnreported: "effort not reported",
10135
10255
  table: "Table",
10136
10256
  json: "JSON",
10137
10257
  viewMode: "View mode",
@@ -10168,6 +10288,10 @@ var roleToolZh = {
10168
10288
  level: "等级",
10169
10289
  route: "报告的路由",
10170
10290
  routeSource: "路由来源",
10291
+ initialRoute: "初始",
10292
+ actualRoute: "实际",
10293
+ routeUnknown: "未知",
10294
+ effortUnreported: "effort 未报告",
10171
10295
  table: "表格",
10172
10296
  json: "JSON",
10173
10297
  viewMode: "视图模式",
@@ -10213,16 +10337,26 @@ function RoleToolView(props) {
10213
10337
  const { t } = props;
10214
10338
  const raw = props.phase === "preparing" ? partial.preview : props.phase === "start" ? props.block.argsRaw : props.block.call?.argsRaw ?? "";
10215
10339
  const requested = partial?.requested ?? requestedRoleTool(props.toolName, raw);
10340
+ const observation = props.useRoleCalls((state2) => state2.calls.get(props.callId));
10216
10341
  const result = props.phase === "result" ? props.block : void 0;
10217
10342
  const failed = result !== void 0 && (result.isError || result.error != null);
10218
- const actual = result === void 0 ? void 0 : actualRoleTool(props.toolName, result.meta, failed);
10343
+ const persisted = result === void 0 ? void 0 : actualRoleTool(props.toolName, result.meta, failed);
10344
+ const observed = observation === void 0 ? void 0 : observedRoleTool(props.toolName, observation);
10345
+ const inactivePersisted = persisted === void 0 || persisted.phase === "settled" ? persisted : persisted.childId === void 0 ? { ...persisted, routeComparison: void 0 } : { ...persisted, routeComparison: {
10346
+ childId: persisted.childId,
10347
+ initialRoute: persisted.routeComparison?.initialRoute ?? (persisted.route === void 0 ? { status: "unknown", reason: "missing-invocation-capture" } : { status: "known", source: "invocation-capture", route: persisted.route }),
10348
+ liveRoute: { status: "unknown", reason: "not-observed" }
10349
+ } };
10350
+ const actual = persisted?.phase === "settled" ? persisted : observed ?? inactivePersisted;
10351
+ const comparison = actual?.routeComparison;
10219
10352
  const target = actual?.role ?? requested.target;
10220
10353
  const action2 = props.phase === "preparing" ? t("calling") : t("call");
10221
10354
  const targetLabel = target === void 0 ? t("unknownTarget") : roleToolDisplay(target);
10222
10355
  const rawDesc = requested.description?.trim();
10223
10356
  const singleLineDesc = rawDesc ? rawDesc.replace(/\s+/gu, " ") : void 0;
10224
10357
  const title = `${action2} ${targetLabel}`;
10225
- const state = result?.error?.code === "interrupted" ? "stopped" : failed ? "error" : result === void 0 ? props.phase === "preparing" ? "preparing" : "running" : actual?.jobId !== void 0 || actual?.mode === "continuable" ? "background" : "result";
10358
+ const observedStop = actual?.phase === "settled" ? actual.stopReason : void 0;
10359
+ const state = result?.error?.code === "interrupted" || observedStop === "aborted" ? "stopped" : failed || observedStop !== void 0 && observedStop !== "completed" ? "error" : result === void 0 ? props.phase === "preparing" ? "preparing" : "running" : actual?.delivery === "parent" && actual.phase !== "settled" ? "background" : "result";
10226
10360
  const isOngoing = state === "running" || props.phase === "preparing";
10227
10361
  const code = (value) => /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.CodeBlock, { code: value, copyLabel: t("copy"), copiedLabel: t("copied") });
10228
10362
  const [viewMode, setViewMode] = (0, import_react11.useState)("table");
@@ -10231,103 +10365,132 @@ function RoleToolView(props) {
10231
10365
  { value: "table", label: t("table") },
10232
10366
  { value: "json", label: t("json") }
10233
10367
  ];
10234
- const tableRows = technicalTableRows(props.toolName, props.callId, raw, result?.meta, actual?.routeSource);
10235
- const jsonData2 = technicalJsonData(props.toolName, props.callId, raw, result?.meta, actual?.routeSource);
10368
+ const tableRows = technicalTableRows(props.toolName, props.callId, raw, result?.meta, actual?.routeSource, observation);
10369
+ const jsonData2 = technicalJsonData(props.toolName, props.callId, raw, result?.meta, actual?.routeSource, observation);
10236
10370
  const roleDiffers = requested.target !== void 0 && actual !== void 0 && actual.role !== requested.target;
10237
10371
  const levelDiffers = requested.level !== void 0 && actual !== void 0 && actual.level !== requested.level;
10238
10372
  const showRequestedVsActual = roleDiffers || levelDiffers;
10373
+ const initialRoute = comparison?.initialRoute ?? (actual?.route === void 0 ? void 0 : { status: "known", source: "invocation-capture", route: actual.route });
10374
+ const actualRoute = comparison?.liveRoute;
10375
+ const routeLabel = (route3, missingEffort = false) => `${route3.provider}/${route3.model}${route3.reasoningEffort === void 0 ? missingEffort ? ` · ${t("effortUnreported")}` : "" : ` · ${route3.reasoningEffort}`}`;
10239
10376
  const collapsedContent = singleLineDesc ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
10240
10377
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "dsmm-role-sep", "aria-hidden": "true" }),
10241
10378
  /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "dsmm-role-summary", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.TextShimmer, { active: isOngoing, children: singleLineDesc }) })
10242
10379
  ] }) : void 0;
10243
10380
  const stateDotState = state === "error" ? "error" : state === "stopped" ? "warning" : result === void 0 ? "ongoing" : state === "background" ? "idle" : "done";
10244
- return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-tool", "data-dsmm-role-tool": props.toolName, "data-identity": actual === void 0 ? "requested" : "actual", "data-state": state, "data-expanded": expanded ? "true" : "false", children: [
10245
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
10246
- import_dsh_client_ui_primitives11.DisclosureRow,
10247
- {
10248
- title,
10249
- titleClassName: "dsmm-role-title",
10250
- rowClassName: "dsmm-role-heading",
10251
- contentClassName: "dsmm-role-text",
10252
- icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.IconAgentPresetOutlineRegular, { size: 14, className: "dsmm-role-icon" }),
10253
- collapsedContent,
10254
- keepContentWhenOpen: true,
10255
- running: isOngoing,
10256
- open: expanded,
10257
- expandable: true,
10258
- onToggle: toggle,
10259
- expandOnRowClick: true,
10260
- children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-body", children: [
10261
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "dsmm-role-identity", children: [
10262
- showRequestedVsActual ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
10263
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-dim", children: [
10264
- t("requested"),
10265
- ": "
10266
- ] }),
10267
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
10268
- requested.target === void 0 ? t("unknown") : roleToolDisplay(requested.target),
10269
- requested.level ? ` (${requested.level})` : ""
10381
+ return /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(
10382
+ "div",
10383
+ {
10384
+ className: "dsmm-role-tool",
10385
+ "data-dsmm-role-tool": props.toolName,
10386
+ "data-identity": actual === void 0 ? "requested" : "actual",
10387
+ "data-state": state,
10388
+ "data-delivery": actual?.delivery,
10389
+ "data-phase": actual?.phase,
10390
+ "data-expanded": expanded ? "true" : "false",
10391
+ children: [
10392
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(
10393
+ import_dsh_client_ui_primitives11.DisclosureRow,
10394
+ {
10395
+ title,
10396
+ titleClassName: "dsmm-role-title",
10397
+ rowClassName: "dsmm-role-heading",
10398
+ contentClassName: "dsmm-role-text",
10399
+ icon: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.IconAgentPresetOutlineRegular, { size: 14, className: "dsmm-role-icon" }),
10400
+ collapsedContent,
10401
+ keepContentWhenOpen: true,
10402
+ running: isOngoing,
10403
+ open: expanded,
10404
+ expandable: true,
10405
+ onToggle: toggle,
10406
+ expandOnRowClick: true,
10407
+ children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-body", children: [
10408
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("p", { className: "dsmm-role-identity", children: [
10409
+ showRequestedVsActual ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)(import_jsx_runtime13.Fragment, { children: [
10410
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-dim", children: [
10411
+ t("requested"),
10412
+ ": "
10413
+ ] }),
10414
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
10415
+ requested.target === void 0 ? t("unknown") : roleToolDisplay(requested.target),
10416
+ requested.level ? ` (${requested.level})` : ""
10417
+ ] }),
10418
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "dsmm-role-dim", children: " → " }),
10419
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-dim", children: [
10420
+ t("actual"),
10421
+ ": "
10422
+ ] }),
10423
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
10424
+ roleToolDisplay(actual.role),
10425
+ " (",
10426
+ actual.level,
10427
+ ")"
10428
+ ] })
10429
+ ] }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
10430
+ actual === void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-dim", children: [
10431
+ t("requested"),
10432
+ ": "
10433
+ ] }),
10434
+ actual !== void 0 ? roleToolDisplay(actual.role) : requested.target === void 0 ? t("unknownTarget") : roleToolDisplay(requested.target),
10435
+ (actual?.level ?? requested.level) !== void 0 && ` · ${actual?.level ?? requested.level}`,
10436
+ props.phase !== "preparing" && actual === void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-dim", children: [
10437
+ " · ",
10438
+ t("actualUnknown")
10439
+ ] })
10440
+ ] }),
10441
+ initialRoute !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-model", children: [
10442
+ " · ",
10443
+ t("initialRoute"),
10444
+ ": ",
10445
+ initialRoute.status === "known" ? routeLabel(initialRoute.route) : t("routeUnknown")
10446
+ ] }),
10447
+ actualRoute !== void 0 ? /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-model", children: [
10448
+ " · ",
10449
+ t("actualRoute"),
10450
+ ": ",
10451
+ actualRoute.status === "known" ? routeLabel(actualRoute.route, true) : t("routeUnknown")
10452
+ ] }) : props.phase !== "preparing" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-model", children: [
10453
+ " · ",
10454
+ t("actualRoute"),
10455
+ ": ",
10456
+ t("routeUnknown")
10457
+ ] })
10270
10458
  ] }),
10271
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "dsmm-role-dim", children: " → " }),
10272
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-dim", children: [
10273
- t("actual"),
10274
- ": "
10459
+ requested.description !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "dsmm-role-task", children: requested.description }),
10460
+ result?.error != null && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-failure", children: [
10461
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "dsmm-role-section-title", children: t("failure") }),
10462
+ code(JSON.stringify(result.error, null, 2))
10275
10463
  ] }),
10276
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
10277
- roleToolDisplay(actual.role),
10278
- " (",
10279
- actual.level,
10280
- ")"
10281
- ] })
10282
- ] }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { children: [
10283
- actual !== void 0 ? roleToolDisplay(actual.role) : requested.target === void 0 ? t("unknownTarget") : roleToolDisplay(requested.target),
10284
- (actual?.level ?? requested.level) !== void 0 && ` · ${actual?.level ?? requested.level}`,
10285
- result !== void 0 && actual === void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-dim", children: [
10286
- " · ",
10287
- t("actualUnknown")
10464
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("details", { className: "dsmm-role-details", children: [
10465
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("summary", { children: t("technicalDetails") }),
10466
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-details-body", children: [
10467
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "dsmm-role-details-header", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.SegmentedControl, { id: controlId, value: viewMode, options: viewOptions, onChange: setViewMode, label: t("viewMode"), className: "dsmm-role-view-switch" }) }),
10468
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { id: `${controlId}-table-panel`, role: "tabpanel", "aria-labelledby": `${controlId}-table`, hidden: viewMode !== "table", tabIndex: 0, children: viewMode === "table" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("table", { className: "dsmm-role-table", children: [
10469
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { children: [
10470
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { scope: "col", children: t("property") }),
10471
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { scope: "col", children: t("value") })
10472
+ ] }) }),
10473
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("tbody", { children: tableRows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { children: [
10474
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "dsmm-role-prop-cell", children: row.property }),
10475
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "dsmm-role-val-cell", children: row.isComplex ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("pre", { className: "dsmm-role-cell-code", children: JSON.stringify(row.value, null, 2) }) : typeof row.value === "string" ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "dsmm-role-cell-text", children: row.value }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: row.value === null ? "null" : row.value === void 0 ? "undefined" : String(row.value) }) })
10476
+ ] }, row.property)) })
10477
+ ] }) }),
10478
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { id: `${controlId}-json-panel`, role: "tabpanel", "aria-labelledby": `${controlId}-json`, hidden: viewMode !== "json", tabIndex: 0, children: viewMode === "json" && code(JSON.stringify(jsonData2, null, 2)) })
10479
+ ] })
10288
10480
  ] })
10289
- ] }),
10290
- actual?.route !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("span", { className: "dsmm-role-model", children: [
10291
- " · ",
10292
- actual.route.provider,
10293
- "/",
10294
- actual.route.model,
10295
- actual.route.reasoningEffort ? ` · ${actual.route.reasoningEffort}` : ""
10296
10481
  ] })
10297
- ] }),
10298
- requested.description !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "dsmm-role-task", children: requested.description }),
10299
- result?.error != null && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-failure", children: [
10300
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "dsmm-role-section-title", children: t("failure") }),
10301
- code(JSON.stringify(result.error, null, 2))
10302
- ] }),
10303
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("details", { className: "dsmm-role-details", children: [
10304
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("summary", { children: t("technicalDetails") }),
10305
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-details-body", children: [
10306
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { className: "dsmm-role-details-header", children: /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.SegmentedControl, { id: controlId, value: viewMode, options: viewOptions, onChange: setViewMode, label: t("viewMode"), className: "dsmm-role-view-switch" }) }),
10307
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { id: `${controlId}-table-panel`, role: "tabpanel", "aria-labelledby": `${controlId}-table`, hidden: viewMode !== "table", tabIndex: 0, children: viewMode === "table" && /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("table", { className: "dsmm-role-table", children: [
10308
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("thead", { children: /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { children: [
10309
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { scope: "col", children: t("property") }),
10310
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("th", { scope: "col", children: t("value") })
10311
- ] }) }),
10312
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("tbody", { children: tableRows.map((row) => /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("tr", { children: [
10313
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "dsmm-role-prop-cell", children: row.property }),
10314
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("td", { className: "dsmm-role-val-cell", children: row.isComplex ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("pre", { className: "dsmm-role-cell-code", children: JSON.stringify(row.value, null, 2) }) : typeof row.value === "string" ? /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { className: "dsmm-role-cell-text", children: row.value }) : /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("span", { children: row.value === null ? "null" : row.value === void 0 ? "undefined" : String(row.value) }) })
10315
- ] }, row.property)) })
10316
- ] }) }),
10317
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("div", { id: `${controlId}-json-panel`, role: "tabpanel", "aria-labelledby": `${controlId}-json`, hidden: viewMode !== "json", tabIndex: 0, children: viewMode === "json" && code(JSON.stringify(jsonData2, null, 2)) })
10318
- ] })
10319
- ] })
10482
+ }
10483
+ ),
10484
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-actions", children: [
10485
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.StateDot, { state: stateDotState }),
10486
+ /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "dsmm-role-status", role: "status", children: t(state) }),
10487
+ props.inspect !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.Button, { variant: "ghost", size: "sm", onClick: props.inspect, children: t("inspect") })
10320
10488
  ] })
10321
- }
10322
- ),
10323
- /* @__PURE__ */ (0, import_jsx_runtime13.jsxs)("div", { className: "dsmm-role-actions", children: [
10324
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.StateDot, { state: stateDotState }),
10325
- /* @__PURE__ */ (0, import_jsx_runtime13.jsx)("p", { className: "dsmm-role-status", role: "status", children: t(state) }),
10326
- props.inspect !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime13.jsx)(import_dsh_client_ui_primitives11.Button, { variant: "ghost", size: "sm", onClick: props.inspect, children: t("inspect") })
10327
- ] })
10328
- ] });
10489
+ ]
10490
+ }
10491
+ );
10329
10492
  }
10330
- function registerRoleToolViews(ctx) {
10493
+ function registerRoleToolViews(ctx, observations) {
10331
10494
  ctx.effect(() => ctx.locale.register(ROLE_TOOL_NS, { en: roleToolEn, zh: roleToolZh }), "dsmm: role tool locale");
10332
10495
  ctx.effect(() => {
10333
10496
  const style = document.createElement("style");
@@ -10337,13 +10500,151 @@ function registerRoleToolViews(ctx) {
10337
10500
  return () => style.remove();
10338
10501
  }, "dsmm: role tool styles");
10339
10502
  ctx.slots.inject("tool.call.toolview", () => {
10340
- const disposers = [...Object.keys(roleToolKeys), "dsmm_role", "dsmm_category"].map((key) => ctx.slots.register({ name: "tool.call.toolview", key, locale: ROLE_TOOL_NS }, RoleToolView));
10503
+ const disposers = [...Object.keys(roleToolKeys), "dsmm_role", "dsmm_category"].map((key) => ctx.slots.register({
10504
+ name: "tool.call.toolview",
10505
+ key,
10506
+ locale: ROLE_TOOL_NS,
10507
+ inject: (sessionId2) => ({ hooks: { roleCalls: observations.source(sessionId2) } })
10508
+ }, RoleToolView));
10341
10509
  return () => {
10342
10510
  for (const dispose of disposers.reverse()) dispose();
10343
10511
  };
10344
10512
  });
10345
10513
  }
10346
10514
 
10515
+ // src/client/role-call-observations.ts
10516
+ var RoleCallObservationController = class {
10517
+ binding = null;
10518
+ sources = /* @__PURE__ */ new Map();
10519
+ source(sessionId2) {
10520
+ let source = this.sources.get(sessionId2);
10521
+ if (source === void 0) {
10522
+ source = new RoleCallObservationSource(sessionId2);
10523
+ source.bind(this.binding);
10524
+ this.sources.set(sessionId2, source);
10525
+ }
10526
+ return source;
10527
+ }
10528
+ bindConnection(factory, open) {
10529
+ const binding = { identity: {}, factory, open };
10530
+ this.binding = binding;
10531
+ for (const source of this.sources.values()) source.bind(binding);
10532
+ return () => {
10533
+ if (this.binding !== binding) return;
10534
+ this.binding = null;
10535
+ for (const source of this.sources.values()) source.bind(null);
10536
+ };
10537
+ }
10538
+ dispose() {
10539
+ this.binding = null;
10540
+ for (const source of this.sources.values()) source.dispose();
10541
+ this.sources.clear();
10542
+ }
10543
+ };
10544
+ var RoleCallObservationSource = class {
10545
+ constructor(sessionId2) {
10546
+ this.sessionId = sessionId2;
10547
+ this.snapshot = { sessionId: sessionId2, status: "unavailable", calls: /* @__PURE__ */ new Map() };
10548
+ }
10549
+ snapshot;
10550
+ listeners = /* @__PURE__ */ new Set();
10551
+ binding = null;
10552
+ revision = 0;
10553
+ stream;
10554
+ getSnapshot() {
10555
+ return this.snapshot;
10556
+ }
10557
+ subscribe(listener) {
10558
+ this.listeners.add(listener);
10559
+ if (this.listeners.size === 1) this.start();
10560
+ return () => {
10561
+ this.listeners.delete(listener);
10562
+ if (this.listeners.size !== 0) return;
10563
+ this.revision++;
10564
+ const stream = this.stream;
10565
+ this.stream = void 0;
10566
+ if (stream !== void 0) void stream.dispose();
10567
+ };
10568
+ }
10569
+ bind(binding) {
10570
+ if (this.binding?.identity === binding?.identity) return;
10571
+ this.binding = binding;
10572
+ this.revision++;
10573
+ const stream = this.stream;
10574
+ this.stream = void 0;
10575
+ if (stream !== void 0) void stream.dispose();
10576
+ this.publish({ sessionId: this.sessionId, status: "unavailable", calls: /* @__PURE__ */ new Map() });
10577
+ if (this.listeners.size > 0) this.start();
10578
+ }
10579
+ dispose() {
10580
+ this.binding = null;
10581
+ this.revision++;
10582
+ const stream = this.stream;
10583
+ this.stream = void 0;
10584
+ if (stream !== void 0) void stream.dispose();
10585
+ this.listeners.clear();
10586
+ }
10587
+ start() {
10588
+ const binding = this.binding;
10589
+ if (binding === null || this.listeners.size === 0 || this.stream !== void 0) return;
10590
+ const revision2 = ++this.revision;
10591
+ this.publish({ sessionId: this.sessionId, status: "connecting", calls: /* @__PURE__ */ new Map() });
10592
+ const stream = binding.factory.$stream({
10593
+ name: `DSMM role calls for ${this.sessionId}`,
10594
+ open: (signal) => binding.open(this.sessionId, signal),
10595
+ ended: (accepted) => new Error(`DSMM role call stream ended ${accepted ? "after" : "before"} its snapshot`),
10596
+ carrierFailed: () => {
10597
+ if (this.revision === revision2 && this.stream === stream) this.invalidate("stale");
10598
+ }
10599
+ });
10600
+ this.stream = stream;
10601
+ void this.consume(stream, revision2);
10602
+ }
10603
+ async consume(stream, revision2) {
10604
+ let generation = 0, admissionEpoch;
10605
+ try {
10606
+ for await (const item of stream) {
10607
+ if (this.revision !== revision2 || this.stream !== stream) return;
10608
+ const frame = item.value;
10609
+ if (frame.sessionId !== this.sessionId) throw new Error("DSMM role call stream changed sessions");
10610
+ if (item.generation !== generation) {
10611
+ if (frame.type !== "snapshot") throw new Error("DSMM role call generation omitted its snapshot");
10612
+ generation = item.generation;
10613
+ admissionEpoch = frame.admissionEpoch;
10614
+ this.publish({
10615
+ sessionId: this.sessionId,
10616
+ status: "live",
10617
+ admissionEpoch,
10618
+ calls: new Map(frame.calls.map((call) => [call.callId, call]))
10619
+ });
10620
+ item.accept();
10621
+ continue;
10622
+ }
10623
+ if (frame.type === "snapshot" || frame.admissionEpoch !== admissionEpoch) throw new Error("DSMM role call update crossed its admission");
10624
+ const calls = new Map(this.snapshot.calls);
10625
+ if (frame.type === "update") calls.set(frame.call.callId, frame.call);
10626
+ else calls.delete(frame.callId);
10627
+ this.publish({ sessionId: this.sessionId, status: "live", admissionEpoch, calls });
10628
+ }
10629
+ } catch {
10630
+ if (this.revision === revision2 && this.stream === stream) this.invalidate("unavailable");
10631
+ } finally {
10632
+ if (this.revision === revision2 && this.stream === stream) this.stream = void 0;
10633
+ }
10634
+ }
10635
+ invalidate(status) {
10636
+ const calls = new Map([...this.snapshot.calls].map(([callId, call]) => [callId, call.phase === "settled" ? call : Object.freeze({
10637
+ ...call,
10638
+ actualRoute: Object.freeze({ status: "unknown", reason: "not-observed" })
10639
+ })]));
10640
+ this.publish({ ...this.snapshot, status, calls });
10641
+ }
10642
+ publish(snapshot4) {
10643
+ this.snapshot = snapshot4;
10644
+ for (const listener of this.listeners) listener();
10645
+ }
10646
+ };
10647
+
10347
10648
  // src/client/profile-blank.ts
10348
10649
  function profileBlankNative(services) {
10349
10650
  const list = services.workspaces.list;
@@ -10985,7 +11286,9 @@ function ChildrenPanel(props) {
10985
11286
  // src/client/index.ts
10986
11287
  var inject = ["slots", "locale", "remote"];
10987
11288
  async function apply(ctx) {
10988
- registerRoleToolViews(ctx);
11289
+ const roleCalls = new RoleCallObservationController();
11290
+ registerRoleToolViews(ctx, roleCalls);
11291
+ ctx.effect(() => () => roleCalls.dispose(), "dsmm: role call observations");
10989
11292
  await ctx.remote.$mount(TYPERT_REMOTE);
10990
11293
  await ctx.remote.$mount(ROLE_CONTROL_REMOTE);
10991
11294
  await ctx.remote.$mount(PERMISSION_REMOTE);
@@ -10994,6 +11297,8 @@ async function apply(ctx) {
10994
11297
  ctx.effect(() => ctx.locale.register(PERMISSIONS_NS, { en: permissionEn, zh: permissionZh }), "dsmm: permission locale");
10995
11298
  void ctx.inject(["connection"], (connectionCtx) => {
10996
11299
  const handle = connectionCtx.connection, invoke = permissionClient(handle);
11300
+ const unbindRoleCalls = roleCalls.bindConnection(connectionCtx.remote, (sessionId2, signal) => connectionCtx.remote.dsmmChildren.observe(sessionId2, signal));
11301
+ connectionCtx.effect(() => unbindRoleCalls, "dsmm: role call connection withdrawal");
10997
11302
  const update = () => {
10998
11303
  const generation = handle.generation.getSnapshot();
10999
11304
  permissions.bindConnection(generation === void 0 ? null : invoke, generation);