@dsmm/dsmm 0.2.0 → 0.3.0

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 (285) hide show
  1. package/README.md +37 -67
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +10 -2015
  3. package/agent-presets/dsmm-clarifier/agent.cordis.yml +24 -343
  4. package/agent-presets/dsmm-code-search/agent.cordis.yml +19 -6
  5. package/agent-presets/dsmm-coding/agent.cordis.yml +19 -438
  6. package/agent-presets/dsmm-complex/agent.cordis.yml +23 -1009
  7. package/agent-presets/dsmm-creative/agent.cordis.yml +25 -442
  8. package/agent-presets/dsmm-cross-cutting/agent.cordis.yml +29 -1013
  9. package/agent-presets/dsmm-deep/agent.cordis.yml +24 -1008
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +19 -6
  11. package/agent-presets/dsmm-documenting/agent.cordis.yml +26 -439
  12. package/agent-presets/dsmm-frontend/agent.cordis.yml +21 -440
  13. package/agent-presets/dsmm-hard-reasoning/agent.cordis.yml +22 -441
  14. package/agent-presets/dsmm-media-reader/agent.cordis.yml +19 -6
  15. package/agent-presets/dsmm-normal-task/agent.cordis.yml +19 -438
  16. package/agent-presets/dsmm-oracle/agent.cordis.yml +25 -340
  17. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +25 -340
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +29 -2025
  19. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +24 -341
  20. package/agent-presets/dsmm-planner/agent.cordis.yml +14 -344
  21. package/agent-presets/dsmm-quick/agent.cordis.yml +19 -6
  22. package/agent-presets/dsmm-research/agent.cordis.yml +23 -8
  23. package/agent-presets/dsmm-reviewer/agent.cordis.yml +25 -340
  24. package/cordis.patch.yml +14 -0
  25. package/docs/agent-presets.md +36 -52
  26. package/docs/compatibility.md +47 -110
  27. package/docs/deferred-native-approval-risk.md +19 -0
  28. package/docs/design.md +2 -2
  29. package/docs/lsp.md +11 -21
  30. package/docs/migration-from-ocmm.md +2 -2
  31. package/docs/model-routing.md +84 -59
  32. package/docs/native-permissions.md +35 -0
  33. package/docs/profiles.md +40 -87
  34. package/docs/releasing.md +123 -2
  35. package/docs/roadmap.md +71 -17
  36. package/docs/settings-status.md +34 -169
  37. package/docs/skill-sync.md +52 -15
  38. package/lib/agent-registry.d.ts +36 -0
  39. package/lib/agent-registry.js +75 -0
  40. package/lib/child-admission-contract.d.ts +37 -0
  41. package/lib/child-admission-contract.js +2 -0
  42. package/lib/child-admission.d.ts +40 -0
  43. package/lib/child-admission.js +151 -0
  44. package/lib/child-capture.d.ts +85 -0
  45. package/lib/child-capture.js +205 -0
  46. package/lib/child-evidence.d.ts +17 -0
  47. package/lib/child-evidence.js +43 -0
  48. package/lib/client/ChildrenPanel.d.ts +43 -0
  49. package/lib/client/ChildrenPanel.js +82 -0
  50. package/lib/client/DeploymentPage.js +15 -8
  51. package/lib/client/EditableChoice.d.ts +17 -0
  52. package/lib/client/EditableChoice.js +49 -0
  53. package/lib/client/PermissionsPanel.d.ts +14 -0
  54. package/lib/client/PermissionsPanel.js +46 -0
  55. package/lib/client/ProfilesSection.js +30 -15
  56. package/lib/client/RoleAvailability.d.ts +7 -0
  57. package/lib/client/RoleAvailability.js +19 -0
  58. package/lib/client/SessionProfiles.js +27 -9
  59. package/lib/client/StructuredEditor.js +15 -7
  60. package/lib/client/children-controller.d.ts +98 -0
  61. package/lib/client/children-controller.js +296 -0
  62. package/lib/client/children-locales.d.ts +367 -0
  63. package/lib/client/children-locales.js +69 -0
  64. package/lib/client/controller.d.ts +6 -1
  65. package/lib/client/controller.js +14 -8
  66. package/lib/client/deployment-controller.js +1 -1
  67. package/lib/client/deployment-data.d.ts +2 -1
  68. package/lib/client/deployment-data.js +34 -5
  69. package/lib/client/deployment-locales.d.ts +4 -0
  70. package/lib/client/deployment-locales.js +11 -2
  71. package/lib/client/diagnostics.d.ts +14 -0
  72. package/lib/client/diagnostics.js +53 -0
  73. package/lib/client/index.d.ts +4 -0
  74. package/lib/client/index.js +96 -2
  75. package/lib/client/locales.d.ts +54 -0
  76. package/lib/client/locales.js +34 -16
  77. package/lib/client/permission-client.d.ts +16 -0
  78. package/lib/client/permission-client.js +38 -0
  79. package/lib/client/permission-controller.d.ts +62 -0
  80. package/lib/client/permission-controller.js +149 -0
  81. package/lib/client/permission-locales.d.ts +114 -0
  82. package/lib/client/permission-locales.js +75 -0
  83. package/lib/client/session-labels.js +4 -4
  84. package/lib/client/structured.js +19 -5
  85. package/lib/client/styles.d.ts +1 -1
  86. package/lib/client/styles.js +20 -0
  87. package/lib/client.js +5780 -1679
  88. package/lib/core-permission-authority.d.ts +18 -0
  89. package/lib/core-permission-authority.js +255 -0
  90. package/lib/core-permissions.d.ts +8 -0
  91. package/lib/core-permissions.js +33 -0
  92. package/lib/delivery-authority.d.ts +83 -0
  93. package/lib/delivery-authority.js +397 -0
  94. package/lib/deployment-config.d.ts +23 -0
  95. package/lib/deployment-config.js +61 -40
  96. package/lib/deployment-permission-rules.d.ts +55 -0
  97. package/lib/deployment-permission-rules.js +306 -0
  98. package/lib/dsh-types.d.ts +10 -4
  99. package/lib/guards.d.ts +1 -1
  100. package/lib/guards.js +29 -8
  101. package/lib/host-llm-startup.d.ts +41 -0
  102. package/lib/host-llm-startup.js +65 -0
  103. package/lib/host-llm.d.ts +92 -0
  104. package/lib/host-llm.js +325 -0
  105. package/lib/index.d.ts +15 -4
  106. package/lib/index.js +288 -48
  107. package/lib/live-pi-ai-owner.d.ts +18 -0
  108. package/lib/live-pi-ai-owner.js +144 -0
  109. package/lib/llm-runtime.d.ts +11 -0
  110. package/lib/llm-runtime.js +21 -0
  111. package/lib/managed-settings.d.ts +5 -0
  112. package/lib/managed-settings.js +14 -0
  113. package/lib/model-parameter-policy.d.ts +11 -0
  114. package/lib/model-parameter-policy.js +27 -0
  115. package/lib/model-routing.js +28 -17
  116. package/lib/modules.d.ts +13 -5
  117. package/lib/modules.js +17 -1
  118. package/lib/native-child-evidence.d.ts +40 -0
  119. package/lib/native-child-evidence.js +104 -0
  120. package/lib/native-pi-ai-wire.d.ts +37 -0
  121. package/lib/native-pi-ai-wire.js +261 -0
  122. package/lib/native-scope.js +1 -1
  123. package/lib/permission-bash.d.ts +6 -0
  124. package/lib/permission-bash.js +7 -0
  125. package/lib/permission-control.d.ts +73 -0
  126. package/lib/permission-control.js +205 -0
  127. package/lib/permission-controller.d.ts +68 -0
  128. package/lib/permission-controller.js +317 -0
  129. package/lib/permission-errors.d.ts +7 -0
  130. package/lib/permission-errors.js +21 -0
  131. package/lib/permission-fs-search.d.ts +5 -0
  132. package/lib/permission-fs-search.js +7 -0
  133. package/lib/permission-fs.d.ts +5 -0
  134. package/lib/permission-fs.js +7 -0
  135. package/lib/permission-native-access.d.ts +11 -0
  136. package/lib/permission-native-access.js +6 -0
  137. package/lib/permission-native-command.d.ts +10 -0
  138. package/lib/permission-native-command.js +93 -0
  139. package/lib/permission-native-rules.d.ts +75 -0
  140. package/lib/permission-native-rules.js +278 -0
  141. package/lib/permission-pwsh.d.ts +6 -0
  142. package/lib/permission-pwsh.js +7 -0
  143. package/lib/permission-remote.d.ts +26 -0
  144. package/lib/permission-remote.js +53 -0
  145. package/lib/permission-rpc.d.ts +29 -0
  146. package/lib/permission-rpc.js +152 -0
  147. package/lib/permission-rules.d.ts +115 -0
  148. package/lib/permission-rules.js +256 -0
  149. package/lib/permission-settings.d.ts +45 -0
  150. package/lib/permission-settings.js +48 -0
  151. package/lib/permission-shell.d.ts +38 -0
  152. package/lib/permission-shell.js +150 -0
  153. package/lib/permission-web.d.ts +5 -0
  154. package/lib/permission-web.js +7 -0
  155. package/lib/preset-registry.js +36 -25
  156. package/lib/profile-diagnostics.d.ts +45 -0
  157. package/lib/profile-diagnostics.js +148 -0
  158. package/lib/profile-locale.d.ts +3 -0
  159. package/lib/profile-locale.js +2 -0
  160. package/lib/profile-remote.d.ts +8 -0
  161. package/lib/profile-remote.js +163 -39
  162. package/lib/profile-rpc.d.ts +4 -3
  163. package/lib/profile-rpc.js +20 -16
  164. package/lib/profile-runtime.d.ts +40 -1
  165. package/lib/profile-runtime.js +368 -93
  166. package/lib/profile-store.d.ts +11 -0
  167. package/lib/profile-store.js +143 -11
  168. package/lib/profile-types.d.ts +70 -1
  169. package/lib/profile-types.js +1 -0
  170. package/lib/profiles.d.ts +16 -2
  171. package/lib/profiles.js +156 -79
  172. package/lib/prompt-content.js +1 -1
  173. package/lib/prompts.d.ts +37 -2
  174. package/lib/prompts.js +111 -9
  175. package/lib/recovery-policy.js +20 -7
  176. package/lib/role-control-remote.d.ts +38 -0
  177. package/lib/role-control-remote.js +211 -0
  178. package/lib/role-control-rpc.d.ts +51 -0
  179. package/lib/role-control-rpc.js +381 -0
  180. package/lib/role-control-types.d.ts +92 -0
  181. package/lib/role-control-types.js +8 -0
  182. package/lib/role-invocation.d.ts +47 -0
  183. package/lib/role-invocation.js +135 -0
  184. package/lib/role-llm-runtime.d.ts +17 -0
  185. package/lib/role-llm-runtime.js +62 -0
  186. package/lib/role-llm.d.ts +31 -0
  187. package/lib/role-llm.js +66 -0
  188. package/lib/role-policy.d.ts +46 -8
  189. package/lib/role-policy.js +421 -61
  190. package/lib/role-providers.d.ts +2 -2
  191. package/lib/role-providers.js +27 -72
  192. package/lib/role-routing.d.ts +11 -2
  193. package/lib/role-routing.js +42 -25
  194. package/lib/role-runs.d.ts +138 -0
  195. package/lib/role-runs.js +335 -0
  196. package/lib/role-subagents.d.ts +58 -3
  197. package/lib/role-subagents.js +179 -56
  198. package/lib/roles.d.ts +5 -6
  199. package/lib/roles.js +10 -39
  200. package/lib/route-json.d.ts +19 -0
  201. package/lib/route-json.js +129 -0
  202. package/lib/routing-policy.d.ts +2 -0
  203. package/lib/routing-policy.js +12 -2
  204. package/lib/runtime-integration.d.ts +81 -0
  205. package/lib/runtime-integration.js +702 -0
  206. package/lib/runtime-recovery.js +18 -8
  207. package/lib/session-persistence.d.ts +2 -1
  208. package/lib/session-persistence.js +1 -1
  209. package/lib/session-scope.js +4 -1
  210. package/lib/settings.d.ts +47 -13
  211. package/lib/settings.js +217 -82
  212. package/lib/skills.js +2 -2
  213. package/lib/status.d.ts +10 -1
  214. package/lib/status.js +11 -8
  215. package/lib/subagent-runtime.d.ts +57 -0
  216. package/lib/subagent-runtime.js +257 -0
  217. package/package.json +149 -89
  218. package/patches/subagent-runtime.yml +15 -0
  219. package/prompts/deepseek-flash.md +1 -1
  220. package/prompts/deepseek-v4-pro.md +2 -2
  221. package/prompts/deepwork.md +27 -18
  222. package/prompts/source/agents/clarifier.md +5 -3
  223. package/prompts/source/agents/orchestrator.md +18 -9
  224. package/prompts/source/agents/plan-critic.md +5 -1
  225. package/prompts/source/agents/planner.md +4 -2
  226. package/prompts/source/agents/reviewer.md +6 -0
  227. package/prompts/source/category/complex.md +4 -4
  228. package/prompts/source/category/creative.md +6 -4
  229. package/prompts/source/category/cross-cutting.md +10 -8
  230. package/prompts/source/category/deep.md +5 -3
  231. package/prompts/source/category/documenting.md +7 -1
  232. package/prompts/source/category/frontend.md +2 -2
  233. package/prompts/source/category/hard-reasoning.md +3 -3
  234. package/prompts/source/category/research.md +4 -2
  235. package/prompts/source/deepwork/claude-opus-5.md +2 -2
  236. package/prompts/source/deepwork/codex.md +1 -1
  237. package/prompts/source/deepwork/default.md +22 -15
  238. package/prompts/source/deepwork/gemini.md +23 -16
  239. package/prompts/source/deepwork/glm.md +21 -14
  240. package/prompts/source/deepwork/gpt.md +12 -6
  241. package/prompts/source/deepwork/planner.md +8 -5
  242. package/prompts/source/manifest.json +178 -63
  243. package/prompts/source/shared/dsh-host-contract.md +5 -3
  244. package/prompts/source/shared/locale.md +2 -2
  245. package/prompts/source/terminal/orchestrator.md +1 -1
  246. package/skills/ast-grep/SKILL.md +7 -4
  247. package/skills/brainstorming/SKILL.md +43 -22
  248. package/skills/coding-agent-sessions/SKILL.md +7 -4
  249. package/skills/coding-agent-sessions/scripts/agent_sessions/pi_family.py +46 -46
  250. package/skills/coding-agent-sessions/scripts/tests/test_pi_family_scanners.py +130 -130
  251. package/skills/debugging/SKILL.md +14 -9
  252. package/skills/debugging/references/methodology/00-setup.md +14 -62
  253. package/skills/debugging/references/methodology/02-investigate.md +4 -4
  254. package/skills/debugging/references/methodology/03-flaky-triage.md +3 -3
  255. package/skills/debugging/references/methodology/04-hard-reasoning-escalation.md +2 -14
  256. package/skills/debugging/references/methodology/06-fix.md +6 -6
  257. package/skills/debugging/references/methodology/08-qa.md +5 -5
  258. package/skills/debugging/references/methodology/09-cleanup.md +15 -153
  259. package/skills/debugging/references/methodology/partial-runtime-evidence.md +3 -16
  260. package/skills/debugging/references/runtimes/bundled-js-binary.md +1 -16
  261. package/skills/debugging/references/runtimes/native-binary.md +9 -54
  262. package/skills/debugging/references/runtimes/node.md +4 -15
  263. package/skills/debugging/references/runtimes/python.md +3 -15
  264. package/skills/debugging/references/runtimes/rust.md +2 -18
  265. package/skills/debugging/references/tools/dap.md +1 -1
  266. package/skills/debugging/references/tools/ghidra.md +4 -15
  267. package/skills/debugging/references/tools/playwright-cli.md +3 -15
  268. package/skills/debugging/references/tools/pwntools.md +4 -16
  269. package/skills/dispatching-parallel-agents/SKILL.md +18 -16
  270. package/skills/frontend/SKILL.md +7 -4
  271. package/skills/frontend/references/design/react-dev-tooling-skill.md +1 -1
  272. package/skills/git-master/SKILL.md +7 -4
  273. package/skills/init-deep/SKILL.md +7 -4
  274. package/skills/receiving-code-review/SKILL.md +17 -12
  275. package/skills/remove-ai-slops/SKILL.md +39 -38
  276. package/skills/requesting-code-review/SKILL.md +19 -17
  277. package/skills/requesting-code-review/code-reviewer.md +13 -1
  278. package/skills/subagent-driven-development/SKILL.md +29 -26
  279. package/skills/subagent-driven-development/implementer-prompt.md +29 -11
  280. package/skills/subagent-driven-development/spec-reviewer-prompt.md +6 -1
  281. package/skills/using-git-worktrees/SKILL.md +7 -4
  282. package/skills/writing-plans/SKILL.md +29 -24
  283. package/skills/writing-plans/plan-document-reviewer-prompt.md +10 -1
  284. package/scripts/repair-session-log.mjs +0 -476
  285. package/scripts/session-repair-native-verifier.mjs +0 -367
