@rtkelly-labs/design-system 0.16.0-dev.0.37dedac → 0.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/components/AlertList.js +246 -0
  3. package/dist/components/AlertList.js.map +1 -0
  4. package/dist/components/FilterBar.js +215 -0
  5. package/dist/components/FilterBar.js.map +1 -0
  6. package/dist/components/FreshnessIndicator.js +50 -0
  7. package/dist/components/FreshnessIndicator.js.map +1 -0
  8. package/dist/components/IdChip.js +58 -0
  9. package/dist/components/IdChip.js.map +1 -0
  10. package/dist/components/IncidentTimeline.js +122 -0
  11. package/dist/components/IncidentTimeline.js.map +1 -0
  12. package/dist/components/LatencyHeatmap.js +382 -0
  13. package/dist/components/LatencyHeatmap.js.map +1 -0
  14. package/dist/components/LatencyHistogram.js +282 -0
  15. package/dist/components/LatencyHistogram.js.map +1 -0
  16. package/dist/components/LogViewer.js +393 -0
  17. package/dist/components/LogViewer.js.map +1 -0
  18. package/dist/components/ServiceMap.js +404 -0
  19. package/dist/components/ServiceMap.js.map +1 -0
  20. package/dist/components/SeverityBadge.js +15 -0
  21. package/dist/components/SeverityBadge.js.map +1 -0
  22. package/dist/components/TimeRange.js +89 -0
  23. package/dist/components/TimeRange.js.map +1 -0
  24. package/dist/components/TimeSeriesChart.js +507 -0
  25. package/dist/components/TimeSeriesChart.js.map +1 -0
  26. package/dist/components/TraceViewer.js +159 -0
  27. package/dist/components/TraceViewer.js.map +1 -0
  28. package/dist/components/TraceWaterfall.js +226 -0
  29. package/dist/components/TraceWaterfall.js.map +1 -0
  30. package/dist/components/saas/ObservabilityConsole.js +220 -0
  31. package/dist/components/saas/ObservabilityConsole.js.map +1 -0
  32. package/dist/components/saas/observabilityData.js +250 -0
  33. package/dist/components/saas/observabilityData.js.map +1 -0
  34. package/dist/hooks/useMeasuredWidth.js +22 -0
  35. package/dist/hooks/useMeasuredWidth.js.map +1 -0
  36. package/dist/hooks/useTraceClock.js +17 -0
  37. package/dist/hooks/useTraceClock.js.map +1 -0
  38. package/dist/hooks/useTraceReplay.js +75 -0
  39. package/dist/hooks/useTraceReplay.js.map +1 -0
  40. package/dist/index.d.ts +1562 -1
  41. package/dist/index.js +25 -0
  42. package/dist/index.js.map +1 -1
  43. package/dist/lib/filters.js +130 -0
  44. package/dist/lib/filters.js.map +1 -0
  45. package/dist/lib/ids.js +9 -0
  46. package/dist/lib/ids.js.map +1 -0
  47. package/dist/lib/latency.js +228 -0
  48. package/dist/lib/latency.js.map +1 -0
  49. package/dist/lib/logs.js +78 -0
  50. package/dist/lib/logs.js.map +1 -0
  51. package/dist/lib/serviceGraph.js +243 -0
  52. package/dist/lib/serviceGraph.js.map +1 -0
  53. package/dist/lib/severity.js +23 -0
  54. package/dist/lib/severity.js.map +1 -0
  55. package/dist/lib/timeRange.js +94 -0
  56. package/dist/lib/timeRange.js.map +1 -0
  57. package/dist/lib/timeSeries.js +285 -0
  58. package/dist/lib/timeSeries.js.map +1 -0
  59. package/dist/lib/trace.js +251 -0
  60. package/dist/lib/trace.js.map +1 -0
  61. package/package.json +1 -1
