fix(arch): inject WalletPort into tool execution context (ENG-233)#43
Open
fix(arch): inject WalletPort into tool execution context (ENG-233)#43
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
All wallet tools were throwing
WalletPort not injectederrors. TheFlashAPIAdapterexisted 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
ToolExecutionContexthad nowalletPortfield.AgentLoopbuilt the context inline with no adapter reference.AgentOrchestratorandindex.tsnever passed the adapter down.Changes
Core wiring:
ToolExecutionContext: add requiredwalletPort: WalletPortAgentLoop: accept + injectwalletPortintoexecContextAgentOrchestrator: accept + passwalletPorttoAgentLoopapp.module.ts+index.ts: wireFlashAPIAdapteras theWalletPortAuth token flow:
UserContext.IdentitySchema: addauthTokenfieldVerifyOTP: persistauthTokeninto context after successful OTPwalletPort.setAuthToken(accountId, token)per requestTool implementations: All 6 wallet tools fully implemented via adapter injection.
Tests: ToolRegistry, AgentOrchestrator, CheckBalance suites updated. 496 tests pass.
Verification
Closes #40
Resolves ENG-233