@dsmm/dsmm 0.1.4 → 0.1.6

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 (52) hide show
  1. package/README.md +13 -12
  2. package/docs/compatibility.md +8 -6
  3. package/docs/migration-from-ocmm.md +8 -0
  4. package/docs/model-routing.md +22 -6
  5. package/docs/profiles.md +23 -9
  6. package/docs/releasing.md +27 -15
  7. package/docs/runtime-recovery.md +41 -14
  8. package/docs/settings-status.md +10 -8
  9. package/lib/client/ProfilesSection.js +7 -3
  10. package/lib/client/SessionProfiles.d.ts +19 -0
  11. package/lib/client/SessionProfiles.js +55 -0
  12. package/lib/client/StructuredEditor.d.ts +11 -0
  13. package/lib/client/StructuredEditor.js +74 -0
  14. package/lib/client/controller.d.ts +68 -1
  15. package/lib/client/controller.js +282 -11
  16. package/lib/client/index.d.ts +3 -1
  17. package/lib/client/index.js +47 -0
  18. package/lib/client/locales.d.ts +109 -0
  19. package/lib/client/locales.js +56 -2
  20. package/lib/client/session-labels.d.ts +8 -0
  21. package/lib/client/session-labels.js +13 -0
  22. package/lib/client/structured.d.ts +18 -0
  23. package/lib/client/structured.js +98 -0
  24. package/lib/client/styles.d.ts +1 -1
  25. package/lib/client/styles.js +14 -1
  26. package/lib/client.js +1215 -74
  27. package/lib/commands.js +1 -0
  28. package/lib/dsh-types.d.ts +16 -0
  29. package/lib/index.js +27 -1
  30. package/lib/model-routing.js +109 -23
  31. package/lib/profile-remote.d.ts +7 -1
  32. package/lib/profile-remote.js +117 -2
  33. package/lib/profile-rpc.d.ts +9 -1
  34. package/lib/profile-rpc.js +99 -2
  35. package/lib/profile-runtime.d.ts +25 -5
  36. package/lib/profile-runtime.js +193 -31
  37. package/lib/profile-store.d.ts +19 -1
  38. package/lib/profile-store.js +120 -10
  39. package/lib/profile-types.d.ts +43 -1
  40. package/lib/profiles.d.ts +1 -1
  41. package/lib/profiles.js +34 -2
  42. package/lib/role-providers.js +12 -2
  43. package/lib/role-routing.d.ts +37 -3
  44. package/lib/role-routing.js +107 -35
  45. package/lib/routing-policy.d.ts +32 -0
  46. package/lib/routing-policy.js +92 -0
  47. package/lib/runtime-recovery.js +216 -52
  48. package/lib/settings.d.ts +27 -1
  49. package/lib/settings.js +29 -7
  50. package/lib/status.d.ts +10 -2
  51. package/lib/status.js +36 -10
  52. package/package.json +8 -1
package/lib/client.js CHANGED
@@ -25,18 +25,70 @@ __export(index_exports, {
25
25
  NS: () => NS,
26
26
  ProfilesController: () => ProfilesController,
27
27
  ProfilesSection: () => ProfilesSection,
28
+ SessionProfiles: () => SessionProfiles,
28
29
  TYPERT_REMOTE: () => TYPERT_REMOTE,
29
30
  apply: () => apply,
31
+ editStructuredPath: () => editStructuredPath,
30
32
  en: () => en,
31
33
  inject: () => inject,
34
+ moveFallback: () => moveFallback,
35
+ structuredDocument: () => structuredDocument,
32
36
  zh: () => zh
33
37
  });
34
38
  module.exports = __toCommonJS(index_exports);
35
39
 
40
+ // src/routing-policy.ts
41
+ var DEFAULT_DSMM_RATE_LIMIT_POLICY = Object.freeze({
42
+ maxRetries: 3,
43
+ initialDelayMs: 500,
44
+ maxDelayMs: 1e4,
45
+ maxTotalDelayMs: 3e4,
46
+ switchAfterRateLimits: 3,
47
+ maxSwitches: 2
48
+ });
49
+ var DEFAULT_DSMM_RUNTIME_POLICY = Object.freeze({
50
+ strategy: "startup-lock",
51
+ rateLimit: DEFAULT_DSMM_RATE_LIMIT_POLICY
52
+ });
53
+ var DSMM_RATE_LIMIT_BOUNDS = Object.freeze({
54
+ maxRetries: Object.freeze([0, 10]),
55
+ initialDelayMs: Object.freeze([0, 3e4]),
56
+ maxDelayMs: Object.freeze([0, 3e4]),
57
+ maxTotalDelayMs: Object.freeze([0, 12e4]),
58
+ switchAfterRateLimits: Object.freeze([1, 10]),
59
+ maxSwitches: Object.freeze([0, 10])
60
+ });
61
+ function normalizeRoutingStrategy(value) {
62
+ if (value !== "startup-lock" && value !== "rate-limit-fallback") {
63
+ throw new TypeError("dsmm strategy must be startup-lock or rate-limit-fallback");
64
+ }
65
+ return value;
66
+ }
67
+ function normalizeRateLimitOverrides(value) {
68
+ if (!isRecord(value)) throw new TypeError("dsmm rateLimit must be an object");
69
+ const result = {};
70
+ for (const [field, raw] of Object.entries(value)) {
71
+ if (!Object.hasOwn(DSMM_RATE_LIMIT_BOUNDS, field)) throw new TypeError("dsmm rateLimit contains an unknown field");
72
+ const [minimum, maximum] = DSMM_RATE_LIMIT_BOUNDS[field];
73
+ if (typeof raw !== "number" || !Number.isSafeInteger(raw) || raw < minimum || raw > maximum) {
74
+ throw new TypeError(`dsmm rateLimit ${field} must be an integer from ${minimum} to ${maximum}`);
75
+ }
76
+ result[field] = raw;
77
+ }
78
+ return result;
79
+ }
80
+ function normalizeRateLimitPolicy(value = void 0, defaults = DEFAULT_DSMM_RATE_LIMIT_POLICY) {
81
+ return { ...defaults, ...value === void 0 ? {} : normalizeRateLimitOverrides(value) };
82
+ }
83
+ function isRecord(value) {
84
+ return typeof value === "object" && value !== null && !Array.isArray(value);
85
+ }
86
+
36
87
  // src/profile-remote.ts
37
- var errorCodes = /* @__PURE__ */ new Set(["validation", "conflict", "not-found", "lock-timeout", "unsafe-path", "io", "activation", "corrupt-selection", "limit"]);
88
+ var errorCodes = /* @__PURE__ */ new Set(["validation", "conflict", "not-found", "lock-timeout", "unsafe-path", "io", "activation", "corrupt-selection", "limit", "busy", "maintenance", "disposed", "not-owned", "unavailable", "cancelled"]);
38
89
  var idPattern = /^[a-z0-9][a-z0-9_-]{0,63}$/u;
39
90
  var revisionPattern = /^[a-f0-9]{64}$/u;
91
+ var rolePattern = /^dsmm-(?:orchestrator|planner|plan-critic|builder|reviewer|oracle|oracle-2nd|creative|code-search|doc-search|clarifier|media-reader)$/u;
40
92
  function isProfileId(value) {
41
93
  return typeof value === "string" && idPattern.test(value) && !/^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])$/iu.test(value);
42
94
  }
