Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(playground): don't stringify ai sdk messages (#10275)

Nimar8c038778f433
diff --git a/web/src/utils/chatml/jumptoplayground.clienttest.ts b/web/src/utils/chatml/jumptoplayground.clienttest.ts
index cb7b49d0ee..c24354fd2a 100644
--- a/web/src/utils/chatml/jumptoplayground.clienttest.ts
+++ b/web/src/utils/chatml/jumptoplayground.clienttest.ts
@@ -505,6 +505,31 @@ describe("Playground Jump Full Pipeline", () => {
}
});
+ it("should extract text from Vercel AI SDK content array format", () => {
+ // Vercel AI SDK format: content as array with type/text structure
+ const input = {
+ messages: [
+ {
+ role: "assistant",
+ content: [{ type: "text", text: "Hello world" }],
+ },
+ ],
+ };
+
+ const inResult = normalizeInput(input, {});
+ expect(inResult.success).toBe(true);
+
+ const playgroundMsg = convertChatMlToPlayground(inResult.data![0]);
+
+ // Should extract text, not stringify array
+ expect(
+ playgroundMsg && "content" in playgroundMsg && playgroundMsg.content,
+ ).toBe("Hello world");
+ expect(
+ playgroundMsg && "content" in playgroundMsg && playgroundMsg.content,
+ ).not.toContain("[{");
+ });
+
it("should extract tools from Microsoft Agent Framework metadata", () => {
// Microsoft Agent Framework stores tools in metadata.attributes["gen_ai.tool.definitions"]
const input = [
diff --git a/web/src/utils/chatml/playgroundConverter.ts b/web/src/utils/chatml/playgroundConverter.ts
index 742672d331..190fd40481 100644
--- a/web/src/utils/chatml/playgroundConverter.ts
+++ b/web/src/utils/chatml/playgroundConverter.ts
@@ -1,4 +1,8 @@
import type { ChatMlMessageSchema } from "@/src/components/schemas/ChatMlSchema";
+import {
+ isOpenAITextContentPart,
+ isOpenAIImageContentPart,
+} from "@/src/components/schemas/ChatMlSchema";
import {
ChatMessageRole,
ChatMessageType,
@@ -14,6 +18,33 @@ function contentToString(content: unknown): string {
if (content === null || content === undefined) {
return "";
}
+
+ // Handle OpenAI/Vercel AI SDK content parts array: [{type: "text", text: "..."}, ...]
+ // Extract text for playground display; stringify other structures (tool results, etc.)
+ if (Array.isArray(content)) {
+ const textParts: string[] = [];
+
+ for (const item of content) {
+ if (isOpenAITextContentPart(item)) {
+ textParts.push(item.text);
+ } else if (isOpenAIImageContentPart(item)) {
+ textParts.push("[Image]");
+ } else if (
+ item &&
+ typeof item === "object" &&
+ "type" in item &&
+ item.type === "input_audio"
+ ) {
+ textParts.push("[Audio]");
+ }
+ }
+
+ // If we extracted any text parts, return them joined
+ if (textParts.length > 0) {
+ return textParts.join("\n");
+ }
+ }
+
return JSON.stringify(content);
}