|
@@ -1,35 +1,8 @@
|
|
|
import { describe, expect, test } from "bun:test"
|
|
import { describe, expect, test } from "bun:test"
|
|
|
import { MessageV2 } from "../../src/session/message-v2"
|
|
import { MessageV2 } from "../../src/session/message-v2"
|
|
|
-import type { ToolSet } from "ai"
|
|
|
|
|
|
|
|
|
|
const sessionID = "session"
|
|
const sessionID = "session"
|
|
|
|
|
|
|
|
-// Mock tool that transforms output to content format with media support
|
|
|
|
|
-function createMockTools(): ToolSet {
|
|
|
|
|
- return {
|
|
|
|
|
- bash: {
|
|
|
|
|
- description: "mock bash tool",
|
|
|
|
|
- inputSchema: { type: "object", properties: {} } as any,
|
|
|
|
|
- toModelOutput(result: { output: string; attachments?: MessageV2.FilePart[] }) {
|
|
|
|
|
- return {
|
|
|
|
|
- type: "content" as const,
|
|
|
|
|
- value: [
|
|
|
|
|
- { type: "text" as const, text: result.output },
|
|
|
|
|
- ...(result.attachments?.map((attachment) => {
|
|
|
|
|
- const base64 = attachment.url.startsWith("data:") ? attachment.url.split(",", 2)[1] : attachment.url
|
|
|
|
|
- return {
|
|
|
|
|
- type: "media" as const,
|
|
|
|
|
- data: base64,
|
|
|
|
|
- mediaType: attachment.mime,
|
|
|
|
|
- }
|
|
|
|
|
- }) ?? []),
|
|
|
|
|
- ],
|
|
|
|
|
- }
|
|
|
|
|
- },
|
|
|
|
|
- },
|
|
|
|
|
- } as ToolSet
|
|
|
|
|
-}
|
|
|
|
|
-
|
|
|
|
|
function userInfo(id: string): MessageV2.User {
|
|
function userInfo(id: string): MessageV2.User {
|
|
|
return {
|
|
return {
|
|
|
id,
|
|
id,
|
|
@@ -286,11 +259,23 @@ describe("session.message-v2.toModelMessage", () => {
|
|
|
},
|
|
},
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
- expect(MessageV2.toModelMessage(input, { tools: createMockTools() })).toStrictEqual([
|
|
|
|
|
|
|
+ expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
|
{
|
|
{
|
|
|
role: "user",
|
|
role: "user",
|
|
|
content: [{ type: "text", text: "run tool" }],
|
|
content: [{ type: "text", text: "run tool" }],
|
|
|
},
|
|
},
|
|
|
|
|
+ {
|
|
|
|
|
+ role: "user",
|
|
|
|
|
+ content: [
|
|
|
|
|
+ { type: "text", text: "Tool bash returned an attachment:" },
|
|
|
|
|
+ {
|
|
|
|
|
+ type: "file",
|
|
|
|
|
+ mediaType: "image/png",
|
|
|
|
|
+ filename: "attachment.png",
|
|
|
|
|
+ data: "https://example.com/attachment.png",
|
|
|
|
|
+ },
|
|
|
|
|
+ ],
|
|
|
|
|
+ },
|
|
|
{
|
|
{
|
|
|
role: "assistant",
|
|
role: "assistant",
|
|
|
content: [
|
|
content: [
|
|
@@ -312,13 +297,7 @@ describe("session.message-v2.toModelMessage", () => {
|
|
|
type: "tool-result",
|
|
type: "tool-result",
|
|
|
toolCallId: "call-1",
|
|
toolCallId: "call-1",
|
|
|
toolName: "bash",
|
|
toolName: "bash",
|
|
|
- output: {
|
|
|
|
|
- type: "content",
|
|
|
|
|
- value: [
|
|
|
|
|
- { type: "text", text: "ok" },
|
|
|
|
|
- { type: "media", data: "https://example.com/attachment.png", mediaType: "image/png" },
|
|
|
|
|
- ],
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ output: { type: "text", value: "ok" },
|
|
|
providerOptions: { openai: { tool: "meta" } },
|
|
providerOptions: { openai: { tool: "meta" } },
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
@@ -362,7 +341,7 @@ describe("session.message-v2.toModelMessage", () => {
|
|
|
},
|
|
},
|
|
|
]
|
|
]
|
|
|
|
|
|
|
|
- expect(MessageV2.toModelMessage(input, { tools: createMockTools() })).toStrictEqual([
|
|
|
|
|
|
|
+ expect(MessageV2.toModelMessage(input)).toStrictEqual([
|
|
|
{
|
|
{
|
|
|
role: "user",
|
|
role: "user",
|
|
|
content: [{ type: "text", text: "run tool" }],
|
|
content: [{ type: "text", text: "run tool" }],
|
|
@@ -386,10 +365,7 @@ describe("session.message-v2.toModelMessage", () => {
|
|
|
type: "tool-result",
|
|
type: "tool-result",
|
|
|
toolCallId: "call-1",
|
|
toolCallId: "call-1",
|
|
|
toolName: "bash",
|
|
toolName: "bash",
|
|
|
- output: {
|
|
|
|
|
- type: "content",
|
|
|
|
|
- value: [{ type: "text", text: "[Old tool result content cleared]" }],
|
|
|
|
|
- },
|
|
|
|
|
|
|
+ output: { type: "text", value: "[Old tool result content cleared]" },
|
|
|
},
|
|
},
|
|
|
],
|
|
],
|
|
|
},
|
|
},
|