@axlsdk/axl 0.7.5 → 0.7.6
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.cjs +103 -40
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +2 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +103 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -310,29 +310,32 @@ async function fetchWithRetry(input, init, maxRetries = MAX_RETRIES) {
|
|
|
310
310
|
|
|
311
311
|
// src/providers/openai.ts
|
|
312
312
|
var OPENAI_PRICING = {
|
|
313
|
-
|
|
314
|
-
"gpt-4o
|
|
315
|
-
"gpt-
|
|
316
|
-
"gpt-4": [
|
|
317
|
-
"gpt-
|
|
318
|
-
"gpt-5": [
|
|
319
|
-
|
|
320
|
-
"
|
|
321
|
-
"
|
|
322
|
-
|
|
323
|
-
"gpt-
|
|
324
|
-
"gpt-
|
|
325
|
-
"gpt-
|
|
326
|
-
|
|
327
|
-
"
|
|
328
|
-
"
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
"
|
|
332
|
-
"
|
|
333
|
-
"gpt-
|
|
334
|
-
"gpt-
|
|
335
|
-
"gpt-
|
|
313
|
+
// gpt-4o era — cache reads at 50% of input rate
|
|
314
|
+
"gpt-4o": [25e-7, 1e-5, 0.5],
|
|
315
|
+
"gpt-4o-mini": [15e-8, 6e-7, 0.5],
|
|
316
|
+
"gpt-4-turbo": [1e-5, 3e-5, 0.5],
|
|
317
|
+
"gpt-4": [3e-5, 6e-5, 0.5],
|
|
318
|
+
"gpt-3.5-turbo": [5e-7, 15e-7, 0.5],
|
|
319
|
+
o1: [15e-6, 6e-5, 0.5],
|
|
320
|
+
"o1-mini": [3e-6, 12e-6, 0.5],
|
|
321
|
+
"o1-pro": [15e-5, 6e-4, 0.5],
|
|
322
|
+
// gpt-4.1 / o3 / o4 era — cache reads at 25% of input rate
|
|
323
|
+
"gpt-4.1": [2e-6, 8e-6, 0.25],
|
|
324
|
+
"gpt-4.1-mini": [4e-7, 16e-7, 0.25],
|
|
325
|
+
"gpt-4.1-nano": [1e-7, 4e-7, 0.25],
|
|
326
|
+
o3: [1e-5, 4e-5, 0.25],
|
|
327
|
+
"o3-mini": [11e-7, 44e-7, 0.25],
|
|
328
|
+
"o3-pro": [2e-5, 8e-5, 0.25],
|
|
329
|
+
"o4-mini": [11e-7, 44e-7, 0.25],
|
|
330
|
+
// gpt-5 era — cache reads at 10% of input rate
|
|
331
|
+
"gpt-5": [125e-8, 1e-5, 0.1],
|
|
332
|
+
"gpt-5-mini": [25e-8, 2e-6, 0.1],
|
|
333
|
+
"gpt-5-nano": [5e-8, 4e-7, 0.1],
|
|
334
|
+
"gpt-5.1": [125e-8, 1e-5, 0.1],
|
|
335
|
+
"gpt-5.2": [175e-8, 14e-6, 0.1],
|
|
336
|
+
"gpt-5.3": [175e-8, 14e-6, 0.1],
|
|
337
|
+
"gpt-5.4": [25e-7, 15e-6, 0.1],
|
|
338
|
+
"gpt-5.4-pro": [3e-5, 18e-5, 0.1]
|
|
336
339
|
};
|
|
337
340
|
var PRICING_KEYS_BY_LENGTH = Object.keys(OPENAI_PRICING).sort((a, b) => b.length - a.length);
|
|
338
341
|
function estimateOpenAICost(model, promptTokens, completionTokens, cachedTokens) {
|
|
@@ -346,9 +349,9 @@ function estimateOpenAICost(model, promptTokens, completionTokens, cachedTokens)
|
|
|
346
349
|
}
|
|
347
350
|
}
|
|
348
351
|
if (!pricing) return 0;
|
|
349
|
-
const [inputRate, outputRate] = pricing;
|
|
352
|
+
const [inputRate, outputRate, cacheMultiplier] = pricing;
|
|
350
353
|
const cached = cachedTokens ?? 0;
|
|
351
|
-
const inputCost = (promptTokens - cached) * inputRate + cached * inputRate *
|
|
354
|
+
const inputCost = (promptTokens - cached) * inputRate + cached * inputRate * cacheMultiplier;
|
|
352
355
|
return inputCost + completionTokens * outputRate;
|
|
353
356
|
}
|
|
354
357
|
function isOSeriesModel(model) {
|
|
@@ -458,7 +461,7 @@ var OpenAIProvider = class {
|
|
|
458
461
|
if (!res.body) {
|
|
459
462
|
throw new Error("OpenAI stream response has no body");
|
|
460
463
|
}
|
|
461
|
-
yield* this.parseSSEStream(res.body);
|
|
464
|
+
yield* this.parseSSEStream(res.body, options.model);
|
|
462
465
|
}
|
|
463
466
|
// ---------------------------------------------------------------------------
|
|
464
467
|
// Internal helpers
|
|
@@ -532,7 +535,7 @@ var OpenAIProvider = class {
|
|
|
532
535
|
if (msg.tool_call_id) out.tool_call_id = msg.tool_call_id;
|
|
533
536
|
return out;
|
|
534
537
|
}
|
|
535
|
-
async *parseSSEStream(body) {
|
|
538
|
+
async *parseSSEStream(body, model) {
|
|
536
539
|
const reader = body.getReader();
|
|
537
540
|
const decoder = new TextDecoder();
|
|
538
541
|
let buffer = "";
|
|
@@ -549,7 +552,16 @@ var OpenAIProvider = class {
|
|
|
549
552
|
const trimmed = line.trim();
|
|
550
553
|
if (!trimmed || trimmed.startsWith(":")) continue;
|
|
551
554
|
if (trimmed === "data: [DONE]") {
|
|
552
|
-
yield {
|
|
555
|
+
yield {
|
|
556
|
+
type: "done",
|
|
557
|
+
usage: usageData,
|
|
558
|
+
cost: usageData ? estimateOpenAICost(
|
|
559
|
+
model,
|
|
560
|
+
usageData.prompt_tokens,
|
|
561
|
+
usageData.completion_tokens,
|
|
562
|
+
usageData.cached_tokens
|
|
563
|
+
) : void 0
|
|
564
|
+
};
|
|
553
565
|
return;
|
|
554
566
|
}
|
|
555
567
|
if (trimmed.startsWith("data: ")) {
|
|
@@ -592,7 +604,16 @@ var OpenAIProvider = class {
|
|
|
592
604
|
}
|
|
593
605
|
}
|
|
594
606
|
}
|
|
595
|
-
yield {
|
|
607
|
+
yield {
|
|
608
|
+
type: "done",
|
|
609
|
+
usage: usageData,
|
|
610
|
+
cost: usageData ? estimateOpenAICost(
|
|
611
|
+
model,
|
|
612
|
+
usageData.prompt_tokens,
|
|
613
|
+
usageData.completion_tokens,
|
|
614
|
+
usageData.cached_tokens
|
|
615
|
+
) : void 0
|
|
616
|
+
};
|
|
596
617
|
} finally {
|
|
597
618
|
reader.releaseLock();
|
|
598
619
|
}
|
|
@@ -850,6 +871,7 @@ var OpenAIResponsesProvider = class {
|
|
|
850
871
|
const decoder = new TextDecoder();
|
|
851
872
|
let buffer = "";
|
|
852
873
|
const callIdMap = /* @__PURE__ */ new Map();
|
|
874
|
+
let eventType = "";
|
|
853
875
|
try {
|
|
854
876
|
while (true) {
|
|
855
877
|
const { done, value } = await reader.read();
|
|
@@ -857,7 +879,6 @@ var OpenAIResponsesProvider = class {
|
|
|
857
879
|
buffer += decoder.decode(value, { stream: true });
|
|
858
880
|
const lines = buffer.split("\n");
|
|
859
881
|
buffer = lines.pop() ?? "";
|
|
860
|
-
let eventType = "";
|
|
861
882
|
for (const line of lines) {
|
|
862
883
|
const trimmed = line.trim();
|
|
863
884
|
if (!trimmed || trimmed.startsWith(":")) continue;
|
|
@@ -925,7 +946,17 @@ var OpenAIResponsesProvider = class {
|
|
|
925
946
|
} : void 0;
|
|
926
947
|
const reasoningItems = response?.output?.filter((item) => item.type === "reasoning") ?? [];
|
|
927
948
|
const providerMetadata = reasoningItems.length > 0 ? { openaiReasoningItems: reasoningItems } : void 0;
|
|
928
|
-
return {
|
|
949
|
+
return {
|
|
950
|
+
type: "done",
|
|
951
|
+
usage,
|
|
952
|
+
cost: usage ? estimateOpenAICost(
|
|
953
|
+
model,
|
|
954
|
+
usage.prompt_tokens,
|
|
955
|
+
usage.completion_tokens,
|
|
956
|
+
usage.cached_tokens
|
|
957
|
+
) : void 0,
|
|
958
|
+
providerMetadata
|
|
959
|
+
};
|
|
929
960
|
}
|
|
930
961
|
case "response.failed": {
|
|
931
962
|
const errorMsg = data.response?.error?.message ?? data.response?.status_details?.error?.message ?? "Unknown error";
|
|
@@ -1058,7 +1089,7 @@ var AnthropicProvider = class {
|
|
|
1058
1089
|
if (!res.body) {
|
|
1059
1090
|
throw new Error("Anthropic stream response has no body");
|
|
1060
1091
|
}
|
|
1061
|
-
yield* this.parseSSEStream(res.body);
|
|
1092
|
+
yield* this.parseSSEStream(res.body, options.model);
|
|
1062
1093
|
}
|
|
1063
1094
|
// ---------------------------------------------------------------------------
|
|
1064
1095
|
// Internal: request building
|
|
@@ -1301,13 +1332,14 @@ ${jsonInstruction}` : jsonInstruction;
|
|
|
1301
1332
|
// ---------------------------------------------------------------------------
|
|
1302
1333
|
// Internal: SSE stream parsing
|
|
1303
1334
|
// ---------------------------------------------------------------------------
|
|
1304
|
-
async *parseSSEStream(body) {
|
|
1335
|
+
async *parseSSEStream(body, model) {
|
|
1305
1336
|
const reader = body.getReader();
|
|
1306
1337
|
const decoder = new TextDecoder();
|
|
1307
1338
|
let buffer = "";
|
|
1308
1339
|
let currentToolId = "";
|
|
1309
1340
|
let currentToolName = "";
|
|
1310
1341
|
let usage;
|
|
1342
|
+
let cacheWrite = 0;
|
|
1311
1343
|
try {
|
|
1312
1344
|
while (true) {
|
|
1313
1345
|
const { done, value } = await reader.read();
|
|
@@ -1364,7 +1396,7 @@ ${jsonInstruction}` : jsonInstruction;
|
|
|
1364
1396
|
case "message_start": {
|
|
1365
1397
|
if (event.message?.usage) {
|
|
1366
1398
|
const cacheRead = event.message.usage.cache_read_input_tokens ?? 0;
|
|
1367
|
-
|
|
1399
|
+
cacheWrite = event.message.usage.cache_creation_input_tokens ?? 0;
|
|
1368
1400
|
const inputTokens = (event.message.usage.input_tokens ?? 0) + cacheRead + cacheWrite;
|
|
1369
1401
|
usage = {
|
|
1370
1402
|
prompt_tokens: inputTokens,
|
|
@@ -1395,13 +1427,33 @@ ${jsonInstruction}` : jsonInstruction;
|
|
|
1395
1427
|
if (usage) {
|
|
1396
1428
|
usage.total_tokens = usage.prompt_tokens + usage.completion_tokens;
|
|
1397
1429
|
}
|
|
1398
|
-
yield {
|
|
1430
|
+
yield {
|
|
1431
|
+
type: "done",
|
|
1432
|
+
usage,
|
|
1433
|
+
cost: usage ? estimateAnthropicCost(
|
|
1434
|
+
model,
|
|
1435
|
+
usage.prompt_tokens,
|
|
1436
|
+
usage.completion_tokens,
|
|
1437
|
+
usage.cached_tokens,
|
|
1438
|
+
cacheWrite
|
|
1439
|
+
) : void 0
|
|
1440
|
+
};
|
|
1399
1441
|
return;
|
|
1400
1442
|
}
|
|
1401
1443
|
}
|
|
1402
1444
|
}
|
|
1403
1445
|
}
|
|
1404
|
-
yield {
|
|
1446
|
+
yield {
|
|
1447
|
+
type: "done",
|
|
1448
|
+
usage,
|
|
1449
|
+
cost: usage ? estimateAnthropicCost(
|
|
1450
|
+
model,
|
|
1451
|
+
usage.prompt_tokens,
|
|
1452
|
+
usage.completion_tokens,
|
|
1453
|
+
usage.cached_tokens,
|
|
1454
|
+
cacheWrite
|
|
1455
|
+
) : void 0
|
|
1456
|
+
};
|
|
1405
1457
|
} finally {
|
|
1406
1458
|
reader.releaseLock();
|
|
1407
1459
|
}
|
|
@@ -1528,7 +1580,7 @@ var GeminiProvider = class {
|
|
|
1528
1580
|
if (!res.body) {
|
|
1529
1581
|
throw new Error("Gemini stream response has no body");
|
|
1530
1582
|
}
|
|
1531
|
-
yield* this.parseSSEStream(res.body);
|
|
1583
|
+
yield* this.parseSSEStream(res.body, options.model);
|
|
1532
1584
|
}
|
|
1533
1585
|
// ---------------------------------------------------------------------------
|
|
1534
1586
|
// Internal: request building
|
|
@@ -1809,7 +1861,7 @@ var GeminiProvider = class {
|
|
|
1809
1861
|
// ---------------------------------------------------------------------------
|
|
1810
1862
|
// Internal: SSE stream parsing
|
|
1811
1863
|
// ---------------------------------------------------------------------------
|
|
1812
|
-
async *parseSSEStream(body) {
|
|
1864
|
+
async *parseSSEStream(body, model) {
|
|
1813
1865
|
const reader = body.getReader();
|
|
1814
1866
|
const decoder = new TextDecoder();
|
|
1815
1867
|
let buffer = "";
|
|
@@ -1865,7 +1917,17 @@ var GeminiProvider = class {
|
|
|
1865
1917
|
}
|
|
1866
1918
|
}
|
|
1867
1919
|
const providerMetadata = accumulatedParts.length > 0 ? { geminiParts: accumulatedParts } : void 0;
|
|
1868
|
-
yield {
|
|
1920
|
+
yield {
|
|
1921
|
+
type: "done",
|
|
1922
|
+
usage,
|
|
1923
|
+
cost: usage ? estimateGeminiCost(
|
|
1924
|
+
model,
|
|
1925
|
+
usage.prompt_tokens,
|
|
1926
|
+
usage.completion_tokens,
|
|
1927
|
+
usage.cached_tokens
|
|
1928
|
+
) : void 0,
|
|
1929
|
+
providerMetadata
|
|
1930
|
+
};
|
|
1869
1931
|
} finally {
|
|
1870
1932
|
reader.releaseLock();
|
|
1871
1933
|
}
|
|
@@ -2575,7 +2637,8 @@ Please fix and try again.`;
|
|
|
2575
2637
|
response = {
|
|
2576
2638
|
content: content2,
|
|
2577
2639
|
tool_calls: void 0,
|
|
2578
|
-
usage: chunk.usage
|
|
2640
|
+
usage: chunk.usage,
|
|
2641
|
+
cost: chunk.cost
|
|
2579
2642
|
};
|
|
2580
2643
|
}
|
|
2581
2644
|
}
|