Skip to content

Commit e2abf2a

Browse files
committed
add promptAiSdkStructured to AgentRuntimeDeps
1 parent 74935ba commit e2abf2a

File tree

6 files changed

+48
-23
lines changed

6 files changed

+48
-23
lines changed

backend/src/impl/agent-runtime.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,23 @@ import { addAgentStep, finishAgentRun, startAgentRun } from '../agent-run'
22
import {
33
promptAiSdk,
44
promptAiSdkStream,
5+
promptAiSdkStructured,
56
} from '../llm-apis/vercel-ai-sdk/ai-sdk'
67
import { logger } from '../util/logger'
78

89
import type { AgentRuntimeDeps } from '@codebuff/common/types/contracts/agent-runtime'
910

1011
export const BACKEND_AGENT_RUNTIME_IMPL: AgentRuntimeDeps = Object.freeze({
11-
logger,
12-
12+
// Database
1313
startAgentRun,
1414
finishAgentRun,
1515
addAgentStep,
1616

17+
// LLM
1718
promptAiSdkStream,
1819
promptAiSdk,
20+
promptAiSdkStructured,
21+
22+
// Other
23+
logger,
1924
})

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

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ import type { Model, OpenAIModel } from '@codebuff/common/old-constants'
2020
import type {
2121
PromptAiSdkFn,
2222
PromptAiSdkStreamFn,
23+
PromptAiSdkStructuredInput,
24+
PromptAiSdkStructuredOutput,
2325
} from '@codebuff/common/types/contracts/llm'
24-
import type { Logger } from '@codebuff/common/types/contracts/logger'
2526
import type { ParamsOf } from '@codebuff/common/types/function-params'
26-
import type { Message } from '@codebuff/common/types/messages/codebuff-message'
2727
import type {
2828
OpenRouterProviderOptions,
2929
OpenRouterUsageAccounting,
@@ -287,24 +287,9 @@ export const promptAiSdk = async function (
287287
}
288288

289289
// Copied over exactly from promptAiSdk but with a schema
290-
export const promptAiSdkStructured = async function <T>(params: {
291-
messages: Message[]
292-
schema: z.ZodType<T>
293-
clientSessionId: string
294-
fingerprintId: string
295-
userInputId: string
296-
model: Model
297-
userId: string | undefined
298-
maxTokens?: number
299-
temperature?: number
300-
timeout?: number
301-
chargeUser?: boolean
302-
agentId?: string
303-
onCostCalculated?: (credits: number) => Promise<void>
304-
includeCacheControl?: boolean
305-
maxRetries?: number
306-
logger: Logger
307-
}): Promise<T> {
290+
export const promptAiSdkStructured = async function <T>(
291+
params: PromptAiSdkStructuredInput<T>,
292+
): PromptAiSdkStructuredOutput<T> {
308293
const { logger } = params
309294

310295
if (!checkLiveUserInput(params)) {

common/src/testing/impl/agent-runtime.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ export const TEST_AGENT_RUNTIME_IMPL: AgentRuntimeDeps = Object.freeze({
2121
promptAiSdk: async function () {
2222
throw new Error('promptAiSdk not implemented in test runtime')
2323
},
24+
promptAiSdkStructured: async function () {
25+
throw new Error('promptAiSdkStructured not implemented in test runtime')
26+
},
2427

2528
// Other
2629
logger: testLogger,

common/src/types/contracts/agent-runtime.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ import type {
33
FinishAgentRunFn,
44
StartAgentRunFn,
55
} from './database'
6-
import type { PromptAiSdkFn, PromptAiSdkStreamFn } from './llm'
6+
import type {
7+
PromptAiSdkFn,
8+
PromptAiSdkStreamFn,
9+
PromptAiSdkStructuredFn,
10+
} from './llm'
711
import type { Logger } from './logger'
812

913
export type AgentRuntimeDeps = {
@@ -15,6 +19,7 @@ export type AgentRuntimeDeps = {
1519
// LLM
1620
promptAiSdkStream: PromptAiSdkStreamFn
1721
promptAiSdk: PromptAiSdkFn
22+
promptAiSdkStructured: PromptAiSdkStructuredFn
1823

1924
// Other
2025
logger: Logger

common/src/types/contracts/llm.ts

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import type { Logger } from './logger'
33
import type { Model } from '../../old-constants'
44
import type { Message } from '../messages/codebuff-message'
55
import type { generateText, streamText } from 'ai'
6+
import type z from 'zod/v4'
67

78
export type StreamChunk =
89
| {
@@ -49,3 +50,26 @@ export type PromptAiSdkFn = (
4950
logger: Logger
5051
} & ParamsExcluding<typeof generateText, 'model' | 'messages'>,
5152
) => Promise<string>
53+
54+
export type PromptAiSdkStructuredInput<T> = {
55+
messages: Message[]
56+
schema: z.ZodType<T>
57+
clientSessionId: string
58+
fingerprintId: string
59+
userInputId: string
60+
model: Model
61+
userId: string | undefined
62+
maxTokens?: number
63+
temperature?: number
64+
timeout?: number
65+
chargeUser?: boolean
66+
agentId?: string
67+
onCostCalculated?: (credits: number) => Promise<void>
68+
includeCacheControl?: boolean
69+
maxRetries?: number
70+
logger: Logger
71+
}
72+
export type PromptAiSdkStructuredOutput<T> = Promise<T>
73+
export type PromptAiSdkStructuredFn = <T>(
74+
params: PromptAiSdkStructuredInput<T>,
75+
) => PromptAiSdkStructuredOutput<T>

evals/impl/agent-runtime.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,7 @@ export const EVALS_AGENT_RUNTIME_IMPL: AgentRuntimeDeps = Object.freeze({
1313
promptAiSdk: async function () {
1414
throw new Error('promptAiSdk not implemented in eval runtime')
1515
},
16+
promptAiSdkStructured: async function () {
17+
throw new Error('promptAiSdkStructured not implemented in eval runtime')
18+
},
1619
})

0 commit comments

Comments
 (0)