/**
 * Provider-owned codec for translating between Heddle LLM port types and the
 * Anthropic Messages API payloads.
 */
export class AnthropicCodec {
    static toMessages(messages) {
        const result = [];
        for (const message of messages) {
            switch (message.role) {
                case 'system':
                    break;
                case 'user':
                    result.push({ role: 'user', content: message.content });
                    break;
                case 'assistant': {
                    const content = [];
                    if (message.content) {
                        content.push({ type: 'text', text: message.content });
                    }
                    for (const call of message.toolCalls ?? []) {
                        content.push({
                            type: 'tool_use',
                            id: call.id,
                            name: call.tool,
                            input: call.input,
                        });
                    }
                    result.push({ role: 'assistant', content });
                    break;
                }
                case 'tool':
                    result.push({
                        role: 'user',
                        content: [{
                                type: 'tool_result',
                                tool_use_id: message.toolCallId,
                                content: message.content,
                            }],
                    });
                    break;
            }
        }
        return result;
    }
    static toTool(tool) {
        return {
            name: tool.name,
            description: tool.description,
            input_schema: tool.parameters,
        };
    }
    static extractUsage(usage) {
        if (!usage) {
            return undefined;
        }
        return {
            inputTokens: usage.input_tokens,
            outputTokens: usage.output_tokens,
            totalTokens: usage.input_tokens + usage.output_tokens,
            requests: 1,
        };
    }
}
//# sourceMappingURL=anthropic-codec.js.map