@runtypelabs/sdk 11.19.0 → 11.19.1

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/dist/index.cjs CHANGED
@@ -222,7 +222,8 @@ function createFlowEventTranslator() {
222
222
  awaitedAt: data.awaitedAt,
223
223
  origin: data.origin,
224
224
  pageOrigin: data.pageOrigin,
225
- annotations: data.annotations
225
+ annotations: data.annotations,
226
+ subagent: data.subagent
226
227
  })];
227
228
  default: return [];
228
229
  }
@@ -870,7 +871,7 @@ var FlowResult = class {
870
871
  */
871
872
  async stream(callbacks = {}) {
872
873
  if (this.consumed && this.cachedSummary) {
873
- if (callbacks.onFlowComplete) callbacks.onFlowComplete({
874
+ if (callbacks.onFlowComplete && !this.cachedSummary.paused) callbacks.onFlowComplete({
874
875
  type: "flow_complete",
875
876
  flowId: this.cachedSummary.flowId,
876
877
  totalSteps: this.cachedSummary.totalSteps,
@@ -1807,6 +1808,13 @@ function createExternalTool(config) {
1807
1808
  };
1808
1809
  }
1809
1810
  // src/local-tool-pause.ts
1811
+ function subagentOf(value) {
1812
+ const subagent = value;
1813
+ return typeof subagent?.toolName === "string" && typeof subagent.parentToolCallId === "string" ? {
1814
+ toolName: subagent.toolName,
1815
+ parentToolCallId: subagent.parentToolCallId
1816
+ } : void 0;
1817
+ }
1810
1818
  /**
1811
1819
  * Fold a unified `await` event, or an SDK stable-callback `flow_await` /
1812
1820
  * `step_await`, into the per-tool paused-state map. Compatibility frames may
@@ -1827,10 +1835,12 @@ function collectLocalToolAwait(pausedTools, event) {
1827
1835
  const pending = pausedTools.get(PENDING_NAMELESS_KEY);
1828
1836
  if (pending) pausedTools.delete(PENDING_NAMELESS_KEY);
1829
1837
  const prev = pausedTools.get(name) ?? pending;
1838
+ const subagent = subagentOf(event.subagent) ?? prev?.subagent;
1830
1839
  pausedTools.set(name, {
1831
1840
  toolName: name,
1832
1841
  executionId: executionId ?? prev?.executionId ?? "",
1833
- parameters: event.parameters ?? prev?.parameters
1842
+ parameters: event.parameters ?? prev?.parameters,
1843
+ ...subagent ? { subagent } : {}
1834
1844
  });
1835
1845
  return;
1836
1846
  }
@@ -1853,6 +1863,55 @@ function resolveBatchExecutionId(pausedTools) {
1853
1863
  for (const tool of pausedTools) if (tool.executionId) return tool.executionId;
1854
1864
  return "";
1855
1865
  }
1866
+ /**
1867
+ * Splits a paused batch into the calls this caller runs and the sub-agent requests it holds no handler for.
1868
+ * Those are left paused on the parent for whoever watches it (an approver, a UI), never thrown as missing.
1869
+ */
1870
+ function partitionLocalToolBatch(pausedTools, hasHandler) {
1871
+ const leftToParent = pausedTools.filter((tool) => tool.subagent && !hasHandler(tool.toolName));
1872
+ return {
1873
+ runnable: pausedTools.filter((tool) => !leftToParent.includes(tool)),
1874
+ leftToParent
1875
+ };
1876
+ }
1877
+ /** The result a run returns when every remaining request belongs to a sub-agent this caller cannot answer. */
1878
+ function pausedOnSubagentEnvelope(executionId, leftToParent) {
1879
+ return {
1880
+ status: "paused",
1881
+ executionId,
1882
+ pausedTools: leftToParent
1883
+ };
1884
+ }
1885
+ /** A run's summary when it stopped on sub-agent requests this caller cannot answer, so every result getter reads it. */
1886
+ function pausedOnSubagentSummary(executionId, leftToParent) {
1887
+ return {
1888
+ flowId: "",
1889
+ flowName: "",
1890
+ totalSteps: 0,
1891
+ successfulSteps: 0,
1892
+ failedSteps: 0,
1893
+ executionTime: 0,
1894
+ results: /* @__PURE__ */ new Map(),
1895
+ success: true,
1896
+ paused: pausedOnSubagentEnvelope(executionId, leftToParent)
1897
+ };
1898
+ }
1899
+ /** The next batch with the sub-agent requests still held from an earlier cycle, each once. */
1900
+ function withCarriedRequests(carried, pausedTools) {
1901
+ const key = (tool) => `${tool.subagent?.parentToolCallId ?? ""}:${tool.toolName}`;
1902
+ const seen = new Set(pausedTools.map(key));
1903
+ return [...pausedTools, ...carried.filter((tool) => !seen.has(key(tool)))];
1904
+ }
1905
+ /** Whether a buffered envelope reached the run's end; one whose follow closed before a terminal frame did not. */
1906
+ function bufferedReachedTerminal(data) {
1907
+ if (typeof data !== "object" || data === null) return true;
1908
+ const { status, events } = data;
1909
+ if (status !== "failed" || !Array.isArray(events)) return true;
1910
+ return events.some((event) => {
1911
+ const type = event?.type;
1912
+ return type === "execution_complete" || type === "execution_error";
1913
+ });
1914
+ }
1856
1915
  // src/detached-reconnect.ts
1857
1916
  /**
1858
1917
  * Transparent reconnect for a DETACHED agent stream (ADR 0020 point 6;
@@ -10792,6 +10851,7 @@ var RuntypeFlowBuilder = class {
10792
10851
  };
10793
10852
  const processStep = async (response) => {
10794
10853
  if (isStreaming) {
10854
+ let reachedTerminal = false;
10795
10855
  const pausedTools = /* @__PURE__ */ new Map();
10796
10856
  const wrappedCallbacks = {
10797
10857
  ...callbacks,
@@ -10820,9 +10880,12 @@ var RuntypeFlowBuilder = class {
10820
10880
  wrappedCallbacks.onStepComplete?.(event.result, event);
10821
10881
  break;
10822
10882
  case "flow_complete":
10883
+ reachedTerminal = true;
10823
10884
  wrappedCallbacks.onFlowComplete?.(event);
10824
10885
  break;
10825
- case "flow_error": wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
10886
+ case "flow_error":
10887
+ reachedTerminal = true;
10888
+ wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
10826
10889
  }
10827
10890
  }
10828
10891
  } catch (e) {
@@ -10838,7 +10901,8 @@ var RuntypeFlowBuilder = class {
10838
10901
  };
10839
10902
  return {
10840
10903
  done: true,
10841
- result: accumulatedSummary
10904
+ result: accumulatedSummary,
10905
+ terminal: reachedTerminal
10842
10906
  };
10843
10907
  } else {
10844
10908
  const data = await response.json();
@@ -10861,10 +10925,15 @@ var RuntypeFlowBuilder = class {
10861
10925
  }
10862
10926
  return {
10863
10927
  done: true,
10864
- result: data
10928
+ result: data,
10929
+ terminal: bufferedReachedTerminal(data)
10865
10930
  };
10866
10931
  }
10867
10932
  };
10933
+ const pausedOnSubagent = (left) => {
10934
+ const summary = pausedOnSubagentSummary(resolveBatchExecutionId(left), left);
10935
+ return new FlowResult(new Response(JSON.stringify(summary.paused), { headers: { "content-type": "application/json" } }), summary);
10936
+ };
10868
10937
  let currentResponse;
10869
10938
  let carriedRelease = {};
10870
10939
  if (isStreaming) currentResponse = await client.dispatch(config);
@@ -10873,8 +10942,11 @@ var RuntypeFlowBuilder = class {
10873
10942
  carriedRelease = releaseFieldsOf(data);
10874
10943
  currentResponse = new Response(JSON.stringify(data), { headers: { "content-type": "application/json" } });
10875
10944
  }
10945
+ let carried = [];
10876
10946
  while (true) {
10877
- const { done, result } = await processStep(currentResponse);
10947
+ const { done, result, terminal } = await processStep(currentResponse);
10948
+ const pausedNow = result;
10949
+ if (carried.length > 0 && (done ? terminal === false : !(pausedNow.status === "paused" && pausedNow.pausedTools?.length))) return pausedOnSubagent(carried);
10878
10950
  if (done) {
10879
10951
  if (isStreaming) return new FlowResult(new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } }), result);
10880
10952
  return new FlowResult(new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } }));
