@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
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { readReasoningReplay, toReplayReasoningItem } from "./reasoning-replay.mjs";
|
|
2
2
|
import { stringifyContent, toImageUrl } from "./to-openai-messages.mjs";
|
|
3
|
-
import { InvalidRequestError } from "@warlock.js/ai";
|
|
3
|
+
import { InvalidRequestError, toolResultText } from "@warlock.js/ai";
|
|
4
4
|
|
|
5
5
|
//#region ../../packages/ai-openai/src/utils/to-responses-input.ts
|
|
6
6
|
/**
|
|
@@ -35,7 +35,7 @@ import { InvalidRequestError } from "@warlock.js/ai";
|
|
|
35
35
|
* ]);
|
|
36
36
|
* // { instructions: "Be brief.", input: [{ role: "user", content: "Hi" }] }
|
|
37
37
|
*/
|
|
38
|
-
function toResponsesInput(messages, model) {
|
|
38
|
+
function toResponsesInput(messages, model, toolImages = false) {
|
|
39
39
|
const input = [];
|
|
40
40
|
let instructions;
|
|
41
41
|
let instructionsTaken = false;
|
|
@@ -57,7 +57,7 @@ function toResponsesInput(messages, model) {
|
|
|
57
57
|
input.push({
|
|
58
58
|
type: "function_call_output",
|
|
59
59
|
call_id: message.toolCallId ?? "",
|
|
60
|
-
output:
|
|
60
|
+
output: toToolOutput(message.content, toolImages)
|
|
61
61
|
});
|
|
62
62
|
continue;
|
|
63
63
|
}
|
|
@@ -93,6 +93,27 @@ function toResponsesInput(messages, model) {
|
|
|
93
93
|
input
|
|
94
94
|
};
|
|
95
95
|
}
|
|
96
|
+
/**
|
|
97
|
+
* A `function_call_output` value: the string, or (when the model reads tool
|
|
98
|
+
* images) an array of `input_text` / `input_image` items. Otherwise images
|
|
99
|
+
* degrade to the placeholder text.
|
|
100
|
+
*/
|
|
101
|
+
function toToolOutput(content, toolImages) {
|
|
102
|
+
if (typeof content === "string") return content;
|
|
103
|
+
if (!toolImages) return toolResultText(content);
|
|
104
|
+
return content.flatMap((part) => {
|
|
105
|
+
if (part.type === "text") return [{
|
|
106
|
+
type: "input_text",
|
|
107
|
+
text: part.text
|
|
108
|
+
}];
|
|
109
|
+
if (part.type === "image") return [{
|
|
110
|
+
type: "input_image",
|
|
111
|
+
image_url: toImageUrl(part.source),
|
|
112
|
+
detail: "auto"
|
|
113
|
+
}];
|
|
114
|
+
return [];
|
|
115
|
+
});
|
|
116
|
+
}
|
|
96
117
|
/** Map a resolved `ContentPart` to a Responses input content part (text and images only). */
|
|
97
118
|
function toResponsesContentPart(part) {
|
|
98
119
|
if (part.type === "text") return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"to-responses-input.mjs","names":[],"sources":["../../../../../../../../packages/ai-openai/src/utils/to-responses-input.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"to-responses-input.mjs","names":[],"sources":["../../../../../../../../packages/ai-openai/src/utils/to-responses-input.ts"],"sourcesContent":["import {\n InvalidRequestError,\n toolResultText,\n type ContentPart,\n type Message,\n} from \"@warlock.js/ai\";\nimport type OpenAI from \"openai\";\nimport { stringifyContent, toImageUrl } from \"./to-openai-messages\";\nimport { readReasoningReplay, toReplayReasoningItem } from \"./reasoning-replay\";\n\n/** One item of the Responses `input` array. */\nexport type ResponsesInputItem = OpenAI.Responses.ResponseInputItem;\n\n/** What `toResponsesInput` produces: the `instructions` string plus the `input` items. */\nexport type ResponsesInputPlan = {\n /** The system prompt, sent as the top-level `instructions` field. */\n instructions?: string;\n input: ResponsesInputItem[];\n};\n\n/**\n * Convert vendor-neutral `Message[]` into the Responses request pieces.\n *\n * - The FIRST system message becomes `instructions` (decision 9: it avoids\n * the `system` vs `developer` role question on reasoning models). Any\n * later system message stays inline as a `system` role item.\n * - `user` / `assistant` text becomes an `EasyInputMessage` (`{ role,\n * content }`). Multipart user content becomes `input_text` / `input_image`\n * parts; images always carry `detail: \"auto\"` because `ResponseInputImage.detail`\n * is required by the SDK types.\n * - An assistant message that requested tools becomes its text (when\n * non-empty) followed by one top-level `function_call` item per call; our\n * `ModelToolCallRequest.id` is the wire `call_id`. No item `id` is sent:\n * with `store: false` nothing was persisted for it to refer to.\n * - When `model` is given, reasoning items stored on the turn's tool calls\n * (`providerMetadata.openaiResponses`, see `reasoning-replay.ts`) are\n * emitted BEFORE the turn's text and `function_call` items (the order the\n * API produced them), only if they were produced by that same model.\n * Without `model` nothing is replayed.\n * - A `tool` message becomes a top-level `function_call_output` item.\n *\n * PDF and audio parts are rejected with a typed `InvalidRequestError`: the\n * Responses adapter declares those capabilities off, so they only arrive\n * here if a caller bypasses the agent's capability gate.\n *\n * @example\n * toResponsesInput([\n * { role: \"system\", content: \"Be brief.\" },\n * { role: \"user\", content: \"Hi\" },\n * ]);\n * // { instructions: \"Be brief.\", input: [{ role: \"user\", content: \"Hi\" }] }\n */\nexport function toResponsesInput(\n messages: Message[],\n model?: string,\n toolImages = false,\n): ResponsesInputPlan {\n const input: ResponsesInputItem[] = [];\n let instructions: string | undefined;\n let instructionsTaken = false;\n\n for (const message of messages) {\n if (message.role === \"system\") {\n const text = stringifyContent(message.content);\n\n if (!instructionsTaken) {\n instructionsTaken = true;\n instructions = text === \"\" ? undefined : text;\n continue;\n }\n\n input.push({ role: \"system\", content: text });\n continue;\n }\n\n if (message.role === \"tool\") {\n input.push({\n type: \"function_call_output\",\n call_id: message.toolCallId ?? \"\",\n output: toToolOutput(message.content, toolImages),\n });\n continue;\n }\n\n if (message.role === \"assistant\" && message.toolCalls && message.toolCalls.length > 0) {\n const text = stringifyContent(message.content);\n\n if (model !== undefined) {\n for (const item of readReasoningReplay(message.toolCalls, model)) {\n input.push(toReplayReasoningItem(item));\n }\n }\n\n if (text !== \"\") {\n input.push({ role: \"assistant\", content: text });\n }\n\n for (const call of message.toolCalls) {\n input.push({\n type: \"function_call\",\n call_id: call.id,\n name: call.name,\n arguments: JSON.stringify(call.input ?? {}),\n });\n }\n\n continue;\n }\n\n if (message.role === \"user\" && Array.isArray(message.content)) {\n input.push({ role: \"user\", content: message.content.map(toResponsesContentPart) });\n continue;\n }\n\n input.push({ role: message.role, content: stringifyContent(message.content) });\n }\n\n return { ...(instructions !== undefined ? { instructions } : {}), input };\n}\n\n/**\n * A `function_call_output` value: the string, or (when the model reads tool\n * images) an array of `input_text` / `input_image` items. Otherwise images\n * degrade to the placeholder text.\n */\nfunction toToolOutput(\n content: string | ContentPart[],\n toolImages: boolean,\n): string | Array<OpenAI.Responses.ResponseInputText | OpenAI.Responses.ResponseInputImage> {\n if (typeof content === \"string\") return content;\n\n if (!toolImages) return toolResultText(content);\n\n return content.flatMap(\n (part): Array<OpenAI.Responses.ResponseInputText | OpenAI.Responses.ResponseInputImage> => {\n if (part.type === \"text\") return [{ type: \"input_text\" as const, text: part.text }];\n\n if (part.type === \"image\") {\n return [\n {\n type: \"input_image\" as const,\n image_url: toImageUrl(part.source),\n detail: \"auto\" as const,\n },\n ];\n }\n\n return [];\n },\n );\n}\n\n/** Map a resolved `ContentPart` to a Responses input content part (text and images only). */\nfunction toResponsesContentPart(\n part: ContentPart,\n): OpenAI.Responses.ResponseInputText | OpenAI.Responses.ResponseInputImage {\n if (part.type === \"text\") {\n return { type: \"input_text\", text: part.text };\n }\n\n if (part.type === \"image\") {\n return { type: \"input_image\", image_url: toImageUrl(part.source), detail: \"auto\" };\n }\n\n throw new InvalidRequestError(\n `OpenAI api: \"responses\" does not accept ${part.type} input in this adapter; use api: \"chat\" for ${part.type} attachments.`,\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoDA,SAAgB,iBACd,UACA,OACA,aAAa,OACO;CACpB,MAAM,QAA8B,CAAC;CACrC,IAAI;CACJ,IAAI,oBAAoB;CAExB,KAAK,MAAM,WAAW,UAAU;EAC9B,IAAI,QAAQ,SAAS,UAAU;GAC7B,MAAM,OAAO,iBAAiB,QAAQ,OAAO;GAE7C,IAAI,CAAC,mBAAmB;IACtB,oBAAoB;IACpB,eAAe,SAAS,KAAK,SAAY;IACzC;GACF;GAEA,MAAM,KAAK;IAAE,MAAM;IAAU,SAAS;GAAK,CAAC;GAC5C;EACF;EAEA,IAAI,QAAQ,SAAS,QAAQ;GAC3B,MAAM,KAAK;IACT,MAAM;IACN,SAAS,QAAQ,cAAc;IAC/B,QAAQ,aAAa,QAAQ,SAAS,UAAU;GAClD,CAAC;GACD;EACF;EAEA,IAAI,QAAQ,SAAS,eAAe,QAAQ,aAAa,QAAQ,UAAU,SAAS,GAAG;GACrF,MAAM,OAAO,iBAAiB,QAAQ,OAAO;GAE7C,IAAI,UAAU,QACZ,KAAK,MAAM,QAAQ,oBAAoB,QAAQ,WAAW,KAAK,GAC7D,MAAM,KAAK,sBAAsB,IAAI,CAAC;GAI1C,IAAI,SAAS,IACX,MAAM,KAAK;IAAE,MAAM;IAAa,SAAS;GAAK,CAAC;GAGjD,KAAK,MAAM,QAAQ,QAAQ,WACzB,MAAM,KAAK;IACT,MAAM;IACN,SAAS,KAAK;IACd,MAAM,KAAK;IACX,WAAW,KAAK,UAAU,KAAK,SAAS,CAAC,CAAC;GAC5C,CAAC;GAGH;EACF;EAEA,IAAI,QAAQ,SAAS,UAAU,MAAM,QAAQ,QAAQ,OAAO,GAAG;GAC7D,MAAM,KAAK;IAAE,MAAM;IAAQ,SAAS,QAAQ,QAAQ,IAAI,sBAAsB;GAAE,CAAC;GACjF;EACF;EAEA,MAAM,KAAK;GAAE,MAAM,QAAQ;GAAM,SAAS,iBAAiB,QAAQ,OAAO;EAAE,CAAC;CAC/E;CAEA,OAAO;EAAE,GAAI,iBAAiB,SAAY,EAAE,aAAa,IAAI,CAAC;EAAI;CAAM;AAC1E;;;;;;AAOA,SAAS,aACP,SACA,YAC0F;CAC1F,IAAI,OAAO,YAAY,UAAU,OAAO;CAExC,IAAI,CAAC,YAAY,OAAO,eAAe,OAAO;CAE9C,OAAO,QAAQ,SACZ,SAA0F;EACzF,IAAI,KAAK,SAAS,QAAQ,OAAO,CAAC;GAAE,MAAM;GAAuB,MAAM,KAAK;EAAK,CAAC;EAElF,IAAI,KAAK,SAAS,SAChB,OAAO,CACL;GACE,MAAM;GACN,WAAW,WAAW,KAAK,MAAM;GACjC,QAAQ;EACV,CACF;EAGF,OAAO,CAAC;CACV,CACF;AACF;;AAGA,SAAS,uBACP,MAC0E;CAC1E,IAAI,KAAK,SAAS,QAChB,OAAO;EAAE,MAAM;EAAc,MAAM,KAAK;CAAK;CAG/C,IAAI,KAAK,SAAS,SAChB,OAAO;EAAE,MAAM;EAAe,WAAW,WAAW,KAAK,MAAM;EAAG,QAAQ;CAAO;CAGnF,MAAM,IAAI,oBACR,2CAA2C,KAAK,KAAK,8CAA8C,KAAK,KAAK,cAC/G;AACF"}
|
package/llms-full.txt
CHANGED
|
@@ -225,7 +225,7 @@ const model = openai.model({
|
|
|
225
225
|
});
|
|
226
226
|
```
|
|
227
227
|
|
|
228
|
-
`promptCacheKey` improves matching for related requests. `promptCacheRetention` is OpenAI's maximum policy (`"in_memory" | "24h"`). `cacheControl.breakpoints` maps to `prompt_cache_breakpoint: { mode: "explicit" }` on the final user content parts (up to OpenAI's four-request limit); use it when you need to pin a reusable prefix rather than rely only on OpenAI's implicit breakpoint.
|
|
228
|
+
`promptCacheKey` improves matching for related requests. A per-call `cacheControl: { key }` is sent as `prompt_cache_key` instead and wins over the model value, so one model can serve several cache groups (for example one key per agent). `promptCacheRetention` is OpenAI's maximum policy (`"in_memory" | "24h"`). `cacheControl.breakpoints` maps to `prompt_cache_breakpoint: { mode: "explicit" }` on the final user content parts (up to OpenAI's four-request limit); use it when you need to pin a reusable prefix rather than rely only on OpenAI's implicit breakpoint.
|
|
229
229
|
|
|
230
230
|
Which fields reach the wire depends on the SDK provider label:
|
|
231
231
|
|
|
@@ -461,4 +461,8 @@ On the direct `"openai"` provider a call carrying the hosted `web_search` tool i
|
|
|
461
461
|
|
|
462
462
|
`await openai.models()` returns `ModelInfo[]` from `GET /models` (also on compatible gateways, with the SDK's provider label); `kind` is classified from the id.
|
|
463
463
|
|
|
464
|
+
## Context window
|
|
465
|
+
|
|
466
|
+
The direct OpenAI provider reports `capabilities.contextWindow` for the gpt-3.5/4/4o/4.1/5.x/6 and o-series ids (400K for gpt-5.x and gpt-6, conservative); `openai.model({ name, contextWindow })` wins and is the only source for OpenAI-compatible endpoints.
|
|
467
|
+
|
|
464
468
|
|
package/package.json
CHANGED
|
@@ -15,12 +15,12 @@
|
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"openai": "^7.23.0",
|
|
18
|
-
"@warlock.js/logger": "5.
|
|
18
|
+
"@warlock.js/logger": "5.45.0"
|
|
19
19
|
},
|
|
20
20
|
"peerDependencies": {
|
|
21
|
-
"@warlock.js/ai": "5.
|
|
21
|
+
"@warlock.js/ai": "5.45.0"
|
|
22
22
|
},
|
|
23
|
-
"version": "5.
|
|
23
|
+
"version": "5.45.0",
|
|
24
24
|
"main": "./cjs/index.cjs",
|
|
25
25
|
"module": "./esm/index.mjs",
|
|
26
26
|
"types": "./esm/index.d.mts",
|
package/skills/SKILL.md
CHANGED
|
@@ -217,7 +217,7 @@ const model = openai.model({
|
|
|
217
217
|
});
|
|
218
218
|
```
|
|
219
219
|
|
|
220
|
-
`promptCacheKey` improves matching for related requests. `promptCacheRetention` is OpenAI's maximum policy (`"in_memory" | "24h"`). `cacheControl.breakpoints` maps to `prompt_cache_breakpoint: { mode: "explicit" }` on the final user content parts (up to OpenAI's four-request limit); use it when you need to pin a reusable prefix rather than rely only on OpenAI's implicit breakpoint.
|
|
220
|
+
`promptCacheKey` improves matching for related requests. A per-call `cacheControl: { key }` is sent as `prompt_cache_key` instead and wins over the model value, so one model can serve several cache groups (for example one key per agent). `promptCacheRetention` is OpenAI's maximum policy (`"in_memory" | "24h"`). `cacheControl.breakpoints` maps to `prompt_cache_breakpoint: { mode: "explicit" }` on the final user content parts (up to OpenAI's four-request limit); use it when you need to pin a reusable prefix rather than rely only on OpenAI's implicit breakpoint.
|
|
221
221
|
|
|
222
222
|
Which fields reach the wire depends on the SDK provider label:
|
|
223
223
|
|
|
@@ -452,3 +452,7 @@ On the direct `"openai"` provider a call carrying the hosted `web_search` tool i
|
|
|
452
452
|
## List models
|
|
453
453
|
|
|
454
454
|
`await openai.models()` returns `ModelInfo[]` from `GET /models` (also on compatible gateways, with the SDK's provider label); `kind` is classified from the id.
|
|
455
|
+
|
|
456
|
+
## Context window
|
|
457
|
+
|
|
458
|
+
The direct OpenAI provider reports `capabilities.contextWindow` for the gpt-3.5/4/4o/4.1/5.x/6 and o-series ids (400K for gpt-5.x and gpt-6, conservative); `openai.model({ name, contextWindow })` wins and is the only source for OpenAI-compatible endpoints.
|