@plitzi/sdk-mcp 0.39.3 → 0.39.6

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.
Files changed (106) hide show
  1. package/CHANGELOG.md +42 -0
  2. package/README.md +39 -39
  3. package/dist/index.d.ts +1 -0
  4. package/dist/index.js +2 -1
  5. package/dist/modules/mcp/answerBudgets.d.ts +29 -0
  6. package/dist/modules/mcp/answerBudgets.js +37 -0
  7. package/dist/modules/mcp/apps/example/view/index.tsx +0 -1
  8. package/dist/modules/mcp/apps/render/view/index.tsx +0 -1
  9. package/dist/modules/mcp/catalogs/pluginCatalog.d.ts +8 -0
  10. package/dist/modules/mcp/catalogs/pluginCatalog.js +35 -1
  11. package/dist/modules/mcp/helpers/guide/reference.d.ts +1 -1
  12. package/dist/modules/mcp/helpers/guide/reference.js +16 -2
  13. package/dist/modules/mcp/helpers/guide/structure.d.ts +1 -1
  14. package/dist/modules/mcp/helpers/guide/structure.js +1 -0
  15. package/dist/modules/mcp/helpers/opResult.d.ts +3 -1
  16. package/dist/modules/mcp/helpers/opResult.js +3 -1
  17. package/dist/modules/mcp/localScreenshotClient.d.ts +10 -0
  18. package/dist/modules/mcp/localScreenshotClient.js +46 -16
  19. package/dist/modules/mcp/previewClient.js +2 -2
  20. package/dist/modules/mcp/resources/canonical.js +2 -2
  21. package/dist/modules/mcp/server.d.ts +1 -1
  22. package/dist/modules/mcp/server.js +10 -3
  23. package/dist/modules/mcp/tools/activity.js +2 -2
  24. package/dist/modules/mcp/tools/apply/dispatch.js +7 -1
  25. package/dist/modules/mcp/tools/apply/index.d.ts +25 -1
  26. package/dist/modules/mcp/tools/apply/index.js +21 -5
  27. package/dist/modules/mcp/tools/describeOperation.js +1 -1
  28. package/dist/modules/mcp/tools/index.js +5 -1
  29. package/dist/modules/mcp/tools/intents.js +26 -4
  30. package/dist/modules/mcp/tools/look.d.ts +1 -0
  31. package/dist/modules/mcp/tools/look.js +2 -1
  32. package/dist/modules/mcp/tools/operations/actions/deleteAction.js +1 -1
  33. package/dist/modules/mcp/tools/operations/actions/patchAction.js +3 -3
  34. package/dist/modules/mcp/tools/operations/actions/upsertAction.js +1 -1
  35. package/dist/modules/mcp/tools/operations/connectors/deleteConnector.js +1 -1
  36. package/dist/modules/mcp/tools/operations/connectors/patchConnector.js +2 -2
  37. package/dist/modules/mcp/tools/operations/data/index.js +3 -3
  38. package/dist/modules/mcp/tools/operations/functions/index.js +2 -2
  39. package/dist/modules/mcp/tools/operations/index.d.ts +97 -4
  40. package/dist/modules/mcp/tools/operations/index.js +1 -0
  41. package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +1 -1
  42. package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +1 -1
  43. package/dist/modules/mcp/tools/operations/schema/components/deleteComponent.js +2 -2
  44. package/dist/modules/mcp/tools/operations/schema/components/upsertComponent.js +8 -8
  45. package/dist/modules/mcp/tools/operations/schema/elements/addSpec.d.ts +29 -0
  46. package/dist/modules/mcp/tools/operations/schema/elements/addSpec.js +118 -0
  47. package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +2 -2
  48. package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +4 -4
  49. package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +2 -2
  50. package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +2 -0
  51. package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +3 -3
  52. package/dist/modules/mcp/tools/operations/schema/flags/deleteFlag.js +1 -1
  53. package/dist/modules/mcp/tools/operations/schema/flags/upsertFlag.js +2 -2
  54. package/dist/modules/mcp/tools/operations/schema/folders/deleteFolder.js +1 -1
  55. package/dist/modules/mcp/tools/operations/schema/folders/upsertFolder.js +1 -1
  56. package/dist/modules/mcp/tools/operations/schema/index.d.ts +1 -0
  57. package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +4 -4
  58. package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +1 -1
  59. package/dist/modules/mcp/tools/operations/schema/operations.d.ts +25 -1
  60. package/dist/modules/mcp/tools/operations/schema/operations.js +2 -0
  61. package/dist/modules/mcp/tools/operations/schema/pages/deleteLayout.js +2 -2
  62. package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +1 -1
  63. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +4 -0
  64. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +14 -7
  65. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +8 -1
  66. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +9 -6
  67. package/dist/modules/mcp/tools/operations/schema/variables/deleteVariable.js +3 -2
  68. package/dist/modules/mcp/tools/operations/schema/write.js +3 -3
  69. package/dist/modules/mcp/tools/operations/style/definitions/deleteDefinition.js +2 -1
  70. package/dist/modules/mcp/tools/operations/style/definitions/patchDefinition.js +1 -1
  71. package/dist/modules/mcp/tools/operations/style/fonts/deleteFont.js +2 -2
  72. package/dist/modules/mcp/tools/operations/style/fonts/upsertFont.js +1 -1
  73. package/dist/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.js +2 -1
  74. package/dist/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.js +1 -1
  75. package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +2 -1
  76. package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +1 -1
  77. package/dist/modules/mcp/tools/operations/style/validate.js +6 -6
  78. package/dist/modules/mcp/tools/operations/style/variables/deleteStyleVariable.js +3 -2
  79. package/dist/modules/mcp/tools/operations/style/write.js +1 -1
  80. package/dist/modules/mcp/tools/releases.d.ts +3 -0
  81. package/dist/modules/mcp/tools/releases.js +60 -0
  82. package/dist/modules/mcp/tools/render.d.ts +24 -1
  83. package/dist/modules/mcp/tools/renderWidget.d.ts +24 -1
  84. package/dist/modules/mcp/tools/search.js +1 -1
  85. package/dist/modules/mcp/tools/shared/agentHtml.d.ts +8 -0
  86. package/dist/modules/mcp/tools/shared/agentHtml.js +18 -0
  87. package/dist/modules/mcp/tools/shared/lintDraft.js +1 -0
  88. package/dist/modules/mcp/tools/shared/look.d.ts +2 -0
  89. package/dist/modules/mcp/tools/shared/look.js +15 -8
  90. package/dist/modules/mcp/tools/shared/repeats.d.ts +1 -1
  91. package/dist/modules/mcp/tools/shared/repeats.js +1 -1
  92. package/dist/modules/mcp/tools/shared/tool.d.ts +21 -1
  93. package/dist/modules/mcp/tools/shared/validator/connectors.js +3 -0
  94. package/dist/modules/mcp/tools/shared/validator/css.js +2 -0
  95. package/dist/modules/mcp/tools/shared/validator/elements.js +3 -0
  96. package/dist/modules/mcp/tools/shared/validator/index.js +39 -0
  97. package/dist/modules/mcp/tools/shared/validator/interactions.js +1 -0
  98. package/dist/modules/mcp/tools/shared/validator/refs.js +3 -0
  99. package/dist/modules/mcp/tools/tryFunction.js +2 -2
  100. package/dist/modules/mcp/types/aiSchema.d.ts +3 -0
  101. package/dist/modules/mcp/types/previewTypes.d.ts +9 -1
  102. package/dist/options.d.ts +1 -1
  103. package/dist/preview/createPreview.js +38 -7
  104. package/dist/server.d.ts +1 -1
  105. package/dist/server.js +2 -2
  106. package/package.json +10 -10
