dsh-model-switch 0.4.41 → 0.4.42

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.
@@ -1,172 +0,0 @@
1
- import { t as groupOf } from "./provider-group-CwadImhH.js";
2
- //#region lib/types/session-route.js
3
- /**
4
- * Per-session capability route derivation.
5
- *
6
- * Model Switch stores one deployment-wide route per capability (the flat
7
- * settings fields) plus, per provider, a saved provider group. Nothing is
8
- * written when a session changes provider: this module DERIVES the route a
9
- * capability should use for one session from (a) the session's own provider and
10
- * (b) the stored group table. Two sessions on different providers therefore
11
- * resolve independently, and no session's actions rewrite another session's
12
- * route.
13
- *
14
- * The session's provider is read from durable, official state in this order:
15
- * the `modelSelection` session projection (`pending` before `lastUsed`, so a
16
- * selection the user just made counts), then the latest logged request-context
17
- * route, then the latest `request/header` route. Every read is optional: a
18
- * session with no observable provider, an unregistered projection, or a
19
- * profile without the projection package all resolve to the deployment default,
20
- * which is exactly the pre-derivation behavior.
21
- *
22
- * All functions are pure except the readers, which never throw and never write.
23
- */
24
- /** Flat deployment-default fields per capability, in group-storage field names. */
25
- const CAPABILITY_FIELDS = Object.freeze({
26
- compaction: {
27
- provider: "compactProvider",
28
- model: "compactModel"
29
- },
30
- autoReview: {
31
- provider: "autoReviewProvider",
32
- model: "autoReviewModel"
33
- },
34
- title: {
35
- provider: "titleProvider",
36
- model: "titleModel"
37
- },
38
- subagent: {
39
- provider: "subagentProvider",
40
- model: "subagentModel"
41
- }
42
- });
43
- /** A non-blank string; blank values behave exactly like an absent field. */
44
- function present(value) {
45
- return typeof value === "string" && value.trim() !== "";
46
- }
47
- /** Read one capability's pair from a flat route record; undefined unless both halves are present. */
48
- function pairOf(source, fields) {
49
- if (source === void 0) return void 0;
50
- const record = source;
51
- const provider = record[fields.provider];
52
- const model = record[fields.model];
53
- if (!present(provider) || !present(model)) return void 0;
54
- return {
55
- provider,
56
- model
57
- };
58
- }
59
- /**
60
- * The deployment-wide route for one capability: the flat settings pair.
61
- * @param settings - live Model Switch settings; undefined means none are reachable.
62
- * @param capability - capability whose flat pair is read.
63
- * @returns The complete pair, or undefined when the capability stays at its official/derived default.
64
- */
65
- function deploymentRoute(settings, capability) {
66
- return pairOf(settings, CAPABILITY_FIELDS[capability]);
67
- }
68
- /**
69
- * The route a subagent spawn should use for one parent-session provider.
70
- *
71
- * A saved group for that provider pins the spawn; otherwise the flat Subagent
72
- * card pins it, but only in `fixed` mode — `follow-main` IS the official inherit
73
- * path, expressed by leaving the request untouched rather than by naming it.
74
- * @param settings - live Model Switch settings.
75
- * @param provider - the delegating session's provider, when one is observable.
76
- * @returns The complete route, or undefined for official inherit.
77
- */
78
- function subagentRouteOf(settings, provider) {
79
- const group = groupRoute(settings, provider, "subagent");
80
- if (group !== void 0) {
81
- const effort = groupOf(settings?.providerGroups, provider ?? "")?.subagentReasoningEffort;
82
- return present(effort) ? {
83
- ...group,
84
- reasoningEffort: effort
85
- } : group;
86
- }
87
- if (settings?.subagentMode !== "fixed") return void 0;
88
- const fixed = deploymentRoute(settings, "subagent");
89
- if (fixed === void 0) return void 0;
90
- return present(settings.subagentReasoningEffort) ? {
91
- ...fixed,
92
- reasoningEffort: settings.subagentReasoningEffort
93
- } : fixed;
94
- }
95
- /**
96
- * One provider's saved route for one capability.
97
- * @param settings - live Model Switch settings carrying the group table.
98
- * @param provider - the session's provider; blank or unknown resolves to undefined.
99
- * @param capability - capability whose group pin is read.
100
- * @returns The complete group pair, or undefined when the group pins nothing here.
101
- */
102
- function groupRoute(settings, provider, capability) {
103
- if (!present(provider)) return void 0;
104
- return pairOf(groupOf(settings?.providerGroups, provider), CAPABILITY_FIELDS[capability]);
105
- }
106
- /**
107
- * The route one capability should use for one session.
108
- *
109
- * A saved provider group for the session's provider wins; otherwise the flat
110
- * deployment default applies. An unknown session provider skips every group, so
111
- * a session Model Switch cannot attribute keeps the deployment default.
112
- * @param settings - live Model Switch settings.
113
- * @param provider - the session's provider, when one is observable.
114
- * @param capability - capability being resolved.
115
- * @returns The complete pair, or undefined for the capability's official default.
116
- */
117
- function resolveCapabilityRoute(settings, provider, capability) {
118
- return groupRoute(settings, provider, capability) ?? deploymentRoute(settings, capability);
119
- }
120
- /**
121
- * Read the provider from the durable model-selection projection.
122
- * @param ctx - context that may expose `sessionProjections`.
123
- * @param session - the session whose selection is read.
124
- * @returns The pending provider, else the last-used provider, else undefined.
125
- */
126
- function projectionProvider(ctx, session) {
127
- let state;
128
- try {
129
- state = ctx.get("sessionProjections", false)?.stateOf(session, "modelSelection");
130
- } catch {
131
- state = void 0;
132
- }
133
- if (state === void 0) return void 0;
134
- if (present(state.pending?.provider)) return state.pending.provider;
135
- if (present(state.lastUsed?.provider)) return state.lastUsed.provider;
136
- }
137
- /**
138
- * The provider one session is using, from official durable state.
139
- *
140
- * Preferred source is the session's own model selection (it covers a switch the
141
- * client has sent but no request has consumed yet); the logged request-context
142
- * and request-header routes cover profiles without the projection package and
143
- * replayed sessions that never emitted a selection.
144
- * @param ctx - context used for the optional projection read.
145
- * @param session - the session to resolve; undefined resolves to undefined.
146
- * @returns The provider, or undefined when nothing durable names one.
147
- */
148
- function sessionProviderOf(ctx, session) {
149
- if (session === void 0) return void 0;
150
- const selected = projectionProvider(ctx, session);
151
- if (selected !== void 0) return selected;
152
- try {
153
- const context = session.requestContext()?.provider;
154
- if (present(context)) return context;
155
- const header = session.requestHeader()?.config.provider;
156
- if (present(header)) return header;
157
- } catch {
158
- return;
159
- }
160
- }
161
- /**
162
- * The subagent route one exact session's spawns should use.
163
- * @param ctx - context used for the optional session reads.
164
- * @param session - the delegating session; undefined keeps official inherit.
165
- * @param settings - live Model Switch settings.
166
- * @returns The complete route, or undefined for official inherit.
167
- */
168
- function sessionSubagentRouteOf(ctx, session, settings) {
169
- return subagentRouteOf(settings, sessionProviderOf(ctx, session));
170
- }
171
- //#endregion
172
- export { sessionProviderOf as n, sessionSubagentRouteOf as r, resolveCapabilityRoute as t };
@@ -1,172 +0,0 @@
1
- import { t as groupOf } from "./provider-group-CwadImhH.js";
2
- //#region lib/types/session-route.js
3
- /**
4
- * Per-session capability route derivation.
5
- *
6
- * Model Switch stores one deployment-wide route per capability (the flat
7
- * settings fields) plus, per provider, a saved provider group. Nothing is
8
- * written when a session changes provider: this module DERIVES the route a
9
- * capability should use for one session from (a) the session's own provider and
10
- * (b) the stored group table. Two sessions on different providers therefore
11
- * resolve independently, and no session's actions rewrite another session's
12
- * route.
13
- *
14
- * The session's provider is read from durable, official state in this order:
15
- * the `modelSelection` session projection (`pending` before `lastUsed`, so a
16
- * selection the user just made counts), then the latest logged request-context
17
- * route, then the latest `request/header` route. Every read is optional: a
18
- * session with no observable provider, an unregistered projection, or a
19
- * profile without the projection package all resolve to the deployment default,
20
- * which is exactly the pre-derivation behavior.
21
- *
22
- * All functions are pure except the readers, which never throw and never write.
23
- */
24
- /** Flat deployment-default fields per capability, in group-storage field names. */
25
- const CAPABILITY_FIELDS = Object.freeze({
26
- compaction: {
27
- provider: "compactProvider",
28
- model: "compactModel"
29
- },
30
- autoReview: {
31
- provider: "autoReviewProvider",
32
- model: "autoReviewModel"
33
- },
34
- title: {
35
- provider: "titleProvider",
36
- model: "titleModel"
37
- },
38
- subagent: {
39
- provider: "subagentProvider",
40
- model: "subagentModel"
41
- }
42
- });
43
- /** A non-blank string; blank values behave exactly like an absent field. */
44
- function present(value) {
45
- return typeof value === "string" && value.trim() !== "";
46
- }
47
- /** Read one capability's pair from a flat route record; undefined unless both halves are present. */
48
- function pairOf(source, fields) {
49
- if (source === void 0) return void 0;
50
- const record = source;
51
- const provider = record[fields.provider];
52
- const model = record[fields.model];
53
- if (!present(provider) || !present(model)) return void 0;
54
- return {
55
- provider,
56
- model
57
- };
58
- }
59
- /**
60
- * The deployment-wide route for one capability: the flat settings pair.
61
- * @param settings - live Model Switch settings; undefined means none are reachable.
62
- * @param capability - capability whose flat pair is read.
63
- * @returns The complete pair, or undefined when the capability stays at its official/derived default.
64
- */
65
- function deploymentRoute(settings, capability) {
66
- return pairOf(settings, CAPABILITY_FIELDS[capability]);
67
- }
68
- /**
69
- * The route a subagent spawn should use for one parent-session provider.
70
- *
71
- * A saved group for that provider pins the spawn; otherwise the flat Subagent
72
- * card pins it, but only in `fixed` mode — `follow-main` IS the official inherit
73
- * path, expressed by leaving the request untouched rather than by naming it.
74
- * @param settings - live Model Switch settings.
75
- * @param provider - the delegating session's provider, when one is observable.
76
- * @returns The complete route, or undefined for official inherit.
77
- */
78
- function subagentRouteOf(settings, provider) {
79
- const group = groupRoute(settings, provider, "subagent");
80
- if (group !== void 0) {
81
- const effort = groupOf(settings?.providerGroups, provider ?? "")?.subagentReasoningEffort;
82
- return present(effort) ? {
83
- ...group,
84
- reasoningEffort: effort
85
- } : group;
86
- }
87
- if (settings?.subagentMode !== "fixed") return void 0;
88
- const fixed = deploymentRoute(settings, "subagent");
89
- if (fixed === void 0) return void 0;
90
- return present(settings.subagentReasoningEffort) ? {
91
- ...fixed,
92
- reasoningEffort: settings.subagentReasoningEffort
93
- } : fixed;
94
- }
95
- /**
96
- * One provider's saved route for one capability.
97
- * @param settings - live Model Switch settings carrying the group table.
98
- * @param provider - the session's provider; blank or unknown resolves to undefined.
99
- * @param capability - capability whose group pin is read.
100
- * @returns The complete group pair, or undefined when the group pins nothing here.
101
- */
102
- function groupRoute(settings, provider, capability) {
103
- if (!present(provider)) return void 0;
104
- return pairOf(groupOf(settings?.providerGroups, provider), CAPABILITY_FIELDS[capability]);
105
- }
106
- /**
107
- * The route one capability should use for one session.
108
- *
109
- * A saved provider group for the session's provider wins; otherwise the flat
110
- * deployment default applies. An unknown session provider skips every group, so
111
- * a session Model Switch cannot attribute keeps the deployment default.
112
- * @param settings - live Model Switch settings.
113
- * @param provider - the session's provider, when one is observable.
114
- * @param capability - capability being resolved.
115
- * @returns The complete pair, or undefined for the capability's official default.
116
- */
117
- function resolveCapabilityRoute(settings, provider, capability) {
118
- return groupRoute(settings, provider, capability) ?? deploymentRoute(settings, capability);
119
- }
120
- /**
121
- * Read the provider from the durable model-selection projection.
122
- * @param ctx - context that may expose `sessionProjections`.
123
- * @param session - the session whose selection is read.
124
- * @returns The pending provider, else the last-used provider, else undefined.
125
- */
126
- function projectionProvider(ctx, session) {
127
- let state;
128
- try {
129
- state = ctx.get("sessionProjections", false)?.stateOf(session, "modelSelection");
130
- } catch {
131
- state = void 0;
132
- }
133
- if (state === void 0) return void 0;
134
- if (present(state.pending?.provider)) return state.pending.provider;
135
- if (present(state.lastUsed?.provider)) return state.lastUsed.provider;
136
- }
137
- /**
138
- * The provider one session is using, from official durable state.
139
- *
140
- * Preferred source is the session's own model selection (it covers a switch the
141
- * client has sent but no request has consumed yet); the logged request-context
142
- * and request-header routes cover profiles without the projection package and
143
- * replayed sessions that never emitted a selection.
144
- * @param ctx - context used for the optional projection read.
145
- * @param session - the session to resolve; undefined resolves to undefined.
146
- * @returns The provider, or undefined when nothing durable names one.
147
- */
148
- function sessionProviderOf(ctx, session) {
149
- if (session === void 0) return void 0;
150
- const selected = projectionProvider(ctx, session);
151
- if (selected !== void 0) return selected;
152
- try {
153
- const context = session.requestContext()?.provider;
154
- if (present(context)) return context;
155
- const header = session.requestHeader()?.config.provider;
156
- if (present(header)) return header;
157
- } catch {
158
- return;
159
- }
160
- }
161
- /**
162
- * The subagent route one exact session's spawns should use.
163
- * @param ctx - context used for the optional session reads.
164
- * @param session - the delegating session; undefined keeps official inherit.
165
- * @param settings - live Model Switch settings.
166
- * @returns The complete route, or undefined for official inherit.
167
- */
168
- function sessionSubagentRouteOf(ctx, session, settings) {
169
- return subagentRouteOf(settings, sessionProviderOf(ctx, session));
170
- }
171
- //#endregion
172
- export { sessionSubagentRouteOf as a, sessionProviderOf as i, groupRoute as n, resolveCapabilityRoute as r, deploymentRoute as t };