dsh-model-switch 0.4.61 → 0.4.63
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/CHANGELOG.md +16 -1
- package/cordis.patch.yml +3 -6
- package/lib/client.js +246 -74
- package/lib/session-title.js +77 -27
- package/lib/subagent-runtime.js +181 -200
- package/lib/types/client/ModelSwitchSettings.d.ts +2 -2
- package/lib/types/client/locales.d.ts +3 -0
- package/lib/types/client/main-row-controller.d.ts +63 -9
- package/lib/types/client/picker/popup-placement.d.ts +53 -0
- package/lib/types/client/picker/useComposerPickerSurface.d.ts +2 -3
- package/lib/types/subagent-runtime-legacy.d.ts +34 -0
- package/lib/types/subagent-runtime.d.ts +36 -101
- package/lib/types/title-settings-reader.d.ts +34 -0
- package/package.json +3 -2
package/lib/session-title.js
CHANGED
|
@@ -1,4 +1,69 @@
|
|
|
1
1
|
import { a as sessionProviderOf, n as groupRoute, t as deploymentRoute } from "./session-route-D8izd8Zd.js";
|
|
2
|
+
//#region lib/types/title-settings-reader.js
|
|
3
|
+
/**
|
|
4
|
+
* Safe reads of the optional Model Switch settings service for the naming row.
|
|
5
|
+
*
|
|
6
|
+
* The session-naming row must keep the official naming behavior when the
|
|
7
|
+
* `model-switch` row is absent, so `modelSwitch` can never join the row's own
|
|
8
|
+
* `inject` list: Cordis waits for every declared dependency before a fiber
|
|
9
|
+
* loads (there is no "optional" inject), and a never-provided service would
|
|
10
|
+
* leave the row pending forever.
|
|
11
|
+
*
|
|
12
|
+
* Two reads are tried per call, in this order:
|
|
13
|
+
*
|
|
14
|
+
* 1. `ctx.get('modelSwitch')` with Cordis' default strict mode — the active
|
|
15
|
+
* implementation only, or undefined. This is the read the shipped row used
|
|
16
|
+
* and it keeps working across a settings-row rebuild because the store
|
|
17
|
+
* entry is replaced, not cached here.
|
|
18
|
+
* 2. A scoped `ctx.inject(['modelSwitch'])` child fiber, which binds a
|
|
19
|
+
* dependent scope and resets it on dispose. This covers compositions where
|
|
20
|
+
* the strict store read is invisible from the row's own entry context.
|
|
21
|
+
*
|
|
22
|
+
* The returned function identity is stable for the row's lifetime and every
|
|
23
|
+
* call re-reads, so a settings save or a service rebuild needs no remount.
|
|
24
|
+
* Reads never throw: a missing face, a disposed scope, or a throwing read all
|
|
25
|
+
* answer undefined, which means "official behavior" to the caller.
|
|
26
|
+
*
|
|
27
|
+
* @module dsh-model-switch/title-settings-reader
|
|
28
|
+
*/
|
|
29
|
+
/** Accept only a settings object; anything else is the official "no settings" answer. */
|
|
30
|
+
function settingsOf(value) {
|
|
31
|
+
if (value === null || typeof value !== "object") return void 0;
|
|
32
|
+
const service = value;
|
|
33
|
+
if (typeof service.currentSettings !== "function") return void 0;
|
|
34
|
+
const settings = service.currentSettings();
|
|
35
|
+
return settings !== null && typeof settings === "object" ? settings : void 0;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Create the settings reader for one naming row context.
|
|
39
|
+
* @param ctx - this row's context (the row fiber's own scope).
|
|
40
|
+
* @returns The reader: per-request live settings, or undefined when unavailable.
|
|
41
|
+
*/
|
|
42
|
+
function titleSettingsReaderOf(ctx) {
|
|
43
|
+
let scoped;
|
|
44
|
+
ctx.inject(["modelSwitch"], (scope) => {
|
|
45
|
+
scope.effect(() => {
|
|
46
|
+
scoped = scope;
|
|
47
|
+
return () => {
|
|
48
|
+
if (scoped === scope) scoped = void 0;
|
|
49
|
+
};
|
|
50
|
+
}, "model-switch: session-title settings reader");
|
|
51
|
+
});
|
|
52
|
+
return () => {
|
|
53
|
+
try {
|
|
54
|
+
const direct = settingsOf(ctx.get("modelSwitch"));
|
|
55
|
+
if (direct !== void 0) return direct;
|
|
56
|
+
} catch {}
|
|
57
|
+
const scope = scoped;
|
|
58
|
+
if (scope === void 0) return void 0;
|
|
59
|
+
try {
|
|
60
|
+
return settingsOf(scope.modelSwitch);
|
|
61
|
+
} catch {
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
//#endregion
|
|
2
67
|
//#region lib/types/session-title.js
|
|
3
68
|
/**
|
|
4
69
|
* Model Switch-owned session-naming row.
|
|
@@ -479,8 +544,8 @@ async function runTitleCall(ctx, module, plan, request, attempt) {
|
|
|
479
544
|
* @returns The official provider result.
|
|
480
545
|
* @throws The last candidate failure when every candidate fails.
|
|
481
546
|
*/
|
|
482
|
-
async function generateTitle(ctx, module, plan, request) {
|
|
483
|
-
const candidates = titleRouteCandidates(
|
|
547
|
+
async function generateTitle(ctx, module, plan, request, settingsReader) {
|
|
548
|
+
const candidates = titleRouteCandidates(settingsReader(), sessionProviderOf(ctx, request.session), plan.config, request.route);
|
|
484
549
|
const attempts = candidates.length === 0 ? [{
|
|
485
550
|
route: void 0,
|
|
486
551
|
config: plan.config
|
|
@@ -513,23 +578,6 @@ async function generateTitle(ctx, module, plan, request) {
|
|
|
513
578
|
if (!request.signal.aborted) ctx.logger.warn(`model-switch: session title generation failed on every candidate (${tried}): ${String(lastError)}`);
|
|
514
579
|
throw lastError;
|
|
515
580
|
}
|
|
516
|
-
/**
|
|
517
|
-
* Read live Model Switch settings without requiring the host row.
|
|
518
|
-
*
|
|
519
|
-
* The host is read structurally instead of injected so this row keeps mirroring
|
|
520
|
-
* the official naming behavior when the `model-switch` row is disabled: an
|
|
521
|
-
* unreachable host resolves to the row's own policy rather than to a pinned
|
|
522
|
-
* route.
|
|
523
|
-
* @param ctx - this row's context.
|
|
524
|
-
* @returns The settings, or undefined when the host is unavailable.
|
|
525
|
-
*/
|
|
526
|
-
function currentSettings(ctx) {
|
|
527
|
-
try {
|
|
528
|
-
return ctx.get("modelSwitch", false)?.currentSettings();
|
|
529
|
-
} catch {
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
}
|
|
533
581
|
/** Resolve the naming plan for one official row, or the shipped defaults when no row exists. */
|
|
534
582
|
function planFor(ctx, module, entry) {
|
|
535
583
|
const cadence = titleCadence(entry === void 0 ? void 0 : officialTitlePackage(entry)) ?? TITLE_CADENCES[0];
|
|
@@ -550,11 +598,11 @@ function planFor(ctx, module, entry) {
|
|
|
550
598
|
};
|
|
551
599
|
}
|
|
552
600
|
/** One naming plan bound to a live route resolver. */
|
|
553
|
-
function providerOf(ctx, module, plan) {
|
|
601
|
+
function providerOf(ctx, module, plan, settingsReader) {
|
|
554
602
|
return {
|
|
555
603
|
id: plan.cadence.id,
|
|
556
604
|
automatic: plan.cadence.automatic,
|
|
557
|
-
generate: (request) => generateTitle(ctx, module, plan, request)
|
|
605
|
+
generate: (request) => generateTitle(ctx, module, plan, request, settingsReader)
|
|
558
606
|
};
|
|
559
607
|
}
|
|
560
608
|
/** Timing knobs for the takeover choreography (exported for tests). */
|
|
@@ -578,11 +626,13 @@ const TAKEOVER_MAX_ATTEMPTS = 20;
|
|
|
578
626
|
var NamingSeam = class {
|
|
579
627
|
ctx;
|
|
580
628
|
module;
|
|
629
|
+
settingsReader;
|
|
581
630
|
disposer;
|
|
582
631
|
plan;
|
|
583
|
-
constructor(ctx, module, plan) {
|
|
632
|
+
constructor(ctx, module, settingsReader, plan) {
|
|
584
633
|
this.ctx = ctx;
|
|
585
634
|
this.module = module;
|
|
635
|
+
this.settingsReader = settingsReader;
|
|
586
636
|
this.plan = plan;
|
|
587
637
|
}
|
|
588
638
|
/** The cadence currently registered. */
|
|
@@ -602,7 +652,7 @@ var NamingSeam = class {
|
|
|
602
652
|
this.plan = plan;
|
|
603
653
|
if (this.disposer !== void 0) return true;
|
|
604
654
|
try {
|
|
605
|
-
this.disposer = this.ctx.sessionTitle.register(providerOf(this.ctx, this.module, plan));
|
|
655
|
+
this.disposer = this.ctx.sessionTitle.register(providerOf(this.ctx, this.module, plan, this.settingsReader));
|
|
606
656
|
return true;
|
|
607
657
|
} catch {
|
|
608
658
|
return false;
|
|
@@ -725,8 +775,7 @@ function installTakeover(ctx, module, seam) {
|
|
|
725
775
|
* the real Host always provides one of them.
|
|
726
776
|
*/
|
|
727
777
|
const entryOfEvent = (self, first) => {
|
|
728
|
-
const candidate
|
|
729
|
-
return candidate !== null && typeof candidate === "object" && "options" in candidate ? candidate : void 0;
|
|
778
|
+
for (const candidate of [first, self]) if (candidate !== null && typeof candidate === "object" && "options" in candidate) return candidate;
|
|
730
779
|
};
|
|
731
780
|
const listeners = [];
|
|
732
781
|
const listen = (event, listener) => {
|
|
@@ -755,9 +804,9 @@ function installTakeover(ctx, module, seam) {
|
|
|
755
804
|
reclaim(entry, plan);
|
|
756
805
|
});
|
|
757
806
|
listen("loader/partial-dispose", function(first) {
|
|
758
|
-
seam.yieldSlot();
|
|
759
807
|
const entry = entryOfEvent(this, first);
|
|
760
808
|
if (entry === void 0 || !isOfficialTitleRow(entry)) return;
|
|
809
|
+
seam.yieldSlot();
|
|
761
810
|
handled.delete(entry);
|
|
762
811
|
if (seam.claimed) return;
|
|
763
812
|
const plan = planFor(ctx, module, officialTitleEntry(ctx.get("loader", false)));
|
|
@@ -797,6 +846,7 @@ function installTakeover(ctx, module, seam) {
|
|
|
797
846
|
* @param ctx - this row's context.
|
|
798
847
|
*/
|
|
799
848
|
async function apply(ctx) {
|
|
849
|
+
const settingsReader = titleSettingsReaderOf(ctx);
|
|
800
850
|
const entry = officialTitleEntry(ctx.get("loader", false));
|
|
801
851
|
if (entry === void 0) ctx.logger.info("model-switch: no instantiated official session-title row to mirror; naming uses the first-prompt cadence");
|
|
802
852
|
let module;
|
|
@@ -809,7 +859,7 @@ async function apply(ctx) {
|
|
|
809
859
|
}
|
|
810
860
|
const plan = planFor(ctx, module, entry);
|
|
811
861
|
if (plan === void 0) return;
|
|
812
|
-
const seam = new NamingSeam(ctx, module, plan);
|
|
862
|
+
const seam = new NamingSeam(ctx, module, settingsReader, plan);
|
|
813
863
|
if (!(enabledOfficialRows(ctx).length > 0) && !seam.claim()) ctx.logger.info("model-switch: another session-title provider already owns the seam; naming follows it while it is active");
|
|
814
864
|
installTakeover(ctx, module, seam);
|
|
815
865
|
}
|
package/lib/subagent-runtime.js
CHANGED
|
@@ -1,105 +1,22 @@
|
|
|
1
1
|
import { o as sessionSubagentRouteOf } from "./session-route-D8izd8Zd.js";
|
|
2
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
2
3
|
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
3
4
|
import OfficialSubagentRuntime from "@deepseek-ai/dsh-subagent";
|
|
4
|
-
//#region lib/types/subagent-runtime.js
|
|
5
|
-
/**
|
|
5
|
+
//#region lib/types/subagent-runtime-legacy.js
|
|
6
|
+
/** Previously published startup error; retained for consumers of this module. */
|
|
6
7
|
var StartupIncompatibilityError = class extends Error {
|
|
7
8
|
name = "StartupIncompatibilityError";
|
|
8
9
|
surface;
|
|
9
|
-
/**
|
|
10
|
-
* @param surfaceOrMessage - the incompatible public surface, or the error message.
|
|
11
|
-
* @param message - the missing or incompatible requirement.
|
|
12
|
-
*/
|
|
13
10
|
constructor(surfaceOrMessage, message) {
|
|
14
11
|
super(message ?? surfaceOrMessage);
|
|
15
12
|
this.surface = message === void 0 ? "startup" : surfaceOrMessage;
|
|
16
13
|
}
|
|
17
14
|
};
|
|
18
|
-
|
|
19
|
-
return typeof value === "string" && value.trim() !== "";
|
|
20
|
-
}
|
|
21
|
-
function spawnHasAnyRouteField(options) {
|
|
22
|
-
return present(options?.provider) || present(options?.model) || options?.reasoningEffort !== void 0;
|
|
23
|
-
}
|
|
24
|
-
/**
|
|
25
|
-
* Inject one resolved route into a spawn that names none.
|
|
26
|
-
*
|
|
27
|
-
* A spawn that already names a provider, model, or effort keeps it: the caller's
|
|
28
|
-
* explicit selection outranks any profile policy. The route itself is derived
|
|
29
|
-
* from the DELEGATING session (its provider selects a saved group, else the flat
|
|
30
|
-
* Subagent card in `fixed` mode), so two sessions on different providers route
|
|
31
|
-
* their own spawns and neither can rewrite the other's policy.
|
|
32
|
-
* @param request - the caller's spawn request.
|
|
33
|
-
* @param route - the delegating session's resolved route, or undefined for official inherit.
|
|
34
|
-
* @returns The request to hand the official runtime.
|
|
35
|
-
*/
|
|
36
|
-
function routeSubagentRequest(request, route) {
|
|
37
|
-
if (spawnHasAnyRouteField(request.agentOptions)) return request;
|
|
38
|
-
if (route === void 0) return request;
|
|
39
|
-
return {
|
|
40
|
-
...request,
|
|
41
|
-
agentOptions: {
|
|
42
|
-
...request.agentOptions,
|
|
43
|
-
provider: route.provider,
|
|
44
|
-
model: route.model,
|
|
45
|
-
...route.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(route.reasoningEffort) }
|
|
46
|
-
}
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
function assertPublicMethod(value, surface, method) {
|
|
50
|
-
if (value === null || typeof value !== "object" && typeof value !== "function" || typeof Reflect.get(value, method) !== "function") throw new StartupIncompatibilityError(surface, surface + " must expose public " + method + "()");
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Classify the runtime surface this Host publishes.
|
|
54
|
-
*
|
|
55
|
-
* DSH 0.2.1 replaced `start()` / `startContinuable()` with the activation API
|
|
56
|
-
* (`startActivation`), so a version-agnostic adapter has to recognize both
|
|
57
|
-
* lines instead of hard-coding one.
|
|
58
|
-
*
|
|
59
|
-
* @param value - a runtime class's prototype or a mounted runtime instance.
|
|
60
|
-
* @returns `activation` (0.2.1+), `start` (0.1.7/0.2.0), or undefined when neither is published.
|
|
61
|
-
*/
|
|
15
|
+
/** Classify the two published start API generations without version guessing. */
|
|
62
16
|
function subagentSurfaceOf(value) {
|
|
63
17
|
if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
|
|
64
18
|
if (typeof Reflect.get(value, "startActivation") === "function") return "activation";
|
|
65
|
-
|
|
66
|
-
const hasContinuable = typeof Reflect.get(value, "startContinuable") === "function";
|
|
67
|
-
return hasStart && hasContinuable ? "start" : void 0;
|
|
68
|
-
}
|
|
69
|
-
/** Read one public method, failing with the typed startup error when it is absent. */
|
|
70
|
-
function publicMethod(prototype, surface, method) {
|
|
71
|
-
if (prototype === null || typeof prototype !== "object" && typeof prototype !== "function") throw new StartupIncompatibilityError(surface, surface + " must expose public " + method + "()");
|
|
72
|
-
const value = Reflect.get(prototype, method);
|
|
73
|
-
if (typeof value !== "function") throw new StartupIncompatibilityError(surface, surface + " must expose public " + method + "()");
|
|
74
|
-
return value;
|
|
75
|
-
}
|
|
76
|
-
function constructible(value) {
|
|
77
|
-
if (typeof value !== "function") return false;
|
|
78
|
-
try {
|
|
79
|
-
Reflect.construct(Object, [], value);
|
|
80
|
-
return true;
|
|
81
|
-
} catch (error) {
|
|
82
|
-
if (error instanceof TypeError) return false;
|
|
83
|
-
throw error;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
function assertOfficialRuntimeSurface() {
|
|
87
|
-
const runtime = OfficialSubagentRuntime;
|
|
88
|
-
if (!constructible(runtime)) throw new StartupIncompatibilityError("OfficialSubagentRuntime", "OfficialSubagentRuntime must be constructible");
|
|
89
|
-
const line = subagentSurfaceOf(Reflect.get(runtime, "prototype"));
|
|
90
|
-
if (line === void 0) throw new StartupIncompatibilityError("OfficialSubagentRuntime", "OfficialSubagentRuntime must expose public startActivation() (0.2.1+) or start()/startContinuable()");
|
|
91
|
-
return line;
|
|
92
|
-
}
|
|
93
|
-
function assertRoutingSurface(ctx) {
|
|
94
|
-
assertPublicMethod(ctx.get("modelSwitch", false), "Model Switch runtime", "currentSettings");
|
|
95
|
-
}
|
|
96
|
-
function routingSurface(ctx) {
|
|
97
|
-
return ctx.modelSwitch;
|
|
98
|
-
}
|
|
99
|
-
function assertMountedSurface(ctx) {
|
|
100
|
-
const service = ctx.subagents;
|
|
101
|
-
assertPublicMethod(service, "mounted Subagent runtime", "resolveMaxDepth");
|
|
102
|
-
if (subagentSurfaceOf(service) === void 0) throw new StartupIncompatibilityError("mounted Subagent runtime", "mounted Subagent runtime must expose public startActivation() (0.2.1+) or start()/startContinuable()");
|
|
19
|
+
return typeof Reflect.get(value, "start") === "function" && typeof Reflect.get(value, "startContinuable") === "function" ? "start" : void 0;
|
|
103
20
|
}
|
|
104
21
|
function once(dispose) {
|
|
105
22
|
let pending;
|
|
@@ -123,9 +40,9 @@ var CleanupLedger = class {
|
|
|
123
40
|
return failures;
|
|
124
41
|
}
|
|
125
42
|
};
|
|
126
|
-
function startupFailure(error,
|
|
127
|
-
if (
|
|
128
|
-
throw new AggregateError([error, ...
|
|
43
|
+
function startupFailure(error, failures) {
|
|
44
|
+
if (failures.length === 0) throw error;
|
|
45
|
+
throw new AggregateError([error, ...failures], "Subagent runtime startup and cleanup failed", { cause: error });
|
|
129
46
|
}
|
|
130
47
|
function cleanupDisposer(ledger) {
|
|
131
48
|
return async () => {
|
|
@@ -133,19 +50,7 @@ function cleanupDisposer(ledger) {
|
|
|
133
50
|
if (failures.length > 0) throw new AggregateError(failures, "Subagent runtime cleanup failed");
|
|
134
51
|
};
|
|
135
52
|
}
|
|
136
|
-
/**
|
|
137
|
-
* Mount a candidate and use the fallback only for typed startup incompatibility.
|
|
138
|
-
*
|
|
139
|
-
* Every resource registered by an attempt is disposed in reverse order before a
|
|
140
|
-
* fallback starts and again when the mounted result is disposed. Cleanup keeps
|
|
141
|
-
* running after failures, and a startup error stays first in any aggregate.
|
|
142
|
-
*
|
|
143
|
-
* @param candidate - startup callback for the routed candidate.
|
|
144
|
-
* @param fallback - startup callback for the untouched official runtime.
|
|
145
|
-
* @returns the selected value and an idempotent disposer.
|
|
146
|
-
* @throws the candidate error unless it is a StartupIncompatibilityError.
|
|
147
|
-
* @throws the fallback startup error when fallback startup fails.
|
|
148
|
-
*/
|
|
53
|
+
/** Retain the typed-only startup fallback and reverse, idempotent cleanup contract. */
|
|
149
54
|
async function mountWithStartupFallback(candidate, fallback) {
|
|
150
55
|
const ledger = new CleanupLedger();
|
|
151
56
|
try {
|
|
@@ -154,9 +59,8 @@ async function mountWithStartupFallback(candidate, fallback) {
|
|
|
154
59
|
dispose: cleanupDisposer(ledger)
|
|
155
60
|
};
|
|
156
61
|
} catch (error) {
|
|
157
|
-
const
|
|
158
|
-
if (!(error instanceof StartupIncompatibilityError)) startupFailure(error,
|
|
159
|
-
if (cleanupFailures.length > 0) startupFailure(error, cleanupFailures);
|
|
62
|
+
const failures = await ledger.disposeAll();
|
|
63
|
+
if (!(error instanceof StartupIncompatibilityError) || failures.length > 0) startupFailure(error, failures);
|
|
160
64
|
}
|
|
161
65
|
try {
|
|
162
66
|
return {
|
|
@@ -167,120 +71,197 @@ async function mountWithStartupFallback(candidate, fallback) {
|
|
|
167
71
|
startupFailure(error, await ledger.disposeAll());
|
|
168
72
|
}
|
|
169
73
|
}
|
|
170
|
-
/**
|
|
171
|
-
* Operator-facing notice for a Host whose Subagent runtime cannot be routed.
|
|
172
|
-
*
|
|
173
|
-
* DSH 0.2.1 replaced `start()`/`startContinuable()` with the activation API, so
|
|
174
|
-
* this adapter's override point is gone; the row then mounts the untouched
|
|
175
|
-
* official runtime instead of guessing a new seam.
|
|
176
|
-
* @param error - the typed startup incompatibility that rejected the candidate.
|
|
177
|
-
* @returns The notice logged once at startup.
|
|
178
|
-
*/
|
|
179
74
|
function routedRuntimeUnavailableNotice(error) {
|
|
180
75
|
return `model-switch: the routed Subagent runtime is unavailable on this DSH Host (${error.message}); delegation follows the official route instead`;
|
|
181
76
|
}
|
|
182
|
-
/**
|
|
183
|
-
function
|
|
184
|
-
|
|
185
|
-
ctx.logger.warn(message);
|
|
186
|
-
} catch {}
|
|
77
|
+
/** @deprecated Only the legacy subclass needs a mirrored dependency list. */
|
|
78
|
+
function subagentRuntimeInject(officialInject) {
|
|
79
|
+
return [.../* @__PURE__ */ new Set([...officialInject ?? [], "modelSwitch"])];
|
|
187
80
|
}
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
return async () => {
|
|
193
|
-
await official.dispose();
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
return (await mountWithStartupFallback(async (track) => {
|
|
197
|
-
try {
|
|
198
|
-
assertOfficialRuntimeSurface();
|
|
199
|
-
} catch (error) {
|
|
200
|
-
if (error instanceof StartupIncompatibilityError) reportNotice(ctx, routedRuntimeUnavailableNotice(error));
|
|
201
|
-
throw error;
|
|
202
|
-
}
|
|
203
|
-
assertRoutingSurface(ctx);
|
|
204
|
-
const candidate = ctx.plugin(ModelSwitchSubagentRuntime);
|
|
205
|
-
track(() => candidate.dispose());
|
|
206
|
-
await candidate;
|
|
207
|
-
const surface = ctx.inject(["subagents"], (surfaceCtx) => {
|
|
208
|
-
assertMountedSurface(surfaceCtx);
|
|
209
|
-
});
|
|
210
|
-
track(() => surface.dispose());
|
|
211
|
-
await surface;
|
|
212
|
-
return candidate;
|
|
213
|
-
}, async (track) => {
|
|
214
|
-
const official = ctx.plugin(OfficialSubagentRuntime);
|
|
215
|
-
track(() => official.dispose());
|
|
216
|
-
await official;
|
|
217
|
-
return official;
|
|
218
|
-
})).dispose;
|
|
81
|
+
function publicMethod(method) {
|
|
82
|
+
const value = Reflect.get(OfficialSubagentRuntime.prototype, method);
|
|
83
|
+
if (typeof value !== "function") throw new StartupIncompatibilityError("OfficialSubagentRuntime", `OfficialSubagentRuntime must expose public ${method}()`);
|
|
84
|
+
return value;
|
|
219
85
|
}
|
|
220
|
-
/** Profile replacement that selects the routed runtime or the untouched official runtime. */
|
|
221
|
-
const profileSubagentRuntime = Object.assign(async (ctx) => mountProfileRuntime(ctx), {});
|
|
222
86
|
/**
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* `inject` from the class it mounts — a static list on this subclass *replaces*
|
|
227
|
-
* the base class's list instead of adding to it. DSH 0.2.1's runtime declares
|
|
228
|
-
* `workingDirectory` and reads it on every activation
|
|
229
|
-
* (`ctx.workingDirectory.ensure(...)`); declaring only `modelSwitch` hid that
|
|
230
|
-
* dependency, so every delegation failed with
|
|
231
|
-
* `cannot get property "workingDirectory" without inject`. The list is read from
|
|
232
|
-
* the installed runtime instead of hard-coded so a future Host dependency is
|
|
233
|
-
* mirrored too.
|
|
87
|
+
* @deprecated Kept importable for existing consumers, not mounted by the bundle.
|
|
88
|
+
* Install profileSubagentRuntime around the official service instead: the
|
|
89
|
+
* official Loader row must remain enabled to own its strict Typert definitions.
|
|
234
90
|
*/
|
|
235
|
-
const OFFICIAL_RUNTIME_INJECT = (() => {
|
|
236
|
-
const declared = OfficialSubagentRuntime.inject;
|
|
237
|
-
return Array.isArray(declared) ? [...declared] : [];
|
|
238
|
-
})();
|
|
239
|
-
/**
|
|
240
|
-
* The plugin dependency list for the mounted runtime.
|
|
241
|
-
*
|
|
242
|
-
* Static inheritance does not merge `inject`: cordis reads the static list off
|
|
243
|
-
* the class it mounts, so the subclass must repeat every service the official
|
|
244
|
-
* runtime's own code reads and add the route surface this adapter uses.
|
|
245
|
-
* @param officialInject - the installed runtime's declared dependencies (absent on 0.1.7/0.2.0).
|
|
246
|
-
* @returns The deduplicated list, official dependencies first.
|
|
247
|
-
*/
|
|
248
|
-
function subagentRuntimeInject(officialInject) {
|
|
249
|
-
return [.../* @__PURE__ */ new Set([...officialInject ?? [], "modelSwitch"])];
|
|
250
|
-
}
|
|
251
|
-
/** Official runtime with only a pre-descriptor route-selection adapter. */
|
|
252
91
|
var ModelSwitchSubagentRuntime = class extends OfficialSubagentRuntime {
|
|
253
|
-
static inject = subagentRuntimeInject(
|
|
92
|
+
static inject = subagentRuntimeInject(OfficialSubagentRuntime.inject);
|
|
254
93
|
routed(name, request) {
|
|
255
94
|
const provider = this.ctx.subagents.getProvider(name);
|
|
256
95
|
if (provider !== void 0 && provider.capabilities.agentOptions !== true) return request;
|
|
257
|
-
|
|
258
|
-
return routeSubagentRequest(request, sessionSubagentRouteOf(this.ctx, request.parent.session, modelSwitch.currentSettings()));
|
|
96
|
+
return routeSubagentRequest(request, sessionSubagentRouteOf(this.ctx, request.parent.session, this.ctx.modelSwitch.currentSettings()));
|
|
259
97
|
}
|
|
260
98
|
start(name, request) {
|
|
261
|
-
return publicMethod(
|
|
99
|
+
return Reflect.apply(publicMethod("start"), this, [name, this.routed(name, request)]);
|
|
262
100
|
}
|
|
263
101
|
startContinuable(spec) {
|
|
264
|
-
return publicMethod(
|
|
102
|
+
return Reflect.apply(publicMethod("startContinuable"), this, [{
|
|
265
103
|
...spec,
|
|
266
104
|
request: this.routed(spec.provider, spec.request)
|
|
267
|
-
});
|
|
105
|
+
}]);
|
|
268
106
|
}
|
|
269
|
-
/**
|
|
270
|
-
* 0.2.1+ activation entry: delegation tools call this instead of
|
|
271
|
-
* `start()`/`startContinuable()`, and its spec carries the same
|
|
272
|
-
* `request.agentOptions` this adapter already rewrites. Every other spec
|
|
273
|
-
* field (label, childId, signal, delivery) passes through untouched.
|
|
274
|
-
*
|
|
275
|
-
* @param spec - the activation spec published by the installed Host.
|
|
276
|
-
* @returns The official activation result.
|
|
277
|
-
*/
|
|
278
107
|
startActivation(spec) {
|
|
279
|
-
return publicMethod(
|
|
108
|
+
return Reflect.apply(publicMethod("startActivation"), this, [{
|
|
280
109
|
...spec,
|
|
281
110
|
request: this.routed(spec.provider, spec.request)
|
|
282
|
-
});
|
|
111
|
+
}]);
|
|
283
112
|
}
|
|
284
113
|
};
|
|
285
114
|
//#endregion
|
|
286
|
-
|
|
115
|
+
//#region lib/types/subagent-runtime.js
|
|
116
|
+
function present(value) {
|
|
117
|
+
return typeof value === "string" && value.trim() !== "";
|
|
118
|
+
}
|
|
119
|
+
function spawnHasAnyRouteField(options) {
|
|
120
|
+
return present(options?.provider) || present(options?.model) || options?.reasoningEffort !== void 0;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Inject a parent-session route only when the caller named no provider, model,
|
|
124
|
+
* or reasoning effort. All other request and Agent options pass through.
|
|
125
|
+
*/
|
|
126
|
+
function routeSubagentRequest(request, route) {
|
|
127
|
+
if (spawnHasAnyRouteField(request.agentOptions) || route === void 0) return request;
|
|
128
|
+
return {
|
|
129
|
+
...request,
|
|
130
|
+
agentOptions: {
|
|
131
|
+
...request.agentOptions,
|
|
132
|
+
provider: route.provider,
|
|
133
|
+
model: route.model,
|
|
134
|
+
...route.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(route.reasoningEffort) }
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
/** Resolve the current public route surface, never retaining a disposed service. */
|
|
139
|
+
function routedSubagentRequest(ctx, runtime, providerName, request) {
|
|
140
|
+
if (spawnHasAnyRouteField(request.agentOptions)) return request;
|
|
141
|
+
const provider = runtime.getProvider?.(providerName);
|
|
142
|
+
if (provider !== void 0 && provider.capabilities?.agentOptions !== true) return request;
|
|
143
|
+
let modelSwitch;
|
|
144
|
+
try {
|
|
145
|
+
modelSwitch = ctx.get("modelSwitch");
|
|
146
|
+
} catch {
|
|
147
|
+
return request;
|
|
148
|
+
}
|
|
149
|
+
if (typeof modelSwitch?.currentSettings !== "function") return request;
|
|
150
|
+
return routeSubagentRequest(request, sessionSubagentRouteOf(ctx, request.parent.session, modelSwitch.currentSettings()));
|
|
151
|
+
}
|
|
152
|
+
/** A tracing proxy is for calls, not method ownership or descriptor restoration. */
|
|
153
|
+
function originalService(value) {
|
|
154
|
+
const original = Reflect.get(value, symbols.original);
|
|
155
|
+
return original !== null && (typeof original === "object" || typeof original === "function") ? original : value;
|
|
156
|
+
}
|
|
157
|
+
function isRequest(value) {
|
|
158
|
+
if (typeof value !== "object" || value === null) return false;
|
|
159
|
+
const parent = Reflect.get(value, "parent");
|
|
160
|
+
return typeof parent === "object" && parent !== null && Reflect.get(parent, "session") !== void 0;
|
|
161
|
+
}
|
|
162
|
+
function warn(ctx, message) {
|
|
163
|
+
try {
|
|
164
|
+
ctx.logger.warn(message);
|
|
165
|
+
} catch {}
|
|
166
|
+
}
|
|
167
|
+
const wrappers = /* @__PURE__ */ new WeakMap();
|
|
168
|
+
function routeFor(state, provider, request) {
|
|
169
|
+
const ctx = [...state.leases].at(-1)?.ctx;
|
|
170
|
+
return ctx === void 0 ? request : routedSubagentRequest(ctx, state.runtime, provider, request);
|
|
171
|
+
}
|
|
172
|
+
function wrapMethod(target, key, factory) {
|
|
173
|
+
const original = Reflect.get(target, key);
|
|
174
|
+
if (typeof original !== "function") return void 0;
|
|
175
|
+
const previous = Object.getOwnPropertyDescriptor(target, key);
|
|
176
|
+
const wrapped = factory(original);
|
|
177
|
+
Object.defineProperty(target, key, {
|
|
178
|
+
configurable: true,
|
|
179
|
+
enumerable: previous?.enumerable ?? false,
|
|
180
|
+
writable: true,
|
|
181
|
+
value: wrapped
|
|
182
|
+
});
|
|
183
|
+
return () => {
|
|
184
|
+
if (Object.getOwnPropertyDescriptor(target, key)?.value !== wrapped) return;
|
|
185
|
+
if (previous === void 0) Reflect.deleteProperty(target, key);
|
|
186
|
+
else Object.defineProperty(target, key, previous);
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Wrap the official service's start entries only. Its identity, prototype,
|
|
191
|
+
* registry, manager, Typert binding and prompt/interrupt methods are untouched.
|
|
192
|
+
* Disposers are idempotent and safe when overlapping adapter fibers unload in
|
|
193
|
+
* either order. Unsupported or sealed surfaces leave the official route usable.
|
|
194
|
+
*/
|
|
195
|
+
function installSubagentRouteWrappers(ctx) {
|
|
196
|
+
const service = ctx.get("subagents");
|
|
197
|
+
if (service === void 0) {
|
|
198
|
+
warn(ctx, "model-switch: subagents service is unavailable; delegation keeps the official route");
|
|
199
|
+
return () => {};
|
|
200
|
+
}
|
|
201
|
+
const runtime = originalService(service);
|
|
202
|
+
let state = wrappers.get(runtime);
|
|
203
|
+
if (state === void 0) {
|
|
204
|
+
state = {
|
|
205
|
+
runtime,
|
|
206
|
+
leases: /* @__PURE__ */ new Set(),
|
|
207
|
+
restores: []
|
|
208
|
+
};
|
|
209
|
+
const current = state;
|
|
210
|
+
const wrap = (key, factory) => {
|
|
211
|
+
const restore = wrapMethod(runtime, key, factory);
|
|
212
|
+
if (restore !== void 0) current.restores.push(restore);
|
|
213
|
+
};
|
|
214
|
+
try {
|
|
215
|
+
for (const key of ["startActivation", "startContinuable"]) wrap(key, (original) => function(...args) {
|
|
216
|
+
const rawSpec = args[0];
|
|
217
|
+
if (typeof rawSpec !== "object" || rawSpec === null) return Reflect.apply(original, this, args);
|
|
218
|
+
const spec = rawSpec;
|
|
219
|
+
if (typeof spec.provider !== "string" || !isRequest(spec.request)) return Reflect.apply(original, this, args);
|
|
220
|
+
const request = routeFor(current, spec.provider, spec.request);
|
|
221
|
+
return Reflect.apply(original, this, [request === spec.request ? spec : {
|
|
222
|
+
...spec,
|
|
223
|
+
request
|
|
224
|
+
}, ...args.slice(1)]);
|
|
225
|
+
});
|
|
226
|
+
wrap("start", (original) => function(...args) {
|
|
227
|
+
const [provider, request] = args;
|
|
228
|
+
if (typeof provider !== "string" || !isRequest(request)) return Reflect.apply(original, this, args);
|
|
229
|
+
return Reflect.apply(original, this, [
|
|
230
|
+
provider,
|
|
231
|
+
routeFor(current, provider, request),
|
|
232
|
+
...args.slice(2)
|
|
233
|
+
]);
|
|
234
|
+
});
|
|
235
|
+
} catch (error) {
|
|
236
|
+
for (const restore of current.restores.reverse()) restore();
|
|
237
|
+
warn(ctx, `model-switch: Subagent starts cannot be wrapped (${String(error)}); delegation keeps the official route`);
|
|
238
|
+
return () => {};
|
|
239
|
+
}
|
|
240
|
+
if (current.restores.length === 0) {
|
|
241
|
+
warn(ctx, "model-switch: no supported public Subagent start entry; delegation keeps the official route");
|
|
242
|
+
return () => {};
|
|
243
|
+
}
|
|
244
|
+
wrappers.set(runtime, state);
|
|
245
|
+
}
|
|
246
|
+
const lease = { ctx };
|
|
247
|
+
state.leases.add(lease);
|
|
248
|
+
const owned = state;
|
|
249
|
+
return () => {
|
|
250
|
+
if (!owned.leases.delete(lease) || owned.leases.size > 0) return;
|
|
251
|
+
for (const restore of [...owned.restores].reverse()) restore();
|
|
252
|
+
wrappers.delete(runtime);
|
|
253
|
+
};
|
|
254
|
+
}
|
|
255
|
+
/**
|
|
256
|
+
* Wait for the official service without replacing it or copying its dependency
|
|
257
|
+
* list. Model Switch is read optionally per call, so its absence cannot hold a
|
|
258
|
+
* startup fiber or retain a stale settings service. Cordis rebinds this effect
|
|
259
|
+
* when the official service is recreated.
|
|
260
|
+
*/
|
|
261
|
+
function profileSubagentRuntime(ctx) {
|
|
262
|
+
ctx.inject(["subagents"], (scope) => {
|
|
263
|
+
scope.effect(() => installSubagentRouteWrappers(scope), "Model Switch: route official Subagent starts");
|
|
264
|
+
});
|
|
265
|
+
}
|
|
266
|
+
//#endregion
|
|
267
|
+
export { ModelSwitchSubagentRuntime, StartupIncompatibilityError, profileSubagentRuntime as default, profileSubagentRuntime, installSubagentRouteWrappers, mountWithStartupFallback, routeSubagentRequest, routedRuntimeUnavailableNotice, routedSubagentRequest, subagentRuntimeInject, subagentSurfaceOf };
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { type ReactNode } from 'react';
|
|
2
|
-
import type { ModelProviderGroup } from '@deepseek-ai/dsh-api-session-controller/types';
|
|
3
2
|
import type { ConfigForm } from '@deepseek-ai/dsh-client-ui-settings/client';
|
|
4
3
|
import type { InjectFace, PropsRuntime } from '@deepseek-ai/dsh-client-ui-slots';
|
|
5
4
|
import { type CapabilityRouteView, type ModelSwitchSettingsView, type ReviewStatusView, type SubagentSettingsView, type ToolCatalogRow } from '../client-contract.js';
|
|
@@ -7,6 +6,7 @@ import { type ProviderGroupConfig } from '../provider-group.js';
|
|
|
7
6
|
import type { RuntimeCapabilities } from '../runtime-capabilities.js';
|
|
8
7
|
import { type CapabilitiesSnapshot } from './search-capabilities.js';
|
|
9
8
|
import type { ModelSwitchLocaleKey } from './locales.js';
|
|
9
|
+
import { type SettingsCatalogPayload } from './main-row-controller.js';
|
|
10
10
|
import type { ConfigViewForm, ConfigViewOp } from './derived-config-form.js';
|
|
11
11
|
export interface ModelSwitchSettingsFace {
|
|
12
12
|
t: (key: ModelSwitchLocaleKey) => string;
|
|
@@ -41,7 +41,7 @@ export interface ModelSwitchSettingsFace {
|
|
|
41
41
|
}>;
|
|
42
42
|
/** Replace or remove (undefined) one provider's saved capability group. */
|
|
43
43
|
saveProviderGroup: (provider: string, group: ProviderGroupConfig | undefined) => Promise<void>;
|
|
44
|
-
loadCatalog: () => Promise<
|
|
44
|
+
loadCatalog: () => Promise<SettingsCatalogPayload>;
|
|
45
45
|
/** Host capabilities long-poll; absent in legacy faces, which keep the static-capabilities path. */
|
|
46
46
|
loadCapabilities?: (revision?: number, signal?: AbortSignal) => Promise<CapabilitiesSnapshot>;
|
|
47
47
|
subscribeProviderOrder?: (listener: () => void) => () => void;
|
|
@@ -28,6 +28,9 @@ export declare const zh: {
|
|
|
28
28
|
readonly loading: "正在加载设置…";
|
|
29
29
|
readonly requestFailed: "保存失败";
|
|
30
30
|
readonly catalogFailed: "无法加载模型目录。";
|
|
31
|
+
readonly catalogLoading: "正在加载模型目录…";
|
|
32
|
+
readonly catalogRetry: "重试";
|
|
33
|
+
readonly catalogUnavailableHint: "模型目录暂时不可用(后台任务繁忙或 Host 忙碌时会偶发);已显示的供应商与已保存的组仍可编辑,也可点击重试。";
|
|
31
34
|
readonly autoReview: "自动审查模型";
|
|
32
35
|
readonly autoReviewFollow: "跟随会话模型";
|
|
33
36
|
readonly autoReviewHelp: "为官方 auto-review(Auto 权限预设的逐调用审查)指定审查模型;需启用官方 auto-review 能力包。关闭时审查跟随当前会话模型。本插件启用时,官方「自动审查」组件由本插件接管。";
|