@lynn123411/dsh-subagent-judge-dispatch 0.5.0 → 0.6.0
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/DETAILS.md +11 -8
- package/README.md +5 -4
- package/lib/client.js +212 -116
- package/lib/client.js.map +3 -3
- package/lib/index.js +82 -37
- package/lib/index.js.map +4 -4
- package/package.json +15 -15
package/lib/index.js
CHANGED
|
@@ -1,6 +1,17 @@
|
|
|
1
1
|
// src/server/config.ts
|
|
2
2
|
import z from "@deepseek-ai/schemastery";
|
|
3
3
|
|
|
4
|
+
// src/server/endpoint.ts
|
|
5
|
+
var ENDPOINT_PATHS = ["/v1/systemone", "/systemone"];
|
|
6
|
+
function resolveEndpointUrl(input) {
|
|
7
|
+
const trimmed = typeof input === "string" ? input.trim() : "";
|
|
8
|
+
if (trimmed === "") return "";
|
|
9
|
+
const address = trimmed.replace(/\/+$/, "");
|
|
10
|
+
if (ENDPOINT_PATHS.some((path2) => address.endsWith(path2))) return address;
|
|
11
|
+
if (address.endsWith("/v1")) return `${address}/systemone`;
|
|
12
|
+
return `${address}/v1/systemone`;
|
|
13
|
+
}
|
|
14
|
+
|
|
4
15
|
// src/server/judge-prompt.ts
|
|
5
16
|
var QUESTION_KEY = "task_type";
|
|
6
17
|
var QUESTION_INSTRUCTIONS = "Which single task type below does the delegated job best match? Weigh what the job actually requires, not how it is phrased. Answer with the number of exactly one listed type.";
|
|
@@ -97,8 +108,6 @@ function readJudgeAnswer(payload, rows) {
|
|
|
97
108
|
|
|
98
109
|
// src/server/config.ts
|
|
99
110
|
var SETTINGS_NAMESPACE = "dsh-subagent-judge-dispatch";
|
|
100
|
-
var DEFAULT_ENDPOINT_URL = "http://127.0.0.1:3425/v1/systemone";
|
|
101
|
-
var DEFAULT_JUDGE_MODEL = "future-jev/jev-latest";
|
|
102
111
|
var TypeRowSchema = z.object({
|
|
103
112
|
/** Criterion text the judge reads for this type. */
|
|
104
113
|
description: z.string().default(""),
|
|
@@ -114,10 +123,10 @@ var Config = z.object({
|
|
|
114
123
|
enabled: z.boolean().default(true).volatile(),
|
|
115
124
|
/** Whether judgements are written to the plugin's own log. */
|
|
116
125
|
logEnabled: z.boolean().default(true).volatile(),
|
|
117
|
-
/**
|
|
118
|
-
endpointUrl: z.string().default(
|
|
126
|
+
/** Judge service address, as the reader typed it; the path is appended when a call is made. */
|
|
127
|
+
endpointUrl: z.string().default("").volatile(),
|
|
119
128
|
/** Judge model id. */
|
|
120
|
-
judgeModel: z.string().default(
|
|
129
|
+
judgeModel: z.string().default("").volatile(),
|
|
121
130
|
/** The task-type list, in page order. */
|
|
122
131
|
rows: z.array(TypeRowSchema).default([]).volatile()
|
|
123
132
|
});
|
|
@@ -136,8 +145,8 @@ function readPluginConfig(refs) {
|
|
|
136
145
|
return {
|
|
137
146
|
enabled: refs.enabled.get() !== false,
|
|
138
147
|
logEnabled: refs.logEnabled.get() !== false,
|
|
139
|
-
endpointUrl:
|
|
140
|
-
judgeModel: typeof refs.judgeModel.get() === "string" ? refs.judgeModel.get() :
|
|
148
|
+
endpointUrl: resolveEndpointUrl(refs.endpointUrl.get()),
|
|
149
|
+
judgeModel: typeof refs.judgeModel.get() === "string" ? refs.judgeModel.get() : "",
|
|
141
150
|
rows
|
|
142
151
|
};
|
|
143
152
|
}
|
|
@@ -169,15 +178,6 @@ function outcomeReason(outcome, decision) {
|
|
|
169
178
|
if (outcome.kind !== "matched") return outcome.reason;
|
|
170
179
|
return "incomplete";
|
|
171
180
|
}
|
|
172
|
-
function applyDecision(config, decision) {
|
|
173
|
-
if (decision.kind === "none") return config;
|
|
174
|
-
return {
|
|
175
|
-
...config,
|
|
176
|
-
provider: decision.rewrite.provider,
|
|
177
|
-
model: decision.rewrite.model,
|
|
178
|
-
reasoningEffort: decision.rewrite.reasoningEffort
|
|
179
|
-
};
|
|
180
|
-
}
|
|
181
181
|
|
|
182
182
|
// src/server/identity.ts
|
|
183
183
|
function ownEventsOf(session) {
|
|
@@ -223,6 +223,44 @@ function readTaskText(agent) {
|
|
|
223
223
|
}
|
|
224
224
|
return "";
|
|
225
225
|
}
|
|
226
|
+
function readDelegatedTask(agent, parentSessionOf) {
|
|
227
|
+
const own = readTaskText(agent);
|
|
228
|
+
if (own !== "") return own;
|
|
229
|
+
const parentId = agent.session.header.parentSession;
|
|
230
|
+
if (typeof parentId !== "string" || parentId === "") return "";
|
|
231
|
+
const parent = parentSessionOf(parentId);
|
|
232
|
+
if (parent === void 0 || typeof parent.snapshotEvents !== "function") return "";
|
|
233
|
+
const label = readChildLabel(agent);
|
|
234
|
+
const events = parent.snapshotEvents();
|
|
235
|
+
let fallback = "";
|
|
236
|
+
for (let index = events.length - 1; index >= 0; index -= 1) {
|
|
237
|
+
const event = events[index];
|
|
238
|
+
if (event.type !== "tool/call") continue;
|
|
239
|
+
const call = delegatedCallOf(event.data);
|
|
240
|
+
if (call === void 0) continue;
|
|
241
|
+
if (label !== "" && call.description === label) return call.prompt;
|
|
242
|
+
if (fallback === "") fallback = call.prompt;
|
|
243
|
+
}
|
|
244
|
+
return fallback;
|
|
245
|
+
}
|
|
246
|
+
function delegatedCallOf(data) {
|
|
247
|
+
if (typeof data !== "object" || data === null) return void 0;
|
|
248
|
+
const raw = data.arguments;
|
|
249
|
+
if (typeof raw !== "string") return void 0;
|
|
250
|
+
let parsed;
|
|
251
|
+
try {
|
|
252
|
+
parsed = JSON.parse(raw);
|
|
253
|
+
} catch {
|
|
254
|
+
return void 0;
|
|
255
|
+
}
|
|
256
|
+
if (typeof parsed !== "object" || parsed === null) return void 0;
|
|
257
|
+
const record = parsed;
|
|
258
|
+
if (typeof record.prompt !== "string" || record.prompt.trim() === "") return void 0;
|
|
259
|
+
return {
|
|
260
|
+
prompt: record.prompt,
|
|
261
|
+
...typeof record.description === "string" ? { description: record.description } : {}
|
|
262
|
+
};
|
|
263
|
+
}
|
|
226
264
|
function delegationMessagesOf(event) {
|
|
227
265
|
if (event.type === "user/message") {
|
|
228
266
|
return sourceOf(event.data)?.kind === "user" ? [event.data] : [];
|
|
@@ -359,7 +397,7 @@ async function judgeTaskType(endpoint, rows, subject, fetchImpl = fetch) {
|
|
|
359
397
|
import * as fs from "node:fs/promises";
|
|
360
398
|
import * as path from "node:path";
|
|
361
399
|
|
|
362
|
-
// node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.2.
|
|
400
|
+
// node_modules/.pnpm/@deepseek-ai+dsh-home-paths@0.2.2-rc.1_@deepseek-ai+cordis@4.1.0/node_modules/@deepseek-ai/dsh-home-paths/lib/index.js
|
|
363
401
|
import { homedir } from "node:os";
|
|
364
402
|
import { basename, dirname, join, resolve } from "node:path";
|
|
365
403
|
var DSH_HOME_DIR_NAME = ".dsh";
|
|
@@ -591,28 +629,37 @@ function apply(ctx, config) {
|
|
|
591
629
|
"dsh-subagent-judge-dispatch: settings page policy"
|
|
592
630
|
);
|
|
593
631
|
});
|
|
594
|
-
ctx.on("agent/
|
|
595
|
-
const resolved = await next();
|
|
632
|
+
ctx.on("agent/created", async (payload) => {
|
|
596
633
|
const agent = payload?.agent;
|
|
597
|
-
if (agent === void 0) return
|
|
634
|
+
if (agent === void 0) return;
|
|
598
635
|
const cfg = resolvedConfig();
|
|
599
|
-
if (!isSubagent(agent) || !cfg.enabled) return
|
|
600
|
-
if (judged.has(agent.id)) return
|
|
601
|
-
if (!isJudgeUsable(cfg)) return
|
|
636
|
+
if (!isSubagent(agent) || !cfg.enabled) return;
|
|
637
|
+
if (judged.has(agent.id)) return;
|
|
638
|
+
if (!isJudgeUsable(cfg)) return;
|
|
602
639
|
judged.add(agent.id);
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
{
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
640
|
+
try {
|
|
641
|
+
const label = readChildLabel(agent);
|
|
642
|
+
const taskText = readDelegatedTask(agent, (id) => ctx.sessions.get(id));
|
|
643
|
+
const inherited = agent.model.current() ?? { provider: "", model: "" };
|
|
644
|
+
const outcome = await judgeTaskType(
|
|
645
|
+
{ url: cfg.endpointUrl, model: cfg.judgeModel, apiKey },
|
|
646
|
+
selectableRows(cfg.rows),
|
|
647
|
+
composeJudgeSubject(label, taskText)
|
|
648
|
+
);
|
|
649
|
+
const decision = decideRewrite(outcome);
|
|
650
|
+
if (decision.kind === "rewrite") {
|
|
651
|
+
agent.model.select({
|
|
652
|
+
provider: decision.rewrite.provider,
|
|
653
|
+
model: decision.rewrite.model,
|
|
654
|
+
reasoningEffort: decision.rewrite.reasoningEffort
|
|
655
|
+
});
|
|
656
|
+
}
|
|
657
|
+
if (cfg.logEnabled) {
|
|
658
|
+
await logReady;
|
|
659
|
+
log.append(buildEntry(ctx, agent, inherited, decision, outcome, label, taskText));
|
|
660
|
+
}
|
|
661
|
+
} catch {
|
|
614
662
|
}
|
|
615
|
-
return applyDecision(resolved, decision);
|
|
616
663
|
});
|
|
617
664
|
ctx.inject(["connection"], (connectionCtx) => {
|
|
618
665
|
const routes = createFetchRoutes({
|
|
@@ -674,8 +721,6 @@ function truncate(text, max = 60) {
|
|
|
674
721
|
}
|
|
675
722
|
export {
|
|
676
723
|
Config,
|
|
677
|
-
DEFAULT_ENDPOINT_URL,
|
|
678
|
-
DEFAULT_JUDGE_MODEL,
|
|
679
724
|
JUDGE_API_KEY_REF,
|
|
680
725
|
apply,
|
|
681
726
|
inject,
|