Skip to content

Commit fa7a47a

Browse files
committed
pass in logger to linkup api
1 parent 3421c10 commit fa7a47a

File tree

4 files changed

+59
-48
lines changed

4 files changed

+59
-48
lines changed

backend/src/__tests__/web-search-tool.test.ts

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ describe('web_search tool with researcher agent', () => {
143143
})
144144

145145
// Just verify that searchWeb was called
146-
expect(linkupApi.searchWeb).toHaveBeenCalledWith('test query', {
146+
expect(linkupApi.searchWeb).toHaveBeenCalledWith({
147+
query: 'test query',
147148
depth: 'standard',
149+
logger: expect.anything(),
148150
})
149151
})
150152

@@ -190,12 +192,11 @@ describe('web_search tool with researcher agent', () => {
190192
logger,
191193
})
192194

193-
expect(linkupApi.searchWeb).toHaveBeenCalledWith(
194-
'Next.js 15 new features',
195-
{
196-
depth: 'standard',
197-
},
198-
)
195+
expect(linkupApi.searchWeb).toHaveBeenCalledWith({
196+
query: 'Next.js 15 new features',
197+
depth: 'standard',
198+
logger: expect.anything(),
199+
})
199200

200201
// Check that the search results were added to the message history
201202
const toolResultMessages = newAgentState.messageHistory.filter(
@@ -242,19 +243,19 @@ describe('web_search tool with researcher agent', () => {
242243
fingerprintId: 'test-fingerprint',
243244
onResponseChunk: () => {},
244245
agentType: 'researcher',
245-
fileContext: mockFileContext, localAgentTemplates: agentTemplates,
246+
fileContext: mockFileContext,
247+
localAgentTemplates: agentTemplates,
246248
agentState,
247249
prompt: 'Search for React Server Components tutorial with deep search',
248250
params: undefined,
249251
logger,
250252
})
251253

252-
expect(linkupApi.searchWeb).toHaveBeenCalledWith(
253-
'React Server Components tutorial',
254-
{
255-
depth: 'deep',
256-
},
257-
)
254+
expect(linkupApi.searchWeb).toHaveBeenCalledWith({
255+
query: 'React Server Components tutorial',
256+
depth: 'deep',
257+
logger: expect.anything(),
258+
})
258259
})
259260

260261
test('should handle case when no search results are found', async () => {
@@ -295,12 +296,11 @@ describe('web_search tool with researcher agent', () => {
295296
})
296297

297298
// Verify that searchWeb was called
298-
expect(linkupApi.searchWeb).toHaveBeenCalledWith(
299-
'very obscure search query that returns nothing',
300-
{
301-
depth: 'standard',
302-
},
303-
)
299+
expect(linkupApi.searchWeb).toHaveBeenCalledWith({
300+
query: 'very obscure search query that returns nothing',
301+
depth: 'standard',
302+
logger: expect.anything(),
303+
})
304304

305305
// Check that the "no results found" message was added
306306
const toolResultMessages = newAgentState.messageHistory.filter(
@@ -354,8 +354,10 @@ describe('web_search tool with researcher agent', () => {
354354
})
355355

356356
// Verify that searchWeb was called
357-
expect(linkupApi.searchWeb).toHaveBeenCalledWith('test query', {
357+
expect(linkupApi.searchWeb).toHaveBeenCalledWith({
358+
query: 'test query',
358359
depth: 'standard',
360+
logger: expect.anything(),
359361
})
360362

361363
// Check that the error message was added
@@ -409,8 +411,10 @@ describe('web_search tool with researcher agent', () => {
409411
})
410412

411413
// Verify that searchWeb was called
412-
expect(linkupApi.searchWeb).toHaveBeenCalledWith('test query', {
414+
expect(linkupApi.searchWeb).toHaveBeenCalledWith({
415+
query: 'test query',
413416
depth: 'standard',
417+
logger: expect.anything(),
414418
})
415419
})
416420

@@ -454,8 +458,10 @@ describe('web_search tool with researcher agent', () => {
454458
})
455459

456460
// Verify that searchWeb was called
457-
expect(linkupApi.searchWeb).toHaveBeenCalledWith('test query', {
461+
expect(linkupApi.searchWeb).toHaveBeenCalledWith({
462+
query: 'test query',
458463
depth: 'standard',
464+
logger: expect.anything(),
459465
})
460466

461467
// Check that the error message was added
@@ -511,8 +517,10 @@ describe('web_search tool with researcher agent', () => {
511517
})
512518

513519
// Verify that searchWeb was called
514-
expect(linkupApi.searchWeb).toHaveBeenCalledWith('test formatting', {
520+
expect(linkupApi.searchWeb).toHaveBeenCalledWith({
521+
query: 'test formatting',
515522
depth: 'standard',
523+
logger: expect.anything(),
516524
})
517525

518526
// Check that the search results were formatted correctly

backend/src/llm-apis/__tests__/linkup-api.test.ts

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ describe('Linkup API', () => {
3535
},
3636
}))
3737

38-
mockModule('@codebuff/backend/util/logger', () => ({
39-
logger: mockLogger,
40-
}))
41-
4238
// Mock withTimeout utility
4339
mockModule('@codebuff/common/util/promise', () => ({
4440
withTimeout: async (promise: Promise<any>, timeout: number) => promise,
@@ -84,7 +80,10 @@ describe('Linkup API', () => {
8480
}),
8581
)
8682

87-
const result = await searchWeb('React tutorial')
83+
const result = await searchWeb({
84+
query: 'React tutorial',
85+
logger: mockLogger,
86+
})
8887

8988
expect(result).toBe(
9089
'React is a JavaScript library for building user interfaces. You can learn how to build your first React application by following the official documentation.',
@@ -128,8 +127,10 @@ describe('Linkup API', () => {
128127
}),
129128
)
130129

131-
const result = await searchWeb('React patterns', {
130+
const result = await searchWeb({
131+
query: 'React patterns',
132132
depth: 'deep',
133+
logger: mockLogger,
133134
})
134135

135136
expect(result).toBe(
@@ -157,15 +158,15 @@ describe('Linkup API', () => {
157158
}),
158159
)
159160

160-
const result = await searchWeb('test query')
161+
const result = await searchWeb({ query: 'test query', logger: mockLogger })
161162

162163
expect(result).toBeNull()
163164
})
164165

165166
test('should handle network errors', async () => {
166167
spyOn(global, 'fetch').mockRejectedValue(new Error('Network error'))
167168

168-
const result = await searchWeb('test query')
169+
const result = await searchWeb({ query: 'test query', logger: mockLogger })
169170

170171
expect(result).toBeNull()
171172
})
@@ -178,7 +179,7 @@ describe('Linkup API', () => {
178179
}),
179180
)
180181

181-
const result = await searchWeb('test query')
182+
const result = await searchWeb({ query: 'test query', logger: mockLogger })
182183

183184
expect(result).toBeNull()
184185
})
@@ -191,7 +192,7 @@ describe('Linkup API', () => {
191192
}),
192193
)
193194

194-
const result = await searchWeb('test query')
195+
const result = await searchWeb({ query: 'test query', logger: mockLogger })
195196

196197
expect(result).toBeNull()
197198
})
@@ -208,7 +209,7 @@ describe('Linkup API', () => {
208209
}),
209210
)
210211

211-
const result = await searchWeb('test query')
212+
const result = await searchWeb({ query: 'test query', logger: mockLogger })
212213

213214
expect(result).toBeNull()
214215
})
@@ -228,7 +229,7 @@ describe('Linkup API', () => {
228229
}),
229230
)
230231

