@mantyx/sdk 2026.11.11 → 2026.11.13

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.
@@ -112,6 +112,7 @@ function defineLocalTool(opts) {
112
112
  longRunning: opts.longRunning ?? false,
113
113
  readOnly: opts.readOnly ?? false,
114
114
  retain: opts.retain ?? false,
115
+ ...toolGrouping(opts),
115
116
  execute: opts.execute
116
117
  };
117
118
  }
@@ -126,7 +127,8 @@ function mantyxA2A(opts) {
126
127
  ...opts.description !== void 0 ? { description: opts.description } : {},
127
128
  agentCardUrl: opts.agentCardUrl,
128
129
  ...opts.headers ? { headers: { ...opts.headers } } : {},
129
- ...opts.contextId ? { contextId: opts.contextId } : {}
130
+ ...opts.contextId ? { contextId: opts.contextId } : {},
131
+ ...toolGrouping(opts)
130
132
  };
131
133
  }
132
134
  function defineLocalA2A(opts) {
@@ -138,7 +140,8 @@ function defineLocalA2A(opts) {
138
140
  kind: "a2a_local",
139
141
  name: opts.name,
140
142
  agentCardUrl: opts.agentCardUrl,
141
- headers: opts.headers ? { ...opts.headers } : void 0
143
+ headers: opts.headers ? { ...opts.headers } : void 0,
144
+ ...toolGrouping(opts)
142
145
  };
143
146
  }
144
147
  function mantyxMcp(opts) {
@@ -151,7 +154,8 @@ function mantyxMcp(opts) {
151
154
  name: opts.name,
152
155
  url: opts.url,
153
156
  ...opts.headers ? { headers: { ...opts.headers } } : {},
154
- ...opts.toolFilter ? { toolFilter: [...opts.toolFilter] } : {}
157
+ ...opts.toolFilter ? { toolFilter: [...opts.toolFilter] } : {},
158
+ ...toolGrouping(opts)
155
159
  };
156
160
  }
157
161
  function defineLocalMcp(opts) {
@@ -177,7 +181,8 @@ function defineLocalMcp(opts) {
177
181
  url,
178
182
  ...opts.headers ? { headers: { ...opts.headers } } : {}
179
183
  },
180
- stdio: void 0
184
+ stdio: void 0,
185
+ ...toolGrouping(opts)
181
186
  };
182
187
  }
183
188
  const command = opts.command;
@@ -190,7 +195,8 @@ function defineLocalMcp(opts) {
190
195
  ...opts.args ? { args: [...opts.args] } : {},
191
196
  ...opts.env ? { env: { ...opts.env } } : {},
192
197
  ...opts.cwd ? { cwd: opts.cwd } : {}
193
- }
198
+ },
199
+ ...toolGrouping(opts)
194
200
  };
195
201
  }
196
202
  function isLocalTool(t) {
@@ -210,6 +216,34 @@ function assertToolName(name) {
210
216
  );
211
217
  }
212
218
  }
