@ai-sdk/openai 4.0.41 → 4.0.42
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 +6 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +9 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/index.d.ts +4 -1
- package/dist/internal/index.js +8 -0
- package/dist/internal/index.js.map +1 -1
- package/docs/03-openai.mdx +35 -0
- package/package.json +3 -3
- package/src/responses/openai-responses-api.ts +6 -1
- package/src/responses/openai-responses-language-model-options.ts +6 -0
- package/src/responses/openai-responses-language-model.ts +7 -0
package/docs/03-openai.mdx
CHANGED
|
@@ -264,6 +264,9 @@ The following provider options are available:
|
|
|
264
264
|
- `type`: `'compaction'`
|
|
265
265
|
- `compactThreshold`: _number_ — the token count at which compaction is triggered
|
|
266
266
|
|
|
267
|
+
- **compactionTrigger** _boolean_
|
|
268
|
+
Request explicit server-side compaction. When `true`, the provider appends a terminal `{ type: 'compaction_trigger' }` item to the Responses input. Support depends on the configured Responses-compatible endpoint and model.
|
|
269
|
+
|
|
267
270
|
The OpenAI responses provider also returns provider-specific metadata:
|
|
268
271
|
|
|
269
272
|
For Responses models, you can type this metadata using `OpenaiResponsesProviderMetadata`:
|
|
@@ -1776,6 +1779,38 @@ const result = await generateText({
|
|
|
1776
1779
|
requests.
|
|
1777
1780
|
</Note>
|
|
1778
1781
|
|
|
1782
|
+
##### Explicit Compaction
|
|
1783
|
+
|
|
1784
|
+
For Responses-compatible endpoints that support explicit compaction, set
|
|
1785
|
+
`compactionTrigger: true`. The provider appends the required
|
|
1786
|
+
`{ type: 'compaction_trigger' }` request control after all converted messages
|
|
1787
|
+
and input items.
|
|
1788
|
+
|
|
1789
|
+
```ts highlight="9"
|
|
1790
|
+
import {
|
|
1791
|
+
openai,
|
|
1792
|
+
type OpenAILanguageModelResponsesOptions,
|
|
1793
|
+
} from '@ai-sdk/openai';
|
|
1794
|
+
import { generateText } from 'ai';
|
|
1795
|
+
|
|
1796
|
+
const result = await generateText({
|
|
1797
|
+
model: openai.responses('gpt-5.3-codex'),
|
|
1798
|
+
messages: conversationHistory,
|
|
1799
|
+
providerOptions: {
|
|
1800
|
+
openai: {
|
|
1801
|
+
store: false,
|
|
1802
|
+
compactionTrigger: true,
|
|
1803
|
+
} satisfies OpenAILanguageModelResponsesOptions,
|
|
1804
|
+
},
|
|
1805
|
+
});
|
|
1806
|
+
```
|
|
1807
|
+
|
|
1808
|
+
This is distinct from `contextManagement`, which configures automatic,
|
|
1809
|
+
threshold-based compaction. When omitted or `false`, `compactionTrigger` does
|
|
1810
|
+
not add an input item. The resulting compaction output uses the existing
|
|
1811
|
+
`openai.compaction` custom part representation. Endpoint and model support can
|
|
1812
|
+
vary.
|
|
1813
|
+
|
|
1779
1814
|
##### Detecting Compaction in Streams
|
|
1780
1815
|
|
|
1781
1816
|
When using `streamText`, you can detect compaction by checking the `providerMetadata` on `text-start` and `text-end` events:
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ai-sdk/openai",
|
|
3
|
-
"version": "4.0.
|
|
3
|
+
"version": "4.0.42",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -43,8 +43,8 @@
|
|
|
43
43
|
"tsup": "^8.5.1",
|
|
44
44
|
"typescript": "5.8.3",
|
|
45
45
|
"zod": "3.25.76",
|
|
46
|
-
"@
|
|
47
|
-
"@ai-
|
|
46
|
+
"@ai-sdk/test-server": "2.0.1",
|
|
47
|
+
"@vercel/ai-tsconfig": "0.0.0"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
50
50
|
"zod": "^3.25.76 || ^4.1.8"
|
|
@@ -133,7 +133,8 @@ export type OpenAIResponsesInputItem =
|
|
|
133
133
|
| OpenAIResponsesToolSearchOutput
|
|
134
134
|
| OpenAIResponsesReasoning
|
|
135
135
|
| OpenAIResponsesItemReference
|
|
136
|
-
| OpenAIResponsesCompactionItem
|
|
136
|
+
| OpenAIResponsesCompactionItem
|
|
137
|
+
| OpenAIResponsesCompactionTrigger;
|
|
137
138
|
|
|
138
139
|
export type OpenAIResponsesIncludeValue =
|
|
139
140
|
| 'web_search_call.action.sources'
|
|
@@ -431,6 +432,10 @@ export type OpenAIResponsesCompactionItem = {
|
|
|
431
432
|
encrypted_content: string;
|
|
432
433
|
};
|
|
433
434
|
|
|
435
|
+
export type OpenAIResponsesCompactionTrigger = {
|
|
436
|
+
type: 'compaction_trigger';
|
|
437
|
+
};
|
|
438
|
+
|
|
434
439
|
/**
|
|
435
440
|
* A filter used to compare a specified attribute key to a given value using a defined comparison operation.
|
|
436
441
|
*/
|
|
@@ -375,6 +375,12 @@ export const openaiLanguageModelResponsesOptionsSchema = lazySchema(() =>
|
|
|
375
375
|
)
|
|
376
376
|
.nullish(),
|
|
377
377
|
|
|
378
|
+
/**
|
|
379
|
+
* Request explicit server-side compaction by appending a
|
|
380
|
+
* `compaction_trigger` item to the Responses input.
|
|
381
|
+
*/
|
|
382
|
+
compactionTrigger: z.boolean().optional(),
|
|
383
|
+
|
|
378
384
|
/**
|
|
379
385
|
* Restrict the callable tools to a subset while keeping the full tools
|
|
380
386
|
* list intact, so prompt caching is preserved across requests with
|
|
@@ -369,6 +369,13 @@ export class OpenAIResponsesLanguageModel implements LanguageModelV4 {
|
|
|
369
369
|
|
|
370
370
|
warnings.push(...inputWarnings);
|
|
371
371
|
|
|
372
|
+
// A compaction trigger is a request control, not conversation history.
|
|
373
|
+
// OpenAI requires it to be the final input item, so append it only after
|
|
374
|
+
// the complete prompt has been converted.
|
|
375
|
+
if (openaiOptions?.compactionTrigger) {
|
|
376
|
+
input.push({ type: 'compaction_trigger' });
|
|
377
|
+
}
|
|
378
|
+
|
|
372
379
|
const strictJsonSchema = openaiOptions?.strictJsonSchema ?? true;
|
|
373
380
|
|
|
374
381
|
let include: OpenAIResponsesIncludeOptions = openaiOptions?.include;
|