@warlock.js/ai-openai 5.43.0 → 5.45.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 +14 -0
- package/cjs/index.cjs +76 -9
- package/cjs/index.cjs.map +1 -1
- package/esm/config.type.d.mts +8 -0
- package/esm/config.type.d.mts.map +1 -1
- package/esm/known-context-windows.mjs +38 -0
- package/esm/known-context-windows.mjs.map +1 -0
- package/esm/model.mjs +6 -2
- package/esm/model.mjs.map +1 -1
- package/esm/responses-model.d.mts.map +1 -1
- package/esm/responses-model.mjs +6 -2
- package/esm/responses-model.mjs.map +1 -1
- package/esm/utils/prompt-cache-params.mjs +6 -2
- package/esm/utils/prompt-cache-params.mjs.map +1 -1
- package/esm/utils/to-openai-messages.mjs +2 -2
- package/esm/utils/to-openai-messages.mjs.map +1 -1
- package/esm/utils/to-responses-input.mjs +24 -3
- package/esm/utils/to-responses-input.mjs.map +1 -1
- package/llms-full.txt +5 -1
- package/package.json +3 -3
- package/skills/SKILL.md +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,20 @@ All notable changes to `@warlock.js/ai-openai` are documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). `@warlock.js/*` packages are released in lockstep — every package shares the same version number, so a version below may list only the changes that affected this package.
|
|
6
6
|
|
|
7
|
+
## 5.45.0 - 2026-11-05
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
- With `api: "responses"` on the OpenAI provider, image parts in a tool result are sent as `input_image` items in the `function_call_output` (`capabilities.toolResultImages: true`). Chat Completions and the OpenAI-compatible providers send the text `[image omitted: provider cannot read images in tool results]` and report `false`.
|
|
12
|
+
- `capabilities.contextWindow` is reported for more direct-OpenAI ids: `gpt-5.x` and `gpt-6` (400K, the documented gpt-5 figure; set `contextWindow` for a larger window), `gpt-4`, `gpt-4-turbo`, `gpt-3.5-turbo`, `chatgpt-4o`, `o3-mini`, `o3-pro` and `o1-pro`.
|
|
13
|
+
|
|
14
|
+
## 5.44.0 - 2026-11-05
|
|
15
|
+
|
|
16
|
+
### Added
|
|
17
|
+
|
|
18
|
+
- `openai.model({ name, contextWindow })` sets `capabilities.contextWindow`; without it the window comes from a table of OpenAI models, and unknown models stay unset so window-relative `compaction.afterTokens` triggers do not fire.
|
|
19
|
+
- `ModelCallOptions.cacheControl.key` is sent as `prompt_cache_key` on Chat Completions and Responses requests for the providers that accept it (OpenAI, xAI, Mistral), and takes precedence over the model's `promptCacheKey`. Groq, DeepSeek and custom provider labels still receive no cache key.
|
|
20
|
+
|
|
7
21
|
## 5.40.0 - 2026-10-29
|
|
8
22
|
|
|
9
23
|
### Added
|
package/cjs/index.cjs
CHANGED
|
@@ -478,10 +478,14 @@ const PROMPT_CACHE_KEY_PROVIDERS = /* @__PURE__ */ new Set([
|
|
|
478
478
|
* ({@link PROMPT_CACHE_KEY_PROVIDERS}); `prompt_cache_retention` is
|
|
479
479
|
* OpenAI-only. Any other provider label — including a custom label on a
|
|
480
480
|
* wrapper SDK — gets neither, since an unknown endpoint may reject them.
|
|
481
|
+
* A per-call `options.cacheControl.key` takes precedence over
|
|
482
|
+
* `config.promptCacheKey`.
|
|
481
483
|
*/
|
|
482
|
-
function buildPromptCacheParams(provider, config) {
|
|
484
|
+
function buildPromptCacheParams(provider, config, options) {
|
|
485
|
+
const sendsKey = PROMPT_CACHE_KEY_PROVIDERS.has(provider);
|
|
486
|
+
const key = options?.cacheControl?.key ?? config.promptCacheKey;
|
|
483
487
|
return {
|
|
484
|
-
...
|
|
488
|
+
...sendsKey && key !== void 0 ? { prompt_cache_key: key } : {},
|
|
485
489
|
...provider === "openai" && config.promptCacheRetention !== void 0 ? { prompt_cache_retention: config.promptCacheRetention } : {}
|
|
486
490
|
};
|
|
487
491
|
}
|
|
@@ -736,7 +740,7 @@ function toOpenAIMessages(messages, cacheBreakpoints = 0) {
|
|
|
736
740
|
return addPromptCacheBreakpoints(messages.map((m) => {
|
|
737
741
|
if (m.role === "tool") return {
|
|
738
742
|
role: "tool",
|
|
739
|
-
content:
|
|
743
|
+
content: (0, _warlock_js_ai.toolResultText)(m.content),
|
|
740
744
|
tool_call_id: m.toolCallId ?? ""
|
|
741
745
|
};
|
|
742
746
|
if (m.role === "assistant" && m.toolCalls && m.toolCalls.length > 0) return {
|
|
@@ -944,7 +948,7 @@ function toToolParameters(input) {
|
|
|
944
948
|
* ]);
|
|
945
949
|
* // { instructions: "Be brief.", input: [{ role: "user", content: "Hi" }] }
|
|
946
950
|
*/
|
|
947
|
-
function toResponsesInput(messages, model) {
|
|
951
|
+
function toResponsesInput(messages, model, toolImages = false) {
|
|
948
952
|
const input = [];
|
|
949
953
|
let instructions;
|
|
950
954
|
let instructionsTaken = false;
|
|
@@ -966,7 +970,7 @@ function toResponsesInput(messages, model) {
|
|
|
966
970
|
input.push({
|
|
967
971
|
type: "function_call_output",
|
|
968
972
|
call_id: message.toolCallId ?? "",
|
|
969
|
-
output:
|
|
973
|
+
output: toToolOutput(message.content, toolImages)
|
|
970
974
|
});
|
|
971
975
|
continue;
|
|
972
976
|
}
|
|
@@ -1002,6 +1006,27 @@ function toResponsesInput(messages, model) {
|
|
|
1002
1006
|
input
|
|
1003
1007
|
};
|
|
1004
1008
|
}
|
|
1009
|
+
/**
|
|
1010
|
+
* A `function_call_output` value: the string, or (when the model reads tool
|
|
1011
|
+
* images) an array of `input_text` / `input_image` items. Otherwise images
|
|
1012
|
+
* degrade to the placeholder text.
|
|
1013
|
+
*/
|
|
1014
|
+
function toToolOutput(content, toolImages) {
|
|
1015
|
+
if (typeof content === "string") return content;
|
|
1016
|
+
if (!toolImages) return (0, _warlock_js_ai.toolResultText)(content);
|
|
1017
|
+
return content.flatMap((part) => {
|
|
1018
|
+
if (part.type === "text") return [{
|
|
1019
|
+
type: "input_text",
|
|
1020
|
+
text: part.text
|
|
1021
|
+
}];
|
|
1022
|
+
if (part.type === "image") return [{
|
|
1023
|
+
type: "input_image",
|
|
1024
|
+
image_url: toImageUrl(part.source),
|
|
1025
|
+
detail: "auto"
|
|
1026
|
+
}];
|
|
1027
|
+
return [];
|
|
1028
|
+
});
|
|
1029
|
+
}
|
|
1005
1030
|
/** Map a resolved `ContentPart` to a Responses input content part (text and images only). */
|
|
1006
1031
|
function toResponsesContentPart(part) {
|
|
1007
1032
|
if (part.type === "text") return {
|
|
@@ -1403,6 +1428,42 @@ function compatibleSearchParams(provider, options) {
|
|
|
1403
1428
|
return { enable_search: value };
|
|
1404
1429
|
}
|
|
1405
1430
|
|
|
1431
|
+
//#endregion
|
|
1432
|
+
//#region ../../packages/ai-openai/src/known-context-windows.ts
|
|
1433
|
+
const PREFIX_WINDOWS = [
|
|
1434
|
+
["gpt-5-", 4e5],
|
|
1435
|
+
["gpt-5.", 4e5],
|
|
1436
|
+
["gpt-6", 4e5],
|
|
1437
|
+
["gpt-4-turbo", 128e3],
|
|
1438
|
+
["gpt-3.5-turbo", 16385],
|
|
1439
|
+
["chatgpt-4o", 128e3],
|
|
1440
|
+
["o3-mini", 2e5],
|
|
1441
|
+
["o3-pro", 2e5],
|
|
1442
|
+
["o1-pro", 2e5],
|
|
1443
|
+
["gpt-4.1", 1047576],
|
|
1444
|
+
["gpt-5-chat", 128e3],
|
|
1445
|
+
["gpt-4o", 128e3],
|
|
1446
|
+
["o4-mini", 2e5],
|
|
1447
|
+
["o3", 2e5],
|
|
1448
|
+
["o1", 2e5],
|
|
1449
|
+
["o1-mini", 128e3],
|
|
1450
|
+
["o1-preview", 128e3]
|
|
1451
|
+
];
|
|
1452
|
+
/**
|
|
1453
|
+
* The known context window of a direct-OpenAI model id, or `undefined`.
|
|
1454
|
+
*
|
|
1455
|
+
* @example
|
|
1456
|
+
* inferContextWindow("gpt-4.1-mini"); // → 1047576
|
|
1457
|
+
*/
|
|
1458
|
+
function inferContextWindow(modelName) {
|
|
1459
|
+
const id = modelName.toLowerCase();
|
|
1460
|
+
if (id === "gpt-5") return 4e5;
|
|
1461
|
+
if (id === "gpt-4") return 8192;
|
|
1462
|
+
let best;
|
|
1463
|
+
for (const entry of PREFIX_WINDOWS) if (id.startsWith(entry[0]) && (!best || entry[0].length > best[0].length)) best = entry;
|
|
1464
|
+
return best?.[1];
|
|
1465
|
+
}
|
|
1466
|
+
|
|
1406
1467
|
//#endregion
|
|
1407
1468
|
//#region ../../packages/ai-openai/src/known-reasoning-models.ts
|
|
1408
1469
|
/**
|
|
@@ -1564,9 +1625,12 @@ var OpenAIResponsesModel = class {
|
|
|
1564
1625
|
this.name = config.name;
|
|
1565
1626
|
this.provider = provider;
|
|
1566
1627
|
this.pricing = config.pricing;
|
|
1628
|
+
const window = config.contextWindow ?? (provider === "openai" ? inferContextWindow(config.name) : void 0);
|
|
1567
1629
|
this.capabilities = {
|
|
1630
|
+
...window !== void 0 ? { contextWindow: window } : {},
|
|
1568
1631
|
structuredOutput: config.structuredOutput ?? inferStructuredOutput(config.responseFormat),
|
|
1569
1632
|
vision: config.vision ?? inferVisionCapability(config.name),
|
|
1633
|
+
toolResultImages: provider === "openai",
|
|
1570
1634
|
reasoning: config.reasoning ?? inferReasoningCapability(config.name),
|
|
1571
1635
|
promptCaching: true,
|
|
1572
1636
|
pdf: false,
|
|
@@ -1771,7 +1835,7 @@ var OpenAIResponsesModel = class {
|
|
|
1771
1835
|
* applies EVEN with tools attached - that is the point of this API.
|
|
1772
1836
|
*/
|
|
1773
1837
|
buildRequest(messages, options) {
|
|
1774
|
-
const { instructions, input } = toResponsesInput(messages, this.name);
|
|
1838
|
+
const { instructions, input } = toResponsesInput(messages, this.name, this.capabilities.toolResultImages === true);
|
|
1775
1839
|
const tools = this.buildTools(options);
|
|
1776
1840
|
const toolChoice = tools ? toResponsesToolChoice(options?.toolChoice) : void 0;
|
|
1777
1841
|
const maxTokens = options?.maxTokens ?? this.config.maxTokens;
|
|
@@ -1789,7 +1853,7 @@ var OpenAIResponsesModel = class {
|
|
|
1789
1853
|
...toolChoice !== void 0 ? { tool_choice: toolChoice } : {},
|
|
1790
1854
|
...this.buildTextFormat(options?.responseSchema),
|
|
1791
1855
|
...this.buildReasoningParams(options?.reasoning),
|
|
1792
|
-
...buildPromptCacheParams(this.provider, this.config)
|
|
1856
|
+
...buildPromptCacheParams(this.provider, this.config, options)
|
|
1793
1857
|
}, options);
|
|
1794
1858
|
}
|
|
1795
1859
|
/**
|
|
@@ -1966,9 +2030,12 @@ var OpenAIModel = class {
|
|
|
1966
2030
|
this.name = config.name;
|
|
1967
2031
|
this.provider = provider;
|
|
1968
2032
|
this.pricing = config.pricing;
|
|
2033
|
+
const window = config.contextWindow ?? (provider === "openai" ? inferContextWindow(config.name) : void 0);
|
|
1969
2034
|
this.capabilities = {
|
|
2035
|
+
...window !== void 0 ? { contextWindow: window } : {},
|
|
1970
2036
|
structuredOutput: config.structuredOutput ?? inferStructuredOutput(config.responseFormat),
|
|
1971
2037
|
vision: config.vision ?? inferVisionCapability(config.name),
|
|
2038
|
+
toolResultImages: false,
|
|
1972
2039
|
reasoning: config.reasoning ?? inferReasoningCapability(config.name),
|
|
1973
2040
|
promptCaching: this.provider === "openai",
|
|
1974
2041
|
pdf: config.pdf ?? false,
|
|
@@ -1997,7 +2064,7 @@ var OpenAIModel = class {
|
|
|
1997
2064
|
...compatibleSearchParams(this.provider, options),
|
|
1998
2065
|
messages: toOpenAIMessages(messages, this.promptCacheBreakpoints(options)),
|
|
1999
2066
|
...this.buildSamplingParams(options),
|
|
2000
|
-
...buildPromptCacheParams(this.provider, this.config),
|
|
2067
|
+
...buildPromptCacheParams(this.provider, this.config, options),
|
|
2001
2068
|
...this.buildTools(options),
|
|
2002
2069
|
...this.buildResponseFormat(options?.responseSchema),
|
|
2003
2070
|
...this.buildReasoningParams(options?.reasoning, Boolean(options?.tools?.length))
|
|
@@ -2059,7 +2126,7 @@ var OpenAIModel = class {
|
|
|
2059
2126
|
...compatibleSearchParams(this.provider, options),
|
|
2060
2127
|
messages: toOpenAIMessages(messages, this.promptCacheBreakpoints(options)),
|
|
2061
2128
|
...this.buildSamplingParams(options),
|
|
2062
|
-
...buildPromptCacheParams(this.provider, this.config),
|
|
2129
|
+
...buildPromptCacheParams(this.provider, this.config, options),
|
|
2063
2130
|
...this.buildTools(options),
|
|
2064
2131
|
stream: true,
|
|
2065
2132
|
stream_options: { include_usage: true },
|