fascicle 0.9.11 → 0.10.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 +26 -0
- package/dist/agents.d.ts +1 -1
- package/dist/{index-BwkQPMfX.d.ts → index-BNgtkeUf.d.ts} +42 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +80 -10
- package/dist/index.js.map +1 -1
- package/dist/mcp.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v0.10.1 — 2026-08-07
|
|
4
|
+
|
|
5
|
+
### Fixed
|
|
6
|
+
|
|
7
|
+
- **A schema call that finished without finishing no longer returns unchecked text typed as your schema.** `generate` gated schema parsing on `finish_reason === 'stop'` and, on any other finish, fell through to returning the raw model text cast to `T`. A Bedrock guardrail block, a `max_tokens` truncation, or a step-cap exit therefore produced a `GenerateResult<T>` whose `content` was a string wearing the schema's type: reading a field off it crashed, and a defensive consumer got `undefined` fields instead, so a blocked call could score as a low-risk one. The gate now throws `incomplete_generation_error` (exported from `fascicle`) carrying `finish_reason`, `raw_text`, and `provider_reported`, the last so a guardrail's own assessment stays reachable from the catch without logging the matched text. Repair is still not attempted, which was the one correct half of the old behaviour: re-prompting a model that was blocked or cut off cannot produce the missing value. The error is deliberately distinct from `schema_validation_error`, which continues to mean a response that completed normally and then failed validation. **Breaking for schema callers** who relied on the old return: those calls now reject, and a streamed one rejects after its text deltas without emitting a `finish` chunk, matching what `schema_validation_error` already did. Calls without a schema are untouched — `content_filter` and `length` still return the partial text with the finish reason. `claude_cli` was never affected (it validates unconditionally and reports every completion as `stop`), so this closes a divergence between the transports rather than opening one. The flipped criterion is pinned in `spec_coverage.test.ts`, the finish reasons and the no-repair guarantee in `generate.test.ts`, and the payload's survival onto the error across plain, streamed, and multi-step runs in `provider_reported.test.ts`.
|
|
8
|
+
|
|
9
|
+
- **A schema that validates to `undefined` returned the raw model text instead of the validated value.** `generate` tracked its parsed value in a `T | undefined` and gated the final read on `content_parsed !== undefined`, so a schema whose `.transform()` or `.catch()` legitimately yields `undefined` parsed successfully and was then discarded in favour of the raw string, cast to `T`. The parsed value now rides a `{ value: T }` holder, which distinguishes "validated to undefined" from "nothing parsed" and collapses the three-way final-content branch to two. This also retires the comment claiming the fallthrough was unreachable: it was reachable before this release, and the branch that remains is the no-schema one.
|
|
10
|
+
|
|
11
|
+
### Internal
|
|
12
|
+
|
|
13
|
+
- **The two grandfathered `unused_class_members` findings on `errors.ts` are resolved rather than baselined.** `turn_timeout_error.kind` and `schema_validation_error.kind` have no in-repo production reader — `classify_retryable` reaches them through `read_string(err, 'kind')` on an `unknown`, and external consumers switch on the discriminant outside this repo — so the finding was a limitation of static analysis, not real debt. Both now carry an inline `fallow-ignore-next-line` with the reason beside the field, and the baseline entries are gone. The entries were anchored by `line:col`, so any edit above them re-surfaced frozen debt as a new finding; documenting the intent at the field removes that fragility.
|
|
14
|
+
|
|
15
|
+
## v0.10.0 — 2026-08-05
|
|
16
|
+
|
|
17
|
+
### Added
|
|
18
|
+
|
|
19
|
+
- **`provider_reported` now carries what an `ai_sdk` provider reports, for every provider on that transport.** The AI SDK returns provider-volunteered detail on `providerMetadata` (Bedrock's guardrail trace, Anthropic's cache breakdown, OpenAI's service tier), already keyed by provider name. The transport read `text`, `toolCalls`, `finishReason`, and `usage` off the result and dropped the rest, so `GenerateResult.provider_reported` was structurally unreachable for every ai_sdk provider: only `claude_cli` ever populated it. The neutral `TurnResult` gains an optional `provider_reported`, the transport fills it from `providerMetadata` on both the `generateText` result and the streamed step-finish (so a streamed run and a plain run of the same call still report identically), the loop copies it onto `steps[i].provider_reported`, and `generate` folds the last reporting step into the call-level field. Keys and payloads ride through untranslated, so `provider_reported.bedrock.trace` needs no translation layer and a custom `ai_sdk` provider is served without per-provider code; a `native` adapter fills the same field from its own `invoke_turn`. Finish-reason mapping is untouched: a guardrail intervention still surfaces as `content_filter`, now with the trace beside it. This closes a real blind spot for Bedrock guardrails configured with a PII action of `NONE`, which detect and report without rewriting: the model output is byte-identical whether such a guardrail is attached and detecting or absent entirely, so the trace was the only in-process evidence it ran. `bedrock_guardrail_wire.test.ts` pins the round trip against the real peer over a stubbed fetch, and `provider_reported.test.ts` pins pass-through, stream parity, and the multi-step semantics.
|
|
20
|
+
|
|
21
|
+
### Fixed
|
|
22
|
+
|
|
23
|
+
- **`docs/cli.md` named a `provider_reported` path that does not exist.** The multi-turn recipe said to capture `result.provider_reported.session_id`, but the adapter reports under a provider-name key, so the value has always been at `result.provider_reported.claude_cli.session_id`. Following the documented path yielded `undefined` and a fresh session on every call.
|
|
24
|
+
|
|
25
|
+
### Internal
|
|
26
|
+
|
|
27
|
+
- **The Bedrock guardrail docs show how to read the trace the change above made readable.** `docs/providers.md` gains a worked read of `provider_reported.bedrock.trace` beside the existing guardrail recipe, `docs/troubleshooting.md` gains an entry for the symptom that actually gets reported ("the guardrail seems ignored, the output came back unchanged"), and the adapter docstring carries the same claim at the source. The entry separates policy from wiring: a PII action of `NONE` detects without rewriting, so unchanged output is the configured behaviour rather than a dropped `guardrailConfig`, and the way to test the wiring instead is a deliberately invalid `guardrailIdentifier`: AWS rejects the call only if the config reached the Converse command, so a call that succeeds is the failure signal.
|
|
28
|
+
|
|
3
29
|
## v0.9.11 — 2026-08-05
|
|
4
30
|
|
|
5
31
|
### Added
|
package/dist/agents.d.ts
CHANGED
|
@@ -189,6 +189,12 @@ type StepRecord = {
|
|
|
189
189
|
usage: UsageTotals;
|
|
190
190
|
cost?: CostBreakdown;
|
|
191
191
|
finish_reason: FinishReason;
|
|
192
|
+
/**
|
|
193
|
+
* This turn's provider-reported detail, keyed by provider name. See
|
|
194
|
+
* TurnResult.provider_reported; a multi-step call keeps every turn's payload
|
|
195
|
+
* here, since the call-level field can only carry one.
|
|
196
|
+
*/
|
|
197
|
+
provider_reported?: Record<string, unknown>;
|
|
192
198
|
};
|
|
193
199
|
type UserContentPart = {
|
|
194
200
|
type: 'text';
|
|
@@ -307,6 +313,18 @@ type TurnResult = {
|
|
|
307
313
|
}>;
|
|
308
314
|
readonly finish_reason: FinishReason;
|
|
309
315
|
readonly usage: UsageTotals;
|
|
316
|
+
/**
|
|
317
|
+
* Opaque detail the provider reported about this turn, keyed by provider
|
|
318
|
+
* name: Bedrock's guardrail trace, Anthropic's cache breakdown, whatever a
|
|
319
|
+
* given provider volunteers beyond text/usage/finish_reason. The keys are the
|
|
320
|
+
* provider's own, so a caller narrows `provider_reported['bedrock']` at its
|
|
321
|
+
* use site rather than the engine modelling every payload.
|
|
322
|
+
*
|
|
323
|
+
* Absent when the provider reported nothing, never an empty object. The loop
|
|
324
|
+
* copies it onto the step record and generate folds it into
|
|
325
|
+
* GenerateResult.provider_reported.
|
|
326
|
+
*/
|
|
327
|
+
readonly provider_reported?: Record<string, unknown>;
|
|
310
328
|
};
|
|
311
329
|
/**
|
|
312
330
|
* One turn's resolved request handed to a native adapter's invoke_turn.
|
|
@@ -420,6 +438,12 @@ type GenerateResult<t = string> = {
|
|
|
420
438
|
provider: string;
|
|
421
439
|
model_id: string;
|
|
422
440
|
};
|
|
441
|
+
/**
|
|
442
|
+
* Provider-keyed detail for the call, taken from the last step that reported
|
|
443
|
+
* any: provider payloads are opaque, so they cannot be summed the way usage
|
|
444
|
+
* and cost are. Mirrors `content` and `finish_reason` in reflecting the final
|
|
445
|
+
* turn; `steps[i].provider_reported` holds every turn's own payload.
|
|
446
|
+
*/
|
|
423
447
|
provider_reported?: Record<string, unknown>;
|
|
424
448
|
};
|
|
425
449
|
type ProviderInit = {
|
|
@@ -682,6 +706,22 @@ declare class provider_auth_error extends Error {
|
|
|
682
706
|
refresh_command?: string;
|
|
683
707
|
});
|
|
684
708
|
}
|
|
709
|
+
/**
|
|
710
|
+
* A generate call that set a schema finished for a reason other than 'stop'
|
|
711
|
+
* (content_filter, length, max_steps, tool_calls), so no schema-validated
|
|
712
|
+
* value exists and validation was never attempted. Carries the raw model text
|
|
713
|
+
* and the last provider-reported payload, so a guardrail trace or other
|
|
714
|
+
* block detail stays reachable from the catch. Distinct from
|
|
715
|
+
* schema_validation_error, which covers a response that completed normally
|
|
716
|
+
* and then failed validation after its repair attempts ran out.
|
|
717
|
+
*/
|
|
718
|
+
declare class incomplete_generation_error extends Error {
|
|
719
|
+
readonly kind: "incomplete_generation_error";
|
|
720
|
+
readonly finish_reason: FinishReason;
|
|
721
|
+
readonly raw_text: string;
|
|
722
|
+
readonly provider_reported: Record<string, unknown> | undefined;
|
|
723
|
+
constructor(finish_reason: FinishReason, raw_text: string, provider_reported?: Record<string, unknown>);
|
|
724
|
+
}
|
|
685
725
|
//#endregion
|
|
686
|
-
export {
|
|
687
|
-
//# sourceMappingURL=index-
|
|
726
|
+
export { ProviderCapability as $, Pricing as A, ToolApprovalHandler as B, FinishReason as C, PrepareStepContext as D, Message as E, RetryFailureKind as F, TurnResult as G, ToolCallRecord as H, RetryPolicy as I, AiSdkProviderAdapter as J, UsageTotals as K, StepRecord as L, ProviderConfigMap as M, ProviderInit as N, PrepareStepHook as O, ResolvedModel as P, ProviderAdapter as Q, StreamChunk as R, EngineDefaults as S, GenerateResult as T, ToolExecContext as U, ToolApprovalRequest as V, TurnRequest as W, ExternalAgentAdapter as X, EffortTranslation as Y, NativeProviderAdapter as Z, AssistantContentPart as _, model_required_error as a, Engine as b, provider_capability_error as c, rate_limit_error as d, ProviderFactory as et, schema_validation_error as f, AiSdkTelemetrySettings as g, create_engine as h, incomplete_generation_error as i, PricingTable as j, PrepareStepResult as k, provider_error as l, tool_error as m, engine_config_error as n, RawProviderUsage as nt, on_chunk_error as o, tool_approval_denied_error as p, UserContentPart as q, engine_disposed_error as r, default_normalize_usage as rt, provider_auth_error as s, claude_cli_error as t, ProviderTransport as tt, provider_not_configured_error as u, CostBreakdown as v, GenerateOptions as w, EngineConfig as x, EffortLevel as y, Tool as z };
|
|
727
|
+
//# sourceMappingURL=index-BNgtkeUf.d.ts.map
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as fallback, B as describe, C as checkpoint, D as LoopResult, E as LoopGuardResult, F as parallel, G as Step, H as run, I as sequence, J as TrajectoryLogger, K as StepMetadata, L as DescribeOptions, M as pipe, N as map, O as loop, P as branch, R as FlowNode, S as suspend, T as LoopConfig, U as CheckpointStore, V as step, W as RunContext, Y as __json_default_export, _ as suspended_error, a as SpanStartEvent, b as stash, c as span_end_event_schema, d as STEP_KINDS, f as StepKind, g as resume_validation_error, h as describe_cycle_error, i as SpanEndEvent, j as retry, k as timeout, l as span_start_event_schema, m as aborted_error, n as EmitEvent, o as custom_event_schema, p as is_step_kind, q as TrajectoryEvent, r as ParsedTrajectoryEvent, s as emit_event_schema, t as CustomTrajectoryEvent, u as trajectory_event_schema, v as timeout_error, w as compose, x as use, y as scope, z as FlowValue } from "./index-SkPG_Rew.js";
|
|
2
|
-
import { $ as
|
|
2
|
+
import { $ as ProviderCapability, A as Pricing, B as ToolApprovalHandler, C as FinishReason, D as PrepareStepContext, E as Message, F as RetryFailureKind, G as TurnResult, H as ToolCallRecord, I as RetryPolicy, J as AiSdkProviderAdapter, K as UsageTotals, L as StepRecord, M as ProviderConfigMap, N as ProviderInit, O as PrepareStepHook, P as ResolvedModel, Q as ProviderAdapter, R as StreamChunk, S as EngineDefaults, T as GenerateResult, U as ToolExecContext, V as ToolApprovalRequest, W as TurnRequest, X as ExternalAgentAdapter, Y as EffortTranslation, Z as NativeProviderAdapter, _ as AssistantContentPart, a as model_required_error, b as Engine, c as provider_capability_error, d as rate_limit_error, et as ProviderFactory, f as schema_validation_error, g as AiSdkTelemetrySettings, h as create_engine, i as incomplete_generation_error, j as PricingTable, k as PrepareStepResult, l as provider_error, m as tool_error, n as engine_config_error, nt as RawProviderUsage, o as on_chunk_error, p as tool_approval_denied_error, q as UserContentPart, r as engine_disposed_error, rt as default_normalize_usage, s as provider_auth_error, t as claude_cli_error, tt as ProviderTransport, u as provider_not_configured_error, v as CostBreakdown, w as GenerateOptions, x as EngineConfig, y as EffortLevel, z as Tool } from "./index-BNgtkeUf.js";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
5
|
//#region src/composites/adversarial.d.ts
|
|
@@ -532,5 +532,5 @@ declare function start_viewer(options?: StartViewerOptions): Promise<ViewerHandl
|
|
|
532
532
|
*/
|
|
533
533
|
declare function run_viewer_cli(argv: readonly string[]): Promise<void>;
|
|
534
534
|
//#endregion
|
|
535
|
-
export { type AdversarialBuildInput, type AdversarialConfig, type AdversarialCritiqueResult, type AdversarialResult, type AiSdkProviderAdapter, type AiSdkTelemetrySettings, type AssistantContentPart, type BenchCase, type BenchOptions, type BenchReport, type BenchSummary, type BracketRecord, type Candidate, type CaseResult, type CheckpointStore, type ConsensusConfig, type ConsensusResult, type CostBreakdown, type CustomTrajectoryEvent, type DescribeOptions, type EffortLevel, type EffortTranslation, type EmitEvent, type Engine, type EngineConfig, type EngineDefaults, type EnsembleConfig, type EnsembleResult, type EnsembleStepConfig, type EnsembleStepResult, type ExternalAgentAdapter, type FinishReason, type FlowNode, type FlowValue, type GenerateOptions, type GenerateResult, type HistoryEntry, type ImproveBudget, type ImproveConfig, type ImproveResult, type ImproveRoundInput, type Improvement, type Judge, type JudgeArgs, type JudgeLlmConfig, type JudgeWithFn, type LearnConfig, type LearnInput, type LearnResult, type Lesson, type LoopConfig, type LoopGuardResult, type LoopResult, type Message, type ModelCallConfig, type ModelCallInput, type NativeProviderAdapter, type ParsedTrajectoryEvent, type PerCaseDelta, type PrepareStepContext, type PrepareStepHook, type PrepareStepResult, type Pricing, type PricingTable, type ProviderAdapter, type ProviderCapability, type ProviderConfigMap, type ProviderFactory, type ProviderInit, type ProviderTransport, type RawProviderUsage, type RegressionCompareOptions, type RegressionDelta, type RegressionReport, type ResolvedModel, type RetryFailureKind, type RetryPolicy, type RunContext, STEP_KINDS, type Score, type ScoredCandidate, type SpanEndEvent, type SpanStartEvent, type StartViewerOptions, type Step, type StepKind, type StepMetadata, type StepRecord, type StreamChunk, type Tool, type ToolApprovalHandler, type ToolApprovalRequest, type ToolCallRecord, type ToolExecContext, type TournamentConfig, type TournamentResult, type TrajectoryEvent, type TrajectoryLogger, type TrajectorySource, type TurnRequest, type TurnResult, type UsageTotals, type UserContentPart, type ViewerHandle, aborted_error, adversarial, bench, branch, checkpoint, claude_cli_error, compose, consensus, create_engine, custom_event_schema, default_normalize_usage, describe, describe_cycle_error, emit_event_schema, engine_config_error, engine_disposed_error, ensemble, ensemble_step, fallback, __json_default_export as flow_schema, forward_standard_env, improve, is_step_kind, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, normalize_score, on_chunk_error, parallel, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, rate_limit_error, read_baseline, regression_compare, resume_validation_error, retry, run, run_viewer_cli, schema_validation_error, scope, sequence, span_end_event_schema, span_start_event_schema, start_viewer, stash, step, suspend, suspended_error, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, trajectory_event_schema, use, write_baseline };
|
|
535
|
+
export { type AdversarialBuildInput, type AdversarialConfig, type AdversarialCritiqueResult, type AdversarialResult, type AiSdkProviderAdapter, type AiSdkTelemetrySettings, type AssistantContentPart, type BenchCase, type BenchOptions, type BenchReport, type BenchSummary, type BracketRecord, type Candidate, type CaseResult, type CheckpointStore, type ConsensusConfig, type ConsensusResult, type CostBreakdown, type CustomTrajectoryEvent, type DescribeOptions, type EffortLevel, type EffortTranslation, type EmitEvent, type Engine, type EngineConfig, type EngineDefaults, type EnsembleConfig, type EnsembleResult, type EnsembleStepConfig, type EnsembleStepResult, type ExternalAgentAdapter, type FinishReason, type FlowNode, type FlowValue, type GenerateOptions, type GenerateResult, type HistoryEntry, type ImproveBudget, type ImproveConfig, type ImproveResult, type ImproveRoundInput, type Improvement, type Judge, type JudgeArgs, type JudgeLlmConfig, type JudgeWithFn, type LearnConfig, type LearnInput, type LearnResult, type Lesson, type LoopConfig, type LoopGuardResult, type LoopResult, type Message, type ModelCallConfig, type ModelCallInput, type NativeProviderAdapter, type ParsedTrajectoryEvent, type PerCaseDelta, type PrepareStepContext, type PrepareStepHook, type PrepareStepResult, type Pricing, type PricingTable, type ProviderAdapter, type ProviderCapability, type ProviderConfigMap, type ProviderFactory, type ProviderInit, type ProviderTransport, type RawProviderUsage, type RegressionCompareOptions, type RegressionDelta, type RegressionReport, type ResolvedModel, type RetryFailureKind, type RetryPolicy, type RunContext, STEP_KINDS, type Score, type ScoredCandidate, type SpanEndEvent, type SpanStartEvent, type StartViewerOptions, type Step, type StepKind, type StepMetadata, type StepRecord, type StreamChunk, type Tool, type ToolApprovalHandler, type ToolApprovalRequest, type ToolCallRecord, type ToolExecContext, type TournamentConfig, type TournamentResult, type TrajectoryEvent, type TrajectoryLogger, type TrajectorySource, type TurnRequest, type TurnResult, type UsageTotals, type UserContentPart, type ViewerHandle, aborted_error, adversarial, bench, branch, checkpoint, claude_cli_error, compose, consensus, create_engine, custom_event_schema, default_normalize_usage, describe, describe_cycle_error, emit_event_schema, engine_config_error, engine_disposed_error, ensemble, ensemble_step, fallback, __json_default_export as flow_schema, forward_standard_env, improve, incomplete_generation_error, is_step_kind, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, normalize_score, on_chunk_error, parallel, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, rate_limit_error, read_baseline, regression_compare, resume_validation_error, retry, run, run_viewer_cli, schema_validation_error, scope, sequence, span_end_event_schema, span_start_event_schema, start_viewer, stash, step, suspend, suspended_error, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, trajectory_event_schema, use, write_baseline };
|
|
536
536
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1560,6 +1560,28 @@ var provider_auth_error = class extends Error {
|
|
|
1560
1560
|
this.refresh_command = metadata.refresh_command;
|
|
1561
1561
|
}
|
|
1562
1562
|
};
|
|
1563
|
+
/**
|
|
1564
|
+
* A generate call that set a schema finished for a reason other than 'stop'
|
|
1565
|
+
* (content_filter, length, max_steps, tool_calls), so no schema-validated
|
|
1566
|
+
* value exists and validation was never attempted. Carries the raw model text
|
|
1567
|
+
* and the last provider-reported payload, so a guardrail trace or other
|
|
1568
|
+
* block detail stays reachable from the catch. Distinct from
|
|
1569
|
+
* schema_validation_error, which covers a response that completed normally
|
|
1570
|
+
* and then failed validation after its repair attempts ran out.
|
|
1571
|
+
*/
|
|
1572
|
+
var incomplete_generation_error = class extends Error {
|
|
1573
|
+
kind = "incomplete_generation_error";
|
|
1574
|
+
finish_reason;
|
|
1575
|
+
raw_text;
|
|
1576
|
+
provider_reported;
|
|
1577
|
+
constructor(finish_reason, raw_text, provider_reported) {
|
|
1578
|
+
super(`generation finished with '${finish_reason}' before a schema-validated response was produced`);
|
|
1579
|
+
this.name = "incomplete_generation_error";
|
|
1580
|
+
this.finish_reason = finish_reason;
|
|
1581
|
+
this.raw_text = raw_text;
|
|
1582
|
+
this.provider_reported = provider_reported;
|
|
1583
|
+
}
|
|
1584
|
+
};
|
|
1563
1585
|
//#endregion
|
|
1564
1586
|
//#region src/engine/retry.ts
|
|
1565
1587
|
const DEFAULT_RETRY = {
|
|
@@ -6787,6 +6809,7 @@ async function run_tool_loop(config) {
|
|
|
6787
6809
|
};
|
|
6788
6810
|
const breakdown = compute_and_record_cost(config, step_index, turn.usage);
|
|
6789
6811
|
if (breakdown !== void 0) record_step.cost = breakdown;
|
|
6812
|
+
if (turn.provider_reported !== void 0) record_step.provider_reported = turn.provider_reported;
|
|
6790
6813
|
steps.push(record_step);
|
|
6791
6814
|
if (config.on_finish_step !== void 0) config.on_finish_step(record_step);
|
|
6792
6815
|
end_step_span(config.trajectory, step_span, {
|
|
@@ -7042,6 +7065,7 @@ async function run_tool_loop(config) {
|
|
|
7042
7065
|
};
|
|
7043
7066
|
const breakdown = compute_and_record_cost(config, step_index, turn.usage);
|
|
7044
7067
|
if (breakdown !== void 0) step_record.cost = breakdown;
|
|
7068
|
+
if (turn.provider_reported !== void 0) step_record.provider_reported = turn.provider_reported;
|
|
7045
7069
|
steps.push(step_record);
|
|
7046
7070
|
if (config.on_finish_step !== void 0) config.on_finish_step(step_record);
|
|
7047
7071
|
end_step_span(config.trajectory, step_span, {
|
|
@@ -7154,6 +7178,26 @@ function to_raw_provider_usage(usage) {
|
|
|
7154
7178
|
return raw;
|
|
7155
7179
|
}
|
|
7156
7180
|
/**
|
|
7181
|
+
* Normalize an AI SDK `providerMetadata` value into the neutral
|
|
7182
|
+
* TurnResult.provider_reported shape.
|
|
7183
|
+
*
|
|
7184
|
+
* The SDK's metadata is already keyed by provider name, which is the shape
|
|
7185
|
+
* provider_reported documents, so the keys ride through untranslated and every
|
|
7186
|
+
* ai_sdk provider is served by this one seam: bedrock's guardrail `trace`,
|
|
7187
|
+
* anthropic's cache detail, openai's own fields. The payloads stay opaque
|
|
7188
|
+
* (callers narrow them at the use site), so this copies the top level and
|
|
7189
|
+
* inspects nothing below it. An absent or empty map returns undefined, keeping
|
|
7190
|
+
* "the provider reported nothing" spelled one way.
|
|
7191
|
+
*/
|
|
7192
|
+
function to_provider_reported(metadata) {
|
|
7193
|
+
if (metadata === null || typeof metadata !== "object") return void 0;
|
|
7194
|
+
const keys = Object.keys(metadata);
|
|
7195
|
+
if (keys.length === 0) return void 0;
|
|
7196
|
+
const reported = {};
|
|
7197
|
+
for (const key of keys) reported[key] = Reflect.get(metadata, key);
|
|
7198
|
+
return reported;
|
|
7199
|
+
}
|
|
7200
|
+
/**
|
|
7157
7201
|
* Map fascicle's Message[] to the AI SDK's ModelMessage[] shape.
|
|
7158
7202
|
*/
|
|
7159
7203
|
function to_sdk_messages(messages) {
|
|
@@ -7341,6 +7385,7 @@ async function collect_stream(params, step_index, dispatcher, on_first_chunk, in
|
|
|
7341
7385
|
const tool_calls = [];
|
|
7342
7386
|
let finish_reason = "stop";
|
|
7343
7387
|
let raw_usage = {};
|
|
7388
|
+
let provider_reported;
|
|
7344
7389
|
let first = true;
|
|
7345
7390
|
for await (const part of stream_result.stream) {
|
|
7346
7391
|
if (first) {
|
|
@@ -7356,6 +7401,7 @@ async function collect_stream(params, step_index, dispatcher, on_first_chunk, in
|
|
|
7356
7401
|
if (part.type === "finish-step") {
|
|
7357
7402
|
finish_reason = map_finish_reason(part.finishReason);
|
|
7358
7403
|
raw_usage = to_raw_provider_usage(part.usage);
|
|
7404
|
+
provider_reported = to_provider_reported(part.providerMetadata);
|
|
7359
7405
|
}
|
|
7360
7406
|
if (part.type === "error") throw part.error;
|
|
7361
7407
|
if (part.type === "abort") throw new aborted_error("aborted", { step_index });
|
|
@@ -7372,7 +7418,8 @@ async function collect_stream(params, step_index, dispatcher, on_first_chunk, in
|
|
|
7372
7418
|
text,
|
|
7373
7419
|
tool_calls,
|
|
7374
7420
|
finish_reason,
|
|
7375
|
-
usage: adapter.normalize_usage(raw_usage)
|
|
7421
|
+
usage: adapter.normalize_usage(raw_usage),
|
|
7422
|
+
...provider_reported !== void 0 ? { provider_reported } : {}
|
|
7376
7423
|
};
|
|
7377
7424
|
}
|
|
7378
7425
|
/**
|
|
@@ -7396,11 +7443,13 @@ async function collect_non_stream(params, adapter) {
|
|
|
7396
7443
|
input: tc.input
|
|
7397
7444
|
});
|
|
7398
7445
|
const raw_usage = to_raw_provider_usage(result.usage);
|
|
7446
|
+
const provider_reported = to_provider_reported(result.providerMetadata);
|
|
7399
7447
|
return {
|
|
7400
7448
|
text: result.text,
|
|
7401
7449
|
tool_calls,
|
|
7402
7450
|
finish_reason: map_finish_reason(result.finishReason),
|
|
7403
|
-
usage: adapter.normalize_usage(raw_usage)
|
|
7451
|
+
usage: adapter.normalize_usage(raw_usage),
|
|
7452
|
+
...provider_reported !== void 0 ? { provider_reported } : {}
|
|
7404
7453
|
};
|
|
7405
7454
|
}
|
|
7406
7455
|
/**
|
|
@@ -7413,6 +7462,10 @@ async function collect_non_stream(params, adapter) {
|
|
|
7413
7462
|
* turn result, so `parse_with_schema` re-validates it and the repair loop
|
|
7414
7463
|
* engages exactly as it does for the prompt-based path. Returns undefined for
|
|
7415
7464
|
* any other error so the caller rethrows.
|
|
7465
|
+
*
|
|
7466
|
+
* The recovered turn carries no provider_reported: the SDK's error exposes
|
|
7467
|
+
* text, usage, finishReason and response metadata, but not providerMetadata,
|
|
7468
|
+
* so there is nothing to read. The repair turn that follows reports normally.
|
|
7416
7469
|
*/
|
|
7417
7470
|
function recover_no_object_generated(err, adapter) {
|
|
7418
7471
|
if (!NoObjectGeneratedError.isInstance(err)) return void 0;
|
|
@@ -7744,7 +7797,12 @@ function build_native_invoke(cfg) {
|
|
|
7744
7797
|
* resolved transport, and drives it through `run_tool_loop`. When a schema
|
|
7745
7798
|
* is set and the model's output fails validation, it appends a repair
|
|
7746
7799
|
* message and re-invokes the loop, until the response parses, repair
|
|
7747
|
-
* attempts run out, or `max_steps` is reached.
|
|
7800
|
+
* attempts run out, or `max_steps` is reached. When a schema is set and the
|
|
7801
|
+
* loop finishes for any reason other than `'stop'` (a content filter, the
|
|
7802
|
+
* token limit, the step cap), no validated value can exist, so it throws
|
|
7803
|
+
* `incomplete_generation_error` carrying the finish reason, the raw text,
|
|
7804
|
+
* and the last `provider_reported` payload rather than returning unchecked
|
|
7805
|
+
* text. Without a schema those finish reasons return normally.
|
|
7748
7806
|
*/
|
|
7749
7807
|
async function generate(opts_in, engine) {
|
|
7750
7808
|
if (opts_in.abort?.aborted === true) throw new aborted_error("aborted", { reason: opts_in.abort.reason });
|
|
@@ -7859,7 +7917,6 @@ async function generate(opts_in, engine) {
|
|
|
7859
7917
|
let finish_reason = "stop";
|
|
7860
7918
|
let repair_remaining = schema_repair_attempts;
|
|
7861
7919
|
let content_parsed;
|
|
7862
|
-
let schema_satisfied = opts.schema === void 0;
|
|
7863
7920
|
const salvage_budget = tool_call_repair_attempts > 0 ? { remaining: tool_call_repair_attempts } : void 0;
|
|
7864
7921
|
try {
|
|
7865
7922
|
while (true) {
|
|
@@ -7889,11 +7946,10 @@ async function generate(opts_in, engine) {
|
|
|
7889
7946
|
text = loop_result.text;
|
|
7890
7947
|
finish_reason = loop_result.finish_reason;
|
|
7891
7948
|
if (opts.schema === void 0) break;
|
|
7892
|
-
if (finish_reason !== "stop")
|
|
7949
|
+
if (finish_reason !== "stop") throw new incomplete_generation_error(finish_reason, text, last_provider_reported(steps_accum));
|
|
7893
7950
|
const parse = parse_with_schema(opts.schema, text);
|
|
7894
7951
|
if (parse.ok) {
|
|
7895
|
-
content_parsed = parse.value;
|
|
7896
|
-
schema_satisfied = true;
|
|
7952
|
+
content_parsed = { value: parse.value };
|
|
7897
7953
|
break;
|
|
7898
7954
|
}
|
|
7899
7955
|
record_schema_validation_failed(trajectory, {
|
|
@@ -7908,8 +7964,7 @@ async function generate(opts_in, engine) {
|
|
|
7908
7964
|
const aggregated_usage = sum_usage(steps_accum);
|
|
7909
7965
|
const aggregated_cost = aggregate_cost(steps_accum, target.provider);
|
|
7910
7966
|
let final_content;
|
|
7911
|
-
if (
|
|
7912
|
-
else if (schema_satisfied && content_parsed !== void 0) final_content = content_parsed;
|
|
7967
|
+
if (content_parsed !== void 0) final_content = content_parsed.value;
|
|
7913
7968
|
else final_content = text;
|
|
7914
7969
|
const result = {
|
|
7915
7970
|
content: final_content,
|
|
@@ -7923,6 +7978,8 @@ async function generate(opts_in, engine) {
|
|
|
7923
7978
|
}
|
|
7924
7979
|
};
|
|
7925
7980
|
if (aggregated_cost !== void 0) result.cost = aggregated_cost;
|
|
7981
|
+
const aggregated_reported = last_provider_reported(steps_accum);
|
|
7982
|
+
if (aggregated_reported !== void 0) result.provider_reported = aggregated_reported;
|
|
7926
7983
|
if (on_chunk_provided) await dispatcher.dispatch({
|
|
7927
7984
|
kind: "finish",
|
|
7928
7985
|
finish_reason,
|
|
@@ -7946,6 +8003,19 @@ function round6(v) {
|
|
|
7946
8003
|
return Math.round(v * 1e6) / 1e6;
|
|
7947
8004
|
}
|
|
7948
8005
|
/**
|
|
8006
|
+
* Pick the call-level `provider_reported` from the step records: the payload of
|
|
8007
|
+
* the last step that reported one.
|
|
8008
|
+
*
|
|
8009
|
+
* Provider payloads are opaque, so unlike usage and cost there is nothing to
|
|
8010
|
+
* sum and no safe way to merge two turns' keys (a provider reports the same keys
|
|
8011
|
+
* every turn, so merging would silently overwrite rather than combine). Taking
|
|
8012
|
+
* the final reporting turn matches how `content` and `finish_reason` are drawn
|
|
8013
|
+
* from the last turn; every turn's own payload stays on `steps[i]`.
|
|
8014
|
+
*/
|
|
8015
|
+
function last_provider_reported(steps) {
|
|
8016
|
+
return steps.findLast((s) => s.provider_reported !== void 0)?.provider_reported;
|
|
8017
|
+
}
|
|
8018
|
+
/**
|
|
7949
8019
|
* Sum per-step cost breakdowns into a single `CostBreakdown` for the whole
|
|
7950
8020
|
* generate call.
|
|
7951
8021
|
*
|
|
@@ -8928,6 +8998,6 @@ if (process.argv[1] !== void 0 && process.argv[1] === fileURLToPath(import.meta.
|
|
|
8928
8998
|
process.exit(1);
|
|
8929
8999
|
});
|
|
8930
9000
|
//#endregion
|
|
8931
|
-
export { STEP_KINDS, aborted_error, adversarial, bench, branch, checkpoint, claude_cli_error, compose, consensus, create_engine, custom_event_schema, default_normalize_usage, describe, describe_cycle_error, emit_event_schema, engine_config_error, engine_disposed_error, ensemble, ensemble_step, fallback, flow_schema_default as flow_schema, forward_standard_env, improve, is_step_kind, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, normalize_score, on_chunk_error, parallel, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, rate_limit_error, read_baseline, regression_compare, resume_validation_error, retry, run, run_viewer_cli, schema_validation_error, scope, sequence, span_end_event_schema, span_start_event_schema, start_viewer, stash, step, suspend, suspended_error, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, trajectory_event_schema, use, write_baseline };
|
|
9001
|
+
export { STEP_KINDS, aborted_error, adversarial, bench, branch, checkpoint, claude_cli_error, compose, consensus, create_engine, custom_event_schema, default_normalize_usage, describe, describe_cycle_error, emit_event_schema, engine_config_error, engine_disposed_error, ensemble, ensemble_step, fallback, flow_schema_default as flow_schema, forward_standard_env, improve, incomplete_generation_error, is_step_kind, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, normalize_score, on_chunk_error, parallel, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, rate_limit_error, read_baseline, regression_compare, resume_validation_error, retry, run, run_viewer_cli, schema_validation_error, scope, sequence, span_end_event_schema, span_start_event_schema, start_viewer, stash, step, suspend, suspended_error, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, trajectory_event_schema, use, write_baseline };
|
|
8932
9002
|
|
|
8933
9003
|
//# sourceMappingURL=index.js.map
|