@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.
|
@@ -26,6 +26,12 @@ export declare class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
26
26
|
responseToHistoryItems(response: unknown): LlmHistory;
|
|
27
27
|
classifyError(error: unknown): ClassifiedError;
|
|
28
28
|
isComplete(response: unknown): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Sanitize history items for the OpenAI Responses API.
|
|
31
|
+
* Strips fields not accepted by specific item types (e.g., `name` on
|
|
32
|
+
* function_call_output items) to prevent 400 "Unknown parameter" errors.
|
|
33
|
+
*/
|
|
34
|
+
private sanitizeInputItems;
|
|
29
35
|
private hasToolCalls;
|
|
30
36
|
private extractContent;
|
|
31
37
|
}
|
package/dist/esm/index.js
CHANGED
|
@@ -2227,7 +2227,7 @@ class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
2227
2227
|
const model = request.model || this.defaultModel;
|
|
2228
2228
|
const openaiRequest = {
|
|
2229
2229
|
model,
|
|
2230
|
-
input: request.messages,
|
|
2230
|
+
input: this.sanitizeInputItems(request.messages),
|
|
2231
2231
|
};
|
|
2232
2232
|
if (request.user) {
|
|
2233
2233
|
openaiRequest.user = request.user;
|
|
@@ -2312,8 +2312,9 @@ class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
2312
2312
|
async executeRequest(client, request, signal) {
|
|
2313
2313
|
const openai = client;
|
|
2314
2314
|
try {
|
|
2315
|
+
return await openai.responses.create(
|
|
2315
2316
|
// @ts-expect-error OpenAI SDK types don't match our request format exactly
|
|
2316
|
-
|
|
2317
|
+
request, signal ? { signal } : undefined);
|
|
2317
2318
|
}
|
|
2318
2319
|
catch (error) {
|
|
2319
2320
|
if (signal?.aborted)
|
|
@@ -2575,6 +2576,31 @@ class OpenAiAdapter extends BaseProviderAdapter {
|
|
|
2575
2576
|
//
|
|
2576
2577
|
// Private Helpers
|
|
2577
2578
|
//
|
|
2579
|
+
/**
|
|
2580
|
+
* Sanitize history items for the OpenAI Responses API.
|
|
2581
|
+
* Strips fields not accepted by specific item types (e.g., `name` on
|
|
2582
|
+
* function_call_output items) to prevent 400 "Unknown parameter" errors.
|
|
2583
|
+
*/
|
|
2584
|
+
sanitizeInputItems(messages) {
|
|
2585
|
+
return messages.map((item) => {
|
|
2586
|
+
const typedItem = item;
|
|
2587
|
+
// function_call_output only accepts: type, call_id, output, id, status
|
|
2588
|
+
if (typedItem.type === LlmMessageType.FunctionCallOutput) {
|
|
2589
|
+
const sanitized = {
|
|
2590
|
+
type: typedItem.type,
|
|
2591
|
+
call_id: typedItem.call_id,
|
|
2592
|
+
output: typedItem.output,
|
|
2593
|
+
};
|
|
2594
|
+
if (typedItem.id)
|
|
2595
|
+
sanitized.id = typedItem.id;
|
|
2596
|
+
if (typedItem.status)
|
|
2597
|
+
sanitized.status = typedItem.status;
|
|
2598
|
+
return sanitized;
|
|
2599
|
+
}
|
|
2600
|
+
// All other items pass through as-is
|
|
2601
|
+
return item;
|
|
2602
|
+
});
|
|
2603
|
+
}
|
|
2578
2604
|
hasToolCalls(response) {
|
|
2579
2605
|
if (!response.output || !Array.isArray(response.output)) {
|
|
2580
2606
|
return false;
|