fauna-api 0.0.0-stage → 1.0.676

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 +106 -0
  42. package/dist/src/extensions/web/session.js +469 -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 +89 -6
  171. package/README.md +0 -3
@@ -0,0 +1,139 @@
1
+ /**
2
+ * Server-hosted live browser room. Contains a WebRoom for HTML replay on the
3
+ * same socket. Tools run on the Marmot host (Puppeteer), not a client tab.
4
+ */
5
+ import { ApiKey, Credentials } from "../authentification.js";
6
+ import { Group } from "../groups.js";
7
+ import { Authorization, Presence, Room } from "../shared/server.js";
8
+ import type { Tool } from "../parrot/generative.js";
9
+ import { Marmot } from "./index.js";
10
+ import { WebRoom, type WebRoomHooks, type HtmlPointer, type BootstrapMeta } from "./web.js";
11
+ export type MouseButton = "left" | "right" | "middle";
12
+ export type BrowserTool = {
13
+ kind: "move";
14
+ x: number;
15
+ y: number;
16
+ }
17
+ /** `count` clicks in a row (2 is a double click). A click on the same spot right after
18
+ * another continues its run, the way a person's quick second click does. */
19
+ | {
20
+ kind: "click";
21
+ x?: number;
22
+ y?: number;
23
+ downMs?: number;
24
+ button?: MouseButton;
25
+ count?: number;
26
+ } | {
27
+ kind: "drag";
28
+ to: {
29
+ x: number;
30
+ y: number;
31
+ };
32
+ from?: {
33
+ x: number;
34
+ y: number;
35
+ };
36
+ downMs?: number;
37
+ } | {
38
+ kind: "scroll";
39
+ deltaX?: number;
40
+ deltaY?: number;
41
+ } | {
42
+ kind: "type";
43
+ text: string;
44
+ } | {
45
+ kind: "executeJavascript";
46
+ code: string;
47
+ } | {
48
+ kind: "search";
49
+ query: string;
50
+ } | {
51
+ kind: "exit";
52
+ answer?: string;
53
+ reason?: string;
54
+ };
55
+ export type BrowserRoomHooks<T extends BrowserTool = BrowserTool> = Partial<{
56
+ onCursor(room: PageRoom<T>, cursor: HtmlPointer): void;
57
+ onTool(room: PageRoom<T>, tool: T): void;
58
+ onClosed(room: PageRoom<T>): void;
59
+ onPresence(room: PageRoom<T>): void;
60
+ /** Control changed hands, or an agent took or released the room. */
61
+ onControl(room: PageRoom<T>): void;
62
+ web?: WebRoomHooks;
63
+ }>;
64
+ /** A server agent driving the room. While one does, nobody else can act. */
65
+ export type RoomAgent = {
66
+ id: string;
67
+ name: string;
68
+ icon?: string;
69
+ };
70
+ export declare const RoomAgent: {
71
+ fromJSON(json: any): RoomAgent;
72
+ };
73
+ /** A model's tools for the `enabled` kinds. A room that takes only some kinds (a machine's
74
+ * desktop) gets calls of only those kinds. */
75
+ export declare function parrotTools<T extends BrowserTool = BrowserTool>(enabled: ReadonlySet<T["kind"]>, invoke: (tool: T) => Promise<string>): Tool[];
76
+ /**
77
+ * A room around one live page: its HTML stream, cursor, control and tools. `T` is the
78
+ * tools it takes: every browser tool for a web page (BrowserRoom), fewer for a machine's
79
+ * desktop (MachineRoom). Each subclass brings its own ways to open one.
80
+ */
81
+ export declare class PageRoom<T extends BrowserTool = BrowserTool> extends Room {
82
+ readonly web: WebRoom;
83
+ cursor: HtmlPointer;
84
+ readonly enabledTools: ReadonlySet<T["kind"]>;
85
+ /** The seat (presence id) whose actions run. */
86
+ controller: string | null;
87
+ /** Set while a server agent holds the room. */
88
+ agent: RoomAgent | null;
89
+ private hooks;
90
+ private pending;
91
+ constructor(ws: WebSocket, authorization: Authorization, id: string, hooks?: BrowserRoomHooks<T>, state?: {
92
+ bootstrap?: BootstrapMeta;
93
+ cursor?: HtmlPointer;
94
+ enabledTools?: T["kind"][];
95
+ control?: {
96
+ controller?: string | null;
97
+ agent?: any;
98
+ };
99
+ }, endpoint?: string);
100
+ watch(hooks: BrowserRoomHooks<T>): void;
101
+ /** Whether your actions run: you control it and no agent holds it. */
102
+ controlling(self: Presence): boolean;
103
+ /** Hand control to a seat, or take it yourself without one. While an agent holds the room this stops the agent. */
104
+ setController(seat?: string): Promise<void>;
105
+ /** Presence changed: tell whoever is watching now. */
106
+ emitPresence(): void;
107
+ emitClosed(): void;
108
+ protected applyControl(control: {
109
+ controller?: string | null;
110
+ agent?: any;
111
+ } | undefined): void;
112
+ invokeTool(tool: T): Promise<string>;
113
+ parrotTools(): Tool[];
114
+ handleEvent(packet: any): boolean;
115
+ }
116
+ /** A live web page in a Marmot (or Ant) browser: every browser tool. */
117
+ export declare class BrowserRoom extends PageRoom<BrowserTool> {
118
+ static connect(authorization: Credentials | ApiKey, target: {
119
+ reference: string;
120
+ }, opts?: {
121
+ tools?: BrowserTool["kind"][];
122
+ hooks?: BrowserRoomHooks;
123
+ group?: Group;
124
+ }): Promise<{
125
+ room: BrowserRoom;
126
+ self: Presence;
127
+ }>;
128
+ /** `endpoint` is where the page's room lives: Marmot's by default, or e.g. Ant's /timeline/browser/live. */
129
+ static join(authorization: Credentials | ApiKey, target: {
130
+ accessCode: string;
131
+ }, opts?: {
132
+ tools?: BrowserTool["kind"][];
133
+ hooks?: BrowserRoomHooks;
134
+ endpoint?: string;
135
+ }): Promise<{
136
+ room: BrowserRoom;
137
+ self: Presence;
138
+ }>;
139
+ }
@@ -0,0 +1,389 @@
1
+ /**
2
+ * Server-hosted live browser room. Contains a WebRoom for HTML replay on the
3
+ * same socket. Tools run on the Marmot host (Puppeteer), not a client tab.
4
+ */
5
+ import { Presence, Room, connect as connectServer } from "../shared/server.js";
6
+ import { Marmot } from "./index.js";
7
+ import { WebRoom } from "./web.js";
8
+ const ALL_TOOLS = [
9
+ "move", "click", "drag", "scroll", "type",
10
+ "executeJavascript", "search", "exit",
11
+ ];
12
+ export const RoomAgent = {
13
+ fromJSON(json) {
14
+ return {
15
+ id: String(json.id),
16
+ name: String(json.name ?? 'Agent'),
17
+ ...(json.icon ? { icon: String(json.icon) } : {}),
18
+ };
19
+ },
20
+ };
21
+ /** A model's tools for the `enabled` kinds. A room that takes only some kinds (a machine's
22
+ * desktop) gets calls of only those kinds. */
23
+ export function parrotTools(enabled, invoke) {
24
+ // Only enabled kinds become tools, so every call below is a T.
25
+ const run = invoke;
26
+ const tools = [];
27
+ const add = (tool) => {
28
+ if (enabled.has(tool.function.name))
29
+ tools.push(tool);
30
+ };
31
+ add({
32
+ function: {
33
+ name: "move",
34
+ description: "Move the pointer to viewport coordinates. Does not click.",
35
+ parameters: {
36
+ type: "OBJECT",
37
+ properties: {
38
+ x: { type: "NUMBER", description: "X pixel" },
39
+ y: { type: "NUMBER", description: "Y pixel" },
40
+ },
41
+ required: ["x", "y"],
42
+ },
43
+ },
44
+ evaluate: async (params) => run({ kind: "move", x: Number(params?.x), y: Number(params?.y) }),
45
+ });
46
+ add({
47
+ function: {
48
+ name: "click",
49
+ description: "Click. Optional coordinates move there first. downMs is how long the button stays down. button right opens context menus; count 2 double clicks.",
50
+ parameters: {
51
+ type: "OBJECT",
52
+ properties: {
53
+ x: { type: "NUMBER", description: "X pixel" },
54
+ y: { type: "NUMBER", description: "Y pixel" },
55
+ downMs: { type: "NUMBER", description: "Hold duration in ms" },
56
+ button: { type: "STRING", enum: ["left", "right", "middle"], description: "Mouse button, default left" },
57
+ count: { type: "NUMBER", description: "Clicks in a row: 2 double clicks, 3 triple clicks. Default 1" },
58
+ },
59
+ },
60
+ },
61
+ evaluate: async (params) => run({
62
+ kind: "click",
63
+ ...(params?.x != null ? { x: Number(params.x) } : {}),
64
+ ...(params?.y != null ? { y: Number(params.y) } : {}),
65
+ ...(params?.downMs != null ? { downMs: Number(params.downMs) } : {}),
66
+ ...(params?.button === "right" || params?.button === "middle" ? { button: params.button } : {}),
67
+ ...(params?.count != null ? { count: Number(params.count) } : {}),
68
+ }),
69
+ });
70
+ add({
71
+ function: {
72
+ name: "drag",
73
+ description: "Drag from an optional start point to a destination.",
74
+ parameters: {
75
+ type: "OBJECT",
76
+ properties: {
77
+ to: { type: "OBJECT", description: "Destination {x,y}" },
78
+ from: { type: "OBJECT", description: "Start {x,y}" },
79
+ downMs: { type: "NUMBER", description: "Hold at the end in ms" },
80
+ },
81
+ required: ["to"],
82
+ },
83
+ },
84
+ evaluate: async (params) => run({
85
+ kind: "drag",
86
+ to: { x: Number(params?.to?.x), y: Number(params?.to?.y) },
87
+ ...(params?.from ? { from: { x: Number(params.from.x), y: Number(params.from.y) } } : {}),
88
+ ...(params?.downMs != null ? { downMs: Number(params.downMs) } : {}),
89
+ }),
90
+ });
91
+ add({
92
+ function: {
93
+ name: "scroll",
94
+ description: "Scroll the page with the wheel at the current pointer.",
95
+ parameters: {
96
+ type: "OBJECT",
97
+ properties: {
98
+ deltaX: { type: "NUMBER", description: "Horizontal wheel delta" },
99
+ deltaY: { type: "NUMBER", description: "Vertical wheel delta" },
100
+ },
101
+ },
102
+ },
103
+ evaluate: async (params) => run({
104
+ kind: "scroll",
105
+ ...(params?.deltaX != null ? { deltaX: Number(params.deltaX) } : {}),
106
+ ...(params?.deltaY != null ? { deltaY: Number(params.deltaY) } : {}),
107
+ }),
108
+ });
109
+ add({
110
+ function: {
111
+ name: "type",
112
+ description: "Type text at the current focus, one key at a time.",
113
+ parameters: {
114
+ type: "OBJECT",
115
+ properties: { text: { type: "STRING", description: "Text to type" } },
116
+ required: ["text"],
117
+ },
118
+ },
119
+ evaluate: async (params) => run({ kind: "type", text: String(params?.text ?? "") }),
120
+ });
121
+ add({
122
+ function: {
123
+ name: "executeJavascript",
124
+ description: "Evaluate JavaScript in the page and return the stringified result.",
125
+ parameters: {
126
+ type: "OBJECT",
127
+ properties: { code: { type: "STRING", description: "JavaScript to evaluate" } },
128
+ required: ["code"],
129
+ },
130
+ },
131
+ evaluate: async (params) => run({ kind: "executeJavascript", code: String(params?.code ?? "") }),
132
+ });
133
+ add({
134
+ function: {
135
+ name: "search",
136
+ description: "Search the web. Returns matching websites.",
137
+ parameters: {
138
+ type: "OBJECT",
139
+ properties: { query: { type: "STRING", description: "Search query" } },
140
+ required: ["query"],
141
+ },
142
+ },
143
+ evaluate: async (params) => run({ kind: "search", query: String(params?.query ?? "") }),
144
+ });
145
+ add({
146
+ function: {
147
+ name: "exit",
148
+ description: "Leave the page. Pass answer when the goal is done, or reason when giving up.",
149
+ parameters: {
150
+ type: "OBJECT",
151
+ properties: {
152
+ answer: { type: "STRING", description: "What was found" },
153
+ reason: { type: "STRING", description: "Why the goal cannot be met" },
154
+ },
155
+ },
156
+ },
157
+ evaluate: async (params) => run({
158
+ kind: "exit",
159
+ ...(params?.answer != null ? { answer: String(params.answer) } : {}),
160
+ ...(params?.reason != null ? { reason: String(params.reason) } : {}),
161
+ }),
162
+ });
163
+ return tools;
164
+ }
165
+ /**
166
+ * A room around one live page: its HTML stream, cursor, control and tools. `T` is the
167
+ * tools it takes: every browser tool for a web page (BrowserRoom), fewer for a machine's
168
+ * desktop (MachineRoom). Each subclass brings its own ways to open one.
169
+ */
170
+ export class PageRoom extends Room {
171
+ constructor(ws, authorization, id, hooks = {}, state, endpoint = `${Marmot.getURL()}/browser/live`) {
172
+ super(endpoint, ws, authorization, id);
173
+ Object.defineProperty(this, "web", {
174
+ enumerable: true,
175
+ configurable: true,
176
+ writable: true,
177
+ value: void 0
178
+ });
179
+ Object.defineProperty(this, "cursor", {
180
+ enumerable: true,
181
+ configurable: true,
182
+ writable: true,
183
+ value: { x: 0, y: 0, scrollX: 0, scrollY: 0 }
184
+ });
185
+ Object.defineProperty(this, "enabledTools", {
186
+ enumerable: true,
187
+ configurable: true,
188
+ writable: true,
189
+ value: void 0
190
+ });
191
+ /** The seat (presence id) whose actions run. */
192
+ Object.defineProperty(this, "controller", {
193
+ enumerable: true,
194
+ configurable: true,
195
+ writable: true,
196
+ value: null
197
+ });
198
+ /** Set while a server agent holds the room. */
199
+ Object.defineProperty(this, "agent", {
200
+ enumerable: true,
201
+ configurable: true,
202
+ writable: true,
203
+ value: null
204
+ });
205
+ Object.defineProperty(this, "hooks", {
206
+ enumerable: true,
207
+ configurable: true,
208
+ writable: true,
209
+ value: void 0
210
+ });
211
+ Object.defineProperty(this, "pending", {
212
+ enumerable: true,
213
+ configurable: true,
214
+ writable: true,
215
+ value: new Map()
216
+ });
217
+ this.hooks = hooks;
218
+ this.enabledTools = new Set(state?.enabledTools?.length ? state.enabledTools : ALL_TOOLS);
219
+ this.web = WebRoom.fromParent(this, hooks.web ?? {}, state);
220
+ if (state?.bootstrap)
221
+ this.web.ingestBootstrap(state.bootstrap);
222
+ if (state?.cursor)
223
+ this.cursor = state.cursor;
224
+ this.applyControl(state?.control);
225
+ }
226
+ watch(hooks) {
227
+ this.hooks = { ...this.hooks, ...hooks };
228
+ if (hooks.web)
229
+ this.web.setHooks(hooks.web);
230
+ }
231
+ /** Whether your actions run: you control it and no agent holds it. */
232
+ controlling(self) {
233
+ return !this.agent && this.controller === self.id;
234
+ }
235
+ /** Hand control to a seat, or take it yourself without one. While an agent holds the room this stops the agent. */
236
+ setController(seat) {
237
+ const id = crypto.randomUUID();
238
+ return new Promise((resolve, reject) => {
239
+ const timer = setTimeout(() => {
240
+ this.pending.delete(id);
241
+ reject(new Error("Control timed out."));
242
+ }, 30000);
243
+ this.pending.set(id, {
244
+ resolve: (v) => { clearTimeout(timer); resolve(v); },
245
+ reject: (e) => { clearTimeout(timer); reject(e); },
246
+ });
247
+ this.post({ event: "control-call", data: { id, ...(seat ? { seat } : {}) } });
248
+ }).then(() => undefined);
249
+ }
250
+ /** Presence changed: tell whoever is watching now. */
251
+ emitPresence() {
252
+ this.hooks.onPresence?.(this);
253
+ }
254
+ emitClosed() {
255
+ this.hooks.onClosed?.(this);
256
+ }
257
+ applyControl(control) {
258
+ if (!control)
259
+ return;
260
+ this.controller = control.controller ?? null;
261
+ this.agent = control.agent ? RoomAgent.fromJSON(control.agent) : null;
262
+ }
263
+ invokeTool(tool) {
264
+ if (!this.enabledTools.has(tool.kind)) {
265
+ return Promise.reject(new Error(`Tool is not enabled: ${tool.kind}`));
266
+ }
267
+ const id = crypto.randomUUID();
268
+ return new Promise((resolve, reject) => {
269
+ const timer = setTimeout(() => {
270
+ this.pending.delete(id);
271
+ reject(new Error(`Tool timed out: ${tool.kind}`));
272
+ }, 30000);
273
+ this.pending.set(id, {
274
+ resolve: (v) => { clearTimeout(timer); resolve(v); },
275
+ reject: (e) => { clearTimeout(timer); reject(e); },
276
+ });
277
+ this.post({ event: "browser-tool-call", data: { id, tool } });
278
+ });
279
+ }
280
+ parrotTools() {
281
+ return parrotTools(this.enabledTools, (tool) => this.invokeTool(tool));
282
+ }
283
+ handleEvent(packet) {
284
+ if (packet.event === "browser-closed" || packet.event === "server-closed") {
285
+ this.web.handleEvent(packet);
286
+ this.hooks.onClosed?.(this);
287
+ return true;
288
+ }
289
+ if (this.web.handleEvent(packet))
290
+ return true;
291
+ switch (packet.event) {
292
+ case "room-control": {
293
+ this.applyControl(packet.data ?? {});
294
+ this.hooks.onControl?.(this);
295
+ return true;
296
+ }
297
+ case "control-result": {
298
+ const id = packet.data?.id;
299
+ const pending = id ? this.pending.get(id) : undefined;
300
+ if (!pending)
301
+ return true;
302
+ this.pending.delete(id);
303
+ if (packet.data?.error)
304
+ pending.reject(new Error(String(packet.data.error)));
305
+ else
306
+ pending.resolve("ok");
307
+ return true;
308
+ }
309
+ case "browser-cursor": {
310
+ if (packet.data?.cursor) {
311
+ this.cursor = packet.data.cursor;
312
+ this.hooks.onCursor?.(this, this.cursor);
313
+ }
314
+ return true;
315
+ }
316
+ case "browser-tool-call": {
317
+ if (packet.data?.tool)
318
+ this.hooks.onTool?.(this, packet.data.tool);
319
+ return true;
320
+ }
321
+ case "browser-tool-result": {
322
+ const id = packet.data?.id;
323
+ if (!id)
324
+ return true;
325
+ const pending = this.pending.get(id);
326
+ if (!pending)
327
+ return true;
328
+ this.pending.delete(id);
329
+ if (packet.data?.error)
330
+ pending.reject(new Error(String(packet.data.error)));
331
+ else
332
+ pending.resolve(String(packet.data?.result ?? ""));
333
+ return true;
334
+ }
335
+ default:
336
+ return false;
337
+ }
338
+ }
339
+ }
340
+ /** A live web page in a Marmot (or Ant) browser: every browser tool. */
341
+ export class BrowserRoom extends PageRoom {
342
+ static async connect(authorization, target, opts) {
343
+ return openBrowser(authorization, { server: target.reference, group: opts?.group?.id }, opts);
344
+ }
345
+ /** `endpoint` is where the page's room lives: Marmot's by default, or e.g. Ant's /timeline/browser/live. */
346
+ static async join(authorization, target, opts) {
347
+ return openBrowser(authorization, { accessCode: target.accessCode }, opts);
348
+ }
349
+ }
350
+ async function openBrowser(authorization, target, opts) {
351
+ const hooks = opts?.hooks ?? {};
352
+ const auth = "accessCode" in target
353
+ ? { authorization, accessCode: target.accessCode }
354
+ : { authorization, server: target.server, ...(target.group ? { group: target.group } : {}) };
355
+ const endpoint = opts?.endpoint ?? `${Marmot.getURL()}/browser/live`;
356
+ let room;
357
+ const notify = () => { if (room)
358
+ room.emitPresence(); };
359
+ const self = await connectServer(auth, endpoint, {
360
+ createRoom: (_endpoint, ws, a, id, state) => {
361
+ room = new BrowserRoom(ws, a, id, hooks, {
362
+ bootstrap: state?.bootstrap,
363
+ cursor: state?.cursor,
364
+ enabledTools: opts?.tools ?? state?.enabledTools,
365
+ control: state?.control,
366
+ }, endpoint);
367
+ return room;
368
+ },
369
+ createPresence: (r, data) => {
370
+ const presence = new Presence(r, data.id, data.profile);
371
+ presence.update(data);
372
+ return presence;
373
+ },
374
+ onPresence: notify,
375
+ onConnection: (r, state) => {
376
+ const next = r;
377
+ if (state?.bootstrap)
378
+ next.web.ingestBootstrap(state.bootstrap);
379
+ if (state?.cursor) {
380
+ next.cursor = state.cursor;
381
+ hooks.onCursor?.(next, next.cursor);
382
+ }
383
+ },
384
+ onEvent: (r, packet) => r.handleEvent(packet),
385
+ onClosed: (r) => r.emitClosed(),
386
+ });
387
+ notify();
388
+ return { room, self };
389
+ }
@@ -0,0 +1,20 @@
1
+ import * as MediaAPI from "./media.js";
2
+ import * as ResearchAPI from './research.js';
3
+ import * as WorkspaceAPI from './workspace.js';
4
+ import * as WebAPI from "./web.js";
5
+ import * as BrowserAPI from "./browser.js";
6
+ import * as ScraperAPI from "./scraper.js";
7
+ export declare namespace Marmot {
8
+ function setRoute(route: string): void;
9
+ function getIP(): string;
10
+ function getPort(): number;
11
+ function getRoute(): string;
12
+ function getURL(): string;
13
+ function ping(): Promise<number>;
14
+ export import Media = MediaAPI;
15
+ export import Research = ResearchAPI;
16
+ export import Workspace = WorkspaceAPI;
17
+ export import Web = WebAPI;
18
+ export import Browser = BrowserAPI;
19
+ export import Scraper = ScraperAPI;
20
+ }
@@ -0,0 +1,65 @@
1
+ import * as MediaAPI from "./media.js";
2
+ import * as ResearchAPI from './research.js';
3
+ import * as WorkspaceAPI from './workspace.js';
4
+ import * as WebAPI from "./web.js";
5
+ import * as BrowserAPI from "./browser.js";
6
+ import * as ScraperAPI from "./scraper.js";
7
+ export var Marmot;
8
+ (function (Marmot) {
9
+ var PREFIX = 'https://';
10
+ var IP = 'api.faunakit.com';
11
+ var PORT = 443;
12
+ function setRoute(route) {
13
+ const parts_0 = route.split('//');
14
+ if (parts_0.length > 1) {
15
+ PREFIX = parts_0[0] + '//';
16
+ const parts_1 = parts_0[1].split(':');
17
+ if (parts_1.length > 1) {
18
+ IP = parts_1[0];
19
+ PORT = Number(parts_1[1]);
20
+ }
21
+ else {
22
+ IP = parts_1[0];
23
+ }
24
+ }
25
+ else {
26
+ const parts_1 = parts_0[0].split(':');
27
+ if (parts_1.length > 1) {
28
+ IP = parts_1[0];
29
+ PORT = Number(parts_1[1]);
30
+ }
31
+ else {
32
+ IP = parts_1[0];
33
+ }
34
+ }
35
+ }
36
+ Marmot.setRoute = setRoute;
37
+ function getIP() {
38
+ return IP;
39
+ }
40
+ Marmot.getIP = getIP;
41
+ function getPort() {
42
+ return PORT;
43
+ }
44
+ Marmot.getPort = getPort;
45
+ function getRoute() {
46
+ return IP + ':' + PORT;
47
+ }
48
+ Marmot.getRoute = getRoute;
49
+ function getURL() {
50
+ return PREFIX + IP + ':' + PORT;
51
+ }
52
+ Marmot.getURL = getURL;
53
+ async function ping() {
54
+ const start = Date.now();
55
+ await fetch(`${getURL()}/`);
56
+ return Date.now() - start;
57
+ }
58
+ Marmot.ping = ping;
59
+ Marmot.Media = MediaAPI;
60
+ Marmot.Research = ResearchAPI;
61
+ Marmot.Workspace = WorkspaceAPI;
62
+ Marmot.Web = WebAPI;
63
+ Marmot.Browser = BrowserAPI;
64
+ Marmot.Scraper = ScraperAPI;
65
+ })(Marmot || (Marmot = {}));
@@ -0,0 +1,56 @@
1
+ import { ApiKey, Credentials } from "../authentification.js";
2
+ import { Part } from "../parrot/generative.js";
3
+ export declare const ATTACHMENT_TYPES: Record<string, string>;
4
+ /** Resolve a usable MIME when the browser leaves `File.type` empty (common for HEIC). */
5
+ export declare function mimeFromFileName(name: string): string | undefined;
6
+ export type Website = {
7
+ url: string;
8
+ contentType: string;
9
+ title: string;
10
+ description: string;
11
+ };
12
+ export type ProxyMode = 'residential' | 'datacenter';
13
+ export type DocumentMode = 'extraction' | 'render' | 'virtualized';
14
+ export type ContentTypeInfo = {
15
+ contentType: string;
16
+ name: string;
17
+ extensions: string[];
18
+ };
19
+ export declare function getTypes(): Promise<Record<string, ContentTypeInfo[]>>;
20
+ export type PullResponse = {
21
+ data: Uint8Array | Uint8Array[];
22
+ contentType: string;
23
+ };
24
+ export declare function query(authorization: Credentials | ApiKey, query: string, options: {
25
+ cursor: number;
26
+ max: number;
27
+ start?: Date;
28
+ end?: Date;
29
+ }): Promise<Website[]>;
30
+ export declare function pull(authorization: Credentials | ApiKey, url: string, request?: RequestInit, options?: Partial<{
31
+ modals: string[];
32
+ segment: [number, number];
33
+ split: number;
34
+ proxy: ProxyMode;
35
+ }>): Promise<PullResponse | undefined>;
36
+ /** A kind of file a text model reads itself. */
37
+ export type Input = 'image' | 'video' | 'audio';
38
+ /**
39
+ * A media file as message parts for a model that takes `takes` natively (images only
40
+ * by default). What it takes passes through; the rest becomes what it can take: a
41
+ * video becomes a line, its frames and its sound (audio, or a description of it),
42
+ * audio becomes a description, and documents become their text. With `split`, one
43
+ * list of parts per segment of that many milliseconds. Undefined when it can't be read.
44
+ */
45
+ export declare function chat(authorization: Credentials | ApiKey, contentType: string, data: Uint8Array, options?: Partial<{
46
+ name: string;
47
+ takes: Input[];
48
+ segment: [number, number];
49
+ split: number;
50
+ }>): Promise<Part[] | Part[][] | undefined>;
51
+ export declare function parse(authorization: Credentials | ApiKey, contentType: string, data: Uint8Array, onProgress?: (percent: number) => void): Promise<string>;
52
+ export declare function slice(authorization: Credentials | ApiKey, contentType: string, data: Uint8Array, options: Partial<{
53
+ segment: [number, number];
54
+ split: number;
55
+ }>): Promise<undefined | Uint8Array | Uint8Array[]>;
56
+ export declare function duration(authorization: Credentials | ApiKey, contentType: string, data: Uint8Array, onProgress?: (percent: number) => void): Promise<number>;