@@ -60,14 +112,38 @@ function revision(value) {
60
112
  function selectionRevision(value) {
61
113
  return value === "absent" ? value : revision(value);
62
114
  }
115
+ function isNativeSessionId(value) {
116
+ return typeof value === "string" && value.length > 0 && value.length <= 256 && !/[\u0000-\u001f\u007f]/u.test(value) && new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(new TextEncoder().encode(value)) === value;
117
+ }
118
+ function sessionId(value) {
119
+ if (!isNativeSessionId(value)) fail("sessionId");
120
+ return value;
121
+ }
122
+ function boolean(value, field) {
123
+ if (typeof value !== "boolean") fail(field);
124
+ return value;
125
+ }
126
+ function integer(value, field, maximum = Number.MAX_SAFE_INTEGER) {
127
+ if (typeof value !== "number" || !Number.isSafeInteger(value) || value < 0 || value > maximum) fail(field);
128
+ return value;
129
+ }
130
+ function routeText(value, field, maximum) {
131
+ const result = text(value, field, maximum);
132
+ if (result.trim() === "" || /[\u0000-\u001f\u007f]/u.test(result) || new TextDecoder("utf-8", { fatal: true, ignoreBOM: true }).decode(new TextEncoder().encode(result)) !== result) fail(field);
133
+ return result;
134
+ }
135
+ function role(value) {
136
+ if (typeof value !== "string" || !rolePattern.test(value)) fail("role");
137
+ return value;
138
+ }
63
139
  function object(value, required, optional2 = []) {
64
140
  if (value === null || typeof value !== "object" || Array.isArray(value)) fail("object");
65
141
  const result = value;
66
142
  if (Object.keys(result).some((key) => !required.includes(key) && !optional2.includes(key)) || required.some((key) => !Object.hasOwn(result, key))) fail("object keys");
67
143
  return result;
68
144
  }
69
- function optional(value, key, parse2) {
70
- return Object.hasOwn(value, key) ? { [key]: parse2(value[key]) } : {};
145
+ function optional(value, key, parse3) {
146
+ return Object.hasOwn(value, key) ? { [key]: parse3(value[key]) } : {};
71
147
  }
72
148
  function errorInfo(value) {
73
149
  const item = object(value, ["code", "message"], ["field"]);
@@ -85,7 +161,7 @@ function content(value) {
85
161
  return result;
86
162
  }
87
163
  function snapshot(value) {
88
- const item = object(value, ["profiles", "selectedId", "appliedRevision", "selectionRevision"], ["selectionError"]);
164
+ const item = object(value, ["profiles", "selectedId", "appliedRevision", "selectionRevision"], ["selectionError", "roles", "editorDefaults"]);
89
165
  if (!Array.isArray(item.profiles) || item.profiles.length > 128) fail("profiles");
90
166
  return {
91
167
  profiles: item.profiles.map((input) => {
@@ -95,7 +171,70 @@ function snapshot(value) {
95
171
  selectedId: item.selectedId === null ? null : id(item.selectedId),
96
172
  appliedRevision: item.appliedRevision === null ? null : revision(item.appliedRevision),
97
173
  selectionRevision: item.selectionRevision === "unavailable" && Object.hasOwn(item, "selectionError") ? "unavailable" : selectionRevision(item.selectionRevision),
98
- ...optional(item, "selectionError", errorInfo)
174
+ ...optional(item, "selectionError", errorInfo),
175
+ ...optional(item, "roles", (input) => {
176
+ if (!Array.isArray(input) || input.length > 12) fail("roles");
177
+ const result = input.map((value2) => {
178
+ const row = object(value2, ["id", "label", "enabled"], ["runtimePolicy"]);
179
+ return { id: role(row.id), label: text(row.label, "label", 120), enabled: boolean(row.enabled, "enabled"), ...optional(row, "runtimePolicy", (input2) => {
180
+ const policy = object(input2, [], ["strategy", "rateLimit"]);
181
+ return { ...optional(policy, "strategy", normalizeRoutingStrategy), ...optional(policy, "rateLimit", normalizeRateLimitOverrides) };
182
+ }) };
183
+ });
184
+ if (new Set(result.map((row) => row.id)).size !== result.length) fail("roles");
185
+ return result;
186
+ }),
187
+ ...optional(item, "editorDefaults", runtimePolicy)
188
+ };
189
+ }
190
+ function rateLimit(value) {
191
+ const item = object(value, Object.keys(DSMM_RATE_LIMIT_BOUNDS));
192
+ return normalizeRateLimitPolicy(item);
193
+ }
194
+ function runtimePolicy(value) {
195
+ const item = object(value, ["strategy", "rateLimit"]);
196
+ return { strategy: normalizeRoutingStrategy(item.strategy), rateLimit: rateLimit(item.rateLimit) };
197
+ }
198
+ function rolePolicy(value) {
199
+ const item = object(value, ["strategy", "rateLimit", "retries", "rateLimitFailures", "switches", "totalDelayMs"], ["role", "route"]);
200
+ return {
201
+ ...runtimePolicy({ strategy: item.strategy, rateLimit: item.rateLimit }),
202
+ retries: integer(item.retries, "retries", 10),
203
+ rateLimitFailures: integer(item.rateLimitFailures, "rateLimitFailures"),
204
+ switches: integer(item.switches, "switches", 10),
205
+ totalDelayMs: integer(item.totalDelayMs, "totalDelayMs", 12e4),
206
+ ...optional(item, "role", role),
207
+ ...optional(item, "route", modelRoute)
208
+ };
209
+ }
210
+ function modelRoute(value) {
211
+ const route2 = object(value, ["provider", "model"], ["reasoningEffort"]);
212
+ const provider = routeText(route2.provider, "provider", 128);
213
+ const model = routeText(route2.model, "model", 512);
214
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/u.test(provider) || model.includes("://")) fail("route");
215
+ return { provider, model, ...optional(route2, "reasoningEffort", (input) => routeText(input, "reasoningEffort", 64)) };
216
+ }
217
+ function selectionState(value) {
218
+ const item = object(value, ["selectedId", "appliedRevision", "selectionRevision"]);
219
+ return { selectedId: item.selectedId === null ? null : id(item.selectedId), appliedRevision: item.appliedRevision === null ? null : revision(item.appliedRevision), selectionRevision: selectionRevision(item.selectionRevision) };
220
+ }
221
+ function sessionSnapshot(value) {
222
+ const item = object(value, ["sessionId", "globalDefault", "selection", "scope", "admissionEpoch", "switchAllowed"], ["admittedSelection", "switchUnavailableReason", "rolePolicy", "profileModel"]);
223
+ if (typeof item.scope !== "string" || !["global-default", "session-override", "deployment-baseline"].includes(item.scope)) fail("scope");
224
+ return {
225
+ sessionId: sessionId(item.sessionId),
226
+ globalDefault: selectionState(item.globalDefault),
227
+ selection: selectionState(item.selection),
228
+ scope: item.scope,
229
+ admissionEpoch: revision(item.admissionEpoch),
230
+ switchAllowed: boolean(item.switchAllowed, "switchAllowed"),
231
+ ...optional(item, "admittedSelection", selectionState),
232
+ ...optional(item, "switchUnavailableReason", (input) => {
233
+ if (typeof input !== "string" || !["busy", "maintenance", "disposed", "not-owned", "unavailable"].includes(input)) fail("switchUnavailableReason");
234
+ return input;
235
+ }),
236
+ ...optional(item, "rolePolicy", rolePolicy),
237
+ ...optional(item, "profileModel", modelRoute)
99
238
  };
100
239
  }
101
240
  function saveRequest(value) {
@@ -109,8 +248,13 @@ function selectRequest(value) {
109
248
  if (result.id === null && result.expectedRevision !== void 0) fail("expectedRevision");
110
249
  return result;
111
250
  }
112
- function codec(symbol, parse2) {
113
- return { mode: "strict", typeSymbol: `@dsmm/dsmm#${symbol}`, create: () => ({ parse: parse2 }) };
251
+ function sessionSelectRequest(value) {
252
+ const item = object(value, ["sessionId", "id", "expectedSelectionRevision", "expectedAdmissionEpoch"], ["expectedRevision"]);
253
+ const { sessionId: inputSessionId, expectedAdmissionEpoch, ...profileRequest } = item;
254
+ return { ...selectRequest(profileRequest), sessionId: sessionId(inputSessionId), expectedAdmissionEpoch: revision(expectedAdmissionEpoch) };
255
+ }
256
+ function codec(symbol, parse3) {
257
+ return { mode: "strict", typeSymbol: `@dsmm/dsmm#${symbol}`, create: () => ({ parse: parse3 }) };
114
258
  }
115
259
  function descriptor(method, result, parameter) {
116
260
  return { id: `@dsmm/dsmm#dsmmProfiles/${method}`, service: "dsmmProfiles", namespace: "dsmmProfiles", method, invocation: { kind: "direct" }, parameters: parameter === void 0 ? [] : [{ name: parameter.name, wire: parameter.name, source: "json", codec: parameter.codec }], result };
@@ -121,7 +265,18 @@ var TYPERT_REMOTE = {
121
265
  descriptor("describe", codec("ProfileSnapshot", snapshot)),
122
266
  descriptor("read", codec("ProfileReadResult", readResult), { name: "id", codec: codec("ProfileId", id) }),
123
267
  descriptor("save", codec("ProfileReadResult", readResult), { name: "request", codec: codec("ProfileSaveRequest", saveRequest) }),
124
- descriptor("select", codec("ProfileSnapshot", snapshot), { name: "request", codec: codec("ProfileSelectRequest", selectRequest) })
268
+ descriptor("select", codec("ProfileSnapshot", snapshot), { name: "request", codec: codec("ProfileSelectRequest", selectRequest) }),
269
+ {
270
+ ...descriptor("describeSession", codec("SessionProfileSnapshot", sessionSnapshot)),
271
+ parameters: [{ name: "sessionId", wire: "sessionId", source: "json", codec: codec("NativeSessionId", sessionId) }]
272
+ },
273
+ {
274
+ ...descriptor("selectSession", codec("SessionProfileSnapshot", sessionSnapshot)),
275
+ parameters: [
276
+ { name: "sessionId", wire: "sessionId", source: "json", codec: codec("NativeSessionId", sessionId) },
277
+ { name: "request", wire: "request", source: "json", codec: codec("SessionProfileSelectRequest", sessionSelectRequest) }
278
+ ]
279
+ }
125
280
  ]
126
281
  };
127
282
  var TYPERT_HOST = {
@@ -827,6 +982,49 @@ var ParseOptions;
827
982
  allowTrailingComma: false
828
983
  };
829
984
  })(ParseOptions || (ParseOptions = {}));
985
+ function parse(text2, errors = [], options = ParseOptions.DEFAULT) {
986
+ let currentProperty = null;
987
+ let currentParent = [];
988
+ const previousParents = [];
989
+ function onValue(value) {
990
+ if (Array.isArray(currentParent)) {
991
+ currentParent.push(value);
992
+ } else if (currentProperty !== null) {
993
+ currentParent[currentProperty] = value;
994
+ }
995
+ }
996
+ const visitor = {
997
+ onObjectBegin: () => {
998
+ const object2 = {};
999
+ onValue(object2);
1000
+ previousParents.push(currentParent);
1001
+ currentParent = object2;
1002
+ currentProperty = null;
1003
+ },
1004
+ onObjectProperty: (name) => {
1005
+ currentProperty = name;
1006
+ },
1007
+ onObjectEnd: () => {
1008
+ currentParent = previousParents.pop();
1009
+ },
1010
+ onArrayBegin: () => {
1011
+ const array = [];
1012
+ onValue(array);
1013
+ previousParents.push(currentParent);
1014
+ currentParent = array;
1015
+ currentProperty = null;
1016
+ },
1017
+ onArrayEnd: () => {
1018
+ currentParent = previousParents.pop();
1019
+ },
1020
+ onLiteralValue: onValue,
1021
+ onError: (error, offset, length) => {
1022
+ errors.push({ error, offset, length });
1023
+ }
1024
+ };
1025
+ visit(text2, visitor, options);
1026
+ return currentParent[0];
1027
+ }
830
1028
  function parseTree(text2, errors = [], options = ParseOptions.DEFAULT) {
831
1029
  let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
832
1030
  function ensurePropertyComplete(endOffset) {
@@ -1417,6 +1615,9 @@ var SyntaxKind;
1417
1615
  SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
1418
1616
  SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
1419
1617
  })(SyntaxKind || (SyntaxKind = {}));
1618
+ var parse2 = parse;
1619
+ var parseTree2 = parseTree;
1620
+ var findNodeAtLocation2 = findNodeAtLocation;
1420
1621
  var ParseErrorCode;
1421
1622
  (function(ParseErrorCode2) {
1422
1623
  ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
@@ -1460,7 +1661,81 @@ function applyEdits(text2, edits) {
1460
1661
  return text2;
1461
1662
  }
1462
1663
 
1664
+ // src/client/structured.ts
1665
+ function record(value) {
1666
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1667
+ }
1668
+ function route(value) {
1669
+ return record(value) && typeof value.provider === "string" && typeof value.model === "string" && (value.reasoningEffort === void 0 || typeof value.reasoningEffort === "string") && Object.keys(value).every((key) => ["provider", "model", "reasoningEffort"].includes(key));
1670
+ }
1671
+ function validTree(node, depth = 0) {
1672
+ if (depth > 32) return false;
1673
+ if (node.type === "object") {
1674
+ const seen = /* @__PURE__ */ new Set();
1675
+ for (const property of node.children ?? []) {
1676
+ const key = property.children?.[0]?.value;
1677
+ if (typeof key !== "string" || seen.has(key) || ["__proto__", "prototype", "constructor"].includes(key)) return false;
1678
+ seen.add(key);
1679
+ }
1680
+ }
1681
+ return (node.children ?? []).every((child) => validTree(child, depth + 1));
1682
+ }
1683
+ function structuredDocument(content2) {
1684
+ const errors = [];
1685
+ const tree = parseTree2(content2, errors, { allowTrailingComma: true });
1686
+ if (errors.length !== 0 || tree === void 0 || !validTree(tree)) return null;
1687
+ const document2 = parse2(content2, errors, { allowTrailingComma: true });
1688
+ if (errors.length !== 0 || !record(document2) || document2.version !== 1 || typeof document2.id !== "string" || !record(document2.settings) || document2.label !== void 0 && typeof document2.label !== "string") return null;
1689
+ const settings = document2.settings;
1690
+ if (settings.defaultActive !== void 0 && typeof settings.defaultActive !== "boolean") return null;
1691
+ if (settings.roleRouting !== void 0 && !record(settings.roleRouting)) return null;
1692
+ if (settings.runtimePolicy !== void 0 && !record(settings.runtimePolicy)) return null;
1693
+ const runtimePolicy2 = settings.runtimePolicy ?? {};
1694
+ const policies = settings.roleRouting ?? {};
1695
+ try {
1696
+ if (Object.keys(runtimePolicy2).some((key) => key !== "strategy" && key !== "rateLimit")) return null;
1697
+ if (runtimePolicy2.strategy !== void 0) normalizeRoutingStrategy(runtimePolicy2.strategy);
1698
+ if (runtimePolicy2.rateLimit !== void 0) normalizeRateLimitOverrides(runtimePolicy2.rateLimit);
1699
+ for (const raw of Object.values(policies)) {
1700
+ if (!record(raw) || Object.keys(raw).some((key) => !["primary", "fallbackRoutes", "strategy", "rateLimit"].includes(key))) return null;
1701
+ if (raw.primary !== void 0 && !route(raw.primary)) return null;
1702
+ if (raw.fallbackRoutes !== void 0 && (!Array.isArray(raw.fallbackRoutes) || raw.fallbackRoutes.length > 32 || !raw.fallbackRoutes.every(route))) return null;
1703
+ if (raw.strategy !== void 0) normalizeRoutingStrategy(raw.strategy);
1704
+ if (raw.rateLimit !== void 0) normalizeRateLimitOverrides(raw.rateLimit);
1705
+ }
1706
+ } catch {
1707
+ return null;
1708
+ }
1709
+ return { label: document2.label, settings, roleRouting: policies, runtimePolicy: runtimePolicy2 };
1710
+ }
1711
+ function editStructuredPath(content2, path, value) {
1712
+ if (structuredDocument(content2) === null) return null;
1713
+ try {
1714
+ return applyEdits(content2, modify(content2, path, value, { formattingOptions: { insertSpaces: true, tabSize: 2 } }));
1715
+ } catch {
1716
+ return null;
1717
+ }
1718
+ }
1719
+ function moveFallback(content2, role2, from, to) {
1720
+ const document2 = structuredDocument(content2);
1721
+ const chain = document2?.roleRouting[role2]?.fallbackRoutes;
1722
+ if (chain === void 0 || from < 0 || from >= chain.length || to < 0 || to >= chain.length) return null;
1723
+ const low = Math.min(from, to), high = Math.max(from, to);
1724
+ const tree = parseTree2(content2);
1725
+ if (tree === void 0) return null;
1726
+ const nodes = chain.map((_, index) => findNodeAtLocation2(tree, ["settings", "roleRouting", role2, "fallbackRoutes", index]));
1727
+ if (nodes.some((node) => node === void 0)) return null;
1728
+ const order = nodes.map((node) => content2.slice(node.offset, node.offset + node.length));
1729
+ order.splice(to, 0, order.splice(from, 1)[0]);
1730
+ return applyEdits(content2, nodes.slice(low, high + 1).map((node, offset) => ({ offset: node.offset, length: node.length, content: order[low + offset] })));
1731
+ }
1732
+
1463
1733
  // src/client/controller.ts
1734
+ function modelSelectionWatermark(window) {
1735
+ let watermark = -1;
1736
+ for (const entry of window.entries) if (entry.type === "event" && entry.event.type === "model/selection") watermark = Math.max(watermark, Number(entry.event.seq));
1737
+ return watermark;
1738
+ }
1464
1739
  var NEW_EDITOR = "";
1465
1740
  var NEW_PROFILE_CONTENT = '{\n "version": 1,\n "id": "new-profile",\n "label": "New profile",\n "settings": {\n // Runtime overlay only. Omitted fields inherit the deployment baseline.\n "defaultActive": true\n }\n}\n';
1466
1741
  function canReconcileSelection(snapshot2) {
@@ -1470,11 +1745,48 @@ var ProfilesController = class {
1470
1745
  constructor(remote) {
1471
1746
  this.remote = remote;
1472
1747
  }
1473
- current = { snapshot: null, editor: null, dirty: false, busy: null, issue: null, notice: null, pendingEditor: null };
1748
+ current = {
1749
+ snapshot: null,
1750
+ editor: null,
1751
+ dirty: false,
1752
+ busy: null,
1753
+ issue: null,
1754
+ notice: null,
1755
+ pendingEditor: null,
1756
+ catalog: null,
1757
+ catalogBusy: false,
1758
+ catalogUnavailable: true,
1759
+ currentSessionId: null,
1760
+ session: null,
1761
+ sessionChoice: null,
1762
+ sessionBusy: null,
1763
+ sessionIssue: null,
1764
+ sessionNotice: null,
1765
+ invalidFields: [],
1766
+ editorEpoch: 0
1767
+ };
1474
1768
  accepted = null;
1475
1769
  listeners = /* @__PURE__ */ new Set();
1476
1770
  generation = 0;
1477
1771
  disposed = false;
1772
+ sessionGeneration = 0;
1773
+ catalogGeneration = 0;
1774
+ catalogRemote = null;
1775
+ modelSelectorGeneration = 0;
1776
+ modelSelector = null;
1777
+ modelSelectionSource = null;
1778
+ modelSelectionSessionId = null;
1779
+ modelSelectionGeneration = 0;
1780
+ stopModelSelection = null;
1781
+ modelEvents = null;
1782
+ modelEventsSessionId = null;
1783
+ modelEventsGeneration = 0;
1784
+ modelEventsWatermark = -1;
1785
+ stopModelEvents = null;
1786
+ modelInteraction = null;
1787
+ modelInteractionSessionId = null;
1788
+ modelInteractionGeneration = 0;
1789
+ stopModelInteraction = null;
1478
1790
  store = {
1479
1791
  getSnapshot: () => this.current,
1480
1792
  subscribe: (listener) => {
@@ -1495,13 +1807,198 @@ var ProfilesController = class {
1495
1807
  apply: () => this.apply(),
1496
1808
  reset: () => this.reset(),
1497
1809
  discardAndOpen: () => this.discardAndOpen(),
1498
- cancelDiscard: () => this.publish({ pendingEditor: null })
1810
+ cancelDiscard: () => this.publish({ pendingEditor: null }),
1811
+ editPath: (path, value) => this.editPath(path, value),
1812
+ moveFallback: (role2, from, to) => this.editFallbackOrder(role2, from, to),
1813
+ editRoute: (path, provider, model) => this.editRoute(path, provider, model),
1814
+ refreshCatalog: () => this.refreshCatalog(),
1815
+ refreshSession: () => this.refreshSession(),
1816
+ chooseSessionProfile: (id2) => {
1817
+ if (!this.disposed && this.current.sessionBusy === null && this.current.busy === null && !this.current.dirty) this.publish({ sessionChoice: id2, sessionNotice: null });
1818
+ },
1819
+ applySession: (options) => this.selectSession(false, options),
1820
+ resetSession: () => this.selectSession(true),
1821
+ setFieldInvalid: (field, invalid) => {
1822
+ if (this.disposed) return;
1823
+ const invalidFields = this.current.invalidFields.filter((candidate) => candidate !== field);
1824
+ if (invalid) invalidFields.push(field);
1825
+ if (invalidFields.join("\n") !== this.current.invalidFields.join("\n")) this.publish({ invalidFields, ...invalid ? { dirty: true } : {} });
1826
+ }
1499
1827
  };
1500
1828
  dispose() {
1501
1829
  this.disposed = true;
1502
1830
  this.generation += 1;
1831
+ this.sessionGeneration += 1;
1832
+ this.catalogGeneration += 1;
1833
+ this.modelSelectorGeneration += 1;
1834
+ this.modelSelectionGeneration += 1;
1835
+ this.stopModelSelection?.();
1836
+ this.stopModelEvents?.();
1837
+ this.stopModelInteraction?.();
1838
+ this.stopModelSelection = null;
1839
+ this.stopModelEvents = null;
1840
+ this.stopModelInteraction = null;
1841
+ this.modelSelectionSource = null;
1842
+ this.modelEvents = null;
1843
+ this.modelInteraction = null;
1844
+ this.catalogRemote = null;
1845
+ this.modelSelector = null;
1503
1846
  this.listeners.clear();
1504
1847
  }
1848
+ attachModelSelector(remote) {
1849
+ if (this.disposed) return;
1850
+ this.modelSelectorGeneration += 1;
1851
+ this.modelSelector = remote;
1852
+ }
1853
+ attachModelSelectionSource(sessionId2, source) {
1854
+ if (this.disposed || sessionId2 === this.modelSelectionSessionId && source === this.modelSelectionSource) return;
1855
+ this.modelSelectionGeneration += 1;
1856
+ this.stopModelSelection?.();
1857
+ this.modelSelectionSessionId = sessionId2;
1858
+ this.modelSelectionSource = source;
1859
+ this.stopModelSelection = source?.subscribe(() => {
1860
+ this.modelSelectionGeneration += 1;
1861
+ }) ?? null;
1862
+ }
1863
+ attachModelEventSource(sessionId2, source) {
1864
+ if (this.disposed || sessionId2 === this.modelEventsSessionId && source === this.modelEvents) return;
1865
+ this.modelEventsGeneration += 1;
1866
+ this.stopModelEvents?.();
1867
+ this.modelEventsSessionId = sessionId2;
1868
+ this.modelEvents = source;
1869
+ this.modelEventsWatermark = source === null ? -1 : modelSelectionWatermark(source.getSnapshot());
1870
+ this.stopModelEvents = source?.subscribe(() => {
1871
+ const window = source.getSnapshot(), change = window.change;
1872
+ if (change.kind === "settle-assistant") return;
1873
+ let watermark = change.kind === "replace" ? -1 : this.modelEventsWatermark;
1874
+ for (const entry of change.entries) if (entry.type === "event" && entry.event.type === "model/selection") watermark = Math.max(watermark, Number(entry.event.seq));
1875
+ if (watermark !== this.modelEventsWatermark) {
1876
+ this.modelEventsWatermark = watermark;
1877
+ this.modelEventsGeneration += 1;
1878
+ }
1879
+ }) ?? null;
1880
+ }
1881
+ attachModelInteractionSource(sessionId2, source) {
1882
+ if (this.disposed || sessionId2 === this.modelInteractionSessionId && source === this.modelInteraction) return;
1883
+ this.modelInteractionGeneration += 1;
1884
+ this.stopModelInteraction?.();
1885
+ this.modelInteractionSessionId = sessionId2;
1886
+ this.modelInteraction = source;
1887
+ this.stopModelInteraction = source?.subscribe(() => {
1888
+ if (source.getSnapshot().status === "selecting") this.modelInteractionGeneration += 1;
1889
+ }) ?? null;
1890
+ }
1891
+ attachCatalog(remote) {
1892
+ if (this.disposed) return;
1893
+ this.catalogGeneration += 1;
1894
+ this.catalogRemote = remote;
1895
+ this.publish({ catalogBusy: false, catalogUnavailable: remote === null });
1896
+ if (remote !== null) void this.refreshCatalog();
1897
+ }
1898
+ setSession(id2) {
1899
+ if (this.disposed || id2 === this.current.currentSessionId) return;
1900
+ this.sessionGeneration += 1;
1901
+ if (id2 !== this.modelSelectionSessionId) this.attachModelSelectionSource(null, null);
1902
+ if (id2 !== this.modelEventsSessionId) this.attachModelEventSource(null, null);
1903
+ if (id2 !== this.modelInteractionSessionId) this.attachModelInteractionSource(null, null);
1904
+ this.publish({ currentSessionId: id2, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
1905
+ if (id2 !== null) void this.refreshSession();
1906
+ }
1907
+ async refreshCatalog() {
1908
+ if (this.disposed || this.current.catalogBusy || this.catalogRemote === null) return;
1909
+ const remote = this.catalogRemote, generation = ++this.catalogGeneration;
1910
+ this.publish({ catalogBusy: true });
1911
+ try {
1912
+ const catalog = await this.unwrap(remote.modelCatalog());
1913
+ if (!this.disposed && generation === this.catalogGeneration) this.publish({ catalog, catalogUnavailable: false });
1914
+ } catch {
1915
+ if (!this.disposed && generation === this.catalogGeneration) this.publish({ catalogUnavailable: true });
1916
+ } finally {
1917
+ if (!this.disposed && generation === this.catalogGeneration) this.publish({ catalogBusy: false });
1918
+ }
1919
+ }
1920
+ async refreshSession() {
1921
+ const id2 = this.current.currentSessionId;
1922
+ if (this.disposed || id2 === null || this.current.sessionBusy !== null) return;
1923
+ const generation = ++this.sessionGeneration;
1924
+ const live = () => !this.disposed && generation === this.sessionGeneration && id2 === this.current.currentSessionId;
1925
+ this.publish({ sessionBusy: "read", sessionIssue: null, sessionNotice: null });
1926
+ try {
1927
+ const session = await this.unwrap(this.remote.describeSession(id2));
1928
+ if (session.sessionId !== id2) throw { kind: "assembly", code: "unavailable" };
1929
+ if (live()) this.publish({ session, sessionChoice: session.selection.selectedId });
1930
+ } catch (error) {
1931
+ if (live()) this.publish({ sessionIssue: this.issue(error) });
1932
+ } finally {
1933
+ if (live()) this.publish({ sessionBusy: null });
1934
+ }
1935
+ }
1936
+ async selectSession(reset, options) {
1937
+ const { currentSessionId: id2, session, sessionChoice, snapshot: snapshot2 } = this.current;
1938
+ if (this.disposed || id2 === null || session === null || !session.switchAllowed || this.current.sessionBusy !== null || this.current.busy !== null || this.current.dirty || this.current.pendingEditor !== null) return;
1939
+ const selectedId = reset ? null : sessionChoice;
1940
+ const revision2 = snapshot2?.profiles.find((profile) => profile.id === selectedId)?.revision;
1941
+ if (selectedId !== null && revision2 == null) return;
1942
+ const generation = ++this.sessionGeneration;
1943
+ const useProfileModel = !reset && options?.useProfileModel === true;
1944
+ const selector = this.modelSelector, selectorGeneration = this.modelSelectorGeneration;
1945
+ const modelSource = this.modelSelectionSource, modelGeneration = this.modelSelectionGeneration;
1946
+ const modelSnapshot = modelSource?.getSnapshot();
1947
+ const eventSource = this.modelEvents, eventGeneration = this.modelEventsGeneration;
1948
+ const eventWatermark = eventSource === null ? -1 : modelSelectionWatermark(eventSource.getSnapshot());
1949
+ const interaction = this.modelInteraction, interactionGeneration = this.modelInteractionGeneration;
1950
+ const pendingNativeChoice = interaction?.getSnapshot().status === "selecting";
1951
+ const live = () => !this.disposed && generation === this.sessionGeneration && id2 === this.current.currentSessionId;
1952
+ const selectorLive = () => live() && selector !== null && selector === this.modelSelector && selectorGeneration === this.modelSelectorGeneration;
1953
+ this.publish({ sessionBusy: reset ? "reset" : "apply", sessionIssue: null, sessionNotice: null });
1954
+ try {
1955
+ const accepted = await this.unwrap(this.remote.selectSession(id2, {
1956
+ sessionId: id2,
1957
+ id: selectedId,
1958
+ ...selectedId === null ? {} : { expectedRevision: revision2 },
1959
+ expectedSelectionRevision: session.selection.selectionRevision,
1960
+ expectedAdmissionEpoch: session.admissionEpoch
1961
+ }));
1962
+ if (accepted.sessionId !== id2) throw { kind: "assembly", code: "unavailable" };
1963
+ if (!live()) return;
1964
+ this.publish({ session: accepted, sessionChoice: accepted.selection.selectedId, sessionNotice: useProfileModel ? null : reset ? "reset" : "applied" });
1965
+ if (!useProfileModel || !live()) return;
1966
+ if (accepted.profileModel === void 0) {
1967
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-unconfigured", source: "profile-model" } });
1968
+ return;
1969
+ }
1970
+ if (!selectorLive()) {
1971
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-service-unavailable", source: "profile-model" } });
1972
+ return;
1973
+ }
1974
+ if (modelSource === null || modelSnapshot === void 0 || this.modelSelectionSessionId !== id2 || modelSource !== this.modelSelectionSource || modelSource.getSnapshot() === void 0) {
1975
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-observation-unavailable", source: "profile-model" } });
1976
+ return;
1977
+ }
1978
+ if (modelGeneration !== this.modelSelectionGeneration || !Object.is(modelSnapshot, modelSource.getSnapshot())) {
1979
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-choice-changed", source: "profile-model" } });
1980
+ return;
1981
+ }
1982
+ if (eventSource === null || eventSource !== this.modelEvents || this.modelEventsSessionId !== id2 || interaction === null || interaction !== this.modelInteraction || this.modelInteractionSessionId !== id2) {
1983
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-observation-unavailable", source: "profile-model" } });
1984
+ return;
1985
+ }
1986
+ if (eventGeneration !== this.modelEventsGeneration || eventWatermark !== modelSelectionWatermark(eventSource.getSnapshot()) || interactionGeneration !== this.modelInteractionGeneration || pendingNativeChoice || interaction.getSnapshot().status === "selecting") {
1987
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-choice-changed", source: "profile-model" } });
1988
+ return;
1989
+ }
1990
+ try {
1991
+ await this.unwrap(selector.selectModel({ sessionId: id2, ...accepted.profileModel }));
1992
+ if (live()) this.publish(selectorLive() && modelSource === this.modelSelectionSource && this.modelSelectionSessionId === id2 ? { sessionNotice: "applied-with-model" } : { sessionIssue: { kind: "assembly", code: "model-service-unavailable", source: "profile-model" } });
1993
+ } catch {
1994
+ if (live()) this.publish({ sessionIssue: { kind: "assembly", code: selectorLive() ? "model-selection-failed" : "model-service-unavailable", source: "profile-model" } });
1995
+ }
1996
+ } catch (error) {
1997
+ if (live()) this.publish({ sessionIssue: this.issue(error) });
1998
+ } finally {
1999
+ if (live()) this.publish({ sessionBusy: null });
2000
+ }
2001
+ }
1505
2002
  publish(patch) {
1506
2003
  if (this.disposed) return;
1507
2004
  this.current = { ...this.current, ...patch };
@@ -1509,7 +2006,7 @@ var ProfilesController = class {
1509
2006
  }
1510
2007
  accept(document2) {
1511
2008
  this.accepted = { ...document2 };
1512
- this.publish({ editor: { ...document2 }, dirty: false, pendingEditor: null });
2009
+ this.publish({ editor: { ...document2 }, dirty: false, pendingEditor: null, invalidFields: [], editorEpoch: this.current.editorEpoch + 1 });
1513
2010
  }
1514
2011
  async unwrap(request, field) {
1515
2012
  const result = await request;
@@ -1527,7 +2024,7 @@ var ProfilesController = class {
1527
2024
  return { kind: "assembly", code: "unavailable" };
1528
2025
  }
1529
2026
  async perform(busy, operation) {
1530
- if (this.disposed || this.current.busy !== null || this.current.pendingEditor !== null) return;
2027
+ if (this.disposed || this.current.busy !== null || this.current.sessionBusy === "apply" || this.current.sessionBusy === "reset" || this.current.pendingEditor !== null) return;
1531
2028
  const generation = ++this.generation;
1532
2029
  const live = () => !this.disposed && generation === this.generation;
1533
2030
  this.publish({ busy, issue: null, notice: null });
@@ -1566,7 +2063,7 @@ var ProfilesController = class {
1566
2063
  async loadEditor(id2) {
1567
2064
  if (id2 === NEW_EDITOR) {
1568
2065
  this.accepted = null;
1569
- this.publish({ editor: { id: "new-profile", content: NEW_PROFILE_CONTENT, revision: null }, dirty: true, issue: null, notice: null, pendingEditor: null });
2066
+ this.publish({ editor: { id: "new-profile", content: NEW_PROFILE_CONTENT, revision: null }, dirty: true, issue: null, notice: null, pendingEditor: null, invalidFields: [], editorEpoch: this.current.editorEpoch + 1 });
1570
2067
  return;
1571
2068
  }
1572
2069
  await this.perform("read", async (live) => {
@@ -1589,10 +2086,10 @@ var ProfilesController = class {
1589
2086
  editId(id2) {
1590
2087
  const editor = this.current.editor;
1591
2088
  if (editor === null || editor.revision !== null || this.current.busy !== null || this.current.pendingEditor !== null) return;
1592
- let content2 = editor.content;
1593
- try {
1594
- content2 = applyEdits(content2, modify(content2, ["id"], id2, { formattingOptions: { insertSpaces: true, tabSize: 2 } }));
1595
- } catch {
2089
+ const content2 = editStructuredPath(editor.content, ["id"], id2);
2090
+ if (content2 === null) {
2091
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
2092
+ return;
1596
2093
  }
1597
2094
  this.publish({ editor: { ...editor, id: id2, content: content2 }, dirty: true, issue: null, notice: null });
1598
2095
  }
@@ -1601,9 +2098,38 @@ var ProfilesController = class {
1601
2098
  if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
1602
2099
  this.publish({ editor: { ...editor, content: content2 }, dirty: this.accepted === null || this.accepted.content !== content2 || this.accepted.id !== editor.id, issue: null, notice: null });
1603
2100
  }
2101
+ editPath(path, value) {
2102
+ const editor = this.current.editor;
2103
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
2104
+ const content2 = editStructuredPath(editor.content, path, value);
2105
+ if (content2 === null) {
2106
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
2107
+ return;
2108
+ }
2109
+ this.editContent(content2);
2110
+ }
2111
+ editRoute(path, provider, model) {
2112
+ const editor = this.current.editor;
2113
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
2114
+ let content2 = editor.content;
2115
+ for (const [key, value] of [["provider", provider], ["model", model], ["reasoningEffort", void 0]]) {
2116
+ content2 = editStructuredPath(content2, [...path, key], value);
2117
+ if (content2 === null) {
2118
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
2119
+ return;
2120
+ }
2121
+ }
2122
+ this.editContent(content2);
2123
+ }
2124
+ editFallbackOrder(role2, from, to) {
2125
+ const editor = this.current.editor;
2126
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
2127
+ const content2 = moveFallback(editor.content, role2, from, to);
2128
+ if (content2 !== null) this.editContent(content2);
2129
+ }
1604
2130
  async save() {
1605
2131
  const editor = this.current.editor;
1606
- if (editor === null || !this.current.dirty || this.current.snapshot === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
2132
+ if (editor === null || !this.current.dirty || this.current.snapshot === null || this.current.busy !== null || this.current.pendingEditor !== null || this.current.invalidFields.length > 0) return;
1607
2133
  if (!isProfileId(editor.id)) {
1608
2134
  this.publish({ issue: { kind: "domain", code: "validation", field: "id" }, notice: null });
1609
2135
  return;
@@ -1649,7 +2175,7 @@ var NS = "settings.dsmm-profiles";
1649
2175
  var en = {
1650
2176
  title: "Deepwork Profiles",
1651
2177
  description: "Save independent runtime configurations and choose which one new sessions use.",
1652
- newSessions: "Apply and reset affect new sessions only. Existing sessions, including blank sessions, keep their current policy. A cold resume uses the currently applied policy.",
2178
+ newSessions: "Global apply and reset affect future unscoped sessions only. Current-session actions below are separate. A cold resume retains an explicit saved session choice; otherwise it inherits the global default.",
1653
2179
  editorSelect: "Profile to edit",
1654
2180
  choose: "Choose a profile",
1655
2181
  newDraft: "New unsaved profile",
@@ -1691,12 +2217,113 @@ var en = {
1691
2217
  transport: "The native connection could not confirm this operation. Your draft is kept. Refresh the Host state before retrying; do not assume a save or apply completed.",
1692
2218
  invalidProfile: "Unavailable profile: {id}",
1693
2219
  details: "Host diagnostic",
1694
- retry: "Resolve the diagnostic, refresh profiles, then retry."
2220
+ retry: "Resolve the diagnostic, refresh profiles, then retry.",
2221
+ globalScope: "Global default for future sessions",
2222
+ sessionScope: "Current native session",
2223
+ sessionSelect: "Current-session profile",
2224
+ globalActionHint: "Apply saved profile below changes the global default for future unscoped sessions only. It does not apply to the current session.",
2225
+ headerProfile: "Profile",
2226
+ headerProfileLabel: "Current-session profile (header)",
2227
+ headerCaptured: "captured global default",
2228
+ headerSavedUnavailable: "saved profile unavailable",
2229
+ headerLoading: "Loading profile…",
2230
+ headerApplying: "Applying profile…",
2231
+ headerApplied: "Profile applied.",
2232
+ headerBusy: "Session is busy.",
2233
+ headerUnavailable: "Profile unavailable.",
2234
+ headerDraft: "Save or discard the draft in Settings.",
2235
+ headerConflict: "Profile changed elsewhere. Refresh in Settings.",
2236
+ headerRefused: "Profile change unconfirmed. Check Settings.",
2237
+ headerKeepModelGroup: "Switch profile — keep current model",
2238
+ headerUseModelGroup: "Switch and use profile model",
2239
+ headerModelDefaultHint: "Normal switching preserves the current model. Explicit switch-and-use-model also saves the native model default, like the Models tab.",
2240
+ headerNoProfileModel: "Profile applied; no main model configured. Current model kept.",
2241
+ headerModelUnconfirmed: "Profile applied; model change unconfirmed. Check Models/Settings.",
2242
+ headerAppliedWithModel: "Profile and native model applied.",
2243
+ headerModelChoiceChanged: "Profile applied; newer native model choice kept.",
2244
+ noSession: "No native session is selected. Session Apply is disabled; global defaults and drafts remain editable.",
2245
+ sessionUnavailable: "The current session could not be confirmed. Refresh its state before retrying; the prior policy is kept.",
2246
+ sessionBusy: "Switching is unavailable: {reason}. The Host must reserve a truly idle ordinary session before applying.",
2247
+ sessionState: "Session {id}: {profile}; scope {scope}; admission epoch {epoch}.",
2248
+ sessionBaseline: "deployment baseline",
2249
+ sessionGlobalCaptured: "captured global default (no explicit session override)",
2250
+ sessionAdmittedProfile: "{id} (revision {revision})",
2251
+ sessionFutureDefault: "Global default for future unscoped sessions: {profile}. This does not change this session's admission.",
2252
+ sessionConflict: "The session selection or admission epoch changed elsewhere. The prior display and draft are kept. Refresh current-session state before applying again.",
2253
+ sessionApply: "Apply profile to current session",
2254
+ sessionApplying: "Applying current-session profile…",
2255
+ sessionReset: "Pin baseline for current session",
2256
+ sessionResetting: "Pinning current-session baseline…",
2257
+ sessionRefresh: "Refresh current-session state",
2258
+ sessionApplied: "Applied the saved revision to this session only. Global default and existing children were not changed.",
2259
+ sessionResetDone: "Pinned the deployment baseline for this session only. Global default was not changed.",
2260
+ sessionAppliedWithModel: "Applied this session profile and explicitly selected its native main model. Native model-default persistence follows the Models tab; the global profile default was not changed.",
2261
+ sessionDirty: "Save or explicitly discard the editor draft before applying a current-session choice.",
2262
+ roleState: "Admitted route {route}; strategy {strategy}; retries {retries}; rate-limit failures {failures}; switches {switches}; total delay {delay} ms.",
2263
+ catalogTitle: "Native model catalog",
2264
+ catalogHint: "Catalog listings are advisory, not network or account health checks. Unlisted/manual routes stay editable; refresh never changes the draft or native model default.",
2265
+ catalogUnavailable: "The native catalog is unavailable. Manual provider/model/effort fields and advanced JSONC remain available.",
2266
+ catalogRefresh: "Refresh model catalog",
2267
+ catalogRefreshing: "Refreshing model catalog…",
2268
+ catalogFailure: "Provider catalog unavailable: {name} ({id}).",
2269
+ profileLabel: "Profile display label",
2270
+ defaultActive: "Default Deepwork mode",
2271
+ activeHint: "This default does not erase an explicit saved session mode.",
2272
+ enabled: "Enabled",
2273
+ disabled: "Disabled",
2274
+ inherit: "Inherit deployment baseline",
2275
+ profileDefaults: "Profile runtime defaults",
2276
+ roleSelect: "Agent role to edit",
2277
+ rolesUnavailable: "Native role inventory unavailable — use advanced JSONC",
2278
+ roleEnabled: "Enabled in the native deployment",
2279
+ roleDisabled: "Disabled in the native deployment",
2280
+ strategy: "{name} strategy",
2281
+ inheritStrategy: "Inherit ({value})",
2282
+ startupLock: "startup-lock — keep the admitted route",
2283
+ rateFallback: "rate-limit-fallback — ordered rollover at threshold",
2284
+ strategyHint: "Both strategies use finite, positively no-output-safe RATE_LIMIT retries. Generic, auth and quota failures do not authorize a model switch. Blank numeric fields inherit; zero is an explicit value.",
2285
+ retryField: "{name} {field}",
2286
+ inheritNumber: "Inherit {value}",
2287
+ retryBounds: "Integer {min}–{max}; inherited value {value}.",
2288
+ unknownDefault: "unavailable",
2289
+ retryCount: "retry count",
2290
+ initialDelay: "initial delay (ms)",
2291
+ maxDelay: "maximum delay (ms)",
2292
+ totalWait: "total wait budget (ms)",
2293
+ switchThreshold: "rate-limit failures before switch",
2294
+ maxSwitches: "maximum switches",
2295
+ primaryMode: "{name} primary route",
2296
+ inheritRoute: "Inherit native/deployment route",
2297
+ configuredRoute: "Configure primary route",
2298
+ primaryName: "{name} primary",
2299
+ fallbackMode: "{name} fallback chain",
2300
+ inheritChain: "Inherit deployment fallback chain",
2301
+ configuredChain: "Explicit ordered fallback chain",
2302
+ emptyChain: "Explicitly empty chain: no configured fallback routes.",
2303
+ fallbackName: "{name} fallback {index}",
2304
+ addFallback: "Add fallback for {name}",
2305
+ removeFallback: "Remove {name}",
2306
+ moveUp: "Move up {name}",
2307
+ moveDown: "Move down {name}",
2308
+ routeProvider: "{name} provider",
2309
+ routeModel: "{name} model",
2310
+ routeEffort: "{name} exact effort",
2311
+ manualProvider: "{name} manual provider",
2312
+ manualModel: "{name} manual model",
2313
+ manualEffort: "{name} manual exact effort",
2314
+ manual: "Enter manual identifier",
2315
+ manualValue: "Manual / unlisted: {value}",
2316
+ unset: "not set",
2317
+ effortDefault: "Native default (omit exact effort)",
2318
+ effortChangeHint: "Changing a provider/model explicitly clears that route's exact effort. Catalog refresh preserves all configured values; choose an exact effort again if required.",
2319
+ advanced: "Advanced JSONC",
2320
+ rawInvalid: "Structured editing is unavailable for this invalid raw draft. Correct Advanced JSONC; no fields, comments or bytes have been normalized.",
2321
+ invalidNumber: "Correct this bounded integer before saving or changing roles. The invalid value has not replaced the saved draft policy."
1695
2322
  };
1696
2323
  var zh = {
1697
2324
  title: "Deepwork 配置档",
1698
2325
  description: "保存独立的运行时配置,并选择新会话使用的配置档。",
1699
- newSessions: "应用和重置仅影响新会话。已有会话(包括空白会话)保留原策略。冷恢复使用当前已应用的策略。",
2326
+ newSessions: "全局应用和重置仅影响之后没有独立选择的新会话。下方当前会话操作相互独立。冷恢复保留明确保存的会话选择,否则继承全局默认值。",
1700
2327
  editorSelect: "要编辑的配置档",
1701
2328
  choose: "选择配置档",
1702
2329
  newDraft: "新的未保存配置档",
@@ -1738,13 +2365,447 @@ var zh = {
1738
2365
  transport: "原生连接无法确认此操作。草稿已保留。重试之前请刷新 Host 状态;不要假定保存或应用已完成。",
1739
2366
  invalidProfile: "不可用配置档:{id}",
1740
2367
  details: "Host 诊断",
1741
- retry: "请解决诊断问题,刷新配置档后重试。"
2368
+ retry: "请解决诊断问题,刷新配置档后重试。",
2369
+ globalScope: "未来会话的全局默认值",
2370
+ sessionScope: "当前原生会话",
2371
+ sessionSelect: "当前会话配置档",
2372
+ globalActionHint: "下方应用已保存配置档仅改变未来没有独立选择的会话的全局默认值,不会应用到当前会话。",
2373
+ headerProfile: "配置档",
2374
+ headerProfileLabel: "当前会话配置档(会话栏)",
2375
+ headerCaptured: "已捕获的全局默认值",
2376
+ headerSavedUnavailable: "保存的配置档不可用",
2377
+ headerLoading: "加载配置档…",
2378
+ headerApplying: "应用配置档…",
2379
+ headerApplied: "配置档已应用。",
2380
+ headerBusy: "会话忙碌。",
2381
+ headerUnavailable: "配置档不可用。",
2382
+ headerDraft: "请在设置中保存或丢弃草稿。",
2383
+ headerConflict: "配置档已在其他位置改变,请在设置中刷新。",
2384
+ headerRefused: "未确认配置档更改,请检查设置。",
2385
+ headerKeepModelGroup: "切换配置档 — 保留当前模型",
2386
+ headerUseModelGroup: "切换并使用配置档模型",
2387
+ headerModelDefaultHint: "普通切换保留当前模型。明确切换并使用模型还会像模型页一样保存原生模型默认值。",
2388
+ headerNoProfileModel: "配置档已应用,未配置主模型。当前模型已保留。",
2389
+ headerModelUnconfirmed: "配置档已应用,模型更改未确认。请检查模型或设置页。",
2390
+ headerAppliedWithModel: "配置档和原生模型已应用。",
2391
+ headerModelChoiceChanged: "配置档已应用,已保留更新的原生模型选择。",
2392
+ noSession: "未选择原生会话。会话应用已禁用;仍可编辑全局默认值和草稿。",
2393
+ sessionUnavailable: "无法确认当前会话。重试前请刷新状态;原策略已保留。",
2394
+ sessionBusy: "暂不可切换:{reason}。Host 必须先保留真正空闲的普通会话。",
2395
+ sessionState: "会话 {id}:{profile};范围 {scope};准入代次 {epoch}。",
2396
+ sessionBaseline: "部署基线",
2397
+ sessionGlobalCaptured: "已捕获的全局默认值(没有明确会话覆盖)",
2398
+ sessionAdmittedProfile: "{id}(修订 {revision})",
2399
+ sessionFutureDefault: "未来没有独立选择的会话的全局默认值:{profile}。这不会改变当前会话的准入。",
2400
+ sessionConflict: "会话选择或准入代次已在其他位置改变。原显示和草稿已保留。再次应用前请刷新当前会话状态。",
2401
+ sessionApply: "应用配置档到当前会话",
2402
+ sessionApplying: "正在应用当前会话配置档…",
2403
+ sessionReset: "为当前会话固定基线",
2404
+ sessionResetting: "正在固定当前会话基线…",
2405
+ sessionRefresh: "刷新当前会话状态",
2406
+ sessionApplied: "已仅对此会话应用保存的修订。全局默认值和已有子会话未改变。",
2407
+ sessionResetDone: "已仅对此会话固定部署基线。全局默认值未改变。",
2408
+ sessionDirty: "应用当前会话选择之前,请保存或明确丢弃编辑器草稿。",
2409
+ sessionAppliedWithModel: "已应用此会话配置档,并明确选择其原生主模型。模型默认值像模型页一样保存;全局配置档默认值未改变。",
2410
+ roleState: "准入路由 {route};策略 {strategy};重试 {retries};限流失败 {failures};切换 {switches};累计延迟 {delay} 毫秒。",
2411
+ catalogTitle: "原生模型目录",
2412
+ catalogHint: "目录仅供参考,不是网络或账户健康检查。未列出或手动路由仍可编辑;刷新不会改变草稿或原生模型默认值。",
2413
+ catalogUnavailable: "原生模型目录不可用。仍可使用手动提供商、模型、强度字段和高级 JSONC。",
2414
+ catalogRefresh: "刷新模型目录",
2415
+ catalogRefreshing: "正在刷新模型目录…",
2416
+ catalogFailure: "提供商目录不可用:{name}({id})。",
2417
+ profileLabel: "配置档显示名称",
2418
+ defaultActive: "默认 Deepwork 模式",
2419
+ activeHint: "此默认值不会抹除已明确保存的会话模式。",
2420
+ enabled: "启用",
2421
+ disabled: "禁用",
2422
+ inherit: "继承部署基线",
2423
+ profileDefaults: "配置档运行时默认值",
2424
+ roleSelect: "要编辑的 Agent 角色",
2425
+ rolesUnavailable: "原生角色列表不可用,请使用高级 JSONC",
2426
+ roleEnabled: "原生部署中已启用",
2427
+ roleDisabled: "原生部署中已禁用",
2428
+ strategy: "{name} 策略",
2429
+ inheritStrategy: "继承({value})",
2430
+ startupLock: "startup-lock — 保留准入路由",
2431
+ rateFallback: "rate-limit-fallback — 达到阈值后按顺序切换",
2432
+ strategyHint: "两种策略均使用有限且已证明无输出的 RATE_LIMIT 重试。普通、认证或配额失败不允许切换模型。数字留空表示继承,零是明确值。",
2433
+ retryField: "{name} {field}",
2434
+ inheritNumber: "继承 {value}",
2435
+ retryBounds: "整数 {min}–{max};继承值 {value}。",
2436
+ unknownDefault: "不可用",
2437
+ retryCount: "重试次数",
2438
+ initialDelay: "初始延迟(毫秒)",
2439
+ maxDelay: "最大单次延迟(毫秒)",
2440
+ totalWait: "累计等待上限(毫秒)",
2441
+ switchThreshold: "切换前的限流失败次数",
2442
+ maxSwitches: "最大切换次数",
2443
+ primaryMode: "{name} 主路由",
2444
+ inheritRoute: "继承原生或部署路由",
2445
+ configuredRoute: "配置主路由",
2446
+ primaryName: "{name} 主路由",
2447
+ fallbackMode: "{name} 备用链",
2448
+ inheritChain: "继承部署备用链",
2449
+ configuredChain: "明确的有序备用链",
2450
+ emptyChain: "明确为空的备用链:没有已配置备用路由。",
2451
+ fallbackName: "{name} 备用 {index}",
2452
+ addFallback: "为 {name} 添加备用路由",
2453
+ removeFallback: "移除 {name}",
2454
+ moveUp: "上移 {name}",
2455
+ moveDown: "下移 {name}",
2456
+ routeProvider: "{name} 提供商",
2457
+ routeModel: "{name} 模型",
2458
+ routeEffort: "{name} 精确强度",
2459
+ manualProvider: "{name} 手动提供商",
2460
+ manualModel: "{name} 手动模型",
2461
+ manualEffort: "{name} 手动精确强度",
2462
+ manual: "输入手动标识",
2463
+ manualValue: "手动或未列出:{value}",
2464
+ unset: "未设置",
2465
+ effortDefault: "原生默认值(省略精确强度)",
2466
+ effortChangeHint: "明确更改提供商或模型会清除该路由的精确强度。刷新目录会保留所有配置值;需要时请重新选择精确强度。",
2467
+ advanced: "高级 JSONC",
2468
+ rawInvalid: "原始草稿无效,暂不可结构化编辑。请修正高级 JSONC;字段、注释和字节均未自动规范化。",
2469
+ invalidNumber: "保存或切换角色之前,请修正此有界整数。无效值尚未替换草稿中的策略。"
2470
+ };
2471
+ var RETRY_FIELD_LABEL_KEYS = {
2472
+ maxRetries: "retryCount",
2473
+ initialDelayMs: "initialDelay",
2474
+ maxDelayMs: "maxDelay",
2475
+ maxTotalDelayMs: "totalWait",
2476
+ switchAfterRateLimits: "switchThreshold",
2477
+ maxSwitches: "maxSwitches"
1742
2478
  };
1743
2479
 
1744
2480
  // src/client/ProfilesSection.tsx
2481
+ var import_react3 = require("react");
2482
+ var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primitives");
2483
+
2484
+ // src/client/StructuredEditor.tsx
1745
2485
  var import_react = require("react");
1746
2486
  var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
1747
2487
  var import_jsx_runtime = require("react/jsx-runtime");
2488
+ var MANUAL = "__dsmm_manual__";
2489
+ function RetryNumber({ id: id2, name, field, value, inherited, path, disabled, actions, t }) {
2490
+ const [draft, setDraft] = (0, import_react.useState)(value === void 0 ? "" : String(value));
2491
+ const [invalid, setInvalid] = (0, import_react.useState)(false);
2492
+ const [min, max] = DSMM_RATE_LIMIT_BOUNDS[field];
2493
+ const key = path.join(".");
2494
+ (0, import_react.useEffect)(() => {
2495
+ setDraft(value === void 0 ? "" : String(value));
2496
+ setInvalid(false);
2497
+ }, [value]);
2498
+ (0, import_react.useEffect)(() => {
2499
+ actions.setFieldInvalid(key, invalid);
2500
+ return () => actions.setFieldInvalid(key, false);
2501
+ }, [actions.setFieldInvalid, key, invalid]);
2502
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2503
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: id2, children: t("retryField", { name, field: t(RETRY_FIELD_LABEL_KEYS[field]) }) }),
2504
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2505
+ import_dsh_client_ui_primitives.Input,
2506
+ {
2507
+ id: id2,
2508
+ "data-dsmm-policy-field": field,
2509
+ className: "dsmm-input",
2510
+ type: "number",
2511
+ inputMode: "numeric",
2512
+ min,
2513
+ max,
2514
+ step: 1,
2515
+ disabled,
2516
+ value: draft,
2517
+ placeholder: inherited === void 0 ? t("unknownDefault") : t("inheritNumber", { value: inherited }),
2518
+ "aria-invalid": invalid || void 0,
2519
+ "aria-describedby": `${id2}-hint${invalid ? ` ${id2}-invalid` : ""}`,
2520
+ onChange: (event) => {
2521
+ const input = event.currentTarget;
2522
+ setDraft(input.value);
2523
+ const valid = input.validity.valid && (input.value === "" || Number.isSafeInteger(input.valueAsNumber));
2524
+ setInvalid(!valid);
2525
+ actions.setFieldInvalid(key, !valid);
2526
+ if (valid) actions.editPath(path, input.value === "" ? void 0 : input.valueAsNumber);
2527
+ }
2528
+ }
2529
+ ),
2530
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", id: `${id2}-hint`, children: t("retryBounds", { min, max, value: inherited ?? t("unknownDefault") }) }),
2531
+ invalid && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { id: `${id2}-invalid`, children: t("invalidNumber") })
2532
+ ] });
2533
+ }
2534
+ function RouteFields({ value, path, name, catalog, disabled, edit, editRoute, t }) {
2535
+ const prefix = (0, import_react.useId)();
2536
+ const providers = catalog?.groups ?? [];
2537
+ const group = providers.find((candidate) => candidate.id === value.provider);
2538
+ const model = group?.models.find((candidate) => candidate.id === value.model);
2539
+ const efforts = model?.reasoning?.efforts ?? [];
2540
+ const providerListed = group !== void 0;
2541
+ const modelListed = model !== void 0;
2542
+ const updateModel = (provider, modelId) => {
2543
+ editRoute(path, provider, modelId);
2544
+ };
2545
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-route-fields", children: [
2546
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2547
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-provider`, children: t("routeProvider", { name }) }),
2548
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: `${prefix}-provider`, disabled, value: providerListed ? value.provider : MANUAL, onChange: (event) => updateModel(event.currentTarget.value === MANUAL ? "" : event.currentTarget.value, ""), children: [
2549
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: MANUAL, children: providerListed ? t("manual") : t("manualValue", { value: value.provider || t("unset") }) }),
2550
+ providers.map((provider) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: provider.id, children: [
2551
+ provider.name,
2552
+ " (",
2553
+ provider.id,
2554
+ ")"
2555
+ ] }, provider.id))
2556
+ ] }),
2557
+ !providerListed && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Input, { "aria-label": t("manualProvider", { name }), className: "dsmm-input", value: value.provider, disabled, onChange: (event) => updateModel(event.currentTarget.value, value.model) })
2558
+ ] }),
2559
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2560
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-model`, children: t("routeModel", { name }) }),
2561
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: `${prefix}-model`, disabled, value: modelListed ? value.model : MANUAL, onChange: (event) => updateModel(value.provider, event.currentTarget.value === MANUAL ? "" : event.currentTarget.value), children: [
2562
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: MANUAL, children: modelListed ? t("manual") : t("manualValue", { value: value.model || t("unset") }) }),
2563
+ group?.models.map((candidate) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: candidate.id, children: [
2564
+ candidate.name,
2565
+ " (",
2566
+ candidate.id,
2567
+ ")"
2568
+ ] }, candidate.id))
2569
+ ] }),
2570
+ !modelListed && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Input, { "aria-label": t("manualModel", { name }), className: "dsmm-input", value: value.model, disabled, onChange: (event) => updateModel(value.provider, event.currentTarget.value) })
2571
+ ] }),
2572
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2573
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-effort`, children: t("routeEffort", { name }) }),
2574
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: `${prefix}-effort`, disabled, value: value.reasoningEffort ?? "", onChange: (event) => edit([...path, "reasoningEffort"], event.currentTarget.value || void 0), children: [
2575
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("effortDefault") }),
2576
+ value.reasoningEffort !== void 0 && !efforts.some((effort) => effort.id === value.reasoningEffort) && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: value.reasoningEffort, children: t("manualValue", { value: value.reasoningEffort }) }),
2577
+ efforts.map((effort) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: effort.id, children: [
2578
+ effort.name,
2579
+ " (",
2580
+ effort.id,
2581
+ ")"
2582
+ ] }, effort.id))
2583
+ ] }),
2584
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Input, { "aria-label": t("manualEffort", { name }), className: "dsmm-input", value: value.reasoningEffort ?? "", disabled, placeholder: t("effortDefault"), onChange: (event) => edit([...path, "reasoningEffort"], event.currentTarget.value || void 0) })
2585
+ ] })
2586
+ ] });
2587
+ }
2588
+ function PolicyFields({ value, inherited, path, name, disabled, actions, t }) {
2589
+ const prefix = (0, import_react.useId)();
2590
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-policy-fields", children: [
2591
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2592
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-strategy`, children: t("strategy", { name }) }),
2593
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: `${prefix}-strategy`, disabled, value: value.strategy ?? "", onChange: (event) => actions.editPath([...path, "strategy"], event.currentTarget.value || void 0), children: [
2594
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("inheritStrategy", { value: inherited?.strategy ?? t("unknownDefault") }) }),
2595
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "startup-lock", children: t("startupLock") }),
2596
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "rate-limit-fallback", children: t("rateFallback") })
2597
+ ] })
2598
+ ] }),
2599
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("strategyHint") }),
2600
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "dsmm-route-fields", children: Object.keys(DSMM_RATE_LIMIT_BOUNDS).map((field) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RetryNumber, { id: `${prefix}-${field}`, t, name, field, value: value.rateLimit?.[field], inherited: inherited?.rateLimit[field], path: [...path, "rateLimit", field], disabled, actions }, field)) })
2601
+ ] });
2602
+ }
2603
+ function StructuredEditor({ state, actions, disabled, t }) {
2604
+ const prefix = (0, import_react.useId)();
2605
+ const [selectedRole, setSelectedRole] = (0, import_react.useState)("dsmm-orchestrator");
2606
+ const document2 = state.editor === null ? null : structuredDocument(state.editor.content);
2607
+ if (document2 === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", "data-dsmm-structured-invalid": true, children: t("rawInvalid") });
2608
+ const roles = state.snapshot?.roles ?? [];
2609
+ const role2 = roles.find((candidate) => candidate.id === selectedRole) ?? roles[0];
2610
+ const policy = role2 === void 0 ? void 0 : document2.roleRouting[role2.id] ?? {};
2611
+ const baseline = state.snapshot?.editorDefaults;
2612
+ let inherited;
2613
+ try {
2614
+ if (baseline !== void 0) {
2615
+ const profileDefaults = { strategy: document2.runtimePolicy.strategy ?? baseline.strategy, rateLimit: normalizeRateLimitPolicy(document2.runtimePolicy.rateLimit, baseline.rateLimit) };
2616
+ inherited = { strategy: role2?.runtimePolicy?.strategy ?? profileDefaults.strategy, rateLimit: normalizeRateLimitPolicy(role2?.runtimePolicy?.rateLimit, profileDefaults.rateLimit) };
2617
+ }
2618
+ } catch {
2619
+ }
2620
+ const rolePath = ["settings", "roleRouting", role2?.id ?? ""];
2621
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-structured", "data-dsmm-structured": true, children: [
2622
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2623
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-label`, children: t("profileLabel") }),
2624
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Input, { id: `${prefix}-label`, className: "dsmm-input", value: document2.label ?? "", disabled, onChange: (event) => actions.editPath(["label"], event.currentTarget.value || void 0) })
2625
+ ] }),
2626
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2627
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-active`, children: t("defaultActive") }),
2628
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: `${prefix}-active`, disabled, value: document2.settings.defaultActive === void 0 ? "" : String(document2.settings.defaultActive), onChange: (event) => actions.editPath(["settings", "defaultActive"], event.currentTarget.value === "" ? void 0 : event.currentTarget.value === "true"), children: [
2629
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("inherit") }),
2630
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "true", children: t("enabled") }),
2631
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "false", children: t("disabled") })
2632
+ ] }),
2633
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("activeHint") })
2634
+ ] }),
2635
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { children: [
2636
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: t("profileDefaults") }),
2637
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PolicyFields, { t, value: document2.runtimePolicy, inherited: baseline, path: ["settings", "runtimePolicy"], name: t("profileDefaults"), disabled, actions })
2638
+ ] }),
2639
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2640
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-role`, children: t("roleSelect") }),
2641
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: `${prefix}-role`, disabled: disabled || roles.length === 0 || state.invalidFields.length > 0, value: role2?.id ?? "", onChange: (event) => setSelectedRole(event.currentTarget.value), children: [
2642
+ roles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("rolesUnavailable") }),
2643
+ roles.map((candidate) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: candidate.id, children: [
2644
+ candidate.label,
2645
+ candidate.enabled ? "" : ` — ${t("roleDisabled")}`
2646
+ ] }, candidate.id))
2647
+ ] })
2648
+ ] }),
2649
+ role2 !== void 0 && policy !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { "data-dsmm-role": role2.id, children: [
2650
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: role2.label }),
2651
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t(role2.enabled ? "roleEnabled" : "roleDisabled") }),
2652
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PolicyFields, { t, value: policy, inherited, path: rolePath, name: role2.label, disabled, actions }),
2653
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2654
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-primary-mode`, children: t("primaryMode", { name: role2.label }) }),
2655
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: `${prefix}-primary-mode`, disabled, value: policy.primary === void 0 ? "inherit" : "explicit", onChange: (event) => actions.editPath([...rolePath, "primary"], event.currentTarget.value === "inherit" ? void 0 : { provider: "", model: "" }), children: [
2656
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "inherit", children: t("inheritRoute") }),
2657
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "explicit", children: t("configuredRoute") })
2658
+ ] })
2659
+ ] }),
2660
+ policy.primary !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouteFields, { t, value: policy.primary, path: [...rolePath, "primary"], name: t("primaryName", { name: role2.label }), catalog: state.catalog, disabled, edit: actions.editPath, editRoute: actions.editRoute }),
2661
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("effortChangeHint") }),
2662
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2663
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-fallback-mode`, children: t("fallbackMode", { name: role2.label }) }),
2664
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { id: `${prefix}-fallback-mode`, disabled, value: policy.fallbackRoutes === void 0 ? "inherit" : "explicit", onChange: (event) => actions.editPath([...rolePath, "fallbackRoutes"], event.currentTarget.value === "inherit" ? void 0 : []), children: [
2665
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "inherit", children: t("inheritChain") }),
2666
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "explicit", children: t("configuredChain") })
2667
+ ] })
2668
+ ] }),
2669
+ policy.fallbackRoutes?.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("emptyChain") }),
2670
+ policy.fallbackRoutes?.map((candidate, index) => {
2671
+ const name = t("fallbackName", { name: role2.label, index: index + 1 });
2672
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { children: [
2673
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: name }),
2674
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(RouteFields, { t, value: candidate, path: [...rolePath, "fallbackRoutes", index], name, catalog: state.catalog, disabled, edit: actions.editPath, editRoute: actions.editRoute }),
2675
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-actions", children: [
2676
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled: disabled || index === 0, onClick: () => actions.moveFallback(role2.id, index, index - 1), children: t("moveUp", { name }) }),
2677
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled: disabled || index === policy.fallbackRoutes.length - 1, onClick: () => actions.moveFallback(role2.id, index, index + 1), children: t("moveDown", { name }) }),
2678
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled, onClick: () => actions.editPath([...rolePath, "fallbackRoutes", index], void 0), children: t("removeFallback", { name }) })
2679
+ ] })
2680
+ ] }, index);
2681
+ }),
2682
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled: disabled || (policy.fallbackRoutes?.length ?? 0) >= 32, onClick: () => {
2683
+ if (policy.fallbackRoutes === void 0) actions.editPath([...rolePath, "fallbackRoutes"], [{ provider: "", model: "" }]);
2684
+ else actions.editPath([...rolePath, "fallbackRoutes", policy.fallbackRoutes.length], { provider: "", model: "" });
2685
+ }, children: t("addFallback", { name: role2.label }) })
2686
+ ] })
2687
+ ] });
2688
+ }
2689
+
2690
+ // src/client/SessionProfiles.tsx
2691
+ var import_react2 = require("react");
2692
+ var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
2693
+
2694
+ // src/client/session-labels.ts
2695
+ function sessionProfileLabels(session, t) {
2696
+ const admitted = session.admittedSelection;
2697
+ const profile = admitted === void 0 && session.scope === "global-default" ? t("sessionGlobalCaptured") : (admitted ?? session.selection).selectedId === null ? t("sessionBaseline") : t("sessionAdmittedProfile", { id: (admitted ?? session.selection).selectedId, revision: (admitted ?? session.selection).appliedRevision?.slice(0, 12) ?? "—" });
2698
+ const future = session.globalDefault;
2699
+ return {
2700
+ admitted: t("sessionState", { id: session.sessionId, profile, scope: session.scope, epoch: session.admissionEpoch }),
2701
+ futureDefault: t("sessionFutureDefault", { profile: future.selectedId === null ? t("sessionBaseline") : t("sessionAdmittedProfile", { id: future.selectedId, revision: future.appliedRevision?.slice(0, 12) ?? "—" }) })
2702
+ };
2703
+ }
2704
+
2705
+ // src/client/SessionProfiles.tsx
2706
+ var import_jsx_runtime2 = require("react/jsx-runtime");
2707
+ function SessionScope({ state, actions, t, compact = false }) {
2708
+ const prefix = (0, import_react2.useId)();
2709
+ const session = state.session;
2710
+ const labels = session === null ? null : sessionProfileLabels(session, t);
2711
+ const selected = state.snapshot?.profiles.find((profile) => profile.id === state.sessionChoice);
2712
+ const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy !== null || state.dirty;
2713
+ const allowed = session !== null && session.switchAllowed && /^[a-f0-9]{64}$|^absent$/u.test(session.selection.selectionRevision);
2714
+ const status = state.sessionNotice === null ? "" : t(state.sessionNotice === "applied-with-model" ? "sessionAppliedWithModel" : state.sessionNotice === "applied" ? "sessionApplied" : "sessionResetDone");
2715
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-session-scope", "aria-busy": state.sessionBusy !== null, "data-dsmm-session-scope": true, children: [
2716
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: t("sessionScope") }),
2717
+ state.currentSessionId === null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-hint", children: t("noSession") }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
2718
+ labels !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { "data-dsmm-session-state": true, children: labels.admitted }),
2719
+ labels !== null && !compact && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-hint", "data-dsmm-session-future-default": true, children: labels.futureDefault }),
2720
+ session !== null && !session.switchAllowed && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-hint", children: t("sessionBusy", { reason: session.switchUnavailableReason ?? "unavailable" }) }),
2721
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-field", children: [
2722
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: `${prefix}-choice`, children: t("sessionSelect") }),
2723
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("select", { id: `${prefix}-choice`, value: state.sessionChoice ?? "", disabled: disabled || !allowed, onChange: (event) => actions.chooseSessionProfile(event.currentTarget.value || null), children: [
2724
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "", children: t("sessionBaseline") }),
2725
+ state.sessionChoice !== null && selected === void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: state.sessionChoice, children: state.sessionChoice }),
2726
+ state.snapshot?.profiles.map((profile) => /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: profile.id, disabled: profile.revision === null || profile.error !== void 0, children: profile.label === void 0 ? profile.id : `${profile.label} (${profile.id})` }, profile.id))
2727
+ ] })
2728
+ ] }),
2729
+ state.dirty && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-hint", children: t("sessionDirty") }),
2730
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-actions", children: [
2731
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Button, { type: "button", variant: "outline", disabled: disabled || !allowed || state.sessionChoice !== null && selected?.revision == null, onClick: () => {
2732
+ void actions.applySession();
2733
+ }, children: t(state.sessionBusy === "apply" ? "sessionApplying" : "sessionApply") }),
2734
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Button, { type: "button", variant: "outline", disabled: disabled || !allowed, onClick: () => {
2735
+ void actions.resetSession();
2736
+ }, children: t(state.sessionBusy === "reset" ? "sessionResetting" : "sessionReset") }),
2737
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Button, { type: "button", variant: "outline", disabled: state.sessionBusy !== null || state.busy !== null || state.pendingEditor !== null, onClick: () => {
2738
+ void actions.refreshSession();
2739
+ }, children: t("sessionRefresh") })
2740
+ ] }),
2741
+ !compact && session?.rolePolicy !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { "data-dsmm-session-policy": true, children: t("roleState", { route: session.rolePolicy.route === void 0 ? t("inheritRoute") : `${session.rolePolicy.route.provider}/${session.rolePolicy.route.model}${session.rolePolicy.route.reasoningEffort === void 0 ? "" : ` (${session.rolePolicy.route.reasoningEffort})`}`, strategy: session.rolePolicy.strategy, retries: session.rolePolicy.retries, failures: session.rolePolicy.rateLimitFailures, switches: session.rolePolicy.switches, delay: session.rolePolicy.totalDelayMs }) })
2742
+ ] }),
2743
+ state.sessionIssue !== null && /* @__PURE__ */ (0, import_jsx_runtime2.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") : state.sessionIssue.code === "conflict" ? t("sessionConflict") : ["busy", "maintenance", "disposed", "not-owned"].includes(state.sessionIssue.code) ? t("sessionBusy", { reason: state.sessionIssue.code }) : t(state.sessionIssue.code === "validation" ? "validation" : "sessionUnavailable") }),
2744
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.sessionBusy === "read" ? t("reading") : status })
2745
+ ] });
2746
+ }
2747
+ function SessionProfiles(props) {
2748
+ const prefix = (0, import_react2.useId)();
2749
+ const state = props.useProfiles((snapshot2) => snapshot2);
2750
+ if (props.sessionId !== state.currentSessionId) return null;
2751
+ const { t } = props;
2752
+ const session = state.session;
2753
+ const admission = session?.admittedSelection ?? (session?.scope === "global-default" ? void 0 : session?.selection);
2754
+ const unknownCaptured = session !== null && admission === void 0;
2755
+ const current = session === null ? "__dsmm_session_unavailable__" : unknownCaptured ? "__dsmm_captured_default__" : admission?.selectedId ?? "";
2756
+ const profiles = state.snapshot?.profiles ?? [];
2757
+ const currentSaved = profiles.find((profile) => profile.id === current);
2758
+ const committing = state.sessionBusy !== null;
2759
+ const disabled = committing || state.busy !== null || state.pendingEditor !== null || state.dirty || state.invalidFields.length > 0 || session === null || !session.switchAllowed || state.snapshot === null;
2760
+ let feedback = "";
2761
+ if (state.sessionIssue !== null) feedback = t(state.sessionIssue.source === "profile-model" ? state.sessionIssue.code === "model-unconfigured" ? "headerNoProfileModel" : state.sessionIssue.code === "model-choice-changed" ? "headerModelChoiceChanged" : "headerModelUnconfirmed" : state.sessionIssue.code === "conflict" ? "headerConflict" : "headerRefused");
2762
+ else if (committing) feedback = t(state.sessionBusy === "read" ? "headerLoading" : "headerApplying");
2763
+ else if (state.dirty || state.invalidFields.length > 0 || state.pendingEditor !== null) feedback = t("headerDraft");
2764
+ else if (session === null || state.snapshot === null) feedback = t("headerUnavailable");
2765
+ else if (!session.switchAllowed) feedback = t("headerBusy");
2766
+ else if (state.sessionNotice !== null) feedback = t(state.sessionNotice === "applied-with-model" ? "headerAppliedWithModel" : "headerApplied");
2767
+ const capturedSuffix = session?.scope === "global-default" && !unknownCaptured ? ` — ${t("headerCaptured")}` : "";
2768
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-profiles dsmm-header-profiles", "data-dsmm-header-profile": true, "aria-busy": committing, children: [
2769
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: `${prefix}-profile`, children: t("headerProfile") }),
2770
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("select", { id: `${prefix}-profile`, "aria-label": t("headerProfileLabel"), title: t("headerModelDefaultHint"), "aria-describedby": feedback === "" ? void 0 : `${prefix}-feedback`, value: current, disabled, onChange: (event) => {
2771
+ const value = event.currentTarget.value;
2772
+ const useProfileModel = value.startsWith("@model:");
2773
+ props.chooseSessionProfile((useProfileModel ? value.slice("@model:".length) : value) || null);
2774
+ void props.applySession(useProfileModel ? { useProfileModel: true } : void 0);
2775
+ }, children: [
2776
+ session === null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "__dsmm_session_unavailable__", disabled: true, children: t("headerUnavailable") }),
2777
+ unknownCaptured && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "__dsmm_captured_default__", disabled: true, children: t("headerCaptured") }),
2778
+ admission?.selectedId != null && currentSaved === void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: admission.selectedId, disabled: true, children: [
2779
+ admission.selectedId,
2780
+ " — ",
2781
+ t("headerSavedUnavailable"),
2782
+ capturedSuffix
2783
+ ] }),
2784
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("optgroup", { label: t("headerKeepModelGroup"), children: [
2785
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: "", children: [
2786
+ t("sessionBaseline"),
2787
+ current === "" ? capturedSuffix : ""
2788
+ ] }),
2789
+ profiles.map((profile) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: profile.id, disabled: profile.revision === null || profile.error !== void 0, children: [
2790
+ profile.label ?? profile.id,
2791
+ profile.id === current ? capturedSuffix : "",
2792
+ profile.error === void 0 && profile.revision !== null ? "" : ` — ${t("headerSavedUnavailable")}`
2793
+ ] }, profile.id))
2794
+ ] }),
2795
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("optgroup", { label: t("headerUseModelGroup"), children: [
2796
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "@model:", children: t("sessionBaseline") }),
2797
+ profiles.map((profile) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: `@model:${profile.id}`, disabled: profile.revision === null || profile.error !== void 0, children: [
2798
+ profile.label ?? profile.id,
2799
+ profile.error === void 0 && profile.revision !== null ? "" : ` — ${t("headerSavedUnavailable")}`
2800
+ ] }, profile.id))
2801
+ ] })
2802
+ ] }),
2803
+ feedback !== "" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { id: `${prefix}-feedback`, role: state.sessionIssue === null ? "status" : "alert", "aria-live": "polite", children: feedback })
2804
+ ] });
2805
+ }
2806
+
2807
+ // src/client/ProfilesSection.tsx
2808
+ var import_jsx_runtime3 = require("react/jsx-runtime");
1748
2809
  function issueKey(issue) {
1749
2810
  if (issue.source === "selection") return issue.code === "conflict" ? "selectionConflict" : "appliedInvalid";
1750
2811
  if (issue.kind === "assembly") return "unavailable";
@@ -1754,20 +2815,21 @@ function issueKey(issue) {
1754
2815
  function ProfilesSection(props) {
1755
2816
  const { t } = props;
1756
2817
  const state = props.useProfiles((snapshot3) => snapshot3);
1757
- const prefix = (0, import_react.useId)();
1758
- const selectRef = (0, import_react.useRef)(null);
1759
- const inputRef = (0, import_react.useRef)(null);
1760
- const editorRef = (0, import_react.useRef)(null);
1761
- const cancelRef = (0, import_react.useRef)(null);
1762
- const hadConfirmation = (0, import_react.useRef)(false);
1763
- const disabled = state.busy !== null || state.pendingEditor !== null;
2818
+ const prefix = (0, import_react3.useId)();
2819
+ const selectRef = (0, import_react3.useRef)(null);
2820
+ const inputRef = (0, import_react3.useRef)(null);
2821
+ const editorRef = (0, import_react3.useRef)(null);
2822
+ const cancelRef = (0, import_react3.useRef)(null);
2823
+ const hadConfirmation = (0, import_react3.useRef)(false);
2824
+ const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy === "apply" || state.sessionBusy === "reset";
1764
2825
  const snapshot2 = state.snapshot;
1765
2826
  const editor = state.editor;
1766
2827
  const reconcilable = canReconcileSelection(snapshot2);
1767
2828
  const selectionConflict = reconcilable && snapshot2?.selectionError?.code === "conflict";
1768
2829
  const invalid = state.issue?.kind === "domain" && state.issue.code === "validation";
1769
2830
  const idInvalid = invalid && state.issue?.field === "id";
1770
- (0, import_react.useEffect)(() => {
2831
+ const rawInvalid = editor !== null && structuredDocument(editor.content) === null;
2832
+ (0, import_react3.useEffect)(() => {
1771
2833
  if (state.pendingEditor !== null) {
1772
2834
  cancelRef.current?.focus();
1773
2835
  hadConfirmation.current = true;
@@ -1776,7 +2838,7 @@ function ProfilesSection(props) {
1776
2838
  hadConfirmation.current = false;
1777
2839
  }
1778
2840
  }, [state.pendingEditor]);
1779
- (0, import_react.useEffect)(() => {
2841
+ (0, import_react3.useEffect)(() => {
1780
2842
  if (state.issue?.kind === "domain" && state.issue.code === "validation") {
1781
2843
  if (state.issue.field === "id") inputRef.current?.focus();
1782
2844
  else editorRef.current?.focus();
@@ -1787,91 +2849,107 @@ function ProfilesSection(props) {
1787
2849
  if (snapshot2?.selectionError !== void 0 && !selectionConflict) selection = t("appliedInvalid");
1788
2850
  else if (snapshot2?.selectedId !== null && snapshot2?.selectedId !== void 0) selection = t("appliedProfile", { id: snapshot2.selectedId, revision: snapshot2.appliedRevision?.slice(0, 12) ?? "—" });
1789
2851
  const notice = state.notice === null ? "" : t(state.notice.key === "reset" ? "resetDone" : state.notice.key, { id: state.notice.id });
1790
- return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("section", { className: "dsmm-profiles", "aria-labelledby": `${prefix}-title`, "aria-busy": state.busy !== null, children: [
1791
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("h2", { id: `${prefix}-title`, children: t("title") }),
1792
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t("description") }),
1793
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("newSessions") }),
1794
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { "data-dsmm-selection": true, children: selection }),
1795
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-actions", children: [
1796
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled: disabled || snapshot2 === null, onClick: () => {
2852
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "dsmm-profiles", "aria-labelledby": `${prefix}-title`, "aria-busy": state.busy !== null, children: [
2853
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { id: `${prefix}-title`, children: t("title") }),
2854
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: t("description") }),
2855
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { id: `${prefix}-global`, children: t("globalScope") }),
2856
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("newSessions") }),
2857
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { "data-dsmm-selection": true, children: selection }),
2858
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-actions", children: [
2859
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled: disabled || snapshot2 === null, onClick: () => {
1797
2860
  void props.create();
1798
2861
  }, children: t("new") }),
1799
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled, onClick: () => {
2862
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled, onClick: () => {
1800
2863
  void props.refresh();
1801
2864
  }, children: t(state.busy === "refresh" ? "refreshing" : "refresh") }),
1802
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled: disabled || !reconcilable || snapshot2?.selectedId === null && !selectionConflict, onClick: () => {
2865
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled: disabled || !reconcilable || snapshot2?.selectedId === null && !selectionConflict, onClick: () => {
1803
2866
  void props.reset();
1804
2867
  }, children: t(state.busy === "reset" ? "resetting" : "reset") })
1805
2868
  ] }),
1806
- snapshot2 !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
1807
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-select`, children: t("editorSelect") }),
1808
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("select", { ref: selectRef, id: `${prefix}-select`, disabled, value: editor?.revision == null ? "" : editor.id, onChange: (event) => {
2869
+ snapshot2 !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-field", children: [
2870
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { htmlFor: `${prefix}-select`, children: t("editorSelect") }),
2871
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("select", { ref: selectRef, id: `${prefix}-select`, disabled, value: editor?.revision == null ? "" : editor.id, onChange: (event) => {
1809
2872
  if (event.currentTarget.value) void props.open(event.currentTarget.value);
1810
2873
  }, children: [
1811
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t(editor?.revision === null ? "newDraft" : "choose") }),
1812
- snapshot2.profiles.map((profile, index) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: profile.id, children: [
2874
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: t(editor?.revision === null ? "newDraft" : "choose") }),
2875
+ snapshot2.profiles.map((profile, index) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("option", { value: profile.id, children: [
1813
2876
  profile.label === void 0 ? profile.id : `${profile.label} (${profile.id})`,
1814
2877
  profile.error === void 0 ? "" : ` — ${t("invalidProfile", { id: profile.id })}`
1815
2878
  ] }, `${index}:${profile.id}`))
1816
2879
  ] }),
