diff --git a/src/services/langfuse/__tests__/langfuse.test.ts b/src/services/langfuse/__tests__/langfuse.test.ts index dab33fd60..6c5a87947 100644 --- a/src/services/langfuse/__tests__/langfuse.test.ts +++ b/src/services/langfuse/__tests__/langfuse.test.ts @@ -231,6 +231,7 @@ describe('Langfuse integration', () => { test('merges assistant tool calls from OpenAI-style array content', async () => { const { convertMessagesToLangfuse } = await import('../convert.js') + // Content part with embedded tool_calls is non-standard; cast for defensive test const result = convertMessagesToLangfuse([ { role: 'assistant', @@ -255,7 +256,7 @@ describe('Langfuse integration', () => { }, ], }, - ]) + ] as any) expect(result).toEqual([ { diff --git a/src/services/langfuse/convert.ts b/src/services/langfuse/convert.ts index ad324c2a0..411692bce 100644 --- a/src/services/langfuse/convert.ts +++ b/src/services/langfuse/convert.ts @@ -10,7 +10,8 @@ * - tool_result blocks → separate { role: 'tool' } messages */ -import type { AssistantMessage } from 'src/types/message.js' +import type { AssistantMessage, UserMessage } from 'src/types/message.js' +import type { ChatCompletionMessageParam } from 'openai/resources/chat/completions/completions.mjs' type LangfuseContentPart = | { type: 'text'; text: string } @@ -79,6 +80,12 @@ function mergeToolCalls( return [...merged.values()] } +/** Union of all message formats accepted by Langfuse converters. */ +type LangfuseInputMessage = + | UserMessage + | AssistantMessage + | ChatCompletionMessageParam + /** Normalize a content block into a LangfuseContentPart (non-tool_use, non-tool_result) */ function toContentPart(block: Record): LangfuseContentPart | null { const type = block.type as string | undefined @@ -178,7 +185,7 @@ function toRoleFromWrappedMessage(msg: Record): 'user' | 'assis /** Convert internal or OpenAI-style messages → Langfuse input format */ export function convertMessagesToLangfuse( - messages: readonly unknown[], + messages: readonly LangfuseInputMessage[], systemPrompt?: readonly string[], ): LangfuseChatMessage[] { const result: LangfuseChatMessage[] = []