@sentientui/mcp 0.26.0 → 0.27.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 +59 -7
- package/README.md +21 -3
- package/dist/{chunk-RRJAIZNT.js → chunk-K2UZ3IVC.js} +510 -252
- package/dist/index.cjs +510 -252
- package/dist/index.js +1 -1
- package/dist/lib.cjs +513 -254
- package/dist/lib.js +4 -3
- package/package.json +1 -1
|
@@ -194,16 +194,26 @@ var BOOTSTRAP_JS = `
|
|
|
194
194
|
var RENDER_JS = {
|
|
195
195
|
"persona-breakdown": `
|
|
196
196
|
window.__render = function(data){
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
var
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
197
|
+
// Served-as audiences (the Matrix share), then behaviour groups \u2014 kept
|
|
198
|
+
// apart: a behaviour group is visitors who behaved alike, never an
|
|
199
|
+
// audience, and it is never drawn under an audience's name.
|
|
200
|
+
var personas = (data && data.personas) || [];
|
|
201
|
+
var groups = (data && data.behaviourGroups) || [];
|
|
202
|
+
var total = (data && data.totalPeople) || 0;
|
|
203
|
+
el('sub').textContent = total + ' people by the audience they were served as, last ' + ((data && data.windowDays) || 30) + ' days';
|
|
204
|
+
if (!total && !groups.length) { showEmpty('No served visitors yet \u2014 nothing to break down.'); return; }
|
|
205
|
+
var html = personas.map(function(p){
|
|
206
|
+
return barRow(p.name, pct1(p.sharePct), p.sharePct, p.people + ' people');
|
|
206
207
|
}).join('');
|
|
208
|
+
if (groups.length) {
|
|
209
|
+
var groupTotal = groups.reduce(function(a, g){ return a + (Number(g.people) || 0); }, 0);
|
|
210
|
+
html += '<p class="sub" style="margin-top:14px">Behaviour groups \u2014 visitors who behaved alike. Not audiences: nothing is shown to a group.</p>';
|
|
211
|
+
html += groups.map(function(g){
|
|
212
|
+
var share = groupTotal > 0 ? (g.people / groupTotal) * 100 : 0;
|
|
213
|
+
return barRow(g.name, g.people + ' people', share, g.description || '');
|
|
214
|
+
}).join('');
|
|
215
|
+
}
|
|
216
|
+
el('viz').innerHTML = html;
|
|
207
217
|
};
|
|
208
218
|
`,
|
|
209
219
|
"variant-performance": `
|
|
@@ -683,7 +693,7 @@ function registerProjectTools(server, client) {
|
|
|
683
693
|
"get_project_stats",
|
|
684
694
|
{
|
|
685
695
|
title: "Project health stats",
|
|
686
|
-
description:
|
|
696
|
+
description: `Get ingestion health for a project: status, events in the last 24 hours, the People count for the same window (visitors who ran the page, interacted and passed the bot check), how many visitors are still being analysed, how many are automated, 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. Also lists domains the snippet keeps running on that are NOT allowed, so their visits are turned away (the usual answer to "why isn't my site tracking?"; fix with add_origin). Use this first when a site reports no data.`,
|
|
687
697
|
inputSchema: { projectId: projectIdSchema },
|
|
688
698
|
outputSchema: {
|
|
689
699
|
status: z2.string().describe("Overall project health status"),
|
|
@@ -694,11 +704,23 @@ function registerProjectTools(server, client) {
|
|
|
694
704
|
people: z2.number().nullable().describe("People in the last 24 hours: visitors who ran the page, interacted and passed the bot check; null when the API predates the traffic classification"),
|
|
695
705
|
beingAnalysed: z2.number().nullable().describe("Visitors still being analysed \u2014 usually settled within 3 hours; null on an older API"),
|
|
696
706
|
automated: z2.number().nullable().describe("Automated visitors: AI assistants, search & AI crawlers and other automated; null on an older API"),
|
|
707
|
+
internal: z2.number().nullable().describe("Visitors the project marked internal (Your team / test sites): never People, never counted; null when the API sends no such group"),
|
|
697
708
|
// Was "Total agent (MCP/API) calls" — but the count comes from
|
|
698
709
|
// agent_events, which only the /v1/agent endpoint writes. MCP tool calls
|
|
699
710
|
// are never in it, so an agent read its own activity as missing.
|
|
700
711
|
agentCalls: z2.number().describe("All-time calls to the /v1/agent agent API (not MCP tool calls)"),
|
|
701
|
-
lastEventAt: z2.string().nullable().describe("ISO timestamp of the last event, or null")
|
|
712
|
+
lastEventAt: z2.string().nullable().describe("ISO timestamp of the last event, or null"),
|
|
713
|
+
rejectedOrigins: z2.array(
|
|
714
|
+
z2.object({
|
|
715
|
+
origin: z2.string(),
|
|
716
|
+
minutesWithTraffic: z2.number().describe("Minutes in which visits were turned away \u2014 recorded at most once a minute, NOT a request count"),
|
|
717
|
+
firstSeenAt: z2.string(),
|
|
718
|
+
lastSeenAt: z2.string(),
|
|
719
|
+
message: z2.string()
|
|
720
|
+
})
|
|
721
|
+
).describe(
|
|
722
|
+
"Sustained turned-away domains: at least 50 minutes with traffic over at least 2 days, previews, translate proxies and trailing-dot variants excluded. Empty on an older API."
|
|
723
|
+
)
|
|
702
724
|
},
|
|
703
725
|
annotations: {
|
|
704
726
|
readOnlyHint: true,
|
|
@@ -707,20 +729,38 @@ function registerProjectTools(server, client) {
|
|
|
707
729
|
}
|
|
708
730
|
},
|
|
709
731
|
withApiErrorGuidance(async ({ projectId }) => {
|
|
710
|
-
var _a, _b, _c, _d, _e, _f, _g;
|
|
732
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
711
733
|
const id = encodeURIComponent(projectId);
|
|
712
734
|
const stats = await client.get(`/projects/${id}/health`);
|
|
713
|
-
const
|
|
735
|
+
const rejectedOrigins = ((_a = stats.rejectedOrigins) != null ? _a : []).map((r) => ({
|
|
736
|
+
origin: r.origin,
|
|
737
|
+
minutesWithTraffic: r.count,
|
|
738
|
+
firstSeenAt: r.firstSeenAt,
|
|
739
|
+
lastSeenAt: r.lastSeenAt,
|
|
740
|
+
message: r.message
|
|
741
|
+
}));
|
|
742
|
+
const peopleCount = (_c = stats.people) != null ? _c : (_b = stats.traffic) == null ? void 0 : _b.people;
|
|
714
743
|
const classified = peopleCount !== void 0;
|
|
715
744
|
const people = classified ? peopleCount : null;
|
|
716
|
-
const beingAnalysed = classified ? (
|
|
717
|
-
const automated = classified ? (
|
|
745
|
+
const beingAnalysed = classified ? (_e = (_d = stats.traffic) == null ? void 0 : _d.beingAnalysed) != null ? _e : 0 : null;
|
|
746
|
+
const automated = classified ? (_g = (_f = stats.traffic) == null ? void 0 : _f.automated) != null ? _g : 0 : null;
|
|
747
|
+
const internalGroup = (_i = (_h = stats.traffic) == null ? void 0 : _h.groups) == null ? void 0 : _i.find((g) => g.group === "internal");
|
|
748
|
+
const internal = internalGroup ? internalGroup.count : null;
|
|
718
749
|
const text2 = [
|
|
719
750
|
`Status: ${stats.status}`,
|
|
720
751
|
`Events (24h): ${stats.events24h}`,
|
|
721
|
-
...classified ? [
|
|
752
|
+
...classified ? [
|
|
753
|
+
`People (24h): ${people}`,
|
|
754
|
+
`Being analysed: ${beingAnalysed}`,
|
|
755
|
+
`Automated: ${automated}`,
|
|
756
|
+
...internal !== null ? [`Your team / test sites (marked internal, not counted): ${internal}`] : []
|
|
757
|
+
] : [`Sessions (24h): ${stats.sessions24h}`],
|
|
722
758
|
`Agent API calls (/v1/agent, all-time): ${stats.agentCalls}`,
|
|
723
|
-
`Last event: ${(
|
|
759
|
+
`Last event: ${(_j = stats.lastEventAt) != null ? _j : "never"}`,
|
|
760
|
+
...rejectedOrigins.length ? [
|
|
761
|
+
"Domains turned away (not on the allowed list \u2014 fix with add_origin if they are your sites):",
|
|
762
|
+
...rejectedOrigins.map((r) => `- ${r.message}`)
|
|
763
|
+
] : []
|
|
724
764
|
].join("\n");
|
|
725
765
|
return {
|
|
726
766
|
content: [{ type: "text", text: text2 }],
|
|
@@ -731,8 +771,10 @@ function registerProjectTools(server, client) {
|
|
|
731
771
|
people,
|
|
732
772
|
beingAnalysed,
|
|
733
773
|
automated,
|
|
774
|
+
internal,
|
|
734
775
|
agentCalls: stats.agentCalls,
|
|
735
|
-
lastEventAt: stats.lastEventAt
|
|
776
|
+
lastEventAt: stats.lastEventAt,
|
|
777
|
+
rejectedOrigins
|
|
736
778
|
}
|
|
737
779
|
};
|
|
738
780
|
})
|
|
@@ -927,7 +969,16 @@ function registerComponentTools(server, client) {
|
|
|
927
969
|
total: z4.number().describe("Total components in the project \u2014 larger than the list when truncated"),
|
|
928
970
|
truncated: z4.boolean().describe("True when the fetch cap was hit before listing every component"),
|
|
929
971
|
regions: regionOutputSchema,
|
|
930
|
-
window: windowOutputSchema
|
|
972
|
+
window: windowOutputSchema,
|
|
973
|
+
audienceNamedVersions: z4.array(
|
|
974
|
+
z4.object({
|
|
975
|
+
componentId: z4.string(),
|
|
976
|
+
versionKey: z4.string(),
|
|
977
|
+
personaKey: z4.string().describe("The declared audience the key is named after"),
|
|
978
|
+
pinned: z4.boolean().describe("Already pinned to that audience"),
|
|
979
|
+
nudge: z4.string().describe("What the dashboard says about it \u2014 quote it")
|
|
980
|
+
})
|
|
981
|
+
).describe("Versions whose key names one of the project's declared audiences. A name targets nobody: declare the persona on the site, then pin the version. Empty on an older API")
|
|
931
982
|
},
|
|
932
983
|
annotations: {
|
|
933
984
|
readOnlyHint: true,
|
|
@@ -936,29 +987,44 @@ function registerComponentTools(server, client) {
|
|
|
936
987
|
}
|
|
937
988
|
},
|
|
938
989
|
withApiErrorGuidance(async ({ projectId, range, from, to }) => {
|
|
939
|
-
|
|
990
|
+
var _a;
|
|
991
|
+
const [componentsRes, regionsRes, namedRes] = await Promise.all([
|
|
940
992
|
settled(fetchAllComponents(client, projectId, { rangeArgs: { range, from, to } })),
|
|
941
|
-
settled(fetchRegions(client, projectId, { range, from, to }))
|
|
993
|
+
settled(fetchRegions(client, projectId, { range, from, to })),
|
|
994
|
+
// Task 6: `variants={{ developer }}` reads as "developer copy for
|
|
995
|
+
// developers", and nothing told the developer a key targets nobody.
|
|
996
|
+
// Additive and best-effort, like regions.
|
|
997
|
+
settled(client.get(
|
|
998
|
+
`/projects/${encodeURIComponent(projectId)}/audience-named-versions`
|
|
999
|
+
))
|
|
942
1000
|
]);
|
|
943
1001
|
throwIfNotDegradable([componentsRes, regionsRes]);
|
|
944
1002
|
if (!componentsRes.ok) throw componentsRes.error;
|
|
945
1003
|
const { components, total, window, truncated } = componentsRes.value;
|
|
946
1004
|
const regions = regionsRes.ok ? regionsRes.value : [];
|
|
1005
|
+
const audienceNamedVersions = namedRes.ok ? ((_a = namedRes.value.versions) != null ? _a : []).map((v) => ({
|
|
1006
|
+
componentId: v.componentId,
|
|
1007
|
+
versionKey: v.versionKey,
|
|
1008
|
+
personaKey: v.personaKey,
|
|
1009
|
+
pinned: v.pinned,
|
|
1010
|
+
nudge: v.nudge
|
|
1011
|
+
})) : [];
|
|
947
1012
|
const structuredContent = {
|
|
948
1013
|
components: components.map((c) => {
|
|
949
|
-
var
|
|
1014
|
+
var _a2;
|
|
950
1015
|
return {
|
|
951
1016
|
componentId: c.component_id,
|
|
952
1017
|
variantCount: c.variants.length,
|
|
953
1018
|
impressions: c.total_impressions,
|
|
954
1019
|
conversions: c.total_conversions,
|
|
955
|
-
unconfirmedConversions: (
|
|
1020
|
+
unconfirmedConversions: (_a2 = c.total_unconfirmed_conversions) != null ? _a2 : null
|
|
956
1021
|
};
|
|
957
1022
|
}),
|
|
958
1023
|
total,
|
|
959
1024
|
truncated,
|
|
960
1025
|
regions,
|
|
961
|
-
window
|
|
1026
|
+
window,
|
|
1027
|
+
audienceNamedVersions
|
|
962
1028
|
};
|
|
963
1029
|
if (!components.length && !regions.length) {
|
|
964
1030
|
return {
|
|
@@ -978,6 +1044,11 @@ function registerComponentTools(server, client) {
|
|
|
978
1044
|
for (const r of regions) lines.push(regionText(r, untrusted));
|
|
979
1045
|
}
|
|
980
1046
|
if (!regionsRes.ok) lines.push("", "Regions could not be read just now \u2014 components served per visitor may be missing from this list.");
|
|
1047
|
+
const unpinned = audienceNamedVersions.filter((v) => !v.pinned);
|
|
1048
|
+
if (unpinned.length) {
|
|
1049
|
+
lines.push("", "Versions named after your audiences (a name doesn't target anyone):");
|
|
1050
|
+
for (const v of unpinned) lines.push(`- ${untrusted(v.componentId)} / ${untrusted(v.versionKey)}: ${v.nudge}`);
|
|
1051
|
+
}
|
|
981
1052
|
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent };
|
|
982
1053
|
})
|
|
983
1054
|
);
|
|
@@ -1319,27 +1390,41 @@ function registerInsightTools(server, client) {
|
|
|
1319
1390
|
|
|
1320
1391
|
// src/tools/personas.ts
|
|
1321
1392
|
import { z as z6 } from "zod/v3";
|
|
1393
|
+
function behaviourGroupName(label) {
|
|
1394
|
+
if (label == null || label === "" || label === "unclustered") return "Not grouped yet";
|
|
1395
|
+
const m = /^behaviour-(\d{1,4})$/.exec(label);
|
|
1396
|
+
return m ? `Behaviour group ${Number(m[1])}` : "Behaviour group";
|
|
1397
|
+
}
|
|
1322
1398
|
function registerPersonaTools(server, client) {
|
|
1323
1399
|
server.registerTool(
|
|
1324
1400
|
"get_persona_breakdown",
|
|
1325
1401
|
{
|
|
1326
1402
|
title: "Persona breakdown",
|
|
1327
|
-
//
|
|
1328
|
-
//
|
|
1329
|
-
//
|
|
1330
|
-
|
|
1403
|
+
// Counted portrait clusters by a label named after the declared
|
|
1404
|
+
// personas until 2026-11-04, so an agent could report "Developer: 410
|
|
1405
|
+
// visitors" while the Matrix showed 0% for Developer. It now reads the
|
|
1406
|
+
// API's served-as breakdown — the Matrix share column's own numbers.
|
|
1407
|
+
description: 'Visitors per audience they were SERVED as, last 30 days, People only \u2014 the same numbers as the Matrix share column (Everyone = no audience applied; a declared audience at 0 means the site never declared anyone as it). Separately, `behaviourGroups`: groups of visitors who behaved alike ("Behaviour group N" + what sets them apart). Behaviour groups are NOT audiences \u2014 nothing is shown to them; never describe one by an audience name.' + UNTRUSTED_FIELDS_NOTE,
|
|
1331
1408
|
inputSchema: { projectId: projectIdSchema },
|
|
1332
1409
|
_meta: uiMeta("persona-breakdown"),
|
|
1333
1410
|
outputSchema: {
|
|
1334
|
-
|
|
1335
|
-
|
|
1411
|
+
windowDays: z6.number().describe("Window in days (30)"),
|
|
1412
|
+
totalPeople: z6.number().describe("People with a served decision in the window \u2014 the share denominator"),
|
|
1413
|
+
personas: z6.array(
|
|
1414
|
+
z6.object({
|
|
1415
|
+
key: z6.string().describe("Persona key served (`unknown` = Everyone)"),
|
|
1416
|
+
name: z6.string().describe('Kind + name as the Matrix row reads it, e.g. "Declared: Developer"'),
|
|
1417
|
+
people: z6.number(),
|
|
1418
|
+
sharePct: z6.number().describe("Share of totalPeople (0-100) \u2014 the Matrix share")
|
|
1419
|
+
})
|
|
1420
|
+
).describe("Everyone, then every Matrix audience row (zeros included), then any other served audience"),
|
|
1421
|
+
behaviourGroups: z6.array(
|
|
1336
1422
|
z6.object({
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
reliability: z6.number().describe("Average cluster reliability (0-1)")
|
|
1423
|
+
name: z6.string().describe('"Behaviour group N" \u2014 never an audience'),
|
|
1424
|
+
description: z6.string().nullable(),
|
|
1425
|
+
people: z6.number()
|
|
1341
1426
|
})
|
|
1342
|
-
).describe("
|
|
1427
|
+
).describe("Visitors who behaved alike. Not audiences: nothing is served or targeted by them")
|
|
1343
1428
|
},
|
|
1344
1429
|
annotations: {
|
|
1345
1430
|
readOnlyHint: true,
|
|
@@ -1349,33 +1434,21 @@ function registerPersonaTools(server, client) {
|
|
|
1349
1434
|
},
|
|
1350
1435
|
withApiErrorGuidance(async ({ projectId }) => {
|
|
1351
1436
|
const id = encodeURIComponent(projectId);
|
|
1352
|
-
const data = await client.get(`/projects/${id}/
|
|
1437
|
+
const data = await client.get(`/projects/${id}/persona-breakdown`);
|
|
1353
1438
|
const structuredContent = {
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
sharePct: data.totalSessions > 0 ? c.sessionCount / data.totalSessions * 100 : 0,
|
|
1359
|
-
reliability: c.avgReliability
|
|
1360
|
-
}))
|
|
1439
|
+
windowDays: data.windowDays,
|
|
1440
|
+
totalPeople: data.totalPeople,
|
|
1441
|
+
personas: data.personas.map((p) => ({ key: p.key, name: p.name, people: p.people, sharePct: p.sharePct })),
|
|
1442
|
+
behaviourGroups: data.behaviourGroups.map((g) => ({ name: g.name, description: g.description, people: g.people }))
|
|
1361
1443
|
};
|
|
1362
|
-
if (!data.clusters.length) {
|
|
1363
|
-
return {
|
|
1364
|
-
content: [{ type: "text", text: "No persona clusters yet. More visitor data is needed." }],
|
|
1365
|
-
structuredContent,
|
|
1366
|
-
_meta: uiMeta("persona-breakdown")
|
|
1367
|
-
};
|
|
1368
|
-
}
|
|
1369
1444
|
const lines = [
|
|
1370
|
-
`
|
|
1445
|
+
`Visitors by the audience they were served as (last ${data.windowDays} days, ${data.totalPeople} people \u2014 same numbers as the Matrix share):`,
|
|
1446
|
+
// Audience names are customer-written — delimit them so a crafted
|
|
1447
|
+
// name can't pose as tool output (see untrusted()).
|
|
1448
|
+
...data.totalPeople === 0 ? ["- No served decisions yet in this window."] : data.personas.map((p) => `- ${untrusted(p.name)}: ${p.people} people (${p.sharePct.toFixed(1)}%)`),
|
|
1371
1449
|
"",
|
|
1372
|
-
"
|
|
1373
|
-
|
|
1374
|
-
// crafted label can't pose as tool output (see untrusted()).
|
|
1375
|
-
...data.clusters.map((c) => {
|
|
1376
|
-
const pct3 = data.totalSessions > 0 ? c.sessionCount / data.totalSessions * 100 : 0;
|
|
1377
|
-
return `- ${untrusted(c.label)}: ${c.sessionCount} sessions (${pct3.toFixed(1)}% of traffic, reliability ${(c.avgReliability * 100).toFixed(0)}%)`;
|
|
1378
|
-
})
|
|
1450
|
+
"Behaviour groups (visitors who behaved alike \u2014 NOT audiences; nothing is shown to a group):",
|
|
1451
|
+
...data.behaviourGroups.length === 0 ? ["- None yet."] : data.behaviourGroups.map((g) => `- ${g.name}: ${g.people} people${g.description ? ` \u2014 ${g.description}` : ""}`)
|
|
1379
1452
|
];
|
|
1380
1453
|
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent, _meta: uiMeta("persona-breakdown") };
|
|
1381
1454
|
})
|
|
@@ -1805,6 +1878,12 @@ function stepChangeText(dropOffFromPrevious) {
|
|
|
1805
1878
|
}
|
|
1806
1879
|
return ` (${Math.round(dropOffFromPrevious * 100)}% drop-off from previous)`;
|
|
1807
1880
|
}
|
|
1881
|
+
var trackingSchema = z9.enum(["recorded", "defined", "silent", "none"]).nullable().describe("What sends this step's goal: recorded (it has fired), defined (set up, nothing recorded yet, under 7 days), silent (set up 7+ days ago, never recorded), none (nothing sends it: no active definition and never fired, so this step can never fill). Null on an older API.");
|
|
1882
|
+
function stepSourceText(goalId, tracking, definedDaysAgo) {
|
|
1883
|
+
if (tracking === "none") return `Nothing sends ${untrusted(goalId)} yet`;
|
|
1884
|
+
if (tracking === "silent") return `${untrusted(goalId)} is set up but nothing has recorded it in ${definedDaysAgo != null ? definedDaysAgo : 7} days`;
|
|
1885
|
+
return null;
|
|
1886
|
+
}
|
|
1808
1887
|
function registerFunnelTools(server, client) {
|
|
1809
1888
|
server.registerTool(
|
|
1810
1889
|
"list_funnels",
|
|
@@ -1824,7 +1903,9 @@ function registerFunnelTools(server, client) {
|
|
|
1824
1903
|
z9.object({
|
|
1825
1904
|
stepIndex: z9.number(),
|
|
1826
1905
|
goalId: z9.string(),
|
|
1827
|
-
weight: z9.number().nullable().describe("Manual optimizer credit for reaching this step (null = automatic end-weighted)")
|
|
1906
|
+
weight: z9.number().nullable().describe("Manual optimizer credit for reaching this step (null = automatic end-weighted)"),
|
|
1907
|
+
tracking: trackingSchema,
|
|
1908
|
+
definedDaysAgo: z9.number().nullable().describe("Days since an unfired goal was set up (null once it fires)")
|
|
1828
1909
|
})
|
|
1829
1910
|
).describe("Ordered steps"),
|
|
1830
1911
|
components: z9.array(z9.object({ componentId: z9.string(), stepIndex: z9.number().nullable() })).describe("Components serving this funnel (stepIndex null = whole funnel)")
|
|
@@ -1845,11 +1926,16 @@ function registerFunnelTools(server, client) {
|
|
|
1845
1926
|
windowDays: f.window_days,
|
|
1846
1927
|
source: f.source,
|
|
1847
1928
|
// NUMERIC arrives serialized as a string; coerce.
|
|
1848
|
-
steps: f.steps.map((s) =>
|
|
1849
|
-
|
|
1850
|
-
|
|
1851
|
-
|
|
1852
|
-
|
|
1929
|
+
steps: f.steps.map((s) => {
|
|
1930
|
+
var _a2, _b;
|
|
1931
|
+
return {
|
|
1932
|
+
stepIndex: s.step_index,
|
|
1933
|
+
goalId: s.goal_id,
|
|
1934
|
+
weight: s.weight == null ? null : Number(s.weight),
|
|
1935
|
+
tracking: (_a2 = s.tracking) != null ? _a2 : null,
|
|
1936
|
+
definedDaysAgo: (_b = s.defined_days_ago) != null ? _b : null
|
|
1937
|
+
};
|
|
1938
|
+
}),
|
|
1853
1939
|
components: f.components.map((c) => {
|
|
1854
1940
|
var _a2;
|
|
1855
1941
|
return { componentId: c.component_id, stepIndex: (_a2 = c.step_index) != null ? _a2 : null };
|
|
@@ -1865,10 +1951,20 @@ function registerFunnelTools(server, client) {
|
|
|
1865
1951
|
structuredContent
|
|
1866
1952
|
};
|
|
1867
1953
|
}
|
|
1868
|
-
const lines =
|
|
1869
|
-
|
|
1870
|
-
)
|
|
1954
|
+
const lines = [];
|
|
1955
|
+
let anyUnsourced = false;
|
|
1956
|
+
for (const f of structuredContent.funnels) {
|
|
1957
|
+
lines.push(`${untrusted(f.funnelId)} (${f.status}) \u2014 ${untrusted(f.displayName)}: ${f.steps.map((s) => untrusted(s.goalId)).join(" \u2192 ")}`);
|
|
1958
|
+
for (const s of f.steps) {
|
|
1959
|
+
const note = stepSourceText(s.goalId, s.tracking, s.definedDaysAgo);
|
|
1960
|
+
if (note) lines.push(` step ${s.stepIndex + 1}: ${note}`);
|
|
1961
|
+
if (s.tracking === "none") anyUnsourced = true;
|
|
1962
|
+
}
|
|
1963
|
+
}
|
|
1871
1964
|
lines.push("", 'Reference a funnelId verbatim from code: <Adaptive funnel="<funnelId>">. Use get_funnel_report for drop-off numbers.');
|
|
1965
|
+
if (anyUnsourced) {
|
|
1966
|
+
lines.push("A step nothing sends can never fill: get_funnel_report gives the exact code to send it (useGoal in the browser, trackServerGoal on the server), or define it as a page visit with define_goal.");
|
|
1967
|
+
}
|
|
1872
1968
|
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent };
|
|
1873
1969
|
})
|
|
1874
1970
|
);
|
|
@@ -1892,7 +1988,14 @@ function registerFunnelTools(server, client) {
|
|
|
1892
1988
|
reached: z9.number().describe("Distinct People reaching this step in-window"),
|
|
1893
1989
|
unconfirmedReached: z9.number().nullable().describe("Visitors we couldn't confirm as people who reached this step (the API's own remainder; not in reached or any drop-off); null on an older API"),
|
|
1894
1990
|
dropOffFromPrevious: z9.number().nullable().describe("1 - reached/previousReached (null on the first step)"),
|
|
1895
|
-
neverFired: z9.boolean().describe("
|
|
1991
|
+
neverFired: z9.boolean().describe("Legacy: no definition in any status and never recorded. Prefer tracking"),
|
|
1992
|
+
tracking: trackingSchema,
|
|
1993
|
+
definedDaysAgo: z9.number().nullable().describe("Days since an unfired goal was set up (null once it fires)"),
|
|
1994
|
+
fromCode: z9.object({
|
|
1995
|
+
client: z9.string().describe("Browser code: useGoal from @sentientui/react"),
|
|
1996
|
+
server: z9.string().describe("Server code: trackServerGoal from @sentientui/react/server"),
|
|
1997
|
+
serverCall: z9.string()
|
|
1998
|
+
}).nullable().describe("Exact code that sends this step's goal, present until it first fires. Repeat it verbatim."),
|
|
1896
1999
|
variants: z9.array(z9.object({
|
|
1897
2000
|
componentId: z9.string(),
|
|
1898
2001
|
variantId: z9.string(),
|
|
@@ -1911,13 +2014,19 @@ function registerFunnelTools(server, client) {
|
|
|
1911
2014
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
1912
2015
|
},
|
|
1913
2016
|
withApiErrorGuidance(async ({ projectId, funnelId }) => {
|
|
1914
|
-
var _a, _b;
|
|
2017
|
+
var _a, _b, _c;
|
|
1915
2018
|
const data = await client.get(`/projects/${encodeURIComponent(projectId)}/funnels/${encodeURIComponent(funnelId)}/report`);
|
|
1916
2019
|
const lines = [`${untrusted(data.displayName)} \u2014 last ${data.windowDays} days`];
|
|
1917
2020
|
for (const s of data.steps) {
|
|
2021
|
+
const tracking = (_a = s.tracking) != null ? _a : s.neverFired ? "none" : null;
|
|
2022
|
+
const note = stepSourceText(s.goalId, tracking, s.definedDaysAgo);
|
|
1918
2023
|
lines.push(
|
|
1919
|
-
`${s.stepIndex + 1}. ${untrusted(s.displayName)}: ${s.reached} People reached` + (s.unconfirmedReached ? ` (${s.unconfirmedReached} more from visitors we couldn't confirm as people)` : "") + stepChangeText(s.dropOffFromPrevious) + (
|
|
2024
|
+
`${s.stepIndex + 1}. ${untrusted(s.displayName)}: ${s.reached} People reached` + (s.unconfirmedReached ? ` (${s.unconfirmedReached} more from visitors we couldn't confirm as people)` : "") + stepChangeText(s.dropOffFromPrevious) + (note ? ` [${note}]` : "")
|
|
1920
2025
|
);
|
|
2026
|
+
if (tracking === "none" && s.fromCode && codeSafe(s.goalId) === s.goalId) {
|
|
2027
|
+
lines.push(" Send it from your server:", ...s.fromCode.server.split("\n").map((l) => ` ${l}`));
|
|
2028
|
+
lines.push(" \u2026or from the browser:", ...s.fromCode.client.split("\n").map((l) => ` ${l}`));
|
|
2029
|
+
}
|
|
1921
2030
|
for (const v of s.variants) {
|
|
1922
2031
|
lines.push(` ${untrusted(v.componentId)}/${untrusted(v.variantId)}: ${v.reached}/${v.assigned} assigned sessions reached this step`);
|
|
1923
2032
|
}
|
|
@@ -1936,11 +2045,16 @@ function registerFunnelTools(server, client) {
|
|
|
1936
2045
|
content: [{ type: "text", text: lines.join("\n") }],
|
|
1937
2046
|
// Tolerate an API deployed before strict funnels existed.
|
|
1938
2047
|
structuredContent: __spreadProps(__spreadValues({}, data), {
|
|
1939
|
-
strictOrder: (
|
|
1940
|
-
unconfirmedRevenue: (
|
|
2048
|
+
strictOrder: (_b = data.strictOrder) != null ? _b : true,
|
|
2049
|
+
unconfirmedRevenue: (_c = data.unconfirmedRevenue) != null ? _c : null,
|
|
1941
2050
|
steps: data.steps.map((s) => {
|
|
1942
|
-
var _a2;
|
|
1943
|
-
return __spreadProps(__spreadValues({}, s), {
|
|
2051
|
+
var _a2, _b2, _c2, _d;
|
|
2052
|
+
return __spreadProps(__spreadValues({}, s), {
|
|
2053
|
+
unconfirmedReached: (_a2 = s.unconfirmedReached) != null ? _a2 : null,
|
|
2054
|
+
tracking: (_b2 = s.tracking) != null ? _b2 : null,
|
|
2055
|
+
definedDaysAgo: (_c2 = s.definedDaysAgo) != null ? _c2 : null,
|
|
2056
|
+
fromCode: (_d = s.fromCode) != null ? _d : null
|
|
2057
|
+
});
|
|
1944
2058
|
})
|
|
1945
2059
|
})
|
|
1946
2060
|
};
|
|
@@ -2559,10 +2673,10 @@ function registerVariantBriefTools(server, client) {
|
|
|
2559
2673
|
lines.push("");
|
|
2560
2674
|
}
|
|
2561
2675
|
if (clusters.length) {
|
|
2562
|
-
lines.push(`
|
|
2676
|
+
lines.push(`Behaviour groups (visitors who behaved alike \u2014 not audiences; ${totalSessions} sessions):`);
|
|
2563
2677
|
for (const c of clusters) {
|
|
2564
2678
|
const share = totalSessions > 0 ? (c.sessionCount / totalSessions * 100).toFixed(0) : "0";
|
|
2565
|
-
lines.push(`- ${
|
|
2679
|
+
lines.push(`- ${behaviourGroupName(c.label)}: ${share}% of traffic, ${c.sessionCount} sessions (reliability ${(c.avgReliability * 100).toFixed(0)}%)`);
|
|
2566
2680
|
}
|
|
2567
2681
|
lines.push("");
|
|
2568
2682
|
}
|
|
@@ -2747,11 +2861,14 @@ import { z as z15 } from "zod/v3";
|
|
|
2747
2861
|
var GUIDE = `# SentientUI integration guide \u2014 the adaptive ladder
|
|
2748
2862
|
|
|
2749
2863
|
SentientUI adapts a site per visitor type (personas), learning from real conversions. Each
|
|
2750
|
-
project has its own persona vocabulary (dashboard ->
|
|
2751
|
-
EMPTY: every visitor is 'unknown' until a persona exists, and the optimizer learns
|
|
2752
|
-
traffic pooled in the meantime.
|
|
2753
|
-
|
|
2754
|
-
<AdaptiveProvider persona=...> / window.sentient.persona
|
|
2864
|
+
project has its own persona vocabulary (dashboard -> Matrix -> Audiences), and it starts
|
|
2865
|
+
EMPTY: every visitor is 'unknown' (Everyone) until a persona exists, and the optimizer learns
|
|
2866
|
+
across all traffic pooled in the meantime. A visit is served as ONE persona, in order: DECLARED
|
|
2867
|
+
by the app when it already knows the visitor's role (init({ persona: 'admin' }) /
|
|
2868
|
+
<AdaptiveProvider persona=...> / window.sentient.persona), a running retargeting group, a
|
|
2869
|
+
DISCOVERED audience the visitor confidently belongs to, a campaign / arrival type, else
|
|
2870
|
+
Everyone. Behaviour groups (visitors who behaved alike, from portraits) are reporting only \u2014
|
|
2871
|
+
nothing is served to them and they are never personas. Declared beats everything and serves
|
|
2755
2872
|
at full confidence; unrecognized values are ignored server-side and surfaced in the dashboard
|
|
2756
2873
|
so the operator can add them. Keep persona a low-cardinality role slug \u2014 never a user id.
|
|
2757
2874
|
Decisions are locked per visit: a first visit usually sees the original and the return visit adapts \u2014 the
|
|
@@ -2837,6 +2954,11 @@ Code variants \u2014 when you write the alternatives yourself:
|
|
|
2837
2954
|
});
|
|
2838
2955
|
return <div {...bind}>{value}</div>;
|
|
2839
2956
|
|
|
2957
|
+
Variant keys are versions, not audiences: naming one \`developer\` does NOT show it to
|
|
2958
|
+
developers \u2014 the optimizer may show any version to anyone. To show it to Developers, declare
|
|
2959
|
+
the persona on the site, then pin the version to that audience (Migrate the component in
|
|
2960
|
+
Matrix -> Components; the last step offers the pins).
|
|
2961
|
+
|
|
2840
2962
|
Children or variants on one <Adaptive>, never both. With the hook, always attach bind \u2014 it
|
|
2841
2963
|
wires exposure tracking and goal listeners. <AdaptiveText> swaps dashboard-managed text.
|
|
2842
2964
|
|
|
@@ -3111,14 +3233,14 @@ function registerTrafficTools(server, client) {
|
|
|
3111
3233
|
"get_traffic_breakdown",
|
|
3112
3234
|
{
|
|
3113
3235
|
title: "Traffic breakdown",
|
|
3114
|
-
description: "Where a project\u2019s traffic came from. Every visitor (one per browser or device) last seen in the window falls into exactly one
|
|
3236
|
+
description: "Where a project\u2019s traffic came from. Every visitor (one per browser or device) last seen in the window falls into exactly one group, and the groups add up to the total: People (ran the page, interacted (click, scroll, mouse, touch or key) and passed the bot check), Loaded but didn\u2019t interact, Not verified \u2014 no browser activity, Being analysed (usually settled within 3 hours), AI assistants, Search & AI crawlers, Other automated, and Your team / test sites (visits the project marked internal \u2014 never People, never counted, never learned from; see get_internal_traffic_rules). Each group carries plain-English evidence counts; named AI assistants and crawlers, conversions (total and from People) and notices are included. Conversion rates elsewhere are conversion rate among People. Reporting only \u2014 it does not change what the optimizer learns from." + UNTRUSTED_FIELDS_NOTE,
|
|
3115
3237
|
inputSchema: { projectId: projectIdSchema, range: trafficRangeSchema },
|
|
3116
3238
|
outputSchema: {
|
|
3117
3239
|
window: z17.object({ from: z17.string(), to: z17.string() }),
|
|
3118
3240
|
total: z17.number().describe("Visitors in the window; the groups add up to this"),
|
|
3119
3241
|
groups: z17.array(
|
|
3120
3242
|
z17.object({
|
|
3121
|
-
group: z17.string().describe("people | loaded_no_interaction | not_verified | being_analysed | ai_assistant | crawler | other_automated"),
|
|
3243
|
+
group: z17.string().describe("people | loaded_no_interaction | not_verified | being_analysed | ai_assistant | crawler | other_automated | internal"),
|
|
3122
3244
|
label: z17.string(),
|
|
3123
3245
|
count: z17.number(),
|
|
3124
3246
|
evidence: z17.array(z17.object({ code: z17.string(), label: z17.string(), count: z17.number() }))
|
|
@@ -3134,7 +3256,7 @@ function registerTrafficTools(server, client) {
|
|
|
3134
3256
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
3135
3257
|
},
|
|
3136
3258
|
withApiErrorGuidance(async ({ projectId, range }) => {
|
|
3137
|
-
var _a, _b, _c;
|
|
3259
|
+
var _a, _b, _c, _d, _e;
|
|
3138
3260
|
const id = encodeURIComponent(projectId);
|
|
3139
3261
|
const t = await client.get(`/projects/${id}/traffic${range ? `?range=${encodeURIComponent(range)}` : ""}`);
|
|
3140
3262
|
const beingAnalysed = (_b = (_a = t.groups.find((g) => g.group === "being_analysed")) == null ? void 0 : _a.count) != null ? _b : 0;
|
|
@@ -3142,6 +3264,10 @@ function registerTrafficTools(server, client) {
|
|
|
3142
3264
|
`Traffic from ${t.window.from.slice(0, 10)} to ${t.window.to.slice(0, 10)}: ${t.total} visitors.`,
|
|
3143
3265
|
...t.groups.map((g) => `- ${g.label}: ${g.count}`)
|
|
3144
3266
|
];
|
|
3267
|
+
const internal = (_d = (_c = t.groups.find((g) => g.group === "internal")) == null ? void 0 : _c.count) != null ? _d : 0;
|
|
3268
|
+
if (internal > 0) {
|
|
3269
|
+
lines.push("", `${internal} visitors were marked internal by the project's own rules (your team / test sites) \u2014 not in People and not learned from. get_internal_traffic_rules shows which rules.`);
|
|
3270
|
+
}
|
|
3145
3271
|
if (beingAnalysed > 0) {
|
|
3146
3272
|
lines.push("", `${beingAnalysed} visitors are being analysed \u2014 usually settled within 3 hours`);
|
|
3147
3273
|
}
|
|
@@ -3149,7 +3275,7 @@ function registerTrafficTools(server, client) {
|
|
|
3149
3275
|
lines.push("", "Named agents:", ...t.agents.map((a2) => `- ${untrusted(a2.name)}: ${a2.count}`));
|
|
3150
3276
|
}
|
|
3151
3277
|
lines.push("", `${t.conversions.total} conversions in total, ${t.conversions.fromPeople} from People.`);
|
|
3152
|
-
for (const n of t.notices) lines.push((
|
|
3278
|
+
for (const n of t.notices) lines.push((_e = NOTICE_TEXT[n]) != null ? _e : n);
|
|
3153
3279
|
return { content: [{ type: "text", text: lines.join("\n") }], structuredContent: t };
|
|
3154
3280
|
}, {
|
|
3155
3281
|
range_too_large: "That window has too much traffic to break down in one go. Ask for a shorter range (24h, 7d or 30d) and try again."
|
|
@@ -3157,33 +3283,119 @@ function registerTrafficTools(server, client) {
|
|
|
3157
3283
|
);
|
|
3158
3284
|
}
|
|
3159
3285
|
|
|
3160
|
-
// src/tools/
|
|
3286
|
+
// src/tools/internal-traffic.ts
|
|
3161
3287
|
import { z as z18 } from "zod/v3";
|
|
3162
|
-
var
|
|
3163
|
-
|
|
3164
|
-
|
|
3165
|
-
|
|
3166
|
-
|
|
3288
|
+
var INTERNAL_TRAFFIC_LABEL = "Your team / test sites";
|
|
3289
|
+
var REASONS = [
|
|
3290
|
+
{ key: "site", words: "internal sites" },
|
|
3291
|
+
{ key: "code", words: "code flag" },
|
|
3292
|
+
{ key: "email_rule", words: "team emails" },
|
|
3293
|
+
{ key: "domain_rule", words: "team domains" },
|
|
3294
|
+
{ key: "browser", words: "browser link" }
|
|
3295
|
+
];
|
|
3296
|
+
function registerInternalTrafficTools(server, client) {
|
|
3297
|
+
server.registerTool(
|
|
3298
|
+
"get_internal_traffic_rules",
|
|
3299
|
+
{
|
|
3300
|
+
title: "Internal traffic rules",
|
|
3301
|
+
description: `Read how this project keeps its own team and test sites out of its numbers (dashboard Settings \u2192 Internal traffic): which allowed domains are internal sites, the team email domains and masked exact emails, whether a "mark this browser" link exists, and how many sessions each way marked internal in the last 7 days. Internal visits still see versions (QA works) but never count in any report or teach the optimizer; get_traffic_breakdown lists them as "${INTERNAL_TRAFFIC_LABEL}". Exact emails are stored only as a hash \u2014 this tool returns the masked form, never an address or the hash. Rules apply from when they are turned on; earlier visits cannot be separated. Read-only: a person changes them in the dashboard.`,
|
|
3302
|
+
inputSchema: { projectId: projectIdSchema },
|
|
3303
|
+
outputSchema: {
|
|
3304
|
+
internalOrigins: z18.array(z18.string()).describe("Allowed domains whose every visit is marked internal"),
|
|
3305
|
+
allowedOrigins: z18.array(z18.string()).describe("Every allowed domain \u2014 only these can be made internal"),
|
|
3306
|
+
emailDomains: z18.array(z18.string()).describe("Email domains (no leading @) whose identified visitors are marked internal"),
|
|
3307
|
+
emails: z18.array(z18.string()).describe("Exact team emails, masked (c***@example.com); stored only as a hash"),
|
|
3308
|
+
browserLinkExists: z18.boolean().describe('Whether a "mark this browser internal" link has been created (copy or rotate it in Settings \u2192 Internal traffic)'),
|
|
3309
|
+
counts7d: z18.object({
|
|
3310
|
+
site: z18.number(),
|
|
3311
|
+
code: z18.number(),
|
|
3312
|
+
email_rule: z18.number(),
|
|
3313
|
+
domain_rule: z18.number(),
|
|
3314
|
+
browser: z18.number(),
|
|
3315
|
+
total: z18.number()
|
|
3316
|
+
}).describe("Sessions marked internal in the last 7 days, by the way that marked them first"),
|
|
3317
|
+
recordingSince: z18.string().nullable().describe("When sessions began recording which site they came from; visits before it cannot be separated")
|
|
3318
|
+
},
|
|
3319
|
+
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
3320
|
+
},
|
|
3321
|
+
withApiErrorGuidance(async ({ projectId }) => {
|
|
3322
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
3323
|
+
const r = await client.get(
|
|
3324
|
+
`/projects/${encodeURIComponent(projectId)}/internal-traffic`
|
|
3325
|
+
);
|
|
3326
|
+
const internalOrigins = (_a = r.internalOrigins) != null ? _a : [];
|
|
3327
|
+
const allowedOrigins = (_b = r.allowedOrigins) != null ? _b : [];
|
|
3328
|
+
const emailDomains = (_c = r.emailDomains) != null ? _c : [];
|
|
3329
|
+
const emails = ((_d = r.emails) != null ? _d : []).map((e) => e.masked);
|
|
3330
|
+
const c = (_e = r.counts7d) != null ? _e : {};
|
|
3331
|
+
const counts7d = {
|
|
3332
|
+
site: (_f = c.site) != null ? _f : 0,
|
|
3333
|
+
code: (_g = c.code) != null ? _g : 0,
|
|
3334
|
+
email_rule: (_h = c.email_rule) != null ? _h : 0,
|
|
3335
|
+
domain_rule: (_i = c.domain_rule) != null ? _i : 0,
|
|
3336
|
+
browser: (_j = c.browser) != null ? _j : 0,
|
|
3337
|
+
total: (_k = c.total) != null ? _k : 0
|
|
3338
|
+
};
|
|
3339
|
+
const recordingSince = (_l = r.recordingSince) != null ? _l : null;
|
|
3340
|
+
const browserLinkExists = r.browserLink != null;
|
|
3341
|
+
const notInternal = allowedOrigins.filter((o) => !internalOrigins.includes(o));
|
|
3342
|
+
const lines = [
|
|
3343
|
+
`Internal traffic \u2014 reported as "${INTERNAL_TRAFFIC_LABEL}": these visits still see versions but never count and never teach the optimizer.`,
|
|
3344
|
+
`Internal sites: ${internalOrigins.length ? internalOrigins.join(", ") : "none"}.`,
|
|
3345
|
+
...notInternal.length ? [`Allowed but counted normally: ${notInternal.join(", ")}.`] : [],
|
|
3346
|
+
`Team domains: ${emailDomains.length ? emailDomains.map((d) => `@${d}`).join(", ") : "none"}.`,
|
|
3347
|
+
`Team emails: ${emails.length ? emails.join(", ") : "none"} (stored only as a hash; they match visitors the site identifies with identify(userId, { email })).`,
|
|
3348
|
+
`Browser link: ${browserLinkExists ? "created \u2014 copy or rotate it in Settings \u2192 Internal traffic" : "not created"}.`,
|
|
3349
|
+
`Sessions marked internal, last 7 days: ${counts7d.total} (${REASONS.map((x) => `${x.words} ${counts7d[x.key]}`).join(", ")}).`,
|
|
3350
|
+
recordingSince ? `Applies from when each rule is turned on; visits before ${recordingSince.slice(0, 10)} cannot be separated (which site a visit came from was not recorded).` : "Applies from when each rule is turned on; earlier visits cannot be separated.",
|
|
3351
|
+
"To change these, a person uses Settings \u2192 Internal traffic in the dashboard."
|
|
3352
|
+
];
|
|
3353
|
+
return {
|
|
3354
|
+
content: [{ type: "text", text: lines.join("\n") }],
|
|
3355
|
+
structuredContent: { internalOrigins, allowedOrigins, emailDomains, emails, browserLinkExists, counts7d, recordingSince }
|
|
3356
|
+
};
|
|
3357
|
+
})
|
|
3358
|
+
);
|
|
3359
|
+
}
|
|
3360
|
+
|
|
3361
|
+
// src/tools/cells.ts
|
|
3362
|
+
import { z as z19 } from "zod/v3";
|
|
3363
|
+
var personaOutput = z19.object({
|
|
3364
|
+
key: z19.string(),
|
|
3365
|
+
displayName: z19.string(),
|
|
3366
|
+
description: z19.string().nullable(),
|
|
3367
|
+
share: z19.number().describe("Fraction of 30-day decided sessions"),
|
|
3368
|
+
// Both ride the API response; without them zod stripped them and an agent
|
|
3369
|
+
// reported a declared audience nothing declares as reachable.
|
|
3370
|
+
state: z19.string().optional().describe("everyone | declared | unlocked | candidate | starter \u2014 why the row exists"),
|
|
3371
|
+
declaredVisits14d: z19.number().nullable().optional().describe(
|
|
3372
|
+
"Declared rows only: visits in 14 days whose site declared this persona. 0 = not declared yet \u2014 nobody sees versions written for it until the site sends it."
|
|
3373
|
+
)
|
|
3167
3374
|
});
|
|
3168
|
-
var
|
|
3169
|
-
|
|
3170
|
-
|
|
3171
|
-
|
|
3172
|
-
|
|
3173
|
-
|
|
3174
|
-
|
|
3175
|
-
|
|
3176
|
-
|
|
3375
|
+
var blockedOutput = z19.enum(["variant_history"]).nullable().optional().describe(
|
|
3376
|
+
"variant_history: the component's code still runs its own variants test, so versions written here are approved but NOT showing until it is migrated (dashboard Components \u2192 Migrate). Null when the column can serve."
|
|
3377
|
+
);
|
|
3378
|
+
var BLOCKED_LINE = "Not showing yet \u2014 your code's own test still runs here. Versions written for this part of the page are approved but no visitor sees them until it is migrated (Components \u2192 this component \u2192 Migrate).";
|
|
3379
|
+
var NOT_DECLARED_LINE = "not declared yet \u2014 your site has not told us anyone is this persona in 14 days, so nobody sees versions written for them until your code sends it (the persona prop, init({ persona }) or window.sentient.persona)";
|
|
3380
|
+
var cellOutput = z19.object({
|
|
3381
|
+
slotId: z19.string(),
|
|
3382
|
+
persona: z19.string(),
|
|
3383
|
+
status: z19.string().describe("pending | generating | review (waiting for approval) | live | error | rejected"),
|
|
3384
|
+
requestedBy: z19.string(),
|
|
3385
|
+
armId: z19.string().nullable(),
|
|
3386
|
+
rationale: z19.string().nullable(),
|
|
3387
|
+
error: z19.string().nullable(),
|
|
3388
|
+
updatedAt: z19.string(),
|
|
3177
3389
|
// These ride the API response too; omitting them from the schema made zod
|
|
3178
3390
|
// STRIP them, so agents could never see refinement or retry state.
|
|
3179
|
-
refinedFrom:
|
|
3180
|
-
notBefore:
|
|
3181
|
-
attempts:
|
|
3182
|
-
performance:
|
|
3183
|
-
shown:
|
|
3184
|
-
conversions:
|
|
3185
|
-
deltaPct:
|
|
3186
|
-
tier:
|
|
3391
|
+
refinedFrom: z19.string().nullable().optional().describe("Incumbent arm this cell is improving on \u2014 a pending cell with this set still SERVES the incumbent"),
|
|
3392
|
+
notBefore: z19.string().nullable().optional().describe("ISO time the queue will next consider this cell (retry backoff / daily-cap deferral); null when due now"),
|
|
3393
|
+
attempts: z19.number().optional().describe("Generation attempts so far"),
|
|
3394
|
+
performance: z19.object({
|
|
3395
|
+
shown: z19.number(),
|
|
3396
|
+
conversions: z19.number(),
|
|
3397
|
+
deltaPct: z19.number().nullable().describe("Signed % vs the original conversion rate \u2014 a point estimate; only meaningful beside a winning/losing tier"),
|
|
3398
|
+
tier: z19.string().describe(
|
|
3187
3399
|
'early | no_baseline (under 100 views) | winning | losing (posterior separated from the original, corrected across the slot column) | flat (NOT separated yet \u2014 not "equal")'
|
|
3188
3400
|
)
|
|
3189
3401
|
}).optional().describe("Present on live cells (and, mid-refinement, the incumbent arm): the at-a-glance readout")
|
|
@@ -3196,28 +3408,29 @@ function registerCellTools(server, client) {
|
|
|
3196
3408
|
description: 'The "Who sees what" matrix: which visitor types (personas) have an AI-generated version live in each personalizable region (slot), with per-persona traffic share and the first-miss auto-fill setting. A cell with no row means that visitor type sees the original.' + UNTRUSTED_FIELDS_NOTE,
|
|
3197
3409
|
inputSchema: { projectId: projectIdSchema },
|
|
3198
3410
|
outputSchema: {
|
|
3199
|
-
slots:
|
|
3200
|
-
|
|
3201
|
-
slotId:
|
|
3202
|
-
displayName:
|
|
3203
|
-
supportsForms:
|
|
3411
|
+
slots: z19.array(
|
|
3412
|
+
z19.object({
|
|
3413
|
+
slotId: z19.string(),
|
|
3414
|
+
displayName: z19.string(),
|
|
3415
|
+
supportsForms: z19.boolean(),
|
|
3204
3416
|
// API sends this; without it zod stripped the draft-vs-live signal.
|
|
3205
|
-
live:
|
|
3417
|
+
live: z19.boolean().optional().describe("False for an sdk-registered draft column \u2014 nothing serves until its first generation publishes it"),
|
|
3418
|
+
blocked: blockedOutput
|
|
3206
3419
|
})
|
|
3207
3420
|
),
|
|
3208
|
-
personas:
|
|
3209
|
-
cells:
|
|
3210
|
-
autoFill:
|
|
3421
|
+
personas: z19.array(personaOutput),
|
|
3422
|
+
cells: z19.array(cellOutput),
|
|
3423
|
+
autoFill: z19.boolean(),
|
|
3211
3424
|
// The API has always sent this; without it in the schema zod stripped
|
|
3212
3425
|
// it, and generate_cell had no way to know a version would wait for a
|
|
3213
3426
|
// human instead of publishing.
|
|
3214
|
-
reviewMode:
|
|
3427
|
+
reviewMode: z19.boolean().optional().describe("True when generated versions wait for approval (review_cell) instead of publishing automatically"),
|
|
3215
3428
|
// Nullable: a project with no persona set at all reports null, not a
|
|
3216
3429
|
// string. That is the NORMAL state since the default vocabulary was
|
|
3217
3430
|
// emptied, so a non-nullable schema failed output validation on most
|
|
3218
3431
|
// projects and the tool returned nothing but a zod error.
|
|
3219
|
-
personaSource:
|
|
3220
|
-
undecidedShare:
|
|
3432
|
+
personaSource: z19.string().nullable().describe('Active persona-set source: default | declared | discovered, or null when the project has no persona set (one "everyone" row)'),
|
|
3433
|
+
undecidedShare: z19.number()
|
|
3221
3434
|
},
|
|
3222
3435
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
3223
3436
|
},
|
|
@@ -3226,22 +3439,27 @@ function registerCellTools(server, client) {
|
|
|
3226
3439
|
const id = encodeURIComponent(projectId);
|
|
3227
3440
|
const data = await client.get(`/projects/${id}/cells`);
|
|
3228
3441
|
const byCell = new Map(data.cells.map((c) => [`${c.slotId}::${c.persona}`, c]));
|
|
3442
|
+
const blockedSlots = data.slots.filter((s) => s.blocked === "variant_history");
|
|
3229
3443
|
const lines = [
|
|
3230
|
-
`Slots: ${data.slots.map((s) => `${untrusted(s.displayName)}${s.live === false ? " [draft]" : ""}`).join(", ") || "(none published)"}`,
|
|
3444
|
+
`Slots: ${data.slots.map((s) => `${untrusted(s.displayName)}${s.live === false ? " [draft]" : ""}${s.blocked === "variant_history" ? " [not showing yet]" : ""}`).join(", ") || "(none published)"}`,
|
|
3445
|
+
...blockedSlots.length > 0 ? [`${blockedSlots.map((s) => untrusted(s.displayName, 40)).join(", ")}: ${BLOCKED_LINE}`] : [],
|
|
3231
3446
|
`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)'}`
|
|
3232
3447
|
];
|
|
3233
3448
|
for (const p of data.personas) {
|
|
3234
3449
|
const states = data.slots.map((s) => {
|
|
3235
3450
|
const c = byCell.get(`${s.slotId}::${p.key}`);
|
|
3236
3451
|
let state = c ? c.status : "original";
|
|
3237
|
-
if (c &&
|
|
3452
|
+
if (c && c.status === "live" && s.blocked === "variant_history") {
|
|
3453
|
+
state = "approved \u2014 not showing yet";
|
|
3454
|
+
} else if (c && (c.status === "pending" || c.status === "generating") && c.refinedFrom) {
|
|
3238
3455
|
state = `${c.status} (improving on ${untrusted(c.refinedFrom, 64)} \u2014 current version still live)`;
|
|
3239
3456
|
} else if (c && c.status === "pending" && c.notBefore && Date.parse(c.notBefore) > Date.now()) {
|
|
3240
3457
|
state = `pending (waiting until ${c.notBefore})`;
|
|
3241
3458
|
}
|
|
3242
3459
|
return `${untrusted(s.displayName, 40)}: ${state}`;
|
|
3243
3460
|
});
|
|
3244
|
-
|
|
3461
|
+
const undeclared = p.state === "declared" && p.declaredVisits14d === 0 ? ` [${NOT_DECLARED_LINE}]` : "";
|
|
3462
|
+
lines.push(`- ${untrusted(p.displayName)} (${Math.round(p.share * 100)}% of visitors)${undeclared} \u2014 ${states.join(" \xB7 ")}`);
|
|
3245
3463
|
}
|
|
3246
3464
|
lines.push(`Undecided visitors (${Math.round(data.undecidedShare * 100)}%) always see the original.`);
|
|
3247
3465
|
return {
|
|
@@ -3257,26 +3475,27 @@ function registerCellTools(server, client) {
|
|
|
3257
3475
|
description: "One cell's full story: the generated option a visitor type sees in a slot, why it was written (the stored generation rationale), and how it is performing vs the original (deterministic plain-language verdict)." + UNTRUSTED_FIELDS_NOTE,
|
|
3258
3476
|
inputSchema: {
|
|
3259
3477
|
projectId: projectIdSchema,
|
|
3260
|
-
slotId:
|
|
3261
|
-
persona:
|
|
3478
|
+
slotId: z19.string().min(1).max(128).describe("The slot id (a matrix column)"),
|
|
3479
|
+
persona: z19.string().min(1).max(64).describe("The persona key (a matrix row)")
|
|
3262
3480
|
},
|
|
3263
3481
|
outputSchema: {
|
|
3264
3482
|
cell: cellOutput.nullable(),
|
|
3265
|
-
arm:
|
|
3266
|
-
id:
|
|
3267
|
-
displayName:
|
|
3268
|
-
content:
|
|
3269
|
-
blocks:
|
|
3483
|
+
arm: z19.object({
|
|
3484
|
+
id: z19.string(),
|
|
3485
|
+
displayName: z19.string().nullable(),
|
|
3486
|
+
content: z19.string().nullable(),
|
|
3487
|
+
blocks: z19.unknown().nullable()
|
|
3270
3488
|
}).nullable(),
|
|
3271
|
-
performance:
|
|
3272
|
-
shown:
|
|
3273
|
-
conversions:
|
|
3274
|
-
conversionRate:
|
|
3275
|
-
baselineShown:
|
|
3276
|
-
baselineConversions:
|
|
3277
|
-
baselineConversionRate:
|
|
3489
|
+
performance: z19.object({
|
|
3490
|
+
shown: z19.number(),
|
|
3491
|
+
conversions: z19.number(),
|
|
3492
|
+
conversionRate: z19.number(),
|
|
3493
|
+
baselineShown: z19.number(),
|
|
3494
|
+
baselineConversions: z19.number(),
|
|
3495
|
+
baselineConversionRate: z19.number()
|
|
3278
3496
|
}).nullable(),
|
|
3279
|
-
verdict:
|
|
3497
|
+
verdict: z19.string(),
|
|
3498
|
+
blocked: blockedOutput
|
|
3280
3499
|
},
|
|
3281
3500
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
3282
3501
|
},
|
|
@@ -3285,7 +3504,12 @@ function registerCellTools(server, client) {
|
|
|
3285
3504
|
const id = encodeURIComponent(projectId);
|
|
3286
3505
|
const data = await client.get(`/projects/${id}/cells/detail?slotId=${encodeURIComponent(slotId)}&persona=${encodeURIComponent(persona)}`);
|
|
3287
3506
|
const lines = [];
|
|
3288
|
-
if (data.arm) {
|
|
3507
|
+
if (data.arm && data.blocked === "variant_history") {
|
|
3508
|
+
lines.push(
|
|
3509
|
+
data.arm.content !== null ? `Approved version (not showing yet): "${untrusted(data.arm.content, 300)}"` : `Approved designed layout (option ${untrusted(data.arm.id, 64)}), not showing yet.`,
|
|
3510
|
+
BLOCKED_LINE
|
|
3511
|
+
);
|
|
3512
|
+
} else if (data.arm) {
|
|
3289
3513
|
lines.push(
|
|
3290
3514
|
data.arm.content !== null ? `They see: "${untrusted(data.arm.content, 300)}"` : `They see a designed layout (option ${untrusted(data.arm.id, 64)}).`
|
|
3291
3515
|
);
|
|
@@ -3321,14 +3545,14 @@ function registerCellTools(server, client) {
|
|
|
3321
3545
|
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.",
|
|
3322
3546
|
inputSchema: {
|
|
3323
3547
|
projectId: projectIdSchema,
|
|
3324
|
-
slotId:
|
|
3325
|
-
persona:
|
|
3548
|
+
slotId: z19.string().min(1).max(128).describe("The slot id (a matrix column)"),
|
|
3549
|
+
persona: z19.string().min(1).max(64).describe("The persona key (a matrix row)")
|
|
3326
3550
|
},
|
|
3327
3551
|
outputSchema: {
|
|
3328
|
-
slotId:
|
|
3329
|
-
persona:
|
|
3330
|
-
status:
|
|
3331
|
-
reviewMode:
|
|
3552
|
+
slotId: z19.string(),
|
|
3553
|
+
persona: z19.string(),
|
|
3554
|
+
status: z19.literal("pending").describe("Queued \u2014 check get_cell_matrix for progress"),
|
|
3555
|
+
reviewMode: z19.boolean().nullable().describe("True: the version will wait for review_cell approval. False: it publishes automatically. Null: could not be read.")
|
|
3332
3556
|
},
|
|
3333
3557
|
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
3334
3558
|
},
|
|
@@ -3356,19 +3580,20 @@ function registerCellTools(server, client) {
|
|
|
3356
3580
|
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,
|
|
3357
3581
|
inputSchema: { projectId: projectIdSchema },
|
|
3358
3582
|
outputSchema: {
|
|
3359
|
-
reviews:
|
|
3360
|
-
|
|
3361
|
-
slotId:
|
|
3362
|
-
slotName:
|
|
3363
|
-
persona:
|
|
3364
|
-
personaDisplay:
|
|
3365
|
-
content:
|
|
3366
|
-
rationale:
|
|
3367
|
-
refinedFrom:
|
|
3368
|
-
updatedAt:
|
|
3583
|
+
reviews: z19.array(
|
|
3584
|
+
z19.object({
|
|
3585
|
+
slotId: z19.string(),
|
|
3586
|
+
slotName: z19.string(),
|
|
3587
|
+
persona: z19.string(),
|
|
3588
|
+
personaDisplay: z19.string(),
|
|
3589
|
+
content: z19.string().nullable().describe("Proposed text, when the version is text (null for a block/layout version)"),
|
|
3590
|
+
rationale: z19.string().nullable(),
|
|
3591
|
+
refinedFrom: z19.string().nullable().describe("Live version this one would replace; that version keeps serving until approval"),
|
|
3592
|
+
updatedAt: z19.string(),
|
|
3593
|
+
blocked: blockedOutput
|
|
3369
3594
|
})
|
|
3370
3595
|
),
|
|
3371
|
-
total:
|
|
3596
|
+
total: z19.number().int().describe("How many versions are waiting in all. The list holds at most the oldest 200; decide those to see the rest.")
|
|
3372
3597
|
},
|
|
3373
3598
|
annotations: { readOnlyHint: true, idempotentHint: true, openWorldHint: false }
|
|
3374
3599
|
},
|
|
@@ -3377,7 +3602,7 @@ function registerCellTools(server, client) {
|
|
|
3377
3602
|
const id = encodeURIComponent(projectId);
|
|
3378
3603
|
const data = await client.get(`/projects/${id}/cell-reviews`);
|
|
3379
3604
|
const reviews = ((_a = data.reviews) != null ? _a : []).map((r) => {
|
|
3380
|
-
var _a2, _b, _c;
|
|
3605
|
+
var _a2, _b, _c, _d;
|
|
3381
3606
|
return {
|
|
3382
3607
|
slotId: r.slotId,
|
|
3383
3608
|
slotName: r.slotName,
|
|
@@ -3386,7 +3611,8 @@ function registerCellTools(server, client) {
|
|
|
3386
3611
|
content: typeof ((_a2 = r.pendingArm) == null ? void 0 : _a2.content) === "string" ? r.pendingArm.content : null,
|
|
3387
3612
|
rationale: (_b = r.rationale) != null ? _b : null,
|
|
3388
3613
|
refinedFrom: (_c = r.refinedFrom) != null ? _c : null,
|
|
3389
|
-
updatedAt: String(r.updatedAt)
|
|
3614
|
+
updatedAt: String(r.updatedAt),
|
|
3615
|
+
blocked: (_d = r.blocked) != null ? _d : null
|
|
3390
3616
|
};
|
|
3391
3617
|
});
|
|
3392
3618
|
const total = typeof data.total === "number" ? data.total : reviews.length;
|
|
@@ -3401,7 +3627,8 @@ function registerCellTools(server, client) {
|
|
|
3401
3627
|
`- ${untrusted(r.slotName, 60)} (slotId ${untrusted(r.slotId, 64)}) for ${untrusted(r.personaDisplay, 60)} (persona ${untrusted(r.persona, 64)})`,
|
|
3402
3628
|
r.content !== null ? ` Proposed text: ${untrusted(r.content, 300)}` : " Proposed: a designed block/layout (preview it in the dashboard)",
|
|
3403
3629
|
r.rationale ? ` Why: ${untrusted(r.rationale, 300)}` : null,
|
|
3404
|
-
r.refinedFrom ? ` Would replace ${untrusted(r.refinedFrom, 64)}, which keeps serving until approval.` : null
|
|
3630
|
+
r.refinedFrom ? ` Would replace ${untrusted(r.refinedFrom, 64)}, which keeps serving until approval.` : null,
|
|
3631
|
+
r.blocked === "variant_history" ? ` Approving it will NOT show it yet: ${BLOCKED_LINE}` : null
|
|
3405
3632
|
].filter((l) => l !== null).join("\n")
|
|
3406
3633
|
);
|
|
3407
3634
|
if (total > reviews.length) {
|
|
@@ -3418,22 +3645,23 @@ function registerCellTools(server, client) {
|
|
|
3418
3645
|
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.",
|
|
3419
3646
|
inputSchema: {
|
|
3420
3647
|
projectId: projectIdSchema,
|
|
3421
|
-
slotId:
|
|
3422
|
-
persona:
|
|
3423
|
-
action:
|
|
3424
|
-
feedback:
|
|
3648
|
+
slotId: z19.string().min(1).max(128).describe("The slot id of the version under review"),
|
|
3649
|
+
persona: z19.string().min(1).max(64).describe("The persona key of the version under review"),
|
|
3650
|
+
action: z19.enum(["approve", "reject"]),
|
|
3651
|
+
feedback: z19.string().max(2e3).optional().describe("On reject: what was wrong, in the user's words. The next version written for that square is told to address it.")
|
|
3425
3652
|
},
|
|
3426
3653
|
outputSchema: {
|
|
3427
|
-
slotId:
|
|
3428
|
-
persona:
|
|
3429
|
-
action:
|
|
3430
|
-
status:
|
|
3431
|
-
armId:
|
|
3654
|
+
slotId: z19.string(),
|
|
3655
|
+
persona: z19.string(),
|
|
3656
|
+
action: z19.enum(["approve", "reject"]),
|
|
3657
|
+
status: z19.string().describe("live (approved, or a rejected refinement whose incumbent keeps serving) | rejected"),
|
|
3658
|
+
armId: z19.string().nullable().describe("The published option id, on approval"),
|
|
3659
|
+
blocked: blockedOutput
|
|
3432
3660
|
},
|
|
3433
3661
|
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false }
|
|
3434
3662
|
},
|
|
3435
3663
|
withApiErrorGuidance(async ({ projectId, slotId, persona, action, feedback }) => {
|
|
3436
|
-
var _a, _b;
|
|
3664
|
+
var _a, _b, _c;
|
|
3437
3665
|
const id = encodeURIComponent(projectId);
|
|
3438
3666
|
const res = await client.post(`/projects/${id}/cells/review`, {
|
|
3439
3667
|
slotId,
|
|
@@ -3442,10 +3670,11 @@ function registerCellTools(server, client) {
|
|
|
3442
3670
|
feedback
|
|
3443
3671
|
});
|
|
3444
3672
|
const status = (_a = res.status) != null ? _a : action === "approve" ? "live" : "rejected";
|
|
3445
|
-
const
|
|
3673
|
+
const blocked = (_b = res.blocked) != null ? _b : null;
|
|
3674
|
+
const text2 = action === "approve" && blocked === "variant_history" ? `Approved the version for ${untrusted(persona, 64)} in ${untrusted(slotId, 64)}, but it is not showing yet. ${BLOCKED_LINE}` : 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.`;
|
|
3446
3675
|
return {
|
|
3447
3676
|
content: [{ type: "text", text: text2 }],
|
|
3448
|
-
structuredContent: { slotId, persona, action, status, armId: (
|
|
3677
|
+
structuredContent: { slotId, persona, action, status, armId: (_c = res.armId) != null ? _c : null, blocked }
|
|
3449
3678
|
};
|
|
3450
3679
|
}, {
|
|
3451
3680
|
not_found: "No version is waiting for review in that cell (it may already have been approved or rejected). Check list_cell_reviews.",
|
|
@@ -3455,7 +3684,7 @@ function registerCellTools(server, client) {
|
|
|
3455
3684
|
}
|
|
3456
3685
|
|
|
3457
3686
|
// src/tools/agent-reads.ts
|
|
3458
|
-
import { z as
|
|
3687
|
+
import { z as z20 } from "zod/v3";
|
|
3459
3688
|
var READ_ONLY = { readOnlyHint: true, idempotentHint: true, openWorldHint: false };
|
|
3460
3689
|
var AREA_NAMES = {
|
|
3461
3690
|
generate: "Generate",
|
|
@@ -3507,15 +3736,15 @@ function registerAgentReadTools(server, client) {
|
|
|
3507
3736
|
description: "See which areas of this project a person has allowed agents to change: Generate, Approve and publish, Run tests, Goals and funnels, Campaigns and audiences, Project settings. Reading is always allowed; this tells you what a write tool will be refused for before you try it. Agents cannot change these switches \u2014 only a person can, in Settings \u2192 Agent access.",
|
|
3508
3737
|
inputSchema: { projectId: projectIdSchema },
|
|
3509
3738
|
outputSchema: {
|
|
3510
|
-
areas:
|
|
3511
|
-
generate:
|
|
3512
|
-
approve:
|
|
3513
|
-
tests:
|
|
3514
|
-
goals:
|
|
3515
|
-
campaigns:
|
|
3516
|
-
settings:
|
|
3739
|
+
areas: z20.object({
|
|
3740
|
+
generate: z20.boolean(),
|
|
3741
|
+
approve: z20.boolean(),
|
|
3742
|
+
tests: z20.boolean(),
|
|
3743
|
+
goals: z20.boolean(),
|
|
3744
|
+
campaigns: z20.boolean(),
|
|
3745
|
+
settings: z20.boolean()
|
|
3517
3746
|
}).describe("true = agents may act in this area"),
|
|
3518
|
-
canEdit:
|
|
3747
|
+
canEdit: z20.boolean().describe("Whether THIS credential could change the switches (always false for an agent)")
|
|
3519
3748
|
},
|
|
3520
3749
|
annotations: READ_ONLY
|
|
3521
3750
|
},
|
|
@@ -3542,35 +3771,35 @@ function registerAgentReadTools(server, client) {
|
|
|
3542
3771
|
description: "List this project's named campaigns, their retargeting groups, and the campaigns seen in traffic. Pass campaignId to get one campaign's card instead: clicks, new people, how many came back, conversions per version, and the control group (visitors held back on the original site). Counts only \u2014 no lift is claimed." + UNTRUSTED_FIELDS_NOTE,
|
|
3543
3772
|
inputSchema: __spreadValues({
|
|
3544
3773
|
projectId: projectIdSchema,
|
|
3545
|
-
campaignId:
|
|
3774
|
+
campaignId: z20.string().optional().describe("A campaign id from this tool's list; returns that campaign's card")
|
|
3546
3775
|
}, rangeInputSchema("30d")),
|
|
3547
3776
|
outputSchema: {
|
|
3548
|
-
campaigns:
|
|
3549
|
-
id:
|
|
3550
|
-
name:
|
|
3551
|
-
status:
|
|
3552
|
-
arrivalType:
|
|
3553
|
-
landingPaths:
|
|
3777
|
+
campaigns: z20.array(z20.object({
|
|
3778
|
+
id: z20.string(),
|
|
3779
|
+
name: z20.string(),
|
|
3780
|
+
status: z20.string().nullable(),
|
|
3781
|
+
arrivalType: z20.string().nullable(),
|
|
3782
|
+
landingPaths: z20.array(z20.string())
|
|
3554
3783
|
})).optional(),
|
|
3555
|
-
retargeting:
|
|
3556
|
-
groupId:
|
|
3557
|
-
campaignId:
|
|
3558
|
-
name:
|
|
3559
|
-
status:
|
|
3560
|
-
endsAt:
|
|
3561
|
-
memberCount:
|
|
3784
|
+
retargeting: z20.array(z20.object({
|
|
3785
|
+
groupId: z20.string(),
|
|
3786
|
+
campaignId: z20.string().nullable(),
|
|
3787
|
+
name: z20.string(),
|
|
3788
|
+
status: z20.string().nullable(),
|
|
3789
|
+
endsAt: z20.string().nullable(),
|
|
3790
|
+
memberCount: z20.number()
|
|
3562
3791
|
})).optional(),
|
|
3563
|
-
observed:
|
|
3564
|
-
card:
|
|
3565
|
-
campaignId:
|
|
3566
|
-
name:
|
|
3567
|
-
status:
|
|
3568
|
-
clicks:
|
|
3569
|
-
people:
|
|
3570
|
-
cameBack:
|
|
3571
|
-
controlGroup:
|
|
3572
|
-
versions:
|
|
3573
|
-
retargetingGroupId:
|
|
3792
|
+
observed: z20.array(z20.object({ campaign: z20.string(), sessions: z20.number(), channel: z20.string().nullable() })).optional(),
|
|
3793
|
+
card: z20.object({
|
|
3794
|
+
campaignId: z20.string(),
|
|
3795
|
+
name: z20.string(),
|
|
3796
|
+
status: z20.string().nullable(),
|
|
3797
|
+
clicks: z20.number(),
|
|
3798
|
+
people: z20.number().describe("New people served as the campaign"),
|
|
3799
|
+
cameBack: z20.number(),
|
|
3800
|
+
controlGroup: z20.number().describe("Matched visits held back on the original site"),
|
|
3801
|
+
versions: z20.array(z20.object({ label: z20.string(), shown: z20.number(), conversions: z20.number() })).describe("Per section and version; one visitor can appear in several rows, so do not add them up"),
|
|
3802
|
+
retargetingGroupId: z20.string().nullable()
|
|
3574
3803
|
}).optional().describe("Only when campaignId was given")
|
|
3575
3804
|
},
|
|
3576
3805
|
annotations: READ_ONLY
|
|
@@ -3653,17 +3882,17 @@ function registerAgentReadTools(server, client) {
|
|
|
3653
3882
|
{
|
|
3654
3883
|
title: "Retargeting report",
|
|
3655
3884
|
description: "One retargeting group's numbers: how many people it started with, how many came back, clicks and conversions. These are counts, not lift. Get the group id from list_campaigns." + UNTRUSTED_FIELDS_NOTE,
|
|
3656
|
-
inputSchema: { projectId: projectIdSchema, groupId:
|
|
3885
|
+
inputSchema: { projectId: projectIdSchema, groupId: z20.string().describe("A retargeting group id from list_campaigns") },
|
|
3657
3886
|
outputSchema: {
|
|
3658
|
-
groupId:
|
|
3659
|
-
name:
|
|
3660
|
-
status:
|
|
3661
|
-
endsAt:
|
|
3662
|
-
members:
|
|
3663
|
-
cameBack:
|
|
3664
|
-
converted:
|
|
3665
|
-
clicks:
|
|
3666
|
-
versions:
|
|
3887
|
+
groupId: z20.string(),
|
|
3888
|
+
name: z20.string(),
|
|
3889
|
+
status: z20.string().nullable(),
|
|
3890
|
+
endsAt: z20.string().nullable(),
|
|
3891
|
+
members: z20.number(),
|
|
3892
|
+
cameBack: z20.number(),
|
|
3893
|
+
converted: z20.number(),
|
|
3894
|
+
clicks: z20.number(),
|
|
3895
|
+
versions: z20.array(z20.object({ label: z20.string(), shown: z20.number(), conversions: z20.number() }))
|
|
3667
3896
|
},
|
|
3668
3897
|
annotations: READ_ONLY
|
|
3669
3898
|
},
|
|
@@ -3700,20 +3929,20 @@ function registerAgentReadTools(server, client) {
|
|
|
3700
3929
|
description: "The audiences visitors are sorted into: the ones the site declares, the ones discovered from behaviour (with how many sessions, their share of traffic, and how much evidence there is), and whether the discovered set can be promoted to serving yet, with what is blocking it in plain words." + UNTRUSTED_FIELDS_NOTE,
|
|
3701
3930
|
inputSchema: { projectId: projectIdSchema },
|
|
3702
3931
|
outputSchema: {
|
|
3703
|
-
declared:
|
|
3704
|
-
source:
|
|
3705
|
-
members:
|
|
3932
|
+
declared: z20.object({
|
|
3933
|
+
source: z20.string().nullable(),
|
|
3934
|
+
members: z20.array(z20.object({ key: z20.string(), displayName: z20.string(), status: z20.string().nullable() }))
|
|
3706
3935
|
}).nullable(),
|
|
3707
|
-
discovered:
|
|
3708
|
-
members:
|
|
3709
|
-
key:
|
|
3710
|
-
displayName:
|
|
3711
|
-
sessions:
|
|
3712
|
-
share:
|
|
3713
|
-
evidence:
|
|
3936
|
+
discovered: z20.object({
|
|
3937
|
+
members: z20.array(z20.object({
|
|
3938
|
+
key: z20.string(),
|
|
3939
|
+
displayName: z20.string(),
|
|
3940
|
+
sessions: z20.number().nullable(),
|
|
3941
|
+
share: z20.number().nullable(),
|
|
3942
|
+
evidence: z20.string().describe("strong_evidence | moderate_evidence | no_clear_difference | not_enough_data | not_checked_yet")
|
|
3714
3943
|
}))
|
|
3715
3944
|
}).nullable().describe("null when no discovered set exists yet"),
|
|
3716
|
-
promotion:
|
|
3945
|
+
promotion: z20.object({ eligible: z20.boolean(), blockers: z20.array(z20.string()) }).nullable()
|
|
3717
3946
|
},
|
|
3718
3947
|
annotations: READ_ONLY
|
|
3719
3948
|
},
|
|
@@ -3779,18 +4008,18 @@ function registerAgentReadTools(server, client) {
|
|
|
3779
4008
|
description: "The styles captured from the site (what generated sections borrow), grouped by role, whether their colors were actually measured, when the scan last ran, and the site audit score. Without measured colors a style cannot be checked for readable contrast." + UNTRUSTED_FIELDS_NOTE,
|
|
3780
4009
|
inputSchema: { projectId: projectIdSchema },
|
|
3781
4010
|
outputSchema: {
|
|
3782
|
-
colorsMeasured:
|
|
3783
|
-
roles:
|
|
3784
|
-
role:
|
|
3785
|
-
count:
|
|
3786
|
-
measuredColors:
|
|
4011
|
+
colorsMeasured: z20.boolean().describe("false when no captured style has a measured text or background color"),
|
|
4012
|
+
roles: z20.array(z20.object({
|
|
4013
|
+
role: z20.string(),
|
|
4014
|
+
count: z20.number(),
|
|
4015
|
+
measuredColors: z20.number().describe("How many of these styles have a measured color")
|
|
3787
4016
|
})),
|
|
3788
|
-
lastScan:
|
|
3789
|
-
audit:
|
|
3790
|
-
status:
|
|
3791
|
-
score:
|
|
3792
|
-
auditedAt:
|
|
3793
|
-
checking:
|
|
4017
|
+
lastScan: z20.object({ editorAt: z20.string().nullable(), crawlAt: z20.string().nullable() }),
|
|
4018
|
+
audit: z20.object({
|
|
4019
|
+
status: z20.string().nullable(),
|
|
4020
|
+
score: z20.number().nullable(),
|
|
4021
|
+
auditedAt: z20.string().nullable(),
|
|
4022
|
+
checking: z20.boolean()
|
|
3794
4023
|
}).nullable().describe("null when the audit could not be read")
|
|
3795
4024
|
},
|
|
3796
4025
|
annotations: READ_ONLY
|
|
@@ -3846,13 +4075,13 @@ function registerAgentReadTools(server, client) {
|
|
|
3846
4075
|
{
|
|
3847
4076
|
title: "Region history",
|
|
3848
4077
|
description: "A region's published versions over time (newest first, which one is live) and whether the region is still found on the live page. Get the region id from list_components." + UNTRUSTED_FIELDS_NOTE,
|
|
3849
|
-
inputSchema: { projectId: projectIdSchema, regionId:
|
|
4078
|
+
inputSchema: { projectId: projectIdSchema, regionId: z20.string().describe("The region's id (the slot id shown by list_components)") },
|
|
3850
4079
|
outputSchema: {
|
|
3851
|
-
regionId:
|
|
3852
|
-
currentVersion:
|
|
3853
|
-
versions:
|
|
3854
|
-
recentDecisions:
|
|
3855
|
-
drift:
|
|
4080
|
+
regionId: z20.string(),
|
|
4081
|
+
currentVersion: z20.number(),
|
|
4082
|
+
versions: z20.array(z20.object({ version: z20.number(), publishedAt: z20.string().nullable(), isCurrent: z20.boolean() })),
|
|
4083
|
+
recentDecisions: z20.array(z20.object({ action: z20.string(), at: z20.string().nullable() })),
|
|
4084
|
+
drift: z20.object({ verdict: z20.string(), message: z20.string(), checkedUrl: z20.string().nullable() }).nullable().describe("Whether the region is still found on the live page; null when the check could not run")
|
|
3856
4085
|
},
|
|
3857
4086
|
annotations: READ_ONLY
|
|
3858
4087
|
},
|
|
@@ -3886,7 +4115,7 @@ function registerAgentReadTools(server, client) {
|
|
|
3886
4115
|
}
|
|
3887
4116
|
|
|
3888
4117
|
// src/tools/manage.ts
|
|
3889
|
-
import { z as
|
|
4118
|
+
import { z as z21 } from "zod/v3";
|
|
3890
4119
|
var a = (method, route, extra = {}) => __spreadValues({ method, route }, extra);
|
|
3891
4120
|
var ACTIONS = {
|
|
3892
4121
|
manage_generation: {
|
|
@@ -4024,13 +4253,13 @@ function registerManageTools(server, client) {
|
|
|
4024
4253
|
const meta = TOOLS[tool];
|
|
4025
4254
|
const shape = {
|
|
4026
4255
|
projectId: projectIdSchema,
|
|
4027
|
-
action:
|
|
4028
|
-
enabled:
|
|
4029
|
-
body:
|
|
4256
|
+
action: z21.enum(names).describe("What to do. Each action needs only the fields noted below."),
|
|
4257
|
+
enabled: z21.boolean().optional().describe("For set_auto_fill, set_require_approval, set_observation_mode: on (true) or off (false)"),
|
|
4258
|
+
body: z21.record(z21.unknown()).optional().describe("The fields to send, for actions that change several things at once; the API checks them and says what's wrong")
|
|
4030
4259
|
};
|
|
4031
|
-
if (tool === "manage_generation") shape.depth =
|
|
4032
|
-
if (tool === "manage_settings") shape.origin =
|
|
4033
|
-
for (const p of paramNames(tool)) shape[p] =
|
|
4260
|
+
if (tool === "manage_generation") shape.depth = z21.enum(["auto", "rewrite", "redesign"]).optional().describe("For set_depth: how far a rewrite may go");
|
|
4261
|
+
if (tool === "manage_settings") shape.origin = z21.string().optional().describe("For remove_origin: the origin to stop allowing, e.g. https://example.com");
|
|
4262
|
+
for (const p of paramNames(tool)) shape[p] = z21.string().optional().describe(`Required by the actions whose route has :${p}`);
|
|
4034
4263
|
server.registerTool(
|
|
4035
4264
|
tool,
|
|
4036
4265
|
{
|
|
@@ -4070,8 +4299,32 @@ function registerManageTools(server, client) {
|
|
|
4070
4299
|
}
|
|
4071
4300
|
}
|
|
4072
4301
|
|
|
4302
|
+
// src/instructions.ts
|
|
4303
|
+
var SERVER_INSTRUCTIONS = `SentientUI serves each visitor the version of each adaptive component that works best for their audience, measured against a control group kept on the original.
|
|
4304
|
+
|
|
4305
|
+
Audiences, and what makes each one serve (precedence: declared > retargeting > discovered > campaign > arrival > everyone):
|
|
4306
|
+
- everyone (key "unknown"): every visitor no other audience claims.
|
|
4307
|
+
- Declared persona (bare key, e.g. "developer"): serves ONLY on visits where the site declares it \u2014 the persona prop on <AdaptiveRoot>/<AdaptiveProvider>, init({ persona }) in @sentientui/core, or window.sentient.persona on the script tag. Adding it to the vocabulary only names it; a declared persona the site never sends has no visitors and nobody sees its versions. Undeclared visitors are never guessed into one. Use declared personas for roles the site knows (signed-in users).
|
|
4308
|
+
- Discovered audience ("d-" key): found in behaviour; serves only after it is promoted (evidence that it wants something different).
|
|
4309
|
+
- Campaign, arrival type, retargeting group ("c-", "a-", "r-" keys): visitors who arrived on a named campaign link, arrived a certain way, or were moved into a retargeting group. This is how to reach anonymous traffic.
|
|
4310
|
+
- get_persona_breakdown personas counts the audience each visit was actually served as (the same number as the Matrix share in get_cell_matrix). Its behaviourGroups ("Behaviour group N") are visitors who behaved alike: not personas or audiences, they serve nothing \u2014 never report one as an audience's visitors.
|
|
4311
|
+
- A version's name, or a code variants key, never targets an audience. To give one audience one version, pin it (manage_approvals pin); pinned visitors stop teaching the optimizer for that component.
|
|
4312
|
+
|
|
4313
|
+
Components: an <Adaptive> with children and variants whose id already ran a variants test keeps serving that old test; dashboard-written or generated versions for it do not serve until it is migrated (dashboard Matrix -> Components -> Migrate..., or manage_tests migrate_component).
|
|
4314
|
+
|
|
4315
|
+
Funnels: every step must have something that sends it (a page-visit rule, a click or form goal, useGoal in the browser, or trackServerGoal from the server), or that step never fills.
|
|
4316
|
+
|
|
4317
|
+
Server goal, exact shape (server only, never the browser):
|
|
4318
|
+
import { trackServerGoal } from '@sentientui/react/server'; // or '@sentientui/core/server'
|
|
4319
|
+
await trackServerGoal({ serverKey: process.env.SENTIENT_SECRET_KEY!, userId: user.id, name: 'subscribed', dedupeKey: user.id });
|
|
4320
|
+
userId must be the id the site identifies the visitor with (<AdaptiveRoot userId={user.id}>); in the visitor's own request pass sessionId: readSessionCookie(cookies, publicKey) instead.
|
|
4321
|
+
|
|
4322
|
+
Excluding the team and test sites (dashboard Settings -> Internal traffic): visits marked internal still see versions (QA works) but never count in any report and never teach the optimizer; get_traffic_breakdown lists them as "Your team / test sites". They are marked by internal sites (allowed domains such as staging or localhost), team emails and domains (they match visitors the site identifies with identify(userId, { email }); the SDK sends only a SHA-256 of the address and its domain, never the address), a browser link, or the code flag (the internal prop on <AdaptiveRoot>/<AdaptiveProvider>, init({ internal }), window.sentient.internal). There is no report filter or IP rule, and visits from before a rule was turned on cannot be separated. Read the rules with get_internal_traffic_rules; a person changes them in the dashboard.
|
|
4323
|
+
|
|
4324
|
+
Write tools change what real visitors see: confirm with the user first. Call get_agent_access before a manage_* write.`;
|
|
4325
|
+
|
|
4073
4326
|
// src/server.ts
|
|
4074
|
-
var PKG_VERSION = true ? "0.
|
|
4327
|
+
var PKG_VERSION = true ? "0.27.0" : "0.0.0-dev";
|
|
4075
4328
|
function createMcpServer(client) {
|
|
4076
4329
|
const server = new McpServer(
|
|
4077
4330
|
{
|
|
@@ -4089,7 +4342,11 @@ function createMcpServer(client) {
|
|
|
4089
4342
|
mimeTypes: [RESOURCE_MIME_TYPE]
|
|
4090
4343
|
}
|
|
4091
4344
|
}
|
|
4092
|
-
}
|
|
4345
|
+
},
|
|
4346
|
+
// Sent in the initialize result: the facts an agent otherwise gets
|
|
4347
|
+
// wrong (which audiences serve, clusters are not personas, hybrids need
|
|
4348
|
+
// Migrate, the server goal call shape). See instructions.ts.
|
|
4349
|
+
instructions: SERVER_INSTRUCTIONS
|
|
4093
4350
|
}
|
|
4094
4351
|
);
|
|
4095
4352
|
registerUiResources(server);
|
|
@@ -4108,6 +4365,7 @@ function createMcpServer(client) {
|
|
|
4108
4365
|
registerIntegrationGuideTools(server);
|
|
4109
4366
|
registerAgentTrafficTools(server, client);
|
|
4110
4367
|
registerTrafficTools(server, client);
|
|
4368
|
+
registerInternalTrafficTools(server, client);
|
|
4111
4369
|
registerCellTools(server, client);
|
|
4112
4370
|
registerAgentReadTools(server, client);
|
|
4113
4371
|
registerManageTools(server, client);
|