1817
- snapshot2.profiles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("empty") })
2880
+ snapshot2.profiles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("empty") })
1818
2881
  ] }),
1819
- state.pendingEditor !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-confirm", role: "group", "aria-labelledby": `${prefix}-confirm`, onKeyDown: (event) => {
2882
+ state.pendingEditor !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-confirm", role: "group", "aria-labelledby": `${prefix}-confirm`, onKeyDown: (event) => {
1820
2883
  if (event.key === "Escape") {
1821
2884
  event.preventDefault();
1822
2885
  props.cancelDiscard();
1823
2886
  }
1824
2887
  }, children: [
1825
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { id: `${prefix}-confirm`, children: t("discardPrompt") }),
1826
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-actions", children: [
1827
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", onClick: () => {
2888
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-confirm`, children: t("discardPrompt") }),
2889
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-actions", children: [
2890
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", onClick: () => {
1828
2891
  void props.discardAndOpen();
1829
2892
  }, children: t("discard") }),
1830
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { ref: cancelRef, type: "button", variant: "primary", onClick: props.cancelDiscard, children: t("cancel") })
2893
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { ref: cancelRef, type: "button", variant: "primary", onClick: props.cancelDiscard, children: t("cancel") })
1831
2894
  ] })
1832
2895
  ] }),
1833
- editor !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-editor", children: [
1834
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
1835
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-id`, children: t("profileId") }),
1836
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Input, { ref: inputRef, id: `${prefix}-id`, className: "dsmm-input", value: editor.id, disabled: disabled || editor.revision !== null, "aria-invalid": idInvalid || void 0, "aria-describedby": `${prefix}-id-hint${idInvalid ? ` ${prefix}-issue` : ""}`, onChange: (event) => props.editId(event.currentTarget.value) }),
1837
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { id: `${prefix}-id-hint`, className: "dsmm-hint", children: t("idHint") })
2896
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SessionScope, { state, actions: props, t }),
2897
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-catalog", children: [
2898
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { children: t("catalogTitle") }),
2899
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("catalogHint") }),
2900
+ state.catalogUnavailable && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("catalogUnavailable") }),
2901
+ state.catalog?.failures.map((failure) => /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("catalogFailure", { name: failure.name, id: failure.id }) }, failure.id)),
2902
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled: state.catalogBusy, onClick: () => {
2903
+ void props.refreshCatalog();
2904
+ }, children: t(state.catalogBusy ? "catalogRefreshing" : "catalogRefresh") })
2905
+ ] }),
2906
+ editor !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-editor", children: [
2907
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-field", children: [
2908
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { htmlFor: `${prefix}-id`, children: t("profileId") }),
2909
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Input, { ref: inputRef, id: `${prefix}-id`, className: "dsmm-input", value: editor.id, disabled: disabled || editor.revision !== null, "aria-invalid": idInvalid || void 0, "aria-describedby": `${prefix}-id-hint${idInvalid ? ` ${prefix}-issue` : ""}`, onChange: (event) => props.editId(event.currentTarget.value) }),
2910
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-id-hint`, className: "dsmm-hint", children: t("idHint") })
1838
2911
  ] }),
1839
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
1840
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-content`, children: t("configuration") }),
1841
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("textarea", { ref: editorRef, id: `${prefix}-content`, rows: 12, spellCheck: false, value: editor.content, disabled, "aria-invalid": invalid && !idInvalid || void 0, "aria-describedby": `${prefix}-content-hint ${prefix}-structural-hint${invalid && !idInvalid ? ` ${prefix}-issue` : ""}`, onChange: (event) => props.editContent(event.currentTarget.value) }),
1842
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { id: `${prefix}-content-hint`, className: "dsmm-hint", children: t("configurationHint") }),
1843
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { id: `${prefix}-structural-hint`, className: "dsmm-hint", children: t("structuralHint") })
2912
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(StructuredEditor, { state, actions: props, disabled, t }, state.editorEpoch),
2913
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("details", { className: "dsmm-advanced", open: true, children: [
2914
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("summary", { children: t("advanced") }),
2915
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-field", children: [
2916
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { htmlFor: `${prefix}-content`, children: t("configuration") }),
2917
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("textarea", { ref: editorRef, id: `${prefix}-content`, rows: 12, spellCheck: false, value: editor.content, disabled, "aria-invalid": rawInvalid || invalid && !idInvalid || void 0, "aria-describedby": `${prefix}-content-hint ${prefix}-structural-hint${invalid && !idInvalid ? ` ${prefix}-issue` : ""}`, onChange: (event) => props.editContent(event.currentTarget.value) }),
2918
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-content-hint`, className: "dsmm-hint", children: t("configurationHint") }),
2919
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-structural-hint`, className: "dsmm-hint", children: t("structuralHint") })
2920
+ ] })
1844
2921
  ] }),
