Skip to content

Commit 3832e5c

Browse files
author
Theodore Li
committed
Strip leading double underscores to avoid breaking change
1 parent 1c5425e commit 3832e5c

File tree

5 files changed

+18
-17
lines changed

5 files changed

+18
-17
lines changed

apps/sim/tools/exa/answer.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ export const answerTool: ToolConfig<ExaAnswerParams, ExaAnswerResponse> = {
3737
pricing: {
3838
type: 'custom',
3939
getCost: (_params, output) => {
40-
// Use _costDollars from Exa API response (internal field, stripped from final output)
41-
const costDollars = output._costDollars as { total?: number } | undefined
40+
// Use __costDollars from Exa API response (internal field, stripped from final output)
41+
const costDollars = output.__costDollars as { total?: number } | undefined
4242
if (costDollars?.total) {
4343
return { cost: costDollars.total, metadata: { costDollars } }
4444
}
@@ -86,7 +86,7 @@ export const answerTool: ToolConfig<ExaAnswerParams, ExaAnswerResponse> = {
8686
url: citation.url,
8787
text: citation.text || '',
8888
})) || [],
89-
_costDollars: data.costDollars,
89+
__costDollars: data.costDollars,
9090
},
9191
}
9292
},

apps/sim/tools/exa/find_similar_links.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@ export const findSimilarLinksTool: ToolConfig<
8686
pricing: {
8787
type: 'custom',
8888
getCost: (_params, output) => {
89-
// Use _costDollars from Exa API response (internal field, stripped from final output)
90-
const costDollars = output._costDollars as { total?: number } | undefined
89+
// Use __costDollars from Exa API response (internal field, stripped from final output)
90+
const costDollars = output.__costDollars as { total?: number } | undefined
9191
if (costDollars?.total) {
9292
return { cost: costDollars.total, metadata: { costDollars } }
9393
}
@@ -167,7 +167,7 @@ export const findSimilarLinksTool: ToolConfig<
167167
highlights: result.highlights,
168168
score: result.score || 0,
169169
})),
170-
_costDollars: data.costDollars,
170+
__costDollars: data.costDollars,
171171
},
172172
}
173173
},

apps/sim/tools/exa/get_contents.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ export const getContentsTool: ToolConfig<ExaGetContentsParams, ExaGetContentsRes
7171
pricing: {
7272
type: 'custom',
7373
getCost: (_params, output) => {
74-
// Use _costDollars from Exa API response (internal field, stripped from final output)
75-
const costDollars = output._costDollars as { total?: number } | undefined
74+
// Use __costDollars from Exa API response (internal field, stripped from final output)
75+
const costDollars = output.__costDollars as { total?: number } | undefined
7676
if (costDollars?.total) {
7777
return { cost: costDollars.total, metadata: { costDollars } }
7878
}
@@ -158,7 +158,7 @@ export const getContentsTool: ToolConfig<ExaGetContentsParams, ExaGetContentsRes
158158
summary: result.summary || '',
159159
highlights: result.highlights,
160160
})),
161-
_costDollars: data.costDollars,
161+
__costDollars: data.costDollars,
162162
},
163163
}
164164
},

apps/sim/tools/exa/search.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
9696
pricing: {
9797
type: 'custom',
9898
getCost: (params, output) => {
99-
// Use _costDollars from Exa API response (internal field, stripped from final output)
100-
const costDollars = output._costDollars as { total?: number } | undefined
99+
// Use __costDollars from Exa API response (internal field, stripped from final output)
100+
const costDollars = output.__costDollars as { total?: number } | undefined
101101
if (costDollars?.total) {
102102
return { cost: costDollars.total, metadata: { costDollars } }
103103
}
@@ -199,7 +199,7 @@ export const searchTool: ToolConfig<ExaSearchParams, ExaSearchResponse> = {
199199
highlights: result.highlights,
200200
score: result.score,
201201
})),
202-
_costDollars: data.costDollars,
202+
__costDollars: data.costDollars,
203203
},
204204
}
205205
},

apps/sim/tools/index.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -326,13 +326,15 @@ async function reportCustomDimensionUsage(
326326
}
327327

328328
/**
329-
* Strips internal fields (keys starting with underscore) from output.
330-
* Used to hide internal data (e.g., _costDollars) from end users.
329+
* Strips internal fields (keys starting with `__`) from tool output before
330+
* returning to users. The double-underscore prefix is reserved for transient
331+
* data (e.g. `__costDollars`) and will never collide with legitimate API
332+
* fields like `_id`.
331333
*/
332334
function stripInternalFields(output: Record<string, unknown>): Record<string, unknown> {
333335
const result: Record<string, unknown> = {}
334336
for (const [key, value] of Object.entries(output)) {
335-
if (!key.startsWith('_')) {
337+
if (!key.startsWith('__')) {
336338
result[key] = value
337339
}
338340
}
@@ -368,6 +370,7 @@ async function applyHostedKeyCostToResult(
368370
},
369371
}
370372
}
373+
371374
}
372375

373376
/**
@@ -785,7 +788,6 @@ export async function executeTool(
785788
)
786789
}
787790

788-
// Strip internal fields (keys starting with _) from output before returning
789791
const strippedOutput = stripInternalFields(finalResult.output || {})
790792

791793
return {
@@ -841,7 +843,6 @@ export async function executeTool(
841843
)
842844
}
843845

844-
// Strip internal fields (keys starting with _) from output before returning
845846
const strippedOutput = stripInternalFields(finalResult.output || {})
846847

847848
return {

0 commit comments

Comments
 (0)