@dsmm/dsmm 0.1.5 → 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.
package/lib/client.js CHANGED
@@ -204,21 +204,22 @@ function rolePolicy(value) {
204
204
  switches: integer(item.switches, "switches", 10),
205
205
  totalDelayMs: integer(item.totalDelayMs, "totalDelayMs", 12e4),
206
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
- })
207
+ ...optional(item, "route", modelRoute)
214
208
  };
215
209
  }
210
+ function modelRoute(value) {
211
+ const route2 = object(value, ["provider", "model"], ["reasoningEffort"]);
212
+ const provider = routeText(route2.provider, "provider", 128);
213
+ const model = routeText(route2.model, "model", 512);
214
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/u.test(provider) || model.includes("://")) fail("route");
215
+ return { provider, model, ...optional(route2, "reasoningEffort", (input) => routeText(input, "reasoningEffort", 64)) };
216
+ }
216
217
  function selectionState(value) {
217
218
  const item = object(value, ["selectedId", "appliedRevision", "selectionRevision"]);
218
219
  return { selectedId: item.selectedId === null ? null : id(item.selectedId), appliedRevision: item.appliedRevision === null ? null : revision(item.appliedRevision), selectionRevision: selectionRevision(item.selectionRevision) };
219
220
  }
220
221
  function sessionSnapshot(value) {
221
- const item = object(value, ["sessionId", "globalDefault", "selection", "scope", "admissionEpoch", "switchAllowed"], ["admittedSelection", "switchUnavailableReason", "rolePolicy"]);
222
+ const item = object(value, ["sessionId", "globalDefault", "selection", "scope", "admissionEpoch", "switchAllowed"], ["admittedSelection", "switchUnavailableReason", "rolePolicy", "profileModel"]);
222
223
  if (typeof item.scope !== "string" || !["global-default", "session-override", "deployment-baseline"].includes(item.scope)) fail("scope");
223
224
  return {
224
225
  sessionId: sessionId(item.sessionId),
@@ -232,7 +233,8 @@ function sessionSnapshot(value) {
232
233
  if (typeof input !== "string" || !["busy", "maintenance", "disposed", "not-owned", "unavailable"].includes(input)) fail("switchUnavailableReason");
233
234
  return input;
234
235
  }),
235
- ...optional(item, "rolePolicy", rolePolicy)
236
+ ...optional(item, "rolePolicy", rolePolicy),
237
+ ...optional(item, "profileModel", modelRoute)
236
238
  };
237
239
  }