1845
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { "data-dsmm-editor-state": true, children: t(state.dirty ? "dirty" : applied ? "savedApplied" : "savedNotApplied") }),
1846
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-actions", children: [
1847
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "primary", disabled: disabled || !state.dirty || snapshot2 === null, onClick: () => {
2922
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { "data-dsmm-editor-state": true, children: t(state.dirty ? "dirty" : applied ? "savedApplied" : "savedNotApplied") }),
2923
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-global-action`, className: "dsmm-hint", children: t("globalActionHint") }),
2924
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-actions", children: [
2925
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "primary", disabled: disabled || !state.dirty || snapshot2 === null || state.invalidFields.length > 0, onClick: () => {
1848
2926
  void props.save();
1849
2927
  }, children: t(state.busy === "save" ? "saving" : "save") }),
1850
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled: disabled || state.dirty || editor.revision === null || !reconcilable || applied && !selectionConflict, onClick: () => {
2928
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", "aria-describedby": `${prefix}-global-action`, disabled: disabled || state.dirty || editor.revision === null || !reconcilable || applied && !selectionConflict, onClick: () => {
1851
2929
  void props.apply();
1852
2930
  }, children: t(state.busy === "apply" ? "applying" : "apply") }),
1853
- editor.revision !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled, onClick: () => {
2931
+ editor.revision !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled, onClick: () => {
1854
2932
  void props.reload();
1855
2933
  }, children: t("reload") })
1856
2934
  ] })
1857
2935
  ] }),
1858
- state.issue !== null && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-issue", id: `${prefix}-issue`, role: "alert", children: [
1859
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t(issueKey(state.issue)) }),
1860
- state.issue.kind === "domain" && state.issue.message !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
2936
+ state.issue !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-issue", id: `${prefix}-issue`, role: "alert", children: [
2937
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: t(issueKey(state.issue)) }),
2938
+ state.issue.kind === "domain" && state.issue.message !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
1861
2939
  t("details"),
1862
2940
  ": ",
1863
2941
  state.issue.message
1864
2942
  ] })
1865
2943
  ] }),
1866
- snapshot2?.selectionError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-issue", children: [
1867
- /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("p", { children: [
2944
+ snapshot2?.selectionError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-issue", children: [
2945
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
1868
2946
  t("details"),
1869
2947
  ": ",
1870
2948
  snapshot2.selectionError.message
1871
2949
  ] }),
1872
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { children: t(selectionConflict ? "selectionConflict" : "retry") })
2950
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: t(selectionConflict ? "selectionConflict" : "retry") })
1873
2951
  ] }),
1874
- /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" && snapshot2 === null ? t("loading") : state.busy === "read" ? t("reading") : notice })
2952
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.busy === "refresh" && snapshot2 === null ? t("loading") : state.busy === "read" ? t("reading") : notice })
1875
2953
  ] });
1876
2954
  }
1877
2955
 
@@ -1879,11 +2957,24 @@ function ProfilesSection(props) {
1879
2957
  var PROFILE_STYLES = `
