import { ParaClient } from '../para-client.js';
import type { Wallet } from '../types.js';
export const definition = {
name: 'list_wallets',
description:
'Batch-fetch multiple wallets by their IDs. Para has no native list endpoint, so this fetches each wallet individually via Promise.allSettled. Maximum 10 IDs per call.',
inputSchema: {
type: 'object' as const,
properties: {
walletIds: {
type: 'array',
items: { type: 'string' },
description: 'Array of wallet IDs to fetch (max 10)',
},
},
required: ['walletIds'],
},
};
export async function handler(client: ParaClient, args: Record<string, unknown>) {
const walletIds = args.walletIds as string[];
if (!Array.isArray(walletIds) || walletIds.length === 0) {
return {
content: [{ type: 'text' as const, text: 'Error: walletIds must be a non-empty array.' }],
isError: true,
};
}
if (walletIds.length > 10) {
return {
content: [{ type: 'text' as const, text: 'Error: Maximum 10 wallet IDs per call.' }],
isError: true,
};
}
const results = await Promise.allSettled(
walletIds.map((id) => client.requestWithRetry<Wallet>(`/v1/wallets/${id}`)),
);
const wallets = results.map((result, i) => {
if (result.status === 'fulfilled') {
return { walletId: walletIds[i], ...result.value };
}
return {
walletId: walletIds[i],
error: result.reason instanceof Error ? result.reason.message : String(result.reason),
};
});
return {
content: [
{
type: 'text' as const,
text: JSON.stringify({ wallets }, null, 2),
},
],
};
}