@kaleidorg/mind 0.4.0 → 0.5.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 (79) hide show
  1. package/dist/funnel.d.ts +19 -0
  2. package/dist/funnel.d.ts.map +1 -1
  3. package/dist/funnel.js +48 -10
  4. package/dist/funnel.js.map +1 -1
  5. package/dist/index.d.ts +5 -2
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +10 -3
  8. package/dist/index.js.map +1 -1
  9. package/dist/kaleidoswap/contract.d.ts +3 -3
  10. package/dist/kaleidoswap/contract.d.ts.map +1 -1
  11. package/dist/kaleidoswap/contract.js +16 -4
  12. package/dist/kaleidoswap/contract.js.map +1 -1
  13. package/dist/knowledge/bitcoin-copilot.d.ts.map +1 -1
  14. package/dist/knowledge/bitcoin-copilot.js +102 -0
  15. package/dist/knowledge/bitcoin-copilot.js.map +1 -1
  16. package/dist/knowledge/btc-map.d.ts +14 -17
  17. package/dist/knowledge/btc-map.d.ts.map +1 -1
  18. package/dist/knowledge/btc-map.js +66 -266
  19. package/dist/knowledge/btc-map.js.map +1 -1
  20. package/dist/lsps1/contract.d.ts.map +1 -1
  21. package/dist/lsps1/contract.js +28 -10
  22. package/dist/lsps1/contract.js.map +1 -1
  23. package/dist/recipe/buy-asset-channel.d.ts +26 -0
  24. package/dist/recipe/buy-asset-channel.d.ts.map +1 -0
  25. package/dist/recipe/buy-asset-channel.js +112 -0
  26. package/dist/recipe/buy-asset-channel.js.map +1 -0
  27. package/dist/recipe/kaleidoswap-atomic.d.ts +26 -18
  28. package/dist/recipe/kaleidoswap-atomic.d.ts.map +1 -1
  29. package/dist/recipe/kaleidoswap-atomic.js +101 -63
  30. package/dist/recipe/kaleidoswap-atomic.js.map +1 -1
  31. package/dist/recipe/kaleidoswap-channel-order.d.ts +35 -0
  32. package/dist/recipe/kaleidoswap-channel-order.d.ts.map +1 -0
  33. package/dist/recipe/kaleidoswap-channel-order.js +493 -0
  34. package/dist/recipe/kaleidoswap-channel-order.js.map +1 -0
  35. package/dist/recipe/kaleidoswap-price.d.ts +21 -0
  36. package/dist/recipe/kaleidoswap-price.d.ts.map +1 -0
  37. package/dist/recipe/kaleidoswap-price.js +57 -0
  38. package/dist/recipe/kaleidoswap-price.js.map +1 -0
  39. package/dist/recipe/runner.d.ts +7 -1
  40. package/dist/recipe/runner.d.ts.map +1 -1
  41. package/dist/recipe/runner.js +115 -29
  42. package/dist/recipe/runner.js.map +1 -1
  43. package/dist/recipe/swap.d.ts +26 -1
  44. package/dist/recipe/swap.d.ts.map +1 -1
  45. package/dist/recipe/swap.js +108 -13
  46. package/dist/recipe/swap.js.map +1 -1
  47. package/dist/recipe/types.d.ts +25 -1
  48. package/dist/recipe/types.d.ts.map +1 -1
  49. package/dist/skills/registry.d.ts +33 -1
  50. package/dist/skills/registry.d.ts.map +1 -1
  51. package/dist/skills/registry.js +45 -1
  52. package/dist/skills/registry.js.map +1 -1
  53. package/package.json +1 -1
  54. package/skills/README.md +3 -0
  55. package/skills/kaleido-lsps/SKILL.md +101 -43
  56. package/skills/kaleido-trading/SKILL.md +81 -31
  57. package/skills/merchant-finder/SKILL.md +96 -66
  58. package/skills/rgb-lightning-node/SKILL.md +108 -0
  59. package/skills/wallet-assistant/SKILL.md +32 -21
  60. package/src/funnel.ts +66 -11
  61. package/src/index.ts +14 -2
  62. package/src/kaleidoswap/contract.test.ts +7 -2
  63. package/src/kaleidoswap/contract.ts +27 -5
  64. package/src/knowledge/bitcoin-copilot.ts +111 -0
  65. package/src/knowledge/btc-map.test.ts +53 -96
  66. package/src/knowledge/btc-map.ts +72 -287
  67. package/src/lsps1/contract.ts +32 -14
  68. package/src/recipe/buy-asset-channel.test.ts +148 -0
  69. package/src/recipe/buy-asset-channel.ts +118 -0
  70. package/src/recipe/kaleidoswap-atomic.test.ts +134 -61
  71. package/src/recipe/kaleidoswap-atomic.ts +112 -66
  72. package/src/recipe/kaleidoswap-channel-order.test.ts +333 -0
  73. package/src/recipe/kaleidoswap-channel-order.ts +548 -0
  74. package/src/recipe/kaleidoswap-price.ts +68 -0
  75. package/src/recipe/recipe.test.ts +61 -5
  76. package/src/recipe/runner.ts +128 -31
  77. package/src/recipe/swap.ts +109 -13
  78. package/src/recipe/types.ts +25 -1
  79. package/src/skills/registry.ts +52 -1
