(
input: {
info: Info
parts: Part[]
}[],
)
| 438 | } |
| 439 | |
| 440 | export function toModelMessage( |
| 441 | input: { |
| 442 | info: Info |
| 443 | parts: Part[] |
| 444 | }[], |
| 445 | ): ModelMessage[] { |
| 446 | const result: UIMessage[] = [] |
| 447 | |
| 448 | for (const msg of input) { |
| 449 | if (msg.parts.length === 0) continue |
| 450 | |
| 451 | if (msg.info.role === "user") { |
| 452 | const userMessage: UIMessage = { |
| 453 | id: msg.info.id, |
| 454 | role: "user", |
| 455 | parts: [], |
| 456 | } |
| 457 | result.push(userMessage) |
| 458 | for (const part of msg.parts) { |
| 459 | if (part.type === "text" && !part.ignored) |
| 460 | userMessage.parts.push({ |
| 461 | type: "text", |
| 462 | text: part.text, |
| 463 | }) |
| 464 | // text/plain and directory files are converted into text parts, ignore them |
| 465 | if (part.type === "file" && part.mime !== "text/plain" && part.mime !== "application/x-directory") |
| 466 | userMessage.parts.push({ |
| 467 | type: "file", |
| 468 | url: part.url, |
| 469 | mediaType: part.mime, |
| 470 | filename: part.filename, |
| 471 | }) |
| 472 | |
| 473 | if (part.type === "compaction") { |
| 474 | userMessage.parts.push({ |
| 475 | type: "text", |
| 476 | text: "What did we do so far?", |
| 477 | }) |
| 478 | } |
| 479 | if (part.type === "subtask") { |
| 480 | userMessage.parts.push({ |
| 481 | type: "text", |
| 482 | text: "The following tool was executed by the user", |
| 483 | }) |
| 484 | } |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | if (msg.info.role === "assistant") { |
| 489 | const assistantMessage: UIMessage = { |
| 490 | id: msg.info.id, |
| 491 | role: "assistant", |
| 492 | parts: [], |
| 493 | } |
| 494 | result.push(assistantMessage) |
| 495 | for (const part of msg.parts) { |
| 496 | if (part.type === "text") |
| 497 | assistantMessage.parts.push({ |
nothing calls this directly
no test coverage detected