From aab520648b5ad9b49cb72f280d761fde3fd53d0b Mon Sep 17 00:00:00 2001 From: kim Date: Sat, 17 Oct 2026 22:03:41 +0900 Subject: [PATCH] =?UTF-8?q?Anthropic=20=EC=96=B4=EB=8C=91=ED=84=B0:=20?= =?UTF-8?q?=ED=86=A0=ED=81=B0=20=EC=82=AC=EC=9A=A9=EB=9F=89(=EC=9D=B4?= =?UTF-8?q?=EB=AF=B8=EC=A7=80=C2=B7=EC=BA=90=EC=8B=9C=20=ED=8F=AC=ED=95=A8?= =?UTF-8?q?)=EC=9D=84=20=EA=B2=8C=EC=9D=B4=EC=A7=80/=EB=B9=84=EC=9A=A9=20?= =?UTF-8?q?=EA=B8=B0=EB=A1=9D=EC=97=90=20=EB=B0=98=EC=98=81,=20=EB=8F=84?= =?UTF-8?q?=EA=B5=AC=20=EA=B2=B0=EA=B3=BC=EC=9D=98=20=EC=9D=B4=EB=AF=B8?= =?UTF-8?q?=EC=A7=80=EB=A5=BC=20Claude=EC=97=90=20=EC=A0=84=EB=8B=AC,=20?= =?UTF-8?q?=EB=AA=A8=EB=8D=B8=20=EB=AA=A9=EB=A1=9D=EC=97=90=205.5=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Sonnet 5.5 --- src/providers/anthropic-adapter.ts | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/providers/anthropic-adapter.ts b/src/providers/anthropic-adapter.ts index 5007a0f..92d7876 100644 --- a/src/providers/anthropic-adapter.ts +++ b/src/providers/anthropic-adapter.ts @@ -4,6 +4,7 @@ * Converts between the server's OpenAI-style ChatMessage format and Anthropic's format. */ +import { logUsage } from './usage-log'; import type { LLMProvider, ChatMessage, ContentPart, ChatOptions, ChatResult, GenerateOptions, GenerateResult, ModelInfo, @@ -67,7 +68,17 @@ export class AnthropicAdapter implements LLMProvider { } const data = await this.post('/v1/messages', body); - return fromAnthropicResponse(data); + const result = fromAnthropicResponse(data); + // 사용량: 지금까지 이 어댑터는 토큰 수를 버렸다 — 컨텍스트 게이지·비용 기록(token-usage.jsonl)에 Claude 호출이 전혀 안 잡혔다 + // (2026-10-17). 입력 토큰에는 이미지·캐시된 토큰도 포함해야 실제 부담이 보인다. + const u = data?.usage; + if (u) { + const promptTokens = (Number(u.input_tokens) || 0) + (Number(u.cache_creation_input_tokens) || 0) + (Number(u.cache_read_input_tokens) || 0); + const completionTokens = Number(u.output_tokens) || 0; + logUsage(model, promptTokens, completionTokens); + return { ...result, usage: { promptTokens, completionTokens, ctxWindow: Number(options?.num_ctx) || 0 } } as ChatResult; + } + return result; } async generate(prompt: string, model: string, options?: GenerateOptions): Promise { @@ -87,7 +98,9 @@ export class AnthropicAdapter implements LLMProvider { async listModels(): Promise { // Anthropic has no public list-models endpoint; return known models return [ - { name: 'claude-opus-4-7' }, + { name: 'claude-haiku-5-5' }, + { name: 'claude-sonnet-5-5' }, + { name: 'claude-opus-5-5' }, { name: 'claude-sonnet-4-6' }, { name: 'claude-haiku-4-5-20251001' }, ]; @@ -121,7 +134,9 @@ function toAnthropicMessages(messages: ChatMessage[]): any[] { const block = { type: 'tool_result', tool_use_id: msg.tool_call_id ?? '', - content: contentToString(msg.content), + // 도구 결과의 이미지(python_eval 차트·CCTV 캡처 등)도 그대로 넘긴다 — contentToString은 이미지 파트를 버려서 + // Claude가 도구가 만든 그림을 한 번도 보지 못했다. Anthropic은 tool_result 안에 text+image 블록을 허용한다. + content: toAnthropicContent(msg.content), }; const last = out[out.length - 1]; if (last?.role === 'user' && Array.isArray(last.content)) {