@@ -0,0 +1,112 @@
1
+ /**
2
+ * Built-in "buy an asset channel" recipe — the onboarding buy.
3
+ *
4
+ * The user has on-chain BTC but no Lightning channel yet, and wants to HOLD an
5
+ * RGB asset (USDT, XAUT). They can't swap (no channel to swap inside), so they
6
+ * buy a NEW channel from the maker LSP pre-loaded with the asset. One quote,
7
+ * one spend:
8
+ *
9
+ * "buy 100 usdt" / "get me 50 xaut" / "i want 200 usdt"
10
+ * ↓ 1 model inference (slot extraction; 0 when the regex hits)
11
+ * kaleidoswap_lsp_quote_asset_channel ← maker prices the asset + channel
12
+ * kaleidoswap_lsp_create_asset_channel 🔒 ← (final) order it; pay to open
13
+ *
14
+ * Distinct from `swapRecipe`: a swap names a source asset ("swap 10 usdt FOR
15
+ * btc", "buy btc WITH usdt") and needs an existing channel. This is the
16
+ * no-source, no-channel onboarding path — "buy <amount> <asset>" with nothing
17
+ * to spend it from — so it must be SELECTED BEFORE swap for that phrasing.
18
+ *
19
+ * Opt-in: register via `Funnel.recipes` (like `kaleidoswapAtomicRecipe`). The
20
+ * host binds `kaleidoswap_lsp_*` to its transport (maker REST / MCP / WDK).
21
+ */
22
+ /** RGB assets the maker sells as an asset channel. BTC is never "bought" this way. */
23
+ const RGB_ASSET = /\b(usdt|tether|xaut|gold)\b/i;
24
+ /** A named funding source ⇒ this is a swap, not an onboarding buy. */
25
+ const HAS_SOURCE = /\b(?:with|using|from)\b|\bfor\s+(?:btc|bitcoin|sats?|usdt|xaut|tether|gold)\b/i;
26
+ /** Verbs other intents own (swap / sell / send) — never an onboarding buy. */
27
+ const NOT_BUY = /\b(swap|exchange|convert|trade|sell|send)\b/i;
28
+ /** Acquire verbs that DO mean an onboarding buy. */
29
+ const BUY_VERB = /\b(buy|get|acquire|want|purchase|onboard|need)\b/i;
30
+ function normAsset(a) {
31
+ if (!a)
32
+ return undefined;
33
+ const x = a.toLowerCase();
34
+ if (/usdt|tether/.test(x))
35
+ return 'USDT';
36
+ if (/xaut|gold/.test(x))
37
+ return 'XAUT';
38
+ return undefined;
39
+ }
40
+ const num = (s) => {
41
+ if (!s)
42
+ return undefined;
43
+ const n = Number(s.replace(/,/g, ''));
44
+ return Number.isFinite(n) ? n : undefined;
45
+ };
46
+ /** Thousands separators, locale-independent (deterministic for tests). */
47
+ const commas = (n) => String(n).replace(/\B(?=(\d{3})+(?!\d))/g, ',');
48
+ /** "buy 100 usdt" / "get me 50 xaut" / "i want 200 usdt" / "purchase 10 xaut". */
49
+ export function extractBuyAsset(text) {
50
+ const t = text.trim();
51
+ if (NOT_BUY.test(t) || HAS_SOURCE.test(t))
52
+ return null;
53
+ if (!RGB_ASSET.test(t))
54
+ return null;
55
+ // buy/get/want/acquire/purchase [me] <amount> <asset>
56
+ const m = t.match(/\b(?:buy|get|acquire|want|purchase|onboard|need)\b(?:\s+me)?\s+([\d.,]+)\s*([a-z]+)/i);
57
+ if (!m)
58
+ return null;
59
+ const asset = normAsset(m[2]);
60
+ const amount = num(m[1]);
61
+ if (!asset || amount === undefined)
62
+ return null;
63
+ return { asset, asset_amount: amount };
64
+ }
65
+ export const buyAssetChannelRecipe = {
66
+ name: 'buy-asset-channel',
67
+ description: 'Onboarding buy: purchase a new Lightning channel pre-loaded with an RGB asset (USDT, XAUT) from the maker LSP — for a user with on-chain BTC but no channel yet. Quote, then order (with confirmation).',
68
+ // "buy/get/want N <rgb-asset>" with NO named source asset and NO swap/send verb.
69
+ match: (t) => !NOT_BUY.test(t) && !HAS_SOURCE.test(t) && RGB_ASSET.test(t) && BUY_VERB.test(t),
70
+ triggers: ['buy', 'get', 'purchase', 'acquire'],
71
+ slots: [
72
+ { name: 'asset', type: 'string', description: 'RGB asset to acquire (USDT or XAUT)', required: true },
73
+ { name: 'asset_amount', type: 'number', description: 'Amount of the asset to load into the channel (display units, e.g. 100)', required: true },
74
+ ],
75
+ extract: extractBuyAsset,
76
+ confident: (s) => !!s.asset && s.asset_amount !== undefined && Number(s.asset_amount) > 0,
77
+ steps: [
78
+ // 1. Maker prices the asset + the channel.
79
+ // Returns { rfq_id, btc_amount_sat, channel_fee_sat, total_sat, expires_at }.
80
+ {
81
+ tool: 'kaleidoswap_lsp_quote_asset_channel',
82
+ as: 'quote',
83
+ args: (ctx) => ({ asset: ctx.slots.asset, asset_amount: ctx.slots.asset_amount }),
84
+ },
85
+ ],
86
+ // 2. Order the channel with the fresh rfq_id. Spend → confirmation-gated.
87
+ // The quote's cost fields ride along so the host's confirm card can show
88
+ // the price before approval; the create tool treats them as display-only.
89
+ final: {
90
+ tool: 'kaleidoswap_lsp_create_asset_channel',
91
+ args: (ctx) => {
92
+ const q = (ctx.results.quote ?? {});
93
+ return {
94
+ asset: ctx.slots.asset,
95
+ asset_amount: ctx.slots.asset_amount,
96
+ rfq_id: q.rfq_id,
97
+ total_sat: q.total_sat,
98
+ btc_amount_sat: q.btc_amount_sat,
99
+ channel_fee_sat: q.channel_fee_sat,
100
+ expires_at: q.expires_at,
101
+ };
102
+ },
103
+ },
104
+ summary: (ctx, finalResult) => {
105
+ const q = ctx.results.quote;
106
+ const o = finalResult;
107
+ const cost = typeof q?.total_sat === 'number' ? ` for ${commas(q.total_sat)} sats` : '';
108
+ const id = o?.order_id ? ` (order ${o.order_id})` : '';
109
+ return `Ordered a Lightning channel with ${ctx.slots.asset_amount} ${ctx.slots.asset}${cost}${id}. Pay the returned invoice/address to open it.`;
110
+ },
111
+ };
112
+ //# sourceMappingURL=buy-asset-channel.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"buy-asset-channel.js","sourceRoot":"","sources":["../../src/recipe/buy-asset-channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;A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AAM,EAAE,GAAG,CAAC,EAAE,QAAQ,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,OAAO,oCAAoC,GAAG,CAAC,KAAK,CAAC,YAAY,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,GAAG,IAAI,GAAG,EAAE,gDAAgD,CAAC;IACnJ,CAAC;CACF,CAAC"}
@@ -1,26 +1,34 @@
1
1
  /**
2
- * Built-in "atomic swap on KaleidoSwap" recipe — trust-minimised chain.
2
+ * Built-in "swap on KaleidoSwap" recipe — the real atomic-swap chain.
3
3
  *
4
- * Most users want the simple market-order swap (`swapRecipe` over generic
5
- * `get_swap_quote` / `execute_swap`). This recipe is the EXPLICIT atomic path:
6
- * the user creates an RGB/LN receive invoice, the maker locks the swap, the
7
- * user pays the maker's Lightning invoice, and the maker releases.
4
+ * A swap (especially the full maker + RLN atomic) is a 6-step, two-service flow
5
+ * no small model can plan reliably, so the recipe carries the plan. The model
6
+ * is used for natural-language understanding of the request (slot extraction).
8
7
  *
9
- * Triggered only by explicit atomic-swap intent ("atomic swap", "trustless
10
- * swap", "htlc swap") so it never preempts the simpler swap path for vague
11
- * phrasings.
8
+ * "buy 1 usdt" (or "swap 10 usdt to btc")
9
+ * heuristic pre-filter (0 inf) decides to enter the reliable recipe branch
10
+ * 1 model inference (forced LLM slot extraction — the model parses intent)
11
+ * kaleidoswap_get_quote ← MAKER prices the swap (read-only)
12
+ * ↓ [ONE confirmation gate — shows the real quote numbers]
13
+ * kaleidoswap_atomic_init ← MAKER locks the swap → swapstring, payment_hash
14
+ * rln_get_node_info ← NODE read pubkey (= taker_pubkey)
15
+ * rln_whitelist_swap ← NODE accept the swapstring
16
+ * kaleidoswap_atomic_execute ← MAKER settle (final)
12
17
  *
13
- * "atomic swap 100000 sats for usdt"
14
- * 1 model inference (slot extraction)
15
- * kaleidoswap_get_quote ← maker prices the swap
16
- * rln_create_rgb_invoice ← user's node prepares receive (if to_asset is RGB)
17
- * rln_create_ln_invoice ← (alt) if to_asset is BTC
18
- * kaleidoswap_atomic_init 🔒 ← maker locks the swap, returns its invoice
19
- * rln_pay_invoice 🔒 ← user pays the maker
20
- * kaleidoswap_atomic_execute 🔒 ← (final) maker releases the asset
18
+ * `forceModelExtract` ensures the model is always consulted for slot parsing
19
+ * (1 inference) so natural language like "buy 1 usdt" is interpreted by the LLM.
20
+ * A safety fallback in the runner uses the deterministic extractor if the model
21
+ * returns incomplete slots. The execution sequence + single-confirm gate remain
22
+ * fully deterministic and reliable.
21
23
  *
22
- * Two-or-three confirmation gates are intentional: each represents a distinct
23
- * decision point. The host's confirm UI describes what's about to happen.
24
+ * Status is NOT polled here settlement takes seconds-to-minutes and blocking
25
+ * the chat is bad UX. The recipe reports "submitted, settling"; the user (or a
26
+ * follow-up turn) calls `kaleidoswap_atomic_status` on demand.
27
+ *
28
+ * Confirmation: the single decision a user makes is "given this quote, proceed?"
29
+ * — so the recipe declares ONE `confirm(ctx)` summary, fired after the quote and
30
+ * before init. init/whitelist/execute then run as one approved unit. (The
31
+ * runner's recipe-level confirm path handles this; see recipe/runner.ts.)
24
32
  */
