Skip to content

Commit cf5aaa9

Browse files
committed
change promptAiSdk functions to function instead of const
1 parent e2abf2a commit cf5aaa9

File tree

3 files changed

+9
-17
lines changed

3 files changed

+9
-17
lines changed

backend/src/__tests__/cost-aggregation.integration.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ class MockWebSocket {
9999
describe('Cost Aggregation Integration Tests', () => {
100100
let mockLocalAgentTemplates: Record<string, any>
101101
let mockWebSocket: MockWebSocket
102-
let agentRuntimeImpl: AgentRuntimeDeps = { ...TEST_AGENT_RUNTIME_IMPL }
102+
let agentRuntimeImpl: AgentRuntimeDeps
103103

104104
beforeEach(async () => {
105+
agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
105106
mockWebSocket = new MockWebSocket()
106107

107108
// Setup mock agent templates
@@ -230,7 +231,6 @@ describe('Cost Aggregation Integration Tests', () => {
230231

231232
afterEach(() => {
232233
mock.restore()
233-
agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
234234
})
235235

236236
it('should correctly aggregate costs across the entire main prompt flow', async () => {

backend/src/__tests__/main-prompt.test.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,10 @@ import * as websocketAction from '../websockets/websocket-action'
2828

2929
import type { AgentTemplate } from '@codebuff/common/types/agent-template'
3030
import type { AgentRuntimeDeps } from '@codebuff/common/types/contracts/agent-runtime'
31-
import type { Logger } from '@codebuff/common/types/contracts/logger'
3231
import type { ProjectFileContext } from '@codebuff/common/util/file'
3332
import type { WebSocket } from 'ws'
3433

35-
let agentRuntimeImpl: AgentRuntimeDeps = { ...TEST_AGENT_RUNTIME_IMPL }
34+
let agentRuntimeImpl: AgentRuntimeDeps
3635

3736
const mockAgentStream = (streamOutput: string) => {
3837
agentRuntimeImpl.promptAiSdkStream = async function* ({}) {
@@ -43,14 +42,10 @@ const mockAgentStream = (streamOutput: string) => {
4342

4443
describe('mainPrompt', () => {
4544
let mockLocalAgentTemplates: Record<string, any>
46-
const logger: Logger = {
47-
debug: () => {},
48-
error: () => {},
49-
info: () => {},
50-
warn: () => {},
51-
}
5245

5346
beforeEach(() => {
47+
agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
48+
5449
// Setup common mock agent templates
5550
mockLocalAgentTemplates = {
5651
[AgentTemplateTypes.base]: {
@@ -86,12 +81,10 @@ describe('mainPrompt', () => {
8681
stepPrompt: '',
8782
} satisfies AgentTemplate,
8883
}
89-
})
9084

91-
beforeEach(() => {
9285
// Mock analytics and tracing
9386
spyOn(analytics, 'initAnalytics').mockImplementation(() => {})
94-
analytics.initAnalytics({ logger }) // Initialize the mock
87+
analytics.initAnalytics(agentRuntimeImpl) // Initialize the mock
9588
spyOn(analytics, 'trackEvent').mockImplementation(() => {})
9689
spyOn(bigquery, 'insertTrace').mockImplementation(() =>
9790
Promise.resolve(true),
@@ -176,7 +169,6 @@ describe('mainPrompt', () => {
176169
afterEach(() => {
177170
// Clear all mocks after each test
178171
mock.restore()
179-
agentRuntimeImpl = { ...TEST_AGENT_RUNTIME_IMPL }
180172
})
181173

182174
class MockWebSocket {

backend/src/llm-apis/vercel-ai-sdk/ai-sdk.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ const modelToAiSDKModel = (model: Model): LanguageModel => {
5353
// TODO: Add retries & fallbacks: likely by allowing this to instead of "model"
5454
// also take an array of form [{model: Model, retries: number}, {model: Model, retries: number}...]
5555
// eg: [{model: "gemini-2.0-flash-001"}, {model: "vertex/gemini-2.0-flash-001"}, {model: "claude-3-5-haiku", retries: 3}]
56-
export const promptAiSdkStream = async function* (
56+
export async function* promptAiSdkStream(
5757
params: ParamsOf<PromptAiSdkStreamFn>,
5858
): ReturnType<PromptAiSdkStreamFn> {
5959
const { logger } = params
@@ -230,7 +230,7 @@ export const promptAiSdkStream = async function* (
230230
}
231231

232232
// TODO: figure out a nice way to unify stream & non-stream versions maybe?
233-
export const promptAiSdk = async function (
233+
export async function promptAiSdk(
234234
params: ParamsOf<PromptAiSdkFn>,
235235
): ReturnType<PromptAiSdkFn> {
236236
const { logger } = params
@@ -287,7 +287,7 @@ export const promptAiSdk = async function (
287287
}
288288

289289
// Copied over exactly from promptAiSdk but with a schema
290-
export const promptAiSdkStructured = async function <T>(
290+
export async function promptAiSdkStructured<T>(
291291
params: PromptAiSdkStructuredInput<T>,
292292
): PromptAiSdkStructuredOutput<T> {
293293
const { logger } = params

0 commit comments

Comments
 (0)