Skip to content

Commit f237d6f

Browse files
author
Theodore Li
committed
Fix unit tests, use cost property
1 parent 36e6464 commit f237d6f

File tree

9 files changed

+621
-141
lines changed

9 files changed

+621
-141
lines changed

apps/sim/executor/handlers/generic/generic-handler.ts

Lines changed: 1 addition & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -97,38 +97,7 @@ export class GenericBlockHandler implements BlockHandler {
9797
throw error
9898
}
9999

100-
const output = result.output
101-
102-
// Merge costs from output (e.g., AI model costs) and result (e.g., hosted key costs)
103-
// TODO: migrate model usage to output cost.
104-
const outputCost = output?.cost
105-
const resultCost = result.cost
106-
107-
let cost = null
108-
if (outputCost || resultCost) {
109-
cost = {
110-
input: (outputCost?.input || 0) + (resultCost?.input || 0),
111-
output: (outputCost?.output || 0) + (resultCost?.output || 0),
112-
total: (outputCost?.total || 0) + (resultCost?.total || 0),
113-
tokens: outputCost?.tokens,
114-
model: outputCost?.model,
115-
}
116-
}
117-
118-
if (cost) {
119-
return {
120-
...output,
121-
cost: {
122-
input: cost.input,
123-
output: cost.output,
124-
total: cost.total,
125-
},
126-
tokens: cost.tokens,
127-
model: cost.model,
128-
}
129-
}
130-
131-
return output
100+
return result.output
132101
} catch (error: any) {
133102
if (!error.message || error.message === 'undefined (undefined)') {
134103
let errorMessage = `Block execution of ${tool?.name || block.config.tool} failed`

apps/sim/tools/exa/answer.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@ export const answerTool: ToolConfig<ExaAnswerParams, ExaAnswerResponse> = {
3636
byokProviderId: 'exa',
3737
pricing: {
3838
type: 'custom',
39-
getCost: (_params, response) => {
40-
// Use costDollars from Exa API response
41-
if (response.costDollars?.total) {
42-
return { cost: response.costDollars.total, metadata: { costDollars: response.costDollars } }
39+
getCost: (_params, output) => {
40+
// Use _costDollars from Exa API response (internal field, stripped from final output)
41+
if (output._costDollars?.total) {
42+
return { cost: output._costDollars.total, metadata: { costDollars: output._costDollars } }
4343
}
4444
// Fallback: $5/1000 requests
4545
logger.warn('Exa answer response missing costDollars, using fallback pricing')
@@ -81,7 +81,7 @@ export const answerTool: ToolConfig<ExaAnswerParams, ExaAnswerResponse> = {
8181
url: citation.url,
8282
text: citation.text || '',
8383
})) || [],
84-
costDollars: data.costDollars,
84+
_costDollars: data.costDollars,
8585
},
8686
}
8787
},

apps/sim/tools/exa/find_similar_links.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,14 @@ export const findSimilarLinksTool: ToolConfig<
8585
byokProviderId: 'exa',
8686
pricing: {
8787
type: 'custom',
88-
getCost: (_params, response) => {
89-
// Use costDollars from Exa API response
90-
if (response.costDollars?.total) {
91-
return { cost: response.costDollars.total, metadata: { costDollars: response.costDollars } }
88+
getCost: (_params, output) => {
89+
// Use _costDollars from Exa API response (internal field, stripped from final output)
90+
if (output._costDollars?.total) {
91+
return { cost: output._costDollars.total, metadata: { costDollars: output._costDollars } }
9292
}
9393
// Fallback: $5/1000 (1-25 results) or $25/1000 (26-100 results)
9494
logger.warn('Exa find_similar_links response missing costDollars, using fallback pricing')
95-
const resultCount = response.similarLinks?.length || 0
95+
const resultCount = output.similarLinks?.length || 0
9696
return resultCount <= 25 ? 0.005 : 0.025
9797
},
9898
},
@@ -161,7 +161,7 @@ export const findSimilarLinksTool: ToolConfig<
161161
highlights: result.highlights,
162162
score: result.score || 0,
163163
})),
164-
costDollars: data.costDollars,
164+
_costDollars: data.costDollars,
165165
},
166166
}
167167
},

