@carrierllc/mcp 0.13.77 → 0.13.79
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
CHANGED
|
@@ -91,7 +91,7 @@ import {
|
|
|
91
91
|
verifyStorefront,
|
|
92
92
|
withOcsListSummary,
|
|
93
93
|
withTemplateResellerId
|
|
94
|
-
} from "./chunk-
|
|
94
|
+
} from "./chunk-4LA42G67.js";
|
|
95
95
|
import "./chunk-SHKKVIIA.js";
|
|
96
96
|
|
|
97
97
|
// src/index.ts
|
|
@@ -209,8 +209,10 @@ async function assertManagedIccidAccess(baseUrl2, auth, iccid) {
|
|
|
209
209
|
|
|
210
210
|
// ../../packages/carrier-ai/dist/index.js
|
|
211
211
|
import { AwsClient } from "aws4fetch";
|
|
212
|
-
var
|
|
212
|
+
var NANO_USD_PER_USD = 1e9;
|
|
213
213
|
var AI_COST_MULTIPLIER = 4;
|
|
214
|
+
var AI_PRICE_MAX_AGE_DAYS = 30;
|
|
215
|
+
var DAY_MS = 864e5;
|
|
214
216
|
var AiCreditError = class extends Error {
|
|
215
217
|
constructor(message, code) {
|
|
216
218
|
super(message);
|
|
@@ -222,7 +224,19 @@ var AiCreditError = class extends Error {
|
|
|
222
224
|
function positive(value) {
|
|
223
225
|
return typeof value === "number" && Number.isFinite(value) && value > 0;
|
|
224
226
|
}
|
|
225
|
-
function
|
|
227
|
+
function validRate(rate) {
|
|
228
|
+
return typeof rate === "number" && Number.isFinite(rate) && rate >= 0;
|
|
229
|
+
}
|
|
230
|
+
function validLongContext(rates) {
|
|
231
|
+
const tier = rates.longContext;
|
|
232
|
+
if (tier === void 0) return true;
|
|
233
|
+
return typeof tier === "object" && tier !== null && Number.isSafeInteger(tier.thresholdTokens) && tier.thresholdTokens > 0 && tier.thresholdTokens < rates.maxInputTokens && [tier.inputPerMTok, tier.outputPerMTok, tier.cacheReadPerMTok, tier.cacheWritePerMTok].every(validRate) && positive(tier.inputPerMTok) && positive(tier.outputPerMTok);
|
|
234
|
+
}
|
|
235
|
+
function aiRatesForPrompt(rates, promptTokens) {
|
|
236
|
+
const tier = rates.longContext;
|
|
237
|
+
return tier && promptTokens > tier.thresholdTokens ? tier : rates;
|
|
238
|
+
}
|
|
239
|
+
function readAiCreditPricing(raw, modelId, now = Date.now()) {
|
|
226
240
|
let value;
|
|
227
241
|
try {
|
|
228
242
|
value = JSON.parse(raw ?? "");
|
|
@@ -231,9 +245,13 @@ function readAiCreditPricing(raw, modelId) {
|
|
|
231
245
|
}
|
|
232
246
|
const rates = value?.models?.[modelId];
|
|
233
247
|
const validDate = (date) => typeof date === "string" && Number.isFinite(Date.parse(date));
|
|
234
|
-
if (!
|
|
248
|
+
if (!value || !validDate(value.priceAsOf) || !rates || ![rates.inputPerMTok, rates.outputPerMTok, rates.cacheReadPerMTok, rates.cacheWritePerMTok].every(validRate) || !positive(rates.inputPerMTok) || !positive(rates.outputPerMTok) || !Number.isSafeInteger(rates.maxInputTokens) || rates.maxInputTokens <= 0 || !validLongContext(rates)) {
|
|
235
249
|
throw new AiCreditError("AI credit pricing is not configured for this model.", "AI_PRICING_UNAVAILABLE");
|
|
236
250
|
}
|
|
251
|
+
const age = now - Date.parse(value.priceAsOf);
|
|
252
|
+
if (age > AI_PRICE_MAX_AGE_DAYS * DAY_MS || age < -DAY_MS) {
|
|
253
|
+
throw new AiCreditError("AI credit pricing is out of date.", "AI_PRICING_STALE");
|
|
254
|
+
}
|
|
237
255
|
return value;
|
|
238
256
|
}
|
|
239
257
|
function aiSupplierCost(usage, pricing, modelId) {
|
|
@@ -241,14 +259,15 @@ function aiSupplierCost(usage, pricing, modelId) {
|
|
|
241
259
|
if (!counts.every((count) => Number.isSafeInteger(count) && count >= 0)) {
|
|
242
260
|
throw new AiCreditError("Supplier usage is invalid.", "AI_USAGE_INVALID");
|
|
243
261
|
}
|
|
244
|
-
const
|
|
245
|
-
if (!
|
|
262
|
+
const model = pricing.models[modelId];
|
|
263
|
+
if (!model) throw new AiCreditError("Unpriced model.", "AI_PRICING_UNAVAILABLE");
|
|
264
|
+
const rates = aiRatesForPrompt(model, usage.inputTokens + usage.cacheReadTokens + usage.cacheWriteTokens);
|
|
246
265
|
const usd = (usage.inputTokens * rates.inputPerMTok + usage.outputTokens * rates.outputPerMTok + usage.cacheReadTokens * rates.cacheReadPerMTok + usage.cacheWriteTokens * rates.cacheWritePerMTok) / 1e6;
|
|
247
|
-
const nanos2 = Math.round(usd *
|
|
266
|
+
const nanos2 = Math.round(usd * NANO_USD_PER_USD);
|
|
248
267
|
if (!Number.isSafeInteger(nanos2 * AI_COST_MULTIPLIER) || nanos2 < 0) {
|
|
249
268
|
throw new AiCreditError("Supplier cost is outside the supported range.", "AI_USAGE_INVALID");
|
|
250
269
|
}
|
|
251
|
-
return {
|
|
270
|
+
return { supplier_cost_nano_usd: nanos2, supplier_cost_usd: usd };
|
|
252
271
|
}
|
|
253
272
|
async function aiWalletRequest(env, orgId, suffix = "", body2) {
|
|
254
273
|
if (!orgId || !env.CARRIER_INTERNAL_API_KEY || !env.ATLAS_BASE_URL) {
|
|
@@ -286,18 +305,21 @@ function createAiCreditBilling(env) {
|
|
|
286
305
|
}
|
|
287
306
|
const ref = `ai:${crypto.randomUUID()}`;
|
|
288
307
|
const rates = pricing.models[modelId];
|
|
289
|
-
const
|
|
308
|
+
const tiers = [
|
|
309
|
+
{ prompt: Math.min(rates.maxInputTokens, rates.longContext?.thresholdTokens ?? rates.maxInputTokens), rates },
|
|
310
|
+
...rates.longContext ? [{ prompt: rates.maxInputTokens, rates: rates.longContext }] : []
|
|
311
|
+
];
|
|
312
|
+
const maxUsd = Math.max(...tiers.map(({ prompt, rates: tier }) => (prompt * Math.max(tier.inputPerMTok, tier.cacheReadPerMTok, tier.cacheWritePerMTok) + maxOutputTokens * tier.outputPerMTok) / 1e6));
|
|
313
|
+
const maxCost = Math.ceil(maxUsd * NANO_USD_PER_USD) * AI_COST_MULTIPLIER;
|
|
290
314
|
if (!Number.isSafeInteger(maxCost) || maxCost <= 0) {
|
|
291
315
|
throw new AiCreditError("Invalid reservation budget.", "AI_PRICING_UNAVAILABLE");
|
|
292
316
|
}
|
|
293
317
|
const reservation = {
|
|
294
318
|
ref,
|
|
295
319
|
model_id: modelId,
|
|
296
|
-
|
|
320
|
+
max_cost_nano_usd: maxCost,
|
|
297
321
|
cost_basis: {
|
|
298
322
|
rates,
|
|
299
|
-
eur_per_usd: pricing.eurPerUsd,
|
|
300
|
-
fx_as_of: pricing.fxAsOf,
|
|
301
323
|
price_as_of: pricing.priceAsOf,
|
|
302
324
|
surface: attribution?.surface ?? "unknown"
|
|
303
325
|
}
|
|
@@ -335,8 +357,6 @@ function createAiCreditBilling(env) {
|
|
|
335
357
|
model_id: modelId,
|
|
336
358
|
surface: attribution?.surface ?? "unknown",
|
|
337
359
|
usage,
|
|
338
|
-
eur_per_usd: pricing.eurPerUsd,
|
|
339
|
-
fx_as_of: pricing.fxAsOf,
|
|
340
360
|
price_as_of: pricing.priceAsOf,
|
|
341
361
|
rates: pricing.models[modelId]
|
|
342
362
|
};
|
|
@@ -432,18 +452,27 @@ function extractUsage(payload) {
|
|
|
432
452
|
};
|
|
433
453
|
}
|
|
434
454
|
var HAIKU_RATES = {
|
|
435
|
-
inputPerMTok: 1,
|
|
436
|
-
outputPerMTok: 5,
|
|
437
|
-
cacheReadPerMTok: 0.
|
|
438
|
-
cacheWritePerMTok:
|
|
439
|
-
|
|
455
|
+
inputPerMTok: 0.1,
|
|
456
|
+
outputPerMTok: 0.5,
|
|
457
|
+
cacheReadPerMTok: 0.01,
|
|
458
|
+
cacheWritePerMTok: 0.125,
|
|
459
|
+
longContext: {
|
|
460
|
+
thresholdTokens: 1e5,
|
|
461
|
+
inputPerMTok: 0.5,
|
|
462
|
+
outputPerMTok: 2.5,
|
|
463
|
+
cacheReadPerMTok: 0.05,
|
|
464
|
+
cacheWritePerMTok: 0.625
|
|
465
|
+
},
|
|
466
|
+
asOf: "2026-11-09"
|
|
440
467
|
};
|
|
441
|
-
function estimateCostUsd(u,
|
|
468
|
+
function estimateCostUsd(u, card = HAIKU_RATES) {
|
|
469
|
+
const prompt = u.inputTokens + u.cacheReadTokens + u.cacheWriteTokens;
|
|
470
|
+
const rates = card.longContext && prompt > card.longContext.thresholdTokens ? card.longContext : card;
|
|
442
471
|
const perTok = (mtok) => mtok / 1e6;
|
|
443
472
|
return u.inputTokens * perTok(rates.inputPerMTok) + u.outputTokens * perTok(rates.outputPerMTok) + u.cacheReadTokens * perTok(rates.cacheReadPerMTok) + u.cacheWriteTokens * perTok(rates.cacheWritePerMTok);
|
|
444
473
|
}
|
|
445
474
|
var DEFAULT_BEDROCK_REGION = "us-east-1";
|
|
446
|
-
var DEFAULT_MODEL_ID = "
|
|
475
|
+
var DEFAULT_MODEL_ID = "global.anthropic.claude-haiku-5-5";
|
|
447
476
|
var RETIRED_HAIKU_MARKERS = [
|
|
448
477
|
"claude-3-haiku",
|
|
449
478
|
"claude-3-5-haiku",
|
|
@@ -7540,14 +7569,14 @@ function registerAiWalletTools(server2, ctx) {
|
|
|
7540
7569
|
"ai_wallet_auto_topup",
|
|
7541
7570
|
{
|
|
7542
7571
|
title: "AI Wallet Auto Top-up Settings",
|
|
7543
|
-
description: "Read or change automatic
|
|
7572
|
+
description: "Read or change automatic USD replenishment for the separate AI-credit wallet. This does not charge a card and does not change the eSIM connectivity wallet. Params: enabled (optional boolean), amount_cents (optional integer nominal USD cents, minimum 1000, maximum 100000). Omitting both reads the current setting. Omitting amount while disabling preserves the saved amount. Sending only an amount changes the amount and keeps the current on/off setting. Reading is open to any organisation member; org admin required to change.",
|
|
7544
7573
|
inputSchema: {
|
|
7545
7574
|
enabled: z10.boolean().optional(),
|
|
7546
7575
|
amount_cents: z10.number().int().min(MIN_AI_TOPUP_CENTS).max(MAX_AI_TOPUP_CENTS).optional()
|
|
7547
7576
|
},
|
|
7548
7577
|
outputSchema: {
|
|
7549
7578
|
org_id: z10.string(),
|
|
7550
|
-
|
|
7579
|
+
balance_usd_micros: z10.number().int(),
|
|
7551
7580
|
auto_topup_enabled: z10.boolean(),
|
|
7552
7581
|
auto_topup_amount_cents: z10.number().int()
|
|
7553
7582
|
},
|
|
@@ -9467,7 +9496,7 @@ async function resolveUserTier2(env, sub) {
|
|
|
9467
9496
|
var PRICING_TOOLS = [
|
|
9468
9497
|
{
|
|
9469
9498
|
name: "ai_credit_balance",
|
|
9470
|
-
description: "Read your organization's AI credit wallet in
|
|
9499
|
+
description: "Read your organization's AI credit wallet in USD: balance_usd and available_usd. Pro plan payments fund this wallet and AI usage spends it. No token counts are exposed.",
|
|
9471
9500
|
scope: "read",
|
|
9472
9501
|
inputSchema: { type: "object", properties: {}, required: [] },
|
|
9473
9502
|
handler: async (env, props2) => {
|
|
@@ -9477,13 +9506,13 @@ var PRICING_TOOLS = [
|
|
|
9477
9506
|
signal: AbortSignal.timeout(5e3)
|
|
9478
9507
|
});
|
|
9479
9508
|
if (!response.ok) throw new Error("AI credits unavailable. Sign in to Carrier and select an organization.");
|
|
9480
|
-
const {
|
|
9481
|
-
return { currency: "
|
|
9509
|
+
const { balance_usd: balance_usd2, available_usd: available_usd2 } = (await response.json()).data;
|
|
9510
|
+
return { currency: "USD", balance_usd: balance_usd2, available_usd: available_usd2 };
|
|
9482
9511
|
}
|
|
9483
9512
|
if (env.CARRIER_AI_CREDITS_ENABLED !== "true") throw new Error("AI credits are not available on this deployment.");
|
|
9484
9513
|
if (!props2.org_id) throw new Error("Select an organization to read AI credits.");
|
|
9485
|
-
const {
|
|
9486
|
-
return { currency: "
|
|
9514
|
+
const { balance_usd, available_usd } = await aiWalletRequest(env, props2.org_id);
|
|
9515
|
+
return { currency: "USD", balance_usd, available_usd };
|
|
9487
9516
|
}
|
|
9488
9517
|
},
|
|
9489
9518
|
// -------------------------------------------------------------------------
|