@dsmm/dsmm 0.1.1 → 0.1.5

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 (108) hide show
  1. package/README.md +26 -15
  2. package/agent-presets/dsmm-builder/agent.cordis.yml +14 -12
  3. package/agent-presets/dsmm-builder/preset.yml +1 -1
  4. package/agent-presets/dsmm-clarifier/agent.cordis.yml +4 -2
  5. package/agent-presets/dsmm-clarifier/preset.yml +1 -1
  6. package/agent-presets/dsmm-code-search/agent.cordis.yml +4 -2
  7. package/agent-presets/dsmm-code-search/preset.yml +1 -1
  8. package/agent-presets/dsmm-creative/agent.cordis.yml +3 -1
  9. package/agent-presets/dsmm-creative/preset.yml +1 -1
  10. package/agent-presets/dsmm-doc-search/agent.cordis.yml +4 -2
  11. package/agent-presets/dsmm-doc-search/preset.yml +1 -1
  12. package/agent-presets/dsmm-media-reader/agent.cordis.yml +4 -2
  13. package/agent-presets/dsmm-media-reader/preset.yml +1 -1
  14. package/agent-presets/dsmm-oracle/agent.cordis.yml +3 -1
  15. package/agent-presets/dsmm-oracle/preset.yml +1 -1
  16. package/agent-presets/dsmm-oracle-2nd/agent.cordis.yml +3 -1
  17. package/agent-presets/dsmm-oracle-2nd/preset.yml +1 -1
  18. package/agent-presets/dsmm-orchestrator/agent.cordis.yml +15 -13
  19. package/agent-presets/dsmm-orchestrator/preset.yml +2 -2
  20. package/agent-presets/dsmm-plan-critic/agent.cordis.yml +4 -2
  21. package/agent-presets/dsmm-plan-critic/preset.yml +1 -1
  22. package/agent-presets/dsmm-planner/agent.cordis.yml +4 -2
  23. package/agent-presets/dsmm-planner/preset.yml +1 -1
  24. package/agent-presets/dsmm-reviewer/agent.cordis.yml +4 -2
  25. package/agent-presets/dsmm-reviewer/preset.yml +1 -1
  26. package/docs/agent-presets.md +15 -5
  27. package/docs/compatibility.md +66 -11
  28. package/docs/migration-from-ocmm.md +8 -0
  29. package/docs/model-routing.md +25 -7
  30. package/docs/profiles.md +95 -0
  31. package/docs/releasing.md +66 -19
  32. package/docs/runtime-recovery.md +39 -14
  33. package/docs/settings-status.md +13 -5
  34. package/lib/client/ProfilesSection.d.ts +11 -0
  35. package/lib/client/ProfilesSection.js +66 -0
  36. package/lib/client/SessionProfiles.d.ts +19 -0
  37. package/lib/client/SessionProfiles.js +24 -0
  38. package/lib/client/StructuredEditor.d.ts +11 -0
  39. package/lib/client/StructuredEditor.js +74 -0
  40. package/lib/client/controller.d.ts +115 -0
  41. package/lib/client/controller.js +340 -0
  42. package/lib/client/index.d.ts +13 -0
  43. package/lib/client/index.js +54 -0
  44. package/lib/client/locales.d.ts +145 -0
  45. package/lib/client/locales.js +91 -0
  46. package/lib/client/session-labels.d.ts +8 -0
  47. package/lib/client/session-labels.js +13 -0
  48. package/lib/client/structured.d.ts +18 -0
  49. package/lib/client/structured.js +98 -0
  50. package/lib/client/styles.d.ts +3 -0
  51. package/lib/client/styles.js +36 -0
  52. package/lib/client.js +2825 -0
  53. package/lib/commands.d.ts +3 -3
  54. package/lib/commands.js +5 -4
  55. package/lib/dsh-types.d.ts +20 -0
  56. package/lib/guards.d.ts +2 -2
  57. package/lib/guards.js +3 -2
  58. package/lib/index.d.ts +12 -4
  59. package/lib/index.js +98 -20
  60. package/lib/mode.d.ts +2 -2
  61. package/lib/mode.js +1 -1
  62. package/lib/model-routing.d.ts +2 -2
  63. package/lib/model-routing.js +100 -15
  64. package/lib/preset-registry.js +5 -3
  65. package/lib/profile-remote.d.ts +37 -0
  66. package/lib/profile-remote.js +219 -0
  67. package/lib/profile-rpc.d.ts +35 -0
  68. package/lib/profile-rpc.js +187 -0
  69. package/lib/profile-runtime.d.ts +63 -0
  70. package/lib/profile-runtime.js +310 -0
  71. package/lib/profile-store.d.ts +60 -0
  72. package/lib/profile-store.js +588 -0
  73. package/lib/profile-types.d.ts +80 -0
  74. package/lib/profile-types.js +2 -0
  75. package/lib/profiles.d.ts +26 -0
  76. package/lib/profiles.js +269 -0
  77. package/lib/prompts.d.ts +2 -2
  78. package/lib/prompts.js +4 -4
  79. package/lib/role-providers.d.ts +2 -2
  80. package/lib/role-providers.js +49 -6
  81. package/lib/role-routing.d.ts +37 -3
  82. package/lib/role-routing.js +110 -35
  83. package/lib/role-subagents.d.ts +2 -2
  84. package/lib/role-subagents.js +6 -4
  85. package/lib/roles.d.ts +4 -0
  86. package/lib/roles.js +43 -27
  87. package/lib/routing-policy.d.ts +32 -0
  88. package/lib/routing-policy.js +92 -0
  89. package/lib/runtime-recovery.d.ts +2 -2
  90. package/lib/runtime-recovery.js +215 -54
  91. package/lib/session-metadata.d.ts +13 -0
  92. package/lib/session-metadata.js +34 -0
  93. package/lib/session-persistence.d.ts +35 -0
  94. package/lib/session-persistence.js +304 -0
  95. package/lib/settings.d.ts +34 -1
  96. package/lib/settings.js +33 -7
  97. package/lib/state.d.ts +1 -0
  98. package/lib/state.js +4 -0
  99. package/lib/status.d.ts +9 -1
  100. package/lib/status.js +34 -12
  101. package/locale/en.json +6 -0
  102. package/locale/zh.json +6 -0
  103. package/package.json +66 -15
  104. package/patches/agent-presets-root.example.cordis.patch.yml +6 -10
  105. package/prompts/deepseek-v4-pro.md +1 -1
  106. package/prompts/deepwork.md +3 -3
  107. package/scripts/repair-session-log.mjs +476 -0
  108. package/scripts/session-repair-native-verifier.mjs +367 -0
