fascicle 0.16.5 → 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 +57 -0
- package/README.md +3 -2
- package/dist/AGENTS.md +69 -18
- package/dist/acp.d.ts +1 -1
- package/dist/acp.js +7 -2
- package/dist/acp.js.map +1 -1
- package/dist/agents.d.ts +1 -1
- package/dist/{engine-B6rIIM4J.js → engine-Bde18P7H.js} +1163 -236
- package/dist/engine-Bde18P7H.js.map +1 -0
- package/dist/index.d.ts +114 -16
- package/dist/index.js +226 -16
- package/dist/index.js.map +1 -1
- package/dist/{invoke-LbzZLZFw.js → invoke-BbJLQcLl.js} +62 -106
- package/dist/invoke-BbJLQcLl.js.map +1 -0
- package/dist/{leading_system-WhW76tRn.js → leading_system-DmNxhvzL.js} +45 -16
- package/dist/leading_system-DmNxhvzL.js.map +1 -0
- package/dist/mcp.d.ts +2 -1
- package/dist/mcp.js +6 -3
- package/dist/mcp.js.map +1 -1
- package/dist/otel.js +48 -3
- package/dist/otel.js.map +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 +77 -2
- package/dist/testing.js +202 -19
- package/dist/testing.js.map +1 -1
- package/dist/{types-Sw0oHW-_.d.ts → types-C7pO0jLq.d.ts} +218 -21
- package/dist/viewer-app/assets/index-9eVv6Mar.css +1 -0
- package/dist/viewer-app/assets/index-BkS2ZQu0.js +4 -0
- package/dist/viewer-app/index.html +2 -2
- package/dist/viewer.d.ts +64 -10
- package/dist/viewer.js +265 -64
- package/dist/viewer.js.map +1 -1
- package/package.json +1 -1
- package/dist/engine-B6rIIM4J.js.map +0 -1
- package/dist/invoke-LbzZLZFw.js.map +0 -1
- package/dist/leading_system-WhW76tRn.js.map +0 -1
- package/dist/search-CpCJYMUm.js.map +0 -1
- package/dist/viewer-app/assets/index-Cev83tcH.css +0 -1
- package/dist/viewer-app/assets/index-D8UmFVfR.js +0 -2
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { a as FlowValue, c as Step, d as StepMetadata, f as StepOptions, h as TrajectoryLogger, i as FlowNode, l as StepFn, m as TrajectoryEvent, n as CheckpointStore, o as RunContext, p as StepOutput, r as CleanupFn, s as ScopedCheckpointStore, t as AnyStep, u as StepInput } from "./types-CPqLZOEr.js";
|
|
2
2
|
import { n as SchemaIssue, r as ToolSchema, t as AnySchema } from "./types-BK0UW28o.js";
|
|
3
3
|
import { _ as is_run_end_event, a as MapItemFailedEvent, b as is_step_replayed_event, c as RunEndStatus, d as StepReplayedEvent, f as TrajectoryParseResult, g as is_map_item_failed_event, h as is_emit_event, i as EmitEvent, l as SpanEndEvent, m as is_custom_trajectory_event, n as CheckpointStatus, o as ParsedTrajectoryEvent, p as is_checkpoint_event, r as CustomTrajectoryEvent, s as RunEndEvent, t as CheckpointEvent, u as SpanStartEvent, v as is_span_end_event, x as parse_trajectory_event, y as is_span_start_event } from "./trajectory-BKGNxi7u.js";
|
|
4
|
-
import { A as
|
|
4
|
+
import { A as StepTiming, B as UsageTotals, C as ProviderConfigMap, D as RetryFailureKind, E as ResolvedModel, F as ToolCallRecord, G as NativeProviderAdapter, H as AiSdkProviderAdapter, I as ToolExecContext, J as ProviderFactory, K as ProviderAdapter, L as TruncatedTurnPolicy, M as Tool, N as ToolApprovalHandler, O as RetryPolicy, P as ToolApprovalRequest, Q as ClaudeCliProviderReported, R as TurnRequest, S as PricingTable, T as ProviderOptions, U as EffortTranslation, V as UserContentPart, W as ExternalAgentAdapter, X as RawProviderUsage, Y as ProviderTransport, Z as default_normalize_usage, _ as Message, a as CacheSetting, b as PrepareStepResult, c as CostBreakdown, d as EngineConfig, f as EngineDefaults, g as GenerateTiming, h as GenerateResult, i as BedrockCredentials, j as StreamChunk, k as StepRecord, l as EffortLevel, m as GenerateOptions, n as AssistantContentPart, o as CaptureLevel, p as FinishReason, q as ProviderCapability, r as BedrockCredentialProvider, s as CapturePayload, t as AiSdkTelemetrySettings, u as Engine, v as PrepareStepContext, w as ProviderInit, x as Pricing, y as PrepareStepHook, z as TurnResult } from "./types-C7pO0jLq.js";
|
|
5
5
|
//#region src/core/runner.d.ts
|
|
6
6
|
type RunOptions = {
|
|
7
7
|
readonly install_signal_handlers?: boolean;
|
|
@@ -1682,9 +1682,10 @@ type Throughput = {
|
|
|
1682
1682
|
/** Output tokens per second over the measured window. Not rounded. */
|
|
1683
1683
|
tokens_per_second: number;
|
|
1684
1684
|
/**
|
|
1685
|
-
* 'decode' when every contributing
|
|
1686
|
-
*
|
|
1687
|
-
*
|
|
1685
|
+
* 'decode' when every contributing window is time the model spent emitting
|
|
1686
|
+
* output, either a decode time the provider reported or a streamed turn's
|
|
1687
|
+
* window after its first chunk; 'blended' when any window is a whole
|
|
1688
|
+
* round-trip (network + queueing + prefill included).
|
|
1688
1689
|
*/
|
|
1689
1690
|
basis: 'decode' | 'blended';
|
|
1690
1691
|
/** Output tokens summed across the contributing steps. */
|
|
@@ -1696,16 +1697,96 @@ type Throughput = {
|
|
|
1696
1697
|
* Compute output throughput from step timing: a whole GenerateResult, a step
|
|
1697
1698
|
* array, or a single step.
|
|
1698
1699
|
*
|
|
1699
|
-
*
|
|
1700
|
-
*
|
|
1701
|
-
*
|
|
1702
|
-
*
|
|
1703
|
-
*
|
|
1704
|
-
*
|
|
1705
|
-
*
|
|
1700
|
+
* Tool-execution time between turns never contributes, since StepTiming
|
|
1701
|
+
* brackets the provider round-trip alone. Each step's window is the decode
|
|
1702
|
+
* time its provider reported when it has one (Ollama's `eval_duration`),
|
|
1703
|
+
* else `duration_ms - first_chunk_ms` when the turn streamed, unless its
|
|
1704
|
+
* first chunk was a tool call that arrived whole, else the full
|
|
1705
|
+
* `duration_ms`, with `basis` reporting 'decode' only when no blended window
|
|
1706
|
+
* contributed. Returns undefined when nothing is measurable: no step has
|
|
1707
|
+
* timing or a reported decode time (an external adapter, a test seam), or the
|
|
1708
|
+
* summed window is 0 ms (a sub-millisecond stub turn), where a rate would
|
|
1709
|
+
* divide by zero.
|
|
1706
1710
|
*/
|
|
1707
1711
|
export declare function throughput(source: GenerateResult<unknown> | StepRecord | ReadonlyArray<StepRecord>): Throughput | undefined;
|
|
1708
1712
|
//#endregion
|
|
1713
|
+
//#region src/engine/replay.d.ts
|
|
1714
|
+
/**
|
|
1715
|
+
* A captured call's settings: the provider and model, the resolved effort and
|
|
1716
|
+
* cache, the sampling knobs it set, its provider options as the engine
|
|
1717
|
+
* defaults and the call merged them, before an adapter's translation, and its
|
|
1718
|
+
* schema as JSON Schema.
|
|
1719
|
+
*/
|
|
1720
|
+
type CapturedSettings = {
|
|
1721
|
+
readonly provider: string;
|
|
1722
|
+
readonly model_id: string;
|
|
1723
|
+
readonly effort: EffortLevel;
|
|
1724
|
+
readonly cache?: Exclude<CacheSetting, 'off'>;
|
|
1725
|
+
readonly temperature?: number;
|
|
1726
|
+
readonly max_tokens?: number;
|
|
1727
|
+
readonly top_p?: number;
|
|
1728
|
+
readonly provider_options?: Readonly<Record<string, unknown>>;
|
|
1729
|
+
readonly schema?: Readonly<Record<string, unknown>>;
|
|
1730
|
+
};
|
|
1731
|
+
/**
|
|
1732
|
+
* A captured tool: its name, its description, and its input schema as JSON
|
|
1733
|
+
* Schema (draft 2020-12), absent when the schema couldn't be written as one.
|
|
1734
|
+
*/
|
|
1735
|
+
type CapturedTool = {
|
|
1736
|
+
readonly name: string;
|
|
1737
|
+
readonly description: string;
|
|
1738
|
+
readonly input_schema?: Readonly<Record<string, unknown>>;
|
|
1739
|
+
};
|
|
1740
|
+
/**
|
|
1741
|
+
* One turn as it was sent: the call it belongs to, its step, the call's
|
|
1742
|
+
* settings and tools, the whole message array, system prompts included, and
|
|
1743
|
+
* the parts the provider returned when the trajectory holds them.
|
|
1744
|
+
*/
|
|
1745
|
+
type CapturedTurn = {
|
|
1746
|
+
readonly call_span_id: string;
|
|
1747
|
+
readonly step_index: number;
|
|
1748
|
+
readonly settings: CapturedSettings;
|
|
1749
|
+
readonly tools: ReadonlyArray<CapturedTool>;
|
|
1750
|
+
readonly messages: ReadonlyArray<Message>;
|
|
1751
|
+
readonly response?: ReadonlyArray<AssistantContentPart>;
|
|
1752
|
+
};
|
|
1753
|
+
/**
|
|
1754
|
+
* Rebuild every captured turn in a trajectory's events, in any order the
|
|
1755
|
+
* events arrive. Each call's turns are folded by `call_span_id` and ordered
|
|
1756
|
+
* by `step_index`, a delta is applied only on top of the turn at the step
|
|
1757
|
+
* just before it, and a turn's `response` is the `response_received.content`
|
|
1758
|
+
* that shares its step span. A turn whose request is missing or unreadable
|
|
1759
|
+
* (absent, `null`, or a string a redactor returned) is left out, and the call
|
|
1760
|
+
* picks up again at its next whole array. A call whose first turn is missing,
|
|
1761
|
+
* as in a truncated log, is left out whole. Calls come out in the order each
|
|
1762
|
+
* first appears in the events.
|
|
1763
|
+
*/
|
|
1764
|
+
export declare function captured_turns(events: Iterable<TrajectoryEvent>): CapturedTurn[];
|
|
1765
|
+
/**
|
|
1766
|
+
* Send one captured turn again, as one turn that can't act: the turn's
|
|
1767
|
+
* messages, settings, and tools through `engine.generate` with
|
|
1768
|
+
* `max_steps: 1`, `cache: 'off'`, `capture: 'off'`, and `system: ''`, so the
|
|
1769
|
+
* engine's default system prompt doesn't add a second one. The captured
|
|
1770
|
+
* schema stays behind, so the reply comes back raw. Each tool is rebuilt
|
|
1771
|
+
* with an `execute` that throws, and a model that calls one comes back with
|
|
1772
|
+
* the call listed and unexecuted (`finish_reason: 'max_steps'`). The
|
|
1773
|
+
* captured `provider_options` go as they were, a raw `cache_control`
|
|
1774
|
+
* included, and the replaying engine's defaults fill whatever the turn left
|
|
1775
|
+
* unset. `edit` changes the turn before it goes, and `provider` and `model`
|
|
1776
|
+
* send it elsewhere. A replay is inert only on the `ai_sdk` and native
|
|
1777
|
+
* transports, since an external provider runs its own loop and tools.
|
|
1778
|
+
*/
|
|
1779
|
+
export declare function replay_turn(engine: Engine, turn: CapturedTurn, options?: {
|
|
1780
|
+
/** Change the turn before it goes (drop a raw `cache_control`, reword a message). */
|
|
1781
|
+
readonly edit?: (turn: CapturedTurn) => CapturedTurn;
|
|
1782
|
+
/** Send it to this provider instead of the one it was captured on. */
|
|
1783
|
+
readonly provider?: string;
|
|
1784
|
+
/** Send it to this model instead of the one it was captured on. */
|
|
1785
|
+
readonly model?: string;
|
|
1786
|
+
/** Where the replay records its own events. */
|
|
1787
|
+
readonly trajectory?: TrajectoryLogger;
|
|
1788
|
+
}): Promise<GenerateResult>;
|
|
1789
|
+
//#endregion
|
|
1709
1790
|
//#region src/engine/providers/claude_cli/reported.d.ts
|
|
1710
1791
|
/**
|
|
1711
1792
|
* Read the claude CLI's reported run detail off anything carrying
|
|
@@ -1747,13 +1828,14 @@ export declare class provider_error extends Error {
|
|
|
1747
1828
|
}
|
|
1748
1829
|
/**
|
|
1749
1830
|
* Turn-timeout expiry. Thrown by the engine-owned retry_turn wrapper when a
|
|
1750
|
-
* single invoke_turn exceeds `turn_timeout_ms` before any chunk
|
|
1831
|
+
* single invoke_turn exceeds `turn_timeout_ms` before any chunk reached a
|
|
1832
|
+
* consumer.
|
|
1751
1833
|
* Its `kind` is the RetryFailureKind wire value `'timeout'` (not the class
|
|
1752
1834
|
* name) on purpose: that is the discriminant classify_retryable /
|
|
1753
1835
|
* classify_provider_error already key on, so the shared classifier treats an
|
|
1754
|
-
* expiry as retryable without any timeout-specific branch.
|
|
1755
|
-
*
|
|
1756
|
-
* stream interruption first.
|
|
1836
|
+
* expiry as retryable without any timeout-specific branch. An expiry after a
|
|
1837
|
+
* chunk has reached an on_chunk consumer never reaches here; retry_turn
|
|
1838
|
+
* converts it to a non-retryable stream interruption first.
|
|
1757
1839
|
*/
|
|
1758
1840
|
export declare class turn_timeout_error extends Error {
|
|
1759
1841
|
readonly kind: 'timeout';
|
|
@@ -2413,6 +2495,16 @@ type ModelCallConfig<T = string, projected = GenerateResult<T>> = {
|
|
|
2413
2495
|
readonly tools?: ReadonlyArray<Tool>;
|
|
2414
2496
|
readonly schema?: ToolSchema<T>;
|
|
2415
2497
|
readonly effort?: EffortLevel;
|
|
2498
|
+
/**
|
|
2499
|
+
* Prompt caching for the call, forwarded to the engine. See
|
|
2500
|
+
* `GenerateOptions.cache`.
|
|
2501
|
+
*/
|
|
2502
|
+
readonly cache?: CacheSetting;
|
|
2503
|
+
/**
|
|
2504
|
+
* What the call records of each turn's request and reply, forwarded to the
|
|
2505
|
+
* engine. See `GenerateOptions.capture`.
|
|
2506
|
+
*/
|
|
2507
|
+
readonly capture?: CaptureLevel;
|
|
2416
2508
|
readonly temperature?: number;
|
|
2417
2509
|
readonly max_tokens?: number;
|
|
2418
2510
|
readonly top_p?: number;
|
|
@@ -2433,6 +2525,12 @@ type ModelCallConfig<T = string, projected = GenerateResult<T>> = {
|
|
|
2433
2525
|
readonly schema_repair_attempts?: number;
|
|
2434
2526
|
readonly tool_call_repair_attempts?: number;
|
|
2435
2527
|
readonly max_tool_calls_per_step?: number;
|
|
2528
|
+
/**
|
|
2529
|
+
* What the loop does with a turn that reached its output limit before it
|
|
2530
|
+
* made a tool call, forwarded to the engine. See
|
|
2531
|
+
* `GenerateOptions.truncated_turn_policy`.
|
|
2532
|
+
*/
|
|
2533
|
+
readonly truncated_turn_policy?: TruncatedTurnPolicy;
|
|
2436
2534
|
readonly on_tool_approval?: ToolApprovalHandler;
|
|
2437
2535
|
/**
|
|
2438
2536
|
* Observe every chunk of the call as it streams, for a live renderer that
|
|
@@ -2495,5 +2593,5 @@ export declare function model_step<T = string>(cfg: Omit<ModelCallConfig<T>, 'pr
|
|
|
2495
2593
|
*/
|
|
2496
2594
|
export declare function forward_standard_env(): Record<string, string>;
|
|
2497
2595
|
//#endregion
|
|
2498
|
-
export { type AdversarialBuildInput, type AdversarialConfig, type AdversarialCritiqueResult, type AdversarialResult, type AiSdkProviderAdapter, type AiSdkTelemetrySettings, type AnySchema, type AnyStep, type AssistantContentPart, type BedrockCredentialProvider, type BedrockCredentials, type BenchCase, type BenchOptions, type BenchReport, type BenchSummary, type BracketRecord, type BranchConfig, type Candidate, type CaseResult, type Chain, type ChainOpen, type ChainStepOptions, type CheckpointConfig, type CheckpointEvent, type CheckpointStatus, type CheckpointStore, type ClaudeCliErrorReason, type ClaudeCliProviderReported, type CleanupFn, type ComposeConfig, type ConsensusConfig, type ConsensusResult, type CostBreakdown, type CustomTrajectoryEvent, type DescribeOptions, type DiagramOptions, type DurableConfig, type DurableOutcome, type DurableRunOptions, type DurableRunState, type DurableRuns, type DurableStore, type EffortLevel, type EffortTranslation, type EmitEvent, type Engine, type EngineConfig, type EngineDefaults, type EnsembleConfig, type EnsembleResult, type EnsembleStepConfig, type EnsembleStepResult, type ExternalAgentAdapter, type FallbackOptions, type FallbackOutcome, type FallbackProjection, type FinishReason, type FlowNode, type FlowValue, type GateConfig, type GenerateOptions, type GenerateResult, type GenerateTiming, 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 LoopGuardPredicate, type LoopGuardResult, type LoopOutcome, type MapConfig, type MapItemFailedEvent, type MapSettleConfig, type Message, type ModelCallConfig, type ModelCallInput, type NativeProviderAdapter, type ParallelOptions, type ParsedTrajectoryEvent, type PerCaseDelta, type PipeOptions, type PrepareStepContext, type PrepareStepHook, type PrepareStepResult, type Pricing, type PricingTable, type ProviderAdapter, type ProviderCapability, type ProviderConfigMap, type ProviderFactory, type ProviderInit, type ProviderOptions, type ProviderTransport, type RawProviderUsage, type RegressionCompareOptions, type RegressionDelta, type RegressionReport, type ReplayHint, type ResolvedModel, type RetryConfig, type RetryFailureKind, type RetryOutcome, type RetryPolicy, type RetryProjection, type RunContext, type RunEndEvent, type RunEndStatus, type RunOptions, type RunOutcome, type SchemaIssue, type ScopeOptions, type ScopedCheckpointStore, type Score, type ScoredCandidate, type SequenceOptions, type Settled, type SettledError, type SpanEndEvent, type SpanStartEvent, type StashOptions, type Step, type StepFn, type StepInput, type StepKind, type StepMetadata, type StepOptions, type StepOutput, type StepRecord, type StepReplayedEvent, type StepTiming, type StreamChunk, type StreamingRunHandle, type SuspendConfig, type Throughput, type TimeoutOptions, type Tool, type ToolApprovalHandler, type ToolApprovalRequest, type ToolCallRecord, type ToolExecContext, type ToolSchema, type TournamentConfig, type TournamentResult, type TrajectoryEvent, type TrajectoryLogger, type TrajectoryParseResult, type TrajectorySource, type TurnRequest, type TurnResult, type UsageTotals, type UseOptions, type UserContentPart, default_normalize_usage, is_checkpoint_event, is_custom_trajectory_event, is_emit_event, is_map_item_failed_event, is_run_end_event, is_span_end_event, is_span_start_event, is_step_replayed_event, parse_trajectory_event };
|
|
2596
|
+
export { type AdversarialBuildInput, type AdversarialConfig, type AdversarialCritiqueResult, type AdversarialResult, type AiSdkProviderAdapter, type AiSdkTelemetrySettings, type AnySchema, type AnyStep, type AssistantContentPart, type BedrockCredentialProvider, type BedrockCredentials, type BenchCase, type BenchOptions, type BenchReport, type BenchSummary, type BracketRecord, type BranchConfig, type CacheSetting, type Candidate, type CaptureLevel, type CapturePayload, type CapturedSettings, type CapturedTool, type CapturedTurn, type CaseResult, type Chain, type ChainOpen, type ChainStepOptions, type CheckpointConfig, type CheckpointEvent, type CheckpointStatus, type CheckpointStore, type ClaudeCliErrorReason, type ClaudeCliProviderReported, type CleanupFn, type ComposeConfig, type ConsensusConfig, type ConsensusResult, type CostBreakdown, type CustomTrajectoryEvent, type DescribeOptions, type DiagramOptions, type DurableConfig, type DurableOutcome, type DurableRunOptions, type DurableRunState, type DurableRuns, type DurableStore, type EffortLevel, type EffortTranslation, type EmitEvent, type Engine, type EngineConfig, type EngineDefaults, type EnsembleConfig, type EnsembleResult, type EnsembleStepConfig, type EnsembleStepResult, type ExternalAgentAdapter, type FallbackOptions, type FallbackOutcome, type FallbackProjection, type FinishReason, type FlowNode, type FlowValue, type GateConfig, type GenerateOptions, type GenerateResult, type GenerateTiming, 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 LoopGuardPredicate, type LoopGuardResult, type LoopOutcome, type MapConfig, type MapItemFailedEvent, type MapSettleConfig, type Message, type ModelCallConfig, type ModelCallInput, type NativeProviderAdapter, type ParallelOptions, type ParsedTrajectoryEvent, type PerCaseDelta, type PipeOptions, type PrepareStepContext, type PrepareStepHook, type PrepareStepResult, type Pricing, type PricingTable, type ProviderAdapter, type ProviderCapability, type ProviderConfigMap, type ProviderFactory, type ProviderInit, type ProviderOptions, type ProviderTransport, type RawProviderUsage, type RegressionCompareOptions, type RegressionDelta, type RegressionReport, type ReplayHint, type ResolvedModel, type RetryConfig, type RetryFailureKind, type RetryOutcome, type RetryPolicy, type RetryProjection, type RunContext, type RunEndEvent, type RunEndStatus, type RunOptions, type RunOutcome, type SchemaIssue, type ScopeOptions, type ScopedCheckpointStore, type Score, type ScoredCandidate, type SequenceOptions, type Settled, type SettledError, type SpanEndEvent, type SpanStartEvent, type StashOptions, type Step, type StepFn, type StepInput, type StepKind, type StepMetadata, type StepOptions, type StepOutput, type StepRecord, type StepReplayedEvent, type StepTiming, type StreamChunk, type StreamingRunHandle, type SuspendConfig, type Throughput, type TimeoutOptions, type Tool, type ToolApprovalHandler, type ToolApprovalRequest, type ToolCallRecord, type ToolExecContext, type ToolSchema, type TournamentConfig, type TournamentResult, type TrajectoryEvent, type TrajectoryLogger, type TrajectoryParseResult, type TrajectorySource, type TruncatedTurnPolicy, type TurnRequest, type TurnResult, type UsageTotals, type UseOptions, type UserContentPart, default_normalize_usage, is_checkpoint_event, is_custom_trajectory_event, is_emit_event, is_map_item_failed_event, is_run_end_event, is_span_end_event, is_span_start_event, is_step_replayed_event, parse_trajectory_event };
|
|
2499
2597
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { A as describe_cycle_error, C as durable, D as describe, E as run, F as suspended_error, I as timeout_error, L as STEP_KINDS, M as flow_changed_error, N as resume_validation_error, O as is_step, P as run_not_found_error, R as is_step_kind, S as suggest_step_id, _ as parallel, a as suspend, b as assert_valid_step_id, c as loop, d as retry, g as branch, h as map, i as use, j as error_path, k as aborted_error, l as timeout, m as pipe, n as scope, o as checkpoint, r as stash, s as compose, t as chain, u as fallback, v as sequence, x as is_valid_step_id, y as step, z as resolve_display_name } from "./core-BOFcG3tp.js";
|
|
2
|
-
import { t as create_engine } from "./engine-
|
|
2
|
+
import { t as create_engine } from "./engine-Bde18P7H.js";
|
|
3
|
+
import { n as is_record$1 } from "./records-1HU7mWXf.js";
|
|
4
|
+
import { t as json_schema_to_standard } from "./json_schema_to_standard-C4F4lXHE.js";
|
|
3
5
|
import { a as is_run_end_event, c as is_step_replayed_event, i as is_map_item_failed_event, l as parse_trajectory_event, n as is_custom_trajectory_event, o as is_span_end_event, r as is_emit_event, s as is_span_start_event, t as is_checkpoint_event } from "./trajectory-DeURWIhj.js";
|
|
4
6
|
import { a as http_logger, n as tee_logger, o as filesystem_logger } from "./adapters-CDUzZlby.js";
|
|
5
|
-
import { A as
|
|
7
|
+
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, d as default_normalize_usage, j as tool_error, k as schema_validation_error, v as engine_config_error, w as provider_capability_error, x as model_required_error, y as engine_disposed_error } from "./leading_system-DmNxhvzL.js";
|
|
6
8
|
import { createHash } from "node:crypto";
|
|
7
9
|
import { mkdir, readFile, readdir, writeFile } from "node:fs/promises";
|
|
8
10
|
import { dirname, join } from "node:path";
|
|
@@ -2243,16 +2245,60 @@ function is_step_list(source) {
|
|
|
2243
2245
|
return Array.isArray(source);
|
|
2244
2246
|
}
|
|
2245
2247
|
/**
|
|
2248
|
+
* The decode time that the provider measured for a step itself, in ms, or
|
|
2249
|
+
* undefined when it reported none.
|
|
2250
|
+
*
|
|
2251
|
+
* Ollama is the one provider that reports it: `eval_duration` is the
|
|
2252
|
+
* nanoseconds the daemon spent generating the step's output, and it lands on
|
|
2253
|
+
* `provider_reported.ollama` on either transport. It holds where the stamp
|
|
2254
|
+
* can't, because a turn that's only a tool call dispatches nothing until it
|
|
2255
|
+
* has finished generating, and its streamed window is the last few
|
|
2256
|
+
* milliseconds of the turn.
|
|
2257
|
+
*/
|
|
2258
|
+
function reported_decode_ms(step) {
|
|
2259
|
+
const ollama = step.provider_reported?.["ollama"];
|
|
2260
|
+
if (typeof ollama !== "object" || ollama === null) return void 0;
|
|
2261
|
+
const eval_duration = Reflect.get(ollama, "eval_duration");
|
|
2262
|
+
return typeof eval_duration === "number" && eval_duration > 0 ? eval_duration / 1e6 : void 0;
|
|
2263
|
+
}
|
|
2264
|
+
/**
|
|
2265
|
+
* One step's measured window and whether it is decode time, or undefined
|
|
2266
|
+
* when the step has nothing to measure. A decode time the provider reported
|
|
2267
|
+
* wins over the engine's own timing, streamed or not. A step whose first
|
|
2268
|
+
* chunk was a tool call that arrived whole streamed nothing while the model
|
|
2269
|
+
* generated that call, so its window is the whole round trip.
|
|
2270
|
+
*/
|
|
2271
|
+
function step_window(step) {
|
|
2272
|
+
const reported = reported_decode_ms(step);
|
|
2273
|
+
if (reported !== void 0) return {
|
|
2274
|
+
ms: reported,
|
|
2275
|
+
decode: true
|
|
2276
|
+
};
|
|
2277
|
+
if (step.timing === void 0) return void 0;
|
|
2278
|
+
const { duration_ms, first_chunk_ms, whole_tool_call } = step.timing;
|
|
2279
|
+
if (first_chunk_ms === void 0 || whole_tool_call === true) return {
|
|
2280
|
+
ms: duration_ms,
|
|
2281
|
+
decode: false
|
|
2282
|
+
};
|
|
2283
|
+
return {
|
|
2284
|
+
ms: duration_ms - first_chunk_ms,
|
|
2285
|
+
decode: true
|
|
2286
|
+
};
|
|
2287
|
+
}
|
|
2288
|
+
/**
|
|
2246
2289
|
* Compute output throughput from step timing: a whole GenerateResult, a step
|
|
2247
2290
|
* array, or a single step.
|
|
2248
2291
|
*
|
|
2249
|
-
*
|
|
2250
|
-
*
|
|
2251
|
-
*
|
|
2252
|
-
*
|
|
2253
|
-
*
|
|
2254
|
-
*
|
|
2255
|
-
*
|
|
2292
|
+
* Tool-execution time between turns never contributes, since StepTiming
|
|
2293
|
+
* brackets the provider round-trip alone. Each step's window is the decode
|
|
2294
|
+
* time its provider reported when it has one (Ollama's `eval_duration`),
|
|
2295
|
+
* else `duration_ms - first_chunk_ms` when the turn streamed, unless its
|
|
2296
|
+
* first chunk was a tool call that arrived whole, else the full
|
|
2297
|
+
* `duration_ms`, with `basis` reporting 'decode' only when no blended window
|
|
2298
|
+
* contributed. Returns undefined when nothing is measurable: no step has
|
|
2299
|
+
* timing or a reported decode time (an external adapter, a test seam), or the
|
|
2300
|
+
* summed window is 0 ms (a sub-millisecond stub turn), where a rate would
|
|
2301
|
+
* divide by zero.
|
|
2256
2302
|
*/
|
|
2257
2303
|
function throughput(source) {
|
|
2258
2304
|
const steps = is_step_list(source) ? source : "steps" in source ? source.steps : [source];
|
|
@@ -2260,13 +2306,11 @@ function throughput(source) {
|
|
|
2260
2306
|
let measured_ms = 0;
|
|
2261
2307
|
let all_decode = true;
|
|
2262
2308
|
for (const step of steps) {
|
|
2263
|
-
|
|
2309
|
+
const window = step_window(step);
|
|
2310
|
+
if (window === void 0) continue;
|
|
2264
2311
|
output_tokens += step.usage.output_tokens;
|
|
2265
|
-
|
|
2266
|
-
|
|
2267
|
-
measured_ms += step.timing.duration_ms;
|
|
2268
|
-
all_decode = false;
|
|
2269
|
-
}
|
|
2312
|
+
measured_ms += window.ms;
|
|
2313
|
+
if (!window.decode) all_decode = false;
|
|
2270
2314
|
}
|
|
2271
2315
|
if (measured_ms <= 0) return void 0;
|
|
2272
2316
|
return {
|
|
@@ -2277,6 +2321,169 @@ function throughput(source) {
|
|
|
2277
2321
|
};
|
|
2278
2322
|
}
|
|
2279
2323
|
//#endregion
|
|
2324
|
+
//#region src/engine/replay.ts
|
|
2325
|
+
/**
|
|
2326
|
+
* True for an array where capture writes messages, which the fold trusts to
|
|
2327
|
+
* hold the messages it wrote.
|
|
2328
|
+
*/
|
|
2329
|
+
function is_messages(value) {
|
|
2330
|
+
return Array.isArray(value);
|
|
2331
|
+
}
|
|
2332
|
+
/**
|
|
2333
|
+
* True for an array where capture writes a reply's parts, which the fold
|
|
2334
|
+
* trusts to hold the parts it wrote.
|
|
2335
|
+
*/
|
|
2336
|
+
function is_parts(value) {
|
|
2337
|
+
return Array.isArray(value);
|
|
2338
|
+
}
|
|
2339
|
+
/**
|
|
2340
|
+
* True for a first turn's request: settings that name a provider and a
|
|
2341
|
+
* model, a tool list, and a message array.
|
|
2342
|
+
*/
|
|
2343
|
+
function is_first_request(value) {
|
|
2344
|
+
if (!is_record$1(value) || !Array.isArray(value["tools"]) || !is_messages(value["messages"])) return false;
|
|
2345
|
+
const settings = value["settings"];
|
|
2346
|
+
return is_record$1(settings) && typeof settings["provider"] === "string" && typeof settings["model_id"] === "string";
|
|
2347
|
+
}
|
|
2348
|
+
/**
|
|
2349
|
+
* Read the events once, keeping each `request_sent` that names its call,
|
|
2350
|
+
* grouped by call in the order each call first appears, and each
|
|
2351
|
+
* `response_received` whose `content` is a list of parts, by its step span.
|
|
2352
|
+
*/
|
|
2353
|
+
function gather(events) {
|
|
2354
|
+
const gathered = {
|
|
2355
|
+
calls: /* @__PURE__ */ new Map(),
|
|
2356
|
+
responses: /* @__PURE__ */ new Map()
|
|
2357
|
+
};
|
|
2358
|
+
for (const event of events) {
|
|
2359
|
+
const { span_id } = event;
|
|
2360
|
+
if (event.kind === "response_received" && span_id !== void 0 && is_parts(event["content"])) gathered.responses.set(span_id, event["content"]);
|
|
2361
|
+
const call = event["call_span_id"];
|
|
2362
|
+
const step_index = event["step_index"];
|
|
2363
|
+
if (event.kind !== "request_sent" || typeof call !== "string" || typeof step_index !== "number") continue;
|
|
2364
|
+
const entry = {
|
|
2365
|
+
step_index,
|
|
2366
|
+
span_id,
|
|
2367
|
+
request: event["request"]
|
|
2368
|
+
};
|
|
2369
|
+
const sent = gathered.calls.get(call);
|
|
2370
|
+
if (sent === void 0) gathered.calls.set(call, [entry]);
|
|
2371
|
+
else sent.push(entry);
|
|
2372
|
+
}
|
|
2373
|
+
return gathered;
|
|
2374
|
+
}
|
|
2375
|
+
/**
|
|
2376
|
+
* The whole array a turn sent: its own when its request holds one (a first
|
|
2377
|
+
* turn, or a reshaped one), and otherwise the array rebuilt at the step just
|
|
2378
|
+
* before it with this turn's `appended` added. Undefined when the request is
|
|
2379
|
+
* missing or unreadable, or when the step before it wasn't rebuilt.
|
|
2380
|
+
*/
|
|
2381
|
+
function rebuilt_messages(sent, previous) {
|
|
2382
|
+
const { request } = sent;
|
|
2383
|
+
if (!is_record$1(request)) return void 0;
|
|
2384
|
+
if (is_messages(request["messages"])) return request["messages"];
|
|
2385
|
+
const appended = request["appended"];
|
|
2386
|
+
if (!is_messages(appended) || previous?.step_index !== sent.step_index - 1) return void 0;
|
|
2387
|
+
return [...previous.messages, ...appended];
|
|
2388
|
+
}
|
|
2389
|
+
/**
|
|
2390
|
+
* Fold one call's requests, in step order, into the turns it sent. A call
|
|
2391
|
+
* whose first turn is missing or unreadable yields nothing, since its
|
|
2392
|
+
* settings and tools went with it, and a turn that can't be rebuilt is left
|
|
2393
|
+
* out until a whole array picks the call up again.
|
|
2394
|
+
*/
|
|
2395
|
+
function fold_call(call_span_id, sent, responses) {
|
|
2396
|
+
const by_step = sent.toSorted((a, b) => a.step_index - b.step_index);
|
|
2397
|
+
const first = by_step.find((step) => step.step_index === 0);
|
|
2398
|
+
if (first === void 0 || !is_first_request(first.request)) return [];
|
|
2399
|
+
const { settings, tools } = first.request;
|
|
2400
|
+
const turns = [];
|
|
2401
|
+
let previous;
|
|
2402
|
+
for (const step of by_step) {
|
|
2403
|
+
const messages = rebuilt_messages(step, previous);
|
|
2404
|
+
previous = messages === void 0 ? void 0 : {
|
|
2405
|
+
step_index: step.step_index,
|
|
2406
|
+
messages
|
|
2407
|
+
};
|
|
2408
|
+
if (messages === void 0) continue;
|
|
2409
|
+
const response = responses.get(step.span_id);
|
|
2410
|
+
turns.push({
|
|
2411
|
+
call_span_id,
|
|
2412
|
+
step_index: step.step_index,
|
|
2413
|
+
settings,
|
|
2414
|
+
tools,
|
|
2415
|
+
messages,
|
|
2416
|
+
...response !== void 0 ? { response } : {}
|
|
2417
|
+
});
|
|
2418
|
+
}
|
|
2419
|
+
return turns;
|
|
2420
|
+
}
|
|
2421
|
+
/**
|
|
2422
|
+
* Rebuild every captured turn in a trajectory's events, in any order the
|
|
2423
|
+
* events arrive. Each call's turns are folded by `call_span_id` and ordered
|
|
2424
|
+
* by `step_index`, a delta is applied only on top of the turn at the step
|
|
2425
|
+
* just before it, and a turn's `response` is the `response_received.content`
|
|
2426
|
+
* that shares its step span. A turn whose request is missing or unreadable
|
|
2427
|
+
* (absent, `null`, or a string a redactor returned) is left out, and the call
|
|
2428
|
+
* picks up again at its next whole array. A call whose first turn is missing,
|
|
2429
|
+
* as in a truncated log, is left out whole. Calls come out in the order each
|
|
2430
|
+
* first appears in the events.
|
|
2431
|
+
*/
|
|
2432
|
+
function captured_turns(events) {
|
|
2433
|
+
const { calls, responses } = gather(events);
|
|
2434
|
+
return [...calls].flatMap(([call_span_id, sent]) => fold_call(call_span_id, sent, responses));
|
|
2435
|
+
}
|
|
2436
|
+
/**
|
|
2437
|
+
* A captured tool rebuilt for a replay: its name, description, and schema,
|
|
2438
|
+
* with an `execute` that throws, so a replay can never act on the world. A
|
|
2439
|
+
* tool whose schema wasn't captured takes any object.
|
|
2440
|
+
*/
|
|
2441
|
+
function inert_tool(tool) {
|
|
2442
|
+
return {
|
|
2443
|
+
name: tool.name,
|
|
2444
|
+
description: tool.description,
|
|
2445
|
+
input_schema: json_schema_to_standard(tool.input_schema ?? { type: "object" }),
|
|
2446
|
+
execute: () => {
|
|
2447
|
+
throw new Error(`replay_turn never runs a tool: the model called '${tool.name}'`);
|
|
2448
|
+
}
|
|
2449
|
+
};
|
|
2450
|
+
}
|
|
2451
|
+
/**
|
|
2452
|
+
* Send one captured turn again, as one turn that can't act: the turn's
|
|
2453
|
+
* messages, settings, and tools through `engine.generate` with
|
|
2454
|
+
* `max_steps: 1`, `cache: 'off'`, `capture: 'off'`, and `system: ''`, so the
|
|
2455
|
+
* engine's default system prompt doesn't add a second one. The captured
|
|
2456
|
+
* schema stays behind, so the reply comes back raw. Each tool is rebuilt
|
|
2457
|
+
* with an `execute` that throws, and a model that calls one comes back with
|
|
2458
|
+
* the call listed and unexecuted (`finish_reason: 'max_steps'`). The
|
|
2459
|
+
* captured `provider_options` go as they were, a raw `cache_control`
|
|
2460
|
+
* included, and the replaying engine's defaults fill whatever the turn left
|
|
2461
|
+
* unset. `edit` changes the turn before it goes, and `provider` and `model`
|
|
2462
|
+
* send it elsewhere. A replay is inert only on the `ai_sdk` and native
|
|
2463
|
+
* transports, since an external provider runs its own loop and tools.
|
|
2464
|
+
*/
|
|
2465
|
+
async function replay_turn(engine, turn, options = {}) {
|
|
2466
|
+
const sent = options.edit === void 0 ? turn : options.edit(turn);
|
|
2467
|
+
const { settings } = sent;
|
|
2468
|
+
const opts = {
|
|
2469
|
+
provider: options.provider ?? settings.provider,
|
|
2470
|
+
model: options.model ?? settings.model_id,
|
|
2471
|
+
prompt: [...sent.messages],
|
|
2472
|
+
system: "",
|
|
2473
|
+
tools: sent.tools.map(inert_tool),
|
|
2474
|
+
effort: settings.effort,
|
|
2475
|
+
max_steps: 1,
|
|
2476
|
+
cache: "off",
|
|
2477
|
+
capture: "off",
|
|
2478
|
+
...settings.temperature !== void 0 ? { temperature: settings.temperature } : {},
|
|
2479
|
+
...settings.max_tokens !== void 0 ? { max_tokens: settings.max_tokens } : {},
|
|
2480
|
+
...settings.top_p !== void 0 ? { top_p: settings.top_p } : {},
|
|
2481
|
+
...settings.provider_options !== void 0 ? { provider_options: { ...settings.provider_options } } : {},
|
|
2482
|
+
...options.trajectory !== void 0 ? { trajectory: options.trajectory } : {}
|
|
2483
|
+
};
|
|
2484
|
+
return await engine.generate(opts);
|
|
2485
|
+
}
|
|
2486
|
+
//#endregion
|
|
2280
2487
|
//#region src/engine/providers/claude_cli/reported.ts
|
|
2281
2488
|
/**
|
|
2282
2489
|
* Read the claude CLI's reported run detail off anything carrying
|
|
@@ -2422,6 +2629,8 @@ function build_generate_options(cfg, prompt, ctx) {
|
|
|
2422
2629
|
if (cfg.tools !== void 0) opts.tools = [...cfg.tools];
|
|
2423
2630
|
assign_if_present(opts, "schema", cfg.schema);
|
|
2424
2631
|
assign_if_present(opts, "effort", cfg.effort);
|
|
2632
|
+
assign_if_present(opts, "cache", cfg.cache);
|
|
2633
|
+
assign_if_present(opts, "capture", cfg.capture);
|
|
2425
2634
|
assign_if_present(opts, "temperature", cfg.temperature);
|
|
2426
2635
|
assign_if_present(opts, "max_tokens", cfg.max_tokens);
|
|
2427
2636
|
assign_if_present(opts, "top_p", cfg.top_p);
|
|
@@ -2434,6 +2643,7 @@ function build_generate_options(cfg, prompt, ctx) {
|
|
|
2434
2643
|
assign_if_present(opts, "schema_repair_attempts", cfg.schema_repair_attempts);
|
|
2435
2644
|
assign_if_present(opts, "tool_call_repair_attempts", cfg.tool_call_repair_attempts);
|
|
2436
2645
|
assign_if_present(opts, "max_tool_calls_per_step", cfg.max_tool_calls_per_step);
|
|
2646
|
+
assign_if_present(opts, "truncated_turn_policy", cfg.truncated_turn_policy);
|
|
2437
2647
|
assign_if_present(opts, "on_tool_approval", cfg.on_tool_approval);
|
|
2438
2648
|
return opts;
|
|
2439
2649
|
}
|
|
@@ -2567,6 +2777,6 @@ function forward_standard_env() {
|
|
|
2567
2777
|
return out;
|
|
2568
2778
|
}
|
|
2569
2779
|
//#endregion
|
|
2570
|
-
export { STEP_KINDS, aborted_error, adversarial, assert_valid_step_id, bench, bench_suspend_error, branch, chain, checkpoint, claude_cli_error, claude_cli_reported, compose, consensus, create_engine, default_normalize_usage, define_tool, describe, describe_cycle_error, durable, engine_config_error, engine_disposed_error, ensemble, ensemble_step, error_path, fallback, flow_changed_error, flow_schema, forward_standard_env, gate, improve, incomplete_generation_error, is_checkpoint_event, is_custom_trajectory_event, is_emit_event, is_map_item_failed_event, is_run_end_event, is_span_end_event, is_span_start_event, is_step, is_step_kind, is_step_replayed_event, is_valid_step_id, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, model_step, normalize_score, on_chunk_error, parallel, parse_trajectory_event, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, provider_required_error, rate_limit_error, read_baseline, regression_compare, resolve_display_name, resume_validation_error, retry, run, run_not_found_error, schema_validation_error, scope, sequence, stash, step, suggest_step_id, suspend, suspended_error, throughput, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, turn_timeout_error, use, write_baseline };
|
|
2780
|
+
export { STEP_KINDS, aborted_error, adversarial, assert_valid_step_id, bench, bench_suspend_error, branch, captured_turns, chain, checkpoint, claude_cli_error, claude_cli_reported, compose, consensus, create_engine, default_normalize_usage, define_tool, describe, describe_cycle_error, durable, engine_config_error, engine_disposed_error, ensemble, ensemble_step, error_path, fallback, flow_changed_error, flow_schema, forward_standard_env, gate, improve, incomplete_generation_error, is_checkpoint_event, is_custom_trajectory_event, is_emit_event, is_map_item_failed_event, is_run_end_event, is_span_end_event, is_span_start_event, is_step, is_step_kind, is_step_replayed_event, is_valid_step_id, judge_equals, judge_llm, judge_with, learn, loop, map, model_call, model_required_error, model_step, normalize_score, on_chunk_error, parallel, parse_trajectory_event, pipe, provider_auth_error, provider_capability_error, provider_error, provider_not_configured_error, provider_required_error, rate_limit_error, read_baseline, regression_compare, replay_turn, resolve_display_name, resume_validation_error, retry, run, run_not_found_error, schema_validation_error, scope, sequence, stash, step, suggest_step_id, suspend, suspended_error, throughput, timeout, timeout_error, tool_approval_denied_error, tool_error, tournament, turn_timeout_error, use, write_baseline };
|
|
2571
2781
|
|
|
2572
2782
|
//# sourceMappingURL=index.js.map
|