Skip to content

Commit ebc89d7

Browse files
committed
improvement(apollo): fix tool outputs to match Apollo API response shapes
1 parent 8ee7d25 commit ebc89d7

9 files changed

Lines changed: 80 additions & 41 deletions

apps/sim/tools/apollo/account_bulk_create.ts

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,21 @@ export const apolloAccountBulkCreateTool: ToolConfig<
5050
}
5151

5252
const data = await response.json()
53+
const createdAccounts = Array.isArray(data.created_accounts)
54+
? data.created_accounts
55+
: Array.isArray(data.accounts)
56+
? data.accounts
57+
: []
58+
const existingAccounts = Array.isArray(data.existing_accounts) ? data.existing_accounts : []
5359

5460
return {
5561
success: true,
5662
output: {
57-
created_accounts: data.accounts || data.created_accounts || [],
58-
failed_accounts: data.failed_accounts || [],
59-
total_submitted: data.accounts?.length || 0,
60-
created: data.created_accounts?.length || data.accounts?.length || 0,
61-
failed: data.failed_accounts?.length || 0,
63+
created_accounts: createdAccounts,
64+
existing_accounts: existingAccounts,
65+
total_submitted: createdAccounts.length + existingAccounts.length,
66+
created: createdAccounts.length,
67+
existing: existingAccounts.length,
6268
},
6369
}
6470
},
@@ -68,21 +74,21 @@ export const apolloAccountBulkCreateTool: ToolConfig<
6874
type: 'json',
6975
description: 'Array of newly created accounts',
7076
},
71-
failed_accounts: {
77+
existing_accounts: {
7278
type: 'json',
73-
description: 'Array of accounts that failed to create',
79+
description: 'Array of existing accounts returned by Apollo (when duplicates are detected)',
7480
},
7581
total_submitted: {
7682
type: 'number',
77-
description: 'Total number of accounts submitted',
83+
description: 'Total number of accounts in the response (created + existing)',
7884
},
7985
created: {
8086
type: 'number',
8187
description: 'Number of accounts successfully created',
8288
},
83-
failed: {
89+
existing: {
8490
type: 'number',
85-
description: 'Number of accounts that failed to create',
91+
description: 'Number of existing accounts found',
8692
},
8793
},
8894
}

apps/sim/tools/apollo/account_search.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ export const apolloAccountSearchTool: ToolConfig<
100100
return {
101101
success: true,
102102
output: {
103-
accounts: data.accounts ?? null,
103+
accounts: data.accounts ?? [],
104104
pagination: data.pagination ?? null,
105105
},
106106
}
@@ -110,7 +110,6 @@ export const apolloAccountSearchTool: ToolConfig<
110110
accounts: {
111111
type: 'json',
112112
description: 'Array of accounts matching the search criteria',
113-
optional: true,
114113
},
115114
pagination: { type: 'json', description: 'Pagination information', optional: true },
116115
},

apps/sim/tools/apollo/contact_search.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const apolloContactSearchTool: ToolConfig<
9999
return {
100100
success: true,
101101
output: {
102-
contacts: data.contacts ?? null,
102+
contacts: data.contacts ?? [],
103103
pagination: data.pagination ?? null,
104104
},
105105
}
@@ -109,7 +109,6 @@ export const apolloContactSearchTool: ToolConfig<
109109
contacts: {
110110
type: 'json',
111111
description: 'Array of contacts matching the search criteria',
112-
optional: true,
113112
},
114113
pagination: { type: 'json', description: 'Pagination information', optional: true },
115114
},

apps/sim/tools/apollo/opportunity_get.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,14 +47,18 @@ export const apolloOpportunityGetTool: ToolConfig<
4747
return {
4848
success: true,
4949
output: {
50-
opportunity: data.opportunity || {},
50+
opportunity: data.opportunity ?? null,
5151
found: !!data.opportunity,
5252
},
5353
}
5454
},
5555

