fascicle 0.5.0 → 0.6.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/CHANGELOG.md +16 -0
- package/README.md +16 -8
- package/dist/adapters.d.ts +38 -0
- package/dist/adapters.js +78 -0
- package/dist/adapters.js.map +1 -0
- package/dist/index-CCFSc--s.d.ts +710 -0
- package/dist/index.d.ts +35 -709
- package/dist/index.js +251 -459
- package/dist/index.js.map +1 -1
- package/dist/tee-D_Qh_vfY.js +169 -0
- package/dist/tee-D_Qh_vfY.js.map +1 -0
- package/package.json +7 -8
package/dist/index.js
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
+
import { n as http_logger, r as filesystem_logger, t as tee_logger } from "./tee-D_Qh_vfY.js";
|
|
1
2
|
import { createHash, randomUUID } from "node:crypto";
|
|
2
3
|
import { z } from "zod";
|
|
3
4
|
import { mkdir, open, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
4
5
|
import { dirname, join, resolve } from "node:path";
|
|
5
|
-
import {
|
|
6
|
+
import { createReadStream, existsSync, mkdtempSync, statSync, watch, writeFileSync } from "node:fs";
|
|
6
7
|
import { tmpdir } from "node:os";
|
|
7
8
|
import { spawn } from "node:child_process";
|
|
8
9
|
import { generateText, stepCountIs, streamText, tool } from "ai";
|
|
@@ -408,6 +409,18 @@ var aborted_error = class extends Error {
|
|
|
408
409
|
if (metadata.tool_call_in_flight !== void 0) this.tool_call_in_flight = metadata.tool_call_in_flight;
|
|
409
410
|
}
|
|
410
411
|
};
|
|
412
|
+
/**
|
|
413
|
+
* Control-flow signals are not application failures. `suspended_error` is a
|
|
414
|
+
* human-approval gate pausing the run for later resume; `aborted_error` is
|
|
415
|
+
* cancellation. Resilience composers (`retry`, `fallback`) must rethrow these
|
|
416
|
+
* rather than retry past a suspend or run a backup under an aborted context.
|
|
417
|
+
*
|
|
418
|
+
* Kept internal to @repo/core: not re-exported by index.ts, so it does not
|
|
419
|
+
* widen the public surface.
|
|
420
|
+
*/
|
|
421
|
+
function is_control_flow_error(err) {
|
|
422
|
+
return err instanceof suspended_error || err instanceof aborted_error;
|
|
423
|
+
}
|
|
411
424
|
//#endregion
|
|
412
425
|
//#region packages/core/src/streaming.ts
|
|
413
426
|
const STREAMING_HIGH_WATER_MARK = 1e4;
|
|
@@ -543,6 +556,39 @@ function resolve_span_label(flow, fallback) {
|
|
|
543
556
|
const display = flow.config?.["display_name"];
|
|
544
557
|
return typeof display === "string" && display.length > 0 ? display : fallback;
|
|
545
558
|
}
|
|
559
|
+
/**
|
|
560
|
+
* Register the standard span-wrapping dispatch handler for a composer kind.
|
|
561
|
+
*
|
|
562
|
+
* Every composer wraps `flow.run` in a span identically; this centralizes that
|
|
563
|
+
* boilerplate and threads span parentage: the span opens with the current
|
|
564
|
+
* `ctx.parent_span_id` as its parent, and `flow.run` receives a child context
|
|
565
|
+
* whose `parent_span_id` is this span. Children dispatched from within
|
|
566
|
+
* (including concurrent ones under `parallel`/`map`, which spread the context)
|
|
567
|
+
* therefore nest correctly instead of leaving `parent_span_id` unpopulated.
|
|
568
|
+
*/
|
|
569
|
+
function register_traced_kind(kind) {
|
|
570
|
+
register_kind(kind, async (flow, input, ctx) => {
|
|
571
|
+
const label = resolve_span_label(flow, kind);
|
|
572
|
+
const span_meta = { id: flow.id };
|
|
573
|
+
if (ctx.parent_span_id !== void 0) span_meta["parent_span_id"] = ctx.parent_span_id;
|
|
574
|
+
const span_id = ctx.trajectory.start_span(label, span_meta);
|
|
575
|
+
const child_ctx = {
|
|
576
|
+
...ctx,
|
|
577
|
+
parent_span_id: span_id
|
|
578
|
+
};
|
|
579
|
+
try {
|
|
580
|
+
const out = await flow.run(input, child_ctx);
|
|
581
|
+
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
582
|
+
return out;
|
|
583
|
+
} catch (err) {
|
|
584
|
+
ctx.trajectory.end_span(span_id, {
|
|
585
|
+
id: flow.id,
|
|
586
|
+
error: err instanceof Error ? err.message : String(err)
|
|
587
|
+
});
|
|
588
|
+
throw err;
|
|
589
|
+
}
|
|
590
|
+
});
|
|
591
|
+
}
|
|
546
592
|
const active_runs = /* @__PURE__ */ new Set();
|
|
547
593
|
let signal_handler_installed = false;
|
|
548
594
|
let sigint_handler = null;
|
|
@@ -573,40 +619,38 @@ const noop_logger = {
|
|
|
573
619
|
end_span: () => {}
|
|
574
620
|
};
|
|
575
621
|
/**
|
|
576
|
-
* Wrap a logger so every emitted event automatically carries `run_id
|
|
622
|
+
* Wrap a logger so every emitted event automatically carries `run_id` and a
|
|
623
|
+
* `ts` (epoch milliseconds) stamped at emission.
|
|
577
624
|
*
|
|
578
|
-
* Studios and other downstream consumers
|
|
579
|
-
*
|
|
580
|
-
*
|
|
625
|
+
* Studios and other downstream consumers multiplex events across runs by
|
|
626
|
+
* `run_id` and reconstruct real timing from `ts` instead of fabricating it at
|
|
627
|
+
* ingest. Either field already present on an event or its meta is preserved;
|
|
628
|
+
* we never overwrite a caller-supplied value.
|
|
581
629
|
*/
|
|
582
|
-
function
|
|
630
|
+
function decorate_logger(inner, run_id) {
|
|
631
|
+
const stamp_meta = (meta) => {
|
|
632
|
+
const out = { ...meta };
|
|
633
|
+
if (!("run_id" in out)) out["run_id"] = run_id;
|
|
634
|
+
if (!("ts" in out)) out["ts"] = Date.now();
|
|
635
|
+
return out;
|
|
636
|
+
};
|
|
583
637
|
return {
|
|
584
638
|
record: (event) => {
|
|
585
|
-
if ("run_id" in event) {
|
|
639
|
+
if ("run_id" in event && "ts" in event) {
|
|
586
640
|
inner.record(event);
|
|
587
641
|
return;
|
|
588
642
|
}
|
|
643
|
+
const extra = {};
|
|
644
|
+
if (!("run_id" in event)) extra["run_id"] = run_id;
|
|
645
|
+
if (!("ts" in event)) extra["ts"] = Date.now();
|
|
589
646
|
inner.record({
|
|
590
647
|
...event,
|
|
591
|
-
|
|
592
|
-
});
|
|
593
|
-
},
|
|
594
|
-
start_span: (name, meta) => {
|
|
595
|
-
if (meta && "run_id" in meta) return inner.start_span(name, meta);
|
|
596
|
-
return inner.start_span(name, {
|
|
597
|
-
...meta,
|
|
598
|
-
run_id
|
|
648
|
+
...extra
|
|
599
649
|
});
|
|
600
650
|
},
|
|
651
|
+
start_span: (name, meta) => inner.start_span(name, stamp_meta(meta)),
|
|
601
652
|
end_span: (id, meta) => {
|
|
602
|
-
|
|
603
|
-
inner.end_span(id, meta);
|
|
604
|
-
return;
|
|
605
|
-
}
|
|
606
|
-
inner.end_span(id, {
|
|
607
|
-
...meta,
|
|
608
|
-
run_id
|
|
609
|
-
});
|
|
653
|
+
inner.end_span(id, stamp_meta(meta));
|
|
610
654
|
}
|
|
611
655
|
};
|
|
612
656
|
}
|
|
@@ -626,21 +670,33 @@ function prepend_path(err, id) {
|
|
|
626
670
|
const next = Array.isArray(existing) ? [id, ...existing.filter((v) => typeof v === "string")] : [id];
|
|
627
671
|
Reflect.set(err, "path", next);
|
|
628
672
|
}
|
|
673
|
+
/**
|
|
674
|
+
* Throw the abort reason if the context has been cancelled. Composers that
|
|
675
|
+
* iterate over children (`sequence`, `scope`, `loop`) call this between steps
|
|
676
|
+
* so a pending abort is honored before the next child starts, not only when a
|
|
677
|
+
* downstream dispatch happens to observe it.
|
|
678
|
+
*/
|
|
679
|
+
function throw_if_aborted$2(ctx) {
|
|
680
|
+
if (!ctx.abort.aborted) return;
|
|
681
|
+
const reason = ctx.abort.reason;
|
|
682
|
+
throw reason instanceof Error ? reason : new aborted_error("aborted", { reason });
|
|
683
|
+
}
|
|
629
684
|
function start_run(flow, input, options, high_water_mark) {
|
|
630
685
|
const install_signal_handlers = options.install_signal_handlers !== false;
|
|
631
686
|
const base_logger = options.trajectory ?? noop_logger;
|
|
632
687
|
const streaming = high_water_mark !== null;
|
|
633
688
|
const controller = new AbortController();
|
|
634
689
|
const run_id = randomUUID();
|
|
635
|
-
let logger = stamp_run_id(base_logger, run_id);
|
|
636
690
|
let stream_events = empty_async_iterable();
|
|
637
691
|
let close_stream = null;
|
|
692
|
+
let inner = base_logger;
|
|
638
693
|
if (streaming) {
|
|
639
|
-
const channel = create_streaming_channel(
|
|
640
|
-
|
|
694
|
+
const channel = create_streaming_channel(base_logger, high_water_mark);
|
|
695
|
+
inner = channel.logger;
|
|
641
696
|
stream_events = channel.events;
|
|
642
697
|
close_stream = channel.close;
|
|
643
698
|
}
|
|
699
|
+
const logger = decorate_logger(inner, run_id);
|
|
644
700
|
const cleanup = create_cleanup_registry(logger);
|
|
645
701
|
const ctx = {
|
|
646
702
|
run_id,
|
|
@@ -746,20 +802,7 @@ function step(id_or_fn, maybe_fn, meta) {
|
|
|
746
802
|
run: maybe_fn
|
|
747
803
|
};
|
|
748
804
|
}
|
|
749
|
-
|
|
750
|
-
const span_id = ctx.trajectory.start_span("step", { id: flow.id });
|
|
751
|
-
try {
|
|
752
|
-
const output = await flow.run(input, ctx);
|
|
753
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
754
|
-
return output;
|
|
755
|
-
} catch (err) {
|
|
756
|
-
ctx.trajectory.end_span(span_id, {
|
|
757
|
-
id: flow.id,
|
|
758
|
-
error: err instanceof Error ? err.message : String(err)
|
|
759
|
-
});
|
|
760
|
-
throw err;
|
|
761
|
-
}
|
|
762
|
-
});
|
|
805
|
+
register_traced_kind("step");
|
|
763
806
|
//#endregion
|
|
764
807
|
//#region packages/core/src/describe.ts
|
|
765
808
|
/**
|
|
@@ -927,7 +970,10 @@ function sequence(children, options) {
|
|
|
927
970
|
const children_ref = children;
|
|
928
971
|
const run_fn = async (input, ctx) => {
|
|
929
972
|
let acc = input;
|
|
930
|
-
for (const child of children_ref)
|
|
973
|
+
for (const child of children_ref) {
|
|
974
|
+
throw_if_aborted$2(ctx);
|
|
975
|
+
acc = await dispatch_step(child, acc, ctx);
|
|
976
|
+
}
|
|
931
977
|
return acc;
|
|
932
978
|
};
|
|
933
979
|
const config_meta = options?.name === void 0 ? void 0 : { display_name: options.name };
|
|
@@ -939,21 +985,7 @@ function sequence(children, options) {
|
|
|
939
985
|
run: run_fn
|
|
940
986
|
};
|
|
941
987
|
}
|
|
942
|
-
|
|
943
|
-
const label = resolve_span_label(flow, "sequence");
|
|
944
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
945
|
-
try {
|
|
946
|
-
const out = await flow.run(input, ctx);
|
|
947
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
948
|
-
return out;
|
|
949
|
-
} catch (err) {
|
|
950
|
-
ctx.trajectory.end_span(span_id, {
|
|
951
|
-
id: flow.id,
|
|
952
|
-
error: err instanceof Error ? err.message : String(err)
|
|
953
|
-
});
|
|
954
|
-
throw err;
|
|
955
|
-
}
|
|
956
|
-
});
|
|
988
|
+
register_traced_kind("sequence");
|
|
957
989
|
//#endregion
|
|
958
990
|
//#region packages/core/src/parallel.ts
|
|
959
991
|
/**
|
|
@@ -968,6 +1000,11 @@ register_kind("sequence", async (flow, input, ctx) => {
|
|
|
968
1000
|
* abort the composer awaits all in-flight children (success, failure, or
|
|
969
1001
|
* aborted) before rethrowing `ctx.abort.reason`. This matches the
|
|
970
1002
|
* "agent-pattern" composer contract in spec.md §6.8.
|
|
1003
|
+
*
|
|
1004
|
+
* When several children fail, a `suspended_error` is preferred over an
|
|
1005
|
+
* application error so a human-approval gate inside a branch stays resumable
|
|
1006
|
+
* rather than being masked by a sibling's failure. Otherwise the first error
|
|
1007
|
+
* in declared order propagates.
|
|
971
1008
|
*/
|
|
972
1009
|
let parallel_counter = 0;
|
|
973
1010
|
function next_id$9() {
|
|
@@ -1013,7 +1050,23 @@ function parallel(members, options) {
|
|
|
1013
1050
|
const reason = ctx.abort.reason;
|
|
1014
1051
|
throw reason instanceof Error ? reason : new aborted_error("aborted", { reason });
|
|
1015
1052
|
}
|
|
1016
|
-
|
|
1053
|
+
let first_err;
|
|
1054
|
+
let has_err = false;
|
|
1055
|
+
let suspended;
|
|
1056
|
+
let has_suspended = false;
|
|
1057
|
+
for (const s of settled) {
|
|
1058
|
+
if (s.status !== "err") continue;
|
|
1059
|
+
if (!has_err) {
|
|
1060
|
+
first_err = s.err;
|
|
1061
|
+
has_err = true;
|
|
1062
|
+
}
|
|
1063
|
+
if (!has_suspended && s.err instanceof suspended_error) {
|
|
1064
|
+
suspended = s.err;
|
|
1065
|
+
has_suspended = true;
|
|
1066
|
+
}
|
|
1067
|
+
}
|
|
1068
|
+
if (has_suspended) throw suspended;
|
|
1069
|
+
if (has_err) throw first_err;
|
|
1017
1070
|
const out = {};
|
|
1018
1071
|
for (const s of settled) if (s.status === "ok") out[s.key] = s.value;
|
|
1019
1072
|
return out;
|
|
@@ -1031,21 +1084,7 @@ function parallel(members, options) {
|
|
|
1031
1084
|
run: run_fn
|
|
1032
1085
|
};
|
|
1033
1086
|
}
|
|
1034
|
-
|
|
1035
|
-
const label = resolve_span_label(flow, "parallel");
|
|
1036
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1037
|
-
try {
|
|
1038
|
-
const out = await flow.run(input, ctx);
|
|
1039
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1040
|
-
return out;
|
|
1041
|
-
} catch (err) {
|
|
1042
|
-
ctx.trajectory.end_span(span_id, {
|
|
1043
|
-
id: flow.id,
|
|
1044
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1045
|
-
});
|
|
1046
|
-
throw err;
|
|
1047
|
-
}
|
|
1048
|
-
});
|
|
1087
|
+
register_traced_kind("parallel");
|
|
1049
1088
|
//#endregion
|
|
1050
1089
|
//#region packages/core/src/branch.ts
|
|
1051
1090
|
/**
|
|
@@ -1082,21 +1121,7 @@ function branch(config) {
|
|
|
1082
1121
|
run: run_fn
|
|
1083
1122
|
};
|
|
1084
1123
|
}
|
|
1085
|
-
|
|
1086
|
-
const label = resolve_span_label(flow, "branch");
|
|
1087
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1088
|
-
try {
|
|
1089
|
-
const out = await flow.run(input, ctx);
|
|
1090
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1091
|
-
return out;
|
|
1092
|
-
} catch (err) {
|
|
1093
|
-
ctx.trajectory.end_span(span_id, {
|
|
1094
|
-
id: flow.id,
|
|
1095
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1096
|
-
});
|
|
1097
|
-
throw err;
|
|
1098
|
-
}
|
|
1099
|
-
});
|
|
1124
|
+
register_traced_kind("branch");
|
|
1100
1125
|
//#endregion
|
|
1101
1126
|
//#region packages/core/src/map.ts
|
|
1102
1127
|
/**
|
|
@@ -1184,21 +1209,7 @@ function map(config) {
|
|
|
1184
1209
|
run: run_fn
|
|
1185
1210
|
};
|
|
1186
1211
|
}
|
|
1187
|
-
|
|
1188
|
-
const label = resolve_span_label(flow, "map");
|
|
1189
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1190
|
-
try {
|
|
1191
|
-
const out = await flow.run(input, ctx);
|
|
1192
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1193
|
-
return out;
|
|
1194
|
-
} catch (err) {
|
|
1195
|
-
ctx.trajectory.end_span(span_id, {
|
|
1196
|
-
id: flow.id,
|
|
1197
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1198
|
-
});
|
|
1199
|
-
throw err;
|
|
1200
|
-
}
|
|
1201
|
-
});
|
|
1212
|
+
register_traced_kind("map");
|
|
1202
1213
|
//#endregion
|
|
1203
1214
|
//#region packages/core/src/pipe.ts
|
|
1204
1215
|
/**
|
|
@@ -1229,30 +1240,21 @@ function pipe(inner, fn, options) {
|
|
|
1229
1240
|
run: run_fn
|
|
1230
1241
|
};
|
|
1231
1242
|
}
|
|
1232
|
-
|
|
1233
|
-
const label = resolve_span_label(flow, "pipe");
|
|
1234
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1235
|
-
try {
|
|
1236
|
-
const out = await flow.run(input, ctx);
|
|
1237
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1238
|
-
return out;
|
|
1239
|
-
} catch (err) {
|
|
1240
|
-
ctx.trajectory.end_span(span_id, {
|
|
1241
|
-
id: flow.id,
|
|
1242
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1243
|
-
});
|
|
1244
|
-
throw err;
|
|
1245
|
-
}
|
|
1246
|
-
});
|
|
1243
|
+
register_traced_kind("pipe");
|
|
1247
1244
|
//#endregion
|
|
1248
1245
|
//#region packages/core/src/retry.ts
|
|
1249
1246
|
/**
|
|
1250
1247
|
* retry: re-run on failure.
|
|
1251
1248
|
*
|
|
1252
1249
|
* `retry(inner, { max_attempts, backoff_ms?, on_error? })` runs `inner`. If it
|
|
1253
|
-
* throws, retries up to `max_attempts - 1` more times with
|
|
1254
|
-
* (`backoff_ms * 2^(attempt-1)`). `on_error` is called on
|
|
1255
|
-
* last error is rethrown if all attempts fail.
|
|
1250
|
+
* throws an application error, retries up to `max_attempts - 1` more times with
|
|
1251
|
+
* exponential backoff (`backoff_ms * 2^(attempt-1)`). `on_error` is called on
|
|
1252
|
+
* every such failure. The last error is rethrown if all attempts fail.
|
|
1253
|
+
*
|
|
1254
|
+
* Control-flow signals (`suspended_error`, `aborted_error`) are not failures:
|
|
1255
|
+
* they propagate immediately without consuming an attempt, firing `on_error`,
|
|
1256
|
+
* or scheduling a backoff. A suspend's `on()` side effect therefore runs once
|
|
1257
|
+
* per run, not once per attempt.
|
|
1256
1258
|
*
|
|
1257
1259
|
* Cancellation / cleanup (constraints.md §5.2, spec.md §6.8): cleanup handlers
|
|
1258
1260
|
* registered by the inner step accumulate across attempts. The parent
|
|
@@ -1300,6 +1302,7 @@ function retry(inner, config) {
|
|
|
1300
1302
|
try {
|
|
1301
1303
|
return await dispatch_step(inner, input, ctx);
|
|
1302
1304
|
} catch (err) {
|
|
1305
|
+
if (is_control_flow_error(err)) throw err;
|
|
1303
1306
|
last_err = err;
|
|
1304
1307
|
if (on_error) on_error(err, attempt);
|
|
1305
1308
|
if (attempt >= max_attempts) break;
|
|
@@ -1322,29 +1325,18 @@ function retry(inner, config) {
|
|
|
1322
1325
|
run: run_fn
|
|
1323
1326
|
};
|
|
1324
1327
|
}
|
|
1325
|
-
|
|
1326
|
-
const label = resolve_span_label(flow, "retry");
|
|
1327
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1328
|
-
try {
|
|
1329
|
-
const out = await flow.run(input, ctx);
|
|
1330
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1331
|
-
return out;
|
|
1332
|
-
} catch (err) {
|
|
1333
|
-
ctx.trajectory.end_span(span_id, {
|
|
1334
|
-
id: flow.id,
|
|
1335
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1336
|
-
});
|
|
1337
|
-
throw err;
|
|
1338
|
-
}
|
|
1339
|
-
});
|
|
1328
|
+
register_traced_kind("retry");
|
|
1340
1329
|
//#endregion
|
|
1341
1330
|
//#region packages/core/src/fallback.ts
|
|
1342
1331
|
/**
|
|
1343
1332
|
* fallback: primary-or-backup.
|
|
1344
1333
|
*
|
|
1345
|
-
* `fallback(primary, backup)` runs `primary`. If it throws
|
|
1346
|
-
* with the same input. If `backup` also throws, the
|
|
1347
|
-
* propagates.
|
|
1334
|
+
* `fallback(primary, backup)` runs `primary`. If it throws an application
|
|
1335
|
+
* error, runs `backup` with the same input. If `backup` also throws, the
|
|
1336
|
+
* `backup` error propagates. Control-flow signals (`suspended_error`,
|
|
1337
|
+
* `aborted_error`) are not failures: they propagate instead of triggering the
|
|
1338
|
+
* backup, so a human-approval gate is never silently bypassed and the backup
|
|
1339
|
+
* never runs under an aborted context. See spec.md §5.8.
|
|
1348
1340
|
*/
|
|
1349
1341
|
let fallback_counter = 0;
|
|
1350
1342
|
function next_id$4() {
|
|
@@ -1356,7 +1348,8 @@ function fallback(primary, backup, options) {
|
|
|
1356
1348
|
const run_fn = async (input, ctx) => {
|
|
1357
1349
|
try {
|
|
1358
1350
|
return await dispatch_step(primary, input, ctx);
|
|
1359
|
-
} catch {
|
|
1351
|
+
} catch (err) {
|
|
1352
|
+
if (is_control_flow_error(err)) throw err;
|
|
1360
1353
|
return dispatch_step(backup, input, ctx);
|
|
1361
1354
|
}
|
|
1362
1355
|
};
|
|
@@ -1369,21 +1362,7 @@ function fallback(primary, backup, options) {
|
|
|
1369
1362
|
run: run_fn
|
|
1370
1363
|
};
|
|
1371
1364
|
}
|
|
1372
|
-
|
|
1373
|
-
const label = resolve_span_label(flow, "fallback");
|
|
1374
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1375
|
-
try {
|
|
1376
|
-
const out = await flow.run(input, ctx);
|
|
1377
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1378
|
-
return out;
|
|
1379
|
-
} catch (err) {
|
|
1380
|
-
ctx.trajectory.end_span(span_id, {
|
|
1381
|
-
id: flow.id,
|
|
1382
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1383
|
-
});
|
|
1384
|
-
throw err;
|
|
1385
|
-
}
|
|
1386
|
-
});
|
|
1365
|
+
register_traced_kind("fallback");
|
|
1387
1366
|
//#endregion
|
|
1388
1367
|
//#region packages/core/src/timeout.ts
|
|
1389
1368
|
/**
|
|
@@ -1450,21 +1429,7 @@ function timeout(inner, ms, options) {
|
|
|
1450
1429
|
run: run_fn
|
|
1451
1430
|
};
|
|
1452
1431
|
}
|
|
1453
|
-
|
|
1454
|
-
const label = resolve_span_label(flow, "timeout");
|
|
1455
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1456
|
-
try {
|
|
1457
|
-
const out = await flow.run(input, ctx);
|
|
1458
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1459
|
-
return out;
|
|
1460
|
-
} catch (err) {
|
|
1461
|
-
ctx.trajectory.end_span(span_id, {
|
|
1462
|
-
id: flow.id,
|
|
1463
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1464
|
-
});
|
|
1465
|
-
throw err;
|
|
1466
|
-
}
|
|
1467
|
-
});
|
|
1432
|
+
register_traced_kind("timeout");
|
|
1468
1433
|
//#endregion
|
|
1469
1434
|
//#region packages/core/src/loop.ts
|
|
1470
1435
|
/**
|
|
@@ -1491,11 +1456,6 @@ function next_id$2(name) {
|
|
|
1491
1456
|
loop_counter += 1;
|
|
1492
1457
|
return `${name ?? "loop"}_${loop_counter}`;
|
|
1493
1458
|
}
|
|
1494
|
-
function throw_if_aborted$2(ctx) {
|
|
1495
|
-
if (!ctx.abort.aborted) return;
|
|
1496
|
-
const reason = ctx.abort.reason;
|
|
1497
|
-
throw reason instanceof Error ? reason : new aborted_error("aborted", { reason });
|
|
1498
|
-
}
|
|
1499
1459
|
function loop(config) {
|
|
1500
1460
|
const { init, body, guard, finish, name } = config;
|
|
1501
1461
|
const rounds_limit = Math.max(1, Math.floor(config.max_rounds));
|
|
@@ -1534,21 +1494,7 @@ function loop(config) {
|
|
|
1534
1494
|
run: run_fn
|
|
1535
1495
|
};
|
|
1536
1496
|
}
|
|
1537
|
-
|
|
1538
|
-
const label = resolve_span_label(flow, "loop");
|
|
1539
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1540
|
-
try {
|
|
1541
|
-
const out = await flow.run(input, ctx);
|
|
1542
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1543
|
-
return out;
|
|
1544
|
-
} catch (err) {
|
|
1545
|
-
ctx.trajectory.end_span(span_id, {
|
|
1546
|
-
id: flow.id,
|
|
1547
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1548
|
-
});
|
|
1549
|
-
throw err;
|
|
1550
|
-
}
|
|
1551
|
-
});
|
|
1497
|
+
register_traced_kind("loop");
|
|
1552
1498
|
//#endregion
|
|
1553
1499
|
//#region packages/core/src/compose.ts
|
|
1554
1500
|
/**
|
|
@@ -1583,21 +1529,7 @@ function compose(name, inner) {
|
|
|
1583
1529
|
run: run_fn
|
|
1584
1530
|
};
|
|
1585
1531
|
}
|
|
1586
|
-
|
|
1587
|
-
const label = resolve_span_label(flow, "compose");
|
|
1588
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1589
|
-
try {
|
|
1590
|
-
const out = await flow.run(input, ctx);
|
|
1591
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1592
|
-
return out;
|
|
1593
|
-
} catch (err) {
|
|
1594
|
-
ctx.trajectory.end_span(span_id, {
|
|
1595
|
-
id: flow.id,
|
|
1596
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1597
|
-
});
|
|
1598
|
-
throw err;
|
|
1599
|
-
}
|
|
1600
|
-
});
|
|
1532
|
+
register_traced_kind("compose");
|
|
1601
1533
|
//#endregion
|
|
1602
1534
|
//#region packages/core/src/checkpoint.ts
|
|
1603
1535
|
/**
|
|
@@ -1651,21 +1583,7 @@ function checkpoint(inner, config) {
|
|
|
1651
1583
|
run: run_fn
|
|
1652
1584
|
};
|
|
1653
1585
|
}
|
|
1654
|
-
|
|
1655
|
-
const label = resolve_span_label(flow, "checkpoint");
|
|
1656
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1657
|
-
try {
|
|
1658
|
-
const out = await flow.run(input, ctx);
|
|
1659
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1660
|
-
return out;
|
|
1661
|
-
} catch (err) {
|
|
1662
|
-
ctx.trajectory.end_span(span_id, {
|
|
1663
|
-
id: flow.id,
|
|
1664
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1665
|
-
});
|
|
1666
|
-
throw err;
|
|
1667
|
-
}
|
|
1668
|
-
});
|
|
1586
|
+
register_traced_kind("checkpoint");
|
|
1669
1587
|
//#endregion
|
|
1670
1588
|
//#region packages/core/src/suspend.ts
|
|
1671
1589
|
/**
|
|
@@ -1717,21 +1635,7 @@ function suspend(config) {
|
|
|
1717
1635
|
run: run_fn
|
|
1718
1636
|
};
|
|
1719
1637
|
}
|
|
1720
|
-
|
|
1721
|
-
const label = resolve_span_label(flow, "suspend");
|
|
1722
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1723
|
-
try {
|
|
1724
|
-
const out = await flow.run(input, ctx);
|
|
1725
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1726
|
-
return out;
|
|
1727
|
-
} catch (err) {
|
|
1728
|
-
ctx.trajectory.end_span(span_id, {
|
|
1729
|
-
id: flow.id,
|
|
1730
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1731
|
-
});
|
|
1732
|
-
throw err;
|
|
1733
|
-
}
|
|
1734
|
-
});
|
|
1638
|
+
register_traced_kind("suspend");
|
|
1735
1639
|
//#endregion
|
|
1736
1640
|
//#region packages/core/src/scope.ts
|
|
1737
1641
|
/**
|
|
@@ -1779,7 +1683,10 @@ function scope(children, options) {
|
|
|
1779
1683
|
state: local
|
|
1780
1684
|
};
|
|
1781
1685
|
let acc = input;
|
|
1782
|
-
for (const child of children_ref)
|
|
1686
|
+
for (const child of children_ref) {
|
|
1687
|
+
throw_if_aborted$2(scope_ctx);
|
|
1688
|
+
acc = await dispatch_step(child, acc, scope_ctx);
|
|
1689
|
+
}
|
|
1783
1690
|
return acc;
|
|
1784
1691
|
};
|
|
1785
1692
|
const config_meta = options?.name === void 0 ? void 0 : { display_name: options.name };
|
|
@@ -1826,51 +1733,9 @@ function use(keys, fn, options) {
|
|
|
1826
1733
|
run: run_fn
|
|
1827
1734
|
};
|
|
1828
1735
|
}
|
|
1829
|
-
|
|
1830
|
-
|
|
1831
|
-
|
|
1832
|
-
try {
|
|
1833
|
-
const out = await flow.run(input, ctx);
|
|
1834
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1835
|
-
return out;
|
|
1836
|
-
} catch (err) {
|
|
1837
|
-
ctx.trajectory.end_span(span_id, {
|
|
1838
|
-
id: flow.id,
|
|
1839
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1840
|
-
});
|
|
1841
|
-
throw err;
|
|
1842
|
-
}
|
|
1843
|
-
});
|
|
1844
|
-
register_kind("stash", async (flow, input, ctx) => {
|
|
1845
|
-
const label = resolve_span_label(flow, "stash");
|
|
1846
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1847
|
-
try {
|
|
1848
|
-
const out = await flow.run(input, ctx);
|
|
1849
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1850
|
-
return out;
|
|
1851
|
-
} catch (err) {
|
|
1852
|
-
ctx.trajectory.end_span(span_id, {
|
|
1853
|
-
id: flow.id,
|
|
1854
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1855
|
-
});
|
|
1856
|
-
throw err;
|
|
1857
|
-
}
|
|
1858
|
-
});
|
|
1859
|
-
register_kind("use", async (flow, input, ctx) => {
|
|
1860
|
-
const label = resolve_span_label(flow, "use");
|
|
1861
|
-
const span_id = ctx.trajectory.start_span(label, { id: flow.id });
|
|
1862
|
-
try {
|
|
1863
|
-
const out = await flow.run(input, ctx);
|
|
1864
|
-
ctx.trajectory.end_span(span_id, { id: flow.id });
|
|
1865
|
-
return out;
|
|
1866
|
-
} catch (err) {
|
|
1867
|
-
ctx.trajectory.end_span(span_id, {
|
|
1868
|
-
id: flow.id,
|
|
1869
|
-
error: err instanceof Error ? err.message : String(err)
|
|
1870
|
-
});
|
|
1871
|
-
throw err;
|
|
1872
|
-
}
|
|
1873
|
-
});
|
|
1736
|
+
register_traced_kind("scope");
|
|
1737
|
+
register_traced_kind("stash");
|
|
1738
|
+
register_traced_kind("use");
|
|
1874
1739
|
//#endregion
|
|
1875
1740
|
//#region packages/core/src/step_kinds.ts
|
|
1876
1741
|
/**
|
|
@@ -1950,7 +1815,7 @@ const trajectory_event_schema = z.union([
|
|
|
1950
1815
|
]);
|
|
1951
1816
|
//#endregion
|
|
1952
1817
|
//#region packages/core/src/version.ts
|
|
1953
|
-
const version = "0.
|
|
1818
|
+
const version = "0.6.0";
|
|
1954
1819
|
//#endregion
|
|
1955
1820
|
//#region packages/core/src/index.ts
|
|
1956
1821
|
/**
|
|
@@ -2599,171 +2464,6 @@ function tournament(config) {
|
|
|
2599
2464
|
return compose(config.name ?? "tournament", inner);
|
|
2600
2465
|
}
|
|
2601
2466
|
//#endregion
|
|
2602
|
-
//#region packages/observability/src/filesystem.ts
|
|
2603
|
-
/**
|
|
2604
|
-
* Filesystem JSONL trajectory logger.
|
|
2605
|
-
*
|
|
2606
|
-
* Appends one JSON object per line to a configured output file. `start_span`
|
|
2607
|
-
* and `end_span` each emit a line; `record` emits a line with the event as
|
|
2608
|
-
* written. Hierarchical span ids are tracked via an in-memory stack: when
|
|
2609
|
-
* `start_span` fires, the innermost still-open span's id is attached as
|
|
2610
|
-
* `parent_span_id` on the new span's record. This is best-effort for
|
|
2611
|
-
* concurrent children (two siblings spawned from the same parent will see
|
|
2612
|
-
* whichever opened most recently as their parent until proper async-context
|
|
2613
|
-
* propagation is wired). Two concurrent `run(...)` calls that pass distinct
|
|
2614
|
-
* logger instances (constructed with distinct `output_path`s) share nothing.
|
|
2615
|
-
*
|
|
2616
|
-
* Paths are accepted at construction; the logger never reads `process.env`.
|
|
2617
|
-
*/
|
|
2618
|
-
function filesystem_logger(options) {
|
|
2619
|
-
const { output_path } = options;
|
|
2620
|
-
mkdirSync(dirname(output_path), { recursive: true });
|
|
2621
|
-
const stack = [];
|
|
2622
|
-
const write_line = (event) => {
|
|
2623
|
-
appendFileSync(output_path, `${JSON.stringify(event)}\n`);
|
|
2624
|
-
};
|
|
2625
|
-
const start_span = (name, meta) => {
|
|
2626
|
-
const span_id = `${name}:${randomUUID().slice(0, 8)}`;
|
|
2627
|
-
const parent_span_id = stack.length > 0 ? stack[stack.length - 1] : void 0;
|
|
2628
|
-
const event = {
|
|
2629
|
-
kind: "span_start",
|
|
2630
|
-
span_id,
|
|
2631
|
-
name,
|
|
2632
|
-
...meta
|
|
2633
|
-
};
|
|
2634
|
-
if (parent_span_id !== void 0) event["parent_span_id"] = parent_span_id;
|
|
2635
|
-
write_line(event);
|
|
2636
|
-
stack.push(span_id);
|
|
2637
|
-
return span_id;
|
|
2638
|
-
};
|
|
2639
|
-
const end_span = (id, meta) => {
|
|
2640
|
-
write_line({
|
|
2641
|
-
kind: "span_end",
|
|
2642
|
-
span_id: id,
|
|
2643
|
-
...meta
|
|
2644
|
-
});
|
|
2645
|
-
const idx = stack.lastIndexOf(id);
|
|
2646
|
-
if (idx !== -1) stack.splice(idx, 1);
|
|
2647
|
-
};
|
|
2648
|
-
const record = (event) => {
|
|
2649
|
-
write_line({ ...event });
|
|
2650
|
-
};
|
|
2651
|
-
return {
|
|
2652
|
-
record,
|
|
2653
|
-
start_span,
|
|
2654
|
-
end_span
|
|
2655
|
-
};
|
|
2656
|
-
}
|
|
2657
|
-
//#endregion
|
|
2658
|
-
//#region packages/observability/src/http.ts
|
|
2659
|
-
/**
|
|
2660
|
-
* HTTP push trajectory logger.
|
|
2661
|
-
*
|
|
2662
|
-
* Conforms to `TrajectoryLogger`. POSTs each event as a single line of
|
|
2663
|
-
* newline-delimited JSON to a configured URL. Pairs naturally with the
|
|
2664
|
-
* fascicle viewer's `/api/ingest` endpoint, but is a generic adapter — the
|
|
2665
|
-
* receiver can be anything that accepts NDJSON over HTTP.
|
|
2666
|
-
*
|
|
2667
|
-
* Failure policy: drop on transport error and invoke the optional `on_error`
|
|
2668
|
-
* callback. Never throws, never blocks the user's flow on a dev tool being
|
|
2669
|
-
* up. The flow always wins; the viewer is best-effort.
|
|
2670
|
-
*
|
|
2671
|
-
* Hierarchical span ids are tracked in-process, mirroring `filesystem_logger`
|
|
2672
|
-
* so the wire format is identical.
|
|
2673
|
-
*/
|
|
2674
|
-
const default_fetch = async (url, init) => {
|
|
2675
|
-
const res = await fetch(url, init);
|
|
2676
|
-
return {
|
|
2677
|
-
ok: res.ok,
|
|
2678
|
-
status: res.status
|
|
2679
|
-
};
|
|
2680
|
-
};
|
|
2681
|
-
function http_logger(options) {
|
|
2682
|
-
const { url, on_error } = options;
|
|
2683
|
-
const send = options.fetch ?? default_fetch;
|
|
2684
|
-
const stack = [];
|
|
2685
|
-
const post = (event) => {
|
|
2686
|
-
send(url, {
|
|
2687
|
-
method: "POST",
|
|
2688
|
-
headers: { "content-type": "application/x-ndjson" },
|
|
2689
|
-
body: `${JSON.stringify(event)}\n`
|
|
2690
|
-
}).then((res) => {
|
|
2691
|
-
if (!res.ok && on_error) on_error(/* @__PURE__ */ new Error(`http_logger: POST ${url} -> ${res.status}`));
|
|
2692
|
-
}).catch((err) => {
|
|
2693
|
-
if (on_error) on_error(err);
|
|
2694
|
-
});
|
|
2695
|
-
};
|
|
2696
|
-
const start_span = (name, meta) => {
|
|
2697
|
-
const span_id = `${name}:${randomUUID().slice(0, 8)}`;
|
|
2698
|
-
const parent_span_id = stack.length > 0 ? stack[stack.length - 1] : void 0;
|
|
2699
|
-
const event = {
|
|
2700
|
-
kind: "span_start",
|
|
2701
|
-
span_id,
|
|
2702
|
-
name,
|
|
2703
|
-
...meta
|
|
2704
|
-
};
|
|
2705
|
-
if (parent_span_id !== void 0) event["parent_span_id"] = parent_span_id;
|
|
2706
|
-
post(event);
|
|
2707
|
-
stack.push(span_id);
|
|
2708
|
-
return span_id;
|
|
2709
|
-
};
|
|
2710
|
-
const end_span = (id, meta) => {
|
|
2711
|
-
post({
|
|
2712
|
-
kind: "span_end",
|
|
2713
|
-
span_id: id,
|
|
2714
|
-
...meta
|
|
2715
|
-
});
|
|
2716
|
-
const idx = stack.lastIndexOf(id);
|
|
2717
|
-
if (idx !== -1) stack.splice(idx, 1);
|
|
2718
|
-
};
|
|
2719
|
-
const record = (event) => {
|
|
2720
|
-
post({ ...event });
|
|
2721
|
-
};
|
|
2722
|
-
return {
|
|
2723
|
-
record,
|
|
2724
|
-
start_span,
|
|
2725
|
-
end_span
|
|
2726
|
-
};
|
|
2727
|
-
}
|
|
2728
|
-
//#endregion
|
|
2729
|
-
//#region packages/observability/src/tee.ts
|
|
2730
|
-
function tee_logger(...loggers) {
|
|
2731
|
-
if (loggers.length === 0) throw new Error("tee_logger: at least one logger required");
|
|
2732
|
-
const id_map = /* @__PURE__ */ new Map();
|
|
2733
|
-
const safe_each = (fn) => {
|
|
2734
|
-
for (let i = 0; i < loggers.length; i += 1) {
|
|
2735
|
-
const l = loggers[i];
|
|
2736
|
-
if (l === void 0) continue;
|
|
2737
|
-
try {
|
|
2738
|
-
fn(l, i);
|
|
2739
|
-
} catch {}
|
|
2740
|
-
}
|
|
2741
|
-
};
|
|
2742
|
-
return {
|
|
2743
|
-
record: (event) => {
|
|
2744
|
-
safe_each((l) => l.record(event));
|
|
2745
|
-
},
|
|
2746
|
-
start_span: (name, meta) => {
|
|
2747
|
-
const ids = [];
|
|
2748
|
-
safe_each((l) => {
|
|
2749
|
-
ids.push(l.start_span(name, meta));
|
|
2750
|
-
});
|
|
2751
|
-
const canonical = ids[0] ?? `${name}:tee`;
|
|
2752
|
-
if (loggers.length > 1) id_map.set(canonical, ids);
|
|
2753
|
-
return canonical;
|
|
2754
|
-
},
|
|
2755
|
-
end_span: (id, meta) => {
|
|
2756
|
-
const ids = id_map.get(id);
|
|
2757
|
-
if (ids === void 0) {
|
|
2758
|
-
safe_each((l) => l.end_span(id, meta));
|
|
2759
|
-
return;
|
|
2760
|
-
}
|
|
2761
|
-
id_map.delete(id);
|
|
2762
|
-
safe_each((l, idx) => l.end_span(ids[idx] ?? id, meta));
|
|
2763
|
-
}
|
|
2764
|
-
};
|
|
2765
|
-
}
|
|
2766
|
-
//#endregion
|
|
2767
2467
|
//#region packages/composites/src/bench.ts
|
|
2768
2468
|
/**
|
|
2769
2469
|
* bench: run a flow against a fixture set, score each result, return a report.
|
|
@@ -3205,7 +2905,7 @@ function validate_report(value, path) {
|
|
|
3205
2905
|
}
|
|
3206
2906
|
//#endregion
|
|
3207
2907
|
//#region packages/engine/src/version.ts
|
|
3208
|
-
const version$1 = "0.
|
|
2908
|
+
const version$1 = "0.6.0";
|
|
3209
2909
|
//#endregion
|
|
3210
2910
|
//#region packages/engine/src/errors.ts
|
|
3211
2911
|
var rate_limit_error = class extends Error {
|
|
@@ -3745,7 +3445,7 @@ function translate_anthropic_effort(effort) {
|
|
|
3745
3445
|
return {
|
|
3746
3446
|
provider_options: { anthropic: { thinking: {
|
|
3747
3447
|
type: "enabled",
|
|
3748
|
-
|
|
3448
|
+
budgetTokens: budget
|
|
3749
3449
|
} } },
|
|
3750
3450
|
effort_ignored: false
|
|
3751
3451
|
};
|
|
@@ -3832,11 +3532,11 @@ const create_openai_adapter = (init) => {
|
|
|
3832
3532
|
//#endregion
|
|
3833
3533
|
//#region packages/engine/src/providers/google.ts
|
|
3834
3534
|
const GOOGLE_THINKING_BUDGET = {
|
|
3835
|
-
low:
|
|
3836
|
-
medium:
|
|
3837
|
-
high:
|
|
3838
|
-
xhigh:
|
|
3839
|
-
max:
|
|
3535
|
+
low: 1024,
|
|
3536
|
+
medium: 8192,
|
|
3537
|
+
high: 24576,
|
|
3538
|
+
xhigh: 32768,
|
|
3539
|
+
max: 32768
|
|
3840
3540
|
};
|
|
3841
3541
|
function translate_google_effort(effort) {
|
|
3842
3542
|
if (effort === "none") return {
|
|
@@ -4204,7 +3904,7 @@ function build_bwrap_args(binary, sandbox) {
|
|
|
4204
3904
|
if (allowlist.length > 0) {
|
|
4205
3905
|
args.push("--share-net");
|
|
4206
3906
|
for (const host of allowlist) args.push("--setenv", "CLAUDE_CLI_NET_ALLOW", host);
|
|
4207
|
-
}
|
|
3907
|
+
} else args.push("--unshare-net");
|
|
4208
3908
|
const write_paths = sandbox.additional_write_paths ?? [];
|
|
4209
3909
|
for (const p of write_paths) args.push("--bind", p, p);
|
|
4210
3910
|
args.push("--");
|
|
@@ -4973,6 +4673,7 @@ function tool_call_record(step_index, call, results, now) {
|
|
|
4973
4673
|
}
|
|
4974
4674
|
function build_generate_result(input) {
|
|
4975
4675
|
const { parsed, resolved } = input;
|
|
4676
|
+
if (parsed.is_error) throw new claude_cli_error("result_error", parsed.final_text.length > 0 ? parsed.final_text : "claude_cli returned an error result");
|
|
4976
4677
|
const turns = normalize_turns(parsed);
|
|
4977
4678
|
const now = Date.now();
|
|
4978
4679
|
const turn_usages = turns.map((t) => ({
|
|
@@ -5166,6 +4867,57 @@ function record_tool_call(trajectory, meta) {
|
|
|
5166
4867
|
...event
|
|
5167
4868
|
});
|
|
5168
4869
|
}
|
|
4870
|
+
/**
|
|
4871
|
+
* Record a resolved tool call's result. `record_tool_call` captures the request
|
|
4872
|
+
* (input); without this event a successful tool's output never reaches the
|
|
4873
|
+
* trajectory, leaving the run record blind to what tools actually returned.
|
|
4874
|
+
*/
|
|
4875
|
+
function record_tool_result(trajectory, meta) {
|
|
4876
|
+
if (trajectory === void 0) return;
|
|
4877
|
+
const event = {
|
|
4878
|
+
kind: "tool_result",
|
|
4879
|
+
step_index: meta.step_index,
|
|
4880
|
+
name: meta.name,
|
|
4881
|
+
tool_call_id: meta.tool_call_id,
|
|
4882
|
+
duration_ms: meta.duration_ms
|
|
4883
|
+
};
|
|
4884
|
+
if (meta.error !== void 0) event["error"] = meta.error;
|
|
4885
|
+
else event["output"] = meta.output;
|
|
4886
|
+
trajectory.record({
|
|
4887
|
+
kind: "tool_result",
|
|
4888
|
+
...event
|
|
4889
|
+
});
|
|
4890
|
+
}
|
|
4891
|
+
/**
|
|
4892
|
+
* Wrap a logger so engine events carry a `ts` (epoch milliseconds) even when
|
|
4893
|
+
* generate is called directly with a caller-supplied logger rather than through
|
|
4894
|
+
* the core runner. When the logger is already runner-decorated, the existing
|
|
4895
|
+
* `ts` is preserved. Private to the engine to avoid widening the public surface.
|
|
4896
|
+
*/
|
|
4897
|
+
function stamp_ts(meta) {
|
|
4898
|
+
const out = { ...meta };
|
|
4899
|
+
if (!("ts" in out)) out["ts"] = Date.now();
|
|
4900
|
+
return out;
|
|
4901
|
+
}
|
|
4902
|
+
function with_timestamps(inner) {
|
|
4903
|
+
if (inner === void 0) return void 0;
|
|
4904
|
+
return {
|
|
4905
|
+
record: (event) => {
|
|
4906
|
+
if ("ts" in event) {
|
|
4907
|
+
inner.record(event);
|
|
4908
|
+
return;
|
|
4909
|
+
}
|
|
4910
|
+
inner.record({
|
|
4911
|
+
...event,
|
|
4912
|
+
ts: Date.now()
|
|
4913
|
+
});
|
|
4914
|
+
},
|
|
4915
|
+
start_span: (name, meta) => inner.start_span(name, stamp_ts(meta)),
|
|
4916
|
+
end_span: (id, meta) => {
|
|
4917
|
+
inner.end_span(id, stamp_ts(meta));
|
|
4918
|
+
}
|
|
4919
|
+
};
|
|
4920
|
+
}
|
|
5169
4921
|
function record_cost(trajectory, step_index, cost, source) {
|
|
5170
4922
|
if (trajectory === void 0) return;
|
|
5171
4923
|
const event = {
|
|
@@ -5378,7 +5130,7 @@ function create_claude_cli_adapter(init) {
|
|
|
5378
5130
|
async generate(opts, resolved) {
|
|
5379
5131
|
if (disposed) throw new engine_disposed_error();
|
|
5380
5132
|
if (opts.abort?.aborted === true) throw new aborted_error("aborted", { reason: opts.abort.reason });
|
|
5381
|
-
const trajectory = opts.trajectory;
|
|
5133
|
+
const trajectory = with_timestamps(opts.trajectory);
|
|
5382
5134
|
const call_opts = extract_call_opts(opts);
|
|
5383
5135
|
const option_ignored = create_option_ignored_dedup(trajectory);
|
|
5384
5136
|
if (opts.max_steps !== void 0) option_ignored.emit("max_steps", PROVIDER_NAME);
|
|
@@ -6083,6 +5835,13 @@ async function run_tool_loop(config) {
|
|
|
6083
5835
|
});
|
|
6084
5836
|
await dispatch_tool_result_chunk(config.dispatch_chunk, step_index, raw_call.id, output);
|
|
6085
5837
|
}
|
|
5838
|
+
for (const r of step_tool_records) record_tool_result(config.trajectory, {
|
|
5839
|
+
step_index,
|
|
5840
|
+
name: r.name,
|
|
5841
|
+
tool_call_id: r.id,
|
|
5842
|
+
duration_ms: r.duration_ms,
|
|
5843
|
+
...r.error !== void 0 ? { error: r.error } : { output: r.output }
|
|
5844
|
+
});
|
|
6086
5845
|
for (const m of tool_results_to_feed) config.messages.push(m);
|
|
6087
5846
|
const turn_finish_reason = would_exceed_after ? "max_steps" : turn.finish_reason;
|
|
6088
5847
|
const step_record = {
|
|
@@ -6434,7 +6193,7 @@ async function generate(opts_in, engine) {
|
|
|
6434
6193
|
const adapter = engine.adapters.get(target.provider);
|
|
6435
6194
|
if (adapter === void 0) throw new provider_not_configured_error(target.provider);
|
|
6436
6195
|
if (adapter.kind === "subprocess") return adapter.generate(opts, target);
|
|
6437
|
-
const trajectory = opts.trajectory;
|
|
6196
|
+
const trajectory = with_timestamps(opts.trajectory);
|
|
6438
6197
|
const on_chunk_provided = opts.on_chunk !== void 0;
|
|
6439
6198
|
const tools_list = opts.tools ?? [];
|
|
6440
6199
|
if (opts.schema !== void 0 && !adapter.supports("schema")) throw new provider_capability_error(target.provider, "schema");
|
|
@@ -6443,7 +6202,8 @@ async function generate(opts_in, engine) {
|
|
|
6443
6202
|
const effort = opts.effort ?? engine.default_effort;
|
|
6444
6203
|
const effort_translation = adapter.translate_effort(effort);
|
|
6445
6204
|
if (effort !== "none" && effort_translation.effort_ignored) record_effort_ignored(trajectory, target.model_id);
|
|
6446
|
-
const
|
|
6205
|
+
const combined_provider_options = merge_provider_options(effort_translation.provider_options, opts.provider_options);
|
|
6206
|
+
const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
|
|
6447
6207
|
const abort = opts.abort ?? new AbortController().signal;
|
|
6448
6208
|
const max_steps = opts.max_steps ?? engine.default_max_steps;
|
|
6449
6209
|
const tool_error_policy = opts.tool_error_policy ?? engine.default_tool_error_policy ?? "feed_back";
|
|
@@ -6769,6 +6529,38 @@ function create_engine(config) {
|
|
|
6769
6529
|
* plumbing. Cost events flow out via ctx.trajectory per the engine's own
|
|
6770
6530
|
* emission rules (constraints §5.3).
|
|
6771
6531
|
*/
|
|
6532
|
+
/**
|
|
6533
|
+
* Wrap the run's trajectory so the engine's own spans (engine.generate and its
|
|
6534
|
+
* step spans) nest under the model_call step rather than floating. The wrapper
|
|
6535
|
+
* keeps a private span stack seeded with the model_call step's id, so nesting
|
|
6536
|
+
* is correct and concurrency-safe even when several model_calls run together
|
|
6537
|
+
* under `parallel`/`map` (each invocation builds its own wrapper). A
|
|
6538
|
+
* caller-supplied `parent_span_id` is never overridden.
|
|
6539
|
+
*/
|
|
6540
|
+
function engine_trajectory(inner, root_parent) {
|
|
6541
|
+
const stack = root_parent !== void 0 ? [root_parent] : [];
|
|
6542
|
+
return {
|
|
6543
|
+
record: (event) => {
|
|
6544
|
+
inner.record(event);
|
|
6545
|
+
},
|
|
6546
|
+
start_span: (name, meta) => {
|
|
6547
|
+
const has_parent = meta !== void 0 && "parent_span_id" in meta;
|
|
6548
|
+
const parent = stack.length > 0 ? stack[stack.length - 1] : void 0;
|
|
6549
|
+
const next_meta = has_parent || parent === void 0 ? meta : {
|
|
6550
|
+
...meta,
|
|
6551
|
+
parent_span_id: parent
|
|
6552
|
+
};
|
|
6553
|
+
const id = inner.start_span(name, next_meta);
|
|
6554
|
+
stack.push(id);
|
|
6555
|
+
return id;
|
|
6556
|
+
},
|
|
6557
|
+
end_span: (id, meta) => {
|
|
6558
|
+
inner.end_span(id, meta);
|
|
6559
|
+
const idx = stack.lastIndexOf(id);
|
|
6560
|
+
if (idx !== -1) stack.splice(idx, 1);
|
|
6561
|
+
}
|
|
6562
|
+
};
|
|
6563
|
+
}
|
|
6772
6564
|
function stable_signature(input) {
|
|
6773
6565
|
const payload = JSON.stringify({
|
|
6774
6566
|
model: input.model ?? null,
|
|
@@ -6812,7 +6604,7 @@ function model_call(cfg) {
|
|
|
6812
6604
|
}]
|
|
6813
6605
|
}] : [...input],
|
|
6814
6606
|
abort: ctx.abort,
|
|
6815
|
-
trajectory: ctx.trajectory
|
|
6607
|
+
trajectory: engine_trajectory(ctx.trajectory, ctx.parent_span_id)
|
|
6816
6608
|
};
|
|
6817
6609
|
if (cfg.model !== void 0) opts.model = cfg.model;
|
|
6818
6610
|
if (cfg.provider !== void 0) opts.provider = cfg.provider;
|
|
@@ -7414,6 +7206,6 @@ function wrap_handle(server, tail, host, port) {
|
|
|
7414
7206
|
};
|
|
7415
7207
|
}
|
|
7416
7208
|
//#endregion
|
|
7417
|
-
export { STEP_KINDS, aborted_error, adversarial, bench, branch, checkpoint, compose, consensus, version as core_version, create_engine, custom_event_schema, describe, describe_cycle_error, emit_event_schema, engine_config_error, version$1 as engine_version, ensemble, ensemble_step, fallback, flow_schema, forward_standard_env, improve, is_step_kind, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_not_found_error, normalize_score, on_chunk_error, parallel, pipe, provider_capability_error, provider_error, provider_not_configured_error, rate_limit_error, read_baseline, regression_compare, resume_validation_error, retry, run, run_viewer_cli, schema_validation_error, scope, sequence, span_end_event_schema, span_start_event_schema, start_viewer, stash, step, suspend, suspended_error, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, trajectory_event_schema, use, write_baseline };
|
|
7209
|
+
export { STEP_KINDS, aborted_error, adversarial, bench, branch, checkpoint, claude_cli_error, compose, consensus, version as core_version, create_engine, custom_event_schema, describe, describe_cycle_error, emit_event_schema, engine_config_error, engine_disposed_error, version$1 as engine_version, ensemble, ensemble_step, fallback, flow_schema, forward_standard_env, improve, is_step_kind, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_family_unavailable_error, model_not_found_error, normalize_score, on_chunk_error, parallel, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, rate_limit_error, read_baseline, regression_compare, resume_validation_error, retry, run, run_viewer_cli, schema_validation_error, scope, sequence, span_end_event_schema, span_start_event_schema, start_viewer, stash, step, suspend, suspended_error, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, trajectory_event_schema, use, write_baseline };
|
|
7418
7210
|
|
|
7419
7211
|
//# sourceMappingURL=index.js.map
|