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.
Files changed (41) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/README.md +3 -2
  3. package/dist/AGENTS.md +69 -18
  4. package/dist/acp.d.ts +1 -1
  5. package/dist/acp.js +7 -2
  6. package/dist/acp.js.map +1 -1
  7. package/dist/agents.d.ts +1 -1
  8. package/dist/{engine-B6rIIM4J.js → engine-Bde18P7H.js} +1163 -236
  9. package/dist/engine-Bde18P7H.js.map +1 -0
  10. package/dist/index.d.ts +114 -16
  11. package/dist/index.js +226 -16
  12. package/dist/index.js.map +1 -1
  13. package/dist/{invoke-LbzZLZFw.js → invoke-BbJLQcLl.js} +62 -106
  14. package/dist/invoke-BbJLQcLl.js.map +1 -0
  15. package/dist/{leading_system-WhW76tRn.js → leading_system-DmNxhvzL.js} +45 -16
  16. package/dist/leading_system-DmNxhvzL.js.map +1 -0
  17. package/dist/mcp.d.ts +2 -1
  18. package/dist/mcp.js +6 -3
  19. package/dist/mcp.js.map +1 -1
  20. package/dist/otel.js +48 -3
  21. package/dist/otel.js.map +1 -1
  22. package/dist/{search-CpCJYMUm.js → search-DjhdMsJ8.js} +4 -1
  23. package/dist/search-DjhdMsJ8.js.map +1 -0
  24. package/dist/search_worker.js +1 -1
  25. package/dist/testing.d.ts +77 -2
  26. package/dist/testing.js +202 -19
  27. package/dist/testing.js.map +1 -1
  28. package/dist/{types-Sw0oHW-_.d.ts → types-C7pO0jLq.d.ts} +218 -21
  29. package/dist/viewer-app/assets/index-9eVv6Mar.css +1 -0
  30. package/dist/viewer-app/assets/index-BkS2ZQu0.js +4 -0
  31. package/dist/viewer-app/index.html +2 -2
  32. package/dist/viewer.d.ts +64 -10
  33. package/dist/viewer.js +265 -64
  34. package/dist/viewer.js.map +1 -1
  35. package/package.json +1 -1
  36. package/dist/engine-B6rIIM4J.js.map +0 -1
  37. package/dist/invoke-LbzZLZFw.js.map +0 -1
  38. package/dist/leading_system-WhW76tRn.js.map +0 -1
  39. package/dist/search-CpCJYMUm.js.map +0 -1
  40. package/dist/viewer-app/assets/index-Cev83tcH.css +0 -1
  41. package/dist/viewer-app/assets/index-D8UmFVfR.js +0 -2
@@ -78,6 +78,14 @@ type EffortTranslation = {
78
78
  reasoning?: Exclude<EffortLevel, 'none'>;
79
79
  };
80
80
  type ProviderCapability = 'text' | 'tools' | 'schema' | 'streaming' | 'image_input' | 'reasoning' | 'structured_output';
