Skip to content

fix(arch): inject WalletPort into tool execution context (ENG-233)#43

Open
patoo0x wants to merge 2 commits intov5from
fix/eng-233-wallet-adapter-injection
Open

fix(arch): inject WalletPort into tool execution context (ENG-233)#43
patoo0x wants to merge 2 commits intov5from
fix/eng-233-wallet-adapter-injection

Conversation

@patoo0x
Copy link

@patoo0x patoo0x commented Mar 20, 2026

Problem

All wallet tools were throwing WalletPort not injected errors. The FlashAPIAdapter existed but was never wired into the tool execution path. Direct API calls had been patched as a workaround, bypassing the port interface and breaking on any refactor.

Root Cause

ToolExecutionContext had no walletPort field. AgentLoop built the context inline with no adapter reference. AgentOrchestrator and index.ts never passed the adapter down.

Changes

Core wiring:

  • ToolExecutionContext: add required walletPort: WalletPort
  • AgentLoop: accept + inject walletPort into execContext
  • AgentOrchestrator: accept + pass walletPort to AgentLoop
  • app.module.ts + index.ts: wire FlashAPIAdapter as the WalletPort

Auth token flow:

  • UserContext.IdentitySchema: add authToken field
  • VerifyOTP: persist authToken into context after successful OTP
  • Wallet tools call walletPort.setAuthToken(accountId, token) per request

Tool implementations: All 6 wallet tools fully implemented via adapter injection.

Tests: ToolRegistry, AgentOrchestrator, CheckBalance suites updated. 496 tests pass.

Verification

Test Suites: 18 passed, 18 total
Tests:       496 passed, 496 total

Closes #40
Resolves ENG-233

patoo0x added 2 commits March 20, 2026 12:45
TypeScript compiler does not copy non-.ts assets. PromptLoader resolves
prompts from dist/prompts/ at runtime — without this copy step, the
directory was missing after a clean build, causing prompt load failures.

Fix:
- Add scripts/copy-prompts.js: mirrors src/prompts/ → dist/prompts/
- Wire into build script: 'tsc && node scripts/copy-prompts.js'

Result: single canonical dist/prompts/ path, no duplication, build
verified clean (11 .md files copied across 3 subdirs).

Closes #39
Resolves ENG-232
Wallet tools (CheckBalance, SendPayment, ReceivePayment, GetTransactionHistory,
GetExchangeRate, EstimateFee) were throwing 'WalletPort not injected' errors
because the adapter was never passed into the tool execution path.

Changes:
- ToolExecutionContext: add required walletPort: WalletPort field
- AgentLoop: accept walletPort in constructor, thread into execContext
- AgentOrchestrator: accept walletPort in constructor, pass to AgentLoop
- app.module.ts + index.ts: wire FlashAPIAdapter into AgentOrchestrator
- UserContext.IdentitySchema: add authToken field (set by VerifyOTP)
- UserContext.PartialIdentityInput: expose authToken for test factories
- VerifyOTP: persist authToken into identity context after successful OTP
- All wallet tools: implement execute() using injected walletPort
  - CheckBalance: getBalance() with token registration
  - SendPayment: sendPayment() with idempotency key
  - ReceivePayment: createInvoice() with optional amount/expiry
  - GetTransactionHistory: getTransactionHistory() with filters
  - GetExchangeRate: getExchangeRate() (no auth required)
  - EstimateFee: estimateFee() with token registration
- Tests: update ToolRegistry, AgentOrchestrator, CheckBalance test suites

Result: all 496 tests pass, no direct Flash API calls in tool layer.

Closes #40
Resolves ENG-233
@linear
Copy link

linear bot commented Mar 20, 2026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant