@jaypie/llm 1.2.17 → 1.2.19
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/dist/cjs/index.cjs
CHANGED
|
@@ -2229,7 +2229,7 @@ class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
2229
2229
|
const model = request.model || this.defaultModel;
|
|
2230
2230
|
const openaiRequest = {
|
|
2231
2231
|
model,
|
|
2232
|
-
input: request.messages,
|
|
2232
|
+
input: this.sanitizeInputItems(request.messages),
|
|
2233
2233
|
};
|
|
2234
2234
|
if (request.user) {
|
|
2235
2235
|
openaiRequest.user = request.user;
|
|
@@ -2314,8 +2314,9 @@ class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
2314
2314
|
async executeRequest(client, request, signal) {
|
|
2315
2315
|
const openai = client;
|
|
2316
2316
|
try {
|
|
2317
|
+
return await openai.responses.create(
|
|
2317
2318
|
// @ts-expect-error OpenAI SDK types don't match our request format exactly
|
|
2318
|
-
|
|
2319
|
+
request, signal ? { signal } : undefined);
|
|
2319
2320
|
}
|
|
2320
2321
|
catch (error) {
|
|
2321
2322
|
if (signal?.aborted)
|
|
@@ -2577,6 +2578,31 @@ class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
2577
2578
|
//
|
|
2578
2579
|
// Private Helpers
|
|
2579
2580
|
//
|
|
2581
|
+
/**
|
|
2582
|
+
* Sanitize history items for the OpenAI Responses API.
|
|
2583
|
+
* Strips fields not accepted by specific item types (e.g., `name` on
|
|
2584
|
+
* function_call_output items) to prevent 400 "Unknown parameter" errors.
|
|
2585
|
+
*/
|
|
2586
|
+
sanitizeInputItems(messages) {
|
|
2587
|
+
return messages.map((item) => {
|
|
2588
|
+
const typedItem = item;
|
|
2589
|
+
// function_call_output only accepts: type, call_id, output, id, status
|
|
2590
|
+
if (typedItem.type === exports.LlmMessageType.FunctionCallOutput) {
|
|
2591
|
+
const sanitized = {
|
|
2592
|
+
type: typedItem.type,
|
|
2593
|
+
call_id: typedItem.call_id,
|
|
2594
|
+
output: typedItem.output,
|
|
2595
|
+
};
|
|
2596
|
+
if (typedItem.id)
|
|
2597
|
+
sanitized.id = typedItem.id;
|
|
2598
|
+
if (typedItem.status)
|
|
2599
|
+
sanitized.status = typedItem.status;
|
|
2600
|
+
return sanitized;
|
|
2601
|
+
}
|
|
2602
|
+
// All other items pass through as-is
|
|
2603
|
+
return item;
|
|
2604
|
+
});
|
|
2605
|
+
}
|
|
2580
2606
|
hasToolCalls(response) {
|
|
2581
2607
|
if (!response.output || !Array.isArray(response.output)) {
|
|
2582
2608
|
return false;
|