@statelyai/agent 2.0.0-alpha.33 → 2.0.0-alpha.35
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/CHANGELOG.md +45 -0
- package/dist/ai-sdk.cjs +114 -63
- package/dist/ai-sdk.d.cts +11 -2
- package/dist/ai-sdk.d.mts +11 -2
- package/dist/ai-sdk.mjs +115 -64
- package/dist/{decision-BPdEaxPf.cjs → decision-BEsATcr1.cjs} +18 -2
- package/dist/{decision-CV7WiV5C.mjs → decision-COkJNjOW.mjs} +18 -2
- package/dist/{event-log-CKWeC7H-.cjs → event-log-BWSSLUff.cjs} +139 -10
- package/dist/{event-log-DAqsalT1.mjs → event-log-C7jeH0y8.mjs} +123 -12
- package/dist/{event-log-store-C2NjVlWU.d.mts → event-log-store-BzXehP7R.d.cts} +28 -3
- package/dist/{event-log-store-s73r1Hxf.d.cts → event-log-store-CWjN6lmM.d.mts} +28 -3
- package/dist/{event-log-store-DKyE7JKr.cjs → event-log-store-CleWpsp5.cjs} +1 -1
- package/dist/{event-log-store-BGehvVTb.mjs → event-log-store-W49TCJXi.mjs} +1 -1
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +7 -7
- package/dist/index.d.mts +7 -7
- package/dist/index.mjs +5 -5
- package/dist/log.cjs +2 -2
- package/dist/log.d.cts +1 -1
- package/dist/log.d.mts +1 -1
- package/dist/log.mjs +2 -2
- package/dist/machines.cjs +1 -1
- package/dist/machines.mjs +1 -1
- package/dist/{model-source-BilDEyqk.mjs → model-source-CK3F4YuU.mjs} +1 -1
- package/dist/{model-source-BQ97_l1-.cjs → model-source-DmhTMK39.cjs} +1 -1
- package/dist/openai.cjs +377 -95
- package/dist/openai.d.cts +55 -20
- package/dist/openai.d.mts +55 -20
- package/dist/openai.mjs +375 -96
- package/dist/otel.d.cts +1 -1
- package/dist/otel.d.mts +1 -1
- package/dist/{run-agent-B5QhabdY.d.cts → run-agent-B1-Eqviq.d.cts} +13 -5
- package/dist/{run-agent-Atu-wEk7.d.mts → run-agent-BGdx5913.d.mts} +13 -5
- package/dist/{run-agent-2UnSUhDb.mjs → run-agent-Ct_GZw_f.mjs} +124 -38
- package/dist/{run-agent-Cg0xd3K-.cjs → run-agent-s5D32w99.cjs} +123 -37
- package/dist/{setup-agent-CmhB-U5P.mjs → setup-agent-05uw4dPZ.mjs} +2 -2
- package/dist/{setup-agent-BiF1N3td.d.cts → setup-agent-BtfeFfF6.d.cts} +2 -2
- package/dist/{setup-agent-J9f_Wu5T.d.mts → setup-agent-C6nqzv_X.d.mts} +2 -2
- package/dist/{setup-agent-CwUJyqKB.cjs → setup-agent-CXEBURdo.cjs} +2 -2
- package/dist/tanstack-ai.cjs +91 -59
- package/dist/tanstack-ai.d.cts +13 -2
- package/dist/tanstack-ai.d.mts +13 -2
- package/dist/tanstack-ai.mjs +91 -59
- package/dist/testing.cjs +629 -13
- package/dist/testing.d.cts +278 -6
- package/dist/testing.d.mts +278 -6
- package/dist/testing.mjs +626 -14
- package/dist/{text-logic-CYP502VT.d.cts → text-logic-CV_4KGr6.d.cts} +28 -3
- package/dist/{text-logic-DuK9HIFM.d.mts → text-logic-Ckh-rJFV.d.mts} +28 -3
- package/dist/{usage-D7JKAxLc.d.mts → usage-BDiJKyv9.d.cts} +11 -1
- package/dist/{usage-DVw-646x.d.cts → usage-DOoVUGVq.d.mts} +11 -1
- package/dist/validate.cjs +3 -3
- package/dist/validate.d.cts +2 -2
- package/dist/validate.d.mts +2 -2
- package/dist/validate.mjs +3 -3
- package/dist/{verify-Dk3Vwnha.d.cts → verify-BQpE8hUz.d.cts} +1 -1
- package/dist/{verify-DgB8P-Wx.mjs → verify-Bpahmr34.mjs} +2 -2
- package/dist/{verify-BVz4cURF.d.mts → verify-CqeuEmIk.d.mts} +1 -1
- package/dist/{verify-CS_WLRXn.cjs → verify-DCLZa9R0.cjs} +2 -2
- package/dist/with-model-calls-BXYdBdcu.cjs +45 -0
- package/dist/with-model-calls-Bv4V4EHC.mjs +34 -0
- package/package.json +5 -5
- package/readme.md +14 -13
- package/skills/loop-to-machine/SKILL.md +42 -2
package/dist/testing.cjs
CHANGED
|
@@ -1,14 +1,15 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_event_log = require("./event-log-
|
|
3
|
-
const require_run_agent = require("./run-agent-
|
|
4
|
-
const require_verify = require("./verify-
|
|
2
|
+
const require_event_log = require("./event-log-BWSSLUff.cjs");
|
|
3
|
+
const require_run_agent = require("./run-agent-s5D32w99.cjs");
|
|
4
|
+
const require_verify = require("./verify-DCLZa9R0.cjs");
|
|
5
|
+
let xstate = require("xstate");
|
|
5
6
|
//#region src/trajectory.ts
|
|
6
7
|
/**
|
|
7
8
|
* Classifies one item. Event-shaped things (log entries, events) become events;
|
|
8
9
|
* everything else is a state value. A snapshot is unwrapped to its `value`.
|
|
9
10
|
* @internal
|
|
10
11
|
*/
|
|
11
|
-
function normalize(item) {
|
|
12
|
+
function normalize$1(item) {
|
|
12
13
|
if (require_event_log.isRecord(item)) {
|
|
13
14
|
const nested = item["event"];
|
|
14
15
|
if (require_event_log.isRecord(nested) && typeof nested["type"] === "string") return {
|
|
@@ -61,17 +62,17 @@ function deepEqual(a, b) {
|
|
|
61
62
|
*/
|
|
62
63
|
function matcherFor(expected) {
|
|
63
64
|
if (typeof expected === "string") return (actual) => {
|
|
64
|
-
const actualItem = normalize(actual);
|
|
65
|
+
const actualItem = normalize$1(actual);
|
|
65
66
|
return actualItem.kind === "event" ? actualItem.event.type === expected : stateMatchesPath(expected, actualItem.value);
|
|
66
67
|
};
|
|
67
|
-
const expectedItem = normalize(expected);
|
|
68
|
+
const expectedItem = normalize$1(expected);
|
|
68
69
|
switch (expectedItem.kind) {
|
|
69
70
|
case "event": return (actual) => {
|
|
70
|
-
const actualItem = normalize(actual);
|
|
71
|
+
const actualItem = normalize$1(actual);
|
|
71
72
|
return actualItem.kind === "event" && Object.keys(expectedItem.event).every((key) => deepEqual(expectedItem.event[key], actualItem.event[key]));
|
|
72
73
|
};
|
|
73
74
|
case "state": return (actual) => {
|
|
74
|
-
const actualItem = normalize(actual);
|
|
75
|
+
const actualItem = normalize$1(actual);
|
|
75
76
|
return actualItem.kind === "state" && deepEqual(expectedItem.value, actualItem.value);
|
|
76
77
|
};
|
|
77
78
|
}
|
|
@@ -384,7 +385,7 @@ function statePaths(value, prefix = "") {
|
|
|
384
385
|
/**
|
|
385
386
|
* A trace's `machine.transition` events as steps, skipping `@xstate.init`.
|
|
386
387
|
* A first-attempt decision's `request.start` names the decision on the step
|
|
387
|
-
* that follows it. Reads live and serialized traces alike.
|
|
388
|
+
* that follows it, skipping `@agent.usage` steps. Reads live and serialized traces alike.
|
|
388
389
|
* @internal
|
|
389
390
|
*/
|
|
390
391
|
function traceSteps(trace) {
|
|
@@ -409,9 +410,9 @@ function traceSteps(trace) {
|
|
|
409
410
|
to: statePaths(toValue),
|
|
410
411
|
toValue,
|
|
411
412
|
ignored: event.ignored === true,
|
|
412
|
-
...decision === void 0 ? {} : { decision }
|
|
413
|
+
...decision === void 0 || type === "@agent.usage" ? {} : { decision }
|
|
413
414
|
});
|
|
414
|
-
decision = void 0;
|
|
415
|
+
if (type !== "@agent.usage") decision = void 0;
|
|
415
416
|
}
|
|
416
417
|
return steps;
|
|
417
418
|
}
|
|
@@ -521,6 +522,37 @@ function candidateAt(node, type, event) {
|
|
|
521
522
|
return keys.find((key) => node.transitions.get(key).some((d) => matchesPattern(d, event)));
|
|
522
523
|
}
|
|
523
524
|
const pathOf = (node) => node.path.join(".");
|
|
525
|
+
const sameLeaves = (a, b) => statePaths(a).sort().join("|") === statePaths(b).sort().join("|");
|
|
526
|
+
/**
|
|
527
|
+
* The leaves a trace passed through inside its macrosteps: states an `always`
|
|
528
|
+
* transition left before the step ended, which no traced snapshot holds.
|
|
529
|
+
* Re-derived with XState's pure `getMicrosteps` from the snapshot before each
|
|
530
|
+
* step (the previous step's, or the fresh start's microsteps from its input).
|
|
531
|
+
* A step that cannot be recomputed, or whose recomputation ends elsewhere
|
|
532
|
+
* than the traced snapshot, adds none. Only `value` and `context` are rebuilt,
|
|
533
|
+
* so a guard that reads live children can take another route to the same
|
|
534
|
+
* leaves, and that route is credited.
|
|
535
|
+
*/
|
|
536
|
+
function passedThrough(machine, trace) {
|
|
537
|
+
const leaves = /* @__PURE__ */ new Set();
|
|
538
|
+
let resumed = false;
|
|
539
|
+
let previous;
|
|
540
|
+
for (const event of trace) {
|
|
541
|
+
if (event.type === "run.start") resumed = event.snapshot !== void 0;
|
|
542
|
+
if (event.type !== "machine.transition" || !require_event_log.isRecord(event.event)) continue;
|
|
543
|
+
const snapshot = require_event_log.isRecord(event.snapshot) ? event.snapshot : void 0;
|
|
544
|
+
try {
|
|
545
|
+
const microsteps = event.event.type === "@xstate.init" ? resumed ? [] : (0, xstate.getInitialMicrosteps)(machine, event.event.input) : previous && sameLeaves(previous.value, valueOf(event.from)) ? (0, xstate.getMicrosteps)(machine, machine.resolveState({
|
|
546
|
+
value: previous.value,
|
|
547
|
+
context: previous.context
|
|
548
|
+
}), event.event) : [];
|
|
549
|
+
const last = microsteps.at(-1)?.[0];
|
|
550
|
+
if (last && snapshot && sameLeaves(last.value, snapshot.value)) for (const [step] of microsteps) for (const leaf of statePaths(step.value)) leaves.add(leaf);
|
|
551
|
+
} catch {}
|
|
552
|
+
previous = snapshot;
|
|
553
|
+
}
|
|
554
|
+
return leaves;
|
|
555
|
+
}
|
|
524
556
|
const ratioOf = (visited, total) => total === 0 ? 1 : visited / total;
|
|
525
557
|
/**
|
|
526
558
|
* Measures how much of a machine a set of runs exercised: which atomic and
|
|
@@ -538,7 +570,8 @@ const ratioOf = (visited, total) => total === 0 ? 1 : visited / total;
|
|
|
538
570
|
* bare type (`xstate.done.actor`), one per state however many invokes; a
|
|
539
571
|
* definition's `matches` (an invoke's `actorId`) must accept the traced event
|
|
540
572
|
* for its state to be credited. Ignored steps credit no handler. `always`
|
|
541
|
-
* handlers are listed as `unobservable`, never as unvisited
|
|
573
|
+
* handlers are listed as `unobservable`, never as unvisited; a state one
|
|
574
|
+
* passes through is visited, re-derived from each step's microsteps.
|
|
542
575
|
*
|
|
543
576
|
* @example
|
|
544
577
|
* ```ts no-check
|
|
@@ -594,6 +627,7 @@ function traceCoverage(machine, traces, options = {}) {
|
|
|
594
627
|
if (event.event.type !== "@xstate.init" || !require_event_log.isRecord(event.snapshot)) continue;
|
|
595
628
|
for (const leaf of statePaths(event.snapshot.value)) visited.add(leaf);
|
|
596
629
|
}
|
|
630
|
+
if (unobservable.length > 0) for (const leaf of passedThrough(machine, trace)) visited.add(leaf);
|
|
597
631
|
const credited = /* @__PURE__ */ new Set();
|
|
598
632
|
for (const step of steps) {
|
|
599
633
|
for (const leaf of step.to) visited.add(leaf);
|
|
@@ -655,6 +689,35 @@ function traceCoverage(machine, traces, options = {}) {
|
|
|
655
689
|
//#endregion
|
|
656
690
|
//#region src/first-divergence.ts
|
|
657
691
|
const defaultKey = (step) => `${step.from.join(",")}|${step.event}|${step.to.join(",")}`;
|
|
692
|
+
const isErrorLike = (value) => require_event_log.isError(value) || require_event_log.isRecord(value) && typeof value.name === "string" && typeof value.message === "string";
|
|
693
|
+
const normalizeErrors = (value, seen = /* @__PURE__ */ new WeakSet()) => {
|
|
694
|
+
if (value === null || typeof value !== "object") return value;
|
|
695
|
+
if (seen.has(value)) return "[circular]";
|
|
696
|
+
seen.add(value);
|
|
697
|
+
try {
|
|
698
|
+
if (isErrorLike(value) && (require_event_log.isError(value) || "stack" in value || "code" in value)) {
|
|
699
|
+
const { name, message, code, cause } = value;
|
|
700
|
+
return {
|
|
701
|
+
name,
|
|
702
|
+
message,
|
|
703
|
+
...typeof code === "string" ? { code } : {},
|
|
704
|
+
...cause !== void 0 ? { cause: normalizeErrors(cause, seen) } : {}
|
|
705
|
+
};
|
|
706
|
+
}
|
|
707
|
+
if (Array.isArray(value)) return value.map((item) => normalizeErrors(item, seen));
|
|
708
|
+
if (!require_event_log.isPlainObject(value)) return value;
|
|
709
|
+
const copy = Object.create(null);
|
|
710
|
+
for (const key of Object.keys(value)) copy[key] = normalizeErrors(value[key], seen);
|
|
711
|
+
return copy;
|
|
712
|
+
} finally {
|
|
713
|
+
seen.delete(value);
|
|
714
|
+
}
|
|
715
|
+
};
|
|
716
|
+
const payloadKey = (step) => {
|
|
717
|
+
if (!require_event_log.isRecord(step.payload)) return `${defaultKey(step)}|${require_event_log.canonicalEventJson(step.payload)}`;
|
|
718
|
+
const { sessionId: _sessionId, ...payload } = step.payload;
|
|
719
|
+
return `${defaultKey(step)}|${require_event_log.canonicalEventJson(normalizeErrors(payload))}`;
|
|
720
|
+
};
|
|
658
721
|
const isTrace = (items) => items.length === 0 || items.some((item) => require_event_log.isRecord(item) && (item.type === "machine.transition" || item.type === "run.start" || item.type === "run.end"));
|
|
659
722
|
/**
|
|
660
723
|
* Finds the first step where a run departs from a reference, so a failure is
|
|
@@ -685,7 +748,7 @@ const isTrace = (items) => items.length === 0 || items.some((item) => require_ev
|
|
|
685
748
|
*/
|
|
686
749
|
function firstDivergence(actual, reference, options = {}) {
|
|
687
750
|
const steps = traceSteps(actual).filter((step) => !step.ignored);
|
|
688
|
-
return isTrace(reference) ? againstTrace(steps, traceSteps(reference).filter((step) => !step.ignored), options.key ?? defaultKey) : againstTrajectory(actual, steps, reference);
|
|
751
|
+
return isTrace(reference) ? againstTrace(steps, traceSteps(reference).filter((step) => !step.ignored), options.key === "payload" ? payloadKey : options.key ?? defaultKey) : againstTrajectory(actual, steps, reference);
|
|
689
752
|
}
|
|
690
753
|
function diverged(steps, index, expected, initial = steps[0]?.fromValue) {
|
|
691
754
|
const step = steps[index];
|
|
@@ -1071,11 +1134,563 @@ function structurallyEqual(a, b) {
|
|
|
1071
1134
|
return keys.length === Object.keys(b).length && keys.every((key) => Object.hasOwn(b, key) && structurallyEqual(a[key], b[key]));
|
|
1072
1135
|
}
|
|
1073
1136
|
//#endregion
|
|
1137
|
+
//#region src/equivalence.ts
|
|
1138
|
+
/**
|
|
1139
|
+
* Thrown in replay when the port asks for something the recording cannot
|
|
1140
|
+
* answer: a model call past the last recorded one, or a tool call the original
|
|
1141
|
+
* never made. The effect is still recorded, so {@link compareRecordings}
|
|
1142
|
+
* reports it.
|
|
1143
|
+
*/
|
|
1144
|
+
var RecordingDivergenceError = class extends Error {
|
|
1145
|
+
name = "RecordingDivergenceError";
|
|
1146
|
+
};
|
|
1147
|
+
function toRecordedError(error) {
|
|
1148
|
+
if (!(error instanceof Error)) return {
|
|
1149
|
+
name: "Error",
|
|
1150
|
+
message: String(error)
|
|
1151
|
+
};
|
|
1152
|
+
const recorded = {
|
|
1153
|
+
name: error.name,
|
|
1154
|
+
message: error.message
|
|
1155
|
+
};
|
|
1156
|
+
const code = error.code;
|
|
1157
|
+
if (code !== void 0) recorded.code = toJson(code);
|
|
1158
|
+
const data = Object.fromEntries(Object.entries(error).filter(([key, value]) => key !== "code" && (typeof value === "number" || typeof value === "boolean")));
|
|
1159
|
+
if (Object.keys(data).length) recorded.data = data;
|
|
1160
|
+
const markers = /* @__PURE__ */ new Set();
|
|
1161
|
+
for (let holder = error; holder; holder = Object.getPrototypeOf(holder)) for (const symbol of Object.getOwnPropertySymbols(holder)) {
|
|
1162
|
+
const key = Symbol.keyFor(symbol);
|
|
1163
|
+
if (key !== void 0 && error[symbol] === true) markers.add(key);
|
|
1164
|
+
}
|
|
1165
|
+
if (markers.size) recorded.markers = [...markers];
|
|
1166
|
+
return recorded;
|
|
1167
|
+
}
|
|
1168
|
+
function fromRecordedError({ data, markers, ...fields }) {
|
|
1169
|
+
const error = Object.assign(new Error(fields.message), fields, data);
|
|
1170
|
+
for (const marker of markers ?? []) error[Symbol.for(marker)] = true;
|
|
1171
|
+
return error;
|
|
1172
|
+
}
|
|
1173
|
+
/** What two runs compare of an error: its data and markers may differ. */
|
|
1174
|
+
function errorIdentity(error) {
|
|
1175
|
+
return error && {
|
|
1176
|
+
name: error.name,
|
|
1177
|
+
message: error.message,
|
|
1178
|
+
code: error.code
|
|
1179
|
+
};
|
|
1180
|
+
}
|
|
1181
|
+
/** A JSON-safe copy: Dates become ISO strings, Errors become {@link RecordedError}. */
|
|
1182
|
+
function toJson(value) {
|
|
1183
|
+
if (value === void 0) return void 0;
|
|
1184
|
+
return JSON.parse(JSON.stringify(value, function(key, item) {
|
|
1185
|
+
const raw = this[key];
|
|
1186
|
+
if (raw instanceof Date) return raw.toISOString();
|
|
1187
|
+
if (item instanceof Error) return toRecordedError(item);
|
|
1188
|
+
if (typeof item === "bigint") return item.toString();
|
|
1189
|
+
if (item instanceof Uint8Array) return Array.from(item);
|
|
1190
|
+
return item;
|
|
1191
|
+
}));
|
|
1192
|
+
}
|
|
1193
|
+
/** Restores the `Date` timestamps the AI SDK puts on responses. */
|
|
1194
|
+
function reviveTimestamps(value) {
|
|
1195
|
+
if (value && typeof value === "object") {
|
|
1196
|
+
for (const holder of [value, value.response]) if (holder && typeof holder["timestamp"] === "string") holder["timestamp"] = new Date(holder["timestamp"]);
|
|
1197
|
+
}
|
|
1198
|
+
return value;
|
|
1199
|
+
}
|
|
1200
|
+
function omit(value, keys) {
|
|
1201
|
+
if (!value || typeof value !== "object") return value;
|
|
1202
|
+
return Object.fromEntries(Object.entries(value).filter(([key]) => !keys.includes(key)));
|
|
1203
|
+
}
|
|
1204
|
+
/** Key-order-independent JSON, for equality. */
|
|
1205
|
+
function stableStringify(value) {
|
|
1206
|
+
if (Array.isArray(value)) return `[${value.map(stableStringify).join(",")}]`;
|
|
1207
|
+
if (value && typeof value === "object") return `{${Object.keys(value).sort().map((key) => `${JSON.stringify(key)}:${stableStringify(value[key])}`).join(",")}}`;
|
|
1208
|
+
return JSON.stringify(value) ?? "undefined";
|
|
1209
|
+
}
|
|
1210
|
+
function jsonEqual(a, b) {
|
|
1211
|
+
return stableStringify(toJson(a)) === stableStringify(toJson(b));
|
|
1212
|
+
}
|
|
1213
|
+
function streamFrom(parts) {
|
|
1214
|
+
return new ReadableStream({ start(controller) {
|
|
1215
|
+
for (const part of parts) controller.enqueue(reviveTimestamps(structuredClone(part)));
|
|
1216
|
+
controller.close();
|
|
1217
|
+
} });
|
|
1218
|
+
}
|
|
1219
|
+
async function* iterate(chunks) {
|
|
1220
|
+
for (const chunk of chunks) yield structuredClone(chunk);
|
|
1221
|
+
}
|
|
1222
|
+
/**
|
|
1223
|
+
* Creates a {@link Recorder}. With no options it records: every wrapped call
|
|
1224
|
+
* runs for real. With `replay` it answers from a recording instead.
|
|
1225
|
+
*/
|
|
1226
|
+
function createRecorder(options = {}) {
|
|
1227
|
+
const effects = [];
|
|
1228
|
+
const replay = options.replay?.effects;
|
|
1229
|
+
const replayedModels = replay?.filter((effect) => effect.kind === "model");
|
|
1230
|
+
const usedModels = /* @__PURE__ */ new Set();
|
|
1231
|
+
const usedTools = /* @__PURE__ */ new Set();
|
|
1232
|
+
const normalizeEffect = (effect, list) => options.normalize?.(effect, list.indexOf(effect), list) ?? effect;
|
|
1233
|
+
let modelCalls = 0;
|
|
1234
|
+
let toolsInFlight = 0;
|
|
1235
|
+
/**
|
|
1236
|
+
* The earliest unused recorded call that fits this one: one `translate`
|
|
1237
|
+
* adapts, or one with the same method and shape. Not by position, so a call
|
|
1238
|
+
* the port added or dropped does not shift every answer after it.
|
|
1239
|
+
*/
|
|
1240
|
+
function nextReplayedModel(effect) {
|
|
1241
|
+
for (const recorded of replayedModels) {
|
|
1242
|
+
if (usedModels.has(recorded)) continue;
|
|
1243
|
+
const translated = options.translate?.(structuredClone(recorded), effect);
|
|
1244
|
+
if (translated) {
|
|
1245
|
+
effect.translated = true;
|
|
1246
|
+
return {
|
|
1247
|
+
recorded,
|
|
1248
|
+
answer: translated
|
|
1249
|
+
};
|
|
1250
|
+
}
|
|
1251
|
+
if (recorded.method === effect.method && modelCallsMatch(options.modelCalls, recorded, effect)) return {
|
|
1252
|
+
recorded,
|
|
1253
|
+
answer: recorded
|
|
1254
|
+
};
|
|
1255
|
+
}
|
|
1256
|
+
}
|
|
1257
|
+
function noAnswerMessage(effect) {
|
|
1258
|
+
const unused = replayedModels.filter((recorded) => !usedModels.has(recorded));
|
|
1259
|
+
return unused.length ? `Model call #${effect.call} (${effect.method}, ${JSON.stringify(modelCallShape(effect))}) fits no unused recorded call: ${unused.map((recorded) => `#${recorded.call} (${recorded.method}, ${JSON.stringify(modelCallShape(recorded))})`).join(", ")}. A recorded answer only fits a call of the same method and shape; pass \`translate\` to adapt one.` : `Model call #${effect.call} was never made by the recorded run (it made ${replayedModels.length}).`;
|
|
1260
|
+
}
|
|
1261
|
+
/**
|
|
1262
|
+
* Records a model call around `run`, or answers it from the recording.
|
|
1263
|
+
* `fallback` runs it on the stand-in when the recording has no answer.
|
|
1264
|
+
*/
|
|
1265
|
+
async function modelCall(seam, method, request, streamed, run, fallback) {
|
|
1266
|
+
const effect = {
|
|
1267
|
+
kind: "model",
|
|
1268
|
+
seam,
|
|
1269
|
+
method,
|
|
1270
|
+
call: modelCalls++,
|
|
1271
|
+
request: toJson(omit(request, [
|
|
1272
|
+
"abortSignal",
|
|
1273
|
+
"headers",
|
|
1274
|
+
"signal"
|
|
1275
|
+
]))
|
|
1276
|
+
};
|
|
1277
|
+
effects.push(effect);
|
|
1278
|
+
if (replay) {
|
|
1279
|
+
const replayed = nextReplayedModel(effect);
|
|
1280
|
+
if (replayed) {
|
|
1281
|
+
const { recorded, answer } = replayed;
|
|
1282
|
+
usedModels.add(recorded);
|
|
1283
|
+
effect.replayed = recorded.call;
|
|
1284
|
+
if (answer.error) {
|
|
1285
|
+
effect.error = answer.error;
|
|
1286
|
+
throw fromRecordedError(answer.error);
|
|
1287
|
+
}
|
|
1288
|
+
effect.response = answer.response;
|
|
1289
|
+
effect.stream = answer.stream;
|
|
1290
|
+
if (seam === "openai") return streamed ? iterate(answer.stream ?? []) : structuredClone(answer.response);
|
|
1291
|
+
return streamed ? {
|
|
1292
|
+
...reviveTimestamps(structuredClone(answer.response) ?? {}),
|
|
1293
|
+
stream: streamFrom(answer.stream ?? [])
|
|
1294
|
+
} : reviveTimestamps(structuredClone(answer.response));
|
|
1295
|
+
}
|
|
1296
|
+
if (!fallback) {
|
|
1297
|
+
const error = new RecordingDivergenceError(noAnswerMessage(effect));
|
|
1298
|
+
effect.error = toRecordedError(error);
|
|
1299
|
+
throw error;
|
|
1300
|
+
}
|
|
1301
|
+
effect.unrecorded = true;
|
|
1302
|
+
run = fallback;
|
|
1303
|
+
}
|
|
1304
|
+
let result;
|
|
1305
|
+
try {
|
|
1306
|
+
result = await run();
|
|
1307
|
+
} catch (error) {
|
|
1308
|
+
effect.error = toRecordedError(error);
|
|
1309
|
+
throw error;
|
|
1310
|
+
}
|
|
1311
|
+
if (!streamed) {
|
|
1312
|
+
effect.response = toJson(result);
|
|
1313
|
+
return result;
|
|
1314
|
+
}
|
|
1315
|
+
const parts = [];
|
|
1316
|
+
effect.stream = parts;
|
|
1317
|
+
if (seam === "openai") {
|
|
1318
|
+
const source = result;
|
|
1319
|
+
return (async function* () {
|
|
1320
|
+
for await (const chunk of source) {
|
|
1321
|
+
parts.push(toJson(chunk));
|
|
1322
|
+
yield chunk;
|
|
1323
|
+
}
|
|
1324
|
+
})();
|
|
1325
|
+
}
|
|
1326
|
+
const { stream, ...rest } = result;
|
|
1327
|
+
effect.response = toJson(rest);
|
|
1328
|
+
return {
|
|
1329
|
+
...rest,
|
|
1330
|
+
stream: stream.pipeThrough(new TransformStream({ transform(part, controller) {
|
|
1331
|
+
parts.push(toJson(part));
|
|
1332
|
+
controller.enqueue(part);
|
|
1333
|
+
} }))
|
|
1334
|
+
};
|
|
1335
|
+
}
|
|
1336
|
+
/** `inputOf` picks the recorded input from the call's arguments. */
|
|
1337
|
+
function tool(name, fn, inputOf = (args) => args.length === 1 ? args[0] : args) {
|
|
1338
|
+
return ((...args) => {
|
|
1339
|
+
const input = toJson(inputOf(args));
|
|
1340
|
+
const effect = {
|
|
1341
|
+
kind: "tool",
|
|
1342
|
+
name,
|
|
1343
|
+
step: modelCalls,
|
|
1344
|
+
input,
|
|
1345
|
+
...toolsInFlight > 0 ? { concurrent: true } : {}
|
|
1346
|
+
};
|
|
1347
|
+
effects.push(effect);
|
|
1348
|
+
return track(call(effect, args));
|
|
1349
|
+
});
|
|
1350
|
+
function call(effect, args) {
|
|
1351
|
+
const { input } = effect;
|
|
1352
|
+
if (replay && options.tools !== "live") {
|
|
1353
|
+
const wanted = normalizeEffect(effect, effects).input;
|
|
1354
|
+
const matches = (candidate) => candidate.kind === "tool" && !usedTools.has(candidate) && candidate.name === name && jsonEqual(normalizeEffect(candidate, replay).input, wanted);
|
|
1355
|
+
const recorded = replay.find(matches);
|
|
1356
|
+
if (!recorded && options.fallback?.tools) {
|
|
1357
|
+
effect.unrecorded = true;
|
|
1358
|
+
return runLive(effect, args);
|
|
1359
|
+
}
|
|
1360
|
+
const settle = (value) => {
|
|
1361
|
+
if (recorded?.sync) return value();
|
|
1362
|
+
try {
|
|
1363
|
+
return Promise.resolve(value());
|
|
1364
|
+
} catch (error) {
|
|
1365
|
+
return Promise.reject(error);
|
|
1366
|
+
}
|
|
1367
|
+
};
|
|
1368
|
+
return settle(() => {
|
|
1369
|
+
if (!recorded) {
|
|
1370
|
+
const error = new RecordingDivergenceError(`Tool '${name}' was called with ${JSON.stringify(input)}; the recorded run made no such call.`);
|
|
1371
|
+
effect.error = toRecordedError(error);
|
|
1372
|
+
throw error;
|
|
1373
|
+
}
|
|
1374
|
+
usedTools.add(recorded);
|
|
1375
|
+
if (recorded.sync) effect.sync = true;
|
|
1376
|
+
if (recorded.error) {
|
|
1377
|
+
effect.error = recorded.error;
|
|
1378
|
+
throw fromRecordedError(recorded.error);
|
|
1379
|
+
}
|
|
1380
|
+
effect.output = recorded.output;
|
|
1381
|
+
return structuredClone(recorded.output);
|
|
1382
|
+
});
|
|
1383
|
+
}
|
|
1384
|
+
return runLive(effect, args);
|
|
1385
|
+
}
|
|
1386
|
+
function runLive(effect, args) {
|
|
1387
|
+
let output;
|
|
1388
|
+
try {
|
|
1389
|
+
output = fn(...args);
|
|
1390
|
+
} catch (error) {
|
|
1391
|
+
effect.sync = true;
|
|
1392
|
+
effect.error = toRecordedError(error);
|
|
1393
|
+
throw error;
|
|
1394
|
+
}
|
|
1395
|
+
if (!(output instanceof Promise)) {
|
|
1396
|
+
effect.sync = true;
|
|
1397
|
+
effect.output = toJson(output);
|
|
1398
|
+
return output;
|
|
1399
|
+
}
|
|
1400
|
+
return output.then((value) => {
|
|
1401
|
+
effect.output = toJson(value);
|
|
1402
|
+
return value;
|
|
1403
|
+
}, (error) => {
|
|
1404
|
+
effect.error = toRecordedError(error);
|
|
1405
|
+
throw error;
|
|
1406
|
+
});
|
|
1407
|
+
}
|
|
1408
|
+
}
|
|
1409
|
+
/** Counts an async tool call as running until it settles. */
|
|
1410
|
+
function track(result) {
|
|
1411
|
+
if (result instanceof Promise) {
|
|
1412
|
+
toolsInFlight++;
|
|
1413
|
+
const settled = () => {
|
|
1414
|
+
toolsInFlight--;
|
|
1415
|
+
};
|
|
1416
|
+
result.then(settled, settled);
|
|
1417
|
+
}
|
|
1418
|
+
return result;
|
|
1419
|
+
}
|
|
1420
|
+
return {
|
|
1421
|
+
model(model) {
|
|
1422
|
+
const base = model;
|
|
1423
|
+
const stand = options.fallback?.model;
|
|
1424
|
+
const wrapped = Object.create(base);
|
|
1425
|
+
for (const method of [
|
|
1426
|
+
"doGenerate",
|
|
1427
|
+
"doStream",
|
|
1428
|
+
"doDecide",
|
|
1429
|
+
"doEvaluate"
|
|
1430
|
+
]) {
|
|
1431
|
+
if (typeof base[method] !== "function") continue;
|
|
1432
|
+
const invoke = (target, callOptions) => target[method].call(target, callOptions);
|
|
1433
|
+
wrapped[method] = (callOptions) => modelCall("ai-sdk", method, callOptions, method === "doStream", () => invoke(base, callOptions), stand && typeof stand[method] === "function" ? () => invoke(stand, callOptions) : void 0);
|
|
1434
|
+
}
|
|
1435
|
+
return wrapped;
|
|
1436
|
+
},
|
|
1437
|
+
openai(client) {
|
|
1438
|
+
const wrapCreate = (resource, method) => new Proxy(resource, { get(target, key, receiver) {
|
|
1439
|
+
if (key !== "create") return Reflect.get(target, key, receiver);
|
|
1440
|
+
return (params, requestOptions) => {
|
|
1441
|
+
let api;
|
|
1442
|
+
const create = (resource) => () => {
|
|
1443
|
+
api = Reflect.get(resource, "create").call(resource, params, requestOptions);
|
|
1444
|
+
return Promise.resolve(api);
|
|
1445
|
+
};
|
|
1446
|
+
const stand = fallbackResource(method);
|
|
1447
|
+
const promise = modelCall("openai", method, params, params?.stream === true, create(target), stand && create(stand));
|
|
1448
|
+
return Object.assign(promise, { withResponse: async () => {
|
|
1449
|
+
const data = await promise;
|
|
1450
|
+
const meta = await api?.withResponse?.();
|
|
1451
|
+
return {
|
|
1452
|
+
data,
|
|
1453
|
+
response: meta?.response ?? new Response(null),
|
|
1454
|
+
request_id: meta?.request_id ?? null
|
|
1455
|
+
};
|
|
1456
|
+
} });
|
|
1457
|
+
};
|
|
1458
|
+
} });
|
|
1459
|
+
const fallbackResource = (method) => {
|
|
1460
|
+
let value = options.fallback?.openai;
|
|
1461
|
+
for (const key of method.split(".").slice(0, -1)) value = value?.[key];
|
|
1462
|
+
return value && typeof value === "object" ? value : void 0;
|
|
1463
|
+
};
|
|
1464
|
+
const wrapped = /* @__PURE__ */ new Map();
|
|
1465
|
+
const wrap = (key, make) => {
|
|
1466
|
+
if (!wrapped.has(key)) wrapped.set(key, make());
|
|
1467
|
+
return wrapped.get(key);
|
|
1468
|
+
};
|
|
1469
|
+
return new Proxy(client, { get(target, key, receiver) {
|
|
1470
|
+
const value = Reflect.get(target, key, receiver);
|
|
1471
|
+
if (key === "responses" && value) return wrap(key, () => wrapCreate(value, "responses.create"));
|
|
1472
|
+
if (key === "chat" && value) return wrap(key, () => new Proxy(value, { get(chat, chatKey, chatReceiver) {
|
|
1473
|
+
const inner = Reflect.get(chat, chatKey, chatReceiver);
|
|
1474
|
+
return chatKey === "completions" && inner ? wrap("chat.completions", () => wrapCreate(inner, "chat.completions.create")) : inner;
|
|
1475
|
+
} }));
|
|
1476
|
+
return value;
|
|
1477
|
+
} });
|
|
1478
|
+
},
|
|
1479
|
+
tool: (name, fn) => tool(name, fn),
|
|
1480
|
+
tools(tools) {
|
|
1481
|
+
return Object.fromEntries(Object.entries(tools).map(([name, definition]) => [name, definition.execute ? {
|
|
1482
|
+
...definition,
|
|
1483
|
+
execute: tool(name, definition.execute, (args) => args[0])
|
|
1484
|
+
} : definition]));
|
|
1485
|
+
},
|
|
1486
|
+
output(value) {
|
|
1487
|
+
effects.push({
|
|
1488
|
+
kind: "output",
|
|
1489
|
+
value: toJson(value)
|
|
1490
|
+
});
|
|
1491
|
+
},
|
|
1492
|
+
get recording() {
|
|
1493
|
+
return {
|
|
1494
|
+
version: 1,
|
|
1495
|
+
effects: toJson(effects)
|
|
1496
|
+
};
|
|
1497
|
+
}
|
|
1498
|
+
};
|
|
1499
|
+
}
|
|
1500
|
+
/** True when two model calls offer the same tool names and response format. */
|
|
1501
|
+
function sameModelCallShape(expected, actual) {
|
|
1502
|
+
return jsonEqual(modelCallShape(expected), modelCallShape(actual));
|
|
1503
|
+
}
|
|
1504
|
+
function modelCallsMatch(match, expected, actual) {
|
|
1505
|
+
if (match === "none") return true;
|
|
1506
|
+
if (typeof match === "function") return match(expected, actual);
|
|
1507
|
+
return sameModelCallShape(expected, actual);
|
|
1508
|
+
}
|
|
1509
|
+
function shapeMessage(expected, actual) {
|
|
1510
|
+
return `Model call #${expected.call} changed shape: ${JSON.stringify(modelCallShape(expected))} → ${JSON.stringify(modelCallShape(actual))}. A recorded answer only fits a call of the same shape.`;
|
|
1511
|
+
}
|
|
1512
|
+
/**
|
|
1513
|
+
* Offered tool names and the response format, or a decision's questions and
|
|
1514
|
+
* their options: what a recorded answer depends on.
|
|
1515
|
+
*/
|
|
1516
|
+
function modelCallShape(effect) {
|
|
1517
|
+
const request = effect.request ?? {};
|
|
1518
|
+
const questions = request["questions"];
|
|
1519
|
+
if (questions && typeof questions === "object") return { questions: Object.entries(questions).map(([name, question]) => {
|
|
1520
|
+
const criteria = question["criteria"];
|
|
1521
|
+
if (question["type"] === "choice" && criteria && typeof criteria === "object") return [
|
|
1522
|
+
name,
|
|
1523
|
+
question["type"],
|
|
1524
|
+
Object.keys(criteria).sort()
|
|
1525
|
+
];
|
|
1526
|
+
if (question["type"] === "score" && Array.isArray(criteria)) return [
|
|
1527
|
+
name,
|
|
1528
|
+
question["type"],
|
|
1529
|
+
criteria.length
|
|
1530
|
+
];
|
|
1531
|
+
return [name, question["type"]];
|
|
1532
|
+
}).sort((x, y) => String(x[0]).localeCompare(String(y[0]))) };
|
|
1533
|
+
return {
|
|
1534
|
+
tools: (Array.isArray(request["tools"]) ? request["tools"] : []).map((tool) => tool["name"] ?? tool["function"]?.["name"]).sort(),
|
|
1535
|
+
format: request["responseFormat"]?.["type"] ?? request["response_format"]?.["type"] ?? (request["text"]?.["format"])?.["type"] ?? "text"
|
|
1536
|
+
};
|
|
1537
|
+
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Puts each group of concurrent tool calls in a stable order, so parallel tool
|
|
1540
|
+
* calls that finished in a different order still compare equal. A tool call
|
|
1541
|
+
* that started after the previous one settled begins a new group, so
|
|
1542
|
+
* sequential calls keep their order.
|
|
1543
|
+
*/
|
|
1544
|
+
function normalize(effects) {
|
|
1545
|
+
const result = [];
|
|
1546
|
+
let batch = [];
|
|
1547
|
+
const flush = () => {
|
|
1548
|
+
result.push(...batch.sort((a, b) => stableStringify([a.name, a.input]).localeCompare(stableStringify([b.name, b.input]))));
|
|
1549
|
+
batch = [];
|
|
1550
|
+
};
|
|
1551
|
+
for (const effect of effects) {
|
|
1552
|
+
if (effect.kind !== "tool" || !effect.concurrent) flush();
|
|
1553
|
+
if (effect.kind === "tool") batch.push(effect);
|
|
1554
|
+
else result.push(effect);
|
|
1555
|
+
}
|
|
1556
|
+
flush();
|
|
1557
|
+
return result;
|
|
1558
|
+
}
|
|
1559
|
+
function describe(effect) {
|
|
1560
|
+
switch (effect.kind) {
|
|
1561
|
+
case "model": return `model call #${effect.call} (${effect.method})`;
|
|
1562
|
+
case "tool": return `tool '${effect.name}' with ${JSON.stringify(effect.input)}`;
|
|
1563
|
+
case "output": return `output ${JSON.stringify(effect.value)}`;
|
|
1564
|
+
}
|
|
1565
|
+
}
|
|
1566
|
+
/** Why two effects differ, or `undefined` when they are the same. */
|
|
1567
|
+
function differ(left, right, options) {
|
|
1568
|
+
if (left.kind !== right.kind) return {
|
|
1569
|
+
reason: "kind",
|
|
1570
|
+
message: `Expected ${describe(left)}; the port made ${describe(right)}.`
|
|
1571
|
+
};
|
|
1572
|
+
if (left.kind === "model" && right.kind === "model") {
|
|
1573
|
+
if (right.translated && right.replayed === left.call) return void 0;
|
|
1574
|
+
if (left.method !== right.method) return {
|
|
1575
|
+
reason: "model-method",
|
|
1576
|
+
message: `Model call #${left.call} used ${left.method}; the port used ${right.method}.`
|
|
1577
|
+
};
|
|
1578
|
+
if (!modelCallsMatch(options.modelCalls, left, right)) return {
|
|
1579
|
+
reason: "model-call-shape",
|
|
1580
|
+
message: shapeMessage(left, right)
|
|
1581
|
+
};
|
|
1582
|
+
if (!jsonEqual(errorIdentity(left.error), errorIdentity(right.error))) {
|
|
1583
|
+
const outcome = (error) => error ? `failed with ${error.name}: ${error.message}` : "succeeded";
|
|
1584
|
+
return {
|
|
1585
|
+
reason: "model-error",
|
|
1586
|
+
message: `Model call #${left.call} ${outcome(left.error)}; in the port it ${outcome(right.error)}.`
|
|
1587
|
+
};
|
|
1588
|
+
}
|
|
1589
|
+
return;
|
|
1590
|
+
}
|
|
1591
|
+
if (left.kind === "tool" && right.kind === "tool") {
|
|
1592
|
+
if (left.name !== right.name) return {
|
|
1593
|
+
reason: "tool-name",
|
|
1594
|
+
message: `Expected ${describe(left)}; the port made ${describe(right)}.`
|
|
1595
|
+
};
|
|
1596
|
+
if (!jsonEqual(left.input, right.input)) return {
|
|
1597
|
+
reason: "tool-input",
|
|
1598
|
+
message: `Expected ${describe(left)}; the port passed ${JSON.stringify(right.input)}.`
|
|
1599
|
+
};
|
|
1600
|
+
if (!jsonEqual(left.output, right.output) || !jsonEqual(errorIdentity(left.error), errorIdentity(right.error))) return {
|
|
1601
|
+
reason: "tool-result",
|
|
1602
|
+
message: `Tool '${left.name}' returned a different result.`
|
|
1603
|
+
};
|
|
1604
|
+
return;
|
|
1605
|
+
}
|
|
1606
|
+
if (left.kind === "output" && right.kind === "output" && !jsonEqual(left.value, right.value)) return {
|
|
1607
|
+
reason: "output",
|
|
1608
|
+
message: `Expected ${describe(left)}; the port returned ${JSON.stringify(right.value)}.`
|
|
1609
|
+
};
|
|
1610
|
+
}
|
|
1611
|
+
/**
|
|
1612
|
+
* Compares two recordings and reports every effect that differs. `expected`
|
|
1613
|
+
* is the original's recording, `actual` the port's. Effects that are the same
|
|
1614
|
+
* on both sides are lined up first (longest common subsequence), so one extra
|
|
1615
|
+
* call does not shift every effect after it; between them, effects of the same
|
|
1616
|
+
* kind pair up and report what changed, and the rest are missing or extra.
|
|
1617
|
+
*/
|
|
1618
|
+
function compareRecordings(expected, actual, options = {}) {
|
|
1619
|
+
const select = (effects) => normalize(effects.flatMap((effect, index) => {
|
|
1620
|
+
if (options.kinds && !options.kinds.includes(effect.kind)) return [];
|
|
1621
|
+
const mapped = options.normalize ? options.normalize(effect, index, effects) : effect;
|
|
1622
|
+
return mapped ? [mapped] : [];
|
|
1623
|
+
}));
|
|
1624
|
+
const a = select(expected.effects);
|
|
1625
|
+
const b = select(actual.effects);
|
|
1626
|
+
const same = a.map((left) => b.map((right) => !differ(left, right, options)));
|
|
1627
|
+
const lcs = Array.from({ length: a.length + 1 }, () => Array.from({ length: b.length + 1 }, () => 0));
|
|
1628
|
+
for (let i = a.length - 1; i >= 0; i--) for (let j = b.length - 1; j >= 0; j--) lcs[i][j] = same[i][j] ? lcs[i + 1][j + 1] + 1 : Math.max(lcs[i + 1][j], lcs[i][j + 1]);
|
|
1629
|
+
const divergences = [];
|
|
1630
|
+
let lefts = [];
|
|
1631
|
+
let rights = [];
|
|
1632
|
+
const flushGap = (at) => {
|
|
1633
|
+
const unpairedRights = [...rights];
|
|
1634
|
+
const changed = [];
|
|
1635
|
+
for (const index of lefts) {
|
|
1636
|
+
const left = a[index];
|
|
1637
|
+
const k = unpairedRights.findIndex((j) => b[j].kind === left.kind);
|
|
1638
|
+
if (k === -1) {
|
|
1639
|
+
changed.push({
|
|
1640
|
+
index,
|
|
1641
|
+
reason: "missing-effect",
|
|
1642
|
+
expected: left,
|
|
1643
|
+
message: `The port never made ${describe(left)}.`
|
|
1644
|
+
});
|
|
1645
|
+
continue;
|
|
1646
|
+
}
|
|
1647
|
+
const right = b[unpairedRights.splice(k, 1)[0]];
|
|
1648
|
+
const difference = differ(left, right, options);
|
|
1649
|
+
if (difference) changed.push({
|
|
1650
|
+
index,
|
|
1651
|
+
expected: left,
|
|
1652
|
+
actual: right,
|
|
1653
|
+
...difference
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
for (const j of unpairedRights) divergences.push({
|
|
1657
|
+
index: lefts[0] ?? at,
|
|
1658
|
+
reason: "extra-effect",
|
|
1659
|
+
actual: b[j],
|
|
1660
|
+
message: `The port made ${describe(b[j])}, which the original never made.`
|
|
1661
|
+
});
|
|
1662
|
+
divergences.push(...changed);
|
|
1663
|
+
lefts = [];
|
|
1664
|
+
rights = [];
|
|
1665
|
+
};
|
|
1666
|
+
let i = 0;
|
|
1667
|
+
let j = 0;
|
|
1668
|
+
while (i < a.length || j < b.length) if (i < a.length && j < b.length && same[i][j]) {
|
|
1669
|
+
flushGap(i);
|
|
1670
|
+
i++;
|
|
1671
|
+
j++;
|
|
1672
|
+
} else if (j < b.length && (i === a.length || lcs[i][j + 1] >= lcs[i + 1][j])) rights.push(j++);
|
|
1673
|
+
else lefts.push(i++);
|
|
1674
|
+
flushGap(i);
|
|
1675
|
+
divergences.sort((x, y) => x.index - y.index);
|
|
1676
|
+
return divergences.length ? {
|
|
1677
|
+
equivalent: false,
|
|
1678
|
+
divergence: divergences[0],
|
|
1679
|
+
divergences
|
|
1680
|
+
} : {
|
|
1681
|
+
equivalent: true,
|
|
1682
|
+
divergences
|
|
1683
|
+
};
|
|
1684
|
+
}
|
|
1685
|
+
//#endregion
|
|
1074
1686
|
exports.AgentLintError = require_verify.AgentLintError;
|
|
1075
1687
|
exports.AgentUnknownStateError = require_verify.AgentUnknownStateError;
|
|
1688
|
+
exports.RecordingDivergenceError = RecordingDivergenceError;
|
|
1076
1689
|
exports.assertAgentMachine = require_verify.assertAgentMachine;
|
|
1077
1690
|
exports.canReach = require_verify.canReach;
|
|
1691
|
+
exports.compareRecordings = compareRecordings;
|
|
1078
1692
|
exports.compareRuns = compareRuns;
|
|
1693
|
+
exports.createRecorder = createRecorder;
|
|
1079
1694
|
exports.explorePaths = require_verify.explorePaths;
|
|
1080
1695
|
exports.firstDivergence = firstDivergence;
|
|
1081
1696
|
exports.foldTraces = foldTraces;
|
|
@@ -1085,6 +1700,7 @@ exports.lintAgentMachine = require_verify.lintAgentMachine;
|
|
|
1085
1700
|
exports.matchesTrajectory = matchesTrajectory;
|
|
1086
1701
|
exports.repeatRuns = repeatRuns;
|
|
1087
1702
|
exports.runSeam = runSeam;
|
|
1703
|
+
exports.sameModelCallShape = sameModelCallShape;
|
|
1088
1704
|
exports.simulateAgent = require_verify.simulateAgent;
|
|
1089
1705
|
exports.summarizeRepeats = summarizeRepeats;
|
|
1090
1706
|
exports.traceCoverage = traceCoverage;
|