@commercelayer/agent-cli 0.8.1 → 1.0.0-dev.0

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.
Files changed (67) hide show
  1. package/README.md +95 -215
  2. package/dist/argv.js +214 -0
  3. package/dist/bin.js +15 -178
  4. package/dist/builtins/auth.js +169 -0
  5. package/dist/builtins/extensions.js +123 -0
  6. package/dist/builtins/index.js +8 -0
  7. package/dist/builtins/loops.js +215 -0
  8. package/dist/builtins/sandbox.js +186 -0
  9. package/dist/config.js +211 -0
  10. package/dist/confirm.js +56 -0
  11. package/dist/engine.js +173 -0
  12. package/dist/errors.js +146 -0
  13. package/dist/help.js +78 -0
  14. package/dist/http.js +117 -0
  15. package/dist/login.js +133 -0
  16. package/dist/resources.js +41 -0
  17. package/dist/schema.js +152 -0
  18. package/dist/schemas.js +72 -0
  19. package/dist/secrets.js +189 -0
  20. package/dist/version.js +4 -8
  21. package/package.json +4 -9
  22. package/dist/api/client.js +0 -190
  23. package/dist/api/server.js +0 -26
  24. package/dist/api/stub/db.js +0 -37
  25. package/dist/api/stub/http.js +0 -18
  26. package/dist/api/stub/index.js +0 -52
  27. package/dist/api/stub/locale.js +0 -52
  28. package/dist/api/stub/management.js +0 -409
  29. package/dist/api/stub/messages.js +0 -126
  30. package/dist/api/stub/orders.js +0 -625
  31. package/dist/api/stub/search.js +0 -78
  32. package/dist/api/stub/shopping.js +0 -673
  33. package/dist/api/stub/theme.js +0 -197
  34. package/dist/api/stub/ucp.js +0 -377
  35. package/dist/api/transport.js +0 -57
  36. package/dist/api/types.js +0 -4
  37. package/dist/assets.js +0 -100
  38. package/dist/catalog.js +0 -372
  39. package/dist/check.js +0 -187
  40. package/dist/commands.js +0 -1241
  41. package/dist/cursor.js +0 -31
  42. package/dist/files.js +0 -98
  43. package/dist/inbox/cursor.js +0 -11
  44. package/dist/inbox/fake.js +0 -95
  45. package/dist/inbox/imap.js +0 -139
  46. package/dist/inbox/mailbox.js +0 -25
  47. package/dist/inbox/message.js +0 -88
  48. package/dist/inspect.js +0 -237
  49. package/dist/languages.js +0 -49
  50. package/dist/links.js +0 -118
  51. package/dist/locales.js +0 -43
  52. package/dist/ops.js +0 -190
  53. package/dist/orderRequest.js +0 -141
  54. package/dist/output.js +0 -39
  55. package/dist/products.js +0 -151
  56. package/dist/promotions.js +0 -291
  57. package/dist/store.js +0 -379
  58. package/dist/storefront.js +0 -285
  59. package/dist/ucp/buy.js +0 -90
  60. package/dist/ucp/check.js +0 -362
  61. package/dist/ucp/client.js +0 -129
  62. package/dist/ucp/images.js +0 -62
  63. package/dist/ucp/platform.js +0 -90
  64. package/dist/ucp/shop.js +0 -357
  65. package/dist/ucp/signing.js +0 -67
  66. package/dist/web.js +0 -316
  67. package/dist/website.js +0 -390