@@ -10882,8 +10954,11 @@ var RuntypeFlowBuilder = class {
10882
10954
  const pausedResult = result;
10883
10955
  if (pausedResult.status === "paused" && pausedResult.pausedTools?.length) {
10884
10956
  const executionId = resolveBatchExecutionId(pausedResult.pausedTools);
10957
+ const { runnable, leftToParent } = partitionLocalToolBatch(withCarriedRequests(carried, pausedResult.pausedTools), (toolName) => Boolean(localTools[toolName]));
10958
+ if (runnable.length === 0) return pausedOnSubagent(leftToParent);
10959
+ carried = leftToParent;
10885
10960
  try {
10886
- const outputs = await Promise.all(pausedResult.pausedTools.map(async ({ toolName, parameters }) => {
10961
+ const outputs = await Promise.all(runnable.map(async ({ toolName, parameters }) => {
10887
10962
  if (!localTools[toolName]) throw new Error(`Local tool "${toolName}" required but not provided in localTools map`);
10888
10963
  try {
10889
10964
  return [toolName, await localTools[toolName](parameters)];
@@ -14755,7 +14830,7 @@ function transformQueryParams(params) {
14755
14830
  return result;
14756
14831
  }
14757
14832
  // src/version.ts
14758
- const SDK_VERSION = "11.19.0";
14833
+ const SDK_VERSION = "11.19.1";
14759
14834
  /**
14760
14835
  * Canonical client identity the API uses for attribution
14761
14836
  * (`detectActorSource` in apps/api/src/lib/audit-log.ts keys `'sdk'` off the
@@ -14772,6 +14847,14 @@ const RUNTYPE_CLIENT_KIND = "sdk";
14772
14847
  */
14773
14848
  const SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
14774
14849
  // src/client.ts
14850
+ /** The handler for a paused tool: its exact name first, then the webmcp:-stripped form, so no namespace shadows one. */
14851
+ function findLocalToolEntry(localTools, toolName) {
14852
+ const BARE_NAME_NAMESPACES = ["webmcp:"];
14853
+ const lookupCandidates = [toolName];
14854
+ for (const ns of BARE_NAME_NAMESPACES) if (toolName.startsWith(ns)) lookupCandidates.push(toolName.slice(ns.length));
14855
+ const matchedKey = lookupCandidates.find((key) => localTools[key]);
14856
+ return matchedKey ? localTools[matchedKey] : void 0;
14857
+ }
14775
14858
  function isObjectRecord(value) {
14776
14859
  return typeof value === "object" && value !== null;
14777
14860
  }
@@ -14900,6 +14983,7 @@ var RuntypeClient = class {
14900
14983
  };
14901
14984
  const processStep = async (response) => {
14902
14985
  if (isStreaming) {
14986
+ let reachedTerminal = false;
14903
14987
  const pausedTools = /* @__PURE__ */ new Map();
14904
14988
  const wrappedCallbacks = {
14905
14989
  ...callbacks,
@@ -14932,9 +15016,12 @@ var RuntypeClient = class {
14932
15016
  wrappedCallbacks.onStepComplete?.(event.result, event);
14933
15017
  break;
14934
15018
  case "flow_complete":
15019
+ reachedTerminal = true;
14935
15020
  wrappedCallbacks.onFlowComplete?.(event);
14936
15021
  break;
14937
- case "flow_error": wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
15022
+ case "flow_error":
15023
+ reachedTerminal = true;
15024
+ wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
14938
15025
  }
14939
15026
  }
14940
15027
  } catch (e) {
@@ -14950,7 +15037,8 @@ var RuntypeClient = class {
14950
15037
  };
14951
15038
  return {
14952
15039
  done: true,
14953
- result: summary
15040
+ result: summary,
15041
+ terminal: reachedTerminal
14954
15042
  };
14955
15043
  } else {
14956
15044
  const data = await response.json();
@@ -14973,10 +15061,16 @@ var RuntypeClient = class {
14973
15061
  }
14974
15062
  return {
14975
15063
  done: true,
14976
- result: data
15064
+ result: data,
15065
+ terminal: bufferedReachedTerminal(data)
14977
15066
  };
14978
15067
  }
14979
15068
  };
15069
+ const pausedOnSubagent = (left) => {
15070
+ const summary = pausedOnSubagentSummary(resolveBatchExecutionId(left), left);
15071
+ if (isStreaming) return summary;
15072
+ return new FlowResult(new Response(JSON.stringify(summary.paused), { headers: { "content-type": "application/json" } }), summary);
15073
+ };
14980
15074
  let currentResponse;
14981
15075
  let carriedRelease = {};
14982
15076
  if (isStreaming) currentResponse = await this.dispatch.executeStream(modifiedRequest);
@@ -14985,21 +15079,22 @@ var RuntypeClient = class {
14985
15079
  carriedRelease = releaseFieldsOf(data);
14986
15080
  currentResponse = new Response(JSON.stringify(data), { headers: { "content-type": "application/json" } });
14987
15081
  }
15082
+ let carried = [];
14988
15083
  while (true) {
14989
- const { done, result } = await processStep(currentResponse);
15084
+ const { done, result, terminal } = await processStep(currentResponse);
15085
+ if (carried.length > 0 && (done ? terminal === false : !isPausedLocalActionResult(result))) return pausedOnSubagent(carried);
14990
15086
  if (done) {
14991
15087
  if (isStreaming) return result;
14992
15088
  return new FlowResult(new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } }));
14993
15089
  }
14994
15090
  if (isPausedLocalActionResult(result)) {
14995
15091
  const executionId = resolveBatchExecutionId(result.pausedTools);
15092
+ const { runnable, leftToParent } = partitionLocalToolBatch(withCarriedRequests(carried, result.pausedTools), (toolName) => Boolean(findLocalToolEntry(localTools, toolName)));
15093
+ if (runnable.length === 0) return pausedOnSubagent(leftToParent);
15094
+ carried = leftToParent;
14996
15095
  try {
14997
- const outputs = await Promise.all(result.pausedTools.map(async ({ toolName, parameters }) => {
14998
- const BARE_NAME_NAMESPACES = ["webmcp:"];
14999
- const lookupCandidates = [toolName];
15000
- for (const ns of BARE_NAME_NAMESPACES) if (toolName.startsWith(ns)) lookupCandidates.push(toolName.slice(ns.length));
15001
- const matchedKey = lookupCandidates.find((key) => localTools[key]);
15002
- const toolEntry = matchedKey ? localTools[matchedKey] : void 0;
15096
+ const outputs = await Promise.all(runnable.map(async ({ toolName, parameters }) => {
15097
+ const toolEntry = findLocalToolEntry(localTools, toolName);
15003
15098
  if (!toolEntry) throw new Error(`Local tool "${toolName}" required but not provided in localTools map`);
15004
15099
  const handler = hasToolEntryShape(toolEntry) ? toolEntry.execute : toolEntry;
15005
15100
  try {
package/dist/index.d.cts CHANGED
@@ -14413,7 +14413,7 @@ interface paths {
14413
14413
  instruction: string;
14414
14414
  maxToolCalls?: number;
14415
14415
  /**
14416
- * @description Execution priority. Defaults to standard; fast uses DeepSeek V4.1 Flash Fast through Vercel. Applies when creating a task.
14416
+ * @description Execution speed. `standard` (the default) runs at normal speed; `fast` runs at a higher speed for tasks that need it. Applies when creating a task.
14417
14417
  * @enum {string}
14418
14418
  */
14419
14419
  priority?: "standard" | "fast";
@@ -63950,6 +63950,11 @@ interface components {
63950
63950
  };
63951
63951
  seq: number;
63952
63952
  stepId?: string;
63953
+ subagent?: {
63954
+ agentName?: string;
63955
+ parentToolCallId?: string;
63956
+ toolName: string;
63957
+ };
63953
63958
  toolCallId?: string;
63954
63959
  toolId?: string;
63955
63960
  toolName?: string;
@@ -67440,6 +67445,19 @@ interface ContextErrorHandling {
67440
67445
  onError: ErrorHandlingMode;
67441
67446
  fallbacks?: ContextFallback[];
67442
67447
  }
67448
+ /** A single paused local tool call awaiting client execution. */
67449
+ interface LocalToolPausedState {
67450
+ toolName: string;
67451
+ executionId: string;
67452
+ parameters?: unknown;
67453
+ /** Set when a sub-agent raised the request on the parent it is parked on; the caller may not hold its handler. */
67454
+ subagent?: LocalToolSubagent;
67455
+ }
67456
+ /** The parent call a sub-agent's request is shown under; answering it on the parent forwards it to the child. */
67457
+ interface LocalToolSubagent {
67458
+ toolName: string;
67459
+ parentToolCallId: string;
67460
+ }
67443
67461
  /**
67444
67462
  * Options for the flow stream consumers.
67445
67463
  *
@@ -68199,6 +68217,12 @@ interface FlowSummary {
68199
68217
  results: Map<string, any>;
68200
68218
  /** Whether the flow completed successfully */
68201
68219
  success: boolean;
68220
+ /** Set when the run stopped on sub-agent requests this caller registered no handler for; answer them on the parent. */
68221
+ paused?: {
68222
+ status: 'paused';
68223
+ executionId: string;
68224
+ pausedTools: LocalToolPausedState[];
68225
+ };
68202
68226
  }
68203
68227
  /**
68204
68228
  * Generic flow-step config for step types that do not yet have a typed SDK
package/dist/index.d.ts CHANGED
@@ -14413,7 +14413,7 @@ interface paths {
14413
14413
  instruction: string;
14414
14414
  maxToolCalls?: number;
14415
14415
  /**
14416
- * @description Execution priority. Defaults to standard; fast uses DeepSeek V4.1 Flash Fast through Vercel. Applies when creating a task.
14416
+ * @description Execution speed. `standard` (the default) runs at normal speed; `fast` runs at a higher speed for tasks that need it. Applies when creating a task.
14417
14417
  * @enum {string}
14418
14418
  */
14419
14419
  priority?: "standard" | "fast";
@@ -63950,6 +63950,11 @@ interface components {
63950
63950
  };
63951
63951
  seq: number;
63952
63952
  stepId?: string;
63953
+ subagent?: {
63954
+ agentName?: string;
63955
+ parentToolCallId?: string;
63956
+ toolName: string;
63957
+ };
63953
63958
  toolCallId?: string;
63954
63959
  toolId?: string;
63955
63960
  toolName?: string;
@@ -67440,6 +67445,19 @@ interface ContextErrorHandling {
67440
67445
  onError: ErrorHandlingMode;
67441
67446
  fallbacks?: ContextFallback[];
67442
67447
  }
67448
+ /** A single paused local tool call awaiting client execution. */
67449
+ interface LocalToolPausedState {
67450
+ toolName: string;
67451
+ executionId: string;
67452
+ parameters?: unknown;
67453
+ /** Set when a sub-agent raised the request on the parent it is parked on; the caller may not hold its handler. */
67454
+ subagent?: LocalToolSubagent;
67455
+ }
67456
+ /** The parent call a sub-agent's request is shown under; answering it on the parent forwards it to the child. */
67457
+ interface LocalToolSubagent {
67458
+ toolName: string;
67459
+ parentToolCallId: string;
67460
+ }
67443
67461
  /**
67444
67462
  * Options for the flow stream consumers.
67445
67463
  *
@@ -68199,6 +68217,12 @@ interface FlowSummary {
68199
68217
  results: Map<string, any>;
68200
68218
  /** Whether the flow completed successfully */
68201
68219
  success: boolean;
68220
+ /** Set when the run stopped on sub-agent requests this caller registered no handler for; answer them on the parent. */
68221
+ paused?: {
68222
+ status: 'paused';
68223
+ executionId: string;
68224
+ pausedTools: LocalToolPausedState[];
68225
+ };
68202
68226
  }
68203
68227
  /**
68204
68228
  * Generic flow-step config for step types that do not yet have a typed SDK
package/dist/index.mjs CHANGED
@@ -221,7 +221,8 @@ function createFlowEventTranslator() {
221
221
  awaitedAt: data.awaitedAt,
222
222
  origin: data.origin,
223
223
  pageOrigin: data.pageOrigin,
224
- annotations: data.annotations
224
+ annotations: data.annotations,
225
+ subagent: data.subagent
225
226
  })];
226
227
  default: return [];
227
228
  }
@@ -869,7 +870,7 @@ var FlowResult = class {
869
870
  */
870
871
  async stream(callbacks = {}) {
871
872
  if (this.consumed && this.cachedSummary) {
872
- if (callbacks.onFlowComplete) callbacks.onFlowComplete({
873
+ if (callbacks.onFlowComplete && !this.cachedSummary.paused) callbacks.onFlowComplete({
873
874
  type: "flow_complete",
874
875
  flowId: this.cachedSummary.flowId,
875
876
  totalSteps: this.cachedSummary.totalSteps,
@@ -1806,6 +1807,13 @@ function createExternalTool(config) {
1806
1807
  };
1807
1808
  }
1808
1809
  // src/local-tool-pause.ts
1810
+ function subagentOf(value) {
1811
+ const subagent = value;
1812
+ return typeof subagent?.toolName === "string" && typeof subagent.parentToolCallId === "string" ? {
1813
+ toolName: subagent.toolName,
1814
+ parentToolCallId: subagent.parentToolCallId
1815
+ } : void 0;
1816
+ }
1809
1817
  /**
1810
1818
  * Fold a unified `await` event, or an SDK stable-callback `flow_await` /
1811
1819
  * `step_await`, into the per-tool paused-state map. Compatibility frames may
@@ -1826,10 +1834,12 @@ function collectLocalToolAwait(pausedTools, event) {
1826
1834
  const pending = pausedTools.get(PENDING_NAMELESS_KEY);
1827
1835
  if (pending) pausedTools.delete(PENDING_NAMELESS_KEY);
1828
1836
  const prev = pausedTools.get(name) ?? pending;
1837
+ const subagent = subagentOf(event.subagent) ?? prev?.subagent;
1829
1838
  pausedTools.set(name, {
1830
1839
  toolName: name,
1831
1840
  executionId: executionId ?? prev?.executionId ?? "",
1832
- parameters: event.parameters ?? prev?.parameters
1841
+ parameters: event.parameters ?? prev?.parameters,
1842
+ ...subagent ? { subagent } : {}
1833
1843
  });
1834
1844
  return;
1835
1845
  }
@@ -1852,6 +1862,55 @@ function resolveBatchExecutionId(pausedTools) {
1852
1862
  for (const tool of pausedTools) if (tool.executionId) return tool.executionId;
1853
1863
  return "";
1854
1864
  }
1865
+ /**
1866
+ * Splits a paused batch into the calls this caller runs and the sub-agent requests it holds no handler for.
1867
+ * Those are left paused on the parent for whoever watches it (an approver, a UI), never thrown as missing.
1868
+ */
1869
+ function partitionLocalToolBatch(pausedTools, hasHandler) {
1870
+ const leftToParent = pausedTools.filter((tool) => tool.subagent && !hasHandler(tool.toolName));
1871
+ return {
1872
+ runnable: pausedTools.filter((tool) => !leftToParent.includes(tool)),
1873
+ leftToParent
1874
+ };
1875
+ }
1876
+ /** The result a run returns when every remaining request belongs to a sub-agent this caller cannot answer. */
1877
+ function pausedOnSubagentEnvelope(executionId, leftToParent) {
1878
+ return {
1879
+ status: "paused",
1880
+ executionId,
1881
+ pausedTools: leftToParent
1882
+ };
1883
+ }
1884
+ /** A run's summary when it stopped on sub-agent requests this caller cannot answer, so every result getter reads it. */
1885
+ function pausedOnSubagentSummary(executionId, leftToParent) {
1886
+ return {
1887
+ flowId: "",
1888
+ flowName: "",
1889
+ totalSteps: 0,
1890
+ successfulSteps: 0,
1891
+ failedSteps: 0,
1892
+ executionTime: 0,
1893
+ results: /* @__PURE__ */ new Map(),
1894
+ success: true,
1895
+ paused: pausedOnSubagentEnvelope(executionId, leftToParent)
1896
+ };
1897
+ }
1898
+ /** The next batch with the sub-agent requests still held from an earlier cycle, each once. */
1899
+ function withCarriedRequests(carried, pausedTools) {
1900
+ const key = (tool) => `${tool.subagent?.parentToolCallId ?? ""}:${tool.toolName}`;
1901
+ const seen = new Set(pausedTools.map(key));
1902
+ return [...pausedTools, ...carried.filter((tool) => !seen.has(key(tool)))];
1903
+ }
1904
+ /** Whether a buffered envelope reached the run's end; one whose follow closed before a terminal frame did not. */
1905
+ function bufferedReachedTerminal(data) {
1906
+ if (typeof data !== "object" || data === null) return true;
1907
+ const { status, events } = data;
1908
+ if (status !== "failed" || !Array.isArray(events)) return true;
1909
+ return events.some((event) => {
1910
+ const type = event?.type;
1911
+ return type === "execution_complete" || type === "execution_error";
1912
+ });
1913
+ }
1855
1914
  // src/detached-reconnect.ts
1856
1915
  /**
1857
1916
  * Transparent reconnect for a DETACHED agent stream (ADR 0020 point 6;
@@ -10791,6 +10850,7 @@ var RuntypeFlowBuilder = class {
10791
10850
  };
10792
10851
  const processStep = async (response) => {
10793
10852
  if (isStreaming) {
10853
+ let reachedTerminal = false;
10794
10854
  const pausedTools = /* @__PURE__ */ new Map();
10795
10855
  const wrappedCallbacks = {
10796
10856
  ...callbacks,
@@ -10819,9 +10879,12 @@ var RuntypeFlowBuilder = class {
10819
10879
  wrappedCallbacks.onStepComplete?.(event.result, event);
10820
10880
  break;
10821
10881
  case "flow_complete":
10882
+ reachedTerminal = true;
10822
10883
  wrappedCallbacks.onFlowComplete?.(event);
10823
10884
  break;
10824
- case "flow_error": wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
10885
+ case "flow_error":
10886
+ reachedTerminal = true;
10887
+ wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
10825
10888
  }
10826
10889
  }
10827
10890
  } catch (e) {
@@ -10837,7 +10900,8 @@ var RuntypeFlowBuilder = class {
10837
10900
  };
10838
10901
  return {
10839
10902
  done: true,
10840
- result: accumulatedSummary
10903
+ result: accumulatedSummary,
10904
+ terminal: reachedTerminal
10841
10905
  };
10842
10906
  } else {
10843
10907
  const data = await response.json();
@@ -10860,10 +10924,15 @@ var RuntypeFlowBuilder = class {
10860
10924
  }
10861
10925
  return {
10862
10926
  done: true,
10863
- result: data
10927
+ result: data,
10928
+ terminal: bufferedReachedTerminal(data)
10864
10929
  };
10865
10930
  }
10866
10931
  };
10932
+ const pausedOnSubagent = (left) => {
10933
+ const summary = pausedOnSubagentSummary(resolveBatchExecutionId(left), left);
10934
+ return new FlowResult(new Response(JSON.stringify(summary.paused), { headers: { "content-type": "application/json" } }), summary);
10935
+ };
10867
10936
  let currentResponse;
10868
10937
  let carriedRelease = {};
10869
10938
  if (isStreaming) currentResponse = await client.dispatch(config);
@@ -10872,8 +10941,11 @@ var RuntypeFlowBuilder = class {
10872
10941
  carriedRelease = releaseFieldsOf(data);
10873
10942
  currentResponse = new Response(JSON.stringify(data), { headers: { "content-type": "application/json" } });
10874
10943
  }
10944
+ let carried = [];
10875
10945
  while (true) {
10876
- const { done, result } = await processStep(currentResponse);
10946
+ const { done, result, terminal } = await processStep(currentResponse);
10947
+ const pausedNow = result;
10948
+ if (carried.length > 0 && (done ? terminal === false : !(pausedNow.status === "paused" && pausedNow.pausedTools?.length))) return pausedOnSubagent(carried);
10877
10949
  if (done) {
10878
10950
  if (isStreaming) return new FlowResult(new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } }), result);
10879
10951
  return new FlowResult(new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } }));
@@ -10881,8 +10953,11 @@ var RuntypeFlowBuilder = class {
10881
10953
  const pausedResult = result;
10882
10954
  if (pausedResult.status === "paused" && pausedResult.pausedTools?.length) {
10883
10955
  const executionId = resolveBatchExecutionId(pausedResult.pausedTools);
10956
+ const { runnable, leftToParent } = partitionLocalToolBatch(withCarriedRequests(carried, pausedResult.pausedTools), (toolName) => Boolean(localTools[toolName]));
10957
+ if (runnable.length === 0) return pausedOnSubagent(leftToParent);
10958
+ carried = leftToParent;
10884
10959
  try {
10885
- const outputs = await Promise.all(pausedResult.pausedTools.map(async ({ toolName, parameters }) => {
10960
+ const outputs = await Promise.all(runnable.map(async ({ toolName, parameters }) => {
10886
10961
  if (!localTools[toolName]) throw new Error(`Local tool "${toolName}" required but not provided in localTools map`);
10887
10962
  try {
10888
10963
  return [toolName, await localTools[toolName](parameters)];
@@ -14754,7 +14829,7 @@ function transformQueryParams(params) {
14754
14829
  return result;
14755
14830
  }
14756
14831
  // src/version.ts
14757
- const SDK_VERSION = "11.19.0";
14832
+ const SDK_VERSION = "11.19.1";
14758
14833
  /**
14759
14834
  * Canonical client identity the API uses for attribution
14760
14835
  * (`detectActorSource` in apps/api/src/lib/audit-log.ts keys `'sdk'` off the
@@ -14771,6 +14846,14 @@ const RUNTYPE_CLIENT_KIND = "sdk";
14771
14846
  */
14772
14847
  const SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
14773
14848
  // src/client.ts
14849
+ /** The handler for a paused tool: its exact name first, then the webmcp:-stripped form, so no namespace shadows one. */
14850
+ function findLocalToolEntry(localTools, toolName) {
14851
+ const BARE_NAME_NAMESPACES = ["webmcp:"];
14852
+ const lookupCandidates = [toolName];
14853
+ for (const ns of BARE_NAME_NAMESPACES) if (toolName.startsWith(ns)) lookupCandidates.push(toolName.slice(ns.length));
14854
+ const matchedKey = lookupCandidates.find((key) => localTools[key]);
14855
+ return matchedKey ? localTools[matchedKey] : void 0;
14856
+ }
14774
14857
  function isObjectRecord(value) {
14775
14858
  return typeof value === "object" && value !== null;
14776
14859
  }
@@ -14899,6 +14982,7 @@ var RuntypeClient = class {
14899
14982
  };
14900
14983
  const processStep = async (response) => {
14901
14984
  if (isStreaming) {
14985
+ let reachedTerminal = false;
14902
14986
  const pausedTools = /* @__PURE__ */ new Map();
14903
14987
  const wrappedCallbacks = {
14904
14988
  ...callbacks,
@@ -14931,9 +15015,12 @@ var RuntypeClient = class {
14931
15015
  wrappedCallbacks.onStepComplete?.(event.result, event);
14932
15016
  break;
14933
15017
  case "flow_complete":
15018
+ reachedTerminal = true;
14934
15019
  wrappedCallbacks.onFlowComplete?.(event);
14935
15020
  break;
14936
- case "flow_error": wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
15021
+ case "flow_error":
15022
+ reachedTerminal = true;
15023
+ wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
14937
15024
  }
14938
15025
  }
14939
15026
  } catch (e) {
@@ -14949,7 +15036,8 @@ var RuntypeClient = class {
14949
15036
  };
14950
15037
  return {
14951
15038
  done: true,
14952
- result: summary
15039
+ result: summary,
15040
+ terminal: reachedTerminal
14953
15041
  };
14954
15042
  } else {
14955
15043
  const data = await response.json();
@@ -14972,10 +15060,16 @@ var RuntypeClient = class {
14972
15060
  }
14973
15061
  return {
14974
15062
  done: true,
14975
- result: data
15063
+ result: data,
15064
+ terminal: bufferedReachedTerminal(data)
14976
15065
  };
14977
15066
  }
14978
15067
  };
15068
+ const pausedOnSubagent = (left) => {
15069
+ const summary = pausedOnSubagentSummary(resolveBatchExecutionId(left), left);
15070
+ if (isStreaming) return summary;
15071
+ return new FlowResult(new Response(JSON.stringify(summary.paused), { headers: { "content-type": "application/json" } }), summary);
15072
+ };
14979
15073
  let currentResponse;
14980
15074
  let carriedRelease = {};
14981
15075
  if (isStreaming) currentResponse = await this.dispatch.executeStream(modifiedRequest);
@@ -14984,21 +15078,22 @@ var RuntypeClient = class {
14984
15078
  carriedRelease = releaseFieldsOf(data);
14985
15079
  currentResponse = new Response(JSON.stringify(data), { headers: { "content-type": "application/json" } });
14986
15080
  }
15081
+ let carried = [];
14987
15082
  while (true) {
14988
- const { done, result } = await processStep(currentResponse);
15083
+ const { done, result, terminal } = await processStep(currentResponse);
15084
+ if (carried.length > 0 && (done ? terminal === false : !isPausedLocalActionResult(result))) return pausedOnSubagent(carried);
14989
15085
  if (done) {
14990
15086
  if (isStreaming) return result;
14991
15087
  return new FlowResult(new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } }));
14992
15088
  }
14993
15089
  if (isPausedLocalActionResult(result)) {
14994
15090
  const executionId = resolveBatchExecutionId(result.pausedTools);
15091
+ const { runnable, leftToParent } = partitionLocalToolBatch(withCarriedRequests(carried, result.pausedTools), (toolName) => Boolean(findLocalToolEntry(localTools, toolName)));
15092
+ if (runnable.length === 0) return pausedOnSubagent(leftToParent);
15093
+ carried = leftToParent;
14995
15094
  try {
14996
- const outputs = await Promise.all(result.pausedTools.map(async ({ toolName, parameters }) => {
14997
- const BARE_NAME_NAMESPACES = ["webmcp:"];
14998
- const lookupCandidates = [toolName];
14999
- for (const ns of BARE_NAME_NAMESPACES) if (toolName.startsWith(ns)) lookupCandidates.push(toolName.slice(ns.length));
15000
- const matchedKey = lookupCandidates.find((key) => localTools[key]);
15001
- const toolEntry = matchedKey ? localTools[matchedKey] : void 0;
15095
+ const outputs = await Promise.all(runnable.map(async ({ toolName, parameters }) => {
15096
+ const toolEntry = findLocalToolEntry(localTools, toolName);
15002
15097
  if (!toolEntry) throw new Error(`Local tool "${toolName}" required but not provided in localTools map`);
15003
15098
  const handler = hasToolEntryShape(toolEntry) ? toolEntry.execute : toolEntry;
15004
15099
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@runtypelabs/sdk",
3
- "version": "11.19.0",
3
+ "version": "11.19.1",
4
4
  "type": "module",
5
5
  "description": "TypeScript SDK for the Runtype API with fluent methods. Use it to quickly realize AI products, agents, and workflows.",
6
6
  "main": "dist/index.cjs",
@@ -24,7 +24,7 @@
24
24
  ],
25
25
  "dependencies": {},
26
26
  "devDependencies": {
27
- "@runtypelabs/shared": "3.114.0",
27
+ "@runtypelabs/shared": "3.114.1",
28
28
  "openapi-typescript": "^7.13.0",
29
29
  "tsdown": "^0.23.2",
30
30
  "typescript": "^6.0.3",