extended type for "audio" update to spec
This commit is contained in:
@@ -7,13 +7,41 @@ import { Textarea } from "@/components/ui/textarea";
|
||||
import {
|
||||
ListToolsResult,
|
||||
Tool,
|
||||
CallToolResultSchema,
|
||||
TextContentSchema,
|
||||
ImageContentSchema,
|
||||
ResultSchema,
|
||||
EmbeddedResourceSchema,
|
||||
} from "@modelcontextprotocol/sdk/types.js";
|
||||
import { AlertCircle, Send } from "lucide-react";
|
||||
import { useState } from "react";
|
||||
import ListPane from "./ListPane";
|
||||
|
||||
import { CompatibilityCallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
||||
import { z } from "zod";
|
||||
|
||||
// Define the AudioContent schema
|
||||
export const AudioContentSchema = z.object({
|
||||
type: z.literal("audio"),
|
||||
data: z.string().base64(),
|
||||
mimeType: z.string(),
|
||||
}).passthrough();
|
||||
|
||||
// Extend the CallToolResult schema to include audio content
|
||||
export const ExtendedCallToolResultSchema = ResultSchema.extend({
|
||||
content: z.array(
|
||||
z.discriminatedUnion("type", [
|
||||
TextContentSchema,
|
||||
ImageContentSchema,
|
||||
AudioContentSchema,
|
||||
EmbeddedResourceSchema,
|
||||
])
|
||||
),
|
||||
isError: z.boolean().default(false).optional(),
|
||||
});
|
||||
|
||||
// Export the types
|
||||
export type AudioContent = z.infer<typeof AudioContentSchema>;
|
||||
export type ExtendedCallToolResult = z.infer<typeof ExtendedCallToolResultSchema>;
|
||||
|
||||
const ToolsTab = ({
|
||||
tools,
|
||||
@@ -40,7 +68,7 @@ const ToolsTab = ({
|
||||
if (!toolResult) return null;
|
||||
|
||||
if ("content" in toolResult) {
|
||||
const parsedResult = CallToolResultSchema.safeParse(toolResult);
|
||||
const parsedResult = ExtendedCallToolResultSchema.safeParse(toolResult);
|
||||
if (!parsedResult.success) {
|
||||
return (
|
||||
<>
|
||||
@@ -82,6 +110,15 @@ const ToolsTab = ({
|
||||
className="max-w-full h-auto"
|
||||
/>
|
||||
)}
|
||||
{item.type === "audio" && (
|
||||
<audio
|
||||
controls
|
||||
src={`data:${item.mimeType};base64,${item.data}`}
|
||||
className="w-full"
|
||||
>
|
||||
<p>Your browser does not support audio playback</p>
|
||||
</audio>
|
||||
)}
|
||||
{item.type === "resource" && (
|
||||
item.resource?.mimeType?.startsWith("audio/") ? (
|
||||
<audio
|
||||
|
||||
Reference in New Issue
Block a user