@ai-sdk/openai 4.0.0-beta.11 → 4.0.0-beta.13
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 +48 -33
- package/dist/index.d.mts +21 -1
- package/dist/index.d.ts +21 -1
- package/dist/index.js +110 -27
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +112 -27
- package/dist/index.mjs.map +1 -1
- package/dist/internal/index.d.mts +17 -1
- package/dist/internal/index.d.ts +17 -1
- package/dist/internal/index.js +109 -26
- package/dist/internal/index.js.map +1 -1
- package/dist/internal/index.mjs +111 -26
- package/dist/internal/index.mjs.map +1 -1
- package/docs/03-openai.mdx +124 -0
- package/package.json +3 -5
- package/src/chat/openai-chat-language-model.ts +10 -2
- package/src/index.ts +1 -0
- package/src/responses/convert-to-openai-responses-input.ts +35 -4
- package/src/responses/openai-responses-api.ts +23 -1
- package/src/responses/openai-responses-language-model.ts +46 -4
- package/src/responses/openai-responses-options.ts +12 -0
- package/src/responses/openai-responses-provider-metadata.ts +10 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,20 @@
|
|
|
1
1
|
# @ai-sdk/openai
|
|
2
2
|
|
|
3
|
+
## 4.0.0-beta.13
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 3887c70: feat(provider): add new top-level reasoning parameter to spec and support it in `generateText` and `streamText`
|
|
8
|
+
- Updated dependencies [3887c70]
|
|
9
|
+
- @ai-sdk/provider-utils@5.0.0-beta.6
|
|
10
|
+
- @ai-sdk/provider@4.0.0-beta.4
|
|
11
|
+
|
|
12
|
+
## 4.0.0-beta.12
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- d9a1e9a: feat(openai): add server side compaction for openai
|
|
17
|
+
|
|
3
18
|
## 4.0.0-beta.11
|
|
4
19
|
|
|
5
20
|
### Patch Changes
|
|
@@ -47,18 +62,18 @@
|
|
|
47
62
|
const toolNameMapping = createToolNameMapping({
|
|
48
63
|
tools,
|
|
49
64
|
providerToolNames: {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
"openai.code_interpreter": "code_interpreter",
|
|
66
|
+
"openai.file_search": "file_search",
|
|
67
|
+
"openai.image_generation": "image_generation",
|
|
68
|
+
"openai.local_shell": "local_shell",
|
|
69
|
+
"openai.shell": "shell",
|
|
70
|
+
"openai.web_search": "web_search",
|
|
71
|
+
"openai.web_search_preview": "web_search_preview",
|
|
72
|
+
"openai.mcp": "mcp",
|
|
73
|
+
"openai.apply_patch": "apply_patch",
|
|
59
74
|
},
|
|
60
|
-
resolveProviderToolName: tool =>
|
|
61
|
-
tool.id ===
|
|
75
|
+
resolveProviderToolName: (tool) =>
|
|
76
|
+
tool.id === "openai.custom"
|
|
62
77
|
? (tool.args as { name?: string }).name
|
|
63
78
|
: undefined,
|
|
64
79
|
});
|
|
@@ -498,13 +513,13 @@
|
|
|
498
513
|
Before
|
|
499
514
|
|
|
500
515
|
```ts
|
|
501
|
-
model.textEmbeddingModel(
|
|
516
|
+
model.textEmbeddingModel("my-model-id");
|
|
502
517
|
```
|
|
503
518
|
|
|
504
519
|
After
|
|
505
520
|
|
|
506
521
|
```ts
|
|
507
|
-
model.embeddingModel(
|
|
522
|
+
model.embeddingModel("my-model-id");
|
|
508
523
|
```
|
|
509
524
|
|
|
510
525
|
- 60f4775: fix: remove code for unsuported o1-mini and o1-preview models
|
|
@@ -514,15 +529,15 @@
|
|
|
514
529
|
- 2e86082: feat(provider/openai): `OpenAIChatLanguageModelOptions` type
|
|
515
530
|
|
|
516
531
|
```ts
|
|
517
|
-
import { openai, type OpenAIChatLanguageModelOptions } from
|
|
518
|
-
import { generateText } from
|
|
532
|
+
import { openai, type OpenAIChatLanguageModelOptions } from "@ai-sdk/openai";
|
|
533
|
+
import { generateText } from "ai";
|
|
519
534
|
|
|
520
535
|
await generateText({
|
|
521
|
-
model: openai.chat(
|
|
522
|
-
prompt:
|
|
536
|
+
model: openai.chat("gpt-4o"),
|
|
537
|
+
prompt: "Invent a new holiday and describe its traditions.",
|
|
523
538
|
providerOptions: {
|
|
524
539
|
openai: {
|
|
525
|
-
user:
|
|
540
|
+
user: "user-123",
|
|
526
541
|
} satisfies OpenAIChatLanguageModelOptions,
|
|
527
542
|
},
|
|
528
543
|
});
|
|
@@ -923,13 +938,13 @@
|
|
|
923
938
|
Before
|
|
924
939
|
|
|
925
940
|
```ts
|
|
926
|
-
model.textEmbeddingModel(
|
|
941
|
+
model.textEmbeddingModel("my-model-id");
|
|
927
942
|
```
|
|
928
943
|
|
|
929
944
|
After
|
|
930
945
|
|
|
931
946
|
```ts
|
|
932
|
-
model.embeddingModel(
|
|
947
|
+
model.embeddingModel("my-model-id");
|
|
933
948
|
```
|
|
934
949
|
|
|
935
950
|
- Updated dependencies [8d9e8ad]
|
|
@@ -1399,15 +1414,15 @@
|
|
|
1399
1414
|
- 2e86082: feat(provider/openai): `OpenAIChatLanguageModelOptions` type
|
|
1400
1415
|
|
|
1401
1416
|
```ts
|
|
1402
|
-
import { openai, type OpenAIChatLanguageModelOptions } from
|
|
1403
|
-
import { generateText } from
|
|
1417
|
+
import { openai, type OpenAIChatLanguageModelOptions } from "@ai-sdk/openai";
|
|
1418
|
+
import { generateText } from "ai";
|
|
1404
1419
|
|
|
1405
1420
|
await generateText({
|
|
1406
|
-
model: openai.chat(
|
|
1407
|
-
prompt:
|
|
1421
|
+
model: openai.chat("gpt-4o"),
|
|
1422
|
+
prompt: "Invent a new holiday and describe its traditions.",
|
|
1408
1423
|
providerOptions: {
|
|
1409
1424
|
openai: {
|
|
1410
|
-
user:
|
|
1425
|
+
user: "user-123",
|
|
1411
1426
|
} satisfies OpenAIChatLanguageModelOptions,
|
|
1412
1427
|
},
|
|
1413
1428
|
});
|
|
@@ -1703,7 +1718,7 @@
|
|
|
1703
1718
|
|
|
1704
1719
|
```js
|
|
1705
1720
|
await generateImage({
|
|
1706
|
-
model: luma.image(
|
|
1721
|
+
model: luma.image("photon-flash-1", {
|
|
1707
1722
|
maxImagesPerCall: 5,
|
|
1708
1723
|
pollIntervalMillis: 500,
|
|
1709
1724
|
}),
|
|
@@ -1716,7 +1731,7 @@
|
|
|
1716
1731
|
|
|
1717
1732
|
```js
|
|
1718
1733
|
await generateImage({
|
|
1719
|
-
model: luma.image(
|
|
1734
|
+
model: luma.image("photon-flash-1"),
|
|
1720
1735
|
prompt,
|
|
1721
1736
|
n: 10,
|
|
1722
1737
|
maxImagesPerCall: 5,
|
|
@@ -1778,10 +1793,10 @@
|
|
|
1778
1793
|
The `experimental_generateImage` method from the `ai` package now returnes revised prompts for OpenAI's image models.
|
|
1779
1794
|
|
|
1780
1795
|
```js
|
|
1781
|
-
const prompt =
|
|
1796
|
+
const prompt = "Santa Claus driving a Cadillac";
|
|
1782
1797
|
|
|
1783
1798
|
const { providerMetadata } = await experimental_generateImage({
|
|
1784
|
-
model: openai.image(
|
|
1799
|
+
model: openai.image("dall-e-3"),
|
|
1785
1800
|
prompt,
|
|
1786
1801
|
});
|
|
1787
1802
|
|
|
@@ -2080,7 +2095,7 @@
|
|
|
2080
2095
|
|
|
2081
2096
|
```js
|
|
2082
2097
|
await generateImage({
|
|
2083
|
-
model: luma.image(
|
|
2098
|
+
model: luma.image("photon-flash-1", {
|
|
2084
2099
|
maxImagesPerCall: 5,
|
|
2085
2100
|
pollIntervalMillis: 500,
|
|
2086
2101
|
}),
|
|
@@ -2093,7 +2108,7 @@
|
|
|
2093
2108
|
|
|
2094
2109
|
```js
|
|
2095
2110
|
await generateImage({
|
|
2096
|
-
model: luma.image(
|
|
2111
|
+
model: luma.image("photon-flash-1"),
|
|
2097
2112
|
prompt,
|
|
2098
2113
|
n: 10,
|
|
2099
2114
|
maxImagesPerCall: 5,
|
|
@@ -2138,10 +2153,10 @@
|
|
|
2138
2153
|
The `experimental_generateImage` method from the `ai` package now returnes revised prompts for OpenAI's image models.
|
|
2139
2154
|
|
|
2140
2155
|
```js
|
|
2141
|
-
const prompt =
|
|
2156
|
+
const prompt = "Santa Claus driving a Cadillac";
|
|
2142
2157
|
|
|
2143
2158
|
const { providerMetadata } = await experimental_generateImage({
|
|
2144
|
-
model: openai.image(
|
|
2159
|
+
model: openai.image("dall-e-3"),
|
|
2145
2160
|
prompt,
|
|
2146
2161
|
});
|
|
2147
2162
|
|
package/dist/index.d.mts
CHANGED
|
@@ -300,6 +300,10 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
300
300
|
action: {
|
|
301
301
|
commands: string[];
|
|
302
302
|
};
|
|
303
|
+
} | {
|
|
304
|
+
type: "compaction";
|
|
305
|
+
id: string;
|
|
306
|
+
encrypted_content?: string | null | undefined;
|
|
303
307
|
} | {
|
|
304
308
|
type: "shell_call_output";
|
|
305
309
|
id: string;
|
|
@@ -483,6 +487,10 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
483
487
|
action: {
|
|
484
488
|
commands: string[];
|
|
485
489
|
};
|
|
490
|
+
} | {
|
|
491
|
+
type: "compaction";
|
|
492
|
+
id: string;
|
|
493
|
+
encrypted_content: string;
|
|
486
494
|
} | {
|
|
487
495
|
type: "shell_call_output";
|
|
488
496
|
id: string;
|
|
@@ -990,6 +998,10 @@ declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.
|
|
|
990
998
|
user?: string | null | undefined;
|
|
991
999
|
systemMessageMode?: "remove" | "system" | "developer" | undefined;
|
|
992
1000
|
forceReasoning?: boolean | undefined;
|
|
1001
|
+
contextManagement?: {
|
|
1002
|
+
type: "compaction";
|
|
1003
|
+
compactThreshold: number;
|
|
1004
|
+
}[] | null | undefined;
|
|
993
1005
|
}>;
|
|
994
1006
|
type OpenAILanguageModelResponsesOptions = InferSchema<typeof openaiLanguageModelResponsesOptionsSchema>;
|
|
995
1007
|
|
|
@@ -1124,6 +1136,14 @@ type OpenaiResponsesReasoningProviderMetadata = {
|
|
|
1124
1136
|
type OpenaiResponsesProviderMetadata = {
|
|
1125
1137
|
openai: ResponsesProviderMetadata;
|
|
1126
1138
|
};
|
|
1139
|
+
type ResponsesCompactionProviderMetadata = {
|
|
1140
|
+
type: 'compaction';
|
|
1141
|
+
itemId: string;
|
|
1142
|
+
encryptedContent?: string;
|
|
1143
|
+
};
|
|
1144
|
+
type OpenaiResponsesCompactionProviderMetadata = {
|
|
1145
|
+
openai: ResponsesCompactionProviderMetadata;
|
|
1146
|
+
};
|
|
1127
1147
|
type ResponsesTextProviderMetadata = {
|
|
1128
1148
|
itemId: string;
|
|
1129
1149
|
phase?: 'commentary' | 'final_answer' | null;
|
|
@@ -1151,4 +1171,4 @@ type OpenaiResponsesSourceDocumentProviderMetadata = {
|
|
|
1151
1171
|
|
|
1152
1172
|
declare const VERSION: string;
|
|
1153
1173
|
|
|
1154
|
-
export { type OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions, type OpenAIEmbeddingModelOptions, type OpenAILanguageModelChatOptions, type OpenAILanguageModelCompletionOptions, type OpenAILanguageModelResponsesOptions, type OpenAIProvider, type OpenAIProviderSettings, type OpenAILanguageModelResponsesOptions as OpenAIResponsesProviderOptions, type OpenAISpeechModelOptions, type OpenAITranscriptionModelOptions, type OpenaiResponsesProviderMetadata, type OpenaiResponsesReasoningProviderMetadata, type OpenaiResponsesSourceDocumentProviderMetadata, type OpenaiResponsesTextProviderMetadata, VERSION, createOpenAI, openai };
|
|
1174
|
+
export { type OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions, type OpenAIEmbeddingModelOptions, 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 };
|
package/dist/index.d.ts
CHANGED
|
@@ -300,6 +300,10 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
300
300
|
action: {
|
|
301
301
|
commands: string[];
|
|
302
302
|
};
|
|
303
|
+
} | {
|
|
304
|
+
type: "compaction";
|
|
305
|
+
id: string;
|
|
306
|
+
encrypted_content?: string | null | undefined;
|
|
303
307
|
} | {
|
|
304
308
|
type: "shell_call_output";
|
|
305
309
|
id: string;
|
|
@@ -483,6 +487,10 @@ declare const openaiResponsesChunkSchema: _ai_sdk_provider_utils.LazySchema<{
|
|
|
483
487
|
action: {
|
|
484
488
|
commands: string[];
|
|
485
489
|
};
|
|
490
|
+
} | {
|
|
491
|
+
type: "compaction";
|
|
492
|
+
id: string;
|
|
493
|
+
encrypted_content: string;
|
|
486
494
|
} | {
|
|
487
495
|
type: "shell_call_output";
|
|
488
496
|
id: string;
|
|
@@ -990,6 +998,10 @@ declare const openaiLanguageModelResponsesOptionsSchema: _ai_sdk_provider_utils.
|
|
|
990
998
|
user?: string | null | undefined;
|
|
991
999
|
systemMessageMode?: "remove" | "system" | "developer" | undefined;
|
|
992
1000
|
forceReasoning?: boolean | undefined;
|
|
1001
|
+
contextManagement?: {
|
|
1002
|
+
type: "compaction";
|
|
1003
|
+
compactThreshold: number;
|
|
1004
|
+
}[] | null | undefined;
|
|
993
1005
|
}>;
|
|
994
1006
|
type OpenAILanguageModelResponsesOptions = InferSchema<typeof openaiLanguageModelResponsesOptionsSchema>;
|
|
995
1007
|
|
|
@@ -1124,6 +1136,14 @@ type OpenaiResponsesReasoningProviderMetadata = {
|
|
|
1124
1136
|
type OpenaiResponsesProviderMetadata = {
|
|
1125
1137
|
openai: ResponsesProviderMetadata;
|
|
1126
1138
|
};
|
|
1139
|
+
type ResponsesCompactionProviderMetadata = {
|
|
1140
|
+
type: 'compaction';
|
|
1141
|
+
itemId: string;
|
|
1142
|
+
encryptedContent?: string;
|
|
1143
|
+
};
|
|
1144
|
+
type OpenaiResponsesCompactionProviderMetadata = {
|
|
1145
|
+
openai: ResponsesCompactionProviderMetadata;
|
|
1146
|
+
};
|
|
1127
1147
|
type ResponsesTextProviderMetadata = {
|
|
1128
1148
|
itemId: string;
|
|
1129
1149
|
phase?: 'commentary' | 'final_answer' | null;
|
|
@@ -1151,4 +1171,4 @@ type OpenaiResponsesSourceDocumentProviderMetadata = {
|
|
|
1151
1171
|
|
|
1152
1172
|
declare const VERSION: string;
|
|
1153
1173
|
|
|
1154
|
-
export { type OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions, type OpenAIEmbeddingModelOptions, type OpenAILanguageModelChatOptions, type OpenAILanguageModelCompletionOptions, type OpenAILanguageModelResponsesOptions, type OpenAIProvider, type OpenAIProviderSettings, type OpenAILanguageModelResponsesOptions as OpenAIResponsesProviderOptions, type OpenAISpeechModelOptions, type OpenAITranscriptionModelOptions, type OpenaiResponsesProviderMetadata, type OpenaiResponsesReasoningProviderMetadata, type OpenaiResponsesSourceDocumentProviderMetadata, type OpenaiResponsesTextProviderMetadata, VERSION, createOpenAI, openai };
|
|
1174
|
+
export { type OpenAILanguageModelChatOptions as OpenAIChatLanguageModelOptions, type OpenAIEmbeddingModelOptions, 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 };
|
package/dist/index.js
CHANGED
|
@@ -671,9 +671,10 @@ var OpenAIChatLanguageModel = class {
|
|
|
671
671
|
seed,
|
|
672
672
|
tools,
|
|
673
673
|
toolChoice,
|
|
674
|
+
reasoning,
|
|
674
675
|
providerOptions
|
|
675
676
|
}) {
|
|
676
|
-
var _a, _b, _c, _d, _e;
|
|
677
|
+
var _a, _b, _c, _d, _e, _f;
|
|
677
678
|
const warnings = [];
|
|
678
679
|
const openaiOptions = (_a = await (0, import_provider_utils5.parseProviderOptions)({
|
|
679
680
|
provider: "openai",
|
|
@@ -681,18 +682,19 @@ var OpenAIChatLanguageModel = class {
|
|
|
681
682
|
schema: openaiLanguageModelChatOptions
|
|
682
683
|
})) != null ? _a : {};
|
|
683
684
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
684
|
-
const
|
|
685
|
+
const resolvedReasoningEffort = (_b = openaiOptions.reasoningEffort) != null ? _b : (0, import_provider_utils5.isCustomReasoning)(reasoning) ? reasoning : void 0;
|
|
686
|
+
const isReasoningModel = (_c = openaiOptions.forceReasoning) != null ? _c : modelCapabilities.isReasoningModel;
|
|
685
687
|
if (topK != null) {
|
|
686
688
|
warnings.push({ type: "unsupported", feature: "topK" });
|
|
687
689
|
}
|
|
688
690
|
const { messages, warnings: messageWarnings } = convertToOpenAIChatMessages(
|
|
689
691
|
{
|
|
690
692
|
prompt,
|
|
691
|
-
systemMessageMode: (
|
|
693
|
+
systemMessageMode: (_d = openaiOptions.systemMessageMode) != null ? _d : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode
|
|
692
694
|
}
|
|
693
695
|
);
|
|
694
696
|
warnings.push(...messageWarnings);
|
|
695
|
-
const strictJsonSchema = (
|
|
697
|
+
const strictJsonSchema = (_e = openaiOptions.strictJsonSchema) != null ? _e : true;
|
|
696
698
|
const baseArgs = {
|
|
697
699
|
// model id:
|
|
698
700
|
model: this.modelId,
|
|
@@ -713,7 +715,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
713
715
|
json_schema: {
|
|
714
716
|
schema: responseFormat.schema,
|
|
715
717
|
strict: strictJsonSchema,
|
|
716
|
-
name: (
|
|
718
|
+
name: (_f = responseFormat.name) != null ? _f : "response",
|
|
717
719
|
description: responseFormat.description
|
|
718
720
|
}
|
|
719
721
|
} : { type: "json_object" } : void 0,
|
|
@@ -726,7 +728,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
726
728
|
store: openaiOptions.store,
|
|
727
729
|
metadata: openaiOptions.metadata,
|
|
728
730
|
prediction: openaiOptions.prediction,
|
|
729
|
-
reasoning_effort:
|
|
731
|
+
reasoning_effort: resolvedReasoningEffort,
|
|
730
732
|
service_tier: openaiOptions.serviceTier,
|
|
731
733
|
prompt_cache_key: openaiOptions.promptCacheKey,
|
|
732
734
|
prompt_cache_retention: openaiOptions.promptCacheRetention,
|
|
@@ -735,7 +737,7 @@ var OpenAIChatLanguageModel = class {
|
|
|
735
737
|
messages
|
|
736
738
|
};
|
|
737
739
|
if (isReasoningModel) {
|
|
738
|
-
if (
|
|
740
|
+
if (resolvedReasoningEffort !== "none" || !modelCapabilities.supportsNonReasoningParameters) {
|
|
739
741
|
if (baseArgs.temperature != null) {
|
|
740
742
|
baseArgs.temperature = void 0;
|
|
741
743
|
warnings.push({
|
|
@@ -2656,7 +2658,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
2656
2658
|
hasApplyPatchTool = false,
|
|
2657
2659
|
customProviderToolNames
|
|
2658
2660
|
}) {
|
|
2659
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
|
|
2661
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
|
|
2660
2662
|
let input = [];
|
|
2661
2663
|
const warnings = [];
|
|
2662
2664
|
const processedApprovalIds = /* @__PURE__ */ new Set();
|
|
@@ -3003,6 +3005,28 @@ async function convertToOpenAIResponsesInput({
|
|
|
3003
3005
|
}
|
|
3004
3006
|
break;
|
|
3005
3007
|
}
|
|
3008
|
+
case "custom": {
|
|
3009
|
+
if (part.kind === "openai-compaction") {
|
|
3010
|
+
const providerOpts = (_n = part.providerOptions) == null ? void 0 : _n[providerOptionsName];
|
|
3011
|
+
const id = providerOpts == null ? void 0 : providerOpts.itemId;
|
|
3012
|
+
if (hasConversation && id != null) {
|
|
3013
|
+
break;
|
|
3014
|
+
}
|
|
3015
|
+
if (store && id != null) {
|
|
3016
|
+
input.push({ type: "item_reference", id });
|
|
3017
|
+
break;
|
|
3018
|
+
}
|
|
3019
|
+
const encryptedContent = providerOpts == null ? void 0 : providerOpts.encryptedContent;
|
|
3020
|
+
if (id != null) {
|
|
3021
|
+
input.push({
|
|
3022
|
+
type: "compaction",
|
|
3023
|
+
id,
|
|
3024
|
+
encrypted_content: encryptedContent
|
|
3025
|
+
});
|
|
3026
|
+
}
|
|
3027
|
+
}
|
|
3028
|
+
break;
|
|
3029
|
+
}
|
|
3006
3030
|
}
|
|
3007
3031
|
}
|
|
3008
3032
|
break;
|
|
@@ -3030,7 +3054,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3030
3054
|
}
|
|
3031
3055
|
const output = part.output;
|
|
3032
3056
|
if (output.type === "execution-denied") {
|
|
3033
|
-
const approvalId = (
|
|
3057
|
+
const approvalId = (_p = (_o = output.providerOptions) == null ? void 0 : _o.openai) == null ? void 0 : _p.approvalId;
|
|
3034
3058
|
if (approvalId) {
|
|
3035
3059
|
continue;
|
|
3036
3060
|
}
|
|
@@ -3104,7 +3128,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3104
3128
|
outputValue = output.value;
|
|
3105
3129
|
break;
|
|
3106
3130
|
case "execution-denied":
|
|
3107
|
-
outputValue = (
|
|
3131
|
+
outputValue = (_q = output.reason) != null ? _q : "Tool execution denied.";
|
|
3108
3132
|
break;
|
|
3109
3133
|
case "json":
|
|
3110
3134
|
case "error-json":
|
|
@@ -3158,7 +3182,7 @@ async function convertToOpenAIResponsesInput({
|
|
|
3158
3182
|
contentValue = output.value;
|
|
3159
3183
|
break;
|
|
3160
3184
|
case "execution-denied":
|
|
3161
|
-
contentValue = (
|
|
3185
|
+
contentValue = (_r = output.reason) != null ? _r : "Tool execution denied.";
|
|
3162
3186
|
break;
|
|
3163
3187
|
case "json":
|
|
3164
3188
|
case "error-json":
|
|
@@ -3410,6 +3434,11 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
3410
3434
|
commands: import_v421.z.array(import_v421.z.string())
|
|
3411
3435
|
})
|
|
3412
3436
|
}),
|
|
3437
|
+
import_v421.z.object({
|
|
3438
|
+
type: import_v421.z.literal("compaction"),
|
|
3439
|
+
id: import_v421.z.string(),
|
|
3440
|
+
encrypted_content: import_v421.z.string().nullish()
|
|
3441
|
+
}),
|
|
3413
3442
|
import_v421.z.object({
|
|
3414
3443
|
type: import_v421.z.literal("shell_call_output"),
|
|
3415
3444
|
id: import_v421.z.string(),
|
|
@@ -3633,6 +3662,11 @@ var openaiResponsesChunkSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
3633
3662
|
commands: import_v421.z.array(import_v421.z.string())
|
|
3634
3663
|
})
|
|
3635
3664
|
}),
|
|
3665
|
+
import_v421.z.object({
|
|
3666
|
+
type: import_v421.z.literal("compaction"),
|
|
3667
|
+
id: import_v421.z.string(),
|
|
3668
|
+
encrypted_content: import_v421.z.string()
|
|
3669
|
+
}),
|
|
3636
3670
|
import_v421.z.object({
|
|
3637
3671
|
type: import_v421.z.literal("shell_call_output"),
|
|
3638
3672
|
id: import_v421.z.string(),
|
|
@@ -4030,6 +4064,11 @@ var openaiResponsesResponseSchema = (0, import_provider_utils26.lazySchema)(
|
|
|
4030
4064
|
commands: import_v421.z.array(import_v421.z.string())
|
|
4031
4065
|
})
|
|
4032
4066
|
}),
|
|
4067
|
+
import_v421.z.object({
|
|
4068
|
+
type: import_v421.z.literal("compaction"),
|
|
4069
|
+
id: import_v421.z.string(),
|
|
4070
|
+
encrypted_content: import_v421.z.string()
|
|
4071
|
+
}),
|
|
4033
4072
|
import_v421.z.object({
|
|
4034
4073
|
type: import_v421.z.literal("shell_call_output"),
|
|
4035
4074
|
id: import_v421.z.string(),
|
|
@@ -4292,7 +4331,16 @@ var openaiLanguageModelResponsesOptionsSchema = (0, import_provider_utils27.lazy
|
|
|
4292
4331
|
* When enabled, the SDK applies reasoning-model parameter compatibility rules
|
|
4293
4332
|
* and defaults `systemMessageMode` to `developer` unless overridden.
|
|
4294
4333
|
*/
|
|
4295
|
-
forceReasoning: import_v422.z.boolean().optional()
|
|
4334
|
+
forceReasoning: import_v422.z.boolean().optional(),
|
|
4335
|
+
/**
|
|
4336
|
+
* Enable server-side context management (compaction).
|
|
4337
|
+
*/
|
|
4338
|
+
contextManagement: import_v422.z.array(
|
|
4339
|
+
import_v422.z.object({
|
|
4340
|
+
type: import_v422.z.literal("compaction"),
|
|
4341
|
+
compactThreshold: import_v422.z.number()
|
|
4342
|
+
})
|
|
4343
|
+
).nullish()
|
|
4296
4344
|
})
|
|
4297
4345
|
)
|
|
4298
4346
|
);
|
|
@@ -4608,12 +4656,13 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4608
4656
|
frequencyPenalty,
|
|
4609
4657
|
seed,
|
|
4610
4658
|
prompt,
|
|
4659
|
+
reasoning,
|
|
4611
4660
|
providerOptions,
|
|
4612
4661
|
tools,
|
|
4613
4662
|
toolChoice,
|
|
4614
4663
|
responseFormat
|
|
4615
4664
|
}) {
|
|
4616
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
4665
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
4617
4666
|
const warnings = [];
|
|
4618
4667
|
const modelCapabilities = getOpenAILanguageModelCapabilities(this.modelId);
|
|
4619
4668
|
if (topK != null) {
|
|
@@ -4644,7 +4693,8 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4644
4693
|
schema: openaiLanguageModelResponsesOptionsSchema
|
|
4645
4694
|
});
|
|
4646
4695
|
}
|
|
4647
|
-
const
|
|
4696
|
+
const resolvedReasoningEffort = (_a = openaiOptions == null ? void 0 : openaiOptions.reasoningEffort) != null ? _a : (0, import_provider_utils29.isCustomReasoning)(reasoning) ? reasoning : void 0;
|
|
4697
|
+
const isReasoningModel = (_b = openaiOptions == null ? void 0 : openaiOptions.forceReasoning) != null ? _b : modelCapabilities.isReasoningModel;
|
|
4648
4698
|
if ((openaiOptions == null ? void 0 : openaiOptions.conversation) && (openaiOptions == null ? void 0 : openaiOptions.previousResponseId)) {
|
|
4649
4699
|
warnings.push({
|
|
4650
4700
|
type: "unsupported",
|
|
@@ -4681,10 +4731,10 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4681
4731
|
const { input, warnings: inputWarnings } = await convertToOpenAIResponsesInput({
|
|
4682
4732
|
prompt,
|
|
4683
4733
|
toolNameMapping,
|
|
4684
|
-
systemMessageMode: (
|
|
4734
|
+
systemMessageMode: (_c = openaiOptions == null ? void 0 : openaiOptions.systemMessageMode) != null ? _c : isReasoningModel ? "developer" : modelCapabilities.systemMessageMode,
|
|
4685
4735
|
providerOptionsName,
|
|
4686
4736
|
fileIdPrefixes: this.config.fileIdPrefixes,
|
|
4687
|
-
store: (
|
|
4737
|
+
store: (_d = openaiOptions == null ? void 0 : openaiOptions.store) != null ? _d : true,
|
|
4688
4738
|
hasConversation: (openaiOptions == null ? void 0 : openaiOptions.conversation) != null,
|
|
4689
4739
|
hasLocalShellTool: hasOpenAITool("openai.local_shell"),
|
|
4690
4740
|
hasShellTool: hasOpenAITool("openai.shell"),
|
|
@@ -4692,7 +4742,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4692
4742
|
customProviderToolNames: customProviderToolNames.size > 0 ? customProviderToolNames : void 0
|
|
4693
4743
|
});
|
|
4694
4744
|
warnings.push(...inputWarnings);
|
|
4695
|
-
const strictJsonSchema = (
|
|
4745
|
+
const strictJsonSchema = (_e = openaiOptions == null ? void 0 : openaiOptions.strictJsonSchema) != null ? _e : true;
|
|
4696
4746
|
let include = openaiOptions == null ? void 0 : openaiOptions.include;
|
|
4697
4747
|
function addInclude(key) {
|
|
4698
4748
|
if (include == null) {
|
|
@@ -4708,9 +4758,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4708
4758
|
if (topLogprobs) {
|
|
4709
4759
|
addInclude("message.output_text.logprobs");
|
|
4710
4760
|
}
|
|
4711
|
-
const webSearchToolName = (
|
|
4761
|
+
const webSearchToolName = (_f = tools == null ? void 0 : tools.find(
|
|
4712
4762
|
(tool) => tool.type === "provider" && (tool.id === "openai.web_search" || tool.id === "openai.web_search_preview")
|
|
4713
|
-
)) == null ? void 0 :
|
|
4763
|
+
)) == null ? void 0 : _f.name;
|
|
4714
4764
|
if (webSearchToolName) {
|
|
4715
4765
|
addInclude("web_search_call.action.sources");
|
|
4716
4766
|
}
|
|
@@ -4733,7 +4783,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4733
4783
|
format: responseFormat.schema != null ? {
|
|
4734
4784
|
type: "json_schema",
|
|
4735
4785
|
strict: strictJsonSchema,
|
|
4736
|
-
name: (
|
|
4786
|
+
name: (_g = responseFormat.name) != null ? _g : "response",
|
|
4737
4787
|
description: responseFormat.description,
|
|
4738
4788
|
schema: responseFormat.schema
|
|
4739
4789
|
} : { type: "json_object" }
|
|
@@ -4759,11 +4809,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4759
4809
|
safety_identifier: openaiOptions == null ? void 0 : openaiOptions.safetyIdentifier,
|
|
4760
4810
|
top_logprobs: topLogprobs,
|
|
4761
4811
|
truncation: openaiOptions == null ? void 0 : openaiOptions.truncation,
|
|
4812
|
+
// context management (server-side compaction):
|
|
4813
|
+
...(openaiOptions == null ? void 0 : openaiOptions.contextManagement) && {
|
|
4814
|
+
context_management: openaiOptions.contextManagement.map((cm) => ({
|
|
4815
|
+
type: cm.type,
|
|
4816
|
+
compact_threshold: cm.compactThreshold
|
|
4817
|
+
}))
|
|
4818
|
+
},
|
|
4762
4819
|
// model-specific settings:
|
|
4763
|
-
...isReasoningModel && (
|
|
4820
|
+
...isReasoningModel && (resolvedReasoningEffort != null || (openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null) && {
|
|
4764
4821
|
reasoning: {
|
|
4765
|
-
...
|
|
4766
|
-
effort:
|
|
4822
|
+
...resolvedReasoningEffort != null && {
|
|
4823
|
+
effort: resolvedReasoningEffort
|
|
4767
4824
|
},
|
|
4768
4825
|
...(openaiOptions == null ? void 0 : openaiOptions.reasoningSummary) != null && {
|
|
4769
4826
|
summary: openaiOptions.reasoningSummary
|
|
@@ -4772,7 +4829,7 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4772
4829
|
}
|
|
4773
4830
|
};
|
|
4774
4831
|
if (isReasoningModel) {
|
|
4775
|
-
if (!(
|
|
4832
|
+
if (!(resolvedReasoningEffort === "none" && modelCapabilities.supportsNonReasoningParameters)) {
|
|
4776
4833
|
if (baseArgs.temperature != null) {
|
|
4777
4834
|
baseArgs.temperature = void 0;
|
|
4778
4835
|
warnings.push({
|
|
@@ -4822,9 +4879,9 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
4822
4879
|
});
|
|
4823
4880
|
delete baseArgs.service_tier;
|
|
4824
4881
|
}
|
|
4825
|
-
const shellToolEnvType = (
|
|
4882
|
+
const shellToolEnvType = (_j = (_i = (_h = tools == null ? void 0 : tools.find(
|
|
4826
4883
|
(tool) => tool.type === "provider" && tool.id === "openai.shell"
|
|
4827
|
-
)) == null ? void 0 :
|
|
4884
|
+
)) == null ? void 0 : _h.args) == null ? void 0 : _i.environment) == null ? void 0 : _j.type;
|
|
4828
4885
|
const isShellProviderExecuted = shellToolEnvType === "containerAuto" || shellToolEnvType === "containerReference";
|
|
4829
4886
|
return {
|
|
4830
4887
|
webSearchToolName,
|
|
@@ -5283,6 +5340,20 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5283
5340
|
});
|
|
5284
5341
|
break;
|
|
5285
5342
|
}
|
|
5343
|
+
case "compaction": {
|
|
5344
|
+
content.push({
|
|
5345
|
+
type: "custom",
|
|
5346
|
+
kind: "openai-compaction",
|
|
5347
|
+
providerMetadata: {
|
|
5348
|
+
[providerOptionsName]: {
|
|
5349
|
+
type: "compaction",
|
|
5350
|
+
itemId: part.id,
|
|
5351
|
+
encryptedContent: part.encrypted_content
|
|
5352
|
+
}
|
|
5353
|
+
}
|
|
5354
|
+
});
|
|
5355
|
+
break;
|
|
5356
|
+
}
|
|
5286
5357
|
}
|
|
5287
5358
|
}
|
|
5288
5359
|
const providerMetadata = {
|
|
@@ -5912,6 +5983,18 @@ var OpenAIResponsesLanguageModel = class {
|
|
|
5912
5983
|
});
|
|
5913
5984
|
}
|
|
5914
5985
|
delete activeReasoning[value.item.id];
|
|
5986
|
+
} else if (value.item.type === "compaction") {
|
|
5987
|
+
controller.enqueue({
|
|
5988
|
+
type: "custom",
|
|
5989
|
+
kind: "openai-compaction",
|
|
5990
|
+
providerMetadata: {
|
|
5991
|
+
[providerOptionsName]: {
|
|
5992
|
+
type: "compaction",
|
|
5993
|
+
itemId: value.item.id,
|
|
5994
|
+
encryptedContent: value.item.encrypted_content
|
|
5995
|
+
}
|
|
5996
|
+
}
|
|
5997
|
+
});
|
|
5915
5998
|
}
|
|
5916
5999
|
} else if (isResponseFunctionCallArgumentsDeltaChunk(value)) {
|
|
5917
6000
|
const toolCall = ongoingToolCalls[value.output_index];
|
|
@@ -6599,7 +6682,7 @@ var OpenAITranscriptionModel = class {
|
|
|
6599
6682
|
};
|
|
6600
6683
|
|
|
6601
6684
|
// src/version.ts
|
|
6602
|
-
var VERSION = true ? "4.0.0-beta.
|
|
6685
|
+
var VERSION = true ? "4.0.0-beta.13" : "0.0.0-test";
|
|
6603
6686
|
|
|
6604
6687
|
// src/openai-provider.ts
|
|
6605
6688
|
function createOpenAI(options = {}) {
|