1880
2958
  .dsmm-profiles{width:100%;max-width:760px;min-width:0;display:flex;flex-direction:column;gap:12px;font-family:var(--dsw-font-family);font-size:14px;line-height:22px;color:var(--dsw-alias-label-primary)}
1881
2959
  .dsmm-profiles h2{margin:0;font-size:18px;font-weight:600}
2960
+ .dsmm-profiles h3,.dsmm-profiles legend{margin:0;font-size:14px;font-weight:500;line-height:22px}
2961
+ .dsmm-profiles :is(label,legend,summary){min-width:0;max-width:100%;overflow-wrap:anywhere}
2962
+ .dsmm-profiles :is(.dsmm-structured,.dsmm-session-scope,.dsmm-catalog,.dsmm-policy-fields){min-width:0;display:flex;flex-direction:column;gap:12px}
2963
+ .dsmm-profiles fieldset{min-width:0;margin:0;padding:12px;border:1px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);display:flex;flex-direction:column;gap:12px}
2964
+ .dsmm-profiles .dsmm-route-fields{display:flex;flex-wrap:wrap;gap:12px;min-width:0}
2965
+ .dsmm-profiles .dsmm-route-fields>.dsmm-field{flex:1 1 240px;max-width:100%}
2966
+ .dsmm-profiles .dsmm-route-fields select{width:100%}
2967
+ .dsmm-profiles summary{cursor:pointer;color:var(--dsw-alias-label-primary);min-height:32px;line-height:32px}
2968
+ .dsmm-profiles summary:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
2969
+ .dsmm-profiles .dsmm-advanced[open]>div{margin-top:8px}
2970
+ .dsmm-profiles.dsmm-header-profiles{width:auto;max-width:min(100%,max(0px,calc(100cqw - 24px)));flex-direction:row;flex-wrap:wrap;align-items:center;gap:8px}
2971
+ .dsmm-profiles.dsmm-header-profiles select{width:240px;max-width:100%;flex:1 1 0}
2972
+ .dsmm-header-profiles span{min-width:0;max-width:100%;overflow-wrap:anywhere;color:var(--dsw-alias-label-secondary)}
1882
2973
  .dsmm-profiles p{margin:0;overflow-wrap:anywhere}
