@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,460 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* AMTP Agent Client SDK
|
|
4
|
+
* TypeScript SDK for AI agents to interact with AMTP servers
|
|
5
|
+
*/
|
|
6
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
7
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
8
|
+
};
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AutonomousAgent = exports.AMTPMarkdownParser = exports.AMTPClient = void 0;
|
|
11
|
+
const crypto_1 = __importDefault(require("crypto"));
|
|
12
|
+
const amtp_types_1 = require("../types/amtp.types");
|
|
13
|
+
/**
|
|
14
|
+
* AMTP Agent Client
|
|
15
|
+
* Main client for agents to interact with AMTP servers
|
|
16
|
+
*/
|
|
17
|
+
class AMTPClient {
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.baseUrl = config.baseUrl;
|
|
20
|
+
this.sessionId = config.sessionId;
|
|
21
|
+
this.timeout = config.timeout || 30000;
|
|
22
|
+
this.maxRetries = config.maxRetries || 3;
|
|
23
|
+
this.capabilities = config.capabilities || [
|
|
24
|
+
"actions",
|
|
25
|
+
"streaming",
|
|
26
|
+
"forms",
|
|
27
|
+
];
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Set session ID
|
|
31
|
+
*/
|
|
32
|
+
setSessionId(sessionId) {
|
|
33
|
+
this.sessionId = sessionId;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Get session ID
|
|
37
|
+
*/
|
|
38
|
+
getSessionId() {
|
|
39
|
+
return this.sessionId;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Fetch a page (supports cursor-based pagination)
|
|
43
|
+
*/
|
|
44
|
+
async getPage(path, options) {
|
|
45
|
+
let url = `${this.baseUrl}${path}`;
|
|
46
|
+
if (options?.cursor) {
|
|
47
|
+
const separator = path.includes('?') ? '&' : '?';
|
|
48
|
+
url += `${separator}cursor=${encodeURIComponent(options.cursor)}`;
|
|
49
|
+
}
|
|
50
|
+
const response = await this.fetchWithRetry(url, {
|
|
51
|
+
method: "GET",
|
|
52
|
+
headers: this.buildHeaders(),
|
|
53
|
+
});
|
|
54
|
+
if (response.status !== amtp_types_1.StatusCode.OK) {
|
|
55
|
+
throw new Error(`Failed to fetch page: ${response.status} ${response.statusText}`);
|
|
56
|
+
}
|
|
57
|
+
const markdown = await response.text();
|
|
58
|
+
const parser = new AMTPMarkdownParser();
|
|
59
|
+
return parser.parse(markdown, path);
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Convenience method: fetch the next page using the pagination info from the current document.
|
|
63
|
+
* Returns null if there is no next page/cursor.
|
|
64
|
+
*/
|
|
65
|
+
async getNextPage(currentDoc) {
|
|
66
|
+
const pagination = currentDoc.pagination;
|
|
67
|
+
if (!pagination)
|
|
68
|
+
return null;
|
|
69
|
+
const nextCursor = pagination.nextCursor || pagination.pageInfo?.endCursor;
|
|
70
|
+
if (!nextCursor)
|
|
71
|
+
return null;
|
|
72
|
+
// Try to extract base path from the document
|
|
73
|
+
const basePath = currentDoc.path || '/';
|
|
74
|
+
return this.getPage(basePath, { cursor: nextCursor });
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Extract all media nodes (images, video, audio) from a document.
|
|
78
|
+
* These now include rich `description` from amtp-meta blocks for agents.
|
|
79
|
+
*/
|
|
80
|
+
getMedia(doc) {
|
|
81
|
+
return doc.nodes.filter((n) => n.type === "image" || n.type === "video" || n.type === "audio");
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* Execute an action
|
|
85
|
+
*/
|
|
86
|
+
async executeAction(action, parameters) {
|
|
87
|
+
const url = `${this.baseUrl}/api/amtp/action`;
|
|
88
|
+
const request = {
|
|
89
|
+
action,
|
|
90
|
+
parameters,
|
|
91
|
+
sessionId: this.sessionId || "",
|
|
92
|
+
requestId: this.generateRequestId(),
|
|
93
|
+
};
|
|
94
|
+
const response = await this.fetchWithRetry(url, {
|
|
95
|
+
method: "POST",
|
|
96
|
+
headers: this.buildHeaders("application/json"),
|
|
97
|
+
body: JSON.stringify(request),
|
|
98
|
+
});
|
|
99
|
+
return response.json();
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Execute multiple actions in a single batch request (v1.1).
|
|
103
|
+
* See AMTPBatchRequest for options (atomic, continueOnError, etc.).
|
|
104
|
+
*/
|
|
105
|
+
async executeBatch(actions, options) {
|
|
106
|
+
const url = `${this.baseUrl}/api/amtp/batch`;
|
|
107
|
+
const items = actions.map((a, index) => ({
|
|
108
|
+
requestId: `batch_${this.generateRequestId()}_${index}`,
|
|
109
|
+
action: a.action,
|
|
110
|
+
parameters: a.parameters,
|
|
111
|
+
}));
|
|
112
|
+
const request = {
|
|
113
|
+
actions: items,
|
|
114
|
+
options,
|
|
115
|
+
sessionId: this.sessionId,
|
|
116
|
+
metadata: {},
|
|
117
|
+
};
|
|
118
|
+
const response = await this.fetchWithRetry(url, {
|
|
119
|
+
method: "POST",
|
|
120
|
+
headers: this.buildHeaders("application/json"),
|
|
121
|
+
body: JSON.stringify(request),
|
|
122
|
+
});
|
|
123
|
+
if (response.status >= 400) {
|
|
124
|
+
throw new Error(`Batch request failed: ${response.status}`);
|
|
125
|
+
}
|
|
126
|
+
return response.json();
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* Execute an AMTP-QL query (v2.0) against the current document context.
|
|
130
|
+
* Returns the projected result (much smaller than full document).
|
|
131
|
+
*/
|
|
132
|
+
async query(rawQuery, variables) {
|
|
133
|
+
const url = `${this.baseUrl}/api/amtp/query`;
|
|
134
|
+
const request = {
|
|
135
|
+
query: rawQuery,
|
|
136
|
+
variables,
|
|
137
|
+
};
|
|
138
|
+
const response = await this.fetchWithRetry(url, {
|
|
139
|
+
method: "POST",
|
|
140
|
+
headers: this.buildHeaders("application/json"),
|
|
141
|
+
body: JSON.stringify(request),
|
|
142
|
+
});
|
|
143
|
+
if (response.status >= 400) {
|
|
144
|
+
const err = await response.json().catch(() => ({ error: { message: "" } }));
|
|
145
|
+
throw new Error(`AMTP-QL query failed: ${response.status} ${err?.error?.message || ""}`);
|
|
146
|
+
}
|
|
147
|
+
const json = await response.json();
|
|
148
|
+
if (json.errors?.length) {
|
|
149
|
+
throw new Error(`AMTP-QL errors: ${json.errors.map(e => e.message).join("; ")}`);
|
|
150
|
+
}
|
|
151
|
+
return json.data || {};
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Register a webhook for push notifications (v2.0)
|
|
155
|
+
*/
|
|
156
|
+
async registerWebhook(payload) {
|
|
157
|
+
const res = await this.fetchWithRetry(`${this.baseUrl}/api/webhooks`, {
|
|
158
|
+
method: "POST",
|
|
159
|
+
headers: this.buildHeaders("application/json"),
|
|
160
|
+
body: JSON.stringify(payload),
|
|
161
|
+
});
|
|
162
|
+
return res.json();
|
|
163
|
+
}
|
|
164
|
+
/**
|
|
165
|
+
* List registered webhooks
|
|
166
|
+
*/
|
|
167
|
+
async listWebhooks() {
|
|
168
|
+
const res = await this.fetchWithRetry(`${this.baseUrl}/api/webhooks`, {
|
|
169
|
+
headers: this.buildHeaders(),
|
|
170
|
+
});
|
|
171
|
+
return res.json();
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Submit a form
|
|
175
|
+
*/
|
|
176
|
+
async submitForm(form, values) {
|
|
177
|
+
const url = `${this.baseUrl}${form.endpoint}`;
|
|
178
|
+
const submission = {
|
|
179
|
+
formId: form.id,
|
|
180
|
+
values,
|
|
181
|
+
sessionId: this.sessionId,
|
|
182
|
+
requestId: this.generateRequestId(),
|
|
183
|
+
};
|
|
184
|
+
const response = await this.fetchWithRetry(url, {
|
|
185
|
+
method: form.method,
|
|
186
|
+
headers: this.buildHeaders("application/json"),
|
|
187
|
+
body: JSON.stringify(submission),
|
|
188
|
+
});
|
|
189
|
+
return response.json();
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Navigate to a URL
|
|
193
|
+
*/
|
|
194
|
+
async navigate(path) {
|
|
195
|
+
return this.getPage(path);
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Click a link
|
|
199
|
+
*/
|
|
200
|
+
async clickLink(url) {
|
|
201
|
+
return this.getPage(url);
|
|
202
|
+
}
|
|
203
|
+
/**
|
|
204
|
+
* Login
|
|
205
|
+
*/
|
|
206
|
+
async login(username, password) {
|
|
207
|
+
const url = `${this.baseUrl}/api/amtp/login`;
|
|
208
|
+
const response = await this.fetchWithRetry(url, {
|
|
209
|
+
method: "POST",
|
|
210
|
+
headers: this.buildHeaders("application/json"),
|
|
211
|
+
body: JSON.stringify({ username, password }),
|
|
212
|
+
});
|
|
213
|
+
const data = (await response.json());
|
|
214
|
+
this.sessionId = data.sessionId;
|
|
215
|
+
return data;
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Logout
|
|
219
|
+
*/
|
|
220
|
+
async logout() {
|
|
221
|
+
const url = `${this.baseUrl}/api/amtp/logout`;
|
|
222
|
+
await this.fetchWithRetry(url, {
|
|
223
|
+
method: "POST",
|
|
224
|
+
headers: this.buildHeaders(),
|
|
225
|
+
});
|
|
226
|
+
this.sessionId = undefined;
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Stream updates from server
|
|
230
|
+
*/
|
|
231
|
+
streamUpdates(path, callback) {
|
|
232
|
+
const url = `${this.baseUrl}${path}?sessionId=${this.sessionId}`;
|
|
233
|
+
const eventSource = new EventSource(url);
|
|
234
|
+
eventSource.onmessage = (event) => {
|
|
235
|
+
const update = JSON.parse(event.data);
|
|
236
|
+
callback(update);
|
|
237
|
+
};
|
|
238
|
+
return eventSource;
|
|
239
|
+
}
|
|
240
|
+
/**
|
|
241
|
+
* Get available actions on a page
|
|
242
|
+
*/
|
|
243
|
+
async getActions(path) {
|
|
244
|
+
const doc = await this.getPage(path);
|
|
245
|
+
return doc.actions;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Get available forms on a page
|
|
249
|
+
*/
|
|
250
|
+
async getForms(path) {
|
|
251
|
+
const doc = await this.getPage(path);
|
|
252
|
+
return doc.forms;
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* Search page content
|
|
256
|
+
*/
|
|
257
|
+
async search(query, limit) {
|
|
258
|
+
const path = `/search?q=${encodeURIComponent(query)}` +
|
|
259
|
+
(limit ? `&limit=${limit}` : "");
|
|
260
|
+
return this.getPage(path);
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* Build request headers
|
|
264
|
+
*/
|
|
265
|
+
buildHeaders(contentType) {
|
|
266
|
+
const headers = {
|
|
267
|
+
Accept: "text/amtp+markdown",
|
|
268
|
+
"X-AMTP-Capabilities": this.capabilities.join(","),
|
|
269
|
+
"User-Agent": "AMTP-Agent/1.0",
|
|
270
|
+
};
|
|
271
|
+
if (contentType) {
|
|
272
|
+
headers["Content-Type"] = contentType;
|
|
273
|
+
}
|
|
274
|
+
if (this.sessionId) {
|
|
275
|
+
headers["X-Session-ID"] = this.sessionId;
|
|
276
|
+
}
|
|
277
|
+
return headers;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Fetch with retry logic
|
|
281
|
+
*/
|
|
282
|
+
async fetchWithRetry(url, options, attempt = 1) {
|
|
283
|
+
try {
|
|
284
|
+
const controller = new AbortController();
|
|
285
|
+
const timeout = setTimeout(() => controller.abort(), this.timeout);
|
|
286
|
+
const response = await fetch(url, {
|
|
287
|
+
...options,
|
|
288
|
+
signal: controller.signal,
|
|
289
|
+
});
|
|
290
|
+
clearTimeout(timeout);
|
|
291
|
+
return response;
|
|
292
|
+
}
|
|
293
|
+
catch (error) {
|
|
294
|
+
if (attempt < this.maxRetries) {
|
|
295
|
+
const backoffMs = Math.pow(2, attempt) * 1000;
|
|
296
|
+
await new Promise((resolve) => setTimeout(resolve, backoffMs));
|
|
297
|
+
return this.fetchWithRetry(url, options, attempt + 1);
|
|
298
|
+
}
|
|
299
|
+
throw error;
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* Generate unique request ID
|
|
304
|
+
*/
|
|
305
|
+
generateRequestId() {
|
|
306
|
+
return `req_${Date.now()}_${crypto_1.default.randomBytes(4).toString("hex")}`;
|
|
307
|
+
}
|
|
308
|
+
}
|
|
309
|
+
exports.AMTPClient = AMTPClient;
|
|
310
|
+
/**
|
|
311
|
+
* Simple Markdown Parser for Client
|
|
312
|
+
*/
|
|
313
|
+
class AMTPMarkdownParser {
|
|
314
|
+
parse(markdown, path) {
|
|
315
|
+
// Simplified parser for client-side use
|
|
316
|
+
const lines = markdown.split("\n");
|
|
317
|
+
const titleMatch = lines[0]?.match(/^# (.+)$/);
|
|
318
|
+
const title = titleMatch?.[1] || "Untitled";
|
|
319
|
+
return {
|
|
320
|
+
type: "document",
|
|
321
|
+
version: "1.0",
|
|
322
|
+
title,
|
|
323
|
+
path,
|
|
324
|
+
nodes: [],
|
|
325
|
+
actions: this.extractActions(markdown),
|
|
326
|
+
forms: this.extractForms(markdown),
|
|
327
|
+
links: this.extractLinks(markdown),
|
|
328
|
+
metadata: {},
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
extractActions(markdown) {
|
|
332
|
+
const actions = [];
|
|
333
|
+
const actionRegex = /\[([A-Z_0-9]+)\]/g;
|
|
334
|
+
let match;
|
|
335
|
+
while ((match = actionRegex.exec(markdown)) !== null) {
|
|
336
|
+
const name = match[1];
|
|
337
|
+
actions.push({
|
|
338
|
+
id: name.toLowerCase(),
|
|
339
|
+
label: name,
|
|
340
|
+
method: amtp_types_1.HTTPMethod.POST,
|
|
341
|
+
endpoint: `/api/actions/${name.toLowerCase()}`,
|
|
342
|
+
});
|
|
343
|
+
}
|
|
344
|
+
return [...new Map(actions.map((a) => [a.id, a])).values()];
|
|
345
|
+
}
|
|
346
|
+
extractForms(markdown) {
|
|
347
|
+
const forms = [];
|
|
348
|
+
const formRegex = /ACTION:\s*(\w+)[\s\S]*?METHOD:\s*(\w+)[\s\S]*?ENDPOINT:\s*(\S+)/g;
|
|
349
|
+
let match;
|
|
350
|
+
while ((match = formRegex.exec(markdown)) !== null) {
|
|
351
|
+
const [, name, method, endpoint] = match;
|
|
352
|
+
forms.push({
|
|
353
|
+
id: name,
|
|
354
|
+
action: name,
|
|
355
|
+
method: method.toUpperCase(),
|
|
356
|
+
endpoint,
|
|
357
|
+
fields: [],
|
|
358
|
+
});
|
|
359
|
+
}
|
|
360
|
+
return forms;
|
|
361
|
+
}
|
|
362
|
+
extractLinks(markdown) {
|
|
363
|
+
const links = [];
|
|
364
|
+
const linkRegex = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
365
|
+
let match;
|
|
366
|
+
while ((match = linkRegex.exec(markdown)) !== null) {
|
|
367
|
+
const [, text, url] = match;
|
|
368
|
+
links.push({
|
|
369
|
+
text,
|
|
370
|
+
url,
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
return links;
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
exports.AMTPMarkdownParser = AMTPMarkdownParser;
|
|
377
|
+
/**
|
|
378
|
+
* Autonomous Agent Workflow
|
|
379
|
+
* Example of building autonomous workflows
|
|
380
|
+
*/
|
|
381
|
+
class AutonomousAgent {
|
|
382
|
+
constructor(config) {
|
|
383
|
+
this.client = new AMTPClient(config);
|
|
384
|
+
}
|
|
385
|
+
/**
|
|
386
|
+
* Example: Autonomous shopping workflow
|
|
387
|
+
*/
|
|
388
|
+
async autonomousShop(productQuery, maxPrice) {
|
|
389
|
+
console.log(`🤖 Starting autonomous shopping for: ${productQuery} (max: $${maxPrice})`);
|
|
390
|
+
try {
|
|
391
|
+
// Step 1: Search for products
|
|
392
|
+
console.log("📍 Step 1: Searching for products...");
|
|
393
|
+
const results = await this.client.search(productQuery, 10);
|
|
394
|
+
// Step 2: Find product within budget (leverage description for better matching in v1.1+)
|
|
395
|
+
const targetProduct = results.actions.find((a) => a.label?.toLowerCase().includes(productQuery.toLowerCase()) ||
|
|
396
|
+
a.description?.toLowerCase().includes(productQuery.toLowerCase()));
|
|
397
|
+
if (!targetProduct) {
|
|
398
|
+
throw new Error("Product not found");
|
|
399
|
+
}
|
|
400
|
+
// Step 3: View product
|
|
401
|
+
console.log(`📍 Step 2: Viewing product: ${targetProduct.label} — ${targetProduct.description || ""}`);
|
|
402
|
+
await this.client.navigate(targetProduct.endpoint || "/");
|
|
403
|
+
// Step 3: Add to cart
|
|
404
|
+
console.log("📍 Step 3: Adding to cart...");
|
|
405
|
+
await this.client.executeAction("add_to_cart", {
|
|
406
|
+
productId: targetProduct.id,
|
|
407
|
+
quantity: 1,
|
|
408
|
+
});
|
|
409
|
+
// Step 4: Navigate to checkout
|
|
410
|
+
console.log("📍 Step 4: Proceeding to checkout...");
|
|
411
|
+
await this.client.navigate("/cart");
|
|
412
|
+
// Step 5: Get checkout form
|
|
413
|
+
const forms = await this.client.getForms("/checkout");
|
|
414
|
+
console.log(`📍 Step 5: Found ${forms.length} forms`);
|
|
415
|
+
console.log("✅ Workflow completed successfully!");
|
|
416
|
+
return { success: true, product: targetProduct };
|
|
417
|
+
}
|
|
418
|
+
catch (error) {
|
|
419
|
+
console.error("❌ Workflow failed:", error);
|
|
420
|
+
return { success: false, error };
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* Example: Multi-step authenticated workflow
|
|
425
|
+
*/
|
|
426
|
+
async authenticatedWorkflow(username, password) {
|
|
427
|
+
try {
|
|
428
|
+
// Login
|
|
429
|
+
console.log("🔐 Logging in...");
|
|
430
|
+
const session = await this.client.login(username, password);
|
|
431
|
+
console.log(`✅ Logged in as ${session.userId}`);
|
|
432
|
+
// Access dashboard
|
|
433
|
+
console.log("📊 Loading dashboard...");
|
|
434
|
+
await this.client.navigate("/dashboard");
|
|
435
|
+
// Monitor updates
|
|
436
|
+
console.log("🔔 Listening for updates...");
|
|
437
|
+
const eventSource = this.client.streamUpdates("/api/stream/orders", (update) => {
|
|
438
|
+
console.log("📬 Update:", update);
|
|
439
|
+
});
|
|
440
|
+
// Simulate work
|
|
441
|
+
await new Promise((resolve) => setTimeout(resolve, 5000));
|
|
442
|
+
// Cleanup
|
|
443
|
+
eventSource.close();
|
|
444
|
+
await this.client.logout();
|
|
445
|
+
console.log("✅ Logged out");
|
|
446
|
+
return { success: true };
|
|
447
|
+
}
|
|
448
|
+
catch (error) {
|
|
449
|
+
console.error("❌ Authenticated workflow failed:", error);
|
|
450
|
+
return { success: false, error };
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
}
|
|
454
|
+
exports.AutonomousAgent = AutonomousAgent;
|
|
455
|
+
exports.default = {
|
|
456
|
+
AMTPClient,
|
|
457
|
+
AMTPMarkdownParser,
|
|
458
|
+
AutonomousAgent,
|
|
459
|
+
};
|
|
460
|
+
//# sourceMappingURL=amtp-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"amtp-client.js","sourceRoot":"","sources":["../../src/client/amtp-client.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;;;;AAEH,oDAA4B;AAC5B,oDAe6B;AAa7B;;;GAGG;AACH,MAAa,UAAU;IAOrB,YAAY,MAAwB;QAClC,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC;QAC9B,IAAI,CAAC,SAAS,GAAG,MAAM,C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|
|
2
|
+
/**
|
|
3
|
+
* Basic AMTP Client / Agent Example
|
|
4
|
+
*
|
|
5
|
+
* Run with: npm run client
|
|
6
|
+
*/
|
|
7
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
8
|
+
const amtp_client_js_1 = require("../amtp-client.js");
|
|
9
|
+
async function main() {
|
|
10
|
+
const config = {
|
|
11
|
+
baseUrl: process.env.AMTP_BASE_URL || "http://localhost:3000",
|
|
12
|
+
timeout: 10000,
|
|
13
|
+
};
|
|
14
|
+
const client = new amtp_client_js_1.AMTPClient(config);
|
|
15
|
+
console.log("🤖 AMTP Client Demo");
|
|
16
|
+
try {
|
|
17
|
+
// Fetch home page
|
|
18
|
+
const home = await client.getPage("/");
|
|
19
|
+
console.log("Home:", home.title);
|
|
20
|
+
// Fetch a product
|
|
21
|
+
const product = await client.getPage("/products/demo");
|
|
22
|
+
console.log("Product fetched:", product.title);
|
|
23
|
+
// Execute an action (note: demo impl uses /api/amtp/action)
|
|
24
|
+
const buyResult = await client.executeAction("BUY", { productId: "demo", quantity: 1 });
|
|
25
|
+
console.log("Action result:", buyResult.title || "ok");
|
|
26
|
+
// Demo autonomous agent
|
|
27
|
+
const agent = new amtp_client_js_1.AutonomousAgent(config);
|
|
28
|
+
console.log("Autonomous agent instantiated for workflows.");
|
|
29
|
+
}
|
|
30
|
+
catch (err) {
|
|
31
|
+
console.log("Demo note: Start `npm run server` in another shell for live demo. Error:", err.message);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
main().catch(console.error);
|
|
35
|
+
//# sourceMappingURL=basic-client.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"basic-client.js","sourceRoot":"","sources":["../../../src/client/examples/basic-client.ts"],"names":[],"mappings":";AAAA;;;;GAIG;;AAEH,sDAAgE;AAEhE,KAAK,UAAU,IAAI;IACjB,MAAM,MAAM,GAAG;QACb,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa,IAAI,uBAAuB;QAC7D,OAAO,EAAE,KAAK;KACf,CAAC;IACF,MAAM,MAAM,GAAG,IAAI,2BAAU,CAAC,MAAM,CAAC,CAAC;IAEtC,OAAO,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;IAEnC,IAAI;QACF,kBAAkB;QAClB,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;QACvC,OAAO,CAAC,GAAG,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC;QAEjC,kBAAkB;QAClB,MAAM,OAAO,GAAG,MAAM,MAAM,CAAC,OAAO,CAAC,gBAAgB,CAAC,CAAC;QACvD,OAAO,CAAC,GAAG,CAAC,kBAAkB,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;QAE/C,4DAA4D;QAC5D,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,aAAa,CAAC,KAAK,EAAE,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,EAAE,CAAC,CAAC;QACxF,OAAO,CAAC,GAAG,CAAC,gBAAgB,EAAE,SAAS,CAAC,KAAK,IAAI,IAAI,CAAC,CAAC;QAEvD,wBAAwB;QACxB,MAAM,KAAK,GAAG,IAAI,gCAAe,CAAC,MAAM,CAAC,CAAC;QAC1C,OAAO,CAAC,GAAG,CAAC,8CAA8C,CAAC,CAAC;KAE7D;IAAC,OAAO,GAAQ,EAAE;QACjB,OAAO,CAAC,GAAG,CAAC,0EAA0E,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC;KACtG;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC"}
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AMTP Crawler & Indexer
|
|
3
|
+
* Crawls AMTP-enabled websites and builds searchable index
|
|
4
|
+
*/
|
|
5
|
+
import { AMTPDocument, StructuredData, Link } from "../types/amtp.types";
|
|
6
|
+
/**
|
|
7
|
+
* Crawler Configuration
|
|
8
|
+
*/
|
|
9
|
+
export interface CrawlerConfig {
|
|
10
|
+
baseUrl: string;
|
|
11
|
+
maxPages?: number;
|
|
12
|
+
maxDepth?: number;
|
|
13
|
+
respectRobotsTxt?: boolean;
|
|
14
|
+
delays?: {
|
|
15
|
+
betweenRequests: number;
|
|
16
|
+
betweenDomains: number;
|
|
17
|
+
};
|
|
18
|
+
userAgent?: string;
|
|
19
|
+
indexCallback?: (doc: AMTPDocument) => Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Crawled Page Index
|
|
23
|
+
*/
|
|
24
|
+
export interface CrawledPage {
|
|
25
|
+
url: string;
|
|
26
|
+
title: string;
|
|
27
|
+
content: string;
|
|
28
|
+
structuredData: StructuredData[];
|
|
29
|
+
links: Link[];
|
|
30
|
+
indexedAt: string;
|
|
31
|
+
embeddingVector?: number[];
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Crawler Statistics
|
|
35
|
+
*/
|
|
36
|
+
export interface CrawlStats {
|
|
37
|
+
totalPages: number;
|
|
38
|
+
totalTime: number;
|
|
39
|
+
avgTimePerPage: number;
|
|
40
|
+
totalLinksDiscovered: number;
|
|
41
|
+
externalLinks: number;
|
|
42
|
+
errors: number;
|
|
43
|
+
startedAt: string;
|
|
44
|
+
completedAt: string;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* AMTP Crawler
|
|
48
|
+
*/
|
|
49
|
+
export declare class AMTPCrawler {
|
|
50
|
+
private config;
|
|
51
|
+
private client;
|
|
52
|
+
private visited;
|
|
53
|
+
private queue;
|
|
54
|
+
private index;
|
|
55
|
+
private stats;
|
|
56
|
+
private startTime;
|
|
57
|
+
constructor(config: CrawlerConfig);
|
|
58
|
+
/**
|
|
59
|
+
* Start crawling
|
|
60
|
+
*/
|
|
61
|
+
crawl(): Promise<CrawledPage[]>;
|
|
62
|
+
/**
|
|
63
|
+
* Crawl a single page
|
|
64
|
+
*/
|
|
65
|
+
private crawlPage;
|
|
66
|
+
private disallowRules;
|
|
67
|
+
private crawlDelayMs;
|
|
68
|
+
/**
|
|
69
|
+
* Check robots.txt — parse rules and enforce them during crawl.
|
|
70
|
+
*/
|
|
71
|
+
private checkRobotsTxt;
|
|
72
|
+
private isAllowedByRobots;
|
|
73
|
+
/**
|
|
74
|
+
* Search the index
|
|
75
|
+
*/
|
|
76
|
+
search(query: string): CrawledPage[];
|
|
77
|
+
/**
|
|
78
|
+
* Get page by URL
|
|
79
|
+
*/
|
|
80
|
+
getPage(url: string): CrawledPage | undefined;
|
|
81
|
+
/**
|
|
82
|
+
* Export index as JSON
|
|
83
|
+
*/
|
|
84
|
+
exportIndex(): string;
|
|
85
|
+
/**
|
|
86
|
+
* Print crawl statistics
|
|
87
|
+
*/
|
|
88
|
+
private printStats;
|
|
89
|
+
/**
|
|
90
|
+
* Delay execution
|
|
91
|
+
*/
|
|
92
|
+
private delay;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Search Engine Indexer
|
|
96
|
+
* Example of building a search engine index from AMTP pages
|
|
97
|
+
*/
|
|
98
|
+
export declare class SearchIndexer {
|
|
99
|
+
private index;
|
|
100
|
+
/**
|
|
101
|
+
* Add pages to index
|
|
102
|
+
*/
|
|
103
|
+
addPages(pages: CrawledPage[]): void;
|
|
104
|
+
/**
|
|
105
|
+
* Search index
|
|
106
|
+
*/
|
|
107
|
+
search(query: string, limit?: number): CrawledPage[];
|
|
108
|
+
/**
|
|
109
|
+
* Extract keywords from content
|
|
110
|
+
*/
|
|
111
|
+
private extractKeywords;
|
|
112
|
+
/**
|
|
113
|
+
* Check if word is stop word
|
|
114
|
+
*/
|
|
115
|
+
private isStopWord;
|
|
116
|
+
/**
|
|
117
|
+
* Export index
|
|
118
|
+
*/
|
|
119
|
+
exportIndex(): string;
|
|
120
|
+
}
|
|
121
|
+
declare const _default: {
|
|
122
|
+
AMTPCrawler: typeof AMTPCrawler;
|
|
123
|
+
SearchIndexer: typeof SearchIndexer;
|
|
124
|
+
};
|
|
125
|
+
export default _default;
|