@ai-sdk/openai 4.0.0-beta.2 → 4.0.0-beta.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +234 -22
  2. package/README.md +2 -0
  3. package/dist/index.d.mts +134 -35
  4. package/dist/index.d.ts +134 -35
  5. package/dist/index.js +1700 -1139
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +1697 -1117
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/internal/index.d.mts +107 -41
  10. package/dist/internal/index.d.ts +107 -41
  11. package/dist/internal/index.js +1380 -939
  12. package/dist/internal/index.js.map +1 -1
  13. package/dist/internal/index.mjs +1371 -917
  14. package/dist/internal/index.mjs.map +1 -1
  15. package/docs/03-openai.mdx +274 -9
  16. package/package.json +3 -5
  17. package/src/chat/convert-openai-chat-usage.ts +2 -2
  18. package/src/chat/convert-to-openai-chat-messages.ts +26 -15
  19. package/src/chat/map-openai-finish-reason.ts +2 -2
  20. package/src/chat/openai-chat-language-model.ts +32 -24
  21. package/src/chat/openai-chat-options.ts +5 -0
  22. package/src/chat/openai-chat-prepare-tools.ts +6 -6
  23. package/src/completion/convert-openai-completion-usage.ts +2 -2
  24. package/src/completion/convert-to-openai-completion-prompt.ts +2 -2
  25. package/src/completion/map-openai-finish-reason.ts +2 -2
  26. package/src/completion/openai-completion-language-model.ts +20 -20
  27. package/src/embedding/openai-embedding-model.ts +5 -5
  28. package/src/files/openai-files-api.ts +17 -0
  29. package/src/files/openai-files-options.ts +18 -0
  30. package/src/files/openai-files.ts +102 -0
  31. package/src/image/openai-image-model.ts +9 -9
  32. package/src/index.ts +2 -0
  33. package/src/openai-config.ts +5 -5
  34. package/src/openai-language-model-capabilities.ts +3 -2
  35. package/src/openai-provider.ts +39 -21
  36. package/src/openai-tools.ts +12 -1
  37. package/src/responses/convert-openai-responses-usage.ts +2 -2
  38. package/src/responses/convert-to-openai-responses-input.ts +188 -14
  39. package/src/responses/map-openai-responses-finish-reason.ts +2 -2
  40. package/src/responses/openai-responses-api.ts +136 -2
  41. package/src/responses/openai-responses-language-model.ts +233 -37
  42. package/src/responses/openai-responses-options.ts +24 -2
  43. package/src/responses/openai-responses-prepare-tools.ts +34 -9
  44. package/src/responses/openai-responses-provider-metadata.ts +10 -0
  45. package/src/speech/openai-speech-model.ts +7 -7
  46. package/src/tool/custom.ts +0 -6
  47. package/src/tool/tool-search.ts +98 -0
  48. package/src/transcription/openai-transcription-model.ts +8 -8
