@jeffusion/bungee-llms 4.3.0 → 4.4.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 +142 -214
- package/dist/plugin-api.js +104 -176
- package/package.json +2 -2
package/dist/index.js
CHANGED
|
@@ -1,130 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
function __accessProp(key) {
|
|
8
|
-
return this[key];
|
|
9
|
-
}
|
|
10
|
-
var __toESMCache_node;
|
|
11
|
-
var __toESMCache_esm;
|
|
12
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
-
var canCache = mod != null && typeof mod === "object";
|
|
14
|
-
if (canCache) {
|
|
15
|
-
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
-
var cached = cache.get(mod);
|
|
17
|
-
if (cached)
|
|
18
|
-
return cached;
|
|
19
|
-
}
|
|
20
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
-
for (let key of __getOwnPropNames(mod))
|
|
23
|
-
if (!__hasOwnProp.call(to, key))
|
|
24
|
-
__defProp(to, key, {
|
|
25
|
-
get: __accessProp.bind(mod, key),
|
|
26
|
-
enumerable: true
|
|
27
|
-
});
|
|
28
|
-
if (canCache)
|
|
29
|
-
cache.set(mod, to);
|
|
30
|
-
return to;
|
|
31
|
-
};
|
|
32
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
-
|
|
34
|
-
// ../../node_modules/base64-js/index.js
|
|
35
|
-
var require_base64_js = __commonJS((exports) => {
|
|
36
|
-
exports.byteLength = byteLength;
|
|
37
|
-
exports.toByteArray = toByteArray;
|
|
38
|
-
exports.fromByteArray = fromByteArray;
|
|
39
|
-
var lookup = [];
|
|
40
|
-
var revLookup = [];
|
|
41
|
-
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
42
|
-
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
43
|
-
for (i = 0, len = code.length;i < len; ++i) {
|
|
44
|
-
lookup[i] = code[i];
|
|
45
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
46
|
-
}
|
|
47
|
-
var i;
|
|
48
|
-
var len;
|
|
49
|
-
revLookup[45] = 62;
|
|
50
|
-
revLookup[95] = 63;
|
|
51
|
-
function getLens(b64) {
|
|
52
|
-
var len2 = b64.length;
|
|
53
|
-
if (len2 % 4 > 0) {
|
|
54
|
-
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
55
|
-
}
|
|
56
|
-
var validLen = b64.indexOf("=");
|
|
57
|
-
if (validLen === -1)
|
|
58
|
-
validLen = len2;
|
|
59
|
-
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
60
|
-
return [validLen, placeHoldersLen];
|
|
61
|
-
}
|
|
62
|
-
function byteLength(b64) {
|
|
63
|
-
var lens = getLens(b64);
|
|
64
|
-
var validLen = lens[0];
|
|
65
|
-
var placeHoldersLen = lens[1];
|
|
66
|
-
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
67
|
-
}
|
|
68
|
-
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
69
|
-
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
70
|
-
}
|
|
71
|
-
function toByteArray(b64) {
|
|
72
|
-
var tmp;
|
|
73
|
-
var lens = getLens(b64);
|
|
74
|
-
var validLen = lens[0];
|
|
75
|
-
var placeHoldersLen = lens[1];
|
|
76
|
-
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
77
|
-
var curByte = 0;
|
|
78
|
-
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
79
|
-
var i2;
|
|
80
|
-
for (i2 = 0;i2 < len2; i2 += 4) {
|
|
81
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
82
|
-
arr[curByte++] = tmp >> 16 & 255;
|
|
83
|
-
arr[curByte++] = tmp >> 8 & 255;
|
|
84
|
-
arr[curByte++] = tmp & 255;
|
|
85
|
-
}
|
|
86
|
-
if (placeHoldersLen === 2) {
|
|
87
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
88
|
-
arr[curByte++] = tmp & 255;
|
|
89
|
-
}
|
|
90
|
-
if (placeHoldersLen === 1) {
|
|
91
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
92
|
-
arr[curByte++] = tmp >> 8 & 255;
|
|
93
|
-
arr[curByte++] = tmp & 255;
|
|
94
|
-
}
|
|
95
|
-
return arr;
|
|
96
|
-
}
|
|
97
|
-
function tripletToBase64(num) {
|
|
98
|
-
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
99
|
-
}
|
|
100
|
-
function encodeChunk(uint8, start, end) {
|
|
101
|
-
var tmp;
|
|
102
|
-
var output = [];
|
|
103
|
-
for (var i2 = start;i2 < end; i2 += 3) {
|
|
104
|
-
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
105
|
-
output.push(tripletToBase64(tmp));
|
|
106
|
-
}
|
|
107
|
-
return output.join("");
|
|
108
|
-
}
|
|
109
|
-
function fromByteArray(uint8) {
|
|
110
|
-
var tmp;
|
|
111
|
-
var len2 = uint8.length;
|
|
112
|
-
var extraBytes = len2 % 3;
|
|
113
|
-
var parts = [];
|
|
114
|
-
var maxChunkLength = 16383;
|
|
115
|
-
for (var i2 = 0, len22 = len2 - extraBytes;i2 < len22; i2 += maxChunkLength) {
|
|
116
|
-
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
117
|
-
}
|
|
118
|
-
if (extraBytes === 1) {
|
|
119
|
-
tmp = uint8[len2 - 1];
|
|
120
|
-
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
121
|
-
} else if (extraBytes === 2) {
|
|
122
|
-
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
123
|
-
parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
124
|
-
}
|
|
125
|
-
return parts.join("");
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
2
|
// src/core/registry.ts
|
|
129
3
|
function normalizeProvider(provider) {
|
|
130
4
|
return String(provider).trim().toLowerCase();
|
|
@@ -1248,10 +1122,10 @@ class OpenAIToAnthropicRequestConversion {
|
|
|
1248
1122
|
}
|
|
1249
1123
|
if (role === "assistant") {
|
|
1250
1124
|
if (Array.isArray(message.tool_calls)) {
|
|
1251
|
-
const
|
|
1125
|
+
const content = [];
|
|
1252
1126
|
const assistantText = this.extractInstructionText(message.content);
|
|
1253
1127
|
if (assistantText) {
|
|
1254
|
-
|
|
1128
|
+
content.push({ type: "text", text: assistantText });
|
|
1255
1129
|
}
|
|
1256
1130
|
for (const toolCall of message.tool_calls) {
|
|
1257
1131
|
if (!isRecord2(toolCall) || toolCall.type !== "function" || !isRecord2(toolCall.function)) {
|
|
@@ -1264,15 +1138,15 @@ class OpenAIToAnthropicRequestConversion {
|
|
|
1264
1138
|
} catch {
|
|
1265
1139
|
argumentsObject = {};
|
|
1266
1140
|
}
|
|
1267
|
-
|
|
1141
|
+
content.push({
|
|
1268
1142
|
type: "tool_use",
|
|
1269
1143
|
id: typeof toolCall.id === "string" ? toolCall.id : "",
|
|
1270
1144
|
name: typeof toolCall.function.name === "string" ? toolCall.function.name : "",
|
|
1271
1145
|
input: argumentsObject
|
|
1272
1146
|
});
|
|
1273
1147
|
}
|
|
1274
|
-
if (
|
|
1275
|
-
anthropicMessages.push({ role: "assistant", content
|
|
1148
|
+
if (content.length > 0) {
|
|
1149
|
+
anthropicMessages.push({ role: "assistant", content });
|
|
1276
1150
|
}
|
|
1277
1151
|
continue;
|
|
1278
1152
|
}
|
|
@@ -2038,8 +1912,8 @@ class OpenAIMessagesCompatibilityNormalizer {
|
|
|
2038
1912
|
};
|
|
2039
1913
|
}
|
|
2040
1914
|
if (content === undefined) {
|
|
2041
|
-
const
|
|
2042
|
-
if (role === "assistant" &&
|
|
1915
|
+
const hasToolCalls = Array.isArray(rawMessage.tool_calls) && rawMessage.tool_calls.length > 0;
|
|
1916
|
+
if (role === "assistant" && hasToolCalls) {
|
|
2043
1917
|
this.ensureAssistantToolCallReasoningContent(normalizedMessage);
|
|
2044
1918
|
return {
|
|
2045
1919
|
ok: true,
|
|
@@ -2568,11 +2442,11 @@ class LLMSRuntime {
|
|
|
2568
2442
|
this.conversionService = options.conversionService ?? new LLMProtocolConversionService(this.adapterRegistry);
|
|
2569
2443
|
this.providerCatalog = options.providerCatalog ?? new LLMProviderCatalog;
|
|
2570
2444
|
}
|
|
2571
|
-
registerAdapter(
|
|
2572
|
-
this.adapterRegistry.register(
|
|
2445
|
+
registerAdapter(adapter, descriptor) {
|
|
2446
|
+
this.adapterRegistry.register(adapter);
|
|
2573
2447
|
const providerDescriptor = descriptor ?? {
|
|
2574
|
-
provider:
|
|
2575
|
-
displayName: String(
|
|
2448
|
+
provider: adapter.provider,
|
|
2449
|
+
displayName: String(adapter.provider)
|
|
2576
2450
|
};
|
|
2577
2451
|
this.providerCatalog.register(providerDescriptor);
|
|
2578
2452
|
}
|
|
@@ -2998,10 +2872,10 @@ class AnthropicToGeminiConverter {
|
|
|
2998
2872
|
return ctx.response;
|
|
2999
2873
|
}
|
|
3000
2874
|
if (geminiBody.totalTokens !== undefined) {
|
|
3001
|
-
const
|
|
2875
|
+
const anthropicBody = {
|
|
3002
2876
|
input_tokens: geminiBody.totalTokens
|
|
3003
2877
|
};
|
|
3004
|
-
return new Response(JSON.stringify(
|
|
2878
|
+
return new Response(JSON.stringify(anthropicBody), {
|
|
3005
2879
|
status: ctx.response.status,
|
|
3006
2880
|
statusText: ctx.response.statusText,
|
|
3007
2881
|
headers: ctx.response.headers
|
|
@@ -4242,9 +4116,9 @@ class AnthropicToOpenAIConverter {
|
|
|
4242
4116
|
const existing = ctx.streamState.get(key);
|
|
4243
4117
|
if (typeof existing === "number" && Number.isFinite(existing))
|
|
4244
4118
|
return existing;
|
|
4245
|
-
const
|
|
4246
|
-
ctx.streamState.set(key,
|
|
4247
|
-
return
|
|
4119
|
+
const assigned = this.nextResponsesContentIndex(ctx);
|
|
4120
|
+
ctx.streamState.set(key, assigned);
|
|
4121
|
+
return assigned;
|
|
4248
4122
|
}
|
|
4249
4123
|
const fallback = ctx.streamState.get("resp_fallback_text_index");
|
|
4250
4124
|
if (typeof fallback === "number" && Number.isFinite(fallback))
|
|
@@ -4448,7 +4322,7 @@ class AnthropicToOpenAIConverter {
|
|
|
4448
4322
|
}
|
|
4449
4323
|
const message = choice.message;
|
|
4450
4324
|
const content = [];
|
|
4451
|
-
const
|
|
4325
|
+
const hasToolCalls = Array.isArray(message.tool_calls) && message.tool_calls.length > 0;
|
|
4452
4326
|
if (message.refusal && typeof message.refusal === "string") {
|
|
4453
4327
|
content.push({
|
|
4454
4328
|
type: "text",
|
|
@@ -4471,7 +4345,7 @@ class AnthropicToOpenAIConverter {
|
|
|
4471
4345
|
}
|
|
4472
4346
|
}
|
|
4473
4347
|
}
|
|
4474
|
-
if (
|
|
4348
|
+
if (hasToolCalls) {
|
|
4475
4349
|
for (const tc of message.tool_calls) {
|
|
4476
4350
|
content.push({
|
|
4477
4351
|
type: "tool_use",
|
|
@@ -4481,7 +4355,7 @@ class AnthropicToOpenAIConverter {
|
|
|
4481
4355
|
});
|
|
4482
4356
|
}
|
|
4483
4357
|
}
|
|
4484
|
-
if (!
|
|
4358
|
+
if (!hasToolCalls && message.function_call) {
|
|
4485
4359
|
const functionCall = message.function_call;
|
|
4486
4360
|
const hasArguments = functionCall.arguments !== undefined;
|
|
4487
4361
|
const name = typeof functionCall.name === "string" ? functionCall.name : "";
|
|
@@ -4681,11 +4555,11 @@ class AnthropicToOpenAIConverter {
|
|
|
4681
4555
|
ctx.streamState.set("legacy_function_name", functionCall.name);
|
|
4682
4556
|
}
|
|
4683
4557
|
if (!ctx.streamState.has("legacy_function_index")) {
|
|
4684
|
-
const
|
|
4685
|
-
ctx.streamState.set("legacy_function_index",
|
|
4558
|
+
const index = this.allocateChatContentBlockIndex(ctx, 0, 0);
|
|
4559
|
+
ctx.streamState.set("legacy_function_index", index);
|
|
4686
4560
|
events.push({
|
|
4687
4561
|
type: "content_block_start",
|
|
4688
|
-
index
|
|
4562
|
+
index,
|
|
4689
4563
|
content_block: {
|
|
4690
4564
|
type: "tool_use",
|
|
4691
4565
|
id: "",
|
|
@@ -4770,13 +4644,13 @@ class AnthropicToOpenAIConverter {
|
|
|
4770
4644
|
ctx.streamState.set("flushed", true);
|
|
4771
4645
|
const pendingStopReason = ctx.streamState.get("pending_stop_reason");
|
|
4772
4646
|
if (pendingStopReason) {
|
|
4773
|
-
const
|
|
4647
|
+
const latestUsage = ctx.streamState.get("latest_usage");
|
|
4774
4648
|
const out = [{
|
|
4775
4649
|
type: "message_delta",
|
|
4776
4650
|
delta: {
|
|
4777
4651
|
stop_reason: pendingStopReason
|
|
4778
4652
|
},
|
|
4779
|
-
...
|
|
4653
|
+
...latestUsage && { usage: latestUsage }
|
|
4780
4654
|
}, {
|
|
4781
4655
|
type: "message_stop"
|
|
4782
4656
|
}];
|
|
@@ -5865,9 +5739,9 @@ class GeminiToOpenAIConverter {
|
|
|
5865
5739
|
}
|
|
5866
5740
|
} else {
|
|
5867
5741
|
const textParts = parts.filter((p) => p.text);
|
|
5868
|
-
const
|
|
5869
|
-
if (
|
|
5870
|
-
messages.push({ role, content
|
|
5742
|
+
const content = textParts.map((p) => p.text).join("");
|
|
5743
|
+
if (content) {
|
|
5744
|
+
messages.push({ role, content });
|
|
5871
5745
|
}
|
|
5872
5746
|
}
|
|
5873
5747
|
}
|
|
@@ -6145,8 +6019,8 @@ class OpenAIToAnthropicConverter {
|
|
|
6145
6019
|
}
|
|
6146
6020
|
if (!ctx.response.ok) {
|
|
6147
6021
|
try {
|
|
6148
|
-
const
|
|
6149
|
-
const errorBody = await
|
|
6022
|
+
const responseClone = ctx.response.clone();
|
|
6023
|
+
const errorBody = await responseClone.json();
|
|
6150
6024
|
if (!this.isLikelyAnthropicErrorBody(errorBody)) {
|
|
6151
6025
|
return ctx.response;
|
|
6152
6026
|
}
|
|
@@ -6633,8 +6507,8 @@ class OpenAIToGeminiConverter {
|
|
|
6633
6507
|
}
|
|
6634
6508
|
if (!ctx.response.ok) {
|
|
6635
6509
|
try {
|
|
6636
|
-
const
|
|
6637
|
-
const errorBody = await
|
|
6510
|
+
const responseClone = ctx.response.clone();
|
|
6511
|
+
const errorBody = await responseClone.json();
|
|
6638
6512
|
if (!this.isLikelyGeminiErrorBody(errorBody)) {
|
|
6639
6513
|
return ctx.response;
|
|
6640
6514
|
}
|
|
@@ -6904,10 +6778,64 @@ var TOKEN_ACCOUNTING_AUTHORITIES = [
|
|
|
6904
6778
|
"none"
|
|
6905
6779
|
];
|
|
6906
6780
|
var TOKEN_ACCOUNTING_OUTCOMES = ["completed", "aborted", "failed"];
|
|
6781
|
+
// ../../node_modules/base64-js/index.js
|
|
6782
|
+
var $toByteArray = toByteArray;
|
|
6783
|
+
var lookup = [];
|
|
6784
|
+
var revLookup = [];
|
|
6785
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
6786
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
6787
|
+
for (i = 0, len = code.length;i < len; ++i) {
|
|
6788
|
+
lookup[i] = code[i];
|
|
6789
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
6790
|
+
}
|
|
6791
|
+
var i;
|
|
6792
|
+
var len;
|
|
6793
|
+
revLookup[45] = 62;
|
|
6794
|
+
revLookup[95] = 63;
|
|
6795
|
+
function getLens(b64) {
|
|
6796
|
+
var len = b64.length;
|
|
6797
|
+
if (len % 4 > 0) {
|
|
6798
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
6799
|
+
}
|
|
6800
|
+
var validLen = b64.indexOf("=");
|
|
6801
|
+
if (validLen === -1)
|
|
6802
|
+
validLen = len;
|
|
6803
|
+
var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
|
|
6804
|
+
return [validLen, placeHoldersLen];
|
|
6805
|
+
}
|
|
6806
|
+
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
6807
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
6808
|
+
}
|
|
6809
|
+
function toByteArray(b64) {
|
|
6810
|
+
var tmp;
|
|
6811
|
+
var lens = getLens(b64);
|
|
6812
|
+
var validLen = lens[0];
|
|
6813
|
+
var placeHoldersLen = lens[1];
|
|
6814
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
6815
|
+
var curByte = 0;
|
|
6816
|
+
var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
6817
|
+
var i;
|
|
6818
|
+
for (i = 0;i < len; i += 4) {
|
|
6819
|
+
tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
|
|
6820
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
6821
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
6822
|
+
arr[curByte++] = tmp & 255;
|
|
6823
|
+
}
|
|
6824
|
+
if (placeHoldersLen === 2) {
|
|
6825
|
+
tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
|
|
6826
|
+
arr[curByte++] = tmp & 255;
|
|
6827
|
+
}
|
|
6828
|
+
if (placeHoldersLen === 1) {
|
|
6829
|
+
tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
|
|
6830
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
6831
|
+
arr[curByte++] = tmp & 255;
|
|
6832
|
+
}
|
|
6833
|
+
return arr;
|
|
6834
|
+
}
|
|
6835
|
+
|
|
6907
6836
|
// ../../node_modules/js-tiktoken/dist/chunk-VL2OQCWN.js
|
|
6908
|
-
var
|
|
6909
|
-
var
|
|
6910
|
-
var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6837
|
+
var __defProp = Object.defineProperty;
|
|
6838
|
+
var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6911
6839
|
var __publicField = (obj, key, value) => {
|
|
6912
6840
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6913
6841
|
return value;
|
|
@@ -6962,7 +6890,7 @@ var _Tiktoken = class {
|
|
|
6962
6890
|
return memo;
|
|
6963
6891
|
}, {});
|
|
6964
6892
|
for (const [token, rank] of Object.entries(uncompressed)) {
|
|
6965
|
-
const bytes =
|
|
6893
|
+
const bytes = $toByteArray(token);
|
|
6966
6894
|
this.rankMap.set(bytes.join(","), rank);
|
|
6967
6895
|
this.textMap.set(rank, bytes);
|
|
6968
6896
|
}
|
|
@@ -7855,16 +7783,16 @@ function normalizeProvider4(provider) {
|
|
|
7855
7783
|
return String(provider).trim().toLowerCase();
|
|
7856
7784
|
}
|
|
7857
7785
|
function getProviderAdapter(provider) {
|
|
7858
|
-
const
|
|
7859
|
-
if (!
|
|
7786
|
+
const adapter = PROVIDER_ADAPTERS[normalizeProvider4(provider)];
|
|
7787
|
+
if (!adapter) {
|
|
7860
7788
|
throw new Error(`Unsupported token accounting provider: ${provider}`);
|
|
7861
7789
|
}
|
|
7862
|
-
return
|
|
7790
|
+
return adapter;
|
|
7863
7791
|
}
|
|
7864
7792
|
function createTokenAccountingSession(input) {
|
|
7865
|
-
const
|
|
7793
|
+
const adapter = getProviderAdapter(input.provider);
|
|
7866
7794
|
const state = {
|
|
7867
|
-
provider:
|
|
7795
|
+
provider: adapter.provider,
|
|
7868
7796
|
routeId: input.routeId,
|
|
7869
7797
|
upstreamId: input.upstreamId,
|
|
7870
7798
|
requestId: input.requestId,
|
|
@@ -7875,63 +7803,63 @@ function createTokenAccountingSession(input) {
|
|
|
7875
7803
|
};
|
|
7876
7804
|
return {
|
|
7877
7805
|
consumeRequest({ body }) {
|
|
7878
|
-
|
|
7806
|
+
adapter.consumeRequest(state, body);
|
|
7879
7807
|
},
|
|
7880
7808
|
consumeResponse({ body }) {
|
|
7881
|
-
return
|
|
7809
|
+
return adapter.consumeResponse(state, body);
|
|
7882
7810
|
},
|
|
7883
7811
|
consumeStreamChunk({ chunk }) {
|
|
7884
|
-
return
|
|
7812
|
+
return adapter.consumeStreamChunk(state, chunk);
|
|
7885
7813
|
},
|
|
7886
7814
|
finalizeAbortedStream() {
|
|
7887
|
-
return
|
|
7815
|
+
return adapter.finalizeAbortedStream(state);
|
|
7888
7816
|
}
|
|
7889
7817
|
};
|
|
7890
7818
|
}
|
|
7891
7819
|
export {
|
|
7892
|
-
|
|
7893
|
-
safeJsonParse,
|
|
7894
|
-
registerDefaultProtocolConverters,
|
|
7895
|
-
readRecord,
|
|
7896
|
-
readNumber,
|
|
7897
|
-
parseThinkingTags2 as parseThinkingTags,
|
|
7898
|
-
mapOpenAIFinishReasonToAnthropic,
|
|
7899
|
-
mapAnthropicStopReasonToOpenAI,
|
|
7900
|
-
isRecord6 as isRecord,
|
|
7901
|
-
getProviderTokenAccountingCapabilities,
|
|
7902
|
-
generateOpenAIChatCompletionId,
|
|
7903
|
-
generateGeminiCandidateId,
|
|
7904
|
-
generateAnthropicMessageId,
|
|
7905
|
-
finalizeTokenAccountingEvent,
|
|
7906
|
-
createTokenAccountingSession,
|
|
7907
|
-
createPartialTokenAccountingEvent,
|
|
7908
|
-
countTextTokens,
|
|
7909
|
-
countModelTextTokens,
|
|
7910
|
-
countJsonLikeTokens,
|
|
7911
|
-
convertThinkingBlocksToTags,
|
|
7912
|
-
clampTokens,
|
|
7913
|
-
buildBaseEvent,
|
|
7914
|
-
assertCanonicalTokenAccountingEventV2,
|
|
7915
|
-
asString2 as asString,
|
|
7916
|
-
asFiniteNumber,
|
|
7917
|
-
TOKEN_ACCOUNTING_OUTCOMES,
|
|
7918
|
-
TOKEN_ACCOUNTING_AUTHORITIES,
|
|
7919
|
-
SUPPORTED_TOKEN_ACCOUNTING_PROVIDERS,
|
|
7920
|
-
ProtocolTransformerRegistry,
|
|
7921
|
-
PROVIDER_TOKEN_ACCOUNTING_CAPABILITY_MATRIX,
|
|
7922
|
-
OpenAIToGeminiConverter,
|
|
7923
|
-
OpenAIToAnthropicRequestConversion,
|
|
7924
|
-
OpenAIToAnthropicConverter,
|
|
7925
|
-
OpenAIProtocolConversion,
|
|
7926
|
-
OpenAIMessagesCompatibilityNormalizer,
|
|
7927
|
-
OpenAIAdapter,
|
|
7928
|
-
LLMSRuntime,
|
|
7929
|
-
LLMProviderCatalog,
|
|
7930
|
-
LLMProtocolConversionService,
|
|
7931
|
-
LLMProtocolAdapterRegistry,
|
|
7932
|
-
GeminiToOpenAIConverter,
|
|
7933
|
-
GeminiToAnthropicConverter,
|
|
7934
|
-
AnthropicToOpenAIConverter,
|
|
7820
|
+
AnthropicAdapter,
|
|
7935
7821
|
AnthropicToGeminiConverter,
|
|
7936
|
-
|
|
7822
|
+
AnthropicToOpenAIConverter,
|
|
7823
|
+
GeminiToAnthropicConverter,
|
|
7824
|
+
GeminiToOpenAIConverter,
|
|
7825
|
+
LLMProtocolAdapterRegistry,
|
|
7826
|
+
LLMProtocolConversionService,
|
|
7827
|
+
LLMProviderCatalog,
|
|
7828
|
+
LLMSRuntime,
|
|
7829
|
+
OpenAIAdapter,
|
|
7830
|
+
OpenAIMessagesCompatibilityNormalizer,
|
|
7831
|
+
OpenAIProtocolConversion,
|
|
7832
|
+
OpenAIToAnthropicConverter,
|
|
7833
|
+
OpenAIToAnthropicRequestConversion,
|
|
7834
|
+
OpenAIToGeminiConverter,
|
|
7835
|
+
PROVIDER_TOKEN_ACCOUNTING_CAPABILITY_MATRIX,
|
|
7836
|
+
ProtocolTransformerRegistry,
|
|
7837
|
+
SUPPORTED_TOKEN_ACCOUNTING_PROVIDERS,
|
|
7838
|
+
TOKEN_ACCOUNTING_AUTHORITIES,
|
|
7839
|
+
TOKEN_ACCOUNTING_OUTCOMES,
|
|
7840
|
+
asFiniteNumber,
|
|
7841
|
+
asString2 as asString,
|
|
7842
|
+
assertCanonicalTokenAccountingEventV2,
|
|
7843
|
+
buildBaseEvent,
|
|
7844
|
+
clampTokens,
|
|
7845
|
+
convertThinkingBlocksToTags,
|
|
7846
|
+
countJsonLikeTokens,
|
|
7847
|
+
countModelTextTokens,
|
|
7848
|
+
countTextTokens,
|
|
7849
|
+
createPartialTokenAccountingEvent,
|
|
7850
|
+
createTokenAccountingSession,
|
|
7851
|
+
finalizeTokenAccountingEvent,
|
|
7852
|
+
generateAnthropicMessageId,
|
|
7853
|
+
generateGeminiCandidateId,
|
|
7854
|
+
generateOpenAIChatCompletionId,
|
|
7855
|
+
getProviderTokenAccountingCapabilities,
|
|
7856
|
+
isRecord6 as isRecord,
|
|
7857
|
+
mapAnthropicStopReasonToOpenAI,
|
|
7858
|
+
mapOpenAIFinishReasonToAnthropic,
|
|
7859
|
+
parseThinkingTags2 as parseThinkingTags,
|
|
7860
|
+
readNumber,
|
|
7861
|
+
readRecord,
|
|
7862
|
+
registerDefaultProtocolConverters,
|
|
7863
|
+
safeJsonParse,
|
|
7864
|
+
safeJsonStringify
|
|
7937
7865
|
};
|
package/dist/plugin-api.js
CHANGED
|
@@ -1,130 +1,4 @@
|
|
|
1
1
|
// @bun
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
function __accessProp(key) {
|
|
8
|
-
return this[key];
|
|
9
|
-
}
|
|
10
|
-
var __toESMCache_node;
|
|
11
|
-
var __toESMCache_esm;
|
|
12
|
-
var __toESM = (mod, isNodeMode, target) => {
|
|
13
|
-
var canCache = mod != null && typeof mod === "object";
|
|
14
|
-
if (canCache) {
|
|
15
|
-
var cache = isNodeMode ? __toESMCache_node ??= new WeakMap : __toESMCache_esm ??= new WeakMap;
|
|
16
|
-
var cached = cache.get(mod);
|
|
17
|
-
if (cached)
|
|
18
|
-
return cached;
|
|
19
|
-
}
|
|
20
|
-
target = mod != null ? __create(__getProtoOf(mod)) : {};
|
|
21
|
-
const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
|
|
22
|
-
for (let key of __getOwnPropNames(mod))
|
|
23
|
-
if (!__hasOwnProp.call(to, key))
|
|
24
|
-
__defProp(to, key, {
|
|
25
|
-
get: __accessProp.bind(mod, key),
|
|
26
|
-
enumerable: true
|
|
27
|
-
});
|
|
28
|
-
if (canCache)
|
|
29
|
-
cache.set(mod, to);
|
|
30
|
-
return to;
|
|
31
|
-
};
|
|
32
|
-
var __commonJS = (cb, mod) => () => (mod || cb((mod = { exports: {} }).exports, mod), mod.exports);
|
|
33
|
-
|
|
34
|
-
// ../../node_modules/base64-js/index.js
|
|
35
|
-
var require_base64_js = __commonJS((exports) => {
|
|
36
|
-
exports.byteLength = byteLength;
|
|
37
|
-
exports.toByteArray = toByteArray;
|
|
38
|
-
exports.fromByteArray = fromByteArray;
|
|
39
|
-
var lookup = [];
|
|
40
|
-
var revLookup = [];
|
|
41
|
-
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
42
|
-
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
43
|
-
for (i = 0, len = code.length;i < len; ++i) {
|
|
44
|
-
lookup[i] = code[i];
|
|
45
|
-
revLookup[code.charCodeAt(i)] = i;
|
|
46
|
-
}
|
|
47
|
-
var i;
|
|
48
|
-
var len;
|
|
49
|
-
revLookup[45] = 62;
|
|
50
|
-
revLookup[95] = 63;
|
|
51
|
-
function getLens(b64) {
|
|
52
|
-
var len2 = b64.length;
|
|
53
|
-
if (len2 % 4 > 0) {
|
|
54
|
-
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
55
|
-
}
|
|
56
|
-
var validLen = b64.indexOf("=");
|
|
57
|
-
if (validLen === -1)
|
|
58
|
-
validLen = len2;
|
|
59
|
-
var placeHoldersLen = validLen === len2 ? 0 : 4 - validLen % 4;
|
|
60
|
-
return [validLen, placeHoldersLen];
|
|
61
|
-
}
|
|
62
|
-
function byteLength(b64) {
|
|
63
|
-
var lens = getLens(b64);
|
|
64
|
-
var validLen = lens[0];
|
|
65
|
-
var placeHoldersLen = lens[1];
|
|
66
|
-
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
67
|
-
}
|
|
68
|
-
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
69
|
-
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
70
|
-
}
|
|
71
|
-
function toByteArray(b64) {
|
|
72
|
-
var tmp;
|
|
73
|
-
var lens = getLens(b64);
|
|
74
|
-
var validLen = lens[0];
|
|
75
|
-
var placeHoldersLen = lens[1];
|
|
76
|
-
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
77
|
-
var curByte = 0;
|
|
78
|
-
var len2 = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
79
|
-
var i2;
|
|
80
|
-
for (i2 = 0;i2 < len2; i2 += 4) {
|
|
81
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 18 | revLookup[b64.charCodeAt(i2 + 1)] << 12 | revLookup[b64.charCodeAt(i2 + 2)] << 6 | revLookup[b64.charCodeAt(i2 + 3)];
|
|
82
|
-
arr[curByte++] = tmp >> 16 & 255;
|
|
83
|
-
arr[curByte++] = tmp >> 8 & 255;
|
|
84
|
-
arr[curByte++] = tmp & 255;
|
|
85
|
-
}
|
|
86
|
-
if (placeHoldersLen === 2) {
|
|
87
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 2 | revLookup[b64.charCodeAt(i2 + 1)] >> 4;
|
|
88
|
-
arr[curByte++] = tmp & 255;
|
|
89
|
-
}
|
|
90
|
-
if (placeHoldersLen === 1) {
|
|
91
|
-
tmp = revLookup[b64.charCodeAt(i2)] << 10 | revLookup[b64.charCodeAt(i2 + 1)] << 4 | revLookup[b64.charCodeAt(i2 + 2)] >> 2;
|
|
92
|
-
arr[curByte++] = tmp >> 8 & 255;
|
|
93
|
-
arr[curByte++] = tmp & 255;
|
|
94
|
-
}
|
|
95
|
-
return arr;
|
|
96
|
-
}
|
|
97
|
-
function tripletToBase64(num) {
|
|
98
|
-
return lookup[num >> 18 & 63] + lookup[num >> 12 & 63] + lookup[num >> 6 & 63] + lookup[num & 63];
|
|
99
|
-
}
|
|
100
|
-
function encodeChunk(uint8, start, end) {
|
|
101
|
-
var tmp;
|
|
102
|
-
var output = [];
|
|
103
|
-
for (var i2 = start;i2 < end; i2 += 3) {
|
|
104
|
-
tmp = (uint8[i2] << 16 & 16711680) + (uint8[i2 + 1] << 8 & 65280) + (uint8[i2 + 2] & 255);
|
|
105
|
-
output.push(tripletToBase64(tmp));
|
|
106
|
-
}
|
|
107
|
-
return output.join("");
|
|
108
|
-
}
|
|
109
|
-
function fromByteArray(uint8) {
|
|
110
|
-
var tmp;
|
|
111
|
-
var len2 = uint8.length;
|
|
112
|
-
var extraBytes = len2 % 3;
|
|
113
|
-
var parts = [];
|
|
114
|
-
var maxChunkLength = 16383;
|
|
115
|
-
for (var i2 = 0, len22 = len2 - extraBytes;i2 < len22; i2 += maxChunkLength) {
|
|
116
|
-
parts.push(encodeChunk(uint8, i2, i2 + maxChunkLength > len22 ? len22 : i2 + maxChunkLength));
|
|
117
|
-
}
|
|
118
|
-
if (extraBytes === 1) {
|
|
119
|
-
tmp = uint8[len2 - 1];
|
|
120
|
-
parts.push(lookup[tmp >> 2] + lookup[tmp << 4 & 63] + "==");
|
|
121
|
-
} else if (extraBytes === 2) {
|
|
122
|
-
tmp = (uint8[len2 - 2] << 8) + uint8[len2 - 1];
|
|
123
|
-
parts.push(lookup[tmp >> 10] + lookup[tmp >> 4 & 63] + lookup[tmp << 2 & 63] + "=");
|
|
124
|
-
}
|
|
125
|
-
return parts.join("");
|
|
126
|
-
}
|
|
127
|
-
});
|
|
128
2
|
// src/protocol-converters/utils.ts
|
|
129
3
|
function generateAnthropicMessageId() {
|
|
130
4
|
return `msg_${crypto.randomUUID().replace(/-/g, "").substring(0, 24)}`;
|
|
@@ -516,10 +390,10 @@ class AnthropicToGeminiConverter {
|
|
|
516
390
|
return ctx.response;
|
|
517
391
|
}
|
|
518
392
|
if (geminiBody.totalTokens !== undefined) {
|
|
519
|
-
const
|
|
393
|
+
const anthropicBody = {
|
|
520
394
|
input_tokens: geminiBody.totalTokens
|
|
521
395
|
};
|
|
522
|
-
return new Response(JSON.stringify(
|
|
396
|
+
return new Response(JSON.stringify(anthropicBody), {
|
|
523
397
|
status: ctx.response.status,
|
|
524
398
|
statusText: ctx.response.statusText,
|
|
525
399
|
headers: ctx.response.headers
|
|
@@ -1760,9 +1634,9 @@ class AnthropicToOpenAIConverter {
|
|
|
1760
1634
|
const existing = ctx.streamState.get(key);
|
|
1761
1635
|
if (typeof existing === "number" && Number.isFinite(existing))
|
|
1762
1636
|
return existing;
|
|
1763
|
-
const
|
|
1764
|
-
ctx.streamState.set(key,
|
|
1765
|
-
return
|
|
1637
|
+
const assigned = this.nextResponsesContentIndex(ctx);
|
|
1638
|
+
ctx.streamState.set(key, assigned);
|
|
1639
|
+
return assigned;
|
|
1766
1640
|
}
|
|
1767
1641
|
const fallback = ctx.streamState.get("resp_fallback_text_index");
|
|
1768
1642
|
if (typeof fallback === "number" && Number.isFinite(fallback))
|
|
@@ -2199,11 +2073,11 @@ class AnthropicToOpenAIConverter {
|
|
|
2199
2073
|
ctx.streamState.set("legacy_function_name", functionCall.name);
|
|
2200
2074
|
}
|
|
2201
2075
|
if (!ctx.streamState.has("legacy_function_index")) {
|
|
2202
|
-
const
|
|
2203
|
-
ctx.streamState.set("legacy_function_index",
|
|
2076
|
+
const index = this.allocateChatContentBlockIndex(ctx, 0, 0);
|
|
2077
|
+
ctx.streamState.set("legacy_function_index", index);
|
|
2204
2078
|
events.push({
|
|
2205
2079
|
type: "content_block_start",
|
|
2206
|
-
index
|
|
2080
|
+
index,
|
|
2207
2081
|
content_block: {
|
|
2208
2082
|
type: "tool_use",
|
|
2209
2083
|
id: "",
|
|
@@ -2288,13 +2162,13 @@ class AnthropicToOpenAIConverter {
|
|
|
2288
2162
|
ctx.streamState.set("flushed", true);
|
|
2289
2163
|
const pendingStopReason = ctx.streamState.get("pending_stop_reason");
|
|
2290
2164
|
if (pendingStopReason) {
|
|
2291
|
-
const
|
|
2165
|
+
const latestUsage = ctx.streamState.get("latest_usage");
|
|
2292
2166
|
const out = [{
|
|
2293
2167
|
type: "message_delta",
|
|
2294
2168
|
delta: {
|
|
2295
2169
|
stop_reason: pendingStopReason
|
|
2296
2170
|
},
|
|
2297
|
-
...
|
|
2171
|
+
...latestUsage && { usage: latestUsage }
|
|
2298
2172
|
}, {
|
|
2299
2173
|
type: "message_stop"
|
|
2300
2174
|
}];
|
|
@@ -3383,9 +3257,9 @@ class GeminiToOpenAIConverter {
|
|
|
3383
3257
|
}
|
|
3384
3258
|
} else {
|
|
3385
3259
|
const textParts = parts.filter((p) => p.text);
|
|
3386
|
-
const
|
|
3387
|
-
if (
|
|
3388
|
-
messages.push({ role, content
|
|
3260
|
+
const content = textParts.map((p) => p.text).join("");
|
|
3261
|
+
if (content) {
|
|
3262
|
+
messages.push({ role, content });
|
|
3389
3263
|
}
|
|
3390
3264
|
}
|
|
3391
3265
|
}
|
|
@@ -4641,10 +4515,10 @@ class OpenAIToAnthropicRequestConversion {
|
|
|
4641
4515
|
}
|
|
4642
4516
|
if (role === "assistant") {
|
|
4643
4517
|
if (Array.isArray(message.tool_calls)) {
|
|
4644
|
-
const
|
|
4518
|
+
const content = [];
|
|
4645
4519
|
const assistantText = this.extractInstructionText(message.content);
|
|
4646
4520
|
if (assistantText) {
|
|
4647
|
-
|
|
4521
|
+
content.push({ type: "text", text: assistantText });
|
|
4648
4522
|
}
|
|
4649
4523
|
for (const toolCall of message.tool_calls) {
|
|
4650
4524
|
if (!isRecord2(toolCall) || toolCall.type !== "function" || !isRecord2(toolCall.function)) {
|
|
@@ -4657,15 +4531,15 @@ class OpenAIToAnthropicRequestConversion {
|
|
|
4657
4531
|
} catch {
|
|
4658
4532
|
argumentsObject = {};
|
|
4659
4533
|
}
|
|
4660
|
-
|
|
4534
|
+
content.push({
|
|
4661
4535
|
type: "tool_use",
|
|
4662
4536
|
id: typeof toolCall.id === "string" ? toolCall.id : "",
|
|
4663
4537
|
name: typeof toolCall.function.name === "string" ? toolCall.function.name : "",
|
|
4664
4538
|
input: argumentsObject
|
|
4665
4539
|
});
|
|
4666
4540
|
}
|
|
4667
|
-
if (
|
|
4668
|
-
anthropicMessages.push({ role: "assistant", content
|
|
4541
|
+
if (content.length > 0) {
|
|
4542
|
+
anthropicMessages.push({ role: "assistant", content });
|
|
4669
4543
|
}
|
|
4670
4544
|
continue;
|
|
4671
4545
|
}
|
|
@@ -5228,8 +5102,8 @@ class OpenAIToAnthropicConverter {
|
|
|
5228
5102
|
}
|
|
5229
5103
|
if (!ctx.response.ok) {
|
|
5230
5104
|
try {
|
|
5231
|
-
const
|
|
5232
|
-
const errorBody = await
|
|
5105
|
+
const responseClone = ctx.response.clone();
|
|
5106
|
+
const errorBody = await responseClone.json();
|
|
5233
5107
|
if (!this.isLikelyAnthropicErrorBody(errorBody)) {
|
|
5234
5108
|
return ctx.response;
|
|
5235
5109
|
}
|
|
@@ -5716,8 +5590,8 @@ class OpenAIToGeminiConverter {
|
|
|
5716
5590
|
}
|
|
5717
5591
|
if (!ctx.response.ok) {
|
|
5718
5592
|
try {
|
|
5719
|
-
const
|
|
5720
|
-
const errorBody = await
|
|
5593
|
+
const responseClone = ctx.response.clone();
|
|
5594
|
+
const errorBody = await responseClone.json();
|
|
5721
5595
|
if (!this.isLikelyGeminiErrorBody(errorBody)) {
|
|
5722
5596
|
return ctx.response;
|
|
5723
5597
|
}
|
|
@@ -6543,8 +6417,8 @@ class OpenAIMessagesCompatibilityNormalizer {
|
|
|
6543
6417
|
};
|
|
6544
6418
|
}
|
|
6545
6419
|
if (content === undefined) {
|
|
6546
|
-
const
|
|
6547
|
-
if (role === "assistant" &&
|
|
6420
|
+
const hasToolCalls = Array.isArray(rawMessage.tool_calls) && rawMessage.tool_calls.length > 0;
|
|
6421
|
+
if (role === "assistant" && hasToolCalls) {
|
|
6548
6422
|
this.ensureAssistantToolCallReasoningContent(normalizedMessage);
|
|
6549
6423
|
return {
|
|
6550
6424
|
ok: true,
|
|
@@ -6910,10 +6784,64 @@ var TOKEN_ACCOUNTING_AUTHORITIES = [
|
|
|
6910
6784
|
"none"
|
|
6911
6785
|
];
|
|
6912
6786
|
var TOKEN_ACCOUNTING_OUTCOMES = ["completed", "aborted", "failed"];
|
|
6787
|
+
// ../../node_modules/base64-js/index.js
|
|
6788
|
+
var $toByteArray = toByteArray;
|
|
6789
|
+
var lookup = [];
|
|
6790
|
+
var revLookup = [];
|
|
6791
|
+
var Arr = typeof Uint8Array !== "undefined" ? Uint8Array : Array;
|
|
6792
|
+
var code = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
|
|
6793
|
+
for (i = 0, len = code.length;i < len; ++i) {
|
|
6794
|
+
lookup[i] = code[i];
|
|
6795
|
+
revLookup[code.charCodeAt(i)] = i;
|
|
6796
|
+
}
|
|
6797
|
+
var i;
|
|
6798
|
+
var len;
|
|
6799
|
+
revLookup[45] = 62;
|
|
6800
|
+
revLookup[95] = 63;
|
|
6801
|
+
function getLens(b64) {
|
|
6802
|
+
var len = b64.length;
|
|
6803
|
+
if (len % 4 > 0) {
|
|
6804
|
+
throw new Error("Invalid string. Length must be a multiple of 4");
|
|
6805
|
+
}
|
|
6806
|
+
var validLen = b64.indexOf("=");
|
|
6807
|
+
if (validLen === -1)
|
|
6808
|
+
validLen = len;
|
|
6809
|
+
var placeHoldersLen = validLen === len ? 0 : 4 - validLen % 4;
|
|
6810
|
+
return [validLen, placeHoldersLen];
|
|
6811
|
+
}
|
|
6812
|
+
function _byteLength(b64, validLen, placeHoldersLen) {
|
|
6813
|
+
return (validLen + placeHoldersLen) * 3 / 4 - placeHoldersLen;
|
|
6814
|
+
}
|
|
6815
|
+
function toByteArray(b64) {
|
|
6816
|
+
var tmp;
|
|
6817
|
+
var lens = getLens(b64);
|
|
6818
|
+
var validLen = lens[0];
|
|
6819
|
+
var placeHoldersLen = lens[1];
|
|
6820
|
+
var arr = new Arr(_byteLength(b64, validLen, placeHoldersLen));
|
|
6821
|
+
var curByte = 0;
|
|
6822
|
+
var len = placeHoldersLen > 0 ? validLen - 4 : validLen;
|
|
6823
|
+
var i;
|
|
6824
|
+
for (i = 0;i < len; i += 4) {
|
|
6825
|
+
tmp = revLookup[b64.charCodeAt(i)] << 18 | revLookup[b64.charCodeAt(i + 1)] << 12 | revLookup[b64.charCodeAt(i + 2)] << 6 | revLookup[b64.charCodeAt(i + 3)];
|
|
6826
|
+
arr[curByte++] = tmp >> 16 & 255;
|
|
6827
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
6828
|
+
arr[curByte++] = tmp & 255;
|
|
6829
|
+
}
|
|
6830
|
+
if (placeHoldersLen === 2) {
|
|
6831
|
+
tmp = revLookup[b64.charCodeAt(i)] << 2 | revLookup[b64.charCodeAt(i + 1)] >> 4;
|
|
6832
|
+
arr[curByte++] = tmp & 255;
|
|
6833
|
+
}
|
|
6834
|
+
if (placeHoldersLen === 1) {
|
|
6835
|
+
tmp = revLookup[b64.charCodeAt(i)] << 10 | revLookup[b64.charCodeAt(i + 1)] << 4 | revLookup[b64.charCodeAt(i + 2)] >> 2;
|
|
6836
|
+
arr[curByte++] = tmp >> 8 & 255;
|
|
6837
|
+
arr[curByte++] = tmp & 255;
|
|
6838
|
+
}
|
|
6839
|
+
return arr;
|
|
6840
|
+
}
|
|
6841
|
+
|
|
6913
6842
|
// ../../node_modules/js-tiktoken/dist/chunk-VL2OQCWN.js
|
|
6914
|
-
var
|
|
6915
|
-
var
|
|
6916
|
-
var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp2(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6843
|
+
var __defProp = Object.defineProperty;
|
|
6844
|
+
var __defNormalProp = (obj, key, value) => (key in obj) ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
6917
6845
|
var __publicField = (obj, key, value) => {
|
|
6918
6846
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
6919
6847
|
return value;
|
|
@@ -6968,7 +6896,7 @@ var _Tiktoken = class {
|
|
|
6968
6896
|
return memo;
|
|
6969
6897
|
}, {});
|
|
6970
6898
|
for (const [token, rank] of Object.entries(uncompressed)) {
|
|
6971
|
-
const bytes =
|
|
6899
|
+
const bytes = $toByteArray(token);
|
|
6972
6900
|
this.rankMap.set(bytes.join(","), rank);
|
|
6973
6901
|
this.textMap.set(rank, bytes);
|
|
6974
6902
|
}
|
|
@@ -7895,27 +7823,27 @@ function createTokenAccountingSession(input) {
|
|
|
7895
7823
|
};
|
|
7896
7824
|
}
|
|
7897
7825
|
export {
|
|
7898
|
-
|
|
7899
|
-
safeJsonParse,
|
|
7900
|
-
registerDefaultProtocolConverters,
|
|
7901
|
-
parseThinkingTags,
|
|
7902
|
-
mapOpenAIFinishReasonToAnthropic,
|
|
7903
|
-
mapAnthropicStopReasonToOpenAI,
|
|
7904
|
-
getProviderTokenAccountingCapabilities,
|
|
7905
|
-
generateOpenAIChatCompletionId,
|
|
7906
|
-
generateGeminiCandidateId,
|
|
7907
|
-
generateAnthropicMessageId,
|
|
7908
|
-
createTokenAccountingSession,
|
|
7909
|
-
convertThinkingBlocksToTags,
|
|
7910
|
-
assertCanonicalTokenAccountingEventV2,
|
|
7911
|
-
TOKEN_ACCOUNTING_AUTHORITIES,
|
|
7912
|
-
ProtocolTransformerRegistry,
|
|
7913
|
-
OpenAIToGeminiConverter,
|
|
7914
|
-
OpenAIToAnthropicConverter,
|
|
7915
|
-
OpenAIProtocolConversion,
|
|
7916
|
-
OpenAIMessagesCompatibilityNormalizer,
|
|
7917
|
-
GeminiToOpenAIConverter,
|
|
7918
|
-
GeminiToAnthropicConverter,
|
|
7826
|
+
AnthropicToGeminiConverter,
|
|
7919
7827
|
AnthropicToOpenAIConverter,
|
|
7920
|
-
|
|
7828
|
+
GeminiToAnthropicConverter,
|
|
7829
|
+
GeminiToOpenAIConverter,
|
|
7830
|
+
OpenAIMessagesCompatibilityNormalizer,
|
|
7831
|
+
OpenAIProtocolConversion,
|
|
7832
|
+
OpenAIToAnthropicConverter,
|
|
7833
|
+
OpenAIToGeminiConverter,
|
|
7834
|
+
ProtocolTransformerRegistry,
|
|
7835
|
+
TOKEN_ACCOUNTING_AUTHORITIES,
|
|
7836
|
+
assertCanonicalTokenAccountingEventV2,
|
|
7837
|
+
convertThinkingBlocksToTags,
|
|
7838
|
+
createTokenAccountingSession,
|
|
7839
|
+
generateAnthropicMessageId,
|
|
7840
|
+
generateGeminiCandidateId,
|
|
7841
|
+
generateOpenAIChatCompletionId,
|
|
7842
|
+
getProviderTokenAccountingCapabilities,
|
|
7843
|
+
mapAnthropicStopReasonToOpenAI,
|
|
7844
|
+
mapOpenAIFinishReasonToAnthropic,
|
|
7845
|
+
parseThinkingTags,
|
|
7846
|
+
registerDefaultProtocolConverters,
|
|
7847
|
+
safeJsonParse,
|
|
7848
|
+
safeJsonStringify
|
|
7921
7849
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jeffusion/bungee-llms",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.4.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": "^4.
|
|
14
|
+
"@jeffusion/bungee-types": "^4.4.1"
|
|
15
15
|
},
|
|
16
16
|
"devDependencies": {
|
|
17
17
|
"bun-types": "^1.3.2",
|