@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
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export declare const keyId: z.ZodString;
|
|
3
|
+
export declare const readScopes: readonly ["status:read", "profiles:read", "proxies:read"];
|
|
4
|
+
export declare const operationScopes: readonly ["profiles:run", "profiles:stop", "profiles:cdp"];
|
|
5
|
+
export declare const operateScopes: readonly ["status:read", "profiles:read", "proxies:read", "profiles:run", "profiles:stop"];
|
|
6
|
+
export declare const keyScopes: readonly ["status:read", "profiles:read", "proxies:read", "profiles:run", "profiles:stop", "profiles:cdp"];
|
|
7
|
+
export type KeyScope = (typeof keyScopes)[number];
|
|
8
|
+
export declare const keyName: z.ZodString;
|
|
9
|
+
export declare const lifetime: z.ZodNumber;
|
|
10
|
+
export declare const expectedContextSchema: z.ZodObject<{
|
|
11
|
+
user_id: z.ZodString;
|
|
12
|
+
workspace_id: z.ZodString;
|
|
13
|
+
device_id: z.ZodString;
|
|
14
|
+
device_sign_pub: z.ZodString;
|
|
15
|
+
}, z.core.$strip>;
|
|
16
|
+
export declare const keyMetadataSchema: z.ZodObject<{
|
|
17
|
+
id: z.ZodString;
|
|
18
|
+
workspace_id: z.ZodString;
|
|
19
|
+
delegated_user_id: z.ZodString;
|
|
20
|
+
device_id: z.ZodString;
|
|
21
|
+
name: z.ZodString;
|
|
22
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
23
|
+
"status:read": "status:read";
|
|
24
|
+
"profiles:read": "profiles:read";
|
|
25
|
+
"proxies:read": "proxies:read";
|
|
26
|
+
"profiles:run": "profiles:run";
|
|
27
|
+
"profiles:stop": "profiles:stop";
|
|
28
|
+
"profiles:cdp": "profiles:cdp";
|
|
29
|
+
}>>;
|
|
30
|
+
role_ceiling: z.ZodEnum<{
|
|
31
|
+
owner: "owner";
|
|
32
|
+
manager: "manager";
|
|
33
|
+
operator: "operator";
|
|
34
|
+
starter: "starter";
|
|
35
|
+
}>;
|
|
36
|
+
created_at: z.ZodString;
|
|
37
|
+
expires_at: z.ZodString;
|
|
38
|
+
last_used_at: z.ZodNullable<z.ZodString>;
|
|
39
|
+
revoked_at: z.ZodNullable<z.ZodString>;
|
|
40
|
+
status: z.ZodEnum<{
|
|
41
|
+
expired: "expired";
|
|
42
|
+
active: "active";
|
|
43
|
+
revoked: "revoked";
|
|
44
|
+
}>;
|
|
45
|
+
}, z.core.$strip>;
|
|
46
|
+
export declare const createKeySchema: z.ZodObject<{
|
|
47
|
+
id: z.ZodString;
|
|
48
|
+
credential: z.ZodString;
|
|
49
|
+
name: z.ZodString;
|
|
50
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
51
|
+
"status:read": "status:read";
|
|
52
|
+
"profiles:read": "profiles:read";
|
|
53
|
+
"proxies:read": "proxies:read";
|
|
54
|
+
"profiles:run": "profiles:run";
|
|
55
|
+
"profiles:stop": "profiles:stop";
|
|
56
|
+
"profiles:cdp": "profiles:cdp";
|
|
57
|
+
}>>;
|
|
58
|
+
lifetime_seconds: z.ZodNumber;
|
|
59
|
+
}, z.core.$strict>;
|
|
60
|
+
export declare function matchingMetadata(file: {
|
|
61
|
+
expected: ExpectedContext;
|
|
62
|
+
create: CreateKey;
|
|
63
|
+
key?: KeyMetadata | null;
|
|
64
|
+
}, key: KeyMetadata): boolean;
|
|
65
|
+
export declare const credentialFileSchema: z.ZodObject<{
|
|
66
|
+
schema: z.ZodLiteral<"ant0-api-key/v1">;
|
|
67
|
+
expected: z.ZodObject<{
|
|
68
|
+
user_id: z.ZodString;
|
|
69
|
+
workspace_id: z.ZodString;
|
|
70
|
+
device_id: z.ZodString;
|
|
71
|
+
device_sign_pub: z.ZodString;
|
|
72
|
+
}, z.core.$strict>;
|
|
73
|
+
create: z.ZodObject<{
|
|
74
|
+
id: z.ZodString;
|
|
75
|
+
credential: z.ZodString;
|
|
76
|
+
name: z.ZodString;
|
|
77
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
78
|
+
"status:read": "status:read";
|
|
79
|
+
"profiles:read": "profiles:read";
|
|
80
|
+
"proxies:read": "proxies:read";
|
|
81
|
+
"profiles:run": "profiles:run";
|
|
82
|
+
"profiles:stop": "profiles:stop";
|
|
83
|
+
"profiles:cdp": "profiles:cdp";
|
|
84
|
+
}>>;
|
|
85
|
+
lifetime_seconds: z.ZodNumber;
|
|
86
|
+
}, z.core.$strict>;
|
|
87
|
+
phase: z.ZodEnum<{
|
|
88
|
+
pending: "pending";
|
|
89
|
+
ready: "ready";
|
|
90
|
+
}>;
|
|
91
|
+
key: z.ZodNullable<z.ZodObject<{
|
|
92
|
+
id: z.ZodString;
|
|
93
|
+
workspace_id: z.ZodString;
|
|
94
|
+
delegated_user_id: z.ZodString;
|
|
95
|
+
device_id: z.ZodString;
|
|
96
|
+
name: z.ZodString;
|
|
97
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
98
|
+
"status:read": "status:read";
|
|
99
|
+
"profiles:read": "profiles:read";
|
|
100
|
+
"proxies:read": "proxies:read";
|
|
101
|
+
"profiles:run": "profiles:run";
|
|
102
|
+
"profiles:stop": "profiles:stop";
|
|
103
|
+
"profiles:cdp": "profiles:cdp";
|
|
104
|
+
}>>;
|
|
105
|
+
role_ceiling: z.ZodEnum<{
|
|
106
|
+
owner: "owner";
|
|
107
|
+
manager: "manager";
|
|
108
|
+
operator: "operator";
|
|
109
|
+
starter: "starter";
|
|
110
|
+
}>;
|
|
111
|
+
created_at: z.ZodString;
|
|
112
|
+
expires_at: z.ZodString;
|
|
113
|
+
last_used_at: z.ZodNullable<z.ZodString>;
|
|
114
|
+
revoked_at: z.ZodNullable<z.ZodString>;
|
|
115
|
+
status: z.ZodEnum<{
|
|
116
|
+
expired: "expired";
|
|
117
|
+
active: "active";
|
|
118
|
+
revoked: "revoked";
|
|
119
|
+
}>;
|
|
120
|
+
}, z.core.$strict>>;
|
|
121
|
+
}, z.core.$strict>;
|
|
122
|
+
export type ExpectedContext = z.infer<typeof expectedContextSchema>;
|
|
123
|
+
export type CreateKey = z.infer<typeof createKeySchema>;
|
|
124
|
+
export type KeyMetadata = z.infer<typeof keyMetadataSchema>;
|
|
125
|
+
export type CredentialFile = z.infer<typeof credentialFileSchema>;
|
|
126
|
+
export declare const credentialResultSchema: z.ZodObject<{
|
|
127
|
+
schema: z.ZodLiteral<"ant0-api-key-result/v1">;
|
|
128
|
+
credential_file_sha256: z.ZodString;
|
|
129
|
+
key: z.ZodObject<{
|
|
130
|
+
id: z.ZodString;
|
|
131
|
+
workspace_id: z.ZodString;
|
|
132
|
+
delegated_user_id: z.ZodString;
|
|
133
|
+
device_id: z.ZodString;
|
|
134
|
+
name: z.ZodString;
|
|
135
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
136
|
+
"status:read": "status:read";
|
|
137
|
+
"profiles:read": "profiles:read";
|
|
138
|
+
"proxies:read": "proxies:read";
|
|
139
|
+
"profiles:run": "profiles:run";
|
|
140
|
+
"profiles:stop": "profiles:stop";
|
|
141
|
+
"profiles:cdp": "profiles:cdp";
|
|
142
|
+
}>>;
|
|
143
|
+
role_ceiling: z.ZodEnum<{
|
|
144
|
+
owner: "owner";
|
|
145
|
+
manager: "manager";
|
|
146
|
+
operator: "operator";
|
|
147
|
+
starter: "starter";
|
|
148
|
+
}>;
|
|
149
|
+
created_at: z.ZodString;
|
|
150
|
+
expires_at: z.ZodString;
|
|
151
|
+
last_used_at: z.ZodNullable<z.ZodString>;
|
|
152
|
+
revoked_at: z.ZodNullable<z.ZodString>;
|
|
153
|
+
status: z.ZodEnum<{
|
|
154
|
+
expired: "expired";
|
|
155
|
+
active: "active";
|
|
156
|
+
revoked: "revoked";
|
|
157
|
+
}>;
|
|
158
|
+
}, z.core.$strict>;
|
|
159
|
+
}, z.core.$strict>;
|
|
160
|
+
export type CredentialResult = z.infer<typeof credentialResultSchema>;
|
|
161
|
+
declare const automationStatusSchema: z.ZodObject<{
|
|
162
|
+
principal: z.ZodObject<{
|
|
163
|
+
kind: z.ZodLiteral<"api_key">;
|
|
164
|
+
key_id: z.ZodString;
|
|
165
|
+
user_id: z.ZodString;
|
|
166
|
+
workspace_id: z.ZodString;
|
|
167
|
+
device_id: z.ZodString;
|
|
168
|
+
role_ceiling: z.ZodEnum<{
|
|
169
|
+
owner: "owner";
|
|
170
|
+
manager: "manager";
|
|
171
|
+
operator: "operator";
|
|
172
|
+
starter: "starter";
|
|
173
|
+
}>;
|
|
174
|
+
current_role: z.ZodEnum<{
|
|
175
|
+
owner: "owner";
|
|
176
|
+
manager: "manager";
|
|
177
|
+
operator: "operator";
|
|
178
|
+
starter: "starter";
|
|
179
|
+
}>;
|
|
180
|
+
scopes: z.ZodArray<z.ZodEnum<{
|
|
181
|
+
"status:read": "status:read";
|
|
182
|
+
"profiles:read": "profiles:read";
|
|
183
|
+
"proxies:read": "proxies:read";
|
|
184
|
+
"profiles:run": "profiles:run";
|
|
185
|
+
"profiles:stop": "profiles:stop";
|
|
186
|
+
"profiles:cdp": "profiles:cdp";
|
|
187
|
+
}>>;
|
|
188
|
+
expires_at: z.ZodString;
|
|
189
|
+
}, z.core.$strip>;
|
|
190
|
+
daemon: z.ZodObject<{
|
|
191
|
+
ok: z.ZodLiteral<true>;
|
|
192
|
+
version: z.ZodString;
|
|
193
|
+
uptime_s: z.ZodNumber;
|
|
194
|
+
}, z.core.$strip>;
|
|
195
|
+
licence: z.ZodObject<{
|
|
196
|
+
state: z.ZodLiteral<"active">;
|
|
197
|
+
mode: z.ZodLiteral<"enforce">;
|
|
198
|
+
plan: z.ZodString;
|
|
199
|
+
limits: z.ZodObject<{
|
|
200
|
+
profiles: z.ZodNumber;
|
|
201
|
+
seats: z.ZodNumber;
|
|
202
|
+
}, z.core.$strip>;
|
|
203
|
+
used: z.ZodNumber;
|
|
204
|
+
used_local: z.ZodNumber;
|
|
205
|
+
features: z.ZodPipe<z.ZodArray<z.ZodString>, z.ZodTransform<string[], string[]>>;
|
|
206
|
+
billing: z.ZodEnum<{
|
|
207
|
+
active: "active";
|
|
208
|
+
past_due: "past_due";
|
|
209
|
+
lapsed: "lapsed";
|
|
210
|
+
}>;
|
|
211
|
+
expires_at: z.ZodNull;
|
|
212
|
+
grace_until: z.ZodNull;
|
|
213
|
+
online: z.ZodLiteral<true>;
|
|
214
|
+
last_refresh_at: z.ZodString;
|
|
215
|
+
}, z.core.$strip>;
|
|
216
|
+
}, z.core.$strip>;
|
|
217
|
+
export declare class CredentialFailure extends Error {
|
|
218
|
+
constructor(message?: string);
|
|
219
|
+
}
|
|
220
|
+
/** Allowlisted metadata is still untrusted text. Never echo a credential disguised as a label. */
|
|
221
|
+
export declare function rejectCredentialEcho(value: unknown, credential?: string): void;
|
|
222
|
+
export declare function projectKeyMetadata(value: unknown): KeyMetadata;
|
|
223
|
+
export declare function projectExpectedContext(value: unknown): ExpectedContext;
|
|
224
|
+
export declare function projectKeyList(value: unknown): {
|
|
225
|
+
items: {
|
|
226
|
+
id: string;
|
|
227
|
+
workspace_id: string;
|
|
228
|
+
delegated_user_id: string;
|
|
229
|
+
device_id: string;
|
|
230
|
+
name: string;
|
|
231
|
+
scopes: ("status:read" | "profiles:read" | "proxies:read" | "profiles:run" | "profiles:stop" | "profiles:cdp")[];
|
|
232
|
+
role_ceiling: "owner" | "manager" | "operator" | "starter";
|
|
233
|
+
created_at: string;
|
|
234
|
+
expires_at: string;
|
|
235
|
+
last_used_at: string | null;
|
|
236
|
+
revoked_at: string | null;
|
|
237
|
+
status: "expired" | "active" | "revoked";
|
|
238
|
+
}[];
|
|
239
|
+
next_cursor: string | null;
|
|
240
|
+
};
|
|
241
|
+
export declare function projectAutomationStatus(value: unknown, file: CredentialFile, consumer?: "api" | "mcp"): {
|
|
242
|
+
principal: {
|
|
243
|
+
kind: "api_key";
|
|
244
|
+
key_id: string;
|
|
245
|
+
user_id: string;
|
|
246
|
+
workspace_id: string;
|
|
247
|
+
device_id: string;
|
|
248
|
+
role_ceiling: "owner" | "manager" | "operator" | "starter";
|
|
249
|
+
current_role: "owner" | "manager" | "operator" | "starter";
|
|
250
|
+
scopes: ("status:read" | "profiles:read" | "proxies:read" | "profiles:run" | "profiles:stop" | "profiles:cdp")[];
|
|
251
|
+
expires_at: string;
|
|
252
|
+
};
|
|
253
|
+
daemon: {
|
|
254
|
+
ok: true;
|
|
255
|
+
version: string;
|
|
256
|
+
uptime_s: number;
|
|
257
|
+
};
|
|
258
|
+
licence: {
|
|
259
|
+
state: "active";
|
|
260
|
+
mode: "enforce";
|
|
261
|
+
plan: string;
|
|
262
|
+
limits: {
|
|
263
|
+
profiles: number;
|
|
264
|
+
seats: number;
|
|
265
|
+
};
|
|
266
|
+
used: number;
|
|
267
|
+
used_local: number;
|
|
268
|
+
features: string[];
|
|
269
|
+
billing: "active" | "past_due" | "lapsed";
|
|
270
|
+
expires_at: null;
|
|
271
|
+
grace_until: null;
|
|
272
|
+
online: true;
|
|
273
|
+
last_refresh_at: string;
|
|
274
|
+
};
|
|
275
|
+
};
|
|
276
|
+
export declare const API_KEY_ENV = "ANT0_API_KEY";
|
|
277
|
+
export interface KeyGrant {
|
|
278
|
+
id: string;
|
|
279
|
+
credential: string;
|
|
280
|
+
scopes: readonly KeyScope[];
|
|
281
|
+
file?: CredentialFile;
|
|
282
|
+
}
|
|
283
|
+
export declare function apiKeyId(credential: string): string | undefined;
|
|
284
|
+
export declare function fileGrant(file: CredentialFile): KeyGrant;
|
|
285
|
+
export declare function grantFromStatus(value: unknown, credential: string, consumer?: "api" | "mcp"): {
|
|
286
|
+
grant: KeyGrant;
|
|
287
|
+
status: z.infer<typeof automationStatusSchema>;
|
|
288
|
+
};
|
|
289
|
+
export declare function projectGrantStatus(value: unknown, grant: KeyGrant, consumer?: "api" | "mcp"): {
|
|
290
|
+
principal: {
|
|
291
|
+
kind: "api_key";
|
|
292
|
+
key_id: string;
|
|
293
|
+
user_id: string;
|
|
294
|
+
workspace_id: string;
|
|
295
|
+
device_id: string;
|
|
296
|
+
role_ceiling: "owner" | "manager" | "operator" | "starter";
|
|
297
|
+
current_role: "owner" | "manager" | "operator" | "starter";
|
|
298
|
+
scopes: ("status:read" | "profiles:read" | "proxies:read" | "profiles:run" | "profiles:stop" | "profiles:cdp")[];
|
|
299
|
+
expires_at: string;
|
|
300
|
+
};
|
|
301
|
+
daemon: {
|
|
302
|
+
ok: true;
|
|
303
|
+
version: string;
|
|
304
|
+
uptime_s: number;
|
|
305
|
+
};
|
|
306
|
+
licence: {
|
|
307
|
+
state: "active";
|
|
308
|
+
mode: "enforce";
|
|
309
|
+
plan: string;
|
|
310
|
+
limits: {
|
|
311
|
+
profiles: number;
|
|
312
|
+
seats: number;
|
|
313
|
+
};
|
|
314
|
+
used: number;
|
|
315
|
+
used_local: number;
|
|
316
|
+
features: string[];
|
|
317
|
+
billing: "active" | "past_due" | "lapsed";
|
|
318
|
+
expires_at: null;
|
|
319
|
+
grace_until: null;
|
|
320
|
+
online: true;
|
|
321
|
+
last_refresh_at: string;
|
|
322
|
+
};
|
|
323
|
+
};
|
|
324
|
+
export {};
|
|
325
|
+
//# sourceMappingURL=key-contract.d.ts.map
|
|
@@ -0,0 +1,241 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
export const keyId = z
|
|
3
|
+
.string()
|
|
4
|
+
.regex(/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/);
|
|
5
|
+
const date = z.string().datetime().max(40);
|
|
6
|
+
const role = z.enum(["owner", "manager", "operator", "starter"]);
|
|
7
|
+
const count = z.number().int().min(0).max(Number.MAX_SAFE_INTEGER);
|
|
8
|
+
export const readScopes = ["status:read", "profiles:read", "proxies:read"];
|
|
9
|
+
export const operationScopes = ["profiles:run", "profiles:stop", "profiles:cdp"];
|
|
10
|
+
export const operateScopes = [...readScopes, "profiles:run", "profiles:stop"];
|
|
11
|
+
export const keyScopes = [...readScopes, ...operationScopes];
|
|
12
|
+
const scopes = z
|
|
13
|
+
.array(z.enum(keyScopes))
|
|
14
|
+
.min(1)
|
|
15
|
+
.max(keyScopes.length)
|
|
16
|
+
.refine((v) => new Set(v).size === v.length);
|
|
17
|
+
export const keyName = z
|
|
18
|
+
.string()
|
|
19
|
+
.min(1)
|
|
20
|
+
.max(200)
|
|
21
|
+
.refine((v) => [...v].length <= 100 && v.trim().length > 0 && !/[\p{Cc}\p{Cs}]/u.test(v));
|
|
22
|
+
export const lifetime = z.number().int().min(60).max(31_536_000);
|
|
23
|
+
const deviceId = z.string().regex(/^[A-Z2-7]{26}$/);
|
|
24
|
+
const publicKey = z.string().refine((v) => {
|
|
25
|
+
const decoded = Buffer.from(v, "base64");
|
|
26
|
+
return decoded.length === 32 && decoded.toString("base64") === v;
|
|
27
|
+
});
|
|
28
|
+
export const expectedContextSchema = z.object({
|
|
29
|
+
user_id: keyId,
|
|
30
|
+
workspace_id: keyId,
|
|
31
|
+
device_id: deviceId,
|
|
32
|
+
device_sign_pub: publicKey,
|
|
33
|
+
});
|
|
34
|
+
const metadataShape = {
|
|
35
|
+
id: keyId,
|
|
36
|
+
workspace_id: keyId,
|
|
37
|
+
delegated_user_id: keyId,
|
|
38
|
+
device_id: deviceId,
|
|
39
|
+
name: keyName,
|
|
40
|
+
scopes,
|
|
41
|
+
role_ceiling: role,
|
|
42
|
+
created_at: date,
|
|
43
|
+
expires_at: date,
|
|
44
|
+
last_used_at: date.nullable(),
|
|
45
|
+
revoked_at: date.nullable(),
|
|
46
|
+
status: z.enum(["active", "expired", "revoked"]),
|
|
47
|
+
};
|
|
48
|
+
export const keyMetadataSchema = z
|
|
49
|
+
.object(metadataShape)
|
|
50
|
+
.refine((v) => Date.parse(v.expires_at) > Date.parse(v.created_at) &&
|
|
51
|
+
(v.status === "revoked") === (v.revoked_at !== null));
|
|
52
|
+
export const createKeySchema = z
|
|
53
|
+
.strictObject({
|
|
54
|
+
id: keyId,
|
|
55
|
+
credential: z.string().max(128),
|
|
56
|
+
name: keyName,
|
|
57
|
+
scopes,
|
|
58
|
+
lifetime_seconds: lifetime,
|
|
59
|
+
})
|
|
60
|
+
.refine((v) => {
|
|
61
|
+
const prefix = `ant0_sk_v1_${v.id}_`;
|
|
62
|
+
if (!v.credential.startsWith(prefix))
|
|
63
|
+
return false;
|
|
64
|
+
const secret = v.credential.slice(prefix.length);
|
|
65
|
+
const bytes = Buffer.from(secret, "base64url");
|
|
66
|
+
return secret.length === 43 && bytes.length === 32 && bytes.toString("base64url") === secret;
|
|
67
|
+
});
|
|
68
|
+
export function matchingMetadata(file, key) {
|
|
69
|
+
return (key.id === file.create.id &&
|
|
70
|
+
key.workspace_id === file.expected.workspace_id &&
|
|
71
|
+
key.delegated_user_id === file.expected.user_id &&
|
|
72
|
+
key.device_id === file.expected.device_id &&
|
|
73
|
+
[...key.scopes].sort().join() === [...file.create.scopes].sort().join() &&
|
|
74
|
+
Date.parse(key.expires_at) - Date.parse(key.created_at) ===
|
|
75
|
+
file.create.lifetime_seconds * 1000 &&
|
|
76
|
+
(!file.key ||
|
|
77
|
+
(file.key.created_at === key.created_at &&
|
|
78
|
+
file.key.expires_at === key.expires_at &&
|
|
79
|
+
file.key.role_ceiling === key.role_ceiling)));
|
|
80
|
+
}
|
|
81
|
+
export const credentialFileSchema = z
|
|
82
|
+
.strictObject({
|
|
83
|
+
schema: z.literal("ant0-api-key/v1"),
|
|
84
|
+
expected: expectedContextSchema.strict(),
|
|
85
|
+
create: createKeySchema,
|
|
86
|
+
phase: z.enum(["pending", "ready"]),
|
|
87
|
+
key: z.object(metadataShape).strict().nullable(),
|
|
88
|
+
})
|
|
89
|
+
.refine((v) => v.phase === "pending"
|
|
90
|
+
? v.key === null
|
|
91
|
+
: v.key !== null && keyMetadataSchema.safeParse(v.key).success && matchingMetadata(v, v.key));
|
|
92
|
+
export const credentialResultSchema = z
|
|
93
|
+
.strictObject({
|
|
94
|
+
schema: z.literal("ant0-api-key-result/v1"),
|
|
95
|
+
credential_file_sha256: z.string().regex(/^[0-9a-f]{64}$/),
|
|
96
|
+
key: z.object(metadataShape).strict(),
|
|
97
|
+
})
|
|
98
|
+
.refine((value) => keyMetadataSchema.safeParse(value.key).success);
|
|
99
|
+
const principalSchema = z.object({
|
|
100
|
+
kind: z.literal("api_key"),
|
|
101
|
+
key_id: keyId,
|
|
102
|
+
user_id: keyId,
|
|
103
|
+
workspace_id: keyId,
|
|
104
|
+
device_id: deviceId,
|
|
105
|
+
role_ceiling: role,
|
|
106
|
+
current_role: role,
|
|
107
|
+
scopes,
|
|
108
|
+
expires_at: date,
|
|
109
|
+
});
|
|
110
|
+
const keyReadStatusSchema = z
|
|
111
|
+
.object({
|
|
112
|
+
state: z.literal("active"),
|
|
113
|
+
mode: z.literal("enforce"),
|
|
114
|
+
plan: z.string().regex(/^[a-z0-9_-]{1,64}$/),
|
|
115
|
+
limits: z.object({ profiles: count, seats: count.min(1) }),
|
|
116
|
+
used: count,
|
|
117
|
+
used_local: count,
|
|
118
|
+
features: z
|
|
119
|
+
.array(z.string().max(64))
|
|
120
|
+
.max(100)
|
|
121
|
+
.transform((v) => v.filter((feature) => ["api", "mcp", "sync", "teams", "priority_support"].includes(feature))),
|
|
122
|
+
billing: z.enum(["active", "past_due", "lapsed"]),
|
|
123
|
+
expires_at: z.null(),
|
|
124
|
+
grace_until: z.null(),
|
|
125
|
+
online: z.literal(true),
|
|
126
|
+
last_refresh_at: date,
|
|
127
|
+
})
|
|
128
|
+
.refine((v) => v.used >= v.used_local);
|
|
129
|
+
const automationStatusSchema = z.object({
|
|
130
|
+
principal: principalSchema,
|
|
131
|
+
daemon: z.object({
|
|
132
|
+
ok: z.literal(true),
|
|
133
|
+
version: z.string().regex(/^[A-Za-z0-9.+-]{1,64}$/),
|
|
134
|
+
uptime_s: count,
|
|
135
|
+
}),
|
|
136
|
+
licence: keyReadStatusSchema,
|
|
137
|
+
});
|
|
138
|
+
export class CredentialFailure extends Error {
|
|
139
|
+
constructor(message = "invalid private credential file") {
|
|
140
|
+
super(message);
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
/** Allowlisted metadata is still untrusted text. Never echo a credential disguised as a label. */
|
|
144
|
+
export function rejectCredentialEcho(value, credential) {
|
|
145
|
+
const suffix = credential?.slice(-43);
|
|
146
|
+
const text = JSON.stringify(value);
|
|
147
|
+
if (text !== undefined &&
|
|
148
|
+
(/ant0_sk_v1_[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}_[A-Za-z0-9_-]{43}/i.test(text) ||
|
|
149
|
+
(credential !== undefined && text.includes(credential)) ||
|
|
150
|
+
(suffix !== undefined && text.includes(suffix))))
|
|
151
|
+
throw new CredentialFailure("credential echoed in metadata");
|
|
152
|
+
}
|
|
153
|
+
export function projectKeyMetadata(value) {
|
|
154
|
+
const parsed = keyMetadataSchema.safeParse(value);
|
|
155
|
+
if (!parsed.success)
|
|
156
|
+
throw new CredentialFailure("invalid API key metadata");
|
|
157
|
+
rejectCredentialEcho(parsed.data);
|
|
158
|
+
return parsed.data;
|
|
159
|
+
}
|
|
160
|
+
export function projectExpectedContext(value) {
|
|
161
|
+
const parsed = expectedContextSchema.safeParse(value);
|
|
162
|
+
if (!parsed.success)
|
|
163
|
+
throw new CredentialFailure("invalid API key context");
|
|
164
|
+
return parsed.data;
|
|
165
|
+
}
|
|
166
|
+
export function projectKeyList(value) {
|
|
167
|
+
const parsed = z
|
|
168
|
+
.object({
|
|
169
|
+
items: z.array(keyMetadataSchema).max(100),
|
|
170
|
+
next_cursor: z.string().min(1).max(4096).nullable(),
|
|
171
|
+
})
|
|
172
|
+
.safeParse(value);
|
|
173
|
+
if (!parsed.success ||
|
|
174
|
+
new Set(parsed.data.items.map((v) => v.id)).size !== parsed.data.items.length)
|
|
175
|
+
throw new CredentialFailure("invalid API key metadata");
|
|
176
|
+
rejectCredentialEcho(parsed.data);
|
|
177
|
+
return parsed.data;
|
|
178
|
+
}
|
|
179
|
+
export function projectAutomationStatus(value, file, consumer = "api") {
|
|
180
|
+
const parsed = automationStatusSchema.safeParse(value);
|
|
181
|
+
if (!parsed.success)
|
|
182
|
+
throw new CredentialFailure("invalid API key status");
|
|
183
|
+
const p = parsed.data.principal;
|
|
184
|
+
if (p.key_id !== file.create.id ||
|
|
185
|
+
p.user_id !== file.expected.user_id ||
|
|
186
|
+
p.workspace_id !== file.expected.workspace_id ||
|
|
187
|
+
p.device_id !== file.expected.device_id ||
|
|
188
|
+
p.expires_at !== file.key?.expires_at ||
|
|
189
|
+
p.role_ceiling !== file.key?.role_ceiling ||
|
|
190
|
+
[...p.scopes].sort().join() !== [...file.create.scopes].sort().join() ||
|
|
191
|
+
!p.scopes.includes("status:read") ||
|
|
192
|
+
Date.parse(p.expires_at) <= Date.now() ||
|
|
193
|
+
!parsed.data.licence.features.includes("api") ||
|
|
194
|
+
(consumer === "mcp" && !parsed.data.licence.features.includes("mcp")))
|
|
195
|
+
throw new CredentialFailure("invalid API key status");
|
|
196
|
+
rejectCredentialEcho(parsed.data, file.create.credential);
|
|
197
|
+
return parsed.data;
|
|
198
|
+
}
|
|
199
|
+
export const API_KEY_ENV = "ANT0_API_KEY";
|
|
200
|
+
export function apiKeyId(credential) {
|
|
201
|
+
const match = /^ant0_sk_v1_([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})_([A-Za-z0-9_-]{43})$/.exec(credential);
|
|
202
|
+
if (!match)
|
|
203
|
+
return undefined;
|
|
204
|
+
const bytes = Buffer.from(match[2], "base64url");
|
|
205
|
+
return bytes.length === 32 && bytes.toString("base64url") === match[2] ? match[1] : undefined;
|
|
206
|
+
}
|
|
207
|
+
export function fileGrant(file) {
|
|
208
|
+
return {
|
|
209
|
+
id: file.create.id,
|
|
210
|
+
credential: file.create.credential,
|
|
211
|
+
scopes: file.create.scopes,
|
|
212
|
+
file,
|
|
213
|
+
};
|
|
214
|
+
}
|
|
215
|
+
function sameScopes(a, b) {
|
|
216
|
+
return [...a].sort().join() === [...b].sort().join();
|
|
217
|
+
}
|
|
218
|
+
export function grantFromStatus(value, credential, consumer = "api") {
|
|
219
|
+
const id = apiKeyId(credential);
|
|
220
|
+
const parsed = automationStatusSchema.safeParse(value);
|
|
221
|
+
if (!id || !parsed.success)
|
|
222
|
+
throw new CredentialFailure("invalid API key status");
|
|
223
|
+
const p = parsed.data.principal;
|
|
224
|
+
if (p.key_id !== id ||
|
|
225
|
+
!p.scopes.includes("status:read") ||
|
|
226
|
+
Date.parse(p.expires_at) <= Date.now() ||
|
|
227
|
+
!parsed.data.licence.features.includes("api") ||
|
|
228
|
+
(consumer === "mcp" && !parsed.data.licence.features.includes("mcp")))
|
|
229
|
+
throw new CredentialFailure("invalid API key status");
|
|
230
|
+
rejectCredentialEcho(parsed.data, credential);
|
|
231
|
+
return { grant: { id, credential, scopes: [...p.scopes] }, status: parsed.data };
|
|
232
|
+
}
|
|
233
|
+
export function projectGrantStatus(value, grant, consumer = "api") {
|
|
234
|
+
if (grant.file)
|
|
235
|
+
return projectAutomationStatus(value, grant.file, consumer);
|
|
236
|
+
const { grant: current, status } = grantFromStatus(value, grant.credential, consumer);
|
|
237
|
+
if (current.id !== grant.id || !sameScopes(current.scopes, grant.scopes))
|
|
238
|
+
throw new CredentialFailure("invalid API key status");
|
|
239
|
+
return status;
|
|
240
|
+
}
|
|
241
|
+
//# sourceMappingURL=key-contract.js.map
|
package/dist/limits.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** PHASE3-CONTRACT §17. Byte limits include UTF-8, not JavaScript character counts. */
|
|
2
|
+
export declare const LIMITS: Readonly<{
|
|
3
|
+
frameBytes: number;
|
|
4
|
+
bodyBytes: number;
|
|
5
|
+
/** A page screenshot from the daemon: its 8 MiB cap plus a margin for the framing. */
|
|
6
|
+
screenshotBytes: number;
|
|
7
|
+
/** Largest PNG returned inline as MCP image content (base64 must fit the output envelope). */
|
|
8
|
+
inlineImageBytes: number;
|
|
9
|
+
resultBytes: number;
|
|
10
|
+
concurrentCalls: 8;
|
|
11
|
+
listItems: 100;
|
|
12
|
+
httpMs: 10000;
|
|
13
|
+
outputMs: 1000;
|
|
14
|
+
writerStartupMs: 1000;
|
|
15
|
+
pingIntervalMs: 1000;
|
|
16
|
+
pingResponseMs: 3000;
|
|
17
|
+
outputBytes: number;
|
|
18
|
+
outputWrites: 32;
|
|
19
|
+
envelopeBytes: number;
|
|
20
|
+
discoveryBytes: 4096;
|
|
21
|
+
}>;
|
|
22
|
+
//# sourceMappingURL=limits.d.ts.map
|
package/dist/limits.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** PHASE3-CONTRACT §17. Byte limits include UTF-8, not JavaScript character counts. */
|
|
2
|
+
export const LIMITS = Object.freeze({
|
|
3
|
+
frameBytes: 1024 * 1024,
|
|
4
|
+
bodyBytes: 1024 * 1024,
|
|
5
|
+
/** A page screenshot from the daemon: its 8 MiB cap plus a margin for the framing. */
|
|
6
|
+
screenshotBytes: 8 * 1024 * 1024 + 64 * 1024,
|
|
7
|
+
/** Largest PNG returned inline as MCP image content (base64 must fit the output envelope). */
|
|
8
|
+
inlineImageBytes: 900 * 1024,
|
|
9
|
+
resultBytes: 256 * 1024,
|
|
10
|
+
concurrentCalls: 8,
|
|
11
|
+
listItems: 100,
|
|
12
|
+
httpMs: 10_000,
|
|
13
|
+
outputMs: 1_000,
|
|
14
|
+
writerStartupMs: 1_000,
|
|
15
|
+
pingIntervalMs: 1_000,
|
|
16
|
+
pingResponseMs: 3_000,
|
|
17
|
+
outputBytes: 2 * 1024 * 1024,
|
|
18
|
+
outputWrites: 32,
|
|
19
|
+
envelopeBytes: 1024 * 1024 + 256 * 1024 + 1024,
|
|
20
|
+
discoveryBytes: 4096,
|
|
21
|
+
});
|
|
22
|
+
//# sourceMappingURL=limits.js.map
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
export interface LocalRoute {
|
|
2
|
+
readonly method: "GET" | "POST" | "PATCH" | "DELETE";
|
|
3
|
+
readonly path: RegExp;
|
|
4
|
+
/** The one success status; anything else is an error. */
|
|
5
|
+
readonly status: 200 | 201 | 204;
|
|
6
|
+
/** Whether the request carries a JSON object body (otherwise none is allowed). */
|
|
7
|
+
readonly body: boolean;
|
|
8
|
+
/** Success body is returned as text, not parsed as JSON (cookie export may be cookies.txt). */
|
|
9
|
+
readonly text?: boolean;
|
|
10
|
+
/** Validates the query string; absent means no query string at all. */
|
|
11
|
+
readonly query?: (params: URLSearchParams) => boolean;
|
|
12
|
+
/** Success body is raw bytes (a PNG) with the larger `screenshotBytes` cap; others keep 1 MiB. */
|
|
13
|
+
readonly binary?: boolean;
|
|
14
|
+
/** A POST that changes nothing, so an abort is a plain cancellation, never "indeterminate". */
|
|
15
|
+
readonly readOnly?: boolean;
|
|
16
|
+
/** Page-action route: the page error codes map to their own fixed MCP failures. */
|
|
17
|
+
readonly page?: boolean;
|
|
18
|
+
/** Hand-off route: the request timeout follows the body's `wait_s`. */
|
|
19
|
+
readonly human?: boolean;
|
|
20
|
+
}
|
|
21
|
+
/** Hand-off request ids are opaque; the daemon owns their shape, so only the charset is bound. */
|
|
22
|
+
export declare const HUMAN_ID = "[A-Za-z0-9_-]{1,64}";
|
|
23
|
+
export declare const LOCAL_ROUTES: readonly LocalRoute[];
|
|
24
|
+
export declare function matchLocalRoute(method: string, pathname: string): LocalRoute | undefined;
|
|
25
|
+
/** Request-shape check shared by the transport: query string and body presence. */
|
|
26
|
+
export declare function localRequestAllowed(route: LocalRoute, url: URL, body: Buffer, isObjectBody: (text: string) => boolean): boolean;
|
|
27
|
+
export type DaemonErrorKind = "forbidden" | "invalid_request" | "profile_running" | "profile_synced" | "conflict" | "upstream" | "ref_stale" | "not_running" | "unsupported_input" | "not_editable" | "select_failed" | "out_of_view" | "focus_mismatch" | "obscured" | "tab_required" | "tab_hidden" | "destination_blocked" | "indeterminate" | "page_timeout" | "no_history" | "dialog_pending" | "no_dialog" | "value_rejected" | "download_not_found" | "download_not_ready" | "save_exists" | "url_not_allowed" | "ambiguous_name" | "human_pending" | "human_headless" | "human_no_approver" | "page_human_pending" | "approval_stale" | "approval_denied" | "approval_unavailable" | "approval_target_mismatch" | "blocked_domain" | "blocked_frame" | "ref_required" | "frame_target" | "rules_unreadable";
|
|
28
|
+
/** Closed mapping of daemon error codes; the daemon's message/details never cross. */
|
|
29
|
+
export declare function mapDaemonError(status: number, body: Buffer, page?: boolean): DaemonErrorKind;
|
|
30
|
+
//# sourceMappingURL=local-routes.d.ts.map
|