@kaleidorg/mind 0.0.1

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.
Files changed (50) hide show
  1. package/dist/engine.d.ts +61 -0
  2. package/dist/engine.d.ts.map +1 -0
  3. package/dist/engine.js +99 -0
  4. package/dist/engine.js.map +1 -0
  5. package/dist/index.d.ts +20 -0
  6. package/dist/index.d.ts.map +1 -0
  7. package/dist/index.js +14 -0
  8. package/dist/index.js.map +1 -0
  9. package/dist/logger.d.ts +74 -0
  10. package/dist/logger.d.ts.map +1 -0
  11. package/dist/logger.js +63 -0
  12. package/dist/logger.js.map +1 -0
  13. package/dist/providers/qvac.d.ts +89 -0
  14. package/dist/providers/qvac.d.ts.map +1 -0
  15. package/dist/providers/qvac.js +150 -0
  16. package/dist/providers/qvac.js.map +1 -0
  17. package/dist/providers/types.d.ts +44 -0
  18. package/dist/providers/types.d.ts.map +1 -0
  19. package/dist/providers/types.js +13 -0
  20. package/dist/providers/types.js.map +1 -0
  21. package/dist/tools/in-process.d.ts +27 -0
  22. package/dist/tools/in-process.d.ts.map +1 -0
  23. package/dist/tools/in-process.js +34 -0
  24. package/dist/tools/in-process.js.map +1 -0
  25. package/dist/tools/mcp.d.ts +52 -0
  26. package/dist/tools/mcp.d.ts.map +1 -0
  27. package/dist/tools/mcp.js +81 -0
  28. package/dist/tools/mcp.js.map +1 -0
  29. package/dist/tools/registry.d.ts +23 -0
  30. package/dist/tools/registry.d.ts.map +1 -0
  31. package/dist/tools/registry.js +49 -0
  32. package/dist/tools/registry.js.map +1 -0
  33. package/dist/tools/source.d.ts +25 -0
  34. package/dist/tools/source.d.ts.map +1 -0
  35. package/dist/tools/source.js +15 -0
  36. package/dist/tools/source.js.map +1 -0
  37. package/dist/types.d.ts +41 -0
  38. package/dist/types.d.ts.map +1 -0
  39. package/dist/types.js +10 -0
  40. package/dist/types.js.map +1 -0
  41. package/package.json +46 -0
  42. package/src/engine.ts +141 -0
  43. package/src/index.ts +31 -0
  44. package/src/logger.ts +127 -0
  45. package/src/providers/types.ts +47 -0
  46. package/src/tools/in-process.ts +49 -0
  47. package/src/tools/mcp.ts +112 -0
  48. package/src/tools/registry.ts +56 -0
  49. package/src/tools/source.ts +26 -0
  50. package/src/types.ts +46 -0
