@full-self-browsing/phantom-stream 0.1.0 → 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.
Files changed (64) hide show
  1. package/README.md +48 -2
  2. package/dist/types/adapters/extension.d.ts.map +1 -1
  3. package/dist/types/adapters/playwright.d.ts.map +1 -1
  4. package/dist/types/capture/index.d.ts +150 -0
  5. package/dist/types/capture/index.d.ts.map +1 -1
  6. package/dist/types/index.d.ts +2 -0
  7. package/dist/types/player/index.d.ts +136 -0
  8. package/dist/types/player/index.d.ts.map +1 -0
  9. package/dist/types/protocol/constants.d.ts +22 -0
  10. package/dist/types/protocol/constants.d.ts.map +1 -1
  11. package/dist/types/protocol/index.d.ts +1 -0
  12. package/dist/types/protocol/media-reconcile.d.ts +53 -0
  13. package/dist/types/protocol/media-reconcile.d.ts.map +1 -0
  14. package/dist/types/protocol/messages.d.ts +326 -4
  15. package/dist/types/protocol/messages.d.ts.map +1 -1
  16. package/dist/types/recorder/index.d.ts +207 -0
  17. package/dist/types/recorder/index.d.ts.map +1 -0
  18. package/dist/types/renderer/asset-policy.d.ts +72 -0
  19. package/dist/types/renderer/asset-policy.d.ts.map +1 -0
  20. package/dist/types/renderer/diff.d.ts.map +1 -1
  21. package/dist/types/renderer/index.d.ts +61 -8
  22. package/dist/types/renderer/index.d.ts.map +1 -1
  23. package/dist/types/renderer/media-player.d.ts +114 -0
  24. package/dist/types/renderer/media-player.d.ts.map +1 -0
  25. package/dist/types/renderer/overlays.d.ts +12 -0
  26. package/dist/types/renderer/overlays.d.ts.map +1 -1
  27. package/dist/types/renderer/parser-safe.d.ts +26 -0
  28. package/dist/types/renderer/parser-safe.d.ts.map +1 -0
  29. package/dist/types/renderer/sanitize.d.ts +22 -0
  30. package/dist/types/renderer/sanitize.d.ts.map +1 -1
  31. package/dist/types/renderer/snapshot.d.ts +38 -0
  32. package/dist/types/renderer/snapshot.d.ts.map +1 -1
  33. package/dist/types/transport/websocket.d.ts.map +1 -1
  34. package/docs/ARCHITECTURE.md +83 -4
  35. package/docs/QUICKSTARTS.md +64 -0
  36. package/docs/SECURITY.md +279 -2
  37. package/docs/paper/OUTLINE.md +24 -91
  38. package/examples/bookmarklet-demo/viewer.html +12 -3
  39. package/examples/extension-mv3/viewer.html +10 -3
  40. package/package.json +25 -1
  41. package/src/adapters/extension.js +202 -7
  42. package/src/adapters/playwright-inject.js +645 -28
  43. package/src/adapters/playwright.js +176 -2
  44. package/src/capture/README.md +96 -1
  45. package/src/capture/index.js +1672 -40
  46. package/src/index.js +2 -0
  47. package/src/player/README.md +175 -0
  48. package/src/player/index.js +627 -0
  49. package/src/protocol/constants.js +24 -0
  50. package/src/protocol/index.js +1 -0
  51. package/src/protocol/media-reconcile.js +188 -0
  52. package/src/protocol/messages.js +195 -4
  53. package/src/recorder/README.md +225 -0
  54. package/src/recorder/index.js +487 -0
  55. package/src/renderer/README.md +111 -8
  56. package/src/renderer/asset-policy.js +172 -0
  57. package/src/renderer/diff.js +158 -15
  58. package/src/renderer/index.js +978 -21
  59. package/src/renderer/media-player.js +367 -0
  60. package/src/renderer/overlays.js +324 -0
  61. package/src/renderer/parser-safe.js +111 -0
  62. package/src/renderer/sanitize.js +25 -3
  63. package/src/renderer/snapshot.js +534 -3
  64. package/src/transport/websocket.js +36 -0
