fauna-api 0.0.0-stage → 1.0.679

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 (171) hide show
  1. package/dist/brands.d.ts +2 -0
  2. package/dist/brands.js +2 -0
  3. package/dist/index.d.ts +64 -0
  4. package/dist/index.js +121 -0
  5. package/dist/src/ant/chat.d.ts +130 -0
  6. package/dist/src/ant/chat.js +467 -0
  7. package/dist/src/ant/format.d.ts +40 -0
  8. package/dist/src/ant/format.js +143 -0
  9. package/dist/src/ant/graph.d.ts +130 -0
  10. package/dist/src/ant/graph.js +449 -0
  11. package/dist/src/ant/index.d.ts +16 -0
  12. package/dist/src/ant/index.js +61 -0
  13. package/dist/src/ant/persona.d.ts +151 -0
  14. package/dist/src/ant/persona.js +136 -0
  15. package/dist/src/ant/timeline.d.ts +283 -0
  16. package/dist/src/ant/timeline.js +1025 -0
  17. package/dist/src/authentification.d.ts +45 -0
  18. package/dist/src/authentification.js +194 -0
  19. package/dist/src/billing.d.ts +135 -0
  20. package/dist/src/billing.js +128 -0
  21. package/dist/src/calendar.d.ts +83 -0
  22. package/dist/src/calendar.js +133 -0
  23. package/dist/src/chats.d.ts +113 -0
  24. package/dist/src/chats.js +100 -0
  25. package/dist/src/cicada/contacts.d.ts +31 -0
  26. package/dist/src/cicada/contacts.js +28 -0
  27. package/dist/src/cicada/conversations.d.ts +73 -0
  28. package/dist/src/cicada/conversations.js +236 -0
  29. package/dist/src/cicada/inboxes.d.ts +48 -0
  30. package/dist/src/cicada/inboxes.js +82 -0
  31. package/dist/src/cicada/index.d.ts +16 -0
  32. package/dist/src/cicada/index.js +61 -0
  33. package/dist/src/cicada/phone.d.ts +48 -0
  34. package/dist/src/cicada/phone.js +306 -0
  35. package/dist/src/drive.d.ts +80 -0
  36. package/dist/src/drive.js +472 -0
  37. package/dist/src/extensions/index.d.ts +4 -0
  38. package/dist/src/extensions/index.js +5 -0
  39. package/dist/src/extensions/web/index.d.ts +6 -0
  40. package/dist/src/extensions/web/index.js +7 -0
  41. package/dist/src/extensions/web/session.d.ts +108 -0
  42. package/dist/src/extensions/web/session.js +470 -0
  43. package/dist/src/extensions/web/tools.d.ts +13 -0
  44. package/dist/src/extensions/web/tools.js +72 -0
  45. package/dist/src/friends.d.ts +39 -0
  46. package/dist/src/friends.js +119 -0
  47. package/dist/src/groups.d.ts +82 -0
  48. package/dist/src/groups.js +269 -0
  49. package/dist/src/inbox.d.ts +11 -0
  50. package/dist/src/inbox.js +35 -0
  51. package/dist/src/integrations.d.ts +52 -0
  52. package/dist/src/integrations.js +205 -0
  53. package/dist/src/magpie/explorer.d.ts +14 -0
  54. package/dist/src/magpie/explorer.js +36 -0
  55. package/dist/src/magpie/index.d.ts +16 -0
  56. package/dist/src/magpie/index.js +61 -0
  57. package/dist/src/magpie/portfolio.d.ts +52 -0
  58. package/dist/src/magpie/portfolio.js +179 -0
  59. package/dist/src/magpie/quotes.d.ts +35 -0
  60. package/dist/src/magpie/quotes.js +47 -0
  61. package/dist/src/magpie/room.d.ts +61 -0
  62. package/dist/src/magpie/room.js +238 -0
  63. package/dist/src/maps.d.ts +159 -0
  64. package/dist/src/maps.js +171 -0
  65. package/dist/src/marmot/browser.d.ts +139 -0
  66. package/dist/src/marmot/browser.js +389 -0
  67. package/dist/src/marmot/index.d.ts +20 -0
  68. package/dist/src/marmot/index.js +65 -0
  69. package/dist/src/marmot/media.d.ts +56 -0
  70. package/dist/src/marmot/media.js +265 -0
  71. package/dist/src/marmot/research.d.ts +337 -0
  72. package/dist/src/marmot/research.js +1138 -0
  73. package/dist/src/marmot/scraper.d.ts +59 -0
  74. package/dist/src/marmot/scraper.js +94 -0
  75. package/dist/src/marmot/web.d.ts +402 -0
  76. package/dist/src/marmot/web.js +2586 -0
  77. package/dist/src/marmot/workspace.d.ts +81 -0
  78. package/dist/src/marmot/workspace.js +263 -0
  79. package/dist/src/parrot/agent.d.ts +53 -0
  80. package/dist/src/parrot/agent.js +93 -0
  81. package/dist/src/parrot/chat.d.ts +84 -0
  82. package/dist/src/parrot/chat.js +237 -0
  83. package/dist/src/parrot/format.d.ts +128 -0
  84. package/dist/src/parrot/format.js +639 -0
  85. package/dist/src/parrot/generative.d.ts +261 -0
  86. package/dist/src/parrot/generative.js +185 -0
  87. package/dist/src/parrot/index.d.ts +22 -0
  88. package/dist/src/parrot/index.js +67 -0
  89. package/dist/src/parrot/room.d.ts +225 -0
  90. package/dist/src/parrot/room.js +466 -0
  91. package/dist/src/parrot/routing.d.ts +90 -0
  92. package/dist/src/parrot/routing.js +78 -0
  93. package/dist/src/parrot/share.d.ts +126 -0
  94. package/dist/src/parrot/share.js +261 -0
  95. package/dist/src/parrot/socket.d.ts +41 -0
  96. package/dist/src/parrot/socket.js +478 -0
  97. package/dist/src/payments.d.ts +73 -0
  98. package/dist/src/payments.js +107 -0
  99. package/dist/src/private/cards.css +75 -0
  100. package/dist/src/rooms.d.ts +76 -0
  101. package/dist/src/rooms.js +168 -0
  102. package/dist/src/shared/schema.d.ts +24 -0
  103. package/dist/src/shared/schema.js +1 -0
  104. package/dist/src/shared/server.d.ts +65 -0
  105. package/dist/src/shared/server.js +302 -0
  106. package/dist/src/termite/environment.d.ts +110 -0
  107. package/dist/src/termite/environment.js +263 -0
  108. package/dist/src/termite/index.d.ts +14 -0
  109. package/dist/src/termite/index.js +59 -0
  110. package/dist/src/termite/os.d.ts +326 -0
  111. package/dist/src/termite/os.js +572 -0
  112. package/dist/src/termite/versioning.d.ts +94 -0
  113. package/dist/src/termite/versioning.js +217 -0
  114. package/dist/src/tickets.d.ts +43 -0
  115. package/dist/src/tickets.js +138 -0
  116. package/dist/src/travel.d.ts +85 -0
  117. package/dist/src/travel.js +44 -0
  118. package/dist/src/ui/authentification.d.ts +24 -0
  119. package/dist/src/ui/authentification.js +177 -0
  120. package/dist/src/ui/brands.css +11 -0
  121. package/dist/src/ui/brands.d.ts +7 -0
  122. package/dist/src/ui/brands.js +14 -0
  123. package/dist/src/ui/browser.d.ts +74 -0
  124. package/dist/src/ui/browser.js +470 -0
  125. package/dist/src/ui/chat.d.ts +183 -0
  126. package/dist/src/ui/chat.js +2379 -0
  127. package/dist/src/ui/chatPanel.d.ts +109 -0
  128. package/dist/src/ui/chatPanel.js +768 -0
  129. package/dist/src/ui/chatSequence.d.ts +36 -0
  130. package/dist/src/ui/chatSequence.js +42 -0
  131. package/dist/src/ui/crown.d.ts +19 -0
  132. package/dist/src/ui/crown.js +199 -0
  133. package/dist/src/ui/cursor.d.ts +73 -0
  134. package/dist/src/ui/cursor.js +175 -0
  135. package/dist/src/ui/device.d.ts +33 -0
  136. package/dist/src/ui/device.js +49 -0
  137. package/dist/src/ui/drive.d.ts +69 -0
  138. package/dist/src/ui/drive.js +1243 -0
  139. package/dist/src/ui/generative.d.ts +39 -0
  140. package/dist/src/ui/generative.js +313 -0
  141. package/dist/src/ui/hover.d.ts +6 -0
  142. package/dist/src/ui/hover.js +210 -0
  143. package/dist/src/ui/index.d.ts +42 -0
  144. package/dist/src/ui/index.js +87 -0
  145. package/dist/src/ui/integrations.d.ts +13 -0
  146. package/dist/src/ui/integrations.js +175 -0
  147. package/dist/src/ui/maps.d.ts +87 -0
  148. package/dist/src/ui/maps.js +547 -0
  149. package/dist/src/ui/roster.d.ts +32 -0
  150. package/dist/src/ui/roster.js +163 -0
  151. package/dist/src/ui/talk.d.ts +12 -0
  152. package/dist/src/ui/talk.js +560 -0
  153. package/dist/src/ui/tickets.d.ts +13 -0
  154. package/dist/src/ui/tickets.js +966 -0
  155. package/dist/src/ui/toast.d.ts +7 -0
  156. package/dist/src/ui/toast.js +258 -0
  157. package/dist/src/ui/tokenText.d.ts +18 -0
  158. package/dist/src/ui/tokenText.js +96 -0
  159. package/dist/src/ui/tokenized.d.ts +42 -0
  160. package/dist/src/ui/tokenized.js +622 -0
  161. package/dist/src/ui/ui.css +4763 -0
  162. package/dist/src/ui/view.d.ts +23 -0
  163. package/dist/src/ui/view.js +584 -0
  164. package/dist/src/view.d.ts +113 -0
  165. package/dist/src/view.js +386 -0
  166. package/dist/src/webhooks.d.ts +66 -0
  167. package/dist/src/webhooks.js +78 -0
  168. package/dist/ui.d.ts +1 -0
  169. package/dist/ui.js +1 -0
  170. package/package.json +87 -4
  171. package/README.md +0 -3
