@jeffusion/bungee-llms 6.10.0 → 6.11.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/dist/index.js +69 -11
- package/dist/plugin-api.js +69 -11
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -3930,8 +3930,9 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3930
3930
|
if (typeof rawContent === "string")
|
|
3931
3931
|
return rawContent;
|
|
3932
3932
|
const parts = list(rawContent, "message content");
|
|
3933
|
-
for (const [index, rawPart] of parts.entries())
|
|
3934
|
-
|
|
3933
|
+
for (const [index, rawPart] of parts.entries()) {
|
|
3934
|
+
const partPath = `${path}[${index}]`;
|
|
3935
|
+
atParam(partPath, () => {
|
|
3935
3936
|
const part = record(rawPart, "content part");
|
|
3936
3937
|
if (part.type === "input_text" || part.type === "output_text" || part.type === "text")
|
|
3937
3938
|
string(part.text, "content text");
|
|
@@ -3939,17 +3940,21 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3939
3940
|
string(part.refusal, "refusal");
|
|
3940
3941
|
if (capabilities.preserveRefusalContent && protocol !== "chat_completions")
|
|
3941
3942
|
fail("unsupported_content", "Target protocol cannot preserve refusal history authority");
|
|
3942
|
-
} else if (part.type === "input_image" && (role === "user" || role === "tool"
|
|
3943
|
+
} else if (part.type === "input_image" && (role === "user" || role === "tool")) {
|
|
3943
3944
|
if (protocol !== "chat_completions")
|
|
3944
3945
|
fail("unsupported_content", "Anthropic image conversion requires provider-specific URL/data support");
|
|
3946
|
+
for (const key of Object.keys(part))
|
|
3947
|
+
if (!["type", "image_url", "detail"].includes(key))
|
|
3948
|
+
fail("unsupported_content", "Unsupported image field", `${partPath}.${key}`);
|
|
3945
3949
|
string(part.image_url, "image_url", true);
|
|
3946
|
-
if (part.detail !== undefined && !["auto", "low", "high"].includes(
|
|
3947
|
-
fail("unsupported_content", "Unknown image detail",
|
|
3950
|
+
if (part.detail !== undefined && (typeof part.detail !== "string" || !["auto", "low", "high"].includes(part.detail)))
|
|
3951
|
+
fail("unsupported_content", "Unknown image detail", `${partPath}.detail`);
|
|
3948
3952
|
} else
|
|
3949
3953
|
fail("unsupported_content", "Unsupported message content type");
|
|
3950
3954
|
if (part.annotations !== undefined && list(part.annotations, "annotations").length)
|
|
3951
3955
|
fail("unsupported_content", "Output annotations cannot be represented in input history");
|
|
3952
3956
|
});
|
|
3957
|
+
}
|
|
3953
3958
|
const normalized = contentNormalizer.normalizeResponsesMessageContent(parts.map((raw) => {
|
|
3954
3959
|
const part = raw;
|
|
3955
3960
|
return part.type === "refusal" ? { type: "output_text", text: part.refusal } : part;
|
|
@@ -3963,11 +3968,23 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3963
3968
|
}
|
|
3964
3969
|
return normalized;
|
|
3965
3970
|
};
|
|
3971
|
+
const appendAssistantContent = (previous, next) => {
|
|
3972
|
+
if (previous == null)
|
|
3973
|
+
return next;
|
|
3974
|
+
if (next == null)
|
|
3975
|
+
return previous;
|
|
3976
|
+
if (typeof previous === "string" && typeof next === "string")
|
|
3977
|
+
return previous + next;
|
|
3978
|
+
const parts = (value) => typeof value === "string" ? [{ type: "text", text: value }] : Array.isArray(value) ? value : [value];
|
|
3979
|
+
return [...parts(previous), ...parts(next)];
|
|
3980
|
+
};
|
|
3966
3981
|
const chat = [];
|
|
3967
3982
|
const messageParams = new WeakMap;
|
|
3968
3983
|
let messageParam = "instructions";
|
|
3969
3984
|
const callIds = new Set;
|
|
3985
|
+
const callToolNames = new Map;
|
|
3970
3986
|
const answered = new Set;
|
|
3987
|
+
const projectedToolImages = [];
|
|
3971
3988
|
let pendingReasoning = "";
|
|
3972
3989
|
const addMessage = (message) => {
|
|
3973
3990
|
if (chat.length >= budget.maxItems)
|
|
@@ -3975,12 +3992,21 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3975
3992
|
chat.push(message);
|
|
3976
3993
|
messageParams.set(message, messageParam);
|
|
3977
3994
|
};
|
|
3995
|
+
const flushToolImages = (force = false) => {
|
|
3996
|
+
if (!force && [...callIds].some((id) => !answered.has(id)))
|
|
3997
|
+
return;
|
|
3998
|
+
for (const { callId, name, images } of projectedToolImages)
|
|
3999
|
+
addMessage({ role: "user", content: [{ type: "text", text: `Images returned by tool ${JSON.stringify(name)} (call ${JSON.stringify(callId)}):` }, ...images] });
|
|
4000
|
+
projectedToolImages.length = 0;
|
|
4001
|
+
};
|
|
3978
4002
|
if (body.instructions !== undefined)
|
|
3979
4003
|
addMessage({ role: "system", content: string(body.instructions, "instructions") });
|
|
3980
4004
|
for (const [inputIndex, rawItem] of input.entries())
|
|
3981
4005
|
atParam(`input[${inputIndex}]`, () => {
|
|
3982
4006
|
messageParam = `input[${inputIndex}]`;
|
|
3983
4007
|
const item = record(rawItem, "input item");
|
|
4008
|
+
if (item.type !== "function_call_output" && item.type !== "custom_tool_call_output")
|
|
4009
|
+
flushToolImages();
|
|
3984
4010
|
if (item.type === "additional_tools")
|
|
3985
4011
|
return;
|
|
3986
4012
|
if (item.type === "agent_message") {
|
|
@@ -4029,11 +4055,12 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
4029
4055
|
bounded(args, budget.maxArgumentBytes, "arguments");
|
|
4030
4056
|
argumentObject(args);
|
|
4031
4057
|
const call = { id, type: "function", function: { name: resolve(item, custom), arguments: args } };
|
|
4058
|
+
callToolNames.set(id, String(item.name));
|
|
4032
4059
|
const previous = chat.at(-1);
|
|
4033
4060
|
if (previous?.role === "assistant" && !options.preserveContentOrder) {
|
|
4034
4061
|
previous.tool_calls = [...previous.tool_calls ?? [], call];
|
|
4035
4062
|
if (pendingReasoning)
|
|
4036
|
-
previous.reasoning_content = pendingReasoning
|
|
4063
|
+
previous.reasoning_content = previous.reasoning_content === undefined ? pendingReasoning : `${previous.reasoning_content}${pendingReasoning}`;
|
|
4037
4064
|
} else
|
|
4038
4065
|
addMessage({ role: "assistant", content: null, tool_calls: [call], ...pendingReasoning ? { reasoning_content: pendingReasoning } : {} });
|
|
4039
4066
|
pendingReasoning = "";
|
|
@@ -4044,7 +4071,21 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
4044
4071
|
if (!callIds.has(id) || answered.has(id))
|
|
4045
4072
|
fail("invalid_tool_history", "Unmatched or duplicate tool result");
|
|
4046
4073
|
answered.add(id);
|
|
4047
|
-
|
|
4074
|
+
if (Array.isArray(item.output) && item.output.length > budget.maxItems && item.output.some((part) => part && typeof part === "object" && part.type === "input_image"))
|
|
4075
|
+
fail("resource_limit", "Too many tool output content parts", `${messageParam}.output`);
|
|
4076
|
+
let output = typeof item.output === "string" ? item.output : normalizeContent(item.output, "tool", `${messageParam}.output`);
|
|
4077
|
+
if (protocol === "chat_completions" && !options.toolOutputImages && Array.isArray(output)) {
|
|
4078
|
+
const images = output.filter((part) => part.type === "image_url");
|
|
4079
|
+
if (images.length) {
|
|
4080
|
+
output.forEach((part, index) => {
|
|
4081
|
+
if (part.type === "image_url")
|
|
4082
|
+
diagnostics.push({ param: `${messageParam}.output[${index}]`, action: "mapped", reason: "chat_tool_image_projected_to_user_message" });
|
|
4083
|
+
});
|
|
4084
|
+
const text = output.filter((part) => part.type !== "image_url");
|
|
4085
|
+
projectedToolImages.push({ callId: id, name: callToolNames.get(id) ?? id, images });
|
|
4086
|
+
output = text.length ? text : "Tool output contained only images; see the following images.";
|
|
4087
|
+
}
|
|
4088
|
+
}
|
|
4048
4089
|
addMessage({ role: "tool", tool_call_id: id, content: output, ...item.is_error === true ? { is_error: true } : {} });
|
|
4049
4090
|
return;
|
|
4050
4091
|
}
|
|
@@ -4053,7 +4094,7 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
4053
4094
|
const role = string(item.role, "message role", true);
|
|
4054
4095
|
if (!["user", "assistant", "system", "developer"].includes(role))
|
|
4055
4096
|
fail("unsupported_content", "Unknown message role");
|
|
4056
|
-
const message = { role, content: normalizeContent(item.content, role) };
|
|
4097
|
+
const message = { role, content: normalizeContent(item.content, role, `${messageParam}.content`) };
|
|
4057
4098
|
if (options.preserveContentOrder && item.id !== undefined)
|
|
4058
4099
|
message.id = string(item.id, "item.id", true);
|
|
4059
4100
|
if (pendingReasoning) {
|
|
@@ -4062,10 +4103,20 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
4062
4103
|
message.reasoning_content = pendingReasoning;
|
|
4063
4104
|
pendingReasoning = "";
|
|
4064
4105
|
}
|
|
4106
|
+
if (protocol === "chat_completions" && !options.preserveContentOrder && role === "assistant") {
|
|
4107
|
+
const previous = chat.at(-1);
|
|
4108
|
+
if (previous?.role === "assistant") {
|
|
4109
|
+
previous.content = appendAssistantContent(previous.content, message.content);
|
|
4110
|
+
if (message.reasoning_content !== undefined)
|
|
4111
|
+
previous.reasoning_content = previous.reasoning_content === undefined ? message.reasoning_content : `${previous.reasoning_content}${message.reasoning_content}`;
|
|
4112
|
+
return;
|
|
4113
|
+
}
|
|
4114
|
+
}
|
|
4065
4115
|
addMessage(message);
|
|
4066
4116
|
});
|
|
4067
4117
|
if (pendingReasoning)
|
|
4068
4118
|
fail("unsupported_reasoning", "Orphan reasoning history cannot be represented");
|
|
4119
|
+
flushToolImages(true);
|
|
4069
4120
|
const result = { model, messages: chat };
|
|
4070
4121
|
const omittedAllTools = !tools.length && diagnostics.some((item) => item.reason === "optional_hosted_web_search_unavailable");
|
|
4071
4122
|
for (const key of ["stream", "temperature", "top_p", "parallel_tool_calls", "metadata"])
|
|
@@ -5570,14 +5621,21 @@ function validateProviderResponse(raw, protocol) {
|
|
|
5570
5621
|
fields2(b, ["id", "object", "created", "model", "choices", "usage", "system_fingerprint", "service_tier"], "", "unsupported_response");
|
|
5571
5622
|
for (const rawChoice of list(b.choices, "choices")) {
|
|
5572
5623
|
const c = record(rawChoice, "choice");
|
|
5573
|
-
fields2(c, ["index", "message", "finish_reason", "logprobs"], "choices", "unsupported_response");
|
|
5624
|
+
fields2(c, ["index", "message", "finish_reason", "logprobs", "provider_specific_fields"], "choices", "unsupported_response");
|
|
5625
|
+
if (c.provider_specific_fields !== undefined) {
|
|
5626
|
+
const providerFields = c.provider_specific_fields;
|
|
5627
|
+
if (providerFields === null || typeof providerFields !== "object" || Array.isArray(providerFields) || Object.keys(providerFields).length)
|
|
5628
|
+
fail("unsupported_response", "Only empty provider-specific choice fields are portable", "choices.provider_specific_fields");
|
|
5629
|
+
}
|
|
5574
5630
|
if (c.logprobs != null)
|
|
5575
5631
|
fail("unsupported_response", "Log probabilities cannot cross protocols", "choices.logprobs");
|
|
5576
5632
|
const m = record(c.message, "message");
|
|
5577
5633
|
fields2(m, ["role", "content", "refusal", "reasoning_content", "reasoning", "tool_calls", "annotations"], "message", "unsupported_content");
|
|
5578
|
-
for (const rawCall of m.tool_calls === undefined ? [] : list(m.tool_calls, "tool_calls")) {
|
|
5634
|
+
for (const [callIndex, rawCall] of (m.tool_calls === undefined ? [] : list(m.tool_calls, "tool_calls")).entries()) {
|
|
5579
5635
|
const call = record(rawCall, "call");
|
|
5580
|
-
fields2(call, ["id", "type", "function"], "tool_calls", "unsupported_tool");
|
|
5636
|
+
fields2(call, ["id", "type", "function", "index"], "tool_calls", "unsupported_tool");
|
|
5637
|
+
if (call.index !== undefined && integer(call.index, `tool_calls[${callIndex}].index`) !== callIndex)
|
|
5638
|
+
fail("invalid_payload", "Tool call index must match its array position", `tool_calls[${callIndex}].index`);
|
|
5581
5639
|
fields2(record(call.function, "function"), ["name", "arguments"], "tool_calls.function", "unsupported_tool");
|
|
5582
5640
|
}
|
|
5583
5641
|
}
|
package/dist/plugin-api.js
CHANGED
|
@@ -2970,8 +2970,9 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
2970
2970
|
if (typeof rawContent === "string")
|
|
2971
2971
|
return rawContent;
|
|
2972
2972
|
const parts = list(rawContent, "message content");
|
|
2973
|
-
for (const [index, rawPart] of parts.entries())
|
|
2974
|
-
|
|
2973
|
+
for (const [index, rawPart] of parts.entries()) {
|
|
2974
|
+
const partPath = `${path}[${index}]`;
|
|
2975
|
+
atParam(partPath, () => {
|
|
2975
2976
|
const part = record(rawPart, "content part");
|
|
2976
2977
|
if (part.type === "input_text" || part.type === "output_text" || part.type === "text")
|
|
2977
2978
|
string(part.text, "content text");
|
|
@@ -2979,17 +2980,21 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
2979
2980
|
string(part.refusal, "refusal");
|
|
2980
2981
|
if (capabilities.preserveRefusalContent && protocol !== "chat_completions")
|
|
2981
2982
|
fail("unsupported_content", "Target protocol cannot preserve refusal history authority");
|
|
2982
|
-
} else if (part.type === "input_image" && (role === "user" || role === "tool"
|
|
2983
|
+
} else if (part.type === "input_image" && (role === "user" || role === "tool")) {
|
|
2983
2984
|
if (protocol !== "chat_completions")
|
|
2984
2985
|
fail("unsupported_content", "Anthropic image conversion requires provider-specific URL/data support");
|
|
2986
|
+
for (const key of Object.keys(part))
|
|
2987
|
+
if (!["type", "image_url", "detail"].includes(key))
|
|
2988
|
+
fail("unsupported_content", "Unsupported image field", `${partPath}.${key}`);
|
|
2985
2989
|
string(part.image_url, "image_url", true);
|
|
2986
|
-
if (part.detail !== undefined && !["auto", "low", "high"].includes(
|
|
2987
|
-
fail("unsupported_content", "Unknown image detail",
|
|
2990
|
+
if (part.detail !== undefined && (typeof part.detail !== "string" || !["auto", "low", "high"].includes(part.detail)))
|
|
2991
|
+
fail("unsupported_content", "Unknown image detail", `${partPath}.detail`);
|
|
2988
2992
|
} else
|
|
2989
2993
|
fail("unsupported_content", "Unsupported message content type");
|
|
2990
2994
|
if (part.annotations !== undefined && list(part.annotations, "annotations").length)
|
|
2991
2995
|
fail("unsupported_content", "Output annotations cannot be represented in input history");
|
|
2992
2996
|
});
|
|
2997
|
+
}
|
|
2993
2998
|
const normalized = contentNormalizer.normalizeResponsesMessageContent(parts.map((raw) => {
|
|
2994
2999
|
const part = raw;
|
|
2995
3000
|
return part.type === "refusal" ? { type: "output_text", text: part.refusal } : part;
|
|
@@ -3003,11 +3008,23 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3003
3008
|
}
|
|
3004
3009
|
return normalized;
|
|
3005
3010
|
};
|
|
3011
|
+
const appendAssistantContent = (previous, next) => {
|
|
3012
|
+
if (previous == null)
|
|
3013
|
+
return next;
|
|
3014
|
+
if (next == null)
|
|
3015
|
+
return previous;
|
|
3016
|
+
if (typeof previous === "string" && typeof next === "string")
|
|
3017
|
+
return previous + next;
|
|
3018
|
+
const parts = (value) => typeof value === "string" ? [{ type: "text", text: value }] : Array.isArray(value) ? value : [value];
|
|
3019
|
+
return [...parts(previous), ...parts(next)];
|
|
3020
|
+
};
|
|
3006
3021
|
const chat = [];
|
|
3007
3022
|
const messageParams = new WeakMap;
|
|
3008
3023
|
let messageParam = "instructions";
|
|
3009
3024
|
const callIds = new Set;
|
|
3025
|
+
const callToolNames = new Map;
|
|
3010
3026
|
const answered = new Set;
|
|
3027
|
+
const projectedToolImages = [];
|
|
3011
3028
|
let pendingReasoning = "";
|
|
3012
3029
|
const addMessage = (message) => {
|
|
3013
3030
|
if (chat.length >= budget.maxItems)
|
|
@@ -3015,12 +3032,21 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3015
3032
|
chat.push(message);
|
|
3016
3033
|
messageParams.set(message, messageParam);
|
|
3017
3034
|
};
|
|
3035
|
+
const flushToolImages = (force = false) => {
|
|
3036
|
+
if (!force && [...callIds].some((id) => !answered.has(id)))
|
|
3037
|
+
return;
|
|
3038
|
+
for (const { callId, name, images } of projectedToolImages)
|
|
3039
|
+
addMessage({ role: "user", content: [{ type: "text", text: `Images returned by tool ${JSON.stringify(name)} (call ${JSON.stringify(callId)}):` }, ...images] });
|
|
3040
|
+
projectedToolImages.length = 0;
|
|
3041
|
+
};
|
|
3018
3042
|
if (body.instructions !== undefined)
|
|
3019
3043
|
addMessage({ role: "system", content: string(body.instructions, "instructions") });
|
|
3020
3044
|
for (const [inputIndex, rawItem] of input.entries())
|
|
3021
3045
|
atParam(`input[${inputIndex}]`, () => {
|
|
3022
3046
|
messageParam = `input[${inputIndex}]`;
|
|
3023
3047
|
const item = record(rawItem, "input item");
|
|
3048
|
+
if (item.type !== "function_call_output" && item.type !== "custom_tool_call_output")
|
|
3049
|
+
flushToolImages();
|
|
3024
3050
|
if (item.type === "additional_tools")
|
|
3025
3051
|
return;
|
|
3026
3052
|
if (item.type === "agent_message") {
|
|
@@ -3069,11 +3095,12 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3069
3095
|
bounded(args, budget.maxArgumentBytes, "arguments");
|
|
3070
3096
|
argumentObject(args);
|
|
3071
3097
|
const call = { id, type: "function", function: { name: resolve(item, custom), arguments: args } };
|
|
3098
|
+
callToolNames.set(id, String(item.name));
|
|
3072
3099
|
const previous = chat.at(-1);
|
|
3073
3100
|
if (previous?.role === "assistant" && !options.preserveContentOrder) {
|
|
3074
3101
|
previous.tool_calls = [...previous.tool_calls ?? [], call];
|
|
3075
3102
|
if (pendingReasoning)
|
|
3076
|
-
previous.reasoning_content = pendingReasoning
|
|
3103
|
+
previous.reasoning_content = previous.reasoning_content === undefined ? pendingReasoning : `${previous.reasoning_content}${pendingReasoning}`;
|
|
3077
3104
|
} else
|
|
3078
3105
|
addMessage({ role: "assistant", content: null, tool_calls: [call], ...pendingReasoning ? { reasoning_content: pendingReasoning } : {} });
|
|
3079
3106
|
pendingReasoning = "";
|
|
@@ -3084,7 +3111,21 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3084
3111
|
if (!callIds.has(id) || answered.has(id))
|
|
3085
3112
|
fail("invalid_tool_history", "Unmatched or duplicate tool result");
|
|
3086
3113
|
answered.add(id);
|
|
3087
|
-
|
|
3114
|
+
if (Array.isArray(item.output) && item.output.length > budget.maxItems && item.output.some((part) => part && typeof part === "object" && part.type === "input_image"))
|
|
3115
|
+
fail("resource_limit", "Too many tool output content parts", `${messageParam}.output`);
|
|
3116
|
+
let output = typeof item.output === "string" ? item.output : normalizeContent(item.output, "tool", `${messageParam}.output`);
|
|
3117
|
+
if (protocol === "chat_completions" && !options.toolOutputImages && Array.isArray(output)) {
|
|
3118
|
+
const images = output.filter((part) => part.type === "image_url");
|
|
3119
|
+
if (images.length) {
|
|
3120
|
+
output.forEach((part, index) => {
|
|
3121
|
+
if (part.type === "image_url")
|
|
3122
|
+
diagnostics.push({ param: `${messageParam}.output[${index}]`, action: "mapped", reason: "chat_tool_image_projected_to_user_message" });
|
|
3123
|
+
});
|
|
3124
|
+
const text = output.filter((part) => part.type !== "image_url");
|
|
3125
|
+
projectedToolImages.push({ callId: id, name: callToolNames.get(id) ?? id, images });
|
|
3126
|
+
output = text.length ? text : "Tool output contained only images; see the following images.";
|
|
3127
|
+
}
|
|
3128
|
+
}
|
|
3088
3129
|
addMessage({ role: "tool", tool_call_id: id, content: output, ...item.is_error === true ? { is_error: true } : {} });
|
|
3089
3130
|
return;
|
|
3090
3131
|
}
|
|
@@ -3093,7 +3134,7 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3093
3134
|
const role = string(item.role, "message role", true);
|
|
3094
3135
|
if (!["user", "assistant", "system", "developer"].includes(role))
|
|
3095
3136
|
fail("unsupported_content", "Unknown message role");
|
|
3096
|
-
const message = { role, content: normalizeContent(item.content, role) };
|
|
3137
|
+
const message = { role, content: normalizeContent(item.content, role, `${messageParam}.content`) };
|
|
3097
3138
|
if (options.preserveContentOrder && item.id !== undefined)
|
|
3098
3139
|
message.id = string(item.id, "item.id", true);
|
|
3099
3140
|
if (pendingReasoning) {
|
|
@@ -3102,10 +3143,20 @@ function decodeResponsesRequest(raw, protocol, capabilities = {}, options = {})
|
|
|
3102
3143
|
message.reasoning_content = pendingReasoning;
|
|
3103
3144
|
pendingReasoning = "";
|
|
3104
3145
|
}
|
|
3146
|
+
if (protocol === "chat_completions" && !options.preserveContentOrder && role === "assistant") {
|
|
3147
|
+
const previous = chat.at(-1);
|
|
3148
|
+
if (previous?.role === "assistant") {
|
|
3149
|
+
previous.content = appendAssistantContent(previous.content, message.content);
|
|
3150
|
+
if (message.reasoning_content !== undefined)
|
|
3151
|
+
previous.reasoning_content = previous.reasoning_content === undefined ? message.reasoning_content : `${previous.reasoning_content}${message.reasoning_content}`;
|
|
3152
|
+
return;
|
|
3153
|
+
}
|
|
3154
|
+
}
|
|
3105
3155
|
addMessage(message);
|
|
3106
3156
|
});
|
|
3107
3157
|
if (pendingReasoning)
|
|
3108
3158
|
fail("unsupported_reasoning", "Orphan reasoning history cannot be represented");
|
|
3159
|
+
flushToolImages(true);
|
|
3109
3160
|
const result = { model, messages: chat };
|
|
3110
3161
|
const omittedAllTools = !tools.length && diagnostics.some((item) => item.reason === "optional_hosted_web_search_unavailable");
|
|
3111
3162
|
for (const key of ["stream", "temperature", "top_p", "parallel_tool_calls", "metadata"])
|
|
@@ -4610,14 +4661,21 @@ function validateProviderResponse(raw, protocol) {
|
|
|
4610
4661
|
fields2(b, ["id", "object", "created", "model", "choices", "usage", "system_fingerprint", "service_tier"], "", "unsupported_response");
|
|
4611
4662
|
for (const rawChoice of list(b.choices, "choices")) {
|
|
4612
4663
|
const c = record(rawChoice, "choice");
|
|
4613
|
-
fields2(c, ["index", "message", "finish_reason", "logprobs"], "choices", "unsupported_response");
|
|
4664
|
+
fields2(c, ["index", "message", "finish_reason", "logprobs", "provider_specific_fields"], "choices", "unsupported_response");
|
|
4665
|
+
if (c.provider_specific_fields !== undefined) {
|
|
4666
|
+
const providerFields = c.provider_specific_fields;
|
|
4667
|
+
if (providerFields === null || typeof providerFields !== "object" || Array.isArray(providerFields) || Object.keys(providerFields).length)
|
|
4668
|
+
fail("unsupported_response", "Only empty provider-specific choice fields are portable", "choices.provider_specific_fields");
|
|
4669
|
+
}
|
|
4614
4670
|
if (c.logprobs != null)
|
|
4615
4671
|
fail("unsupported_response", "Log probabilities cannot cross protocols", "choices.logprobs");
|
|
4616
4672
|
const m = record(c.message, "message");
|
|
4617
4673
|
fields2(m, ["role", "content", "refusal", "reasoning_content", "reasoning", "tool_calls", "annotations"], "message", "unsupported_content");
|
|
4618
|
-
for (const rawCall of m.tool_calls === undefined ? [] : list(m.tool_calls, "tool_calls")) {
|
|
4674
|
+
for (const [callIndex, rawCall] of (m.tool_calls === undefined ? [] : list(m.tool_calls, "tool_calls")).entries()) {
|
|
4619
4675
|
const call = record(rawCall, "call");
|
|
4620
|
-
fields2(call, ["id", "type", "function"], "tool_calls", "unsupported_tool");
|
|
4676
|
+
fields2(call, ["id", "type", "function", "index"], "tool_calls", "unsupported_tool");
|
|
4677
|
+
if (call.index !== undefined && integer(call.index, `tool_calls[${callIndex}].index`) !== callIndex)
|
|
4678
|
+
fail("invalid_payload", "Tool call index must match its array position", `tool_calls[${callIndex}].index`);
|
|
4621
4679
|
fields2(record(call.function, "function"), ["name", "arguments"], "tool_calls.function", "unsupported_tool");
|
|
4622
4680
|
}
|
|
4623
4681
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffusion/bungee-llms",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.11.0",
|
|
4
4
|
"description": "Extensible LLM adapters and protocol conversion package for Bungee",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
"prepublishOnly": "bun run build"
|
|
12
12
|
},
|
|
13
13
|
"dependencies": {
|
|
14
|
-
"@jeffusion/bungee-types": "^6.
|
|
14
|
+
"@jeffusion/bungee-types": "^6.11.0"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"bun-types": "^1.3.2",
|