fascicle 0.17.0 → 0.17.2
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 +25 -0
- package/dist/AGENTS.md +8 -8
- package/dist/acp.d.ts +1 -1
- package/dist/acp.js +2 -2
- package/dist/agents.d.ts +1 -1
- package/dist/agents.js +1 -1
- package/dist/{core-BOFcG3tp.js → core-Dwir3pkb.js} +231 -15
- package/dist/core-Dwir3pkb.js.map +1 -0
- package/dist/diagram_bin.js +1 -1
- package/dist/{engine-BMdRqWL2.js → engine-DPPqAVdZ.js} +224 -38
- package/dist/engine-DPPqAVdZ.js.map +1 -0
- package/dist/index.d.ts +61 -6
- package/dist/index.js +132 -18
- package/dist/index.js.map +1 -1
- package/dist/{invoke-BbJLQcLl.js → invoke-DF7YLovL.js} +3 -3
- package/dist/{invoke-BbJLQcLl.js.map → invoke-DF7YLovL.js.map} +1 -1
- package/dist/{leading_system-DmNxhvzL.js → leading_system-DJvuhESU.js} +2 -2
- package/dist/{leading_system-DmNxhvzL.js.map → leading_system-DJvuhESU.js.map} +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +1 -1
- package/dist/{search-CpCJYMUm.js → search-DjhdMsJ8.js} +4 -1
- package/dist/search-DjhdMsJ8.js.map +1 -0
- package/dist/search_worker.js +1 -1
- package/dist/stdio.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +3 -3
- package/dist/{types-BNgAUQP1.d.ts → types-C7pO0jLq.d.ts} +51 -7
- package/dist/viewer.d.ts +27 -0
- package/dist/viewer.js +165 -19
- package/dist/viewer.js.map +1 -1
- package/package.json +1 -1
- package/dist/core-BOFcG3tp.js.map +0 -1
- package/dist/engine-BMdRqWL2.js.map +0 -1
- package/dist/search-CpCJYMUm.js.map +0 -1
package/dist/diagram_bin.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { O as describe, k as is_step } from "./core-Dwir3pkb.js";
|
|
2
2
|
import { createRequire } from "node:module";
|
|
3
3
|
import { resolve } from "node:path";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { A as aborted_error, T as validate_schema, f as compute_backoff, p as wait_with_abort, w as format_schema_issues } from "./core-Dwir3pkb.js";
|
|
2
2
|
import { n as is_record$1 } from "./records-1HU7mWXf.js";
|
|
3
|
-
import { A as tool_approval_denied_error, C as provider_auth_error, D as provider_required_error, E as provider_not_configured_error, M as turn_timeout_error, O as rate_limit_error, S as on_chunk_error, T as provider_error, _ as claude_cli_error, b as incomplete_generation_error, c as parse_tool_call_arguments, d as default_normalize_usage, f as load_optional_peer, g as translate_effort_to_sdk_reasoning, h as resolve_transport, i as invoke_http_turn, j as tool_error, k as schema_validation_error, l as read_dialect_init, m as normalize_local_usage, n as consume_framed_stream, o as map_messages_by_role, p as missing_peer_error, r as create_line_splitter, s as network_failure, t as split_leading_system_run, u as split_assistant_parts, v as engine_config_error, w as provider_capability_error, x as model_required_error, y as engine_disposed_error } from "./leading_system-
|
|
3
|
+
import { A as tool_approval_denied_error, C as provider_auth_error, D as provider_required_error, E as provider_not_configured_error, M as turn_timeout_error, O as rate_limit_error, S as on_chunk_error, T as provider_error, _ as claude_cli_error, b as incomplete_generation_error, c as parse_tool_call_arguments, d as default_normalize_usage, f as load_optional_peer, g as translate_effort_to_sdk_reasoning, h as resolve_transport, i as invoke_http_turn, j as tool_error, k as schema_validation_error, l as read_dialect_init, m as normalize_local_usage, n as consume_framed_stream, o as map_messages_by_role, p as missing_peer_error, r as create_line_splitter, s as network_failure, t as split_leading_system_run, u as split_assistant_parts, v as engine_config_error, w as provider_capability_error, x as model_required_error, y as engine_disposed_error } from "./leading_system-DJvuhESU.js";
|
|
4
4
|
import { join } from "node:path";
|
|
5
5
|
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
6
6
|
import { tmpdir } from "node:os";
|
|
@@ -465,36 +465,58 @@ function to_abort_error(reason) {
|
|
|
465
465
|
return new aborted_error("aborted", { reason });
|
|
466
466
|
}
|
|
467
467
|
/**
|
|
468
|
-
* Build the `rate_limit_error`
|
|
469
|
-
* failing attempt's own `Retry-After`, falling back to the most
|
|
470
|
-
* prior attempt carried (`last_rate_limit_after`)
|
|
468
|
+
* Build the `rate_limit_error` for a 429 that this layer won't retry again.
|
|
469
|
+
* Prefers the failing attempt's own `Retry-After`, falling back to the most
|
|
470
|
+
* recent one a prior attempt carried (`last_rate_limit_after`), and carries
|
|
471
|
+
* the failure's own message, or `fallback` when it had none.
|
|
471
472
|
*/
|
|
472
|
-
function build_rate_limit_error(retryable, attempt, last_rate_limit_after) {
|
|
473
|
+
function build_rate_limit_error(retryable, attempt, last_rate_limit_after, fallback) {
|
|
473
474
|
const metadata = { attempts: attempt };
|
|
474
475
|
if (retryable.retry_after_ms !== void 0) metadata.retry_after_ms = retryable.retry_after_ms;
|
|
475
476
|
else if (last_rate_limit_after !== void 0) metadata.retry_after_ms = last_rate_limit_after;
|
|
476
477
|
if (retryable.status !== void 0) metadata.status = retryable.status;
|
|
477
|
-
return new rate_limit_error(retryable.message ??
|
|
478
|
+
return new rate_limit_error(retryable.message ?? fallback, metadata);
|
|
478
479
|
}
|
|
479
480
|
/**
|
|
480
|
-
* Build the `provider_error`
|
|
481
|
-
* Timeout collapses onto the `network` cause; only
|
|
481
|
+
* Build the `provider_error` for a 5xx, network, or timeout failure that this
|
|
482
|
+
* layer won't retry again. Timeout collapses onto the `network` cause; only
|
|
483
|
+
* 5xx carries status/body. The failure's own message wins over `fallback`.
|
|
482
484
|
*/
|
|
483
|
-
function build_provider_error(retryable,
|
|
485
|
+
function build_provider_error(retryable, fallback) {
|
|
484
486
|
const metadata = { cause_kind: retryable.kind === "provider_5xx" ? "provider_5xx" : "network" };
|
|
485
487
|
if (retryable.kind === "provider_5xx") {
|
|
486
488
|
if (retryable.status !== void 0) metadata.status = retryable.status;
|
|
487
489
|
if (retryable.body !== void 0) metadata.body = retryable.body;
|
|
488
490
|
}
|
|
489
|
-
return new provider_error(retryable.message ??
|
|
491
|
+
return new provider_error(retryable.message ?? fallback, metadata);
|
|
490
492
|
}
|
|
491
493
|
/**
|
|
492
|
-
* Map
|
|
493
|
-
* `rate_limit_error` for 429s, `provider_error` for
|
|
494
|
+
* Map a classified failure that this layer won't retry again onto the error
|
|
495
|
+
* it rejects with: `rate_limit_error` for 429s, `provider_error` for
|
|
496
|
+
* everything else, after `attempt` failures in all. `fallback` is the message
|
|
497
|
+
* for a failure that carried none of its own.
|
|
494
498
|
*/
|
|
495
|
-
function
|
|
496
|
-
if (retryable.kind === "rate_limit") return build_rate_limit_error(retryable, attempt, last_rate_limit_after);
|
|
497
|
-
return build_provider_error(retryable,
|
|
499
|
+
function build_typed_error(retryable, attempt, last_rate_limit_after, fallback) {
|
|
500
|
+
if (retryable.kind === "rate_limit") return build_rate_limit_error(retryable, attempt, last_rate_limit_after, fallback);
|
|
501
|
+
return build_provider_error(retryable, fallback);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* The error for a failure whose kind `retry_on` leaves out. One that's
|
|
505
|
+
* already an `Error`, such as `turn_timeout_error` or a native adapter's
|
|
506
|
+
* network failure, is rethrown as it is, so a caller that catches its class
|
|
507
|
+
* still gets it. A plain record that `classify_provider_error` built becomes
|
|
508
|
+
* the typed error that exhaustion would have thrown for its kind, so a
|
|
509
|
+
* caller never gets a value that prints as `[object Object]`.
|
|
510
|
+
*/
|
|
511
|
+
function build_left_out_error(err, retryable, attempt, last_rate_limit_after) {
|
|
512
|
+
if (err instanceof Error) return err;
|
|
513
|
+
return build_typed_error(retryable, attempt, last_rate_limit_after, `${retryable.kind} not retried: retry_on leaves ${retryable.kind} out`);
|
|
514
|
+
}
|
|
515
|
+
/**
|
|
516
|
+
* The message for an exhausted failure that carried none of its own.
|
|
517
|
+
*/
|
|
518
|
+
function exhaustion_message(retryable, attempt) {
|
|
519
|
+
return retryable.kind === "rate_limit" ? `rate limited after ${attempt} attempts` : `${retryable.kind} after ${attempt} attempts`;
|
|
498
520
|
}
|
|
499
521
|
/**
|
|
500
522
|
* The server's `Retry-After`, in milliseconds, that a 429 or a 5xx carried,
|
|
@@ -552,6 +574,12 @@ function build_attempt_info(retryable, attempt, delay_ms) {
|
|
|
552
574
|
* exhaustion, throws `rate_limit_error` (for 429s) or `provider_error` (for
|
|
553
575
|
* 5xx/network/timeout).
|
|
554
576
|
*
|
|
577
|
+
* A failure whose kind `retry_on` leaves out isn't retried. It's rethrown as
|
|
578
|
+
* it is when it's already an `Error`, and a plain record becomes the
|
|
579
|
+
* `rate_limit_error` or `provider_error` that exhaustion would throw for its
|
|
580
|
+
* kind, counting every failure so far in `attempts`, with the record's own
|
|
581
|
+
* message, or else one that says `retry_on` leaves its kind out.
|
|
582
|
+
*
|
|
555
583
|
* `on_retry` fires once per retried failure, just before its backoff wait.
|
|
556
584
|
* It does NOT fire for a first attempt that succeeds, a non-retryable
|
|
557
585
|
* failure, or the final failure that exhausts the policy (those two throw
|
|
@@ -572,9 +600,10 @@ async function retry_with_policy(fn, policy = DEFAULT_RETRY, abort, on_retry) {
|
|
|
572
600
|
return await fn(attempt);
|
|
573
601
|
} catch (err) {
|
|
574
602
|
const retryable = classify_retryable(err);
|
|
575
|
-
if (retryable === void 0
|
|
603
|
+
if (retryable === void 0) throw err;
|
|
576
604
|
attempt += 1;
|
|
577
|
-
if (
|
|
605
|
+
if (!is_retryable(retryable.kind, policy)) throw build_left_out_error(err, retryable, attempt, last_rate_limit_after);
|
|
606
|
+
if (attempt >= policy.max_attempts) throw build_typed_error(retryable, attempt, last_rate_limit_after, exhaustion_message(retryable, attempt));
|
|
578
607
|
const backoff = next_backoff(retryable, backoff_policy, attempt);
|
|
579
608
|
last_rate_limit_after = carry_rate_limit_after(retryable, backoff, last_rate_limit_after);
|
|
580
609
|
on_retry?.(build_attempt_info(retryable, attempt, backoff.delay));
|
|
@@ -4769,6 +4798,22 @@ function record_turn_paused(trajectory, step_index, span_id) {
|
|
|
4769
4798
|
});
|
|
4770
4799
|
}
|
|
4771
4800
|
/**
|
|
4801
|
+
* Record that the loop went on past a turn that hit its output limit before
|
|
4802
|
+
* it made a tool call (`truncated_turn_policy: 'continue'`). `output_tokens`
|
|
4803
|
+
* is what the turn generated, and `max_tokens` is the limit, when the call
|
|
4804
|
+
* set one.
|
|
4805
|
+
*/
|
|
4806
|
+
function record_turn_truncated(trajectory, meta) {
|
|
4807
|
+
if (trajectory === void 0) return;
|
|
4808
|
+
trajectory.record({
|
|
4809
|
+
kind: "turn_truncated",
|
|
4810
|
+
step_index: meta.step_index,
|
|
4811
|
+
output_tokens: meta.output_tokens,
|
|
4812
|
+
...meta.max_tokens !== void 0 ? { max_tokens: meta.max_tokens } : {},
|
|
4813
|
+
...meta.span_id !== void 0 ? { span_id: meta.span_id } : {}
|
|
4814
|
+
});
|
|
4815
|
+
}
|
|
4816
|
+
/**
|
|
4772
4817
|
* Record that a requested reasoning-effort setting was ignored because the
|
|
4773
4818
|
* model does not support it.
|
|
4774
4819
|
*/
|
|
@@ -5060,6 +5105,7 @@ function emit_ignored_options(opts, trajectory) {
|
|
|
5060
5105
|
if (opts.on_tool_approval !== void 0) option_ignored.emit("on_tool_approval", PROVIDER_NAME);
|
|
5061
5106
|
if (opts.tool_call_repair_attempts !== void 0) option_ignored.emit("tool_call_repair_attempts", PROVIDER_NAME);
|
|
5062
5107
|
if (opts.max_tool_calls_per_step !== void 0) option_ignored.emit("max_tool_calls_per_step", PROVIDER_NAME);
|
|
5108
|
+
if (opts.truncated_turn_policy !== void 0) option_ignored.emit("truncated_turn_policy", PROVIDER_NAME);
|
|
5063
5109
|
if (opts.cache !== void 0) option_ignored.emit("cache", PROVIDER_NAME, "the provider caches on its own");
|
|
5064
5110
|
if (opts.capture !== void 0) option_ignored.emit("capture", PROVIDER_NAME, "Claude Code builds its own requests");
|
|
5065
5111
|
}
|
|
@@ -5968,11 +6014,15 @@ async function salvage_tool_calls(text, tool_map) {
|
|
|
5968
6014
|
* Validated matches run the normal execute path and produce the same
|
|
5969
6015
|
* records/events/chunks as native calls, marked salvaged. The budget is
|
|
5970
6016
|
* a shared mutable holder so it spans schema-repair re-invocations.
|
|
5971
|
-
* - max_tool_calls_per_step:
|
|
5972
|
-
*
|
|
5973
|
-
*
|
|
5974
|
-
*
|
|
5975
|
-
*
|
|
6017
|
+
* - max_tool_calls_per_step: a call to a tool flagged read_only doesn't
|
|
6018
|
+
* count toward the cap. The first counted call past it, and every call
|
|
6019
|
+
* after that one, are dropped for the step, so what runs is a prefix of
|
|
6020
|
+
* what the model asked for. Dropped calls are recorded with
|
|
6021
|
+
* error: { message: 'dropped_max_tool_calls_per_step' } and excluded from
|
|
6022
|
+
* the assistant history message, so providers that require a result per
|
|
6023
|
+
* emitted call do not reject the next request. When the loop goes on,
|
|
6024
|
+
* one user message after the step's tool results names them, so the
|
|
6025
|
+
* model learns they didn't run and can make them again.
|
|
5976
6026
|
* - ends_turn (Tool.ends_turn): a tool flagged terminal ends the loop when a
|
|
5977
6027
|
* call to it executes SUCCESSFULLY. The call runs the normal execute path
|
|
5978
6028
|
* (record, fed tool_result message, trajectory events + chunk), then the
|
|
@@ -5982,6 +6032,14 @@ async function salvage_tool_calls(text, tool_map) {
|
|
|
5982
6032
|
* terminal call is exempt from the max_steps would_exceed_after skip (it
|
|
5983
6033
|
* needs no follow-up turn), so a terminal finish wins over a coincident
|
|
5984
6034
|
* max_steps cap (finish_reason 'stop', max_steps_reached false).
|
|
6035
|
+
* - truncated_turns (truncated_turn_policy 'continue'): a turn that
|
|
6036
|
+
* finishes 'length' with no calls, salvaged ones included, on a call
|
|
6037
|
+
* with tools and with a step left, doesn't end the loop. Its visible
|
|
6038
|
+
* text goes back as a plain assistant message (none when it showed no
|
|
6039
|
+
* text, and never its reasoning), then a user message that says it was
|
|
6040
|
+
* cut off. The turn counts toward max_steps, records turn_truncated, and
|
|
6041
|
+
* its StepRecord says truncated: true. Without the holder, or on the last
|
|
6042
|
+
* step, such a turn ends the loop with 'length' as before.
|
|
5985
6043
|
*
|
|
5986
6044
|
* The loop does not itself call the AI SDK. It invokes a supplied `invoke_once`
|
|
5987
6045
|
* seam that returns a neutral TurnResult. generate.ts builds the real seam
|
|
@@ -6297,6 +6355,53 @@ function continue_paused_turn(config, acc, step_index, step_span, turn) {
|
|
|
6297
6355
|
acc.paused_texts.push(turn.text);
|
|
6298
6356
|
}
|
|
6299
6357
|
/**
|
|
6358
|
+
* The truncated-turn holder when the loop goes on past this turn, which made
|
|
6359
|
+
* no call, salvaged ones included, and undefined when the turn ends the loop
|
|
6360
|
+
* as any other turn without calls does. The loop goes on only past a turn
|
|
6361
|
+
* that hit its output limit, on a call that asked it to and has tools, so the
|
|
6362
|
+
* turn could have made one, and with a step left for another turn.
|
|
6363
|
+
*/
|
|
6364
|
+
function truncation_holder(config, turn, step_index) {
|
|
6365
|
+
return turn.finish_reason === "length" && config.tools.length > 0 && step_index + 1 < config.max_steps ? config.truncated_turns : void 0;
|
|
6366
|
+
}
|
|
6367
|
+
/**
|
|
6368
|
+
* The user message that follows a turn the loop went on past. It says that
|
|
6369
|
+
* the turn was cut off, naming the limit when the call set `max_tokens`, and
|
|
6370
|
+
* asks for a shorter one: the next tool call or the final answer, since a
|
|
6371
|
+
* turn can be cut off partway through an answer as well as its reasoning.
|
|
6372
|
+
*/
|
|
6373
|
+
function truncation_notice(max_tokens) {
|
|
6374
|
+
return {
|
|
6375
|
+
role: "user",
|
|
6376
|
+
content: `Your last turn reached ${max_tokens === void 0 ? "the output limit" : `the ${String(max_tokens)}-token output limit`} before it finished, so it was cut off. Keep this turn short: make your next tool call, or give your final answer.`
|
|
6377
|
+
};
|
|
6378
|
+
}
|
|
6379
|
+
/**
|
|
6380
|
+
* Go on past a turn that hit its output limit before it made a call. Its
|
|
6381
|
+
* visible text goes back as a plain assistant message, and nothing goes back
|
|
6382
|
+
* when it showed only whitespace, which some transports would send as an
|
|
6383
|
+
* empty block that the API refuses. Its reasoning never goes back: a thinking
|
|
6384
|
+
* block cut off before its signature can't be sent again, and the abandoned
|
|
6385
|
+
* reasoning is what the limit was set to stop paying for. The notice follows
|
|
6386
|
+
* it. The turn counts toward max_steps, its record says truncated, and it
|
|
6387
|
+
* ends whatever response the paused turns before it began.
|
|
6388
|
+
*/
|
|
6389
|
+
function continue_truncated_turn(config, acc, at, turn, max_tokens) {
|
|
6390
|
+
record_turn_truncated(config.trajectory, {
|
|
6391
|
+
step_index: at.step_index,
|
|
6392
|
+
span_id: at.step_span,
|
|
6393
|
+
output_tokens: turn.usage.output_tokens,
|
|
6394
|
+
max_tokens
|
|
6395
|
+
});
|
|
6396
|
+
if (turn.text.trim().length > 0) config.messages.push({
|
|
6397
|
+
role: "assistant",
|
|
6398
|
+
content: turn.text
|
|
6399
|
+
});
|
|
6400
|
+
config.messages.push(truncation_notice(max_tokens));
|
|
6401
|
+
push_step_record(config, acc, at.step_index, turn, [], "length", at.step_span, true);
|
|
6402
|
+
acc.paused_texts.length = 0;
|
|
6403
|
+
}
|
|
6404
|
+
/**
|
|
6300
6405
|
* Record a `cache_miss` when the previous turn read or wrote cache tokens
|
|
6301
6406
|
* and this one read none, then remember this turn's reads plus writes for
|
|
6302
6407
|
* the next. The rule needs no table of model minimums and no knowledge of
|
|
@@ -6621,18 +6726,70 @@ async function dispatch_salvaged_call_chunks(config, calls, step_index) {
|
|
|
6621
6726
|
}
|
|
6622
6727
|
}
|
|
6623
6728
|
/**
|
|
6729
|
+
* The most characters of a dropped call's input that the notice quotes.
|
|
6730
|
+
*/
|
|
6731
|
+
const NOTICE_INPUT_LIMIT = 120;
|
|
6732
|
+
/**
|
|
6733
|
+
* `text` cut to at most `limit` characters, counted by code point so that no
|
|
6734
|
+
* surrogate pair is split, with an ellipsis standing in for what was cut.
|
|
6735
|
+
*/
|
|
6736
|
+
function clip(text, limit) {
|
|
6737
|
+
const points = Array.from(text);
|
|
6738
|
+
return points.length <= limit ? text : `${points.slice(0, limit - 1).join("")}…`;
|
|
6739
|
+
}
|
|
6740
|
+
/**
|
|
6741
|
+
* The user message that names the calls the per-step cap dropped. It's fed
|
|
6742
|
+
* back after the step's tool results, since the dropped calls themselves never
|
|
6743
|
+
* reach history, so without it the model would never learn they didn't run.
|
|
6744
|
+
* Each call reads as `name(input)`, with the input as JSON clipped to
|
|
6745
|
+
* NOTICE_INPUT_LIMIT characters. When the call has read-only tools, the
|
|
6746
|
+
* notice says that they don't count, or a turn that made more calls than the
|
|
6747
|
+
* cap would read as a contradiction.
|
|
6748
|
+
*/
|
|
6749
|
+
function dropped_notice(cap, dropped, reads_exempt) {
|
|
6750
|
+
const one = dropped.length === 1;
|
|
6751
|
+
const counted = one ? "1 call" : `${String(dropped.length)} calls`;
|
|
6752
|
+
const exempt = reads_exempt ? ", not counting read-only tools" : "";
|
|
6753
|
+
const listed = dropped.map((call) => `${call.name}(${clip(safe_json_stringify(call.input), NOTICE_INPUT_LIMIT)})`).join(", ");
|
|
6754
|
+
return {
|
|
6755
|
+
role: "user",
|
|
6756
|
+
content: `${counted} didn't run, because max_tool_calls_per_step allows ${String(cap)} per turn${exempt}: ${listed}. Make ${one ? "it" : "them"} again, no more than ${String(cap)} per turn.`
|
|
6757
|
+
};
|
|
6758
|
+
}
|
|
6759
|
+
/**
|
|
6760
|
+
* The index of the first call past `cap`, counting only calls to tools that
|
|
6761
|
+
* aren't flagged read_only (an unknown name counts), or -1 when every call
|
|
6762
|
+
* fits.
|
|
6763
|
+
*/
|
|
6764
|
+
function first_over_cap(calls, tool_map, cap) {
|
|
6765
|
+
let counted = 0;
|
|
6766
|
+
for (const [n, call] of calls.entries()) {
|
|
6767
|
+
if (tool_map.get(call.name)?.read_only === true) continue;
|
|
6768
|
+
counted += 1;
|
|
6769
|
+
if (counted > cap) return n;
|
|
6770
|
+
}
|
|
6771
|
+
return -1;
|
|
6772
|
+
}
|
|
6773
|
+
/**
|
|
6624
6774
|
* Apply `max_tool_calls_per_step` to a turn's calls, native and salvaged
|
|
6625
|
-
* alike.
|
|
6626
|
-
*
|
|
6775
|
+
* alike. A call to a read-only tool doesn't count. The first counted call past
|
|
6776
|
+
* the cap is dropped, and so is every call after it, so what runs is always a
|
|
6777
|
+
* prefix of what the model asked for, and nothing runs after a call that
|
|
6778
|
+
* didn't. Dropped calls never reach history; the notice names them instead.
|
|
6627
6779
|
*/
|
|
6628
|
-
function clamp_calls(config, calls, step_index) {
|
|
6780
|
+
function clamp_calls(config, tool_map, calls, step_index) {
|
|
6629
6781
|
const cap = config.max_tool_calls_per_step;
|
|
6630
|
-
if (cap === void 0
|
|
6782
|
+
if (cap === void 0) return {
|
|
6783
|
+
kept: calls,
|
|
6784
|
+
dropped: []
|
|
6785
|
+
};
|
|
6786
|
+
const cut = first_over_cap(calls, tool_map, cap);
|
|
6787
|
+
if (cut === -1) return {
|
|
6631
6788
|
kept: calls,
|
|
6632
6789
|
dropped: []
|
|
6633
6790
|
};
|
|
6634
|
-
const kept = calls.slice(0,
|
|
6635
|
-
const dropped = calls.slice(
|
|
6791
|
+
const kept = calls.slice(0, cut);
|
|
6792
|
+
const dropped = calls.slice(cut);
|
|
6636
6793
|
record_tool_calls_dropped(config.trajectory, {
|
|
6637
6794
|
step_index,
|
|
6638
6795
|
max_tool_calls_per_step: cap,
|
|
@@ -6644,7 +6801,8 @@ function clamp_calls(config, calls, step_index) {
|
|
|
6644
6801
|
});
|
|
6645
6802
|
return {
|
|
6646
6803
|
kept,
|
|
6647
|
-
dropped
|
|
6804
|
+
dropped,
|
|
6805
|
+
notice: dropped_notice(cap, dropped, config.tools.some((tool) => tool.read_only === true))
|
|
6648
6806
|
};
|
|
6649
6807
|
}
|
|
6650
6808
|
/**
|
|
@@ -6923,16 +7081,17 @@ function resolve_turn_finish_reason(ctx, salvaged, turn_finish) {
|
|
|
6923
7081
|
}
|
|
6924
7082
|
/**
|
|
6925
7083
|
* Build one StepRecord (cost derived and recorded, timing and
|
|
6926
|
-
* provider_reported passed through
|
|
6927
|
-
* close the step span.
|
|
7084
|
+
* provider_reported passed through, `truncated` set for a turn the loop went
|
|
7085
|
+
* on past), push it, notify on_finish_step, and close the step span.
|
|
6928
7086
|
*/
|
|
6929
|
-
function push_step_record(config, acc, step_index, turn, tool_calls, finish_reason, step_span) {
|
|
7087
|
+
function push_step_record(config, acc, step_index, turn, tool_calls, finish_reason, step_span, truncated = false) {
|
|
6930
7088
|
const record = {
|
|
6931
7089
|
index: step_index,
|
|
6932
7090
|
text: turn.text,
|
|
6933
7091
|
tool_calls,
|
|
6934
7092
|
usage: turn.usage,
|
|
6935
|
-
finish_reason
|
|
7093
|
+
finish_reason,
|
|
7094
|
+
...truncated ? { truncated: true } : {}
|
|
6936
7095
|
};
|
|
6937
7096
|
const breakdown = compute_and_record_cost(config, step_index, turn, step_span);
|
|
6938
7097
|
if (breakdown !== void 0) record.cost = breakdown;
|
|
@@ -6959,7 +7118,15 @@ async function run_loop_step(config, tool_map, acc, step_index) {
|
|
|
6959
7118
|
if (turn.tool_calls.length === 0) return continue_paused_turn(config, acc, step_index, step_span, turn);
|
|
6960
7119
|
}
|
|
6961
7120
|
const view = await salvage_turn(config, turn, tool_map, step_index);
|
|
6962
|
-
const
|
|
7121
|
+
const truncated = view.calls.length === 0 ? truncation_holder(config, turn, step_index) : void 0;
|
|
7122
|
+
if (truncated !== void 0) {
|
|
7123
|
+
continue_truncated_turn(config, acc, {
|
|
7124
|
+
step_index,
|
|
7125
|
+
step_span
|
|
7126
|
+
}, turn, truncated.max_tokens);
|
|
7127
|
+
return;
|
|
7128
|
+
}
|
|
7129
|
+
const { kept, dropped, notice } = clamp_calls(config, tool_map, view.calls, step_index);
|
|
6963
7130
|
config.messages.push(build_assistant_message(turn, view, kept));
|
|
6964
7131
|
if (kept.length === 0) {
|
|
6965
7132
|
push_step_record(config, acc, step_index, turn, [], turn.finish_reason, step_span);
|
|
@@ -6985,6 +7152,7 @@ async function run_loop_step(config, tool_map, acc, step_index) {
|
|
|
6985
7152
|
push_step_record(config, acc, step_index, turn, ctx.records, turn_finish_reason, step_span);
|
|
6986
7153
|
if (ctx.terminal_fired) return loop_result(acc, turn.text, "stop", false);
|
|
6987
7154
|
if (ctx.would_exceed_after) return loop_result(acc, turn.text, "max_steps", true);
|
|
7155
|
+
if (notice !== void 0) config.messages.push(notice);
|
|
6988
7156
|
acc.paused_texts.length = 0;
|
|
6989
7157
|
}
|
|
6990
7158
|
/**
|
|
@@ -7365,6 +7533,10 @@ const CAPTURE_LEVELS = {
|
|
|
7365
7533
|
turns: true,
|
|
7366
7534
|
wire: true
|
|
7367
7535
|
};
|
|
7536
|
+
const TRUNCATED_TURN_POLICIES = {
|
|
7537
|
+
stop: true,
|
|
7538
|
+
continue: true
|
|
7539
|
+
};
|
|
7368
7540
|
/**
|
|
7369
7541
|
* Throw `engine_config_error` when `value` is set to anything but a key of
|
|
7370
7542
|
* `allowed`, naming the field, the value, and the values it takes.
|
|
@@ -7391,6 +7563,15 @@ function assert_capture_level(value, field) {
|
|
|
7391
7563
|
assert_allowed(CAPTURE_LEVELS, value, field);
|
|
7392
7564
|
}
|
|
7393
7565
|
/**
|
|
7566
|
+
* Throw `engine_config_error` for a truncated-turn policy that isn't a
|
|
7567
|
+
* `TruncatedTurnPolicy`. `create_engine` checks
|
|
7568
|
+
* `defaults.truncated_turn_policy` with it, and `generate` a call's
|
|
7569
|
+
* `truncated_turn_policy`.
|
|
7570
|
+
*/
|
|
7571
|
+
function assert_truncated_turn_policy(value, field) {
|
|
7572
|
+
assert_allowed(TRUNCATED_TURN_POLICIES, value, field);
|
|
7573
|
+
}
|
|
7574
|
+
/**
|
|
7394
7575
|
* Resolve the provider name: per-call, then the engine default, then the sole
|
|
7395
7576
|
* configured adapter. With several providers configured and neither a per-call
|
|
7396
7577
|
* provider nor a default, there is no sane guess, so this throws
|
|
@@ -7528,7 +7709,8 @@ function resolve_loop_limits(opts, engine) {
|
|
|
7528
7709
|
tool_error_policy,
|
|
7529
7710
|
schema_repair_attempts,
|
|
7530
7711
|
salvage_budget,
|
|
7531
|
-
max_tool_calls_per_step
|
|
7712
|
+
max_tool_calls_per_step,
|
|
7713
|
+
truncated_turns: (opts.truncated_turn_policy ?? engine.default_truncated_turn_policy) === "continue" ? { max_tokens: opts.max_tokens } : void 0
|
|
7532
7714
|
};
|
|
7533
7715
|
}
|
|
7534
7716
|
/**
|
|
@@ -7557,7 +7739,7 @@ async function build_ai_sdk_transport(cfg) {
|
|
|
7557
7739
|
const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
|
|
7558
7740
|
let ai_sdk_invoke_mod;
|
|
7559
7741
|
try {
|
|
7560
|
-
ai_sdk_invoke_mod = await import("./invoke-
|
|
7742
|
+
ai_sdk_invoke_mod = await import("./invoke-DF7YLovL.js");
|
|
7561
7743
|
} catch (err) {
|
|
7562
7744
|
throw missing_peer_error("ai", err);
|
|
7563
7745
|
}
|
|
@@ -7666,6 +7848,7 @@ function build_loop_config(cfg) {
|
|
|
7666
7848
|
capture: cfg.capture,
|
|
7667
7849
|
...limits.salvage_budget !== void 0 ? { salvage_budget: limits.salvage_budget } : {},
|
|
7668
7850
|
...limits.max_tool_calls_per_step !== void 0 ? { max_tool_calls_per_step: limits.max_tool_calls_per_step } : {},
|
|
7851
|
+
truncated_turns: limits.truncated_turns,
|
|
7669
7852
|
...opts.prepare_step !== void 0 ? { prepare_step: opts.prepare_step } : {}
|
|
7670
7853
|
};
|
|
7671
7854
|
}
|
|
@@ -7821,6 +8004,7 @@ async function generate(opts_in, engine) {
|
|
|
7821
8004
|
assert_unique_tool_names(opts.tools);
|
|
7822
8005
|
assert_cache_setting(opts.cache, "cache");
|
|
7823
8006
|
assert_capture_level(opts.capture, "capture");
|
|
8007
|
+
assert_truncated_turn_policy(opts.truncated_turn_policy, "truncated_turn_policy");
|
|
7824
8008
|
if (adapter.kind === "external") return {
|
|
7825
8009
|
...await adapter.generate(opts, target),
|
|
7826
8010
|
timing: call_timing(started_at)
|
|
@@ -8116,6 +8300,7 @@ function build_internals(base, defaults) {
|
|
|
8116
8300
|
assign_if_present(internals, "default_schema_repair_attempts", defaults.schema_repair_attempts);
|
|
8117
8301
|
assign_if_present(internals, "default_tool_call_repair_attempts", defaults.tool_call_repair_attempts);
|
|
8118
8302
|
assign_if_present(internals, "default_max_tool_calls_per_step", defaults.max_tool_calls_per_step);
|
|
8303
|
+
assign_if_present(internals, "default_truncated_turn_policy", defaults.truncated_turn_policy);
|
|
8119
8304
|
assign_if_present(internals, "default_turn_timeout_ms", defaults.turn_timeout_ms);
|
|
8120
8305
|
assign_if_present(internals, "default_ai_sdk_telemetry", defaults.ai_sdk_telemetry);
|
|
8121
8306
|
assign_if_present(internals, "default_provider_options", defaults.provider_options);
|
|
@@ -8137,6 +8322,7 @@ function create_engine(config) {
|
|
|
8137
8322
|
validate_numeric_defaults(config.defaults);
|
|
8138
8323
|
assert_cache_setting(config.defaults?.cache, "defaults.cache");
|
|
8139
8324
|
assert_capture_level(config.defaults?.capture, "defaults.capture");
|
|
8325
|
+
assert_truncated_turn_policy(config.defaults?.truncated_turn_policy, "defaults.truncated_turn_policy");
|
|
8140
8326
|
const get_internals = () => ({
|
|
8141
8327
|
...build_internals({
|
|
8142
8328
|
pricing,
|
|
@@ -8190,4 +8376,4 @@ function create_engine(config) {
|
|
|
8190
8376
|
//#endregion
|
|
8191
8377
|
export { to_json_schema as n, create_engine as t };
|
|
8192
8378
|
|
|
8193
|
-
//# sourceMappingURL=engine-
|
|
8379
|
+
//# sourceMappingURL=engine-DPPqAVdZ.js.map
|