@sentientui/mcp 0.19.0 → 0.20.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 +58 -26
- package/README.md +44 -28
- package/dist/{chunk-HT23NB6F.js → chunk-35I5EJTS.js} +424 -46
- package/dist/index.cjs +429 -46
- package/dist/index.js +6 -1
- package/dist/lib.cjs +473 -46
- package/dist/lib.d.cts +29 -2
- package/dist/lib.d.ts +29 -2
- package/dist/lib.js +48 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -25,9 +25,10 @@ var import_stdio = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
|
25
25
|
|
|
26
26
|
// src/api-client.ts
|
|
27
27
|
var ApiError = class extends Error {
|
|
28
|
-
constructor(status, message) {
|
|
28
|
+
constructor(status, message, detail) {
|
|
29
29
|
super(message);
|
|
30
30
|
this.status = status;
|
|
31
|
+
this.detail = detail;
|
|
31
32
|
this.name = "ApiError";
|
|
32
33
|
}
|
|
33
34
|
};
|
|
@@ -44,8 +45,14 @@ var ApiClient = class {
|
|
|
44
45
|
async post(path, body) {
|
|
45
46
|
return this.request("POST", path, body);
|
|
46
47
|
}
|
|
48
|
+
async patch(path, body) {
|
|
49
|
+
return this.request("PATCH", path, body);
|
|
50
|
+
}
|
|
51
|
+
async delete(path, body) {
|
|
52
|
+
return this.request("DELETE", path, body);
|
|
53
|
+
}
|
|
47
54
|
async request(method, path, body, isRetry = false) {
|
|
48
|
-
var _a2, _b;
|
|
55
|
+
var _a2, _b, _c;
|
|
49
56
|
const res = await fetch(`${this.baseUrl}/v1/mgmt${path}`, {
|
|
50
57
|
method,
|
|
51
58
|
headers: __spreadValues({
|
|
@@ -62,7 +69,9 @@ var ApiClient = class {
|
|
|
62
69
|
return this.request(method, path, body, true);
|
|
63
70
|
}
|
|
64
71
|
}
|
|
65
|
-
|
|
72
|
+
const code = String((_b = (_a2 = errBody.error) != null ? _a2 : errBody.message) != null ? _b : res.statusText);
|
|
73
|
+
const human = (_c = errBody.message) != null ? _c : errBody.reason;
|
|
74
|
+
throw new ApiError(res.status, code, typeof human === "string" && human !== code ? human : void 0);
|
|
66
75
|
}
|
|
67
76
|
};
|
|
68
77
|
|
|
@@ -141,7 +150,7 @@ function localDate(iso, timeZone) {
|
|
|
141
150
|
}
|
|
142
151
|
function apiErrorGuidance(err, extra) {
|
|
143
152
|
if (extra && Object.prototype.hasOwnProperty.call(extra, err.message)) {
|
|
144
|
-
return extra[err.message];
|
|
153
|
+
return extra[err.message] + detailSuffix(err);
|
|
145
154
|
}
|
|
146
155
|
switch (err.message) {
|
|
147
156
|
case "insufficient_scope":
|
|
@@ -150,6 +159,15 @@ function apiErrorGuidance(err, extra) {
|
|
|
150
159
|
return "Demo mode is read-only. Create a SentientUI account and sign in (or use a project server key) to make changes.";
|
|
151
160
|
case "insufficient_role":
|
|
152
161
|
return "Your account role does not permit this action \u2014 it needs the account owner or an admin.";
|
|
162
|
+
// The mgmt write routes answer a viewer with `role_required` (and origins
|
|
163
|
+
// with `not_authorized`), not `insufficient_role` — so every role refusal
|
|
164
|
+
// fell through to the generic 403 "check your key has access" advice and
|
|
165
|
+
// sent the agent re-authenticating for a permission it already had wrong.
|
|
166
|
+
case "role_required":
|
|
167
|
+
case "not_authorized":
|
|
168
|
+
return `Your role on this project cannot make this change \u2014 it needs an editor or admin.${detailSuffix(err)}`;
|
|
169
|
+
case "ai_unavailable":
|
|
170
|
+
return "AI generation is unavailable on the SentientUI server right now (no model is configured). Nothing was queued \u2014 retry later.";
|
|
153
171
|
default:
|
|
154
172
|
break;
|
|
155
173
|
}
|
|
@@ -181,10 +199,25 @@ function apiErrorGuidance(err, extra) {
|
|
|
181
199
|
return `This feature requires a higher plan (${err.message}). Upgrade your SentientUI plan, then try again.`;
|
|
182
200
|
}
|
|
183
201
|
if (err.status === 403) {
|
|
184
|
-
return `Access denied (${err.message}). Check that your key or login has access to this project
|
|
202
|
+
return `Access denied (${err.message}). Check that your key or login has access to this project.${detailSuffix(err)}`;
|
|
203
|
+
}
|
|
204
|
+
if (err.status === 404) {
|
|
205
|
+
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);
|
|
206
|
+
}
|
|
207
|
+
if (err.status === 400) {
|
|
208
|
+
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.`;
|
|
209
|
+
}
|
|
210
|
+
if (err.status === 409) {
|
|
211
|
+
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.`;
|
|
212
|
+
}
|
|
213
|
+
if (err.status === 502 || err.status === 503 || err.status === 504) {
|
|
214
|
+
return `SentientUI is temporarily unavailable (${err.status} ${err.message}). Nothing changed \u2014 wait a moment and retry.`;
|
|
185
215
|
}
|
|
186
216
|
return null;
|
|
187
217
|
}
|
|
218
|
+
function detailSuffix(err) {
|
|
219
|
+
return err.detail ? ` Server says: ${untrusted(err.detail, 300)}` : "";
|
|
220
|
+
}
|
|
188
221
|
async function settled(p) {
|
|
189
222
|
try {
|
|
190
223
|
return { ok: true, value: await p };
|
|
@@ -297,6 +330,37 @@ function registerProjectTools(server, client) {
|
|
|
297
330
|
};
|
|
298
331
|
}, CREATE_PROJECT_GUIDANCE)
|
|
299
332
|
);
|
|
333
|
+
server.registerTool(
|
|
334
|
+
"add_origin",
|
|
335
|
+
{
|
|
336
|
+
title: "Add allowed origin",
|
|
337
|
+
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.",
|
|
338
|
+
inputSchema: {
|
|
339
|
+
projectId: projectIdSchema,
|
|
340
|
+
origin: import_zod2.z.string().min(1).max(500).describe("The site origin, e.g. https://www.example.com (a pasted page URL is reduced to its origin)")
|
|
341
|
+
},
|
|
342
|
+
outputSchema: {
|
|
343
|
+
origins: import_zod2.z.array(import_zod2.z.string()).describe("The full allow-list after the change")
|
|
344
|
+
},
|
|
345
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
346
|
+
},
|
|
347
|
+
withApiErrorGuidance(async ({ projectId, origin }) => {
|
|
348
|
+
var _a2;
|
|
349
|
+
const id = encodeURIComponent(projectId);
|
|
350
|
+
const res = await client.post(`/projects/${id}/origins`, { origin });
|
|
351
|
+
const origins = (_a2 = res.origins) != null ? _a2 : [];
|
|
352
|
+
return {
|
|
353
|
+
content: [{
|
|
354
|
+
type: "text",
|
|
355
|
+
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).`
|
|
356
|
+
}],
|
|
357
|
+
structuredContent: { origins }
|
|
358
|
+
};
|
|
359
|
+
}, {
|
|
360
|
+
invalid_origin: "That is not a usable origin. Pass a scheme and host, e.g. https://www.example.com.",
|
|
361
|
+
origin_required: "An origin is required, e.g. https://www.example.com."
|
|
362
|
+
})
|
|
363
|
+
);
|
|
300
364
|
server.registerTool(
|
|
301
365
|
"list_projects",
|
|
302
366
|
{
|
|
@@ -341,13 +405,16 @@ function registerProjectTools(server, client) {
|
|
|
341
405
|
"get_project_stats",
|
|
342
406
|
{
|
|
343
407
|
title: "Project health stats",
|
|
344
|
-
description: "Get health
|
|
408
|
+
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.",
|
|
345
409
|
inputSchema: { projectId: projectIdSchema },
|
|
346
410
|
outputSchema: {
|
|
347
411
|
status: import_zod2.z.string().describe("Overall project health status"),
|
|
348
412
|
events24h: import_zod2.z.number().describe("Events in the last 24 hours"),
|
|
349
413
|
sessions24h: import_zod2.z.number().describe("Sessions in the last 24 hours"),
|
|
350
|
-
|
|
414
|
+
// Was "Total agent (MCP/API) calls" — but the count comes from
|
|
415
|
+
// agent_events, which only the /v1/agent endpoint writes. MCP tool calls
|
|
416
|
+
// are never in it, so an agent read its own activity as missing.
|
|
417
|
+
agentCalls: import_zod2.z.number().describe("All-time calls to the /v1/agent agent API (not MCP tool calls)"),
|
|
351
418
|
lastEventAt: import_zod2.z.string().nullable().describe("ISO timestamp of the last event, or null")
|
|
352
419
|
},
|
|
353
420
|
annotations: {
|
|
@@ -364,7 +431,7 @@ function registerProjectTools(server, client) {
|
|
|
364
431
|
`Status: ${stats.status}`,
|
|
365
432
|
`Events (24h): ${stats.events24h}`,
|
|
366
433
|
`Sessions (24h): ${stats.sessions24h}`,
|
|
367
|
-
`Agent calls (
|
|
434
|
+
`Agent API calls (/v1/agent, all-time): ${stats.agentCalls}`,
|
|
368
435
|
`Last event: ${(_a2 = stats.lastEventAt) != null ? _a2 : "never"}`
|
|
369
436
|
].join("\n");
|
|
370
437
|
return {
|
|
@@ -1111,7 +1178,10 @@ function registerPersonaTools(server, client) {
|
|
|
1111
1178
|
"get_persona_breakdown",
|
|
1112
1179
|
{
|
|
1113
1180
|
title: "Persona breakdown",
|
|
1114
|
-
|
|
1181
|
+
// Takes no range/from/to on purpose: the API computes it over every
|
|
1182
|
+
// retained session and has no window. Saying so stops an agent from
|
|
1183
|
+
// reading it beside a 7d get_variant_performance as the same period.
|
|
1184
|
+
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,
|
|
1115
1185
|
inputSchema: { projectId: projectIdSchema },
|
|
1116
1186
|
_meta: uiMeta("persona-breakdown"),
|
|
1117
1187
|
outputSchema: {
|
|
@@ -1172,8 +1242,13 @@ function registerGoalTools(server, client) {
|
|
|
1172
1242
|
server.registerTool(
|
|
1173
1243
|
"get_goal_funnel",
|
|
1174
1244
|
{
|
|
1175
|
-
|
|
1176
|
-
|
|
1245
|
+
// Named get_goal_funnel for compatibility (renaming a published tool
|
|
1246
|
+
// breaks every saved prompt and host allow-list), but it is NOT a funnel:
|
|
1247
|
+
// agents asked it for step drop-off and reported per-goal rates as funnel
|
|
1248
|
+
// stages. The title and the first words of the description now say what
|
|
1249
|
+
// it is, and point to the real funnel tool.
|
|
1250
|
+
title: "Goal conversions (per goal \u2014 not a step funnel)",
|
|
1251
|
+
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,
|
|
1177
1252
|
inputSchema: __spreadValues({ projectId: projectIdSchema }, rangeInputSchema("30d")),
|
|
1178
1253
|
_meta: uiMeta("goal-funnel"),
|
|
1179
1254
|
outputSchema: {
|
|
@@ -1563,7 +1638,9 @@ function registerLayoutTools(server, client) {
|
|
|
1563
1638
|
"get_layout_stats",
|
|
1564
1639
|
{
|
|
1565
1640
|
title: "Layout stats",
|
|
1566
|
-
|
|
1641
|
+
// No window by design: these are the bandit's cumulative pulls and reward,
|
|
1642
|
+
// the state serving reads — not a report over a period.
|
|
1643
|
+
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,
|
|
1567
1644
|
inputSchema: { projectId: projectIdSchema },
|
|
1568
1645
|
_meta: uiMeta("layout-stats"),
|
|
1569
1646
|
outputSchema: {
|
|
@@ -1615,7 +1692,7 @@ function registerVariantWriteTools(server, client) {
|
|
|
1615
1692
|
"create_variant",
|
|
1616
1693
|
{
|
|
1617
1694
|
title: "Create managed variant",
|
|
1618
|
-
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.
|
|
1695
|
+
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.",
|
|
1619
1696
|
inputSchema: {
|
|
1620
1697
|
projectId: projectIdSchema,
|
|
1621
1698
|
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID to add a variant to"),
|
|
@@ -1649,7 +1726,7 @@ function registerVariantWriteTools(server, client) {
|
|
|
1649
1726
|
return {
|
|
1650
1727
|
content: [{
|
|
1651
1728
|
type: "text",
|
|
1652
|
-
text: `Managed text variant created: ${result.variantId} ("${result.displayName}") for component ${componentId}${contentNote}. It is
|
|
1729
|
+
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).`
|
|
1653
1730
|
}],
|
|
1654
1731
|
structuredContent: {
|
|
1655
1732
|
variantId: result.variantId,
|
|
@@ -1665,20 +1742,24 @@ function registerVariantWriteTools(server, client) {
|
|
|
1665
1742
|
"pause_variant",
|
|
1666
1743
|
{
|
|
1667
1744
|
title: "Pause variant",
|
|
1668
|
-
description: "Pause a variant
|
|
1745
|
+
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.",
|
|
1669
1746
|
inputSchema: {
|
|
1670
1747
|
projectId: projectIdSchema,
|
|
1671
|
-
componentId: import_zod10.z.string().describe("The component ID"),
|
|
1672
|
-
variantId: import_zod10.z.string().describe("The variant ID to pause")
|
|
1748
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1749
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The variant ID to pause")
|
|
1673
1750
|
},
|
|
1674
1751
|
outputSchema: {
|
|
1675
1752
|
variantId: import_zod10.z.string(),
|
|
1676
1753
|
componentId: import_zod10.z.string(),
|
|
1677
1754
|
paused: import_zod10.z.literal(true).describe("The variant is now paused")
|
|
1678
1755
|
},
|
|
1756
|
+
// destructiveHint was false, so hosts that gate destructive tools behind a
|
|
1757
|
+
// confirmation ran this without asking — yet it pulls a live arm out of
|
|
1758
|
+
// serving for every visitor. It is reversible (resume_variant), but the
|
|
1759
|
+
// hint is about the change to the environment, not about undo.
|
|
1679
1760
|
annotations: {
|
|
1680
1761
|
readOnlyHint: false,
|
|
1681
|
-
destructiveHint:
|
|
1762
|
+
destructiveHint: true,
|
|
1682
1763
|
idempotentHint: true,
|
|
1683
1764
|
openWorldHint: false
|
|
1684
1765
|
}
|
|
@@ -1689,17 +1770,194 @@ function registerVariantWriteTools(server, client) {
|
|
|
1689
1770
|
return {
|
|
1690
1771
|
content: [{
|
|
1691
1772
|
type: "text",
|
|
1692
|
-
text: `Variant ${variantId} in component ${componentId}
|
|
1773
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is paused. No new traffic will be assigned to it. Undo with resume_variant.`
|
|
1693
1774
|
}],
|
|
1694
1775
|
structuredContent: { variantId, componentId, paused: true }
|
|
1695
1776
|
};
|
|
1696
1777
|
})
|
|
1697
1778
|
);
|
|
1779
|
+
server.registerTool(
|
|
1780
|
+
"resume_variant",
|
|
1781
|
+
{
|
|
1782
|
+
title: "Resume variant",
|
|
1783
|
+
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.",
|
|
1784
|
+
inputSchema: {
|
|
1785
|
+
projectId: projectIdSchema,
|
|
1786
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1787
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The paused variant ID to resume")
|
|
1788
|
+
},
|
|
1789
|
+
outputSchema: {
|
|
1790
|
+
variantId: import_zod10.z.string(),
|
|
1791
|
+
componentId: import_zod10.z.string(),
|
|
1792
|
+
paused: import_zod10.z.literal(false).describe("The variant is no longer paused")
|
|
1793
|
+
},
|
|
1794
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1795
|
+
},
|
|
1796
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1797
|
+
const id = encodeURIComponent(projectId);
|
|
1798
|
+
await client.post(`/projects/${id}/guardrails/${encodeURIComponent(componentId)}/unpause`, {
|
|
1799
|
+
variantIds: [variantId]
|
|
1800
|
+
});
|
|
1801
|
+
return {
|
|
1802
|
+
content: [{
|
|
1803
|
+
type: "text",
|
|
1804
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is resumed and will be assigned traffic again.`
|
|
1805
|
+
}],
|
|
1806
|
+
structuredContent: { variantId, componentId, paused: false }
|
|
1807
|
+
};
|
|
1808
|
+
})
|
|
1809
|
+
);
|
|
1810
|
+
server.registerTool(
|
|
1811
|
+
"update_variant",
|
|
1812
|
+
{
|
|
1813
|
+
title: "Update managed variant",
|
|
1814
|
+
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.",
|
|
1815
|
+
inputSchema: {
|
|
1816
|
+
projectId: projectIdSchema,
|
|
1817
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1818
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The managed variant ID (dm_\u2026)"),
|
|
1819
|
+
displayName: import_zod10.z.string().min(1).max(200).optional().describe("New display name"),
|
|
1820
|
+
content: import_zod10.z.string().max(1e4).optional().describe("New text content (replaces the old text)"),
|
|
1821
|
+
status: import_zod10.z.enum(["draft", "active"]).optional().describe("'active' serves it; 'draft' stops serving it")
|
|
1822
|
+
},
|
|
1823
|
+
outputSchema: {
|
|
1824
|
+
variantId: import_zod10.z.string(),
|
|
1825
|
+
componentId: import_zod10.z.string(),
|
|
1826
|
+
changed: import_zod10.z.array(import_zod10.z.string()).describe("Fields that were sent for update"),
|
|
1827
|
+
status: import_zod10.z.enum(["draft", "active"]).nullable().describe("The new status, or null when unchanged")
|
|
1828
|
+
},
|
|
1829
|
+
// Destructive: the previous text is overwritten, not versioned.
|
|
1830
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
|
|
1831
|
+
},
|
|
1832
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId, displayName, content, status }) => {
|
|
1833
|
+
const changed = [
|
|
1834
|
+
...displayName !== void 0 ? ["displayName"] : [],
|
|
1835
|
+
...content !== void 0 ? ["content"] : [],
|
|
1836
|
+
...status !== void 0 ? ["status"] : []
|
|
1837
|
+
];
|
|
1838
|
+
if (changed.length === 0) {
|
|
1839
|
+
return {
|
|
1840
|
+
content: [{ type: "text", text: "Nothing to update \u2014 pass displayName, content and/or status." }],
|
|
1841
|
+
isError: true
|
|
1842
|
+
};
|
|
1843
|
+
}
|
|
1844
|
+
const id = encodeURIComponent(projectId);
|
|
1845
|
+
await client.patch(`/projects/${id}/variants`, { componentId, variantId, displayName, content, status });
|
|
1846
|
+
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." : "";
|
|
1847
|
+
return {
|
|
1848
|
+
content: [{
|
|
1849
|
+
type: "text",
|
|
1850
|
+
text: `Managed variant ${untrusted(variantId)} in component ${untrusted(componentId)} updated (${changed.join(", ")}).${statusNote}`
|
|
1851
|
+
}],
|
|
1852
|
+
structuredContent: { variantId, componentId, changed, status: status != null ? status : null }
|
|
1853
|
+
};
|
|
1854
|
+
}, {
|
|
1855
|
+
// PATCH matches managed variants only, so a code-native id answers a
|
|
1856
|
+
// bare not_found that read as "that variant does not exist".
|
|
1857
|
+
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)."
|
|
1858
|
+
})
|
|
1859
|
+
);
|
|
1860
|
+
server.registerTool(
|
|
1861
|
+
"delete_variant_draft",
|
|
1862
|
+
{
|
|
1863
|
+
title: "Delete draft variant",
|
|
1864
|
+
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.",
|
|
1865
|
+
inputSchema: {
|
|
1866
|
+
projectId: projectIdSchema,
|
|
1867
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1868
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The draft managed variant ID (dm_\u2026)")
|
|
1869
|
+
},
|
|
1870
|
+
outputSchema: {
|
|
1871
|
+
variantId: import_zod10.z.string(),
|
|
1872
|
+
componentId: import_zod10.z.string(),
|
|
1873
|
+
deleted: import_zod10.z.literal(true)
|
|
1874
|
+
},
|
|
1875
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
1876
|
+
},
|
|
1877
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1878
|
+
const id = encodeURIComponent(projectId);
|
|
1879
|
+
await client.delete(`/projects/${id}/variants`, { componentId, variantId });
|
|
1880
|
+
return {
|
|
1881
|
+
content: [{
|
|
1882
|
+
type: "text",
|
|
1883
|
+
text: `Draft variant ${untrusted(variantId)} in component ${untrusted(componentId)} was deleted.`
|
|
1884
|
+
}],
|
|
1885
|
+
structuredContent: { variantId, componentId, deleted: true }
|
|
1886
|
+
};
|
|
1887
|
+
}, {
|
|
1888
|
+
// The API's DELETE matches managed drafts only, so an active or
|
|
1889
|
+
// code-native variant answers a bare not_found — say why.
|
|
1890
|
+
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)."
|
|
1891
|
+
})
|
|
1892
|
+
);
|
|
1893
|
+
server.registerTool(
|
|
1894
|
+
"retire_variant",
|
|
1895
|
+
{
|
|
1896
|
+
title: "Retire variant",
|
|
1897
|
+
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.",
|
|
1898
|
+
inputSchema: {
|
|
1899
|
+
projectId: projectIdSchema,
|
|
1900
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1901
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The active variant ID to retire")
|
|
1902
|
+
},
|
|
1903
|
+
outputSchema: {
|
|
1904
|
+
variantId: import_zod10.z.string(),
|
|
1905
|
+
componentId: import_zod10.z.string(),
|
|
1906
|
+
status: import_zod10.z.literal("retired")
|
|
1907
|
+
},
|
|
1908
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false }
|
|
1909
|
+
},
|
|
1910
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1911
|
+
const id = encodeURIComponent(projectId);
|
|
1912
|
+
await client.post(`/projects/${id}/variants/retire`, { componentId, variantId });
|
|
1913
|
+
return {
|
|
1914
|
+
content: [{
|
|
1915
|
+
type: "text",
|
|
1916
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is retired and no longer serves. Undo with restore_variant.`
|
|
1917
|
+
}],
|
|
1918
|
+
structuredContent: { variantId, componentId, status: "retired" }
|
|
1919
|
+
};
|
|
1920
|
+
}, {
|
|
1921
|
+
variant_promoted: "This variant is promoted (pinned as the winner), so it cannot be retired. Unpromote it in the dashboard first, then retry.",
|
|
1922
|
+
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."
|
|
1923
|
+
})
|
|
1924
|
+
);
|
|
1925
|
+
server.registerTool(
|
|
1926
|
+
"restore_variant",
|
|
1927
|
+
{
|
|
1928
|
+
title: "Restore variant",
|
|
1929
|
+
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.",
|
|
1930
|
+
inputSchema: {
|
|
1931
|
+
projectId: projectIdSchema,
|
|
1932
|
+
componentId: import_zod10.z.string().min(1).max(200).describe("The component ID"),
|
|
1933
|
+
variantId: import_zod10.z.string().min(1).max(200).describe("The retired variant ID to restore")
|
|
1934
|
+
},
|
|
1935
|
+
outputSchema: {
|
|
1936
|
+
variantId: import_zod10.z.string(),
|
|
1937
|
+
componentId: import_zod10.z.string(),
|
|
1938
|
+
status: import_zod10.z.literal("active")
|
|
1939
|
+
},
|
|
1940
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1941
|
+
},
|
|
1942
|
+
withApiErrorGuidance(async ({ projectId, componentId, variantId }) => {
|
|
1943
|
+
const id = encodeURIComponent(projectId);
|
|
1944
|
+
await client.post(`/projects/${id}/variants/restore`, { componentId, variantId });
|
|
1945
|
+
return {
|
|
1946
|
+
content: [{
|
|
1947
|
+
type: "text",
|
|
1948
|
+
text: `Variant ${untrusted(variantId)} in component ${untrusted(componentId)} is active again. If it was also paused, call resume_variant.`
|
|
1949
|
+
}],
|
|
1950
|
+
structuredContent: { variantId, componentId, status: "active" }
|
|
1951
|
+
};
|
|
1952
|
+
})
|
|
1953
|
+
);
|
|
1698
1954
|
server.registerTool(
|
|
1699
1955
|
"refresh_insights",
|
|
1700
1956
|
{
|
|
1701
1957
|
title: "Refresh insights",
|
|
1702
|
-
|
|
1958
|
+
// The plan and role gates were undocumented, so agents on Free called it
|
|
1959
|
+
// and got a bare 403 they could not explain to the user.
|
|
1960
|
+
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.",
|
|
1703
1961
|
inputSchema: { projectId: projectIdSchema },
|
|
1704
1962
|
outputSchema: {
|
|
1705
1963
|
projectId: import_zod10.z.string(),
|
|
@@ -1751,11 +2009,21 @@ var BEST_PRACTICE_PRIORS = {
|
|
|
1751
2009
|
"Make the CTA specific and benefit-led.",
|
|
1752
2010
|
"Add a single strong proof point; remove competing distractions."
|
|
1753
2011
|
],
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
2012
|
+
// Keys must be the project context types the API accepts (projects.ts
|
|
2013
|
+
// VALID_CONTEXT_TYPES: saas | ecommerce | marketing | landing | internal).
|
|
2014
|
+
// A `marketplace` key sat here that no project could ever have, while
|
|
2015
|
+
// marketing and internal projects silently fell through to the generic list.
|
|
2016
|
+
marketing: [
|
|
2017
|
+
'Make the page answer "what is this and why should I care" in the first screen.',
|
|
2018
|
+
"Give each section one job and one next step; cut competing CTAs.",
|
|
2019
|
+
"Put the strongest proof (named customers, a hard number) near the primary CTA.",
|
|
2020
|
+
"Match the copy to where the visitor came from (campaign, search intent)."
|
|
2021
|
+
],
|
|
2022
|
+
internal: [
|
|
2023
|
+
"Optimize for task completion, not persuasion: make the next step obvious.",
|
|
2024
|
+
"Reduce steps and fields; prefill what the system already knows.",
|
|
2025
|
+
"Use plain, specific labels over marketing copy.",
|
|
2026
|
+
"Make errors and empty states say exactly what to do next."
|
|
1759
2027
|
]
|
|
1760
2028
|
};
|
|
1761
2029
|
var GENERIC_PRIORS = [
|
|
@@ -2286,12 +2554,12 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2286
2554
|
"get_agent_traffic",
|
|
2287
2555
|
{
|
|
2288
2556
|
title: "Agent traffic",
|
|
2289
|
-
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
|
|
2290
|
-
|
|
2291
|
-
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
},
|
|
2557
|
+
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,
|
|
2558
|
+
// This tool alone took ad-hoc ISO from/to with no range token and echoed
|
|
2559
|
+
// no window, while every other windowed tool used rangeInputSchema — so
|
|
2560
|
+
// agents passed range:'7d' here, it was silently dropped, and 30 days of
|
|
2561
|
+
// traffic was reported as a week. The endpoint uses the shared resolver.
|
|
2562
|
+
inputSchema: __spreadValues({ projectId: projectIdSchema }, rangeInputSchema("30d")),
|
|
2295
2563
|
outputSchema: {
|
|
2296
2564
|
totals: import_zod14.z.object({ crawler: import_zod14.z.number(), api: import_zod14.z.number(), browser: import_zod14.z.number() }),
|
|
2297
2565
|
engines: import_zod14.z.array(
|
|
@@ -2305,20 +2573,18 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2305
2573
|
})
|
|
2306
2574
|
),
|
|
2307
2575
|
intents: import_zod14.z.object({ user: import_zod14.z.number(), search: import_zod14.z.number(), training: import_zod14.z.number(), other: import_zod14.z.number() }).describe("Crawler fetches by purpose: user = an assistant answering a real person live"),
|
|
2308
|
-
topPaths: import_zod14.z.array(import_zod14.z.object({ path: import_zod14.z.string(), count: import_zod14.z.number(), engines: import_zod14.z.number() }))
|
|
2576
|
+
topPaths: import_zod14.z.array(import_zod14.z.object({ path: import_zod14.z.string(), count: import_zod14.z.number(), engines: import_zod14.z.number() })),
|
|
2577
|
+
window: windowOutputSchema
|
|
2309
2578
|
},
|
|
2310
2579
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
2311
2580
|
},
|
|
2312
|
-
withApiErrorGuidance(async ({ projectId, from, to }) => {
|
|
2581
|
+
withApiErrorGuidance(async ({ projectId, range, from, to }) => {
|
|
2313
2582
|
const id = encodeURIComponent(projectId);
|
|
2314
|
-
const qs = new URLSearchParams();
|
|
2315
|
-
if (from) qs.set("from", from);
|
|
2316
|
-
if (to) qs.set("to", to);
|
|
2317
|
-
const query = qs.toString();
|
|
2318
2583
|
const s = await client.get(
|
|
2319
|
-
`/projects/${id}/agent-activity/summary${
|
|
2584
|
+
`/projects/${id}/agent-activity/summary${rangeQuery({ range, from, to })}`
|
|
2320
2585
|
);
|
|
2321
|
-
const structuredContent = { totals: s.totals, engines: s.engines, intents: s.intents, topPaths: s.topPaths };
|
|
2586
|
+
const structuredContent = { totals: s.totals, engines: s.engines, intents: s.intents, topPaths: s.topPaths, window: s.window };
|
|
2587
|
+
const win = windowLine(s.window);
|
|
2322
2588
|
const total = s.totals.crawler + s.totals.api + s.totals.browser;
|
|
2323
2589
|
if (total === 0) {
|
|
2324
2590
|
return {
|
|
@@ -2330,6 +2596,7 @@ function registerAgentTrafficTools(server, client) {
|
|
|
2330
2596
|
};
|
|
2331
2597
|
}
|
|
2332
2598
|
const lines = [
|
|
2599
|
+
...win ? [win] : [],
|
|
2333
2600
|
`Agent traffic: ${s.totals.crawler} crawler fetches, ${s.totals.api} agent API calls, ${s.totals.browser} agentic browser sessions.`,
|
|
2334
2601
|
`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).`,
|
|
2335
2602
|
"",
|
|
@@ -2420,7 +2687,7 @@ var personaOutput = import_zod15.z.object({
|
|
|
2420
2687
|
var cellOutput = import_zod15.z.object({
|
|
2421
2688
|
slotId: import_zod15.z.string(),
|
|
2422
2689
|
persona: import_zod15.z.string(),
|
|
2423
|
-
status: import_zod15.z.string().describe("pending | generating | live | error | rejected"),
|
|
2690
|
+
status: import_zod15.z.string().describe("pending | generating | review (waiting for approval) | live | error | rejected"),
|
|
2424
2691
|
requestedBy: import_zod15.z.string(),
|
|
2425
2692
|
armId: import_zod15.z.string().nullable(),
|
|
2426
2693
|
rationale: import_zod15.z.string().nullable(),
|
|
@@ -2460,6 +2727,10 @@ function registerCellTools(server, client) {
|
|
|
2460
2727
|
personas: import_zod15.z.array(personaOutput),
|
|
2461
2728
|
cells: import_zod15.z.array(cellOutput),
|
|
2462
2729
|
autoFill: import_zod15.z.boolean(),
|
|
2730
|
+
// The API has always sent this; without it in the schema zod stripped
|
|
2731
|
+
// it, and generate_cell had no way to know a version would wait for a
|
|
2732
|
+
// human instead of publishing.
|
|
2733
|
+
reviewMode: import_zod15.z.boolean().optional().describe("True when generated versions wait for approval (review_cell) instead of publishing automatically"),
|
|
2463
2734
|
// Nullable: a project with no persona set at all reports null, not a
|
|
2464
2735
|
// string. That is the NORMAL state since the default vocabulary was
|
|
2465
2736
|
// emptied, so a non-nullable schema failed output validation on most
|
|
@@ -2476,7 +2747,7 @@ function registerCellTools(server, client) {
|
|
|
2476
2747
|
const byCell = new Map(data.cells.map((c) => [`${c.slotId}::${c.persona}`, c]));
|
|
2477
2748
|
const lines = [
|
|
2478
2749
|
`Slots: ${data.slots.map((s) => `${untrusted(s.displayName)}${s.live === false ? " [draft]" : ""}`).join(", ") || "(none published)"}`,
|
|
2479
|
-
`Auto-fill on first miss: ${data.autoFill ? "ON" : "off"} \xB7 persona source: ${(_a2 = data.personaSource) != null ? _a2 : 'none (one "everyone" row)'}`
|
|
2750
|
+
`Auto-fill on first miss: ${data.autoFill ? "ON" : "off"} \xB7 review before publishing: ${data.reviewMode ? "ON (approve with review_cell)" : "off"} \xB7 persona source: ${(_a2 = data.personaSource) != null ? _a2 : 'none (one "everyone" row)'}`
|
|
2480
2751
|
];
|
|
2481
2752
|
for (const p of data.personas) {
|
|
2482
2753
|
const states = data.slots.map((s) => {
|
|
@@ -2561,7 +2832,12 @@ function registerCellTools(server, client) {
|
|
|
2561
2832
|
"generate_cell",
|
|
2562
2833
|
{
|
|
2563
2834
|
title: "Generate a cell version",
|
|
2564
|
-
|
|
2835
|
+
// The old copy promised "goes live, usually under a minute" — but with
|
|
2836
|
+
// review mode on the worker parks the version for a human (status
|
|
2837
|
+
// 'review') and nothing serves until someone approves it, and the queue
|
|
2838
|
+
// can defer a cell (retry backoff, the plan's monthly generation cap). An
|
|
2839
|
+
// agent relayed "it's live" for versions no visitor would ever see.
|
|
2840
|
+
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.",
|
|
2565
2841
|
inputSchema: {
|
|
2566
2842
|
projectId: projectIdSchema,
|
|
2567
2843
|
slotId: import_zod15.z.string().min(1).max(128).describe("The slot id (a matrix column)"),
|
|
@@ -2570,28 +2846,130 @@ function registerCellTools(server, client) {
|
|
|
2570
2846
|
outputSchema: {
|
|
2571
2847
|
slotId: import_zod15.z.string(),
|
|
2572
2848
|
persona: import_zod15.z.string(),
|
|
2573
|
-
status: import_zod15.z.literal("pending").describe("Queued \u2014 check get_cell_matrix for progress")
|
|
2849
|
+
status: import_zod15.z.literal("pending").describe("Queued \u2014 check get_cell_matrix for progress"),
|
|
2850
|
+
reviewMode: import_zod15.z.boolean().nullable().describe("True: the version will wait for review_cell approval. False: it publishes automatically. Null: could not be read.")
|
|
2574
2851
|
},
|
|
2575
2852
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
2576
2853
|
},
|
|
2577
2854
|
withApiErrorGuidance(async ({ projectId, slotId, persona }) => {
|
|
2578
2855
|
const id = encodeURIComponent(projectId);
|
|
2579
2856
|
await client.post(`/projects/${id}/cells/generate`, { slotId, persona });
|
|
2857
|
+
const matrix = await settled(client.get(`/projects/${id}/cells`));
|
|
2858
|
+
const reviewMode = matrix.ok && typeof matrix.value.reviewMode === "boolean" ? matrix.value.reviewMode : null;
|
|
2859
|
+
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.';
|
|
2580
2860
|
return {
|
|
2581
2861
|
content: [
|
|
2582
2862
|
{
|
|
2583
2863
|
type: "text",
|
|
2584
|
-
text: `
|
|
2864
|
+
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.`
|
|
2585
2865
|
}
|
|
2586
2866
|
],
|
|
2587
|
-
structuredContent: { slotId, persona, status: "pending" }
|
|
2867
|
+
structuredContent: { slotId, persona, status: "pending", reviewMode }
|
|
2588
2868
|
};
|
|
2589
2869
|
})
|
|
2590
2870
|
);
|
|
2871
|
+
server.registerTool(
|
|
2872
|
+
"list_cell_reviews",
|
|
2873
|
+
{
|
|
2874
|
+
title: "Versions waiting for review",
|
|
2875
|
+
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,
|
|
2876
|
+
inputSchema: { projectId: projectIdSchema },
|
|
2877
|
+
outputSchema: {
|
|
2878
|
+
reviews: import_zod15.z.array(
|
|
2879
|
+
import_zod15.z.object({
|
|
2880
|
+
slotId: import_zod15.z.string(),
|
|
2881
|
+
slotName: import_zod15.z.string(),
|
|
2882
|
+
persona: import_zod15.z.string(),
|
|
2883
|
+
personaDisplay: import_zod15.z.string(),
|
|
2884
|
+
content: import_zod15.z.string().nullable().describe("Proposed text, when the version is text (null for a block/layout version)"),
|
|
2885
|
+
rationale: import_zod15.z.string().nullable(),
|
|
2886
|
+
refinedFrom: import_zod15.z.string().nullable().describe("Live version this one would replace; that version keeps serving until approval"),
|
|
2887
|
+
updatedAt: import_zod15.z.string()
|
|
2888
|
+
})
|
|
2889
|
+
)
|
|
2890
|
+
},
|
|
2891
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
2892
|
+
},
|
|
2893
|
+
withApiErrorGuidance(async ({ projectId }) => {
|
|
2894
|
+
var _a2;
|
|
2895
|
+
const id = encodeURIComponent(projectId);
|
|
2896
|
+
const data = await client.get(`/projects/${id}/cell-reviews`);
|
|
2897
|
+
const reviews = ((_a2 = data.reviews) != null ? _a2 : []).map((r) => {
|
|
2898
|
+
var _a3, _b, _c;
|
|
2899
|
+
return {
|
|
2900
|
+
slotId: r.slotId,
|
|
2901
|
+
slotName: r.slotName,
|
|
2902
|
+
persona: r.persona,
|
|
2903
|
+
personaDisplay: r.personaDisplay,
|
|
2904
|
+
content: typeof ((_a3 = r.pendingArm) == null ? void 0 : _a3.content) === "string" ? r.pendingArm.content : null,
|
|
2905
|
+
rationale: (_b = r.rationale) != null ? _b : null,
|
|
2906
|
+
refinedFrom: (_c = r.refinedFrom) != null ? _c : null,
|
|
2907
|
+
updatedAt: String(r.updatedAt)
|
|
2908
|
+
};
|
|
2909
|
+
});
|
|
2910
|
+
if (reviews.length === 0) {
|
|
2911
|
+
return {
|
|
2912
|
+
content: [{ type: "text", text: "No generated versions are waiting for review." }],
|
|
2913
|
+
structuredContent: { reviews }
|
|
2914
|
+
};
|
|
2915
|
+
}
|
|
2916
|
+
const lines = reviews.map(
|
|
2917
|
+
(r) => [
|
|
2918
|
+
`- ${untrusted(r.slotName, 60)} (slotId ${untrusted(r.slotId, 64)}) for ${untrusted(r.personaDisplay, 60)} (persona ${untrusted(r.persona, 64)})`,
|
|
2919
|
+
r.content !== null ? ` Proposed text: ${untrusted(r.content, 300)}` : " Proposed: a designed block/layout (preview it in the dashboard)",
|
|
2920
|
+
r.rationale ? ` Why: ${untrusted(r.rationale, 300)}` : null,
|
|
2921
|
+
r.refinedFrom ? ` Would replace ${untrusted(r.refinedFrom, 64)}, which keeps serving until approval.` : null
|
|
2922
|
+
].filter((l) => l !== null).join("\n")
|
|
2923
|
+
);
|
|
2924
|
+
lines.push("", "Approve or reject each with review_cell (slotId + persona) once the user has decided.");
|
|
2925
|
+
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent: { reviews } };
|
|
2926
|
+
})
|
|
2927
|
+
);
|
|
2928
|
+
server.registerTool(
|
|
2929
|
+
"review_cell",
|
|
2930
|
+
{
|
|
2931
|
+
title: "Approve or reject a generated version",
|
|
2932
|
+
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.",
|
|
2933
|
+
inputSchema: {
|
|
2934
|
+
projectId: projectIdSchema,
|
|
2935
|
+
slotId: import_zod15.z.string().min(1).max(128).describe("The slot id of the version under review"),
|
|
2936
|
+
persona: import_zod15.z.string().min(1).max(64).describe("The persona key of the version under review"),
|
|
2937
|
+
action: import_zod15.z.enum(["approve", "reject"]),
|
|
2938
|
+
feedback: import_zod15.z.string().max(2e3).optional().describe("Optional reviewer note, stored with a rejection")
|
|
2939
|
+
},
|
|
2940
|
+
outputSchema: {
|
|
2941
|
+
slotId: import_zod15.z.string(),
|
|
2942
|
+
persona: import_zod15.z.string(),
|
|
2943
|
+
action: import_zod15.z.enum(["approve", "reject"]),
|
|
2944
|
+
status: import_zod15.z.string().describe("live (approved, or a rejected refinement whose incumbent keeps serving) | rejected"),
|
|
2945
|
+
armId: import_zod15.z.string().nullable().describe("The published option id, on approval")
|
|
2946
|
+
},
|
|
2947
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
2948
|
+
},
|
|
2949
|
+
withApiErrorGuidance(async ({ projectId, slotId, persona, action, feedback }) => {
|
|
2950
|
+
var _a2, _b;
|
|
2951
|
+
const id = encodeURIComponent(projectId);
|
|
2952
|
+
const res = await client.post(`/projects/${id}/cells/review`, {
|
|
2953
|
+
slotId,
|
|
2954
|
+
persona,
|
|
2955
|
+
action,
|
|
2956
|
+
feedback
|
|
2957
|
+
});
|
|
2958
|
+
const status = (_a2 = res.status) != null ? _a2 : action === "approve" ? "live" : "rejected";
|
|
2959
|
+
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.`;
|
|
2960
|
+
return {
|
|
2961
|
+
content: [{ type: "text", text }],
|
|
2962
|
+
structuredContent: { slotId, persona, action, status, armId: (_b = res.armId) != null ? _b : null }
|
|
2963
|
+
};
|
|
2964
|
+
}, {
|
|
2965
|
+
not_found: "No version is waiting for review in that cell (it may already have been approved or rejected). Check list_cell_reviews.",
|
|
2966
|
+
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."
|
|
2967
|
+
})
|
|
2968
|
+
);
|
|
2591
2969
|
}
|
|
2592
2970
|
|
|
2593
2971
|
// src/server.ts
|
|
2594
|
-
var PKG_VERSION = true ? "0.
|
|
2972
|
+
var PKG_VERSION = true ? "0.20.0" : "0.0.0-dev";
|
|
2595
2973
|
function createMcpServer(client) {
|
|
2596
2974
|
const server = new import_mcp.McpServer(
|
|
2597
2975
|
{
|
|
@@ -2706,6 +3084,11 @@ async function main() {
|
|
|
2706
3084
|
"SENTIENTUI_API_KEY is set but empty. Set it to a real server key (sk_\u2026), or unset it entirely to use anonymous demo mode."
|
|
2707
3085
|
);
|
|
2708
3086
|
}
|
|
3087
|
+
if (apiKey && /^pk_/i.test(apiKey)) {
|
|
3088
|
+
throw new Error(
|
|
3089
|
+
"SENTIENTUI_API_KEY is a pk_ publishable key \u2014 that key is for the browser SDK and cannot read or manage project data. Use the project's sk_ server key (Dashboard \u2192 Settings \u2192 API keys \u2192 Server key), or connect by URL (https://api.sentient-ui.com/mcp) and sign in."
|
|
3090
|
+
);
|
|
3091
|
+
}
|
|
2709
3092
|
if (!apiKey) {
|
|
2710
3093
|
apiKey = await resolveDemoToken();
|
|
2711
3094
|
refreshApiKey = refreshDemoToken;
|