diff --git a/packages/ai/src/schema/messages.ts b/packages/ai/src/schema/messages.ts index 9fae163370e..103b018ad2a 100644 --- a/packages/ai/src/schema/messages.ts +++ b/packages/ai/src/schema/messages.ts @@ -45,35 +45,34 @@ const isToolResultValue = (value: unknown): value is ToolResultValue => (value.type === "text" || value.type === "json" || value.type === "error" || value.type === "content") && "value" in value -export const ToolResultValue = Object.assign( - Schema.Union([ - Schema.Struct({ - type: Schema.Literal("json"), - value: Schema.Unknown, - }), - Schema.Struct({ - type: Schema.Literal("text"), - value: Schema.Unknown, - }), - Schema.Struct({ - type: Schema.Literal("error"), - value: Schema.Unknown, - }), - Schema.Struct({ - type: Schema.Literal("content"), - value: Schema.Array(Tool.Content), - }), - ]).annotate({ identifier: "LLM.ToolResult" }), - { - is: isToolResultValue, - make: (value: unknown, type: ToolResultValue["type"] = "json"): ToolResultValue => { - if (isToolResultValue(value)) return value - if (type === "content") return { type, value: Array.isArray(value) ? value : [] } - return { type, value } - }, +const toolResultValueSchema = Schema.Union([ + Schema.Struct({ + type: Schema.Literal("json"), + value: Schema.Unknown, + }), + Schema.Struct({ + type: Schema.Literal("text"), + value: Schema.Unknown, + }), + Schema.Struct({ + type: Schema.Literal("error"), + value: Schema.Unknown, + }), + Schema.Struct({ + type: Schema.Literal("content"), + value: Schema.Array(Tool.Content), + }), +]).annotate({ identifier: "LLM.ToolResult" }) +export type ToolResultValue = Schema.Schema.Type + +export const ToolResultValue = Object.assign(toolResultValueSchema, { + is: isToolResultValue, + make: (value: unknown, type: ToolResultValue["type"] = "json"): ToolResultValue => { + if (isToolResultValue(value)) return value + if (type === "content") return { type, value: Array.isArray(value) ? value : [] } + return { type, value } }, -) -export type ToolResultValue = Schema.Schema.Type +}) export interface ToolOutput { readonly structured: unknown