1883
2974
  .dsmm-profiles .dsmm-hint{color:var(--dsw-alias-label-secondary)}
1884
2975
  .dsmm-profiles .dsmm-field{min-width:0;display:flex;flex-direction:column;gap:6px}
1885
2976
  .dsmm-profiles .dsmm-actions{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
1886
- .dsmm-profiles .dsmm-actions>button{max-width:100%;white-space:normal;overflow-wrap:anywhere;min-height:36px;height:auto}
2977
+ .dsmm-profiles button{max-width:100%;white-space:normal;overflow-wrap:anywhere;min-height:36px;height:auto}
1887
2978
  .dsmm-profiles .dsmm-input{width:100%;min-width:0;box-sizing:border-box;border-color:var(--dsw-alias-label-secondary)}
1888
2979
  .dsmm-profiles .dsmm-input input{width:100%;min-width:0;font:inherit;color:inherit}
1889
2980
  .dsmm-profiles select,.dsmm-profiles textarea{box-sizing:border-box;min-width:0;max-width:100%;font:inherit;color:var(--dsw-alias-label-primary);background:var(--dsw-alias-bg-layer-1);border:1px solid var(--dsw-alias-label-secondary);border-radius:var(--dsw-radius-md)}
@@ -1924,6 +3015,56 @@ async function apply(ctx) {
1924
3015
  locale: NS,
1925
3016
  inject: () => ({ hooks: { profiles: controller.store }, ...controller.actions })
1926
3017
  }, ProfilesSection));