package/lib/client.js ADDED
@@ -0,0 +1,2825 @@
1
+ window.__ModuleLoader__.load({ id: "@dsmm/dsmm", factory: (require) => { const module = { exports: {} }; const exports = module.exports;
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/client/index.ts
22
+ var index_exports = {};
23
+ __export(index_exports, {
24
+ NEW_PROFILE_CONTENT: () => NEW_PROFILE_CONTENT,
25
+ NS: () => NS,
26
+ ProfilesController: () => ProfilesController,
27
+ ProfilesSection: () => ProfilesSection,
28
+ SessionProfiles: () => SessionProfiles,
29
+ TYPERT_REMOTE: () => TYPERT_REMOTE,
30
+ apply: () => apply,
31
+ editStructuredPath: () => editStructuredPath,
32
+ en: () => en,
33
+ inject: () => inject,
34
+ moveFallback: () => moveFallback,
35
+ structuredDocument: () => structuredDocument,
36
+ zh: () => zh
37
+ });
38
+ module.exports = __toCommonJS(index_exports);
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
+
87
+ // src/profile-remote.ts
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"]);
89
+ var idPattern = /^[a-z0-9][a-z0-9_-]{0,63}$/u;
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;
92
+ function isProfileId(value) {
93
+ return typeof value === "string" && idPattern.test(value) && !/^(?:con|prn|aux|nul|com[0-9]|lpt[0-9])$/iu.test(value);
94
+ }
95
+ function fail(field) {
96
+ throw new TypeError(`Invalid Deepwork profile wire field: ${field}`);
97
+ }
98
+ function text(value, field, maximum = 1024) {
99
+ if (typeof value !== "string" || value.length > maximum) fail(field);
100
+ return value;
101
+ }
102
+ function id(value) {
103
+ const result = text(value, "id", 64);
104
+ if (!isProfileId(result)) fail("id");
105
+ return result;
106
+ }
107
+ function revision(value) {
108
+ const result = text(value, "revision", 64);
109
+ if (!revisionPattern.test(result)) fail("revision");
110
+ return result;
111
+ }
112
+ function selectionRevision(value) {
113
+ return value === "absent" ? value : revision(value);
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
+ }
139
+ function object(value, required, optional2 = []) {
140
+ if (value === null || typeof value !== "object" || Array.isArray(value)) fail("object");
141
+ const result = value;
142
+ if (Object.keys(result).some((key) => !required.includes(key) && !optional2.includes(key)) || required.some((key) => !Object.hasOwn(result, key))) fail("object keys");
143
+ return result;
144
+ }
145
+ function optional(value, key, parse3) {
146
+ return Object.hasOwn(value, key) ? { [key]: parse3(value[key]) } : {};
147
+ }
148
+ function errorInfo(value) {
149
+ const item = object(value, ["code", "message"], ["field"]);
150
+ const code = text(item.code, "code");
151
+ if (!errorCodes.has(code)) fail("code");
152
+ return { code, message: text(item.message, "message", 4096), ...optional(item, "field", (input) => text(input, "field", 256)) };
153
+ }
154
+ function readResult(value) {
155
+ const item = object(value, ["id", "revision", "content"], ["label"]);
156
+ return { id: id(item.id), revision: revision(item.revision), content: content(item.content), ...optional(item, "label", (input) => text(input, "label", 120)) };
157
+ }
158
+ function content(value) {
159
+ const result = text(value, "content", 128 * 1024);
160
+ if (new TextEncoder().encode(result).byteLength > 128 * 1024) fail("content");
161
+ return result;
162
+ }
163
+ function snapshot(value) {
164
+ const item = object(value, ["profiles", "selectedId", "appliedRevision", "selectionRevision"], ["selectionError", "roles", "editorDefaults"]);
165
+ if (!Array.isArray(item.profiles) || item.profiles.length > 128) fail("profiles");
166
+ return {
167
+ profiles: item.profiles.map((input) => {
168
+ const row = object(input, ["id", "revision"], ["label", "error"]);
169
+ return { id: text(row.id, "id", 64), revision: row.revision === null ? null : revision(row.revision), ...optional(row, "label", (input2) => text(input2, "label", 120)), ...optional(row, "error", errorInfo) };
170
+ }),
171
+ selectedId: item.selectedId === null ? null : id(item.selectedId),
172
+ appliedRevision: item.appliedRevision === null ? null : revision(item.appliedRevision),
173
+ selectionRevision: item.selectionRevision === "unavailable" && Object.hasOwn(item, "selectionError") ? "unavailable" : selectionRevision(item.selectionRevision),
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", (input) => {
208
+ const route2 = object(input, ["provider", "model"], ["reasoningEffort"]);
209
+ const provider = routeText(route2.provider, "provider", 128);
210
+ const model = routeText(route2.model, "model", 512);
211
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/u.test(provider) || model.includes("://")) fail("route");
212
+ return { provider, model, ...optional(route2, "reasoningEffort", (value2) => routeText(value2, "reasoningEffort", 64)) };
213
+ })
214
+ };
215
+ }
216
+ function selectionState(value) {
217
+ const item = object(value, ["selectedId", "appliedRevision", "selectionRevision"]);
218
+ return { selectedId: item.selectedId === null ? null : id(item.selectedId), appliedRevision: item.appliedRevision === null ? null : revision(item.appliedRevision), selectionRevision: selectionRevision(item.selectionRevision) };
219
+ }
220
+ function sessionSnapshot(value) {
221
+ const item = object(value, ["sessionId", "globalDefault", "selection", "scope", "admissionEpoch", "switchAllowed"], ["admittedSelection", "switchUnavailableReason", "rolePolicy"]);
222
+ if (typeof item.scope !== "string" || !["global-default", "session-override", "deployment-baseline"].includes(item.scope)) fail("scope");
223
+ return {
224
+ sessionId: sessionId(item.sessionId),
225
+ globalDefault: selectionState(item.globalDefault),
226
+ selection: selectionState(item.selection),
227
+ scope: item.scope,
228
+ admissionEpoch: revision(item.admissionEpoch),
229
+ switchAllowed: boolean(item.switchAllowed, "switchAllowed"),
230
+ ...optional(item, "admittedSelection", selectionState),
231
+ ...optional(item, "switchUnavailableReason", (input) => {
232
+ if (typeof input !== "string" || !["busy", "maintenance", "disposed", "not-owned", "unavailable"].includes(input)) fail("switchUnavailableReason");
233
+ return input;
234
+ }),
235
+ ...optional(item, "rolePolicy", rolePolicy)
236
+ };
237
+ }
238
+ function saveRequest(value) {
239
+ const item = object(value, ["id", "content", "expectedRevision"]);
240
+ return { id: id(item.id), content: content(item.content), expectedRevision: item.expectedRevision === null ? null : revision(item.expectedRevision) };
241
+ }
242
+ function selectRequest(value) {
243
+ const item = object(value, ["id", "expectedSelectionRevision"], ["expectedRevision"]);
244
+ const result = { id: item.id === null ? null : id(item.id), expectedSelectionRevision: selectionRevision(item.expectedSelectionRevision), ...optional(item, "expectedRevision", revision) };
245
+ if (result.id !== null && result.expectedRevision === void 0) fail("expectedRevision");
246
+ if (result.id === null && result.expectedRevision !== void 0) fail("expectedRevision");
247
+ return result;
248
+ }
249
+ function sessionSelectRequest(value) {
250
+ const item = object(value, ["sessionId", "id", "expectedSelectionRevision", "expectedAdmissionEpoch"], ["expectedRevision"]);
251
+ const { sessionId: inputSessionId, expectedAdmissionEpoch, ...profileRequest } = item;
252
+ return { ...selectRequest(profileRequest), sessionId: sessionId(inputSessionId), expectedAdmissionEpoch: revision(expectedAdmissionEpoch) };
253
+ }
254
+ function codec(symbol, parse3) {
255
+ return { mode: "strict", typeSymbol: `@dsmm/dsmm#${symbol}`, create: () => ({ parse: parse3 }) };
256
+ }
257
+ function descriptor(method, result, parameter) {
258
+ 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 };
259
+ }
260
+ var TYPERT_REMOTE = {
261
+ package: "@dsmm/dsmm",
262
+ descriptors: [
263
+ descriptor("describe", codec("ProfileSnapshot", snapshot)),
264
+ descriptor("read", codec("ProfileReadResult", readResult), { name: "id", codec: codec("ProfileId", id) }),
265
+ descriptor("save", codec("ProfileReadResult", readResult), { name: "request", codec: codec("ProfileSaveRequest", saveRequest) }),
266
+ descriptor("select", codec("ProfileSnapshot", snapshot), { name: "request", codec: codec("ProfileSelectRequest", selectRequest) }),
267
+ {
268
+ ...descriptor("describeSession", codec("SessionProfileSnapshot", sessionSnapshot)),
269
+ parameters: [{ name: "sessionId", wire: "sessionId", source: "json", codec: codec("NativeSessionId", sessionId) }]
270
+ },
271
+ {
272
+ ...descriptor("selectSession", codec("SessionProfileSnapshot", sessionSnapshot)),
273
+ parameters: [
274
+ { name: "sessionId", wire: "sessionId", source: "json", codec: codec("NativeSessionId", sessionId) },
275
+ { name: "request", wire: "request", source: "json", codec: codec("SessionProfileSelectRequest", sessionSelectRequest) }
276
+ ]
277
+ }
278
+ ]
279
+ };
280
+ var TYPERT_HOST = {
281
+ package: "@dsmm/dsmm",
282
+ face: "host",
283
+ schemas: [],
284
+ model: { services: [], events: [], objects: [] },
285
+ invocations: TYPERT_REMOTE.descriptors
286
+ };
287
+
288
+ // ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/scanner.js
289
+ function createScanner(text2, ignoreTrivia = false) {
290
+ const len = text2.length;
291
+ let pos = 0, value = "", tokenOffset = 0, token = 16, lineNumber = 0, lineStartOffset = 0, tokenLineStartOffset = 0, prevTokenLineStartOffset = 0, scanError = 0;
292
+ function scanHexDigits(count, exact) {
293
+ let digits = 0;
294
+ let value2 = 0;
295
+ while (digits < count || !exact) {
296
+ let ch = text2.charCodeAt(pos);
297
+ if (ch >= 48 && ch <= 57) {
298
+ value2 = value2 * 16 + ch - 48;
299
+ } else if (ch >= 65 && ch <= 70) {
300
+ value2 = value2 * 16 + ch - 65 + 10;
301
+ } else if (ch >= 97 && ch <= 102) {
302
+ value2 = value2 * 16 + ch - 97 + 10;
303
+ } else {
304
+ break;
305
+ }
306
+ pos++;
307
+ digits++;
308
+ }
309
+ if (digits < count) {
310
+ value2 = -1;
311
+ }
312
+ return value2;
313
+ }
314
+ function setPosition(newPosition) {
315
+ pos = newPosition;
316
+ value = "";
317
+ tokenOffset = 0;
318
+ token = 16;
319
+ scanError = 0;
320
+ }
321
+ function scanNumber() {
322
+ let start = pos;
323
+ if (text2.charCodeAt(pos) === 48) {
324
+ pos++;
325
+ } else {
326
+ pos++;
327
+ while (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
328
+ pos++;
329
+ }
330
+ }
331
+ if (pos < text2.length && text2.charCodeAt(pos) === 46) {
332
+ pos++;
333
+ if (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
334
+ pos++;
335
+ while (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
336
+ pos++;
337
+ }
338
+ } else {
339
+ scanError = 3;
340
+ return text2.substring(start, pos);
341
+ }
342
+ }
343
+ let end = pos;
344
+ if (pos < text2.length && (text2.charCodeAt(pos) === 69 || text2.charCodeAt(pos) === 101)) {
345
+ pos++;
346
+ if (pos < text2.length && text2.charCodeAt(pos) === 43 || text2.charCodeAt(pos) === 45) {
347
+ pos++;
348
+ }
349
+ if (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
350
+ pos++;
351
+ while (pos < text2.length && isDigit(text2.charCodeAt(pos))) {
352
+ pos++;
353
+ }
354
+ end = pos;
355
+ } else {
356
+ scanError = 3;
357
+ }
358
+ }
359
+ return text2.substring(start, end);
360
+ }
361
+ function scanString() {
362
+ let result = "", start = pos;
363
+ while (true) {
364
+ if (pos >= len) {
365
+ result += text2.substring(start, pos);
366
+ scanError = 2;
367
+ break;
368
+ }
369
+ const ch = text2.charCodeAt(pos);
370
+ if (ch === 34) {
371
+ result += text2.substring(start, pos);
372
+ pos++;
373
+ break;
374
+ }
375
+ if (ch === 92) {
376
+ result += text2.substring(start, pos);
377
+ pos++;
378
+ if (pos >= len) {
379
+ scanError = 2;
380
+ break;
381
+ }
382
+ const ch2 = text2.charCodeAt(pos++);
383
+ switch (ch2) {
384
+ case 34:
385
+ result += '"';
386
+ break;
387
+ case 92:
388
+ result += "\\";
389
+ break;
390
+ case 47:
391
+ result += "/";
392
+ break;
393
+ case 98:
394
+ result += "\b";
395
+ break;
396
+ case 102:
397
+ result += "\f";
398
+ break;
399
+ case 110:
400
+ result += "\n";
401
+ break;
402
+ case 114:
403
+ result += "\r";
404
+ break;
405
+ case 116:
406
+ result += " ";
407
+ break;
408
+ case 117:
409
+ const ch3 = scanHexDigits(4, true);
410
+ if (ch3 >= 0) {
411
+ result += String.fromCharCode(ch3);
412
+ } else {
413
+ scanError = 4;
414
+ }
415
+ break;
416
+ default:
417
+ scanError = 5;
418
+ }
419
+ start = pos;
420
+ continue;
421
+ }
422
+ if (ch >= 0 && ch <= 31) {
423
+ if (isLineBreak(ch)) {
424
+ result += text2.substring(start, pos);
425
+ scanError = 2;
426
+ break;
427
+ } else {
428
+ scanError = 6;
429
+ }
430
+ }
431
+ pos++;
432
+ }
433
+ return result;
434
+ }
435
+ function scanNext() {
436
+ value = "";
437
+ scanError = 0;
438
+ tokenOffset = pos;
439
+ lineStartOffset = lineNumber;
440
+ prevTokenLineStartOffset = tokenLineStartOffset;
441
+ if (pos >= len) {
442
+ tokenOffset = len;
443
+ return token = 17;
444
+ }
445
+ let code = text2.charCodeAt(pos);
446
+ if (isWhiteSpace(code)) {
447
+ do {
448
+ pos++;
449
+ value += String.fromCharCode(code);
450
+ code = text2.charCodeAt(pos);
451
+ } while (isWhiteSpace(code));
452
+ return token = 15;
453
+ }
454
+ if (isLineBreak(code)) {
455
+ pos++;
456
+ value += String.fromCharCode(code);
457
+ if (code === 13 && text2.charCodeAt(pos) === 10) {
458
+ pos++;
459
+ value += "\n";
460
+ }
461
+ lineNumber++;
462
+ tokenLineStartOffset = pos;
463
+ return token = 14;
464
+ }
465
+ switch (code) {
466
+ // tokens: []{}:,
467
+ case 123:
468
+ pos++;
469
+ return token = 1;
470
+ case 125:
471
+ pos++;
472
+ return token = 2;
473
+ case 91:
474
+ pos++;
475
+ return token = 3;
476
+ case 93:
477
+ pos++;
478
+ return token = 4;
479
+ case 58:
480
+ pos++;
481
+ return token = 6;
482
+ case 44:
483
+ pos++;
484
+ return token = 5;
485
+ // strings
486
+ case 34:
487
+ pos++;
488
+ value = scanString();
489
+ return token = 10;
490
+ // comments
491
+ case 47:
492
+ const start = pos - 1;
493
+ if (text2.charCodeAt(pos + 1) === 47) {
494
+ pos += 2;
495
+ while (pos < len) {
496
+ if (isLineBreak(text2.charCodeAt(pos))) {
497
+ break;
498
+ }
499
+ pos++;
500
+ }
501
+ value = text2.substring(start, pos);
502
+ return token = 12;
503
+ }
504
+ if (text2.charCodeAt(pos + 1) === 42) {
505
+ pos += 2;
506
+ const safeLength = len - 1;
507
+ let commentClosed = false;
508
+ while (pos < safeLength) {
509
+ const ch = text2.charCodeAt(pos);
510
+ if (ch === 42 && text2.charCodeAt(pos + 1) === 47) {
511
+ pos += 2;
512
+ commentClosed = true;
513
+ break;
514
+ }
515
+ pos++;
516
+ if (isLineBreak(ch)) {
517
+ if (ch === 13 && text2.charCodeAt(pos) === 10) {
518
+ pos++;
519
+ }
520
+ lineNumber++;
521
+ tokenLineStartOffset = pos;
522
+ }
523
+ }
524
+ if (!commentClosed) {
525
+ pos++;
526
+ scanError = 1;
527
+ }
528
+ value = text2.substring(start, pos);
529
+ return token = 13;
530
+ }
531
+ value += String.fromCharCode(code);
532
+ pos++;
533
+ return token = 16;
534
+ // numbers
535
+ case 45:
536
+ value += String.fromCharCode(code);
537
+ pos++;
538
+ if (pos === len || !isDigit(text2.charCodeAt(pos))) {
539
+ return token = 16;
540
+ }
541
+ // found a minus, followed by a number so
542
+ // we fall through to proceed with scanning
543
+ // numbers
544
+ case 48:
545
+ case 49:
546
+ case 50:
547
+ case 51:
548
+ case 52:
549
+ case 53:
550
+ case 54:
551
+ case 55:
552
+ case 56:
553
+ case 57:
554
+ value += scanNumber();
555
+ return token = 11;
556
+ // literals and unknown symbols
557
+ default:
558
+ while (pos < len && isUnknownContentCharacter(code)) {
559
+ pos++;
560
+ code = text2.charCodeAt(pos);
561
+ }
562
+ if (tokenOffset !== pos) {
563
+ value = text2.substring(tokenOffset, pos);
564
+ switch (value) {
565
+ case "true":
566
+ return token = 8;
567
+ case "false":
568
+ return token = 9;
569
+ case "null":
570
+ return token = 7;
571
+ }
572
+ return token = 16;
573
+ }
574
+ value += String.fromCharCode(code);
575
+ pos++;
576
+ return token = 16;
577
+ }
578
+ }
579
+ function isUnknownContentCharacter(code) {
580
+ if (isWhiteSpace(code) || isLineBreak(code)) {
581
+ return false;
582
+ }
583
+ switch (code) {
584
+ case 125:
585
+ case 93:
586
+ case 123:
587
+ case 91:
588
+ case 34:
589
+ case 58:
590
+ case 44:
591
+ case 47:
592
+ return false;
593
+ }
594
+ return true;
595
+ }
596
+ function scanNextNonTrivia() {
597
+ let result;
598
+ do {
599
+ result = scanNext();
600
+ } while (result >= 12 && result <= 15);
601
+ return result;
602
+ }
603
+ return {
604
+ setPosition,
605
+ getPosition: () => pos,
606
+ scan: ignoreTrivia ? scanNextNonTrivia : scanNext,
607
+ getToken: () => token,
608
+ getTokenValue: () => value,
609
+ getTokenOffset: () => tokenOffset,
610
+ getTokenLength: () => pos - tokenOffset,
611
+ getTokenStartLine: () => lineStartOffset,
612
+ getTokenStartCharacter: () => tokenOffset - prevTokenLineStartOffset,
613
+ getTokenError: () => scanError
614
+ };
615
+ }
616
+ function isWhiteSpace(ch) {
617
+ return ch === 32 || ch === 9;
618
+ }
619
+ function isLineBreak(ch) {
620
+ return ch === 10 || ch === 13;
621
+ }
622
+ function isDigit(ch) {
623
+ return ch >= 48 && ch <= 57;
624
+ }
625
+ var CharacterCodes;
626
+ (function(CharacterCodes2) {
627
+ CharacterCodes2[CharacterCodes2["lineFeed"] = 10] = "lineFeed";
628
+ CharacterCodes2[CharacterCodes2["carriageReturn"] = 13] = "carriageReturn";
629
+ CharacterCodes2[CharacterCodes2["space"] = 32] = "space";
630
+ CharacterCodes2[CharacterCodes2["_0"] = 48] = "_0";
631
+ CharacterCodes2[CharacterCodes2["_1"] = 49] = "_1";
632
+ CharacterCodes2[CharacterCodes2["_2"] = 50] = "_2";
633
+ CharacterCodes2[CharacterCodes2["_3"] = 51] = "_3";
634
+ CharacterCodes2[CharacterCodes2["_4"] = 52] = "_4";
635
+ CharacterCodes2[CharacterCodes2["_5"] = 53] = "_5";
636
+ CharacterCodes2[CharacterCodes2["_6"] = 54] = "_6";
637
+ CharacterCodes2[CharacterCodes2["_7"] = 55] = "_7";
638
+ CharacterCodes2[CharacterCodes2["_8"] = 56] = "_8";
639
+ CharacterCodes2[CharacterCodes2["_9"] = 57] = "_9";
640
+ CharacterCodes2[CharacterCodes2["a"] = 97] = "a";
641
+ CharacterCodes2[CharacterCodes2["b"] = 98] = "b";
642
+ CharacterCodes2[CharacterCodes2["c"] = 99] = "c";
643
+ CharacterCodes2[CharacterCodes2["d"] = 100] = "d";
644
+ CharacterCodes2[CharacterCodes2["e"] = 101] = "e";
645
+ CharacterCodes2[CharacterCodes2["f"] = 102] = "f";
646
+ CharacterCodes2[CharacterCodes2["g"] = 103] = "g";
647
+ CharacterCodes2[CharacterCodes2["h"] = 104] = "h";
648
+ CharacterCodes2[CharacterCodes2["i"] = 105] = "i";
649
+ CharacterCodes2[CharacterCodes2["j"] = 106] = "j";
650
+ CharacterCodes2[CharacterCodes2["k"] = 107] = "k";
651
+ CharacterCodes2[CharacterCodes2["l"] = 108] = "l";
652
+ CharacterCodes2[CharacterCodes2["m"] = 109] = "m";
653
+ CharacterCodes2[CharacterCodes2["n"] = 110] = "n";
654
+ CharacterCodes2[CharacterCodes2["o"] = 111] = "o";
655
+ CharacterCodes2[CharacterCodes2["p"] = 112] = "p";
656
+ CharacterCodes2[CharacterCodes2["q"] = 113] = "q";
657
+ CharacterCodes2[CharacterCodes2["r"] = 114] = "r";
658
+ CharacterCodes2[CharacterCodes2["s"] = 115] = "s";
659
+ CharacterCodes2[CharacterCodes2["t"] = 116] = "t";
660
+ CharacterCodes2[CharacterCodes2["u"] = 117] = "u";
661
+ CharacterCodes2[CharacterCodes2["v"] = 118] = "v";
662
+ CharacterCodes2[CharacterCodes2["w"] = 119] = "w";
663
+ CharacterCodes2[CharacterCodes2["x"] = 120] = "x";
664
+ CharacterCodes2[CharacterCodes2["y"] = 121] = "y";
665
+ CharacterCodes2[CharacterCodes2["z"] = 122] = "z";
666
+ CharacterCodes2[CharacterCodes2["A"] = 65] = "A";
667
+ CharacterCodes2[CharacterCodes2["B"] = 66] = "B";
668
+ CharacterCodes2[CharacterCodes2["C"] = 67] = "C";
669
+ CharacterCodes2[CharacterCodes2["D"] = 68] = "D";
670
+ CharacterCodes2[CharacterCodes2["E"] = 69] = "E";
671
+ CharacterCodes2[CharacterCodes2["F"] = 70] = "F";
672
+ CharacterCodes2[CharacterCodes2["G"] = 71] = "G";
673
+ CharacterCodes2[CharacterCodes2["H"] = 72] = "H";
674
+ CharacterCodes2[CharacterCodes2["I"] = 73] = "I";
675
+ CharacterCodes2[CharacterCodes2["J"] = 74] = "J";
676
+ CharacterCodes2[CharacterCodes2["K"] = 75] = "K";
677
+ CharacterCodes2[CharacterCodes2["L"] = 76] = "L";
678
+ CharacterCodes2[CharacterCodes2["M"] = 77] = "M";
679
+ CharacterCodes2[CharacterCodes2["N"] = 78] = "N";
680
+ CharacterCodes2[CharacterCodes2["O"] = 79] = "O";
681
+ CharacterCodes2[CharacterCodes2["P"] = 80] = "P";
682
+ CharacterCodes2[CharacterCodes2["Q"] = 81] = "Q";
683
+ CharacterCodes2[CharacterCodes2["R"] = 82] = "R";
684
+ CharacterCodes2[CharacterCodes2["S"] = 83] = "S";
685
+ CharacterCodes2[CharacterCodes2["T"] = 84] = "T";
686
+ CharacterCodes2[CharacterCodes2["U"] = 85] = "U";
687
+ CharacterCodes2[CharacterCodes2["V"] = 86] = "V";
688
+ CharacterCodes2[CharacterCodes2["W"] = 87] = "W";
689
+ CharacterCodes2[CharacterCodes2["X"] = 88] = "X";
690
+ CharacterCodes2[CharacterCodes2["Y"] = 89] = "Y";
691
+ CharacterCodes2[CharacterCodes2["Z"] = 90] = "Z";
692
+ CharacterCodes2[CharacterCodes2["asterisk"] = 42] = "asterisk";
693
+ CharacterCodes2[CharacterCodes2["backslash"] = 92] = "backslash";
694
+ CharacterCodes2[CharacterCodes2["closeBrace"] = 125] = "closeBrace";
695
+ CharacterCodes2[CharacterCodes2["closeBracket"] = 93] = "closeBracket";
696
+ CharacterCodes2[CharacterCodes2["colon"] = 58] = "colon";
697
+ CharacterCodes2[CharacterCodes2["comma"] = 44] = "comma";
698
+ CharacterCodes2[CharacterCodes2["dot"] = 46] = "dot";
699
+ CharacterCodes2[CharacterCodes2["doubleQuote"] = 34] = "doubleQuote";
700
+ CharacterCodes2[CharacterCodes2["minus"] = 45] = "minus";
701
+ CharacterCodes2[CharacterCodes2["openBrace"] = 123] = "openBrace";
702
+ CharacterCodes2[CharacterCodes2["openBracket"] = 91] = "openBracket";
703
+ CharacterCodes2[CharacterCodes2["plus"] = 43] = "plus";
704
+ CharacterCodes2[CharacterCodes2["slash"] = 47] = "slash";
705
+ CharacterCodes2[CharacterCodes2["formFeed"] = 12] = "formFeed";
706
+ CharacterCodes2[CharacterCodes2["tab"] = 9] = "tab";
707
+ })(CharacterCodes || (CharacterCodes = {}));
708
+
709
+ // ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/string-intern.js
710
+ var cachedSpaces = new Array(20).fill(0).map((_, index) => {
711
+ return " ".repeat(index);
712
+ });
713
+ var maxCachedValues = 200;
714
+ var cachedBreakLinesWithSpaces = {
715
+ " ": {
716
+ "\n": new Array(maxCachedValues).fill(0).map((_, index) => {
717
+ return "\n" + " ".repeat(index);
718
+ }),
719
+ "\r": new Array(maxCachedValues).fill(0).map((_, index) => {
720
+ return "\r" + " ".repeat(index);
721
+ }),
722
+ "\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
723
+ return "\r\n" + " ".repeat(index);
724
+ })
725
+ },
726
+ " ": {
727
+ "\n": new Array(maxCachedValues).fill(0).map((_, index) => {
728
+ return "\n" + " ".repeat(index);
729
+ }),
730
+ "\r": new Array(maxCachedValues).fill(0).map((_, index) => {
731
+ return "\r" + " ".repeat(index);
732
+ }),
733
+ "\r\n": new Array(maxCachedValues).fill(0).map((_, index) => {
734
+ return "\r\n" + " ".repeat(index);
735
+ })
736
+ }
737
+ };
738
+ var supportedEols = ["\n", "\r", "\r\n"];
739
+
740
+ // ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/format.js
741
+ function format(documentText, range, options) {
742
+ let initialIndentLevel;
743
+ let formatText;
744
+ let formatTextStart;
745
+ let rangeStart;
746
+ let rangeEnd;
747
+ if (range) {
748
+ rangeStart = range.offset;
749
+ rangeEnd = rangeStart + range.length;
750
+ formatTextStart = rangeStart;
751
+ while (formatTextStart > 0 && !isEOL(documentText, formatTextStart - 1)) {
752
+ formatTextStart--;
753
+ }
754
+ let endOffset = rangeEnd;
755
+ while (endOffset < documentText.length && !isEOL(documentText, endOffset)) {
756
+ endOffset++;
757
+ }
758
+ formatText = documentText.substring(formatTextStart, endOffset);
759
+ initialIndentLevel = computeIndentLevel(formatText, options);
760
+ } else {
761
+ formatText = documentText;
762
+ initialIndentLevel = 0;
763
+ formatTextStart = 0;
764
+ rangeStart = 0;
765
+ rangeEnd = documentText.length;
766
+ }
767
+ const eol = getEOL(options, documentText);
768
+ const eolFastPathSupported = supportedEols.includes(eol);
769
+ let numberLineBreaks = 0;
770
+ let indentLevel = 0;
771
+ let indentValue;
772
+ if (options.insertSpaces) {
773
+ indentValue = cachedSpaces[options.tabSize || 4] ?? repeat(cachedSpaces[1], options.tabSize || 4);
774
+ } else {
775
+ indentValue = " ";
776
+ }
777
+ const indentType = indentValue === " " ? " " : " ";
778
+ let scanner = createScanner(formatText, false);
779
+ let hasError = false;
780
+ function newLinesAndIndent() {
781
+ if (numberLineBreaks > 1) {
782
+ return repeat(eol, numberLineBreaks) + repeat(indentValue, initialIndentLevel + indentLevel);
783
+ }
784
+ const amountOfSpaces = indentValue.length * (initialIndentLevel + indentLevel);
785
+ if (!eolFastPathSupported || amountOfSpaces > cachedBreakLinesWithSpaces[indentType][eol].length) {
786
+ return eol + repeat(indentValue, initialIndentLevel + indentLevel);
787
+ }
788
+ if (amountOfSpaces <= 0) {
789
+ return eol;
790
+ }
791
+ return cachedBreakLinesWithSpaces[indentType][eol][amountOfSpaces];
792
+ }
793
+ function scanNext() {
794
+ let token = scanner.scan();
795
+ numberLineBreaks = 0;
796
+ while (token === 15 || token === 14) {
797
+ if (token === 14 && options.keepLines) {
798
+ numberLineBreaks += 1;
799
+ } else if (token === 14) {
800
+ numberLineBreaks = 1;
801
+ }
802
+ token = scanner.scan();
803
+ }
804
+ hasError = token === 16 || scanner.getTokenError() !== 0;
805
+ return token;
806
+ }
807
+ const editOperations = [];
808
+ function addEdit(text2, startOffset, endOffset) {
809
+ if (!hasError && (!range || startOffset < rangeEnd && endOffset > rangeStart) && documentText.substring(startOffset, endOffset) !== text2) {
810
+ editOperations.push({ offset: startOffset, length: endOffset - startOffset, content: text2 });
811
+ }
812
+ }
813
+ let firstToken = scanNext();
814
+ if (options.keepLines && numberLineBreaks > 0) {
815
+ addEdit(repeat(eol, numberLineBreaks), 0, 0);
816
+ }
817
+ if (firstToken !== 17) {
818
+ let firstTokenStart = scanner.getTokenOffset() + formatTextStart;
819
+ let initialIndent = indentValue.length * initialIndentLevel < 20 && options.insertSpaces ? cachedSpaces[indentValue.length * initialIndentLevel] : repeat(indentValue, initialIndentLevel);
820
+ addEdit(initialIndent, formatTextStart, firstTokenStart);
821
+ }
822
+ while (firstToken !== 17) {
823
+ let firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
824
+ let secondToken = scanNext();
825
+ let replaceContent = "";
826
+ let needsLineBreak = false;
827
+ while (numberLineBreaks === 0 && (secondToken === 12 || secondToken === 13)) {
828
+ let commentTokenStart = scanner.getTokenOffset() + formatTextStart;
829
+ addEdit(cachedSpaces[1], firstTokenEnd, commentTokenStart);
830
+ firstTokenEnd = scanner.getTokenOffset() + scanner.getTokenLength() + formatTextStart;
831
+ needsLineBreak = secondToken === 12;
832
+ replaceContent = needsLineBreak ? newLinesAndIndent() : "";
833
+ secondToken = scanNext();
834
+ }
835
+ if (secondToken === 2) {
836
+ if (firstToken !== 1) {
837
+ indentLevel--;
838
+ }
839
+ ;
840
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 1) {
841
+ replaceContent = newLinesAndIndent();
842
+ } else if (options.keepLines) {
843
+ replaceContent = cachedSpaces[1];
844
+ }
845
+ } else if (secondToken === 4) {
846
+ if (firstToken !== 3) {
847
+ indentLevel--;
848
+ }
849
+ ;
850
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines && firstToken !== 3) {
851
+ replaceContent = newLinesAndIndent();
852
+ } else if (options.keepLines) {
853
+ replaceContent = cachedSpaces[1];
854
+ }
855
+ } else {
856
+ switch (firstToken) {
857
+ case 3:
858
+ case 1:
859
+ indentLevel++;
860
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
861
+ replaceContent = newLinesAndIndent();
862
+ } else {
863
+ replaceContent = cachedSpaces[1];
864
+ }
865
+ break;
866
+ case 5:
867
+ if (options.keepLines && numberLineBreaks > 0 || !options.keepLines) {
868
+ replaceContent = newLinesAndIndent();
869
+ } else {
870
+ replaceContent = cachedSpaces[1];
871
+ }
872
+ break;
873
+ case 12:
874
+ replaceContent = newLinesAndIndent();
875
+ break;
876
+ case 13:
877
+ if (numberLineBreaks > 0) {
878
+ replaceContent = newLinesAndIndent();
879
+ } else if (!needsLineBreak) {
880
+ replaceContent = cachedSpaces[1];
881
+ }
882
+ break;
883
+ case 6:
884
+ if (options.keepLines && numberLineBreaks > 0) {
885
+ replaceContent = newLinesAndIndent();
886
+ } else if (!needsLineBreak) {
887
+ replaceContent = cachedSpaces[1];
888
+ }
889
+ break;
890
+ case 10:
891
+ if (options.keepLines && numberLineBreaks > 0) {
892
+ replaceContent = newLinesAndIndent();
893
+ } else if (secondToken === 6 && !needsLineBreak) {
894
+ replaceContent = "";
895
+ }
896
+ break;
897
+ case 7:
898
+ case 8:
899
+ case 9:
900
+ case 11:
901
+ case 2:
902
+ case 4:
903
+ if (options.keepLines && numberLineBreaks > 0) {
904
+ replaceContent = newLinesAndIndent();
905
+ } else {
906
+ if ((secondToken === 12 || secondToken === 13) && !needsLineBreak) {
907
+ replaceContent = cachedSpaces[1];
908
+ } else if (secondToken !== 5 && secondToken !== 17) {
909
+ hasError = true;
910
+ }
911
+ }
912
+ break;
913
+ case 16:
914
+ hasError = true;
915
+ break;
916
+ }
917
+ if (numberLineBreaks > 0 && (secondToken === 12 || secondToken === 13)) {
918
+ replaceContent = newLinesAndIndent();
919
+ }
920
+ }
921
+ if (secondToken === 17) {
922
+ if (options.keepLines && numberLineBreaks > 0) {
923
+ replaceContent = newLinesAndIndent();
924
+ } else {
925
+ replaceContent = options.insertFinalNewline ? eol : "";
926
+ }
927
+ }
928
+ const secondTokenStart = scanner.getTokenOffset() + formatTextStart;
929
+ addEdit(replaceContent, firstTokenEnd, secondTokenStart);
930
+ firstToken = secondToken;
931
+ }
932
+ return editOperations;
933
+ }
934
+ function repeat(s, count) {
935
+ let result = "";
936
+ for (let i = 0; i < count; i++) {
937
+ result += s;
938
+ }
939
+ return result;
940
+ }
941
+ function computeIndentLevel(content2, options) {
942
+ let i = 0;
943
+ let nChars = 0;
944
+ const tabSize = options.tabSize || 4;
945
+ while (i < content2.length) {
946
+ let ch = content2.charAt(i);
947
+ if (ch === cachedSpaces[1]) {
948
+ nChars++;
949
+ } else if (ch === " ") {
950
+ nChars += tabSize;
951
+ } else {
952
+ break;
953
+ }
954
+ i++;
955
+ }
956
+ return Math.floor(nChars / tabSize);
957
+ }
958
+ function getEOL(options, text2) {
959
+ for (let i = 0; i < text2.length; i++) {
960
+ const ch = text2.charAt(i);
961
+ if (ch === "\r") {
962
+ if (i + 1 < text2.length && text2.charAt(i + 1) === "\n") {
963
+ return "\r\n";
964
+ }
965
+ return "\r";
966
+ } else if (ch === "\n") {
967
+ return "\n";
968
+ }
969
+ }
970
+ return options && options.eol || "\n";
971
+ }
972
+ function isEOL(text2, offset) {
973
+ return "\r\n".indexOf(text2.charAt(offset)) !== -1;
974
+ }
975
+
976
+ // ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/parser.js
977
+ var ParseOptions;
978
+ (function(ParseOptions2) {
979
+ ParseOptions2.DEFAULT = {
980
+ allowTrailingComma: false
981
+ };
982
+ })(ParseOptions || (ParseOptions = {}));
983
+ function parse(text2, errors = [], options = ParseOptions.DEFAULT) {
984
+ let currentProperty = null;
985
+ let currentParent = [];
986
+ const previousParents = [];
987
+ function onValue(value) {
988
+ if (Array.isArray(currentParent)) {
989
+ currentParent.push(value);
990
+ } else if (currentProperty !== null) {
991
+ currentParent[currentProperty] = value;
992
+ }
993
+ }
994
+ const visitor = {
995
+ onObjectBegin: () => {
996
+ const object2 = {};
997
+ onValue(object2);
998
+ previousParents.push(currentParent);
999
+ currentParent = object2;
1000
+ currentProperty = null;
1001
+ },
1002
+ onObjectProperty: (name) => {
1003
+ currentProperty = name;
1004
+ },
1005
+ onObjectEnd: () => {
1006
+ currentParent = previousParents.pop();
1007
+ },
1008
+ onArrayBegin: () => {
1009
+ const array = [];
1010
+ onValue(array);
1011
+ previousParents.push(currentParent);
1012
+ currentParent = array;
1013
+ currentProperty = null;
1014
+ },
1015
+ onArrayEnd: () => {
1016
+ currentParent = previousParents.pop();
1017
+ },
1018
+ onLiteralValue: onValue,
1019
+ onError: (error, offset, length) => {
1020
+ errors.push({ error, offset, length });
1021
+ }
1022
+ };
1023
+ visit(text2, visitor, options);
1024
+ return currentParent[0];
1025
+ }
1026
+ function parseTree(text2, errors = [], options = ParseOptions.DEFAULT) {
1027
+ let currentParent = { type: "array", offset: -1, length: -1, children: [], parent: void 0 };
1028
+ function ensurePropertyComplete(endOffset) {
1029
+ if (currentParent.type === "property") {
1030
+ currentParent.length = endOffset - currentParent.offset;
1031
+ currentParent = currentParent.parent;
1032
+ }
1033
+ }
1034
+ function onValue(valueNode) {
1035
+ currentParent.children.push(valueNode);
1036
+ return valueNode;
1037
+ }
1038
+ const visitor = {
1039
+ onObjectBegin: (offset) => {
1040
+ currentParent = onValue({ type: "object", offset, length: -1, parent: currentParent, children: [] });
1041
+ },
1042
+ onObjectProperty: (name, offset, length) => {
1043
+ currentParent = onValue({ type: "property", offset, length: -1, parent: currentParent, children: [] });
1044
+ currentParent.children.push({ type: "string", value: name, offset, length, parent: currentParent });
1045
+ },
1046
+ onObjectEnd: (offset, length) => {
1047
+ ensurePropertyComplete(offset + length);
1048
+ currentParent.length = offset + length - currentParent.offset;
1049
+ currentParent = currentParent.parent;
1050
+ ensurePropertyComplete(offset + length);
1051
+ },
1052
+ onArrayBegin: (offset, length) => {
1053
+ currentParent = onValue({ type: "array", offset, length: -1, parent: currentParent, children: [] });
1054
+ },
1055
+ onArrayEnd: (offset, length) => {
1056
+ currentParent.length = offset + length - currentParent.offset;
1057
+ currentParent = currentParent.parent;
1058
+ ensurePropertyComplete(offset + length);
1059
+ },
1060
+ onLiteralValue: (value, offset, length) => {
1061
+ onValue({ type: getNodeType(value), offset, length, parent: currentParent, value });
1062
+ ensurePropertyComplete(offset + length);
1063
+ },
1064
+ onSeparator: (sep, offset, length) => {
1065
+ if (currentParent.type === "property") {
1066
+ if (sep === ":") {
1067
+ currentParent.colonOffset = offset;
1068
+ } else if (sep === ",") {
1069
+ ensurePropertyComplete(offset);
1070
+ }
1071
+ }
1072
+ },
1073
+ onError: (error, offset, length) => {
1074
+ errors.push({ error, offset, length });
1075
+ }
1076
+ };
1077
+ visit(text2, visitor, options);
1078
+ const result = currentParent.children[0];
1079
+ if (result) {
1080
+ delete result.parent;
1081
+ }
1082
+ return result;
1083
+ }
1084
+ function findNodeAtLocation(root, path) {
1085
+ if (!root) {
1086
+ return void 0;
1087
+ }
1088
+ let node = root;
1089
+ for (let segment of path) {
1090
+ if (typeof segment === "string") {
1091
+ if (node.type !== "object" || !Array.isArray(node.children)) {
1092
+ return void 0;
1093
+ }
1094
+ let found = false;
1095
+ for (const propertyNode of node.children) {
1096
+ if (Array.isArray(propertyNode.children) && propertyNode.children[0].value === segment && propertyNode.children.length === 2) {
1097
+ node = propertyNode.children[1];
1098
+ found = true;
1099
+ break;
1100
+ }
1101
+ }
1102
+ if (!found) {
1103
+ return void 0;
1104
+ }
1105
+ } else {
1106
+ const index = segment;
1107
+ if (node.type !== "array" || index < 0 || !Array.isArray(node.children) || index >= node.children.length) {
1108
+ return void 0;
1109
+ }
1110
+ node = node.children[index];
1111
+ }
1112
+ }
1113
+ return node;
1114
+ }
1115
+ function visit(text2, visitor, options = ParseOptions.DEFAULT) {
1116
+ const _scanner = createScanner(text2, false);
1117
+ const _jsonPath = [];
1118
+ let suppressedCallbacks = 0;
1119
+ function toNoArgVisit(visitFunction) {
1120
+ return visitFunction ? () => suppressedCallbacks === 0 && visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
1121
+ }
1122
+ function toOneArgVisit(visitFunction) {
1123
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter()) : () => true;
1124
+ }
1125
+ function toOneArgVisitWithPath(visitFunction) {
1126
+ return visitFunction ? (arg) => suppressedCallbacks === 0 && visitFunction(arg, _scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice()) : () => true;
1127
+ }
1128
+ function toBeginVisit(visitFunction) {
1129
+ return visitFunction ? () => {
1130
+ if (suppressedCallbacks > 0) {
1131
+ suppressedCallbacks++;
1132
+ } else {
1133
+ let cbReturn = visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter(), () => _jsonPath.slice());
1134
+ if (cbReturn === false) {
1135
+ suppressedCallbacks = 1;
1136
+ }
1137
+ }
1138
+ } : () => true;
1139
+ }
1140
+ function toEndVisit(visitFunction) {
1141
+ return visitFunction ? () => {
1142
+ if (suppressedCallbacks > 0) {
1143
+ suppressedCallbacks--;
1144
+ }
1145
+ if (suppressedCallbacks === 0) {
1146
+ visitFunction(_scanner.getTokenOffset(), _scanner.getTokenLength(), _scanner.getTokenStartLine(), _scanner.getTokenStartCharacter());
1147
+ }
1148
+ } : () => true;
1149
+ }
1150
+ const onObjectBegin = toBeginVisit(visitor.onObjectBegin), onObjectProperty = toOneArgVisitWithPath(visitor.onObjectProperty), onObjectEnd = toEndVisit(visitor.onObjectEnd), onArrayBegin = toBeginVisit(visitor.onArrayBegin), onArrayEnd = toEndVisit(visitor.onArrayEnd), onLiteralValue = toOneArgVisitWithPath(visitor.onLiteralValue), onSeparator = toOneArgVisit(visitor.onSeparator), onComment = toNoArgVisit(visitor.onComment), onError = toOneArgVisit(visitor.onError);
1151
+ const disallowComments = options && options.disallowComments;
1152
+ const allowTrailingComma = options && options.allowTrailingComma;
1153
+ function scanNext() {
1154
+ while (true) {
1155
+ const token = _scanner.scan();
1156
+ switch (_scanner.getTokenError()) {
1157
+ case 4:
1158
+ handleError(
1159
+ 14
1160
+ /* ParseErrorCode.InvalidUnicode */
1161
+ );
1162
+ break;
1163
+ case 5:
1164
+ handleError(
1165
+ 15
1166
+ /* ParseErrorCode.InvalidEscapeCharacter */
1167
+ );
1168
+ break;
1169
+ case 3:
1170
+ handleError(
1171
+ 13
1172
+ /* ParseErrorCode.UnexpectedEndOfNumber */
1173
+ );
1174
+ break;
1175
+ case 1:
1176
+ if (!disallowComments) {
1177
+ handleError(
1178
+ 11
1179
+ /* ParseErrorCode.UnexpectedEndOfComment */
1180
+ );
1181
+ }
1182
+ break;
1183
+ case 2:
1184
+ handleError(
1185
+ 12
1186
+ /* ParseErrorCode.UnexpectedEndOfString */
1187
+ );
1188
+ break;
1189
+ case 6:
1190
+ handleError(
1191
+ 16
1192
+ /* ParseErrorCode.InvalidCharacter */
1193
+ );
1194
+ break;
1195
+ }
1196
+ switch (token) {
1197
+ case 12:
1198
+ case 13:
1199
+ if (disallowComments) {
1200
+ handleError(
1201
+ 10
1202
+ /* ParseErrorCode.InvalidCommentToken */
1203
+ );
1204
+ } else {
1205
+ onComment();
1206
+ }
1207
+ break;
1208
+ case 16:
1209
+ handleError(
1210
+ 1
1211
+ /* ParseErrorCode.InvalidSymbol */
1212
+ );
1213
+ break;
1214
+ case 15:
1215
+ case 14:
1216
+ break;
1217
+ default:
1218
+ return token;
1219
+ }
1220
+ }
1221
+ }
1222
+ function handleError(error, skipUntilAfter = [], skipUntil = []) {
1223
+ onError(error);
1224
+ if (skipUntilAfter.length + skipUntil.length > 0) {
1225
+ let token = _scanner.getToken();
1226
+ while (token !== 17) {
1227
+ if (skipUntilAfter.indexOf(token) !== -1) {
1228
+ scanNext();
1229
+ break;
1230
+ } else if (skipUntil.indexOf(token) !== -1) {
1231
+ break;
1232
+ }
1233
+ token = scanNext();
1234
+ }
1235
+ }
1236
+ }
1237
+ function parseString(isValue) {
1238
+ const value = _scanner.getTokenValue();
1239
+ if (isValue) {
1240
+ onLiteralValue(value);
1241
+ } else {
1242
+ onObjectProperty(value);
1243
+ _jsonPath.push(value);
1244
+ }
1245
+ scanNext();
1246
+ return true;
1247
+ }
1248
+ function parseLiteral() {
1249
+ switch (_scanner.getToken()) {
1250
+ case 11:
1251
+ const tokenValue = _scanner.getTokenValue();
1252
+ let value = Number(tokenValue);
1253
+ if (isNaN(value)) {
1254
+ handleError(
1255
+ 2
1256
+ /* ParseErrorCode.InvalidNumberFormat */
1257
+ );
1258
+ value = 0;
1259
+ }
1260
+ onLiteralValue(value);
1261
+ break;
1262
+ case 7:
1263
+ onLiteralValue(null);
1264
+ break;
1265
+ case 8:
1266
+ onLiteralValue(true);
1267
+ break;
1268
+ case 9:
1269
+ onLiteralValue(false);
1270
+ break;
1271
+ default:
1272
+ return false;
1273
+ }
1274
+ scanNext();
1275
+ return true;
1276
+ }
1277
+ function parseProperty() {
1278
+ if (_scanner.getToken() !== 10) {
1279
+ handleError(3, [], [
1280
+ 2,
1281
+ 5
1282
+ /* SyntaxKind.CommaToken */
1283
+ ]);
1284
+ return false;
1285
+ }
1286
+ parseString(false);
1287
+ if (_scanner.getToken() === 6) {
1288
+ onSeparator(":");
1289
+ scanNext();
1290
+ if (!parseValue()) {
1291
+ handleError(4, [], [
1292
+ 2,
1293
+ 5
1294
+ /* SyntaxKind.CommaToken */
1295
+ ]);
1296
+ }
1297
+ } else {
1298
+ handleError(5, [], [
1299
+ 2,
1300
+ 5
1301
+ /* SyntaxKind.CommaToken */
1302
+ ]);
1303
+ }
1304
+ _jsonPath.pop();
1305
+ return true;
1306
+ }
1307
+ function parseObject() {
1308
+ onObjectBegin();
1309
+ scanNext();
1310
+ let needsComma = false;
1311
+ while (_scanner.getToken() !== 2 && _scanner.getToken() !== 17) {
1312
+ if (_scanner.getToken() === 5) {
1313
+ if (!needsComma) {
1314
+ handleError(4, [], []);
1315
+ }
1316
+ onSeparator(",");
1317
+ scanNext();
1318
+ if (_scanner.getToken() === 2 && allowTrailingComma) {
1319
+ break;
1320
+ }
1321
+ } else if (needsComma) {
1322
+ handleError(6, [], []);
1323
+ }
1324
+ if (!parseProperty()) {
1325
+ handleError(4, [], [
1326
+ 2,
1327
+ 5
1328
+ /* SyntaxKind.CommaToken */
1329
+ ]);
1330
+ }
1331
+ needsComma = true;
1332
+ }
1333
+ onObjectEnd();
1334
+ if (_scanner.getToken() !== 2) {
1335
+ handleError(7, [
1336
+ 2
1337
+ /* SyntaxKind.CloseBraceToken */
1338
+ ], []);
1339
+ } else {
1340
+ scanNext();
1341
+ }
1342
+ return true;
1343
+ }
1344
+ function parseArray() {
1345
+ onArrayBegin();
1346
+ scanNext();
1347
+ let isFirstElement = true;
1348
+ let needsComma = false;
1349
+ while (_scanner.getToken() !== 4 && _scanner.getToken() !== 17) {
1350
+ if (_scanner.getToken() === 5) {
1351
+ if (!needsComma) {
1352
+ handleError(4, [], []);
1353
+ }
1354
+ onSeparator(",");
1355
+ scanNext();
1356
+ if (_scanner.getToken() === 4 && allowTrailingComma) {
1357
+ break;
1358
+ }
1359
+ } else if (needsComma) {
1360
+ handleError(6, [], []);
1361
+ }
1362
+ if (isFirstElement) {
1363
+ _jsonPath.push(0);
1364
+ isFirstElement = false;
1365
+ } else {
1366
+ _jsonPath[_jsonPath.length - 1]++;
1367
+ }
1368
+ if (!parseValue()) {
1369
+ handleError(4, [], [
1370
+ 4,
1371
+ 5
1372
+ /* SyntaxKind.CommaToken */
1373
+ ]);
1374
+ }
1375
+ needsComma = true;
1376
+ }
1377
+ onArrayEnd();
1378
+ if (!isFirstElement) {
1379
+ _jsonPath.pop();
1380
+ }
1381
+ if (_scanner.getToken() !== 4) {
1382
+ handleError(8, [
1383
+ 4
1384
+ /* SyntaxKind.CloseBracketToken */
1385
+ ], []);
1386
+ } else {
1387
+ scanNext();
1388
+ }
1389
+ return true;
1390
+ }
1391
+ function parseValue() {
1392
+ switch (_scanner.getToken()) {
1393
+ case 3:
1394
+ return parseArray();
1395
+ case 1:
1396
+ return parseObject();
1397
+ case 10:
1398
+ return parseString(true);
1399
+ default:
1400
+ return parseLiteral();
1401
+ }
1402
+ }
1403
+ scanNext();
1404
+ if (_scanner.getToken() === 17) {
1405
+ if (options.allowEmptyContent) {
1406
+ return true;
1407
+ }
1408
+ handleError(4, [], []);
1409
+ return false;
1410
+ }
1411
+ if (!parseValue()) {
1412
+ handleError(4, [], []);
1413
+ return false;
1414
+ }
1415
+ if (_scanner.getToken() !== 17) {
1416
+ handleError(9, [], []);
1417
+ }
1418
+ return true;
1419
+ }
1420
+ function getNodeType(value) {
1421
+ switch (typeof value) {
1422
+ case "boolean":
1423
+ return "boolean";
1424
+ case "number":
1425
+ return "number";
1426
+ case "string":
1427
+ return "string";
1428
+ case "object": {
1429
+ if (!value) {
1430
+ return "null";
1431
+ } else if (Array.isArray(value)) {
1432
+ return "array";
1433
+ }
1434
+ return "object";
1435
+ }
1436
+ default:
1437
+ return "null";
1438
+ }
1439
+ }
1440
+
1441
+ // ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/impl/edit.js
1442
+ function setProperty(text2, originalPath, value, options) {
1443
+ const path = originalPath.slice();
1444
+ const errors = [];
1445
+ const root = parseTree(text2, errors);
1446
+ let parent = void 0;
1447
+ let lastSegment = void 0;
1448
+ while (path.length > 0) {
1449
+ lastSegment = path.pop();
1450
+ parent = findNodeAtLocation(root, path);
1451
+ if (parent === void 0 && value !== void 0) {
1452
+ if (typeof lastSegment === "string") {
1453
+ value = { [lastSegment]: value };
1454
+ } else {
1455
+ value = [value];
1456
+ }
1457
+ } else {
1458
+ break;
1459
+ }
1460
+ }
1461
+ if (!parent) {
1462
+ if (value === void 0) {
1463
+ throw new Error("Can not delete in empty document");
1464
+ }
1465
+ return withFormatting(text2, { offset: root ? root.offset : 0, length: root ? root.length : 0, content: JSON.stringify(value) }, options);
1466
+ } else if (parent.type === "object" && typeof lastSegment === "string" && Array.isArray(parent.children)) {
1467
+ const existing = findNodeAtLocation(parent, [lastSegment]);
1468
+ if (existing !== void 0) {
1469
+ if (value === void 0) {
1470
+ if (!existing.parent) {
1471
+ throw new Error("Malformed AST");
1472
+ }
1473
+ const propertyIndex = parent.children.indexOf(existing.parent);
1474
+ let removeBegin;
1475
+ let removeEnd = existing.parent.offset + existing.parent.length;
1476
+ if (propertyIndex > 0) {
1477
+ let previous = parent.children[propertyIndex - 1];
1478
+ removeBegin = previous.offset + previous.length;
1479
+ } else {
1480
+ removeBegin = parent.offset + 1;
1481
+ if (parent.children.length > 1) {
1482
+ let next = parent.children[1];
1483
+ removeEnd = next.offset;
1484
+ }
1485
+ }
1486
+ return withFormatting(text2, { offset: removeBegin, length: removeEnd - removeBegin, content: "" }, options);
1487
+ } else {
1488
+ return withFormatting(text2, { offset: existing.offset, length: existing.length, content: JSON.stringify(value) }, options);
1489
+ }
1490
+ } else {
1491
+ if (value === void 0) {
1492
+ return [];
1493
+ }
1494
+ const newProperty = `${JSON.stringify(lastSegment)}: ${JSON.stringify(value)}`;
1495
+ const index = options.getInsertionIndex ? options.getInsertionIndex(parent.children.map((p) => p.children[0].value)) : parent.children.length;
1496
+ let edit;
1497
+ if (index > 0) {
1498
+ let previous = parent.children[index - 1];
1499
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1500
+ } else if (parent.children.length === 0) {
1501
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1502
+ } else {
1503
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty + "," };
1504
+ }
1505
+ return withFormatting(text2, edit, options);
1506
+ }
1507
+ } else if (parent.type === "array" && typeof lastSegment === "number" && Array.isArray(parent.children)) {
1508
+ const insertIndex = lastSegment;
1509
+ if (insertIndex === -1) {
1510
+ const newProperty = `${JSON.stringify(value)}`;
1511
+ let edit;
1512
+ if (parent.children.length === 0) {
1513
+ edit = { offset: parent.offset + 1, length: 0, content: newProperty };
1514
+ } else {
1515
+ const previous = parent.children[parent.children.length - 1];
1516
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1517
+ }
1518
+ return withFormatting(text2, edit, options);
1519
+ } else if (value === void 0 && parent.children.length >= 0) {
1520
+ const removalIndex = lastSegment;
1521
+ const toRemove = parent.children[removalIndex];
1522
+ let edit;
1523
+ if (parent.children.length === 1) {
1524
+ edit = { offset: parent.offset + 1, length: parent.length - 2, content: "" };
1525
+ } else if (parent.children.length - 1 === removalIndex) {
1526
+ let previous = parent.children[removalIndex - 1];
1527
+ let offset = previous.offset + previous.length;
1528
+ let parentEndOffset = parent.offset + parent.length;
1529
+ edit = { offset, length: parentEndOffset - 2 - offset, content: "" };
1530
+ } else {
1531
+ edit = { offset: toRemove.offset, length: parent.children[removalIndex + 1].offset - toRemove.offset, content: "" };
1532
+ }
1533
+ return withFormatting(text2, edit, options);
1534
+ } else if (value !== void 0) {
1535
+ let edit;
1536
+ const newProperty = `${JSON.stringify(value)}`;
1537
+ if (!options.isArrayInsertion && parent.children.length > lastSegment) {
1538
+ const toModify = parent.children[lastSegment];
1539
+ edit = { offset: toModify.offset, length: toModify.length, content: newProperty };
1540
+ } else if (parent.children.length === 0 || lastSegment === 0) {
1541
+ edit = { offset: parent.offset + 1, length: 0, content: parent.children.length === 0 ? newProperty : newProperty + "," };
1542
+ } else {
1543
+ const index = lastSegment > parent.children.length ? parent.children.length : lastSegment;
1544
+ const previous = parent.children[index - 1];
1545
+ edit = { offset: previous.offset + previous.length, length: 0, content: "," + newProperty };
1546
+ }
1547
+ return withFormatting(text2, edit, options);
1548
+ } else {
1549
+ throw new Error(`Can not ${value === void 0 ? "remove" : options.isArrayInsertion ? "insert" : "modify"} Array index ${insertIndex} as length is not sufficient`);
1550
+ }
1551
+ } else {
1552
+ throw new Error(`Can not add ${typeof lastSegment !== "number" ? "index" : "property"} to parent of type ${parent.type}`);
1553
+ }
1554
+ }
1555
+ function withFormatting(text2, edit, options) {
1556
+ if (!options.formattingOptions) {
1557
+ return [edit];
1558
+ }
1559
+ let newText = applyEdit(text2, edit);
1560
+ let begin = edit.offset;
1561
+ let end = edit.offset + edit.content.length;
1562
+ if (edit.length === 0 || edit.content.length === 0) {
1563
+ while (begin > 0 && !isEOL(newText, begin - 1)) {
1564
+ begin--;
1565
+ }
1566
+ while (end < newText.length && !isEOL(newText, end)) {
1567
+ end++;
1568
+ }
1569
+ }
1570
+ const edits = format(newText, { offset: begin, length: end - begin }, { ...options.formattingOptions, keepLines: false });
1571
+ for (let i = edits.length - 1; i >= 0; i--) {
1572
+ const edit2 = edits[i];
1573
+ newText = applyEdit(newText, edit2);
1574
+ begin = Math.min(begin, edit2.offset);
1575
+ end = Math.max(end, edit2.offset + edit2.length);
1576
+ end += edit2.content.length - edit2.length;
1577
+ }
1578
+ const editLength = text2.length - (newText.length - end) - begin;
1579
+ return [{ offset: begin, length: editLength, content: newText.substring(begin, end) }];
1580
+ }
1581
+ function applyEdit(text2, edit) {
1582
+ return text2.substring(0, edit.offset) + edit.content + text2.substring(edit.offset + edit.length);
1583
+ }
1584
+
1585
+ // ../node_modules/.pnpm/jsonc-parser@3.3.1/node_modules/jsonc-parser/lib/esm/main.js
1586
+ var ScanError;
1587
+ (function(ScanError2) {
1588
+ ScanError2[ScanError2["None"] = 0] = "None";
1589
+ ScanError2[ScanError2["UnexpectedEndOfComment"] = 1] = "UnexpectedEndOfComment";
1590
+ ScanError2[ScanError2["UnexpectedEndOfString"] = 2] = "UnexpectedEndOfString";
1591
+ ScanError2[ScanError2["UnexpectedEndOfNumber"] = 3] = "UnexpectedEndOfNumber";
1592
+ ScanError2[ScanError2["InvalidUnicode"] = 4] = "InvalidUnicode";
1593
+ ScanError2[ScanError2["InvalidEscapeCharacter"] = 5] = "InvalidEscapeCharacter";
1594
+ ScanError2[ScanError2["InvalidCharacter"] = 6] = "InvalidCharacter";
1595
+ })(ScanError || (ScanError = {}));
1596
+ var SyntaxKind;
1597
+ (function(SyntaxKind2) {
1598
+ SyntaxKind2[SyntaxKind2["OpenBraceToken"] = 1] = "OpenBraceToken";
1599
+ SyntaxKind2[SyntaxKind2["CloseBraceToken"] = 2] = "CloseBraceToken";
1600
+ SyntaxKind2[SyntaxKind2["OpenBracketToken"] = 3] = "OpenBracketToken";
1601
+ SyntaxKind2[SyntaxKind2["CloseBracketToken"] = 4] = "CloseBracketToken";
1602
+ SyntaxKind2[SyntaxKind2["CommaToken"] = 5] = "CommaToken";
1603
+ SyntaxKind2[SyntaxKind2["ColonToken"] = 6] = "ColonToken";
1604
+ SyntaxKind2[SyntaxKind2["NullKeyword"] = 7] = "NullKeyword";
1605
+ SyntaxKind2[SyntaxKind2["TrueKeyword"] = 8] = "TrueKeyword";
1606
+ SyntaxKind2[SyntaxKind2["FalseKeyword"] = 9] = "FalseKeyword";
1607
+ SyntaxKind2[SyntaxKind2["StringLiteral"] = 10] = "StringLiteral";
1608
+ SyntaxKind2[SyntaxKind2["NumericLiteral"] = 11] = "NumericLiteral";
1609
+ SyntaxKind2[SyntaxKind2["LineCommentTrivia"] = 12] = "LineCommentTrivia";
1610
+ SyntaxKind2[SyntaxKind2["BlockCommentTrivia"] = 13] = "BlockCommentTrivia";
1611
+ SyntaxKind2[SyntaxKind2["LineBreakTrivia"] = 14] = "LineBreakTrivia";
1612
+ SyntaxKind2[SyntaxKind2["Trivia"] = 15] = "Trivia";
1613
+ SyntaxKind2[SyntaxKind2["Unknown"] = 16] = "Unknown";
1614
+ SyntaxKind2[SyntaxKind2["EOF"] = 17] = "EOF";
1615
+ })(SyntaxKind || (SyntaxKind = {}));
1616
+ var parse2 = parse;
1617
+ var parseTree2 = parseTree;
1618
+ var findNodeAtLocation2 = findNodeAtLocation;
1619
+ var ParseErrorCode;
1620
+ (function(ParseErrorCode2) {
1621
+ ParseErrorCode2[ParseErrorCode2["InvalidSymbol"] = 1] = "InvalidSymbol";
1622
+ ParseErrorCode2[ParseErrorCode2["InvalidNumberFormat"] = 2] = "InvalidNumberFormat";
1623
+ ParseErrorCode2[ParseErrorCode2["PropertyNameExpected"] = 3] = "PropertyNameExpected";
1624
+ ParseErrorCode2[ParseErrorCode2["ValueExpected"] = 4] = "ValueExpected";
1625
+ ParseErrorCode2[ParseErrorCode2["ColonExpected"] = 5] = "ColonExpected";
1626
+ ParseErrorCode2[ParseErrorCode2["CommaExpected"] = 6] = "CommaExpected";
1627
+ ParseErrorCode2[ParseErrorCode2["CloseBraceExpected"] = 7] = "CloseBraceExpected";
1628
+ ParseErrorCode2[ParseErrorCode2["CloseBracketExpected"] = 8] = "CloseBracketExpected";
1629
+ ParseErrorCode2[ParseErrorCode2["EndOfFileExpected"] = 9] = "EndOfFileExpected";
1630
+ ParseErrorCode2[ParseErrorCode2["InvalidCommentToken"] = 10] = "InvalidCommentToken";
1631
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfComment"] = 11] = "UnexpectedEndOfComment";
1632
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfString"] = 12] = "UnexpectedEndOfString";
1633
+ ParseErrorCode2[ParseErrorCode2["UnexpectedEndOfNumber"] = 13] = "UnexpectedEndOfNumber";
1634
+ ParseErrorCode2[ParseErrorCode2["InvalidUnicode"] = 14] = "InvalidUnicode";
1635
+ ParseErrorCode2[ParseErrorCode2["InvalidEscapeCharacter"] = 15] = "InvalidEscapeCharacter";
1636
+ ParseErrorCode2[ParseErrorCode2["InvalidCharacter"] = 16] = "InvalidCharacter";
1637
+ })(ParseErrorCode || (ParseErrorCode = {}));
1638
+ function modify(text2, path, value, options) {
1639
+ return setProperty(text2, path, value, options);
1640
+ }
1641
+ function applyEdits(text2, edits) {
1642
+ let sortedEdits = edits.slice(0).sort((a, b) => {
1643
+ const diff = a.offset - b.offset;
1644
+ if (diff === 0) {
1645
+ return a.length - b.length;
1646
+ }
1647
+ return diff;
1648
+ });
1649
+ let lastModifiedOffset = text2.length;
1650
+ for (let i = sortedEdits.length - 1; i >= 0; i--) {
1651
+ let e = sortedEdits[i];
1652
+ if (e.offset + e.length <= lastModifiedOffset) {
1653
+ text2 = applyEdit(text2, e);
1654
+ } else {
1655
+ throw new Error("Overlapping edit");
1656
+ }
1657
+ lastModifiedOffset = e.offset;
1658
+ }
1659
+ return text2;
1660
+ }
1661
+
1662
+ // src/client/structured.ts
1663
+ function record(value) {
1664
+ return value !== null && typeof value === "object" && !Array.isArray(value);
1665
+ }
1666
+ function route(value) {
1667
+ 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));
1668
+ }
1669
+ function validTree(node, depth = 0) {
1670
+ if (depth > 32) return false;
1671
+ if (node.type === "object") {
1672
+ const seen = /* @__PURE__ */ new Set();
1673
+ for (const property of node.children ?? []) {
1674
+ const key = property.children?.[0]?.value;
1675
+ if (typeof key !== "string" || seen.has(key) || ["__proto__", "prototype", "constructor"].includes(key)) return false;
1676
+ seen.add(key);
1677
+ }
1678
+ }
1679
+ return (node.children ?? []).every((child) => validTree(child, depth + 1));
1680
+ }
1681
+ function structuredDocument(content2) {
1682
+ const errors = [];
1683
+ const tree = parseTree2(content2, errors, { allowTrailingComma: true });
1684
+ if (errors.length !== 0 || tree === void 0 || !validTree(tree)) return null;
1685
+ const document2 = parse2(content2, errors, { allowTrailingComma: true });
1686
+ 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;
1687
+ const settings = document2.settings;
1688
+ if (settings.defaultActive !== void 0 && typeof settings.defaultActive !== "boolean") return null;
1689
+ if (settings.roleRouting !== void 0 && !record(settings.roleRouting)) return null;
1690
+ if (settings.runtimePolicy !== void 0 && !record(settings.runtimePolicy)) return null;
1691
+ const runtimePolicy2 = settings.runtimePolicy ?? {};
1692
+ const policies = settings.roleRouting ?? {};
1693
+ try {
1694
+ if (Object.keys(runtimePolicy2).some((key) => key !== "strategy" && key !== "rateLimit")) return null;
1695
+ if (runtimePolicy2.strategy !== void 0) normalizeRoutingStrategy(runtimePolicy2.strategy);
1696
+ if (runtimePolicy2.rateLimit !== void 0) normalizeRateLimitOverrides(runtimePolicy2.rateLimit);
1697
+ for (const raw of Object.values(policies)) {
1698
+ if (!record(raw) || Object.keys(raw).some((key) => !["primary", "fallbackRoutes", "strategy", "rateLimit"].includes(key))) return null;
1699
+ if (raw.primary !== void 0 && !route(raw.primary)) return null;
1700
+ if (raw.fallbackRoutes !== void 0 && (!Array.isArray(raw.fallbackRoutes) || raw.fallbackRoutes.length > 32 || !raw.fallbackRoutes.every(route))) return null;
1701
+ if (raw.strategy !== void 0) normalizeRoutingStrategy(raw.strategy);
1702
+ if (raw.rateLimit !== void 0) normalizeRateLimitOverrides(raw.rateLimit);
1703
+ }
1704
+ } catch {
1705
+ return null;
1706
+ }
1707
+ return { label: document2.label, settings, roleRouting: policies, runtimePolicy: runtimePolicy2 };
1708
+ }
1709
+ function editStructuredPath(content2, path, value) {
1710
+ if (structuredDocument(content2) === null) return null;
1711
+ try {
1712
+ return applyEdits(content2, modify(content2, path, value, { formattingOptions: { insertSpaces: true, tabSize: 2 } }));
1713
+ } catch {
1714
+ return null;
1715
+ }
1716
+ }
1717
+ function moveFallback(content2, role2, from, to) {
1718
+ const document2 = structuredDocument(content2);
1719
+ const chain = document2?.roleRouting[role2]?.fallbackRoutes;
1720
+ if (chain === void 0 || from < 0 || from >= chain.length || to < 0 || to >= chain.length) return null;
1721
+ const low = Math.min(from, to), high = Math.max(from, to);
1722
+ const tree = parseTree2(content2);
1723
+ if (tree === void 0) return null;
1724
+ const nodes = chain.map((_, index) => findNodeAtLocation2(tree, ["settings", "roleRouting", role2, "fallbackRoutes", index]));
1725
+ if (nodes.some((node) => node === void 0)) return null;
1726
+ const order = nodes.map((node) => content2.slice(node.offset, node.offset + node.length));
1727
+ order.splice(to, 0, order.splice(from, 1)[0]);
1728
+ return applyEdits(content2, nodes.slice(low, high + 1).map((node, offset) => ({ offset: node.offset, length: node.length, content: order[low + offset] })));
1729
+ }
1730
+
1731
+ // src/client/controller.ts
1732
+ var NEW_EDITOR = "";
1733
+ 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';
1734
+ function canReconcileSelection(snapshot2) {
1735
+ return snapshot2 !== null && (snapshot2.selectionRevision === "absent" || /^[a-f0-9]{64}$/u.test(snapshot2.selectionRevision)) && (snapshot2.selectionError === void 0 || snapshot2.selectionError.code === "conflict");
1736
+ }
1737
+ var ProfilesController = class {
1738
+ constructor(remote) {
1739
+ this.remote = remote;
1740
+ }
1741
+ current = {
1742
+ snapshot: null,
1743
+ editor: null,
1744
+ dirty: false,
1745
+ busy: null,
1746
+ issue: null,
1747
+ notice: null,
1748
+ pendingEditor: null,
1749
+ catalog: null,
1750
+ catalogBusy: false,
1751
+ catalogUnavailable: true,
1752
+ currentSessionId: null,
1753
+ session: null,
1754
+ sessionChoice: null,
1755
+ sessionBusy: null,
1756
+ sessionIssue: null,
1757
+ sessionNotice: null,
1758
+ invalidFields: [],
1759
+ editorEpoch: 0
1760
+ };
1761
+ accepted = null;
1762
+ listeners = /* @__PURE__ */ new Set();
1763
+ generation = 0;
1764
+ disposed = false;
1765
+ sessionGeneration = 0;
1766
+ catalogGeneration = 0;
1767
+ catalogRemote = null;
1768
+ store = {
1769
+ getSnapshot: () => this.current,
1770
+ subscribe: (listener) => {
1771
+ this.listeners.add(listener);
1772
+ return () => {
1773
+ this.listeners.delete(listener);
1774
+ };
1775
+ }
1776
+ };
1777
+ actions = {
1778
+ refresh: () => this.refresh(),
1779
+ open: (id2) => this.open(id2),
1780
+ create: () => this.open(NEW_EDITOR),
1781
+ reload: () => this.reload(),
1782
+ editId: (id2) => this.editId(id2),
1783
+ editContent: (content2) => this.editContent(content2),
1784
+ save: () => this.save(),
1785
+ apply: () => this.apply(),
1786
+ reset: () => this.reset(),
1787
+ discardAndOpen: () => this.discardAndOpen(),
1788
+ cancelDiscard: () => this.publish({ pendingEditor: null }),
1789
+ editPath: (path, value) => this.editPath(path, value),
1790
+ moveFallback: (role2, from, to) => this.editFallbackOrder(role2, from, to),
1791
+ editRoute: (path, provider, model) => this.editRoute(path, provider, model),
1792
+ refreshCatalog: () => this.refreshCatalog(),
1793
+ refreshSession: () => this.refreshSession(),
1794
+ chooseSessionProfile: (id2) => {
1795
+ if (!this.disposed && this.current.sessionBusy === null && this.current.busy === null && !this.current.dirty) this.publish({ sessionChoice: id2, sessionNotice: null });
1796
+ },
1797
+ applySession: () => this.selectSession(false),
1798
+ resetSession: () => this.selectSession(true),
1799
+ setFieldInvalid: (field, invalid) => {
1800
+ if (this.disposed) return;
1801
+ const invalidFields = this.current.invalidFields.filter((candidate) => candidate !== field);
1802
+ if (invalid) invalidFields.push(field);
1803
+ if (invalidFields.join("\n") !== this.current.invalidFields.join("\n")) this.publish({ invalidFields, ...invalid ? { dirty: true } : {} });
1804
+ }
1805
+ };
1806
+ dispose() {
1807
+ this.disposed = true;
1808
+ this.generation += 1;
1809
+ this.sessionGeneration += 1;
1810
+ this.catalogGeneration += 1;
1811
+ this.catalogRemote = null;
1812
+ this.listeners.clear();
1813
+ }
1814
+ attachCatalog(remote) {
1815
+ if (this.disposed) return;
1816
+ this.catalogGeneration += 1;
1817
+ this.catalogRemote = remote;
1818
+ this.publish({ catalogBusy: false, catalogUnavailable: remote === null });
1819
+ if (remote !== null) void this.refreshCatalog();
1820
+ }
1821
+ setSession(id2) {
1822
+ if (this.disposed || id2 === this.current.currentSessionId) return;
1823
+ this.sessionGeneration += 1;
1824
+ this.publish({ currentSessionId: id2, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
1825
+ if (id2 !== null) void this.refreshSession();
1826
+ }
1827
+ async refreshCatalog() {
1828
+ if (this.disposed || this.current.catalogBusy || this.catalogRemote === null) return;
1829
+ const remote = this.catalogRemote, generation = ++this.catalogGeneration;
1830
+ this.publish({ catalogBusy: true });
1831
+ try {
1832
+ const catalog = await this.unwrap(remote.modelCatalog());
1833
+ if (!this.disposed && generation === this.catalogGeneration) this.publish({ catalog, catalogUnavailable: false });
1834
+ } catch {
1835
+ if (!this.disposed && generation === this.catalogGeneration) this.publish({ catalogUnavailable: true });
1836
+ } finally {
1837
+ if (!this.disposed && generation === this.catalogGeneration) this.publish({ catalogBusy: false });
1838
+ }
1839
+ }
1840
+ async refreshSession() {
1841
+ const id2 = this.current.currentSessionId;
1842
+ if (this.disposed || id2 === null || this.current.sessionBusy !== null) return;
1843
+ const generation = ++this.sessionGeneration;
1844
+ const live = () => !this.disposed && generation === this.sessionGeneration && id2 === this.current.currentSessionId;
1845
+ this.publish({ sessionBusy: "read", sessionIssue: null, sessionNotice: null });
1846
+ try {
1847
+ const session = await this.unwrap(this.remote.describeSession(id2));
1848
+ if (session.sessionId !== id2) throw { kind: "assembly", code: "unavailable" };
1849
+ if (live()) this.publish({ session, sessionChoice: session.selection.selectedId });
1850
+ } catch (error) {
1851
+ if (live()) this.publish({ sessionIssue: this.issue(error) });
1852
+ } finally {
1853
+ if (live()) this.publish({ sessionBusy: null });
1854
+ }
1855
+ }
1856
+ async selectSession(reset) {
1857
+ const { currentSessionId: id2, session, sessionChoice, snapshot: snapshot2 } = this.current;
1858
+ 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;
1859
+ const selectedId = reset ? null : sessionChoice;
1860
+ const revision2 = snapshot2?.profiles.find((profile) => profile.id === selectedId)?.revision;
1861
+ if (selectedId !== null && revision2 == null) return;
1862
+ const generation = ++this.sessionGeneration;
1863
+ const live = () => !this.disposed && generation === this.sessionGeneration && id2 === this.current.currentSessionId;
1864
+ this.publish({ sessionBusy: reset ? "reset" : "apply", sessionIssue: null, sessionNotice: null });
1865
+ try {
1866
+ const accepted = await this.unwrap(this.remote.selectSession(id2, {
1867
+ sessionId: id2,
1868
+ id: selectedId,
1869
+ ...selectedId === null ? {} : { expectedRevision: revision2 },
1870
+ expectedSelectionRevision: session.selection.selectionRevision,
1871
+ expectedAdmissionEpoch: session.admissionEpoch
1872
+ }));
1873
+ if (accepted.sessionId !== id2) throw { kind: "assembly", code: "unavailable" };
1874
+ if (live()) this.publish({ session: accepted, sessionChoice: accepted.selection.selectedId, sessionNotice: reset ? "reset" : "applied" });
1875
+ } catch (error) {
1876
+ if (live()) this.publish({ sessionIssue: this.issue(error) });
1877
+ } finally {
1878
+ if (live()) this.publish({ sessionBusy: null });
1879
+ }
1880
+ }
1881
+ publish(patch) {
1882
+ if (this.disposed) return;
1883
+ this.current = { ...this.current, ...patch };
1884
+ for (const listener of this.listeners) listener();
1885
+ }
1886
+ accept(document2) {
1887
+ this.accepted = { ...document2 };
1888
+ this.publish({ editor: { ...document2 }, dirty: false, pendingEditor: null, invalidFields: [], editorEpoch: this.current.editorEpoch + 1 });
1889
+ }
1890
+ async unwrap(request, field) {
1891
+ const result = await request;
1892
+ if (result.ok) return result.value;
1893
+ if (result.error.code === "dsmm-profiles/refused") {
1894
+ throw { kind: "domain", ...result.error.details };
1895
+ }
1896
+ if (["gateway/input-invalid", "gateway/arguments-invalid"].includes(String(result.error.code))) {
1897
+ throw { kind: "domain", code: "validation", field, message: "The native Host rejected a request field. Check the profile ID and document size before retrying." };
1898
+ }
1899
+ throw { kind: "transport", code: result.error.code };
1900
+ }
1901
+ issue(error) {
1902
+ if (typeof error === "object" && error !== null && "kind" in error && (error.kind === "domain" || error.kind === "transport")) return error;
1903
+ return { kind: "assembly", code: "unavailable" };
1904
+ }
1905
+ async perform(busy, operation) {
1906
+ if (this.disposed || this.current.busy !== null || this.current.sessionBusy === "apply" || this.current.sessionBusy === "reset" || this.current.pendingEditor !== null) return;
1907
+ const generation = ++this.generation;
1908
+ const live = () => !this.disposed && generation === this.generation;
1909
+ this.publish({ busy, issue: null, notice: null });
1910
+ try {
1911
+ await operation(live);
1912
+ } catch (error) {
1913
+ if (live()) this.publish({ issue: this.issue(error) });
1914
+ } finally {
1915
+ if (live()) this.publish({ busy: null });
1916
+ }
1917
+ }
1918
+ async refresh() {
1919
+ await this.perform("refresh", async (live) => {
1920
+ const snapshot2 = await this.unwrap(this.remote.describe());
1921
+ if (live()) this.publish({ snapshot: snapshot2 });
1922
+ });
1923
+ }
1924
+ async open(id2) {
1925
+ if (this.disposed || this.current.busy !== null || this.current.pendingEditor !== null) return;
1926
+ if (id2 !== NEW_EDITOR && this.current.editor?.id === id2) return;
1927
+ if (this.current.dirty) {
1928
+ this.publish({ pendingEditor: id2 });
1929
+ return;
1930
+ }
1931
+ await this.loadEditor(id2);
1932
+ }
1933
+ async reload() {
1934
+ const editor = this.current.editor;
1935
+ if (editor === null || editor.revision === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
1936
+ if (this.current.dirty) {
1937
+ this.publish({ pendingEditor: editor.id });
1938
+ return;
1939
+ }
1940
+ await this.loadEditor(editor.id);
1941
+ }
1942
+ async loadEditor(id2) {
1943
+ if (id2 === NEW_EDITOR) {
1944
+ this.accepted = null;
1945
+ 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 });
1946
+ return;
1947
+ }
1948
+ await this.perform("read", async (live) => {
1949
+ const document2 = await this.unwrap(this.remote.read(id2), "id");
1950
+ if (live()) this.accept(document2);
1951
+ });
1952
+ }
1953
+ async discardAndOpen() {
1954
+ const wanted = this.current.pendingEditor;
1955
+ if (wanted === null || this.current.busy !== null) return;
1956
+ this.publish({ pendingEditor: null });
1957
+ const previous = this.current.editor;
1958
+ const accepted = this.accepted;
1959
+ await this.loadEditor(wanted);
1960
+ if (this.current.issue !== null && previous !== null) {
1961
+ this.accepted = accepted;
1962
+ this.publish({ editor: previous, dirty: true });
1963
+ }
1964
+ }
1965
+ editId(id2) {
1966
+ const editor = this.current.editor;
1967
+ if (editor === null || editor.revision !== null || this.current.busy !== null || this.current.pendingEditor !== null) return;
1968
+ const content2 = editStructuredPath(editor.content, ["id"], id2);
1969
+ if (content2 === null) {
1970
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
1971
+ return;
1972
+ }
1973
+ this.publish({ editor: { ...editor, id: id2, content: content2 }, dirty: true, issue: null, notice: null });
1974
+ }
1975
+ editContent(content2) {
1976
+ const editor = this.current.editor;
1977
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
1978
+ this.publish({ editor: { ...editor, content: content2 }, dirty: this.accepted === null || this.accepted.content !== content2 || this.accepted.id !== editor.id, issue: null, notice: null });
1979
+ }
1980
+ editPath(path, value) {
1981
+ const editor = this.current.editor;
1982
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
1983
+ const content2 = editStructuredPath(editor.content, path, value);
1984
+ if (content2 === null) {
1985
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
1986
+ return;
1987
+ }
1988
+ this.editContent(content2);
1989
+ }
1990
+ editRoute(path, provider, model) {
1991
+ const editor = this.current.editor;
1992
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
1993
+ let content2 = editor.content;
1994
+ for (const [key, value] of [["provider", provider], ["model", model], ["reasoningEffort", void 0]]) {
1995
+ content2 = editStructuredPath(content2, [...path, key], value);
1996
+ if (content2 === null) {
1997
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
1998
+ return;
1999
+ }
2000
+ }
2001
+ this.editContent(content2);
2002
+ }
2003
+ editFallbackOrder(role2, from, to) {
2004
+ const editor = this.current.editor;
2005
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null) return;
2006
+ const content2 = moveFallback(editor.content, role2, from, to);
2007
+ if (content2 !== null) this.editContent(content2);
2008
+ }
2009
+ async save() {
2010
+ const editor = this.current.editor;
2011
+ if (editor === null || !this.current.dirty || this.current.snapshot === null || this.current.busy !== null || this.current.pendingEditor !== null || this.current.invalidFields.length > 0) return;
2012
+ if (!isProfileId(editor.id)) {
2013
+ this.publish({ issue: { kind: "domain", code: "validation", field: "id" }, notice: null });
2014
+ return;
2015
+ }
2016
+ await this.perform("save", async (live) => {
2017
+ const document2 = await this.unwrap(this.remote.save({ id: editor.id, content: editor.content, expectedRevision: editor.revision }), "content");
2018
+ if (!live()) return;
2019
+ this.accept(document2);
2020
+ const old = this.current.snapshot;
2021
+ const profiles = old.profiles.filter((item) => item.id !== document2.id);
2022
+ profiles.push({ id: document2.id, revision: document2.revision, ...document2.label === void 0 ? {} : { label: document2.label } });
2023
+ profiles.sort((a, b) => a.id.localeCompare(b.id));
2024
+ this.publish({ snapshot: { ...old, profiles }, notice: { key: "saved", id: document2.id } });
2025
+ });
2026
+ }
2027
+ async apply() {
2028
+ const { editor, snapshot: snapshot2, dirty } = this.current;
2029
+ if (editor?.revision == null || !canReconcileSelection(snapshot2) || dirty) return;
2030
+ await this.perform("apply", async (live) => {
2031
+ const accepted = await this.unwrap(this.remote.select({ id: editor.id, expectedRevision: editor.revision, expectedSelectionRevision: snapshot2.selectionRevision }));
2032
+ if (live()) this.acceptSelection(accepted, { key: "applied", id: accepted.selectedId ?? void 0 });
2033
+ });
2034
+ }
2035
+ async reset() {
2036
+ const snapshot2 = this.current.snapshot;
2037
+ if (!canReconcileSelection(snapshot2)) return;
2038
+ await this.perform("reset", async (live) => {
2039
+ const accepted = await this.unwrap(this.remote.select({ id: null, expectedSelectionRevision: snapshot2.selectionRevision }));
2040
+ if (live()) this.acceptSelection(accepted, { key: "reset" });
2041
+ });
2042
+ }
2043
+ acceptSelection(snapshot2, notice) {
2044
+ this.publish({
2045
+ snapshot: snapshot2,
2046
+ notice: snapshot2.selectionError === void 0 ? notice : null,
2047
+ issue: snapshot2.selectionError === void 0 ? null : { kind: "domain", ...snapshot2.selectionError, source: "selection" }
2048
+ });
2049
+ }
2050
+ };
2051
+
2052
+ // src/client/locales.ts
2053
+ var NS = "settings.dsmm-profiles";
2054
+ var en = {
2055
+ title: "Deepwork Profiles",
2056
+ description: "Save independent runtime configurations and choose which one new sessions use.",
2057
+ 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.",
2058
+ editorSelect: "Profile to edit",
2059
+ choose: "Choose a profile",
2060
+ newDraft: "New unsaved profile",
2061
+ new: "New profile",
2062
+ profileId: "Profile ID (name)",
2063
+ idHint: "Use 1–64 lowercase letters, digits, hyphens or underscores. The ID cannot be changed after saving. Add an optional display label in the JSONC document.",
2064
+ configuration: "Runtime configuration (JSONC)",
2065
+ configurationHint: "Document: version 1, matching id, optional label, and settings. Supported runtime settings: defaultActive, roleRouting, workflow, guards, runtimeRecovery, and both DeepSeek families’ calibration, default-effort and max-preset policies.",
2066
+ structuralHint: "Roles, skills, mode names, prompt order/content, preset installation, LSP, providers and accounts belong in native deployment configuration, not profiles. Routing may reference an existing provider; never paste credentials.",
2067
+ save: "Save profile",
2068
+ saving: "Saving profile…",
2069
+ apply: "Apply saved profile",
2070
+ applying: "Applying profile…",
2071
+ reset: "Reset to baseline",
2072
+ resetting: "Resetting to baseline…",
2073
+ refresh: "Refresh profiles",
2074
+ refreshing: "Refreshing profiles…",
2075
+ reload: "Reload saved profile",
2076
+ loading: "Loading profiles…",
2077
+ reading: "Reading profile…",
2078
+ empty: "No saved profiles yet. Create a profile to start; the deployment baseline remains applied.",
2079
+ baseline: "Applied to new sessions: deployment baseline.",
2080
+ appliedProfile: "Applied to new sessions: {id} (revision {revision}).",
2081
+ appliedInvalid: "The stored selection cannot be confirmed. Existing sessions remain unchanged. Resolve the Host diagnostic before applying or resetting a profile.",
2082
+ selectionConflict: "The stored selection changed outside this Host. This Host still uses the policy shown above for new sessions. Apply a saved profile or reset to baseline to reconcile it; restarting adopts the stored selection. Existing sessions stay unchanged.",
2083
+ dirty: "Unsaved changes. Save before applying; saving alone does not apply this profile.",
2084
+ savedNotApplied: "Saved profile; this revision is not applied to new sessions.",
2085
+ savedApplied: "This saved revision is applied to new sessions.",
2086
+ saved: "Saved {id}. The applied policy was not changed.",
2087
+ applied: "Applied {id} for new sessions. Existing sessions were not changed.",
2088
+ resetDone: "Reset to the deployment baseline for new sessions. Existing sessions were not changed.",
2089
+ discardPrompt: "Discard the unsaved draft before changing the editor?",
2090
+ discard: "Discard changes",
2091
+ cancel: "Cancel",
2092
+ conflict: "The saved file or selection changed elsewhere. Your draft and the prior selection were kept. Refresh profiles, then reload the saved profile or review your draft before retrying.",
2093
+ validation: "This profile is not valid. Correct the field below; your draft is unchanged.",
2094
+ io: "The Host could not commit this operation. Your draft and the prior selection were kept. Check profile storage access, refresh, then retry.",
2095
+ unavailable: "The native profile service is unavailable. Your draft is kept. Refresh after the Host reconnects or Deepwork is enabled.",
2096
+ 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.",
2097
+ invalidProfile: "Unavailable profile: {id}",
2098
+ details: "Host diagnostic",
2099
+ retry: "Resolve the diagnostic, refresh profiles, then retry.",
2100
+ globalScope: "Global default for future sessions",
2101
+ sessionScope: "Current native session",
2102
+ sessionSelect: "Current-session profile",
2103
+ globalActionHint: "Apply saved profile below changes the global default for future unscoped sessions only. It does not apply to the current session.",
2104
+ noSession: "No native session is selected. Session Apply is disabled; global defaults and drafts remain editable.",
2105
+ sessionUnavailable: "The current session could not be confirmed. Refresh its state before retrying; the prior policy is kept.",
2106
+ sessionBusy: "Switching is unavailable: {reason}. The Host must reserve a truly idle ordinary session before applying.",
2107
+ sessionState: "Session {id}: {profile}; scope {scope}; admission epoch {epoch}.",
2108
+ sessionBaseline: "deployment baseline",
2109
+ sessionGlobalCaptured: "captured global default (no explicit session override)",
2110
+ sessionAdmittedProfile: "{id} (revision {revision})",
2111
+ sessionFutureDefault: "Global default for future unscoped sessions: {profile}. This does not change this session's admission.",
2112
+ sessionConflict: "The session selection or admission epoch changed elsewhere. The prior display and draft are kept. Refresh current-session state before applying again.",
2113
+ sessionApply: "Apply profile to current session",
2114
+ sessionApplying: "Applying current-session profile…",
2115
+ sessionReset: "Pin baseline for current session",
2116
+ sessionResetting: "Pinning current-session baseline…",
2117
+ sessionRefresh: "Refresh current-session state",
2118
+ sessionApplied: "Applied the saved revision to this session only. Global default and existing children were not changed.",
2119
+ sessionResetDone: "Pinned the deployment baseline for this session only. Global default was not changed.",
2120
+ sessionDirty: "Save or explicitly discard the editor draft before applying a current-session choice.",
2121
+ roleState: "Admitted route {route}; strategy {strategy}; retries {retries}; rate-limit failures {failures}; switches {switches}; total delay {delay} ms.",
2122
+ catalogTitle: "Native model catalog",
2123
+ 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.",
2124
+ catalogUnavailable: "The native catalog is unavailable. Manual provider/model/effort fields and advanced JSONC remain available.",
2125
+ catalogRefresh: "Refresh model catalog",
2126
+ catalogRefreshing: "Refreshing model catalog…",
2127
+ catalogFailure: "Provider catalog unavailable: {name} ({id}).",
2128
+ profileLabel: "Profile display label",
2129
+ defaultActive: "Default Deepwork mode",
2130
+ activeHint: "This default does not erase an explicit saved session mode.",
2131
+ enabled: "Enabled",
2132
+ disabled: "Disabled",
2133
+ inherit: "Inherit deployment baseline",
2134
+ profileDefaults: "Profile runtime defaults",
2135
+ roleSelect: "Agent role to edit",
2136
+ rolesUnavailable: "Native role inventory unavailable — use advanced JSONC",
2137
+ roleEnabled: "Enabled in the native deployment",
2138
+ roleDisabled: "Disabled in the native deployment",
2139
+ strategy: "{name} strategy",
2140
+ inheritStrategy: "Inherit ({value})",
2141
+ startupLock: "startup-lock — keep the admitted route",
2142
+ rateFallback: "rate-limit-fallback — ordered rollover at threshold",
2143
+ 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.",
2144
+ retryField: "{name} {field}",
2145
+ inheritNumber: "Inherit {value}",
2146
+ retryBounds: "Integer {min}–{max}; inherited value {value}.",
2147
+ unknownDefault: "unavailable",
2148
+ retryCount: "retry count",
2149
+ initialDelay: "initial delay (ms)",
2150
+ maxDelay: "maximum delay (ms)",
2151
+ totalWait: "total wait budget (ms)",
2152
+ switchThreshold: "rate-limit failures before switch",
2153
+ maxSwitches: "maximum switches",
2154
+ primaryMode: "{name} primary route",
2155
+ inheritRoute: "Inherit native/deployment route",
2156
+ configuredRoute: "Configure primary route",
2157
+ primaryName: "{name} primary",
2158
+ fallbackMode: "{name} fallback chain",
2159
+ inheritChain: "Inherit deployment fallback chain",
2160
+ configuredChain: "Explicit ordered fallback chain",
2161
+ emptyChain: "Explicitly empty chain: no configured fallback routes.",
2162
+ fallbackName: "{name} fallback {index}",
2163
+ addFallback: "Add fallback for {name}",
2164
+ removeFallback: "Remove {name}",
2165
+ moveUp: "Move up {name}",
2166
+ moveDown: "Move down {name}",
2167
+ routeProvider: "{name} provider",
2168
+ routeModel: "{name} model",
2169
+ routeEffort: "{name} exact effort",
2170
+ manualProvider: "{name} manual provider",
2171
+ manualModel: "{name} manual model",
2172
+ manualEffort: "{name} manual exact effort",
2173
+ manual: "Enter manual identifier",
2174
+ manualValue: "Manual / unlisted: {value}",
2175
+ unset: "not set",
2176
+ effortDefault: "Native default (omit exact effort)",
2177
+ 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.",
2178
+ advanced: "Advanced JSONC",
2179
+ rawInvalid: "Structured editing is unavailable for this invalid raw draft. Correct Advanced JSONC; no fields, comments or bytes have been normalized.",
2180
+ invalidNumber: "Correct this bounded integer before saving or changing roles. The invalid value has not replaced the saved draft policy."
2181
+ };
2182
+ var zh = {
2183
+ title: "Deepwork 配置档",
2184
+ description: "保存独立的运行时配置,并选择新会话使用的配置档。",
2185
+ newSessions: "全局应用和重置仅影响之后没有独立选择的新会话。下方当前会话操作相互独立。冷恢复保留明确保存的会话选择,否则继承全局默认值。",
2186
+ editorSelect: "要编辑的配置档",
2187
+ choose: "选择配置档",
2188
+ newDraft: "新的未保存配置档",
2189
+ new: "新建配置档",
2190
+ profileId: "配置档 ID(名称)",
2191
+ idHint: "使用 1–64 个小写字母、数字、连字符或下划线。保存后不能修改 ID。可在 JSONC 文档中添加可选的显示名称 label。",
2192
+ configuration: "运行时配置(JSONC)",
2193
+ configurationHint: "文档包含 version: 1、相同的 id、可选 label 和 settings。支持 defaultActive、roleRouting、workflow、guards、runtimeRecovery,以及两个 DeepSeek 系列的校准、默认推理强度和最高强度预设策略。",
2194
+ structuralHint: "角色、技能、模式名称、提示顺序或内容、预设安装、LSP、提供商和账户由原生部署配置管理,不属于配置档。路由可引用已有提供商;请勿粘贴凭证。",
2195
+ save: "保存配置档",
2196
+ saving: "正在保存配置档…",
2197
+ apply: "应用已保存配置档",
2198
+ applying: "正在应用配置档…",
2199
+ reset: "重置为基线",
2200
+ resetting: "正在重置为基线…",
2201
+ refresh: "刷新配置档",
2202
+ refreshing: "正在刷新配置档…",
2203
+ reload: "重新加载已保存配置档",
2204
+ loading: "正在加载配置档…",
2205
+ reading: "正在读取配置档…",
2206
+ empty: "尚无已保存的配置档。可新建配置档;当前仍应用部署基线。",
2207
+ baseline: "新会话使用:部署基线。",
2208
+ appliedProfile: "新会话使用:{id}(修订 {revision})。",
2209
+ appliedInvalid: "无法确认保存的选择。已有会话未改变。请先解决 Host 诊断,再应用或重置配置档。",
2210
+ selectionConflict: "保存的选择已被此 Host 之外的操作修改。此 Host 的新会话仍使用上方策略。请应用已保存配置档或重置为基线以协调选择;重启将采用保存的选择。已有会话未改变。",
2211
+ dirty: "有未保存的更改。请先保存再应用;仅保存不会应用此配置档。",
2212
+ savedNotApplied: "已保存;此修订尚未应用到新会话。",
2213
+ savedApplied: "此已保存修订已应用到新会话。",
2214
+ saved: "已保存 {id},未改变已应用的策略。",
2215
+ applied: "已为新会话应用 {id},已有会话未改变。",
2216
+ resetDone: "已为新会话重置为部署基线,已有会话未改变。",
2217
+ discardPrompt: "切换编辑器之前,是否丢弃未保存的草稿?",
2218
+ discard: "丢弃更改",
2219
+ cancel: "取消",
2220
+ conflict: "已保存文件或选择已被其他操作修改。草稿和原选择已保留。请刷新配置档,然后重新加载已保存配置档或检查草稿后重试。",
2221
+ validation: "此配置档无效。请修正下方字段;草稿未改变。",
2222
+ io: "Host 无法提交此操作。草稿和原选择已保留。请检查配置档存储权限,刷新后重试。",
2223
+ unavailable: "原生配置档服务不可用。草稿已保留。Host 重新连接或启用 Deepwork 后请刷新。",
2224
+ transport: "原生连接无法确认此操作。草稿已保留。重试之前请刷新 Host 状态;不要假定保存或应用已完成。",
2225
+ invalidProfile: "不可用配置档:{id}",
2226
+ details: "Host 诊断",
2227
+ retry: "请解决诊断问题,刷新配置档后重试。",
2228
+ globalScope: "未来会话的全局默认值",
2229
+ sessionScope: "当前原生会话",
2230
+ sessionSelect: "当前会话配置档",
2231
+ globalActionHint: "下方应用已保存配置档仅改变未来没有独立选择的会话的全局默认值,不会应用到当前会话。",
2232
+ noSession: "未选择原生会话。会话应用已禁用;仍可编辑全局默认值和草稿。",
2233
+ sessionUnavailable: "无法确认当前会话。重试前请刷新状态;原策略已保留。",
2234
+ sessionBusy: "暂不可切换:{reason}。Host 必须先保留真正空闲的普通会话。",
2235
+ sessionState: "会话 {id}:{profile};范围 {scope};准入代次 {epoch}。",
2236
+ sessionBaseline: "部署基线",
2237
+ sessionGlobalCaptured: "已捕获的全局默认值(没有明确会话覆盖)",
2238
+ sessionAdmittedProfile: "{id}(修订 {revision})",
2239
+ sessionFutureDefault: "未来没有独立选择的会话的全局默认值:{profile}。这不会改变当前会话的准入。",
2240
+ sessionConflict: "会话选择或准入代次已在其他位置改变。原显示和草稿已保留。再次应用前请刷新当前会话状态。",
2241
+ sessionApply: "应用配置档到当前会话",
2242
+ sessionApplying: "正在应用当前会话配置档…",
2243
+ sessionReset: "为当前会话固定基线",
2244
+ sessionResetting: "正在固定当前会话基线…",
2245
+ sessionRefresh: "刷新当前会话状态",
2246
+ sessionApplied: "已仅对此会话应用保存的修订。全局默认值和已有子会话未改变。",
2247
+ sessionResetDone: "已仅对此会话固定部署基线。全局默认值未改变。",
2248
+ sessionDirty: "应用当前会话选择之前,请保存或明确丢弃编辑器草稿。",
2249
+ roleState: "准入路由 {route};策略 {strategy};重试 {retries};限流失败 {failures};切换 {switches};累计延迟 {delay} 毫秒。",
2250
+ catalogTitle: "原生模型目录",
2251
+ catalogHint: "目录仅供参考,不是网络或账户健康检查。未列出或手动路由仍可编辑;刷新不会改变草稿或原生模型默认值。",
2252
+ catalogUnavailable: "原生模型目录不可用。仍可使用手动提供商、模型、强度字段和高级 JSONC。",
2253
+ catalogRefresh: "刷新模型目录",
2254
+ catalogRefreshing: "正在刷新模型目录…",
2255
+ catalogFailure: "提供商目录不可用:{name}({id})。",
2256
+ profileLabel: "配置档显示名称",
2257
+ defaultActive: "默认 Deepwork 模式",
2258
+ activeHint: "此默认值不会抹除已明确保存的会话模式。",
2259
+ enabled: "启用",
2260
+ disabled: "禁用",
2261
+ inherit: "继承部署基线",
2262
+ profileDefaults: "配置档运行时默认值",
2263
+ roleSelect: "要编辑的 Agent 角色",
2264
+ rolesUnavailable: "原生角色列表不可用,请使用高级 JSONC",
2265
+ roleEnabled: "原生部署中已启用",
2266
+ roleDisabled: "原生部署中已禁用",
2267
+ strategy: "{name} 策略",
2268
+ inheritStrategy: "继承({value})",
2269
+ startupLock: "startup-lock — 保留准入路由",
2270
+ rateFallback: "rate-limit-fallback — 达到阈值后按顺序切换",
2271
+ strategyHint: "两种策略均使用有限且已证明无输出的 RATE_LIMIT 重试。普通、认证或配额失败不允许切换模型。数字留空表示继承,零是明确值。",
2272
+ retryField: "{name} {field}",
2273
+ inheritNumber: "继承 {value}",
2274
+ retryBounds: "整数 {min}–{max};继承值 {value}。",
2275
+ unknownDefault: "不可用",
2276
+ retryCount: "重试次数",
2277
+ initialDelay: "初始延迟(毫秒)",
2278
+ maxDelay: "最大单次延迟(毫秒)",
2279
+ totalWait: "累计等待上限(毫秒)",
2280
+ switchThreshold: "切换前的限流失败次数",
2281
+ maxSwitches: "最大切换次数",
2282
+ primaryMode: "{name} 主路由",
2283
+ inheritRoute: "继承原生或部署路由",
2284
+ configuredRoute: "配置主路由",
2285
+ primaryName: "{name} 主路由",
2286
+ fallbackMode: "{name} 备用链",
2287
+ inheritChain: "继承部署备用链",
2288
+ configuredChain: "明确的有序备用链",
2289
+ emptyChain: "明确为空的备用链:没有已配置备用路由。",
2290
+ fallbackName: "{name} 备用 {index}",
2291
+ addFallback: "为 {name} 添加备用路由",
2292
+ removeFallback: "移除 {name}",
2293
+ moveUp: "上移 {name}",
2294
+ moveDown: "下移 {name}",
2295
+ routeProvider: "{name} 提供商",
2296
+ routeModel: "{name} 模型",
2297
+ routeEffort: "{name} 精确强度",
2298
+ manualProvider: "{name} 手动提供商",
2299
+ manualModel: "{name} 手动模型",
2300
+ manualEffort: "{name} 手动精确强度",
2301
+ manual: "输入手动标识",
2302
+ manualValue: "手动或未列出:{value}",
2303
+ unset: "未设置",
2304
+ effortDefault: "原生默认值(省略精确强度)",
2305
+ effortChangeHint: "明确更改提供商或模型会清除该路由的精确强度。刷新目录会保留所有配置值;需要时请重新选择精确强度。",
2306
+ advanced: "高级 JSONC",
2307
+ rawInvalid: "原始草稿无效,暂不可结构化编辑。请修正高级 JSONC;字段、注释和字节均未自动规范化。",
2308
+ invalidNumber: "保存或切换角色之前,请修正此有界整数。无效值尚未替换草稿中的策略。"
2309
+ };
2310
+ var RETRY_FIELD_LABEL_KEYS = {
2311
+ maxRetries: "retryCount",
2312
+ initialDelayMs: "initialDelay",
2313
+ maxDelayMs: "maxDelay",
2314
+ maxTotalDelayMs: "totalWait",
2315
+ switchAfterRateLimits: "switchThreshold",
2316
+ maxSwitches: "maxSwitches"
2317
+ };
2318
+
2319
+ // src/client/ProfilesSection.tsx
2320
+ var import_react3 = require("react");
2321
+ var import_dsh_client_ui_primitives3 = require("@deepseek-ai/dsh-client-ui-primitives");
2322
+
2323
+ // src/client/StructuredEditor.tsx
2324
+ var import_react = require("react");
2325
+ var import_dsh_client_ui_primitives = require("@deepseek-ai/dsh-client-ui-primitives");
2326
+ var import_jsx_runtime = require("react/jsx-runtime");
2327
+ var MANUAL = "__dsmm_manual__";
2328
+ function RetryNumber({ id: id2, name, field, value, inherited, path, disabled, actions, t }) {
2329
+ const [draft, setDraft] = (0, import_react.useState)(value === void 0 ? "" : String(value));
2330
+ const [invalid, setInvalid] = (0, import_react.useState)(false);
2331
+ const [min, max] = DSMM_RATE_LIMIT_BOUNDS[field];
2332
+ const key = path.join(".");
2333
+ (0, import_react.useEffect)(() => {
2334
+ setDraft(value === void 0 ? "" : String(value));
2335
+ setInvalid(false);
2336
+ }, [value]);
2337
+ (0, import_react.useEffect)(() => {
2338
+ actions.setFieldInvalid(key, invalid);
2339
+ return () => actions.setFieldInvalid(key, false);
2340
+ }, [actions.setFieldInvalid, key, invalid]);
2341
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2342
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: id2, children: t("retryField", { name, field: t(RETRY_FIELD_LABEL_KEYS[field]) }) }),
2343
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
2344
+ import_dsh_client_ui_primitives.Input,
2345
+ {
2346
+ id: id2,
2347
+ "data-dsmm-policy-field": field,
2348
+ className: "dsmm-input",
2349
+ type: "number",
2350
+ inputMode: "numeric",
2351
+ min,
2352
+ max,
2353
+ step: 1,
2354
+ disabled,
2355
+ value: draft,
2356
+ placeholder: inherited === void 0 ? t("unknownDefault") : t("inheritNumber", { value: inherited }),
2357
+ "aria-invalid": invalid || void 0,
2358
+ "aria-describedby": `${id2}-hint${invalid ? ` ${id2}-invalid` : ""}`,
2359
+ onChange: (event) => {
2360
+ const input = event.currentTarget;
2361
+ setDraft(input.value);
2362
+ const valid = input.validity.valid && (input.value === "" || Number.isSafeInteger(input.valueAsNumber));
2363
+ setInvalid(!valid);
2364
+ actions.setFieldInvalid(key, !valid);
2365
+ if (valid) actions.editPath(path, input.value === "" ? void 0 : input.valueAsNumber);
2366
+ }
2367
+ }
2368
+ ),
2369
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", id: `${id2}-hint`, children: t("retryBounds", { min, max, value: inherited ?? t("unknownDefault") }) }),
2370
+ invalid && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { id: `${id2}-invalid`, children: t("invalidNumber") })
2371
+ ] });
2372
+ }
2373
+ function RouteFields({ value, path, name, catalog, disabled, edit, editRoute, t }) {
2374
+ const prefix = (0, import_react.useId)();
2375
+ const providers = catalog?.groups ?? [];
2376
+ const group = providers.find((candidate) => candidate.id === value.provider);
2377
+ const model = group?.models.find((candidate) => candidate.id === value.model);
2378
+ const efforts = model?.reasoning?.efforts ?? [];
2379
+ const providerListed = group !== void 0;
2380
+ const modelListed = model !== void 0;
2381
+ const updateModel = (provider, modelId) => {
2382
+ editRoute(path, provider, modelId);
2383
+ };
2384
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-route-fields", children: [
2385
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2386
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-provider`, children: t("routeProvider", { name }) }),
2387
+ /* @__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: [
2388
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: MANUAL, children: providerListed ? t("manual") : t("manualValue", { value: value.provider || t("unset") }) }),
2389
+ providers.map((provider) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: provider.id, children: [
2390
+ provider.name,
2391
+ " (",
2392
+ provider.id,
2393
+ ")"
2394
+ ] }, provider.id))
2395
+ ] }),
2396
+ !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) })
2397
+ ] }),
2398
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2399
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-model`, children: t("routeModel", { name }) }),
2400
+ /* @__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: [
2401
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: MANUAL, children: modelListed ? t("manual") : t("manualValue", { value: value.model || t("unset") }) }),
2402
+ group?.models.map((candidate) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: candidate.id, children: [
2403
+ candidate.name,
2404
+ " (",
2405
+ candidate.id,
2406
+ ")"
2407
+ ] }, candidate.id))
2408
+ ] }),
2409
+ !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) })
2410
+ ] }),
2411
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2412
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-effort`, children: t("routeEffort", { name }) }),
2413
+ /* @__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: [
2414
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("effortDefault") }),
2415
+ 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 }) }),
2416
+ efforts.map((effort) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: effort.id, children: [
2417
+ effort.name,
2418
+ " (",
2419
+ effort.id,
2420
+ ")"
2421
+ ] }, effort.id))
2422
+ ] }),
2423
+ /* @__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) })
2424
+ ] })
2425
+ ] });
2426
+ }
2427
+ function PolicyFields({ value, inherited, path, name, disabled, actions, t }) {
2428
+ const prefix = (0, import_react.useId)();
2429
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-policy-fields", children: [
2430
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2431
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-strategy`, children: t("strategy", { name }) }),
2432
+ /* @__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: [
2433
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("inheritStrategy", { value: inherited?.strategy ?? t("unknownDefault") }) }),
2434
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "startup-lock", children: t("startupLock") }),
2435
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "rate-limit-fallback", children: t("rateFallback") })
2436
+ ] })
2437
+ ] }),
2438
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("strategyHint") }),
2439
+ /* @__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)) })
2440
+ ] });
2441
+ }
2442
+ function StructuredEditor({ state, actions, disabled, t }) {
2443
+ const prefix = (0, import_react.useId)();
2444
+ const [selectedRole, setSelectedRole] = (0, import_react.useState)("dsmm-orchestrator");
2445
+ const document2 = state.editor === null ? null : structuredDocument(state.editor.content);
2446
+ if (document2 === null) return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", "data-dsmm-structured-invalid": true, children: t("rawInvalid") });
2447
+ const roles = state.snapshot?.roles ?? [];
2448
+ const role2 = roles.find((candidate) => candidate.id === selectedRole) ?? roles[0];
2449
+ const policy = role2 === void 0 ? void 0 : document2.roleRouting[role2.id] ?? {};
2450
+ const baseline = state.snapshot?.editorDefaults;
2451
+ let inherited;
2452
+ try {
2453
+ if (baseline !== void 0) {
2454
+ const profileDefaults = { strategy: document2.runtimePolicy.strategy ?? baseline.strategy, rateLimit: normalizeRateLimitPolicy(document2.runtimePolicy.rateLimit, baseline.rateLimit) };
2455
+ inherited = { strategy: role2?.runtimePolicy?.strategy ?? profileDefaults.strategy, rateLimit: normalizeRateLimitPolicy(role2?.runtimePolicy?.rateLimit, profileDefaults.rateLimit) };
2456
+ }
2457
+ } catch {
2458
+ }
2459
+ const rolePath = ["settings", "roleRouting", role2?.id ?? ""];
2460
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-structured", "data-dsmm-structured": true, children: [
2461
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2462
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-label`, children: t("profileLabel") }),
2463
+ /* @__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) })
2464
+ ] }),
2465
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2466
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-active`, children: t("defaultActive") }),
2467
+ /* @__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: [
2468
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("inherit") }),
2469
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "true", children: t("enabled") }),
2470
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "false", children: t("disabled") })
2471
+ ] }),
2472
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("activeHint") })
2473
+ ] }),
2474
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { children: [
2475
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: t("profileDefaults") }),
2476
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PolicyFields, { t, value: document2.runtimePolicy, inherited: baseline, path: ["settings", "runtimePolicy"], name: t("profileDefaults"), disabled, actions })
2477
+ ] }),
2478
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2479
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-role`, children: t("roleSelect") }),
2480
+ /* @__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: [
2481
+ roles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "", children: t("rolesUnavailable") }),
2482
+ roles.map((candidate) => /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("option", { value: candidate.id, children: [
2483
+ candidate.label,
2484
+ candidate.enabled ? "" : ` — ${t("roleDisabled")}`
2485
+ ] }, candidate.id))
2486
+ ] })
2487
+ ] }),
2488
+ role2 !== void 0 && policy !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { "data-dsmm-role": role2.id, children: [
2489
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: role2.label }),
2490
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t(role2.enabled ? "roleEnabled" : "roleDisabled") }),
2491
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(PolicyFields, { t, value: policy, inherited, path: rolePath, name: role2.label, disabled, actions }),
2492
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2493
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-primary-mode`, children: t("primaryMode", { name: role2.label }) }),
2494
+ /* @__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: [
2495
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "inherit", children: t("inheritRoute") }),
2496
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "explicit", children: t("configuredRoute") })
2497
+ ] })
2498
+ ] }),
2499
+ 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 }),
2500
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("effortChangeHint") }),
2501
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-field", children: [
2502
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("label", { htmlFor: `${prefix}-fallback-mode`, children: t("fallbackMode", { name: role2.label }) }),
2503
+ /* @__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: [
2504
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "inherit", children: t("inheritChain") }),
2505
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("option", { value: "explicit", children: t("configuredChain") })
2506
+ ] })
2507
+ ] }),
2508
+ policy.fallbackRoutes?.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime.jsx)("p", { className: "dsmm-hint", children: t("emptyChain") }),
2509
+ policy.fallbackRoutes?.map((candidate, index) => {
2510
+ const name = t("fallbackName", { name: role2.label, index: index + 1 });
2511
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("fieldset", { children: [
2512
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("legend", { children: name }),
2513
+ /* @__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 }),
2514
+ /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "dsmm-actions", children: [
2515
+ /* @__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 }) }),
2516
+ /* @__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 }) }),
2517
+ /* @__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 }) })
2518
+ ] })
2519
+ ] }, index);
2520
+ }),
2521
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)(import_dsh_client_ui_primitives.Button, { type: "button", variant: "outline", disabled: disabled || (policy.fallbackRoutes?.length ?? 0) >= 32, onClick: () => {
2522
+ if (policy.fallbackRoutes === void 0) actions.editPath([...rolePath, "fallbackRoutes"], [{ provider: "", model: "" }]);
2523
+ else actions.editPath([...rolePath, "fallbackRoutes", policy.fallbackRoutes.length], { provider: "", model: "" });
2524
+ }, children: t("addFallback", { name: role2.label }) })
2525
+ ] })
2526
+ ] });
2527
+ }
2528
+
2529
+ // src/client/SessionProfiles.tsx
2530
+ var import_react2 = require("react");
2531
+ var import_dsh_client_ui_primitives2 = require("@deepseek-ai/dsh-client-ui-primitives");
2532
+
2533
+ // src/client/session-labels.ts
2534
+ function sessionProfileLabels(session, t) {
2535
+ const admitted = session.admittedSelection;
2536
+ 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) ?? "—" });
2537
+ const future = session.globalDefault;
2538
+ return {
2539
+ admitted: t("sessionState", { id: session.sessionId, profile, scope: session.scope, epoch: session.admissionEpoch }),
2540
+ futureDefault: t("sessionFutureDefault", { profile: future.selectedId === null ? t("sessionBaseline") : t("sessionAdmittedProfile", { id: future.selectedId, revision: future.appliedRevision?.slice(0, 12) ?? "—" }) })
2541
+ };
2542
+ }
2543
+
2544
+ // src/client/SessionProfiles.tsx
2545
+ var import_jsx_runtime2 = require("react/jsx-runtime");
2546
+ function SessionScope({ state, actions, t, compact = false }) {
2547
+ const prefix = (0, import_react2.useId)();
2548
+ const session = state.session;
2549
+ const labels = session === null ? null : sessionProfileLabels(session, t);
2550
+ const selected = state.snapshot?.profiles.find((profile) => profile.id === state.sessionChoice);
2551
+ const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy !== null || state.dirty;
2552
+ const allowed = session !== null && session.switchAllowed && /^[a-f0-9]{64}$|^absent$/u.test(session.selection.selectionRevision);
2553
+ const status = state.sessionNotice === null ? "" : t(state.sessionNotice === "applied" ? "sessionApplied" : "sessionResetDone");
2554
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-session-scope", "aria-busy": state.sessionBusy !== null, "data-dsmm-session-scope": true, children: [
2555
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: t("sessionScope") }),
2556
+ 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: [
2557
+ labels !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { "data-dsmm-session-state": true, children: labels.admitted }),
2558
+ labels !== null && !compact && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-hint", "data-dsmm-session-future-default": true, children: labels.futureDefault }),
2559
+ session !== null && !session.switchAllowed && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-hint", children: t("sessionBusy", { reason: session.switchUnavailableReason ?? "unavailable" }) }),
2560
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-field", children: [
2561
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: `${prefix}-choice`, children: t("sessionSelect") }),
2562
+ /* @__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: [
2563
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "", children: t("sessionBaseline") }),
2564
+ state.sessionChoice !== null && selected === void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: state.sessionChoice, children: state.sessionChoice }),
2565
+ 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))
2566
+ ] })
2567
+ ] }),
2568
+ state.dirty && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-hint", children: t("sessionDirty") }),
2569
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-actions", children: [
2570
+ /* @__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: () => {
2571
+ void actions.applySession();
2572
+ }, children: t(state.sessionBusy === "apply" ? "sessionApplying" : "sessionApply") }),
2573
+ !compact && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(import_dsh_client_ui_primitives2.Button, { type: "button", variant: "outline", disabled: disabled || !allowed, onClick: () => {
2574
+ void actions.resetSession();
2575
+ }, children: t(state.sessionBusy === "reset" ? "sessionResetting" : "sessionReset") }),
2576
+ /* @__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: () => {
2577
+ void actions.refreshSession();
2578
+ }, children: t("sessionRefresh") })
2579
+ ] }),
2580
+ !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 }) })
2581
+ ] }),
2582
+ state.sessionIssue !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "alert", children: 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") }),
2583
+ /* @__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 })
2584
+ ] });
2585
+ }
2586
+ function SessionProfiles(props) {
2587
+ const state = props.useProfiles((snapshot2) => snapshot2);
2588
+ if (props.sessionId !== state.currentSessionId) return null;
2589
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("div", { className: "dsmm-profiles dsmm-header-profiles", children: /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("details", { children: [
2590
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("summary", { children: props.t("title") }),
2591
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)(SessionScope, { state, actions: props, t: props.t, compact: true })
2592
+ ] }) });
2593
+ }
2594
+
2595
+ // src/client/ProfilesSection.tsx
2596
+ var import_jsx_runtime3 = require("react/jsx-runtime");
2597
+ function issueKey(issue) {
2598
+ if (issue.source === "selection") return issue.code === "conflict" ? "selectionConflict" : "appliedInvalid";
2599
+ if (issue.kind === "assembly") return "unavailable";
2600
+ if (issue.kind === "transport") return "transport";
2601
+ return issue.code === "conflict" || issue.code === "validation" ? issue.code : "io";
2602
+ }
2603
+ function ProfilesSection(props) {
2604
+ const { t } = props;
2605
+ const state = props.useProfiles((snapshot3) => snapshot3);
2606
+ const prefix = (0, import_react3.useId)();
2607
+ const selectRef = (0, import_react3.useRef)(null);
2608
+ const inputRef = (0, import_react3.useRef)(null);
2609
+ const editorRef = (0, import_react3.useRef)(null);
2610
+ const cancelRef = (0, import_react3.useRef)(null);
2611
+ const hadConfirmation = (0, import_react3.useRef)(false);
2612
+ const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy === "apply" || state.sessionBusy === "reset";
2613
+ const snapshot2 = state.snapshot;
2614
+ const editor = state.editor;
2615
+ const reconcilable = canReconcileSelection(snapshot2);
2616
+ const selectionConflict = reconcilable && snapshot2?.selectionError?.code === "conflict";
2617
+ const invalid = state.issue?.kind === "domain" && state.issue.code === "validation";
2618
+ const idInvalid = invalid && state.issue?.field === "id";
2619
+ const rawInvalid = editor !== null && structuredDocument(editor.content) === null;
2620
+ (0, import_react3.useEffect)(() => {
2621
+ if (state.pendingEditor !== null) {
2622
+ cancelRef.current?.focus();
2623
+ hadConfirmation.current = true;
2624
+ } else if (hadConfirmation.current) {
2625
+ selectRef.current?.focus();
2626
+ hadConfirmation.current = false;
2627
+ }
2628
+ }, [state.pendingEditor]);
2629
+ (0, import_react3.useEffect)(() => {
2630
+ if (state.issue?.kind === "domain" && state.issue.code === "validation") {
2631
+ if (state.issue.field === "id") inputRef.current?.focus();
2632
+ else editorRef.current?.focus();
2633
+ }
2634
+ }, [state.issue]);
2635
+ const applied = editor?.revision !== null && editor?.id === snapshot2?.selectedId && editor?.revision === snapshot2?.appliedRevision;
2636
+ let selection = t("baseline");
2637
+ if (snapshot2?.selectionError !== void 0 && !selectionConflict) selection = t("appliedInvalid");
2638
+ else if (snapshot2?.selectedId !== null && snapshot2?.selectedId !== void 0) selection = t("appliedProfile", { id: snapshot2.selectedId, revision: snapshot2.appliedRevision?.slice(0, 12) ?? "—" });
2639
+ const notice = state.notice === null ? "" : t(state.notice.key === "reset" ? "resetDone" : state.notice.key, { id: state.notice.id });
2640
+ return /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("section", { className: "dsmm-profiles", "aria-labelledby": `${prefix}-title`, "aria-busy": state.busy !== null, children: [
2641
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h2", { id: `${prefix}-title`, children: t("title") }),
2642
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: t("description") }),
2643
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { id: `${prefix}-global`, children: t("globalScope") }),
2644
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("newSessions") }),
2645
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { "data-dsmm-selection": true, children: selection }),
2646
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-actions", children: [
2647
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled: disabled || snapshot2 === null, onClick: () => {
2648
+ void props.create();
2649
+ }, children: t("new") }),
2650
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled, onClick: () => {
2651
+ void props.refresh();
2652
+ }, children: t(state.busy === "refresh" ? "refreshing" : "refresh") }),
2653
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled: disabled || !reconcilable || snapshot2?.selectedId === null && !selectionConflict, onClick: () => {
2654
+ void props.reset();
2655
+ }, children: t(state.busy === "reset" ? "resetting" : "reset") })
2656
+ ] }),
2657
+ snapshot2 !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-field", children: [
2658
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { htmlFor: `${prefix}-select`, children: t("editorSelect") }),
2659
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("select", { ref: selectRef, id: `${prefix}-select`, disabled, value: editor?.revision == null ? "" : editor.id, onChange: (event) => {
2660
+ if (event.currentTarget.value) void props.open(event.currentTarget.value);
2661
+ }, children: [
2662
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("option", { value: "", children: t(editor?.revision === null ? "newDraft" : "choose") }),
2663
+ snapshot2.profiles.map((profile, index) => /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("option", { value: profile.id, children: [
2664
+ profile.label === void 0 ? profile.id : `${profile.label} (${profile.id})`,
2665
+ profile.error === void 0 ? "" : ` — ${t("invalidProfile", { id: profile.id })}`
2666
+ ] }, `${index}:${profile.id}`))
2667
+ ] }),
2668
+ snapshot2.profiles.length === 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("empty") })
2669
+ ] }),
2670
+ state.pendingEditor !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-confirm", role: "group", "aria-labelledby": `${prefix}-confirm`, onKeyDown: (event) => {
2671
+ if (event.key === "Escape") {
2672
+ event.preventDefault();
2673
+ props.cancelDiscard();
2674
+ }
2675
+ }, children: [
2676
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-confirm`, children: t("discardPrompt") }),
2677
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-actions", children: [
2678
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", onClick: () => {
2679
+ void props.discardAndOpen();
2680
+ }, children: t("discard") }),
2681
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { ref: cancelRef, type: "button", variant: "primary", onClick: props.cancelDiscard, children: t("cancel") })
2682
+ ] })
2683
+ ] }),
2684
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(SessionScope, { state, actions: props, t }),
2685
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-catalog", children: [
2686
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("h3", { children: t("catalogTitle") }),
2687
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("catalogHint") }),
2688
+ state.catalogUnavailable && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { className: "dsmm-hint", children: t("catalogUnavailable") }),
2689
+ 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)),
2690
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled: state.catalogBusy, onClick: () => {
2691
+ void props.refreshCatalog();
2692
+ }, children: t(state.catalogBusy ? "catalogRefreshing" : "catalogRefresh") })
2693
+ ] }),
2694
+ editor !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-editor", children: [
2695
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-field", children: [
2696
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { htmlFor: `${prefix}-id`, children: t("profileId") }),
2697
+ /* @__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) }),
2698
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-id-hint`, className: "dsmm-hint", children: t("idHint") })
2699
+ ] }),
2700
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(StructuredEditor, { state, actions: props, disabled, t }, state.editorEpoch),
2701
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("details", { className: "dsmm-advanced", open: true, children: [
2702
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("summary", { children: t("advanced") }),
2703
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-field", children: [
2704
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("label", { htmlFor: `${prefix}-content`, children: t("configuration") }),
2705
+ /* @__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) }),
2706
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-content-hint`, className: "dsmm-hint", children: t("configurationHint") }),
2707
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-structural-hint`, className: "dsmm-hint", children: t("structuralHint") })
2708
+ ] })
2709
+ ] }),
2710
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { "data-dsmm-editor-state": true, children: t(state.dirty ? "dirty" : applied ? "savedApplied" : "savedNotApplied") }),
2711
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { id: `${prefix}-global-action`, className: "dsmm-hint", children: t("globalActionHint") }),
2712
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-actions", children: [
2713
+ /* @__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: () => {
2714
+ void props.save();
2715
+ }, children: t(state.busy === "save" ? "saving" : "save") }),
2716
+ /* @__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: () => {
2717
+ void props.apply();
2718
+ }, children: t(state.busy === "apply" ? "applying" : "apply") }),
2719
+ editor.revision !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsx)(import_dsh_client_ui_primitives3.Button, { type: "button", variant: "outline", disabled, onClick: () => {
2720
+ void props.reload();
2721
+ }, children: t("reload") })
2722
+ ] })
2723
+ ] }),
2724
+ state.issue !== null && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-issue", id: `${prefix}-issue`, role: "alert", children: [
2725
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: t(issueKey(state.issue)) }),
2726
+ state.issue.kind === "domain" && state.issue.message !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
2727
+ t("details"),
2728
+ ": ",
2729
+ state.issue.message
2730
+ ] })
2731
+ ] }),
2732
+ snapshot2?.selectionError !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("div", { className: "dsmm-issue", children: [
2733
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("p", { children: [
2734
+ t("details"),
2735
+ ": ",
2736
+ snapshot2.selectionError.message
2737
+ ] }),
2738
+ /* @__PURE__ */ (0, import_jsx_runtime3.jsx)("p", { children: t(selectionConflict ? "selectionConflict" : "retry") })
2739
+ ] }),
2740
+ /* @__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 })
2741
+ ] });
2742
+ }
2743
+
2744
+ // src/client/styles.ts
2745
+ var PROFILE_STYLES = `
2746
+ .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)}
2747
+ .dsmm-profiles h2{margin:0;font-size:18px;font-weight:600}
2748
+ .dsmm-profiles h3,.dsmm-profiles legend{margin:0;font-size:14px;font-weight:500;line-height:22px}
2749
+ .dsmm-profiles :is(label,legend,summary){min-width:0;max-width:100%;overflow-wrap:anywhere}
2750
+ .dsmm-profiles :is(.dsmm-structured,.dsmm-session-scope,.dsmm-catalog,.dsmm-policy-fields){min-width:0;display:flex;flex-direction:column;gap:12px}
2751
+ .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}
2752
+ .dsmm-profiles .dsmm-route-fields{display:flex;flex-wrap:wrap;gap:12px;min-width:0}
2753
+ .dsmm-profiles .dsmm-route-fields>.dsmm-field{flex:1 1 240px;max-width:100%}
2754
+ .dsmm-profiles .dsmm-route-fields select{width:100%}
2755
+ .dsmm-profiles summary{cursor:pointer;color:var(--dsw-alias-label-primary);min-height:32px;line-height:32px}
2756
+ .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}
2757
+ .dsmm-profiles .dsmm-advanced[open]>div{margin-top:8px}
2758
+ .dsmm-header-profiles{width:auto;max-width:760px}
2759
+ .dsmm-profiles p{margin:0;overflow-wrap:anywhere}
2760
+ .dsmm-profiles .dsmm-hint{color:var(--dsw-alias-label-secondary)}
2761
+ .dsmm-profiles .dsmm-field{min-width:0;display:flex;flex-direction:column;gap:6px}
2762
+ .dsmm-profiles .dsmm-actions{display:flex;flex-wrap:wrap;align-items:center;gap:8px}
2763
+ .dsmm-profiles button{max-width:100%;white-space:normal;overflow-wrap:anywhere;min-height:36px;height:auto}
2764
+ .dsmm-profiles .dsmm-input{width:100%;min-width:0;box-sizing:border-box;border-color:var(--dsw-alias-label-secondary)}
2765
+ .dsmm-profiles .dsmm-input input{width:100%;min-width:0;font:inherit;color:inherit}
2766
+ .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)}
2767
+ .dsmm-profiles select{width:240px;height:32px;padding:0 10px;text-overflow:ellipsis}
2768
+ .dsmm-profiles textarea{width:100%;padding:12px;font-family:var(--ds-font-family-code);resize:vertical;overflow:auto;white-space:pre;}
2769
+ .dsmm-profiles select:hover:not(:disabled),.dsmm-profiles textarea:hover:not(:disabled){border-color:var(--dsw-alias-label-primary)}
2770
+ .dsmm-profiles select:active:not(:disabled){background:var(--dsw-alias-interactive-bg-active)}
2771
+ .dsmm-profiles :is(select,textarea,button):focus-visible,.dsmm-profiles .dsmm-input:has(input:focus-visible){outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
2772
+ .dsmm-profiles :is(select,textarea):disabled{color:var(--dsw-alias-label-secondary);background:var(--dsw-alias-bg-module-platform);cursor:not-allowed}
2773
+ .dsmm-profiles .dsmm-editor,.dsmm-profiles .dsmm-confirm{min-width:0;display:flex;flex-direction:column;gap:12px;padding:16px;border:1px solid var(--dsw-alias-border-l4);border-radius:var(--dsw-radius-md);background:var(--dsw-alias-bg-module-platform)}
2774
+ .dsmm-profiles .dsmm-issue{padding:12px;border-left:4px solid var(--dsw-alias-state-error-primary);color:var(--dsw-alias-label-primary);overflow-wrap:anywhere}
2775
+ .dsmm-profiles .dsmm-issue p+p{margin-top:8px}
2776
+ .dsmm-profiles .dsmm-status{min-height:22px}
2777
+ @media(prefers-reduced-motion:reduce){.dsmm-profiles *{transition:none!important;animation:none!important}}
2778
+ `;
2779
+
2780
+ // src/client/index.ts
2781
+ var inject = ["slots", "locale", "remote"];
2782
+ async function apply(ctx) {
2783
+ await ctx.remote.$mount(TYPERT_REMOTE);
2784
+ await ctx.inject(["remote.dsmmProfiles"], (profileCtx) => {
2785
+ const controller = new ProfilesController(profileCtx.remote.dsmmProfiles);
2786
+ profileCtx.effect(() => () => controller.dispose(), "dsmm: profile editor");
2787
+ profileCtx.effect(() => profileCtx.locale.register(NS, { en, zh }), "dsmm: profile locale");
2788
+ profileCtx.effect(() => {
2789
+ const style = document.createElement("style");
2790
+ style.dataset.dsmmProfiles = "";
2791
+ style.textContent = PROFILE_STYLES;
2792
+ document.head.append(style);
2793
+ return () => style.remove();
2794
+ }, "dsmm: profile styles");
2795
+ const t = profileCtx.locale.bind(NS);
2796
+ profileCtx.slots.inject("settings.section", () => profileCtx.slots.register({
2797
+ name: "settings.section",
2798
+ id: "dsmm-profiles",
2799
+ order: 30,
2800
+ label: () => t("title"),
2801
+ locale: NS,
2802
+ inject: () => ({ hooks: { profiles: controller.store }, ...controller.actions })
2803
+ }, ProfilesSection));
2804
+ void profileCtx.inject(["remote.session"], (catalogCtx) => {
2805
+ controller.attachCatalog(catalogCtx.remote.session);
2806
+ catalogCtx.effect(() => () => controller.attachCatalog(null), "dsmm: native catalog lifetime");
2807
+ });
2808
+ void profileCtx.inject(["uiSession"], (sessionCtx) => {
2809
+ const source = sessionCtx.uiSession.adapter.current;
2810
+ const update = () => controller.setSession(source.getSnapshot().key ?? null);
2811
+ update();
2812
+ sessionCtx.effect(() => source.subscribe(update), "dsmm: current native session");
2813
+ sessionCtx.effect(() => () => controller.setSession(null), "dsmm: native session withdrawal");
2814
+ sessionCtx.slots.inject("conversation.session.header.utilities", () => sessionCtx.slots.register({
2815
+ name: "conversation.session.header.utilities",
2816
+ id: "dsmm-session-profiles",
2817
+ order: 30,
2818
+ locale: NS,
2819
+ inject: () => ({ hooks: { profiles: controller.store }, ...controller.actions })
2820
+ }, SessionProfiles));
2821
+ });
2822
+ void controller.refresh();
2823
+ });
2824
+ }
2825
+ return module.exports; } });