@@ -2,15 +2,17 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
2
2
  import { useEffect, useId, useState } from "react";
3
3
  import { Button, IconBranchOutlineRegular, Menu } from "@deepseek-ai/dsh-client-ui-primitives";
4
4
  import { sessionProfileLabels } from "./session-labels.js";
5
+ import { IssueDetails, ProfileWarnings, profileWarnings } from "./diagnostics.js";
6
+ import { RoleAvailability } from "./RoleAvailability.js";
7
+ import { parseSubagentRuntimeAdmissionView } from "../profile-remote.js";
8
+ import { isSafeDiagnosticField } from "../profile-diagnostics.js";
5
9
  const MENU_ISSUE_CODES = new Set(["validation", "conflict", "not-found", "lock-timeout", "unsafe-path", "io", "activation", "corrupt-selection", "limit", "busy", "maintenance", "disposed", "not-owned", "unavailable", "cancelled", "model-unconfigured", "model-choice-changed", "model-service-unavailable", "model-observation-unavailable", "model-selection-failed"]);
6
- const MENU_ROLE_FIELD = /^(?:settings\.roleRouting\.)?dsmm-(?:orchestrator|planner|plan-critic|builder|reviewer|oracle|oracle-2nd|creative|code-search|doc-search|clarifier|media-reader)(?:\.(?:primary|fallbackRoutes)(?:\[[0-7]\])?(?:\.(?:provider|model|reasoningEffort))?|\.strategy|\.rateLimit(?:\.(?:maxRetries|initialDelayMs|maxDelayMs|maxTotalDelayMs|switchAfterRateLimits|maxSwitches))?)?$/u;
7
- const MENU_COMMON_FIELD = /^(?:version|id|label|content|sessionId|expectedRevision|expectedSelectionRevision|expectedAdmissionEpoch|settings(?:\.(?:defaultActive|roleRouting|workflow|guards|runtimeRecovery|runtimePolicy))?)$/u;
8
10
  function menuIssue(issue) {
9
11
  const code = MENU_ISSUE_CODES.has(issue.code) ? issue.code : issue.kind === "transport" ? "transport" : "unavailable";
10
12
  const field = issue.field;
11
13
  // Only closed configuration grammar is displayable; never echo messages,
12
14
  // arbitrary wire fields, provider identifiers, credentials or file paths.
13
- return { code, ...(typeof field === "string" && field.length <= 128 && (MENU_ROLE_FIELD.test(field) || MENU_COMMON_FIELD.test(field)) ? { field } : {}) };
15
+ return { code, ...(isSafeDiagnosticField(field) ? { field } : {}) };
14
16
  }
