dsh-model-switch 0.4.67 → 0.4.68
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 +13 -0
- package/README.en.md +8 -16
- package/README.md +8 -16
- package/lib/index.js +5 -0
- package/lib/subagent-runtime-BgLqMl2z.js +424 -0
- package/lib/subagent-runtime-CluWLZio.js +412 -0
- package/lib/subagent-runtime.js +2 -289
- package/lib/types/subagent-runtime.d.ts +34 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,16 @@
|
|
|
1
|
+
## v0.4.68
|
|
2
|
+
|
|
3
|
+
`list_subagent_models` 现在同时报出「未点名 spawn 的实际默认路由」(按用户 2026-11-19 要求)。
|
|
4
|
+
|
|
5
|
+
- **动机**:官方发现工具只列「显式点名」的授权路由(数据来自会话投影 `subagent/model-selection-policy`,无 policy 时回落父路由),按设计不含本插件在 Subagent 运行时注入的未命名路由(供应商组 pin → 固定卡片 → 官方继承)——排查时曾因此误判「无识图子代理路由可用」。
|
|
6
|
+
- **实现(`src/subagent-runtime.ts`,挂在 `model-switch-subagent-runtime` 行)**:在 `ctx.tools` 注册表上挂钩 `register` 本身——任何注册路径(宿主行,以及每个会话的 preset 层:Web 面按 agent preset 组装该工具,作用域层会 shadow 全局注册,扫描全局视图够不着)把 definition 存入层之前,发现 `list_subagent_models` 即原地包装其 `execute`:官方文本输出尾部追加一行 `Default route for spawns that name no provider/model (Model Switch, <provider group pin|fixed card>): <provider/model>[, effort <e>]`,无固定时明确写 official inherit。非字符串结果原样放行;包装幂等(符号标记)、行卸载时恢复官方 execute;另保留全局视图的迟到扫描与 `tools/change` 重挂。路由解析复用 `sessionSubagentRouteOf`(与委派注入同源同优先级)。
|
|
7
|
+
- **状态面**:capabilities RPC 的 `status` 新增 `subagentDiscoveryHint{installed, toolWrapped}`(与 automode / prime-memory / reviewTimeout 的适配器状态同构)。
|
|
8
|
+
- **测试**:`tests/subagent-runtime.spec.ts` 新增 10 条(footer 纯函数四种形态、安装追加、卸载恢复、重挂、非字符串放行、无注册表静默);`tests/subagent-discovery.integration.spec.ts` 新增 4 条真实 cordis + 真实 `ToolsService` 组合测试(根注册、行加载后注册、兄弟插件上下文注册、卸载恢复)。
|
|
9
|
+
- **验证(virtual / 零真实额度)**:DSH `0.2.2-rc.5` lab(`D:\dsh-artifacts\rc2-diff`,端口 3084/4719)+ 0.4.68 构建:`model-switch-subagent-runtime` 行 active;lab 临时启用 `tool-subagent` 行使工具注册(`provider: subagent-spawn-in-process` + `modelDiscovery: true`,运行后还原)。无头 UI 回合中模型(探针回放)调用 `list_subagent_models`,**回传给模型的工具结果**(探针 `--capture-last` 逐字捕获)为:`apigoto — apigoto\nDefault route for spawns that name no provider/model (Model Switch, provider group pin): apigoto/mimo-v2.6-flash, effort high`——授权清单与实际默认路由(组 pin + effort)并列,与 lab patch 的 apigoto 组配置一致。`status.subagentDiscoveryHint = {installed:true, toolWrapped:true}`。证据:`D:\dsh-artifacts\rc2-diff\report-hint-0468-2026-11-19T15-43-28-382Z.json`、`probe-hint-2026-11-19T15-43-28-382Z.jsonl`。
|
|
10
|
+
- 探针 `tools/route-probe.mjs` 新增 `--capture-last` 开关(记录每条 chat 请求末条消息的截断文本,默认关闭),本轮为取证引入,保留为 lab 工具能力。
|
|
11
|
+
- 文档:README 的「正式版安装」段不再链接本仓库 Release 页不存在的 tarball / sha256 附件(该页从未带附件,旧链接一直是 404)——本插件安装统一指向 npm 注册表,固定版本用 `npm pack dsh-model-switch@<版本>` 取归档后本地安装;Release 链接只指向发布页并注明 npm provenance。
|
|
12
|
+
- `pnpm run check` 全绿(tsc + tsdown + 693 测试 + pack 闸门)。
|
|
13
|
+
|
|
1
14
|
## v0.4.67
|
|
2
15
|
|
|
3
16
|
冻结审查超时功能(按用户 2026-11-19 要求)+ README 重构(中文升主)。
|
package/README.en.md
CHANGED
|
@@ -212,32 +212,24 @@ pnpm run check
|
|
|
212
212
|
|
|
213
213
|
Explicit model routing for Subagents, Composer, Plan Review, and capability tools, checked on official DeepSeek Harness `0.1.7-rc.2` through `0.2.2-rc.5`. The release artifact contains built Host/Client files, not sibling source or local paths.
|
|
214
214
|
|
|
215
|
-
|
|
215
|
+
This plugin installs from the npm registry (this repository's releases carry no attachments, so an install never depends on release assets); to pin a version, fetch the archive with `npm pack dsh-model-switch@<version>` and install the local tarball as shown above:
|
|
216
216
|
|
|
217
217
|
~~~sh
|
|
218
|
-
dsh plugin --profile web add --force
|
|
219
|
-
https://github.com/NOirBRight/dsh-llm-providers-ui/releases/latest/download/dsh-llm-providers-ui-0.2.14.tgz
|
|
220
|
-
dsh plugin --profile web add --force \
|
|
221
|
-
https://github.com/vandoor7-droid/dsh-model-switch/releases/latest/download/dsh-model-switch-0.4.67.tgz
|
|
218
|
+
dsh plugin --profile web add --force dsh-model-switch
|
|
222
219
|
~~~
|
|
223
220
|
|
|
224
|
-
|
|
221
|
+
Provider adapters install from their own releases:
|
|
225
222
|
|
|
226
223
|
~~~sh
|
|
227
224
|
dsh plugin --profile web add --force \
|
|
228
|
-
https://github.com/NOirBRight/dsh-llm-providers-ui/releases/download/
|
|
229
|
-
dsh plugin --profile web add --force \
|
|
230
|
-
https://github.com/vandoor7-droid/dsh-model-switch/releases/download/v0.4.67/dsh-model-switch-0.4.67.tgz
|
|
225
|
+
https://github.com/NOirBRight/dsh-llm-providers-ui/releases/latest/download/dsh-llm-providers-ui-0.2.14.tgz
|
|
231
226
|
~~~
|
|
232
227
|
|
|
233
228
|
Update, uninstall, and verify:
|
|
234
229
|
|
|
235
230
|
~~~sh
|
|
236
|
-
# Update to the latest
|
|
237
|
-
dsh plugin --profile web add --force
|
|
238
|
-
https://github.com/NOirBRight/dsh-llm-providers-ui/releases/latest/download/dsh-llm-providers-ui-0.2.14.tgz
|
|
239
|
-
dsh plugin --profile web add --force \
|
|
240
|
-
https://github.com/vandoor7-droid/dsh-model-switch/releases/latest/download/dsh-model-switch-0.4.67.tgz
|
|
231
|
+
# Update to the latest release
|
|
232
|
+
dsh plugin --profile web add --force dsh-model-switch
|
|
241
233
|
# Verify the loaded version
|
|
242
234
|
dsh plugin --profile web list
|
|
243
235
|
# Uninstall only this plugin
|
|
@@ -246,6 +238,6 @@ dsh plugin --profile web remove dsh-model-switch
|
|
|
246
238
|
|
|
247
239
|
Configuration: use the plugin section in Settings for Web UI plugins, or the profile dsh.profile.bundles entry for Host-only plugins.
|
|
248
240
|
|
|
249
|
-
Rollback: reinstall the previous release (
|
|
241
|
+
Rollback: reinstall the previous release (`npm pack dsh-model-switch@0.4.66`, then the local tarball) and restore the recorded profile; no Host downgrade is required. Inspect the DSH Host logs; never link a checkout into production.
|
|
250
242
|
|
|
251
|
-
Release
|
|
243
|
+
Release record: [v0.4.67](https://github.com/vandoor7-droid/dsh-model-switch/releases/tag/v0.4.67) (the npm package carries a signed build-provenance statement).
|
package/README.md
CHANGED
|
@@ -210,32 +210,24 @@ pnpm run check
|
|
|
210
210
|
|
|
211
211
|
本版在官方 DeepSeek Harness `0.1.7-rc.2` 至 `0.2.2-rc.5` 上验证了子代理、Composer、Plan Review 与能力路由;发布包只包含构建后的 Host/Client 产物,不包含兄弟仓库源码或本机路径。
|
|
212
212
|
|
|
213
|
-
|
|
213
|
+
本插件从 npm 注册表安装(本仓库的 Release 页不带附件,安装不依赖 Release 资产);需要固定版本时先用 `npm pack dsh-model-switch@<版本>` 取得归档,再按上文本地 tarball 方式安装:
|
|
214
214
|
|
|
215
215
|
~~~sh
|
|
216
|
-
dsh plugin --profile web add --force
|
|
217
|
-
https://github.com/NOirBRight/dsh-llm-providers-ui/releases/latest/download/dsh-llm-providers-ui-0.2.14.tgz
|
|
218
|
-
dsh plugin --profile web add --force \
|
|
219
|
-
https://github.com/vandoor7-droid/dsh-model-switch/releases/latest/download/dsh-model-switch-0.4.67.tgz
|
|
216
|
+
dsh plugin --profile web add --force dsh-model-switch
|
|
220
217
|
~~~
|
|
221
218
|
|
|
222
|
-
|
|
219
|
+
Provider Adapter 从其各自 Release 安装:
|
|
223
220
|
|
|
224
221
|
~~~sh
|
|
225
222
|
dsh plugin --profile web add --force \
|
|
226
|
-
https://github.com/NOirBRight/dsh-llm-providers-ui/releases/download/
|
|
227
|
-
dsh plugin --profile web add --force \
|
|
228
|
-
https://github.com/vandoor7-droid/dsh-model-switch/releases/download/v0.4.67/dsh-model-switch-0.4.67.tgz
|
|
223
|
+
https://github.com/NOirBRight/dsh-llm-providers-ui/releases/latest/download/dsh-llm-providers-ui-0.2.14.tgz
|
|
229
224
|
~~~
|
|
230
225
|
|
|
231
226
|
更新、卸载与验证:
|
|
232
227
|
|
|
233
228
|
~~~sh
|
|
234
|
-
#
|
|
235
|
-
dsh plugin --profile web add --force
|
|
236
|
-
https://github.com/NOirBRight/dsh-llm-providers-ui/releases/latest/download/dsh-llm-providers-ui-0.2.14.tgz
|
|
237
|
-
dsh plugin --profile web add --force \
|
|
238
|
-
https://github.com/vandoor7-droid/dsh-model-switch/releases/latest/download/dsh-model-switch-0.4.67.tgz
|
|
229
|
+
# 更新到最新版
|
|
230
|
+
dsh plugin --profile web add --force dsh-model-switch
|
|
239
231
|
# 验证加载与版本
|
|
240
232
|
dsh plugin --profile web list
|
|
241
233
|
# 只卸载本插件
|
|
@@ -244,6 +236,6 @@ dsh plugin --profile web remove dsh-model-switch
|
|
|
244
236
|
|
|
245
237
|
配置入口:Web 使用「设置」中的本插件页面;Host-only 插件使用 profile 的 dsh.profile.bundles 配置。
|
|
246
238
|
|
|
247
|
-
|
|
239
|
+
回滚:重新安装上一版(`npm pack dsh-model-switch@0.4.66` 后本地安装)并恢复已记录的 profile;不需要降级 Host。失败时查看 DSH Host 日志,不要将源码 checkout 链入生产 profile。
|
|
248
240
|
|
|
249
|
-
Release
|
|
241
|
+
Release 记录:[v0.4.67](https://github.com/vandoor7-droid/dsh-model-switch/releases/tag/v0.4.67)(npm 包附带构建来源 provenance 签名)。
|
package/lib/index.js
CHANGED
|
@@ -3,6 +3,7 @@ import { r as resolveToolSource, t as DEFAULT_READ_ONLY_TOOLS } from "./tool-all
|
|
|
3
3
|
import { i as autoReviewStatus } from "./auto-review-C5cwVyMD.js";
|
|
4
4
|
import { ModelSwitchAdapterRegistry } from "./adapter-registry.js";
|
|
5
5
|
import { automodeCompatView } from "./automode-compat.js";
|
|
6
|
+
import { s as subagentDiscoveryHintStatus } from "./subagent-runtime-BgLqMl2z.js";
|
|
6
7
|
import { u as reviewTimeoutStatus } from "./review-timeout-BU0BFHoJ.js";
|
|
7
8
|
import { l as primeMemoryCompatStatus } from "./prime-memory-compat-X6WlrtaN.js";
|
|
8
9
|
import { createRequire } from "node:module";
|
|
@@ -556,6 +557,10 @@ function installCapabilitiesRpc(ctx, registry, snapshot) {
|
|
|
556
557
|
hotApplied: reviewTimeoutStatus.hotApplied,
|
|
557
558
|
hot: reviewTimeoutStatus.hot,
|
|
558
559
|
hotReason: reviewTimeoutStatus.hotReason
|
|
560
|
+
},
|
|
561
|
+
subagentDiscoveryHint: {
|
|
562
|
+
installed: subagentDiscoveryHintStatus.installed,
|
|
563
|
+
toolWrapped: subagentDiscoveryHintStatus.toolWrapped
|
|
559
564
|
}
|
|
560
565
|
}));
|
|
561
566
|
const dispose = scope.connection.fetch.register({
|
|
@@ -0,0 +1,424 @@
|
|
|
1
|
+
import { a as sessionProviderOf, n as groupRoute, o as sessionSubagentRouteOf } from "./session-route-D8izd8Zd.js";
|
|
2
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
3
|
+
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
4
|
+
import OfficialSubagentRuntime from "@deepseek-ai/dsh-subagent";
|
|
5
|
+
//#region lib/types/subagent-runtime-legacy.js
|
|
6
|
+
/** Previously published startup error; retained for consumers of this module. */
|
|
7
|
+
var StartupIncompatibilityError = class extends Error {
|
|
8
|
+
name = "StartupIncompatibilityError";
|
|
9
|
+
surface;
|
|
10
|
+
constructor(surfaceOrMessage, message) {
|
|
11
|
+
super(message ?? surfaceOrMessage);
|
|
12
|
+
this.surface = message === void 0 ? "startup" : surfaceOrMessage;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/** Classify the two published start API generations without version guessing. */
|
|
16
|
+
function subagentSurfaceOf(value) {
|
|
17
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
|
|
18
|
+
if (typeof Reflect.get(value, "startActivation") === "function") return "activation";
|
|
19
|
+
return typeof Reflect.get(value, "start") === "function" && typeof Reflect.get(value, "startContinuable") === "function" ? "start" : void 0;
|
|
20
|
+
}
|
|
21
|
+
function once(dispose) {
|
|
22
|
+
let pending;
|
|
23
|
+
return () => {
|
|
24
|
+
pending ??= Promise.resolve().then(() => dispose()).then(() => void 0);
|
|
25
|
+
return pending;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var CleanupLedger = class {
|
|
29
|
+
attempts = [];
|
|
30
|
+
add(dispose) {
|
|
31
|
+
this.attempts.push(once(dispose));
|
|
32
|
+
}
|
|
33
|
+
async disposeAll() {
|
|
34
|
+
const failures = [];
|
|
35
|
+
for (const dispose of [...this.attempts].reverse()) try {
|
|
36
|
+
await dispose();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
failures.push(error);
|
|
39
|
+
}
|
|
40
|
+
return failures;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
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 });
|
|
46
|
+
}
|
|
47
|
+
function cleanupDisposer(ledger) {
|
|
48
|
+
return async () => {
|
|
49
|
+
const failures = await ledger.disposeAll();
|
|
50
|
+
if (failures.length > 0) throw new AggregateError(failures, "Subagent runtime cleanup failed");
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Retain the typed-only startup fallback and reverse, idempotent cleanup contract. */
|
|
54
|
+
async function mountWithStartupFallback(candidate, fallback) {
|
|
55
|
+
const ledger = new CleanupLedger();
|
|
56
|
+
try {
|
|
57
|
+
return {
|
|
58
|
+
value: await candidate((dispose) => ledger.add(dispose)),
|
|
59
|
+
dispose: cleanupDisposer(ledger)
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const failures = await ledger.disposeAll();
|
|
63
|
+
if (!(error instanceof StartupIncompatibilityError) || failures.length > 0) startupFailure(error, failures);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return {
|
|
67
|
+
value: await fallback((dispose) => ledger.add(dispose)),
|
|
68
|
+
dispose: cleanupDisposer(ledger)
|
|
69
|
+
};
|
|
70
|
+
} catch (error) {
|
|
71
|
+
startupFailure(error, await ledger.disposeAll());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function routedRuntimeUnavailableNotice(error) {
|
|
75
|
+
return `model-switch: the routed Subagent runtime is unavailable on this DSH Host (${error.message}); delegation follows the official route instead`;
|
|
76
|
+
}
|
|
77
|
+
/** @deprecated Only the legacy subclass needs a mirrored dependency list. */
|
|
78
|
+
function subagentRuntimeInject(officialInject) {
|
|
79
|
+
return [.../* @__PURE__ */ new Set([...officialInject ?? [], "modelSwitch"])];
|
|
80
|
+
}
|
|
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;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
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.
|
|
90
|
+
*/
|
|
91
|
+
var ModelSwitchSubagentRuntime = class extends OfficialSubagentRuntime {
|
|
92
|
+
static inject = subagentRuntimeInject(OfficialSubagentRuntime.inject);
|
|
93
|
+
routed(name, request) {
|
|
94
|
+
const provider = this.ctx.subagents.getProvider(name);
|
|
95
|
+
if (provider !== void 0 && provider.capabilities.agentOptions !== true) return request;
|
|
96
|
+
return routeSubagentRequest(request, sessionSubagentRouteOf(this.ctx, request.parent.session, this.ctx.modelSwitch.currentSettings()));
|
|
97
|
+
}
|
|
98
|
+
start(name, request) {
|
|
99
|
+
return Reflect.apply(publicMethod("start"), this, [name, this.routed(name, request)]);
|
|
100
|
+
}
|
|
101
|
+
startContinuable(spec) {
|
|
102
|
+
return Reflect.apply(publicMethod("startContinuable"), this, [{
|
|
103
|
+
...spec,
|
|
104
|
+
request: this.routed(spec.provider, spec.request)
|
|
105
|
+
}]);
|
|
106
|
+
}
|
|
107
|
+
startActivation(spec) {
|
|
108
|
+
const request = spec.request ?? spec;
|
|
109
|
+
return Reflect.apply(publicMethod("startActivation"), this, [{
|
|
110
|
+
...spec,
|
|
111
|
+
request: this.routed(spec.provider, request)
|
|
112
|
+
}]);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region lib/types/subagent-runtime.js
|
|
117
|
+
function present(value) {
|
|
118
|
+
return typeof value === "string" && value.trim() !== "";
|
|
119
|
+
}
|
|
120
|
+
function spawnHasAnyRouteField(options) {
|
|
121
|
+
return present(options?.provider) || present(options?.model) || options?.reasoningEffort !== void 0;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Inject a parent-session route only when the caller named no provider, model,
|
|
125
|
+
* or reasoning effort. All other request and Agent options pass through.
|
|
126
|
+
*/
|
|
127
|
+
function routeSubagentRequest(request, route) {
|
|
128
|
+
if (spawnHasAnyRouteField(request.agentOptions) || route === void 0) return request;
|
|
129
|
+
return {
|
|
130
|
+
...request,
|
|
131
|
+
agentOptions: {
|
|
132
|
+
...request.agentOptions,
|
|
133
|
+
provider: route.provider,
|
|
134
|
+
model: route.model,
|
|
135
|
+
...route.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(route.reasoningEffort) }
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Resolve the current public route surface, never retaining a disposed service. */
|
|
140
|
+
function routedSubagentRequest(ctx, runtime, providerName, request) {
|
|
141
|
+
if (spawnHasAnyRouteField(request.agentOptions)) return request;
|
|
142
|
+
const provider = runtime.getProvider?.(providerName);
|
|
143
|
+
if (provider !== void 0 && provider.capabilities?.agentOptions !== true) return request;
|
|
144
|
+
let modelSwitch;
|
|
145
|
+
try {
|
|
146
|
+
modelSwitch = ctx.get("modelSwitch");
|
|
147
|
+
} catch {
|
|
148
|
+
return request;
|
|
149
|
+
}
|
|
150
|
+
if (typeof modelSwitch?.currentSettings !== "function") return request;
|
|
151
|
+
return routeSubagentRequest(request, sessionSubagentRouteOf(ctx, request.parent.session, modelSwitch.currentSettings()));
|
|
152
|
+
}
|
|
153
|
+
/** A tracing proxy is for calls, not method ownership or descriptor restoration. */
|
|
154
|
+
function originalService(value) {
|
|
155
|
+
const original = Reflect.get(value, symbols.original);
|
|
156
|
+
return original !== null && (typeof original === "object" || typeof original === "function") ? original : value;
|
|
157
|
+
}
|
|
158
|
+
function isRequest(value) {
|
|
159
|
+
if (typeof value !== "object" || value === null) return false;
|
|
160
|
+
const parent = Reflect.get(value, "parent");
|
|
161
|
+
return typeof parent === "object" && parent !== null && Reflect.get(parent, "session") !== void 0;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Route one activation spec under either released shape. 0.2.1 through
|
|
165
|
+
* 0.2.2-rc.1 nest the SubagentStartRequest under spec.request; 0.2.2-rc.2
|
|
166
|
+
* flattens those fields onto the spec itself. Unknown shapes pass through
|
|
167
|
+
* untouched, so an unanticipated future shape keeps the official route.
|
|
168
|
+
*/
|
|
169
|
+
function routedSpecOf(spec, provider, state) {
|
|
170
|
+
const nested = Reflect.get(spec, "request");
|
|
171
|
+
if (typeof nested === "object" && nested !== null && isRequest(nested)) {
|
|
172
|
+
const request = routeFor(state, provider, nested);
|
|
173
|
+
return request === nested ? spec : {
|
|
174
|
+
...spec,
|
|
175
|
+
request
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (isRequest(spec)) {
|
|
179
|
+
const request = routeFor(state, provider, spec);
|
|
180
|
+
if (request === spec) return spec;
|
|
181
|
+
return {
|
|
182
|
+
...spec,
|
|
183
|
+
agentOptions: request.agentOptions
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return spec;
|
|
187
|
+
}
|
|
188
|
+
function warn(ctx, message) {
|
|
189
|
+
try {
|
|
190
|
+
ctx.logger.warn(message);
|
|
191
|
+
} catch {}
|
|
192
|
+
}
|
|
193
|
+
const wrappers = /* @__PURE__ */ new WeakMap();
|
|
194
|
+
function routeFor(state, provider, request) {
|
|
195
|
+
const ctx = [...state.leases].at(-1)?.ctx;
|
|
196
|
+
return ctx === void 0 ? request : routedSubagentRequest(ctx, state.runtime, provider, request);
|
|
197
|
+
}
|
|
198
|
+
function wrapMethod(target, key, factory) {
|
|
199
|
+
const original = Reflect.get(target, key);
|
|
200
|
+
if (typeof original !== "function") return void 0;
|
|
201
|
+
const previous = Object.getOwnPropertyDescriptor(target, key);
|
|
202
|
+
const wrapped = factory(original);
|
|
203
|
+
Object.defineProperty(target, key, {
|
|
204
|
+
configurable: true,
|
|
205
|
+
enumerable: previous?.enumerable ?? false,
|
|
206
|
+
writable: true,
|
|
207
|
+
value: wrapped
|
|
208
|
+
});
|
|
209
|
+
return () => {
|
|
210
|
+
if (Object.getOwnPropertyDescriptor(target, key)?.value !== wrapped) return;
|
|
211
|
+
if (previous === void 0) Reflect.deleteProperty(target, key);
|
|
212
|
+
else Object.defineProperty(target, key, previous);
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Wrap the official service's start entries only. Its identity, prototype,
|
|
217
|
+
* registry, manager, Typert binding and prompt/interrupt methods are untouched.
|
|
218
|
+
* Disposers are idempotent and safe when overlapping adapter fibers unload in
|
|
219
|
+
* either order. Unsupported or sealed surfaces leave the official route usable.
|
|
220
|
+
*/
|
|
221
|
+
function installSubagentRouteWrappers(ctx) {
|
|
222
|
+
const service = ctx.get("subagents");
|
|
223
|
+
if (service === void 0) {
|
|
224
|
+
warn(ctx, "model-switch: subagents service is unavailable; delegation keeps the official route");
|
|
225
|
+
return () => {};
|
|
226
|
+
}
|
|
227
|
+
const runtime = originalService(service);
|
|
228
|
+
let state = wrappers.get(runtime);
|
|
229
|
+
if (state === void 0) {
|
|
230
|
+
state = {
|
|
231
|
+
runtime,
|
|
232
|
+
leases: /* @__PURE__ */ new Set(),
|
|
233
|
+
restores: []
|
|
234
|
+
};
|
|
235
|
+
const current = state;
|
|
236
|
+
const wrap = (key, factory) => {
|
|
237
|
+
const restore = wrapMethod(runtime, key, factory);
|
|
238
|
+
if (restore !== void 0) current.restores.push(restore);
|
|
239
|
+
};
|
|
240
|
+
try {
|
|
241
|
+
for (const key of ["startActivation", "startContinuable"]) wrap(key, (original) => function(...args) {
|
|
242
|
+
const rawSpec = args[0];
|
|
243
|
+
if (typeof rawSpec !== "object" || rawSpec === null) return Reflect.apply(original, this, args);
|
|
244
|
+
const spec = rawSpec;
|
|
245
|
+
if (typeof spec.provider !== "string") return Reflect.apply(original, this, args);
|
|
246
|
+
return Reflect.apply(original, this, [routedSpecOf(spec, spec.provider, current), ...args.slice(1)]);
|
|
247
|
+
});
|
|
248
|
+
wrap("start", (original) => function(...args) {
|
|
249
|
+
const [provider, request] = args;
|
|
250
|
+
if (typeof provider !== "string" || !isRequest(request)) return Reflect.apply(original, this, args);
|
|
251
|
+
return Reflect.apply(original, this, [
|
|
252
|
+
provider,
|
|
253
|
+
routeFor(current, provider, request),
|
|
254
|
+
...args.slice(2)
|
|
255
|
+
]);
|
|
256
|
+
});
|
|
257
|
+
} catch (error) {
|
|
258
|
+
for (const restore of current.restores.reverse()) restore();
|
|
259
|
+
warn(ctx, `model-switch: Subagent starts cannot be wrapped (${String(error)}); delegation keeps the official route`);
|
|
260
|
+
return () => {};
|
|
261
|
+
}
|
|
262
|
+
if (current.restores.length === 0) {
|
|
263
|
+
warn(ctx, "model-switch: no supported public Subagent start entry; delegation keeps the official route");
|
|
264
|
+
return () => {};
|
|
265
|
+
}
|
|
266
|
+
wrappers.set(runtime, state);
|
|
267
|
+
}
|
|
268
|
+
const lease = { ctx };
|
|
269
|
+
state.leases.add(lease);
|
|
270
|
+
const owned = state;
|
|
271
|
+
return () => {
|
|
272
|
+
if (!owned.leases.delete(lease) || owned.leases.size > 0) return;
|
|
273
|
+
for (const restore of [...owned.restores].reverse()) restore();
|
|
274
|
+
wrappers.delete(runtime);
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/** The official tool that lists routes available for explicit child selection. */
|
|
278
|
+
const SUBAGENT_MODEL_DISCOVERY_TOOL = "list_subagent_models";
|
|
279
|
+
/**
|
|
280
|
+
* Live state of the discovery-hint adapter, surfaced through the capabilities
|
|
281
|
+
* RPC next to the other adapter states.
|
|
282
|
+
*/
|
|
283
|
+
const subagentDiscoveryHintStatus = {
|
|
284
|
+
/** The tools registry was reachable and the adapter installed. */
|
|
285
|
+
installed: false,
|
|
286
|
+
/** The discovery tool was found and its execute wrapped. */
|
|
287
|
+
toolWrapped: false
|
|
288
|
+
};
|
|
289
|
+
/** Marker so a re-sweep never wraps a wrapper. */
|
|
290
|
+
const discoveryHintMarker = Symbol("modelSwitchSubagentDiscoveryHint");
|
|
291
|
+
/** The calling agent's session handle, as discovery executions carry it. */
|
|
292
|
+
function sessionOfExec(exec) {
|
|
293
|
+
const agent = exec?.agent;
|
|
294
|
+
const session = agent === null || typeof agent !== "object" ? void 0 : agent.session;
|
|
295
|
+
return session === null || typeof session !== "object" ? void 0 : session;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Compose the route footer appended to the discovery tool's text output.
|
|
299
|
+
*
|
|
300
|
+
* Pure so the copy and the source attribution stay unit-testable.
|
|
301
|
+
*
|
|
302
|
+
* @param route - the route an unnamed spawn from this session would use.
|
|
303
|
+
* @param pinnedByGroup - whether a provider group (not the flat card) pinned it.
|
|
304
|
+
* @returns the footer line; undefined routes are stated as official inherit.
|
|
305
|
+
*/
|
|
306
|
+
function subagentDiscoveryFooter(route, pinnedByGroup) {
|
|
307
|
+
if (route === void 0) return "Default route for spawns that name no provider/model (Model Switch): official inherit (nothing pinned).";
|
|
308
|
+
const source = pinnedByGroup ? "provider group pin" : "fixed card";
|
|
309
|
+
const effort = route.reasoningEffort === void 0 ? "" : `, effort ${route.reasoningEffort}`;
|
|
310
|
+
return `Default route for spawns that name no provider/model (Model Switch, ${source}): ${route.provider}/${route.model}${effort}`;
|
|
311
|
+
}
|
|
312
|
+
/** Read the effective route and its source for one discovery execution. */
|
|
313
|
+
function discoveryRouteOf(ctx, exec) {
|
|
314
|
+
const session = sessionOfExec(exec);
|
|
315
|
+
let settings;
|
|
316
|
+
try {
|
|
317
|
+
const modelSwitch = ctx.get("modelSwitch");
|
|
318
|
+
settings = typeof modelSwitch?.currentSettings === "function" ? modelSwitch.currentSettings() : void 0;
|
|
319
|
+
} catch {
|
|
320
|
+
settings = void 0;
|
|
321
|
+
}
|
|
322
|
+
const route = sessionSubagentRouteOf(ctx, session, settings);
|
|
323
|
+
return {
|
|
324
|
+
route,
|
|
325
|
+
pinnedByGroup: route !== void 0 && groupRoute(settings, sessionProviderOf(ctx, session), "subagent") !== void 0
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Wrap the official discovery tool's execute so its text output also states the
|
|
330
|
+
* route an unnamed spawn would actually take — the one piece the
|
|
331
|
+
* authorized-route listing cannot know.
|
|
332
|
+
*
|
|
333
|
+
* The wrap is in place on the registered definition (the registry resolves
|
|
334
|
+
* tools per call), idempotent across re-sweeps, and re-applied when the
|
|
335
|
+
* registry changes so a re-registered tool is covered too. Unknown result
|
|
336
|
+
* shapes pass through untouched; unload restores the official execute.
|
|
337
|
+
*
|
|
338
|
+
* @param ctx - this row's context.
|
|
339
|
+
* @returns a disposer that detaches the listener and restores the execute.
|
|
340
|
+
*/
|
|
341
|
+
function installSubagentDiscoveryHint(ctx) {
|
|
342
|
+
const tools = ctx.get("tools", false);
|
|
343
|
+
if (tools === void 0 || typeof tools.get !== "function") {
|
|
344
|
+
warn(ctx, "model-switch: the tools registry is unavailable; list_subagent_models keeps its official output");
|
|
345
|
+
return () => {};
|
|
346
|
+
}
|
|
347
|
+
subagentDiscoveryHintStatus.installed = true;
|
|
348
|
+
const restores = [];
|
|
349
|
+
let announced = false;
|
|
350
|
+
const wrapExecute = (definition) => {
|
|
351
|
+
const current = definition.execute;
|
|
352
|
+
if (typeof current !== "function" || Reflect.get(current, discoveryHintMarker) === true) return false;
|
|
353
|
+
const restore = wrapMethod(definition, "execute", (original) => {
|
|
354
|
+
const wrapped = function(...args) {
|
|
355
|
+
const returned = Reflect.apply(original, this, args);
|
|
356
|
+
const append = (value) => {
|
|
357
|
+
if (typeof value !== "string") return value;
|
|
358
|
+
const { route, pinnedByGroup } = discoveryRouteOf(ctx, args[1]);
|
|
359
|
+
return `${value}\n${subagentDiscoveryFooter(route, pinnedByGroup)}`;
|
|
360
|
+
};
|
|
361
|
+
if (returned !== null && (typeof returned === "object" || typeof returned === "function") && typeof returned.then === "function") return returned.then(append);
|
|
362
|
+
return append(returned);
|
|
363
|
+
};
|
|
364
|
+
Object.defineProperty(wrapped, discoveryHintMarker, { value: true });
|
|
365
|
+
return wrapped;
|
|
366
|
+
});
|
|
367
|
+
if (restore === void 0) return false;
|
|
368
|
+
restores.push(restore);
|
|
369
|
+
return true;
|
|
370
|
+
};
|
|
371
|
+
const announce = () => {
|
|
372
|
+
if (announced) return;
|
|
373
|
+
announced = true;
|
|
374
|
+
subagentDiscoveryHintStatus.toolWrapped = true;
|
|
375
|
+
try {
|
|
376
|
+
ctx.logger.info("model-switch: list_subagent_models now states the effective default route for unnamed spawns");
|
|
377
|
+
} catch {}
|
|
378
|
+
};
|
|
379
|
+
const registerRestore = wrapMethod(tools, "register", (original) => {
|
|
380
|
+
const wrapped = function(...args) {
|
|
381
|
+
const definition = args[0];
|
|
382
|
+
if (definition !== null && typeof definition === "object" && definition.name === SUBAGENT_MODEL_DISCOVERY_TOOL && wrapExecute(definition)) announce();
|
|
383
|
+
return Reflect.apply(original, this, args);
|
|
384
|
+
};
|
|
385
|
+
return wrapped;
|
|
386
|
+
});
|
|
387
|
+
if (registerRestore !== void 0) restores.push(registerRestore);
|
|
388
|
+
const sweep = () => {
|
|
389
|
+
const definition = tools.get(SUBAGENT_MODEL_DISCOVERY_TOOL);
|
|
390
|
+
if (definition !== void 0 && wrapExecute(definition)) announce();
|
|
391
|
+
};
|
|
392
|
+
sweep();
|
|
393
|
+
let attempts = 0;
|
|
394
|
+
const retry = setInterval(() => {
|
|
395
|
+
attempts += 1;
|
|
396
|
+
sweep();
|
|
397
|
+
if (announced || attempts >= 15) clearInterval(retry);
|
|
398
|
+
}, 1e3);
|
|
399
|
+
const off = ctx.on("tools/change", sweep);
|
|
400
|
+
return () => {
|
|
401
|
+
off();
|
|
402
|
+
clearInterval(retry);
|
|
403
|
+
for (const restore of restores.reverse()) restore();
|
|
404
|
+
restores.length = 0;
|
|
405
|
+
subagentDiscoveryHintStatus.installed = false;
|
|
406
|
+
subagentDiscoveryHintStatus.toolWrapped = false;
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
/**
|
|
410
|
+
* Wait for the official service without replacing it or copying its dependency
|
|
411
|
+
* list. Model Switch is read optionally per call, so its absence cannot hold a
|
|
412
|
+
* startup fiber or retain a stale settings service. Cordis rebinds this effect
|
|
413
|
+
* when the official service is recreated.
|
|
414
|
+
*/
|
|
415
|
+
function profileSubagentRuntime(ctx) {
|
|
416
|
+
ctx.inject(["subagents"], (scope) => {
|
|
417
|
+
scope.effect(() => installSubagentRouteWrappers(scope), "Model Switch: route official Subagent starts");
|
|
418
|
+
});
|
|
419
|
+
ctx.inject(["tools"], (scope) => {
|
|
420
|
+
scope.effect(() => installSubagentDiscoveryHint(scope), "Model Switch: annotate the subagent model discovery tool");
|
|
421
|
+
});
|
|
422
|
+
}
|
|
423
|
+
//#endregion
|
|
424
|
+
export { routedSubagentRequest as a, ModelSwitchSubagentRuntime as c, routedRuntimeUnavailableNotice as d, subagentRuntimeInject as f, routeSubagentRequest as i, StartupIncompatibilityError as l, installSubagentRouteWrappers as n, subagentDiscoveryFooter as o, subagentSurfaceOf as p, profileSubagentRuntime as r, subagentDiscoveryHintStatus as s, installSubagentDiscoveryHint as t, mountWithStartupFallback as u };
|
|
@@ -0,0 +1,412 @@
|
|
|
1
|
+
import { a as sessionProviderOf, n as groupRoute, o as sessionSubagentRouteOf } from "./session-route-D8izd8Zd.js";
|
|
2
|
+
import { symbols } from "@deepseek-ai/cordis";
|
|
3
|
+
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
4
|
+
import OfficialSubagentRuntime from "@deepseek-ai/dsh-subagent";
|
|
5
|
+
//#region lib/types/subagent-runtime-legacy.js
|
|
6
|
+
/** Previously published startup error; retained for consumers of this module. */
|
|
7
|
+
var StartupIncompatibilityError = class extends Error {
|
|
8
|
+
name = "StartupIncompatibilityError";
|
|
9
|
+
surface;
|
|
10
|
+
constructor(surfaceOrMessage, message) {
|
|
11
|
+
super(message ?? surfaceOrMessage);
|
|
12
|
+
this.surface = message === void 0 ? "startup" : surfaceOrMessage;
|
|
13
|
+
}
|
|
14
|
+
};
|
|
15
|
+
/** Classify the two published start API generations without version guessing. */
|
|
16
|
+
function subagentSurfaceOf(value) {
|
|
17
|
+
if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
|
|
18
|
+
if (typeof Reflect.get(value, "startActivation") === "function") return "activation";
|
|
19
|
+
return typeof Reflect.get(value, "start") === "function" && typeof Reflect.get(value, "startContinuable") === "function" ? "start" : void 0;
|
|
20
|
+
}
|
|
21
|
+
function once(dispose) {
|
|
22
|
+
let pending;
|
|
23
|
+
return () => {
|
|
24
|
+
pending ??= Promise.resolve().then(() => dispose()).then(() => void 0);
|
|
25
|
+
return pending;
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
var CleanupLedger = class {
|
|
29
|
+
attempts = [];
|
|
30
|
+
add(dispose) {
|
|
31
|
+
this.attempts.push(once(dispose));
|
|
32
|
+
}
|
|
33
|
+
async disposeAll() {
|
|
34
|
+
const failures = [];
|
|
35
|
+
for (const dispose of [...this.attempts].reverse()) try {
|
|
36
|
+
await dispose();
|
|
37
|
+
} catch (error) {
|
|
38
|
+
failures.push(error);
|
|
39
|
+
}
|
|
40
|
+
return failures;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
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 });
|
|
46
|
+
}
|
|
47
|
+
function cleanupDisposer(ledger) {
|
|
48
|
+
return async () => {
|
|
49
|
+
const failures = await ledger.disposeAll();
|
|
50
|
+
if (failures.length > 0) throw new AggregateError(failures, "Subagent runtime cleanup failed");
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/** Retain the typed-only startup fallback and reverse, idempotent cleanup contract. */
|
|
54
|
+
async function mountWithStartupFallback(candidate, fallback) {
|
|
55
|
+
const ledger = new CleanupLedger();
|
|
56
|
+
try {
|
|
57
|
+
return {
|
|
58
|
+
value: await candidate((dispose) => ledger.add(dispose)),
|
|
59
|
+
dispose: cleanupDisposer(ledger)
|
|
60
|
+
};
|
|
61
|
+
} catch (error) {
|
|
62
|
+
const failures = await ledger.disposeAll();
|
|
63
|
+
if (!(error instanceof StartupIncompatibilityError) || failures.length > 0) startupFailure(error, failures);
|
|
64
|
+
}
|
|
65
|
+
try {
|
|
66
|
+
return {
|
|
67
|
+
value: await fallback((dispose) => ledger.add(dispose)),
|
|
68
|
+
dispose: cleanupDisposer(ledger)
|
|
69
|
+
};
|
|
70
|
+
} catch (error) {
|
|
71
|
+
startupFailure(error, await ledger.disposeAll());
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function routedRuntimeUnavailableNotice(error) {
|
|
75
|
+
return `model-switch: the routed Subagent runtime is unavailable on this DSH Host (${error.message}); delegation follows the official route instead`;
|
|
76
|
+
}
|
|
77
|
+
/** @deprecated Only the legacy subclass needs a mirrored dependency list. */
|
|
78
|
+
function subagentRuntimeInject(officialInject) {
|
|
79
|
+
return [.../* @__PURE__ */ new Set([...officialInject ?? [], "modelSwitch"])];
|
|
80
|
+
}
|
|
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;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
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.
|
|
90
|
+
*/
|
|
91
|
+
var ModelSwitchSubagentRuntime = class extends OfficialSubagentRuntime {
|
|
92
|
+
static inject = subagentRuntimeInject(OfficialSubagentRuntime.inject);
|
|
93
|
+
routed(name, request) {
|
|
94
|
+
const provider = this.ctx.subagents.getProvider(name);
|
|
95
|
+
if (provider !== void 0 && provider.capabilities.agentOptions !== true) return request;
|
|
96
|
+
return routeSubagentRequest(request, sessionSubagentRouteOf(this.ctx, request.parent.session, this.ctx.modelSwitch.currentSettings()));
|
|
97
|
+
}
|
|
98
|
+
start(name, request) {
|
|
99
|
+
return Reflect.apply(publicMethod("start"), this, [name, this.routed(name, request)]);
|
|
100
|
+
}
|
|
101
|
+
startContinuable(spec) {
|
|
102
|
+
return Reflect.apply(publicMethod("startContinuable"), this, [{
|
|
103
|
+
...spec,
|
|
104
|
+
request: this.routed(spec.provider, spec.request)
|
|
105
|
+
}]);
|
|
106
|
+
}
|
|
107
|
+
startActivation(spec) {
|
|
108
|
+
const request = spec.request ?? spec;
|
|
109
|
+
return Reflect.apply(publicMethod("startActivation"), this, [{
|
|
110
|
+
...spec,
|
|
111
|
+
request: this.routed(spec.provider, request)
|
|
112
|
+
}]);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
//#endregion
|
|
116
|
+
//#region lib/types/subagent-runtime.js
|
|
117
|
+
function present(value) {
|
|
118
|
+
return typeof value === "string" && value.trim() !== "";
|
|
119
|
+
}
|
|
120
|
+
function spawnHasAnyRouteField(options) {
|
|
121
|
+
return present(options?.provider) || present(options?.model) || options?.reasoningEffort !== void 0;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Inject a parent-session route only when the caller named no provider, model,
|
|
125
|
+
* or reasoning effort. All other request and Agent options pass through.
|
|
126
|
+
*/
|
|
127
|
+
function routeSubagentRequest(request, route) {
|
|
128
|
+
if (spawnHasAnyRouteField(request.agentOptions) || route === void 0) return request;
|
|
129
|
+
return {
|
|
130
|
+
...request,
|
|
131
|
+
agentOptions: {
|
|
132
|
+
...request.agentOptions,
|
|
133
|
+
provider: route.provider,
|
|
134
|
+
model: route.model,
|
|
135
|
+
...route.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(route.reasoningEffort) }
|
|
136
|
+
}
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
/** Resolve the current public route surface, never retaining a disposed service. */
|
|
140
|
+
function routedSubagentRequest(ctx, runtime, providerName, request) {
|
|
141
|
+
if (spawnHasAnyRouteField(request.agentOptions)) return request;
|
|
142
|
+
const provider = runtime.getProvider?.(providerName);
|
|
143
|
+
if (provider !== void 0 && provider.capabilities?.agentOptions !== true) return request;
|
|
144
|
+
let modelSwitch;
|
|
145
|
+
try {
|
|
146
|
+
modelSwitch = ctx.get("modelSwitch");
|
|
147
|
+
} catch {
|
|
148
|
+
return request;
|
|
149
|
+
}
|
|
150
|
+
if (typeof modelSwitch?.currentSettings !== "function") return request;
|
|
151
|
+
return routeSubagentRequest(request, sessionSubagentRouteOf(ctx, request.parent.session, modelSwitch.currentSettings()));
|
|
152
|
+
}
|
|
153
|
+
/** A tracing proxy is for calls, not method ownership or descriptor restoration. */
|
|
154
|
+
function originalService(value) {
|
|
155
|
+
const original = Reflect.get(value, symbols.original);
|
|
156
|
+
return original !== null && (typeof original === "object" || typeof original === "function") ? original : value;
|
|
157
|
+
}
|
|
158
|
+
function isRequest(value) {
|
|
159
|
+
if (typeof value !== "object" || value === null) return false;
|
|
160
|
+
const parent = Reflect.get(value, "parent");
|
|
161
|
+
return typeof parent === "object" && parent !== null && Reflect.get(parent, "session") !== void 0;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Route one activation spec under either released shape. 0.2.1 through
|
|
165
|
+
* 0.2.2-rc.1 nest the SubagentStartRequest under spec.request; 0.2.2-rc.2
|
|
166
|
+
* flattens those fields onto the spec itself. Unknown shapes pass through
|
|
167
|
+
* untouched, so an unanticipated future shape keeps the official route.
|
|
168
|
+
*/
|
|
169
|
+
function routedSpecOf(spec, provider, state) {
|
|
170
|
+
const nested = Reflect.get(spec, "request");
|
|
171
|
+
if (typeof nested === "object" && nested !== null && isRequest(nested)) {
|
|
172
|
+
const request = routeFor(state, provider, nested);
|
|
173
|
+
return request === nested ? spec : {
|
|
174
|
+
...spec,
|
|
175
|
+
request
|
|
176
|
+
};
|
|
177
|
+
}
|
|
178
|
+
if (isRequest(spec)) {
|
|
179
|
+
const request = routeFor(state, provider, spec);
|
|
180
|
+
if (request === spec) return spec;
|
|
181
|
+
return {
|
|
182
|
+
...spec,
|
|
183
|
+
agentOptions: request.agentOptions
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
return spec;
|
|
187
|
+
}
|
|
188
|
+
function warn(ctx, message) {
|
|
189
|
+
try {
|
|
190
|
+
ctx.logger.warn(message);
|
|
191
|
+
} catch {}
|
|
192
|
+
}
|
|
193
|
+
const wrappers = /* @__PURE__ */ new WeakMap();
|
|
194
|
+
function routeFor(state, provider, request) {
|
|
195
|
+
const ctx = [...state.leases].at(-1)?.ctx;
|
|
196
|
+
return ctx === void 0 ? request : routedSubagentRequest(ctx, state.runtime, provider, request);
|
|
197
|
+
}
|
|
198
|
+
function wrapMethod(target, key, factory) {
|
|
199
|
+
const original = Reflect.get(target, key);
|
|
200
|
+
if (typeof original !== "function") return void 0;
|
|
201
|
+
const previous = Object.getOwnPropertyDescriptor(target, key);
|
|
202
|
+
const wrapped = factory(original);
|
|
203
|
+
Object.defineProperty(target, key, {
|
|
204
|
+
configurable: true,
|
|
205
|
+
enumerable: previous?.enumerable ?? false,
|
|
206
|
+
writable: true,
|
|
207
|
+
value: wrapped
|
|
208
|
+
});
|
|
209
|
+
return () => {
|
|
210
|
+
if (Object.getOwnPropertyDescriptor(target, key)?.value !== wrapped) return;
|
|
211
|
+
if (previous === void 0) Reflect.deleteProperty(target, key);
|
|
212
|
+
else Object.defineProperty(target, key, previous);
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
* Wrap the official service's start entries only. Its identity, prototype,
|
|
217
|
+
* registry, manager, Typert binding and prompt/interrupt methods are untouched.
|
|
218
|
+
* Disposers are idempotent and safe when overlapping adapter fibers unload in
|
|
219
|
+
* either order. Unsupported or sealed surfaces leave the official route usable.
|
|
220
|
+
*/
|
|
221
|
+
function installSubagentRouteWrappers(ctx) {
|
|
222
|
+
const service = ctx.get("subagents");
|
|
223
|
+
if (service === void 0) {
|
|
224
|
+
warn(ctx, "model-switch: subagents service is unavailable; delegation keeps the official route");
|
|
225
|
+
return () => {};
|
|
226
|
+
}
|
|
227
|
+
const runtime = originalService(service);
|
|
228
|
+
let state = wrappers.get(runtime);
|
|
229
|
+
if (state === void 0) {
|
|
230
|
+
state = {
|
|
231
|
+
runtime,
|
|
232
|
+
leases: /* @__PURE__ */ new Set(),
|
|
233
|
+
restores: []
|
|
234
|
+
};
|
|
235
|
+
const current = state;
|
|
236
|
+
const wrap = (key, factory) => {
|
|
237
|
+
const restore = wrapMethod(runtime, key, factory);
|
|
238
|
+
if (restore !== void 0) current.restores.push(restore);
|
|
239
|
+
};
|
|
240
|
+
try {
|
|
241
|
+
for (const key of ["startActivation", "startContinuable"]) wrap(key, (original) => function(...args) {
|
|
242
|
+
const rawSpec = args[0];
|
|
243
|
+
if (typeof rawSpec !== "object" || rawSpec === null) return Reflect.apply(original, this, args);
|
|
244
|
+
const spec = rawSpec;
|
|
245
|
+
if (typeof spec.provider !== "string") return Reflect.apply(original, this, args);
|
|
246
|
+
return Reflect.apply(original, this, [routedSpecOf(spec, spec.provider, current), ...args.slice(1)]);
|
|
247
|
+
});
|
|
248
|
+
wrap("start", (original) => function(...args) {
|
|
249
|
+
const [provider, request] = args;
|
|
250
|
+
if (typeof provider !== "string" || !isRequest(request)) return Reflect.apply(original, this, args);
|
|
251
|
+
return Reflect.apply(original, this, [
|
|
252
|
+
provider,
|
|
253
|
+
routeFor(current, provider, request),
|
|
254
|
+
...args.slice(2)
|
|
255
|
+
]);
|
|
256
|
+
});
|
|
257
|
+
} catch (error) {
|
|
258
|
+
for (const restore of current.restores.reverse()) restore();
|
|
259
|
+
warn(ctx, `model-switch: Subagent starts cannot be wrapped (${String(error)}); delegation keeps the official route`);
|
|
260
|
+
return () => {};
|
|
261
|
+
}
|
|
262
|
+
if (current.restores.length === 0) {
|
|
263
|
+
warn(ctx, "model-switch: no supported public Subagent start entry; delegation keeps the official route");
|
|
264
|
+
return () => {};
|
|
265
|
+
}
|
|
266
|
+
wrappers.set(runtime, state);
|
|
267
|
+
}
|
|
268
|
+
const lease = { ctx };
|
|
269
|
+
state.leases.add(lease);
|
|
270
|
+
const owned = state;
|
|
271
|
+
return () => {
|
|
272
|
+
if (!owned.leases.delete(lease) || owned.leases.size > 0) return;
|
|
273
|
+
for (const restore of [...owned.restores].reverse()) restore();
|
|
274
|
+
wrappers.delete(runtime);
|
|
275
|
+
};
|
|
276
|
+
}
|
|
277
|
+
/** The official tool that lists routes available for explicit child selection. */
|
|
278
|
+
const SUBAGENT_MODEL_DISCOVERY_TOOL = "list_subagent_models";
|
|
279
|
+
/**
|
|
280
|
+
* Live state of the discovery-hint adapter, surfaced through the capabilities
|
|
281
|
+
* RPC next to the other adapter states.
|
|
282
|
+
*/
|
|
283
|
+
const subagentDiscoveryHintStatus = {
|
|
284
|
+
/** The tools registry was reachable and the adapter installed. */
|
|
285
|
+
installed: false,
|
|
286
|
+
/** The discovery tool was found and its execute wrapped. */
|
|
287
|
+
toolWrapped: false
|
|
288
|
+
};
|
|
289
|
+
/** Marker so a re-sweep never wraps a wrapper. */
|
|
290
|
+
const discoveryHintMarker = Symbol("modelSwitchSubagentDiscoveryHint");
|
|
291
|
+
/** The calling agent's session handle, as discovery executions carry it. */
|
|
292
|
+
function sessionOfExec(exec) {
|
|
293
|
+
const agent = exec?.agent;
|
|
294
|
+
const session = agent === null || typeof agent !== "object" ? void 0 : agent.session;
|
|
295
|
+
return session === null || typeof session !== "object" ? void 0 : session;
|
|
296
|
+
}
|
|
297
|
+
/**
|
|
298
|
+
* Compose the route footer appended to the discovery tool's text output.
|
|
299
|
+
*
|
|
300
|
+
* Pure so the copy and the source attribution stay unit-testable.
|
|
301
|
+
*
|
|
302
|
+
* @param route - the route an unnamed spawn from this session would use.
|
|
303
|
+
* @param pinnedByGroup - whether a provider group (not the flat card) pinned it.
|
|
304
|
+
* @returns the footer line; undefined routes are stated as official inherit.
|
|
305
|
+
*/
|
|
306
|
+
function subagentDiscoveryFooter(route, pinnedByGroup) {
|
|
307
|
+
if (route === void 0) return "Default route for spawns that name no provider/model (Model Switch): official inherit (nothing pinned).";
|
|
308
|
+
const source = pinnedByGroup ? "provider group pin" : "fixed card";
|
|
309
|
+
const effort = route.reasoningEffort === void 0 ? "" : `, effort ${route.reasoningEffort}`;
|
|
310
|
+
return `Default route for spawns that name no provider/model (Model Switch, ${source}): ${route.provider}/${route.model}${effort}`;
|
|
311
|
+
}
|
|
312
|
+
/** Read the effective route and its source for one discovery execution. */
|
|
313
|
+
function discoveryRouteOf(ctx, exec) {
|
|
314
|
+
const session = sessionOfExec(exec);
|
|
315
|
+
let settings;
|
|
316
|
+
try {
|
|
317
|
+
const modelSwitch = ctx.get("modelSwitch");
|
|
318
|
+
settings = typeof modelSwitch?.currentSettings === "function" ? modelSwitch.currentSettings() : void 0;
|
|
319
|
+
} catch {
|
|
320
|
+
settings = void 0;
|
|
321
|
+
}
|
|
322
|
+
const route = sessionSubagentRouteOf(ctx, session, settings);
|
|
323
|
+
return {
|
|
324
|
+
route,
|
|
325
|
+
pinnedByGroup: route !== void 0 && groupRoute(settings, sessionProviderOf(ctx, session), "subagent") !== void 0
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
/**
|
|
329
|
+
* Wrap the official discovery tool's execute so its text output also states the
|
|
330
|
+
* route an unnamed spawn would actually take — the one piece the
|
|
331
|
+
* authorized-route listing cannot know.
|
|
332
|
+
*
|
|
333
|
+
* The wrap is in place on the registered definition (the registry resolves
|
|
334
|
+
* tools per call), idempotent across re-sweeps, and re-applied when the
|
|
335
|
+
* registry changes so a re-registered tool is covered too. Unknown result
|
|
336
|
+
* shapes pass through untouched; unload restores the official execute.
|
|
337
|
+
*
|
|
338
|
+
* @param ctx - this row's context.
|
|
339
|
+
* @returns a disposer that detaches the listener and restores the execute.
|
|
340
|
+
*/
|
|
341
|
+
function installSubagentDiscoveryHint(ctx) {
|
|
342
|
+
const tools = ctx.get("tools", false);
|
|
343
|
+
if (tools === void 0 || typeof tools.get !== "function") {
|
|
344
|
+
warn(ctx, "model-switch: the tools registry is unavailable; list_subagent_models keeps its official output");
|
|
345
|
+
return () => {};
|
|
346
|
+
}
|
|
347
|
+
subagentDiscoveryHintStatus.installed = true;
|
|
348
|
+
const restores = [];
|
|
349
|
+
let wrappedOnce = false;
|
|
350
|
+
const sweep = () => {
|
|
351
|
+
const definition = tools.get(SUBAGENT_MODEL_DISCOVERY_TOOL);
|
|
352
|
+
if (definition === void 0) return;
|
|
353
|
+
const current = definition.execute;
|
|
354
|
+
if (typeof current !== "function" || Reflect.get(current, discoveryHintMarker) === true) return;
|
|
355
|
+
const restore = wrapMethod(definition, "execute", (original) => {
|
|
356
|
+
const wrapped = function(...args) {
|
|
357
|
+
const returned = Reflect.apply(original, this, args);
|
|
358
|
+
const append = (value) => {
|
|
359
|
+
if (typeof value !== "string") return value;
|
|
360
|
+
const { route, pinnedByGroup } = discoveryRouteOf(ctx, args[1]);
|
|
361
|
+
return `${value}\n${subagentDiscoveryFooter(route, pinnedByGroup)}`;
|
|
362
|
+
};
|
|
363
|
+
if (returned !== null && (typeof returned === "object" || typeof returned === "function") && typeof returned.then === "function") return returned.then(append);
|
|
364
|
+
return append(returned);
|
|
365
|
+
};
|
|
366
|
+
Object.defineProperty(wrapped, discoveryHintMarker, { value: true });
|
|
367
|
+
return wrapped;
|
|
368
|
+
});
|
|
369
|
+
if (restore !== void 0) {
|
|
370
|
+
restores.push(restore);
|
|
371
|
+
subagentDiscoveryHintStatus.toolWrapped = true;
|
|
372
|
+
if (!wrappedOnce) {
|
|
373
|
+
wrappedOnce = true;
|
|
374
|
+
try {
|
|
375
|
+
ctx.logger.info("model-switch: list_subagent_models now states the effective default route for unnamed spawns");
|
|
376
|
+
} catch {}
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
sweep();
|
|
381
|
+
let attempts = 0;
|
|
382
|
+
const retry = setInterval(() => {
|
|
383
|
+
attempts += 1;
|
|
384
|
+
sweep();
|
|
385
|
+
if (wrappedOnce || attempts >= 15) clearInterval(retry);
|
|
386
|
+
}, 1e3);
|
|
387
|
+
const off = ctx.on("tools/change", sweep);
|
|
388
|
+
return () => {
|
|
389
|
+
off();
|
|
390
|
+
clearInterval(retry);
|
|
391
|
+
for (const restore of restores.reverse()) restore();
|
|
392
|
+
restores.length = 0;
|
|
393
|
+
subagentDiscoveryHintStatus.installed = false;
|
|
394
|
+
subagentDiscoveryHintStatus.toolWrapped = false;
|
|
395
|
+
};
|
|
396
|
+
}
|
|
397
|
+
/**
|
|
398
|
+
* Wait for the official service without replacing it or copying its dependency
|
|
399
|
+
* list. Model Switch is read optionally per call, so its absence cannot hold a
|
|
400
|
+
* startup fiber or retain a stale settings service. Cordis rebinds this effect
|
|
401
|
+
* when the official service is recreated.
|
|
402
|
+
*/
|
|
403
|
+
function profileSubagentRuntime(ctx) {
|
|
404
|
+
ctx.inject(["subagents"], (scope) => {
|
|
405
|
+
scope.effect(() => installSubagentRouteWrappers(scope), "Model Switch: route official Subagent starts");
|
|
406
|
+
});
|
|
407
|
+
ctx.inject(["tools"], (scope) => {
|
|
408
|
+
scope.effect(() => installSubagentDiscoveryHint(scope), "Model Switch: annotate the subagent model discovery tool");
|
|
409
|
+
});
|
|
410
|
+
}
|
|
411
|
+
//#endregion
|
|
412
|
+
export { routedSubagentRequest as a, ModelSwitchSubagentRuntime as c, routedRuntimeUnavailableNotice as d, subagentRuntimeInject as f, routeSubagentRequest as i, StartupIncompatibilityError as l, installSubagentRouteWrappers as n, subagentDiscoveryFooter as o, subagentSurfaceOf as p, profileSubagentRuntime as r, subagentDiscoveryHintStatus as s, installSubagentDiscoveryHint as t, mountWithStartupFallback as u };
|
package/lib/subagent-runtime.js
CHANGED
|
@@ -1,289 +1,2 @@
|
|
|
1
|
-
import { o as
|
|
2
|
-
|
|
3
|
-
import { ReasoningEffortId } from "@deepseek-ai/dsh-llm";
|
|
4
|
-
import OfficialSubagentRuntime from "@deepseek-ai/dsh-subagent";
|
|
5
|
-
//#region lib/types/subagent-runtime-legacy.js
|
|
6
|
-
/** Previously published startup error; retained for consumers of this module. */
|
|
7
|
-
var StartupIncompatibilityError = class extends Error {
|
|
8
|
-
name = "StartupIncompatibilityError";
|
|
9
|
-
surface;
|
|
10
|
-
constructor(surfaceOrMessage, message) {
|
|
11
|
-
super(message ?? surfaceOrMessage);
|
|
12
|
-
this.surface = message === void 0 ? "startup" : surfaceOrMessage;
|
|
13
|
-
}
|
|
14
|
-
};
|
|
15
|
-
/** Classify the two published start API generations without version guessing. */
|
|
16
|
-
function subagentSurfaceOf(value) {
|
|
17
|
-
if (value === null || typeof value !== "object" && typeof value !== "function") return void 0;
|
|
18
|
-
if (typeof Reflect.get(value, "startActivation") === "function") return "activation";
|
|
19
|
-
return typeof Reflect.get(value, "start") === "function" && typeof Reflect.get(value, "startContinuable") === "function" ? "start" : void 0;
|
|
20
|
-
}
|
|
21
|
-
function once(dispose) {
|
|
22
|
-
let pending;
|
|
23
|
-
return () => {
|
|
24
|
-
pending ??= Promise.resolve().then(() => dispose()).then(() => void 0);
|
|
25
|
-
return pending;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
var CleanupLedger = class {
|
|
29
|
-
attempts = [];
|
|
30
|
-
add(dispose) {
|
|
31
|
-
this.attempts.push(once(dispose));
|
|
32
|
-
}
|
|
33
|
-
async disposeAll() {
|
|
34
|
-
const failures = [];
|
|
35
|
-
for (const dispose of [...this.attempts].reverse()) try {
|
|
36
|
-
await dispose();
|
|
37
|
-
} catch (error) {
|
|
38
|
-
failures.push(error);
|
|
39
|
-
}
|
|
40
|
-
return failures;
|
|
41
|
-
}
|
|
42
|
-
};
|
|
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 });
|
|
46
|
-
}
|
|
47
|
-
function cleanupDisposer(ledger) {
|
|
48
|
-
return async () => {
|
|
49
|
-
const failures = await ledger.disposeAll();
|
|
50
|
-
if (failures.length > 0) throw new AggregateError(failures, "Subagent runtime cleanup failed");
|
|
51
|
-
};
|
|
52
|
-
}
|
|
53
|
-
/** Retain the typed-only startup fallback and reverse, idempotent cleanup contract. */
|
|
54
|
-
async function mountWithStartupFallback(candidate, fallback) {
|
|
55
|
-
const ledger = new CleanupLedger();
|
|
56
|
-
try {
|
|
57
|
-
return {
|
|
58
|
-
value: await candidate((dispose) => ledger.add(dispose)),
|
|
59
|
-
dispose: cleanupDisposer(ledger)
|
|
60
|
-
};
|
|
61
|
-
} catch (error) {
|
|
62
|
-
const failures = await ledger.disposeAll();
|
|
63
|
-
if (!(error instanceof StartupIncompatibilityError) || failures.length > 0) startupFailure(error, failures);
|
|
64
|
-
}
|
|
65
|
-
try {
|
|
66
|
-
return {
|
|
67
|
-
value: await fallback((dispose) => ledger.add(dispose)),
|
|
68
|
-
dispose: cleanupDisposer(ledger)
|
|
69
|
-
};
|
|
70
|
-
} catch (error) {
|
|
71
|
-
startupFailure(error, await ledger.disposeAll());
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
function routedRuntimeUnavailableNotice(error) {
|
|
75
|
-
return `model-switch: the routed Subagent runtime is unavailable on this DSH Host (${error.message}); delegation follows the official route instead`;
|
|
76
|
-
}
|
|
77
|
-
/** @deprecated Only the legacy subclass needs a mirrored dependency list. */
|
|
78
|
-
function subagentRuntimeInject(officialInject) {
|
|
79
|
-
return [.../* @__PURE__ */ new Set([...officialInject ?? [], "modelSwitch"])];
|
|
80
|
-
}
|
|
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;
|
|
85
|
-
}
|
|
86
|
-
/**
|
|
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.
|
|
90
|
-
*/
|
|
91
|
-
var ModelSwitchSubagentRuntime = class extends OfficialSubagentRuntime {
|
|
92
|
-
static inject = subagentRuntimeInject(OfficialSubagentRuntime.inject);
|
|
93
|
-
routed(name, request) {
|
|
94
|
-
const provider = this.ctx.subagents.getProvider(name);
|
|
95
|
-
if (provider !== void 0 && provider.capabilities.agentOptions !== true) return request;
|
|
96
|
-
return routeSubagentRequest(request, sessionSubagentRouteOf(this.ctx, request.parent.session, this.ctx.modelSwitch.currentSettings()));
|
|
97
|
-
}
|
|
98
|
-
start(name, request) {
|
|
99
|
-
return Reflect.apply(publicMethod("start"), this, [name, this.routed(name, request)]);
|
|
100
|
-
}
|
|
101
|
-
startContinuable(spec) {
|
|
102
|
-
return Reflect.apply(publicMethod("startContinuable"), this, [{
|
|
103
|
-
...spec,
|
|
104
|
-
request: this.routed(spec.provider, spec.request)
|
|
105
|
-
}]);
|
|
106
|
-
}
|
|
107
|
-
startActivation(spec) {
|
|
108
|
-
const request = spec.request ?? spec;
|
|
109
|
-
return Reflect.apply(publicMethod("startActivation"), this, [{
|
|
110
|
-
...spec,
|
|
111
|
-
request: this.routed(spec.provider, request)
|
|
112
|
-
}]);
|
|
113
|
-
}
|
|
114
|
-
};
|
|
115
|
-
//#endregion
|
|
116
|
-
//#region lib/types/subagent-runtime.js
|
|
117
|
-
function present(value) {
|
|
118
|
-
return typeof value === "string" && value.trim() !== "";
|
|
119
|
-
}
|
|
120
|
-
function spawnHasAnyRouteField(options) {
|
|
121
|
-
return present(options?.provider) || present(options?.model) || options?.reasoningEffort !== void 0;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Inject a parent-session route only when the caller named no provider, model,
|
|
125
|
-
* or reasoning effort. All other request and Agent options pass through.
|
|
126
|
-
*/
|
|
127
|
-
function routeSubagentRequest(request, route) {
|
|
128
|
-
if (spawnHasAnyRouteField(request.agentOptions) || route === void 0) return request;
|
|
129
|
-
return {
|
|
130
|
-
...request,
|
|
131
|
-
agentOptions: {
|
|
132
|
-
...request.agentOptions,
|
|
133
|
-
provider: route.provider,
|
|
134
|
-
model: route.model,
|
|
135
|
-
...route.reasoningEffort === void 0 ? {} : { reasoningEffort: ReasoningEffortId(route.reasoningEffort) }
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
}
|
|
139
|
-
/** Resolve the current public route surface, never retaining a disposed service. */
|
|
140
|
-
function routedSubagentRequest(ctx, runtime, providerName, request) {
|
|
141
|
-
if (spawnHasAnyRouteField(request.agentOptions)) return request;
|
|
142
|
-
const provider = runtime.getProvider?.(providerName);
|
|
143
|
-
if (provider !== void 0 && provider.capabilities?.agentOptions !== true) return request;
|
|
144
|
-
let modelSwitch;
|
|
145
|
-
try {
|
|
146
|
-
modelSwitch = ctx.get("modelSwitch");
|
|
147
|
-
} catch {
|
|
148
|
-
return request;
|
|
149
|
-
}
|
|
150
|
-
if (typeof modelSwitch?.currentSettings !== "function") return request;
|
|
151
|
-
return routeSubagentRequest(request, sessionSubagentRouteOf(ctx, request.parent.session, modelSwitch.currentSettings()));
|
|
152
|
-
}
|
|
153
|
-
/** A tracing proxy is for calls, not method ownership or descriptor restoration. */
|
|
154
|
-
function originalService(value) {
|
|
155
|
-
const original = Reflect.get(value, symbols.original);
|
|
156
|
-
return original !== null && (typeof original === "object" || typeof original === "function") ? original : value;
|
|
157
|
-
}
|
|
158
|
-
function isRequest(value) {
|
|
159
|
-
if (typeof value !== "object" || value === null) return false;
|
|
160
|
-
const parent = Reflect.get(value, "parent");
|
|
161
|
-
return typeof parent === "object" && parent !== null && Reflect.get(parent, "session") !== void 0;
|
|
162
|
-
}
|
|
163
|
-
/**
|
|
164
|
-
* Route one activation spec under either released shape. 0.2.1 through
|
|
165
|
-
* 0.2.2-rc.1 nest the SubagentStartRequest under spec.request; 0.2.2-rc.2
|
|
166
|
-
* flattens those fields onto the spec itself. Unknown shapes pass through
|
|
167
|
-
* untouched, so an unanticipated future shape keeps the official route.
|
|
168
|
-
*/
|
|
169
|
-
function routedSpecOf(spec, provider, state) {
|
|
170
|
-
const nested = Reflect.get(spec, "request");
|
|
171
|
-
if (typeof nested === "object" && nested !== null && isRequest(nested)) {
|
|
172
|
-
const request = routeFor(state, provider, nested);
|
|
173
|
-
return request === nested ? spec : {
|
|
174
|
-
...spec,
|
|
175
|
-
request
|
|
176
|
-
};
|
|
177
|
-
}
|
|
178
|
-
if (isRequest(spec)) {
|
|
179
|
-
const request = routeFor(state, provider, spec);
|
|
180
|
-
if (request === spec) return spec;
|
|
181
|
-
return {
|
|
182
|
-
...spec,
|
|
183
|
-
agentOptions: request.agentOptions
|
|
184
|
-
};
|
|
185
|
-
}
|
|
186
|
-
return spec;
|
|
187
|
-
}
|
|
188
|
-
function warn(ctx, message) {
|
|
189
|
-
try {
|
|
190
|
-
ctx.logger.warn(message);
|
|
191
|
-
} catch {}
|
|
192
|
-
}
|
|
193
|
-
const wrappers = /* @__PURE__ */ new WeakMap();
|
|
194
|
-
function routeFor(state, provider, request) {
|
|
195
|
-
const ctx = [...state.leases].at(-1)?.ctx;
|
|
196
|
-
return ctx === void 0 ? request : routedSubagentRequest(ctx, state.runtime, provider, request);
|
|
197
|
-
}
|
|
198
|
-
function wrapMethod(target, key, factory) {
|
|
199
|
-
const original = Reflect.get(target, key);
|
|
200
|
-
if (typeof original !== "function") return void 0;
|
|
201
|
-
const previous = Object.getOwnPropertyDescriptor(target, key);
|
|
202
|
-
const wrapped = factory(original);
|
|
203
|
-
Object.defineProperty(target, key, {
|
|
204
|
-
configurable: true,
|
|
205
|
-
enumerable: previous?.enumerable ?? false,
|
|
206
|
-
writable: true,
|
|
207
|
-
value: wrapped
|
|
208
|
-
});
|
|
209
|
-
return () => {
|
|
210
|
-
if (Object.getOwnPropertyDescriptor(target, key)?.value !== wrapped) return;
|
|
211
|
-
if (previous === void 0) Reflect.deleteProperty(target, key);
|
|
212
|
-
else Object.defineProperty(target, key, previous);
|
|
213
|
-
};
|
|
214
|
-
}
|
|
215
|
-
/**
|
|
216
|
-
* Wrap the official service's start entries only. Its identity, prototype,
|
|
217
|
-
* registry, manager, Typert binding and prompt/interrupt methods are untouched.
|
|
218
|
-
* Disposers are idempotent and safe when overlapping adapter fibers unload in
|
|
219
|
-
* either order. Unsupported or sealed surfaces leave the official route usable.
|
|
220
|
-
*/
|
|
221
|
-
function installSubagentRouteWrappers(ctx) {
|
|
222
|
-
const service = ctx.get("subagents");
|
|
223
|
-
if (service === void 0) {
|
|
224
|
-
warn(ctx, "model-switch: subagents service is unavailable; delegation keeps the official route");
|
|
225
|
-
return () => {};
|
|
226
|
-
}
|
|
227
|
-
const runtime = originalService(service);
|
|
228
|
-
let state = wrappers.get(runtime);
|
|
229
|
-
if (state === void 0) {
|
|
230
|
-
state = {
|
|
231
|
-
runtime,
|
|
232
|
-
leases: /* @__PURE__ */ new Set(),
|
|
233
|
-
restores: []
|
|
234
|
-
};
|
|
235
|
-
const current = state;
|
|
236
|
-
const wrap = (key, factory) => {
|
|
237
|
-
const restore = wrapMethod(runtime, key, factory);
|
|
238
|
-
if (restore !== void 0) current.restores.push(restore);
|
|
239
|
-
};
|
|
240
|
-
try {
|
|
241
|
-
for (const key of ["startActivation", "startContinuable"]) wrap(key, (original) => function(...args) {
|
|
242
|
-
const rawSpec = args[0];
|
|
243
|
-
if (typeof rawSpec !== "object" || rawSpec === null) return Reflect.apply(original, this, args);
|
|
244
|
-
const spec = rawSpec;
|
|
245
|
-
if (typeof spec.provider !== "string") return Reflect.apply(original, this, args);
|
|
246
|
-
return Reflect.apply(original, this, [routedSpecOf(spec, spec.provider, current), ...args.slice(1)]);
|
|
247
|
-
});
|
|
248
|
-
wrap("start", (original) => function(...args) {
|
|
249
|
-
const [provider, request] = args;
|
|
250
|
-
if (typeof provider !== "string" || !isRequest(request)) return Reflect.apply(original, this, args);
|
|
251
|
-
return Reflect.apply(original, this, [
|
|
252
|
-
provider,
|
|
253
|
-
routeFor(current, provider, request),
|
|
254
|
-
...args.slice(2)
|
|
255
|
-
]);
|
|
256
|
-
});
|
|
257
|
-
} catch (error) {
|
|
258
|
-
for (const restore of current.restores.reverse()) restore();
|
|
259
|
-
warn(ctx, `model-switch: Subagent starts cannot be wrapped (${String(error)}); delegation keeps the official route`);
|
|
260
|
-
return () => {};
|
|
261
|
-
}
|
|
262
|
-
if (current.restores.length === 0) {
|
|
263
|
-
warn(ctx, "model-switch: no supported public Subagent start entry; delegation keeps the official route");
|
|
264
|
-
return () => {};
|
|
265
|
-
}
|
|
266
|
-
wrappers.set(runtime, state);
|
|
267
|
-
}
|
|
268
|
-
const lease = { ctx };
|
|
269
|
-
state.leases.add(lease);
|
|
270
|
-
const owned = state;
|
|
271
|
-
return () => {
|
|
272
|
-
if (!owned.leases.delete(lease) || owned.leases.size > 0) return;
|
|
273
|
-
for (const restore of [...owned.restores].reverse()) restore();
|
|
274
|
-
wrappers.delete(runtime);
|
|
275
|
-
};
|
|
276
|
-
}
|
|
277
|
-
/**
|
|
278
|
-
* Wait for the official service without replacing it or copying its dependency
|
|
279
|
-
* list. Model Switch is read optionally per call, so its absence cannot hold a
|
|
280
|
-
* startup fiber or retain a stale settings service. Cordis rebinds this effect
|
|
281
|
-
* when the official service is recreated.
|
|
282
|
-
*/
|
|
283
|
-
function profileSubagentRuntime(ctx) {
|
|
284
|
-
ctx.inject(["subagents"], (scope) => {
|
|
285
|
-
scope.effect(() => installSubagentRouteWrappers(scope), "Model Switch: route official Subagent starts");
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
//#endregion
|
|
289
|
-
export { ModelSwitchSubagentRuntime, StartupIncompatibilityError, profileSubagentRuntime as default, profileSubagentRuntime, installSubagentRouteWrappers, mountWithStartupFallback, routeSubagentRequest, routedRuntimeUnavailableNotice, routedSubagentRequest, subagentRuntimeInject, subagentSurfaceOf };
|
|
1
|
+
import { a as routedSubagentRequest, c as ModelSwitchSubagentRuntime, d as routedRuntimeUnavailableNotice, f as subagentRuntimeInject, i as routeSubagentRequest, l as StartupIncompatibilityError, n as installSubagentRouteWrappers, o as subagentDiscoveryFooter, p as subagentSurfaceOf, r as profileSubagentRuntime, s as subagentDiscoveryHintStatus, t as installSubagentDiscoveryHint, u as mountWithStartupFallback } from "./subagent-runtime-BgLqMl2z.js";
|
|
2
|
+
export { ModelSwitchSubagentRuntime, StartupIncompatibilityError, profileSubagentRuntime as default, profileSubagentRuntime, installSubagentDiscoveryHint, installSubagentRouteWrappers, mountWithStartupFallback, routeSubagentRequest, routedRuntimeUnavailableNotice, routedSubagentRequest, subagentDiscoveryFooter, subagentDiscoveryHintStatus, subagentRuntimeInject, subagentSurfaceOf };
|
|
@@ -46,6 +46,40 @@ export declare function routedSubagentRequest<T extends RoutableSubagentRequest>
|
|
|
46
46
|
* either order. Unsupported or sealed surfaces leave the official route usable.
|
|
47
47
|
*/
|
|
48
48
|
export declare function installSubagentRouteWrappers(ctx: Context): () => void;
|
|
49
|
+
/**
|
|
50
|
+
* Live state of the discovery-hint adapter, surfaced through the capabilities
|
|
51
|
+
* RPC next to the other adapter states.
|
|
52
|
+
*/
|
|
53
|
+
export declare const subagentDiscoveryHintStatus: {
|
|
54
|
+
/** The tools registry was reachable and the adapter installed. */
|
|
55
|
+
installed: boolean;
|
|
56
|
+
/** The discovery tool was found and its execute wrapped. */
|
|
57
|
+
toolWrapped: boolean;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* Compose the route footer appended to the discovery tool's text output.
|
|
61
|
+
*
|
|
62
|
+
* Pure so the copy and the source attribution stay unit-testable.
|
|
63
|
+
*
|
|
64
|
+
* @param route - the route an unnamed spawn from this session would use.
|
|
65
|
+
* @param pinnedByGroup - whether a provider group (not the flat card) pinned it.
|
|
66
|
+
* @returns the footer line; undefined routes are stated as official inherit.
|
|
67
|
+
*/
|
|
68
|
+
export declare function subagentDiscoveryFooter(route: SubagentRoute | undefined, pinnedByGroup: boolean): string;
|
|
69
|
+
/**
|
|
70
|
+
* Wrap the official discovery tool's execute so its text output also states the
|
|
71
|
+
* route an unnamed spawn would actually take — the one piece the
|
|
72
|
+
* authorized-route listing cannot know.
|
|
73
|
+
*
|
|
74
|
+
* The wrap is in place on the registered definition (the registry resolves
|
|
75
|
+
* tools per call), idempotent across re-sweeps, and re-applied when the
|
|
76
|
+
* registry changes so a re-registered tool is covered too. Unknown result
|
|
77
|
+
* shapes pass through untouched; unload restores the official execute.
|
|
78
|
+
*
|
|
79
|
+
* @param ctx - this row's context.
|
|
80
|
+
* @returns a disposer that detaches the listener and restores the execute.
|
|
81
|
+
*/
|
|
82
|
+
export declare function installSubagentDiscoveryHint(ctx: Context): () => void;
|
|
49
83
|
/**
|
|
50
84
|
* Wait for the official service without replacing it or copying its dependency
|
|
51
85
|
* list. Model Switch is read optionally per call, so its absence cannot hold a
|