dsh-multi-router 0.5.7 → 0.5.9
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 -0
- package/README.md +26 -10
- package/cordis.patch.yml +2 -2
- package/lib/accounts.js +3 -1
- package/lib/{chunk-JDZCWBA4.js → chunk-I4EW5TI7.js} +250 -66
- package/lib/chunk-I4EW5TI7.js.map +7 -0
- package/lib/{chunk-OFFVP6YN.js → chunk-S6ZQ45SS.js} +20 -3
- package/lib/chunk-S6ZQ45SS.js.map +7 -0
- package/lib/cli.js +1 -1
- package/lib/client.js +405 -310
- package/lib/client.js.map +2 -2
- package/lib/{host-v0.5.7.js → host-v0.5.9.js} +7 -108
- package/lib/host.js +7 -108
- package/lib/index.js +7 -108
- package/lib/index.js.map +4 -4
- package/lib/manager.js +2 -2
- package/package.json +1 -1
- package/lib/chunk-JDZCWBA4.js.map +0 -7
- package/lib/chunk-OFFVP6YN.js.map +0 -7
|
@@ -4,13 +4,14 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
MANAGEMENT_PATH,
|
|
6
6
|
Manager,
|
|
7
|
+
PluginReload,
|
|
7
8
|
managementHandler,
|
|
8
9
|
version
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-I4EW5TI7.js";
|
|
10
11
|
import {
|
|
11
12
|
createAccountClient
|
|
12
13
|
} from "./chunk-U2MU2M5C.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-S6ZQ45SS.js";
|
|
14
15
|
import "./chunk-FTM7RHQV.js";
|
|
15
16
|
import "./chunk-S5KMFAQM.js";
|
|
16
17
|
import "./chunk-DNQPZMPF.js";
|
|
@@ -32,7 +33,7 @@ import {
|
|
|
32
33
|
import z from "@deepseek-ai/schemastery";
|
|
33
34
|
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
34
35
|
import { resolveRetryPolicy as resolveRetryPolicy2, resolveImageAttachmentAccess } from "@deepseek-ai/dsh-llm";
|
|
35
|
-
import { join
|
|
36
|
+
import { join, resolve } from "node:path";
|
|
36
37
|
|
|
37
38
|
// upstream/workbuddy/src/adapter.ts
|
|
38
39
|
import { createProvider } from "@earendil-works/pi-ai";
|
|
@@ -246,113 +247,10 @@ var WorkBuddyPiAiAdapter = class extends PiAiAdapter {
|
|
|
246
247
|
}
|
|
247
248
|
};
|
|
248
249
|
|
|
249
|
-
// src/plugin-reload.mjs
|
|
250
|
-
import { readFile } from "node:fs/promises";
|
|
251
|
-
import { watch } from "node:fs";
|
|
252
|
-
import { join } from "node:path";
|
|
253
|
-
var PluginReload = class {
|
|
254
|
-
constructor({ service, profile, canReload, busy = () => false, now = Date.now, runningVersion }) {
|
|
255
|
-
Object.assign(this, { service, profile, canReload, busy, now, runningVersion });
|
|
256
|
-
this.phase = "current";
|
|
257
|
-
this.installedVersion = runningVersion;
|
|
258
|
-
this.retryAt = 0;
|
|
259
|
-
}
|
|
260
|
-
state() {
|
|
261
|
-
return { runningVersion: this.runningVersion, installedVersion: this.installedVersion, phase: this.phase, canReload: !!this.canReload(), message: this.message };
|
|
262
|
-
}
|
|
263
|
-
start() {
|
|
264
|
-
const dir = this.profile()?.dir;
|
|
265
|
-
if (dir) try {
|
|
266
|
-
this.watcher = watch(dir, () => this.schedule());
|
|
267
|
-
this.watcher.unref();
|
|
268
|
-
} catch {
|
|
269
|
-
}
|
|
270
|
-
this.schedule();
|
|
271
|
-
}
|
|
272
|
-
schedule(delay = 500) {
|
|
273
|
-
if (this.closed) return;
|
|
274
|
-
clearTimeout(this.timer);
|
|
275
|
-
this.timer = setTimeout(() => {
|
|
276
|
-
void this.check().catch(() => {
|
|
277
|
-
});
|
|
278
|
-
}, delay);
|
|
279
|
-
this.timer.unref();
|
|
280
|
-
}
|
|
281
|
-
stop() {
|
|
282
|
-
this.closed = true;
|
|
283
|
-
clearTimeout(this.timer);
|
|
284
|
-
this.watcher?.close();
|
|
285
|
-
}
|
|
286
|
-
check() {
|
|
287
|
-
if (this.closed) return Promise.resolve();
|
|
288
|
-
if (this.flight) return this.flight;
|
|
289
|
-
this.flight = this.inspect().finally(() => {
|
|
290
|
-
this.flight = void 0;
|
|
291
|
-
});
|
|
292
|
-
return this.flight;
|
|
293
|
-
}
|
|
294
|
-
async inspect() {
|
|
295
|
-
const dir = this.profile()?.dir;
|
|
296
|
-
if (!dir) return;
|
|
297
|
-
let manifest, installed;
|
|
298
|
-
try {
|
|
299
|
-
manifest = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
|
|
300
|
-
installed = JSON.parse(await readFile(join(dir, "node_modules/dsh-multi-router/package.json"), "utf8"));
|
|
301
|
-
} catch {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (this.closed || !manifest.dsh?.profile?.bundles?.includes("dsh-multi-router")) return;
|
|
305
|
-
if (installed.name !== "dsh-multi-router" || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(installed.version)) return;
|
|
306
|
-
this.installedVersion = installed.version;
|
|
307
|
-
if (installed.version === this.runningVersion) {
|
|
308
|
-
this.phase = "current";
|
|
309
|
-
this.message = void 0;
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if (!this.canReload() || !this.service()?.setBundleEnabled) {
|
|
313
|
-
this.phase = "restart-required";
|
|
314
|
-
this.message = "\u5F53\u524D DSH \u672A\u63D0\u4F9B\u8FD0\u884C\u4E2D\u91CD\u8F7D\uFF0C\u8BF7\u5347\u7EA7 DSH \u6216\u91CD\u542F\u5E94\u7528\u3002";
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
if (this.busy()) {
|
|
318
|
-
this.phase = "waiting";
|
|
319
|
-
this.message = "\u65B0\u7248\u672C\u5DF2\u5B89\u88C5\uFF0C\u7B49\u5F85\u5F53\u524D\u8BF7\u6C42\u548C\u8D26\u53F7\u64CD\u4F5C\u7ED3\u675F\u540E\u81EA\u52A8\u751F\u6548\u3002";
|
|
320
|
-
this.schedule(1e3);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
const root = join(dir, "node_modules/dsh-multi-router");
|
|
324
|
-
try {
|
|
325
|
-
const patch = await readFile(join(root, "cordis.patch.yml"), "utf8");
|
|
326
|
-
if (!patch.includes(`id: llm-multi-router-v2-${installed.version}
|
|
327
|
-
`) || !patch.includes(`name: ./lib/host-v${installed.version}.js`)) throw Error("legacy entry");
|
|
328
|
-
await readFile(join(root, `lib/host-v${installed.version}.js`));
|
|
329
|
-
} catch {
|
|
330
|
-
this.phase = "restart-required";
|
|
331
|
-
this.message = "\u5B89\u88C5\u7248\u672C\u7F3A\u5C11\u7248\u672C\u5316\u5165\u53E3\uFF0C\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248\u540E\u518D\u8BD5\u3002";
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
if (this.now() < this.retryAt) return;
|
|
335
|
-
this.phase = "reloading";
|
|
336
|
-
this.message = "\u6B63\u5728\u91CD\u65B0\u52A0\u8F7D\u63D2\u4EF6\u4E0E\u914D\u7F6E\u9762\u677F\u2026";
|
|
337
|
-
this.retryAt = this.now() + 6e4;
|
|
338
|
-
try {
|
|
339
|
-
const result = await this.service().setBundleEnabled("dsh-multi-router", true);
|
|
340
|
-
if (this.closed) return;
|
|
341
|
-
this.phase = "restart-required";
|
|
342
|
-
this.message = result.application === "applied" ? "DSH \u5C1A\u672A\u5207\u6362\u5230\u65B0\u7248\u672C\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u63D2\u4EF6\u6216\u67E5\u770B\u7EC4\u4EF6\u9519\u8BEF\u3002" : "DSH \u672A\u80FD\u91CD\u8F7D\u63D2\u4EF6\uFF0C\u8BF7\u5347\u7EA7 DSH \u6216\u91CD\u542F\u5E94\u7528\u3002";
|
|
343
|
-
} catch {
|
|
344
|
-
if (!this.closed) {
|
|
345
|
-
this.phase = "failed";
|
|
346
|
-
this.message = "\u63D2\u4EF6\u91CD\u8F7D\u672A\u5B8C\u6210\uFF0C\u53EF\u7A0D\u540E\u91CD\u8BD5\uFF1B\u5DF2\u4FDD\u5B58\u7684\u914D\u7F6E\u4FDD\u6301\u4E0D\u53D8\u3002";
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
|
|
352
250
|
// src/index.mjs
|
|
353
251
|
var name = "dsh-multi-router";
|
|
354
252
|
var inject = ["llm"];
|
|
355
|
-
var defaultConfigFile = () =>
|
|
253
|
+
var defaultConfigFile = () => join(resolveDshHome(), "multi-router", "router.json");
|
|
356
254
|
var Config = z.object({ configFile: z.string().description("Absolute path to multi-account router.json") });
|
|
357
255
|
async function apply(ctx, options = {}) {
|
|
358
256
|
let disposed = false, manager, stopWatch, monitorTimer, startup;
|
|
@@ -383,7 +281,7 @@ async function apply(ctx, options = {}) {
|
|
|
383
281
|
manager = new Manager(file, router, () => {
|
|
384
282
|
for (const wrapper of wrappers) wrapper.invalidate();
|
|
385
283
|
ctx.emit("llm/adapters-updated");
|
|
386
|
-
}, { service: () => ctx.get("pluginManager"), profile: () => ctx.get("profileContext") });
|
|
284
|
+
}, { service: () => ctx.get("pluginManager"), profile: () => ctx.get("profileContext"), hmr: () => ctx.get("hmr") });
|
|
387
285
|
await manager.load();
|
|
388
286
|
if (disposed) return;
|
|
389
287
|
manager.startup = { phase: "discovering" };
|
|
@@ -392,6 +290,7 @@ async function apply(ctx, options = {}) {
|
|
|
392
290
|
service: () => ctx.get("pluginManager"),
|
|
393
291
|
profile: () => ctx.get("profileContext"),
|
|
394
292
|
canReload: () => !!ctx.get("hmr"),
|
|
293
|
+
hmr: () => ctx.get("hmr"),
|
|
395
294
|
busy: () => !!(manager.localScan || manager.requests || manager.plugins.flight || manager.checkins.flight || manager.workbuddyLogin.flight || manager.workbuddyLogin.pending || manager.refreshes.size || manager.monitorFlights.size || shims.some((s) => s.active()))
|
|
396
295
|
});
|
|
397
296
|
ctx.inject?.(["webServer"], (webCtx) => {
|
package/lib/host.js
CHANGED
|
@@ -4,13 +4,14 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
MANAGEMENT_PATH,
|
|
6
6
|
Manager,
|
|
7
|
+
PluginReload,
|
|
7
8
|
managementHandler,
|
|
8
9
|
version
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-I4EW5TI7.js";
|
|
10
11
|
import {
|
|
11
12
|
createAccountClient
|
|
12
13
|
} from "./chunk-U2MU2M5C.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-S6ZQ45SS.js";
|
|
14
15
|
import "./chunk-FTM7RHQV.js";
|
|
15
16
|
import "./chunk-S5KMFAQM.js";
|
|
16
17
|
import "./chunk-DNQPZMPF.js";
|
|
@@ -32,7 +33,7 @@ import {
|
|
|
32
33
|
import z from "@deepseek-ai/schemastery";
|
|
33
34
|
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
34
35
|
import { resolveRetryPolicy as resolveRetryPolicy2, resolveImageAttachmentAccess } from "@deepseek-ai/dsh-llm";
|
|
35
|
-
import { join
|
|
36
|
+
import { join, resolve } from "node:path";
|
|
36
37
|
|
|
37
38
|
// upstream/workbuddy/src/adapter.ts
|
|
38
39
|
import { createProvider } from "@earendil-works/pi-ai";
|
|
@@ -246,113 +247,10 @@ var WorkBuddyPiAiAdapter = class extends PiAiAdapter {
|
|
|
246
247
|
}
|
|
247
248
|
};
|
|
248
249
|
|
|
249
|
-
// src/plugin-reload.mjs
|
|
250
|
-
import { readFile } from "node:fs/promises";
|
|
251
|
-
import { watch } from "node:fs";
|
|
252
|
-
import { join } from "node:path";
|
|
253
|
-
var PluginReload = class {
|
|
254
|
-
constructor({ service, profile, canReload, busy = () => false, now = Date.now, runningVersion }) {
|
|
255
|
-
Object.assign(this, { service, profile, canReload, busy, now, runningVersion });
|
|
256
|
-
this.phase = "current";
|
|
257
|
-
this.installedVersion = runningVersion;
|
|
258
|
-
this.retryAt = 0;
|
|
259
|
-
}
|
|
260
|
-
state() {
|
|
261
|
-
return { runningVersion: this.runningVersion, installedVersion: this.installedVersion, phase: this.phase, canReload: !!this.canReload(), message: this.message };
|
|
262
|
-
}
|
|
263
|
-
start() {
|
|
264
|
-
const dir = this.profile()?.dir;
|
|
265
|
-
if (dir) try {
|
|
266
|
-
this.watcher = watch(dir, () => this.schedule());
|
|
267
|
-
this.watcher.unref();
|
|
268
|
-
} catch {
|
|
269
|
-
}
|
|
270
|
-
this.schedule();
|
|
271
|
-
}
|
|
272
|
-
schedule(delay = 500) {
|
|
273
|
-
if (this.closed) return;
|
|
274
|
-
clearTimeout(this.timer);
|
|
275
|
-
this.timer = setTimeout(() => {
|
|
276
|
-
void this.check().catch(() => {
|
|
277
|
-
});
|
|
278
|
-
}, delay);
|
|
279
|
-
this.timer.unref();
|
|
280
|
-
}
|
|
281
|
-
stop() {
|
|
282
|
-
this.closed = true;
|
|
283
|
-
clearTimeout(this.timer);
|
|
284
|
-
this.watcher?.close();
|
|
285
|
-
}
|
|
286
|
-
check() {
|
|
287
|
-
if (this.closed) return Promise.resolve();
|
|
288
|
-
if (this.flight) return this.flight;
|
|
289
|
-
this.flight = this.inspect().finally(() => {
|
|
290
|
-
this.flight = void 0;
|
|
291
|
-
});
|
|
292
|
-
return this.flight;
|
|
293
|
-
}
|
|
294
|
-
async inspect() {
|
|
295
|
-
const dir = this.profile()?.dir;
|
|
296
|
-
if (!dir) return;
|
|
297
|
-
let manifest, installed;
|
|
298
|
-
try {
|
|
299
|
-
manifest = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
|
|
300
|
-
installed = JSON.parse(await readFile(join(dir, "node_modules/dsh-multi-router/package.json"), "utf8"));
|
|
301
|
-
} catch {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (this.closed || !manifest.dsh?.profile?.bundles?.includes("dsh-multi-router")) return;
|
|
305
|
-
if (installed.name !== "dsh-multi-router" || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(installed.version)) return;
|
|
306
|
-
this.installedVersion = installed.version;
|
|
307
|
-
if (installed.version === this.runningVersion) {
|
|
308
|
-
this.phase = "current";
|
|
309
|
-
this.message = void 0;
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if (!this.canReload() || !this.service()?.setBundleEnabled) {
|
|
313
|
-
this.phase = "restart-required";
|
|
314
|
-
this.message = "\u5F53\u524D DSH \u672A\u63D0\u4F9B\u8FD0\u884C\u4E2D\u91CD\u8F7D\uFF0C\u8BF7\u5347\u7EA7 DSH \u6216\u91CD\u542F\u5E94\u7528\u3002";
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
if (this.busy()) {
|
|
318
|
-
this.phase = "waiting";
|
|
319
|
-
this.message = "\u65B0\u7248\u672C\u5DF2\u5B89\u88C5\uFF0C\u7B49\u5F85\u5F53\u524D\u8BF7\u6C42\u548C\u8D26\u53F7\u64CD\u4F5C\u7ED3\u675F\u540E\u81EA\u52A8\u751F\u6548\u3002";
|
|
320
|
-
this.schedule(1e3);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
const root = join(dir, "node_modules/dsh-multi-router");
|
|
324
|
-
try {
|
|
325
|
-
const patch = await readFile(join(root, "cordis.patch.yml"), "utf8");
|
|
326
|
-
if (!patch.includes(`id: llm-multi-router-v2-${installed.version}
|
|
327
|
-
`) || !patch.includes(`name: ./lib/host-v${installed.version}.js`)) throw Error("legacy entry");
|
|
328
|
-
await readFile(join(root, `lib/host-v${installed.version}.js`));
|
|
329
|
-
} catch {
|
|
330
|
-
this.phase = "restart-required";
|
|
331
|
-
this.message = "\u5B89\u88C5\u7248\u672C\u7F3A\u5C11\u7248\u672C\u5316\u5165\u53E3\uFF0C\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248\u540E\u518D\u8BD5\u3002";
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
if (this.now() < this.retryAt) return;
|
|
335
|
-
this.phase = "reloading";
|
|
336
|
-
this.message = "\u6B63\u5728\u91CD\u65B0\u52A0\u8F7D\u63D2\u4EF6\u4E0E\u914D\u7F6E\u9762\u677F\u2026";
|
|
337
|
-
this.retryAt = this.now() + 6e4;
|
|
338
|
-
try {
|
|
339
|
-
const result = await this.service().setBundleEnabled("dsh-multi-router", true);
|
|
340
|
-
if (this.closed) return;
|
|
341
|
-
this.phase = "restart-required";
|
|
342
|
-
this.message = result.application === "applied" ? "DSH \u5C1A\u672A\u5207\u6362\u5230\u65B0\u7248\u672C\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u63D2\u4EF6\u6216\u67E5\u770B\u7EC4\u4EF6\u9519\u8BEF\u3002" : "DSH \u672A\u80FD\u91CD\u8F7D\u63D2\u4EF6\uFF0C\u8BF7\u5347\u7EA7 DSH \u6216\u91CD\u542F\u5E94\u7528\u3002";
|
|
343
|
-
} catch {
|
|
344
|
-
if (!this.closed) {
|
|
345
|
-
this.phase = "failed";
|
|
346
|
-
this.message = "\u63D2\u4EF6\u91CD\u8F7D\u672A\u5B8C\u6210\uFF0C\u53EF\u7A0D\u540E\u91CD\u8BD5\uFF1B\u5DF2\u4FDD\u5B58\u7684\u914D\u7F6E\u4FDD\u6301\u4E0D\u53D8\u3002";
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
|
|
352
250
|
// src/index.mjs
|
|
353
251
|
var name = "dsh-multi-router";
|
|
354
252
|
var inject = ["llm"];
|
|
355
|
-
var defaultConfigFile = () =>
|
|
253
|
+
var defaultConfigFile = () => join(resolveDshHome(), "multi-router", "router.json");
|
|
356
254
|
var Config = z.object({ configFile: z.string().description("Absolute path to multi-account router.json") });
|
|
357
255
|
async function apply(ctx, options = {}) {
|
|
358
256
|
let disposed = false, manager, stopWatch, monitorTimer, startup;
|
|
@@ -383,7 +281,7 @@ async function apply(ctx, options = {}) {
|
|
|
383
281
|
manager = new Manager(file, router, () => {
|
|
384
282
|
for (const wrapper of wrappers) wrapper.invalidate();
|
|
385
283
|
ctx.emit("llm/adapters-updated");
|
|
386
|
-
}, { service: () => ctx.get("pluginManager"), profile: () => ctx.get("profileContext") });
|
|
284
|
+
}, { service: () => ctx.get("pluginManager"), profile: () => ctx.get("profileContext"), hmr: () => ctx.get("hmr") });
|
|
387
285
|
await manager.load();
|
|
388
286
|
if (disposed) return;
|
|
389
287
|
manager.startup = { phase: "discovering" };
|
|
@@ -392,6 +290,7 @@ async function apply(ctx, options = {}) {
|
|
|
392
290
|
service: () => ctx.get("pluginManager"),
|
|
393
291
|
profile: () => ctx.get("profileContext"),
|
|
394
292
|
canReload: () => !!ctx.get("hmr"),
|
|
293
|
+
hmr: () => ctx.get("hmr"),
|
|
395
294
|
busy: () => !!(manager.localScan || manager.requests || manager.plugins.flight || manager.checkins.flight || manager.workbuddyLogin.flight || manager.workbuddyLogin.pending || manager.refreshes.size || manager.monitorFlights.size || shims.some((s) => s.active()))
|
|
396
295
|
});
|
|
397
296
|
ctx.inject?.(["webServer"], (webCtx) => {
|
package/lib/index.js
CHANGED
|
@@ -4,13 +4,14 @@ import {
|
|
|
4
4
|
import {
|
|
5
5
|
MANAGEMENT_PATH,
|
|
6
6
|
Manager,
|
|
7
|
+
PluginReload,
|
|
7
8
|
managementHandler,
|
|
8
9
|
version
|
|
9
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-I4EW5TI7.js";
|
|
10
11
|
import {
|
|
11
12
|
createAccountClient
|
|
12
13
|
} from "./chunk-U2MU2M5C.js";
|
|
13
|
-
import "./chunk-
|
|
14
|
+
import "./chunk-S6ZQ45SS.js";
|
|
14
15
|
import "./chunk-FTM7RHQV.js";
|
|
15
16
|
import "./chunk-S5KMFAQM.js";
|
|
16
17
|
import "./chunk-DNQPZMPF.js";
|
|
@@ -32,7 +33,7 @@ import {
|
|
|
32
33
|
import z from "@deepseek-ai/schemastery";
|
|
33
34
|
import { resolveDshHome } from "@deepseek-ai/dsh-home-paths";
|
|
34
35
|
import { resolveRetryPolicy as resolveRetryPolicy2, resolveImageAttachmentAccess } from "@deepseek-ai/dsh-llm";
|
|
35
|
-
import { join
|
|
36
|
+
import { join, resolve } from "node:path";
|
|
36
37
|
|
|
37
38
|
// upstream/workbuddy/src/adapter.ts
|
|
38
39
|
import { createProvider } from "@earendil-works/pi-ai";
|
|
@@ -246,113 +247,10 @@ var WorkBuddyPiAiAdapter = class extends PiAiAdapter {
|
|
|
246
247
|
}
|
|
247
248
|
};
|
|
248
249
|
|
|
249
|
-
// src/plugin-reload.mjs
|
|
250
|
-
import { readFile } from "node:fs/promises";
|
|
251
|
-
import { watch } from "node:fs";
|
|
252
|
-
import { join } from "node:path";
|
|
253
|
-
var PluginReload = class {
|
|
254
|
-
constructor({ service, profile, canReload, busy = () => false, now = Date.now, runningVersion }) {
|
|
255
|
-
Object.assign(this, { service, profile, canReload, busy, now, runningVersion });
|
|
256
|
-
this.phase = "current";
|
|
257
|
-
this.installedVersion = runningVersion;
|
|
258
|
-
this.retryAt = 0;
|
|
259
|
-
}
|
|
260
|
-
state() {
|
|
261
|
-
return { runningVersion: this.runningVersion, installedVersion: this.installedVersion, phase: this.phase, canReload: !!this.canReload(), message: this.message };
|
|
262
|
-
}
|
|
263
|
-
start() {
|
|
264
|
-
const dir = this.profile()?.dir;
|
|
265
|
-
if (dir) try {
|
|
266
|
-
this.watcher = watch(dir, () => this.schedule());
|
|
267
|
-
this.watcher.unref();
|
|
268
|
-
} catch {
|
|
269
|
-
}
|
|
270
|
-
this.schedule();
|
|
271
|
-
}
|
|
272
|
-
schedule(delay = 500) {
|
|
273
|
-
if (this.closed) return;
|
|
274
|
-
clearTimeout(this.timer);
|
|
275
|
-
this.timer = setTimeout(() => {
|
|
276
|
-
void this.check().catch(() => {
|
|
277
|
-
});
|
|
278
|
-
}, delay);
|
|
279
|
-
this.timer.unref();
|
|
280
|
-
}
|
|
281
|
-
stop() {
|
|
282
|
-
this.closed = true;
|
|
283
|
-
clearTimeout(this.timer);
|
|
284
|
-
this.watcher?.close();
|
|
285
|
-
}
|
|
286
|
-
check() {
|
|
287
|
-
if (this.closed) return Promise.resolve();
|
|
288
|
-
if (this.flight) return this.flight;
|
|
289
|
-
this.flight = this.inspect().finally(() => {
|
|
290
|
-
this.flight = void 0;
|
|
291
|
-
});
|
|
292
|
-
return this.flight;
|
|
293
|
-
}
|
|
294
|
-
async inspect() {
|
|
295
|
-
const dir = this.profile()?.dir;
|
|
296
|
-
if (!dir) return;
|
|
297
|
-
let manifest, installed;
|
|
298
|
-
try {
|
|
299
|
-
manifest = JSON.parse(await readFile(join(dir, "package.json"), "utf8"));
|
|
300
|
-
installed = JSON.parse(await readFile(join(dir, "node_modules/dsh-multi-router/package.json"), "utf8"));
|
|
301
|
-
} catch {
|
|
302
|
-
return;
|
|
303
|
-
}
|
|
304
|
-
if (this.closed || !manifest.dsh?.profile?.bundles?.includes("dsh-multi-router")) return;
|
|
305
|
-
if (installed.name !== "dsh-multi-router" || !/^\d+\.\d+\.\d+(?:-[\w.-]+)?$/.test(installed.version)) return;
|
|
306
|
-
this.installedVersion = installed.version;
|
|
307
|
-
if (installed.version === this.runningVersion) {
|
|
308
|
-
this.phase = "current";
|
|
309
|
-
this.message = void 0;
|
|
310
|
-
return;
|
|
311
|
-
}
|
|
312
|
-
if (!this.canReload() || !this.service()?.setBundleEnabled) {
|
|
313
|
-
this.phase = "restart-required";
|
|
314
|
-
this.message = "\u5F53\u524D DSH \u672A\u63D0\u4F9B\u8FD0\u884C\u4E2D\u91CD\u8F7D\uFF0C\u8BF7\u5347\u7EA7 DSH \u6216\u91CD\u542F\u5E94\u7528\u3002";
|
|
315
|
-
return;
|
|
316
|
-
}
|
|
317
|
-
if (this.busy()) {
|
|
318
|
-
this.phase = "waiting";
|
|
319
|
-
this.message = "\u65B0\u7248\u672C\u5DF2\u5B89\u88C5\uFF0C\u7B49\u5F85\u5F53\u524D\u8BF7\u6C42\u548C\u8D26\u53F7\u64CD\u4F5C\u7ED3\u675F\u540E\u81EA\u52A8\u751F\u6548\u3002";
|
|
320
|
-
this.schedule(1e3);
|
|
321
|
-
return;
|
|
322
|
-
}
|
|
323
|
-
const root = join(dir, "node_modules/dsh-multi-router");
|
|
324
|
-
try {
|
|
325
|
-
const patch = await readFile(join(root, "cordis.patch.yml"), "utf8");
|
|
326
|
-
if (!patch.includes(`id: llm-multi-router-v2-${installed.version}
|
|
327
|
-
`) || !patch.includes(`name: ./lib/host-v${installed.version}.js`)) throw Error("legacy entry");
|
|
328
|
-
await readFile(join(root, `lib/host-v${installed.version}.js`));
|
|
329
|
-
} catch {
|
|
330
|
-
this.phase = "restart-required";
|
|
331
|
-
this.message = "\u5B89\u88C5\u7248\u672C\u7F3A\u5C11\u7248\u672C\u5316\u5165\u53E3\uFF0C\u91CD\u65B0\u5B89\u88C5\u6700\u65B0\u7248\u540E\u518D\u8BD5\u3002";
|
|
332
|
-
return;
|
|
333
|
-
}
|
|
334
|
-
if (this.now() < this.retryAt) return;
|
|
335
|
-
this.phase = "reloading";
|
|
336
|
-
this.message = "\u6B63\u5728\u91CD\u65B0\u52A0\u8F7D\u63D2\u4EF6\u4E0E\u914D\u7F6E\u9762\u677F\u2026";
|
|
337
|
-
this.retryAt = this.now() + 6e4;
|
|
338
|
-
try {
|
|
339
|
-
const result = await this.service().setBundleEnabled("dsh-multi-router", true);
|
|
340
|
-
if (this.closed) return;
|
|
341
|
-
this.phase = "restart-required";
|
|
342
|
-
this.message = result.application === "applied" ? "DSH \u5C1A\u672A\u5207\u6362\u5230\u65B0\u7248\u672C\uFF0C\u8BF7\u91CD\u65B0\u52A0\u8F7D\u63D2\u4EF6\u6216\u67E5\u770B\u7EC4\u4EF6\u9519\u8BEF\u3002" : "DSH \u672A\u80FD\u91CD\u8F7D\u63D2\u4EF6\uFF0C\u8BF7\u5347\u7EA7 DSH \u6216\u91CD\u542F\u5E94\u7528\u3002";
|
|
343
|
-
} catch {
|
|
344
|
-
if (!this.closed) {
|
|
345
|
-
this.phase = "failed";
|
|
346
|
-
this.message = "\u63D2\u4EF6\u91CD\u8F7D\u672A\u5B8C\u6210\uFF0C\u53EF\u7A0D\u540E\u91CD\u8BD5\uFF1B\u5DF2\u4FDD\u5B58\u7684\u914D\u7F6E\u4FDD\u6301\u4E0D\u53D8\u3002";
|
|
347
|
-
}
|
|
348
|
-
}
|
|
349
|
-
}
|
|
350
|
-
};
|
|
351
|
-
|
|
352
250
|
// src/index.mjs
|
|
353
251
|
var name = "dsh-multi-router";
|
|
354
252
|
var inject = ["llm"];
|
|
355
|
-
var defaultConfigFile = () =>
|
|
253
|
+
var defaultConfigFile = () => join(resolveDshHome(), "multi-router", "router.json");
|
|
356
254
|
var Config = z.object({ configFile: z.string().description("Absolute path to multi-account router.json") });
|
|
357
255
|
async function apply(ctx, options = {}) {
|
|
358
256
|
let disposed = false, manager, stopWatch, monitorTimer, startup;
|
|
@@ -383,7 +281,7 @@ async function apply(ctx, options = {}) {
|
|
|
383
281
|
manager = new Manager(file, router, () => {
|
|
384
282
|
for (const wrapper of wrappers) wrapper.invalidate();
|
|
385
283
|
ctx.emit("llm/adapters-updated");
|
|
386
|
-
}, { service: () => ctx.get("pluginManager"), profile: () => ctx.get("profileContext") });
|
|
284
|
+
}, { service: () => ctx.get("pluginManager"), profile: () => ctx.get("profileContext"), hmr: () => ctx.get("hmr") });
|
|
387
285
|
await manager.load();
|
|
388
286
|
if (disposed) return;
|
|
389
287
|
manager.startup = { phase: "discovering" };
|
|
@@ -392,6 +290,7 @@ async function apply(ctx, options = {}) {
|
|
|
392
290
|
service: () => ctx.get("pluginManager"),
|
|
393
291
|
profile: () => ctx.get("profileContext"),
|
|
394
292
|
canReload: () => !!ctx.get("hmr"),
|
|
293
|
+
hmr: () => ctx.get("hmr"),
|
|
395
294
|
busy: () => !!(manager.localScan || manager.requests || manager.plugins.flight || manager.checkins.flight || manager.workbuddyLogin.flight || manager.workbuddyLogin.pending || manager.refreshes.size || manager.monitorFlights.size || shims.some((s) => s.active()))
|
|
396
295
|
});
|
|
397
296
|
ctx.inject?.(["webServer"], (webCtx) => {
|