Skip to content

Commit 22bcb46

Browse files
committed
add generateText endpoint to openrouter wrapper
1 parent 8e6058d commit 22bcb46

File tree

11 files changed

+407
-245
lines changed

11 files changed

+407
-245
lines changed

common/src/constants/analytics-events.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,8 @@ export enum AnalyticsEvent {
9696
CHAT_COMPLETIONS_AUTH_ERROR = 'api.chat_completions_auth_error',
9797
CHAT_COMPLETIONS_VALIDATION_ERROR = 'api.chat_completions_validation_error',
9898
CHAT_COMPLETIONS_INSUFFICIENT_CREDITS = 'api.chat_completions_insufficient_credits',
99+
CHAT_COMPLETIONS_GENERATION_STARTED = 'api.chat_completions_generation_started',
99100
CHAT_COMPLETIONS_STREAM_STARTED = 'api.chat_completions_stream_started',
100-
CHAT_COMPLETIONS_STREAM_ERROR = 'api.chat_completions_stream_error',
101101
CHAT_COMPLETIONS_ERROR = 'api.chat_completions_error',
102102

103103
// Common
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import type { Logger } from './logger'
2+
3+
export type MessageRow = {
4+
id: string
5+
user_id: string
6+
finished_at: Date
7+
created_at: Date
8+
request: unknown
9+
reasoning_text: string
10+
response: string
11+
output_tokens?: number | null
12+
reasoning_tokens?: number | null
13+
cost?: number | null
14+
upstream_inference_cost?: number | null
15+
input_tokens?: number | null
16+
cache_read_input_tokens?: number | null
17+
}
18+
19+
export type InsertMessageBigqueryFn = (params: {
20+
row: MessageRow
21+
dataset?: string
22+
logger: Logger
23+
}) => Promise<boolean>

common/src/types/contracts/database.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export type GetAgentRunFromIdOutput<T extends AgentRunColumn> = Promise<
3535
| {
3636
[K in T]: AgentRun[K]
3737
}
38-
| undefined
38+
| null
3939
>
4040
export type GetAgentRunFromIdFn = <T extends AgentRunColumn>(
4141
params: GetAgentRunFromIdInput<T>,

packages/bigquery/src/client.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,8 @@ import { BigQuery } from '@google-cloud/bigquery'
33

44
import { MESSAGE_SCHEMA, RELABELS_SCHEMA, TRACES_SCHEMA } from './schema'
55

6-
import type {
7-
BaseTrace,
8-
GetRelevantFilesTrace,
9-
MessageRow,
10-
Relabel,
11-
Trace,
12-
} from './schema'
6+
import type { BaseTrace, GetRelevantFilesTrace, Relabel, Trace } from './schema'
7+
import type { MessageRow } from '@codebuff/common/types/contracts/bigquery'
138
import type { Logger } from '@codebuff/common/types/contracts/logger'
149

1510
const DATASET =
@@ -99,7 +94,7 @@ export async function setupBigQuery({
9994
}
10095
}
10196

102-
export async function insertMessage({
97+
export async function insertMessageBigquery({
10398
row,
10499
dataset = DATASET,
105100
logger,

packages/bigquery/src/schema.ts

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -126,22 +126,6 @@ export const RELABELS_SCHEMA: TableSchema = {
126126
],
127127
}
128128

129-
export type MessageRow = {
130-
id: string
131-
user_id: string
132-
finished_at: Date
133-
created_at: Date
134-
request: unknown
135-
reasoning_text: string
136-
response: string
137-
output_tokens?: number | null
138-
reasoning_tokens?: number | null
139-
cost?: number | null
140-
upstream_inference_cost?: number | null
141-
input_tokens?: number | null
142-
cache_read_input_tokens?: number | null
143-
}
144-
145129
export const MESSAGE_SCHEMA: TableSchema = {
146130
fields: [
147131
{ name: 'id', type: 'STRING', mode: 'REQUIRED' },

scripts/fat-sdk-openrouter-example.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { createOpenAICompatible } from '@ai-sdk/openai-compatible'
22
import { websiteUrl } from '@codebuff/npm-app/config'
3-
import { streamText } from 'ai'
3+
import { generateText } from 'ai'
44

55
const codebuffBackendProvider = createOpenAICompatible({
66
name: 'codebuff',
77
apiKey: '12345',
88
baseURL: websiteUrl + '/api/v1',
99
})
1010

11-
const response = streamText({
11+
// const response = await streamText({
12+
const response = await generateText({
1213
model: codebuffBackendProvider('anthropic/claude-sonnet-4.5'),
1314
messages: [
1415
{
@@ -44,6 +45,8 @@ const response = streamText({
4445
},
4546
},
4647
})
47-
for await (const chunk of response.fullStream) {
48-
console.log({ chunk })
49-
}
48+
49+
console.dir({ response }, { depth: null })
50+
// for await (const chunk of response.fullStream) {
51+
// console.dir({ chunk }, { depth: null })
52+
// }

0 commit comments

Comments
 (0)