@runtypelabs/sdk 2.2.0 → 3.0.0
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 +49 -29
- package/dist/index.d.cts +39564 -251
- package/dist/index.d.ts +39564 -251
- package/dist/index.mjs +49 -29
- package/package.json +6 -3
package/dist/index.cjs
CHANGED
|
@@ -23,9 +23,12 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
23
23
|
// src/stream-utils.ts
|
|
24
24
|
var stream_utils_exports = {};
|
|
25
25
|
__export(stream_utils_exports, {
|
|
26
|
+
flowErrorMessage: () => flowErrorMessage,
|
|
26
27
|
parseFinalBuffer: () => parseFinalBuffer,
|
|
27
28
|
parseSSEChunk: () => parseSSEChunk,
|
|
28
29
|
processStream: () => processStream,
|
|
30
|
+
stepDeltaText: () => stepDeltaText,
|
|
31
|
+
stepDisplayName: () => stepDisplayName,
|
|
29
32
|
streamEvents: () => streamEvents
|
|
30
33
|
});
|
|
31
34
|
function parseSSEChunk(chunk, buffer) {
|
|
@@ -146,7 +149,7 @@ async function processStream(response, callbacks = {}) {
|
|
|
146
149
|
try {
|
|
147
150
|
const event = JSON.parse(eventStr);
|
|
148
151
|
handleEvent(event, callbacks, results, flowSummary);
|
|
149
|
-
} catch
|
|
152
|
+
} catch {
|
|
150
153
|
console.warn("Failed to parse SSE event:", eventStr);
|
|
151
154
|
}
|
|
152
155
|
}
|
|
@@ -156,7 +159,7 @@ async function processStream(response, callbacks = {}) {
|
|
|
156
159
|
try {
|
|
157
160
|
const event = JSON.parse(finalEvent);
|
|
158
161
|
handleEvent(event, callbacks, results, flowSummary);
|
|
159
|
-
} catch
|
|
162
|
+
} catch {
|
|
160
163
|
}
|
|
161
164
|
}
|
|
162
165
|
} catch (error) {
|
|
@@ -178,6 +181,15 @@ async function processStream(response, callbacks = {}) {
|
|
|
178
181
|
success: flowSummary.success ?? true
|
|
179
182
|
};
|
|
180
183
|
}
|
|
184
|
+
function stepDeltaText(event) {
|
|
185
|
+
return event.text ?? event.delta ?? "";
|
|
186
|
+
}
|
|
187
|
+
function stepDisplayName(event) {
|
|
188
|
+
return event.name ?? event.stepName ?? "";
|
|
189
|
+
}
|
|
190
|
+
function flowErrorMessage(event) {
|
|
191
|
+
return typeof event.error === "string" ? event.error : JSON.stringify(event.error);
|
|
192
|
+
}
|
|
181
193
|
function handleEvent(event, callbacks, results, summary) {
|
|
182
194
|
switch (event.type) {
|
|
183
195
|
case "flow_start":
|
|
@@ -190,24 +202,26 @@ function handleEvent(event, callbacks, results, summary) {
|
|
|
190
202
|
callbacks.onStepStart?.(event);
|
|
191
203
|
break;
|
|
192
204
|
case "step_delta":
|
|
193
|
-
callbacks.onStepDelta?.(event
|
|
205
|
+
callbacks.onStepDelta?.(stepDeltaText(event), event);
|
|
194
206
|
break;
|
|
195
|
-
case "step_complete":
|
|
196
|
-
results.set(event
|
|
207
|
+
case "step_complete": {
|
|
208
|
+
results.set(stepDisplayName(event), event.result);
|
|
197
209
|
callbacks.onStepComplete?.(event.result, event);
|
|
198
210
|
break;
|
|
211
|
+
}
|
|
199
212
|
case "flow_complete":
|
|
200
213
|
summary.totalSteps = event.totalSteps;
|
|
201
214
|
summary.successfulSteps = event.successfulSteps;
|
|
202
215
|
summary.failedSteps = event.failedSteps;
|
|
203
216
|
summary.executionTime = event.executionTime;
|
|
204
|
-
summary.success = event.failedSteps === 0;
|
|
217
|
+
summary.success = event.success ?? (event.failedSteps ?? 0) === 0;
|
|
205
218
|
callbacks.onFlowComplete?.(event);
|
|
206
219
|
break;
|
|
207
|
-
case "flow_error":
|
|
220
|
+
case "flow_error": {
|
|
208
221
|
summary.success = false;
|
|
209
|
-
callbacks.onError?.(new Error(event
|
|
222
|
+
callbacks.onError?.(new Error(flowErrorMessage(event)));
|
|
210
223
|
break;
|
|
224
|
+
}
|
|
211
225
|
case "flow_await":
|
|
212
226
|
break;
|
|
213
227
|
case "step_await":
|
|
@@ -1034,22 +1048,24 @@ var RuntypeFlowBuilder = class {
|
|
|
1034
1048
|
onFlowComplete: (event) => callbacks?.onFlowComplete?.(event),
|
|
1035
1049
|
onError: (error) => callbacks?.onError?.(error)
|
|
1036
1050
|
};
|
|
1037
|
-
const { streamEvents: streamEvents2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
|
|
1051
|
+
const { streamEvents: streamEvents2, stepDeltaText: stepDeltaText2, stepDisplayName: stepDisplayName2, flowErrorMessage: flowErrorMessage2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
|
|
1038
1052
|
try {
|
|
1039
1053
|
for await (const event of streamEvents2(response)) {
|
|
1040
1054
|
const awaitEvent = event;
|
|
1041
1055
|
if (awaitEvent.type === "flow_await") {
|
|
1056
|
+
const prev = pausedState;
|
|
1042
1057
|
pausedState = {
|
|
1043
|
-
toolName: awaitEvent.toolName || "",
|
|
1044
|
-
parameters: awaitEvent.parameters,
|
|
1045
|
-
executionId: awaitEvent.executionId || ""
|
|
1058
|
+
toolName: awaitEvent.toolName || prev?.toolName || "",
|
|
1059
|
+
parameters: awaitEvent.parameters ?? prev?.parameters,
|
|
1060
|
+
executionId: awaitEvent.executionId || prev?.executionId || ""
|
|
1046
1061
|
};
|
|
1047
1062
|
}
|
|
1048
1063
|
if (awaitEvent.type === "step_await") {
|
|
1064
|
+
const prev = pausedState;
|
|
1049
1065
|
pausedState = {
|
|
1050
|
-
toolName: awaitEvent.toolName || "",
|
|
1051
|
-
parameters: awaitEvent.parameters,
|
|
1052
|
-
executionId: awaitEvent.executionId || ""
|
|
1066
|
+
toolName: awaitEvent.toolName || prev?.toolName || "",
|
|
1067
|
+
parameters: awaitEvent.parameters ?? prev?.parameters,
|
|
1068
|
+
executionId: awaitEvent.executionId || prev?.executionId || ""
|
|
1053
1069
|
};
|
|
1054
1070
|
}
|
|
1055
1071
|
switch (event.type) {
|
|
@@ -1060,10 +1076,10 @@ var RuntypeFlowBuilder = class {
|
|
|
1060
1076
|
wrappedCallbacks.onStepStart?.(event);
|
|
1061
1077
|
break;
|
|
1062
1078
|
case "step_delta":
|
|
1063
|
-
wrappedCallbacks.onStepDelta?.(event
|
|
1079
|
+
wrappedCallbacks.onStepDelta?.(stepDeltaText2(event), event);
|
|
1064
1080
|
break;
|
|
1065
1081
|
case "step_complete": {
|
|
1066
|
-
accumulatedSummary.results?.set(event
|
|
1082
|
+
accumulatedSummary.results?.set(stepDisplayName2(event), event.result);
|
|
1067
1083
|
wrappedCallbacks.onStepComplete?.(event.result, event);
|
|
1068
1084
|
break;
|
|
1069
1085
|
}
|
|
@@ -1071,7 +1087,7 @@ var RuntypeFlowBuilder = class {
|
|
|
1071
1087
|
wrappedCallbacks.onFlowComplete?.(event);
|
|
1072
1088
|
break;
|
|
1073
1089
|
case "flow_error":
|
|
1074
|
-
wrappedCallbacks.onError?.(new Error(event
|
|
1090
|
+
wrappedCallbacks.onError?.(new Error(flowErrorMessage2(event)));
|
|
1075
1091
|
break;
|
|
1076
1092
|
}
|
|
1077
1093
|
}
|
|
@@ -8292,7 +8308,7 @@ var RuntypeClient2 = class {
|
|
|
8292
8308
|
onFlowComplete: (event) => callbacks?.onFlowComplete?.(event),
|
|
8293
8309
|
onError: (error) => callbacks?.onError?.(error)
|
|
8294
8310
|
};
|
|
8295
|
-
const { streamEvents: streamEvents2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
|
|
8311
|
+
const { streamEvents: streamEvents2, stepDeltaText: stepDeltaText2, stepDisplayName: stepDisplayName2, flowErrorMessage: flowErrorMessage2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
|
|
8296
8312
|
const summary = {
|
|
8297
8313
|
results: /* @__PURE__ */ new Map(),
|
|
8298
8314
|
success: true
|
|
@@ -8301,19 +8317,23 @@ var RuntypeClient2 = class {
|
|
|
8301
8317
|
for await (const event of streamEvents2(response)) {
|
|
8302
8318
|
if (event.type === "flow_await") {
|
|
8303
8319
|
const pausedEvent = event;
|
|
8304
|
-
|
|
8305
|
-
|
|
8306
|
-
toolName: pausedEvent.toolName,
|
|
8307
|
-
executionId: pausedEvent.executionId
|
|
8320
|
+
const prev = pausedState;
|
|
8321
|
+
const next = {
|
|
8322
|
+
toolName: pausedEvent.toolName ?? prev?.toolName ?? "",
|
|
8323
|
+
executionId: pausedEvent.executionId ?? prev?.executionId ?? "",
|
|
8324
|
+
parameters: prev?.parameters
|
|
8308
8325
|
};
|
|
8326
|
+
pausedState = next;
|
|
8309
8327
|
}
|
|
8310
8328
|
if (event.type === "step_await") {
|
|
8311
8329
|
const pausedEvent = event;
|
|
8312
|
-
|
|
8313
|
-
|
|
8330
|
+
const prev = pausedState;
|
|
8331
|
+
const next = {
|
|
8332
|
+
toolName: typeof pausedEvent.toolName === "string" ? pausedEvent.toolName : prev?.toolName ?? "",
|
|
8314
8333
|
parameters: pausedEvent.parameters,
|
|
8315
|
-
executionId: pausedEvent.executionId
|
|
8334
|
+
executionId: typeof pausedEvent.executionId === "string" ? pausedEvent.executionId : prev?.executionId ?? ""
|
|
8316
8335
|
};
|
|
8336
|
+
pausedState = next;
|
|
8317
8337
|
}
|
|
8318
8338
|
switch (event.type) {
|
|
8319
8339
|
case "flow_start":
|
|
@@ -8323,10 +8343,10 @@ var RuntypeClient2 = class {
|
|
|
8323
8343
|
wrappedCallbacks.onStepStart?.(event);
|
|
8324
8344
|
break;
|
|
8325
8345
|
case "step_delta":
|
|
8326
|
-
wrappedCallbacks.onStepDelta?.(event
|
|
8346
|
+
wrappedCallbacks.onStepDelta?.(stepDeltaText2(event), event);
|
|
8327
8347
|
break;
|
|
8328
8348
|
case "step_complete": {
|
|
8329
|
-
summary.results?.set(event
|
|
8349
|
+
summary.results?.set(stepDisplayName2(event), event.result);
|
|
8330
8350
|
wrappedCallbacks.onStepComplete?.(event.result, event);
|
|
8331
8351
|
break;
|
|
8332
8352
|
}
|
|
@@ -8334,7 +8354,7 @@ var RuntypeClient2 = class {
|
|
|
8334
8354
|
wrappedCallbacks.onFlowComplete?.(event);
|
|
8335
8355
|
break;
|
|
8336
8356
|
case "flow_error":
|
|
8337
|
-
wrappedCallbacks.onError?.(new Error(event
|
|
8357
|
+
wrappedCallbacks.onError?.(new Error(flowErrorMessage2(event)));
|
|
8338
8358
|
break;
|
|
8339
8359
|
}
|
|
8340
8360
|
}
|