238
240
  function saveRequest(value) {
@@ -1729,6 +1731,11 @@ function moveFallback(content2, role2, from, to) {
1729
1731
  }
1730
1732
 
1731
1733
  // src/client/controller.ts
1734
+ function modelSelectionWatermark(window) {
1735
+ let watermark = -1;
1736
+ for (const entry of window.entries) if (entry.type === "event" && entry.event.type === "model/selection") watermark = Math.max(watermark, Number(entry.event.seq));
1737
+ return watermark;
1738
+ }
1732
1739
  var NEW_EDITOR = "";
1733
1740
  var NEW_PROFILE_CONTENT = '{\n "version": 1,\n "id": "new-profile",\n "label": "New profile",\n "settings": {\n // Runtime overlay only. Omitted fields inherit the deployment baseline.\n "defaultActive": true\n }\n}\n';
1734
1741
  function canReconcileSelection(snapshot2) {
@@ -1765,6 +1772,21 @@ var ProfilesController = class {
1765
1772
  sessionGeneration = 0;
1766
1773
  catalogGeneration = 0;
1767
1774
  catalogRemote = null;
1775
+ modelSelectorGeneration = 0;
1776
+ modelSelector = null;
1777
+ modelSelectionSource = null;
1778
+ modelSelectionSessionId = null;
1779
+ modelSelectionGeneration = 0;
1780
+ stopModelSelection = null;
1781
+ modelEvents = null;
1782
+ modelEventsSessionId = null;
1783
+ modelEventsGeneration = 0;
1784
+ modelEventsWatermark = -1;
1785
+ stopModelEvents = null;
1786
+ modelInteraction = null;
1787
+ modelInteractionSessionId = null;
1788
+ modelInteractionGeneration = 0;
1789
+ stopModelInteraction = null;
1768
1790
  store = {
1769
1791
  getSnapshot: () => this.current,
1770
1792
  subscribe: (listener) => {
@@ -1794,7 +1816,7 @@ var ProfilesController = class {
1794
1816
  chooseSessionProfile: (id2) => {
1795
1817
  if (!this.disposed && this.current.sessionBusy === null && this.current.busy === null && !this.current.dirty) this.publish({ sessionChoice: id2, sessionNotice: null });
1796
1818
  },
1797
- applySession: () => this.selectSession(false),
1819
+ applySession: (options) => this.selectSession(false, options),
1798
1820
  resetSession: () => this.selectSession(true),
1799
1821
  setFieldInvalid: (field, invalid) => {
1800
1822
  if (this.disposed) return;
@@ -1808,9 +1830,64 @@ var ProfilesController = class {
1808
1830
  this.generation += 1;
1809
1831
  this.sessionGeneration += 1;
1810
1832
  this.catalogGeneration += 1;
1833
+ this.modelSelectorGeneration += 1;
1834
+ this.modelSelectionGeneration += 1;
1835
+ this.stopModelSelection?.();
1836
+ this.stopModelEvents?.();
1837
+ this.stopModelInteraction?.();
1838
+ this.stopModelSelection = null;
1839
+ this.stopModelEvents = null;
1840
+ this.stopModelInteraction = null;
1841
+ this.modelSelectionSource = null;
1842
+ this.modelEvents = null;
1843
+ this.modelInteraction = null;
1811
1844
  this.catalogRemote = null;
1845
+ this.modelSelector = null;
1812
1846
  this.listeners.clear();
1813
1847
  }
1848
+ attachModelSelector(remote) {
1849
+ if (this.disposed) return;
1850
+ this.modelSelectorGeneration += 1;
1851
+ this.modelSelector = remote;
1852
+ }
1853
+ attachModelSelectionSource(sessionId2, source) {
1854
+ if (this.disposed || sessionId2 === this.modelSelectionSessionId && source === this.modelSelectionSource) return;
1855
+ this.modelSelectionGeneration += 1;
1856
+ this.stopModelSelection?.();
1857
+ this.modelSelectionSessionId = sessionId2;
1858
+ this.modelSelectionSource = source;
1859
+ this.stopModelSelection = source?.subscribe(() => {
1860
+ this.modelSelectionGeneration += 1;
1861
+ }) ?? null;
1862
+ }
1863
+ attachModelEventSource(sessionId2, source) {
1864
+ if (this.disposed || sessionId2 === this.modelEventsSessionId && source === this.modelEvents) return;
1865
+ this.modelEventsGeneration += 1;
1866
+ this.stopModelEvents?.();
1867
+ this.modelEventsSessionId = sessionId2;
1868
+ this.modelEvents = source;
1869
+ this.modelEventsWatermark = source === null ? -1 : modelSelectionWatermark(source.getSnapshot());
1870
+ this.stopModelEvents = source?.subscribe(() => {
1871
+ const window = source.getSnapshot(), change = window.change;
1872
+ if (change.kind === "settle-assistant") return;
1873
+ let watermark = change.kind === "replace" ? -1 : this.modelEventsWatermark;
1874
+ for (const entry of change.entries) if (entry.type === "event" && entry.event.type === "model/selection") watermark = Math.max(watermark, Number(entry.event.seq));
1875
+ if (watermark !== this.modelEventsWatermark) {
1876
+ this.modelEventsWatermark = watermark;
1877
+ this.modelEventsGeneration += 1;
1878
+ }
1879
+ }) ?? null;
1880
+ }
1881
+ attachModelInteractionSource(sessionId2, source) {
1882
+ if (this.disposed || sessionId2 === this.modelInteractionSessionId && source === this.modelInteraction) return;
1883
+ this.modelInteractionGeneration += 1;
1884
+ this.stopModelInteraction?.();
1885
+ this.modelInteractionSessionId = sessionId2;
1886
+ this.modelInteraction = source;
1887
+ this.stopModelInteraction = source?.subscribe(() => {
1888
+ if (source.getSnapshot().status === "selecting") this.modelInteractionGeneration += 1;
1889
+ }) ?? null;
1890
+ }
1814
1891
  attachCatalog(remote) {
1815
1892
  if (this.disposed) return;
1816
1893
  this.catalogGeneration += 1;
@@ -1821,6 +1898,9 @@ var ProfilesController = class {
1821
1898
  setSession(id2) {
1822
1899
  if (this.disposed || id2 === this.current.currentSessionId) return;
1823
1900
  this.sessionGeneration += 1;
1901
+ if (id2 !== this.modelSelectionSessionId) this.attachModelSelectionSource(null, null);
1902
+ if (id2 !== this.modelEventsSessionId) this.attachModelEventSource(null, null);
1903
+ if (id2 !== this.modelInteractionSessionId) this.attachModelInteractionSource(null, null);
1824
1904
  this.publish({ currentSessionId: id2, session: null, sessionChoice: null, sessionBusy: null, sessionIssue: null, sessionNotice: null });
1825
1905
  if (id2 !== null) void this.refreshSession();
1826
1906
  }
@@ -1853,14 +1933,23 @@ var ProfilesController = class {
1853
1933
  if (live()) this.publish({ sessionBusy: null });
1854
1934
  }
1855
1935
  }
1856
- async selectSession(reset) {
1936
+ async selectSession(reset, options) {
1857
1937
  const { currentSessionId: id2, session, sessionChoice, snapshot: snapshot2 } = this.current;
1858
1938
  if (this.disposed || id2 === null || session === null || !session.switchAllowed || this.current.sessionBusy !== null || this.current.busy !== null || this.current.dirty || this.current.pendingEditor !== null) return;
1859
1939
  const selectedId = reset ? null : sessionChoice;
1860
1940
  const revision2 = snapshot2?.profiles.find((profile) => profile.id === selectedId)?.revision;
1861
1941
  if (selectedId !== null && revision2 == null) return;
1862
1942
  const generation = ++this.sessionGeneration;
1943
+ const useProfileModel = !reset && options?.useProfileModel === true;
1944
+ const selector = this.modelSelector, selectorGeneration = this.modelSelectorGeneration;
1945
+ const modelSource = this.modelSelectionSource, modelGeneration = this.modelSelectionGeneration;
1946
+ const modelSnapshot = modelSource?.getSnapshot();
1947
+ const eventSource = this.modelEvents, eventGeneration = this.modelEventsGeneration;
1948
+ const eventWatermark = eventSource === null ? -1 : modelSelectionWatermark(eventSource.getSnapshot());
1949
+ const interaction = this.modelInteraction, interactionGeneration = this.modelInteractionGeneration;
1950
+ const pendingNativeChoice = interaction?.getSnapshot().status === "selecting";
1863
1951
  const live = () => !this.disposed && generation === this.sessionGeneration && id2 === this.current.currentSessionId;
1952
+ const selectorLive = () => live() && selector !== null && selector === this.modelSelector && selectorGeneration === this.modelSelectorGeneration;
1864
1953
  this.publish({ sessionBusy: reset ? "reset" : "apply", sessionIssue: null, sessionNotice: null });
1865
1954
  try {
1866
1955
  const accepted = await this.unwrap(this.remote.selectSession(id2, {
@@ -1871,7 +1960,39 @@ var ProfilesController = class {
1871
1960
  expectedAdmissionEpoch: session.admissionEpoch
1872
1961
  }));
1873
1962
  if (accepted.sessionId !== id2) throw { kind: "assembly", code: "unavailable" };
1874
- if (live()) this.publish({ session: accepted, sessionChoice: accepted.selection.selectedId, sessionNotice: reset ? "reset" : "applied" });
1963
+ if (!live()) return;
1964
+ this.publish({ session: accepted, sessionChoice: accepted.selection.selectedId, sessionNotice: useProfileModel ? null : reset ? "reset" : "applied" });
1965
+ if (!useProfileModel || !live()) return;
1966
+ if (accepted.profileModel === void 0) {
1967
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-unconfigured", source: "profile-model" } });
1968
+ return;
1969
+ }
1970
+ if (!selectorLive()) {
1971
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-service-unavailable", source: "profile-model" } });
1972
+ return;
1973
+ }
1974
+ if (modelSource === null || modelSnapshot === void 0 || this.modelSelectionSessionId !== id2 || modelSource !== this.modelSelectionSource || modelSource.getSnapshot() === void 0) {
1975
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-observation-unavailable", source: "profile-model" } });
1976
+ return;
1977
+ }
1978
+ if (modelGeneration !== this.modelSelectionGeneration || !Object.is(modelSnapshot, modelSource.getSnapshot())) {
1979
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-choice-changed", source: "profile-model" } });
1980
+ return;
1981
+ }
1982
+ if (eventSource === null || eventSource !== this.modelEvents || this.modelEventsSessionId !== id2 || interaction === null || interaction !== this.modelInteraction || this.modelInteractionSessionId !== id2) {
1983
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-observation-unavailable", source: "profile-model" } });
1984
+ return;
1985
+ }
1986
+ if (eventGeneration !== this.modelEventsGeneration || eventWatermark !== modelSelectionWatermark(eventSource.getSnapshot()) || interactionGeneration !== this.modelInteractionGeneration || pendingNativeChoice || interaction.getSnapshot().status === "selecting") {
1987
+ this.publish({ sessionIssue: { kind: "assembly", code: "model-choice-changed", source: "profile-model" } });
1988
+ return;
1989
+ }
1990
+ try {
1991
+ await this.unwrap(selector.selectModel({ sessionId: id2, ...accepted.profileModel }));
1992
+ if (live()) this.publish(selectorLive() && modelSource === this.modelSelectionSource && this.modelSelectionSessionId === id2 ? { sessionNotice: "applied-with-model" } : { sessionIssue: { kind: "assembly", code: "model-service-unavailable", source: "profile-model" } });
1993
+ } catch {
1994
+ if (live()) this.publish({ sessionIssue: { kind: "assembly", code: selectorLive() ? "model-selection-failed" : "model-service-unavailable", source: "profile-model" } });
1995
+ }
1875
1996
  } catch (error) {
1876
1997
  if (live()) this.publish({ sessionIssue: this.issue(error) });
1877
1998
  } finally {
@@ -2101,6 +2222,25 @@ var en = {
2101
2222
  sessionScope: "Current native session",
2102
2223
  sessionSelect: "Current-session profile",
2103
2224
  globalActionHint: "Apply saved profile below changes the global default for future unscoped sessions only. It does not apply to the current session.",
2225
+ headerProfile: "Profile",
2226
+ headerProfileLabel: "Current-session profile (header)",
2227
+ headerCaptured: "captured global default",
2228
+ headerSavedUnavailable: "saved profile unavailable",
2229
+ headerLoading: "Loading profile…",
2230
+ headerApplying: "Applying profile…",
2231
+ headerApplied: "Profile applied.",
2232
+ headerBusy: "Session is busy.",
2233
+ headerUnavailable: "Profile unavailable.",
2234
+ headerDraft: "Save or discard the draft in Settings.",
2235
+ headerConflict: "Profile changed elsewhere. Refresh in Settings.",
2236
+ headerRefused: "Profile change unconfirmed. Check Settings.",
2237
+ headerKeepModelGroup: "Switch profile — keep current model",
2238
+ headerUseModelGroup: "Switch and use profile model",
2239
+ headerModelDefaultHint: "Normal switching preserves the current model. Explicit switch-and-use-model also saves the native model default, like the Models tab.",
2240
+ headerNoProfileModel: "Profile applied; no main model configured. Current model kept.",
2241
+ headerModelUnconfirmed: "Profile applied; model change unconfirmed. Check Models/Settings.",
2242
+ headerAppliedWithModel: "Profile and native model applied.",
2243
+ headerModelChoiceChanged: "Profile applied; newer native model choice kept.",
2104
2244
  noSession: "No native session is selected. Session Apply is disabled; global defaults and drafts remain editable.",
2105
2245
  sessionUnavailable: "The current session could not be confirmed. Refresh its state before retrying; the prior policy is kept.",
2106
2246
  sessionBusy: "Switching is unavailable: {reason}. The Host must reserve a truly idle ordinary session before applying.",
@@ -2117,6 +2257,7 @@ var en = {
2117
2257
  sessionRefresh: "Refresh current-session state",
2118
2258
  sessionApplied: "Applied the saved revision to this session only. Global default and existing children were not changed.",
2119
2259
  sessionResetDone: "Pinned the deployment baseline for this session only. Global default was not changed.",
2260
+ sessionAppliedWithModel: "Applied this session profile and explicitly selected its native main model. Native model-default persistence follows the Models tab; the global profile default was not changed.",
2120
2261
  sessionDirty: "Save or explicitly discard the editor draft before applying a current-session choice.",
2121
2262
  roleState: "Admitted route {route}; strategy {strategy}; retries {retries}; rate-limit failures {failures}; switches {switches}; total delay {delay} ms.",
2122
2263
  catalogTitle: "Native model catalog",
@@ -2229,6 +2370,25 @@ var zh = {
2229
2370
  sessionScope: "当前原生会话",
2230
2371
  sessionSelect: "当前会话配置档",
2231
2372
  globalActionHint: "下方应用已保存配置档仅改变未来没有独立选择的会话的全局默认值,不会应用到当前会话。",
2373
+ headerProfile: "配置档",
2374
+ headerProfileLabel: "当前会话配置档(会话栏)",
2375
+ headerCaptured: "已捕获的全局默认值",
2376
+ headerSavedUnavailable: "保存的配置档不可用",
2377
+ headerLoading: "加载配置档…",
2378
+ headerApplying: "应用配置档…",
2379
+ headerApplied: "配置档已应用。",
2380
+ headerBusy: "会话忙碌。",
2381
+ headerUnavailable: "配置档不可用。",
2382
+ headerDraft: "请在设置中保存或丢弃草稿。",
2383
+ headerConflict: "配置档已在其他位置改变,请在设置中刷新。",
2384
+ headerRefused: "未确认配置档更改,请检查设置。",
2385
+ headerKeepModelGroup: "切换配置档 — 保留当前模型",
2386
+ headerUseModelGroup: "切换并使用配置档模型",
2387
+ headerModelDefaultHint: "普通切换保留当前模型。明确切换并使用模型还会像模型页一样保存原生模型默认值。",
2388
+ headerNoProfileModel: "配置档已应用,未配置主模型。当前模型已保留。",
2389
+ headerModelUnconfirmed: "配置档已应用,模型更改未确认。请检查模型或设置页。",
2390
+ headerAppliedWithModel: "配置档和原生模型已应用。",
2391
+ headerModelChoiceChanged: "配置档已应用,已保留更新的原生模型选择。",
2232
2392
  noSession: "未选择原生会话。会话应用已禁用;仍可编辑全局默认值和草稿。",
2233
2393
  sessionUnavailable: "无法确认当前会话。重试前请刷新状态;原策略已保留。",
2234
2394
  sessionBusy: "暂不可切换:{reason}。Host 必须先保留真正空闲的普通会话。",
@@ -2246,6 +2406,7 @@ var zh = {
2246
2406
  sessionApplied: "已仅对此会话应用保存的修订。全局默认值和已有子会话未改变。",
2247
2407
  sessionResetDone: "已仅对此会话固定部署基线。全局默认值未改变。",
2248
2408
  sessionDirty: "应用当前会话选择之前,请保存或明确丢弃编辑器草稿。",
2409
+ sessionAppliedWithModel: "已应用此会话配置档,并明确选择其原生主模型。模型默认值像模型页一样保存;全局配置档默认值未改变。",
2249
2410
  roleState: "准入路由 {route};策略 {strategy};重试 {retries};限流失败 {failures};切换 {switches};累计延迟 {delay} 毫秒。",
2250
2411
  catalogTitle: "原生模型目录",
2251
2412
  catalogHint: "目录仅供参考,不是网络或账户健康检查。未列出或手动路由仍可编辑;刷新不会改变草稿或原生模型默认值。",
@@ -2550,7 +2711,7 @@ function SessionScope({ state, actions, t, compact = false }) {
2550
2711
  const selected = state.snapshot?.profiles.find((profile) => profile.id === state.sessionChoice);
2551
2712
  const disabled = state.busy !== null || state.pendingEditor !== null || state.sessionBusy !== null || state.dirty;
2552
2713
  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");
2714
+ const status = state.sessionNotice === null ? "" : t(state.sessionNotice === "applied-with-model" ? "sessionAppliedWithModel" : state.sessionNotice === "applied" ? "sessionApplied" : "sessionResetDone");
2554
2715
  return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-session-scope", "aria-busy": state.sessionBusy !== null, "data-dsmm-session-scope": true, children: [
2555
2716
  !compact && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("h3", { children: t("sessionScope") }),
2556
2717
  state.currentSessionId === null ? /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-hint", children: t("noSession") }) : /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)(import_jsx_runtime2.Fragment, { children: [
@@ -2579,17 +2740,68 @@ function SessionScope({ state, actions, t, compact = false }) {
2579
2740
  ] }),
2580
2741
  !compact && session?.rolePolicy !== void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { "data-dsmm-session-policy": true, children: t("roleState", { route: session.rolePolicy.route === void 0 ? t("inheritRoute") : `${session.rolePolicy.route.provider}/${session.rolePolicy.route.model}${session.rolePolicy.route.reasoningEffort === void 0 ? "" : ` (${session.rolePolicy.route.reasoningEffort})`}`, strategy: session.rolePolicy.strategy, retries: session.rolePolicy.retries, failures: session.rolePolicy.rateLimitFailures, switches: session.rolePolicy.switches, delay: session.rolePolicy.totalDelayMs }) })
2581
2742
  ] }),
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") }),
2743
+ state.sessionIssue !== null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { role: "alert", children: state.sessionIssue.source === "profile-model" ? t(state.sessionIssue.code === "model-unconfigured" ? "headerNoProfileModel" : state.sessionIssue.code === "model-choice-changed" ? "headerModelChoiceChanged" : "headerModelUnconfirmed") : state.sessionIssue.code === "conflict" ? t("sessionConflict") : ["busy", "maintenance", "disposed", "not-owned"].includes(state.sessionIssue.code) ? t("sessionBusy", { reason: state.sessionIssue.code }) : t(state.sessionIssue.code === "validation" ? "validation" : "sessionUnavailable") }),
2583
2744
  /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("p", { className: "dsmm-status", role: "status", "aria-live": "polite", "aria-atomic": "true", children: state.sessionBusy === "read" ? t("reading") : status })
2584
2745
  ] });
2585
2746
  }
2586
2747
  function SessionProfiles(props) {
2748
+ const prefix = (0, import_react2.useId)();
2587
2749
  const state = props.useProfiles((snapshot2) => snapshot2);
2588
2750
  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
- ] }) });
2751
+ const { t } = props;
2752
+ const session = state.session;
2753
+ const admission = session?.admittedSelection ?? (session?.scope === "global-default" ? void 0 : session?.selection);
2754
+ const unknownCaptured = session !== null && admission === void 0;
2755
+ const current = session === null ? "__dsmm_session_unavailable__" : unknownCaptured ? "__dsmm_captured_default__" : admission?.selectedId ?? "";
2756
+ const profiles = state.snapshot?.profiles ?? [];
2757
+ const currentSaved = profiles.find((profile) => profile.id === current);
2758
+ const committing = state.sessionBusy !== null;
2759
+ const disabled = committing || state.busy !== null || state.pendingEditor !== null || state.dirty || state.invalidFields.length > 0 || session === null || !session.switchAllowed || state.snapshot === null;
2760
+ let feedback = "";
2761
+ if (state.sessionIssue !== null) feedback = t(state.sessionIssue.source === "profile-model" ? state.sessionIssue.code === "model-unconfigured" ? "headerNoProfileModel" : state.sessionIssue.code === "model-choice-changed" ? "headerModelChoiceChanged" : "headerModelUnconfirmed" : state.sessionIssue.code === "conflict" ? "headerConflict" : "headerRefused");
2762
+ else if (committing) feedback = t(state.sessionBusy === "read" ? "headerLoading" : "headerApplying");
2763
+ else if (state.dirty || state.invalidFields.length > 0 || state.pendingEditor !== null) feedback = t("headerDraft");
2764
+ else if (session === null || state.snapshot === null) feedback = t("headerUnavailable");
2765
+ else if (!session.switchAllowed) feedback = t("headerBusy");
2766
+ else if (state.sessionNotice !== null) feedback = t(state.sessionNotice === "applied-with-model" ? "headerAppliedWithModel" : "headerApplied");
2767
+ const capturedSuffix = session?.scope === "global-default" && !unknownCaptured ? ` — ${t("headerCaptured")}` : "";
2768
+ return /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("div", { className: "dsmm-profiles dsmm-header-profiles", "data-dsmm-header-profile": true, "aria-busy": committing, children: [
2769
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("label", { htmlFor: `${prefix}-profile`, children: t("headerProfile") }),
2770
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("select", { id: `${prefix}-profile`, "aria-label": t("headerProfileLabel"), title: t("headerModelDefaultHint"), "aria-describedby": feedback === "" ? void 0 : `${prefix}-feedback`, value: current, disabled, onChange: (event) => {
2771
+ const value = event.currentTarget.value;
2772
+ const useProfileModel = value.startsWith("@model:");
2773
+ props.chooseSessionProfile((useProfileModel ? value.slice("@model:".length) : value) || null);
2774
+ void props.applySession(useProfileModel ? { useProfileModel: true } : void 0);
2775
+ }, children: [
2776
+ session === null && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "__dsmm_session_unavailable__", disabled: true, children: t("headerUnavailable") }),
2777
+ unknownCaptured && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "__dsmm_captured_default__", disabled: true, children: t("headerCaptured") }),
2778
+ admission?.selectedId != null && currentSaved === void 0 && /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: admission.selectedId, disabled: true, children: [
2779
+ admission.selectedId,
2780
+ " — ",
2781
+ t("headerSavedUnavailable"),
2782
+ capturedSuffix
2783
+ ] }),
2784
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("optgroup", { label: t("headerKeepModelGroup"), children: [
2785
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: "", children: [
2786
+ t("sessionBaseline"),
2787
+ current === "" ? capturedSuffix : ""
2788
+ ] }),
2789
+ profiles.map((profile) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: profile.id, disabled: profile.revision === null || profile.error !== void 0, children: [
2790
+ profile.label ?? profile.id,
2791
+ profile.id === current ? capturedSuffix : "",
2792
+ profile.error === void 0 && profile.revision !== null ? "" : ` — ${t("headerSavedUnavailable")}`
2793
+ ] }, profile.id))
2794
+ ] }),
2795
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("optgroup", { label: t("headerUseModelGroup"), children: [
2796
+ /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("option", { value: "@model:", children: t("sessionBaseline") }),
2797
+ profiles.map((profile) => /* @__PURE__ */ (0, import_jsx_runtime2.jsxs)("option", { value: `@model:${profile.id}`, disabled: profile.revision === null || profile.error !== void 0, children: [
2798
+ profile.label ?? profile.id,
2799
+ profile.error === void 0 && profile.revision !== null ? "" : ` — ${t("headerSavedUnavailable")}`
2800
+ ] }, profile.id))
2801
+ ] })
2802
+ ] }),
2803
+ feedback !== "" && /* @__PURE__ */ (0, import_jsx_runtime2.jsx)("span", { id: `${prefix}-feedback`, role: state.sessionIssue === null ? "status" : "alert", "aria-live": "polite", children: feedback })
2804
+ ] });
2593
2805
  }