@@ -8,7 +8,6 @@ import { z } from 'zod/v4';
8
8
  export const customArgsSchema = lazySchema(() =>
9
9
  zodSchema(
10
10
  z.object({
11
- name: z.string(),
12
11
  description: z.string().optional(),
13
12
  format: z
14
13
  .union([
@@ -31,11 +30,6 @@ const customInputSchema = lazySchema(() => zodSchema(z.string()));
31
30
  export const customToolFactory = createProviderToolFactory<
32
31
  string,
33
32
  {
34
- /**
35
- * The name of the custom tool, used to identify it in the API.
36
- */
37
- name: string;
38
-
39
33
  /**
40
34
  * An optional description of what the tool does.
41
35
  */
@@ -0,0 +1,98 @@
1
+ import { JSONObject } from '@ai-sdk/provider';
2
+ import {
3
+ createProviderToolFactoryWithOutputSchema,
4
+ FlexibleSchema,
5
+ lazySchema,
6
+ zodSchema,
7
+ } from '@ai-sdk/provider-utils';
8
+ import { z } from 'zod/v4';
9
+
10
+ export const toolSearchArgsSchema = lazySchema(() =>
11
+ zodSchema(
12
+ z.object({
13
+ execution: z.enum(['server', 'client']).optional(),
14
+ description: z.string().optional(),
15
+ parameters: z.record(z.string(), z.unknown()).optional(),
16
+ }),
17
+ ),
18
+ );
19
+
20
+ export const toolSearchInputSchema = lazySchema(() =>
21
+ zodSchema(
22
+ z.object({
23
+ arguments: z.unknown().optional(),
24
+ call_id: z.string().nullish(),
25
+ }),
26
+ ),
27
+ );
28
+
29
+ export const toolSearchOutputSchema: FlexibleSchema<{
30
+ tools: Array<JSONObject>;
31
+ }> = lazySchema(() =>
32
+ zodSchema(
33
+ z.object({
34
+ tools: z.array(z.record(z.string(), z.unknown())),
35
+ }),
36
+ ),
37
+ ) as FlexibleSchema<{ tools: Array<JSONObject> }>;
38
+
39
+ const toolSearchToolFactory = createProviderToolFactoryWithOutputSchema<
40
+ {
41
+ /**
42
+ * The arguments from the tool_search_call.
43
+ * This is preserved for multi-turn conversation reconstruction.
44
+ */
45
+ arguments?: unknown;
46
+
47
+ /**
48
+ * The call ID from the tool_search_call.
49
+ * Present for client-executed tool search; null for hosted.
50
+ */
51
+ call_id?: string | null;
52
+ },
53
+ {
54
+ /**
55
+ * The tools that were loaded by the tool search.
56
+ * These are the deferred tools that the model requested to load.
57
+ * Each tool is represented as a JSON object with properties depending on its type.
58
+ *
59
+ * Common properties include:
60
+ * - `type`: The type of the tool (e.g., 'function', 'web_search', etc.)
61
+ * - `name`: The name of the tool (for function tools)
62
+ * - `description`: A description of the tool
63
+ * - `deferLoading`: Whether this tool was deferred (had defer_loading: true)
64
+ * - `parameters`: The JSON Schema for the function parameters (for function tools)
65
+ * - `strict`: Whether to enable strict schema adherence (for function tools)
66
+ */
67
+ tools: Array<JSONObject>;
68
+ },
69
+ {
70
+ /**
71
+ * Whether the tool search is executed by the server (hosted) or client.
72
+ * - `'server'` (default): OpenAI performs the search across deferred tools.
73
+ * - `'client'`: The model emits a `tool_search_call` and your `execute`
74
+ * function performs the lookup, returning the tools to load.
75
+ */
76
+ execution?: 'server' | 'client';
77
+
78
+ /**
79
+ * A description of the tool search capability.
80
+ * Only used for client-executed tool search.
81
+ */
82
+ description?: string;
83
+
84
+ /**
85
+ * JSON Schema for the search arguments your application expects.
86
+ * Only used for client-executed tool search.
87
+ */
88
+ parameters?: Record<string, unknown>;
89
+ }
90
+ >({
91
+ id: 'openai.tool_search',
92
+ inputSchema: toolSearchInputSchema,
93
+ outputSchema: toolSearchOutputSchema,
94
+ });
95
+
96
+ export const toolSearch = (
97
+ args: Parameters<typeof toolSearchToolFactory>[0] = {},
98
+ ) => toolSearchToolFactory(args);
@@ -1,7 +1,7 @@
1
1
  import {
2
- TranscriptionModelV3,
3
- TranscriptionModelV3CallOptions,
4
- SharedV3Warning,
2
+ TranscriptionModelV4,
3
+ TranscriptionModelV4CallOptions,
4
+ SharedV4Warning,
5
5
  } from '@ai-sdk/provider';
6
6
  import {
7
7
  combineHeaders,
@@ -21,7 +21,7 @@ import {
21
21
  } from './openai-transcription-options';
22
22
 
23
23
  export type OpenAITranscriptionCallOptions = Omit<
24
- TranscriptionModelV3CallOptions,
24
+ TranscriptionModelV4CallOptions,
25
25
  'providerOptions'
26
26
  > & {
27
27
  providerOptions?: {
@@ -96,8 +96,8 @@ const languageMap = {
96
96
  welsh: 'cy',
97
97
  };
98
98
 
99
- export class OpenAITranscriptionModel implements TranscriptionModelV3 {
100
- readonly specificationVersion = 'v3';
99
+ export class OpenAITranscriptionModel implements TranscriptionModelV4 {
100
+ readonly specificationVersion = 'v4';
101
101
 
102
102
  get provider(): string {
103
103
  return this.config.provider;
@@ -113,7 +113,7 @@ export class OpenAITranscriptionModel implements TranscriptionModelV3 {
113
113
  mediaType,
114
114
  providerOptions,
115
115
  }: OpenAITranscriptionCallOptions) {
116
- const warnings: SharedV3Warning[] = [];
116
+ const warnings: SharedV4Warning[] = [];
117
117
 
118
118
  // Parse provider options
119
119
  const openAIOptions = await parseProviderOptions({
@@ -176,7 +176,7 @@ export class OpenAITranscriptionModel implements TranscriptionModelV3 {
176
176
 
177
177
  async doGenerate(
178
178
  options: OpenAITranscriptionCallOptions,
179
- ): Promise<Awaited<ReturnType<TranscriptionModelV3['doGenerate']>>> {
179
+ ): Promise<Awaited<ReturnType<TranscriptionModelV4['doGenerate']>>> {
180
180
  const currentDate = this.config._internal?.currentDate?.() ?? new Date();
181
181
  const { formData, warnings } = await this.getArgs(options);
182
182