#!/usr/bin/env node import { privateKeyToAccount } from 'viem/accounts'; import { BriefError, createBlockchainIqBriefTool, quoteBrief } from './index.js'; const USAGE = `Blockchain IQ LangChain market brief node src/cli.js --quote One unsigned challenge; prints price and recipient. No wallet is loaded. node src/cli.js --pay --pay-to 0xREVIEWED_RECIPIENT Invoke the LangChain tool once. Requires AGENT_PRIVATE_KEY in the environment. Exactly 0.01 USDC on Base; no retry after the one paid request. No arguments or --help prints this help without reading a key or using the network. Use a throwaway wallet with a small USDC balance; never put a key in CLI arguments. `; async function main() { const args = process.argv.slice(2); if (args.length === 0 || (args.length === 1 && args[0] === '--help')) { process.stdout.write(USAGE); return; } if (args.length === 1 && args[0] === '--quote') { process.stdout.write(JSON.stringify(await quoteBrief(), null, 2) + '\n'); return; } if (args.length !== 3 || args[0] !== '--pay' || args[1] !== '--pay-to') { throw new BriefError('INVALID_ARGUMENTS'); } // Lazy: even the private-key configuration is inspected only after quote validation. const brief = createBlockchainIqBriefTool({ expectedPayTo: args[2], signerFactory: () => { const value = process.env.AGENT_PRIVATE_KEY; if (typeof value !== 'string' || !/^0x[0-9a-fA-F]{64}$/.test(value)) { throw new BriefError('PRIVATE_KEY_CONFIGURATION_REQUIRED'); } return privateKeyToAccount(value); }, }); process.stdout.write(JSON.stringify(JSON.parse(await brief.invoke({})), null, 2) + '\n'); } main().catch(error => { const safe = error instanceof BriefError ? error : new BriefError('COMMAND_FAILED'); process.stderr.write(JSON.stringify({ error: safe.code, paymentMayHaveCommitted: safe.paymentMayHaveCommitted, instruction: 'Do not automatically repeat a failed paid call. Inspect its status separately.' }) + '\n'); process.exitCode = 1; });