3018
+ void profileCtx.inject(["remote.session"], (catalogCtx) => {
3019
+ controller.attachCatalog(catalogCtx.remote.session);
3020
+ controller.attachModelSelector(catalogCtx.remote.session);
3021
+ catalogCtx.effect(() => () => {
3022
+ controller.attachModelSelector(null);
3023
+ controller.attachCatalog(null);
3024
+ }, "dsmm: native catalog/selector lifetime");
3025
+ });
3026
+ void profileCtx.inject(["uiSession", "sessions"], (sessionCtx) => {
3027
+ const source = sessionCtx.uiSession.adapter.current;
3028
+ const nativeSessions = sessionCtx.sessions;
3029
+ const update = () => {
3030
+ const binding = source.getSnapshot();
3031
+ controller.setSession(binding.key ?? null);
3032
+ controller.attachModelSelectionSource(binding.key ?? null, binding.key === void 0 ? null : binding.keyedHooks.projection?.("modelSelection") ?? null);
3033
+ controller.attachModelEventSource(binding.key ?? null, binding.key === void 0 ? null : nativeSessions.binding(binding.key)?.eventSource ?? null);
3034
+ };
3035
+ update();
3036
+ sessionCtx.effect(() => source.subscribe(update), "dsmm: current native session");
3037
+ sessionCtx.effect(() => () => {
3038
+ controller.attachModelSelectionSource(null, null);
3039
+ controller.attachModelEventSource(null, null);
3040
+ controller.attachModelInteractionSource(null, null);
3041
+ controller.setSession(null);
3042
+ }, "dsmm: native session withdrawal");
3043
+ void sessionCtx.inject(["modelDirectories", "remote.session"], (modelCtx) => {
3044
+ const updateInteraction = () => {
3045
+ const id2 = source.getSnapshot().key;
3046
+ if (id2 === void 0 || nativeSessions.binding(id2) === void 0) {
3047
+ controller.attachModelInteractionSource(null, null);
3048
+ return;
3049
+ }
3050
+ try {
3051
+ controller.attachModelInteractionSource(id2, modelCtx.modelDirectories.directoryFor(id2).store);
3052
+ } catch {
3053
+ controller.attachModelInteractionSource(null, null);
3054
+ }
3055
+ };
3056
+ updateInteraction();
3057
+ modelCtx.effect(() => source.subscribe(updateInteraction), "dsmm: native model interaction binding");
3058
+ modelCtx.effect(() => () => controller.attachModelInteractionSource(null, null), "dsmm: native model interaction withdrawal");
3059
+ });
3060
+ sessionCtx.slots.inject("conversation.session.header.utilities", () => sessionCtx.slots.register({
3061
+ name: "conversation.session.header.utilities",
3062
+ id: "dsmm-session-profiles",
3063
+ order: 30,
3064
+ locale: NS,
3065
+ inject: () => ({ hooks: { profiles: controller.store }, ...controller.actions })
3066
+ }, SessionProfiles));
3067
+ });
1927
3068
  void controller.refresh();
1928
3069
  });
1929
3070
  }