25
33
  import type { Recipe } from './types.js';
26
34
  export declare const kaleidoswapAtomicRecipe: Recipe;
@@ -1 +1 @@
1
- {"version":3,"file":"kaleidoswap-atomic.d.ts","sourceRoot":"","sources":["../../src/recipe/kaleidoswap-atomic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAUzC,eAAO,MAAM,uBAAuB,EAAE,MAiFrC,CAAC"}
1
+ {"version":3,"file":"kaleidoswap-atomic.d.ts","sourceRoot":"","sources":["../../src/recipe/kaleidoswap-atomic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAkCxD,eAAO,MAAM,uBAAuB,EAAE,MA+FrC,CAAC"}
@@ -1,46 +1,77 @@
1
1
  /**
2
- * Built-in "atomic swap on KaleidoSwap" recipe — trust-minimised chain.
2
+ * Built-in "swap on KaleidoSwap" recipe — the real atomic-swap chain.
3
3
  *
4
- * Most users want the simple market-order swap (`swapRecipe` over generic
5
- * `get_swap_quote` / `execute_swap`). This recipe is the EXPLICIT atomic path:
6
- * the user creates an RGB/LN receive invoice, the maker locks the swap, the
7
- * user pays the maker's Lightning invoice, and the maker releases.
4
+ * A swap (especially the full maker + RLN atomic) is a 6-step, two-service flow
5
+ * no small model can plan reliably, so the recipe carries the plan. The model
6
+ * is used for natural-language understanding of the request (slot extraction).
8
7
  *
9
- * Triggered only by explicit atomic-swap intent ("atomic swap", "trustless
10
- * swap", "htlc swap") so it never preempts the simpler swap path for vague
11
- * phrasings.
8
+ * "buy 1 usdt" (or "swap 10 usdt to btc")
9
+ * heuristic pre-filter (0 inf) decides to enter the reliable recipe branch
10
+ * 1 model inference (forced LLM slot extraction — the model parses intent)
11
+ * kaleidoswap_get_quote ← MAKER prices the swap (read-only)
12
+ * ↓ [ONE confirmation gate — shows the real quote numbers]
13
+ * kaleidoswap_atomic_init ← MAKER locks the swap → swapstring, payment_hash
14
+ * rln_get_node_info ← NODE read pubkey (= taker_pubkey)
15
+ * rln_whitelist_swap ← NODE accept the swapstring
16
+ * kaleidoswap_atomic_execute ← MAKER settle (final)
12
17
  *
13
- * "atomic swap 100000 sats for usdt"
14
- * 1 model inference (slot extraction)
15
- * kaleidoswap_get_quote ← maker prices the swap
16
- * rln_create_rgb_invoice ← user's node prepares receive (if to_asset is RGB)
17
- * rln_create_ln_invoice ← (alt) if to_asset is BTC
18
- * kaleidoswap_atomic_init 🔒 ← maker locks the swap, returns its invoice
19
- * rln_pay_invoice 🔒 ← user pays the maker
20
- * kaleidoswap_atomic_execute 🔒 ← (final) maker releases the asset
18
+ * `forceModelExtract` ensures the model is always consulted for slot parsing
19
+ * (1 inference) so natural language like "buy 1 usdt" is interpreted by the LLM.
20
+ * A safety fallback in the runner uses the deterministic extractor if the model
21
+ * returns incomplete slots. The execution sequence + single-confirm gate remain
22
+ * fully deterministic and reliable.
21
23
  *
22
- * Two-or-three confirmation gates are intentional: each represents a distinct
23
- * decision point. The host's confirm UI describes what's about to happen.
24
+ * Status is NOT polled here settlement takes seconds-to-minutes and blocking
25
+ * the chat is bad UX. The recipe reports "submitted, settling"; the user (or a
26
+ * follow-up turn) calls `kaleidoswap_atomic_status` on demand.
27
+ *
28
+ * Confirmation: the single decision a user makes is "given this quote, proceed?"
29
+ * — so the recipe declares ONE `confirm(ctx)` summary, fired after the quote and
30
+ * before init. init/whitelist/execute then run as one approved unit. (The
31
+ * runner's recipe-level confirm path handles this; see recipe/runner.ts.)
24
32
  */
25
33
  import { extractSwap } from './swap.js';
26
- const ATOMIC_INTENT = /\b(atomic|trustless|htlc)\b.*\b(swap|exchange|convert|trade)\b|\b(swap|exchange|convert|trade)\b.*\b(atomic|trustless|htlc)\b/i;
27
- function isBtc(asset) {
28
- return String(asset ?? '').toUpperCase() === 'BTC';
29
- }
34
+ // Fire on swap intent — "swap/exchange/convert/trade", or "buy/sell/get" when a
35
+ // crypto asset is named (so "buy one usdt" routes here, but "buy a gift card"
36
+ // does not). PRICE / rate / "how much" questions are read-only and go to
37
+ // `kaleidoswapPriceRecipe` instead — keep them out of this match.
38
+ const ASSET = /\b(btc|bitcoin|sats?|usdt|tether|xaut|gold)\b/i;
39
+ const SWAP_INTENT = (t) => {
40
+ // Explanatory / educational questions → route to RAG-backed agentic answer,
41
+ // not the deterministic spend chain.
42
+ if (/\b(why|how|what|when|explain|tell\s+me|do\s+I\s+need|should\s+I|can\s+I)\b/i.test(t))
43
+ return false;
44
+ if (/\b(swap|exchange|convert|trade)\b/i.test(t))
45
+ return true;
46
+ if (/\b(buy|sell|get|purchase|acquire)\b/i.test(t) &&
47
+ ASSET.test(t) &&
48
+ // Exclude commerce / receive / LSPS1 channel-order phrasings that share
49
+ // the buy/get verb. "Buy a USDT channel" is a channel order, not a swap.
50
+ !/\b(gift\s?card|top-?up|esim|voucher|invoice|address|channel|inbound|liquidity|lsps?\b)\b/i.test(t))
51
+ return true;
52
+ return false;
53
+ };
30
54
  export const kaleidoswapAtomicRecipe = {
31
55
  name: 'kaleidoswap-atomic',
32
- description: 'Trust-minimised atomic swap on KaleidoSwap: quote, prepare a receive invoice on the user\'s node, lock the swap with the maker, pay, and execute.',
33
- match: (t) => ATOMIC_INTENT.test(t),
34
- triggers: ['atomic swap', 'trustless swap', 'htlc swap'],
56
+ description: 'Swap between BTC and an RGB asset on KaleidoSwap: quote, confirm once, then init (maker) whitelist (node) execute (maker).',
57
+ match: (t) => SWAP_INTENT(t),
58
+ triggers: ['swap', 'exchange', 'convert', 'trade', 'buy', 'sell'],
35
59
  slots: [
36
60
  { name: 'from_asset', type: 'string', description: 'Asset to spend (BTC / USDT / XAUT)', required: true },
37
61
  { name: 'to_asset', type: 'string', description: 'Asset to receive (BTC / USDT / XAUT)', required: true },
38
- { name: 'amount', type: 'number', description: 'Amount of from_asset to swap' },
62
+ { name: 'amount', type: 'number', description: 'The amount the user named' },
63
+ { name: 'amount_side', type: 'string', description: "Which leg the amount is on: 'from' (sell/swap) or 'to' (buy)" },
39
64
  ],
65
+ // Keep the fast `extract` for the Funnel's cheap pre-filter (so "buy 1 usdt"
66
+ // reliably enters the recipe branch instead of falling to free agentic).
67
+ // `forceModelExtract` makes runRecipe ignore the deterministic result and
68
+ // always ask the model to produce the actual slots used for execution.
40
69
  extract: extractSwap,
70
+ forceModelExtract: true,
41
71
  confident: (s) => !!s.from_asset && !!s.to_asset && !!s.amount,
42
72
  steps: [
43
- // 1. Maker quotes the swap. Returns { quote_id, receive_amount, fees, ttl_ms, ... }.
73
+ // 1. MAKER quotes the swap (read-only). Returns rfq_id + full asset specs
74
+ // (echoes the rgb: asset ids and maker-unit amounts) + *_display strings.
44
75
  {
45
76
  tool: 'kaleidoswap_get_quote',
46
77
  as: 'quote',
@@ -48,64 +79,71 @@ export const kaleidoswapAtomicRecipe = {
48
79
  from_asset: ctx.slots.from_asset,
49
80
  to_asset: ctx.slots.to_asset,
50
81
  amount: ctx.slots.amount,
82
+ // 'to' for buy ("buy 1 USDT" → amount is what you RECEIVE); default
83
+ // 'from' for sell/swap. The host puts the amount on the right leg.
84
+ amount_side: ctx.slots.amount_side ?? 'from',
51
85
  }),
52
86
  },
53
- // 2a. User's node creates an RGB receive invoice (when to_asset is an RGB asset).
54
- {
55
- tool: 'rln_create_rgb_invoice',
56
- as: 'receive_rgb',
57
- args: (ctx) => {
58
- const q = ctx.results.quote;
59
- return { asset: ctx.slots.to_asset, amount: q?.receive_amount };
60
- },
61
- skipIf: (ctx) => isBtc(ctx.slots.to_asset),
62
- },
63
- // 2b. User's node creates an LN receive invoice (when to_asset is BTC).
64
- {
65
- tool: 'rln_create_ln_invoice',
66
- as: 'receive_ln',
67
- args: (ctx) => {
68
- const q = ctx.results.quote;
69
- return { amount_sats: q?.receive_amount };
70
- },
71
- skipIf: (ctx) => !isBtc(ctx.slots.to_asset),
72
- },
73
- // 3. Maker locks the swap. Returns { atomic_id, maker_invoice }. Spend-gated.
87
+ // 2. MAKER locks the swap. SwapRequest is flat (asset ids + maker-unit
88
+ // amounts) — sourced straight from the quote result, no re-scaling.
89
+ // First spend step → the recipe-level confirm gate fires just before it.
74
90
  {
75
91
  tool: 'kaleidoswap_atomic_init',
76
- as: 'atomic',
92
+ as: 'init',
77
93
  args: (ctx) => {
78
- const rgb = ctx.results.receive_rgb;
79
- const ln = ctx.results.receive_ln;
80
94
  const q = ctx.results.quote;
81
95
  return {
82
- quote_id: q?.quote_id,
83
- receive_invoice: rgb?.invoice ?? ln?.invoice,
96
+ rfq_id: q?.rfq_id,
97
+ from_asset: q?.from_asset?.asset_id,
98
+ from_amount: q?.from_asset?.amount,
99
+ to_asset: q?.to_asset?.asset_id,
100
+ to_amount: q?.to_asset?.amount,
84
101
  };
85
102
  },
86
103
  },
87
- // 4. User pays the maker's Lightning invoice. Spend-gated by the wallet contract.
104
+ // 3. NODE: read our pubkey — the maker needs it as taker_pubkey for execute.
88
105
  {
89
- tool: 'rln_pay_invoice',
90
- as: 'paid',
106
+ tool: 'rln_get_node_info',
107
+ as: 'node',
108
+ args: () => ({}),
109
+ },
110
+ // 4. NODE: whitelist the maker's swapstring (accept the swap). Ungated —
111
+ // covered by the single confirm above.
112
+ {
113
+ tool: 'rln_whitelist_swap',
114
+ as: 'whitelist',
91
115
  args: (ctx) => {
92
- const a = ctx.results.atomic;
93
- return { invoice: a?.maker_invoice };
116
+ const init = ctx.results.init;
117
+ return { swapstring: init?.swapstring };
94
118
  },
95
119
  },
96
120
  ],
97
- // 5. Maker releases the receive asset swap completes. Spend-gated.
121
+ // 5. MAKER settles the swap. Needs swapstring + taker_pubkey + payment_hash.
98
122
  final: {
99
123
  tool: 'kaleidoswap_atomic_execute',
100
124
  args: (ctx) => {
101
- const a = ctx.results.atomic;
102
- return { atomic_id: a?.atomic_id };
125
+ const init = ctx.results.init;
126
+ const node = ctx.results.node;
127
+ return {
128
+ swapstring: init?.swapstring,
129
+ taker_pubkey: node?.pubkey,
130
+ payment_hash: init?.payment_hash,
131
+ };
103
132
  },
104
133
  },
134
+ // ONE confirmation, fired after the quote / before init, with the real numbers.
135
+ confirm: (ctx) => {
136
+ const q = ctx.results.quote;
137
+ const from = q?.from_amount_display ?? `${ctx.slots.amount} ${ctx.slots.from_asset}`;
138
+ const to = q?.to_amount_display ?? String(ctx.slots.to_asset);
139
+ const fee = q?.fee_display ? ` · fee ${q.fee_display}` : '';
140
+ return `Swap ${from} → ${to}${fee} on KaleidoSwap. Proceed?`;
141
+ },
105
142
  summary: (ctx) => {
106
143
  const q = ctx.results.quote;
107
- const tail = q?.receive_amount ? ` ≈ ${q.receive_amount} ${ctx.slots.to_asset}` : '';
108
- return `Atomic swap: ${ctx.slots.amount} ${ctx.slots.from_asset} → ${ctx.slots.to_asset}${tail}.`;
144
+ const from = q?.from_amount_display ?? `${ctx.slots.amount} ${ctx.slots.from_asset}`;
145
+ const to = q?.to_amount_display ?? String(ctx.slots.to_asset);
146
+ return `Swap submitted: ${from} → ${to}. Settling now — ask me to check the status.`;
109
147
  },
110
148
  };
111
149
  //# sourceMappingURL=kaleidoswap-atomic.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"kaleidoswap-atomic.js","sourceRoot":"","sources":["../../src/recipe/kaleidoswap-atomic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,MAAM,aAAa,GACjB,gIAAgI,CAAC;AAEnI,SAAS,KAAK,CAAC,KAAc;IAC3B,OAAO,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC;AACrD,CAAC;AAED,MAAM,CAAC,MAAM,uBAAuB,GAAW;IAC7C,IAAI,EAAE,oBAAoB;IAC1B,WAAW,EACT,mJAAmJ;IACrJ,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;IACnC,QAAQ,EAAE,CAAC,aAAa,EAAE,gBAAgB,EAAE,WAAW,CAAC;IACxD,KAAK,EAAE;QACL,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,oCAAoC,EAAE,QAAQ,EAAE,IAAI,EAAE;QACzG,EAAE,IAAI,EAAE,UAAU,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,sCAAsC,EAAE,QAAQ,EAAE,IAAI,EAAE;QACzG,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,QAAQ,EAAE,WAAW,EAAE,8BAA8B,EAAE;KAChF;IACD,OAAO,EAAE,WAAW;IACpB,SAAS,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAA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AC,UAAU,EAAE,CAAC;QACrF,MAAM,EAAE,GAAG,CAAC,EAAE,iBAAiB,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9D,MAAM,GAAG,GAAG,CAAC,EAAE,WAAW,CAAC,CAAC,CAAC,UAAU,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QAC5D,OAAO,QAAQ,IAAI,MAAM,EAAE,GAAG,GAAG,2BAA2B,CAAC;IAC/D,CAAC;IACD,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACf,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,KAAgC,CAAC;QACvD,MAAM,IAAI,GAAG,CAAC,EAAE,mBAAmB,IAAI,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,CAAC;QACrF,MAAM,EAAE,GAAG,CAAC,EAAE,iBAAiB,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;QAC9D,OAAO,mBAAmB,IAAI,MAAM,EAAE,8CAA8C,CAAC;IACvF,CAAC;CACF,CAAC"}
@@ -0,0 +1,35 @@
1
+ /**
2
+ * Built-in "buy inbound channel capacity from the LSP" recipe (LSPS1).
3
+ *
4
+ * "buy a 500k inbound channel"
5
+ * "I need 200000 sats of inbound liquidity"
6
+ * "open a channel from the LSP, 1M inbound for 30 days"
7
+ * ↓ heuristic pre-filter (0 inf) decides to enter the recipe branch
8
+ * ↓ 1 model inference (forced LLM slot extraction)
9
+ * lsp_get_info ← LSP options + assets (read-only)
10
+ * lsp_estimate_fees ← LSP fee preview (read-only)
11
+ * rln_get_node_info ← NODE client_pubkey (read-only)
12
+ * ↓ [ONE confirmation gate — shows estimated total fee + channel terms]
13
+ * lsp_create_order ← LSP creates the order → bolt11 invoice
14
+ * rln_pay_invoice ← NODE pays the LSP invoice → channel opens
15
+ *
16
+ * Mirrors the single-confirm pattern from kaleidoswapAtomicRecipe: the user
17
+ * decides ONCE on the fee, then create_order + pay_invoice run as one
18
+ * approved unit. The channel's actual opening is asynchronous — the recipe
19
+ * reports "order placed and paid, channel opening" and leaves polling to a
20
+ * follow-up turn (lsp_get_order) so the chat isn't blocked.
21
+ *
22
+ * forceModelExtract: a small model can't reliably regex out a fuzzy phrasing
23
+ * like "I want a channel from the LSP, 500k inbound for a month, no push" —
24
+ * so the recipe still owns the chain + the single confirm, but lets the LLM
25
+ * do the natural-language understanding for slot extraction.
26
+ */
27
+ import type { Recipe } from './types.js';
28
+ /**
29
+ * Deterministic extractor — fast pre-filter for the Funnel to decide whether
30
+ * to enter the recipe branch. The model still runs (forceModelExtract) for
31
+ * the slots actually used in execution.
32
+ */
33
+ export declare function extractChannelOrder(text: string): Record<string, unknown> | null;
34
+ export declare const kaleidoswapChannelOrderRecipe: Recipe;
35
+ //# sourceMappingURL=kaleidoswap-channel-order.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"kaleidoswap-channel-order.d.ts","sourceRoot":"","sources":["../../src/recipe/kaleidoswap-channel-order.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAuCxD;;;;GAIG;AACH,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAgKhF;AAwED,eAAO,MAAM,6BAA6B,EAAE,MAoP3C,CAAC"}