@kaleidorg/mind 0.1.0 → 0.2.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.
- package/dist/capabilities.d.ts +34 -0
- package/dist/capabilities.d.ts.map +1 -0
- package/dist/capabilities.js +34 -0
- package/dist/capabilities.js.map +1 -0
- package/dist/context/budget.d.ts +29 -0
- package/dist/context/budget.d.ts.map +1 -0
- package/dist/context/budget.js +36 -0
- package/dist/context/budget.js.map +1 -0
- package/dist/context/builder.d.ts +39 -0
- package/dist/context/builder.d.ts.map +1 -0
- package/dist/context/builder.js +77 -0
- package/dist/context/builder.js.map +1 -0
- package/dist/fastpath/fastpath.d.ts +38 -0
- package/dist/fastpath/fastpath.d.ts.map +1 -0
- package/dist/fastpath/fastpath.js +52 -0
- package/dist/fastpath/fastpath.js.map +1 -0
- package/dist/funnel.d.ts +111 -0
- package/dist/funnel.d.ts.map +1 -0
- package/dist/funnel.js +175 -0
- package/dist/funnel.js.map +1 -0
- package/dist/index.d.ts +36 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge/bitcoin-copilot.d.ts +11 -0
- package/dist/knowledge/bitcoin-copilot.d.ts.map +1 -0
- package/dist/knowledge/bitcoin-copilot.js +155 -0
- package/dist/knowledge/bitcoin-copilot.js.map +1 -0
- package/dist/knowledge/merchants.d.ts +24 -0
- package/dist/knowledge/merchants.d.ts.map +1 -0
- package/dist/knowledge/merchants.js +34 -0
- package/dist/knowledge/merchants.js.map +1 -0
- package/dist/knowledge/wallet.d.ts +34 -0
- package/dist/knowledge/wallet.d.ts.map +1 -0
- package/dist/knowledge/wallet.js +63 -0
- package/dist/knowledge/wallet.js.map +1 -0
- package/dist/memory/store.d.ts +34 -0
- package/dist/memory/store.d.ts.map +1 -0
- package/dist/memory/store.js +103 -0
- package/dist/memory/store.js.map +1 -0
- package/dist/memory/tool.d.ts +9 -0
- package/dist/memory/tool.d.ts.map +1 -0
- package/dist/memory/tool.js +70 -0
- package/dist/memory/tool.js.map +1 -0
- package/dist/memory/types.d.ts +56 -0
- package/dist/memory/types.d.ts.map +1 -0
- package/dist/memory/types.js +14 -0
- package/dist/memory/types.js.map +1 -0
- package/dist/rag/retriever.d.ts +30 -0
- package/dist/rag/retriever.d.ts.map +1 -0
- package/dist/rag/retriever.js +72 -0
- package/dist/rag/retriever.js.map +1 -0
- package/dist/rag/tool.d.ts +15 -0
- package/dist/rag/tool.d.ts.map +1 -0
- package/dist/rag/tool.js +42 -0
- package/dist/rag/tool.js.map +1 -0
- package/dist/rag/types.d.ts +44 -0
- package/dist/rag/types.d.ts.map +1 -0
- package/dist/rag/types.js +11 -0
- package/dist/rag/types.js.map +1 -0
- package/dist/rag/vector-store.d.ts +23 -0
- package/dist/rag/vector-store.d.ts.map +1 -0
- package/dist/rag/vector-store.js +72 -0
- package/dist/rag/vector-store.js.map +1 -0
- package/dist/recipe/asset-send.d.ts +15 -0
- package/dist/recipe/asset-send.d.ts.map +1 -0
- package/dist/recipe/asset-send.js +83 -0
- package/dist/recipe/asset-send.js.map +1 -0
- package/dist/recipe/payments.d.ts +15 -0
- package/dist/recipe/payments.d.ts.map +1 -0
- package/dist/recipe/payments.js +119 -0
- package/dist/recipe/payments.js.map +1 -0
- package/dist/recipe/receive.d.ts +14 -0
- package/dist/recipe/receive.d.ts.map +1 -0
- package/dist/recipe/receive.js +109 -0
- package/dist/recipe/receive.js.map +1 -0
- package/dist/recipe/runner.d.ts +42 -0
- package/dist/recipe/runner.d.ts.map +1 -0
- package/dist/recipe/runner.js +94 -0
- package/dist/recipe/runner.js.map +1 -0
- package/dist/recipe/swap.d.ts +16 -0
- package/dist/recipe/swap.d.ts.map +1 -0
- package/dist/recipe/swap.js +73 -0
- package/dist/recipe/swap.js.map +1 -0
- package/dist/recipe/types.d.ts +71 -0
- package/dist/recipe/types.d.ts.map +1 -0
- package/dist/recipe/types.js +13 -0
- package/dist/recipe/types.js.map +1 -0
- package/dist/tools/cli.d.ts +43 -0
- package/dist/tools/cli.d.ts.map +1 -0
- package/dist/tools/cli.js +61 -0
- package/dist/tools/cli.js.map +1 -0
- package/dist/tools/mcp.d.ts +3 -2
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mcp.js +3 -2
- package/dist/tools/mcp.js.map +1 -1
- package/dist/wallet/contract.d.ts +57 -0
- package/dist/wallet/contract.d.ts.map +1 -0
- package/dist/wallet/contract.js +113 -0
- package/dist/wallet/contract.js.map +1 -0
- package/package.json +9 -5
- package/src/capabilities.ts +67 -0
- package/src/context/budget.ts +46 -0
- package/src/context/builder.ts +100 -0
- package/src/context/context.test.ts +83 -0
- package/src/fastpath/fastpath.test.ts +34 -0
- package/src/fastpath/fastpath.ts +70 -0
- package/src/funnel.test.ts +207 -0
- package/src/funnel.ts +260 -0
- package/src/index.ts +85 -0
- package/src/knowledge/bitcoin-copilot.ts +177 -0
- package/src/knowledge/knowledge.test.ts +63 -0
- package/src/knowledge/merchants.ts +49 -0
- package/src/knowledge/wallet.ts +84 -0
- package/src/memory/memory.test.ts +85 -0
- package/src/memory/store.ts +129 -0
- package/src/memory/tool.ts +76 -0
- package/src/memory/types.ts +63 -0
- package/src/rag/rag.test.ts +85 -0
- package/src/rag/retriever.ts +94 -0
- package/src/rag/tool.ts +55 -0
- package/src/rag/types.ts +49 -0
- package/src/rag/vector-store.ts +78 -0
- package/src/recipe/asset-send.ts +79 -0
- package/src/recipe/payments.ts +116 -0
- package/src/recipe/receive.ts +98 -0
- package/src/recipe/recipe.test.ts +193 -0
- package/src/recipe/runner.ts +122 -0
- package/src/recipe/swap.ts +74 -0
- package/src/recipe/types.ts +76 -0
- package/src/tools/cli.test.ts +53 -0
- package/src/tools/cli.ts +98 -0
- package/src/tools/mcp.ts +3 -2
- package/src/wallet/contract.test.ts +89 -0
- package/src/wallet/contract.ts +157 -0
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipe runner — executes a Recipe with ONE structured extraction (or a
|
|
3
|
+
* deterministic regex), then runs the deterministic step chain and the
|
|
4
|
+
* confirmation-gated final action. This is mobile multi-step: a tiny model
|
|
5
|
+
* fills slots; the engine does the planning.
|
|
6
|
+
*/
|
|
7
|
+
const EXTRACT_TOOL = 'extract_request';
|
|
8
|
+
/** Extract the recipe's slots — deterministic regex first, else ONE LLM call. */
|
|
9
|
+
export async function extractSlots(provider, recipe, text) {
|
|
10
|
+
const det = recipe.extract?.(text);
|
|
11
|
+
if (det && Object.values(det).some((v) => v !== undefined && v !== null && v !== '')) {
|
|
12
|
+
return { slots: det, inferences: 0 };
|
|
13
|
+
}
|
|
14
|
+
const properties = {};
|
|
15
|
+
for (const s of recipe.slots)
|
|
16
|
+
properties[s.name] = { type: s.type ?? 'string', description: s.description };
|
|
17
|
+
const extractTool = {
|
|
18
|
+
name: EXTRACT_TOOL,
|
|
19
|
+
description: `Extract the fields from the user's request.`,
|
|
20
|
+
parameters: { type: 'object', properties, required: recipe.slots.filter((s) => s.required).map((s) => s.name) },
|
|
21
|
+
};
|
|
22
|
+
const out = await provider.runTurn({
|
|
23
|
+
system: `Call ${EXTRACT_TOOL} with the fields from the user's message. Do not call any other tool and do not add commentary.`,
|
|
24
|
+
messages: [{ role: 'user', content: text }],
|
|
25
|
+
tools: [extractTool],
|
|
26
|
+
});
|
|
27
|
+
const call = out.toolCalls?.find((c) => c.name === EXTRACT_TOOL) ?? out.toolCalls?.[0];
|
|
28
|
+
return { slots: call?.arguments ?? {}, inferences: 1 };
|
|
29
|
+
}
|
|
30
|
+
/** Run a recipe end to end. Never throws — failures come back as status:'error'. */
|
|
31
|
+
export async function runRecipe(recipe, text, opts) {
|
|
32
|
+
const ctx = { text, slots: opts.slots ?? {}, results: {} };
|
|
33
|
+
let inferences = 0;
|
|
34
|
+
try {
|
|
35
|
+
if (!opts.slots) {
|
|
36
|
+
const ex = await extractSlots(opts.provider, recipe, text);
|
|
37
|
+
ctx.slots = ex.slots;
|
|
38
|
+
inferences = ex.inferences;
|
|
39
|
+
}
|
|
40
|
+
// Deterministic steps.
|
|
41
|
+
for (const step of recipe.steps) {
|
|
42
|
+
if (step.skipIf?.(ctx))
|
|
43
|
+
continue;
|
|
44
|
+
const args = step.args(ctx);
|
|
45
|
+
const result = await opts.tools.execute(step.tool, args);
|
|
46
|
+
ctx.results[step.as ?? step.tool] = result;
|
|
47
|
+
opts.onStep?.(step.tool, args, result);
|
|
48
|
+
}
|
|
49
|
+
// Final action — confirmation-gated if the tool requires it. Like the
|
|
50
|
+
// Engine, a missing onConfirm FAILS CLOSED: the spend is declined, never
|
|
51
|
+
// silently executed.
|
|
52
|
+
const finalArgs = recipe.final.args(ctx);
|
|
53
|
+
const def = await opts.tools.getDef(recipe.final.tool);
|
|
54
|
+
if (def?.requiresConfirmation) {
|
|
55
|
+
const decision = opts.onConfirm
|
|
56
|
+
? await opts.onConfirm({ name: recipe.final.tool, arguments: finalArgs })
|
|
57
|
+
: { approved: false, reason: 'no confirmation handler available' };
|
|
58
|
+
if (!decision.approved) {
|
|
59
|
+
return { recipe: recipe.name, slots: ctx.slots, results: ctx.results, text: 'Cancelled — nothing was sent.', status: 'cancelled', inferences };
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
const finalResult = await opts.tools.execute(recipe.final.tool, finalArgs);
|
|
63
|
+
ctx.results[recipe.final.as ?? recipe.final.tool] = finalResult;
|
|
64
|
+
opts.onStep?.(recipe.final.tool, finalArgs, finalResult);
|
|
65
|
+
const out = recipe.summary?.(ctx, finalResult) ?? 'Done.';
|
|
66
|
+
return { recipe: recipe.name, slots: ctx.slots, results: ctx.results, final: finalResult, text: out, status: 'done', inferences };
|
|
67
|
+
}
|
|
68
|
+
catch (e) {
|
|
69
|
+
const msg = e?.message ?? String(e);
|
|
70
|
+
return { recipe: recipe.name, slots: ctx.slots, results: ctx.results, text: `Couldn't complete that: ${msg}`, status: 'error', error: msg, inferences };
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** Selects a recipe for a request. Use before falling back to the free agentic loop. */
|
|
74
|
+
export class RecipeRegistry {
|
|
75
|
+
recipes;
|
|
76
|
+
constructor(recipes = []) {
|
|
77
|
+
this.recipes = [...recipes];
|
|
78
|
+
}
|
|
79
|
+
add(recipe) {
|
|
80
|
+
this.recipes.push(recipe);
|
|
81
|
+
}
|
|
82
|
+
list() {
|
|
83
|
+
return [...this.recipes];
|
|
84
|
+
}
|
|
85
|
+
get(name) {
|
|
86
|
+
return this.recipes.find((r) => r.name === name);
|
|
87
|
+
}
|
|
88
|
+
/** First recipe whose match()/triggers fit the text, else null. */
|
|
89
|
+
select(text) {
|
|
90
|
+
const lc = text.toLowerCase();
|
|
91
|
+
return (this.recipes.find((r) => r.match ? r.match(text) : (r.triggers ?? []).some((t) => lc.includes(t.toLowerCase()))) ?? null);
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
//# sourceMappingURL=runner.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.js","sourceRoot":"","sources":["../../src/recipe/runner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAOH,MAAM,YAAY,GAAG,iBAAiB,CAAC;AAcvC,iFAAiF;AACjF,MAAM,CAAC,KAAK,UAAU,YAAY,CAChC,QAAqB,EACrB,MAAc,EACd,IAAY;IAEZ,MAAM,GAAG,GAAG,MAAM,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,CAAC;IACnC,IAAI,GAAG,IAAI,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,IAAI,CAAC,KAAK,EAAE,CAAC,EAAE,CAAC;QACrF,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,UAAU,EAAE,CAAC,EAAE,CAAC;IACvC,CAAC;IACD,MAAM,UAAU,GAA0D,EAAE,CAAC;IAC7E,KAAK,M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ipe — quote → (confirm) → execute, over the contract tools.
|
|
3
|
+
*
|
|
4
|
+
* "buy 0.001 btc with usdt" → from USDT, to BTC
|
|
5
|
+
* "swap 10 usdt for btc" → from USDT, to BTC
|
|
6
|
+
* "sell 100 usdt for sats" → from USDT, to BTC
|
|
7
|
+
*
|
|
8
|
+
* The deterministic extractor handles the common phrasings; the runner falls
|
|
9
|
+
* back to one LLM extraction otherwise. execute_swap is a spend → the engine's
|
|
10
|
+
* confirmation gate fires before it runs.
|
|
11
|
+
*/
|
|
12
|
+
import type { Recipe } from './types.js';
|
|
13
|
+
/** "buy 0.001 btc with usdt" / "swap 10 usdt for btc" / "sell 100 usdt for sats". */
|
|
14
|
+
export declare function extractSwap(text: string): Record<string, unknown> | null;
|
|
15
|
+
export declare const swapRecipe: Recipe;
|
|
16
|
+
//# sourceMappingURL=swap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.d.ts","sourceRoot":"","sources":["../../src/recipe/swap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAczC,qFAAqF;AACrF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAYxE;AAED,eAAO,MAAM,UAAU,EAAE,MAgCxB,CAAC"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in "swap" recipe — quote → (confirm) → execute, over the contract tools.
|
|
3
|
+
*
|
|
4
|
+
* "buy 0.001 btc with usdt" → from USDT, to BTC
|
|
5
|
+
* "swap 10 usdt for btc" → from USDT, to BTC
|
|
6
|
+
* "sell 100 usdt for sats" → from USDT, to BTC
|
|
7
|
+
*
|
|
8
|
+
* The deterministic extractor handles the common phrasings; the runner falls
|
|
9
|
+
* back to one LLM extraction otherwise. execute_swap is a spend → the engine's
|
|
10
|
+
* confirmation gate fires before it runs.
|
|
11
|
+
*/
|
|
12
|
+
const ASSET = /\b(btc|bitcoin|sats?|usdt|tether|xaut|gold)\b/i;
|
|
13
|
+
function normAsset(a) {
|
|
14
|
+
if (!a)
|
|
15
|
+
return undefined;
|
|
16
|
+
const x = a.toLowerCase();
|
|
17
|
+
if (/btc|bitcoin|sat/.test(x))
|
|
18
|
+
return 'BTC';
|
|
19
|
+
if (/usdt|tether/.test(x))
|
|
20
|
+
return 'USDT';
|
|
21
|
+
if (/xaut|gold/.test(x))
|
|
22
|
+
return 'XAUT';
|
|
23
|
+
return a.toUpperCase();
|
|
24
|
+
}
|
|
25
|
+
const num = (s) => (s ? Number(s.replace(/,/g, '')) : undefined);
|
|
26
|
+
/** "buy 0.001 btc with usdt" / "swap 10 usdt for btc" / "sell 100 usdt for sats". */
|
|
27
|
+
export function extractSwap(text) {
|
|
28
|
+
const t = text.trim();
|
|
29
|
+
let m;
|
|
30
|
+
// buy <amt> <to> with/using <from> (amount is of the asset being bought)
|
|
31
|
+
if ((m = t.match(/buy\s+([\d.,]+)\s*([a-z]+)\s+(?:with|using|for)\s+([a-z]+)/i))) {
|
|
32
|
+
return { amount: num(m[1]), to_asset: normAsset(m[2]), from_asset: normAsset(m[3]) };
|
|
33
|
+
}
|
|
34
|
+
// swap/sell/convert/exchange/trade <amt> <from> for/to/into <to>
|
|
35
|
+
if ((m = t.match(/(?:swap|sell|convert|exchange|trade)\s+([\d.,]+)\s*([a-z]+)\s+(?:for|to|into)\s+([a-z]+)/i))) {
|
|
36
|
+
return { amount: num(m[1]), from_asset: normAsset(m[2]), to_asset: normAsset(m[3]) };
|
|
37
|
+
}
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
export const swapRecipe = {
|
|
41
|
+
name: 'swap',
|
|
42
|
+
description: 'Swap between BTC and an RGB asset — quote, then execute (with confirmation).',
|
|
43
|
+
// A crypto swap intent — but NOT buying a gift card (that's commerce) or an invoice.
|
|
44
|
+
match: (t) => /\b(swap|exchange|convert|trade)\b/i.test(t) || (/\b(buy|sell)\b/i.test(t) && ASSET.test(t) && !/\b(gift\s?card|top-?up|esim|voucher|invoice|address)\b/i.test(t)),
|
|
45
|
+
triggers: ['swap', 'exchange', 'convert', 'trade'],
|
|
46
|
+
slots: [
|
|
47
|
+
{ name: 'from_asset', type: 'string', description: 'Asset to spend (e.g. USDT, BTC)', required: true },
|
|
48
|
+
{ name: 'to_asset', type: 'string', description: 'Asset to receive (e.g. BTC, USDT)', required: true },
|
|
49
|
+
{ name: 'amount', type: 'number', description: 'Amount to swap' },
|
|
50
|
+
],
|
|
51
|
+
extract: extractSwap,
|
|
52
|
+
confident: (s) => !!s.from_asset && !!s.to_asset,
|
|
53
|
+
steps: [
|
|
54
|
+
{
|
|
55
|
+
tool: 'get_swap_quote',
|
|
56
|
+
as: 'quote',
|
|
57
|
+
args: (ctx) => ({ from_asset: ctx.slots.from_asset, to_asset: ctx.slots.to_asset, amount: ctx.slots.amount }),
|
|
58
|
+
},
|
|
59
|
+
],
|
|
60
|
+
final: {
|
|
61
|
+
tool: 'execute_swap',
|
|
62
|
+
args: (ctx) => {
|
|
63
|
+
const q = ctx.results.quote;
|
|
64
|
+
return { quote_id: q?.quote_id, from_asset: ctx.slots.from_asset, to_asset: ctx.slots.to_asset, amount: ctx.slots.amount };
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
summary: (ctx) => {
|
|
68
|
+
const q = ctx.results.quote;
|
|
69
|
+
const tail = q?.receive_amount ? ` (~${q.receive_amount} ${ctx.slots.to_asset})` : '';
|
|
70
|
+
return `Swapped ${ctx.slots.amount} ${ctx.slots.from_asset} → ${ctx.slots.to_asset}${tail}.`;
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
//# sourceMappingURL=swap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"swap.js","sourceRoot":"","sources":["../../src/recipe/swap.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;G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AU,EAAE,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;SAC9G;KACF;IACD,KAAK,EAAE;QACL,IAAI,EAAE,cAAc;QACpB,IAAI,EAAE,CAAC,GAAG,EAAE,EAAE;YACZ,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,KAA0C,CAAC;YACjE,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,QAAQ,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC;QAC7H,CAAC;KACF;IACD,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACf,MAAM,CAAC,GAAG,GAAG,CAAC,OAAO,CAAC,KAAgD,CAAC;QACvE,MAAM,IAAI,GAAG,CAAC,EAAE,cAAc,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,cAAc,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC;QACtF,OAAO,WAAW,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,UAAU,MAAM,GAAG,CAAC,KAAK,CAAC,QAAQ,GAAG,IAAI,GAAG,CAAC;IAC/F,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipes — multi-step that works on a tiny model. "Recipes, not planning."
|
|
3
|
+
*
|
|
4
|
+
* A small model can't reliably PLAN a chain ("pay bob 3 EUR" = resolve → price
|
|
5
|
+
* → convert → send) from scratch. So a Recipe carries the plan; the model is
|
|
6
|
+
* used for ONE thing — extracting the request's slots (recipient, amount, …).
|
|
7
|
+
* The engine then runs the deterministic steps and the (confirmation-gated)
|
|
8
|
+
* final action. ~1 inference instead of 5; reliable on 0.6–4B.
|
|
9
|
+
*
|
|
10
|
+
* Pure data + interfaces — no deps. The provider + tools are injected.
|
|
11
|
+
*/
|
|
12
|
+
export interface RecipeSlot {
|
|
13
|
+
name: string;
|
|
14
|
+
type?: 'string' | 'number' | 'boolean';
|
|
15
|
+
description: string;
|
|
16
|
+
required?: boolean;
|
|
17
|
+
}
|
|
18
|
+
export interface RecipeContext {
|
|
19
|
+
/** The original user text. */
|
|
20
|
+
text: string;
|
|
21
|
+
/** Extracted slots (deterministic regex, else one LLM call). */
|
|
22
|
+
slots: Record<string, unknown>;
|
|
23
|
+
/** Results of completed steps, keyed by `as` (or tool name). */
|
|
24
|
+
results: Record<string, unknown>;
|
|
25
|
+
}
|
|
26
|
+
export interface RecipeStep {
|
|
27
|
+
/** Tool to call. */
|
|
28
|
+
tool: string;
|
|
29
|
+
/** Build the tool args from the accumulated context. */
|
|
30
|
+
args: (ctx: RecipeContext) => Record<string, unknown>;
|
|
31
|
+
/** Store the result under this key (default: the tool name). */
|
|
32
|
+
as?: string;
|
|
33
|
+
/** Skip this step when true (e.g. recipient is already an address). */
|
|
34
|
+
skipIf?: (ctx: RecipeContext) => boolean;
|
|
35
|
+
}
|
|
36
|
+
export interface Recipe {
|
|
37
|
+
name: string;
|
|
38
|
+
description?: string;
|
|
39
|
+
/** Selection: a predicate or trigger phrases. */
|
|
40
|
+
match?: (text: string) => boolean;
|
|
41
|
+
triggers?: string[];
|
|
42
|
+
/** Fields the model (or regex) extracts from the request. */
|
|
43
|
+
slots: RecipeSlot[];
|
|
44
|
+
/** Optional deterministic extractor tried BEFORE the LLM (Tier-0 fast-path). */
|
|
45
|
+
extract?: (text: string) => Record<string, unknown> | null;
|
|
46
|
+
/**
|
|
47
|
+
* Whether the recipe is confident enough to RUN deterministically given the
|
|
48
|
+
* extracted slots (vs falling back to the agentic loop). e.g. payments needs a
|
|
49
|
+
* recipient; receive needs an amount or asset. Default: any slot extracted.
|
|
50
|
+
*/
|
|
51
|
+
confident?: (slots: Record<string, unknown>) => boolean;
|
|
52
|
+
/** Deterministic steps, run in order, results threaded into `ctx`. */
|
|
53
|
+
steps: RecipeStep[];
|
|
54
|
+
/** The terminal action (usually a spend → confirmation-gated by its tool). */
|
|
55
|
+
final: RecipeStep;
|
|
56
|
+
/** Render the outcome for the user. */
|
|
57
|
+
summary?: (ctx: RecipeContext, finalResult: unknown) => string;
|
|
58
|
+
}
|
|
59
|
+
export type RecipeStatus = 'done' | 'cancelled' | 'error';
|
|
60
|
+
export interface RecipeResult {
|
|
61
|
+
recipe: string;
|
|
62
|
+
slots: Record<string, unknown>;
|
|
63
|
+
results: Record<string, unknown>;
|
|
64
|
+
final?: unknown;
|
|
65
|
+
text: string;
|
|
66
|
+
status: RecipeStatus;
|
|
67
|
+
error?: string;
|
|
68
|
+
/** Number of LLM inferences used (0 if extraction was deterministic). */
|
|
69
|
+
inferences: number;
|
|
70
|
+
}
|
|
71
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/recipe/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,SAAS,CAAC;IACvC,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB;AAED,MAAM,WAAW,aAAa;IAC5B,8BAA8B;IAC9B,IAAI,EAAE,MAAM,CAAC;IACb,gEAAgE;IAChE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,gEAAgE;IAChE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED,MAAM,WAAW,UAAU;IACzB,oBA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AK,CAAC,EAAE,OAAO,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,YAAY,CAAC;IACrB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,yEAAyE;IACzE,UAAU,EAAE,MAAM,CAAC;CACpB"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Recipes — multi-step that works on a tiny model. "Recipes, not planning."
|
|
3
|
+
*
|
|
4
|
+
* A small model can't reliably PLAN a chain ("pay bob 3 EUR" = resolve → price
|
|
5
|
+
* → convert → send) from scratch. So a Recipe carries the plan; the model is
|
|
6
|
+
* used for ONE thing — extracting the request's slots (recipient, amount, …).
|
|
7
|
+
* The engine then runs the deterministic steps and the (confirmation-gated)
|
|
8
|
+
* final action. ~1 inference instead of 5; reliable on 0.6–4B.
|
|
9
|
+
*
|
|
10
|
+
* Pure data + interfaces — no deps. The provider + tools are injected.
|
|
11
|
+
*/
|
|
12
|
+
export {};
|
|
13
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/recipe/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI tool source — the fourth tool mechanism (alongside in-process function
|
|
3
|
+
* calling, MCP, and skills). Lets the agent run shell commands, e.g. a skill's
|
|
4
|
+
* documented CLI path (`@bitrefill/cli`, `kaleido`, `git`, …).
|
|
5
|
+
*
|
|
6
|
+
* Command execution is INJECTED (`CommandRunner`) so this file has no Node
|
|
7
|
+
* dependency and stays RN-safe — a Node host provides the runner (ideally via a
|
|
8
|
+
* non-shell `execFile`-style helper); React Native simply never provides one.
|
|
9
|
+
* Guarded by a required allowlist of command prefixes, and confirmation-gated
|
|
10
|
+
* by default since it runs real commands.
|
|
11
|
+
*/
|
|
12
|
+
import type { ToolSource } from './source.js';
|
|
13
|
+
export interface CommandResult {
|
|
14
|
+
stdout: string;
|
|
15
|
+
stderr: string;
|
|
16
|
+
code: number;
|
|
17
|
+
}
|
|
18
|
+
/** Injected shell runner. The Node host supplies a safe implementation. */
|
|
19
|
+
export interface CommandRunner {
|
|
20
|
+
run(command: string, opts?: {
|
|
21
|
+
cwd?: string;
|
|
22
|
+
timeoutMs?: number;
|
|
23
|
+
}): Promise<CommandResult>;
|
|
24
|
+
}
|
|
25
|
+
export interface CliToolOptions {
|
|
26
|
+
runner: CommandRunner;
|
|
27
|
+
/**
|
|
28
|
+
* Allowed command prefixes (REQUIRED — no empty allowlist). A command runs
|
|
29
|
+
* only if it starts with one of these tokens, e.g. ['kaleido', 'git status',
|
|
30
|
+
* 'npx @bitrefill/cli'].
|
|
31
|
+
*/
|
|
32
|
+
allow: string[];
|
|
33
|
+
cwd?: string;
|
|
34
|
+
timeoutMs?: number;
|
|
35
|
+
/** Confirmation gate (default true — it executes real commands). */
|
|
36
|
+
requiresConfirmation?: boolean;
|
|
37
|
+
/** Tool description override (e.g. name the specific CLI). */
|
|
38
|
+
description?: string;
|
|
39
|
+
}
|
|
40
|
+
/** True if `command` is permitted by the allowlist (prefix match on tokens). */
|
|
41
|
+
export declare function isAllowed(command: string, allow: string[]): boolean;
|
|
42
|
+
export declare function createCliToolSource(opts: CliToolOptions): ToolSource;
|
|
43
|
+
//# sourceMappingURL=cli.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../../src/tools/cli.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,aAAa;IAC5B,MAAM,EAAE,MAAM,CAAC;IACf,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAED,2EAA2E;AAC3E,MAAM,WAAW,aAAa;IAC5B,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QAAE,GAAG,CAAC,EAAE,MAAM,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,aAAa,CAAC,CAAC;CAC3F;AAED,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,aAAa,CAAC;IACtB;;;;OAIG;IACH,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,oEAAoE;IACpE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,8DAA8D;IAC9D,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAID,gFAAgF;AAChF,wBAAgB,SAAS,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,OAAO,CAMnE;AAED,wBAAgB,mBAAmB,CAAC,IAAI,EAAE,cAAc,GAAG,UAAU,CA4CpE"}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CLI tool source — the fourth tool mechanism (alongside in-process function
|
|
3
|
+
* calling, MCP, and skills). Lets the agent run shell commands, e.g. a skill's
|
|
4
|
+
* documented CLI path (`@bitrefill/cli`, `kaleido`, `git`, …).
|
|
5
|
+
*
|
|
6
|
+
* Command execution is INJECTED (`CommandRunner`) so this file has no Node
|
|
7
|
+
* dependency and stays RN-safe — a Node host provides the runner (ideally via a
|
|
8
|
+
* non-shell `execFile`-style helper); React Native simply never provides one.
|
|
9
|
+
* Guarded by a required allowlist of command prefixes, and confirmation-gated
|
|
10
|
+
* by default since it runs real commands.
|
|
11
|
+
*/
|
|
12
|
+
const RUN = 'run_command';
|
|
13
|
+
/** True if `command` is permitted by the allowlist (prefix match on tokens). */
|
|
14
|
+
export function isAllowed(command, allow) {
|
|
15
|
+
const cmd = command.trim();
|
|
16
|
+
return allow.some((prefix) => {
|
|
17
|
+
const p = prefix.trim();
|
|
18
|
+
return p.length > 0 && (cmd === p || cmd.startsWith(p + ' '));
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
export function createCliToolSource(opts) {
|
|
22
|
+
if (!opts.allow || opts.allow.length === 0) {
|
|
23
|
+
throw new Error('createCliToolSource: a non-empty `allow` allowlist is required');
|
|
24
|
+
}
|
|
25
|
+
const tool = {
|
|
26
|
+
name: RUN,
|
|
27
|
+
description: opts.description ??
|
|
28
|
+
`Run an allowed shell command and return its output. Allowed commands start ` +
|
|
29
|
+
`with: ${opts.allow.join(', ')}. Use for documented CLI tools.`,
|
|
30
|
+
parameters: {
|
|
31
|
+
type: 'object',
|
|
32
|
+
properties: {
|
|
33
|
+
command: { type: 'string', description: 'The full command line to run' },
|
|
34
|
+
},
|
|
35
|
+
required: ['command'],
|
|
36
|
+
},
|
|
37
|
+
requiresConfirmation: opts.requiresConfirmation ?? true,
|
|
38
|
+
};
|
|
39
|
+
async function execute(_name, args) {
|
|
40
|
+
const command = String(args.command ?? '').trim();
|
|
41
|
+
if (!command)
|
|
42
|
+
throw new Error('run_command: command is required');
|
|
43
|
+
if (!isAllowed(command, opts.allow)) {
|
|
44
|
+
throw new Error(`run_command: "${command.split(' ')[0]}" is not allowed. Allowed: ${opts.allow.join(', ')}`);
|
|
45
|
+
}
|
|
46
|
+
const res = await opts.runner.run(command, { cwd: opts.cwd, timeoutMs: opts.timeoutMs });
|
|
47
|
+
const out = (res.stdout || '').trim();
|
|
48
|
+
const err = (res.stderr || '').trim();
|
|
49
|
+
if (res.code !== 0) {
|
|
50
|
+
return `exit ${res.code}${err ? `\n${err}` : ''}${out ? `\n${out}` : ''}`.trim();
|
|
51
|
+
}
|
|
52
|
+
return out || '(no output)';
|
|
53
|
+
}
|
|
54
|
+
return {
|
|
55
|
+
id: 'cli',
|
|
56
|
+
listTools: () => [tool],
|
|
57
|
+
has: (name) => name === RUN,
|
|
58
|
+
execute,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|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C,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG;QAC3B,OAAO;KACR,CAAC;AACJ,CAAC"}
|
package/dist/tools/mcp.d.ts
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* file type-checks and ships even where the SDK isn't installed; constructing
|
|
14
14
|
* an McpToolSource without it throws a clear error.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Wired end-to-end: connect() (stdio + HTTP transports), listTools() and
|
|
17
|
+
* execute() are implemented. Used by the desktop sidecar (kaleido-mcp +
|
|
18
|
+
* Bitrefill MCP) and verified against the remote Bitrefill MCP.
|
|
18
19
|
*/
|
|
19
20
|
import type { ToolDef } from '../types.js';
|
|
20
21
|
import type { ToolSource } from './source.js';
|
package/dist/tools/mcp.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,MAAM,YAAY,GACpB;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,OAAO,EAAE,MAAM,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,EAAE,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,GACjF;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAAE,CAAC;AAEpE,MAAM,WAAW,oBAAoB;IACnC,EAAE,EAAE,MAAM,CAAC;IACX,SAAS,EAAE,YAAY,CAAC;IACxB,qEAAqE;IACrE,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,qBAAa,aAAc,YAAW,UAAU;IAC9C,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,IAAI,CAAuB;IAC5C,OAAO,CAAC,MAAM,CAAoB;IAClC,OAAO,CAAC,KAAK,CAAiB;gBAElB,IAAI,EAAE,oBAAoB;IAKtC,+EAA+E;IACzE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;IAkC9B,SAAS,IAAI,OAAO,EAAE;IAItB,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;IAIpB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAkBtE,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAI7B"}
|
package/dist/tools/mcp.js
CHANGED
|
@@ -13,8 +13,9 @@
|
|
|
13
13
|
* file type-checks and ships even where the SDK isn't installed; constructing
|
|
14
14
|
* an McpToolSource without it throws a clear error.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
16
|
+
* Wired end-to-end: connect() (stdio + HTTP transports), listTools() and
|
|
17
|
+
* execute() are implemented. Used by the desktop sidecar (kaleido-mcp +
|
|
18
|
+
* Bitrefill MCP) and verified against the remote Bitrefill MCP.
|
|
18
19
|
*/
|
|
19
20
|
export class McpToolSource {
|
|
20
21
|
id;
|
package/dist/tools/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"mcp.js","sourceRoot":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AAC,EAAE,wCAAwC,CAAC,CAAC;QACrG,MAAM,GAAG,GAAG,MAAM,IAAI,CAAC,MAAM,CAAC,QAAQ,CACpC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,EACzB,SAAS,EACT,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,SAAS,IAAI,MAAM,EAAE,CAC3C,CAAC;QACF,uEAAuE;QACvE,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,EAAE,CAAC;YAChC,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO;iBACrB,MAAM,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,MAAM,CAAC;iBACrC,GAAG,CAAC,CAAC,CAAM,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;iBACvB,IAAI,CAAC,IAAI,CAAC,CAAC;YACd,OAAO,IAAI,IAAI,GAAG,CAAC,OAAO,CAAC;QAC7B,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE,CAAC;QAC7B,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC;IACrB,CAAC;CACF"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Canonical multi-L2 wallet tool contract — the single source of truth for
|
|
3
|
+
* KaleidoMind's wallet tools (names + JSON schemas + spend flags).
|
|
4
|
+
*
|
|
5
|
+
* Every surface implements THESE EXACT tools, only the transport differs:
|
|
6
|
+
* - mobile → in-process handlers over the WDK adapters (`bindWalletTools`)
|
|
7
|
+
* - desktop → kaleido-mcp (tools namespaced per layer) + a `kaleido` CLI
|
|
8
|
+
* - eval → stub handlers
|
|
9
|
+
*
|
|
10
|
+
* Because the schemas are identical everywhere, skills are portable and the
|
|
11
|
+
* model comparison is honest. Tools are namespaced per layer (`spark_*`,
|
|
12
|
+
* `rln_*`, `arkade_*`, `liquid_*`); cross-cutting router/helpers are unprefixed.
|
|
13
|
+
*
|
|
14
|
+
* Spend tools (move funds) carry `spend: true` → `requiresConfirmation: true`,
|
|
15
|
+
* so the Engine always pauses for the host's confirm gate before executing.
|
|
16
|
+
*
|
|
17
|
+
* Pure data — no deps, RN-safe.
|
|
18
|
+
*/
|
|
19
|
+
import type { ToolDef } from '../types.js';
|
|
20
|
+
import { InProcessToolSource } from '../tools/in-process.js';
|
|
21
|
+
export type WalletLayer = 'spark' | 'rln' | 'arkade' | 'liquid' | 'core';
|
|
22
|
+
export interface WalletToolDef extends ToolDef {
|
|
23
|
+
/** Which L2 (or 'core' for cross-cutting router/helpers). */
|
|
24
|
+
layer: WalletLayer;
|
|
25
|
+
/** Moves funds → confirmation-gated. */
|
|
26
|
+
spend?: boolean;
|
|
27
|
+
}
|
|
28
|
+
/** The full contract. Keep descriptions terse — small models read every word. */
|
|
29
|
+
export declare const WALLET_TOOLS: WalletToolDef[];
|
|
30
|
+
export declare const WALLET_LAYERS: WalletLayer[];
|
|
31
|
+
/** Names of all spend (fund-moving) tools — these are confirmation-gated. */
|
|
32
|
+
export declare const SPEND_TOOLS: ReadonlySet<string>;
|
|
33
|
+
export declare function isSpendTool(name: string): boolean;
|
|
34
|
+
export declare function getWalletTool(name: string): WalletToolDef | undefined;
|
|
35
|
+
/** Pick the contract tools for the given layers (core helpers included by default). */
|
|
36
|
+
export declare function walletTools(opts?: {
|
|
37
|
+
layers?: WalletLayer[];
|
|
38
|
+
includeCore?: boolean;
|
|
39
|
+
}): WalletToolDef[];
|
|
40
|
+
/** Strip to plain ToolDefs (drop the layer/spend metadata). */
|
|
41
|
+
export declare function toToolDefs(tools: WalletToolDef[]): ToolDef[];
|
|
42
|
+
/** A handler bound to one contract tool. */
|
|
43
|
+
export type WalletHandler = (args: Record<string, unknown>) => Promise<unknown>;
|
|
44
|
+
export interface BindWalletOptions {
|
|
45
|
+
layers?: WalletLayer[];
|
|
46
|
+
includeCore?: boolean;
|
|
47
|
+
/** Skip tools that have no handler instead of throwing (default false). */
|
|
48
|
+
allowMissing?: boolean;
|
|
49
|
+
id?: string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Bind contract tools to in-process handlers → an InProcessToolSource. The
|
|
53
|
+
* mobile (and eval) binding: pass a map of `{ toolName: handler }` and you get a
|
|
54
|
+
* ToolSource implementing the canonical schemas with spend flags preserved.
|
|
55
|
+
*/
|
|
56
|
+
export declare function bindWalletTools(handlers: Record<string, WalletHandler>, opts?: BindWalletOptions): InProcessToolSource;
|
|
57
|
+
//# sourceMappingURL=contract.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"contract.d.ts","sourceRoot":"","sources":["../../src/wallet/contract.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAC;AAG7D,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,KAAK,GAAG,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;AAEzE,MAAM,WAAW,aAAc,SAAQ,OAAO;IAC5C,6DAA6D;IAC7D,KAAK,EAAE,WAAW,CAAC;IACnB,wCAAwC;IACxC,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAyBD,iFAAiF;AACjF,eAAO,MAAM,YAAY,EAAE,aAAa,EAqCvC,CAAC;AAIF,eAAO,MAAM,aAAa,EAAE,WAAW,EAAiD,CAAC;AAEzF,6EAA6E;AAC7E,eAAO,MAAM,WAAW,EAAE,WAAW,CAAC,MAAM,CAAmE,CAAC;AAEhH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAEjD;AAED,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,aAAa,GAAG,SAAS,CAErE;AAED,uFAAuF;AAC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