@carrierllc/mcp 0.13.61 → 0.13.63
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/{chunk-JEIKZQ4Z.js → chunk-WCIQ6OYP.js} +453 -138
- package/dist/chunk-WCIQ6OYP.js.map +1 -0
- package/dist/cli.js +156 -4
- package/dist/cli.js.map +1 -1
- package/dist/index.js +741 -589
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-JEIKZQ4Z.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -40,6 +40,7 @@ import {
|
|
|
40
40
|
loadStorefrontBrand,
|
|
41
41
|
locationParams,
|
|
42
42
|
locationZoneCreateParams,
|
|
43
|
+
marketingSnapshot,
|
|
43
44
|
mccToIso,
|
|
44
45
|
mergeEnvLocal,
|
|
45
46
|
modifySubscriberContactInfoFromTool,
|
|
@@ -48,6 +49,7 @@ import {
|
|
|
48
49
|
networkDefaultPartition,
|
|
49
50
|
networkEventRows,
|
|
50
51
|
networkEventsOverPeriodParams,
|
|
52
|
+
ocsArray,
|
|
51
53
|
ocsHlrBitrate,
|
|
52
54
|
ocsHlrBitrateFromBps,
|
|
53
55
|
ocsLocalDateTime,
|
|
@@ -68,13 +70,19 @@ import {
|
|
|
68
70
|
recordToolDescription,
|
|
69
71
|
recurringIdForPackage,
|
|
70
72
|
recurringPackageParams,
|
|
73
|
+
regionalArpu,
|
|
74
|
+
regionalArpuPeriod,
|
|
71
75
|
renderHtml,
|
|
76
|
+
renderMarketingContext,
|
|
77
|
+
renderRegionalArpu,
|
|
72
78
|
repairPlanFor,
|
|
73
79
|
scopeListSubscriberParams,
|
|
74
80
|
setNetworkDefault,
|
|
75
81
|
staleActivePackages,
|
|
76
82
|
storefrontClerkUrls,
|
|
83
|
+
subscriberIccid,
|
|
77
84
|
subscriberIdParams,
|
|
85
|
+
subscriberListEnvelope,
|
|
78
86
|
subscriberRows,
|
|
79
87
|
subscriberSimId,
|
|
80
88
|
summarizeNetworkEvents,
|
|
@@ -82,7 +90,7 @@ import {
|
|
|
82
90
|
verifyStorefront,
|
|
83
91
|
withOcsListSummary,
|
|
84
92
|
withTemplateResellerId
|
|
85
|
-
} from "./chunk-
|
|
93
|
+
} from "./chunk-WCIQ6OYP.js";
|
|
86
94
|
import "./chunk-SHKKVIIA.js";
|
|
87
95
|
|
|
88
96
|
// src/index.ts
|
|
@@ -1113,7 +1121,7 @@ function boundTariffResult(raw, opts = {}) {
|
|
|
1113
1121
|
const cap = opts.maxRules ?? (verbose ? TARIFF_VERBOSE_MAX_RULES : TARIFF_MAX_RULES);
|
|
1114
1122
|
const kept = matched.slice(0, cap);
|
|
1115
1123
|
const truncated = kept.length < matched.length;
|
|
1116
|
-
const
|
|
1124
|
+
const result3 = {
|
|
1117
1125
|
resellerId,
|
|
1118
1126
|
totalRules: all.length,
|
|
1119
1127
|
matchedRules: matched.length,
|
|
@@ -1123,22 +1131,22 @@ function boundTariffResult(raw, opts = {}) {
|
|
|
1123
1131
|
rules: []
|
|
1124
1132
|
};
|
|
1125
1133
|
if (country !== void 0 || trafficType !== void 0) {
|
|
1126
|
-
|
|
1127
|
-
if (country !== void 0)
|
|
1128
|
-
if (trafficType !== void 0)
|
|
1134
|
+
result3.filters = {};
|
|
1135
|
+
if (country !== void 0) result3.filters.country = country;
|
|
1136
|
+
if (trafficType !== void 0) result3.filters.trafficType = trafficType;
|
|
1129
1137
|
}
|
|
1130
1138
|
if (verbose) {
|
|
1131
|
-
|
|
1132
|
-
if (truncated)
|
|
1133
|
-
return
|
|
1139
|
+
result3.rules = kept;
|
|
1140
|
+
if (truncated) result3.note = truncationNote("tariff", kept.length, matched.length);
|
|
1141
|
+
return result3;
|
|
1134
1142
|
}
|
|
1135
1143
|
const currencies = new Set(
|
|
1136
1144
|
kept.map((r) => r.currency?.currencycode).filter((c) => typeof c === "string")
|
|
1137
1145
|
);
|
|
1138
1146
|
const hoistCurrency = currencies.size === 1;
|
|
1139
|
-
if (hoistCurrency)
|
|
1147
|
+
if (hoistCurrency) result3.currency = [...currencies][0];
|
|
1140
1148
|
const columns = trafficType ? RATE_COLUMNS[trafficType] : ALL_RATE_COLUMNS;
|
|
1141
|
-
|
|
1149
|
+
result3.rules = kept.map((r) => {
|
|
1142
1150
|
const op = r.operator ?? {};
|
|
1143
1151
|
const row = {};
|
|
1144
1152
|
if (op.countryIso2 !== void 0) row.iso = op.countryIso2;
|
|
@@ -1160,14 +1168,14 @@ function boundTariffResult(raw, opts = {}) {
|
|
|
1160
1168
|
}
|
|
1161
1169
|
}
|
|
1162
1170
|
if (!hoistCurrency) legend.cur = "ISO-4217 currency code";
|
|
1163
|
-
|
|
1171
|
+
result3.fields = legend;
|
|
1164
1172
|
const notes = [];
|
|
1165
1173
|
if (truncated) notes.push(truncationNote("tariff", kept.length, matched.length));
|
|
1166
1174
|
notes.push(
|
|
1167
1175
|
`Projected result: nested operator detail (mccMncs, tadigs, continent, countryCode, utcOffset), the sponsor object, plan ids (roamingplanruleid, roamingplanid, sponsoridx) and the validity/discount flags (startdate, enddate, isDiscounted, hidden, dailyCap) are omitted. Pass verbose=true for the full untouched rule shape (capped at ${TARIFF_VERBOSE_MAX_RULES} rows \u2014 use 'country'/'trafficType' with it).`
|
|
1168
1176
|
);
|
|
1169
|
-
|
|
1170
|
-
return
|
|
1177
|
+
result3.note = notes.join(" ");
|
|
1178
|
+
return result3;
|
|
1171
1179
|
}
|
|
1172
1180
|
var ZONE_FIELD_LEGEND = {
|
|
1173
1181
|
zoneId: "location zone id \u2014 pass to package-template tools",
|
|
@@ -1180,22 +1188,22 @@ function boundZonesResult(raw, opts = {}) {
|
|
|
1180
1188
|
const { verbose = false, resellerId } = opts;
|
|
1181
1189
|
const maxZones = opts.maxZones ?? ZONES_MAX_ZONES;
|
|
1182
1190
|
const maxOperators = opts.maxOperators ?? (verbose ? ZONES_VERBOSE_MAX_OPERATORS : ZONES_MAX_OPERATORS);
|
|
1183
|
-
const totalOperators = all.reduce((n,
|
|
1191
|
+
const totalOperators = all.reduce((n, z29) => n + (z29.operators?.length ?? 0), 0);
|
|
1184
1192
|
const keptZones = all.slice(0, maxZones);
|
|
1185
1193
|
let budget = maxOperators;
|
|
1186
1194
|
let returnedOperators = 0;
|
|
1187
|
-
const zones = keptZones.map((
|
|
1188
|
-
const ops =
|
|
1195
|
+
const zones = keptZones.map((z29) => {
|
|
1196
|
+
const ops = z29.operators ?? [];
|
|
1189
1197
|
const take = Math.max(0, Math.min(ops.length, budget));
|
|
1190
1198
|
budget -= take;
|
|
1191
1199
|
returnedOperators += take;
|
|
1192
1200
|
const sliced = ops.slice(0, take);
|
|
1193
1201
|
if (verbose) {
|
|
1194
|
-
return { ...
|
|
1202
|
+
return { ...z29, operators: sliced, operatorCount: ops.length };
|
|
1195
1203
|
}
|
|
1196
1204
|
return {
|
|
1197
|
-
zoneId:
|
|
1198
|
-
zoneName:
|
|
1205
|
+
zoneId: z29.zoneId,
|
|
1206
|
+
zoneName: z29.zoneName,
|
|
1199
1207
|
operatorCount: ops.length,
|
|
1200
1208
|
operators: sliced.map((o) => ({
|
|
1201
1209
|
net: o.networkId,
|
|
@@ -1205,7 +1213,7 @@ function boundZonesResult(raw, opts = {}) {
|
|
|
1205
1213
|
};
|
|
1206
1214
|
});
|
|
1207
1215
|
const truncated = keptZones.length < all.length || returnedOperators < totalOperators;
|
|
1208
|
-
const
|
|
1216
|
+
const result3 = {
|
|
1209
1217
|
resellerId,
|
|
1210
1218
|
totalZones: all.length,
|
|
1211
1219
|
returnedZones: keptZones.length,
|
|
@@ -1218,13 +1226,13 @@ function boundZonesResult(raw, opts = {}) {
|
|
|
1218
1226
|
const notes = [];
|
|
1219
1227
|
if (truncated) notes.push(truncationNote("zones", returnedOperators, totalOperators));
|
|
1220
1228
|
if (!verbose) {
|
|
1221
|
-
|
|
1229
|
+
result3.fields = ZONE_FIELD_LEGEND;
|
|
1222
1230
|
notes.push(
|
|
1223
1231
|
`Projected result: per-operator mccMncs, tadigs, continent, countryCode, countryName and utcOffset are omitted, as is the repeated reseller object. Pass verbose=true for the full untouched zone shape (capped at ${ZONES_VERBOSE_MAX_OPERATORS} operator entries).`
|
|
1224
1232
|
);
|
|
1225
1233
|
}
|
|
1226
|
-
if (notes.length)
|
|
1227
|
-
return
|
|
1234
|
+
if (notes.length) result3.note = notes.join(" ");
|
|
1235
|
+
return result3;
|
|
1228
1236
|
}
|
|
1229
1237
|
|
|
1230
1238
|
// src/tools.ts
|
|
@@ -1397,11 +1405,11 @@ function wrapHandler(toolName, ocsMethod, requiredScope, ctx, handler, options)
|
|
|
1397
1405
|
]
|
|
1398
1406
|
};
|
|
1399
1407
|
}
|
|
1400
|
-
let
|
|
1408
|
+
let result3;
|
|
1401
1409
|
try {
|
|
1402
1410
|
const skipToken = typeof options?.skipUserToken === "function" ? options.skipUserToken(args) : options?.skipUserToken;
|
|
1403
1411
|
const token2 = skipToken ? "" : await ctx.getUserToken(ctx.props.sub);
|
|
1404
|
-
|
|
1412
|
+
result3 = extra === void 0 ? await handler(args, token2) : await handler(args, token2, extra);
|
|
1405
1413
|
} catch (err9) {
|
|
1406
1414
|
try {
|
|
1407
1415
|
Sentry.captureException(err9, {
|
|
@@ -1428,30 +1436,30 @@ function wrapHandler(toolName, ocsMethod, requiredScope, ctx, handler, options)
|
|
|
1428
1436
|
content: [{ type: "text", text: `Error: ${message}` }]
|
|
1429
1437
|
};
|
|
1430
1438
|
}
|
|
1431
|
-
const handledOcsCode =
|
|
1439
|
+
const handledOcsCode = result3.ocsStatusCode;
|
|
1432
1440
|
if (handledOcsCode !== void 0) {
|
|
1433
|
-
const { ocsStatusCode: _auditOnly, ...clientResult } =
|
|
1441
|
+
const { ocsStatusCode: _auditOnly, ...clientResult } = result3;
|
|
1434
1442
|
void _auditOnly;
|
|
1435
|
-
|
|
1443
|
+
result3 = clientResult;
|
|
1436
1444
|
}
|
|
1437
1445
|
ctx.audit({
|
|
1438
1446
|
tool_name: toolName,
|
|
1439
1447
|
ocs_method: ocsMethod,
|
|
1440
|
-
status:
|
|
1448
|
+
status: result3.isError ? "error" : "ok",
|
|
1441
1449
|
dry_run: isDryRun,
|
|
1442
1450
|
duration_ms: Date.now() - start,
|
|
1443
1451
|
...handledOcsCode !== void 0 ? { ocs_status_code: handledOcsCode } : {}
|
|
1444
1452
|
});
|
|
1445
|
-
if (!
|
|
1453
|
+
if (!result3.isError && !isDryRun) {
|
|
1446
1454
|
recordUsage(ctx.env, ctx.props.sub, ctx.props.tier);
|
|
1447
1455
|
}
|
|
1448
|
-
return
|
|
1456
|
+
return result3;
|
|
1449
1457
|
};
|
|
1450
1458
|
}
|
|
1451
1459
|
async function ocsCall(env, token2, method, params = {}, listKind) {
|
|
1452
1460
|
const client2 = new OcsClient(env.CARRIER_OCS_BASE_URL, token2);
|
|
1453
|
-
const
|
|
1454
|
-
const payload = listKind ? withOcsListSummary(
|
|
1461
|
+
const result3 = await client2.call(method, params);
|
|
1462
|
+
const payload = listKind ? withOcsListSummary(result3, listKind) : result3;
|
|
1455
1463
|
return {
|
|
1456
1464
|
content: [{ type: "text", text: JSON.stringify(payload, null, 2) }]
|
|
1457
1465
|
};
|
|
@@ -2749,7 +2757,7 @@ function registerAllTools(server2, ctx) {
|
|
|
2749
2757
|
}
|
|
2750
2758
|
|
|
2751
2759
|
// src/intelligence.ts
|
|
2752
|
-
import { z as
|
|
2760
|
+
import { z as z3 } from "zod";
|
|
2753
2761
|
|
|
2754
2762
|
// ../../packages/ocs-spec/ocs-methods.json
|
|
2755
2763
|
var ocs_methods_default = {
|
|
@@ -3829,7 +3837,8 @@ var ocsIntelligenceMethods = ocsSpec.v1_intelligence_methods;
|
|
|
3829
3837
|
var ocsBacklog = ocsSpec.v1_1_backlog;
|
|
3830
3838
|
var ocsAppMethods = ocsSpec.v1_app_methods;
|
|
3831
3839
|
|
|
3832
|
-
// src/intelligence.ts
|
|
3840
|
+
// src/marketing-intelligence.ts
|
|
3841
|
+
import { z as z2 } from "zod";
|
|
3833
3842
|
async function safeCall(env, token2, method, params = {}) {
|
|
3834
3843
|
try {
|
|
3835
3844
|
const client2 = new OcsClient(env.CARRIER_OCS_BASE_URL, token2);
|
|
@@ -3839,12 +3848,118 @@ async function safeCall(env, token2, method, params = {}) {
|
|
|
3839
3848
|
return { data: null, error: err9 instanceof Error ? err9.message : String(err9) };
|
|
3840
3849
|
}
|
|
3841
3850
|
}
|
|
3851
|
+
function result(text, isError = false) {
|
|
3852
|
+
return { content: [{ type: "text", text }], ...isError ? { isError: true } : {} };
|
|
3853
|
+
}
|
|
3854
|
+
function registerMarketingIntelligenceTool(server2, ctx) {
|
|
3855
|
+
server2.registerTool("marketing_intelligence", {
|
|
3856
|
+
title: "Marketing Intelligence Report",
|
|
3857
|
+
description: "Reports regional ARPU from historical rated subscriber charges, measured subscribers, and catalogue coverage. Countries and currencies remain separate; missing charges are reported.",
|
|
3858
|
+
inputSchema: {
|
|
3859
|
+
accountId: z2.number().optional().describe("Filter to a specific account"),
|
|
3860
|
+
start: z2.string().optional().describe("Usage period start (YYYY-MM-DD, maximum seven inclusive days)"),
|
|
3861
|
+
end: z2.string().optional().describe("Usage period end (YYYY-MM-DD, default today UTC)")
|
|
3862
|
+
},
|
|
3863
|
+
annotations: { readOnlyHint: true }
|
|
3864
|
+
}, async ({ accountId, start, end }) => {
|
|
3865
|
+
let period;
|
|
3866
|
+
try {
|
|
3867
|
+
period = regionalArpuPeriod(start, end);
|
|
3868
|
+
} catch (err9) {
|
|
3869
|
+
return result(err9 instanceof Error ? err9.message : String(err9), true);
|
|
3870
|
+
}
|
|
3871
|
+
const token2 = await ctx.getUserToken(ctx.props.sub);
|
|
3872
|
+
const params = {};
|
|
3873
|
+
const accountIds = tenantAccountIds(ctx.managedAuth);
|
|
3874
|
+
if (accountIds?.length === 0) return result("Subscriber not found", true);
|
|
3875
|
+
if (!ctx.managedAuth.managed && accountIds !== void 0 && accountId !== void 0 && !accountIds.includes(accountId)) return result("Account not found", true);
|
|
3876
|
+
if (accountIds !== void 0) {
|
|
3877
|
+
params.accountId = accountId !== void 0 && accountIds.includes(accountId) ? accountId : accountIds[0];
|
|
3878
|
+
} else if (accountId !== void 0) {
|
|
3879
|
+
params.accountId = accountId;
|
|
3880
|
+
}
|
|
3881
|
+
const scope = await scopeListSubscriberParams({
|
|
3882
|
+
params,
|
|
3883
|
+
managed: ctx.managedAuth.managed,
|
|
3884
|
+
preferredAccountId: ctx.managedAuth.preferredAccountId,
|
|
3885
|
+
call: async (method, callParams) => {
|
|
3886
|
+
const response = await safeCall(ctx.env, token2, method, callParams);
|
|
3887
|
+
if (response.error) throw new Error(response.error);
|
|
3888
|
+
return response.data;
|
|
3889
|
+
}
|
|
3890
|
+
});
|
|
3891
|
+
if (!scope.ok) return result(scope.message, true);
|
|
3892
|
+
const [subsResult, templatesResult, resellerId] = await Promise.all([
|
|
3893
|
+
safeCall(ctx.env, token2, "listSubscriber", scope.params),
|
|
3894
|
+
safeCall(ctx.env, token2, "listPrepaidPackageTemplate", {}),
|
|
3895
|
+
getDefaultResellerId(ctx.env, token2)
|
|
3896
|
+
]);
|
|
3897
|
+
if (subsResult.error) return result(`Failed to fetch subscribers: ${subsResult.error}`, true);
|
|
3898
|
+
const subscribers = ocsArray(subsResult.data, ["subscriberList", "subscribers", "subscriber"]);
|
|
3899
|
+
const distinct = [...new Map(subscribers.map((sub, index) => [subscriberIccid(sub) || `missing-iccid:${index}`, sub])).entries()];
|
|
3900
|
+
const sample = distinct.slice(0, 100);
|
|
3901
|
+
const reads = [];
|
|
3902
|
+
const snapshots = [];
|
|
3903
|
+
for (let i = 0; i < sample.length; i += 10) {
|
|
3904
|
+
reads.push(...await Promise.all(sample.slice(i, i + 10).map(async ([subscriber, sub]) => {
|
|
3905
|
+
const iccid = subscriberIccid(sub);
|
|
3906
|
+
if (!iccid) return { subscriber, data: null, error: "Missing subscriber ICCID" };
|
|
3907
|
+
const access = await assertManagedIccidAccess(
|
|
3908
|
+
ctx.env.CARRIER_OCS_BASE_URL,
|
|
3909
|
+
{ ...ctx.managedAuth, token: token2 },
|
|
3910
|
+
iccid
|
|
3911
|
+
);
|
|
3912
|
+
if (!access.ok) return { subscriber, data: null, error: access.error };
|
|
3913
|
+
const usage = await safeCall(ctx.env, token2, "subscriberUsageOverPeriod", {
|
|
3914
|
+
subscriber: { iccid },
|
|
3915
|
+
period
|
|
3916
|
+
});
|
|
3917
|
+
const current = await safeCall(ctx.env, token2, "getSingleSubscriber", { iccid });
|
|
3918
|
+
if (!isManagedSubscriberDenied(ctx.managedAuth, current.data)) {
|
|
3919
|
+
snapshots.push(marketingSnapshot(sub, current.data));
|
|
3920
|
+
}
|
|
3921
|
+
return { subscriber, data: usage.data, error: usage.error };
|
|
3922
|
+
})));
|
|
3923
|
+
}
|
|
3924
|
+
const envelope = subscriberListEnvelope(subsResult.data);
|
|
3925
|
+
const total = typeof envelope?.nbFound === "number" && Number.isFinite(envelope.nbFound) ? Math.max(distinct.length, envelope.nbFound) : distinct.length;
|
|
3926
|
+
const report = regionalArpu(reads, {
|
|
3927
|
+
period,
|
|
3928
|
+
total_subscribers: total,
|
|
3929
|
+
truncated: envelope?.hasMore === true || envelope?.truncated === true || sample.length < distinct.length
|
|
3930
|
+
});
|
|
3931
|
+
const sections = ["# Marketing Intelligence Report\n", renderRegionalArpu(report)];
|
|
3932
|
+
if (scope.defaultAccount) sections.push(scope.defaultAccount.note);
|
|
3933
|
+
const zonesResult = await safeCall(ctx.env, token2, "listDetailedLocationZone", resellerId);
|
|
3934
|
+
const zones = ocsArray(zonesResult.data, "zones");
|
|
3935
|
+
const templates = ocsArray(templatesResult.data, "templates");
|
|
3936
|
+
sections.push(
|
|
3937
|
+
`
|
|
3938
|
+
## Coverage Catalog
|
|
3939
|
+
- Location zones available: ${zonesResult.error ? `Unavailable (${zonesResult.error})` : zones.length}
|
|
3940
|
+
- Package templates available: ${templatesResult.error ? `Unavailable (${templatesResult.error})` : templates.length}`
|
|
3941
|
+
);
|
|
3942
|
+
sections.push(renderMarketingContext(snapshots, sample.length, templates));
|
|
3943
|
+
return result(sections.join("\n"));
|
|
3944
|
+
});
|
|
3945
|
+
}
|
|
3946
|
+
|
|
3947
|
+
// src/intelligence.ts
|
|
3948
|
+
async function safeCall2(env, token2, method, params = {}) {
|
|
3949
|
+
try {
|
|
3950
|
+
const client2 = new OcsClient(env.CARRIER_OCS_BASE_URL, token2);
|
|
3951
|
+
const data = await client2.call(method, params);
|
|
3952
|
+
return { data, error: null };
|
|
3953
|
+
} catch (err9) {
|
|
3954
|
+
return { data: null, error: err9 instanceof Error ? err9.message : String(err9) };
|
|
3955
|
+
}
|
|
3956
|
+
}
|
|
3842
3957
|
async function fetchActiveSubscribers(env, token2, accountId, resellerId) {
|
|
3843
3958
|
let accountIds;
|
|
3844
3959
|
if (accountId !== void 0) {
|
|
3845
3960
|
accountIds = [accountId];
|
|
3846
3961
|
} else {
|
|
3847
|
-
const accountsResult = await
|
|
3962
|
+
const accountsResult = await safeCall2(
|
|
3848
3963
|
env,
|
|
3849
3964
|
token2,
|
|
3850
3965
|
"listResellerAccount",
|
|
@@ -3857,7 +3972,7 @@ async function fetchActiveSubscribers(env, token2, accountId, resellerId) {
|
|
|
3857
3972
|
}
|
|
3858
3973
|
const aggregated = [];
|
|
3859
3974
|
for (const acctId of accountIds) {
|
|
3860
|
-
const subResult = await
|
|
3975
|
+
const subResult = await safeCall2(
|
|
3861
3976
|
env,
|
|
3862
3977
|
token2,
|
|
3863
3978
|
"listSubscriber",
|
|
@@ -3868,7 +3983,7 @@ async function fetchActiveSubscribers(env, token2, accountId, resellerId) {
|
|
|
3868
3983
|
}
|
|
3869
3984
|
return { data: filterActiveSubscribers(aggregated), error: null };
|
|
3870
3985
|
}
|
|
3871
|
-
function
|
|
3986
|
+
function result2(text, isError = false) {
|
|
3872
3987
|
return { content: [{ type: "text", text }], ...isError ? { isError: true } : {} };
|
|
3873
3988
|
}
|
|
3874
3989
|
function registerIntelligenceTools(server2, ctx) {
|
|
@@ -3876,7 +3991,7 @@ function registerIntelligenceTools(server2, ctx) {
|
|
|
3876
3991
|
title: "Diagnose Subscriber Issues",
|
|
3877
3992
|
description: "Smart diagnostic that chains multiple API calls to analyze why a subscriber may be offline, throttled, or having connectivity issues. Returns a structured diagnosis with root cause analysis and recommended actions.",
|
|
3878
3993
|
inputSchema: {
|
|
3879
|
-
iccid:
|
|
3994
|
+
iccid: z3.string().describe("The subscriber ICCID to diagnose")
|
|
3880
3995
|
},
|
|
3881
3996
|
annotations: { readOnlyHint: true }
|
|
3882
3997
|
}, async ({ iccid }) => {
|
|
@@ -3884,9 +3999,9 @@ function registerIntelligenceTools(server2, ctx) {
|
|
|
3884
3999
|
const findings = [];
|
|
3885
4000
|
const actions = [];
|
|
3886
4001
|
let severity = "healthy";
|
|
3887
|
-
const sub = await
|
|
3888
|
-
if (sub.error) return
|
|
3889
|
-
if (!sub.data) return
|
|
4002
|
+
const sub = await safeCall2(ctx.env, token2, "getSingleSubscriber", { iccid });
|
|
4003
|
+
if (sub.error) return result2(`Failed to fetch subscriber: ${sub.error}`, true);
|
|
4004
|
+
if (!sub.data) return result2("Subscriber not found", true);
|
|
3890
4005
|
const status = (extractSubscriberStatus(sub.data) ?? "").toUpperCase();
|
|
3891
4006
|
const balance = Number(sub.data.balance ?? 0);
|
|
3892
4007
|
if (status === "") {
|
|
@@ -3897,7 +4012,7 @@ function registerIntelligenceTools(server2, ctx) {
|
|
|
3897
4012
|
actions.push(`Reactivate subscriber via modify_subscriber_status`);
|
|
3898
4013
|
severity = "critical";
|
|
3899
4014
|
}
|
|
3900
|
-
const pkgs = await
|
|
4015
|
+
const pkgs = await safeCall2(ctx.env, token2, "listSubscriberPrepaidPackages", { iccid });
|
|
3901
4016
|
const allPkgs = prepaidPackageRows(pkgs.data);
|
|
3902
4017
|
const activePkgs = allPkgs.filter((p) => isActivePackage(p));
|
|
3903
4018
|
const stalePkgs = staleActivePackages(allPkgs);
|
|
@@ -3949,7 +4064,7 @@ function registerIntelligenceTools(server2, ctx) {
|
|
|
3949
4064
|
if (severity !== "critical") severity = "warning";
|
|
3950
4065
|
}
|
|
3951
4066
|
const simId = subscriberSimId(sub.data);
|
|
3952
|
-
const sim = simId !== void 0 ? await
|
|
4067
|
+
const sim = simId !== void 0 ? await safeCall2(ctx.env, token2, "getSimProviderStatus", simId) : { data: null, error: null };
|
|
3953
4068
|
if (sim.data) {
|
|
3954
4069
|
const simStatus = (extractSimProviderStatus(sim.data) ?? "").toUpperCase();
|
|
3955
4070
|
if (simStatus && !["ENABLED", "ACTIVE", "ACTIVATED"].includes(simStatus)) {
|
|
@@ -3960,7 +4075,7 @@ function registerIntelligenceTools(server2, ctx) {
|
|
|
3960
4075
|
}
|
|
3961
4076
|
const now = /* @__PURE__ */ new Date();
|
|
3962
4077
|
const eventWindow = lastNDaysPeriod(3, now);
|
|
3963
|
-
const events = await
|
|
4078
|
+
const events = await safeCall2(ctx.env, token2, "subscriberNetworkEventsOverPeriod", {
|
|
3964
4079
|
subscriber: { iccid },
|
|
3965
4080
|
period: eventWindow
|
|
3966
4081
|
});
|
|
@@ -3998,7 +4113,7 @@ function registerIntelligenceTools(server2, ctx) {
|
|
|
3998
4113
|
}
|
|
3999
4114
|
}
|
|
4000
4115
|
const imsiForBitrate = imsiFromSubscriberRecord(sub.data) ?? null;
|
|
4001
|
-
const bitrate = imsiForBitrate ? await
|
|
4116
|
+
const bitrate = imsiForBitrate ? await safeCall2(ctx.env, token2, "hlrGetBitrate", { imsi: imsiForBitrate }) : { data: null, error: null };
|
|
4002
4117
|
if (bitrate.data) {
|
|
4003
4118
|
const rate = Number(bitrate.data.bitrate ?? bitrate.data.maxBitrate ?? 0);
|
|
4004
4119
|
if (rate > 0 && rate < 1e6) {
|
|
@@ -4028,26 +4143,26 @@ function registerIntelligenceTools(server2, ctx) {
|
|
|
4028
4143
|
`- Balance: ${balance}`,
|
|
4029
4144
|
`- Active Packages: ${pkgs.error ? "unknown" : activePkgs.length}`
|
|
4030
4145
|
].join("\n");
|
|
4031
|
-
return
|
|
4146
|
+
return result2(report);
|
|
4032
4147
|
});
|
|
4033
4148
|
server2.registerTool("fleet_health", {
|
|
4034
4149
|
title: "Fleet Health Dashboard",
|
|
4035
4150
|
description: "Aggregates eSIM status counts, low-balance accounts, and provides a fleet-wide health summary in a single call. Identifies accounts that need attention.",
|
|
4036
4151
|
inputSchema: {
|
|
4037
|
-
accountId:
|
|
4152
|
+
accountId: z3.number().optional().describe("Filter to a specific account (omit for all)")
|
|
4038
4153
|
},
|
|
4039
4154
|
annotations: { readOnlyHint: true }
|
|
4040
4155
|
}, async ({ accountId }) => {
|
|
4041
4156
|
const token2 = await ctx.getUserToken(ctx.props.sub);
|
|
4042
4157
|
const resellerId = await getDefaultResellerId(ctx.env, token2).catch(() => void 0);
|
|
4043
4158
|
const [statusResult, accountsResult, resellerInfoResult] = await Promise.all([
|
|
4044
|
-
|
|
4159
|
+
safeCall2(
|
|
4045
4160
|
ctx.env,
|
|
4046
4161
|
token2,
|
|
4047
4162
|
"esimStatusPerAccount",
|
|
4048
4163
|
accountId !== void 0 ? { accountId } : resellerId !== void 0 ? { resellerId } : {}
|
|
4049
4164
|
),
|
|
4050
|
-
|
|
4165
|
+
safeCall2(
|
|
4051
4166
|
ctx.env,
|
|
4052
4167
|
token2,
|
|
4053
4168
|
"listResellerAccount",
|
|
@@ -4057,7 +4172,7 @@ function registerIntelligenceTools(server2, ctx) {
|
|
|
4057
4172
|
// parent is out of credit, and that is the one state which silently
|
|
4058
4173
|
// zeroes every rating group (2026-08-28: reseller 1170 at 0.00 while
|
|
4059
4174
|
// fleet_health reported "require no action").
|
|
4060
|
-
resellerId !== void 0 ?
|
|
4175
|
+
resellerId !== void 0 ? safeCall2(
|
|
4061
4176
|
ctx.env,
|
|
4062
4177
|
token2,
|
|
4063
4178
|
"getResellerInfo",
|
|
@@ -4172,15 +4287,15 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4172
4287
|
## Errors`);
|
|
4173
4288
|
if (statusResult.error) sections.push(`- esimStatusPerAccount: ${statusResult.error}`);
|
|
4174
4289
|
if (accountsResult.error) sections.push(`- listResellerAccount: ${accountsResult.error}`);
|
|
4175
|
-
return
|
|
4290
|
+
return result2(sections.join("\n"), true);
|
|
4176
4291
|
}
|
|
4177
|
-
return
|
|
4292
|
+
return result2(sections.join("\n"));
|
|
4178
4293
|
});
|
|
4179
4294
|
server2.registerTool("detect_usage_anomalies", {
|
|
4180
4295
|
title: "Detect Usage Anomalies",
|
|
4181
4296
|
description: "Analyzes a subscriber's recent usage patterns over the last 7 days to detect anomalies: sudden spikes, unusual off-hours activity, or consumption rates that would exhaust the package before expiry.",
|
|
4182
4297
|
inputSchema: {
|
|
4183
|
-
iccid:
|
|
4298
|
+
iccid: z3.string().describe("The subscriber ICCID to analyze")
|
|
4184
4299
|
},
|
|
4185
4300
|
annotations: { readOnlyHint: true }
|
|
4186
4301
|
}, async ({ iccid }) => {
|
|
@@ -4188,13 +4303,13 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4188
4303
|
const now = /* @__PURE__ */ new Date();
|
|
4189
4304
|
const usagePeriod = lastNDaysPeriod(OCS_MAX_USAGE_WINDOW_DAYS, now);
|
|
4190
4305
|
const [usageResult, pkgResult] = await Promise.all([
|
|
4191
|
-
|
|
4306
|
+
safeCall2(ctx.env, token2, "subscriberUsageOverPeriod", {
|
|
4192
4307
|
subscriber: { iccid },
|
|
4193
4308
|
period: usagePeriod
|
|
4194
4309
|
}),
|
|
4195
|
-
|
|
4310
|
+
safeCall2(ctx.env, token2, "listSubscriberPrepaidPackages", { iccid })
|
|
4196
4311
|
]);
|
|
4197
|
-
if (usageResult.error) return
|
|
4312
|
+
if (usageResult.error) return result2(`Failed to fetch usage: ${usageResult.error}`, true);
|
|
4198
4313
|
const sections = [`# Usage Anomaly Report: ${iccid}
|
|
4199
4314
|
`];
|
|
4200
4315
|
const anomalies = [];
|
|
@@ -4255,13 +4370,13 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4255
4370
|
sections.push(`
|
|
4256
4371
|
## No anomalies detected \u2014 usage appears normal.`);
|
|
4257
4372
|
}
|
|
4258
|
-
return
|
|
4373
|
+
return result2(sections.join("\n"));
|
|
4259
4374
|
});
|
|
4260
4375
|
server2.registerTool("optimize_package", {
|
|
4261
4376
|
title: "Package Optimization Advisor",
|
|
4262
4377
|
description: "Compares a subscriber's actual usage against their current package and all available templates. Recommends better-fit packages to reduce waste or prevent overages. Calculates potential savings.",
|
|
4263
4378
|
inputSchema: {
|
|
4264
|
-
iccid:
|
|
4379
|
+
iccid: z3.string().describe("The subscriber ICCID to optimize")
|
|
4265
4380
|
},
|
|
4266
4381
|
annotations: { readOnlyHint: true }
|
|
4267
4382
|
}, async ({ iccid }) => {
|
|
@@ -4269,12 +4384,12 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4269
4384
|
const now = /* @__PURE__ */ new Date();
|
|
4270
4385
|
const usagePeriod = lastNDaysPeriod(OCS_MAX_USAGE_WINDOW_DAYS, now);
|
|
4271
4386
|
const [usageResult, pkgResult, templatesResult] = await Promise.all([
|
|
4272
|
-
|
|
4387
|
+
safeCall2(ctx.env, token2, "subscriberUsageOverPeriod", {
|
|
4273
4388
|
subscriber: { iccid },
|
|
4274
4389
|
period: usagePeriod
|
|
4275
4390
|
}),
|
|
4276
|
-
|
|
4277
|
-
|
|
4391
|
+
safeCall2(ctx.env, token2, "listSubscriberPrepaidPackages", { iccid }),
|
|
4392
|
+
safeCall2(ctx.env, token2, "listPrepaidPackageTemplate", {})
|
|
4278
4393
|
]);
|
|
4279
4394
|
const sections = [`# Package Optimization: ${iccid}
|
|
4280
4395
|
`];
|
|
@@ -4340,13 +4455,13 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4340
4455
|
sections.push(`
|
|
4341
4456
|
*No usage data available \u2014 cannot recommend packages without usage history.*`);
|
|
4342
4457
|
}
|
|
4343
|
-
return
|
|
4458
|
+
return result2(sections.join("\n"));
|
|
4344
4459
|
});
|
|
4345
4460
|
server2.registerTool("churn_risk", {
|
|
4346
4461
|
title: "Churn Risk Assessment",
|
|
4347
4462
|
description: "Analyzes a subscriber's usage trends, package status, balance, and activity to produce a churn risk score (0-100) with contributing factors and retention recommendations.",
|
|
4348
4463
|
inputSchema: {
|
|
4349
|
-
iccid:
|
|
4464
|
+
iccid: z3.string().describe("The subscriber ICCID to assess")
|
|
4350
4465
|
},
|
|
4351
4466
|
annotations: { readOnlyHint: true }
|
|
4352
4467
|
}, async ({ iccid }) => {
|
|
@@ -4354,13 +4469,13 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4354
4469
|
const now = /* @__PURE__ */ new Date();
|
|
4355
4470
|
const usagePeriod = lastNDaysPeriod(OCS_MAX_USAGE_WINDOW_DAYS, now);
|
|
4356
4471
|
const [subResult, usageResult, pkgResult, activeResult] = await Promise.all([
|
|
4357
|
-
|
|
4358
|
-
|
|
4472
|
+
safeCall2(ctx.env, token2, "getSingleSubscriber", { iccid }),
|
|
4473
|
+
safeCall2(ctx.env, token2, "subscriberUsageOverPeriod", {
|
|
4359
4474
|
subscriber: { iccid },
|
|
4360
4475
|
period: usagePeriod
|
|
4361
4476
|
}),
|
|
4362
|
-
|
|
4363
|
-
|
|
4477
|
+
safeCall2(ctx.env, token2, "listSubscriberPrepaidPackages", { iccid }),
|
|
4478
|
+
safeCall2(ctx.env, token2, "getSubscriberActivePeriod", { iccid })
|
|
4364
4479
|
]);
|
|
4365
4480
|
let riskScore = 0;
|
|
4366
4481
|
const factors = [];
|
|
@@ -4462,14 +4577,14 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4462
4577
|
sections.push("1. No immediate action required");
|
|
4463
4578
|
sections.push("2. Continue monitoring via regular fleet_health checks");
|
|
4464
4579
|
}
|
|
4465
|
-
return
|
|
4580
|
+
return result2(sections.join("\n"));
|
|
4466
4581
|
});
|
|
4467
4582
|
server2.registerTool("audit_network_coverage", {
|
|
4468
4583
|
title: "Network Coverage Audit",
|
|
4469
4584
|
description: "Analyzes which networks your subscribers are actually connecting to in a given country or across all countries. Compares against your steering lists to identify mismatches \u2014 subscribers roaming on expensive or non-preferred networks. Use this to answer: 'Am I using the right networks in country X?'",
|
|
4470
4585
|
inputSchema: {
|
|
4471
|
-
accountId:
|
|
4472
|
-
limit:
|
|
4586
|
+
accountId: z3.number().optional().describe("Filter to a specific account"),
|
|
4587
|
+
limit: z3.number().optional().describe("Max subscribers to sample (default 50)")
|
|
4473
4588
|
},
|
|
4474
4589
|
annotations: { readOnlyHint: true }
|
|
4475
4590
|
}, async ({ accountId, limit: sampleLimit }) => {
|
|
@@ -4478,9 +4593,9 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4478
4593
|
const resellerId = await getDefaultResellerId(ctx.env, token2);
|
|
4479
4594
|
const [subsResult, steeringResult] = await Promise.all([
|
|
4480
4595
|
fetchActiveSubscribers(ctx.env, token2, accountId, resellerId),
|
|
4481
|
-
|
|
4596
|
+
safeCall2(ctx.env, token2, "listSteeringList", resellerId)
|
|
4482
4597
|
]);
|
|
4483
|
-
if (subsResult.error) return
|
|
4598
|
+
if (subsResult.error) return result2(`Failed to fetch subscribers: ${subsResult.error}`, true);
|
|
4484
4599
|
const sections = [`# Network Coverage Audit
|
|
4485
4600
|
`];
|
|
4486
4601
|
const steeringMap = /* @__PURE__ */ new Map();
|
|
@@ -4500,7 +4615,7 @@ Package-only accounts at 0 balance require no action.`);
|
|
|
4500
4615
|
const batch = subs.slice(i, i + batchSize);
|
|
4501
4616
|
const locations = await Promise.all(
|
|
4502
4617
|
batch.map(
|
|
4503
|
-
(s) =>
|
|
4618
|
+
(s) => safeCall2(ctx.env, token2, "getSubscriberLocation", {
|
|
4504
4619
|
iccid: String(s.iccid ?? "")
|
|
4505
4620
|
})
|
|
4506
4621
|
)
|
|
@@ -4542,129 +4657,16 @@ ${networksSorted.length} different networks in ${country} \u2014 possible steeri
|
|
|
4542
4657
|
} else {
|
|
4543
4658
|
sections.push("No location data available for sampled subscribers.");
|
|
4544
4659
|
}
|
|
4545
|
-
return
|
|
4546
|
-
});
|
|
4547
|
-
server2.registerTool("marketing_intelligence", {
|
|
4548
|
-
title: "Marketing Intelligence Report",
|
|
4549
|
-
description: "Analyzes your subscriber base to identify high-growth markets, underserved regions, and revenue concentration. Answers: 'Which countries should I target with marketing?' and 'Where are my most valuable subscribers?'",
|
|
4550
|
-
inputSchema: {
|
|
4551
|
-
accountId: z2.number().optional().describe("Filter to a specific account")
|
|
4552
|
-
},
|
|
4553
|
-
annotations: { readOnlyHint: true }
|
|
4554
|
-
}, async ({ accountId }) => {
|
|
4555
|
-
const token2 = await ctx.getUserToken(ctx.props.sub);
|
|
4556
|
-
const params = {};
|
|
4557
|
-
if (accountId !== void 0) params.accountId = accountId;
|
|
4558
|
-
const [subsResult, templatesResult, resellerId] = await Promise.all([
|
|
4559
|
-
safeCall(ctx.env, token2, "listSubscriber", params),
|
|
4560
|
-
safeCall(ctx.env, token2, "listPrepaidPackageTemplate", {}),
|
|
4561
|
-
getDefaultResellerId(ctx.env, token2)
|
|
4562
|
-
]);
|
|
4563
|
-
const zonesResult = await safeCall(
|
|
4564
|
-
ctx.env,
|
|
4565
|
-
token2,
|
|
4566
|
-
"listDetailedLocationZone",
|
|
4567
|
-
resellerId
|
|
4568
|
-
);
|
|
4569
|
-
const sections = [`# Marketing Intelligence Report
|
|
4570
|
-
`];
|
|
4571
|
-
if (subsResult.data && Array.isArray(subsResult.data)) {
|
|
4572
|
-
const total = subsResult.data.length;
|
|
4573
|
-
sections.push(`## Fleet Size: ${total} subscribers sampled
|
|
4574
|
-
`);
|
|
4575
|
-
const sample = subsResult.data.slice(0, 100);
|
|
4576
|
-
const countryData = /* @__PURE__ */ new Map();
|
|
4577
|
-
const batchSize = 10;
|
|
4578
|
-
for (let i = 0; i < sample.length; i += batchSize) {
|
|
4579
|
-
const batch = sample.slice(i, i + batchSize);
|
|
4580
|
-
const locations = await Promise.all(
|
|
4581
|
-
batch.map(
|
|
4582
|
-
(s) => safeCall(ctx.env, token2, "getSubscriberLocation", {
|
|
4583
|
-
iccid: String(s.iccid ?? "")
|
|
4584
|
-
})
|
|
4585
|
-
)
|
|
4586
|
-
);
|
|
4587
|
-
for (let j = 0; j < batch.length; j++) {
|
|
4588
|
-
const loc = locations[j];
|
|
4589
|
-
const sub = batch[j];
|
|
4590
|
-
const country = loc.data ? String(loc.data.country ?? loc.data.countryCode ?? "Unknown") : "Unknown";
|
|
4591
|
-
if (!countryData.has(country)) {
|
|
4592
|
-
countryData.set(country, { subscribers: 0, activePackages: 0, totalBalance: 0 });
|
|
4593
|
-
}
|
|
4594
|
-
const cd = countryData.get(country);
|
|
4595
|
-
cd.subscribers++;
|
|
4596
|
-
cd.totalBalance += Number(sub.balance ?? 0);
|
|
4597
|
-
}
|
|
4598
|
-
}
|
|
4599
|
-
if (countryData.size > 0) {
|
|
4600
|
-
const sorted = [...countryData.entries()].sort((a, b) => b[1].subscribers - a[1].subscribers);
|
|
4601
|
-
sections.push(`## Subscriber Concentration by Country`);
|
|
4602
|
-
sections.push(`| Country | Subscribers | % of Fleet | Avg Balance |`);
|
|
4603
|
-
sections.push(`|---------|-----------|------------|-------------|`);
|
|
4604
|
-
for (const [country, data] of sorted) {
|
|
4605
|
-
const pct = (data.subscribers / sample.length * 100).toFixed(1);
|
|
4606
|
-
const avgBal = (data.totalBalance / data.subscribers).toFixed(2);
|
|
4607
|
-
sections.push(`| ${country} | ${data.subscribers} | ${pct}% | ${avgBal} |`);
|
|
4608
|
-
}
|
|
4609
|
-
sections.push(`
|
|
4610
|
-
## Market Insights`);
|
|
4611
|
-
const topMarket = sorted[0];
|
|
4612
|
-
if (topMarket) {
|
|
4613
|
-
sections.push(`- **Strongest market**: ${topMarket[0]} (${topMarket[1].subscribers} subscribers)`);
|
|
4614
|
-
if (topMarket[1].subscribers / sample.length > 0.5) {
|
|
4615
|
-
sections.push(` Revenue concentration risk \u2014 >50% of fleet in one market`);
|
|
4616
|
-
}
|
|
4617
|
-
}
|
|
4618
|
-
const highValue = sorted.filter(([, d]) => d.subscribers >= 3).sort((a, b) => b[1].totalBalance / b[1].subscribers - a[1].totalBalance / a[1].subscribers).slice(0, 3);
|
|
4619
|
-
if (highValue.length > 0) {
|
|
4620
|
-
sections.push(`
|
|
4621
|
-
### High-Value Markets (by avg balance)`);
|
|
4622
|
-
for (const [country, data] of highValue) {
|
|
4623
|
-
sections.push(`- **${country}**: avg balance ${(data.totalBalance / data.subscribers).toFixed(2)} (${data.subscribers} subs)`);
|
|
4624
|
-
}
|
|
4625
|
-
}
|
|
4626
|
-
const emerging = sorted.filter(([, d]) => d.subscribers >= 1 && d.subscribers <= 3);
|
|
4627
|
-
if (emerging.length > 0) {
|
|
4628
|
-
sections.push(`
|
|
4629
|
-
### Emerging Markets (early traction, 1-3 subscribers)`);
|
|
4630
|
-
sections.push(`These markets show initial demand \u2014 consider targeted campaigns:`);
|
|
4631
|
-
for (const [country, data] of emerging) {
|
|
4632
|
-
sections.push(`- ${country}: ${data.subscribers} subscriber(s)`);
|
|
4633
|
-
}
|
|
4634
|
-
}
|
|
4635
|
-
}
|
|
4636
|
-
}
|
|
4637
|
-
if (zonesResult.data && Array.isArray(zonesResult.data)) {
|
|
4638
|
-
sections.push(`
|
|
4639
|
-
## Coverage Catalog`);
|
|
4640
|
-
sections.push(`- Location zones available: ${zonesResult.data.length}`);
|
|
4641
|
-
}
|
|
4642
|
-
if (templatesResult.data && Array.isArray(templatesResult.data)) {
|
|
4643
|
-
sections.push(`- Package templates available: ${templatesResult.data.length}`);
|
|
4644
|
-
const prices = templatesResult.data.map((t) => Number(t.price ?? t.cost ?? 0)).filter((p) => p > 0);
|
|
4645
|
-
if (prices.length > 0) {
|
|
4646
|
-
const avgPrice = prices.reduce((a, b) => a + b, 0) / prices.length;
|
|
4647
|
-
const minPrice = Math.min(...prices);
|
|
4648
|
-
const maxPrice = Math.max(...prices);
|
|
4649
|
-
sections.push(`
|
|
4650
|
-
### Pricing Range`);
|
|
4651
|
-
sections.push(`- Min: ${minPrice.toFixed(2)} | Avg: ${avgPrice.toFixed(2)} | Max: ${maxPrice.toFixed(2)}`);
|
|
4652
|
-
}
|
|
4653
|
-
}
|
|
4654
|
-
sections.push(`
|
|
4655
|
-
## Recommended Actions`);
|
|
4656
|
-
sections.push(`1. Run \`audit_network_coverage\` to verify network quality in top markets`);
|
|
4657
|
-
sections.push(`2. Run \`high_cost_subscribers\` to identify margin pressure`);
|
|
4658
|
-
sections.push(`3. Consider creating regional package templates for emerging markets`);
|
|
4659
|
-
return result(sections.join("\n"));
|
|
4660
|
+
return result2(sections.join("\n"));
|
|
4660
4661
|
});
|
|
4662
|
+
registerMarketingIntelligenceTool(server2, ctx);
|
|
4661
4663
|
server2.registerTool("high_cost_subscribers", {
|
|
4662
4664
|
title: "High Cost Subscriber Report",
|
|
4663
4665
|
description: "Identifies subscribers with disproportionately high data consumption relative to their package value. Finds subscribers burning through data at rates that erode margins. Answers: 'Which subscribers are costing me money?'",
|
|
4664
4666
|
inputSchema: {
|
|
4665
|
-
accountId:
|
|
4666
|
-
limit:
|
|
4667
|
-
thresholdPct:
|
|
4667
|
+
accountId: z3.number().optional().describe("Filter to a specific account"),
|
|
4668
|
+
limit: z3.number().optional().describe("Max subscribers to analyze (default 100)"),
|
|
4669
|
+
thresholdPct: z3.number().optional().describe("Usage % threshold to flag (default 80)")
|
|
4668
4670
|
},
|
|
4669
4671
|
annotations: { readOnlyHint: true }
|
|
4670
4672
|
}, async ({ accountId, limit: maxLimit, thresholdPct }) => {
|
|
@@ -4673,8 +4675,8 @@ ${networksSorted.length} different networks in ${country} \u2014 possible steeri
|
|
|
4673
4675
|
const threshold = thresholdPct ?? 80;
|
|
4674
4676
|
const resellerId = await getDefaultResellerId(ctx.env, token2);
|
|
4675
4677
|
const subsResult = await fetchActiveSubscribers(ctx.env, token2, accountId, resellerId);
|
|
4676
|
-
if (subsResult.error) return
|
|
4677
|
-
if (!subsResult.data || subsResult.data.length === 0) return
|
|
4678
|
+
if (subsResult.error) return result2(`Failed to fetch subscribers: ${subsResult.error}`, true);
|
|
4679
|
+
if (!subsResult.data || subsResult.data.length === 0) return result2("No subscribers found", true);
|
|
4678
4680
|
const sections = [`# High Cost Subscriber Report
|
|
4679
4681
|
`];
|
|
4680
4682
|
const now = /* @__PURE__ */ new Date();
|
|
@@ -4688,12 +4690,12 @@ ${networksSorted.length} different networks in ${country} \u2014 possible steeri
|
|
|
4688
4690
|
batch.map(async (sub) => {
|
|
4689
4691
|
const iccid = String(sub.iccid ?? "");
|
|
4690
4692
|
const [usage, pkgs, loc] = await Promise.all([
|
|
4691
|
-
|
|
4693
|
+
safeCall2(ctx.env, token2, "subscriberUsageOverPeriod", {
|
|
4692
4694
|
subscriber: { iccid },
|
|
4693
4695
|
period: usagePeriod
|
|
4694
4696
|
}),
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
+
safeCall2(ctx.env, token2, "listSubscriberPrepaidPackages", { iccid }),
|
|
4698
|
+
safeCall2(ctx.env, token2, "getSubscriberLocation", { iccid })
|
|
4697
4699
|
]);
|
|
4698
4700
|
const dailyRows = extractDailyUsage(usage.data);
|
|
4699
4701
|
const dailyAvgBytes = dailyRows.length > 0 ? dailyRows.reduce((sum, r) => sum + r.bytes, 0) / dailyRows.length : 0;
|
|
@@ -4767,39 +4769,39 @@ ${networksSorted.length} different networks in ${country} \u2014 possible steeri
|
|
|
4767
4769
|
sections.push(`3. Run \`optimize_package\` on flagged ICCIDs to find better-fit plans`);
|
|
4768
4770
|
sections.push(`4. Negotiate better wholesale rates for high-volume countries`);
|
|
4769
4771
|
}
|
|
4770
|
-
return
|
|
4772
|
+
return result2(sections.join("\n"));
|
|
4771
4773
|
});
|
|
4772
4774
|
server2.registerTool("detect_country_entry", {
|
|
4773
4775
|
title: "Detect Country Entry",
|
|
4774
4776
|
description: "Detects when a subscriber has entered a new country by reading networkInfo.lastMcc from getSingleSubscriber (one cheap OCS call \u2014 avoids the per-call cost of getSubscriberLocationByCellId). Resolves MCC \u2192 ISO 3166-1 alpha-2 and optionally diffs against a caller-supplied expectedCountry to return countryChanged. Designed for downstream country-entry upsell workflows (e.g. mango.talk SMS/push offers). NOT AN AI TOOL: this is a deterministic MCC lookup and returns no model-written analysis, unlike the eight intelligence composites. COST NOTE: This tool makes exactly one OCS call per invocation. Consumers running polling crons MUST enforce their own rate floor \u2014 this layer provides no throttle.",
|
|
4775
4777
|
inputSchema: {
|
|
4776
|
-
subscriber:
|
|
4777
|
-
|
|
4778
|
-
|
|
4779
|
-
|
|
4780
|
-
|
|
4781
|
-
|
|
4782
|
-
|
|
4778
|
+
subscriber: z3.union([
|
|
4779
|
+
z3.object({ subscriberId: z3.number() }).describe("Internal subscriber ID"),
|
|
4780
|
+
z3.object({ imsi: z3.string() }).describe("IMSI"),
|
|
4781
|
+
z3.object({ iccid: z3.string() }).describe("ICCID"),
|
|
4782
|
+
z3.object({ msisdn: z3.string() }).describe("MSISDN / phone number"),
|
|
4783
|
+
z3.object({ multiImsi: z3.string() }).describe("Multi-IMSI identifier"),
|
|
4784
|
+
z3.object({ activationCode: z3.string() }).describe("eSIM activation code")
|
|
4783
4785
|
]).describe("Subscriber identifier (use exactly one field)"),
|
|
4784
|
-
expectedCountry:
|
|
4786
|
+
expectedCountry: z3.string().length(2).transform((code) => code.toUpperCase()).optional().describe(
|
|
4785
4787
|
'Caller\u2019s last-known ISO 3166-1 alpha-2 country for this subscriber (e.g. "RU"). When provided, countryChanged is included in the response.'
|
|
4786
4788
|
)
|
|
4787
4789
|
},
|
|
4788
4790
|
annotations: { readOnlyHint: true }
|
|
4789
4791
|
}, async ({ subscriber, expectedCountry }) => {
|
|
4790
4792
|
const token2 = await ctx.getUserToken(ctx.props.sub);
|
|
4791
|
-
const sub = await
|
|
4793
|
+
const sub = await safeCall2(
|
|
4792
4794
|
ctx.env,
|
|
4793
4795
|
token2,
|
|
4794
4796
|
"getSingleSubscriber",
|
|
4795
4797
|
subscriber
|
|
4796
4798
|
);
|
|
4797
|
-
if (sub.error) return
|
|
4798
|
-
if (!sub.data) return
|
|
4799
|
+
if (sub.error) return result2(`Failed to fetch subscriber: ${sub.error}`, true);
|
|
4800
|
+
if (!sub.data) return result2("Subscriber not found", true);
|
|
4799
4801
|
const subscriberId = sub.data.subscriberId ?? sub.data.id ?? ("subscriberId" in subscriber ? subscriber.subscriberId : void 0);
|
|
4800
4802
|
const networkInfo = sub.data.networkInfo;
|
|
4801
4803
|
if (networkInfo === null || networkInfo === void 0 || typeof networkInfo !== "object") {
|
|
4802
|
-
return
|
|
4804
|
+
return result2(
|
|
4803
4805
|
JSON.stringify({ status: "no_location_data", subscriberId: subscriberId ?? null })
|
|
4804
4806
|
);
|
|
4805
4807
|
}
|
|
@@ -4807,7 +4809,7 @@ ${networksSorted.length} different networks in ${country} \u2014 possible steeri
|
|
|
4807
4809
|
const lastMnc = networkInfo.lastMnc != null ? Number(networkInfo.lastMnc) : null;
|
|
4808
4810
|
const lastSeenAtUtc = networkInfo.time != null ? String(networkInfo.time) : null;
|
|
4809
4811
|
if (lastMcc === null || isNaN(lastMcc)) {
|
|
4810
|
-
return
|
|
4812
|
+
return result2(
|
|
4811
4813
|
JSON.stringify({ status: "no_location_data", subscriberId: subscriberId ?? null })
|
|
4812
4814
|
);
|
|
4813
4815
|
}
|
|
@@ -4825,14 +4827,14 @@ ${networksSorted.length} different networks in ${country} \u2014 possible steeri
|
|
|
4825
4827
|
response.expectedCountry = expectedCountry;
|
|
4826
4828
|
response.countryChanged = currentCountry !== null ? currentCountry !== expectedCountry : null;
|
|
4827
4829
|
}
|
|
4828
|
-
return
|
|
4830
|
+
return result2(JSON.stringify(response, null, 2));
|
|
4829
4831
|
});
|
|
4830
4832
|
}
|
|
4831
4833
|
|
|
4832
4834
|
// src/tools-backlog.ts
|
|
4833
|
-
import { z as
|
|
4835
|
+
import { z as z4 } from "zod";
|
|
4834
4836
|
var DRY_RUN_FIELD2 = {
|
|
4835
|
-
dry_run:
|
|
4837
|
+
dry_run: z4.boolean().optional().describe(
|
|
4836
4838
|
"If true, do not call OCS \u2014 return the would-be request for confirmation"
|
|
4837
4839
|
)
|
|
4838
4840
|
};
|
|
@@ -4862,9 +4864,9 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4862
4864
|
title: "Assign Phone Number to Subscriber",
|
|
4863
4865
|
description: "Use this to assign a phone number (MSISDN) to a subscriber. Supports both fake/test MSISDNs and real production MSISDNs via the `phone_type` parameter. Required for MSISDN assignment workflows before activating voice services. Params: `iccid` (subscriber identifier), `phone_number` (E.164 format, e.g. +31612345678), `phone_type` ('fake' for test/dev, 'real' for production). Returns: updated subscriber record with the new MSISDN. Do NOT use this to check a subscriber's current MSISDN \u2014 use `get_subscriber` instead.",
|
|
4864
4866
|
inputSchema: {
|
|
4865
|
-
iccid:
|
|
4866
|
-
phone_number:
|
|
4867
|
-
phone_type:
|
|
4867
|
+
iccid: z4.string().describe("The subscriber ICCID (20-digit ICC identifier)"),
|
|
4868
|
+
phone_number: z4.string().describe("E.164 phone number to assign (e.g. +31612345678)"),
|
|
4869
|
+
phone_type: z4.enum(["fake", "real"]).describe(
|
|
4868
4870
|
"'fake' assigns a test/dev MSISDN (affectSubscriberFakePhoneNumber in OCS); 'real' assigns a production MSISDN (affectSubscriberRealPhoneNumber in OCS)"
|
|
4869
4871
|
),
|
|
4870
4872
|
...DRY_RUN_FIELD2
|
|
@@ -4879,9 +4881,9 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4879
4881
|
async ({ iccid, phone_number, phone_type }, token2) => {
|
|
4880
4882
|
const ocsMethod = phone_type === "fake" ? "affectSubscriberFakePhoneNumber" : "affectSubscriberRealPhoneNumber";
|
|
4881
4883
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
4882
|
-
const
|
|
4884
|
+
const result3 = await client2.call(ocsMethod, { subscriber: iccid, phoneNumber: phone_number });
|
|
4883
4885
|
return {
|
|
4884
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
4886
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
4885
4887
|
};
|
|
4886
4888
|
}
|
|
4887
4889
|
)
|
|
@@ -4892,14 +4894,14 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4892
4894
|
title: "Get Location by Cell ID (GeoSense)",
|
|
4893
4895
|
description: "Powered by Bridge4IP GeoSense \u2014 cell-level location resolution with sub-cell accuracy where available. Use this to resolve a cell tower tuple (radio type + MCC + MNC + LAC + optional cellId) to a latitude/longitude estimate. No subscriber identifier required \u2014 caller supplies cell parameters directly. Useful for fraud detection, roaming cost attribution, and network troubleshooting when you have raw cell info from an external source (e.g. a Relay LU webhook event). Params: `radio_type` ('2G'|'3G'|'4G'|'5G'|'NB-IoT'; also accepts 'NBIOT'|'nb-iot'|'nbiot' \u2014 normalised to 'NB-IoT'), `mcc` (int), `mnc` (int), `lac` (int), `cell_id` (int, optional but strongly recommended for accuracy), `signal_strength` (number dBm, optional). Returns: { latitude, longitude, accuracy } \u2014 accuracy is median error in meters at 50% confidence. Without cell_id accuracy degrades significantly (>10 km). Do NOT use this for bulk fleet location sweeps \u2014 one OCS call per cell tower; use `audit_network_coverage` for fleet-level analysis instead.",
|
|
4894
4896
|
inputSchema: {
|
|
4895
|
-
radio_type:
|
|
4897
|
+
radio_type: z4.string().transform(normalizeRadioType).refine((v) => VALID_RADIO_TYPES.has(v), {
|
|
4896
4898
|
message: "radio_type must be one of: 2G, 3G, 4G, 5G, NB-IoT (also accepts NBIOT, nb-iot, nbiot)"
|
|
4897
4899
|
}).describe("Radio access technology type: '2G'|'3G'|'4G'|'5G'|'NB-IoT'. Also accepts 'NBIOT'|'nb-iot'|'nbiot' \u2014 normalised to 'NB-IoT'."),
|
|
4898
|
-
mcc:
|
|
4899
|
-
mnc:
|
|
4900
|
-
lac:
|
|
4901
|
-
cell_id:
|
|
4902
|
-
signal_strength:
|
|
4900
|
+
mcc: z4.number().int().describe("Mobile Country Code (e.g. 250 for Russia, 234 for UK)"),
|
|
4901
|
+
mnc: z4.number().int().describe("Mobile Network Code"),
|
|
4902
|
+
lac: z4.number().int().describe("Location Area Code"),
|
|
4903
|
+
cell_id: z4.number().int().optional().describe("Cell tower ID \u2014 strongly recommended for accuracy"),
|
|
4904
|
+
signal_strength: z4.number().optional().describe("Signal strength in dBm (e.g. -89). Optional, improves accuracy.")
|
|
4903
4905
|
},
|
|
4904
4906
|
annotations: { readOnlyHint: true }
|
|
4905
4907
|
},
|
|
@@ -4920,9 +4922,9 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4920
4922
|
const params = { radioType: radio_type, mcc, mnc, lac };
|
|
4921
4923
|
if (cell_id !== void 0) params.cellId = cell_id;
|
|
4922
4924
|
if (signal_strength !== void 0) params.signalStrength = signal_strength;
|
|
4923
|
-
const
|
|
4925
|
+
const result3 = await client2.call("getSubscriberLocationByCellId", params);
|
|
4924
4926
|
return {
|
|
4925
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
4927
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
4926
4928
|
};
|
|
4927
4929
|
}
|
|
4928
4930
|
)
|
|
@@ -4933,7 +4935,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4933
4935
|
title: "List Destination Lists",
|
|
4934
4936
|
description: "Use this to retrieve the full catalog of destination lists available to this reseller. A destination list is a named set of phone number prefixes (country codes) that control which numbers a subscriber may call on a voice/SMS package. Returns: array of destination list records, each with `id`, `name`, and prefix count. Do NOT use this to read the prefixes inside a specific list \u2014 use `list_destination_prefixes` with a known `destinationListId` for that. Do NOT use this for data-only eSIM products without MOC voice; destination lists only apply to packages with voice/SMS allowances.",
|
|
4935
4937
|
inputSchema: {
|
|
4936
|
-
resellerId:
|
|
4938
|
+
resellerId: z4.number().optional().describe("Reseller ID (omit to use the token owner's reseller)")
|
|
4937
4939
|
},
|
|
4938
4940
|
annotations: { readOnlyHint: true }
|
|
4939
4941
|
},
|
|
@@ -4953,9 +4955,9 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4953
4955
|
return resolvedId;
|
|
4954
4956
|
})();
|
|
4955
4957
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
4956
|
-
const
|
|
4958
|
+
const result3 = await client2.call("listDetailedDestinationList", id);
|
|
4957
4959
|
return {
|
|
4958
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
4960
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
4959
4961
|
};
|
|
4960
4962
|
}
|
|
4961
4963
|
)
|
|
@@ -4966,8 +4968,8 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4966
4968
|
title: "Modify Subscriber Mobile Plan",
|
|
4967
4969
|
description: "Use this to change the mobile pricing plan assigned to a specific subscriber. The mobile plan determines per-country rates for data, voice, and SMS. Changing the plan takes effect immediately on the next OCS rating cycle. Params: `iccid` (subscriber identifier), `mobile_plan_id` (integer plan ID \u2014 obtain valid plan IDs from the OCS reseller settings or `get_tariff`). Returns: updated subscriber record confirming the new plan assignment. Do NOT use this to change package allowances \u2014 use `modify_package_limits` for that. Do NOT use this to change account-level pricing \u2014 this only affects the individual subscriber.",
|
|
4968
4970
|
inputSchema: {
|
|
4969
|
-
iccid:
|
|
4970
|
-
mobile_plan_id:
|
|
4971
|
+
iccid: z4.string().describe("The subscriber ICCID (20-digit ICC identifier)"),
|
|
4972
|
+
mobile_plan_id: z4.number().describe("The mobile pricing plan ID to assign to this subscriber"),
|
|
4971
4973
|
...DRY_RUN_FIELD2
|
|
4972
4974
|
},
|
|
4973
4975
|
annotations: { destructiveHint: true }
|
|
@@ -4979,12 +4981,12 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4979
4981
|
ctx,
|
|
4980
4982
|
async ({ iccid, mobile_plan_id }, token2) => {
|
|
4981
4983
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
4982
|
-
const
|
|
4984
|
+
const result3 = await client2.call(
|
|
4983
4985
|
"modifySubscriberMobilePlan",
|
|
4984
4986
|
{ subscriberId: { iccid }, mobilePlanId: mobile_plan_id }
|
|
4985
4987
|
);
|
|
4986
4988
|
return {
|
|
4987
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
4989
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
4988
4990
|
};
|
|
4989
4991
|
}
|
|
4990
4992
|
)
|
|
@@ -4995,11 +4997,11 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
4995
4997
|
title: "Modify Subscriber Package Active Period",
|
|
4996
4998
|
description: "Use this to change the start and/or end date of a prepaid package's active period for a specific subscriber. This controls WHEN the package runs, not what it contains. Useful for scheduling packages in advance (e.g. activate on arrival date) or extending a package that would otherwise expire while the subscriber is still travelling. Params: `iccid` (subscriber identifier), `package_id` (from `list_subscriber_packages`), `start_date` (ISO 8601 date, optional), `end_date` (ISO 8601 date, optional). Returns: updated package record with new active period. Do NOT use this to change a package's data/voice allowance \u2014 use `modify_package_limits`. Do NOT use this to change the expiry date of a package \u2014 use `modify_package_expiry`.",
|
|
4997
4999
|
inputSchema: {
|
|
4998
|
-
iccid:
|
|
4999
|
-
package_id:
|
|
5000
|
-
start_date:
|
|
5001
|
-
end_date:
|
|
5002
|
-
comment:
|
|
5000
|
+
iccid: z4.string().describe("The subscriber ICCID (20-digit ICC identifier)"),
|
|
5001
|
+
package_id: z4.number().describe("The subscriber package ID (from list_subscriber_packages)"),
|
|
5002
|
+
start_date: z4.string().optional().describe("New start date in ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss)"),
|
|
5003
|
+
end_date: z4.string().optional().describe("New end date in ISO 8601 format (YYYY-MM-DD or YYYY-MM-DDTHH:mm:ss)"),
|
|
5004
|
+
comment: z4.string().optional().describe(
|
|
5003
5005
|
"Audit note stored on the OCS package record. OCS requires this field, so a default is sent when it is omitted."
|
|
5004
5006
|
),
|
|
5005
5007
|
...DRY_RUN_FIELD2
|
|
@@ -5027,12 +5029,12 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5027
5029
|
comment,
|
|
5028
5030
|
current
|
|
5029
5031
|
});
|
|
5030
|
-
const
|
|
5032
|
+
const result3 = await client2.call(
|
|
5031
5033
|
"modifySubscriberPrepaidPackageActivePeriod",
|
|
5032
5034
|
params
|
|
5033
5035
|
);
|
|
5034
5036
|
return {
|
|
5035
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
5037
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
5036
5038
|
};
|
|
5037
5039
|
}
|
|
5038
5040
|
)
|
|
@@ -5043,8 +5045,8 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5043
5045
|
title: "Modify Subscriber VoIP Plan",
|
|
5044
5046
|
description: "Use this to change the VoIP pricing plan assigned to a specific subscriber. VoIP plans control billing rates for VoIP calls made through the OCS platform, separate from the standard mobile plan's call rates. Params: `iccid` (subscriber identifier), `voip_plan_id` (integer VoIP plan ID from the OCS reseller settings). Returns: updated subscriber record confirming the new VoIP plan. Do NOT use this for mobile (non-VoIP) plan changes \u2014 use `modify_subscriber_mobile_plan`. For data-only eSIM products without VoIP services this tool has no effect.",
|
|
5045
5047
|
inputSchema: {
|
|
5046
|
-
iccid:
|
|
5047
|
-
voip_plan_id:
|
|
5048
|
+
iccid: z4.string().describe("The subscriber ICCID (20-digit ICC identifier)"),
|
|
5049
|
+
voip_plan_id: z4.number().describe("The VoIP pricing plan ID to assign to this subscriber"),
|
|
5048
5050
|
...DRY_RUN_FIELD2
|
|
5049
5051
|
},
|
|
5050
5052
|
annotations: { destructiveHint: true }
|
|
@@ -5056,12 +5058,12 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5056
5058
|
ctx,
|
|
5057
5059
|
async ({ iccid, voip_plan_id }, token2) => {
|
|
5058
5060
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
5059
|
-
const
|
|
5061
|
+
const result3 = await client2.call(
|
|
5060
5062
|
"modifySubscriberVoipPlan",
|
|
5061
5063
|
{ subscriberId: { iccid }, voipPlanId: voip_plan_id }
|
|
5062
5064
|
);
|
|
5063
5065
|
return {
|
|
5064
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
5066
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
5065
5067
|
};
|
|
5066
5068
|
}
|
|
5067
5069
|
)
|
|
@@ -5072,7 +5074,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5072
5074
|
title: "Push Steering List to Subscriber Device",
|
|
5073
5075
|
description: "Use this AFTER `modify_subscriber_steering_list` to actively push the updated OPLMN (operator preference list) to the subscriber's physical eSIM/SIM. Without this call, the steering list assignment change is recorded in OCS but the device continues using the old operator preference list until it performs a network re-registration. This is required for immediate operator switching (e.g. steering a subscriber away from an expensive roaming partner in real time). Params: `iccid` (subscriber identifier). Returns: push confirmation from OCS with delivery status. Do NOT call this without first calling `modify_subscriber_steering_list` \u2014 pushing without an assigned steering list is a no-op and wastes an OCS call.",
|
|
5074
5076
|
inputSchema: {
|
|
5075
|
-
iccid:
|
|
5077
|
+
iccid: z4.string().describe("The subscriber ICCID (20-digit ICC identifier)"),
|
|
5076
5078
|
...DRY_RUN_FIELD2
|
|
5077
5079
|
},
|
|
5078
5080
|
annotations: { destructiveHint: true }
|
|
@@ -5084,12 +5086,12 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5084
5086
|
ctx,
|
|
5085
5087
|
async ({ iccid }, token2) => {
|
|
5086
5088
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
5087
|
-
const
|
|
5089
|
+
const result3 = await client2.call(
|
|
5088
5090
|
"pushSteeringToSubs",
|
|
5089
5091
|
{ iccid }
|
|
5090
5092
|
);
|
|
5091
5093
|
return {
|
|
5092
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
5094
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
5093
5095
|
};
|
|
5094
5096
|
}
|
|
5095
5097
|
)
|
|
@@ -5100,7 +5102,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5100
5102
|
title: "Reset Subscriber Green Zone Counter",
|
|
5101
5103
|
description: "ADMIN: Use this to reset the Green Zone (Greenzone) volume counter for a subscriber. The Green Zone counter tracks bytes consumed on the reseller-defined whitelist of hosts/IPs after the subscriber's bundle is depleted \u2014 NOT the Diameter Gz/Gy accounting interface. Typically used after a billing dispute or test-cycle reset. This operation is IRREVERSIBLE \u2014 volumeOnGZ is permanently zeroed. Params: `iccid` (subscriber identifier). Returns: new counter state with volumeOnGZ (bytes, normally 0 after reset), lastResetDate, lastUpdateDate. Always call `get_subscriber` with `with_gz_counter=true` first to capture the snapshot. Do NOT use this to pause data usage \u2014 use `set_subscriber_traffic_restrictions` with `dataAllowed=false` instead.",
|
|
5102
5104
|
inputSchema: {
|
|
5103
|
-
iccid:
|
|
5105
|
+
iccid: z4.string().describe("The subscriber ICCID (20-digit ICC identifier)"),
|
|
5104
5106
|
...DRY_RUN_FIELD2
|
|
5105
5107
|
},
|
|
5106
5108
|
annotations: { destructiveHint: true }
|
|
@@ -5112,9 +5114,9 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5112
5114
|
ctx,
|
|
5113
5115
|
async ({ iccid }, token2) => {
|
|
5114
5116
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
5115
|
-
const
|
|
5117
|
+
const result3 = await client2.call("resetSubsGzCounter", { iccid });
|
|
5116
5118
|
return {
|
|
5117
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
5119
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
5118
5120
|
};
|
|
5119
5121
|
}
|
|
5120
5122
|
)
|
|
@@ -5125,7 +5127,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5125
5127
|
title: "Carrier Webhook / Relay Flag Status",
|
|
5126
5128
|
description: "Use this to check the current Bridge4IP webhook and relay flag configuration for this reseller. Returns the active state of all four traffic relay flags: Relay LU (Update Location \u2014 cell tower changes, closest to country-change signal), Relay Gy (mobile data usage events), Relay VoIP (VoIP usage events), Relay calls+SMS (call and SMS events). Also returns which notification webhooks are enabled (prepaid package usage threshold, reseller low credit, ES2 eSIM status, recurring packages) as a passthrough object. All relay/notification configuration is done in the OCS portal UI \u2014 this tool is READ-ONLY and reflects current state. Relay LU is the highest-value flag: when active, Bridge4IP pushes real-time Update Location events (mcc, mnc, lac, cellId) to the configured HTTP endpoint.",
|
|
5127
5129
|
inputSchema: {
|
|
5128
|
-
reseller_id:
|
|
5130
|
+
reseller_id: z4.number().int().optional().describe("Reseller ID (omit to use the token owner's reseller)")
|
|
5129
5131
|
},
|
|
5130
5132
|
annotations: { readOnlyHint: true }
|
|
5131
5133
|
},
|
|
@@ -5145,7 +5147,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5145
5147
|
const raw = await client2.call("getResellerInfo", params);
|
|
5146
5148
|
const traffic = raw.trafficInfo ?? {};
|
|
5147
5149
|
const notification = raw.notificationInfo ?? {};
|
|
5148
|
-
const
|
|
5150
|
+
const result3 = {
|
|
5149
5151
|
resellerId: raw.id ?? resellerId,
|
|
5150
5152
|
traffic: {
|
|
5151
5153
|
relayGy: traffic.relayGy === true,
|
|
@@ -5156,7 +5158,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5156
5158
|
notification
|
|
5157
5159
|
};
|
|
5158
5160
|
return {
|
|
5159
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
5161
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
5160
5162
|
};
|
|
5161
5163
|
}
|
|
5162
5164
|
)
|
|
@@ -5167,7 +5169,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5167
5169
|
title: "List VoIP Tariffs",
|
|
5168
5170
|
description: "Use this to list VoIP tariff definitions available to a reseller. Despite the OCS method name (listSubscriberVoipTariff), this is a reseller-level catalog listing \u2014 not a per-ICCID lookup. Use results (or get_reseller_info chargingInfo.voipPlan.id) to feed `list_voip_tariff_rule` for rate detail. Params: `reseller_id` (integer, optional \u2014 omit to use the token owner's reseller). Returns: OCS VoIP tariff records (may be empty when no VoIP catalog is configured). Do NOT use this for mobile wholesale rates \u2014 use `get_tariff` (getCustomerTariff). Do NOT use this to assign a VoIP plan \u2014 use `modify_subscriber_voip_plan`.",
|
|
5169
5171
|
inputSchema: {
|
|
5170
|
-
reseller_id:
|
|
5172
|
+
reseller_id: z4.number().int().positive().optional().describe("Reseller ID (omit to list tariffs for the token owner's reseller)")
|
|
5171
5173
|
},
|
|
5172
5174
|
annotations: { readOnlyHint: true }
|
|
5173
5175
|
},
|
|
@@ -5182,9 +5184,9 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5182
5184
|
if (reseller_id !== void 0) {
|
|
5183
5185
|
params.resellerId = reseller_id;
|
|
5184
5186
|
}
|
|
5185
|
-
const
|
|
5187
|
+
const result3 = await client2.call("listSubscriberVoipTariff", params);
|
|
5186
5188
|
return {
|
|
5187
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
5189
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
5188
5190
|
};
|
|
5189
5191
|
}
|
|
5190
5192
|
)
|
|
@@ -5195,7 +5197,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5195
5197
|
title: "List VoIP Tariff Rules",
|
|
5196
5198
|
description: "Use this to list the rate rules (costs) for a specific VoIP plan/tariff. OCS expects a bare integer plan id in the request body (not an object). Obtain plan ids from `get_reseller_info` \u2192 chargingInfo.voipPlan.id, or from `list_subscriber_voip_tariff`. Params: `voip_plan_id` (integer, required \u2014 VoIP plan/tariff id). Returns: VoIP tariff rule rows for that plan, or an OCS error when the id is unknown. Do NOT use this for mobile (non-VoIP) wholesale rates \u2014 use `get_tariff`. Do NOT use this to change a subscriber's VoIP plan \u2014 use `modify_subscriber_voip_plan`.",
|
|
5197
5199
|
inputSchema: {
|
|
5198
|
-
voip_plan_id:
|
|
5200
|
+
voip_plan_id: z4.number().int().positive().describe(
|
|
5199
5201
|
"VoIP plan/tariff ID (bare integer to OCS listVoipTariffRule; from get_reseller_info chargingInfo.voipPlan.id or list_subscriber_voip_tariff)"
|
|
5200
5202
|
)
|
|
5201
5203
|
},
|
|
@@ -5208,9 +5210,9 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5208
5210
|
ctx,
|
|
5209
5211
|
async ({ voip_plan_id }, token2) => {
|
|
5210
5212
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
5211
|
-
let
|
|
5213
|
+
let result3;
|
|
5212
5214
|
try {
|
|
5213
|
-
|
|
5215
|
+
result3 = await client2.call("listVoipTariffRule", voip_plan_id);
|
|
5214
5216
|
} catch (err9) {
|
|
5215
5217
|
if (err9 instanceof OcsApiError && err9.code === 11) {
|
|
5216
5218
|
return {
|
|
@@ -5228,7 +5230,7 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5228
5230
|
throw err9;
|
|
5229
5231
|
}
|
|
5230
5232
|
return {
|
|
5231
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
5233
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
5232
5234
|
};
|
|
5233
5235
|
}
|
|
5234
5236
|
)
|
|
@@ -5239,8 +5241,8 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5239
5241
|
title: "Change Network Profile of Location Zone",
|
|
5240
5242
|
description: "Use this to attach or change the network profile on an existing location zone. A network profile defines sponsor/roaming configuration used when the zone is referenced by package templates. Params: `location_zone_id` (integer from list_detailed_location_zones), `network_profile_id` (integer from list_network_profiles). Returns: OCS confirmation of the updated zone/profile binding. Do NOT use this to create a new location zone \u2014 use `create_location_zone` (which requires networkProfileId at creation time). Do NOT use this for edit/delete of zone TADIG lists \u2014 those remain UI-agent-only (G-19).",
|
|
5241
5243
|
inputSchema: {
|
|
5242
|
-
location_zone_id:
|
|
5243
|
-
network_profile_id:
|
|
5244
|
+
location_zone_id: z4.number().int().positive().describe("Location zone ID (locationZoneId / zoneId from list_detailed_location_zones)"),
|
|
5245
|
+
network_profile_id: z4.number().int().positive().describe("Network profile ID (from list_network_profiles)"),
|
|
5244
5246
|
...DRY_RUN_FIELD2
|
|
5245
5247
|
},
|
|
5246
5248
|
annotations: { destructiveHint: true }
|
|
@@ -5255,12 +5257,12 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5255
5257
|
network_profile_id
|
|
5256
5258
|
}, token2) => {
|
|
5257
5259
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
5258
|
-
const
|
|
5260
|
+
const result3 = await client2.call("changeNetworkProfileOfLocationZone", {
|
|
5259
5261
|
locationZoneId: location_zone_id,
|
|
5260
5262
|
networkProfileId: network_profile_id
|
|
5261
5263
|
});
|
|
5262
5264
|
return {
|
|
5263
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
5265
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
5264
5266
|
};
|
|
5265
5267
|
}
|
|
5266
5268
|
)
|
|
@@ -5268,10 +5270,10 @@ function registerAllBacklogTools(server2, ctx) {
|
|
|
5268
5270
|
}
|
|
5269
5271
|
|
|
5270
5272
|
// src/tools-carrier-ask.ts
|
|
5271
|
-
import { z as
|
|
5273
|
+
import { z as z17 } from "zod";
|
|
5272
5274
|
|
|
5273
5275
|
// src/tools-ui-agent.ts
|
|
5274
|
-
import { z as
|
|
5276
|
+
import { z as z5 } from "zod";
|
|
5275
5277
|
|
|
5276
5278
|
// src/ui-agent-stub.ts
|
|
5277
5279
|
var REMOTE_MCP_URL = "https://mcp.carrier.llc/mcp";
|
|
@@ -5561,13 +5563,13 @@ function wrapPortalHandler(toolName, gapId, requiredScope, ctx, runtime, optIn,
|
|
|
5561
5563
|
throw err9;
|
|
5562
5564
|
}
|
|
5563
5565
|
try {
|
|
5564
|
-
const
|
|
5566
|
+
const result3 = await runUiAgent(
|
|
5565
5567
|
fullPrompt,
|
|
5566
5568
|
`Carrier CLI UI Agent: ${toolName} (${gapId})`,
|
|
5567
5569
|
runtime.env,
|
|
5568
5570
|
{ ownerSub: ctx.props.sub, redact }
|
|
5569
5571
|
);
|
|
5570
|
-
if (!
|
|
5572
|
+
if (!result3.task_id) {
|
|
5571
5573
|
ctx.audit({
|
|
5572
5574
|
tool_name: toolName,
|
|
5573
5575
|
ocs_method: ocsMethod,
|
|
@@ -5584,38 +5586,38 @@ function wrapPortalHandler(toolName, gapId, requiredScope, ctx, runtime, optIn,
|
|
|
5584
5586
|
true
|
|
5585
5587
|
);
|
|
5586
5588
|
}
|
|
5587
|
-
runtime.dispatchedTaskIds.add(
|
|
5589
|
+
runtime.dispatchedTaskIds.add(result3.task_id);
|
|
5588
5590
|
ctx.audit({
|
|
5589
5591
|
tool_name: toolName,
|
|
5590
5592
|
ocs_method: ocsMethod,
|
|
5591
|
-
status:
|
|
5593
|
+
status: result3.status === "error" ? "error" : "ui_agent_dispatched",
|
|
5592
5594
|
dry_run: false,
|
|
5593
5595
|
duration_ms: Date.now() - start,
|
|
5594
5596
|
event_type: "ui_agent_dispatch",
|
|
5595
|
-
manus_task_id:
|
|
5597
|
+
manus_task_id: result3.task_id
|
|
5596
5598
|
// AE blob position is the contract; the name is history
|
|
5597
5599
|
});
|
|
5598
5600
|
return jsonResult({
|
|
5599
|
-
status:
|
|
5601
|
+
status: result3.status === "stopped" ? "ui_agent_completed" : result3.status === "waiting" ? "ui_agent_awaiting_input" : result3.status,
|
|
5600
5602
|
tool: toolName,
|
|
5601
5603
|
gap_id: gapId,
|
|
5602
5604
|
// Held still across the vendor swap and across transports: MCP clients
|
|
5603
5605
|
// and the console read these names.
|
|
5604
|
-
steel_task_id:
|
|
5605
|
-
steel_session_viewer_url:
|
|
5606
|
+
steel_task_id: result3.task_id,
|
|
5607
|
+
steel_session_viewer_url: result3.session_viewer_url,
|
|
5606
5608
|
// Redacted defensively. `runUiAgent` already applies the same redactor
|
|
5607
5609
|
// before the record is stored, so this is the second of two passes over
|
|
5608
5610
|
// the fields an agent can echo its instructions into. Field-by-field
|
|
5609
5611
|
// rather than over the serialised JSON: a password containing a quote
|
|
5610
5612
|
// or a backslash is escaped by JSON.stringify and would no longer match
|
|
5611
5613
|
// a plain substring replace.
|
|
5612
|
-
result:
|
|
5613
|
-
...
|
|
5614
|
-
summary: redact(
|
|
5615
|
-
...
|
|
5616
|
-
...
|
|
5614
|
+
result: result3.result ? {
|
|
5615
|
+
...result3.result,
|
|
5616
|
+
summary: redact(result3.result.summary),
|
|
5617
|
+
...result3.result.entity_id !== void 0 ? { entity_id: redact(result3.result.entity_id) } : {},
|
|
5618
|
+
...result3.result.error_message !== void 0 ? { error_message: redact(result3.result.error_message) } : {}
|
|
5617
5619
|
} : void 0,
|
|
5618
|
-
cost_usd:
|
|
5620
|
+
cost_usd: result3.spend?.costUsd,
|
|
5619
5621
|
session_spend_usd: runtime.spend.costUsd,
|
|
5620
5622
|
runs_remaining_this_session: runtime.budget.remaining,
|
|
5621
5623
|
note: "The run completed in-process \u2014 a local CLI has no background runtime, so this call blocked for its duration.",
|
|
@@ -5653,9 +5655,9 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5653
5655
|
title: "Create Steering List (UI Agent)",
|
|
5654
5656
|
description: "Creates a new network steering list (OPLMN preference configuration) via the OCS web dashboard. This operation is not available via the OCS REST API. A browser agent is dispatched to perform the operation. Params: `name` (steering list name), `description` (optional)." + NOTE,
|
|
5655
5657
|
inputSchema: {
|
|
5656
|
-
name:
|
|
5657
|
-
description:
|
|
5658
|
-
dry_run:
|
|
5658
|
+
name: z5.string().describe("Name for the new steering list"),
|
|
5659
|
+
description: z5.string().optional().describe("Optional description for the steering list"),
|
|
5660
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5659
5661
|
}
|
|
5660
5662
|
},
|
|
5661
5663
|
gated(
|
|
@@ -5674,11 +5676,11 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5674
5676
|
title: "Build Steering List (UI Agent)",
|
|
5675
5677
|
description: "Adds or removes operators (MCC-MNC) from an existing steering list via the OCS web dashboard. This operation is not available via the OCS REST API. Params: `steering_list_id`, `add_operators` (array of MCC-MNC to add), `remove_operators` (array to remove), `operator_type` ('priority' or 'excluded')." + NOTE,
|
|
5676
5678
|
inputSchema: {
|
|
5677
|
-
steering_list_id:
|
|
5678
|
-
add_operators:
|
|
5679
|
-
remove_operators:
|
|
5680
|
-
operator_type:
|
|
5681
|
-
dry_run:
|
|
5679
|
+
steering_list_id: z5.number().describe("ID of the steering list to modify"),
|
|
5680
|
+
add_operators: z5.array(z5.string()).optional().describe("MCC-MNC codes to add (e.g. ['20801', '26201'])"),
|
|
5681
|
+
remove_operators: z5.array(z5.string()).optional().describe("MCC-MNC codes to remove"),
|
|
5682
|
+
operator_type: z5.enum(["priority", "excluded"]).default("priority").describe("Whether operators are priority or excluded"),
|
|
5683
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5682
5684
|
}
|
|
5683
5685
|
},
|
|
5684
5686
|
gated(
|
|
@@ -5697,9 +5699,9 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5697
5699
|
title: "Set Account Steering List (UI Agent)",
|
|
5698
5700
|
description: "Assigns or removes a steering list at the account level via the OCS web dashboard. The subscriber-level counterpart `modify_subscriber_steering_list` is available via API; this account-level operation is UI-only. Params: `account_id`, `steering_list_id` (0 to remove)." + NOTE,
|
|
5699
5701
|
inputSchema: {
|
|
5700
|
-
account_id:
|
|
5701
|
-
steering_list_id:
|
|
5702
|
-
dry_run:
|
|
5702
|
+
account_id: z5.number().describe("Account ID to assign the steering list to"),
|
|
5703
|
+
steering_list_id: z5.number().describe("Steering list ID to assign (0 to remove/unset)"),
|
|
5704
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5703
5705
|
}
|
|
5704
5706
|
},
|
|
5705
5707
|
gated(
|
|
@@ -5718,11 +5720,11 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5718
5720
|
title: "Request Reseller Relay Change",
|
|
5719
5721
|
description: "Drafts a parent-reseller/support request for Relay Gy, calls/SMS relay, or VoIP relay when those portal controls are read-only at the current reseller tier. Does not send the request or mutate the portal.",
|
|
5720
5722
|
inputSchema: {
|
|
5721
|
-
reseller_id:
|
|
5722
|
-
relay_gy:
|
|
5723
|
-
relay_calls_sms:
|
|
5724
|
-
relay_voip:
|
|
5725
|
-
reason:
|
|
5723
|
+
reseller_id: z5.number().optional().describe("Reseller id; defaults to the authenticated reseller"),
|
|
5724
|
+
relay_gy: z5.boolean().optional().describe("Desired Relay Gy state"),
|
|
5725
|
+
relay_calls_sms: z5.boolean().optional().describe("Desired calls/SMS relay state"),
|
|
5726
|
+
relay_voip: z5.boolean().optional().describe("Desired VoIP relay state"),
|
|
5727
|
+
reason: z5.string().optional().describe("Operational reason for the requested change")
|
|
5726
5728
|
}
|
|
5727
5729
|
},
|
|
5728
5730
|
async (args) => {
|
|
@@ -5814,10 +5816,10 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5814
5816
|
title: "Create Account (UI Agent)",
|
|
5815
5817
|
description: "Creates a new sub-account under the reseller via the OCS web dashboard. This operation is not available via the OCS REST API. Params: `name` (account name), `description` (optional), `initial_balance` (optional, default 0)." + NOTE,
|
|
5816
5818
|
inputSchema: {
|
|
5817
|
-
name:
|
|
5818
|
-
description:
|
|
5819
|
-
initial_balance:
|
|
5820
|
-
dry_run:
|
|
5819
|
+
name: z5.string().describe("Name for the new account"),
|
|
5820
|
+
description: z5.string().optional().describe("Optional description"),
|
|
5821
|
+
initial_balance: z5.number().optional().describe("Initial balance in account currency (default 0)"),
|
|
5822
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5821
5823
|
}
|
|
5822
5824
|
},
|
|
5823
5825
|
gated(
|
|
@@ -5836,10 +5838,10 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5836
5838
|
title: "Create Destination List (UI Agent)",
|
|
5837
5839
|
description: "Creates a new destination list (named set of phone number prefixes for MOC call permissions) via the OCS web dashboard. Params: `name`, `prefixes` (array of prefix strings), `description`." + NOTE,
|
|
5838
5840
|
inputSchema: {
|
|
5839
|
-
name:
|
|
5840
|
-
prefixes:
|
|
5841
|
-
description:
|
|
5842
|
-
dry_run:
|
|
5841
|
+
name: z5.string().describe("Name for the new destination list"),
|
|
5842
|
+
prefixes: z5.array(z5.string()).optional().describe("Phone number prefixes to include (e.g. ['+31', '+49'])"),
|
|
5843
|
+
description: z5.string().optional().describe("Optional description"),
|
|
5844
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5843
5845
|
}
|
|
5844
5846
|
},
|
|
5845
5847
|
gated(
|
|
@@ -5858,11 +5860,11 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5858
5860
|
title: "Edit Destination List (UI Agent)",
|
|
5859
5861
|
description: "Edits an existing destination list via the OCS web dashboard. Params: `destination_list_id`, `add_prefixes`, `remove_prefixes`, `new_name`." + NOTE,
|
|
5860
5862
|
inputSchema: {
|
|
5861
|
-
destination_list_id:
|
|
5862
|
-
add_prefixes:
|
|
5863
|
-
remove_prefixes:
|
|
5864
|
-
new_name:
|
|
5865
|
-
dry_run:
|
|
5863
|
+
destination_list_id: z5.number().describe("ID of the destination list to edit"),
|
|
5864
|
+
add_prefixes: z5.array(z5.string()).optional().describe("Prefixes to add"),
|
|
5865
|
+
remove_prefixes: z5.array(z5.string()).optional().describe("Prefixes to remove"),
|
|
5866
|
+
new_name: z5.string().optional().describe("Rename the destination list"),
|
|
5867
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5866
5868
|
}
|
|
5867
5869
|
},
|
|
5868
5870
|
gated(
|
|
@@ -5881,8 +5883,8 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5881
5883
|
title: "Delete Destination List (UI Agent)",
|
|
5882
5884
|
description: "Deletes a destination list via the OCS web dashboard. Params: `destination_list_id`. WARNING: This is destructive and cannot be undone." + NOTE,
|
|
5883
5885
|
inputSchema: {
|
|
5884
|
-
destination_list_id:
|
|
5885
|
-
dry_run:
|
|
5886
|
+
destination_list_id: z5.number().describe("ID of the destination list to delete"),
|
|
5887
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5886
5888
|
}
|
|
5887
5889
|
},
|
|
5888
5890
|
gated(
|
|
@@ -5901,8 +5903,8 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5901
5903
|
title: "Delete Package Template (UI Agent)",
|
|
5902
5904
|
description: "Deletes a package template from the product catalog via the OCS web dashboard. This operation is not available via the OCS REST API. Params: `template_id`. WARNING: This is destructive." + NOTE,
|
|
5903
5905
|
inputSchema: {
|
|
5904
|
-
template_id:
|
|
5905
|
-
dry_run:
|
|
5906
|
+
template_id: z5.number().describe("ID of the package template to delete"),
|
|
5907
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5906
5908
|
}
|
|
5907
5909
|
},
|
|
5908
5910
|
gated(
|
|
@@ -5921,11 +5923,11 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5921
5923
|
title: "Edit Location Zone (UI Agent)",
|
|
5922
5924
|
description: "Edits an existing location zone via the OCS web dashboard. `create_location_zone` is available via API; edit is UI-only. Params: `zone_id`, `new_name`, `add_countries`, `remove_countries`." + NOTE,
|
|
5923
5925
|
inputSchema: {
|
|
5924
|
-
zone_id:
|
|
5925
|
-
new_name:
|
|
5926
|
-
add_countries:
|
|
5927
|
-
remove_countries:
|
|
5928
|
-
dry_run:
|
|
5926
|
+
zone_id: z5.number().describe("ID of the location zone to edit"),
|
|
5927
|
+
new_name: z5.string().optional().describe("Rename the location zone"),
|
|
5928
|
+
add_countries: z5.array(z5.string()).optional().describe("ISO country codes to add (e.g. ['NL', 'DE'])"),
|
|
5929
|
+
remove_countries: z5.array(z5.string()).optional().describe("ISO country codes to remove"),
|
|
5930
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5929
5931
|
}
|
|
5930
5932
|
},
|
|
5931
5933
|
gated(
|
|
@@ -5944,8 +5946,8 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5944
5946
|
title: "Delete Location Zone (UI Agent)",
|
|
5945
5947
|
description: "Deletes a location zone via the OCS web dashboard. `create_location_zone` is available via API; delete is UI-only. Params: `zone_id`. WARNING: Zones in use by active templates may not be deletable." + NOTE,
|
|
5946
5948
|
inputSchema: {
|
|
5947
|
-
zone_id:
|
|
5948
|
-
dry_run:
|
|
5949
|
+
zone_id: z5.number().describe("ID of the location zone to delete"),
|
|
5950
|
+
dry_run: z5.boolean().optional().describe("Preview the agent prompt without dispatching")
|
|
5949
5951
|
}
|
|
5950
5952
|
},
|
|
5951
5953
|
gated(
|
|
@@ -5961,7 +5963,7 @@ function registerAllUiAgentTools(server2, ctx, runtime, optIn = readPortalOptIn(
|
|
|
5961
5963
|
}
|
|
5962
5964
|
|
|
5963
5965
|
// src/tools-ui-agent-ask.ts
|
|
5964
|
-
import { z as
|
|
5966
|
+
import { z as z6 } from "zod";
|
|
5965
5967
|
var UI_AGENT_ASK_TOOL_SCOPES = {
|
|
5966
5968
|
ui_agent_reply: "write",
|
|
5967
5969
|
ui_agent_list_pending: "read"
|
|
@@ -6013,8 +6015,8 @@ function registerUiAgentAskTools(server2, ctx, runtime) {
|
|
|
6013
6015
|
title: "Reply to Paused UI Agent Task",
|
|
6014
6016
|
description: "Resumes a browser automation task that paused to ask a question. Use ui_agent_list_pending to find tasks waiting for input. Provide the task_id and your reply (e.g. a 2FA code, a field value, or a yes/no answer). The reply content is never recorded in audit logs \u2014 only its length is logged.",
|
|
6015
6017
|
inputSchema: {
|
|
6016
|
-
task_id:
|
|
6017
|
-
reply:
|
|
6018
|
+
task_id: z6.string().describe("Task ID to resume (from ui_agent_list_pending)"),
|
|
6019
|
+
reply: z6.string().describe(
|
|
6018
6020
|
"Your answer to the agent's question (e.g. a 2FA code or confirmation)"
|
|
6019
6021
|
)
|
|
6020
6022
|
}
|
|
@@ -6184,12 +6186,17 @@ function registerUiAgentAskTools(server2, ctx, runtime) {
|
|
|
6184
6186
|
}
|
|
6185
6187
|
|
|
6186
6188
|
// src/carrier-api-tools.ts
|
|
6187
|
-
import { z as
|
|
6189
|
+
import { z as z7 } from "zod";
|
|
6188
6190
|
var CARRIER_API_TOOL_SCOPES = {
|
|
6189
6191
|
list_connectivity_offering_templates: "read",
|
|
6190
6192
|
create_benefit_campaign: "write",
|
|
6191
6193
|
claim_benefit: "write",
|
|
6192
|
-
issue_benefit_claim: "write"
|
|
6194
|
+
issue_benefit_claim: "write",
|
|
6195
|
+
set_benefit_campaign_status: "write",
|
|
6196
|
+
create_benefit_entitlement: "write",
|
|
6197
|
+
reconcile_benefit_claim: "write",
|
|
6198
|
+
record_experiment_event: "write",
|
|
6199
|
+
experiment_report: "read"
|
|
6193
6200
|
};
|
|
6194
6201
|
var CAMPAIGN_ID_PATTERN = /^cbc_[0-9a-f]{32}$/;
|
|
6195
6202
|
var CLAIM_ID_PATTERN = /^cbl_[0-9a-f]{32}$/;
|
|
@@ -6286,12 +6293,12 @@ function registerCarrierApiTools(server2, ctx) {
|
|
|
6286
6293
|
title: "Create a benefit campaign",
|
|
6287
6294
|
description: "Create a member-benefit campaign: a capped number of eSIM claims for one offering revision, each costing a fixed amount from your sponsor wallet. Calls POST /v1/connectivity/benefit-campaigns on api.carrier.llc with your own MCP access token and returns the new campaign id. Needs write scope. A campaign cannot be deleted once created. cost_cents above the deployment ceiling is rejected with cost_above_limit and creates nothing. Params: offering_id, revision (>=1), max_claims (>=1), cost_cents (>=1, per claim), expires_at (epoch milliseconds), product_id (optional, an active product of your organization). Do NOT use this to claim or issue an eSIM \u2014 that is claim_benefit and issue_benefit_claim.",
|
|
6288
6295
|
inputSchema: {
|
|
6289
|
-
offering_id:
|
|
6290
|
-
revision:
|
|
6291
|
-
max_claims:
|
|
6292
|
-
cost_cents:
|
|
6293
|
-
expires_at:
|
|
6294
|
-
product_id:
|
|
6296
|
+
offering_id: z7.string().min(1).max(200).describe("Offering the campaign issues from."),
|
|
6297
|
+
revision: z7.number().int().min(1).max(Number.MAX_SAFE_INTEGER).describe("Offering revision, 1 or higher."),
|
|
6298
|
+
max_claims: z7.number().int().min(1).max(Number.MAX_SAFE_INTEGER).describe("Most claims the campaign accepts."),
|
|
6299
|
+
cost_cents: z7.number().int().min(1).max(Number.MAX_SAFE_INTEGER).describe("Cost of one claim in cents. The API enforces a ceiling."),
|
|
6300
|
+
expires_at: z7.number().int().min(1).max(Number.MAX_SAFE_INTEGER).describe("Expiry as epoch milliseconds."),
|
|
6301
|
+
product_id: z7.string().min(1).max(200).optional().describe("Optional product to issue from.")
|
|
6295
6302
|
},
|
|
6296
6303
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
|
|
6297
6304
|
},
|
|
@@ -6321,8 +6328,8 @@ function registerCarrierApiTools(server2, ctx) {
|
|
|
6321
6328
|
title: "Claim a benefit",
|
|
6322
6329
|
description: "Claim one benefit from a campaign for an external reference, which places a hold on the sponsor wallet. Calls POST /v1/connectivity/benefit-campaigns/{id}/claims on api.carrier.llc with your own MCP access token. Needs write scope. Safe to repeat with the same external_ref: the same claim comes back (HTTP 200) and nothing is held twice. Results: 201 held, 200 replay of an existing claim, 202 funding outcome unknown (repeat the call), 402 wallet cannot fund the claim, 409 campaign paused, expired or full. Params: campaign_id (cbc_ plus 32 hex), external_ref (1 to 200 characters, your own reference for the person). Do NOT use this to issue the eSIM \u2014 that is issue_benefit_claim, called with the claim id from this result.",
|
|
6323
6330
|
inputSchema: {
|
|
6324
|
-
campaign_id:
|
|
6325
|
-
external_ref:
|
|
6331
|
+
campaign_id: z7.string().regex(CAMPAIGN_ID_PATTERN).describe("Campaign id, cbc_ followed by 32 hex characters."),
|
|
6332
|
+
external_ref: z7.string().min(1).max(200).describe("Your own reference for the claimant, 1 to 200 characters.")
|
|
6326
6333
|
},
|
|
6327
6334
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
6328
6335
|
},
|
|
@@ -6348,8 +6355,8 @@ function registerCarrierApiTools(server2, ctx) {
|
|
|
6348
6355
|
title: "Issue the eSIM for a held claim",
|
|
6349
6356
|
description: "Issue ONE REAL eSIM for a held claim and settle the wallet hold. This spends money and cannot be undone. Calls POST /v1/connectivity/benefit-campaigns/{id}/claims/{claimId}/issue on api.carrier.llc with your own MCP access token. Needs write scope. A retry returns the same eSIM and never a second one, but do not retry blindly: on 202 the outcome is unknown and the hold is kept, so wait and call again once. Results: 200 settled with the eSIM, 202 outcome unknown, 404 not found (or issuing is switched off), 409 the claim is not issuable. Params: campaign_id (cbc_ plus 32 hex), claim_id (cbl_ plus 32 hex, from claim_benefit). No other params. Do NOT use this before claim_benefit returned a held claim.",
|
|
6350
6357
|
inputSchema: {
|
|
6351
|
-
campaign_id:
|
|
6352
|
-
claim_id:
|
|
6358
|
+
campaign_id: z7.string().regex(CAMPAIGN_ID_PATTERN).describe("Campaign id, cbc_ followed by 32 hex characters."),
|
|
6359
|
+
claim_id: z7.string().regex(CLAIM_ID_PATTERN).describe("Claim id from claim_benefit, cbl_ followed by 32 hex characters.")
|
|
6353
6360
|
},
|
|
6354
6361
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }
|
|
6355
6362
|
},
|
|
@@ -6369,10 +6376,155 @@ function registerCarrierApiTools(server2, ctx) {
|
|
|
6369
6376
|
{ skipUserToken: true }
|
|
6370
6377
|
)
|
|
6371
6378
|
);
|
|
6379
|
+
server2.registerTool(
|
|
6380
|
+
"set_benefit_campaign_status",
|
|
6381
|
+
{
|
|
6382
|
+
title: "Pause or resume a benefit campaign",
|
|
6383
|
+
description: "Pause a campaign so it accepts no new claims, or resume it. Calls POST /v1/connectivity/benefit-campaigns/{id}/status on api.carrier.llc with your own MCP access token. Needs write scope. Pausing blocks NEW claims; it does not release holds that were already made. Params: campaign_id (cbc_ plus 32 hex), status (active or paused).",
|
|
6384
|
+
inputSchema: {
|
|
6385
|
+
campaign_id: z7.string().regex(CAMPAIGN_ID_PATTERN).describe("Campaign id, cbc_ followed by 32 hex characters."),
|
|
6386
|
+
status: z7.enum(["active", "paused"]).describe("The status to set.")
|
|
6387
|
+
},
|
|
6388
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
6389
|
+
},
|
|
6390
|
+
wrapHandler(
|
|
6391
|
+
"set_benefit_campaign_status",
|
|
6392
|
+
"carrier-api.benefit-campaigns.status",
|
|
6393
|
+
"write",
|
|
6394
|
+
ctx,
|
|
6395
|
+
(args, _token, extra) => {
|
|
6396
|
+
if (typeof args.campaign_id !== "string" || !CAMPAIGN_ID_PATTERN.test(args.campaign_id)) return Promise.resolve(idPathError("campaign_id"));
|
|
6397
|
+
return carrierApiRequest(ctx, extra, {
|
|
6398
|
+
method: "POST",
|
|
6399
|
+
path: `/v1/connectivity/benefit-campaigns/${args.campaign_id}/status`,
|
|
6400
|
+
body: { status: args.status }
|
|
6401
|
+
});
|
|
6402
|
+
},
|
|
6403
|
+
{ skipUserToken: true }
|
|
6404
|
+
)
|
|
6405
|
+
);
|
|
6406
|
+
server2.registerTool(
|
|
6407
|
+
"create_benefit_entitlement",
|
|
6408
|
+
{
|
|
6409
|
+
title: "Issue a claim right for a booking reference",
|
|
6410
|
+
description: "Issue ONE single-use right for one external booking or member reference, which the claimant presents to claim a benefit. Calls POST /v1/connectivity/benefit-campaigns/{id}/entitlements on api.carrier.llc with your own MCP access token. Needs write scope. The token is returned once and is never stored in plain text; a second right for the same reference is refused. Params: campaign_id (cbc_ plus 32 hex), external_ref (1 to 200 characters), ttl_ms (optional lifetime in milliseconds).",
|
|
6411
|
+
inputSchema: {
|
|
6412
|
+
campaign_id: z7.string().regex(CAMPAIGN_ID_PATTERN).describe("Campaign id, cbc_ followed by 32 hex characters."),
|
|
6413
|
+
external_ref: z7.string().min(1).max(200).describe("Your own reference for the person, 1 to 200 characters."),
|
|
6414
|
+
ttl_ms: z7.number().int().min(1).max(Number.MAX_SAFE_INTEGER).optional().describe("Lifetime of the right in milliseconds. Defaults to 30 days.")
|
|
6415
|
+
},
|
|
6416
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
|
|
6417
|
+
},
|
|
6418
|
+
wrapHandler(
|
|
6419
|
+
"create_benefit_entitlement",
|
|
6420
|
+
"carrier-api.benefit-entitlements.create",
|
|
6421
|
+
"write",
|
|
6422
|
+
ctx,
|
|
6423
|
+
(args, _token, extra) => {
|
|
6424
|
+
if (typeof args.campaign_id !== "string" || !CAMPAIGN_ID_PATTERN.test(args.campaign_id)) return Promise.resolve(idPathError("campaign_id"));
|
|
6425
|
+
return carrierApiRequest(ctx, extra, {
|
|
6426
|
+
method: "POST",
|
|
6427
|
+
path: `/v1/connectivity/benefit-campaigns/${args.campaign_id}/entitlements`,
|
|
6428
|
+
body: {
|
|
6429
|
+
external_ref: args.external_ref,
|
|
6430
|
+
...args.ttl_ms !== void 0 ? { ttl_ms: args.ttl_ms } : {}
|
|
6431
|
+
}
|
|
6432
|
+
});
|
|
6433
|
+
},
|
|
6434
|
+
{ skipUserToken: true }
|
|
6435
|
+
)
|
|
6436
|
+
);
|
|
6437
|
+
server2.registerTool(
|
|
6438
|
+
"reconcile_benefit_claim",
|
|
6439
|
+
{
|
|
6440
|
+
title: "Close a claim whose issuance outcome is unknown",
|
|
6441
|
+
description: "Ask the provider what happened to a claim whose issuance ended in an unknown outcome. Calls POST /v1/connectivity/benefit-campaigns/{id}/claims/{claimId}/reconcile on api.carrier.llc with your own MCP access token. Needs write scope. It never dispatches a second eSIM: it reads the existing issuance under the same claim id. Results: 200 the claim is closed, 202 the outcome is still unknown (call again later), 409 the claim never started issuing or is not held. Params: campaign_id (cbc_ plus 32 hex), claim_id (cbl_ plus 32 hex).",
|
|
6442
|
+
inputSchema: {
|
|
6443
|
+
campaign_id: z7.string().regex(CAMPAIGN_ID_PATTERN).describe("Campaign id, cbc_ followed by 32 hex characters."),
|
|
6444
|
+
claim_id: z7.string().regex(CLAIM_ID_PATTERN).describe("Claim id, cbl_ followed by 32 hex characters.")
|
|
6445
|
+
},
|
|
6446
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
6447
|
+
},
|
|
6448
|
+
wrapHandler(
|
|
6449
|
+
"reconcile_benefit_claim",
|
|
6450
|
+
"carrier-api.benefit-claims.reconcile",
|
|
6451
|
+
"write",
|
|
6452
|
+
ctx,
|
|
6453
|
+
(args, _token, extra) => {
|
|
6454
|
+
if (typeof args.campaign_id !== "string" || !CAMPAIGN_ID_PATTERN.test(args.campaign_id)) return Promise.resolve(idPathError("campaign_id"));
|
|
6455
|
+
if (typeof args.claim_id !== "string" || !CLAIM_ID_PATTERN.test(args.claim_id)) return Promise.resolve(idPathError("claim_id"));
|
|
6456
|
+
return carrierApiRequest(ctx, extra, {
|
|
6457
|
+
method: "POST",
|
|
6458
|
+
path: `/v1/connectivity/benefit-campaigns/${args.campaign_id}/claims/${args.claim_id}/reconcile`
|
|
6459
|
+
});
|
|
6460
|
+
},
|
|
6461
|
+
{ skipUserToken: true }
|
|
6462
|
+
)
|
|
6463
|
+
);
|
|
6464
|
+
server2.registerTool(
|
|
6465
|
+
"record_experiment_event",
|
|
6466
|
+
{
|
|
6467
|
+
title: "Record one experiment event",
|
|
6468
|
+
description: "Record ONE event of an experiment: what a participant saw or did. Calls POST /v1/connectivity/experiment-events on api.carrier.llc with your own MCP access token. Needs write scope. Safe to repeat with the same event_id: the event is stored once and the replay returns 200. Params: event_id (your own id for this event), experiment_id, revision (>=1), link (the participant), measure (viewed, confirmed, issued or first_data).",
|
|
6469
|
+
inputSchema: {
|
|
6470
|
+
event_id: z7.string().min(1).max(200).describe("Your own id for this event."),
|
|
6471
|
+
experiment_id: z7.string().min(1).max(200).describe("The experiment this event belongs to."),
|
|
6472
|
+
revision: z7.number().int().min(1).max(Number.MAX_SAFE_INTEGER).describe("The revision of the experiment."),
|
|
6473
|
+
link: z7.string().min(1).max(200).describe("The participant this event is about."),
|
|
6474
|
+
measure: z7.enum(["viewed", "confirmed", "issued", "first_data"]).describe("What the participant did.")
|
|
6475
|
+
},
|
|
6476
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
6477
|
+
},
|
|
6478
|
+
wrapHandler(
|
|
6479
|
+
"record_experiment_event",
|
|
6480
|
+
"carrier-api.experiment-events.create",
|
|
6481
|
+
"write",
|
|
6482
|
+
ctx,
|
|
6483
|
+
(args, _token, extra) => carrierApiRequest(ctx, extra, {
|
|
6484
|
+
method: "POST",
|
|
6485
|
+
path: "/v1/connectivity/experiment-events",
|
|
6486
|
+
body: {
|
|
6487
|
+
event_id: args.event_id,
|
|
6488
|
+
experiment_id: args.experiment_id,
|
|
6489
|
+
revision: args.revision,
|
|
6490
|
+
link: args.link,
|
|
6491
|
+
measure: args.measure
|
|
6492
|
+
}
|
|
6493
|
+
}),
|
|
6494
|
+
{ skipUserToken: true }
|
|
6495
|
+
)
|
|
6496
|
+
);
|
|
6497
|
+
server2.registerTool(
|
|
6498
|
+
"experiment_report",
|
|
6499
|
+
{
|
|
6500
|
+
title: "Counts for one experiment",
|
|
6501
|
+
description: "Count the events of one experiment per measure inside a time window. Calls GET /v1/connectivity/experiment-events/{experimentId}/report on api.carrier.llc with your own MCP access token. Needs read scope. The counts describe what happened; they do not say why. A measure without events is absent, never zero. Params: experiment_id, from and to (epoch milliseconds, to is exclusive).",
|
|
6502
|
+
inputSchema: {
|
|
6503
|
+
experiment_id: z7.string().min(1).max(200).describe("The experiment to report on."),
|
|
6504
|
+
from: z7.number().int().min(0).max(Number.MAX_SAFE_INTEGER).describe("Start of the window, epoch milliseconds."),
|
|
6505
|
+
to: z7.number().int().min(0).max(Number.MAX_SAFE_INTEGER).describe("End of the window, epoch milliseconds, exclusive.")
|
|
6506
|
+
},
|
|
6507
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
6508
|
+
},
|
|
6509
|
+
wrapHandler(
|
|
6510
|
+
"experiment_report",
|
|
6511
|
+
"carrier-api.experiment-events.report",
|
|
6512
|
+
"read",
|
|
6513
|
+
ctx,
|
|
6514
|
+
(args, _token, extra) => {
|
|
6515
|
+
const q = `from=${encodeURIComponent(String(args.from))}&to=${encodeURIComponent(String(args.to))}`;
|
|
6516
|
+
return carrierApiRequest(ctx, extra, {
|
|
6517
|
+
method: "GET",
|
|
6518
|
+
path: `/v1/connectivity/experiment-events/${encodeURIComponent(args.experiment_id)}/report?${q}`
|
|
6519
|
+
});
|
|
6520
|
+
},
|
|
6521
|
+
{ skipUserToken: true }
|
|
6522
|
+
)
|
|
6523
|
+
);
|
|
6372
6524
|
}
|
|
6373
6525
|
|
|
6374
6526
|
// src/tools-ui-agent-schedule.ts
|
|
6375
|
-
import { z as
|
|
6527
|
+
import { z as z8 } from "zod";
|
|
6376
6528
|
var UI_AGENT_SCHEDULE_TOOL_SCOPES = {
|
|
6377
6529
|
ui_agent_schedule_create: "admin",
|
|
6378
6530
|
ui_agent_schedule_list: "read",
|
|
@@ -6410,14 +6562,14 @@ function registerScheduleAndUsageTools(server2, ctx, runtime) {
|
|
|
6410
6562
|
title: "Create UI Agent Schedule",
|
|
6411
6563
|
description: "Creates a recurring browser-agent run on a cron schedule, to automate periodic OCS audits, fleet health checks, or any recurring browser-automation task. Minimum interval: 5 minutes. Requires admin scope." + STDIO_NOTE,
|
|
6412
6564
|
inputSchema: {
|
|
6413
|
-
name:
|
|
6414
|
-
cron:
|
|
6565
|
+
name: z8.string().describe("Human-readable name for this schedule"),
|
|
6566
|
+
cron: z8.string().describe(
|
|
6415
6567
|
"Standard 5-field cron expression (minute hour day month weekday). Minimum interval: 5 minutes. Example: '0 */6 * * *' = every 6 hours."
|
|
6416
6568
|
),
|
|
6417
|
-
prompt_template:
|
|
6569
|
+
prompt_template: z8.string().describe(
|
|
6418
6570
|
"Agent prompt/task template the browser agent will execute on each run"
|
|
6419
6571
|
),
|
|
6420
|
-
profile:
|
|
6572
|
+
profile: z8.string().optional().describe(
|
|
6421
6573
|
"Browser-agent profile to use. Defaults to the deployment's configured profile."
|
|
6422
6574
|
)
|
|
6423
6575
|
}
|
|
@@ -6439,7 +6591,7 @@ function registerScheduleAndUsageTools(server2, ctx, runtime) {
|
|
|
6439
6591
|
title: "Delete UI Agent Schedule",
|
|
6440
6592
|
description: "Permanently deletes a recurring browser-agent schedule. This cannot be undone. Use ui_agent_schedule_pause to temporarily suspend instead. Requires admin scope." + STDIO_NOTE,
|
|
6441
6593
|
inputSchema: {
|
|
6442
|
-
schedule_id:
|
|
6594
|
+
schedule_id: z8.string().describe("ID of the schedule to delete")
|
|
6443
6595
|
}
|
|
6444
6596
|
},
|
|
6445
6597
|
async () => !ctx.props.scope.includes("admin") ? scopeDenied(ctx, "ui_agent_schedule_delete", "admin") : uiAgentStubError("ui_agent_schedule_delete", "recurring_runtime")
|
|
@@ -6450,7 +6602,7 @@ function registerScheduleAndUsageTools(server2, ctx, runtime) {
|
|
|
6450
6602
|
title: "Pause UI Agent Schedule",
|
|
6451
6603
|
description: "Pauses an active recurring browser-agent schedule. The schedule is preserved and can be resumed later with ui_agent_schedule_resume. Requires admin scope." + STDIO_NOTE,
|
|
6452
6604
|
inputSchema: {
|
|
6453
|
-
schedule_id:
|
|
6605
|
+
schedule_id: z8.string().describe("ID of the schedule to pause")
|
|
6454
6606
|
}
|
|
6455
6607
|
},
|
|
6456
6608
|
async () => !ctx.props.scope.includes("admin") ? scopeDenied(ctx, "ui_agent_schedule_pause", "admin") : uiAgentStubError("ui_agent_schedule_pause", "recurring_runtime")
|
|
@@ -6461,7 +6613,7 @@ function registerScheduleAndUsageTools(server2, ctx, runtime) {
|
|
|
6461
6613
|
title: "Resume UI Agent Schedule",
|
|
6462
6614
|
description: "Resumes a paused recurring browser-agent schedule. Requires admin scope." + STDIO_NOTE,
|
|
6463
6615
|
inputSchema: {
|
|
6464
|
-
schedule_id:
|
|
6616
|
+
schedule_id: z8.string().describe("ID of the schedule to resume")
|
|
6465
6617
|
}
|
|
6466
6618
|
},
|
|
6467
6619
|
async () => !ctx.props.scope.includes("admin") ? scopeDenied(ctx, "ui_agent_schedule_resume", "admin") : uiAgentStubError("ui_agent_schedule_resume", "recurring_runtime")
|
|
@@ -6518,7 +6670,7 @@ function registerScheduleAndUsageTools(server2, ctx, runtime) {
|
|
|
6518
6670
|
}
|
|
6519
6671
|
|
|
6520
6672
|
// src/wallet-tools.ts
|
|
6521
|
-
import { z as
|
|
6673
|
+
import { z as z9 } from "zod";
|
|
6522
6674
|
import * as Sentry2 from "@sentry/cloudflare";
|
|
6523
6675
|
|
|
6524
6676
|
// src/audit-schema.ts
|
|
@@ -6846,15 +6998,15 @@ async function createTopupCheckout(env, args) {
|
|
|
6846
6998
|
} else {
|
|
6847
6999
|
params.set("customer_creation", "always");
|
|
6848
7000
|
}
|
|
6849
|
-
const
|
|
7001
|
+
const result3 = await stripePostForm(
|
|
6850
7002
|
stripeKey,
|
|
6851
7003
|
"/v1/checkout/sessions",
|
|
6852
7004
|
params
|
|
6853
7005
|
);
|
|
6854
|
-
if (!
|
|
6855
|
-
throw new Error(`Stripe checkout session create failed: ${JSON.stringify(
|
|
7006
|
+
if (!result3.ok) {
|
|
7007
|
+
throw new Error(`Stripe checkout session create failed: ${JSON.stringify(result3.data)}`);
|
|
6856
7008
|
}
|
|
6857
|
-
return { id:
|
|
7009
|
+
return { id: result3.data.id, url: result3.data.url };
|
|
6858
7010
|
}
|
|
6859
7011
|
async function runAutoTopup(env, args) {
|
|
6860
7012
|
const stripeKey = env.STRIPE_SECRET_KEY;
|
|
@@ -6978,13 +7130,13 @@ function registerWalletTools(server2, ctx) {
|
|
|
6978
7130
|
// — returns null here. Requiring a number turned that, the most common
|
|
6979
7131
|
// state a new operator is in, into an output validation error.
|
|
6980
7132
|
outputSchema: {
|
|
6981
|
-
org_id:
|
|
6982
|
-
balance_eur_cents:
|
|
6983
|
-
auto_topup_enabled:
|
|
6984
|
-
auto_topup_threshold_cents:
|
|
7133
|
+
org_id: z9.string().describe("Carrier organisation the wallet belongs to"),
|
|
7134
|
+
balance_eur_cents: z9.number().int().describe("Current balance in EUR cents"),
|
|
7135
|
+
auto_topup_enabled: z9.boolean(),
|
|
7136
|
+
auto_topup_threshold_cents: z9.number().int().nullable().describe(
|
|
6985
7137
|
"Balance at or below which an auto top-up fires, EUR cents. Null when auto-top-up is unconfigured."
|
|
6986
7138
|
),
|
|
6987
|
-
auto_topup_pack_cents:
|
|
7139
|
+
auto_topup_pack_cents: z9.number().int().nullable().describe(
|
|
6988
7140
|
"Amount an auto top-up charges, EUR cents. Null when auto-top-up is unconfigured."
|
|
6989
7141
|
)
|
|
6990
7142
|
},
|
|
@@ -7026,7 +7178,7 @@ function registerWalletTools(server2, ctx) {
|
|
|
7026
7178
|
title: "Wallet Top-up Checkout",
|
|
7027
7179
|
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.",
|
|
7028
7180
|
inputSchema: {
|
|
7029
|
-
pack:
|
|
7181
|
+
pack: z9.string().optional().describe(
|
|
7030
7182
|
"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."
|
|
7031
7183
|
)
|
|
7032
7184
|
},
|
|
@@ -7039,21 +7191,21 @@ function registerWalletTools(server2, ctx) {
|
|
|
7039
7191
|
* documented here. Marking either arm required would break the other.
|
|
7040
7192
|
*/
|
|
7041
7193
|
outputSchema: {
|
|
7042
|
-
packs:
|
|
7043
|
-
|
|
7044
|
-
id:
|
|
7045
|
-
eur_cents:
|
|
7046
|
-
bonus_pct:
|
|
7047
|
-
bonus_eur_cents:
|
|
7048
|
-
credited_eur_cents:
|
|
7194
|
+
packs: z9.array(
|
|
7195
|
+
z9.object({
|
|
7196
|
+
id: z9.string(),
|
|
7197
|
+
eur_cents: z9.number().int(),
|
|
7198
|
+
bonus_pct: z9.number(),
|
|
7199
|
+
bonus_eur_cents: z9.number().int(),
|
|
7200
|
+
credited_eur_cents: z9.number().int()
|
|
7049
7201
|
})
|
|
7050
7202
|
).optional().describe("Catalogue arm \u2014 present only when `pack` was omitted."),
|
|
7051
|
-
org_id:
|
|
7052
|
-
pack_id:
|
|
7053
|
-
pack_eur_cents:
|
|
7054
|
-
bonus_eur_cents:
|
|
7055
|
-
checkout_session_id:
|
|
7056
|
-
checkout_url:
|
|
7203
|
+
org_id: z9.string().optional().describe("Session arm."),
|
|
7204
|
+
pack_id: z9.string().optional().describe("Session arm."),
|
|
7205
|
+
pack_eur_cents: z9.number().int().optional().describe("Session arm."),
|
|
7206
|
+
bonus_eur_cents: z9.number().int().optional().describe("Session arm."),
|
|
7207
|
+
checkout_session_id: z9.string().optional().describe("Session arm."),
|
|
7208
|
+
checkout_url: z9.string().nullable().optional().describe("Session arm. Stripe may return null for a session URL.")
|
|
7057
7209
|
},
|
|
7058
7210
|
annotations: annotationsFor("wallet_topup_checkout", "write")
|
|
7059
7211
|
},
|
|
@@ -7110,7 +7262,7 @@ function registerWalletTools(server2, ctx) {
|
|
|
7110
7262
|
title: "Wallet Auto Top-up (charges card now)",
|
|
7111
7263
|
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`.",
|
|
7112
7264
|
inputSchema: {
|
|
7113
|
-
pack_cents:
|
|
7265
|
+
pack_cents: z9.number().int().positive().optional().describe("Override pack amount in EUR cents (must match a catalog pack).")
|
|
7114
7266
|
},
|
|
7115
7267
|
/**
|
|
7116
7268
|
* Only the charged arm is described here — `charged: false` returns
|
|
@@ -7125,12 +7277,12 @@ function registerWalletTools(server2, ctx) {
|
|
|
7125
7277
|
* into a validation error.
|
|
7126
7278
|
*/
|
|
7127
7279
|
outputSchema: {
|
|
7128
|
-
org_id:
|
|
7129
|
-
charged:
|
|
7130
|
-
credited_eur_cents:
|
|
7131
|
-
balance_after_cents:
|
|
7132
|
-
payment_intent_id:
|
|
7133
|
-
note:
|
|
7280
|
+
org_id: z9.string(),
|
|
7281
|
+
charged: z9.literal(true),
|
|
7282
|
+
credited_eur_cents: z9.number().int(),
|
|
7283
|
+
balance_after_cents: z9.number().int().optional().describe("Absent when the charge succeeded but crediting is pending."),
|
|
7284
|
+
payment_intent_id: z9.string().optional(),
|
|
7285
|
+
note: z9.string().optional().describe("Present when the charge landed but the credit is still pending.")
|
|
7134
7286
|
},
|
|
7135
7287
|
annotations: annotationsFor("wallet_auto_topup", "write")
|
|
7136
7288
|
},
|
|
@@ -7140,32 +7292,32 @@ function registerWalletTools(server2, ctx) {
|
|
|
7140
7292
|
const orgId = defaultOrgId;
|
|
7141
7293
|
const start = Date.now();
|
|
7142
7294
|
try {
|
|
7143
|
-
const
|
|
7295
|
+
const result3 = await runAutoTopup(env, { orgId, sub: props2.sub, packCents: pack_cents });
|
|
7144
7296
|
writeAudit(env, {
|
|
7145
7297
|
tool_name: "wallet_auto_topup",
|
|
7146
7298
|
ocs_method: "stripe.payment_intent.off_session",
|
|
7147
|
-
status:
|
|
7299
|
+
status: result3.charged ? "ok" : "error",
|
|
7148
7300
|
dry_run: false,
|
|
7149
7301
|
duration_ms: Date.now() - start,
|
|
7150
7302
|
sub: props2.sub,
|
|
7151
7303
|
reseller_id: props2.reseller_id
|
|
7152
7304
|
});
|
|
7153
|
-
if (!
|
|
7305
|
+
if (!result3.charged) {
|
|
7154
7306
|
return err(
|
|
7155
|
-
JSON.stringify({ org_id: orgId, charged: false, reason:
|
|
7307
|
+
JSON.stringify({ org_id: orgId, charged: false, reason: result3.reason })
|
|
7156
7308
|
);
|
|
7157
7309
|
}
|
|
7158
7310
|
return okStructured({
|
|
7159
7311
|
org_id: orgId,
|
|
7160
7312
|
charged: true,
|
|
7161
|
-
credited_eur_cents:
|
|
7313
|
+
credited_eur_cents: result3.creditedCents,
|
|
7162
7314
|
// Spread rather than assign, so the key is absent instead of set to
|
|
7163
7315
|
// `undefined`. JSON.stringify drops an undefined value anyway, so
|
|
7164
7316
|
// assigning it would make `content` and `structuredContent` disagree
|
|
7165
7317
|
// about whether the field is there.
|
|
7166
|
-
...
|
|
7167
|
-
...
|
|
7168
|
-
...
|
|
7318
|
+
...result3.balanceAfterCents !== void 0 ? { balance_after_cents: result3.balanceAfterCents } : {},
|
|
7319
|
+
...result3.paymentIntentId !== void 0 ? { payment_intent_id: result3.paymentIntentId } : {},
|
|
7320
|
+
...result3.reason ? { note: result3.reason } : {}
|
|
7169
7321
|
});
|
|
7170
7322
|
} catch (e) {
|
|
7171
7323
|
Sentry2.captureException(e);
|
|
@@ -7176,7 +7328,7 @@ function registerWalletTools(server2, ctx) {
|
|
|
7176
7328
|
}
|
|
7177
7329
|
|
|
7178
7330
|
// src/stripe-connect-tools.ts
|
|
7179
|
-
import { z as
|
|
7331
|
+
import { z as z10 } from "zod";
|
|
7180
7332
|
import * as Sentry3 from "@sentry/cloudflare";
|
|
7181
7333
|
|
|
7182
7334
|
// src/binding-unavailable.ts
|
|
@@ -7332,7 +7484,7 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7332
7484
|
title: "Stripe Connect Status",
|
|
7333
7485
|
description: "Read-only: returns the Stripe Connect account status, capabilities, and requirements for the authenticated operator.",
|
|
7334
7486
|
inputSchema: {
|
|
7335
|
-
operator_id:
|
|
7487
|
+
operator_id: z10.string().optional().describe("Override operator_id (admin use). Defaults to caller's org/user.")
|
|
7336
7488
|
},
|
|
7337
7489
|
annotations: annotationsFor("stripe_connect_status", "read")
|
|
7338
7490
|
},
|
|
@@ -7356,9 +7508,9 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7356
7508
|
if (!accountId) {
|
|
7357
7509
|
return ok(JSON.stringify({ status: "not_connected", operator_id: opId }));
|
|
7358
7510
|
}
|
|
7359
|
-
const
|
|
7360
|
-
if (!
|
|
7361
|
-
const a =
|
|
7511
|
+
const result3 = await stripeGet(stripeKey, `/v1/accounts/${accountId}`);
|
|
7512
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7513
|
+
const a = result3.data;
|
|
7362
7514
|
const status = a.charges_enabled && a.details_submitted ? "active" : "pending";
|
|
7363
7515
|
writeAudit(env, {
|
|
7364
7516
|
tool_name: "stripe_connect_status",
|
|
@@ -7393,8 +7545,8 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7393
7545
|
title: "List Stripe Payouts",
|
|
7394
7546
|
description: "List money Stripe has already sent from the operator's connected account to their bank, newest first. Read-only. Params: `limit` (1-50, default 10), `status` (optional Stripe payout status, e.g. 'paid', 'pending', 'failed'). Returns: { payouts: [{ id, amount, currency, status, arrival_date, automatic, created }], has_more } \u2014 amount in the currency's smallest unit. Do NOT use this for money still sitting at Stripe and not yet paid out \u2014 use `stripe_connect_balance`.",
|
|
7395
7547
|
inputSchema: {
|
|
7396
|
-
limit:
|
|
7397
|
-
status:
|
|
7548
|
+
limit: z10.number().int().min(1).max(50).default(10).describe("Number of payouts to return."),
|
|
7549
|
+
status: z10.enum(["pending", "paid", "failed", "canceled", "in_transit"]).optional().describe("Filter by payout status.")
|
|
7398
7550
|
},
|
|
7399
7551
|
annotations: annotationsFor("stripe_connect_payouts", "read")
|
|
7400
7552
|
},
|
|
@@ -7409,8 +7561,8 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7409
7561
|
if (!accountId) return err2("No connected Stripe account found.");
|
|
7410
7562
|
const params = new URLSearchParams({ limit: String(limit) });
|
|
7411
7563
|
if (status) params.set("status", status);
|
|
7412
|
-
const
|
|
7413
|
-
if (!
|
|
7564
|
+
const result3 = await stripeGet(stripeKey, `/v1/payouts?${params.toString()}`, accountId);
|
|
7565
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7414
7566
|
writeAudit(env, {
|
|
7415
7567
|
tool_name: "stripe_connect_payouts",
|
|
7416
7568
|
ocs_method: "stripe.payouts.list",
|
|
@@ -7420,7 +7572,7 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7420
7572
|
sub: props2.sub,
|
|
7421
7573
|
reseller_id: props2.reseller_id
|
|
7422
7574
|
});
|
|
7423
|
-
return ok(JSON.stringify({ payouts:
|
|
7575
|
+
return ok(JSON.stringify({ payouts: result3.data.data, has_more: result3.data.has_more }));
|
|
7424
7576
|
} catch (e) {
|
|
7425
7577
|
Sentry3.captureException(e);
|
|
7426
7578
|
return err2(`Error: ${e instanceof Error ? e.message : "unknown"}`);
|
|
@@ -7433,8 +7585,8 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7433
7585
|
title: "Stripe Connect Charges",
|
|
7434
7586
|
description: "List recent payments (charges) on the operator's connected Stripe account, e.g. storefront purchases. Read-only. Params: limit (1-100), starting_after (charge id for paging). Returns: { charges: [{ id, amount, amount_refunded, currency, status, paid, captured, refunded, created, payment_intent, payment_method_type, metadata }], has_more }. Do NOT use this for payouts to the bank \u2014 use `stripe_connect_payouts`.",
|
|
7435
7587
|
inputSchema: {
|
|
7436
|
-
limit:
|
|
7437
|
-
starting_after:
|
|
7588
|
+
limit: z10.number().int().min(1).max(100).default(20).describe("Number of charges to return."),
|
|
7589
|
+
starting_after: z10.string().regex(/^(ch|py)_[A-Za-z0-9]+$/).optional().describe("Charge id to page after.")
|
|
7438
7590
|
},
|
|
7439
7591
|
annotations: annotationsFor("stripe_connect_charges_list", "read")
|
|
7440
7592
|
},
|
|
@@ -7449,12 +7601,12 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7449
7601
|
if (!accountId) return err2("No connected Stripe account found.");
|
|
7450
7602
|
const params = new URLSearchParams({ limit: String(limit) });
|
|
7451
7603
|
if (starting_after) params.set("starting_after", starting_after);
|
|
7452
|
-
const
|
|
7604
|
+
const result3 = await stripeGet(
|
|
7453
7605
|
stripeKey,
|
|
7454
7606
|
`/v1/charges?${params.toString()}`,
|
|
7455
7607
|
accountId
|
|
7456
7608
|
);
|
|
7457
|
-
if (!
|
|
7609
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7458
7610
|
writeAudit(env, {
|
|
7459
7611
|
tool_name: "stripe_connect_charges_list",
|
|
7460
7612
|
ocs_method: "stripe.charges.list",
|
|
@@ -7464,7 +7616,7 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7464
7616
|
sub: props2.sub,
|
|
7465
7617
|
reseller_id: props2.reseller_id
|
|
7466
7618
|
});
|
|
7467
|
-
const charges = (
|
|
7619
|
+
const charges = (result3.data.data ?? []).map((ch) => ({
|
|
7468
7620
|
id: ch["id"],
|
|
7469
7621
|
amount: ch["amount"],
|
|
7470
7622
|
amount_refunded: ch["amount_refunded"],
|
|
@@ -7478,7 +7630,7 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7478
7630
|
payment_method_type: ch["payment_method_details"]?.type ?? null,
|
|
7479
7631
|
metadata: ch["metadata"]
|
|
7480
7632
|
}));
|
|
7481
|
-
return ok(JSON.stringify({ charges, has_more:
|
|
7633
|
+
return ok(JSON.stringify({ charges, has_more: result3.data.has_more }));
|
|
7482
7634
|
} catch (e) {
|
|
7483
7635
|
Sentry3.captureException(e);
|
|
7484
7636
|
return err2(`stripe_connect_charges_list failed: ${e instanceof Error ? e.message : String(e)}`);
|
|
@@ -7502,8 +7654,8 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7502
7654
|
if (!stripeKey) return err2("Stripe not configured");
|
|
7503
7655
|
const accountId = await getAccountId();
|
|
7504
7656
|
if (!accountId) return err2("No connected Stripe account found.");
|
|
7505
|
-
const
|
|
7506
|
-
if (!
|
|
7657
|
+
const result3 = await stripeGet(stripeKey, `/v1/balance`, accountId);
|
|
7658
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7507
7659
|
writeAudit(env, {
|
|
7508
7660
|
tool_name: "stripe_connect_balance",
|
|
7509
7661
|
ocs_method: "stripe.balance.read",
|
|
@@ -7515,8 +7667,8 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7515
7667
|
});
|
|
7516
7668
|
return ok(JSON.stringify({
|
|
7517
7669
|
account_id: accountId,
|
|
7518
|
-
available:
|
|
7519
|
-
pending:
|
|
7670
|
+
available: result3.data.available ?? [],
|
|
7671
|
+
pending: result3.data.pending ?? []
|
|
7520
7672
|
}));
|
|
7521
7673
|
} catch (e) {
|
|
7522
7674
|
Sentry3.captureException(e);
|
|
@@ -7530,10 +7682,10 @@ function registerStripeConnectTools(server2, ctx) {
|
|
|
7530
7682
|
title: "Refund a Charge (moves real money)",
|
|
7531
7683
|
description: "Refund money to a customer on one charge in the operator's connected Stripe account. This returns real funds and Stripe cannot reverse a refund once issued. Two-step by design: call without `confirm_token` to get a token and a summary of what would be refunded, then call again with that token to execute. The token expires in 5 minutes. Params: `charge_id` (Stripe charge id, `ch_...`), `amount_cents` (optional integer in the charge's smallest currency unit \u2014 omit for a full refund), `reason` ('duplicate' | 'fraudulent' | 'requested_by_customer', optional), `confirm_token`. Returns: the refund id and status. Requires `write` scope. Do NOT use this on a payment that was authorized but not captured \u2014 cancel its PaymentIntent instead (Stripe POST /v1/payment_intents/:id/cancel). Do NOT use this to contest a chargeback \u2014 read the case with `stripe_connect_dispute_list` first, since refunding a disputed charge can cost the operator twice.",
|
|
7532
7684
|
inputSchema: {
|
|
7533
|
-
charge_id:
|
|
7534
|
-
amount_cents:
|
|
7535
|
-
reason:
|
|
7536
|
-
confirm_token:
|
|
7685
|
+
charge_id: z10.string().min(1).describe("Stripe charge ID (ch_...)."),
|
|
7686
|
+
amount_cents: z10.number().int().min(1).optional().describe("Partial refund amount in cents. Omit for full refund."),
|
|
7687
|
+
reason: z10.enum(["duplicate", "fraudulent", "requested_by_customer"]).optional(),
|
|
7688
|
+
confirm_token: z10.string().optional().describe("Confirmation token from previous call. Required to execute.")
|
|
7537
7689
|
},
|
|
7538
7690
|
annotations: annotationsFor("stripe_connect_refund", "write")
|
|
7539
7691
|
},
|
|
@@ -7562,14 +7714,14 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7562
7714
|
const params = { charge: charge_id };
|
|
7563
7715
|
if (amount_cents) params.amount = String(amount_cents);
|
|
7564
7716
|
if (reason) params.reason = reason;
|
|
7565
|
-
const
|
|
7717
|
+
const result3 = await stripePost(
|
|
7566
7718
|
stripeKey,
|
|
7567
7719
|
"/v1/refunds",
|
|
7568
7720
|
params,
|
|
7569
7721
|
accountId,
|
|
7570
7722
|
refundIdempotencyKey(props2.sub, charge_id, amount_cents, reason)
|
|
7571
7723
|
);
|
|
7572
|
-
if (!
|
|
7724
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7573
7725
|
writeAudit(env, {
|
|
7574
7726
|
tool_name: toolName,
|
|
7575
7727
|
ocs_method: "stripe.refund.create",
|
|
@@ -7579,7 +7731,7 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7579
7731
|
sub: props2.sub,
|
|
7580
7732
|
reseller_id: props2.reseller_id
|
|
7581
7733
|
});
|
|
7582
|
-
return ok(`Refund issued: ${
|
|
7734
|
+
return ok(`Refund issued: ${result3.data.id} \u2014 status: ${result3.data.status}`);
|
|
7583
7735
|
} catch (e) {
|
|
7584
7736
|
Sentry3.captureException(e);
|
|
7585
7737
|
return err2(`Error: ${e instanceof Error ? e.message : "unknown"}`);
|
|
@@ -7592,8 +7744,8 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7592
7744
|
title: "List Chargeback Disputes",
|
|
7593
7745
|
description: "List chargebacks customers have raised with their bank against the operator's connected Stripe account. Read-only \u2014 responding to one is Dashboard work. Params: `limit` (1-50, default 10), `status` (optional Stripe dispute status, e.g. 'needs_response', 'under_review'). Returns: { disputes: [{ id, charge, amount, currency, status, reason, evidence_details.due_by }], has_more } \u2014 amount in the currency's smallest unit, `due_by` a Unix timestamp or null. Do NOT use this for charges Stripe is holding for fraud review before they settle \u2014 those are `radar_review_list`. Check this before refunding: refunding a disputed charge can cost the operator the amount twice.",
|
|
7594
7746
|
inputSchema: {
|
|
7595
|
-
limit:
|
|
7596
|
-
status:
|
|
7747
|
+
limit: z10.number().int().min(1).max(50).default(10),
|
|
7748
|
+
status: z10.string().optional().describe("Filter by dispute status (e.g. needs_response, under_review).")
|
|
7597
7749
|
},
|
|
7598
7750
|
annotations: annotationsFor("stripe_connect_dispute_list", "read")
|
|
7599
7751
|
},
|
|
@@ -7608,8 +7760,8 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7608
7760
|
if (!accountId) return err2("No connected Stripe account found.");
|
|
7609
7761
|
const params = new URLSearchParams({ limit: String(limit) });
|
|
7610
7762
|
if (status) params.set("status", status);
|
|
7611
|
-
const
|
|
7612
|
-
if (!
|
|
7763
|
+
const result3 = await stripeGet(stripeKey, `/v1/disputes?${params.toString()}`, accountId);
|
|
7764
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7613
7765
|
writeAudit(env, {
|
|
7614
7766
|
tool_name: "stripe_connect_dispute_list",
|
|
7615
7767
|
ocs_method: "stripe.disputes.list",
|
|
@@ -7619,7 +7771,7 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7619
7771
|
sub: props2.sub,
|
|
7620
7772
|
reseller_id: props2.reseller_id
|
|
7621
7773
|
});
|
|
7622
|
-
return ok(JSON.stringify({ disputes:
|
|
7774
|
+
return ok(JSON.stringify({ disputes: result3.data.data, has_more: result3.data.has_more }));
|
|
7623
7775
|
} catch (e) {
|
|
7624
7776
|
Sentry3.captureException(e);
|
|
7625
7777
|
return err2(`Error: ${e instanceof Error ? e.message : "unknown"}`);
|
|
@@ -7632,8 +7784,8 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7632
7784
|
title: "List Radar Fraud Reviews",
|
|
7633
7785
|
description: "List the Stripe Radar fraud reviews waiting on a manual approve/decline decision, newest first. Reads only \u2014 deciding a review is a separate call. Params: `open_only` (boolean, default true; Stripe lists open reviews only, so false returns the same set), `limit` (1-50, default 10). Returns: { reviews: [{ id (`prv_...`), charge, reason, opened_reason, closed_reason, created, closed }], has_more }. Call this first to get the `review_id` that `radar_review_approve` and `radar_review_decline` require. Do NOT use this for chargebacks the customer has already raised with their bank \u2014 use `stripe_connect_dispute_list`.",
|
|
7634
7786
|
inputSchema: {
|
|
7635
|
-
open_only:
|
|
7636
|
-
limit:
|
|
7787
|
+
open_only: z10.boolean().default(true).describe("Stripe lists only open (undecided) reviews; kept for compatibility."),
|
|
7788
|
+
limit: z10.number().int().min(1).max(50).default(10)
|
|
7637
7789
|
},
|
|
7638
7790
|
annotations: annotationsFor("radar_review_list", "read")
|
|
7639
7791
|
},
|
|
@@ -7650,9 +7802,9 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7650
7802
|
const stripeKey = env.STRIPE_ORG_SECRET_KEY ?? env.STRIPE_SECRET_KEY;
|
|
7651
7803
|
if (!stripeKey) return err2("Stripe not configured");
|
|
7652
7804
|
const params = new URLSearchParams({ limit: String(limit) });
|
|
7653
|
-
const
|
|
7654
|
-
if (!
|
|
7655
|
-
const reviews = open_only ?
|
|
7805
|
+
const result3 = await stripeGet(stripeKey, `/v1/reviews?${params.toString()}`);
|
|
7806
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7807
|
+
const reviews = open_only ? result3.data.data.filter((r) => r.open !== false) : result3.data.data;
|
|
7656
7808
|
writeAudit(env, {
|
|
7657
7809
|
tool_name: "radar_review_list",
|
|
7658
7810
|
ocs_method: "stripe.radar.reviews.list",
|
|
@@ -7662,7 +7814,7 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7662
7814
|
sub: props2.sub,
|
|
7663
7815
|
reseller_id: props2.reseller_id
|
|
7664
7816
|
});
|
|
7665
|
-
return ok(JSON.stringify({ reviews, has_more:
|
|
7817
|
+
return ok(JSON.stringify({ reviews, has_more: result3.data.has_more }));
|
|
7666
7818
|
} catch (e) {
|
|
7667
7819
|
Sentry3.captureException(e);
|
|
7668
7820
|
return err2(`Error: ${e instanceof Error ? e.message : "unknown"}`);
|
|
@@ -7675,8 +7827,8 @@ Call again with confirm_token="${token2}" to execute. Token expires in 5 minutes
|
|
|
7675
7827
|
title: "Approve Radar Review (captures charge)",
|
|
7676
7828
|
description: "Clear a Stripe Radar fraud review so the held charge is captured and the money is taken. Approving overrides Radar's fraud signal, so a genuinely fraudulent charge approved here usually returns later as a chargeback plus a fee. Two-step by design: call without `confirm_token` to get a token, then call again with it to execute. Params: `review_id` (`prv_...`, from `radar_review_list`), `confirm_token`. Requires `admin` scope. Do NOT call this to turn a suspicious charge away \u2014 Stripe has no review decline; refund the charge (`stripe_connect_refund`) or cancel an uncaptured PaymentIntent. Do NOT call this to return money on a charge that already went through \u2014 that is `stripe_connect_refund`.",
|
|
7677
7829
|
inputSchema: {
|
|
7678
|
-
review_id:
|
|
7679
|
-
confirm_token:
|
|
7830
|
+
review_id: z10.string().min(1).describe("Stripe Radar review ID (prv_...)."),
|
|
7831
|
+
confirm_token: z10.string().optional()
|
|
7680
7832
|
},
|
|
7681
7833
|
annotations: annotationsFor("radar_review_approve", "admin")
|
|
7682
7834
|
},
|
|
@@ -7703,13 +7855,13 @@ Call again with confirm_token="${token2}" to execute. Expires in 5 minutes.`
|
|
|
7703
7855
|
try {
|
|
7704
7856
|
const stripeKey = env.STRIPE_ORG_SECRET_KEY ?? env.STRIPE_SECRET_KEY;
|
|
7705
7857
|
if (!stripeKey) return err2("Stripe not configured");
|
|
7706
|
-
const
|
|
7858
|
+
const result3 = await stripePost(
|
|
7707
7859
|
stripeKey,
|
|
7708
7860
|
// POST /v1/reviews/:id/approve (docs.stripe.com/api/radar/reviews/approve).
|
|
7709
7861
|
`/v1/reviews/${encodeURIComponent(review_id)}/approve`,
|
|
7710
7862
|
{}
|
|
7711
7863
|
);
|
|
7712
|
-
if (!
|
|
7864
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7713
7865
|
writeAudit(env, {
|
|
7714
7866
|
tool_name: toolName,
|
|
7715
7867
|
ocs_method: "stripe.radar.review.approve",
|
|
@@ -7732,8 +7884,8 @@ Call again with confirm_token="${token2}" to execute. Expires in 5 minutes.`
|
|
|
7732
7884
|
title: "Decline Radar Review (not supported by Stripe)",
|
|
7733
7885
|
description: "Always refuses and calls nothing: Stripe has no endpoint to decline a Radar review (its Reviews API only lists, retrieves and approves). Payments in review have usually already been processed. To turn one away, refund the charge on Carrier's platform account in Stripe itself (Dashboard, or platform-scoped POST /v1/refunds with no Stripe-Account header): `stripe_connect_refund` always acts as the operator's connected account, so it will NOT find a platform charge from this review list. or, for a payment authorized but not captured, cancel its PaymentIntent (Stripe POST /v1/payment_intents/:id/cancel); either closes the review. Params: `review_id` (`prv_...`), `confirm_token` (ignored). Requires `admin` scope. Do NOT call this expecting a charge to be blocked; nothing happens.",
|
|
7734
7886
|
inputSchema: {
|
|
7735
|
-
review_id:
|
|
7736
|
-
confirm_token:
|
|
7887
|
+
review_id: z10.string().min(1),
|
|
7888
|
+
confirm_token: z10.string().optional()
|
|
7737
7889
|
},
|
|
7738
7890
|
annotations: annotationsFor("radar_review_decline", "admin")
|
|
7739
7891
|
},
|
|
@@ -7754,9 +7906,9 @@ Call again with confirm_token="${token2}" to execute. Expires in 5 minutes.`
|
|
|
7754
7906
|
title: "Add Value to Radar List",
|
|
7755
7907
|
description: "Add one value to an existing Stripe Radar value list, changing how every future charge is scored. Whether the value ends up blocked or allowed depends entirely on which list you name in `value_list_id` \u2014 this tool does not choose, and putting a value on the allow list when you meant the block list silently lets fraud through. Confirm the list's purpose before calling. Two-step by design: call without `confirm_token` to get a token, then call again with it to execute. Params: `value_list_id` (`rsl_...`, an existing list), `value` (one email, IP address, card fingerprint, or ISO country code \u2014 one item per call), `confirm_token`. Requires `admin` scope. Do NOT use this to decide a single charge that is already under review \u2014 use `radar_review_approve` or `radar_review_decline`. Do NOT use this to create a list or a rule: only `value` is added, and rules cannot be edited through this API at all (see `radar_rule_toggle`).",
|
|
7756
7908
|
inputSchema: {
|
|
7757
|
-
value_list_id:
|
|
7758
|
-
value:
|
|
7759
|
-
confirm_token:
|
|
7909
|
+
value_list_id: z10.string().min(1).describe("Stripe Radar value list ID (rsl_...)."),
|
|
7910
|
+
value: z10.string().min(1).describe("The value to add (email, IP address, country code, etc.)."),
|
|
7911
|
+
confirm_token: z10.string().optional()
|
|
7760
7912
|
},
|
|
7761
7913
|
annotations: annotationsFor("radar_value_list_add", "admin")
|
|
7762
7914
|
},
|
|
@@ -7783,12 +7935,12 @@ Expires in 5 minutes.`
|
|
|
7783
7935
|
try {
|
|
7784
7936
|
const stripeKey = env.STRIPE_ORG_SECRET_KEY ?? env.STRIPE_SECRET_KEY;
|
|
7785
7937
|
if (!stripeKey) return err2("Stripe not configured");
|
|
7786
|
-
const
|
|
7938
|
+
const result3 = await stripePost(
|
|
7787
7939
|
stripeKey,
|
|
7788
7940
|
"/v1/radar/value_list_items",
|
|
7789
7941
|
{ value_list: value_list_id, value }
|
|
7790
7942
|
);
|
|
7791
|
-
if (!
|
|
7943
|
+
if (!result3.ok) return err2(`Stripe error: ${JSON.stringify(result3.data)}`);
|
|
7792
7944
|
writeAudit(env, {
|
|
7793
7945
|
tool_name: toolName,
|
|
7794
7946
|
ocs_method: "stripe.radar.value_list.add",
|
|
@@ -7811,8 +7963,8 @@ Expires in 5 minutes.`
|
|
|
7811
7963
|
title: "Radar Rule Toggle (instructions only)",
|
|
7812
7964
|
description: "Return the Stripe Dashboard steps for enabling or disabling a Radar rule. This tool changes nothing: Stripe has no public API for rule state, so the call always succeeds and the rule stays exactly as it was. Never report the rule as toggled. Params: `rule_id` (Stripe Radar rule id), `enabled` (true for the enable instructions, false for disable). Returns: the Dashboard URL and steps for a human to follow. Requires `admin` scope. Do NOT use this when a change must actually take effect from an agent \u2014 the only Radar state reachable through this API is value-list membership, via `radar_value_list_add`.",
|
|
7813
7965
|
inputSchema: {
|
|
7814
|
-
rule_id:
|
|
7815
|
-
enabled:
|
|
7966
|
+
rule_id: z10.string().min(1).describe("Stripe Radar rule ID."),
|
|
7967
|
+
enabled: z10.boolean().describe("true = enable, false = disable.")
|
|
7816
7968
|
},
|
|
7817
7969
|
annotations: annotationsFor("radar_rule_toggle", "admin")
|
|
7818
7970
|
},
|
|
@@ -7837,7 +7989,7 @@ Note: If you need this automated, use the Radar for Platforms beta \u2014 contac
|
|
|
7837
7989
|
}
|
|
7838
7990
|
|
|
7839
7991
|
// src/tools-storefront-logo.ts
|
|
7840
|
-
import { z as
|
|
7992
|
+
import { z as z11 } from "zod";
|
|
7841
7993
|
var STOREFRONT_LOGO_TOOL_SCOPES = {
|
|
7842
7994
|
generate_storefront_logo: "read"
|
|
7843
7995
|
};
|
|
@@ -7850,9 +8002,9 @@ function registerStorefrontLogoTools(server2, env = {}, props2) {
|
|
|
7850
8002
|
title: "Generate Storefront Logo",
|
|
7851
8003
|
description: "Generate a storefront logo (SVG always; PNG when an image key is configured on the Carrier worker). Works for any authenticated Carrier MCP user \u2014 no local image-API key required. Write the SVG to public/brand/logo.svg in the storefront.",
|
|
7852
8004
|
inputSchema: {
|
|
7853
|
-
name:
|
|
7854
|
-
accent:
|
|
7855
|
-
tagline:
|
|
8005
|
+
name: z11.string().min(1).describe("Brand / shop name, e.g. Bananas"),
|
|
8006
|
+
accent: z11.string().regex(/^#?[0-9A-Fa-f]{6}$/).optional().describe("Accent hex, e.g. #FF8A00"),
|
|
8007
|
+
tagline: z11.string().optional().describe("Optional tagline for AI-enhanced marks")
|
|
7856
8008
|
},
|
|
7857
8009
|
annotations: annotationsFor("generate_storefront_logo", "read")
|
|
7858
8010
|
},
|
|
@@ -7886,7 +8038,7 @@ function registerStorefrontLogoTools(server2, env = {}, props2) {
|
|
|
7886
8038
|
}
|
|
7887
8039
|
|
|
7888
8040
|
// src/tools-storefront-deploy.ts
|
|
7889
|
-
import { z as
|
|
8041
|
+
import { z as z12 } from "zod";
|
|
7890
8042
|
var STOREFRONT_DEPLOY_TOOL_SCOPES = {
|
|
7891
8043
|
list_deploy_targets: "read",
|
|
7892
8044
|
deploy_storefront: "write",
|
|
@@ -7903,7 +8055,7 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
7903
8055
|
title: "List Deploy Targets",
|
|
7904
8056
|
description: "Report which storefront deploy hosts (Cloudflare, Vercel, Netlify, Fly) are installed, logged in, and ready on this machine, and which one a deploy would pick.",
|
|
7905
8057
|
inputSchema: {
|
|
7906
|
-
dir:
|
|
8058
|
+
dir: z12.string().min(1).describe("Path to the scaffolded storefront directory")
|
|
7907
8059
|
},
|
|
7908
8060
|
annotations: annotationsFor("list_deploy_targets", "read")
|
|
7909
8061
|
},
|
|
@@ -7929,17 +8081,17 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
7929
8081
|
title: "Deploy Storefront",
|
|
7930
8082
|
description: "Build and deploy a scaffolded storefront to whichever host is available on this machine, then push its runtime secrets (CARRIER_API_KEY, CLERK_SECRET_KEY) to that host.",
|
|
7931
8083
|
inputSchema: {
|
|
7932
|
-
dir:
|
|
7933
|
-
target:
|
|
7934
|
-
name:
|
|
7935
|
-
force:
|
|
8084
|
+
dir: z12.string().min(1).describe("Path to the scaffolded storefront directory"),
|
|
8085
|
+
target: z12.enum(TARGET_IDS).optional().describe("Force a host instead of auto-detecting"),
|
|
8086
|
+
name: z12.string().optional().describe("Project/worker name (defaults from brand)"),
|
|
8087
|
+
force: z12.boolean().optional().describe(
|
|
7936
8088
|
'Acknowledge the scaffold-default-name risk: required when the resolved name is the scaffold default "storefront"'
|
|
7937
8089
|
),
|
|
7938
|
-
skip_build:
|
|
7939
|
-
push_secrets:
|
|
7940
|
-
provision_clerk:
|
|
7941
|
-
verify:
|
|
7942
|
-
domain:
|
|
8090
|
+
skip_build: z12.boolean().optional().describe("Deploy the existing build without rebuilding"),
|
|
8091
|
+
push_secrets: z12.boolean().optional().describe("Stage runtime secrets on the host before deploy (default true)"),
|
|
8092
|
+
provision_clerk: z12.boolean().optional().default(true).describe("Provision and configure Clerk automatically (default true)"),
|
|
8093
|
+
verify: z12.boolean().optional().describe("Probe the deployed URL and report whether it actually serves (default true)"),
|
|
8094
|
+
domain: z12.boolean().optional().describe("Route the brand domain to the deployment (Cloudflare provisions DNS + cert)")
|
|
7943
8095
|
},
|
|
7944
8096
|
annotations: annotationsFor("deploy_storefront", "write")
|
|
7945
8097
|
},
|
|
@@ -8003,7 +8155,7 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
8003
8155
|
const built = await buildSite(dir, buildFor);
|
|
8004
8156
|
if (!built) return err4(`Build failed for ${buildFor}. Run the build locally to see why.`);
|
|
8005
8157
|
}
|
|
8006
|
-
const
|
|
8158
|
+
const result3 = await deploySite(dir, brand, {
|
|
8007
8159
|
preferred,
|
|
8008
8160
|
pushSecrets: push_secrets !== false,
|
|
8009
8161
|
customDomain: domain === true,
|
|
@@ -8014,29 +8166,29 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
8014
8166
|
explicitName: name,
|
|
8015
8167
|
force: force === true
|
|
8016
8168
|
});
|
|
8017
|
-
if (!
|
|
8018
|
-
return err4(
|
|
8169
|
+
if (!result3.ok) {
|
|
8170
|
+
return err4(result3.reason ?? "Deploy failed.");
|
|
8019
8171
|
}
|
|
8020
|
-
if (provision_clerk !== false &&
|
|
8172
|
+
if (provision_clerk !== false && result3.url) {
|
|
8021
8173
|
const secretKey = clerkCredentials?.secretKey ?? (await discoverSecrets(dir, process.env)).CLERK_SECRET_KEY;
|
|
8022
8174
|
if (secretKey) {
|
|
8023
8175
|
const configured = await configureClerkInstance(
|
|
8024
8176
|
secretKey,
|
|
8025
|
-
storefrontClerkUrls(
|
|
8177
|
+
storefrontClerkUrls(result3.url, brand.domain)
|
|
8026
8178
|
);
|
|
8027
8179
|
clerkConfigured = configured.applied;
|
|
8028
8180
|
clerkConfigureFailures = configured.failed;
|
|
8029
8181
|
}
|
|
8030
8182
|
}
|
|
8031
|
-
const verification = verify !== false &&
|
|
8183
|
+
const verification = verify !== false && result3.url ? await verifyStorefront(result3.url, dir, process.env) : void 0;
|
|
8032
8184
|
const repairHint = skip_build && clerkEnvWritten.includes("NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY") ? "Clerk keys were written to .env.local, but the publishable key is only inlined at build time; rebuild and redeploy to apply it." : verification && !verification.ok ? repairPlanFor(verification.diagnosis)?.note ?? verification.summary : void 0;
|
|
8033
8185
|
return ok3({
|
|
8034
8186
|
deployed: true,
|
|
8035
|
-
target:
|
|
8036
|
-
project:
|
|
8037
|
-
url:
|
|
8038
|
-
secrets_staged:
|
|
8039
|
-
secrets_failed:
|
|
8187
|
+
target: result3.target,
|
|
8188
|
+
project: result3.projectName,
|
|
8189
|
+
url: result3.url ?? null,
|
|
8190
|
+
secrets_staged: result3.secrets?.pushed ?? [],
|
|
8191
|
+
secrets_failed: result3.secrets?.failed ?? [],
|
|
8040
8192
|
clerk_provisioned: clerkProvisioned,
|
|
8041
8193
|
clerk_tier: clerkTier,
|
|
8042
8194
|
clerk_configured: clerkConfigured.length,
|
|
@@ -8046,7 +8198,7 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
8046
8198
|
diagnosis: verification?.ok === false ? verification.diagnosis : void 0,
|
|
8047
8199
|
probes: verification ? formatProbes(verification.probes) : void 0,
|
|
8048
8200
|
repair_hint: repairHint,
|
|
8049
|
-
warning:
|
|
8201
|
+
warning: result3.secrets?.pushed.includes("CARRIER_API_KEY") ? void 0 : "CARRIER_API_KEY was not staged \u2014 / and /shop will return 500 until it is set."
|
|
8050
8202
|
});
|
|
8051
8203
|
} catch (e) {
|
|
8052
8204
|
return err4(e instanceof Error ? e.message : "deploy failed");
|
|
@@ -8059,11 +8211,11 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
8059
8211
|
title: "Provision Storefront Clerk App",
|
|
8060
8212
|
description: "Create a Clerk application (Platform API) or reuse Clerk keys already on this machine, write them into the storefront .env.local, and configure allowed origins and redirect URLs on the instance.",
|
|
8061
8213
|
inputSchema: {
|
|
8062
|
-
dir:
|
|
8063
|
-
name:
|
|
8064
|
-
production:
|
|
8065
|
-
no_create:
|
|
8066
|
-
url:
|
|
8214
|
+
dir: z12.string().min(1).describe("Path to the scaffolded storefront directory"),
|
|
8215
|
+
name: z12.string().optional().describe("Clerk application name (defaults from brand)"),
|
|
8216
|
+
production: z12.boolean().optional().describe("Also create a production instance (Platform API only)"),
|
|
8217
|
+
no_create: z12.boolean().optional().describe("Never create a new application; only reuse existing keys"),
|
|
8218
|
+
url: z12.string().optional().describe("Deployed URL to whitelist as origin and redirect")
|
|
8067
8219
|
},
|
|
8068
8220
|
annotations: annotationsFor("provision_storefront_clerk", "write")
|
|
8069
8221
|
},
|
|
@@ -8076,7 +8228,7 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
8076
8228
|
if (denied) return denied;
|
|
8077
8229
|
try {
|
|
8078
8230
|
const brand = await loadStorefrontBrand(dir, name ? { name } : void 0);
|
|
8079
|
-
const
|
|
8231
|
+
const result3 = await provisionClerk({
|
|
8080
8232
|
name: name ?? brand.name,
|
|
8081
8233
|
domain: brand.domain,
|
|
8082
8234
|
production: production === true,
|
|
@@ -8085,28 +8237,28 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
8085
8237
|
storefront: dir,
|
|
8086
8238
|
cli: clerkCliDeps()
|
|
8087
8239
|
});
|
|
8088
|
-
if (!
|
|
8240
|
+
if (!result3.ok || !result3.credentials) {
|
|
8089
8241
|
return ok3({
|
|
8090
8242
|
provisioned: false,
|
|
8091
|
-
tier:
|
|
8092
|
-
reason:
|
|
8093
|
-
guidance:
|
|
8243
|
+
tier: result3.tier,
|
|
8244
|
+
reason: result3.reason,
|
|
8245
|
+
guidance: result3.guidance ?? []
|
|
8094
8246
|
});
|
|
8095
8247
|
}
|
|
8096
8248
|
const written = await mergeEnvLocal(dir, {
|
|
8097
|
-
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY:
|
|
8098
|
-
CLERK_SECRET_KEY:
|
|
8249
|
+
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY: result3.credentials.publishableKey,
|
|
8250
|
+
CLERK_SECRET_KEY: result3.credentials.secretKey
|
|
8099
8251
|
});
|
|
8100
8252
|
const { allowedOrigins, redirectUrls } = storefrontClerkUrls(url, brand.domain);
|
|
8101
|
-
const configured = await configureClerkInstance(
|
|
8253
|
+
const configured = await configureClerkInstance(result3.credentials.secretKey, {
|
|
8102
8254
|
allowedOrigins,
|
|
8103
8255
|
redirectUrls
|
|
8104
8256
|
});
|
|
8105
8257
|
return ok3({
|
|
8106
8258
|
provisioned: true,
|
|
8107
|
-
tier:
|
|
8108
|
-
application_id:
|
|
8109
|
-
instance_id:
|
|
8259
|
+
tier: result3.tier,
|
|
8260
|
+
application_id: result3.credentials.applicationId ?? null,
|
|
8261
|
+
instance_id: result3.credentials.instanceId ?? null,
|
|
8110
8262
|
env_written: written,
|
|
8111
8263
|
configured: configured.applied,
|
|
8112
8264
|
configure_failures: configured.failed
|
|
@@ -8119,7 +8271,7 @@ function registerStorefrontDeployTools(server2, props2) {
|
|
|
8119
8271
|
}
|
|
8120
8272
|
|
|
8121
8273
|
// src/tools-storefront-plan.ts
|
|
8122
|
-
import { z as
|
|
8274
|
+
import { z as z13 } from "zod";
|
|
8123
8275
|
|
|
8124
8276
|
// src/lib/storefront-plan-update.ts
|
|
8125
8277
|
var STRIPE_PRICE_ID_RE = /^price_[A-Za-z0-9_]+$/;
|
|
@@ -8225,14 +8377,14 @@ function registerStorefrontPlanTools(server2, props2, call = (path, body2) => {
|
|
|
8225
8377
|
server2.registerTool(name, {
|
|
8226
8378
|
title: name === "list_storefronts" ? "List Storefronts" : "Get Storefront",
|
|
8227
8379
|
description: "Read hosted storefront plans including stored OCS account ids and account_status.",
|
|
8228
|
-
inputSchema: name === "get_storefront" ? { storefront_id:
|
|
8380
|
+
inputSchema: name === "get_storefront" ? { storefront_id: z13.string().min(1) } : {},
|
|
8229
8381
|
annotations: annotationsFor(name, "read")
|
|
8230
8382
|
}, async (args) => {
|
|
8231
8383
|
const denied = denyUnlessScoped(props2, name, STOREFRONT_PLAN_TOOL_SCOPES);
|
|
8232
8384
|
if (denied) return denied;
|
|
8233
8385
|
try {
|
|
8234
|
-
const
|
|
8235
|
-
return
|
|
8386
|
+
const result3 = await read("storefront_id" in args ? String(args.storefront_id) : void 0);
|
|
8387
|
+
return result3.ok ? ok4(JSON.stringify(result3.body)) : err5(JSON.stringify(result3.body));
|
|
8236
8388
|
} catch (e) {
|
|
8237
8389
|
return err5(e instanceof Error ? e.message : "storefront read failed");
|
|
8238
8390
|
}
|
|
@@ -8244,14 +8396,14 @@ function registerStorefrontPlanTools(server2, props2, call = (path, body2) => {
|
|
|
8244
8396
|
title: "Update Storefront Plan",
|
|
8245
8397
|
description: "Change the retail price, whether a plan is for sale, its OCS account, its display order, or the stored Stripe Price on the caller's own hosted storefront. The plan must already exist. A price of zero or less is refused. stripe_price_id and stripe_price_mode are set together; null clears both. The id must look like price_\u2026 and be 1-255 characters. A plan on another storefront is not found and is left unchanged. The Price is stored, not yet charged. This does not create a Stripe Price, and a buyer cannot set one. The later checkout must verify the Price on the connected account.",
|
|
8246
8398
|
inputSchema: {
|
|
8247
|
-
ocs_account_id:
|
|
8248
|
-
storefront_id:
|
|
8249
|
-
slug:
|
|
8250
|
-
price_cents:
|
|
8251
|
-
active:
|
|
8252
|
-
sort_order:
|
|
8253
|
-
stripe_price_id:
|
|
8254
|
-
stripe_price_mode:
|
|
8399
|
+
ocs_account_id: z13.number().int().positive().optional().describe("Owned OCS account override. Omit for automatic resolution."),
|
|
8400
|
+
storefront_id: z13.string().min(1).describe("Id of the hosted storefront"),
|
|
8401
|
+
slug: z13.string().min(1).describe("Plan slug, such as eu-1gb"),
|
|
8402
|
+
price_cents: z13.number().int().positive().optional().describe("Retail price in minor units. Must be greater than zero. Omit to leave the price."),
|
|
8403
|
+
active: z13.boolean().optional().describe("Whether the plan is for sale. Omit to leave it."),
|
|
8404
|
+
sort_order: z13.number().int().nonnegative().optional().describe("Display order, lowest first. Omit to leave it."),
|
|
8405
|
+
stripe_price_id: z13.string().regex(/^price_[A-Za-z0-9_]+$/).max(255).nullable().optional().describe("Existing Stripe Price id (price_\u2026, 1-255 characters), stored, not yet charged. Set with stripe_price_mode. Null clears both. Omit to leave them."),
|
|
8406
|
+
stripe_price_mode: z13.enum(["test", "live"]).nullable().optional().describe("test or live. Set with stripe_price_id. Null clears both. Omit to leave them.")
|
|
8255
8407
|
},
|
|
8256
8408
|
annotations: annotationsFor("update_storefront_plan", "write")
|
|
8257
8409
|
},
|
|
@@ -8268,9 +8420,9 @@ function registerStorefrontPlanTools(server2, props2, call = (path, body2) => {
|
|
|
8268
8420
|
});
|
|
8269
8421
|
if (!update.ok) return err5(update.message);
|
|
8270
8422
|
try {
|
|
8271
|
-
const
|
|
8272
|
-
const text = JSON.stringify(
|
|
8273
|
-
return
|
|
8423
|
+
const result3 = await call(`${storefront_id}/${slug}`, update.body);
|
|
8424
|
+
const text = JSON.stringify(result3.body);
|
|
8425
|
+
return result3.ok ? ok4(text) : err5(text);
|
|
8274
8426
|
} catch (e) {
|
|
8275
8427
|
return err5(e instanceof Error ? e.message : "plan update failed");
|
|
8276
8428
|
}
|
|
@@ -8279,7 +8431,7 @@ function registerStorefrontPlanTools(server2, props2, call = (path, body2) => {
|
|
|
8279
8431
|
}
|
|
8280
8432
|
|
|
8281
8433
|
// src/tools-atlas.ts
|
|
8282
|
-
import { z as
|
|
8434
|
+
import { z as z14 } from "zod";
|
|
8283
8435
|
|
|
8284
8436
|
// src/atlas-public.ts
|
|
8285
8437
|
var ATLAS_PUBLIC_BASE_URL = "https://atlas.carrier.llc";
|
|
@@ -8337,13 +8489,13 @@ var ATLAS_TOOL_SCOPES = {
|
|
|
8337
8489
|
get_atlas_network_status: "read"
|
|
8338
8490
|
};
|
|
8339
8491
|
var coverageSchema = {
|
|
8340
|
-
country:
|
|
8341
|
-
status:
|
|
8342
|
-
technology:
|
|
8492
|
+
country: z14.string().regex(/^[A-Za-z]{2}$/, "country must be a 2-letter ISO code").describe("ISO 3166-1 alpha-2 country code, for example JP or NL"),
|
|
8493
|
+
status: z14.enum(["up", "degraded", "down", "unknown"]).optional().describe("Keep only networks whose latest probe has this status"),
|
|
8494
|
+
technology: z14.enum(["2G", "3G", "4G", "5G"]).optional().describe("Keep only networks of this radio generation")
|
|
8343
8495
|
};
|
|
8344
8496
|
var networkSchema = {
|
|
8345
|
-
mcc:
|
|
8346
|
-
mnc:
|
|
8497
|
+
mcc: z14.string().regex(/^\d{3}$/, "mcc must be 3 digits").describe("Mobile Country Code"),
|
|
8498
|
+
mnc: z14.string().regex(/^\d{2,3}$/, "mnc must be 2 or 3 digits").describe("Mobile Network Code")
|
|
8347
8499
|
};
|
|
8348
8500
|
function jsonResult3(body2) {
|
|
8349
8501
|
return {
|
|
@@ -8398,15 +8550,15 @@ function registerAtlasTools(server2, ctx) {
|
|
|
8398
8550
|
}
|
|
8399
8551
|
|
|
8400
8552
|
// src/tools-network-default.ts
|
|
8401
|
-
import { z as
|
|
8553
|
+
import { z as z15 } from "zod";
|
|
8402
8554
|
var NETWORK_DEFAULT_TOOL_SCOPES = {
|
|
8403
8555
|
get_network_default: "read",
|
|
8404
8556
|
set_network_default: "write",
|
|
8405
8557
|
plan_network_default: "read"
|
|
8406
8558
|
};
|
|
8407
|
-
var choiceShape =
|
|
8408
|
-
mode:
|
|
8409
|
-
steeringListId:
|
|
8559
|
+
var choiceShape = z15.object({
|
|
8560
|
+
mode: z15.enum(NETWORK_DEFAULT_MODES),
|
|
8561
|
+
steeringListId: z15.number().int().positive().optional()
|
|
8410
8562
|
}).describe("`cheapest_available`, `all`, or `custom` with a steeringListId from list_steering_lists");
|
|
8411
8563
|
function ioFor(ctx, token2) {
|
|
8412
8564
|
const kv = ctx.env.CARRIER_USERS;
|
|
@@ -8461,9 +8613,9 @@ function registerNetworkDefaultTools(server2, ctx) {
|
|
|
8461
8613
|
title: "Set Network Default",
|
|
8462
8614
|
description: "Use this to set the organisation's network default to `cheapest_available`, `all`, or `custom` (a steering list id from `list_steering_lists`, which must exist). This only stores the setting. It changes no SIM, writes nothing to OCS and does not migrate existing customers: it applies to NEW assignments. A single assignment can still override it with `plan_network_default`'s `simOverride`. Params: `mode` (required), `steeringListId` (required when mode is `custom`), `dry_run` (preview only). Do NOT use this to assign a list to one SIM \u2014 use `modify_subscriber_steering_list`.",
|
|
8463
8615
|
inputSchema: {
|
|
8464
|
-
mode:
|
|
8465
|
-
steeringListId:
|
|
8466
|
-
dry_run:
|
|
8616
|
+
mode: z15.enum(NETWORK_DEFAULT_MODES).describe("cheapest_available | all | custom"),
|
|
8617
|
+
steeringListId: z15.number().int().positive().optional().describe("Required when mode is custom"),
|
|
8618
|
+
dry_run: z15.boolean().optional().describe("If true, validate and return what would be stored; store nothing")
|
|
8467
8619
|
},
|
|
8468
8620
|
annotations: { readOnlyHint: false, idempotentHint: true, destructiveHint: false }
|
|
8469
8621
|
},
|
|
@@ -8492,10 +8644,10 @@ function registerNetworkDefaultTools(server2, ctx) {
|
|
|
8492
8644
|
title: "Plan Network Default",
|
|
8493
8645
|
description: "Use this to see which networks a SIM would be given in one or more countries, before anything is assigned. By default that is the cheapest available network per country (lowest data rate above zero, among rules really in force). Precedence: `simOverride`, then `packageOverride`, then the org default, then `cheapest_available`. Read only: `applied` is always false. If the tariff is missing or cannot be compared it falls back to ALL networks and says so in `warnings` and `summary` (`fellBackToAll: true`); never present that as a cheapest choice. The price basis is the wholesale data rate per MB, not the end price. Creating a steering list has no OCS REST method, so when no existing list matches the result is `needs_list`, not a created list. Params: `countries` (ISO-3166 alpha-2 codes, required), `simOverride`, `packageOverride`, `resellerId` (optional).",
|
|
8494
8646
|
inputSchema: {
|
|
8495
|
-
countries:
|
|
8647
|
+
countries: z15.array(z15.string().length(2)).min(1).describe('ISO-3166 alpha-2 codes, e.g. ["CA"]'),
|
|
8496
8648
|
simOverride: choiceShape.optional(),
|
|
8497
8649
|
packageOverride: choiceShape.optional(),
|
|
8498
|
-
resellerId:
|
|
8650
|
+
resellerId: z15.number().int().positive().optional().describe("Omit to use the token owner's reseller")
|
|
8499
8651
|
},
|
|
8500
8652
|
annotations: { readOnlyHint: true }
|
|
8501
8653
|
},
|
|
@@ -8510,7 +8662,7 @@ function registerNetworkDefaultTools(server2, ctx) {
|
|
|
8510
8662
|
}
|
|
8511
8663
|
|
|
8512
8664
|
// src/affiliate-tools.ts
|
|
8513
|
-
import { z as
|
|
8665
|
+
import { z as z16 } from "zod";
|
|
8514
8666
|
var AFFILIATE_TOOL_SCOPES = {
|
|
8515
8667
|
affiliate_status: "read",
|
|
8516
8668
|
affiliate_commissions: "read",
|
|
@@ -8581,7 +8733,7 @@ function registerAffiliateTools(server2, ctx) {
|
|
|
8581
8733
|
title: "Affiliate Commissions",
|
|
8582
8734
|
description: "Read-only: returns the list of commission records for the authenticated operator.",
|
|
8583
8735
|
inputSchema: {
|
|
8584
|
-
limit:
|
|
8736
|
+
limit: z16.number().int().min(1).max(200).optional().default(50).describe("Maximum number of commission records to return (1-200, default: 50).")
|
|
8585
8737
|
},
|
|
8586
8738
|
annotations: annotationsFor("affiliate_commissions", "read")
|
|
8587
8739
|
},
|
|
@@ -10732,15 +10884,15 @@ function registerAllCarrierAskTools(server2, ctx) {
|
|
|
10732
10884
|
title: "Natural Language Carrier Tool Router",
|
|
10733
10885
|
description: "Use this when you want to perform a carrier operation but don't know which specific tool to call. Describe your intent in plain language and carrier_ask will identify the correct tool(s) and suggest the required parameters. For simple read intents, it executes directly and returns results. For destructive operations it returns a confirm_token that you must pass in a second call. Params: `intent` (string \u2014 natural language description of what you want to do), `context` (optional: iccid, account_id, reseller_id if already known). Returns: RouteResult \u2014 confirmed | pending_confirm | ambiguous | none. Do NOT use this when you know the right tool \u2014 direct calls are faster and cheaper.",
|
|
10734
10886
|
inputSchema: {
|
|
10735
|
-
intent:
|
|
10887
|
+
intent: z17.string().min(3).describe(
|
|
10736
10888
|
"Natural-language description of the operation to perform (e.g. 'suspend ICCID 89316 until next month', 'show fleet health', 'assign Europe 5GB package to subscriber 89316...')"
|
|
10737
10889
|
),
|
|
10738
|
-
context:
|
|
10739
|
-
iccid:
|
|
10740
|
-
account_id:
|
|
10741
|
-
reseller_id:
|
|
10890
|
+
context: z17.object({
|
|
10891
|
+
iccid: z17.string().optional().describe("Subscriber ICCID if already known"),
|
|
10892
|
+
account_id: z17.number().optional().describe("Account ID if already known"),
|
|
10893
|
+
reseller_id: z17.number().optional().describe("Reseller ID if already known")
|
|
10742
10894
|
}).optional().describe("Optional pre-resolved context to improve routing accuracy"),
|
|
10743
|
-
confirm_token:
|
|
10895
|
+
confirm_token: z17.string().optional().describe(
|
|
10744
10896
|
"One-time token from a previous carrier_ask call with confirm_required=true. Providing this executes the previously staged destructive operation."
|
|
10745
10897
|
)
|
|
10746
10898
|
}
|
|
@@ -10944,7 +11096,7 @@ function registerAllCarrierAskTools(server2, ctx) {
|
|
|
10944
11096
|
title: "Describe a Carrier Tool",
|
|
10945
11097
|
description: "Get full documentation for any registered Carrier MCP tool: description, parameters, 2-3 example invocations, required scope, destructive flag, and guidance. Params: `tool_name` (exact MCP tool name, e.g. 'assign_package'). Returns: structured tool metadata. Does NOT execute the tool.",
|
|
10946
11098
|
inputSchema: {
|
|
10947
|
-
tool_name:
|
|
11099
|
+
tool_name: z17.string().describe("The exact MCP tool name to describe (e.g. 'assign_package', 'hlr_set_bitrate')")
|
|
10948
11100
|
}
|
|
10949
11101
|
},
|
|
10950
11102
|
wrapHandler(
|
|
@@ -11037,7 +11189,7 @@ function buildExamples(toolName) {
|
|
|
11037
11189
|
}
|
|
11038
11190
|
|
|
11039
11191
|
// src/list-recent-ocs-events.ts
|
|
11040
|
-
import { z as
|
|
11192
|
+
import { z as z18 } from "zod";
|
|
11041
11193
|
|
|
11042
11194
|
// ../../packages/ocs-spec/src/ocs-event-buffer-read.ts
|
|
11043
11195
|
var LIFECYCLE_RESELLER_ID2 = 1170;
|
|
@@ -11166,10 +11318,10 @@ var ALLOWED_EVENT_TYPES = [
|
|
|
11166
11318
|
"usage.anomaly"
|
|
11167
11319
|
];
|
|
11168
11320
|
var listRecentOcsEventsSchema = {
|
|
11169
|
-
iccid:
|
|
11170
|
-
limit:
|
|
11171
|
-
event_types:
|
|
11172
|
-
since:
|
|
11321
|
+
iccid: z18.string().regex(/^\d{19,20}$/).describe("ICCID, 19 or 20 digits, ITU-T E.118 format"),
|
|
11322
|
+
limit: z18.number().int().min(1).max(50).default(20).describe("Max events to return, newest first"),
|
|
11323
|
+
event_types: z18.array(z18.enum(ALLOWED_EVENT_TYPES)).optional().describe("Filter to specific event types"),
|
|
11324
|
+
since: z18.string().datetime().optional().describe("ISO-8601 timestamp; only events after this point")
|
|
11173
11325
|
};
|
|
11174
11326
|
async function listRecentOcsEvents2(iccid, limit, eventTypes, since, kv) {
|
|
11175
11327
|
return listRecentOcsEvents(iccid, limit, eventTypes, since, kv);
|
|
@@ -11210,7 +11362,7 @@ function registerListRecentOcsEventsTool(server2, ctx) {
|
|
|
11210
11362
|
"OCS_EVENT_ROUTING",
|
|
11211
11363
|
"the OCS event ring buffer"
|
|
11212
11364
|
);
|
|
11213
|
-
const
|
|
11365
|
+
const result3 = await listRecentOcsEvents2(
|
|
11214
11366
|
iccid,
|
|
11215
11367
|
limit,
|
|
11216
11368
|
event_types,
|
|
@@ -11218,7 +11370,7 @@ function registerListRecentOcsEventsTool(server2, ctx) {
|
|
|
11218
11370
|
env.OCS_EVENT_ROUTING
|
|
11219
11371
|
);
|
|
11220
11372
|
return {
|
|
11221
|
-
content: [{ type: "text", text: JSON.stringify(
|
|
11373
|
+
content: [{ type: "text", text: JSON.stringify(result3, null, 2) }]
|
|
11222
11374
|
};
|
|
11223
11375
|
} catch (err9) {
|
|
11224
11376
|
const message = err9 instanceof Error ? err9.message : String(err9);
|
|
@@ -11232,7 +11384,7 @@ function registerListRecentOcsEventsTool(server2, ctx) {
|
|
|
11232
11384
|
}
|
|
11233
11385
|
|
|
11234
11386
|
// src/tools-rate-governor.ts
|
|
11235
|
-
import { z as
|
|
11387
|
+
import { z as z19 } from "zod";
|
|
11236
11388
|
var MONITORED_ENDPOINTS = [
|
|
11237
11389
|
"subscriberNetworkEventsOverPeriod",
|
|
11238
11390
|
// 30/min
|
|
@@ -11264,7 +11416,7 @@ function registerRateLimitStatusTool(server2, ctx) {
|
|
|
11264
11416
|
title: "API Rate-Limit Governor Status",
|
|
11265
11417
|
description: "Inspect Bridge4IP OCS rate-limit governor state \u2014 bucket fill levels, per-endpoint limits, and 80% alert thresholds. Use this to answer: 'are we rate limited', 'check ocs quota', 'how full is the rate limit bucket', 'rate limit status'. Params: `endpoint` (optional \u2014 OCS camelCase method name to inspect a single bucket, e.g. 'subscriberUsageOverPeriod'; omit for all monitored endpoints). Returns: per-endpoint { limit_per_min, batch_cap_per_min, calls_in_window, batch_calls_in_window, utilisation_pct, alert (true when \u226580% of limit) }. Note: counts come from the in-process sliding-window log (same key as OCS calls: API token + endpoint) \u2014 they reset when the Worker isolate recycles. Use as a relative signal, not an exact counter. Do NOT use this to adjust limits \u2014 limits are set by Bridge4IP contract and cannot be changed via MCP.",
|
|
11266
11418
|
inputSchema: {
|
|
11267
|
-
endpoint:
|
|
11419
|
+
endpoint: z19.string().optional().describe(
|
|
11268
11420
|
"OCS method name in camelCase (e.g. 'subscriberUsageOverPeriod'). Omit to return status for all monitored endpoints."
|
|
11269
11421
|
)
|
|
11270
11422
|
},
|
|
@@ -11320,7 +11472,7 @@ function registerRateLimitStatusTool(server2, ctx) {
|
|
|
11320
11472
|
}
|
|
11321
11473
|
|
|
11322
11474
|
// src/tools-depletion-events.ts
|
|
11323
|
-
import { z as
|
|
11475
|
+
import { z as z20 } from "zod";
|
|
11324
11476
|
function ok6(payload) {
|
|
11325
11477
|
return { content: [{ type: "text", text: JSON.stringify(payload, null, 2) }] };
|
|
11326
11478
|
}
|
|
@@ -11348,10 +11500,10 @@ function registerDepletionEventsTool(server2, ctx) {
|
|
|
11348
11500
|
title: "Subscriber Bundle Depletion Events",
|
|
11349
11501
|
description: "Look up bundle depletion events for a subscriber (or list recent fleet-wide depletions). Returns the most recent bundle.depleted event stored when the prepaid usage webhook received a last_slice notification. Events are retained for 7 days. Use subscriberId to check a specific subscriber, or omit to list the 20 most recent fleet-wide depletions. Requires 'read' scope.",
|
|
11350
11502
|
inputSchema: {
|
|
11351
|
-
subscriberId:
|
|
11503
|
+
subscriberId: z20.string().optional().describe(
|
|
11352
11504
|
"OCS subscriber ID to look up. Omit to list the 20 most recent fleet-wide depletions."
|
|
11353
11505
|
),
|
|
11354
|
-
since:
|
|
11506
|
+
since: z20.string().optional().describe(
|
|
11355
11507
|
"ISO-8601 timestamp \u2014 only return events at or after this time (for single-subscriber lookup)."
|
|
11356
11508
|
)
|
|
11357
11509
|
},
|
|
@@ -11466,7 +11618,7 @@ function registerDepletionEventsTool(server2, ctx) {
|
|
|
11466
11618
|
}
|
|
11467
11619
|
|
|
11468
11620
|
// src/tools-country-history.ts
|
|
11469
|
-
import { z as
|
|
11621
|
+
import { z as z21 } from "zod";
|
|
11470
11622
|
function isoDate(now, daysAgo = 0) {
|
|
11471
11623
|
const d = new Date(now.getTime() - daysAgo * 864e5);
|
|
11472
11624
|
return d.toISOString().slice(0, 10);
|
|
@@ -11489,10 +11641,10 @@ function registerCountryHistoryTool(server2, ctx) {
|
|
|
11489
11641
|
title: "Subscriber Country History",
|
|
11490
11642
|
description: "Return cross-border movement history for a subscriber, reconstructed from OCS Gy charging events. Reads `gyAnswer.events` from `subscriberNetworkEventsOverPeriod` \u2014 every Gy record carries its own country, operator and MCC \u2014 and collapses consecutive same-country records into stays with first-seen and last-seen timestamps. This needs no webhook: it works with Relay LU and Relay Gy off. Relay `country.entered` events from the 24h ring-buffer are merged in as a supplement when present. Use this to answer: 'where has subscriber X traveled', 'show country history for ICCID', 'border crossings for this SIM'. Params: `subscriberId` (ICCID, 19\u201320 digits), `startDate`/`endDate` (YYYY-MM-DD, max 7 days apart, default the last 7 days), `limit` (1\u201350, default 20, newest first). Returns: `stays` ({ country, country_name, first_seen, last_seen, operators, mccs, event_count, used_bytes }), `transitions` ({ from, to, at }), and `country_events` in the legacy flat shape. `used_bytes` already handles the string-typed `usedUnits` and its 'N/A' values. Do NOT use this for raw per-session records \u2014 use `subscriber_network_events` for those.",
|
|
11491
11643
|
inputSchema: {
|
|
11492
|
-
subscriberId:
|
|
11493
|
-
startDate:
|
|
11494
|
-
endDate:
|
|
11495
|
-
limit:
|
|
11644
|
+
subscriberId: z21.string().regex(/^\d{19,20}$/, "subscriberId must be a 19\u201320 digit ICCID").describe("Subscriber ICCID (19\u201320 digits, ITU-T E.118)"),
|
|
11645
|
+
startDate: z21.string().regex(/^\d{4}-\d{2}-\d{2}$/, "startDate must be YYYY-MM-DD").optional().describe("Start of the period, YYYY-MM-DD inclusive (default: 7 days ago)"),
|
|
11646
|
+
endDate: z21.string().regex(/^\d{4}-\d{2}-\d{2}$/, "endDate must be YYYY-MM-DD").optional().describe("End of the period, YYYY-MM-DD inclusive, max 7 days from start (default: today)"),
|
|
11647
|
+
limit: z21.number().int().min(1).max(50).default(20).optional().describe("Maximum number of country_events to return, newest first (default 20, max 50)")
|
|
11496
11648
|
},
|
|
11497
11649
|
annotations: { readOnlyHint: true, idempotentHint: true }
|
|
11498
11650
|
},
|
|
@@ -11600,7 +11752,7 @@ function registerCountryHistoryTool(server2, ctx) {
|
|
|
11600
11752
|
}
|
|
11601
11753
|
|
|
11602
11754
|
// src/apps/fleet-health-app.ts
|
|
11603
|
-
import { z as
|
|
11755
|
+
import { z as z22 } from "zod";
|
|
11604
11756
|
import {
|
|
11605
11757
|
registerAppTool,
|
|
11606
11758
|
registerAppResource,
|
|
@@ -11648,7 +11800,7 @@ function toFleetInput(raw) {
|
|
|
11648
11800
|
|
|
11649
11801
|
// src/apps/fleet-health-app.ts
|
|
11650
11802
|
var FLEET_APP_RESOURCE_URI = "ui://fleet-health-dashboard";
|
|
11651
|
-
async function
|
|
11803
|
+
async function safeCall3(client2, method, params) {
|
|
11652
11804
|
try {
|
|
11653
11805
|
return { data: await client2.call(method, params), error: null };
|
|
11654
11806
|
} catch (err9) {
|
|
@@ -11662,8 +11814,8 @@ async function loadFleet(ctx, accountId) {
|
|
|
11662
11814
|
const statusParams = accountId !== void 0 ? { accountId } : resellerId !== void 0 ? { resellerId } : {};
|
|
11663
11815
|
const accountParams = resellerId !== void 0 ? { resellerId } : {};
|
|
11664
11816
|
const [status, accounts] = await Promise.all([
|
|
11665
|
-
|
|
11666
|
-
|
|
11817
|
+
safeCall3(client2, "esimStatusPerAccount", statusParams),
|
|
11818
|
+
safeCall3(client2, "listResellerAccount", accountParams)
|
|
11667
11819
|
]);
|
|
11668
11820
|
return toFleetInput({
|
|
11669
11821
|
status: status.data,
|
|
@@ -11716,7 +11868,7 @@ function registerFleetHealthApp(server2, ctx) {
|
|
|
11716
11868
|
title: "Fleet Health Dashboard",
|
|
11717
11869
|
description: "Draw the fleet overview as an interactive panel: eSIM status, per-account breakdown and low-balance alerts. Returns structuredContent for the panel, so it only helps a client that can render MCP UI resources. Do NOT use this when the answer has to be readable text, or in any headless or scripted context \u2014 `fleet_health` returns the same data as prose.",
|
|
11718
11870
|
inputSchema: {
|
|
11719
|
-
accountId:
|
|
11871
|
+
accountId: z22.number().optional().describe("Filter to a specific account (omit for all)")
|
|
11720
11872
|
},
|
|
11721
11873
|
annotations: { readOnlyHint: true },
|
|
11722
11874
|
_meta: {
|
|
@@ -11759,7 +11911,7 @@ function registerFleetHealthApp(server2, ctx) {
|
|
|
11759
11911
|
}
|
|
11760
11912
|
|
|
11761
11913
|
// src/apps/provisioning-wizard.ts
|
|
11762
|
-
import { z as
|
|
11914
|
+
import { z as z23 } from "zod";
|
|
11763
11915
|
import {
|
|
11764
11916
|
registerAppTool as registerAppTool2,
|
|
11765
11917
|
registerAppResource as registerAppResource2,
|
|
@@ -11864,10 +12016,10 @@ function registerProvisioningWizard(server2, ctx) {
|
|
|
11864
12016
|
title: "eSIM Provisioning Wizard",
|
|
11865
12017
|
description: "Interactive 3-step wizard to provision an eSIM: select subscriber, choose package template, preview (dry_run) and confirm execution.",
|
|
11866
12018
|
inputSchema: {
|
|
11867
|
-
step:
|
|
11868
|
-
wizardId:
|
|
11869
|
-
subscriber_iccid:
|
|
11870
|
-
package_template_id:
|
|
12019
|
+
step: z23.enum(["init", "select-package", "preview", "confirm"]).describe("Current wizard step"),
|
|
12020
|
+
wizardId: z23.string().optional().describe("Wizard session ID (absent on init)"),
|
|
12021
|
+
subscriber_iccid: z23.string().optional().describe("Subscriber ICCID (required for select-package)"),
|
|
12022
|
+
package_template_id: z23.number().optional().describe("Package template ID (required for preview)")
|
|
11871
12023
|
},
|
|
11872
12024
|
_meta: {
|
|
11873
12025
|
ui: {
|
|
@@ -12098,7 +12250,7 @@ function registerProvisioningWizard(server2, ctx) {
|
|
|
12098
12250
|
isError: true
|
|
12099
12251
|
};
|
|
12100
12252
|
}
|
|
12101
|
-
const
|
|
12253
|
+
const result3 = await safeCallWithToken(
|
|
12102
12254
|
client2,
|
|
12103
12255
|
token2,
|
|
12104
12256
|
"affectPackageToSubscriber",
|
|
@@ -12108,12 +12260,12 @@ function registerProvisioningWizard(server2, ctx) {
|
|
|
12108
12260
|
}
|
|
12109
12261
|
);
|
|
12110
12262
|
await deleteWizardSession(ctx.env, ctx.props.sub, wizardId);
|
|
12111
|
-
if (
|
|
12263
|
+
if (result3.error) {
|
|
12112
12264
|
return {
|
|
12113
12265
|
content: [
|
|
12114
12266
|
{
|
|
12115
12267
|
type: "text",
|
|
12116
|
-
text: `Provisioning failed: ${
|
|
12268
|
+
text: `Provisioning failed: ${result3.error}`
|
|
12117
12269
|
}
|
|
12118
12270
|
],
|
|
12119
12271
|
isError: true
|
|
@@ -12124,7 +12276,7 @@ function registerProvisioningWizard(server2, ctx) {
|
|
|
12124
12276
|
structuredContent: {
|
|
12125
12277
|
wizardId,
|
|
12126
12278
|
step: "done",
|
|
12127
|
-
result:
|
|
12279
|
+
result: result3.data
|
|
12128
12280
|
}
|
|
12129
12281
|
};
|
|
12130
12282
|
}
|
|
@@ -12137,7 +12289,7 @@ function registerProvisioningWizard(server2, ctx) {
|
|
|
12137
12289
|
}
|
|
12138
12290
|
|
|
12139
12291
|
// src/apps/balance-topup.ts
|
|
12140
|
-
import { z as
|
|
12292
|
+
import { z as z24 } from "zod";
|
|
12141
12293
|
import {
|
|
12142
12294
|
registerAppTool as registerAppTool3,
|
|
12143
12295
|
registerAppResource as registerAppResource3,
|
|
@@ -12190,9 +12342,9 @@ function registerBalanceTopupApp(server2, ctx) {
|
|
|
12190
12342
|
title: "Balance Top-up Form",
|
|
12191
12343
|
description: "Adjust the OCS reseller-account balance behind one subscriber, through a form panel the user can review before it commits. Defaults to preview: a call that omits `preview` returns a projection and writes nothing. Only `preview: false` performs the OCS write. Params: `iccid` (subscriber identifier used to find the account), `delta` (amount to add when positive, deduct when negative), `preview` (boolean, default true). Requires `admin` scope plus recent MFA, and a client that can render UI panels. Do NOT use this in a headless or scripted context \u2014 call `modify_account_balance` directly, which takes an `accountId` and needs no panel. Do NOT use this for a subscriber's own balance \u2014 the `iccid` here only locates the account; per-subscriber money is `modify_subscriber_balance`. Do NOT use this for the Carrier prepaid wallet or MCP credits \u2014 see `wallet_topup_checkout` and `credit_balance`.",
|
|
12192
12344
|
inputSchema: {
|
|
12193
|
-
iccid:
|
|
12194
|
-
delta:
|
|
12195
|
-
preview:
|
|
12345
|
+
iccid: z24.string().describe("The subscriber ICCID for the account lookup"),
|
|
12346
|
+
delta: z24.number().describe("Amount to add (positive) or deduct (negative) from the account balance"),
|
|
12347
|
+
preview: z24.boolean().default(true).describe("If true, return preview without writing. If false, execute the balance change.")
|
|
12196
12348
|
},
|
|
12197
12349
|
annotations: { destructiveHint: true },
|
|
12198
12350
|
_meta: {
|
|
@@ -12211,13 +12363,13 @@ function registerBalanceTopupApp(server2, ctx) {
|
|
|
12211
12363
|
const token2 = await ctx.getUserToken(ctx.props.sub);
|
|
12212
12364
|
const client2 = new OcsClient(ctx.env.CARRIER_OCS_BASE_URL, token2);
|
|
12213
12365
|
if (preview === true) {
|
|
12214
|
-
const
|
|
12366
|
+
const result3 = await safeCallWithToken2(
|
|
12215
12367
|
client2,
|
|
12216
12368
|
token2,
|
|
12217
12369
|
"getSingleSubscriber",
|
|
12218
12370
|
{ iccid }
|
|
12219
12371
|
);
|
|
12220
|
-
const currentBalance =
|
|
12372
|
+
const currentBalance = result3.data ? Number(result3.data["balance"] ?? result3.data["accountBalance"] ?? 0) : 0;
|
|
12221
12373
|
const newBalance2 = currentBalance + delta;
|
|
12222
12374
|
const structured2 = {
|
|
12223
12375
|
iccid,
|
|
@@ -12275,7 +12427,7 @@ function registerAllApps(server2, ctx) {
|
|
|
12275
12427
|
}
|
|
12276
12428
|
|
|
12277
12429
|
// src/prompts.ts
|
|
12278
|
-
import { z as
|
|
12430
|
+
import { z as z25 } from "zod";
|
|
12279
12431
|
function registerAllPrompts(server2) {
|
|
12280
12432
|
server2.registerPrompt(
|
|
12281
12433
|
"fleet_health_report",
|
|
@@ -12311,7 +12463,7 @@ Format as a structured report with sections, tables, and actionable recommendati
|
|
|
12311
12463
|
{
|
|
12312
12464
|
title: "Subscriber Deep Dive",
|
|
12313
12465
|
description: "Comprehensive analysis of a single subscriber: profile, packages, usage patterns, location history, recommendations.",
|
|
12314
|
-
argsSchema: { iccid:
|
|
12466
|
+
argsSchema: { iccid: z25.string().describe("The subscriber ICCID to analyse") }
|
|
12315
12467
|
},
|
|
12316
12468
|
async ({ iccid }) => ({
|
|
12317
12469
|
messages: [
|
|
@@ -12410,7 +12562,7 @@ Analyze and present:
|
|
|
12410
12562
|
{
|
|
12411
12563
|
title: "Bulk Operations Planner",
|
|
12412
12564
|
description: "Plan bulk operations safely: mass package assignments, account migrations, balance adjustments, or status changes.",
|
|
12413
|
-
argsSchema: { operation:
|
|
12565
|
+
argsSchema: { operation: z25.string().describe("Describe the bulk operation you want to perform") }
|
|
12414
12566
|
},
|
|
12415
12567
|
async ({ operation }) => ({
|
|
12416
12568
|
messages: [
|
|
@@ -12443,7 +12595,7 @@ NEVER execute destructive operations without confirmation.`
|
|
|
12443
12595
|
}
|
|
12444
12596
|
|
|
12445
12597
|
// src/tools-pricing.ts
|
|
12446
|
-
import { z as
|
|
12598
|
+
import { z as z26 } from "zod";
|
|
12447
12599
|
function registerAllPricingTools(server2, ctx) {
|
|
12448
12600
|
const allTools = [...PRICING_TOOLS, ...PROJECTS_TOOLS];
|
|
12449
12601
|
for (const tool of allTools) {
|
|
@@ -12507,7 +12659,7 @@ function buildPricingHandler(tool, ctx) {
|
|
|
12507
12659
|
}
|
|
12508
12660
|
}
|
|
12509
12661
|
try {
|
|
12510
|
-
const
|
|
12662
|
+
const result3 = await tool.handler(ctx.env, ctx.props, args);
|
|
12511
12663
|
recordUsage(ctx.env, ctx.props.sub, tier);
|
|
12512
12664
|
deductCredits(ctx.env, ctx.props.sub, tier, tool.scope);
|
|
12513
12665
|
ctx.audit({
|
|
@@ -12521,7 +12673,7 @@ function buildPricingHandler(tool, ctx) {
|
|
|
12521
12673
|
content: [
|
|
12522
12674
|
{
|
|
12523
12675
|
type: "text",
|
|
12524
|
-
text: JSON.stringify(
|
|
12676
|
+
text: JSON.stringify(result3, null, 2)
|
|
12525
12677
|
}
|
|
12526
12678
|
]
|
|
12527
12679
|
};
|
|
@@ -12546,23 +12698,23 @@ function toolNameToTitle(name) {
|
|
|
12546
12698
|
}
|
|
12547
12699
|
function buildZodSchema(schema) {
|
|
12548
12700
|
const properties = schema.properties ?? {};
|
|
12549
|
-
const
|
|
12701
|
+
const result3 = {};
|
|
12550
12702
|
for (const [key, prop] of Object.entries(properties)) {
|
|
12551
12703
|
let field;
|
|
12552
12704
|
if (prop.enum) {
|
|
12553
|
-
field =
|
|
12705
|
+
field = z26.enum(prop.enum);
|
|
12554
12706
|
} else if (prop.type === "number") {
|
|
12555
|
-
field =
|
|
12707
|
+
field = z26.number();
|
|
12556
12708
|
} else if (prop.type === "boolean") {
|
|
12557
|
-
field =
|
|
12709
|
+
field = z26.boolean();
|
|
12558
12710
|
} else if (prop.type === "array") {
|
|
12559
12711
|
if (prop.items?.type === "number") {
|
|
12560
|
-
field =
|
|
12712
|
+
field = z26.array(z26.number());
|
|
12561
12713
|
} else {
|
|
12562
|
-
field =
|
|
12714
|
+
field = z26.array(z26.string());
|
|
12563
12715
|
}
|
|
12564
12716
|
} else {
|
|
12565
|
-
field =
|
|
12717
|
+
field = z26.string();
|
|
12566
12718
|
}
|
|
12567
12719
|
const required = schema.required ?? [];
|
|
12568
12720
|
if (!required.includes(key)) {
|
|
@@ -12571,13 +12723,13 @@ function buildZodSchema(schema) {
|
|
|
12571
12723
|
if (prop.description) {
|
|
12572
12724
|
field = field.describe(prop.description);
|
|
12573
12725
|
}
|
|
12574
|
-
|
|
12726
|
+
result3[key] = field;
|
|
12575
12727
|
}
|
|
12576
|
-
return
|
|
12728
|
+
return result3;
|
|
12577
12729
|
}
|
|
12578
12730
|
|
|
12579
12731
|
// src/tools-greenzone.ts
|
|
12580
|
-
import { z as
|
|
12732
|
+
import { z as z27 } from "zod";
|
|
12581
12733
|
|
|
12582
12734
|
// src/greenzone-whitelist.ts
|
|
12583
12735
|
var STATE_KEY = "greenzone:state";
|
|
@@ -12868,9 +13020,9 @@ function registerGreenzoneTools(server2, ctx) {
|
|
|
12868
13020
|
title: "Greenzone Whitelist \u2014 Add",
|
|
12869
13021
|
description: "Add a hostname and/or IP address to the Bridge4IP Greenzone whitelist. The Greenzone whitelist controls which hosts/IPs are exempt from data charging after a subscriber's bundle is depleted. This operates via browser automation (Kapture) against the OCS portal \u2014 no REST API exists for this surface. Provide `host` (e.g. 'example.com') and/or `ip` (e.g. '203.0.113.0/24'). At least one of host or ip must be provided. Returns Kapture step sequence for Claude Code to execute. Requires 'write' scope and Kapture running in Sam's Chrome.",
|
|
12870
13022
|
inputSchema: {
|
|
12871
|
-
host:
|
|
12872
|
-
ip:
|
|
12873
|
-
dry_run:
|
|
13023
|
+
host: z27.string().optional().describe("Hostname to whitelist (e.g. 'example.com')"),
|
|
13024
|
+
ip: z27.string().optional().describe("IP address or CIDR to whitelist (e.g. '203.0.113.0/24')"),
|
|
13025
|
+
dry_run: z27.boolean().optional().describe("If true, return the Kapture steps without executing portal automation")
|
|
12874
13026
|
},
|
|
12875
13027
|
annotations: { destructiveHint: true }
|
|
12876
13028
|
},
|
|
@@ -12929,9 +13081,9 @@ function registerGreenzoneTools(server2, ctx) {
|
|
|
12929
13081
|
title: "Greenzone Whitelist \u2014 Remove",
|
|
12930
13082
|
description: "Remove a hostname and/or IP address from the Bridge4IP Greenzone whitelist. This operates via browser automation (Kapture) against the OCS portal. Provide `host` and/or `ip` to remove \u2014 at least one required. Returns Kapture step sequence for Claude Code to execute. Requires 'write' scope and Kapture running in Sam's Chrome.",
|
|
12931
13083
|
inputSchema: {
|
|
12932
|
-
host:
|
|
12933
|
-
ip:
|
|
12934
|
-
dry_run:
|
|
13084
|
+
host: z27.string().optional().describe("Hostname to remove from whitelist"),
|
|
13085
|
+
ip: z27.string().optional().describe("IP address or CIDR to remove from whitelist"),
|
|
13086
|
+
dry_run: z27.boolean().optional().describe("If true, return the Kapture steps without executing portal automation")
|
|
12935
13087
|
},
|
|
12936
13088
|
annotations: { destructiveHint: true }
|
|
12937
13089
|
},
|
|
@@ -12990,7 +13142,7 @@ function registerGreenzoneTools(server2, ctx) {
|
|
|
12990
13142
|
title: "Greenzone Whitelist \u2014 List",
|
|
12991
13143
|
description: "List current Greenzone whitelist entries from the KV cache. Returns all whitelisted hosts and IPs, when the state was last synced, and whether the last hourly reconciliation detected drift from the portal. This is a fast read from KV \u2014 no browser automation required. Use `from_portal: true` to trigger a live portal read via Kapture instead of KV. Requires 'read' scope.",
|
|
12992
13144
|
inputSchema: {
|
|
12993
|
-
from_portal:
|
|
13145
|
+
from_portal: z27.boolean().optional().describe(
|
|
12994
13146
|
"When true, return Kapture steps to read live portal state instead of KV cache"
|
|
12995
13147
|
)
|
|
12996
13148
|
},
|
|
@@ -13042,7 +13194,7 @@ function registerGreenzoneTools(server2, ctx) {
|
|
|
13042
13194
|
}
|
|
13043
13195
|
|
|
13044
13196
|
// src/tools-ui-agent-generic.ts
|
|
13045
|
-
import { z as
|
|
13197
|
+
import { z as z28 } from "zod";
|
|
13046
13198
|
var COST_PER_STEP_USD = 0.014;
|
|
13047
13199
|
var SESSION_OVERHEAD_USD = 5e-3;
|
|
13048
13200
|
function estimateCostUsd2(steps) {
|
|
@@ -13084,13 +13236,13 @@ function registerUiAgentGenericTools(server2, ctx, runtime) {
|
|
|
13084
13236
|
title: "Dispatch Generic Browsing Agent",
|
|
13085
13237
|
description: "Send a plain-language task to a hosted browsing agent, which drives a real browser on the open web \u2014 navigating pages, searching, extracting content, filling forms outside the OCS portal. Each run costs roughly $0.20-1.00 in model spend against your own BROWSER_USE_API_KEY, so treat it as the expensive last resort, not a lookup. Limited to CARRIER_BROWSER_USE_MAX_RUNS runs per CLI session (default 10). Params: `prompt` (1-4000 chars \u2014 name the target URL and the exact data or action), `max_steps` (1-30, default 15; prices the dry-run estimate only), `dry_run` (true returns only `estimated_cost_usd` and creates no session). Returns the finished result: unlike the hosted Worker, a local CLI has no background runtime, so this call blocks for the length of the run. Requires `write` scope. Do NOT use this to work out which Carrier tool answers a request \u2014 that is `carrier_ask`, which costs nothing. Do NOT use this for anything the OCS API already covers; every other tool here is faster, free, and audited.",
|
|
13086
13238
|
inputSchema: {
|
|
13087
|
-
prompt:
|
|
13239
|
+
prompt: z28.string().min(1).max(4e3).describe(
|
|
13088
13240
|
"Natural-language task description for the browsing agent. Be specific: include target URLs, data to extract, or actions to perform."
|
|
13089
13241
|
),
|
|
13090
|
-
max_steps:
|
|
13242
|
+
max_steps: z28.number().int().min(1).max(30).optional().describe(
|
|
13091
13243
|
"Advisory step budget (1\u201330, default 15). Prices the dry-run estimate; the hosted agent sets its own depth."
|
|
13092
13244
|
),
|
|
13093
|
-
dry_run:
|
|
13245
|
+
dry_run: z28.boolean().optional().describe(
|
|
13094
13246
|
"Preview cost estimate without dispatching. Returns estimated_cost_usd only \u2014 no browser session is created."
|
|
13095
13247
|
)
|
|
13096
13248
|
}
|
|
@@ -13162,31 +13314,31 @@ function registerUiAgentGenericTools(server2, ctx, runtime) {
|
|
|
13162
13314
|
throw err9;
|
|
13163
13315
|
}
|
|
13164
13316
|
try {
|
|
13165
|
-
const
|
|
13317
|
+
const result3 = await runUiAgent(
|
|
13166
13318
|
prompt,
|
|
13167
13319
|
"Carrier CLI browsing agent",
|
|
13168
13320
|
runtime.env
|
|
13169
13321
|
);
|
|
13170
|
-
runtime.dispatchedTaskIds.add(
|
|
13322
|
+
runtime.dispatchedTaskIds.add(result3.task_id);
|
|
13171
13323
|
ctx.audit({
|
|
13172
13324
|
tool_name: toolName,
|
|
13173
13325
|
ocs_method: "[ui-agent:generic-ask]",
|
|
13174
|
-
status:
|
|
13326
|
+
status: result3.status === "error" ? "error" : "ok",
|
|
13175
13327
|
dry_run: false,
|
|
13176
13328
|
duration_ms: Date.now() - start,
|
|
13177
13329
|
event_type: "ui_agent_dispatch"
|
|
13178
13330
|
});
|
|
13179
13331
|
return {
|
|
13180
|
-
...
|
|
13332
|
+
...result3.status === "error" ? { isError: true } : {},
|
|
13181
13333
|
content: [
|
|
13182
13334
|
{
|
|
13183
13335
|
type: "text",
|
|
13184
13336
|
text: JSON.stringify(
|
|
13185
13337
|
{
|
|
13186
|
-
status:
|
|
13187
|
-
task_id:
|
|
13188
|
-
...
|
|
13189
|
-
result:
|
|
13338
|
+
status: result3.status,
|
|
13339
|
+
task_id: result3.task_id,
|
|
13340
|
+
...result3.session_viewer_url ? { session_viewer_url: result3.session_viewer_url } : {},
|
|
13341
|
+
result: result3.result,
|
|
13190
13342
|
session_spend_usd: runtime.spend.costUsd,
|
|
13191
13343
|
runs_remaining_this_session: runtime.budget.remaining,
|
|
13192
13344
|
note: "The run completed in-process. Task records live only for this CLI session \u2014 ui_agent_status can read this task_id until the process exits."
|
|
@@ -13227,7 +13379,7 @@ function registerUiAgentGenericTools(server2, ctx, runtime) {
|
|
|
13227
13379
|
title: "Poll Browsing Agent Task Status",
|
|
13228
13380
|
description: "Returns the current state of a browsing-agent task by `task_id`, including its result once finished. In the local CLI, ui_agent_ask already returns the finished result, so this is mainly for re-reading a task within the same session. Task records do not survive the CLI process exiting. Requires `read` scope.",
|
|
13229
13381
|
inputSchema: {
|
|
13230
|
-
task_id:
|
|
13382
|
+
task_id: z28.string().describe("Task ID returned by ui_agent_ask")
|
|
13231
13383
|
}
|
|
13232
13384
|
},
|
|
13233
13385
|
async (args) => {
|