dsh-model-switch 0.4.43 → 0.4.45

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.
@@ -0,0 +1,279 @@
1
+ //#region lib/types/provider-group.js
2
+ /**
3
+ * Provider configuration groups: per-provider presets for the compaction,
4
+ * auto-review, session-naming, and subagent routes.
5
+ *
6
+ * A group is a DERIVED policy, not a write: `src/session-route.ts` resolves the
7
+ * routes one session should use from its own provider plus this stored table, so
8
+ * switching a session's provider never rewrites deployment-wide settings and two
9
+ * sessions on different providers cannot overwrite each other. The field names
10
+ * below are the flat settings field names a group pins, which keeps the stored
11
+ * shape identical across releases.
12
+ *
13
+ * All functions here are pure and never throw on malformed storage.
14
+ */
15
+ const ROUTE_FIELDS = Object.freeze([
16
+ "compactProvider",
17
+ "compactModel",
18
+ "autoReviewProvider",
19
+ "autoReviewModel",
20
+ "subagentProvider",
21
+ "subagentModel",
22
+ "subagentReasoningEffort",
23
+ "titleProvider",
24
+ "titleModel",
25
+ "memoryProvider",
26
+ "memoryModel"
27
+ ]);
28
+ /** Own data property, so a literal '__proto__' provider id can never touch a prototype. */
29
+ function setKey(target, key, value) {
30
+ Object.defineProperty(target, key, {
31
+ value,
32
+ enumerable: true,
33
+ writable: true,
34
+ configurable: true
35
+ });
36
+ }
37
+ /** A non-blank string. Blank values behave exactly like an absent field. */
38
+ function present$1(value) {
39
+ return typeof value === "string" && value.trim() !== "";
40
+ }
41
+ /** Normalize one raw entry to its owning provider and route view; undefined for non-object junk. */
42
+ function normalizeEntry(value) {
43
+ if (value === null || typeof value !== "object" || Array.isArray(value)) return void 0;
44
+ const source = value;
45
+ const group = {};
46
+ for (const field of ROUTE_FIELDS) {
47
+ const item = source[field];
48
+ if (present$1(item)) group[field] = item;
49
+ }
50
+ return {
51
+ provider: present$1(source.provider) ? source.provider : "",
52
+ group
53
+ };
54
+ }
55
+ /**
56
+ * Strip a raw stored value to well-formed groups; never throws. Both storage
57
+ * shapes are accepted: the stored entry array (keys live in each entry's
58
+ * `provider` field) and a hand-written provider → routes map (keys are the
59
+ * providers). All-empty entries stay: they pin a provider to every default.
60
+ */
61
+ function normalizeProviderGroups(raw) {
62
+ const groups = {};
63
+ if (Array.isArray(raw)) {
64
+ for (const entry of raw) {
65
+ const view = normalizeEntry(entry);
66
+ if (view === void 0 || view.provider === "") continue;
67
+ setKey(groups, view.provider, view.group);
68
+ }
69
+ return groups;
70
+ }
71
+ if (raw !== null && typeof raw === "object") for (const [key, value] of Object.entries(raw)) {
72
+ if (key.trim() === "") continue;
73
+ const view = normalizeEntry(value);
74
+ if (view === void 0) continue;
75
+ setKey(groups, key, view.group);
76
+ }
77
+ return groups;
78
+ }
79
+ /**
80
+ * The saved group for a provider.
81
+ * @returns the normalized group, or undefined when the provider has no group —
82
+ * which is what leaves the live routes untouched during a switch.
83
+ */
84
+ function groupOf(groups, provider) {
85
+ if (groups === void 0 || provider.trim() === "") return void 0;
86
+ if (!Object.prototype.hasOwnProperty.call(groups, provider)) return void 0;
87
+ return groups[provider];
88
+ }
89
+ //#endregion
90
+ //#region lib/types/session-route.js
91
+ /**
92
+ * Per-session capability route derivation.
93
+ *
94
+ * Model Switch stores one deployment-wide route per capability (the flat
95
+ * settings fields) plus, per provider, a saved provider group. Nothing is
96
+ * written when a session changes provider: this module DERIVES the route a
97
+ * capability should use for one session from (a) the session's own provider and
98
+ * (b) the stored group table. Two sessions on different providers therefore
99
+ * resolve independently, and no session's actions rewrite another session's
100
+ * route.
101
+ *
102
+ * The session's provider is read from durable, official state in this order:
103
+ * the `modelSelection` session projection (`pending` before `lastUsed`, so a
104
+ * selection the user just made counts), then the latest logged request-context
105
+ * route, then the latest `request/header` route. Every read is optional: a
106
+ * session with no observable provider, an unregistered projection, or a
107
+ * profile without the projection package all resolve to the deployment default,
108
+ * which is exactly the pre-derivation behavior.
109
+ *
110
+ * All functions are pure except the readers, which never throw and never write.
111
+ */
112
+ /** Flat deployment-default fields per capability, in group-storage field names. */
113
+ const CAPABILITY_FIELDS = Object.freeze({
114
+ compaction: {
115
+ provider: "compactProvider",
116
+ model: "compactModel"
117
+ },
118
+ autoReview: {
119
+ provider: "autoReviewProvider",
120
+ model: "autoReviewModel"
121
+ },
122
+ title: {
123
+ provider: "titleProvider",
124
+ model: "titleModel"
125
+ },
126
+ subagent: {
127
+ provider: "subagentProvider",
128
+ model: "subagentModel"
129
+ },
130
+ memory: {
131
+ provider: "memoryProvider",
132
+ model: "memoryModel"
133
+ }
134
+ });
135
+ /** A non-blank string; blank values behave exactly like an absent field. */
136
+ function present(value) {
137
+ return typeof value === "string" && value.trim() !== "";
138
+ }
139
+ /** Read one capability's pair from a flat route record; undefined unless both halves are present. */
140
+ function pairOf(source, fields) {
141
+ if (source === void 0) return void 0;
142
+ const record = source;
143
+ const provider = record[fields.provider];
144
+ const model = record[fields.model];
145
+ if (!present(provider) || !present(model)) return void 0;
146
+ return {
147
+ provider,
148
+ model
149
+ };
150
+ }
151
+ /**
152
+ * The deployment-wide route for one capability: the flat settings pair.
153
+ * @param settings - live Model Switch settings; undefined means none are reachable.
154
+ * @param capability - capability whose flat pair is read.
155
+ * @returns The complete pair, or undefined when the capability stays at its official/derived default.
156
+ */
157
+ function deploymentRoute(settings, capability) {
158
+ return pairOf(settings, CAPABILITY_FIELDS[capability]);
159
+ }
160
+ /**
161
+ * The distillation route one deployment should use.
162
+ *
163
+ * Distillation is a background pipeline with no session of its own, so the group
164
+ * key is the deployment default provider (the provider the profile starts
165
+ * sessions on) rather than a session's provider. A provider without a group falls
166
+ * back to the flat memory pair; an empty pair leaves the memory plugin at its own
167
+ * default.
168
+ * @param settings - live Model Switch settings.
169
+ * @param provider - the deployment default provider, when one is observable.
170
+ * @returns The complete pair, or undefined when nothing is pinned.
171
+ */
172
+ function memoryRouteOf(settings, provider) {
173
+ return groupRoute(settings, provider, "memory") ?? deploymentRoute(settings, "memory");
174
+ }
175
+ /**
176
+ * The route a subagent spawn should use for one parent-session provider.
177
+ *
178
+ * A saved group for that provider pins the spawn; otherwise the flat Subagent
179
+ * card pins it, but only in `fixed` mode — `follow-main` IS the official inherit
180
+ * path, expressed by leaving the request untouched rather than by naming it.
181
+ * @param settings - live Model Switch settings.
182
+ * @param provider - the delegating session's provider, when one is observable.
183
+ * @returns The complete route, or undefined for official inherit.
184
+ */
185
+ function subagentRouteOf(settings, provider) {
186
+ const group = groupRoute(settings, provider, "subagent");
187
+ if (group !== void 0) {
188
+ const effort = groupOf(settings?.providerGroups, provider ?? "")?.subagentReasoningEffort;
189
+ return present(effort) ? {
190
+ ...group,
191
+ reasoningEffort: effort
192
+ } : group;
193
+ }
194
+ if (settings?.subagentMode !== "fixed") return void 0;
195
+ const fixed = deploymentRoute(settings, "subagent");
196
+ if (fixed === void 0) return void 0;
197
+ return present(settings.subagentReasoningEffort) ? {
198
+ ...fixed,
199
+ reasoningEffort: settings.subagentReasoningEffort
200
+ } : fixed;
201
+ }
202
+ /**
203
+ * One provider's saved route for one capability.
204
+ * @param settings - live Model Switch settings carrying the group table.
205
+ * @param provider - the session's provider; blank or unknown resolves to undefined.
206
+ * @param capability - capability whose group pin is read.
207
+ * @returns The complete group pair, or undefined when the group pins nothing here.
208
+ */
209
+ function groupRoute(settings, provider, capability) {
210
+ if (!present(provider)) return void 0;
211
+ return pairOf(groupOf(settings?.providerGroups, provider), CAPABILITY_FIELDS[capability]);
212
+ }
213
+ /**
214
+ * The route one capability should use for one session.
215
+ *
216
+ * A saved provider group for the session's provider wins; otherwise the flat
217
+ * deployment default applies. An unknown session provider skips every group, so
218
+ * a session Model Switch cannot attribute keeps the deployment default.
219
+ * @param settings - live Model Switch settings.
220
+ * @param provider - the session's provider, when one is observable.
221
+ * @param capability - capability being resolved.
222
+ * @returns The complete pair, or undefined for the capability's official default.
223
+ */
224
+ function resolveCapabilityRoute(settings, provider, capability) {
225
+ return groupRoute(settings, provider, capability) ?? deploymentRoute(settings, capability);
226
+ }
227
+ /**
228
+ * Read the provider from the durable model-selection projection.
229
+ * @param ctx - context that may expose `sessionProjections`.
230
+ * @param session - the session whose selection is read.
231
+ * @returns The pending provider, else the last-used provider, else undefined.
232
+ */
233
+ function projectionProvider(ctx, session) {
234
+ let state;
235
+ try {
236
+ state = ctx.get("sessionProjections", false)?.stateOf(session, "modelSelection");
237
+ } catch {
238
+ state = void 0;
239
+ }
240
+ if (state === void 0) return void 0;
241
+ if (present(state.pending?.provider)) return state.pending.provider;
242
+ if (present(state.lastUsed?.provider)) return state.lastUsed.provider;
243
+ }
244
+ /**
245
+ * The provider one session is using, from official durable state.
246
+ *
247
+ * Preferred source is the session's own model selection (it covers a switch the
248
+ * client has sent but no request has consumed yet); the logged request-context
249
+ * and request-header routes cover profiles without the projection package and
250
+ * replayed sessions that never emitted a selection.
251
+ * @param ctx - context used for the optional projection read.
252
+ * @param session - the session to resolve; undefined resolves to undefined.
253
+ * @returns The provider, or undefined when nothing durable names one.
254
+ */
255
+ function sessionProviderOf(ctx, session) {
256
+ if (session === void 0) return void 0;
257
+ const selected = projectionProvider(ctx, session);
258
+ if (selected !== void 0) return selected;
259
+ try {
260
+ const context = session.requestContext()?.provider;
261
+ if (present(context)) return context;
262
+ const header = session.requestHeader()?.config.provider;
263
+ if (present(header)) return header;
264
+ } catch {
265
+ return;
266
+ }
267
+ }
268
+ /**
269
+ * The subagent route one exact session's spawns should use.
270
+ * @param ctx - context used for the optional session reads.
271
+ * @param session - the delegating session; undefined keeps official inherit.
272
+ * @param settings - live Model Switch settings.
273
+ * @returns The complete route, or undefined for official inherit.
274
+ */
275
+ function sessionSubagentRouteOf(ctx, session, settings) {
276
+ return subagentRouteOf(settings, sessionProviderOf(ctx, session));
277
+ }
278
+ //#endregion
279
+ export { sessionProviderOf as a, resolveCapabilityRoute as i, groupRoute as n, sessionSubagentRouteOf as o, memoryRouteOf as r, normalizeProviderGroups as s, deploymentRoute as t };
@@ -1,4 +1,4 @@
1
- import { i as sessionProviderOf, n as groupRoute, t as deploymentRoute } from "./session-route-D1zoZgf3.js";
1
+ import { a as sessionProviderOf, n as groupRoute, t as deploymentRoute } from "./session-route-D8izd8Zd.js";
2
2
  //#region lib/types/session-title.js
