@ai-sdk/openai
Advanced tools
| import { | ||
| createProviderDefinedToolFactoryWithOutputSchema, | ||
| lazySchema, | ||
| zodSchema, | ||
| } from '@ai-sdk/provider-utils'; | ||
| import { z } from 'zod/v4'; | ||
| const safetyCheckSchema = z.object({ | ||
| id: z.string(), | ||
| code: z.string().optional(), | ||
| message: z.string().optional(), | ||
| }); | ||
| const computerActionSchema = z.discriminatedUnion('type', [ | ||
| z.object({ | ||
| type: z.literal('click'), | ||
| button: z.enum(['left', 'right', 'wheel', 'back', 'forward']), | ||
| x: z.number(), | ||
| y: z.number(), | ||
| keys: z.array(z.string()).optional(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('double_click'), | ||
| x: z.number(), | ||
| y: z.number(), | ||
| keys: z.array(z.string()).optional(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('drag'), | ||
| path: z.array(z.object({ x: z.number(), y: z.number() })), | ||
| keys: z.array(z.string()).optional(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('keypress'), | ||
| keys: z.array(z.string()), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('move'), | ||
| x: z.number(), | ||
| y: z.number(), | ||
| keys: z.array(z.string()).optional(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('screenshot'), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('scroll'), | ||
| x: z.number(), | ||
| y: z.number(), | ||
| scrollX: z.number(), | ||
| scrollY: z.number(), | ||
| keys: z.array(z.string()).optional(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('type'), | ||
| text: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('wait'), | ||
| }), | ||
| ]); | ||
| export const computerInputSchema = lazySchema(() => | ||
| zodSchema( | ||
| z.object({ | ||
| actions: z.array(computerActionSchema), | ||
| pendingSafetyChecks: z.array(safetyCheckSchema), | ||
| status: z.enum(['in_progress', 'completed', 'incomplete']), | ||
| }), | ||
| ), | ||
| ); | ||
| export const computerOutputSchema = lazySchema(() => | ||
| zodSchema( | ||
| z.object({ | ||
| output: z.union([ | ||
| z.object({ | ||
| type: z.literal('computer_screenshot'), | ||
| imageUrl: z.string(), | ||
| fileId: z.string().optional(), | ||
| detail: z.enum(['auto', 'low', 'high', 'original']).optional(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('computer_screenshot'), | ||
| fileId: z.string(), | ||
| imageUrl: z.string().optional(), | ||
| detail: z.enum(['auto', 'low', 'high', 'original']).optional(), | ||
| }), | ||
| ]), | ||
| acknowledgedSafetyChecks: z.array(safetyCheckSchema).optional(), | ||
| }), | ||
| ), | ||
| ); | ||
| export type OpenAIComputerAction = z.infer<typeof computerActionSchema>; | ||
| export type OpenAIComputerSafetyCheck = z.infer<typeof safetyCheckSchema>; | ||
| const computerToolFactory = createProviderDefinedToolFactoryWithOutputSchema< | ||
| { | ||
| /** | ||
| * Ordered UI actions to execute. | ||
| */ | ||
| actions: OpenAIComputerAction[]; | ||
| /** | ||
| * Safety checks that must be acknowledged before continuing. | ||
| */ | ||
| pendingSafetyChecks: OpenAIComputerSafetyCheck[]; | ||
| /** | ||
| * Status of the computer call. | ||
| */ | ||
| status: 'in_progress' | 'completed' | 'incomplete'; | ||
| }, | ||
| { | ||
| /** | ||
| * The screenshot captured after executing all actions. | ||
| */ | ||
| output: | ||
| | { | ||
| type: 'computer_screenshot'; | ||
| imageUrl: string; | ||
| fileId?: string; | ||
| detail?: 'auto' | 'low' | 'high' | 'original'; | ||
| } | ||
| | { | ||
| type: 'computer_screenshot'; | ||
| fileId: string; | ||
| imageUrl?: string; | ||
| detail?: 'auto' | 'low' | 'high' | 'original'; | ||
| }; | ||
| /** | ||
| * Safety checks that the application has reviewed and acknowledged. | ||
| */ | ||
| acknowledgedSafetyChecks?: OpenAIComputerSafetyCheck[]; | ||
| }, | ||
| {} | ||
| >({ | ||
| id: 'openai.computer', | ||
| inputSchema: computerInputSchema, | ||
| outputSchema: computerOutputSchema, | ||
| }); | ||
| export const computer = ( | ||
| options: Parameters<typeof computerToolFactory>[0] = {}, | ||
| ) => computerToolFactory(options); |
+285
-24
@@ -5,2 +5,3 @@ import * as _ai_sdk_provider from '@ai-sdk/provider'; | ||
| import { InferSchema, FetchFunction, WebSocketConstructor } from '@ai-sdk/provider-utils'; | ||
| import { z } from 'zod/v4'; | ||
@@ -311,2 +312,94 @@ type OpenAIChatModelId = 'o1' | 'o1-2024-12-17' | 'o3-mini' | 'o3-mini-2025-01-31' | 'o3' | 'o3-2025-04-16' | 'o4-mini' | 'o4-mini-2025-04-16' | 'gpt-4.1' | 'gpt-4.1-2025-04-14' | 'gpt-4.1-mini' | 'gpt-4.1-mini-2025-04-14' | 'gpt-4.1-nano' | 'gpt-4.1-nano-2025-04-14' | 'gpt-4o' | 'gpt-4o-2024-05-13' | 'gpt-4o-2024-08-06' | 'gpt-4o-2024-11-20' | 'gpt-4o-audio-preview' | 'gpt-4o-audio-preview-2024-12-17' | 'gpt-4o-audio-preview-2025-06-03' | 'gpt-4o-mini' | 'gpt-4o-mini-2024-07-18' | 'gpt-4o-mini-audio-preview' | 'gpt-4o-mini-audio-preview-2024-12-17' | 'gpt-4o-search-preview' | 'gpt-4o-search-preview-2025-03-11' | 'gpt-4o-mini-search-preview' | 'gpt-4o-mini-search-preview-2025-03-11' | 'gpt-3.5-turbo-0125' | 'gpt-3.5-turbo' | 'gpt-3.5-turbo-1106' | 'gpt-3.5-turbo-16k' | 'gpt-5' | 'gpt-5-2025-08-07' | 'gpt-5-mini' | 'gpt-5-mini-2025-08-07' | 'gpt-5-nano' | 'gpt-5-nano-2025-08-07' | 'gpt-5-chat-latest' | 'gpt-5.1' | 'gpt-5.1-2025-11-13' | 'gpt-5.1-chat-latest' | 'gpt-5.2' | 'gpt-5.2-2025-12-11' | 'gpt-5.2-chat-latest' | 'gpt-5.2-pro' | 'gpt-5.2-pro-2025-12-11' | 'gpt-5.3-chat-latest' | 'gpt-5.4' | 'gpt-5.4-2026-03-05' | 'gpt-5.4-mini' | 'gpt-5.4-mini-2026-03-17' | 'gpt-5.4-nano' | 'gpt-5.4-nano-2026-03-17' | 'gpt-5.4-pro' | 'gpt-5.4-pro-2026-03-05' | 'gpt-5.5' | 'gpt-5.5-2026-04-23' | 'gpt-5.6' | 'gpt-5.6-luna' | 'gpt-5.6-sol' | 'gpt-5.6-terra' | (string & {}); | ||
| item: { | ||
| type: "computer_call"; | ||
| id: string; | ||
| status: "completed" | "in_progress" | "incomplete"; | ||
| call_id?: string | null | undefined; | ||
| action?: { | ||
| type: "click"; | ||
| button: "left" | "right" | "wheel" | "back" | "forward"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "double_click"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "drag"; | ||
| path: { | ||
| x: number; | ||
| y: number; | ||
| }[]; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "keypress"; | ||
| keys: string[]; | ||
| } | { | ||
| type: "move"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "screenshot"; | ||
| } | { | ||
| type: "scroll"; | ||
| x: number; | ||
| y: number; | ||
| scroll_x: number; | ||
| scroll_y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "type"; | ||
| text: string; | ||
| } | { | ||
| type: "wait"; | ||
| } | null | undefined; | ||
| actions?: ({ | ||
| type: "click"; | ||
| button: "left" | "right" | "wheel" | "back" | "forward"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "double_click"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "drag"; | ||
| path: { | ||
| x: number; | ||
| y: number; | ||
| }[]; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "keypress"; | ||
| keys: string[]; | ||
| } | { | ||
| type: "move"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "screenshot"; | ||
| } | { | ||
| type: "scroll"; | ||
| x: number; | ||
| y: number; | ||
| scroll_x: number; | ||
| scroll_y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "type"; | ||
| text: string; | ||
| } | { | ||
| type: "wait"; | ||
| })[] | null | undefined; | ||
| pending_safety_checks?: { | ||
| id: string; | ||
| code?: string | null | undefined; | ||
| message?: string | null | undefined; | ||
| }[] | null | undefined; | ||
| } | { | ||
| type: "message"; | ||
@@ -331,6 +424,2 @@ id: string; | ||
| } | { | ||
| type: "computer_call"; | ||
| id: string; | ||
| status: string; | ||
| } | { | ||
| type: "file_search_call"; | ||
@@ -434,2 +523,94 @@ id: string; | ||
| item: { | ||
| type: "computer_call"; | ||
| id: string; | ||
| status: "completed" | "in_progress" | "incomplete"; | ||
| call_id?: string | null | undefined; | ||
| action?: { | ||
| type: "click"; | ||
| button: "left" | "right" | "wheel" | "back" | "forward"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "double_click"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "drag"; | ||
| path: { | ||
| x: number; | ||
| y: number; | ||
| }[]; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "keypress"; | ||
| keys: string[]; | ||
| } | { | ||
| type: "move"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "screenshot"; | ||
| } | { | ||
| type: "scroll"; | ||
| x: number; | ||
| y: number; | ||
| scroll_x: number; | ||
| scroll_y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "type"; | ||
| text: string; | ||
| } | { | ||
| type: "wait"; | ||
| } | null | undefined; | ||
| actions?: ({ | ||
| type: "click"; | ||
| button: "left" | "right" | "wheel" | "back" | "forward"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "double_click"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "drag"; | ||
| path: { | ||
| x: number; | ||
| y: number; | ||
| }[]; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "keypress"; | ||
| keys: string[]; | ||
| } | { | ||
| type: "move"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "screenshot"; | ||
| } | { | ||
| type: "scroll"; | ||
| x: number; | ||
| y: number; | ||
| scroll_x: number; | ||
| scroll_y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "type"; | ||
| text: string; | ||
| } | { | ||
| type: "wait"; | ||
| })[] | null | undefined; | ||
| pending_safety_checks?: { | ||
| id: string; | ||
| code?: string | null | undefined; | ||
| message?: string | null | undefined; | ||
| }[] | null | undefined; | ||
| } | { | ||
| type: "message"; | ||
@@ -520,6 +701,2 @@ id: string; | ||
| } | { | ||
| type: "computer_call"; | ||
| id: string; | ||
| status: "completed"; | ||
| } | { | ||
| type: "mcp_call"; | ||
@@ -798,2 +975,45 @@ id: string; | ||
| /** | ||
| * The computer tool allows models to operate a browser or desktop through | ||
| * batched UI actions. Your application executes the actions and returns an | ||
| * updated screenshot. | ||
| * | ||
| * WARNING: Run computer use in an isolated environment, treat on-screen | ||
| * content as untrusted, and require confirmation for consequential actions. | ||
| */ | ||
| computer: (options?: Parameters<_ai_sdk_provider_utils.ProviderDefinedToolFactoryWithOutputSchema<{ | ||
| actions: OpenAIComputerAction[]; | ||
| pendingSafetyChecks: OpenAIComputerSafetyCheck[]; | ||
| status: "in_progress" | "completed" | "incomplete"; | ||
| }, { | ||
| output: { | ||
| type: "computer_screenshot"; | ||
| imageUrl: string; | ||
| fileId?: string; | ||
| detail?: "auto" | "low" | "high" | "original"; | ||
| } | { | ||
| type: "computer_screenshot"; | ||
| fileId: string; | ||
| imageUrl?: string; | ||
| detail?: "auto" | "low" | "high" | "original"; | ||
| }; | ||
| acknowledgedSafetyChecks?: OpenAIComputerSafetyCheck[]; | ||
| }, {}, {}>>[0]) => _ai_sdk_provider_utils.ProviderDefinedTool<{ | ||
| actions: OpenAIComputerAction[]; | ||
| pendingSafetyChecks: OpenAIComputerSafetyCheck[]; | ||
| status: "in_progress" | "completed" | "incomplete"; | ||
| }, { | ||
| output: { | ||
| type: "computer_screenshot"; | ||
| imageUrl: string; | ||
| fileId?: string; | ||
| detail?: "auto" | "low" | "high" | "original"; | ||
| } | { | ||
| type: "computer_screenshot"; | ||
| fileId: string; | ||
| imageUrl?: string; | ||
| detail?: "auto" | "low" | "high" | "original"; | ||
| }; | ||
| acknowledgedSafetyChecks?: OpenAIComputerSafetyCheck[]; | ||
| }, {}>; | ||
| /** | ||
| * File search is a tool available in the Responses API. It enables models to | ||
@@ -940,17 +1160,3 @@ * retrieve information in a knowledge base of previously uploaded files through | ||
| type?: "local"; | ||
| skills | ||
| /** | ||
| * Web search allows models to access up-to-date information from the internet | ||
| * and provide answers with sourced citations. | ||
| * | ||
| * @param searchContextSize - The search context size to use for the web search. | ||
| * @param userLocation - The user location to use for the web search. | ||
| */ | ||
| ? /** | ||
| * Web search allows models to access up-to-date information from the internet | ||
| * and provide answers with sourced citations. | ||
| * | ||
| * @param searchContextSize - The search context size to use for the web search. | ||
| * @param userLocation - The user location to use for the web search. | ||
| */: Array<{ | ||
| skills?: Array<{ | ||
| name: string; | ||
@@ -1289,2 +1495,57 @@ description: string; | ||
| declare const safetyCheckSchema: z.ZodObject<{ | ||
| id: z.ZodString; | ||
| code: z.ZodOptional<z.ZodString>; | ||
| message: z.ZodOptional<z.ZodString>; | ||
| }, z.core.$strip>; | ||
| declare const computerActionSchema: z.ZodDiscriminatedUnion<[z.ZodObject<{ | ||
| type: z.ZodLiteral<"click">; | ||
| button: z.ZodEnum<{ | ||
| left: "left"; | ||
| right: "right"; | ||
| wheel: "wheel"; | ||
| back: "back"; | ||
| forward: "forward"; | ||
| }>; | ||
| x: z.ZodNumber; | ||
| y: z.ZodNumber; | ||
| keys: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"double_click">; | ||
| x: z.ZodNumber; | ||
| y: z.ZodNumber; | ||
| keys: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"drag">; | ||
| path: z.ZodArray<z.ZodObject<{ | ||
| x: z.ZodNumber; | ||
| y: z.ZodNumber; | ||
| }, z.core.$strip>>; | ||
| keys: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"keypress">; | ||
| keys: z.ZodArray<z.ZodString>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"move">; | ||
| x: z.ZodNumber; | ||
| y: z.ZodNumber; | ||
| keys: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"screenshot">; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"scroll">; | ||
| x: z.ZodNumber; | ||
| y: z.ZodNumber; | ||
| scrollX: z.ZodNumber; | ||
| scrollY: z.ZodNumber; | ||
| keys: z.ZodOptional<z.ZodArray<z.ZodString>>; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"type">; | ||
| text: z.ZodString; | ||
| }, z.core.$strip>, z.ZodObject<{ | ||
| type: z.ZodLiteral<"wait">; | ||
| }, z.core.$strip>]>; | ||
| type OpenAIComputerAction = z.infer<typeof computerActionSchema>; | ||
| type OpenAIComputerSafetyCheck = z.infer<typeof safetyCheckSchema>; | ||
| type OpenaiResponsesChunk = InferSchema<typeof openaiResponsesChunkSchema>; | ||
@@ -1345,2 +1606,2 @@ type ResponsesOutputTextAnnotationProviderMetadata = Extract<OpenaiResponsesChunk, { | ||
| export { OpenAIRealtimeModel as Experimental_OpenAIRealtimeModel, type OpenAIRealtimeModelConfig as Experimental_OpenAIRealtimeModelConfig, type OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions, type OpenAIEmbeddingModelOptions, type OpenAIFilesOptions, type OpenAIImageModelEditOptions, type OpenAIImageModelGenerationOptions, type OpenAIImageModelOptions, type OpenAILanguageModelChatOptions, type OpenAILanguageModelCompletionOptions, type OpenAILanguageModelResponsesOptions, type OpenAIProvider, type OpenAIProviderSettings, type OpenAILanguageModelResponsesOptions as OpenAIResponsesProviderOptions, type OpenAISpeechModelOptions, type OpenAITranscriptionModelOptions, type OpenaiResponsesCompactionProviderMetadata, type OpenaiResponsesProviderMetadata, type OpenaiResponsesReasoningProviderMetadata, type OpenaiResponsesSourceDocumentProviderMetadata, type OpenaiResponsesTextProviderMetadata, VERSION, createOpenAI, openai }; | ||
| export { OpenAIRealtimeModel as Experimental_OpenAIRealtimeModel, type OpenAIRealtimeModelConfig as Experimental_OpenAIRealtimeModelConfig, type OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions, type OpenAIComputerAction, type OpenAIComputerSafetyCheck, type OpenAIEmbeddingModelOptions, type OpenAIFilesOptions, type OpenAIImageModelEditOptions, type OpenAIImageModelGenerationOptions, type OpenAIImageModelOptions, type OpenAILanguageModelChatOptions, type OpenAILanguageModelCompletionOptions, type OpenAILanguageModelResponsesOptions, type OpenAIProvider, type OpenAIProviderSettings, type OpenAILanguageModelResponsesOptions as OpenAIResponsesProviderOptions, type OpenAISpeechModelOptions, type OpenAITranscriptionModelOptions, type OpenaiResponsesCompactionProviderMetadata, type OpenaiResponsesProviderMetadata, type OpenaiResponsesReasoningProviderMetadata, type OpenaiResponsesSourceDocumentProviderMetadata, type OpenaiResponsesTextProviderMetadata, VERSION, createOpenAI, openai }; |
+184
-8
@@ -431,2 +431,94 @@ import * as _ai_sdk_provider from '@ai-sdk/provider'; | ||
| item: { | ||
| type: "computer_call"; | ||
| id: string; | ||
| status: "completed" | "in_progress" | "incomplete"; | ||
| call_id?: string | null | undefined; | ||
| action?: { | ||
| type: "click"; | ||
| button: "left" | "right" | "wheel" | "back" | "forward"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "double_click"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "drag"; | ||
| path: { | ||
| x: number; | ||
| y: number; | ||
| }[]; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "keypress"; | ||
| keys: string[]; | ||
| } | { | ||
| type: "move"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "screenshot"; | ||
| } | { | ||
| type: "scroll"; | ||
| x: number; | ||
| y: number; | ||
| scroll_x: number; | ||
| scroll_y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "type"; | ||
| text: string; | ||
| } | { | ||
| type: "wait"; | ||
| } | null | undefined; | ||
| actions?: ({ | ||
| type: "click"; | ||
| button: "left" | "right" | "wheel" | "back" | "forward"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "double_click"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "drag"; | ||
| path: { | ||
| x: number; | ||
| y: number; | ||
| }[]; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "keypress"; | ||
| keys: string[]; | ||
| } | { | ||
| type: "move"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "screenshot"; | ||
| } | { | ||
| type: "scroll"; | ||
| x: number; | ||
| y: number; | ||
| scroll_x: number; | ||
| scroll_y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "type"; | ||
| text: string; | ||
| } | { | ||
| type: "wait"; | ||
| })[] | null | undefined; | ||
| pending_safety_checks?: { | ||
| id: string; | ||
| code?: string | null | undefined; | ||
| message?: string | null | undefined; | ||
| }[] | null | undefined; | ||
| } | { | ||
| type: "message"; | ||
@@ -451,6 +543,2 @@ id: string; | ||
| } | { | ||
| type: "computer_call"; | ||
| id: string; | ||
| status: string; | ||
| } | { | ||
| type: "file_search_call"; | ||
@@ -554,2 +642,94 @@ id: string; | ||
| item: { | ||
| type: "computer_call"; | ||
| id: string; | ||
| status: "completed" | "in_progress" | "incomplete"; | ||
| call_id?: string | null | undefined; | ||
| action?: { | ||
| type: "click"; | ||
| button: "left" | "right" | "wheel" | "back" | "forward"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "double_click"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "drag"; | ||
| path: { | ||
| x: number; | ||
| y: number; | ||
| }[]; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "keypress"; | ||
| keys: string[]; | ||
| } | { | ||
| type: "move"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "screenshot"; | ||
| } | { | ||
| type: "scroll"; | ||
| x: number; | ||
| y: number; | ||
| scroll_x: number; | ||
| scroll_y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "type"; | ||
| text: string; | ||
| } | { | ||
| type: "wait"; | ||
| } | null | undefined; | ||
| actions?: ({ | ||
| type: "click"; | ||
| button: "left" | "right" | "wheel" | "back" | "forward"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "double_click"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "drag"; | ||
| path: { | ||
| x: number; | ||
| y: number; | ||
| }[]; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "keypress"; | ||
| keys: string[]; | ||
| } | { | ||
| type: "move"; | ||
| x: number; | ||
| y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "screenshot"; | ||
| } | { | ||
| type: "scroll"; | ||
| x: number; | ||
| y: number; | ||
| scroll_x: number; | ||
| scroll_y: number; | ||
| keys?: string[] | null | undefined; | ||
| } | { | ||
| type: "type"; | ||
| text: string; | ||
| } | { | ||
| type: "wait"; | ||
| })[] | null | undefined; | ||
| pending_safety_checks?: { | ||
| id: string; | ||
| code?: string | null | undefined; | ||
| message?: string | null | undefined; | ||
| }[] | null | undefined; | ||
| } | { | ||
| type: "message"; | ||
@@ -640,6 +820,2 @@ id: string; | ||
| } | { | ||
| type: "computer_call"; | ||
| id: string; | ||
| status: "completed"; | ||
| } | { | ||
| type: "mcp_call"; | ||
@@ -646,0 +822,0 @@ id: string; |
+1
-1
| { | ||
| "name": "@ai-sdk/openai", | ||
| "version": "4.0.14", | ||
| "version": "4.0.15", | ||
| "type": "module", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
+4
-0
@@ -26,2 +26,6 @@ export { createOpenAI, openai } from './openai-provider'; | ||
| export type { | ||
| OpenAIComputerAction, | ||
| OpenAIComputerSafetyCheck, | ||
| } from './tool/computer'; | ||
| export type { | ||
| OpenaiResponsesCompactionProviderMetadata, | ||
@@ -28,0 +32,0 @@ OpenaiResponsesProviderMetadata, |
+11
-0
| import { applyPatch } from './tool/apply-patch'; | ||
| import { codeInterpreter } from './tool/code-interpreter'; | ||
| import { computer } from './tool/computer'; | ||
| import { customTool } from './tool/custom'; | ||
@@ -43,2 +44,12 @@ import { fileSearch } from './tool/file-search'; | ||
| /** | ||
| * The computer tool allows models to operate a browser or desktop through | ||
| * batched UI actions. Your application executes the actions and returns an | ||
| * updated screenshot. | ||
| * | ||
| * WARNING: Run computer use in an isolated environment, treat on-screen | ||
| * content as untrusted, and require confirmation for consequential actions. | ||
| */ | ||
| computer, | ||
| /** | ||
| * File search is a tool available in the Responses API. It enables models to | ||
@@ -45,0 +56,0 @@ * retrieve information in a knowledge base of previously uploaded files through |
@@ -24,2 +24,3 @@ import { | ||
| } from '../tool/apply-patch'; | ||
| import { computerInputSchema, computerOutputSchema } from '../tool/computer'; | ||
| import { | ||
@@ -81,2 +82,3 @@ localShellInputSchema, | ||
| hasApplyPatchTool = false, | ||
| hasComputerTool = false, | ||
| customProviderToolNames, | ||
@@ -97,2 +99,3 @@ }: { | ||
| hasApplyPatchTool?: boolean; | ||
| hasComputerTool?: boolean; | ||
| customProviderToolNames?: Set<string>; | ||
@@ -407,3 +410,3 @@ }): Promise<{ | ||
| // Provider-defined tool calls (local_shell, shell, apply_patch, | ||
| // and custom tools) are stored by the API and can be sent as an | ||
| // computer, and custom tools) are stored by the API and can be sent as an | ||
| // `item_reference` to reduce payload size. Plain client-executed | ||
@@ -421,2 +424,3 @@ // function calls must NOT be: the matching `function_call_output` | ||
| (hasApplyPatchTool && resolvedToolName === 'apply_patch') || | ||
| (hasComputerTool && resolvedToolName === 'computer') || | ||
| (customProviderToolNames?.has(resolvedToolName) ?? false); | ||
@@ -487,2 +491,51 @@ | ||
| if (hasComputerTool && resolvedToolName === 'computer') { | ||
| const parsedInput = await validateTypes({ | ||
| value: part.input, | ||
| schema: computerInputSchema, | ||
| }); | ||
| input.push({ | ||
| type: 'computer_call', | ||
| call_id: part.toolCallId, | ||
| id: id!, | ||
| status: parsedInput.status, | ||
| actions: parsedInput.actions.map(action => { | ||
| switch (action.type) { | ||
| case 'click': | ||
| case 'double_click': | ||
| case 'move': | ||
| return { | ||
| ...action, | ||
| keys: action.keys, | ||
| }; | ||
| case 'drag': | ||
| return { | ||
| ...action, | ||
| keys: action.keys, | ||
| }; | ||
| case 'scroll': | ||
| return { | ||
| type: 'scroll' as const, | ||
| x: action.x, | ||
| y: action.y, | ||
| scroll_x: action.scrollX, | ||
| scroll_y: action.scrollY, | ||
| keys: action.keys, | ||
| }; | ||
| default: | ||
| return action; | ||
| } | ||
| }), | ||
| pending_safety_checks: parsedInput.pendingSafetyChecks.map( | ||
| safetyCheck => ({ | ||
| id: safetyCheck.id, | ||
| code: safetyCheck.code, | ||
| message: safetyCheck.message, | ||
| }), | ||
| ), | ||
| }); | ||
| break; | ||
| } | ||
| if (customProviderToolNames?.has(resolvedToolName)) { | ||
@@ -878,2 +931,31 @@ input.push({ | ||
| if ( | ||
| hasComputerTool && | ||
| resolvedToolName === 'computer' && | ||
| output.type === 'json' | ||
| ) { | ||
| const parsedOutput = await validateTypes({ | ||
| value: output.value, | ||
| schema: computerOutputSchema, | ||
| }); | ||
| input.push({ | ||
| type: 'computer_call_output', | ||
| call_id: part.toolCallId, | ||
| output: { | ||
| type: 'computer_screenshot', | ||
| image_url: parsedOutput.output.imageUrl, | ||
| file_id: parsedOutput.output.fileId, | ||
| detail: parsedOutput.output.detail, | ||
| }, | ||
| acknowledged_safety_checks: | ||
| parsedOutput.acknowledgedSafetyChecks?.map(safetyCheck => ({ | ||
| id: safetyCheck.id, | ||
| code: safetyCheck.code, | ||
| message: safetyCheck.message, | ||
| })), | ||
| }); | ||
| continue; | ||
| } | ||
| if (customProviderToolNames?.has(resolvedToolName)) { | ||
@@ -880,0 +962,0 @@ let outputValue: OpenAIResponsesCustomToolCallOutput['output']; |
@@ -20,2 +20,69 @@ import type { JSONObject, JSONSchema7, JSONValue } from '@ai-sdk/provider'; | ||
| const openaiResponsesComputerSafetyCheckSchema = z.object({ | ||
| id: z.string(), | ||
| code: z.string().nullish(), | ||
| message: z.string().nullish(), | ||
| }); | ||
| const openaiResponsesComputerActionSchema = z.discriminatedUnion('type', [ | ||
| z.object({ | ||
| type: z.literal('click'), | ||
| button: z.enum(['left', 'right', 'wheel', 'back', 'forward']), | ||
| x: z.number(), | ||
| y: z.number(), | ||
| keys: z.array(z.string()).nullish(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('double_click'), | ||
| x: z.number(), | ||
| y: z.number(), | ||
| keys: z.array(z.string()).nullish(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('drag'), | ||
| path: z.array(z.object({ x: z.number(), y: z.number() })), | ||
| keys: z.array(z.string()).nullish(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('keypress'), | ||
| keys: z.array(z.string()), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('move'), | ||
| x: z.number(), | ||
| y: z.number(), | ||
| keys: z.array(z.string()).nullish(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('screenshot'), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('scroll'), | ||
| x: z.number(), | ||
| y: z.number(), | ||
| scroll_x: z.number(), | ||
| scroll_y: z.number(), | ||
| keys: z.array(z.string()).nullish(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('type'), | ||
| text: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('wait'), | ||
| }), | ||
| ]); | ||
| const openaiResponsesComputerCallSchema = z.object({ | ||
| type: z.literal('computer_call'), | ||
| id: z.string(), | ||
| call_id: z.string().nullish(), | ||
| status: z.enum(['in_progress', 'completed', 'incomplete']), | ||
| action: openaiResponsesComputerActionSchema.nullish(), | ||
| actions: z.array(openaiResponsesComputerActionSchema).nullish(), | ||
| pending_safety_checks: z | ||
| .array(openaiResponsesComputerSafetyCheckSchema) | ||
| .nullish(), | ||
| }); | ||
| export type OpenAIResponsesInput = Array<OpenAIResponsesInputItem>; | ||
@@ -33,2 +100,3 @@ | ||
| | OpenAIResponsesComputerCall | ||
| | OpenAIResponsesComputerCallOutput | ||
| | OpenAIResponsesLocalShellCall | ||
@@ -190,6 +258,24 @@ | OpenAIResponsesLocalShellCallOutput | ||
| export type OpenAIResponsesComputerCall = { | ||
| type: 'computer_call'; | ||
| id: string; | ||
| status?: string; | ||
| export type OpenAIResponsesComputerAction = InferSchema< | ||
| typeof openaiResponsesComputerActionSchema | ||
| >; | ||
| export type OpenAIResponsesComputerCall = InferSchema< | ||
| typeof openaiResponsesComputerCallSchema | ||
| >; | ||
| export type OpenAIResponsesComputerCallOutput = { | ||
| type: 'computer_call_output'; | ||
| call_id: string; | ||
| output: { | ||
| type: 'computer_screenshot'; | ||
| image_url?: string; | ||
| file_id?: string; | ||
| detail?: 'auto' | 'low' | 'high' | 'original'; | ||
| }; | ||
| acknowledged_safety_checks?: Array<{ | ||
| id: string; | ||
| code?: string; | ||
| message?: string; | ||
| }>; | ||
| }; | ||
@@ -362,2 +448,5 @@ | ||
| | { | ||
| type: 'computer'; | ||
| } | ||
| | { | ||
| type: 'web_search'; | ||
@@ -685,8 +774,4 @@ external_web_access: boolean | undefined; | ||
| }), | ||
| openaiResponsesComputerCallSchema, | ||
| z.object({ | ||
| type: z.literal('computer_call'), | ||
| id: z.string(), | ||
| status: z.string(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('file_search_call'), | ||
@@ -921,8 +1006,4 @@ id: z.string(), | ||
| }), | ||
| openaiResponsesComputerCallSchema, | ||
| z.object({ | ||
| type: z.literal('computer_call'), | ||
| id: z.string(), | ||
| status: z.literal('completed'), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('mcp_call'), | ||
@@ -1349,8 +1430,4 @@ id: z.string(), | ||
| }), | ||
| openaiResponsesComputerCallSchema, | ||
| z.object({ | ||
| type: z.literal('computer_call'), | ||
| id: z.string(), | ||
| status: z.string().optional(), | ||
| }), | ||
| z.object({ | ||
| type: z.literal('reasoning'), | ||
@@ -1357,0 +1434,0 @@ id: z.string(), |
@@ -65,2 +65,3 @@ import { | ||
| | { type: 'apply_patch' } | ||
| | { type: 'computer' } | ||
| | { | ||
@@ -175,2 +176,8 @@ type: 'allowed_tools'; | ||
| } | ||
| case 'openai.computer': { | ||
| openaiTools.push({ | ||
| type: 'computer', | ||
| }); | ||
| break; | ||
| } | ||
| case 'openai.web_search_preview': { | ||
@@ -379,3 +386,4 @@ const args = await validateTypes({ | ||
| resolvedToolName === 'mcp' || | ||
| resolvedToolName === 'apply_patch' | ||
| resolvedToolName === 'apply_patch' || | ||
| resolvedToolName === 'computer' | ||
| ? { type: resolvedToolName } | ||
@@ -382,0 +390,0 @@ : resolvedCustomProviderToolNames.has(resolvedToolName) |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
2584964
3.73%79
1.28%32870
4.94%