15
17
  export function SessionScope({ state, actions, t, compact = false }) {
16
18
  const prefix = useId();
@@ -18,12 +20,26 @@ export function SessionScope({ state, actions, t, compact = false }) {
18
20
  const labels = session === null ? null : sessionProfileLabels(session, t);
19
21
  const selected = state.snapshot?.profiles.find((profile) => profile.id === state.sessionChoice);
20
22
  const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy !== null || state.dirty;
23
+ const current = () => actions.readProfileView().currentSessionId === state.currentSessionId;
21
24
  const allowed = session !== null && session.switchAllowed && /^[a-f0-9]{64}$|^absent$/u.test(session.selection.selectionRevision);
22
25
  const status = state.sessionNotice === null ? "" : t(state.sessionNotice === "mode-on" ? "headerModeOn" : state.sessionNotice === "mode-off" ? "headerModeOff" : state.sessionNotice === "applied-with-model" ? "sessionAppliedWithModel" : state.sessionNotice === "applied" ? "sessionApplied" : "sessionResetDone");
23
- return _jsxs("div", { className: "dsmm-session-scope", "aria-busy": state.sessionBusy !== null, "data-dsmm-session-scope": true, children: [!compact && _jsx("h3", { children: t("sessionScope") }), state.currentSessionId === null ? _jsx("p", { className: "dsmm-hint", children: t("noSession") }) : _jsxs(_Fragment, { children: [labels !== null && _jsx("p", { "data-dsmm-session-state": true, children: labels.admitted }), labels !== null && !compact && _jsx("p", { className: "dsmm-hint", "data-dsmm-session-future-default": true, children: labels.futureDefault }), session !== null && !session.switchAllowed && _jsx("p", { className: "dsmm-hint", children: t("sessionBusy", { reason: session.switchUnavailableReason ?? "unavailable" }) }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-choice`, children: t("sessionSelect") }), _jsxs("select", { id: `${prefix}-choice`, value: state.sessionChoice ?? "", disabled: disabled || !allowed, onChange: (event) => actions.chooseSessionProfile(event.currentTarget.value || null), children: [_jsx("option", { value: "", children: t("sessionBaseline") }), state.sessionChoice !== null && selected === undefined && _jsx("option", { value: state.sessionChoice, children: state.sessionChoice }), state.snapshot?.profiles.map((profile) => _jsx("option", { value: profile.id, disabled: profile.revision === null || profile.error !== undefined, children: profile.label === undefined ? profile.id : `${profile.label} (${profile.id})` }, profile.id))] })] }), state.dirty && _jsx("p", { className: "dsmm-hint", children: t("sessionDirty") }), _jsxs("div", { className: "dsmm-actions", children: [_jsx(Button, { type: "button", variant: "outline", disabled: disabled || !allowed || (state.sessionChoice !== null && selected?.revision == null), onClick: () => { void actions.applySession(); }, children: t(state.sessionBusy === "apply" ? "sessionApplying" : "sessionApply") }), !compact && _jsx(Button, { type: "button", variant: "outline", disabled: disabled || !allowed, onClick: () => { void actions.resetSession(); }, children: t(state.sessionBusy === "reset" ? "sessionResetting" : "sessionReset") }), _jsx(Button, { type: "button", variant: "outline", disabled: state.sessionBusy !== null || state.busy !== null || state.pendingEditor !== null, onClick: () => { void actions.refreshSession(); }, children: t("sessionRefresh") })] }), !compact && session?.rolePolicy !== undefined && _jsx("p", { "data-dsmm-session-policy": true, children: t("roleState", { route: session.rolePolicy.route === undefined ? t("inheritRoute") : `${session.rolePolicy.route.provider}/${session.rolePolicy.route.model}${session.rolePolicy.route.reasoningEffort === undefined ? "" : ` (${session.rolePolicy.route.reasoningEffort})`}`, strategy: session.rolePolicy.strategy, retries: session.rolePolicy.retries, failures: session.rolePolicy.rateLimitFailures, switches: session.rolePolicy.switches, delay: session.rolePolicy.totalDelayMs }) })] }), state.sessionIssue !== null && _jsx("p", { role: "alert", children: state.sessionIssue.source === "profile-model" ? t(state.sessionIssue.code === "model-unconfigured" ? "headerNoProfileModel" : state.sessionIssue.code === "model-choice-changed" ? "headerModelChoiceChanged" : "headerModelUnconfirmed")
26
+ let binding = session?.subagentRuntime;
27
+ try {
28
+ if (binding !== undefined)
29
+ binding = parseSubagentRuntimeAdmissionView(binding);
30
+ }
31
+ catch {
32
+ binding = undefined;
33
+ }
34
+ return _jsxs("div", { className: "dsmm-session-scope", "aria-busy": state.sessionBusy !== null, "data-dsmm-session-scope": true, children: [!compact && _jsx("h3", { children: t("sessionScope") }), state.currentSessionId === null ? _jsx("p", { className: "dsmm-hint", children: t("noSession") }) : _jsxs(_Fragment, { children: [labels !== null && _jsx("p", { "data-dsmm-session-state": true, children: labels.admitted }), labels !== null && !compact && _jsx("p", { className: "dsmm-hint", "data-dsmm-session-future-default": true, children: labels.futureDefault }), session === null && _jsx("p", { className: "dsmm-hint", children: t("sessionUnavailable") }), session?.warnings?.length ? _jsxs("div", { children: [_jsx("p", { children: t("admissionWarnings") }), _jsx(ProfileWarnings, { warnings: session.warnings, t: t })] }) : null, session !== null && !session.switchAllowed && _jsx("p", { className: "dsmm-hint", children: t("sessionBusy", { reason: session.switchUnavailableReason ?? "unavailable" }) }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-choice`, children: t("sessionSelect") }), _jsxs("select", { id: `${prefix}-choice`, value: state.sessionChoice ?? "", disabled: disabled || !allowed, onChange: (event) => { if (current())
35
+ actions.chooseSessionProfile(event.currentTarget.value || null); }, children: [_jsx("option", { value: "", children: t("sessionBaseline") }), state.sessionChoice !== null && selected === undefined && _jsx("option", { value: state.sessionChoice, children: state.sessionChoice }), state.snapshot?.profiles.map((profile) => _jsxs("option", { value: profile.id, disabled: profile.revision === null || profile.error !== undefined, children: [profile.label?.trim() ? `${profile.label} (${profile.id})` : profile.id, profileWarnings(profile.warnings).length ? ` — ${t("warningProfile")}` : ""] }, profile.id))] })] }), !compact && _jsxs(_Fragment, { children: [_jsx("p", { className: "dsmm-hint", children: t("sessionModelHint") }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled || !allowed || session?.profileModel === undefined, onClick: () => { if (current())
36
+ void actions.useSessionProfileModel(); }, children: t("headerUseCurrentModel") }), session !== null && _jsxs("div", { className: "dsmm-availability", children: [_jsx("p", { children: binding === undefined ? t("bindingUnknown") : t("bindingState", { binding: binding.binding, ready: t(binding.deliveryFenceReady ? "enabled" : "disabled"), restart: t(binding.restartRequired ? "enabled" : "disabled") }) }), binding?.reason !== undefined && _jsx("p", { children: t("bindingReason", { reason: binding.reason }) })] }), session?.roles !== undefined && _jsxs("details", { children: [_jsx("summary", { children: t("admittedRoles") }), session.roles.map(role => _jsxs("div", { className: "dsmm-availability", children: [_jsx("p", { children: role.id }), _jsx(RoleAvailability, { value: role, t: t })] }, role.id))] })] }), state.dirty && _jsx("p", { className: "dsmm-hint", children: t("sessionDirty") }), _jsxs("div", { className: "dsmm-actions", children: [_jsx(Button, { type: "button", variant: "outline", disabled: disabled || !allowed || (state.sessionChoice !== null && selected?.revision == null), onClick: () => { if (current())
37
+ void actions.applySession(); }, children: t(state.sessionBusy === "apply" ? "sessionApplying" : "sessionApply") }), !compact && _jsx(Button, { type: "button", variant: "outline", disabled: disabled || !allowed, onClick: () => { if (current())
38
+ void actions.resetSession(); }, children: t(state.sessionBusy === "reset" ? "sessionResetting" : "sessionReset") }), _jsx(Button, { type: "button", variant: "outline", disabled: state.sessionBusy !== null || state.busy !== null || state.pendingEditor !== null, onClick: () => { if (current())
39
+ void actions.refreshSession(); }, children: t("sessionRefresh") })] }), !compact && session?.rolePolicy !== undefined && _jsx("p", { "data-dsmm-session-policy": true, children: t("roleState", { route: session.rolePolicy.route === undefined ? t("inheritRoute") : `${session.rolePolicy.route.provider}/${session.rolePolicy.route.model}${session.rolePolicy.route.reasoningEffort === undefined ? "" : ` (${session.rolePolicy.route.reasoningEffort})`}`, strategy: session.rolePolicy.strategy, retries: session.rolePolicy.retries, failures: session.rolePolicy.rateLimitFailures, switches: session.rolePolicy.switches, delay: session.rolePolicy.totalDelayMs }) })] }), state.sessionIssue !== null && _jsx("p", { role: "alert", children: state.sessionIssue.source === "profile-model" ? t(state.sessionIssue.code === "model-unconfigured" ? "headerNoProfileModel" : state.sessionIssue.code === "model-choice-changed" ? "headerModelChoiceChanged" : "headerModelUnconfirmed")
24
40
  : state.sessionIssue.code === "conflict" ? t("sessionConflict")
25
41
  : ["busy", "maintenance", "disposed", "not-owned"].includes(state.sessionIssue.code) ? t("sessionBusy", { reason: state.sessionIssue.code })
26
- : t(state.sessionIssue.code === "validation" ? "validation" : "sessionUnavailable") }), _jsx("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.sessionBusy === "read" ? t("reading") : status })] });
42
+ : t(state.sessionIssue.code === "validation" ? "validation" : "sessionUnavailable") }), state.sessionIssue !== null && _jsx(IssueDetails, { issue: state.sessionIssue, t: t }), _jsx("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.sessionBusy === "read" ? t("reading") : status })] });
27
43
  }