5656
outputs: {
57-
opportunity: { type: 'json', description: 'Complete opportunity data from Apollo' },
57+
opportunity: {
58+
type: 'json',
59+
description: 'Complete opportunity data from Apollo',
60+
optional: true,
61+
},
5862
found: { type: 'boolean', description: 'Whether the opportunity was found' },
5963
},
6064
}

apps/sim/tools/apollo/people_bulk_enrich.ts

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,21 +70,46 @@ export const apolloPeopleBulkEnrichTool: ToolConfig<
7070
}
7171

7272
const data = await response.json()
73-
const people = data.people || data.matches || []
73+
const matches = Array.isArray(data.matches)
74+
? data.matches
75+
: Array.isArray(data.people)
76+
? data.people
77+
: []
7478

7579
return {
7680
success: true,
7781
output: {
78-
people,
79-
total: people.length,
80-
enriched: people.filter((p: unknown) => p).length,
82+
matches,
83+
total_requested_enrichments: data.total_requested_enrichments ?? matches.length,
84+
unique_enriched_records: data.unique_enriched_records ?? matches.filter(Boolean).length,
85+
missing_records: data.missing_records ?? null,
86+
credits_consumed: data.credits_consumed ?? null,
8187
},
8288
}
8389
},
8490

8591
outputs: {
86-
people: { type: 'json', description: 'Array of enriched people data' },
87-
total: { type: 'number', description: 'Total number of people processed' },
88-
enriched: { type: 'number', description: 'Number of people successfully enriched' },
92+
matches: {
93+
type: 'json',
94+
description: 'Array of enriched people (null entries indicate no match)',
95+
},
96+
total_requested_enrichments: {
97+
type: 'number',
98+
description: 'Total number of records submitted for enrichment',
99+
},
100+
unique_enriched_records: {
101+
type: 'number',
102+
description: 'Number of records successfully enriched',
103+
},
104+
missing_records: {
105+
type: 'number',
106+
description: 'Number of records that could not be enriched',
107+
optional: true,
108+
},
109+
credits_consumed: {
110+
type: 'number',
111+
description: 'Number of Apollo credits consumed by this request',
112+
optional: true,
113+
},
89114
},
90115
}

apps/sim/tools/apollo/people_enrich.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,18 @@ export const apolloPeopleEnrichTool: ToolConfig<
110110
return {
111111
success: true,
112112
output: {
113-
person: data.person || {},
113+
person: data.person ?? null,
114114
enriched: !!data.person,
115115
},
116116
}
117117
},
118118

119119
outputs: {
120-
person: { type: 'json', description: 'Enriched person data from Apollo' },
120+
person: {
121+
type: 'json',
122+
description: 'Enriched person data from Apollo',
123+
optional: true,
124+
},
121125
enriched: { type: 'boolean', description: 'Whether the person was successfully enriched' },
122126
},
123127
}

apps/sim/tools/apollo/sequence_add_contacts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ export const apolloSequenceAddContactsTool: ToolConfig<
131131

132132
const added = Array.isArray(data?.contacts?.added) ? data.contacts.added : []
133133
const skipped = Array.isArray(data?.contacts?.skipped) ? data.contacts.skipped : []
134-
const skippedIds = data?.skipped_contact_ids ?? null
134+
const skippedIds = Array.isArray(data?.skipped_contact_ids) ? data.skipped_contact_ids : null
135135

136136
return {
137137
success: true,
@@ -158,7 +158,7 @@ export const apolloSequenceAddContactsTool: ToolConfig<
158158
},
159159
skipped_contact_ids: {
160160
type: 'json',
161-
description: 'Hash mapping contact IDs to skip reason codes',
161+
description: 'Array of contact IDs that were skipped',
162162
optional: true,
163163
},
164164
emailer_campaign: {

apps/sim/tools/apollo/task_search.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export const apolloTaskSearchTool: ToolConfig<ApolloTaskSearchParams, ApolloTask
7171
return {
7272
success: true,
7373
output: {
74-
tasks: data.tasks ?? null,
74+
tasks: data.tasks ?? [],
7575
pagination: data.pagination ?? null,
7676
},
7777
}
@@ -81,7 +81,6 @@ export const apolloTaskSearchTool: ToolConfig<ApolloTaskSearchParams, ApolloTask
8181
tasks: {
8282
type: 'json',
8383
description: 'Array of tasks matching the search criteria',
84-
optional: true,
8584
},
8685
pagination: { type: 'json', description: 'Pagination information', optional: true },
8786
},

