@amtp/protocol 1.0.1
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 +21 -0
- package/README.md +386 -0
- package/USAGE_GUIDE.md +722 -0
- package/bin/amtp.ts +387 -0
- package/dist/client/amtp-client.d.ts +164 -0
- package/dist/client/amtp-client.js +460 -0
- package/dist/client/amtp-client.js.map +1 -0
- package/dist/client/examples/basic-client.d.ts +6 -0
- package/dist/client/examples/basic-client.js +35 -0
- package/dist/client/examples/basic-client.js.map +1 -0
- package/dist/crawler/amtp-crawler.d.ts +125 -0
- package/dist/crawler/amtp-crawler.js +359 -0
- package/dist/crawler/amtp-crawler.js.map +1 -0
- package/dist/crawler/examples/basic-crawler.d.ts +6 -0
- package/dist/crawler/examples/basic-crawler.js +28 -0
- package/dist/crawler/examples/basic-crawler.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +70 -0
- package/dist/index.js.map +1 -0
- package/dist/server/adapters/fastify-adapter.d.ts +86 -0
- package/dist/server/adapters/fastify-adapter.js +169 -0
- package/dist/server/adapters/fastify-adapter.js.map +1 -0
- package/dist/server/amtp-ql-executor.d.ts +24 -0
- package/dist/server/amtp-ql-executor.js +198 -0
- package/dist/server/amtp-ql-executor.js.map +1 -0
- package/dist/server/amtp-ql-parser.d.ts +30 -0
- package/dist/server/amtp-ql-parser.js +212 -0
- package/dist/server/amtp-ql-parser.js.map +1 -0
- package/dist/server/amtp-server.d.ts +183 -0
- package/dist/server/amtp-server.js +650 -0
- package/dist/server/amtp-server.js.map +1 -0
- package/dist/server/examples/basic-server.d.ts +6 -0
- package/dist/server/examples/basic-server.js +215 -0
- package/dist/server/examples/basic-server.js.map +1 -0
- package/dist/server/examples/saas-dashboard-server.d.ts +44 -0
- package/dist/server/examples/saas-dashboard-server.js +387 -0
- package/dist/server/examples/saas-dashboard-server.js.map +1 -0
- package/dist/server/markdown-parser.d.ts +31 -0
- package/dist/server/markdown-parser.js +463 -0
- package/dist/server/markdown-parser.js.map +1 -0
- package/dist/server/notifications.d.ts +40 -0
- package/dist/server/notifications.js +134 -0
- package/dist/server/notifications.js.map +1 -0
- package/dist/server/permissions.d.ts +40 -0
- package/dist/server/permissions.js +156 -0
- package/dist/server/permissions.js.map +1 -0
- package/dist/server/security.d.ts +127 -0
- package/dist/server/security.js +368 -0
- package/dist/server/security.js.map +1 -0
- package/dist/types/amtp.types.d.ts +720 -0
- package/dist/types/amtp.types.js +224 -0
- package/dist/types/amtp.types.js.map +1 -0
- package/package.json +89 -0
|
@@ -0,0 +1,720 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AMTP Protocol - TypeScript Type Definitions
|
|
3
|
+
* Core types, schemas, and interfaces for the Agent Markdown Transfer Protocol
|
|
4
|
+
*/
|
|
5
|
+
/** AMTP Protocol version */
|
|
6
|
+
export type AMTPVersion = "1.0" | "1.1" | "2.0";
|
|
7
|
+
/** Supported MIME types */
|
|
8
|
+
export declare enum MIMEType {
|
|
9
|
+
AMTP_MARKDOWN = "text/amtp+markdown",
|
|
10
|
+
APP_AMTP_MARKDOWN = "application/amtp+markdown",
|
|
11
|
+
MARKDOWN = "text/markdown",
|
|
12
|
+
HTML = "text/html",
|
|
13
|
+
JSON = "application/json",
|
|
14
|
+
EVENT_STREAM = "text/event-stream",
|
|
15
|
+
FORM_URLENCODED = "application/x-www-form-urlencoded"
|
|
16
|
+
}
|
|
17
|
+
/** HTTP methods */
|
|
18
|
+
export declare enum HTTPMethod {
|
|
19
|
+
GET = "GET",
|
|
20
|
+
POST = "POST",
|
|
21
|
+
PUT = "PUT",
|
|
22
|
+
PATCH = "PATCH",
|
|
23
|
+
DELETE = "DELETE",
|
|
24
|
+
HEAD = "HEAD",
|
|
25
|
+
OPTIONS = "OPTIONS"
|
|
26
|
+
}
|
|
27
|
+
/** AMTP Status codes (extend HTTP) */
|
|
28
|
+
export declare enum StatusCode {
|
|
29
|
+
OK = 200,
|
|
30
|
+
CREATED = 201,
|
|
31
|
+
ACCEPTED = 202,
|
|
32
|
+
NO_CONTENT = 204,
|
|
33
|
+
MOVED_PERMANENTLY = 301,
|
|
34
|
+
FOUND = 302,
|
|
35
|
+
NOT_MODIFIED = 304,
|
|
36
|
+
BAD_REQUEST = 400,
|
|
37
|
+
UNAUTHORIZED = 401,
|
|
38
|
+
FORBIDDEN = 403,
|
|
39
|
+
NOT_FOUND = 404,
|
|
40
|
+
CONFLICT = 409,
|
|
41
|
+
UNPROCESSABLE_ENTITY = 422,
|
|
42
|
+
TOO_MANY_REQUESTS = 429,
|
|
43
|
+
INTERNAL_ERROR = 500,
|
|
44
|
+
SERVICE_UNAVAILABLE = 503
|
|
45
|
+
}
|
|
46
|
+
/** AMTP Request headers */
|
|
47
|
+
export interface AMTPRequestHeaders {
|
|
48
|
+
accept?: string;
|
|
49
|
+
"user-agent"?: string;
|
|
50
|
+
"x-amtp-capabilities"?: string;
|
|
51
|
+
"x-session-id"?: string;
|
|
52
|
+
"x-agent-identity"?: string;
|
|
53
|
+
"x-agent-context"?: string;
|
|
54
|
+
authorization?: string;
|
|
55
|
+
[key: string]: string | undefined;
|
|
56
|
+
}
|
|
57
|
+
/** Supported AMTP capabilities */
|
|
58
|
+
export declare enum AgentCapability {
|
|
59
|
+
ACTIONS = "actions",
|
|
60
|
+
STREAMING = "streaming",
|
|
61
|
+
FORMS = "forms",
|
|
62
|
+
TOOLS = "tools",
|
|
63
|
+
MULTIMODAL = "multimodal",
|
|
64
|
+
PAGINATION = "pagination",
|
|
65
|
+
SESSIONS = "sessions",
|
|
66
|
+
FILE_UPLOAD = "file_upload"
|
|
67
|
+
}
|
|
68
|
+
/** AMTP GET request for page */
|
|
69
|
+
export interface AMTPPageRequest {
|
|
70
|
+
path: string;
|
|
71
|
+
headers: AMTPRequestHeaders;
|
|
72
|
+
query?: Record<string, string | string[]>;
|
|
73
|
+
sessionId?: string;
|
|
74
|
+
capabilities?: AgentCapability[];
|
|
75
|
+
}
|
|
76
|
+
/** AMTP action invocation request */
|
|
77
|
+
export interface AMTPActionRequest {
|
|
78
|
+
action: string;
|
|
79
|
+
parameters?: Record<string, unknown>;
|
|
80
|
+
sessionId: string;
|
|
81
|
+
requestId?: string;
|
|
82
|
+
metadata?: Record<string, unknown>;
|
|
83
|
+
}
|
|
84
|
+
/** AMTP Response headers */
|
|
85
|
+
export interface AMTPResponseHeaders {
|
|
86
|
+
"content-type": MIMEType;
|
|
87
|
+
"x-amtp-version": AMTPVersion;
|
|
88
|
+
"x-session-id"?: string;
|
|
89
|
+
"cache-control"?: string;
|
|
90
|
+
etag?: string;
|
|
91
|
+
"x-amtp-next-action"?: string;
|
|
92
|
+
[key: string]: string | undefined;
|
|
93
|
+
}
|
|
94
|
+
/** Successful response wrapper */
|
|
95
|
+
export interface AMTPSuccessResponse<T = unknown> {
|
|
96
|
+
status: "success";
|
|
97
|
+
data?: T;
|
|
98
|
+
metadata?: Record<string, unknown>;
|
|
99
|
+
headers?: AMTPResponseHeaders;
|
|
100
|
+
}
|
|
101
|
+
/** Error response wrapper */
|
|
102
|
+
export interface AMTPErrorResponse {
|
|
103
|
+
status: "error";
|
|
104
|
+
error: {
|
|
105
|
+
code: string;
|
|
106
|
+
message: string;
|
|
107
|
+
details?: Record<string, unknown>;
|
|
108
|
+
requestId?: string;
|
|
109
|
+
timestamp?: string;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/** AMTP Response (union of success/error) */
|
|
113
|
+
export type AMTPResponse<T = unknown> = AMTPSuccessResponse<T> | AMTPErrorResponse;
|
|
114
|
+
/** Markdown AST node types */
|
|
115
|
+
export declare enum MarkdownNodeType {
|
|
116
|
+
DOCUMENT = "document",
|
|
117
|
+
HEADING = "heading",
|
|
118
|
+
PARAGRAPH = "paragraph",
|
|
119
|
+
BLOCKQUOTE = "blockquote",
|
|
120
|
+
LIST = "list",
|
|
121
|
+
LIST_ITEM = "list_item",
|
|
122
|
+
CODE_BLOCK = "code_block",
|
|
123
|
+
INLINE_CODE = "inline_code",
|
|
124
|
+
BOLD = "bold",
|
|
125
|
+
ITALIC = "italic",
|
|
126
|
+
LINK = "link",
|
|
127
|
+
IMAGE = "image",
|
|
128
|
+
VIDEO = "video",
|
|
129
|
+
AUDIO = "audio",
|
|
130
|
+
TABLE = "table",
|
|
131
|
+
THEMATIC_BREAK = "thematic_break",
|
|
132
|
+
ACTION = "action",
|
|
133
|
+
FORM = "form",
|
|
134
|
+
METADATA = "metadata",
|
|
135
|
+
STRUCTURED_DATA = "structured_data"
|
|
136
|
+
}
|
|
137
|
+
/** Markdown AST node */
|
|
138
|
+
export interface MarkdownNode {
|
|
139
|
+
type: MarkdownNodeType;
|
|
140
|
+
children?: MarkdownNode[];
|
|
141
|
+
content?: string;
|
|
142
|
+
url?: string;
|
|
143
|
+
alt?: string;
|
|
144
|
+
title?: string;
|
|
145
|
+
metadata?: Record<string, unknown>;
|
|
146
|
+
/** Agent-facing description extracted from associated amtp-meta block */
|
|
147
|
+
description?: string;
|
|
148
|
+
/** For multimedia: image | video | audio (future) */
|
|
149
|
+
mediaType?: 'image' | 'video' | 'audio';
|
|
150
|
+
}
|
|
151
|
+
/** Parsed AMTP markdown document */
|
|
152
|
+
export interface AMTPDocument {
|
|
153
|
+
type: "document";
|
|
154
|
+
version: AMTPVersion;
|
|
155
|
+
title: string;
|
|
156
|
+
path: string;
|
|
157
|
+
nodes: MarkdownNode[];
|
|
158
|
+
actions: Action[];
|
|
159
|
+
forms: Form[];
|
|
160
|
+
links: Link[];
|
|
161
|
+
metadata: DocumentMetadata;
|
|
162
|
+
structured_data?: StructuredData[];
|
|
163
|
+
/** Pagination information for this document (if the content is paginated) */
|
|
164
|
+
pagination?: Pagination;
|
|
165
|
+
/** Declared permissions for this document or resource (v2.0) */
|
|
166
|
+
permissions?: Permission[];
|
|
167
|
+
/** Access policies binding permissions to roles/conditions (v2.0) */
|
|
168
|
+
policies?: Policy[];
|
|
169
|
+
/** Declared skills (bundled capabilities) for this document (v2.0) */
|
|
170
|
+
skills?: Skill[];
|
|
171
|
+
}
|
|
172
|
+
/** Document metadata */
|
|
173
|
+
export interface DocumentMetadata {
|
|
174
|
+
pageId?: string;
|
|
175
|
+
pageType?: string;
|
|
176
|
+
version?: string;
|
|
177
|
+
updatedAt?: string;
|
|
178
|
+
cacheControl?: string;
|
|
179
|
+
sessionRequired?: boolean;
|
|
180
|
+
[key: string]: unknown;
|
|
181
|
+
}
|
|
182
|
+
/** Parameter types for actions */
|
|
183
|
+
export declare enum ParameterType {
|
|
184
|
+
STRING = "string",
|
|
185
|
+
NUMBER = "number",
|
|
186
|
+
INTEGER = "integer",
|
|
187
|
+
BOOLEAN = "boolean",
|
|
188
|
+
EMAIL = "email",
|
|
189
|
+
URL = "url",
|
|
190
|
+
DATE = "date",
|
|
191
|
+
DATETIME = "datetime",
|
|
192
|
+
PHONE = "phone",
|
|
193
|
+
ENUM = "enum",
|
|
194
|
+
OBJECT = "object",
|
|
195
|
+
ARRAY = "array",
|
|
196
|
+
FILE = "file"
|
|
197
|
+
}
|
|
198
|
+
/** Action parameter schema */
|
|
199
|
+
export interface ActionParameter {
|
|
200
|
+
name: string;
|
|
201
|
+
type: ParameterType;
|
|
202
|
+
required?: boolean;
|
|
203
|
+
description?: string;
|
|
204
|
+
default?: unknown;
|
|
205
|
+
enum?: string[];
|
|
206
|
+
min?: number;
|
|
207
|
+
max?: number;
|
|
208
|
+
pattern?: string;
|
|
209
|
+
validation?: Record<string, unknown>;
|
|
210
|
+
}
|
|
211
|
+
/** Action definition */
|
|
212
|
+
export interface Action {
|
|
213
|
+
id: string;
|
|
214
|
+
label?: string;
|
|
215
|
+
description?: string;
|
|
216
|
+
method: HTTPMethod;
|
|
217
|
+
endpoint: string;
|
|
218
|
+
parameters?: ActionParameter[];
|
|
219
|
+
requiresAuthentication?: boolean;
|
|
220
|
+
idempotent?: boolean;
|
|
221
|
+
timeoutMs?: number;
|
|
222
|
+
expectedOutcomes?: string[];
|
|
223
|
+
rateLimit?: RateLimit;
|
|
224
|
+
permissions?: string[];
|
|
225
|
+
}
|
|
226
|
+
/** Rate limiting configuration */
|
|
227
|
+
export interface RateLimit {
|
|
228
|
+
requests: number;
|
|
229
|
+
window: "second" | "minute" | "hour" | "day";
|
|
230
|
+
burst?: number;
|
|
231
|
+
}
|
|
232
|
+
/** Action invocation result */
|
|
233
|
+
export interface ActionResult {
|
|
234
|
+
actionId: string;
|
|
235
|
+
status: "success" | "error";
|
|
236
|
+
result?: Record<string, unknown>;
|
|
237
|
+
nextActions?: string[];
|
|
238
|
+
redirectTo?: string;
|
|
239
|
+
error?: {
|
|
240
|
+
code: string;
|
|
241
|
+
message: string;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
* A permission grants the bearer the right to perform a set of actions
|
|
246
|
+
* on a specific resource, optionally under constraints.
|
|
247
|
+
*/
|
|
248
|
+
export interface Permission {
|
|
249
|
+
id: string;
|
|
250
|
+
name: string;
|
|
251
|
+
description?: string;
|
|
252
|
+
/** Resource pattern this permission governs (e.g. "workspace:*", "order:read") */
|
|
253
|
+
resource: string;
|
|
254
|
+
/** Action IDs this permission allows on the resource */
|
|
255
|
+
actions: string[];
|
|
256
|
+
/** Optional constraints that narrow when the permission applies */
|
|
257
|
+
constraints?: Record<string, unknown>;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* A policy binds a set of permissions to roles and optionally to conditions.
|
|
261
|
+
* Policies are evaluated at action-execution time.
|
|
262
|
+
*/
|
|
263
|
+
export interface Policy {
|
|
264
|
+
id: string;
|
|
265
|
+
name: string;
|
|
266
|
+
description?: string;
|
|
267
|
+
/** Permission IDs this policy grants */
|
|
268
|
+
permissions: string[];
|
|
269
|
+
/** Roles that receive this policy. Empty means all authenticated sessions. */
|
|
270
|
+
roles?: string[];
|
|
271
|
+
/** Conditions that must be satisfied for this policy to apply */
|
|
272
|
+
conditions?: PolicyCondition[];
|
|
273
|
+
/** Higher priority policies override lower ones (default 0) */
|
|
274
|
+
priority?: number;
|
|
275
|
+
}
|
|
276
|
+
/** Condition expression inside a policy */
|
|
277
|
+
export interface PolicyCondition {
|
|
278
|
+
field: string;
|
|
279
|
+
operator: "eq" | "neq" | "in" | "gt" | "lt" | "contains" | "exists";
|
|
280
|
+
value?: unknown;
|
|
281
|
+
}
|
|
282
|
+
/**
|
|
283
|
+
* A skill bundles actions, permissions, and dependencies into a named
|
|
284
|
+
* capability group that an agent can request or a server can advertise.
|
|
285
|
+
*/
|
|
286
|
+
export interface Skill {
|
|
287
|
+
id: string;
|
|
288
|
+
name: string;
|
|
289
|
+
description?: string;
|
|
290
|
+
/** Action IDs this skill includes */
|
|
291
|
+
actions: string[];
|
|
292
|
+
/** Permission IDs this skill requires or grants */
|
|
293
|
+
permissions?: string[];
|
|
294
|
+
/** IDs of skills that must be acquired first */
|
|
295
|
+
requires?: string[];
|
|
296
|
+
/** Arbitrary metadata (pricing, reputation, etc.) */
|
|
297
|
+
metadata?: Record<string, unknown>;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Recommended Batch Endpoint Pattern:
|
|
301
|
+
*
|
|
302
|
+
* POST /api/amtp/batch
|
|
303
|
+
* Content-Type: application/json
|
|
304
|
+
* Body: AMTPBatchRequest
|
|
305
|
+
*
|
|
306
|
+
* Response:
|
|
307
|
+
* 200 OK with AMTPBatchResponse (even for partial failures)
|
|
308
|
+
* 4xx/5xx only for transport-level errors
|
|
309
|
+
*
|
|
310
|
+
* Semantics:
|
|
311
|
+
* - Each item has a client-generated `requestId` for correlation in results.
|
|
312
|
+
* - `batchId` can be used for idempotency (server should dedup if same batchId + session).
|
|
313
|
+
* - `options.atomic` requests all-or-nothing behavior (server may ignore if not supported).
|
|
314
|
+
* - `options.continueOnError` allows partial success.
|
|
315
|
+
*
|
|
316
|
+
* Error codes in top-level error or per-result:
|
|
317
|
+
* BATCH_PARTIAL, BATCH_ATOMIC_FAILED, ACTION_INVALID, etc.
|
|
318
|
+
*/
|
|
319
|
+
/** Single item in a batch action request */
|
|
320
|
+
export interface BatchActionItem {
|
|
321
|
+
/** Client-provided ID for correlating request and response */
|
|
322
|
+
requestId: string;
|
|
323
|
+
action: string;
|
|
324
|
+
parameters?: Record<string, unknown>;
|
|
325
|
+
}
|
|
326
|
+
/** Request to execute multiple actions in one call */
|
|
327
|
+
export interface AMTPBatchRequest {
|
|
328
|
+
/** Optional server-generated or client-provided batch identifier */
|
|
329
|
+
batchId?: string;
|
|
330
|
+
actions: BatchActionItem[];
|
|
331
|
+
options?: {
|
|
332
|
+
/** If true, all actions must succeed or the entire batch is rolled back (if supported by server) */
|
|
333
|
+
atomic?: boolean;
|
|
334
|
+
/** Continue processing remaining actions even if some fail */
|
|
335
|
+
continueOnError?: boolean;
|
|
336
|
+
/** Maximum time for the entire batch */
|
|
337
|
+
timeoutMs?: number;
|
|
338
|
+
};
|
|
339
|
+
sessionId?: string;
|
|
340
|
+
metadata?: Record<string, unknown>;
|
|
341
|
+
}
|
|
342
|
+
/** Response from a batch action execution */
|
|
343
|
+
export interface AMTPBatchResponse {
|
|
344
|
+
batchId?: string;
|
|
345
|
+
/** Overall status of the batch */
|
|
346
|
+
status: 'success' | 'partial' | 'failed';
|
|
347
|
+
/** Individual results in the same order as the request */
|
|
348
|
+
results: ActionResult[];
|
|
349
|
+
error?: {
|
|
350
|
+
code: string;
|
|
351
|
+
message: string;
|
|
352
|
+
/** List of requestIds that failed (when partial or failed) */
|
|
353
|
+
failedRequestIds?: string[];
|
|
354
|
+
};
|
|
355
|
+
metadata?: Record<string, unknown>;
|
|
356
|
+
}
|
|
357
|
+
/** Form field types */
|
|
358
|
+
export declare enum FormFieldType {
|
|
359
|
+
TEXT = "text",
|
|
360
|
+
EMAIL = "email",
|
|
361
|
+
PASSWORD = "password",
|
|
362
|
+
NUMBER = "number",
|
|
363
|
+
CHECKBOX = "checkbox",
|
|
364
|
+
RADIO = "radio",
|
|
365
|
+
SELECT = "select",
|
|
366
|
+
TEXTAREA = "textarea",
|
|
367
|
+
FILE = "file",
|
|
368
|
+
DATE = "date",
|
|
369
|
+
TIME = "time",
|
|
370
|
+
DATETIME = "datetime",
|
|
371
|
+
HIDDEN = "hidden"
|
|
372
|
+
}
|
|
373
|
+
/** Form field definition */
|
|
374
|
+
export interface FormField {
|
|
375
|
+
name: string;
|
|
376
|
+
type: FormFieldType;
|
|
377
|
+
label?: string;
|
|
378
|
+
placeholder?: string;
|
|
379
|
+
description?: string;
|
|
380
|
+
required?: boolean;
|
|
381
|
+
default?: unknown;
|
|
382
|
+
options?: FormOption[];
|
|
383
|
+
validation?: FieldValidation;
|
|
384
|
+
maxLength?: number;
|
|
385
|
+
minLength?: number;
|
|
386
|
+
pattern?: string;
|
|
387
|
+
multiple?: boolean;
|
|
388
|
+
accept?: string;
|
|
389
|
+
}
|
|
390
|
+
/** Form option (for select, radio) */
|
|
391
|
+
export interface FormOption {
|
|
392
|
+
value: string;
|
|
393
|
+
label: string;
|
|
394
|
+
disabled?: boolean;
|
|
395
|
+
}
|
|
396
|
+
/** Field validation rule */
|
|
397
|
+
export interface FieldValidation {
|
|
398
|
+
type: "email" | "url" | "phone" | "pattern" | "custom";
|
|
399
|
+
pattern?: string;
|
|
400
|
+
message?: string;
|
|
401
|
+
[key: string]: unknown;
|
|
402
|
+
}
|
|
403
|
+
/** Form definition */
|
|
404
|
+
export interface Form {
|
|
405
|
+
id: string;
|
|
406
|
+
action: string;
|
|
407
|
+
method: HTTPMethod;
|
|
408
|
+
endpoint: string;
|
|
409
|
+
label?: string;
|
|
410
|
+
description?: string;
|
|
411
|
+
fields: FormField[];
|
|
412
|
+
submitLabel?: string;
|
|
413
|
+
cancelLabel?: string;
|
|
414
|
+
multipart?: boolean;
|
|
415
|
+
csrfToken?: string;
|
|
416
|
+
}
|
|
417
|
+
/** Form submission */
|
|
418
|
+
export interface FormSubmission {
|
|
419
|
+
formId: string;
|
|
420
|
+
values: Record<string, unknown>;
|
|
421
|
+
sessionId?: string;
|
|
422
|
+
requestId?: string;
|
|
423
|
+
}
|
|
424
|
+
/** Link types */
|
|
425
|
+
export declare enum LinkType {
|
|
426
|
+
INTERNAL = "internal",
|
|
427
|
+
EXTERNAL = "external",
|
|
428
|
+
ACTION = "action",
|
|
429
|
+
NAVIGATION = "navigation"
|
|
430
|
+
}
|
|
431
|
+
/** Link definition */
|
|
432
|
+
export interface Link {
|
|
433
|
+
text: string;
|
|
434
|
+
url: string;
|
|
435
|
+
type: LinkType;
|
|
436
|
+
title?: string;
|
|
437
|
+
method?: HTTPMethod;
|
|
438
|
+
data?: Record<string, unknown>;
|
|
439
|
+
}
|
|
440
|
+
/** Cursor for cursor-based pagination (preferred for agents) */
|
|
441
|
+
export interface Cursor {
|
|
442
|
+
value: string;
|
|
443
|
+
/** Direction for bidirectional cursors */
|
|
444
|
+
direction?: 'forward' | 'backward';
|
|
445
|
+
}
|
|
446
|
+
/** Modern page info (GraphQL-inspired but lightweight) */
|
|
447
|
+
export interface PageInfo {
|
|
448
|
+
hasNextPage: boolean;
|
|
449
|
+
hasPreviousPage: boolean;
|
|
450
|
+
startCursor?: string;
|
|
451
|
+
endCursor?: string;
|
|
452
|
+
/** Total count is optional because counting can be expensive on large datasets */
|
|
453
|
+
totalCount?: number;
|
|
454
|
+
}
|
|
455
|
+
/** Pagination metadata — supports both simple page-based and advanced cursor-based */
|
|
456
|
+
export interface Pagination {
|
|
457
|
+
currentPage?: number;
|
|
458
|
+
totalPages?: number;
|
|
459
|
+
itemsPerPage?: number;
|
|
460
|
+
totalItems?: number;
|
|
461
|
+
hasNextPage?: boolean;
|
|
462
|
+
hasPreviousPage?: boolean;
|
|
463
|
+
nextUrl?: string;
|
|
464
|
+
previousUrl?: string;
|
|
465
|
+
pageInfo?: PageInfo;
|
|
466
|
+
nextCursor?: string;
|
|
467
|
+
previousCursor?: string;
|
|
468
|
+
/** The cursor that was used to fetch this page */
|
|
469
|
+
currentCursor?: string;
|
|
470
|
+
}
|
|
471
|
+
/** Authentication method */
|
|
472
|
+
export declare enum AuthMethod {
|
|
473
|
+
SESSION_TOKEN = "session_token",
|
|
474
|
+
BEARER_TOKEN = "bearer_token",
|
|
475
|
+
JWT = "jwt",
|
|
476
|
+
API_KEY = "api_key",
|
|
477
|
+
BASIC = "basic"
|
|
478
|
+
}
|
|
479
|
+
/** Session data */
|
|
480
|
+
export interface Session {
|
|
481
|
+
sessionId: string;
|
|
482
|
+
userId?: string;
|
|
483
|
+
username?: string;
|
|
484
|
+
email?: string;
|
|
485
|
+
createdAt: string;
|
|
486
|
+
expiresAt: string;
|
|
487
|
+
lastActivityAt: string;
|
|
488
|
+
capabilities: string[];
|
|
489
|
+
permissions: string[];
|
|
490
|
+
preferences?: Record<string, unknown>;
|
|
491
|
+
metadata?: Record<string, unknown>;
|
|
492
|
+
}
|
|
493
|
+
/** Login request */
|
|
494
|
+
export interface LoginRequest {
|
|
495
|
+
username: string;
|
|
496
|
+
password: string;
|
|
497
|
+
rememberMe?: boolean;
|
|
498
|
+
}
|
|
499
|
+
/** Login response */
|
|
500
|
+
export interface LoginResponse {
|
|
501
|
+
sessionId: string;
|
|
502
|
+
userId: string;
|
|
503
|
+
username: string;
|
|
504
|
+
expiresAt: string;
|
|
505
|
+
capabilities: string[];
|
|
506
|
+
preferences?: Record<string, unknown>;
|
|
507
|
+
}
|
|
508
|
+
/** Server-sent event */
|
|
509
|
+
export interface ServerSentEvent {
|
|
510
|
+
event: string;
|
|
511
|
+
data: Record<string, unknown>;
|
|
512
|
+
id?: string;
|
|
513
|
+
retry?: number;
|
|
514
|
+
}
|
|
515
|
+
/** Streaming update types */
|
|
516
|
+
export declare enum StreamUpdateType {
|
|
517
|
+
PAGE_UPDATE = "page_update",
|
|
518
|
+
ITEM_ADDED = "item_added",
|
|
519
|
+
ITEM_REMOVED = "item_removed",
|
|
520
|
+
ITEM_UPDATED = "item_updated",
|
|
521
|
+
PRICE_CHANGED = "price_changed",
|
|
522
|
+
STOCK_CHANGED = "stock_changed",
|
|
523
|
+
STATUS_CHANGED = "status_changed",
|
|
524
|
+
ERROR = "error",
|
|
525
|
+
COMPLETED = "completed"
|
|
526
|
+
}
|
|
527
|
+
/** Streaming update */
|
|
528
|
+
export interface StreamUpdate {
|
|
529
|
+
type: StreamUpdateType;
|
|
530
|
+
data: Record<string, unknown>;
|
|
531
|
+
timestamp: string;
|
|
532
|
+
}
|
|
533
|
+
/** Types of events that can trigger notifications */
|
|
534
|
+
export declare enum NotificationEventType {
|
|
535
|
+
ORDER_UPDATED = "order.updated",
|
|
536
|
+
ORDER_SHIPPED = "order.shipped",
|
|
537
|
+
NEW_MESSAGE = "message.new",
|
|
538
|
+
WORKSPACE_UPDATED = "workspace.updated",
|
|
539
|
+
ITEM_PRICE_CHANGED = "item.price_changed",
|
|
540
|
+
SESSION_EXPIRED = "session.expired",
|
|
541
|
+
ACTION_REQUIRED = "action.required"
|
|
542
|
+
}
|
|
543
|
+
/** Payload for a notification event (used in both SSE and webhooks) */
|
|
544
|
+
export interface NotificationEvent {
|
|
545
|
+
id: string;
|
|
546
|
+
type: NotificationEventType | string;
|
|
547
|
+
timestamp: string;
|
|
548
|
+
/** The main payload (e.g. order details, message, etc.) */
|
|
549
|
+
data: Record<string, unknown>;
|
|
550
|
+
/** Optional metadata (sessionId, userId, etc.) */
|
|
551
|
+
metadata?: Record<string, unknown>;
|
|
552
|
+
}
|
|
553
|
+
/** Webhook subscription registered by an agent */
|
|
554
|
+
export interface WebhookSubscription {
|
|
555
|
+
id: string;
|
|
556
|
+
/** URL the server will POST events to */
|
|
557
|
+
url: string;
|
|
558
|
+
/** List of event types this webhook cares about */
|
|
559
|
+
events: Array<NotificationEventType | string>;
|
|
560
|
+
/** Secret used by server to sign the payload (HMAC-SHA256) */
|
|
561
|
+
secret?: string;
|
|
562
|
+
createdAt: string;
|
|
563
|
+
active: boolean;
|
|
564
|
+
/** Optional description for the agent */
|
|
565
|
+
description?: string;
|
|
566
|
+
}
|
|
567
|
+
/** Request to register a new webhook */
|
|
568
|
+
export interface RegisterWebhookRequest {
|
|
569
|
+
url: string;
|
|
570
|
+
events: Array<NotificationEventType | string>;
|
|
571
|
+
secret?: string;
|
|
572
|
+
description?: string;
|
|
573
|
+
}
|
|
574
|
+
/** Response after registering a webhook */
|
|
575
|
+
export interface RegisterWebhookResponse {
|
|
576
|
+
subscription: WebhookSubscription;
|
|
577
|
+
/** Example curl to test the webhook */
|
|
578
|
+
testCommand?: string;
|
|
579
|
+
}
|
|
580
|
+
/** Structured data type */
|
|
581
|
+
export type StructuredDataType = "Product" | "Event" | "Person" | "Organization" | "LocalBusiness" | "Article" | "BlogPosting" | "Review" | "AggregateRating" | "Offer" | "Order" | "Invoice" | "Unknown";
|
|
582
|
+
/** Structured data */
|
|
583
|
+
export interface StructuredData {
|
|
584
|
+
"@context"?: string;
|
|
585
|
+
"@type": StructuredDataType;
|
|
586
|
+
name?: string;
|
|
587
|
+
description?: string;
|
|
588
|
+
url?: string;
|
|
589
|
+
image?: string;
|
|
590
|
+
[key: string]: unknown;
|
|
591
|
+
}
|
|
592
|
+
/** Error codes */
|
|
593
|
+
export declare enum ErrorCode {
|
|
594
|
+
VALIDATION_ERROR = "VALIDATION_ERROR",
|
|
595
|
+
AUTH_REQUIRED = "AUTH_REQUIRED",
|
|
596
|
+
PERMISSION_DENIED = "PERMISSION_DENIED",
|
|
597
|
+
RESOURCE_NOT_FOUND = "RESOURCE_NOT_FOUND",
|
|
598
|
+
INVALID_REQUEST = "INVALID_REQUEST",
|
|
599
|
+
RATE_LIMITED = "RATE_LIMITED",
|
|
600
|
+
SERVER_ERROR = "SERVER_ERROR",
|
|
601
|
+
SERVICE_UNAVAILABLE = "SERVICE_UNAVAILABLE",
|
|
602
|
+
CONFLICT = "CONFLICT",
|
|
603
|
+
INVALID_STATE = "INVALID_STATE"
|
|
604
|
+
}
|
|
605
|
+
/** Error detail */
|
|
606
|
+
export interface ErrorDetail {
|
|
607
|
+
field?: string;
|
|
608
|
+
code: ErrorCode;
|
|
609
|
+
message: string;
|
|
610
|
+
suggestion?: string;
|
|
611
|
+
}
|
|
612
|
+
/** AMTP Error */
|
|
613
|
+
export declare class AMTPError extends Error {
|
|
614
|
+
code: ErrorCode;
|
|
615
|
+
statusCode: StatusCode;
|
|
616
|
+
details?: ErrorDetail[] | undefined;
|
|
617
|
+
constructor(code: ErrorCode, message: string, statusCode?: StatusCode, details?: ErrorDetail[] | undefined);
|
|
618
|
+
}
|
|
619
|
+
/** Page request options */
|
|
620
|
+
export interface PageRequestOptions {
|
|
621
|
+
sessionId?: string;
|
|
622
|
+
capabilities?: AgentCapability[];
|
|
623
|
+
headers?: Record<string, string>;
|
|
624
|
+
query?: Record<string, string | string[]>;
|
|
625
|
+
}
|
|
626
|
+
/** Page response options */
|
|
627
|
+
export interface PageResponseOptions {
|
|
628
|
+
cacheControl?: string;
|
|
629
|
+
etag?: string;
|
|
630
|
+
sessionId?: string;
|
|
631
|
+
nextAction?: string;
|
|
632
|
+
}
|
|
633
|
+
/** Middleware context */
|
|
634
|
+
export interface AMTPContext {
|
|
635
|
+
request: AMTPPageRequest;
|
|
636
|
+
response: {
|
|
637
|
+
statusCode: StatusCode;
|
|
638
|
+
headers: AMTPResponseHeaders;
|
|
639
|
+
body?: AMTPDocument | string;
|
|
640
|
+
};
|
|
641
|
+
session?: Session;
|
|
642
|
+
user?: {
|
|
643
|
+
id: string;
|
|
644
|
+
username: string;
|
|
645
|
+
[key: string]: unknown;
|
|
646
|
+
};
|
|
647
|
+
state: Record<string, unknown>;
|
|
648
|
+
/** Permissions resolved for the current session against the current document (v2.0) */
|
|
649
|
+
resolvedPermissions?: string[];
|
|
650
|
+
}
|
|
651
|
+
/** Middleware function */
|
|
652
|
+
export type AMTPMiddleware = (context: AMTPContext, next: () => Promise<void>) => Promise<void>;
|
|
653
|
+
/** Handler function */
|
|
654
|
+
export type AMTPHandler = (request: AMTPPageRequest) => Promise<AMTPDocument | string>;
|
|
655
|
+
/** Content negotiation result */
|
|
656
|
+
export interface ContentNegotiation {
|
|
657
|
+
mimeType: MIMEType;
|
|
658
|
+
quality: number;
|
|
659
|
+
charSet?: string;
|
|
660
|
+
}
|
|
661
|
+
/** Raw AMTP-QL query string (GraphQL-inspired) */
|
|
662
|
+
export interface AMTPQLQuery {
|
|
663
|
+
raw: string;
|
|
664
|
+
variables?: Record<string, unknown>;
|
|
665
|
+
}
|
|
666
|
+
/** Result of executing an AMTP-QL query (projected document parts) */
|
|
667
|
+
export interface AMTPQLResult {
|
|
668
|
+
title?: string;
|
|
669
|
+
path?: string;
|
|
670
|
+
version?: string;
|
|
671
|
+
metadata?: Partial<DocumentMetadata>;
|
|
672
|
+
pagination?: Pagination;
|
|
673
|
+
actions?: Array<Pick<Action, 'id' | 'description' | 'parameters'>>;
|
|
674
|
+
forms?: Array<Pick<Form, 'id' | 'fields'>>;
|
|
675
|
+
links?: Array<Pick<Link, 'text' | 'url' | 'type'>>;
|
|
676
|
+
structured_data?: StructuredData[];
|
|
677
|
+
nodes?: Array<Partial<MarkdownNode> & {
|
|
678
|
+
type: MarkdownNodeType;
|
|
679
|
+
}>;
|
|
680
|
+
permissions?: Permission[];
|
|
681
|
+
policies?: Policy[];
|
|
682
|
+
skills?: Skill[];
|
|
683
|
+
}
|
|
684
|
+
/** Server request for /api/amtp/query */
|
|
685
|
+
export interface AMTPQLQueryRequest {
|
|
686
|
+
query: string;
|
|
687
|
+
variables?: Record<string, unknown>;
|
|
688
|
+
}
|
|
689
|
+
/** Server response for AMTP-QL (data or errors) */
|
|
690
|
+
export interface AMTPQLQueryResponse {
|
|
691
|
+
data?: AMTPQLResult;
|
|
692
|
+
errors?: Array<{
|
|
693
|
+
message: string;
|
|
694
|
+
path?: string[];
|
|
695
|
+
extensions?: Record<string, unknown>;
|
|
696
|
+
}>;
|
|
697
|
+
}
|
|
698
|
+
/** Parsed internal representation (for parser/executor) */
|
|
699
|
+
export interface AMTPQLSelection {
|
|
700
|
+
field: string;
|
|
701
|
+
arguments?: Record<string, unknown>;
|
|
702
|
+
selections?: AMTPQLSelection[];
|
|
703
|
+
}
|
|
704
|
+
export interface AMTPQLParsedQuery {
|
|
705
|
+
selections: AMTPQLSelection[];
|
|
706
|
+
}
|
|
707
|
+
declare const _default: {
|
|
708
|
+
MIMEType: typeof MIMEType;
|
|
709
|
+
HTTPMethod: typeof HTTPMethod;
|
|
710
|
+
StatusCode: typeof StatusCode;
|
|
711
|
+
AgentCapability: typeof AgentCapability;
|
|
712
|
+
MarkdownNodeType: typeof MarkdownNodeType;
|
|
713
|
+
ParameterType: typeof ParameterType;
|
|
714
|
+
FormFieldType: typeof FormFieldType;
|
|
715
|
+
LinkType: typeof LinkType;
|
|
716
|
+
AuthMethod: typeof AuthMethod;
|
|
717
|
+
StreamUpdateType: typeof StreamUpdateType;
|
|
718
|
+
ErrorCode: typeof ErrorCode;
|
|
719
|
+
};
|
|
720
|
+
export default _default;
|