@intentic/machine 1.233.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 (131) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +72 -0
  3. package/dist/app.d.ts +2 -0
  4. package/dist/app.d.ts.map +1 -0
  5. package/dist/app.js +12 -0
  6. package/dist/app.js.map +1 -0
  7. package/dist/autostart.d.ts +3 -0
  8. package/dist/autostart.d.ts.map +1 -0
  9. package/dist/autostart.js +13 -0
  10. package/dist/autostart.js.map +1 -0
  11. package/dist/cli.d.ts +3 -0
  12. package/dist/cli.d.ts.map +1 -0
  13. package/dist/cli.js +5 -0
  14. package/dist/cli.js.map +1 -0
  15. package/dist/commands.d.ts +11 -0
  16. package/dist/commands.d.ts.map +1 -0
  17. package/dist/commands.js +91 -0
  18. package/dist/commands.js.map +1 -0
  19. package/dist/computer/audit.d.ts +6 -0
  20. package/dist/computer/audit.d.ts.map +1 -0
  21. package/dist/computer/audit.js +12 -0
  22. package/dist/computer/audit.js.map +1 -0
  23. package/dist/computer/commands.d.ts +8 -0
  24. package/dist/computer/commands.d.ts.map +1 -0
  25. package/dist/computer/commands.js +113 -0
  26. package/dist/computer/commands.js.map +1 -0
  27. package/dist/computer/config.d.ts +19 -0
  28. package/dist/computer/config.d.ts.map +1 -0
  29. package/dist/computer/config.js +31 -0
  30. package/dist/computer/config.js.map +1 -0
  31. package/dist/computer/connection.d.ts +8 -0
  32. package/dist/computer/connection.d.ts.map +1 -0
  33. package/dist/computer/connection.js +63 -0
  34. package/dist/computer/connection.js.map +1 -0
  35. package/dist/computer/mcp.d.ts +3 -0
  36. package/dist/computer/mcp.d.ts.map +1 -0
  37. package/dist/computer/mcp.js +312 -0
  38. package/dist/computer/mcp.js.map +1 -0
  39. package/dist/computer/policy.d.ts +8 -0
  40. package/dist/computer/policy.d.ts.map +1 -0
  41. package/dist/computer/policy.js +42 -0
  42. package/dist/computer/policy.js.map +1 -0
  43. package/dist/computer/router.d.ts +93 -0
  44. package/dist/computer/router.d.ts.map +1 -0
  45. package/dist/computer/router.js +79 -0
  46. package/dist/computer/router.js.map +1 -0
  47. package/dist/computer/tools/apps.d.ts +9 -0
  48. package/dist/computer/tools/apps.d.ts.map +1 -0
  49. package/dist/computer/tools/apps.js +41 -0
  50. package/dist/computer/tools/apps.js.map +1 -0
  51. package/dist/computer/tools/browser.d.ts +11 -0
  52. package/dist/computer/tools/browser.d.ts.map +1 -0
  53. package/dist/computer/tools/browser.js +63 -0
  54. package/dist/computer/tools/browser.js.map +1 -0
  55. package/dist/computer/tools/computer.d.ts +16 -0
  56. package/dist/computer/tools/computer.d.ts.map +1 -0
  57. package/dist/computer/tools/computer.js +80 -0
  58. package/dist/computer/tools/computer.js.map +1 -0
  59. package/dist/computer/tools/describe.d.ts +4 -0
  60. package/dist/computer/tools/describe.d.ts.map +1 -0
  61. package/dist/computer/tools/describe.js +37 -0
  62. package/dist/computer/tools/describe.js.map +1 -0
  63. package/dist/computer/tools/files.d.ts +12 -0
  64. package/dist/computer/tools/files.d.ts.map +1 -0
  65. package/dist/computer/tools/files.js +58 -0
  66. package/dist/computer/tools/files.js.map +1 -0
  67. package/dist/computer/tools/sandboxes.d.ts +45 -0
  68. package/dist/computer/tools/sandboxes.d.ts.map +1 -0
  69. package/dist/computer/tools/sandboxes.js +230 -0
  70. package/dist/computer/tools/sandboxes.js.map +1 -0
  71. package/dist/computer/tools/shell.d.ts +22 -0
  72. package/dist/computer/tools/shell.d.ts.map +1 -0
  73. package/dist/computer/tools/shell.js +78 -0
  74. package/dist/computer/tools/shell.js.map +1 -0
  75. package/dist/config.d.ts +4 -0
  76. package/dist/config.d.ts.map +1 -0
  77. package/dist/config.js +7 -0
  78. package/dist/config.js.map +1 -0
  79. package/dist/resident.d.ts +8 -0
  80. package/dist/resident.d.ts.map +1 -0
  81. package/dist/resident.js +92 -0
  82. package/dist/resident.js.map +1 -0
  83. package/dist/status.d.ts +21 -0
  84. package/dist/status.d.ts.map +1 -0
  85. package/dist/status.js +123 -0
  86. package/dist/status.js.map +1 -0
  87. package/dist/sync/commands.d.ts +20 -0
  88. package/dist/sync/commands.d.ts.map +1 -0
  89. package/dist/sync/commands.js +244 -0
  90. package/dist/sync/commands.js.map +1 -0
  91. package/dist/sync/config.d.ts +41 -0
  92. package/dist/sync/config.d.ts.map +1 -0
  93. package/dist/sync/config.js +35 -0
  94. package/dist/sync/config.js.map +1 -0
  95. package/dist/sync/exec.d.ts +10 -0
  96. package/dist/sync/exec.d.ts.map +1 -0
  97. package/dist/sync/exec.js +26 -0
  98. package/dist/sync/exec.js.map +1 -0
  99. package/dist/sync/git-bridge.d.ts +11 -0
  100. package/dist/sync/git-bridge.d.ts.map +1 -0
  101. package/dist/sync/git-bridge.js +122 -0
  102. package/dist/sync/git-bridge.js.map +1 -0
  103. package/dist/sync/mirror.d.ts +19 -0
  104. package/dist/sync/mirror.d.ts.map +1 -0
  105. package/dist/sync/mirror.js +310 -0
  106. package/dist/sync/mirror.js.map +1 -0
  107. package/dist/sync/mutagen.d.ts +68 -0
  108. package/dist/sync/mutagen.d.ts.map +1 -0
  109. package/dist/sync/mutagen.js +289 -0
  110. package/dist/sync/mutagen.js.map +1 -0
  111. package/dist/sync/report.d.ts +6 -0
  112. package/dist/sync/report.d.ts.map +1 -0
  113. package/dist/sync/report.js +66 -0
  114. package/dist/sync/report.js.map +1 -0
  115. package/dist/sync/ssh.d.ts +29 -0
  116. package/dist/sync/ssh.d.ts.map +1 -0
  117. package/dist/sync/ssh.js +165 -0
  118. package/dist/sync/ssh.js.map +1 -0
  119. package/dist/sync/tunnel.d.ts +22 -0
  120. package/dist/sync/tunnel.d.ts.map +1 -0
  121. package/dist/sync/tunnel.js +160 -0
  122. package/dist/sync/tunnel.js.map +1 -0
  123. package/dist/upgrade.d.ts +36 -0
  124. package/dist/upgrade.d.ts.map +1 -0
  125. package/dist/upgrade.js +95 -0
  126. package/dist/upgrade.js.map +1 -0
  127. package/dist/version.d.ts +2 -0
  128. package/dist/version.d.ts.map +1 -0
  129. package/dist/version.js +2 -0
  130. package/dist/version.js.map +1 -0
  131. package/package.json +49 -0