3
3
  /**
4
4
  * Model Switch-owned session-naming row.
@@ -1,4 +1,4 @@
1
- import { a as sessionSubagentRouteOf } from "./session-route-D1zoZgf3.js";
1
+ import { o as sessionSubagentRouteOf } from "./session-route-D8izd8Zd.js";
2
2
  import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
3
3
  import OfficialSubagentRuntime from "@deepseek-ai/dsh-subagent";
4
4
  //#region lib/types/subagent-runtime.js
@@ -17,6 +17,7 @@ export interface ModelSwitchSettingsFace {
17
17
  autoReviewSettings: ConfigViewForm<CapabilityRouteView>;
18
18
  compactionSettings: ConfigViewForm<CapabilityRouteView>;
19
19
  titleSettings: ConfigViewForm<CapabilityRouteView>;
20
+ memorySettings: ConfigViewForm<CapabilityRouteView>;
20
21
  switchSettings: Pick<ConfigForm<ModelSwitchSettingsView>, 'getSnapshot' | 'subscribe'>;
21
22
  };
22
23
  capabilities: RuntimeCapabilities;
@@ -25,7 +26,7 @@ export interface ModelSwitchSettingsFace {
25
26
  * write can never leave a half-written provider/model pair behind.
26
27
  */
27
28
  saveSubagent: (ops: readonly ConfigViewOp<SubagentSettingsView>[]) => Promise<void>;
