@jeffusion/bungee-llms 6.14.1 → 6.15.1
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
CHANGED
|
@@ -4836,7 +4836,9 @@ function readGeminiSignatures(item, budget) {
|
|
|
4836
4836
|
}
|
|
4837
4837
|
function restoreGeminiHistory(input, budget) {
|
|
4838
4838
|
const original = typeof input === "string" ? [] : list(input, "input").map((raw) => record(raw, "input item"));
|
|
4839
|
-
|
|
4839
|
+
if (original.length > budget.maxItems)
|
|
4840
|
+
fail("resource_limit", "Too many input items", "input");
|
|
4841
|
+
const retained = new Map, parts = new Map, ids = new Map;
|
|
4840
4842
|
original.forEach((item, i) => {
|
|
4841
4843
|
if (typeof item.id === "string") {
|
|
4842
4844
|
if (ids.has(item.id))
|
|
@@ -4845,10 +4847,19 @@ function restoreGeminiHistory(input, budget) {
|
|
|
4845
4847
|
}
|
|
4846
4848
|
});
|
|
4847
4849
|
original.forEach((carrier, index) => {
|
|
4850
|
+
if (carrier.type === "configuration_update") {
|
|
4851
|
+
retained.set(carrier, carrier);
|
|
4852
|
+
return;
|
|
4853
|
+
}
|
|
4848
4854
|
if (carrier.encrypted_content == null)
|
|
4849
4855
|
return;
|
|
4850
|
-
const
|
|
4851
|
-
|
|
4856
|
+
const { content, internal_chat_message_metadata_passthrough: metadata, ...normalized } = carrier;
|
|
4857
|
+
if (content !== undefined && content !== null)
|
|
4858
|
+
fail("unsupported_reasoning", "Gemini signature carriers cannot contain reasoning content", `input[${index}].content`);
|
|
4859
|
+
if (metadata !== undefined)
|
|
4860
|
+
atParam(`input[${index}].internal_chat_message_metadata_passthrough`, () => record(metadata, "message metadata"));
|
|
4861
|
+
const signed = readGeminiSignatures(normalized, budget);
|
|
4862
|
+
retained.set(carrier, normalized);
|
|
4852
4863
|
let previous = -1;
|
|
4853
4864
|
for (const item of signed) {
|
|
4854
4865
|
const at = ids.get(item.id);
|
|
@@ -4878,14 +4889,18 @@ function restoreGeminiHistory(input, budget) {
|
|
|
4878
4889
|
parts.set(item.id, restored);
|
|
4879
4890
|
}
|
|
4880
4891
|
});
|
|
4892
|
+
const positions = original.flatMap((item, index) => retained.has(item) ? [] : [index]);
|
|
4881
4893
|
return {
|
|
4882
|
-
input: typeof input === "string" ? input :
|
|
4894
|
+
input: typeof input === "string" ? input : positions.map((index) => original[index]),
|
|
4883
4895
|
parts,
|
|
4896
|
+
sourceParam(param) {
|
|
4897
|
+
return param.replace(/^input\[(\d+)\]/, (match, index) => positions[Number(index)] === undefined ? match : `input[${positions[Number(index)]}]`);
|
|
4898
|
+
},
|
|
4884
4899
|
canonicalHistory(decoded) {
|
|
4885
|
-
if (!
|
|
4900
|
+
if (!retained.size)
|
|
4886
4901
|
return decoded;
|
|
4887
4902
|
let next = 0;
|
|
4888
|
-
return original.
|
|
4903
|
+
return original.filter((item) => item.type !== "additional_tools").map((item) => retained.get(item) ?? decoded[next++]);
|
|
4889
4904
|
}
|
|
4890
4905
|
};
|
|
4891
4906
|
}
|
|
@@ -5251,6 +5266,8 @@ function canonicalRequest(raw, protocol, model) {
|
|
|
5251
5266
|
return out;
|
|
5252
5267
|
}
|
|
5253
5268
|
function validateCanonical(b, context) {
|
|
5269
|
+
const responsesToGemini = context.sourceProtocol === "responses" && context.targetProtocol === "gemini_generate_content";
|
|
5270
|
+
let configuration;
|
|
5254
5271
|
for (const key of ["stream", "parallel_tool_calls", "store", "background"])
|
|
5255
5272
|
if (b[key] !== undefined)
|
|
5256
5273
|
bool(b[key], key);
|
|
@@ -5280,6 +5297,19 @@ function validateCanonical(b, context) {
|
|
|
5280
5297
|
const input = typeof b.input === "string" ? [] : list(b.input, "input");
|
|
5281
5298
|
for (const [i, raw] of input.entries()) {
|
|
5282
5299
|
const t = record(raw, "input item"), p = `input[${i}]`;
|
|
5300
|
+
if (responsesToGemini && t.type === "configuration_update") {
|
|
5301
|
+
fields2(t, ["type", "reasoning"], p, "unsupported_content");
|
|
5302
|
+
const reasoning = atParam(`${p}.reasoning`, () => record(t.reasoning, "configuration reasoning"));
|
|
5303
|
+
fields2(reasoning, ["effort"], `${p}.reasoning`, "unsupported_reasoning");
|
|
5304
|
+
const param = `${p}.reasoning.effort`;
|
|
5305
|
+
const effort = atParam(param, () => string(reasoning.effort, "configuration effort", true));
|
|
5306
|
+
const map = context.reasoningPolicy?.effortMap;
|
|
5307
|
+
const level = map && Object.hasOwn(map, effort) ? map[effort] : undefined;
|
|
5308
|
+
if (level === undefined || !["minimal", "low", "medium", "high"].includes(level))
|
|
5309
|
+
fail("unsupported_reasoning", "Configuration update requires an explicit Gemini level mapping", param);
|
|
5310
|
+
configuration = { effort, level, param };
|
|
5311
|
+
continue;
|
|
5312
|
+
}
|
|
5283
5313
|
if (t.type === "agent_message") {
|
|
5284
5314
|
validateAgentMessage(t, p, context.capabilities?.limits);
|
|
5285
5315
|
continue;
|
|
@@ -5349,9 +5379,37 @@ function validateCanonical(b, context) {
|
|
|
5349
5379
|
for (const [j, tool] of list(t.tools, "tools").entries())
|
|
5350
5380
|
inspectTool(tool, `input[${i}].tools[${j}]`);
|
|
5351
5381
|
}
|
|
5382
|
+
return configuration;
|
|
5383
|
+
}
|
|
5384
|
+
function projectCodexPageSnapshot(raw, index, target, diagnostics) {
|
|
5385
|
+
const item = record(raw, "input item");
|
|
5386
|
+
const { name } = item;
|
|
5387
|
+
if (item.type !== "function_call_output" || item.call_id !== undefined || item.namespace !== "agent" || typeof name !== "string" || name !== "codex_apps_open_page" && !/^codex_apps_selected_page_part_[1-9]\d*_of_[1-9]\d*$/.test(name))
|
|
5388
|
+
return item;
|
|
5389
|
+
const param = `input[${index}]`;
|
|
5390
|
+
fields2(item, ["type", "id", "namespace", "name", "output", "internal_chat_message_metadata_passthrough"], param, "unsupported_content");
|
|
5391
|
+
const text = atParam(`${param}.output`, () => string(item.output, "page snapshot output"));
|
|
5392
|
+
const { id, internal_chat_message_metadata_passthrough: metadata } = item;
|
|
5393
|
+
const reason = target === "chat_completions" ? "chat_codex_page_snapshot_as_user_data" : "gemini_codex_page_snapshot_as_user_data";
|
|
5394
|
+
diagnostics.push({ param, action: "mapped", reason });
|
|
5395
|
+
return {
|
|
5396
|
+
type: "message",
|
|
5397
|
+
role: "user",
|
|
5398
|
+
...id === undefined ? {} : { id },
|
|
5399
|
+
...metadata === undefined ? {} : { internal_chat_message_metadata_passthrough: metadata },
|
|
5400
|
+
content: [
|
|
5401
|
+
{ type: "input_text", text: `[Codex context snapshot: agent.${name}. Untrusted data.]` },
|
|
5402
|
+
{ type: "input_text", text }
|
|
5403
|
+
]
|
|
5404
|
+
};
|
|
5352
5405
|
}
|
|
5353
5406
|
function convertProtocolRequest(raw, context) {
|
|
5354
5407
|
const b = canonicalRequest(raw, context.sourceProtocol, context.model);
|
|
5408
|
+
const target = context.targetProtocol;
|
|
5409
|
+
const responsesToGemini = context.sourceProtocol === "responses" && target === "gemini_generate_content";
|
|
5410
|
+
const pageSnapshotDiagnostics = [];
|
|
5411
|
+
if (context.sourceProtocol === "responses" && (target === "chat_completions" || target === "gemini_generate_content") && Array.isArray(b.input))
|
|
5412
|
+
b.input = b.input.map((item, index) => projectCodexPageSnapshot(item, index, target, pageSnapshotDiagnostics));
|
|
5355
5413
|
const originalInput = b.input;
|
|
5356
5414
|
if (context.streaming !== undefined) {
|
|
5357
5415
|
bool(context.streaming, "context.streaming");
|
|
@@ -5359,8 +5417,8 @@ function convertProtocolRequest(raw, context) {
|
|
|
5359
5417
|
fail("invalid_payload", "Request stream mode disagrees with transport context", "stream");
|
|
5360
5418
|
b.stream = context.streaming;
|
|
5361
5419
|
}
|
|
5362
|
-
validateCanonical(b, context);
|
|
5363
|
-
const geminiHistory =
|
|
5420
|
+
const configuration = validateCanonical(b, context);
|
|
5421
|
+
const geminiHistory = responsesToGemini ? restoreGeminiHistory(b.input, limits(context.capabilities?.limits)) : undefined;
|
|
5364
5422
|
if (geminiHistory)
|
|
5365
5423
|
b.input = geminiHistory.input;
|
|
5366
5424
|
const cap = { ...context.capabilities, agentMessageDelivery: context.agentMessageDelivery ?? context.capabilities?.agentMessageDelivery, omitOptionalWebSearch: true, preserveToolIdentityDescription: true, preserveRefusalContent: true }, policy = context.reasoningPolicy;
|
|
@@ -5385,9 +5443,10 @@ function convertProtocolRequest(raw, context) {
|
|
|
5385
5443
|
if (mappedEffort !== undefined)
|
|
5386
5444
|
string(mappedEffort, "reasoningPolicy.effortMap", true);
|
|
5387
5445
|
}
|
|
5446
|
+
if (configuration)
|
|
5447
|
+
mappedEffort = configuration.level;
|
|
5388
5448
|
if (sourceThinking !== undefined && reasoning?.effort === undefined && policy?.targetEffort !== undefined)
|
|
5389
5449
|
mappedEffort = string(policy.targetEffort, "reasoningPolicy.targetEffort", true);
|
|
5390
|
-
const target = context.targetProtocol;
|
|
5391
5450
|
if (target === "gemini_generate_content" && reasoning?.effort !== undefined && mappedEffort === undefined && policy?.geminiThinkingBudget === undefined && policy?.geminiThinkingLevel === undefined)
|
|
5392
5451
|
fail("unsupported_reasoning", "Gemini requires an explicit thinking budget or level", "reasoning.effort");
|
|
5393
5452
|
if (sourceThinking !== undefined) {
|
|
@@ -5450,8 +5509,21 @@ function convertProtocolRequest(raw, context) {
|
|
|
5450
5509
|
const decodingTarget = target === "gemini_generate_content" ? "chat_completions" : target;
|
|
5451
5510
|
if (target === "gemini_generate_content" && reasoning)
|
|
5452
5511
|
b.reasoning = { ...reasoning, effort: undefined };
|
|
5453
|
-
|
|
5512
|
+
let decoded;
|
|
5513
|
+
try {
|
|
5514
|
+
decoded = decodeResponsesRequest(b, decodingTarget, { ...cap, reasoningHistory: target !== "anthropic_messages" && cap.reasoningHistory === true, reasoningEffort: target === "chat_completions" && cap.reasoningEffort === true, anthropicThinkingBudget: undefined }, { preserveContentOrder: target === "gemini_generate_content", toolOutputImages: responsesToGemini });
|
|
5515
|
+
} catch (error) {
|
|
5516
|
+
if (geminiHistory && error instanceof ResponsesCodecError && error.param !== undefined)
|
|
5517
|
+
throw new ResponsesCodecError(error.code, error.message, geminiHistory.sourceParam(error.param));
|
|
5518
|
+
throw error;
|
|
5519
|
+
}
|
|
5454
5520
|
const diagnostics = decoded.diagnostics;
|
|
5521
|
+
if (geminiHistory)
|
|
5522
|
+
for (const diagnostic of diagnostics)
|
|
5523
|
+
diagnostic.param = geminiHistory.sourceParam(diagnostic.param);
|
|
5524
|
+
diagnostics.push(...pageSnapshotDiagnostics);
|
|
5525
|
+
if (configuration)
|
|
5526
|
+
diagnostics.push({ param: configuration.param, action: "mapped", reason: "gemini_configuration_effort_update" });
|
|
5455
5527
|
if (target === "gemini_generate_content" && decoded.body.parallel_tool_calls === true) {
|
|
5456
5528
|
delete decoded.body.parallel_tool_calls;
|
|
5457
5529
|
diagnostics.push({ param: "parallel_tool_calls", action: "omitted", reason: "gemini_parallel_tool_calls_allowed" });
|
|
@@ -5481,17 +5553,24 @@ function convertProtocolRequest(raw, context) {
|
|
|
5481
5553
|
if (target === "gemini_generate_content" && (mappedEffort !== undefined || policy?.geminiThinkingBudget !== undefined || policy?.geminiThinkingLevel !== undefined)) {
|
|
5482
5554
|
const level = policy?.geminiThinkingLevel ?? mappedEffort;
|
|
5483
5555
|
if (policy?.geminiThinkingBudget !== undefined && level !== undefined)
|
|
5484
|
-
fail("unsupported_reasoning", "Choose one Gemini thinking policy", "reasoningPolicy");
|
|
5556
|
+
fail("unsupported_reasoning", "Choose one Gemini thinking policy", configuration?.param ?? "reasoningPolicy");
|
|
5485
5557
|
if (level !== undefined && !["minimal", "low", "medium", "high"].includes(level))
|
|
5486
5558
|
fail("unsupported_reasoning", "Unknown Gemini thinking level", "reasoning.effort");
|
|
5487
5559
|
if (mappedEffort !== undefined && policy?.geminiThinkingLevel !== undefined && mappedEffort !== policy.geminiThinkingLevel)
|
|
5488
|
-
fail("unsupported_reasoning", "Conflicting Gemini thinking levels", "reasoning.effort");
|
|
5560
|
+
fail("unsupported_reasoning", "Conflicting Gemini thinking levels", configuration?.param ?? "reasoning.effort");
|
|
5489
5561
|
const thinkingConfig = policy?.geminiThinkingBudget !== undefined ? { thinkingBudget: integer(policy.geminiThinkingBudget, "reasoningPolicy.geminiThinkingBudget", -1) } : { thinkingLevel: string(level, "reasoningPolicy.geminiThinkingLevel", true) };
|
|
5490
5562
|
body.generationConfig = { ...record(body.generationConfig ?? {}, "generationConfig"), thinkingConfig };
|
|
5491
5563
|
}
|
|
5492
5564
|
if (mappedEffort !== undefined || sourceThinking !== undefined || policy?.anthropicThinkingBudget !== undefined)
|
|
5493
5565
|
diagnostics.push({ param: "reasoning", action: "mapped", reason: "explicit_verified_wire_policy" });
|
|
5494
|
-
return {
|
|
5566
|
+
return {
|
|
5567
|
+
body,
|
|
5568
|
+
canonicalHistory: geminiHistory?.canonicalHistory(decoded.canonicalInput) ?? decoded.canonicalInput,
|
|
5569
|
+
diagnostics,
|
|
5570
|
+
toolNames: decoded.toolNames,
|
|
5571
|
+
streaming: b.stream === true,
|
|
5572
|
+
...configuration ? { effectiveReasoningEffort: configuration.effort } : {}
|
|
5573
|
+
};
|
|
5495
5574
|
}
|
|
5496
5575
|
function renderGemini(chat, context, input, signedParts, diagnostics) {
|
|
5497
5576
|
const result = { contents: [] }, contents = result.contents, system = [], calls = new Map;
|
|
@@ -6396,7 +6475,7 @@ class CanonicalStreamRenderer {
|
|
|
6396
6475
|
var LLM_PROTOCOLS = ["responses", "chat_completions", "anthropic_messages", "gemini_generate_content"];
|
|
6397
6476
|
|
|
6398
6477
|
// src/protocol-session/index.ts
|
|
6399
|
-
var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.
|
|
6478
|
+
var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.5";
|
|
6400
6479
|
function describeProtocolConversion() {
|
|
6401
6480
|
return {
|
|
6402
6481
|
rulesVersion: PROTOCOL_CONVERSION_RULES_VERSION,
|
package/dist/plugin-api.js
CHANGED
|
@@ -3876,7 +3876,9 @@ function readGeminiSignatures(item, budget) {
|
|
|
3876
3876
|
}
|
|
3877
3877
|
function restoreGeminiHistory(input, budget) {
|
|
3878
3878
|
const original = typeof input === "string" ? [] : list(input, "input").map((raw) => record(raw, "input item"));
|
|
3879
|
-
|
|
3879
|
+
if (original.length > budget.maxItems)
|
|
3880
|
+
fail("resource_limit", "Too many input items", "input");
|
|
3881
|
+
const retained = new Map, parts = new Map, ids = new Map;
|
|
3880
3882
|
original.forEach((item, i) => {
|
|
3881
3883
|
if (typeof item.id === "string") {
|
|
3882
3884
|
if (ids.has(item.id))
|
|
@@ -3885,10 +3887,19 @@ function restoreGeminiHistory(input, budget) {
|
|
|
3885
3887
|
}
|
|
3886
3888
|
});
|
|
3887
3889
|
original.forEach((carrier, index) => {
|
|
3890
|
+
if (carrier.type === "configuration_update") {
|
|
3891
|
+
retained.set(carrier, carrier);
|
|
3892
|
+
return;
|
|
3893
|
+
}
|
|
3888
3894
|
if (carrier.encrypted_content == null)
|
|
3889
3895
|
return;
|
|
3890
|
-
const
|
|
3891
|
-
|
|
3896
|
+
const { content, internal_chat_message_metadata_passthrough: metadata, ...normalized } = carrier;
|
|
3897
|
+
if (content !== undefined && content !== null)
|
|
3898
|
+
fail("unsupported_reasoning", "Gemini signature carriers cannot contain reasoning content", `input[${index}].content`);
|
|
3899
|
+
if (metadata !== undefined)
|
|
3900
|
+
atParam(`input[${index}].internal_chat_message_metadata_passthrough`, () => record(metadata, "message metadata"));
|
|
3901
|
+
const signed = readGeminiSignatures(normalized, budget);
|
|
3902
|
+
retained.set(carrier, normalized);
|
|
3892
3903
|
let previous = -1;
|
|
3893
3904
|
for (const item of signed) {
|
|
3894
3905
|
const at = ids.get(item.id);
|
|
@@ -3918,14 +3929,18 @@ function restoreGeminiHistory(input, budget) {
|
|
|
3918
3929
|
parts.set(item.id, restored);
|
|
3919
3930
|
}
|
|
3920
3931
|
});
|
|
3932
|
+
const positions = original.flatMap((item, index) => retained.has(item) ? [] : [index]);
|
|
3921
3933
|
return {
|
|
3922
|
-
input: typeof input === "string" ? input :
|
|
3934
|
+
input: typeof input === "string" ? input : positions.map((index) => original[index]),
|
|
3923
3935
|
parts,
|
|
3936
|
+
sourceParam(param) {
|
|
3937
|
+
return param.replace(/^input\[(\d+)\]/, (match, index) => positions[Number(index)] === undefined ? match : `input[${positions[Number(index)]}]`);
|
|
3938
|
+
},
|
|
3924
3939
|
canonicalHistory(decoded) {
|
|
3925
|
-
if (!
|
|
3940
|
+
if (!retained.size)
|
|
3926
3941
|
return decoded;
|
|
3927
3942
|
let next = 0;
|
|
3928
|
-
return original.
|
|
3943
|
+
return original.filter((item) => item.type !== "additional_tools").map((item) => retained.get(item) ?? decoded[next++]);
|
|
3929
3944
|
}
|
|
3930
3945
|
};
|
|
3931
3946
|
}
|
|
@@ -4291,6 +4306,8 @@ function canonicalRequest(raw, protocol, model) {
|
|
|
4291
4306
|
return out;
|
|
4292
4307
|
}
|
|
4293
4308
|
function validateCanonical(b, context) {
|
|
4309
|
+
const responsesToGemini = context.sourceProtocol === "responses" && context.targetProtocol === "gemini_generate_content";
|
|
4310
|
+
let configuration;
|
|
4294
4311
|
for (const key of ["stream", "parallel_tool_calls", "store", "background"])
|
|
4295
4312
|
if (b[key] !== undefined)
|
|
4296
4313
|
bool(b[key], key);
|
|
@@ -4320,6 +4337,19 @@ function validateCanonical(b, context) {
|
|
|
4320
4337
|
const input = typeof b.input === "string" ? [] : list(b.input, "input");
|
|
4321
4338
|
for (const [i, raw] of input.entries()) {
|
|
4322
4339
|
const t = record(raw, "input item"), p = `input[${i}]`;
|
|
4340
|
+
if (responsesToGemini && t.type === "configuration_update") {
|
|
4341
|
+
fields2(t, ["type", "reasoning"], p, "unsupported_content");
|
|
4342
|
+
const reasoning = atParam(`${p}.reasoning`, () => record(t.reasoning, "configuration reasoning"));
|
|
4343
|
+
fields2(reasoning, ["effort"], `${p}.reasoning`, "unsupported_reasoning");
|
|
4344
|
+
const param = `${p}.reasoning.effort`;
|
|
4345
|
+
const effort = atParam(param, () => string(reasoning.effort, "configuration effort", true));
|
|
4346
|
+
const map = context.reasoningPolicy?.effortMap;
|
|
4347
|
+
const level = map && Object.hasOwn(map, effort) ? map[effort] : undefined;
|
|
4348
|
+
if (level === undefined || !["minimal", "low", "medium", "high"].includes(level))
|
|
4349
|
+
fail("unsupported_reasoning", "Configuration update requires an explicit Gemini level mapping", param);
|
|
4350
|
+
configuration = { effort, level, param };
|
|
4351
|
+
continue;
|
|
4352
|
+
}
|
|
4323
4353
|
if (t.type === "agent_message") {
|
|
4324
4354
|
validateAgentMessage(t, p, context.capabilities?.limits);
|
|
4325
4355
|
continue;
|
|
@@ -4389,9 +4419,37 @@ function validateCanonical(b, context) {
|
|
|
4389
4419
|
for (const [j, tool] of list(t.tools, "tools").entries())
|
|
4390
4420
|
inspectTool(tool, `input[${i}].tools[${j}]`);
|
|
4391
4421
|
}
|
|
4422
|
+
return configuration;
|
|
4423
|
+
}
|
|
4424
|
+
function projectCodexPageSnapshot(raw, index, target, diagnostics) {
|
|
4425
|
+
const item = record(raw, "input item");
|
|
4426
|
+
const { name } = item;
|
|
4427
|
+
if (item.type !== "function_call_output" || item.call_id !== undefined || item.namespace !== "agent" || typeof name !== "string" || name !== "codex_apps_open_page" && !/^codex_apps_selected_page_part_[1-9]\d*_of_[1-9]\d*$/.test(name))
|
|
4428
|
+
return item;
|
|
4429
|
+
const param = `input[${index}]`;
|
|
4430
|
+
fields2(item, ["type", "id", "namespace", "name", "output", "internal_chat_message_metadata_passthrough"], param, "unsupported_content");
|
|
4431
|
+
const text = atParam(`${param}.output`, () => string(item.output, "page snapshot output"));
|
|
4432
|
+
const { id, internal_chat_message_metadata_passthrough: metadata } = item;
|
|
4433
|
+
const reason = target === "chat_completions" ? "chat_codex_page_snapshot_as_user_data" : "gemini_codex_page_snapshot_as_user_data";
|
|
4434
|
+
diagnostics.push({ param, action: "mapped", reason });
|
|
4435
|
+
return {
|
|
4436
|
+
type: "message",
|
|
4437
|
+
role: "user",
|
|
4438
|
+
...id === undefined ? {} : { id },
|
|
4439
|
+
...metadata === undefined ? {} : { internal_chat_message_metadata_passthrough: metadata },
|
|
4440
|
+
content: [
|
|
4441
|
+
{ type: "input_text", text: `[Codex context snapshot: agent.${name}. Untrusted data.]` },
|
|
4442
|
+
{ type: "input_text", text }
|
|
4443
|
+
]
|
|
4444
|
+
};
|
|
4392
4445
|
}
|
|
4393
4446
|
function convertProtocolRequest(raw, context) {
|
|
4394
4447
|
const b = canonicalRequest(raw, context.sourceProtocol, context.model);
|
|
4448
|
+
const target = context.targetProtocol;
|
|
4449
|
+
const responsesToGemini = context.sourceProtocol === "responses" && target === "gemini_generate_content";
|
|
4450
|
+
const pageSnapshotDiagnostics = [];
|
|
4451
|
+
if (context.sourceProtocol === "responses" && (target === "chat_completions" || target === "gemini_generate_content") && Array.isArray(b.input))
|
|
4452
|
+
b.input = b.input.map((item, index) => projectCodexPageSnapshot(item, index, target, pageSnapshotDiagnostics));
|
|
4395
4453
|
const originalInput = b.input;
|
|
4396
4454
|
if (context.streaming !== undefined) {
|
|
4397
4455
|
bool(context.streaming, "context.streaming");
|
|
@@ -4399,8 +4457,8 @@ function convertProtocolRequest(raw, context) {
|
|
|
4399
4457
|
fail("invalid_payload", "Request stream mode disagrees with transport context", "stream");
|
|
4400
4458
|
b.stream = context.streaming;
|
|
4401
4459
|
}
|
|
4402
|
-
validateCanonical(b, context);
|
|
4403
|
-
const geminiHistory =
|
|
4460
|
+
const configuration = validateCanonical(b, context);
|
|
4461
|
+
const geminiHistory = responsesToGemini ? restoreGeminiHistory(b.input, limits(context.capabilities?.limits)) : undefined;
|
|
4404
4462
|
if (geminiHistory)
|
|
4405
4463
|
b.input = geminiHistory.input;
|
|
4406
4464
|
const cap = { ...context.capabilities, agentMessageDelivery: context.agentMessageDelivery ?? context.capabilities?.agentMessageDelivery, omitOptionalWebSearch: true, preserveToolIdentityDescription: true, preserveRefusalContent: true }, policy = context.reasoningPolicy;
|
|
@@ -4425,9 +4483,10 @@ function convertProtocolRequest(raw, context) {
|
|
|
4425
4483
|
if (mappedEffort !== undefined)
|
|
4426
4484
|
string(mappedEffort, "reasoningPolicy.effortMap", true);
|
|
4427
4485
|
}
|
|
4486
|
+
if (configuration)
|
|
4487
|
+
mappedEffort = configuration.level;
|
|
4428
4488
|
if (sourceThinking !== undefined && reasoning?.effort === undefined && policy?.targetEffort !== undefined)
|
|
4429
4489
|
mappedEffort = string(policy.targetEffort, "reasoningPolicy.targetEffort", true);
|
|
4430
|
-
const target = context.targetProtocol;
|
|
4431
4490
|
if (target === "gemini_generate_content" && reasoning?.effort !== undefined && mappedEffort === undefined && policy?.geminiThinkingBudget === undefined && policy?.geminiThinkingLevel === undefined)
|
|
4432
4491
|
fail("unsupported_reasoning", "Gemini requires an explicit thinking budget or level", "reasoning.effort");
|
|
4433
4492
|
if (sourceThinking !== undefined) {
|
|
@@ -4490,8 +4549,21 @@ function convertProtocolRequest(raw, context) {
|
|
|
4490
4549
|
const decodingTarget = target === "gemini_generate_content" ? "chat_completions" : target;
|
|
4491
4550
|
if (target === "gemini_generate_content" && reasoning)
|
|
4492
4551
|
b.reasoning = { ...reasoning, effort: undefined };
|
|
4493
|
-
|
|
4552
|
+
let decoded;
|
|
4553
|
+
try {
|
|
4554
|
+
decoded = decodeResponsesRequest(b, decodingTarget, { ...cap, reasoningHistory: target !== "anthropic_messages" && cap.reasoningHistory === true, reasoningEffort: target === "chat_completions" && cap.reasoningEffort === true, anthropicThinkingBudget: undefined }, { preserveContentOrder: target === "gemini_generate_content", toolOutputImages: responsesToGemini });
|
|
4555
|
+
} catch (error) {
|
|
4556
|
+
if (geminiHistory && error instanceof ResponsesCodecError && error.param !== undefined)
|
|
4557
|
+
throw new ResponsesCodecError(error.code, error.message, geminiHistory.sourceParam(error.param));
|
|
4558
|
+
throw error;
|
|
4559
|
+
}
|
|
4494
4560
|
const diagnostics = decoded.diagnostics;
|
|
4561
|
+
if (geminiHistory)
|
|
4562
|
+
for (const diagnostic of diagnostics)
|
|
4563
|
+
diagnostic.param = geminiHistory.sourceParam(diagnostic.param);
|
|
4564
|
+
diagnostics.push(...pageSnapshotDiagnostics);
|
|
4565
|
+
if (configuration)
|
|
4566
|
+
diagnostics.push({ param: configuration.param, action: "mapped", reason: "gemini_configuration_effort_update" });
|
|
4495
4567
|
if (target === "gemini_generate_content" && decoded.body.parallel_tool_calls === true) {
|
|
4496
4568
|
delete decoded.body.parallel_tool_calls;
|
|
4497
4569
|
diagnostics.push({ param: "parallel_tool_calls", action: "omitted", reason: "gemini_parallel_tool_calls_allowed" });
|
|
@@ -4521,17 +4593,24 @@ function convertProtocolRequest(raw, context) {
|
|
|
4521
4593
|
if (target === "gemini_generate_content" && (mappedEffort !== undefined || policy?.geminiThinkingBudget !== undefined || policy?.geminiThinkingLevel !== undefined)) {
|
|
4522
4594
|
const level = policy?.geminiThinkingLevel ?? mappedEffort;
|
|
4523
4595
|
if (policy?.geminiThinkingBudget !== undefined && level !== undefined)
|
|
4524
|
-
fail("unsupported_reasoning", "Choose one Gemini thinking policy", "reasoningPolicy");
|
|
4596
|
+
fail("unsupported_reasoning", "Choose one Gemini thinking policy", configuration?.param ?? "reasoningPolicy");
|
|
4525
4597
|
if (level !== undefined && !["minimal", "low", "medium", "high"].includes(level))
|
|
4526
4598
|
fail("unsupported_reasoning", "Unknown Gemini thinking level", "reasoning.effort");
|
|
4527
4599
|
if (mappedEffort !== undefined && policy?.geminiThinkingLevel !== undefined && mappedEffort !== policy.geminiThinkingLevel)
|
|
4528
|
-
fail("unsupported_reasoning", "Conflicting Gemini thinking levels", "reasoning.effort");
|
|
4600
|
+
fail("unsupported_reasoning", "Conflicting Gemini thinking levels", configuration?.param ?? "reasoning.effort");
|
|
4529
4601
|
const thinkingConfig = policy?.geminiThinkingBudget !== undefined ? { thinkingBudget: integer(policy.geminiThinkingBudget, "reasoningPolicy.geminiThinkingBudget", -1) } : { thinkingLevel: string(level, "reasoningPolicy.geminiThinkingLevel", true) };
|
|
4530
4602
|
body.generationConfig = { ...record(body.generationConfig ?? {}, "generationConfig"), thinkingConfig };
|
|
4531
4603
|
}
|
|
4532
4604
|
if (mappedEffort !== undefined || sourceThinking !== undefined || policy?.anthropicThinkingBudget !== undefined)
|
|
4533
4605
|
diagnostics.push({ param: "reasoning", action: "mapped", reason: "explicit_verified_wire_policy" });
|
|
4534
|
-
return {
|
|
4606
|
+
return {
|
|
4607
|
+
body,
|
|
4608
|
+
canonicalHistory: geminiHistory?.canonicalHistory(decoded.canonicalInput) ?? decoded.canonicalInput,
|
|
4609
|
+
diagnostics,
|
|
4610
|
+
toolNames: decoded.toolNames,
|
|
4611
|
+
streaming: b.stream === true,
|
|
4612
|
+
...configuration ? { effectiveReasoningEffort: configuration.effort } : {}
|
|
4613
|
+
};
|
|
4535
4614
|
}
|
|
4536
4615
|
function renderGemini(chat, context, input, signedParts, diagnostics) {
|
|
4537
4616
|
const result = { contents: [] }, contents = result.contents, system = [], calls = new Map;
|
|
@@ -5436,7 +5515,7 @@ class CanonicalStreamRenderer {
|
|
|
5436
5515
|
var LLM_PROTOCOLS = ["responses", "chat_completions", "anthropic_messages", "gemini_generate_content"];
|
|
5437
5516
|
|
|
5438
5517
|
// src/protocol-session/index.ts
|
|
5439
|
-
var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.
|
|
5518
|
+
var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.5";
|
|
5440
5519
|
function describeProtocolConversion() {
|
|
5441
5520
|
return {
|
|
5442
5521
|
rulesVersion: PROTOCOL_CONVERSION_RULES_VERSION,
|
|
@@ -24,6 +24,7 @@ export declare function readGeminiSignatures(item: JsonRecord, budget: Responses
|
|
|
24
24
|
export declare function restoreGeminiHistory(input: unknown, budget: ResponsesCodecLimits): {
|
|
25
25
|
input: string | JsonRecord[];
|
|
26
26
|
parts: Map<string, JsonRecord[]>;
|
|
27
|
+
sourceParam(param: string): string;
|
|
27
28
|
canonicalHistory(decoded: JsonRecord[]): JsonRecord[];
|
|
28
29
|
};
|
|
29
30
|
export declare function encodeGeminiCallId(id: string, signature: unknown, maxBytes: number): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ProtocolSession, type ProtocolSessionContext } from './types';
|
|
2
2
|
export * from './types';
|
|
3
|
-
export declare const PROTOCOL_CONVERSION_RULES_VERSION = "1.0.
|
|
3
|
+
export declare const PROTOCOL_CONVERSION_RULES_VERSION = "1.0.5";
|
|
4
4
|
export declare function describeProtocolConversion(): {
|
|
5
5
|
rulesVersion: string;
|
|
6
6
|
protocols: ("chat_completions" | "anthropic_messages" | "responses" | "gemini_generate_content")[];
|
|
@@ -33,6 +33,8 @@ export interface ProtocolSessionContext {
|
|
|
33
33
|
}
|
|
34
34
|
export interface ProtocolRequestConversion {
|
|
35
35
|
body: ProtocolJsonObject;
|
|
36
|
+
/** Source effort selected by a validated history update, when present. */
|
|
37
|
+
effectiveReasoningEffort?: string;
|
|
36
38
|
canonicalHistory: ProtocolJsonObject[];
|
|
37
39
|
diagnostics: ResponsesConversionDiagnostic[];
|
|
38
40
|
toolNames: ResponsesToolNames;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffusion/bungee-llms",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.15.1",
|
|
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.15.1"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"bun-types": "^1.3.2",
|