@jeffusion/bungee-llms 6.15.0 → 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
@@ -4733,27 +4733,6 @@ function textParts(raw, path, style, role) {
4733
4733
 
4734
4734
  // src/protocol-session/gemini.ts
4735
4735
  var signatureSeparator = "__thought__";
4736
- function projectGeminiCodexPageSnapshot(raw, index, diagnostics) {
4737
- const item = record(raw, "input item");
4738
- const { name } = item;
4739
- 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))
4740
- return item;
4741
- const param = `input[${index}]`;
4742
- fields2(item, ["type", "id", "namespace", "name", "output", "internal_chat_message_metadata_passthrough"], param, "unsupported_content");
4743
- const text = atParam(`${param}.output`, () => string(item.output, "page snapshot output"));
4744
- const { id, internal_chat_message_metadata_passthrough: metadata } = item;
4745
- diagnostics.push({ param, action: "mapped", reason: "gemini_codex_page_snapshot_as_user_data" });
4746
- return {
4747
- type: "message",
4748
- role: "user",
4749
- ...id === undefined ? {} : { id },
4750
- ...metadata === undefined ? {} : { internal_chat_message_metadata_passthrough: metadata },
4751
- content: [
4752
- { type: "input_text", text: `[Codex context snapshot: agent.${name}. Untrusted data.]` },
4753
- { type: "input_text", text }
4754
- ]
4755
- };
4756
- }
4757
4736
  function geminiInlineImage(image, path, budget) {
4758
4737
  const param = `${path}.image_url`;
4759
4738
  const url = bounded(string(image.url, "image URL", true), budget.maxRequestBytes, param);
@@ -4857,7 +4836,9 @@ function readGeminiSignatures(item, budget) {
4857
4836
  }
4858
4837
  function restoreGeminiHistory(input, budget) {
4859
4838
  const original = typeof input === "string" ? [] : list(input, "input").map((raw) => record(raw, "input item"));
4860
- const carriers = new Set, parts = new Map, ids = new Map;
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;
4861
4842
  original.forEach((item, i) => {
4862
4843
  if (typeof item.id === "string") {
4863
4844
  if (ids.has(item.id))
@@ -4866,10 +4847,19 @@ function restoreGeminiHistory(input, budget) {
4866
4847
  }
4867
4848
  });
4868
4849
  original.forEach((carrier, index) => {
4850
+ if (carrier.type === "configuration_update") {
4851
+ retained.set(carrier, carrier);
4852
+ return;
4853
+ }
4869
4854
  if (carrier.encrypted_content == null)
4870
4855
  return;
4871
- const signed = readGeminiSignatures(carrier, budget);
4872
- carriers.add(carrier);
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);
4873
4863
  let previous = -1;
4874
4864
  for (const item of signed) {
4875
4865
  const at = ids.get(item.id);
@@ -4899,14 +4889,18 @@ function restoreGeminiHistory(input, budget) {
4899
4889
  parts.set(item.id, restored);
4900
4890
  }
4901
4891
  });
4892
+ const positions = original.flatMap((item, index) => retained.has(item) ? [] : [index]);
4902
4893
  return {
4903
- input: typeof input === "string" ? input : original.filter((item) => !carriers.has(item)),
4894
+ input: typeof input === "string" ? input : positions.map((index) => original[index]),
4904
4895
  parts,
4896
+ sourceParam(param) {
4897
+ return param.replace(/^input\[(\d+)\]/, (match, index) => positions[Number(index)] === undefined ? match : `input[${positions[Number(index)]}]`);
4898
+ },
4905
4899
  canonicalHistory(decoded) {
4906
- if (!carriers.size)
4900
+ if (!retained.size)
4907
4901
  return decoded;
4908
4902
  let next = 0;
4909
- return original.flatMap((item) => carriers.has(item) ? [item] : item.type === "additional_tools" ? [] : [decoded[next++]]);
4903
+ return original.filter((item) => item.type !== "additional_tools").map((item) => retained.get(item) ?? decoded[next++]);
4910
4904
  }
4911
4905
  };
4912
4906
  }
@@ -5272,6 +5266,8 @@ function canonicalRequest(raw, protocol, model) {
5272
5266
  return out;
5273
5267
  }
5274
5268
  function validateCanonical(b, context) {
5269
+ const responsesToGemini = context.sourceProtocol === "responses" && context.targetProtocol === "gemini_generate_content";
5270
+ let configuration;
5275
5271
  for (const key of ["stream", "parallel_tool_calls", "store", "background"])
5276
5272
  if (b[key] !== undefined)
5277
5273
  bool(b[key], key);
@@ -5301,6 +5297,19 @@ function validateCanonical(b, context) {
5301
5297
  const input = typeof b.input === "string" ? [] : list(b.input, "input");
5302
5298
  for (const [i, raw] of input.entries()) {
5303
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
+ }
5304
5313
  if (t.type === "agent_message") {
5305
5314
  validateAgentMessage(t, p, context.capabilities?.limits);
5306
5315
  continue;
@@ -5370,13 +5379,37 @@ function validateCanonical(b, context) {
5370
5379
  for (const [j, tool] of list(t.tools, "tools").entries())
5371
5380
  inspectTool(tool, `input[${i}].tools[${j}]`);
5372
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
+ };
5373
5405
  }
5374
5406
  function convertProtocolRequest(raw, context) {
5375
5407
  const b = canonicalRequest(raw, context.sourceProtocol, context.model);
5376
- const responsesToGemini = context.sourceProtocol === "responses" && context.targetProtocol === "gemini_generate_content";
5408
+ const target = context.targetProtocol;
5409
+ const responsesToGemini = context.sourceProtocol === "responses" && target === "gemini_generate_content";
5377
5410
  const pageSnapshotDiagnostics = [];
5378
- if (responsesToGemini && Array.isArray(b.input))
5379
- b.input = b.input.map((item, index) => projectGeminiCodexPageSnapshot(item, index, 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));
5380
5413
  const originalInput = b.input;
5381
5414
  if (context.streaming !== undefined) {
5382
5415
  bool(context.streaming, "context.streaming");
@@ -5384,7 +5417,7 @@ function convertProtocolRequest(raw, context) {
5384
5417
  fail("invalid_payload", "Request stream mode disagrees with transport context", "stream");
5385
5418
  b.stream = context.streaming;
5386
5419
  }
5387
- validateCanonical(b, context);
5420
+ const configuration = validateCanonical(b, context);
5388
5421
  const geminiHistory = responsesToGemini ? restoreGeminiHistory(b.input, limits(context.capabilities?.limits)) : undefined;
5389
5422
  if (geminiHistory)
5390
5423
  b.input = geminiHistory.input;
@@ -5410,9 +5443,10 @@ function convertProtocolRequest(raw, context) {
5410
5443
  if (mappedEffort !== undefined)
5411
5444
  string(mappedEffort, "reasoningPolicy.effortMap", true);
5412
5445
  }
5446
+ if (configuration)
5447
+ mappedEffort = configuration.level;
5413
5448
  if (sourceThinking !== undefined && reasoning?.effort === undefined && policy?.targetEffort !== undefined)
5414
5449
  mappedEffort = string(policy.targetEffort, "reasoningPolicy.targetEffort", true);
5415
- const target = context.targetProtocol;
5416
5450
  if (target === "gemini_generate_content" && reasoning?.effort !== undefined && mappedEffort === undefined && policy?.geminiThinkingBudget === undefined && policy?.geminiThinkingLevel === undefined)
5417
5451
  fail("unsupported_reasoning", "Gemini requires an explicit thinking budget or level", "reasoning.effort");
5418
5452
  if (sourceThinking !== undefined) {
@@ -5475,9 +5509,21 @@ function convertProtocolRequest(raw, context) {
5475
5509
  const decodingTarget = target === "gemini_generate_content" ? "chat_completions" : target;
5476
5510
  if (target === "gemini_generate_content" && reasoning)
5477
5511
  b.reasoning = { ...reasoning, effort: undefined };
5478
- const 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 });
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
+ }
5479
5520
  const diagnostics = decoded.diagnostics;
5521
+ if (geminiHistory)
5522
+ for (const diagnostic of diagnostics)
5523
+ diagnostic.param = geminiHistory.sourceParam(diagnostic.param);
5480
5524
  diagnostics.push(...pageSnapshotDiagnostics);
5525
+ if (configuration)
5526
+ diagnostics.push({ param: configuration.param, action: "mapped", reason: "gemini_configuration_effort_update" });
5481
5527
  if (target === "gemini_generate_content" && decoded.body.parallel_tool_calls === true) {
5482
5528
  delete decoded.body.parallel_tool_calls;
5483
5529
  diagnostics.push({ param: "parallel_tool_calls", action: "omitted", reason: "gemini_parallel_tool_calls_allowed" });
@@ -5507,17 +5553,24 @@ function convertProtocolRequest(raw, context) {
5507
5553
  if (target === "gemini_generate_content" && (mappedEffort !== undefined || policy?.geminiThinkingBudget !== undefined || policy?.geminiThinkingLevel !== undefined)) {
5508
5554
  const level = policy?.geminiThinkingLevel ?? mappedEffort;
5509
5555
  if (policy?.geminiThinkingBudget !== undefined && level !== undefined)
5510
- fail("unsupported_reasoning", "Choose one Gemini thinking policy", "reasoningPolicy");
5556
+ fail("unsupported_reasoning", "Choose one Gemini thinking policy", configuration?.param ?? "reasoningPolicy");
5511
5557
  if (level !== undefined && !["minimal", "low", "medium", "high"].includes(level))
5512
5558
  fail("unsupported_reasoning", "Unknown Gemini thinking level", "reasoning.effort");
5513
5559
  if (mappedEffort !== undefined && policy?.geminiThinkingLevel !== undefined && mappedEffort !== policy.geminiThinkingLevel)
5514
- fail("unsupported_reasoning", "Conflicting Gemini thinking levels", "reasoning.effort");
5560
+ fail("unsupported_reasoning", "Conflicting Gemini thinking levels", configuration?.param ?? "reasoning.effort");
5515
5561
  const thinkingConfig = policy?.geminiThinkingBudget !== undefined ? { thinkingBudget: integer(policy.geminiThinkingBudget, "reasoningPolicy.geminiThinkingBudget", -1) } : { thinkingLevel: string(level, "reasoningPolicy.geminiThinkingLevel", true) };
5516
5562
  body.generationConfig = { ...record(body.generationConfig ?? {}, "generationConfig"), thinkingConfig };
5517
5563
  }
5518
5564
  if (mappedEffort !== undefined || sourceThinking !== undefined || policy?.anthropicThinkingBudget !== undefined)
5519
5565
  diagnostics.push({ param: "reasoning", action: "mapped", reason: "explicit_verified_wire_policy" });
5520
- return { body, canonicalHistory: geminiHistory?.canonicalHistory(decoded.canonicalInput) ?? decoded.canonicalInput, diagnostics, toolNames: decoded.toolNames, streaming: b.stream === true };
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
+ };
5521
5574
  }
5522
5575
  function renderGemini(chat, context, input, signedParts, diagnostics) {
5523
5576
  const result = { contents: [] }, contents = result.contents, system = [], calls = new Map;
@@ -6422,7 +6475,7 @@ class CanonicalStreamRenderer {
6422
6475
  var LLM_PROTOCOLS = ["responses", "chat_completions", "anthropic_messages", "gemini_generate_content"];
6423
6476
 
6424
6477
  // src/protocol-session/index.ts
6425
- var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.4";
6478
+ var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.5";
6426
6479
  function describeProtocolConversion() {
6427
6480
  return {
6428
6481
  rulesVersion: PROTOCOL_CONVERSION_RULES_VERSION,
@@ -3773,27 +3773,6 @@ function textParts(raw, path, style, role) {
3773
3773
 
3774
3774
  // src/protocol-session/gemini.ts
3775
3775
  var signatureSeparator = "__thought__";
3776
- function projectGeminiCodexPageSnapshot(raw, index, diagnostics) {
3777
- const item = record(raw, "input item");
3778
- const { name } = item;
3779
- 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))
3780
- return item;
3781
- const param = `input[${index}]`;
3782
- fields2(item, ["type", "id", "namespace", "name", "output", "internal_chat_message_metadata_passthrough"], param, "unsupported_content");
3783
- const text = atParam(`${param}.output`, () => string(item.output, "page snapshot output"));
3784
- const { id, internal_chat_message_metadata_passthrough: metadata } = item;
3785
- diagnostics.push({ param, action: "mapped", reason: "gemini_codex_page_snapshot_as_user_data" });
3786
- return {
3787
- type: "message",
3788
- role: "user",
3789
- ...id === undefined ? {} : { id },
3790
- ...metadata === undefined ? {} : { internal_chat_message_metadata_passthrough: metadata },
3791
- content: [
3792
- { type: "input_text", text: `[Codex context snapshot: agent.${name}. Untrusted data.]` },
3793
- { type: "input_text", text }
3794
- ]
3795
- };
3796
- }
3797
3776
  function geminiInlineImage(image, path, budget) {
3798
3777
  const param = `${path}.image_url`;
3799
3778
  const url = bounded(string(image.url, "image URL", true), budget.maxRequestBytes, param);
@@ -3897,7 +3876,9 @@ function readGeminiSignatures(item, budget) {
3897
3876
  }
3898
3877
  function restoreGeminiHistory(input, budget) {
3899
3878
  const original = typeof input === "string" ? [] : list(input, "input").map((raw) => record(raw, "input item"));
3900
- const carriers = new Set, parts = new Map, ids = new Map;
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;
3901
3882
  original.forEach((item, i) => {
3902
3883
  if (typeof item.id === "string") {
3903
3884
  if (ids.has(item.id))
@@ -3906,10 +3887,19 @@ function restoreGeminiHistory(input, budget) {
3906
3887
  }
3907
3888
  });
3908
3889
  original.forEach((carrier, index) => {
3890
+ if (carrier.type === "configuration_update") {
3891
+ retained.set(carrier, carrier);
3892
+ return;
3893
+ }
3909
3894
  if (carrier.encrypted_content == null)
3910
3895
  return;
3911
- const signed = readGeminiSignatures(carrier, budget);
3912
- carriers.add(carrier);
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);
3913
3903
  let previous = -1;
3914
3904
  for (const item of signed) {
3915
3905
  const at = ids.get(item.id);
@@ -3939,14 +3929,18 @@ function restoreGeminiHistory(input, budget) {
3939
3929
  parts.set(item.id, restored);
3940
3930
  }
3941
3931
  });
3932
+ const positions = original.flatMap((item, index) => retained.has(item) ? [] : [index]);
3942
3933
  return {
3943
- input: typeof input === "string" ? input : original.filter((item) => !carriers.has(item)),
3934
+ input: typeof input === "string" ? input : positions.map((index) => original[index]),
3944
3935
  parts,
3936
+ sourceParam(param) {
3937
+ return param.replace(/^input\[(\d+)\]/, (match, index) => positions[Number(index)] === undefined ? match : `input[${positions[Number(index)]}]`);
3938
+ },
3945
3939
  canonicalHistory(decoded) {
3946
- if (!carriers.size)
3940
+ if (!retained.size)
3947
3941
  return decoded;
3948
3942
  let next = 0;
3949
- return original.flatMap((item) => carriers.has(item) ? [item] : item.type === "additional_tools" ? [] : [decoded[next++]]);
3943
+ return original.filter((item) => item.type !== "additional_tools").map((item) => retained.get(item) ?? decoded[next++]);
3950
3944
  }
3951
3945
  };
3952
3946
  }
@@ -4312,6 +4306,8 @@ function canonicalRequest(raw, protocol, model) {
4312
4306
  return out;
4313
4307
  }
4314
4308
  function validateCanonical(b, context) {
4309
+ const responsesToGemini = context.sourceProtocol === "responses" && context.targetProtocol === "gemini_generate_content";
4310
+ let configuration;
4315
4311
  for (const key of ["stream", "parallel_tool_calls", "store", "background"])
4316
4312
  if (b[key] !== undefined)
4317
4313
  bool(b[key], key);
@@ -4341,6 +4337,19 @@ function validateCanonical(b, context) {
4341
4337
  const input = typeof b.input === "string" ? [] : list(b.input, "input");
4342
4338
  for (const [i, raw] of input.entries()) {
4343
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
+ }
4344
4353
  if (t.type === "agent_message") {
4345
4354
  validateAgentMessage(t, p, context.capabilities?.limits);
4346
4355
  continue;
@@ -4410,13 +4419,37 @@ function validateCanonical(b, context) {
4410
4419
  for (const [j, tool] of list(t.tools, "tools").entries())
4411
4420
  inspectTool(tool, `input[${i}].tools[${j}]`);
4412
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
+ };
4413
4445
  }
4414
4446
  function convertProtocolRequest(raw, context) {
4415
4447
  const b = canonicalRequest(raw, context.sourceProtocol, context.model);
4416
- const responsesToGemini = context.sourceProtocol === "responses" && context.targetProtocol === "gemini_generate_content";
4448
+ const target = context.targetProtocol;
4449
+ const responsesToGemini = context.sourceProtocol === "responses" && target === "gemini_generate_content";
4417
4450
  const pageSnapshotDiagnostics = [];
4418
- if (responsesToGemini && Array.isArray(b.input))
4419
- b.input = b.input.map((item, index) => projectGeminiCodexPageSnapshot(item, index, 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));
4420
4453
  const originalInput = b.input;
4421
4454
  if (context.streaming !== undefined) {
4422
4455
  bool(context.streaming, "context.streaming");
@@ -4424,7 +4457,7 @@ function convertProtocolRequest(raw, context) {
4424
4457
  fail("invalid_payload", "Request stream mode disagrees with transport context", "stream");
4425
4458
  b.stream = context.streaming;
4426
4459
  }
4427
- validateCanonical(b, context);
4460
+ const configuration = validateCanonical(b, context);
4428
4461
  const geminiHistory = responsesToGemini ? restoreGeminiHistory(b.input, limits(context.capabilities?.limits)) : undefined;
4429
4462
  if (geminiHistory)
4430
4463
  b.input = geminiHistory.input;
@@ -4450,9 +4483,10 @@ function convertProtocolRequest(raw, context) {
4450
4483
  if (mappedEffort !== undefined)
4451
4484
  string(mappedEffort, "reasoningPolicy.effortMap", true);
4452
4485
  }
4486
+ if (configuration)
4487
+ mappedEffort = configuration.level;
4453
4488
  if (sourceThinking !== undefined && reasoning?.effort === undefined && policy?.targetEffort !== undefined)
4454
4489
  mappedEffort = string(policy.targetEffort, "reasoningPolicy.targetEffort", true);
4455
- const target = context.targetProtocol;
4456
4490
  if (target === "gemini_generate_content" && reasoning?.effort !== undefined && mappedEffort === undefined && policy?.geminiThinkingBudget === undefined && policy?.geminiThinkingLevel === undefined)
4457
4491
  fail("unsupported_reasoning", "Gemini requires an explicit thinking budget or level", "reasoning.effort");
4458
4492
  if (sourceThinking !== undefined) {
@@ -4515,9 +4549,21 @@ function convertProtocolRequest(raw, context) {
4515
4549
  const decodingTarget = target === "gemini_generate_content" ? "chat_completions" : target;
4516
4550
  if (target === "gemini_generate_content" && reasoning)
4517
4551
  b.reasoning = { ...reasoning, effort: undefined };
4518
- const 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 });
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
+ }
4519
4560
  const diagnostics = decoded.diagnostics;
4561
+ if (geminiHistory)
4562
+ for (const diagnostic of diagnostics)
4563
+ diagnostic.param = geminiHistory.sourceParam(diagnostic.param);
4520
4564
  diagnostics.push(...pageSnapshotDiagnostics);
4565
+ if (configuration)
4566
+ diagnostics.push({ param: configuration.param, action: "mapped", reason: "gemini_configuration_effort_update" });
4521
4567
  if (target === "gemini_generate_content" && decoded.body.parallel_tool_calls === true) {
4522
4568
  delete decoded.body.parallel_tool_calls;
4523
4569
  diagnostics.push({ param: "parallel_tool_calls", action: "omitted", reason: "gemini_parallel_tool_calls_allowed" });
@@ -4547,17 +4593,24 @@ function convertProtocolRequest(raw, context) {
4547
4593
  if (target === "gemini_generate_content" && (mappedEffort !== undefined || policy?.geminiThinkingBudget !== undefined || policy?.geminiThinkingLevel !== undefined)) {
4548
4594
  const level = policy?.geminiThinkingLevel ?? mappedEffort;
4549
4595
  if (policy?.geminiThinkingBudget !== undefined && level !== undefined)
4550
- fail("unsupported_reasoning", "Choose one Gemini thinking policy", "reasoningPolicy");
4596
+ fail("unsupported_reasoning", "Choose one Gemini thinking policy", configuration?.param ?? "reasoningPolicy");
4551
4597
  if (level !== undefined && !["minimal", "low", "medium", "high"].includes(level))
4552
4598
  fail("unsupported_reasoning", "Unknown Gemini thinking level", "reasoning.effort");
4553
4599
  if (mappedEffort !== undefined && policy?.geminiThinkingLevel !== undefined && mappedEffort !== policy.geminiThinkingLevel)
4554
- fail("unsupported_reasoning", "Conflicting Gemini thinking levels", "reasoning.effort");
4600
+ fail("unsupported_reasoning", "Conflicting Gemini thinking levels", configuration?.param ?? "reasoning.effort");
4555
4601
  const thinkingConfig = policy?.geminiThinkingBudget !== undefined ? { thinkingBudget: integer(policy.geminiThinkingBudget, "reasoningPolicy.geminiThinkingBudget", -1) } : { thinkingLevel: string(level, "reasoningPolicy.geminiThinkingLevel", true) };
4556
4602
  body.generationConfig = { ...record(body.generationConfig ?? {}, "generationConfig"), thinkingConfig };
4557
4603
  }
4558
4604
  if (mappedEffort !== undefined || sourceThinking !== undefined || policy?.anthropicThinkingBudget !== undefined)
4559
4605
  diagnostics.push({ param: "reasoning", action: "mapped", reason: "explicit_verified_wire_policy" });
4560
- return { body, canonicalHistory: geminiHistory?.canonicalHistory(decoded.canonicalInput) ?? decoded.canonicalInput, diagnostics, toolNames: decoded.toolNames, streaming: b.stream === true };
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
+ };
4561
4614
  }
4562
4615
  function renderGemini(chat, context, input, signedParts, diagnostics) {
4563
4616
  const result = { contents: [] }, contents = result.contents, system = [], calls = new Map;
@@ -5462,7 +5515,7 @@ class CanonicalStreamRenderer {
5462
5515
  var LLM_PROTOCOLS = ["responses", "chat_completions", "anthropic_messages", "gemini_generate_content"];
5463
5516
 
5464
5517
  // src/protocol-session/index.ts
5465
- var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.4";
5518
+ var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.5";
5466
5519
  function describeProtocolConversion() {
5467
5520
  return {
5468
5521
  rulesVersion: PROTOCOL_CONVERSION_RULES_VERSION,
@@ -1,5 +1,4 @@
1
1
  import { type JsonRecord, type ResponsesCodecLimits, type ResponsesConversionDiagnostic } from '../responses-codec/common';
2
- export declare function projectGeminiCodexPageSnapshot(raw: unknown, index: number, diagnostics: ResponsesConversionDiagnostic[]): JsonRecord;
3
2
  export declare function geminiInlineImage(image: JsonRecord, path: string, budget: ResponsesCodecLimits): {
4
3
  mimeType: string;
5
4
  data: string;
@@ -25,6 +24,7 @@ export declare function readGeminiSignatures(item: JsonRecord, budget: Responses
25
24
  export declare function restoreGeminiHistory(input: unknown, budget: ResponsesCodecLimits): {
26
25
  input: string | JsonRecord[];
27
26
  parts: Map<string, JsonRecord[]>;
27
+ sourceParam(param: string): string;
28
28
  canonicalHistory(decoded: JsonRecord[]): JsonRecord[];
29
29
  };
30
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.4";
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.15.0",
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.15.0"
14
+ "@jeffusion/bungee-types": "^6.15.1"
15
15
  },
16
16
  "devDependencies": {
17
17
  "bun-types": "^1.3.2",