@lynn123411/dsh-subagent-judge-dispatch 0.6.8 → 0.6.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/README.md +8 -7
- package/lib/client.js +74 -13
- package/lib/client.js.map +2 -2
- package/lib/index.js +67 -9
- package/lib/index.js.map +3 -3
- package/package.json +20 -20
package/lib/index.js
CHANGED
|
@@ -131,6 +131,7 @@ function readJudgeAnswer(payload, rows) {
|
|
|
131
131
|
|
|
132
132
|
// src/server/config.ts
|
|
133
133
|
var TypeRowSchema = z.object({
|
|
134
|
+
stableId: z.string().default(""),
|
|
134
135
|
/** Whether this type takes part in judgements; a row written before the switch existed counts as on. */
|
|
135
136
|
enabled: z.boolean().default(true),
|
|
136
137
|
/** Criterion text the judge reads for this type. */
|
|
@@ -158,6 +159,7 @@ var Config = z.object({
|
|
|
158
159
|
function readPluginConfig(refs) {
|
|
159
160
|
const stored = refs.rows.get();
|
|
160
161
|
const rows = numberTypeRows((Array.isArray(stored) ? stored : []).map((row) => ({
|
|
162
|
+
stableId: typeof row?.stableId === "string" ? row.stableId : "",
|
|
161
163
|
enabled: row?.enabled !== false,
|
|
162
164
|
description: typeof row?.description === "string" ? row.description : "",
|
|
163
165
|
provider: typeof row?.provider === "string" ? row.provider : "",
|
|
@@ -435,13 +437,13 @@ async function judgeTaskType(endpoint, rows, subject, fetchImpl = fetch, sharedB
|
|
|
435
437
|
import * as fs from "node:fs/promises";
|
|
436
438
|
import * as path from "node:path";
|
|
437
439
|
|
|
438
|
-
// node_modules/.pnpm/@deepseek-ai+dsh-atomic-write@0.2.3-alpha.
|
|
440
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-atomic-write@0.2.3-alpha.3_@deepseek-ai+cordis@4.2.0-alpha.2_@deepseek_69d89bc51c1ad90ac0788ea4be89e3f9/node_modules/@deepseek-ai/dsh-atomic-write/lib/index.js
|
|
439
441
|
import { createHash, randomBytes } from "node:crypto";
|
|
440
442
|
import { lstat, mkdir, readFile, rename, rm, writeFile } from "node:fs/promises";
|
|
441
443
|
import { dirname } from "node:path";
|
|
442
444
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
443
445
|
|
|
444
|
-
// node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.3-alpha.
|
|
446
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-error@0.2.3-alpha.3_@deepseek-ai+cordis@4.2.0-alpha.2/node_modules/@deepseek-ai/dsh-error/lib/index.js
|
|
445
447
|
var HarnessError = class extends Error {
|
|
446
448
|
/** Stable machine-routable failure class (e.g. `RATE_LIMIT`); route on this, never by parsing `message`. */
|
|
447
449
|
code;
|
|
@@ -452,7 +454,7 @@ var HarnessError = class extends Error {
|
|
|
452
454
|
}
|
|
453
455
|
};
|
|
454
456
|
|
|
455
|
-
// node_modules/.pnpm/@deepseek-ai+dsh-atomic-write@0.2.3-alpha.
|
|
457
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-atomic-write@0.2.3-alpha.3_@deepseek-ai+cordis@4.2.0-alpha.2_@deepseek_69d89bc51c1ad90ac0788ea4be89e3f9/node_modules/@deepseek-ai/dsh-atomic-write/lib/index.js
|
|
456
458
|
var WINDOWS_TRANSIENT_RENAME_ERRORS = /* @__PURE__ */ new Set([
|
|
457
459
|
"EACCES",
|
|
458
460
|
"EBUSY",
|
|
@@ -600,7 +602,7 @@ async function withFileLock(filename, operation, options) {
|
|
|
600
602
|
}
|
|
601
603
|
}
|
|
602
604
|
|
|
603
|
-
// node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.2.3-alpha.
|
|
605
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.2.3-alpha.3_@deepseek-ai+cordis@4.2.0-alpha.2/node_modules/@deepseek-ai/dsh-home-paths/lib/index.js
|
|
604
606
|
import { homedir } from "node:os";
|
|
605
607
|
import { basename, dirname as dirname2, join, resolve } from "node:path";
|
|
606
608
|
var DSH_HOME_DIR_NAME = ".dsh";
|
|
@@ -662,6 +664,7 @@ function readEntry(value) {
|
|
|
662
664
|
const metrics = readMetrics(item.metrics);
|
|
663
665
|
return {
|
|
664
666
|
typeId: count(item.typeId) || null,
|
|
667
|
+
...typeof item.typeKey === "string" && /^[0-9a-f-]{36}$/i.test(item.typeKey) ? { typeKey: item.typeKey } : {},
|
|
665
668
|
provider: text(item.provider),
|
|
666
669
|
model: text(item.model),
|
|
667
670
|
effort: text(item.effort),
|
|
@@ -704,7 +707,7 @@ var LogStore = class {
|
|
|
704
707
|
}
|
|
705
708
|
async readLatest() {
|
|
706
709
|
const previous = this.entries;
|
|
707
|
-
const disk = await this.readDisk()
|
|
710
|
+
const disk = await this.readDisk();
|
|
708
711
|
return this.snapshot(this.entries === previous ? disk : this.entries);
|
|
709
712
|
}
|
|
710
713
|
snapshot(entries) {
|
|
@@ -717,9 +720,10 @@ var LogStore = class {
|
|
|
717
720
|
async readDisk() {
|
|
718
721
|
try {
|
|
719
722
|
const parsed = JSON.parse(await fs.readFile(this.filePath, "utf8"));
|
|
720
|
-
|
|
723
|
+
if (!Array.isArray(parsed)) throw new Error("Invalid log format");
|
|
724
|
+
return newest(parsed.map(readEntry).filter((entry) => entry !== void 0));
|
|
721
725
|
} catch (error) {
|
|
722
|
-
if (error
|
|
726
|
+
if (error.code === "ENOENT") return [];
|
|
723
727
|
throw error;
|
|
724
728
|
}
|
|
725
729
|
}
|
|
@@ -742,6 +746,7 @@ var LogStore = class {
|
|
|
742
746
|
var LOG_ROUTE_PATH = "/api/dsh-subagent-judge-dispatch/log";
|
|
743
747
|
var PREVIEW_ROUTE_PATH = "/api/dsh-subagent-judge-dispatch/preview";
|
|
744
748
|
var PROBE_ROUTE_PATH = "/api/dsh-subagent-judge-dispatch/probe";
|
|
749
|
+
var SAMPLE_ROUTE_PATH = "/api/dsh-subagent-judge-dispatch/sample";
|
|
745
750
|
function sendJson(status, body) {
|
|
746
751
|
return new Response(JSON.stringify(body), {
|
|
747
752
|
status,
|
|
@@ -793,7 +798,22 @@ function createFetchRoutes(face) {
|
|
|
793
798
|
}
|
|
794
799
|
}
|
|
795
800
|
};
|
|
796
|
-
|
|
801
|
+
const sample = {
|
|
802
|
+
path: SAMPLE_ROUTE_PATH,
|
|
803
|
+
methods: ["POST"],
|
|
804
|
+
requestBody: "buffered",
|
|
805
|
+
fetch: async (request) => {
|
|
806
|
+
try {
|
|
807
|
+
const body = await request.json();
|
|
808
|
+
const task = typeof body === "object" && body !== null && "task" in body ? body.task : void 0;
|
|
809
|
+
if (typeof task !== "string" || task.trim() === "" || task.length > 1e4) return sendJson(400, { ok: false });
|
|
810
|
+
return sendJson(200, await face.sample(task));
|
|
811
|
+
} catch {
|
|
812
|
+
return sendJson(500, { ok: false });
|
|
813
|
+
}
|
|
814
|
+
}
|
|
815
|
+
};
|
|
816
|
+
return [log, preview, probe, sample];
|
|
797
817
|
}
|
|
798
818
|
function describe(err) {
|
|
799
819
|
return err instanceof Error ? err.message : String(err);
|
|
@@ -899,7 +919,44 @@ function apply(ctx, config) {
|
|
|
899
919
|
const routes = createFetchRoutes({
|
|
900
920
|
config: resolvedConfig,
|
|
901
921
|
log: () => log.readLatest(),
|
|
902
|
-
apiKey: () => apiKey
|
|
922
|
+
apiKey: () => apiKey,
|
|
923
|
+
sample: async (task) => {
|
|
924
|
+
const cfg = resolvedConfig();
|
|
925
|
+
const budget = new JudgeBudget(lifetime.signal);
|
|
926
|
+
try {
|
|
927
|
+
const outcome = await judgeTaskType(
|
|
928
|
+
{ url: cfg.endpointUrl, model: cfg.judgeModel, apiKey },
|
|
929
|
+
selectableRows(cfg.rows),
|
|
930
|
+
composeJudgeSubject("", task),
|
|
931
|
+
fetch,
|
|
932
|
+
budget
|
|
933
|
+
);
|
|
934
|
+
const decision = decideRewrite(outcome);
|
|
935
|
+
if (decision.kind !== "rewrite") return { ok: false, reason: outcomeReason(outcome, decision) };
|
|
936
|
+
const route = decision.rewrite;
|
|
937
|
+
const llm = ctx.get("llm");
|
|
938
|
+
const allowed = () => ctx.get("subagentModelSelection")?.allowedRoutes()?.some(
|
|
939
|
+
(pair) => pair.provider === route.provider && pair.model === route.model
|
|
940
|
+
) === true;
|
|
941
|
+
try {
|
|
942
|
+
if (llm === void 0 || !allowed()) throw new Error("Unavailable child route");
|
|
943
|
+
await budget.run((signal) => llm.resolveCallConfig(route, signal));
|
|
944
|
+
if (!allowed()) throw new Error("Child route no longer allowed");
|
|
945
|
+
budget.check();
|
|
946
|
+
return { ok: true, typeId: outcome.kind === "matched" ? outcome.row.id : null, route, valid: true };
|
|
947
|
+
} catch {
|
|
948
|
+
return {
|
|
949
|
+
ok: false,
|
|
950
|
+
typeId: outcome.kind === "matched" ? outcome.row.id : null,
|
|
951
|
+
route,
|
|
952
|
+
valid: false,
|
|
953
|
+
reason: budget.expired() ? "timeout" : "unavailable-route"
|
|
954
|
+
};
|
|
955
|
+
}
|
|
956
|
+
} finally {
|
|
957
|
+
budget.dispose();
|
|
958
|
+
}
|
|
959
|
+
}
|
|
903
960
|
});
|
|
904
961
|
const disposers = routes.map(
|
|
905
962
|
(route) => connectionCtx.connection.fetch.register(route)
|
|
@@ -922,6 +979,7 @@ function buildEntry(resolved, decision, outcome, latencyMs, routeFailure) {
|
|
|
922
979
|
const reason = routeFailure ?? outcomeReason(outcome, decision);
|
|
923
980
|
return {
|
|
924
981
|
typeId: matched && outcome.kind === "matched" ? outcome.row.id : null,
|
|
982
|
+
...matched && outcome.kind === "matched" && outcome.row.stableId ? { typeKey: outcome.row.stableId } : {},
|
|
925
983
|
provider: matched ? decision.rewrite.provider : resolved.provider,
|
|
926
984
|
model: matched ? decision.rewrite.model : resolved.model,
|
|
927
985
|
effort: matched ? decision.rewrite.reasoningEffort : typeof resolved.reasoningEffort === "string" ? resolved.reasoningEffort : "",
|