@frondruntime/devtools 0.3.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.
package/dist/index.js ADDED
@@ -0,0 +1,705 @@
1
+ import {
2
+ Attach,
3
+ AttachmentInfo,
4
+ EncodedEventRecord,
5
+ EncodedGraphEdge,
6
+ EncodedNodeSnapshot,
7
+ FrondHubRpcs,
8
+ GraphQuery,
9
+ GraphSnapshot,
10
+ HUB_ATTACH_PATH,
11
+ HUB_DEFAULT_ATTACH_URL,
12
+ HUB_DEFAULT_HOST,
13
+ HUB_DEFAULT_PORT,
14
+ HUB_PROTOCOL_VERSION,
15
+ HubAttached,
16
+ HubCommand,
17
+ HubPing,
18
+ HubQuery,
19
+ HubRejection,
20
+ Ingest,
21
+ NodeQuery,
22
+ QueryOutcome,
23
+ Reply,
24
+ RuntimeEventCategory,
25
+ RuntimeEventSeverity,
26
+ RuntimeEventTimeline,
27
+ RuntimeWorkPriority,
28
+ RuntimeWorkReason,
29
+ RuntimeWorkSource,
30
+ StateQuery,
31
+ ValuePolicy
32
+ } from "./chunk-8xwbnbvs.js";
33
+
34
+ // src/attach.ts
35
+ import { Clock, Effect, Layer, Stream } from "effect";
36
+ import { RpcClient, RpcSerialization } from "effect/unstable/rpc";
37
+ import { Socket } from "effect/unstable/socket";
38
+
39
+ // src/cause.ts
40
+ import { Diagnostics } from "@frondruntime/core";
41
+ var CAUSE_MAX_DEPTH = 8;
42
+ var SHAPE_CAUSE_STRING_LENGTH = 256;
43
+ var FULL_CAUSE_STRING_LENGTH = 1024;
44
+ var CAUSE_STACK_SOURCE_LENGTH = 32768;
45
+ var KEPT_STACK_FRAMES = 15;
46
+ var LIBRARY_ONLY_STACK_FRAMES = 2;
47
+ var FULL_CAUSE_STACK_LENGTH = 2048;
48
+ var V8_STACK_FRAME = /^\s*at\s\S/;
49
+ var AT_STACK_FRAME = /^\S*@\S*:\d+:\d+\s*$/;
50
+ var LIBRARY_STACK_FRAME = /node_modules|node:|bun:|native:|\(native\)|\[native code]/;
51
+ function describeError(value, policy, full) {
52
+ const disclose = policy === "full";
53
+ const frames = Diagnostics.serializeCauseChain(value, {
54
+ maxDepth: CAUSE_MAX_DEPTH,
55
+ maxStringLength: disclose ? FULL_CAUSE_STRING_LENGTH : SHAPE_CAUSE_STRING_LENGTH,
56
+ maxStackLength: CAUSE_STACK_SOURCE_LENGTH,
57
+ maxObjectKeys: disclose ? 20 : 8
58
+ });
59
+ if (full === undefined) {
60
+ const shed = policy === "none" ? { path: undefined, valueKind: undefined } : {};
61
+ return {
62
+ _: "error",
63
+ message: rootMessage(frames),
64
+ causes: frames.map((frame) => compact({ ...frame, ...shed, stack: undefined, preview: undefined }))
65
+ };
66
+ }
67
+ const links = causeValues(value, frames.length);
68
+ const marked = links.filter((link) => typeof link === "object" && link !== null && !full.seen.has(link));
69
+ for (const link of marked) {
70
+ full.seen.add(link);
71
+ }
72
+ try {
73
+ return {
74
+ _: "error",
75
+ message: rootMessage(frames),
76
+ causes: frames.map((frame, index) => compact({
77
+ ...frame,
78
+ preview: undefined,
79
+ stack: frame.stack === undefined ? undefined : abridgeStack(frame.stack),
80
+ fields: errorFields(links[index], full.encodeValue)
81
+ }))
82
+ };
83
+ } finally {
84
+ for (const link of marked) {
85
+ full.seen.delete(link);
86
+ }
87
+ }
88
+ }
89
+ function abridgeStack(stack) {
90
+ const lines = stack.split(`
91
+ `);
92
+ const first = lines.findIndex(isStackFrame);
93
+ if (first === -1) {
94
+ return stack.length <= FULL_CAUSE_STACK_LENGTH ? stack : `${stack.slice(0, FULL_CAUSE_STACK_LENGTH)}…`;
95
+ }
96
+ const header = lines.slice(0, first);
97
+ const body = lines.slice(first).filter((line) => line.trim() !== "");
98
+ const frames = body.filter(isStackFrame);
99
+ const own = frames.filter((line) => !LIBRARY_STACK_FRAME.test(line));
100
+ const kept = (own.length === 0 ? frames.slice(0, LIBRARY_ONLY_STACK_FRAMES) : own).slice(0, KEPT_STACK_FRAMES);
101
+ const dropped = body.length - kept.length;
102
+ if (dropped === 0) {
103
+ return [...header, ...kept].join(`
104
+ `);
105
+ }
106
+ return [
107
+ ...header,
108
+ ...kept,
109
+ ` … ${dropped} frame${dropped === 1 ? "" : "s"} dropped: library internals, unrecognized lines, and any past the first ${KEPT_STACK_FRAMES}`
110
+ ].join(`
111
+ `);
112
+ }
113
+ function isStackFrame(line) {
114
+ return V8_STACK_FRAME.test(line) || AT_STACK_FRAME.test(line);
115
+ }
116
+ function causeValues(root, count) {
117
+ const values = [];
118
+ let current = root;
119
+ for (let index = 0;index < count; index += 1) {
120
+ values.push(current);
121
+ if (typeof current !== "object" || current === null) {
122
+ break;
123
+ }
124
+ try {
125
+ current = current["cause"];
126
+ } catch {
127
+ break;
128
+ }
129
+ }
130
+ return values;
131
+ }
132
+ var NAMED_ERROR_KEYS = new Set([
133
+ "boundary",
134
+ "cancellation",
135
+ "cause",
136
+ "dependency",
137
+ "invariant",
138
+ "kind",
139
+ "message",
140
+ "name",
141
+ "nodeId",
142
+ "operation",
143
+ "path",
144
+ "stack",
145
+ "tag",
146
+ "timeout",
147
+ "_tag"
148
+ ]);
149
+ function errorFields(value, encodeValue) {
150
+ if (typeof value !== "object" || value === null) {
151
+ return encodeValue(value);
152
+ }
153
+ const own = {};
154
+ try {
155
+ for (const key of Object.keys(value)) {
156
+ if (!NAMED_ERROR_KEYS.has(key)) {
157
+ own[key] = value[key];
158
+ }
159
+ }
160
+ } catch {
161
+ return;
162
+ }
163
+ return Object.keys(own).length === 0 ? undefined : encodeValue(own);
164
+ }
165
+ function rootMessage(frames) {
166
+ for (let index = frames.length - 1;index >= 0; index -= 1) {
167
+ const frame = frames[index];
168
+ const message = frame?.message;
169
+ if (message !== undefined && message !== "" && message !== frame?.valueKind) {
170
+ return message;
171
+ }
172
+ }
173
+ return frames[0]?.tag ?? frames[0]?.name ?? "";
174
+ }
175
+ function compact(frame) {
176
+ const out = {};
177
+ for (const [key, value] of Object.entries(frame)) {
178
+ if (value !== undefined) {
179
+ out[key] = value;
180
+ }
181
+ }
182
+ return out;
183
+ }
184
+
185
+ // src/descriptors.ts
186
+ var WITHHELD = "withheld";
187
+ var UNREADABLE = { _: "opaque", type: "unreadable" };
188
+
189
+ // src/full.ts
190
+ var FULL_MAX_DEPTH = 24;
191
+ var FULL_MAX_STRING_LENGTH = 65536;
192
+ var FULL_MAX_ENTRIES = 4096;
193
+ var FULL_MAX_NODES = 50000;
194
+ function describeFull(value, depth, seen, budget) {
195
+ if (budget.remaining <= 0) {
196
+ return { _: "elided", by: "budget" };
197
+ }
198
+ budget.remaining -= 1;
199
+ if (value === null || value === undefined) {
200
+ return value ?? null;
201
+ }
202
+ switch (typeof value) {
203
+ case "boolean":
204
+ case "number": {
205
+ return value;
206
+ }
207
+ case "bigint": {
208
+ return { _: "opaque", type: `bigint:${value.toString()}` };
209
+ }
210
+ case "function": {
211
+ return {
212
+ _: "opaque",
213
+ type: `function:${value.name || "anonymous"}`
214
+ };
215
+ }
216
+ case "symbol": {
217
+ return { _: "opaque", type: value.toString() };
218
+ }
219
+ case "string": {
220
+ return value.length <= FULL_MAX_STRING_LENGTH ? value : {
221
+ _: "string",
222
+ length: value.length,
223
+ head: value.slice(0, FULL_MAX_STRING_LENGTH)
224
+ };
225
+ }
226
+ default: {
227
+ return describeFullStructure(value, depth, seen, budget);
228
+ }
229
+ }
230
+ }
231
+ function describeFullStructure(value, depth, seen, budget) {
232
+ try {
233
+ return describeFullStructureUnguarded(value, depth, seen, budget);
234
+ } catch {
235
+ return UNREADABLE;
236
+ }
237
+ }
238
+ function describeFullStructureUnguarded(value, depth, seen, budget) {
239
+ if (seen.has(value)) {
240
+ return { _: "cycle" };
241
+ }
242
+ if (value instanceof Error) {
243
+ const described = describeError(value, "full", {
244
+ seen,
245
+ encodeValue: (own) => describeFull(own, depth + 1, seen, budget)
246
+ });
247
+ budget.remaining -= described.causes.length;
248
+ return described;
249
+ }
250
+ if (value instanceof Date) {
251
+ return value.toISOString();
252
+ }
253
+ if (depth >= FULL_MAX_DEPTH) {
254
+ return { _: "elided", by: "depth" };
255
+ }
256
+ seen.add(value);
257
+ try {
258
+ if (Array.isArray(value)) {
259
+ const kept = value.slice(0, FULL_MAX_ENTRIES);
260
+ const encoded = kept.map((entry) => describeFull(entry, depth + 1, seen, budget));
261
+ if (value.length > FULL_MAX_ENTRIES) {
262
+ encoded.push({
263
+ _: "elided",
264
+ by: "entries",
265
+ length: value.length
266
+ });
267
+ }
268
+ return encoded;
269
+ }
270
+ if (value instanceof Map) {
271
+ return {
272
+ _: "map",
273
+ entries: [...value.entries()].slice(0, FULL_MAX_ENTRIES).map(([key, entry]) => [
274
+ describeFull(key, depth + 1, seen, budget),
275
+ describeFull(entry, depth + 1, seen, budget)
276
+ ]),
277
+ size: value.size
278
+ };
279
+ }
280
+ if (value instanceof Set) {
281
+ return {
282
+ _: "set",
283
+ values: [...value.values()].slice(0, FULL_MAX_ENTRIES).map((entry) => describeFull(entry, depth + 1, seen, budget)),
284
+ size: value.size
285
+ };
286
+ }
287
+ const out = {};
288
+ const allKeys = Object.keys(value);
289
+ const keys = allKeys.slice(0, FULL_MAX_ENTRIES);
290
+ for (const key of keys) {
291
+ out[key] = describeFull(value[key], depth + 1, seen, budget);
292
+ }
293
+ if (allKeys.length > keys.length) {
294
+ out["_elided"] = {
295
+ _: "elided",
296
+ by: "entries",
297
+ length: allKeys.length
298
+ };
299
+ }
300
+ const prototype = Object.getPrototypeOf(value);
301
+ if (prototype !== null && prototype !== Object.prototype) {
302
+ out["_type"] = value.constructor?.name ?? "object";
303
+ }
304
+ return out;
305
+ } finally {
306
+ seen.delete(value);
307
+ }
308
+ }
309
+
310
+ // src/shape.ts
311
+ var MAX_STRING_LENGTH = 256;
312
+ var MAX_KEYS = 32;
313
+ var MAX_DEPTH = 3;
314
+ function describeShape(value, depth) {
315
+ if (value === null || value === undefined) {
316
+ return value ?? null;
317
+ }
318
+ switch (typeof value) {
319
+ case "boolean":
320
+ case "number": {
321
+ return value;
322
+ }
323
+ case "bigint":
324
+ case "function":
325
+ case "symbol": {
326
+ return typeof value;
327
+ }
328
+ case "string": {
329
+ return value.length <= MAX_STRING_LENGTH ? value : {
330
+ _: "string",
331
+ length: value.length,
332
+ head: value.slice(0, MAX_STRING_LENGTH)
333
+ };
334
+ }
335
+ default: {
336
+ return describeStructure(value, depth);
337
+ }
338
+ }
339
+ }
340
+ function describeStructure(value, depth) {
341
+ try {
342
+ return describeStructureUnguarded(value, depth);
343
+ } catch {
344
+ return UNREADABLE;
345
+ }
346
+ }
347
+ function describeStructureUnguarded(value, depth) {
348
+ if (value instanceof Error) {
349
+ return describeError(value, "shape");
350
+ }
351
+ if (depth >= MAX_DEPTH) {
352
+ return Array.isArray(value) ? "[…]" : "{…}";
353
+ }
354
+ if (Array.isArray(value)) {
355
+ const first = value[0];
356
+ return `${first === undefined ? "unknown" : shapeName(first, depth + 1)}[${value.length}]`;
357
+ }
358
+ if (value instanceof Map) {
359
+ return `Map(${value.size})`;
360
+ }
361
+ if (value instanceof Set) {
362
+ return `Set(${value.size})`;
363
+ }
364
+ const prototype = Object.getPrototypeOf(value);
365
+ if (prototype !== null && prototype !== Object.prototype) {
366
+ return `${value.constructor?.name ?? "object"}{?}`;
367
+ }
368
+ const keys = Object.keys(value);
369
+ const shown = keys.length > MAX_KEYS ? [...keys.slice(0, MAX_KEYS), "…"] : keys;
370
+ const tag = value._tag;
371
+ return `${typeof tag === "string" ? tag : ""}{${shown.join(",")}}`;
372
+ }
373
+ function shapeName(value, depth) {
374
+ if (value === null) {
375
+ return "null";
376
+ }
377
+ if (typeof value !== "object") {
378
+ return typeof value;
379
+ }
380
+ const described = describeStructure(value, depth);
381
+ return typeof described === "string" ? described : "error";
382
+ }
383
+
384
+ // src/encode.ts
385
+ function createValueEncoder(policy) {
386
+ if (policy === "none") {
387
+ return {
388
+ value: () => WITHHELD,
389
+ failure: (value) => describeError(value, policy)
390
+ };
391
+ }
392
+ if (policy === "shape") {
393
+ return {
394
+ value: (value) => describeShape(value, 0),
395
+ failure: (value) => describeError(value, policy)
396
+ };
397
+ }
398
+ const budget = { remaining: FULL_MAX_NODES };
399
+ return {
400
+ value: (value) => describeFull(value, 0, new Set, budget),
401
+ failure: (value) => {
402
+ const seen = new Set;
403
+ return describeError(value, policy, {
404
+ seen,
405
+ encodeValue: (own) => describeFull(own, 1, seen, budget)
406
+ });
407
+ }
408
+ };
409
+ }
410
+ function encodeRecord(record, policy) {
411
+ const encoder = createValueEncoder(policy);
412
+ const known = new Set(record.failures.filter((failure) => typeof failure === "object" && failure !== null));
413
+ const encodeField = (value) => typeof value === "object" && value !== null && known.has(value) ? encoder.failure(value) : encoder.value(value);
414
+ return {
415
+ sequence: record.sequence,
416
+ recordedAt: record.recordedAt,
417
+ tag: record.event._tag,
418
+ category: record.classification.category,
419
+ severity: record.classification.severity,
420
+ timeline: record.classification.timeline,
421
+ reportable: record.classification.reportable,
422
+ workId: record.work.workId,
423
+ parentWorkId: record.work.parentWorkId,
424
+ source: record.work.source,
425
+ reason: record.work.reason,
426
+ priority: record.work.priority,
427
+ nodeIds: record.nodeIds,
428
+ fields: policy === "none" ? {} : describeFields(record.event, encodeField),
429
+ failures: record.failures.map(encoder.failure)
430
+ };
431
+ }
432
+ function describeFields(event, encodeValue) {
433
+ const fields = {};
434
+ for (const [key, value] of Object.entries(event)) {
435
+ if (key === "_tag") {
436
+ continue;
437
+ }
438
+ fields[key] = encodeValue(value);
439
+ }
440
+ return fields;
441
+ }
442
+
443
+ // src/policy.ts
444
+ var POLICY_RANK = { none: 0, shape: 1, full: 2 };
445
+ function resolvePolicy(requested, ceiling) {
446
+ return POLICY_RANK[requested] <= POLICY_RANK[ceiling] ? requested : ceiling;
447
+ }
448
+
449
+ // src/snapshot.ts
450
+ function encodeGraphSnapshot(snapshot, request) {
451
+ const encoder = createValueEncoder(request.policy);
452
+ const nodes = request.nodeId === undefined ? snapshot.graph.nodes : snapshot.graph.nodes.filter((node) => node.nodeId === request.nodeId);
453
+ const edges = request.nodeId === undefined ? snapshot.graph.edges : snapshot.graph.edges.filter((edge) => edge.from === request.nodeId || edge.to === request.nodeId);
454
+ return {
455
+ capturedAt: request.capturedAt,
456
+ ...absent("sequence", snapshot.events.at(-1)?.sequence, identity),
457
+ runtimeId: snapshot.runtimeId,
458
+ runtimeStatus: snapshot.status,
459
+ graphStatus: snapshot.graph.status,
460
+ observedInputs: snapshot.graph.observedInputs,
461
+ values: request.policy,
462
+ nodes: nodes.map((node) => encodeNode(node, encoder, request.nodeId !== undefined)),
463
+ edges: edges.map(encodeEdge)
464
+ };
465
+ }
466
+ function encodeEdge(edge) {
467
+ return { from: edge.from, to: edge.to, dependency: edge.dependency };
468
+ }
469
+ function encodeNode(node, encoder, includeResult) {
470
+ try {
471
+ return encodeNodeUnguarded(node, encoder, includeResult);
472
+ } catch {
473
+ return {
474
+ nodeId: node.nodeId,
475
+ tag: node.tag,
476
+ kind: node.kind,
477
+ state: node._tag,
478
+ revision: node.revision,
479
+ status: { _: "opaque", type: "unreadable" },
480
+ liveDemand: { _: "opaque", type: "unreadable" },
481
+ operation: { _: "opaque", type: "unreadable" }
482
+ };
483
+ }
484
+ }
485
+ function encodeNodeUnguarded(node, encoder, includeResult) {
486
+ const failure = nodeFailure(node);
487
+ return {
488
+ nodeId: node.nodeId,
489
+ tag: node.tag,
490
+ kind: node.kind,
491
+ state: node._tag,
492
+ revision: node.revision,
493
+ status: encoder.value(node.status),
494
+ liveDemand: encoder.value(node.liveDemand),
495
+ operation: encoder.value(node.operation),
496
+ ...absent("resultValidity", node.resultValidity, encoder.value),
497
+ ...absent("failure", failure, encoder.failure),
498
+ ...absent("operationFailure", encodeOperationFailure(node.operationFailure, encoder), identity),
499
+ ...absent("liveFailure", encodeLiveFailure(node.liveFailure, encoder), identity),
500
+ ...absent("result", includeResult && node._tag === "Ready" ? { value: node.result } : undefined, (held) => encoder.value(held.value))
501
+ };
502
+ }
503
+ var identity = (value) => value;
504
+ function absent(key, value, encode) {
505
+ return value === undefined ? {} : { [key]: encode(value) };
506
+ }
507
+ function nodeFailure(node) {
508
+ if (node._tag === "ReadinessError" || node._tag === "Invalid") {
509
+ return node.error;
510
+ }
511
+ return node.failure;
512
+ }
513
+ function encodeOperationFailure(failure, encoder) {
514
+ return failure === undefined ? undefined : {
515
+ operationId: failure.operationId,
516
+ kind: failure.kind,
517
+ at: failure.at,
518
+ error: encoder.failure(failure.error)
519
+ };
520
+ }
521
+ function encodeLiveFailure(failure, encoder) {
522
+ return failure === undefined ? undefined : { at: failure.at, failures: failure.failures.map(encoder.failure) };
523
+ }
524
+
525
+ // src/attach.ts
526
+ var MAX_BUFFERED_RECORDS = 4096;
527
+ var FLUSH_INTERVAL = "250 millis";
528
+ function attachLayer(attachUrl) {
529
+ return RpcClient.layerProtocolSocket().pipe(Layer.provide(Socket.layerWebSocket(attachUrl)), Layer.provide(Socket.layerWebSocketConstructorGlobal), Layer.provide(RpcSerialization.layerNdjson));
530
+ }
531
+ var attachRuntime = Effect.fnUntraced(function* (options) {
532
+ const client = yield* RpcClient.make(FrondHubRpcs);
533
+ const ceiling = options.values ?? "shape";
534
+ let buffer = [];
535
+ let dropped = 0;
536
+ let policy = resolvePolicy("shape", ceiling);
537
+ let attachmentId;
538
+ const subscription = options.runtime.observe((record) => {
539
+ if (options.include !== undefined && !options.include(record)) {
540
+ return;
541
+ }
542
+ if (buffer.length >= MAX_BUFFERED_RECORDS) {
543
+ dropped += 1;
544
+ return;
545
+ }
546
+ buffer.push(encodeRecord(record, policy));
547
+ });
548
+ yield* Effect.addFinalizer(() => Effect.sync(() => subscription.unsubscribe()));
549
+ const info = {
550
+ protocolVersion: HUB_PROTOCOL_VERSION,
551
+ instanceId: options.instanceId ?? crypto.randomUUID(),
552
+ runtimeId: options.runtime.getSnapshotSync().runtimeId,
553
+ generation: options.generation ?? 0,
554
+ name: options.name,
555
+ platform: options.platform,
556
+ startedAt: yield* Clock.currentTimeMillis,
557
+ values: ceiling
558
+ };
559
+ const flushOnce = Effect.gen(function* () {
560
+ yield* Effect.sleep(FLUSH_INTERVAL);
561
+ const id = attachmentId;
562
+ if (id === undefined || buffer.length === 0 && dropped === 0) {
563
+ return;
564
+ }
565
+ const records = buffer;
566
+ const droppedSince = dropped;
567
+ buffer = [];
568
+ dropped = 0;
569
+ yield* client["Frond.Ingest"]({ attachmentId: id, records, droppedSince });
570
+ });
571
+ yield* Effect.forkScoped(Effect.forever(flushOnce));
572
+ const answer = (command) => Effect.gen(function* () {
573
+ const id = attachmentId;
574
+ if (id === undefined) {
575
+ return;
576
+ }
577
+ const capturedAt = yield* Clock.currentTimeMillis;
578
+ const outcome = yield* Effect.map(Effect.exit(Effect.sync(() => {
579
+ const requested = resolvePolicy(command.values, ceiling);
580
+ return encodeGraphSnapshot(options.runtime.getSnapshotSync(), {
581
+ policy: requested,
582
+ capturedAt,
583
+ nodeId: command.query._tag === "Node" ? command.query.nodeId : undefined
584
+ });
585
+ })), (exit) => exit._tag === "Success" ? { _tag: "Snapshot", snapshot: exit.value } : { _tag: "Failed", reason: failureReason(exit.cause) });
586
+ yield* Effect.ignore(client["Frond.Reply"]({ attachmentId: id, requestId: command.requestId, outcome }));
587
+ });
588
+ yield* Stream.runForEach(client["Frond.Attach"]({ info }), (command) => {
589
+ if (command._tag === "Attached") {
590
+ return Effect.sync(() => {
591
+ attachmentId = command.attachmentId;
592
+ policy = resolvePolicy(command.values, ceiling);
593
+ options.onAttached?.();
594
+ });
595
+ }
596
+ if (command._tag === "Query") {
597
+ return Effect.forkScoped(answer(command));
598
+ }
599
+ return Effect.void;
600
+ });
601
+ });
602
+ function failureReason(cause) {
603
+ if (cause instanceof Error) {
604
+ return cause.message === "" ? cause.name : cause.message;
605
+ }
606
+ return String(cause);
607
+ }
608
+ // src/attachDevtools.ts
609
+ import { Cause, Data, Effect as Effect2, Fiber } from "effect";
610
+ var RETRY_DELAY = "2 seconds";
611
+
612
+ class AttachRefused extends Data.TaggedError("AttachRefused") {
613
+ }
614
+ function refusal(cause) {
615
+ for (const reason of cause.reasons) {
616
+ if (Cause.isFailReason(reason) && reason.error instanceof HubRejection) {
617
+ return reason.error;
618
+ }
619
+ }
620
+ return;
621
+ }
622
+ function attachDevtools(options) {
623
+ const url = options.url ?? HUB_DEFAULT_ATTACH_URL;
624
+ const instanceId = options.instanceId ?? crypto.randomUUID();
625
+ let generation = 0;
626
+ const session = Effect2.suspend(() => attachRuntime({
627
+ runtime: options.runtime,
628
+ attachUrl: url,
629
+ name: options.name,
630
+ platform: options.platform ?? detectPlatform(),
631
+ instanceId,
632
+ generation,
633
+ onAttached: () => {
634
+ generation += 1;
635
+ },
636
+ ...options.values === undefined ? {} : { values: options.values },
637
+ ...options.include === undefined ? {} : { include: options.include }
638
+ })).pipe(Effect2.scoped, Effect2.provide(attachLayer(url)), Effect2.catchCause((cause) => {
639
+ options.onError?.(cause);
640
+ const refused = refusal(cause);
641
+ return refused === undefined ? Effect2.void : new AttachRefused({ reason: refused.reason });
642
+ }));
643
+ const fiber = Effect2.runFork(Effect2.forever(Effect2.andThen(session, Effect2.sleep(RETRY_DELAY))).pipe(Effect2.catchTag("AttachRefused", (refused) => Effect2.sync(() => {
644
+ if (options.onError === undefined) {
645
+ console.error(`[frond] devtools attach refused: ${refused.reason}`);
646
+ }
647
+ }))));
648
+ return () => {
649
+ Effect2.runFork(Fiber.interrupt(fiber));
650
+ };
651
+ }
652
+ function detectPlatform() {
653
+ const globals = globalThis;
654
+ if (globals.document !== undefined) {
655
+ return "web";
656
+ }
657
+ if (globals.navigator?.product === "ReactNative") {
658
+ return "react-native";
659
+ }
660
+ if (globals.process !== undefined) {
661
+ return globals.process.versions?.bun === undefined ? "node" : "bun";
662
+ }
663
+ return "unknown";
664
+ }
665
+ export {
666
+ resolvePolicy,
667
+ encodeRecord,
668
+ encodeGraphSnapshot,
669
+ createValueEncoder,
670
+ attachRuntime,
671
+ attachLayer,
672
+ attachDevtools,
673
+ ValuePolicy,
674
+ StateQuery,
675
+ RuntimeWorkSource,
676
+ RuntimeWorkReason,
677
+ RuntimeWorkPriority,
678
+ RuntimeEventTimeline,
679
+ RuntimeEventSeverity,
680
+ RuntimeEventCategory,
681
+ Reply,
682
+ QueryOutcome,
683
+ NodeQuery,
684
+ Ingest,
685
+ HubRejection,
686
+ HubQuery,
687
+ HubPing,
688
+ HubCommand,
689
+ HubAttached,
690
+ HUB_PROTOCOL_VERSION,
691
+ HUB_DEFAULT_PORT,
692
+ HUB_DEFAULT_HOST,
693
+ HUB_DEFAULT_ATTACH_URL,
694
+ HUB_ATTACH_PATH,
695
+ GraphSnapshot,
696
+ GraphQuery,
697
+ FrondHubRpcs,
698
+ EncodedNodeSnapshot,
699
+ EncodedGraphEdge,
700
+ EncodedEventRecord,
701
+ AttachmentInfo,
702
+ Attach
703
+ };
704
+
705
+ //# debugId=EFBC398C8CBD8EDB64756E2164756E21