@sentientui/mcp 0.19.0 → 0.21.0
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/AGENTS.md +60 -27
- package/README.md +45 -28
- package/dist/{chunk-HT23NB6F.js → chunk-K7JN3LOH.js} +481 -49
- package/dist/index.cjs +486 -49
- package/dist/index.js +6 -1
- package/dist/lib.cjs +531 -49
- package/dist/lib.d.cts +29 -2
- package/dist/lib.d.ts +29 -2
- package/dist/lib.js +49 -1
- package/package.json +3 -2
|
@@ -21,9 +21,10 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
21
21
|
|
|
22
22
|
// src/api-client.ts
|
|
23
23
|
var ApiError = class extends Error {
|
|
24
|
-
constructor(status, message) {
|
|
24
|
+
constructor(status, message, detail) {
|
|
25
25
|
super(message);
|
|
26
26
|
this.status = status;
|
|
27
|
+
this.detail = detail;
|
|
27
28
|
this.name = "ApiError";
|
|
28
29
|
}
|
|
29
30
|
};
|
|
@@ -40,8 +41,14 @@ var ApiClient = class {
|
|
|
40
41
|
async post(path, body) {
|
|
41
42
|
return this.request("POST", path, body);
|
|
42
43
|
}
|
|
44
|
+
async patch(path, body) {
|
|
45
|
+
return this.request("PATCH", path, body);
|
|
46
|
+
}
|
|
47
|
+
async delete(path, body) {
|
|
48
|
+
return this.request("DELETE", path, body);
|
|
49
|
+
}
|
|
43
50
|
async request(method, path, body, isRetry = false) {
|
|
44
|
-
var _a, _b;
|
|
51
|
+
var _a, _b, _c;
|
|
45
52
|
const res = await fetch(`${this.baseUrl}/v1/mgmt${path}`, {
|
|
46
53
|
method,
|
|
47
54
|
headers: __spreadValues({
|
|
@@ -58,7 +65,9 @@ var ApiClient = class {
|
|
|
58
65
|
return this.request(method, path, body, true);
|
|
59
66
|
}
|
|
60
67
|
}
|
|
61
|
-
|
|
68
|
+
const code = String((_b = (_a = errBody.error) != null ? _a : errBody.message) != null ? _b : res.statusText);
|
|
69
|
+
const human = (_c = errBody.message) != null ? _c : errBody.reason;
|
|
70
|
+
throw new ApiError(res.status, code, typeof human === "string" && human !== code ? human : void 0);
|
|
62
71
|
}
|
|
63
72
|
};
|
|
64
73
|
|
|
@@ -403,7 +412,7 @@ function localDate(iso, timeZone) {
|
|
|
403
412
|
}
|
|
404
413
|
function apiErrorGuidance(err, extra) {
|
|
405
414
|
if (extra && Object.prototype.hasOwnProperty.call(extra, err.message)) {
|
|
406
|
-
return extra[err.message];
|
|
415
|
+
return extra[err.message] + detailSuffix(err);
|
|
407
416
|
}
|
|
408
417
|
switch (err.message) {
|
|
409
418
|
case "insufficient_scope":
|
|
@@ -412,6 +421,15 @@ function apiErrorGuidance(err, extra) {
|
|
|
412
421
|
return "Demo mode is read-only. Create a SentientUI account and sign in (or use a project server key) to make changes.";
|
|
413
422
|
case "insufficient_role":
|
|
414
423
|
return "Your account role does not permit this action \u2014 it needs the account owner or an admin.";
|
|
424
|
+
// The mgmt write routes answer a viewer with `role_required` (and origins
|
|
425
|
+
// with `not_authorized`), not `insufficient_role` — so every role refusal
|
|
426
|
+
// fell through to the generic 403 "check your key has access" advice and
|
|
427
|
+
// sent the agent re-authenticating for a permission it already had wrong.
|
|
428
|
+
case "role_required":
|
|
429
|
+
case "not_authorized":
|
|
430
|
+
return `Your role on this project cannot make this change \u2014 it needs an editor or admin.${detailSuffix(err)}`;
|
|
431
|
+
case "ai_unavailable":
|
|
432
|
+
return "AI generation is unavailable on the SentientUI server right now (no model is configured). Nothing was queued \u2014 retry later.";
|
|
415
433
|
default:
|
|
416
434
|
break;
|
|
417
435
|
}
|
|
@@ -443,10 +461,25 @@ function apiErrorGuidance(err, extra) {
|
|
|
443
461
|
return `This feature requires a higher plan (${err.message}). Upgrade your SentientUI plan, then try again.`;
|
|
444
462
|
}
|
|
445
463
|
if (err.status === 403) {
|
|
446
|
-
return `Access denied (${err.message}). Check that your key or login has access to this project
|
|
464
|
+
return `Access denied (${err.message}). Check that your key or login has access to this project.${detailSuffix(err)}`;
|
|
465
|
+
}
|
|
466
|
+
if (err.status === 404) {
|
|
467
|
+
return `Not found (${err.message}). The project, component, variant, goal or cell does not exist, or this credential cannot see it (an sk_ server key sees only its own project). Re-read the ids with list_projects, list_components, list_goals or get_cell_matrix and retry with an exact id.` + detailSuffix(err);
|
|
468
|
+
}
|
|
469
|
+
if (err.status === 400) {
|
|
470
|
+
return `The API rejected the arguments (${err.message}).${detailSuffix(err)} Correct the input and retry \u2014 repeating the same call will fail the same way.`;
|
|
471
|
+
}
|
|
472
|
+
if (err.status === 409) {
|
|
473
|
+
return `Conflict (${err.message}): the target's current state does not allow this.${detailSuffix(err)} Read its current state first, then retry the step that makes this valid.`;
|
|
474
|
+
}
|
|
475
|
+
if (err.status === 502 || err.status === 503 || err.status === 504) {
|
|
476
|
+
return `SentientUI is temporarily unavailable (${err.status} ${err.message}). Nothing changed \u2014 wait a moment and retry.`;
|
|
447
477
|
}
|
|
448
478
|
return null;
|
|
449
479
|
}
|
|
480
|
+
function detailSuffix(err) {
|
|
481
|
+
return err.detail ? ` Server says: ${untrusted(err.detail, 300)}` : "";
|
|
482
|
+
}
|
|
450
483
|
async function settled(p) {
|
|
451
484
|
try {
|
|
452
485
|
return { ok: true, value: await p };
|
|
@@ -559,6 +592,37 @@ function registerProjectTools(server, client) {
|
|
|
559
592
|
};
|
|
560
593
|
}, CREATE_PROJECT_GUIDANCE)
|
|
561
594
|
);
|
|
595
|
+
server.registerTool(
|
|
596
|
+
"add_origin",
|
|
597
|
+
{
|
|
598
|
+
title: "Add allowed origin",
|
|
599
|
+
description: "Allow-list a site origin (scheme + host, e.g. https://www.example.com) so the SDK's events from it are accepted. Idempotent: an origin already on the list is left as is. Removing an origin is dashboard-only. Needs an editor/admin login or the project's sk_ server key. Confirm the exact origin with the user first \u2014 an allowed origin can send events into this project.",
|
|
600
|
+
inputSchema: {
|
|
601
|
+
projectId: projectIdSchema,
|
|
602
|
+
origin: z2.string().min(1).max(500).describe("The site origin, e.g. https://www.example.com (a pasted page URL is reduced to its origin)")
|
|
603
|
+
},
|
|
604
|
+
outputSchema: {
|
|
605
|
+
origins: z2.array(z2.string()).describe("The full allow-list after the change")
|
|
606
|
+
},
|
|
607
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
608
|
+
},
|
|
609
|
+
withApiErrorGuidance(async ({ projectId, origin }) => {
|
|
610
|
+
var _a;
|
|
611
|
+
const id = encodeURIComponent(projectId);
|
|
612
|
+
const res = await client.post(`/projects/${id}/origins`, { origin });
|
|
613
|
+
const origins = (_a = res.origins) != null ? _a : [];
|
|
614
|
+
return {
|
|
615
|
+
content: [{
|
|
616
|
+
type: "text",
|
|
617
|
+
text: `Allowed origins: ${origins.map((o) => untrusted(o)).join(", ") || "(none)"}. Events from these origins are accepted (other API instances pick the change up within ~30 seconds, when their key cache expires).`
|
|
618
|
+
}],
|
|
619
|
+
structuredContent: { origins }
|
|
620
|
+
};
|
|
621
|
+
}, {
|
|
622
|
+
invalid_origin: "That is not a usable origin. Pass a scheme and host, e.g. https://www.example.com.",
|
|
623
|
+
origin_required: "An origin is required, e.g. https://www.example.com."
|
|
624
|
+
})
|
|
625
|
+
);
|
|
562
626
|
server.registerTool(
|
|
563
627
|
"list_projects",
|
|
564
628
|
{
|
|
@@ -603,13 +667,16 @@ function registerProjectTools(server, client) {
|
|
|
603
667
|
"get_project_stats",
|
|
604
668
|
{
|
|
605
669
|
title: "Project health stats",
|
|
606
|
-
description: "Get health
|
|
670
|
+
description: "Get ingestion health for a project: status, events and sessions in the last 24 hours, the time of the last event, and the all-time count of calls to the SentientUI agent API (/v1/agent) \u2014 NOT MCP tool calls.",
|
|
607
671
|
inputSchema: { projectId: projectIdSchema },
|
|
608
672
|
outputSchema: {
|
|
609
673
|
status: z2.string().describe("Overall project health status"),
|
|
610
674
|
events24h: z2.number().describe("Events in the last 24 hours"),
|
|
611
675
|
sessions24h: z2.number().describe("Sessions in the last 24 hours"),
|
|
612
|
-
|
|
676
|
+
// Was "Total agent (MCP/API) calls" — but the count comes from
|
|
677
|
+
// agent_events, which only the /v1/agent endpoint writes. MCP tool calls
|
|
678
|
+
// are never in it, so an agent read its own activity as missing.
|
|
679
|
+
agentCalls: z2.number().describe("All-time calls to the /v1/agent agent API (not MCP tool calls)"),
|
|
613
680
|
lastEventAt: z2.string().nullable().describe("ISO timestamp of the last event, or null")
|
|
614
681
|
},
|
|
615
682
|
annotations: {
|
|
@@ -626,7 +693,7 @@ function registerProjectTools(server, client) {
|
|
|
626
693
|
`Status: ${stats.status}`,
|
|
627
694
|
`Events (24h): ${stats.events24h}`,
|
|
628
695
|
`Sessions (24h): ${stats.sessions24h}`,
|
|
629
|
-
`Agent calls (
|
|
696
|
+
`Agent API calls (/v1/agent, all-time): ${stats.agentCalls}`,
|
|
630
697
|
`Last event: ${(_a = stats.lastEventAt) != null ? _a : "never"}`
|
|
631
698
|
].join("\n");
|
|
632
699
|
return {
|
|
@@ -653,6 +720,10 @@ var EVIDENCE_LABEL = {
|
|
|
653
720
|
early_signal: "Early signal (still moving \u2014 not a result)",
|
|
654
721
|
moderate_evidence: "Moderate evidence (about one call in five of this strength is wrong \u2014 not decided)",
|
|
655
722
|
strong_evidence: "Strong evidence",
|
|
723
|
+
// The mirror of moderate_evidence. Before the server had it, an arm clearly
|
|
724
|
+
// behind its baseline read "Inconclusive (… without separating)" — it HAD
|
|
725
|
+
// separated, downward.
|
|
726
|
+
likely_worse: "Likely worse than the baseline (about one call in five of this strength is wrong \u2014 not decided)",
|
|
656
727
|
inconclusive: "Inconclusive (ran a full period without separating from the baseline)"
|
|
657
728
|
};
|
|
658
729
|
var STATES = new Set(Object.keys(EVIDENCE_LABEL));
|
|
@@ -703,7 +774,9 @@ function verdictOf(state, stats, isBaseline) {
|
|
|
703
774
|
var VERDICT_TEXT = {
|
|
704
775
|
ahead: "reliably AHEAD of the baseline",
|
|
705
776
|
behind: "reliably BEHIND the baseline",
|
|
706
|
-
|
|
777
|
+
// "not RELIABLY": this is printed beside moderate_evidence and likely_worse
|
|
778
|
+
// labels too, and a bare "not separated" contradicted the label next to it.
|
|
779
|
+
unclear: "not reliably separated from the baseline",
|
|
707
780
|
no_evidence: "no evidence available from the server"
|
|
708
781
|
};
|
|
709
782
|
function rateWithN(conversions, n, unit = "sessions") {
|
|
@@ -789,7 +862,7 @@ function registerComponentTools(server, client) {
|
|
|
789
862
|
conversions: z3.number().describe("Converting sessions in the window"),
|
|
790
863
|
currentCvr: z3.number().nullable().describe("conversions / sessions over the window (0-1); null at 0 sessions"),
|
|
791
864
|
lowSample: z3.boolean().describe(`True under ${MIN_EVIDENCE_SAMPLE} sessions \u2014 the rate is not interpretable on its own`),
|
|
792
|
-
evidenceState: z3.string().nullable().describe("Reliability (all time): the server's ALL-TIME evidence state vs the baseline on direct evidence \u2014 not_enough_data | early_signal | moderate_evidence | strong_evidence | inconclusive; null for the baseline or when not provided. Not a verdict on the windowed rate"),
|
|
865
|
+
evidenceState: z3.string().nullable().describe("Reliability (all time): the server's ALL-TIME evidence state vs the baseline on direct evidence \u2014 not_enough_data | early_signal | moderate_evidence | strong_evidence | likely_worse | inconclusive; null for the baseline or when not provided. Not a verdict on the windowed rate"),
|
|
793
866
|
probBeatsBaseline: z3.number().nullable().describe("P(this arm > baseline), all-time, from the server; null when not provided"),
|
|
794
867
|
reliabilityVerdict: z3.enum(["baseline", "ahead", "behind", "unclear", "no_evidence"]).describe("The all-time verdict read from evidenceState \u2014 reliability (all time), which can differ from `verdict` on the window"),
|
|
795
868
|
windowEvidenceState: z3.string().nullable().describe("The server's evidence state on the WINDOWED session conversion rate vs the baseline; null for the baseline, when the arm was not scored in the window, or on older APIs"),
|
|
@@ -1107,7 +1180,10 @@ function registerPersonaTools(server, client) {
|
|
|
1107
1180
|
"get_persona_breakdown",
|
|
1108
1181
|
{
|
|
1109
1182
|
title: "Persona breakdown",
|
|
1110
|
-
|
|
1183
|
+
// Takes no range/from/to on purpose: the API computes it over every
|
|
1184
|
+
// retained session and has no window. Saying so stops an agent from
|
|
1185
|
+
// reading it beside a 7d get_variant_performance as the same period.
|
|
1186
|
+
description: "Get the distribution of visitor persona clusters with session counts and reliability scores, over ALL retained human sessions (not windowed \u2014 this has no range input, unlike the conversion tools)." + UNTRUSTED_FIELDS_NOTE,
|
|
1111
1187
|
inputSchema: { projectId: projectIdSchema },
|
|
1112
1188
|
_meta: uiMeta("persona-breakdown"),
|
|
1113
1189
|
outputSchema: {
|
|
@@ -1168,8 +1244,13 @@ function registerGoalTools(server, client) {
|
|
|
1168
1244
|
server.registerTool(
|
|
1169
1245
|
"get_goal_funnel",
|
|
1170
1246
|
{
|
|
1171
|
-
|
|
1172
|
-
|
|
1247
|
+
// Named get_goal_funnel for compatibility (renaming a published tool
|
|
1248
|
+
// breaks every saved prompt and host allow-list), but it is NOT a funnel:
|
|
1249
|
+
// agents asked it for step drop-off and reported per-goal rates as funnel
|
|
1250
|
+
// stages. The title and the first words of the description now say what
|
|
1251
|
+
// it is, and point to the real funnel tool.
|
|
1252
|
+
title: "Goal conversions (per goal \u2014 not a step funnel)",
|
|
1253
|
+
description: "Per-goal conversion summary \u2014 NOT a step funnel (for step-by-step drop-off use list_funnels + get_funnel_report). Gets goal hit counts and unique-session conversion rates for a window (default: last 30 calendar days), plus a per-variant breakdown. NOTE: the per-variant completionRate values are ALL-TIME (bounded only by plan retention), NOT windowed \u2014 a variant completion rate needs the full assignment history as its denominator, so it does not change when you narrow `range`, and retired components keep appearing in it. Only hits/uniqueSessions/conversionRate/revenue respect the window. Per-variant rates are descriptive, not joined to the evidence verdicts \u2014 for whether an arm is ahead, use get_variant_performance." + UNTRUSTED_FIELDS_NOTE,
|
|
1173
1254
|
inputSchema: __spreadValues({ projectId: projectIdSchema }, rangeInputSchema("30d")),
|
|
1174
1255
|
_meta: uiMeta("goal-funnel"),
|
|
1175
1256
|
outputSchema: {
|
|
@@ -1350,6 +1431,51 @@ function registerGoalTools(server, client) {
|
|
|
1350
1431
|
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent };
|
|
1351
1432
|
})
|
|
1352
1433
|
);
|
|
1434
|
+
server.registerTool(
|
|
1435
|
+
"define_goal",
|
|
1436
|
+
{
|
|
1437
|
+
title: "Define a new goal",
|
|
1438
|
+
description: "Create a NEW goal (conversion signal) for a project. Create-only: it never changes an existing goal \u2014 an id that already exists, including an archived one, is refused (goal_exists); call list_goals first. It never sets or changes the PRIMARY goal (what experiments optimize): the goal is created as 'secondary' (default) or 'guardrail'; choosing the primary stays a dashboard decision. A guardrail goal can pause variants that hurt it \u2014 say so when proposing one. Event types: url_reached (needs urlPattern, e.g. /thank-you), click / form_submit (need a locator, usually easier to pick in the dashboard on-site editor, or fire from code with client.goal('<goalId>') instead), scroll_depth (needs threshold in (0, 1]). Needs an editor/admin login or the project's sk_ server key. Confirm the goal id, event and pattern with the user before calling.",
|
|
1439
|
+
inputSchema: {
|
|
1440
|
+
projectId: projectIdSchema,
|
|
1441
|
+
goalId: z6.string().min(1).max(128).refine((s) => !s.startsWith("funnel:"), "'funnel:' is reserved for funnel bindings").describe("Stable id code will reference, e.g. 'signup' or 'checkout-complete'. Must not exist yet."),
|
|
1442
|
+
event: z6.enum(["url_reached", "click", "form_submit", "scroll_depth"]).describe("What counts as a conversion"),
|
|
1443
|
+
urlPattern: z6.string().min(1).max(512).optional().describe("url_reached only: the path pattern, e.g. '/thank-you' or '/orders/*'"),
|
|
1444
|
+
locator: z6.record(z6.unknown()).optional().describe('click / form_submit only: the element locator (e.g. { "id": "signup-button" })'),
|
|
1445
|
+
threshold: z6.number().gt(0).max(1).optional().describe("scroll_depth only: how far down the page counts, in (0, 1]"),
|
|
1446
|
+
displayName: z6.string().min(1).max(128).optional().describe("Human-readable name shown in the dashboard"),
|
|
1447
|
+
role: z6.enum(["secondary", "guardrail"]).optional().describe("secondary (default) is tracked and reported; guardrail can also pause variants that hurt it. Never 'primary'."),
|
|
1448
|
+
defaultValue: z6.number().positive().max(1e9).optional().describe("Fixed worth of one conversion in the project currency (revenue goals)")
|
|
1449
|
+
},
|
|
1450
|
+
outputSchema: {
|
|
1451
|
+
goalId: z6.string(),
|
|
1452
|
+
role: z6.enum(["secondary", "guardrail"]).describe("Never primary \u2014 this tool cannot change the primary goal")
|
|
1453
|
+
},
|
|
1454
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: false }
|
|
1455
|
+
},
|
|
1456
|
+
withApiErrorGuidance(async ({ projectId, goalId, event, urlPattern, locator, threshold, displayName, role, defaultValue }) => {
|
|
1457
|
+
var _a, _b, _c;
|
|
1458
|
+
const id = encodeURIComponent(projectId);
|
|
1459
|
+
const res = await client.post(`/projects/${id}/goal-definitions`, __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({
|
|
1460
|
+
goalId,
|
|
1461
|
+
event
|
|
1462
|
+
}, urlPattern !== void 0 ? { urlPattern } : {}), locator !== void 0 ? { locator } : {}), threshold !== void 0 ? { threshold } : {}), displayName !== void 0 ? { displayName } : {}), role !== void 0 ? { role } : {}), defaultValue !== void 0 ? { defaultValue } : {}));
|
|
1463
|
+
const structuredContent = { goalId: (_a = res.goalId) != null ? _a : goalId, role: (_c = (_b = res.role) != null ? _b : role) != null ? _c : "secondary" };
|
|
1464
|
+
return {
|
|
1465
|
+
content: [{
|
|
1466
|
+
type: "text",
|
|
1467
|
+
text: `Created goal ${untrusted(structuredContent.goalId)} (${structuredContent.role}, ${event}). It is active now. The primary goal was not changed \u2014 if this should be what experiments optimize, the owner can make it primary in the dashboard. Reference the goalId verbatim from code (client.goal('<goalId>')) if the event is not tracked automatically.`
|
|
1468
|
+
}],
|
|
1469
|
+
structuredContent
|
|
1470
|
+
};
|
|
1471
|
+
}, {
|
|
1472
|
+
goal_exists: "A goal with this id already exists (it may be archived). define_goal never changes an existing goal \u2014 pick a new id (see list_goals), or edit that goal in the dashboard.",
|
|
1473
|
+
primary_not_allowed: "define_goal never sets the primary goal. Create it as secondary; the owner can make it primary in the dashboard.",
|
|
1474
|
+
invalid_goal_id: "That goal id is not allowed: use 1-128 characters, and not the reserved 'funnel:' prefix.",
|
|
1475
|
+
invalid_goal: "The goal definition is incomplete for its event type: url_reached needs urlPattern, click/form_submit need a locator, scroll_depth needs threshold.",
|
|
1476
|
+
"Not Found": "This SentientUI API does not support creating goals from MCP yet (it predates create-only goals). Define the goal in the dashboard instead."
|
|
1477
|
+
})
|
|
1478
|
+
);
|
|
1353
1479
|
}
|
|
1354
1480
|
|
|
1355
1481
|
// src/tools/funnels.ts
|
|
@@ -1559,7 +1685,9 @@ function registerLayoutTools(server, client) {
|
|
|
1559
1685
|
"get_layout_stats",
|
|
1560
1686
|
{
|
|
1561
1687
|
title: "Layout stats",
|
|
1562
|
-
|
|
1688
|
+
// No window by design: these are the bandit's cumulative pulls and reward,
|
|
1689
|
+
// the state serving reads — not a report over a period.
|
|
1690
|
+
description: "Get per-persona section layout rankings with bandit pulls and average reward \u2014 the cumulative learning state serving uses (not windowed; there is no range input). avgReward is a reward signal, not a conversion rate." + UNTRUSTED_FIELDS_NOTE,
|
|
1563
1691
|
inputSchema: { projectId: projectIdSchema },
|
|
1564
1692
|
_meta: uiMeta("layout-stats"),
|
|
1565
1693
|
outputSchema: {
|
|
@@ -1611,7 +1739,7 @@ function registerVariantWriteTools(server, client) {
|
|
|
1611
1739
|
"create_variant",
|
|
1612
1740
|
{
|
|
1613
1741
|
title: "Create managed variant",
|
|
1614
|
-
description: "Create a NO-CODE managed text variant for a component (content stored in SentientUI, rendered by <AdaptiveText>). Use this ONLY for text-only variants the user wants without a code change. For variants that will live in the codebase (full components \u2014 copy, markup, styling), use get_variant_brief and write the variant in code instead; those auto-register on deploy and do not need create_variant.
|
|
1742
|
+
description: "Create a NO-CODE managed text variant for a component (content stored in SentientUI, rendered by <AdaptiveText>). Use this ONLY for text-only variants the user wants without a code change. For variants that will live in the codebase (full components \u2014 copy, markup, styling), use get_variant_brief and write the variant in code instead; those auto-register on deploy and do not need create_variant. Works on every plan with an editor/admin login or the project's sk_ server key (anonymous demo tokens are read-only). The variant is created as a DRAFT \u2014 it serves no traffic until activated with update_variant (status 'active'). Confirm the text with the user before calling.",
|
|
1615
1743
|
inputSchema: {
|
|
1616
1744
|
projectId: projectIdSchema,
|
|
1617
1745
|
componentId: z10.string().min(1).max(200).describe("The component ID to add a variant to"),
|
|
@@ -1645,7 +1773,7 @@ function registerVariantWriteTools(server, client) {
|
|
|
1645
1773
|
return {
|
|
1646
1774
|
content: [{
|
|
1647
1775
|
type: "text",
|
|
1648
|
-
text: `Managed text variant created: ${result.variantId} ("${result.displayName}") for component ${componentId}${contentNote}. It is
|
|
1776
|
+
text: `Managed text variant created: ${result.variantId} ("${result.displayName}") for component ${componentId}${contentNote}. It is a draft and serves no traffic yet \u2014 after the user confirms, activate it with update_variant (status 'active'), or delete it with delete_variant_draft. Reminder: this is a no-code managed variant; for code-native variants, edit the code instead (see get_variant_brief).`
|
|
1649
1777
|
}],
|
|
1650
1778
|
structuredContent: {
|
|
1651
1779
|
variantId: result.variantId,
|
|
@@ -1661,20 +1789,24 @@ function registerVariantWriteTools(server, client) {
|
|
|
1661
1789
|
"pause_variant",
|
|
1662
1790
|
{
|
|
1663
1791
|
title: "Pause variant",
|
|
1664
|
-
description: "Pause a variant
|
|
1792
|
+
description: "Pause a variant: no new traffic is assigned to it until it is resumed. This changes what live visitors see, so CONFIRM with the user before calling. Undo with resume_variant.",
|
|
1665
1793
|
inputSchema: {
|
|
1666
1794
|
projectId: projectIdSchema,
|
|
1667
|
-
componentId: z10.string().describe("The component ID"),
|
|
1668
|
-
variantId: z10.string().describe("The variant ID to pause")
|
|
1795
|
+
componentId: z10.string().min(1).max(200).describe("The component ID"),
|
|
1796
|
+
variantId: z10.string().min(1).max(200).describe("The variant ID to pause")
|
|
1669
1797
|
},
|
|
1670
1798
|
outputSchema: {
|
|
1671
1799
|
variantId: z10.string(),
|
|
1672
1800
|
componentId: z10.string(),
|
|
1673
1801
|
paused: z10.literal(true).describe("The variant is now paused")
|
|
1674
1802
|
},
|
|
1803
|
+
// destructiveHint was false, so hosts that gate destructive tools behind a
|
|
1804
|
+
// confirmation ran this without asking — yet it pulls a live arm out of
|
|
1805
|
+
// serving for every visitor. It is reversible (resume_variant), but the
|
|
1806
|
+
// hint is about the change to the environment, not about undo.
|
|
1675
1807
|
annotations: {
|
|
1676
1808
|
readOnlyHint: false,
|
|
1677
|
-
destructiveHint:
|
|
1809
|
+
destructiveHint: true,
|
|
1678
1810
|
idempotentHint: true,
|
|
1679
1811
|
openWorldHint: false
|
|
1680
1812
|
}
|
|
@@ -1685,17 +1817,194 @@ function registerVariantWriteTools(server, client) {
|
|
|
1685
1817
|
return {
|
|
1686
1818
|
content: [{
|
|
1687
1819
|
type: "text",
|
|
1688
|
-
text: `Variant ${variantId} in component ${componentId}
|
|
1820
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is paused. No new traffic will be assigned to it. Undo with resume_variant.`
|
|
1689
1821
|
}],
|
|
1690
1822
|
structuredContent: { variantId, componentId, paused: true }
|
|
1691
1823
|
};
|
|
1692
1824
|
})
|
|
1693
1825
|
);
|
|
1826
|
+
server.registerTool(
|
|
1827
|
+
"resume_variant",
|
|
1828
|
+
{
|
|
1829
|
+
title: "Resume variant",
|
|
1830
|
+
description: "Resume a paused variant so it is assigned traffic again \u2014 works for a manual pause (pause_variant) and for a guardrail auto-pause (see list_guardrail_events). Resuming a guardrail-paused arm puts a variant the guardrail judged harmful back in front of visitors, so CONFIRM with the user first.",
|
|
1831
|
+
inputSchema: {
|
|
1832
|
+
projectId: projectIdSchema,
|
|
1833
|
+
componentId: z10.string().min(1).max(200).describe("The component ID"),
|
|
1834
|
+
variantId: z10.string().min(1).max(200).describe("The paused variant ID to resume")
|
|
1835
|
+
},
|
|
1836
|
+
outputSchema: {
|
|
1837
|
+
variantId: z10.string(),
|
|
1838
|
+
componentId: z10.string(),
|
|
1839
|
+
paused: z10.literal(false).describe("The variant is no longer paused")
|
|
1840
|
+
},
|
|
1841
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1842
|
+
},
|
|
1843
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1844
|
+
const id = encodeURIComponent(projectId);
|
|
1845
|
+
await client.post(`/projects/${id}/guardrails/${encodeURIComponent(componentId)}/unpause`, {
|
|
1846
|
+
variantIds: [variantId]
|
|
1847
|
+
});
|
|
1848
|
+
return {
|
|
1849
|
+
content: [{
|
|
1850
|
+
type: "text",
|
|
1851
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is resumed and will be assigned traffic again.`
|
|
1852
|
+
}],
|
|
1853
|
+
structuredContent: { variantId, componentId, paused: false }
|
|
1854
|
+
};
|
|
1855
|
+
})
|
|
1856
|
+
);
|
|
1857
|
+
server.registerTool(
|
|
1858
|
+
"update_variant",
|
|
1859
|
+
{
|
|
1860
|
+
title: "Update managed variant",
|
|
1861
|
+
description: "Edit a NO-CODE managed variant (one created with create_variant or in the dashboard): its display name, its text, or its status \u2014 'active' starts serving it to visitors, 'draft' takes it back out of rotation. Code-native variants cannot be edited here (change the code). Overwriting text or activating changes what live visitors see, so CONFIRM with the user first. Omit a field to leave it unchanged.",
|
|
1862
|
+
inputSchema: {
|
|
1863
|
+
projectId: projectIdSchema,
|
|
1864
|
+
componentId: z10.string().min(1).max(200).describe("The component ID"),
|
|
1865
|
+
variantId: z10.string().min(1).max(200).describe("The managed variant ID (dm_\u2026)"),
|
|
1866
|
+
displayName: z10.string().min(1).max(200).optional().describe("New display name"),
|
|
1867
|
+
content: z10.string().max(1e4).optional().describe("New text content (replaces the old text)"),
|
|
1868
|
+
status: z10.enum(["draft", "active"]).optional().describe("'active' serves it; 'draft' stops serving it")
|
|
1869
|
+
},
|
|
1870
|
+
outputSchema: {
|
|
1871
|
+
variantId: z10.string(),
|
|
1872
|
+
componentId: z10.string(),
|
|
1873
|
+
changed: z10.array(z10.string()).describe("Fields that were sent for update"),
|
|
1874
|
+
status: z10.enum(["draft", "active"]).nullable().describe("The new status, or null when unchanged")
|
|
1875
|
+
},
|
|
1876
|
+
// Destructive: the previous text is overwritten, not versioned.
|
|
1877
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
|
|
1878
|
+
},
|
|
1879
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId, displayName, content, status }) => {
|
|
1880
|
+
const changed = [
|
|
1881
|
+
...displayName !== void 0 ? ["displayName"] : [],
|
|
1882
|
+
...content !== void 0 ? ["content"] : [],
|
|
1883
|
+
...status !== void 0 ? ["status"] : []
|
|
1884
|
+
];
|
|
1885
|
+
if (changed.length === 0) {
|
|
1886
|
+
return {
|
|
1887
|
+
content: [{ type: "text", text: "Nothing to update \u2014 pass displayName, content and/or status." }],
|
|
1888
|
+
isError: true
|
|
1889
|
+
};
|
|
1890
|
+
}
|
|
1891
|
+
const id = encodeURIComponent(projectId);
|
|
1892
|
+
await client.patch(`/projects/${id}/variants`, { componentId, variantId, displayName, content, status });
|
|
1893
|
+
const statusNote = status === "active" ? " It is now ACTIVE and will be assigned traffic." : status === "draft" ? " It is now a draft and no longer serves traffic." : "";
|
|
1894
|
+
return {
|
|
1895
|
+
content: [{
|
|
1896
|
+
type: "text",
|
|
1897
|
+
text: `Managed variant ${untrusted(variantId)} in component ${untrusted(componentId)} updated (${changed.join(", ")}).${statusNote}`
|
|
1898
|
+
}],
|
|
1899
|
+
structuredContent: { variantId, componentId, changed, status: status != null ? status : null }
|
|
1900
|
+
};
|
|
1901
|
+
}, {
|
|
1902
|
+
// PATCH matches managed variants only, so a code-native id answers a
|
|
1903
|
+
// bare not_found that read as "that variant does not exist".
|
|
1904
|
+
not_found: "No MANAGED variant with that id exists in this component. Code-native variants (declared in <Adaptive variants>) are edited in the code, not here \u2014 check ids with list_components (a wrong projectId answers the same way)."
|
|
1905
|
+
})
|
|
1906
|
+
);
|
|
1907
|
+
server.registerTool(
|
|
1908
|
+
"delete_variant_draft",
|
|
1909
|
+
{
|
|
1910
|
+
title: "Delete draft variant",
|
|
1911
|
+
description: "Permanently delete a managed variant that is still a DRAFT (never activated). Active variants cannot be deleted \u2014 pause or retire them instead. CONFIRM with the user first: this cannot be undone.",
|
|
1912
|
+
inputSchema: {
|
|
1913
|
+
projectId: projectIdSchema,
|
|
1914
|
+
componentId: z10.string().min(1).max(200).describe("The component ID"),
|
|
1915
|
+
variantId: z10.string().min(1).max(200).describe("The draft managed variant ID (dm_\u2026)")
|
|
1916
|
+
},
|
|
1917
|
+
outputSchema: {
|
|
1918
|
+
variantId: z10.string(),
|
|
1919
|
+
componentId: z10.string(),
|
|
1920
|
+
deleted: z10.literal(true)
|
|
1921
|
+
},
|
|
1922
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
1923
|
+
},
|
|
1924
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1925
|
+
const id = encodeURIComponent(projectId);
|
|
1926
|
+
await client.delete(`/projects/${id}/variants`, { componentId, variantId });
|
|
1927
|
+
return {
|
|
1928
|
+
content: [{
|
|
1929
|
+
type: "text",
|
|
1930
|
+
text: `Draft variant ${untrusted(variantId)} in component ${untrusted(componentId)} was deleted.`
|
|
1931
|
+
}],
|
|
1932
|
+
structuredContent: { variantId, componentId, deleted: true }
|
|
1933
|
+
};
|
|
1934
|
+
}, {
|
|
1935
|
+
// The API's DELETE matches managed drafts only, so an active or
|
|
1936
|
+
// code-native variant answers a bare not_found — say why.
|
|
1937
|
+
not_found: "No managed DRAFT variant with that id exists in this component. Active and code-native variants cannot be deleted \u2014 use pause_variant or retire_variant instead (check ids with list_components; a wrong projectId answers the same way)."
|
|
1938
|
+
})
|
|
1939
|
+
);
|
|
1940
|
+
server.registerTool(
|
|
1941
|
+
"retire_variant",
|
|
1942
|
+
{
|
|
1943
|
+
title: "Retire variant",
|
|
1944
|
+
description: "Retire (archive) an ACTIVE variant: it stops serving and moves to the archived list. Works for code-native variants that were removed from the code and linger. A promoted (pinned) variant must be unpromoted in the dashboard first. CONFIRM with the user first; undo with restore_variant.",
|
|
1945
|
+
inputSchema: {
|
|
1946
|
+
projectId: projectIdSchema,
|
|
1947
|
+
componentId: z10.string().min(1).max(200).describe("The component ID"),
|
|
1948
|
+
variantId: z10.string().min(1).max(200).describe("The active variant ID to retire")
|
|
1949
|
+
},
|
|
1950
|
+
outputSchema: {
|
|
1951
|
+
variantId: z10.string(),
|
|
1952
|
+
componentId: z10.string(),
|
|
1953
|
+
status: z10.literal("retired")
|
|
1954
|
+
},
|
|
1955
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
|
|
1956
|
+
},
|
|
1957
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1958
|
+
const id = encodeURIComponent(projectId);
|
|
1959
|
+
await client.post(`/projects/${id}/variants/retire`, { componentId, variantId });
|
|
1960
|
+
return {
|
|
1961
|
+
content: [{
|
|
1962
|
+
type: "text",
|
|
1963
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is retired and no longer serves. Undo with restore_variant.`
|
|
1964
|
+
}],
|
|
1965
|
+
structuredContent: { variantId, componentId, status: "retired" }
|
|
1966
|
+
};
|
|
1967
|
+
}, {
|
|
1968
|
+
variant_promoted: "This variant is promoted (pinned as the winner), so it cannot be retired. Unpromote it in the dashboard first, then retry.",
|
|
1969
|
+
not_found: "No ACTIVE variant with that id exists in this component (it may already be retired, or still a draft), or the projectId is wrong. Check ids with list_components."
|
|
1970
|
+
})
|
|
1971
|
+
);
|
|
1972
|
+
server.registerTool(
|
|
1973
|
+
"restore_variant",
|
|
1974
|
+
{
|
|
1975
|
+
title: "Restore variant",
|
|
1976
|
+
description: "Bring a RETIRED variant back to active so it serves again. For a managed draft that was never activated use update_variant (status 'active') instead. Restoring does not clear a pause \u2014 use resume_variant for that. CONFIRM with the user first.",
|
|
1977
|
+
inputSchema: {
|
|
1978
|
+
projectId: projectIdSchema,
|
|
1979
|
+
componentId: z10.string().min(1).max(200).describe("The component ID"),
|
|
1980
|
+
variantId: z10.string().min(1).max(200).describe("The retired variant ID to restore")
|
|
1981
|
+
},
|
|
1982
|
+
outputSchema: {
|
|
1983
|
+
variantId: z10.string(),
|
|
1984
|
+
componentId: z10.string(),
|
|
1985
|
+
status: z10.literal("active")
|
|
1986
|
+
},
|
|
1987
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1988
|
+
},
|
|
1989
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1990
|
+
const id = encodeURIComponent(projectId);
|
|
1991
|
+
await client.post(`/projects/${id}/variants/restore`, { componentId, variantId });
|
|
1992
|
+
return {
|
|
1993
|
+
content: [{
|
|
1994
|
+
type: "text",
|
|
1995
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is active again. If it was also paused, call resume_variant.`
|
|
1996
|
+
}],
|
|
1997
|
+
structuredContent: { variantId, componentId, status: "active" }
|
|
1998
|
+
};
|
|
1999
|
+
})
|
|
2000
|
+
);
|
|
1694
2001
|
server.registerTool(
|
|
1695
2002
|
"refresh_insights",
|
|
1696
2003
|
{
|
|
1697
2004
|
title: "Refresh insights",
|
|
1698
|
-
|
|
2005
|
+
// The plan and role gates were undocumented, so agents on Free called it
|
|
2006
|
+
// and got a bare 403 they could not explain to the user.
|
|
2007
|
+
description: "Trigger fresh AI insight generation for a project (a paid model call). Needs the Starter plan or higher and an editor/admin role (anonymous demo tokens are read-only); advisor recommendations additionally need Growth or higher. Returns immediately; call get_insights in ~15 seconds to see results.",
|
|
1699
2008
|
inputSchema: { projectId: projectIdSchema },
|
|
1700
2009
|
outputSchema: {
|
|
1701
2010
|
projectId: z10.string(),
|
|
@@ -1747,11 +2056,21 @@ var BEST_PRACTICE_PRIORS = {
|
|
|
1747
2056
|
"Make the CTA specific and benefit-led.",
|
|
1748
2057
|
"Add a single strong proof point; remove competing distractions."
|
|
1749
2058
|
],
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
2059
|
+
// Keys must be the project context types the API accepts (projects.ts
|
|
2060
|
+
// VALID_CONTEXT_TYPES: saas | ecommerce | marketing | landing | internal).
|
|
2061
|
+
// A `marketplace` key sat here that no project could ever have, while
|
|
2062
|
+
// marketing and internal projects silently fell through to the generic list.
|
|
2063
|
+
marketing: [
|
|
2064
|
+
'Make the page answer "what is this and why should I care" in the first screen.',
|
|
2065
|
+
"Give each section one job and one next step; cut competing CTAs.",
|
|
2066
|
+
"Put the strongest proof (named customers, a hard number) near the primary CTA.",
|
|
2067
|
+
"Match the copy to where the visitor came from (campaign, search intent)."
|
|
2068
|
+
],
|
|
2069
|
+
internal: [
|
|
2070
|
+
"Optimize for task completion, not persuasion: make the next step obvious.",
|
|
2071
|
+
"Reduce steps and fields; prefill what the system already knows.",
|
|
2072
|
+
"Use plain, specific labels over marketing copy.",
|
|
2073
|
+
"Make errors and empty states say exactly what to do next."
|
|
1755
2074
|
]
|
|
1756
2075
|
};
|
|
1757
2076
|
var GENERIC_PRIORS = [
|
|
@@ -1784,7 +2103,10 @@ function guidanceFor(dataState, contextType, arms) {
|
|
|
1784
2103
|
}
|
|
1785
2104
|
case "directional": {
|
|
1786
2105
|
const inconclusive = arms.some((a) => a.state === "inconclusive");
|
|
1787
|
-
|
|
2106
|
+
const likelyWorse = arms.filter((a) => !a.isBaseline && a.state === "likely_worse").map((a) => untrusted(a.variantId));
|
|
2107
|
+
return 'No comparison on this component is decided. Early, moderate and likely-worse signals are hypotheses, not results (each is wrong about one time in five), so do not target an arm as "under-" or "out-performing". ' + (likelyWorse.length ? `Probably behind the baseline (not decided): ${likelyWorse.join(", ")} \u2014 do not build on ${likelyWorse.length === 1 ? "it" : "them"}. ` : "") + // "did not separate" is not "do not differ": the old wording asserted
|
|
2108
|
+
// an equality the evidence never measured.
|
|
2109
|
+
(inconclusive ? "At least one arm ran a full period without separating from the baseline \u2014 any difference between the existing versions is too small to detect, so make a clearly different change rather than a tweak. " : "") + "Lean on the best-practice priors below and make one focused change.";
|
|
1788
2110
|
}
|
|
1789
2111
|
case "collecting":
|
|
1790
2112
|
if (!arms.some((a) => !a.isBaseline)) {
|
|
@@ -2282,12 +2604,12 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2282
2604
|
"get_agent_traffic",
|
|
2283
2605
|
{
|
|
2284
2606
|
title: "Agent traffic",
|
|
2285
|
-
description: "Which AI agents and crawlers are reading this site: totals by type (passive crawlers, agentic browsers, agent API calls), engine breakdown, and the paths they fetch most. Defaults to the last 30 days; pass from/to
|
|
2286
|
-
|
|
2287
|
-
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
},
|
|
2607
|
+
description: "Which AI agents and crawlers are reading this site: totals by type (passive crawlers, agentic browsers, agent API calls), engine breakdown, and the paths they fetch most. Defaults to the last 30 calendar days; pass range (7d/30d/90d/all) or from/to (YYYY-MM-DD) like every other windowed tool (agent logs are retained 30 days on Free/Starter, 90 on Growth+). Agent traffic is tracked separately and never counted in conversion rate." + UNTRUSTED_FIELDS_NOTE,
|
|
2608
|
+
// This tool alone took ad-hoc ISO from/to with no range token and echoed
|
|
2609
|
+
// no window, while every other windowed tool used rangeInputSchema — so
|
|
2610
|
+
// agents passed range:'7d' here, it was silently dropped, and 30 days of
|
|
2611
|
+
// traffic was reported as a week. The endpoint uses the shared resolver.
|
|
2612
|
+
inputSchema: __spreadValues({ projectId: projectIdSchema }, rangeInputSchema("30d")),
|
|
2291
2613
|
outputSchema: {
|
|
2292
2614
|
totals: z14.object({ crawler: z14.number(), api: z14.number(), browser: z14.number() }),
|
|
2293
2615
|
engines: z14.array(
|
|
@@ -2301,20 +2623,18 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2301
2623
|
})
|
|
2302
2624
|
),
|
|
2303
2625
|
intents: z14.object({ user: z14.number(), search: z14.number(), training: z14.number(), other: z14.number() }).describe("Crawler fetches by purpose: user = an assistant answering a real person live"),
|
|
2304
|
-
topPaths: z14.array(z14.object({ path: z14.string(), count: z14.number(), engines: z14.number() }))
|
|
2626
|
+
topPaths: z14.array(z14.object({ path: z14.string(), count: z14.number(), engines: z14.number() })),
|
|
2627
|
+
window: windowOutputSchema
|
|
2305
2628
|
},
|
|
2306
2629
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
2307
2630
|
},
|
|
2308
|
-
withApiErrorGuidance(async ({ projectId, from, to }) => {
|
|
2631
|
+
withApiErrorGuidance(async ({ projectId, range, from, to }) => {
|
|
2309
2632
|
const id = encodeURIComponent(projectId);
|
|
2310
|
-
const qs = new URLSearchParams();
|
|
2311
|
-
if (from) qs.set("from", from);
|
|
2312
|
-
if (to) qs.set("to", to);
|
|
2313
|
-
const query = qs.toString();
|
|
2314
2633
|
const s = await client.get(
|
|
2315
|
-
`/projects/${id}/agent-activity/summary${
|
|
2634
|
+
`/projects/${id}/agent-activity/summary${rangeQuery({ range, from, to })}`
|
|
2316
2635
|
);
|
|
2317
|
-
const structuredContent = { totals: s.totals, engines: s.engines, intents: s.intents, topPaths: s.topPaths };
|
|
2636
|
+
const structuredContent = { totals: s.totals, engines: s.engines, intents: s.intents, topPaths: s.topPaths, window: s.window };
|
|
2637
|
+
const win = windowLine(s.window);
|
|
2318
2638
|
const total = s.totals.crawler + s.totals.api + s.totals.browser;
|
|
2319
2639
|
if (total === 0) {
|
|
2320
2640
|
return {
|
|
@@ -2326,6 +2646,7 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2326
2646
|
};
|
|
2327
2647
|
}
|
|
2328
2648
|
const lines = [
|
|
2649
|
+
...win ? [win] : [],
|
|
2329
2650
|
`Agent traffic: ${s.totals.crawler} crawler fetches, ${s.totals.api} agent API calls, ${s.totals.browser} agentic browser sessions.`,
|
|
2330
2651
|
`Live user fetches: ${s.intents.user} \xB7 Search index: ${s.intents.search} \xB7 Training: ${s.intents.training}${s.intents.other ? ` \xB7 Other: ${s.intents.other}` : ""} (a "live user fetch" = an AI assistant reading your site to answer a real person).`,
|
|
2331
2652
|
"",
|
|
@@ -2416,7 +2737,7 @@ var personaOutput = z15.object({
|
|
|
2416
2737
|
var cellOutput = z15.object({
|
|
2417
2738
|
slotId: z15.string(),
|
|
2418
2739
|
persona: z15.string(),
|
|
2419
|
-
status: z15.string().describe("pending | generating | live | error | rejected"),
|
|
2740
|
+
status: z15.string().describe("pending | generating | review (waiting for approval) | live | error | rejected"),
|
|
2420
2741
|
requestedBy: z15.string(),
|
|
2421
2742
|
armId: z15.string().nullable(),
|
|
2422
2743
|
rationale: z15.string().nullable(),
|
|
@@ -2456,6 +2777,10 @@ function registerCellTools(server, client) {
|
|
|
2456
2777
|
personas: z15.array(personaOutput),
|
|
2457
2778
|
cells: z15.array(cellOutput),
|
|
2458
2779
|
autoFill: z15.boolean(),
|
|
2780
|
+
// The API has always sent this; without it in the schema zod stripped
|
|
2781
|
+
// it, and generate_cell had no way to know a version would wait for a
|
|
2782
|
+
// human instead of publishing.
|
|
2783
|
+
reviewMode: z15.boolean().optional().describe("True when generated versions wait for approval (review_cell) instead of publishing automatically"),
|
|
2459
2784
|
// Nullable: a project with no persona set at all reports null, not a
|
|
2460
2785
|
// string. That is the NORMAL state since the default vocabulary was
|
|
2461
2786
|
// emptied, so a non-nullable schema failed output validation on most
|
|
@@ -2472,7 +2797,7 @@ function registerCellTools(server, client) {
|
|
|
2472
2797
|
const byCell = new Map(data.cells.map((c) => [`${c.slotId}::${c.persona}`, c]));
|
|
2473
2798
|
const lines = [
|
|
2474
2799
|
`Slots: ${data.slots.map((s) => `${untrusted(s.displayName)}${s.live === false ? " [draft]" : ""}`).join(", ") || "(none published)"}`,
|
|
2475
|
-
`Auto-fill on first miss: ${data.autoFill ? "ON" : "off"} \xB7 persona source: ${(_a = data.personaSource) != null ? _a : 'none (one "everyone" row)'}`
|
|
2800
|
+
`Auto-fill on first miss: ${data.autoFill ? "ON" : "off"} \xB7 review before publishing: ${data.reviewMode ? "ON (approve with review_cell)" : "off"} \xB7 persona source: ${(_a = data.personaSource) != null ? _a : 'none (one "everyone" row)'}`
|
|
2476
2801
|
];
|
|
2477
2802
|
for (const p of data.personas) {
|
|
2478
2803
|
const states = data.slots.map((s) => {
|
|
@@ -2557,7 +2882,12 @@ function registerCellTools(server, client) {
|
|
|
2557
2882
|
"generate_cell",
|
|
2558
2883
|
{
|
|
2559
2884
|
title: "Generate a cell version",
|
|
2560
|
-
|
|
2885
|
+
// The old copy promised "goes live, usually under a minute" — but with
|
|
2886
|
+
// review mode on the worker parks the version for a human (status
|
|
2887
|
+
// 'review') and nothing serves until someone approves it, and the queue
|
|
2888
|
+
// can defer a cell (retry backoff, the plan's monthly generation cap). An
|
|
2889
|
+
// agent relayed "it's live" for versions no visitor would ever see.
|
|
2890
|
+
description: "Queue AI generation of a version for one (persona, slot) cell; the worker writes it asynchronously, brand-locked. If the project has review mode on, the finished version WAITS for approval (list_cell_reviews / review_cell) and serves nobody until approved; otherwise it publishes automatically as a named option the optimizer explores. Also regenerates or retries a failed cell. Generation volume is capped per plan (Free included). Check get_cell_matrix for progress. Confirm with the user before calling \u2014 each generation is a model call against the plan quota.",
|
|
2561
2891
|
inputSchema: {
|
|
2562
2892
|
projectId: projectIdSchema,
|
|
2563
2893
|
slotId: z15.string().min(1).max(128).describe("The slot id (a matrix column)"),
|
|
@@ -2566,28 +2896,130 @@ function registerCellTools(server, client) {
|
|
|
2566
2896
|
outputSchema: {
|
|
2567
2897
|
slotId: z15.string(),
|
|
2568
2898
|
persona: z15.string(),
|
|
2569
|
-
status: z15.literal("pending").describe("Queued \u2014 check get_cell_matrix for progress")
|
|
2899
|
+
status: z15.literal("pending").describe("Queued \u2014 check get_cell_matrix for progress"),
|
|
2900
|
+
reviewMode: z15.boolean().nullable().describe("True: the version will wait for review_cell approval. False: it publishes automatically. Null: could not be read.")
|
|
2570
2901
|
},
|
|
2571
2902
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
2572
2903
|
},
|
|
2573
2904
|
withApiErrorGuidance(async ({ projectId, slotId, persona }) => {
|
|
2574
2905
|
const id = encodeURIComponent(projectId);
|
|
2575
2906
|
await client.post(`/projects/${id}/cells/generate`, { slotId, persona });
|
|
2907
|
+
const matrix = await settled(client.get(`/projects/${id}/cells`));
|
|
2908
|
+
const reviewMode = matrix.ok && typeof matrix.value.reviewMode === "boolean" ? matrix.value.reviewMode : null;
|
|
2909
|
+
const next = reviewMode === true ? "Review mode is ON: when it is written it will WAIT for approval and serve nobody until then \u2014 list it with list_cell_reviews and approve or reject it with review_cell (after the user decides)." : reviewMode === false ? "Review mode is off: once written it publishes automatically and the optimizer starts exploring it." : 'Could not read whether review mode is on \u2014 check get_cell_matrix: status "review" means it is waiting for approval (review_cell), "live" means it is serving.';
|
|
2576
2910
|
return {
|
|
2577
2911
|
content: [
|
|
2578
2912
|
{
|
|
2579
2913
|
type: "text",
|
|
2580
|
-
text: `
|
|
2914
|
+
text: `Queued a version of ${untrusted(slotId, 64)} for ${untrusted(persona, 64)}. It is written asynchronously (the queue may defer it \u2014 retries back off, and the plan caps generations). ${next} Track it with get_cell_matrix or get_cell_detail.`
|
|
2581
2915
|
}
|
|
2582
2916
|
],
|
|
2583
|
-
structuredContent: { slotId, persona, status: "pending" }
|
|
2917
|
+
structuredContent: { slotId, persona, status: "pending", reviewMode }
|
|
2918
|
+
};
|
|
2919
|
+
})
|
|
2920
|
+
);
|
|
2921
|
+
server.registerTool(
|
|
2922
|
+
"list_cell_reviews",
|
|
2923
|
+
{
|
|
2924
|
+
title: "Versions waiting for review",
|
|
2925
|
+
description: "Generated versions waiting for approval (review mode): which slot and visitor type, the proposed text or layout, and why it was written. Approve or reject each with review_cell after the user decides." + UNTRUSTED_FIELDS_NOTE,
|
|
2926
|
+
inputSchema: { projectId: projectIdSchema },
|
|
2927
|
+
outputSchema: {
|
|
2928
|
+
reviews: z15.array(
|
|
2929
|
+
z15.object({
|
|
2930
|
+
slotId: z15.string(),
|
|
2931
|
+
slotName: z15.string(),
|
|
2932
|
+
persona: z15.string(),
|
|
2933
|
+
personaDisplay: z15.string(),
|
|
2934
|
+
content: z15.string().nullable().describe("Proposed text, when the version is text (null for a block/layout version)"),
|
|
2935
|
+
rationale: z15.string().nullable(),
|
|
2936
|
+
refinedFrom: z15.string().nullable().describe("Live version this one would replace; that version keeps serving until approval"),
|
|
2937
|
+
updatedAt: z15.string()
|
|
2938
|
+
})
|
|
2939
|
+
)
|
|
2940
|
+
},
|
|
2941
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
2942
|
+
},
|
|
2943
|
+
withApiErrorGuidance(async ({ projectId }) => {
|
|
2944
|
+
var _a;
|
|
2945
|
+
const id = encodeURIComponent(projectId);
|
|
2946
|
+
const data = await client.get(`/projects/${id}/cell-reviews`);
|
|
2947
|
+
const reviews = ((_a = data.reviews) != null ? _a : []).map((r) => {
|
|
2948
|
+
var _a2, _b, _c;
|
|
2949
|
+
return {
|
|
2950
|
+
slotId: r.slotId,
|
|
2951
|
+
slotName: r.slotName,
|
|
2952
|
+
persona: r.persona,
|
|
2953
|
+
personaDisplay: r.personaDisplay,
|
|
2954
|
+
content: typeof ((_a2 = r.pendingArm) == null ? void 0 : _a2.content) === "string" ? r.pendingArm.content : null,
|
|
2955
|
+
rationale: (_b = r.rationale) != null ? _b : null,
|
|
2956
|
+
refinedFrom: (_c = r.refinedFrom) != null ? _c : null,
|
|
2957
|
+
updatedAt: String(r.updatedAt)
|
|
2958
|
+
};
|
|
2959
|
+
});
|
|
2960
|
+
if (reviews.length === 0) {
|
|
2961
|
+
return {
|
|
2962
|
+
content: [{ type: "text", text: "No generated versions are waiting for review." }],
|
|
2963
|
+
structuredContent: { reviews }
|
|
2964
|
+
};
|
|
2965
|
+
}
|
|
2966
|
+
const lines = reviews.map(
|
|
2967
|
+
(r) => [
|
|
2968
|
+
`- ${untrusted(r.slotName, 60)} (slotId ${untrusted(r.slotId, 64)}) for ${untrusted(r.personaDisplay, 60)} (persona ${untrusted(r.persona, 64)})`,
|
|
2969
|
+
r.content !== null ? ` Proposed text: ${untrusted(r.content, 300)}` : " Proposed: a designed block/layout (preview it in the dashboard)",
|
|
2970
|
+
r.rationale ? ` Why: ${untrusted(r.rationale, 300)}` : null,
|
|
2971
|
+
r.refinedFrom ? ` Would replace ${untrusted(r.refinedFrom, 64)}, which keeps serving until approval.` : null
|
|
2972
|
+
].filter((l) => l !== null).join("\n")
|
|
2973
|
+
);
|
|
2974
|
+
lines.push("", "Approve or reject each with review_cell (slotId + persona) once the user has decided.");
|
|
2975
|
+
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent: { reviews } };
|
|
2976
|
+
})
|
|
2977
|
+
);
|
|
2978
|
+
server.registerTool(
|
|
2979
|
+
"review_cell",
|
|
2980
|
+
{
|
|
2981
|
+
title: "Approve or reject a generated version",
|
|
2982
|
+
description: "Approve or reject ONE generated version waiting for review (see list_cell_reviews). 'approve' publishes it to live visitors of that type; 'reject' discards it (a rejected refinement leaves the current live version in place). This is the human decision review mode exists for \u2014 only call it with the user's explicit go-ahead.",
|
|
2983
|
+
inputSchema: {
|
|
2984
|
+
projectId: projectIdSchema,
|
|
2985
|
+
slotId: z15.string().min(1).max(128).describe("The slot id of the version under review"),
|
|
2986
|
+
persona: z15.string().min(1).max(64).describe("The persona key of the version under review"),
|
|
2987
|
+
action: z15.enum(["approve", "reject"]),
|
|
2988
|
+
feedback: z15.string().max(2e3).optional().describe("Optional reviewer note, stored with a rejection")
|
|
2989
|
+
},
|
|
2990
|
+
outputSchema: {
|
|
2991
|
+
slotId: z15.string(),
|
|
2992
|
+
persona: z15.string(),
|
|
2993
|
+
action: z15.enum(["approve", "reject"]),
|
|
2994
|
+
status: z15.string().describe("live (approved, or a rejected refinement whose incumbent keeps serving) | rejected"),
|
|
2995
|
+
armId: z15.string().nullable().describe("The published option id, on approval")
|
|
2996
|
+
},
|
|
2997
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
2998
|
+
},
|
|
2999
|
+
withApiErrorGuidance(async ({ projectId, slotId, persona, action, feedback }) => {
|
|
3000
|
+
var _a, _b;
|
|
3001
|
+
const id = encodeURIComponent(projectId);
|
|
3002
|
+
const res = await client.post(`/projects/${id}/cells/review`, {
|
|
3003
|
+
slotId,
|
|
3004
|
+
persona,
|
|
3005
|
+
action,
|
|
3006
|
+
feedback
|
|
3007
|
+
});
|
|
3008
|
+
const status = (_a = res.status) != null ? _a : action === "approve" ? "live" : "rejected";
|
|
3009
|
+
const text = action === "approve" ? `Approved: the version for ${untrusted(persona, 64)} in ${untrusted(slotId, 64)} is now live${res.armId ? ` as option ${untrusted(res.armId, 64)}` : ""}.` : status === "live" ? `Rejected: the proposed refinement for ${untrusted(persona, 64)} in ${untrusted(slotId, 64)} was discarded; the current live version keeps serving.` : `Rejected: the version for ${untrusted(persona, 64)} in ${untrusted(slotId, 64)} was discarded; that visitor type keeps seeing the original.`;
|
|
3010
|
+
return {
|
|
3011
|
+
content: [{ type: "text", text }],
|
|
3012
|
+
structuredContent: { slotId, persona, action, status, armId: (_b = res.armId) != null ? _b : null }
|
|
2584
3013
|
};
|
|
3014
|
+
}, {
|
|
3015
|
+
not_found: "No version is waiting for review in that cell (it may already have been approved or rejected). Check list_cell_reviews.",
|
|
3016
|
+
publish_failed: "Approval could not publish this version (the slot may be full of options, or its configuration changed). It stays in review \u2014 check the reason in get_cell_detail or the dashboard, then retry."
|
|
2585
3017
|
})
|
|
2586
3018
|
);
|
|
2587
3019
|
}
|
|
2588
3020
|
|
|
2589
3021
|
// src/server.ts
|
|
2590
|
-
var PKG_VERSION = true ? "0.
|
|
3022
|
+
var PKG_VERSION = true ? "0.21.0" : "0.0.0-dev";
|
|
2591
3023
|
function createMcpServer(client) {
|
|
2592
3024
|
const server = new McpServer(
|
|
2593
3025
|
{
|