{"record":{"id":"bf9da07291490058","repo":"earendil-works/pi","slug":"invalid-mistral-streaming-event","errorCode":null,"errorMessage":"Invalid Mistral streaming event","messagePattern":"Invalid Mistral streaming event","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"packages/ai/src/api/mistral-conversations.ts","lineNumber":498,"sourceCode":"\nfunction findMistralEventBoundary(buffer: string): { index: number; length: number } | undefined {\n\tconst match = /\\r\\n\\r\\n|\\r\\n\\r|\\r\\n\\n|\\r\\r\\n|\\n\\r\\n|\\r\\r|\\n\\r|\\n\\n/u.exec(buffer);\n\treturn match?.index === undefined ? undefined : { index: match.index, length: match[0].length };\n}\n\nfunction parseMistralEvent(raw: string): MistralCompletionEvent | typeof MISTRAL_STREAM_DONE | undefined {\n\tconst data = raw\n\t\t.split(/\\r\\n|\\r|\\n/u)\n\t\t.filter((line) => line.startsWith(\"data:\"))\n\t\t.map((line) => line.slice(5).trimStart())\n\t\t.join(\"\\n\")\n\t\t.trim();\n\tif (!data) return undefined;\n\tif (data === \"[DONE]\") return MISTRAL_STREAM_DONE;\n\n\tconst parsed: unknown = JSON.parse(data);\n\tif (!isMistralRecord(parsed) || !Array.isArray(parsed.choices)) {\n\t\tthrow new Error(\"Invalid Mistral streaming event\");\n\t}\n\treturn { data: parsed as MistralCompletionEvent[\"data\"] };\n}\n\nfunction buildChatPayload(\n\tmodel: Model<\"mistral-conversations\">,\n\tcontext: Context,\n\tmessages: Message[],\n\toptions?: MistralOptions,\n): MistralChatPayload {\n\tconst payload: MistralChatPayload = {\n\t\tmodel: model.id,\n\t\tstream: true,\n\t\tmessages: toChatMessages(messages, model.input.includes(\"image\")),\n\t};\n\n\tif (context.tools?.length) payload.tools = toFunctionTools(context.tools);\n\tif (options?.temperature !== undefined) payload.temperature = options.temperature;","sourceCodeStart":480,"sourceCodeEnd":516,"githubUrl":"https://github.com/earendil-works/pi/blob/4af9d21d3b4d664e4a29fcabfec85171077248e3/packages/ai/src/api/mistral-conversations.ts#L480-L516","documentation":"Error \"Invalid Mistral streaming event\" thrown in earendil-works/pi.","triggerScenarios":"Thrown at packages/ai/src/api/mistral-conversations.ts:498 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Log the raw event; update the parser if Mistral changed the streaming event shape."],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"4af9d21d3b4d664e4a29fcabfec85171077248e3","analyzedAt":"2026-08-24T13:07:14.692Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}