@@ -0,0 +1,404 @@
1
+ "use client";
2
+
3
+ // src/components/ServiceMap.tsx
4
+ import { forwardRef, useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
5
+ import { cn, recipe } from "../lib/recipe.js";
6
+ import {
7
+ formatServiceCount,
8
+ formatServiceErrorRate,
9
+ layoutServiceGraph,
10
+ serviceEdgeMidpoint,
11
+ serviceEdgePath,
12
+ serviceGraph
13
+ } from "../lib/serviceGraph.js";
14
+ import { formatTraceDuration } from "../lib/trace.js";
15
+ import { jsx, jsxs } from "react/jsx-runtime";
16
+ var NODE_WIDTH = 176;
17
+ var NODE_HEIGHT = 64;
18
+ var COLUMN_GAP = 136;
19
+ var ROW_GAP = 28;
20
+ var PAD = 16;
21
+ var LABEL_CHAR = 6.1;
22
+ var LABEL_HEIGHT = 14;
23
+ var DIM = 0.25;
24
+ var serviceMap = recipe({
25
+ slots: {
26
+ root: "flex min-w-0 flex-col gap-3 font-mono text-sm text-content-primary lg:flex-row lg:items-start",
27
+ canvas: "block h-auto w-full min-w-0 flex-1 overflow-visible",
28
+ node: "cursor-pointer",
29
+ name: "fill-content-primary text-[13px] font-bold",
30
+ kind: "fill-content-muted text-[10px] uppercase tracking-wider",
31
+ stats: "fill-content-secondary text-[11px]",
32
+ latency: "fill-content-muted text-[10px]",
33
+ label: "fill-content-secondary text-[10px]",
34
+ details: "flex w-full shrink-0 flex-col gap-3 border-2 border-edge-strong bg-surface-raised p-3 lg:w-72",
35
+ heading: "flex items-baseline justify-between gap-2 font-bold",
36
+ stat: "grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs",
37
+ term: "text-content-muted",
38
+ value: "text-right tabular-nums",
39
+ group: "flex flex-col gap-1 text-xs",
40
+ groupTitle: "text-content-muted uppercase tracking-wider",
41
+ link: "flex w-full cursor-pointer items-baseline justify-between gap-2 border border-edge-subtle bg-surface-base px-2 py-1 text-left hover:border-edge-strong hover:bg-surface-sunken",
42
+ clear: "cursor-pointer self-start border border-edge-default px-2 py-1 text-xs hover:bg-surface-sunken",
43
+ empty: "text-content-muted"
44
+ },
45
+ variants: {
46
+ danger: { true: { value: "text-intent-danger" } }
47
+ }
48
+ });
49
+ var KIND_LABEL = { service: "svc", database: "db", queue: "queue", external: "ext" };
50
+ var KIND_WORD = { service: "service", database: "database", queue: "queue", external: "external service" };
51
+ function plural(count, one, many = `${one}s`) {
52
+ return `${formatServiceCount(count)} ${count === 1 ? one : many}`;
53
+ }
54
+ function rate(errors, total) {
55
+ return total > 0 ? errors / total : 0;
56
+ }
57
+ function edgeWeight(calls) {
58
+ return 1.5 + Math.min(3, Math.max(0, Math.floor(Math.log10(Math.max(1, calls)))));
59
+ }
60
+ function edgeLabel(edge) {
61
+ return `${plural(edge.calls, "call")} \xB7 ${formatServiceErrorRate(edge.errors, edge.calls)} err`;
62
+ }
63
+ function truncate(text, max) {
64
+ return text.length <= max ? text : `${text.slice(0, Math.max(1, max - 1))}\u2026`;
65
+ }
66
+ function describeNode(node, inbound, outbound, overThreshold) {
67
+ const kind = node.kind ?? "service";
68
+ return [
69
+ node.id,
70
+ KIND_WORD[kind],
71
+ plural(node.requests, "request"),
72
+ plural(node.errors, "error"),
73
+ `${formatServiceErrorRate(node.errors, node.requests)} error rate`,
74
+ `average ${formatTraceDuration(node.avgDuration)}`,
75
+ ...node.p95Duration !== void 0 ? [`p95 ${formatTraceDuration(node.p95Duration)}`] : [],
76
+ ...overThreshold ? ["over the error threshold"] : [],
77
+ `called by ${plural(inbound, "service")}`,
78
+ `calls ${plural(outbound, "service")}`
79
+ ].join(", ");
80
+ }
81
+ function useControllable(value, initial, onChange) {
82
+ const [owned, setOwned] = useState(initial);
83
+ const current = value === void 0 ? owned : value;
84
+ const set = useCallback((next) => {
85
+ if (value === void 0) setOwned(next);
86
+ onChange?.(next);
87
+ }, [value, onChange]);
88
+ return [current, set];
89
+ }
90
+ function overlaps(a, b) {
91
+ return a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;
92
+ }
93
+ var ServiceMap = forwardRef(function ServiceMap2({
94
+ graph: graphProp,
95
+ spans,
96
+ selectedId: selectedProp,
97
+ defaultSelectedId = null,
98
+ onSelectedChange,
99
+ errorThreshold = 0.05,
100
+ title = "Service map",
101
+ height,
102
+ edgeLabels = "auto",
103
+ className,
104
+ ...props
105
+ }, ref) {
106
+ const graph = useMemo(() => graphProp ?? serviceGraph(spans ?? []), [graphProp, spans]);
107
+ const layout = useMemo(
108
+ () => layoutServiceGraph(graph, { nodeWidth: NODE_WIDTH, nodeHeight: NODE_HEIGHT, columnGap: COLUMN_GAP, rowGap: ROW_GAP }),
109
+ [graph]
110
+ );
111
+ const nodeById = useMemo(() => new Map(graph.nodes.map((node) => [node.id, node])), [graph]);
112
+ const placedById = useMemo(() => new Map(layout.nodes.map((node) => [node.id, node])), [layout]);
113
+ const edgeByKey = useMemo(() => new Map(graph.edges.map((edge) => [`${edge.from}\0${edge.to}`, edge])), [graph]);
114
+ const inboundOf = useCallback((id) => graph.edges.filter((edge) => edge.to === id && edge.from !== id), [graph]);
115
+ const outboundOf = useCallback((id) => graph.edges.filter((edge) => edge.from === id && edge.to !== id), [graph]);
116
+ const over = useCallback((node) => rate(node.errors, node.requests) > errorThreshold, [errorThreshold]);
117
+ const [selectedRaw, setSelectedId] = useControllable(selectedProp, defaultSelectedId, onSelectedChange);
118
+ const selectedId = selectedRaw !== null && placedById.has(selectedRaw) ? selectedRaw : null;
119
+ const neighbourhood = useMemo(() => {
120
+ if (!selectedId) return null;
121
+ const ids = /* @__PURE__ */ new Set([selectedId]);
122
+ for (const edge of graph.edges) {
123
+ if (edge.from === selectedId) ids.add(edge.to);
124
+ if (edge.to === selectedId) ids.add(edge.from);
125
+ }
126
+ return ids;
127
+ }, [graph, selectedId]);
128
+ const [activeId, setActiveId] = useState(null);
129
+ const [focusedId, setFocusedId] = useState(null);
130
+ const [hoveredEdge, setHoveredEdge] = useState(null);
131
+ const focusId = activeId && placedById.has(activeId) ? activeId : selectedId ?? layout.nodes[0]?.id ?? null;
132
+ const nodeRefs = useRef(/* @__PURE__ */ new Map());
133
+ const pendingFocus = useRef(false);
134
+ useEffect(() => {
135
+ if (!pendingFocus.current || !focusId) return;
136
+ pendingFocus.current = false;
137
+ nodeRefs.current.get(focusId)?.focus();
138
+ }, [focusId]);
139
+ const moveTo = (id) => {
140
+ if (!id) return;
141
+ pendingFocus.current = true;
142
+ setActiveId(id);
143
+ };
144
+ const layerNodes = useMemo(() => {
145
+ const layers = Array.from({ length: layout.layers }, () => []);
146
+ for (const node of layout.nodes) layers[node.layer].push(node);
147
+ return layers;
148
+ }, [layout]);
149
+ const nearestIn = (layer, y) => {
150
+ const candidates = layerNodes[layer];
151
+ if (!candidates?.length) return void 0;
152
+ return candidates.reduce((best, node) => Math.abs(node.y - y) < Math.abs(best.y - y) ? node : best).id;
153
+ };
154
+ const onKeyDown = (event, node) => {
155
+ switch (event.key) {
156
+ case "ArrowRight":
157
+ moveTo(nearestIn(node.layer + 1, node.y));
158
+ break;
159
+ case "ArrowLeft":
160
+ moveTo(nearestIn(node.layer - 1, node.y));
161
+ break;
162
+ case "ArrowDown":
163
+ moveTo(layerNodes[node.layer]?.[node.index + 1]?.id);
164
+ break;
165
+ case "ArrowUp":
166
+ moveTo(layerNodes[node.layer]?.[node.index - 1]?.id);
167
+ break;
168
+ case "Home":
169
+ moveTo(layout.nodes[0]?.id);
170
+ break;
171
+ case "End":
172
+ moveTo(layout.nodes[layout.nodes.length - 1]?.id);
173
+ break;
174
+ case "Enter":
175
+ case " ":
176
+ setSelectedId(node.id);
177
+ break;
178
+ case "Escape":
179
+ if (selectedId === null) return;
180
+ setSelectedId(null);
181
+ break;
182
+ default:
183
+ return;
184
+ }
185
+ event.preventDefault();
186
+ };
187
+ const fitting = useMemo(() => {
188
+ const fits = /* @__PURE__ */ new Set();
189
+ const taken = layout.nodes.map((node) => ({ x: node.x, y: node.y, width: NODE_WIDTH, height: NODE_HEIGHT }));
190
+ for (const placed of layout.edges) {
191
+ const edge = edgeByKey.get(`${placed.from}\0${placed.to}`);
192
+ if (!edge) continue;
193
+ const mid = serviceEdgeMidpoint(placed);
194
+ const width = edgeLabel(edge).length * LABEL_CHAR + 8;
195
+ const box = { x: mid.x - width / 2, y: mid.y - LABEL_HEIGHT / 2, width, height: LABEL_HEIGHT };
196
+ if (taken.some((other) => overlaps(box, other))) continue;
197
+ taken.push(box);
198
+ fits.add(`${placed.from}\0${placed.to}`);
199
+ }
200
+ return fits;
201
+ }, [layout, edgeByKey]);
202
+ const uid = useId().replace(/[^a-zA-Z0-9_-]/g, "");
203
+ const summaryId = `${uid}-summary`;
204
+ const styles = serviceMap();
205
+ if (!layout.nodes.length) {
206
+ return /* @__PURE__ */ jsx("div", { ref, "data-slot": "service-map", ...props, className: styles.root({ className }), children: /* @__PURE__ */ jsx("p", { className: styles.empty(), children: "No services to map." }) });
207
+ }
208
+ const hasBack = layout.edges.some((edge) => edge.back);
209
+ const viewWidth = layout.width + PAD * 2;
210
+ const viewHeight = layout.height + PAD * 2 + (hasBack ? ROW_GAP : 0);
211
+ const flagged = graph.nodes.filter(over);
212
+ const thresholdText = `${Number((errorThreshold * 100).toFixed(2))}%`;
213
+ const summary = `${plural(graph.nodes.length, "service")}, ${plural(layout.edges.length, "connection")}. ${flagged.length ? `${plural(flagged.length, "service")} over the ${thresholdText} error threshold: ${flagged.map((node) => node.id).join(", ")}.` : `None over the ${thresholdText} error threshold.`}`;
214
+ const selected = selectedId ? nodeById.get(selectedId) : void 0;
215
+ const nameChars = Math.floor((NODE_WIDTH - 20 - 40) / 7.8);
216
+ const edgeLink = (edge, neighbour, arrow) => /* @__PURE__ */ jsx("li", { children: /* @__PURE__ */ jsxs("button", { type: "button", "data-slot": "service-map-details-link", className: styles.link(), onClick: () => setSelectedId(neighbour), children: [
217
+ /* @__PURE__ */ jsxs("span", { className: "truncate", children: [
218
+ arrow,
219
+ " ",
220
+ neighbour
221
+ ] }),
222
+ /* @__PURE__ */ jsx("span", { className: cn("shrink-0 tabular-nums", edge.errors > 0 ? "text-intent-danger" : "text-content-secondary"), children: edgeLabel(edge) })
223
+ ] }) }, `${edge.from}-${edge.to}`);
224
+ return /* @__PURE__ */ jsxs("div", { ref, "data-slot": "service-map", ...props, className: styles.root({ className }), children: [
225
+ /* @__PURE__ */ jsx("p", { id: summaryId, className: "sr-only", children: summary }),
226
+ /* @__PURE__ */ jsxs(
227
+ "svg",
228
+ {
229
+ "data-slot": "service-map-canvas",
230
+ role: "group",
231
+ "aria-label": title,
232
+ "aria-describedby": summaryId,
233
+ viewBox: `0 0 ${viewWidth} ${viewHeight}`,
234
+ width: "100%",
235
+ height,
236
+ preserveAspectRatio: "xMidYMid meet",
237
+ className: styles.canvas(),
238
+ children: [
239
+ /* @__PURE__ */ jsxs("defs", { children: [
240
+ /* @__PURE__ */ jsx("marker", { id: `${uid}-arrow`, viewBox: "0 0 10 10", refX: 9, refY: 5, markerWidth: 9, markerHeight: 9, markerUnits: "userSpaceOnUse", orient: "auto", children: /* @__PURE__ */ jsx("path", { d: "M 0 0 L 10 5 L 0 10 z", className: "fill-edge-default" }) }),
241
+ /* @__PURE__ */ jsx("marker", { id: `${uid}-arrow-danger`, viewBox: "0 0 10 10", refX: 9, refY: 5, markerWidth: 9, markerHeight: 9, markerUnits: "userSpaceOnUse", orient: "auto", children: /* @__PURE__ */ jsx("path", { d: "M 0 0 L 10 5 L 0 10 z", className: "fill-intent-danger" }) }),
242
+ /* @__PURE__ */ jsx("marker", { id: `${uid}-arrow-active`, viewBox: "0 0 10 10", refX: 9, refY: 5, markerWidth: 9, markerHeight: 9, markerUnits: "userSpaceOnUse", orient: "auto", children: /* @__PURE__ */ jsx("path", { d: "M 0 0 L 10 5 L 0 10 z", className: "fill-accent-primary" }) })
243
+ ] }),
244
+ /* @__PURE__ */ jsxs("g", { transform: `translate(${PAD} ${PAD})`, children: [
245
+ /* @__PURE__ */ jsx("g", { "data-part": "edges", children: layout.edges.map((placed) => {
246
+ const key = `${placed.from}\0${placed.to}`;
247
+ const edge = edgeByKey.get(key);
248
+ if (!edge) return null;
249
+ const failing = edge.errors > 0;
250
+ const touchesSelected = selectedId !== null && (placed.from === selectedId || placed.to === selectedId);
251
+ const active = touchesSelected && !failing;
252
+ const d = serviceEdgePath(placed);
253
+ return /* @__PURE__ */ jsxs(
254
+ "g",
255
+ {
256
+ "data-slot": "service-map-edge",
257
+ "data-from": placed.from,
258
+ "data-to": placed.to,
259
+ "data-error": failing || void 0,
260
+ opacity: selectedId !== null && !touchesSelected ? DIM : void 0,
261
+ onMouseEnter: () => setHoveredEdge(key),
262
+ onMouseLeave: () => setHoveredEdge((current) => current === key ? null : current),
263
+ children: [
264
+ /* @__PURE__ */ jsx("path", { d, fill: "none", className: "stroke-transparent", strokeWidth: 12 }),
265
+ /* @__PURE__ */ jsx(
266
+ "path",
267
+ {
268
+ d,
269
+ fill: "none",
270
+ strokeWidth: edgeWeight(edge.calls),
271
+ strokeDasharray: placed.back ? "6 4" : void 0,
272
+ markerEnd: `url(#${uid}-arrow${failing ? "-danger" : active ? "-active" : ""})`,
273
+ className: failing ? "stroke-intent-danger" : active ? "stroke-accent-primary" : "stroke-edge-default"
274
+ }
275
+ )
276
+ ]
277
+ },
278
+ key
279
+ );
280
+ }) }),
281
+ /* @__PURE__ */ jsx("g", { "data-part": "nodes", children: layout.nodes.map((placed) => {
282
+ const node = nodeById.get(placed.id);
283
+ const kind = node.kind ?? "service";
284
+ const flaggedNode = over(node);
285
+ const isSelected = placed.id === selectedId;
286
+ const dimmed = neighbourhood !== null && !neighbourhood.has(placed.id);
287
+ const inbound = inboundOf(placed.id).length;
288
+ const outbound = outboundOf(placed.id).length;
289
+ return /* @__PURE__ */ jsxs(
290
+ "g",
291
+ {
292
+ ref: (element) => {
293
+ if (element) nodeRefs.current.set(placed.id, element);
294
+ else nodeRefs.current.delete(placed.id);
295
+ },
296
+ "data-slot": "service-map-node",
297
+ "data-service": placed.id,
298
+ "data-kind": kind,
299
+ "data-over-threshold": flaggedNode || void 0,
300
+ "data-selected": isSelected || void 0,
301
+ role: "button",
302
+ "aria-pressed": isSelected,
303
+ "aria-label": describeNode(node, inbound, outbound, flaggedNode),
304
+ tabIndex: placed.id === focusId ? 0 : -1,
305
+ transform: `translate(${placed.x} ${placed.y})`,
306
+ opacity: dimmed ? DIM : void 0,
307
+ className: styles.node(),
308
+ onFocus: () => {
309
+ setActiveId(placed.id);
310
+ setFocusedId(placed.id);
311
+ },
312
+ onBlur: () => setFocusedId((current) => current === placed.id ? null : current),
313
+ onClick: () => setSelectedId(placed.id),
314
+ onKeyDown: (event) => onKeyDown(event, placed),
315
+ children: [
316
+ /* @__PURE__ */ jsx("title", { children: placed.id }),
317
+ focusedId === placed.id ? /* @__PURE__ */ jsx("rect", { "data-part": "focus-ring", x: -5, y: -5, width: NODE_WIDTH + 10, height: NODE_HEIGHT + 10, rx: 6, fill: "none", strokeWidth: 2, strokeDasharray: "4 3", className: "stroke-accent-primary" }) : null,
318
+ /* @__PURE__ */ jsx(
319
+ "rect",
320
+ {
321
+ width: NODE_WIDTH,
322
+ height: NODE_HEIGHT,
323
+ rx: 4,
324
+ strokeWidth: isSelected ? 3 : 2,
325
+ className: cn("fill-surface-raised", isSelected ? "stroke-accent-primary" : flaggedNode ? "stroke-intent-danger" : "stroke-edge-strong")
326
+ }
327
+ ),
328
+ /* @__PURE__ */ jsx("text", { x: 10, y: 22, className: styles.name(), children: truncate(placed.id, nameChars) }),
329
+ /* @__PURE__ */ jsx("text", { x: NODE_WIDTH - 10, y: 21, textAnchor: "end", className: styles.kind(), children: KIND_LABEL[kind] }),
330
+ /* @__PURE__ */ jsxs("text", { x: 10, y: 41, className: styles.stats(), children: [
331
+ plural(node.requests, "req", "req"),
332
+ " \xB7 ",
333
+ /* @__PURE__ */ jsxs("tspan", { className: flaggedNode ? "fill-intent-danger" : void 0, children: [
334
+ formatServiceErrorRate(node.errors, node.requests),
335
+ " err"
336
+ ] })
337
+ ] }),
338
+ /* @__PURE__ */ jsxs("text", { x: 10, y: 56, className: styles.latency(), children: [
339
+ "avg ",
340
+ formatTraceDuration(node.avgDuration),
341
+ node.p95Duration !== void 0 ? ` \xB7 p95 ${formatTraceDuration(node.p95Duration)}` : ""
342
+ ] }),
343
+ flaggedNode ? /* @__PURE__ */ jsxs("g", { "data-part": "danger-badge", transform: `translate(${NODE_WIDTH} 0)`, children: [
344
+ /* @__PURE__ */ jsx("circle", { r: 9, className: "fill-intent-danger" }),
345
+ /* @__PURE__ */ jsx("text", { y: 4, textAnchor: "middle", className: "fill-content-inverse text-[12px] font-bold", children: "!" })
346
+ ] }) : null
347
+ ]
348
+ },
349
+ placed.id
350
+ );
351
+ }) }),
352
+ /* @__PURE__ */ jsx("g", { "data-part": "edge-labels", "aria-hidden": "true", children: layout.edges.map((placed) => {
353
+ const key = `${placed.from}\0${placed.to}`;
354
+ const edge = edgeByKey.get(key);
355
+ if (!edge) return null;
356
+ const touches = (id) => id !== null && (placed.from === id || placed.to === id);
357
+ const shown = edgeLabels === "always" || edgeLabels === "auto" && fitting.has(key) || hoveredEdge === key || touches(focusedId) || touches(selectedId);
358
+ if (!shown) return null;
359
+ const text = edgeLabel(edge);
360
+ const mid = serviceEdgeMidpoint(placed);
361
+ const width = text.length * LABEL_CHAR + 8;
362
+ return /* @__PURE__ */ jsxs("g", { "data-slot": "service-map-edge-label", transform: `translate(${mid.x} ${mid.y})`, opacity: selectedId !== null && !touches(selectedId) ? DIM : void 0, children: [
363
+ /* @__PURE__ */ jsx("rect", { x: -width / 2, y: -LABEL_HEIGHT / 2, width, height: LABEL_HEIGHT, rx: 2, className: "fill-surface-base" }),
364
+ /* @__PURE__ */ jsx("text", { y: 3.5, textAnchor: "middle", className: cn(styles.label(), edge.errors > 0 && "fill-intent-danger"), children: text })
365
+ ] }, key);
366
+ }) })
367
+ ] })
368
+ ]
369
+ }
370
+ ),
371
+ selected ? /* @__PURE__ */ jsxs("section", { "data-slot": "service-map-details", "aria-label": `${selected.id} details`, className: styles.details(), children: [
372
+ /* @__PURE__ */ jsxs("div", { className: styles.heading(), children: [
373
+ /* @__PURE__ */ jsx("span", { className: "truncate", children: selected.id }),
374
+ /* @__PURE__ */ jsx("span", { className: "shrink-0 text-xs font-normal text-content-muted", children: KIND_WORD[selected.kind ?? "service"] })
375
+ ] }),
376
+ /* @__PURE__ */ jsxs("dl", { className: styles.stat(), children: [
377
+ /* @__PURE__ */ jsx("dt", { className: styles.term(), children: "Requests" }),
378
+ /* @__PURE__ */ jsx("dd", { className: styles.value(), children: formatServiceCount(selected.requests) }),
379
+ /* @__PURE__ */ jsx("dt", { className: styles.term(), children: "Errors" }),
380
+ /* @__PURE__ */ jsx("dd", { className: styles.value({ danger: selected.errors > 0 }), children: formatServiceCount(selected.errors) }),
381
+ /* @__PURE__ */ jsx("dt", { className: styles.term(), children: "Error rate" }),
382
+ /* @__PURE__ */ jsx("dd", { className: styles.value({ danger: over(selected) }), children: formatServiceErrorRate(selected.errors, selected.requests) }),
383
+ /* @__PURE__ */ jsx("dt", { className: styles.term(), children: "Avg latency" }),
384
+ /* @__PURE__ */ jsx("dd", { className: styles.value(), children: formatTraceDuration(selected.avgDuration) }),
385
+ /* @__PURE__ */ jsx("dt", { className: styles.term(), children: "p95 latency" }),
386
+ /* @__PURE__ */ jsx("dd", { className: styles.value(), children: selected.p95Duration !== void 0 ? formatTraceDuration(selected.p95Duration) : "\u2014" })
387
+ ] }),
388
+ /* @__PURE__ */ jsxs("div", { className: styles.group(), children: [
389
+ /* @__PURE__ */ jsx("span", { className: styles.groupTitle(), children: "Inbound" }),
390
+ inboundOf(selected.id).length ? /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-1", children: inboundOf(selected.id).map((edge) => edgeLink(edge, edge.from, "\u2190")) }) : /* @__PURE__ */ jsx("span", { className: "text-content-muted", children: "Nothing calls this service." })
391
+ ] }),
392
+ /* @__PURE__ */ jsxs("div", { className: styles.group(), children: [
393
+ /* @__PURE__ */ jsx("span", { className: styles.groupTitle(), children: "Outbound" }),
394
+ outboundOf(selected.id).length ? /* @__PURE__ */ jsx("ul", { className: "flex flex-col gap-1", children: outboundOf(selected.id).map((edge) => edgeLink(edge, edge.to, "\u2192")) }) : /* @__PURE__ */ jsx("span", { className: "text-content-muted", children: "Calls no other service." })
395
+ ] }),
396
+ /* @__PURE__ */ jsx("button", { type: "button", className: styles.clear(), onClick: () => setSelectedId(null), children: "Clear selection" })
397
+ ] }) : null
398
+ ] });
399
+ });
400
+ ServiceMap.displayName = "ServiceMap";
401
+ export {
402
+ ServiceMap
403
+ };
404
+ //# sourceMappingURL=ServiceMap.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/ServiceMap.tsx"],"sourcesContent":["'use client';\n\nimport { forwardRef, useCallback, useEffect, useId, useMemo, useRef, useState, type HTMLAttributes, type KeyboardEvent } from 'react';\nimport { cn, recipe } from '../lib/recipe';\nimport {\n formatServiceCount,\n formatServiceErrorRate,\n layoutServiceGraph,\n serviceEdgeMidpoint,\n serviceEdgePath,\n serviceGraph,\n type ServiceEdge,\n type ServiceGraph,\n type ServiceGraphLayoutNode,\n type ServiceNode,\n type ServiceNodeKind,\n} from '../lib/serviceGraph';\nimport { formatTraceDuration, type TraceSpanInput } from '../lib/trace';\n\n/** Geometry in SVG user units. The SVG scales uniformly, so these are proportions. */\nconst NODE_WIDTH = 176;\nconst NODE_HEIGHT = 64;\nconst COLUMN_GAP = 136;\nconst ROW_GAP = 28;\nconst PAD = 16;\n/** Edge label: 10-unit monospace, so a character is about 6 units wide. */\nconst LABEL_CHAR = 6.1;\nconst LABEL_HEIGHT = 14;\nconst DIM = 0.25;\n\nconst serviceMap = recipe({\n slots: {\n root: 'flex min-w-0 flex-col gap-3 font-mono text-sm text-content-primary lg:flex-row lg:items-start',\n canvas: 'block h-auto w-full min-w-0 flex-1 overflow-visible',\n node: 'cursor-pointer',\n name: 'fill-content-primary text-[13px] font-bold',\n kind: 'fill-content-muted text-[10px] uppercase tracking-wider',\n stats: 'fill-content-secondary text-[11px]',\n latency: 'fill-content-muted text-[10px]',\n label: 'fill-content-secondary text-[10px]',\n details: 'flex w-full shrink-0 flex-col gap-3 border-2 border-edge-strong bg-surface-raised p-3 lg:w-72',\n heading: 'flex items-baseline justify-between gap-2 font-bold',\n stat: 'grid grid-cols-[auto_1fr] gap-x-3 gap-y-1 text-xs',\n term: 'text-content-muted',\n value: 'text-right tabular-nums',\n group: 'flex flex-col gap-1 text-xs',\n groupTitle: 'text-content-muted uppercase tracking-wider',\n link: 'flex w-full cursor-pointer items-baseline justify-between gap-2 border border-edge-subtle bg-surface-base px-2 py-1 text-left hover:border-edge-strong hover:bg-surface-sunken',\n clear: 'cursor-pointer self-start border border-edge-default px-2 py-1 text-xs hover:bg-surface-sunken',\n empty: 'text-content-muted',\n },\n variants: {\n danger: { true: { value: 'text-intent-danger' } },\n },\n});\n\nconst KIND_LABEL: Record<ServiceNodeKind, string> = { service: 'svc', database: 'db', queue: 'queue', external: 'ext' };\nconst KIND_WORD: Record<ServiceNodeKind, string> = { service: 'service', database: 'database', queue: 'queue', external: 'external service' };\n\nfunction plural(count: number, one: string, many = `${one}s`): string {\n return `${formatServiceCount(count)} ${count === 1 ? one : many}`;\n}\n\nfunction rate(errors: number, total: number): number {\n return total > 0 ? errors / total : 0;\n}\n\n/** Thicker for more traffic, by order of magnitude: 1–9, 10–99, 100–999, 1k+. */\nfunction edgeWeight(calls: number): number {\n return 1.5 + Math.min(3, Math.max(0, Math.floor(Math.log10(Math.max(1, calls)))));\n}\n\n/** `1.2k calls · 2% err`. */\nfunction edgeLabel(edge: ServiceEdge): string {\n return `${plural(edge.calls, 'call')} · ${formatServiceErrorRate(edge.errors, edge.calls)} err`;\n}\n\nfunction truncate(text: string, max: number): string {\n return text.length <= max ? text : `${text.slice(0, Math.max(1, max - 1))}…`;\n}\n\n/** What a screen reader hears for one node — its box, said in words. */\nfunction describeNode(node: ServiceNode, inbound: number, outbound: number, overThreshold: boolean): string {\n const kind = node.kind ?? 'service';\n return [\n node.id,\n KIND_WORD[kind],\n plural(node.requests, 'request'),\n plural(node.errors, 'error'),\n `${formatServiceErrorRate(node.errors, node.requests)} error rate`,\n `average ${formatTraceDuration(node.avgDuration)}`,\n ...(node.p95Duration !== undefined ? [`p95 ${formatTraceDuration(node.p95Duration)}`] : []),\n ...(overThreshold ? ['over the error threshold'] : []),\n `called by ${plural(inbound, 'service')}`,\n `calls ${plural(outbound, 'service')}`,\n ].join(', ');\n}\n\n/** A value that is controlled when the prop is defined, and owned here otherwise. */\nfunction useControllable<T>(value: T | undefined, initial: T, onChange?: (next: T) => void): [T, (next: T) => void] {\n const [owned, setOwned] = useState(initial);\n const current = value === undefined ? owned : value;\n const set = useCallback((next: T) => {\n if (value === undefined) setOwned(next);\n onChange?.(next);\n }, [value, onChange]);\n return [current, set];\n}\n\ninterface Box { x: number; y: number; width: number; height: number }\nfunction overlaps(a: Box, b: Box): boolean {\n return a.x < b.x + b.width && b.x < a.x + a.width && a.y < b.y + b.height && b.y < a.y + a.height;\n}\n\nexport interface ServiceMapProps extends Omit<HTMLAttributes<HTMLDivElement>, 'title'> {\n /** The graph to draw. Takes precedence over `spans`. */\n graph?: ServiceGraph;\n /**\n * Spans folded into a graph with `serviceGraph`: one flat list (ids unique\n * across it), or a list of traces whose ids may repeat. Ignored when `graph`\n * is given.\n */\n spans?: readonly TraceSpanInput[] | readonly (readonly TraceSpanInput[])[];\n /** The selected service id. Controlled when defined; `null` selects nothing. */\n selectedId?: string | null;\n /** The service selected on mount when uncontrolled. */\n defaultSelectedId?: string | null;\n /** Called with the id a click, Enter or Space selects, or `null` when Escape clears it. */\n onSelectedChange?: (id: string | null) => void;\n /**\n * Error rate (0–1) above which a service is flagged: outlined in the danger\n * role and badged. Default `0.05`.\n */\n errorThreshold?: number;\n /** Accessible name for the map. Default `Service map`. */\n title?: string;\n /**\n * Height of the drawing, as an SVG length (`320`, `\"20rem\"`). The graph is\n * fitted inside it without stretching. Default: as tall as its width implies.\n */\n height?: number | string;\n /**\n * When edge labels (`1.2k calls · 2% err`) show. `auto` (default) shows every\n * label that fits without overlapping a node or another label, and the rest\n * on hover or when an end is focused or selected; `interactive` shows them\n * only then; `always` shows all of them.\n */\n edgeLabels?: 'auto' | 'always' | 'interactive';\n}\n\n/**\n * A service dependency map: one box per service, one arrow per caller →\n * callee pair, laid out in layers from the services nothing calls.\n *\n * Feed it a `graph`, or `spans` from any number of traces and it folds them\n * with `serviceGraph`. Boxes carry request count and error rate; a service\n * over `errorThreshold` is outlined and badged in the danger role, and an\n * edge that carried errors is drawn in it. Selecting a service dims all but\n * its neighbourhood and opens a details panel whose inbound and outbound\n * calls are buttons to the neighbour.\n *\n * The boxes are a roving tab stop in layer order — Left and Right cross\n * layers, Up and Down move within one, Enter or Space selects, Escape clears —\n * hand-rolled per the one-interaction-library rule. Everything is placed with\n * SVG attributes, so no inline style.\n */\nexport const ServiceMap = forwardRef<HTMLDivElement, ServiceMapProps>(function ServiceMap(\n {\n graph: graphProp,\n spans,\n selectedId: selectedProp,\n defaultSelectedId = null,\n onSelectedChange,\n errorThreshold = 0.05,\n title = 'Service map',\n height,\n edgeLabels = 'auto',\n className,\n ...props\n },\n ref,\n) {\n const graph = useMemo(() => graphProp ?? serviceGraph(spans ?? []), [graphProp, spans]);\n const layout = useMemo(\n () => layoutServiceGraph(graph, { nodeWidth: NODE_WIDTH, nodeHeight: NODE_HEIGHT, columnGap: COLUMN_GAP, rowGap: ROW_GAP }),\n [graph],\n );\n const nodeById = useMemo(() => new Map(graph.nodes.map((node) => [node.id, node])), [graph]);\n const placedById = useMemo(() => new Map(layout.nodes.map((node) => [node.id, node])), [layout]);\n const edgeByKey = useMemo(() => new Map(graph.edges.map((edge) => [`${edge.from}\\u0000${edge.to}`, edge])), [graph]);\n const inboundOf = useCallback((id: string) => graph.edges.filter((edge) => edge.to === id && edge.from !== id), [graph]);\n const outboundOf = useCallback((id: string) => graph.edges.filter((edge) => edge.from === id && edge.to !== id), [graph]);\n const over = useCallback((node: ServiceNode) => rate(node.errors, node.requests) > errorThreshold, [errorThreshold]);\n\n const [selectedRaw, setSelectedId] = useControllable<string | null>(selectedProp, defaultSelectedId, onSelectedChange);\n const selectedId = selectedRaw !== null && placedById.has(selectedRaw) ? selectedRaw : null;\n const neighbourhood = useMemo(() => {\n if (!selectedId) return null;\n const ids = new Set([selectedId]);\n for (const edge of graph.edges) {\n if (edge.from === selectedId) ids.add(edge.to);\n if (edge.to === selectedId) ids.add(edge.from);\n }\n return ids;\n }, [graph, selectedId]);\n\n // Roving tabindex over the boxes, in layer order.\n const [activeId, setActiveId] = useState<string | null>(null);\n const [focusedId, setFocusedId] = useState<string | null>(null);\n const [hoveredEdge, setHoveredEdge] = useState<string | null>(null);\n const focusId = activeId && placedById.has(activeId) ? activeId : (selectedId ?? layout.nodes[0]?.id ?? null);\n const nodeRefs = useRef(new Map<string, SVGGElement>());\n const pendingFocus = useRef(false);\n useEffect(() => {\n if (!pendingFocus.current || !focusId) return;\n pendingFocus.current = false;\n nodeRefs.current.get(focusId)?.focus();\n }, [focusId]);\n const moveTo = (id: string | undefined) => {\n if (!id) return;\n pendingFocus.current = true;\n setActiveId(id);\n };\n\n const layerNodes = useMemo(() => {\n const layers: ServiceGraphLayoutNode[][] = Array.from({ length: layout.layers }, () => []);\n for (const node of layout.nodes) layers[node.layer]!.push(node);\n return layers;\n }, [layout]);\n const nearestIn = (layer: number, y: number) => {\n const candidates = layerNodes[layer];\n if (!candidates?.length) return undefined;\n return candidates.reduce((best, node) => (Math.abs(node.y - y) < Math.abs(best.y - y) ? node : best)).id;\n };\n\n const onKeyDown = (event: KeyboardEvent<SVGGElement>, node: ServiceGraphLayoutNode) => {\n switch (event.key) {\n case 'ArrowRight': moveTo(nearestIn(node.layer + 1, node.y)); break;\n case 'ArrowLeft': moveTo(nearestIn(node.layer - 1, node.y)); break;\n case 'ArrowDown': moveTo(layerNodes[node.layer]?.[node.index + 1]?.id); break;\n case 'ArrowUp': moveTo(layerNodes[node.layer]?.[node.index - 1]?.id); break;\n case 'Home': moveTo(layout.nodes[0]?.id); break;\n case 'End': moveTo(layout.nodes[layout.nodes.length - 1]?.id); break;\n case 'Enter':\n case ' ':\n setSelectedId(node.id);\n break;\n case 'Escape':\n if (selectedId === null) return;\n setSelectedId(null);\n break;\n default:\n return;\n }\n event.preventDefault();\n };\n\n // Labels that fit: greedily, in edge order, clear of every box and of each other.\n const fitting = useMemo(() => {\n const fits = new Set<string>();\n const taken: Box[] = layout.nodes.map((node) => ({ x: node.x, y: node.y, width: NODE_WIDTH, height: NODE_HEIGHT }));\n for (const placed of layout.edges) {\n const edge = edgeByKey.get(`${placed.from}\\u0000${placed.to}`);\n if (!edge) continue;\n const mid = serviceEdgeMidpoint(placed);\n const width = edgeLabel(edge).length * LABEL_CHAR + 8;\n const box = { x: mid.x - width / 2, y: mid.y - LABEL_HEIGHT / 2, width, height: LABEL_HEIGHT };\n if (taken.some((other) => overlaps(box, other))) continue;\n taken.push(box);\n fits.add(`${placed.from}\\u0000${placed.to}`);\n }\n return fits;\n }, [layout, edgeByKey]);\n\n const uid = useId().replace(/[^a-zA-Z0-9_-]/g, '');\n const summaryId = `${uid}-summary`;\n const styles = serviceMap();\n\n if (!layout.nodes.length) {\n return (\n <div ref={ref} data-slot=\"service-map\" {...props} className={styles.root({ className })}>\n <p className={styles.empty()}>No services to map.</p>\n </div>\n );\n }\n\n const hasBack = layout.edges.some((edge) => edge.back);\n const viewWidth = layout.width + PAD * 2;\n const viewHeight = layout.height + PAD * 2 + (hasBack ? ROW_GAP : 0);\n const flagged = graph.nodes.filter(over);\n const thresholdText = `${Number((errorThreshold * 100).toFixed(2))}%`;\n const summary = `${plural(graph.nodes.length, 'service')}, ${plural(layout.edges.length, 'connection')}. ${\n flagged.length\n ? `${plural(flagged.length, 'service')} over the ${thresholdText} error threshold: ${flagged.map((node) => node.id).join(', ')}.`\n : `None over the ${thresholdText} error threshold.`\n }`;\n\n const selected = selectedId ? nodeById.get(selectedId) : undefined;\n const nameChars = Math.floor((NODE_WIDTH - 20 - 40) / 7.8);\n\n const edgeLink = (edge: ServiceEdge, neighbour: string, arrow: string) => (\n <li key={`${edge.from}-${edge.to}`}>\n <button type=\"button\" data-slot=\"service-map-details-link\" className={styles.link()} onClick={() => setSelectedId(neighbour)}>\n <span className=\"truncate\">{arrow} {neighbour}</span>\n <span className={cn('shrink-0 tabular-nums', edge.errors > 0 ? 'text-intent-danger' : 'text-content-secondary')}>{edgeLabel(edge)}</span>\n </button>\n </li>\n );\n\n return (\n <div ref={ref} data-slot=\"service-map\" {...props} className={styles.root({ className })}>\n <p id={summaryId} className=\"sr-only\">{summary}</p>\n <svg\n data-slot=\"service-map-canvas\"\n role=\"group\"\n aria-label={title}\n aria-describedby={summaryId}\n viewBox={`0 0 ${viewWidth} ${viewHeight}`}\n width=\"100%\"\n height={height}\n preserveAspectRatio=\"xMidYMid meet\"\n className={styles.canvas()}\n >\n <defs>\n <marker id={`${uid}-arrow`} viewBox=\"0 0 10 10\" refX={9} refY={5} markerWidth={9} markerHeight={9} markerUnits=\"userSpaceOnUse\" orient=\"auto\">\n <path d=\"M 0 0 L 10 5 L 0 10 z\" className=\"fill-edge-default\" />\n </marker>\n <marker id={`${uid}-arrow-danger`} viewBox=\"0 0 10 10\" refX={9} refY={5} markerWidth={9} markerHeight={9} markerUnits=\"userSpaceOnUse\" orient=\"auto\">\n <path d=\"M 0 0 L 10 5 L 0 10 z\" className=\"fill-intent-danger\" />\n </marker>\n <marker id={`${uid}-arrow-active`} viewBox=\"0 0 10 10\" refX={9} refY={5} markerWidth={9} markerHeight={9} markerUnits=\"userSpaceOnUse\" orient=\"auto\">\n <path d=\"M 0 0 L 10 5 L 0 10 z\" className=\"fill-accent-primary\" />\n </marker>\n </defs>\n <g transform={`translate(${PAD} ${PAD})`}>\n <g data-part=\"edges\">\n {layout.edges.map((placed) => {\n const key = `${placed.from}\\u0000${placed.to}`;\n const edge = edgeByKey.get(key);\n if (!edge) return null;\n const failing = edge.errors > 0;\n const touchesSelected = selectedId !== null && (placed.from === selectedId || placed.to === selectedId);\n const active = touchesSelected && !failing;\n const d = serviceEdgePath(placed);\n return (\n <g\n key={key}\n data-slot=\"service-map-edge\"\n data-from={placed.from}\n data-to={placed.to}\n data-error={failing || undefined}\n opacity={selectedId !== null && !touchesSelected ? DIM : undefined}\n onMouseEnter={() => setHoveredEdge(key)}\n onMouseLeave={() => setHoveredEdge((current) => (current === key ? null : current))}\n >\n <path d={d} fill=\"none\" className=\"stroke-transparent\" strokeWidth={12} />\n <path\n d={d}\n fill=\"none\"\n strokeWidth={edgeWeight(edge.calls)}\n strokeDasharray={placed.back ? '6 4' : undefined}\n markerEnd={`url(#${uid}-arrow${failing ? '-danger' : active ? '-active' : ''})`}\n className={failing ? 'stroke-intent-danger' : active ? 'stroke-accent-primary' : 'stroke-edge-default'}\n />\n </g>\n );\n })}\n </g>\n <g data-part=\"nodes\">\n {layout.nodes.map((placed) => {\n const node = nodeById.get(placed.id)!;\n const kind = node.kind ?? 'service';\n const flaggedNode = over(node);\n const isSelected = placed.id === selectedId;\n const dimmed = neighbourhood !== null && !neighbourhood.has(placed.id);\n const inbound = inboundOf(placed.id).length;\n const outbound = outboundOf(placed.id).length;\n return (\n <g\n key={placed.id}\n ref={(element) => { if (element) nodeRefs.current.set(placed.id, element); else nodeRefs.current.delete(placed.id); }}\n data-slot=\"service-map-node\"\n data-service={placed.id}\n data-kind={kind}\n data-over-threshold={flaggedNode || undefined}\n data-selected={isSelected || undefined}\n role=\"button\"\n aria-pressed={isSelected}\n aria-label={describeNode(node, inbound, outbound, flaggedNode)}\n tabIndex={placed.id === focusId ? 0 : -1}\n transform={`translate(${placed.x} ${placed.y})`}\n opacity={dimmed ? DIM : undefined}\n className={styles.node()}\n onFocus={() => { setActiveId(placed.id); setFocusedId(placed.id); }}\n onBlur={() => setFocusedId((current) => (current === placed.id ? null : current))}\n onClick={() => setSelectedId(placed.id)}\n onKeyDown={(event) => onKeyDown(event, placed)}\n >\n <title>{placed.id}</title>\n {focusedId === placed.id ? (\n <rect data-part=\"focus-ring\" x={-5} y={-5} width={NODE_WIDTH + 10} height={NODE_HEIGHT + 10} rx={6} fill=\"none\" strokeWidth={2} strokeDasharray=\"4 3\" className=\"stroke-accent-primary\" />\n ) : null}\n <rect\n width={NODE_WIDTH}\n height={NODE_HEIGHT}\n rx={4}\n strokeWidth={isSelected ? 3 : 2}\n className={cn('fill-surface-raised', isSelected ? 'stroke-accent-primary' : flaggedNode ? 'stroke-intent-danger' : 'stroke-edge-strong')}\n />\n <text x={10} y={22} className={styles.name()}>{truncate(placed.id, nameChars)}</text>\n <text x={NODE_WIDTH - 10} y={21} textAnchor=\"end\" className={styles.kind()}>{KIND_LABEL[kind]}</text>\n <text x={10} y={41} className={styles.stats()}>\n {plural(node.requests, 'req', 'req')} · <tspan className={flaggedNode ? 'fill-intent-danger' : undefined}>{formatServiceErrorRate(node.errors, node.requests)} err</tspan>\n </text>\n <text x={10} y={56} className={styles.latency()}>\n avg {formatTraceDuration(node.avgDuration)}{node.p95Duration !== undefined ? ` · p95 ${formatTraceDuration(node.p95Duration)}` : ''}\n </text>\n {flaggedNode ? (\n <g data-part=\"danger-badge\" transform={`translate(${NODE_WIDTH} 0)`}>\n <circle r={9} className=\"fill-intent-danger\" />\n <text y={4} textAnchor=\"middle\" className=\"fill-content-inverse text-[12px] font-bold\">!</text>\n </g>\n ) : null}\n </g>\n );\n })}\n </g>\n <g data-part=\"edge-labels\" aria-hidden=\"true\">\n {layout.edges.map((placed) => {\n const key = `${placed.from}\\u0000${placed.to}`;\n const edge = edgeByKey.get(key);\n if (!edge) return null;\n const touches = (id: string | null) => id !== null && (placed.from === id || placed.to === id);\n const shown = edgeLabels === 'always'\n || (edgeLabels === 'auto' && fitting.has(key))\n || hoveredEdge === key\n || touches(focusedId)\n || touches(selectedId);\n if (!shown) return null;\n const text = edgeLabel(edge);\n const mid = serviceEdgeMidpoint(placed);\n const width = text.length * LABEL_CHAR + 8;\n return (\n <g key={key} data-slot=\"service-map-edge-label\" transform={`translate(${mid.x} ${mid.y})`} opacity={selectedId !== null && !touches(selectedId) ? DIM : undefined}>\n <rect x={-width / 2} y={-LABEL_HEIGHT / 2} width={width} height={LABEL_HEIGHT} rx={2} className=\"fill-surface-base\" />\n <text y={3.5} textAnchor=\"middle\" className={cn(styles.label(), edge.errors > 0 && 'fill-intent-danger')}>{text}</text>\n </g>\n );\n })}\n </g>\n </g>\n </svg>\n {selected ? (\n <section data-slot=\"service-map-details\" aria-label={`${selected.id} details`} className={styles.details()}>\n <div className={styles.heading()}>\n <span className=\"truncate\">{selected.id}</span>\n <span className=\"shrink-0 text-xs font-normal text-content-muted\">{KIND_WORD[selected.kind ?? 'service']}</span>\n </div>\n <dl className={styles.stat()}>\n <dt className={styles.term()}>Requests</dt>\n <dd className={styles.value()}>{formatServiceCount(selected.requests)}</dd>\n <dt className={styles.term()}>Errors</dt>\n <dd className={styles.value({ danger: selected.errors > 0 })}>{formatServiceCount(selected.errors)}</dd>\n <dt className={styles.term()}>Error rate</dt>\n <dd className={styles.value({ danger: over(selected) })}>{formatServiceErrorRate(selected.errors, selected.requests)}</dd>\n <dt className={styles.term()}>Avg latency</dt>\n <dd className={styles.value()}>{formatTraceDuration(selected.avgDuration)}</dd>\n <dt className={styles.term()}>p95 latency</dt>\n <dd className={styles.value()}>{selected.p95Duration !== undefined ? formatTraceDuration(selected.p95Duration) : '—'}</dd>\n </dl>\n <div className={styles.group()}>\n <span className={styles.groupTitle()}>Inbound</span>\n {inboundOf(selected.id).length ? <ul className=\"flex flex-col gap-1\">{inboundOf(selected.id).map((edge) => edgeLink(edge, edge.from, '←'))}</ul> : <span className=\"text-content-muted\">Nothing calls this service.</span>}\n </div>\n <div className={styles.group()}>\n <span className={styles.groupTitle()}>Outbound</span>\n {outboundOf(selected.id).length ? <ul className=\"flex flex-col gap-1\">{outboundOf(selected.id).map((edge) => edgeLink(edge, edge.to, '→'))}</ul> : <span className=\"text-content-muted\">Calls no other service.</span>}\n </div>\n <button type=\"button\" className={styles.clear()} onClick={() => setSelectedId(null)}>Clear selection</button>\n </section>\n ) : null}\n </div>\n );\n});\n\nServiceMap.displayName = 'ServiceMap';\n"],"mappings":";;;AAEA,SAAS,YAAY,aAAa,WAAW,OAAO,SAAS,QAAQ,gBAAyD;AAC9H,SAAS,IAAI,cAAc;AAC3B;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAMK;AACP,SAAS,2BAAgD;AAwQjD,cAsBA,YAtBA;AArQR,IAAM,aAAa;AACnB,IAAM,cAAc;AACpB,IAAM,aAAa;AACnB,IAAM,UAAU;AAChB,IAAM,MAAM;AAEZ,IAAM,aAAa;AACnB,IAAM,eAAe;AACrB,IAAM,MAAM;AAEZ,IAAM,aAAa,OAA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S,EAAE,EAAE,IAAI,CAAC,SAAS,SAAS,MAAM,KAAK,MAAM,QAAG,CAAC,GAAE,IAAQ,oBAAC,UAAK,WAAU,sBAAqB,yCAA2B;AAAA,SACrN;AAAA,MACA,qBAAC,SAAI,WAAW,OAAO,MAAM,GAC3B;AAAA,4BAAC,UAAK,WAAW,OAAO,WAAW,GAAG,sBAAQ;AAAA,QAC7C,WAAW,SAAS,EAAE,EAAE,SAAS,oBAAC,QAAG,WAAU,uBAAuB,qBAAW,SAAS,EAAE,EAAE,IAAI,CAAC,SAAS,SAAS,MAAM,KAAK,IAAI,QAAG,CAAC,GAAE,IAAQ,oBAAC,UAAK,WAAU,sBAAqB,qCAAuB;AAAA,SACjN;AAAA,MACA,oBAAC,YAAO,MAAK,UAAS,WAAW,OAAO,MAAM,GAAG,SAAS,MAAM,cAAc,IAAI,GAAG,6BAAe;AAAA,OACtG,IACE;AAAA,KACN;AAEJ,CAAC;AAED,WAAW,cAAc;","names":["ServiceMap"]}
@@ -0,0 +1,15 @@
1
+ // src/components/SeverityBadge.tsx
2
+ import { forwardRef } from "react";
3
+ import { cn } from "../lib/recipe.js";
4
+ import { severityAccent } from "../lib/severity.js";
5
+ import { Badge } from "./Badge.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ var LABELS = { warn: "WARN", fatal: "FATAL" };
8
+ var SeverityBadge = forwardRef(function SeverityBadge2({ severity, children, className, ...props }, ref) {
9
+ return /* @__PURE__ */ jsx(Badge, { ref, "data-slot": "severity-badge", "data-severity": severity, accent: severityAccent(severity), ...props, className: cn("whitespace-nowrap", className), children: children ?? LABELS[severity] ?? severity.toUpperCase() });
10
+ });
11
+ SeverityBadge.displayName = "SeverityBadge";
12
+ export {
13
+ SeverityBadge
14
+ };
15
+ //# sourceMappingURL=SeverityBadge.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/SeverityBadge.tsx"],"sourcesContent":["import { forwardRef } from 'react';\nimport { cn } from '../lib/recipe';\nimport { severityAccent, type Severity } from '../lib/severity';\nimport { Badge, type BadgeProps } from './Badge';\n\nconst LABELS: Partial<Record<Severity, string>> = { warn: 'WARN', fatal: 'FATAL' };\n\nexport interface SeverityBadgeProps extends Omit<BadgeProps, 'accent' | 'children'> {\n /** A log level, an alert state or an alert severity. */\n severity: Severity;\n /** Replaces the upper-cased severity as the visible text. */\n children?: BadgeProps['children'];\n}\n\n/**\n * A `Badge` whose colour comes from a fixed observability vocabulary — log\n * levels, alert states and severities — rather than from the caller, so\n * \"error\" cannot be painted as a success anywhere on a page.\n */\nexport const SeverityBadge = forwardRef<HTMLSpanElement, SeverityBadgeProps>(function SeverityBadge(\n { severity, children, className, ...props },\n ref,\n) {\n return (\n <Badge ref={ref} data-slot=\"severity-badge\" data-severity={severity} accent={severityAccent(severity)} {...props} className={cn('whitespace-nowrap', className)}>\n {children ?? LABELS[severity] ?? severity.toUpperCase()}\n </Badge>\n );\n});\n\nSeverityBadge.displayName = 'SeverityBadge';\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,UAAU;AACnB,SAAS,sBAAqC;AAC9C,SAAS,aAA8B;AAqBnC;AAnBJ,IAAM,SAA4C,EAAE,MAAM,QAAQ,OAAO,QAAQ;AAc1E,IAAM,gBAAgB,WAAgD,SAASA,eACpF,EAAE,UAAU,UAAU,WAAW,GAAG,MAAM,GAC1C,KACA;AACA,SACE,oBAAC,SAAM,KAAU,aAAU,kBAAiB,iBAAe,UAAU,QAAQ,eAAe,QAAQ,GAAI,GAAG,OAAO,WAAW,GAAG,qBAAqB,SAAS,GAC3J,sBAAY,OAAO,QAAQ,KAAK,SAAS,YAAY,GACxD;AAEJ,CAAC;AAED,cAAc,cAAc;","names":["SeverityBadge"]}
@@ -0,0 +1,89 @@
1
+ "use client";
2
+
3
+ // src/components/TimeRange.tsx
4
+ import { createContext, forwardRef, useCallback, useContext, useMemo, useState } from "react";
5
+ import { recipe } from "../lib/recipe.js";
6
+ import {
7
+ TIME_RANGE_PRESETS,
8
+ formatRange,
9
+ formatRangeDuration,
10
+ normaliseRange,
11
+ presetRange
12
+ } from "../lib/timeRange.js";
13
+ import { jsx, jsxs } from "react/jsx-runtime";
14
+ var RangeContext = createContext(null);
15
+ var CursorContext = createContext(null);
16
+ function useTimeRange() {
17
+ return useContext(RangeContext);
18
+ }
19
+ function useTimeCursor() {
20
+ return useContext(CursorContext);
21
+ }
22
+ function TimeRangeProvider({ now, defaultPresetId = "1h", range: rangeProp, onRangeChange, presets = TIME_RANGE_PRESETS, children }) {
23
+ const initial = presets.find((preset) => preset.id === defaultPresetId) ?? presets[0];
24
+ const [owned, setOwned] = useState(() => ({
25
+ range: initial ? presetRange(initial, now) : { from: now - 36e5, to: now },
26
+ presetId: initial?.id ?? null
27
+ }));
28
+ const [cursor, setCursor] = useState(null);
29
+ const setRange = useCallback((next, presetId = null) => {
30
+ const clean = normaliseRange(next);
31
+ if (!clean) return;
32
+ setOwned({ range: clean, presetId });
33
+ onRangeChange?.(clean, presetId);
34
+ }, [onRangeChange]);
35
+ const selectPreset = useCallback((id) => {
36
+ const preset = presets.find((candidate) => candidate.id === id);
37
+ if (preset) setRange(presetRange(preset, now), preset.id);
38
+ }, [presets, now, setRange]);
39
+ const rangeValue = useMemo(() => {
40
+ const active = owned.presetId ? presets.find((preset) => preset.id === owned.presetId) : void 0;
41
+ const controlled = normaliseRange(rangeProp);
42
+ const range = controlled ?? (active ? presetRange(active, now) : owned.range);
43
+ const presetId = controlled ? presets.find((preset) => controlled.to === now && controlled.to - controlled.from === preset.duration)?.id ?? null : owned.presetId;
44
+ return { now, range, presetId, presets, setRange, selectPreset };
45
+ }, [now, rangeProp, owned, presets, setRange, selectPreset]);
46
+ const cursorValue = useMemo(() => ({ cursor, setCursor }), [cursor]);
47
+ return /* @__PURE__ */ jsx(RangeContext.Provider, { value: rangeValue, children: /* @__PURE__ */ jsx(CursorContext.Provider, { value: cursorValue, children }) });
48
+ }
49
+ var timeRangePicker = recipe({
50
+ slots: {
51
+ root: "inline-flex flex-wrap items-center gap-2 font-mono text-xs text-content-primary",
52
+ presets: "flex border border-edge-default",
53
+ preset: "cursor-pointer border-l border-edge-default px-2 py-1 tabular-nums text-content-secondary first:border-l-0 hover:bg-surface-raised hover:text-content-primary aria-pressed:bg-accent-primary aria-pressed:text-content-inverse",
54
+ range: "tabular-nums text-content-secondary",
55
+ custom: "border border-accent-primary px-1.5 py-0.5 uppercase text-accent-primary",
56
+ reset: "cursor-pointer underline decoration-dotted underline-offset-2 text-content-secondary hover:text-content-primary"
57
+ }
58
+ });
59
+ var TimeRangePicker = forwardRef(function TimeRangePicker2({ label = "Time range", className, ...props }, ref) {
60
+ const state = useTimeRange();
61
+ const [lastPreset, setLastPreset] = useState(state?.presetId ?? null);
62
+ if (state?.presetId && state.presetId !== lastPreset) setLastPreset(state.presetId);
63
+ const styles = timeRangePicker();
64
+ if (!state) return null;
65
+ const custom = state.presetId === null;
66
+ return /* @__PURE__ */ jsxs("div", { ref, "data-slot": "time-range-picker", ...props, className: styles.root({ className }), children: [
67
+ /* @__PURE__ */ jsx("div", { role: "group", "aria-label": label, className: styles.presets(), children: state.presets.map((preset) => /* @__PURE__ */ jsx("button", { type: "button", "aria-pressed": state.presetId === preset.id, onClick: () => state.selectPreset(preset.id), className: styles.preset(), children: preset.label }, preset.id)) }),
68
+ custom ? /* @__PURE__ */ jsxs("span", { className: styles.custom(), children: [
69
+ "Zoomed \xB7 ",
70
+ formatRangeDuration(state.range.to - state.range.from)
71
+ ] }) : null,
72
+ /* @__PURE__ */ jsxs("span", { className: styles.range(), children: [
73
+ formatRange(state.range),
74
+ " UTC"
75
+ ] }),
76
+ custom && lastPreset ? /* @__PURE__ */ jsxs("button", { type: "button", onClick: () => state.selectPreset(lastPreset), className: styles.reset(), children: [
77
+ "Reset to ",
78
+ state.presets.find((preset) => preset.id === lastPreset)?.label
79
+ ] }) : null
80
+ ] });
81
+ });
82
+ TimeRangePicker.displayName = "TimeRangePicker";
83
+ export {
84
+ TimeRangePicker,
85
+ TimeRangeProvider,
86
+ useTimeCursor,
87
+ useTimeRange
88
+ };
89
+ //# sourceMappingURL=TimeRange.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/components/TimeRange.tsx"],"sourcesContent":["'use client';\n\nimport { createContext, forwardRef, useCallback, useContext, useMemo, useState, type HTMLAttributes, type ReactNode } from 'react';\nimport { recipe } from '../lib/recipe';\nimport {\n TIME_RANGE_PRESETS,\n formatRange,\n formatRangeDuration,\n normaliseRange,\n presetRange,\n type TimeRange,\n type TimeRangePreset,\n} from '../lib/timeRange';\n\nexport interface TimeRangeState {\n /** The page's clock, as the provider was given it. */\n now: number;\n /** The window every view on the page draws. */\n range: TimeRange;\n /** The preset the range came from, or null once it was zoomed or set by hand. */\n presetId: string | null;\n presets: readonly TimeRangePreset[];\n /** Set the window. Pass a preset id to keep it relative; omit to mark it custom. */\n setRange: (range: TimeRange, presetId?: string | null) => void;\n /** Select a preset by id. */\n selectPreset: (id: string) => void;\n}\n\nexport interface TimeCursorState {\n /** The time being hovered on any view, or null. */\n cursor: number | null;\n setCursor: (time: number | null) => void;\n}\n\nconst RangeContext = createContext<TimeRangeState | null>(null);\nconst CursorContext = createContext<TimeCursorState | null>(null);\n\n/**\n * The shared window, or null outside a `TimeRangeProvider` — every consumer\n * works standalone too, with its own props.\n */\nexport function useTimeRange(): TimeRangeState | null {\n return useContext(RangeContext);\n}\n\n/**\n * The shared hover cursor, or null outside a provider. Its own context, so a\n * cursor moving across a chart re-renders the views that draw it and nothing\n * that only reads the range.\n */\nexport function useTimeCursor(): TimeCursorState | null {\n return useContext(CursorContext);\n}\n\nexport interface TimeRangeProviderProps {\n /** The page's clock. Pass `Date.now()` in an app and a fixed epoch in a story. */\n now: number;\n /** The preset selected on mount when uncontrolled. Default `1h`. */\n defaultPresetId?: string;\n /** A controlled window. */\n range?: TimeRange;\n /** Called when the window changes, with the preset it came from. */\n onRangeChange?: (range: TimeRange, presetId: string | null) => void;\n /** The windows the picker offers. Default `TIME_RANGE_PRESETS`. */\n presets?: readonly TimeRangePreset[];\n children?: ReactNode;\n}\n\n/**\n * The time window and hover cursor every observability view on a page shares:\n * pick \"last hour\" once and every chart, heatmap and log list follows; hover\n * one chart and the others draw the same moment; drag across a chart to zoom\n * them all.\n *\n * Renders nothing of its own — it is context, like `ThemeProvider`.\n */\nexport function TimeRangeProvider({ now, defaultPresetId = '1h', range: rangeProp, onRangeChange, presets = TIME_RANGE_PRESETS, children }: TimeRangeProviderProps) {\n const initial = presets.find((preset) => preset.id === defaultPresetId) ?? presets[0];\n const [owned, setOwned] = useState<{ range: TimeRange; presetId: string | null }>(() => ({\n range: initial ? presetRange(initial, now) : { from: now - 3_600_000, to: now },\n presetId: initial?.id ?? null,\n }));\n const [cursor, setCursor] = useState<number | null>(null);\n\n const setRange = useCallback((next: TimeRange, presetId: string | null = null) => {\n const clean = normaliseRange(next);\n if (!clean) return;\n setOwned({ range: clean, presetId });\n onRangeChange?.(clean, presetId);\n }, [onRangeChange]);\n const selectPreset = useCallback((id: string) => {\n const preset = presets.find((candidate) => candidate.id === id);\n if (preset) setRange(presetRange(preset, now), preset.id);\n }, [presets, now, setRange]);\n\n const rangeValue = useMemo<TimeRangeState>(() => {\n // A relative preset follows `now`; a custom window stays where it was put.\n const active = owned.presetId ? presets.find((preset) => preset.id === owned.presetId) : undefined;\n const controlled = normaliseRange(rangeProp);\n const range = controlled ?? (active ? presetRange(active, now) : owned.range);\n // A controlled range that is exactly a preset ending at `now` is that preset,\n // so a parent that stores what `onRangeChange` gave it still shows it pressed.\n const presetId = controlled\n ? presets.find((preset) => controlled.to === now && controlled.to - controlled.from === preset.duration)?.id ?? null\n : owned.presetId;\n return { now, range, presetId, presets, setRange, selectPreset };\n }, [now, rangeProp, owned, presets, setRange, selectPreset]);\n const cursorValue = useMemo<TimeCursorState>(() => ({ cursor, setCursor }), [cursor]);\n\n return (\n <RangeContext.Provider value={rangeValue}>\n <CursorContext.Provider value={cursorValue}>{children}</CursorContext.Provider>\n </RangeContext.Provider>\n );\n}\n\nconst timeRangePicker = recipe({\n slots: {\n root: 'inline-flex flex-wrap items-center gap-2 font-mono text-xs text-content-primary',\n presets: 'flex border border-edge-default',\n preset: 'cursor-pointer border-l border-edge-default px-2 py-1 tabular-nums text-content-secondary first:border-l-0 hover:bg-surface-raised hover:text-content-primary aria-pressed:bg-accent-primary aria-pressed:text-content-inverse',\n range: 'tabular-nums text-content-secondary',\n custom: 'border border-accent-primary px-1.5 py-0.5 uppercase text-accent-primary',\n reset: 'cursor-pointer underline decoration-dotted underline-offset-2 text-content-secondary hover:text-content-primary',\n },\n});\n\nexport interface TimeRangePickerProps extends HTMLAttributes<HTMLDivElement> {\n /** Accessible name for the preset group. Default `Time range`. */\n label?: string;\n}\n\n/**\n * The preset strip — 15m, 1h, 6h, 24h, 7d — and the window it resolves to, in\n * UTC. When a chart zooms the window it shows `Zoomed` and a reset back to the\n * last preset. Reads and writes the nearest `TimeRangeProvider`, and renders\n * nothing without one.\n */\nexport const TimeRangePicker = forwardRef<HTMLDivElement, TimeRangePickerProps>(function TimeRangePicker(\n { label = 'Time range', className, ...props },\n ref,\n) {\n const state = useTimeRange();\n const [lastPreset, setLastPreset] = useState<string | null>(state?.presetId ?? null);\n if (state?.presetId && state.presetId !== lastPreset) setLastPreset(state.presetId);\n const styles = timeRangePicker();\n if (!state) return null;\n const custom = state.presetId === null;\n return (\n <div ref={ref} data-slot=\"time-range-picker\" {...props} className={styles.root({ className })}>\n <div role=\"group\" aria-label={label} className={styles.presets()}>\n {state.presets.map((preset) => (\n <button key={preset.id} type=\"button\" aria-pressed={state.presetId === preset.id} onClick={() => state.selectPreset(preset.id)} className={styles.preset()}>\n {preset.label}\n </button>\n ))}\n </div>\n {custom ? <span className={styles.custom()}>Zoomed · {formatRangeDuration(state.range.to - state.range.from)}</span> : null}\n <span className={styles.range()}>{formatRange(state.range)} UTC</span>\n {custom && lastPreset ? (\n <button type=\"button\" onClick={() => state.selectPreset(lastPreset)} className={styles.reset()}>\n Reset to {state.presets.find((preset) => preset.id === lastPreset)?.label}\n </button>\n ) : null}\n </div>\n );\n});\n\nTimeRangePicker.displayName = 'TimeRangePicker';\n"],"mappings":";;;AAEA,SAAS,eAAe,YAAY,aAAa,YAAY,SAAS,gBAAqD;AAC3H,SAAS,cAAc;AACvB;AAAA,EACE;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;AAmGD,cA8CU,YA9CV;AA7EN,IAAM,eAAe,cAAqC,IAAI;AAC9D,IAAM,gBAAgB,cAAsC,IAAI;AAMzD,SAAS,eAAsC;AACpD,SAAO,WAAW,YAAY;AAChC;AAOO,SAAS,gBAAwC;AACtD,SAAO,WAAW,aAAa;AACjC;AAwBO,SAAS,kBAAkB,EAAE,KAAK,kBAAkB,MAAM,OAAO,WAAW,eAAe,UAAU,oBAAoB,SAAS,GAA2B;AAClK,QAAM,UAAU,QAAQ,KAAK,CAAC,WAAW,OAAO,OAAO,eAAe,KAAK,QAAQ,CAAC;AACpF,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAwD,OAAO;AAAA,IACvF,OAAO,UAAU,YAAY,SAAS,GAAG,IAAI,EAAE,MAAM,MAAM,MAAW,IAAI,IAAI;AAAA,IAC9E,UAAU,SAAS,MAAM;AAAA,EAC3B,EAAE;AACF,QAAM,CAAC,QAAQ,SAAS,IAAI,SAAwB,IAAI;AAExD,QAAM,WAAW,YAAY,CAAC,MAAiB,WAA0B,SAAS;AAChF,UAAM,QAAQ,eAAe,IAAI;AACjC,QAAI,CAAC,MAAO;AACZ,aAAS,EAAE,OAAO,OAAO,SAAS,CAAC;AACnC,oBAAgB,OAAO,QAAQ;AAAA,EACjC,GAAG,CAAC,aAAa,CAAC;AAClB,QAAM,eAAe,YAAY,CAAC,OAAe;AAC/C,UAAM,SAAS,QAAQ,KAAK,CAAC,cAAc,UAAU,OAAO,EAAE;AAC9D,QAAI,OAAQ,UAAS,YAAY,QAAQ,GAAG,GAAG,OAA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