fascicle 0.11.1 → 0.12.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 +32 -0
- package/README.md +26 -27
- package/dist/adapters.d.ts +1 -1
- package/dist/agents.d.ts +2 -2
- package/dist/agents.js +1 -1
- package/dist/{core-DgH4mDbK.js → core-BkB2l1-e.js} +257 -16
- package/dist/core-BkB2l1-e.js.map +1 -0
- package/dist/index.d.ts +251 -86
- package/dist/index.js +66 -22
- package/dist/index.js.map +1 -1
- package/dist/{invoke-BjrbCBSV.js → invoke-JkzNf7-Y.js} +3 -3
- package/dist/{invoke-BjrbCBSV.js.map → invoke-JkzNf7-Y.js.map} +1 -1
- package/dist/{leading_system-CpkjHoCQ.js → leading_system-BVtGMweY.js} +2 -2
- package/dist/{leading_system-CpkjHoCQ.js.map → leading_system-BVtGMweY.js.map} +1 -1
- package/dist/mcp.d.ts +2 -2
- package/dist/mcp.js +1 -1
- package/dist/otel.d.ts +1 -1
- package/dist/stdio.d.ts +1 -1
- package/dist/stdio.js +1 -1
- package/dist/testing.d.ts +39 -0
- package/dist/testing.js +90 -0
- package/dist/testing.js.map +1 -0
- package/dist/{types-B3HIsBBD.d.ts → types-4l54cexm.d.ts} +2 -2
- package/dist/{types-BDSbSUAO.d.ts → types-CVdTBXE_.d.ts} +13 -4
- package/dist/ui.d.ts +1 -1
- package/package.json +7 -2
- package/dist/core-DgH4mDbK.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { A as
|
|
1
|
+
import { A as run, C as pipe, D as sequence, E as parallel, F as timeout_error, I as flow_schema_default, M as describe_cycle_error, N as resume_validation_error, O as describe, P as suspended_error, S as wait_with_abort, T as branch, _ as loop, a as parse_trajectory_event, b as retry, c as chain, d as use, f as suspend, g as compose, h as checkpoint, i as is_span_start_event, j as aborted_error, k as step, l as scope, m as validate_schema, n as is_emit_event, o as STEP_KINDS, p as format_schema_issues, r as is_span_end_event, s as is_step_kind, t as is_custom_trajectory_event, u as stash, v as timeout, w as map, x as compute_backoff, y as fallback } from "./core-BkB2l1-e.js";
|
|
2
2
|
import { a as http_logger, n as tee_logger, o as filesystem_logger } from "./adapters-hmnJOOgf.js";
|
|
3
|
-
import { _ as rate_limit_error, a as normalize_local_usage, b as tool_error, c as engine_config_error, d as model_required_error, f as on_chunk_error, g as provider_not_configured_error, h as provider_error, i as missing_peer_error, l as engine_disposed_error, m as provider_capability_error, n as default_normalize_usage, o as resolve_transport, p as provider_auth_error, r as load_optional_peer, s as claude_cli_error, t as split_leading_system_run, u as incomplete_generation_error, v as schema_validation_error, x as turn_timeout_error, y as tool_approval_denied_error } from "./leading_system-
|
|
3
|
+
import { _ as rate_limit_error, a as normalize_local_usage, b as tool_error, c as engine_config_error, d as model_required_error, f as on_chunk_error, g as provider_not_configured_error, h as provider_error, i as missing_peer_error, l as engine_disposed_error, m as provider_capability_error, n as default_normalize_usage, o as resolve_transport, p as provider_auth_error, r as load_optional_peer, s as claude_cli_error, t as split_leading_system_run, u as incomplete_generation_error, v as schema_validation_error, x as turn_timeout_error, y as tool_approval_denied_error } from "./leading_system-BVtGMweY.js";
|
|
4
4
|
import { createHash } from "node:crypto";
|
|
5
5
|
import { mkdir, open, readFile, readdir, stat, writeFile } from "node:fs/promises";
|
|
6
6
|
import { dirname, join, resolve } from "node:path";
|
|
@@ -180,7 +180,9 @@ function build_input_from_state(s) {
|
|
|
180
180
|
* Each round builds a candidate (receiving the prior candidate and critique
|
|
181
181
|
* notes when available), critiques it, then checks `accept(critique_result)`.
|
|
182
182
|
* Returns `{ candidate, converged, rounds }`. Does not throw on
|
|
183
|
-
* non-convergence; `converged: false` reports it instead.
|
|
183
|
+
* non-convergence; `converged: false` reports it instead. `project` maps
|
|
184
|
+
* that envelope into the step's output (e.g. `(r) => r.candidate`); omitted,
|
|
185
|
+
* the envelope itself is the output.
|
|
184
186
|
*
|
|
185
187
|
* Implemented as a `compose`d `loop` whose body builds a new candidate and
|
|
186
188
|
* whose guard runs the critique step and checks `accept`. State is threaded
|
|
@@ -189,6 +191,7 @@ function build_input_from_state(s) {
|
|
|
189
191
|
*/
|
|
190
192
|
function adversarial(config) {
|
|
191
193
|
const { build, critique, accept, max_rounds } = config;
|
|
194
|
+
const project = config.project ?? ((r) => r);
|
|
192
195
|
const inner = loop({
|
|
193
196
|
init: (input) => ({ input }),
|
|
194
197
|
body: scope([
|
|
@@ -223,11 +226,11 @@ function adversarial(config) {
|
|
|
223
226
|
]),
|
|
224
227
|
finish: (s, { converged, rounds }) => {
|
|
225
228
|
if (s.candidate === void 0) throw new Error("adversarial: finished without a candidate");
|
|
226
|
-
return {
|
|
229
|
+
return project({
|
|
227
230
|
candidate: s.candidate,
|
|
228
231
|
converged,
|
|
229
232
|
rounds
|
|
230
|
-
};
|
|
233
|
+
});
|
|
231
234
|
},
|
|
232
235
|
max_rounds
|
|
233
236
|
});
|
|
@@ -245,6 +248,8 @@ function adversarial(config) {
|
|
|
245
248
|
* On agreement, returns the round's results with `converged: true`.
|
|
246
249
|
* Otherwise re-runs all members up to `max_rounds` times and returns the
|
|
247
250
|
* last results with `converged: false` if no agreement is reached.
|
|
251
|
+
* `project` maps the `{ result, converged }` envelope into the step's output
|
|
252
|
+
* (e.g. `(r) => r.converged`); omitted, the envelope itself is the output.
|
|
248
253
|
*
|
|
249
254
|
* Implemented as a `compose`d `loop` whose body runs `parallel(members)` and
|
|
250
255
|
* whose guard evaluates `agree`. State carries the original input alongside
|
|
@@ -252,6 +257,7 @@ function adversarial(config) {
|
|
|
252
257
|
*/
|
|
253
258
|
function consensus(config) {
|
|
254
259
|
const { members, agree, max_rounds } = config;
|
|
260
|
+
const project = config.project ?? ((r) => r);
|
|
255
261
|
const round_step = parallel(members);
|
|
256
262
|
const inner = loop({
|
|
257
263
|
init: (input) => ({
|
|
@@ -273,7 +279,7 @@ function consensus(config) {
|
|
|
273
279
|
stop: agree(s.results),
|
|
274
280
|
state: s
|
|
275
281
|
})),
|
|
276
|
-
finish: (s, { converged }) => ({
|
|
282
|
+
finish: (s, { converged }) => project({
|
|
277
283
|
result: s.results,
|
|
278
284
|
converged
|
|
279
285
|
}),
|
|
@@ -292,7 +298,9 @@ function consensus(config) {
|
|
|
292
298
|
*
|
|
293
299
|
* `select` picks the highest (`'max'`, the default) or lowest (`'min'`)
|
|
294
300
|
* score. Tie-breaking is "any tied result is acceptable": the first member
|
|
295
|
-
* (in `members` key order) holding the best score wins.
|
|
301
|
+
* (in `members` key order) holding the best score wins. `project` maps the
|
|
302
|
+
* `{ winner, scores }` envelope into the step's output (e.g. `(r) =>
|
|
303
|
+
* r.winner`); omitted, the envelope itself is the output.
|
|
296
304
|
*
|
|
297
305
|
* Implemented as a `compose`d `sequence` of `parallel(members)` followed by
|
|
298
306
|
* a single picking step. Cancellation, fan-out, and abort propagation come
|
|
@@ -302,6 +310,7 @@ function ensemble(config) {
|
|
|
302
310
|
const select = config.select ?? "max";
|
|
303
311
|
const score_fn = config.score;
|
|
304
312
|
const keys = Object.keys(config.members);
|
|
313
|
+
const project = config.project ?? ((r) => r);
|
|
305
314
|
const inner = sequence([parallel(config.members), step("pick_winner", async (results) => {
|
|
306
315
|
const scores = {};
|
|
307
316
|
for (const k of keys) {
|
|
@@ -327,10 +336,10 @@ function ensemble(config) {
|
|
|
327
336
|
if (winner_key === void 0) throw new Error("ensemble: no members produced a result");
|
|
328
337
|
const winner = results[winner_key];
|
|
329
338
|
if (winner === void 0) throw new Error("ensemble: winner missing from results");
|
|
330
|
-
return {
|
|
339
|
+
return project({
|
|
331
340
|
winner,
|
|
332
341
|
scores
|
|
333
|
-
};
|
|
342
|
+
});
|
|
334
343
|
})]);
|
|
335
344
|
return compose(config.name ?? "ensemble", inner);
|
|
336
345
|
}
|
|
@@ -353,7 +362,9 @@ const ITEM_KEY = "__ensemble_step_item";
|
|
|
353
362
|
*
|
|
354
363
|
* The result carries `winner_scored`, the structured output from the round's
|
|
355
364
|
* scoring run preserved verbatim, so callers never pay to re-score the
|
|
356
|
-
* winner. `scored` holds the structured score for every member.
|
|
365
|
+
* winner. `scored` holds the structured score for every member. `project`
|
|
366
|
+
* maps that envelope into the step's output (e.g. `(r) => r.winner`);
|
|
367
|
+
* omitted, the envelope itself is the output.
|
|
357
368
|
*
|
|
358
369
|
* Implemented as a `compose`d `scope` over (`stash(parallel(members))` ->
|
|
359
370
|
* `to_pairs` -> `map(score per result, threading id)` -> `use` to pick the
|
|
@@ -364,6 +375,7 @@ function ensemble_step(config) {
|
|
|
364
375
|
const { members, score, rank_by } = config;
|
|
365
376
|
const select = config.select ?? "max";
|
|
366
377
|
const keys = Object.keys(members);
|
|
378
|
+
const project = config.project ?? ((r) => r);
|
|
367
379
|
if (keys.length === 0) throw new Error("ensemble_step: at least one member required");
|
|
368
380
|
const fan_out = parallel(members);
|
|
369
381
|
const score_one = scope([
|
|
@@ -407,12 +419,12 @@ function ensemble_step(config) {
|
|
|
407
419
|
if (winner_id === void 0 || winner_scored === void 0) throw new Error("ensemble_step: no members produced a result");
|
|
408
420
|
const winner = results[winner_id];
|
|
409
421
|
if (winner === void 0) throw new Error("ensemble_step: winner missing from results");
|
|
410
|
-
return {
|
|
422
|
+
return project({
|
|
411
423
|
winner_id,
|
|
412
424
|
winner,
|
|
413
425
|
winner_scored,
|
|
414
426
|
scored
|
|
415
|
-
};
|
|
427
|
+
});
|
|
416
428
|
});
|
|
417
429
|
const inner = scope([
|
|
418
430
|
stash(RESULTS_KEY, fan_out),
|
|
@@ -444,7 +456,9 @@ const PRIOR_KEY = "__improve_prior";
|
|
|
444
456
|
* Rejected rounds with a `reason` feed a bounded lessons list back into the
|
|
445
457
|
* next round's input. Plateau detection stops the loop early when no
|
|
446
458
|
* progress has been made for `patience` rounds; an optional wall-clock
|
|
447
|
-
* budget caps total runtime.
|
|
459
|
+
* budget caps total runtime. `project` maps the result envelope into the
|
|
460
|
+
* step's output (e.g. `(r) => r.best.content`); omitted, the envelope
|
|
461
|
+
* itself is the output.
|
|
448
462
|
*
|
|
449
463
|
* Implemented as a `compose`d `scope` of (seed) -> (init state) -> (loop) ->
|
|
450
464
|
* (unwrap). The loop body is itself a small `scope` that snapshots prior
|
|
@@ -454,6 +468,7 @@ const PRIOR_KEY = "__improve_prior";
|
|
|
454
468
|
*/
|
|
455
469
|
function improve(config) {
|
|
456
470
|
const { seed, propose, score, budget } = config;
|
|
471
|
+
const project = config.project ?? ((r) => r);
|
|
457
472
|
const epsilon = config.epsilon ?? 0;
|
|
458
473
|
const proposers_per_round = Math.max(1, config.proposers_per_round ?? 1);
|
|
459
474
|
const lessons_capacity = Math.max(0, config.lessons_capacity ?? 5);
|
|
@@ -596,7 +611,7 @@ function improve(config) {
|
|
|
596
611
|
rounds_used: result.rounds_used,
|
|
597
612
|
final_score: result.best.score
|
|
598
613
|
});
|
|
599
|
-
return result;
|
|
614
|
+
return project(result);
|
|
600
615
|
})
|
|
601
616
|
]);
|
|
602
617
|
return compose(config.name ?? "improve", inner);
|
|
@@ -794,11 +809,14 @@ function learn(config) {
|
|
|
794
809
|
*
|
|
795
810
|
* All members run concurrently via `parallel`; the bracket step then reduces
|
|
796
811
|
* survivors round by round with `compare`, recording every match. Requires at
|
|
797
|
-
* least one member so a winner always exists.
|
|
812
|
+
* least one member so a winner always exists. `project` maps the `{ winner,
|
|
813
|
+
* bracket }` envelope into the step's output (e.g. `(r) => r.winner`);
|
|
814
|
+
* omitted, the envelope itself is the output.
|
|
798
815
|
*/
|
|
799
816
|
function tournament(config) {
|
|
800
817
|
const compare_fn = config.compare;
|
|
801
818
|
const keys = Object.keys(config.members);
|
|
819
|
+
const project = config.project ?? ((r) => r);
|
|
802
820
|
if (keys.length === 0) throw new Error("tournament: at least one member required");
|
|
803
821
|
const inner = sequence([parallel(config.members), step("bracket", async (results) => {
|
|
804
822
|
let current = [...keys];
|
|
@@ -808,10 +826,10 @@ function tournament(config) {
|
|
|
808
826
|
round += 1;
|
|
809
827
|
current = await play_round(current, results, compare_fn, round, bracket);
|
|
810
828
|
}
|
|
811
|
-
return {
|
|
829
|
+
return project({
|
|
812
830
|
winner: winner_of(current, results),
|
|
813
831
|
bracket
|
|
814
|
-
};
|
|
832
|
+
});
|
|
815
833
|
})]);
|
|
816
834
|
return compose(config.name ?? "tournament", inner);
|
|
817
835
|
}
|
|
@@ -7858,7 +7876,7 @@ async function build_ai_sdk_transport(cfg) {
|
|
|
7858
7876
|
const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
|
|
7859
7877
|
let ai_sdk_invoke_mod;
|
|
7860
7878
|
try {
|
|
7861
|
-
ai_sdk_invoke_mod = await import("./invoke-
|
|
7879
|
+
ai_sdk_invoke_mod = await import("./invoke-JkzNf7-Y.js");
|
|
7862
7880
|
} catch (err) {
|
|
7863
7881
|
throw missing_peer_error("ai", err);
|
|
7864
7882
|
}
|
|
@@ -8503,11 +8521,14 @@ function build_generate_options(cfg, prompt, ctx) {
|
|
|
8503
8521
|
*
|
|
8504
8522
|
* Threads `ctx.abort` and `ctx.trajectory` (nested under the model_call
|
|
8505
8523
|
* step's own span) into every call, and, when `run.stream` is driving,
|
|
8506
|
-
* records each chunk as a `model_chunk` trajectory event.
|
|
8524
|
+
* records each chunk as a `model_chunk` trajectory event. `cfg.project`
|
|
8525
|
+
* maps the `GenerateResult` envelope into the step's output inside the same
|
|
8526
|
+
* step; omitted, the envelope is the output.
|
|
8507
8527
|
*/
|
|
8508
8528
|
function model_call(cfg) {
|
|
8509
8529
|
const has_tools = Boolean(cfg.tools && cfg.tools.length > 0);
|
|
8510
8530
|
const has_schema = cfg.schema !== void 0;
|
|
8531
|
+
const project = cfg.project ?? ((r) => r);
|
|
8511
8532
|
const step_id = cfg.id ?? `model_call:${stable_signature({
|
|
8512
8533
|
model: cfg.model,
|
|
8513
8534
|
provider: cfg.provider,
|
|
@@ -8517,7 +8538,8 @@ function model_call(cfg) {
|
|
|
8517
8538
|
})}`;
|
|
8518
8539
|
const describe_config = {
|
|
8519
8540
|
has_tools,
|
|
8520
|
-
has_schema
|
|
8541
|
+
has_schema,
|
|
8542
|
+
has_project: cfg.project !== void 0
|
|
8521
8543
|
};
|
|
8522
8544
|
if (cfg.model !== void 0) describe_config.model = cfg.model;
|
|
8523
8545
|
if (cfg.provider !== void 0) describe_config.provider = cfg.provider;
|
|
@@ -8542,7 +8564,7 @@ function model_call(cfg) {
|
|
|
8542
8564
|
chunk
|
|
8543
8565
|
});
|
|
8544
8566
|
};
|
|
8545
|
-
return cfg.engine.generate(opts);
|
|
8567
|
+
return project(await cfg.engine.generate(opts));
|
|
8546
8568
|
});
|
|
8547
8569
|
return {
|
|
8548
8570
|
id: inner.id,
|
|
@@ -8551,6 +8573,28 @@ function model_call(cfg) {
|
|
|
8551
8573
|
config: Object.freeze({ ...describe_config })
|
|
8552
8574
|
};
|
|
8553
8575
|
}
|
|
8576
|
+
/**
|
|
8577
|
+
* model_step: `model_call` projected to its content.
|
|
8578
|
+
*
|
|
8579
|
+
* Returns a Step whose output is the model's final content (a `string`, or
|
|
8580
|
+
* the schema-validated value when `cfg.schema` is set) instead of the full
|
|
8581
|
+
* `GenerateResult` envelope. Use `model_step` when the flow only wants the
|
|
8582
|
+
* answer, keeping compositions at the `step, step, model_step, step` cadence;
|
|
8583
|
+
* drop to `model_call` when the caller needs usage, cost, tool calls, or
|
|
8584
|
+
* finish reason (or its `project` option, when the flow wants a slice of the
|
|
8585
|
+
* envelope mapped at the source).
|
|
8586
|
+
*
|
|
8587
|
+
* Implemented as `model_call` with `project` preset to `(r) => r.content`,
|
|
8588
|
+
* so the leaf is a single node in `describe` and the trajectory. Wrapping a
|
|
8589
|
+
* primitive into an app-shaped helper of your own is still the extension
|
|
8590
|
+
* pattern; this is its smallest instance.
|
|
8591
|
+
*/
|
|
8592
|
+
function model_step(cfg) {
|
|
8593
|
+
return model_call({
|
|
8594
|
+
...cfg,
|
|
8595
|
+
project: (r) => r.content
|
|
8596
|
+
});
|
|
8597
|
+
}
|
|
8554
8598
|
//#endregion
|
|
8555
8599
|
//#region src/forward_standard_env.ts
|
|
8556
8600
|
/**
|
|
@@ -9237,6 +9281,6 @@ if (process.argv[1] !== void 0 && process.argv[1] === fileURLToPath(import.meta.
|
|
|
9237
9281
|
process.exit(1);
|
|
9238
9282
|
});
|
|
9239
9283
|
//#endregion
|
|
9240
|
-
export { STEP_KINDS, aborted_error, adversarial, bench, bench_suspend_error, branch, checkpoint, claude_cli_error, compose, consensus, create_engine, default_normalize_usage, describe, describe_cycle_error, engine_config_error, engine_disposed_error, ensemble, ensemble_step, fallback, flow_schema_default as flow_schema, forward_standard_env, improve, incomplete_generation_error, is_custom_trajectory_event, is_emit_event, is_span_end_event, is_span_start_event, is_step_kind, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, normalize_score, on_chunk_error, parallel, parse_trajectory_event, 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, start_viewer, stash, step, suspend, suspended_error, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, use, write_baseline };
|
|
9284
|
+
export { STEP_KINDS, aborted_error, adversarial, bench, bench_suspend_error, branch, chain, checkpoint, claude_cli_error, compose, consensus, create_engine, default_normalize_usage, describe, describe_cycle_error, engine_config_error, engine_disposed_error, ensemble, ensemble_step, fallback, flow_schema_default as flow_schema, forward_standard_env, improve, incomplete_generation_error, is_custom_trajectory_event, is_emit_event, is_span_end_event, is_span_start_event, is_step_kind, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, model_step, normalize_score, on_chunk_error, parallel, parse_trajectory_event, 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, start_viewer, stash, step, suspend, suspended_error, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, use, write_baseline };
|
|
9241
9285
|
|
|
9242
9286
|
//# sourceMappingURL=index.js.map
|