@jeffusion/bungee-core 5.23.0 → 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.
- package/dist/config-storage-worker.js +3 -1
- package/dist/main.js +2756 -295
- package/dist/plugins/chatgpt-oauth/index.js +92 -20
- package/dist/plugins/chatgpt-oauth/index.js.map +4 -4
- package/dist/plugins/codex-router/control.js +606 -2
- package/dist/plugins/codex-router/control.js.map +20 -5
- package/dist/plugins/codex-router/index.js +2459 -94
- package/dist/plugins/codex-router/index.js.map +20 -8
- package/dist/plugins/codex-router/manifest.json +14 -14
- package/dist/plugins/llm-protocol-adapter/control.js +96 -21
- package/dist/plugins/llm-protocol-adapter/control.js.map +8 -7
- package/dist/plugins/llm-protocol-adapter/index.js +134 -38
- package/dist/plugins/llm-protocol-adapter/index.js.map +11 -10
- package/dist/plugins/model-mapping/control.js +1 -1
- package/dist/plugins/model-mapping/control.js.map +3 -3
- package/dist/plugins/model-mapping/index.js +48 -17
- package/dist/plugins/model-mapping/index.js.map +6 -5
- package/dist/plugins/model-mapping/manifest.json +50 -6
- package/dist/plugins/models-dev/control.js +1 -1
- package/dist/plugins/models-dev/control.js.map +3 -3
- package/dist/plugins/models-dev/index.js +1 -1
- package/dist/plugins/models-dev/index.js.map +3 -3
- package/dist/plugins/token-metering/index.js +1 -1
- package/dist/plugins/token-metering/index.js.map +1 -1
- package/dist/plugins/token-stats/control.js +1 -1
- package/dist/plugins/token-stats/control.js.map +3 -3
- package/dist/plugins/token-stats/index.js +1 -1
- package/dist/plugins/token-stats/index.js.map +3 -3
- package/package.json +2 -2
|
@@ -25,25 +25,18 @@
|
|
|
25
25
|
"llm-protocol-adapter": "^1.0.0"
|
|
26
26
|
},
|
|
27
27
|
"services": {
|
|
28
|
-
"provides": [
|
|
29
|
-
"consumes": [
|
|
28
|
+
"provides": [
|
|
30
29
|
{
|
|
31
|
-
"id": "
|
|
30
|
+
"id": "codex-router.catalog-validators.v1",
|
|
32
31
|
"version": 1,
|
|
33
32
|
"process": "control",
|
|
34
|
-
"
|
|
35
|
-
|
|
36
|
-
|
|
33
|
+
"kind": "rpc"
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"consumes": [
|
|
37
37
|
{
|
|
38
38
|
"id": "models-dev.catalog.v1",
|
|
39
39
|
"version": 1,
|
|
40
|
-
"process": "worker",
|
|
41
|
-
"plugin": "models-dev",
|
|
42
|
-
"kind": "local"
|
|
43
|
-
},
|
|
44
|
-
{
|
|
45
|
-
"id": "models-dev.capabilities.v1",
|
|
46
|
-
"version": 1,
|
|
47
40
|
"process": "control",
|
|
48
41
|
"plugin": "models-dev",
|
|
49
42
|
"kind": "local"
|
|
@@ -51,7 +44,7 @@
|
|
|
51
44
|
{
|
|
52
45
|
"id": "models-dev.capabilities.v1",
|
|
53
46
|
"version": 1,
|
|
54
|
-
"process": "
|
|
47
|
+
"process": "control",
|
|
55
48
|
"plugin": "models-dev",
|
|
56
49
|
"kind": "local"
|
|
57
50
|
},
|
|
@@ -75,6 +68,13 @@
|
|
|
75
68
|
"process": "worker",
|
|
76
69
|
"plugin": "llm-protocol-adapter",
|
|
77
70
|
"kind": "rpc"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"id": "codex-router.catalog-validators.v1",
|
|
74
|
+
"version": 1,
|
|
75
|
+
"process": "worker",
|
|
76
|
+
"plugin": "codex-router",
|
|
77
|
+
"kind": "rpc"
|
|
78
78
|
}
|
|
79
79
|
]
|
|
80
80
|
},
|
|
@@ -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
|
|
|
@@ -5886,7 +5912,8 @@ async function relayPayload(result, param, signal) {
|
|
|
5886
5912
|
if (result.status < 200 || result.status >= 300)
|
|
5887
5913
|
throw new DataAdmissionError(result.status === 401 || result.status === 429 ? result.status : 502, "llm_adapter_relay_upstream_failed", undefined, { param, message: `Relay upstream rejected the request (HTTP ${result.status})` });
|
|
5888
5914
|
let response;
|
|
5889
|
-
|
|
5915
|
+
const contentType = result.bodyHandle.identity.contentType;
|
|
5916
|
+
if (contentType === "" || contentType.includes("text/event-stream") || contentType.includes("application/octet-stream")) {
|
|
5890
5917
|
const iterator = result.bodyHandle.events({ id: "llm-adapter.relay", mandatory: true, signal })[Symbol.asyncIterator]();
|
|
5891
5918
|
let call, callIndex, args = "", argumentBytes = 0, argumentsDone, outputDone = false, terminal = false, done = false;
|
|
5892
5919
|
const reasoning = new Map;
|
|
@@ -5976,7 +6003,7 @@ async function relayPayload(result, param, signal) {
|
|
|
5976
6003
|
} finally {
|
|
5977
6004
|
await iterator.return?.();
|
|
5978
6005
|
}
|
|
5979
|
-
} else if (
|
|
6006
|
+
} else if (contentType.includes("json"))
|
|
5980
6007
|
response = await result.bodyHandle.json({ id: "llm-adapter.relay", mandatory: true, signal });
|
|
5981
6008
|
else
|
|
5982
6009
|
invalid(param);
|
|
@@ -6215,10 +6242,25 @@ class AgentRelay {
|
|
|
6215
6242
|
}
|
|
6216
6243
|
|
|
6217
6244
|
// plugins/llm-protocol-adapter/server/service.ts
|
|
6218
|
-
var REASONING_RULES_VERSION = "2026-10-
|
|
6245
|
+
var REASONING_RULES_VERSION = "2026-10-12.1";
|
|
6219
6246
|
var concrete = new Set(["none", "minimal", "low", "medium", "high", "xhigh", "max"]);
|
|
6220
|
-
function
|
|
6221
|
-
|
|
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;
|
|
6222
6264
|
}
|
|
6223
6265
|
function rule(provider, model, protocol) {
|
|
6224
6266
|
if (provider === "zai" && ["glm-5.3", "glm-5.3-flash"].includes(model) && protocol === "chat_completions")
|
|
@@ -6232,7 +6274,6 @@ function rule(provider, model, protocol) {
|
|
|
6232
6274
|
return null;
|
|
6233
6275
|
}
|
|
6234
6276
|
function resolveCapabilities(catalog, context) {
|
|
6235
|
-
context = { ...context, model: catalogModel(context.provider, context.model) };
|
|
6236
6277
|
const info = catalog.model(context);
|
|
6237
6278
|
if (!info)
|
|
6238
6279
|
return null;
|
|
@@ -6294,8 +6335,15 @@ function conversionService(catalog, worker, history, runBackground) {
|
|
|
6294
6335
|
createSession(context) {
|
|
6295
6336
|
if (!worker)
|
|
6296
6337
|
throw new Error("llm_adapter_conversion_requires_worker");
|
|
6297
|
-
const
|
|
6298
|
-
const
|
|
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;
|
|
6299
6347
|
let selected = context.selectedEffort;
|
|
6300
6348
|
const passthrough = context.sourceProtocol === context.targetProtocol;
|
|
6301
6349
|
if (!passthrough && selected !== undefined && (!profile || !profile.supportedEfforts.includes(selected)))
|
|
@@ -6328,29 +6376,56 @@ function conversionService(catalog, worker, history, runBackground) {
|
|
|
6328
6376
|
engine.dispose();
|
|
6329
6377
|
}
|
|
6330
6378
|
},
|
|
6331
|
-
validateAttempt({ model, protocol, body, url }) {
|
|
6379
|
+
validateAttempt({ model, protocol, body, url, modelIdentity }) {
|
|
6332
6380
|
if (disposed)
|
|
6333
6381
|
throw new Error("llm_adapter_session_disposed");
|
|
6334
6382
|
if (protocol !== context.targetProtocol)
|
|
6335
6383
|
throw new ResponsesCodecError("target_protocol_mismatch", "Actual target protocol differs from the session", "url");
|
|
6336
6384
|
if (url) {
|
|
6337
|
-
|
|
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
|
+
}
|
|
6338
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);
|
|
6339
6392
|
if (!valid)
|
|
6340
6393
|
throw new ResponsesCodecError("target_protocol_mismatch", "Actual target URL does not implement the session protocol", "url");
|
|
6341
6394
|
}
|
|
6342
|
-
const
|
|
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;
|
|
6343
6409
|
if (selected !== undefined) {
|
|
6344
|
-
if (passthrough &&
|
|
6345
|
-
|
|
6346
|
-
|
|
6347
|
-
|
|
6348
|
-
|
|
6349
|
-
|
|
6350
|
-
|
|
6351
|
-
|
|
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;
|
|
6352
6421
|
}
|
|
6353
|
-
return {
|
|
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
|
+
};
|
|
6354
6429
|
}
|
|
6355
6430
|
};
|
|
6356
6431
|
return session;
|
|
@@ -6390,4 +6465,4 @@ export {
|
|
|
6390
6465
|
control_default as default
|
|
6391
6466
|
};
|
|
6392
6467
|
|
|
6393
|
-
//# debugId=
|
|
6468
|
+
//# debugId=FD48268D956989F464756E2164756E21
|