@jeffusion/bungee-core 5.23.1 → 5.23.2

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.
@@ -5849,6 +5849,32 @@ function validateStreamEnvelope(raw, protocol) {
5849
5849
  validateUsage(e.usage, protocol);
5850
5850
  }
5851
5851
  }
5852
+ // packages/llms/src/protocol-session/endpoint.ts
5853
+ function protocolRequestModel(protocol, body, url) {
5854
+ if (protocol === "gemini_generate_content") {
5855
+ let path;
5856
+ try {
5857
+ path = new URL(url).pathname;
5858
+ } catch {
5859
+ return fail("invalid_payload", "A valid Gemini target URL is required", "url");
5860
+ }
5861
+ const match = path.match(/\/models\/([^/]+):(?:streamGenerateContent|generateContent)$/);
5862
+ if (!match)
5863
+ return fail("invalid_payload", "Gemini target URL has no terminal model", "url");
5864
+ try {
5865
+ const model = decodeURIComponent(match[1]);
5866
+ if (model)
5867
+ return model;
5868
+ } catch {
5869
+ return fail("invalid_payload", "Gemini target model encoding is invalid", "url");
5870
+ }
5871
+ return fail("invalid_payload", "Gemini target model is required", "url");
5872
+ }
5873
+ const model = body?.model;
5874
+ if (typeof model !== "string" || !model)
5875
+ return fail("invalid_payload", "Target model is required", "model");
5876
+ return model;
5877
+ }
5852
5878
  // plugins/llm-protocol-adapter/server/relay.ts
5853
5879
  import { createHash } from "crypto";
5854
5880
 
@@ -6216,10 +6242,25 @@ class AgentRelay {
6216
6242
  }
6217
6243
 
6218
6244
  // plugins/llm-protocol-adapter/server/service.ts
6219
- var REASONING_RULES_VERSION = "2026-10-10.3";
6245
+ var REASONING_RULES_VERSION = "2026-10-12.1";
6220
6246
  var concrete = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max"]);
