@agentrhq/webcmd 0.4.1 → 0.4.2
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/README.md +3 -0
- package/cli-manifest.json +278 -0
- package/clis/amazon-in/auth.js +44 -0
- package/clis/amazon-in/checkout-status.js +54 -0
- package/clis/amazon-in/checkout.js +479 -0
- package/clis/amazon-in/parsers.js +252 -0
- package/clis/amazon-in/parsers.test.js +230 -0
- package/clis/amazon-in/product.js +72 -0
- package/clis/amazon-in/search.js +76 -0
- package/clis/amazon-in/shared.js +40 -0
- package/clis/amazon-in/wishlist.js +98 -0
- package/dist/src/hosted/client.d.ts +8 -10
- package/dist/src/hosted/client.js +24 -32
- package/dist/src/hosted/client.test.js +79 -24
- package/dist/src/hosted/runner.js +7 -35
- package/dist/src/hosted/runner.test.js +27 -51
- package/dist/src/hosted/types.d.ts +1 -5
- package/dist/src/root-command-surface.js +10 -2
- package/hosted-contract.json +329 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -108,7 +108,10 @@ Webcmd Cloud can run supported commands and browser sessions on hosted infrastru
|
|
|
108
108
|
|
|
109
109
|
| Plugin | Description | Author |
|
|
110
110
|
| --- | --- | --- |
|
|
111
|
+
| [`bmwblog`](./plugins/bmwblog/) | BMWBLOG article discovery commands for Webcmd | [WebCMD Agent](https://github.com/agentrhq) |
|
|
111
112
|
| [`skyscanner`](./plugins/skyscanner/) | Skyscanner flight search commands for Webcmd | [Rishabh](https://github.com/rishabhraj36) |
|
|
113
|
+
| [`techcrunch`](./plugins/techcrunch/) | Search and read TechCrunch stories from its public API | [WebCMD Agent](https://github.com/agentrhq) |
|
|
114
|
+
| [`ycombinator`](./plugins/ycombinator/) | Read-only Y Combinator startup directory commands for WebCMD | [WebCMD Agent](https://github.com/agentrhq) |
|
|
112
115
|
<!-- webcmd-community-plugins:end -->
|
|
113
116
|
|
|
114
117
|
## Contributing
|
package/cli-manifest.json
CHANGED
|
@@ -287,6 +287,284 @@
|
|
|
287
287
|
"navigateBefore": false,
|
|
288
288
|
"siteSession": "persistent"
|
|
289
289
|
},
|
|
290
|
+
{
|
|
291
|
+
"site": "amazon-in",
|
|
292
|
+
"name": "checkout",
|
|
293
|
+
"description": "Prepare a guarded Amazon.in checkout with browser-only payment handoff",
|
|
294
|
+
"access": "write",
|
|
295
|
+
"domain": "amazon.in",
|
|
296
|
+
"strategy": "ui",
|
|
297
|
+
"browser": true,
|
|
298
|
+
"args": [
|
|
299
|
+
{
|
|
300
|
+
"name": "input",
|
|
301
|
+
"type": "str",
|
|
302
|
+
"required": true,
|
|
303
|
+
"positional": true,
|
|
304
|
+
"help": "Amazon.in product URL or ASIN"
|
|
305
|
+
},
|
|
306
|
+
{
|
|
307
|
+
"name": "quantity",
|
|
308
|
+
"type": "int",
|
|
309
|
+
"default": 1,
|
|
310
|
+
"required": false,
|
|
311
|
+
"help": "Quantity (1-10)"
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
"name": "size",
|
|
315
|
+
"type": "str",
|
|
316
|
+
"required": false,
|
|
317
|
+
"help": "Exact visible size label"
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
"name": "colour",
|
|
321
|
+
"type": "str",
|
|
322
|
+
"required": false,
|
|
323
|
+
"help": "Exact visible colour label"
|
|
324
|
+
},
|
|
325
|
+
{
|
|
326
|
+
"name": "payment",
|
|
327
|
+
"type": "str",
|
|
328
|
+
"required": true,
|
|
329
|
+
"help": "Payment method; secrets remain browser-only",
|
|
330
|
+
"choices": [
|
|
331
|
+
"upi",
|
|
332
|
+
"saved-card",
|
|
333
|
+
"new-card",
|
|
334
|
+
"cod"
|
|
335
|
+
]
|
|
336
|
+
},
|
|
337
|
+
{
|
|
338
|
+
"name": "card-last4",
|
|
339
|
+
"type": "str",
|
|
340
|
+
"required": false,
|
|
341
|
+
"help": "Saved-card selector: exactly four digits"
|
|
342
|
+
},
|
|
343
|
+
{
|
|
344
|
+
"name": "place-order",
|
|
345
|
+
"type": "boolean",
|
|
346
|
+
"default": false,
|
|
347
|
+
"required": false,
|
|
348
|
+
"help": "Submit the final Amazon action once"
|
|
349
|
+
}
|
|
350
|
+
],
|
|
351
|
+
"columns": [
|
|
352
|
+
"status",
|
|
353
|
+
"asin",
|
|
354
|
+
"title",
|
|
355
|
+
"size",
|
|
356
|
+
"colour",
|
|
357
|
+
"quantity",
|
|
358
|
+
"item_price",
|
|
359
|
+
"total",
|
|
360
|
+
"payment_method",
|
|
361
|
+
"delivery_date",
|
|
362
|
+
"action",
|
|
363
|
+
"verify_command"
|
|
364
|
+
],
|
|
365
|
+
"type": "js",
|
|
366
|
+
"modulePath": "amazon-in/checkout.js",
|
|
367
|
+
"sourceFile": "amazon-in/checkout.js",
|
|
368
|
+
"navigateBefore": false,
|
|
369
|
+
"siteSession": "persistent",
|
|
370
|
+
"freshPage": true,
|
|
371
|
+
"defaultWindowMode": "foreground"
|
|
372
|
+
},
|
|
373
|
+
{
|
|
374
|
+
"site": "amazon-in",
|
|
375
|
+
"name": "checkout-status",
|
|
376
|
+
"description": "Read the current Amazon.in checkout or payment state without clicking",
|
|
377
|
+
"access": "read",
|
|
378
|
+
"domain": "amazon.in",
|
|
379
|
+
"strategy": "ui",
|
|
380
|
+
"browser": true,
|
|
381
|
+
"args": [],
|
|
382
|
+
"columns": [
|
|
383
|
+
"status",
|
|
384
|
+
"order_id",
|
|
385
|
+
"total",
|
|
386
|
+
"payment_method",
|
|
387
|
+
"action"
|
|
388
|
+
],
|
|
389
|
+
"type": "js",
|
|
390
|
+
"modulePath": "amazon-in/checkout-status.js",
|
|
391
|
+
"sourceFile": "amazon-in/checkout-status.js",
|
|
392
|
+
"navigateBefore": false,
|
|
393
|
+
"siteSession": "persistent"
|
|
394
|
+
},
|
|
395
|
+
{
|
|
396
|
+
"site": "amazon-in",
|
|
397
|
+
"name": "login",
|
|
398
|
+
"description": "Open amazon-in login",
|
|
399
|
+
"access": "write",
|
|
400
|
+
"domain": "amazon.in",
|
|
401
|
+
"strategy": "cookie",
|
|
402
|
+
"browser": true,
|
|
403
|
+
"args": [],
|
|
404
|
+
"columns": [
|
|
405
|
+
"status",
|
|
406
|
+
"logged_in",
|
|
407
|
+
"site",
|
|
408
|
+
"user_name",
|
|
409
|
+
"action",
|
|
410
|
+
"verify_command"
|
|
411
|
+
],
|
|
412
|
+
"type": "js",
|
|
413
|
+
"modulePath": "amazon-in/auth.js",
|
|
414
|
+
"sourceFile": "amazon-in/auth.js",
|
|
415
|
+
"navigateBefore": false,
|
|
416
|
+
"siteSession": "persistent",
|
|
417
|
+
"defaultWindowMode": "foreground"
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
"site": "amazon-in",
|
|
421
|
+
"name": "product",
|
|
422
|
+
"description": "Fetch the current Amazon.in price and selected product variant",
|
|
423
|
+
"access": "read",
|
|
424
|
+
"domain": "amazon.in",
|
|
425
|
+
"strategy": "ui",
|
|
426
|
+
"browser": true,
|
|
427
|
+
"args": [
|
|
428
|
+
{
|
|
429
|
+
"name": "input",
|
|
430
|
+
"type": "str",
|
|
431
|
+
"required": true,
|
|
432
|
+
"positional": true,
|
|
433
|
+
"help": "Amazon.in product URL or ASIN"
|
|
434
|
+
}
|
|
435
|
+
],
|
|
436
|
+
"columns": [
|
|
437
|
+
"asin",
|
|
438
|
+
"title",
|
|
439
|
+
"price",
|
|
440
|
+
"mrp",
|
|
441
|
+
"discount",
|
|
442
|
+
"availability",
|
|
443
|
+
"size",
|
|
444
|
+
"colour",
|
|
445
|
+
"image_url",
|
|
446
|
+
"product_url"
|
|
447
|
+
],
|
|
448
|
+
"type": "js",
|
|
449
|
+
"modulePath": "amazon-in/product.js",
|
|
450
|
+
"sourceFile": "amazon-in/product.js",
|
|
451
|
+
"navigateBefore": false,
|
|
452
|
+
"siteSession": "persistent"
|
|
453
|
+
},
|
|
454
|
+
{
|
|
455
|
+
"site": "amazon-in",
|
|
456
|
+
"name": "search",
|
|
457
|
+
"description": "Search Amazon.in products with inclusive INR price bounds and images",
|
|
458
|
+
"access": "read",
|
|
459
|
+
"domain": "amazon.in",
|
|
460
|
+
"strategy": "ui",
|
|
461
|
+
"browser": true,
|
|
462
|
+
"args": [
|
|
463
|
+
{
|
|
464
|
+
"name": "query",
|
|
465
|
+
"type": "str",
|
|
466
|
+
"required": true,
|
|
467
|
+
"positional": true,
|
|
468
|
+
"help": "Product search query"
|
|
469
|
+
},
|
|
470
|
+
{
|
|
471
|
+
"name": "min-price",
|
|
472
|
+
"type": "number",
|
|
473
|
+
"required": false,
|
|
474
|
+
"help": "Inclusive minimum price in rupees"
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
"name": "max-price",
|
|
478
|
+
"type": "number",
|
|
479
|
+
"required": false,
|
|
480
|
+
"help": "Inclusive maximum price in rupees"
|
|
481
|
+
},
|
|
482
|
+
{
|
|
483
|
+
"name": "limit",
|
|
484
|
+
"type": "int",
|
|
485
|
+
"default": 20,
|
|
486
|
+
"required": false,
|
|
487
|
+
"help": "Maximum results (1-50)"
|
|
488
|
+
}
|
|
489
|
+
],
|
|
490
|
+
"columns": [
|
|
491
|
+
"rank",
|
|
492
|
+
"asin",
|
|
493
|
+
"title",
|
|
494
|
+
"price",
|
|
495
|
+
"mrp",
|
|
496
|
+
"rating",
|
|
497
|
+
"review_count",
|
|
498
|
+
"image_url",
|
|
499
|
+
"product_url",
|
|
500
|
+
"is_sponsored"
|
|
501
|
+
],
|
|
502
|
+
"type": "js",
|
|
503
|
+
"modulePath": "amazon-in/search.js",
|
|
504
|
+
"sourceFile": "amazon-in/search.js",
|
|
505
|
+
"navigateBefore": false,
|
|
506
|
+
"siteSession": "persistent"
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
"site": "amazon-in",
|
|
510
|
+
"name": "whoami",
|
|
511
|
+
"description": "Show the current logged-in amazon-in account",
|
|
512
|
+
"access": "read",
|
|
513
|
+
"domain": "amazon.in",
|
|
514
|
+
"strategy": "cookie",
|
|
515
|
+
"browser": true,
|
|
516
|
+
"args": [],
|
|
517
|
+
"columns": [
|
|
518
|
+
"logged_in",
|
|
519
|
+
"site",
|
|
520
|
+
"user_name"
|
|
521
|
+
],
|
|
522
|
+
"type": "js",
|
|
523
|
+
"modulePath": "amazon-in/auth.js",
|
|
524
|
+
"sourceFile": "amazon-in/auth.js",
|
|
525
|
+
"navigateBefore": false,
|
|
526
|
+
"siteSession": "persistent"
|
|
527
|
+
},
|
|
528
|
+
{
|
|
529
|
+
"site": "amazon-in",
|
|
530
|
+
"name": "wishlist",
|
|
531
|
+
"description": "Fetch current prices for products in the default Amazon.in wishlist",
|
|
532
|
+
"access": "read",
|
|
533
|
+
"domain": "amazon.in",
|
|
534
|
+
"strategy": "ui",
|
|
535
|
+
"browser": true,
|
|
536
|
+
"args": [
|
|
537
|
+
{
|
|
538
|
+
"name": "filter",
|
|
539
|
+
"type": "str",
|
|
540
|
+
"default": "unpurchased",
|
|
541
|
+
"required": false,
|
|
542
|
+
"help": "Wishlist items to include",
|
|
543
|
+
"choices": [
|
|
544
|
+
"unpurchased",
|
|
545
|
+
"all"
|
|
546
|
+
]
|
|
547
|
+
}
|
|
548
|
+
],
|
|
549
|
+
"columns": [
|
|
550
|
+
"list_name",
|
|
551
|
+
"item_id",
|
|
552
|
+
"asin",
|
|
553
|
+
"title",
|
|
554
|
+
"price",
|
|
555
|
+
"mrp",
|
|
556
|
+
"availability",
|
|
557
|
+
"size",
|
|
558
|
+
"colour",
|
|
559
|
+
"image_url",
|
|
560
|
+
"product_url"
|
|
561
|
+
],
|
|
562
|
+
"type": "js",
|
|
563
|
+
"modulePath": "amazon-in/wishlist.js",
|
|
564
|
+
"sourceFile": "amazon-in/wishlist.js",
|
|
565
|
+
"navigateBefore": false,
|
|
566
|
+
"siteSession": "persistent"
|
|
567
|
+
},
|
|
290
568
|
{
|
|
291
569
|
"site": "antigravity",
|
|
292
570
|
"name": "add-context",
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { AuthRequiredError, CommandExecutionError } from '@agentrhq/webcmd/errors';
|
|
2
|
+
import { registerSiteAuthCommands } from '../_shared/site-auth.js';
|
|
3
|
+
import { hasAmazonInAuthCookie } from './parsers.js';
|
|
4
|
+
import { DOMAIN, HOME_URL, SITE } from './shared.js';
|
|
5
|
+
|
|
6
|
+
async function hasAmazonInSessionCookies(page) {
|
|
7
|
+
const cookies = await page.getCookies({ url: HOME_URL });
|
|
8
|
+
return hasAmazonInAuthCookie(cookies.map((cookie) => cookie.name));
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
async function verifyAmazonInIdentity(page) {
|
|
12
|
+
if (!await hasAmazonInSessionCookies(page)) {
|
|
13
|
+
throw new AuthRequiredError(DOMAIN, 'Amazon.in authentication cookies are missing');
|
|
14
|
+
}
|
|
15
|
+
await page.goto(HOME_URL, { waitUntil: 'load' });
|
|
16
|
+
await page.wait(2);
|
|
17
|
+
const identity = await page.evaluate(`
|
|
18
|
+
(() => {
|
|
19
|
+
const greeting = (
|
|
20
|
+
document.querySelector('#nav-link-accountList-nav-line-1')?.textContent || ''
|
|
21
|
+
).trim();
|
|
22
|
+
if (/sign\\s*in/i.test(greeting)) return { kind: 'auth' };
|
|
23
|
+
const match = greeting.match(/^Hello,?\\s+(.+)$/i);
|
|
24
|
+
return match ? { user_name: match[1].trim() } : null;
|
|
25
|
+
})()
|
|
26
|
+
`);
|
|
27
|
+
if (identity?.kind === 'auth') throw new AuthRequiredError(DOMAIN);
|
|
28
|
+
if (!identity?.user_name) {
|
|
29
|
+
throw new CommandExecutionError(
|
|
30
|
+
'Amazon.in account greeting could not be read',
|
|
31
|
+
'Open Amazon.in in the Webcmd browser and check for a robot challenge or layout change.',
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
return identity;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
registerSiteAuthCommands({
|
|
38
|
+
site: SITE,
|
|
39
|
+
domain: DOMAIN,
|
|
40
|
+
loginUrl: 'https://www.amazon.in/ap/signin',
|
|
41
|
+
columns: ['user_name'],
|
|
42
|
+
quickCheck: hasAmazonInSessionCookies,
|
|
43
|
+
verify: verifyAmazonInIdentity,
|
|
44
|
+
});
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { AuthRequiredError, CommandExecutionError } from '@agentrhq/webcmd/errors';
|
|
2
|
+
import { cli, Strategy } from '@agentrhq/webcmd/registry';
|
|
3
|
+
import { classifyCheckoutSnapshot } from './parsers.js';
|
|
4
|
+
import { DOMAIN, SITE } from './shared.js';
|
|
5
|
+
|
|
6
|
+
cli({
|
|
7
|
+
site: SITE,
|
|
8
|
+
name: 'checkout-status',
|
|
9
|
+
access: 'read',
|
|
10
|
+
description: 'Read the current Amazon.in checkout or payment state without clicking',
|
|
11
|
+
domain: DOMAIN,
|
|
12
|
+
strategy: Strategy.UI,
|
|
13
|
+
browser: true,
|
|
14
|
+
navigateBefore: false,
|
|
15
|
+
siteSession: 'persistent',
|
|
16
|
+
args: [],
|
|
17
|
+
columns: ['status', 'order_id', 'total', 'payment_method', 'action'],
|
|
18
|
+
func: async (page) => {
|
|
19
|
+
const snapshot = await page.evaluate(`
|
|
20
|
+
(() => {
|
|
21
|
+
const body = document.body?.innerText || '';
|
|
22
|
+
const rows = [...document.querySelectorAll('#subtotals-marketplace-table li')];
|
|
23
|
+
const total = rows.find((node) => /^Order Total:/i.test((node.textContent || '').trim()));
|
|
24
|
+
const selectedPayment = document.querySelector('#selected-payment-methods-list-container');
|
|
25
|
+
const checkedPayment = document.querySelector(
|
|
26
|
+
'#checkout-paymentOptionPanel input[type="radio"]:checked, input[name*="payment"]:checked'
|
|
27
|
+
);
|
|
28
|
+
const payment = selectedPayment ||
|
|
29
|
+
checkedPayment?.closest('label, [data-testid*="payment"], .pmts-instrument-box');
|
|
30
|
+
const order = document.querySelector('[data-order-id], #orderDetails, .order-number');
|
|
31
|
+
return {
|
|
32
|
+
url: location.href,
|
|
33
|
+
paymentText: payment?.textContent || '',
|
|
34
|
+
text: [
|
|
35
|
+
total?.textContent || '',
|
|
36
|
+
order?.textContent || '',
|
|
37
|
+
body,
|
|
38
|
+
].join('\\n'),
|
|
39
|
+
};
|
|
40
|
+
})()
|
|
41
|
+
`);
|
|
42
|
+
try {
|
|
43
|
+
const row = classifyCheckoutSnapshot(snapshot);
|
|
44
|
+
if (row.status === 'login_required') throw new AuthRequiredError(DOMAIN);
|
|
45
|
+
return [row];
|
|
46
|
+
} catch (error) {
|
|
47
|
+
if (error instanceof AuthRequiredError) throw error;
|
|
48
|
+
throw new CommandExecutionError(
|
|
49
|
+
`Amazon checkout status could not be classified: ${error.message}`,
|
|
50
|
+
'Keep the checkout or payment page open in the persistent Webcmd browser and retry.',
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
});
|