Use Claude Code with your ChatGPT, Kimi, Cursor or Grok subscription via a local Anthropic-compatible proxy
Rust
share anthropic non-stream response types via provider translate accumulate
Raine Virta414cb621b25b
diff --git a/src/providers/codex/translate/accumulate.ts b/src/providers/codex/translate/accumulate.tsindex e5cc24d..627d949 100644--- a/src/providers/codex/translate/accumulate.ts+++ b/src/providers/codex/translate/accumulate.ts@@ -5,6 +5,7 @@ import type { TrafficCapture } from "../../types.ts";import { attachTrafficCapture, createUpstreamStreamDiagnostics } from "./reducer.ts";import {collectAnthropicContentFromAccumulatedBlocks,+ AnthropicNonStreamResponse,createBlockAccumulator,defaultAnthropicNonStreamUsage,parseToolInputJsonOrRaw,@@ -12,24 +13,6 @@ import {export { UpstreamStreamError } from "./reducer.ts";-export interface AnthropicNonStreamResponse {- id: string;- type: "message";- role: "assistant";- model: string;- content: Array<- { type: "text"; text: string } | { type: "tool_use"; id: string; name: string; input: unknown }- >;- stop_reason: "end_turn" | "tool_use" | "max_tokens" | null;- stop_sequence: null;- usage: {- input_tokens: number;- output_tokens: number;- cache_creation_input_tokens: number;- cache_read_input_tokens: number;- };-}-type FinishEvent = Extract<ReducerEvent, { kind: "finish" }>;export interface AccumulatedResponse {diff --git a/src/providers/kimi/translate/accumulate.ts b/src/providers/kimi/translate/accumulate.tsindex 381ff49..436675f 100644--- a/src/providers/kimi/translate/accumulate.ts+++ b/src/providers/kimi/translate/accumulate.ts@@ -3,6 +3,7 @@ import { makeThinkingSignature } from "./signature.ts";import type { TrafficCapture } from "../../types.ts";import {collectAnthropicContentFromAccumulatedBlocks,+ AnthropicNonStreamResponse,createBlockAccumulator,defaultAnthropicNonStreamUsage,parseToolInputJsonOrRaw,@@ -10,26 +11,6 @@ import {export { UpstreamStreamError } from "./reducer.ts";-export interface AnthropicNonStreamResponse {- id: string;- type: "message";- role: "assistant";- model: string;- content: Array<- | { type: "text"; text: string }- | { type: "thinking"; thinking: string; signature: string }- | { type: "tool_use"; id: string; name: string; input: unknown }- >;- stop_reason: "end_turn" | "tool_use" | "max_tokens" | null;- stop_sequence: null;- usage: {- input_tokens: number;- output_tokens: number;- cache_creation_input_tokens: number;- cache_read_input_tokens: number;- };-}-export interface AccumulatedResponse {response: AnthropicNonStreamResponse;rawUsage?: KimiUsage;diff --git a/src/providers/translate/accumulate.ts b/src/providers/translate/accumulate.tsindex 7db91d6..964e78c 100644--- a/src/providers/translate/accumulate.ts+++ b/src/providers/translate/accumulate.ts@@ -40,6 +40,26 @@ export interface AnthropicNonStreamUsage {cache_read_input_tokens: number;}+export type AnthropicTextContent = { type: "text"; text: string };+export type AnthropicThinkingContent = { type: "thinking"; thinking: string; signature: string };+export type AnthropicToolUseContent = { type: "tool_use"; id: string; name: string; input: unknown };++export type AnthropicNonStreamContent =+ | AnthropicTextContent+ | AnthropicThinkingContent+ | AnthropicToolUseContent;++export interface AnthropicNonStreamResponse<ContentType = AnthropicNonStreamContent> {+ id: string;+ type: "message";+ role: "assistant";+ model: string;+ content: Array<ContentType>;+ stop_reason: "end_turn" | "tool_use" | "max_tokens" | null;+ stop_sequence: null;+ usage: AnthropicNonStreamUsage;+}+export interface CachedInputUsage {inputTokens?: number;outputTokens?: number;