feat(tools): add generic search tool (#2140)

This commit is contained in:
Waleed
2025-11-30 14:13:46 -08:00
committed by GitHub
parent f25db707d7
commit e3a57d30e8
16 changed files with 553 additions and 196 deletions

View File

@@ -318,48 +318,49 @@ describe('GenericBlockHandler', () => {
})
})
it.concurrent('should not process cost info for non-knowledge tools', async () => {
// Set up non-knowledge tool
mockBlock.config.tool = 'some_other_tool'
mockTool.id = 'some_other_tool'
it.concurrent(
'should process cost info for all tools (universal cost extraction)',
async () => {
mockBlock.config.tool = 'some_other_tool'
mockTool.id = 'some_other_tool'
mockGetTool.mockImplementation((toolId) => {
if (toolId === 'some_other_tool') {
return mockTool
mockGetTool.mockImplementation((toolId) => {
if (toolId === 'some_other_tool') {
return mockTool
}
return undefined
})
const inputs = { param: 'value' }
const mockToolResponse = {
success: true,
output: {
result: 'success',
cost: {
input: 0.001,
output: 0.002,
total: 0.003,
tokens: { prompt: 100, completion: 50, total: 150 },
model: 'some-model',
},
},
}
return undefined
})
const inputs = { param: 'value' }
const mockToolResponse = {
success: true,
output: {
mockExecuteTool.mockResolvedValue(mockToolResponse)
const result = await handler.execute(mockContext, mockBlock, inputs)
expect(result).toEqual({
result: 'success',
cost: {
input: 0.001,
output: 0.002,
total: 0.003,
tokens: { prompt: 100, completion: 50, total: 150 },
model: 'some-model',
},
},
}
mockExecuteTool.mockResolvedValue(mockToolResponse)
const result = await handler.execute(mockContext, mockBlock, inputs)
// Should return original output without cost transformation
expect(result).toEqual({
result: 'success',
cost: {
input: 0.001,
output: 0.002,
total: 0.003,
tokens: { prompt: 100, completion: 50, total: 150 },
model: 'some-model',
},
})
})
})
}
)
})
})

View File

@@ -104,7 +104,7 @@ export class GenericBlockHandler implements BlockHandler {
const output = result.output
let cost = null
if (block.config.tool?.startsWith('knowledge_') && output?.cost) {
if (output?.cost) {
cost = output.cost
}