231-
await searchWeb('test query')
232+
await searchWeb({ query: 'test query', logger: mockLogger })
232233

233234
// Verify fetch was called with default parameters
234235
expect(fetch).toHaveBeenCalledWith(
@@ -251,7 +252,7 @@ describe('Linkup API', () => {
251252
}),
252253
)
253254

254-
const result = await searchWeb('test query')
255+
const result = await searchWeb({ query: 'test query', logger: mockLogger })
255256

256257
expect(result).toBeNull()
257258
// Verify that error logging was called
@@ -269,7 +270,10 @@ describe('Linkup API', () => {
269270
}),
270271
)
271272

272-
const result = await searchWeb('test query for 404')
273+
const result = await searchWeb({
274+
query: 'test query for 404',
275+
logger: mockLogger,
276+
})
273277

274278
expect(result).toBeNull()
275279
// Verify that detailed error logging was called with 404 info

backend/src/llm-apis/linkup-api.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { withTimeout } from '@codebuff/common/util/promise'
22
import { env } from '@codebuff/internal'
33

4-
import { logger } from '../util/logger'
4+
import type { Logger } from '@codebuff/types/logger'
55

66
const LINKUP_API_BASE_URL = 'https://api.linkup.so/v1'
77
const FETCH_TIMEOUT_MS = 30_000
@@ -23,13 +23,12 @@ export interface LinkupSearchResponse {
2323
* @param options Search options including depth and max results
2424
* @returns Array containing a single result with the sourced answer or null if the request fails
2525
*/
26-
export async function searchWeb(
27-
query: string,
28-
options: {
29-
depth?: 'standard' | 'deep'
30-
} = {},
31-
): Promise<string | null> {
32-
const { depth = 'standard' } = options
26+
export async function searchWeb(options: {
27+
query: string
28+
depth?: 'standard' | 'deep'
29+
logger: Logger
30+
}): Promise<string | null> {
31+
const { query, depth = 'standard', logger } = options
3332
const apiStartTime = Date.now()
3433

3534
const requestBody = {

backend/src/tools/handlers/tool/web-search.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import { searchWeb } from '../../../llm-apis/linkup-api'
55
import { PROFIT_MARGIN } from '../../../llm-apis/message-cost-tracker'
66

77
import type { CodebuffToolHandlerFunction } from '../handler-function-type'
8-
import type { Logger } from '@codebuff/types/logger'
98
import type {
109
CodebuffToolCall,
1110
CodebuffToolOutput,
1211
} from '@codebuff/common/tools/list'
12+
import type { Logger } from '@codebuff/types/logger'
1313

1414
export const handleWebSearch = ((params: {
1515
previousToolCallFinished: Promise<void>
@@ -59,7 +59,7 @@ export const handleWebSearch = ((params: {
5959
const webSearchPromise: Promise<CodebuffToolOutput<'web_search'>> =
6060
(async () => {
6161
try {
62-
const searchResult = await searchWeb(query, { depth })
62+
const searchResult = await searchWeb({ query, depth, logger })
6363
const searchDuration = Date.now() - searchStartTime
6464
const resultLength = searchResult?.length || 0
6565
const hasResults = Boolean(searchResult && searchResult.trim())

0 commit comments

Comments
 (0)