Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit 9fb6e81

Browse files
author
Frank
committed
wip: zen
1 parent 3ac8222 commit 9fb6e81

4 files changed

Lines changed: 14 additions & 11 deletions

File tree

packages/console/app/src/routes/zen/util/format.ts

Lines changed: 0 additions & 1 deletion
This file was deleted.

packages/console/app/src/routes/zen/util/handler.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ import {
1818
createStreamPartConverter,
1919
createResponseConverter,
2020
} from "./provider/provider"
21-
import { Format } from "./format"
2221
import { anthropicHelper } from "./provider/anthropic"
2322
import { openaiHelper } from "./provider/openai"
2423
import { oaCompatHelper } from "./provider/openai-compatible"
@@ -29,7 +28,7 @@ type Model = ZenData["models"][string]
2928
export async function handler(
3029
input: APIEvent,
3130
opts: {
32-
format: Format
31+
format: ZenData.Format
3332
parseApiKey: (headers: Headers) => string | undefined
3433
},
3534
) {
@@ -248,12 +247,14 @@ export async function handler(
248247
throw new ModelError(`Provider ${provider.id} not supported`)
249248
}
250249

250+
const format = zenData.providers[provider.id].format
251+
251252
return {
252253
...provider,
253254
...zenData.providers[provider.id],
254-
...(provider.id === "anthropic"
255+
...(format === "anthropic"
255256
? anthropicHelper
256-
: provider.id === "openai"
257+
: format === "openai"
257258
? openaiHelper
258259
: oaCompatHelper),
259260
}

packages/console/app/src/routes/zen/util/provider/provider.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
import { Format } from "../format"
2-
1+
import { ZenData } from "@opencode-ai/console-core/model.js"
32
import {
43
fromAnthropicChunk,
54
fromAnthropicRequest,
@@ -26,7 +25,7 @@ import {
2625
} from "./openai-compatible"
2726

2827
export type ProviderHelper = {
29-
format: Format
28+
format: ZenData.Format
3029
modifyUrl: (providerApi: string) => string
3130
modifyHeaders: (headers: Headers, body: Record<string, any>, apiKey: string) => void
3231
modifyBody: (body: Record<string, any>) => Record<string, any>
@@ -158,7 +157,7 @@ export interface CommonChunk {
158157
}
159158
}
160159

161-
export function createBodyConverter(from: Format, to: Format) {
160+
export function createBodyConverter(from: ZenData.Format, to: ZenData.Format) {
162161
return (body: any): any => {
163162
if (from === to) return body
164163

@@ -173,7 +172,7 @@ export function createBodyConverter(from: Format, to: Format) {
173172
}
174173
}
175174

176-
export function createStreamPartConverter(from: Format, to: Format) {
175+
export function createStreamPartConverter(from: ZenData.Format, to: ZenData.Format) {
177176
return (part: any): any => {
178177
if (from === to) return part
179178

@@ -191,7 +190,7 @@ export function createStreamPartConverter(from: Format, to: Format) {
191190
}
192191
}
193192

194-
export function createResponseConverter(from: Format, to: Format) {
193+
export function createResponseConverter(from: ZenData.Format, to: ZenData.Format) {
195194
return (response: any): any => {
196195
if (from === to) return response
197196

packages/console/core/src/model.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ import { Actor } from "./actor"
88
import { Resource } from "@opencode-ai/console-resource"
99

1010
export namespace ZenData {
11+
const FormatSchema = z.enum(["anthropic", "openai", "oa-compat"])
12+
export type Format = z.infer<typeof FormatSchema>
13+
1114
const ModelCostSchema = z.object({
1215
input: z.number(),
1316
output: z.number(),
@@ -34,6 +37,7 @@ export namespace ZenData {
3437
const ProviderSchema = z.object({
3538
api: z.string(),
3639
apiKey: z.string(),
40+
format: FormatSchema,
3741
headerMappings: z.record(z.string(), z.string()).optional(),
3842
})
3943

0 commit comments

Comments
 (0)