@carrierllc/mcp 0.13.78 → 0.13.80
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-C4CICMRO.js";
|
|
95
95
|
import "./chunk-SHKKVIIA.js";
|
|
96
96
|
|
|
97
97
|
// src/index.ts
|
|
@@ -209,7 +209,69 @@ 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 PRODUCTION_ATLAS_BASE_URL = "https://atlas.carrier.llc";
|
|
213
|
+
var AtlasConfigError = class extends Error {
|
|
214
|
+
code = "ATLAS_NOT_CONFIGURED";
|
|
215
|
+
};
|
|
216
|
+
function clean(value) {
|
|
217
|
+
const trimmed = value?.trim();
|
|
218
|
+
return trimmed ? trimmed.replace(/\/+$/, "") : void 0;
|
|
219
|
+
}
|
|
220
|
+
function canonicalHost(url) {
|
|
221
|
+
return url.hostname.toLowerCase().replace(/\.+$/, "");
|
|
222
|
+
}
|
|
223
|
+
var PRODUCTION_HOST = canonicalHost(new URL(PRODUCTION_ATLAS_BASE_URL));
|
|
224
|
+
var LOOPBACK_HOSTS = /* @__PURE__ */ new Set(["127.0.0.1", "[::1]", "localhost"]);
|
|
225
|
+
function parse(url, environment) {
|
|
226
|
+
let parsed;
|
|
227
|
+
try {
|
|
228
|
+
parsed = new URL(url);
|
|
229
|
+
} catch {
|
|
230
|
+
throw new AtlasConfigError(`ATLAS_BASE_URL is not a valid URL (CARRIER_ENVIRONMENT=${environment}).`);
|
|
231
|
+
}
|
|
232
|
+
if (parsed.protocol !== "https:" && !(parsed.protocol === "http:" && LOOPBACK_HOSTS.has(canonicalHost(parsed)))) {
|
|
233
|
+
throw new AtlasConfigError(`ATLAS_BASE_URL must use https (got ${parsed.protocol}).`);
|
|
234
|
+
}
|
|
235
|
+
if (parsed.username || parsed.password) {
|
|
236
|
+
throw new AtlasConfigError("ATLAS_BASE_URL may not contain credentials.");
|
|
237
|
+
}
|
|
238
|
+
return parsed;
|
|
239
|
+
}
|
|
240
|
+
function resolveInternalAtlasBase(env) {
|
|
241
|
+
const configured = clean(env.ATLAS_BASE_URL) ?? clean(env.ATLAS_API_URL);
|
|
242
|
+
const environment = env.CARRIER_ENVIRONMENT?.trim().toLowerCase();
|
|
243
|
+
if (!environment || environment === "production") {
|
|
244
|
+
if (configured) parse(configured, environment || "production");
|
|
245
|
+
return configured ?? PRODUCTION_ATLAS_BASE_URL;
|
|
246
|
+
}
|
|
247
|
+
if (!configured) {
|
|
248
|
+
throw new AtlasConfigError(
|
|
249
|
+
`ATLAS_BASE_URL is required when CARRIER_ENVIRONMENT=${environment}; refusing to fall back to production Atlas.`
|
|
250
|
+
);
|
|
251
|
+
}
|
|
252
|
+
if (canonicalHost(parse(configured, environment)) === PRODUCTION_HOST) {
|
|
253
|
+
throw new AtlasConfigError(
|
|
254
|
+
`CARRIER_ENVIRONMENT=${environment} may not call production Atlas (${configured}).`
|
|
255
|
+
);
|
|
256
|
+
}
|
|
257
|
+
return configured;
|
|
258
|
+
}
|
|
259
|
+
var AtlasRedirectError = class extends Error {
|
|
260
|
+
constructor(status) {
|
|
261
|
+
super(`Atlas answered with a redirect (HTTP ${status}); internal calls never follow redirects.`);
|
|
262
|
+
this.status = status;
|
|
263
|
+
}
|
|
264
|
+
status;
|
|
265
|
+
code = "ATLAS_REDIRECT_REFUSED";
|
|
266
|
+
};
|
|
267
|
+
async function internalAtlasFetch(url, init = {}) {
|
|
268
|
+
const response = await fetch(url, { ...init, redirect: "manual" });
|
|
269
|
+
if (response.type === "opaqueredirect" || response.status >= 300 && response.status < 400) {
|
|
270
|
+
throw new AtlasRedirectError(response.status);
|
|
271
|
+
}
|
|
272
|
+
return response;
|
|
273
|
+
}
|
|
274
|
+
var NANO_USD_PER_USD = 1e9;
|
|
213
275
|
var AI_COST_MULTIPLIER = 4;
|
|
214
276
|
var AI_PRICE_MAX_AGE_DAYS = 30;
|
|
215
277
|
var DAY_MS = 864e5;
|
|
@@ -245,14 +307,12 @@ function readAiCreditPricing(raw, modelId, now = Date.now()) {
|
|
|
245
307
|
}
|
|
246
308
|
const rates = value?.models?.[modelId];
|
|
247
309
|
const validDate = (date) => typeof date === "string" && Number.isFinite(Date.parse(date));
|
|
248
|
-
if (!
|
|
310
|
+
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)) {
|
|
249
311
|
throw new AiCreditError("AI credit pricing is not configured for this model.", "AI_PRICING_UNAVAILABLE");
|
|
250
312
|
}
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
throw new AiCreditError("AI credit pricing is out of date.", "AI_PRICING_STALE");
|
|
255
|
-
}
|
|
313
|
+
const age = now - Date.parse(value.priceAsOf);
|
|
314
|
+
if (age > AI_PRICE_MAX_AGE_DAYS * DAY_MS || age < -DAY_MS) {
|
|
315
|
+
throw new AiCreditError("AI credit pricing is out of date.", "AI_PRICING_STALE");
|
|
256
316
|
}
|
|
257
317
|
return value;
|
|
258
318
|
}
|
|
@@ -265,18 +325,24 @@ function aiSupplierCost(usage, pricing, modelId) {
|
|
|
265
325
|
if (!model) throw new AiCreditError("Unpriced model.", "AI_PRICING_UNAVAILABLE");
|
|
266
326
|
const rates = aiRatesForPrompt(model, usage.inputTokens + usage.cacheReadTokens + usage.cacheWriteTokens);
|
|
267
327
|
const usd = (usage.inputTokens * rates.inputPerMTok + usage.outputTokens * rates.outputPerMTok + usage.cacheReadTokens * rates.cacheReadPerMTok + usage.cacheWriteTokens * rates.cacheWritePerMTok) / 1e6;
|
|
268
|
-
const nanos2 = Math.round(usd *
|
|
328
|
+
const nanos2 = Math.round(usd * NANO_USD_PER_USD);
|
|
269
329
|
if (!Number.isSafeInteger(nanos2 * AI_COST_MULTIPLIER) || nanos2 < 0) {
|
|
270
330
|
throw new AiCreditError("Supplier cost is outside the supported range.", "AI_USAGE_INVALID");
|
|
271
331
|
}
|
|
272
|
-
return {
|
|
332
|
+
return { supplier_cost_nano_usd: nanos2, supplier_cost_usd: usd };
|
|
273
333
|
}
|
|
274
334
|
async function aiWalletRequest(env, orgId, suffix = "", body2) {
|
|
275
335
|
if (!orgId || !env.CARRIER_INTERNAL_API_KEY || !env.ATLAS_BASE_URL) {
|
|
276
336
|
throw new AiCreditError("AI credit wallet is not configured.", "AI_WALLET_UNAVAILABLE");
|
|
277
337
|
}
|
|
278
|
-
|
|
279
|
-
|
|
338
|
+
let base;
|
|
339
|
+
try {
|
|
340
|
+
base = resolveInternalAtlasBase({ ATLAS_BASE_URL: env.ATLAS_BASE_URL, CARRIER_ENVIRONMENT: env.CARRIER_ENVIRONMENT });
|
|
341
|
+
} catch {
|
|
342
|
+
throw new AiCreditError("AI credit wallet is not configured.", "AI_WALLET_UNAVAILABLE");
|
|
343
|
+
}
|
|
344
|
+
const response = await internalAtlasFetch(
|
|
345
|
+
`${base}/internal/ai-wallet/${encodeURIComponent(orgId)}${suffix}`,
|
|
280
346
|
{
|
|
281
347
|
method: body2 === void 0 ? "GET" : "POST",
|
|
282
348
|
headers: {
|
|
@@ -312,18 +378,16 @@ function createAiCreditBilling(env) {
|
|
|
312
378
|
...rates.longContext ? [{ prompt: rates.maxInputTokens, rates: rates.longContext }] : []
|
|
313
379
|
];
|
|
314
380
|
const maxUsd = Math.max(...tiers.map(({ prompt, rates: tier }) => (prompt * Math.max(tier.inputPerMTok, tier.cacheReadPerMTok, tier.cacheWritePerMTok) + maxOutputTokens * tier.outputPerMTok) / 1e6));
|
|
315
|
-
const maxCost = Math.ceil(maxUsd *
|
|
381
|
+
const maxCost = Math.ceil(maxUsd * NANO_USD_PER_USD) * AI_COST_MULTIPLIER;
|
|
316
382
|
if (!Number.isSafeInteger(maxCost) || maxCost <= 0) {
|
|
317
383
|
throw new AiCreditError("Invalid reservation budget.", "AI_PRICING_UNAVAILABLE");
|
|
318
384
|
}
|
|
319
385
|
const reservation = {
|
|
320
386
|
ref,
|
|
321
387
|
model_id: modelId,
|
|
322
|
-
|
|
388
|
+
max_cost_nano_usd: maxCost,
|
|
323
389
|
cost_basis: {
|
|
324
390
|
rates,
|
|
325
|
-
eur_per_usd: pricing.eurPerUsd,
|
|
326
|
-
fx_as_of: pricing.fxAsOf,
|
|
327
391
|
price_as_of: pricing.priceAsOf,
|
|
328
392
|
surface: attribution?.surface ?? "unknown"
|
|
329
393
|
}
|
|
@@ -361,8 +425,6 @@ function createAiCreditBilling(env) {
|
|
|
361
425
|
model_id: modelId,
|
|
362
426
|
surface: attribution?.surface ?? "unknown",
|
|
363
427
|
usage,
|
|
364
|
-
eur_per_usd: pricing.eurPerUsd,
|
|
365
|
-
fx_as_of: pricing.fxAsOf,
|
|
366
428
|
price_as_of: pricing.priceAsOf,
|
|
367
429
|
rates: pricing.models[modelId]
|
|
368
430
|
};
|
|
@@ -414,7 +476,7 @@ var MAX_ENTRIES = 16;
|
|
|
414
476
|
var MAX_KEY_LEN = 256;
|
|
415
477
|
var MAX_VALUE_LEN = 256;
|
|
416
478
|
var ALLOWED = /[^a-zA-Z0-9\s:_@$#=/+,\-.]/g;
|
|
417
|
-
function
|
|
479
|
+
function clean2(value, max) {
|
|
418
480
|
return value.replace(ALLOWED, "").slice(0, max);
|
|
419
481
|
}
|
|
420
482
|
var REQUEST_METADATA_HEADER = "X-Amzn-Bedrock-Request-Metadata";
|
|
@@ -429,8 +491,8 @@ function requestMetadata(attr2) {
|
|
|
429
491
|
];
|
|
430
492
|
for (const [k, v] of pairs) {
|
|
431
493
|
if (v === void 0 || v === "") continue;
|
|
432
|
-
const key =
|
|
433
|
-
const value =
|
|
494
|
+
const key = clean2(k, MAX_KEY_LEN);
|
|
495
|
+
const value = clean2(v, MAX_VALUE_LEN);
|
|
434
496
|
if (key && value && Object.keys(out).length < MAX_ENTRIES) out[key] = value;
|
|
435
497
|
}
|
|
436
498
|
return Object.keys(out).length > 0 ? out : null;
|
|
@@ -7034,7 +7096,6 @@ function installAnnotationDefaults(server2, scopes) {
|
|
|
7034
7096
|
var UNKNOWN_TOOL_SCOPE = "admin";
|
|
7035
7097
|
|
|
7036
7098
|
// src/wallet-client.ts
|
|
7037
|
-
var DEFAULT_ATLAS_BASE_URL = "https://atlas.carrier.llc";
|
|
7038
7099
|
var WalletClientError = class extends Error {
|
|
7039
7100
|
status;
|
|
7040
7101
|
constructor(message, status) {
|
|
@@ -7051,10 +7112,12 @@ function resolveConfig(env) {
|
|
|
7051
7112
|
0
|
|
7052
7113
|
);
|
|
7053
7114
|
}
|
|
7054
|
-
|
|
7055
|
-
|
|
7056
|
-
|
|
7057
|
-
)
|
|
7115
|
+
let baseUrl2;
|
|
7116
|
+
try {
|
|
7117
|
+
baseUrl2 = resolveInternalAtlasBase(env);
|
|
7118
|
+
} catch (err9) {
|
|
7119
|
+
throw new WalletClientError(err9.message, 0);
|
|
7120
|
+
}
|
|
7058
7121
|
return { baseUrl: baseUrl2, key };
|
|
7059
7122
|
}
|
|
7060
7123
|
async function atlasFetch(env, path, init) {
|
|
@@ -7067,7 +7130,7 @@ async function atlasFetch(env, path, init) {
|
|
|
7067
7130
|
}
|
|
7068
7131
|
let res;
|
|
7069
7132
|
try {
|
|
7070
|
-
res = await
|
|
7133
|
+
res = await internalAtlasFetch(`${baseUrl2}${path}`, { method: init.method, headers, body: body2 });
|
|
7071
7134
|
} catch (e) {
|
|
7072
7135
|
throw new WalletClientError(
|
|
7073
7136
|
`ATLAS wallet request failed: ${e instanceof Error ? e.message : "network error"}`,
|
|
@@ -7555,8 +7618,8 @@ var AI_WALLET_TOOL_SCOPES = {
|
|
|
7555
7618
|
ai_wallet_auto_topup: "write"
|
|
7556
7619
|
};
|
|
7557
7620
|
async function aiWallet(env, orgId, method, body2) {
|
|
7558
|
-
const response = await
|
|
7559
|
-
`${env
|
|
7621
|
+
const response = await internalAtlasFetch(
|
|
7622
|
+
`${resolveInternalAtlasBase(env)}/internal/ai-topup/${encodeURIComponent(orgId)}`,
|
|
7560
7623
|
{
|
|
7561
7624
|
method,
|
|
7562
7625
|
headers: {
|
|
@@ -7575,14 +7638,14 @@ function registerAiWalletTools(server2, ctx) {
|
|
|
7575
7638
|
"ai_wallet_auto_topup",
|
|
7576
7639
|
{
|
|
7577
7640
|
title: "AI Wallet Auto Top-up Settings",
|
|
7578
|
-
description: "Read or change automatic
|
|
7641
|
+
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.",
|
|
7579
7642
|
inputSchema: {
|
|
7580
7643
|
enabled: z10.boolean().optional(),
|
|
7581
7644
|
amount_cents: z10.number().int().min(MIN_AI_TOPUP_CENTS).max(MAX_AI_TOPUP_CENTS).optional()
|
|
7582
7645
|
},
|
|
7583
7646
|
outputSchema: {
|
|
7584
7647
|
org_id: z10.string(),
|
|
7585
|
-
|
|
7648
|
+
balance_usd_micros: z10.number().int(),
|
|
7586
7649
|
auto_topup_enabled: z10.boolean(),
|
|
7587
7650
|
auto_topup_amount_cents: z10.number().int()
|
|
7588
7651
|
},
|
|
@@ -9502,7 +9565,7 @@ async function resolveUserTier2(env, sub) {
|
|
|
9502
9565
|
var PRICING_TOOLS = [
|
|
9503
9566
|
{
|
|
9504
9567
|
name: "ai_credit_balance",
|
|
9505
|
-
description: "Read your organization's AI credit wallet in
|
|
9568
|
+
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.",
|
|
9506
9569
|
scope: "read",
|
|
9507
9570
|
inputSchema: { type: "object", properties: {}, required: [] },
|
|
9508
9571
|
handler: async (env, props2) => {
|
|
@@ -9512,13 +9575,13 @@ var PRICING_TOOLS = [
|
|
|
9512
9575
|
signal: AbortSignal.timeout(5e3)
|
|
9513
9576
|
});
|
|
9514
9577
|
if (!response.ok) throw new Error("AI credits unavailable. Sign in to Carrier and select an organization.");
|
|
9515
|
-
const {
|
|
9516
|
-
return { currency: "
|
|
9578
|
+
const { balance_usd: balance_usd2, available_usd: available_usd2 } = (await response.json()).data;
|
|
9579
|
+
return { currency: "USD", balance_usd: balance_usd2, available_usd: available_usd2 };
|
|
9517
9580
|
}
|
|
9518
9581
|
if (env.CARRIER_AI_CREDITS_ENABLED !== "true") throw new Error("AI credits are not available on this deployment.");
|
|
9519
9582
|
if (!props2.org_id) throw new Error("Select an organization to read AI credits.");
|
|
9520
|
-
const {
|
|
9521
|
-
return { currency: "
|
|
9583
|
+
const { balance_usd, available_usd } = await aiWalletRequest(env, props2.org_id);
|
|
9584
|
+
return { currency: "USD", balance_usd, available_usd };
|
|
9522
9585
|
}
|
|
9523
9586
|
},
|
|
9524
9587
|
// -------------------------------------------------------------------------
|
|
@@ -13801,6 +13864,7 @@ var stdioEnv = {
|
|
|
13801
13864
|
// registered (catalog parity with the Worker) and return an explicit
|
|
13802
13865
|
// configuration error instead of silently disappearing from tools/list.
|
|
13803
13866
|
ATLAS_BASE_URL: process.env.ATLAS_BASE_URL,
|
|
13867
|
+
CARRIER_ENVIRONMENT: process.env.CARRIER_ENVIRONMENT,
|
|
13804
13868
|
CARRIER_INTERNAL_API_KEY: process.env.CARRIER_INTERNAL_API_KEY,
|
|
13805
13869
|
WALLET_CHECKOUT_SUCCESS_URL: process.env.WALLET_CHECKOUT_SUCCESS_URL,
|
|
13806
13870
|
WALLET_CHECKOUT_CANCEL_URL: process.env.WALLET_CHECKOUT_CANCEL_URL,
|