/** * ROB Domains — Claude (Anthropic) SDK Integration Example * * Demonstrates using the ROB Domains Agent API with Claude's tool_use feature. * Covers Search, Mint, Set Primary, and Update Profile. * * Requires: npm install @anthropic-ai/sdk */ import Anthropic from '@anthropic-ai/sdk'; const client = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY }); const BASE_URL = 'https://robdn.com'; // ─── Tool Definitions ───────────────────────────────────────────────────────── const ROB_DOMAINS_TOOLS: Anthropic.Tool[] = [ { name: 'search_rob_domain', description: 'Search for a .rob domain name. Returns availability, owner, tokenId, primary owner, and profile summary.', input_schema: { type: 'object', properties: { domain: { type: 'string', description: 'Domain label without ".rob" suffix (e.g. "alice")', }, }, required: ['domain'], }, }, { name: 'get_rob_profile', description: 'Get the full on-chain profile for a .rob domain.', input_schema: { type: 'object', properties: { domain: { type: 'string' }, }, required: ['domain'], }, }, { name: 'reverse_resolve_rob', description: 'Reverse-resolve an Ethereum wallet to its primary .rob domain.', input_schema: { type: 'object', properties: { wallet: { type: 'string', description: 'Ethereum wallet address (0x-prefixed)' }, }, required: ['wallet'], }, }, { name: 'build_mint_transaction', description: 'Generate an unsigned mint transaction payload for a .rob domain. User must sign and broadcast.', input_schema: { type: 'object', properties: { domain: { type: 'string', description: 'Domain label (e.g. "alice")' }, }, required: ['domain'], }, }, { name: 'build_set_primary_transaction', description: 'Generate an unsigned set-primary transaction payload for a .rob domain.', input_schema: { type: 'object', properties: { tokenId: { type: 'string' }, wallet: { type: 'string' }, }, required: ['tokenId', 'wallet'], }, }, { name: 'build_update_profile_transaction', description: 'Generate unsigned update-profile transaction payload(s) for a .rob domain.', input_schema: { type: 'object', properties: { tokenId: { type: 'string' }, bio: { type: 'string' }, profilePicture: { type: 'string' }, coverImage: { type: 'string' }, background: { type: 'string' }, socialLinks: { type: 'array', items: { type: 'object', properties: { platform: { type: 'string' }, url: { type: 'string' }, }, }, }, customLinks: { type: 'array', items: { type: 'object', properties: { title: { type: 'string' }, url: { type: 'string' }, }, }, }, }, required: ['tokenId'], }, }, { name: 'register_domain_workflow', description: 'Get a complete multi-step execution plan for registering a .rob domain (mint + optional primary + optional profile).', input_schema: { type: 'object', properties: { domain: { type: 'string' }, wallet: { type: 'string' }, setPrimary: { type: 'boolean' }, profile: { type: 'object', properties: { bio: { type: 'string' }, profilePicture: { type: 'string' }, socialLinks: { type: 'array', items: { type: 'object' } }, }, }, }, required: ['domain', 'wallet'], }, }, ]; // ─── Tool Execution ─────────────────────────────────────────────────────────── async function executeTool(name: string, input: Record): Promise { const handlers: Record Promise> = { search_rob_domain: () => fetch(`${BASE_URL}/agent/search/${input.domain}`), get_rob_profile: () => fetch(`${BASE_URL}/agent/profile/${input.domain}`), reverse_resolve_rob: () => fetch(`${BASE_URL}/agent/reverse/${input.wallet}`), build_mint_transaction: () => fetch(`${BASE_URL}/agent/tx/mint`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ domain: input.domain }), }), build_set_primary_transaction: () => fetch(`${BASE_URL}/agent/tx/set-primary`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify({ tokenId: input.tokenId, wallet: input.wallet }), }), build_update_profile_transaction: () => fetch(`${BASE_URL}/agent/tx/update-profile`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input), }), register_domain_workflow: () => fetch(`${BASE_URL}/agent/workflow/register-domain`, { method: 'POST', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(input), }), }; const res = await handlers[name](); return res.json(); } // ─── Agent Loop ─────────────────────────────────────────────────────────────── async function robDomainsAgent(userMessage: string): Promise { const messages: Anthropic.MessageParam[] = [ { role: 'user', content: userMessage }, ]; while (true) { const response = await client.messages.create({ model: 'claude-opus-4-5', max_tokens: 4096, system: 'You are a helpful assistant for ROB Domains (.rob), a Web3 domain name system on Robinhood Chain. Help users search domains, read profiles, and generate unsigned transaction payloads. Always remind users they must sign and broadcast payloads — the API never executes on their behalf.', messages, tools: ROB_DOMAINS_TOOLS, }); messages.push({ role: 'assistant', content: response.content }); if (response.stop_reason === 'end_turn') { const textBlock = response.content.find((b) => b.type === 'text'); return textBlock?.type === 'text' ? textBlock.text : ''; } if (response.stop_reason === 'tool_use') { const toolResults: Anthropic.ToolResultBlockParam[] = []; for (const block of response.content) { if (block.type === 'tool_use') { const result = await executeTool(block.name, block.input as Record); toolResults.push({ type: 'tool_result', tool_use_id: block.id, content: JSON.stringify(result), }); } } messages.push({ role: 'user', content: toolResults }); } } } // ─── Demo ───────────────────────────────────────────────────────────────────── async function main() { console.log('─── Search ───'); console.log(await robDomainsAgent('Check if "alice.rob" is available.')); console.log('\n─── Profile ───'); console.log(await robDomainsAgent('Show me the profile for "rob.rob".')); console.log('\n─── Full Registration Workflow ───'); console.log( await robDomainsAgent( 'I want to register "alice.rob" for my wallet 0xAbCd1234567890AbCd1234567890AbCd12345678. Set it as my primary domain and set my bio to "Web3 builder". Give me the full plan.' ) ); } main().catch(console.error);