UNPKG

@just-every/ensemble

Version:

LLM provider abstraction layer with unified streaming interface

64 lines 2.24 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.convertToThinkingMessage = convertToThinkingMessage; exports.convertToOutputMessage = convertToOutputMessage; exports.convertToFunctionCall = convertToFunctionCall; exports.convertToFunctionCallOutput = convertToFunctionCallOutput; exports.ensureMessageId = ensureMessageId; const crypto_1 = require("crypto"); function convertToThinkingMessage(event, model) { return { id: event.message_id || (0, crypto_1.randomUUID)(), type: 'thinking', role: 'assistant', content: event.thinking_content || '', signature: event.thinking_signature || '', thinking_id: event.message_id || '', status: 'completed', model, timestamp: event.timestamp ? new Date(event.timestamp).getTime() : undefined, }; } function convertToOutputMessage(event, model, status = 'completed') { return { id: event.message_id || (0, crypto_1.randomUUID)(), type: 'message', role: 'assistant', content: event.content, status, model, timestamp: event.timestamp ? new Date(event.timestamp).getTime() : undefined, }; } function convertToFunctionCall(toolCall, model, status = 'completed') { return { id: toolCall.id || (0, crypto_1.randomUUID)(), type: 'function_call', call_id: toolCall.call_id || toolCall.id, name: toolCall.function.name, arguments: toolCall.function.arguments, model, status, timestamp: Date.now(), }; } function convertToFunctionCallOutput(toolResult, model, status = 'completed') { const id = toolResult.id ? `${toolResult.id}_output` : (0, crypto_1.randomUUID)(); return { id, type: 'function_call_output', call_id: toolResult.call_id || toolResult.toolCall.id, name: toolResult.toolCall.function.name, output: toolResult.output + (toolResult.error || ''), model, status, timestamp: Date.now(), }; } function ensureMessageId(message) { if (!message.id) { message.id = (0, crypto_1.randomUUID)(); } return message; } //# sourceMappingURL=message_converter.js.map