|
| 1 | +import { |
| 2 | + DESTINATION_PROPERTIES, |
| 3 | + type FivetranCreateDestinationParams, |
| 4 | + type FivetranDestinationResponse, |
| 5 | +} from '@/tools/fivetran/types' |
| 6 | +import { |
| 7 | + compactBody, |
| 8 | + envelopeData, |
| 9 | + FIVETRAN_AUTH_PARAMS, |
| 10 | + FIVETRAN_ERROR_EXTRACTOR, |
| 11 | + FIVETRAN_OAUTH, |
| 12 | + FIVETRAN_TRUST_PARAMS, |
| 13 | + fivetranHeaders, |
| 14 | + fivetranUrl, |
| 15 | + mapDestination, |
| 16 | + optionalBoolean, |
| 17 | + parseJsonObject, |
| 18 | + trimmed, |
| 19 | +} from '@/tools/fivetran/utils' |
| 20 | +import type { ToolConfig } from '@/tools/types' |
| 21 | + |
| 22 | +export const fivetranCreateDestinationTool: ToolConfig< |
| 23 | + FivetranCreateDestinationParams, |
| 24 | + FivetranDestinationResponse |
| 25 | +> = { |
| 26 | + id: 'fivetran_create_destination', |
| 27 | + name: 'Fivetran Create Destination', |
| 28 | + description: |
| 29 | + 'Create the destination for a Fivetran group, such as a Databricks workspace. The config object holds the destination-specific connection settings.', |
| 30 | + version: '1.0.0', |
| 31 | + errorExtractor: FIVETRAN_ERROR_EXTRACTOR, |
| 32 | + oauth: FIVETRAN_OAUTH, |
| 33 | + |
| 34 | + params: { |
| 35 | + ...FIVETRAN_AUTH_PARAMS, |
| 36 | + groupId: { |
| 37 | + type: 'string', |
| 38 | + required: true, |
| 39 | + visibility: 'user-or-llm', |
| 40 | + description: 'ID of the group the destination belongs to (each group has one destination)', |
| 41 | + }, |
| 42 | + service: { |
| 43 | + type: 'string', |
| 44 | + required: true, |
| 45 | + visibility: 'user-or-llm', |
| 46 | + description: 'Destination type, e.g. databricks, snowflake, or big_query', |
| 47 | + }, |
| 48 | + timeZoneOffset: { |
| 49 | + type: 'string', |
| 50 | + required: true, |
| 51 | + visibility: 'user-or-llm', |
| 52 | + description: 'UTC offset used for sync scheduling, from -11 to +12, e.g. -5 or 0', |
| 53 | + }, |
| 54 | + region: { |
| 55 | + type: 'string', |
| 56 | + required: false, |
| 57 | + visibility: 'user-or-llm', |
| 58 | + description: 'Data processing region, e.g. AWS_US_EAST_1 or GCP_US_EAST4', |
| 59 | + }, |
| 60 | + config: { |
| 61 | + type: 'json', |
| 62 | + required: false, |
| 63 | + visibility: 'user-or-llm', |
| 64 | + description: |
| 65 | + 'Destination-specific settings, e.g. for Databricks {"server_host_name": "...", "http_path": "...", "catalog": "...", "auth_type": "PERSONAL_ACCESS_TOKEN", "personal_access_token": "..."}', |
| 66 | + }, |
| 67 | + daylightSavingTimeEnabled: { |
| 68 | + type: 'boolean', |
| 69 | + required: false, |
| 70 | + visibility: 'user-or-llm', |
| 71 | + description: 'Shift the UTC offset with daylight saving time (US only)', |
| 72 | + }, |
| 73 | + runSetupTests: { |
| 74 | + type: 'boolean', |
| 75 | + required: false, |
| 76 | + visibility: 'user-or-llm', |
| 77 | + description: 'Run the setup tests after creating the destination', |
| 78 | + }, |
| 79 | + ...FIVETRAN_TRUST_PARAMS, |
| 80 | + }, |
| 81 | + |
| 82 | + request: { |
| 83 | + url: () => fivetranUrl('/destinations'), |
| 84 | + method: 'POST', |
| 85 | + headers: (params) => fivetranHeaders(params), |
| 86 | + body: (params) => |
| 87 | + compactBody({ |
| 88 | + group_id: params.groupId?.trim(), |
| 89 | + service: params.service?.trim(), |
| 90 | + time_zone_offset: trimmed(params.timeZoneOffset), |
| 91 | + region: trimmed(params.region), |
| 92 | + config: parseJsonObject(params.config, 'config'), |
| 93 | + daylight_saving_time_enabled: optionalBoolean(params.daylightSavingTimeEnabled), |
| 94 | + run_setup_tests: optionalBoolean(params.runSetupTests), |
| 95 | + trust_certificates: optionalBoolean(params.trustCertificates), |
| 96 | + trust_fingerprints: optionalBoolean(params.trustFingerprints), |
| 97 | + }), |
| 98 | + }, |
| 99 | + |
| 100 | + transformResponse: async (response: Response) => { |
| 101 | + return { |
| 102 | + success: true, |
| 103 | + output: { destination: mapDestination(envelopeData(await response.json())) }, |
| 104 | + } |
| 105 | + }, |
| 106 | + |
| 107 | + outputs: { |
| 108 | + destination: { |
| 109 | + type: 'object', |
| 110 | + description: 'The created destination, with setup test results when they ran', |
| 111 | + properties: DESTINATION_PROPERTIES, |
| 112 | + }, |
| 113 | + }, |
| 114 | +} |
0 commit comments