@lynn123411/dsh-subagent-judge-dispatch 0.6.5 → 0.6.7
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 +4 -3
- package/lib/client.js +279 -176
- package/lib/client.js.map +4 -4
- package/lib/index.js +37 -23
- package/lib/index.js.map +3 -3
- package/package.json +4 -1
package/lib/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
// src/enablement.ts
|
|
2
|
+
var DEFAULT_ENABLED = true;
|
|
3
|
+
var SETTINGS_NAMESPACE = "dsh-subagent-judge-dispatch";
|
|
4
|
+
function enabledFor(overrides, fallback, sessionId) {
|
|
5
|
+
if (sessionId === void 0 || overrides === null || typeof overrides !== "object" || !Object.hasOwn(overrides, sessionId)) return fallback;
|
|
6
|
+
const choice = overrides[sessionId];
|
|
7
|
+
return typeof choice === "boolean" ? choice : fallback;
|
|
8
|
+
}
|
|
9
|
+
|
|
1
10
|
// src/server/config.ts
|
|
2
11
|
import z from "@deepseek-ai/schemastery";
|
|
3
12
|
|
|
@@ -121,7 +130,6 @@ function readJudgeAnswer(payload, rows) {
|
|
|
121
130
|
}
|
|
122
131
|
|
|
123
132
|
// src/server/config.ts
|
|
124
|
-
var SETTINGS_NAMESPACE = "dsh-subagent-judge-dispatch";
|
|
125
133
|
var TypeRowSchema = z.object({
|
|
126
134
|
/** Whether this type takes part in judgements; a row written before the switch existed counts as on. */
|
|
127
135
|
enabled: z.boolean().default(true),
|
|
@@ -135,8 +143,9 @@ var TypeRowSchema = z.object({
|
|
|
135
143
|
effort: z.string().default("")
|
|
136
144
|
});
|
|
137
145
|
var Config = z.object({
|
|
138
|
-
/**
|
|
139
|
-
enabled: z.boolean().default(
|
|
146
|
+
/** Default for conversations without their own choice. */
|
|
147
|
+
enabled: z.boolean().default(DEFAULT_ENABLED).volatile(),
|
|
148
|
+
sessionOverrides: z.dict(z.boolean()).default({}).volatile(),
|
|
140
149
|
/** Whether judgements are written to the plugin's own log. */
|
|
141
150
|
logEnabled: z.boolean().default(true).volatile(),
|
|
142
151
|
/** Judge service address, as the reader typed it; the path is appended when a call is made. */
|
|
@@ -156,15 +165,16 @@ function readPluginConfig(refs) {
|
|
|
156
165
|
effort: typeof row?.effort === "string" ? row.effort : ""
|
|
157
166
|
})));
|
|
158
167
|
return {
|
|
159
|
-
enabled: refs.enabled.get()
|
|
168
|
+
enabled: refs.enabled.get() ?? DEFAULT_ENABLED,
|
|
169
|
+
sessionOverrides: refs.sessionOverrides.get(),
|
|
160
170
|
logEnabled: refs.logEnabled.get() !== false,
|
|
161
171
|
endpointUrl: resolveEndpointUrl(refs.endpointUrl.get()),
|
|
162
172
|
judgeModel: typeof refs.judgeModel.get() === "string" ? refs.judgeModel.get() : "",
|
|
163
173
|
rows
|
|
164
174
|
};
|
|
165
175
|
}
|
|
166
|
-
function isJudgeUsable(config) {
|
|
167
|
-
if (!config.enabled) return false;
|
|
176
|
+
function isJudgeUsable(config, rootSessionId) {
|
|
177
|
+
if (!enabledFor(config.sessionOverrides, config.enabled, rootSessionId)) return false;
|
|
168
178
|
if (config.endpointUrl.trim() === "" || config.judgeModel.trim() === "") return false;
|
|
169
179
|
return selectableRows(config.rows).length > 0;
|
|
170
180
|
}
|
|
@@ -316,12 +326,13 @@ function textBlocksOf(data) {
|
|
|
316
326
|
}
|
|
317
327
|
return texts;
|
|
318
328
|
}
|
|
319
|
-
function resolveRootSessionId(startId, lookup) {
|
|
329
|
+
async function resolveRootSessionId(startId, lookup) {
|
|
320
330
|
const seen = /* @__PURE__ */ new Set([startId]);
|
|
321
331
|
let current = startId;
|
|
322
332
|
for (let hop = 0; hop < 32; hop += 1) {
|
|
323
|
-
const
|
|
324
|
-
|
|
333
|
+
const header = await lookup(current);
|
|
334
|
+
if (header === void 0 || header.origin !== "subagent" && (header.delegationDepth ?? 0) < 1) return current;
|
|
335
|
+
const parent = header.parentSession;
|
|
325
336
|
if (typeof parent !== "string" || parent === "" || seen.has(parent)) return current;
|
|
326
337
|
seen.add(parent);
|
|
327
338
|
current = parent;
|
|
@@ -657,15 +668,19 @@ function apply(ctx, config) {
|
|
|
657
668
|
});
|
|
658
669
|
ctx.on("agent/created", async (payload) => {
|
|
659
670
|
const agent = payload?.agent;
|
|
660
|
-
if (agent === void 0) return;
|
|
661
|
-
const cfg = resolvedConfig();
|
|
662
|
-
if (!isSubagent(agent) || !cfg.enabled) return;
|
|
663
|
-
if (judged.has(agent.id)) return;
|
|
664
|
-
if (!isJudgeUsable(cfg)) return;
|
|
665
|
-
judged.add(agent.id);
|
|
671
|
+
if (agent === void 0 || !isSubagent(agent) || judged.has(agent.id)) return;
|
|
666
672
|
try {
|
|
673
|
+
const lookup = (id) => ctx.sessions.get(id);
|
|
674
|
+
const parentId = agent.session.header.parentSession;
|
|
675
|
+
const rootId = parentId ? await resolveRootSessionId(
|
|
676
|
+
parentId,
|
|
677
|
+
async (id) => lookup(id)?.header ?? (await ctx.get("sessionPersistence")?.stat(id))?.header
|
|
678
|
+
) : void 0;
|
|
679
|
+
const cfg = resolvedConfig();
|
|
680
|
+
if (!isJudgeUsable(cfg, rootId) || judged.has(agent.id)) return;
|
|
681
|
+
judged.add(agent.id);
|
|
667
682
|
const label = readChildLabel(agent);
|
|
668
|
-
const taskText = readDelegatedTask(agent,
|
|
683
|
+
const taskText = readDelegatedTask(agent, lookup);
|
|
669
684
|
const inherited = agent.model.current() ?? { provider: "", model: "" };
|
|
670
685
|
const outcome = await judgeTaskType(
|
|
671
686
|
{ url: cfg.endpointUrl, model: cfg.judgeModel, apiKey },
|
|
@@ -682,7 +697,7 @@ function apply(ctx, config) {
|
|
|
682
697
|
}
|
|
683
698
|
if (cfg.logEnabled) {
|
|
684
699
|
await logReady;
|
|
685
|
-
log.append(buildEntry(ctx,
|
|
700
|
+
log.append(buildEntry(ctx, rootId, inherited, decision, outcome, label, taskText));
|
|
686
701
|
}
|
|
687
702
|
} catch {
|
|
688
703
|
}
|
|
@@ -713,7 +728,7 @@ function apply(ctx, config) {
|
|
|
713
728
|
"dsh-subagent-judge-dispatch: judgement log flush"
|
|
714
729
|
);
|
|
715
730
|
}
|
|
716
|
-
function buildEntry(ctx,
|
|
731
|
+
function buildEntry(ctx, rootId, resolved, decision, outcome, label, taskText) {
|
|
717
732
|
const matched = decision.kind === "rewrite";
|
|
718
733
|
const reason = outcomeReason(outcome, decision);
|
|
719
734
|
return {
|
|
@@ -724,21 +739,20 @@ function buildEntry(ctx, agent, resolved, decision, outcome, label, taskText) {
|
|
|
724
739
|
...reason === void 0 ? {} : { reason },
|
|
725
740
|
at: Date.now(),
|
|
726
741
|
latencyMs: outcome.latencyMs,
|
|
727
|
-
parentTitle: readParentTitle(ctx,
|
|
742
|
+
parentTitle: readParentTitle(ctx, rootId),
|
|
728
743
|
childLabel: truncate(label !== "" ? label : taskText),
|
|
729
744
|
prompt: outcome.prompt
|
|
730
745
|
};
|
|
731
746
|
}
|
|
732
|
-
function readParentTitle(ctx,
|
|
733
|
-
if (
|
|
747
|
+
function readParentTitle(ctx, rootId) {
|
|
748
|
+
if (rootId === void 0) return "";
|
|
734
749
|
try {
|
|
735
|
-
const rootId = resolveRootSessionId(parentId, (id) => ctx.sessions.get(id));
|
|
736
750
|
const session = ctx.sessions.get(rootId);
|
|
737
751
|
if (session === void 0) return rootId;
|
|
738
752
|
const title = ctx.sessionTitle.get(session)?.title;
|
|
739
753
|
return typeof title === "string" && title.trim() !== "" ? title.trim() : rootId;
|
|
740
754
|
} catch {
|
|
741
|
-
return
|
|
755
|
+
return rootId;
|
|
742
756
|
}
|
|
743
757
|
}
|
|
744
758
|
function truncate(text, max = 60) {
|