fascicle 0.17.0 → 0.17.1
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 +8 -0
- package/dist/AGENTS.md +7 -7
- package/dist/acp.d.ts +1 -1
- package/dist/acp.js +1 -1
- package/dist/agents.d.ts +1 -1
- package/dist/{engine-BMdRqWL2.js → engine-Bde18P7H.js} +176 -19
- package/dist/engine-Bde18P7H.js.map +1 -0
- package/dist/index.d.ts +8 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +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/testing.d.ts +1 -1
- package/dist/testing.js +1 -1
- package/dist/{types-BNgAUQP1.d.ts → types-C7pO0jLq.d.ts} +51 -7
- package/dist/viewer.d.ts +27 -0
- package/dist/viewer.js +164 -18
- package/dist/viewer.js.map +1 -1
- package/package.json +1 -1
- package/dist/engine-BMdRqWL2.js.map +0 -1
- package/dist/search-CpCJYMUm.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v0.17.1 — 2026-10-26
|
|
4
|
+
|
|
5
|
+
### Added
|
|
6
|
+
|
|
7
|
+
- **The viewer can read a trajectory without following a link.** A host that checked a run's `trajectory.jsonl` before it started a viewer couldn't keep that check true, because the tail and `/api/trajectory` opened the path again on every read and followed a link there, so a link that was swapped in afterwards, such as one that points at `~/.ssh/id_ed25519`, was read and served to whoever held the viewer's URL. `follow_links: false` on `start_viewer`, `start_tail`, and `create_viewer_handler` opens the trajectory with `O_NOFOLLOW` and checks the handle that it opened rather than the path, so the viewer reads only a regular file with no other name, and a FIFO at the path is refused without waiting for a writer. The tail reports a refusal to `on_io_error` and waits for a file that it can read, as it does for a missing one, and `/api/trajectory` serves the ring, as it does when there's no file. A directory above the file is still followed, so a host keeps checking those itself, and the option throws on a platform that has no `O_NOFOLLOW`. Following links stays the default. See [viewer.md](./docs/viewer.md#security).
|
|
8
|
+
- **The tool loop tells the model which calls `max_tool_calls_per_step` dropped, and a read-only tool doesn't count toward the cap.** Calls past the cap were left out of history with no result, so that no provider saw a call without one, but the model never learned that they hadn't run, and whether it made them again was left to chance. When the loop goes on, one user message after the step's tool results now names each dropped call with its input, clipped to 120 characters, as in `1 call didn't run, because max_tool_calls_per_step allows 1 per turn: write_file({"path":"a.ts"}). Make it again, no more than 1 per turn.` A `Tool` gains `read_only`, and a call to a tool that sets it doesn't count, so a turn can make several reads and still make only one write or command. The first counted call past the cap is dropped, and so is every call after it, so what runs is always the start of what the model asked for. The ACP `read_file`, `list_files`, and `search` tools set it. MCP tools don't, since `readOnlyHint` is a hint from the server that nothing checks. The dropped calls' `ToolCallRecord`s and the `tool_calls_dropped` event are unchanged. See [configuration.md](./docs/configuration.md#local-runtime-tool-reliability).
|
|
9
|
+
- **`truncated_turn_policy: 'continue'` keeps a tool loop going past a turn that reached its output limit before it made a call.** The loop ended on any turn that made no tool call, whatever its finish reason, so a turn that reached `max_tokens` while a thinking model was still reasoning ended the whole session, which made `max_tokens` useless as a per-turn cap. Under `'continue'`, on a call with tools and with a step left, the loop sends back whatever text the turn showed and leaves out its reasoning, which a provider wouldn't take back without the signature that it never got. Then it adds a user message that says the turn was cut off at the limit and asks for the next tool call or the final answer, and asks for another turn, which counts toward `max_steps`. The turn's `StepRecord` says `truncated: true`, and a `turn_truncated` event records its `output_tokens` and the call's `max_tokens`. The option goes on a call, on `defaults`, or on a `model_call` or `model_step` config, any other value throws `engine_config_error`, and `claude_cli` records `option_ignored`. `'stop'` stays the default. Ollama counts a model's thinking against `num_predict`, on its MLX runner as on llama.cpp, so the cap does stop a long reasoning turn there. See [configuration.md](./docs/configuration.md#local-runtime-tool-reliability).
|
|
10
|
+
|
|
3
11
|
## v0.17.0 — 2026-10-24
|
|
4
12
|
|
|
5
13
|
### Added
|
package/dist/AGENTS.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
This file is for a coding agent (Claude Code, Codex, Cursor, or another) that's
|
|
4
4
|
working in a project which uses the published `fascicle` package. A person who
|
|
5
5
|
is learning Fascicle will usually import it from their `CLAUDE.md`, as
|
|
6
|
-
[lesson 0](https://github.com/robmclarty/fascicle/blob/v0.17.
|
|
6
|
+
[lesson 0](https://github.com/robmclarty/fascicle/blob/v0.17.1/docs/learn/00-set-up.md) shows. Every shape, rule, and error message below
|
|
7
7
|
was checked against `fascicle` 0.16.3, and against 0.15.0 where the two differ,
|
|
8
8
|
except what's marked 0.17.0 and later, which was checked against 0.17.0. A rule
|
|
9
9
|
that a later release changes says what changed.
|
|
@@ -396,11 +396,11 @@ describe('the calculator', () => {
|
|
|
396
396
|
|
|
397
397
|
## Where to Look Next
|
|
398
398
|
|
|
399
|
-
- [blueprint.md](https://github.com/robmclarty/fascicle/blob/v0.17.
|
|
400
|
-
- [leaf-arm-spine.md](https://github.com/robmclarty/fascicle/blob/v0.17.
|
|
399
|
+
- [blueprint.md](https://github.com/robmclarty/fascicle/blob/v0.17.1/docs/blueprint.md) for the layout of a growing app.
|
|
400
|
+
- [leaf-arm-spine.md](https://github.com/robmclarty/fascicle/blob/v0.17.1/docs/leaf-arm-spine.md) for choosing a primitive at each
|
|
401
401
|
layer.
|
|
402
|
-
- [composition.md](https://github.com/robmclarty/fascicle/blob/v0.17.
|
|
403
|
-
- [cookbook.md](https://github.com/robmclarty/fascicle/blob/v0.17.
|
|
402
|
+
- [composition.md](https://github.com/robmclarty/fascicle/blob/v0.17.1/docs/composition.md) for one line on every composer.
|
|
403
|
+
- [cookbook.md](https://github.com/robmclarty/fascicle/blob/v0.17.1/docs/cookbook.md) for worked patterns, including tool loops with
|
|
404
404
|
`define_tool`.
|
|
405
|
-
- [testing.md](https://github.com/robmclarty/fascicle/blob/v0.17.
|
|
406
|
-
- [troubleshooting.md](https://github.com/robmclarty/fascicle/blob/v0.17.
|
|
405
|
+
- [testing.md](https://github.com/robmclarty/fascicle/blob/v0.17.1/docs/testing.md) for the stand-in engines.
|
|
406
|
+
- [troubleshooting.md](https://github.com/robmclarty/fascicle/blob/v0.17.1/docs/troubleshooting.md) for errors and their causes.
|
package/dist/acp.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { c as Step, h as TrajectoryLogger, m as TrajectoryEvent } from "./types-CPqLZOEr.js";
|
|
2
|
-
import { M as Tool, N as ToolApprovalHandler } from "./types-
|
|
2
|
+
import { M as Tool, N as ToolApprovalHandler } from "./types-C7pO0jLq.js";
|
|
3
3
|
import { AgentApp, ClientCapabilities, ContentBlock, SessionUpdate } from "@agentclientprotocol/sdk";
|
|
4
4
|
//#region src/acp/types.d.ts
|
|
5
5
|
/**
|
package/dist/acp.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { E as run, k as aborted_error } from "./core-BOFcG3tp.js";
|
|
2
2
|
import { n as is_record, t as as_record } from "./records-1HU7mWXf.js";
|
|
3
3
|
import { t as json_schema_to_standard } from "./json_schema_to_standard-C4F4lXHE.js";
|
|
4
|
-
import { a as read_file_tool, c as resolve_roots, i as is_binary, l as shown_path, n as search_tool, o as contain_writable, r as list_files_tool, s as error_code } from "./search-
|
|
4
|
+
import { a as read_file_tool, c as resolve_roots, i as is_binary, l as shown_path, n as search_tool, o as contain_writable, r as list_files_tool, s as error_code } from "./search-DjhdMsJ8.js";
|
|
5
5
|
import { t as route_console_to_stderr } from "./console-CdB4pcFO.js";
|
|
6
6
|
import { randomUUID } from "node:crypto";
|
|
7
7
|
import { mkdir, open, stat, writeFile } from "node:fs/promises";
|
package/dist/agents.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { c as Step } from "./types-CPqLZOEr.js";
|
|
2
2
|
import { r as ToolSchema } from "./types-BK0UW28o.js";
|
|
3
|
-
import { l as EffortLevel, u as Engine } from "./types-
|
|
3
|
+
import { l as EffortLevel, u as Engine } from "./types-C7pO0jLq.js";
|
|
4
4
|
//#region src/agents/define_agent.d.ts
|
|
5
5
|
type AgentBuiltPrompt = string | {
|
|
6
6
|
readonly user: string;
|
|
@@ -4769,6 +4769,22 @@ function record_turn_paused(trajectory, step_index, span_id) {
|
|
|
4769
4769
|
});
|
|
4770
4770
|
}
|
|
4771
4771
|
/**
|
|
4772
|
+
* Record that the loop went on past a turn that hit its output limit before
|
|
4773
|
+
* it made a tool call (`truncated_turn_policy: 'continue'`). `output_tokens`
|
|
4774
|
+
* is what the turn generated, and `max_tokens` is the limit, when the call
|
|
4775
|
+
* set one.
|
|
4776
|
+
*/
|
|
4777
|
+
function record_turn_truncated(trajectory, meta) {
|
|
4778
|
+
if (trajectory === void 0) return;
|
|
4779
|
+
trajectory.record({
|
|
4780
|
+
kind: "turn_truncated",
|
|
4781
|
+
step_index: meta.step_index,
|
|
4782
|
+
output_tokens: meta.output_tokens,
|
|
4783
|
+
...meta.max_tokens !== void 0 ? { max_tokens: meta.max_tokens } : {},
|
|
4784
|
+
...meta.span_id !== void 0 ? { span_id: meta.span_id } : {}
|
|
4785
|
+
});
|
|
4786
|
+
}
|
|
4787
|
+
/**
|
|
4772
4788
|
* Record that a requested reasoning-effort setting was ignored because the
|
|
4773
4789
|
* model does not support it.
|
|
4774
4790
|
*/
|
|
@@ -5060,6 +5076,7 @@ function emit_ignored_options(opts, trajectory) {
|
|
|
5060
5076
|
if (opts.on_tool_approval !== void 0) option_ignored.emit("on_tool_approval", PROVIDER_NAME);
|
|
5061
5077
|
if (opts.tool_call_repair_attempts !== void 0) option_ignored.emit("tool_call_repair_attempts", PROVIDER_NAME);
|
|
5062
5078
|
if (opts.max_tool_calls_per_step !== void 0) option_ignored.emit("max_tool_calls_per_step", PROVIDER_NAME);
|
|
5079
|
+
if (opts.truncated_turn_policy !== void 0) option_ignored.emit("truncated_turn_policy", PROVIDER_NAME);
|
|
5063
5080
|
if (opts.cache !== void 0) option_ignored.emit("cache", PROVIDER_NAME, "the provider caches on its own");
|
|
5064
5081
|
if (opts.capture !== void 0) option_ignored.emit("capture", PROVIDER_NAME, "Claude Code builds its own requests");
|
|
5065
5082
|
}
|
|
@@ -5968,11 +5985,15 @@ async function salvage_tool_calls(text, tool_map) {
|
|
|
5968
5985
|
* Validated matches run the normal execute path and produce the same
|
|
5969
5986
|
* records/events/chunks as native calls, marked salvaged. The budget is
|
|
5970
5987
|
* a shared mutable holder so it spans schema-repair re-invocations.
|
|
5971
|
-
* - max_tool_calls_per_step:
|
|
5972
|
-
*
|
|
5973
|
-
*
|
|
5974
|
-
*
|
|
5975
|
-
*
|
|
5988
|
+
* - max_tool_calls_per_step: a call to a tool flagged read_only doesn't
|
|
5989
|
+
* count toward the cap. The first counted call past it, and every call
|
|
5990
|
+
* after that one, are dropped for the step, so what runs is a prefix of
|
|
5991
|
+
* what the model asked for. Dropped calls are recorded with
|
|
5992
|
+
* error: { message: 'dropped_max_tool_calls_per_step' } and excluded from
|
|
5993
|
+
* the assistant history message, so providers that require a result per
|
|
5994
|
+
* emitted call do not reject the next request. When the loop goes on,
|
|
5995
|
+
* one user message after the step's tool results names them, so the
|
|
5996
|
+
* model learns they didn't run and can make them again.
|
|
5976
5997
|
* - ends_turn (Tool.ends_turn): a tool flagged terminal ends the loop when a
|
|
5977
5998
|
* call to it executes SUCCESSFULLY. The call runs the normal execute path
|
|
5978
5999
|
* (record, fed tool_result message, trajectory events + chunk), then the
|
|
@@ -5982,6 +6003,14 @@ async function salvage_tool_calls(text, tool_map) {
|
|
|
5982
6003
|
* terminal call is exempt from the max_steps would_exceed_after skip (it
|
|
5983
6004
|
* needs no follow-up turn), so a terminal finish wins over a coincident
|
|
5984
6005
|
* max_steps cap (finish_reason 'stop', max_steps_reached false).
|
|
6006
|
+
* - truncated_turns (truncated_turn_policy 'continue'): a turn that
|
|
6007
|
+
* finishes 'length' with no calls, salvaged ones included, on a call
|
|
6008
|
+
* with tools and with a step left, doesn't end the loop. Its visible
|
|
6009
|
+
* text goes back as a plain assistant message (none when it showed no
|
|
6010
|
+
* text, and never its reasoning), then a user message that says it was
|
|
6011
|
+
* cut off. The turn counts toward max_steps, records turn_truncated, and
|
|
6012
|
+
* its StepRecord says truncated: true. Without the holder, or on the last
|
|
6013
|
+
* step, such a turn ends the loop with 'length' as before.
|
|
5985
6014
|
*
|
|
5986
6015
|
* The loop does not itself call the AI SDK. It invokes a supplied `invoke_once`
|
|
5987
6016
|
* seam that returns a neutral TurnResult. generate.ts builds the real seam
|
|
@@ -6297,6 +6326,53 @@ function continue_paused_turn(config, acc, step_index, step_span, turn) {
|
|
|
6297
6326
|
acc.paused_texts.push(turn.text);
|
|
6298
6327
|
}
|
|
6299
6328
|
/**
|
|
6329
|
+
* The truncated-turn holder when the loop goes on past this turn, which made
|
|
6330
|
+
* no call, salvaged ones included, and undefined when the turn ends the loop
|
|
6331
|
+
* as any other turn without calls does. The loop goes on only past a turn
|
|
6332
|
+
* that hit its output limit, on a call that asked it to and has tools, so the
|
|
6333
|
+
* turn could have made one, and with a step left for another turn.
|
|
6334
|
+
*/
|
|
6335
|
+
function truncation_holder(config, turn, step_index) {
|
|
6336
|
+
return turn.finish_reason === "length" && config.tools.length > 0 && step_index + 1 < config.max_steps ? config.truncated_turns : void 0;
|
|
6337
|
+
}
|
|
6338
|
+
/**
|
|
6339
|
+
* The user message that follows a turn the loop went on past. It says that
|
|
6340
|
+
* the turn was cut off, naming the limit when the call set `max_tokens`, and
|
|
6341
|
+
* asks for a shorter one: the next tool call or the final answer, since a
|
|
6342
|
+
* turn can be cut off partway through an answer as well as its reasoning.
|
|
6343
|
+
*/
|
|
6344
|
+
function truncation_notice(max_tokens) {
|
|
6345
|
+
return {
|
|
6346
|
+
role: "user",
|
|
6347
|
+
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.`
|
|
6348
|
+
};
|
|
6349
|
+
}
|
|
6350
|
+
/**
|
|
6351
|
+
* Go on past a turn that hit its output limit before it made a call. Its
|
|
6352
|
+
* visible text goes back as a plain assistant message, and nothing goes back
|
|
6353
|
+
* when it showed only whitespace, which some transports would send as an
|
|
6354
|
+
* empty block that the API refuses. Its reasoning never goes back: a thinking
|
|
6355
|
+
* block cut off before its signature can't be sent again, and the abandoned
|
|
6356
|
+
* reasoning is what the limit was set to stop paying for. The notice follows
|
|
6357
|
+
* it. The turn counts toward max_steps, its record says truncated, and it
|
|
6358
|
+
* ends whatever response the paused turns before it began.
|
|
6359
|
+
*/
|
|
6360
|
+
function continue_truncated_turn(config, acc, at, turn, max_tokens) {
|
|
6361
|
+
record_turn_truncated(config.trajectory, {
|
|
6362
|
+
step_index: at.step_index,
|
|
6363
|
+
span_id: at.step_span,
|
|
6364
|
+
output_tokens: turn.usage.output_tokens,
|
|
6365
|
+
max_tokens
|
|
6366
|
+
});
|
|
6367
|
+
if (turn.text.trim().length > 0) config.messages.push({
|
|
6368
|
+
role: "assistant",
|
|
6369
|
+
content: turn.text
|
|
6370
|
+
});
|
|
6371
|
+
config.messages.push(truncation_notice(max_tokens));
|
|
6372
|
+
push_step_record(config, acc, at.step_index, turn, [], "length", at.step_span, true);
|
|
6373
|
+
acc.paused_texts.length = 0;
|
|
6374
|
+
}
|
|
6375
|
+
/**
|
|
6300
6376
|
* Record a `cache_miss` when the previous turn read or wrote cache tokens
|
|
6301
6377
|
* and this one read none, then remember this turn's reads plus writes for
|
|
6302
6378
|
* the next. The rule needs no table of model minimums and no knowledge of
|
|
@@ -6621,18 +6697,70 @@ async function dispatch_salvaged_call_chunks(config, calls, step_index) {
|
|
|
6621
6697
|
}
|
|
6622
6698
|
}
|
|
6623
6699
|
/**
|
|
6700
|
+
* The most characters of a dropped call's input that the notice quotes.
|
|
6701
|
+
*/
|
|
6702
|
+
const NOTICE_INPUT_LIMIT = 120;
|
|
6703
|
+
/**
|
|
6704
|
+
* `text` cut to at most `limit` characters, counted by code point so that no
|
|
6705
|
+
* surrogate pair is split, with an ellipsis standing in for what was cut.
|
|
6706
|
+
*/
|
|
6707
|
+
function clip(text, limit) {
|
|
6708
|
+
const points = Array.from(text);
|
|
6709
|
+
return points.length <= limit ? text : `${points.slice(0, limit - 1).join("")}…`;
|
|
6710
|
+
}
|
|
6711
|
+
/**
|
|
6712
|
+
* The user message that names the calls the per-step cap dropped. It's fed
|
|
6713
|
+
* back after the step's tool results, since the dropped calls themselves never
|
|
6714
|
+
* reach history, so without it the model would never learn they didn't run.
|
|
6715
|
+
* Each call reads as `name(input)`, with the input as JSON clipped to
|
|
6716
|
+
* NOTICE_INPUT_LIMIT characters. When the call has read-only tools, the
|
|
6717
|
+
* notice says that they don't count, or a turn that made more calls than the
|
|
6718
|
+
* cap would read as a contradiction.
|
|
6719
|
+
*/
|
|
6720
|
+
function dropped_notice(cap, dropped, reads_exempt) {
|
|
6721
|
+
const one = dropped.length === 1;
|
|
6722
|
+
const counted = one ? "1 call" : `${String(dropped.length)} calls`;
|
|
6723
|
+
const exempt = reads_exempt ? ", not counting read-only tools" : "";
|
|
6724
|
+
const listed = dropped.map((call) => `${call.name}(${clip(safe_json_stringify(call.input), NOTICE_INPUT_LIMIT)})`).join(", ");
|
|
6725
|
+
return {
|
|
6726
|
+
role: "user",
|
|
6727
|
+
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.`
|
|
6728
|
+
};
|
|
6729
|
+
}
|
|
6730
|
+
/**
|
|
6731
|
+
* The index of the first call past `cap`, counting only calls to tools that
|
|
6732
|
+
* aren't flagged read_only (an unknown name counts), or -1 when every call
|
|
6733
|
+
* fits.
|
|
6734
|
+
*/
|
|
6735
|
+
function first_over_cap(calls, tool_map, cap) {
|
|
6736
|
+
let counted = 0;
|
|
6737
|
+
for (const [n, call] of calls.entries()) {
|
|
6738
|
+
if (tool_map.get(call.name)?.read_only === true) continue;
|
|
6739
|
+
counted += 1;
|
|
6740
|
+
if (counted > cap) return n;
|
|
6741
|
+
}
|
|
6742
|
+
return -1;
|
|
6743
|
+
}
|
|
6744
|
+
/**
|
|
6624
6745
|
* Apply `max_tool_calls_per_step` to a turn's calls, native and salvaged
|
|
6625
|
-
* alike.
|
|
6626
|
-
*
|
|
6746
|
+
* alike. A call to a read-only tool doesn't count. The first counted call past
|
|
6747
|
+
* the cap is dropped, and so is every call after it, so what runs is always a
|
|
6748
|
+
* prefix of what the model asked for, and nothing runs after a call that
|
|
6749
|
+
* didn't. Dropped calls never reach history; the notice names them instead.
|
|
6627
6750
|
*/
|
|
6628
|
-
function clamp_calls(config, calls, step_index) {
|
|
6751
|
+
function clamp_calls(config, tool_map, calls, step_index) {
|
|
6629
6752
|
const cap = config.max_tool_calls_per_step;
|
|
6630
|
-
if (cap === void 0
|
|
6753
|
+
if (cap === void 0) return {
|
|
6631
6754
|
kept: calls,
|
|
6632
6755
|
dropped: []
|
|
6633
6756
|
};
|
|
6634
|
-
const
|
|
6635
|
-
|
|
6757
|
+
const cut = first_over_cap(calls, tool_map, cap);
|
|
6758
|
+
if (cut === -1) return {
|
|
6759
|
+
kept: calls,
|
|
6760
|
+
dropped: []
|
|
6761
|
+
};
|
|
6762
|
+
const kept = calls.slice(0, cut);
|
|
6763
|
+
const dropped = calls.slice(cut);
|
|
6636
6764
|
record_tool_calls_dropped(config.trajectory, {
|
|
6637
6765
|
step_index,
|
|
6638
6766
|
max_tool_calls_per_step: cap,
|
|
@@ -6644,7 +6772,8 @@ function clamp_calls(config, calls, step_index) {
|
|
|
6644
6772
|
});
|
|
6645
6773
|
return {
|
|
6646
6774
|
kept,
|
|
6647
|
-
dropped
|
|
6775
|
+
dropped,
|
|
6776
|
+
notice: dropped_notice(cap, dropped, config.tools.some((tool) => tool.read_only === true))
|
|
6648
6777
|
};
|
|
6649
6778
|
}
|
|
6650
6779
|
/**
|
|
@@ -6923,16 +7052,17 @@ function resolve_turn_finish_reason(ctx, salvaged, turn_finish) {
|
|
|
6923
7052
|
}
|
|
6924
7053
|
/**
|
|
6925
7054
|
* Build one StepRecord (cost derived and recorded, timing and
|
|
6926
|
-
* provider_reported passed through
|
|
6927
|
-
* close the step span.
|
|
7055
|
+
* provider_reported passed through, `truncated` set for a turn the loop went
|
|
7056
|
+
* on past), push it, notify on_finish_step, and close the step span.
|
|
6928
7057
|
*/
|
|
6929
|
-
function push_step_record(config, acc, step_index, turn, tool_calls, finish_reason, step_span) {
|
|
7058
|
+
function push_step_record(config, acc, step_index, turn, tool_calls, finish_reason, step_span, truncated = false) {
|
|
6930
7059
|
const record = {
|
|
6931
7060
|
index: step_index,
|
|
6932
7061
|
text: turn.text,
|
|
6933
7062
|
tool_calls,
|
|
6934
7063
|
usage: turn.usage,
|
|
6935
|
-
finish_reason
|
|
7064
|
+
finish_reason,
|
|
7065
|
+
...truncated ? { truncated: true } : {}
|
|
6936
7066
|
};
|
|
6937
7067
|
const breakdown = compute_and_record_cost(config, step_index, turn, step_span);
|
|
6938
7068
|
if (breakdown !== void 0) record.cost = breakdown;
|
|
@@ -6959,7 +7089,15 @@ async function run_loop_step(config, tool_map, acc, step_index) {
|
|
|
6959
7089
|
if (turn.tool_calls.length === 0) return continue_paused_turn(config, acc, step_index, step_span, turn);
|
|
6960
7090
|
}
|
|
6961
7091
|
const view = await salvage_turn(config, turn, tool_map, step_index);
|
|
6962
|
-
const
|
|
7092
|
+
const truncated = view.calls.length === 0 ? truncation_holder(config, turn, step_index) : void 0;
|
|
7093
|
+
if (truncated !== void 0) {
|
|
7094
|
+
continue_truncated_turn(config, acc, {
|
|
7095
|
+
step_index,
|
|
7096
|
+
step_span
|
|
7097
|
+
}, turn, truncated.max_tokens);
|
|
7098
|
+
return;
|
|
7099
|
+
}
|
|
7100
|
+
const { kept, dropped, notice } = clamp_calls(config, tool_map, view.calls, step_index);
|
|
6963
7101
|
config.messages.push(build_assistant_message(turn, view, kept));
|
|
6964
7102
|
if (kept.length === 0) {
|
|
6965
7103
|
push_step_record(config, acc, step_index, turn, [], turn.finish_reason, step_span);
|
|
@@ -6985,6 +7123,7 @@ async function run_loop_step(config, tool_map, acc, step_index) {
|
|
|
6985
7123
|
push_step_record(config, acc, step_index, turn, ctx.records, turn_finish_reason, step_span);
|
|
6986
7124
|
if (ctx.terminal_fired) return loop_result(acc, turn.text, "stop", false);
|
|
6987
7125
|
if (ctx.would_exceed_after) return loop_result(acc, turn.text, "max_steps", true);
|
|
7126
|
+
if (notice !== void 0) config.messages.push(notice);
|
|
6988
7127
|
acc.paused_texts.length = 0;
|
|
6989
7128
|
}
|
|
6990
7129
|
/**
|
|
@@ -7365,6 +7504,10 @@ const CAPTURE_LEVELS = {
|
|
|
7365
7504
|
turns: true,
|
|
7366
7505
|
wire: true
|
|
7367
7506
|
};
|
|
7507
|
+
const TRUNCATED_TURN_POLICIES = {
|
|
7508
|
+
stop: true,
|
|
7509
|
+
continue: true
|
|
7510
|
+
};
|
|
7368
7511
|
/**
|
|
7369
7512
|
* Throw `engine_config_error` when `value` is set to anything but a key of
|
|
7370
7513
|
* `allowed`, naming the field, the value, and the values it takes.
|
|
@@ -7391,6 +7534,15 @@ function assert_capture_level(value, field) {
|
|
|
7391
7534
|
assert_allowed(CAPTURE_LEVELS, value, field);
|
|
7392
7535
|
}
|
|
7393
7536
|
/**
|
|
7537
|
+
* Throw `engine_config_error` for a truncated-turn policy that isn't a
|
|
7538
|
+
* `TruncatedTurnPolicy`. `create_engine` checks
|
|
7539
|
+
* `defaults.truncated_turn_policy` with it, and `generate` a call's
|
|
7540
|
+
* `truncated_turn_policy`.
|
|
7541
|
+
*/
|
|
7542
|
+
function assert_truncated_turn_policy(value, field) {
|
|
7543
|
+
assert_allowed(TRUNCATED_TURN_POLICIES, value, field);
|
|
7544
|
+
}
|
|
7545
|
+
/**
|
|
7394
7546
|
* Resolve the provider name: per-call, then the engine default, then the sole
|
|
7395
7547
|
* configured adapter. With several providers configured and neither a per-call
|
|
7396
7548
|
* provider nor a default, there is no sane guess, so this throws
|
|
@@ -7528,7 +7680,8 @@ function resolve_loop_limits(opts, engine) {
|
|
|
7528
7680
|
tool_error_policy,
|
|
7529
7681
|
schema_repair_attempts,
|
|
7530
7682
|
salvage_budget,
|
|
7531
|
-
max_tool_calls_per_step
|
|
7683
|
+
max_tool_calls_per_step,
|
|
7684
|
+
truncated_turns: (opts.truncated_turn_policy ?? engine.default_truncated_turn_policy) === "continue" ? { max_tokens: opts.max_tokens } : void 0
|
|
7532
7685
|
};
|
|
7533
7686
|
}
|
|
7534
7687
|
/**
|
|
@@ -7666,6 +7819,7 @@ function build_loop_config(cfg) {
|
|
|
7666
7819
|
capture: cfg.capture,
|
|
7667
7820
|
...limits.salvage_budget !== void 0 ? { salvage_budget: limits.salvage_budget } : {},
|
|
7668
7821
|
...limits.max_tool_calls_per_step !== void 0 ? { max_tool_calls_per_step: limits.max_tool_calls_per_step } : {},
|
|
7822
|
+
truncated_turns: limits.truncated_turns,
|
|
7669
7823
|
...opts.prepare_step !== void 0 ? { prepare_step: opts.prepare_step } : {}
|
|
7670
7824
|
};
|
|
7671
7825
|
}
|
|
@@ -7821,6 +7975,7 @@ async function generate(opts_in, engine) {
|
|
|
7821
7975
|
assert_unique_tool_names(opts.tools);
|
|
7822
7976
|
assert_cache_setting(opts.cache, "cache");
|
|
7823
7977
|
assert_capture_level(opts.capture, "capture");
|
|
7978
|
+
assert_truncated_turn_policy(opts.truncated_turn_policy, "truncated_turn_policy");
|
|
7824
7979
|
if (adapter.kind === "external") return {
|
|
7825
7980
|
...await adapter.generate(opts, target),
|
|
7826
7981
|
timing: call_timing(started_at)
|
|
@@ -8116,6 +8271,7 @@ function build_internals(base, defaults) {
|
|
|
8116
8271
|
assign_if_present(internals, "default_schema_repair_attempts", defaults.schema_repair_attempts);
|
|
8117
8272
|
assign_if_present(internals, "default_tool_call_repair_attempts", defaults.tool_call_repair_attempts);
|
|
8118
8273
|
assign_if_present(internals, "default_max_tool_calls_per_step", defaults.max_tool_calls_per_step);
|
|
8274
|
+
assign_if_present(internals, "default_truncated_turn_policy", defaults.truncated_turn_policy);
|
|
8119
8275
|
assign_if_present(internals, "default_turn_timeout_ms", defaults.turn_timeout_ms);
|
|
8120
8276
|
assign_if_present(internals, "default_ai_sdk_telemetry", defaults.ai_sdk_telemetry);
|
|
8121
8277
|
assign_if_present(internals, "default_provider_options", defaults.provider_options);
|
|
@@ -8137,6 +8293,7 @@ function create_engine(config) {
|
|
|
8137
8293
|
validate_numeric_defaults(config.defaults);
|
|
8138
8294
|
assert_cache_setting(config.defaults?.cache, "defaults.cache");
|
|
8139
8295
|
assert_capture_level(config.defaults?.capture, "defaults.capture");
|
|
8296
|
+
assert_truncated_turn_policy(config.defaults?.truncated_turn_policy, "defaults.truncated_turn_policy");
|
|
8140
8297
|
const get_internals = () => ({
|
|
8141
8298
|
...build_internals({
|
|
8142
8299
|
pricing,
|
|
@@ -8190,4 +8347,4 @@ function create_engine(config) {
|
|
|
8190
8347
|
//#endregion
|
|
8191
8348
|
export { to_json_schema as n, create_engine as t };
|
|
8192
8349
|
|
|
8193
|
-
//# sourceMappingURL=engine-
|
|
8350
|
+
//# sourceMappingURL=engine-Bde18P7H.js.map
|