apps/sim/tools/exa/get_contents.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,14 @@ export const getContentsTool: ToolConfig<ExaGetContentsParams, ExaGetContentsRes
7070
byokProviderId: 'exa',
7171
pricing: {
7272
type: 'custom',
73-
getCost: (_params, response) => {
74-
// Use costDollars from Exa API response
75-
if (response.costDollars?.total) {
76-
return { cost: response.costDollars.total, metadata: { costDollars: response.costDollars } }
73+
getCost: (_params, output) => {
74+
// Use _costDollars from Exa API response (internal field, stripped from final output)
75+
if (output._costDollars?.total) {
76+
return { cost: output._costDollars.total, metadata: { costDollars: output._costDollars } }
7777
}
7878
// Fallback: $1/1000 pages
7979
logger.warn('Exa get_contents response missing costDollars, using fallback pricing')
80-
return (response.results?.length || 0) * 0.001
80+
return (output.results?.length || 0) * 0.001
8181
},
8282
},
8383
},
@@ -152,7 +152,7 @@ export const getContentsTool: ToolConfig<ExaGetContentsParams, ExaGetContentsRes
152152
summary: result.summary || '',
153153
highlights: result.highlights,
154154
})),
155-
costDollars: data.costDollars,
155+
_costDollars: data.costDollars,
156156
},
157157
}
158158
},

apps/sim/tools/exa/research.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,10 @@ export const researchTool: ToolConfig<ExaResearchParams, ExaResearchResponse> =
4040
byokProviderId: 'exa',
4141
pricing: {
4242
type: 'custom',
43-
getCost: (params, response) => {
44-
// Use costDollars from Exa API response
45-
if (response.costDollars?.total) {
46-
return { cost: response.costDollars.total, metadata: { costDollars: response.costDollars } }
43+
getCost: (params, output) => {
44+
// Use _costDollars from Exa API response (internal field, stripped from final output)
45+
if (output._costDollars?.total) {
46+
return { cost: output._costDollars.total, metadata: { costDollars: output._costDollars } }
4747
}
4848

4949
// Fallback to estimate if cost not available
@@ -130,8 +130,8 @@ export const researchTool: ToolConfig<ExaResearchParams, ExaResearchResponse> =
130130
score: 1.0,
131131
},
132132
],
133-
// Include cost breakdown for pricing calculation
134-
costDollars: taskData.costDollars,
133+
// Include cost breakdown for pricing calculation (internal field, stripped from final output)
134+
_costDollars: taskData.costDollars,
135135
}
136136
return result
137137
}

apps/sim/tools/exa/search.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,10 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
9595
byokProviderId: 'exa',
9696
pricing: {
9797
type: 'custom',
98-
getCost: (params, response) => {
99-
// Use costDollars from Exa API response
100-
if (response.costDollars?.total) {
101-
return { cost: response.costDollars.total, metadata: { costDollars: response.costDollars } }
98+
getCost: (params, output) => {
99+
// Use _costDollars from Exa API response (internal field, stripped from final output)
100+
if (output._costDollars?.total) {
101+
return { cost: output._costDollars.total, metadata: { costDollars: output._costDollars } }
102102
}
103103

104104
// Fallback: estimate based on search type and result count
@@ -107,7 +107,7 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
107107
if (isDeepSearch) {
108108
return 0.015
109109
}
110-
const resultCount = response.results?.length || 0
110+
const resultCount = output.results?.length || 0
111111
return resultCount <= 25 ? 0.005 : 0.025
112112
},
113113
},
@@ -193,7 +193,7 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
193193
highlights: result.highlights,
194194
score: result.score,
195195
})),
196-
costDollars: data.costDollars,
196+
_costDollars: data.costDollars,
197197
},
198198
}
199199
},

0 commit comments

Comments
 (0)