"use strict";
// =============================================================================
// Pure Agent - Anthropic Messages Transport
// Ported from Hermes agent/transports/anthropic.py
// =============================================================================
Object.defineProperty(exports, "__esModule", { value: true });
const types_1 = require("./types");
const registry_1 = require("./registry");
const anthropic_adapter_1 = require("./anthropic-adapter");
class AnthropicTransport {
    apiMode = 'anthropic_messages';
    convertMessages(messages) {
        return (0, anthropic_adapter_1.convertMessagesToAnthropic)(messages);
    }
    convertTools(tools) {
        return (0, anthropic_adapter_1.convertToolsToAnthropic)(tools);
    }
    buildRequestBody(model, messages, tools, params) {
        return (0, anthropic_adapter_1.buildAnthropicRequestBody)(model, messages, tools, params);
    }
    normalizeResponse(response) {
        const normalized = (0, anthropic_adapter_1.normalizeAnthropicResponse)(response);
        return {
            content: normalized.content,
            toolCalls: normalized.toolCalls?.map(tc => (0, types_1.buildToolCall)(tc.id, tc.name, tc.arguments)) || null,
            finishReason: normalized.finishReason,
            reasoning: normalized.reasoning,
            usage: normalized.usage || (0, types_1.emptyUsage)(),
        };
    }
    normalizeStreamChunk(chunk) {
        const event = (0, anthropic_adapter_1.normalizeAnthropicStreamEvent)(chunk);
        if (!event)
            return null;
        switch (event.type) {
            case 'content':
                return { content: event.content };
            case 'reasoning':
                return { reasoning: event.reasoning };
            case 'tool_call_start':
                return { toolCalls: [event.toolCall] };
            case 'tool_call_delta':
                return { toolCalls: [event.toolCall] };
            case 'finish':
                return { finishReason: event.finishReason };
            case 'usage':
                return { usage: event.usage };
            default:
                return null;
        }
    }
    getEndpoint() {
        return (0, anthropic_adapter_1.getAnthropicEndpoint)();
    }
    getExtraHeaders() {
        return {
            'anthropic-version': '2023-06-01',
        };
    }
}
// Auto-register
(0, registry_1.registerTransport)('anthropic_messages', () => new AnthropicTransport());
//# sourceMappingURL=anthropic.js.map