@dsmm/dsmm 0.1.4 → 0.1.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/README.md +13 -12
  2. package/docs/compatibility.md +8 -6
  3. package/docs/migration-from-ocmm.md +8 -0
  4. package/docs/model-routing.md +22 -6
  5. package/docs/profiles.md +23 -9
  6. package/docs/releasing.md +27 -15
  7. package/docs/runtime-recovery.md +41 -14
  8. package/docs/settings-status.md +10 -8
  9. package/lib/client/ProfilesSection.js +7 -3
  10. package/lib/client/SessionProfiles.d.ts +19 -0
  11. package/lib/client/SessionProfiles.js +55 -0
  12. package/lib/client/StructuredEditor.d.ts +11 -0
  13. package/lib/client/StructuredEditor.js +74 -0
  14. package/lib/client/controller.d.ts +68 -1
  15. package/lib/client/controller.js +282 -11
  16. package/lib/client/index.d.ts +3 -1
  17. package/lib/client/index.js +47 -0
  18. package/lib/client/locales.d.ts +109 -0
  19. package/lib/client/locales.js +56 -2
  20. package/lib/client/session-labels.d.ts +8 -0
  21. package/lib/client/session-labels.js +13 -0
  22. package/lib/client/structured.d.ts +18 -0
  23. package/lib/client/structured.js +98 -0
  24. package/lib/client/styles.d.ts +1 -1
  25. package/lib/client/styles.js +14 -1
  26. package/lib/client.js +1215 -74
  27. package/lib/commands.js +1 -0
  28. package/lib/dsh-types.d.ts +16 -0
  29. package/lib/index.js +27 -1
  30. package/lib/model-routing.js +109 -23
  31. package/lib/profile-remote.d.ts +7 -1
  32. package/lib/profile-remote.js +117 -2
  33. package/lib/profile-rpc.d.ts +9 -1
  34. package/lib/profile-rpc.js +99 -2
  35. package/lib/profile-runtime.d.ts +25 -5
  36. package/lib/profile-runtime.js +193 -31
  37. package/lib/profile-store.d.ts +19 -1
  38. package/lib/profile-store.js +120 -10
  39. package/lib/profile-types.d.ts +43 -1
  40. package/lib/profiles.d.ts +1 -1
  41. package/lib/profiles.js +34 -2
  42. package/lib/role-providers.js +12 -2
  43. package/lib/role-routing.d.ts +37 -3
  44. package/lib/role-routing.js +107 -35
  45. package/lib/routing-policy.d.ts +32 -0
  46. package/lib/routing-policy.js +92 -0
  47. package/lib/runtime-recovery.js +216 -52
  48. package/lib/settings.d.ts +27 -1
  49. package/lib/settings.js +29 -7
  50. package/lib/status.d.ts +10 -2
  51. package/lib/status.js +36 -10
  52. package/package.json +8 -1
@@ -1,5 +1,12 @@
1
- import { applyEdits, modify } from "jsonc-parser";
2
1
  import { isProfileId } from "../profile-remote.js";
2
+ import { editStructuredPath, moveFallback } from "./structured.js";
3
+ function modelSelectionWatermark(window) {
4
+ let watermark = -1;
5
+ for (const entry of window.entries)
6
+ if (entry.type === "event" && entry.event.type === "model/selection")
7
+ watermark = Math.max(watermark, Number(entry.event.seq));
8
+ return watermark;
9
+ }
3
10
  const NEW_EDITOR = "";
4
11
  export const 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';
5
12
  /** A valid external CAS conflict is reconcilable; corruption is never reset implicitly. */
