@ai-sdk/openai 4.0.87 → 4.0.89
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 +24 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +46 -15
- package/dist/index.js.map +1 -1
- package/dist/internal/index.js +13 -9
- package/dist/internal/index.js.map +1 -1
- package/package.json +3 -3
- package/src/chat/convert-to-openai-chat-messages.ts +4 -2
- package/src/openai-decision-model.ts +50 -5
- package/src/responses/convert-to-openai-responses-input.ts +9 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.89",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -35,8 +35,8 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@ai-sdk/provider": "4.0.
|
|
39
|
-
"@ai-sdk/provider-utils": "5.0.
|
|
38
|
+
"@ai-sdk/provider": "4.0.25",
|
|
39
|
+
"@ai-sdk/provider-utils": "5.0.57"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
|
42
42
|
"@ai-sdk/test-server": "2.0.4",
|
|
@@ -322,15 +322,17 @@ export function convertToOpenAIChatMessages({
|
|
|
322
322
|
let contentValue: string;
|
|
323
323
|
switch (output.type) {
|
|
324
324
|
case 'text':
|
|
325
|
-
case 'error-text':
|
|
326
325
|
contentValue = output.value;
|
|
327
326
|
break;
|
|
327
|
+
case 'error-text':
|
|
328
|
+
case 'error-json':
|
|
329
|
+
contentValue = JSON.stringify({ error: output.value });
|
|
330
|
+
break;
|
|
328
331
|
case 'execution-denied':
|
|
329
332
|
contentValue = output.reason ?? 'Tool call execution denied.';
|
|
330
333
|
break;
|
|
331
334
|
case 'content':
|
|
332
335
|
case 'json':
|
|
333
|
-
case 'error-json':
|
|
334
336
|
contentValue = JSON.stringify(output.value);
|
|
335
337
|
break;
|
|
336
338
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import {
|
|
2
2
|
InvalidResponseDataError,
|
|
3
|
+
UnsupportedFunctionalityError,
|
|
3
4
|
type Experimental_DecisionModelV4 as DecisionModelV4,
|
|
4
5
|
type Experimental_DecisionModelV4Answer as DecisionModelV4Answer,
|
|
5
6
|
type Experimental_DecisionModelV4Input as DecisionModelV4Input,
|
|
6
7
|
} from '@ai-sdk/provider';
|
|
7
8
|
import {
|
|
8
9
|
combineHeaders,
|
|
10
|
+
convertUint8ArrayToBase64,
|
|
11
|
+
detectMediaType,
|
|
12
|
+
isFullMediaType,
|
|
9
13
|
createJsonResponseHandler,
|
|
10
14
|
postJsonToApi,
|
|
11
15
|
parseProviderOptions,
|
|
@@ -72,10 +76,6 @@ const responseSchema = z.object({
|
|
|
72
76
|
),
|
|
73
77
|
});
|
|
74
78
|
|
|
75
|
-
function toText(input: DecisionModelV4Input): string {
|
|
76
|
-
return typeof input === 'string' ? input : JSON.stringify(input);
|
|
77
|
-
}
|
|
78
|
-
|
|
79
79
|
export class DecisionOpenAIModel implements DecisionModelV4 {
|
|
80
80
|
readonly specificationVersion = 'v4';
|
|
81
81
|
readonly supportedQuestionTypes = ['choice', 'score', 'boolean'] as const;
|
|
@@ -135,7 +135,48 @@ export class DecisionOpenAIModel implements DecisionModelV4 {
|
|
|
135
135
|
body: {
|
|
136
136
|
model: this.modelId,
|
|
137
137
|
safety_identifier: openaiOptions?.safetyIdentifier,
|
|
138
|
-
input:
|
|
138
|
+
input: [
|
|
139
|
+
{
|
|
140
|
+
role: 'user',
|
|
141
|
+
content: state.map(part => {
|
|
142
|
+
if (part.type === 'text')
|
|
143
|
+
return { type: 'input_text', text: part.text };
|
|
144
|
+
if (part.type === 'json')
|
|
145
|
+
return {
|
|
146
|
+
type: 'input_text',
|
|
147
|
+
text: JSON.stringify(part.value),
|
|
148
|
+
};
|
|
149
|
+
if (part.data.type !== 'data') {
|
|
150
|
+
throw new UnsupportedFunctionalityError({
|
|
151
|
+
functionality: `OpenAI decision file input: ${part.mediaType} (${part.data.type})`,
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
// Direct doDecide calls can bypass Core's media type detection.
|
|
155
|
+
const mediaType = isFullMediaType(part.mediaType)
|
|
156
|
+
? part.mediaType
|
|
157
|
+
: detectMediaType({
|
|
158
|
+
data: part.data.data,
|
|
159
|
+
topLevelType: 'image',
|
|
160
|
+
});
|
|
161
|
+
if (
|
|
162
|
+
![
|
|
163
|
+
'image/png',
|
|
164
|
+
'image/jpeg',
|
|
165
|
+
'image/webp',
|
|
166
|
+
'image/gif',
|
|
167
|
+
].includes(mediaType ?? '')
|
|
168
|
+
) {
|
|
169
|
+
throw new UnsupportedFunctionalityError({
|
|
170
|
+
functionality: `OpenAI decision image media type: ${part.mediaType}`,
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
return {
|
|
174
|
+
type: 'input_image',
|
|
175
|
+
image_url: `data:${mediaType};base64,${typeof part.data.data === 'string' ? part.data.data : convertUint8ArrayToBase64(part.data.data)}`,
|
|
176
|
+
};
|
|
177
|
+
}),
|
|
178
|
+
},
|
|
179
|
+
],
|
|
139
180
|
questions: Object.entries(questions).map(([name, question]) => {
|
|
140
181
|
const instructions = toText(question.instructions);
|
|
141
182
|
switch (question.type) {
|
|
@@ -283,3 +324,7 @@ export class DecisionOpenAIModel implements DecisionModelV4 {
|
|
|
283
324
|
};
|
|
284
325
|
}
|
|
285
326
|
}
|
|
327
|
+
|
|
328
|
+
function toText(input: DecisionModelV4Input): string {
|
|
329
|
+
return typeof input === 'string' ? input : JSON.stringify(input);
|
|
330
|
+
}
|
|
@@ -102,10 +102,12 @@ async function convertFunctionToolResultOutput({
|
|
|
102
102
|
|
|
103
103
|
switch (output.type) {
|
|
104
104
|
case 'text':
|
|
105
|
-
case 'error-text':
|
|
106
105
|
return convertScalarOutput(
|
|
107
106
|
hasOutputSchema ? JSON.stringify(output.value) : output.value,
|
|
108
107
|
);
|
|
108
|
+
case 'error-text':
|
|
109
|
+
case 'error-json':
|
|
110
|
+
return convertScalarOutput(JSON.stringify({ error: output.value }));
|
|
109
111
|
case 'execution-denied': {
|
|
110
112
|
const reason = output.reason ?? 'Tool call execution denied.';
|
|
111
113
|
return convertScalarOutput(
|
|
@@ -113,7 +115,6 @@ async function convertFunctionToolResultOutput({
|
|
|
113
115
|
);
|
|
114
116
|
}
|
|
115
117
|
case 'json':
|
|
116
|
-
case 'error-json':
|
|
117
118
|
return convertScalarOutput(JSON.stringify(output.value));
|
|
118
119
|
case 'content':
|
|
119
120
|
return output.value
|
|
@@ -1542,16 +1543,20 @@ export async function convertToOpenAIResponsesInput({
|
|
|
1542
1543
|
let outputValue: OpenAIResponsesCustomToolCallOutput['output'];
|
|
1543
1544
|
switch (output.type) {
|
|
1544
1545
|
case 'text':
|
|
1545
|
-
case 'error-text':
|
|
1546
1546
|
outputValue = convertScalarOutput(output.value);
|
|
1547
1547
|
break;
|
|
1548
|
+
case 'error-text':
|
|
1549
|
+
case 'error-json':
|
|
1550
|
+
outputValue = convertScalarOutput(
|
|
1551
|
+
JSON.stringify({ error: output.value }),
|
|
1552
|
+
);
|
|
1553
|
+
break;
|
|
1548
1554
|
case 'execution-denied':
|
|
1549
1555
|
outputValue = convertScalarOutput(
|
|
1550
1556
|
output.reason ?? 'Tool call execution denied.',
|
|
1551
1557
|
);
|
|
1552
1558
|
break;
|
|
1553
1559
|
case 'json':
|
|
1554
|
-
case 'error-json':
|
|
1555
1560
|
outputValue = convertScalarOutput(JSON.stringify(output.value));
|
|
1556
1561
|
break;
|
|
1557
1562
|
case 'content':
|