@jeffusion/bungee-core 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.
@@ -4380,27 +4380,6 @@ function textParts(raw, path, style, role) {
4380
4380
 
4381
4381
  // packages/llms/src/protocol-session/gemini.ts
4382
4382
  var signatureSeparator = "__thought__";
4383
- function projectGeminiCodexPageSnapshot(raw, index, diagnostics) {
4384
- const item = record(raw, "input item");
4385
- const { name } = item;
4386
- 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))
4387
- return item;
4388
- const param = `input[${index}]`;
4389
- fields2(item, ["type", "id", "namespace", "name", "output", "internal_chat_message_metadata_passthrough"], param, "unsupported_content");
4390
- const text = atParam(`${param}.output`, () => string(item.output, "page snapshot output"));
4391
- const { id, internal_chat_message_metadata_passthrough: metadata } = item;
4392
- diagnostics.push({ param, action: "mapped", reason: "gemini_codex_page_snapshot_as_user_data" });
4393
- return {
4394
- type: "message",
4395
- role: "user",
4396
- ...id === undefined ? {} : { id },
4397
- ...metadata === undefined ? {} : { internal_chat_message_metadata_passthrough: metadata },
4398
- content: [
4399
- { type: "input_text", text: `[Codex context snapshot: agent.${name}. Untrusted data.]` },
4400
- { type: "input_text", text }
4401
- ]
4402
- };
4403
- }
4404
4383
  function geminiInlineImage(image, path, budget) {
4405
4384
  const param = `${path}.image_url`;
4406
4385
  const url = bounded(string(image.url, "image URL", true), budget.maxRequestBytes, param);
@@ -4504,7 +4483,9 @@ function readGeminiSignatures(item, budget) {
4504
4483
  }
4505
4484
  function restoreGeminiHistory(input, budget) {
4506
4485
  const original = typeof input === "string" ? [] : list(input, "input").map((raw) => record(raw, "input item"));
4507
- const carriers = new Set, parts = new Map, ids = new Map;
4486
+ if (original.length > budget.maxItems)
4487
+ fail("resource_limit", "Too many input items", "input");
4488
+ const retained = new Map, parts = new Map, ids = new Map;
4508
4489
  original.forEach((item, i) => {
4509
4490
  if (typeof item.id === "string") {
4510
4491
  if (ids.has(item.id))
@@ -4513,10 +4494,19 @@ function restoreGeminiHistory(input, budget) {
4513
4494
  }
4514
4495
  });
4515
4496
  original.forEach((carrier, index) => {
4497
+ if (carrier.type === "configuration_update") {
4498
+ retained.set(carrier, carrier);
4499
+ return;
4500
+ }
4516
4501
  if (carrier.encrypted_content == null)
4517
4502
  return;
4518
- const signed = readGeminiSignatures(carrier, budget);
4519
- carriers.add(carrier);
4503
+ const { content, internal_chat_message_metadata_passthrough: metadata, ...normalized } = carrier;
4504
+ if (content !== undefined && content !== null)
4505
+ fail("unsupported_reasoning", "Gemini signature carriers cannot contain reasoning content", `input[${index}].content`);
4506
+ if (metadata !== undefined)
4507
+ atParam(`input[${index}].internal_chat_message_metadata_passthrough`, () => record(metadata, "message metadata"));
4508
+ const signed = readGeminiSignatures(normalized, budget);
4509
+ retained.set(carrier, normalized);
4520
4510
  let previous = -1;
4521
4511
  for (const item of signed) {
4522
4512
  const at = ids.get(item.id);
@@ -4546,14 +4536,18 @@ function restoreGeminiHistory(input, budget) {
4546
4536
  parts.set(item.id, restored);
4547
4537
  }
4548
4538
  });
4539
+ const positions = original.flatMap((item, index) => retained.has(item) ? [] : [index]);
4549
4540
  return {
4550
- input: typeof input === "string" ? input : original.filter((item) => !carriers.has(item)),
4541
+ input: typeof input === "string" ? input : positions.map((index) => original[index]),
4551
4542
  parts,
4543
+ sourceParam(param) {
4544
+ return param.replace(/^input\[(\d+)\]/, (match, index) => positions[Number(index)] === undefined ? match : `input[${positions[Number(index)]}]`);
4545
+ },
4552
4546
  canonicalHistory(decoded) {
4553
- if (!carriers.size)
4547
+ if (!retained.size)
4554
4548
  return decoded;
4555
4549
  let next = 0;
4556
- return original.flatMap((item) => carriers.has(item) ? [item] : item.type === "additional_tools" ? [] : [decoded[next++]]);
4550
+ return original.filter((item) => item.type !== "additional_tools").map((item) => retained.get(item) ?? decoded[next++]);
4557
4551
  }
4558
4552
  };
4559
4553
  }
@@ -4919,6 +4913,8 @@ function canonicalRequest(raw, protocol, model) {
4919
4913
  return out;
4920
4914
  }
4921
4915
  function validateCanonical(b, context) {
4916
+ const responsesToGemini = context.sourceProtocol === "responses" && context.targetProtocol === "gemini_generate_content";
4917
+ let configuration;
4922
4918
  for (const key of ["stream", "parallel_tool_calls", "store", "background"])
4923
4919
  if (b[key] !== undefined)
4924
4920
  bool(b[key], key);
@@ -4948,6 +4944,19 @@ function validateCanonical(b, context) {
4948
4944
  const input = typeof b.input === "string" ? [] : list(b.input, "input");
4949
4945
  for (const [i, raw] of input.entries()) {
4950
4946
  const t = record(raw, "input item"), p = `input[${i}]`;
4947
+ if (responsesToGemini && t.type === "configuration_update") {
4948
+ fields2(t, ["type", "reasoning"], p, "unsupported_content");
4949
+ const reasoning = atParam(`${p}.reasoning`, () => record(t.reasoning, "configuration reasoning"));
4950
+ fields2(reasoning, ["effort"], `${p}.reasoning`, "unsupported_reasoning");
4951
+ const param = `${p}.reasoning.effort`;
4952
+ const effort = atParam(param, () => string(reasoning.effort, "configuration effort", true));
4953
+ const map = context.reasoningPolicy?.effortMap;
4954
+ const level = map && Object.hasOwn(map, effort) ? map[effort] : undefined;
4955
+ if (level === undefined || !["minimal", "low", "medium", "high"].includes(level))
4956
+ fail("unsupported_reasoning", "Configuration update requires an explicit Gemini level mapping", param);
4957
+ configuration = { effort, level, param };
4958
+ continue;
4959
+ }
4951
4960
  if (t.type === "agent_message") {
4952
4961
  validateAgentMessage(t, p, context.capabilities?.limits);
4953
4962
  continue;
@@ -5017,13 +5026,37 @@ function validateCanonical(b, context) {
5017
5026
  for (const [j, tool] of list(t.tools, "tools").entries())
5018
5027
  inspectTool(tool, `input[${i}].tools[${j}]`);
5019
5028
  }
5029
+ return configuration;
5030
+ }
5031
+ function projectCodexPageSnapshot(raw, index, target, diagnostics) {
5032
+ const item = record(raw, "input item");
5033
+ const { name } = item;
5034
+ 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))
5035
+ return item;
5036
+ const param = `input[${index}]`;
5037
+ fields2(item, ["type", "id", "namespace", "name", "output", "internal_chat_message_metadata_passthrough"], param, "unsupported_content");
5038
+ const text = atParam(`${param}.output`, () => string(item.output, "page snapshot output"));
5039
+ const { id, internal_chat_message_metadata_passthrough: metadata } = item;
5040
+ const reason = target === "chat_completions" ? "chat_codex_page_snapshot_as_user_data" : "gemini_codex_page_snapshot_as_user_data";
5041
+ diagnostics.push({ param, action: "mapped", reason });
5042
+ return {
5043
+ type: "message",
5044
+ role: "user",
5045
+ ...id === undefined ? {} : { id },
5046
+ ...metadata === undefined ? {} : { internal_chat_message_metadata_passthrough: metadata },
5047
+ content: [
5048
+ { type: "input_text", text: `[Codex context snapshot: agent.${name}. Untrusted data.]` },
5049
+ { type: "input_text", text }
5050
+ ]
5051
+ };
5020
5052
  }
5021
5053
  function convertProtocolRequest(raw, context) {
5022
5054
  const b = canonicalRequest(raw, context.sourceProtocol, context.model);
5023
- const responsesToGemini = context.sourceProtocol === "responses" && context.targetProtocol === "gemini_generate_content";
5055
+ const target = context.targetProtocol;
5056
+ const responsesToGemini = context.sourceProtocol === "responses" && target === "gemini_generate_content";
5024
5057
  const pageSnapshotDiagnostics = [];
5025
- if (responsesToGemini && Array.isArray(b.input))
5026
- b.input = b.input.map((item, index) => projectGeminiCodexPageSnapshot(item, index, pageSnapshotDiagnostics));
5058
+ if (context.sourceProtocol === "responses" && (target === "chat_completions" || target === "gemini_generate_content") && Array.isArray(b.input))
5059
+ b.input = b.input.map((item, index) => projectCodexPageSnapshot(item, index, target, pageSnapshotDiagnostics));
5027
5060
  const originalInput = b.input;
5028
5061
  if (context.streaming !== undefined) {
5029
5062
  bool(context.streaming, "context.streaming");
@@ -5031,7 +5064,7 @@ function convertProtocolRequest(raw, context) {
5031
5064
  fail("invalid_payload", "Request stream mode disagrees with transport context", "stream");
5032
5065
  b.stream = context.streaming;
5033
5066
  }
5034
- validateCanonical(b, context);
5067
+ const configuration = validateCanonical(b, context);
5035
5068
  const geminiHistory = responsesToGemini ? restoreGeminiHistory(b.input, limits(context.capabilities?.limits)) : undefined;
5036
5069
  if (geminiHistory)
5037
5070
  b.input = geminiHistory.input;
@@ -5057,9 +5090,10 @@ function convertProtocolRequest(raw, context) {
5057
5090
  if (mappedEffort !== undefined)
5058
5091
  string(mappedEffort, "reasoningPolicy.effortMap", true);
5059
5092
  }
5093
+ if (configuration)
5094
+ mappedEffort = configuration.level;
5060
5095
  if (sourceThinking !== undefined && reasoning?.effort === undefined && policy?.targetEffort !== undefined)
5061
5096
  mappedEffort = string(policy.targetEffort, "reasoningPolicy.targetEffort", true);
5062
- const target = context.targetProtocol;
5063
5097
  if (target === "gemini_generate_content" && reasoning?.effort !== undefined && mappedEffort === undefined && policy?.geminiThinkingBudget === undefined && policy?.geminiThinkingLevel === undefined)
5064
5098
  fail("unsupported_reasoning", "Gemini requires an explicit thinking budget or level", "reasoning.effort");
5065
5099
  if (sourceThinking !== undefined) {
@@ -5122,9 +5156,21 @@ function convertProtocolRequest(raw, context) {
5122
5156
  const decodingTarget = target === "gemini_generate_content" ? "chat_completions" : target;
5123
5157
  if (target === "gemini_generate_content" && reasoning)
5124
5158
  b.reasoning = { ...reasoning, effort: undefined };
5125
- 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 });
5159
+ let decoded;
5160
+ try {
5161
+ 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 });
5162
+ } catch (error) {
5163
+ if (geminiHistory && error instanceof ResponsesCodecError && error.param !== undefined)
5164
+ throw new ResponsesCodecError(error.code, error.message, geminiHistory.sourceParam(error.param));
5165
+ throw error;
5166
+ }
5126
5167
  const diagnostics = decoded.diagnostics;
5168
+ if (geminiHistory)
5169
+ for (const diagnostic of diagnostics)
5170
+ diagnostic.param = geminiHistory.sourceParam(diagnostic.param);
5127
5171
  diagnostics.push(...pageSnapshotDiagnostics);
5172
+ if (configuration)
5173
+ diagnostics.push({ param: configuration.param, action: "mapped", reason: "gemini_configuration_effort_update" });
5128
5174
  if (target === "gemini_generate_content" && decoded.body.parallel_tool_calls === true) {
5129
5175
  delete decoded.body.parallel_tool_calls;
5130
5176
  diagnostics.push({ param: "parallel_tool_calls", action: "omitted", reason: "gemini_parallel_tool_calls_allowed" });
@@ -5154,17 +5200,24 @@ function convertProtocolRequest(raw, context) {
5154
5200
  if (target === "gemini_generate_content" && (mappedEffort !== undefined || policy?.geminiThinkingBudget !== undefined || policy?.geminiThinkingLevel !== undefined)) {
5155
5201
  const level = policy?.geminiThinkingLevel ?? mappedEffort;
5156
5202
  if (policy?.geminiThinkingBudget !== undefined && level !== undefined)
5157
- fail("unsupported_reasoning", "Choose one Gemini thinking policy", "reasoningPolicy");
5203
+ fail("unsupported_reasoning", "Choose one Gemini thinking policy", configuration?.param ?? "reasoningPolicy");
5158
5204
  if (level !== undefined && !["minimal", "low", "medium", "high"].includes(level))
5159
5205
  fail("unsupported_reasoning", "Unknown Gemini thinking level", "reasoning.effort");
5160
5206
  if (mappedEffort !== undefined && policy?.geminiThinkingLevel !== undefined && mappedEffort !== policy.geminiThinkingLevel)
5161
- fail("unsupported_reasoning", "Conflicting Gemini thinking levels", "reasoning.effort");
5207
+ fail("unsupported_reasoning", "Conflicting Gemini thinking levels", configuration?.param ?? "reasoning.effort");
5162
5208
  const thinkingConfig = policy?.geminiThinkingBudget !== undefined ? { thinkingBudget: integer(policy.geminiThinkingBudget, "reasoningPolicy.geminiThinkingBudget", -1) } : { thinkingLevel: string(level, "reasoningPolicy.geminiThinkingLevel", true) };
5163
5209
  body.generationConfig = { ...record(body.generationConfig ?? {}, "generationConfig"), thinkingConfig };
5164
5210
  }
5165
5211
  if (mappedEffort !== undefined || sourceThinking !== undefined || policy?.anthropicThinkingBudget !== undefined)
5166
5212
  diagnostics.push({ param: "reasoning", action: "mapped", reason: "explicit_verified_wire_policy" });
5167
- return { body, canonicalHistory: geminiHistory?.canonicalHistory(decoded.canonicalInput) ?? decoded.canonicalInput, diagnostics, toolNames: decoded.toolNames, streaming: b.stream === true };
5213
+ return {
5214
+ body,
5215
+ canonicalHistory: geminiHistory?.canonicalHistory(decoded.canonicalInput) ?? decoded.canonicalInput,
5216
+ diagnostics,
5217
+ toolNames: decoded.toolNames,
5218
+ streaming: b.stream === true,
5219
+ ...configuration ? { effectiveReasoningEffort: configuration.effort } : {}
5220
+ };
5168
5221
  }
5169
5222
  function renderGemini(chat, context, input, signedParts, diagnostics) {
5170
5223
  const result = { contents: [] }, contents = result.contents, system = [], calls = new Map;
@@ -6069,7 +6122,7 @@ class CanonicalStreamRenderer {
6069
6122
  var LLM_PROTOCOLS = ["responses", "chat_completions", "anthropic_messages", "gemini_generate_content"];
6070
6123
 
6071
6124
  // packages/llms/src/protocol-session/index.ts
6072
- var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.4";
6125
+ var PROTOCOL_CONVERSION_RULES_VERSION = "1.0.5";
6073
6126
  function describeProtocolConversion() {
6074
6127
  return {
6075
6128
  rulesVersion: PROTOCOL_CONVERSION_RULES_VERSION,
@@ -6703,7 +6756,7 @@ class AgentRelay {
6703
6756
  }
6704
6757
 
6705
6758
  // plugins/llm-protocol-adapter/server/service.ts
6706
- var REASONING_RULES_VERSION = "2026-10-27.1";
6759
+ var REASONING_RULES_VERSION = "2026-11-11.1";
6707
6760
  var concrete = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max"]);
6708
6761
  var effortProtocols = new Set(["responses", "chat_completions", "anthropic_messages", "gemini_generate_content"]);
6709
6762
  var geminiEfforts = new Set(["minimal", "low", "medium", "high"]);
@@ -6820,6 +6873,11 @@ function conversionService(catalog, worker, history, runBackground) {
6820
6873
  selected = effort;
6821
6874
  }
6822
6875
  const result = engine.convertRequest(raw);
6876
+ if (result.effectiveReasoningEffort !== undefined) {
6877
+ if (!profile?.supportedEfforts.includes(result.effectiveReasoningEffort))
6878
+ fail2("reasoning.effort");
6879
+ selected = result.effectiveReasoningEffort;
6880
+ }
6823
6881
  rewrittenDeveloper = false;
6824
6882
  if (deepseekChat) {
6825
6883
  for (const message of chatMessages(result.body))
@@ -6937,4 +6995,4 @@ export {
6937
6995
  control_default as default
6938
6996
  };
6939
6997
 
6940
- //# debugId=DF2F30C0215A142764756E2164756E21
6998
+ //# debugId=03634829068B51AD64756E2164756E21