File tree Expand file tree Collapse file tree
packages/console/app/src/routes/zen Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import type { APIEvent } from "@solidjs/start/server"
22import { handler } from "~/routes/zen/util/handler"
3+ import { parseOpenAiVariant } from "~/routes/zen/util/variant"
34
45export function POST ( input : APIEvent ) {
56 return handler ( input , {
67 format : "oa-compat" ,
78 modelList : "lite" ,
89 parseApiKey : ( headers : Headers ) => headers . get ( "authorization" ) ?. split ( " " ) [ 1 ] ,
910 parseModel : ( url : string , body : any ) => body . model ,
10- parseVariant : ( url : string , body : any ) => body . reasoningEffort ?? body . reasoning_effort ,
11+ parseVariant : ( url : string , body : any ) => parseOpenAiVariant ( body ) ,
1112 parseIsStream : ( url : string , body : any ) => ! ! body . stream ,
1213 } )
1314}
Original file line number Diff line number Diff line change 11import type { APIEvent } from "@solidjs/start/server"
22import { handler } from "~/routes/zen/util/handler"
3+ import { parseAnthropicVariant } from "~/routes/zen/util/variant"
34
45export function POST ( input : APIEvent ) {
56 return handler ( input , {
67 format : "anthropic" ,
78 modelList : "lite" ,
89 parseApiKey : ( headers : Headers ) => headers . get ( "x-api-key" ) ?? undefined ,
910 parseModel : ( url : string , body : any ) => body . model ,
10- parseVariant : ( url : string , body : any ) => body . effort ,
11+ parseVariant : ( url : string , body : any ) => parseAnthropicVariant ( body ) ,
1112 parseIsStream : ( url : string , body : any ) => ! ! body . stream ,
1213 } )
1314}
Original file line number Diff line number Diff line change 1+ export function parseAnthropicVariant ( body : any ) {
2+ const effort = body . effort ?? body . output_config ?. effort ?? body . outputConfig ?. effort ?? body . thinking ?. effort
3+ if ( effort ) return effort
4+
5+ const budget = body . thinking ?. budget_tokens ?? body . thinking ?. budgetTokens
6+ if ( body . thinking ?. type !== "enabled" || typeof budget !== "number" ) return undefined
7+ return budget > 16_000 ? "max" : "high"
8+ }
9+
10+ export function parseGoogleVariant ( body : any ) {
11+ const thinkingConfig = body . generationConfig ?. thinkingConfig ?? body . thinkingConfig
12+ if ( thinkingConfig ?. thinkingLevel ) return thinkingConfig . thinkingLevel
13+
14+ const budget = thinkingConfig ?. thinkingBudget ?? thinkingConfig ?. thinking_budget
15+ if ( typeof budget !== "number" || budget <= 0 ) return undefined
16+ return budget > 16_000 ? "max" : "high"
17+ }
18+
19+ export function parseOpenAiVariant ( body : any ) {
20+ return body . reasoningEffort ?? body . reasoning_effort ?? body . reasoning ?. effort
21+ }
Original file line number Diff line number Diff line change 11import type { APIEvent } from "@solidjs/start/server"
22import { handler } from "~/routes/zen/util/handler"
3+ import { parseOpenAiVariant } from "~/routes/zen/util/variant"
34
45export function POST ( input : APIEvent ) {
56 return handler ( input , {
67 format : "oa-compat" ,
78 modelList : "full" ,
89 parseApiKey : ( headers : Headers ) => headers . get ( "authorization" ) ?. split ( " " ) [ 1 ] ,
910 parseModel : ( url : string , body : any ) => body . model ,
10- parseVariant : ( url : string , body : any ) => body . reasoningEffort ?? body . reasoning_effort ,
11+ parseVariant : ( url : string , body : any ) => parseOpenAiVariant ( body ) ,
1112 parseIsStream : ( url : string , body : any ) => ! ! body . stream ,
1213 } )
1314}
Original file line number Diff line number Diff line change 11import type { APIEvent } from "@solidjs/start/server"
22import { handler } from "~/routes/zen/util/handler"
3+ import { parseAnthropicVariant } from "~/routes/zen/util/variant"
34
45export function POST ( input : APIEvent ) {
56 return handler ( input , {
67 format : "anthropic" ,
78 modelList : "full" ,
89 parseApiKey : ( headers : Headers ) => headers . get ( "x-api-key" ) ?? undefined ,
910 parseModel : ( url : string , body : any ) => body . model ,
10- parseVariant : ( url : string , body : any ) => body . effort ,
11+ parseVariant : ( url : string , body : any ) => parseAnthropicVariant ( body ) ,
1112 parseIsStream : ( url : string , body : any ) => ! ! body . stream ,
1213 } )
1314}
Original file line number Diff line number Diff line change 11import type { APIEvent } from "@solidjs/start/server"
22import { handler } from "~/routes/zen/util/handler"
3+ import { parseGoogleVariant } from "~/routes/zen/util/variant"
34
45export function POST ( input : APIEvent ) {
56 return handler ( input , {
67 format : "google" ,
78 modelList : "full" ,
89 parseApiKey : ( headers : Headers ) => headers . get ( "x-goog-api-key" ) ?? undefined ,
910 parseModel : ( url : string , _body : any ) => url . split ( "/" ) . pop ( ) ?. split ( ":" ) ?. [ 0 ] ?? "" ,
10- parseVariant : ( url : string , body : any ) => body . thinkingLevel ,
11+ parseVariant : ( url : string , body : any ) => parseGoogleVariant ( body ) ,
1112 parseIsStream : ( url : string , _body : any ) =>
1213 // ie. url: https://opencode.ai/zen/v1/models/gemini-3-pro:streamGenerateContent?alt=sse'
1314 url . split ( "/" ) . pop ( ) ?. split ( ":" ) ?. [ 1 ] ?. startsWith ( "streamGenerateContent" ) ?? false ,
Original file line number Diff line number Diff line change 11import type { APIEvent } from "@solidjs/start/server"
22import { handler } from "~/routes/zen/util/handler"
3+ import { parseOpenAiVariant } from "~/routes/zen/util/variant"
34
45export function POST ( input : APIEvent ) {
56 return handler ( input , {
67 format : "openai" ,
78 modelList : "full" ,
89 parseApiKey : ( headers : Headers ) => headers . get ( "authorization" ) ?. split ( " " ) [ 1 ] ,
910 parseModel : ( url : string , body : any ) => body . model ,
10- parseVariant : ( url : string , body : any ) => body . reasoning ?. effort ,
11+ parseVariant : ( url : string , body : any ) => parseOpenAiVariant ( body ) ,
1112 parseIsStream : ( url : string , body : any ) => ! ! body . stream ,
1213 } )
1314}
You can’t perform that action at this time.
0 commit comments