@kaleidorg/mind 0.8.0 → 0.9.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/README.md +7 -5
- package/dist/bitrefill/index.d.ts +4 -0
- package/dist/bitrefill/index.d.ts.map +1 -0
- package/dist/bitrefill/index.js +3 -0
- package/dist/bitrefill/index.js.map +1 -0
- package/dist/capabilities.d.ts +3 -3
- package/dist/capabilities.d.ts.map +1 -1
- package/dist/capabilities.js +4 -4
- package/dist/capabilities.js.map +1 -1
- package/dist/engine/answer.d.ts +37 -0
- package/dist/engine/answer.d.ts.map +1 -0
- package/dist/engine/answer.js +35 -0
- package/dist/engine/answer.js.map +1 -0
- package/dist/engine.d.ts +15 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +171 -170
- package/dist/engine.js.map +1 -1
- package/dist/evidence.d.ts +1 -1
- package/dist/evidence.d.ts.map +1 -1
- package/dist/fastpath/fastpath.d.ts +6 -1
- package/dist/fastpath/fastpath.d.ts.map +1 -1
- package/dist/fastpath/fastpath.js +16 -2
- package/dist/fastpath/fastpath.js.map +1 -1
- package/dist/fastpath/render.d.ts +2 -0
- package/dist/fastpath/render.d.ts.map +1 -0
- package/dist/fastpath/render.js +58 -0
- package/dist/fastpath/render.js.map +1 -0
- package/dist/flashnet/index.d.ts +5 -0
- package/dist/flashnet/index.d.ts.map +1 -0
- package/dist/flashnet/index.js +4 -0
- package/dist/flashnet/index.js.map +1 -0
- package/dist/funnel.d.ts.map +1 -1
- package/dist/funnel.js +11 -14
- package/dist/funnel.js.map +1 -1
- package/dist/index.d.ts +6 -23
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +10 -27
- package/dist/index.js.map +1 -1
- package/dist/kaleidoswap/index.d.ts +8 -0
- package/dist/kaleidoswap/index.d.ts.map +1 -0
- package/dist/kaleidoswap/index.js +7 -0
- package/dist/kaleidoswap/index.js.map +1 -0
- package/dist/knowledge/index.d.ts +9 -0
- package/dist/knowledge/index.d.ts.map +1 -0
- package/dist/knowledge/index.js +6 -0
- package/dist/knowledge/index.js.map +1 -0
- package/dist/lsps1/index.d.ts +4 -0
- package/dist/lsps1/index.d.ts.map +1 -0
- package/dist/lsps1/index.js +3 -0
- package/dist/lsps1/index.js.map +1 -0
- package/dist/providers/types.d.ts +16 -3
- package/dist/providers/types.d.ts.map +1 -1
- package/dist/providers/types.js +3 -3
- package/dist/qvac/index.d.ts +0 -1
- package/dist/qvac/index.d.ts.map +1 -1
- package/dist/qvac/index.js +0 -1
- package/dist/qvac/index.js.map +1 -1
- package/dist/qvac/provider.d.ts +15 -6
- package/dist/qvac/provider.d.ts.map +1 -1
- package/dist/qvac/provider.js +14 -16
- package/dist/qvac/provider.js.map +1 -1
- package/dist/qvac/stream.d.ts +4 -3
- package/dist/qvac/stream.d.ts.map +1 -1
- package/dist/qvac/stream.js.map +1 -1
- package/dist/qvac/voice.d.ts +1 -1
- package/dist/submarine/index.d.ts +5 -0
- package/dist/submarine/index.d.ts.map +1 -0
- package/dist/submarine/index.js +4 -0
- package/dist/submarine/index.js.map +1 -0
- package/dist/tools/in-process.d.ts +2 -2
- package/dist/tools/in-process.js +2 -2
- package/package.json +32 -2
- package/src/bitrefill/index.ts +13 -0
- package/src/capabilities.ts +7 -7
- package/src/context/context.test.ts +2 -2
- package/src/engine/answer.ts +66 -0
- package/src/engine.test.ts +39 -0
- package/src/engine.ts +199 -188
- package/src/evidence.ts +1 -1
- package/src/fastpath/fastpath.ts +22 -2
- package/src/fastpath/render.test.ts +39 -0
- package/src/fastpath/render.ts +56 -0
- package/src/flashnet/index.ts +14 -0
- package/src/funnel.mind.test.ts +11 -15
- package/src/funnel.ts +11 -15
- package/src/index.ts +10 -107
- package/src/kaleidoswap/index.ts +19 -0
- package/src/knowledge/index.ts +14 -0
- package/src/lsps1/index.ts +13 -0
- package/src/providers/types.ts +16 -3
- package/src/qvac/index.ts +0 -8
- package/src/qvac/provider.test.ts +20 -17
- package/src/qvac/provider.ts +28 -26
- package/src/qvac/stream.ts +4 -3
- package/src/qvac/voice.ts +1 -1
- package/src/submarine/index.ts +17 -0
- package/src/tools/in-process.ts +2 -2
- package/dist/qvac/delegate.d.ts +0 -50
- package/dist/qvac/delegate.d.ts.map +0 -1
- package/dist/qvac/delegate.js +0 -53
- package/dist/qvac/delegate.js.map +0 -1
- package/src/qvac/delegate.test.ts +0 -68
- package/src/qvac/delegate.ts +0 -73
package/README.md
CHANGED
|
@@ -33,11 +33,11 @@ needs no model. To connect MCP servers, also install
|
|
|
33
33
|
|
|
34
34
|
| `@qvac/sdk` | Status |
|
|
35
35
|
|---|---|
|
|
36
|
-
| 0.
|
|
37
|
-
| 0.
|
|
36
|
+
| 0.20 – 0.21 | Supported (tested with 0.21.0). |
|
|
37
|
+
| < 0.20 | Not supported from mind 0.9: the provider sends `tool_choice` and `reasoning_budget`, which older SDKs reject or ignore. Use mind 0.8.x. |
|
|
38
38
|
|
|
39
39
|
The Qwen3.5 model constants used below (`QWEN3_5_*_MULTIMODAL_Q4_K_M`) exist in
|
|
40
|
-
every supported `@qvac/sdk` version
|
|
40
|
+
every supported `@qvac/sdk` version.
|
|
41
41
|
|
|
42
42
|
## Models
|
|
43
43
|
|
|
@@ -146,9 +146,11 @@ aborts the request on `signal`. Reasoning deltas (`reasoning_content`) go to
|
|
|
146
146
|
|
|
147
147
|
| Import | What it gives you | Runtime |
|
|
148
148
|
|---|---|---|
|
|
149
|
-
| `@kaleidorg/mind` | `Engine`, `Funnel` (fast-path → recipe → agent), `ToolRegistry`, `InProcessToolSource`, `SkillRegistry`, wallet
|
|
150
|
-
| `@kaleidorg/mind/qvac` | `createQvacProvider`, `toQvacTools`, `consumeRun`, voice (`createQvacVoice`, `runVoiceAssistant`), model configs
|
|
149
|
+
| `@kaleidorg/mind` | `Engine`, `Funnel` (fast-path → recipe → agent), `ToolRegistry`, `InProcessToolSource`, `SkillRegistry`, the wallet contract and binder, `confirmReadback`, recipes, memory, RAG, context budgeting, L402 and CLI tool sources | Any (RN-safe) |
|
|
150
|
+
| `@kaleidorg/mind/qvac` | `createQvacProvider`, `toQvacTools`, `consumeRun`, voice (`createQvacVoice`, `runVoiceAssistant`), model configs | Any; you inject the SDK functions |
|
|
151
151
|
| `@kaleidorg/mind/openai` | `createOpenAICompatibleProvider` for Ollama, LM Studio, llama.cpp, vLLM, hosted APIs | Any with `fetch` |
|
|
152
|
+
| `@kaleidorg/mind/kaleidoswap` · `/lsps1` · `/submarine` · `/bitrefill` · `/flashnet` | Each domain's tool contract (`*_TOOLS`, `bind*Tools`) and its recipes. Also re-exported from the root until 1.0 | Any |
|
|
153
|
+
| `@kaleidorg/mind/knowledge` | Knowledge packs (`BITCOIN_COPILOT_DOCS`), corpus adapters for RAG, `createBtcMapToolSource` | Any |
|
|
152
154
|
| `@kaleidorg/mind/mcp` | `McpToolSource`: tools from an MCP server over stdio or streamable HTTP | Node |
|
|
153
155
|
| `@kaleidorg/mind/skills` | `loadSkillsDir`, `loadSkillFromDir`, `packagedSkillsDir()` (the 14 bundled skills) | Node (fs) |
|
|
154
156
|
| `@kaleidorg/mind/testing` | `MockWallet` (stateful fake wallet bound to the real contract), `scriptedProvider` | Any |
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
/** Bitrefill (gift cards, top-ups, eSIMs): tool contract. */
|
|
2
|
+
export { BITREFILL_TOOLS, BITREFILL_SPEND_TOOLS, isBitrefillSpendTool, getBitrefillTool, bindBitrefillTools, } from './contract.js';
|
|
3
|
+
export type { BitrefillToolDef, BitrefillHandler, BindBitrefillOptions, } from './contract.js';
|
|
4
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/bitrefill/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,eAAe,CAAC;AACvB,YAAY,EACV,gBAAgB,EAChB,gBAAgB,EAChB,oBAAoB,GACrB,MAAM,eAAe,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/bitrefill/index.ts"],"names":[],"mappings":"AAAA,6DAA6D;AAC7D,OAAO,EACL,eAAe,EACf,qBAAqB,EACrB,oBAAoB,EACpB,gBAAgB,EAChB,kBAAkB,GACnB,MAAM,eAAe,CAAC"}
|
package/dist/capabilities.d.ts
CHANGED
|
@@ -13,8 +13,8 @@ export interface CapabilityInput {
|
|
|
13
13
|
modelCtxTokens: number;
|
|
14
14
|
/** Whether an EmbeddingProvider is wired (QVAC embed, etc.). */
|
|
15
15
|
hasEmbeddings?: boolean;
|
|
16
|
-
/**
|
|
17
|
-
|
|
16
|
+
/** Inference runs on a larger remote model (e.g. an OpenAI-compatible server) — relaxes limits. */
|
|
17
|
+
remote?: boolean;
|
|
18
18
|
}
|
|
19
19
|
export interface MindCapabilities {
|
|
20
20
|
/** Long-term memory (cheap — on unless the window is tiny). */
|
|
@@ -23,7 +23,7 @@ export interface MindCapabilities {
|
|
|
23
23
|
semanticMemory: boolean;
|
|
24
24
|
/** Embedding-only dedup of near-duplicate memories (zero inference — mobile-safe). */
|
|
25
25
|
dedupeMemory: boolean;
|
|
26
|
-
/** LLM merge of near-duplicate memories (an extra inference — capable/
|
|
26
|
+
/** LLM merge of near-duplicate memories (an extra inference — capable/remote only). */
|
|
27
27
|
mergeMemory: boolean;
|
|
28
28
|
/** Retrieval-augmented generation (needs embeddings + enough RAM/context). */
|
|
29
29
|
rag: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,cAAc,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,
|
|
1
|
+
{"version":3,"file":"capabilities.d.ts","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAIH,MAAM,WAAW,eAAe;IAC9B,gFAAgF;IAChF,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,0EAA0E;IAC1E,cAAc,EAAE,MAAM,CAAC;IACvB,gEAAgE;IAChE,aAAa,CAAC,EAAE,OAAO,CAAC;IACxB,mGAAmG;IACnG,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,gBAAgB;IAC/B,+DAA+D;IAC/D,MAAM,EAAE,OAAO,CAAC;IAChB,qDAAqD;IACrD,cAAc,EAAE,OAAO,CAAC;IACxB,sFAAsF;IACtF,YAAY,EAAE,OAAO,CAAC;IACtB,uFAAuF;IACvF,WAAW,EAAE,OAAO,CAAC;IACrB,8EAA8E;IAC9E,GAAG,EAAE,OAAO,CAAC;IACb,gDAAgD;IAChD,mBAAmB,EAAE,MAAM,CAAC;IAC5B,4CAA4C;IAC5C,UAAU,EAAE,MAAM,CAAC;IACnB,0DAA0D;IAC1D,OAAO,EAAE,MAAM,CAAC;CACjB;AAID,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,eAAe,GAAG,gBAAgB,CAmC1E"}
|
package/dist/capabilities.js
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
import { contextBudgetTokens } from './context/budget.js';
|
|
10
10
|
const GiB = 1024 * 1024 * 1024;
|
|
11
11
|
export function capabilityProfile(input) {
|
|
12
|
-
const ramGb = input.
|
|
12
|
+
const ramGb = input.remote ? Infinity : (input.ramBytes ?? 0) / GiB;
|
|
13
13
|
const ctx = input.modelCtxTokens;
|
|
14
14
|
const hasEmb = !!input.hasEmbeddings;
|
|
15
15
|
const budget = contextBudgetTokens(ctx);
|
|
@@ -18,12 +18,12 @@ export function capabilityProfile(input) {
|
|
|
18
18
|
const semanticMemory = memory && hasEmb;
|
|
19
19
|
// Consolidation: embedding-only dedup is cheap (no inference) — on wherever
|
|
20
20
|
// semantic memory is. The LLM merge costs an extra inference, so reserve it
|
|
21
|
-
// for
|
|
21
|
+
// for remote or roomy on-device setups; never run it on a tiny phone model.
|
|
22
22
|
const dedupeMemory = semanticMemory;
|
|
23
|
-
const mergeMemory = dedupeMemory && (input.
|
|
23
|
+
const mergeMemory = dedupeMemory && (input.remote || (ramGb >= 4 && ctx >= 4096));
|
|
24
24
|
// RAG is the expensive one: needs embeddings, a non-tiny context window, and
|
|
25
25
|
// (on-device) enough RAM to hold an embedding model + index.
|
|
26
|
-
const rag = hasEmb && ctx >= 4096 && (input.
|
|
26
|
+
const rag = hasEmb && ctx >= 4096 && (input.remote || ramGb >= 3);
|
|
27
27
|
// Scale how much we pull in with the available window.
|
|
28
28
|
const topKMemory = budget >= 1500 ? 4 : budget >= 700 ? 3 : 2;
|
|
29
29
|
const topKRag = rag ? (budget >= 2500 ? 5 : 3) : 0;
|
package/dist/capabilities.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAgC1D,MAAM,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/B,MAAM,UAAU,iBAAiB,CAAC,KAAsB;IACtD,MAAM,KAAK,GAAG,KAAK,CAAC,
|
|
1
|
+
{"version":3,"file":"capabilities.js","sourceRoot":"","sources":["../src/capabilities.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAgC1D,MAAM,GAAG,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAE/B,MAAM,U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E,MAAM;QAC3B,UAAU;QACV,OAAO;KACR,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How an agentic run ends: the Engine's fixed replies, and the checks every
|
|
3
|
+
* answer the model wrote goes through before the user sees it.
|
|
4
|
+
*
|
|
5
|
+
* An answer is tagged with where it came from. Fixed replies are final; only
|
|
6
|
+
* model text is rewritten (amount fixes) or replaced (payment data no tool
|
|
7
|
+
* returned). Keeping that rule in one place is what stops a fixed reply that
|
|
8
|
+
* quotes a readback from being mistaken for an invented invoice.
|
|
9
|
+
*/
|
|
10
|
+
import type { ToolCallError } from '../providers/types.js';
|
|
11
|
+
export interface Answer {
|
|
12
|
+
text: string;
|
|
13
|
+
/** `engine`: one of the fixed replies below, never rewritten. */
|
|
14
|
+
source: 'model' | 'engine';
|
|
15
|
+
}
|
|
16
|
+
export declare const model: (text: string) => Answer;
|
|
17
|
+
export declare const engine: (text: string) => Answer;
|
|
18
|
+
export declare const STOPPED_REPLY = "I had to stop after several steps \u2014 please try a more specific request.";
|
|
19
|
+
export declare const TOOL_CALL_FAILED_REPLY = "I couldn't put together a valid request for that. Please rephrase it with the exact values (asset, amount, recipient).";
|
|
20
|
+
export declare const REPEATED_CALL_REPLY = "I could not get a different result from the wallet \u2014 please try a more specific request.";
|
|
21
|
+
export declare function cancelledReply(declined: string[]): string;
|
|
22
|
+
/** Fed back to the model after a tool call it emitted could not be parsed. */
|
|
23
|
+
export declare function toolErrorFeedback(errors: ToolCallError[], cutOff: boolean): string;
|
|
24
|
+
export interface FinalizeOptions {
|
|
25
|
+
/** Recompute BTC figures and relabel RGB balances. */
|
|
26
|
+
fixAmounts: boolean;
|
|
27
|
+
/** Replace answers carrying payment data no tool returned and the user never typed. */
|
|
28
|
+
guardPaymentData: boolean;
|
|
29
|
+
/** What the answer may legitimately quote: the user's messages and the tool results. */
|
|
30
|
+
sources: unknown[];
|
|
31
|
+
/** Tool results, for relabelling RGB balances. */
|
|
32
|
+
toolResults: unknown[];
|
|
33
|
+
aborted: boolean;
|
|
34
|
+
}
|
|
35
|
+
/** The text the user sees. */
|
|
36
|
+
export declare function finalizeAnswer(answer: Answer, opts: FinalizeOptions): string;
|
|
37
|
+
//# sourceMappingURL=answer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answer.d.ts","sourceRoot":"","sources":["../../src/engine/answer.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAI3D,MAAM,WAAW,MAAM;IACrB,IAAI,EAAE,MAAM,CAAC;IACb,iEAAiE;IACjE,MAAM,EAAE,OAAO,GAAG,QAAQ,CAAC;CAC5B;AAED,eAAO,MAAM,KAAK,SAAU,MAAM,KAAG,MAAqC,CAAC;AAC3E,eAAO,MAAM,MAAM,SAAU,MAAM,KAAG,MAAsC,CAAC;AAE7E,eAAO,MAAM,aAAa,iFAA4E,CAAC;AAEvG,eAAO,MAAM,sBAAsB,2HACuF,CAAC;AAE3H,eAAO,MAAM,mBAAmB,kGAA6F,CAAC;AAE9H,wBAAgB,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,GAAG,MAAM,CAEzD;AAED,8EAA8E;AAC9E,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,aAAa,EAAE,EAAE,MAAM,EAAE,OAAO,GAAG,MAAM,CAMlF;AAED,MAAM,WAAW,eAAe;IAC9B,sDAAsD;IACtD,UAAU,EAAE,OAAO,CAAC;IACpB,uFAAuF;IACvF,gBAAgB,EAAE,OAAO,CAAC;IAC1B,wFAAwF;IACxF,OAAO,EAAE,OAAO,EAAE,CAAC;IACnB,kDAAkD;IAClD,WAAW,EAAE,OAAO,EAAE,CAAC;IACvB,OAAO,EAAE,OAAO,CAAC;CAClB;AAED,8BAA8B;AAC9B,wBAAgB,cAAc,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,eAAe,GAAG,MAAM,CAU5E"}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { findUngroundedPaymentData, fixSatsBtcConversions, ungroundedReply } from '../guards.js';
|
|
2
|
+
import { fixRgbBalanceUnits } from '../context/rgb-units.js';
|
|
3
|
+
export const model = (text) => ({ text, source: 'model' });
|
|
4
|
+
export const engine = (text) => ({ text, source: 'engine' });
|
|
5
|
+
export const STOPPED_REPLY = 'I had to stop after several steps — please try a more specific request.';
|
|
6
|
+
export const TOOL_CALL_FAILED_REPLY = "I couldn't put together a valid request for that. Please rephrase it with the exact values (asset, amount, recipient).";
|
|
7
|
+
export const REPEATED_CALL_REPLY = 'I could not get a different result from the wallet — please try a more specific request.';
|
|
8
|
+
export function cancelledReply(declined) {
|
|
9
|
+
return `Cancelled — you declined: ${declined.join('; ')}. Nothing was sent or changed.`;
|
|
10
|
+
}
|
|
11
|
+
/** Fed back to the model after a tool call it emitted could not be parsed. */
|
|
12
|
+
export function toolErrorFeedback(errors, cutOff) {
|
|
13
|
+
if (cutOff) {
|
|
14
|
+
return 'Your tool call was cut off because the output got too long. Make ONE tool call at a time with only the required arguments, or answer from the results you already have.';
|
|
15
|
+
}
|
|
16
|
+
const detail = errors.map((e) => e.message).join('; ');
|
|
17
|
+
return `Your tool call could not be read (${detail}). Call the tool again with valid JSON arguments that match its schema, or ask the user for the missing values.`;
|
|
18
|
+
}
|
|
19
|
+
/** The text the user sees. */
|
|
20
|
+
export function finalizeAnswer(answer, opts) {
|
|
21
|
+
if (!answer.text)
|
|
22
|
+
return opts.aborted ? '' : STOPPED_REPLY;
|
|
23
|
+
if (answer.source === 'engine')
|
|
24
|
+
return answer.text;
|
|
25
|
+
let text = answer.text;
|
|
26
|
+
if (opts.fixAmounts)
|
|
27
|
+
text = fixRgbBalanceUnits(fixSatsBtcConversions(text), opts.toolResults);
|
|
28
|
+
if (opts.guardPaymentData) {
|
|
29
|
+
const ungrounded = findUngroundedPaymentData(text, opts.sources);
|
|
30
|
+
if (ungrounded.length)
|
|
31
|
+
text = ungroundedReply(ungrounded);
|
|
32
|
+
}
|
|
33
|
+
return text;
|
|
34
|
+
}
|
|
35
|
+
//# sourceMappingURL=answer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"answer.js","sourceRoot":"","sources":["../../src/engine/answer.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,yBAAyB,EAAE,qBAAqB,EAAE,eAAe,EAAE,MAAM,cAAc,CAAC;AACjG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAQ7D,MAAM,CAAC,MAAM,KAAK,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;AAC3E,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,IAAY,EAAU,EAAE,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC;AAE7E,MAAM,CAAC,MAAM,aAAa,GAAG,yEAAyE,CAAC;AAEvG,MAAM,CAAC,MAAM,sBAAsB,GACjC,wHAAwH,CAAC;AAE3H,MAAM,CAAC,MAAM,mBAAmB,GAAG,0FAA0F,CAAC;AAE9H,MAAM,UAAU,cAAc,CAAC,QAAkB;IAC/C,OAAO,6BAA6B,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,gCAAgC,CAAC;AAC1F,CAAC;AAED,8EAA8E;AAC9E,MAAM,UAAU,iBAAiB,CAAC,MAAuB,EAAE,MAAe;IACxE,IAAI,MAAM,EAAE,CAAC;QACX,OAAO,yKAAyK,CAAC;IACnL,CAAC;IACD,MAAM,MAAM,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACvD,OAAO,qCAAqC,MAAM,iHAAiH,CAAC;AACtK,CAAC;AAcD,8BAA8B;AAC9B,MAAM,UAAU,cAAc,CAAC,MAAc,EAAE,IAAqB;IAClE,IAAI,CAAC,MAAM,CAAC,IAAI;QAAE,OAAO,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,aAAa,CAAC;IAC3D,IAAI,MAAM,CAAC,MAAM,KAAK,QAAQ;QAAE,OAAO,MAAM,CAAC,IAAI,CAAC;IACnD,IAAI,IAAI,GAAG,MAAM,CAAC,IAAI,CAAC;IACvB,IAAI,IAAI,CAAC,UAAU;QAAE,IAAI,GAAG,kBAAkB,CAAC,qBAAqB,CAAC,IAAI,CAAC,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAC9F,IAAI,IAAI,CAAC,gBAAgB,EAAE,CAAC;QAC1B,MAAM,UAAU,GAAG,yBAAyB,CAAC,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QACjE,IAAI,UAAU,CAAC,MAAM;YAAE,IAAI,GAAG,eAAe,CAAC,UAAU,CAAC,CAAC;IAC5D,CAAC;IACD,OAAO,IAAI,CAAC;AACd,CAAC"}
|
package/dist/engine.d.ts
CHANGED
|
@@ -11,11 +11,10 @@
|
|
|
11
11
|
* `{role:'tool'}` results into history each round, loop until the model stops
|
|
12
12
|
* calling tools. Money tools pause for an `onConfirm` gate; their handlers run
|
|
13
13
|
* wherever the ToolSource lives (on the phone for the wallet), even when
|
|
14
|
-
* inference
|
|
14
|
+
* inference runs on a remote server.
|
|
15
15
|
*/
|
|
16
16
|
import type { ConfirmDecision, Message, ToolResult } from './types.js';
|
|
17
|
-
import type { LLMProvider } from './providers/types.js';
|
|
18
|
-
import type { InferenceMetrics, ToolChoice } from './providers/types.js';
|
|
17
|
+
import type { InferenceMetrics, LLMProvider, ToolChoice } from './providers/types.js';
|
|
19
18
|
import type { ToolRegistry } from './tools/registry.js';
|
|
20
19
|
import { type ToolCrushOptions } from './context/compress.js';
|
|
21
20
|
import type { SkillRegistry } from './skills/registry.js';
|
|
@@ -47,6 +46,8 @@ export interface EngineOptions {
|
|
|
47
46
|
* asset balance the answer calls sats. Default true.
|
|
48
47
|
*/
|
|
49
48
|
fixAmountConversions?: boolean;
|
|
49
|
+
/** Let the model reason on a forced first tool call. Default false (thinking off). */
|
|
50
|
+
thinkOnForcedCalls?: boolean;
|
|
50
51
|
/**
|
|
51
52
|
* Answer a wallet action (create an invoice, get an address, pay, send) with
|
|
52
53
|
* a fixed "no tool" reply, without inference, when no exposed tool can do it.
|
|
@@ -98,6 +99,8 @@ export interface AgenticOptions {
|
|
|
98
99
|
* made-up data. Later rounds are left to the model.
|
|
99
100
|
*/
|
|
100
101
|
firstTurnToolChoice?: ToolChoice;
|
|
102
|
+
/** Session key passed to every model call of this run. Default: a fresh key per run. */
|
|
103
|
+
sessionKey?: string;
|
|
101
104
|
signal?: AbortSignal;
|
|
102
105
|
}
|
|
103
106
|
export interface AgenticResult {
|
|
@@ -120,6 +123,7 @@ export declare class Engine {
|
|
|
120
123
|
private readonly compressOpts?;
|
|
121
124
|
private readonly guardPaymentData;
|
|
122
125
|
private readonly fixAmounts;
|
|
126
|
+
private readonly thinkOnForcedCalls;
|
|
123
127
|
private readonly guardMissingTools;
|
|
124
128
|
private readonly endTurnOnDecline;
|
|
125
129
|
constructor(opts: EngineOptions);
|
|
@@ -133,6 +137,14 @@ export declare class Engine {
|
|
|
133
137
|
*/
|
|
134
138
|
composeSkill(skills: SkillRegistry, query: string, base: string): Promise<ComposedSkill>;
|
|
135
139
|
runAgentic(messages: Message[], opts?: AgenticOptions): Promise<AgenticResult>;
|
|
140
|
+
private runAgenticSession;
|
|
141
|
+
/** One model call within the run's session; records its receipt. */
|
|
142
|
+
private callModel;
|
|
143
|
+
/**
|
|
144
|
+
* Validate, confirm (for spends) and execute one tool call, and add its
|
|
145
|
+
* result to the history. Returns the readback when the user declined it.
|
|
146
|
+
*/
|
|
147
|
+
private executeCall;
|
|
136
148
|
/**
|
|
137
149
|
* The model ran tools but produced no visible answer (e.g. reasoning used the
|
|
138
150
|
* whole output budget). Ask once more without tools; if that is empty too,
|
package/dist/engine.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"engine.d.ts","sourceRoot":"","sources":["../src/engine.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH,OAAO,KAAK,EAAE,eAAe,EAAE,OAAO,EAAqB,UAAU,EAAE,MAAM,YAAY,CAAC;AAC1F,OAAO,KAAK,EAAE,gBAAgB,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,sBAAsB,CAAC;AACtF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACxD,OAAO,EAAsB,KAAK,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AAclF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AAC1D,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,mBAAmB,CAAC;AAG/C,MAAM,WAAW,aAAa;IAC5B,QAAQ,EAAE,WAAW,CAAC;IACtB,KAAK,EAAE,YAAY,CAAC;IACpB,uEAAuE;IACvE,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,kEAAkE;IAClE,eAAe,CAAC,EAAE,MAAM,CAAC;IACzB;;;;;;;OAOG;IACH,kBAAkB,CAAC,EAAE,OAAO,GAAG,gBAAgB,CAAC;IAChD;;;OAGG;IACH,0BAA0B,CAAC,EAAE,OAAO,CAAC;IACrC;;;;OAIG;IACH,oBAAoB,CAAC,EAAE,OAAO,CAAC;IAC/B,sFAAsF;IACtF,kBAAkB,CAAC,EAAE,OAAO,CAAC;IAC7B;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,4GAA4G;IAC5G,gBAAgB,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