@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,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,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QAAQ,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,WAAW,EAAE,CAAC,CAAC,CACvF,IAAI,IAAI,CACV,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
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;;;;;;;;;;GAUG;AAIH,MAAM,KAAK,GAAG,gDAAgD,CAAC;AAE/D,SAAS,SAAS,CAAC,CAAU;IAC3B,IAAI,CAAC,CAAC;QAAE,OAAO,SAAS,CAAC;IACzB,MAAM,CAAC,GAAG,CAAC,CAAC,WAAW,EAAE,CAAC;IAC1B,IAAI,iBAAiB,CAAC,IAAI,CAAC,CAAC,CAAC;QAAE,OAAO,KAAK,CAAC;IAC5C,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,MAAM,GAAG,GAAG,CAAC,CAAU,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAE1E,qFAAqF;AACrF,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACtB,IAAI,CAA0B,CAAC;IAC/B,0EAA0E;IAC1E,IAAI,CAAC,CAAC,GAAG,CAAC,CAAC,KAAK,CAAC,6DAA6D,CAAC,CAAC,EAAE,CAAC;QACjF,OAAO,EAAE,MAAM,EAAE,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,SAAS,CAAC,CAAC,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 @@
|
|
|
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,MAA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AED,MAAM,MAAM,YAAY,GAAG,MAAM,GAAG,WAAW,GAAG,OAAO,CAAC;AAE1D,MAAM,WAAW,YAAY;IAC3B,MAAM,EAAE,MAAM,CAAC;IACf,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACjC,KAAK,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,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill bundle — the RN-safe counterpart to the Node fs loader.
|
|
3
|
+
*
|
|
4
|
+
* React Native has no filesystem, so a skill folder can't be read at runtime.
|
|
5
|
+
* Instead a build step serialises the skills into a `SkillBundle` (plain JSON:
|
|
6
|
+
* each skill's raw SKILL.md text + its reference files), and the app rehydrates
|
|
7
|
+
* them here with `skillsFromBundle()`. Same skills, same SKILL.md authoring —
|
|
8
|
+
* just delivered as data instead of files.
|
|
9
|
+
*
|
|
10
|
+
* Pure, dependency-free, no fs/url imports — safe to import from the package's
|
|
11
|
+
* main entry on any host.
|
|
12
|
+
*/
|
|
13
|
+
import type { Skill, SkillReference } from './types.js';
|
|
14
|
+
/** One serialised skill: the SKILL.md text + its reference files. */
|
|
15
|
+
export interface BundledSkill {
|
|
16
|
+
/** Folder name (informational; the real name comes from the frontmatter). */
|
|
17
|
+
dir?: string;
|
|
18
|
+
/** Raw SKILL.md contents. */
|
|
19
|
+
markdown: string;
|
|
20
|
+
/** references/*.md files. */
|
|
21
|
+
references?: SkillReference[];
|
|
22
|
+
}
|
|
23
|
+
/** A bundle of skills produced by the bundler script. */
|
|
24
|
+
export interface SkillBundle {
|
|
25
|
+
version: 1;
|
|
26
|
+
skills: BundledSkill[];
|
|
27
|
+
}
|
|
28
|
+
/** Rehydrate Skills from a bundle (RN-safe — no filesystem). */
|
|
29
|
+
export declare function skillsFromBundle(bundle: SkillBundle): Skill[];
|
|
30
|
+
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../src/skills/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,KAAK,EAAE,cAAc,EAAE,MAAM,YAAY,CAAC;AAGxD,qEAAqE;AACrE,MAAM,WAAW,YAAY;IAC3B,6EAA6E;IAC7E,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,6BAA6B;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,6BAA6B;IAC7B,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;CAC/B;AAED,yDAAyD;AACzD,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,CAAC,CAAC;IACX,MAAM,EAAE,YAAY,EAAE,CAAC;CACxB;AAED,gEAAgE;AAChE,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,WAAW,GAAG,KAAK,EAAE,CAQ7D"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill bundle — the RN-safe counterpart to the Node fs loader.
|
|
3
|
+
*
|
|
4
|
+
* React Native has no filesystem, so a skill folder can't be read at runtime.
|
|
5
|
+
* Instead a build step serialises the skills into a `SkillBundle` (plain JSON:
|
|
6
|
+
* each skill's raw SKILL.md text + its reference files), and the app rehydrates
|
|
7
|
+
* them here with `skillsFromBundle()`. Same skills, same SKILL.md authoring —
|
|
8
|
+
* just delivered as data instead of files.
|
|
9
|
+
*
|
|
10
|
+
* Pure, dependency-free, no fs/url imports — safe to import from the package's
|
|
11
|
+
* main entry on any host.
|
|
12
|
+
*/
|
|
13
|
+
import { parseSkill } from './registry.js';
|
|
14
|
+
/** Rehydrate Skills from a bundle (RN-safe — no filesystem). */
|
|
15
|
+
export function skillsFromBundle(bundle) {
|
|
16
|
+
if (!bundle || bundle.version !== 1 || !Array.isArray(bundle.skills)) {
|
|
17
|
+
throw new Error('skillsFromBundle: not a valid v1 SkillBundle');
|
|
18
|
+
}
|
|
19
|
+
return bundle.skills.map((b) => ({
|
|
20
|
+
...parseSkill(b.markdown, b.references),
|
|
21
|
+
dir: b.dir,
|
|
22
|
+
}));
|
|
23
|
+
}
|
|
24
|
+
//# sourceMappingURL=bundle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bundle.js","sourceRoot":"","sources":["../../src/skills/bundle.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAGH,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAkB3C,gEAAgE;AAChE,MAAM,UAAU,gBAAgB,CAAC,MAAmB;IAClD,IAAI,CAAC,MAAM,IAAI,MAAM,CAAC,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,CAAC;QACrE,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;IAClE,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QAC/B,GAAG,UAAU,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC,CAAC,UAAU,CAAC;QACvC,GAAG,EAAE,CAAC,CAAC,GAAG;KACX,CAAC,CAAC,CAAC;AACN,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill loader — reads Claude-style Agent Skill folders from disk. NODE ONLY.
|
|
3
|
+
*
|
|
4
|
+
* Import from `@kaleidorg/mind/skills` on Node hosts (desktop sidecar,
|
|
5
|
+
* kaleidoagent). React Native has no filesystem — there, build skills with
|
|
6
|
+
* `SkillRegistry.addMarkdown(text, references)` from bundled strings instead.
|
|
7
|
+
*
|
|
8
|
+
* Layout (Anthropic Agent Skills spec, e.g. bitrefill/agents):
|
|
9
|
+
*
|
|
10
|
+
* skills/
|
|
11
|
+
* bitrefill/
|
|
12
|
+
* SKILL.md
|
|
13
|
+
* references/
|
|
14
|
+
* mcp.md
|
|
15
|
+
* cli.md
|
|
16
|
+
* …
|
|
17
|
+
*
|
|
18
|
+
* `loadSkillsDir(root)` returns one Skill per SKILL.md found, with every
|
|
19
|
+
* reference markdown read into `skill.references` for progressive disclosure.
|
|
20
|
+
*/
|
|
21
|
+
import type { Skill } from './types.js';
|
|
22
|
+
/**
|
|
23
|
+
* Absolute path to the skills shipped inside this package
|
|
24
|
+
* (`@kaleidorg/mind/skills`). Resolves relative to the compiled loader, so it
|
|
25
|
+
* works from any host that installs the package. Override with an explicit dir
|
|
26
|
+
* when you keep skills elsewhere.
|
|
27
|
+
*/
|
|
28
|
+
export declare function packagedSkillsDir(): string;
|
|
29
|
+
/** Load one skill folder containing a SKILL.md (+ optional references/). */
|
|
30
|
+
export declare function loadSkillFromDir(dir: string): Skill;
|
|
31
|
+
/** Load every skill folder under `root` (each a dir with a SKILL.md). */
|
|
32
|
+
export declare function loadSkillsDir(root: string): Skill[];
|
|
33
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../../src/skills/loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAKH,OAAO,KAAK,EAAE,KAAK,EAAkB,MAAM,YAAY,CAAC;AAGxD;;;;;GAKG;AACH,wBAAgB,iBAAiB,IAAI,MAAM,CAG1C;AAED,4EAA4E;AAC5E,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,KAAK,CAcnD;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,CAMnD"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill loader — reads Claude-style Agent Skill folders from disk. NODE ONLY.
|
|
3
|
+
*
|
|
4
|
+
* Import from `@kaleidorg/mind/skills` on Node hosts (desktop sidecar,
|
|
5
|
+
* kaleidoagent). React Native has no filesystem — there, build skills with
|
|
6
|
+
* `SkillRegistry.addMarkdown(text, references)` from bundled strings instead.
|
|
7
|
+
*
|
|
8
|
+
* Layout (Anthropic Agent Skills spec, e.g. bitrefill/agents):
|
|
9
|
+
*
|
|
10
|
+
* skills/
|
|
11
|
+
* bitrefill/
|
|
12
|
+
* SKILL.md
|
|
13
|
+
* references/
|
|
14
|
+
* mcp.md
|
|
15
|
+
* cli.md
|
|
16
|
+
* …
|
|
17
|
+
*
|
|
18
|
+
* `loadSkillsDir(root)` returns one Skill per SKILL.md found, with every
|
|
19
|
+
* reference markdown read into `skill.references` for progressive disclosure.
|
|
20
|
+
*/
|
|
21
|
+
import { readdirSync, readFileSync, existsSync } from 'node:fs';
|
|
22
|
+
import { join } from 'node:path';
|
|
23
|
+
import { fileURLToPath } from 'node:url';
|
|
24
|
+
import { parseSkill } from './registry.js';
|
|
25
|
+
/**
|
|
26
|
+
* Absolute path to the skills shipped inside this package
|
|
27
|
+
* (`@kaleidorg/mind/skills`). Resolves relative to the compiled loader, so it
|
|
28
|
+
* works from any host that installs the package. Override with an explicit dir
|
|
29
|
+
* when you keep skills elsewhere.
|
|
30
|
+
*/
|
|
31
|
+
export function packagedSkillsDir() {
|
|
32
|
+
// dist/skills/loader.js → ../../skills == <package root>/skills
|
|
33
|
+
return fileURLToPath(new URL('../../skills/', import.meta.url));
|
|
34
|
+
}
|
|
35
|
+
/** Load one skill folder containing a SKILL.md (+ optional references/). */
|
|
36
|
+
export function loadSkillFromDir(dir) {
|
|
37
|
+
const skillFile = join(dir, 'SKILL.md');
|
|
38
|
+
if (!existsSync(skillFile))
|
|
39
|
+
throw new Error(`No SKILL.md in ${dir}`);
|
|
40
|
+
const markdown = readFileSync(skillFile, 'utf8');
|
|
41
|
+
const refDir = join(dir, 'references');
|
|
42
|
+
const references = existsSync(refDir)
|
|
43
|
+
? readdirSync(refDir)
|
|
44
|
+
.filter((f) => f.endsWith('.md'))
|
|
45
|
+
.sort()
|
|
46
|
+
.map((name) => ({ name, content: readFileSync(join(refDir, name), 'utf8') }))
|
|
47
|
+
: [];
|
|
48
|
+
return { ...parseSkill(markdown, references), dir };
|
|
49
|
+
}
|
|
50
|
+
/** Load every skill folder under `root` (each a dir with a SKILL.md). */
|
|
51
|
+
export function loadSkillsDir(root) {
|
|
52
|
+
if (!existsSync(root))
|
|
53
|
+
return [];
|
|
54
|
+
return readdirSync(root, { withFileTypes: true })
|
|
55
|
+
.filter((e) => e.isDirectory() && existsSync(join(root, e.name, 'SKILL.md')))
|
|
56
|
+
.sort((a, b) => a.name.localeCompare(b.name))
|
|
57
|
+
.map((e) => loadSkillFromDir(join(root, e.name)));
|
|
58
|
+
}
|
|
59
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -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CAAC,CAAC;QACjF,CAAC,CAAC,EAAE,CAAC;IAEP,OAAO,EAAE,GAAG,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,EAAE,GAAG,EAAE,CAAC;AACtD,CAAC;AAED,yEAAyE;AACzE,MAAM,UAAU,aAAa,CAAC,IAAY;IACxC,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IACjC,OAAO,WAAW,CAAC,IAAI,EAAE,EAAE,aAAa,EAAE,IAAI,EAAE,CAAC;SAC9C,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC;SAC5E,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC;SAC5C,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,gBAAgB,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AACtD,CAAC"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill reference tool source — the read-side of Agent-Skills progressive
|
|
3
|
+
* disclosure.
|
|
4
|
+
*
|
|
5
|
+
* Exposes one tool, `read_skill_reference({ file, skill? })`, that returns the
|
|
6
|
+
* contents of a `references/*.md` file bundled with a skill. The brain enters a
|
|
7
|
+
* skill (its SKILL.md playbook lists the reference files), then pulls in only
|
|
8
|
+
* the reference it needs for the current step — instead of every doc being in
|
|
9
|
+
* context at once.
|
|
10
|
+
*
|
|
11
|
+
* Pure in-process: it reads from the SkillRegistry's already-loaded reference
|
|
12
|
+
* strings, so it works on every host (React Native included) once the skills
|
|
13
|
+
* are loaded. No filesystem, no network.
|
|
14
|
+
*/
|
|
15
|
+
import type { ToolSource } from '../tools/source.js';
|
|
16
|
+
import { SkillRegistry } from './registry.js';
|
|
17
|
+
export declare function createSkillReferenceToolSource(registry: SkillRegistry): ToolSource;
|
|
18
|
+
//# sourceMappingURL=reference-source.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-source.d.ts","sourceRoot":"","sources":["../../src/skills/reference-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,aAAa,EAAuB,MAAM,eAAe,CAAC;AAEnE,wBAAgB,8BAA8B,CAAC,QAAQ,EAAE,aAAa,GAAG,UAAU,CAwClF"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill reference tool source — the read-side of Agent-Skills progressive
|
|
3
|
+
* disclosure.
|
|
4
|
+
*
|
|
5
|
+
* Exposes one tool, `read_skill_reference({ file, skill? })`, that returns the
|
|
6
|
+
* contents of a `references/*.md` file bundled with a skill. The brain enters a
|
|
7
|
+
* skill (its SKILL.md playbook lists the reference files), then pulls in only
|
|
8
|
+
* the reference it needs for the current step — instead of every doc being in
|
|
9
|
+
* context at once.
|
|
10
|
+
*
|
|
11
|
+
* Pure in-process: it reads from the SkillRegistry's already-loaded reference
|
|
12
|
+
* strings, so it works on every host (React Native included) once the skills
|
|
13
|
+
* are loaded. No filesystem, no network.
|
|
14
|
+
*/
|
|
15
|
+
import { READ_REFERENCE_TOOL } from './registry.js';
|
|
16
|
+
export function createSkillReferenceToolSource(registry) {
|
|
17
|
+
const tool = {
|
|
18
|
+
name: READ_REFERENCE_TOOL,
|
|
19
|
+
description: 'Read a reference document bundled with the active skill (its SKILL.md ' +
|
|
20
|
+
'lists the available files). Use this to pull in the detailed instructions ' +
|
|
21
|
+
'for a step — e.g. the MCP, CLI, or API guide — before acting.',
|
|
22
|
+
parameters: {
|
|
23
|
+
type: 'object',
|
|
24
|
+
properties: {
|
|
25
|
+
file: { type: 'string', description: 'Reference filename, e.g. "mcp.md"' },
|
|
26
|
+
skill: { type: 'string', description: 'Optional skill name to scope the lookup' },
|
|
27
|
+
},
|
|
28
|
+
required: ['file'],
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
async function execute(_name, args) {
|
|
32
|
+
const file = String(args.file ?? '').trim();
|
|
33
|
+
if (!file)
|
|
34
|
+
throw new Error('read_skill_reference: file is required');
|
|
35
|
+
const skill = args.skill ? String(args.skill) : undefined;
|
|
36
|
+
const ref = registry.reference(file, skill);
|
|
37
|
+
if (!ref) {
|
|
38
|
+
const available = registry
|
|
39
|
+
.references()
|
|
40
|
+
.map((r) => `${r.skill}/${r.name}`)
|
|
41
|
+
.join(', ');
|
|
42
|
+
throw new Error(`read_skill_reference: "${file}" not found. Available: ${available || '(none)'}`);
|
|
43
|
+
}
|
|
44
|
+
return ref.content;
|
|
45
|
+
}
|
|
46
|
+
return {
|
|
47
|
+
id: 'skill-references',
|
|
48
|
+
listTools: () => [tool],
|
|
49
|
+
has: (name) => name === READ_REFERENCE_TOOL,
|
|
50
|
+
execute,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=reference-source.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"reference-source.js","sourceRoot":"","sources":["../../src/skills/reference-source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAIH,OAAO,EAAiB,mBAAmB,EAAE,MAAM,eAAe,CAAC;AAEnE,MAAM,UAAU,8BAA8B,CAAC,QAAuB;IACpE,MAAM,IAAI,GAAY;QACpB,IAAI,EAAE,mBAAmB;QACzB,WAAW,EACT,wEAAwE;YACxE,4EAA4E;YAC5E,+DAA+D;QACjE,UAAU,EAAE;YACV,IAAI,EAAE,QAAQ;YACd,UAAU,EAAE;gBACV,IAAI,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,WAA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ds skills, parses SKILL.md files, selects per query, and
|
|
3
|
+
* composes the system prompt for the selected skill.
|
|
4
|
+
*
|
|
5
|
+
* Selection is pluggable. The default is a fast keyword heuristic (no model
|
|
6
|
+
* call); a host can inject a model-driven or embedding selector instead.
|
|
7
|
+
*/
|
|
8
|
+
import type { Skill, SkillReference, SkillSelector } from './types.js';
|
|
9
|
+
/** Tool name the reference source exposes for progressive disclosure. */
|
|
10
|
+
export declare const READ_REFERENCE_TOOL = "read_skill_reference";
|
|
11
|
+
export declare function parseSkill(markdown: string, references?: SkillReference[]): Skill;
|
|
12
|
+
/** Default selector: score by meaningful keyword overlap; triggers weigh most. */
|
|
13
|
+
export declare const keywordSelector: SkillSelector;
|
|
14
|
+
export declare class SkillRegistry {
|
|
15
|
+
private readonly skills;
|
|
16
|
+
private readonly selector;
|
|
17
|
+
constructor(skills?: Skill[], selector?: SkillSelector);
|
|
18
|
+
add(skill: Skill): this;
|
|
19
|
+
/** Add a skill from raw SKILL.md text (+ optional reference files). */
|
|
20
|
+
addMarkdown(markdown: string, references?: SkillReference[]): this;
|
|
21
|
+
/** All reference files across skills, tagged with their owning skill. */
|
|
22
|
+
references(): Array<SkillReference & {
|
|
23
|
+
skill: string;
|
|
24
|
+
}>;
|
|
25
|
+
/** Look up a reference file by name (optionally scoped to one skill). */
|
|
26
|
+
reference(file: string, skill?: string): SkillReference | undefined;
|
|
27
|
+
list(): Skill[];
|
|
28
|
+
get(name: string): Skill | undefined;
|
|
29
|
+
/** Pick the most relevant skill for a query (null = none). */
|
|
30
|
+
select(query: string): Skill | null;
|
|
31
|
+
/**
|
|
32
|
+
* Compose the effective system prompt for a skill: the base prompt + the
|
|
33
|
+
* skill's playbook. The returned `allowedTools` should be passed to
|
|
34
|
+
* `engine.runAgentic(..., { allowedTools })` for progressive tool disclosure.
|
|
35
|
+
*/
|
|
36
|
+
compose(base: string, skill: Skill | null): {
|
|
37
|
+
system: string;
|
|
38
|
+
allowedTools?: string[];
|
|
39
|
+
};
|
|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