@buoy-gg/events 7.0.28 → 7.0.30

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.
@@ -1,391 +0,0 @@
1
- import {
2
- approxJsonSize,
3
- isJsonSerializable,
4
- isOverWireBudget,
5
- } from "@buoy-gg/shared-ui";
6
- import { unifiedEventStore } from "../stores/unifiedEventStore";
7
- import type { EventSource } from "../types";
8
- import { generateExport } from "../utils/eventExportFormatter";
9
- import {
10
- DEFAULT_COPY_SETTINGS,
11
- COPY_PRESETS,
12
- type EventsCopySettings,
13
- type CopyPresetName,
14
- } from "../types/copySettings";
15
-
16
- interface ExportEventsParams {
17
- /** A named preset (llm, errors, minimal, …) as the base; defaults to the compact default. */
18
- preset?: CopyPresetName;
19
- /** Field/format overrides merged over the preset/default (the Copy Settings toggles). */
20
- settings?: Partial<EventsCopySettings>;
21
- /** Cap to the most-recent N events (before formatting). */
22
- limit?: number;
23
- }
24
-
25
- // ==========================================================================
26
- // Snapshot compaction — keep the device→broker socket healthy.
27
- //
28
- // Each UnifiedEvent carries `originalEvent` (full network bodies, query
29
- // payloads, redux prev/next state trees) for the on-device detail view. The
30
- // sync snapshot re-sends ALL events on every change (throttled to 200ms), and
31
- // measured sessions hit 4–6MB per push — a socket firehose that starves the
32
- // broker and the device's JS thread. Cap the per-event payload for the WIRE
33
- // only; the on-device modal reads the store directly and keeps full detail.
34
- // ==========================================================================
35
-
36
- /** Max serialized bytes of one event's originalEvent on the wire. */
37
- const MAX_SYNC_ORIGINAL_EVENT_BYTES = 16 * 1024;
38
-
39
- interface TruncatedOriginalEvent {
40
- __buoyTruncated: true;
41
- approxBytes: number;
42
- note: string;
43
- }
44
-
45
- function truncatedMarker(approxBytes: number, note?: string): TruncatedOriginalEvent {
46
- return {
47
- __buoyTruncated: true,
48
- approxBytes,
49
- note:
50
- note ??
51
- `Payload (≥${(approxBytes / 1024).toFixed(0)}KB approx) exceeds the ${MAX_SYNC_ORIGINAL_EVENT_BYTES / 1024}KB sync limit and stayed on the device. Open the tool on-device (or use the source tool's detail action) for the full payload.`,
52
- };
53
- }
54
-
55
- /** Marker replacing per-event redux state trees at the sync boundary. */
56
- const STATE_TREE_OMITTED = {
57
- __buoyOmitted: "state-tree",
58
- note: "prevState/nextState stay on the device (use get_redux_state / the on-device tool).",
59
- } as const;
60
-
61
- /** Marker replacing oversized / unserializable react-query payloads. */
62
- const QUERY_PAYLOAD_OMITTED = {
63
- __buoyOmitted: "query-payload",
64
- note: "Query/mutation data stays on the device (open the Query tool or the on-device Events detail).",
65
- } as const;
66
-
67
- const NETWORK_BODY_OMITTED = {
68
- __buoyOmitted: "network-body",
69
- note: "Request/response body stays on the device (open the Network tool or the on-device Events detail).",
70
- } as const;
71
-
72
- const NETWORK_HEADERS_OMITTED = {
73
- __buoyOmitted: "network-headers",
74
- note: "Request/response headers stay on the device (open the Network tool or the on-device Events detail).",
75
- } as const;
76
-
77
- const GRAPHQL_VARS_OMITTED = {
78
- __buoyOmitted: "graphql-variables",
79
- note: "GraphQL variables stay on the device (open the Network tool or the on-device Events detail).",
80
- } as const;
81
-
82
- const STORAGE_VALUE_OMITTED = {
83
- __buoyOmitted: "storage-value",
84
- note: "Storage value stays on the device (open the Storage tool or the on-device Events detail).",
85
- } as const;
86
-
87
- const ROUTE_PARAMS_OMITTED = {
88
- __buoyOmitted: "route-params",
89
- note: "Navigation params stay on the device (open the Routes tool or the on-device Events detail).",
90
- } as const;
91
-
92
- function isReactQuerySource(source?: string): boolean {
93
- return (
94
- source === "react-query" ||
95
- source === "react-query-query" ||
96
- source === "react-query-mutation"
97
- );
98
- }
99
-
100
- /**
101
- * Markers are CLONED per field rather than shared. Not for correctness any
102
- * more — sharing a reference is now handled properly below — but because a
103
- * repeated reference makes the size walk report `sawRepeat`, which costs a
104
- * full serializability check on an event we already know is fine.
105
- */
106
- function omitIfHeavy(
107
- value: unknown,
108
- marker: { __buoyOmitted: string; note: string },
109
- ): unknown {
110
- if (value === undefined) return undefined;
111
- return isOverWireBudget(value, MAX_SYNC_ORIGINAL_EVENT_BYTES)
112
- ? { ...marker }
113
- : value;
114
- }
115
-
116
- function wireQueryPayload(value: unknown): unknown {
117
- return omitIfHeavy(value, QUERY_PAYLOAD_OMITTED);
118
- }
119
-
120
- function wireError(value: unknown): unknown {
121
- if (value == null) return value;
122
- if (value instanceof Error) {
123
- return { name: value.name, message: value.message };
124
- }
125
- return wireQueryPayload(value);
126
- }
127
-
128
- // Events are immutable once created, so compaction is computed once per event
129
- // object and drops out of the cache when the store evicts the event.
130
- const compactionCache = new WeakMap<object, unknown>();
131
-
132
- function compactEventForSync<T extends { source?: string; originalEvent: unknown }>(
133
- event: T
134
- ): T {
135
- const original = event.originalEvent;
136
- if (typeof original !== "object" || original === null) return event;
137
-
138
- const cached = compactionCache.get(event as object);
139
- if (cached !== undefined) return cached as T;
140
-
141
- let result: T = event;
142
-
143
- // Redux events carry the whole ReduxAction, whose prevState/nextState are
144
- // FULL state trees — per event. Never ship (or even size-walk) those:
145
- // drop them unconditionally before estimating, so the rest of the action
146
- // (type/payload/meta/diff) still makes it onto the wire when it fits.
147
- let candidate = original as Record<string, unknown>;
148
- if (
149
- (event.source === "redux" || event.source === "zustand") &&
150
- ("prevState" in candidate || "nextState" in candidate)
151
- ) {
152
- // Clone the sentinel per field. `approxSizeOver` flags a repeated object
153
- // reference as cyclic, and a shared marker would truncate the whole
154
- // originalEvent — dropping type/payload, which is the part we kept.
155
- candidate = {
156
- ...candidate,
157
- prevState: { ...STATE_TREE_OMITTED },
158
- nextState: { ...STATE_TREE_OMITTED },
159
- ...(event.source === "zustand" && "partial" in candidate
160
- ? { partial: { ...STATE_TREE_OMITTED } }
161
- : {}),
162
- };
163
- result = { ...event, originalEvent: candidate };
164
- } else if (
165
- event.source === "jotai" &&
166
- ("prevValue" in candidate || "nextValue" in candidate)
167
- ) {
168
- candidate = {
169
- ...candidate,
170
- prevValue: { ...STATE_TREE_OMITTED },
171
- nextValue: { ...STATE_TREE_OMITTED },
172
- };
173
- result = { ...event, originalEvent: candidate };
174
- } else if (event.source === "render") {
175
- // Highlight-updates events embed the full TrackedRender (including
176
- // renderHistory) plus the RenderEvent (captured props/state, hookChanges).
177
- // Drop those trees so the timeline keeps title/cause type.
178
- const render = candidate.render as Record<string, unknown> | undefined;
179
- const nested = candidate.event as Record<string, unknown> | undefined;
180
- const omitCause = (cause: unknown) => {
181
- if (!cause || typeof cause !== "object") return cause;
182
- const { hookChanges: _hookChanges, ...rest } = cause as Record<
183
- string,
184
- unknown
185
- >;
186
- return rest;
187
- };
188
- candidate = {
189
- ...candidate,
190
- render: render
191
- ? {
192
- ...render,
193
- renderHistory: undefined,
194
- lastRenderCause: omitCause(render.lastRenderCause),
195
- }
196
- : render,
197
- event: nested
198
- ? {
199
- ...nested,
200
- capturedProps: undefined,
201
- capturedState: undefined,
202
- cause: omitCause(nested.cause),
203
- }
204
- : nested,
205
- };
206
- result = { ...event, originalEvent: candidate };
207
- } else if (isReactQuerySource(event.source)) {
208
- // React Query events embed the live Query/Mutation objects (cyclic —
209
- // observers point back at the query) plus full cache `queryData`.
210
- // Walking those either flags cyclic and truncates the WHOLE originalEvent
211
- // (losing type/queryKey/duration) or blows the 16KB cap. Drop the live
212
- // objects unconditionally; keep light fields; replace heavy data.
213
- const { query: _query, mutation: _mutation, ...rest } = candidate;
214
- candidate = {
215
- ...rest,
216
- queryData: wireQueryPayload(rest.queryData),
217
- mutationData: wireQueryPayload(rest.mutationData),
218
- mutationVariables: wireQueryPayload(rest.mutationVariables),
219
- queryError: wireError(rest.queryError),
220
- mutationError: wireError(rest.mutationError),
221
- };
222
- result = { ...event, originalEvent: candidate };
223
- } else if (event.source === "network") {
224
- // Network events carry request/response bodies. A 20KB body blows the
225
- // 16KB cap and truncates the WHOLE originalEvent — method/url/status
226
- // never reach the dashboard. Strip heavy bodies first (same 16KB
227
- // threshold as the network adapter).
228
- const requestSize =
229
- typeof candidate.requestSize === "number"
230
- ? candidate.requestSize
231
- : undefined;
232
- const responseSize =
233
- typeof candidate.responseSize === "number"
234
- ? candidate.responseSize
235
- : undefined;
236
- candidate = {
237
- ...candidate,
238
- requestData:
239
- requestSize !== undefined && requestSize > MAX_SYNC_ORIGINAL_EVENT_BYTES
240
- ? { ...NETWORK_BODY_OMITTED }
241
- : omitIfHeavy(candidate.requestData, NETWORK_BODY_OMITTED),
242
- responseData:
243
- responseSize !== undefined &&
244
- responseSize > MAX_SYNC_ORIGINAL_EVENT_BYTES
245
- ? { ...NETWORK_BODY_OMITTED }
246
- : omitIfHeavy(candidate.responseData, NETWORK_BODY_OMITTED),
247
- graphqlVariables: omitIfHeavy(
248
- candidate.graphqlVariables,
249
- GRAPHQL_VARS_OMITTED,
250
- ),
251
- requestHeaders: omitIfHeavy(
252
- candidate.requestHeaders,
253
- NETWORK_HEADERS_OMITTED,
254
- ),
255
- responseHeaders: omitIfHeavy(
256
- candidate.responseHeaders,
257
- NETWORK_HEADERS_OMITTED,
258
- ),
259
- };
260
- result = { ...event, originalEvent: candidate };
261
- } else if (
262
- event.source === "storage-async" ||
263
- event.source === "storage-mmkv"
264
- ) {
265
- const data = candidate.data as Record<string, unknown> | undefined;
266
- if (data) {
267
- candidate = {
268
- ...candidate,
269
- data: {
270
- ...data,
271
- value: omitIfHeavy(data.value, STORAGE_VALUE_OMITTED),
272
- prevValue: omitIfHeavy(data.prevValue, STORAGE_VALUE_OMITTED),
273
- pairs: omitIfHeavy(data.pairs, STORAGE_VALUE_OMITTED),
274
- },
275
- };
276
- result = { ...event, originalEvent: candidate };
277
- }
278
- } else if (event.source === "route") {
279
- // Route events embed navigate() params. A fat object (or a 20KB
280
- // stringified payload) blows the 16KB cap and truncates the WHOLE
281
- // originalEvent — pathname never reaches the dashboard.
282
- candidate = {
283
- ...candidate,
284
- params: omitIfHeavy(candidate.params, ROUTE_PARAMS_OMITTED),
285
- };
286
- result = { ...event, originalEvent: candidate };
287
- }
288
-
289
- const { bytes, sawRepeat, sawBigInt } = approxJsonSize(
290
- candidate,
291
- MAX_SYNC_ORIGINAL_EVENT_BYTES
292
- );
293
- if (bytes > MAX_SYNC_ORIGINAL_EVENT_BYTES) {
294
- result = { ...event, originalEvent: truncatedMarker(bytes) };
295
- } else if ((sawRepeat || sawBigInt) && !isJsonSerializable(candidate)) {
296
- // Only a CONFIRMED failure truncates. The walk dedupes by identity to stay
297
- // O(limit), so it cannot distinguish a cycle from ordinary structural
298
- // sharing — and `{ user, currentUser }` pointing at one object is both
299
- // commonplace and perfectly serializable. Treating that as cyclic threw
300
- // away the whole event, type and title included, for a payload that was
301
- // always safe to send.
302
- result = {
303
- ...event,
304
- originalEvent: truncatedMarker(-1, "Payload is not JSON-serializable (cyclic or bigint) and stayed on the device."),
305
- };
306
- }
307
-
308
- compactionCache.set(event as object, result);
309
- return result;
310
- }
311
-
312
- /**
313
- * Sync adapter for the events tool, consumed by @buoy-gg/external-sync's
314
- * `useExternalSync` (structurally matches its ToolSyncAdapter interface so
315
- * this package doesn't need a dependency on it).
316
- *
317
- * This adapter is the "remote consumer" of the unified event store. While a
318
- * dashboard is watching, it requests a SET of event sources (defaulting to all,
319
- * narrowed by the dashboard via `setEnabledSources`). On unwatch it releases
320
- * those requests, so — unlike before — the device stops capturing sources that
321
- * nothing else is watching. Source requests are ref-counted in the store, so
322
- * the on-device EventsModal keeps working when open at the same time.
323
- *
324
- * The snapshot carries the device's available sources so the dashboard can
325
- * render the source filter chips (its own auto-discovery finds nothing — the
326
- * tool packages live on the device).
327
- */
328
- export const eventsSyncAdapter = {
329
- version: 2,
330
- getSnapshot: () => ({
331
- events: unifiedEventStore.getEvents().map(compactEventForSync),
332
- availableSources: Array.from(unifiedEventStore.getAvailableEventSources()),
333
- }),
334
- subscribe: (onChange: () => void) => {
335
- // Default to all sources until the dashboard narrows the set via
336
- // setEnabledSources — backward compatible with dashboards that don't send
337
- // it. Uses ensureRemoteSourcesDefault so a setEnabledSources that raced
338
- // ahead of this watch isn't clobbered back to "all".
339
- unifiedEventStore.ensureRemoteSourcesDefault();
340
- const unsubscribe = unifiedEventStore.subscribe(() => onChange());
341
- return () => {
342
- unsubscribe();
343
- // Release this consumer's source subscriptions so the device stops
344
- // capturing sources nothing else is watching (fixes the old leak).
345
- unifiedEventStore.clearRemoteSources();
346
- };
347
- },
348
- actions: {
349
- clearEvents: () => {
350
- unifiedEventStore.clearEvents();
351
- },
352
- /**
353
- * Narrow which sources the device captures for this dashboard, driven by
354
- * the dashboard's source badges. Ref-counted in the store, so disabling a
355
- * source here only stops its capture if no other consumer wants it.
356
- */
357
- setEnabledSources: (params?: unknown) => {
358
- const sources =
359
- (params as { sources?: EventSource[] } | undefined)?.sources ?? [];
360
- unifiedEventStore.setRemoteEnabledSources(sources);
361
- return { enabledSources: sources };
362
- },
363
- /**
364
- * Format the captured events using the SAME "Copy Settings" formatter the
365
- * on-device copy button uses — driven by toggles instead of taps. Heavy raw
366
- * payloads (`originalEvent`) stay on the device unless the caller opts in
367
- * (`includeEventData`), so a remote driver (MCP/LLM) gets a compact result
368
- * by default and only pulls more detail when it asks. Returns the formatted
369
- * string + metadata so the caller knows how much was returned.
370
- */
371
- exportEvents: (params?: unknown) => {
372
- const p = (params as ExportEventsParams | undefined) ?? {};
373
- const base =
374
- p.preset && COPY_PRESETS[p.preset]
375
- ? COPY_PRESETS[p.preset]
376
- : DEFAULT_COPY_SETTINGS;
377
- const settings = { ...base, ...(p.settings ?? {}) } as EventsCopySettings;
378
- const all = unifiedEventStore.getEvents(); // newest-first, capped by the store
379
- const limit =
380
- typeof p.limit === "number" && p.limit > 0 ? p.limit : all.length;
381
- const events = all.slice(0, limit); // newest N (generateExport re-sorts ascending)
382
- return {
383
- output: generateExport(events, settings),
384
- returned: events.length,
385
- totalAvailable: all.length,
386
- includedData: settings.includeEventData,
387
- format: settings.format,
388
- };
389
- },
390
- },
391
- };
@@ -1,299 +0,0 @@
1
- /**
2
- * Events Copy Settings Types
3
- *
4
- * Configuration for exporting unified events in various formats.
5
- */
6
-
7
- import type { EventSource } from "./index";
8
-
9
- /**
10
- * Copy settings for event export
11
- */
12
- export interface EventsCopySettings {
13
- // Timestamps
14
- timestampFormat: "relative" | "absolute" | "both";
15
-
16
- // Event Info
17
- includeSource: boolean;
18
- includeStatus: boolean;
19
- includeTitle: boolean;
20
- includeSubtitle: boolean;
21
- includeCorrelation: boolean;
22
- includeDuration: boolean;
23
-
24
- // Summary
25
- includeSummaryHeader: boolean;
26
- includeTotalDuration: boolean;
27
-
28
- // Data
29
- includeEventData: boolean;
30
- dataSizeThreshold: 1 | 5 | 10 | 50 | -1; // KB, -1 = unlimited
31
-
32
- // Format
33
- format: "markdown" | "json" | "plaintext" | "mermaid";
34
-
35
- // Filters
36
- filterMode: "all" | "errors" | "success" | "pending";
37
- filterSources: EventSource[];
38
-
39
- // Advanced formatting (LLM-optimized)
40
- /** Compact mode - single line per event, no JSON blocks */
41
- compactMode: boolean;
42
- /** Parse and pretty-print JSON strings in values (prevents double-escaping) */
43
- smartJsonParsing: boolean;
44
- /** For Redux: only show slices that changed, not entire state */
45
- reduxChangedOnly: boolean;
46
- /** For Storage: show diff between prevValue and value */
47
- showStorageDiff: boolean;
48
- /** Strip verbose fields like image URLs and descriptions for cleaner output */
49
- stripVerboseFields: boolean;
50
- }
51
-
52
- /**
53
- * Default copy settings
54
- */
55
- export const DEFAULT_COPY_SETTINGS: EventsCopySettings = {
56
- timestampFormat: "relative",
57
- includeSource: true,
58
- includeStatus: true,
59
- includeTitle: true,
60
- includeSubtitle: true,
61
- includeCorrelation: true,
62
- includeDuration: true,
63
- includeSummaryHeader: true,
64
- includeTotalDuration: true,
65
- includeEventData: false,
66
- dataSizeThreshold: 5,
67
- format: "markdown",
68
- filterMode: "all",
69
- filterSources: [],
70
- // Advanced formatting defaults (optimized for LLM consumption)
71
- compactMode: false,
72
- smartJsonParsing: true,
73
- reduxChangedOnly: true,
74
- showStorageDiff: true,
75
- stripVerboseFields: true,
76
- };
77
-
78
- /**
79
- * Preset configurations
80
- */
81
- export const COPY_PRESETS = {
82
- /**
83
- * LLM Flow - Optimized for AI assistants
84
- * Readable markdown with relative timestamps and status icons
85
- */
86
- llm: {
87
- timestampFormat: "relative" as const,
88
- includeSource: true,
89
- includeStatus: true,
90
- includeTitle: true,
91
- includeSubtitle: true,
92
- includeCorrelation: true,
93
- includeDuration: true,
94
- includeSummaryHeader: true,
95
- includeTotalDuration: true,
96
- includeEventData: false,
97
- dataSizeThreshold: 5 as const,
98
- format: "markdown" as const,
99
- filterMode: "all" as const,
100
- filterSources: [],
101
- compactMode: false,
102
- smartJsonParsing: true,
103
- reduxChangedOnly: true,
104
- showStorageDiff: true,
105
- stripVerboseFields: true,
106
- },
107
-
108
- /**
109
- * Bug Report - Full context with errors emphasized
110
- */
111
- bugReport: {
112
- timestampFormat: "both" as const,
113
- includeSource: true,
114
- includeStatus: true,
115
- includeTitle: true,
116
- includeSubtitle: true,
117
- includeCorrelation: true,
118
- includeDuration: true,
119
- includeSummaryHeader: true,
120
- includeTotalDuration: true,
121
- includeEventData: true,
122
- dataSizeThreshold: 10 as const,
123
- format: "markdown" as const,
124
- filterMode: "all" as const,
125
- filterSources: [],
126
- compactMode: false,
127
- smartJsonParsing: true,
128
- reduxChangedOnly: true,
129
- showStorageDiff: true,
130
- stripVerboseFields: true,
131
- },
132
-
133
- /**
134
- * JSON Export - Full data for debugging/replay
135
- */
136
- json: {
137
- timestampFormat: "absolute" as const,
138
- includeSource: true,
139
- includeStatus: true,
140
- includeTitle: true,
141
- includeSubtitle: true,
142
- includeCorrelation: true,
143
- includeDuration: true,
144
- includeSummaryHeader: false,
145
- includeTotalDuration: false,
146
- includeEventData: true,
147
- dataSizeThreshold: -1 as const,
148
- format: "json" as const,
149
- filterMode: "all" as const,
150
- filterSources: [],
151
- compactMode: false,
152
- smartJsonParsing: true,
153
- reduxChangedOnly: false,
154
- showStorageDiff: false,
155
- stripVerboseFields: false,
156
- },
157
-
158
- /**
159
- * Errors Only - Just failed events for quick debugging
160
- */
161
- errors: {
162
- timestampFormat: "relative" as const,
163
- includeSource: true,
164
- includeStatus: true,
165
- includeTitle: true,
166
- includeSubtitle: true,
167
- includeCorrelation: true,
168
- includeDuration: true,
169
- includeSummaryHeader: true,
170
- includeTotalDuration: false,
171
- includeEventData: true,
172
- dataSizeThreshold: 10 as const,
173
- format: "markdown" as const,
174
- filterMode: "errors" as const,
175
- filterSources: [],
176
- compactMode: false,
177
- smartJsonParsing: true,
178
- reduxChangedOnly: true,
179
- showStorageDiff: true,
180
- stripVerboseFields: true,
181
- },
182
-
183
- /**
184
- * Minimal - Just titles and timestamps
185
- */
186
- minimal: {
187
- timestampFormat: "relative" as const,
188
- includeSource: false,
189
- includeStatus: true,
190
- includeTitle: true,
191
- includeSubtitle: false,
192
- includeCorrelation: false,
193
- includeDuration: false,
194
- includeSummaryHeader: false,
195
- includeTotalDuration: false,
196
- includeEventData: false,
197
- dataSizeThreshold: 1 as const,
198
- format: "plaintext" as const,
199
- filterMode: "all" as const,
200
- filterSources: [],
201
- compactMode: true,
202
- smartJsonParsing: true,
203
- reduxChangedOnly: true,
204
- showStorageDiff: false,
205
- stripVerboseFields: true,
206
- },
207
-
208
- /**
209
- * Mermaid Diagram - Visual sequence diagram for flow visualization
210
- */
211
- mermaid: {
212
- timestampFormat: "relative" as const,
213
- includeSource: true,
214
- includeStatus: true,
215
- includeTitle: true,
216
- includeSubtitle: false,
217
- includeCorrelation: true,
218
- includeDuration: true,
219
- includeSummaryHeader: false,
220
- includeTotalDuration: false,
221
- includeEventData: false,
222
- dataSizeThreshold: 1 as const,
223
- format: "mermaid" as const,
224
- filterMode: "all" as const,
225
- filterSources: [],
226
- compactMode: false,
227
- smartJsonParsing: true,
228
- reduxChangedOnly: true,
229
- showStorageDiff: true,
230
- stripVerboseFields: true,
231
- },
232
- } as const;
233
-
234
- export type CopyPresetName = keyof typeof COPY_PRESETS;
235
-
236
- /**
237
- * Detect which preset matches current settings
238
- */
239
- export function detectActivePreset(settings: EventsCopySettings): CopyPresetName | null {
240
- for (const [presetName, presetConfig] of Object.entries(COPY_PRESETS)) {
241
- const matches = Object.keys(presetConfig).every((key) => {
242
- const settingValue = settings[key as keyof EventsCopySettings];
243
- const presetValue = presetConfig[key as keyof typeof presetConfig];
244
-
245
- // Handle array comparison for filterSources
246
- if (Array.isArray(settingValue) && Array.isArray(presetValue)) {
247
- return (
248
- settingValue.length === presetValue.length &&
249
- settingValue.every((v, i) => v === presetValue[i])
250
- );
251
- }
252
-
253
- return settingValue === presetValue;
254
- });
255
-
256
- if (matches) return presetName as CopyPresetName;
257
- }
258
-
259
- return null;
260
- }
261
-
262
- /**
263
- * Preset metadata for UI display
264
- */
265
- export const PRESET_METADATA: Record<
266
- CopyPresetName,
267
- { label: string; description: string; color: string }
268
- > = {
269
- llm: {
270
- label: "LLM",
271
- description: "AI-ready format",
272
- color: "#10B981", // Green
273
- },
274
- bugReport: {
275
- label: "Bug Report",
276
- description: "Full context",
277
- color: "#EF4444", // Red
278
- },
279
- json: {
280
- label: "JSON",
281
- description: "Machine-readable",
282
- color: "#F59E0B", // Yellow
283
- },
284
- errors: {
285
- label: "Errors",
286
- description: "Failed only",
287
- color: "#EF4444", // Red
288
- },
289
- minimal: {
290
- label: "Minimal",
291
- description: "Quick reference",
292
- color: "#6B7280", // Gray
293
- },
294
- mermaid: {
295
- label: "Diagram",
296
- description: "Visual flow",
297
- color: "#A855F7", // Purple
298
- },
299
- };