@@ -10,11 +17,30 @@ export function canReconcileSelection(snapshot) {
10
17
  /** Stable native Store seat, with no filesystem or transport authority. */
11
18
  export class ProfilesController {
12
19
  remote;
13
- current = { snapshot: null, editor: null, dirty: false, busy: null, issue: null, notice: null, pendingEditor: null };
20
+ current = { snapshot: null, editor: null, dirty: false, busy: null, issue: null, notice: null, pendingEditor: null,
21
+ catalog: null, catalogBusy: false, catalogUnavailable: true, currentSessionId: null, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null, invalidFields: [], editorEpoch: 0 };
14
22
  accepted = null;
15
23
  listeners = new Set();
16
24
  generation = 0;
17
25
  disposed = false;
26
+ sessionGeneration = 0;
27
+ catalogGeneration = 0;
28
+ catalogRemote = null;
29
+ modelSelectorGeneration = 0;
30
+ modelSelector = null;
31
+ modelSelectionSource = null;
32
+ modelSelectionSessionId = null;
33
+ modelSelectionGeneration = 0;
34
+ stopModelSelection = null;
35
+ modelEvents = null;
36
+ modelEventsSessionId = null;
37
+ modelEventsGeneration = 0;
38
+ modelEventsWatermark = -1;
39
+ stopModelEvents = null;
40
+ modelInteraction = null;
41
+ modelInteractionSessionId = null;
42
+ modelInteractionGeneration = 0;
43
+ stopModelInteraction = null;
18
44
  store = {
19
45
  getSnapshot: () => this.current,
20
46
  subscribe: (listener) => {
@@ -27,11 +53,223 @@ export class ProfilesController {
27
53
  editId: (id) => this.editId(id), editContent: (content) => this.editContent(content),
28
54
  save: () => this.save(), apply: () => this.apply(), reset: () => this.reset(),
29
55
  discardAndOpen: () => this.discardAndOpen(), cancelDiscard: () => this.publish({ pendingEditor: null }),
56
+ editPath: (path, value) => this.editPath(path, value), moveFallback: (role, from, to) => this.editFallbackOrder(role, from, to),
57
+ editRoute: (path, provider, model) => this.editRoute(path, provider, model),
58
+ refreshCatalog: () => this.refreshCatalog(), refreshSession: () => this.refreshSession(),
59
+ chooseSessionProfile: (id) => { if (!this.disposed && this.current.sessionBusy === null && this.current.busy === null && !this.current.dirty)
60
+ this.publish({ sessionChoice: id, sessionNotice: null }); },
61
+ applySession: (options) => this.selectSession(false, options), resetSession: () => this.selectSession(true),
62
+ setFieldInvalid: (field, invalid) => {
63
+ if (this.disposed)
64
+ return;
65
+ const invalidFields = this.current.invalidFields.filter((candidate) => candidate !== field);
66
+ if (invalid)
67
+ invalidFields.push(field);
68
+ if (invalidFields.join("\n") !== this.current.invalidFields.join("\n"))
69
+ this.publish({ invalidFields, ...(invalid ? { dirty: true } : {}) });
70
+ },
30
71
  };
31
72
  constructor(remote) {
32
73
  this.remote = remote;
33
74
  }
34
- dispose() { this.disposed = true; this.generation += 1; this.listeners.clear(); }
75
+ dispose() { this.disposed = true; this.generation += 1; this.sessionGeneration += 1; this.catalogGeneration += 1; this.modelSelectorGeneration += 1; this.modelSelectionGeneration += 1; this.stopModelSelection?.(); this.stopModelEvents?.(); this.stopModelInteraction?.(); this.stopModelSelection = null; this.stopModelEvents = null; this.stopModelInteraction = null; this.modelSelectionSource = null; this.modelEvents = null; this.modelInteraction = null; this.catalogRemote = null; this.modelSelector = null; this.listeners.clear(); }
76
+ attachModelSelector(remote) {
77
+ if (this.disposed)
78
+ return;
79
+ this.modelSelectorGeneration += 1;
80
+ this.modelSelector = remote;
81
+ }
82
+ attachModelSelectionSource(sessionId, source) {
83
+ if (this.disposed || (sessionId === this.modelSelectionSessionId && source === this.modelSelectionSource))
84
+ return;
85
+ this.modelSelectionGeneration += 1;
86
+ this.stopModelSelection?.();
87
+ this.modelSelectionSessionId = sessionId;
88
+ this.modelSelectionSource = source;
89
+ this.stopModelSelection = source?.subscribe(() => { this.modelSelectionGeneration += 1; }) ?? null;
90
+ }
91
+ attachModelEventSource(sessionId, source) {
92
+ if (this.disposed || (sessionId === this.modelEventsSessionId && source === this.modelEvents))
93
+ return;
94
+ this.modelEventsGeneration += 1;
95
+ this.stopModelEvents?.();
96
+ this.modelEventsSessionId = sessionId;
97
+ this.modelEvents = source;
98
+ this.modelEventsWatermark = source === null ? -1 : modelSelectionWatermark(source.getSnapshot());
99
+ this.stopModelEvents = source?.subscribe(() => {
100
+ const window = source.getSnapshot(), change = window.change;
101
+ if (change.kind === "settle-assistant")
102
+ return;
103
+ let watermark = change.kind === "replace" ? -1 : this.modelEventsWatermark;
104
+ for (const entry of change.entries)
105
+ if (entry.type === "event" && entry.event.type === "model/selection")
106
+ watermark = Math.max(watermark, Number(entry.event.seq));
107
+ if (watermark !== this.modelEventsWatermark) {
108
+ this.modelEventsWatermark = watermark;
109
+ this.modelEventsGeneration += 1;
110
+ }
111
+ }) ?? null;
112
+ }
113
+ attachModelInteractionSource(sessionId, source) {
114
+ if (this.disposed || (sessionId === this.modelInteractionSessionId && source === this.modelInteraction))
115
+ return;
116
+ this.modelInteractionGeneration += 1;
117
+ this.stopModelInteraction?.();
118
+ this.modelInteractionSessionId = sessionId;
119
+ this.modelInteraction = source;
120
+ this.stopModelInteraction = source?.subscribe(() => { if (source.getSnapshot().status === "selecting")
121
+ this.modelInteractionGeneration += 1; }) ?? null;
122
+ }
123
+ attachCatalog(remote) {
124
+ if (this.disposed)
125
+ return;
126
+ this.catalogGeneration += 1;
127
+ this.catalogRemote = remote;
128
+ this.publish({ catalogBusy: false, catalogUnavailable: remote === null });
129
+ if (remote !== null)
130
+ void this.refreshCatalog();
131
+ }
132
+ setSession(id) {
133
+ if (this.disposed || id === this.current.currentSessionId)
134
+ return;
135
+ this.sessionGeneration += 1;
136
+ if (id !== this.modelSelectionSessionId)
137
+ this.attachModelSelectionSource(null, null);
138
+ if (id !== this.modelEventsSessionId)
139
+ this.attachModelEventSource(null, null);
140
+ if (id !== this.modelInteractionSessionId)
141
+ this.attachModelInteractionSource(null, null);
142
+ this.publish({ currentSessionId: id, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
143
+ if (id !== null)
144
+ void this.refreshSession();
145
+ }
146
+ async refreshCatalog() {
147
+ if (this.disposed || this.current.catalogBusy || this.catalogRemote === null)
148
+ return;
149
+ const remote = this.catalogRemote, generation = ++this.catalogGeneration;
150
+ this.publish({ catalogBusy: true });
151
+ try {
152
+ const catalog = await this.unwrap(remote.modelCatalog());
153
+ if (!this.disposed && generation === this.catalogGeneration)
154
+ this.publish({ catalog, catalogUnavailable: false });
155
+ }
156
+ catch {
157
+ if (!this.disposed && generation === this.catalogGeneration)
158
+ this.publish({ catalogUnavailable: true });
159
+ }
160
+ finally {
161
+ if (!this.disposed && generation === this.catalogGeneration)
162
+ this.publish({ catalogBusy: false });
163
+ }
164
+ }
165
+ async refreshSession() {
166
+ const id = this.current.currentSessionId;
167
+ if (this.disposed || id === null || this.current.sessionBusy !== null)
168
+ return;
169
+ const generation = ++this.sessionGeneration;
170
+ const live = () => !this.disposed && generation === this.sessionGeneration && id === this.current.currentSessionId;
171
+ this.publish({ sessionBusy: "read", sessionIssue: null, sessionNotice: null });
172
+ try {
173
+ const session = await this.unwrap(this.remote.describeSession(id));
174
+ if (session.sessionId !== id)
175
+ throw { kind: "assembly", code: "unavailable" };
176
+ if (live())
177
+ this.publish({ session, sessionChoice: session.selection.selectedId });
178
+ }
179
+ catch (error) {
180
+ if (live())
181
+ this.publish({ sessionIssue: this.issue(error) });
182
+ }
183
+ finally {
184
+ if (live())
185
+ this.publish({ sessionBusy: null });
186
+ }
187
+ }
188
+ async selectSession(reset, options) {
189
+ const { currentSessionId: id, session, sessionChoice, snapshot } = this.current;
190
+ if (this.disposed || id === null || session === null || !session.switchAllowed || this.current.sessionBusy !== null
191
+ || this.current.busy !== null || this.current.dirty || this.current.pendingEditor !== null)
192
+ return;
193
+ const selectedId = reset ? null : sessionChoice;
194
+ const revision = snapshot?.profiles.find((profile) => profile.id === selectedId)?.revision;
195
+ if (selectedId !== null && revision == null)
196
+ return;
197
+ const generation = ++this.sessionGeneration;
198
+ const useProfileModel = !reset && options?.useProfileModel === true;
199
+ const selector = this.modelSelector, selectorGeneration = this.modelSelectorGeneration;
200
+ const modelSource = this.modelSelectionSource, modelGeneration = this.modelSelectionGeneration;
201
+ const modelSnapshot = modelSource?.getSnapshot();
202
+ const eventSource = this.modelEvents, eventGeneration = this.modelEventsGeneration;
203
+ const eventWatermark = eventSource === null ? -1 : modelSelectionWatermark(eventSource.getSnapshot());
204
+ const interaction = this.modelInteraction, interactionGeneration = this.modelInteractionGeneration;
205
+ const pendingNativeChoice = interaction?.getSnapshot().status === "selecting";
206
+ const live = () => !this.disposed && generation === this.sessionGeneration && id === this.current.currentSessionId;
207
+ const selectorLive = () => live() && selector !== null && selector === this.modelSelector && selectorGeneration === this.modelSelectorGeneration;
208
+ this.publish({ sessionBusy: reset ? "reset" : "apply", sessionIssue: null, sessionNotice: null });
209
+ try {
210
+ const accepted = await this.unwrap(this.remote.selectSession(id, {
211
+ sessionId: id, id: selectedId, ...(selectedId === null ? {} : { expectedRevision: revision }),
212
+ expectedSelectionRevision: session.selection.selectionRevision, expectedAdmissionEpoch: session.admissionEpoch,
213
+ }));
214
+ if (accepted.sessionId !== id)
215
+ throw { kind: "assembly", code: "unavailable" };
216
+ if (!live())
217
+ return;
218
+ this.publish({ session: accepted, sessionChoice: accepted.selection.selectedId, sessionNotice: useProfileModel ? null : reset ? "reset" : "applied" });
219
+ if (!useProfileModel || !live())
220
+ return;
221
+ if (accepted.profileModel === undefined) {
222
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-unconfigured", source: "profile-model" } });
223
+ return;
224
+ }
225
+ if (!selectorLive()) {
226
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-service-unavailable", source: "profile-model" } });
227
+ return;
228
+ }
229
+ if (modelSource === null || modelSnapshot === undefined || this.modelSelectionSessionId !== id || modelSource !== this.modelSelectionSource || modelSource.getSnapshot() === undefined) {
230
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-observation-unavailable", source: "profile-model" } });
231
+ return;
232
+ }
233
+ // Projection fences cover observed view changes, including a frame whose
234
+ // notification has not fired. The raw sequence fence below covers deduped intent.
235
+ if (modelGeneration !== this.modelSelectionGeneration || !Object.is(modelSnapshot, modelSource.getSnapshot())) {
236
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-choice-changed", source: "profile-model" } });
237
+ return;
238
+ }
239
+ if (eventSource === null || eventSource !== this.modelEvents || this.modelEventsSessionId !== id
240
+ || interaction === null || interaction !== this.modelInteraction || this.modelInteractionSessionId !== id) {
241
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-observation-unavailable", source: "profile-model" } });
242
+ return;
243
+ }
244
+ if (eventGeneration !== this.modelEventsGeneration || eventWatermark !== modelSelectionWatermark(eventSource.getSnapshot())
245
+ || interactionGeneration !== this.modelInteractionGeneration || pendingNativeChoice || interaction.getSnapshot().status === "selecting") {
246
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-choice-changed", source: "profile-model" } });
247
+ return;
248
+ }
249
+ try {
250
+ // The accepted DTO and current native view have the same validated ID;
251
+ // native strict codecs remain authoritative for its branded wire type.
252
+ await this.unwrap(selector.selectModel({ sessionId: id, ...accepted.profileModel }));
253
+ // Never echo the returned model locally: native projections own the
254
+ // actual picker, and a later native Models-tab selection must win.
255
+ if (live())
256
+ this.publish(selectorLive() && modelSource === this.modelSelectionSource && this.modelSelectionSessionId === id ? { sessionNotice: "applied-with-model" }
257
+ : { sessionIssue: { kind: "assembly", code: "model-service-unavailable", source: "profile-model" } });
258
+ }
259
+ catch {
260
+ if (live())
261
+ this.publish({ sessionIssue: { kind: "assembly", code: selectorLive() ? "model-selection-failed" : "model-service-unavailable", source: "profile-model" } });
262
+ }
263
+ }
264
+ catch (error) {
265
+ if (live())
266
+ this.publish({ sessionIssue: this.issue(error) });
267
+ }
268
+ finally {
269
+ if (live())
270
+ this.publish({ sessionBusy: null });
271
+ }
272
+ }
35
273
  publish(patch) {
36
274
  if (this.disposed)
37
275
  return;
@@ -41,7 +279,7 @@ export class ProfilesController {
41
279
  }
42
280
  accept(document) {
43
281
  this.accepted = { ...document };
44
- this.publish({ editor: { ...document }, dirty: false, pendingEditor: null });
282
+ this.publish({ editor: { ...document }, dirty: false, pendingEditor: null, invalidFields: [], editorEpoch: this.current.editorEpoch + 1 });
45
283
  }
46
284
  async unwrap(request, field) {
47
285
  const result = await request;
@@ -61,7 +299,7 @@ export class ProfilesController {
61
299
  return { kind: "assembly", code: "unavailable" };
62
300
  }
63
301
  async perform(busy, operation) {
64
- if (this.disposed || this.current.busy !== null || this.current.pendingEditor !== null)
302
+ if (this.disposed || this.current.busy !== null || this.current.sessionBusy === "apply" || this.current.sessionBusy === "reset" || this.current.pendingEditor !== null)
65
303
  return;
66
304
  const generation = ++this.generation;
67
305
  const live = () => !this.disposed && generation === this.generation;
@@ -109,7 +347,7 @@ export class ProfilesController {
109
347
  async loadEditor(id) {
110
348
  if (id === NEW_EDITOR) {
111
349
  this.accepted = null;
112
- this.publish({ editor: { id: "new-profile", content: NEW_PROFILE_CONTENT, revision: null }, dirty: true, issue: null, notice: null, pendingEditor: null });
350
+ 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 });
113
351
  return;
114
352
  }
115
353
  await this.perform("read", async (live) => {
@@ -136,11 +374,11 @@ export class ProfilesController {
136
374
  const editor = this.current.editor;
137
375
  if (editor === null || editor.revision !== null || this.current.busy !== null || this.current.pendingEditor !== null)
138
376
  return;
139
- let content = editor.content;
140
- try {
141
- content = applyEdits(content, modify(content, ["id"], id, { formattingOptions: { insertSpaces: true, tabSize: 2 } }));
377
+ const content = editStructuredPath(editor.content, ["id"], id);
378
+ if (content === null) {
379
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
380
+ return;
142
381
  }
143
- catch { /* Keep invalid JSONC intact; the Host explains validation on save. */ }
144
382
  this.publish({ editor: { ...editor, id, content }, dirty: true, issue: null, notice: null });
145
383
  }
146
384
  editContent(content) {
@@ -149,9 +387,42 @@ export class ProfilesController {
149
387
  return;
150
388
  this.publish({ editor: { ...editor, content }, dirty: this.accepted === null || this.accepted.content !== content || this.accepted.id !== editor.id, issue: null, notice: null });
151
389
  }
390
+ editPath(path, value) {
391
+ const editor = this.current.editor;
392
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null)
393
+ return;
394
+ const content = editStructuredPath(editor.content, path, value);
395
+ if (content === null) {
396
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
397
+ return;
398
+ }
399
+ this.editContent(content);
400
+ }
401
+ editRoute(path, provider, model) {
402
+ const editor = this.current.editor;
403
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null)
404
+ return;
405
+ let content = editor.content;
406
+ for (const [key, value] of [["provider", provider], ["model", model], ["reasoningEffort", undefined]]) {
407
+ content = editStructuredPath(content, [...path, key], value);
408
+ if (content === null) {
409
+ this.publish({ issue: { kind: "domain", code: "validation", field: "content" }, notice: null });
410
+ return;
411
+ }
412
+ }
413
+ this.editContent(content);
414
+ }
415
+ editFallbackOrder(role, from, to) {
416
+ const editor = this.current.editor;
417
+ if (editor === null || this.current.busy !== null || this.current.pendingEditor !== null)
418
+ return;
419
+ const content = moveFallback(editor.content, role, from, to);
420
+ if (content !== null)
421
+ this.editContent(content);
422
+ }
152
423
  async save() {
153
424
  const editor = this.current.editor;
154
- if (editor === null || !this.current.dirty || this.current.snapshot === null || this.current.busy !== null || this.current.pendingEditor !== null)
425
+ if (editor === null || !this.current.dirty || this.current.snapshot === null || this.current.busy !== null || this.current.pendingEditor !== null || this.current.invalidFields.length > 0)
155
426
  return;
156
427
  if (!isProfileId(editor.id)) {
157
428
  this.publish({ issue: { kind: "domain", code: "validation", field: "id" }, notice: null });
@@ -1,10 +1,12 @@
1
1
  import type { Context } from "@deepseek-ai/cordis";
2
2
  export { ProfilesController, NEW_PROFILE_CONTENT } from "./controller.js";
3
- export type { ProfilesActions, ProfilesViewSnapshot, ProfilesIssue } from "./controller.js";
3
+ export type { ProfilesActions, ProfilesViewSnapshot, ProfilesIssue, SessionApplyOptions, ProfileModelSelectorRemote } from "./controller.js";
4
4
  export { ProfilesSection } from "./ProfilesSection.js";
5
5
  export type { ProfilesSectionProps, ProfilesInjected } from "./ProfilesSection.js";
6
6
  export { NS, en, zh } from "./locales.js";
7
7
  export { TYPERT_REMOTE } from "../profile-remote.js";
8
+ export { SessionProfiles } from "./SessionProfiles.js";
9
+ export { structuredDocument, editStructuredPath, moveFallback } from "./structured.js";
8
10
  /** No self-dependency on a namespace that this contribution has not mounted. */
9
11
  export declare const inject: readonly ["slots", "locale", "remote"];
10
12
  export declare function apply(ctx: Context): Promise<void>;
@@ -3,10 +3,13 @@ import { ProfilesController } from "./controller.js";
3
3
  import { NS, en, zh } from "./locales.js";
4
4
  import { ProfilesSection } from "./ProfilesSection.js";
5
5
  import { PROFILE_STYLES } from "./styles.js";
6
+ import { SessionProfiles } from "./SessionProfiles.js";
6
7
  export { ProfilesController, NEW_PROFILE_CONTENT } from "./controller.js";
7
8
  export { ProfilesSection } from "./ProfilesSection.js";
8
9
  export { NS, en, zh } from "./locales.js";
9
10
  export { TYPERT_REMOTE } from "../profile-remote.js";
11
+ export { SessionProfiles } from "./SessionProfiles.js";
12
+ export { structuredDocument, editStructuredPath, moveFallback } from "./structured.js";
10
13
  /** No self-dependency on a namespace that this contribution has not mounted. */
11
14
  export const inject = ["slots", "locale", "remote"];
12
15
  export async function apply(ctx) {
@@ -28,6 +31,50 @@ export async function apply(ctx) {
28
31
  label: () => t("title"), locale: NS,
29
32
  inject: () => ({ hooks: { profiles: controller.store }, ...controller.actions }),
30
33
  }, ProfilesSection));
34
+ // Optional native services have their own lifetime. Do not await them or
35
+ // make sessionless Settings depend on a Conversation/session provider.
36
+ void profileCtx.inject(["remote.session"], (catalogCtx) => {
37
+ controller.attachCatalog(catalogCtx.remote.session);
38
+ controller.attachModelSelector(catalogCtx.remote.session);
39
+ catalogCtx.effect(() => () => { controller.attachModelSelector(null); controller.attachCatalog(null); }, "dsmm: native catalog/selector lifetime");
40
+ });
41
+ void profileCtx.inject(["uiSession", "sessions"], (sessionCtx) => {
42
+ const source = sessionCtx.uiSession.adapter.current;
43
+ // This adapter compiles with both Host and Client Cordis declarations;
44
+ // the injected browser service has the public Client Sessions face.
45
+ const nativeSessions = sessionCtx.sessions;
46
+ const update = () => {
47
+ const binding = source.getSnapshot();
48
+ controller.setSession(binding.key ?? null);
49
+ controller.attachModelSelectionSource(binding.key ?? null, binding.key === undefined ? null : binding.keyedHooks.projection?.("modelSelection") ?? null);
50
+ controller.attachModelEventSource(binding.key ?? null, binding.key === undefined ? null : nativeSessions.binding(binding.key)?.eventSource ?? null);
51
+ };
52
+ update();
53
+ sessionCtx.effect(() => source.subscribe(update), "dsmm: current native session");
54
+ sessionCtx.effect(() => () => { controller.attachModelSelectionSource(null, null); controller.attachModelEventSource(null, null); controller.attachModelInteractionSource(null, null); controller.setSession(null); }, "dsmm: native session withdrawal");
55
+ void sessionCtx.inject(["modelDirectories", "remote.session"], (modelCtx) => {
56
+ const updateInteraction = () => {
57
+ const id = source.getSnapshot().key;
58
+ if (id === undefined || nativeSessions.binding(id) === undefined) {
59
+ controller.attachModelInteractionSource(null, null);
60
+ return;
61
+ }
62
+ try {
63
+ controller.attachModelInteractionSource(id, modelCtx.modelDirectories.directoryFor(id).store);
64
+ }
65
+ catch {
66
+ controller.attachModelInteractionSource(null, null);
67
+ } // An ended native scope fails closed for the optional model stage.
68
+ };
69
+ updateInteraction();
70
+ modelCtx.effect(() => source.subscribe(updateInteraction), "dsmm: native model interaction binding");
71
+ modelCtx.effect(() => () => controller.attachModelInteractionSource(null, null), "dsmm: native model interaction withdrawal");
72
+ });
73
+ sessionCtx.slots.inject("conversation.session.header.utilities", () => sessionCtx.slots.register({
74
+ name: "conversation.session.header.utilities", id: "dsmm-session-profiles", order: 30, locale: NS,
75
+ inject: () => ({ hooks: { profiles: controller.store }, ...controller.actions }),
76
+ }, SessionProfiles));
77
+ });
31
78
  void controller.refresh();
32
79
  });
33
80
  }
@@ -45,9 +45,118 @@ export declare const en: {
45
45
  invalidProfile: string;
46
46
  details: string;
47
47
  retry: string;
48
+ globalScope: string;
49
+ sessionScope: string;
50
+ sessionSelect: string;
51
+ globalActionHint: string;
52
+ headerProfile: string;
53
+ headerProfileLabel: string;
54
+ headerCaptured: string;
55
+ headerSavedUnavailable: string;
56
+ headerLoading: string;
57
+ headerApplying: string;
58
+ headerApplied: string;
59
+ headerBusy: string;
60
+ headerUnavailable: string;
61
+ headerDraft: string;
62
+ headerConflict: string;
63
+ headerRefused: string;
64
+ headerKeepModelGroup: string;
65
+ headerUseModelGroup: string;
66
+ headerModelDefaultHint: string;
67
+ headerNoProfileModel: string;
68
+ headerModelUnconfirmed: string;
69
+ headerAppliedWithModel: string;
70
+ headerModelChoiceChanged: string;
71
+ noSession: string;
72
+ sessionUnavailable: string;
73
+ sessionBusy: string;
74
+ sessionState: string;
75
+ sessionBaseline: string;
76
+ sessionGlobalCaptured: string;
77
+ sessionAdmittedProfile: string;
78
+ sessionFutureDefault: string;
79
+ sessionConflict: string;
80
+ sessionApply: string;
81
+ sessionApplying: string;
82
+ sessionReset: string;
83
+ sessionResetting: string;
84
+ sessionRefresh: string;
85
+ sessionApplied: string;
86
+ sessionResetDone: string;
87
+ sessionAppliedWithModel: string;
88
+ sessionDirty: string;
89
+ roleState: string;
90
+ catalogTitle: string;
91
+ catalogHint: string;
92
+ catalogUnavailable: string;
93
+ catalogRefresh: string;
94
+ catalogRefreshing: string;
95
+ catalogFailure: string;
96
+ profileLabel: string;
97
+ defaultActive: string;
98
+ activeHint: string;
99
+ enabled: string;
100
+ disabled: string;
101
+ inherit: string;
102
+ profileDefaults: string;
103
+ roleSelect: string;
104
+ rolesUnavailable: string;
105
+ roleEnabled: string;
106
+ roleDisabled: string;
107
+ strategy: string;
108
+ inheritStrategy: string;
109
+ startupLock: string;
110
+ rateFallback: string;
111
+ strategyHint: string;
112
+ retryField: string;
113
+ inheritNumber: string;
114
+ retryBounds: string;
115
+ unknownDefault: string;
116
+ retryCount: string;
117
+ initialDelay: string;
118
+ maxDelay: string;
119
+ totalWait: string;
120
+ switchThreshold: string;
121
+ maxSwitches: string;
122
+ primaryMode: string;
123
+ inheritRoute: string;
124
+ configuredRoute: string;
125
+ primaryName: string;
126
+ fallbackMode: string;
127
+ inheritChain: string;
128
+ configuredChain: string;
129
+ emptyChain: string;
130
+ fallbackName: string;
131
+ addFallback: string;
132
+ removeFallback: string;
133
+ moveUp: string;
134
+ moveDown: string;
135
+ routeProvider: string;
136
+ routeModel: string;
137
+ routeEffort: string;
138
+ manualProvider: string;
139
+ manualModel: string;
140
+ manualEffort: string;
141
+ manual: string;
142
+ manualValue: string;
143
+ unset: string;
144
+ effortDefault: string;
145
+ effortChangeHint: string;
146
+ advanced: string;
147
+ rawInvalid: string;
148
+ invalidNumber: string;
48
149
  };
49
150
  export type ProfilesLocaleKey = keyof typeof en;
50
151
  export declare const zh: Record<ProfilesLocaleKey, string>;
152
+ export declare const RETRY_FIELD_LABEL_KEYS: {
153
+ readonly maxRetries: "retryCount";
154
+ readonly initialDelayMs: "initialDelay";
155
+ readonly maxDelayMs: "maxDelay";
156
+ readonly maxTotalDelayMs: "totalWait";
157
+ readonly switchAfterRateLimits: "switchThreshold";
158
+ readonly maxSwitches: "maxSwitches";
159
+ };
51
160
  declare module "@deepseek-ai/dsh-client-ui-slots" {
52
161
  interface LocaleNamespaceMap {
53
162
  "settings.dsmm-profiles": ProfilesLocaleKey;