MCPcopy Index your code
hub / github.com/continuedev/continue / convertToUnifiedMessage

Function convertToUnifiedMessage

core/util/messageConversion.ts:23–71  ·  view source on GitHub ↗
(
  message: ChatCompletionMessageParam,
)

Source from the content-addressed store, hash-verified

21 * Convert ChatCompletionMessageParam to ChatMessage
22 */
23export function convertToUnifiedMessage(
24 message: ChatCompletionMessageParam,
25): ChatMessage {
26 switch (message.role) {
27 case "system":
28 return {
29 role: "system",
30 content: typeof message.content === "string" ? message.content : "",
31 };
32
33 case "user":
34 return {
35 role: "user",
36 content: convertMessageContent(message.content),
37 };
38
39 case "assistant": {
40 const assistantMessage: AssistantChatMessage = {
41 role: "assistant",
42 content: convertMessageContent(message.content || ""),
43 };
44
45 // Convert tool calls if present
46 if ("tool_calls" in message && message.tool_calls) {
47 assistantMessage.toolCalls = message.tool_calls.map((tc: any) => ({
48 id: tc.id,
49 type: "function" as const,
50 function: {
51 name: tc.function?.name || "",
52 arguments: tc.function?.arguments || "",
53 },
54 ...(tc.extra_content && { extra_content: tc.extra_content }),
55 }));
56 }
57
58 return assistantMessage;
59 }
60
61 case "tool":
62 return {
63 role: "tool",
64 content: typeof message.content === "string" ? message.content : "",
65 toolCallId: message.tool_call_id,
66 };
67
68 default:
69 throw new Error(`Unsupported message role: ${(message as any).role}`);
70 }
71}
72
73/**
74 * Convert ChatMessage to ChatCompletionMessageParam

Callers 1

convertToUnifiedHistoryFunction · 0.85

Calls 1

convertMessageContentFunction · 0.85

Tested by

no test coverage detected