@kaleidorg/mind 0.8.1 → 0.10.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 +9 -3
- package/dist/engine.d.ts.map +1 -1
- package/dist/engine.js +159 -175
- package/dist/engine.js.map +1 -1
- package/dist/evidence.d.ts +1 -1
- package/dist/evidence.d.ts.map +1 -1
- 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/guards.d.ts.map +1 -1
- package/dist/guards.js +20 -0
- package/dist/guards.js.map +1 -1
- package/dist/index.d.ts +7 -24
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +11 -28
- package/dist/index.js.map +1 -1
- package/dist/kaleidoswap/contract.d.ts +7 -0
- package/dist/kaleidoswap/contract.d.ts.map +1 -1
- package/dist/kaleidoswap/contract.js +71 -17
- package/dist/kaleidoswap/contract.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 +3 -3
- 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 +9 -9
- package/dist/qvac/provider.d.ts.map +1 -1
- package/dist/qvac/provider.js +115 -109
- 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/recipe/asset-send.js +1 -1
- package/dist/recipe/asset-send.js.map +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/testing/mock-wallet.d.ts.map +1 -1
- package/dist/testing/mock-wallet.js +6 -0
- package/dist/testing/mock-wallet.js.map +1 -1
- package/dist/tools/in-process.d.ts +2 -2
- package/dist/tools/in-process.js +2 -2
- package/dist/wallet/contract.d.ts +5 -0
- package/dist/wallet/contract.d.ts.map +1 -1
- package/dist/wallet/contract.js +39 -6
- package/dist/wallet/contract.js.map +1 -1
- package/package.json +32 -2
- package/scripts/snapshot-mcp-tools.mjs +38 -0
- package/skills/README.md +98 -64
- package/skills/bitrefill/SKILL.md +30 -157
- package/skills/channel-manager/SKILL.md +31 -52
- package/skills/flashnet-swaps/SKILL.md +24 -150
- package/skills/kaleido-node/SKILL.md +25 -55
- package/skills/kaleido-trading/SKILL.md +28 -172
- package/skills/kaleido-trading/references/assets.md +4 -4
- package/skills/kaleido-trading/references/atomic.md +5 -7
- package/skills/merchant-finder/SKILL.md +25 -108
- package/skills/paid-data/SKILL.md +25 -58
- package/skills/portfolio-manager/SKILL.md +26 -60
- package/skills/rgb-lightning-node/SKILL.md +37 -255
- package/skills/rgb-lightning-node/references/channels.md +34 -0
- package/skills/spark-wallet/SKILL.md +26 -228
- package/skills/submarine-swaps/SKILL.md +19 -37
- package/skills/wallet-assistant/SKILL.md +26 -44
- 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.ts +185 -194
- package/src/evidence.ts +1 -1
- package/src/flashnet/index.ts +14 -0
- package/src/funnel.mind.test.ts +6 -5
- package/src/guards.test.ts +12 -0
- package/src/guards.ts +20 -0
- package/src/index.ts +11 -107
- package/src/kaleidoswap/contract.test.ts +32 -3
- package/src/kaleidoswap/contract.ts +65 -17
- package/src/kaleidoswap/index.ts +20 -0
- package/src/knowledge/index.ts +14 -0
- package/src/lsps1/index.ts +13 -0
- package/src/providers/types.ts +3 -3
- package/src/qvac/index.ts +0 -8
- package/src/qvac/provider.test.ts +17 -17
- package/src/qvac/provider.ts +33 -31
- package/src/qvac/stream.ts +4 -3
- package/src/qvac/voice.ts +1 -1
- package/src/recipe/asset-send.ts +1 -1
- package/src/recipe/recipe.test.ts +1 -1
- package/src/skills/catalog.test.ts +215 -0
- package/src/skills/mcp-tools.snapshot.json +1938 -0
- package/src/submarine/index.ts +17 -0
- package/src/testing/mock-wallet.ts +6 -0
- package/src/tools/in-process.ts +2 -2
- package/src/wallet/contract.test.ts +20 -1
- package/src/wallet/contract.ts +36 -6
- 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/skills/dca/SKILL.md +0 -48
- package/skills/kaleido-lsps/SKILL.md +0 -131
- package/skills/liquidity-optimizer/SKILL.md +0 -91
- package/src/qvac/delegate.test.ts +0 -68
- package/src/qvac/delegate.ts +0 -73
|
@@ -1,48 +1,30 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: submarine-swaps
|
|
3
|
-
description: "Pay a Lightning invoice from Liquid funds (L-USDT or L-BTC) through a KaleidoSwap submarine swap
|
|
3
|
+
description: "Pay a Lightning invoice from Liquid funds (L-USDT or L-BTC) through a KaleidoSwap submarine swap, and follow its status."
|
|
4
4
|
tools: kaleidoswap_submarine_pairs, kaleidoswap_submarine_create, kaleidoswap_submarine_fund, kaleidoswap_submarine_status
|
|
5
|
-
|
|
5
|
+
requires-tools: kaleidoswap_submarine_create
|
|
6
|
+
triggers: l-usdt, liquid usdt, usdt on liquid, l-btc, liquid bitcoin, submarine, submarine swap, pay invoice with liquid
|
|
6
7
|
metadata:
|
|
7
8
|
author: kaleidoswap
|
|
8
|
-
version: "0.
|
|
9
|
+
version: "0.2.0"
|
|
9
10
|
---
|
|
11
|
+
# Submarine swaps
|
|
10
12
|
|
|
11
|
-
|
|
13
|
+
The user locks Liquid funds; the maker pays the Lightning invoice, then claims
|
|
14
|
+
the lockup. If the maker can't pay, the lockup is refundable. Plain "USDT" is
|
|
15
|
+
RGB USDT (`kaleido-trading`), not this skill.
|
|
12
16
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
## Critical rules
|
|
18
|
-
|
|
19
|
-
- Every amount, fee and status in your reply MUST come from a tool result in the
|
|
20
|
-
CURRENT turn. Never guess the amount to lock — `kaleidoswap_submarine_create`
|
|
21
|
-
returns it.
|
|
22
|
-
- `kaleidoswap_submarine_fund` moves money. Call it ONLY after the user has
|
|
23
|
-
confirmed the exact `expected_amount` returned by `kaleidoswap_submarine_create`.
|
|
24
|
-
- `kaleidoswap_submarine_fund` takes only `swap_id`. Never try to pass an amount
|
|
25
|
-
or an address.
|
|
26
|
-
- A bare "USDT" means RGB USDT on the Lightning node, which uses the atomic swap
|
|
27
|
-
tools, not this skill. Use this skill only for Liquid assets (L-USDT, L-BTC).
|
|
28
|
-
|
|
29
|
-
## Flow
|
|
30
|
-
|
|
31
|
-
1. `kaleidoswap_submarine_create { invoice, from_asset }` — from_asset is
|
|
32
|
-
`L-USDT` (default) or `L-BTC`. Returns `swap_id`, `expected_amount` (smallest
|
|
33
|
-
unit: L-USDT has 8 decimals, L-BTC is sats) and the fees.
|
|
17
|
+
## Do
|
|
18
|
+
1. `kaleidoswap_submarine_create` (`invoice`, `from_asset`) — `from_asset` is
|
|
19
|
+
`L-USDT` (default) or `L-BTC`. Returns `swap_id`, `expected_amount`
|
|
20
|
+
(smallest unit, 8 decimals for both) and fees. Nothing moves yet.
|
|
34
21
|
2. Tell the user the amount and ask to confirm.
|
|
35
|
-
3. `kaleidoswap_submarine_fund
|
|
36
|
-
4. `kaleidoswap_submarine_status
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
Use `kaleidoswap_submarine_pairs` when the user asks what can pay a Lightning
|
|
41
|
-
invoice, or for the limits and fees.
|
|
22
|
+
3. `kaleidoswap_submarine_fund` (`swap_id` only; confirm-gated).
|
|
23
|
+
4. `kaleidoswap_submarine_status` (`swap_id`) — `transaction.claimed` means paid;
|
|
24
|
+
`failed: true` on a funded swap needs a refund: quote the `refund` field.
|
|
25
|
+
- Limits and fees: `kaleidoswap_submarine_pairs {}`.
|
|
42
26
|
|
|
43
27
|
## Examples
|
|
44
|
-
|
|
45
|
-
- "
|
|
46
|
-
|
|
47
|
-
- "did my Liquid payment go through? swap sub1" →
|
|
48
|
-
`kaleidoswap_submarine_status { swap_id: "sub1" }`
|
|
28
|
+
- "Pay lntbs10u1p… with L-USDT" → `kaleidoswap_submarine_create {"invoice":"lntbs10u1p…","from_asset":"L-USDT"}`
|
|
29
|
+
- "Did swap sub1 go through?" → `kaleidoswap_submarine_status {"swap_id":"sub1"}`
|
|
30
|
+
- "What can pay Lightning from Liquid?" → `kaleidoswap_submarine_pairs {}`
|
|
@@ -1,49 +1,31 @@
|
|
|
1
1
|
---
|
|
2
2
|
name: wallet-assistant
|
|
3
|
-
description: Everyday wallet tasks
|
|
4
|
-
tools: get_balances,
|
|
5
|
-
|
|
3
|
+
description: "Everyday wallet tasks in the app across all layers: balance, receive (invoice or address), send or pay, contacts, BTC price and fiat conversion."
|
|
4
|
+
tools: get_balances, create_invoice, send_payment, resolve_contact, get_price, fiat_to_sats, rln_list_assets, rln_pay_invoice, spark_pay_invoice
|
|
5
|
+
requires-tools: get_balances
|
|
6
|
+
triggers: balance, balances, pay, send, receive, address, invoice, contact, funds, money, price, how much
|
|
7
|
+
metadata:
|
|
8
|
+
author: kaleidoswap
|
|
9
|
+
version: "0.3.0"
|
|
6
10
|
---
|
|
7
|
-
|
|
8
11
|
# Wallet assistant
|
|
9
12
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
##
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
-
|
|
28
|
-
|
|
29
|
-
yourself.
|
|
30
|
-
|
|
31
|
-
## Rules
|
|
32
|
-
|
|
33
|
-
- **Balance / "how much do I have"** → use the balance tool, then state the
|
|
34
|
-
number.
|
|
35
|
-
- **Receive / "an invoice for N sats"** → use the invoice creation tool (for
|
|
36
|
-
the appropriate layer) with the amount.
|
|
37
|
-
- **"How many sats is N USDT?" / "What's 0.1 BTC in USDT?" / "convert N X
|
|
38
|
-
to Y"** → use the quote/conversion tool and
|
|
39
|
-
read the display fields from the result. Supported pairs: any of
|
|
40
|
-
BTC/USDT/XAUT against each other. Fiat (EUR/USD/GBP) is NOT quoted by
|
|
41
|
-
the maker — if the user asks "how much sats is 10 EUR", say so plainly
|
|
42
|
-
and offer USDT as the closest analogue (USDT is a USD-pegged stablecoin).
|
|
43
|
-
- **Pay a Lightning invoice** → use the lightning payment tool.
|
|
44
|
-
- **Send to a person/amount** → first resolve the contact, then use the send
|
|
45
|
-
payment tool with the amount in sats and the recipient. State the amount and
|
|
46
|
-
destination; the app asks the user to confirm before it sends.
|
|
47
|
-
|
|
48
|
-
Keep replies short, but never drop a balance component, a fee, or the
|
|
49
|
-
quote's `rfq_id` when present.
|
|
13
|
+
The app routes these tools to the right layer (Spark, RLN, Arkade, Liquid).
|
|
14
|
+
`amount_sats` is satoshis; other amounts are display units of the asset.
|
|
15
|
+
|
|
16
|
+
## Do
|
|
17
|
+
- Balance: `get_balances` (add `layer` for one layer). Report every component;
|
|
18
|
+
`pending` is not spendable yet.
|
|
19
|
+
- Receive: `create_invoice` with `asset` and optional `amount`; reply with the
|
|
20
|
+
full invoice or address returned.
|
|
21
|
+
- Send to a name: `resolve_contact` first, then `send_payment`. A BOLT11
|
|
22
|
+
invoice the user pasted: `rln_pay_invoice` or `spark_pay_invoice`. Every
|
|
23
|
+
send is confirm-gated; state amount and destination.
|
|
24
|
+
- Fiat: `fiat_to_sats` converts; `get_price` gives the BTC price.
|
|
25
|
+
- Swaps go to `kaleido-trading` (RGB) or `flashnet-swaps` (Spark tokens).
|
|
26
|
+
|
|
27
|
+
## Examples
|
|
28
|
+
- "What's my balance?" → `get_balances {}`
|
|
29
|
+
- "Invoice for 2000 sats" → `create_invoice {"asset":"BTC","amount":2000}`
|
|
30
|
+
- "Send 5000 sats to bob" → `resolve_contact {"name":"bob"}` then `send_payment {"to":"<bob's address>","amount_sats":5000}`
|
|
31
|
+
- "How many sats is 10 EUR?" → `fiat_to_sats {"amount":10,"currency":"EUR"}`
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Bitrefill (gift cards, top-ups, eSIMs): tool contract. */
|
|
2
|
+
export {
|
|
3
|
+
BITREFILL_TOOLS,
|
|
4
|
+
BITREFILL_SPEND_TOOLS,
|
|
5
|
+
isBitrefillSpendTool,
|
|
6
|
+
getBitrefillTool,
|
|
7
|
+
bindBitrefillTools,
|
|
8
|
+
} from './contract.js';
|
|
9
|
+
export type {
|
|
10
|
+
BitrefillToolDef,
|
|
11
|
+
BitrefillHandler,
|
|
12
|
+
BindBitrefillOptions,
|
|
13
|
+
} from './contract.js';
|
package/src/capabilities.ts
CHANGED
|
@@ -16,8 +16,8 @@ export interface CapabilityInput {
|
|
|
16
16
|
modelCtxTokens: number;
|
|
17
17
|
/** Whether an EmbeddingProvider is wired (QVAC embed, etc.). */
|
|
18
18
|
hasEmbeddings?: boolean;
|
|
19
|
-
/**
|
|
20
|
-
|
|
19
|
+
/** Inference runs on a larger remote model (e.g. an OpenAI-compatible server) — relaxes limits. */
|
|
20
|
+
remote?: boolean;
|
|
21
21
|
}
|
|
22
22
|
|
|
23
23
|
export interface MindCapabilities {
|
|
@@ -27,7 +27,7 @@ export interface MindCapabilities {
|
|
|
27
27
|
semanticMemory: boolean;
|
|
28
28
|
/** Embedding-only dedup of near-duplicate memories (zero inference — mobile-safe). */
|
|
29
29
|
dedupeMemory: boolean;
|
|
30
|
-
/** LLM merge of near-duplicate memories (an extra inference — capable/
|
|
30
|
+
/** LLM merge of near-duplicate memories (an extra inference — capable/remote only). */
|
|
31
31
|
mergeMemory: boolean;
|
|
32
32
|
/** Retrieval-augmented generation (needs embeddings + enough RAM/context). */
|
|
33
33
|
rag: boolean;
|
|
@@ -42,7 +42,7 @@ export interface MindCapabilities {
|
|
|
42
42
|
const GiB = 1024 * 1024 * 1024;
|
|
43
43
|
|
|
44
44
|
export function capabilityProfile(input: CapabilityInput): MindCapabilities {
|
|
45
|
-
const ramGb = input.
|
|
45
|
+
const ramGb = input.remote ? Infinity : (input.ramBytes ?? 0) / GiB;
|
|
46
46
|
const ctx = input.modelCtxTokens;
|
|
47
47
|
const hasEmb = !!input.hasEmbeddings;
|
|
48
48
|
|
|
@@ -54,13 +54,13 @@ export function capabilityProfile(input: CapabilityInput): MindCapabilities {
|
|
|
54
54
|
|
|
55
55
|
// Consolidation: embedding-only dedup is cheap (no inference) — on wherever
|
|
56
56
|
// semantic memory is. The LLM merge costs an extra inference, so reserve it
|
|
57
|
-
// for
|
|
57
|
+
// for remote or roomy on-device setups; never run it on a tiny phone model.
|
|
58
58
|
const dedupeMemory = semanticMemory;
|
|
59
|
-
const mergeMemory = dedupeMemory && (input.
|
|
59
|
+
const mergeMemory = dedupeMemory && (input.remote || (ramGb >= 4 && ctx >= 4096));
|
|
60
60
|
|
|
61
61
|
// RAG is the expensive one: needs embeddings, a non-tiny context window, and
|
|
62
62
|
// (on-device) enough RAM to hold an embedding model + index.
|
|
63
|
-
const rag = hasEmb && ctx >= 4096 && (input.
|
|
63
|
+
const rag = hasEmb && ctx >= 4096 && (input.remote || ramGb >= 3);
|
|
64
64
|
|
|
65
65
|
// Scale how much we pull in with the available window.
|
|
66
66
|
const topKMemory = budget >= 1500 ? 4 : budget >= 700 ? 3 : 2;
|
|
@@ -69,8 +69,8 @@ describe('capabilityProfile', () => {
|
|
|
69
69
|
expect(c.mergeMemory).toBe(false); // never run merge inference on a tiny phone
|
|
70
70
|
});
|
|
71
71
|
|
|
72
|
-
it('
|
|
73
|
-
const c = capabilityProfile({ modelCtxTokens: 8192, hasEmbeddings: true,
|
|
72
|
+
it('remote model: RAG on, memory merge on', () => {
|
|
73
|
+
const c = capabilityProfile({ modelCtxTokens: 8192, hasEmbeddings: true, remote: true });
|
|
74
74
|
expect(c.rag).toBe(true);
|
|
75
75
|
expect(c.topKRag).toBeGreaterThan(0);
|
|
76
76
|
expect(c.semanticMemory).toBe(true);
|
|
@@ -0,0 +1,66 @@
|
|
|
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
|
+
import { findUngroundedPaymentData, fixSatsBtcConversions, ungroundedReply } from '../guards.js';
|
|
12
|
+
import { fixRgbBalanceUnits } from '../context/rgb-units.js';
|
|
13
|
+
|
|
14
|
+
export interface Answer {
|
|
15
|
+
text: string;
|
|
16
|
+
/** `engine`: one of the fixed replies below, never rewritten. */
|
|
17
|
+
source: 'model' | 'engine';
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export const model = (text: string): Answer => ({ text, source: 'model' });
|
|
21
|
+
export const engine = (text: string): Answer => ({ text, source: 'engine' });
|
|
22
|
+
|
|
23
|
+
export const STOPPED_REPLY = 'I had to stop after several steps — please try a more specific request.';
|
|
24
|
+
|
|
25
|
+
export const TOOL_CALL_FAILED_REPLY =
|
|
26
|
+
"I couldn't put together a valid request for that. Please rephrase it with the exact values (asset, amount, recipient).";
|
|
27
|
+
|
|
28
|
+
export const REPEATED_CALL_REPLY = 'I could not get a different result from the wallet — please try a more specific request.';
|
|
29
|
+
|
|
30
|
+
export function cancelledReply(declined: string[]): string {
|
|
31
|
+
return `Cancelled — you declined: ${declined.join('; ')}. Nothing was sent or changed.`;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** Fed back to the model after a tool call it emitted could not be parsed. */
|
|
35
|
+
export function toolErrorFeedback(errors: ToolCallError[], cutOff: boolean): string {
|
|
36
|
+
if (cutOff) {
|
|
37
|
+
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.';
|
|
38
|
+
}
|
|
39
|
+
const detail = errors.map((e) => e.message).join('; ');
|
|
40
|
+
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.`;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FinalizeOptions {
|
|
44
|
+
/** Recompute BTC figures and relabel RGB balances. */
|
|
45
|
+
fixAmounts: boolean;
|
|
46
|
+
/** Replace answers carrying payment data no tool returned and the user never typed. */
|
|
47
|
+
guardPaymentData: boolean;
|
|
48
|
+
/** What the answer may legitimately quote: the user's messages and the tool results. */
|
|
49
|
+
sources: unknown[];
|
|
50
|
+
/** Tool results, for relabelling RGB balances. */
|
|
51
|
+
toolResults: unknown[];
|
|
52
|
+
aborted: boolean;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
/** The text the user sees. */
|
|
56
|
+
export function finalizeAnswer(answer: Answer, opts: FinalizeOptions): string {
|
|
57
|
+
if (!answer.text) return opts.aborted ? '' : STOPPED_REPLY;
|
|
58
|
+
if (answer.source === 'engine') return answer.text;
|
|
59
|
+
let text = answer.text;
|
|
60
|
+
if (opts.fixAmounts) text = fixRgbBalanceUnits(fixSatsBtcConversions(text), opts.toolResults);
|
|
61
|
+
if (opts.guardPaymentData) {
|
|
62
|
+
const ungrounded = findUngroundedPaymentData(text, opts.sources);
|
|
63
|
+
if (ungrounded.length) text = ungroundedReply(ungrounded);
|
|
64
|
+
}
|
|
65
|
+
return text;
|
|
66
|
+
}
|