@wrongstack/core 0.3.3 → 0.3.4

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.
@@ -130,6 +130,7 @@ interface MCPServerConfig {
130
130
  allowedTools?: string[];
131
131
  permission?: Permission;
132
132
  startupTimeoutMs?: number;
133
+ requestTimeoutMs?: number;
133
134
  }
134
135
  interface LogConfig {
135
136
  level: 'error' | 'warn' | 'info' | 'debug' | 'trace';
@@ -5,12 +5,12 @@ import { I as InMemoryAgentBridge } from '../agent-bridge-C3DUGjSb.js';
5
5
  export { a as InMemoryBridgeTransport, c as createMessage } from '../agent-bridge-C3DUGjSb.js';
6
6
  import { E as EventBus } from '../events-BHIQs4o1.js';
7
7
  import { EventEmitter } from 'node:events';
8
- import { r as Agent, u as AgentInput } from '../index-hWNybrNZ.js';
8
+ import { r as Agent, u as AgentInput } from '../index-DedY4Euf.js';
9
9
  import '../logger-BMQgxvdy.js';
10
10
  import '../system-prompt-Dk1qm8ey.js';
11
11
  import '../observability-BhnVLBLS.js';
12
12
  import '../secret-scrubber-CgG2tV2B.js';
13
- import '../config-D2qvAxVd.js';
13
+ import '../config-DgE3JslD.js';
14
14
  import '../models-registry-Y2xbog0E.js';
15
15
 
16
16
  /**
@@ -590,7 +590,9 @@ declare class DefaultMultiAgentCoordinator extends EventEmitter implements Multi
590
590
  completeTask(result: TaskResult): void;
591
591
  private tryDispatchNext;
592
592
  private canDispatch;
593
+ private takeNextDispatchableTask;
593
594
  private findIdleSubagent;
595
+ private isIdleSubagent;
594
596
  /**
595
597
  * Returns true iff at least one spawned subagent could still
596
598
  * process a task. A "live" subagent is one that is not stopped
@@ -893,8 +893,8 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
893
893
  // --- internal dispatching ---------------------------------------------
894
894
  tryDispatchNext() {
895
895
  while (this.canDispatch()) {
896
- const subagentId = this.findIdleSubagent();
897
- if (!subagentId) {
896
+ const dispatchable = this.takeNextDispatchableTask();
897
+ if (!dispatchable) {
898
898
  if (this.pendingTasks.length > 0 && !this.hasLiveSubagent()) {
899
899
  this.drainPendingAsAborted(
900
900
  "No live subagent available \u2014 all stopped or mid-termination"
@@ -902,8 +902,7 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
902
902
  }
903
903
  return;
904
904
  }
905
- const task = this.pendingTasks.shift();
906
- if (!task) return;
905
+ const { subagentId, task } = dispatchable;
907
906
  this.runDispatched(subagentId, task).catch((err) => {
908
907
  this.recordCompletion({
909
908
  subagentId,
@@ -921,12 +920,26 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
921
920
  const max = this.config.maxConcurrent ?? 4;
922
921
  return this.inFlight < max && this.pendingTasks.length > 0;
923
922
  }
923
+ takeNextDispatchableTask() {
924
+ for (let i = 0; i < this.pendingTasks.length; i++) {
925
+ const task = this.pendingTasks[i];
926
+ const subagentId = task.subagentId ? this.isIdleSubagent(task.subagentId) ? task.subagentId : null : this.findIdleSubagent();
927
+ if (!subagentId) continue;
928
+ this.pendingTasks.splice(i, 1);
929
+ return { subagentId, task };
930
+ }
931
+ return null;
932
+ }
924
933
  findIdleSubagent() {
925
934
  for (const [id, s] of this.subagents) {
926
935
  if (s.status === "idle" && !this.terminating.has(id)) return id;
927
936
  }
928
937
  return null;
929
938
  }
939
+ isIdleSubagent(id) {
940
+ const subagent = this.subagents.get(id);
941
+ return !!subagent && subagent.status === "idle" && !this.terminating.has(id);
942
+ }
930
943
  /**
931
944
  * Returns true iff at least one spawned subagent could still
932
945
  * process a task. A "live" subagent is one that is not stopped
@@ -1111,10 +1124,11 @@ var DefaultMultiAgentCoordinator = class extends EventEmitter {
1111
1124
  };
1112
1125
  function classifySubagentError(err, hints = {}) {
1113
1126
  const cause = err instanceof Error ? { name: err.name, message: err.message, stack: err.stack } : void 0;
1114
- const baseMessage = err instanceof Error ? err.message : String(err);
1115
1127
  if (err instanceof ProviderError) {
1116
- return providerErrorToSubagentError(err, baseMessage, cause);
1128
+ const baseMessage2 = err.describe();
1129
+ return providerErrorToSubagentError(err, baseMessage2, cause);
1117
1130
  }
1131
+ const baseMessage = err instanceof Error ? err.message : String(err);
1118
1132
  if (err instanceof BudgetExceededError) {
1119
1133
  const map = {
1120
1134
  iterations: "budget_iterations",
@@ -1231,7 +1245,7 @@ function makeSpawnTool(director, roster) {
1231
1245
  if (role && !base) {
1232
1246
  return { error: `unknown role "${role}". roster has: ${roster ? Object.keys(roster).join(", ") : "(empty)"}` };
1233
1247
  }
1234
- const cfg = { ...base ?? { name: i.name ?? "subagent" } };
1248
+ const cfg = base ? instantiateRosterConfig(role, base) : { name: i.name ?? "subagent" };
1235
1249
  if (typeof i.name === "string") cfg.name = i.name;
1236
1250
  if (typeof i.provider === "string") cfg.provider = i.provider;
1237
1251
  if (typeof i.model === "string") cfg.model = i.model;
@@ -1251,6 +1265,14 @@ function makeSpawnTool(director, roster) {
1251
1265
  }
1252
1266
  };
1253
1267
  }
1268
+ function instantiateRosterConfig(role, base) {
1269
+ return {
1270
+ ...base,
1271
+ // Roster entries are templates. A director may spawn several
1272
+ // workers with the same role, so never reuse the template id.
1273
+ id: `${role}-${randomUUID().slice(0, 8)}`
1274
+ };
1275
+ }
1254
1276
  function makeAssignTool(director) {
1255
1277
  const inputSchema = {
1256
1278
  type: "object",
@@ -2012,7 +2034,7 @@ function createDelegateTool(opts) {
2012
2034
  error: `Unknown role "${i.role}". Available: ${rosterIds.join(", ") || "(no roster configured)"}.`
2013
2035
  };
2014
2036
  }
2015
- cfg = { ...base };
2037
+ cfg = instantiateRosterConfig2(i.role, base);
2016
2038
  if (i.systemPromptOverride) cfg.systemPromptOverride = i.systemPromptOverride;
2017
2039
  if (i.provider) cfg.provider = i.provider;
2018
2040
  if (i.model) cfg.model = i.model;
@@ -2098,6 +2120,14 @@ function createDelegateTool(opts) {
2098
2120
  }
2099
2121
  };
2100
2122
  }
2123
+ function instantiateRosterConfig2(role, base) {
2124
+ return {
2125
+ ...base,
2126
+ // Roster entries are templates. Give each spawn a fresh id so
2127
+ // parallel or repeated delegates can use the same role safely.
2128
+ id: `${role}-${randomUUID().slice(0, 8)}`
2129
+ };
2130
+ }
2101
2131
  function hintForKind(kind, retryable, backoffMs) {
2102
2132
  if (!kind) return void 0;
2103
2133
  switch (kind) {