@warlock.js/ai-openai 5.43.0 → 5.44.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 CHANGED
@@ -4,6 +4,13 @@ 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.44.0 - 2026-11-05
8
+
9
+ ### Added
10
+
11
+ - `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.
12
+ - `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.
13
+
7
14
  ## 5.40.0 - 2026-10-29
8
15
 
9
16
  ### 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
- ...PROMPT_CACHE_KEY_PROVIDERS.has(provider) && config.promptCacheKey !== void 0 ? { prompt_cache_key: config.promptCacheKey } : {},
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
  }
@@ -1403,6 +1407,33 @@ function compatibleSearchParams(provider, options) {
1403
1407
  return { enable_search: value };
1404
1408
  }
1405
1409
 
1410
+ //#endregion
1411
+ //#region ../../packages/ai-openai/src/known-context-windows.ts
1412
+ const PREFIX_WINDOWS = [
1413
+ ["gpt-5-", 4e5],
1414
+ ["gpt-4.1", 1047576],
1415
+ ["gpt-5-chat", 128e3],
1416
+ ["gpt-4o", 128e3],
1417
+ ["o4-mini", 2e5],
1418
+ ["o3", 2e5],
1419
+ ["o1", 2e5],
1420
+ ["o1-mini", 128e3],
1421
+ ["o1-preview", 128e3]
1422
+ ];
1423
+ /**
1424
+ * The known context window of a direct-OpenAI model id, or `undefined`.
1425
+ *
1426
+ * @example
1427
+ * inferContextWindow("gpt-4.1-mini"); // → 1047576
1428
+ */
1429
+ function inferContextWindow(modelName) {
1430
+ const id = modelName.toLowerCase();
1431
+ if (id === "gpt-5") return 4e5;
1432
+ let best;
1433
+ for (const entry of PREFIX_WINDOWS) if (id.startsWith(entry[0]) && (!best || entry[0].length > best[0].length)) best = entry;
1434
+ return best?.[1];
1435
+ }
1436
+
1406
1437
  //#endregion
1407
1438
  //#region ../../packages/ai-openai/src/known-reasoning-models.ts
1408
1439
  /**
@@ -1564,7 +1595,9 @@ var OpenAIResponsesModel = class {
1564
1595
  this.name = config.name;
1565
1596
  this.provider = provider;
1566
1597
  this.pricing = config.pricing;
1598
+ const window = config.contextWindow ?? (provider === "openai" ? inferContextWindow(config.name) : void 0);
1567
1599
  this.capabilities = {
1600
+ ...window !== void 0 ? { contextWindow: window } : {},
1568
1601
  structuredOutput: config.structuredOutput ?? inferStructuredOutput(config.responseFormat),
1569
1602
  vision: config.vision ?? inferVisionCapability(config.name),
1570
1603
  reasoning: config.reasoning ?? inferReasoningCapability(config.name),
@@ -1789,7 +1822,7 @@ var OpenAIResponsesModel = class {
1789
1822
  ...toolChoice !== void 0 ? { tool_choice: toolChoice } : {},
1790
1823
  ...this.buildTextFormat(options?.responseSchema),
1791
1824
  ...this.buildReasoningParams(options?.reasoning),
1792
- ...buildPromptCacheParams(this.provider, this.config)
1825
+ ...buildPromptCacheParams(this.provider, this.config, options)
1793
1826
  }, options);
1794
1827
  }
1795
1828
  /**
@@ -1966,7 +1999,9 @@ var OpenAIModel = class {
1966
1999
  this.name = config.name;
1967
2000
  this.provider = provider;
1968
2001
  this.pricing = config.pricing;
2002
+ const window = config.contextWindow ?? (provider === "openai" ? inferContextWindow(config.name) : void 0);
1969
2003
  this.capabilities = {
2004
+ ...window !== void 0 ? { contextWindow: window } : {},
1970
2005
  structuredOutput: config.structuredOutput ?? inferStructuredOutput(config.responseFormat),
1971
2006
  vision: config.vision ?? inferVisionCapability(config.name),
1972
2007
  reasoning: config.reasoning ?? inferReasoningCapability(config.name),
@@ -1997,7 +2032,7 @@ var OpenAIModel = class {
1997
2032
  ...compatibleSearchParams(this.provider, options),
1998
2033
  messages: toOpenAIMessages(messages, this.promptCacheBreakpoints(options)),
1999
2034
  ...this.buildSamplingParams(options),
2000
- ...buildPromptCacheParams(this.provider, this.config),
2035
+ ...buildPromptCacheParams(this.provider, this.config, options),
2001
2036
  ...this.buildTools(options),
2002
2037
  ...this.buildResponseFormat(options?.responseSchema),
2003
2038
  ...this.buildReasoningParams(options?.reasoning, Boolean(options?.tools?.length))
@@ -2059,7 +2094,7 @@ var OpenAIModel = class {
2059
2094
  ...compatibleSearchParams(this.provider, options),
2060
2095
  messages: toOpenAIMessages(messages, this.promptCacheBreakpoints(options)),
2061
2096
  ...this.buildSamplingParams(options),
2062
- ...buildPromptCacheParams(this.provider, this.config),
2097
+ ...buildPromptCacheParams(this.provider, this.config, options),
2063
2098
  ...this.buildTools(options),
2064
2099
  stream: true,
2065
2100
  stream_options: { include_usage: true },