@@ -1,78 +0,0 @@
1
- // A copy of the store Worker's search (commercelayer-ai-store src/store/search.ts), so the
2
- // stub ranks as the store does. Keep it in step with the store's; only the import differs.
3
- //
4
- // Catalog search over what apply sent: words in any order, ranked. A query is folded
5
- // (case and accents aside), split into words, stripped of the stop words of the theme's
6
- // languages and of plurals; each product scores by where its words appear (title over
7
- // category over description, in its base text or any translation) and by how many of
8
- // the query's words it has. Products with every word come first, then those with some;
9
- // ties go by sku. No embeddings: what a word means is not known here, only that it is there.
10
- const WEIGHT = { sku: 8, title: 4, category: 2, description: 1 };
11
- /** Lower case, without accents: "Caffè" and "caffe" compare equal. */
12
- export const fold = (t) => t.normalize('NFD').replace(/[̀-ͯ]/g, '').toLowerCase();
13
- // The theme's languages: en, it, fr, de, es. Words that say nothing about a product.
14
- const STOP = new Set(`a an and any are as at be best but by can do does for from get good have i in into is it its looking me my need of on or our please some something show that the their them these this those to want with without you your
15
- il lo la i gli le un uno una di da del della dei delle per con su e o che qualcosa cerco vorrei voglio mi un po
16
- le la les un une des de du d et ou pour avec sur dans au aux en quelque chose je veux cherche
17
- der die das ein eine einen einem und oder fur mit auf im in zu etwas ich suche mochte
18
- el la los las un una unos unas de del y o para con en algo busco quiero`.split(/\s+/));
19
- /** A word in one spelling: folded, and singular for the common plurals (beans, berries, boxes). */
20
- function stem(word) {
21
- if (word.length > 4 && word.endsWith('ies'))
22
- return `${word.slice(0, -3)}y`;
23
- if (word.length > 4 && /(ches|shes|sses|xes)$/.test(word))
24
- return word.slice(0, -2);
25
- if (word.length > 3 && word.endsWith('s') && !/(ss|us|is)$/.test(word))
26
- return word.slice(0, -1);
27
- return word;
28
- }
29
- const wordsIn = (text) => (text ? fold(text).split(/[^\p{L}\p{N}]+/u).filter(Boolean).map(stem) : []);
30
- /** The words a query searches for: no stop words, no repeats, in the order given. */
31
- export function queryWords(text) {
32
- return [...new Set(wordsIn(text).filter((w) => !STOP.has(w)))];
33
- }
34
- /** A product's words by field, its base text and every translation together. */
35
- function fieldsOf(p) {
36
- const texts = [p, ...Object.values(p.translations ?? {})];
37
- return {
38
- sku: new Set([fold(p.sku), ...wordsIn(p.sku)]),
39
- title: new Set(texts.flatMap((t) => wordsIn(t.name))),
40
- category: new Set(texts.flatMap((t) => wordsIn(t.category))),
41
- description: new Set(texts.flatMap((t) => wordsIn(t.description))),
42
- };
43
- }
44
- /** A word is in a field when the field has it, or (for words of four letters or more) a word that starts with it: "filt" finds "filter". */
45
- const has = (field, word) => field.has(word) || (word.length >= 4 && [...field].some((w) => w.startsWith(word)));
46
- /** How well a product matches the query's words, or null when none of them is in it. */
47
- export function scoreOf(p, words) {
48
- if (!words.length)
49
- return { score: 0, words: [], matched: [], all: true };
50
- const fields = fieldsOf(p);
51
- const found = [];
52
- const matched = new Set();
53
- let score = 0;
54
- for (const w of words) {
55
- const where = Object.keys(WEIGHT).filter((f) => has(fields[f], w));
56
- if (!where.length)
57
- continue;
58
- found.push(w);
59
- where.forEach((f) => matched.add(f));
60
- score += WEIGHT[where[0]];
61
- }
62
- if (!found.length)
63
- return null;
64
- const all = found.length === words.length;
65
- // Every word beats some words; more words beat better places.
66
- score += found.length * 10 + (all ? 100 : 0);
67
- return { score, words: found, matched: Object.keys(WEIGHT).filter((f) => matched.has(f)), all };
68
- }
69
- /** The products matching a query, best first; ties by sku. An empty query (or only stop words) matches everything, by sku. */
70
- export function rank(products, text) {
71
- const words = queryWords(text);
72
- return products
73
- .flatMap((product) => {
74
- const match = scoreOf(product, words);
75
- return match ? [{ product, match }] : [];
76
- })
77
- .sort((a, b) => b.match.score - a.match.score || (a.product.sku < b.product.sku ? -1 : a.product.sku > b.product.sku ? 1 : 0));
78
- }