@@ -0,0 +1,59 @@
1
+ /**
2
+ * Keep updated: a workspace's one Termite repository, where its machine agent
3
+ * keeps a scraper per kept dataset running nonstop. Scrapers push rows into
4
+ * their dataset as they scrape; with `store` on, the rows merge into it.
5
+ */
6
+ import { Fauna } from "../../index.js";
7
+ import { ApiKey, Credentials } from "../authentification.js";
8
+ import { Wake } from "../termite/os.js";
9
+ export type ScraperStatus = 'building' | 'active' | 'off';
10
+ /** A dataset kept updated by its workspace's scraper agent. */
11
+ export type Scraper = {
12
+ datasetId: string;
13
+ workspaceId: string;
14
+ /** `building` until its first rows arrive, then `active`. `off` when it stopped and needs turning on again. */
15
+ status: ScraperStatus;
16
+ /** Pushed rows merge into the dataset's live snapshot, so its data includes them. */
17
+ store: boolean;
18
+ /** Fields a row is known by: a pushed row with the same key replaces the old one. None means rows append. */
19
+ key: string[];
20
+ instructions: string;
21
+ /** The snapshot pushed rows merge into, once there is one. */
22
+ liveSnapshotId: string | null;
23
+ lastRowsAt: Date | null;
24
+ rowsTotal: number;
25
+ /** The last thing that went wrong, or ''. */
26
+ lastError: string;
27
+ createdAt: Date | null;
28
+ updatedAt: Date | null;
29
+ };
30
+ export declare const Scraper: {
31
+ fromJSON(json: any): Scraper;
32
+ };
33
+ export type ScraperSettings = {
34
+ store?: boolean;
35
+ key?: string[];
36
+ /** What the agent should know about this dataset. */
37
+ instructions?: string;
38
+ /** The model the workspace's agent thinks with. */
39
+ text?: Fauna.Parrot.Generative.Text;
40
+ };
41
+ /** Whether a dataset is kept updated, and how it's going. Null when it isn't. */
42
+ export declare function getScraper(authorization: Credentials | ApiKey, datasetId: string): Promise<Scraper | null>;
43
+ /**
44
+ * Keep a dataset updated. The workspace's machine agent writes its scraper, and
45
+ * the workspace's machine runs it nonstop; the workspace's owner pays for both.
46
+ * You become the person the agent runs as.
47
+ */
48
+ export declare function createScraper(authorization: Credentials | ApiKey, datasetId: string, settings?: ScraperSettings): Promise<Scraper>;
49
+ /** Change a kept dataset's settings. Key and instruction changes go to the agent. */
50
+ export declare function updateScraper(authorization: Credentials | ApiKey, datasetId: string, settings: ScraperSettings): Promise<Scraper>;
51
+ /** Ask the agent to go over a kept dataset's scraper again, with a note for it. */
52
+ export declare function rebuildScraper(authorization: Credentials | ApiKey, datasetId: string, note?: string): Promise<void>;
53
+ /** Stop keeping a dataset updated. Its scraper goes; the machine stops with the workspace's last one. */
54
+ export declare function removeScraper(authorization: Credentials | ApiKey, datasetId: string): Promise<void>;
55
+ /** The times a workspace's scraper agent woke, newest first. */
56
+ export declare function listWakes(authorization: Credentials | ApiKey, workspaceId: string, query: {
57
+ cursor: number;
58
+ max: number;
59
+ }): Promise<Wake[]>;
@@ -0,0 +1,94 @@
1
+ /**
2
+ * Keep updated: a workspace's one Termite repository, where its machine agent
3
+ * keeps a scraper per kept dataset running nonstop. Scrapers push rows into
4
+ * their dataset as they scrape; with `store` on, the rows merge into it.
5
+ */
6
+ import { Fauna } from "../../index.js";
7
+ import { Wake } from "../termite/os.js";
8
+ export const Scraper = {
9
+ fromJSON(json) {
10
+ return {
11
+ datasetId: String(json.datasetId),
12
+ workspaceId: String(json.workspaceId),
13
+ status: json.status === 'active' || json.status === 'off' ? json.status : 'building',
14
+ store: Boolean(json.store),
15
+ key: Array.isArray(json.key) ? json.key.map(String) : [],
16
+ instructions: String(json.instructions ?? ''),
17
+ liveSnapshotId: json.liveSnapshotId ?? null,
18
+ lastRowsAt: json.lastRowsAt ? new Date(json.lastRowsAt) : null,
19
+ rowsTotal: Number(json.rowsTotal ?? 0),
20
+ lastError: String(json.lastError ?? ''),
21
+ createdAt: json.createdAt ? new Date(json.createdAt) : null,
22
+ updatedAt: json.updatedAt ? new Date(json.updatedAt) : null,
23
+ };
24
+ },
25
+ };
26
+ /** Whether a dataset is kept updated, and how it's going. Null when it isn't. */
27
+ export async function getScraper(authorization, datasetId) {
28
+ const response = await fetch(`${Fauna.getURL()}/marmot/dataset/scraper/get`, {
29
+ method: "POST",
30
+ headers: { "Content-Type": "application/json", "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` },
31
+ body: JSON.stringify({ datasetId }),
32
+ });
33
+ if (!response.ok)
34
+ throw new Error(await response.text());
35
+ const json = await response.json();
36
+ return json ? Scraper.fromJSON(json) : null;
37
+ }
38
+ /**
39
+ * Keep a dataset updated. The workspace's machine agent writes its scraper, and
40
+ * the workspace's machine runs it nonstop; the workspace's owner pays for both.
41
+ * You become the person the agent runs as.
42
+ */
43
+ export async function createScraper(authorization, datasetId, settings = {}) {
44
+ const response = await fetch(`${Fauna.getURL()}/marmot/dataset/scraper/create`, {
45
+ method: "POST",
46
+ headers: { "Content-Type": "application/json", "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` },
47
+ body: JSON.stringify({ datasetId, ...settings }),
48
+ });
49
+ if (!response.ok)
50
+ throw new Error(await response.text());
51
+ return Scraper.fromJSON(await response.json());
52
+ }
53
+ /** Change a kept dataset's settings. Key and instruction changes go to the agent. */
54
+ export async function updateScraper(authorization, datasetId, settings) {
55
+ const response = await fetch(`${Fauna.getURL()}/marmot/dataset/scraper/update`, {
56
+ method: "POST",
57
+ headers: { "Content-Type": "application/json", "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` },
58
+ body: JSON.stringify({ datasetId, ...settings }),
59
+ });
60
+ if (!response.ok)
61
+ throw new Error(await response.text());
62
+ return Scraper.fromJSON(await response.json());
63
+ }
64
+ /** Ask the agent to go over a kept dataset's scraper again, with a note for it. */
65
+ export async function rebuildScraper(authorization, datasetId, note) {
66
+ const response = await fetch(`${Fauna.getURL()}/marmot/dataset/scraper/rebuild`, {
67
+ method: "POST",
68
+ headers: { "Content-Type": "application/json", "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` },
69
+ body: JSON.stringify({ datasetId, note }),
70
+ });
71
+ if (!response.ok)
72
+ throw new Error(await response.text());
73
+ }
74
+ /** Stop keeping a dataset updated. Its scraper goes; the machine stops with the workspace's last one. */
75
+ export async function removeScraper(authorization, datasetId) {
76
+ const response = await fetch(`${Fauna.getURL()}/marmot/dataset/scraper/remove`, {
77
+ method: "POST",
78
+ headers: { "Content-Type": "application/json", "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` },
79
+ body: JSON.stringify({ datasetId }),
80
+ });
81
+ if (!response.ok)
82
+ throw new Error(await response.text());
83
+ }
84
+ /** The times a workspace's scraper agent woke, newest first. */
85
+ export async function listWakes(authorization, workspaceId, query) {
86
+ const response = await fetch(`${Fauna.getURL()}/marmot/workspace/wakes`, {
87
+ method: "POST",
88
+ headers: { "Content-Type": "application/json", "Authorization": 'email' in authorization ? `Token ${authorization.token}` : `ApiKey ${authorization.id}` },
89
+ body: JSON.stringify({ workspaceId, cursor: query.cursor, max: query.max }),
90
+ });
91
+ if (!response.ok)
92
+ throw new Error(await response.text());
93
+ return (await response.json()).map(Wake.fromJSON);
94
+ }
@@ -0,0 +1,402 @@
1
+ /**
2
+ * Marmot-owned live web-room client: DOM capture/replay, HTTP bootstrap/assets,
3
+ * and the WebRoom socket. Transport-agnostic capture plus the fauna share
4
+ * routes (`/extensions/web/live`, `/bootstrap`, `/asset`). Session orchestration
5
+ * (startWebShare, invite, chat pairing) stays in extensions/web.
6
+ */
7
+ import { Credentials, ApiKey } from "../authentification.js";
8
+ import { Room, Presence, Authorization } from "../shared/server.js";
9
+ /** A single serialized DOM node. `id` is a synthetic stable key assigned by the
10
+ * recorder; it is NOT the element's DOM id attribute. */
11
+ export type WebNode = {
12
+ id: number;
13
+ kind: "element";
14
+ tag: string;
15
+ attributes: Record<string, string>;
16
+ children: number[];
17
+ } | {
18
+ id: number;
19
+ kind: "text";
20
+ text: string;
21
+ };
22
+ /** A full document snapshot: the root node id plus every node reachable from
23
+ * it, flattened into an id->node map for O(1) patching on the viewer. */
24
+ export type WebSnapshot = {
25
+ root: number;
26
+ nodes: Record<number, WebNode>;
27
+ /** Viewport the host captured at (viewers use it only for reference — they
28
+ * render at their own size). */
29
+ viewport: {
30
+ width: number;
31
+ height: number;
32
+ };
33
+ };
34
+ /** An incremental change to a previously-snapshotted tree. */
35
+ export type WebMutation = {
36
+ kind: "insert";
37
+ parent: number;
38
+ node: WebNode;
39
+ subtree: WebNode[];
40
+ before: number | null;
41
+ } | {
42
+ kind: "remove";
43
+ id: number;
44
+ } | {
45
+ kind: "text";
46
+ id: number;
47
+ text: string;
48
+ } | {
49
+ kind: "attribute";
50
+ id: number;
51
+ name: string;
52
+ value: string | null;
53
+ } | {
54
+ kind: "viewport";
55
+ width: number;
56
+ height: number;
57
+ };
58
+ /** Agent or host pointer. Sibling of WebMutation — not applied by DomReplayer. */
59
+ export type HtmlPointer = {
60
+ x: number;
61
+ y: number;
62
+ scrollX: number;
63
+ scrollY: number;
64
+ visible?: boolean;
65
+ /** The CSS cursor under the pointer (`pointer`, `text`, `nwse-resize`...), `default` for `auto`. */
66
+ shape?: string;
67
+ };
68
+ /** Placeholder scheme rewritten into guest blob: URLs after asset download. */
69
+ export declare const WEB_ASSET_SCHEME = "fauna-web-asset:";
70
+ /** Optional privileged fetcher (extension background). */
71
+ export type MediaFetcher = (url: string) => Promise<{
72
+ data: Uint8Array;
73
+ contentType: string;
74
+ } | null>;
75
+ /** Install a privileged media fetcher (e.g. chrome.runtime fetch-bytes). */
76
+ export declare function setMediaFetcher(fetcher: MediaFetcher | null): void;
77
+ /** Pull url(...) and @import targets out of CSS text (preserves @media as-is). */
78
+ export declare function extractCssUrls(css: string): string[];
79
+ /** Rewrite url()/ @import targets in CSS using fauna-web-asset codes. */
80
+ export declare function rewriteCssUrls(css: string, map: Map<string, string>): string;
81
+ /**
82
+ * Serialize readable document stylesheets as rule text (keeps @media / @supports).
83
+ * Opaque cross-origin sheets are skipped unless their <style> text is available.
84
+ */
85
+ export declare function serializeDocumentStyles(doc?: Document): {
86
+ css: string;
87
+ urls: string[];
88
+ };
89
+ /**
90
+ * Deep-serialize an element tree: strip scripts/extension UI, flatten open
91
+ * shadow roots into light DOM, replace opaque iframes with placeholders.
92
+ */
93
+ export declare function deepFreezeClone(source: Element): Element;
94
+ /** Collect absolute/resolvable media URLs from a cleaned element tree. */
95
+ export declare function collectMediaUrls(root: Element): string[];
96
+ /** Rewrite media URLs in-place using `map` (original URL → fauna-web-asset:code). */
97
+ export declare function rewriteMediaUrls(root: Element, map: Map<string, string>): void;
98
+ export declare function extractAssetCodes(html: string): string[];
99
+ /** Replace `fauna-web-asset:CODE` markers with blob/object URLs from `blobs`. */
100
+ export declare function materializeAssetUrls(html: string, blobs: Map<string, string>): string;
101
+ /**
102
+ * Deep-freeze `root` + inject serialized stylesheets. Does not rewrite assets —
103
+ * call `collectMediaUrls` / `rewriteMediaUrls` (and CSS urls) afterward.
104
+ */
105
+ export declare function toHtml(root?: Node): {
106
+ html: string;
107
+ viewport: {
108
+ width: number;
109
+ height: number;
110
+ };
111
+ clone: Element;
112
+ cssUrls: string[];
113
+ };
114
+ /** Best-effort fetch of a media URL — prefers privileged `setMediaFetcher`. */
115
+ export declare function fetchMediaBytes(url: string): Promise<{
116
+ data: Uint8Array;
117
+ contentType: string;
118
+ } | null>;
119
+ /** Absolute-resolve a URL against the current page (or a provided base). */
120
+ export declare function absoluteUrl(url: string, base?: string): string;
121
+ /** Collect media + CSS urls from a frozen clone / stylesheet list. */
122
+ export declare function collectAllAssetUrls(root: Element, cssUrls?: string[]): string[];
123
+ /**
124
+ * Serialize a live DOM subtree into a flat `WebSnapshot`. The recorder tags each
125
+ * captured node with a synthetic id via a WeakMap so later mutations can
126
+ * reference nodes by that id without relying on DOM identity crossing the wire.
127
+ */
128
+ export declare class DomRecorder {
129
+ private readonly root;
130
+ private nextId;
131
+ private ids;
132
+ private observer;
133
+ private frames;
134
+ private onMutation;
135
+ constructor(root?: Node);
136
+ /**
137
+ * Reset and DFS-assign synthetic ids on the live tree (same order as
138
+ * `serializeNode`, descending into framed documents). Call after publishing
139
+ * HTML bootstrap so mutations align with the guest's `applyHtml` bind.
140
+ */
141
+ bindIds(): void;
142
+ private idFor;
143
+ private serializeNode;
144
+ /** The one child a frame's wrapper holds: its document root, or a placeholder text. */
145
+ private serializeFrameContent;
146
+ /** Track a frame: observe its document and re-inline it when it navigates. */
147
+ private watchFrame;
148
+ private reinline;
149
+ /** Serialize a single node and its whole subtree into a flat node list (used
150
+ * to describe inserted subtrees in mutations). */
151
+ private serializeSubtree;
152
+ /** Capture the current document as a snapshot. */
153
+ snapshot(): WebSnapshot;
154
+ private handle;
155
+ /**
156
+ * Start observing the document, and every framed document it inlines.
157
+ * `onMutation` fires with a batched-flattened `WebMutation` for every DOM
158
+ * change. Also emits `viewport` mutations on resize. Call `stop()` to detach.
159
+ */
160
+ start(onMutation: (mutation: WebMutation) => void): void;
161
+ private detachResize;
162
+ stop(): void;
163
+ }
164
+ /**
165
+ * Re-render a `WebSnapshot` into a target document (typically an isolated iframe
166
+ * or shadow root on the viewer) and apply incoming `WebMutation`s. The replayer
167
+ * keeps its own id->Node map mirroring the recorder's synthetic ids.
168
+ */
169
+ export declare class DomReplayer {
170
+ private readonly mount;
171
+ private nodes;
172
+ private _viewport;
173
+ private iframe;
174
+ private queued;
175
+ private loads;
176
+ private frameScopes;
177
+ private scopedSheets;
178
+ private boxSheet;
179
+ private boxes;
180
+ constructor(mount: Element);
181
+ /** Host viewport from the last snapshot / viewport mutation (advisory). */
182
+ getViewport(): {
183
+ width: number;
184
+ height: number;
185
+ } | null;
186
+ private docRoot;
187
+ /**
188
+ * Apply a full cleaned HTML document (or fragment). Uses an iframe when the
189
+ * payload looks like a full document so `<html>/<head>/<body>` structure and
190
+ * DFS ids match the host.
191
+ */
192
+ applyHtml(html: string, viewport?: {
193
+ width: number;
194
+ height: number;
195
+ }): Promise<void>;
196
+ /** Bind synthetic ids: from the ids a recorded snapshot carries, else in DFS order to
197
+ * match a recorder that numbers in that order. */
198
+ bindIds(): void;
199
+ /** Elements carry `data-fauna-node`, text-only elements name their text with
200
+ * `data-fauna-text`, and every other text node follows a `fauna:N` comment. A marker
201
+ * with no text after it was an empty text node on the host, so one is made here. */
202
+ private bindMarked;
203
+ /** The document the replay renders into: its iframe's for full documents, else the mount's. */
204
+ getDocument(): Document;
205
+ /** Scope inlined frames' styles, mirror hover and focus, and size frame boxes, for a full document's frame. */
206
+ private restyle;
207
+ /**
208
+ * Inlined frames are divs, so they get an iframe's box: inline block, 300 by 150 and
209
+ * clipped unless the page says otherwise, their `width`, `height` and `frameborder`
210
+ * attributes as sizes and border, and the framed document filling them. All at zero
211
+ * specificity in a sheet of its own, so page CSS wins, like a real iframe's
212
+ * presentational hints. No nodes join the replay, so ids stay aligned.
213
+ */
214
+ private frameBoxes;
215
+ /** Scroll a replayed element, or a framed document's html, to the host's `data-fauna-scroll`. */
216
+ private applyScroll;
217
+ /**
218
+ * A framed document is inlined into the replay, so its stylesheets would style the
219
+ * whole copy: a site's `body { background }` repaints the page around its frame. Each
220
+ * of its sheets goes inside `@scope` at the frame's html div instead. Sheets from other
221
+ * origins can't be read, so they stay as they are.
222
+ */
223
+ private scopeFrames;
224
+ /**
225
+ * `:hover` and `:focus` never apply in a replay. The host marks what they would match
226
+ * with `data-fauna-hover` and the focus attributes, so point those selectors at the
227
+ * attributes instead; both weigh the same in the cascade. Only a full document's own
228
+ * frame is rewritten.
229
+ */
230
+ private mirrorStates;
231
+ private ownerDoc;
232
+ private build;
233
+ private buildFromList;
234
+ /** Render a fresh snapshot, replacing whatever the mount currently holds. */
235
+ apply(snapshot: WebSnapshot): void;
236
+ /** Apply one incremental mutation to the rendered tree. */
237
+ mutate(mutation: WebMutation): void;
238
+ }
239
+ /**
240
+ * Self-contained freeze + style serialize for `page.evaluate`. Closures over
241
+ * module helpers break Puppeteer serialization, so helpers live inside.
242
+ */
243
+ export declare function pageToHtml(root?: Node): {
244
+ html: string;
245
+ viewport: {
246
+ width: number;
247
+ height: number;
248
+ };
249
+ clone: Element;
250
+ cssUrls: string[];
251
+ };
252
+ /** Install a MutationObserver that posts WebMutations to `window[pushName]`.
253
+ * Framed documents are walked, observed, and re-inlined on navigation, with
254
+ * their html, head, and body addressed as the divs `pageToHtml` emits. */
255
+ export declare function pageInstallRecorder(pushName: string): void;
256
+ export declare function pageStopRecorder(): void;
257
+ /** Runs in the page: the pointer at (x, y) with the CSS cursor of whatever is under it,
258
+ * looking inside frames the recorder inlines. */
259
+ export declare function pageReadPointer(x?: number, y?: number, visible?: boolean): HtmlPointer;
260
+ /** In-page media fetch for Puppeteer evaluate (cookies, no chrome.runtime). */
261
+ export declare function pageFetchMedia(url: string): Promise<{
262
+ dataBase64: string;
263
+ contentType: string;
264
+ } | null>;
265
+ export type WebTarget = {
266
+ code: string;
267
+ } | {
268
+ reference: string;
269
+ };
270
+ export type BootstrapMeta = {
271
+ version: number;
272
+ viewport?: {
273
+ width: number;
274
+ height: number;
275
+ };
276
+ contentLength?: number;
277
+ contentType?: string;
278
+ /** In-band HTML for server-hosted rooms (BrowserRoom). Extension share uses HTTP. */
279
+ html?: string;
280
+ };
281
+ export type AssetUploadResult = {
282
+ assetId: string;
283
+ accessCode: string;
284
+ contentType: string;
285
+ };
286
+ /**
287
+ * Upload cleaned HTML as a raw stream (XHR for upload progress, Drive-style).
288
+ */
289
+ export declare function uploadBootstrap(authorization: Credentials | ApiKey, target: WebTarget, html: string | Uint8Array, options?: {
290
+ version?: number;
291
+ viewport?: {
292
+ width: number;
293
+ height: number;
294
+ };
295
+ contentType?: string;
296
+ onProgress?: (percent: number) => void;
297
+ }): Promise<{
298
+ ok: boolean;
299
+ version: number;
300
+ }>;
301
+ /**
302
+ * Download the room HTML bootstrap with download progress when Content-Length is known.
303
+ */
304
+ export declare function downloadBootstrap(authorization: Credentials | ApiKey, target: WebTarget, onProgress?: (percent: number) => void): Promise<{
305
+ html: string;
306
+ contentLength: number;
307
+ contentType: string;
308
+ }>;
309
+ /**
310
+ * Upload one media asset; returns a per-asset access code for guest download.
311
+ */
312
+ export declare function uploadAsset(authorization: Credentials | ApiKey, target: WebTarget, data: Uint8Array, contentType: string, options?: {
313
+ assetId?: string;
314
+ onProgress?: (percent: number) => void;
315
+ }): Promise<AssetUploadResult>;
316
+ /** Download one asset by its file access code. */
317
+ export declare function downloadAsset(authorization: Credentials | ApiKey, accessCode: string, onProgress?: (percent: number) => void): Promise<{
318
+ data: Uint8Array;
319
+ contentType: string;
320
+ }>;
321
+ /** Aggregate sequential upload/download stages into a single 0..1 progress. */
322
+ export declare function weightedProgress(stages: {
323
+ weight: number;
324
+ run: (onProgress: (p: number) => void) => Promise<void>;
325
+ }[], onProgress?: (percent: number) => void): Promise<void>;
326
+ export type WebRoomHooks = Partial<{
327
+ /** Host published bootstrap meta — guests should HTTP GET the HTML. */
328
+ onBootstrap(room: WebRoom, bootstrap: BootstrapMeta): void;
329
+ /** The host published a fresh full-page snapshot (legacy / fallback). */
330
+ onSnapshot(room: WebRoom, snapshot: WebSnapshot): void;
331
+ /** The host emitted one incremental DOM mutation. */
332
+ onMutation(room: WebRoom, mutation: WebMutation): void;
333
+ /** The host disconnected / stopped sharing — the room is closing. */
334
+ onClosed(room: WebRoom): void;
335
+ /** Presence roster changed (join/leave/update). */
336
+ onPresence(room: WebRoom): void;
337
+ }>;
338
+ /**
339
+ * A live web room for page sharing. `WebRoom extends Room` and carries presence
340
+ * + small DOM mutations. Initial HTML and media bytes travel over HTTP
341
+ * bootstrap/asset routes, not this socket.
342
+ */
343
+ export declare class WebRoom extends Room {
344
+ private hooks;
345
+ private latest;
346
+ private bootstrap;
347
+ private toolHandler;
348
+ private pendingTools;
349
+ /** Tagged host principal from the live connection (`credentials:` / `group:` / …). */
350
+ private hostPrincipal;
351
+ /** Server-computed: whether this caller may invite others to the share. */
352
+ private _canInvite;
353
+ constructor(ws: WebSocket, authorization: Authorization, id: string, hooks: WebRoomHooks, connectionState?: {
354
+ room?: {
355
+ hostPrincipal?: string;
356
+ canInvite?: boolean;
357
+ };
358
+ }, opts?: {
359
+ owned?: boolean;
360
+ endpoint?: string;
361
+ });
362
+ private readonly owned;
363
+ setHooks(hooks: WebRoomHooks): void;
364
+ /** Ingest-only child of a BrowserRoom (same socket). */
365
+ static fromParent(parent: Room, hooks?: WebRoomHooks, connectionState?: {
366
+ room?: {
367
+ hostPrincipal?: string;
368
+ canInvite?: boolean;
369
+ };
370
+ }): WebRoom;
371
+ /** Host principal tagged string, if the connection provided it. */
372
+ getHostPrincipal(): string | null;
373
+ /** Whether this signed-in caller may invite others (server-gated). */
374
+ canInvite(): boolean;
375
+ getSnapshot(): WebSnapshot | null;
376
+ getBootstrap(): BootstrapMeta | null;
377
+ disconnect(): void;
378
+ ingestSnapshot(snapshot: WebSnapshot): void;
379
+ ingestBootstrap(meta: BootstrapMeta): void;
380
+ publishBootstrap(meta: BootstrapMeta): void;
381
+ publishSnapshot(snapshot: WebSnapshot): void;
382
+ publishMutation(mutation: WebMutation): void;
383
+ publishClosed(): void;
384
+ /** Host: fulfill inbound `web-tool-call` frames. */
385
+ setToolHandler(handler: (name: string, params: Record<string, unknown>) => Promise<string>): () => void;
386
+ /** Any member: ask the host to run a page tool. */
387
+ invokeTool(name: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<string>;
388
+ handleEvent(packet: any): boolean;
389
+ private handleToolCall;
390
+ }
391
+ /**
392
+ * Connect to a web room. `target` is an access code (viewer joining a shared
393
+ * page) or a room reference (host opening its own room).
394
+ */
395
+ export declare function connectWebRoom(authorization: Credentials | ApiKey, target: {
396
+ code: string;
397
+ } | {
398
+ reference: string;
399
+ }, hooks?: WebRoomHooks): Promise<{
400
+ room: WebRoom;
401
+ self: Presence;
402
+ }>;