@@ -36,7 +36,7 @@
36
36
  /**
37
37
  * @typedef {Object} AddDiffOp
38
38
  * @property {'add'} op
39
- * @property {string} parentNid Parent node id in the current mirror
39
+ * @property {string} parentNid Parent node id in the current mirror, or BODY_NID for a direct child of the main <body>
40
40
  * @property {string} html Serialized subtree HTML, without framework identity attrs
41
41
  * @property {string|null} beforeNid Insert before this sibling nid, or append when null
42
42
  * @property {string[]} nodeIds Preorder ids for every serialized element in html
@@ -59,6 +59,8 @@
59
59
  * @property {string} kind Frame policy kind, e.g. 'same-origin' or 'cross-origin'
60
60
  * @property {string} [html] Serialized frame body HTML for accessible frames
61
61
  * @property {string[]} [nodeIds] Preorder ids for serialized frame elements
62
+ * @property {string} [htmlNid] Counter nid of the frame document <html> (empty string when unavailable)
63
+ * @property {string} [bodyNid] Counter nid of the frame document <body> (empty string when unavailable)
62
64
  * @property {string[]} [stylesheets] Absolutified stylesheet URLs
63
65
  * @property {string[]} [inlineStyles] Sanitized inline style blocks
64
66
  * @property {StyleSource[]} [styleSources] Scoped CSSOM sources for this frame document
@@ -77,7 +79,81 @@
77
79
  * @property {string} nid
78
80
  * @property {string} [value] Textual value for input/textarea/select-like controls
79
81
  * @property {boolean} [checked] Checked state for checkbox/radio controls
80
- * @property {string[]} [selectedValues] Selected option values for multi-select controls
82
+ * @property {string[]} [selectedValues] Selected option values for select controls (masked when maskInputs is on, so renderers must not treat these as a selection key)
83
+ * @property {number[]} [selectedIndexes] Authoritative positional identity of selected options; preferred over selectedValues because option indexes never carry page content and stay unambiguous under masking
84
+ */
85
+ /**
86
+ * Captured live playback state of a single <video>/<audio> element, keyed by
87
+ * nid. Models the DIFF_OP.VALUE side-channel-property-state precedent: live
88
+ * media properties travel as side-channel data, never serialized into the HTML
89
+ * clone (preserves the Phase 7 no-mutation invariant + HTML byte-identity).
90
+ *
91
+ * Live/Infinity-duration encoding: `duration` is present ONLY when finite;
92
+ * non-finite (streaming) durations are encoded as `live: true` instead, never
93
+ * both. This sidesteps the JSON Infinity -> null trap (JSON.stringify(Infinity)
94
+ * === "null") so the reconciler can branch on `live` before any duration math
95
+ * and never compute NaN.
96
+ *
97
+ * @typedef {Object} MediaBaselineEntry
98
+ * @property {string} nid Element nid the playback state addresses
99
+ * @property {number} currentTime Playback position in seconds
100
+ * @property {boolean} paused Whether the element is paused
101
+ * @property {boolean} muted Whether audio output is muted
102
+ * @property {number} volume Audio volume in [0, 1]
103
+ * @property {number} playbackRate Effective playback rate (1 = normal)
104
+ * @property {boolean} loop Whether the element loops
105
+ * @property {boolean} ended Whether playback reached the end
106
+ * @property {number} [duration] Media duration in seconds; present ONLY when finite
107
+ * @property {boolean} [live] true when duration is non-finite (stream); mutually exclusive with duration
108
+ */
109
+ /**
110
+ * One STREAM.MEDIA wire message: a MediaBaselineEntry enriched with the event
111
+ * that triggered emission, a capture-side monotonic timestamp for latency
112
+ * compensation, and the stream identity stamps every side channel carries.
113
+ *
114
+ * The reconciler predicts the expected position from `currentTime`,
115
+ * `playbackRate`, and `(now - sentAt)`; `streamSessionId`/`snapshotId` let the
116
+ * renderer reject stale cross-generation frames via isCurrentStream (Plan 03).
117
+ * One message is emitted per media element per tick (scroll-like granularity).
118
+ *
119
+ * @typedef {Object} MediaSyncPayload
120
+ * @property {string} nid Element nid the playback state addresses
121
+ * @property {'play'|'pause'|'seeked'|'ratechange'|'ended'|'volumechange'|'loadedmetadata'|'timeupdate'} event Triggering media event
122
+ * @property {number} currentTime Playback position in seconds at capture
123
+ * @property {boolean} paused Whether the element is paused
124
+ * @property {boolean} muted Whether audio output is muted
125
+ * @property {number} volume Audio volume in [0, 1]
126
+ * @property {number} playbackRate Effective playback rate (1 = normal)
127
+ * @property {boolean} loop Whether the element loops
128
+ * @property {boolean} ended Whether playback reached the end
129
+ * @property {number} [duration] Media duration in seconds; present ONLY when finite
130
+ * @property {boolean} [live] true when duration is non-finite (stream); mutually exclusive with duration
131
+ * @property {number} sentAt Capture-side monotonic ms stamp for latency compensation
132
+ * @property {string} streamSessionId Identity: minted per stream session
133
+ * @property {number} snapshotId Identity: minted per snapshot
134
+ */
135
+ /**
136
+ * One adaptive-manifest discovery hint surfaced by an adapter's opt-in network
137
+ * observation (Playwright `page.on('response')` / extension `chrome.webRequest`).
138
+ * The hint originates in the ADAPTER, never the capture core, so it adds no
139
+ * capture-wire divergence (no differential-oracle entry); it rides the existing
140
+ * raw relay + 1 MiB cap with the envelope byte-unchanged, and old viewers ignore
141
+ * the unknown STREAM.MEDIA_HINT type via the renderer dispatch default.
142
+ *
143
+ * Addressing is nid-scoped when manifest->element correlation is confident, else
144
+ * page-scoped (nid omitted, scope 'page'); a page hint is matched to an
145
+ * MSE-opaque media element on play by the viewer. Identity-stamped like every
146
+ * side channel; the viewer re-gates `manifestUrl` through the same fail-closed
147
+ * origin policy before any use.
148
+ *
149
+ * @typedef {Object} MediaHintPayload
150
+ * @property {string} [nid] Element nid when correlation is confident; omitted for page-level
151
+ * @property {'page'|'element'} scope 'element' (nid set) or 'page' (viewer matches on play)
152
+ * @property {string} manifestUrl Absolute manifest URL (https; viewer re-gates before use)
153
+ * @property {'hls'|'dash'} kind Derived from URL extension and/or content-type
154
+ * @property {string} [contentType] Observed response content-type (diagnostic)
155
+ * @property {string} streamSessionId Identity: minted per stream session
156
+ * @property {number} snapshotId Identity: minted per snapshot
81
157
  */
