@lynn123411/dsh-subagent-judge-dispatch 0.6.10 → 0.6.11

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/lib/index.js CHANGED
@@ -14,11 +14,11 @@ import z from "@deepseek-ai/schemastery";
14
14
  var ENDPOINT_PATHS = ["/v1/systemone", "/systemone"];
15
15
  function resolveEndpointUrl(input) {
16
16
  const trimmed = typeof input === "string" ? input.trim() : "";
17
- if (trimmed === "") return "";
18
- const address = trimmed.replace(/\/+$/, "");
19
- if (ENDPOINT_PATHS.some((path2) => address.endsWith(path2))) return address;
20
- if (address.endsWith("/v1")) return `${address}/systemone`;
21
- return `${address}/v1/systemone`;
17
+ const url = URL.parse(trimmed);
18
+ if (url === null) return trimmed;
19
+ const pathname = url.pathname.replace(/\/+$/, "");
20
+ url.pathname = ENDPOINT_PATHS.some((path2) => pathname.endsWith(path2)) ? pathname : pathname + (pathname.endsWith("/v1") ? "/systemone" : ENDPOINT_PATHS[0]);
21
+ return url.href;
22
22
  }
23
23
 
24
24
  // src/server/judge-prompt.ts
@@ -296,8 +296,10 @@ function outstandingDelegation(events, label, resumedChildId) {
296
296
  }
297
297
  return task;
298
298
  }
299
- function hasRecordedRoute(session, events = ownEventsOf(session)) {
300
- return events.some((event) => event.type === "model/selection" || event.type === "request/header");
299
+ function hasRecordedRoute(session, resumed, events = ownEventsOf(session)) {
300
+ const descriptor = events.findIndex((event) => event.type === "subagent/descriptor");
301
+ const initialSelection = !resumed && descriptor !== -1 ? descriptor + 1 : -1;
302
+ return events.some((event, index) => event.type === "request/header" || event.type === "model/selection" && index !== initialSelection);
301
303
  }
302
304
  function readDelegatedTask(agent, parentSessionOf, resumed) {
303
305
  const parentId = agent.session.header.parentSession;
@@ -305,7 +307,7 @@ function readDelegatedTask(agent, parentSessionOf, resumed) {
305
307
  const parent = parentSessionOf(parentId);
306
308
  if (parent?.header.id !== parentId) return void 0;
307
309
  const own = ownEventsOf(agent.session);
308
- if (hasRecordedRoute(agent.session, own)) return void 0;
310
+ if (hasRecordedRoute(agent.session, resumed, own)) return void 0;
309
311
  const descriptor = [...own].reverse().find((event) => event.type === "subagent/descriptor");
310
312
  const label = asRecord(descriptor?.data)?.label;
311
313
  if (typeof label !== "string" || label.trim() === "") return void 0;
@@ -664,6 +666,8 @@ function readEntry(value) {
664
666
  const metrics = readMetrics(item.metrics);
665
667
  return {
666
668
  typeId: count(item.typeId) || null,
669
+ ...typeof item.typeDescription === "string" ? { typeDescription: item.typeDescription } : {},
670
+ ...typeof item.taskText === "string" ? { taskText: item.taskText } : {},
667
671
  ...typeof item.typeKey === "string" && /^[0-9a-f-]{36}$/i.test(item.typeKey) ? { typeKey: item.typeKey } : {},
668
672
  provider: text(item.provider),
669
673
  model: text(item.model),
@@ -865,6 +869,7 @@ function apply(ctx, config) {
865
869
  const cancellation = signal === void 0 ? lifetime.signal : AbortSignal.any([signal, lifetime.signal]);
866
870
  if (agent === void 0 || !isSubagent(agent) || judged.has(agent.id) || cancellation.aborted) return;
867
871
  if (source !== "startup" && source !== "resume") return;
872
+ const resumed = source === "resume";
868
873
  const budget = new JudgeBudget(cancellation);
869
874
  try {
870
875
  const lookup = (id) => ctx.sessions.get(id);
@@ -875,7 +880,7 @@ function apply(ctx, config) {
875
880
  })) : void 0;
876
881
  const cfg = resolvedConfig();
877
882
  if (cancellation.aborted || !isJudgeUsable(cfg, rootId) || judged.has(agent.id)) return;
878
- const task = readDelegatedTask(agent, lookup, source === "resume");
883
+ const task = readDelegatedTask(agent, lookup, resumed);
879
884
  if (task === void 0 || task.explicitRoute) return;
880
885
  judged.add(agent.id);
881
886
  const { label, text: taskText } = task;
@@ -899,7 +904,7 @@ function apply(ctx, config) {
899
904
  if (llm === void 0 || !allowed()) throw new Error("Unavailable child route");
900
905
  await budget.run((preflightSignal) => llm.resolveCallConfig(route, preflightSignal));
901
906
  if (!allowed()) throw new Error("Child route no longer allowed");
902
- if (cancellation.aborted || !isJudgeUsable(resolvedConfig(), rootId) || hasRecordedRoute(agent.session)) return;
907
+ if (cancellation.aborted || !isJudgeUsable(resolvedConfig(), rootId) || hasRecordedRoute(agent.session, resumed)) return;
903
908
  budget.check();
904
909
  agent.model.select(route);
905
910
  } catch {
@@ -908,7 +913,7 @@ function apply(ctx, config) {
908
913
  }
909
914
  }
910
915
  if (resolvedConfig().logEnabled && !cancellation.aborted) {
911
- log.append(buildEntry(inherited, decision, outcome, budget.elapsed(), routeFailure));
916
+ log.append(buildEntry(inherited, decision, outcome, taskText, budget.elapsed(), routeFailure));
912
917
  }
913
918
  } catch {
914
919
  } finally {
@@ -974,11 +979,13 @@ function apply(ctx, config) {
974
979
  "dsh-subagent-judge-dispatch: judgement log flush"
975
980
  );
976
981
  }
977
- function buildEntry(resolved, decision, outcome, latencyMs, routeFailure) {
982
+ function buildEntry(resolved, decision, outcome, taskText, latencyMs, routeFailure) {
978
983
  const matched = decision.kind === "rewrite";
979
984
  const reason = routeFailure ?? outcomeReason(outcome, decision);
980
985
  return {
981
986
  typeId: matched && outcome.kind === "matched" ? outcome.row.id : null,
987
+ ...outcome.kind === "matched" ? { typeDescription: outcome.row.description } : {},
988
+ taskText,
982
989
  ...matched && outcome.kind === "matched" && outcome.row.stableId ? { typeKey: outcome.row.stableId } : {},
983
990
  provider: matched ? decision.rewrite.provider : resolved.provider,
984
991
  model: matched ? decision.rewrite.model : resolved.model,