219
+ var TOOL_NAMESPACE_RE = /^[a-zA-Z0-9_]{1,64}$/;
220
+ function assertToolNamespace(namespace, label = "tool namespace") {
221
+ if (typeof namespace !== "string" || !TOOL_NAMESPACE_RE.test(namespace)) {
222
+ throw new Error(
223
+ `Invalid ${label} ${JSON.stringify(namespace)}: must match /^[a-zA-Z0-9_]{1,64}$/`
224
+ );
225
+ }
226
+ }
227
+ function toolGrouping(opts) {
228
+ const out = {};
229
+ if (opts.namespace !== void 0) {
230
+ assertToolNamespace(opts.namespace);
231
+ out.namespace = opts.namespace;
232
+ }
233
+ if (opts.alwaysLoaded !== void 0) {
234
+ if (typeof opts.alwaysLoaded !== "boolean") {
235
+ throw new Error(`alwaysLoaded must be a boolean, got ${JSON.stringify(opts.alwaysLoaded)}`);
236
+ }
237
+ out.alwaysLoaded = opts.alwaysLoaded;
238
+ }
239
+ return out;
240
+ }
241
+ function toolGroupingWire(t) {
242
+ return {
243
+ ...t.namespace !== void 0 ? { namespace: t.namespace } : {},
244
+ ...t.alwaysLoaded !== void 0 ? { alwaysLoaded: t.alwaysLoaded } : {}
245
+ };
246
+ }
213
247
  function prefixedMcpToolName(serverName, toolName) {
214
248
  const prefix = `${serverName}_`;
215
249
  return toolName.startsWith(prefix) ? toolName : `${prefix}${toolName}`;
@@ -684,13 +718,6 @@ function inputFileUrlAttachment(opts) {
684
718
  return { type: "input_file_url", ...opts };
685
719
  }
686
720
  var RUN_FEEDBACK_EXPLANATION_MAX = 8e3;
687
- function planOnly(options = {}) {
688
- return {
689
- planOnly: true,
690
- ...options.steps !== void 0 ? { steps: options.steps } : {},
691
- ...options.brief !== void 0 ? { brief: options.brief } : {}
692
- };
693
- }
694
721
  function buildQueryString(query) {
695
722
  if (!query) return "";
696
723
  const parts = [];
@@ -752,7 +779,7 @@ var MantyxClient = class {
752
779
  }
753
780
  // ------------------------------------------------------------- One-shot
754
781
  async runAgent(spec) {
755
- const tools = spec.tools ?? [];
782
+ const tools = toolsWithSubagentTools(spec.tools ?? [], spec.subagents);
756
783
  await resolveLocalRefs(tools, { fetch: this.options.fetch });
757
784
  const handlers = collectLocalHandlers(tools);
758
785
  try {
@@ -776,26 +803,8 @@ var MantyxClient = class {
776
803
  await closeMcpRefs(tools);
777
804
  }
778
805
  }
779
- /**
780
- * Plan-only run: classify (or accept caller `steps`) and return the
781
- * structured checklist without executing the agent loop. Sugar for
782
- * `runAgent({ ..., plan: planOnly({ steps, brief }) })`.
783
- *
784
- * The final checklist is on {@link RunResult.plan}; intermediate
785
- * progress is available via `task_plan` events when streaming.
786
- */
787
- async runPlan(spec) {
788
- const { steps, brief, ...rest } = spec;
789
- return this.runAgent({
790
- ...rest,
791
- plan: planOnly({
792
- ...steps !== void 0 ? { steps } : {},
793
- ...brief !== void 0 ? { brief } : {}
794
- })
795
- });
796
- }
797
806
  async *streamAgent(spec) {
798
- const tools = spec.tools ?? [];
807
+ const tools = toolsWithSubagentTools(spec.tools ?? [], spec.subagents);
799
808
  await resolveLocalRefs(tools, { fetch: this.options.fetch });
800
809
  const handlers = collectLocalHandlers(tools);
801
810
  try {
@@ -825,14 +834,15 @@ var MantyxClient = class {
825
834
  // ------------------------------------------------------------- Sessions
826
835
  async createSession(spec) {
827
836
  const tools = spec.tools ?? [];
828
- await resolveLocalRefs(tools, { fetch: this.options.fetch });
829
- const handlers = collectLocalHandlers(tools);
837
+ const ownedTools = toolsWithSubagentTools(tools, spec.subagents);
838
+ await resolveLocalRefs(ownedTools, { fetch: this.options.fetch });
839
+ const handlers = collectLocalHandlers(ownedTools);
830
840
  const created = await this.request({
831
841
  method: "POST",
832
842
  path: "/agent-sessions",
833
843
  body: serializeAgentSpec(spec)
834
844
  });
835
- return new AgentSession(this, created.sessionId, handlers, tools);
845
+ return new AgentSession(this, created.sessionId, handlers, tools, ownedTools);
836
846
  }
837
847
  /**
838
848
  * Re-emit a `local_tool_call` event into the right local handler. Useful
@@ -935,7 +945,6 @@ var MantyxClient = class {
935
945
  let turns;
936
946
  let modelInfo;
937
947
  let structuredOutput;
938
- let plan;
939
948
  for await (const ev of this.streamRunEvents(runId, handlers, opts.signal)) {
940
949
  collected.push(ev);
941
950
  if (opts.onEvent) opts.onEvent(ev);
@@ -950,10 +959,6 @@ var MantyxClient = class {
950
959
  structuredOutput = parseStructuredOutputInfo(r.structuredOutput) ?? structuredOutput;
951
960
  if (r.subtype === "success") {
952
961
  finalText = typeof r.text === "string" ? r.text : "";
953
- const parsedPlan = parseTaskPlan(r.plan);
954
- if (parsedPlan !== void 0) {
955
- plan = parsedPlan;
956
- }
957
962
  } else {
958
963
  const errInit = {};
959
964
  if (tokens !== void 0) errInit.tokens = tokens;
@@ -990,7 +995,6 @@ var MantyxClient = class {
990
995
  if (turns !== void 0) result.turns = turns;
991
996
  if (modelInfo !== void 0) result.model = modelInfo;
992
997
  if (structuredOutput !== void 0) result.structuredOutput = structuredOutput;
993
- if (plan !== void 0) result.plan = plan;
994
998
  return result;
995
999
  }
996
1000
  async *streamRunEvents(runId, handlers, signal) {
@@ -1106,6 +1110,59 @@ var MantyxClient = class {
1106
1110
  }
1107
1111
  }
1108
1112
  }
1113
+ /**
1114
+ * Fetch a run's snapshot: status, final text, token totals, model, and
1115
+ * for a sub-agent run its parent (`parentRunId`, `parentToolUseId`).
1116
+ */
1117
+ async getRun(runId) {
1118
+ return this.request({
1119
+ method: "GET",
1120
+ path: `/agent-runs/${encodeURIComponent(runId)}`
1121
+ });
1122
+ }
1123
+ /**
1124
+ * List runs, newest first, one page at a time (follow `nextCursor`).
1125
+ * Without `parentRunId` only top-level runs are listed; with it, the
1126
+ * sub-agent runs that run started.
1127
+ */
1128
+ async listRuns(opts = {}) {
1129
+ const query = {};
1130
+ if (typeof opts.limit === "number") query.limit = opts.limit;
1131
+ if (opts.cursor) query.cursor = opts.cursor;
1132
+ if (opts.status) query.status = opts.status;
1133
+ if (opts.modelId) query.modelId = opts.modelId;
1134
+ if (opts.metadata) {
1135
+ const pairs = Object.entries(opts.metadata).map(([k, v]) => `${k}:${v}`);
1136
+ if (pairs.length > 0) query.metadata = pairs;
1137
+ }
1138
+ if (opts.parentRunId) query.parentRunId = opts.parentRunId;
1139
+ if (opts.includeTotal) query.includeTotal = "1";
1140
+ const res = await this.request({
1141
+ method: "GET",
1142
+ path: "/agent-runs",
1143
+ query
1144
+ });
1145
+ return {
1146
+ total: typeof res.total === "number" ? res.total : null,
1147
+ limit: res.limit ?? 0,
1148
+ nextCursor: res.nextCursor ?? null,
1149
+ runs: res.runs ?? []
1150
+ };
1151
+ }
1152
+ /**
1153
+ * Every sub-agent run the given run started, newest first. Pages through
1154
+ * {@link listRuns} with `parentRunId` until the last page.
1155
+ */
1156
+ async listSubagents(runId) {
1157
+ const runs = [];
1158
+ let cursor;
1159
+ do {
1160
+ const page = await this.listRuns({ parentRunId: runId, limit: 200, cursor });
1161
+ runs.push(...page.runs);
1162
+ cursor = page.nextCursor ?? void 0;
1163
+ } while (cursor);
1164
+ return runs;
1165
+ }
1109
1166
  async cancelRun(runId) {
1110
1167
  await this.request({
1111
1168
  method: "POST",
@@ -1267,11 +1324,13 @@ var AgentSession = class {
1267
1324
  client;
1268
1325
  handlers;
1269
1326
  tools;
1270
- constructor(client, id, handlers, tools) {
1327
+ ownedTools;
1328
+ constructor(client, id, handlers, tools, ownedTools) {
1271
1329
  this.client = client;
1272
1330
  this.id = id;
1273
1331
  this.handlers = handlers;
1274
1332
  this.tools = tools ?? [];
1333
+ this.ownedTools = ownedTools ?? this.tools;
1275
1334
  }
1276
1335
  async send(promptOrMessages, opts = {}) {
1277
1336
  const created = await this.client.request({
@@ -1332,19 +1391,6 @@ var AgentSession = class {
1332
1391
  }
1333
1392
  return body;
1334
1393
  }
1335
- /**
1336
- * Plan-only session turn. Sugar for `send(prompt, { plan: planOnly(...) })`.
1337
- */
1338
- async runPlan(promptOrMessages, opts = {}) {
1339
- const { steps, brief, ...rest } = opts;
1340
- return this.send(promptOrMessages, {
1341
- ...rest,
1342
- plan: planOnly({
1343
- ...steps !== void 0 ? { steps } : {},
1344
- ...brief !== void 0 ? { brief } : {}
1345
- })
1346
- });
1347
- }
1348
1394
  async history() {
1349
1395
  const info = await this.client.getSessionInfo(this.id);
1350
1396
  return info.messages;
@@ -1362,7 +1408,7 @@ var AgentSession = class {
1362
1408
  try {
1363
1409
  await this.client.endSession(this.id);
1364
1410
  } finally {
1365
- await closeMcpRefs(this.tools);
1411
+ await closeMcpRefs(this.ownedTools);
1366
1412
  }
1367
1413
  }
1368
1414
  };
@@ -1417,6 +1463,15 @@ function serializeAgentSpec(spec, extra = {}) {
1417
1463
  if (spec.fallbackModelId) body.fallbackModelId = spec.fallbackModelId;
1418
1464
  if (spec.openRouterProvider !== void 0) body.openRouterProvider = spec.openRouterProvider;
1419
1465
  if (spec.newLoop !== void 0) body.newLoop = spec.newLoop;
1466
+ if (spec.toolSearch !== void 0) {
1467
+ if (typeof spec.toolSearch !== "boolean") {
1468
+ throw new MantyxError(`toolSearch must be a boolean, got ${JSON.stringify(spec.toolSearch)}`);
1469
+ }
1470
+ body.toolSearch = spec.toolSearch;
1471
+ }
1472
+ if (spec.toolNamespaces !== void 0) {
1473
+ body.toolNamespaces = normalizeToolNamespaces(spec.toolNamespaces);
1474
+ }
1420
1475
  if (spec.reasoningLevel !== void 0) {
1421
1476
  body.reasoningLevel = normalizeReasoningLevel(spec.reasoningLevel);
1422
1477
  }
@@ -1432,6 +1487,9 @@ function serializeAgentSpec(spec, extra = {}) {
1432
1487
  if (spec.supervisor !== void 0) {
1433
1488
  body.supervisor = normalizeSupervisor(spec.supervisor);
1434
1489
  }
1490
+ if (spec.subagents !== void 0) {
1491
+ body.subagents = normalizeSubagents(spec.subagents);
1492
+ }
1435
1493
  if (spec.plan !== void 0) {
1436
1494
  body.plan = normalizePlan(spec.plan);
1437
1495
  }
@@ -1440,6 +1498,32 @@ function serializeAgentSpec(spec, extra = {}) {
1440
1498
  Object.assign(body, serializeTurnInput(extra));
1441
1499
  return body;
1442
1500
  }
1501
+ var MAX_TOOL_NAMESPACES = 64;
1502
+ var MAX_TOOL_NAMESPACE_DESCRIPTION = 2e3;
1503
+ function normalizeToolNamespaces(value) {
1504
+ if (!Array.isArray(value)) {
1505
+ throw new MantyxError(`toolNamespaces must be an array, got ${JSON.stringify(value)}`);
1506
+ }
1507
+ if (value.length > MAX_TOOL_NAMESPACES) {
1508
+ throw new MantyxError(`toolNamespaces accepts at most ${MAX_TOOL_NAMESPACES} entries, got ${value.length}`);
1509
+ }
1510
+ return value.map((ns, i) => {
1511
+ if (!ns || typeof ns !== "object") {
1512
+ throw new MantyxError(`toolNamespaces[${i}] must be an object, got ${JSON.stringify(ns)}`);
1513
+ }
1514
+ try {
1515
+ assertToolNamespace(ns.name, `toolNamespaces[${i}].name`);
1516
+ } catch (err) {
1517
+ throw new MantyxError(err.message);
1518
+ }
1519
+ if (typeof ns.description !== "string" || ns.description.length < 1 || ns.description.length > MAX_TOOL_NAMESPACE_DESCRIPTION) {
1520
+ throw new MantyxError(
1521
+ `toolNamespaces[${i}].description must be a string of 1-${MAX_TOOL_NAMESPACE_DESCRIPTION} characters`
1522
+ );
1523
+ }
1524
+ return { name: ns.name, description: ns.description };
1525
+ });
1526
+ }
1443
1527
  function serializeToolRefs(tools) {
1444
1528
  return tools.map((t) => {
1445
1529
  switch (t.kind) {
@@ -1452,7 +1536,8 @@ function serializeToolRefs(tools) {
1452
1536
  ...t.outputSchema !== void 0 ? { outputSchema: toToolParametersWire(t.outputSchema) } : {},
1453
1537
  ...t.longRunning ? { longRunning: true } : {},
1454
1538
  ...t.readOnly ? { readOnly: true } : {},
1455
- ...t.retain ? { retain: true } : {}
1539
+ ...t.retain ? { retain: true } : {},
1540
+ ...toolGroupingWire(t)
1456
1541
  };
1457
1542
  case "a2a":
1458
1543
  return {
@@ -1461,7 +1546,8 @@ function serializeToolRefs(tools) {
1461
1546
  ...t.description !== void 0 ? { description: t.description } : {},
1462
1547
  agentCardUrl: t.agentCardUrl,
1463
1548
  ...t.headers ? { headers: { ...t.headers } } : {},
1464
- ...t.contextId ? { contextId: t.contextId } : {}
1549
+ ...t.contextId ? { contextId: t.contextId } : {},
1550
+ ...toolGroupingWire(t)
1465
1551
  };
1466
1552
  case "a2a_local": {
1467
1553
  const card = t._resolvedCard;
@@ -1476,7 +1562,8 @@ function serializeToolRefs(tools) {
1476
1562
  // The wire ships the resolved A2A Agent Card. Shallow-clone so
1477
1563
  // consumers can mutate the input later without affecting the
1478
1564
  // wire payload.
1479
- agentCard: { ...card }
1565
+ agentCard: { ...card },
1566
+ ...toolGroupingWire(t)
1480
1567
  };
1481
1568
  }
1482
1569
  case "mcp":
@@ -1485,7 +1572,8 @@ function serializeToolRefs(tools) {
1485
1572
  name: t.name,
1486
1573
  url: t.url,
1487
1574
  ...t.headers ? { headers: { ...t.headers } } : {},
1488
- ...t.toolFilter ? { toolFilter: [...t.toolFilter] } : {}
1575
+ ...t.toolFilter ? { toolFilter: [...t.toolFilter] } : {},
1576
+ ...toolGroupingWire(t)
1489
1577
  };
1490
1578
  case "mcp_local": {
1491
1579
  const resolved = t._resolved;
@@ -1507,7 +1595,8 @@ function serializeToolRefs(tools) {
1507
1595
  kind: "mcp_local",
1508
1596
  name: t.name,
1509
1597
  serverInfo: { ...resolved.serverInfo },
1510
- tools: tools2
1598
+ tools: tools2,
1599
+ ...toolGroupingWire(t)
1511
1600
  };
1512
1601
  }
1513
1602
  }
@@ -1700,6 +1789,157 @@ function normalizeSupervisor(value) {
1700
1789
  }
1701
1790
  return out;
1702
1791
  }
1792
+ var SUBAGENTS_MAX_PER_RUN = 50;
1793
+ var SUBAGENTS_MAX_CONCURRENT = 20;
1794
+ var SUBAGENTS_MAX_TOOL_TURNS = 200;
1795
+ var SUBAGENTS_MODEL_ID_MAX = 200;
1796
+ var SUBAGENTS_TOOL_NAME_MAX = 128;
1797
+ var SUBAGENTS_INSTRUCTIONS_MAX = 8e3;
1798
+ var SUBAGENTS_MAX_DEFINITIONS = 20;
1799
+ var SUBAGENT_NAME_RE = /^[a-zA-Z0-9_-]{1,64}$/;
1800
+ var SUBAGENT_DESCRIPTION_MAX = 1e3;
1801
+ var SUBAGENT_SYSTEM_PROMPT_MAX = 64e3;
1802
+ function isPlainObject(value) {
1803
+ return !!value && typeof value === "object" && !Array.isArray(value);
1804
+ }
1805
+ function subagentModelId(label, value) {
1806
+ const modelId = typeof value === "string" ? value.trim() : value;
1807
+ if (typeof modelId !== "string" || modelId.length < 1 || modelId.length > SUBAGENTS_MODEL_ID_MAX) {
1808
+ throw new MantyxError(
1809
+ `${label} must be a 1..${SUBAGENTS_MODEL_ID_MAX}-char string, got ${JSON.stringify(value)}`
1810
+ );
1811
+ }
1812
+ return modelId;
1813
+ }
1814
+ function subagentToolName(label, value) {
1815
+ if (typeof value !== "string" || value.length < 1 || value.length > SUBAGENTS_TOOL_NAME_MAX) {
1816
+ throw new MantyxError(
1817
+ `${label} must be a 1..${SUBAGENTS_TOOL_NAME_MAX}-char tool name, got ${JSON.stringify(value)}`
1818
+ );
1819
+ }
1820
+ return value;
1821
+ }
1822
+ function normalizeSubagentSelf(value) {
1823
+ if (value === true || value === false) return value;
1824
+ if (!isPlainObject(value)) {
1825
+ throw new MantyxError(`subagents.self must be a boolean or an object, got ${JSON.stringify(value)}`);
1826
+ }
1827
+ const out = {};
1828
+ if (value.modelId !== void 0) out.modelId = subagentModelId("subagents.self.modelId", value.modelId);
1829
+ if (value.reasoningLevel !== void 0) out.reasoningLevel = normalizeReasoningLevel(value.reasoningLevel);
1830
+ if (value.maxToolTurns !== void 0) {
1831
+ out.maxToolTurns = assertThreshold("subagents.self.maxToolTurns", value.maxToolTurns, 1, SUBAGENTS_MAX_TOOL_TURNS);
1832
+ }
1833
+ if (value.tools !== void 0) {
1834
+ if (!Array.isArray(value.tools)) {
1835
+ throw new MantyxError(`subagents.self.tools must be an array of tool names, got ${JSON.stringify(value.tools)}`);
1836
+ }
1837
+ out.tools = value.tools.map((t, i) => subagentToolName(`subagents.self.tools[${i}]`, t));
1838
+ }
1839
+ if (value.instructions !== void 0) {
1840
+ if (typeof value.instructions !== "string" || value.instructions.length > SUBAGENTS_INSTRUCTIONS_MAX) {
1841
+ throw new MantyxError(`subagents.self.instructions must be a string of at most ${SUBAGENTS_INSTRUCTIONS_MAX} chars`);
1842
+ }
1843
+ out.instructions = value.instructions;
1844
+ }
1845
+ return out;
1846
+ }
1847
+ function normalizeSubagentDefinition(value, index) {
1848
+ const label = `subagents.agents[${index}]`;
1849
+ if (!isPlainObject(value)) {
1850
+ throw new MantyxError(`${label} must be an object, got ${JSON.stringify(value)}`);
1851
+ }
1852
+ if (typeof value.name !== "string" || !SUBAGENT_NAME_RE.test(value.name) || value.name.toLowerCase() === "self") {
1853
+ throw new MantyxError(
1854
+ `${label}.name must match /^[a-zA-Z0-9_-]{1,64}$/ and not be "self", got ${JSON.stringify(value.name)}`
1855
+ );
1856
+ }
1857
+ const description = typeof value.description === "string" ? value.description.trim() : "";
1858
+ if (description.length < 1 || description.length > SUBAGENT_DESCRIPTION_MAX) {
1859
+ throw new MantyxError(`${label}.description must be a 1..${SUBAGENT_DESCRIPTION_MAX}-char string`);
1860
+ }
1861
+ if (typeof value.systemPrompt !== "string" || value.systemPrompt.length < 1 || value.systemPrompt.length > SUBAGENT_SYSTEM_PROMPT_MAX) {
1862
+ throw new MantyxError(`${label}.systemPrompt must be a 1..${SUBAGENT_SYSTEM_PROMPT_MAX}-char string`);
1863
+ }
1864
+ const out = {
1865
+ name: value.name,
1866
+ description: value.description,
1867
+ systemPrompt: value.systemPrompt
1868
+ };
1869
+ if (value.modelId !== void 0) out.modelId = subagentModelId(`${label}.modelId`, value.modelId);
1870
+ if (value.fallbackModelId !== void 0) {
1871
+ out.fallbackModelId = subagentModelId(`${label}.fallbackModelId`, value.fallbackModelId);
1872
+ }
1873
+ if (value.reasoningLevel !== void 0) out.reasoningLevel = normalizeReasoningLevel(value.reasoningLevel);
1874
+ if (value.tools !== void 0) {
1875
+ if (!Array.isArray(value.tools)) {
1876
+ throw new MantyxError(`${label}.tools must be an array, got ${JSON.stringify(value.tools)}`);
1877
+ }
1878
+ out.tools = value.tools.map(
1879
+ (t, i) => typeof t === "string" ? subagentToolName(`${label}.tools[${i}]`, t) : serializeToolRefs([t])[0]
1880
+ );
1881
+ }
1882
+ if (value.budgets !== void 0) {
1883
+ if (!isPlainObject(value.budgets)) {
1884
+ throw new MantyxError(`${label}.budgets must be an object { maxToolTurns? }`);
1885
+ }
1886
+ const budgets = {};
1887
+ if (value.budgets.maxToolTurns !== void 0) {
1888
+ budgets.maxToolTurns = assertThreshold(
1889
+ `${label}.budgets.maxToolTurns`,
1890
+ value.budgets.maxToolTurns,
1891
+ 1,
1892
+ SUBAGENTS_MAX_TOOL_TURNS
1893
+ );
1894
+ }
1895
+ out.budgets = budgets;
1896
+ }
1897
+ if (value.toolBudgets !== void 0) out.toolBudgets = normalizeToolBudgets(value.toolBudgets);
1898
+ if (value.outputSchema !== void 0) out.outputSchema = normalizeOutputSchema(value.outputSchema);
1899
+ return out;
1900
+ }
1901
+ function normalizeSubagents(value) {
1902
+ if (value === true || value === false) return value;
1903
+ if (!isPlainObject(value)) {
1904
+ throw new MantyxError(`subagents must be a boolean or an object, got ${JSON.stringify(value)}`);
1905
+ }
1906
+ const out = {};
1907
+ if (value.self !== void 0) out.self = normalizeSubagentSelf(value.self);
1908
+ if (value.agents !== void 0) {
1909
+ if (!Array.isArray(value.agents) || value.agents.length > SUBAGENTS_MAX_DEFINITIONS) {
1910
+ throw new MantyxError(`subagents.agents must be an array of at most ${SUBAGENTS_MAX_DEFINITIONS} definitions`);
1911
+ }
1912
+ const names = /* @__PURE__ */ new Set();
1913
+ out.agents = value.agents.map((a, i) => {
1914
+ const wire = normalizeSubagentDefinition(a, i);
1915
+ if (names.has(wire.name)) {
1916
+ throw new MantyxError(`subagents.agents: duplicate name ${JSON.stringify(wire.name)}`);
1917
+ }
1918
+ names.add(wire.name);
1919
+ return wire;
1920
+ });
1921
+ }
1922
+ if (value.maxPerRun !== void 0) {
1923
+ out.maxPerRun = assertThreshold("subagents.maxPerRun", value.maxPerRun, 1, SUBAGENTS_MAX_PER_RUN);
1924
+ }
1925
+ if (value.maxConcurrent !== void 0) {
1926
+ out.maxConcurrent = assertThreshold("subagents.maxConcurrent", value.maxConcurrent, 1, SUBAGENTS_MAX_CONCURRENT);
1927
+ }
1928
+ return out;
1929
+ }
1930
+ function toolsWithSubagentTools(tools, subagents) {
1931
+ if (!isPlainObject(subagents) || !Array.isArray(subagents.agents)) return tools;
1932
+ const all = [...tools];
1933
+ const seen = new Set(tools);
1934
+ for (const agent of subagents.agents) {
1935
+ for (const t of agent?.tools ?? []) {
1936
+ if (typeof t === "string" || seen.has(t)) continue;
1937
+ seen.add(t);
1938
+ all.push(t);
1939
+ }
1940
+ }
1941
+ return all;
1942
+ }
1703
1943
  var PLAN_MODES = /* @__PURE__ */ new Set(["off", "auto", "required"]);
1704
1944
  var TASK_PLAN_STEP_STATUSES = /* @__PURE__ */ new Set([
1705
1945
  "pending",
@@ -1728,18 +1968,15 @@ function normalizePlan(value) {
1728
1968
  if (typeof value === "string") return assertPlanMode("plan", value);
1729
1969
  if (!value || typeof value !== "object" || Array.isArray(value)) {
1730
1970
  throw new MantyxError(
1731
- `plan must be "off", "auto", "required", \`true\`, \`false\`, or an object { mode?, planOnly?, brief?, steps? }, got ${JSON.stringify(value)}`
1971
+ `plan must be "off", "auto", "required", \`true\`, \`false\`, or an object { mode?, brief?, steps? }, got ${JSON.stringify(value)}`
1732
1972
  );
1733
1973
  }
1734
1974
  const out = {};
1735
1975
  if (value.mode !== void 0) {
1736
1976
  out.mode = assertPlanMode("plan.mode", value.mode);
1737
1977
  }
1738
- if (value.planOnly !== void 0) {
1739
- if (typeof value.planOnly !== "boolean") {
1740
- throw new MantyxError(`plan.planOnly must be a boolean, got ${JSON.stringify(value.planOnly)}`);
1741
- }
1742
- out.planOnly = value.planOnly;
1978
+ if (value.planOnly === true) {
1979
+ throw new MantyxError("plan.planOnly: plan-only runs are no longer supported");
1743
1980
  }
1744
1981
  if (value.brief !== void 0) {
1745
1982
  if (typeof value.brief !== "string") {
@@ -1986,7 +2223,6 @@ export {
1986
2223
  DEFAULT_BASE_URL,
1987
2224
  inputFileAttachment,
1988
2225
  inputFileUrlAttachment,
1989
- planOnly,
1990
2226
  MantyxClient,
1991
2227
  AgentSession,
1992
2228
  taskPlanFromEventData,