Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
drop title-gen stub, translate json_schema to Responses text.format
Raine Virta87b7e8454af4
diff --git a/src/anthropic/schema.ts b/src/anthropic/schema.tsindex a8d784a..9743c13 100644--- a/src/anthropic/schema.ts+++ b/src/anthropic/schema.ts@@ -55,7 +55,7 @@ export interface AnthropicRequest {thinking?: { type: string; [k: string]: unknown }output_config?: {effort?: "low" | "medium" | "high"- format?: { type: "json_schema"; schema: unknown; name?: string }+ format?: { type: "json_schema"; schema: unknown; name?: string; strict?: boolean }}context_management?: unknownmetadata?: unknowndiff --git a/src/server.ts b/src/server.tsindex 553c67e..a544ab2 100644--- a/src/server.ts+++ b/src/server.ts@@ -1,10 +1,9 @@import { createLogger, logDir } from "./log.ts"import type { AnthropicRequest } from "./anthropic/schema.ts"import { assertAllowedModel, ModelNotAllowedError } from "./translate/model-allowlist.ts"-import { isTitleGenRequest, translateRequest } from "./translate/request.ts"+import { translateRequest } from "./translate/request.ts"import { translateStream } from "./translate/stream.ts"import { accumulateResponse } from "./translate/accumulate.ts"-import { encodeSseEvent } from "./translate/sse.ts"import { CodexError, postCodex } from "./codex/client.ts"import { countTokens } from "./count-tokens.ts"@@ -82,14 +81,9 @@ async function handleMessages(req: Request, reqId: string): Promise<Response> {toolCount: body.tools?.length ?? 0,stream: wantStream,sessionId,- hasTitleGenFormat: isTitleGenRequest(body),+ hasJsonSchemaFormat: body.output_config?.format?.type === "json_schema",})- // Title-generation stub: Claude Code fires this in parallel for session titles.- if (isTitleGenRequest(body)) {- return titleGenStub({ messageId, model: body.model, wantStream })- }-try {assertAllowedModel(body.model)} catch (err) {@@ -154,90 +148,6 @@ async function handleMessages(req: Request, reqId: string): Promise<Response> {})}-function titleGenStub(opts: {- messageId: string- model: string- wantStream: boolean-}): Response {- const content = [{ type: "text" as const, text: JSON.stringify({ title: "Session" }) }]- if (!opts.wantStream) {- return new Response(- JSON.stringify({- id: opts.messageId,- type: "message",- role: "assistant",- model: opts.model,- content,- stop_reason: "end_turn",- stop_sequence: null,- usage: {- input_tokens: 0,- output_tokens: 0,- cache_creation_input_tokens: 0,- cache_read_input_tokens: 0,- },- }),- { headers: { "content-type": "application/json" } },- )- }- const enc = new TextEncoder()- const stream = new ReadableStream<Uint8Array>({- start(controller) {- const emit = (event: string, data: unknown) =>- controller.enqueue(enc.encode(encodeSseEvent(event, data)))- emit("message_start", {- type: "message_start",- message: {- id: opts.messageId,- type: "message",- role: "assistant",- model: opts.model,- content: [],- stop_reason: null,- stop_sequence: null,- usage: {- input_tokens: 0,- output_tokens: 0,- cache_creation_input_tokens: 0,- cache_read_input_tokens: 0,- },- },- })- emit("ping", { type: "ping" })- emit("content_block_start", {- type: "content_block_start",- index: 0,- content_block: { type: "text", text: "" },- })- emit("content_block_delta", {- type: "content_block_delta",- index: 0,- delta: { type: "text_delta", text: content[0]!.text },- })- emit("content_block_stop", { type: "content_block_stop", index: 0 })- emit("message_delta", {- type: "message_delta",- delta: { stop_reason: "end_turn", stop_sequence: null },- usage: {- input_tokens: 0,- output_tokens: 0,- cache_creation_input_tokens: 0,- cache_read_input_tokens: 0,- },- })- emit("message_stop", { type: "message_stop" })- controller.close()- },- })- return new Response(stream, {- headers: {- "content-type": "text/event-stream",- "cache-control": "no-cache",- connection: "keep-alive",- },- })-}-function jsonError(status: number, type: string, message: string): Response {return new Response(JSON.stringify({ type: "error", error: { type, message } }), {status,diff --git a/src/translate/request.ts b/src/translate/request.tsindex a89f9fc..e67c5df 100644--- a/src/translate/request.ts+++ b/src/translate/request.ts@@ -18,7 +18,13 @@ export interface ResponsesRequest {include?: string[]prompt_cache_key?: stringreasoning?: { effort?: "low" | "medium" | "high" }- text?: { verbosity?: "low" | "medium" | "high" }+ text?: {+ verbosity?: "low" | "medium" | "high"+ format?:+ | { type: "text" }+ | { type: "json_object" }+ | { type: "json_schema"; name: string; schema: unknown; strict?: boolean }+ }}export type ResponsesInputItem =@@ -56,15 +62,22 @@ export interface TranslateOptions {sessionId?: string}-export function isTitleGenRequest(req: AnthropicRequest): boolean {- return req.output_config?.format?.type === "json_schema"-}-export function translateRequest(req: AnthropicRequest, opts: TranslateOptions = {}): ResponsesRequest {const instructions = buildInstructions(req.system)const input = buildInput(req.messages)const tools = req.tools?.map(toResponsesTool)+ const text: ResponsesRequest["text"] = { verbosity: "low" }+ const fmt = req.output_config?.format+ if (fmt?.type === "json_schema") {+ text.format = {+ type: "json_schema",+ name: fmt.name ?? "response",+ schema: fmt.schema,+ strict: true,+ }+ }+const out: ResponsesRequest = {model: req.model,input,@@ -73,7 +86,7 @@ export function translateRequest(req: AnthropicRequest, opts: TranslateOptions =include: ["reasoning.encrypted_content"],parallel_tool_calls: true,tool_choice: mapToolChoice(req.tool_choice),- text: { verbosity: "low" },+ text,}if (instructions) out.instructions = instructionsif (tools && tools.length) out.tools = tools