@kaleidorg/mind 0.5.0 → 0.6.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/autonomy/index.d.ts +21 -0
- package/dist/autonomy/index.d.ts.map +1 -0
- package/dist/autonomy/index.js +16 -0
- package/dist/autonomy/index.js.map +1 -0
- package/dist/autonomy/prompt.d.ts +21 -0
- package/dist/autonomy/prompt.d.ts.map +1 -0
- package/dist/autonomy/prompt.js +37 -0
- package/dist/autonomy/prompt.js.map +1 -0
- package/dist/autonomy/risk.d.ts +53 -0
- package/dist/autonomy/risk.d.ts.map +1 -0
- package/dist/autonomy/risk.js +74 -0
- package/dist/autonomy/risk.js.map +1 -0
- package/dist/autonomy/run-state.d.ts +39 -0
- package/dist/autonomy/run-state.d.ts.map +1 -0
- package/dist/autonomy/run-state.js +118 -0
- package/dist/autonomy/run-state.js.map +1 -0
- package/dist/autonomy/scheduler.d.ts +18 -0
- package/dist/autonomy/scheduler.d.ts.map +1 -0
- package/dist/autonomy/scheduler.js +113 -0
- package/dist/autonomy/scheduler.js.map +1 -0
- package/dist/autonomy/task-store.d.ts +44 -0
- package/dist/autonomy/task-store.d.ts.map +1 -0
- package/dist/autonomy/task-store.js +139 -0
- package/dist/autonomy/task-store.js.map +1 -0
- package/dist/autonomy/types.d.ts +164 -0
- package/dist/autonomy/types.d.ts.map +1 -0
- package/dist/autonomy/types.js +20 -0
- package/dist/autonomy/types.js.map +1 -0
- package/dist/funnel.d.ts.map +1 -1
- package/dist/funnel.js +12 -0
- package/dist/funnel.js.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -0
- package/dist/index.js.map +1 -1
- package/dist/knowledge/bitcoin-copilot.js +2 -2
- package/dist/knowledge/bitcoin-copilot.js.map +1 -1
- package/dist/qvac/index.d.ts +1 -1
- package/dist/qvac/index.d.ts.map +1 -1
- package/dist/qvac/index.js.map +1 -1
- package/dist/qvac/parse.d.ts +33 -0
- package/dist/qvac/parse.d.ts.map +1 -1
- package/dist/qvac/parse.js +69 -5
- package/dist/qvac/parse.js.map +1 -1
- package/dist/qvac/provider.d.ts +16 -0
- package/dist/qvac/provider.d.ts.map +1 -1
- package/dist/qvac/provider.js +17 -1
- package/dist/qvac/provider.js.map +1 -1
- package/dist/qvac/stream.d.ts +16 -0
- package/dist/qvac/stream.d.ts.map +1 -1
- package/dist/qvac/stream.js +21 -1
- package/dist/qvac/stream.js.map +1 -1
- package/dist/qvac/text.d.ts.map +1 -1
- package/dist/qvac/text.js +4 -0
- package/dist/qvac/text.js.map +1 -1
- package/dist/recipe/buy-asset-channel.d.ts +1 -1
- package/dist/recipe/buy-asset-channel.d.ts.map +1 -1
- package/dist/recipe/buy-asset-channel.js +4 -3
- package/dist/recipe/buy-asset-channel.js.map +1 -1
- package/dist/recipe/kaleidoswap-atomic.d.ts +1 -1
- package/dist/recipe/kaleidoswap-atomic.d.ts.map +1 -1
- package/dist/recipe/kaleidoswap-atomic.js +5 -4
- package/dist/recipe/kaleidoswap-atomic.js.map +1 -1
- package/dist/recipe/runner.d.ts.map +1 -1
- package/dist/recipe/runner.js +38 -0
- package/dist/recipe/runner.js.map +1 -1
- package/dist/tools/mcp.d.ts +19 -0
- package/dist/tools/mcp.d.ts.map +1 -1
- package/dist/tools/mcp.js +51 -9
- package/dist/tools/mcp.js.map +1 -1
- package/package.json +2 -1
- package/skills/channel-manager/SKILL.md +59 -0
- package/skills/dca/SKILL.md +48 -0
- package/skills/kaleido-lsps/SKILL.md +12 -12
- package/skills/kaleido-trading/SKILL.md +1 -1
- package/skills/liquidity-optimizer/SKILL.md +91 -0
- package/skills/merchant-finder/SKILL.md +1 -1
- package/skills/portfolio-manager/SKILL.md +67 -0
- package/skills/rgb-lightning-node/SKILL.md +3 -3
- package/skills/wallet-assistant/SKILL.md +1 -1
- package/src/autonomy/autonomy.test.ts +348 -0
- package/src/autonomy/index.ts +50 -0
- package/src/autonomy/prompt.ts +48 -0
- package/src/autonomy/risk.ts +139 -0
- package/src/autonomy/run-state.ts +144 -0
- package/src/autonomy/scheduler.ts +120 -0
- package/src/autonomy/task-store.ts +167 -0
- package/src/autonomy/types.ts +186 -0
- package/src/funnel.mind.test.ts +390 -0
- package/src/funnel.ts +14 -0
- package/src/index.ts +41 -0
- package/src/knowledge/bitcoin-copilot.ts +2 -2
- package/src/qvac/index.ts +1 -0
- package/src/qvac/parse.test.ts +70 -1
- package/src/qvac/parse.ts +91 -5
- package/src/qvac/provider.test.ts +17 -0
- package/src/qvac/provider.ts +37 -1
- package/src/qvac/stream.test.ts +25 -0
- package/src/qvac/stream.ts +38 -1
- package/src/qvac/text.ts +4 -0
- package/src/recipe/buy-asset-channel.test.ts +5 -0
- package/src/recipe/buy-asset-channel.ts +6 -3
- package/src/recipe/kaleidoswap-atomic.test.ts +3 -3
- package/src/recipe/kaleidoswap-atomic.ts +5 -4
- package/src/recipe/recipe.test.ts +16 -0
- package/src/recipe/runner.ts +41 -0
- package/src/tools/mcp.live.test.ts +116 -0
- package/src/tools/mcp.parse.test.ts +37 -0
- package/src/tools/mcp.ts +55 -9
package/src/tools/mcp.ts
CHANGED
|
@@ -20,6 +20,18 @@
|
|
|
20
20
|
|
|
21
21
|
import type { ToolDef } from '../types.js';
|
|
22
22
|
import type { ToolSource } from './source.js';
|
|
23
|
+
import { isKaleidoswapSpendTool } from '../kaleidoswap/contract.js';
|
|
24
|
+
import { isLsps1SpendTool } from '../lsps1/contract.js';
|
|
25
|
+
import { isSpendTool } from '../wallet/contract.js';
|
|
26
|
+
|
|
27
|
+
function toolRequiresConfirmation(name: string, description: string): boolean {
|
|
28
|
+
return (
|
|
29
|
+
isSpendTool(name) ||
|
|
30
|
+
isKaleidoswapSpendTool(name) ||
|
|
31
|
+
isLsps1SpendTool(name) ||
|
|
32
|
+
/\bSPEND\b.*\bconfirm/i.test(description)
|
|
33
|
+
);
|
|
34
|
+
}
|
|
23
35
|
|
|
24
36
|
export type McpTransport =
|
|
25
37
|
| { kind: 'stdio'; command: string; args?: string[]; env?: Record<string, string> }
|
|
@@ -30,10 +42,47 @@ export interface McpToolSourceOptions {
|
|
|
30
42
|
transport: McpTransport;
|
|
31
43
|
/** Optional allowlist — only expose these tool names if provided. */
|
|
32
44
|
allow?: string[];
|
|
45
|
+
/** Optional prefix denylist applied after discovery (for host-specific rails). */
|
|
46
|
+
denyPrefixes?: string[];
|
|
33
47
|
/** Per-call timeout (ms). Default 60_000. */
|
|
34
48
|
timeoutMs?: number;
|
|
35
49
|
}
|
|
36
50
|
|
|
51
|
+
/**
|
|
52
|
+
* Normalize an MCP `callTool` result into a structured value.
|
|
53
|
+
*
|
|
54
|
+
* Two fixes vs. returning the raw text content:
|
|
55
|
+
* - `isError` (the MCP failure signal) becomes an `{ error }` object, so callers
|
|
56
|
+
* — the recipe runner's `toolFailure`, the agent — treat it as a FAILURE
|
|
57
|
+
* instead of a successful result. Without this the agent claimed a spend had
|
|
58
|
+
* succeeded when the wallet actually rejected it.
|
|
59
|
+
* - JSON text is PARSED, so recipes thread real fields (rfq_id, total_sat,
|
|
60
|
+
* order_id) and any failure fields (error/status) are visible. A raw string
|
|
61
|
+
* hid both — the quote's rfq_id never reached the create call, and the canned
|
|
62
|
+
* success summary fired regardless. Non-JSON text passes through unchanged;
|
|
63
|
+
* the engine re-stringifies objects when feeding the model.
|
|
64
|
+
*
|
|
65
|
+
* Exported for unit testing.
|
|
66
|
+
*/
|
|
67
|
+
export function parseMcpResult(res: unknown): unknown {
|
|
68
|
+
const r = res as { content?: Array<{ type?: string; text?: string }>; isError?: boolean } | null;
|
|
69
|
+
const text = Array.isArray(r?.content)
|
|
70
|
+
? r!.content
|
|
71
|
+
.filter((c) => c?.type === 'text')
|
|
72
|
+
.map((c) => c?.text ?? '')
|
|
73
|
+
.join('\n')
|
|
74
|
+
: '';
|
|
75
|
+
if (r?.isError) return { error: text || 'The tool reported an error.' };
|
|
76
|
+
if (text) {
|
|
77
|
+
try {
|
|
78
|
+
return JSON.parse(text);
|
|
79
|
+
} catch {
|
|
80
|
+
return text;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return Array.isArray(r?.content) ? r!.content : res;
|
|
84
|
+
}
|
|
85
|
+
|
|
37
86
|
export class McpToolSource implements ToolSource {
|
|
38
87
|
readonly id: string;
|
|
39
88
|
private readonly opts: McpToolSourceOptions;
|
|
@@ -71,12 +120,15 @@ export class McpToolSource implements ToolSource {
|
|
|
71
120
|
|
|
72
121
|
const listed = await this.client.listTools();
|
|
73
122
|
const allow = this.opts.allow ? new Set(this.opts.allow) : null;
|
|
123
|
+
const denied = this.opts.denyPrefixes ?? [];
|
|
74
124
|
this.tools = (listed.tools ?? [])
|
|
75
125
|
.filter((t: any) => !allow || allow.has(t.name))
|
|
126
|
+
.filter((t: any) => !denied.some((prefix) => t.name.startsWith(prefix)))
|
|
76
127
|
.map((t: any) => ({
|
|
77
128
|
name: t.name,
|
|
78
129
|
description: t.description ?? '',
|
|
79
130
|
parameters: t.inputSchema ?? { type: 'object', properties: {} },
|
|
131
|
+
requiresConfirmation: toolRequiresConfirmation(t.name, t.description ?? ''),
|
|
80
132
|
}));
|
|
81
133
|
}
|
|
82
134
|
|
|
@@ -95,15 +147,9 @@ export class McpToolSource implements ToolSource {
|
|
|
95
147
|
undefined,
|
|
96
148
|
{ timeout: this.opts.timeoutMs ?? 60_000 },
|
|
97
149
|
);
|
|
98
|
-
//
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
.filter((c: any) => c.type === 'text')
|
|
102
|
-
.map((c: any) => c.text)
|
|
103
|
-
.join('\n');
|
|
104
|
-
return text || res.content;
|
|
105
|
-
}
|
|
106
|
-
return res;
|
|
150
|
+
// Parse JSON + surface isError so recipes/agent get structured results and
|
|
151
|
+
// real failures (not an opaque string that hid both). See parseMcpResult.
|
|
152
|
+
return parseMcpResult(res);
|
|
107
153
|
}
|
|
108
154
|
|
|
109
155
|
async close(): Promise<void> {
|