6221
- function catalogModel(provider, model) {
6222
- return provider === "zai" && model === "GLM-5.3-Flash" ? "glm-5.3-flash" : model;
6247
+ function identityError(code, message) {
6248
+ throw new ResponsesCodecError(code, message, "modelIdentity");
6249
+ }
6250
+ function parseModelIdentity(value) {
6251
+ if (value === undefined)
6252
+ return;
6253
+ const object = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
6254
+ const identifier = (v) => typeof v === "string" && v.length > 0 && v === v.trim();
6255
+ if (!object(value) || Object.keys(value).length !== 2 || !Object.keys(value).every((key) => ["wireModel", "catalogModel"].includes(key)) || !identifier(value.wireModel) || !object(value.catalogModel) || Object.keys(value.catalogModel).length !== 2 || !Object.keys(value.catalogModel).every((key) => ["provider", "model"].includes(key)) || !identifier(value.catalogModel.provider) || !identifier(value.catalogModel.model))
6256
+ throw new ResponsesCodecError("invalid_model_identity", "Model identity declaration is invalid", "modelIdentity");
6257
+ return { wireModel: value.wireModel, catalogModel: { provider: value.catalogModel.provider, model: value.catalogModel.model } };
6258
+ }
6259
+ function checkedIdentity(value, model) {
6260
+ const identity = parseModelIdentity(value);
6261
+ if (identity && identity.wireModel !== model)
6262
+ identityError("model_identity_mismatch", "Declared wire model differs from the actual target");
6263
+ return identity;
6223
6264
  }
6224
6265
  function rule(provider, model, protocol) {
6225
6266
  if (provider === "zai" && ["glm-5.3", "glm-5.3-flash"].includes(model) && protocol === "chat_completions")
@@ -6233,7 +6274,6 @@ function rule(provider, model, protocol) {
6233
6274
  return null;
6234
6275
  }
6235
6276
  function resolveCapabilities(catalog, context) {
6236
- context = { ...context, model: catalogModel(context.provider, context.model) };
6237
6277
  const info = catalog.model(context);
6238
6278
  if (!info)
6239
6279
  return null;
@@ -6295,8 +6335,15 @@ function conversionService(catalog, worker, history, runBackground) {
6295
6335
  createSession(context) {
6296
6336
  if (!worker)
6297
6337
  throw new Error("llm_adapter_conversion_requires_worker");
6298
- const info = context.profile ?? catalog.model({ provider: context.provider, model: catalogModel(context.provider, context.model) });
6299
- const profile = context.profile ? structuredClone(context.profile) : info ? resolveCapabilities(catalog, { provider: info.provider, model: context.model, targetProtocol: context.targetProtocol }) : undefined;
6338
+ const declaration = checkedIdentity(context.modelIdentity, context.model);
6339
+ const restrictions = context.restrictions ? structuredClone(context.restrictions) : undefined;
6340
+ const reference = declaration?.catalogModel ?? { provider: context.provider, model: context.model };
6341
+ const info = context.profile ?? catalog.model(reference);
6342
+ let profile = context.profile ? structuredClone(context.profile) : info ? resolveCapabilities(catalog, { provider: info.provider, model: info.model, targetProtocol: context.targetProtocol, restrictions }) : null;
6343
+ if (declaration && (!profile || profile.provider !== reference.provider || profile.model !== reference.model))
6344
+ identityError("model_identity_unavailable", "Declared catalog model is unavailable");
6345
+ const entryProfile = profile;
6346
+ let catalogVersion = profile?.catalogVersion ?? null;
6300
6347
  let selected = context.selectedEffort;
6301
6348
  const passthrough = context.sourceProtocol === context.targetProtocol;
6302
6349
  if (!passthrough && selected !== undefined && (!profile || !profile.supportedEfforts.includes(selected)))
@@ -6329,29 +6376,56 @@ function conversionService(catalog, worker, history, runBackground) {
6329
6376
  engine.dispose();
6330
6377
  }
6331
6378
  },
6332
- validateAttempt({ model, protocol, body, url }) {
6379
+ validateAttempt({ model, protocol, body, url, modelIdentity }) {
6333
6380
  if (disposed)
6334
6381
  throw new Error("llm_adapter_session_disposed");
6335
6382
  if (protocol !== context.targetProtocol)
6336
6383
  throw new ResponsesCodecError("target_protocol_mismatch", "Actual target protocol differs from the session", "url");
6337
6384
  if (url) {
6338
- const path = new URL(url).pathname;
6385
+ let path;
6386
+ try {
6387
+ path = new URL(url).pathname;
6388
+ } catch {
6389
+ throw new ResponsesCodecError("target_protocol_mismatch", "Actual target URL is invalid", "url");
6390
+ }
6339
6391
  const valid = protocol === "responses" ? /\/responses$/.test(path) : protocol === "chat_completions" ? /\/chat\/completions$/.test(path) : protocol === "anthropic_messages" ? /\/messages$/.test(path) : /:(?:streamGenerateContent|generateContent)$/.test(path);
6340
6392
  if (!valid)
6341
6393
  throw new ResponsesCodecError("target_protocol_mismatch", "Actual target URL does not implement the session protocol", "url");
6342
6394
  }
6343
- const actual = profile && profile.model === catalogModel(profile.provider, model) ? profile : profile ? resolveCapabilities(catalog, { provider: profile.provider, model, targetProtocol: protocol }) : null;
6395
+ const actualModel = protocolRequestModel(protocol, body, url);
6396
+ const identity = checkedIdentity(modelIdentity, actualModel);
6397
+ if (model !== actualModel)
6398
+ identityError("model_identity_mismatch", "Model argument differs from the actual target");
6399
+ model = actualModel;
6400
+ const reference = identity?.catalogModel ?? { provider: profile?.provider ?? context.provider, model };
6401
+ const sameIdentity = !!profile && reference.provider === profile.provider && reference.model === profile.model;
6402
+ const info = sameIdentity ? profile : catalog.model(reference);
6403
+ const actual = sameIdentity ? profile : info ? resolveCapabilities(catalog, { provider: info.provider, model: info.model, targetProtocol: protocol, restrictions }) : null;
6404
+ if (identity && !actual)
6405
+ identityError("model_identity_unavailable", "Declared catalog model is unavailable");
6406
+ if (actual && catalogVersion !== null && actual.catalogVersion !== catalogVersion)
6407
+ identityError("model_identity_catalog_changed", "Target catalog version differs from the generation snapshot");
6408
+ const sameNativeIdentity = entryProfile ? !!actual && actual.provider === entryProfile.provider && actual.model === entryProfile.model : !identity && model === context.model;
6344
6409
  if (selected !== undefined) {
6345
- if (passthrough && model === context.model && wireEffort(body, protocol) === selected)
6346
- return { model, effort: selected, catalogVersion: profile?.catalogVersion ?? null, rulesVersion: REASONING_RULES_VERSION };
6347
- if (!actual || actual.catalogVersion !== profile?.catalogVersion || actual.rulesVersion !== profile?.rulesVersion || !actual.supportedEfforts.includes(selected) || wireEffort(body, protocol) !== selected)
6348
- fail2("reasoning.effort");
6349
- if (protocol === "anthropic_messages" && body?.thinking?.type !== "adaptive")
6350
- fail2("thinking.type");
6351
- if (protocol === "chat_completions" && profile?.provider === "zai" && body?.thinking?.type !== "enabled")
6352
- fail2("thinking.type");
6410
+ if (!(passthrough && sameNativeIdentity && wireEffort(body, protocol) === selected)) {
6411
+ if (!entryProfile || !actual || actual.rulesVersion !== entryProfile.rulesVersion || !actual.supportedEfforts.includes(selected) || wireEffort(body, protocol) !== selected)
6412
+ fail2("reasoning.effort");
6413
+ if (protocol === "anthropic_messages" && body?.thinking?.type !== "adaptive")
6414
+ fail2("thinking.type");
6415
+ if (protocol === "chat_completions" && actual.provider === "zai" && body?.thinking?.type !== "enabled")
6416
+ fail2("thinking.type");
6417
+ }
6418
+ } else if (!profile && actual && identity) {
6419
+ profile = structuredClone(actual);
6420
+ catalogVersion = actual.catalogVersion;
6353
6421
  }
6354
- return { model, effort: selected ?? null, catalogVersion: profile?.catalogVersion ?? null, rulesVersion: REASONING_RULES_VERSION };
6422
+ return {
6423
+ model,
6424
+ catalogModel: actual ? { provider: actual.provider, model: actual.model } : null,
6425
+ effort: selected ?? null,
6426
+ catalogVersion,
6427
+ rulesVersion: REASONING_RULES_VERSION
6428
+ };
6355
6429
  }
6356
6430
  };
6357
6431
  return session;
@@ -6391,4 +6465,4 @@ export {
6391
6465
  control_default as default
6392
6466
  };
6393
6467
 
6394
- //# debugId=6F7D783A1BAB181564756E2164756E21
6468
+ //# debugId=FD48268D956989F464756E2164756E21