@depup/ai-sdk__openai 3.0.41-depup.0
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.
- package/CHANGELOG.md +3101 -0
- package/LICENSE +13 -0
- package/README.md +25 -0
- package/changes.json +5 -0
- package/dist/index.d.mts +1107 -0
- package/dist/index.d.ts +1107 -0
- package/dist/index.js +6408 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +6493 -0
- package/dist/index.mjs.map +1 -0
- package/dist/internal/index.d.mts +1137 -0
- package/dist/internal/index.d.ts +1137 -0
- package/dist/internal/index.js +6256 -0
- package/dist/internal/index.js.map +1 -0
- package/dist/internal/index.mjs +6306 -0
- package/dist/internal/index.mjs.map +1 -0
- package/docs/03-openai.mdx +2396 -0
- package/internal.d.ts +1 -0
- package/package.json +96 -0
- package/src/chat/convert-openai-chat-usage.ts +57 -0
- package/src/chat/convert-to-openai-chat-messages.ts +225 -0
- package/src/chat/get-response-metadata.ts +15 -0
- package/src/chat/map-openai-finish-reason.ts +19 -0
- package/src/chat/openai-chat-api.ts +198 -0
- package/src/chat/openai-chat-language-model.ts +703 -0
- package/src/chat/openai-chat-options.ts +192 -0
- package/src/chat/openai-chat-prepare-tools.ts +84 -0
- package/src/chat/openai-chat-prompt.ts +70 -0
- package/src/completion/convert-openai-completion-usage.ts +46 -0
- package/src/completion/convert-to-openai-completion-prompt.ts +93 -0
- package/src/completion/get-response-metadata.ts +15 -0
- package/src/completion/map-openai-finish-reason.ts +19 -0
- package/src/completion/openai-completion-api.ts +81 -0
- package/src/completion/openai-completion-language-model.ts +336 -0
- package/src/completion/openai-completion-options.ts +61 -0
- package/src/embedding/openai-embedding-api.ts +13 -0
- package/src/embedding/openai-embedding-model.ts +95 -0
- package/src/embedding/openai-embedding-options.ts +30 -0
- package/src/image/openai-image-api.ts +35 -0
- package/src/image/openai-image-model.ts +349 -0
- package/src/image/openai-image-options.ts +31 -0
- package/src/index.ts +23 -0
- package/src/internal/index.ts +19 -0
- package/src/openai-config.ts +18 -0
- package/src/openai-error.ts +22 -0
- package/src/openai-language-model-capabilities.ts +52 -0
- package/src/openai-provider.ts +270 -0
- package/src/openai-tools.ts +126 -0
- package/src/responses/convert-openai-responses-usage.ts +53 -0
- package/src/responses/convert-to-openai-responses-input.ts +735 -0
- package/src/responses/map-openai-responses-finish-reason.ts +22 -0
- package/src/responses/openai-responses-api.ts +1260 -0
- package/src/responses/openai-responses-language-model.ts +2098 -0
- package/src/responses/openai-responses-options.ts +299 -0
- package/src/responses/openai-responses-prepare-tools.ts +408 -0
- package/src/responses/openai-responses-provider-metadata.ts +62 -0
- package/src/speech/openai-speech-api.ts +38 -0
- package/src/speech/openai-speech-model.ts +137 -0
- package/src/speech/openai-speech-options.ts +26 -0
- package/src/tool/apply-patch.ts +141 -0
- package/src/tool/code-interpreter.ts +104 -0
- package/src/tool/custom.ts +64 -0
- package/src/tool/file-search.ts +145 -0
- package/src/tool/image-generation.ts +126 -0
- package/src/tool/local-shell.ts +72 -0
- package/src/tool/mcp.ts +125 -0
- package/src/tool/shell.ts +203 -0
- package/src/tool/web-search-preview.ts +141 -0
- package/src/tool/web-search.ts +181 -0
- package/src/transcription/openai-transcription-api.ts +37 -0
- package/src/transcription/openai-transcription-model.ts +232 -0
- package/src/transcription/openai-transcription-options.ts +53 -0
- package/src/transcription/transcription-test.mp3 +0 -0
- package/src/version.ts +6 -0
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderToolFactoryWithOutputSchema,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
import {
|
|
8
|
+
OpenAIResponsesFileSearchToolComparisonFilter,
|
|
9
|
+
OpenAIResponsesFileSearchToolCompoundFilter,
|
|
10
|
+
} from '../responses/openai-responses-api';
|
|
11
|
+
|
|
12
|
+
const comparisonFilterSchema = z.object({
|
|
13
|
+
key: z.string(),
|
|
14
|
+
type: z.enum(['eq', 'ne', 'gt', 'gte', 'lt', 'lte', 'in', 'nin']),
|
|
15
|
+
value: z.union([z.string(), z.number(), z.boolean(), z.array(z.string())]),
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
const compoundFilterSchema: z.ZodType<any> = z.object({
|
|
19
|
+
type: z.enum(['and', 'or']),
|
|
20
|
+
filters: z.array(
|
|
21
|
+
z.union([comparisonFilterSchema, z.lazy(() => compoundFilterSchema)]),
|
|
22
|
+
),
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
export const fileSearchArgsSchema = lazySchema(() =>
|
|
26
|
+
zodSchema(
|
|
27
|
+
z.object({
|
|
28
|
+
vectorStoreIds: z.array(z.string()),
|
|
29
|
+
maxNumResults: z.number().optional(),
|
|
30
|
+
ranking: z
|
|
31
|
+
.object({
|
|
32
|
+
ranker: z.string().optional(),
|
|
33
|
+
scoreThreshold: z.number().optional(),
|
|
34
|
+
})
|
|
35
|
+
.optional(),
|
|
36
|
+
filters: z
|
|
37
|
+
.union([comparisonFilterSchema, compoundFilterSchema])
|
|
38
|
+
.optional(),
|
|
39
|
+
}),
|
|
40
|
+
),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
export const fileSearchOutputSchema = lazySchema(() =>
|
|
44
|
+
zodSchema(
|
|
45
|
+
z.object({
|
|
46
|
+
queries: z.array(z.string()),
|
|
47
|
+
results: z
|
|
48
|
+
.array(
|
|
49
|
+
z.object({
|
|
50
|
+
attributes: z.record(z.string(), z.unknown()),
|
|
51
|
+
fileId: z.string(),
|
|
52
|
+
filename: z.string(),
|
|
53
|
+
score: z.number(),
|
|
54
|
+
text: z.string(),
|
|
55
|
+
}),
|
|
56
|
+
)
|
|
57
|
+
.nullable(),
|
|
58
|
+
}),
|
|
59
|
+
),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
export const fileSearch = createProviderToolFactoryWithOutputSchema<
|
|
63
|
+
{},
|
|
64
|
+
{
|
|
65
|
+
/**
|
|
66
|
+
* The search query to execute.
|
|
67
|
+
*/
|
|
68
|
+
queries: string[];
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* The results of the file search tool call.
|
|
72
|
+
*/
|
|
73
|
+
results:
|
|
74
|
+
| null
|
|
75
|
+
| {
|
|
76
|
+
/**
|
|
77
|
+
* Set of 16 key-value pairs that can be attached to an object.
|
|
78
|
+
* This can be useful for storing additional information about the object
|
|
79
|
+
* in a structured format, and querying for objects via API or the dashboard.
|
|
80
|
+
* Keys are strings with a maximum length of 64 characters.
|
|
81
|
+
* Values are strings with a maximum length of 512 characters, booleans, or numbers.
|
|
82
|
+
*/
|
|
83
|
+
attributes: Record<string, unknown>;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The unique ID of the file.
|
|
87
|
+
*/
|
|
88
|
+
fileId: string;
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* The name of the file.
|
|
92
|
+
*/
|
|
93
|
+
filename: string;
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* The relevance score of the file - a value between 0 and 1.
|
|
97
|
+
*/
|
|
98
|
+
score: number;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The text that was retrieved from the file.
|
|
102
|
+
*/
|
|
103
|
+
text: string;
|
|
104
|
+
}[];
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
/**
|
|
108
|
+
* List of vector store IDs to search through.
|
|
109
|
+
*/
|
|
110
|
+
vectorStoreIds: string[];
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* Maximum number of search results to return. Defaults to 10.
|
|
114
|
+
*/
|
|
115
|
+
maxNumResults?: number;
|
|
116
|
+
|
|
117
|
+
/**
|
|
118
|
+
* Ranking options for the search.
|
|
119
|
+
*/
|
|
120
|
+
ranking?: {
|
|
121
|
+
/**
|
|
122
|
+
* The ranker to use for the file search.
|
|
123
|
+
*/
|
|
124
|
+
ranker?: string;
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The score threshold for the file search, a number between 0 and 1.
|
|
128
|
+
* Numbers closer to 1 will attempt to return only the most relevant results,
|
|
129
|
+
* but may return fewer results.
|
|
130
|
+
*/
|
|
131
|
+
scoreThreshold?: number;
|
|
132
|
+
};
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* A filter to apply.
|
|
136
|
+
*/
|
|
137
|
+
filters?:
|
|
138
|
+
| OpenAIResponsesFileSearchToolComparisonFilter
|
|
139
|
+
| OpenAIResponsesFileSearchToolCompoundFilter;
|
|
140
|
+
}
|
|
141
|
+
>({
|
|
142
|
+
id: 'openai.file_search',
|
|
143
|
+
inputSchema: z.object({}),
|
|
144
|
+
outputSchema: fileSearchOutputSchema,
|
|
145
|
+
});
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderToolFactoryWithOutputSchema,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
export const imageGenerationArgsSchema = lazySchema(() =>
|
|
9
|
+
zodSchema(
|
|
10
|
+
z
|
|
11
|
+
.object({
|
|
12
|
+
background: z.enum(['auto', 'opaque', 'transparent']).optional(),
|
|
13
|
+
inputFidelity: z.enum(['low', 'high']).optional(),
|
|
14
|
+
inputImageMask: z
|
|
15
|
+
.object({
|
|
16
|
+
fileId: z.string().optional(),
|
|
17
|
+
imageUrl: z.string().optional(),
|
|
18
|
+
})
|
|
19
|
+
.optional(),
|
|
20
|
+
model: z.string().optional(),
|
|
21
|
+
moderation: z.enum(['auto']).optional(),
|
|
22
|
+
outputCompression: z.number().int().min(0).max(100).optional(),
|
|
23
|
+
outputFormat: z.enum(['png', 'jpeg', 'webp']).optional(),
|
|
24
|
+
partialImages: z.number().int().min(0).max(3).optional(),
|
|
25
|
+
quality: z.enum(['auto', 'low', 'medium', 'high']).optional(),
|
|
26
|
+
size: z
|
|
27
|
+
.enum(['1024x1024', '1024x1536', '1536x1024', 'auto'])
|
|
28
|
+
.optional(),
|
|
29
|
+
})
|
|
30
|
+
.strict(),
|
|
31
|
+
),
|
|
32
|
+
);
|
|
33
|
+
|
|
34
|
+
const imageGenerationInputSchema = lazySchema(() => zodSchema(z.object({})));
|
|
35
|
+
|
|
36
|
+
export const imageGenerationOutputSchema = lazySchema(() =>
|
|
37
|
+
zodSchema(z.object({ result: z.string() })),
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
type ImageGenerationArgs = {
|
|
41
|
+
/**
|
|
42
|
+
* Background type for the generated image. Default is 'auto'.
|
|
43
|
+
*/
|
|
44
|
+
background?: 'auto' | 'opaque' | 'transparent';
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Input fidelity for the generated image. Default is 'low'.
|
|
48
|
+
*/
|
|
49
|
+
inputFidelity?: 'low' | 'high';
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Optional mask for inpainting.
|
|
53
|
+
* Contains image_url (string, optional) and file_id (string, optional).
|
|
54
|
+
*/
|
|
55
|
+
inputImageMask?: {
|
|
56
|
+
/**
|
|
57
|
+
* File ID for the mask image.
|
|
58
|
+
*/
|
|
59
|
+
fileId?: string;
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Base64-encoded mask image.
|
|
63
|
+
*/
|
|
64
|
+
imageUrl?: string;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* The image generation model to use. Default: gpt-image-1.
|
|
69
|
+
*/
|
|
70
|
+
model?: string;
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Moderation level for the generated image. Default: auto.
|
|
74
|
+
*/
|
|
75
|
+
moderation?: 'auto';
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Compression level for the output image. Default: 100.
|
|
79
|
+
*/
|
|
80
|
+
outputCompression?: number;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The output format of the generated image. One of png, webp, or jpeg.
|
|
84
|
+
* Default: png
|
|
85
|
+
*/
|
|
86
|
+
outputFormat?: 'png' | 'jpeg' | 'webp';
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Number of partial images to generate in streaming mode, from 0 (default value) to 3.
|
|
90
|
+
*/
|
|
91
|
+
partialImages?: number;
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* The quality of the generated image.
|
|
95
|
+
* One of low, medium, high, or auto. Default: auto.
|
|
96
|
+
*/
|
|
97
|
+
quality?: 'auto' | 'low' | 'medium' | 'high';
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The size of the generated image.
|
|
101
|
+
* One of 1024x1024, 1024x1536, 1536x1024, or auto.
|
|
102
|
+
* Default: auto.
|
|
103
|
+
*/
|
|
104
|
+
size?: 'auto' | '1024x1024' | '1024x1536' | '1536x1024';
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const imageGenerationToolFactory = createProviderToolFactoryWithOutputSchema<
|
|
108
|
+
{},
|
|
109
|
+
{
|
|
110
|
+
/**
|
|
111
|
+
* The generated image encoded in base64.
|
|
112
|
+
*/
|
|
113
|
+
result: string;
|
|
114
|
+
},
|
|
115
|
+
ImageGenerationArgs
|
|
116
|
+
>({
|
|
117
|
+
id: 'openai.image_generation',
|
|
118
|
+
inputSchema: imageGenerationInputSchema,
|
|
119
|
+
outputSchema: imageGenerationOutputSchema,
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
export const imageGeneration = (
|
|
123
|
+
args: ImageGenerationArgs = {}, // default
|
|
124
|
+
) => {
|
|
125
|
+
return imageGenerationToolFactory(args);
|
|
126
|
+
};
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderToolFactoryWithOutputSchema,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
export const localShellInputSchema = lazySchema(() =>
|
|
9
|
+
zodSchema(
|
|
10
|
+
z.object({
|
|
11
|
+
action: z.object({
|
|
12
|
+
type: z.literal('exec'),
|
|
13
|
+
command: z.array(z.string()),
|
|
14
|
+
timeoutMs: z.number().optional(),
|
|
15
|
+
user: z.string().optional(),
|
|
16
|
+
workingDirectory: z.string().optional(),
|
|
17
|
+
env: z.record(z.string(), z.string()).optional(),
|
|
18
|
+
}),
|
|
19
|
+
}),
|
|
20
|
+
),
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
export const localShellOutputSchema = lazySchema(() =>
|
|
24
|
+
zodSchema(z.object({ output: z.string() })),
|
|
25
|
+
);
|
|
26
|
+
|
|
27
|
+
export const localShell = createProviderToolFactoryWithOutputSchema<
|
|
28
|
+
{
|
|
29
|
+
/**
|
|
30
|
+
* Execute a shell command on the server.
|
|
31
|
+
*/
|
|
32
|
+
action: {
|
|
33
|
+
type: 'exec';
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* The command to run.
|
|
37
|
+
*/
|
|
38
|
+
command: string[];
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* Optional timeout in milliseconds for the command.
|
|
42
|
+
*/
|
|
43
|
+
timeoutMs?: number;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Optional user to run the command as.
|
|
47
|
+
*/
|
|
48
|
+
user?: string;
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Optional working directory to run the command in.
|
|
52
|
+
*/
|
|
53
|
+
workingDirectory?: string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Environment variables to set for the command.
|
|
57
|
+
*/
|
|
58
|
+
env?: Record<string, string>;
|
|
59
|
+
};
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
/**
|
|
63
|
+
* The output of local shell tool call.
|
|
64
|
+
*/
|
|
65
|
+
output: string;
|
|
66
|
+
},
|
|
67
|
+
{}
|
|
68
|
+
>({
|
|
69
|
+
id: 'openai.local_shell',
|
|
70
|
+
inputSchema: localShellInputSchema,
|
|
71
|
+
outputSchema: localShellOutputSchema,
|
|
72
|
+
});
|
package/src/tool/mcp.ts
ADDED
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderToolFactoryWithOutputSchema,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { JSONValue } from '@ai-sdk/provider';
|
|
7
|
+
import { z } from 'zod/v4';
|
|
8
|
+
|
|
9
|
+
const jsonValueSchema: z.ZodType<JSONValue> = z.lazy(() =>
|
|
10
|
+
z.union([
|
|
11
|
+
z.string(),
|
|
12
|
+
z.number(),
|
|
13
|
+
z.boolean(),
|
|
14
|
+
z.null(),
|
|
15
|
+
z.array(jsonValueSchema),
|
|
16
|
+
z.record(z.string(), jsonValueSchema),
|
|
17
|
+
]),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const mcpArgsSchema = lazySchema(() =>
|
|
21
|
+
zodSchema(
|
|
22
|
+
z
|
|
23
|
+
.object({
|
|
24
|
+
serverLabel: z.string(),
|
|
25
|
+
allowedTools: z
|
|
26
|
+
.union([
|
|
27
|
+
z.array(z.string()),
|
|
28
|
+
z.object({
|
|
29
|
+
readOnly: z.boolean().optional(),
|
|
30
|
+
toolNames: z.array(z.string()).optional(),
|
|
31
|
+
}),
|
|
32
|
+
])
|
|
33
|
+
.optional(),
|
|
34
|
+
authorization: z.string().optional(),
|
|
35
|
+
connectorId: z.string().optional(),
|
|
36
|
+
headers: z.record(z.string(), z.string()).optional(),
|
|
37
|
+
|
|
38
|
+
requireApproval: z
|
|
39
|
+
.union([
|
|
40
|
+
z.enum(['always', 'never']),
|
|
41
|
+
z.object({
|
|
42
|
+
never: z
|
|
43
|
+
.object({
|
|
44
|
+
toolNames: z.array(z.string()).optional(),
|
|
45
|
+
})
|
|
46
|
+
.optional(),
|
|
47
|
+
}),
|
|
48
|
+
])
|
|
49
|
+
.optional(),
|
|
50
|
+
serverDescription: z.string().optional(),
|
|
51
|
+
serverUrl: z.string().optional(),
|
|
52
|
+
})
|
|
53
|
+
.refine(
|
|
54
|
+
v => v.serverUrl != null || v.connectorId != null,
|
|
55
|
+
'One of serverUrl or connectorId must be provided.',
|
|
56
|
+
),
|
|
57
|
+
),
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const mcpInputSchema = lazySchema(() => zodSchema(z.object({})));
|
|
61
|
+
|
|
62
|
+
export const mcpOutputSchema = lazySchema(() =>
|
|
63
|
+
zodSchema(
|
|
64
|
+
z.object({
|
|
65
|
+
type: z.literal('call'),
|
|
66
|
+
serverLabel: z.string(),
|
|
67
|
+
name: z.string(),
|
|
68
|
+
arguments: z.string(),
|
|
69
|
+
output: z.string().nullish(),
|
|
70
|
+
error: z.union([z.string(), jsonValueSchema]).optional(),
|
|
71
|
+
}),
|
|
72
|
+
),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
type McpArgs = {
|
|
76
|
+
/** A label for this MCP server, used to identify it in tool calls. */
|
|
77
|
+
serverLabel: string;
|
|
78
|
+
/** List of allowed tool names or a filter object. */
|
|
79
|
+
allowedTools?:
|
|
80
|
+
| string[]
|
|
81
|
+
| {
|
|
82
|
+
readOnly?: boolean;
|
|
83
|
+
toolNames?: string[];
|
|
84
|
+
};
|
|
85
|
+
/** OAuth access token usable with the remote MCP server or connector. */
|
|
86
|
+
authorization?: string;
|
|
87
|
+
/** Identifier for a service connector. */
|
|
88
|
+
connectorId?: string;
|
|
89
|
+
/** Optional HTTP headers to send to the MCP server. */
|
|
90
|
+
headers?: Record<string, string>;
|
|
91
|
+
/**
|
|
92
|
+
* Which tools require approval before execution.
|
|
93
|
+
*/
|
|
94
|
+
requireApproval?:
|
|
95
|
+
| 'always'
|
|
96
|
+
| 'never'
|
|
97
|
+
| {
|
|
98
|
+
never?: {
|
|
99
|
+
toolNames?: string[];
|
|
100
|
+
};
|
|
101
|
+
};
|
|
102
|
+
/** Optional description of the MCP server. */
|
|
103
|
+
serverDescription?: string;
|
|
104
|
+
/** URL for the MCP server. One of serverUrl or connectorId must be provided. */
|
|
105
|
+
serverUrl?: string;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
export const mcpToolFactory = createProviderToolFactoryWithOutputSchema<
|
|
109
|
+
{},
|
|
110
|
+
{
|
|
111
|
+
type: 'call';
|
|
112
|
+
serverLabel: string;
|
|
113
|
+
name: string;
|
|
114
|
+
arguments: string;
|
|
115
|
+
output?: string | null;
|
|
116
|
+
error?: JSONValue;
|
|
117
|
+
},
|
|
118
|
+
McpArgs
|
|
119
|
+
>({
|
|
120
|
+
id: 'openai.mcp',
|
|
121
|
+
inputSchema: mcpInputSchema,
|
|
122
|
+
outputSchema: mcpOutputSchema,
|
|
123
|
+
});
|
|
124
|
+
|
|
125
|
+
export const mcp = (args: McpArgs) => mcpToolFactory(args);
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createProviderToolFactoryWithOutputSchema,
|
|
3
|
+
lazySchema,
|
|
4
|
+
zodSchema,
|
|
5
|
+
} from '@ai-sdk/provider-utils';
|
|
6
|
+
import { z } from 'zod/v4';
|
|
7
|
+
|
|
8
|
+
export const shellInputSchema = lazySchema(() =>
|
|
9
|
+
zodSchema(
|
|
10
|
+
z.object({
|
|
11
|
+
action: z.object({
|
|
12
|
+
commands: z.array(z.string()),
|
|
13
|
+
timeoutMs: z.number().optional(),
|
|
14
|
+
maxOutputLength: z.number().optional(),
|
|
15
|
+
}),
|
|
16
|
+
}),
|
|
17
|
+
),
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export const shellOutputSchema = lazySchema(() =>
|
|
21
|
+
zodSchema(
|
|
22
|
+
z.object({
|
|
23
|
+
output: z.array(
|
|
24
|
+
z.object({
|
|
25
|
+
stdout: z.string(),
|
|
26
|
+
stderr: z.string(),
|
|
27
|
+
outcome: z.discriminatedUnion('type', [
|
|
28
|
+
z.object({ type: z.literal('timeout') }),
|
|
29
|
+
z.object({ type: z.literal('exit'), exitCode: z.number() }),
|
|
30
|
+
]),
|
|
31
|
+
}),
|
|
32
|
+
),
|
|
33
|
+
}),
|
|
34
|
+
),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const shellSkillsSchema = z
|
|
38
|
+
.array(
|
|
39
|
+
z.discriminatedUnion('type', [
|
|
40
|
+
z.object({
|
|
41
|
+
type: z.literal('skillReference'),
|
|
42
|
+
skillId: z.string(),
|
|
43
|
+
version: z.string().optional(),
|
|
44
|
+
}),
|
|
45
|
+
z.object({
|
|
46
|
+
type: z.literal('inline'),
|
|
47
|
+
name: z.string(),
|
|
48
|
+
description: z.string(),
|
|
49
|
+
source: z.object({
|
|
50
|
+
type: z.literal('base64'),
|
|
51
|
+
mediaType: z.literal('application/zip'),
|
|
52
|
+
data: z.string(),
|
|
53
|
+
}),
|
|
54
|
+
}),
|
|
55
|
+
]),
|
|
56
|
+
)
|
|
57
|
+
.optional();
|
|
58
|
+
|
|
59
|
+
export const shellArgsSchema = lazySchema(() =>
|
|
60
|
+
zodSchema(
|
|
61
|
+
z.object({
|
|
62
|
+
environment: z
|
|
63
|
+
.union([
|
|
64
|
+
z.object({
|
|
65
|
+
type: z.literal('containerAuto'),
|
|
66
|
+
fileIds: z.array(z.string()).optional(),
|
|
67
|
+
memoryLimit: z.enum(['1g', '4g', '16g', '64g']).optional(),
|
|
68
|
+
networkPolicy: z
|
|
69
|
+
.discriminatedUnion('type', [
|
|
70
|
+
z.object({ type: z.literal('disabled') }),
|
|
71
|
+
z.object({
|
|
72
|
+
type: z.literal('allowlist'),
|
|
73
|
+
allowedDomains: z.array(z.string()),
|
|
74
|
+
domainSecrets: z
|
|
75
|
+
.array(
|
|
76
|
+
z.object({
|
|
77
|
+
domain: z.string(),
|
|
78
|
+
name: z.string(),
|
|
79
|
+
value: z.string(),
|
|
80
|
+
}),
|
|
81
|
+
)
|
|
82
|
+
.optional(),
|
|
83
|
+
}),
|
|
84
|
+
])
|
|
85
|
+
.optional(),
|
|
86
|
+
skills: shellSkillsSchema,
|
|
87
|
+
}),
|
|
88
|
+
z.object({
|
|
89
|
+
type: z.literal('containerReference'),
|
|
90
|
+
containerId: z.string(),
|
|
91
|
+
}),
|
|
92
|
+
z.object({
|
|
93
|
+
type: z.literal('local').optional(),
|
|
94
|
+
skills: z
|
|
95
|
+
.array(
|
|
96
|
+
z.object({
|
|
97
|
+
name: z.string(),
|
|
98
|
+
description: z.string(),
|
|
99
|
+
path: z.string(),
|
|
100
|
+
}),
|
|
101
|
+
)
|
|
102
|
+
.optional(),
|
|
103
|
+
}),
|
|
104
|
+
])
|
|
105
|
+
.optional(),
|
|
106
|
+
}),
|
|
107
|
+
),
|
|
108
|
+
);
|
|
109
|
+
|
|
110
|
+
type ShellArgs = {
|
|
111
|
+
environment?:
|
|
112
|
+
| {
|
|
113
|
+
type: 'containerAuto';
|
|
114
|
+
fileIds?: string[];
|
|
115
|
+
memoryLimit?: '1g' | '4g' | '16g' | '64g';
|
|
116
|
+
networkPolicy?:
|
|
117
|
+
| { type: 'disabled' }
|
|
118
|
+
| {
|
|
119
|
+
type: 'allowlist';
|
|
120
|
+
allowedDomains: string[];
|
|
121
|
+
domainSecrets?: Array<{
|
|
122
|
+
domain: string;
|
|
123
|
+
name: string;
|
|
124
|
+
value: string;
|
|
125
|
+
}>;
|
|
126
|
+
};
|
|
127
|
+
skills?: Array<
|
|
128
|
+
| { type: 'skillReference'; skillId: string; version?: string }
|
|
129
|
+
| {
|
|
130
|
+
type: 'inline';
|
|
131
|
+
name: string;
|
|
132
|
+
description: string;
|
|
133
|
+
source: {
|
|
134
|
+
type: 'base64';
|
|
135
|
+
mediaType: 'application/zip';
|
|
136
|
+
data: string;
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
>;
|
|
140
|
+
}
|
|
141
|
+
| {
|
|
142
|
+
type: 'containerReference';
|
|
143
|
+
containerId: string;
|
|
144
|
+
}
|
|
145
|
+
| {
|
|
146
|
+
type?: 'local';
|
|
147
|
+
skills?: Array<{
|
|
148
|
+
name: string;
|
|
149
|
+
description: string;
|
|
150
|
+
path: string;
|
|
151
|
+
}>;
|
|
152
|
+
};
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
export const shell = createProviderToolFactoryWithOutputSchema<
|
|
156
|
+
{
|
|
157
|
+
/**
|
|
158
|
+
* Shell tool action containing commands to execute.
|
|
159
|
+
*/
|
|
160
|
+
action: {
|
|
161
|
+
/**
|
|
162
|
+
* A list of shell commands to execute.
|
|
163
|
+
*/
|
|
164
|
+
commands: string[];
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Optional timeout in milliseconds for the commands.
|
|
168
|
+
*/
|
|
169
|
+
timeoutMs?: number;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Optional maximum number of characters to return from each command.
|
|
173
|
+
*/
|
|
174
|
+
maxOutputLength?: number;
|
|
175
|
+
};
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
/**
|
|
179
|
+
* An array of shell call output contents.
|
|
180
|
+
*/
|
|
181
|
+
output: Array<{
|
|
182
|
+
/**
|
|
183
|
+
* Standard output from the command.
|
|
184
|
+
*/
|
|
185
|
+
stdout: string;
|
|
186
|
+
|
|
187
|
+
/**
|
|
188
|
+
* Standard error from the command.
|
|
189
|
+
*/
|
|
190
|
+
stderr: string;
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* The outcome of the shell execution - either timeout or exit with code.
|
|
194
|
+
*/
|
|
195
|
+
outcome: { type: 'timeout' } | { type: 'exit'; exitCode: number };
|
|
196
|
+
}>;
|
|
197
|
+
},
|
|
198
|
+
ShellArgs
|
|
199
|
+
>({
|
|
200
|
+
id: 'openai.shell',
|
|
201
|
+
inputSchema: shellInputSchema,
|
|
202
|
+
outputSchema: shellOutputSchema,
|
|
203
|
+
});
|