@kaleidorg/mind 0.0.1 → 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/engine.d.ts +9 -0
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +18 -2
- package/dist/engine.js.map +1 -1
- 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 +43 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -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/skills/bundle.d.ts +30 -0
- package/dist/skills/bundle.d.ts.map +1 -0
- package/dist/skills/bundle.js +24 -0
- package/dist/skills/bundle.js.map +1 -0
- package/dist/skills/loader.d.ts +33 -0
- package/dist/skills/loader.d.ts.map +1 -0
- package/dist/skills/loader.js +59 -0
- package/dist/skills/loader.js.map +1 -0
- package/dist/skills/reference-source.d.ts +18 -0
- package/dist/skills/reference-source.d.ts.map +1 -0
- package/dist/skills/reference-source.js +53 -0
- package/dist/skills/reference-source.js.map +1 -0
- package/dist/skills/registry.d.ts +41 -0
- package/dist/skills/registry.d.ts.map +1 -0
- package/dist/skills/registry.js +167 -0
- package/dist/skills/registry.js.map +1 -0
- package/dist/skills/types.d.ts +53 -0
- package/dist/skills/types.d.ts.map +1 -0
- package/dist/skills/types.js +18 -0
- package/dist/skills/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/l402.d.ts +47 -0
- package/dist/tools/l402.d.ts.map +1 -0
- package/dist/tools/l402.js +84 -0
- package/dist/tools/l402.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 +16 -5
- package/scripts/bundle-skills.mjs +84 -0
- package/skills/README.md +74 -0
- package/skills/bitrefill/SKILL.md +66 -0
- package/skills/bitrefill/references/api.md +99 -0
- package/skills/bitrefill/references/browse.md +71 -0
- package/skills/bitrefill/references/capability-matrix.md +115 -0
- package/skills/bitrefill/references/cli-headless-auth.md +133 -0
- package/skills/bitrefill/references/cli.md +237 -0
- package/skills/bitrefill/references/host-openclaw.md +167 -0
- package/skills/bitrefill/references/mcp.md +150 -0
- package/skills/bitrefill/references/safeguards.md +138 -0
- package/skills/bitrefill/references/troubleshooting.md +182 -0
- package/skills/kaleido-trading/SKILL.md +31 -0
- package/skills/kaleido-wallet/SKILL.md +28 -0
- 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/engine.test.ts +204 -0
- package/src/engine.ts +27 -2
- 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 +102 -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/skills/bundle.ts +42 -0
- package/src/skills/loader.ts +63 -0
- package/src/skills/reference-source.ts +60 -0
- package/src/skills/registry.ts +183 -0
- package/src/skills/skills.test.ts +191 -0
- package/src/skills/types.ts +55 -0
- package/src/tools/cli.test.ts +53 -0
- package/src/tools/cli.ts +98 -0
- package/src/tools/l402.test.ts +113 -0
- package/src/tools/l402.ts +122 -0
- package/src/tools/mcp.ts +3 -2
- package/src/wallet/contract.test.ts +89 -0
- package/src/wallet/contract.ts +157 -0
- package/dist/providers/qvac.d.ts +0 -89
- package/dist/providers/qvac.d.ts.map +0 -1
- package/dist/providers/qvac.js +0 -150
- package/dist/providers/qvac.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/rag/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory vector store — pure-JS cosine similarity index. Zero deps, so it
|
|
3
|
+
* bundles in Bare/RN. Good for thousands of chunks; swap in a native/SQLite
|
|
4
|
+
* store via the VectorStore interface for larger corpora.
|
|
5
|
+
*/
|
|
6
|
+
import type { Chunk, RetrievedChunk, VectorStore, VectorStoreIO } from './types.js';
|
|
7
|
+
/** Cosine similarity of two equal-length vectors. Returns 0 on degenerate input. */
|
|
8
|
+
export declare function cosineSimilarity(a: number[], b: number[]): number;
|
|
9
|
+
export interface InMemoryVectorStoreOptions {
|
|
10
|
+
io?: VectorStoreIO;
|
|
11
|
+
}
|
|
12
|
+
export declare class InMemoryVectorStore implements VectorStore {
|
|
13
|
+
private chunks;
|
|
14
|
+
private hydrated;
|
|
15
|
+
private readonly io?;
|
|
16
|
+
constructor(opts?: InMemoryVectorStoreOptions);
|
|
17
|
+
private hydrate;
|
|
18
|
+
upsert(chunks: Chunk[]): Promise<void>;
|
|
19
|
+
query(embedding: number[], k: number): Promise<RetrievedChunk[]>;
|
|
20
|
+
size(): Promise<number>;
|
|
21
|
+
clear(): Promise<void>;
|
|
22
|
+
}
|
|
23
|
+
//# sourceMappingURL=vector-store.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"vector-store.d.ts","sourceRoot":"","sources":["../../src/rag/vector-store.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,YAAY,CAAC;AAEpF,oFAAoF;AACpF,wBAAgB,gBAAgB,CAAC,CAAC,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,EAAE,GAAG,MAAM,CAYjE;AAED,MAAM,WAAW,0BAA0B;IACzC,EAAE,CAAC,EAAE,aAAa,CAAC;CACpB;AAED,qBAAa,mBAAoB,YAAW,WAAW;IACrD,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAS;IACzB,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAgB;gBAExB,IAAI,GAAE,0BAA+B;YAInC,OAAO;IAYf,MAAM,CAAC,MAAM,EAAE,KAAK,EAAE,GAAG,OAAO,CAAC,IAAI,CAAC;IAUtC,KAAK,CAAC,SAAS,EAAE,MAAM,EAAE,EAAE,CAAC,EAAE,MAAM,GAAG,OAAO,CAAC,cAAc,EAAE,CAAC;IAShE,IAAI,IAAI,OAAO,CAAC,MAAM,CAAC;IAKvB,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;CAK7B"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* In-memory vector store — pure-JS cosine similarity index. Zero deps, so it
|
|
3
|
+
* bundles in Bare/RN. Good for thousands of chunks; swap in a native/SQLite
|
|
4
|
+
* store via the VectorStore interface for larger corpora.
|
|
5
|
+
*/
|
|
6
|
+
/** Cosine similarity of two equal-length vectors. Returns 0 on degenerate input. */
|
|
7
|
+
export function cosineSimilarity(a, b) {
|
|
8
|
+
const n = Math.min(a.length, b.length);
|
|
9
|
+
let dot = 0;
|
|
10
|
+
let na = 0;
|
|
11
|
+
let nb = 0;
|
|
12
|
+
for (let i = 0; i < n; i++) {
|
|
13
|
+
dot += a[i] * b[i];
|
|
14
|
+
na += a[i] * a[i];
|
|
15
|
+
nb += b[i] * b[i];
|
|
16
|
+
}
|
|
17
|
+
if (na === 0 || nb === 0)
|
|
18
|
+
return 0;
|
|
19
|
+
return dot / (Math.sqrt(na) * Math.sqrt(nb));
|
|
20
|
+
}
|
|
21
|
+
export class InMemoryVectorStore {
|
|
22
|
+
chunks = [];
|
|
23
|
+
hydrated = false;
|
|
24
|
+
io;
|
|
25
|
+
constructor(opts = {}) {
|
|
26
|
+
this.io = opts.io;
|
|
27
|
+
}
|
|
28
|
+
async hydrate() {
|
|
29
|
+
if (this.hydrated)
|
|
30
|
+
return;
|
|
31
|
+
this.hydrated = true;
|
|
32
|
+
if (this.io) {
|
|
33
|
+
try {
|
|
34
|
+
this.chunks = await this.io.load();
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
this.chunks = [];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
async upsert(chunks) {
|
|
42
|
+
await this.hydrate();
|
|
43
|
+
for (const c of chunks) {
|
|
44
|
+
const i = this.chunks.findIndex((x) => x.id === c.id);
|
|
45
|
+
if (i >= 0)
|
|
46
|
+
this.chunks[i] = c;
|
|
47
|
+
else
|
|
48
|
+
this.chunks.push(c);
|
|
49
|
+
}
|
|
50
|
+
if (this.io)
|
|
51
|
+
await this.io.save(this.chunks);
|
|
52
|
+
}
|
|
53
|
+
async query(embedding, k) {
|
|
54
|
+
await this.hydrate();
|
|
55
|
+
return this.chunks
|
|
56
|
+
.filter((c) => c.embedding && c.embedding.length > 0)
|
|
57
|
+
.map((c) => ({ ...c, score: cosineSimilarity(embedding, c.embedding) }))
|
|
58
|
+
.sort((a, b) => b.score - a.score)
|
|
59
|
+
.slice(0, k);
|
|
60
|
+
}
|
|
61
|
+
async size() {
|
|
62
|
+
await this.hydrate();
|
|
63
|
+
return this.chunks.length;
|
|
64
|
+
}
|
|
65
|
+
async clear() {
|
|
66
|
+
await this.hydrate();
|
|
67
|
+
this.chunks = [];
|
|
68
|
+
if (this.io)
|
|
69
|
+
await this.io.save(this.chunks);
|
|
70
|
+
}
|
|
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,CAAC,SAAU,CAAC,EAAE,CAAC,CAAC;aACxE,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,CAAC;aACjC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IACjB,CAAC;IAED,KAAK,CAAC,IAAI;QACR,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;IAC5B,CAAC;IAED,KAAK,CAAC,KAAK;QACT,MAAM,IAAI,CAAC,OAAO,EAAE,CAAC;QACrB,IAAI,CAAC,MAAM,GAAG,EAAE,CAAC;QACjB,IAAI,IAAI,CAAC,EAAE;YAAE,MAAM,IAAI,CAAC,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in "send an RGB asset" recipe — distinct from the BTC payments recipe
|
|
3
|
+
* because an asset amount must NOT be treated as fiat.
|
|
4
|
+
*
|
|
5
|
+
* "send 10 USDT to bob" → resolve_contact → rln_send_asset 🔒
|
|
6
|
+
* "pay alice 5 XAUT" → resolve_contact → rln_send_asset 🔒
|
|
7
|
+
*
|
|
8
|
+
* Fixes the bug where the payments recipe parsed "USDT" as a fiat currency and
|
|
9
|
+
* ran fiat_to_sats. Payments now excludes RGB assets; this recipe owns them.
|
|
10
|
+
*/
|
|
11
|
+
import type { Recipe } from './types.js';
|
|
12
|
+
/** "send 10 USDT to bob" / "pay alice 5 xaut". */
|
|
13
|
+
export declare function extractAssetSend(text: string): Record<string, unknown> | null;
|
|
14
|
+
export declare const assetSendRecipe: Recipe;
|
|
15
|
+
//# sourceMappingURL=asset-send.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-send.d.ts","sourceRoot":"","sources":["../../src/recipe/asset-send.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAoBxD,kDAAkD;AAClD,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAa7E;AAED,eAAO,MAAM,eAAe,EAAE,MA+B7B,CAAC"}
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in "send an RGB asset" recipe — distinct from the BTC payments recipe
|
|
3
|
+
* because an asset amount must NOT be treated as fiat.
|
|
4
|
+
*
|
|
5
|
+
* "send 10 USDT to bob" → resolve_contact → rln_send_asset 🔒
|
|
6
|
+
* "pay alice 5 XAUT" → resolve_contact → rln_send_asset 🔒
|
|
7
|
+
*
|
|
8
|
+
* Fixes the bug where the payments recipe parsed "USDT" as a fiat currency and
|
|
9
|
+
* ran fiat_to_sats. Payments now excludes RGB assets; this recipe owns them.
|
|
10
|
+
*/
|
|
11
|
+
const RGB_ASSET = /\b(usdt|tether|xaut|gold)\b/i;
|
|
12
|
+
const isOnchainOrInvoice = (s) => /^(ln(bc|tb|bcrt)|bc1|tb1|lnurl|rgb:|[a-z0-9._-]+@)/i.test(s.trim());
|
|
13
|
+
function normAsset(a) {
|
|
14
|
+
if (!a)
|
|
15
|
+
return undefined;
|
|
16
|
+
const x = a.toLowerCase();
|
|
17
|
+
if (/usdt|tether/.test(x))
|
|
18
|
+
return 'USDT';
|
|
19
|
+
if (/xaut|gold/.test(x))
|
|
20
|
+
return 'XAUT';
|
|
21
|
+
return a.toUpperCase();
|
|
22
|
+
}
|
|
23
|
+
function parseAmount(t) {
|
|
24
|
+
const m = t.match(/(\d[\d.,]*)\s*([km])?\b/i);
|
|
25
|
+
if (!m)
|
|
26
|
+
return undefined;
|
|
27
|
+
let n = Number(m[1].replace(/,/g, ''));
|
|
28
|
+
if (m[2])
|
|
29
|
+
n *= m[2].toLowerCase() === 'k' ? 1_000 : 1_000_000;
|
|
30
|
+
return Number.isNaN(n) ? undefined : n;
|
|
31
|
+
}
|
|
32
|
+
/** "send 10 USDT to bob" / "pay alice 5 xaut". */
|
|
33
|
+
export function extractAssetSend(text) {
|
|
34
|
+
const t = text.trim();
|
|
35
|
+
if (!/\b(send|pay|transfer)\b/i.test(t))
|
|
36
|
+
return null;
|
|
37
|
+
const asset = normAsset(t.match(RGB_ASSET)?.[1]);
|
|
38
|
+
if (!asset)
|
|
39
|
+
return null; // not an asset send → let the payments recipe handle it
|
|
40
|
+
const amount = parseAmount(t);
|
|
41
|
+
let recipient = t.match(/\bto\s+([^\s,]+)/i)?.[1];
|
|
42
|
+
if (!recipient) {
|
|
43
|
+
const after = t.match(/\b(?:pay|send|transfer)\s+([^\s,]+)/i)?.[1];
|
|
44
|
+
if (after && !/^\d/.test(after) && !RGB_ASSET.test(after))
|
|
45
|
+
recipient = after;
|
|
46
|
+
}
|
|
47
|
+
if (!recipient && amount == null)
|
|
48
|
+
return null;
|
|
49
|
+
return { recipient, asset, amount };
|
|
50
|
+
}
|
|
51
|
+
export const assetSendRecipe = {
|
|
52
|
+
name: 'pay-asset',
|
|
53
|
+
description: 'Send an RGB asset (USDT, XAUT) to a contact or address — resolves the contact, then sends (with confirmation).',
|
|
54
|
+
match: (t) => /\b(send|pay|transfer)\b/i.test(t) && RGB_ASSET.test(t) && !/\b(invoice|receive|swap|buy|sell|for)\b/i.test(t),
|
|
55
|
+
triggers: ['send', 'pay', 'transfer'],
|
|
56
|
+
slots: [
|
|
57
|
+
{ name: 'recipient', type: 'string', description: 'Contact name, address, or RGB invoice', required: true },
|
|
58
|
+
{ name: 'asset', type: 'string', description: 'RGB asset: USDT or XAUT', required: true },
|
|
59
|
+
{ name: 'amount', type: 'number', description: 'Asset amount' },
|
|
60
|
+
],
|
|
61
|
+
extract: extractAssetSend,
|
|
62
|
+
confident: (s) => !!s.recipient && !!s.asset,
|
|
63
|
+
steps: [
|
|
64
|
+
{
|
|
65
|
+
tool: 'resolve_contact',
|
|
66
|
+
as: 'contact',
|
|
67
|
+
args: (ctx) => ({ name: ctx.slots.recipient }),
|
|
68
|
+
skipIf: (ctx) => !ctx.slots.recipient || isOnchainOrInvoice(String(ctx.slots.recipient)),
|
|
69
|
+
},
|
|
70
|
+
],
|
|
71
|
+
final: {
|
|
72
|
+
tool: 'rln_send_asset',
|
|
73
|
+
args: (ctx) => {
|
|
74
|
+
const contact = ctx.results.contact;
|
|
75
|
+
return { asset: ctx.slots.asset, amount: ctx.slots.amount, to: contact?.ln_address ?? ctx.slots.recipient };
|
|
76
|
+
},
|
|
77
|
+
},
|
|
78
|
+
summary: (ctx) => {
|
|
79
|
+
const to = ctx.results.contact?.name ?? ctx.slots.recipient;
|
|
80
|
+
return `Sent ${ctx.slots.amount} ${ctx.slots.asset} to ${to}.`;
|
|
81
|
+
},
|
|
82
|
+
};
|
|
83
|
+
//# sourceMappingURL=asset-send.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"asset-send.js","sourceRoot":"","sources":["../../src/recipe/asset-send.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,SAAS,GAAG,8BAA8B,CAAC;AACjD,MAAM,kBAAkB,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,qDAAqD,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAE/G,SAAS,SAAS,CAAC,CAAU;IAC3B,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1B,IAAI,aAAa,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC;IACzC,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,MAAM,CAAC;IACvC,OAAO,CAAC,CAAC,WAAW,EAAE,CAAC;AACzB,CAAC;AACD,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AC9C,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,IAAI,kBAAkB,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;SACzF;KACF;IACD,KAAK,EAAE;QACL,IAAI,EAAE,gBAAgB;QACtB,IAAI,EAAE,CAAC,GAAkB,EAAE,EAAE;YAC3B,MAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC,OAA8C,CAAC;YAC3E,OAAO,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,MAAM,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,EAAE,EAAE,OAAO,EAAE,UAAU,IAAI,GAAG,CAAC,KAAK,CAAC,SAAS,EAAE,CAAC;QAC9G,CAAC;KACF;IACD,OAAO,EAAE,CAAC,GAAG,EAAE,EAAE;QACf,MAAM,EAAE,GAAI,GAAG,CAAC,OAAO,CAAC,OAAyC,EAAE,IAAI,IAAI,GAAG,CAAC,KAAK,CAAC,SAAS,CAAC;QAC/F,OAAO,QAAQ,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,OAAO,EAAE,GAAG,CAAC;IACjE,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in "pay a contact" recipe — the flagship mobile multi-step flow.
|
|
3
|
+
*
|
|
4
|
+
* "pay bob 3 EUR" → resolve_contact → fiat_to_sats → send_payment 🔒
|
|
5
|
+
* "send 5000 sats to alice" → resolve_contact → send_payment 🔒
|
|
6
|
+
*
|
|
7
|
+
* Uses the canonical contract tools. The deterministic extractor handles most
|
|
8
|
+
* phrasings with no LLM at all (Tier-0); the runner falls back to one LLM
|
|
9
|
+
* extraction otherwise.
|
|
10
|
+
*/
|
|
11
|
+
import type { Recipe } from './types.js';
|
|
12
|
+
/** "pay bob 3 eur", "send 5,000 sats to alice", "pay lnbc... ", "send 0.001 btc to bob" */
|
|
13
|
+
export declare function extractPayment(text: string): Record<string, unknown> | null;
|
|
14
|
+
export declare const paymentsRecipe: Recipe;
|
|
15
|
+
//# sourceMappingURL=payments.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.d.ts","sourceRoot":"","sources":["../../src/recipe/payments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAiB,MAAM,YAAY,CAAC;AAgBxD,2FAA2F;AAC3F,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAuB3E;AAgBD,eAAO,MAAM,cAAc,EAAE,MAgD5B,CAAC"}
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in "pay a contact" recipe — the flagship mobile multi-step flow.
|
|
3
|
+
*
|
|
4
|
+
* "pay bob 3 EUR" → resolve_contact → fiat_to_sats → send_payment 🔒
|
|
5
|
+
* "send 5000 sats to alice" → resolve_contact → send_payment 🔒
|
|
6
|
+
*
|
|
7
|
+
* Uses the canonical contract tools. The deterministic extractor handles most
|
|
8
|
+
* phrasings with no LLM at all (Tier-0); the runner falls back to one LLM
|
|
9
|
+
* extraction otherwise.
|
|
10
|
+
*/
|
|
11
|
+
const CURRENCIES = /\b(sats?|sat|btc|usdt|xaut|eur|usd|gbp|dollars?|euros?|pounds?)\b/i;
|
|
12
|
+
const isOnchainOrInvoice = (s) => /^(ln(bc|tb|bcrt)|bc1|tb1|lnurl|[a-z0-9._-]+@)/i.test(s.trim());
|
|
13
|
+
function normCurrency(c) {
|
|
14
|
+
if (!c)
|
|
15
|
+
return undefined;
|
|
16
|
+
const x = c.toLowerCase();
|
|
17
|
+
if (/^sat/.test(x))
|
|
18
|
+
return 'sats';
|
|
19
|
+
if (x === 'btc')
|
|
20
|
+
return 'btc';
|
|
21
|
+
if (/dollar|^usd/.test(x))
|
|
22
|
+
return 'usd';
|
|
23
|
+
if (/euro|^eur/.test(x))
|
|
24
|
+
return 'eur';
|
|
25
|
+
if (/pound|^gbp/.test(x))
|
|
26
|
+
return 'gbp';
|
|
27
|
+
return x.toUpperCase();
|
|
28
|
+
}
|
|
29
|
+
/** "pay bob 3 eur", "send 5,000 sats to alice", "pay lnbc... ", "send 0.001 btc to bob" */
|
|
30
|
+
export function extractPayment(text) {
|
|
31
|
+
const t = text.trim();
|
|
32
|
+
if (!/\b(pay|send|transfer)\b/i.test(t))
|
|
33
|
+
return null;
|
|
34
|
+
// Amount with optional k/m shorthand: "5k" → 5000, "2m" → 2_000_000.
|
|
35
|
+
const amtMatch = t.match(/(\d[\d.,]*)\s*([km])?\b/i);
|
|
36
|
+
let amountNum = amtMatch ? Number(amtMatch[1].replace(/,/g, '')) : undefined;
|
|
37
|
+
if (amountNum != null && amtMatch?.[2])
|
|
38
|
+
amountNum *= amtMatch[2].toLowerCase() === 'k' ? 1_000 : 1_000_000;
|
|
39
|
+
const amount = amountNum != null && !Number.isNaN(amountNum) ? String(amountNum) : undefined;
|
|
40
|
+
const currency = normCurrency(t.match(CURRENCIES)?.[1]);
|
|
41
|
+
// recipient: prefer "to <x>", else the token right after pay/send that isn't a number/currency
|
|
42
|
+
let recipient = t.match(/\bto\s+([^\s,]+)/i)?.[1];
|
|
43
|
+
if (!recipient) {
|
|
44
|
+
const after = t.match(/\b(?:pay|send|transfer)\s+([^\s,]+)/i)?.[1];
|
|
45
|
+
if (after && !/^\d/.test(after) && !CURRENCIES.test(after))
|
|
46
|
+
recipient = after;
|
|
47
|
+
}
|
|
48
|
+
if (!recipient && !amount)
|
|
49
|
+
return null;
|
|
50
|
+
return {
|
|
51
|
+
recipient,
|
|
52
|
+
amount: amount ? Number(amount) : undefined,
|
|
53
|
+
currency,
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
/** Compute the sats amount when no fiat conversion step is needed. */
|
|
57
|
+
function directSats(ctx) {
|
|
58
|
+
const amount = Number(ctx.slots.amount);
|
|
59
|
+
if (!amount || Number.isNaN(amount))
|
|
60
|
+
return undefined;
|
|
61
|
+
const cur = String(ctx.slots.currency ?? 'sats').toLowerCase();
|
|
62
|
+
if (cur === 'btc')
|
|
63
|
+
return Math.round(amount * 1e8);
|
|
64
|
+
return Math.round(amount); // sats (default)
|
|
65
|
+
}
|
|
66
|
+
const isFiat = (ctx) => {
|
|
67
|
+
const c = String(ctx.slots.currency ?? '').toLowerCase();
|
|
68
|
+
return c !== '' && c !== 'sats' && c !== 'btc';
|
|
69
|
+
};
|
|
70
|
+
export const paymentsRecipe = {
|
|
71
|
+
name: 'pay-contact',
|
|
72
|
+
description: 'Pay a contact or address — resolves the contact, converts fiat to sats, then sends (with confirmation).',
|
|
73
|
+
// A BTC/fiat spend intent — NOT a receive/invoice, and NOT an RGB-asset send
|
|
74
|
+
// ("send 10 USDT to bob" is handled by the asset-send recipe, so USDT/XAUT
|
|
75
|
+
// amounts are never mis-parsed as fiat).
|
|
76
|
+
match: (t) => /\b(pay|send|transfer)\b/i.test(t) && !/\b(invoice|receive|request|address|qr|deposit|usdt|tether|xaut|gold)\b/i.test(t),
|
|
77
|
+
triggers: ['pay', 'send', 'transfer'],
|
|
78
|
+
slots: [
|
|
79
|
+
{ name: 'recipient', type: 'string', description: 'Who to pay: a contact name, Lightning address, or invoice', required: true },
|
|
80
|
+
{ name: 'amount', type: 'number', description: 'The amount to send' },
|
|
81
|
+
{ name: 'currency', type: 'string', description: 'Unit of the amount: sats, btc, or a fiat code like eur/usd' },
|
|
82
|
+
],
|
|
83
|
+
extract: extractPayment,
|
|
84
|
+
confident: (s) => !!s.recipient,
|
|
85
|
+
steps: [
|
|
86
|
+
{
|
|
87
|
+
// Resolve a contact name → payable address (skip if already an address/invoice).
|
|
88
|
+
tool: 'resolve_contact',
|
|
89
|
+
as: 'contact',
|
|
90
|
+
args: (ctx) => ({ name: ctx.slots.recipient }),
|
|
91
|
+
skipIf: (ctx) => !ctx.slots.recipient || isOnchainOrInvoice(String(ctx.slots.recipient)),
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
// Convert fiat → sats (skip when the amount is already sats/btc or absent).
|
|
95
|
+
tool: 'fiat_to_sats',
|
|
96
|
+
as: 'conv',
|
|
97
|
+
args: (ctx) => ({ amount: ctx.slots.amount, currency: ctx.slots.currency }),
|
|
98
|
+
skipIf: (ctx) => !ctx.slots.amount || !isFiat(ctx),
|
|
99
|
+
},
|
|
100
|
+
],
|
|
101
|
+
final: {
|
|
102
|
+
tool: 'send_payment',
|
|
103
|
+
args: (ctx) => {
|
|
104
|
+
const contact = ctx.results.contact;
|
|
105
|
+
const conv = ctx.results.conv;
|
|
106
|
+
return {
|
|
107
|
+
to: contact?.ln_address ?? ctx.slots.recipient,
|
|
108
|
+
amount_sats: conv?.sats ?? directSats(ctx),
|
|
109
|
+
};
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
summary: (ctx) => {
|
|
113
|
+
const conv = ctx.results.conv;
|
|
114
|
+
const sats = conv?.sats ?? directSats(ctx);
|
|
115
|
+
const to = ctx.results.contact?.name ?? ctx.slots.recipient;
|
|
116
|
+
return sats ? `Sent ${sats.toLocaleString()} sats to ${to}.` : `Payment sent to ${to}.`;
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
//# sourceMappingURL=payments.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"payments.js","sourceRoot":"","sources":["../../src/recipe/payments.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,UAAU,GAAG,oEAAoE,CAAC;AACxF,MAAM,kBAAkB,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,gDAAgD,CAAC,IAAI,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC;AAE1G,SAAS,YAAY,CAAC,CAAU;IAC9B,IAAI,CAAC,CAAC;QAAE,OA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C,CAAC,QAAQ,IAAI,CAAC,cAAc,EAAE,YAAY,EAAE,GAAG,CAAC,CAAC,CAAC,mBAAmB,EAAE,GAAG,CAAC;IAC1F,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in "receive" recipe — create an invoice/address to get paid, in sats,
|
|
3
|
+
* BTC, an RGB asset, OR a fiat amount (converted to sats deterministically so a
|
|
4
|
+
* small model never mis-parses "$2.00").
|
|
5
|
+
*
|
|
6
|
+
* "invoice for 5000 sats" → BTC invoice, 5000 sats
|
|
7
|
+
* "create a payment request of $2" → fiat_to_sats(2, USD) → BTC invoice
|
|
8
|
+
* "invoice for 25 USDT on Liquid" → RGB asset invoice
|
|
9
|
+
* "an invoice" → BTC invoice, any amount
|
|
10
|
+
*/
|
|
11
|
+
import type { Recipe } from './types.js';
|
|
12
|
+
export declare function extractReceive(text: string): Record<string, unknown> | null;
|
|
13
|
+
export declare const receiveRecipe: Recipe;
|
|
14
|
+
//# sourceMappingURL=receive.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receive.d.ts","sourceRoot":"","sources":["../../src/recipe/receive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AA+BzC,wBAAgB,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAO3E;AAED,eAAO,MAAM,aAAa,EAAE,MA8C3B,CAAC"}
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Built-in "receive" recipe — create an invoice/address to get paid, in sats,
|
|
3
|
+
* BTC, an RGB asset, OR a fiat amount (converted to sats deterministically so a
|
|
4
|
+
* small model never mis-parses "$2.00").
|
|
5
|
+
*
|
|
6
|
+
* "invoice for 5000 sats" → BTC invoice, 5000 sats
|
|
7
|
+
* "create a payment request of $2" → fiat_to_sats(2, USD) → BTC invoice
|
|
8
|
+
* "invoice for 25 USDT on Liquid" → RGB asset invoice
|
|
9
|
+
* "an invoice" → BTC invoice, any amount
|
|
10
|
+
*/
|
|
11
|
+
const LAYER = /\b(spark|arkade|liquid|rln|lightning|rgb)\b/i;
|
|
12
|
+
const RECEIVE_INTENT = /\b(invoice|receive|deposit|get paid|pay me|payment request|request (a )?payment)\b/i;
|
|
13
|
+
function classify(text) {
|
|
14
|
+
if (/\$|\busd\b|dollar/i.test(text))
|
|
15
|
+
return { kind: 'fiat', code: 'USD' };
|
|
16
|
+
if (/€|\beur\b|euro/i.test(text))
|
|
17
|
+
return { kind: 'fiat', code: 'EUR' };
|
|
18
|
+
if (/£|\bgbp\b|pound/i.test(text))
|
|
19
|
+
return { kind: 'fiat', code: 'GBP' };
|
|
20
|
+
if (/usdt|tether/i.test(text))
|
|
21
|
+
return { kind: 'asset', code: 'USDT' };
|
|
22
|
+
if (/xaut|gold/i.test(text))
|
|
23
|
+
return { kind: 'asset', code: 'XAUT' };
|
|
24
|
+
if (/\bbtc\b|bitcoin/i.test(text))
|
|
25
|
+
return { kind: 'btc', code: 'BTC' };
|
|
26
|
+
return { kind: 'sats', code: 'BTC' }; // default: sats
|
|
27
|
+
}
|
|
28
|
+
function normLayer(l) {
|
|
29
|
+
if (!l)
|
|
30
|
+
return undefined;
|
|
31
|
+
const x = l.toLowerCase();
|
|
32
|
+
if (x === 'lightning' || x === 'rgb')
|
|
33
|
+
return 'rln';
|
|
34
|
+
if (['spark', 'arkade', 'liquid', 'rln'].includes(x))
|
|
35
|
+
return x;
|
|
36
|
+
return undefined;
|
|
37
|
+
}
|
|
38
|
+
function parseAmount(t) {
|
|
39
|
+
const m = t.match(/(\d[\d.,]*)\s*([km])?\b/i);
|
|
40
|
+
if (!m)
|
|
41
|
+
return undefined;
|
|
42
|
+
let n = Number(m[1].replace(/,/g, ''));
|
|
43
|
+
if (m[2])
|
|
44
|
+
n *= m[2].toLowerCase() === 'k' ? 1_000 : 1_000_000;
|
|
45
|
+
return Number.isNaN(n) ? undefined : n;
|
|
46
|
+
}
|
|
47
|
+
export function extractReceive(text) {
|
|
48
|
+
const t = text.trim();
|
|
49
|
+
if (!RECEIVE_INTENT.test(t))
|
|
50
|
+
return null;
|
|
51
|
+
const amount = parseAmount(t);
|
|
52
|
+
const { kind, code } = classify(t);
|
|
53
|
+
const layer = normLayer(t.match(LAYER)?.[1]);
|
|
54
|
+
return { ...(amount != null ? { amount } : {}), kind, currency: code, ...(layer ? { layer } : {}) };
|
|
55
|
+
}
|
|
56
|
+
export const receiveRecipe = {
|
|
57
|
+
name: 'receive',
|
|
58
|
+
description: 'Create an invoice/address to receive funds — sats, BTC, a fiat amount (converted), or an RGB asset.',
|
|
59
|
+
match: (t) => RECEIVE_INTENT.test(t) && !/\b(send|transfer|swap|buy|sell)\b/i.test(t),
|
|
60
|
+
triggers: ['invoice', 'receive', 'deposit', 'payment request'],
|
|
61
|
+
slots: [
|
|
62
|
+
{ name: 'amount', type: 'number', description: 'Amount to receive (optional)' },
|
|
63
|
+
{ name: 'currency', type: 'string', description: 'sats | BTC | USD | EUR | USDT | XAUT' },
|
|
64
|
+
{ name: 'layer', type: 'string', description: 'Rail: spark, rln, liquid (optional)' },
|
|
65
|
+
],
|
|
66
|
+
extract: extractReceive,
|
|
67
|
+
confident: () => true,
|
|
68
|
+
steps: [
|
|
69
|
+
{
|
|
70
|
+
// Fiat → sats, only when the amount is fiat-denominated.
|
|
71
|
+
tool: 'fiat_to_sats',
|
|
72
|
+
as: 'conv',
|
|
73
|
+
args: (ctx) => ({ amount: ctx.slots.amount, currency: ctx.slots.currency }),
|
|
74
|
+
skipIf: (ctx) => ctx.slots.kind !== 'fiat' || ctx.slots.amount == null,
|
|
75
|
+
},
|
|
76
|
+
],
|
|
77
|
+
final: {
|
|
78
|
+
tool: 'create_invoice',
|
|
79
|
+
args: (ctx) => {
|
|
80
|
+
const kind = ctx.slots.kind;
|
|
81
|
+
const conv = ctx.results.conv;
|
|
82
|
+
let asset = 'BTC';
|
|
83
|
+
let amount = ctx.slots.amount;
|
|
84
|
+
if (kind === 'asset')
|
|
85
|
+
asset = String(ctx.slots.currency);
|
|
86
|
+
else if (kind === 'fiat')
|
|
87
|
+
amount = conv?.sats;
|
|
88
|
+
else if (kind === 'btc' && amount != null)
|
|
89
|
+
amount = Math.round(amount * 1e8); // sats
|
|
90
|
+
return { asset, amount, layer: ctx.slots.layer };
|
|
91
|
+
},
|
|
92
|
+
},
|
|
93
|
+
summary: (ctx, result) => {
|
|
94
|
+
const r = result;
|
|
95
|
+
const dest = r?.invoice ?? r?.address ?? '';
|
|
96
|
+
const kind = ctx.slots.kind;
|
|
97
|
+
const conv = ctx.results.conv;
|
|
98
|
+
let amt = 'any amount';
|
|
99
|
+
if (kind === 'fiat' && ctx.slots.amount != null)
|
|
100
|
+
amt = `${ctx.slots.currency} ${ctx.slots.amount} (${(conv?.sats ?? 0).toLocaleString()} sats)`;
|
|
101
|
+
else if (kind === 'asset' && ctx.slots.amount != null)
|
|
102
|
+
amt = `${Number(ctx.slots.amount).toLocaleString()} ${ctx.slots.currency}`;
|
|
103
|
+
else if (ctx.slots.amount != null)
|
|
104
|
+
amt = `${Number(ctx.slots.amount).toLocaleString()} ${kind === 'btc' ? 'BTC' : 'sats'}`;
|
|
105
|
+
const label = kind === 'asset' ? String(ctx.slots.currency) : 'BTC';
|
|
106
|
+
return dest ? `Here's your ${label} invoice for ${amt}:\n\n${dest}` : `Created an invoice for ${amt}.`;
|
|
107
|
+
},
|
|
108
|
+
};
|
|
109
|
+
//# sourceMappingURL=receive.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"receive.js","sourceRoot":"","sources":["../../src/recipe/receive.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,MAAM,KAAK,GAAG,8CAA8C,CAAC;AAC7D,MAAM,cAAc,GAAG,qFAAqF,CAAC;AAI7G,SA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C,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,EAAE,CAAC;aAC7H,IAAI,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,IAAI;YAAE,GAAG,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,IAAI,IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;QAC3H,MAAM,KAAK,GAAG,IAAI,KAAK,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC;QACpE,OAAO,IAAI,CAAC,CAAC,CAAC,eAAe,KAAK,gBAAgB,GAAG,QAAQ,IAAI,EAAE,CAAC,CAAC,CAAC,0BAA0B,GAAG,GAAG,CAAC;IACzG,CAAC;CACF,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
import type { LLMProvider } from '../providers/types.js';
|
|
8
|
+
import type { ToolRegistry } from '../tools/registry.js';
|
|
9
|
+
import type { ConfirmDecision } from '../types.js';
|
|
10
|
+
import type { Recipe, RecipeResult } from './types.js';
|
|
11
|
+
export interface RunRecipeOptions {
|
|
12
|
+
provider: LLMProvider;
|
|
13
|
+
tools: ToolRegistry;
|
|
14
|
+
/** Called before the (spend) final action when its tool is confirmation-gated. */
|
|
15
|
+
onConfirm?: (call: {
|
|
16
|
+
name: string;
|
|
17
|
+
arguments: Record<string, unknown>;
|
|
18
|
+
}) => Promise<ConfirmDecision>;
|
|
19
|
+
/** Progress hook per completed step. */
|
|
20
|
+
onStep?: (name: string, args: Record<string, unknown>, result: unknown) => void;
|
|
21
|
+
/** Skip extraction and use these slots (deterministic Tier-0 / tests). */
|
|
22
|
+
slots?: Record<string, unknown>;
|
|
23
|
+
signal?: AbortSignal;
|
|
24
|
+
}
|
|
25
|
+
/** Extract the recipe's slots — deterministic regex first, else ONE LLM call. */
|
|
26
|
+
export declare function extractSlots(provider: LLMProvider, recipe: Recipe, text: string): Promise<{
|
|
27
|
+
slots: Record<string, unknown>;
|
|
28
|
+
inferences: number;
|
|
29
|
+
}>;
|
|
30
|
+
/** Run a recipe end to end. Never throws — failures come back as status:'error'. */
|
|
31
|
+
export declare function runRecipe(recipe: Recipe, text: string, opts: RunRecipeOptions): Promise<RecipeResult>;
|
|
32
|
+
/** Selects a recipe for a request. Use before falling back to the free agentic loop. */
|
|
33
|
+
export declare class RecipeRegistry {
|
|
34
|
+
private recipes;
|
|
35
|
+
constructor(recipes?: Recipe[]);
|
|
36
|
+
add(recipe: Recipe): void;
|
|
37
|
+
list(): Recipe[];
|
|
38
|
+
get(name: string): Recipe | undefined;
|
|
39
|
+
/** First recipe whose match()/triggers fit the text, else null. */
|
|
40
|
+
select(text: string): Recipe | null;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=runner.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runner.d.ts","sourceRoot":"","sources":["../../src/recipe/runner.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACzD,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AACnD,OAAO,KAAK,EAAE,MAAM,EAAiB,YAAY,EAAE,MAAM,YAAY,CAAC;AAItE,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,WAA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