fascicle 0.12.3 → 0.12.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +61 -6
- package/README.md +3 -2
- package/dist/agents.d.ts +1 -1
- package/dist/agents.js +1 -1
- package/dist/{core-DdJEhyQc.js → core-CFdEjtiT.js} +281 -270
- package/dist/core-CFdEjtiT.js.map +1 -0
- package/dist/{engine-J4lIxpw5.js → engine-DQiQHiy8.js} +182 -34
- package/dist/engine-DQiQHiy8.js.map +1 -0
- package/dist/index.d.ts +28 -2
- package/dist/index.js +48 -4
- package/dist/index.js.map +1 -1
- package/dist/{invoke-CH_eJZeS.js → invoke-eEYMZmWg.js} +3 -3
- package/dist/{invoke-CH_eJZeS.js.map → invoke-eEYMZmWg.js.map} +1 -1
- package/dist/{leading_system-BUCT-PwD.js → leading_system-DQmlA6Fs.js} +2 -2
- package/dist/{leading_system-BUCT-PwD.js.map → leading_system-DQmlA6Fs.js.map} +1 -1
- package/dist/mcp.d.ts +1 -1
- package/dist/mcp.js +1 -1
- package/dist/otel.d.ts +20 -2
- package/dist/otel.js +228 -8
- package/dist/otel.js.map +1 -1
- package/dist/stdio.js +1 -1
- package/dist/testing.d.ts +1 -1
- package/dist/testing.js +3 -3
- package/dist/{types-DU6cvoA4.d.ts → types-CLigYA62.d.ts} +28 -2
- package/dist/viewer-app/assets/index-BGb1-MwM.js +2 -0
- package/dist/viewer-app/assets/index-D7kvKs40.css +1 -0
- package/dist/viewer-app/fonts/sora-OFL.txt +93 -0
- package/dist/viewer-app/fonts/sora-latin.woff2 +0 -0
- package/dist/viewer-app/fonts/spline-sans-mono-OFL.txt +93 -0
- package/dist/viewer-app/fonts/spline-sans-mono-latin.woff2 +0 -0
- package/dist/viewer-app/index.html +13 -0
- package/dist/viewer.d.ts +17 -3
- package/dist/viewer.js +210 -50
- package/dist/viewer.js.map +1 -1
- package/package.json +14 -3
- package/dist/core-DdJEhyQc.js.map +0 -1
- package/dist/engine-J4lIxpw5.js.map +0 -1
- package/dist/static/viewer.html +0 -375
package/dist/otel.js
CHANGED
|
@@ -1,4 +1,189 @@
|
|
|
1
|
-
import { SpanStatusCode, context, trace } from "@opentelemetry/api";
|
|
1
|
+
import { SpanStatusCode, context, metrics, trace } from "@opentelemetry/api";
|
|
2
|
+
//#region src/otel/metrics.ts
|
|
3
|
+
/**
|
|
4
|
+
* Opt-in OpenTelemetry metrics derived from the trajectory stream.
|
|
5
|
+
*
|
|
6
|
+
* The bridge's spans answer "what happened on this run"; SRE dashboards ask
|
|
7
|
+
* aggregate questions ("p95 latency by model", "429s per minute", "tokens per
|
|
8
|
+
* hour"), which want real OTel metric instruments rather than a
|
|
9
|
+
* spans-to-metrics pipeline. This recorder listens to the same trajectory
|
|
10
|
+
* events the span bridge mirrors and records the GenAI semantic-convention
|
|
11
|
+
* client histograms, plus two Fascicle-named instruments for the data the
|
|
12
|
+
* conventions do not cover yet (cost, absorbed retries).
|
|
13
|
+
*
|
|
14
|
+
* Instruments and sources:
|
|
15
|
+
* - `gen_ai.client.token.usage` ({token}) from `response_received`, one
|
|
16
|
+
* point per direction via `gen_ai.token.type`.
|
|
17
|
+
* - `gen_ai.client.operation.duration` (s) from `response_received`
|
|
18
|
+
* `duration_ms`, the model-only round trip.
|
|
19
|
+
* - `gen_ai.client.operation.time_to_first_chunk` (s) from
|
|
20
|
+
* `first_chunk_ms` on streamed turns.
|
|
21
|
+
* - `gen_ai.execute_tool.duration` (s) from `tool_result`, tagged
|
|
22
|
+
* `gen_ai.tool.name`.
|
|
23
|
+
* - `fascicle.client.operation.cost` (usd) from the `cost` event's
|
|
24
|
+
* `total_usd`.
|
|
25
|
+
* - `fascicle.client.turn_retries` ({retry}) counter from `turn_retry`,
|
|
26
|
+
* tagged `error.type` with the classified failure kind.
|
|
27
|
+
*
|
|
28
|
+
* Provider and model attributes come from the enclosing `engine.generate`
|
|
29
|
+
* span's start meta, tracked on a stack with the same documented
|
|
30
|
+
* approximation as the span bridge: concurrent generates sharing one logger
|
|
31
|
+
* attribute to the innermost open call. The semantic conventions are still
|
|
32
|
+
* experimental (mid-2026), so a semconv revision may rename instruments;
|
|
33
|
+
* this module tracks the names at implementation time.
|
|
34
|
+
*/
|
|
35
|
+
/** Semconv-suggested boundaries for the duration histograms, in seconds. */
|
|
36
|
+
const DURATION_BOUNDARIES = [
|
|
37
|
+
.01,
|
|
38
|
+
.02,
|
|
39
|
+
.04,
|
|
40
|
+
.08,
|
|
41
|
+
.16,
|
|
42
|
+
.32,
|
|
43
|
+
.64,
|
|
44
|
+
1.28,
|
|
45
|
+
2.56,
|
|
46
|
+
5.12,
|
|
47
|
+
10.24,
|
|
48
|
+
20.48,
|
|
49
|
+
40.96,
|
|
50
|
+
81.92
|
|
51
|
+
];
|
|
52
|
+
/** Semconv-suggested boundaries for the token-usage histogram. */
|
|
53
|
+
const TOKEN_BOUNDARIES = [
|
|
54
|
+
1,
|
|
55
|
+
4,
|
|
56
|
+
16,
|
|
57
|
+
64,
|
|
58
|
+
256,
|
|
59
|
+
1024,
|
|
60
|
+
4096,
|
|
61
|
+
16384,
|
|
62
|
+
65536,
|
|
63
|
+
262144,
|
|
64
|
+
1048576,
|
|
65
|
+
4194304
|
|
66
|
+
];
|
|
67
|
+
/**
|
|
68
|
+
* Read `key` off the loose event and return it only when it is a number.
|
|
69
|
+
*/
|
|
70
|
+
function event_number(event, key) {
|
|
71
|
+
const value = event[key];
|
|
72
|
+
return typeof value === "number" ? value : void 0;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Read `key` off the loose event and return it only when it is a string.
|
|
76
|
+
*/
|
|
77
|
+
function event_string(event, key) {
|
|
78
|
+
const value = event[key];
|
|
79
|
+
return typeof value === "string" ? value : void 0;
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Create the metrics recorder: instruments are created once here, and every
|
|
83
|
+
* recording stamps the provider/model of the innermost open generate call.
|
|
84
|
+
*/
|
|
85
|
+
function create_metrics_recorder(options) {
|
|
86
|
+
const meter = options.meter ?? metrics.getMeter("fascicle");
|
|
87
|
+
const token_usage = meter.createHistogram("gen_ai.client.token.usage", {
|
|
88
|
+
unit: "{token}",
|
|
89
|
+
description: "Number of input and output tokens used per model turn",
|
|
90
|
+
advice: { explicitBucketBoundaries: TOKEN_BOUNDARIES }
|
|
91
|
+
});
|
|
92
|
+
const operation_duration = meter.createHistogram("gen_ai.client.operation.duration", {
|
|
93
|
+
unit: "s",
|
|
94
|
+
description: "Model round-trip duration of the successful turn attempt",
|
|
95
|
+
advice: { explicitBucketBoundaries: DURATION_BOUNDARIES }
|
|
96
|
+
});
|
|
97
|
+
const time_to_first_chunk = meter.createHistogram("gen_ai.client.operation.time_to_first_chunk", {
|
|
98
|
+
unit: "s",
|
|
99
|
+
description: "Time from turn start to the first streamed chunk",
|
|
100
|
+
advice: { explicitBucketBoundaries: DURATION_BOUNDARIES }
|
|
101
|
+
});
|
|
102
|
+
const tool_duration = meter.createHistogram("gen_ai.execute_tool.duration", {
|
|
103
|
+
unit: "s",
|
|
104
|
+
description: "Tool execution duration",
|
|
105
|
+
advice: { explicitBucketBoundaries: DURATION_BOUNDARIES }
|
|
106
|
+
});
|
|
107
|
+
const cost = meter.createHistogram("fascicle.client.operation.cost", {
|
|
108
|
+
unit: "usd",
|
|
109
|
+
description: "Estimated cost per model turn"
|
|
110
|
+
});
|
|
111
|
+
const retries = meter.createCounter("fascicle.client.turn_retries", {
|
|
112
|
+
unit: "{retry}",
|
|
113
|
+
description: "Provider turn attempts that failed and were retried"
|
|
114
|
+
});
|
|
115
|
+
const generate_ids = /* @__PURE__ */ new Set();
|
|
116
|
+
const context_stack = [];
|
|
117
|
+
const base_attributes = () => {
|
|
118
|
+
const attrs = { "gen_ai.operation.name": "chat" };
|
|
119
|
+
const top = context_stack[context_stack.length - 1];
|
|
120
|
+
if (top?.provider !== void 0) attrs["gen_ai.provider.name"] = top.provider;
|
|
121
|
+
if (top?.model !== void 0) attrs["gen_ai.request.model"] = top.model;
|
|
122
|
+
return attrs;
|
|
123
|
+
};
|
|
124
|
+
const on_response_received = (event) => {
|
|
125
|
+
const base = base_attributes();
|
|
126
|
+
const input = event_number(event, "input_tokens");
|
|
127
|
+
if (input !== void 0) token_usage.record(input, {
|
|
128
|
+
...base,
|
|
129
|
+
"gen_ai.token.type": "input"
|
|
130
|
+
});
|
|
131
|
+
const output = event_number(event, "output_tokens");
|
|
132
|
+
if (output !== void 0) token_usage.record(output, {
|
|
133
|
+
...base,
|
|
134
|
+
"gen_ai.token.type": "output"
|
|
135
|
+
});
|
|
136
|
+
const duration_ms = event_number(event, "duration_ms");
|
|
137
|
+
if (duration_ms !== void 0) operation_duration.record(duration_ms / 1e3, base);
|
|
138
|
+
const first_chunk_ms = event_number(event, "first_chunk_ms");
|
|
139
|
+
if (first_chunk_ms !== void 0) time_to_first_chunk.record(first_chunk_ms / 1e3, base);
|
|
140
|
+
};
|
|
141
|
+
return {
|
|
142
|
+
on_start_span(id, name, meta) {
|
|
143
|
+
if (name !== "engine.generate") return;
|
|
144
|
+
generate_ids.add(id);
|
|
145
|
+
const provider = meta?.["provider"];
|
|
146
|
+
const model = meta?.["model_id"];
|
|
147
|
+
context_stack.push({
|
|
148
|
+
...typeof provider === "string" ? { provider } : {},
|
|
149
|
+
...typeof model === "string" ? { model } : {}
|
|
150
|
+
});
|
|
151
|
+
},
|
|
152
|
+
on_end_span(id) {
|
|
153
|
+
if (!generate_ids.delete(id)) return;
|
|
154
|
+
context_stack.pop();
|
|
155
|
+
},
|
|
156
|
+
on_record(event) {
|
|
157
|
+
if (event.kind === "response_received") {
|
|
158
|
+
on_response_received(event);
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (event.kind === "tool_result") {
|
|
162
|
+
const duration_ms = event_number(event, "duration_ms");
|
|
163
|
+
if (duration_ms === void 0) return;
|
|
164
|
+
const name = event_string(event, "name");
|
|
165
|
+
tool_duration.record(duration_ms / 1e3, {
|
|
166
|
+
...base_attributes(),
|
|
167
|
+
...name !== void 0 ? { "gen_ai.tool.name": name } : {}
|
|
168
|
+
});
|
|
169
|
+
return;
|
|
170
|
+
}
|
|
171
|
+
if (event.kind === "cost") {
|
|
172
|
+
const total_usd = event_number(event, "total_usd");
|
|
173
|
+
if (total_usd !== void 0) cost.record(total_usd, base_attributes());
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
if (event.kind === "turn_retry") {
|
|
177
|
+
const failure_kind = event_string(event, "failure_kind");
|
|
178
|
+
retries.add(1, {
|
|
179
|
+
...base_attributes(),
|
|
180
|
+
...failure_kind !== void 0 ? { "error.type": failure_kind } : {}
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
//#endregion
|
|
2
187
|
//#region src/otel/trajectory_logger.ts
|
|
3
188
|
/**
|
|
4
189
|
* OpenTelemetry bridge for Fascicle trajectory events.
|
|
@@ -11,10 +196,10 @@ import { SpanStatusCode, context, trace } from "@opentelemetry/api";
|
|
|
11
196
|
* spans come from events the engine already emits, so native and external
|
|
12
197
|
* transports get traces without any AI-SDK involvement.
|
|
13
198
|
*
|
|
14
|
-
*
|
|
15
|
-
* outside `src/engine/` on purpose: the engine's `ai + zod`
|
|
16
|
-
* holds unmodified, and an app that never imports
|
|
17
|
-
* zero OTel packages at runtime.
|
|
199
|
+
* `@opentelemetry/api` is imported ONLY under `src/otel/` (this module and
|
|
200
|
+
* metrics.ts), outside `src/engine/` on purpose: the engine's `ai + zod`
|
|
201
|
+
* npm-dep invariant holds unmodified, and an app that never imports
|
|
202
|
+
* `fascicle/otel` pulls in zero OTel packages at runtime.
|
|
18
203
|
*
|
|
19
204
|
* Nesting is resolved two ways, in order: an explicit `parent_span_id` on the
|
|
20
205
|
* start meta (how the composition runner threads composer-span parenthood) wins;
|
|
@@ -60,17 +245,48 @@ function to_attribute_value(value) {
|
|
|
60
245
|
return safe_json(value);
|
|
61
246
|
}
|
|
62
247
|
/**
|
|
248
|
+
* True for a plain object value (not null, not an array): the shape span-meta
|
|
249
|
+
* flattening applies to.
|
|
250
|
+
*/
|
|
251
|
+
function is_plain_object(value) {
|
|
252
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Spread one object-valued span-meta field into dotted attribute keys
|
|
256
|
+
* (`usage` + `input_tokens` becomes `<prefix>usage.input_tokens`), with
|
|
257
|
+
* deeper nesting falling back to `to_attribute_value`'s JSON form.
|
|
258
|
+
*/
|
|
259
|
+
function flatten_into(attrs, key, value, prefix) {
|
|
260
|
+
for (const [inner_key, inner_value] of Object.entries(value)) {
|
|
261
|
+
const attr = to_attribute_value(inner_value);
|
|
262
|
+
if (attr !== void 0) attrs[`${prefix}${key}.${inner_key}`] = attr;
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
63
266
|
* Build an OTel `Attributes` object from event/meta fields.
|
|
64
267
|
*
|
|
65
268
|
* Skips the bridge's internal plumbing keys (`kind`, `span_id`,
|
|
66
269
|
* `parent_span_id`) and prefixes the rest with `prefix` so they stay out of
|
|
67
270
|
* OTel's semantic-convention namespace.
|
|
271
|
+
*
|
|
272
|
+
* With `flatten`, an object-valued field spreads one level into dotted keys
|
|
273
|
+
* (`usage: { input_tokens: 5 }` becomes `<prefix>usage.input_tokens = 5`), so
|
|
274
|
+
* span metadata like usage and model_resolved lands as numeric attributes a
|
|
275
|
+
* dashboard can aggregate rather than a JSON string it cannot query. Flattening
|
|
276
|
+
* applies to span meta only, never to `record`ed events: an event may carry
|
|
277
|
+
* arbitrary payloads (a tool call's input, a salvage blob) where
|
|
278
|
+
* attribute-per-key would explode cardinality and leak structure, so those
|
|
279
|
+
* keep the JSON-string fallback.
|
|
68
280
|
*/
|
|
69
|
-
function to_attributes(meta, prefix) {
|
|
281
|
+
function to_attributes(meta, prefix, flatten = false) {
|
|
70
282
|
const attrs = {};
|
|
71
283
|
if (meta === void 0) return attrs;
|
|
72
284
|
for (const [key, value] of Object.entries(meta)) {
|
|
73
285
|
if (INTERNAL_KEYS.has(key)) continue;
|
|
286
|
+
if (flatten && is_plain_object(value)) {
|
|
287
|
+
flatten_into(attrs, key, value, prefix);
|
|
288
|
+
continue;
|
|
289
|
+
}
|
|
74
290
|
const attr = to_attribute_value(value);
|
|
75
291
|
if (attr !== void 0) attrs[`${prefix}${key}`] = attr;
|
|
76
292
|
}
|
|
@@ -86,6 +302,7 @@ function to_attributes(meta, prefix) {
|
|
|
86
302
|
function create_otel_trajectory_logger(options = {}) {
|
|
87
303
|
const tracer = options.tracer ?? trace.getTracer("fascicle");
|
|
88
304
|
const prefix = options.attribute_prefix ?? "fascicle.";
|
|
305
|
+
const metrics_recorder = options.metrics === void 0 || options.metrics === false ? void 0 : create_metrics_recorder(options.metrics === true ? {} : options.metrics);
|
|
89
306
|
const open = /* @__PURE__ */ new Map();
|
|
90
307
|
const stack = [];
|
|
91
308
|
let counter = 0;
|
|
@@ -113,7 +330,7 @@ function create_otel_trajectory_logger(options = {}) {
|
|
|
113
330
|
return {
|
|
114
331
|
start_span(name, meta) {
|
|
115
332
|
const parent = parent_context(meta);
|
|
116
|
-
const span = tracer.startSpan(name, { attributes: to_attributes(meta, prefix) }, parent);
|
|
333
|
+
const span = tracer.startSpan(name, { attributes: to_attributes(meta, prefix, true) }, parent);
|
|
117
334
|
counter += 1;
|
|
118
335
|
const id = `fascicle-otel-${counter}`;
|
|
119
336
|
open.set(id, {
|
|
@@ -121,13 +338,15 @@ function create_otel_trajectory_logger(options = {}) {
|
|
|
121
338
|
context: trace.setSpan(parent, span)
|
|
122
339
|
});
|
|
123
340
|
stack.push(id);
|
|
341
|
+
metrics_recorder?.on_start_span(id, name, meta);
|
|
124
342
|
return id;
|
|
125
343
|
},
|
|
126
344
|
end_span(id, meta) {
|
|
345
|
+
metrics_recorder?.on_end_span(id);
|
|
127
346
|
const entry = open.get(id);
|
|
128
347
|
if (entry === void 0) return;
|
|
129
348
|
const { span } = entry;
|
|
130
|
-
span.setAttributes(to_attributes(meta, prefix));
|
|
349
|
+
span.setAttributes(to_attributes(meta, prefix, true));
|
|
131
350
|
const error = meta?.["error"];
|
|
132
351
|
if (typeof error === "string" && error.length > 0) span.setStatus({
|
|
133
352
|
code: SpanStatusCode.ERROR,
|
|
@@ -139,6 +358,7 @@ function create_otel_trajectory_logger(options = {}) {
|
|
|
139
358
|
if (idx !== -1) stack.splice(idx, 1);
|
|
140
359
|
},
|
|
141
360
|
record(event) {
|
|
361
|
+
metrics_recorder?.on_record(event);
|
|
142
362
|
const span = target_for_event(event);
|
|
143
363
|
if (span === void 0) return;
|
|
144
364
|
const name = typeof event.kind === "string" ? event.kind : "event";
|
package/dist/otel.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"otel.js","names":["otel_context"],"sources":["../src/otel/trajectory_logger.ts"],"sourcesContent":["/**\n * OpenTelemetry bridge for Fascicle trajectory events.\n *\n * `create_otel_trajectory_logger` returns a plain TrajectoryLogger that turns\n * the engine's own span + event stream into OpenTelemetry spans: the\n * `engine.generate` span becomes an OTel root span, each `engine.generate.step`\n * a child span, and every `record`ed event (tool_call, tool_result, cost, ...)\n * an OTel span event on the currently open span. It is transport-neutral: the\n * spans come from events the engine already emits, so native and external\n * transports get traces without any AI-SDK involvement.\n *\n * This module is the ONLY place `@opentelemetry/api` is imported, and it lives\n * outside `src/engine/` on purpose: the engine's `ai + zod` npm-dep invariant\n * holds unmodified, and an app that never imports `fascicle/otel` pulls in\n * zero OTel packages at runtime.\n *\n * Nesting is resolved two ways, in order: an explicit `parent_span_id` on the\n * start meta (how the composition runner threads composer-span parenthood) wins;\n * otherwise the currently open span (top of the open stack) is the parent. This\n * is exact for the sequential engine flow (generate → step → step) and for\n * runner-nested spans; genuinely interleaved sibling spans that carry no\n * `parent_span_id` (concurrent branches sharing one logger) fall back to stack\n * order, which is this bridge's one documented approximation.\n */\n\nimport {\n context as otel_context,\n trace,\n SpanStatusCode,\n type AttributeValue,\n type Attributes,\n type Context,\n type Span,\n type Tracer,\n} from '@opentelemetry/api'\nimport type { TrajectoryEvent, TrajectoryLogger } from '#core'\n\nexport type OtelTrajectoryLoggerOptions = {\n /**\n * Tracer to open spans on. Defaults to `trace.getTracer('fascicle')`, which\n * resolves against whatever global TracerProvider the host has registered.\n */\n readonly tracer?: Tracer\n /**\n * Prefix for span + event attributes derived from event metadata, keeping\n * them out of the OTel semantic-convention namespace. Defaults to `fascicle.`.\n */\n readonly attribute_prefix?: string\n}\n\n// Event/meta keys that are bridge plumbing, not span attributes.\nconst INTERNAL_KEYS: ReadonlySet<string> = new Set(['kind', 'span_id', 'parent_span_id'])\n\n/**\n * JSON-stringify `value`, falling back to `String(value)` when `stringify`\n * throws or returns `undefined`, as it does for functions and symbols.\n */\nfunction safe_json(value: unknown): string {\n try {\n return JSON.stringify(value) ?? String(value)\n } catch {\n return String(value)\n }\n}\n\n/**\n * Convert a JS value into an OTel-compatible attribute value.\n *\n * Primitives and homogeneous primitive arrays pass through unchanged;\n * anything else falls back to `safe_json`; `null`/`undefined` drop out\n * entirely (returning `undefined`) so the caller can omit the attribute.\n */\nfunction to_attribute_value(value: unknown): AttributeValue | undefined {\n if (value === null || value === undefined) return undefined\n const kind = typeof value\n if (kind === 'string' || kind === 'number' || kind === 'boolean') {\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion\n return value as AttributeValue\n }\n if (Array.isArray(value)) {\n if (value.every((v) => typeof v === 'string')) return value\n if (value.every((v) => typeof v === 'number')) return value\n if (value.every((v) => typeof v === 'boolean')) return value\n return safe_json(value)\n }\n return safe_json(value)\n}\n\n/**\n * Build an OTel `Attributes` object from event/meta fields.\n *\n * Skips the bridge's internal plumbing keys (`kind`, `span_id`,\n * `parent_span_id`) and prefixes the rest with `prefix` so they stay out of\n * OTel's semantic-convention namespace.\n */\nfunction to_attributes(\n meta: Readonly<Record<string, unknown>> | undefined,\n prefix: string,\n): Attributes {\n const attrs: Attributes = {}\n if (meta === undefined) return attrs\n for (const [key, value] of Object.entries(meta)) {\n if (INTERNAL_KEYS.has(key)) continue\n const attr = to_attribute_value(value)\n if (attr !== undefined) attrs[`${prefix}${key}`] = attr\n }\n return attrs\n}\n\ntype OpenSpan = { readonly span: Span; readonly context: Context }\n\n/**\n * Create a `TrajectoryLogger` that mirrors spans and events onto\n * OpenTelemetry, using `options.tracer` (or the global `fascicle` tracer).\n *\n * Parent resolution favors an explicit `parent_span_id` on the start meta;\n * otherwise it falls back to the currently open span on an internal stack.\n */\nexport function create_otel_trajectory_logger(\n options: OtelTrajectoryLoggerOptions = {},\n): TrajectoryLogger {\n const tracer = options.tracer ?? trace.getTracer('fascicle')\n const prefix = options.attribute_prefix ?? 'fascicle.'\n const open = new Map<string, OpenSpan>()\n const stack: string[] = []\n let counter = 0\n\n const top_context = (): Context | undefined => {\n const top = stack[stack.length - 1]\n if (top === undefined) return undefined\n return open.get(top)?.context\n }\n\n const parent_context = (meta: Record<string, unknown> | undefined): Context => {\n const explicit = meta?.['parent_span_id']\n if (typeof explicit === 'string') {\n const parent = open.get(explicit)\n if (parent !== undefined) return parent.context\n }\n return top_context() ?? otel_context.active()\n }\n\n const target_for_event = (event: TrajectoryEvent): Span | undefined => {\n if (typeof event.span_id === 'string') {\n const target = open.get(event.span_id)\n if (target !== undefined) return target.span\n }\n const top = stack[stack.length - 1]\n return top !== undefined ? open.get(top)?.span : undefined\n }\n\n return {\n start_span(name, meta) {\n const parent = parent_context(meta)\n const span = tracer.startSpan(name, { attributes: to_attributes(meta, prefix) }, parent)\n counter += 1\n const id = `fascicle-otel-${counter}`\n open.set(id, { span, context: trace.setSpan(parent, span) })\n stack.push(id)\n return id\n },\n end_span(id, meta) {\n const entry = open.get(id)\n if (entry === undefined) return\n const { span } = entry\n span.setAttributes(to_attributes(meta, prefix))\n const error = meta?.['error']\n if (typeof error === 'string' && error.length > 0) {\n span.setStatus({ code: SpanStatusCode.ERROR, message: error })\n }\n span.end()\n open.delete(id)\n const idx = stack.lastIndexOf(id)\n if (idx !== -1) stack.splice(idx, 1)\n },\n record(event) {\n const span = target_for_event(event)\n if (span === undefined) return\n const name = typeof event.kind === 'string' ? event.kind : 'event'\n span.addEvent(name, to_attributes(event, prefix))\n },\n }\n}\n"],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"otel.js","names":["otel_metrics","otel_context"],"sources":["../src/otel/metrics.ts","../src/otel/trajectory_logger.ts"],"sourcesContent":["/**\n * Opt-in OpenTelemetry metrics derived from the trajectory stream.\n *\n * The bridge's spans answer \"what happened on this run\"; SRE dashboards ask\n * aggregate questions (\"p95 latency by model\", \"429s per minute\", \"tokens per\n * hour\"), which want real OTel metric instruments rather than a\n * spans-to-metrics pipeline. This recorder listens to the same trajectory\n * events the span bridge mirrors and records the GenAI semantic-convention\n * client histograms, plus two Fascicle-named instruments for the data the\n * conventions do not cover yet (cost, absorbed retries).\n *\n * Instruments and sources:\n * - `gen_ai.client.token.usage` ({token}) from `response_received`, one\n * point per direction via `gen_ai.token.type`.\n * - `gen_ai.client.operation.duration` (s) from `response_received`\n * `duration_ms`, the model-only round trip.\n * - `gen_ai.client.operation.time_to_first_chunk` (s) from\n * `first_chunk_ms` on streamed turns.\n * - `gen_ai.execute_tool.duration` (s) from `tool_result`, tagged\n * `gen_ai.tool.name`.\n * - `fascicle.client.operation.cost` (usd) from the `cost` event's\n * `total_usd`.\n * - `fascicle.client.turn_retries` ({retry}) counter from `turn_retry`,\n * tagged `error.type` with the classified failure kind.\n *\n * Provider and model attributes come from the enclosing `engine.generate`\n * span's start meta, tracked on a stack with the same documented\n * approximation as the span bridge: concurrent generates sharing one logger\n * attribute to the innermost open call. The semantic conventions are still\n * experimental (mid-2026), so a semconv revision may rename instruments;\n * this module tracks the names at implementation time.\n */\n\nimport {\n metrics as otel_metrics,\n type Attributes,\n type Counter,\n type Histogram,\n type Meter,\n} from '@opentelemetry/api'\nimport type { TrajectoryEvent } from '#core'\n\nexport type OtelMetricsOptions = {\n /**\n * Meter to create instruments on. Defaults to\n * `metrics.getMeter('fascicle')`, which resolves against the global\n * MeterProvider the host has registered.\n */\n readonly meter?: Meter\n}\n\n/**\n * The span-lifecycle + event listener the trajectory logger drives when\n * metrics are enabled.\n */\nexport type MetricsRecorder = {\n readonly on_start_span: (\n id: string,\n name: string,\n meta: Record<string, unknown> | undefined,\n ) => void\n readonly on_end_span: (id: string) => void\n readonly on_record: (event: TrajectoryEvent) => void\n}\n\n/** Semconv-suggested boundaries for the duration histograms, in seconds. */\nconst DURATION_BOUNDARIES = [\n 0.01, 0.02, 0.04, 0.08, 0.16, 0.32, 0.64, 1.28, 2.56, 5.12, 10.24, 20.48,\n 40.96, 81.92,\n]\n\n/** Semconv-suggested boundaries for the token-usage histogram. */\nconst TOKEN_BOUNDARIES = [\n 1, 4, 16, 64, 256, 1024, 4096, 16384, 65536, 262144, 1048576, 4194304,\n]\n\n/**\n * Read `key` off the loose event and return it only when it is a number.\n */\nfunction event_number(event: TrajectoryEvent, key: string): number | undefined {\n const value = event[key]\n return typeof value === 'number' ? value : undefined\n}\n\n/**\n * Read `key` off the loose event and return it only when it is a string.\n */\nfunction event_string(event: TrajectoryEvent, key: string): string | undefined {\n const value = event[key]\n return typeof value === 'string' ? value : undefined\n}\n\n/**\n * Create the metrics recorder: instruments are created once here, and every\n * recording stamps the provider/model of the innermost open generate call.\n */\nexport function create_metrics_recorder(options: OtelMetricsOptions): MetricsRecorder {\n const meter = options.meter ?? otel_metrics.getMeter('fascicle')\n\n const token_usage: Histogram = meter.createHistogram('gen_ai.client.token.usage', {\n unit: '{token}',\n description: 'Number of input and output tokens used per model turn',\n advice: { explicitBucketBoundaries: TOKEN_BOUNDARIES },\n })\n const operation_duration: Histogram = meter.createHistogram(\n 'gen_ai.client.operation.duration',\n {\n unit: 's',\n description: 'Model round-trip duration of the successful turn attempt',\n advice: { explicitBucketBoundaries: DURATION_BOUNDARIES },\n },\n )\n const time_to_first_chunk: Histogram = meter.createHistogram(\n 'gen_ai.client.operation.time_to_first_chunk',\n {\n unit: 's',\n description: 'Time from turn start to the first streamed chunk',\n advice: { explicitBucketBoundaries: DURATION_BOUNDARIES },\n },\n )\n const tool_duration: Histogram = meter.createHistogram('gen_ai.execute_tool.duration', {\n unit: 's',\n description: 'Tool execution duration',\n advice: { explicitBucketBoundaries: DURATION_BOUNDARIES },\n })\n const cost: Histogram = meter.createHistogram('fascicle.client.operation.cost', {\n unit: 'usd',\n description: 'Estimated cost per model turn',\n })\n const retries: Counter = meter.createCounter('fascicle.client.turn_retries', {\n unit: '{retry}',\n description: 'Provider turn attempts that failed and were retried',\n })\n\n // Innermost open engine.generate call's identity, for metric attributes.\n const generate_ids = new Set<string>()\n const context_stack: Array<{ provider?: string; model?: string }> = []\n\n const base_attributes = (): Attributes => {\n const attrs: Attributes = { 'gen_ai.operation.name': 'chat' }\n const top = context_stack[context_stack.length - 1]\n if (top?.provider !== undefined) attrs['gen_ai.provider.name'] = top.provider\n if (top?.model !== undefined) attrs['gen_ai.request.model'] = top.model\n return attrs\n }\n\n const on_response_received = (event: TrajectoryEvent): void => {\n const base = base_attributes()\n const input = event_number(event, 'input_tokens')\n if (input !== undefined) {\n token_usage.record(input, { ...base, 'gen_ai.token.type': 'input' })\n }\n const output = event_number(event, 'output_tokens')\n if (output !== undefined) {\n token_usage.record(output, { ...base, 'gen_ai.token.type': 'output' })\n }\n const duration_ms = event_number(event, 'duration_ms')\n if (duration_ms !== undefined) operation_duration.record(duration_ms / 1000, base)\n const first_chunk_ms = event_number(event, 'first_chunk_ms')\n if (first_chunk_ms !== undefined) {\n time_to_first_chunk.record(first_chunk_ms / 1000, base)\n }\n }\n\n return {\n on_start_span(id, name, meta) {\n if (name !== 'engine.generate') return\n generate_ids.add(id)\n const provider = meta?.['provider']\n const model = meta?.['model_id']\n context_stack.push({\n ...(typeof provider === 'string' ? { provider } : {}),\n ...(typeof model === 'string' ? { model } : {}),\n })\n },\n on_end_span(id) {\n if (!generate_ids.delete(id)) return\n context_stack.pop()\n },\n on_record(event) {\n if (event.kind === 'response_received') {\n on_response_received(event)\n return\n }\n if (event.kind === 'tool_result') {\n const duration_ms = event_number(event, 'duration_ms')\n if (duration_ms === undefined) return\n const name = event_string(event, 'name')\n tool_duration.record(duration_ms / 1000, {\n ...base_attributes(),\n ...(name !== undefined ? { 'gen_ai.tool.name': name } : {}),\n })\n return\n }\n if (event.kind === 'cost') {\n const total_usd = event_number(event, 'total_usd')\n if (total_usd !== undefined) cost.record(total_usd, base_attributes())\n return\n }\n if (event.kind === 'turn_retry') {\n const failure_kind = event_string(event, 'failure_kind')\n retries.add(1, {\n ...base_attributes(),\n ...(failure_kind !== undefined ? { 'error.type': failure_kind } : {}),\n })\n }\n },\n }\n}\n","/**\n * OpenTelemetry bridge for Fascicle trajectory events.\n *\n * `create_otel_trajectory_logger` returns a plain TrajectoryLogger that turns\n * the engine's own span + event stream into OpenTelemetry spans: the\n * `engine.generate` span becomes an OTel root span, each `engine.generate.step`\n * a child span, and every `record`ed event (tool_call, tool_result, cost, ...)\n * an OTel span event on the currently open span. It is transport-neutral: the\n * spans come from events the engine already emits, so native and external\n * transports get traces without any AI-SDK involvement.\n *\n * `@opentelemetry/api` is imported ONLY under `src/otel/` (this module and\n * metrics.ts), outside `src/engine/` on purpose: the engine's `ai + zod`\n * npm-dep invariant holds unmodified, and an app that never imports\n * `fascicle/otel` pulls in zero OTel packages at runtime.\n *\n * Nesting is resolved two ways, in order: an explicit `parent_span_id` on the\n * start meta (how the composition runner threads composer-span parenthood) wins;\n * otherwise the currently open span (top of the open stack) is the parent. This\n * is exact for the sequential engine flow (generate → step → step) and for\n * runner-nested spans; genuinely interleaved sibling spans that carry no\n * `parent_span_id` (concurrent branches sharing one logger) fall back to stack\n * order, which is this bridge's one documented approximation.\n */\n\nimport {\n context as otel_context,\n trace,\n SpanStatusCode,\n type AttributeValue,\n type Attributes,\n type Context,\n type Span,\n type Tracer,\n} from '@opentelemetry/api'\nimport type { TrajectoryEvent, TrajectoryLogger } from '#core'\nimport { create_metrics_recorder, type OtelMetricsOptions } from './metrics.js'\n\nexport type OtelTrajectoryLoggerOptions = {\n /**\n * Tracer to open spans on. Defaults to `trace.getTracer('fascicle')`, which\n * resolves against whatever global TracerProvider the host has registered.\n */\n readonly tracer?: Tracer\n /**\n * Prefix for span + event attributes derived from event metadata, keeping\n * them out of the OTel semantic-convention namespace. Defaults to `fascicle.`.\n */\n readonly attribute_prefix?: string\n /**\n * Opt-in metric instruments recorded from the same trajectory stream the\n * spans mirror (GenAI semconv client histograms plus Fascicle's cost and\n * retry instruments; see metrics.ts). `true` uses the global MeterProvider's\n * `fascicle` meter; an object supplies a custom Meter. Off by default so the\n * bridge stays a pure tracer for hosts without a metrics pipeline.\n */\n readonly metrics?: boolean | OtelMetricsOptions\n}\n\n// Event/meta keys that are bridge plumbing, not span attributes.\nconst INTERNAL_KEYS: ReadonlySet<string> = new Set(['kind', 'span_id', 'parent_span_id'])\n\n/**\n * JSON-stringify `value`, falling back to `String(value)` when `stringify`\n * throws or returns `undefined`, as it does for functions and symbols.\n */\nfunction safe_json(value: unknown): string {\n try {\n return JSON.stringify(value) ?? String(value)\n } catch {\n return String(value)\n }\n}\n\n/**\n * Convert a JS value into an OTel-compatible attribute value.\n *\n * Primitives and homogeneous primitive arrays pass through unchanged;\n * anything else falls back to `safe_json`; `null`/`undefined` drop out\n * entirely (returning `undefined`) so the caller can omit the attribute.\n */\nfunction to_attribute_value(value: unknown): AttributeValue | undefined {\n if (value === null || value === undefined) return undefined\n const kind = typeof value\n if (kind === 'string' || kind === 'number' || kind === 'boolean') {\n // oxlint-disable-next-line typescript-eslint/no-unsafe-type-assertion\n return value as AttributeValue\n }\n if (Array.isArray(value)) {\n if (value.every((v) => typeof v === 'string')) return value\n if (value.every((v) => typeof v === 'number')) return value\n if (value.every((v) => typeof v === 'boolean')) return value\n return safe_json(value)\n }\n return safe_json(value)\n}\n\n/**\n * True for a plain object value (not null, not an array): the shape span-meta\n * flattening applies to.\n */\nfunction is_plain_object(value: unknown): value is Record<string, unknown> {\n return value !== null && typeof value === 'object' && !Array.isArray(value)\n}\n\n/**\n * Spread one object-valued span-meta field into dotted attribute keys\n * (`usage` + `input_tokens` becomes `<prefix>usage.input_tokens`), with\n * deeper nesting falling back to `to_attribute_value`'s JSON form.\n */\nfunction flatten_into(\n attrs: Attributes,\n key: string,\n value: Record<string, unknown>,\n prefix: string,\n): void {\n for (const [inner_key, inner_value] of Object.entries(value)) {\n const attr = to_attribute_value(inner_value)\n if (attr !== undefined) attrs[`${prefix}${key}.${inner_key}`] = attr\n }\n}\n\n/**\n * Build an OTel `Attributes` object from event/meta fields.\n *\n * Skips the bridge's internal plumbing keys (`kind`, `span_id`,\n * `parent_span_id`) and prefixes the rest with `prefix` so they stay out of\n * OTel's semantic-convention namespace.\n *\n * With `flatten`, an object-valued field spreads one level into dotted keys\n * (`usage: { input_tokens: 5 }` becomes `<prefix>usage.input_tokens = 5`), so\n * span metadata like usage and model_resolved lands as numeric attributes a\n * dashboard can aggregate rather than a JSON string it cannot query. Flattening\n * applies to span meta only, never to `record`ed events: an event may carry\n * arbitrary payloads (a tool call's input, a salvage blob) where\n * attribute-per-key would explode cardinality and leak structure, so those\n * keep the JSON-string fallback.\n */\nfunction to_attributes(\n meta: Readonly<Record<string, unknown>> | undefined,\n prefix: string,\n flatten = false,\n): Attributes {\n const attrs: Attributes = {}\n if (meta === undefined) return attrs\n for (const [key, value] of Object.entries(meta)) {\n if (INTERNAL_KEYS.has(key)) continue\n if (flatten && is_plain_object(value)) {\n flatten_into(attrs, key, value, prefix)\n continue\n }\n const attr = to_attribute_value(value)\n if (attr !== undefined) attrs[`${prefix}${key}`] = attr\n }\n return attrs\n}\n\ntype OpenSpan = { readonly span: Span; readonly context: Context }\n\n/**\n * Create a `TrajectoryLogger` that mirrors spans and events onto\n * OpenTelemetry, using `options.tracer` (or the global `fascicle` tracer).\n *\n * Parent resolution favors an explicit `parent_span_id` on the start meta;\n * otherwise it falls back to the currently open span on an internal stack.\n */\nexport function create_otel_trajectory_logger(\n options: OtelTrajectoryLoggerOptions = {},\n): TrajectoryLogger {\n const tracer = options.tracer ?? trace.getTracer('fascicle')\n const prefix = options.attribute_prefix ?? 'fascicle.'\n const metrics_recorder =\n options.metrics === undefined || options.metrics === false\n ? undefined\n : create_metrics_recorder(options.metrics === true ? {} : options.metrics)\n const open = new Map<string, OpenSpan>()\n const stack: string[] = []\n let counter = 0\n\n const top_context = (): Context | undefined => {\n const top = stack[stack.length - 1]\n if (top === undefined) return undefined\n return open.get(top)?.context\n }\n\n const parent_context = (meta: Record<string, unknown> | undefined): Context => {\n const explicit = meta?.['parent_span_id']\n if (typeof explicit === 'string') {\n const parent = open.get(explicit)\n if (parent !== undefined) return parent.context\n }\n return top_context() ?? otel_context.active()\n }\n\n const target_for_event = (event: TrajectoryEvent): Span | undefined => {\n if (typeof event.span_id === 'string') {\n const target = open.get(event.span_id)\n if (target !== undefined) return target.span\n }\n const top = stack[stack.length - 1]\n return top !== undefined ? open.get(top)?.span : undefined\n }\n\n return {\n start_span(name, meta) {\n const parent = parent_context(meta)\n const span = tracer.startSpan(\n name,\n { attributes: to_attributes(meta, prefix, true) },\n parent,\n )\n counter += 1\n const id = `fascicle-otel-${counter}`\n open.set(id, { span, context: trace.setSpan(parent, span) })\n stack.push(id)\n metrics_recorder?.on_start_span(id, name, meta)\n return id\n },\n end_span(id, meta) {\n metrics_recorder?.on_end_span(id)\n const entry = open.get(id)\n if (entry === undefined) return\n const { span } = entry\n span.setAttributes(to_attributes(meta, prefix, true))\n const error = meta?.['error']\n if (typeof error === 'string' && error.length > 0) {\n span.setStatus({ code: SpanStatusCode.ERROR, message: error })\n }\n span.end()\n open.delete(id)\n const idx = stack.lastIndexOf(id)\n if (idx !== -1) stack.splice(idx, 1)\n },\n record(event) {\n metrics_recorder?.on_record(event)\n const span = target_for_event(event)\n if (span === undefined) return\n const name = typeof event.kind === 'string' ? event.kind : 'event'\n span.addEvent(name, to_attributes(event, prefix))\n },\n }\n}\n"],"mappings":"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"}
|
package/dist/stdio.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { T as run, s as validate_schema } from "./core-CFdEjtiT.js";
|
|
2
2
|
import { r as stderr_logger } from "./adapters-CutexJd3.js";
|
|
3
3
|
import { text } from "node:stream/consumers";
|
|
4
4
|
//#region src/stdio/execute_stdio.ts
|
package/dist/testing.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { M as UsageTotals, O as ToolCallRecord, a as Engine, c as FinishReason, l as GenerateOptions, u as GenerateResult } from "./types-CLigYA62.js";
|
|
2
2
|
|
|
3
3
|
//#region src/testing/engine_from_generate.d.ts
|
|
4
4
|
/**
|
package/dist/testing.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "./engine-
|
|
3
|
-
import { y as schema_validation_error } from "./leading_system-
|
|
1
|
+
import { k as aborted_error } from "./core-CFdEjtiT.js";
|
|
2
|
+
import "./engine-DQiQHiy8.js";
|
|
3
|
+
import { y as schema_validation_error } from "./leading_system-DQmlA6Fs.js";
|
|
4
4
|
//#region src/testing/engine_from_generate.ts
|
|
5
5
|
/**
|
|
6
6
|
* Build an `Engine` whose only live member is the supplied `generate`.
|
|
@@ -164,6 +164,20 @@ type CostBreakdown = {
|
|
|
164
164
|
is_estimate: true;
|
|
165
165
|
};
|
|
166
166
|
type SalvageFormat = 'hermes' | 'json' | 'qwen_xml';
|
|
167
|
+
/**
|
|
168
|
+
* Wall-clock timing of one step's provider round-trip, measured by the engine
|
|
169
|
+
* around the successful turn attempt: failed attempts and retry backoff are
|
|
170
|
+
* excluded, as is tool execution (that is ToolCallRecord.duration_ms).
|
|
171
|
+
* `first_chunk_ms` is present only on streamed turns: milliseconds from the
|
|
172
|
+
* attempt start to the first chunk, so `duration_ms - first_chunk_ms` is the
|
|
173
|
+
* window the model spent emitting output. See `throughput()` for the derived
|
|
174
|
+
* tokens-per-second view.
|
|
175
|
+
*/
|
|
176
|
+
type StepTiming = {
|
|
177
|
+
/** Epoch ms when the successful provider attempt started. */started_at: number; /** Wall-clock ms from attempt start to the turn result. */
|
|
178
|
+
duration_ms: number; /** Streamed turns only: ms from attempt start to the first chunk. */
|
|
179
|
+
first_chunk_ms?: number;
|
|
180
|
+
};
|
|
167
181
|
type ToolCallRecord = {
|
|
168
182
|
id: string;
|
|
169
183
|
name: string;
|
|
@@ -188,6 +202,12 @@ type StepRecord = {
|
|
|
188
202
|
tool_calls: ToolCallRecord[];
|
|
189
203
|
usage: UsageTotals;
|
|
190
204
|
cost?: CostBreakdown;
|
|
205
|
+
/**
|
|
206
|
+
* Present on every step the engine's tool loop produced (both transports),
|
|
207
|
+
* absent on steps built by external adapters (claude_cli) and injected test
|
|
208
|
+
* seams that return a TurnResult without one.
|
|
209
|
+
*/
|
|
210
|
+
timing?: StepTiming;
|
|
191
211
|
finish_reason: FinishReason;
|
|
192
212
|
/**
|
|
193
213
|
* This turn's provider-reported detail, keyed by provider name. See
|
|
@@ -313,6 +333,12 @@ type TurnResult = {
|
|
|
313
333
|
}>;
|
|
314
334
|
readonly finish_reason: FinishReason;
|
|
315
335
|
readonly usage: UsageTotals;
|
|
336
|
+
/**
|
|
337
|
+
* Stamped by the engine's retry wrapper around the successful attempt, not
|
|
338
|
+
* by adapters: an adapter-returned TurnResult never carries one, and the
|
|
339
|
+
* wrapper's value would overwrite it if it did. See StepTiming.
|
|
340
|
+
*/
|
|
341
|
+
readonly timing?: StepTiming;
|
|
316
342
|
/**
|
|
317
343
|
* Opaque detail the provider reported about this turn, keyed by provider
|
|
318
344
|
* name: Bedrock's guardrail trace, Anthropic's cache breakdown, whatever a
|
|
@@ -601,5 +627,5 @@ type Engine = {
|
|
|
601
627
|
dispose: () => Promise<void>;
|
|
602
628
|
};
|
|
603
629
|
//#endregion
|
|
604
|
-
export {
|
|
605
|
-
//# sourceMappingURL=types-
|
|
630
|
+
export { TurnRequest as A, ProviderFactory as B, StepTiming as C, ToolApprovalRequest as D, ToolApprovalHandler as E, EffortTranslation as F, RawProviderUsage as H, ExternalAgentAdapter as I, NativeProviderAdapter as L, UsageTotals as M, UserContentPart as N, ToolCallRecord as O, AiSdkProviderAdapter as P, ProviderAdapter as R, StepRecord as S, Tool as T, default_normalize_usage as U, ProviderTransport as V, ProviderConfigMap as _, Engine as a, RetryFailureKind as b, FinishReason as c, Message as d, PrepareStepContext as f, PricingTable as g, Pricing as h, EffortLevel as i, TurnResult as j, ToolExecContext as k, GenerateOptions as l, PrepareStepResult as m, AssistantContentPart as n, EngineConfig as o, PrepareStepHook as p, CostBreakdown as r, EngineDefaults as s, AiSdkTelemetrySettings as t, GenerateResult as u, ProviderInit as v, StreamChunk as w, RetryPolicy as x, ResolvedModel as y, ProviderCapability as z };
|
|
631
|
+
//# sourceMappingURL=types-CLigYA62.d.ts.map
|
|
@@ -0,0 +1,2 @@
|
|
|
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=oe,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(()=>S(()=>M(o)));d=o,p=null;try{return A(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[ie.bind(n),e=>(typeof e==`function`&&(e=f&&f.running&&f.sources.has(n)?e(n.tValue):e(n.value)),T(n,e))]}function y(e,t,n){E(O(e,t,!1,c))}function b(e,t,n){s=se;let r=O(e,t,!1,c),i=w&&ne(w);i&&(r.suspense=i),(!n||!n.render)&&(r.user=!0),h?h.push(r):E(r)}function x(e,t,n){n=n?Object.assign({},a,n):a;let r=O(e,t,!0,0);return r.observers=null,r.observerSlots=null,r.comparator=n.equals||void 0,E(r),ie.bind(r)}function S(e){if(p===null)return e();let t=p;p=null;try{return e()}finally{p=t}}function ee(e){return d===null||(d.cleanups===null?d.cleanups=[e]:d.cleanups.push(e)),e}var[C,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(()=>pe(t()));return n.toArray=()=>{let e=n();return Array.isArray(e)?e:e==null?[]:[e]},n}var w;function ie(){let e=f&&f.running;if(this.sources&&(e?this.tState:this.state)){if((e?this.tState:this.state)===c)E(this);else{let e=m;m=null,A(()=>j(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 T(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&&A(()=>{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&&ce(n)),r?n.tState=c:n.state=c)}if(m.length>1e6)throw m=[],Error()},!1)}return t}function E(e){if(!e.fn)return;M(e);let t=g;D(e,f&&f.running&&f.sources.has(e)?e.tValue:e.value,t),f&&!f.running&&f.sources.has(e)&&queueMicrotask(()=>{A(()=>{f&&(f.running=!0),p=d=e,D(e,e.tValue,t),p=d=null},!1)})}function D(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(M),e.tOwned=void 0):(e.state=c,e.owned&&e.owned.forEach(M),e.owned=null)),e.updatedAt=n+1,fe(t)}finally{p=a,d=i}(!e.updatedAt||e.updatedAt<=n)&&(e.updatedAt!=null&&`observers`in e?T(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 O(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 k(e){let t=f&&f.running;if((t?e.tState:e.state)===0)return;if((t?e.tState:e.state)===l)return j(e);if(e.suspense&&S(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)E(e);else if((t?e.tState:e.state)===l){let t=m;m=null,A(()=>j(e,n[0]),!1),m=t}}}function A(e,t){if(m)return e();let n=!1;t||(m=[]),h?n=!0:h=[],g++;try{let t=e();return ae(n),t}catch(e){n||(h=null),m=null,fe(e)}}function ae(e){if(m&&=(oe(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,A(()=>{for(let e of n)M(e);for(let t of e){if(t.value=t.tValue,t.owned)for(let e=0,n=t.owned.length;e<n;e++)M(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&&A(()=>s(n),!1),t&&t()}function oe(e){for(let t=0;t<e.length;t++)k(e[t])}function se(t){let r,i=0;for(r=0;r<t.length;r++){let e=t[r];e.user?t[i++]=e:k(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++)k(t[r])}function j(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)&&k(i):e===l&&j(i,t)}}}function ce(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&&ce(r))}}function M(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--)M(e.tOwned[t]);delete e.tOwned}if(f&&f.running&&e.pure)le(e,!0);else if(e.owned){for(t=e.owned.length-1;t>=0;t--)M(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 le(e,t){if(t||(e.tState=0,f.disposed.add(e)),e.owned)for(let t=0;t<e.owned.length;t++)le(e.owned[t])}function ue(e){return e instanceof Error?e:Error(typeof e==`string`?e:`Unknown error`,{cause:e})}function de(e,t,n){try{for(let n of t)n(e)}catch(e){fe(e,n&&n.owner||null)}}function fe(e,t=d){let n=o&&t&&t.context&&t.context[o],r=ue(e);if(!n)throw r;h?h.push({fn(){de(r,n,t)},state:c}):de(r,n,t)}function pe(e){if(typeof e==`function`&&!e.length)return pe(e());if(Array.isArray(e)){let t=[];for(let n=0;n<e.length;n++){let r=pe(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 me=Symbol(`fallback`);function he(e){for(let t=0;t<e.length;t++)e[t]()}function ge(e,t,n={}){let r=[],a=[],o=[],s=0,c=t.length>1?[]:null;return ee(()=>he(o)),()=>{let l=e()||[],u=l.length,d,f;return l[i],S(()=>{let e,t,i,m,h,g,v,y,b;if(u===0)s!==0&&(he(o),o=[],r=[],a=[],s=0,c&&=[]),n.fallback&&(r=[me],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 N(e,t){return S(()=>e(t||{}))}var _e=e=>`Stale read from <${e}>.`;function P(e){let t=`fallback`in e&&{fallback:()=>e.fallback};return x(ge(()=>e.each,e.children,t||void 0))}function F(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?S(()=>a(t?i:()=>{if(!S(r))throw _e(`Show`);return n()})):a}return e.fallback},void 0,void 0)}function ve(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?S(()=>o(a.keyed?i():()=>{if(S(n)()?.[0]!==r)throw _e(`Match`);return i()})):o},void 0,void 0)}function ye(e){return e}var be=e=>x(()=>e());function xe(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++;continue}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 Se=`_$DX_DELEGATE`;function Ce(e,t,n,r={}){let i;return _(r=>{i=r,t===document?e():R(t,e(),t.firstChild?null:void 0,n)},r.owner),()=>{i(),t.textContent=``}}function I(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?()=>S(()=>document.importNode(i||=a(),!0)):()=>(i||=a()).cloneNode(!0);return o.cloneNode=o,o}function we(e,t=window.document){let n=t[Se]||(t[Se]=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,De))}}function L(e,t,n){Ee(e)||(n==null?e.removeAttribute(t):e.setAttribute(t,n))}function Te(e,t){Ee(e)||(t==null?e.removeAttribute(`class`):e.className=t)}function R(e,t,n,r){if(n!==void 0&&!r&&(r=[]),typeof t!=`function`)return z(e,t,r,n);y(r=>z(e,t(),r,n),r)}function Ee(t){return!!e.context&&!e.done&&(!t||t.isConnected)}function De(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););};if(Object.defineProperty(t,"currentTarget",{configurable:!0,get(){return n||document}}),e.registry&&!e.done&&(e.done=_$HY.done=!0),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)}function z(e,t,n,r,i){let a=Ee(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=B(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=B(e,n,r)}else if(o===`function`)return y(()=>{let i=t();for(;typeof i==`function`;)i=i();n=z(e,i,n,r)}),()=>n;else if(Array.isArray(t)){let o=[],c=n&&Array.isArray(n);if(Oe(o,t,n,i))return y(()=>n=z(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=B(e,n,r),s)return n}else c?n.length===0?ke(e,o,r):xe(e,n,o):(n&&B(e),ke(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=B(e,n,r,t);B(e,n,null,t)}else n==null||n===``||!e.firstChild?e.appendChild(t):e.replaceChild(t,e.firstChild);n=t}return n}function Oe(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=Oe(e,o,s)||i;else if(c===`function`){if(r){for(;typeof o==`function`;)o=o();i=Oe(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 ke(e,t,n=null){for(let r=0,i=t.length;r<i;r++)e.insertBefore(t[r],n)}function B(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 Ae=I(`<button type=button class=pb-button>`),je=I(`<div class=playback data-testid=playback>`);function V(e){return(()=>{var t=Ae();return t.$$click=()=>e.on_click(),R(t,()=>e.label),y(n=>{var r=e.testid,i=e.active?`true`:void 0;return r!==n.e&&L(t,`data-testid`,n.e=r),i!==n.t&&L(t,`data-active`,n.t=i),n},{e:void 0,t:void 0}),t})()}function Me(e){return(()=>{var t=je();return R(t,N(V,{testid:`play-toggle`,get label(){return e.playback.playing?`PAUSE`:`PLAY`},get on_click(){return e.on_toggle_play}}),null),R(t,N(V,{testid:`speed`,get label(){return`${e.playback.speed}X`},get on_click(){return e.on_cycle_speed}}),null),R(t,N(V,{testid:`compress-toggle`,label:`COMPRESS`,get active(){return e.playback.compress},get on_click(){return e.on_toggle_compress}}),null),R(t,N(V,{testid:`loop-toggle`,label:`LOOP`,get active(){return e.playback.loop},get on_click(){return e.on_toggle_loop}}),null),R(t,N(V,{testid:`density-toggle`,label:`DENSITY`,get active(){return e.density},get on_click(){return e.on_toggle_density}}),null),t})()}we([`click`]);function Ne(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 Pe=8,Fe=`·`.repeat(Pe);function Ie(e){return e.slice(0,Pe)}function H(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 Le(e){return`T+${H(e)}`}function Re(e){return e<.01?`$${e.toFixed(4)}`:`$${e.toFixed(2)}`}function ze(e){return e===1?`RETRY`:`RETRIES`}var Be={text:`·`,role:`sep`};function Ve(e){return[{text:Le(e.t_plus_ms),role:`value`},Be,{text:String(e.retries_absorbed),role:`value`},{text:`${ze(e.retries_absorbed)} ABSORBED`,role:`word`},Be,{text:`SCARS`,role:`word`},{text:String(e.scars),role:e.scars>0?`scar`:`value`},Be,{text:Re(e.cost_usd),role:`value`}]}var U={status:`pending`,occurrences:[],scarred:!1,suspended:!1,turn_retries:0,cost_usd:0,emits:0,checkpoint:null};function He(e){let t=new Map,n=new Map;return e!==null&&Ue(e,t,n),{run_id:null,run_status:null,t0_ts:null,last_ts:null,retries_absorbed:0,scars:0,cost_usd:0,unattributed_usd:0,nodes:n,spans:new Map,open_spans:[],kinds:t}}function Ue(e,t,n){t.has(e.id)||(t.set(e.id,e.kind),n.set(e.id,U));for(let r of e.children??[])Ue(r,t,n)}function We(e){return e.t0_ts===null||e.last_ts===null?0:Math.max(0,e.last_ts-e.t0_ts)}function Ge(e,t){if(!Ke(t))return e;let n=t,r=qe(n,`ts`),i={...e,run_id:e.run_id??W(n,`run_id`),t0_ts:e.t0_ts??r,last_ts:r??e.last_ts};switch(n.kind){case`span_start`:return Je(i,n,r);case`span_end`:return Ye(i,n,r);case`suspended`:return et(i,n);case`emit`:return tt(i,n);case`checkpoint`:return rt(i,n);case`turn_retry`:return it(i,n);case`cost`:return at(i,n);case`run_end`:return st(i,n);default:return i}}function Ke(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:typeof e.kind==`string`}function W(e,t){let n=e[t];return typeof n==`string`?n:null}function qe(e,t){let n=e[t];return typeof n==`number`&&Number.isFinite(n)?n:null}function Je(e,t,n){let r=W(t,`span_id`),i=W(t,`name`);if(r===null||i===null)return e;let a=W(t,`parent_span_id`),o=W(t,`id`),s=new Map(e.spans);s.set(r,{name:i,node_id:o,parent_span_id:a,open:!0,failed_descendant:!1,failed_joined_descendant:!1});let c={...e,spans:s,open_spans:[...e.open_spans,r]};if(o===null)return c;let l=e.nodes.get(o)??U,u={span_id:r,parent_span_id:a,status:`active`,started_ts:n,ended_ts:null,error:null},d=new Map(e.nodes);return d.set(o,ct({...l,occurrences:[...l.occurrences,u],suspended:!1})),{...c,nodes:d}}function Ye(e,t,n){let r=W(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=Xe(e,r,i,a),s=new Map(o.nodes),c=Ze(o,r,i,a,n,W(t,`error`)),l={scars:o.scars,retries_absorbed:o.retries_absorbed};if(a){let e=Qe(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,ct(c)),a&&(l=$e(o,r,i,s,l)),{...o,nodes:s,...l}}function Xe(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 Ze(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 Qe(e,t,n,r){if(n?.suspended===!0)return{...r,node:n};if(dt(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 $e(e,t,n,r,i){if(ut(e,n)!==`retry`||dt(e,n))return i;let a=pt(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 et(e,t){let n=W(t,`step_id`);if(n===null)return e;let r=e.nodes.get(n)??U,i=new Map(e.nodes);return i.set(n,ct({...r,suspended:!0})),{...e,nodes:i}}function tt(e,t){let n=ft(e,W(t,`span_id`));if(n===null)return e;let r=e.nodes.get(n)??U,i=new Map(e.nodes);return i.set(n,{...r,emits:r.emits+1}),{...e,nodes:i}}function nt(e){return e===`hit`||e===`miss`||e===`read_error`}function rt(e,t){let n=W(t,`id`),r=W(t,`status`);if(n===null||r===null||!nt(r))return e;let i=e.nodes.get(n)??U,a=new Map(e.nodes);return a.set(n,{...i,checkpoint:r}),{...e,nodes:a}}function it(e,t){let n=e.retries_absorbed+1,r=ft(e,W(t,`span_id`));if(r===null)return{...e,retries_absorbed:n};let i=e.nodes.get(r)??U,a=new Map(e.nodes);return a.set(r,{...i,turn_retries:i.turn_retries+1}),{...e,retries_absorbed:n,nodes:a}}function at(e,t){let n=qe(t,`total_usd`);if(n===null)return e;let r=e.cost_usd+n,i=ft(e,W(t,`span_id`));if(i===null)return{...e,cost_usd:r,unattributed_usd:e.unattributed_usd+n};let a=e.nodes.get(i)??U,o=new Map(e.nodes);return o.set(i,{...a,cost_usd:a.cost_usd+n}),{...e,cost_usd:r,nodes:o}}function ot(e){return e===`done`||e===`failed`||e===`aborted`||e===`suspended`}function st(e,t){let n=W(t,`status`);return n===null||!ot(n)?e:{...e,run_status:n}}function ct(e){return{...e,status:lt(e)}}function lt(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 ut(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 dt(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&&ut(e,t)===`retry`)return!0;r=t.parent_span_id}return!1}function ft(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 pt(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 G={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},mt=G.min_name_px/G.name_px,ht=10,gt=4,_t=11,vt=G.name_drop+G.meta_drop+gt,K=4,yt=G.group_label_rise+_t,bt=G.label_clear+_t,xt=G.junction_label_drop+gt,St=G.basin_drop+K+gt,Ct=40,wt=40,Tt=8,Et=new Set([`parallel`,`branch`,`adversarial`,`ensemble`,`tournament`,`consensus`]),Dt=new Set([`retry`,`loop`]);function Ot(e){let t={nodes:[],junctions:[],segments:[],group_labels:[],tick_lanes:[]};if(e===null)return{width:2*G.margin,height:2*G.margin,spine_y:G.margin,...t};let n=kt(e),r=G.margin+n.above,i=G.margin+G.entry_stub;return t.segments.push({role:`entry`,from:null,to:n.id,path:`M ${G.margin} ${r} H ${i}`}),n.place(i,r,t,0),Ut(t,n.exit_glyph),{width:i+n.width+G.margin,height:r+n.below+G.margin,spine_y:r,...t}}function kt(e){let t=(e.children??[]).map(kt);return Et.has(e.kind)&&t.length>0?Lt(e,t):Dt.has(e.kind)?Rt(e,t):e.kind===`fallback`&&t.length>=2?Vt(e,t):e.kind===`map`?Ht(e,t):t.length>0?{id:e.id,...Mt(t)}:jt(e)}function At(e){let t=e.config?.display_name;return typeof t==`string`&&t.length>0?t:e.id}function jt(e){return{id:e.id,width:0,above:ht,below:vt,exit_glyph:e.id,place:(t,n,r,i)=>{let a=n+i+G.name_drop;r.nodes.push({id:e.id,kind:e.kind,label:At(e),center:{x:t,y:n},radius:G.puck_radius,terminus:!1,name_anchor:{x:t,y:a},meta_anchor:{x:t,y:a+G.meta_drop}})}}}function Mt(e){let t=G.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+G.node_pitch}`}),a+=G.node_pitch),t.place(a,n,r,i),a+=t.width,o=t}}}function Nt(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*G.branch_pitch)}return n}function Pt(e){let t=Nt(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+G.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 Ft(e,t,n,r){if(r===t)return`M ${e} ${t} H ${n}`;let i=G.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 It(e,t,n,r){let i=G.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 Lt(e,t){let n=Pt(t),r=2*G.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+G.lane_lead+i+G.lane_lead+r+G.junction_gap,above:-o+Math.max(c?.above??0,yt),below:Math.max(s+(l?.below??0),xt),exit_glyph:null,place:(s,c,l)=>{let u=s+r+G.lane_lead,d=u+i+G.lane_lead,f=d+r,p=f+G.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:Ft(s,c,u,t)}),i.place(u,t,l,0),l.segments.push({role:`branch_out`,from:i.id,to:a,path:It(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:G.junction_radius,label_anchor:{x:p,y:c+G.junction_label_drop}});let m=c+o-G.group_label_rise;l.group_labels.push({owner:e.id,tick:{x:s+G.corner_radius,y:m-K},text_anchor:{x:s+G.corner_radius+G.group_text_indent,y:m}})}}}function Rt(e,t){let n=Mt(t);if(n.width>0)return zt(e,n);let r=G.loop_radius,i=t[0]?.id??e.id;return{id:e.id,width:2*r,above:r+bt,below:r+vt,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+G.label_clear,y:c-G.label_clear-K},text_anchor:{x:s+G.label_clear+G.group_text_indent,y:c-G.label_clear}})}}}function zt(e,t){let n=G.corner_radius,r=t.below+wt;return{id:e.id,width:t.width,above:Math.max(t.above,yt),below:r+Tt,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-G.group_label_rise;o.group_labels.push({owner:e.id,tick:{x:i,y:l-K},text_anchor:{x:i+G.group_text_indent,y:l}})}}}function Bt(e,t,n,r){let i=G.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 Vt(e,t){let n=t[0];if(n===void 0)return jt(e);let r=t.slice(1),i=[],a=G.basin_drop,o=null;for(let e of r)o!==null&&(a+=Math.max(G.basin_drop,o.below+e.above+G.label_clear)),i.push(a),o=e;let s=n.width+2*G.basin_shoulder,c=i[i.length-1]??G.basin_drop,l=r[r.length-1];return{id:e.id,width:s,above:n.above,below:c+Math.max(l?.below??0,St),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+G.basin_shoulder,a,o,0);for(let[n,c]of r.entries()){let r=i[n]??G.basin_drop;o.segments.push({role:`basin`,from:e.id,to:c.id,path:Bt(t,a,s,r)}),c.place(t+(s-c.width)/2,a+r,o,0)}let l=a+c+G.basin_drop+K;o.group_labels.push({owner:e.id,tick:{x:t+Ct,y:l-K},text_anchor:{x:t+Ct+G.group_text_indent,y:l}})}}}function Ht(e,t){let n=Mt(t),r=n.width+G.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+G.tick_lead,x1:t+r})}}}function Ut(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:G.terminus_radius};return}}}function Wt(e,t){if(!Number.isInteger(e)||e<=0)return{xs:[],decades:[],pitch:0};let n=e>G.decade,r=n?G.comb_pitch:G.tick_pitch,i=[];for(let t=0;t<e;t+=1){let e=n?Math.floor(t/G.decade):0;i.push(t*r+e*G.decade_gap)}return Kt({xs:i,decades:n?Gt(i,e,r):[],pitch:r},t)}function Gt(e,t,n){let r=[];for(let i=G.decade;i<=t;i+=G.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 Kt(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 qt(e,t,n){let r=Math.min(t/e.width,n/e.height),i=Math.max(Math.min(1,r),mt),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 Jt={structure:null,state:He(null)};function Yt(e,t){if(Xt(t)){let e=Zt(t.structure);if(e!==null)return{structure:e,state:Ge(He(e),t)}}let n=Ge(e.state,t);return n===e.state?e:{structure:e.structure,state:n}}function Xt(e){return q(e)&&e.kind===`flow_structure`}function q(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function Zt(e){if(!q(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(Zt).filter(e=>e!==null):[],a=e.config;return{kind:t,id:n,...q(a)?{config:a}:{},...i.length===0?{}:{children:i}}}function Qt(e){let t=new Map;return e!==null&&$t(e,t),t}function $t(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=en(e,i,r);n!==null&&!t.has(i.id)&&t.set(i.id,n)}for(let e of n)$t(e,t)}function en(e,t,n){switch(e.kind){case`map`:return`MAP`;case`loop`:return`LOOP`;case`retry`:return tn(e.config?.max_attempts);case`fallback`:return`${t.kind.toUpperCase()} · ${n===0?`PRIMARY`:`BACKUP`}`;default:return null}}function tn(e){let t=J(e);return t===null?`RETRY`:`RETRY · ${t} ${t===1?`ATTEMPT`:`ATTEMPTS`}`}function J(e){return typeof e!=`number`||!Number.isInteger(e)||e<=0?null:e}var nn=14,rn=Math.PI/4,an=14,on=-17,sn=30,cn=-156,ln=279,un=22,dn=14,fn=112,pn=44,mn=12,hn=24;function gn(e,t){let n=yn(e,t),r=Qt(t.structure);return{nodes:e.nodes.map(e=>{let i=Ln(n,e,r);return{glyph:e,meta:i.text,meta_fail:i.fail,status:Fn(n,e.id),scar:Rn(n,e.id)?null:Pn(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:Un(n,e.owner)})),segments:e.segments.map(e=>({segment:e,state:wn(n,e)})),fail_marks:Nn(e,t.state),tick_lanes:_n(e,n),cards:Wn(e,n)}}function _n(e,t){return e.tick_lanes.map(e=>{let n=t.nodes_by_id.get(e.owner)?.children?.[0],r=n===void 0?[]:Y(t.state,n.id),i=Wt(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:vn(t.status)})),decades:i.decades.map(t=>({x:e.x0+t.x,y:e.y+sn,value:t.value}))}})}function vn(e){return e===`active`?`live`:e===`failed`?`failed`:`done`}function yn(e,t){let n=new Map,r=new Map,i=new Map;t.structure!==null&&xn(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:bn(t.state,r,i)}}function bn(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 xn(e,t,n,r){n.has(e.id)||(n.set(e.id,e),r.set(e.id,Sn(e)));for(let i of e.children??[])t.has(i.id)||t.set(i.id,e.id),xn(i,t,n,r)}function Sn(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 Y(e,t){return e.nodes.get(t)?.occurrences??[]}function X(e){return e.some(e=>e.status===`active`)}function Cn(e,t){let n=Y(e,t);return n.length>0&&!X(n)}function wn(e,t){switch(t.role){case`loop_upper`:return kn(e.state,t.from??t.to,t.to);case`loop_lower`:return An(e.state,t.to);case`loop_return`:return Mn(e,t.to)}let n=e.junction_owners.get(t.to);return n===void 0?t.from!==null&&On(e.parents,t.from,t.to)?Cn(e.state,t.to)?`traversed`:`unbuilt`:Tn(e,t):Cn(e.state,n)?`traversed`:`unbuilt`}function Tn(e,t){if(e.fallback_primaries.has(t.to)&&En(e.state,t.to))return`unbuilt`;let n=e.first_leaves.get(t.to)??t.to,r=Y(e.state,n);return r.length===0?`unbuilt`:X(r)&&!e.loop_leaves.has(n)&&!Dn(e.state,n)?`live`:`traversed`}function En(e,t){return e.nodes.get(t)?.scarred===!0}function Dn(e,t){return e.nodes.get(t)?.suspended===!0}function On(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 kn(e,t,n){let r=Y(e,n);return jn(e,t,r)?`live`:r.length>0?`traversed`:`unbuilt`}function An(e,t){return Y(e,t).some(e=>e.status===`failed`)?`traversed`:`unbuilt`}function jn(e,t,n){return X(Y(e,t))?X(n)?!0:n[n.length-1]?.status===`failed`:!1}function Mn(e,t){let n=e.nodes_by_id.get(t)?.children?.[0];if(n===void 0)return`unbuilt`;let r=Y(e.state,n.id),i=r.length>=2;return jn(e.state,t,r)&&(i||!X(r))?`live`:i?`traversed`:`unbuilt`}function Nn(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=Y(t,r.to).filter(e=>e.status===`failed`).length,o=i.center.x+G.loop_radius,s=G.loop_radius+nn;for(let e=0;e<a;e+=1){let t=rn+Math.min(a-1-e,2)*rn;n.push({x:o+Math.cos(t)*s,y:i.center.y+Math.sin(t)*s})}}return n}function Pn(e,t){return e.nodes.get(t.id)?.scarred===!0?{x:t.center.x+an,y:t.center.y+on}:null}function Fn(e,t){let n=e.state.nodes.get(t)?.status??`pending`;if(n!==`failed`)return n;let r=In(e,t);return r!==null&&X(Y(e.state,r.id))?`active`:n}function In(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 Ln(e,t,n){if(Dn(e.state,t.id))return{text:`SUSPENDED`,fail:null};let r=t.terminus?`TERMINUS`:n.get(t.id)??t.kind.toUpperCase(),i=Y(e.state,t.id);if(i.length===0)return{text:r,fail:null};let a=t.terminus?null:In(e,t.id);if(a!==null)return{text:Bn(e.state,a,i),fail:null};if(!t.terminus&&Rn(e,t.id))return zn(r,i);let o=i.length>=2?`${r} ×${i.length}`:r;return X(i)?{text:`${o} · RUNNING`,fail:null}:{text:Vn(o,i),fail:null}}function Rn(e,t){let n=e.parents.get(t);return n!==void 0&&e.nodes_by_id.get(n)?.kind===`map`}function zn(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>G.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:Vn(n,t),fail:null}}function Bn(e,t,n){let r=n[n.length-1]?.status===`failed`&&X(Y(e,t.id)),i=J(t.config?.max_attempts),a=n.length+ +!!r,o=`RETRY · ATT ${i===null?a:Math.min(a,i)}${i===null?``:`/${i}`}`;return X(n)||r?o:Vn(o,n)}function Vn(e,t){let n=Hn(t);return n===null?e:`${e} · ${H(n)}`}function Hn(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 Un(e,t){let n=t.toUpperCase(),r=e.state.kinds.get(t)===`fallback`?` · ARMED`:``,i=Y(e.state,t);if(i.length===0||X(i))return`${n}${r}`;let a=Hn(i);return a===null?`${n}${r}`:`${n} · ${H(a)}`}function Z(e,t){return{role:e,spans:[{text:t,ember:!1}]}}function Wn(e,t){let n=[];for(let r of e.nodes){let e=Gn(t,r);e!==null&&n.push(Xn(r,e))}return n}function Gn(e,t){let n=e.state.nodes.get(t.id);return n===void 0?null:n.suspended?[Z(`title`,`SUSPENDED`),Z(`detail`,`AWAITING RESUME`)]:n.scarred&&!Rn(e,t.id)?Kn(n):qn(e,t.id,n.occurrences)}function Kn(e){let t=Yn(Jn(e.occurrences)?.occurrence.error??null);return[Z(`title`,`PERMANENT FAILURE`),{role:`detail`,spans:t===null?[{text:`✕`,ember:!0}]:[{text:`✕`,ember:!0},{text:` ${t}`,ember:!1}]}]}function qn(e,t,n){let r=In(e,t);if(r===null||!X(Y(e.state,r.id)))return null;let i=n[n.length-1]?.status===`failed`;if(!i&&!X(n))return null;let a=J(r.config?.max_attempts),o=n.length+ +!!i,s=a===null?o:Math.min(o,a);if(s<2)return null;let c=[Z(`title`,`ATTEMPT ${s}${a===null?``:` OF ${a}`}`)],l=Jn(n);if(l!==null){let e=Yn(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=J(r.config?.backoff_ms);return u!==null&&c.push(Z(`detail`,`BACKOFF ${H(u)} HONORED`)),c}function Jn(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 Yn(e){if(e===null||e.length===0)return null;let t=e.toUpperCase();return t.length<=hn?t:`${t.slice(0,23)}…`}function Xn(e,t){let n=e.center.x+cn<G.margin,r=e.center.x+(n?pn:cn),i=e.center.y-ln,a={x:r+(n?mn:fn),y:i+(t.length-1)*un+dn},o=Zn(e.center,a);return{owner:e.id,lines:t.map((e,t)=>({x:r,y:i+t*un,role:e.role,spans:e.spans})),leader:`M ${a.x} ${a.y} L ${o.x} ${o.y}`,dot:o}}function Zn(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 Qn(e){let t=null,n=null,r=[],i=[];for(let a of e){let e=cr(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=>sr(e,a))}}function $n(e,t){let{times:n,span_ms:r,count:i}=e;if(i===0)return 0;let a=Q(t,0,i-1);return r>0?Q((n[a]??0)/r,0,1):i>1?a/(i-1):0}function er(e,t){let{times:n,span_ms:r,count:i}=e;if(i===0)return 0;let a=Q(t,0,1);return r<=0?Math.round(a*(i-1)):or(n,a*r)}function tr(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($n(e,r)*t));n[i]=(n[i]??0)+1}let r=Math.max(...n);return n.map(e=>e/r)}function nr(e,t,n){return Q(e+Math.sign(t),0,Math.max(0,n-1))}function rr(e,t,n){let{times:r,count:i}=e;if(i===0)return 0;let a=Q(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 ir(e,t,n,r){if(e.count===0)return`ignore`;switch(n){case`ArrowRight`:return r?rr(e,t,1):nr(t,1,e.count);case`ArrowLeft`:return r?rr(e,t,-1):nr(t,-1,e.count);case`Home`:return 0;case`End`:return`live`;default:return`ignore`}}function ar(e,t){let n=Jt,r=Q(t+1,0,e.length);for(let t=0;t<r;t+=1)n=Yt(n,e[t]);return n}function or(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 sr(e,t){return t>0?Q(e/t,0,1):0}function cr(e){let t=e.ts;return typeof t==`number`&&Number.isFinite(t)?t:null}function Q(e,t,n){return Math.min(n,Math.max(t,e))}var lr=I(`<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>`),ur=I(`<svg><rect class=scrub-density y=15 height=10></svg>`,!1,!0,!1),dr=I(`<svg><line class=scrub-fail y1=16 y2=24></svg>`,!1,!0,!1),$=4,fr=48,pr=.3;function mr(e){let t=()=>e.width-G.margin,n=()=>Math.max(0,t()-G.margin),r=e=>G.margin+e*n(),i=()=>r(hr(e.fraction)),a=(t,n)=>{let r=n.width-2*G.margin,i=r<=0?0:(t-n.left-G.margin)/r;e.on_seek(hr(i))},o=()=>e.density?tr(e.timeline,fr):[];return(()=>{var s=lr(),c=s.firstChild,l=c.nextSibling,u=l.nextSibling,d=u.nextSibling;return R(s,N(P,{get each(){return o()},children:(e,t)=>(()=>{var i=ur();return L(i,`opacity`,e*pr),y(e=>{var a=r(t()/fr),o=n()/fr;return a!==e.e&&L(i,`x`,e.e=a),o!==e.t&&L(i,`width`,e.t=o),e},{e:void 0,t:void 0}),i})()}),c),R(s,N(P,{get each(){return e.timeline.failures},children:e=>[(()=>{var t=dr();return y(n=>{var i=r(e)-$,a=r(e)+$;return i!==n.e&&L(t,`x1`,n.e=i),a!==n.t&&L(t,`x2`,n.t=a),n},{e:void 0,t:void 0}),t})(),(()=>{var t=dr();return y(n=>{var i=r(e)+$,a=r(e)-$;return i!==n.e&&L(t,`x1`,n.e=i),a!==n.t&&L(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=G.margin,s=i(),f=i(),p=e.width;return r!==n.e&&L(c,`x1`,n.e=r),a!==n.t&&L(c,`x2`,n.t=a),o!==n.a&&L(l,`x1`,n.a=o),s!==n.o&&L(l,`x2`,n.o=s),f!==n.i&&L(u,`cx`,n.i=f),p!==n.n&&L(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 hr(e){return Math.min(1,Math.max(0,e))}we([`pointerdown`,`pointermove`]);var gr=I(`<svg><circle class=scar-mask r=13></svg>`,!1,!0,!1),_r=I(`<svg><circle class=scar-ring r=8.5></svg>`,!1,!0,!1),vr=I(`<svg><path class=scar-mark></svg>`,!1,!0,!1),yr=I(`<svg><path class=tick-fail></svg>`,!1,!0,!1),br=I(`<svg><line class="tick tick-live-glow"></svg>`,!1,!0,!1),xr=I(`<svg><line class="tick tick-live"></svg>`,!1,!0,!1),Sr=I(`<svg><line class="tick tick-done"></svg>`,!1,!0,!1),Cr=I(`<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),wr=I(`<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>`),Tr=I(`<svg><circle class=bloom></svg>`,!1,!0,!1),Er=I(`<svg><path></svg>`,!1,!0,!1),Dr=I(`<svg><g class=tick-lane data-testid=tick-lane></svg>`,!1,!0,!1),Or=I(`<svg><text class=tick-decade></svg>`,!1,!0,!1),kr=I(`<svg><circle class=halo></svg>`,!1,!0,!1),Ar=I(`<svg><circle class=puck-core r=2.5></svg>`,!1,!0,!1),jr=I(`<svg><circle class=emit-bloom r=16></svg>`,!1,!0,!1),Mr=I(`<svg><circle class=terminus-ring></svg>`,!1,!0,!1),Nr=I(`<svg><tspan class=meta-check> ✓</svg>`,!1,!0,!1),Pr=I(`<svg><g class=node data-testid=node><text class=node-name></text><text class=node-meta></svg>`,!1,!0,!1),Fr=I(`<svg><circle class=puck></svg>`,!1,!0,!1),Ir=I(`<svg><line class=pause-bar></svg>`,!1,!0,!1),Lr=I(`<svg><tspan> · </svg>`,!1,!0,!1),Rr=I(`<svg><tspan class=meta-fail></svg>`,!1,!0,!1),zr=I(`<svg><path class=fail-mark></svg>`,!1,!0,!1),Br=I(`<svg><g class=junction data-testid=junction><circle class=puck></circle><text class=junction-label></svg>`,!1,!0,!1),Vr=I(`<svg><g class=group-label data-testid=group-label><line class=group-tick></line><text class=group-text></svg>`,!1,!0,!1),Hr=I(`<svg><g class=card data-testid=card><path class=card-leader></path><circle class=card-dot r=2.5></svg>`,!1,!0,!1),Ur=I(`<svg><text></svg>`,!1,!0,!1),Wr=I(`<svg><tspan></svg>`,!1,!0,!1),Gr=4.5,Kr=6,qr=4,Jr=-32,Yr=2.4,Xr=3.2;function Zr(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 Qr(e){return[(()=>{var t=gr();return y(n=>{var r=e.center.x,i=e.center.y;return r!==n.e&&L(t,`cx`,n.e=r),i!==n.t&&L(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t})(),(()=>{var t=_r();return y(n=>{var r=e.center.x,i=e.center.y,a=`rotate(${Jr} ${e.center.x} ${e.center.y})`;return r!==n.e&&L(t,`cx`,n.e=r),i!==n.t&&L(t,`cy`,n.t=i),a!==n.a&&L(t,`transform`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})(),(()=>{var t=vr();return y(()=>L(t,`d`,Zr(e.mark.x,e.mark.y,Gr))),t})()]}function $r(e){let t=()=>e.tick.y-Kr,n=()=>e.tick.y+Kr;return N(ve,{get children(){return[N(ye,{get when(){return e.tick.status===`failed`},get children(){var t=yr();return y(()=>L(t,`d`,Zr(e.tick.x,e.tick.y,qr))),t}}),N(ye,{get when(){return e.tick.status===`live`},get children(){return[(()=>{var r=br();return y(i=>{var a=e.tick.x,o=t(),s=e.tick.x,c=n();return a!==i.e&&L(r,`x1`,i.e=a),o!==i.t&&L(r,`y1`,i.t=o),s!==i.a&&L(r,`x2`,i.a=s),c!==i.o&&L(r,`y2`,i.o=c),i},{e:void 0,t:void 0,a:void 0,o:void 0}),r})(),(()=>{var r=xr();return y(i=>{var a=e.tick.x,o=t(),s=e.tick.x,c=n();return a!==i.e&&L(r,`x1`,i.e=a),o!==i.t&&L(r,`y1`,i.t=o),s!==i.a&&L(r,`x2`,i.a=s),c!==i.o&&L(r,`y2`,i.o=c),i},{e:void 0,t:void 0,a:void 0,o:void 0}),r})()]}}),N(ye,{get when(){return e.tick.status===`done`},get children(){var r=Sr();return y(i=>{var a=e.tick.x,o=t(),s=e.tick.x,c=n();return a!==i.e&&L(r,`x1`,i.e=a),o!==i.t&&L(r,`y1`,i.t=o),s!==i.a&&L(r,`x2`,i.a=s),c!==i.o&&L(r,`y2`,i.o=c),i},{e:void 0,t:void 0,a:void 0,o:void 0}),r}})]}})}function ei(e){return(()=>{var t=Cr(),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&&L(t,`data-role`,a.e=o),s!==a.t&&L(t,`data-to`,a.t=s),c!==a.a&&L(n,`d`,a.a=c),l!==a.o&&L(r,`d`,a.o=l),u!==a.i&&L(i,`d`,a.i=u),a},{e:void 0,t:void 0,a:void 0,o:void 0,i:void 0}),t})()}function ti(e){let t=x(()=>e.session.structure),n=x(()=>Ot(t())),r=x(()=>gn(n(),e.session)),i=x(()=>r().nodes.filter(e=>e.status===`active`)),a=x(()=>qt(n(),e.viewport.width,e.viewport.height));return(()=>{var e=wr(),t=e.firstChild.nextSibling,n=t.firstChild;return R(t,N(P,{get each(){return i()},children:e=>(()=>{var t=Tr();return L(t,`r`,215),y(n=>{var r=e.glyph.center.x,i=e.glyph.center.y;return r!==n.e&&L(t,`cx`,n.e=r),i!==n.t&&L(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t})()}),n),R(n,N(P,{get each(){return r().segments},children:e=>N(F,{get when(){return e.state===`live`},get fallback(){return(()=>{var t=Er();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&&L(t,`class`,n.e=r),i!==n.t&&L(t,`d`,n.t=i),a!==n.a&&L(t,`data-role`,n.a=a),o!==n.o&&L(t,`data-to`,n.o=o),s!==n.i&&L(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 N(ei,{scene_segment:e})}})})),R(t,N(P,{get each(){return r().tick_lanes},children:e=>(()=>{var t=Dr();return R(t,N(P,{get each(){return e.ticks},children:e=>N($r,{tick:e})}),null),R(t,N(P,{get each(){return e.decades},children:e=>(()=>{var t=Or();return R(t,()=>e.value),y(n=>{var r=e.x,i=e.y;return r!==n.e&&L(t,`x`,n.e=r),i!==n.t&&L(t,`y`,n.t=i),n},{e:void 0,t:void 0}),t})()}),null),y(()=>L(t,`data-owner`,e.owner)),t})()}),null),R(t,N(P,{get each(){return i()},children:e=>(()=>{var t=kr();return L(t,`r`,40),y(n=>{var r=e.glyph.center.x,i=e.glyph.center.y;return r!==n.e&&L(t,`cx`,n.e=r),i!==n.t&&L(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t})()}),null),R(t,N(P,{get each(){return r().nodes},children:e=>(()=>{var t=Pr(),n=t.firstChild,r=n.nextSibling;return R(t,N(F,{get when(){return e.scar},get fallback(){return(()=>{var t=Fr();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&&L(t,`cx`,n.e=r),i!==n.t&&L(t,`cy`,n.t=i),a!==n.a&&L(t,`r`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t})()},children:t=>N(Qr,{get center(){return e.glyph.center},get mark(){return t()}})}),n),R(t,N(F,{get when(){return e.status===`active`},get children(){var t=Ar();return y(n=>{var r=e.glyph.center.x,i=e.glyph.center.y;return r!==n.e&&L(t,`cx`,n.e=r),i!==n.t&&L(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),R(t,N(F,{get when(){return e.status===`suspended`},get children(){return N(P,{each:[-2.4,Yr],children:t=>(()=>{var n=Ir();return y(r=>{var i=e.glyph.center.x+t,a=e.glyph.center.y-Xr,o=e.glyph.center.x+t,s=e.glyph.center.y+Xr;return i!==r.e&&L(n,`x1`,r.e=i),a!==r.t&&L(n,`y1`,r.t=a),o!==r.a&&L(n,`x2`,r.a=o),s!==r.o&&L(n,`y2`,r.o=s),r},{e:void 0,t:void 0,a:void 0,o:void 0}),n})()})}}),n),R(t,N(F,{keyed:!0,get when(){return be(()=>e.emits>0)()?e.emits:null},get children(){var t=jr();return y(n=>{var r=e.glyph.center.x,i=e.glyph.center.y;return r!==n.e&&L(t,`cx`,n.e=r),i!==n.t&&L(t,`cy`,n.t=i),n},{e:void 0,t:void 0}),t}}),n),R(t,N(F,{get when(){return e.glyph.terminus},get children(){var t=Mr();return y(n=>{var r=e.glyph.center.x,i=e.glyph.center.y,a=G.terminus_ring_radius;return r!==n.e&&L(t,`cx`,n.e=r),i!==n.t&&L(t,`cy`,n.t=i),a!==n.a&&L(t,`r`,n.a=a),n},{e:void 0,t:void 0,a:void 0}),t}}),n),R(n,()=>e.glyph.label),R(r,()=>e.meta,null),R(r,N(F,{get when(){return e.meta_fail},children:e=>[Lr(),(()=>{var t=Rr();return R(t,e),t})()]}),null),R(r,N(F,{get when(){return e.checkpoint},get children(){return Nr()}}),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&&L(t,`data-status`,i.e=a),o!==i.t&&L(t,`data-scar`,i.t=o),s!==i.a&&L(t,`data-node-id`,i.a=s),c!==i.o&&L(n,`x`,i.o=c),l!==i.i&&L(n,`y`,i.i=l),u!==i.n&&L(r,`x`,i.n=u),d!==i.s&&L(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),R(t,N(P,{get each(){return r().fail_marks},children:e=>(()=>{var t=zr();return y(()=>L(t,`d`,Zr(e.x,e.y,Gr))),t})()}),null),R(t,N(P,{get each(){return r().junctions},children:e=>(()=>{var t=Br(),n=t.firstChild,r=n.nextSibling;return R(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&&L(t,`data-status`,i.e=a),o!==i.t&&L(n,`cx`,i.t=o),s!==i.a&&L(n,`cy`,i.a=s),c!==i.o&&L(n,`r`,i.o=c),l!==i.i&&L(r,`x`,i.i=l),u!==i.n&&L(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),R(t,N(P,{get each(){return r().group_labels},children:e=>(()=>{var t=Vr(),n=t.firstChild,r=n.nextSibling;return R(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+G.group_tick_length,l=e.anchor.tick.y,u=e.anchor.text_anchor.x,d=e.anchor.text_anchor.y;return a!==i.e&&L(t,`data-owner`,i.e=a),o!==i.t&&L(n,`x1`,i.t=o),s!==i.a&&L(n,`y1`,i.a=s),c!==i.o&&L(n,`x2`,i.o=c),l!==i.i&&L(n,`y2`,i.i=l),u!==i.n&&L(r,`x`,i.n=u),d!==i.s&&L(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),R(t,N(P,{get each(){return r().cards},children:e=>(()=>{var t=Hr(),n=t.firstChild,r=n.nextSibling;return R(t,N(P,{get each(){return e.lines},children:e=>(()=>{var t=Ur();return R(t,N(P,{get each(){return e.spans},children:e=>(()=>{var t=Wr();return R(t,()=>e.text),y(()=>L(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&&L(t,`class`,n.e=r),i!==n.t&&L(t,`x`,n.t=i),a!==n.a&&L(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&&L(t,`data-owner`,i.e=a),o!==i.t&&L(n,`d`,i.t=o),s!==i.a&&L(r,`cx`,i.a=s),c!==i.o&&L(r,`cy`,i.o=c),i},{e:void 0,t:void 0,a:void 0,o:void 0}),t})()}),null),y(()=>L(t,`transform`,`translate(${a().offset_x} ${a().offset_y}) scale(${a().scale})`)),e})()}var ni=I(`<span data-testid=status><i class=status-dot>`),ri=I(`<button type=button class=return-live data-testid=return-to-live>RETURN TO LIVE`),ii=I(`<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>`),ai=I(`<span class="status status-replay"data-testid=status><i class=status-dot></i>REPLAY`),oi=I(`<span>`),si={connecting:`CONNECTING`,live:`LIVE`,offline:`OFFLINE`};function ci(e){return(()=>{var t=ni();return t.firstChild,R(t,()=>si[e.status],null),y(()=>Te(t,e.status===`live`?`status status-live`:`status status-offline`)),t})()}function li(e){let t=x(()=>Ve({t_plus_ms:e.play_t_plus_ms??Ne({fold_t_plus_ms:We(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}));return(()=>{var n=ii(),r=n.firstChild.firstChild,i=r.firstChild.nextSibling,a=r.nextSibling;return R(i,(()=>{var t=be(()=>e.session.state.run_id===null);return()=>t()?Fe:Ie(e.session.state.run_id)})()),R(r,N(F,{get when(){return e.following},get fallback(){return ai()},get children(){return N(ci,{get status(){return e.status}})}}),null),R(r,N(F,{get when(){return!e.following},get children(){var t=ri();return t.$$click=()=>e.on_return_to_live(),t}}),null),R(a,N(P,{get each(){return t()},children:e=>(()=>{var t=oi();return R(t,()=>e.text),y(()=>Te(t,`stats-${e.role}`)),t})()})),R(n,N(ti,{get session(){return e.session},get viewport(){return e.viewport}}),null),R(n,N(F,{get when(){return e.timeline.count>0},get children(){return[N(mr,{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}}),N(Me,{get playback(){return e.playback},get density(){return e.density},get on_toggle_play(){return e.on_toggle_play},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(()=>L(n,`data-chrome`,e.chrome_hidden?`hidden`:`visible`)),n})()}we([`click`]);function ui(e){let t;try{t=JSON.parse(e)}catch{return null}return di(t)?t:null}function di(e){return typeof e!=`object`||!e||Array.isArray(e)?!1:typeof e.kind==`string`}function fi(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=ui(e.data);t!==null&&r(t)}),a.addEventListener(`close`,()=>{i(`offline`)}),a.addEventListener(`error`,()=>{i(`offline`)}),{close:()=>{a.close()}}}var pi=`x-fascicle-cursor`;function mi(e,t){let n=Jt,r=[];for(let t of e.split(`
|
|
2
|
+
`)){if(t.length===0)continue;let e=ui(t);e!==null&&(n=Yt(n,e),r.push(e))}return{session:n,frames:r,count:r.length,cursor:Math.max(r.length,t)}}function hi(e){if(e===null)return 0;let t=Number.parseInt(e,10);return Number.isFinite(t)&&t>0?t:0}function gi(e){return e>0?`/api/events?since=${e}`:`/api/events`}var _i=2e3;function vi(e,t,n){let r=[],i=0,a=null;for(let o of e){if(a!==null){let e=(o-a)/t;i+=n===null?e:Math.min(e,n)}r.push(i),a=o}return{wall_times:r,wall_total_ms:i}}function yi(e,t){return vi(e,t.speed,t.compress?_i:null)}function bi(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 xi={playing:!1,speed:1,compress:!0,loop:!1,anchor_index:0,anchor_now_ms:0};function Si(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 Ci(e,t,n){let r=e.speed===1?2:e.speed===2?3:1;return Ai({...e,speed:r},t,n)}function wi(e,t,n){return Ai({...e,compress:!e.compress},t,n)}function Ti(e){return{...e,loop:!e.loop}}function Ei(e,t,n){return Ai(e,t,n)}function Di(e){return e.playing?{...e,playing:!1}:e}function Oi(e,t,n){return(e.wall_times[t.anchor_index]??0)+(n-t.anchor_now_ms)}function ki(e,t,n){return e.playing&&n-t>=2500}function Ai(e,t,n){return e.playing?{...e,anchor_index:t,anchor_now_ms:n}:e}var ji=`fascicle-viewer:density`;function Mi(){try{return localStorage.getItem(ji)===`on`}catch{return!1}}function Ni(e){try{localStorage.setItem(ji,e?`on`:`off`)}catch{}}function Pi(){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:Jt,received_at_ms:null}),[a,o]=v(`connecting`),[s,c]=v(performance.now()),[l,u]=v(Ii()),[d,f]=v(null),[p,m]=v(xi),[h,g]=v(Mi()),[_,y]=v(performance.now());window.addEventListener(`resize`,()=>u(Ii()));let S=x(()=>Qn(t())),ee=x(()=>d()===null),C=x(()=>d()??Math.max(0,S().count-1)),te=x(()=>d()===null?r().session:ar(t(),C())),ne=x(()=>d()===null?r().received_at_ms:null),re=x(()=>yi(S().times,p())),w=x(()=>{let e=p();return e.playing?bi(re(),S().times,Oi(re(),e,s())):null}),ie=x(()=>ki(p(),_(),s())),T=e=>{f(e),m(t=>Ei(t,e,s()))},E=e=>{T(er(S(),e))},D=()=>{m(Di),f(null)},O=()=>{m(e=>Si(e,d(),S().count,s()))},k=()=>{let e=!h();g(e),Ni(e)};window.addEventListener(`keydown`,e=>{if(e.key===` `){O(),e.preventDefault();return}let t=ir(S(),C(),e.key,e.shiftKey);t!==`ignore`&&(t===`live`?D():T(t),e.preventDefault())});let A=()=>{y(performance.now())};window.addEventListener(`pointermove`,A),window.addEventListener(`pointerdown`,A),window.addEventListener(`keydown`,A);let ae=e=>{c(e),requestAnimationFrame(ae)};requestAnimationFrame(ae),b(()=>{let e=w();e!==null&&(f(e.index),e.done&&m(e=>e.loop?{...e,anchor_index:0,anchor_now_ms:s()}:{...e,playing:!1}))}),Ce(()=>N(li,{get session(){return te()},get status(){return a()},get viewport(){return l()},get received_at_ms(){return ne()},get now_ms(){return s()},get following(){return ee()},get timeline(){return S()},get fraction(){return $n(S(),C())},get playback(){return p()},get play_t_plus_ms(){return w()?.t_plus_ms??null},get chrome_hidden(){return ie()},get density(){return h()},on_seek:E,on_return_to_live:D,on_toggle_play:O,on_cycle_speed:()=>m(e=>Ci(e,C(),s())),on_toggle_compress:()=>m(e=>wi(e,C(),s())),on_toggle_loop:()=>m(Ti),on_toggle_density:k}),e),Fi(n,i,o)}async function Fi(e,t,n){let r=0;try{let n=await fetch(`/api/trajectory`),i=mi(await n.text(),hi(n.headers.get(pi)));r=i.cursor,i.count>0&&(e(i.frames),t({session:i.session,received_at_ms:performance.now()}))}catch{}fi({url:gi(r),open:e=>new EventSource(e),on_status:n,on_frame:n=>{e(e=>[...e,n]),t(({session:e})=>({session:Yt(e,n),received_at_ms:performance.now()}))}})}function Ii(){return{width:window.innerWidth,height:window.innerHeight}}Pi();
|
|
@@ -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{color:#f6f3eae0}.status-replay .status-dot{animation:none}.return-live,.pb-button{font:500 10px var(--mono);letter-spacing:.2em;color:#f6f3ea9e;cursor:pointer;background:0 0;border:1px solid #f6f3ea38;border-radius:3px;padding:3px 9px}.return-live{margin-left:16px}.return-live:hover,.pb-button: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[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}@media (prefers-reduced-motion:reduce){.status-live .status-dot,.seg-live-march,.halo{animation:none}}
|