@ant0/mcp 0.0.0-stage → 0.3.22-beta.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +28 -0
- package/README.md +95 -2
- package/THIRD_PARTY_NOTICES +311 -0
- package/dist/api/generated/schema.d.ts +7340 -0
- package/dist/api/generated/schema.js +6 -0
- package/dist/api/index.d.ts +171 -0
- package/dist/api/index.js +332 -0
- package/dist/bin.d.ts +3 -0
- package/dist/bin.js +59 -0
- package/dist/call-permits.d.ts +10 -0
- package/dist/call-permits.js +67 -0
- package/dist/connection.d.ts +20 -0
- package/dist/connection.js +157 -0
- package/dist/credential-file.d.ts +33 -0
- package/dist/credential-file.js +773 -0
- package/dist/daemon.d.ts +7 -0
- package/dist/daemon.js +306 -0
- package/dist/errors.d.ts +92 -0
- package/dist/errors.js +101 -0
- package/dist/export-files.d.ts +37 -0
- package/dist/export-files.js +167 -0
- package/dist/grant.d.ts +5 -0
- package/dist/grant.js +11 -0
- package/dist/http-local.d.ts +38 -0
- package/dist/http-local.js +324 -0
- package/dist/http.d.ts +66 -0
- package/dist/http.js +556 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +86 -0
- package/dist/key-contract.d.ts +325 -0
- package/dist/key-contract.js +241 -0
- package/dist/limits.d.ts +22 -0
- package/dist/limits.js +22 -0
- package/dist/local-routes.d.ts +30 -0
- package/dist/local-routes.js +231 -0
- package/dist/output-descriptor.d.ts +3 -0
- package/dist/output-descriptor.js +19 -0
- package/dist/output-worker-body.d.ts +3 -0
- package/dist/output-worker-body.js +77 -0
- package/dist/output-worker.d.ts +2 -0
- package/dist/output-worker.js +4 -0
- package/dist/output-writer.d.ts +39 -0
- package/dist/output-writer.js +199 -0
- package/dist/peer-watchdog.d.ts +4 -0
- package/dist/peer-watchdog.js +55 -0
- package/dist/server.d.ts +28 -0
- package/dist/server.js +33 -0
- package/dist/text-budget.d.ts +13 -0
- package/dist/text-budget.js +42 -0
- package/dist/tools.d.ts +39 -0
- package/dist/tools.js +1893 -0
- package/dist/transport.d.ts +45 -0
- package/dist/transport.js +313 -0
- package/package.json +66 -4
package/dist/daemon.d.ts
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type Ant0Client } from "./api/index.js";
|
|
2
|
+
import { type Connection } from "./connection.js";
|
|
3
|
+
/** Long launches get only their requested daemon timeout plus a ten-second transport margin. */
|
|
4
|
+
export declare function requestTimeoutMs(method: string, path: string, body: string): number;
|
|
5
|
+
/** Typed API client with a direct, non-proxying HTTP transport and no redirects or retries. */
|
|
6
|
+
export declare function daemonClient(connection: Connection, lifetime: AbortSignal, consumer?: "api" | "mcp"): Ant0Client;
|
|
7
|
+
//# sourceMappingURL=daemon.d.ts.map
|
package/dist/daemon.js
ADDED
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
import { createAnt0Client } from "./api/index.js";
|
|
2
|
+
import { request } from "node:http";
|
|
3
|
+
import { keyMode } from "./connection.js";
|
|
4
|
+
import { McpFailure } from "./errors.js";
|
|
5
|
+
import { LIMITS } from "./limits.js";
|
|
6
|
+
import { assertCredentialUnchangedAsync } from "./credential-file.js";
|
|
7
|
+
import { localRequestAllowed, mapDaemonError, matchLocalRoute } from "./local-routes.js";
|
|
8
|
+
// Profile path segments: the run, stop and status tools and the CLI pass a UUID or an exact name.
|
|
9
|
+
const UUID = "[0-9a-f-]{36}";
|
|
10
|
+
const PROFILE_REF = "[^/]+";
|
|
11
|
+
const LOCAL_READ_PATH = new RegExp(`^/v1/(health|licence|automation/status|profiles/${UUID}|inventory/(?:proxies|profiles(?:/${PROFILE_REF})?))$`);
|
|
12
|
+
/** Unchanged v0.25 delegated inventory reads. */
|
|
13
|
+
const KEY_READ_PATH = new RegExp(`^/v1/(automation/status|inventory/(?:proxies|profiles(?:/${PROFILE_REF})?))$`);
|
|
14
|
+
/** The CLI additionally inspects the endpoint-free lifecycle of a run it could not confirm. */
|
|
15
|
+
const CLI_READ_PATH = new RegExp(`^/v1/(automation/status|inventory/(?:proxies|profiles(?:/${PROFILE_REF})?)|profiles/${PROFILE_REF}/run)$`);
|
|
16
|
+
/** §17.4 operations. MCP drives one saved profile; CDP start and bulk stay explicit CLI actions. */
|
|
17
|
+
const MCP_OPERATION_PATH = new RegExp(`^/v1/profiles/${PROFILE_REF}/(?:run|stop)$`);
|
|
18
|
+
const CLI_OPERATION_PATH = new RegExp(`^/v1/profiles/(?:${PROFILE_REF}/(?:run|start|stop)|bulk-(?:start|stop))$`);
|
|
19
|
+
/** Only the daemon's error code is read from a name-resolution conflict; nothing else crosses. */
|
|
20
|
+
function isAmbiguousName(body) {
|
|
21
|
+
try {
|
|
22
|
+
const parsed = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(body));
|
|
23
|
+
return (parsed !== null &&
|
|
24
|
+
typeof parsed === "object" &&
|
|
25
|
+
parsed.error === "profile.ambiguous_name");
|
|
26
|
+
}
|
|
27
|
+
catch {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
function parsedBody(text) {
|
|
32
|
+
try {
|
|
33
|
+
const value = JSON.parse(text);
|
|
34
|
+
return value !== null && typeof value === "object" && !Array.isArray(value)
|
|
35
|
+
? value
|
|
36
|
+
: undefined;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return undefined;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** Long launches get only their requested daemon timeout plus a ten-second transport margin. */
|
|
43
|
+
export function requestTimeoutMs(method, path, body) {
|
|
44
|
+
if (method !== "POST")
|
|
45
|
+
return LIMITS.httpMs;
|
|
46
|
+
const value = parsedBody(body);
|
|
47
|
+
const ids = value?.ids;
|
|
48
|
+
if (/\/bulk-(?:start|stop)$/.test(path)) {
|
|
49
|
+
return Array.isArray(ids) && ids.length >= 1 && ids.length <= 50
|
|
50
|
+
? ids.length * 60_000 + 10_000
|
|
51
|
+
: LIMITS.httpMs;
|
|
52
|
+
}
|
|
53
|
+
if (/\/(?:run|start)$/.test(path)) {
|
|
54
|
+
const requested = value?.timeout_s;
|
|
55
|
+
const seconds = requested === undefined
|
|
56
|
+
? 60
|
|
57
|
+
: typeof requested === "number" &&
|
|
58
|
+
Number.isInteger(requested) &&
|
|
59
|
+
requested >= 1 &&
|
|
60
|
+
requested <= 600
|
|
61
|
+
? requested
|
|
62
|
+
: 0;
|
|
63
|
+
return seconds === 0 ? LIMITS.httpMs : seconds * 1_000 + 10_000;
|
|
64
|
+
}
|
|
65
|
+
if (/^\/v1\/(?:profiles\/[^/]+\/human|human\/[^/]+\/wait)$/.test(path)) {
|
|
66
|
+
// A hand-off hold: the daemon waits wait_s (default 40, at most 50), then answers.
|
|
67
|
+
const wait = value?.wait_s;
|
|
68
|
+
const seconds = wait === undefined
|
|
69
|
+
? 40
|
|
70
|
+
: typeof wait === "number" && Number.isInteger(wait) && wait >= 1 && wait <= 50
|
|
71
|
+
? wait
|
|
72
|
+
: 0;
|
|
73
|
+
return seconds === 0 ? LIMITS.httpMs : seconds * 1_000 + 10_000;
|
|
74
|
+
}
|
|
75
|
+
return 70_000;
|
|
76
|
+
}
|
|
77
|
+
/** Typed API client with a direct, non-proxying HTTP transport and no redirects or retries. */
|
|
78
|
+
export function daemonClient(connection, lifetime, consumer = "mcp") {
|
|
79
|
+
const boundedFetch = async (input) => {
|
|
80
|
+
if (!(input instanceof Request))
|
|
81
|
+
throw new McpFailure("internal");
|
|
82
|
+
const url = new URL(input.url);
|
|
83
|
+
const method = input.method;
|
|
84
|
+
// Local-bearer-only routes (identity tools). Key-mode connections never consult this table,
|
|
85
|
+
// so their allowlists below are unchanged.
|
|
86
|
+
const local = consumer === "mcp" && !keyMode(connection)
|
|
87
|
+
? matchLocalRoute(method, url.pathname)
|
|
88
|
+
: undefined;
|
|
89
|
+
const body = method === "POST" || (local !== undefined && method === "PATCH")
|
|
90
|
+
? Buffer.from(await input.clone().arrayBuffer())
|
|
91
|
+
: Buffer.alloc(0);
|
|
92
|
+
if (body.length > LIMITS.bodyBytes)
|
|
93
|
+
throw new McpFailure("configuration");
|
|
94
|
+
const mutation = (method === "POST" &&
|
|
95
|
+
(consumer === "mcp" ? MCP_OPERATION_PATH : CLI_OPERATION_PATH).test(url.pathname)) ||
|
|
96
|
+
(local !== undefined && local.method !== "GET" && local.readOnly !== true);
|
|
97
|
+
const allowedRead = !keyMode(connection)
|
|
98
|
+
? LOCAL_READ_PATH
|
|
99
|
+
: consumer === "mcp"
|
|
100
|
+
? KEY_READ_PATH
|
|
101
|
+
: CLI_READ_PATH;
|
|
102
|
+
const inventoryQuery = /^\/v1\/inventory\/(?:profiles|proxies)$/.test(url.pathname);
|
|
103
|
+
if (url.origin !== connection.origin ||
|
|
104
|
+
url.username ||
|
|
105
|
+
url.password ||
|
|
106
|
+
url.hash ||
|
|
107
|
+
(local
|
|
108
|
+
? !localRequestAllowed(local, url, body, (text) => parsedBody(text) !== undefined)
|
|
109
|
+
: !((method === "GET" && allowedRead.test(url.pathname)) || mutation) ||
|
|
110
|
+
(method === "GET" && body.length !== 0) ||
|
|
111
|
+
(method === "POST" &&
|
|
112
|
+
(url.searchParams.size !== 0 || !parsedBody(body.toString("utf8")))) ||
|
|
113
|
+
[...url.searchParams.keys()].some((key) => !inventoryQuery ||
|
|
114
|
+
!["limit", "offset", "q", "group", "tag", "running", "trashed"].includes(key))))
|
|
115
|
+
throw new McpFailure("configuration");
|
|
116
|
+
// Raw PNG bytes (screenshots) get their own cap; every other body keeps 1 MiB.
|
|
117
|
+
const bodyLimit = local?.binary ? LIMITS.screenshotBytes : LIMITS.bodyBytes;
|
|
118
|
+
const timeout = local && !local.human
|
|
119
|
+
? 70_000
|
|
120
|
+
: requestTimeoutMs(method, url.pathname, body.toString("utf8"));
|
|
121
|
+
const deadline = AbortSignal.timeout(timeout);
|
|
122
|
+
const signal = AbortSignal.any([lifetime, input.signal, deadline]);
|
|
123
|
+
const credentialCheck = async () => {
|
|
124
|
+
if (!connection.credential)
|
|
125
|
+
return;
|
|
126
|
+
try {
|
|
127
|
+
await assertCredentialUnchangedAsync(connection.credential, signal);
|
|
128
|
+
}
|
|
129
|
+
catch {
|
|
130
|
+
throw new McpFailure(deadline.aborted ? "deadline" : signal.aborted ? "cancelled" : "configuration");
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
if (connection.credential) {
|
|
134
|
+
await credentialCheck();
|
|
135
|
+
}
|
|
136
|
+
const response = await new Promise((resolve, reject) => {
|
|
137
|
+
if (signal.aborted)
|
|
138
|
+
return reject(new McpFailure("cancelled"));
|
|
139
|
+
let settled = false;
|
|
140
|
+
const finish = (code, body) => {
|
|
141
|
+
if (settled)
|
|
142
|
+
return;
|
|
143
|
+
settled = true;
|
|
144
|
+
clearTimeout(timer);
|
|
145
|
+
signal.removeEventListener("abort", abort);
|
|
146
|
+
if (code) {
|
|
147
|
+
req.destroy();
|
|
148
|
+
void drained.then(() => reject(new McpFailure(code)));
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
try {
|
|
152
|
+
let response;
|
|
153
|
+
if (local?.binary) {
|
|
154
|
+
response = new Response(new Uint8Array(body), {
|
|
155
|
+
headers: { "content-type": "image/png" },
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
else {
|
|
159
|
+
const text = new TextDecoder("utf-8", { fatal: true }).decode(body);
|
|
160
|
+
if (!local?.text)
|
|
161
|
+
JSON.parse(text);
|
|
162
|
+
response = new Response(text, {
|
|
163
|
+
headers: { "content-type": local?.text ? "text/plain" : "application/json" },
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
void drained.then(() => resolve(response));
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
req.destroy();
|
|
170
|
+
void drained.then(() => reject(new McpFailure(mutation ? "indeterminate" : "response")));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
const abort = () => finish(mutation ? "indeterminate" : deadline.aborted ? "deadline" : "cancelled");
|
|
175
|
+
const req = request(url, {
|
|
176
|
+
method,
|
|
177
|
+
agent: false,
|
|
178
|
+
maxHeaderSize: 16 * 1024,
|
|
179
|
+
headers: {
|
|
180
|
+
authorization: `Bearer ${connection.token}`,
|
|
181
|
+
accept: "application/json",
|
|
182
|
+
"accept-encoding": "identity",
|
|
183
|
+
...(body.length > 0 ? { "content-type": "application/json" } : {}),
|
|
184
|
+
// The daemon reads this header only for API keys; with the local token it is ignored.
|
|
185
|
+
"x-ant0-consumer": consumer,
|
|
186
|
+
},
|
|
187
|
+
});
|
|
188
|
+
// Keep the handler's permit until the local request has closed, not merely until destroy()
|
|
189
|
+
// was requested. agent:false also closes successful requests rather than pooling sockets.
|
|
190
|
+
const drained = new Promise((resolve) => req.once("close", resolve));
|
|
191
|
+
const timer = setTimeout(() => finish(mutation ? "indeterminate" : "deadline"), timeout);
|
|
192
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
193
|
+
req.on("error", () => finish(mutation ? "indeterminate" : "unavailable"));
|
|
194
|
+
req.on("response", (res) => {
|
|
195
|
+
res.on("error", () => finish(mutation ? "indeterminate" : "response"));
|
|
196
|
+
const status = res.statusCode;
|
|
197
|
+
const stopRoute = method === "POST" && /^\/v1\/profiles\/[^/]+\/stop$/.test(url.pathname);
|
|
198
|
+
const expectedStatus = local?.status ?? (stopRoute ? 204 : 200);
|
|
199
|
+
if (local &&
|
|
200
|
+
(status === 400 ||
|
|
201
|
+
status === 409 ||
|
|
202
|
+
status === 422 ||
|
|
203
|
+
status === 423 ||
|
|
204
|
+
(local.page && (status === 408 || status === 403 || status === 404)))) {
|
|
205
|
+
// Read only the daemon's error `code`; no message, details or other field is kept.
|
|
206
|
+
const chunks = [];
|
|
207
|
+
let size = 0;
|
|
208
|
+
res.on("data", (chunk) => {
|
|
209
|
+
size += chunk.length;
|
|
210
|
+
if (size > LIMITS.bodyBytes)
|
|
211
|
+
return finish("upstream");
|
|
212
|
+
chunks.push(chunk);
|
|
213
|
+
});
|
|
214
|
+
res.on("end", () => {
|
|
215
|
+
const kind = mapDaemonError(status, Buffer.concat(chunks, size), local.page === true);
|
|
216
|
+
// A 404 without a page code of its own stays the generic "not found".
|
|
217
|
+
finish(status === 404 && kind === "upstream" ? "not_found" : kind);
|
|
218
|
+
});
|
|
219
|
+
res.on("close", () => {
|
|
220
|
+
if (!res.complete)
|
|
221
|
+
finish("upstream");
|
|
222
|
+
});
|
|
223
|
+
return;
|
|
224
|
+
}
|
|
225
|
+
if (!local && status === 409) {
|
|
226
|
+
// Run, stop and status accept an exact name: a name shared by profiles is a fixed failure.
|
|
227
|
+
const chunks = [];
|
|
228
|
+
let size = 0;
|
|
229
|
+
res.on("data", (chunk) => {
|
|
230
|
+
size += chunk.length;
|
|
231
|
+
if (size > LIMITS.bodyBytes)
|
|
232
|
+
return finish("upstream");
|
|
233
|
+
chunks.push(chunk);
|
|
234
|
+
});
|
|
235
|
+
res.on("end", () => finish(isAmbiguousName(Buffer.concat(chunks, size)) ? "ambiguous_name" : "upstream"));
|
|
236
|
+
res.on("close", () => {
|
|
237
|
+
if (!res.complete)
|
|
238
|
+
finish("upstream");
|
|
239
|
+
});
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
if (status !== expectedStatus) {
|
|
243
|
+
res.destroy();
|
|
244
|
+
return finish(status === 401
|
|
245
|
+
? "unauthorized"
|
|
246
|
+
: status === 403
|
|
247
|
+
? "forbidden"
|
|
248
|
+
: status === 404
|
|
249
|
+
? "not_found"
|
|
250
|
+
: local && status === 503
|
|
251
|
+
? "unavailable"
|
|
252
|
+
: "upstream");
|
|
253
|
+
}
|
|
254
|
+
if (res.headers["content-encoding"] && res.headers["content-encoding"] !== "identity") {
|
|
255
|
+
return finish(mutation ? "indeterminate" : "response");
|
|
256
|
+
}
|
|
257
|
+
if (Number(res.headers["content-length"]) > bodyLimit)
|
|
258
|
+
return finish(mutation ? "indeterminate" : "body_limit");
|
|
259
|
+
const chunks = [];
|
|
260
|
+
let size = 0;
|
|
261
|
+
res.on("data", (chunk) => {
|
|
262
|
+
size += chunk.length;
|
|
263
|
+
if (size > bodyLimit)
|
|
264
|
+
return finish(mutation ? "indeterminate" : "body_limit");
|
|
265
|
+
chunks.push(chunk);
|
|
266
|
+
});
|
|
267
|
+
res.on("end", () => {
|
|
268
|
+
if (settled)
|
|
269
|
+
return;
|
|
270
|
+
if (expectedStatus === 204) {
|
|
271
|
+
if (size !== 0)
|
|
272
|
+
return finish("indeterminate");
|
|
273
|
+
settled = true;
|
|
274
|
+
clearTimeout(timer);
|
|
275
|
+
signal.removeEventListener("abort", abort);
|
|
276
|
+
// Only a stop answer may carry the sync state, and only the two known values pass.
|
|
277
|
+
const sync = res.headers["ant0-sync"];
|
|
278
|
+
const headers = stopRoute && (sync === "done" || sync === "pending") ? { "ant0-sync": sync } : {};
|
|
279
|
+
void drained.then(() => resolve(new Response(null, { status: 204, headers })));
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
finish(undefined, Buffer.concat(chunks, size));
|
|
283
|
+
});
|
|
284
|
+
res.on("close", () => {
|
|
285
|
+
if (!res.complete)
|
|
286
|
+
finish(mutation ? "indeterminate" : "response");
|
|
287
|
+
});
|
|
288
|
+
});
|
|
289
|
+
req.end(body);
|
|
290
|
+
});
|
|
291
|
+
// A credential that changed mid-flight invalidates the reply, never the effect already applied.
|
|
292
|
+
try {
|
|
293
|
+
await credentialCheck();
|
|
294
|
+
}
|
|
295
|
+
catch (error) {
|
|
296
|
+
throw mutation ? new McpFailure("indeterminate") : error;
|
|
297
|
+
}
|
|
298
|
+
return response;
|
|
299
|
+
};
|
|
300
|
+
return createAnt0Client({
|
|
301
|
+
baseUrl: connection.origin,
|
|
302
|
+
token: connection.token,
|
|
303
|
+
fetch: boundedFetch,
|
|
304
|
+
});
|
|
305
|
+
}
|
|
306
|
+
//# sourceMappingURL=daemon.js.map
|
package/dist/errors.d.ts
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
declare const MESSAGES: {
|
|
2
|
+
readonly configuration: "invalid local daemon configuration";
|
|
3
|
+
readonly token_file: "the local daemon token file is not private; the path and the fix are in the error output of ant0 mcp serve";
|
|
4
|
+
readonly unavailable: "local daemon unavailable";
|
|
5
|
+
readonly unauthorized: "local daemon authorization required";
|
|
6
|
+
readonly forbidden: "local daemon denied this request";
|
|
7
|
+
readonly not_found: "item not found";
|
|
8
|
+
readonly upstream: "local daemon request failed";
|
|
9
|
+
readonly response: "invalid local daemon response";
|
|
10
|
+
readonly body_limit: "local daemon response exceeds limit";
|
|
11
|
+
readonly result_limit: "tool result exceeds limit; request fewer items";
|
|
12
|
+
readonly deadline: "local daemon request timed out";
|
|
13
|
+
readonly cancelled: "request cancelled";
|
|
14
|
+
readonly indeterminate: "operation outcome is unknown; check the current state before retrying";
|
|
15
|
+
readonly invalid_request: "The daemon rejected the input.";
|
|
16
|
+
readonly profile_running: "Stop the profile first.";
|
|
17
|
+
readonly profile_synced: "This profile syncs with the cloud; remove it in the Ant0 app.";
|
|
18
|
+
readonly ambiguous_name: "Several profiles have that name; call ant0_profiles_list and pass the UUID.";
|
|
19
|
+
readonly conflict: "The daemon reported a conflict; check the profile and retry.";
|
|
20
|
+
readonly ref_stale: "The ref is stale; take a new snapshot and use a ref from it.";
|
|
21
|
+
readonly not_running: "The profile is not running; start it with ant0_profile_run first.";
|
|
22
|
+
readonly unsupported_input: "This control cannot be driven by typing or pointer input.";
|
|
23
|
+
readonly not_editable: "The field is disabled or read-only.";
|
|
24
|
+
readonly select_failed: "The select did not take the requested option.";
|
|
25
|
+
readonly out_of_view: "The target is outside the viewport or has no box.";
|
|
26
|
+
readonly focus_mismatch: "The target was not (or no longer) the focused element, so typing stopped; earlier characters or fields may already have been entered, and with submit the form may already have been submitted. Take a new snapshot, check the page state before retrying, and retry only what is missing. If its tab is in the background select it with ant0_tabs first.";
|
|
27
|
+
readonly obscured: "Another element covers the target, so that click was not sent (earlier fields of a fill may already have been entered); close the overlay or scroll and retry.";
|
|
28
|
+
readonly tab_hidden: "The tab is in the background (or went there mid-action; earlier characters or fields may already have been entered): call ant0_tabs with action select for it first (this changes the tab the user sees), check the page state, then retry.";
|
|
29
|
+
readonly tab_required: "Several tabs are open: call ant0_tabs to list them and pass the tab id as tab.";
|
|
30
|
+
readonly destination_blocked: "This URL points to a local or private-network address, which the page tools refuse. Use a public http(s) URL.";
|
|
31
|
+
readonly page_timeout: "The wait did not finish in time.";
|
|
32
|
+
readonly no_history: "There is no history entry in that direction.";
|
|
33
|
+
readonly dialog_pending: "A JavaScript dialog is open on this tab and blocks it: call ant0_page_dialog with action list, then accept or dismiss it.";
|
|
34
|
+
readonly no_dialog: "No dialog is open on this tab.";
|
|
35
|
+
readonly value_rejected: "The input did not take this value; use the format the field expects.";
|
|
36
|
+
readonly download_not_found: "That download is not known; call ant0_page_downloads with action list.";
|
|
37
|
+
readonly download_not_ready: "The download did not finish in time or did not complete.";
|
|
38
|
+
readonly url_not_allowed: "This tab shows a browser-internal page, which the page tools do not drive: open a web page with ant0_tabs new, or navigate a blank tab.";
|
|
39
|
+
readonly save_exists: "A file already exists at that path; choose a new path.";
|
|
40
|
+
readonly human_pending: "A hand-off or approval request is already open for this profile: call ant0_human_wait with the request id you already have.";
|
|
41
|
+
readonly human_headless: "This profile runs headless, so nobody can act in it: stop it and start it again with headless false.";
|
|
42
|
+
readonly human_no_approver: "The Ant0 app is not running, so nobody can take the hand-off: ask the user to open the Ant0 app.";
|
|
43
|
+
readonly page_human_pending: "A person is handling a hand-off request on this profile, so input is refused: call ant0_human_wait with the request id until it is no longer pending.";
|
|
44
|
+
readonly rules_active: "This profile has approval rules (or they cannot be read), and this tool would bypass them, so it is refused. Use the ant0_page_* tools, or ask the user to clear the rules in the Ant0 app.";
|
|
45
|
+
readonly approval_required: "A person has to approve this action first, and this tool cannot ask: ask the user to change the profile's approval rules in the Ant0 app, or use a tool that takes approval_id.";
|
|
46
|
+
readonly approval_stale: "The approval no longer fits this action (it was used, it ran out after 120 s, or the request changed): repeat the action without approval_id to ask again.";
|
|
47
|
+
readonly approval_denied: "The person denied this action: do not retry it; ask the user what to do instead.";
|
|
48
|
+
readonly approval_unavailable: "Nobody can approve right now because the Ant0 app is not running: ask the user to open the Ant0 app.";
|
|
49
|
+
readonly approval_target_mismatch: "The key would land on another element than the ref you named: pass the ref of the control itself.";
|
|
50
|
+
readonly blocked_domain: "This profile blocks that site, so the page tools will not read or act on it: ask the user to change the profile's rules in the Ant0 app.";
|
|
51
|
+
readonly blocked_frame: "A frame of a blocked site is on this page, so this action is refused: ask the user to change the profile's rules in the Ant0 app.";
|
|
52
|
+
readonly ref_required: "This profile has approval rules: pass the element's ref.";
|
|
53
|
+
readonly frame_target: "The key would land on a frame: pass the ref of an element inside the frame.";
|
|
54
|
+
readonly rules_unreadable: "The profile's rules cannot be read, so page actions are refused: ask the user to check them in the Ant0 app.";
|
|
55
|
+
readonly arguments: "invalid tool arguments";
|
|
56
|
+
readonly unknown_tool: "unknown tool";
|
|
57
|
+
readonly busy: "too many concurrent calls";
|
|
58
|
+
readonly frame: "invalid MCP input frame";
|
|
59
|
+
readonly frame_limit: "MCP input frame exceeds limit";
|
|
60
|
+
readonly input: "MCP input failed";
|
|
61
|
+
readonly output: "MCP output failed";
|
|
62
|
+
readonly stdio: "MCP requires pipe or socket stdout";
|
|
63
|
+
readonly peer: "MCP peer did not answer ping";
|
|
64
|
+
readonly backpressure: "MCP output stalled";
|
|
65
|
+
readonly internal: "MCP adapter failed";
|
|
66
|
+
};
|
|
67
|
+
export type FailureCode = keyof typeof MESSAGES;
|
|
68
|
+
/** Tool discovery must advertise the same fixed structured failures that errorResult emits. */
|
|
69
|
+
export declare const FAILURE_OUTPUT_SCHEMA: {
|
|
70
|
+
type: "object";
|
|
71
|
+
anyOf: {
|
|
72
|
+
type: string;
|
|
73
|
+
additionalProperties: boolean;
|
|
74
|
+
required: string[];
|
|
75
|
+
properties: {
|
|
76
|
+
error: {
|
|
77
|
+
const: string;
|
|
78
|
+
};
|
|
79
|
+
message: {
|
|
80
|
+
const: "invalid local daemon configuration" | "the local daemon token file is not private; the path and the fix are in the error output of ant0 mcp serve" | "local daemon unavailable" | "local daemon authorization required" | "local daemon denied this request" | "item not found" | "local daemon request failed" | "invalid local daemon response" | "local daemon response exceeds limit" | "tool result exceeds limit; request fewer items" | "local daemon request timed out" | "request cancelled" | "operation outcome is unknown; check the current state before retrying" | "The daemon rejected the input." | "Stop the profile first." | "This profile syncs with the cloud; remove it in the Ant0 app." | "Several profiles have that name; call ant0_profiles_list and pass the UUID." | "The daemon reported a conflict; check the profile and retry." | "The ref is stale; take a new snapshot and use a ref from it." | "The profile is not running; start it with ant0_profile_run first." | "This control cannot be driven by typing or pointer input." | "The field is disabled or read-only." | "The select did not take the requested option." | "The target is outside the viewport or has no box." | "The target was not (or no longer) the focused element, so typing stopped; earlier characters or fields may already have been entered, and with submit the form may already have been submitted. Take a new snapshot, check the page state before retrying, and retry only what is missing. If its tab is in the background select it with ant0_tabs first." | "Another element covers the target, so that click was not sent (earlier fields of a fill may already have been entered); close the overlay or scroll and retry." | "The tab is in the background (or went there mid-action; earlier characters or fields may already have been entered): call ant0_tabs with action select for it first (this changes the tab the user sees), check the page state, then retry." | "Several tabs are open: call ant0_tabs to list them and pass the tab id as tab." | "This URL points to a local or private-network address, which the page tools refuse. Use a public http(s) URL." | "The wait did not finish in time." | "There is no history entry in that direction." | "A JavaScript dialog is open on this tab and blocks it: call ant0_page_dialog with action list, then accept or dismiss it." | "No dialog is open on this tab." | "The input did not take this value; use the format the field expects." | "That download is not known; call ant0_page_downloads with action list." | "The download did not finish in time or did not complete." | "This tab shows a browser-internal page, which the page tools do not drive: open a web page with ant0_tabs new, or navigate a blank tab." | "A file already exists at that path; choose a new path." | "A hand-off or approval request is already open for this profile: call ant0_human_wait with the request id you already have." | "This profile runs headless, so nobody can act in it: stop it and start it again with headless false." | "The Ant0 app is not running, so nobody can take the hand-off: ask the user to open the Ant0 app." | "A person is handling a hand-off request on this profile, so input is refused: call ant0_human_wait with the request id until it is no longer pending." | "This profile has approval rules (or they cannot be read), and this tool would bypass them, so it is refused. Use the ant0_page_* tools, or ask the user to clear the rules in the Ant0 app." | "A person has to approve this action first, and this tool cannot ask: ask the user to change the profile's approval rules in the Ant0 app, or use a tool that takes approval_id." | "The approval no longer fits this action (it was used, it ran out after 120 s, or the request changed): repeat the action without approval_id to ask again." | "The person denied this action: do not retry it; ask the user what to do instead." | "Nobody can approve right now because the Ant0 app is not running: ask the user to open the Ant0 app." | "The key would land on another element than the ref you named: pass the ref of the control itself." | "This profile blocks that site, so the page tools will not read or act on it: ask the user to change the profile's rules in the Ant0 app." | "A frame of a blocked site is on this page, so this action is refused: ask the user to change the profile's rules in the Ant0 app." | "This profile has approval rules: pass the element's ref." | "The key would land on a frame: pass the ref of an element inside the frame." | "The profile's rules cannot be read, so page actions are refused: ask the user to check them in the Ant0 app." | "invalid tool arguments" | "unknown tool" | "too many concurrent calls" | "invalid MCP input frame" | "MCP input frame exceeds limit" | "MCP input failed" | "MCP output failed" | "MCP requires pipe or socket stdout" | "MCP peer did not answer ping" | "MCP output stalled" | "MCP adapter failed";
|
|
81
|
+
};
|
|
82
|
+
};
|
|
83
|
+
}[];
|
|
84
|
+
};
|
|
85
|
+
/** Only these fixed strings cross the diagnostic boundary. Never retain a raw cause. */
|
|
86
|
+
export declare class McpFailure extends Error {
|
|
87
|
+
readonly code: FailureCode;
|
|
88
|
+
constructor(code: FailureCode);
|
|
89
|
+
}
|
|
90
|
+
export declare function safeFailure(error: unknown): McpFailure;
|
|
91
|
+
export {};
|
|
92
|
+
//# sourceMappingURL=errors.d.ts.map
|
package/dist/errors.js
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { isAnt0ApiError } from "./api/index.js";
|
|
2
|
+
import { CredentialFailure } from "./key-contract.js";
|
|
3
|
+
const MESSAGES = {
|
|
4
|
+
configuration: "invalid local daemon configuration",
|
|
5
|
+
token_file: "the local daemon token file is not private; the path and the fix are in the error output of ant0 mcp serve",
|
|
6
|
+
unavailable: "local daemon unavailable",
|
|
7
|
+
unauthorized: "local daemon authorization required",
|
|
8
|
+
forbidden: "local daemon denied this request",
|
|
9
|
+
not_found: "item not found",
|
|
10
|
+
upstream: "local daemon request failed",
|
|
11
|
+
response: "invalid local daemon response",
|
|
12
|
+
body_limit: "local daemon response exceeds limit",
|
|
13
|
+
result_limit: "tool result exceeds limit; request fewer items",
|
|
14
|
+
deadline: "local daemon request timed out",
|
|
15
|
+
cancelled: "request cancelled",
|
|
16
|
+
indeterminate: "operation outcome is unknown; check the current state before retrying",
|
|
17
|
+
invalid_request: "The daemon rejected the input.",
|
|
18
|
+
profile_running: "Stop the profile first.",
|
|
19
|
+
profile_synced: "This profile syncs with the cloud; remove it in the Ant0 app.",
|
|
20
|
+
ambiguous_name: "Several profiles have that name; call ant0_profiles_list and pass the UUID.",
|
|
21
|
+
conflict: "The daemon reported a conflict; check the profile and retry.",
|
|
22
|
+
ref_stale: "The ref is stale; take a new snapshot and use a ref from it.",
|
|
23
|
+
not_running: "The profile is not running; start it with ant0_profile_run first.",
|
|
24
|
+
unsupported_input: "This control cannot be driven by typing or pointer input.",
|
|
25
|
+
not_editable: "The field is disabled or read-only.",
|
|
26
|
+
select_failed: "The select did not take the requested option.",
|
|
27
|
+
out_of_view: "The target is outside the viewport or has no box.",
|
|
28
|
+
focus_mismatch: "The target was not (or no longer) the focused element, so typing stopped; earlier characters or fields may already have been entered, and with submit the form may already have been submitted. Take a new snapshot, check the page state before retrying, and retry only what is missing. If its tab is in the background select it with ant0_tabs first.",
|
|
29
|
+
obscured: "Another element covers the target, so that click was not sent (earlier fields of a fill may already have been entered); close the overlay or scroll and retry.",
|
|
30
|
+
tab_hidden: "The tab is in the background (or went there mid-action; earlier characters or fields may already have been entered): call ant0_tabs with action select for it first (this changes the tab the user sees), check the page state, then retry.",
|
|
31
|
+
tab_required: "Several tabs are open: call ant0_tabs to list them and pass the tab id as tab.",
|
|
32
|
+
destination_blocked: "This URL points to a local or private-network address, which the page tools refuse. Use a public http(s) URL.",
|
|
33
|
+
page_timeout: "The wait did not finish in time.",
|
|
34
|
+
no_history: "There is no history entry in that direction.",
|
|
35
|
+
dialog_pending: "A JavaScript dialog is open on this tab and blocks it: call ant0_page_dialog with action list, then accept or dismiss it.",
|
|
36
|
+
no_dialog: "No dialog is open on this tab.",
|
|
37
|
+
value_rejected: "The input did not take this value; use the format the field expects.",
|
|
38
|
+
download_not_found: "That download is not known; call ant0_page_downloads with action list.",
|
|
39
|
+
download_not_ready: "The download did not finish in time or did not complete.",
|
|
40
|
+
url_not_allowed: "This tab shows a browser-internal page, which the page tools do not drive: open a web page with ant0_tabs new, or navigate a blank tab.",
|
|
41
|
+
save_exists: "A file already exists at that path; choose a new path.",
|
|
42
|
+
human_pending: "A hand-off or approval request is already open for this profile: call ant0_human_wait with the request id you already have.",
|
|
43
|
+
human_headless: "This profile runs headless, so nobody can act in it: stop it and start it again with headless false.",
|
|
44
|
+
human_no_approver: "The Ant0 app is not running, so nobody can take the hand-off: ask the user to open the Ant0 app.",
|
|
45
|
+
page_human_pending: "A person is handling a hand-off request on this profile, so input is refused: call ant0_human_wait with the request id until it is no longer pending.",
|
|
46
|
+
rules_active: "This profile has approval rules (or they cannot be read), and this tool would bypass them, so it is refused. Use the ant0_page_* tools, or ask the user to clear the rules in the Ant0 app.",
|
|
47
|
+
approval_required: "A person has to approve this action first, and this tool cannot ask: ask the user to change the profile's approval rules in the Ant0 app, or use a tool that takes approval_id.",
|
|
48
|
+
approval_stale: "The approval no longer fits this action (it was used, it ran out after 120 s, or the request changed): repeat the action without approval_id to ask again.",
|
|
49
|
+
approval_denied: "The person denied this action: do not retry it; ask the user what to do instead.",
|
|
50
|
+
approval_unavailable: "Nobody can approve right now because the Ant0 app is not running: ask the user to open the Ant0 app.",
|
|
51
|
+
approval_target_mismatch: "The key would land on another element than the ref you named: pass the ref of the control itself.",
|
|
52
|
+
blocked_domain: "This profile blocks that site, so the page tools will not read or act on it: ask the user to change the profile's rules in the Ant0 app.",
|
|
53
|
+
blocked_frame: "A frame of a blocked site is on this page, so this action is refused: ask the user to change the profile's rules in the Ant0 app.",
|
|
54
|
+
ref_required: "This profile has approval rules: pass the element's ref.",
|
|
55
|
+
frame_target: "The key would land on a frame: pass the ref of an element inside the frame.",
|
|
56
|
+
rules_unreadable: "The profile's rules cannot be read, so page actions are refused: ask the user to check them in the Ant0 app.",
|
|
57
|
+
arguments: "invalid tool arguments",
|
|
58
|
+
unknown_tool: "unknown tool",
|
|
59
|
+
busy: "too many concurrent calls",
|
|
60
|
+
frame: "invalid MCP input frame",
|
|
61
|
+
frame_limit: "MCP input frame exceeds limit",
|
|
62
|
+
input: "MCP input failed",
|
|
63
|
+
output: "MCP output failed",
|
|
64
|
+
stdio: "MCP requires pipe or socket stdout",
|
|
65
|
+
peer: "MCP peer did not answer ping",
|
|
66
|
+
backpressure: "MCP output stalled",
|
|
67
|
+
internal: "MCP adapter failed",
|
|
68
|
+
};
|
|
69
|
+
/** Tool discovery must advertise the same fixed structured failures that errorResult emits. */
|
|
70
|
+
export const FAILURE_OUTPUT_SCHEMA = {
|
|
71
|
+
type: "object",
|
|
72
|
+
anyOf: Object.entries(MESSAGES).map(([code, message]) => ({
|
|
73
|
+
type: "object",
|
|
74
|
+
additionalProperties: false,
|
|
75
|
+
required: ["error", "message"],
|
|
76
|
+
properties: { error: { const: `mcp.${code}` }, message: { const: message } },
|
|
77
|
+
})),
|
|
78
|
+
};
|
|
79
|
+
/** Only these fixed strings cross the diagnostic boundary. Never retain a raw cause. */
|
|
80
|
+
export class McpFailure extends Error {
|
|
81
|
+
code;
|
|
82
|
+
constructor(code) {
|
|
83
|
+
super(MESSAGES[code]);
|
|
84
|
+
this.code = code;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
export function safeFailure(error) {
|
|
88
|
+
if (error instanceof CredentialFailure)
|
|
89
|
+
return new McpFailure("response");
|
|
90
|
+
if (isAnt0ApiError(error)) {
|
|
91
|
+
return new McpFailure(error.status === 401
|
|
92
|
+
? "unauthorized"
|
|
93
|
+
: error.status === 403
|
|
94
|
+
? "forbidden"
|
|
95
|
+
: error.status === 404
|
|
96
|
+
? "not_found"
|
|
97
|
+
: "upstream");
|
|
98
|
+
}
|
|
99
|
+
return error instanceof McpFailure ? error : new McpFailure("internal");
|
|
100
|
+
}
|
|
101
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
export declare const EXPORT_TTL_HOURS = 24;
|
|
2
|
+
/** `<ANT0_HOME>/exports/cookies`. */
|
|
3
|
+
export declare function cookieExportDir(home: string): string;
|
|
4
|
+
/** `<ANT0_HOME>/exports/screenshots`. */
|
|
5
|
+
export declare function screenshotExportDir(home: string): string;
|
|
6
|
+
/** `<ANT0_HOME>/imports/cookies`: the only place `ant0_cookies_import` reads files from. */
|
|
7
|
+
export declare function cookieImportDir(home: string): string;
|
|
8
|
+
/** Delete our own files older than the TTL. Regular files with our name pattern only; best effort. */
|
|
9
|
+
export declare function sweepExports(dir: string, now?: number): void;
|
|
10
|
+
/**
|
|
11
|
+
* Write one export file and return its absolute path. The leaf directory is mode 0700 and the
|
|
12
|
+
* file 0600 (written under a temp name with flag "wx", then renamed in the same directory). On
|
|
13
|
+
* Windows the mode bits are ignored and the user-profile ACL inheritance protects the folder.
|
|
14
|
+
* Failures carry no cookie data.
|
|
15
|
+
*/
|
|
16
|
+
export declare function writeCookieExport(home: string, profileId: string, extension: "json" | "txt", data: string, now?: Date, test?: {
|
|
17
|
+
suffix?: string;
|
|
18
|
+
beforeRename?: (temp: string) => void;
|
|
19
|
+
}): string;
|
|
20
|
+
/** Write one screenshot (PNG bytes) with the same guarantees as a cookie export. */
|
|
21
|
+
export declare function writeScreenshotExport(home: string, profileId: string, png: Buffer, now?: Date, test?: {
|
|
22
|
+
suffix?: string;
|
|
23
|
+
beforeRename?: (temp: string) => void;
|
|
24
|
+
}): string;
|
|
25
|
+
/** Sweep now and then hourly (unref'd, so it never keeps the process alive). Returns the stopper. */
|
|
26
|
+
export declare const SWEEP_INTERVAL_MS = 3600000;
|
|
27
|
+
export declare function startExportSweeper(home: string): () => void;
|
|
28
|
+
/**
|
|
29
|
+
* Read one cookie file from `<ANT0_HOME>/imports/cookies` (UTF-8, at most one request body).
|
|
30
|
+
* The directory is created 0700 if missing. Every failure (missing, unreadable, outside the
|
|
31
|
+
* directory, symlink, directory, FIFO, too large, swapped, bad UTF-8) is the same `arguments`
|
|
32
|
+
* failure, so the tool is not an existence or content oracle for other paths.
|
|
33
|
+
*/
|
|
34
|
+
export declare function readImportFile(home: string, path: string, test?: {
|
|
35
|
+
afterLstat?: (path: string) => void;
|
|
36
|
+
}): string;
|
|
37
|
+
//# sourceMappingURL=export-files.d.ts.map
|