@kaleidorg/mind 0.4.0 → 0.5.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/dist/funnel.d.ts +19 -0
- package/dist/funnel.d.ts.map +1 -1
- package/dist/funnel.js +48 -10
- package/dist/funnel.js.map +1 -1
- package/dist/index.d.ts +5 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -3
- package/dist/index.js.map +1 -1
- package/dist/kaleidoswap/contract.d.ts +3 -3
- package/dist/kaleidoswap/contract.d.ts.map +1 -1
- package/dist/kaleidoswap/contract.js +16 -4
- package/dist/kaleidoswap/contract.js.map +1 -1
- package/dist/knowledge/bitcoin-copilot.d.ts.map +1 -1
- package/dist/knowledge/bitcoin-copilot.js +102 -0
- package/dist/knowledge/bitcoin-copilot.js.map +1 -1
- package/dist/knowledge/btc-map.d.ts +14 -17
- package/dist/knowledge/btc-map.d.ts.map +1 -1
- package/dist/knowledge/btc-map.js +66 -266
- package/dist/knowledge/btc-map.js.map +1 -1
- package/dist/lsps1/contract.d.ts.map +1 -1
- package/dist/lsps1/contract.js +28 -10
- package/dist/lsps1/contract.js.map +1 -1
- package/dist/qvac/parse.d.ts +15 -0
- package/dist/qvac/parse.d.ts.map +1 -1
- package/dist/qvac/parse.js +68 -5
- package/dist/qvac/parse.js.map +1 -1
- package/dist/qvac/text.d.ts.map +1 -1
- package/dist/qvac/text.js +4 -0
- package/dist/qvac/text.js.map +1 -1
- package/dist/recipe/buy-asset-channel.d.ts +26 -0
- package/dist/recipe/buy-asset-channel.d.ts.map +1 -0
- package/dist/recipe/buy-asset-channel.js +112 -0
- package/dist/recipe/buy-asset-channel.js.map +1 -0
- package/dist/recipe/kaleidoswap-atomic.d.ts +26 -18
- package/dist/recipe/kaleidoswap-atomic.d.ts.map +1 -1
- package/dist/recipe/kaleidoswap-atomic.js +101 -63
- package/dist/recipe/kaleidoswap-atomic.js.map +1 -1
- package/dist/recipe/kaleidoswap-channel-order.d.ts +35 -0
- package/dist/recipe/kaleidoswap-channel-order.d.ts.map +1 -0
- package/dist/recipe/kaleidoswap-channel-order.js +493 -0
- package/dist/recipe/kaleidoswap-channel-order.js.map +1 -0
- package/dist/recipe/kaleidoswap-price.d.ts +21 -0
- package/dist/recipe/kaleidoswap-price.d.ts.map +1 -0
- package/dist/recipe/kaleidoswap-price.js +57 -0
- package/dist/recipe/kaleidoswap-price.js.map +1 -0
- package/dist/recipe/runner.d.ts +7 -1
- package/dist/recipe/runner.d.ts.map +1 -1
- package/dist/recipe/runner.js +115 -29
- package/dist/recipe/runner.js.map +1 -1
- package/dist/recipe/swap.d.ts +26 -1
- package/dist/recipe/swap.d.ts.map +1 -1
- package/dist/recipe/swap.js +108 -13
- package/dist/recipe/swap.js.map +1 -1
- package/dist/recipe/types.d.ts +25 -1
- package/dist/recipe/types.d.ts.map +1 -1
- package/dist/skills/registry.d.ts +33 -1
- package/dist/skills/registry.d.ts.map +1 -1
- package/dist/skills/registry.js +45 -1
- package/dist/skills/registry.js.map +1 -1
- package/package.json +1 -1
- package/skills/README.md +3 -0
- package/skills/kaleido-lsps/SKILL.md +101 -43
- package/skills/kaleido-trading/SKILL.md +81 -31
- package/skills/merchant-finder/SKILL.md +96 -66
- package/skills/rgb-lightning-node/SKILL.md +108 -0
- package/skills/wallet-assistant/SKILL.md +32 -21
- package/src/funnel.ts +66 -11
- package/src/index.ts +14 -2
- package/src/kaleidoswap/contract.test.ts +7 -2
- package/src/kaleidoswap/contract.ts +27 -5
- package/src/knowledge/bitcoin-copilot.ts +111 -0
- package/src/knowledge/btc-map.test.ts +53 -96
- package/src/knowledge/btc-map.ts +72 -287
- package/src/lsps1/contract.ts +32 -14
- package/src/qvac/parse.test.ts +70 -1
- package/src/qvac/parse.ts +71 -5
- package/src/qvac/text.ts +4 -0
- package/src/recipe/buy-asset-channel.test.ts +148 -0
- package/src/recipe/buy-asset-channel.ts +118 -0
- package/src/recipe/kaleidoswap-atomic.test.ts +134 -61
- package/src/recipe/kaleidoswap-atomic.ts +112 -66
- package/src/recipe/kaleidoswap-channel-order.test.ts +333 -0
- package/src/recipe/kaleidoswap-channel-order.ts +548 -0
- package/src/recipe/kaleidoswap-price.ts +68 -0
- package/src/recipe/recipe.test.ts +61 -5
- package/src/recipe/runner.ts +128 -31
- package/src/recipe/swap.ts +109 -13
- package/src/recipe/types.ts +25 -1
- package/src/skills/registry.ts +52 -1
package/dist/qvac/parse.js
CHANGED
|
@@ -5,22 +5,85 @@
|
|
|
5
5
|
* desktop, and the eval harness.
|
|
6
6
|
*/
|
|
7
7
|
import { cleanAssistantVisibleText } from './text.js';
|
|
8
|
+
/** Parse the first balanced `{…}` from a string as a `{name, arguments}` call. */
|
|
9
|
+
function parseCallObject(s) {
|
|
10
|
+
const start = s.indexOf('{');
|
|
11
|
+
if (start < 0)
|
|
12
|
+
return null;
|
|
13
|
+
let depth = 0;
|
|
14
|
+
for (let i = start; i < s.length; i++) {
|
|
15
|
+
const ch = s[i];
|
|
16
|
+
if (ch === '{')
|
|
17
|
+
depth++;
|
|
18
|
+
else if (ch === '}' && --depth === 0) {
|
|
19
|
+
try {
|
|
20
|
+
const obj = JSON.parse(s.slice(start, i + 1));
|
|
21
|
+
if (obj && typeof obj.name === 'string') {
|
|
22
|
+
const args = obj.arguments && typeof obj.arguments === 'object'
|
|
23
|
+
? obj.arguments
|
|
24
|
+
: {};
|
|
25
|
+
return { name: obj.name, arguments: args };
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
catch {
|
|
29
|
+
/* malformed JSON — give up on this fragment */
|
|
30
|
+
}
|
|
31
|
+
return null;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Recover tool calls a model emitted as PLAIN TEXT instead of structured frames
|
|
38
|
+
* — `<tool_call>{"name":…,"arguments":…}</tool_call>` (Qwen/Hermes) or a bare
|
|
39
|
+
* leading `{"name":…,"arguments":…}`. Small local models (and SDK builds that
|
|
40
|
+
* don't apply the tool grammar) do this; without recovery the call leaks into
|
|
41
|
+
* the visible answer and never runs.
|
|
42
|
+
*/
|
|
43
|
+
export function extractTextToolCalls(text) {
|
|
44
|
+
const calls = [];
|
|
45
|
+
for (const m of text.matchAll(/<tool_call\b[^>]*>([\s\S]*?)<\/tool_call>/gi)) {
|
|
46
|
+
const c = parseCallObject(m[1] ?? '');
|
|
47
|
+
if (c)
|
|
48
|
+
calls.push(c);
|
|
49
|
+
}
|
|
50
|
+
if (calls.length)
|
|
51
|
+
return calls;
|
|
52
|
+
// No tags — accept a bare tool-call object only at the very start of the
|
|
53
|
+
// text (so we don't misread JSON the model is merely talking about).
|
|
54
|
+
if (/^\s*\{?\s*"name"\s*:/i.test(text)) {
|
|
55
|
+
const c = parseCallObject(text);
|
|
56
|
+
if (c)
|
|
57
|
+
calls.push(c);
|
|
58
|
+
}
|
|
59
|
+
return calls;
|
|
60
|
+
}
|
|
8
61
|
/**
|
|
9
62
|
* Map a completion `final` (plus the streamed fallback text) into a ParsedTurn.
|
|
10
63
|
* `rawContent` prefers the SDK's framed `raw.fullText` so the Engine can anchor
|
|
11
64
|
* the next turn; falls back to the visible text when a provider has no raw form.
|
|
65
|
+
*
|
|
66
|
+
* When the SDK reports no structured tool calls, we re-scan the raw text for
|
|
67
|
+
* tool calls the model emitted inline (see `extractTextToolCalls`) so they still
|
|
68
|
+
* execute instead of leaking into the chat.
|
|
12
69
|
*/
|
|
13
70
|
export function finalToTurn(final, streamed = '') {
|
|
14
71
|
const rawText = final.contentText || streamed;
|
|
15
72
|
const text = cleanAssistantVisibleText(rawText);
|
|
73
|
+
let toolCalls = (final.toolCalls ?? []).map((c) => ({
|
|
74
|
+
id: c.id,
|
|
75
|
+
name: c.name,
|
|
76
|
+
arguments: c.arguments ?? {},
|
|
77
|
+
}));
|
|
78
|
+
if (toolCalls.length === 0) {
|
|
79
|
+
const recovered = extractTextToolCalls(final.raw?.fullText ?? rawText);
|
|
80
|
+
if (recovered.length)
|
|
81
|
+
toolCalls = recovered.map((c) => ({ id: undefined, ...c }));
|
|
82
|
+
}
|
|
16
83
|
return {
|
|
17
84
|
text,
|
|
18
85
|
rawContent: final.raw?.fullText ?? rawText,
|
|
19
|
-
toolCalls
|
|
20
|
-
id: c.id,
|
|
21
|
-
name: c.name,
|
|
22
|
-
arguments: c.arguments ?? {},
|
|
23
|
-
})),
|
|
86
|
+
toolCalls,
|
|
24
87
|
truncated: final.stopReason === 'length',
|
|
25
88
|
stopReason: final.stopReason,
|
|
26
89
|
};
|
package/dist/qvac/parse.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/qvac/parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AA+BtD
|
|
1
|
+
{"version":3,"file":"parse.js","sourceRoot":"","sources":["../../src/qvac/parse.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,yBAAyB,EAAE,MAAM,WAAW,CAAC;AA+BtD,kFAAkF;AAClF,SAAS,eAAe,CACtB,CAAS;IAET,MAAM,KAAK,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC7B,IAAI,KAAK,GAAG,CAAC;QAAE,OAAO,IAAI,CAAC;IAC3B,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,IAAI,CAAC,GAAG,KAAK,EAAE,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;QACtC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;QAChB,IAAI,EAAE,KAAK,GAAG;YAAE,KAAK,EAAE,CAAC;aACnB,IAAI,EAAE,KAAK,GAAG,IAAI,EAAE,KAAK,KAAK,CAAC,EAAE,CAAC;YACrC,IAAI,CAAC;gBACH,MAAM,GAAG,GAAG,IAAI,CAA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ourceRoot":"","sources":["../../src/qvac/text.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAsB9D;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAsB1D"}
|
package/dist/qvac/text.js
CHANGED
|
@@ -14,6 +14,10 @@ export function cleanAssistantVisibleText(text) {
|
|
|
14
14
|
// Qwen-style reasoning sometimes arrives in contentText. Never show/speak it.
|
|
15
15
|
.replace(/<think\b[\s\S]*?<\/think>/gi, ' ')
|
|
16
16
|
.replace(/<think\b[\s\S]*$/gi, ' ')
|
|
17
|
+
// Tool calls some models emit as text (<tool_call>{…}</tool_call>) are
|
|
18
|
+
// extracted + executed by the Engine (see parse.ts); never show the tags.
|
|
19
|
+
.replace(/<tool_call\b[^>]*>[\s\S]*?<\/tool_call>/gi, ' ')
|
|
20
|
+
.replace(/<tool_call\b[^>]*>[\s\S]*$/gi, ' ')
|
|
17
21
|
.replace(/\s+/g, ' ')
|
|
18
22
|
.trim();
|
|
19
23
|
// Some small local models emit a tool-call object as plain text. Drop the
|
package/dist/qvac/text.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/qvac/text.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,IAAI,OAAO,GAAG,IAAI;QAChB,8EAA8E;SAC7E,OAAO,CAAC,6BAA6B,EAAE,GAAG,CAAC;SAC3C,OAAO,CAAC,oBAAoB,EAAE,GAAG,CAAC;
|
|
1
|
+
{"version":3,"file":"text.js","sourceRoot":"","sources":["../../src/qvac/text.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;GAKG;AACH,MAAM,UAAU,yBAAyB,CAAC,IAAY;IACpD,IAAI,OAA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KAAK,CAAC,IAAI,CAAC,UAAU,CAAC;SAC1B,MAAM,CAAC,CAAC,EAAE,EAAE,EAAE;QACb,MAAM,IAAI,GAAG,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QAC9B,OAAO,CAAC,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,IAAI,KAAK,IAAI,IAAI,CAAC,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,IAAI,CAAC,CAAC;YACxF,IAAI,KAAK,IAAI,CAAC;IAClB,CAAC,CAAC;SACD,IAAI,CAAC,EAAE,CAAC;SACR,OAAO,CAAC,MAAM,EAAE,GAAG,CAAC;SACpB,IAAI,EAAE,CAAC;AACZ,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
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
|
+
import type { Recipe } from './types.js';
|
|
23
|
+
/** "buy 100 usdt" / "get me 50 xaut" / "i want 200 usdt" / "purchase 10 xaut". */
|
|
24
|
+
export declare function extractBuyAsset(text: string): Record<string, unknown> | null;
|
|
25
|
+
export declare const buyAssetChannelRecipe: Recipe;
|
|
26
|
+
//# sourceMappingURL=buy-asset-channel.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"buy-asset-channel.d.ts","sourceRoot":"","sources":["../../src/recipe/buy-asset-channel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA4BzC,kFAAkF;AAClF,wBAAgB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAW5E;AAED,eAAO,MAAM,qBAAqB,EAAE,MAqDnC,CAAC"}
|
|
@@ -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","sour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C,QAAQ,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC;QACxF,MAAM,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 "
|
|
2
|
+
* Built-in "swap on KaleidoSwap" recipe — the real atomic-swap chain.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
-
*
|
|
23
|
-
*
|
|
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
|
|
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 "
|
|
2
|
+
* Built-in "swap on KaleidoSwap" recipe — the real atomic-swap chain.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
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
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
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
|
-
*
|
|
14
|
-
*
|
|
15
|
-
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
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
|
-
*
|
|
23
|
-
*
|
|
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
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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: '
|
|
33
|
-
match: (t) =>
|
|
34
|
-
triggers: ['
|
|
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: '
|
|
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.
|
|
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
|
-
//
|
|
54
|
-
|
|
55
|
-
|
|
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: '
|
|
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
|
-
|
|
83
|
-
|
|
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
|
-
//
|
|
104
|
+
// 3. NODE: read our pubkey — the maker needs it as taker_pubkey for execute.
|
|
88
105
|
{
|
|
89
|
-
tool: '
|
|
90
|
-
as: '
|
|
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
|
|
93
|
-
return {
|
|
116
|
+
const init = ctx.results.init;
|
|
117
|
+
return { swapstring: init?.swapstring };
|
|
94
118
|
},
|
|
95
119
|
},
|
|
96
120
|
],
|
|
97
|
-
// 5.
|
|
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
|
|
102
|
-
|
|
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
|
|
108
|
-
|
|
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
|
|
1
|
+
{"version":3,"file":"kaleidoswap-atomic.js","sourceRoot":"","sources":["../../src/recipe/kaleidoswap-atomic.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AAGH,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAExC,gFAAgF;AAChF,8EAA8E;AAC9E,yEAAyE;AACzE,kEAAkE;AAClE,MAAM,KAAK,GAAG,gDAAgD,CAAC;AAC/D,MAAM,WAAW,GAAG,CAAC,CAAS,EAAE,EAAE;IAChC,4EAA4E;IAC5E,qCAAqC;IACrC,IAAI,6EAA6E,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IACxG,IAAI,oCA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C,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"}
|