@carrierllc/mcp 0.13.79 → 0.13.81

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-4LA42G67.js";
94
+ } from "./chunk-QOEAUPWD.js";
95
95
  import "./chunk-SHKKVIIA.js";
96
96
 
97
97
  // src/index.ts
@@ -209,6 +209,68 @@ async function assertManagedIccidAccess(baseUrl2, auth, iccid) {
209
209
 
210
210
  // ../../packages/carrier-ai/dist/index.js
211
211
  import { AwsClient } from "aws4fetch";
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
+ }
212
274
  var NANO_USD_PER_USD = 1e9;
213
275
  var AI_COST_MULTIPLIER = 4;
214
276
  var AI_PRICE_MAX_AGE_DAYS = 30;
@@ -273,8 +335,14 @@ async function aiWalletRequest(env, orgId, suffix = "", body2) {
273
335
  if (!orgId || !env.CARRIER_INTERNAL_API_KEY || !env.ATLAS_BASE_URL) {
274
336
  throw new AiCreditError("AI credit wallet is not configured.", "AI_WALLET_UNAVAILABLE");
275
337
  }
276
- const response = await fetch(
277
- `${env.ATLAS_BASE_URL.replace(/\/+$/, "")}/internal/ai-wallet/${encodeURIComponent(orgId)}${suffix}`,
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}`,
278
346
  {
279
347
  method: body2 === void 0 ? "GET" : "POST",
280
348
  headers: {
@@ -408,7 +476,7 @@ var MAX_ENTRIES = 16;
408
476
  var MAX_KEY_LEN = 256;
409
477
  var MAX_VALUE_LEN = 256;
410
478
  var ALLOWED = /[^a-zA-Z0-9\s:_@$#=/+,\-.]/g;
411
- function clean(value, max) {
479
+ function clean2(value, max) {
412
480
  return value.replace(ALLOWED, "").slice(0, max);
413
481
  }
414
482
  var REQUEST_METADATA_HEADER = "X-Amzn-Bedrock-Request-Metadata";
@@ -423,8 +491,8 @@ function requestMetadata(attr2) {
423
491
  ];
424
492
  for (const [k, v] of pairs) {
425
493
  if (v === void 0 || v === "") continue;
426
- const key = clean(k, MAX_KEY_LEN);
427
- const value = clean(v, MAX_VALUE_LEN);
494
+ const key = clean2(k, MAX_KEY_LEN);
495
+ const value = clean2(v, MAX_VALUE_LEN);
428
496
  if (key && value && Object.keys(out).length < MAX_ENTRIES) out[key] = value;
429
497
  }
430
498
  return Object.keys(out).length > 0 ? out : null;
@@ -7028,7 +7096,6 @@ function installAnnotationDefaults(server2, scopes) {
7028
7096
  var UNKNOWN_TOOL_SCOPE = "admin";
7029
7097
 
7030
7098
  // src/wallet-client.ts
7031
- var DEFAULT_ATLAS_BASE_URL = "https://atlas.carrier.llc";
7032
7099
  var WalletClientError = class extends Error {
7033
7100
  status;
7034
7101
  constructor(message, status) {
@@ -7045,10 +7112,12 @@ function resolveConfig(env) {
7045
7112
  0
7046
7113
  );
7047
7114
  }
7048
- const baseUrl2 = (env.ATLAS_BASE_URL ?? DEFAULT_ATLAS_BASE_URL).replace(
7049
- /\/+$/,
7050
- ""
7051
- );
7115
+ let baseUrl2;
7116
+ try {
7117
+ baseUrl2 = resolveInternalAtlasBase(env);
7118
+ } catch (err9) {
7119
+ throw new WalletClientError(err9.message, 0);
7120
+ }
7052
7121
  return { baseUrl: baseUrl2, key };
7053
7122
  }
7054
7123
  async function atlasFetch(env, path, init) {
@@ -7061,7 +7130,7 @@ async function atlasFetch(env, path, init) {
7061
7130
  }
7062
7131
  let res;
7063
7132
  try {
7064
- res = await fetch(`${baseUrl2}${path}`, { method: init.method, headers, body: body2 });
7133
+ res = await internalAtlasFetch(`${baseUrl2}${path}`, { method: init.method, headers, body: body2 });
7065
7134
  } catch (e) {
7066
7135
  throw new WalletClientError(
7067
7136
  `ATLAS wallet request failed: ${e instanceof Error ? e.message : "network error"}`,
@@ -7084,7 +7153,8 @@ async function walletTopup(env, orgId, args) {
7084
7153
  {
7085
7154
  method: "POST",
7086
7155
  body: {
7087
- eur_cents: args.eurCents,
7156
+ amount_cents: args.amountCents,
7157
+ currency: args.currency,
7088
7158
  ref: args.ref,
7089
7159
  ...args.type ? { type: args.type } : {}
7090
7160
  }
@@ -7134,23 +7204,24 @@ function denyUnlessScoped(props2, toolName, scopes) {
7134
7204
  }
7135
7205
 
7136
7206
  // src/wallet-tools.ts
7207
+ var PACK_CURRENCY = "usd";
7137
7208
  var PACKS = [
7138
- { id: "pack_25", eurCents: 2500, bonusPct: 0 },
7139
- { id: "pack_50", eurCents: 5e3, bonusPct: 0 },
7140
- { id: "pack_100", eurCents: 1e4, bonusPct: 0 },
7141
- { id: "pack_500", eurCents: 5e4, bonusPct: 0 },
7142
- { id: "pack_1000", eurCents: 1e5, bonusPct: 3 },
7143
- { id: "pack_2500", eurCents: 25e4, bonusPct: 6 },
7144
- { id: "pack_5000", eurCents: 5e5, bonusPct: 10 }
7209
+ { id: "pack_25", amountCents: 2500, bonusPct: 0 },
7210
+ { id: "pack_50", amountCents: 5e3, bonusPct: 0 },
7211
+ { id: "pack_100", amountCents: 1e4, bonusPct: 0 },
7212
+ { id: "pack_500", amountCents: 5e4, bonusPct: 0 },
7213
+ { id: "pack_1000", amountCents: 1e5, bonusPct: 3 },
7214
+ { id: "pack_2500", amountCents: 25e4, bonusPct: 6 },
7215
+ { id: "pack_5000", amountCents: 5e5, bonusPct: 10 }
7145
7216
  ];
7146
7217
  function bonusCentsFor(pack) {
7147
- return Math.floor(pack.eurCents * pack.bonusPct / 100);
7218
+ return Math.floor(pack.amountCents * pack.bonusPct / 100);
7148
7219
  }
7149
7220
  function resolvePack(idOrCents) {
7150
7221
  if (typeof idOrCents === "number") {
7151
- return PACKS.find((p) => p.eurCents === idOrCents);
7222
+ return PACKS.find((p) => p.amountCents === idOrCents);
7152
7223
  }
7153
- return PACKS.find((p) => p.id === idOrCents) ?? PACKS.find((p) => String(p.eurCents) === idOrCents);
7224
+ return PACKS.find((p) => p.id === idOrCents) ?? PACKS.find((p) => String(p.amountCents) === idOrCents);
7154
7225
  }
7155
7226
  var STRIPE_API = "https://api.stripe.com";
7156
7227
  async function stripePostForm(stripeKey, path, params, opts) {
@@ -7169,6 +7240,36 @@ async function stripePostForm(stripeKey, path, params, opts) {
7169
7240
  const data = await res.json();
7170
7241
  return { ok: res.ok, status: res.status, data };
7171
7242
  }
7243
+ var walletCustomerKey = (sub) => `stripe_wallet_customer_id:${sub}`;
7244
+ var walletPmKey = (sub) => `stripe_wallet_pm_id:${sub}`;
7245
+ function isCurrencyLockError(data) {
7246
+ const err9 = data?.error;
7247
+ if (!err9) return false;
7248
+ const message = typeof err9.message === "string" ? err9.message : "";
7249
+ const code = typeof err9.code === "string" ? err9.code : "";
7250
+ return /currenc/i.test(code) || /cannot combine currencies|currency.{0,60}customer|customer.{0,60}currency/i.test(message);
7251
+ }
7252
+ async function ensureWalletCustomer(env, stripeKey, sub, orgId) {
7253
+ if (!env.CARRIER_USERS) throw new Error("Wallet customer needs the hosted KV binding");
7254
+ const known = await env.CARRIER_USERS.get(walletCustomerKey(sub)).catch(() => null);
7255
+ if (known) return known;
7256
+ const res = await stripePostForm(
7257
+ stripeKey,
7258
+ "/v1/customers",
7259
+ new URLSearchParams({
7260
+ description: "Carrier prepaid wallet (USD)",
7261
+ "metadata[kind]": "wallet_usd_customer",
7262
+ "metadata[org_id]": orgId,
7263
+ "metadata[billing_sub]": sub
7264
+ }),
7265
+ { idempotencyKey: `wallet-usd-customer:${sub}` }
7266
+ );
7267
+ if (!res.ok || !res.data.id) {
7268
+ throw new Error(`Stripe wallet customer create failed: ${JSON.stringify(res.data)}`);
7269
+ }
7270
+ await env.CARRIER_USERS.put(walletCustomerKey(sub), res.data.id);
7271
+ return res.data.id;
7272
+ }
7172
7273
  var DEFAULT_SUCCESS_URL = "https://app.carrier.llc/billing?topup=success";
7173
7274
  var DEFAULT_CANCEL_URL = "https://app.carrier.llc/billing?topup=cancelled";
7174
7275
  async function createTopupCheckout(env, args) {
@@ -7177,28 +7278,32 @@ async function createTopupCheckout(env, args) {
7177
7278
  const bonusCents = bonusCentsFor(args.pack);
7178
7279
  const successUrl = args.successUrl ?? env.WALLET_CHECKOUT_SUCCESS_URL ?? DEFAULT_SUCCESS_URL;
7179
7280
  const cancelUrl = args.cancelUrl ?? env.WALLET_CHECKOUT_CANCEL_URL ?? DEFAULT_CANCEL_URL;
7180
- const bonusLabel = bonusCents > 0 ? ` (+\u20AC${(bonusCents / 100).toFixed(2)} bonus)` : "";
7281
+ const bonusLabel = bonusCents > 0 ? ` (+$${(bonusCents / 100).toFixed(2)} bonus)` : "";
7181
7282
  if (!env.CARRIER_USERS) {
7182
7283
  throw new Error(
7183
7284
  "Wallet top-up is not available in local stdio mode: the prepaid wallet is credited by the hosted Carrier service after payment, and this process cannot reach the customer record that crediting depends on. Creating the session here would bill the card against a duplicate Stripe customer and the wallet would never be credited. Top up from the console at https://app.carrier.llc/billing, or connect to the hosted MCP at https://mcp.carrier.llc/mcp, which has the binding. `wallet_balance` still works here if ATLAS_BASE_URL and CARRIER_INTERNAL_API_KEY are set."
7184
7285
  );
7185
7286
  }
7186
7287
  const billingSub = await resolveBillingSub(env, args.orgId);
7187
- const existingCustomer = await env.CARRIER_USERS.get(`stripe_customer_id:${billingSub}`).catch(() => null);
7288
+ const walletCustomer = await env.CARRIER_USERS.get(walletCustomerKey(billingSub)).catch(
7289
+ () => null
7290
+ );
7291
+ const existingCustomer = walletCustomer ?? await env.CARRIER_USERS.get(`stripe_customer_id:${billingSub}`).catch(() => null);
7188
7292
  const params = new URLSearchParams({
7189
7293
  mode: "payment",
7190
7294
  success_url: successUrl,
7191
7295
  cancel_url: cancelUrl,
7192
7296
  "line_items[0][quantity]": "1",
7193
- "line_items[0][price_data][currency]": "eur",
7194
- "line_items[0][price_data][unit_amount]": String(args.pack.eurCents),
7195
- "line_items[0][price_data][product_data][name]": `Carrier wallet top-up \u2014 \u20AC${(args.pack.eurCents / 100).toFixed(2)}${bonusLabel}`,
7297
+ "line_items[0][price_data][currency]": PACK_CURRENCY,
7298
+ "line_items[0][price_data][unit_amount]": String(args.pack.amountCents),
7299
+ "line_items[0][price_data][product_data][name]": `Carrier wallet top-up \u2014 $${(args.pack.amountCents / 100).toFixed(2)}${bonusLabel}`,
7196
7300
  client_reference_id: args.orgId,
7197
7301
  "metadata[kind]": "wallet_topup",
7198
7302
  "metadata[org_id]": args.orgId,
7199
7303
  "metadata[pack_id]": args.pack.id,
7200
- "metadata[pack_eur_cents]": String(args.pack.eurCents),
7201
- "metadata[bonus_eur_cents]": String(bonusCents),
7304
+ "metadata[currency]": PACK_CURRENCY,
7305
+ "metadata[pack_cents]": String(args.pack.amountCents),
7306
+ "metadata[bonus_cents]": String(bonusCents),
7202
7307
  // Save the payment method for reuse so subsequent off-session auto-top-up
7203
7308
  // charges (runAutoTopup) can charge it without the customer present.
7204
7309
  "payment_intent_data[setup_future_usage]": "off_session",
@@ -7206,19 +7311,29 @@ async function createTopupCheckout(env, args) {
7206
7311
  // payment_intent.succeeded webhook can also credit idempotently.
7207
7312
  "payment_intent_data[metadata][kind]": "wallet_topup",
7208
7313
  "payment_intent_data[metadata][org_id]": args.orgId,
7209
- "payment_intent_data[metadata][pack_eur_cents]": String(args.pack.eurCents),
7210
- "payment_intent_data[metadata][bonus_eur_cents]": String(bonusCents)
7314
+ "payment_intent_data[metadata][currency]": PACK_CURRENCY,
7315
+ "payment_intent_data[metadata][pack_cents]": String(args.pack.amountCents),
7316
+ "payment_intent_data[metadata][bonus_cents]": String(bonusCents)
7211
7317
  });
7212
7318
  if (existingCustomer) {
7213
7319
  params.set("customer", existingCustomer);
7214
7320
  } else {
7215
7321
  params.set("customer_creation", "always");
7216
7322
  }
7217
- const result3 = await stripePostForm(
7323
+ let result3 = await stripePostForm(
7218
7324
  stripeKey,
7219
7325
  "/v1/checkout/sessions",
7220
7326
  params
7221
7327
  );
7328
+ if (!result3.ok && existingCustomer && !walletCustomer && isCurrencyLockError(result3.data)) {
7329
+ const usdCustomer = await ensureWalletCustomer(env, stripeKey, billingSub, args.orgId);
7330
+ params.set("customer", usdCustomer);
7331
+ result3 = await stripePostForm(
7332
+ stripeKey,
7333
+ "/v1/checkout/sessions",
7334
+ params
7335
+ );
7336
+ }
7222
7337
  if (!result3.ok) {
7223
7338
  throw new Error(`Stripe checkout session create failed: ${JSON.stringify(result3.data)}`);
7224
7339
  }
@@ -7249,26 +7364,30 @@ async function runAutoTopup(env, args) {
7249
7364
  if (!env.CARRIER_USERS) {
7250
7365
  return { charged: false, creditedCents: 0, reason: "no_payment_method" };
7251
7366
  }
7252
- const customerId = await env.CARRIER_USERS.get(`stripe_customer_id:${args.sub}`).catch(
7367
+ const walletCustomerId = await env.CARRIER_USERS.get(walletCustomerKey(args.sub)).catch(
7253
7368
  () => null
7254
7369
  );
7255
- const pmId = await env.CARRIER_USERS.get(`stripe_pm_id:${args.sub}`).catch(() => null);
7370
+ const walletPmId = walletCustomerId ? await env.CARRIER_USERS.get(walletPmKey(args.sub)).catch(() => null) : null;
7371
+ const useWallet = Boolean(walletCustomerId && walletPmId);
7372
+ const customerId = useWallet ? walletCustomerId : await env.CARRIER_USERS.get(`stripe_customer_id:${args.sub}`).catch(() => null);
7373
+ const pmId = useWallet ? walletPmId : await env.CARRIER_USERS.get(`stripe_pm_id:${args.sub}`).catch(() => null);
7256
7374
  if (!customerId || !pmId) {
7257
7375
  return { charged: false, creditedCents: 0, reason: "no_payment_method" };
7258
7376
  }
7259
7377
  const bonusCents = bonusCentsFor(pack);
7260
7378
  const body2 = new URLSearchParams({
7261
- amount: String(pack.eurCents),
7262
- currency: "eur",
7379
+ amount: String(pack.amountCents),
7380
+ currency: PACK_CURRENCY,
7263
7381
  customer: customerId,
7264
7382
  payment_method: pmId,
7265
7383
  confirm: "true",
7266
7384
  off_session: "true",
7267
- description: `Carrier wallet auto-top-up \u2014 \u20AC${(pack.eurCents / 100).toFixed(2)}`,
7385
+ description: `Carrier wallet auto-top-up \u2014 $${(pack.amountCents / 100).toFixed(2)}`,
7268
7386
  "metadata[kind]": "wallet_topup",
7269
7387
  "metadata[org_id]": args.orgId,
7270
- "metadata[pack_eur_cents]": String(pack.eurCents),
7271
- "metadata[bonus_eur_cents]": String(bonusCents),
7388
+ "metadata[currency]": PACK_CURRENCY,
7389
+ "metadata[pack_cents]": String(pack.amountCents),
7390
+ "metadata[bonus_cents]": String(bonusCents),
7272
7391
  "metadata[auto_topup]": "true"
7273
7392
  });
7274
7393
  const resp = await stripePostForm(
@@ -7291,10 +7410,11 @@ async function runAutoTopup(env, args) {
7291
7410
  paymentIntentId: resp.data.id
7292
7411
  };
7293
7412
  }
7294
- const creditedCents = pack.eurCents + bonusCents;
7413
+ const creditedCents = pack.amountCents + bonusCents;
7295
7414
  try {
7296
7415
  const topup = await walletTopup(env, args.orgId, {
7297
- eurCents: creditedCents,
7416
+ amountCents: creditedCents,
7417
+ currency: PACK_CURRENCY,
7298
7418
  ref: resp.data.id,
7299
7419
  type: "auto_topup"
7300
7420
  });
@@ -7335,7 +7455,7 @@ function registerWalletTools(server2, ctx) {
7335
7455
  "wallet_balance",
7336
7456
  {
7337
7457
  title: "Wallet Balance",
7338
- description: "Read the caller organisation's Carrier prepaid wallet: current balance and auto-top-up settings. The wallet is what Carrier bills your own eSIM spend against \u2014 it is not an OCS balance and not your MCP plan credits. Params: none (the organisation is taken from the session). Returns: { org_id, balance_eur_cents, auto_topup_enabled, auto_topup_threshold_cents, auto_topup_pack_cents } \u2014 all amounts in EUR cents, not euros. Do NOT use this for a reseller account balance in OCS \u2014 use `get_reseller_info` or `list_reseller_accounts`. Do NOT use this for a subscriber's OCS balance \u2014 use `get_subscriber`. Do NOT use this for MCP plan credits \u2014 use `credit_balance`. Do NOT use this for money held at Stripe \u2014 use `stripe_connect_balance`.",
7458
+ description: "Read the caller organisation's Carrier prepaid wallet: current balance and auto-top-up settings. The wallet is what Carrier bills your own eSIM spend against \u2014 it is not an OCS balance and not your MCP plan credits. Params: none (the organisation is taken from the session). Returns: { org_id, balance_cents, currency, balance_usd_cents, balance_eur_cents, auto_topup_enabled, auto_topup_threshold_cents, auto_topup_pack_cents } \u2014 all amounts in cents, not dollars. `balance_cents` is the spendable total; `balance_eur_cents` is credit bought in EUR before the USD move, spent first, never topped up. Do NOT use this for a reseller account balance in OCS \u2014 use `get_reseller_info` or `list_reseller_accounts`. Do NOT use this for a subscriber's OCS balance \u2014 use `get_subscriber`. Do NOT use this for MCP plan credits \u2014 use `credit_balance`. Do NOT use this for money held at Stripe \u2014 use `stripe_connect_balance`.",
7339
7459
  inputSchema: {},
7340
7460
  // Derived from the object literal this handler builds below, not from the
7341
7461
  // description. All five keys are always present on the success path, so
@@ -7347,13 +7467,16 @@ function registerWalletTools(server2, ctx) {
7347
7467
  // state a new operator is in, into an output validation error.
7348
7468
  outputSchema: {
7349
7469
  org_id: z9.string().describe("Carrier organisation the wallet belongs to"),
7350
- balance_eur_cents: z9.number().int().describe("Current balance in EUR cents"),
7470
+ balance_cents: z9.number().int().describe("Spendable balance in cents: USD plus any legacy EUR credit"),
7471
+ currency: z9.literal("usd").describe("Currency new top-ups are credited in"),
7472
+ balance_usd_cents: z9.number().int().describe("USD balance in cents"),
7473
+ balance_eur_cents: z9.number().int().describe("Legacy EUR balance in cents. Spent before USD; no new EUR is credited."),
7351
7474
  auto_topup_enabled: z9.boolean(),
7352
7475
  auto_topup_threshold_cents: z9.number().int().nullable().describe(
7353
- "Balance at or below which an auto top-up fires, EUR cents. Null when auto-top-up is unconfigured."
7476
+ "Spendable balance below which an auto top-up fires, USD cents. Null when auto-top-up is unconfigured."
7354
7477
  ),
7355
7478
  auto_topup_pack_cents: z9.number().int().nullable().describe(
7356
- "Amount an auto top-up charges, EUR cents. Null when auto-top-up is unconfigured."
7479
+ "Amount an auto top-up charges, USD cents. Null when auto-top-up is unconfigured."
7357
7480
  )
7358
7481
  },
7359
7482
  annotations: annotationsFor("wallet_balance", "read")
@@ -7376,6 +7499,9 @@ function registerWalletTools(server2, ctx) {
7376
7499
  });
7377
7500
  return okStructured({
7378
7501
  org_id: orgId,
7502
+ balance_cents: wallet.balance_cents,
7503
+ currency: wallet.currency,
7504
+ balance_usd_cents: wallet.balance_usd_cents,
7379
7505
  balance_eur_cents: wallet.balance_eur_cents,
7380
7506
  auto_topup_enabled: wallet.auto_topup_enabled,
7381
7507
  auto_topup_threshold_cents: wallet.auto_topup_threshold_cents,
@@ -7392,10 +7518,10 @@ function registerWalletTools(server2, ctx) {
7392
7518
  "wallet_topup_checkout",
7393
7519
  {
7394
7520
  title: "Wallet Top-up Checkout",
7395
- description: "Create a Stripe Checkout link so a human can top up the Carrier prepaid wallet by card. This tool charges nothing itself: it returns a hosted URL, and the wallet is credited (pack amount + bonus) only after someone completes the payment in a browser. Params: `pack` (optional \u2014 pack id `pack_25`/`pack_50`/`pack_100`/`pack_500`/`pack_1000`/`pack_2500`/`pack_5000`, or an exact EUR-cents amount matching a catalog pack; omit to list the packs and their bonuses without creating a session). Returns: { pack_id, pack_eur_cents, bonus_eur_cents, checkout_session_id, checkout_url } \u2014 amounts in EUR cents. Do NOT use this when the wallet must be funded now with no human in the loop \u2014 use `wallet_auto_topup`, which charges the saved card immediately. Do NOT use this to move money in OCS \u2014 `modify_account_balance` and `modify_subscriber_balance` are unrelated ledgers.",
7521
+ description: "Create a Stripe Checkout link so a human can top up the Carrier prepaid wallet by card. This tool charges nothing itself: it returns a hosted URL, and the wallet is credited (pack amount + bonus) only after someone completes the payment in a browser. Params: `pack` (optional \u2014 pack id `pack_25`/`pack_50`/`pack_100`/`pack_500`/`pack_1000`/`pack_2500`/`pack_5000`, or an exact USD-cents amount matching a catalog pack; omit to list the packs and their bonuses without creating a session). Returns: { pack_id, pack_cents, bonus_cents, currency, checkout_session_id, checkout_url } \u2014 amounts in USD cents. Do NOT use this when the wallet must be funded now with no human in the loop \u2014 use `wallet_auto_topup`, which charges the saved card immediately. Do NOT use this to move money in OCS \u2014 `modify_account_balance` and `modify_subscriber_balance` are unrelated ledgers.",
7396
7522
  inputSchema: {
7397
7523
  pack: z9.string().optional().describe(
7398
- "Pack id (pack_25/pack_50/pack_100/pack_500/pack_1000/pack_2500/pack_5000) or exact EUR-cents amount. Omit to list packs."
7524
+ "Pack id (pack_25/pack_50/pack_100/pack_500/pack_1000/pack_2500/pack_5000) or exact USD-cents amount. Omit to list packs."
7399
7525
  )
7400
7526
  },
7401
7527
  /**
@@ -7410,16 +7536,18 @@ function registerWalletTools(server2, ctx) {
7410
7536
  packs: z9.array(
7411
7537
  z9.object({
7412
7538
  id: z9.string(),
7413
- eur_cents: z9.number().int(),
7539
+ amount_cents: z9.number().int(),
7540
+ currency: z9.literal("usd"),
7414
7541
  bonus_pct: z9.number(),
7415
- bonus_eur_cents: z9.number().int(),
7416
- credited_eur_cents: z9.number().int()
7542
+ bonus_cents: z9.number().int(),
7543
+ credited_cents: z9.number().int()
7417
7544
  })
7418
7545
  ).optional().describe("Catalogue arm \u2014 present only when `pack` was omitted."),
7419
7546
  org_id: z9.string().optional().describe("Session arm."),
7420
7547
  pack_id: z9.string().optional().describe("Session arm."),
7421
- pack_eur_cents: z9.number().int().optional().describe("Session arm."),
7422
- bonus_eur_cents: z9.number().int().optional().describe("Session arm."),
7548
+ pack_cents: z9.number().int().optional().describe("Session arm."),
7549
+ bonus_cents: z9.number().int().optional().describe("Session arm."),
7550
+ currency: z9.literal("usd").optional().describe("Session arm."),
7423
7551
  checkout_session_id: z9.string().optional().describe("Session arm."),
7424
7552
  checkout_url: z9.string().nullable().optional().describe("Session arm. Stripe may return null for a session URL.")
7425
7553
  },
@@ -7434,10 +7562,11 @@ function registerWalletTools(server2, ctx) {
7434
7562
  return okStructured({
7435
7563
  packs: PACKS.map((p) => ({
7436
7564
  id: p.id,
7437
- eur_cents: p.eurCents,
7565
+ amount_cents: p.amountCents,
7566
+ currency: PACK_CURRENCY,
7438
7567
  bonus_pct: p.bonusPct,
7439
- bonus_eur_cents: bonusCentsFor(p),
7440
- credited_eur_cents: p.eurCents + bonusCentsFor(p)
7568
+ bonus_cents: bonusCentsFor(p),
7569
+ credited_cents: p.amountCents + bonusCentsFor(p)
7441
7570
  }))
7442
7571
  });
7443
7572
  }
@@ -7461,8 +7590,9 @@ function registerWalletTools(server2, ctx) {
7461
7590
  return okStructured({
7462
7591
  org_id: orgId,
7463
7592
  pack_id: selected.id,
7464
- pack_eur_cents: selected.eurCents,
7465
- bonus_eur_cents: bonusCentsFor(selected),
7593
+ pack_cents: selected.amountCents,
7594
+ bonus_cents: bonusCentsFor(selected),
7595
+ currency: PACK_CURRENCY,
7466
7596
  checkout_session_id: session.id,
7467
7597
  checkout_url: session.url
7468
7598
  });
@@ -7476,9 +7606,9 @@ function registerWalletTools(server2, ctx) {
7476
7606
  "wallet_auto_topup",
7477
7607
  {
7478
7608
  title: "Wallet Auto Top-up (charges card now)",
7479
- description: "Charge the organisation's saved card off-session, right now, and credit the Carrier prepaid wallet with the pack. This spends real money without any browser step or human confirmation, so only call it when the user has asked to be charged. Params: `pack_cents` (optional integer, EUR cents \u2014 must match a catalog pack; omit to use the organisation's configured auto-top-up pack). Returns on success: { org_id, charged: true, credited_eur_cents, balance_after_cents, payment_intent_id } \u2014 amounts in EUR cents. Returns { charged: false, reason } as an error when the card declines or no payment method is saved. Do NOT use this to let a human pay in a browser \u2014 use `wallet_topup_checkout`, which only returns a link. Do NOT use this to change the threshold that triggers automatic top-ups; this tool performs one charge and does not edit the configuration. Do NOT use this to credit an OCS reseller account or subscriber \u2014 see `modify_account_balance` and `modify_subscriber_balance`.",
7609
+ description: "Charge the organisation's saved card off-session, right now, and credit the Carrier prepaid wallet with the pack. This spends real money without any browser step or human confirmation, so only call it when the user has asked to be charged. Params: `pack_cents` (optional integer, USD cents \u2014 must match a catalog pack; omit to use the organisation's configured auto-top-up pack). Returns on success: { org_id, charged: true, credited_cents, currency, balance_after_cents, payment_intent_id } \u2014 amounts in USD cents. Returns { charged: false, reason } as an error when the card declines or no payment method is saved. Do NOT use this to let a human pay in a browser \u2014 use `wallet_topup_checkout`, which only returns a link. Do NOT use this to change the threshold that triggers automatic top-ups; this tool performs one charge and does not edit the configuration. Do NOT use this to credit an OCS reseller account or subscriber \u2014 see `modify_account_balance` and `modify_subscriber_balance`.",
7480
7610
  inputSchema: {
7481
- pack_cents: z9.number().int().positive().optional().describe("Override pack amount in EUR cents (must match a catalog pack).")
7611
+ pack_cents: z9.number().int().positive().optional().describe("Override pack amount in USD cents (must match a catalog pack).")
7482
7612
  },
7483
7613
  /**
7484
7614
  * Only the charged arm is described here — `charged: false` returns
@@ -7495,7 +7625,8 @@ function registerWalletTools(server2, ctx) {
7495
7625
  outputSchema: {
7496
7626
  org_id: z9.string(),
7497
7627
  charged: z9.literal(true),
7498
- credited_eur_cents: z9.number().int(),
7628
+ credited_cents: z9.number().int(),
7629
+ currency: z9.literal("usd"),
7499
7630
  balance_after_cents: z9.number().int().optional().describe("Absent when the charge succeeded but crediting is pending."),
7500
7631
  payment_intent_id: z9.string().optional(),
7501
7632
  note: z9.string().optional().describe("Present when the charge landed but the credit is still pending.")
@@ -7526,7 +7657,8 @@ function registerWalletTools(server2, ctx) {
7526
7657
  return okStructured({
7527
7658
  org_id: orgId,
7528
7659
  charged: true,
7529
- credited_eur_cents: result3.creditedCents,
7660
+ credited_cents: result3.creditedCents,
7661
+ currency: PACK_CURRENCY,
7530
7662
  // Spread rather than assign, so the key is absent instead of set to
7531
7663
  // `undefined`. JSON.stringify drops an undefined value anyway, so
7532
7664
  // assigning it would make `content` and `structuredContent` disagree
@@ -7549,8 +7681,8 @@ var AI_WALLET_TOOL_SCOPES = {
7549
7681
  ai_wallet_auto_topup: "write"
7550
7682
  };
7551
7683
  async function aiWallet(env, orgId, method, body2) {
7552
- const response = await fetch(
7553
- `${env.ATLAS_BASE_URL ?? "https://atlas.carrier.llc"}/internal/ai-topup/${encodeURIComponent(orgId)}`,
7684
+ const response = await internalAtlasFetch(
7685
+ `${resolveInternalAtlasBase(env)}/internal/ai-topup/${encodeURIComponent(orgId)}`,
7554
7686
  {
7555
7687
  method,
7556
7688
  headers: {
@@ -13795,6 +13927,7 @@ var stdioEnv = {
13795
13927
  // registered (catalog parity with the Worker) and return an explicit
13796
13928
  // configuration error instead of silently disappearing from tools/list.
13797
13929
  ATLAS_BASE_URL: process.env.ATLAS_BASE_URL,
13930
+ CARRIER_ENVIRONMENT: process.env.CARRIER_ENVIRONMENT,
13798
13931
  CARRIER_INTERNAL_API_KEY: process.env.CARRIER_INTERNAL_API_KEY,
13799
13932
  WALLET_CHECKOUT_SUCCESS_URL: process.env.WALLET_CHECKOUT_SUCCESS_URL,
13800
13933
  WALLET_CHECKOUT_CANCEL_URL: process.env.WALLET_CHECKOUT_CANCEL_URL,