@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.mjs
CHANGED
|
@@ -11,9 +11,12 @@ var __export = (target, all) => {
|
|
|
11
11
|
// src/stream-utils.ts
|
|
12
12
|
var stream_utils_exports = {};
|
|
13
13
|
__export(stream_utils_exports, {
|
|
14
|
+
flowErrorMessage: () => flowErrorMessage,
|
|
14
15
|
parseFinalBuffer: () => parseFinalBuffer,
|
|
15
16
|
parseSSEChunk: () => parseSSEChunk,
|
|
16
17
|
processStream: () => processStream,
|
|
18
|
+
stepDeltaText: () => stepDeltaText,
|
|
19
|
+
stepDisplayName: () => stepDisplayName,
|
|
17
20
|
streamEvents: () => streamEvents
|
|
18
21
|
});
|
|
19
22
|
function parseSSEChunk(chunk, buffer) {
|
|
@@ -134,7 +137,7 @@ async function processStream(response, callbacks = {}) {
|
|
|
134
137
|
try {
|
|
135
138
|
const event = JSON.parse(eventStr);
|
|
136
139
|
handleEvent(event, callbacks, results, flowSummary);
|
|
137
|
-
} catch
|
|
140
|
+
} catch {
|
|
138
141
|
console.warn("Failed to parse SSE event:", eventStr);
|
|
139
142
|
}
|
|
140
143
|
}
|
|
@@ -144,7 +147,7 @@ async function processStream(response, callbacks = {}) {
|
|
|
144
147
|
try {
|
|
145
148
|
const event = JSON.parse(finalEvent);
|
|
146
149
|
handleEvent(event, callbacks, results, flowSummary);
|
|
147
|
-
} catch
|
|
150
|
+
} catch {
|
|
148
151
|
}
|
|
149
152
|
}
|
|
150
153
|
} catch (error) {
|
|
@@ -166,6 +169,15 @@ async function processStream(response, callbacks = {}) {
|
|
|
166
169
|
success: flowSummary.success ?? true
|
|
167
170
|
};
|
|
168
171
|
}
|
|
172
|
+
function stepDeltaText(event) {
|
|
173
|
+
return event.text ?? event.delta ?? "";
|
|
174
|
+
}
|
|
175
|
+
function stepDisplayName(event) {
|
|
176
|
+
return event.name ?? event.stepName ?? "";
|
|
177
|
+
}
|
|
178
|
+
function flowErrorMessage(event) {
|
|
179
|
+
return typeof event.error === "string" ? event.error : JSON.stringify(event.error);
|
|
180
|
+
}
|
|
169
181
|
function handleEvent(event, callbacks, results, summary) {
|
|
170
182
|
switch (event.type) {
|
|
171
183
|
case "flow_start":
|
|
@@ -178,24 +190,26 @@ function handleEvent(event, callbacks, results, summary) {
|
|
|
178
190
|
callbacks.onStepStart?.(event);
|
|
179
191
|
break;
|
|
180
192
|
case "step_delta":
|
|
181
|
-
callbacks.onStepDelta?.(event
|
|
193
|
+
callbacks.onStepDelta?.(stepDeltaText(event), event);
|
|
182
194
|
break;
|
|
183
|
-
case "step_complete":
|
|
184
|
-
results.set(event
|
|
195
|
+
case "step_complete": {
|
|
196
|
+
results.set(stepDisplayName(event), event.result);
|
|
185
197
|
callbacks.onStepComplete?.(event.result, event);
|
|
186
198
|
break;
|
|
199
|
+
}
|
|
187
200
|
case "flow_complete":
|
|
188
201
|
summary.totalSteps = event.totalSteps;
|
|
189
202
|
summary.successfulSteps = event.successfulSteps;
|
|
190
203
|
summary.failedSteps = event.failedSteps;
|
|
191
204
|
summary.executionTime = event.executionTime;
|
|
192
|
-
summary.success = event.failedSteps === 0;
|
|
205
|
+
summary.success = event.success ?? (event.failedSteps ?? 0) === 0;
|
|
193
206
|
callbacks.onFlowComplete?.(event);
|
|
194
207
|
break;
|
|
195
|
-
case "flow_error":
|
|
208
|
+
case "flow_error": {
|
|
196
209
|
summary.success = false;
|
|
197
|
-
callbacks.onError?.(new Error(event
|
|
210
|
+
callbacks.onError?.(new Error(flowErrorMessage(event)));
|
|
198
211
|
break;
|
|
212
|
+
}
|
|
199
213
|
case "flow_await":
|
|
200
214
|
break;
|
|
201
215
|
case "step_await":
|
|
@@ -953,22 +967,24 @@ var RuntypeFlowBuilder = class {
|
|
|
953
967
|
onFlowComplete: (event) => callbacks?.onFlowComplete?.(event),
|
|
954
968
|
onError: (error) => callbacks?.onError?.(error)
|
|
955
969
|
};
|
|
956
|
-
const { streamEvents: streamEvents2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
|
|
970
|
+
const { streamEvents: streamEvents2, stepDeltaText: stepDeltaText2, stepDisplayName: stepDisplayName2, flowErrorMessage: flowErrorMessage2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
|
|
957
971
|
try {
|
|
958
972
|
for await (const event of streamEvents2(response)) {
|
|
959
973
|
const awaitEvent = event;
|
|
960
974
|
if (awaitEvent.type === "flow_await") {
|
|
975
|
+
const prev = pausedState;
|
|
961
976
|
pausedState = {
|
|
962
|
-
toolName: awaitEvent.toolName || "",
|
|
963
|
-
parameters: awaitEvent.parameters,
|
|
964
|
-
executionId: awaitEvent.executionId || ""
|
|
977
|
+
toolName: awaitEvent.toolName || prev?.toolName || "",
|
|
978
|
+
parameters: awaitEvent.parameters ?? prev?.parameters,
|
|
979
|
+
executionId: awaitEvent.executionId || prev?.executionId || ""
|
|
965
980
|
};
|
|
966
981
|
}
|
|
967
982
|
if (awaitEvent.type === "step_await") {
|
|
983
|
+
const prev = pausedState;
|
|
968
984
|
pausedState = {
|
|
969
|
-
toolName: awaitEvent.toolName || "",
|
|
970
|
-
parameters: awaitEvent.parameters,
|
|
971
|
-
executionId: awaitEvent.executionId || ""
|
|
985
|
+
toolName: awaitEvent.toolName || prev?.toolName || "",
|
|
986
|
+
parameters: awaitEvent.parameters ?? prev?.parameters,
|
|
987
|
+
executionId: awaitEvent.executionId || prev?.executionId || ""
|
|
972
988
|
};
|
|
973
989
|
}
|
|
974
990
|
switch (event.type) {
|
|
@@ -979,10 +995,10 @@ var RuntypeFlowBuilder = class {
|
|
|
979
995
|
wrappedCallbacks.onStepStart?.(event);
|
|
980
996
|
break;
|
|
981
997
|
case "step_delta":
|
|
982
|
-
wrappedCallbacks.onStepDelta?.(event
|
|
998
|
+
wrappedCallbacks.onStepDelta?.(stepDeltaText2(event), event);
|
|
983
999
|
break;
|
|
984
1000
|
case "step_complete": {
|
|
985
|
-
accumulatedSummary.results?.set(event
|
|
1001
|
+
accumulatedSummary.results?.set(stepDisplayName2(event), event.result);
|
|
986
1002
|
wrappedCallbacks.onStepComplete?.(event.result, event);
|
|
987
1003
|
break;
|
|
988
1004
|
}
|
|
@@ -990,7 +1006,7 @@ var RuntypeFlowBuilder = class {
|
|
|
990
1006
|
wrappedCallbacks.onFlowComplete?.(event);
|
|
991
1007
|
break;
|
|
992
1008
|
case "flow_error":
|
|
993
|
-
wrappedCallbacks.onError?.(new Error(event
|
|
1009
|
+
wrappedCallbacks.onError?.(new Error(flowErrorMessage2(event)));
|
|
994
1010
|
break;
|
|
995
1011
|
}
|
|
996
1012
|
}
|
|
@@ -8211,7 +8227,7 @@ var RuntypeClient2 = class {
|
|
|
8211
8227
|
onFlowComplete: (event) => callbacks?.onFlowComplete?.(event),
|
|
8212
8228
|
onError: (error) => callbacks?.onError?.(error)
|
|
8213
8229
|
};
|
|
8214
|
-
const { streamEvents: streamEvents2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
|
|
8230
|
+
const { streamEvents: streamEvents2, stepDeltaText: stepDeltaText2, stepDisplayName: stepDisplayName2, flowErrorMessage: flowErrorMessage2 } = await Promise.resolve().then(() => (init_stream_utils(), stream_utils_exports));
|
|
8215
8231
|
const summary = {
|
|
8216
8232
|
results: /* @__PURE__ */ new Map(),
|
|
8217
8233
|
success: true
|
|
@@ -8220,19 +8236,23 @@ var RuntypeClient2 = class {
|
|
|
8220
8236
|
for await (const event of streamEvents2(response)) {
|
|
8221
8237
|
if (event.type === "flow_await") {
|
|
8222
8238
|
const pausedEvent = event;
|
|
8223
|
-
|
|
8224
|
-
|
|
8225
|
-
toolName: pausedEvent.toolName,
|
|
8226
|
-
executionId: pausedEvent.executionId
|
|
8239
|
+
const prev = pausedState;
|
|
8240
|
+
const next = {
|
|
8241
|
+
toolName: pausedEvent.toolName ?? prev?.toolName ?? "",
|
|
8242
|
+
executionId: pausedEvent.executionId ?? prev?.executionId ?? "",
|
|
8243
|
+
parameters: prev?.parameters
|
|
8227
8244
|
};
|
|
8245
|
+
pausedState = next;
|
|
8228
8246
|
}
|
|
8229
8247
|
if (event.type === "step_await") {
|
|
8230
8248
|
const pausedEvent = event;
|
|
8231
|
-
|
|
8232
|
-
|
|
8249
|
+
const prev = pausedState;
|
|
8250
|
+
const next = {
|
|
8251
|
+
toolName: typeof pausedEvent.toolName === "string" ? pausedEvent.toolName : prev?.toolName ?? "",
|
|
8233
8252
|
parameters: pausedEvent.parameters,
|
|
8234
|
-
executionId: pausedEvent.executionId
|
|
8253
|
+
executionId: typeof pausedEvent.executionId === "string" ? pausedEvent.executionId : prev?.executionId ?? ""
|
|
8235
8254
|
};
|
|
8255
|
+
pausedState = next;
|
|
8236
8256
|
}
|
|
8237
8257
|
switch (event.type) {
|
|
8238
8258
|
case "flow_start":
|
|
@@ -8242,10 +8262,10 @@ var RuntypeClient2 = class {
|
|
|
8242
8262
|
wrappedCallbacks.onStepStart?.(event);
|
|
8243
8263
|
break;
|
|
8244
8264
|
case "step_delta":
|
|
8245
|
-
wrappedCallbacks.onStepDelta?.(event
|
|
8265
|
+
wrappedCallbacks.onStepDelta?.(stepDeltaText2(event), event);
|
|
8246
8266
|
break;
|
|
8247
8267
|
case "step_complete": {
|
|
8248
|
-
summary.results?.set(event
|
|
8268
|
+
summary.results?.set(stepDisplayName2(event), event.result);
|
|
8249
8269
|
wrappedCallbacks.onStepComplete?.(event.result, event);
|
|
8250
8270
|
break;
|
|
8251
8271
|
}
|
|
@@ -8253,7 +8273,7 @@ var RuntypeClient2 = class {
|
|
|
8253
8273
|
wrappedCallbacks.onFlowComplete?.(event);
|
|
8254
8274
|
break;
|
|
8255
8275
|
case "flow_error":
|
|
8256
|
-
wrappedCallbacks.onError?.(new Error(event
|
|
8276
|
+
wrappedCallbacks.onError?.(new Error(flowErrorMessage2(event)));
|
|
8257
8277
|
break;
|
|
8258
8278
|
}
|
|
8259
8279
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@runtypelabs/sdk",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.0.0",
|
|
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,9 +24,10 @@
|
|
|
24
24
|
],
|
|
25
25
|
"dependencies": {},
|
|
26
26
|
"devDependencies": {
|
|
27
|
+
"openapi-typescript": "^7.13.0",
|
|
27
28
|
"tsup": "^8.0.2",
|
|
28
29
|
"typescript": "^5.3.3",
|
|
29
|
-
"vitest": "^4.0
|
|
30
|
+
"vitest": "^4.1.0"
|
|
30
31
|
},
|
|
31
32
|
"keywords": [
|
|
32
33
|
"runtype",
|
|
@@ -64,6 +65,8 @@
|
|
|
64
65
|
"typecheck": "tsc --noEmit",
|
|
65
66
|
"clean": "rm -rf dist",
|
|
66
67
|
"test": "vitest run",
|
|
67
|
-
"test:watch": "vitest watch"
|
|
68
|
+
"test:watch": "vitest watch",
|
|
69
|
+
"generate:types": "openapi-typescript ../../apps/api/openapi/public/v1/openapi.json -o src/generated/openapi-types.ts",
|
|
70
|
+
"generate:types:check": "pnpm run generate:types && git diff --exit-code src/generated/openapi-types.ts"
|
|
68
71
|
}
|
|
69
72
|
}
|