@@ -0,0 +1,44 @@
1
+ /**
2
+ * LLMProvider — the only thing the Engine talks to for inference.
3
+ *
4
+ * Each host implements this over its own LLM transport:
5
+ * - rate (mobile): wraps @qvac/sdk completion() (local or P2P-delegated)
6
+ * - desktop-app: wraps @qvac/sdk completion() in Node
7
+ * - kaleidoagent: could wrap Anthropic/OpenAI
8
+ *
9
+ * The core package never imports any LLM SDK — it only depends on this
10
+ * interface, so it stays pure TS and bundles anywhere.
11
+ */
12
+ import type { Message, ToolCall, ToolDef } from '../types.js';
13
+ export interface TurnInput {
14
+ messages: Message[];
15
+ tools: ToolDef[];
16
+ /** System prompt, when not already present as a message. */
17
+ system?: string;
18
+ /** Visible content tokens as they stream. */
19
+ onToken?: (token: string) => void;
20
+ signal?: AbortSignal;
21
+ }
22
+ export interface TurnOutput {
23
+ /** Cleaned assistant content for display. */
24
+ text: string;
25
+ /**
26
+ * Raw assistant frame to push back into history for the next turn. For
27
+ * tool-calling models this includes the tool-call framing the model needs
28
+ * to anchor continuation (e.g. QVAC's `final.raw.fullText`). Falls back to
29
+ * `text` when a provider has no separate raw form.
30
+ */
31
+ rawContent: string;
32
+ /** Tool calls the model requested this turn (empty ⇒ final answer). */
33
+ toolCalls: ToolCall[];
34
+ /** Provider request id, for cancellation. */
35
+ requestId?: string;
36
+ }
37
+ export interface LLMProvider {
38
+ readonly name: string;
39
+ /** Run one completion turn. */
40
+ runTurn(input: TurnInput): Promise<TurnOutput>;
41
+ /** Cancel an in-flight turn by request id, if the provider supports it. */
42
+ cancel?(requestId: string): Promise<void>;
43
+ }
44
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE9D,MAAM,WAAW,SAAS;IACxB,QAAQ,EAAE,OAAO,EAAE,CAAC;IACpB,KAAK,EAAE,OAAO,EAAE,CAAC;IACjB,4DAA4D;IAC5D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,6CAA6C;IAC7C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,UAAU;IACzB,6CAA6C;IAC7C,IAAI,EAAE,MAAM,CAAC;IACb;;;;;OAKG;IACH,UAAU,EAAE,MAAM,CAAC;IACnB,uEAAuE;IACvE,SAAS,EAAE,QAAQ,EAAE,CAAC;IACtB,6CAA6C;IAC7C,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,MAAM,WAAW,WAAW;IAC1B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,+BAA+B;IAC/B,OAAO,CAAC,KAAK,EAAE,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;IAC/C,2EAA2E;IAC3E,MAAM,CAAC,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAC3C"}
@@ -0,0 +1,13 @@
1
+ /**
2
+ * LLMProvider — the only thing the Engine talks to for inference.
3
+ *
4
+ * Each host implements this over its own LLM transport:
5
+ * - rate (mobile): wraps @qvac/sdk completion() (local or P2P-delegated)
6
+ * - desktop-app: wraps @qvac/sdk completion() in Node
7
+ * - kaleidoagent: could wrap Anthropic/OpenAI
8
+ *
9
+ * The core package never imports any LLM SDK — it only depends on this
10
+ * interface, so it stays pure TS and bundles anywhere.
11
+ */
12
+ export {};
13
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../src/providers/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * InProcessToolSource — tools whose handlers run in the same process.
3
+ *
4
+ * Used by the mobile wallet: the handlers call the device's wallet adapters
5
+ * (Spark / Arkade / RGB) directly, so signing happens on the phone even when
6
+ * the model's inference is delegated to a desktop over P2P.
7
+ */
8
+ import type { ToolDef } from '../types.js';
9
+ import type { ToolSource } from './source.js';
10
+ export interface InProcessTool<Args = Record<string, unknown>> {
11
+ name: string;
12
+ description: string;
13
+ /** Zod schema (or any shape the provider understands). */
14
+ parameters: unknown;
15
+ /** When true, the engine pauses for confirmation before executing. */
16
+ requiresConfirmation?: boolean;
17
+ handler: (args: Args) => Promise<unknown>;
18
+ }
19
+ export declare class InProcessToolSource implements ToolSource {
20
+ readonly id: string;
21
+ private readonly tools;
22
+ constructor(id: string, tools: InProcessTool[]);
23
+ listTools(): ToolDef[];
24
+ has(name: string): boolean;
25
+ execute(name: string, args: Record<string, unknown>): Promise<unknown>;
26
+ }
27
+ //# sourceMappingURL=in-process.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-process.d.ts","sourceRoot":"","sources":["../../src/tools/in-process.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,WAAW,aAAa,CAAC,IAAI,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAC3D,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,0DAA0D;IAC1D,UAAU,EAAE,OAAO,CAAC;IACpB,sEAAsE;IACtE,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,OAAO,EAAE,CAAC,IAAI,EAAE,IAAI,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3C;AAED,qBAAa,mBAAoB,YAAW,UAAU;IACpD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAoC;gBAE9C,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE;IAK9C,SAAS,IAAI,OAAO,EAAE;IAStB,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;CAK7E"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * InProcessToolSource — tools whose handlers run in the same process.
3
+ *
4
+ * Used by the mobile wallet: the handlers call the device's wallet adapters
5
+ * (Spark / Arkade / RGB) directly, so signing happens on the phone even when
6
+ * the model's inference is delegated to a desktop over P2P.
7
+ */
8
+ export class InProcessToolSource {
9
+ id;
10
+ tools = new Map();
11
+ constructor(id, tools) {
12
+ this.id = id;
13
+ for (const t of tools)
14
+ this.tools.set(t.name, t);
15
+ }
16
+ listTools() {
17
+ return Array.from(this.tools.values()).map((t) => ({
18
+ name: t.name,
19
+ description: t.description,
20
+ parameters: t.parameters,
21
+ requiresConfirmation: t.requiresConfirmation,
22
+ }));
23
+ }
24
+ has(name) {
25
+ return this.tools.has(name);
26
+ }
27
+ async execute(name, args) {
28
+ const tool = this.tools.get(name);
29
+ if (!tool)
30
+ throw new Error(`Tool "${name}" not found in source "${this.id}"`);
31
+ return tool.handler(args);
32
+ }
33
+ }
34
+ //# sourceMappingURL=in-process.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"in-process.js","sourceRoot":"","sources":["../../src/tools/in-process.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAeH,MAAM,OAAO,mBAAmB;IACrB,EAAE,CAAS;IACH,KAAK,GAAG,IAAI,GAAG,EAAyB,CAAC;IAE1D,YAAY,EAAU,EAAE,KAAsB;QAC5C,IAAI,CAAC,EAAE,GAAG,EAAE,CAAC;QACb,KAAK,MAAM,CAAC,IAAI,KAAK;YAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAkB,CAAC,CAAC;IACpE,CAAC;IAED,SAAS;QACP,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACjD,IAAI,EAAE,CAAC,CAAC,IAAI;YACZ,WAAW,EAAE,CAAC,CAAC,WAAW;YAC1B,UAAU,EAAE,CAAC,CAAC,UAAU;YACxB,oBAAoB,EAAE,CAAC,CAAC,oBAAoB;SAC7C,CAAC,CAAC,CAAC;IACN,CAAC;IAED,GAAG,CAAC,IAAY;QACd,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC9B,CAAC;IAED,KAAK,CAAC,OAAO,CAAC,IAAY,EAAE,IAA6B;QACvD,MAAM,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,SAAS,IAAI,0BAA0B,IAAI,CAAC,EAAE,GAAG,CAAC,CAAC;QAC9E,OAAO,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * McpToolSource — exposes an MCP server's tools to the engine. NODE ONLY.
3
+ *
4
+ * Not exported from the package's main entry (`@kaleido/mind`) — import it
5
+ * explicitly from `@kaleido/mind/mcp` on Node hosts (desktop-app, kaleidoagent)
6
+ * so React Native never bundles the MCP SDK or any subprocess machinery.
7
+ *
8
+ * Connects to a server like `kaleido-mcp` (Spark + RLN + KaleidoSwap DEX +
9
+ * MPP/L402 + market data, ~64 tools) over stdio or HTTP, lists its tools, and
10
+ * routes execute() calls through the MCP client.
11
+ *
12
+ * The `@modelcontextprotocol/sdk` dependency is imported dynamically so this
13
+ * file type-checks and ships even where the SDK isn't installed; constructing
14
+ * an McpToolSource without it throws a clear error.
15
+ *
16
+ * STATUS: skeleton for the desktop pass. The shape is final; the connect()
17
+ * body is wired when we integrate desktop-app.
18
+ */
19
+ import type { ToolDef } from '../types.js';
20
+ import type { ToolSource } from './source.js';
21
+ export type McpTransport = {
22
+ kind: 'stdio';
23
+ command: string;
24
+ args?: string[];
25
+ env?: Record<string, string>;
26
+ } | {
27
+ kind: 'http';
28
+ url: string;
29
+ headers?: Record<string, string>;
30
+ };
31
+ export interface McpToolSourceOptions {
32
+ id: string;
33
+ transport: McpTransport;
34
+ /** Optional allowlist — only expose these tool names if provided. */
35
+ allow?: string[];
36
+ /** Per-call timeout (ms). Default 60_000. */
37
+ timeoutMs?: number;
38
+ }
39
+ export declare class McpToolSource implements ToolSource {
40
+ readonly id: string;
41
+ private readonly opts;
42
+ private client;
43
+ private tools;
44
+ constructor(opts: McpToolSourceOptions);
45
+ /** Connect to the MCP server and cache its tool list. Call once at startup. */
46
+ connect(): Promise<void>;
47
+ listTools(): ToolDef[];
48
+ has(name: string): boolean;
49
+ execute(name: string, args: Record<string, unknown>): Promise<unknown>;
50
+ close(): Promise<void>;
51
+ }
52
+ //# sourceMappingURL=mcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.d.ts","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;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"}
@@ -0,0 +1,81 @@
1
+ /**
2
+ * McpToolSource — exposes an MCP server's tools to the engine. NODE ONLY.
3
+ *
4
+ * Not exported from the package's main entry (`@kaleido/mind`) — import it
5
+ * explicitly from `@kaleido/mind/mcp` on Node hosts (desktop-app, kaleidoagent)
6
+ * so React Native never bundles the MCP SDK or any subprocess machinery.
7
+ *
8
+ * Connects to a server like `kaleido-mcp` (Spark + RLN + KaleidoSwap DEX +
9
+ * MPP/L402 + market data, ~64 tools) over stdio or HTTP, lists its tools, and
10
+ * routes execute() calls through the MCP client.
11
+ *
12
+ * The `@modelcontextprotocol/sdk` dependency is imported dynamically so this
13
+ * file type-checks and ships even where the SDK isn't installed; constructing
14
+ * an McpToolSource without it throws a clear error.
15
+ *
16
+ * STATUS: skeleton for the desktop pass. The shape is final; the connect()
17
+ * body is wired when we integrate desktop-app.
18
+ */
19
+ export class McpToolSource {
20
+ id;
21
+ opts;
22
+ client = null;
23
+ tools = [];
24
+ constructor(opts) {
25
+ this.id = opts.id;
26
+ this.opts = opts;
27
+ }
28
+ /** Connect to the MCP server and cache its tool list. Call once at startup. */
29
+ async connect() {
30
+ // Dynamic import keeps the MCP SDK out of bundles that never call connect().
31
+ const { Client } = await import('@modelcontextprotocol/sdk/client/index.js');
32
+ const t = this.opts.transport;
33
+ let transport;
34
+ if (t.kind === 'stdio') {
35
+ const { StdioClientTransport } = await import('@modelcontextprotocol/sdk/client/stdio.js');
36
+ transport = new StdioClientTransport({ command: t.command, args: t.args ?? [], env: t.env });
37
+ }
38
+ else {
39
+ const { StreamableHTTPClientTransport } = await import('@modelcontextprotocol/sdk/client/streamableHttp.js');
40
+ transport = new StreamableHTTPClientTransport(new URL(t.url), {
41
+ requestInit: t.headers ? { headers: t.headers } : undefined,
42
+ });
43
+ }
44
+ this.client = new Client({ name: `kaleido-mind:${this.id}`, version: '0.0.1' }, { capabilities: {} });
45
+ await this.client.connect(transport);
46
+ const listed = await this.client.listTools();
47
+ const allow = this.opts.allow ? new Set(this.opts.allow) : null;
48
+ this.tools = (listed.tools ?? [])
49
+ .filter((t) => !allow || allow.has(t.name))
50
+ .map((t) => ({
51
+ name: t.name,
52
+ description: t.description ?? '',
53
+ parameters: t.inputSchema ?? { type: 'object', properties: {} },
54
+ }));
55
+ }
56
+ listTools() {
57
+ return this.tools;
58
+ }
59
+ has(name) {
60
+ return this.tools.some((t) => t.name === name);
61
+ }
62
+ async execute(name, args) {
63
+ if (!this.client)
64
+ throw new Error(`McpToolSource "${this.id}" not connected — call connect() first`);
65
+ const res = await this.client.callTool({ name, arguments: args }, undefined, { timeout: this.opts.timeoutMs ?? 60_000 });
66
+ // MCP returns content blocks; surface text content as the tool result.
67
+ if (Array.isArray(res?.content)) {
68
+ const text = res.content
69
+ .filter((c) => c.type === 'text')
70
+ .map((c) => c.text)
71
+ .join('\n');
72
+ return text || res.content;
73
+ }
74
+ return res;
75
+ }
76
+ async close() {
77
+ await this.client?.close?.();
78
+ this.client = null;
79
+ }
80
+ }
81
+ //# sourceMappingURL=mcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp.js","sourceRoot":"","sources":["../../src/tools/mcp.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;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,E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,0 +1,23 @@
1
+ /**
2
+ * ToolRegistry — merges multiple ToolSources into one tool list for the model
3
+ * and routes each tool call back to the source that owns it.
4
+ *
5
+ * Name-clash policy: first source wins (sources are consulted in registration
6
+ * order), so a host can layer a high-priority source over a broader one.
7
+ */
8
+ import type { ToolDef } from '../types.js';
9
+ import type { ToolSource } from './source.js';
10
+ export declare class ToolRegistry {
11
+ private readonly sources;
12
+ constructor(sources?: ToolSource[]);
13
+ add(source: ToolSource): this;
14
+ /** Merged, de-duplicated tool list across all sources. */
15
+ listTools(): Promise<ToolDef[]>;
16
+ /** The first source that owns a tool by name. */
17
+ private ownerOf;
18
+ /** Execute a tool, routing to its owning source. */
19
+ execute(name: string, args: Record<string, unknown>): Promise<unknown>;
20
+ /** Look up a tool definition (e.g. to check requiresConfirmation). */
21
+ getDef(name: string): Promise<ToolDef | undefined>;
22
+ }
23
+ //# sourceMappingURL=registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAE9C,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAoB;gBAEhC,OAAO,GAAE,UAAU,EAAO;IAItC,GAAG,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAK7B,0DAA0D;IACpD,SAAS,IAAI,OAAO,CAAC,OAAO,EAAE,CAAC;IAcrC,iDAAiD;IACjD,OAAO,CAAC,OAAO;IAIf,oDAAoD;IAC9C,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC;IAM5E,sEAAsE;IAChE,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,GAAG,SAAS,CAAC;CAIzD"}
@@ -0,0 +1,49 @@
1
+ /**
2
+ * ToolRegistry — merges multiple ToolSources into one tool list for the model
3
+ * and routes each tool call back to the source that owns it.
4
+ *
5
+ * Name-clash policy: first source wins (sources are consulted in registration
6
+ * order), so a host can layer a high-priority source over a broader one.
7
+ */
8
+ export class ToolRegistry {
9
+ sources = [];
10
+ constructor(sources = []) {
11
+ this.sources = [...sources];
12
+ }
13
+ add(source) {
14
+ this.sources.push(source);
15
+ return this;
16
+ }
17
+ /** Merged, de-duplicated tool list across all sources. */
18
+ async listTools() {
19
+ const out = [];
20
+ const seen = new Set();
21
+ for (const source of this.sources) {
22
+ const tools = await source.listTools();
23
+ for (const t of tools) {
24
+ if (seen.has(t.name))
25
+ continue; // first source wins
26
+ seen.add(t.name);
27
+ out.push(t);
28
+ }
29
+ }
30
+ return out;
31
+ }
32
+ /** The first source that owns a tool by name. */
33
+ ownerOf(name) {
34
+ return this.sources.find((s) => s.has(name));
35
+ }
36
+ /** Execute a tool, routing to its owning source. */
37
+ async execute(name, args) {
38
+ const owner = this.ownerOf(name);
39
+ if (!owner)
40
+ throw new Error(`No tool source owns "${name}"`);
41
+ return owner.execute(name, args);
42
+ }
43
+ /** Look up a tool definition (e.g. to check requiresConfirmation). */
44
+ async getDef(name) {
45
+ const tools = await this.listTools();
46
+ return tools.find((t) => t.name === name);
47
+ }
48
+ }
49
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../../src/tools/registry.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAKH,MAAM,OAAO,YAAY;IACN,OAAO,GAAiB,EAAE,CAAC;IAE5C,YAAY,UAAwB,EAAE;QACpC,IAAI,CAAC,OAAO,GAAG,CAAC,GAAG,OAAO,CAAC,CAAC;IAC9B,CAAC;IAED,GAAG,CAAC,MAAkB;QACpB,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,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EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAC5C,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * ToolSource — anything that exposes a set of tools and can execute them.
3
+ *
4
+ * This is the seam that makes the engine modular. Two implementations cover
5
+ * every surface:
6
+ * - InProcessToolSource — Zod tools + local handlers (works on React Native;
7
+ * used by the mobile wallet — handlers run on-device so keys never leave)
8
+ * - McpToolSource — connects an MCP server over stdio/HTTP (Node only;
9
+ * used on desktop for the full kaleido-mcp toolset)
10
+ *
11
+ * The engine merges N sources into one tool list for the model and routes each
12
+ * tool call back to the source that owns it.
13
+ */
14
+ import type { ToolDef } from '../types.js';
15
+ export interface ToolSource {
16
+ /** Stable identifier (for logging / debugging). */
17
+ readonly id: string;
18
+ /** The tools this source exposes. May be async (e.g. MCP listTools). */
19
+ listTools(): ToolDef[] | Promise<ToolDef[]>;
20
+ /** Whether this source owns a tool by name. */
21
+ has(name: string): boolean;
22
+ /** Execute a tool this source owns. */
23
+ execute(name: string, args: Record<string, unknown>): Promise<unknown>;
24
+ }
25
+ //# sourceMappingURL=source.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.d.ts","sourceRoot":"","sources":["../../src/tools/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,WAAW,UAAU;IACzB,mDAAmD;IACnD,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,wEAAwE;IACxE,SAAS,IAAI,OAAO,EAAE,GAAG,OAAO,CAAC,OAAO,EAAE,CAAC,CAAC;IAC5C,+CAA+C;IAC/C,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IAC3B,uCAAuC;IACvC,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CACxE"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * ToolSource — anything that exposes a set of tools and can execute them.
3
+ *
4
+ * This is the seam that makes the engine modular. Two implementations cover
5
+ * every surface:
6
+ * - InProcessToolSource — Zod tools + local handlers (works on React Native;
7
+ * used by the mobile wallet — handlers run on-device so keys never leave)
8
+ * - McpToolSource — connects an MCP server over stdio/HTTP (Node only;
9
+ * used on desktop for the full kaleido-mcp toolset)
10
+ *
11
+ * The engine merges N sources into one tool list for the model and routes each
12
+ * tool call back to the source that owns it.
13
+ */
14
+ export {};
15
+ //# sourceMappingURL=source.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"source.js","sourceRoot":"","sources":["../../src/tools/source.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG"}
@@ -0,0 +1,41 @@
1
+ /**
2
+ * Core types for the kaleido-mind engine.
3
+ *
4
+ * Pure data shapes — no runtime dependencies. The engine, tool sources and
5
+ * providers are all defined in terms of these, so the core package bundles
6
+ * cleanly on any host (React Native / Node / browser) without dragging in
7
+ * @qvac/sdk or any native code.
8
+ */
9
+ export type Role = 'system' | 'user' | 'assistant' | 'tool';
10
+ export interface Message {
11
+ role: Role;
12
+ content: string;
13
+ }
14
+ /**
15
+ * A tool the model can call. `parameters` is intentionally `unknown` — it may
16
+ * be a Zod schema (in-process tools) or a JSON Schema (MCP tools). Each
17
+ * provider converts it to whatever its SDK expects.
18
+ */
19
+ export interface ToolDef {
20
+ name: string;
21
+ description: string;
22
+ parameters: unknown;
23
+ /** When true, the engine pauses for `onConfirm` before executing (e.g. payments). */
24
+ requiresConfirmation?: boolean;
25
+ }
26
+ export interface ToolCall {
27
+ /** Provider-assigned id, when available. */
28
+ id?: string;
29
+ name: string;
30
+ arguments: Record<string, unknown>;
31
+ }
32
+ export interface ToolResult {
33
+ name: string;
34
+ arguments: Record<string, unknown>;
35
+ result: unknown;
36
+ }
37
+ export interface ConfirmDecision {
38
+ approved: boolean;
39
+ reason?: string;
40
+ }
41
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,MAAM,MAAM,IAAI,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,MAAM,CAAC;AAE5D,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,IAAI,CAAC;IACX,OAAO,EAAE,MAAM,CAAC;CACjB;AAED;;;;GAIG;AACH,MAAM,WAAW,OAAO;IACtB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,OAAO,CAAC;IACpB,qFAAqF;IACrF,oBAAoB,CAAC,EAAE,OAAO,CAAC;CAChC;AAED,MAAM,WAAW,QAAQ;IACvB,4CAA4C;IAC5C,EAAE,CAAC,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IACnC,MAAM,EAAE,OAAO,CAAC;CACjB;AAED,MAAM,WAAW,eAAe;IAC9B,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB"}
package/dist/types.js ADDED
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Core types for the kaleido-mind engine.
3
+ *
4
+ * Pure data shapes — no runtime dependencies. The engine, tool sources and
5
+ * providers are all defined in terms of these, so the core package bundles
6
+ * cleanly on any host (React Native / Node / browser) without dragging in
7
+ * @qvac/sdk or any native code.
8
+ */
9
+ export {};
10
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG"}
package/package.json ADDED
@@ -0,0 +1,46 @@
1
+ {
2
+ "name": "@kaleidorg/mind",
3
+ "version": "0.0.1",
4
+ "description": "Local-first reasoning + function-calling engine for KaleidoSwap. QVAC-powered.",
5
+ "license": "Apache-2.0",
6
+ "type": "module",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/kaleidoswap/kaleido-mind.git",
10
+ "directory": "packages/core"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "main": "./dist/index.js",
16
+ "types": "./dist/index.d.ts",
17
+ "exports": {
18
+ ".": {
19
+ "import": "./dist/index.js",
20
+ "types": "./dist/index.d.ts"
21
+ },
22
+ "./mcp": {
23
+ "import": "./dist/tools/mcp.js",
24
+ "types": "./dist/tools/mcp.d.ts"
25
+ },
26
+ "./logger": {
27
+ "import": "./dist/logger.js",
28
+ "types": "./dist/logger.d.ts"
29
+ }
30
+ },
31
+ "files": [
32
+ "dist",
33
+ "src",
34
+ "README.md",
35
+ "LICENSE"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc",
39
+ "typecheck": "tsc --noEmit",
40
+ "test": "vitest run",
41
+ "lint": "eslint src"
42
+ },
43
+ "devDependencies": {
44
+ "vitest": "^1.6.0"
45
+ }
46
+ }