2594
2806
 
2595
2807
  // src/client/ProfilesSection.tsx
@@ -2755,7 +2967,9 @@ var PROFILE_STYLES = `
2755
2967
  .dsmm-profiles summary{cursor:pointer;color:var(--dsw-alias-label-primary);min-height:32px;line-height:32px}
2756
2968
  .dsmm-profiles summary:focus-visible{outline:var(--dsw-focus-ring-width,2px) solid var(--dsw-focus-ring-color,var(--dsw-alias-state-business-primary));outline-offset:2px}
2757
2969
  .dsmm-profiles .dsmm-advanced[open]>div{margin-top:8px}
2758
- .dsmm-header-profiles{width:auto;max-width:760px}
2970
+ .dsmm-profiles.dsmm-header-profiles{width:auto;max-width:min(100%,max(0px,calc(100cqw - 24px)));flex-direction:row;flex-wrap:wrap;align-items:center;gap:8px}
2971
+ .dsmm-profiles.dsmm-header-profiles select{width:240px;max-width:100%;flex:1 1 0}
2972
+ .dsmm-header-profiles span{min-width:0;max-width:100%;overflow-wrap:anywhere;color:var(--dsw-alias-label-secondary)}
2759
2973
  .dsmm-profiles p{margin:0;overflow-wrap:anywhere}
2760
2974
  .dsmm-profiles .dsmm-hint{color:var(--dsw-alias-label-secondary)}
2761
2975
  .dsmm-profiles .dsmm-field{min-width:0;display:flex;flex-direction:column;gap:6px}
@@ -2803,14 +3017,46 @@ async function apply(ctx) {
2803
3017
  }, ProfilesSection));
2804
3018
  void profileCtx.inject(["remote.session"], (catalogCtx) => {
2805
3019
  controller.attachCatalog(catalogCtx.remote.session);
2806
- catalogCtx.effect(() => () => controller.attachCatalog(null), "dsmm: native catalog lifetime");
3020
+ controller.attachModelSelector(catalogCtx.remote.session);
3021
+ catalogCtx.effect(() => () => {
3022
+ controller.attachModelSelector(null);
3023
+ controller.attachCatalog(null);
3024
+ }, "dsmm: native catalog/selector lifetime");
2807
3025
  });
2808
- void profileCtx.inject(["uiSession"], (sessionCtx) => {
3026
+ void profileCtx.inject(["uiSession", "sessions"], (sessionCtx) => {
2809
3027
  const source = sessionCtx.uiSession.adapter.current;
2810
- const update = () => controller.setSession(source.getSnapshot().key ?? null);
3028
+ const nativeSessions = sessionCtx.sessions;
3029
+ const update = () => {
3030
+ const binding = source.getSnapshot();
3031
+ controller.setSession(binding.key ?? null);
3032
+ controller.attachModelSelectionSource(binding.key ?? null, binding.key === void 0 ? null : binding.keyedHooks.projection?.("modelSelection") ?? null);
3033
+ controller.attachModelEventSource(binding.key ?? null, binding.key === void 0 ? null : nativeSessions.binding(binding.key)?.eventSource ?? null);
3034
+ };
2811
3035
  update();
2812
3036
  sessionCtx.effect(() => source.subscribe(update), "dsmm: current native session");
2813
- sessionCtx.effect(() => () => controller.setSession(null), "dsmm: native session withdrawal");
3037
+ sessionCtx.effect(() => () => {
3038
+ controller.attachModelSelectionSource(null, null);
3039
+ controller.attachModelEventSource(null, null);
3040
+ controller.attachModelInteractionSource(null, null);
3041
+ controller.setSession(null);
3042
+ }, "dsmm: native session withdrawal");
3043
+ void sessionCtx.inject(["modelDirectories", "remote.session"], (modelCtx) => {
3044
+ const updateInteraction = () => {
3045
+ const id2 = source.getSnapshot().key;
3046
+ if (id2 === void 0 || nativeSessions.binding(id2) === void 0) {
3047
+ controller.attachModelInteractionSource(null, null);
3048
+ return;
3049
+ }
3050
+ try {
3051
+ controller.attachModelInteractionSource(id2, modelCtx.modelDirectories.directoryFor(id2).store);
3052
+ } catch {
3053
+ controller.attachModelInteractionSource(null, null);
3054
+ }
3055
+ };
3056
+ updateInteraction();
3057
+ modelCtx.effect(() => source.subscribe(updateInteraction), "dsmm: native model interaction binding");
3058
+ modelCtx.effect(() => () => controller.attachModelInteractionSource(null, null), "dsmm: native model interaction withdrawal");
3059
+ });
2814
3060
  sessionCtx.slots.inject("conversation.session.header.utilities", () => sessionCtx.slots.register({
2815
3061
  name: "conversation.session.header.utilities",
2816
3062
  id: "dsmm-session-profiles",
@@ -58,6 +58,7 @@ export function registerModelRouting(ctx, controller, getSettings) {
58
58
  if (frame.signal.aborted)
59
59
  return downstream;
60
60
  const settings = getSettings(frame.agent);
61
+ const ordinaryRoot = frame.agent.session.header?.origin !== "subagent";
61
62
  const admitted = takeAdmittedRecoveryRoute(frame);
62
63
  const active = controller.active(frame.agent, settings.defaultActive);
63
64
  const role = resolveEffectiveDsmmRole(frame.agent, settings, active);
@@ -75,6 +76,18 @@ export function registerModelRouting(ctx, controller, getSettings) {
75
76
  const exactPolicy = primary !== undefined || policy?.fallbackRoutes !== undefined || fallbacks.length > 0;
76
77
  const captured = assembledSelections.get(frame.agent);
77
78
  const manual = captured?.signal === frame.signal ? captured.intent : undefined;
79
+ if (ordinaryRoot) {
80
+ const selected = { provider: downstream.provider, model: downstream.model,
81
+ ...(downstream.reasoningEffort === undefined ? {} : { reasoningEffort: downstream.reasoningEffort }) };
82
+ if (lock === undefined || !sameExactModelRoute(lock.route, selected) || lock.manualSelectionSeq !== manual?.seq) {
83
+ const generation = (lock?.generation ?? -1) + 1;
84
+ lock = pinRoleRoute(frame.agent, identity, selected, [selected]);
85
+ lock.manualSelectionSeq = manual?.seq;
86
+ lock.generation = generation;
87
+ lockedAgents.add(frame.agent);
88
+ }
89
+ return downstream;
90
+ }
78
91
  if (manual !== undefined && lock?.manualSelectionSeq !== manual.seq
79
92
  && (sameExactModelRoute(downstream, manual.route) || nativeModelSelectionWasAccepted(frame.agent, manual))) {
80
93
  const llm = frame.agent.ctx?.get?.("llm")
@@ -124,6 +137,9 @@ export function registerModelRouting(ctx, controller, getSettings) {
124
137
  if (exactPolicy || lock.attempts > 0)
125
138
  return downstream;
126
139
  }
140
+ // Ordinary roots belong to the native model tab, including its exact effort.
141
+ if (ordinaryRoot)
142
+ return downstream;
127
143
  // Named fallback efforts are native policy IDs, never legacy calibration inputs.
128
144
  if (fallbacks.some((fallback) => fallback.reasoningEffort !== undefined
129
145
  && sameModelRoute(fallback, downstream) && fallback.reasoningEffort === downstream.reasoningEffort))
@@ -136,22 +136,23 @@ function rolePolicy(value) {
136
136
  switches: integer(item.switches, "switches", 10),
137
137
  totalDelayMs: integer(item.totalDelayMs, "totalDelayMs", 120000),
138
138
  ...optional(item, "role", role),
139
- ...optional(item, "route", (input) => {
140
- const route = object(input, ["provider", "model"], ["reasoningEffort"]);
141
- const provider = routeText(route.provider, "provider", 128);
142
- const model = routeText(route.model, "model", 512);
143
- if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/u.test(provider) || model.includes("://"))
144
- fail("route");
145
- return { provider, model, ...optional(route, "reasoningEffort", (value) => routeText(value, "reasoningEffort", 64)) };
146
- }),
139
+ ...optional(item, "route", modelRoute),
147
140
  };
148
141
  }
142
+ function modelRoute(value) {
143
+ const route = object(value, ["provider", "model"], ["reasoningEffort"]);
144
+ const provider = routeText(route.provider, "provider", 128);
145
+ const model = routeText(route.model, "model", 512);
146
+ if (!/^[a-zA-Z0-9][a-zA-Z0-9_.:-]*$/u.test(provider) || model.includes("://"))
147
+ fail("route");
148
+ return { provider, model, ...optional(route, "reasoningEffort", (input) => routeText(input, "reasoningEffort", 64)) };
149
+ }
149
150
  function selectionState(value) {
150
151
  const item = object(value, ["selectedId", "appliedRevision", "selectionRevision"]);
151
152
  return { selectedId: item.selectedId === null ? null : id(item.selectedId), appliedRevision: item.appliedRevision === null ? null : revision(item.appliedRevision), selectionRevision: selectionRevision(item.selectionRevision) };
152
153
  }
153
154
  function sessionSnapshot(value) {
154
- const item = object(value, ["sessionId", "globalDefault", "selection", "scope", "admissionEpoch", "switchAllowed"], ["admittedSelection", "switchUnavailableReason", "rolePolicy"]);
155
+ const item = object(value, ["sessionId", "globalDefault", "selection", "scope", "admissionEpoch", "switchAllowed"], ["admittedSelection", "switchUnavailableReason", "rolePolicy", "profileModel"]);
155
156
  if (typeof item.scope !== "string" || !["global-default", "session-override", "deployment-baseline"].includes(item.scope))
156
157
  fail("scope");
157
158
  return {
@@ -164,6 +165,7 @@ function sessionSnapshot(value) {
164
165
  return input;
165
166
  }),
166
167
  ...optional(item, "rolePolicy", rolePolicy),
168
+ ...optional(item, "profileModel", modelRoute),
167
169
  };
168
170
  }
169
171
  function saveRequest(value) {
@@ -50,6 +50,7 @@ export declare class DsmmProfileRuntime {
50
50
  select(request: ProfileSelectRequest): Promise<ProfileSnapshot>;
51
51
  private prepare;
52
52
  private profileAdmission;
53
+ private declaredProfileModel;
53
54
  private agents;
54
55
  private bind;
55
56
  private owner;
@@ -69,8 +69,10 @@ export class DsmmProfileRuntime {
69
69
  }
70
70
  const reason = this.switching.has(agent) ? "maintenance" : agent.status === "running" ? "busy" : agent.runMaintenance === undefined ? "unavailable" : undefined;
71
71
  const role = resolveEffectiveDsmmRole(agent, admitted.settings, isDeepworkActive(sessionEvents(agent.session), admitted.settings.defaultActive));
72
+ const profileModel = this.declaredProfileModel(admitted.settings, role);
72
73
  return { sessionId: agent.id, globalDefault: selectionState(this.current), selection: selectionState(disk), admittedSelection: selectionState(admitted), scope: admitted.scope,
73
74
  rolePolicy: roleRouteRuntimeState(agent, admitted.settings, role, admitted.epoch),
75
+ ...(profileModel === undefined ? {} : { profileModel }),
74
76
  admissionEpoch: admitted.epoch, switchAllowed: reason === undefined, ...(reason === undefined ? {} : { switchUnavailableReason: reason }) };
75
77
  }
76
78
  /** The fourth argument is trusted native caller authority, never wire data. */
@@ -99,9 +101,12 @@ export class DsmmProfileRuntime {
99
101
  try {
100
102
  assertCurrent(maintenanceSignal);
101
103
  const epoch = newEpoch();
104
+ let profileModel;
102
105
  const result = await this.store.selectSession(request, epoch, async (document) => {
103
106
  const prepared = immutableSettings(resolveProfileSettings(this.baseline, document?.settings ?? {}));
104
107
  await this.validate(prepared, agent, maintenanceSignal);
108
+ const role = resolveEffectiveDsmmRole(agent, prepared, isDeepworkActive(sessionEvents(agent.session), prepared.defaultActive));
109
+ profileModel = this.declaredProfileModel(prepared, role);
105
110
  assertCurrent(maintenanceSignal);
106
111
  return prepared;
107
112
  }, {
@@ -113,6 +118,7 @@ export class DsmmProfileRuntime {
113
118
  // A committed selection remains a successful transaction even if a
114
119
  // queued wake or disposal wins immediately when maintenance releases.
115
120
  return { sessionId: request.sessionId, globalDefault: selectionState(this.current), selection: selectionState(result.selection), admittedSelection: selectionState(result.selection),
121
+ ...(profileModel === undefined ? {} : { profileModel }),
116
122
  scope: request.id === null ? "deployment-baseline" : "session-override", admissionEpoch: epoch, switchAllowed: true };
117
123
  }
118
124
  finally {
@@ -178,6 +184,11 @@ export class DsmmProfileRuntime {
178
184
  profileAdmission(selection, settings, epoch, scope) {
179
185
  return Object.freeze({ ...selectionState(selection), settings, epoch, scope, profile: selection.selectedId === null || selection.appliedRevision === null ? null : Object.freeze({ id: selection.selectedId, revision: selection.appliedRevision }) });
180
186
  }
187
+ declaredProfileModel(settings, role) {
188
+ const primary = role === undefined ? undefined : settings.roleRouting[role]?.primary;
189
+ return primary === undefined ? undefined : { provider: primary.provider, model: primary.model,
190
+ ...(primary.reasoningEffort === undefined ? {} : { reasoningEffort: primary.reasoningEffort }) };
191
+ }
181
192
  agents() { return this.ctx.get?.("agents"); }
182
193
  bind(agent) {
183
194
  const existing = this.bound.get(agent);
@@ -71,6 +71,8 @@ export interface SessionProfileSnapshot {
71
71
  switchAllowed: boolean;
72
72
  switchUnavailableReason?: "busy" | "maintenance" | "disposed" | "not-owned" | "unavailable";
73
73
  rolePolicy?: DsmmRoleRuntimeState;
74
+ /** Declared profile primary for the current ordinary root role, not an applied native selection. */
75
+ profileModel?: DsmmModelRoute;
74
76
  }
75
77
  export interface SessionProfileSelectRequest extends ProfileSelectRequest {
76
78
  sessionId: string;
@@ -82,7 +82,7 @@ export function roleRouteRuntimeState(agent, settings, role, epoch) {
82
82
  const resolved = resolveRoleRuntimePolicy(settings, role);
83
83
  const identity = liveRolePolicyIdentity(agent, settings, role, epoch);
84
84
  const lock = identity === undefined ? undefined : roleRouteLock(agent, identity);
85
- return { ...(role === undefined ? {} : { role }), strategy: resolved.strategy, rateLimit: { ...resolved.rateLimit },
85
+ return { ...(role === undefined ? {} : { role }), strategy: agent.session.header?.origin === "subagent" ? resolved.strategy : "startup-lock", rateLimit: { ...resolved.rateLimit },
86
86
  ...(lock === undefined ? {} : { route: { ...lock.route } }), retries: lock?.retries ?? 0,
87
87
  rateLimitFailures: lock?.rateLimits ?? 0, switches: lock?.switches ?? 0, totalDelayMs: lock?.totalDelayMs ?? 0 };
88
88
  }
@@ -178,6 +178,8 @@ export function registerRuntimeRecovery(ctx, controller, getSettings) {
178
178
  return downstream;
179
179
  }
180
180
  pendingByAgent.delete(frame.agent);
181
+ if (frame.agent.session.header?.origin !== "subagent")
182
+ return downstream;
181
183
  lock.route = { ...pending.route };
182
184
  recordAdmittedRecoveryRoute(frame, pending.route);
183
185
  return applyModelRoute(downstream, pending.route);
@@ -220,7 +222,8 @@ export function registerRuntimeRecovery(ctx, controller, getSettings) {
220
222
  else {
221
223
  lock.startupSettled = true;
222
224
  lock.rateLimits += 1;
223
- switching = resolved.strategy === "rate-limit-fallback" && lock.rateLimits >= bounds.switchAfterRateLimits;
225
+ switching = frame.agent.session.header?.origin === "subagent"
226
+ && resolved.strategy === "rate-limit-fallback" && lock.rateLimits >= bounds.switchAfterRateLimits;
224
227
  if (!switching && lock.retries >= bounds.maxRetries)
225
228
  return undefined;
226
229
  }
package/lib/status.d.ts CHANGED
@@ -27,7 +27,7 @@ export interface DsmmStatusSnapshot {
27
27
  mode: DeepseekCalibration;
28
28
  applies: boolean;
29
29
  policyEffort?: "off" | "low" | "high" | "max";
30
- action: "disabled" | "out-of-scope" | "non-target-route" | "preserve-explicit" | "fill-missing" | "enforce" | "fixed-role-policy";
30
+ action: "disabled" | "out-of-scope" | "non-target-route" | "preserve-explicit" | "fill-missing" | "enforce" | "native-owned" | "fixed-role-policy";
31
31
  };
32
32
  rolePolicy: {
33
33
  role?: DsmmRoleId;