81
+ /**
82
+ * How an adapter caches prompts, which decides what a call's `cache` setting
83
+ * does on it. `'with_tools'` caches for five minutes by default on a call
84
+ * with tools, `'opt_in'` caches only when the call or the engine asks, and
85
+ * `'automatic'` marks a provider that caches on its own, so an explicit
86
+ * setting is ignored. An adapter that declares nothing requests no caching.
87
+ */
88
+ type PromptCacheDeclaration = 'with_tools' | 'opt_in' | 'automatic';
81
89
  type RawProviderUsage = {
82
90
  input_tokens?: number;
83
91
  output_tokens?: number;
@@ -99,8 +107,21 @@ type AiSdkProviderAdapter = {
99
107
  readonly metadata_key?: string;
100
108
  readonly build_model: (model_id: string) => Promise<unknown>;
101
109
  readonly translate_effort: (effort: EffortLevel) => EffortTranslation;
102
- readonly normalize_usage: (raw: RawProviderUsage | undefined) => UsageTotals;
110
+ /**
111
+ * Map the SDK's usage to UsageTotals. The engine also hands it the step's
112
+ * `providerMetadata`, for a split that the SDK's usage object leaves out.
113
+ */
114
+ readonly normalize_usage: (raw: RawProviderUsage | undefined, provider_metadata?: unknown) => UsageTotals;
103
115
  readonly supports: (capability: ProviderCapability) => boolean;
116
+ readonly prompt_cache?: PromptCacheDeclaration;
117
+ /**
118
+ * Turn the call's resolved cache setting into call-level provider options,
119
+ * given the caller's own (engine defaults merged with the call's). The
120
+ * engine merges the result beneath the caller's options, where effort's
121
+ * translation goes. An adapter that declares `'with_tools'` or `'opt_in'`
122
+ * without this hook asks for no cache, as one that declares nothing.
123
+ */
124
+ readonly translate_cache?: (cache: CacheSetting, provider_options: Readonly<Record<string, unknown>> | undefined) => Record<string, Record<string, unknown>>;
104
125
  };
105
126
  /**
106
127
  * Raw-HTTP transport: implements a single turn against a provider's own
@@ -115,6 +136,7 @@ type NativeProviderAdapter = {
115
136
  readonly name: string;
116
137
  readonly invoke_turn: (req: TurnRequest) => Promise<TurnResult>;
117
138
  readonly supports: (capability: ProviderCapability) => boolean;
139
+ readonly prompt_cache?: PromptCacheDeclaration;
118
140
  readonly dispose?: () => Promise<void>;
119
141
  readonly classify_error?: (err: unknown) => unknown;
120
142
  };
@@ -138,6 +160,45 @@ declare function default_normalize_usage(raw: RawProviderUsage | undefined): Usa
138
160
  //#endregion
139
161
  //#region src/engine/types.d.ts
140
162
  type EffortLevel = 'none' | 'low' | 'medium' | 'high' | 'xhigh' | 'max';
163
+ /**
164
+ * Prompt caching for a call: `'off'` asks for none, `'5m'` for a five-minute
165
+ * cache, and `'1h'` for a one-hour one. What a provider does with it depends
166
+ * on the caching its adapter declares; see `docs/providers.md`'s Prompt
167
+ * Caching.
168
+ */
169
+ type CacheSetting = 'off' | '5m' | '1h';
170
+ /**
171
+ * What a call records of the requests it sends and the replies it gets:
172
+ * `'off'` records neither, `'turns'` records each turn's request (the
173
+ * first turn whole, a later one as what it changed) on `request_sent` and
174
+ * the reply on `response_received`, and `'wire'` records all that and, on a
175
+ * native transport, the exact body each attempt sends, as `request_wire`.
176
+ * See `docs/concepts.md`'s What Gets Recorded.
177
+ */
178
+ type CaptureLevel = 'off' | 'turns' | 'wire';
179
+ /**
180
+ * What a tool loop does with a turn that reached its output limit (finish
181
+ * reason `'length'`) before it made a tool call: `'stop'` ends the loop with
182
+ * that turn, and `'continue'` sends back the turn's text with a message that
183
+ * says it was cut off, and asks for another turn, which counts toward
184
+ * `max_steps`. See `docs/configuration.md`'s Local-Runtime Tool Reliability.
185
+ */
186
+ type TruncatedTurnPolicy = 'stop' | 'continue';
187
+ /**
188
+ * One captured payload, as `EngineConfig.redact_capture` receives it before
189
+ * the trajectory does: `'request'` is what a turn's `request_sent` would
190
+ * carry as `request`, `'response'` what its `response_received` would carry
191
+ * as `content`, and `'wire'` is `{ url, body }`, what a native adapter is
192
+ * about to send, whose `request_wire` records the `url` and `body` of the
193
+ * object the redactor returns. `data` is a fresh JSON-safe copy, so a
194
+ * redactor may change it in place without touching what goes out, and an
195
+ * image in it is already its base64 text.
196
+ */
197
+ type CapturePayload = {
198
+ readonly kind: 'request' | 'response' | 'wire';
199
+ readonly step_index: number;
200
+ readonly data: unknown;
201
+ };
141
202
  type FinishReason = 'stop' | 'tool_calls' | 'length' | 'content_filter' | 'max_steps';
142
203
  type RetryFailureKind = 'rate_limit' | 'provider_5xx' | 'network' | 'timeout';
143
204
  type RetryPolicy = {
@@ -159,6 +220,11 @@ type Pricing = {
159
220
  output_per_million: number;
160
221
  cached_input_per_million?: number;
161
222
  cache_write_per_million?: number;
223
+ /**
224
+ * The rate for a one-hour cache write. Unset, a one-hour write costs twice
225
+ * `input_per_million`, which is Anthropic's rate.
226
+ */
227
+ cache_write_1h_per_million?: number;
162
228
  reasoning_per_million?: number;
163
229
  };
164
230
  type PricingTable = Readonly<Record<string, Pricing>>;
@@ -168,6 +234,11 @@ type UsageTotals = {
168
234
  reasoning_tokens?: number;
169
235
  cached_input_tokens?: number;
170
236
  cache_write_tokens?: number;
237
+ /**
238
+ * The part of `cache_write_tokens` written with a one-hour lifetime, when
239
+ * the provider reports the split.
240
+ */
241
+ cache_write_1h_tokens?: number;
171
242
  };
172
243
  type CostBreakdown = {
173
244
  total_usd: number;
@@ -184,19 +255,33 @@ type SalvageFormat = 'hermes' | 'json' | 'qwen_xml';
184
255
  * Wall-clock timing of one step's provider round-trip, measured by the engine
185
256
  * around the successful turn attempt: failed attempts and retry backoff are
186
257
  * excluded, as is tool execution (that is ToolCallRecord.duration_ms).
187
- * `first_chunk_ms` is present only on streamed turns: milliseconds from the
188
- * attempt start to the first StreamChunk the turn dispatched (a token, a
189
- * reasoning delta, or a tool-call part, never the transport's stream-open
190
- * framing), so `duration_ms - first_chunk_ms` is the window the model spent
191
- * emitting output. See `throughput()` for the derived tokens-per-second view.
258
+ * `first_chunk_ms` is present on every turn that dispatched a chunk:
259
+ * milliseconds from the attempt start to the first StreamChunk the turn
260
+ * dispatched (a token, a reasoning delta, or a tool-call part, never the
261
+ * transport's stream-open framing). Every depth-1 turn streams, consumer or
262
+ * not (an ai_sdk turn always, a native one whenever its adapter supports
263
+ * streaming), so it carries one, while a whole-body turn from a native
264
+ * adapter that doesn't stream has none. `duration_ms - first_chunk_ms` is the window the model spent
265
+ * emitting output, as long as the turn streams output while it generates it.
266
+ * A provider that sends a tool call whole once it has generated it leaves
267
+ * that window at the turn's last few milliseconds. `whole_tool_call` marks
268
+ * such a turn, and `throughput()`, the derived tokens-per-second view,
269
+ * prefers a decode time the provider reports itself, and counts a marked
270
+ * turn's whole round trip when there's none.
192
271
  */
193
272
  type StepTiming = {
194
273
  /** Epoch ms when the successful provider attempt started. */
195
274
  started_at: number;
196
275
  /** Wall-clock ms from attempt start to the turn result. */
197
276
  duration_ms: number;
198
- /** Streamed turns only: ms from attempt start to the first dispatched chunk. */
277
+ /** Turns that dispatched a chunk: ms from attempt start to the first one. */
199
278
  first_chunk_ms?: number;
279
+ /**
280
+ * Present when the first chunk belonged to a tool call that arrived whole,
281
+ * its input in one delta or none, so the model generated it before the
282
+ * stamp and the window after `first_chunk_ms` isn't decode time.
283
+ */
284
+ whole_tool_call?: true;
200
285
  };
201
286
  /**
202
287
  * Wall-clock timing of a whole generate call, stamped by the engine around
@@ -249,6 +334,13 @@ type StepRecord = {
249
334
  * here, since the call-level field can only carry one.
250
335
  */
251
336
  provider_reported?: Record<string, unknown>;
337
+ /**
338
+ * Present on a turn that reached its output limit before it made a tool
339
+ * call, and that the loop went on past (`truncated_turn_policy:
340
+ * 'continue'`). Its `finish_reason` is `'length'`. A turn the loop ended
341
+ * on carries no such mark, so a call that ends on one says `'length'`.
342
+ */
343
+ truncated?: true;
252
344
  };
253
345
  /**
254
346
  * Provider-specific data on a content part, keyed by provider name: the AI
@@ -280,7 +372,9 @@ type UserContentPart = {
280
372
  * request (a thinking block's signature, Gemini's thought signature on a tool
281
373
  * call), keyed by provider name. Each adapter sends back only the reasoning
282
374
  * parts carrying its own key, so a `fallback` never hands one vendor's
283
- * signature to another.
375
+ * signature to another. An `opaque` part is a block that only its provider
376
+ * understands (a server tool's call or result, say), carried back verbatim
377
+ * under that provider's key and skipped by every other adapter.
284
378
  */
285
379
  type AssistantContentPart = {
286
380
  type: 'text';
@@ -297,6 +391,10 @@ type AssistantContentPart = {
297
391
  /** The thinking the model showed, or '' when it showed none (encrypted, redacted, or omitted). */
298
392
  text: string;
299
393
  provider_options?: ProviderOptions;
394
+ } | {
395
+ type: 'opaque';
396
+ /** The block as its provider sent it, under that provider's key (`{ anthropic: { block } }`). */
397
+ provider_options: ProviderOptions;
300
398
  };
301
399
  type Message = {
302
400
  role: 'system';
@@ -312,6 +410,14 @@ type Message = {
312
410
  tool_call_id: string;
313
411
  name: string;
314
412
  content: string;
413
+ /**
414
+ * True when the call failed (an unknown tool, invalid input, a denied
415
+ * approval, or a thrown error) and `content` is its `{"error": "…"}`
416
+ * text; absent on a success. The native Anthropic transport sends it as
417
+ * the `tool_result`'s `is_error`, and the ai_sdk transport as an
418
+ * `error-text` output; the other wire formats have no such field.
419
+ */
420
+ is_error?: boolean;
315
421
  };
316
422
  type ToolExecContext = {
317
423
  abort: AbortSignal;
@@ -333,6 +439,14 @@ type Tool<i = unknown, o = unknown> = {
333
439
  * end the loop. undefined (the default) never ends the loop early.
334
440
  */
335
441
  ends_turn?: boolean;
442
+ /**
443
+ * True for a tool whose calls change nothing, such as a file read or a
444
+ * search. A call to it doesn't count toward `max_tool_calls_per_step`,
445
+ * which is there to stop a turn from making calls that depend on each
446
+ * other's effects before the model has seen a result, and a call that
447
+ * changes nothing can't. undefined (the default) counts like any call.
448
+ */
449
+ read_only?: boolean;
336
450
  };
337
451
  type ToolApprovalRequest = {
338
452
  tool_name: string;
@@ -413,6 +527,13 @@ type TurnResult = {
413
527
  * else reads.
414
528
  */
415
529
  readonly content?: ReadonlyArray<AssistantContentPart>;
530
+ /**
531
+ * True when the provider paused the turn partway through its response
532
+ * (Anthropic's `pause_turn`, which a long server-tool turn can hit), with
533
+ * `finish_reason` left at `'stop'`. The loop sends the turn back as it is
534
+ * and asks for another turn to continue it. Absent on every other turn.
535
+ */
536
+ readonly paused?: boolean;
416
537
  /**
417
538
  * What the provider says this turn cost, in US dollars, for a provider that
418
539
  * reports its charge on the response (OpenRouter does). The loop records it
@@ -444,7 +565,10 @@ type TurnResult = {
444
565
  * generate.ts assembles it from GenerateOptions plus engine defaults (resolved
445
566
  * system, effort, merged provider_options, sampling params). When `stream` is
446
567
  * true `dispatch_chunk` is defined and the adapter MUST emit StreamChunks
447
- * through it while still returning the fully aggregated TurnResult.
568
+ * through it while still returning the fully aggregated TurnResult. The
569
+ * engine sets `stream` on every turn to an adapter that supports streaming,
570
+ * whether or not the caller passed `on_chunk`, and passes the chunks on only
571
+ * to a consumer.
448
572
  */
449
573
  type TurnRequest = {
450
574
  readonly step_index: number;
@@ -460,7 +584,21 @@ type TurnRequest = {
460
584
  readonly temperature?: number;
461
585
  readonly max_tokens?: number;
462
586
  readonly top_p?: number;
587
+ /**
588
+ * The cache lifetime the engine resolved for this call, absent when caching
589
+ * is off. An adapter that declares `prompt_cache` maps it onto its wire.
590
+ */
591
+ readonly cache?: Exclude<CacheSetting, 'off'>;
463
592
  readonly dispatch_chunk?: (chunk: StreamChunk) => Promise<void>;
593
+ /**
594
+ * Present when the call captures at `'wire'`. An adapter that builds an
595
+ * HTTP body calls it with the URL and the body object just before it
596
+ * serializes the body, once per attempt, and never with a header.
597
+ */
598
+ readonly on_wire?: (wire: {
599
+ readonly url: string;
600
+ readonly body: Record<string, unknown>;
601
+ }) => void;
464
602
  };
465
603
  /**
466
604
  * Context handed to a prepare_step hook: the turn's index and the would-be
@@ -502,9 +640,9 @@ type GenerateOptions<t = string> = {
502
640
  max_steps?: number;
503
641
  /**
504
642
  * Per-turn wall-clock budget in milliseconds. When set, the engine composes
505
- * a timeout signal with `abort` around every turn; expiry before
506
- * any chunk streams throws a retryable timeout, while an expiry after chunks
507
- * have flowed becomes a non-retryable stream interruption. undefined (the
643
+ * a timeout signal with `abort` around every turn; an expiry throws a
644
+ * retryable timeout, unless a chunk has already reached `on_chunk`, in which
645
+ * case it becomes a non-retryable stream interruption. undefined (the
508
646
  * default) leaves turns unbounded. Must be > 0.
509
647
  */
510
648
  turn_timeout_ms?: number;
@@ -522,12 +660,26 @@ type GenerateOptions<t = string> = {
522
660
  */
523
661
  tool_call_repair_attempts?: number;
524
662
  /**
525
- * Cap on tool calls executed per step. Calls beyond the cap are dropped
526
- * for that step (the model can re-issue them next turn) and surfaced via
527
- * ToolCallRecord errors and a tool_calls_dropped trajectory event.
528
- * undefined (the default) leaves the count unlimited.
663
+ * Cap on tool calls executed per step. A call to a tool flagged
664
+ * `read_only` doesn't count. The first call past the cap, and every call
665
+ * after it, are dropped for that step and surfaced via ToolCallRecord
666
+ * errors and a tool_calls_dropped trajectory event. When the loop goes on,
667
+ * one user message after the step's tool results names them, so the model
668
+ * can make them again. undefined (the default) leaves the count unlimited.
529
669
  */
530
670
  max_tool_calls_per_step?: number;
671
+ /**
672
+ * What the loop does with a turn that reached its output limit before it
673
+ * made a tool call. `'stop'` (the default) ends the loop with that turn.
674
+ * `'continue'`, on a call with tools and with a step left, sends back the
675
+ * turn's visible text (its reasoning is left out) and a user message that
676
+ * says the turn was cut off, then asks for another turn; the turn's
677
+ * StepRecord says `truncated: true`, and a turn_truncated trajectory event
678
+ * records it. That makes `max_tokens` a per-turn cap that a thinking model
679
+ * can run into without ending its session. Any other value throws
680
+ * `engine_config_error`.
681
+ */
682
+ truncated_turn_policy?: TruncatedTurnPolicy;
531
683
  on_tool_approval?: ToolApprovalHandler;
532
684
  /**
533
685
  * Per-turn hook to reshape the messages sent to the model without mutating
@@ -538,6 +690,22 @@ type GenerateOptions<t = string> = {
538
690
  * PrepareStepHook.
539
691
  */
540
692
  prepare_step?: PrepareStepHook;
693
+ /**
694
+ * Prompt caching for this call. Left unset, an adapter that caches with
695
+ * tools (Anthropic, on either transport) caches for five minutes when the
696
+ * call has tools, and every other adapter asks for no cache. `'off'` turns it off. An
697
+ * adapter that can't honor an explicit `'5m'` or `'1h'` records
698
+ * `option_ignored`. Any other value throws `engine_config_error`.
699
+ */
700
+ cache?: CacheSetting;
701
+ /**
702
+ * What this call records of each turn's request and reply. Left unset,
703
+ * the engine's `defaults.capture` applies, and with neither set nothing is
704
+ * recorded. A captured request carries user data, so keep it off where
705
+ * the trajectory goes somewhere that data mustn't. Any other value throws
706
+ * `engine_config_error`. See CaptureLevel.
707
+ */
708
+ capture?: CaptureLevel;
541
709
  provider_options?: Record<string, unknown>;
542
710
  };
543
711
  type GenerateResult<t = string> = {
@@ -629,8 +797,8 @@ type ProviderConfigMap = {
629
797
  /**
630
798
  * Opt-in OpenTelemetry for the `ai_sdk` transport (Layer 2). When `enabled`,
631
799
  * the transport constructs an `@ai-sdk/otel` integration strictly below the turn
632
- * seam and hands it to the SDK's telemetry, so generateText / streamText emit
633
- * turn-internal spans on the ai_sdk transport only. Native transports ignore it;
800
+ * seam and hands it to the SDK's telemetry, so streamText, which every turn
801
+ * takes, emits turn-internal spans on the ai_sdk transport only. Native transports ignore it;
634
802
  * loop-level, transport-neutral tracing is the `fascicle/otel` bridge's job
635
803
  * (Layer 1). `tracer` is an `@opentelemetry/api` Tracer, typed `unknown` here so
636
804
  * the engine's public type surface stays free of the optional OTel peer.
@@ -652,7 +820,7 @@ type AiSdkTelemetrySettings = {
652
820
  * | --------------------------------------------------------------------- | ----------------------------------------- |
653
821
  * | `model` | per-call wins; else default; else model_required_error is thrown |
654
822
  * | `provider` | per-call wins; else default; else sole configured provider; else provider_required_error is thrown |
655
- * | `system`, `effort`, `max_steps`, `turn_timeout_ms`, `tool_error_policy`, `schema_repair_attempts`, `tool_call_repair_attempts`, `max_tool_calls_per_step` | per-call wins (nullish coalesce) |
823
+ * | `system`, `effort`, `cache`, `capture`, `max_steps`, `turn_timeout_ms`, `tool_error_policy`, `schema_repair_attempts`, `tool_call_repair_attempts`, `max_tool_calls_per_step`, `truncated_turn_policy` | per-call wins (nullish coalesce) |
656
824
  * | `temperature`, `max_tokens`, `top_p` | per-call wins (nullish coalesce) |
657
825
  * | `retry_policy` | per-call replaces wholesale |
658
826
  * | `provider_options` | two-level: per-provider-key shallow merge |
@@ -663,6 +831,17 @@ type EngineDefaults = {
663
831
  readonly provider?: string;
664
832
  readonly system?: string;
665
833
  readonly effort?: EffortLevel;
834
+ /**
835
+ * Prompt caching for every call that sets none. An unknown value throws
836
+ * `engine_config_error` at `create_engine`. See `GenerateOptions.cache`.
837
+ */
838
+ readonly cache?: CacheSetting;
839
+ /**
840
+ * What every call that sets none records of its requests and replies. An
841
+ * unknown value throws `engine_config_error` at `create_engine`. See
842
+ * `GenerateOptions.capture`.
843
+ */
844
+ readonly capture?: CaptureLevel;
666
845
  readonly temperature?: number;
667
846
  readonly max_tokens?: number;
668
847
  readonly top_p?: number;
@@ -673,6 +852,13 @@ type EngineDefaults = {
673
852
  readonly schema_repair_attempts?: number;
674
853
  readonly tool_call_repair_attempts?: number;
675
854
  readonly max_tool_calls_per_step?: number;
855
+ /**
856
+ * What every call that sets none does with a turn that reached its output
857
+ * limit before it made a tool call. An unknown value throws
858
+ * `engine_config_error` at `create_engine`. See
859
+ * `GenerateOptions.truncated_turn_policy`.
860
+ */
861
+ readonly truncated_turn_policy?: TruncatedTurnPolicy;
676
862
  readonly provider_options?: Readonly<Record<string, Readonly<Record<string, unknown>>>>;
677
863
  /**
678
864
  * Opt-in OpenTelemetry for the `ai_sdk` transport (Layer 2). Enabling it
@@ -697,6 +883,17 @@ type EngineConfig = {
697
883
  default_effort?: EffortLevel;
698
884
  default_max_steps?: number;
699
885
  defaults?: EngineDefaults;
886
+ /**
887
+ * Scrub or drop each captured payload before the trajectory records it,
888
+ * for every call on this engine. It returns what to record in the
889
+ * payload's place, and `undefined` records nothing. A redactor that
890
+ * throws, or that returns a promise or any other thenable, records
891
+ * nothing either, and the turn records `capture_redaction_failed` naming
892
+ * the payload's kind, so nothing that it would have scrubbed is written. It
893
+ * covers only what `capture` adds, never `model_chunk`, `tool_call.input`,
894
+ * `tool_result.output`, or the `raw_text` fields. See CapturePayload.
895
+ */
896
+ redact_capture?: (payload: CapturePayload) => unknown;
700
897
  };
701
898
  type Engine = {
702
899
  generate: <t = string>(opts: GenerateOptions<t>) => Promise<GenerateResult<t>>;
@@ -720,5 +917,5 @@ type Engine = {
720
917
  dispose: () => Promise<void>;
721
918
  };
722
919
  //#endregion
723
- export { ToolApprovalHandler as A, ExternalAgentAdapter as B, ResolvedModel as C, StepTiming as D, StepRecord as E, TurnResult as F, ProviderTransport as G, ProviderAdapter as H, UsageTotals as I, ClaudeCliProviderReported as J, RawProviderUsage as K, UserContentPart as L, ToolCallRecord as M, ToolExecContext as N, StreamChunk as O, TurnRequest as P, AiSdkProviderAdapter as R, ProviderOptions as S, RetryPolicy as T, ProviderCapability as U, NativeProviderAdapter as V, ProviderFactory as W, PrepareStepResult as _, CostBreakdown as a, ProviderConfigMap as b, EngineConfig as c, GenerateOptions as d, GenerateResult as f, PrepareStepHook as g, PrepareStepContext as h, BedrockCredentials as i, ToolApprovalRequest as j, Tool as k, EngineDefaults as l, Message as m, AssistantContentPart as n, EffortLevel as o, GenerateTiming as p, default_normalize_usage as q, BedrockCredentialProvider as r, Engine as s, AiSdkTelemetrySettings as t, FinishReason as u, Pricing as v, RetryFailureKind as w, ProviderInit as x, PricingTable as y, EffortTranslation as z };
724
- //# sourceMappingURL=types-Sw0oHW-_.d.ts.map
920
+ export { StepTiming as A, UsageTotals as B, ProviderConfigMap as C, RetryFailureKind as D, ResolvedModel as E, ToolCallRecord as F, NativeProviderAdapter as G, AiSdkProviderAdapter as H, ToolExecContext as I, ProviderFactory as J, ProviderAdapter as K, TruncatedTurnPolicy as L, Tool as M, ToolApprovalHandler as N, RetryPolicy as O, ToolApprovalRequest as P, ClaudeCliProviderReported as Q, TurnRequest as R, PricingTable as S, ProviderOptions as T, EffortTranslation as U, UserContentPart as V, ExternalAgentAdapter as W, RawProviderUsage as X, ProviderTransport as Y, default_normalize_usage as Z, Message as _, CacheSetting as a, PrepareStepResult as b, CostBreakdown as c, EngineConfig as d, EngineDefaults as f, GenerateTiming as g, GenerateResult as h, BedrockCredentials as i, StreamChunk as j, StepRecord as k, EffortLevel as l, GenerateOptions as m, AssistantContentPart as n, CaptureLevel as o, FinishReason as p, ProviderCapability as q, BedrockCredentialProvider as r, CapturePayload as s, AiSdkTelemetrySettings as t, Engine as u, PrepareStepContext as v, ProviderInit as w, Pricing as x, PrepareStepHook as y, TurnResult as z };
921
+ //# sourceMappingURL=types-C7pO0jLq.d.ts.map
@@ -0,0 +1 @@
1
+ @font-face{font-family:Sora;font-style:normal;font-weight:500 600;font-display:block;src:url(../fonts/sora-latin.woff2)format("woff2")}@font-face{font-family:Spline Sans Mono;font-style:normal;font-weight:400 500;font-display:block;src:url(../fonts/spline-sans-mono-latin.woff2)format("woff2")}:root{--ground:#14110c;--ink:#f3f0e9;--ink-bright:#faf7f0;--line-traversed:#8a8478;--line-unbuilt:#514c43;--puck-ring:#b7afa0;--puck-pending:#57524a;--amber:#ffac33;--amber-core:#ffc876;--ember:#e2503e;--unit:8px;--margin:72px;--sans:Sora, "Avenir Next", "Segoe UI", system-ui, sans-serif;--mono:"Spline Sans Mono", ui-monospace, "SF Mono", Menlo, monospace}*{box-sizing:border-box}html,body{background:var(--ground);height:100%;margin:0;padding:0}#root{height:100%}.canvas{background-color:var(--ground);-webkit-font-smoothing:antialiased;text-rendering:optimizelegibility;background-image:radial-gradient(#ffeed40d 1px,#0000 1.2px);background-position:14px 14px;background-size:28px 28px;width:100%;height:100%;position:relative;overflow:hidden}.canvas:after{content:"";pointer-events:none;background:radial-gradient(120% 95% at 50% 44%,#0000 62%,#0503016b 100%);position:absolute;inset:0}.canvas-header{left:var(--margin);right:var(--margin);z-index:2;justify-content:space-between;align-items:baseline;display:flex;position:absolute;top:50px}.run{align-items:baseline;gap:10px;display:flex}.run-key{font:400 12px var(--mono);letter-spacing:.08em;color:#f3f0e966}.run-id{font:600 17px var(--sans);letter-spacing:.01em;color:var(--ink)}.status{font:500 11px var(--mono);letter-spacing:.24em;color:#f6f3eae0;align-items:baseline;margin-left:26px;display:inline-flex}.status-dot{background:#f6f3ea;border-radius:50%;align-self:center;width:5px;height:5px;margin-right:9px;transform:translateY(-1px);box-shadow:0 0 10px 1.5px #fffaee8c}.status-live .status-dot{animation:2.4s ease-in-out infinite status-pulse}.status-offline{color:#f6f3ea61}.status-offline .status-dot{box-shadow:none;background:#f6f3ea61;animation:none}.status-replay,.status-ended{color:#f6f3eae0}.status-replay .status-dot,.status-ended .status-dot{animation:none}.return-live,.pb-button,.td-chip{font:500 11px var(--mono);letter-spacing:.2em;color:#f6f3ea9e;cursor:pointer;background:0 0;border:1px solid #f6f3ea38;border-radius:3px;padding:5px 12px}.return-live{margin-left:16px}.return-live:hover,.pb-button:hover,.td-chip:hover{color:#f6f3eae0;border-color:#f6f3ea66}.stats{font:500 11px var(--mono);letter-spacing:.14em;color:var(--ink);white-space:nowrap;align-items:baseline;gap:5px;display:flex}.stats-value{opacity:.78}.stats-word{opacity:.38}.stats-sep{opacity:.2;padding:0 6px}.stats-scar{color:var(--ember);opacity:1}.stage{z-index:1;width:100%;height:100%;position:absolute;inset:0}.seg{fill:none;stroke-linecap:round;stroke-linejoin:round}.seg-unbuilt{stroke:var(--line-unbuilt);stroke-width:3px;stroke-dasharray:4 9}.seg-traversed{stroke:var(--line-traversed);stroke-width:3.5px}.seg-live-outer{stroke:var(--amber);stroke-width:11px;opacity:.16;filter:url(#glow-4)}.seg-live-inner{stroke:var(--amber);stroke-width:6px;opacity:.32;filter:url(#glow-2)}.seg-live-march{stroke:var(--amber);stroke-width:3.5px;stroke-dasharray:6.5 8;animation:.45s linear infinite march}@keyframes march{to{stroke-dashoffset:-14.5px}}.bloom{fill:url(#bloom)}.halo{fill:url(#halo);animation:2.4s ease-in-out infinite halo-pulse}@keyframes halo-pulse{0%,to{opacity:1}50%{opacity:.62}}.puck{fill:var(--ground);stroke:var(--puck-pending);stroke-width:3px}.node[data-status=done] .puck,.node[data-status=failed] .puck{stroke:var(--puck-ring)}.node[data-status=active] .puck{stroke:var(--amber)}.puck-core{fill:var(--amber-core)}.node[data-status=suspended] .puck{fill:none;stroke:var(--puck-ring)}.pause-bar{stroke:var(--ink-bright);stroke-width:1.8px;stroke-linecap:round}.emit-bloom{fill:var(--ink-bright);opacity:0;filter:url(#glow-4);animation:.2s ease-out emit-bloom}@keyframes emit-bloom{0%{opacity:.85}to{opacity:0}}.meta-check{fill:var(--ink-bright)}.fail-mark{stroke:var(--ember);stroke-width:2px;stroke-linecap:round}.tick{stroke-linecap:round}.tick-done{stroke:#a79f8f;stroke-width:2px;opacity:.9}.tick-live-glow{stroke:var(--amber);stroke-width:2.5px;opacity:.55;filter:url(#glow-2)}.tick-live{stroke:var(--amber);stroke-width:2.2px}.tick-fail{stroke:var(--ember);stroke-width:1.7px;stroke-linecap:round}.tick-decade{font:400 9px var(--mono);letter-spacing:.1em;fill:var(--ink);opacity:.25;text-anchor:middle}.meta-fail{fill:var(--ember)}.scar-mask{fill:var(--ground);stroke:none}.scar-ring{fill:var(--ground);stroke:var(--puck-ring);stroke-width:3px;stroke-dasharray:12 5 10 5 11 10.4}.scar-mark{stroke:var(--ember);stroke-width:2px;stroke-linecap:round}.node[data-scar] .node-name{opacity:.55}.node[data-scar] .node-meta{opacity:.3}.card-title{font:500 11.5px var(--mono);letter-spacing:.1em;fill:var(--ink);opacity:.82}.card-detail{font:400 11.5px var(--mono);letter-spacing:.1em;fill:#8f8b82}.card-fail{fill:var(--ember)}.card-leader{stroke:var(--line-traversed);stroke-width:1px;opacity:.5;fill:none}.card-dot{fill:var(--puck-ring)}.junction .puck{stroke-width:2.5px}.junction[data-status=done] .puck,.junction[data-status=failed] .puck{stroke:var(--puck-ring)}.terminus-ring{fill:none;stroke:var(--puck-pending);stroke-width:1.5px}.node[data-status=done] .terminus-ring{stroke:var(--puck-ring)}.node-name{font:600 15px var(--sans);fill:var(--ink);opacity:.92;text-anchor:middle}.node-meta{font:500 11px var(--mono);letter-spacing:.14em;fill:var(--ink);opacity:.42;text-anchor:middle}.node[data-status=pending] .node-name{opacity:.45}.node[data-status=pending] .node-meta{opacity:.26}.node[data-status=active] .node-name{opacity:1;fill:var(--ink-bright)}.node[data-status=active] .node-meta{opacity:.5}.junction-label{font:500 13px var(--sans);fill:var(--ink);opacity:.55;text-anchor:middle}.junction[data-status=pending] .junction-label{opacity:.35}.group-tick{stroke:var(--ink);stroke-width:1.5px;opacity:.3}.group-text{font:500 11px var(--mono);letter-spacing:.18em;fill:var(--ink);opacity:.35}@keyframes status-pulse{0%,to{opacity:1}50%{opacity:.45}}.scrubber{z-index:2;width:100%;position:absolute;bottom:44px;left:0;right:0}.scrub-spine-traversed{stroke:var(--line-traversed);stroke-width:2px;stroke-linecap:round}.scrub-spine-ahead{stroke:var(--line-unbuilt);stroke-width:2px;stroke-dasharray:4 9;stroke-linecap:round}.scrub-density{fill:var(--ink)}.scrub-fail{stroke:var(--ember);stroke-width:1.6px;stroke-linecap:round}.scrub-playhead{fill:var(--amber)}.scrub-band{fill:#0000;cursor:pointer}.playback{left:var(--margin);z-index:2;gap:8px;display:flex;position:absolute;bottom:12px}.pb-button{min-height:28px;padding:0 14px}.pb-button-play{min-width:84px}.pb-button[data-active]{color:#f6f3eaeb;border-color:#f6f3ea73}.scrubber,.playback,.status,.return-live{transition:opacity .5s}.canvas[data-chrome=hidden] .scrubber,.canvas[data-chrome=hidden] .playback,.canvas[data-chrome=hidden] .status,.canvas[data-chrome=hidden] .return-live{opacity:0;pointer-events:none}.turns-badge{cursor:pointer;outline:none}.turns-badge-box{fill:var(--ground);stroke:#f6f3ea38;stroke-width:1px}.turns-badge-text{font:500 9.5px var(--mono);fill:#f6f3ea9e}.turns-badge:hover .turns-badge-box,.turns-badge:focus-visible .turns-badge-box{stroke:#f6f3ea66}.turns-badge:hover .turns-badge-text,.turns-badge:focus-visible .turns-badge-text{fill:#f6f3eae0}.turns-badge[data-open] .turns-badge-box{stroke:#f6f3ea73}.turns-badge[data-open] .turns-badge-text{fill:#f6f3eaeb}.turns-drawer{z-index:3;background:var(--ground);font-family:var(--mono);color:var(--ink);scrollbar-color:#f3f0e92e transparent;scrollbar-width:thin;border:1px solid #f3f0e91a;border-right:none;flex-direction:column;display:flex;position:absolute;top:92px;bottom:96px;right:0;box-shadow:-32px 0 64px #0503018c}.td-head{justify-content:space-between;align-items:baseline;gap:16px;padding:22px 28px 14px;display:flex}.td-title{align-items:baseline;gap:16px;min-width:0;display:flex}.td-node{font:600 15px var(--sans);color:#f3f0e9eb}.td-meta{font:500 11px var(--mono);letter-spacing:.14em;color:#f3f0e96b;white-space:nowrap}.td-sep{opacity:.5;padding:0 8px}.td-model{letter-spacing:.02em}.td-actions{gap:8px;display:flex}.td-list{border-bottom:1px solid #f3f0e914;max-height:28%;margin:0;padding:4px 28px 14px;list-style:none;overflow-y:auto}.td-turn{width:100%;font:500 11px var(--mono);letter-spacing:.14em;color:#f3f0e973;text-align:left;cursor:pointer;background:0 0;border:none;border-left:1.5px solid #0000;grid-template-columns:88px 240px 1fr;padding:6px 0 6px 12px;display:grid}.td-turn:hover{color:#f3f0e9bf}.td-turn[data-selected]{color:#f3f0e9eb;border-left-color:#f3f0e999}.td-body{flex:1;grid-template-columns:1fr 1fr;min-height:0;display:grid}.td-col{min-width:0;padding:18px 28px 28px;overflow-y:auto}.td-col+.td-col{border-left:1px solid #f3f0e914}.td-sec{font:500 11px var(--mono);letter-spacing:.24em;color:#f3f0e94d;margin:0 0 16px}.td-msg{margin-bottom:20px}.td-msg-head{align-items:baseline;gap:12px;margin-bottom:6px;display:flex}.td-label,.td-flag{font:500 10.5px var(--mono);letter-spacing:.18em;color:#f3f0e961}.td-name-ref{letter-spacing:.02em;color:#f3f0e9b8;margin-left:10px}.td-error{color:var(--ember)}.td-block+.td-block{margin-top:10px}.td-block>.td-label{margin-bottom:4px;display:block}.td-text{white-space:pre-wrap;overflow-wrap:anywhere;font:400 12px/1.6 var(--mono);color:#f3f0e9cc;margin:0}.td-code{color:#f3f0e99e;border-left:1px solid #f3f0e91a;padding-left:12px;font-size:11.5px}.td-fold{font:500 10.5px var(--mono);letter-spacing:.18em;color:#f3f0e973;cursor:pointer;background:0 0;border:none;margin-top:4px;padding:2px 0}.td-fold:hover{color:#f3f0e9cc}.td-tools{font:400 12px/1.6 var(--mono);color:#f3f0e9b8;margin:0}.td-empty{font:500 11px var(--mono);letter-spacing:.18em;color:#f3f0e94d;margin:0}@media (prefers-reduced-motion:reduce){.status-live .status-dot,.seg-live-march,.halo{animation:none}}
@@ -0,0 +1,4 @@
1
+ (function(){let e=document.createElement(`link`).relList;if(e&&e.supports&&e.supports(`modulepreload`))return;for(let e of document.querySelectorAll(`link[rel="modulepreload"]`))n(e);new MutationObserver(e=>{for(let t of e)if(t.type===`childList`)for(let e of t.addedNodes)e.tagName===`LINK`&&e.rel===`modulepreload`&&n(e)}).observe(document,{childList:!0,subtree:!0});function t(e){let t={};return e.integrity&&(t.integrity=e.integrity),e.referrerPolicy&&(t.referrerPolicy=e.referrerPolicy),t.credentials=e.crossOrigin===`use-credentials`?`include`:e.crossOrigin===`anonymous`?`omit`:`same-origin`,t}function n(e){if(e.ep)return;e.ep=!0;let n=t(e);fetch(e.href,n)}})();var e={context:void 0,registry:void 0,effects:void 0,done:!1,getContextId(){return t(this.context.count)},getNextContextId(){return t(this.context.count++)}};function t(t){let n=String(t),r=n.length-1;return e.context.id+(r?String.fromCharCode(96+r):``)+n}function n(t){e.context=t}var r=(e,t)=>e===t,i=Symbol(`solid-track`),a={equals:r},o=null,s=ue,c=1,l=2,u={owned:null,cleanups:null,context:null,owner:null},d=null,f=null,p=null,m=null,h=null,g=0;function _(e,t){let n=p,r=d,i=e.length===0,a=t===void 0?r:t,o=i?u:{owned:null,cleanups:null,context:a?a.context:null,owner:a},s=i?e:()=>e(()=>C(()=>k(o)));d=o,p=null;try{return D(s,!0)}finally{p=n,d=r}}function v(e,t){t=t?Object.assign({},a,t):a;let n={value:e,observers:null,observerSlots:null,comparator:t.equals||void 0};return[ae.bind(n),e=>(typeof e==`function`&&(e=f&&f.running&&f.sources.has(n)?e(n.tValue):e(n.value)),oe(n,e))]}function y(e,t,n){T(se(e,t,!1,c))}function b(e,t,n){s=de;let r=se(e,t,!1,c),i=ie&&ne(ie);i&&(r.suspense=i),(!n||!n.render)&&(r.user=!0),h?h.push(r):T(r)}function x(e,t,n){n=n?Object.assign({},a,n):a;let r=se(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,T(r),ae.bind(r)}function S(e){return D(e,!1)}function C(e){if(p===null)return e();let t=p;p=null;try{return e()}finally{p=t}}function w(e){return d===null||(d.cleanups===null?d.cleanups=[e]:d.cleanups.push(e)),e}var[ee,te]=v(!1);function ne(e){let t;return d&&d.context&&(t=d.context[e.id])!==void 0?t:e.defaultValue}function re(e){let t=x(e),n=x(()=>_e(t()));return n.toArray=()=>{let e=n();return Array.isArray(e)?e:e==null?[]:[e]},n}var ie;function ae(){let e=f&&f.running;if(this.sources&&(e?this.tState:this.state)){if((e?this.tState:this.state)===c)T(this);else{let e=m;m=null,D(()=>O(this),!1),m=e}}if(p){let e=this.observers;if(!e||e[e.length-1]!==p){let t=e?e.length:0;p.sources?(p.sources.push(this),p.sourceSlots.push(t)):(p.sources=[this],p.sourceSlots=[t]),e?(e.push(p),this.observerSlots.push(p.sources.length-1)):(this.observers=[p],this.observerSlots=[p.sources.length-1])}}return e&&f.sources.has(this)?this.tValue:this.value}function oe(e,t,n){let r=f&&f.running&&f.sources.has(e)?e.tValue:e.value;if(!e.comparator||!e.comparator(r,t)){if(f){let r=f.running;(r||!n&&f.sources.has(e))&&(f.sources.add(e),e.tValue=t),r||(e.value=t)}else e.value=t;e.observers&&e.observers.length&&D(()=>{for(let t=0;t<e.observers.length;t+=1){let n=e.observers[t],r=f&&f.running;r&&f.disposed.has(n)||((r?!n.tState:!n.state)&&(n.pure?m.push(n):h.push(n),n.observers&&fe(n)),r?n.tState=c:n.state=c)}if(m.length>1e6)throw m=[],Error()},!1)}return t}function T(e){if(!e.fn)return;k(e);let t=g;E(e,f&&f.running&&f.sources.has(e)?e.tValue:e.value,t),f&&!f.running&&f.sources.has(e)&&queueMicrotask(()=>{D(()=>{f&&(f.running=!0),p=d=e,E(e,e.tValue,t),p=d=null},!1)})}function E(e,t,n){let r,i=d,a=p;p=d=e;try{r=e.fn(t)}catch(t){return e.pure&&(f&&f.running?(e.tState=c,e.tOwned&&e.tOwned.forEach(k),e.tOwned=void 0):(e.state=c,e.owned&&e.owned.forEach(k),e.owned=null)),e.updatedAt=n+1,ge(t)}finally{p=a,d=i}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&`observers`in e?oe(e,r,!0):f&&f.running&&e.pure?(f.sources.has(e)||(e.value=r),f.sources.add(e),e.tValue=r):e.value=r,e.updatedAt=n)}function se(e,t,n,r=c,i){let a={fn:e,state:r,updatedAt:null,owned:null,sources:null,sourceSlots:null,cleanups:null,value:t,owner:d,context:d?d.context:null,pure:n};return f&&f.running&&(a.state=0,a.tState=r),d===null||d!==u&&(f&&f.running&&d.pure?d.tOwned?d.tOwned.push(a):d.tOwned=[a]:d.owned?d.owned.push(a):d.owned=[a]),a}function ce(e){let t=f&&f.running;if((t?e.tState:e.state)===0)return;if((t?e.tState:e.state)===l)return O(e);if(e.suspense&&C(e.suspense.inFallback))return e.suspense.effects.push(e);let n=[e];for(;(e=e.owner)&&(!e.updatedAt||e.updatedAt<g);){if(t&&f.disposed.has(e))return;(t?e.tState:e.state)&&n.push(e)}for(let r=n.length-1;r>=0;r--){if(e=n[r],t){let t=e,i=n[r+1];for(;(t=t.owner)&&t!==i;)if(f.disposed.has(t))return}if((t?e.tState:e.state)===c)T(e);else if((t?e.tState:e.state)===l){let t=m;m=null,D(()=>O(e,n[0]),!1),m=t}}}function D(e,t){if(m)return e();let n=!1;t||(m=[]),h?n=!0:h=[],g++;try{let t=e();return le(n),t}catch(e){n||(h=null),m=null,ge(e)}}function le(e){if(m&&=(ue(m),null),e)return;let t;if(f){if(!f.promises.size&&!f.queue.size){let e=f.sources,n=f.disposed;h.push.apply(h,f.effects),t=f.resolve;for(let e of h)`tState`in e&&(e.state=e.tState),delete e.tState;f=null,D(()=>{for(let e of n)k(e);for(let t of e){if(t.value=t.tValue,t.owned)for(let e=0,n=t.owned.length;e<n;e++)k(t.owned[e]);t.tOwned&&(t.owned=t.tOwned),delete t.tValue,delete t.tOwned,t.tState=0}te(!1)},!1)}else if(f.running){f.running=!1,f.effects.push.apply(f.effects,h),h=null,te(!0);return}}let n=h;h=null,n.length&&D(()=>s(n),!1),t&&t()}function ue(e){for(let t=0;t<e.length;t++)ce(e[t])}function de(t){let r,i=0;for(r=0;r<t.length;r++){let e=t[r];e.user?t[i++]=e:ce(e)}if(e.context){if(e.count){e.effects||=[],e.effects.push(...t.slice(0,i));return}n()}for(e.effects&&(e.done||!e.count)&&(t=[...e.effects,...t],i+=e.effects.length,delete e.effects),r=0;r<i;r++)ce(t[r])}function O(e,t){let n=f&&f.running;n?e.tState=0:e.state=0;for(let r=0;r<e.sources.length;r+=1){let i=e.sources[r];if(i.sources){let e=n?i.tState:i.state;e===c?i!==t&&(!i.updatedAt||i.updatedAt<g)&&ce(i):e===l&&O(i,t)}}}function fe(e){let t=f&&f.running;for(let n=0;n<e.observers.length;n+=1){let r=e.observers[n];(t?!r.tState:!r.state)&&(t?r.tState=l:r.state=l,r.pure?m.push(r):h.push(r),r.observers&&fe(r))}}function k(e){let t;if(e.sources)for(;e.sources.length;){let t=e.sources.pop(),n=e.sourceSlots.pop(),r=t.observers;if(r&&r.length){let e=r.pop(),i=t.observerSlots.pop();n<r.length&&(e.sourceSlots[i]=n,r[n]=e,t.observerSlots[n]=i)}}if(e.tOwned){for(t=e.tOwned.length-1;t>=0;t--)k(e.tOwned[t]);delete e.tOwned}if(f&&f.running&&e.pure)pe(e,!0);else if(e.owned){for(t=e.owned.length-1;t>=0;t--)k(e.owned[t]);e.owned=null}if(e.cleanups){for(t=e.cleanups.length-1;t>=0;t--)e.cleanups[t]();e.cleanups=null}f&&f.running?e.tState=0:e.state=0}function pe(e,t){if(t||(e.tState=0,f.disposed.add(e)),e.owned)for(let t=0;t<e.owned.length;t++)pe(e.owned[t])}function me(e){return e instanceof Error?e:Error(typeof e==`string`?e:`Unknown error`,{cause:e})}function he(e,t,n){try{for(let n of t)n(e)}catch(e){ge(e,n&&n.owner||null)}}function ge(e,t=d){let n=o&&t&&t.context&&t.context[o],r=me(e);if(!n)throw r;h?h.push({fn(){he(r,n,t)},state:c}):he(r,n,t)}function _e(e){if(typeof e==`function`&&!e.length)return _e(e());if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=_e(e[n]);if(Array.isArray(r)){if(r.length<32768)t.push.apply(t,r);else for(let e=0;e<r.length;e++)t.push(r[e])}else t.push(r)}return t}return e}var ve=Symbol(`fallback`);function ye(e){for(let t=0;t<e.length;t++)e[t]()}function be(e,t,n={}){let r=[],a=[],o=[],s=0,c=t.length>1?[]:null;return w(()=>ye(o)),()=>{let l=e()||[],u=l.length,d,f;return l[i],C(()=>{let e,t,i,m,h,g,v,y,b;if(u===0)s!==0&&(ye(o),o=[],r=[],a=[],s=0,c&&=[]),n.fallback&&(r=[ve],a[0]=_(e=>(o[0]=e,n.fallback())),s=1);else if(s===0){for(a=Array(u),f=0;f<u;f++)r[f]=l[f],a[f]=_(p);s=u}else{for(i=Array(u),m=Array(u),c&&(h=Array(u)),g=0,v=Math.min(s,u);g<v&&r[g]===l[g];g++);for(v=s-1,y=u-1;v>=g&&y>=g&&r[v]===l[y];v--,y--)i[y]=a[v],m[y]=o[v],c&&(h[y]=c[v]);for(e=new Map,t=Array(y+1),f=y;f>=g;f--)b=l[f],d=e.get(b),t[f]=d===void 0?-1:d,e.set(b,f);for(d=g;d<=v;d++)b=r[d],f=e.get(b),f!==void 0&&f!==-1?(i[f]=a[d],m[f]=o[d],c&&(h[f]=c[d]),f=t[f],e.set(b,f)):o[d]();for(f=g;f<u;f++)f in i?(a[f]=i[f],o[f]=m[f],c&&(c[f]=h[f],c[f](f))):a[f]=_(p);a=a.slice(0,s=u),r=l.slice(0)}return a});function p(e){if(o[f]=e,c){let[e,n]=v(f);return c[f]=n,t(l[f],e)}return t(l[f])}}}function xe(e,t,n={}){let r=[],a=[],o=[],s=[],c=0,l;return w(()=>ye(o)),()=>{let u=e()||[],d=u.length;return u[i],C(()=>{if(d===0)return c!==0&&(ye(o),o=[],r=[],a=[],c=0,s=[]),n.fallback&&(r=[ve],a[0]=_(e=>(o[0]=e,n.fallback())),c=1),a;for(r[0]===ve&&(o[0](),o=[],r=[],a=[],c=0),l=0;l<d;l++)l<r.length&&r[l]!==u[l]?s[l](()=>u[l]):l>=r.length&&(a[l]=_(f));for(;l<r.length;l++)o[l]();return c=s.length=o.length=d,r=u.slice(0),a=a.slice(0,c)});function f(e){o[l]=e;let[n,r]=v(u[l]);return s[l]=r,t(n,l)}}}function A(e,t){return C(()=>e(t||{}))}var Se=e=>`Stale read from <${e}>.`;function j(e){let t=`fallback`in e&&{fallback:()=>e.fallback};return x(be(()=>e.each,e.children,t||void 0))}function M(e){let t=`fallback`in e&&{fallback:()=>e.fallback};return x(xe(()=>e.each,e.children,t||void 0))}function N(e){let t=e.keyed,n=x(()=>e.when,void 0,void 0),r=t?n:x(n,void 0,{equals:(e,t)=>!e==!t});return x(()=>{let i=r();if(i){let a=e.children;return typeof a==`function`&&a.length>0?C(()=>a(t?i:()=>{if(!C(r))throw Se(`Show`);return n()})):a}return e.fallback},void 0,void 0)}function Ce(e){let t=re(()=>e.children),n=x(()=>{let e=t(),n=Array.isArray(e)?e:[e],r=()=>void 0;for(let e=0;e<n.length;e++){let t=e,i=n[e],a=r,o=x(()=>a()?void 0:i.when,void 0,void 0),s=i.keyed?o:x(o,void 0,{equals:(e,t)=>!e==!t});r=()=>a()||(s()?[t,o,i]:void 0)}return r});return x(()=>{let t=n()();if(!t)return e.fallback;let[r,i,a]=t,o=a.children;return typeof o==`function`&&o.length>0?C(()=>o(a.keyed?i():()=>{if(C(n)()?.[0]!==r)throw Se(`Match`);return i()})):o},void 0,void 0)}function we(e){return e}var Te=e=>x(()=>e());function Ee(e,t,n){let r=n.length,i=t.length,a=r,o=0,s=0,c=t[i-1].nextSibling,l=null;for(;o<i||s<a;)if(t[o]===n[s])o++,s++;else{for(;t[i-1]===n[a-1];)i--,a--;if(i===o){let t=a<r?s?n[s-1].nextSibling:n[a-s]:c;for(;s<a;)e.insertBefore(n[s++],t)}else if(a===s)for(;o<i;)(!l||!l.has(t[o]))&&t[o].remove(),o++;else if(t[o]===n[a-1]&&n[s]===t[i-1]){let r=t[--i].nextSibling;e.insertBefore(n[s++],t[o++].nextSibling),e.insertBefore(n[--a],r),t[i]=n[a]}else{if(!l){l=new Map;let e=s;for(;e<a;)l.set(n[e],e++)}let r=l.get(t[o]);if(r!=null){if(s<r&&r<a){let c=o,u=1,d;for(;++c<i&&c<a&&(d=l.get(t[c]))!=null&&d===r+u;)u++;if(u>r-s){let i=t[o];for(;s<r;)e.insertBefore(n[s++],i)}else e.replaceChild(n[s++],t[o++])}else o++}else t[o++].remove()}}}var De=`_$DX_DELEGATE`;function Oe(e,t,n,r={}){let i;return _(r=>{i=r,t===document?e():I(t,e(),!n&&t.firstChild?null:void 0,n)},r.owner),()=>{i(),t.textContent=``}}function P(e,t,n,r){let i,a=()=>{let t=r?document.createElementNS(`http://www.w3.org/1998/Math/MathML`,`template`):document.createElement(`template`);return t.innerHTML=e,n?t.content.firstChild.firstChild:r?t.firstChild:t.content.firstChild},o=t?()=>C(()=>document.importNode(i||=a(),!0)):()=>(i||=a()).cloneNode(!0);return o.cloneNode=o,o}function ke(e,t=window.document){let n=t[De]||(t[De]=new Set);for(let r=0,i=e.length;r<i;r++){let i=e[r];n.has(i)||(n.add(i),t.addEventListener(i,Ne))}}function F(e,t,n){Me(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function Ae(e,t){Me(e)||(t==null?e.removeAttribute(`class`):e.className=t)}function je(e,t,n){n==null?e.style.removeProperty(t):e.style.setProperty(t,n)}function I(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!=`function`)return Pe(e,t,r,n);y(r=>Pe(e,t(),r,n),r)}function Me(t){return!!e.context&&!e.done&&(!t||t.isConnected)}function Ne(t){if(e.registry&&e.events&&e.events.find(([e,n])=>n===t))return;let n=t.target,r=`$$${t.type}`,i=t.target,a=t.currentTarget,o=e=>Object.defineProperty(t,"target",{configurable:!0,value:e}),s=()=>{let e=n[r];if(e&&!n.disabled){let i=n[`${r}Data`];if(i===void 0?e.call(n,t):e.call(n,i,t),t.cancelBubble)return}return n.host&&typeof n.host!=`string`&&!n.host._$host&&n.contains(t.target)&&o(n.host),!0},c=()=>{for(;s()&&(n=n._$host||n.parentNode||n.host););};Object.defineProperty(t,"currentTarget",{configurable:!0,get(){return n||document}}),e.registry&&!e.done&&(e.done=_$HY.done=!0);try{if(t.composedPath){let e=t.composedPath();o(e[0]);for(let t=0;t<e.length-2&&(n=e[t],s());t++){if(n._$host){n=n._$host,c();break}if(n.parentNode===a)break}}else c();o(i)}finally{t=n=null}}function Pe(e,t,n,r,i){let a=Me(e);if(a){!n&&(n=[...e.childNodes]);let t=[];for(let e=0;e<n.length;e++){let r=n[e];r.nodeType===8&&r.data.slice(0,2)===`!$`?r.remove():t.push(r)}n=t}for(;typeof n==`function`;)n=n();if(t===n)return n;let o=typeof t,s=r!==void 0;if(e=s&&n[0]&&n[0].parentNode||e,o===`string`||o===`number`){if(a||o===`number`&&(t=t.toString(),t===n))return n;if(s){let i=n[0];i&&i.nodeType===3?i.data!==t&&(i.data=t):i=document.createTextNode(t),n=L(e,n,r,i)}else n=n!==``&&typeof n==`string`?e.firstChild.data=t:e.textContent=t}else if(t==null||o===`boolean`){if(a)return n;n=L(e,n,r)}else if(o===`function`)return y(()=>{let i=t();for(;typeof i==`function`;)i=i();n=Pe(e,i,n,r)}),()=>n;else if(Array.isArray(t)){let o=[],c=n&&Array.isArray(n);if(Fe(o,t,n,i))return y(()=>n=Pe(e,o,n,r,!0)),()=>n;if(a){if(!o.length)return n;if(r===void 0)return n=[...e.childNodes];let t=o[0];if(t.parentNode!==e)return n;let i=[t];for(;(t=t.nextSibling)!==r;)i.push(t);return n=i}if(o.length===0){if(n=L(e,n,r),s)return n}else c?n.length===0?Ie(e,o,r):Ee(e,n,o):(n&&L(e),Ie(e,o));n=o}else if(t.nodeType){if(a&&t.parentNode)return n=s?[t]:t;if(Array.isArray(n)){if(s)return n=L(e,n,r,t);L(e,n,null,t)}else n==null||n===``||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}return n}function Fe(e,t,n,r){let i=!1;for(let a=0,o=t.length;a<o;a++){let o=t[a],s=n&&n[e.length],c;if(o!=null&&o!==!0&&o!==!1){if((c=typeof o)==`object`&&o.nodeType)e.push(o);else if(Array.isArray(o))i=Fe(e,o,s)||i;else if(c===`function`){if(r){for(;typeof o==`function`;)o=o();i=Fe(e,Array.isArray(o)?o:[o],Array.isArray(s)?s:[s])||i}else e.push(o),i=!0}else{let t=String(o);s&&s.nodeType===3&&s.data===t?e.push(s):e.push(document.createTextNode(t))}}}return i}function Ie(e,t,n=null){for(let r=0,i=t.length;r<i;r++)e.insertBefore(t[r],n)}function L(e,t,n,r){if(n===void 0)return e.textContent=``;let i=r||document.createTextNode(``);if(t.length){let r=!1;for(let a=t.length-1;a>=0;a--){let o=t[a];if(i!==o){let t=o.parentNode===e;!r&&!a?t?e.replaceChild(i,o):e.insertBefore(i,n):t&&o.remove()}else r=!0}}else e.insertBefore(i,n);return[i]}var Le=2e3,Re=1e3;function ze(e,t){let{speed:n,floor_ms:r,cap_ms:i}=t,a=[],o=0,s=null;for(let t of e){if(s!==null){let e=t-s,a=(e>0?Math.max(e,r):0)/n;o+=i===null?a:Math.min(a,i)}a.push(o),s=t}return{wall_times:a,wall_total_ms:o}}function Be(e,t){return ze(e,{speed:t.speed,floor_ms:Re,cap_ms:t.compress?Le:null})}function Ve(e,t,n){let{wall_times:r,wall_total_ms:i}=e,a=r.length;if(a===0)return{index:0,t_plus_ms:0,done:!0};let o=Math.max(0,n);if(o>=i)return{index:a-1,t_plus_ms:t[a-1]??0,done:!0};let s=0;for(let e=1;e<a&&!((r[e]??0)>o);e+=1)s=e;let c=r[s]??0,l=r[s+1]??i,u=t[s]??0,d=t[s+1]??u,f=(o-c)/(l-c);return{index:s,t_plus_ms:u+f*(d-u),done:!1}}var He={playing:!1,stepping:!1,speed:1,compress:!0,loop:!1,anchor_index:0,anchor_now_ms:0};function Ue(e,t,n,r){if(e.playing)return{...e,playing:!1};if(n<2)return e;let i=t===null||t>=n-1;return{...e,playing:!0,anchor_index:i?0:t,anchor_now_ms:r}}function We(e,t,n){let r=e.speed===1?2:e.speed===2?3:1;return et({...e,speed:r},t,n)}function Ge(e,t,n){return et({...e,compress:!e.compress},t,n)}function Ke(e){return e.stepping?{...e,stepping:!1}:{...e,stepping:!0,playing:!1}}function qe(e,t){return e===null||e>=t-1?0:e}function Je(e){return e.stepping?`NEXT`:e.playing?`PAUSE`:`PLAY`}function Ye(e){return{...e,loop:!e.loop}}function Xe(e,t,n){return et(e,t,n)}function Ze(e){return e.playing?{...e,playing:!1}:e}function Qe(e,t,n){return(e.wall_times[t.anchor_index]??0)+(n-t.anchor_now_ms)}function $e(e,t,n){return e.playing&&n-t>=2500}function et(e,t,n){return e.playing?{...e,anchor_index:t,anchor_now_ms:n}:e}var tt=P(`<button type=button>`),nt=P(`<div class=playback data-testid=playback>`);function R(e){return(()=>{var t=tt();return t.$$click=()=>e.on_click(),I(t,()=>e.label),y(n=>{var r=e.play?`pb-button pb-button-play`:`pb-button`,i=e.testid,a=e.active?`true`:void 0;return r!==n.e&&Ae(t,n.e=r),i!==n.t&&F(t,`data-testid`,n.t=i),a!==n.a&&F(t,`data-active`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}function rt(e){return(()=>{var t=nt();return I(t,A(R,{testid:`play-toggle`,get label(){return Je(e.playback)},play:!0,get on_click(){return e.on_play_chip}}),null),I(t,A(R,{testid:`step-toggle`,label:`STEP`,get active(){return e.playback.stepping},get on_click(){return e.on_toggle_step}}),null),I(t,A(R,{testid:`speed`,get label(){return`${e.playback.speed}X`},get on_click(){return e.on_cycle_speed}}),null),I(t,A(R,{testid:`compress-toggle`,label:`COMPRESS`,get active(){return e.playback.compress},get on_click(){return e.on_toggle_compress}}),null),I(t,A(R,{testid:`loop-toggle`,label:`LOOP`,get active(){return e.playback.loop},get on_click(){return e.on_toggle_loop}}),null),I(t,A(R,{testid:`density-toggle`,label:`DENSITY`,get active(){return e.density},get on_click(){return e.on_toggle_density}}),null),t})()}ke([`click`]);function it(e){let{fold_t_plus_ms:t,run_over:n,connected:r,received_at_ms:i,now_ms:a}=e;return n||!r||i===null?t:t+Math.max(0,a-i)}var at=8,ot=`·`.repeat(at);function st(e){return e.slice(0,at)}var ct={connecting:`CONNECTING`,offline:`OFFLINE`},lt={done:`DONE`,failed:`FAILED`,aborted:`ABORTED`,suspended:`SUSPENDED`};function ut(e,t){return e===`live`?t===null?{label:`LIVE`,tone:`live`}:{label:lt[t],tone:`ended`}:{label:ct[e],tone:`offline`}}function dt(e){let t=Math.max(0,Math.floor(e));if(t<1e3)return`${t}MS`;if(t<6e4)return`${(Math.floor(t/10)/100).toFixed(2)}S`;let n=Math.floor(t/6e4),r=Math.floor(t%6e4/1e3);return`${n}M${String(r).padStart(2,`0`)}S`}function ft(e){return`T+${dt(e)}`}function pt(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function mt(e){return e===1?`RETRY`:`RETRIES`}var z={text:`·`,role:`sep`};function ht(e){if(e.cached_input_tokens+e.cache_write_tokens<=0)return;let t=e.input_tokens>0?e.cached_input_tokens/e.input_tokens:0;return`${String(Math.round(t*100))}%`}function gt(e){return e===1?`MISS`:`MISSES`}function _t(e){if(e===void 0)return[];let t=ht(e);if(t===void 0)return[];let n=[z,{text:`CACHE`,role:`word`},{text:t,role:`value`}];return e.misses>0&&n.push(z,{text:String(e.misses),role:`value`},{text:gt(e.misses),role:`word`}),n}function vt(e){return[{text:ft(e.t_plus_ms),role:`value`},z,{text:String(e.retries_absorbed),role:`value`},{text:`${mt(e.retries_absorbed)} ABSORBED`,role:`word`},z,{text:`SCARS`,role:`word`},{text:String(e.scars),role:e.scars>0?`scar`:`value`},..._t(e.cache),z,{text:pt(e.cost_usd),role:`value`}]}var B={status:`pending`,occurrences:[],scarred:!1,suspended:!1,turn_retries:0,cost_usd:0,emits:0,checkpoint:null};function yt(e){let t={kinds:new Map,nodes:new Map,seats:new Map};return e!==null&&bt(e,t),{run_id:null,run_status:null,t0_ts:null,last_ts:null,retries_absorbed:0,scars:0,cost_usd:0,unattributed_usd:0,input_tokens:0,cached_input_tokens:0,cache_write_tokens:0,cache_misses:0,nodes:t.nodes,spans:new Map,open_spans:[],kinds:t.kinds,seats:t.seats}}function bt(e,t){t.kinds.has(e.id)||(t.kinds.set(e.id,e.kind),t.nodes.set(e.id,B),e.children!==void 0&&t.seats.set(e.id,xt(e.children)));for(let n of e.children??[])bt(n,t)}function xt(e){let t=new Map;for(let n of e){let e=n.step_id??n.id;t.set(e,[...t.get(e)??[],n.id])}return t}function St(e){return e.t0_ts===null||e.last_ts===null?0:Math.max(0,e.last_ts-e.t0_ts)}function Ct(e,t){if(!wt(t))return e;let n=t,r=H(n,`ts`),i={...e,run_id:e.run_id??V(n,`run_id`),t0_ts:e.t0_ts??r,last_ts:r??e.last_ts};switch(n.kind){case`span_start`:return Tt(i,n,r);case`span_end`:return Dt(i,n,r);case`suspended`:return Mt(i,n);case`emit`:return Pt(i,n);case`checkpoint`:return It(i,n);case`turn_retry`:return Lt(i,n);case`cost`:return Rt(i,n);case`response_received`:return zt(i,n);case`cache_miss`:return{...i,cache_misses:i.cache_misses+1};case`run_end`:return Vt(i,n);default:return i}}function wt(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:typeof e.kind==`string`}function V(e,t){let n=e[t];return typeof n==`string`?n:null}function H(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Tt(e,t,n){let r=V(t,`span_id`),i=V(t,`name`);if(r===null||i===null)return e;let a=V(t,`parent_span_id`),o=V(t,`id`),s=o===null?null:Et(e,o,a),c=new Map(e.spans);c.set(r,{name:i,step_id:o,node_id:s,parent_span_id:a,open:!0,failed_descendant:!1,failed_joined_descendant:!1});let l={...e,spans:c,open_spans:[...e.open_spans,r]};if(s===null)return l;let u=e.nodes.get(s)??B,d={span_id:r,parent_span_id:a,status:`active`,started_ts:n,ended_ts:null,error:null},f=new Map(e.nodes);return f.set(s,Ht({...u,occurrences:[...u.occurrences,d],suspended:!1})),{...l,nodes:f}}function Et(e,t,n){let r=Kt(e,n),i=r===null?void 0:e.seats.get(r)?.get(t);if(i===void 0)return t;let a=0;for(let r of e.spans.values())r.parent_span_id===n&&r.step_id===t&&(a+=1);return i[a%i.length]??t}function Dt(e,t,n){let r=V(t,`span_id`);if(r===null)return e;let i=e.spans.get(r);if(i===void 0||!i.open)return e;let a=t.error!==void 0,o=Ot(e,r,i,a),s=new Map(o.nodes),c=kt(o,r,i,a,n,V(t,`error`)),l={scars:o.scars,retries_absorbed:o.retries_absorbed};if(a){let e=At(o,i,c,l);c=e.node,l={scars:e.scars,retries_absorbed:e.retries_absorbed}}return c!==void 0&&i.node_id!==null&&s.set(i.node_id,Ht(c)),a&&(l=jt(o,r,i,s,l)),{...o,nodes:s,...l}}function Ot(e,t,n,r){let i=new Map(e.spans);if(i.set(t,{...n,open:!1}),r&&n.parent_span_id!==null){let e=i.get(n.parent_span_id);e!==void 0&&i.set(n.parent_span_id,{...e,failed_descendant:!0,failed_joined_descendant:e.failed_joined_descendant||n.node_id!==null||n.failed_joined_descendant})}return{...e,spans:i,open_spans:e.open_spans.filter(e=>e!==t)}}function kt(e,t,n,r,i,a){if(n.node_id===null)return;let o=e.nodes.get(n.node_id);if(o===void 0)return;let s=r?`failed`:`done`;return{...o,occurrences:o.occurrences.map(e=>e.span_id===t?{...e,status:s,ended_ts:i,error:a}:e)}}function At(e,t,n,r){if(n?.suspended===!0)return{...r,node:n};if(Gt(e,t)){let e=+!t.failed_descendant;return{...r,retries_absorbed:r.retries_absorbed+e,node:n}}return n===void 0||t.failed_joined_descendant||n.scarred?{...r,node:n}:{...r,scars:r.scars+1,node:{...n,scarred:!0}}}function jt(e,t,n,r,i){if(Wt(e,n)!==`retry`||Gt(e,n))return i;let a=qt(r,t);return a===null||a.node.scarred?i:(r.set(a.id,{...a.node,scarred:!0}),{scars:i.scars+1,retries_absorbed:Math.max(0,i.retries_absorbed-1)})}function Mt(e,t){let n=V(t,`step_id`);if(n===null)return e;let r=Nt(e,n),i=e.nodes.get(r)??B,a=new Map(e.nodes);return a.set(r,Ht({...i,suspended:!0})),{...e,nodes:a}}function Nt(e,t){for(let n of e.spans.values())if(n.open&&n.step_id===t)return n.node_id??t;return t}function Pt(e,t){let n=Kt(e,V(t,`span_id`));if(n===null)return e;let r=e.nodes.get(n)??B,i=new Map(e.nodes);return i.set(n,{...r,emits:r.emits+1}),{...e,nodes:i}}function Ft(e){return e===`hit`||e===`miss`||e===`read_error`||e===`write_error`}function It(e,t){let n=V(t,`id`),r=V(t,`status`);if(n===null||r===null||!Ft(r))return e;let i=Nt(e,n),a=e.nodes.get(i)??B,o=new Map(e.nodes);return o.set(i,{...a,checkpoint:r}),{...e,nodes:o}}function Lt(e,t){let n=e.retries_absorbed+1,r=Kt(e,V(t,`span_id`));if(r===null)return{...e,retries_absorbed:n};let i=e.nodes.get(r)??B,a=new Map(e.nodes);return a.set(r,{...i,turn_retries:i.turn_retries+1}),{...e,retries_absorbed:n,nodes:a}}function Rt(e,t){let n=H(t,`total_usd`);if(n===null)return e;let r=e.cost_usd+n,i=Kt(e,V(t,`span_id`));if(i===null)return{...e,cost_usd:r,unattributed_usd:e.unattributed_usd+n};let a=e.nodes.get(i)??B,o=new Map(e.nodes);return o.set(i,{...a,cost_usd:a.cost_usd+n}),{...e,cost_usd:r,nodes:o}}function zt(e,t){return{...e,input_tokens:e.input_tokens+(H(t,`input_tokens`)??0),cached_input_tokens:e.cached_input_tokens+(H(t,`cached_input_tokens`)??0),cache_write_tokens:e.cache_write_tokens+(H(t,`cache_write_tokens`)??0)}}function Bt(e){return e===`done`||e===`failed`||e===`aborted`||e===`suspended`}function Vt(e,t){let n=V(t,`status`);return n===null||!Bt(n)?e:{...e,run_status:n}}function Ht(e){return{...e,status:Ut(e)}}function Ut(e){if(e.suspended)return`suspended`;if(e.occurrences.some(e=>e.status===`active`))return`active`;let t=e.occurrences[e.occurrences.length-1];return t===void 0?`pending`:t.status===`failed`?`failed`:`done`}function Wt(e,t){if(t.node_id!==null){let n=e.kinds.get(t.node_id);if(n!==void 0)return n}return t.name}function Gt(e,t){let n=e.spans.size+1,r=t.parent_span_id;for(;r!==null&&n>0;){--n;let t=e.spans.get(r);if(t===void 0)return!1;if(t.open&&Wt(e,t)===`retry`)return!0;r=t.parent_span_id}return!1}function Kt(e,t){let n=t??e.open_spans[e.open_spans.length-1]??null;if(n===null)return null;let r=e.spans.size+1,i=e.spans.get(n);for(;i!==void 0&&r>0;){if(--r,i.node_id!==null)return i.node_id;if(i.parent_span_id===null)return null;i=e.spans.get(i.parent_span_id)}return null}function qt(e,t){for(let[n,r]of e){let e=r.occurrences[r.occurrences.length-1];if(e?.status===`failed`&&e.parent_span_id===t)return{id:n,node:r}}return null}var U={margin:72,branch_pitch:92,corner_radius:24,label_clear:16,name_drop:38,meta_drop:20,group_label_rise:52,group_tick_length:14,tick_pitch:30,comb_pitch:18,decade:10,decade_gap:8,node_pitch:128,entry_stub:28,lane_lead:56,junction_gap:36,junction_label_drop:37,loop_radius:46,basin_radius:32,basin_shoulder:108,basin_drop:92,group_text_indent:22,tick_lead:72,tick_reserve:160,puck_radius:7,junction_radius:5.5,terminus_radius:6.5,terminus_ring_radius:12,name_px:15,min_name_px:11},Jt=U.min_name_px/U.name_px,Yt=10,Xt=4,Zt=11,Qt=U.name_drop+U.meta_drop+Xt,W=4,$t=U.group_label_rise+Zt,en=U.label_clear+Zt,tn=U.junction_label_drop+Xt,nn=U.basin_drop+W+Xt,rn=40,an=40,on=8,sn=new Set([`parallel`,`branch`]),cn=new Set([`retry`,`loop`]);function ln(e){let t={nodes:[],junctions:[],segments:[],group_labels:[],tick_lanes:[]};if(e===null)return{width:2*U.margin,height:2*U.margin,spine_y:U.margin,...t};let n=un(e),r=U.margin+n.above,i=U.margin+U.entry_stub;return t.segments.push({role:`entry`,from:null,to:n.id,path:`M ${U.margin} ${r} H ${i}`}),n.place(i,r,t,0),Tn(t,n.exit_glyph),{width:i+n.width+U.margin,height:r+n.below+U.margin,spine_y:r,...t}}function un(e,t){let n=(e.children??[]).map((t,n)=>un(t,dn(e,n)));return sn.has(e.kind)&&n.length>0?yn(e,n):cn.has(e.kind)?bn(e,n):e.kind===`fallback`&&n.length>=2?Cn(e,n):e.kind===`map`?wn(e,n):n.length>0?{id:e.id,...mn(n)}:pn(e,t)}function dn(e,t){return e.kind===`loop`&&t===1?`guard`:void 0}function fn(e,t){for(let t of[e.config?.display_name,e.meta?.name])if(typeof t==`string`&&t.length>0)return t;return e.anonymous===!0?t??e.kind:e.step_id??e.id}function pn(e,t){return{id:e.id,width:0,above:Yt,below:Qt,exit_glyph:e.id,place:(n,r,i,a)=>{let o=r+a+U.name_drop;i.nodes.push({id:e.id,kind:e.kind,label:fn(e,t),center:{x:n,y:r},radius:U.puck_radius,terminus:!1,name_anchor:{x:n,y:o},meta_anchor:{x:n,y:o+U.meta_drop}})}}}function mn(e){let t=U.node_pitch*Math.max(0,e.length-1),n=e.reduce((e,t)=>e+t.width,t),r=null;for(let t of e)r=t.exit_glyph??r;return{width:n,above:e.reduce((e,t)=>Math.max(e,t.above),0),below:e.reduce((e,t)=>Math.max(e,t.below),0),exit_glyph:r,place:(t,n,r,i)=>{let a=t,o=null;for(let t of e)o!==null&&(r.segments.push({role:`line`,from:o.id,to:t.id,path:`M ${a} ${n} H ${a+U.node_pitch}`}),a+=U.node_pitch),t.place(a,n,r,i),a+=t.width,o=t}}}function hn(e){let t=(e-1)/2,n=[];for(let r=0;r<e;r+=1){let e=r-t,i=Number.isInteger(e)?e:e+.5*Math.sign(e);n.push(i*U.branch_pitch)}return n}function gn(e){let t=hn(e.length),n=[],r=0,i=null;for(let[a,o]of e.entries()){let e=(t[a]??0)+r;if(i!==null){let t=i.box.below+o.above+U.label_clear,n=e-i.offset;n<t&&(r+=t-n,e+=t-n)}n.push(e),i={box:o,offset:e}}let a=Math.round(((n[0]??0)+(n[n.length-1]??0))/2);return n.map(e=>e-a)}function _n(e,t,n,r){if(r===t)return`M ${e} ${t} H ${n}`;let i=U.corner_radius,a=e+i,o=r>t?1:-1;return`M ${e} ${t} Q ${a} ${t} ${a} ${t+o*i} L ${a} ${r-o*i} Q ${a} ${r} ${a+i} ${r} H ${n}`}function vn(e,t,n,r){let i=U.corner_radius;if(n===r)return`M ${e} ${r} H ${t+2*i}`;let a=t+i,o=n>r?-1:1;return`M ${e} ${n} H ${t} Q ${a} ${n} ${a} ${n+o*i} L ${a} ${r-o*i} Q ${a} ${r} ${a+i} ${r}`}function yn(e,t){let n=gn(t),r=2*U.corner_radius,i=t.reduce((e,t)=>Math.max(e,t.width),0),a=`${e.id}:junction`,o=n[0]??0,s=n[n.length-1]??0,c=t[0],l=t[t.length-1];return{id:e.id,width:r+U.lane_lead+i+U.lane_lead+r+U.junction_gap,above:-o+Math.max(c?.above??0,$t),below:Math.max(s+(l?.below??0),tn),exit_glyph:null,place:(s,c,l)=>{let u=s+r+U.lane_lead,d=u+i+U.lane_lead,f=d+r,p=f+U.junction_gap;for(let[r,i]of t.entries()){let t=c+(n[r]??0);l.segments.push({role:`branch_in`,from:e.id,to:i.id,path:_n(s,c,u,t)}),i.place(u,t,l,0),l.segments.push({role:`branch_out`,from:i.id,to:a,path:vn(u+i.width,d,t,c)})}l.segments.push({role:`line`,from:e.id,to:a,path:`M ${f} ${c} H ${p}`}),l.junctions.push({id:a,owner:e.id,center:{x:p,y:c},radius:U.junction_radius,label_anchor:{x:p,y:c+U.junction_label_drop}});let m=c+o-U.group_label_rise;l.group_labels.push({owner:e.id,tick:{x:s+U.corner_radius,y:m-W},text_anchor:{x:s+U.corner_radius+U.group_text_indent,y:m}})}}}function bn(e,t){let n=mn(t);if(n.width>0)return xn(e,n);let r=U.loop_radius,i=t[0]?.id??e.id;return{id:e.id,width:2*r,above:r+en,below:r+Qt,exit_glyph:n.exit_glyph,place:(t,a,o)=>{n.place(t,a,o,r);let s=t+2*r;o.segments.push({role:`loop_upper`,from:e.id,to:i,path:`M ${t} ${a} A ${r} ${r} 0 0 1 ${s} ${a}`}),o.segments.push({role:`loop_lower`,from:e.id,to:i,path:`M ${t} ${a} A ${r} ${r} 0 0 0 ${s} ${a}`});let c=a-r;o.group_labels.push({owner:e.id,tick:{x:s+U.label_clear,y:c-U.label_clear-W},text_anchor:{x:s+U.label_clear+U.group_text_indent,y:c-U.label_clear}})}}}function xn(e,t){let n=U.corner_radius,r=t.below+an;return{id:e.id,width:t.width,above:Math.max(t.above,$t),below:r+on,exit_glyph:t.exit_glyph,place:(i,a,o)=>{t.place(i,a,o,0);let s=i+t.width,c=a+r;o.segments.push({role:`loop_return`,from:e.id,to:e.id,path:`M ${s} ${a} Q ${s+n} ${a} ${s+n} ${a+n} L ${s+n} ${c-n} Q ${s+n} ${c} ${s} ${c} H ${i} Q ${i-n} ${c} ${i-n} ${c-n} L ${i-n} ${a+n} Q ${i-n} ${a} ${i} ${a}`});let l=a-U.group_label_rise;o.group_labels.push({owner:e.id,tick:{x:i,y:l-W},text_anchor:{x:i+U.group_text_indent,y:l}})}}}function Sn(e,t,n,r){let i=U.basin_radius,a=t+r,o=e+i,s=e+n-i;return`M ${e} ${t} Q ${o} ${t} ${o} ${t+i} L ${o} ${a-i} Q ${o} ${a} ${e+2*i} ${a} H ${e+n-2*i} Q ${s} ${a} ${s} ${a-i} L ${s} ${t+i} Q ${s} ${t} ${e+n} ${t}`}function Cn(e,t){let n=t[0];if(n===void 0)return pn(e);let r=t.slice(1),i=[],a=U.basin_drop,o=null;for(let e of r)o!==null&&(a+=Math.max(U.basin_drop,o.below+e.above+U.label_clear)),i.push(a),o=e;let s=n.width+2*U.basin_shoulder,c=i[i.length-1]??U.basin_drop,l=r[r.length-1];return{id:e.id,width:s,above:n.above,below:c+Math.max(l?.below??0,nn),exit_glyph:n.exit_glyph,place:(t,a,o)=>{o.segments.push({role:`line`,from:e.id,to:n.id,path:`M ${t} ${a} H ${t+s}`}),n.place(t+U.basin_shoulder,a,o,0);for(let[n,c]of r.entries()){let r=i[n]??U.basin_drop;o.segments.push({role:`basin`,from:e.id,to:c.id,path:Sn(t,a,s,r)}),c.place(t+(s-c.width)/2,a+r,o,0)}let l=a+c+U.basin_drop+W;o.group_labels.push({owner:e.id,tick:{x:t+rn,y:l-W},text_anchor:{x:t+rn+U.group_text_indent,y:l}})}}}function wn(e,t){let n=mn(t),r=n.width+U.tick_reserve,i=t[t.length-1]?.id??e.id;return{id:e.id,width:r,above:n.above,below:n.below,exit_glyph:n.exit_glyph,place:(t,a,o,s)=>{n.place(t,a,o,s),o.segments.push({role:`line`,from:i,to:e.id,path:`M ${t+n.width} ${a} H ${t+r}`}),o.tick_lanes.push({owner:e.id,y:a,x0:t+n.width+U.tick_lead,x1:t+r})}}}function Tn(e,t){if(t!==null)for(let n=e.nodes.length-1;n>=0;--n){let r=e.nodes[n];if(r?.id===t){e.nodes[n]={...r,terminus:!0,radius:U.terminus_radius};return}}}function En(e,t){if(!Number.isInteger(e)||e<=0)return{xs:[],decades:[],pitch:0};let n=e>U.decade,r=n?U.comb_pitch:U.tick_pitch,i=[];for(let t=0;t<e;t+=1){let e=n?Math.floor(t/U.decade):0;i.push(t*r+e*U.decade_gap)}return On({xs:i,decades:n?Dn(i,e,r):[],pitch:r},t)}function Dn(e,t,n){let r=[];for(let i=U.decade;i<=t;i+=U.decade){let t=e[i-1],a=e[i];if(t===void 0)break;r.push({value:i,x:a===void 0?t+n:(t+a)/2})}return r}function On(e,t){let n=e.xs[e.xs.length-1]??0;if(n<=t)return e;let r=t/n;return{xs:e.xs.map(e=>e*r),decades:e.decades.map(e=>({value:e.value,x:e.x*r})),pitch:e.pitch*r}}function kn(e,t,n){let r=Math.min(t/e.width,n/e.height),i=Math.max(Math.min(1,r),Jt),a=e.width*i-t>.5,o=e.height*i-n>.5;return{scale:i,offset_x:a?0:(t-e.width*i)/2,offset_y:o?0:(n-e.height*i)/2,pan_x:a,pan_y:o}}var An={structure:null,state:yt(null)};function jn(e,t){if(Mn(t)){let e=Pn(t.structure);if(e!==null){let n=Fn(e);return{structure:n,state:Ct(yt(n),t)}}}let n=Ct(e.state,t);return n===e.state?e:{structure:e.structure,state:n}}function Mn(e){return Nn(e)&&e.kind===`flow_structure`}function Nn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Pn(e){if(!Nn(e))return null;let t=e.kind,n=e.id;if(typeof t!=`string`||typeof n!=`string`)return null;let r=e.children,i=Array.isArray(r)?r.map(Pn).filter(e=>e!==null):[],a=e.config,o=e.meta;return{kind:t,id:n,...e.anonymous===!0?{anonymous:!0}:{},...Nn(a)?{config:a}:{},...Nn(o)?{meta:o}:{},...i.length===0?{}:{children:i}}}function Fn(e){return In(e,new Map,new Map)}function In(e,t,n){let r=(e.kind===`<cycle>`?t.get(e.id):void 0)??Ln(e.id,n),i=new Map(t).set(e.id,r),a=e.children?.map(e=>In(e,i,n));return{...e,id:r,...r===e.id?{}:{step_id:e.id},...a===void 0?{}:{children:a}}}function Ln(e,t){let n=(t.get(e)??0)+1;return t.set(e,n),n===1?e:`${e}#${n}`}function Rn(e){let t=new Map;return e!==null&&zn(e,t),t}function zn(e,t){t.has(e.id)||t.set(e.id,e.kind.toUpperCase());let n=e.children??[];for(let[r,i]of n.entries()){let n=Bn(e,i,r);n!==null&&!t.has(i.id)&&t.set(i.id,n)}for(let e of n)zn(e,t)}function Bn(e,t,n){switch(e.kind){case`map`:return`MAP`;case`loop`:return`LOOP`;case`retry`:return Vn(e.config?.max_attempts);case`fallback`:return`${t.kind.toUpperCase()} · ${n===0?`PRIMARY`:`BACKUP`}`;default:return null}}function Vn(e){let t=Hn(e);return t===null?`RETRY`:`RETRY · ${t} ${t===1?`ATTEMPT`:`ATTEMPTS`}`}function Hn(e){return typeof e!=`number`||!Number.isInteger(e)||e<=0?null:e}var Un=14,Wn=Math.PI/4,Gn=14,Kn=-17,qn=30,Jn=-156,Yn=279,Xn=22,Zn=14,Qn=112,$n=44,er=12,tr=24;function nr(e,t){let n=ar(e,t),r=Rn(t.structure);return{nodes:e.nodes.map(e=>{let i=Cr(n,e,r);return{glyph:e,meta:i.text,meta_fail:i.fail,status:xr(n,e.id),scar:wr(n,e.id)?null:br(t.state,e),emits:t.state.nodes.get(e.id)?.emits??0,checkpoint:n.checkpoint_hits.has(e.id)}}),junctions:e.junctions.map(e=>({glyph:e,label:`merge`,status:t.state.nodes.get(e.owner)?.status??`pending`})),group_labels:e.group_labels.map(e=>({anchor:e,text:kr(n,e.owner)})),segments:e.segments.map(e=>({segment:e,state:ur(n,e)})),fail_marks:yr(e,t.state),tick_lanes:rr(e,n),cards:Ar(e,n)}}function rr(e,t){return e.tick_lanes.map(e=>{let n=t.nodes_by_id.get(e.owner)?.children?.[0],r=n===void 0?[]:G(t.state,n.id),i=En(r.length,e.x1-e.x0);return{owner:e.owner,ticks:r.map((t,n)=>({x:e.x0+(i.xs[n]??0),y:e.y,status:ir(t.status)})),decades:i.decades.map(t=>({x:e.x0+t.x,y:e.y+qn,value:t.value}))}})}function ir(e){return e===`active`?`live`:e===`failed`?`failed`:`done`}function ar(e,t){let n=new Map,r=new Map,i=new Map;t.structure!==null&&sr(t.structure,n,r,i);let a=new Map;for(let t of e.junctions)a.set(t.id,t.owner);let o=new Set;for(let t of e.segments)t.role===`loop_upper`&&o.add(t.to);let s=new Set;for(let e of r.values()){if(e.kind!==`fallback`)continue;let t=e.children?.[0];t!==void 0&&s.add(t.id)}return{state:t.state,parents:n,nodes_by_id:r,first_leaves:i,junction_owners:a,loop_leaves:o,fallback_primaries:s,checkpoint_hits:or(t.state,r,i)}}function or(e,t,n){let r=new Set;for(let i of t.values())i.kind===`checkpoint`&&e.nodes.get(i.id)?.checkpoint===`hit`&&r.add(n.get(i.id)??i.id);return r}function sr(e,t,n,r){n.has(e.id)||(n.set(e.id,e),r.set(e.id,cr(e)));for(let i of e.children??[])t.has(i.id)||t.set(i.id,e.id),sr(i,t,n,r)}function cr(e){let t=e;for(;t.children!==void 0&&t.children.length>0;){let e=t.children[0];if(e===void 0)break;t=e}return t.id}function G(e,t){return e.nodes.get(t)?.occurrences??[]}function K(e){return e.some(e=>e.status===`active`)}function lr(e,t){let n=G(e,t);return n.length>0&&!K(n)}function ur(e,t){switch(t.role){case`loop_upper`:return hr(e.state,t.from??t.to,t.to);case`loop_lower`:return gr(e.state,t.to);case`loop_return`:return vr(e,t.to)}let n=e.junction_owners.get(t.to);return n===void 0?t.from!==null&&mr(e.parents,t.from,t.to)?lr(e.state,t.to)?`traversed`:`unbuilt`:dr(e,t):lr(e.state,n)?`traversed`:`unbuilt`}function dr(e,t){if(e.fallback_primaries.has(t.to)&&fr(e.state,t.to))return`unbuilt`;let n=e.first_leaves.get(t.to)??t.to,r=G(e.state,n);return r.length===0?`unbuilt`:K(r)&&!e.loop_leaves.has(n)&&!pr(e.state,n)?`live`:`traversed`}function fr(e,t){return e.nodes.get(t)?.scarred===!0}function pr(e,t){return e.nodes.get(t)?.suspended===!0}function mr(e,t,n){let r=e.size+1,i=t;for(;i!==void 0&&r>0;){if(--r,i===n)return!0;i=e.get(i)}return!1}function hr(e,t,n){let r=G(e,n);return _r(e,t,r)?`live`:r.length>0?`traversed`:`unbuilt`}function gr(e,t){return G(e,t).some(e=>e.status===`failed`)?`traversed`:`unbuilt`}function _r(e,t,n){return K(G(e,t))?K(n)?!0:n[n.length-1]?.status===`failed`:!1}function vr(e,t){let n=e.nodes_by_id.get(t)?.children?.[0];if(n===void 0)return`unbuilt`;let r=G(e.state,n.id),i=r.length>=2;return _r(e.state,t,r)&&(i||!K(r))?`live`:i?`traversed`:`unbuilt`}function yr(e,t){let n=[];for(let r of e.segments){if(r.role!==`loop_lower`)continue;let i=e.nodes.find(e=>e.id===r.to);if(i===void 0)continue;let a=G(t,r.to).filter(e=>e.status===`failed`).length,o=i.center.x+U.loop_radius,s=U.loop_radius+Un;for(let e=0;e<a;e+=1){let t=Wn+Math.min(a-1-e,2)*Wn;n.push({x:o+Math.cos(t)*s,y:i.center.y+Math.sin(t)*s})}}return n}function br(e,t){return e.nodes.get(t.id)?.scarred===!0?{x:t.center.x+Gn,y:t.center.y+Kn}:null}function xr(e,t){let n=e.state.nodes.get(t)?.status??`pending`;if(n!==`failed`)return n;let r=Sr(e,t);return r!==null&&K(G(e.state,r.id))?`active`:n}function Sr(e,t){let n=e.parents.get(t);if(n===void 0)return null;let r=e.nodes_by_id.get(n);return r?.kind===`retry`?r:null}function Cr(e,t,n){if(pr(e.state,t.id))return{text:`SUSPENDED`,fail:null};let r=t.terminus?`TERMINUS`:n.get(t.id)??t.kind.toUpperCase(),i=G(e.state,t.id);if(i.length===0)return{text:r,fail:null};let a=t.terminus?null:Sr(e,t.id);if(a!==null)return{text:Er(e.state,a,i),fail:null};if(!t.terminus&&wr(e,t.id))return Tr(r,i);let o=i.length>=2?`${r} ×${i.length}`:r;return K(i)?{text:`${o} · RUNNING`,fail:null}:{text:Dr(o,i),fail:null}}function wr(e,t){let n=e.parents.get(t);return n!==void 0&&e.nodes_by_id.get(n)?.kind===`map`}function Tr(e,t){let n=t.length>=2?`${e} ×${t.length}`:e,r=t.filter(e=>e.status===`active`).length,i=t.filter(e=>e.status===`failed`).length,a=t.length>U.decade;return i>0||r>0&&a?{text:r>0?`${n} · ${r} LIVE`:n,fail:i>0?`${i} ✕`:null}:r>0?{text:`${n} · RUNNING`,fail:null}:{text:Dr(n,t),fail:null}}function Er(e,t,n){let r=n[n.length-1]?.status===`failed`&&K(G(e,t.id)),i=Hn(t.config?.max_attempts),a=n.length+ +!!r,o=`RETRY · ATT ${i===null?a:Math.min(a,i)}${i===null?``:`/${i}`}`;return K(n)||r?o:Dr(o,n)}function Dr(e,t){let n=Or(t);return n===null?e:`${e} · ${dt(n)}`}function Or(e){let t=null,n=null;for(let r of e)r.started_ts!==null&&(t===null||r.started_ts<t)&&(t=r.started_ts),r.ended_ts!==null&&(n===null||r.ended_ts>n)&&(n=r.ended_ts);return t===null||n===null?null:Math.max(0,n-t)}function kr(e,t){let n=e.nodes_by_id.get(t),r=(n===void 0?t:fn(n)).toUpperCase(),i=e.state.kinds.get(t)===`fallback`?` · ARMED`:``,a=G(e.state,t);if(a.length===0||K(a))return`${r}${i}`;let o=Or(a);return o===null?`${r}${i}`:`${r} · ${dt(o)}`}function q(e,t){return{role:e,spans:[{text:t,ember:!1}]}}function Ar(e,t){let n=[];for(let r of e.nodes){let e=jr(t,r);e!==null&&n.push(Ir(r,e))}return n}function jr(e,t){let n=e.state.nodes.get(t.id);return n===void 0?null:n.suspended?[q(`title`,`SUSPENDED`),q(`detail`,`AWAITING RESUME`)]:n.scarred&&!wr(e,t.id)?Mr(n):Nr(e,t.id,n.occurrences)}function Mr(e){let t=Fr(Pr(e.occurrences)?.occurrence.error??null);return[q(`title`,`PERMANENT FAILURE`),{role:`detail`,spans:t===null?[{text:`✕`,ember:!0}]:[{text:`✕`,ember:!0},{text:` ${t}`,ember:!1}]}]}function Nr(e,t,n){let r=Sr(e,t);if(r===null||!K(G(e.state,r.id)))return null;let i=n[n.length-1]?.status===`failed`;if(!i&&!K(n))return null;let a=Hn(r.config?.max_attempts),o=n.length+ +!!i,s=a===null?o:Math.min(o,a);if(s<2)return null;let c=[q(`title`,`ATTEMPT ${s}${a===null?``:` OF ${a}`}`)],l=Pr(n);if(l!==null){let e=Fr(l.occurrence.error);c.push({role:`detail`,spans:[{text:`ATT ${l.attempt} `,ember:!1},{text:`✕`,ember:!0},...e===null?[]:[{text:` ${e}`,ember:!1}]]})}let u=Hn(r.config?.backoff_ms);return u!==null&&c.push(q(`detail`,`BACKOFF ${dt(u)} HONORED`)),c}function Pr(e){for(let t=e.length-1;t>=0;--t){let n=e[t];if(n?.status===`failed`)return{occurrence:n,attempt:t+1}}return null}function Fr(e){if(e===null||e.length===0)return null;let t=e.toUpperCase();return t.length<=tr?t:`${t.slice(0,23)}…`}function Ir(e,t){let n=e.center.x+Jn<U.margin,r=e.center.x+(n?$n:Jn),i=e.center.y-Yn,a={x:r+(n?er:Qn),y:i+(t.length-1)*Xn+Zn},o=Lr(e.center,a);return{owner:e.id,lines:t.map((e,t)=>({x:r,y:i+t*Xn,role:e.role,spans:e.spans})),leader:`M ${a.x} ${a.y} L ${o.x} ${o.y}`,dot:o}}function Lr(e,t){let n=t.x-e.x,r=t.y-e.y,i=Math.hypot(n,r);return i===0?{x:e.x,y:e.y-40}:{x:e.x+n/i*40,y:e.y+r/i*40}}function Rr(e,t){return t.structure!==e.structure}function zr(e,t){let n=jn(e.session,t),r=Rr(e.session,n);return{session:n,frames:r?[t]:[...e.frames,t],started:r}}function Br(e){let t=null,n=null,r=[],i=[];for(let a of e){let e=Zr(a);e!==null&&(t??=e,n=e);let o=t===null||n===null?0:Math.max(0,n-t);r.push(o),a.kind===`span_end`&&a.error!==void 0&&i.push(o)}let a=t===null||n===null?0:Math.max(0,n-t);return{count:r.length,span_ms:a,times:r,failures:i.map(e=>Xr(e,a))}}function Vr(e,t){let{times:n,span_ms:r,count:i}=e;if(i===0)return 0;let a=J(t,0,i-1);return r>0?J((n[a]??0)/r,0,1):i>1?a/(i-1):0}function Hr(e,t){let{times:n,span_ms:r,count:i}=e;if(i===0)return 0;let a=J(t,0,1);return r<=0?Math.round(a*(i-1)):Yr(n,a*r)}function Ur(e,t){let n=Array.from({length:t},()=>0);if(e.count===0)return n;for(let r=0;r<e.count;r+=1){let i=Math.min(t-1,Math.floor(Vr(e,r)*t));n[i]=(n[i]??0)+1}let r=Math.max(...n);return n.map(e=>e/r)}function Wr(e,t){let{times:n,count:r,span_ms:i}=e;if(r===0)return 0;if(i<=0)return Gr(t,1,r);let a=J(t,0,r-1);for(let e=a+1;e<r;e+=1)if(e===r-1||(n[e+1]??0)>(n[e]??0))return e;return a}function Gr(e,t,n){return J(e+Math.sign(t),0,Math.max(0,n-1))}function Kr(e,t,n){let{times:r,count:i}=e;if(i===0)return 0;let a=J(t,0,i-1),o=r[a]??0;if(n>0){let e=o+1e3;for(let t=a+1;t<i;t+=1)if((r[t]??0)>=e)return t;return i-1}let s=o-1e3;for(let e=a-1;e>=0;--e)if((r[e]??0)<=s)return e;return 0}function qr(e,t,n,r){if(e.count===0)return`ignore`;switch(n){case`ArrowRight`:return r?Kr(e,t,1):Gr(t,1,e.count);case`ArrowLeft`:return r?Kr(e,t,-1):Gr(t,-1,e.count);case`Home`:return 0;case`End`:return`live`;default:return`ignore`}}function Jr(e,t){let n=An,r=J(t+1,0,e.length);for(let t=0;t<r;t+=1)n=jn(n,e[t]);return n}function Yr(e,t){let n=e.length;for(let r=0;r<e.length;r+=1)if((e[r]??0)>=t){n=r;break}if(n<=0)return 0;if(n>=e.length)return e.length-1;let r=n-1;return t-(e[r]??0)<=(e[n]??0)-t?r:n}function Xr(e,t){return t>0?J(e/t,0,1):0}function Zr(e){let t=e.ts;return typeof t==`number`&&Number.isFinite(t)?t:null}function J(e,t,n){return Math.min(n,Math.max(t,e))}var Qr=P(`<svg class=scrubber data-testid=scrubber height=40 fill=none><line class=scrub-spine-ahead y1=20 y2=20></line><line class=scrub-spine-traversed y1=20 y2=20></line><circle class=scrub-playhead data-testid=playhead cy=20 r=3.5></circle><rect class=scrub-band x=0 y=8 height=24>`),$r=P(`<svg><rect class=scrub-density y=15 height=10></svg>`,!1,!0,!1),ei=P(`<svg><line class=scrub-fail y1=16 y2=24></svg>`,!1,!0,!1),ti=4,ni=48,ri=.3;function ii(e){let t=()=>e.width-U.margin,n=()=>Math.max(0,t()-U.margin),r=e=>U.margin+e*n(),i=()=>r(ai(e.fraction)),a=(t,n)=>{let r=n.width-2*U.margin,i=r<=0?0:(t-n.left-U.margin)/r;e.on_seek(ai(i))},o=()=>e.density?Ur(e.timeline,ni):[];return(()=>{var s=Qr(),c=s.firstChild,l=c.nextSibling,u=l.nextSibling,d=u.nextSibling;return I(s,A(j,{get each(){return o()},children:(e,t)=>(()=>{var i=$r();return F(i,`opacity`,e*ri),y(e=>{var a=r(t()/ni),o=n()/ni;return a!==e.e&&F(i,`x`,e.e=a),o!==e.t&&F(i,`width`,e.t=o),e},{e:void 0,t:void 0}),i})()}),c),I(s,A(j,{get each(){return e.timeline.failures},children:e=>[(()=>{var t=ei();return y(n=>{var i=r(e)-ti,a=r(e)+ti;return i!==n.e&&F(t,`x1`,n.e=i),a!==n.t&&F(t,`x2`,n.t=a),n},{e:void 0,t:void 0}),t})(),(()=>{var t=ei();return y(n=>{var i=r(e)+ti,a=r(e)-ti;return i!==n.e&&F(t,`x1`,n.e=i),a!==n.t&&F(t,`x2`,n.t=a),n},{e:void 0,t:void 0}),t})()]}),u),d.$$pointermove=e=>{e.currentTarget.hasPointerCapture(e.pointerId)&&a(e.clientX,e.currentTarget.getBoundingClientRect())},d.$$pointerdown=e=>{e.currentTarget.setPointerCapture(e.pointerId),a(e.clientX,e.currentTarget.getBoundingClientRect())},y(n=>{var r=i(),a=t(),o=U.margin,s=i(),f=i(),p=e.width;return r!==n.e&&F(c,`x1`,n.e=r),a!==n.t&&F(c,`x2`,n.t=a),o!==n.a&&F(l,`x1`,n.a=o),s!==n.o&&F(l,`x2`,n.o=s),f!==n.i&&F(u,`cx`,n.i=f),p!==n.n&&F(d,`width`,n.n=p),n},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),s})()}function ai(e){return Math.min(1,Math.max(0,e))}ke([`pointerdown`,`pointermove`]);function Y(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function X(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Z(e,t){let n=e[t];return typeof n==`string`?n:null}function oi(e){let t=e.content;return{content:Array.isArray(t)?t:null,usage:{input_tokens:X(e,`input_tokens`),output_tokens:X(e,`output_tokens`),cached_input_tokens:X(e,`cached_input_tokens`),cache_write_tokens:X(e,`cache_write_tokens`),cache_hit_ratio:X(e,`cache_hit_ratio`)}}}function si(e){let t=[],n=new Map;for(let r of e){if(!Y(r))continue;let e=Z(r,`span_id`),i=Z(r,`call_span_id`),a=X(r,`step_index`);r.kind===`response_received`&&e!==null&&n.set(e,oi(r)),r.kind===`request_sent`&&i!==null&&a!==null&&t.push({call:i,step_index:a,span_id:e,request:r.request})}return{calls:Map.groupBy(t,e=>e.call),replies:n}}function ci(e){if(!Y(e)||!Array.isArray(e.tools)||!Array.isArray(e.messages))return!1;let t=e.settings;return Y(t)&&Z(t,`provider`)!==null&&Z(t,`model_id`)!==null}function li(e,t){let{request:n}=e;if(!Y(n))return null;let r=n.messages;if(Array.isArray(r))return r;let i=n.appended;return!Array.isArray(i)||t?.step_index!==e.step_index-1?null:[...t.messages,...i]}function ui(e,t,n){let r=n?.content??null;return{call_span_id:e.call_span_id,step_index:t.step_index,settings:e.settings,tools:e.tools,messages:t.messages,...r===null?{}:{response:r},usage:n?.usage??null}}function di(e,t,n){let r=t.toSorted((e,t)=>e.step_index-t.step_index),i=r[0];if(i?.step_index!==0||!ci(i.request))return[];let a={call_span_id:e,settings:i.request.settings,tools:i.request.tools},o=[],s=null;for(let e of r){let t=li(e,s);s=t===null?null:{step_index:e.step_index,messages:t},s!==null&&o.push(ui(a,s,n.get(e.span_id)))}return o}function fi(e){let{calls:t,replies:n}=si(e);return[...t].flatMap(([e,t])=>di(e,t,n))}function pi(e,t){let n=e.size,r=e.get(t);for(;r!==void 0&&n>0;){if(--n,r.node_id!==null)return r.node_id;if(r.parent_span_id===null)return null;r=e.get(r.parent_span_id)}return null}function mi(e,t){let n=new Map;for(let r of e){let e=pi(t,r.call_span_id);if(e===null)continue;let i=n.get(e);i===void 0?n.set(e,[r]):i.push(r)}return n}function hi(e){let t={call_span_id:e.call_span_id,step_index:e.step_index,settings:e.settings,tools:e.tools,messages:e.messages,response:e.response};return JSON.stringify(t,null,2)}function gi(e){return e.toLocaleString(`en-US`)}function _i(e){return e===1?`1 TURN`:`${e} TURNS`}function vi(e){let t=e.usage,n=[];t!==null&&t.input_tokens!==null&&n.push(`${gi(t.input_tokens)} IN`),t!==null&&t.output_tokens!==null&&n.push(`${gi(t.output_tokens)} OUT`);let r=t===null?null:t.cache_hit_ratio;return{step:`STEP ${e.step_index}`,tokens:n.length===0?`NO USAGE`:n.join(` · `),cache:r===null?null:`CACHE ${Math.round(r*100)}%`}}function yi(e){let t=e[0]?.settings,n=(t===void 0?[]:[Z(t,`provider`),Z(t,`model_id`)]).filter(e=>e!==null).join(` · `);return{count:_i(e.length),model:n===``?null:n}}function bi(e,t){let n=Math.max(0,t-1);return e===null?n:Math.min(Math.max(0,e),n)}function xi(e,t){return e===null||e.index!==t?`COPY TURN`:e.ok?`COPIED`:`COPY FAILED`}function Q(e,t){return{label:null,name:null,format:e,body:t}}function $(e){try{return JSON.stringify(e,null,2)??String(e)}catch{return String(e)}}function Si(e){try{let t=JSON.parse(e);if(typeof t==`object`&&t)return Q(`code`,$(t))}catch{}return Q(`text`,e)}function Ci(e){let t=Z(e,`media_type`)??`image`,n=Z(e,`image`);return n===null?t:`${t} · ${gi(Math.floor(n.length*3/4))} bytes`}function wi(e){let t=e.provider_options;if(!Y(t))return null;for(let e of Object.values(t)){let t=Y(e)?e.block:void 0,n=Y(t)?Z(t,`type`):null;if(n!==null)return n}return null}function Ti(e){if(!Y(e))return Q(`code`,$(e));switch(e.type){case`text`:return Q(`text`,Z(e,`text`)??``);case`tool_call`:return{label:`CALL`,name:Z(e,`name`),format:`code`,body:$(e.input)};case`reasoning`:{let t=Z(e,`text`)??``;return{label:`REASONING`,name:null,format:`text`,body:t===``?`(hidden by the provider)`:t}}case`image`:return{label:`IMAGE`,name:null,format:`text`,body:Ci(e)};case`opaque`:return{label:`OPAQUE`,name:wi(e),format:`code`,body:$(e.provider_options)};default:return Q(`code`,$(e))}}function Ei(e){return typeof e==`string`?[Q(`text`,e)]:Array.isArray(e)?e.map(Ti):[Q(`code`,$(e))]}function Di(e){if(!Y(e))return{role:`unknown`,label:`MESSAGE`,name:null,error:!1,blocks:[Q(`code`,$(e))]};let t=Z(e,`role`)??`unknown`,n=e.content;return t===`tool`?{role:t,label:`TOOL`,name:Z(e,`name`),error:e.is_error===!0,blocks:typeof n==`string`?[Si(n)]:Ei(n)}:{role:t,label:t.toUpperCase(),name:null,error:!1,blocks:Ei(n)}}function Oi(e){return Y(e)&&e.role===`system`&&typeof e.content==`string`}function ki(e){let t=Y(e)?Z(e,`name`):null;return t===null?[]:[t]}function Ai(e){let t=[];for(let n of e.messages){if(!Oi(n))break;t.push(n.content)}return{system:t,tools:e.tools.flatMap(ki).join(` · `),messages:e.messages.slice(t.length).map(Di)}}function ji(e){return e.response===void 0?null:e.response.map(Ti)}function Mi(e){let t=e.split(`
2
+ `);if(t.length>8){let e=t.slice(0,5).join(`
3
+ `);if(e.length<=480)return{head:e,more:`+${t.length-5} LINES`}}else if(e.length<=720)return{head:e,more:null};return{head:e.slice(0,480),more:`+${gi(e.length-480)} CHARS`}}var Ni=.56;function Pi(e){return Math.round(Math.min(820,e*Ni))}function Fi(e,t,n,r){if(e===null)return null;let i=t.get(e);return i===void 0?null:{name:n.find(t=>t.id===e)?.label??e,turns:i,width:Pi(r)}}var Ii=6,Li=15,Ri=7.03,zi=10.5;function Bi(e,t){let n=_i(t),r=n.length*Ri-1.33,i=r+14,a=e.y+Ii;return{label:n,x:e.x-i/2,y:a,width:i,height:Li,text_x:e.x-r/2,text_y:a+zi,text_length:r}}var Vi=P(`<pre>`),Hi=P(`<button type=button class=td-fold data-testid=fold-toggle>`),Ui=P(`<span class=td-label>`),Wi=P(`<span class=td-name-ref>`),Gi=P(`<div class=td-block>`),Ki=P(`<span class=td-flag><span class=td-error>✕</span> IS_ERROR`),qi=P(`<div class=td-msg data-testid=turn-message><div class=td-msg-head>`),Ji=P(`<div class=td-msg data-role=system><div class=td-msg-head>`),Yi=P(`<div class=td-body><section class=td-col data-testid=turn-request><h3 class=td-sec>REQUEST</h3></section><section class=td-col data-testid=turn-response><h3 class=td-sec>RESPONSE`),Xi=P(`<div class=td-msg data-role=tools><div class=td-msg-head></div><p class=td-tools data-testid=turn-tools>`),Zi=P(`<p class=td-empty>NOT CAPTURED`),Qi=P(`<aside class=turns-drawer data-testid=turn-drawer><header class=td-head><div class=td-title><span class=td-node></span><span class=td-meta></span></div><div class=td-actions><button type=button class=td-chip data-testid=copy-turn></button><button type=button class=td-chip data-testid=close-turns>CLOSE</button></div></header><ol class=td-list data-testid=turn-list>`),$i=P(`<span class=td-sep>·`),ea=P(`<span class=td-model>`),ta=P(`<li><button type=button class=td-turn data-testid=turn-row><span class=td-step></span><span class=td-tokens></span><span class=td-cache>`);function na(e){let[t,n]=v(!1),r=x(()=>Mi(e.text));return[(()=>{var n=Vi();return I(n,(()=>{var n=Te(()=>!!t());return()=>n()?e.text:r().head})()),y(()=>Ae(n,`td-text td-${e.format}`)),n})(),A(N,{get when(){return r().more},children:e=>(()=>{var r=Hi();return r.$$click=()=>n(!t()),I(r,(()=>{var n=Te(()=>!!t());return()=>n()?`FOLD`:e()})()),y(()=>F(r,`aria-expanded`,t())),r})()})]}function ra(e){return(()=>{var t=Ui();return I(t,()=>e.label,null),I(t,A(N,{get when(){return e.name},children:e=>(()=>{var t=Wi();return I(t,e),t})()}),null),t})()}function ia(e){return(()=>{var t=Gi();return I(t,A(N,{get when(){return e.block.label},children:t=>A(ra,{get label(){return t()},get name(){return e.block.name}})}),null),I(t,A(na,{get text(){return e.block.body},get format(){return e.block.format}}),null),t})()}function aa(e){return(()=>{var t=qi(),n=t.firstChild;return I(n,A(ra,{get label(){return e.view.label},get name(){return e.view.name}}),null),I(n,A(N,{get when(){return e.view.error},get children(){return Ki()}}),null),I(t,A(M,{get each(){return e.view.blocks},children:e=>A(ia,{get block(){return e()}})}),null),y(()=>F(t,`data-role`,e.view.role)),t})()}function oa(e){let t=x(()=>Ai(e.turn)),n=x(()=>ji(e.turn));return(()=>{var e=Yi(),r=e.firstChild;r.firstChild;var i=r.nextSibling;return i.firstChild,I(r,A(N,{get when(){return t().system.length>0},get children(){var e=Ji(),n=e.firstChild;return I(n,A(ra,{label:`SYSTEM`,name:null})),I(e,A(M,{get each(){return t().system},children:e=>(()=>{var t=Gi();return I(t,A(na,{get text(){return e()},format:`text`})),t})()}),null),e}}),null),I(r,A(N,{get when(){return t().tools},children:e=>(()=>{var t=Xi(),n=t.firstChild,r=n.nextSibling;return I(n,A(ra,{label:`TOOLS`,name:null})),I(r,e),t})()}),null),I(r,A(M,{get each(){return t().messages},children:e=>A(aa,{get view(){return e()}})}),null),I(i,A(N,{get when(){return n()},get fallback(){return Zi()},children:e=>A(M,{get each(){return e()},children:e=>A(ia,{get block(){return e()}})})}),null),e})()}function sa(e){let[t,n]=v(null),[r,i]=v(null),a=x(()=>bi(t(),e.turns.length)),o=x(()=>e.turns[a()]),s=x(()=>yi(e.turns)),c=()=>{let t=o();if(t===void 0)return;let n=a();e.copy_text(hi(t)).then(()=>i({index:n,ok:!0}),()=>i({index:n,ok:!1}))};return(()=>{var t=Qi(),i=t.firstChild,o=i.firstChild,l=o.firstChild,u=l.nextSibling,d=o.nextSibling.firstChild,f=d.nextSibling,p=i.nextSibling;return t.$$keydown=t=>{t.key===`Escape`&&e.on_close()},I(l,()=>e.name),I(u,()=>s().count,null),I(u,A(N,{get when(){return s().model},children:e=>[$i(),(()=>{var t=ea();return I(t,e),t})()]}),null),d.$$click=c,I(d,()=>xi(r(),a())),f.$$click=()=>e.on_close(),I(p,A(M,{get each(){return e.turns},children:(e,t)=>{let r=x(()=>vi(e()));return(()=>{var e=ta(),i=e.firstChild,o=i.firstChild,s=o.nextSibling,c=s.nextSibling;return i.$$click=()=>n(t),I(o,()=>r().step),I(s,()=>r().tokens),I(c,()=>r().cache),y(e=>{var n=t===a()?`true`:void 0,r=t===a();return n!==e.e&&F(i,`data-selected`,e.e=n),r!==e.t&&F(i,`aria-pressed`,e.t=r),e},{e:void 0,t:void 0}),e})()}})),I(t,A(N,{keyed:!0,get when(){return a()+1},children:t=>A(N,{get when(){return e.turns[t-1]},children:e=>A(oa,{get turn(){return e()}})})}),null),y(n=>{var r=`Captured turns of ${e.name}`,i=`${e.width}px`;return r!==n.e&&F(t,`aria-label`,n.e=r),i!==n.t&&je(t,`width`,n.t=i),n},{e:void 0,t:void 0}),t})()}ke([`click`,`keydown`]);var ca=P(`<svg><circle class=scar-mask r=13></svg>`,!1,!0,!1),la=P(`<svg><circle class=scar-ring r=8.5></svg>`,!1,!0,!1),ua=P(`<svg><path class=scar-mark></svg>`,!1,!0,!1),da=P(`<svg><path class=tick-fail></svg>`,!1,!0,!1),fa=P(`<svg><line class="tick tick-live-glow"></svg>`,!1,!0,!1),pa=P(`<svg><line class="tick tick-live"></svg>`,!1,!0,!1),ma=P(`<svg><line class="tick tick-done"></svg>`,!1,!0,!1),ha=P(`<svg><g class=seg-live data-state=live><path class="seg seg-live-outer"></path><path class="seg seg-live-inner"></path><path class="seg seg-live-march"></svg>`,!1,!0,!1),ga=P(`<svg><g class=turns-badge data-testid=turns-badge role=button tabindex=0><rect class=turns-badge-box rx=3></rect><text class=turns-badge-text lengthAdjust=spacing></svg>`,!1,!0,!1),_a=P(`<svg class=stage data-testid=stage fill=none><defs><radialGradient id=halo><stop offset=0% stop-color=#FFAC33 stop-opacity=0.5></stop><stop offset=45% stop-color=#FFAC33 stop-opacity=0.16></stop><stop offset=78% stop-color=#FFAC33 stop-opacity=0></stop></radialGradient><radialGradient id=bloom><stop offset=0% stop-color=#FFAC33 stop-opacity=0.055></stop><stop offset=70% stop-color=#FFAC33 stop-opacity=0></stop></radialGradient><filter id=glow-2 x=-60% y=-60% width=220% height=220%><feGaussianBlur stdDeviation=2></feGaussianBlur></filter><filter id=glow-4 x=-60% y=-60% width=220% height=220%><feGaussianBlur stdDeviation=4></feGaussianBlur></filter></defs><g><g class=scaffold data-testid=scaffold>`),va=P(`<svg><circle class=bloom></svg>`,!1,!0,!1),ya=P(`<svg><path></svg>`,!1,!0,!1),ba=P(`<svg><g class=tick-lane data-testid=tick-lane></svg>`,!1,!0,!1),xa=P(`<svg><text class=tick-decade></svg>`,!1,!0,!1),Sa=P(`<svg><circle class=halo></svg>`,!1,!0,!1),Ca=P(`<svg><circle class=puck-core r=2.5></svg>`,!1,!0,!1),wa=P(`<svg><circle class=emit-bloom r=16></svg>`,!1,!0,!1),Ta=P(`<svg><circle class=terminus-ring></svg>`,!1,!0,!1),Ea=P(`<svg><tspan class=meta-check> ✓</svg>`,!1,!0,!1),Da=P(`<svg><g class=node data-testid=node><text class=node-name></text><text class=node-meta></svg>`,!1,!0,!1),Oa=P(`<svg><circle class=puck></svg>`,!1,!0,!1),ka=P(`<svg><line class=pause-bar></svg>`,!1,!0,!1),Aa=P(`<svg><tspan> · </svg>`,!1,!0,!1),ja=P(`<svg><tspan class=meta-fail></svg>`,!1,!0,!1),Ma=P(`<svg><path class=fail-mark></svg>`,!1,!0,!1),Na=P(`<svg><g class=junction data-testid=junction><circle class=puck></circle><text class=junction-label></svg>`,!1,!0,!1),Pa=P(`<svg><g class=group-label data-testid=group-label><line class=group-tick></line><text class=group-text></svg>`,!1,!0,!1),Fa=P(`<svg><g class=card data-testid=card><path class=card-leader></path><circle class=card-dot r=2.5></svg>`,!1,!0,!1),Ia=P(`<svg><text></svg>`,!1,!0,!1),La=P(`<svg><tspan></svg>`,!1,!0,!1),Ra=4.5,za=6,Ba=4,Va=-32,Ha=2.4,Ua=3.2;function Wa(e,t,n){return`M ${e-n} ${t-n} L ${e+n} ${t+n} M ${e+n} ${t-n} L ${e-n} ${t+n}`}function Ga(e){return[(()=>{var t=ca();return y(n=>{var r=e.center.x,i=e.center.y;return r!==n.e&&F(t,`cx`,n.e=r),i!==n.t&&F(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t})(),(()=>{var t=la();return y(n=>{var r=e.center.x,i=e.center.y,a=`rotate(${Va} ${e.center.x} ${e.center.y})`;return r!==n.e&&F(t,`cx`,n.e=r),i!==n.t&&F(t,`cy`,n.t=i),a!==n.a&&F(t,`transform`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})(),(()=>{var t=ua();return y(()=>F(t,`d`,Wa(e.mark.x,e.mark.y,Ra))),t})()]}function Ka(e){let t=()=>e.tick.y-za,n=()=>e.tick.y+za;return A(Ce,{get children(){return[A(we,{get when(){return e.tick.status===`failed`},get children(){var t=da();return y(()=>F(t,`d`,Wa(e.tick.x,e.tick.y,Ba))),t}}),A(we,{get when(){return e.tick.status===`live`},get children(){return[(()=>{var r=fa();return y(i=>{var a=e.tick.x,o=t(),s=e.tick.x,c=n();return a!==i.e&&F(r,`x1`,i.e=a),o!==i.t&&F(r,`y1`,i.t=o),s!==i.a&&F(r,`x2`,i.a=s),c!==i.o&&F(r,`y2`,i.o=c),i},{e:void 0,t:void 0,a:void 0,o:void 0}),r})(),(()=>{var r=pa();return y(i=>{var a=e.tick.x,o=t(),s=e.tick.x,c=n();return a!==i.e&&F(r,`x1`,i.e=a),o!==i.t&&F(r,`y1`,i.t=o),s!==i.a&&F(r,`x2`,i.a=s),c!==i.o&&F(r,`y2`,i.o=c),i},{e:void 0,t:void 0,a:void 0,o:void 0}),r})()]}}),A(we,{get when(){return e.tick.status===`done`},get children(){var r=ma();return y(i=>{var a=e.tick.x,o=t(),s=e.tick.x,c=n();return a!==i.e&&F(r,`x1`,i.e=a),o!==i.t&&F(r,`y1`,i.t=o),s!==i.a&&F(r,`x2`,i.a=s),c!==i.o&&F(r,`y2`,i.o=c),i},{e:void 0,t:void 0,a:void 0,o:void 0}),r}})]}})}function qa(e){return(()=>{var t=ha(),n=t.firstChild,r=n.nextSibling,i=r.nextSibling;return y(a=>{var o=e.scene_segment.segment.role,s=e.scene_segment.segment.to,c=e.scene_segment.segment.path,l=e.scene_segment.segment.path,u=e.scene_segment.segment.path;return o!==a.e&&F(t,`data-role`,a.e=o),s!==a.t&&F(t,`data-to`,a.t=s),c!==a.a&&F(n,`d`,a.a=c),l!==a.o&&F(r,`d`,a.o=l),u!==a.i&&F(i,`d`,a.i=u),a},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),t})()}function Ja(e){return(()=>{var t=ga(),n=t.firstChild,r=n.nextSibling;return t.$$keydown=t=>{t.key===`Enter`&&(e.on_toggle(),t.preventDefault())},t.$$click=()=>e.on_toggle(),I(r,()=>e.badge.label),y(i=>{var a=e.open?`true`:void 0,o=`${e.badge.label} captured`,s=e.open,c=e.badge.x,l=e.badge.y,u=e.badge.width,d=e.badge.height,f=e.badge.text_x,p=e.badge.text_y,m=e.badge.text_length;return a!==i.e&&F(t,`data-open`,i.e=a),o!==i.t&&F(t,`aria-label`,i.t=o),s!==i.a&&F(t,`aria-expanded`,i.a=s),c!==i.o&&F(n,`x`,i.o=c),l!==i.i&&F(n,`y`,i.i=l),u!==i.n&&F(n,`width`,i.n=u),d!==i.s&&F(n,`height`,i.s=d),f!==i.h&&F(r,`x`,i.h=f),p!==i.r&&F(r,`y`,i.r=p),m!==i.d&&F(r,`textLength`,i.d=m),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0,h:void 0,r:void 0,d:void 0}),t})()}function Ya(e){let t=x(()=>e.session.structure),n=x(()=>ln(t())),r=x(()=>nr(n(),e.session)),i=x(()=>r().nodes.filter(e=>e.status===`active`).map(e=>e.glyph)),a=x(()=>mi(fi(e.events),e.session.state.spans)),[o,s]=v(null),c=e=>{s(o()===e?null:e)},l=x(()=>Fi(o(),a(),r().nodes.map(e=>e.glyph),e.viewport.width)),u=x(()=>kn(n(),e.viewport.width-(l()?.width??0),e.viewport.height));return[(()=>{var e=_a(),t=e.firstChild.nextSibling,n=t.firstChild;return I(t,A(j,{get each(){return i()},children:e=>(()=>{var t=va();return F(t,`r`,215),y(n=>{var r=e.center.x,i=e.center.y;return r!==n.e&&F(t,`cx`,n.e=r),i!==n.t&&F(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t})()}),n),I(n,A(M,{get each(){return r().segments},children:e=>A(N,{get when(){return e().state===`live`},get fallback(){return(()=>{var t=ya();return y(n=>{var r=e().state===`traversed`?`seg seg-traversed`:`seg seg-unbuilt`,i=e().segment.path,a=e().segment.role,o=e().segment.to,s=e().state;return r!==n.e&&F(t,`class`,n.e=r),i!==n.t&&F(t,`d`,n.t=i),a!==n.a&&F(t,`data-role`,n.a=a),o!==n.o&&F(t,`data-to`,n.o=o),s!==n.i&&F(t,`data-state`,n.i=s),n},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),t})()},get children(){return A(qa,{get scene_segment(){return e()}})}})})),I(t,A(M,{get each(){return r().tick_lanes},children:e=>(()=>{var t=ba();return I(t,A(M,{get each(){return e().ticks},children:e=>A(Ka,{get tick(){return e()}})}),null),I(t,A(M,{get each(){return e().decades},children:e=>(()=>{var t=xa();return I(t,()=>e().value),y(n=>{var r=e().x,i=e().y;return r!==n.e&&F(t,`x`,n.e=r),i!==n.t&&F(t,`y`,n.t=i),n},{e:void 0,t:void 0}),t})()}),null),y(()=>F(t,`data-owner`,e().owner)),t})()}),null),I(t,A(j,{get each(){return i()},children:e=>(()=>{var t=Sa();return F(t,`r`,40),y(n=>{var r=e.center.x,i=e.center.y;return r!==n.e&&F(t,`cx`,n.e=r),i!==n.t&&F(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t})()}),null),I(t,A(M,{get each(){return r().nodes},children:e=>(()=>{var t=Da(),n=t.firstChild,r=n.nextSibling;return I(t,A(N,{get when(){return e().scar},get fallback(){return(()=>{var t=Oa();return y(n=>{var r=e().glyph.center.x,i=e().glyph.center.y,a=e().status===`active`?e().glyph.radius+.5:e().glyph.radius;return r!==n.e&&F(t,`cx`,n.e=r),i!==n.t&&F(t,`cy`,n.t=i),a!==n.a&&F(t,`r`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()},children:t=>A(Ga,{get center(){return e().glyph.center},get mark(){return t()}})}),n),I(t,A(N,{get when(){return e().status===`active`},get children(){var t=Ca();return y(n=>{var r=e().glyph.center.x,i=e().glyph.center.y;return r!==n.e&&F(t,`cx`,n.e=r),i!==n.t&&F(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),I(t,A(N,{get when(){return e().status===`suspended`},get children(){return A(j,{each:[-2.4,Ha],children:t=>(()=>{var n=ka();return y(r=>{var i=e().glyph.center.x+t,a=e().glyph.center.y-Ua,o=e().glyph.center.x+t,s=e().glyph.center.y+Ua;return i!==r.e&&F(n,`x1`,r.e=i),a!==r.t&&F(n,`y1`,r.t=a),o!==r.a&&F(n,`x2`,r.a=o),s!==r.o&&F(n,`y2`,r.o=s),r},{e:void 0,t:void 0,a:void 0,o:void 0}),n})()})}}),n),I(t,A(N,{keyed:!0,get when(){return Te(()=>e().emits>0)()?e().emits:null},get children(){var t=wa();return y(n=>{var r=e().glyph.center.x,i=e().glyph.center.y;return r!==n.e&&F(t,`cx`,n.e=r),i!==n.t&&F(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),I(t,A(N,{get when(){return e().glyph.terminus},get children(){var t=Ta();return y(n=>{var r=e().glyph.center.x,i=e().glyph.center.y,a=U.terminus_ring_radius;return r!==n.e&&F(t,`cx`,n.e=r),i!==n.t&&F(t,`cy`,n.t=i),a!==n.a&&F(t,`r`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t}}),n),I(n,()=>e().glyph.label),I(r,()=>e().meta,null),I(r,A(N,{get when(){return e().meta_fail},children:e=>[Aa(),(()=>{var t=ja();return I(t,e),t})()]}),null),I(r,A(N,{get when(){return e().checkpoint},get children(){return Ea()}}),null),I(t,A(N,{get when(){return a().get(e().glyph.id)},children:t=>A(Ja,{get badge(){return Bi(e().glyph.meta_anchor,t().length)},get open(){return o()===e().glyph.id},on_toggle:()=>c(e().glyph.id)})}),null),y(i=>{var a=e().status,o=e().scar===null?void 0:`true`,s=e().glyph.id,c=e().glyph.name_anchor.x,l=e().glyph.name_anchor.y,u=e().glyph.meta_anchor.x,d=e().glyph.meta_anchor.y;return a!==i.e&&F(t,`data-status`,i.e=a),o!==i.t&&F(t,`data-scar`,i.t=o),s!==i.a&&F(t,`data-node-id`,i.a=s),c!==i.o&&F(n,`x`,i.o=c),l!==i.i&&F(n,`y`,i.i=l),u!==i.n&&F(r,`x`,i.n=u),d!==i.s&&F(r,`y`,i.s=d),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),t})()}),null),I(t,A(M,{get each(){return r().fail_marks},children:e=>(()=>{var t=Ma();return y(()=>F(t,`d`,Wa(e().x,e().y,Ra))),t})()}),null),I(t,A(M,{get each(){return r().junctions},children:e=>(()=>{var t=Na(),n=t.firstChild,r=n.nextSibling;return I(r,()=>e().label),y(i=>{var a=e().status,o=e().glyph.center.x,s=e().glyph.center.y,c=e().glyph.radius,l=e().glyph.label_anchor.x,u=e().glyph.label_anchor.y;return a!==i.e&&F(t,`data-status`,i.e=a),o!==i.t&&F(n,`cx`,i.t=o),s!==i.a&&F(n,`cy`,i.a=s),c!==i.o&&F(n,`r`,i.o=c),l!==i.i&&F(r,`x`,i.i=l),u!==i.n&&F(r,`y`,i.n=u),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0}),t})()}),null),I(t,A(M,{get each(){return r().group_labels},children:e=>(()=>{var t=Pa(),n=t.firstChild,r=n.nextSibling;return I(r,()=>e().text),y(i=>{var a=e().anchor.owner,o=e().anchor.tick.x,s=e().anchor.tick.y,c=e().anchor.tick.x+U.group_tick_length,l=e().anchor.tick.y,u=e().anchor.text_anchor.x,d=e().anchor.text_anchor.y;return a!==i.e&&F(t,`data-owner`,i.e=a),o!==i.t&&F(n,`x1`,i.t=o),s!==i.a&&F(n,`y1`,i.a=s),c!==i.o&&F(n,`x2`,i.o=c),l!==i.i&&F(n,`y2`,i.i=l),u!==i.n&&F(r,`x`,i.n=u),d!==i.s&&F(r,`y`,i.s=d),i},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0,n:void 0,s:void 0}),t})()}),null),I(t,A(M,{get each(){return r().cards},children:e=>(()=>{var t=Fa(),n=t.firstChild,r=n.nextSibling;return I(t,A(M,{get each(){return e().lines},children:e=>(()=>{var t=Ia();return I(t,A(M,{get each(){return e().spans},children:e=>(()=>{var t=La();return I(t,()=>e().text),y(()=>F(t,`class`,e().ember?`card-fail`:void 0)),t})()})),y(n=>{var r=e().role===`title`?`card-title`:`card-detail`,i=e().x,a=e().y;return r!==n.e&&F(t,`class`,n.e=r),i!==n.t&&F(t,`x`,n.t=i),a!==n.a&&F(t,`y`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()}),n),y(i=>{var a=e().owner,o=e().leader,s=e().dot.x,c=e().dot.y;return a!==i.e&&F(t,`data-owner`,i.e=a),o!==i.t&&F(n,`d`,i.t=o),s!==i.a&&F(r,`cx`,i.a=s),c!==i.o&&F(r,`cy`,i.o=c),i},{e:void 0,t:void 0,a:void 0,o:void 0}),t})()}),null),y(()=>F(t,`transform`,`translate(${u().offset_x} ${u().offset_y}) scale(${u().scale})`)),e})(),A(N,{get when(){return l()},children:t=>A(sa,{get name(){return t().name},get turns(){return t().turns},get width(){return t().width},get copy_text(){return e.copy_text},on_close:()=>s(null)})})]}ke([`click`,`keydown`]);var Xa=P(`<span data-testid=status><i class=status-dot>`),Za=P(`<button type=button class=return-live data-testid=return-to-live>RETURN TO LIVE`),Qa=P(`<div class=canvas><header class=canvas-header><div class=run><span class=run-key>run</span><span class=run-id data-testid=run-id></span></div><div class=stats data-testid=stats>`),$a=P(`<span class="status status-replay"data-testid=status><i class=status-dot></i>REPLAY`),eo=P(`<span>`);function to(e){let t=x(()=>ut(e.status,e.run_status));return(()=>{var e=Xa();return e.firstChild,I(e,()=>t().label,null),y(()=>Ae(e,`status status-${t().tone}`)),e})()}function no(e){let t=x(()=>vt({t_plus_ms:e.play_t_plus_ms??it({fold_t_plus_ms:St(e.session.state),run_over:e.session.state.run_status!==null,connected:e.following&&e.status===`live`,received_at_ms:e.received_at_ms,now_ms:e.now_ms}),retries_absorbed:e.session.state.retries_absorbed,scars:e.session.state.scars,cost_usd:e.session.state.cost_usd,cache:{input_tokens:e.session.state.input_tokens,cached_input_tokens:e.session.state.cached_input_tokens,cache_write_tokens:e.session.state.cache_write_tokens,misses:e.session.state.cache_misses}}));return(()=>{var n=Qa(),r=n.firstChild.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling;return I(i,(()=>{var t=Te(()=>e.session.state.run_id===null);return()=>t()?ot:st(e.session.state.run_id)})()),I(r,A(N,{get when(){return e.following},get fallback(){return $a()},get children(){return A(to,{get status(){return e.status},get run_status(){return e.session.state.run_status}})}}),null),I(r,A(N,{get when(){return!e.following},get children(){var t=Za();return t.$$click=()=>e.on_return_to_live(),t}}),null),I(a,A(j,{get each(){return t()},children:e=>(()=>{var t=eo();return I(t,()=>e.text),y(()=>Ae(t,`stats-${e.role}`)),t})()})),I(n,A(Ya,{get session(){return e.session},get viewport(){return e.viewport},get events(){return e.events},get copy_text(){return e.copy_text}}),null),I(n,A(N,{get when(){return e.timeline.count>0},get children(){return[A(ii,{get timeline(){return e.timeline},get fraction(){return e.fraction},get width(){return e.viewport.width},get density(){return e.density},get on_seek(){return e.on_seek}}),A(rt,{get playback(){return e.playback},get density(){return e.density},get on_play_chip(){return e.on_play_chip},get on_toggle_step(){return e.on_toggle_step},get on_cycle_speed(){return e.on_cycle_speed},get on_toggle_compress(){return e.on_toggle_compress},get on_toggle_loop(){return e.on_toggle_loop},get on_toggle_density(){return e.on_toggle_density}})]}}),null),y(()=>F(n,`data-chrome`,e.chrome_hidden?`hidden`:`visible`)),n})()}ke([`click`]);function ro(e){let t;try{t=JSON.parse(e)}catch{return null}return io(t)?t:null}function io(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:typeof e.kind==`string`}function ao(e){let{url:t,open:n,on_frame:r,on_status:i}=e;i(`connecting`);let a=n(t);return a.addEventListener(`open`,()=>{i(`live`)}),a.addEventListener(`trajectory`,e=>{let t=ro(e.data);t!==null&&r(t)}),a.addEventListener(`close`,()=>{i(`offline`)}),a.addEventListener(`error`,()=>{i(`offline`)}),{close:()=>{a.close()}}}var oo=`x-fascicle-cursor`;function so(e,t){let n=An,r=[],i=0;for(let t of e.split(`
4
+ `)){if(t.length===0)continue;let e=ro(t);if(e===null)continue;let a=jn(n,e);Rr(n,a)&&(r=[]),r.push(e),n=a,i+=1}return{session:n,frames:r,count:i,cursor:Math.max(i,t)}}function co(e){if(e===null)return 0;let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:0}function lo(e){return e>0?`api/events?since=${e}`:`api/events`}var uo=`fascicle-viewer:density`;function fo(){try{return localStorage.getItem(uo)===`on`}catch{return!1}}function po(e){try{localStorage.setItem(uo,e?`on`:`off`)}catch{}}async function mo(e){await navigator.clipboard.writeText(e)}function ho(){let e=document.querySelector(`#root`);if(e===null)throw Error(`viewer app: #root is missing from index.html`);let[t,n]=v([]),[r,i]=v({session:An,received_at_ms:null}),[a,o]=v(`connecting`),[s,c]=v(performance.now()),[l,u]=v(_o()),[d,f]=v(null),[p,m]=v(He),[h,g]=v(fo()),[_,y]=v(performance.now());window.addEventListener(`resize`,()=>u(_o()));let S=x(()=>Br(t())),C=x(()=>d()===null),w=x(()=>d()??Math.max(0,S().count-1)),ee=x(()=>d()===null?r().session:Jr(t(),w())),te=x(()=>d()===null?r().received_at_ms:null),ne=x(()=>d()===null?t():t().slice(0,w()+1)),re=x(()=>Be(S().times,p())),ie=x(()=>{let e=p();return e.playing?Ve(re(),S().times,Qe(re(),e,s())):null}),ae=x(()=>$e(p(),_(),s())),oe=e=>{f(e),m(t=>Xe(t,e,s()))},T=e=>{oe(Hr(S(),e))},E=()=>{m(Ze),f(null)},se=()=>{m(e=>Ue(e,d(),S().count,s()))},ce=()=>{let e=S();e.count!==0&&f(Wr(e,w()))},D=()=>{p().stepping?ce():se()},le=()=>{p().stepping||f(qe(d(),S().count)),m(Ke)},ue=()=>{let e=!h();g(e),po(e)};window.addEventListener(`keydown`,e=>{if(e.key===` `){D(),e.preventDefault();return}let t=qr(S(),w(),e.key,e.shiftKey);t!==`ignore`&&(t===`live`?E():oe(t),e.preventDefault())});let de=()=>{y(performance.now())};window.addEventListener(`pointermove`,de),window.addEventListener(`pointerdown`,de),window.addEventListener(`keydown`,de);let O=e=>{c(e),requestAnimationFrame(O)};requestAnimationFrame(O),b(()=>{let e=ie();e!==null&&(f(e.index),e.done&&m(e=>e.loop?{...e,anchor_index:0,anchor_now_ms:s()}:{...e,playing:!1}))}),Oe(()=>A(no,{get session(){return ee()},get events(){return ne()},copy_text:mo,get status(){return a()},get viewport(){return l()},get received_at_ms(){return te()},get now_ms(){return s()},get following(){return C()},get timeline(){return S()},get fraction(){return Vr(S(),w())},get playback(){return p()},get play_t_plus_ms(){return ie()?.t_plus_ms??null},get chrome_hidden(){return ae()},get density(){return h()},on_seek:T,on_return_to_live:E,on_play_chip:D,on_toggle_step:le,on_cycle_speed:()=>m(e=>We(e,w(),s())),on_toggle_compress:()=>m(e=>Ge(e,w(),s())),on_toggle_loop:()=>m(Ye),on_toggle_density:ue}),e),go({set_frames:n,set_feed:i,set_status:o,on_new_run:E})}async function go(e){let t=0,n={session:An,frames:[]};try{let r=await fetch(`api/trajectory`),i=so(await r.text(),co(r.headers.get(oo)));t=i.cursor,i.count>0&&(n={session:i.session,frames:i.frames},e.set_frames(n.frames),e.set_feed({session:n.session,received_at_ms:performance.now()}))}catch{}ao({url:lo(t),open:e=>new EventSource(e),on_status:e.set_status,on_frame:t=>{let r=zr(n,t);n=r,S(()=>{r.started&&e.on_new_run(),e.set_frames(r.frames),e.set_feed({session:r.session,received_at_ms:performance.now()})})}})}function _o(){return{width:window.innerWidth,height:window.innerHeight}}ho();