@kaleidorg/mind 0.1.0 → 0.3.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 (182) hide show
  1. package/dist/capabilities.d.ts +38 -0
  2. package/dist/capabilities.d.ts.map +1 -0
  3. package/dist/capabilities.js +41 -0
  4. package/dist/capabilities.js.map +1 -0
  5. package/dist/context/budget.d.ts +29 -0
  6. package/dist/context/budget.d.ts.map +1 -0
  7. package/dist/context/budget.js +36 -0
  8. package/dist/context/budget.js.map +1 -0
  9. package/dist/context/builder.d.ts +39 -0
  10. package/dist/context/builder.d.ts.map +1 -0
  11. package/dist/context/builder.js +77 -0
  12. package/dist/context/builder.js.map +1 -0
  13. package/dist/engine.d.ts +9 -0
  14. package/dist/engine.d.ts.map +1 -1
  15. package/dist/engine.js +1 -0
  16. package/dist/engine.js.map +1 -1
  17. package/dist/fastpath/fastpath.d.ts +38 -0
  18. package/dist/fastpath/fastpath.d.ts.map +1 -0
  19. package/dist/fastpath/fastpath.js +52 -0
  20. package/dist/fastpath/fastpath.js.map +1 -0
  21. package/dist/funnel.d.ts +117 -0
  22. package/dist/funnel.d.ts.map +1 -0
  23. package/dist/funnel.js +195 -0
  24. package/dist/funnel.js.map +1 -0
  25. package/dist/index.d.ts +44 -0
  26. package/dist/index.d.ts.map +1 -1
  27. package/dist/index.js +36 -0
  28. package/dist/index.js.map +1 -1
  29. package/dist/kaleidoswap/contract.d.ts +72 -0
  30. package/dist/kaleidoswap/contract.d.ts.map +1 -0
  31. package/dist/kaleidoswap/contract.js +125 -0
  32. package/dist/kaleidoswap/contract.js.map +1 -0
  33. package/dist/knowledge/bitcoin-copilot.d.ts +11 -0
  34. package/dist/knowledge/bitcoin-copilot.d.ts.map +1 -0
  35. package/dist/knowledge/bitcoin-copilot.js +155 -0
  36. package/dist/knowledge/bitcoin-copilot.js.map +1 -0
  37. package/dist/knowledge/btc-map.d.ts +87 -0
  38. package/dist/knowledge/btc-map.d.ts.map +1 -0
  39. package/dist/knowledge/btc-map.js +365 -0
  40. package/dist/knowledge/btc-map.js.map +1 -0
  41. package/dist/knowledge/merchants.d.ts +24 -0
  42. package/dist/knowledge/merchants.d.ts.map +1 -0
  43. package/dist/knowledge/merchants.js +34 -0
  44. package/dist/knowledge/merchants.js.map +1 -0
  45. package/dist/knowledge/wallet.d.ts +34 -0
  46. package/dist/knowledge/wallet.d.ts.map +1 -0
  47. package/dist/knowledge/wallet.js +63 -0
  48. package/dist/knowledge/wallet.js.map +1 -0
  49. package/dist/lsps1/contract.d.ts +55 -0
  50. package/dist/lsps1/contract.d.ts.map +1 -0
  51. package/dist/lsps1/contract.js +91 -0
  52. package/dist/lsps1/contract.js.map +1 -0
  53. package/dist/memory/store.d.ts +40 -0
  54. package/dist/memory/store.d.ts.map +1 -0
  55. package/dist/memory/store.js +143 -0
  56. package/dist/memory/store.js.map +1 -0
  57. package/dist/memory/tool.d.ts +9 -0
  58. package/dist/memory/tool.d.ts.map +1 -0
  59. package/dist/memory/tool.js +70 -0
  60. package/dist/memory/tool.js.map +1 -0
  61. package/dist/memory/types.d.ts +68 -0
  62. package/dist/memory/types.d.ts.map +1 -0
  63. package/dist/memory/types.js +14 -0
  64. package/dist/memory/types.js.map +1 -0
  65. package/dist/rag/retriever.d.ts +30 -0
  66. package/dist/rag/retriever.d.ts.map +1 -0
  67. package/dist/rag/retriever.js +72 -0
  68. package/dist/rag/retriever.js.map +1 -0
  69. package/dist/rag/tool.d.ts +15 -0
  70. package/dist/rag/tool.d.ts.map +1 -0
  71. package/dist/rag/tool.js +42 -0
  72. package/dist/rag/tool.js.map +1 -0
  73. package/dist/rag/types.d.ts +44 -0
  74. package/dist/rag/types.d.ts.map +1 -0
  75. package/dist/rag/types.js +11 -0
  76. package/dist/rag/types.js.map +1 -0
  77. package/dist/rag/vector-store.d.ts +23 -0
  78. package/dist/rag/vector-store.d.ts.map +1 -0
  79. package/dist/rag/vector-store.js +72 -0
  80. package/dist/rag/vector-store.js.map +1 -0
  81. package/dist/recipe/asset-send.d.ts +15 -0
  82. package/dist/recipe/asset-send.d.ts.map +1 -0
  83. package/dist/recipe/asset-send.js +83 -0
  84. package/dist/recipe/asset-send.js.map +1 -0
  85. package/dist/recipe/kaleidoswap-atomic.d.ts +27 -0
  86. package/dist/recipe/kaleidoswap-atomic.d.ts.map +1 -0
  87. package/dist/recipe/kaleidoswap-atomic.js +111 -0
  88. package/dist/recipe/kaleidoswap-atomic.js.map +1 -0
  89. package/dist/recipe/payments.d.ts +15 -0
  90. package/dist/recipe/payments.d.ts.map +1 -0
  91. package/dist/recipe/payments.js +119 -0
  92. package/dist/recipe/payments.js.map +1 -0
  93. package/dist/recipe/receive.d.ts +14 -0
  94. package/dist/recipe/receive.d.ts.map +1 -0
  95. package/dist/recipe/receive.js +109 -0
  96. package/dist/recipe/receive.js.map +1 -0
  97. package/dist/recipe/runner.d.ts +42 -0
  98. package/dist/recipe/runner.d.ts.map +1 -0
  99. package/dist/recipe/runner.js +106 -0
  100. package/dist/recipe/runner.js.map +1 -0
  101. package/dist/recipe/swap.d.ts +16 -0
  102. package/dist/recipe/swap.d.ts.map +1 -0
  103. package/dist/recipe/swap.js +73 -0
  104. package/dist/recipe/swap.js.map +1 -0
  105. package/dist/recipe/types.d.ts +71 -0
  106. package/dist/recipe/types.d.ts.map +1 -0
  107. package/dist/recipe/types.js +13 -0
  108. package/dist/recipe/types.js.map +1 -0
  109. package/dist/skills/registry.d.ts.map +1 -1
  110. package/dist/skills/registry.js +20 -2
  111. package/dist/skills/registry.js.map +1 -1
  112. package/dist/tools/cli.d.ts +43 -0
  113. package/dist/tools/cli.d.ts.map +1 -0
  114. package/dist/tools/cli.js +61 -0
  115. package/dist/tools/cli.js.map +1 -0
  116. package/dist/tools/mcp.d.ts +3 -2
  117. package/dist/tools/mcp.d.ts.map +1 -1
  118. package/dist/tools/mcp.js +3 -2
  119. package/dist/tools/mcp.js.map +1 -1
  120. package/dist/wallet/confirm.d.ts +12 -0
  121. package/dist/wallet/confirm.d.ts.map +1 -0
  122. package/dist/wallet/confirm.js +67 -0
  123. package/dist/wallet/confirm.js.map +1 -0
  124. package/dist/wallet/contract.d.ts +57 -0
  125. package/dist/wallet/contract.d.ts.map +1 -0
  126. package/dist/wallet/contract.js +113 -0
  127. package/dist/wallet/contract.js.map +1 -0
  128. package/package.json +10 -5
  129. package/skills/README.md +6 -1
  130. package/skills/kaleido-lsps/SKILL.md +56 -0
  131. package/skills/kaleido-trading/SKILL.md +85 -18
  132. package/skills/merchant-finder/SKILL.md +87 -0
  133. package/skills/paid-data/SKILL.md +12 -0
  134. package/skills/wallet-assistant/SKILL.md +38 -0
  135. package/src/capabilities.ts +79 -0
  136. package/src/context/budget.ts +46 -0
  137. package/src/context/builder.ts +100 -0
  138. package/src/context/context.test.ts +87 -0
  139. package/src/engine.ts +6 -0
  140. package/src/fastpath/fastpath.test.ts +34 -0
  141. package/src/fastpath/fastpath.ts +70 -0
  142. package/src/funnel.test.ts +207 -0
  143. package/src/funnel.ts +285 -0
  144. package/src/index.ts +128 -0
  145. package/src/kaleidoswap/contract.test.ts +147 -0
  146. package/src/kaleidoswap/contract.ts +212 -0
  147. package/src/knowledge/bitcoin-copilot.ts +177 -0
  148. package/src/knowledge/btc-map.test.ts +188 -0
  149. package/src/knowledge/btc-map.ts +446 -0
  150. package/src/knowledge/knowledge.test.ts +63 -0
  151. package/src/knowledge/merchants.ts +49 -0
  152. package/src/knowledge/wallet.ts +84 -0
  153. package/src/lsps1/contract.test.ts +81 -0
  154. package/src/lsps1/contract.ts +132 -0
  155. package/src/memory/memory.test.ts +140 -0
  156. package/src/memory/store.ts +174 -0
  157. package/src/memory/tool.ts +76 -0
  158. package/src/memory/types.ts +76 -0
  159. package/src/rag/rag.test.ts +85 -0
  160. package/src/rag/retriever.ts +94 -0
  161. package/src/rag/tool.ts +55 -0
  162. package/src/rag/types.ts +49 -0
  163. package/src/rag/vector-store.ts +78 -0
  164. package/src/recipe/asset-send.ts +79 -0
  165. package/src/recipe/kaleidoswap-atomic.test.ts +138 -0
  166. package/src/recipe/kaleidoswap-atomic.ts +117 -0
  167. package/src/recipe/payments.ts +116 -0
  168. package/src/recipe/receive.ts +98 -0
  169. package/src/recipe/recipe.test.ts +193 -0
  170. package/src/recipe/runner.ts +134 -0
  171. package/src/recipe/swap.ts +74 -0
  172. package/src/recipe/types.ts +76 -0
  173. package/src/skills/registry.ts +21 -2
  174. package/src/skills/skills.test.ts +42 -0
  175. package/src/tools/cli.test.ts +53 -0
  176. package/src/tools/cli.ts +98 -0
  177. package/src/tools/mcp.ts +3 -2
  178. package/src/wallet/confirm.test.ts +57 -0
  179. package/src/wallet/confirm.ts +74 -0
  180. package/src/wallet/contract.test.ts +89 -0
  181. package/src/wallet/contract.ts +157 -0
  182. package/skills/kaleido-wallet/SKILL.md +0 -28
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merchants.d.ts","sourceRoot":"","sources":["../../src/knowledge/merchants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,4CAA4C;IAC5C,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,kFAAkF;AAClF,wBAAgB,oBAAoB,CAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,CAuBzE"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * BTC map discovery — turn a merchant directory (e.g. BTCMap / a local dataset)
3
+ * into `RagDocument[]` so the agent can answer "where can I spend Bitcoin for
4
+ * coffee near me?" with on-device semantic search over places.
5
+ *
6
+ * Pure transform over a generic Merchant shape. Coordinates are kept in
7
+ * metadata so the host can still pin results on a map after retrieval.
8
+ */
9
+ /** One searchable doc per merchant; lat/lng preserved in metadata for mapping. */
10
+ export function merchantsToDocuments(merchants) {
11
+ return merchants
12
+ .filter((m) => m.name)
13
+ .map((m, i) => {
14
+ const where = [m.address, m.city].filter(Boolean).join(', ');
15
+ const pays = m.acceptedAssets?.length
16
+ ? `Accepts ${m.acceptedAssets.join(', ')}.`
17
+ : 'Accepts Bitcoin.';
18
+ const cat = m.category ? ` (${m.category})` : '';
19
+ const desc = m.description ? ` ${m.description}` : '';
20
+ return {
21
+ id: m.id ?? `merchant_${m.name ?? i}`,
22
+ text: `${m.name}${cat}${where ? ` at ${where}` : ''}. ${pays}${desc}`.trim(),
23
+ metadata: {
24
+ kind: 'merchant',
25
+ name: m.name,
26
+ category: m.category,
27
+ city: m.city,
28
+ lat: m.lat,
29
+ lng: m.lng,
30
+ },
31
+ };
32
+ });
33
+ }
34
+ //# sourceMappingURL=merchants.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"merchants.js","sourceRoot":"","sources":["../../src/knowledge/merchants.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAiBH,kFAAkF;AAClF,MAAM,UAAU,oBAAoB,CAAC,SAAqB;IACxD,OAAO,SAAS;SACb,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACrB,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACZ,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;QAC7D,MAAM,IAAI,GAAG,CAAC,CAAC,cAAc,EAAE,MAAM;YACnC,CAAC,CAAC,WAAW,CAAC,CAAC,cAAc,CAAC,IAAI,CAAC,IAAI,CAAC,GAAG;YAC3C,CAAC,CAAC,kBAAkB,CAAC;QACvB,MAAM,GAAG,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,GAAG,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACtD,OAAO;YACL,EAAE,EAAE,CAAC,CAAC,EAAE,IAAI,YAAY,CAAC,CAAC,IAAI,IAAI,CAAC,EAAE;YACrC,IAAI,EAAE,GAAG,CAAC,CAAC,IAAI,GAAG,GAAG,GAAG,KAAK,CAAC,CAAC,CAAC,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,KAAK,IAAI,GAAG,IAAI,EAAE,CAAC,IAAI,EAAE;YAC5E,QAAQ,EAAE;gBACR,IAAI,EAAE,UAAU;gBAChB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,QAAQ,EAAE,CAAC,CAAC,QAAQ;gBACpB,IAAI,EAAE,CAAC,CAAC,IAAI;gBACZ,GAAG,EAAE,CAAC,CAAC,GAAG;gBACV,GAAG,EAAE,CAAC,CAAC,GAAG;aACX;SACF,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * Personal wallet knowledge — turn a user's transaction history + contacts into
3
+ * `RagDocument[]` so the agent can answer "what did I spend on coffee last
4
+ * month?", "who did I pay 50k sats to?", "summarise my swaps" — all on-device,
5
+ * nothing leaving the phone.
6
+ *
7
+ * Pure transforms over minimal, generic shapes (hosts map their own types in).
8
+ * No deps, no PII leaves: the host decides what to ingest.
9
+ */
10
+ import type { RagDocument } from '../rag/types.js';
11
+ export interface WalletTx {
12
+ id?: string;
13
+ /** 'send' | 'receive' | 'swap' | 'deposit' | 'withdraw' | … */
14
+ type?: string;
15
+ amountSats?: number;
16
+ asset?: string;
17
+ /** Who/where — a name, contact, address, or merchant. */
18
+ counterparty?: string;
19
+ memo?: string;
20
+ status?: string;
21
+ /** Epoch ms. */
22
+ timestamp?: number;
23
+ }
24
+ export interface Contact {
25
+ name?: string;
26
+ lightningAddress?: string;
27
+ npub?: string;
28
+ note?: string;
29
+ }
30
+ /** One short, searchable sentence per transaction. */
31
+ export declare function walletHistoryToDocuments(txs: WalletTx[]): RagDocument[];
32
+ /** One doc per contact, so "who is Bob?" / "pay my friend" can resolve. */
33
+ export declare function contactsToDocuments(contacts: Contact[]): RagDocument[];
34
+ //# sourceMappingURL=wallet.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.d.ts","sourceRoot":"","sources":["../../src/knowledge/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAEnD,MAAM,WAAW,QAAQ;IACvB,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,+DAA+D;IAC/D,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yDAAyD;IACzD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,gBAAgB;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,OAAO;IACtB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,CAAC;CACf;AAYD,sDAAsD;AACtD,wBAAgB,wBAAwB,CAAC,GAAG,EAAE,QAAQ,EAAE,GAAG,WAAW,EAAE,CAsBvE;AAED,2EAA2E;AAC3E,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,OAAO,EAAE,GAAG,WAAW,EAAE,CActE"}
@@ -0,0 +1,63 @@
1
+ /**
2
+ * Personal wallet knowledge — turn a user's transaction history + contacts into
3
+ * `RagDocument[]` so the agent can answer "what did I spend on coffee last
4
+ * month?", "who did I pay 50k sats to?", "summarise my swaps" — all on-device,
5
+ * nothing leaving the phone.
6
+ *
7
+ * Pure transforms over minimal, generic shapes (hosts map their own types in).
8
+ * No deps, no PII leaves: the host decides what to ingest.
9
+ */
10
+ function isoDate(ts) {
11
+ if (!ts)
12
+ return 'an unknown date';
13
+ // Avoid Date formatting differences — just YYYY-MM-DD from the ISO string.
14
+ try {
15
+ return new Date(ts).toISOString().slice(0, 10);
16
+ }
17
+ catch {
18
+ return 'an unknown date';
19
+ }
20
+ }
21
+ /** One short, searchable sentence per transaction. */
22
+ export function walletHistoryToDocuments(txs) {
23
+ return txs.map((tx, i) => {
24
+ const date = isoDate(tx.timestamp);
25
+ const asset = tx.asset ?? 'sats';
26
+ const amount = tx.amountSats != null ? `${tx.amountSats} ${asset === 'BTC' ? 'sats' : asset}` : 'an amount';
27
+ const verb = tx.type === 'receive' || tx.type === 'deposit'
28
+ ? 'received'
29
+ : tx.type === 'swap'
30
+ ? 'swapped'
31
+ : tx.type === 'withdraw'
32
+ ? 'withdrew'
33
+ : 'sent';
34
+ const who = tx.counterparty ? ` ${verb === 'received' ? 'from' : 'to'} ${tx.counterparty}` : '';
35
+ const memo = tx.memo ? ` — "${tx.memo}"` : '';
36
+ const status = tx.status && tx.status !== 'complete' ? ` (${tx.status})` : '';
37
+ return {
38
+ id: tx.id ?? `tx_${i}`,
39
+ text: `On ${date} you ${verb} ${amount}${who}${memo}${status}.`,
40
+ metadata: { kind: 'transaction', type: tx.type, asset: tx.asset, timestamp: tx.timestamp },
41
+ };
42
+ });
43
+ }
44
+ /** One doc per contact, so "who is Bob?" / "pay my friend" can resolve. */
45
+ export function contactsToDocuments(contacts) {
46
+ return contacts
47
+ .filter((c) => c.name || c.lightningAddress || c.npub)
48
+ .map((c, i) => {
49
+ const parts = [];
50
+ if (c.lightningAddress)
51
+ parts.push(`Lightning address ${c.lightningAddress}`);
52
+ if (c.npub)
53
+ parts.push(`Nostr ${c.npub}`);
54
+ if (c.note)
55
+ parts.push(c.note);
56
+ return {
57
+ id: `contact_${c.name ?? c.lightningAddress ?? i}`,
58
+ text: `Contact: ${c.name ?? 'unnamed'}${parts.length ? ` — ${parts.join(', ')}` : ''}.`,
59
+ metadata: { kind: 'contact', name: c.name },
60
+ };
61
+ });
62
+ }
63
+ //# sourceMappingURL=wallet.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"wallet.js","sourceRoot":"","sources":["../../src/knowledge/wallet.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAyBH,SAAS,OAAO,CAAC,EAAW;IAC1B,IAAI,CAAC,EAAE;QAAE,OAAO,iBAAiB,CAAC;IAClC,2EAA2E;IAC3E,IAAI,CAAC;QACH,OAAO,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;IACjD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,iBAAiB,CAAC;IAC3B,CAAC;AACH,CAAC;AAED,sDAAsD;AACtD,MAAM,UAAU,wBAAwB,CAAC,GAAe;IACtD,OAAO,GAAG,CAAC,GAAG,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,EAAE;QACvB,MAAM,IAAI,GAAG,OAAO,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC;QACnC,MAAM,KAAK,GAAG,EAAE,CAAC,KAAK,IAAI,MAAM,CAAC;QACjC,MAAM,MAAM,GAAG,EAAE,CAAC,UAAU,IAAI,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,CAAC,UAAU,IAAI,KAAK,KAAK,KAAK,CAAC,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AAC3E,MAAM,UAAU,mBAAmB,CAAC,QAAmB;IACrD,OAAO,QAAQ;SACZ,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,gBAAgB,IAAI,CAAC,CAAC,IAAI,CAAC;SACrD,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACZ,MAAM,KAAK,GAAa,EAAE,CAAC;QAC3B,IAAI,CAAC,CAAC,gBAAgB;YAAE,KAAK,CAAC,IAAI,CAAC,qBAAqB,CAAC,CAAC,gBAAgB,EAAE,CAAC,CAAC;QAC9E,IAAI,CAAC,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;QAC1C,IAAI,CAAC,CAAC,IAAI;YAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;QAC/B,OAAO;YACL,EAAE,EAAE,WAAW,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,gBAAgB,IAAI,CAAC,EAAE;YAClD,IAAI,EAAE,YAAY,CAAC,CAAC,IAAI,IAAI,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,GAAG;YACvF,QAAQ,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE;SAC5C,CAAC;IACJ,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,55 @@
1
+ /**
2
+ * Canonical LSPS1 tool contract — Lightning Service Provider channel orders.
3
+ *
4
+ * LSPS1 is a transport-agnostic protocol for buying inbound channel liquidity
5
+ * from a Lightning Service Provider. The maker happens to implement it, but a
6
+ * different LSP could too — so the tool names are LSP-agnostic (`lsp_*`),
7
+ * not `kaleidoswap_*`. The host's binder decides which LSP they reach.
8
+ *
9
+ * Every surface implements THESE EXACT tools, only the transport differs:
10
+ * - mobile → in-process handlers over the WDK LSP adapter
11
+ * - desktop → HTTP / MCP / CLI handlers
12
+ * - eval → stub handlers
13
+ *
14
+ * `lsp_create_order` is a spend → confirmation-gated.
15
+ *
16
+ * Pure data — no deps, no fetch, RN-safe.
17
+ */
18
+ import type { ToolDef } from '../types.js';
19
+ import { InProcessToolSource } from '../tools/in-process.js';
20
+ export interface Lsps1ToolDef extends ToolDef {
21
+ /** Moves funds → confirmation-gated. */
22
+ spend?: boolean;
23
+ }
24
+ /**
25
+ * The canonical LSPS1 tool list — agent-facing schemas. Each host's binder
26
+ * translates these args into the LSP's request body (LSPS1 JSON-RPC, the
27
+ * KaleidoSwap maker's REST routes, MCP, or a WDK adapter call).
28
+ */
29
+ export declare const LSPS1_TOOLS: Lsps1ToolDef[];
30
+ /** All LSPS1 tool names that move funds (confirmation-gated). */
31
+ export declare const LSPS1_SPEND_TOOLS: Set<string>;
32
+ export declare function isLsps1SpendTool(name: string): boolean;
33
+ export declare function getLsps1Tool(name: string): Lsps1ToolDef | undefined;
34
+ /** A handler bound to one LSPS1 tool. */
35
+ export type Lsps1Handler = (args: Record<string, unknown>) => Promise<unknown>;
36
+ export interface BindLsps1Options {
37
+ /** Skip tools without a handler instead of throwing (default false). */
38
+ allowMissing?: boolean;
39
+ /** ToolSource id for the registry (default 'lsps1'). */
40
+ id?: string;
41
+ }
42
+ /**
43
+ * Bind LSPS1 contract tools to in-process handlers → an InProcessToolSource.
44
+ *
45
+ * const source = bindLsps1Tools({
46
+ * lsp_get_info: async () => makerLsp.getInfo(),
47
+ * lsp_estimate_fees: async (args) => makerLsp.estimateFees(args),
48
+ * lsp_create_order: async (args) => makerLsp.createOrder(args),
49
+ * lsp_get_order: async ({ order_id }) => makerLsp.getOrder(order_id),
50
+ * lsp_get_network_info:async () => makerLsp.networkInfo(),
51
+ * });
52
+ * tools.register(source);
53
+ */
54
+ export declare function bindLsps1Tools(handlers: Record<string, Lsps1Handler>, opts?: BindLsps1Options): InProcessToolSource;
55
+ //# sourceMappingURL=contract.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/lsps1/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,MAAM,WAAW,YAAa,SAAQ,OAAO;IAC3C,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAcD;;;;GAIG;AACH,eAAO,MAAM,WAAW,EAAE,YAAY,EAiCrC,CAAC;AAEF,iEAAiE;AACjE,eAAO,MAAM,iBAAiB,EAAE,GAAG,CAAC,MAAM,CAEzC,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEtD;AAED,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS,CAEnE;AAED,yCAAyC;AACzC,MAAM,MAAM,YAAY,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;AAE/E,MAAM,WAAW,gBAAgB;IAC/B,wEAAwE;IACxE,YAAY,CAAC,EAAE,OAAO,CAAC;IACvB,wDAAwD;IACxD,EAAE,CAAC,EAAE,MAAM,CAAC;CACb;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,YAAY,CAAC,EAAE,IAAI,GAAE,gBAAqB,GAAG,mBAAmB,CAiBvH"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * Canonical LSPS1 tool contract — Lightning Service Provider channel orders.
3
+ *
4
+ * LSPS1 is a transport-agnostic protocol for buying inbound channel liquidity
5
+ * from a Lightning Service Provider. The maker happens to implement it, but a
6
+ * different LSP could too — so the tool names are LSP-agnostic (`lsp_*`),
7
+ * not `kaleidoswap_*`. The host's binder decides which LSP they reach.
8
+ *
9
+ * Every surface implements THESE EXACT tools, only the transport differs:
10
+ * - mobile → in-process handlers over the WDK LSP adapter
11
+ * - desktop → HTTP / MCP / CLI handlers
12
+ * - eval → stub handlers
13
+ *
14
+ * `lsp_create_order` is a spend → confirmation-gated.
15
+ *
16
+ * Pure data — no deps, no fetch, RN-safe.
17
+ */
18
+ import { InProcessToolSource } from '../tools/in-process.js';
19
+ function t(name, description, properties = {}, required = [], spend = false) {
20
+ return {
21
+ name,
22
+ description,
23
+ spend,
24
+ requiresConfirmation: spend,
25
+ parameters: { type: 'object', properties, required },
26
+ };
27
+ }
28
+ /**
29
+ * The canonical LSPS1 tool list — agent-facing schemas. Each host's binder
30
+ * translates these args into the LSP's request body (LSPS1 JSON-RPC, the
31
+ * KaleidoSwap maker's REST routes, MCP, or a WDK adapter call).
32
+ */
33
+ export const LSPS1_TOOLS = [
34
+ t('lsp_get_info', "Get the LSP's capabilities: minimum/maximum channel size, supported expiries, fee structure, accepted payment options. Use this before estimating or ordering a channel. No args."),
35
+ t('lsp_get_network_info', "Get the LSP's Lightning network info: pubkey, host, port, connect URI. Useful to display the counterparty or pre-connect a peer. No args."),
36
+ t('lsp_estimate_fees', "Estimate the fee for a channel order BEFORE committing. Returns the total cost in sats plus any LSP routing fee. Re-estimate rather than reusing a stale value.", {
37
+ lsp_balance_sat: { type: 'number', description: "Sats the LSP commits on their side (inbound capacity for the user)." },
38
+ client_balance_sat: { type: 'number', description: "Sats the user pre-funds into the channel (push amount). Often 0." },
39
+ channel_expiry_blocks: { type: 'number', description: 'Optional minimum lease in blocks. Defaults to the LSP minimum.' },
40
+ }, ['lsp_balance_sat']),
41
+ t('lsp_create_order', "Create a channel order. SPEND: confirmation-gated. Returns an order id + a Lightning invoice the user pays to lock the order. The channel opens only after payment.", {
42
+ lsp_balance_sat: { type: 'number', description: "Sats the LSP commits on their side (inbound capacity for the user)." },
43
+ client_balance_sat: { type: 'number', description: 'Sats the user pre-funds. Often 0.' },
44
+ channel_expiry_blocks: { type: 'number', description: 'Minimum lease in blocks. Defaults to LSP minimum from lsp_get_info.' },
45
+ refund_onchain_address: { type: 'string', description: 'Optional on-chain refund address if the LSP cannot open the channel.' },
46
+ }, ['lsp_balance_sat'],
47
+ /* spend */ true),
48
+ t('lsp_get_order', 'Check the status of an LSPS1 order — pending / paid / opening / completed / failed. Poll after creating an order until the channel opens.', {
49
+ order_id: { type: 'string', description: 'The order id from lsp_create_order.' },
50
+ }, ['order_id']),
51
+ ];
52
+ /** All LSPS1 tool names that move funds (confirmation-gated). */
53
+ export const LSPS1_SPEND_TOOLS = new Set(LSPS1_TOOLS.filter((t) => t.spend).map((t) => t.name));
54
+ export function isLsps1SpendTool(name) {
55
+ return LSPS1_SPEND_TOOLS.has(name);
56
+ }
57
+ export function getLsps1Tool(name) {
58
+ return LSPS1_TOOLS.find((t) => t.name === name);
59
+ }
60
+ /**
61
+ * Bind LSPS1 contract tools to in-process handlers → an InProcessToolSource.
62
+ *
63
+ * const source = bindLsps1Tools({
64
+ * lsp_get_info: async () => makerLsp.getInfo(),
65
+ * lsp_estimate_fees: async (args) => makerLsp.estimateFees(args),
66
+ * lsp_create_order: async (args) => makerLsp.createOrder(args),
67
+ * lsp_get_order: async ({ order_id }) => makerLsp.getOrder(order_id),
68
+ * lsp_get_network_info:async () => makerLsp.networkInfo(),
69
+ * });
70
+ * tools.register(source);
71
+ */
72
+ export function bindLsps1Tools(handlers, opts = {}) {
73
+ const bound = [];
74
+ for (const def of LSPS1_TOOLS) {
75
+ const handler = handlers[def.name];
76
+ if (!handler) {
77
+ if (opts.allowMissing)
78
+ continue;
79
+ throw new Error(`bindLsps1Tools: no handler for "${def.name}"`);
80
+ }
81
+ bound.push({
82
+ name: def.name,
83
+ description: def.description,
84
+ parameters: def.parameters,
85
+ requiresConfirmation: def.requiresConfirmation,
86
+ handler,
87
+ });
88
+ }
89
+ return new InProcessToolSource(opts.id ?? 'lsps1', bound);
90
+ }
91
+ //# sourceMappingURL=contract.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"contract.js","sourceRoot":"","sources":["../../src/lsps1/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAGH,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAU7D,SAAS,CAAC,CAAC,IAAY,EAAE,WAAmB,EAAE,aAAoB,EAAE,EAAE,WAAqB,EAAE,EAAE,KAAK,GAAG,KAAK;IAC1G,OAAO;QACL,IAAI;QACJ,WAAW;QACX,KAAK;QACL,oBAAoB,EAAE,KAAK;QAC3B,UAAU,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,QAAQ,EAAE;KACrD,CAAC;AACJ,CAAC;AAED;;;;GAIG;AACH,MAAM,CAAC,MAAM,WAAW,GAAmB;IACzC,CAAC,CAAC,cAAc,EACd,mLAAmL,CAAC;IAEtL,CAAC,CAAC,sBAAsB,EACtB,2IAA2I,CAAC;IAE9I,CAAC,CAAC,mBAAmB,EACnB,iKAAiK,EACjK;QACE,eAAe,EAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qEAAqE,EAAE;QAC1H,kBAAkB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,kEAAkE,EAAE;QACvH,qBAAqB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,gEAAgE,EAAE;KACzH,EACD,CAAC,iBAAiB,CAAC,CAAC;IAEtB,CAAC,CAAC,kBAAkB,EAClB,qKAAqK,EACrK;QACE,eAAe,EAAK,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qEAAqE,EAAE;QAC1H,kBAAkB,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,mCAAmC,EAAE;QACxF,qBAAqB,E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IAAI,GAAG,CAAC,CAAC;QAClE,CAAC;QACD,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,GAAG,CAAC,IAAI;YACd,WAAW,EAAE,GAAG,CAAC,WAAW;YAC5B,UAAU,EAAE,GAAG,CAAC,UAAU;YAC1B,oBAAoB,EAAE,GAAG,CAAC,oBAAoB;YAC9C,OAAO;SACR,CAAC,CAAC;IACL,CAAC;IACD,OAAO,IAAI,mBAAmB,CAAC,IAAI,CAAC,EAAE,IAAI,OAAO,EAAE,KAAK,CAAC,CAAC;AAC5D,CAAC"}
@@ -0,0 +1,40 @@
1
+ /**
2
+ * MemoryStore implementation — in-memory, with optional injected persistence
3
+ * and optional semantic ranking. Pure TS, zero deps.
4
+ *
5
+ * const store = new InMemoryMemoryStore(); // ephemeral
6
+ * const store = new InMemoryMemoryStore({ io }); // persisted (RN/Node)
7
+ * const store = new InMemoryMemoryStore({ io, embed }); // + semantic recall
8
+ */
9
+ import type { MemoryConsolidation, MemoryIO, MemoryItem, MemoryQuery, MemoryStore, NewMemory } from './types.js';
10
+ export interface MemoryStoreOptions {
11
+ /** Persistence (load on first use, save on writes). Omit for ephemeral memory. */
12
+ io?: MemoryIO;
13
+ /** Embed text for semantic recall. Omit to fall back to substring matching. */
14
+ embed?: (text: string) => Promise<number[]>;
15
+ /**
16
+ * Fold near-duplicate writes into one item instead of appending. Needs `embed`.
17
+ * Omit for append-only. See {@link MemoryConsolidation}.
18
+ */
19
+ consolidate?: MemoryConsolidation;
20
+ /** Clock — injectable for deterministic tests. */
21
+ now?: () => number;
22
+ }
23
+ export declare class InMemoryMemoryStore implements MemoryStore {
24
+ private items;
25
+ private hydrated;
26
+ private counter;
27
+ private readonly io?;
28
+ private readonly embed?;
29
+ private readonly consolidate?;
30
+ private readonly now;
31
+ constructor(opts?: MemoryStoreOptions);
32
+ private hydrate;
33
+ private persist;
34
+ add(item: NewMemory): Promise<MemoryItem>;
35
+ all(): Promise<MemoryItem[]>;
36
+ search(query: MemoryQuery): Promise<MemoryItem[]>;
37
+ remove(id: string): Promise<void>;
38
+ clear(): Promise<void>;
39
+ }
40
+ //# sourceMappingURL=store.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.d.ts","sourceRoot":"","sources":["../../src/memory/store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EACV,mBAAmB,EACnB,QAAQ,EACR,UAAU,EACV,WAAW,EACX,WAAW,EACX,SAAS,EACV,MAAM,YAAY,CAAC;AAIpB,MAAM,WAAW,kBAAkB;IACjC,kFAAkF;IAClF,EAAE,CAAC,EAAE,QAAQ,CAAC;IACd,+EAA+E;IAC/E,KAAK,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,CAAC,MAAM,EAAE,CAAC,CAAC;IAC5C;;;OAGG;IACH,WAAW,CAAC,EAAE,mBAAmB,CAAC;IAClC,kDAAkD;IAClD,GAAG,CAAC,EAAE,MAAM,MAAM,CAAC;CACpB;AAED,qBAAa,mBAAoB,YAAW,WAAW;IACrD,OAAO,CAAC,KAAK,CAAoB;IACjC,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,OAAO,CAAK;IACpB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAW;IAC/B,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAsC;IAC7D,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAC,CAAsB;IACnD,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAe;gBAEvB,IAAI,GAAE,kBAAuB;YAO3B,OAAO;YAaP,OAAO;IAIf,GAAG,CAAC,IAAI,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC;IA8CzC,GAAG,IAAI,OAAO,CAAC,UAAU,EAAE,CAAC;IAK5B,MAAM,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO,CAAC,UAAU,EAAE,CAAC;IAqCjD,MAAM,CAAC,EAAE,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC;IAMjC,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
@@ -0,0 +1,143 @@
1
+ /**
2
+ * MemoryStore implementation — in-memory, with optional injected persistence
3
+ * and optional semantic ranking. Pure TS, zero deps.
4
+ *
5
+ * const store = new InMemoryMemoryStore(); // ephemeral
6
+ * const store = new InMemoryMemoryStore({ io }); // persisted (RN/Node)
7
+ * const store = new InMemoryMemoryStore({ io, embed }); // + semantic recall
8
+ */
9
+ import { cosineSimilarity } from '../rag/vector-store.js';
10
+ const DEFAULT_DEDUP_THRESHOLD = 0.92;
11
+ export class InMemoryMemoryStore {
12
+ items = [];
13
+ hydrated = false;
14
+ counter = 0;
15
+ io;
16
+ embed;
17
+ consolidate;
18
+ now;
19
+ constructor(opts = {}) {
20
+ this.io = opts.io;
21
+ this.embed = opts.embed;
22
+ this.consolidate = opts.consolidate;
23
+ this.now = opts.now ?? (() => Date.now());
24
+ }
25
+ async hydrate() {
26
+ if (this.hydrated)
27
+ return;
28
+ this.hydrated = true;
29
+ if (this.io) {
30
+ try {
31
+ this.items = await this.io.load();
32
+ this.counter = this.items.length;
33
+ }
34
+ catch {
35
+ this.items = [];
36
+ }
37
+ }
38
+ }
39
+ async persist() {
40
+ if (this.io)
41
+ await this.io.save(this.items);
42
+ }
43
+ async add(item) {
44
+ await this.hydrate();
45
+ let text = item.text;
46
+ let embedding = item.embedding ?? (this.embed ? await this.embed(text).catch(() => undefined) : undefined);
47
+ let tags = item.tags;
48
+ let supersedeId;
49
+ // Consolidation: fold a same-kind near-duplicate into this write instead of
50
+ // appending — embedding-only by default, LLM rewrite when `merge` is set.
51
+ if (this.consolidate && embedding) {
52
+ const threshold = this.consolidate.threshold ?? DEFAULT_DEDUP_THRESHOLD;
53
+ let best;
54
+ for (const m of this.items) {
55
+ if (m.kind !== item.kind || !m.embedding)
56
+ continue;
57
+ const score = cosineSimilarity(embedding, m.embedding);
58
+ if (!best || score > best.score)
59
+ best = { item: m, score };
60
+ }
61
+ if (best && best.score >= threshold) {
62
+ supersedeId = best.item.id;
63
+ tags = unionTags(best.item.tags, item.tags);
64
+ if (this.consolidate.merge) {
65
+ const merged = await this.consolidate.merge(best.item.text, text).catch(() => null);
66
+ if (merged && merged.trim()) {
67
+ text = merged.trim();
68
+ if (this.embed)
69
+ embedding = await this.embed(text).catch(() => embedding);
70
+ }
71
+ }
72
+ // No merger → the incoming (newer) text supersedes the older item as-is.
73
+ }
74
+ }
75
+ const full = {
76
+ id: item.id ?? `mem_${this.now()}_${++this.counter}`,
77
+ text,
78
+ kind: item.kind,
79
+ tags,
80
+ createdAt: item.createdAt ?? this.now(),
81
+ ...(embedding ? { embedding } : {}),
82
+ };
83
+ if (supersedeId)
84
+ this.items = this.items.filter((m) => m.id !== supersedeId);
85
+ this.items.push(full);
86
+ await this.persist();
87
+ return full;
88
+ }
89
+ async all() {
90
+ await this.hydrate();
91
+ return [...this.items];
92
+ }
93
+ async search(query) {
94
+ await this.hydrate();
95
+ const limit = query.limit ?? 5;
96
+ let pool = this.items;
97
+ if (query.kind)
98
+ pool = pool.filter((m) => m.kind === query.kind);
99
+ if (query.tags?.length) {
100
+ pool = pool.filter((m) => query.tags.every((t) => m.tags?.includes(t)));
101
+ }
102
+ const text = query.text?.trim();
103
+ if (!text) {
104
+ // No query text → most recent first.
105
+ return [...pool].sort((a, b) => b.createdAt - a.createdAt).slice(0, limit);
106
+ }
107
+ // Semantic ranking when both the query and items are embedded.
108
+ if (this.embed && pool.some((m) => m.embedding)) {
109
+ const qv = await this.embed(text).catch(() => null);
110
+ if (qv) {
111
+ return [...pool]
112
+ .map((m) => ({ m, score: m.embedding ? cosineSimilarity(qv, m.embedding) : -1 }))
113
+ .sort((a, b) => b.score - a.score)
114
+ .slice(0, limit)
115
+ .map((x) => x.m);
116
+ }
117
+ }
118
+ // Fallback: substring score + recency.
119
+ const q = text.toLowerCase();
120
+ return [...pool]
121
+ .map((m) => ({ m, hit: m.text.toLowerCase().includes(q) ? 1 : 0 }))
122
+ .sort((a, b) => b.hit - a.hit || b.m.createdAt - a.m.createdAt)
123
+ .slice(0, limit)
124
+ .map((x) => x.m);
125
+ }
126
+ async remove(id) {
127
+ await this.hydrate();
128
+ this.items = this.items.filter((m) => m.id !== id);
129
+ await this.persist();
130
+ }
131
+ async clear() {
132
+ await this.hydrate();
133
+ this.items = [];
134
+ await this.persist();
135
+ }
136
+ }
137
+ /** Merge two optional tag lists, de-duplicated. Returns undefined when both empty. */
138
+ function unionTags(a, b) {
139
+ if (!a?.length && !b?.length)
140
+ return undefined;
141
+ return [...new Set([...(a ?? []), ...(b ?? [])])];
142
+ }
143
+ //# sourceMappingURL=store.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"store.js","sourceRoot":"","sources":["../../src/memory/store.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAU1D,MAAM,uBAAuB,GAAG,IAAI,CAAC;AAgBrC,MAAM,OAAO,mBAAmB;IACtB,KAAK,GAAiB,EAAE,CAAC;IACzB,QAAQ,GAAG,KAAK,CAAC;IACjB,OAAO,GAAG,CAAC,CAAC;IACH,EAAE,CAAY;IACd,KAAK,CAAuC;IAC5C,WAAW,CAAuB;IAClC,GAAG,CAAe;IAEnC,YAAY,OAA2B,EAAE;QACvC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;QACxB,IAAI,CAAC,WAAW,GAAG,IAAI,CAAC,WAAW,CAAC;QACpC,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5C,CAAC;IAEO,KAAK,CAAC,OAAO;QACnB,IAAI,IAAI,CAAC,QAAQ;YAAE,OAAO;QAC1B,IAAI,CAAC,QAAQ,GAAG,IA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memory tool source — lets the agent persist and recall things across
3
+ * sessions (`remember`, `recall`). Pairs with auto-recall in the
4
+ * ContextBuilder; this is the explicit, agent-driven side.
5
+ */
6
+ import type { ToolSource } from '../tools/source.js';
7
+ import type { MemoryStore } from './types.js';
8
+ export declare function createMemoryToolSource(store: MemoryStore): ToolSource;
9
+ //# sourceMappingURL=tool.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.d.ts","sourceRoot":"","sources":["../../src/memory/tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,KAAK,EAAc,WAAW,EAAE,MAAM,YAAY,CAAC;AAM1D,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,WAAW,GAAG,UAAU,CA6DrE"}
@@ -0,0 +1,70 @@
1
+ /**
2
+ * Memory tool source — lets the agent persist and recall things across
3
+ * sessions (`remember`, `recall`). Pairs with auto-recall in the
4
+ * ContextBuilder; this is the explicit, agent-driven side.
5
+ */
6
+ const REMEMBER = 'remember';
7
+ const RECALL = 'recall';
8
+ const KINDS = ['fact', 'preference', 'event', 'note'];
9
+ export function createMemoryToolSource(store) {
10
+ const tools = [
11
+ {
12
+ name: REMEMBER,
13
+ description: 'Save something to long-term memory so you recall it in future sessions ' +
14
+ '— a user preference, a fact, or an event. Use sparingly for durable info.',
15
+ parameters: {
16
+ type: 'object',
17
+ properties: {
18
+ text: { type: 'string', description: 'What to remember (a short sentence)' },
19
+ kind: { type: 'string', enum: KINDS, description: 'fact | preference | event | note' },
20
+ tags: { type: 'array', items: { type: 'string' }, description: 'Optional tags' },
21
+ },
22
+ required: ['text'],
23
+ },
24
+ },
25
+ {
26
+ name: RECALL,
27
+ description: 'Search your long-term memory for what you know about something before answering.',
28
+ parameters: {
29
+ type: 'object',
30
+ properties: {
31
+ query: { type: 'string', description: 'What to recall' },
32
+ limit: { type: 'number', description: 'Max items (default 5)' },
33
+ },
34
+ required: ['query'],
35
+ },
36
+ },
37
+ ];
38
+ async function execute(name, args) {
39
+ if (name === REMEMBER) {
40
+ const text = String(args.text ?? '').trim();
41
+ if (!text)
42
+ throw new Error('remember: text is required');
43
+ const kind = KINDS.includes(String(args.kind))
44
+ ? args.kind
45
+ : 'note';
46
+ const tags = Array.isArray(args.tags) ? args.tags.map(String) : undefined;
47
+ const item = await store.add({ text, kind, tags });
48
+ return `Remembered (${item.kind}): ${item.text}`;
49
+ }
50
+ if (name === RECALL) {
51
+ const query = String(args.query ?? '').trim();
52
+ if (!query)
53
+ throw new Error('recall: query is required');
54
+ const limit = Number(args.limit) > 0 ? Number(args.limit) : 5;
55
+ const items = await store.search({ text: query, limit });
56
+ if (items.length === 0)
57
+ return 'Nothing relevant in memory.';
58
+ return items.map((m) => `- (${m.kind}) ${m.text}`).join('\n');
59
+ }
60
+ throw new Error(`memory: unknown tool ${name}`);
61
+ }
62
+ const names = new Set([REMEMBER, RECALL]);
63
+ return {
64
+ id: 'memory',
65
+ listTools: () => tools,
66
+ has: (name) => names.has(name),
67
+ execute,
68
+ };
69
+ }
70
+ //# sourceMappingURL=tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tool.js","sourceRoot":"","sources":["../../src/memory/tool.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAMH,MAAM,QAAQ,GAAG,UAAU,CAAC;AAC5B,MAAM,MAAM,GAAG,QAAQ,CAAC;AACxB,MAAM,KAAK,GAAiB,CAAC,MAAM,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAEpE,MAAM,UAAU,sBAAsB,CAAC,KAAkB;IACvD,MAAM,KAAK,GAAc;QACvB;YACE,IAAI,EAAE,QAAQ;YACd,WAAW,EACT,yEAAyE;gBACzE,2EAA2E;YAC7E,UAAU,EAAE;gBACV,IAAI,EAAE,QAAQ;gBACd,UAAU,EAAE;oBACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,qC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