82
158
  /**
83
159
  * @typedef {Object} SubtreeRequestPayload
@@ -105,6 +181,7 @@
105
181
  * @typedef {Object} SnapshotPayload
106
182
  * @property {string} html Serialized body innerHTML (style-inlined; framework identity-clean)
107
183
  * @property {string[]} nodeIds Preorder ids for every serialized element in html
184
+ * @property {string} [bodyNid] Reserved main <body> identity, always BODY_NID (absent on captures older than this fix)
108
185
  * @property {ShadowRootPayload[]} [shadowRoots] Open shadow roots keyed by host nid
109
186
  * @property {FramePayload[]} [frames] Frame sidecars keyed by iframe nid
110
187
  * @property {boolean} truncated True if the size budget forced subtree drops
@@ -159,6 +236,24 @@ export function isCurrentStream(msg: {
159
236
  streamSessionId?: string;
160
237
  snapshotId?: number;
161
238
  }): boolean;
239
+ /**
240
+ * Pure manifest classifier: is an observed response an adaptive-streaming
241
+ * manifest, and of which kind? Returns `'hls'` for an `.m3u8` path OR an HLS
242
+ * content-type; `'dash'` for an `.mpd` path OR `application/dash+xml`; `null`
243
+ * otherwise. URL-OR-content-type: either signal is independently sufficient.
244
+ *
245
+ * Never throws (T-14-03): a malformed/hostile url string is a guarded `null`
246
+ * (or a regex-fallback classification when the extension is still discernible),
247
+ * so it can never wedge the adapter. Project convention: a pure helper returns
248
+ * a primitive, not the `{ok,...}` fallible shape.
249
+ *
250
+ * @param {{url?: string, contentType?: string}} [input]
251
+ * @returns {'hls'|'dash'|null}
252
+ */
253
+ export function classifyManifest(input?: {
254
+ url?: string;
255
+ contentType?: string;
256
+ }): "hls" | "dash" | null;
162
257
  export namespace CONTROL {
163
258
  let START: string;
164
259
  let STOP: string;
@@ -170,6 +265,8 @@ export namespace STREAM {
170
265
  let SNAPSHOT: string;
171
266
  let MUTATIONS: string;
172
267
  let SCROLL: string;
268
+ let MEDIA: string;
269
+ let MEDIA_HINT: string;
173
270
  let OVERLAY: string;
174
271
  let DIALOG: string;
175
272
  let READY: string;
@@ -208,6 +305,49 @@ export namespace DIFF_OP {
208
305
  * nodeIds sidecars instead of mutating observed page elements.
209
306
  */
210
307
  export const NID_ATTR: "data-fsb-nid";
308
+ /**
309
+ * Reserved identity for the MAIN document `<body>` (quick task 261127-u5c).
310
+ *
311
+ * The snapshot sidecar starts below `<body>`, so the body itself never gets a
312
+ * counter nid. This value is non-numeric, so it can never collide with the
313
+ * capture counter (which only ever yields `String(n)` for n >= 1), and it
314
+ * consumes no counter value, so nodeIds sidecars keep their exact numbering.
315
+ *
316
+ * - Carried on every main snapshot as SnapshotPayload.bodyNid.
317
+ * - The add-op parentNid for a direct child of the main `<body>` (toasts,
318
+ * modals, portals); beforeNid resolution is unchanged.
319
+ * - The attr-op nid for a `<body>` attribute change other than `style` (the
320
+ * snapshot shell bodyStyle owns the mirror body's style attribute).
321
+ * - Not returned by capture getNodeId, and not a subtree-request target: the
322
+ * body is a structural anchor for body-level diffs, not an addressable
323
+ * element.
324
+ *
325
+ * Same-origin frame documents keep their counter htmlNid/bodyNid
326
+ * (FramePayload); only the main document body uses this value.
327
+ */
328
+ export const BODY_NID: "body";
329
+ /**
330
+ * Parser-safe placeholder element and attribute (quick task 261202-jwf).
331
+ *
332
+ * A DOM built by scripts can hold nesting that HTML text cannot express: a
333
+ * `<button>` inside a `<button>`, an `<a>` inside an `<a>`, a `<div>` inside a
334
+ * `<p>`, a `<tr>` without a `<tbody>`, an `<img>` with children. Re-parsing the
335
+ * serialized HTML rewrites such a tree, which moves content and breaks the
336
+ * positional nodeIds pairing.
337
+ *
338
+ * - Capture renames each such element in its detached wire clone to
339
+ * `<ps-node>` (PARSER_SAFE_TAG), copying every attribute and setting
340
+ * PARSER_SAFE_TAG_ATTR to the lowercase original tag. Element order and
341
+ * count are unchanged, so nodeIds sidecars stay aligned. Capture strips
342
+ * PARSER_SAFE_TAG_ATTR from page-owned `<ps-node>` elements.
343
+ * - Viewers restore only an allowlist of tags (never script, iframe, object,
344
+ * embed, style, link, meta, base, html, head, body or frameset), right
345
+ * after each parse and before the post-parse scrub and identity pairing.
346
+ * - Viewers older than 0.3.0 render the placeholders as generic elements:
347
+ * structure and nid pairing stay intact, only the original tags are lost.
348
+ */
349
+ export const PARSER_SAFE_TAG: "ps-node";
350
+ export const PARSER_SAFE_TAG_ATTR: "data-ps-tag";
211
351
  export type StyleScope = {
212
352
  kind: "document" | "shadow" | "frame";
213
353
  /**
@@ -250,7 +390,7 @@ export type StyleSourceDiffOp = {
250
390
  export type AddDiffOp = {
251
391
  op: "add";
252
392
  /**
253
- * Parent node id in the current mirror
393
+ * Parent node id in the current mirror, or BODY_NID for a direct child of the main <body>
254
394
  */
255
395
  parentNid: string;
256
396
  /**
@@ -321,6 +461,14 @@ export type FramePayload = {
321
461
  * Preorder ids for serialized frame elements
322
462
  */
323
463
  nodeIds?: string[];
464
+ /**
465
+ * Counter nid of the frame document <html> (empty string when unavailable)
466
+ */
467
+ htmlNid?: string;
468
+ /**
469
+ * Counter nid of the frame document <body> (empty string when unavailable)
470
+ */
471
+ bodyNid?: string;
324
472
  /**
325
473
  * Absolutified stylesheet URLs
326
474
  */
@@ -378,9 +526,179 @@ export type ValueDiffOp = {
378
526
  */
379
527
  checked?: boolean;
380
528
  /**
381
- * Selected option values for multi-select controls
529
+ * Selected option values for select controls (masked when maskInputs is on, so renderers must not treat these as a selection key)
382
530
  */
383
531
  selectedValues?: string[];
532
+ /**
533
+ * Authoritative positional identity of selected options; preferred over selectedValues because option indexes never carry page content and stay unambiguous under masking
534
+ */
535
+ selectedIndexes?: number[];
536
+ };
537
+ /**
538
+ * Captured live playback state of a single <video>/<audio> element, keyed by
539
+ * nid. Models the DIFF_OP.VALUE side-channel-property-state precedent: live
540
+ * media properties travel as side-channel data, never serialized into the HTML
541
+ * clone (preserves the Phase 7 no-mutation invariant + HTML byte-identity).
542
+ *
543
+ * Live/Infinity-duration encoding: `duration` is present ONLY when finite;
544
+ * non-finite (streaming) durations are encoded as `live: true` instead, never
545
+ * both. This sidesteps the JSON Infinity -> null trap (JSON.stringify(Infinity)
546
+ * === "null") so the reconciler can branch on `live` before any duration math
547
+ * and never compute NaN.
548
+ */
549
+ export type MediaBaselineEntry = {
550
+ /**
551
+ * Element nid the playback state addresses
552
+ */
553
+ nid: string;
554
+ /**
555
+ * Playback position in seconds
556
+ */
557
+ currentTime: number;
558
+ /**
559
+ * Whether the element is paused
560
+ */
561
+ paused: boolean;
562
+ /**
563
+ * Whether audio output is muted
564
+ */
565
+ muted: boolean;
566
+ /**
567
+ * Audio volume in [0, 1]
568
+ */
569
+ volume: number;
570
+ /**
571
+ * Effective playback rate (1 = normal)
572
+ */
573
+ playbackRate: number;
574
+ /**
575
+ * Whether the element loops
576
+ */
577
+ loop: boolean;
578
+ /**
579
+ * Whether playback reached the end
580
+ */
581
+ ended: boolean;
582
+ /**
583
+ * Media duration in seconds; present ONLY when finite
584
+ */
585
+ duration?: number;
586
+ /**
587
+ * true when duration is non-finite (stream); mutually exclusive with duration
588
+ */
589
+ live?: boolean;
590
+ };
591
+ /**
592
+ * One STREAM.MEDIA wire message: a MediaBaselineEntry enriched with the event
593
+ * that triggered emission, a capture-side monotonic timestamp for latency
594
+ * compensation, and the stream identity stamps every side channel carries.
595
+ *
596
+ * The reconciler predicts the expected position from `currentTime`,
597
+ * `playbackRate`, and `(now - sentAt)`; `streamSessionId`/`snapshotId` let the
598
+ * renderer reject stale cross-generation frames via isCurrentStream (Plan 03).
599
+ * One message is emitted per media element per tick (scroll-like granularity).
600
+ */
601
+ export type MediaSyncPayload = {
602
+ /**
603
+ * Element nid the playback state addresses
604
+ */
605
+ nid: string;
606
+ /**
607
+ * Triggering media event
608
+ */
609
+ event: "play" | "pause" | "seeked" | "ratechange" | "ended" | "volumechange" | "loadedmetadata" | "timeupdate";
610
+ /**
611
+ * Playback position in seconds at capture
612
+ */
613
+ currentTime: number;
614
+ /**
615
+ * Whether the element is paused
616
+ */
617
+ paused: boolean;
618
+ /**
619
+ * Whether audio output is muted
620
+ */
621
+ muted: boolean;
622
+ /**
623
+ * Audio volume in [0, 1]
624
+ */
625
+ volume: number;
626
+ /**
627
+ * Effective playback rate (1 = normal)
628
+ */
629
+ playbackRate: number;
630
+ /**
631
+ * Whether the element loops
632
+ */
633
+ loop: boolean;
634
+ /**
635
+ * Whether playback reached the end
636
+ */
637
+ ended: boolean;
638
+ /**
639
+ * Media duration in seconds; present ONLY when finite
640
+ */
641
+ duration?: number;
642
+ /**
643
+ * true when duration is non-finite (stream); mutually exclusive with duration
644
+ */
645
+ live?: boolean;
646
+ /**
647
+ * Capture-side monotonic ms stamp for latency compensation
648
+ */
649
+ sentAt: number;
650
+ /**
651
+ * Identity: minted per stream session
652
+ */
653
+ streamSessionId: string;
654
+ /**
655
+ * Identity: minted per snapshot
656
+ */
657
+ snapshotId: number;
658
+ };
659
+ /**
660
+ * One adaptive-manifest discovery hint surfaced by an adapter's opt-in network
661
+ * observation (Playwright `page.on('response')` / extension `chrome.webRequest`).
662
+ * The hint originates in the ADAPTER, never the capture core, so it adds no
663
+ * capture-wire divergence (no differential-oracle entry); it rides the existing
664
+ * raw relay + 1 MiB cap with the envelope byte-unchanged, and old viewers ignore
665
+ * the unknown STREAM.MEDIA_HINT type via the renderer dispatch default.
666
+ *
667
+ * Addressing is nid-scoped when manifest->element correlation is confident, else
668
+ * page-scoped (nid omitted, scope 'page'); a page hint is matched to an
669
+ * MSE-opaque media element on play by the viewer. Identity-stamped like every
670
+ * side channel; the viewer re-gates `manifestUrl` through the same fail-closed
671
+ * origin policy before any use.
672
+ */
673
+ export type MediaHintPayload = {
674
+ /**
675
+ * Element nid when correlation is confident; omitted for page-level
676
+ */
677
+ nid?: string;
678
+ /**
679
+ * 'element' (nid set) or 'page' (viewer matches on play)
680
+ */
681
+ scope: "page" | "element";
682
+ /**
683
+ * Absolute manifest URL (https; viewer re-gates before use)
684
+ */
685
+ manifestUrl: string;
686
+ /**
687
+ * Derived from URL extension and/or content-type
688
+ */
689
+ kind: "hls" | "dash";
690
+ /**
691
+ * Observed response content-type (diagnostic)
692
+ */
693
+ contentType?: string;
694
+ /**
695
+ * Identity: minted per stream session
696
+ */
697
+ streamSessionId: string;
698
+ /**
699
+ * Identity: minted per snapshot
700
+ */
701
+ snapshotId: number;
384
702
  };
385
703
  export type SubtreeRequestPayload = {
386
704
  requestId: string;
@@ -432,6 +750,10 @@ export type SnapshotPayload = {
432
750
  * Preorder ids for every serialized element in html
433
751
  */
434
752
  nodeIds: string[];
753
+ /**
754
+ * Reserved main <body> identity, always BODY_NID (absent on captures older than this fix)
755
+ */
756
+ bodyNid?: string;
435
757
  /**
436
758
  * Open shadow roots keyed by host nid
437
759
  */
@@ -1 +1 @@
1
- {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/protocol/messages.js"],"names":[],"mappings":"AAuFA;;;;;GAKG;AAEH;;;;;;;;;;;;GAYG;AAEH;;;;;;;GAOG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;GAOG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,6CAHW,MAAM,QACN,MAAM,UAIhB;AAED;;;;;;;;GAQG;AACH,qCAJW;IAAC,eAAe,CAAC,EAAE,MAAM,CAAC;IAAC,UAAU,CAA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AM,EAAE;;;eAKR,MAAM;SACN,MAAM;qBACN,MAAM;gBACN,MAAM;aACN,MAAM;;;eAKN,MAAM;SACN,MAAM;;;;YACN,MAAM;;;;WACN,MAAM;;;;cACN,MAAM,EAAE;;;;kBACR,iBAAiB,EAAE;;;;aACnB,YAAY,EAAE;;;;mBACd,WAAW,EAAE;;;;oBACb,aAAa;qBACb,MAAM;gBACN,MAAM;;;;;;UAKN,MAAM;;;;aACN,MAAM,EAAE;;;;kBACR,iBAAiB,EAAE;;;;aACnB,YAAY,EAAE;;;;eACd,OAAO;;;;wBACP,MAAM;;;;iBACN,MAAM,EAAE;;;;kBACR,MAAM,EAAE;;;;mBACR,WAAW,EAAE;;;;oBACb,aAAa;;;;;;;;;;;;eAGb,MAAM;;;;eACN,MAAM;aACN,MAAM;aACN,MAAM;mBACN,MAAM;oBACN,MAAM;eACN,MAAM;gBACN,MAAM;SACN,MAAM;WACN,MAAM;;;;qBACN,MAAM;;;;gBACN,MAAM;;;UAKN,OAAO,GAAC,SAAS,GAAC,QAAQ;WAC1B,MAAM,GAAC,QAAQ;cACf,MAAM;;;;mBACN,MAAM;;;;aACN,GAAC"}
1
+ {"version":3,"file":"messages.d.ts","sourceRoot":"","sources":["../../../src/protocol/messages.js"],"names":[],"mappings":"AAwIA;;;;;GAKG;AAEH;;;;;;;;;;;;GAYG;AAEH;;;;;;;GAOG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;GASG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AAEH;;;;;;;;GAQG;AAEH;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AAEH;;;;;;;GAOG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AAEH;;;;;;;GAOG;AAEH;;;;;GAKG;AACH,6CAHW,MAAM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AAM,EAAE;;;;kBACR,iBAAiB,EAAE;;;;aACnB,YAAY,EAAE;;;;mBACd,WAAW,EAAE;;;;oBACb,aAAa;qBACb,MAAM;gBACN,MAAM;;;;;;UAKN,MAAM;;;;aACN,MAAM,EAAE;;;;cACR,MAAM;;;;kBACN,iBAAiB,EAAE;;;;aACnB,YAAY,EAAE;;;;eACd,OAAO;;;;wBACP,MAAM;;;;iBACN,MAAM,EAAE;;;;kBACR,MAAM,EAAE;;;;mBACR,WAAW,EAAE;;;;oBACb,aAAa;;;;;;;;;;;;eAGb,MAAM;;;;eACN,MAAM;aACN,MAAM;aACN,MAAM;mBACN,MAAM;oBACN,MAAM;eACN,MAAM;gBACN,MAAM;SACN,MAAM;WACN,MAAM;;;;qBACN,MAAM;;;;gBACN,MAAM;;;UAKN,OAAO,GAAC,SAAS,GAAC,QAAQ;WAC1B,MAAM,GAAC,QAAQ;cACf,MAAM;;;;mBACN,MAAM;;;;aACN,GAAC"}
@@ -0,0 +1,207 @@
1
+ /**
2
+ * Build a recording object from events (and optional bounds and meta).
3
+ * Never validates: pair it with validateRecording when the input is not
4
+ * the recorder's own output.
5
+ *
6
+ * Bounds default to the first and last event times (0 and 0 with no
7
+ * events); explicit finite startedAt/endedAt are kept as given.
8
+ *
9
+ * @param {{events?: RecordingEvent[], meta?: Object, startedAt?: number, endedAt?: number}} [options]
10
+ * @returns {Recording}
11
+ */
12
+ export function createRecording(options?: {
13
+ events?: RecordingEvent[];
14
+ meta?: any;
15
+ startedAt?: number;
16
+ endedAt?: number;
17
+ }): Recording;
18
+ /**
19
+ * Structural check of a recording. Never throws. Checks, in order: an
20
+ * object, the format, the version, finite bounds with startedAt not above
21
+ * endedAt, a non-array object meta, a non-empty events array, each event's
22
+ * shape, non-decreasing t, and at least one snapshot with string html.
23
+ * Reports the first fault only. It checks structure, not content: payloads
24
+ * still go through the viewer's sanitizers at playback.
25
+ *
26
+ * @param {*} rec
27
+ * @returns {RecordingValidation}
28
+ */
29
+ export function validateRecording(rec: any): RecordingValidation;
30
+ /**
31
+ * Create a recorder: a capture transport that timestamps every message into
32
+ * a portable recording.
33
+ *
34
+ * Retained mode (no onChunk) keeps every event; toRecording(meta) returns
35
+ * the full recording. Chunk mode (onChunk given) retains nothing: every
36
+ * snapshot opens a new keyframe chunk, and a chunk is emitted when it
37
+ * reaches chunkMaxEvents, before an event that would make it span more than
38
+ * chunkMaxMs, or on flush(). onChunk runs synchronously; the recorder
39
+ * updates its own state first, so a throwing onChunk propagates to the
40
+ * caller without corrupting the recorder (capture contains transport
41
+ * throws).
42
+ *
43
+ * @param {RecorderOptions} [options]
44
+ * @returns {Recorder}
45
+ */
46
+ export function createRecorder(options?: RecorderOptions): Recorder;
47
+ /** Recording format id carried in every recording. */
48
+ export const RECORDING_FORMAT: "phantomstream-recording/1";
49
+ /** Recording schema version carried in every recording. */
50
+ export const RECORDING_VERSION: 1;
51
+ /** Event type of host timeline marks. Never a wire message type. */
52
+ export const HOST_MARK_TYPE: "host:mark";
53
+ /**
54
+ * One recorded message: the recorder clock time in ms, the wire type (or
55
+ * HOST_MARK_TYPE), and the payload exactly as it was sent.
56
+ */
57
+ export type RecordingEvent = {
58
+ /**
59
+ * Recorder clock time in ms. Never decreases within a recording.
60
+ */
61
+ t: number;
62
+ /**
63
+ * A STREAM.* protocol string, or HOST_MARK_TYPE for host marks.
64
+ */
65
+ type: string;
66
+ /**
67
+ * The wire payload (same reference as sent), or the JSON-safe mark data
68
+ * with its `kind`.
69
+ */
70
+ payload: any;
71
+ };
72
+ /**
73
+ * A portable recording. JSON-safe whenever its payloads are (capture
74
+ * payloads and host marks always are).
75
+ */
76
+ export type Recording = {
77
+ /**
78
+ * Exactly RECORDING_FORMAT.
79
+ */
80
+ format: string;
81
+ /**
82
+ * Exactly RECORDING_VERSION.
83
+ */
84
+ version: number;
85
+ /**
86
+ * Recorder clock ms of the first event.
87
+ */
88
+ startedAt: number;
89
+ /**
90
+ * Recorder clock ms of the end of the recording (the last flush, never
91
+ * below the last event's t).
92
+ */
93
+ endedAt: number;
94
+ /**
95
+ * Host metadata, shallow-copied from toRecording(meta).
96
+ */
97
+ meta: any;
98
+ /**
99
+ * Non-decreasing t; at least one STREAM.SNAPSHOT for playback.
100
+ */
101
+ events: RecordingEvent[];
102
+ };
103
+ /**
104
+ * One chunk-mode upload unit. A chunk whose first event is a snapshot is a
105
+ * keyframe: playback can start from it without any earlier chunk.
106
+ */
107
+ export type RecordingChunk = {
108
+ /**
109
+ * 0-based chunk counter.
110
+ */
111
+ seq: number;
112
+ /**
113
+ * t of the first event in the chunk.
114
+ */
115
+ t0: number;
116
+ /**
117
+ * t of the last event in the chunk.
118
+ */
119
+ t1: number;
120
+ /**
121
+ * True when events[0] is a STREAM.SNAPSHOT.
122
+ */
123
+ keyframe: boolean;
124
+ /**
125
+ * At most one snapshot, and only at index 0.
126
+ */
127
+ events: RecordingEvent[];
128
+ };
129
+ export type RecorderOptions = {
130
+ /**
131
+ * Clock in ms. Defaults to Date.now(). A non-finite reading reuses the
132
+ * previous event time.
133
+ */
134
+ now?: () => number;
135
+ /**
136
+ * Enables chunk mode: events are not retained, and each finished chunk is
137
+ * handed to this callback synchronously.
138
+ */
139
+ onChunk?: (chunk: RecordingChunk) => void;
140
+ /**
141
+ * Positive integer. Chunk mode cuts a chunk once it holds this many
142
+ * events. Default 200.
143
+ */
144
+ chunkMaxEvents?: number;
145
+ /**
146
+ * Positive finite ms. Chunk mode cuts before an event that would make the
147
+ * chunk span more than this. Default 1000.
148
+ */
149
+ chunkMaxMs?: number;
150
+ /**
151
+ * Record STREAM.READY readiness pings too. Default false.
152
+ */
153
+ recordReady?: boolean;
154
+ };
155
+ /**
156
+ * Capture-compatible transport returned on the recorder handle.
157
+ */
158
+ export type RecorderTransport = {
159
+ /**
160
+ * Stamp and record one wire message.
161
+ */
162
+ send: (type: string, payload: any) => void;
163
+ /**
164
+ * Same function as Recorder.flush; capture.stop() calls it.
165
+ */
166
+ flush: () => void;
167
+ };
168
+ export type RecorderIdentity = {
169
+ streamSessionId: string;
170
+ snapshotId: number;
171
+ };
172
+ export type Recorder = {
173
+ /**
174
+ * Pass to createCapture({ transport }).
175
+ */
176
+ transport: RecorderTransport;
177
+ /**
178
+ * Record a JSON-safe host mark. Returns false (recording nothing) for an
179
+ * empty kind or data that cannot be serialized.
180
+ */
181
+ mark: (kind: string, data?: any) => boolean;
182
+ /**
183
+ * Record a STREAM.OVERLAY with the current identity stamped last. Returns
184
+ * false (recording nothing) before the first snapshot.
185
+ */
186
+ overlay: (payload: any) => boolean;
187
+ /**
188
+ * A copy of the latest snapshot identity, or null before the first one.
189
+ */
190
+ identity: () => (RecorderIdentity | null);
191
+ /**
192
+ * Mark the end time and, in chunk mode, emit the partial chunk.
193
+ */
194
+ flush: () => void;
195
+ /**
196
+ * The retained recording, or null in chunk mode.
197
+ */
198
+ toRecording: (meta?: any) => (Recording | null);
199
+ };
200
+ export type RecordingValidation = {
201
+ ok: boolean;
202
+ /**
203
+ * Lowercase kebab-case reason, present only when ok is false.
204
+ */
205
+ error?: string;
206
+ };
207
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/recorder/index.js"],"names":[],"mappings":"AAuLA;;;;;;;;;;GAUG;AACH,0CAHW;IAAC,MAAM,CAAC,EAAE,cAAc,EAAE,CAAC;IAAC,IAAI,CAAC,MAAS;IAAC,SAAS,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAA;CAAC,GAC9E,SAAS,CAsBrB;AAED;;;;;;;;;;GAUG;AACH,uCAHW,GAAC,GACC,mBAAmB,CAsC/B;AAED;;;;;;;;;;;;;;;GAeG;AACH,yCAHW,eAAe,GACb,QAAQ,CA+MpB;AApdD,sDAAsD;AACtD,+BAAgC,2BAA2B,CAAC;AAE5D,2DAA2D;AAC3D,gCAAiC,CAAC,CAAC;AAEnC,oEAAoE;AACpE,6BAA8B,WAAW,CAAC;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