@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,167 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SkillRegistry — holds 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
|
+
/** Tool name the reference source exposes for progressive disclosure. */
|
|
9
|
+
export const READ_REFERENCE_TOOL = 'read_skill_reference';
|
|
10
|
+
/**
|
|
11
|
+
* Parse a SKILL.md file: a YAML-ish frontmatter block (name/description/tools/
|
|
12
|
+
* triggers) followed by the instruction body.
|
|
13
|
+
*
|
|
14
|
+
* ---
|
|
15
|
+
* name: portfolio-manager
|
|
16
|
+
* description: Rebalance BTC/USDT/XAUT to target allocations.
|
|
17
|
+
* tools: get_balance, kaleidoswap_get_quote, kaleidoswap_place_order
|
|
18
|
+
* triggers: rebalance, allocation, portfolio
|
|
19
|
+
* ---
|
|
20
|
+
* <instructions…>
|
|
21
|
+
*/
|
|
22
|
+
/** Strip wrapping single/double quotes from a frontmatter value. */
|
|
23
|
+
function unquote(v) {
|
|
24
|
+
const t = v.trim();
|
|
25
|
+
if ((t.startsWith('"') && t.endsWith('"')) || (t.startsWith("'") && t.endsWith("'"))) {
|
|
26
|
+
return t.slice(1, -1);
|
|
27
|
+
}
|
|
28
|
+
return t;
|
|
29
|
+
}
|
|
30
|
+
export function parseSkill(markdown, references) {
|
|
31
|
+
const fm = markdown.match(/^---\s*\n([\s\S]*?)\n---\s*\n?([\s\S]*)$/);
|
|
32
|
+
const meta = {};
|
|
33
|
+
let body = markdown;
|
|
34
|
+
if (fm) {
|
|
35
|
+
body = fm[2] ?? '';
|
|
36
|
+
for (const line of (fm[1] ?? '').split('\n')) {
|
|
37
|
+
// Flat `key: value` lines (incl. indented keys under a nested `metadata:`
|
|
38
|
+
// block, which fold into the same map — we don't need YAML nesting here).
|
|
39
|
+
const m = line.match(/^\s*([A-Za-z_][\w-]*)\s*:\s*(.+?)\s*$/);
|
|
40
|
+
if (m && m[1])
|
|
41
|
+
meta[m[1].toLowerCase()] = unquote(m[2] ?? '');
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
const list = (v) => v
|
|
45
|
+
? v.split(',').map((s) => s.trim()).filter(Boolean)
|
|
46
|
+
: undefined;
|
|
47
|
+
if (!meta.name)
|
|
48
|
+
throw new Error('SKILL.md missing `name` in frontmatter');
|
|
49
|
+
// Everything that isn't a first-class field becomes metadata.
|
|
50
|
+
const KNOWN = new Set(['name', 'description', 'tools', 'triggers']);
|
|
51
|
+
const metadata = {};
|
|
52
|
+
for (const [k, v] of Object.entries(meta))
|
|
53
|
+
if (!KNOWN.has(k))
|
|
54
|
+
metadata[k] = v;
|
|
55
|
+
return {
|
|
56
|
+
name: meta.name,
|
|
57
|
+
description: meta.description ?? '',
|
|
58
|
+
instructions: body.trim(),
|
|
59
|
+
tools: list(meta.tools),
|
|
60
|
+
triggers: list(meta.triggers),
|
|
61
|
+
metadata: Object.keys(metadata).length ? metadata : undefined,
|
|
62
|
+
references: references && references.length ? references : undefined,
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Common words that shouldn't count toward a skill match.
|
|
66
|
+
const STOPWORDS = new Set([
|
|
67
|
+
'the', 'and', 'for', 'you', 'your', 'what', 'this', 'that', 'with', 'from',
|
|
68
|
+
'have', 'has', 'are', 'was', 'can', 'will', 'please', 'today', 'now', 'get',
|
|
69
|
+
'show', 'tell', 'how', 'much', 'many', 'about', 'into', 'over',
|
|
70
|
+
]);
|
|
71
|
+
/** Default selector: score by meaningful keyword overlap; triggers weigh most. */
|
|
72
|
+
export const keywordSelector = {
|
|
73
|
+
select(query, skills) {
|
|
74
|
+
const q = query.toLowerCase();
|
|
75
|
+
const words = new Set(q.split(/\W+/).filter((w) => w.length > 2 && !STOPWORDS.has(w)));
|
|
76
|
+
let best = null;
|
|
77
|
+
let bestScore = 0;
|
|
78
|
+
for (const skill of skills) {
|
|
79
|
+
const haystack = `${skill.description} ${(skill.triggers ?? []).join(' ')}`.toLowerCase();
|
|
80
|
+
const hayWords = haystack.split(/\W+/).filter((w) => w.length > 2 && !STOPWORDS.has(w));
|
|
81
|
+
let score = 0;
|
|
82
|
+
for (const w of hayWords)
|
|
83
|
+
if (words.has(w))
|
|
84
|
+
score += 1;
|
|
85
|
+
// Strong boost for an explicit trigger appearing in the query.
|
|
86
|
+
for (const t of skill.triggers ?? [])
|
|
87
|
+
if (q.includes(t.toLowerCase()))
|
|
88
|
+
score += 3;
|
|
89
|
+
if (score > bestScore) {
|
|
90
|
+
bestScore = score;
|
|
91
|
+
best = skill;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Require a real signal, not a single incidental word overlap.
|
|
95
|
+
return bestScore >= 2 ? best : null;
|
|
96
|
+
},
|
|
97
|
+
};
|
|
98
|
+
export class SkillRegistry {
|
|
99
|
+
skills = [];
|
|
100
|
+
selector;
|
|
101
|
+
constructor(skills = [], selector = keywordSelector) {
|
|
102
|
+
this.skills = [...skills];
|
|
103
|
+
this.selector = selector;
|
|
104
|
+
}
|
|
105
|
+
add(skill) {
|
|
106
|
+
this.skills.push(skill);
|
|
107
|
+
return this;
|
|
108
|
+
}
|
|
109
|
+
/** Add a skill from raw SKILL.md text (+ optional reference files). */
|
|
110
|
+
addMarkdown(markdown, references) {
|
|
111
|
+
return this.add(parseSkill(markdown, references));
|
|
112
|
+
}
|
|
113
|
+
/** All reference files across skills, tagged with their owning skill. */
|
|
114
|
+
references() {
|
|
115
|
+
return this.skills.flatMap((s) => (s.references ?? []).map((r) => ({ ...r, skill: s.name })));
|
|
116
|
+
}
|
|
117
|
+
/** Look up a reference file by name (optionally scoped to one skill). */
|
|
118
|
+
reference(file, skill) {
|
|
119
|
+
const base = file.replace(/^references\//, '');
|
|
120
|
+
for (const s of this.skills) {
|
|
121
|
+
if (skill && s.name !== skill)
|
|
122
|
+
continue;
|
|
123
|
+
const hit = (s.references ?? []).find((r) => r.name === base || r.name === file);
|
|
124
|
+
if (hit)
|
|
125
|
+
return hit;
|
|
126
|
+
}
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
129
|
+
list() {
|
|
130
|
+
return [...this.skills];
|
|
131
|
+
}
|
|
132
|
+
get(name) {
|
|
133
|
+
return this.skills.find((s) => s.name === name);
|
|
134
|
+
}
|
|
135
|
+
/** Pick the most relevant skill for a query (null = none). */
|
|
136
|
+
select(query) {
|
|
137
|
+
return this.selector.select(query, this.skills);
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Compose the effective system prompt for a skill: the base prompt + the
|
|
141
|
+
* skill's playbook. The returned `allowedTools` should be passed to
|
|
142
|
+
* `engine.runAgentic(..., { allowedTools })` for progressive tool disclosure.
|
|
143
|
+
*/
|
|
144
|
+
compose(base, skill) {
|
|
145
|
+
if (!skill)
|
|
146
|
+
return { system: base };
|
|
147
|
+
let system = `${base}\n\n## Active skill: ${skill.name}\n${skill.instructions}`.trim();
|
|
148
|
+
// Progressive disclosure: tell the model the reference files exist and how
|
|
149
|
+
// to pull one in, rather than dumping them all into context.
|
|
150
|
+
const refs = skill.references ?? [];
|
|
151
|
+
if (refs.length) {
|
|
152
|
+
const names = refs.map((r) => r.name).join(', ');
|
|
153
|
+
system +=
|
|
154
|
+
`\n\n## Reference files\nThis skill has detailed reference docs: ${names}. ` +
|
|
155
|
+
`When you need the detail for a step, call \`${READ_REFERENCE_TOOL}\` with the ` +
|
|
156
|
+
`filename (e.g. {"file":"${refs[0].name}"}) to read it before acting.`;
|
|
157
|
+
}
|
|
158
|
+
// When the skill scopes tools, keep the reference reader reachable too.
|
|
159
|
+
const allowedTools = skill.tools
|
|
160
|
+
? refs.length
|
|
161
|
+
? [...skill.tools, READ_REFERENCE_TOOL]
|
|
162
|
+
: skill.tools
|
|
163
|
+
: undefined;
|
|
164
|
+
return { system, allowedTools };
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
//# sourceMappingURL=registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/skills/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH,yEAAyE;AACzE,MAAM,CAAC,MAAM,mBAAmB,GAAG,sBAAsB,CAAC;AAE1D;;;;;;;;;;;GAWG;AACH,oEAAoE;AACpE,SAAS,OAAO,CAAC,CAAS;IACxB,MAAM,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,CAAC;IACnB,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,UAAU,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC;QACrF,OAAO,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxB,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,MAAM,UAAU,UAAU,CAAC,QAAgB,EAAE,UAA6B;IACxE,MAAM,EAAE,GAAG,QAAQ,CAAC,KAAK,CAAC,0CAA0C,CAAC,CAAC;IACtE,MAAM,IAAI,GAA2B,EAAE,CAAC;IACxC,IAAI,IAAI,GAAG,QAAQ,CAAC;IACpB,IAAI,EAAE,EAAE,CAAC;QACP,IAAI,GAAG,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC;QACnB,KAAK,MAAM,IAAI,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,C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of tool use: a folder with a `SKILL.md` (YAML
|
|
5
|
+
* frontmatter + a markdown playbook) and optional `references/*.md` files that
|
|
6
|
+
* are loaded on demand. Entering a skill injects its playbook into the system
|
|
7
|
+
* prompt and (optionally) scopes the agent to a subset of tools. The tools are
|
|
8
|
+
* still invoked via function calling and may be backed by in-process handlers
|
|
9
|
+
* or MCP servers — skills don't replace those, they *direct* them.
|
|
10
|
+
*
|
|
11
|
+
* This is progressive disclosure, the core idea behind Anthropic's Agent Skills:
|
|
12
|
+
* a small local model never sees every tool or instruction at once — only the
|
|
13
|
+
* selected skill's playbook, and it can pull a reference file in when it needs
|
|
14
|
+
* the detail. The format is compatible with skills published for Claude (e.g.
|
|
15
|
+
* `bitrefill/agents`), so the same SKILL.md runs the QVAC brain unchanged.
|
|
16
|
+
*/
|
|
17
|
+
/** A reference file (references/*.md) the agent can read on demand. */
|
|
18
|
+
export interface SkillReference {
|
|
19
|
+
/** Filename, e.g. "mcp.md". */
|
|
20
|
+
name: string;
|
|
21
|
+
/** Markdown contents. */
|
|
22
|
+
content: string;
|
|
23
|
+
}
|
|
24
|
+
export interface Skill {
|
|
25
|
+
/** Stable id, e.g. "bitrefill" / "portfolio-manager". */
|
|
26
|
+
name: string;
|
|
27
|
+
/**
|
|
28
|
+
* "When to use this" — the spec's selection signal. May be long and embed the
|
|
29
|
+
* trigger phrases ("…Triggers when the user mentions gift cards, eSIM…").
|
|
30
|
+
*/
|
|
31
|
+
description: string;
|
|
32
|
+
/** The playbook: markdown instructions injected into the system prompt. */
|
|
33
|
+
instructions: string;
|
|
34
|
+
/**
|
|
35
|
+
* Tool names this skill is allowed to use. When set, the engine exposes only
|
|
36
|
+
* these tools while the skill is active (progressive disclosure). Omit to
|
|
37
|
+
* allow all registered tools (the default for capability-routing skills).
|
|
38
|
+
*/
|
|
39
|
+
tools?: string[];
|
|
40
|
+
/** Optional trigger keywords to boost selection (in addition to description). */
|
|
41
|
+
triggers?: string[];
|
|
42
|
+
/** Remaining frontmatter (compatibility, author, version, homepage, …). */
|
|
43
|
+
metadata?: Record<string, string>;
|
|
44
|
+
/** Reference files (references/*.md) for progressive disclosure. */
|
|
45
|
+
references?: SkillReference[];
|
|
46
|
+
/** Source folder, when loaded from disk (Node). */
|
|
47
|
+
dir?: string;
|
|
48
|
+
}
|
|
49
|
+
/** Picks the most relevant skill for a query (or null for none). */
|
|
50
|
+
export interface SkillSelector {
|
|
51
|
+
select(query: string, skills: Skill[]): Skill | null;
|
|
52
|
+
}
|
|
53
|
+
//# sourceMappingURL=types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/skills/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,uEAAuE;AACvE,MAAM,WAAW,cAAc;IAC7B,+BAA+B;IAC/B,IAAI,EAAE,MAAM,CAAC;IACb,yBAAyB;IACzB,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,KAAK;IACpB,yDAAyD;IACzD,IAAI,EAAE,MAAM,CAAC;IACb;;;OAGG;IACH,WAAW,EAAE,MAAM,CAAC;IACpB,2EAA2E;IAC3E,YAAY,EAAE,MAAM,CAAC;IACrB;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,EAAE,CAAC;IACjB,iFAAiF;IACjF,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,2EAA2E;IAC3E,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAClC,oEAAoE;IACpE,UAAU,CAAC,EAAE,cAAc,EAAE,CAAC;IAC9B,mDAAmD;IACnD,GAAG,CAAC,EAAE,MAAM,CAAC;CACd;AAED,oEAAoE;AACpE,MAAM,WAAW,aAAa;IAC5B,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,KAAK,GAAG,IAAI,CAAC;CACtD"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skills — Claude-style Agent Skills the brain can "enter".
|
|
3
|
+
*
|
|
4
|
+
* A skill is the top layer of tool use: a folder with a `SKILL.md` (YAML
|
|
5
|
+
* frontmatter + a markdown playbook) and optional `references/*.md` files that
|
|
6
|
+
* are loaded on demand. Entering a skill injects its playbook into the system
|
|
7
|
+
* prompt and (optionally) scopes the agent to a subset of tools. The tools are
|
|
8
|
+
* still invoked via function calling and may be backed by in-process handlers
|
|
9
|
+
* or MCP servers — skills don't replace those, they *direct* them.
|
|
10
|
+
*
|
|
11
|
+
* This is progressive disclosure, the core idea behind Anthropic's Agent Skills:
|
|
12
|
+
* a small local model never sees every tool or instruction at once — only the
|
|
13
|
+
* selected skill's playbook, and it can pull a reference file in when it needs
|
|
14
|
+
* the detail. The format is compatible with skills published for Claude (e.g.
|
|
15
|
+
* `bitrefill/agents`), so the same SKILL.md runs the QVAC brain unchanged.
|
|
16
|
+
*/
|
|
17
|
+
export {};
|
|
18
|
+
//# sourceMappingURL=types.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/skills/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG"}
|
|
@@ -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
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GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,GAAG;QAC3B,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L402 tool source — lets the agent pay for paywalled HTTP resources in sats.
|
|
3
|
+
*
|
|
4
|
+
* Exposes one tool, `fetch_paid_resource(url)`, that runs the L402 flow:
|
|
5
|
+
* GET url → 402 with an L402 challenge (macaroon + Lightning invoice)
|
|
6
|
+
* → pay the invoice (via the injected `payInvoice`, e.g. the on-device wallet)
|
|
7
|
+
* → re-GET with `Authorization: L402 <macaroon>:<preimage>` → return the body.
|
|
8
|
+
*
|
|
9
|
+
* This is the "agent pays for a tool in sats" capability: any KaleidoMind agent
|
|
10
|
+
* (mobile or desktop) can buy premium data / inference autonomously. Payment
|
|
11
|
+
* runs through the host's wallet, so it stays on-device; the engine's
|
|
12
|
+
* confirmation gate can wrap the spend if desired.
|
|
13
|
+
*
|
|
14
|
+
* No dependencies — uses global fetch (Node ≥18, React Native). The fetch impl
|
|
15
|
+
* is injectable for testing.
|
|
16
|
+
*/
|
|
17
|
+
import type { ToolSource } from './source.js';
|
|
18
|
+
export interface L402PayResult {
|
|
19
|
+
/** Payment preimage (hex) — proves the invoice was paid. */
|
|
20
|
+
preimage: string;
|
|
21
|
+
}
|
|
22
|
+
export interface L402Options {
|
|
23
|
+
/** Pay a BOLT11 invoice, resolve with the preimage. Wallet on device; mock in tests. */
|
|
24
|
+
payInvoice: (invoice: string, amountSats: number) => Promise<L402PayResult>;
|
|
25
|
+
/** Override fetch (tests). Defaults to global fetch. */
|
|
26
|
+
fetchImpl?: typeof fetch;
|
|
27
|
+
/** Optional progress logging. */
|
|
28
|
+
log?: (msg: string) => void;
|
|
29
|
+
/**
|
|
30
|
+
* Gate the tool behind the engine's confirmation (default true). The catch:
|
|
31
|
+
* the invoice amount is only known DURING execution (the 402 challenge), so a
|
|
32
|
+
* pre-execution confirmation can't show it. On hosts without a dedicated L402
|
|
33
|
+
* confirmation UX, set this false and bound spending with `maxAutoPaySats`.
|
|
34
|
+
*/
|
|
35
|
+
requiresConfirmation?: boolean;
|
|
36
|
+
/** Auto-pay only invoices up to this many sats; reject larger ones. */
|
|
37
|
+
maxAutoPaySats?: number;
|
|
38
|
+
}
|
|
39
|
+
/** Parse an L402 (or legacy LSAT) WWW-Authenticate challenge. */
|
|
40
|
+
export declare function parseL402Challenge(header: string): {
|
|
41
|
+
macaroon: string;
|
|
42
|
+
invoice: string;
|
|
43
|
+
} | null;
|
|
44
|
+
/** Rough BOLT11 amount → sats (for logging / spend caps). 0 if unparseable. */
|
|
45
|
+
export declare function bolt11AmountSats(invoice: string): number;
|
|
46
|
+
export declare function createL402ToolSource(opts: L402Options): ToolSource;
|
|
47
|
+
//# sourceMappingURL=l402.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l402.d.ts","sourceRoot":"","sources":["../../src/tools/l402.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,aAAa;IAC5B,4DAA4D;IAC5D,QAAQ,EAAE,MAAM,CAAC;CAClB;AAED,MAAM,WAAW,WAAW;IAC1B,wFAAwF;IACxF,UAAU,EAAE,CAAC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,OAAO,CAAC,aAAa,CAAC,CAAC;IAC5E,wDAAwD;IACxD,SAAS,CAAC,EAAE,OAAO,KAAK,CAAC;IACzB,iCAAiC;IACjC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC5B;;;;;OAKG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,uEAAuE;IACvE,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED,iEAAiE;AACjE,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG;IAAE,QAAQ,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GAAG,IAAI,CAI/F;AAED,+EAA+E;AAC/E,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAOxD;AAED,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,WAAW,GAAG,UAAU,CA6DlE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* L402 tool source — lets the agent pay for paywalled HTTP resources in sats.
|
|
3
|
+
*
|
|
4
|
+
* Exposes one tool, `fetch_paid_resource(url)`, that runs the L402 flow:
|
|
5
|
+
* GET url → 402 with an L402 challenge (macaroon + Lightning invoice)
|
|
6
|
+
* → pay the invoice (via the injected `payInvoice`, e.g. the on-device wallet)
|
|
7
|
+
* → re-GET with `Authorization: L402 <macaroon>:<preimage>` → return the body.
|
|
8
|
+
*
|
|
9
|
+
* This is the "agent pays for a tool in sats" capability: any KaleidoMind agent
|
|
10
|
+
* (mobile or desktop) can buy premium data / inference autonomously. Payment
|
|
11
|
+
* runs through the host's wallet, so it stays on-device; the engine's
|
|
12
|
+
* confirmation gate can wrap the spend if desired.
|
|
13
|
+
*
|
|
14
|
+
* No dependencies — uses global fetch (Node ≥18, React Native). The fetch impl
|
|
15
|
+
* is injectable for testing.
|
|
16
|
+
*/
|
|
17
|
+
/** Parse an L402 (or legacy LSAT) WWW-Authenticate challenge. */
|
|
18
|
+
export function parseL402Challenge(header) {
|
|
19
|
+
const macaroon = header.match(/macaroon="([^"]+)"/i)?.[1];
|
|
20
|
+
const invoice = header.match(/invoice="([^"]+)"/i)?.[1];
|
|
21
|
+
return macaroon && invoice ? { macaroon, invoice } : null;
|
|
22
|
+
}
|
|
23
|
+
/** Rough BOLT11 amount → sats (for logging / spend caps). 0 if unparseable. */
|
|
24
|
+
export function bolt11AmountSats(invoice) {
|
|
25
|
+
const m = invoice.match(/^ln(?:bc|tb|bcrt)(\d+)([munp]?)/i);
|
|
26
|
+
if (!m)
|
|
27
|
+
return 0;
|
|
28
|
+
const n = Number(m[1]);
|
|
29
|
+
const mult = (m[2] || '').toLowerCase();
|
|
30
|
+
const btc = mult === 'm' ? n / 1e3 : mult === 'u' ? n / 1e6 : mult === 'n' ? n / 1e9 : mult === 'p' ? n / 1e12 : n;
|
|
31
|
+
return Math.round(btc * 1e8);
|
|
32
|
+
}
|
|
33
|
+
export function createL402ToolSource(opts) {
|
|
34
|
+
const doFetch = opts.fetchImpl ?? fetch;
|
|
35
|
+
const tool = {
|
|
36
|
+
name: 'fetch_paid_resource',
|
|
37
|
+
description: 'Fetch a paywalled (L402) HTTP resource, automatically paying the required ' +
|
|
38
|
+
'Lightning invoice in sats. Use this for premium or paid APIs (market data, ' +
|
|
39
|
+
'inference, etc.). Pass the resource URL.',
|
|
40
|
+
parameters: {
|
|
41
|
+
type: 'object',
|
|
42
|
+
properties: { url: { type: 'string', description: 'The resource URL to fetch' } },
|
|
43
|
+
required: ['url'],
|
|
44
|
+
},
|
|
45
|
+
requiresConfirmation: opts.requiresConfirmation ?? true,
|
|
46
|
+
};
|
|
47
|
+
async function execute(_name, args) {
|
|
48
|
+
const url = String(args.url ?? '');
|
|
49
|
+
if (!url)
|
|
50
|
+
throw new Error('fetch_paid_resource: url is required');
|
|
51
|
+
let res = await doFetch(url);
|
|
52
|
+
if (res.status === 402) {
|
|
53
|
+
const challenge = parseL402Challenge(res.headers.get('www-authenticate') ?? '');
|
|
54
|
+
if (!challenge)
|
|
55
|
+
throw new Error('402 Payment Required but no L402 challenge present');
|
|
56
|
+
const amountSats = bolt11AmountSats(challenge.invoice) || Number(res.headers.get('x-amount-sats') ?? 0);
|
|
57
|
+
if (opts.maxAutoPaySats != null && amountSats > opts.maxAutoPaySats) {
|
|
58
|
+
throw new Error(`L402 invoice is ${amountSats} sats, above the ${opts.maxAutoPaySats} sat auto-pay cap — declined`);
|
|
59
|
+
}
|
|
60
|
+
opts.log?.(`L402: ${url} requires ${amountSats} sats — paying…`);
|
|
61
|
+
const { preimage } = await opts.payInvoice(challenge.invoice, amountSats);
|
|
62
|
+
res = await doFetch(url, {
|
|
63
|
+
headers: { Authorization: `L402 ${challenge.macaroon}:${preimage}` },
|
|
64
|
+
});
|
|
65
|
+
opts.log?.(`L402: paid ${amountSats} sats → ${res.status}`);
|
|
66
|
+
}
|
|
67
|
+
if (!res.ok)
|
|
68
|
+
throw new Error(`fetch_paid_resource: ${res.status} ${res.statusText}`);
|
|
69
|
+
const body = await res.text();
|
|
70
|
+
try {
|
|
71
|
+
return JSON.parse(body);
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return body;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
return {
|
|
78
|
+
id: 'l402',
|
|
79
|
+
listTools: () => [tool],
|
|
80
|
+
has: (name) => name === tool.name,
|
|
81
|
+
execute,
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=l402.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"l402.js","sourceRoot":"","sources":["../../src/tools/l402.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AA4BH,iEAAiE;AACjE,MAAM,UAAU,kBAAkB,CAAC,MAAc;IAC/C,MAAM,QAAQ,GAAG,MAAM,CAAC,KAAK,CAAC,qBAAqB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1D,MAAM,OAAO,GAAG,MAAM,CAAC,KAAK,CAAC,oBAAoB,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC;IACxD,OAAO,QAAQ,IAAI,OAAO,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;AAC5D,CAAC;AAED,+EAA+E;AAC/E,MAAM,UAAU,gBAAgB,CAAC,OAAe;IAC9C,MAAM,CAAC,GAAG,OAAO,CAAC,KAAK,CAAC,kCAAkC,C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,GAAG,CAAC,MAAM,IAAI,GAAG,CAAC,UAAU,EAAE,CAAC,CAAC;QACrF,MAAM,IAAI,GAAG,MAAM,GAAG,CAAC,IAAI,EAAE,CAAC;QAC9B,IAAI,CAAC;YACH,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC1B,CAAC;QAAC,MAAM,CAAC;YACP,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IAED,OAAO;QACL,EAAE,EAAE,MAAM;QACV,SAAS,EAAE,GAAG,EAAE,CAAC,CAAC,IAAI,CAAC;QACvB,GAAG,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI;QACjC,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":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;GAkBG;AAkBH,MAAM,OAAO,aAAa;IACf,EAAE,CAAS;IACH,IAAI,CAAuB;IACpC,MAAM,GAAe,IAAI,CAAC;IAC1B,KAAK,GAAc,EAAE,CAAC;IAE9B,YAAY,IAA0B;QACpC,IAAI,CAAC,EAAE,GAAG,IAAI,CAAC,EAAE,CAAC;QAClB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,+EAA+E;IAC/E,KAAK,CAAC,OAAO;QACX,6EAA6E;QAC7E,MAAM,EAAE,MAAM,EAAE,GAAG,MAAM,MAAM,CAAC,2CAA2C,CAAC,CAAC;QAC7E,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC;QAE9B,IAAI,SAAc,CAAC;QACnB,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,EAAE,CAAC;YACvB,MAAM,EAAE,oBAAoB,EAAE,GAAG,MAAM,MAAM,CAC3C,2CAA2C,CAC5C,CAAC;YACF,SAAS,GAAG,IAAI,oBAAoB,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,IAAI,EAAE,EAAE,GAAG,EAAE,CAAC,CAAC,GAAG,EAAE,CAAC,CAA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|
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;I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