|
| 1 | +import { ToolConfig } from '../types' |
| 2 | +import { ClayPopulateParams, ClayPopulateResponse } from './types' |
| 3 | + |
| 4 | +export const clayPopulateTool: ToolConfig<ClayPopulateParams, ClayPopulateResponse> = { |
| 5 | + id: 'clay_populate', |
| 6 | + name: 'Clay Populate', |
| 7 | + description: |
| 8 | + 'Populate Clay with data from a JSON file. Enables direct communication and notifications with timestamp tracking and channel confirmation.', |
| 9 | + version: '1.0.0', |
| 10 | + |
| 11 | + params: { |
| 12 | + webhookURL: { |
| 13 | + type: 'string', |
| 14 | + required: true, |
| 15 | + requiredForToolCall: true, |
| 16 | + description: 'The webhook URL to populate', |
| 17 | + }, |
| 18 | + data: { |
| 19 | + type: 'json', |
| 20 | + required: true, |
| 21 | + description: 'The data to populate', |
| 22 | + optionalToolInput: true, |
| 23 | + }, |
| 24 | + authToken: { |
| 25 | + type: 'string', |
| 26 | + required: false, |
| 27 | + description: 'Optional auth token for WebhookURL', |
| 28 | + }, |
| 29 | + }, |
| 30 | + |
| 31 | + request: { |
| 32 | + url: (params: ClayPopulateParams) => params.webhookURL, |
| 33 | + method: 'POST', |
| 34 | + headers: (params: ClayPopulateParams) => ({ |
| 35 | + 'Content-Type': 'application/json', |
| 36 | + Authorization: `Bearer ${params.authToken}`, |
| 37 | + }), |
| 38 | + body: (params: ClayPopulateParams) => ({ |
| 39 | + data: params.data, |
| 40 | + }), |
| 41 | + }, |
| 42 | + |
| 43 | + transformResponse: async (response: Response) => { |
| 44 | + const contentType = response.headers.get('content-type') |
| 45 | + let data |
| 46 | + |
| 47 | + if (contentType?.includes('application/json')) { |
| 48 | + data = await response.json() |
| 49 | + if (!data.ok) { |
| 50 | + throw new Error(data.error || 'Clay API error') |
| 51 | + } |
| 52 | + } else { |
| 53 | + // Handle text response |
| 54 | + data = await response.text() |
| 55 | + if (data !== 'OK' && !response.ok) { |
| 56 | + throw new Error(data || 'Clay API error') |
| 57 | + } |
| 58 | + } |
| 59 | + |
| 60 | + return { |
| 61 | + success: true, |
| 62 | + output: { |
| 63 | + data: contentType?.includes('application/json') ? data : { message: data }, |
| 64 | + }, |
| 65 | + } |
| 66 | + }, |
| 67 | + |
| 68 | + transformError: (error: any) => { |
| 69 | + const message = error.message || 'Clay populate failed' |
| 70 | + return message |
| 71 | + }, |
| 72 | +} |
0 commit comments