@@ -0,0 +1,312 @@
1
+ import { browser } from "@intentic/browser";
2
+ import { desktop, pngSize } from "@intentic/desktop";
3
+ import { MCP_PROTOCOL_VERSION } from "@intentic/sandbox-contract";
4
+ import { z } from "zod";
5
+ import { audit } from "./audit.js";
6
+ import { assertScope, ScopeError } from "./policy.js";
7
+ import { describeText } from "./tools/describe.js";
8
+ import { listDirectory, readTextFile, trashFile, writeTextFile } from "./tools/files.js";
9
+ import { focusWindow, listWindows, openTarget, readClipboard, writeClipboard } from "./tools/apps.js";
10
+ import { clickElement, fillElement, listTabs, openPage, pressKey, readPage, selectTab, snapshotPage } from "./tools/browser.js";
11
+ import { act, describeAction, settle } from "./tools/computer.js";
12
+ import { DEFAULT_LOG_LINES, listSandboxes, manageSandbox, MAX_LOG_LINES, removeSandbox, SandboxOpSchema, SandboxSwapSchema, sandboxLogs, swapSandbox, } from "./tools/sandboxes.js";
13
+ import { DEFAULT_TIMEOUT_MS, describeResult, MAX_TIMEOUT_MS, runCommand } from "./tools/shell.js";
14
+ import { MACHINE_VERSION } from "../version.js";
15
+ const textResult = (text, isError = false) => ({ content: [{ type: "text", text }], isError });
16
+ const tool = (spec) => {
17
+ const { $schema: _dialect, ...inputSchema } = z.toJSONSchema(spec.input, { io: "input" });
18
+ return {
19
+ name: spec.name,
20
+ description: spec.description,
21
+ inputSchema,
22
+ call: async (args, scopes) => {
23
+ const parsed = spec.input.safeParse(args);
24
+ return parsed.success ? await spec.run(parsed.data, scopes) : textResult(z.prettifyError(parsed.error), true);
25
+ },
26
+ };
27
+ };
28
+ const NO_ARGS = z.object({});
29
+ const screenshotResult = async (scopes) => {
30
+ assertScope(scopes, "screen");
31
+ const screen = desktop();
32
+ const png = await screen.capture();
33
+ const { width, height } = pngSize(png);
34
+ return {
35
+ content: [
36
+ { type: "text", text: `Screen is ${width}×${height}. Coordinates for the computer tool are pixels in this image.` },
37
+ { type: "image", data: png.toString("base64"), mimeType: "image/png" },
38
+ ],
39
+ isError: false,
40
+ };
41
+ };
42
+ let webHandle;
43
+ const web = () => (webHandle ??= browser());
44
+ const point = z.tuple([z.number(), z.number()]);
45
+ const required = z.string().min(1);
46
+ const TOOLS = [
47
+ tool({
48
+ name: "describe",
49
+ description: "What this computer is: OS and version, CPU architecture, the exact shell run_command uses, the home directory, the folders you may touch, and which permissions are on. Call this once before your first command here, it is the difference between writing for this machine and guessing.",
50
+ input: NO_ARGS,
51
+ run: async (_args, scopes) => textResult(await describeText(scopes)),
52
+ }),
53
+ tool({
54
+ name: "run_command",
55
+ description: "Run a command on this computer and get back its exit code, stdout and stderr. The shell is PowerShell on Windows and the user's login shell elsewhere (see describe). There is no terminal for anyone to type into: a command that prompts will fail rather than wait. Commands that DELETE (a recursive delete, a formatted disk, a removed Docker volume) need this computer's \"Run destructive commands\" switch, which is off unless its owner turned it on: they are refused with a message naming the switch, so ask the owner to turn it on rather than looking for a spelling that gets past it. Prefer one script that does the whole job over many small calls, every call is a network round trip to somebody's laptop.",
56
+ input: z.object({
57
+ command: required.describe("The command line to run, in this machine's shell."),
58
+ cwd: required.optional().describe("Working directory. Must be inside the allowed folders. Defaults to the first allowed folder."),
59
+ timeoutMs: z
60
+ .int()
61
+ .positive()
62
+ .max(MAX_TIMEOUT_MS)
63
+ .default(DEFAULT_TIMEOUT_MS)
64
+ .describe(`How long to wait before killing it. Default ${DEFAULT_TIMEOUT_MS}, maximum ${MAX_TIMEOUT_MS}.`),
65
+ }),
66
+ run: async ({ command, cwd, timeoutMs }, scopes) => {
67
+ const result = await runCommand({ command, ...(cwd === undefined ? {} : { cwd }), timeoutMs }, scopes);
68
+ return textResult(describeResult(result, timeoutMs));
69
+ },
70
+ }),
71
+ tool({
72
+ name: "read_file",
73
+ description: "Read a text file on this computer. Bounded by the folders this machine allows.",
74
+ input: z.object({ path: required }),
75
+ run: async ({ path }, scopes) => textResult(await readTextFile(path, scopes)),
76
+ }),
77
+ tool({
78
+ name: "write_file",
79
+ description: "Create a file or replace its contents. Requires the 'Create and change files' permission, which is OFF unless the user turned it on. Overwrites whole: read first if you mean to edit.",
80
+ input: z.object({ path: required, content: z.string() }),
81
+ run: async ({ path, content }, scopes) => textResult(await writeTextFile(path, content, scopes)),
82
+ }),
83
+ tool({
84
+ name: "list_dir",
85
+ description: "List a directory, with each entry's kind, size and modification time.",
86
+ input: z.object({ path: required }),
87
+ run: async ({ path }, scopes) => textResult(JSON.stringify(await listDirectory(path, scopes), undefined, 2)),
88
+ }),
89
+ tool({
90
+ name: "trash_file",
91
+ description: "Move a file into this agent's trash folder, from which the user can restore it. There is deliberately no permanent-delete tool. Requires the 'Create and change files' permission.",
92
+ input: z.object({ path: required }),
93
+ run: async ({ path }, scopes) => textResult(await trashFile(path, scopes)),
94
+ }),
95
+ tool({
96
+ name: "list_windows",
97
+ description: "Every window open on this computer: its app, title, size, position, and which one has focus. Call this before any GUI work, it is how you find the application you were asked about, and how you know where your typing will land. Requires the 'See the screen' permission.",
98
+ input: NO_ARGS,
99
+ run: async (_args, scopes) => textResult(await listWindows(desktop(), scopes)),
100
+ }),
101
+ tool({
102
+ name: "focus_window",
103
+ description: "Bring a window to the front and give it the keyboard, by the id from list_windows. ALWAYS do this before typing: text goes to whatever window has focus, not to where the pointer is. Requires the 'Use the mouse and keyboard' permission.",
104
+ input: z.object({ id: required }),
105
+ run: async ({ id }, scopes) => textResult(await focusWindow(desktop(), id, scopes)),
106
+ }),
107
+ tool({
108
+ name: "open",
109
+ description: "Start an application, or open a URL or file with whatever this computer has registered for it: the usual first step of a task ('open the browser at this page'). Use this rather than working out the platform's own incantation. Requires the 'Run commands' permission.",
110
+ input: z.object({ target: required.describe("An application name, a file path, or a URL.") }),
111
+ run: async ({ target }, scopes) => textResult(await openTarget(desktop(), target, scopes)),
112
+ }),
113
+ tool({
114
+ name: "clipboard",
115
+ description: "Read or replace this computer's clipboard: the reliable way to move text between applications, and often easier than reading it off a screenshot. Reading needs 'See the screen'; writing needs 'Use the mouse and keyboard'.",
116
+ input: z
117
+ .object({
118
+ action: z.enum(["read", "write"]),
119
+ text: z.string().min(1).optional().describe("The text to put on the clipboard (write)."),
120
+ })
121
+ .refine((args) => args.action !== "write" || args.text !== undefined, {
122
+ error: `"text" is what a write puts on the clipboard, a write without it would clear it, which read/write cannot express.`,
123
+ path: ["text"],
124
+ }),
125
+ run: async ({ action, text }, scopes) => action === "write" && text !== undefined
126
+ ? textResult(await writeClipboard(desktop(), text, scopes))
127
+ : textResult(await readClipboard(desktop(), scopes)),
128
+ }),
129
+ tool({
130
+ name: "browser_open",
131
+ description: "Open a page in a browser on this computer and answer with what is on it: the page's title, its URL, and every element you can click or type into, each with a reference like [e12]. THIS IS THE RIGHT WAY TO USE A WEBSITE, act on elements by reference, never by clicking pixels, because references survive scrolling, resizing and re-rendering. The browser is a separate instance with its own profile, so the user's own tabs and session are untouched; the first time it opens they may need to sign in. Requires the 'Run commands' permission.",
132
+ input: z.object({ url: required.describe("The page to open. A bare host like example.com is fine.") }),
133
+ run: async ({ url }, scopes) => textResult(await openPage(web(), url, scopes)),
134
+ }),
135
+ tool({
136
+ name: "browser_snapshot",
137
+ description: "What the current page shows right now, with fresh [e…] references. Take one after anything that might have changed the page: references from an older snapshot are refused rather than clicking the wrong thing. Requires the 'See the screen' permission.",
138
+ input: NO_ARGS,
139
+ run: async (_args, scopes) => textResult(await snapshotPage(web(), scopes)),
140
+ }),
141
+ tool({
142
+ name: "browser_read",
143
+ description: "The current page as readable text: what a person would get by selecting all of it. Use this to ANSWER QUESTIONS about a page; use browser_snapshot when you intend to act on it. Requires the 'See the screen' permission.",
144
+ input: NO_ARGS,
145
+ run: async (_args, scopes) => textResult(await readPage(web(), scopes)),
146
+ }),
147
+ tool({
148
+ name: "browser_click",
149
+ description: "Click an element by its [e…] reference from the last snapshot. Answers with the page as it stands afterwards, so you see the result without asking. Requires the 'Use the mouse and keyboard' permission.",
150
+ input: z.object({ ref: required }),
151
+ run: async ({ ref }, scopes) => textResult(await clickElement(web(), ref, scopes)),
152
+ }),
153
+ tool({
154
+ name: "browser_fill",
155
+ description: "Type into a field by its [e…] reference: replaces what is there, and fires the events a page's own JavaScript listens for (setting a value without them is how a filled form submits empty). Set submit to press Enter afterwards. Requires the 'Use the mouse and keyboard' permission.",
156
+ input: z.object({
157
+ ref: required,
158
+ text: z.string(),
159
+ submit: z.boolean().default(false).describe("Submit the form after typing. Default false."),
160
+ }),
161
+ run: async ({ ref, text, submit }, scopes) => textResult(await fillElement(web(), ref, text, submit, scopes)),
162
+ }),
163
+ tool({
164
+ name: "browser_key",
165
+ description: 'Press a key on the page as a whole: "Return", "Escape", "Tab". For typing into a field use browser_fill. Requires the \'Use the mouse and keyboard\' permission.',
166
+ input: z.object({ key: required }),
167
+ run: async ({ key }, scopes) => textResult(await pressKey(web(), key, scopes)),
168
+ }),
169
+ tool({
170
+ name: "browser_tabs",
171
+ description: "Every tab open in that browser, and which one these tools are acting on. Pass an id to `select` to switch. Reading the list needs 'See the screen'; switching needs 'Use the mouse and keyboard'.",
172
+ input: z.object({ select: required.optional().describe("The id of the tab to switch to. Omit to just list them.") }),
173
+ run: async ({ select }, scopes) => textResult(select === undefined ? await listTabs(web(), scopes) : await selectTab(web(), select, scopes)),
174
+ }),
175
+ tool({
176
+ name: "computer",
177
+ description: "Use this computer's mouse and keyboard: click what is on the screen, type into the focused window, press a key combination, scroll, drag. Coordinates are PIXELS IN THE LAST SCREENSHOT, take one first and read them off it. Every action answers with a fresh screenshot so you can see what happened. Requires the 'Use the mouse and keyboard' permission, which is OFF unless the user turned it on. Prefer a command over the GUI when both would work: a command is exact, and a click is a guess about where something is.",
178
+ input: z.object({
179
+ action: z.enum([
180
+ "mouse_move",
181
+ "left_click",
182
+ "right_click",
183
+ "middle_click",
184
+ "double_click",
185
+ "left_click_drag",
186
+ "type",
187
+ "key",
188
+ "scroll",
189
+ "wait",
190
+ ]),
191
+ coordinate: point.optional().describe("[x, y] in screenshot pixels, required for every pointer action."),
192
+ to: point.optional().describe("[x, y] the drag ends at (left_click_drag)."),
193
+ text: z.string().optional().describe('The text to type, or the key combination to press: "Return", "ctrl+c", "alt+Tab", "super+e".'),
194
+ direction: z.enum(["up", "down", "left", "right"]).optional().describe("Scroll direction. Default down."),
195
+ amount: z.number().optional().describe("Wheel notches to scroll. Default 3."),
196
+ ms: z.number().optional().describe('How long to wait (action "wait"). Default 400, maximum 10000.'),
197
+ }),
198
+ run: async (input, scopes) => {
199
+ await act(desktop(), input, scopes);
200
+ if (scopes.screen !== "on") {
201
+ return textResult(`${describeAction(input)} (No screenshot: "See the screen" is off for this computer.)`);
202
+ }
203
+ await settle();
204
+ const shot = await screenshotResult(scopes);
205
+ return { content: [{ type: "text", text: describeAction(input) }, ...shot["content"]], isError: false };
206
+ },
207
+ }),
208
+ tool({
209
+ name: "screenshot",
210
+ description: "Capture what is on this computer's screen right now, as an image. Use it to read a dialog, check on a window, or see what the user is describing. Requires the 'See the screen' permission.",
211
+ input: NO_ARGS,
212
+ run: async (_args, scopes) => await screenshotResult(scopes),
213
+ }),
214
+ tool({
215
+ name: "list_sandboxes",
216
+ description: "The Intentic sandboxes on this computer, as JSON: each one's slug, whether it is running, and whether its tunnel is up. Only sandbox containers; nothing else on the machine is listed. Requires 'Run commands' or 'Manage sandboxes on this computer'.",
217
+ input: NO_ARGS,
218
+ run: async (_args, scopes) => textResult(await listSandboxes(scopes)),
219
+ }),
220
+ tool({
221
+ name: "manage_sandbox",
222
+ description: "Start, stop or restart one Intentic sandbox on this computer, by its slug from list_sandboxes. Stopping one interrupts whoever is working in it, and stopping the sandbox you are calling from severs your own connection. Requires the 'Manage sandboxes on this computer' permission, which is OFF unless the user turned it on.",
223
+ input: z.object({ op: SandboxOpSchema, slug: required.describe("The sandbox's slug, from list_sandboxes.") }),
224
+ run: async ({ op, slug }, scopes) => textResult(await manageSandbox(op, slug, scopes)),
225
+ }),
226
+ tool({
227
+ name: "swap_sandbox",
228
+ description: "Move one Intentic sandbox on this computer onto a different image: 'update' pulls the newest image of its release channel, 'rollback' returns it to the image it ran before its last update, and 'rebuild' rebuilds the owner-approved environment overlay. Files (/work) and history are kept in all three. Takes MINUTES, it pulls an image and recreates the container, and the sandbox is down while it happens. 'prepare' is the exception and the one to reach for first: it does the downloading and building of the next update WITHOUT touching the container, so the sandbox keeps running throughout and the 'update' that follows is a restart of seconds instead of a wait of minutes. Requires the 'Manage sandboxes on this computer' permission.",
229
+ input: z.object({
230
+ op: SandboxSwapSchema,
231
+ slug: required.describe("The sandbox's slug, from list_sandboxes."),
232
+ hash: required.optional().describe("sha256 of the approved overlay, required for 'rebuild', ignored otherwise."),
233
+ }),
234
+ run: async ({ op, slug, hash }, scopes) => textResult(await swapSandbox(op, slug, hash, scopes, () => { })),
235
+ }),
236
+ tool({
237
+ name: "remove_sandbox",
238
+ description: "Delete one Intentic sandbox from this computer: its container, its network, and the volumes holding its files and its history. THIS CANNOT BE UNDONE and is not what stopping it does, confirm with the user before calling it. Requires the 'Remove sandboxes from this computer' permission, which is separate from managing them and OFF unless the user turned it on.",
239
+ input: z.object({ slug: required.describe("The sandbox's slug, from list_sandboxes.") }),
240
+ run: async ({ slug }, scopes) => textResult(await removeSandbox(slug, scopes, () => { })),
241
+ }),
242
+ tool({
243
+ name: "sandbox_logs",
244
+ description: "The tail of one Intentic sandbox's container log on this computer: how you find out why it will not start or what it did before it stopped. Requires 'Run commands' or 'Manage sandboxes on this computer'.",
245
+ input: z.object({
246
+ slug: required.describe("The sandbox's slug, from list_sandboxes."),
247
+ lines: z
248
+ .int()
249
+ .positive()
250
+ .max(MAX_LOG_LINES)
251
+ .optional()
252
+ .describe(`How many trailing lines to answer with. Default ${DEFAULT_LOG_LINES}, maximum ${MAX_LOG_LINES}.`),
253
+ }),
254
+ run: async ({ slug, lines }, scopes) => textResult(await sandboxLogs(slug, lines, scopes)),
255
+ }),
256
+ ];
257
+ const BY_NAME = new Map(TOOLS.map((entry) => [entry.name, entry]));
258
+ const auditDetail = (name, args) => {
259
+ const redact = (name === "computer" && args["action"] === "type") || (name === "clipboard" && args["action"] === "write") || name === "browser_fill";
260
+ const safe = redact ? { ...args, text: `<${String(args["text"] ?? "").length} characters>` } : args;
261
+ return JSON.stringify(safe).slice(0, 500);
262
+ };
263
+ const isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
264
+ export const handleMcpMessage = async (message, scopes) => {
265
+ if (!isRecord(message)) {
266
+ return { jsonrpc: "2.0", id: null, error: { code: -32600, message: "invalid request" } };
267
+ }
268
+ const id = message["id"];
269
+ const method = message["method"];
270
+ if (id === undefined) {
271
+ return undefined;
272
+ }
273
+ const reply = (result) => ({ jsonrpc: "2.0", id, result });
274
+ if (method === "initialize") {
275
+ return reply({
276
+ protocolVersion: MCP_PROTOCOL_VERSION,
277
+ capabilities: { tools: {} },
278
+ serverInfo: { name: "intentic-machine", version: MACHINE_VERSION },
279
+ });
280
+ }
281
+ if (method === "ping") {
282
+ return reply({});
283
+ }
284
+ if (method === "tools/list") {
285
+ return reply({ tools: TOOLS.map(({ name, description, inputSchema }) => ({ name, description, inputSchema })) });
286
+ }
287
+ if (method === "tools/call") {
288
+ const params = isRecord(message["params"]) ? message["params"] : {};
289
+ const name = typeof params["name"] === "string" ? params["name"] : "";
290
+ const args = isRecord(params["arguments"]) ? params["arguments"] : {};
291
+ const found = BY_NAME.get(name);
292
+ if (found === undefined) {
293
+ return reply(textResult(`This computer has no tool called "${name}".`, true));
294
+ }
295
+ try {
296
+ const result = await found.call(args, scopes());
297
+ void audit({ tool: name, ok: result["isError"] !== true, detail: auditDetail(name, args) });
298
+ return reply(result);
299
+ }
300
+ catch (error) {
301
+ const refused = error instanceof ScopeError;
302
+ void audit({
303
+ tool: name,
304
+ ok: false,
305
+ detail: `${refused ? "refused" : "failed"}: ${error instanceof Error ? error.message : String(error)}`,
306
+ });
307
+ return reply(textResult(error instanceof Error ? error.message : String(error), true));
308
+ }
309
+ }
310
+ return { jsonrpc: "2.0", id, error: { code: -32601, message: `method "${String(method)}" is not supported` } };
311
+ };
312
+ //# sourceMappingURL=mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/computer/mcp.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAmB,oBAAoB,EAAE,MAAM,4BAA4B,CAAC;AACnF,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AACnC,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,YAAY,EAAE,SAAS,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAC;AACzF,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACtG,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,QAAQ,EAAE,SAAS,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAChI,OAAO,EAAE,GAAG,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAClE,OAAO,EACH,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,aAAa,EACb,aAAa,EACb,eAAe,EACf,iBAAiB,EACjB,WAAW,EACX,WAAW,GACd,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAE,kBAAkB,EAAE,cAAc,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAClG,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,C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{ HostScopes } from "@intentic/sandbox-contract";
2
+ export declare class ScopeError extends Error {
3
+ }
4
+ export declare const rootsOf: (scopes: HostScopes) => string[];
5
+ export declare const withinRoots: (path: string, roots: readonly string[]) => boolean;
6
+ export declare const assertPath: (path: string, scopes: HostScopes, intent: string) => string;
7
+ export declare const assertScope: (scopes: HostScopes, scope: "shell" | "write" | "screen" | "control" | "sandboxes" | "sandboxRemove" | "destructive") => void;
8
+ //# sourceMappingURL=policy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.d.ts","sourceRoot":"","sources":["../../src/computer/policy.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAa7D,qBAAa,UAAW,SAAQ,KAAK;CAAG;AAIxC,eAAO,MAAM,OAAO,WAAY,UAAU,KAAG,MAAM,EAUlD,CAAC;AAOF,eAAO,MAAM,WAAW,SAAU,MAAM,SAAS,SAAS,MAAM,EAAE,KAAG,OAGpE,CAAC;AAIF,eAAO,MAAM,UAAU,SAAU,MAAM,UAAU,UAAU,UAAU,MAAM,KAAG,MAS7E,CAAC;AAIF,eAAO,MAAM,WAAW,WACZ,UAAU,SACX,OAAO,GAAG,OAAO,GAAG,QAAQ,GAAG,SAAS,GAAG,WAAW,GAAG,eAAe,GAAG,aAAa,KAChG,IAcF,CAAC"}
@@ -0,0 +1,42 @@
1
+ import { homedir } from "node:os";
2
+ import { isAbsolute, join, resolve, sep } from "node:path";
3
+ export class ScopeError extends Error {
4
+ }
5
+ export const rootsOf = (scopes) => {
6
+ const declared = (scopes.roots ?? "")
7
+ .split(/\r?\n/)
8
+ .map((line) => line.trim())
9
+ .filter((line) => line !== "")
10
+ .map((line) => (line.startsWith("~") ? join(homedir(), line.slice(1)) : line))
11
+ .filter((line) => isAbsolute(line))
12
+ .map((line) => resolve(line));
13
+ return declared.length > 0 ? declared : [resolve(homedir())];
14
+ };
15
+ export const withinRoots = (path, roots) => {
16
+ const target = resolve(path);
17
+ return roots.some((root) => target === root || target.startsWith(root.endsWith(sep) ? root : `${root}${sep}`));
18
+ };
19
+ export const assertPath = (path, scopes, intent) => {
20
+ const roots = rootsOf(scopes);
21
+ if (!withinRoots(path, roots)) {
22
+ throw new ScopeError(`Refused to ${intent} "${path}": it is outside the folders this computer allows (${roots.join(", ")}). ` +
23
+ `Widen "Folders it may touch" on this computer's capability card to change that.`);
24
+ }
25
+ return resolve(path);
26
+ };
27
+ export const assertScope = (scopes, scope) => {
28
+ if (scopes[scope] === "on") {
29
+ return;
30
+ }
31
+ const label = {
32
+ shell: "Run commands",
33
+ write: "Create and change files",
34
+ screen: "See the screen",
35
+ control: "Use the mouse and keyboard",
36
+ sandboxes: "Manage sandboxes on this computer",
37
+ sandboxRemove: "Remove sandboxes from this computer",
38
+ destructive: "Run destructive commands",
39
+ }[scope];
40
+ throw new ScopeError(`Refused: "${label}" is switched off for this computer. Turn it on in its capability card to allow this.`);
41
+ };
42
+ //# sourceMappingURL=policy.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"policy.js","sourceRoot":"","sources":["../../src/computer/policy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,WAAW,CAAC;AAc3D,MAAM,OAAO,UAAW,SAAQ,KAAK;CAAG;AAIxC,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,MAAkB,EAAY,EAAE;IACpD,MAAM,QAAQ,GAAG,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC;SAChC,KAAK,CAAC,OAAO,CAAC;SACd,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;SAC1B,MAAM,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,EAAE,CAAC;SAE7B,GAAG,CAAC,CAAC,IAAI,EAAE,E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AC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC;AACzB,CAAC,CAAC;AAIF,MAAM,CAAC,MAAM,WAAW,GAAG,CACvB,MAAkB,EAClB,KAA+F,EAC3F,EAAE;IACN,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC;QACzB,OAAO;IACX,CAAC;IACD,MAAM,KAAK,GAAG;QACV,KAAK,EAAE,cAAc;QACrB,KAAK,EAAE,yBAAyB;QAChC,MAAM,EAAE,gBAAgB;QACxB,OAAO,EAAE,4BAA4B;QACrC,SAAS,EAAE,mCAAmC;QAC9C,aAAa,EAAE,qCAAqC;QACpD,WAAW,EAAE,0BAA0B;KAC1C,CAAC,KAAK,CAAC,CAAC;IACT,MAAM,IAAI,UAAU,CAAC,aAAa,KAAK,uFAAuF,CAAC,CAAC;AACpI,CAAC,CAAC"}
@@ -0,0 +1,93 @@
1
+ import { type HostScopes } from "@intentic/sandbox-contract";
2
+ export interface HostRuntime {
3
+ readonly scopes: () => HostScopes;
4
+ readonly setScopes: (scopes: HostScopes) => void;
5
+ readonly log: (message: string) => void;
6
+ }
7
+ export declare const createHostRouter: (runtime: HostRuntime) => {
8
+ describe: import("@orpc/server").Procedure<import("@orpc/server").MergedInitialContext<Record<never, never>, Record<never, never>, Record<never, never>>, Record<never, never>, import("@orpc/server").Schema<unknown, unknown>, import("zod").ZodObject<{
9
+ os: import("zod").ZodString;
10
+ arch: import("zod").ZodString;
11
+ shell: import("zod").ZodString;
12
+ home: import("zod").ZodString;
13
+ roots: import("zod").ZodArray<import("zod").ZodString>;
14
+ }, import("zod/v4/core").$strip>, import("@orpc/server").MergedErrorMap<Record<never, never>, Record<never, never>>, Record<never, never>>;
15
+ setScopes: import("@orpc/server").Procedure<import("@orpc/server").MergedInitialContext<Record<never, never>, Record<never, never>, Record<never, never>>, Record<never, never>, import("zod").ZodObject<{
16
+ shell: import("zod").ZodDefault<import("zod").ZodEnum<{
17
+ off: "off";
18
+ on: "on";
19
+ }>>;
20
+ write: import("zod").ZodDefault<import("zod").ZodEnum<{
21
+ off: "off";
22
+ on: "on";
23
+ }>>;
24
+ screen: import("zod").ZodDefault<import("zod").ZodEnum<{
25
+ off: "off";
26
+ on: "on";
27
+ }>>;
28
+ control: import("zod").ZodDefault<import("zod").ZodEnum<{
29
+ off: "off";
30
+ on: "on";
31
+ }>>;
32
+ sandboxes: import("zod").ZodDefault<import("zod").ZodEnum<{
33
+ off: "off";
34
+ on: "on";
35
+ }>>;
36
+ sandboxRemove: import("zod").ZodDefault<import("zod").ZodEnum<{
37
+ off: "off";
38
+ on: "on";
39
+ }>>;
40
+ destructive: import("zod").ZodDefault<import("zod").ZodEnum<{
41
+ off: "off";
42
+ on: "on";
43
+ }>>;
44
+ roots: import("zod").ZodOptional<import("zod").ZodString>;
45
+ }, import("zod/v4/core").$strip>, import("zod").ZodObject<{
46
+ ok: import("zod").ZodLiteral<true>;
47
+ }, import("zod/v4/core").$strip>, import("@orpc/server").MergedErrorMap<Record<never, never>, Record<never, never>>, Record<never, never>>;
48
+ ping: import("@orpc/server").Procedure<import("@orpc/server").MergedInitialContext<Record<never, never>, Record<never, never>, Record<never, never>>, Record<never, never>, import("@orpc/server").Schema<unknown, unknown>, import("zod").ZodObject<{
49
+ ok: import("zod").ZodLiteral<true>;
50
+ }, import("zod/v4/core").$strip>, import("@orpc/server").MergedErrorMap<Record<never, never>, Record<never, never>>, Record<never, never>>;
51
+ mcp: import("@orpc/server").Procedure<import("@orpc/server").MergedInitialContext<Record<never, never>, Record<never, never>, Record<never, never>>, Record<never, never>, import("zod").ZodUnknown, import("zod").ZodUnknown, import("@orpc/server").MergedErrorMap<Record<never, never>, Record<never, never>>, Record<never, never>>;
52
+ runSandboxFlow: import("@orpc/server").Procedure<import("@orpc/server").MergedInitialContext<Record<never, never>, Record<never, never>, Record<never, never>>, Record<never, never>, import("zod").ZodObject<{
53
+ op: import("zod").ZodEnum<{
54
+ logs: "logs";
55
+ prepare: "prepare";
56
+ rebuild: "rebuild";
57
+ remove: "remove";
58
+ restart: "restart";
59
+ rollback: "rollback";
60
+ "runner-remove": "runner-remove";
61
+ "runner-up": "runner-up";
62
+ start: "start";
63
+ stop: "stop";
64
+ update: "update";
65
+ }>;
66
+ slug: import("zod").ZodString;
67
+ hash: import("zod").ZodOptional<import("zod").ZodString>;
68
+ parentUrl: import("zod").ZodOptional<import("zod").ZodString>;
69
+ pair: import("zod").ZodOptional<import("zod").ZodString>;
70
+ definition: import("zod").ZodOptional<import("zod").ZodString>;
71
+ overlay: import("zod").ZodOptional<import("zod").ZodString>;
72
+ overlayHash: import("zod").ZodOptional<import("zod").ZodString>;
73
+ }, import("zod/v4/core").$strip>, import("@orpc/server").Schema<AsyncIteratorObject<{
74
+ kind: "line";
75
+ text: string;
76
+ } | {
77
+ kind: "result";
78
+ message: string;
79
+ } | {
80
+ kind: "error";
81
+ message: string;
82
+ }, unknown, void>, import("@orpc/server").AsyncIteratorClass<{
83
+ kind: "line";
84
+ text: string;
85
+ } | {
86
+ kind: "result";
87
+ message: string;
88
+ } | {
89
+ kind: "error";
90
+ message: string;
91
+ }, unknown, void>>, import("@orpc/server").MergedErrorMap<Record<never, never>, Record<never, never>>, Record<never, never>>;
92
+ };
93
+ //# sourceMappingURL=router.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.d.ts","sourceRoot":"","sources":["../../src/computer/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,UAAU,EAA+D,MAAM,4BAA4B,CAAC;AAe1H,MAAM,WAAW,WAAW;IACxB,QAAQ,CAAC,MAAM,EAAE,MAAM,UAAU,CAAC;IAClC,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,CAAC;IACjD,QAAQ,CAAC,GAAG,EAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAI,CAAC;CAC3C;AA2FD,eAAO,MAAM,gBAAgB,YAAa,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAoBpD,CAAC"}
@@ -0,0 +1,79 @@
1
+ import { hostContract } from "@intentic/sandbox-contract";
2
+ import { implement } from "@orpc/server";
3
+ import { handleMcpMessage } from "./mcp.js";
4
+ import { hostFacts } from "./tools/describe.js";
5
+ import { manageSandbox, removeSandbox, runnerFlow, swapSandbox, tailSandboxLogs } from "./tools/sandboxes.js";
6
+ async function* streamFlow(run) {
7
+ const queued = [];
8
+ let wake;
9
+ const nudge = () => {
10
+ const pending = wake;
11
+ wake = undefined;
12
+ pending?.();
13
+ };
14
+ let settled;
15
+ const finished = run((line) => {
16
+ queued.push(line);
17
+ nudge();
18
+ })
19
+ .then((message) => ({ ok: true, message }))
20
+ .catch((error) => ({ ok: false, message: error instanceof Error ? error.message : String(error) }))
21
+ .then((outcome) => {
22
+ settled = outcome;
23
+ nudge();
24
+ });
25
+ for (;;) {
26
+ const next = queued.shift();
27
+ if (next !== undefined) {
28
+ yield { kind: "line", text: next };
29
+ continue;
30
+ }
31
+ if (settled !== undefined) {
32
+ break;
33
+ }
34
+ await new Promise((resolve) => {
35
+ wake = resolve;
36
+ });
37
+ }
38
+ await finished;
39
+ yield settled?.ok === true
40
+ ? { kind: "result", message: settled.message }
41
+ : { kind: "error", message: settled?.message ?? "The operation stopped without saying why." };
42
+ }
43
+ const flowFor = ({ op, slug, hash, parentUrl, pair, definition, overlay, overlayHash }, scopes) => {
44
+ switch (op) {
45
+ case "remove":
46
+ return (onLine) => removeSandbox(slug, scopes, onLine);
47
+ case "runner-up":
48
+ case "runner-remove":
49
+ return (onLine) => runnerFlow(op, slug, parentUrl, pair, {
50
+ ...(definition !== undefined ? { definition } : {}),
51
+ ...(overlay !== undefined ? { overlay } : {}),
52
+ ...(overlayHash !== undefined ? { overlayHash } : {}),
53
+ }, scopes, onLine);
54
+ case "logs":
55
+ return (onLine) => tailSandboxLogs(slug, scopes, onLine);
56
+ case "prepare":
57
+ case "update":
58
+ case "rebuild":
59
+ case "rollback":
60
+ return (onLine) => swapSandbox(op, slug, hash, scopes, onLine);
61
+ default:
62
+ return async () => await manageSandbox(op, slug, scopes);
63
+ }
64
+ };
65
+ export const createHostRouter = (runtime) => {
66
+ const os = implement(hostContract);
67
+ return os.router({
68
+ describe: os.describe.handler(async () => await hostFacts(runtime.scopes())),
69
+ setScopes: os.setScopes.handler(({ input }) => {
70
+ runtime.setScopes(input);
71
+ runtime.log(`permissions updated: commands ${input.shell}, writes ${input.write}, screen ${input.screen}`);
72
+ return { ok: true };
73
+ }),
74
+ ping: os.ping.handler(() => ({ ok: true })),
75
+ mcp: os.mcp.handler(async ({ input }) => await handleMcpMessage(input, runtime.scopes)),
76
+ runSandboxFlow: os.runSandboxFlow.handler(({ input }) => streamFlow(flowFor(input, runtime.scopes()))),
77
+ });
78
+ };
79
+ //# sourceMappingURL=router.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"router.js","sourceRoot":"","sources":["../../src/computer/router.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkE,YAAY,EAAE,MAAM,4BAA4B,CAAC;AAC1H,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,gBAAgB,EAAE,MAAM,UAAU,CAAC;AAC5C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA0B9G,KAAK,SAAS,CAAC,CAAC,UAAU,CAAC,GAAwD;IAC/E,MAAM,MAAM,GAAa,EAAE,CAAC;IAC5B,IAAI,IAA8B,CAAC;IACnC,MAAM,KAAK,GAAG,GAAS,EAAE;QACrB,MAAM,OAAO,GAAG,IAAI,CAAC;QACrB,IAAI,GAAG,SAAS,CAAC;QACjB,OAAO,EAAE,EAAE,CAAC;IAChB,CAAC,CAAC;IACF,IA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HostScopes } from "@intentic/sandbox-contract";
3
+ export declare const describeWindows: (windows: readonly WindowInfo[]) => string;
4
+ export declare const listWindows: (screen: Desktop, scopes: HostScopes) => Promise<string>;
5
+ export declare const focusWindow: (screen: Desktop, id: string, scopes: HostScopes) => Promise<string>;
6
+ export declare const openTarget: (screen: Desktop, target: string, scopes: HostScopes) => Promise<string>;
7
+ export declare const readClipboard: (screen: Desktop, scopes: HostScopes) => Promise<string>;
8
+ export declare const writeClipboard: (screen: Desktop, text: string, scopes: HostScopes) => Promise<string>;
9
+ //# sourceMappingURL=apps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"apps.d.ts","sourceRoot":"","sources":["../../../src/computer/tools/apps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,OAAO,EAAgB,KAAK,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAChF,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAC;AAmB7D,eAAO,MAAM,eAAe,YAAa,SAAS,UAAU,EAAE,KAAG,MAShE,CAAC;AAEF,eAAO,MAAM,WAAW,WAAkB,OAAO,UAAU,UAAU,KAAG,OAAO,CAAC,MAAM,CAGrF,CAAC;AAKF,eAAO,MAAM,WAAW,WAAkB,OAAO,MAAM,MAAM,UAAU,UAAU,KAAG,OAAO,CAAC,MAAM,CAQjG,CAAC;AAEF,eAAO,MAAM,UAAU,WAAkB,OAAO,UAAU,MAAM,UAAU,UAAU,KAAG,OAAO,CAAC,MAAM,CAQpG,CAAC;AAIF,eAAO,MAAM,aAAa,WAAkB,OAAO,UAAU,UAAU,KAAG,OAAO,CAAC,MAAM,CAIvF,CAAC;AAEF,eAAO,MAAM,cAAc,WAAkB,OAAO,QAAQ,MAAM,UAAU,UAAU,KAAG,OAAO,CAAC,MAAM,CAItG,CAAC"}