28
- saveCapability: (route: 'search' | 'image' | 'autoReview' | 'compaction' | 'title', ops: readonly ConfigViewOp<CapabilityRouteView>[]) => Promise<void>;
29
+ saveCapability: (route: 'search' | 'image' | 'autoReview' | 'compaction' | 'title' | 'memory', ops: readonly ConfigViewOp<CapabilityRouteView>[]) => Promise<void>;
29
30
  /** Persist the read-only skip switch and its allowlist as one atomic write. */
30
31
  saveReviewAllowlist: (value: {
31
32
  enabled: boolean;
@@ -42,11 +42,15 @@ export declare const zh: {
42
42
  readonly titleFollow: "跟随会话模型";
43
43
  readonly titleHelp: "为官方自动命名(新会话首条消息后生成标题)指定模型;关闭(两个字段都留空)时命名跟随当前会话模型。";
44
44
  readonly titleRouteHelp: "命名请求固定使用这里的 Provider/模型(不带推理强度);关闭时跟随会话模型。保存后立即对下一次命名生效,不会中断正在进行的命名,会话日志记录的也是实际使用的模型。";
45
+ readonly memory: "记忆蒸馏模型";
46
+ readonly memoryFollow: "跟随记忆插件默认";
47
+ readonly memoryHelp: "为 dsh-prime-memory 的记忆蒸馏指定路由;两个字段都留空时跟随该插件自己的默认模型。";
48
+ readonly memoryRouteHelp: "按部署默认供应商的配置组解析;该供应商没有组时使用这里填写的平面默认。只改它的内存配置,不写入它的设置。";
45
49
  readonly providerGroups: "供应商配置组";
46
50
  readonly providerGroupsCard: "按供应商预设路由";
47
51
  readonly providerGroupsSummary: "使用该供应商的会话自动采用对应组";
48
- readonly providerGroupsHelp: "为压缩、自动审查、会话命名与子代理按供应商分别保存路由。";
49
- readonly providerGroupsBodyHelp: "每个供应商保存一组压缩、自动审查、会话命名与子代理路由。会话自身的供应商与该组一致时,这四项能力按组实时解析,未固定项回落到上方卡片里的全局设置。切换某个会话的模型不会写入任何全局设置,因此不同供应商的多个会话并行时互不影响,会话中切换供应商后下一次调用也会立即跟随新供应商的配置组。";
52
+ readonly providerGroupsHelp: "为压缩、自动审查、会话命名、记忆蒸馏与子代理按供应商分别保存路由。";
53
+ readonly providerGroupsBodyHelp: "每个供应商保存一组压缩、自动审查、会话命名与子代理路由。会话自身的供应商与该组一致时,这五项能力(含记忆蒸馏)按组实时解析,未固定项回落到上方卡片里的全局设置。切换某个会话的模型不会写入任何全局设置,因此不同供应商的多个会话并行时互不影响,会话中切换供应商后下一次调用也会立即跟随新供应商的配置组。";
50
54
  readonly providerGroupPick: "选择供应商以编辑其配置组。";
51
55
  readonly providerGroupDelete: "删除该组";
52
56
  readonly groupOverridesLabel: "组覆盖:{pins};无组时用上方默认值";
@@ -20,6 +20,9 @@ export interface ModelSwitchSettingsView {
20
20
  compactModel?: string;
21
21
  titleProvider?: string;
22
22
  titleModel?: string;
23
+ /** Distillation route for the memory plugin; both unset means it keeps its own default. */
24
+ memoryProvider?: string;
25
+ memoryModel?: string;
23
26
  /** Raw saved per-provider groups; edited whole through the provider-groups card. */
24
27
  providerGroups?: ProviderGroupsStorage;
25
28
  }
@@ -81,12 +84,18 @@ export declare const TITLE_SETTINGS_FIELDS: Readonly<{
81
84
  readonly provider: "titleProvider";
82
85
  readonly model: "titleModel";
83
86
  }>;
87
+ /** Distillation route handed to the memory plugin when it follows its own default. */
88
+ export declare const MEMORY_SETTINGS_FIELDS: Readonly<{
89
+ readonly provider: "memoryProvider";
90
+ readonly model: "memoryModel";
91
+ }>;
84
92
  export declare function deriveSubagentSettings(settings: ModelSwitchSettingsView): SubagentSettingsView;
85
93
  export declare function deriveSearchSettings(settings: ModelSwitchSettingsView): CapabilityRouteView;
86
94
  export declare function deriveImageSettings(settings: ModelSwitchSettingsView): CapabilityRouteView;
87
95
  export declare function deriveAutoReviewSettings(settings: ModelSwitchSettingsView): CapabilityRouteView;
88
96
  export declare function deriveCompactionSettings(settings: ModelSwitchSettingsView): CapabilityRouteView;
89
97
  export declare function deriveTitleSettings(settings: ModelSwitchSettingsView): CapabilityRouteView;
98
+ export declare function deriveMemorySettings(settings: ModelSwitchSettingsView): CapabilityRouteView;
90
99
  /** Whether both fields of a model route form a complete pair; an incomplete pair stays off. */
91
100
  export declare function routePairConfigured(route: CapabilityRouteView | undefined): boolean;
92
101
  /** Live reviewer counters shown beside the allowlist editor. */
@@ -37,6 +37,10 @@ export interface ModelSwitchSettings {
37
37
  titleProvider?: string;
38
38
  /** Naming model for automatic session titles; set together with `titleProvider`. */
39
39
  titleModel?: string;
40
+ /** Distillation provider for the memory plugin; both fields unset = its own default. */
41
+ memoryProvider?: string;
42
+ /** Distillation model for the memory plugin; set together with `memoryProvider`. */
43
+ memoryModel?: string;
40
44
  /** Per-provider compaction/subagent/review presets, keyed by provider id; absent when no group is saved. */
41
45
  providerGroups?: ProviderGroups;
42
46
  }
@@ -60,6 +64,9 @@ export interface Config {
60
64
  compactModel: Volatile<string | undefined>;
61
65
  titleProvider: Volatile<string | undefined>;
62
66
  titleModel: Volatile<string | undefined>;
67
+ /** Distillation route handed to the memory plugin when it follows its default. */
68
+ memoryProvider: Volatile<string | undefined>;
69
+ memoryModel: Volatile<string | undefined>;
63
70
  /** Saved per-provider capability groups as one entry per provider; entry route fields are '' when the capability stays at its default. */
64
71
  providerGroups: Volatile<readonly ProviderGroupEntry[]>;
65
72
  }
@@ -0,0 +1,103 @@
1
+ /**
2
+ * Adapt `dsh-prime-memory`'s distillation route to this plugin's route.
3
+ *
4
+ * The memory plugin resolves its distillation route from its own runtime
5
+ * settings section (`live.distillChain`, legacy `live.distillProvider/Model`,
6
+ * else the deployment default model), and it WRITES that section through the
7
+ * host's settings-forms service:
8
+ *
9
+ * await forms.update('dsh-memory', { live: next })
10
+ *
11
+ * Its row config is read once at plugin init, so patching
12
+ * `entry.options.config.llm.*` afterwards has no effect (verified on 0.2.1-rc.3:
13
+ * the model kept being the deployment default). This adapter therefore writes
14
+ * the same section the plugin itself writes, and only that key:
15
+ *
16
+ * - a chain that is already set and is not the one this adapter wrote counts as
17
+ * user intent and is left alone (`user-set`);
18
+ * - an empty Model Switch route means "leave it alone" (`no-route`);
19
+ * - nothing is persisted by us beyond that section, and no other `live` key
20
+ * (capture, trace, embedding, memory mutation) is touched.
21
+ *
22
+ * The route itself is provider-group based: the group of the deployment default
23
+ * provider (read from the `agent-default-model` row), falling back to the flat
24
+ * memory pair.
25
+ */
26
+ import type { Context } from '@deepseek-ai/cordis';
27
+ import type { Entry } from '@deepseek-ai/cordis-plugin-loader';
28
+ import { type CapabilityRoute } from './session-route.js';
29
+ import { type DistillChainEntry } from './prime-memory-route.js';
30
+ /** Row name and dependencies, mirroring the sibling adapter row. */
31
+ export declare const name = "model-switch-prime-memory-compat";
32
+ export declare const inject: string[];
33
+ /** Why the adapter stayed out of the way. */
34
+ export type PrimeMemoryRouteSkip = 'user-set' | 'no-route';
35
+ /** Live adapter state, surfaced next to the settings card. */
36
+ export interface PrimeMemoryCompatStatus {
37
+ /** Whether at least one write reached the memory plugin's settings. */
38
+ installed: boolean;
39
+ /** The `provider/model` written on the last pass. */
40
+ route?: string | undefined;
41
+ /** Why the route was not written, when it was not. */
42
+ routeSkipped?: PrimeMemoryRouteSkip | undefined;
43
+ }
44
+ /** The state the settings page reads. */
45
+ export declare const primeMemoryCompatStatus: PrimeMemoryCompatStatus;
46
+ /**
47
+ * The distillation chain a settings section currently carries.
48
+ *
49
+ * Accepts the chain form and the legacy provider/model pair, so a user who set
50
+ * the old two fields is still recognised as user intent.
51
+ * @param section - the `live` section (or a whole settings view) to read.
52
+ * @returns The chain entries; empty when nothing is set.
53
+ */
54
+ export declare function chainOf(section: unknown): readonly DistillChainEntry[];
55
+ /** What one memory row's config decides, kept pure for the unit tests. */
56
+ export interface PrimeMemoryPlan {
57
+ /** The config to install (unchanged when `changed` is false). */
58
+ readonly config: Record<string, unknown>;
59
+ /** Whether the config differs from the input. */
60
+ readonly changed: boolean;
61
+ /** The `provider/model` written on this pass. */
62
+ readonly route?: string | undefined;
63
+ /** Why nothing was written. */
64
+ readonly skipped?: PrimeMemoryRouteSkip | undefined;
65
+ }
66
+ /**
67
+ * Decide the route config one memory row would run with from its config alone.
68
+ *
69
+ * Kept for the settings-free path (a profile that pins `config.llm.*`): the
70
+ * runtime path writes the settings section instead, because the plugin reads its
71
+ * config only at init.
72
+ * @param config - the row's current config (any JSON-ish value).
73
+ * @param route - this plugin's distillation route; an incomplete pair counts as unset.
74
+ * @param adoptedRoute - a `provider/model` this adapter wrote on an earlier pass.
75
+ * @returns The config to install, whether it changed, and what was applied.
76
+ */
77
+ export declare function planPrimeMemoryRoute(config: unknown, route: CapabilityRoute | undefined, adoptedRoute?: string): PrimeMemoryPlan;
78
+ /** What the adapter needs from the loader. */
79
+ interface Loader {
80
+ entries?(): Iterable<Entry>;
81
+ }
82
+ /**
83
+ * Install the adapter for the whole profile.
84
+ *
85
+ * Writes the memory plugin's own `live` section on activation, on every
86
+ * `loader/patch-context`, on `loader/entry-init`, once more after a short delay
87
+ * (a bundle-inserted row is often composed after this one), and again whenever
88
+ * this plugin's settings change.
89
+ * @param ctx - this row's context.
90
+ * @param loader - the loader service, when present.
91
+ * @param routeOf - resolves this plugin's distillation route for one settings snapshot.
92
+ * @returns The disposer and a replay hook.
93
+ */
94
+ export declare function installPrimeMemoryCompat(ctx: Context, loader: Loader | undefined, routeOf: () => CapabilityRoute | undefined): {
95
+ dispose: () => void;
96
+ replay: () => boolean;
97
+ };
98
+ /**
99
+ * Row entry point: adapt the memory plugin on activation and on remount.
100
+ * @param ctx - this row's context.
101
+ */
102
+ export declare function apply(ctx: Context): void;
103
+ export {};
@@ -0,0 +1,75 @@
1
+ /**
2
+ * Model Switch's adapter to `dsh-prime-memory`'s distillation route.
3
+ *
4
+ * prime-memory owns its distillation route: a `distillChain` in the volatile
5
+ * `live` settings section (`distillProvider`/`distillModel` before 0.x chains
6
+ * existed), read through its own settings handle and committed with
7
+ * `ctx.settings.update('dsh-memory', { live })` — a volatile-only commit that
8
+ * does not remount the plugin. This module only builds the write Model Switch
9
+ * offers; it never runs a distillation call, never rewrites the plugin, and
10
+ * never changes a route the user did not ask to change.
11
+ *
12
+ * All functions here are pure.
13
+ */
14
+ /** One entry of prime-memory's distillation route chain. */
15
+ export interface DistillChainEntry {
16
+ readonly provider: string;
17
+ readonly model: string;
18
+ readonly reasoningEffort?: string;
19
+ }
20
+ /** The loader row id prime-memory is composed under (fixed by its bundle patch). */
21
+ export declare const PRIME_MEMORY_ENTRY_ID = "dsh-memory";
22
+ /** The package name that identifies the row; the authoritative identity. */
23
+ export declare const PRIME_MEMORY_PACKAGE = "dsh-prime-memory";
24
+ /** The subset of a loader entry this adapter reads. */
25
+ export interface RowLike {
26
+ readonly options?: {
27
+ readonly id?: unknown;
28
+ readonly name?: unknown;
29
+ };
30
+ }
31
+ /**
32
+ * Whether one loader entry is prime-memory.
33
+ *
34
+ * The package name wins over the row id: a profile layer may rename the row,
35
+ * while an unrelated row could recycle the id.
36
+ * @param entry - the loader entry to test.
37
+ * @returns True for prime-memory's row.
38
+ */
39
+ export declare function isPrimeMemoryRow(entry: RowLike | undefined): boolean;
40
+ /**
41
+ * The prime-memory rows present in one loader tree.
42
+ * @param entries - the loader's entries.
43
+ * @returns Matching rows, in loader order.
44
+ */
45
+ export declare function primeMemoryRows<T extends RowLike>(entries: Iterable<T>): T[];
46
+ /**
47
+ * The chain prime-memory should use, given the route Model Switch wants.
48
+ *
49
+ * The chosen route goes first; the entries prime-memory already had follow in
50
+ * their own order, minus any route that duplicates the chosen one (a duplicate
51
+ * is a guaranteed second failure, not a fallback). An empty chosen route leaves
52
+ * the existing chain untouched.
53
+ * @param primary - the route Model Switch wants first, if any.
54
+ * @param existing - prime-memory's current chain, as read from its settings.
55
+ * @returns The chain to write; empty when neither side has a complete route.
56
+ */
57
+ export declare function planDistillChain(primary: {
58
+ readonly provider?: string;
59
+ readonly model?: string;
60
+ readonly reasoningEffort?: string;
61
+ } | undefined, existing: readonly DistillChainEntry[] | undefined): readonly DistillChainEntry[];
62
+ /**
63
+ * The settings patch that writes one distillation chain.
64
+ *
65
+ * Only the `distillChain` key is produced: prime-memory's `live` section carries
66
+ * unrelated switches (capture, trace, embedding, memory mutation), and a patch
67
+ * naming them would rewrite the user's choices.
68
+ * @param chain - the chain to write.
69
+ * @returns The `live` patch to pass to `ctx.settings.update`.
70
+ */
71
+ export declare function distillChainPatch(chain: readonly DistillChainEntry[]): {
72
+ readonly live: {
73
+ readonly distillChain: readonly DistillChainEntry[];
74
+ };
75
+ };
@@ -12,7 +12,7 @@
12
12
  * All functions here are pure and never throw on malformed storage.
13
13
  */
14
14
  /** Flat settings fields a provider group carries across all four per-session capabilities. */
15
- export type ProviderGroupRouteField = 'compactProvider' | 'compactModel' | 'autoReviewProvider' | 'autoReviewModel' | 'subagentProvider' | 'subagentModel' | 'subagentReasoningEffort' | 'titleProvider' | 'titleModel';
15
+ export type ProviderGroupRouteField = 'compactProvider' | 'compactModel' | 'autoReviewProvider' | 'autoReviewModel' | 'subagentProvider' | 'subagentModel' | 'subagentReasoningEffort' | 'titleProvider' | 'titleModel' | 'memoryProvider' | 'memoryModel';
16
16
  /** Stored entry: the owning provider plus every route field; '' means the capability stays at its default. */
17
17
  export interface ProviderGroupEntry {
18
18
  provider: string;
@@ -25,6 +25,9 @@ export interface ProviderGroupEntry {
25
25
  subagentReasoningEffort: string;
26
26
  titleProvider: string;
27
27
  titleModel: string;
28
+ /** Distillation route for the memory plugin; '' keeps that plugin's own default. */
29
+ memoryProvider: string;
30
+ memoryModel: string;
28
31
  }
29
32
  /** Normalized view of one provider's group; absent fields follow their default state. */
30
33
  export type ProviderGroupConfig = Partial<Record<ProviderGroupRouteField, string>>;
@@ -23,7 +23,7 @@ import type { Context } from '@deepseek-ai/cordis';
23
23
  import type { Session } from '@deepseek-ai/dsh-session';
24
24
  import { type ProviderGroups } from './provider-group.js';
25
25
  /** Capabilities whose route can be derived per session. */
26
- export type CapabilityId = 'compaction' | 'autoReview' | 'title' | 'subagent';
26
+ export type CapabilityId = 'compaction' | 'autoReview' | 'title' | 'subagent' | 'memory';
27
27
  /** A complete pinned route; either half missing means "follow the default". */
28
28
  export interface CapabilityRoute {
29
29
  readonly provider: string;
@@ -45,6 +45,8 @@ export interface RouteBearingSettings {
45
45
  readonly compactModel?: string;
46
46
  readonly titleProvider?: string;
47
47
  readonly titleModel?: string;
48
+ readonly memoryProvider?: string;
49
+ readonly memoryModel?: string;
48
50
  readonly providerGroups?: ProviderGroups;
49
51
  }
50
52
  /**
@@ -54,6 +56,19 @@ export interface RouteBearingSettings {
54
56
  * @returns The complete pair, or undefined when the capability stays at its official/derived default.
55
57
  */
56
58
  export declare function deploymentRoute(settings: RouteBearingSettings | undefined, capability: CapabilityId): CapabilityRoute | undefined;
59
+ /**
60
+ * The distillation route one deployment should use.
61
+ *
62
+ * Distillation is a background pipeline with no session of its own, so the group
63
+ * key is the deployment default provider (the provider the profile starts
64
+ * sessions on) rather than a session's provider. A provider without a group falls
65
+ * back to the flat memory pair; an empty pair leaves the memory plugin at its own
66
+ * default.
67
+ * @param settings - live Model Switch settings.
68
+ * @param provider - the deployment default provider, when one is observable.
69
+ * @returns The complete pair, or undefined when nothing is pinned.
70
+ */
71
+ export declare function memoryRouteOf(settings: RouteBearingSettings | undefined, provider: string | undefined): CapabilityRoute | undefined;
57
72
  /** One capability's route plus the reasoning effort a subagent spawn also carries. */
58
73
  export interface SubagentRoute extends CapabilityRoute {
59
74
  readonly reasoningEffort?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "dsh-model-switch",
3
- "version": "0.4.43",
3
+ "version": "0.4.45",
4
4
  "description": "Explicit model routing plus composer/Plan picker for DeepSeek Harness",
5
5
  "repository": {
6
6
  "type": "git",
@@ -62,6 +62,10 @@
62
62
  "types": "./lib/types/automode-compat.d.ts",
63
63
  "default": "./lib/automode-compat.js"
64
64
  },
65
+ "./prime-memory-compat": {
66
+ "types": "./lib/types/prime-memory-compat.d.ts",
67
+ "default": "./lib/prime-memory-compat.js"
68
+ },
65
69
  "./package.json": "./package.json"
66
70
  },
67
71
  "files": [