| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { describe, expect, test } from "bun:test"
- import { Message, ToolResultPart } from "@opencode-ai/ai"
- import { unsupportedParts } from "@opencode-ai/core/session/model-request"
- const capabilities = (input: string[]) => ({ tools: true, input, output: ["text"] })
- describe("SessionModelRequest.unsupportedParts", () => {
- test("replaces unsupported user media with a visible error", () => {
- const messages = unsupportedParts(
- [
- Message.user([
- Message.text("Describe this image"),
- { type: "media", mediaType: "image/png", data: "aGVsbG8=", filename: "logo.png" },
- ]),
- ],
- capabilities(["text"]),
- )
- expect(messages[0]?.content).toEqual([
- Message.text("Describe this image"),
- Message.text('ERROR: Cannot read "logo.png" (this model does not support image input). Inform the user.'),
- ])
- })
- test("replaces unsupported media nested in tool results", () => {
- const messages = unsupportedParts(
- [
- Message.tool(
- ToolResultPart.make({
- id: "call_1",
- name: "read",
- result: {
- type: "content",
- value: [
- { type: "text", text: "Image read successfully" },
- { type: "file", uri: "data:image/png;base64,aGVsbG8=", mime: "image/png", name: "logo.png" },
- ],
- },
- }),
- ),
- ],
- capabilities(["text"]),
- )
- expect(messages[0]?.content[0]).toMatchObject({
- type: "tool-result",
- result: {
- type: "content",
- value: [
- { type: "text", text: "Image read successfully" },
- {
- type: "text",
- text: 'ERROR: Cannot read "logo.png" (this model does not support image input). Inform the user.',
- },
- ],
- },
- })
- })
- test("preserves supported media", () => {
- const message = Message.user({ type: "media", mediaType: "image/png", data: "aGVsbG8=" })
- expect(unsupportedParts([message], capabilities(["text", "image"]))[0]?.content).toEqual(message.content)
- })
- })
|