28
44
  /** Root-scoped native menu; an explicitly scoped foreign occurrence still refuses. */
29
45
  export function SessionProfiles(props) {
@@ -36,7 +52,7 @@ export function SessionProfiles(props) {
36
52
  return null;
37
53
  const { t } = props;
38
54
  const session = state.session;
39
- const admission = session?.admittedSelection ?? (session?.scope === "global-default" ? undefined : session?.selection);
55
+ const admission = session?.admittedSelection;
40
56
  const unknownCaptured = session !== null && admission === undefined;
41
57
  const current = session === null ? "__dsmm_session_unavailable__" : unknownCaptured ? "__dsmm_captured_default__" : admission?.selectedId ?? "";
42
58
  const profiles = state.snapshot?.profiles ?? [];
@@ -62,11 +78,13 @@ export function SessionProfiles(props) {
62
78
  feedback = t("headerBusy");
63
79
  else if (state.sessionNotice !== null)
64
80
  feedback = t(state.sessionNotice === "mode-on" ? "headerModeOn" : state.sessionNotice === "mode-off" ? "headerModeOff" : state.sessionNotice === "applied-with-model" ? "headerAppliedWithModel" : "headerApplied");
65
- const profileName = unknownCaptured ? t("headerCaptured") : currentSaved?.label === undefined ? admission?.selectedId ?? t("sessionBaseline") : `${currentSaved.label} (${currentSaved.id})`;
81
+ const profileName = unknownCaptured ? t("headerCaptured") : currentSaved?.revision === admission?.appliedRevision && currentSaved?.label?.trim() ? `${currentSaved.label} (${currentSaved.id})` : admission?.selectedId ?? t("sessionBaseline");
66
82
  const currentLabel = t("headerCurrentProfile", { profile: session === null ? t("headerUnavailable") : profileName });
67
83
  const entries = [{ type: "label", id: "@current", text: currentLabel }];
84
+ for (const warning of profileWarnings(session?.warnings))
85
+ entries.push({ type: "label", id: `@warning:${warning.code}`, text: t("warningMarker", { code: warning.code, field: warning.field }) });
68
86
  if (id === null && state.snapshot !== null)
69
- entries.push({ type: "label", id: "@future", text: t("sessionFutureDefault", { profile: state.snapshot.profiles.find((profile) => profile.id === state.snapshot.selectedId)?.label ?? state.snapshot.selectedId ?? t("sessionBaseline") }) });
87
+ entries.push({ type: "label", id: "@future", text: t("sessionFutureDefault", { profile: state.snapshot.profiles.find((profile) => profile.id === state.snapshot.selectedId)?.label?.trim() || state.snapshot.selectedId || t("sessionBaseline") }) });
70
88
  if (feedback !== "" && (state.sessionNotice === null || state.sessionIssue !== null))
71
89
  entries.push({ type: "label", id: "@status", text: feedback });
72
90
  const mode = session?.deepwork;
@@ -83,7 +101,7 @@ export function SessionProfiles(props) {
83
101
  entries.push({ id: "__dsmm_captured_default__", label: t("headerCaptured"), disabled: true });
84
102
  entries.push({ type: "separator", id: "@keep-separator" }, { type: "label", id: "@keep-heading", text: t("headerCompactProfiles") }, { id: "", label: t("sessionBaseline"), disabled });
85
103
  for (const profile of profiles)
86
- entries.push({ id: profile.id, label: (profile.label ?? profile.id) + (profile.error === undefined && profile.revision !== null ? "" : ` — ${t("headerSavedUnavailable")}`), disabled: disabled || profile.revision === null || profile.error !== undefined });
104
+ entries.push({ id: profile.id, label: (profile.label?.trim() ? profile.label : profile.id) + (profile.error === undefined && profile.revision !== null ? "" : ` — ${t("headerSavedUnavailable")}`) + (profileWarnings(profile.warnings).length ? ` — ${t("warningProfile")}` : ""), disabled: disabled || profile.revision === null || profile.error !== undefined });
87
105
  entries.push({ type: "separator", id: "@model-separator" }, { id: "@use-model", label: t("headerUseCurrentModel"), disabled: disabled || session?.profileModel === undefined });
88
106
  const open = openFor === id;
89
107
  return _jsxs("div", { className: "dsmm-header-profiles", "data-dsmm-header-profile": true, "aria-busy": committing, children: [_jsx(Menu, { open: open, autoFocus: true, portal: true, align: "start", className: "dsmm-profile-anchor", listClassName: "dsmm-profile-menu", items: entries, selectedId: current, footer: [{ id: "@refresh", label: t("headerCompactRefresh"), disabled: committing || state.busy !== null }], anchor: _jsx(Button, { type: "button", size: "sm", variant: "toolbar", className: "dsmm-profile-trigger", icon: _jsx(IconBranchOutlineRegular, {}), "aria-label": t("headerProfileLabel"), "aria-haspopup": "menu", "aria-expanded": open, "aria-describedby": `${prefix}-feedback`, onClick: () => setOpenFor(open ? undefined : id) }), onClose: () => setOpenFor(undefined), onSelect: (value) => {
@@ -1,10 +1,12 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
1
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useEffect, useId, useState } from "react";
3
3
  import { Button, Input } from "@deepseek-ai/dsh-client-ui-primitives";
4
+ import { DSMM_LOCALES } from "../profile-locale.js";
4
5
  import { DSMM_RATE_LIMIT_BOUNDS, normalizeRateLimitPolicy } from "../routing-policy.js";
5
6
  import { structuredDocument } from "./structured.js";
6
7
  import { RETRY_FIELD_LABEL_KEYS } from "./locales.js";
7
- const MANUAL = "__dsmm_manual__";
8
+ import { RoleAvailability, roleAvailability } from "./RoleAvailability.js";
9
+ import { EditableChoice } from "./EditableChoice.js";
8
10
  function RetryNumber({ id, name, field, value, inherited, path, disabled, actions, t }) {
9
11
  const [draft, setDraft] = useState(value === undefined ? "" : String(value));
10
12
  const [invalid, setInvalid] = useState(false);
@@ -28,19 +30,22 @@ function RouteFields({ value, path, name, catalog, disabled, edit, editRoute, t
28
30
  const group = providers.find((candidate) => candidate.id === value.provider);
29
31
  const model = group?.models.find((candidate) => candidate.id === value.model);
30
32
  const efforts = model?.reasoning?.efforts ?? [];
31
- const providerListed = group !== undefined;
32
- const modelListed = model !== undefined;
33
33
  const updateModel = (provider, modelId) => {
34
34
  // This is an explicit user change, not a catalog refresh. Clear only this
35
35
  // route's adapter-owned effort; do not save or touch the native model default.
36
36
  editRoute(path, provider, modelId);
37
37
  };
38
- return _jsxs("div", { className: "dsmm-route-fields", children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-provider`, children: t("routeProvider", { name }) }), _jsxs("select", { id: `${prefix}-provider`, disabled: disabled, value: providerListed ? value.provider : MANUAL, onChange: (event) => updateModel(event.currentTarget.value === MANUAL ? "" : event.currentTarget.value, ""), children: [_jsx("option", { value: MANUAL, children: providerListed ? t("manual") : t("manualValue", { value: value.provider || t("unset") }) }), providers.map((provider) => _jsxs("option", { value: provider.id, children: [provider.name, " (", provider.id, ")"] }, provider.id))] }), !providerListed && _jsx(Input, { "aria-label": t("manualProvider", { name }), className: "dsmm-input", value: value.provider, disabled: disabled, onChange: (event) => updateModel(event.currentTarget.value, value.model) })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-model`, children: t("routeModel", { name }) }), _jsxs("select", { id: `${prefix}-model`, disabled: disabled, value: modelListed ? value.model : MANUAL, onChange: (event) => updateModel(value.provider, event.currentTarget.value === MANUAL ? "" : event.currentTarget.value), children: [_jsx("option", { value: MANUAL, children: modelListed ? t("manual") : t("manualValue", { value: value.model || t("unset") }) }), group?.models.map((candidate) => _jsxs("option", { value: candidate.id, children: [candidate.name, " (", candidate.id, ")"] }, candidate.id))] }), !modelListed && _jsx(Input, { "aria-label": t("manualModel", { name }), className: "dsmm-input", value: value.model, disabled: disabled, onChange: (event) => updateModel(value.provider, event.currentTarget.value) })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-effort`, children: t("routeEffort", { name }) }), _jsxs("select", { id: `${prefix}-effort`, disabled: disabled, value: value.reasoningEffort ?? "", onChange: (event) => edit([...path, "reasoningEffort"], event.currentTarget.value || undefined), children: [_jsx("option", { value: "", children: t("effortDefault") }), value.reasoningEffort !== undefined && !efforts.some((effort) => effort.id === value.reasoningEffort) && _jsx("option", { value: value.reasoningEffort, children: t("manualValue", { value: value.reasoningEffort }) }), efforts.map((effort) => _jsxs("option", { value: effort.id, children: [effort.name, " (", effort.id, ")"] }, effort.id))] }), _jsx(Input, { "aria-label": t("manualEffort", { name }), className: "dsmm-input", value: value.reasoningEffort ?? "", disabled: disabled, placeholder: t("effortDefault"), onChange: (event) => edit([...path, "reasoningEffort"], event.currentTarget.value || undefined) })] })] });
38
+ return _jsxs("div", { className: "dsmm-route-fields", children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-provider`, children: t("routeProvider", { name }) }), _jsx(EditableChoice, { id: `${prefix}-provider`, label: t("routeProvider", { name }), value: value.provider, options: providers, disabled: disabled, onChange: provider => updateModel(provider, value.model), onSelect: provider => updateModel(provider, "") })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-model`, children: t("routeModel", { name }) }), _jsx(EditableChoice, { id: `${prefix}-model`, label: t("routeModel", { name }), value: value.model, options: group?.models ?? [], disabled: disabled, onChange: modelId => updateModel(value.provider, modelId) })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-effort`, children: t("routeEffort", { name }) }), _jsx(EditableChoice, { id: `${prefix}-effort`, label: t("routeEffort", { name }), value: value.reasoningEffort ?? "", options: efforts, disabled: disabled, placeholder: t("effortDefault"), onChange: effort => edit([...path, "reasoningEffort"], effort || undefined) })] })] });
39
39
  }
40
40
  function PolicyFields({ value, inherited, path, name, disabled, actions, t }) {
41
41
  const prefix = useId();
42
42
  return _jsxs("div", { className: "dsmm-policy-fields", children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-strategy`, children: t("strategy", { name }) }), _jsxs("select", { id: `${prefix}-strategy`, disabled: disabled, value: value.strategy ?? "", onChange: (event) => actions.editPath([...path, "strategy"], event.currentTarget.value || undefined), children: [_jsx("option", { value: "", children: t("inheritStrategy", { value: inherited?.strategy ?? t("unknownDefault") }) }), _jsx("option", { value: "startup-lock", children: t("startupLock") }), _jsx("option", { value: "rate-limit-fallback", children: t("rateFallback") })] })] }), _jsx("p", { className: "dsmm-hint", children: t("strategyHint") }), _jsx("div", { className: "dsmm-route-fields", children: Object.keys(DSMM_RATE_LIMIT_BOUNDS).map((field) => _jsx(RetryNumber, { id: `${prefix}-${field}`, t: t, name: name, field: field, value: value.rateLimit?.[field], inherited: inherited?.rateLimit[field], path: [...path, "rateLimit", field], disabled: disabled, actions: actions }, field)) })] });
43
43
  }
44
+ function LevelFields({ level, value, path, catalog, disabled, actions, t }) {
45
+ const prefix = useId();
46
+ const mode = value === undefined ? "inherit" : value.provider === undefined ? "effort" : "route";
47
+ return _jsxs("fieldset", { "data-dsmm-level": level, children: [_jsx("legend", { children: t("levelName", { level }) }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-mode`, children: t("levelMode", { level }) }), _jsxs("select", { id: `${prefix}-mode`, value: mode, disabled: disabled, onChange: event => actions.editPath(path, event.currentTarget.value === "inherit" ? undefined : event.currentTarget.value === "effort" ? { reasoningEffort: "" } : { provider: "", model: "" }), children: [_jsx("option", { value: "inherit", children: t("levelUnconfigured") }), _jsx("option", { value: "effort", children: t("levelEffortOnly") }), _jsx("option", { value: "route", children: t("levelFullRoute") })] })] }), mode === "effort" && _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-effort`, children: t("routeEffort", { name: level }) }), _jsx(EditableChoice, { id: `${prefix}-effort`, label: t("routeEffort", { name: level }), value: value?.reasoningEffort ?? "", options: [], disabled: disabled, onChange: effort => actions.editPath([...path, "reasoningEffort"], effort) })] }), value?.provider !== undefined && _jsx(RouteFields, { value: value, path: path, name: t("levelName", { level }), catalog: catalog, disabled: disabled, edit: actions.editPath, editRoute: actions.editRoute, t: t })] });
48
+ }
44
49
  /** The same raw draft drives every control; there is no form-to-document rewrite. */
45
50
  export function StructuredEditor({ state, actions, disabled, t }) {
46
51
  const prefix = useId();
@@ -61,7 +66,10 @@ export function StructuredEditor({ state, actions, disabled, t }) {
61
66
  }
62
67
  catch { /* Invalid effective values remain a raw/Host validation error. */ }
63
68
  const rolePath = ["settings", "roleRouting", role?.id ?? ""];
64
- return _jsxs("div", { className: "dsmm-structured", "data-dsmm-structured": true, children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-label`, children: t("profileLabel") }), _jsx(Input, { id: `${prefix}-label`, className: "dsmm-input", value: document.label ?? "", disabled: disabled, onChange: (event) => actions.editPath(["label"], event.currentTarget.value || undefined) })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-active`, children: t("defaultActive") }), _jsxs("select", { id: `${prefix}-active`, disabled: disabled, value: document.settings.defaultActive === undefined ? "" : String(document.settings.defaultActive), onChange: (event) => actions.editPath(["settings", "defaultActive"], event.currentTarget.value === "" ? undefined : event.currentTarget.value === "true"), children: [_jsx("option", { value: "", children: t("inherit") }), _jsx("option", { value: "true", children: t("enabled") }), _jsx("option", { value: "false", children: t("disabled") })] }), _jsx("p", { className: "dsmm-hint", children: t("activeHint") })] }), _jsxs("fieldset", { children: [_jsx("legend", { children: t("profileDefaults") }), _jsx(PolicyFields, { t: t, value: document.runtimePolicy, inherited: baseline, path: ["settings", "runtimePolicy"], name: t("profileDefaults"), disabled: disabled, actions: actions })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-role`, children: t("roleSelect") }), _jsxs("select", { id: `${prefix}-role`, disabled: disabled || roles.length === 0 || state.invalidFields.length > 0, value: role?.id ?? "", onChange: (event) => setSelectedRole(event.currentTarget.value), children: [roles.length === 0 && _jsx("option", { value: "", children: t("rolesUnavailable") }), roles.map((candidate) => _jsxs("option", { value: candidate.id, children: [candidate.label, candidate.enabled ? "" : ` — ${t("roleDisabled")}`] }, candidate.id))] })] }), role !== undefined && policy !== undefined && _jsxs("fieldset", { "data-dsmm-role": role.id, children: [_jsx("legend", { children: role.label }), _jsx("p", { className: "dsmm-hint", children: t(role.enabled ? "roleEnabled" : "roleDisabled") }), _jsx(PolicyFields, { t: t, value: policy, inherited: inherited, path: rolePath, name: role.label, disabled: disabled, actions: actions }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-primary-mode`, children: t("primaryMode", { name: role.label }) }), _jsxs("select", { id: `${prefix}-primary-mode`, disabled: disabled, value: policy.primary === undefined ? "inherit" : "explicit", onChange: (event) => actions.editPath([...rolePath, "primary"], event.currentTarget.value === "inherit" ? undefined : { provider: "", model: "" }), children: [_jsx("option", { value: "inherit", children: t("inheritRoute") }), _jsx("option", { value: "explicit", children: t("configuredRoute") })] })] }), policy.primary !== undefined && _jsx(RouteFields, { t: t, value: policy.primary, path: [...rolePath, "primary"], name: t("primaryName", { name: role.label }), catalog: state.catalog, disabled: disabled, edit: actions.editPath, editRoute: actions.editRoute }), _jsx("p", { className: "dsmm-hint", children: t("effortChangeHint") }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-fallback-mode`, children: t("fallbackMode", { name: role.label }) }), _jsxs("select", { id: `${prefix}-fallback-mode`, disabled: disabled, value: policy.fallbackRoutes === undefined ? "inherit" : "explicit", onChange: (event) => actions.editPath([...rolePath, "fallbackRoutes"], event.currentTarget.value === "inherit" ? undefined : []), children: [_jsx("option", { value: "inherit", children: t("inheritChain") }), _jsx("option", { value: "explicit", children: t("configuredChain") })] })] }), policy.fallbackRoutes?.length === 0 && _jsx("p", { className: "dsmm-hint", children: t("emptyChain") }), policy.fallbackRoutes?.map((candidate, index) => {
69
+ const availability = roleAvailability(role?.availability);
70
+ const namedRoles = document.settings.roles;
71
+ const topology = document.settings.subagents?.toolTopology;
72
+ return _jsxs("div", { className: "dsmm-structured", "data-dsmm-structured": true, children: [_jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-label`, children: t("profileLabel") }), _jsx(Input, { id: `${prefix}-label`, className: "dsmm-input", value: document.label ?? "", disabled: disabled, onChange: (event) => actions.editPath(["label"], event.currentTarget.value) }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled || document.label === undefined, onClick: () => actions.editPath(["label"], undefined), children: t("omitLabel") })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-locale`, children: t("businessLocale") }), _jsxs("select", { id: `${prefix}-locale`, value: String(document.settings.locale ?? ""), disabled: disabled, "aria-describedby": `${prefix}-locale-hint`, onChange: event => actions.editPath(["settings", "locale"], event.currentTarget.value || undefined), children: [_jsx("option", { value: "", children: t("inheritLocale") }), typeof document.settings.locale === "string" && !DSMM_LOCALES.includes(document.settings.locale) && _jsx("option", { value: document.settings.locale, children: t("unsupportedLocale") }), DSMM_LOCALES.map(locale => _jsx("option", { value: locale, children: locale }, locale))] }), _jsx("p", { id: `${prefix}-locale-hint`, className: "dsmm-hint", children: t("localeHint") })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-topology`, children: t("toolTopology") }), _jsxs("select", { id: `${prefix}-topology`, value: topology ?? "", disabled: disabled, "aria-describedby": `${prefix}-topology-hint`, onChange: event => actions.editPath(["settings", "subagents", "toolTopology"], event.currentTarget.value || undefined), children: [_jsx("option", { value: "", children: t("inherit") }), _jsx("option", { value: "per-role", children: "per-role" }), _jsx("option", { value: "parameterized", children: "parameterized" })] }), _jsx("p", { id: `${prefix}-topology-hint`, className: "dsmm-hint", children: t("topologyHint") })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-active`, children: t("defaultActive") }), _jsxs("select", { id: `${prefix}-active`, disabled: disabled, value: document.settings.defaultActive === undefined ? "" : String(document.settings.defaultActive), onChange: (event) => actions.editPath(["settings", "defaultActive"], event.currentTarget.value === "" ? undefined : event.currentTarget.value === "true"), children: [_jsx("option", { value: "", children: t("inherit") }), _jsx("option", { value: "true", children: t("enabled") }), _jsx("option", { value: "false", children: t("disabled") })] }), _jsx("p", { className: "dsmm-hint", children: t("activeHint") })] }), _jsxs("fieldset", { children: [_jsx("legend", { children: t("profileDefaults") }), _jsx(PolicyFields, { t: t, value: document.runtimePolicy, inherited: baseline, path: ["settings", "runtimePolicy"], name: t("profileDefaults"), disabled: disabled, actions: actions })] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-role`, children: t("roleSelect") }), _jsxs("select", { id: `${prefix}-role`, disabled: disabled || roles.length === 0 || state.invalidFields.length > 0, value: role?.id ?? "", onChange: (event) => setSelectedRole(event.currentTarget.value), children: [roles.length === 0 && _jsx("option", { value: "", children: t("rolesUnavailable") }), roles.map((candidate) => _jsxs("option", { value: candidate.id, children: [candidate.label, candidate.enabled ? "" : ` — ${t("roleDisabled")}`] }, candidate.id))] })] }), role !== undefined && policy !== undefined && _jsxs("fieldset", { "data-dsmm-role": role.id, children: [_jsx("legend", { children: role.label }), _jsx(RoleAvailability, { value: role.availability, t: t }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-role-enabled`, children: t("namedRole", { name: role.label }) }), _jsxs("select", { id: `${prefix}-role-enabled`, value: namedRoles?.[role.id] === undefined ? "" : String(namedRoles[role.id]), disabled: disabled, "aria-describedby": `${prefix}-role-hint`, onChange: event => actions.editPath(["settings", "roles", role.id], event.currentTarget.value === "" ? undefined : event.currentTarget.value === "true"), children: [_jsx("option", { value: "", children: t("inherit") }), _jsx("option", { value: "true", disabled: availability === undefined || !availability.startupAvailable || !availability.deploymentEnabled || availability.reason === "module-off", children: t("enabled") }), _jsx("option", { value: "false", disabled: availability === undefined || availability.required, children: t("disabled") })] }), _jsx("p", { id: `${prefix}-role-hint`, className: "dsmm-hint", children: t("namedRoleHint") })] }), _jsx(PolicyFields, { t: t, value: policy, inherited: inherited, path: rolePath, name: role.label, disabled: disabled, actions: actions }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-primary-mode`, children: t("primaryMode", { name: role.label }) }), _jsxs("select", { id: `${prefix}-primary-mode`, disabled: disabled, value: policy.primary === undefined ? "inherit" : "explicit", onChange: (event) => actions.editPath([...rolePath, "primary"], event.currentTarget.value === "inherit" ? undefined : { provider: "", model: "" }), children: [_jsx("option", { value: "inherit", children: t("inheritRoute") }), _jsx("option", { value: "explicit", children: t("configuredRoute") })] })] }), policy.primary !== undefined && _jsx(RouteFields, { t: t, value: policy.primary, path: [...rolePath, "primary"], name: t("primaryName", { name: role.label }), catalog: state.catalog, disabled: disabled, edit: actions.editPath, editRoute: actions.editRoute }), _jsx("p", { className: "dsmm-hint", children: t("effortChangeHint") }), _jsx("p", { className: "dsmm-hint", children: t("normalLevel") }), role.id === "dsmm-orchestrator" ? _jsx("p", { className: "dsmm-hint", children: t("orchestratorLevels") }) : _jsxs(_Fragment, { children: [_jsx("p", { className: "dsmm-hint", children: t("levelsHint") }), ["low", "high", "max"].map(level => _jsx(LevelFields, { level: level, value: policy.levels?.[level], path: [...rolePath, "levels", level], catalog: state.catalog, disabled: disabled, actions: actions, t: t }, level))] }), _jsxs("div", { className: "dsmm-field", children: [_jsx("label", { htmlFor: `${prefix}-fallback-mode`, children: t("fallbackMode", { name: role.label }) }), _jsxs("select", { id: `${prefix}-fallback-mode`, disabled: disabled, value: policy.fallbackRoutes === undefined ? "inherit" : "explicit", onChange: (event) => actions.editPath([...rolePath, "fallbackRoutes"], event.currentTarget.value === "inherit" ? undefined : []), children: [_jsx("option", { value: "inherit", children: t("inheritChain") }), _jsx("option", { value: "explicit", children: t("configuredChain") })] })] }), policy.fallbackRoutes?.length === 0 && _jsx("p", { className: "dsmm-hint", children: t("emptyChain") }), policy.fallbackRoutes?.map((candidate, index) => {
65
73
  const name = t("fallbackName", { name: role.label, index: index + 1 });
66
74
  return _jsxs("fieldset", { children: [_jsx("legend", { children: name }), _jsx(RouteFields, { t: t, value: candidate, path: [...rolePath, "fallbackRoutes", index], name: name, catalog: state.catalog, disabled: disabled, edit: actions.editPath, editRoute: actions.editRoute }), _jsxs("div", { className: "dsmm-actions", children: [_jsx(Button, { type: "button", variant: "outline", disabled: disabled || index === 0, onClick: () => actions.moveFallback(role.id, index, index - 1), children: t("moveUp", { name }) }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled || index === policy.fallbackRoutes.length - 1, onClick: () => actions.moveFallback(role.id, index, index + 1), children: t("moveDown", { name }) }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled, onClick: () => actions.editPath([...rolePath, "fallbackRoutes", index], undefined), children: t("removeFallback", { name }) })] })] }, index);
67
75
  }), _jsx(Button, { type: "button", variant: "outline", disabled: disabled || (policy.fallbackRoutes?.length ?? 0) >= 32, onClick: () => {
@@ -69,6 +77,6 @@ export function StructuredEditor({ state, actions, disabled, t }) {
69
77
  actions.editPath([...rolePath, "fallbackRoutes"], [{ provider: "", model: "" }]);
70
78
  else
71
79
  actions.editPath([...rolePath, "fallbackRoutes", policy.fallbackRoutes.length], { provider: "", model: "" });
72
- }, children: t("addFallback", { name: role.label }) })] })] });
80
+ }, children: t("addFallback", { name: role.label }) })] }, role.id)] });
73
81
  }
74
82
  //# sourceMappingURL=StructuredEditor.js.map
@@ -0,0 +1,98 @@
1
+ import type { DsmmChildrenRemote } from "../role-control-remote.js";
2
+ import type { BackgroundTransitionResult, ChildSessionSnapshot, RoleControlAvailability, RoleControlDescendantsSnapshot, RoleControlErrorInfo, SubagentInterruptReceipt, SubagentPromptReceipt, SubagentPromptRequest } from "../role-control-types.js";
3
+ export interface ChildrenIssue extends Partial<RoleControlErrorInfo> {
4
+ kind: "domain" | "transport" | "protocol" | "local";
5
+ code: RoleControlErrorInfo["code"];
6
+ unknown?: boolean;
7
+ }
8
+ export type ChildImage = Extract<SubagentPromptRequest["content"][number], {
9
+ type: "image";
10
+ }>;
11
+ export interface ChildDraft {
12
+ text: string;
13
+ delivery: "queue" | "steer";
14
+ images: readonly ChildImage[];
15
+ imageBusy: boolean;
16
+ uncertain: boolean;
17
+ }
18
+ export type ChildOutcome = {
19
+ kind: "background";
20
+ receipt: BackgroundTransitionResult;
21
+ } | {
22
+ kind: "prompt";
23
+ receipt: SubagentPromptReceipt;
24
+ } | {
25
+ kind: "interrupt";
26
+ receipt: SubagentInterruptReceipt;
27
+ };
28
+ export interface ChildrenSnapshot {
29
+ sessionId: string | null;
30
+ generation: number;
31
+ snapshot: ChildSessionSnapshot | null;
32
+ descendants: RoleControlDescendantsSnapshot | null;
33
+ fresh: boolean;
34
+ reading: boolean;
35
+ issue: ChildrenIssue | null;
36
+ descendantIssue: ChildrenIssue | null;
37
+ drafts: ReadonlyMap<string, ChildDraft>;
38
+ pending: ReadonlyMap<string, "background" | "prompt" | "interrupt">;
39
+ issues: ReadonlyMap<string, ChildrenIssue>;
40
+ outcomes: ReadonlyMap<string, ChildOutcome>;
41
+ }
42
+ export interface ChildrenActions {
43
+ refresh(generation: number): Promise<void>;
44
+ background(generation: number, toolCallId: string, runId: string): Promise<void>;
45
+ prompt(generation: number, childId: string): Promise<void>;
46
+ interrupt(generation: number, childId: string): Promise<void>;
47
+ editText(generation: number, childId: string, text: string): void;
48
+ setDelivery(generation: number, childId: string, delivery: "queue" | "steer"): void;
49
+ addImages(generation: number, childId: string, files: readonly File[]): Promise<void>;
50
+ removeImage(generation: number, childId: string, image: ChildImage): void;
51
+ acknowledgeUnknown(generation: number, childId: string): void;
52
+ }
53
+ export declare const EMPTY_CHILD_DRAFT: ChildDraft;
54
+ export declare const childActionKey: (childId: string) => string;
55
+ export declare const runActionKey: (toolCallId: string, runId: string) => string;
56
+ export declare function enabled(availability: RoleControlAvailability | undefined): boolean;
57
+ /** Client presentation/draft state only. Host owns all run, inbox and admission authority. */
58
+ export declare class ChildrenController {
59
+ private readonly remote;
60
+ private current;
61
+ private owner;
62
+ private connection;
63
+ private connectionGeneration;
64
+ private observedAdmission;
65
+ private disposed;
66
+ private listeners;
67
+ readonly store: {
68
+ getSnapshot: () => ChildrenSnapshot;
69
+ subscribe: (listener: () => void) => (() => void);
70
+ };
71
+ readonly actions: ChildrenActions;
72
+ constructor(remote: DsmmChildrenRemote);
73
+ dispose(): void;
74
+ bindConnection(connection: object | null, generation?: unknown): void;
75
+ bindScope(sessionId: string | null, owner: object | null): void;
76
+ observeAdmission(sessionId: string, epoch: string): void;
77
+ private publish;
78
+ private fence;
79
+ private live;
80
+ private available;
81
+ private draft;
82
+ private child;
83
+ private editDraft;
84
+ private publishDraft;
85
+ private issue;
86
+ private unwrap;
87
+ refresh(generation: number): Promise<void>;
88
+ private begin;
89
+ private finish;
90
+ private refuse;
91
+ private accepted;
92
+ background(generation: number, toolCallId: string, runId: string): Promise<void>;
93
+ private canControl;
94
+ prompt(generation: number, id: string): Promise<void>;
95
+ interrupt(generation: number, id: string): Promise<void>;
96
+ addImages(generation: number, id: string, files: readonly File[]): Promise<void>;
97
+ }
98
+ //# sourceMappingURL=children-controller.d.ts.map
@@ -0,0 +1,296 @@
1
+ import { ROLE_CONTROL_REMOTE, parseChildSessionSnapshot, parseRoleControlDescendants, parseRoleControlErrorInfo, parseRoleControlPromptRequest } from "../role-control-remote.js";
2
+ export const EMPTY_CHILD_DRAFT = { text: "", delivery: "queue", images: [], imageBusy: false, uncertain: false };
3
+ export const childActionKey = (childId) => `child:${childId}`;
4
+ export const runActionKey = (toolCallId, runId) => `run:${JSON.stringify([toolCallId, runId])}`;
5
+ export function enabled(availability) { return availability?.enabled === true; }
6
+ class ControlFailure extends Error {
7
+ safe;
8
+ constructor(safe) {
9
+ super("Child control refused.");
10
+ this.safe = safe;
11
+ }
12
+ }
13
+ /** Client presentation/draft state only. Host owns all run, inbox and admission authority. */
14
+ export class ChildrenController {
15
+ remote;
16
+ current = { sessionId: null, generation: 0, snapshot: null, descendants: null, fresh: false, reading: false,
17
+ issue: null, descendantIssue: null, drafts: new Map(), pending: new Map(), issues: new Map(), outcomes: new Map() };
18
+ owner = null;
19
+ connection = null;
20
+ connectionGeneration;
21
+ observedAdmission = null;
22
+ disposed = false;
23
+ listeners = new Set();
24
+ store = {
25
+ getSnapshot: () => this.current,
26
+ subscribe: (listener) => { this.listeners.add(listener); return () => { this.listeners.delete(listener); }; },
27
+ };
28
+ actions = {
29
+ refresh: generation => this.refresh(generation), background: (generation, call, run) => this.background(generation, call, run),
30
+ prompt: (generation, child) => this.prompt(generation, child), interrupt: (generation, child) => this.interrupt(generation, child),
31
+ editText: (generation, child, text) => this.editDraft(generation, child, { text }),
32
+ setDelivery: (generation, child, delivery) => this.editDraft(generation, child, { delivery }),
33
+ addImages: (generation, child, files) => this.addImages(generation, child, files),
34
+ removeImage: (generation, child, image) => { const draft = this.draft(child); if (!draft.imageBusy)
35
+ this.editDraft(generation, child, { images: draft.images.filter(part => part !== image) }); },
36
+ acknowledgeUnknown: (generation, child) => { if (this.available(generation))
37
+ this.editDraft(generation, child, { uncertain: false }); },
38
+ };
39
+ constructor(remote) {
40
+ this.remote = remote;
41
+ }
42
+ dispose() { if (this.disposed)
43
+ return; this.owner = null; this.connection = null; this.fence(false); this.disposed = true; this.listeners.clear(); }
44
+ bindConnection(connection, generation) {
45
+ if (this.disposed || connection === this.connection && generation === this.connectionGeneration)
46
+ return;
47
+ this.connection = connection;
48
+ this.connectionGeneration = generation;
49
+ this.fence(true);
50
+ if (connection !== null)
51
+ void this.refresh(this.current.generation);
52
+ }
53
+ bindScope(sessionId, owner) {
54
+ if (this.disposed || sessionId === this.current.sessionId && owner === this.owner)
55
+ return;
56
+ this.owner = owner;
57
+ this.observedAdmission = null;
58
+ this.fence(false, sessionId);
59
+ if (sessionId !== null && owner !== null)
60
+ void this.refresh(this.current.generation);
61
+ }
62
+ observeAdmission(sessionId, epoch) {
63
+ if (this.disposed || sessionId !== this.current.sessionId || epoch === this.observedAdmission)
64
+ return;
65
+ this.observedAdmission = epoch;
66
+ if (this.current.snapshot?.admissionEpoch === epoch)
67
+ return;
68
+ this.fence(true);
69
+ void this.refresh(this.current.generation);
70
+ }
71
+ publish(patch) {
72
+ if (this.disposed)
73
+ return;
74
+ this.current = { ...this.current, ...patch };
75
+ for (const listener of this.listeners)
76
+ listener();
77
+ }
78
+ fence(preserveDrafts, sessionId = this.current.sessionId) {
79
+ const drafts = new Map();
80
+ if (preserveDrafts)
81
+ for (const [id, draft] of this.current.drafts)
82
+ drafts.set(id, { ...draft, imageBusy: false,
83
+ uncertain: draft.uncertain || this.current.pending.get(childActionKey(id)) === "prompt" });
84
+ this.publish({ sessionId, generation: this.current.generation + 1, snapshot: preserveDrafts ? this.current.snapshot : null,
85
+ fresh: false, descendants: null, reading: false, drafts, pending: new Map(), issues: new Map(), outcomes: new Map(), issue: null, descendantIssue: null });
86
+ }
87
+ live(generation) { return !this.disposed && generation === this.current.generation && this.owner !== null && this.connection !== null && this.current.sessionId !== null; }
88
+ available(generation) { return this.live(generation) && this.current.fresh && !this.current.reading; }
89
+ draft(id) { return this.current.drafts.get(id) ?? EMPTY_CHILD_DRAFT; }
90
+ child(id) { return this.current.snapshot?.children.find(child => child.id === id && child.parentSessionId === this.current.sessionId); }
91
+ editDraft(generation, id, patch) {
92
+ if (this.disposed || generation !== this.current.generation || this.child(id)?.mode !== "continuable" || this.current.pending.has(childActionKey(id)))
93
+ return;
94
+ this.publishDraft(id, patch);
95
+ }
96
+ publishDraft(id, patch) {
97
+ const drafts = new Map(this.current.drafts);
98
+ drafts.set(id, { ...this.draft(id), ...patch });
99
+ this.publish({ drafts });
100
+ }
101
+ issue(error) {
102
+ if (error instanceof ControlFailure)
103
+ return error.safe;
104
+ return { kind: "transport", code: "unavailable", unknown: true };
105
+ }
106
+ async unwrap(method, call) {
107
+ const result = await call();
108
+ if (!result.ok) {
109
+ if (result.error.code === "dsmm-children/refused") {
110
+ let info;
111
+ try {
112
+ info = parseRoleControlErrorInfo(result.error.details);
113
+ }
114
+ catch {
115
+ throw new ControlFailure({ kind: "protocol", code: "unavailable", unknown: true });
116
+ }
117
+ throw new ControlFailure({ kind: "domain", ...info });
118
+ }
119
+ throw new ControlFailure({ kind: "transport", code: "unavailable", unknown: true });
120
+ }
121
+ try {
122
+ const codec = ROLE_CONTROL_REMOTE.descriptors.find(row => row.method === method).result;
123
+ if (codec.mode !== "strict")
124
+ throw new TypeError("Child result requires a strict codec.");
125
+ return codec.create().parse(result.value);
126
+ }
127
+ catch {
128
+ throw new ControlFailure({ kind: "protocol", code: "unavailable", unknown: true });
129
+ }
130
+ }
131
+ async refresh(generation) {
132
+ if (!this.live(generation) || this.current.reading || this.current.pending.size > 0 || [...this.current.drafts.values()].some(draft => draft.imageBusy))
133
+ return;
134
+ const id = this.current.sessionId;
135
+ this.publish({ reading: true, issue: null, descendantIssue: null, fresh: false });
136
+ const [description, descendants] = await Promise.allSettled([this.unwrap("describe", () => this.remote.describe(id)), this.unwrap("descendants", () => this.remote.descendants(id))]);
137
+ if (!this.live(generation))
138
+ return;
139
+ if (description.status === "rejected") {
140
+ this.publish({ reading: false, issue: this.issue(description.reason), descendants: null });
141
+ return;
142
+ }
143
+ const snapshot = parseChildSessionSnapshot(description.value);
144
+ if (snapshot.sessionId !== id) {
145
+ this.publish({ reading: false, issue: { kind: "protocol", code: "not-owned" }, descendants: null });
146
+ return;
147
+ }
148
+ if (this.observedAdmission !== null && snapshot.admissionEpoch !== this.observedAdmission) {
149
+ this.publish({ reading: false, issue: { kind: "protocol", code: "conflict" }, descendants: null });
150
+ return;
151
+ }
152
+ let tree = null, descendantIssue = null;
153
+ if (descendants.status === "rejected")
154
+ descendantIssue = this.issue(descendants.reason);
155
+ else {
156
+ tree = parseRoleControlDescendants(descendants.value);
157
+ if (tree.sessionId !== id || tree.admissionEpoch !== snapshot.admissionEpoch) {
158
+ tree = null;
159
+ descendantIssue = { kind: "protocol", code: "conflict" };
160
+ }
161
+ }
162
+ this.publish({ snapshot, descendants: tree, descendantIssue, fresh: true, reading: false, generation: generation + 1 });
163
+ }
164
+ begin(key, kind) {
165
+ const pending = new Map(this.current.pending), issues = new Map(this.current.issues), outcomes = new Map(this.current.outcomes);
166
+ pending.set(key, kind);
167
+ issues.delete(key);
168
+ outcomes.delete(key);
169
+ this.publish({ pending, issues, outcomes });
170
+ }
171
+ finish(key) { const pending = new Map(this.current.pending); pending.delete(key); this.publish({ pending }); }
172
+ refuse(key, error) { const issues = new Map(this.current.issues); issues.set(key, this.issue(error)); this.publish({ issues }); }
173
+ accepted(key, outcome) { const outcomes = new Map(this.current.outcomes); outcomes.set(key, outcome); this.publish({ outcomes }); }
174
+ async background(generation, toolCallId, runId) {
175
+ const key = runActionKey(toolCallId, runId), snapshot = this.current.snapshot;
176
+ const run = snapshot?.runs.find(row => row.toolCallId === toolCallId && row.invocation?.runId === runId);
177
+ if (!this.available(generation) || this.current.pending.has(key) || this.current.outcomes.get(key)?.kind === "background"
178
+ || run?.state !== "running" || !enabled(run.background) || !enabled(snapshot?.capabilities.background))
179
+ return;
180
+ this.begin(key, "background");
181
+ try {
182
+ const receipt = await this.unwrap("background", () => this.remote.background(snapshot.sessionId, { sessionId: snapshot.sessionId, toolCallId, runId, expectedAdmissionEpoch: snapshot.admissionEpoch }));
183
+ if (!this.live(generation))
184
+ return;
185
+ if (receipt.runId !== runId)
186
+ throw new ControlFailure({ kind: "protocol", code: "conflict", unknown: true });
187
+ this.accepted(key, { kind: "background", receipt });
188
+ }
189
+ catch (error) {
190
+ if (this.live(generation))
191
+ this.refuse(key, error);
192
+ }
193
+ finally {
194
+ if (this.live(generation))
195
+ this.finish(key);
196
+ }
197
+ }
198
+ canControl(generation, id, action) {
199
+ const child = this.child(id);
200
+ return this.available(generation) && !this.current.pending.has(childActionKey(id)) && child?.mode === "continuable" && !child.readonly
201
+ && enabled(child.controls[action]) && enabled(this.current.snapshot?.capabilities[action]);
202
+ }
203
+ async prompt(generation, id) {
204
+ const draft = this.draft(id), key = childActionKey(id);
205
+ if (!this.canControl(generation, id, "prompt") || draft.uncertain || draft.imageBusy || draft.text.trim() === "" && draft.images.length === 0
206
+ || draft.images.length > 0 && !enabled(this.current.snapshot?.capabilities.images))
207
+ return;
208
+ this.begin(key, "prompt");
209
+ try {
210
+ let clientTimeZone;
211
+ try {
212
+ clientTimeZone = Intl.DateTimeFormat().resolvedOptions().timeZone;
213
+ }
214
+ catch { /* Omission delegates to native zone handling. */ }
215
+ let request;
216
+ try {
217
+ request = parseRoleControlPromptRequest({ requestId: crypto.randomUUID(), parentSessionId: this.current.sessionId, childSessionId: id, mode: "continuable", delivery: draft.delivery,
218
+ content: [...(draft.text === "" ? [] : [{ type: "text", text: draft.text }]), ...draft.images], ...(clientTimeZone === undefined ? {} : { clientTimeZone }) });
219
+ }
220
+ catch {
221
+ throw new ControlFailure({ kind: "local", code: "invalid-content" });
222
+ }
223
+ const receipt = await this.unwrap("prompt", () => this.remote.prompt(this.current.sessionId, request));
224
+ if (!this.live(generation))
225
+ return;
226
+ this.accepted(key, { kind: "prompt", receipt });
227
+ const drafts = new Map(this.current.drafts);
228
+ drafts.set(id, { ...draft, text: "", images: [], uncertain: false });
229
+ this.publish({ drafts });
230
+ }
231
+ catch (error) {
232
+ if (this.live(generation)) {
233
+ const issue = this.issue(error);
234
+ this.refuse(key, error);
235
+ if (issue.unknown) {
236
+ const drafts = new Map(this.current.drafts);
237
+ drafts.set(id, { ...this.draft(id), uncertain: true });
238
+ this.publish({ drafts });
239
+ }
240
+ }
241
+ }
242
+ finally {
243
+ if (this.live(generation))
244
+ this.finish(key);
245
+ }
246
+ }
247
+ async interrupt(generation, id) {
248
+ if (!this.canControl(generation, id, "interrupt"))
249
+ return;
250
+ const key = childActionKey(id);
251
+ this.begin(key, "interrupt");
252
+ try {
253
+ const receipt = await this.unwrap("interrupt", () => this.remote.interrupt(this.current.sessionId, { parentSessionId: this.current.sessionId, childSessionId: id, mode: "continuable" }));
254
+ if (this.live(generation))
255
+ this.accepted(key, { kind: "interrupt", receipt });
256
+ }
257
+ catch (error) {
258
+ if (this.live(generation))
259
+ this.refuse(key, error);
260
+ }
261
+ finally {
262
+ if (this.live(generation))
263
+ this.finish(key);
264
+ }
265
+ }
266
+ async addImages(generation, id, files) {
267
+ if (!this.canControl(generation, id, "prompt") || !enabled(this.current.snapshot?.capabilities.images) || this.draft(id).imageBusy || files.length === 0)
268
+ return;
269
+ this.editDraft(generation, id, { imageBusy: true });
270
+ try {
271
+ const images = [];
272
+ for (const file of files) {
273
+ const bytes = new Uint8Array(await file.arrayBuffer());
274
+ if (!this.live(generation))
275
+ return;
276
+ let body = "";
277
+ for (const byte of bytes)
278
+ body += String.fromCharCode(byte);
279
+ const parsed = parseRoleControlPromptRequest({ requestId: "image-intake", parentSessionId: this.current.sessionId, childSessionId: id, mode: "continuable", delivery: "queue",
280
+ content: [{ type: "image", mediaType: file.type, data: btoa(body), name: file.name }] });
281
+ images.push(parsed.content[0]);
282
+ }
283
+ if (this.live(generation))
284
+ this.publishDraft(id, { images: [...this.draft(id).images, ...images] });
285
+ }
286
+ catch {
287
+ if (this.live(generation))
288
+ this.refuse(childActionKey(id), new ControlFailure({ kind: "local", code: "invalid-content" }));
289
+ }
290
+ finally {
291
+ if (this.live(generation))
292
+ this.publishDraft(id, { imageBusy: false });
293
+ }
294
+ }
295
+ }
296
+ //# sourceMappingURL=children-controller.js.map