fascicle 0.12.3 → 0.12.7
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 +61 -6
- package/README.md +3 -2
- package/dist/agents.d.ts +1 -1
- package/dist/agents.js +1 -1
- package/dist/{core-DdJEhyQc.js → core-CFdEjtiT.js} +281 -270
- package/dist/core-CFdEjtiT.js.map +1 -0
- package/dist/{engine-J4lIxpw5.js → engine-DQiQHiy8.js} +182 -34
- package/dist/engine-DQiQHiy8.js.map +1 -0
- package/dist/index.d.ts +28 -2
- package/dist/index.js +48 -4
- package/dist/index.js.map +1 -1
- package/dist/{invoke-CH_eJZeS.js → invoke-eEYMZmWg.js} +3 -3
- package/dist/{invoke-CH_eJZeS.js.map → invoke-eEYMZmWg.js.map} +1 -1
- package/dist/{leading_system-BUCT-PwD.js → leading_system-DQmlA6Fs.js} +2 -2
- package/dist/{leading_system-BUCT-PwD.js.map → leading_system-DQmlA6Fs.js.map} +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +1 -1
- package/dist/otel.d.ts +20 -2
- package/dist/otel.js +228 -8
- package/dist/otel.js.map +1 -1
- package/dist/stdio.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +3 -3
- package/dist/{types-DU6cvoA4.d.ts → types-CLigYA62.d.ts} +28 -2
- package/dist/viewer-app/assets/index-BGb1-MwM.js +2 -0
- package/dist/viewer-app/assets/index-D7kvKs40.css +1 -0
- package/dist/viewer-app/fonts/sora-OFL.txt +93 -0
- package/dist/viewer-app/fonts/sora-latin.woff2 +0 -0
- package/dist/viewer-app/fonts/spline-sans-mono-OFL.txt +93 -0
- package/dist/viewer-app/fonts/spline-sans-mono-latin.woff2 +0 -0
- package/dist/viewer-app/index.html +13 -0
- package/dist/viewer.d.ts +17 -3
- package/dist/viewer.js +210 -50
- package/dist/viewer.js.map +1 -1
- package/package.json +14 -3
- package/dist/core-DdJEhyQc.js.map +0 -1
- package/dist/engine-J4lIxpw5.js.map +0 -1
- package/dist/static/viewer.html +0 -375
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { S as turn_timeout_error, _ as provider_required_error, a as normalize_local_usage, b as tool_approval_denied_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 rate_limit_error, x as tool_error, y as schema_validation_error } from "./leading_system-
|
|
1
|
+
import { h as wait_with_abort, k as aborted_error, m as compute_backoff, o as format_schema_issues, s as validate_schema } from "./core-CFdEjtiT.js";
|
|
2
|
+
import { S as turn_timeout_error, _ as provider_required_error, a as normalize_local_usage, b as tool_approval_denied_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 rate_limit_error, x as tool_error, y as schema_validation_error } from "./leading_system-DQmlA6Fs.js";
|
|
3
3
|
import { join } from "node:path";
|
|
4
4
|
import { mkdtempSync, writeFileSync } from "node:fs";
|
|
5
5
|
import { tmpdir } from "node:os";
|
|
@@ -387,6 +387,22 @@ function next_backoff(retryable, backoff_policy, attempt) {
|
|
|
387
387
|
return { delay };
|
|
388
388
|
}
|
|
389
389
|
/**
|
|
390
|
+
* Assemble the `on_retry` payload from the classified failure and the backoff
|
|
391
|
+
* the retry will actually wait.
|
|
392
|
+
*/
|
|
393
|
+
function build_attempt_info(retryable, attempt, delay_ms) {
|
|
394
|
+
const info = {
|
|
395
|
+
attempt,
|
|
396
|
+
failure_kind: retryable.kind,
|
|
397
|
+
delay_ms
|
|
398
|
+
};
|
|
399
|
+
if (retryable.kind === "rate_limit" || retryable.kind === "provider_5xx") {
|
|
400
|
+
if (retryable.status !== void 0) info.status = retryable.status;
|
|
401
|
+
}
|
|
402
|
+
if (retryable.kind === "rate_limit" && retryable.retry_after_ms !== void 0) info.retry_after_ms = retryable.retry_after_ms;
|
|
403
|
+
return info;
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
390
406
|
* Retry `fn` under `policy`. `fn` must throw a RetryableError-shaped object to
|
|
391
407
|
* trigger retry; any other thrown value short-circuits as a permanent failure.
|
|
392
408
|
*
|
|
@@ -394,8 +410,13 @@ function next_backoff(retryable, backoff_policy, attempt) {
|
|
|
394
410
|
* `aborted_error`. Returns the value from the last successful `fn()` call. On
|
|
395
411
|
* exhaustion, throws `rate_limit_error` (for 429s) or `provider_error` (for
|
|
396
412
|
* 5xx/network/timeout).
|
|
413
|
+
*
|
|
414
|
+
* `on_retry` fires once per retried failure, just before its backoff wait.
|
|
415
|
+
* It does NOT fire for a first attempt that succeeds, a non-retryable
|
|
416
|
+
* failure, or the final failure that exhausts the policy (those two throw
|
|
417
|
+
* instead), so its call count is exactly the number of extra attempts made.
|
|
397
418
|
*/
|
|
398
|
-
async function retry_with_policy(fn, policy = DEFAULT_RETRY, abort) {
|
|
419
|
+
async function retry_with_policy(fn, policy = DEFAULT_RETRY, abort, on_retry) {
|
|
399
420
|
const backoff_policy = {
|
|
400
421
|
initial_delay_ms: policy.initial_delay_ms,
|
|
401
422
|
max_delay_ms: policy.max_delay_ms,
|
|
@@ -415,6 +436,7 @@ async function retry_with_policy(fn, policy = DEFAULT_RETRY, abort) {
|
|
|
415
436
|
if (attempt >= policy.max_attempts) throw build_exhaustion_error(retryable, attempt, last_rate_limit_after);
|
|
416
437
|
const backoff = next_backoff(retryable, backoff_policy, attempt);
|
|
417
438
|
last_rate_limit_after = backoff.retry_after_ms ?? last_rate_limit_after;
|
|
439
|
+
on_retry?.(build_attempt_info(retryable, attempt, backoff.delay));
|
|
418
440
|
await wait_with_abort(backoff.delay, signal, to_abort_error);
|
|
419
441
|
}
|
|
420
442
|
}
|
|
@@ -2071,6 +2093,28 @@ function map_ollama_usage(payload) {
|
|
|
2071
2093
|
output_tokens: typeof evaluated === "number" ? evaluated : 0
|
|
2072
2094
|
};
|
|
2073
2095
|
}
|
|
2096
|
+
const REPORTED_DURATION_FIELDS = [
|
|
2097
|
+
"total_duration",
|
|
2098
|
+
"load_duration",
|
|
2099
|
+
"prompt_eval_duration",
|
|
2100
|
+
"eval_duration"
|
|
2101
|
+
];
|
|
2102
|
+
/**
|
|
2103
|
+
* Collect the daemon's nanosecond duration fields for verbatim passthrough
|
|
2104
|
+
* under `provider_reported.ollama`: the daemon's own decode/prefill timing,
|
|
2105
|
+
* which is what an honest local tokens-per-second number derives from
|
|
2106
|
+
* (eval_count over eval_duration). Units and names stay the wire's own, per
|
|
2107
|
+
* the provider_reported contract; returns undefined when none are present
|
|
2108
|
+
* (mid-proxy shapes that strip them), never an empty object.
|
|
2109
|
+
*/
|
|
2110
|
+
function map_ollama_reported(payload) {
|
|
2111
|
+
const out = {};
|
|
2112
|
+
for (const key of REPORTED_DURATION_FIELDS) {
|
|
2113
|
+
const value = Reflect.get(payload, key);
|
|
2114
|
+
if (typeof value === "number") out[key] = value;
|
|
2115
|
+
}
|
|
2116
|
+
return Object.keys(out).length > 0 ? out : void 0;
|
|
2117
|
+
}
|
|
2074
2118
|
/**
|
|
2075
2119
|
* This wire sends no tool-call id, so one is synthesized from the step index
|
|
2076
2120
|
* and the call's ordinal within the turn: deterministic, so the streamed and
|
|
@@ -2105,11 +2149,13 @@ function parse_ollama_chat(payload, step_index) {
|
|
|
2105
2149
|
const content = Reflect.get(message, "content");
|
|
2106
2150
|
const raw_tool_calls = Reflect.get(message, "tool_calls");
|
|
2107
2151
|
const tool_calls = Array.isArray(raw_tool_calls) ? raw_tool_calls.map((entry, ordinal) => parse_ollama_tool_call(entry, ordinal, step_index)) : [];
|
|
2152
|
+
const reported = map_ollama_reported(payload);
|
|
2108
2153
|
return {
|
|
2109
2154
|
text: typeof content === "string" ? content : "",
|
|
2110
2155
|
tool_calls,
|
|
2111
2156
|
finish_reason: map_ollama_finish_reason(Reflect.get(payload, "done_reason"), tool_calls.length > 0),
|
|
2112
|
-
usage: map_ollama_usage(payload)
|
|
2157
|
+
usage: map_ollama_usage(payload),
|
|
2158
|
+
...reported !== void 0 ? { provider_reported: { ollama: reported } } : {}
|
|
2113
2159
|
};
|
|
2114
2160
|
}
|
|
2115
2161
|
/**
|
|
@@ -2145,6 +2191,7 @@ function create_ollama_stream_aggregator(step_index, dispatch) {
|
|
|
2145
2191
|
input_tokens: 0,
|
|
2146
2192
|
output_tokens: 0
|
|
2147
2193
|
};
|
|
2194
|
+
let reported;
|
|
2148
2195
|
const on_message = async (message) => {
|
|
2149
2196
|
const content = Reflect.get(message, "content");
|
|
2150
2197
|
if (typeof content === "string" && content.length > 0) {
|
|
@@ -2190,6 +2237,7 @@ function create_ollama_stream_aggregator(step_index, dispatch) {
|
|
|
2190
2237
|
done = true;
|
|
2191
2238
|
done_reason = Reflect.get(frame, "done_reason");
|
|
2192
2239
|
usage = map_ollama_usage(frame);
|
|
2240
|
+
reported = map_ollama_reported(frame);
|
|
2193
2241
|
await dispatch({
|
|
2194
2242
|
kind: "step_finish",
|
|
2195
2243
|
step_index,
|
|
@@ -2216,7 +2264,8 @@ function create_ollama_stream_aggregator(step_index, dispatch) {
|
|
|
2216
2264
|
done: true,
|
|
2217
2265
|
done_reason: done_reason ?? null,
|
|
2218
2266
|
prompt_eval_count: usage.input_tokens,
|
|
2219
|
-
eval_count: usage.output_tokens
|
|
2267
|
+
eval_count: usage.output_tokens,
|
|
2268
|
+
...reported
|
|
2220
2269
|
}, step_index);
|
|
2221
2270
|
}
|
|
2222
2271
|
};
|
|
@@ -4061,7 +4110,10 @@ function start_generate_span(trajectory, meta) {
|
|
|
4061
4110
|
}
|
|
4062
4111
|
/**
|
|
4063
4112
|
* Close the `engine.generate` span with usage, finish reason, resolved model,
|
|
4064
|
-
* or the error message on failure.
|
|
4113
|
+
* or the error message on failure. `step_count` and `tool_call_count` are the
|
|
4114
|
+
* call-level totals (model turns and tool executions in the call), the
|
|
4115
|
+
* span-attribute analog of the GenAI semconv agent metrics
|
|
4116
|
+
* `inference_calls` / `tool_calls`.
|
|
4065
4117
|
*/
|
|
4066
4118
|
function end_generate_span(trajectory, span_id, meta) {
|
|
4067
4119
|
if (trajectory === void 0 || span_id === void 0) return;
|
|
@@ -4082,6 +4134,66 @@ function end_step_span(trajectory, span_id, meta) {
|
|
|
4082
4134
|
trajectory.end_span(span_id, { ...meta });
|
|
4083
4135
|
}
|
|
4084
4136
|
/**
|
|
4137
|
+
* Record a provider response: finish reason, flat token counts, and the
|
|
4138
|
+
* engine-measured turn timing when the turn carried one.
|
|
4139
|
+
*
|
|
4140
|
+
* Every field is a flat number or string on purpose. An OTel span event or a
|
|
4141
|
+
* log pipeline can aggregate `input_tokens` / `duration_ms` /
|
|
4142
|
+
* `first_chunk_ms` directly, where a nested usage object would arrive as an
|
|
4143
|
+
* opaque JSON string. This is the one per-turn event a metrics dashboard
|
|
4144
|
+
* needs: tokens by direction, the cache and reasoning splits when the
|
|
4145
|
+
* provider reports them, and the model-only latency window.
|
|
4146
|
+
*/
|
|
4147
|
+
function record_response_received(trajectory, step_index, turn, span_id) {
|
|
4148
|
+
if (trajectory === void 0) return;
|
|
4149
|
+
const { usage, timing } = turn;
|
|
4150
|
+
const event = {
|
|
4151
|
+
kind: "response_received",
|
|
4152
|
+
step_index,
|
|
4153
|
+
input_tokens: usage.input_tokens,
|
|
4154
|
+
output_tokens: usage.output_tokens,
|
|
4155
|
+
finish_reason: turn.finish_reason
|
|
4156
|
+
};
|
|
4157
|
+
if (span_id !== void 0) event["span_id"] = span_id;
|
|
4158
|
+
if (usage.reasoning_tokens !== void 0) event["reasoning_tokens"] = usage.reasoning_tokens;
|
|
4159
|
+
if (usage.cached_input_tokens !== void 0) event["cached_input_tokens"] = usage.cached_input_tokens;
|
|
4160
|
+
if (usage.cache_write_tokens !== void 0) event["cache_write_tokens"] = usage.cache_write_tokens;
|
|
4161
|
+
if (timing !== void 0) {
|
|
4162
|
+
event["started_at"] = timing.started_at;
|
|
4163
|
+
event["duration_ms"] = timing.duration_ms;
|
|
4164
|
+
if (timing.first_chunk_ms !== void 0) event["first_chunk_ms"] = timing.first_chunk_ms;
|
|
4165
|
+
}
|
|
4166
|
+
trajectory.record({
|
|
4167
|
+
kind: "response_received",
|
|
4168
|
+
...event
|
|
4169
|
+
});
|
|
4170
|
+
}
|
|
4171
|
+
/**
|
|
4172
|
+
* Record one failed-then-retried provider attempt as a `turn_retry` event:
|
|
4173
|
+
* the 1-based attempt count, the classified failure kind, the backoff this
|
|
4174
|
+
* retry waits, and the HTTP status / `Retry-After` when the failure carried
|
|
4175
|
+
* them. This is the event a rate-limit or error-budget dashboard counts;
|
|
4176
|
+
* without it, only the final exhaustion is visible (as a span error), and
|
|
4177
|
+
* every absorbed 429 or 5xx goes unrecorded.
|
|
4178
|
+
*/
|
|
4179
|
+
function record_turn_retry(trajectory, step_index, info, span_id) {
|
|
4180
|
+
if (trajectory === void 0) return;
|
|
4181
|
+
const event = {
|
|
4182
|
+
kind: "turn_retry",
|
|
4183
|
+
step_index,
|
|
4184
|
+
attempt: info.attempt,
|
|
4185
|
+
failure_kind: info.failure_kind,
|
|
4186
|
+
delay_ms: info.delay_ms
|
|
4187
|
+
};
|
|
4188
|
+
if (span_id !== void 0) event["span_id"] = span_id;
|
|
4189
|
+
if (info.status !== void 0) event["status"] = info.status;
|
|
4190
|
+
if (info.retry_after_ms !== void 0) event["retry_after_ms"] = info.retry_after_ms;
|
|
4191
|
+
trajectory.record({
|
|
4192
|
+
kind: "turn_retry",
|
|
4193
|
+
...event
|
|
4194
|
+
});
|
|
4195
|
+
}
|
|
4196
|
+
/**
|
|
4085
4197
|
* Record a tool invocation request: name, call id, input, and duration.
|
|
4086
4198
|
*/
|
|
4087
4199
|
function record_tool_call(trajectory, meta) {
|
|
@@ -4157,8 +4269,14 @@ function with_timestamps(inner) {
|
|
|
4157
4269
|
/**
|
|
4158
4270
|
* Record a per-step cost breakdown, tagged with whether the engine derived it
|
|
4159
4271
|
* from pricing tables or the provider reported it directly.
|
|
4272
|
+
*
|
|
4273
|
+
* `span_id` is the enclosing `engine.generate.step` span when the tool loop
|
|
4274
|
+
* emits, so a consumer attributes cost to its exact turn instead of guessing
|
|
4275
|
+
* from an open-span stack (which mis-attributes under `parallel`). It stays
|
|
4276
|
+
* optional so paths without that span in hand (a provider-reported CLI cost)
|
|
4277
|
+
* emit unattributed and legibly so.
|
|
4160
4278
|
*/
|
|
4161
|
-
function record_cost(trajectory, step_index, cost, source) {
|
|
4279
|
+
function record_cost(trajectory, step_index, cost, source, span_id) {
|
|
4162
4280
|
if (trajectory === void 0) return;
|
|
4163
4281
|
const event = {
|
|
4164
4282
|
kind: "cost",
|
|
@@ -4168,6 +4286,7 @@ function record_cost(trajectory, step_index, cost, source) {
|
|
|
4168
4286
|
input_usd: cost.input_usd,
|
|
4169
4287
|
output_usd: cost.output_usd
|
|
4170
4288
|
};
|
|
4289
|
+
if (span_id !== void 0) event["span_id"] = span_id;
|
|
4171
4290
|
if (cost.cached_input_usd !== void 0) event["cached_input_usd"] = cost.cached_input_usd;
|
|
4172
4291
|
if (cost.cache_write_usd !== void 0) event["cache_write_usd"] = cost.cache_write_usd;
|
|
4173
4292
|
if (cost.reasoning_usd !== void 0) event["reasoning_usd"] = cost.reasoning_usd;
|
|
@@ -5517,14 +5636,14 @@ function build_assistant_message(text, tool_calls) {
|
|
|
5517
5636
|
* Missing pricing for a paid provider emits `pricing_missing` (deduped per
|
|
5518
5637
|
* call) and yields no breakdown; free providers skip the emit entirely.
|
|
5519
5638
|
*/
|
|
5520
|
-
function compute_and_record_cost(config, step_index, usage) {
|
|
5639
|
+
function compute_and_record_cost(config, step_index, usage, step_span) {
|
|
5521
5640
|
const pricing = config.resolve_pricing();
|
|
5522
5641
|
if (pricing === void 0 && !FREE_PROVIDERS.has(config.provider)) {
|
|
5523
5642
|
config.pricing_dedup.emit(config.provider, config.model_id);
|
|
5524
5643
|
return;
|
|
5525
5644
|
}
|
|
5526
5645
|
const breakdown = compute_cost(usage, pricing, config.provider);
|
|
5527
|
-
if (breakdown !== void 0) record_cost(config.trajectory, step_index, breakdown, "engine_derived");
|
|
5646
|
+
if (breakdown !== void 0) record_cost(config.trajectory, step_index, breakdown, "engine_derived", step_span);
|
|
5528
5647
|
return breakdown;
|
|
5529
5648
|
}
|
|
5530
5649
|
/**
|
|
@@ -5595,14 +5714,10 @@ async function invoke_turn(config, step_index, step_span) {
|
|
|
5595
5714
|
messages: request_messages,
|
|
5596
5715
|
tools: config.tools,
|
|
5597
5716
|
abort: config.abort,
|
|
5598
|
-
stream: config.stream
|
|
5599
|
-
|
|
5600
|
-
config.trajectory?.record({
|
|
5601
|
-
kind: "response_received",
|
|
5602
|
-
step_index,
|
|
5603
|
-
output_tokens: turn.usage.output_tokens,
|
|
5604
|
-
finish_reason: turn.finish_reason
|
|
5717
|
+
stream: config.stream,
|
|
5718
|
+
step_span
|
|
5605
5719
|
});
|
|
5720
|
+
record_response_received(config.trajectory, step_index, turn, step_span);
|
|
5606
5721
|
return turn;
|
|
5607
5722
|
} catch (err) {
|
|
5608
5723
|
const message = err instanceof Error ? err.message : String(err);
|
|
@@ -5984,8 +6099,9 @@ function resolve_turn_finish_reason(ctx, salvaged, turn_finish) {
|
|
|
5984
6099
|
return turn_finish;
|
|
5985
6100
|
}
|
|
5986
6101
|
/**
|
|
5987
|
-
* Build one StepRecord (cost derived and recorded,
|
|
5988
|
-
* passed through), push it, notify on_finish_step, and
|
|
6102
|
+
* Build one StepRecord (cost derived and recorded, timing and
|
|
6103
|
+
* provider_reported passed through), push it, notify on_finish_step, and
|
|
6104
|
+
* close the step span.
|
|
5989
6105
|
*/
|
|
5990
6106
|
function push_step_record(config, acc, step_index, turn, tool_calls, finish_reason, step_span) {
|
|
5991
6107
|
const record = {
|
|
@@ -5995,8 +6111,9 @@ function push_step_record(config, acc, step_index, turn, tool_calls, finish_reas
|
|
|
5995
6111
|
usage: turn.usage,
|
|
5996
6112
|
finish_reason
|
|
5997
6113
|
};
|
|
5998
|
-
const breakdown = compute_and_record_cost(config, step_index, turn.usage);
|
|
6114
|
+
const breakdown = compute_and_record_cost(config, step_index, turn.usage, step_span);
|
|
5999
6115
|
if (breakdown !== void 0) record.cost = breakdown;
|
|
6116
|
+
if (turn.timing !== void 0) record.timing = turn.timing;
|
|
6000
6117
|
if (turn.provider_reported !== void 0) record.provider_reported = turn.provider_reported;
|
|
6001
6118
|
acc.steps.push(record);
|
|
6002
6119
|
if (config.on_finish_step !== void 0) config.on_finish_step(record);
|
|
@@ -6241,12 +6358,24 @@ function arm_turn_timeout(user_abort, turn_timeout_ms) {
|
|
|
6241
6358
|
* actually cancels the in-flight request. Adapters may swap `classify`, but
|
|
6242
6359
|
* never the ladder itself: the engine owns retry, so a hidden adapter-level
|
|
6243
6360
|
* retry would be invisible to anything relying on this ladder.
|
|
6244
|
-
|
|
6245
|
-
|
|
6361
|
+
*
|
|
6362
|
+
* The wrapper also stamps StepTiming here, and only here, because this is the
|
|
6363
|
+
* one place that can see attempt boundaries: started_at re-stamps at every
|
|
6364
|
+
* attempt entry, so failed attempts and backoff waits never inflate
|
|
6365
|
+
* duration_ms. `first_chunk_at` (the builder's Date.now() from its first
|
|
6366
|
+
* dispatched chunk) can only belong to the returning attempt, since any
|
|
6367
|
+
* failure after a chunk has flowed is non-retryable by the ladder below.
|
|
6368
|
+
*/
|
|
6369
|
+
function retry_turn(call_once, args, first_chunk_at, retry_policy, classify, turn_timeout_ms, trajectory) {
|
|
6370
|
+
const has_streamed = () => first_chunk_at() !== void 0;
|
|
6246
6371
|
return retry_with_policy(async () => {
|
|
6372
|
+
const started_at = Date.now();
|
|
6247
6373
|
const deadline = arm_turn_timeout(args.abort, turn_timeout_ms);
|
|
6248
6374
|
try {
|
|
6249
|
-
return
|
|
6375
|
+
return {
|
|
6376
|
+
...await call_once(deadline.signal),
|
|
6377
|
+
timing: build_step_timing(started_at, first_chunk_at())
|
|
6378
|
+
};
|
|
6250
6379
|
} catch (err) {
|
|
6251
6380
|
if (err instanceof on_chunk_error) throw err;
|
|
6252
6381
|
if (args.abort.aborted) throw new aborted_error("aborted", {
|
|
@@ -6260,28 +6389,43 @@ function retry_turn(call_once, args, has_streamed, retry_policy, classify, turn_
|
|
|
6260
6389
|
} finally {
|
|
6261
6390
|
deadline.dispose();
|
|
6262
6391
|
}
|
|
6263
|
-
}, retry_policy, args.abort)
|
|
6392
|
+
}, retry_policy, args.abort, (info) => {
|
|
6393
|
+
record_turn_retry(trajectory, args.step_index, info, args.step_span);
|
|
6394
|
+
});
|
|
6395
|
+
}
|
|
6396
|
+
/**
|
|
6397
|
+
* Assemble one turn's StepTiming from the attempt's start stamp and the
|
|
6398
|
+
* builder's first-chunk stamp (undefined on non-streamed turns).
|
|
6399
|
+
*/
|
|
6400
|
+
function build_step_timing(started_at, first_chunk) {
|
|
6401
|
+
const timing = {
|
|
6402
|
+
started_at,
|
|
6403
|
+
duration_ms: Date.now() - started_at
|
|
6404
|
+
};
|
|
6405
|
+
if (first_chunk !== void 0) timing.first_chunk_ms = first_chunk - started_at;
|
|
6406
|
+
return timing;
|
|
6264
6407
|
}
|
|
6265
6408
|
/**
|
|
6266
6409
|
* Build the ai_sdk-transport InvokeOnce: the SDK turn built by
|
|
6267
6410
|
* providers/ai_sdk/invoke.ts behind the same engine-owned retry_turn wrapper
|
|
6268
6411
|
* the native path uses. The SDK call body lives behind the seam; this builder
|
|
6269
6412
|
* owns only retry and the streamed-output tracking that makes a mid-stream
|
|
6270
|
-
* failure a non-retryable interruption
|
|
6413
|
+
* failure a non-retryable interruption (the same first-chunk stamp doubles as
|
|
6414
|
+
* StepTiming.first_chunk_ms).
|
|
6271
6415
|
*/
|
|
6272
6416
|
function build_ai_sdk_invoke(cfg) {
|
|
6273
6417
|
return async (args) => {
|
|
6274
|
-
let
|
|
6418
|
+
let first_chunk_at;
|
|
6275
6419
|
const call_once = (turn_abort) => cfg.invoke_turn({
|
|
6276
6420
|
step_index: args.step_index,
|
|
6277
6421
|
messages: args.messages,
|
|
6278
6422
|
abort: turn_abort,
|
|
6279
6423
|
stream: args.stream,
|
|
6280
6424
|
on_first_chunk: () => {
|
|
6281
|
-
|
|
6425
|
+
first_chunk_at ??= Date.now();
|
|
6282
6426
|
}
|
|
6283
6427
|
});
|
|
6284
|
-
return await retry_turn(call_once, args, () =>
|
|
6428
|
+
return await retry_turn(call_once, args, () => first_chunk_at, cfg.retry_policy, classify_provider_error, cfg.turn_timeout_ms, cfg.trajectory);
|
|
6285
6429
|
};
|
|
6286
6430
|
}
|
|
6287
6431
|
/**
|
|
@@ -6295,7 +6439,7 @@ function build_ai_sdk_invoke(cfg) {
|
|
|
6295
6439
|
function build_native_invoke(cfg) {
|
|
6296
6440
|
const classify = cfg.adapter.classify_error ?? classify_provider_error;
|
|
6297
6441
|
return async (args) => {
|
|
6298
|
-
let
|
|
6442
|
+
let first_chunk_at;
|
|
6299
6443
|
const call_once = async (turn_abort) => {
|
|
6300
6444
|
const internal_controller = new AbortController();
|
|
6301
6445
|
const cancel_on_turn_abort = () => {
|
|
@@ -6304,7 +6448,7 @@ function build_native_invoke(cfg) {
|
|
|
6304
6448
|
if (turn_abort.aborted) internal_controller.abort(turn_abort.reason);
|
|
6305
6449
|
else turn_abort.addEventListener("abort", cancel_on_turn_abort, { once: true });
|
|
6306
6450
|
const dispatch_chunk = async (chunk) => {
|
|
6307
|
-
|
|
6451
|
+
first_chunk_at ??= Date.now();
|
|
6308
6452
|
try {
|
|
6309
6453
|
await cfg.dispatcher.dispatch(chunk);
|
|
6310
6454
|
} catch (err) {
|
|
@@ -6335,7 +6479,7 @@ function build_native_invoke(cfg) {
|
|
|
6335
6479
|
turn_abort.removeEventListener("abort", cancel_on_turn_abort);
|
|
6336
6480
|
}
|
|
6337
6481
|
};
|
|
6338
|
-
return await retry_turn(call_once, args, () =>
|
|
6482
|
+
return await retry_turn(call_once, args, () => first_chunk_at, cfg.retry_policy, classify, cfg.turn_timeout_ms, cfg.trajectory);
|
|
6339
6483
|
};
|
|
6340
6484
|
}
|
|
6341
6485
|
/**
|
|
@@ -6451,7 +6595,7 @@ async function build_ai_sdk_transport(cfg) {
|
|
|
6451
6595
|
const provider_options = combined_provider_options !== void 0 && Object.keys(combined_provider_options).length > 0 ? combined_provider_options : void 0;
|
|
6452
6596
|
let ai_sdk_invoke_mod;
|
|
6453
6597
|
try {
|
|
6454
|
-
ai_sdk_invoke_mod = await import("./invoke-
|
|
6598
|
+
ai_sdk_invoke_mod = await import("./invoke-eEYMZmWg.js");
|
|
6455
6599
|
} catch (err) {
|
|
6456
6600
|
throw missing_peer_error("ai", err);
|
|
6457
6601
|
}
|
|
@@ -6470,7 +6614,8 @@ async function build_ai_sdk_transport(cfg) {
|
|
|
6470
6614
|
telemetry: cfg.telemetry
|
|
6471
6615
|
}),
|
|
6472
6616
|
retry_policy: cfg.retry_policy,
|
|
6473
|
-
turn_timeout_ms: cfg.turn_timeout_ms
|
|
6617
|
+
turn_timeout_ms: cfg.turn_timeout_ms,
|
|
6618
|
+
trajectory: cfg.trajectory
|
|
6474
6619
|
});
|
|
6475
6620
|
}
|
|
6476
6621
|
/**
|
|
@@ -6684,6 +6829,7 @@ async function generate(opts_in, engine) {
|
|
|
6684
6829
|
model_id: target.model_id,
|
|
6685
6830
|
retry_policy: turn.retry_policy,
|
|
6686
6831
|
turn_timeout_ms: turn.turn_timeout_ms,
|
|
6832
|
+
trajectory,
|
|
6687
6833
|
dispatcher,
|
|
6688
6834
|
effort: turn.effort,
|
|
6689
6835
|
schema: opts.schema,
|
|
@@ -6729,7 +6875,9 @@ async function generate(opts_in, engine) {
|
|
|
6729
6875
|
end_generate_span(trajectory, generate_span, {
|
|
6730
6876
|
usage: result.usage,
|
|
6731
6877
|
finish_reason: outcome.finish_reason,
|
|
6732
|
-
model_resolved: result.model_resolved
|
|
6878
|
+
model_resolved: result.model_resolved,
|
|
6879
|
+
step_count: result.steps.length,
|
|
6880
|
+
tool_call_count: result.tool_calls.length
|
|
6733
6881
|
});
|
|
6734
6882
|
return result;
|
|
6735
6883
|
} catch (err) {
|
|
@@ -6997,4 +7145,4 @@ function create_engine(config) {
|
|
|
6997
7145
|
//#endregion
|
|
6998
7146
|
export { create_engine as t };
|
|
6999
7147
|
|
|
7000
|
-
//# sourceMappingURL=engine-
|
|
7148
|
+
//# sourceMappingURL=engine-DQiQHiy8.js.map
|