@runtypelabs/sdk 1.22.0 → 1.24.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 +92 -2
- package/dist/index.d.cts +1539 -1521
- package/dist/index.d.ts +1539 -1521
- package/dist/index.mjs +92 -2
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -397,6 +397,53 @@ var FlowResult = class {
|
|
|
397
397
|
};
|
|
398
398
|
|
|
399
399
|
// src/flows-namespace.ts
|
|
400
|
+
function isRecord(value) {
|
|
401
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
402
|
+
}
|
|
403
|
+
function normalizeConfig(config) {
|
|
404
|
+
if (!isRecord(config)) return {};
|
|
405
|
+
const normalized = {};
|
|
406
|
+
for (const key of Object.keys(config).sort()) {
|
|
407
|
+
const value = config[key];
|
|
408
|
+
if (value === void 0) continue;
|
|
409
|
+
if (value !== null && typeof value === "object" && !Array.isArray(value)) {
|
|
410
|
+
normalized[key] = normalizeConfig(value);
|
|
411
|
+
} else if (Array.isArray(value)) {
|
|
412
|
+
normalized[key] = value.map((item) => {
|
|
413
|
+
if (item !== null && typeof item === "object" && !Array.isArray(item)) {
|
|
414
|
+
return normalizeConfig(item);
|
|
415
|
+
}
|
|
416
|
+
return item;
|
|
417
|
+
});
|
|
418
|
+
} else {
|
|
419
|
+
normalized[key] = value;
|
|
420
|
+
}
|
|
421
|
+
}
|
|
422
|
+
return normalized;
|
|
423
|
+
}
|
|
424
|
+
function normalizeStepForHash(step) {
|
|
425
|
+
const stepObj = isRecord(step) ? step : {};
|
|
426
|
+
return {
|
|
427
|
+
type: typeof stepObj.type === "string" ? stepObj.type : "",
|
|
428
|
+
name: typeof stepObj.name === "string" ? stepObj.name : "",
|
|
429
|
+
enabled: stepObj.enabled !== false,
|
|
430
|
+
...typeof stepObj.when === "string" ? { when: stepObj.when } : {},
|
|
431
|
+
config: normalizeConfig(stepObj.config),
|
|
432
|
+
order: typeof stepObj.order === "number" ? stepObj.order : 0
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
async function computeFlowContentHash(steps) {
|
|
436
|
+
const normalized = [...steps].sort((a, b) => {
|
|
437
|
+
const orderA = isRecord(a) && typeof a.order === "number" ? a.order : 0;
|
|
438
|
+
const orderB = isRecord(b) && typeof b.order === "number" ? b.order : 0;
|
|
439
|
+
return orderA - orderB;
|
|
440
|
+
}).map(normalizeStepForHash);
|
|
441
|
+
const serialized = JSON.stringify(normalized);
|
|
442
|
+
const encoded = new TextEncoder().encode(serialized);
|
|
443
|
+
const hashBuffer = await crypto.subtle.digest("SHA-256", encoded);
|
|
444
|
+
const hashArray = new Uint8Array(hashBuffer);
|
|
445
|
+
return Array.from(hashArray).map((b) => b.toString(16).padStart(2, "0")).join("");
|
|
446
|
+
}
|
|
400
447
|
var FlowsNamespace = class {
|
|
401
448
|
constructor(getClient) {
|
|
402
449
|
this.getClient = getClient;
|
|
@@ -842,7 +889,7 @@ var RuntypeFlowBuilder = class {
|
|
|
842
889
|
}
|
|
843
890
|
config.options = { ...config.options, streamResponse: true };
|
|
844
891
|
const client = this.getClient();
|
|
845
|
-
const response = await
|
|
892
|
+
const response = await this.dispatchWithPersistedFlow(client, config);
|
|
846
893
|
const result = new FlowResult(response);
|
|
847
894
|
if (callbacks) {
|
|
848
895
|
await result.stream(callbacks);
|
|
@@ -871,7 +918,7 @@ var RuntypeFlowBuilder = class {
|
|
|
871
918
|
}
|
|
872
919
|
config.options = { ...config.options, streamResponse: true };
|
|
873
920
|
const client = this.getClient();
|
|
874
|
-
const response = await
|
|
921
|
+
const response = await this.dispatchWithPersistedFlow(client, config);
|
|
875
922
|
const result = new FlowResult(response);
|
|
876
923
|
await result.getSummary();
|
|
877
924
|
return result;
|
|
@@ -1055,6 +1102,37 @@ var RuntypeFlowBuilder = class {
|
|
|
1055
1102
|
// ============================================================================
|
|
1056
1103
|
// Private Helpers
|
|
1057
1104
|
// ============================================================================
|
|
1105
|
+
/**
|
|
1106
|
+
* Persisted flow protocol (APQ-style): send hash-only first, retry with
|
|
1107
|
+
* full definition on FLOW_DEFINITION_REQUIRED. For non-upsert modes,
|
|
1108
|
+
* dispatches directly.
|
|
1109
|
+
*/
|
|
1110
|
+
async dispatchWithPersistedFlow(client, config) {
|
|
1111
|
+
if (this.mode !== "upsert" || !this.steps.length) {
|
|
1112
|
+
return client.dispatch(config);
|
|
1113
|
+
}
|
|
1114
|
+
const contentHash = await this.computeContentHash();
|
|
1115
|
+
const hashOnlyConfig = {
|
|
1116
|
+
...config,
|
|
1117
|
+
flow: { name: config.flow.name, contentHash }
|
|
1118
|
+
};
|
|
1119
|
+
try {
|
|
1120
|
+
return await client.dispatch(hashOnlyConfig);
|
|
1121
|
+
} catch (err) {
|
|
1122
|
+
const message = err instanceof Error ? err.message : "";
|
|
1123
|
+
if (!message.includes("422")) {
|
|
1124
|
+
throw err;
|
|
1125
|
+
}
|
|
1126
|
+
}
|
|
1127
|
+
const fullConfig = {
|
|
1128
|
+
...config,
|
|
1129
|
+
flow: { ...config.flow, contentHash }
|
|
1130
|
+
};
|
|
1131
|
+
return client.dispatch(fullConfig);
|
|
1132
|
+
}
|
|
1133
|
+
async computeContentHash() {
|
|
1134
|
+
return computeFlowContentHash(this.steps);
|
|
1135
|
+
}
|
|
1058
1136
|
addStep(type, name, config, enabled = true) {
|
|
1059
1137
|
this.stepCounter++;
|
|
1060
1138
|
const cleanConfig = {};
|
|
@@ -3454,6 +3532,12 @@ var FlowsEndpoint = class {
|
|
|
3454
3532
|
async delete(id) {
|
|
3455
3533
|
return this.client.delete(`/flows/${id}`);
|
|
3456
3534
|
}
|
|
3535
|
+
/**
|
|
3536
|
+
* Export a flow as a self-contained runtime definition for @runtypelabs/runtime
|
|
3537
|
+
*/
|
|
3538
|
+
async exportRuntime(id) {
|
|
3539
|
+
return this.client.get(`/flows/${id}/export-runtime`);
|
|
3540
|
+
}
|
|
3457
3541
|
/**
|
|
3458
3542
|
* Run a flow on all records of a specific type
|
|
3459
3543
|
*/
|
|
@@ -4435,6 +4519,12 @@ var _AgentsEndpoint = class _AgentsEndpoint {
|
|
|
4435
4519
|
async delete(id) {
|
|
4436
4520
|
return this.client.delete(`/agents/${id}`);
|
|
4437
4521
|
}
|
|
4522
|
+
/**
|
|
4523
|
+
* Export an agent as a self-contained runtime definition for @runtypelabs/runtime
|
|
4524
|
+
*/
|
|
4525
|
+
async exportRuntime(id) {
|
|
4526
|
+
return this.client.get(`/agents/${id}/export-runtime`);
|
|
4527
|
+
}
|
|
4438
4528
|
/**
|
|
4439
4529
|
* Evaluate a model-proposed runtime tool against a configurable allowlist policy.
|
|
4440
4530
|
* Useful for local `propose_runtime_tool` handlers before follow-up execution.
|
package/package.json
CHANGED