apps/sim/tools/apollo/types.ts

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ export interface ApolloPeopleEnrichParams extends ApolloBaseParams {
155155

156156
export interface ApolloPeopleEnrichResponse extends ToolResponse {
157157
output: {
158-
person: ApolloPerson
158+
person: ApolloPerson | null
159159
enriched: boolean
160160
}
161161
}
@@ -179,9 +179,11 @@ export interface ApolloPeopleBulkEnrichParams extends ApolloBaseParams {
179179

180180
export interface ApolloPeopleBulkEnrichResponse extends ToolResponse {
181181
output: {
182-
people: ApolloPerson[]
183-
total: number
184-
enriched: number
182+
matches: Array<ApolloPerson | null>
183+
total_requested_enrichments: number
184+
unique_enriched_records: number
185+
missing_records: number | null
186+
credits_consumed: number | null
185187
}
186188
}
187189

@@ -355,7 +357,7 @@ export interface ApolloPagination {
355357

356358
export interface ApolloContactSearchResponse extends ToolResponse {
357359
output: {
358-
contacts: ApolloContact[] | null
360+
contacts: ApolloContact[]
359361
pagination: ApolloPagination | null
360362
}
361363
}
@@ -410,7 +412,7 @@ export interface ApolloAccountSearchParams extends ApolloBaseParams {
410412

411413
export interface ApolloAccountSearchResponse extends ToolResponse {
412414
output: {
413-
accounts: ApolloAccount[] | null
415+
accounts: ApolloAccount[]
414416
pagination: ApolloPagination | null
415417
}
416418
}
@@ -428,10 +430,10 @@ export interface ApolloAccountBulkCreateParams extends ApolloBaseParams {
428430
export interface ApolloAccountBulkCreateResponse extends ToolResponse {
429431
output: {
430432
created_accounts: ApolloAccount[]
431-
failed_accounts: Array<{ name: string; error: string }>
433+
existing_accounts: ApolloAccount[]
432434
total_submitted: number
433435
created: number
434-
failed: number
436+
existing: number
435437
}
436438
}
437439

@@ -483,7 +485,7 @@ export interface ApolloSequenceAddContactsResponse extends ToolResponse {
483485
output: {
484486
added: ApolloSequenceAddedContact[]
485487
skipped: ApolloSequenceSkippedContact[]
486-
skipped_contact_ids: Record<string, string> | null
488+
skipped_contact_ids: string[] | null
487489
emailer_campaign: { id: string; name: string } | null
488490
sequence_id: string
489491
total_added: number
@@ -519,7 +521,7 @@ export interface ApolloTaskSearchParams extends ApolloBaseParams {
519521

520522
export interface ApolloTaskSearchResponse extends ToolResponse {
521523
output: {
522-
tasks: ApolloTask[] | null
524+
tasks: ApolloTask[]
523525
pagination: ApolloPagination | null
524526
}
525527
}
@@ -528,11 +530,12 @@ export interface ApolloTaskSearchResponse extends ToolResponse {
528530
export interface ApolloEmailAccountsParams extends ApolloBaseParams {}
529531

530532
export interface ApolloEmailAccount {
531-
id: string
533+
id: string | number
532534
email: string
533535
type?: string
534536
active?: boolean
535537
default?: boolean
538+
linked_at?: string | null
536539
}
537540

538541
export interface ApolloEmailAccountsResponse extends ToolResponse {
@@ -583,7 +586,7 @@ export interface ApolloOpportunityGetParams extends ApolloBaseParams {
583586

584587
export interface ApolloOpportunityGetResponse extends ToolResponse {
585588
output: {
586-
opportunity: ApolloOpportunity
589+
opportunity: ApolloOpportunity | null
587590
found: boolean
588591
}
589592
}

0 commit comments

Comments
 (0)