@@ -1,4 +1,5 @@
1
1
  import { ValidationError } from '../types';
2
+ import { RefusalCode } from '@plitzi/sdk-shared/refusals';
2
3
  /** The result of one mutation handler: counts, the resource URIs it invalidated, any error, and the refs of
3
4
  * elements it created/updated (so the caller can return their full detail as context — never for deletes). */
4
5
  export interface OpResult {
@@ -10,4 +11,5 @@ export interface OpResult {
10
11
  elementRefs?: string[];
11
12
  }
12
13
  export declare const empty: () => OpResult;
13
- export declare const fail: (path: string, message: string, hint: string, validValues?: unknown[]) => OpResult;
14
+ /** A refusal of one operation: its code (`@plitzi/sdk-shared/refusals`), where, what was wrong, and the step that fixes it. */
15
+ export declare const fail: (code: RefusalCode, path: string, message: string, hint: string, validValues?: unknown[]) => OpResult;
@@ -5,9 +5,11 @@ var empty = () => ({
5
5
  deleted: 0,
6
6
  staleResources: []
7
7
  });
8
- var fail = (path, message, hint, validValues) => ({
8
+ /** A refusal of one operation: its code (`@plitzi/sdk-shared/refusals`), where, what was wrong, and the step that fixes it. */
9
+ var fail = (code, path, message, hint, validValues) => ({
9
10
  ...empty(),
10
11
  errors: [{
12
+ code,
11
13
  path,
12
14
  message,
13
15
  hint,
@@ -57,6 +57,16 @@ type Browser = {
57
57
  type Launcher = {
58
58
  launch: (options?: Record<string, unknown>) => Promise<Browser>;
59
59
  };
60
+ /** The regions a page of `height` is captured in: one, or parts of `PART_HEIGHT` each labelled with its place. */
61
+ export declare const captureParts: (label: string, width: number, height: number) => {
62
+ label: string;
63
+ clip?: {
64
+ x: number;
65
+ y: number;
66
+ width: number;
67
+ height: number;
68
+ };
69
+ }[];
60
70
  /** Which driver this host has, if any. Playwright first: it is what the visual suites already install. */
61
71
  export declare const resolveLocalBrowser: () => Promise<Launcher | undefined>;
62
72
  export type LocalScreenshotClientConfig = {
@@ -21,8 +21,31 @@ var CONTENT_HEIGHT = () => {
21
21
  * by then was not going to make the shot anyway, and a picture in a fallback beats no picture at all.
22
22
  */
23
23
  var FONTS_READY = () => Promise.race([document.fonts.ready, new Promise((resolve) => setTimeout(resolve, 3e3))]);
24
- /** Guard against a runaway page turning one screenshot into a hundred-megabyte PNG. */
25
- var MAX_HEIGHT = 8e3;
24
+ /**
25
+ * A capture shows the page, the same in the three places one is taken — this client, the screenshot service
26
+ * (`plitzi-platform` `cluster/services/screenshot`) and `plitzi-sdk-server`'s visual suite (`visual/helpers.ts`,
27
+ * `shoot`): drawn with `prefers-reduced-motion: reduce` (`emulateCaptureMedia`), so what reveals itself as it scrolls in
28
+ * rests at its end state; and a page taller than `ONE_SHOT_HEIGHT` in parts of at most `PART_HEIGHT` (`clip`), in order
29
+ * — Chromium paints nothing past 16,384 px of one capture. Never by scrolling: what sticks would be in every part.
30
+ */
31
+ var ONE_SHOT_HEIGHT = 16e3;
32
+ var PART_HEIGHT = 8e3;
33
+ /** Guard against a runaway page: past this, its foot is not captured, and the capture says so in its last part. */
34
+ var MAX_HEIGHT = 32e3;
35
+ /** The regions a page of `height` is captured in: one, or parts of `PART_HEIGHT` each labelled with its place. */
36
+ var captureParts = (label, width, height) => {
37
+ if (height <= ONE_SHOT_HEIGHT) return [{ label }];
38
+ const count = Math.ceil(height / PART_HEIGHT);
39
+ return Array.from({ length: count }, (_, index) => ({
40
+ label: `${label} (${String(index + 1)}/${String(count)})`,
41
+ clip: {
42
+ x: 0,
43
+ y: index * PART_HEIGHT,
44
+ width,
45
+ height: Math.min(PART_HEIGHT, height - index * PART_HEIGHT)
46
+ }
47
+ }));
48
+ };
26
49
  var importDriver = async (name) => {
27
50
  try {
28
51
  const module = await import(
@@ -101,27 +124,34 @@ var createLocalScreenshotClient = async ({ renderBaseUrl, ignoreHttpsErrors = tr
101
124
  message: `The page answered ${response.status()}.`
102
125
  };
103
126
  await page.evaluate(FONTS_READY);
127
+ let height = viewport.height;
104
128
  if (fullPage) {
105
- const height = Math.min(await page.evaluate(CONTENT_HEIGHT), MAX_HEIGHT);
129
+ height = Math.min(await page.evaluate(CONTENT_HEIGHT), MAX_HEIGHT);
106
130
  if (height > viewport.height) await setViewport(page, {
107
131
  width: viewport.width,
108
132
  height
109
133
  });
110
134
  }
111
135
  if (views.includes("image")) {
112
- const shot = await page.screenshot(format === "webp" ? {
136
+ const type = format === "webp" ? {
113
137
  type: "webp",
114
- quality,
115
- fullPage
116
- } : {
117
- type: "png",
118
- fullPage
119
- });
120
- images.push({
121
- label: viewport.label,
122
- mimeType: format === "webp" ? "image/webp" : "image/png",
123
- data: Buffer.from(shot).toString("base64")
124
- });
138
+ quality
139
+ } : { type: "png" };
140
+ for (const part of fullPage ? captureParts(viewport.label, viewport.width, height) : [{ label: viewport.label }]) {
141
+ const shot = await page.screenshot("clip" in part ? {
142
+ ...type,
143
+ clip: part.clip,
144
+ captureBeyondViewport: true
145
+ } : {
146
+ ...type,
147
+ fullPage
148
+ });
149
+ images.push({
150
+ label: part.label,
151
+ mimeType: format === "webp" ? "image/webp" : "image/png",
152
+ data: Buffer.from(shot).toString("base64")
153
+ });
154
+ }
125
155
  }
126
156
  const outline = views.includes("accessibility") ? await readOutline(page) : void 0;
127
157
  if (outline !== void 0) accessibility.push({
@@ -145,4 +175,4 @@ var createLocalScreenshotClient = async ({ renderBaseUrl, ignoreHttpsErrors = tr
145
175
  }
146
176
  } };
147
177
  };
148
- export { createLocalScreenshotClient, resolveLocalBrowser };
178
+ export { captureParts, createLocalScreenshotClient, resolveLocalBrowser };
@@ -16,13 +16,13 @@ var createHttpPreviewClient = ({ url, secret, fetchImpl = fetch }) => ({ async r
16
16
  } catch (err) {
17
17
  return {
18
18
  ok: false,
19
- error: "PREVIEW_UNREACHABLE",
19
+ error: "unanswered",
20
20
  message: `Preview endpoint unreachable: ${String(err)}`
21
21
  };
22
22
  }
23
23
  if (!res.ok && res.status !== 422) return {
24
24
  ok: false,
25
- error: "PREVIEW_REQUEST_FAILED",
25
+ error: "unanswered",
26
26
  message: `Preview endpoint returned ${res.status}.`
27
27
  };
28
28
  return await res.json();
@@ -15,12 +15,12 @@ var canonicalUri = (env, uri) => {
15
15
  var resourceErrorMessage = (env, uri) => {
16
16
  const canonical = canonicalUri(env, uri);
17
17
  if (itemTemplates(env).some((tpl) => canonical.startsWith(tpl.slice(0, tpl.lastIndexOf("/") + 1)))) return JSON.stringify({
18
- error: "NOT_FOUND",
18
+ error: "missing",
19
19
  message: `No resource at '${uri}'. Its shape is valid but the ref does not resolve.`,
20
20
  hint: "It may have been deleted or your URI is stale. Re-list the parent resource (pages/definitions) to refresh."
21
21
  });
22
22
  return JSON.stringify({
23
- error: "MALFORMED_URI",
23
+ error: "bad-value",
24
24
  message: `'${uri}' matches no resource template.`,
25
25
  hint: "Do not hand-build element URIs — take the ready-made uri from plitzi_search or a write response.",
26
26
  validTemplates: [primerUri(env), ...itemTemplates(env)]
@@ -11,7 +11,7 @@ import { SSRAdapters, ServerLogger, SSRGrant } from '@plitzi/sdk-kernel/types';
11
11
  export interface McpServerContext {
12
12
  adapters: SSRAdapters;
13
13
  getGrant: () => Promise<SSRGrant | undefined>;
14
- /** How a look (plitzi_look, plitzi_apply's `look`) reaches the renderer. Absent → it reports PREVIEW_UNAVAILABLE, so an
14
+ /** How a look (plitzi_look, plitzi_apply's `look`) reaches the renderer. Absent → it refuses with `not-allowed`, so an
15
15
  * MCP-only deployment without a renderer still runs every other tool. */
16
16
  preview?: PreviewClient;
17
17
  /** The dedicated browser service a look takes an image or an accessibility outline with. Absent → a look answers
@@ -60,7 +60,7 @@ var createMcpServer = async ({ adapters, getGrant, preview, screenshot, logger,
60
60
  ...entitlements ? { entitlements } : {}
61
61
  };
62
62
  };
63
- const { saveSchema, saveStyle, saveConnector, deleteConnector, saveAction, deleteAction, saveFunctions, tryFunction, runE2eTests, saveData, getActivity } = adapters;
63
+ const { saveSchema, saveStyle, saveConnector, deleteConnector, saveAction, deleteAction, saveFunctions, tryFunction, runE2eTests, saveData, getActivity, getRenderCredential, releases } = adapters;
64
64
  const write = {
65
65
  userId: grant?.userId,
66
66
  batch: randomUUID(),
@@ -81,7 +81,7 @@ var createMcpServer = async ({ adapters, getGrant, preview, screenshot, logger,
81
81
  const getSpace = () => spacePromise ??= loadSpace();
82
82
  const server = new McpServer({
83
83
  name: "plitzi-mcp",
84
- version: "0.39.3"
84
+ version: "0.39.6"
85
85
  }, { instructions: hasSpace ? serverInstructions : widgetsOnlyInstructions });
86
86
  const { getChanges } = adapters;
87
87
  registerResources(server, getSpace, MCP_ENV, log, hasSpace, getChanges ? (query) => getChanges(requireSpaceId(), MCP_ENV, query) : void 0);
@@ -99,10 +99,17 @@ var createMcpServer = async ({ adapters, getGrant, preview, screenshot, logger,
99
99
  proxy: proxyForTool(proxy, tool.name),
100
100
  ...tryFunction ? { tryFunction: (task, params) => tryFunction(requireWritableSpaceId(), task, params, write) } : {},
101
101
  ...runE2eTests ? { runE2eTests: (ids) => runE2eTests(requireTestableSpaceId(), ids) } : {},
102
+ ...getRenderCredential ? { renderCredential: () => getRenderCredential(requireSpaceId()) } : {},
102
103
  ...getActivity ? { activity: (query) => getActivity(requireSpaceId(), query, {
103
104
  userId: grant?.userId,
104
105
  origin: "mcp"
105
- }, signal) } : {}
106
+ }, signal) } : {},
107
+ ...releases ? { releases: {
108
+ domains: () => releases.domains(requireSpaceId()),
109
+ history: (domain) => releases.history(requireSpaceId(), domain),
110
+ publish: (asked) => releases.publish(requireWritableSpaceId(), asked, write),
111
+ rollback: (asked) => releases.rollback(requireWritableSpaceId(), asked, write)
112
+ } } : {}
106
113
  });
107
114
  const spacelessContext = (tool) => ({
108
115
  space: emptySpace(),
@@ -1,11 +1,11 @@
1
1
  import { defineTool } from "./shared/tool.js";
2
2
  import { z } from "zod";
3
- import { ACTIVITY_LIMIT_MAX, ACTIVITY_WAIT_DEFAULT_SECONDS, ACTIVITY_WAIT_MAX_SECONDS } from "@plitzi/sdk-shared/activity";
3
+ import { ACTIVITY_LIMIT_DEFAULT, ACTIVITY_LIMIT_MAX, ACTIVITY_WAIT_DEFAULT_SECONDS, ACTIVITY_WAIT_MAX_SECONDS } from "@plitzi/sdk-shared/activity";
4
4
  // src/modules/mcp/tools/activity.ts
5
5
  var activityShape = {
6
6
  after: z.string().optional().describe("The `cursor` last answered. Left out: the latest, at once"),
7
7
  wait: z.number().min(0).max(ACTIVITY_WAIT_MAX_SECONDS).optional().describe(`Seconds to wait for something; default ${String(ACTIVITY_WAIT_DEFAULT_SECONDS)}`),
8
- limit: z.number().int().min(1).max(ACTIVITY_LIMIT_MAX).optional(),
8
+ limit: z.number().int().min(1).max(ACTIVITY_LIMIT_MAX).optional().describe(`At most this many; default ${String(ACTIVITY_LIMIT_DEFAULT)}`),
9
9
  mine: z.boolean().optional().describe("Include your own writes")
10
10
  };
11
11
  /**
@@ -14,6 +14,7 @@ import { patchBinding } from "../operations/schema/bindings/patchBinding.js";
14
14
  import { upsertBinding } from "../operations/schema/bindings/upsertBinding.js";
15
15
  import { deleteComponent } from "../operations/schema/components/deleteComponent.js";
16
16
  import { upsertComponent } from "../operations/schema/components/upsertComponent.js";
17
+ import { addSpec } from "../operations/schema/elements/addSpec.js";
17
18
  import { deleteElement } from "../operations/schema/elements/deleteElement.js";
18
19
  import { moveElement } from "../operations/schema/elements/moveElement.js";
19
20
  import { patchElement } from "../operations/schema/elements/patchElement.js";
@@ -73,6 +74,7 @@ var executeOp = (space, env, op) => {
73
74
  case "patchElement": return patchElement(space, env, op);
74
75
  case "deleteElement": return deleteElement(space, env, op);
75
76
  case "moveElement": return moveElement(space, env, op);
77
+ case "addSpec": return addSpec(space, env, op);
76
78
  case "upsertPage": return upsertPage(space, env, op);
77
79
  case "deletePage": return deletePage(space, env, op);
78
80
  case "upsertLayout": return upsertLayout(space, env, op);
@@ -116,7 +118,7 @@ var executeOp = (space, env, op) => {
116
118
  case "deleteFunctionFile": return deleteFunctionFile(space, env, op);
117
119
  case "upsertDataFile": return upsertDataFile(space, env, op);
118
120
  case "deleteDataFile": return deleteDataFile(space, env, op);
119
- default: return fail("type", `Unknown operation "${op.type}"`, "See the Operation union");
121
+ default: return fail("missing", "type", `Unknown operation "${op.type}"`, "plitzi_describe_operation lists every operation type");
120
122
  }
121
123
  };
122
124
  /** Apply operations in order to the space (mutating it). Records which schema(s) changed so the caller can
@@ -181,6 +183,10 @@ var applyOperations = (space, env, ops) => {
181
183
  case "deleteDataFile":
182
184
  outcome.changedData = true;
183
185
  break;
186
+ case "addSpec":
187
+ outcome.changedSchema = true;
188
+ if (Object.keys(op.classes ?? {}).length > 0) outcome.changedStyle = true;
189
+ break;
184
190
  default: if (isStyleOp(op.type)) outcome.changedStyle = true;
185
191
  else outcome.changedSchema = true;
186
192
  }
@@ -72,6 +72,18 @@ export declare const applyShape: {
72
72
  after: "after";
73
73
  inside: "inside";
74
74
  }>;
75
+ }, z.core.$strict>, z.ZodObject<{
76
+ type: z.ZodLiteral<"addSpec">;
77
+ pageRef: z.ZodString;
78
+ parentRef: z.ZodOptional<z.ZodString>;
79
+ position: z.ZodOptional<z.ZodEnum<{
80
+ before: "before";
81
+ after: "after";
82
+ inside: "inside";
83
+ }>>;
84
+ replaces: z.ZodOptional<z.ZodString>;
85
+ spec: z.ZodRecord<z.ZodString, z.ZodUnknown>;
86
+ classes: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodRecord<z.ZodString, z.ZodUnknown>>>;
75
87
  }, z.core.$strict>, z.ZodObject<{
76
88
  type: z.ZodLiteral<"upsertPage">;
77
89
  ref: z.ZodString;
@@ -87,6 +99,10 @@ export declare const applyShape: {
87
99
  noBounce: "noBounce";
88
100
  }>>>;
89
101
  flag: z.ZodOptional<z.ZodNullable<z.ZodString>>;
102
+ style: z.ZodOptional<z.ZodObject<{
103
+ base: z.ZodOptional<z.ZodArray<z.ZodString>>;
104
+ slots: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodArray<z.ZodString>>>;
105
+ }, z.core.$strip>>;
90
106
  }, z.core.$strict>, z.ZodObject<{
91
107
  type: z.ZodLiteral<"deletePage">;
92
108
  ref: z.ZodString;
@@ -289,9 +305,16 @@ export declare const applyShape: {
289
305
  dark: z.ZodOptional<z.ZodString>;
290
306
  }, z.core.$strip>]>>;
291
307
  robotsTxt: z.ZodOptional<z.ZodString>;
292
- blockAiCrawlers: z.ZodOptional<z.ZodBoolean>;
308
+ securityTxt: z.ZodOptional<z.ZodString>;
309
+ llmsTxt: z.ZodOptional<z.ZodString>;
310
+ blockAiCrawlers: z.ZodOptional<z.ZodArray<z.ZodEnum<{
311
+ training: "training";
312
+ assistants: "assistants";
313
+ search: "search";
314
+ }>>>;
293
315
  viewTransitions: z.ZodOptional<z.ZodBoolean>;
294
316
  withheldPage: z.ZodOptional<z.ZodString>;
317
+ wholeDocument: z.ZodOptional<z.ZodBoolean>;
295
318
  channels: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodNullable<z.ZodObject<{
296
319
  access: z.ZodObject<{
297
320
  mode: z.ZodEnum<{
@@ -1736,6 +1759,7 @@ export declare const applyShape: {
1736
1759
  both: "both";
1737
1760
  }>>;
1738
1761
  pageRef: z.ZodOptional<z.ZodString>;
1762
+ routeParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
1739
1763
  viewport: z.ZodOptional<z.ZodEnum<{
1740
1764
  desktop: "desktop";
1741
1765
  mobile: "mobile";
@@ -3,10 +3,11 @@ import { dataFileUri, dataUri, functionFileUri, functionsUri } from "../../helpe
3
3
  import { environment, operations } from "../operations/index.js";
4
4
  import { draftBatch } from "../shared/draftBatch.js";
5
5
  import { effectsOf } from "../shared/effects.js";
6
- import { fullPage, lookAt, pageRef, viewport } from "../shared/look.js";
6
+ import { fullPage, lookAt, pageRef, routeParams, viewport } from "../shared/look.js";
7
7
  import { AGAIN, REPEATED, batchKey, forgetRefused, noteRefused, timesRefused } from "../shared/repeats.js";
8
8
  import { defineTool, imageResult } from "../shared/tool.js";
9
9
  import { z } from "zod";
10
+ import { deepEqual } from "@plitzi/sdk-shared/helpers";
10
11
  import { generateCache } from "@plitzi/sdk-style";
11
12
  // src/modules/mcp/tools/apply/index.ts
12
13
  var applyShape = {
@@ -21,26 +22,38 @@ var applyShape = {
21
22
  "both"
22
23
  ]).optional().describe("Also render the page: with dryRun, as the batch would leave it (nothing saved); without, as it was saved. \"html\" the markup, \"image\" a PNG, \"accessibility\" the outline a screen reader reads (text, far cheaper than an image), \"both\" image and outline. Check, look and then save with the same operations — written once."),
23
24
  pageRef,
25
+ routeParams,
24
26
  viewport,
25
27
  fullPage
26
28
  };
27
29
  var NOTHING_CHANGED = "Nothing changed: every operation left the space as it was.";
28
30
  var noWarnings = (warnings) => warnings.length > 0 ? warnings : void 0;
31
+ /**
32
+ * Whether the batch left a store as the space holds it. A write sent again — a client that timed out and retried, an
33
+ * agent that lost the answer — reads the space as the first left it, and its operations change nothing: written again,
34
+ * it would be a second entry in the space's history for an edit nobody made. Strict the other way: any difference, an
35
+ * `undefined` beside a missing key included, is written.
36
+ */
37
+ var unchanged = (before, after, skip) => deepEqual(before, after, "soft", { skip });
29
38
  /** Why the platform did not save the functions, as the batch's errors: each problem where it is, or the refusal. */
30
39
  var functionsErrors = (saved, env) => "problems" in saved ? saved.problems.map((problem) => ({
40
+ code: "bad-value",
31
41
  path: problem.file ? `functions/${problem.file}${problem.line ? `:${String(problem.line)}` : ""}` : "functions",
32
42
  message: problem.message,
33
43
  hint: `Fix it with upsertFunctionFile; read ${functionFileUri(env, problem.file ?? "index.ts")} for the file`
34
44
  })) : [{
45
+ code: "changed-since",
35
46
  path: "functions",
36
47
  message: saved.refusal.error,
37
48
  hint: `Read ${functionsUri(env)} again and redo the change on the current files`
38
49
  }];
39
50
  var dataErrors = (saved, env) => "problems" in saved ? saved.problems.map((problem) => ({
51
+ code: "bad-value",
40
52
  path: `data/${problem.file}`,
41
53
  message: problem.message,
42
54
  hint: `Fix it with upsertDataFile, or deleteDataFile; read ${dataFileUri(env, problem.file)} for the file`
43
55
  })) : [{
56
+ code: "changed-since",
44
57
  path: "data",
45
58
  message: saved.refusal.error,
46
59
  hint: `Read ${dataUri(env)} again and redo the change on the current files`
@@ -93,7 +106,7 @@ var apply = async (input, space, persisters) => {
93
106
  suggestions: noWarnings(suggestions)
94
107
  };
95
108
  const unsaved = [];
96
- if (outcome.changedFunctions && draft.functions) {
109
+ if (outcome.changedFunctions && draft.functions && !unchanged(space.functions?.files, draft.functions.files)) {
97
110
  if (persisters?.saveFunctions) {
98
111
  const saved = await persisters.saveFunctions(draft.functions.files, space.functions?.version ?? "");
99
112
  if (!saved.ok) return {
@@ -110,7 +123,7 @@ var apply = async (input, space, persisters) => {
110
123
  };
111
124
  } else unsaved.push("the functions");
112
125
  }
113
- if (outcome.changedData && draft.data) {
126
+ if (outcome.changedData && draft.data && !unchanged(space.data?.files, draft.data.files)) {
114
127
  if (persisters?.saveData) {
115
128
  const saved = await persisters.saveData(draft.data.files, space.data?.version ?? "");
116
129
  if (!saved.ok) return {
@@ -127,11 +140,11 @@ var apply = async (input, space, persisters) => {
127
140
  };
128
141
  } else unsaved.push("the data");
129
142
  }
130
- if (outcome.changedSchema) {
143
+ if (outcome.changedSchema && !unchanged(space.schema, draft.schema)) {
131
144
  if (persisters?.schema) await persisters.schema(draft.schema);
132
145
  else unsaved.push("the schema");
133
146
  }
134
- if (outcome.changedStyle) {
147
+ if (outcome.changedStyle && !unchanged(space.style, draft.style, ["cache"])) {
135
148
  if (persisters?.style) {
136
149
  draft.style.cache = generateCache(draft.style);
137
150
  await persisters.style(draft.style);
@@ -139,6 +152,7 @@ var apply = async (input, space, persisters) => {
139
152
  }
140
153
  for (const id of outcome.changedConnectors) {
141
154
  const entry = draft.connectors.find((item) => item.id === id);
155
+ if (entry && unchanged(space.connectors.find((item) => item.id === id), entry)) continue;
142
156
  if (entry && persisters?.saveConnector) await persisters.saveConnector(entry);
143
157
  else unsaved.push(`connector ${id}`);
144
158
  }
@@ -146,6 +160,7 @@ var apply = async (input, space, persisters) => {
146
160
  else unsaved.push(`the removal of connector ${id}`);
147
161
  for (const id of outcome.changedActions) {
148
162
  const entry = draft.actions.find((item) => item.id === id);
163
+ if (entry && unchanged(space.actions.find((item) => item.id === id), entry)) continue;
149
164
  if (entry && persisters?.saveAction) await persisters.saveAction(entry);
150
165
  else unsaved.push(`action ${id}`);
151
166
  }
@@ -192,6 +207,7 @@ var applyTool = defineTool({
192
207
  if (!input.look || !result.applied && !result.dryRun) return result;
193
208
  const look = await lookAt(ctx, {
194
209
  pageRef: input.pageRef,
210
+ routeParams: input.routeParams,
195
211
  operations: result.dryRun ? input.operations : void 0,
196
212
  view: input.look,
197
213
  viewport: input.viewport,
@@ -16,7 +16,7 @@ var describeOperation = (type) => {
16
16
  if (!schema) {
17
17
  const nearest = closest(type, types);
18
18
  return {
19
- error: "UNKNOWN_OPERATION",
19
+ error: "missing",
20
20
  message: `There is no "${type}" operation${nearest ? ` — did you mean "${nearest}"?` : ""}`,
21
21
  ...nearest ? { describe: { type: nearest } } : {},
22
22
  types
@@ -6,6 +6,7 @@ import { describeOperationTool } from "./describeOperation.js";
6
6
  import { addPageTool, bindAttributeTool, placeComponentTool, setAttributesTool, setClassesTool } from "./intents.js";
7
7
  import { lookTool } from "./look.js";
8
8
  import { read, readShape, readTool } from "./read.js";
9
+ import { publishTool, releasesTool, rollbackTool } from "./releases.js";
9
10
  import { renderTool } from "./render.js";
10
11
  import { search, searchShape, searchTool } from "./search.js";
11
12
  import { testTool } from "./test.js";
@@ -27,6 +28,9 @@ var tools = [
27
28
  lookTool,
28
29
  tryFunctionTool,
29
30
  testTool,
30
- activityTool
31
+ activityTool,
32
+ releasesTool,
33
+ publishTool,
34
+ rollbackTool
31
35
  ];
32
36
  export { apply, applyShape, operation, read, readShape, search, searchShape, tools };
@@ -1,5 +1,5 @@
1
1
  import { apply } from "./apply/index.js";
2
- import { findElementByRef } from "../helpers/space.js";
2
+ import { findElementByRef, findLayoutByRef, findRootByRef } from "../helpers/space.js";
3
3
  import { scalar } from "./operations/schema/shared.js";
4
4
  import { defineTool } from "./shared/tool.js";
5
5
  import { closest } from "@plitzi/sdk-authoring";
@@ -13,10 +13,24 @@ var locate = (ctx, ref) => {
13
13
  root: element.definition.rootId,
14
14
  classes: element.definition.styleSelectors.base.split(/\s+/).filter(Boolean)
15
15
  };
16
- const nearest = closest(ref, Object.keys(ctx.space.schema.flat));
16
+ if (findRootByRef(ctx.space.schema, ref)) {
17
+ const kind = findLayoutByRef(ctx.space.schema, ref) ? "layout" : "page";
18
+ return {
19
+ done: false,
20
+ errors: [{
21
+ code: "bad-value",
22
+ path: "ref",
23
+ message: `"${ref}" is a ${kind}, not an element on one: this tool edits the elements inside it`,
24
+ hint: kind === "page" ? `plitzi://schema/{env}/pages/${ref} lists them by ref; plitzi_apply upsertPage { ref: "${ref}", style: { base: [...] } } gives the page its own classes` : `plitzi://schema/{env}/pages/${ref} lists them by ref; plitzi_apply upsertLayout edits the layout itself`
25
+ }]
26
+ };
27
+ }
28
+ const elements = Object.keys(ctx.space.schema.flat).filter((id) => findElementByRef(ctx.space.schema, id));
29
+ const nearest = closest(ref, elements);
17
30
  return {
18
31
  done: false,
19
32
  errors: [{
33
+ code: "missing",
20
34
  path: "ref",
21
35
  message: `There is no element "${ref}"${nearest ? ` — did you mean "${nearest}"?` : ""}`,
22
36
  hint: "plitzi_search finds an element by its words, type or class"
@@ -37,7 +51,12 @@ var run = async (ctx, operations, page, notes = []) => {
37
51
  const warnings = [...notes, ...result.warnings ?? []];
38
52
  if (!result.applied) return {
39
53
  done: false,
40
- errors: result.errors ?? (result.conflict ? [result.conflict] : []),
54
+ errors: result.errors ?? (result.conflict ? [{
55
+ code: "changed-since",
56
+ path: "space",
57
+ message: result.conflict.message,
58
+ hint: "Someone changed it meanwhile: read it again and make the change on what it holds now"
59
+ }] : []),
41
60
  ...warnings.length > 0 ? { warnings } : {}
42
61
  };
43
62
  return {
@@ -68,6 +87,7 @@ var setAttributesTool = defineTool({
68
87
  if (covered.length > 0) return {
69
88
  done: false,
70
89
  errors: covered.map((key) => ({
90
+ code: "not-allowed",
71
91
  path: key,
72
92
  message: `${key} of ${input.ref} is bound to ${String(bound.get(key))}: the page shows what the binding computes, not a value written here`,
73
93
  hint: "plitzi_bind_attribute changes what it reads; to write a value instead, plitzi_apply deleteBinding first"
@@ -106,8 +126,10 @@ var setClassesTool = defineTool({
106
126
  errors: absent.map((name) => {
107
127
  const nearest = closest(name, at.classes);
108
128
  return {
129
+ code: "missing",
109
130
  path: "remove",
110
- message: `${input.ref} does not wear "${name}"${nearest ? ` — did you mean "${nearest}"?` : ""}; it wears ${at.classes.join(", ") || "no class"}`
131
+ message: `${input.ref} does not wear "${name}"${nearest ? ` — did you mean "${nearest}"?` : ""}; it wears ${at.classes.join(", ") || "no class"}`,
132
+ hint: "Take off a class it wears, as plitzi_read shows it"
111
133
  };
112
134
  })
113
135
  };
@@ -1,6 +1,7 @@
1
1
  import { z } from 'zod';
2
2
  export declare const lookShape: {
3
3
  pageRef: z.ZodOptional<z.ZodString>;
4
+ routeParams: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
4
5
  view: z.ZodOptional<z.ZodEnum<{
5
6
  image: "image";
6
7
  accessibility: "accessibility";
@@ -1,9 +1,10 @@
1
- import { fullPage, lookAt, pageRef, viewport } from "./shared/look.js";
1
+ import { fullPage, lookAt, pageRef, routeParams, viewport } from "./shared/look.js";
2
2
  import { defineTool, imageResult } from "./shared/tool.js";
3
3
  import { z } from "zod";
4
4
  // src/modules/mcp/tools/look.ts
5
5
  var lookShape = {
6
6
  pageRef,
7
+ routeParams,
7
8
  view: z.enum([
8
9
  "accessibility",
9
10
  "html",
@@ -8,7 +8,7 @@ var deleteActionOp = z.object({
8
8
  ref: z.string().describe("Identifier of the action to remove")
9
9
  }).describe("Remove a server action. Destructive and not undoable: every step that runs it stops working, on published pages included, and a webhook pointing at it starts failing. Confirm with the user first.");
10
10
  var deleteAction = (space, env, op) => {
11
- if (!findActionEntry(space, op.ref)) return fail("ref", `Action "${op.ref}" does not exist`, `Read ${actionsUri(env)} for the actions this space has`, space.actions.map((item) => item.id));
11
+ if (!findActionEntry(space, op.ref)) return fail("missing", "ref", `Action "${op.ref}" does not exist`, `Read ${actionsUri(env)} for the actions this space has`, space.actions.map((item) => item.id));
12
12
  space.actions = space.actions.filter((item) => item.id !== op.ref);
13
13
  return {
14
14
  ...empty(),
@@ -25,12 +25,12 @@ var mergeMap = (current, patch) => {
25
25
  };
26
26
  var patchAction = (space, env, op) => {
27
27
  const entry = findActionEntry(space, op.ref);
28
- if (!entry) return fail("ref", `Action "${op.ref}" does not exist`, `Create it with upsertAction, or read ${actionsUri(env)} for the actions this space has`, space.actions.map((item) => item.id));
28
+ if (!entry) return fail("missing", "ref", `Action "${op.ref}" does not exist`, `Create it with upsertAction, or read ${actionsUri(env)} for the actions this space has`, space.actions.map((item) => item.id));
29
29
  const { document } = entry;
30
30
  const nodes = { ...document.nodes };
31
31
  for (const node of op.nodes ?? []) {
32
32
  if (node.remove) {
33
- delete nodes[node.id];
33
+ Reflect.deleteProperty(nodes, node.id);
34
34
  continue;
35
35
  }
36
36
  const previous = nodes[node.id];
@@ -59,7 +59,7 @@ var patchAction = (space, env, op) => {
59
59
  nodes
60
60
  };
61
61
  const report = validateActionDocument(patched);
62
- if (!report.valid) return fail("nodes", `Invalid action: ${report.errors.map((issue) => issue.message).join("; ")}`, "", []);
62
+ if (!report.valid) return fail("bad-value", "nodes", `Invalid action: ${report.errors.map((issue) => issue.message).join("; ")}`, "Fix each step the message names: plitzi_describe_operation { type: \"patchAction\" } shows the fields a step takes", []);
63
63
  entry.document = patched;
64
64
  return {
65
65
  ...empty(),
@@ -58,7 +58,7 @@ var toDocument = (op) => ({
58
58
  var upsertAction = (space, env, op) => {
59
59
  const document = toDocument(op);
60
60
  const report = validateActionDocument(document);
61
- if (!report.valid) return fail("nodes", `Invalid action: ${report.errors.map((issue) => issue.message).join("; ")}`, "", []);
61
+ if (!report.valid) return fail("bad-value", "nodes", `Invalid action: ${report.errors.map((issue) => issue.message).join("; ")}`, "Fix each step the message names: plitzi_describe_operation { type: \"upsertAction\" } shows the fields a step takes", []);
62
62
  const existing = findActionEntry(space, op.ref);
63
63
  const stale = [actionsUri(env), actionUri(env, op.ref)];
64
64
  if (existing) {
@@ -8,7 +8,7 @@ var deleteConnectorOp = z.object({
8
8
  ref: z.string().describe("Identifier of the connector to remove")
9
9
  }).describe("Remove a connector. Destructive and not undoable: every provider element pointing at it stops resolving and its page renders empty. Confirm with the user first.");
10
10
  var deleteConnector = (space, env, op) => {
11
- if (!findConnectorEntry(space, op.ref)) return fail("ref", `Connector "${op.ref}" does not exist`, `Read ${connectorsUri(env)} for the connectors this space has`, space.connectors.map((item) => item.id));
11
+ if (!findConnectorEntry(space, op.ref)) return fail("missing", "ref", `Connector "${op.ref}" does not exist`, `Read ${connectorsUri(env)} for the connectors this space has`, space.connectors.map((item) => item.id));
12
12
  space.connectors = space.connectors.filter((item) => item.id !== op.ref);
13
13
  return {
14
14
  ...empty(),
@@ -28,7 +28,7 @@ var mergeEndpoints = (current, patch) => {
28
28
  };
29
29
  var patchConnector = (space, env, op) => {
30
30
  const entry = findConnectorEntry(space, op.ref);
31
- if (!entry) return fail("ref", `Connector "${op.ref}" does not exist`, `Create it with upsertConnector, or read ${connectorsUri(env)} for the connectors this space has`, space.connectors.map((item) => item.id));
31
+ if (!entry) return fail("missing", "ref", `Connector "${op.ref}" does not exist`, `Create it with upsertConnector, or read ${connectorsUri(env)} for the connectors this space has`, space.connectors.map((item) => item.id));
32
32
  const { manifest } = entry;
33
33
  if (op.name !== void 0) entry.name = op.name;
34
34
  if (op.baseUrl !== void 0) manifest.baseUrl = op.baseUrl;
@@ -43,7 +43,7 @@ var patchConnector = (space, env, op) => {
43
43
  if (connection.projection !== void 0) manifest.projection = connection.projection;
44
44
  const nextRead = mergeEndpoints(manifest.endpoints.read, op.endpoints?.read);
45
45
  const nextWrite = mergeEndpoints(manifest.endpoints.write, op.endpoints?.write);
46
- if (nextRead && Object.keys(nextRead).length === 0) return fail("endpoints.read", `This would leave connector "${op.ref}" with no read endpoint`, "A connector needs at least one read endpoint to feed an element. Delete the connector if that is the intent");
46
+ if (nextRead && Object.keys(nextRead).length === 0) return fail("bad-value", "endpoints.read", `This would leave connector "${op.ref}" with no read endpoint`, "A connector needs at least one read endpoint to feed an element. Delete the connector if that is the intent");
47
47
  manifest.endpoints = {
48
48
  read: nextRead ?? {},
49
49
  ...nextWrite === void 0 ? {} : { write: nextWrite }