import { z } from 'zod';
import type { RegistryApiClient } from '../client/api.js';
import type { Config } from '../config/index.js';
import { getPublicKey } from '../crypto/signing.js';
export const whoamiInputSchema = z.object({});
export type WhoamiInput = z.infer<typeof whoamiInputSchema>;
export interface WhoamiResult {
origin: string;
keyId: string;
publicKey: string;
agent?: {
id: string;
name: string;
description: string | null;
visibility: string;
status: string;
domain: string | null;
capabilities: string[] | null;
};
registryConnected: boolean;
error?: string;
}
/**
* Get information about this agent's identity.
*
* Returns local configuration info and optionally fetches
* the registered agent details from the registry.
*/
export async function whoami(
_input: WhoamiInput,
config: Config,
client: RegistryApiClient
): Promise<WhoamiResult> {
// Always return local identity info
const publicKey = await getPublicKey(config.privateKey);
const result: WhoamiResult = {
origin: config.origin,
keyId: config.pubkeyId,
publicKey,
registryConnected: false,
};
// Try to fetch registered agent info
try {
const response = await client.whoami();
result.registryConnected = true;
result.agent = {
id: response.agent.id,
name: response.agent.name,
description: response.agent.description,
visibility: response.agent.visibility,
status: response.agent.status,
domain: response.agent.domain,
capabilities: response.agent.capabilities,
};
} catch (error) {
result.error =
error instanceof Error
? `Failed to connect to registry: ${error.message}`
: 'Failed to connect to registry';
}
return result;
}
export const whoamiTool = {
name: 'agents_registry_whoami',
description: 'Get information about this agent\'s identity, including origin, public key, and registered agent details',
inputSchema: {
type: 'object' as const,
properties: {},
required: [] as string[],
},
};