@runtypelabs/sdk 11.18.2 → 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 +123 -22
- package/dist/index.d.cts +67 -363
- package/dist/index.d.ts +67 -363
- package/dist/index.mjs +123 -22
- package/package.json +2 -2
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":
|
|
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(
|
|
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)];
|
|
@@ -14703,9 +14778,15 @@ var SimulationsEndpoint = class {
|
|
|
14703
14778
|
async previewVariant(simulationId, variantId, data) {
|
|
14704
14779
|
return this.client.post(`/simulations/${segment(simulationId)}/variants/${segment(variantId)}/preview`, data);
|
|
14705
14780
|
}
|
|
14706
|
-
/**
|
|
14707
|
-
|
|
14708
|
-
|
|
14781
|
+
/**
|
|
14782
|
+
* Discard a run variant's frozen synthesized answers so its next run synthesizes again; `tools` limits it to those
|
|
14783
|
+
* server tools' answers.
|
|
14784
|
+
*/
|
|
14785
|
+
async resynthesizeVariant(runId, variantId, options) {
|
|
14786
|
+
const query = new URLSearchParams();
|
|
14787
|
+
for (const tool of options?.tools ?? []) query.append("tools", tool);
|
|
14788
|
+
const search = query.toString() ? `?${query.toString()}` : "";
|
|
14789
|
+
return this.client.post(`/simulations/runs/${segment(runId)}/variants/${segment(variantId)}/resynthesize${search}`);
|
|
14709
14790
|
}
|
|
14710
14791
|
/** Mark a synthesized answer plausible or implausible; `null` clears the review. */
|
|
14711
14792
|
async reviewSynthesizedAnswer(runId, exchangeId, plausible) {
|
|
@@ -14749,7 +14830,7 @@ function transformQueryParams(params) {
|
|
|
14749
14830
|
return result;
|
|
14750
14831
|
}
|
|
14751
14832
|
// src/version.ts
|
|
14752
|
-
const SDK_VERSION = "11.
|
|
14833
|
+
const SDK_VERSION = "11.19.1";
|
|
14753
14834
|
/**
|
|
14754
14835
|
* Canonical client identity the API uses for attribution
|
|
14755
14836
|
* (`detectActorSource` in apps/api/src/lib/audit-log.ts keys `'sdk'` off the
|
|
@@ -14766,6 +14847,14 @@ const RUNTYPE_CLIENT_KIND = "sdk";
|
|
|
14766
14847
|
*/
|
|
14767
14848
|
const SDK_USER_AGENT = `runtype-sdk/${SDK_VERSION} (typescript)`;
|
|
14768
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
|
+
}
|
|
14769
14858
|
function isObjectRecord(value) {
|
|
14770
14859
|
return typeof value === "object" && value !== null;
|
|
14771
14860
|
}
|
|
@@ -14894,6 +14983,7 @@ var RuntypeClient = class {
|
|
|
14894
14983
|
};
|
|
14895
14984
|
const processStep = async (response) => {
|
|
14896
14985
|
if (isStreaming) {
|
|
14986
|
+
let reachedTerminal = false;
|
|
14897
14987
|
const pausedTools = /* @__PURE__ */ new Map();
|
|
14898
14988
|
const wrappedCallbacks = {
|
|
14899
14989
|
...callbacks,
|
|
@@ -14926,9 +15016,12 @@ var RuntypeClient = class {
|
|
|
14926
15016
|
wrappedCallbacks.onStepComplete?.(event.result, event);
|
|
14927
15017
|
break;
|
|
14928
15018
|
case "flow_complete":
|
|
15019
|
+
reachedTerminal = true;
|
|
14929
15020
|
wrappedCallbacks.onFlowComplete?.(event);
|
|
14930
15021
|
break;
|
|
14931
|
-
case "flow_error":
|
|
15022
|
+
case "flow_error":
|
|
15023
|
+
reachedTerminal = true;
|
|
15024
|
+
wrappedCallbacks.onError?.(new Error(flowErrorMessage(event)));
|
|
14932
15025
|
}
|
|
14933
15026
|
}
|
|
14934
15027
|
} catch (e) {
|
|
@@ -14944,7 +15037,8 @@ var RuntypeClient = class {
|
|
|
14944
15037
|
};
|
|
14945
15038
|
return {
|
|
14946
15039
|
done: true,
|
|
14947
|
-
result: summary
|
|
15040
|
+
result: summary,
|
|
15041
|
+
terminal: reachedTerminal
|
|
14948
15042
|
};
|
|
14949
15043
|
} else {
|
|
14950
15044
|
const data = await response.json();
|
|
@@ -14967,10 +15061,16 @@ var RuntypeClient = class {
|
|
|
14967
15061
|
}
|
|
14968
15062
|
return {
|
|
14969
15063
|
done: true,
|
|
14970
|
-
result: data
|
|
15064
|
+
result: data,
|
|
15065
|
+
terminal: bufferedReachedTerminal(data)
|
|
14971
15066
|
};
|
|
14972
15067
|
}
|
|
14973
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
|
+
};
|
|
14974
15074
|
let currentResponse;
|
|
14975
15075
|
let carriedRelease = {};
|
|
14976
15076
|
if (isStreaming) currentResponse = await this.dispatch.executeStream(modifiedRequest);
|
|
@@ -14979,21 +15079,22 @@ var RuntypeClient = class {
|
|
|
14979
15079
|
carriedRelease = releaseFieldsOf(data);
|
|
14980
15080
|
currentResponse = new Response(JSON.stringify(data), { headers: { "content-type": "application/json" } });
|
|
14981
15081
|
}
|
|
15082
|
+
let carried = [];
|
|
14982
15083
|
while (true) {
|
|
14983
|
-
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);
|
|
14984
15086
|
if (done) {
|
|
14985
15087
|
if (isStreaming) return result;
|
|
14986
15088
|
return new FlowResult(new Response(JSON.stringify(result), { headers: { "content-type": "application/json" } }));
|
|
14987
15089
|
}
|
|
14988
15090
|
if (isPausedLocalActionResult(result)) {
|
|
14989
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;
|
|
14990
15095
|
try {
|
|
14991
|
-
const outputs = await Promise.all(
|
|
14992
|
-
const
|
|
14993
|
-
const lookupCandidates = [toolName];
|
|
14994
|
-
for (const ns of BARE_NAME_NAMESPACES) if (toolName.startsWith(ns)) lookupCandidates.push(toolName.slice(ns.length));
|
|
14995
|
-
const matchedKey = lookupCandidates.find((key) => localTools[key]);
|
|
14996
|
-
const toolEntry = matchedKey ? localTools[matchedKey] : void 0;
|
|
15096
|
+
const outputs = await Promise.all(runnable.map(async ({ toolName, parameters }) => {
|
|
15097
|
+
const toolEntry = findLocalToolEntry(localTools, toolName);
|
|
14997
15098
|
if (!toolEntry) throw new Error(`Local tool "${toolName}" required but not provided in localTools map`);
|
|
14998
15099
|
const handler = hasToolEntryShape(toolEntry) ? toolEntry.execute : toolEntry;
|
|
14999
15100
|
try {
|