crud.ts•2.99 kB
/**
* CRUD operations for people
*/
import {
AttioRecord,
Person,
PersonCreateAttributes,
} from '../../../types/attio.js';
import { createPerson } from '../../../objects/people-write.js';
import { getPersonDetails } from '../../../objects/people/index.js';
import { ToolConfig } from '../../tool-types.js';
import { formatPersonDetails, getPersonName } from './formatters.js';
export const crudToolConfigs = {
create: {
name: 'create-person',
handler: async (attributes: PersonCreateAttributes): Promise<Person> => {
try {
return await createPerson(attributes);
} catch (error: unknown) {
const errorMessage =
error instanceof Error ? error.message : String(error);
const contextualError = new Error(
`Failed to create person via adapter: ${errorMessage}`
);
(contextualError as Error & { cause?: unknown }).cause = error;
throw contextualError;
}
},
formatResult: (result: Person) =>
`Person created: ${getPersonName(
result as unknown as AttioRecord
)} (ID: ${result.id?.record_id || result.id || 'unknown'})`,
} as ToolConfig,
details: {
name: 'get-person-details',
handler: getPersonDetails,
formatResult: formatPersonDetails,
} as ToolConfig,
};
export const crudToolDefinitions = [
{
name: 'create-person',
description: 'Create a new person record in your CRM (Attio)',
inputSchema: {
type: 'object',
properties: {
attributes: {
type: 'object',
description: 'Person attributes to set',
properties: {
name: { type: 'string', description: 'Person name' },
email_addresses: {
type: 'array',
items: { type: 'string' },
description:
'Email address(es) - array of email strings. For single email, provide as single-item array.',
},
phone_numbers: {
type: 'array',
items: {
type: 'object',
properties: {
original_phone_number: { type: 'string' },
},
},
description:
'Phone numbers in format [{"original_phone_number": "+1-555-0100"}]. E.164 format (+country code) recommended. System auto-normalizes most formats. Note: Use "original_phone_number" as the key, not "phone_number".',
},
job_title: { type: 'string', description: 'Job title' },
company: { type: 'string', description: 'Company name' },
},
},
},
required: ['attributes'],
},
},
{
name: 'get-person-details',
description: 'Get details of a person',
inputSchema: {
type: 'object',
properties: {
personId: {
type: 'string',
description: 'ID of the person to get details for',
},
},
required: ['personId'],
},
},
];