@plitzi/sdk-server 0.32.5 → 0.32.7

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 (175) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/core/services/mcp.js +1 -1
  3. package/dist/helpers/buildServerInfo.js +3 -9
  4. package/dist/index.js +2 -1
  5. package/dist/modules/ai/toolkit.js +1 -0
  6. package/dist/modules/mcp/catalogs/builtinCallbacks.js +204 -0
  7. package/dist/modules/mcp/catalogs/builtinComponents.js +170 -0
  8. package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +50 -0
  9. package/dist/modules/mcp/catalogs/builtinTransformers.js +148 -0
  10. package/dist/modules/mcp/catalogs/builtinUtilities.js +90 -0
  11. package/dist/modules/mcp/{tools/operations/style → catalogs}/cssCatalog.js +75 -2
  12. package/dist/modules/mcp/catalogs/observed.js +90 -0
  13. package/dist/modules/mcp/catalogs/paramSpec.js +69 -0
  14. package/dist/modules/mcp/catalogs/registry.js +89 -0
  15. package/dist/modules/mcp/handler.js +41 -13
  16. package/dist/modules/mcp/helpers/agentPrompt.js +104 -0
  17. package/dist/modules/mcp/helpers/guide.js +334 -15
  18. package/dist/modules/mcp/helpers/interactions.js +123 -0
  19. package/dist/modules/mcp/helpers/log.js +54 -0
  20. package/dist/modules/mcp/helpers/space.js +184 -33
  21. package/dist/modules/mcp/helpers/uris.js +44 -0
  22. package/dist/modules/mcp/resources/canonical.js +6 -21
  23. package/dist/modules/mcp/resources/core.js +4 -3
  24. package/dist/modules/mcp/resources/primer.js +13 -8
  25. package/dist/modules/mcp/resources/register.js +37 -5
  26. package/dist/modules/mcp/resources/schema.js +30 -20
  27. package/dist/modules/mcp/resources/style.js +18 -11
  28. package/dist/modules/mcp/server.js +29 -8
  29. package/dist/modules/mcp/tools/apply/dispatch.js +38 -18
  30. package/dist/modules/mcp/tools/apply/index.js +19 -4
  31. package/dist/modules/mcp/tools/apply/writeResult.js +2 -1
  32. package/dist/modules/mcp/tools/index.js +3 -1
  33. package/dist/modules/mcp/tools/operations/index.js +13 -2
  34. package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +32 -0
  35. package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +36 -0
  36. package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +47 -0
  37. package/dist/modules/mcp/tools/operations/schema/{deleteElement.js → elements/deleteElement.js} +10 -6
  38. package/dist/modules/mcp/tools/operations/schema/{moveElement.js → elements/moveElement.js} +8 -6
  39. package/dist/modules/mcp/tools/operations/schema/{patchElement.js → elements/patchElement.js} +19 -7
  40. package/dist/modules/mcp/tools/operations/schema/{upsertElement.js → elements/upsertElement.js} +11 -5
  41. package/dist/modules/mcp/tools/operations/schema/{deleteFolder.js → folders/deleteFolder.js} +4 -4
  42. package/dist/modules/mcp/tools/operations/schema/{upsertFolder.js → folders/upsertFolder.js} +4 -4
  43. package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +52 -0
  44. package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +47 -0
  45. package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +43 -0
  46. package/dist/modules/mcp/tools/operations/schema/operations.js +25 -11
  47. package/dist/modules/mcp/tools/operations/schema/{deletePage.js → pages/deletePage.js} +8 -5
  48. package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +75 -0
  49. package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +45 -0
  50. package/dist/modules/mcp/tools/operations/schema/shared.js +94 -2
  51. package/dist/modules/mcp/tools/operations/schema/translator.js +77 -10
  52. package/dist/modules/mcp/tools/operations/schema/{deleteVariable.js → variables/deleteVariable.js} +3 -3
  53. package/dist/modules/mcp/tools/operations/schema/{upsertVariable.js → variables/upsertVariable.js} +4 -4
  54. package/dist/modules/mcp/tools/operations/schema/write.js +78 -13
  55. package/dist/modules/mcp/tools/operations/style/{deleteDefinition.js → definitions/deleteDefinition.js} +4 -3
  56. package/dist/modules/mcp/tools/operations/style/{patchDefinition.js → definitions/patchDefinition.js} +6 -5
  57. package/dist/modules/mcp/tools/operations/style/{upsertDefinition.js → definitions/upsertDefinition.js} +5 -4
  58. package/dist/modules/mcp/tools/operations/style/{deleteGlobalStyle.js → globalStyles/deleteGlobalStyle.js} +4 -3
  59. package/dist/modules/mcp/tools/operations/style/{patchGlobalStyle.js → globalStyles/patchGlobalStyle.js} +6 -5
  60. package/dist/modules/mcp/tools/operations/style/{upsertGlobalStyle.js → globalStyles/upsertGlobalStyle.js} +5 -4
  61. package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +21 -0
  62. package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +28 -0
  63. package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.js +24 -0
  64. package/dist/modules/mcp/tools/operations/style/operations.js +14 -8
  65. package/dist/modules/mcp/tools/operations/style/translator.js +25 -1
  66. package/dist/modules/mcp/tools/operations/style/{deleteStyleVariable.js → variables/deleteStyleVariable.js} +4 -4
  67. package/dist/modules/mcp/tools/operations/style/{upsertStyleVariable.js → variables/upsertStyleVariable.js} +4 -4
  68. package/dist/modules/mcp/tools/operations/style/write.js +19 -11
  69. package/dist/modules/mcp/tools/read.js +1 -1
  70. package/dist/modules/mcp/tools/render.js +114 -0
  71. package/dist/modules/mcp/tools/search.js +34 -27
  72. package/dist/modules/mcp/tools/shared/tool.js +1 -0
  73. package/dist/modules/mcp/tools/shared/validator/audit.js +124 -0
  74. package/dist/modules/mcp/tools/shared/validator/batch.js +30 -0
  75. package/dist/modules/mcp/tools/shared/validator/bindings.js +70 -0
  76. package/dist/modules/mcp/tools/shared/validator/context.js +35 -0
  77. package/dist/modules/mcp/tools/shared/validator/css.js +47 -0
  78. package/dist/modules/mcp/tools/shared/validator/elements.js +55 -0
  79. package/dist/modules/mcp/tools/shared/validator/index.js +226 -0
  80. package/dist/modules/mcp/tools/shared/validator/interactions.js +106 -0
  81. package/dist/modules/mcp/tools/shared/validator/refs.js +28 -0
  82. package/dist/modules/mcp/tools/validate.js +23 -3
  83. package/dist/modules/ssr/preview.js +1 -1
  84. package/dist/modules/ssr/views/template.ejs +2 -0
  85. package/dist/src/index.d.ts +1 -1
  86. package/dist/src/modules/mcp/catalogs/builtinCallbacks.d.ts +23 -0
  87. package/dist/src/modules/mcp/catalogs/builtinComponents.d.ts +4 -0
  88. package/dist/src/modules/mcp/catalogs/builtinElementCallbacks.d.ts +20 -0
  89. package/dist/src/modules/mcp/catalogs/builtinTransformers.d.ts +28 -0
  90. package/dist/src/modules/mcp/catalogs/builtinTransformers.test.d.ts +1 -0
  91. package/dist/src/modules/mcp/catalogs/builtinUtilities.d.ts +18 -0
  92. package/dist/src/modules/mcp/{tools/operations/style → catalogs}/cssCatalog.d.ts +5 -1
  93. package/dist/src/modules/mcp/catalogs/index.d.ts +9 -0
  94. package/dist/src/modules/mcp/catalogs/observed.d.ts +48 -0
  95. package/dist/src/modules/mcp/catalogs/paramSpec.d.ts +42 -0
  96. package/dist/src/modules/mcp/catalogs/registry.d.ts +35 -0
  97. package/dist/src/modules/mcp/handler.d.ts +2 -2
  98. package/dist/src/modules/mcp/helpers/agentPrompt.d.ts +4 -0
  99. package/dist/src/modules/mcp/helpers/guide.d.ts +2 -1
  100. package/dist/src/modules/mcp/helpers/index.d.ts +4 -0
  101. package/dist/src/modules/mcp/helpers/interactions.d.ts +30 -0
  102. package/dist/src/modules/mcp/helpers/log.d.ts +8 -0
  103. package/dist/src/modules/mcp/helpers/log.test.d.ts +1 -0
  104. package/dist/src/modules/mcp/helpers/space.d.ts +68 -11
  105. package/dist/src/modules/mcp/helpers/uris.d.ts +28 -0
  106. package/dist/src/modules/mcp/index.d.ts +1 -1
  107. package/dist/src/modules/mcp/mcp.bench.d.ts +1 -0
  108. package/dist/src/modules/mcp/resources/canonical.d.ts +0 -1
  109. package/dist/src/modules/mcp/resources/index.d.ts +2 -3
  110. package/dist/src/modules/mcp/resources/primer.d.ts +2 -1
  111. package/dist/src/modules/mcp/resources/register.d.ts +2 -2
  112. package/dist/src/modules/mcp/server.d.ts +5 -2
  113. package/dist/src/modules/mcp/tools/apply/index.d.ts +191 -2
  114. package/dist/src/modules/mcp/tools/index.d.ts +1 -0
  115. package/dist/src/modules/mcp/tools/operations/index.d.ts +383 -4
  116. package/dist/src/modules/mcp/tools/operations/schema/bindings/deleteBinding.d.ts +17 -0
  117. package/dist/src/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +25 -0
  118. package/dist/src/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +27 -0
  119. package/dist/src/modules/mcp/tools/operations/schema/{deleteElement.d.ts → elements/deleteElement.d.ts} +2 -2
  120. package/dist/src/modules/mcp/tools/operations/schema/{moveElement.d.ts → elements/moveElement.d.ts} +2 -2
  121. package/dist/src/modules/mcp/tools/operations/schema/{patchElement.d.ts → elements/patchElement.d.ts} +7 -2
  122. package/dist/src/modules/mcp/tools/operations/schema/{upsertElement.d.ts → elements/upsertElement.d.ts} +3 -3
  123. package/dist/src/modules/mcp/tools/operations/schema/{deleteFolder.d.ts → folders/deleteFolder.d.ts} +2 -2
  124. package/dist/src/modules/mcp/tools/operations/schema/{upsertFolder.d.ts → folders/upsertFolder.d.ts} +2 -2
  125. package/dist/src/modules/mcp/tools/operations/schema/index.d.ts +17 -11
  126. package/dist/src/modules/mcp/tools/operations/schema/interactions/deleteInteraction.d.ts +12 -0
  127. package/dist/src/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +18 -0
  128. package/dist/src/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +27 -0
  129. package/dist/src/modules/mcp/tools/operations/schema/operations.d.ts +131 -0
  130. package/dist/src/modules/mcp/tools/operations/schema/{deletePage.d.ts → pages/deletePage.d.ts} +2 -2
  131. package/dist/src/modules/mcp/tools/operations/schema/{upsertPage.d.ts → pages/upsertPage.d.ts} +3 -2
  132. package/dist/src/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +34 -0
  133. package/dist/src/modules/mcp/tools/operations/schema/shared.d.ts +53 -0
  134. package/dist/src/modules/mcp/tools/operations/schema/translator.d.ts +5 -2
  135. package/dist/src/modules/mcp/tools/operations/schema/{deleteVariable.d.ts → variables/deleteVariable.d.ts} +2 -2
  136. package/dist/src/modules/mcp/tools/operations/schema/{upsertVariable.d.ts → variables/upsertVariable.d.ts} +2 -2
  137. package/dist/src/modules/mcp/tools/operations/schema/write.d.ts +38 -8
  138. package/dist/src/modules/mcp/tools/operations/style/{deleteDefinition.d.ts → definitions/deleteDefinition.d.ts} +2 -2
  139. package/dist/src/modules/mcp/tools/operations/style/{patchDefinition.d.ts → definitions/patchDefinition.d.ts} +2 -2
  140. package/dist/src/modules/mcp/tools/operations/style/{upsertDefinition.d.ts → definitions/upsertDefinition.d.ts} +2 -2
  141. package/dist/src/modules/mcp/tools/operations/style/{deleteGlobalStyle.d.ts → globalStyles/deleteGlobalStyle.d.ts} +2 -2
  142. package/dist/src/modules/mcp/tools/operations/style/{patchGlobalStyle.d.ts → globalStyles/patchGlobalStyle.d.ts} +2 -2
  143. package/dist/src/modules/mcp/tools/operations/style/{upsertGlobalStyle.d.ts → globalStyles/upsertGlobalStyle.d.ts} +2 -2
  144. package/dist/src/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.d.ts +9 -0
  145. package/dist/src/modules/mcp/tools/operations/style/idStyles/patchIdStyle.d.ts +37 -0
  146. package/dist/src/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.d.ts +37 -0
  147. package/dist/src/modules/mcp/tools/operations/style/index.d.ts +11 -9
  148. package/dist/src/modules/mcp/tools/operations/style/operations.d.ts +70 -2
  149. package/dist/src/modules/mcp/tools/operations/style/shared.d.ts +1 -1
  150. package/dist/src/modules/mcp/tools/operations/style/translator.d.ts +4 -1
  151. package/dist/src/modules/mcp/tools/operations/style/{deleteStyleVariable.d.ts → variables/deleteStyleVariable.d.ts} +3 -3
  152. package/dist/src/modules/mcp/tools/operations/style/{upsertStyleVariable.d.ts → variables/upsertStyleVariable.d.ts} +3 -3
  153. package/dist/src/modules/mcp/tools/operations/style/write.d.ts +2 -7
  154. package/dist/src/modules/mcp/tools/preview.d.ts +191 -2
  155. package/dist/src/modules/mcp/tools/render.d.ts +434 -0
  156. package/dist/src/modules/mcp/tools/render.test.d.ts +1 -0
  157. package/dist/src/modules/mcp/tools/screenshot.d.ts +191 -2
  158. package/dist/src/modules/mcp/tools/shared/tool.d.ts +4 -0
  159. package/dist/src/modules/mcp/tools/shared/validator/audit.d.ts +4 -0
  160. package/dist/src/modules/mcp/tools/shared/validator/batch.d.ts +5 -0
  161. package/dist/src/modules/mcp/tools/shared/validator/bindings.d.ts +6 -0
  162. package/dist/src/modules/mcp/tools/shared/validator/context.d.ts +34 -0
  163. package/dist/src/modules/mcp/tools/shared/validator/css.d.ts +4 -0
  164. package/dist/src/modules/mcp/tools/shared/validator/elements.d.ts +6 -0
  165. package/dist/src/modules/mcp/tools/shared/validator/index.d.ts +8 -0
  166. package/dist/src/modules/mcp/tools/shared/validator/interactions.d.ts +3 -0
  167. package/dist/src/modules/mcp/tools/shared/validator/refs.d.ts +4 -0
  168. package/dist/src/modules/mcp/tools/validate.d.ts +191 -2
  169. package/dist/src/modules/mcp/types/aiSchema.d.ts +93 -1
  170. package/package.json +12 -10
  171. package/dist/modules/mcp/tools/operations/schema/registry.js +0 -55
  172. package/dist/modules/mcp/tools/operations/schema/upsertPage.js +0 -64
  173. package/dist/modules/mcp/tools/shared/validator.js +0 -262
  174. package/dist/src/modules/mcp/tools/operations/schema/registry.d.ts +0 -22
  175. package/dist/src/modules/mcp/tools/shared/validator.d.ts +0 -4
@@ -1,20 +1,184 @@
1
1
  //#region src/modules/mcp/helpers/space.ts
2
- var cloneSpace = (space) => structuredClone(space);
2
+ var cloneSpace = (space) => ({
3
+ schema: structuredClone(space.schema),
4
+ style: structuredClone(space.style),
5
+ ...space.catalog ? { catalog: space.catalog } : {}
6
+ });
7
+ var emptySpace = () => ({
8
+ schema: {
9
+ flat: {},
10
+ definition: {
11
+ name: "",
12
+ permanentUrl: ""
13
+ },
14
+ variables: [],
15
+ settings: { customCss: "" },
16
+ pages: [],
17
+ pageFolders: []
18
+ },
19
+ style: {
20
+ platform: {
21
+ desktop: {},
22
+ tablet: {},
23
+ mobile: {}
24
+ },
25
+ theme: {
26
+ default: "system",
27
+ schemes: ["light", "dark"]
28
+ },
29
+ variables: {},
30
+ cache: ""
31
+ }
32
+ });
3
33
  var slugify = (value) => value.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "";
4
- var isPageElement = (schema, el) => schema.pages.includes(el.id) || el.definition.type === "page";
5
- var getPageElements = (schema) => Object.values(schema.flat).filter((el) => isPageElement(schema, el));
6
- /** Stable, human-readable ref for a page. Prefers an agent-chosen aiRef, then slug, then a slugified label. */
34
+ /** A value when it is a string, otherwise undefined for the many attributes typed as `unknown` that are strings
35
+ * in practice (name, slug, subType, dom id…). */
36
+ var strOr = (value) => typeof value === "string" ? value : void 0;
37
+ /** Display name of a page or element: its `name` attribute when set, otherwise its definition label. */
38
+ var nameOf = (el) => strOr(el.attributes.name) ?? el.definition.label;
39
+ /** Stable, human-readable ref for a page: its idRef, then slug, then a slugified label. A page without an idRef is
40
+ * still addressable — unlike a data source, a page ref has meaningful fallbacks the agent can read off the tree. */
7
41
  var pageRefOf = (el) => {
8
- if (el.definition.aiRef) return el.definition.aiRef;
9
- const slug = typeof el.attributes.slug === "string" ? el.attributes.slug.trim() : "";
42
+ if (el.idRef) return el.idRef;
43
+ const slug = strOr(el.attributes.slug)?.trim();
10
44
  if (slug) return slugify(slug);
11
45
  if (el.attributes.default === true) return "home";
12
- return slugify(typeof el.attributes.name === "string" ? el.attributes.name : el.definition.label) || el.id;
46
+ return slugify(nameOf(el)) || el.id;
47
+ };
48
+ /** Stable ref for ADDRESSING a non-page element in the tree: its idRef when present, otherwise the opaque id so an
49
+ * element without one is still reachable — the agent needs to name it to give it an idRef in the first place.
50
+ * This is not the wiring key: the runtime wires interactions and data sources by idRef only, so an element
51
+ * addressed here by its id alone publishes no source and takes no interactions (see `getSourceName`). */
52
+ var elementRefOf = (el) => el.idRef ?? el.id;
53
+ var buildIndex = (schema) => {
54
+ const flat = schema.flat;
55
+ const lookup = (id) => flat[id];
56
+ const pageIds = new Set(schema.pages);
57
+ for (const el of Object.values(flat)) if (el.definition.type === "page") pageIds.add(el.id);
58
+ const pageElements = [];
59
+ const pageByRef = /* @__PURE__ */ new Map();
60
+ const elementByRef = /* @__PURE__ */ new Map();
61
+ for (const el of Object.values(flat)) if (pageIds.has(el.id)) {
62
+ pageElements.push(el);
63
+ const ref = pageRefOf(el);
64
+ if (!pageByRef.has(ref)) pageByRef.set(ref, el);
65
+ if (!pageByRef.has(el.id)) pageByRef.set(el.id, el);
66
+ } else {
67
+ const ref = elementRefOf(el);
68
+ if (!elementByRef.has(ref)) elementByRef.set(ref, el);
69
+ if (!elementByRef.has(el.id)) elementByRef.set(el.id, el);
70
+ }
71
+ const pageOf = /* @__PURE__ */ new Map();
72
+ for (const page of pageElements) {
73
+ pageOf.set(page.id, page.id);
74
+ const stack = [...page.definition.items ?? []];
75
+ while (stack.length > 0) {
76
+ const id = stack.pop();
77
+ if (id === void 0 || pageOf.has(id)) continue;
78
+ const el = lookup(id);
79
+ if (!el) continue;
80
+ pageOf.set(id, page.id);
81
+ for (const childId of el.definition.items ?? []) stack.push(childId);
82
+ }
83
+ }
84
+ return {
85
+ pageIds,
86
+ pageElements,
87
+ pageByRef,
88
+ elementByRef,
89
+ pageOf,
90
+ detailCache: /* @__PURE__ */ new Map()
91
+ };
92
+ };
93
+ var indexCache = /* @__PURE__ */ new WeakMap();
94
+ /** The index for a schema, built once and memoized on the schema object. */
95
+ var spaceIndex = (schema) => {
96
+ let index = indexCache.get(schema);
97
+ if (!index) {
98
+ index = buildIndex(schema);
99
+ indexCache.set(schema, index);
100
+ }
101
+ return index;
102
+ };
103
+ var cachedIndex = (schema) => indexCache.get(schema);
104
+ /** A new non-page element was created under `pageId`. */
105
+ var indexAddElement = (schema, el, pageId) => {
106
+ const index = cachedIndex(schema);
107
+ if (!index) return;
108
+ index.elementByRef.set(el.id, el);
109
+ if (el.idRef) index.elementByRef.set(el.idRef, el);
110
+ index.pageOf.set(el.id, pageId);
111
+ index.detailCache.clear();
112
+ };
113
+ /** These non-page elements were deleted (an element and its descendants). */
114
+ var indexRemoveElements = (schema, els) => {
115
+ const index = cachedIndex(schema);
116
+ if (!index) return;
117
+ for (const el of els) {
118
+ index.elementByRef.delete(el.id);
119
+ if (el.idRef) index.elementByRef.delete(el.idRef);
120
+ index.pageOf.delete(el.id);
121
+ }
122
+ index.detailCache.clear();
13
123
  };
14
- /** Stable ref for a non-page element. An agent-chosen aiRef when present, otherwise the opaque id. */
15
- var elementRefOf = (el) => el.definition.aiRef ?? el.id;
16
- /** Finds a page by its semantic ref (aiRef/slug/…) or its raw id, so legacy schemas without an aiRef still resolve. */
17
- var findPageByRef = (schema, pageRef) => getPageElements(schema).find((el) => pageRefOf(el) === pageRef || el.id === pageRef);
124
+ /** An existing element was just given an idRef (it had none), so it becomes addressable by that ref. */
125
+ var indexReRefElement = (schema, el) => {
126
+ const index = cachedIndex(schema);
127
+ if (!index) return;
128
+ if (el.idRef) index.elementByRef.set(el.idRef, el);
129
+ index.detailCache.clear();
130
+ };
131
+ /** A new page element was created. */
132
+ var indexAddPage = (schema, page) => {
133
+ const index = cachedIndex(schema);
134
+ if (!index) return;
135
+ index.pageIds.add(page.id);
136
+ index.pageElements.push(page);
137
+ index.pageByRef.set(page.id, page);
138
+ index.pageByRef.set(pageRefOf(page), page);
139
+ index.pageOf.set(page.id, page.id);
140
+ index.detailCache.clear();
141
+ };
142
+ /** A page and its `descendants` (its non-page elements) were deleted. */
143
+ var indexRemovePage = (schema, page, descendants) => {
144
+ const index = cachedIndex(schema);
145
+ if (!index) return;
146
+ index.pageIds.delete(page.id);
147
+ const at = index.pageElements.findIndex((p) => p.id === page.id);
148
+ if (at >= 0) index.pageElements.splice(at, 1);
149
+ index.pageByRef.delete(page.id);
150
+ index.pageByRef.delete(pageRefOf(page));
151
+ index.pageOf.delete(page.id);
152
+ for (const el of descendants) {
153
+ index.elementByRef.delete(el.id);
154
+ if (el.idRef) index.elementByRef.delete(el.idRef);
155
+ index.pageOf.delete(el.id);
156
+ }
157
+ index.detailCache.clear();
158
+ };
159
+ /** A page's slug/name/default changed; re-key its pageByRef entry if that changed its ref. `oldRef` is the ref
160
+ * computed BEFORE the attribute change. */
161
+ var indexReRefPage = (schema, page, oldRef) => {
162
+ const index = cachedIndex(schema);
163
+ if (!index) return;
164
+ const newRef = pageRefOf(page);
165
+ if (newRef !== oldRef) {
166
+ index.pageByRef.delete(oldRef);
167
+ index.pageByRef.set(newRef, page);
168
+ index.detailCache.clear();
169
+ }
170
+ };
171
+ /** A move reparented an element within its page: the ref/page maps are unchanged, but the moved element's
172
+ * parentRef and both parents' childRefs did change, so their memoized detail must be dropped. */
173
+ var indexInvalidateDetails = (schema) => {
174
+ cachedIndex(schema)?.detailCache.clear();
175
+ };
176
+ var isPageElement = (schema, el) => spaceIndex(schema).pageIds.has(el.id) || el.definition.type === "page";
177
+ var getPageElements = (schema) => spaceIndex(schema).pageElements;
178
+ /** Finds a page by its semantic ref (idRef/slug/…) or its raw id, so legacy schemas without an idRef still resolve. */
179
+ var findPageByRef = (schema, pageRef) => spaceIndex(schema).pageByRef.get(pageRef);
180
+ /** Find any non-page element by its semantic ref (idRef) or raw id, across the whole space. */
181
+ var findElementByRef = (schema, ref) => spaceIndex(schema).elementByRef.get(ref);
18
182
  var pageFoldersOf = (schema) => {
19
183
  schema.pageFolders ??= [];
20
184
  return schema.pageFolders;
@@ -96,35 +260,22 @@ var descendantIds = (schema, pageRootId) => {
96
260
  return acc;
97
261
  };
98
262
  /** Resolve a ref to a concrete element within a page subtree (or the page root itself). Accepts either the
99
- * semantic ref (aiRef) or the raw element id, so schemas predating aiRef keep working through their ids. */
263
+ * semantic ref (idRef) or the raw element id, so schemas predating idRef keep working through their ids. */
100
264
  var resolveRef = (schema, page, ref) => {
101
265
  if (elementRefOf(page) === ref || pageRefOf(page) === ref || page.id === ref) return page;
102
- for (const id of descendantIds(schema, page.id)) {
103
- const el = elementById(schema, id);
104
- if (el && (elementRefOf(el) === ref || el.id === ref)) return el;
105
- }
266
+ const index = spaceIndex(schema);
267
+ const el = index.elementByRef.get(ref);
268
+ return el && index.pageOf.get(el.id) === page.id ? el : void 0;
106
269
  };
107
270
  /** Ordered children of an element, honoring definition.items and skipping dangling ids. */
108
271
  var orderedChildren = (schema, el) => {
109
272
  return (el.definition.items ?? []).map((id) => schema.flat[id]).filter((child) => Boolean(child));
110
273
  };
111
- /** The page ref an element belongs to, walking up parents. 'unknown' when it has no page ancestor. */
274
+ /** The page ref an element belongs to. 'unknown' when it has no page ancestor. */
112
275
  var pageRefOfElement = (schema, el) => {
113
- let current = el;
114
- const guard = /* @__PURE__ */ new Set();
115
- while (current && !guard.has(current.id)) {
116
- guard.add(current.id);
117
- if (isPageElement(schema, current)) return pageRefOf(current);
118
- current = current.definition.parentId ? schema.flat[current.definition.parentId] : void 0;
119
- }
120
- return "unknown";
121
- };
122
- /** Find any non-page element by its semantic ref (aiRef) or raw id, across the whole space. */
123
- var findElementByRef = (schema, ref) => {
124
- for (const el of Object.values(schema.flat)) {
125
- if (isPageElement(schema, el)) continue;
126
- if (elementRefOf(el) === ref || el.id === ref) return el;
127
- }
276
+ const pageId = spaceIndex(schema).pageOf.get(el.id);
277
+ const page = pageId ? schema.flat[pageId] : void 0;
278
+ return page ? pageRefOf(page) : "unknown";
128
279
  };
129
280
  /** Total number of descendant elements under a subtree (excluding the root). */
130
281
  var descendantCount = (schema, rootId) => descendantIds(schema, rootId).length;
@@ -134,4 +285,4 @@ var generateObjectId = () => {
134
285
  return `${Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0")}${Array.from({ length: 16 }, () => Math.floor(Math.random() * 16).toString(16)).join("")}`;
135
286
  };
136
287
  //#endregion
137
- export { cloneSpace, descendantCount, descendantIds, elementById, elementRefOf, emptySpaceMessage, findElementByRef, findFolderByRef, findPageByRef, folderAncestorIds, generateObjectId, getPageElements, isPageElement, orderedChildren, pageFoldersOf, pageRefOf, pageRefOfElement, resolveRef, routeParamNames, slugRouteParams, slugify, sortFolders, unauthorizedSpaceMessage };
288
+ export { cloneSpace, descendantCount, descendantIds, elementById, elementRefOf, emptySpace, emptySpaceMessage, findElementByRef, findFolderByRef, findPageByRef, folderAncestorIds, generateObjectId, getPageElements, indexAddElement, indexAddPage, indexInvalidateDetails, indexReRefElement, indexReRefPage, indexRemoveElements, indexRemovePage, isPageElement, nameOf, orderedChildren, pageFoldersOf, pageRefOf, pageRefOfElement, resolveRef, routeParamNames, slugRouteParams, slugify, sortFolders, spaceIndex, strOr, unauthorizedSpaceMessage };
@@ -0,0 +1,44 @@
1
+ //#region src/modules/mcp/helpers/uris.ts
2
+ var guideUri = "plitzi://guide";
3
+ var typesUri = "plitzi://types";
4
+ var cssPropertiesUri = "plitzi://css-properties";
5
+ var primerUri = (env) => `plitzi://primer/${env}`;
6
+ var pagesUri = (env) => `plitzi://schema/${env}/pages`;
7
+ var pageUri = (env, ref) => `plitzi://schema/${env}/pages/${ref}`;
8
+ var elementUri = (env, ref) => `plitzi://schema/${env}/elements/${ref}`;
9
+ var schemaVarsUri = (env) => `plitzi://schema-variables/${env}`;
10
+ var settingsUri = (env) => `plitzi://settings/${env}`;
11
+ var interactionsUri = (env) => `plitzi://interactions/${env}`;
12
+ var dataSourcesUri = (env) => `plitzi://data-sources/${env}`;
13
+ var foldersUri = (env) => `plitzi://folders/${env}`;
14
+ var folderUri = (env, ref) => `plitzi://folders/${env}/${ref}`;
15
+ var defsUri = (env) => `plitzi://definitions/${env}`;
16
+ var defUri = (env, ref) => `plitzi://definitions/${env}/${ref}`;
17
+ var globalsUri = (env) => `plitzi://global-styles/${env}`;
18
+ var globalUri = (env, componentType) => `plitzi://global-styles/${env}/${componentType}`;
19
+ var idsUri = (env) => `plitzi://id-styles/${env}`;
20
+ var idUri = (env, targetId) => `plitzi://id-styles/${env}/${targetId}`;
21
+ var styleVarsUri = (env) => `plitzi://style-variables/${env}`;
22
+ var styleVarUri = (env, category) => `plitzi://style-variables/${env}/${category}`;
23
+ var aliasedRoots = [
24
+ "definitions",
25
+ "global-styles",
26
+ "id-styles",
27
+ "style-variables",
28
+ "schema-variables",
29
+ "folders"
30
+ ];
31
+ var itemTemplates = (env) => [
32
+ pageUri(env, "{ref}"),
33
+ elementUri(env, "{ref}"),
34
+ defUri(env, "{ref}"),
35
+ globalUri(env, "{componentType}"),
36
+ idUri(env, "{targetId}"),
37
+ styleVarUri(env, "{category}"),
38
+ folderUri(env, "{ref}")
39
+ ];
40
+ /** The remainder of `uri` after `prefix`, or undefined when it does not start with it — so a resolver matches a
41
+ * family and extracts its ref in one step, without repeating the prefix string for both the startsWith and slice. */
42
+ var afterPrefix = (uri, prefix) => uri.startsWith(prefix) ? uri.slice(prefix.length) : void 0;
43
+ //#endregion
44
+ export { afterPrefix, aliasedRoots, cssPropertiesUri, dataSourcesUri, defUri, defsUri, elementUri, folderUri, foldersUri, globalUri, globalsUri, guideUri, idUri, idsUri, interactionsUri, itemTemplates, pageUri, pagesUri, primerUri, schemaVarsUri, settingsUri, styleVarUri, styleVarsUri, typesUri };
@@ -1,29 +1,14 @@
1
+ import { afterPrefix, aliasedRoots, itemTemplates, primerUri } from "../helpers/uris.js";
1
2
  //#region src/modules/mcp/resources/canonical.ts
2
- var ALIASED_ROOTS = [
3
- "definitions",
4
- "global-styles",
5
- "style-variables",
6
- "schema-variables",
7
- "folders"
8
- ];
9
3
  var canonicalUri = (env, uri) => {
10
- const aliasPrefix = `plitzi://schema/${env}/`;
11
- if (!uri.startsWith(aliasPrefix)) return uri;
12
- const rest = uri.slice(aliasPrefix.length);
13
- for (const root of ALIASED_ROOTS) {
4
+ const rest = afterPrefix(uri, `plitzi://schema/${env}/`);
5
+ if (rest === void 0) return uri;
6
+ for (const root of aliasedRoots) {
14
7
  if (rest === root) return `plitzi://${root}/${env}`;
15
8
  if (rest.startsWith(`${root}/`)) return `plitzi://${root}/${env}/${rest.slice(root.length + 1)}`;
16
9
  }
17
10
  return uri;
18
11
  };
19
- var itemTemplates = (env) => [
20
- `plitzi://schema/${env}/pages/{ref}`,
21
- `plitzi://schema/${env}/elements/{ref}`,
22
- `plitzi://definitions/${env}/{ref}`,
23
- `plitzi://global-styles/${env}/{componentType}`,
24
- `plitzi://style-variables/${env}/{category}`,
25
- `plitzi://folders/${env}/{ref}`
26
- ];
27
12
  /** Teachable message for a URI that read as null. Distinguishes a well-formed URI whose ref does not resolve (the
28
13
  * resource may be stale/deleted) from a URI whose shape matches no template at all (malformed — echo the valid
29
14
  * templates so the agent stops hand-building URIs). See RFC 0004 I2. */
@@ -38,8 +23,8 @@ var resourceErrorMessage = (env, uri) => {
38
23
  error: "MALFORMED_URI",
39
24
  message: `'${uri}' matches no resource template.`,
40
25
  hint: "Do not hand-build element URIs — take the ready-made uri from plitzi_search or a write response.",
41
- validTemplates: [`plitzi://primer/${env}`, ...itemTemplates(env)]
26
+ validTemplates: [primerUri(env), ...itemTemplates(env)]
42
27
  });
43
28
  };
44
29
  //#endregion
45
- export { canonicalUri, itemTemplates, resourceErrorMessage };
30
+ export { canonicalUri, resourceErrorMessage };
@@ -1,13 +1,14 @@
1
+ import { cssProperties } from "../catalogs/cssCatalog.js";
2
+ import { buildTypeRegistry } from "../catalogs/registry.js";
3
+ import "../helpers/uris.js";
1
4
  import { guideText } from "../helpers/guide.js";
2
5
  import { envelope } from "./envelope.js";
3
- import { cssProperties } from "../tools/operations/style/cssCatalog.js";
4
- import { buildTypeRegistry } from "../tools/operations/schema/registry.js";
5
6
  //#region src/modules/mcp/resources/core.ts
6
7
  /** Space-independent singletons: the usage guide, the observed type registry and the CSS property catalog.
7
8
  * Returns undefined when the URI is not one of these, so the router falls through to the next resolver. */
8
9
  var readCoreResource = (space, uri) => {
9
10
  if (uri === "plitzi://guide") return envelope(guideText);
10
- if (uri === "plitzi://types") return envelope(buildTypeRegistry(space.schema));
11
+ if (uri === "plitzi://types") return envelope(buildTypeRegistry(space.schema, space.catalog));
11
12
  if (uri === "plitzi://css-properties") return envelope(cssProperties);
12
13
  };
13
14
  //#endregion
@@ -1,24 +1,29 @@
1
- import { guideText } from "../helpers/guide.js";
1
+ import { cssProperties } from "../catalogs/cssCatalog.js";
2
+ import { buildDataSourceCatalog, buildInteractionCatalog } from "../catalogs/observed.js";
3
+ import { buildTypeRegistry } from "../catalogs/registry.js";
4
+ import { guideQuickstart } from "../helpers/guide.js";
2
5
  import { envelope } from "./envelope.js";
3
- import { cssProperties } from "../tools/operations/style/cssCatalog.js";
4
- import { buildTypeRegistry } from "../tools/operations/schema/registry.js";
5
6
  import { definitionRefs, styleVariablesToAI } from "../tools/operations/style/translator.js";
6
- import { foldersToAI, pageSummariesToAI, schemaVariablesToAI } from "../tools/operations/schema/translator.js";
7
+ import { foldersToAI, pageSummariesToAI, schemaVariablesToAI, settingsToAI } from "../tools/operations/schema/translator.js";
7
8
  //#region src/modules/mcp/resources/primer.ts
8
9
  /** The cold-start bundle: everything the guide says to read before the first write, in one round-trip.
9
10
  * Summaries only — never full page/element trees (those are opened on demand), so it stays cheap even on a
10
- * large space. Returns undefined when the URI is not the primer. */
11
+ * large space. Carries the condensed `guideQuickstart` (not the full guideText, which the agent reads on demand at
12
+ * plitzi://guide) to keep the bundle small. Returns undefined when the URI is not the primer. */
11
13
  var readPrimerResource = (space, env, uri) => {
12
14
  if (uri !== `plitzi://primer/${env}`) return;
13
15
  return envelope({
14
- guide: guideText,
15
- types: buildTypeRegistry(space.schema),
16
+ guide: guideQuickstart,
17
+ types: buildTypeRegistry(space.schema, space.catalog),
16
18
  cssProperties,
17
19
  pages: pageSummariesToAI(space.schema),
18
20
  folders: foldersToAI(space.schema),
19
21
  definitions: definitionRefs(space.style),
20
22
  styleVariables: styleVariablesToAI(space.style),
21
- schemaVariables: schemaVariablesToAI(space.schema, false)
23
+ schemaVariables: schemaVariablesToAI(space.schema, false),
24
+ settings: settingsToAI(space.schema),
25
+ interactions: buildInteractionCatalog(space.schema),
26
+ dataSources: buildDataSourceCatalog(space.schema)
22
27
  });
23
28
  };
24
29
  //#endregion
@@ -1,17 +1,24 @@
1
+ import { cssProperties } from "../catalogs/cssCatalog.js";
1
2
  import { guideText } from "../helpers/guide.js";
2
3
  import { resourceErrorMessage } from "./canonical.js";
3
4
  import { envelope, jsonContents } from "./envelope.js";
4
- import { cssProperties } from "../tools/operations/style/cssCatalog.js";
5
5
  import { readResource } from "./router.js";
6
6
  import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp";
7
7
  //#region src/modules/mcp/resources/register.ts
8
8
  /** Register every resource on the MCP server: fixed listings plus templated per-item reads. The space is
9
9
  * loaded lazily via getSpace, so listing resources never touches the store — only reading one does. */
10
- var registerResources = (server, getSpace, env) => {
10
+ var registerResources = (server, getSpace, env, log) => {
11
11
  const emit = async (uri) => {
12
- const result = readResource(await getSpace(), env, uri);
13
- if (!result) throw new Error(resourceErrorMessage(env, uri));
14
- return jsonContents(uri, result);
12
+ const start = performance.now();
13
+ try {
14
+ const result = readResource(await getSpace(), env, uri);
15
+ if (!result) throw new Error(resourceErrorMessage(env, uri));
16
+ log.resourceRead(uri, performance.now() - start);
17
+ return jsonContents(uri, result);
18
+ } catch (error) {
19
+ log.resourceRead(uri, performance.now() - start, error);
20
+ throw error;
21
+ }
15
22
  };
16
23
  server.registerResource("Guide", "plitzi://guide", {
17
24
  description: "How to read and write this space with mcp-ai",
@@ -56,6 +63,11 @@ var registerResources = (server, getSpace, env) => {
56
63
  `plitzi://global-styles/${env}`,
57
64
  "Element types that have a site-wide global style"
58
65
  ],
66
+ [
67
+ "Id styles",
68
+ `plitzi://id-styles/${env}`,
69
+ "DOM ids that have an id rule (#id) targeting a single element"
70
+ ],
59
71
  [
60
72
  "Style variables",
61
73
  `plitzi://style-variables/${env}`,
@@ -66,6 +78,21 @@ var registerResources = (server, getSpace, env) => {
66
78
  `plitzi://schema-variables/${env}`,
67
79
  "Space-level values referenced via {{name}}"
68
80
  ],
81
+ [
82
+ "Settings",
83
+ `plitzi://settings/${env}`,
84
+ "Space-level settings: global customCss and state/auth configuration"
85
+ ],
86
+ [
87
+ "Interactions catalog",
88
+ `plitzi://interactions/${env}`,
89
+ "Interaction actions (observed, grouped by node type) plus the built-in vocabularies — globalCallbacks (with their source module), element callbacks and utilities — each with its full param schema, the vocabulary for upsertInteractionFlow"
90
+ ],
91
+ [
92
+ "Data sources catalog",
93
+ `plitzi://data-sources/${env}`,
94
+ "Data-source paths and binding targets observed in this space — the vocabulary for upsertBinding"
95
+ ],
69
96
  [
70
97
  "Style definitions (schema alias)",
71
98
  `plitzi://schema/${env}/definitions`,
@@ -117,6 +144,11 @@ var registerResources = (server, getSpace, env) => {
117
144
  `plitzi://global-styles/${env}/{componentType}`,
118
145
  "The site-wide CSS applied to every element of one type"
119
146
  ],
147
+ [
148
+ "Id style",
149
+ `plitzi://id-styles/${env}/{targetId}`,
150
+ "The CSS of an id rule (#id) targeting a single element"
151
+ ],
120
152
  [
121
153
  "Style variables by category",
122
154
  `plitzi://style-variables/${env}/{category}`,
@@ -1,33 +1,43 @@
1
+ import { buildDataSourceCatalog, buildInteractionCatalog } from "../catalogs/observed.js";
1
2
  import { findElementByRef, findPageByRef } from "../helpers/space.js";
3
+ import { afterPrefix, dataSourcesUri, elementUri, folderUri, foldersUri, interactionsUri, pageUri, pagesUri, schemaVarsUri, settingsUri } from "../helpers/uris.js";
2
4
  import { envelope } from "./envelope.js";
3
- import { elementDetailToAI, folderRefToAI, foldersToAI, pageSkeletonToAI, pageStylesToAI, pageSummariesToAI, schemaVariablesToAI } from "../tools/operations/schema/translator.js";
5
+ import { elementView, folderRefToAI, foldersToAI, pageSkeletonToAI, pageStylesToAI, pageSummariesToAI, schemaVariablesToAI, settingsToAI } from "../tools/operations/schema/translator.js";
4
6
  //#region src/modules/mcp/resources/schema.ts
5
7
  /** Element-schema reads: page listings/skeletons/styles, folders, single elements and schema variables. Returns
6
8
  * undefined when the URI belongs to another domain, null when the shape is ours but the ref does not resolve. */
7
9
  var readSchemaResource = (space, env, uri) => {
8
- if (uri === `plitzi://schema/${env}/pages`) return envelope(pageSummariesToAI(space.schema));
9
- if (uri === `plitzi://folders/${env}`) return envelope(foldersToAI(space.schema));
10
- if (uri.startsWith(`plitzi://folders/${env}/`)) {
11
- const ref = uri.slice(`plitzi://folders/${env}/`.length);
12
- const folder = folderRefToAI(space.schema, ref);
10
+ if (uri === pagesUri(env)) return envelope(pageSummariesToAI(space.schema));
11
+ if (uri === foldersUri(env)) return envelope(foldersToAI(space.schema));
12
+ const folderRef = afterPrefix(uri, folderUri(env, ""));
13
+ if (folderRef !== void 0) {
14
+ const folder = folderRefToAI(space.schema, folderRef);
13
15
  return folder ? envelope(folder) : null;
14
16
  }
15
- if (uri.startsWith(`plitzi://schema/${env}/pages/`) && uri.endsWith("/styles")) {
16
- const ref = uri.slice(`plitzi://schema/${env}/pages/`.length, -7);
17
- const page = findPageByRef(space.schema, ref);
18
- return page ? envelope(pageStylesToAI(space.schema, space.style, page)) : null;
17
+ const pageItem = afterPrefix(uri, pageUri(env, ""));
18
+ if (pageItem !== void 0) {
19
+ if (pageItem.endsWith("/styles")) {
20
+ const ref = pageItem.slice(0, -7);
21
+ const page = findPageByRef(space.schema, ref);
22
+ return page ? envelope(pageStylesToAI(space.schema, space.style, page)) : null;
23
+ }
24
+ const page = findPageByRef(space.schema, pageItem);
25
+ return page ? envelope(pageSkeletonToAI(space.schema, page, space.style)) : null;
19
26
  }
20
- if (uri.startsWith(`plitzi://schema/${env}/pages/`)) {
21
- const ref = uri.slice(`plitzi://schema/${env}/pages/`.length);
22
- const page = findPageByRef(space.schema, ref);
23
- return page ? envelope(pageSkeletonToAI(space.schema, page)) : null;
27
+ const elementRef = afterPrefix(uri, elementUri(env, ""));
28
+ if (elementRef !== void 0) {
29
+ const el = findElementByRef(space.schema, elementRef);
30
+ if (!el) return null;
31
+ const view = elementView(space.schema, el, space.style);
32
+ return {
33
+ stateVersion: view.version,
34
+ data: view.detail
35
+ };
24
36
  }
25
- if (uri.startsWith(`plitzi://schema/${env}/elements/`)) {
26
- const ref = uri.slice(`plitzi://schema/${env}/elements/`.length);
27
- const el = findElementByRef(space.schema, ref);
28
- return el ? envelope(elementDetailToAI(space.schema, el, space.style)) : null;
29
- }
30
- if (uri === `plitzi://schema-variables/${env}`) return envelope(schemaVariablesToAI(space.schema));
37
+ if (uri === schemaVarsUri(env)) return envelope(schemaVariablesToAI(space.schema));
38
+ if (uri === settingsUri(env)) return envelope(settingsToAI(space.schema));
39
+ if (uri === interactionsUri(env)) return envelope(buildInteractionCatalog(space.schema));
40
+ if (uri === dataSourcesUri(env)) return envelope(buildDataSourceCatalog(space.schema));
31
41
  };
32
42
  //#endregion
33
43
  export { readSchemaResource };
@@ -1,24 +1,31 @@
1
+ import { afterPrefix, defUri, defsUri, globalUri, globalsUri, idUri, idsUri, styleVarUri, styleVarsUri } from "../helpers/uris.js";
1
2
  import { envelope } from "./envelope.js";
2
- import { definitionRefs, definitionToAI, globalStyleToAI, globalStyleTypes, styleVariablesToAI } from "../tools/operations/style/translator.js";
3
+ import { definitionRefs, definitionToAI, globalStyleToAI, globalStyleTypes, idStyleIds, idStyleToAI, styleVariablesToAI } from "../tools/operations/style/translator.js";
3
4
  //#region src/modules/mcp/resources/style.ts
4
5
  /** Style-schema reads: definitions, global (per-type) styles and design-token variables by category. Returns
5
6
  * undefined when the URI belongs to another domain, null when the shape is ours but the ref does not resolve. */
6
7
  var readStyleResource = (space, env, uri) => {
7
- if (uri === `plitzi://definitions/${env}`) return envelope(definitionRefs(space.style));
8
- if (uri.startsWith(`plitzi://definitions/${env}/`)) {
9
- const ref = uri.slice(`plitzi://definitions/${env}/`.length);
10
- const def = definitionToAI(space.style, ref);
8
+ if (uri === defsUri(env)) return envelope(definitionRefs(space.style));
9
+ const defRef = afterPrefix(uri, defUri(env, ""));
10
+ if (defRef !== void 0) {
11
+ const def = definitionToAI(space.style, defRef);
11
12
  return def ? envelope(def) : null;
12
13
  }
13
- if (uri === `plitzi://global-styles/${env}`) return envelope(globalStyleTypes(space.style));
14
- if (uri.startsWith(`plitzi://global-styles/${env}/`)) {
15
- const componentType = uri.slice(`plitzi://global-styles/${env}/`.length);
14
+ if (uri === globalsUri(env)) return envelope(globalStyleTypes(space.style));
15
+ const componentType = afterPrefix(uri, globalUri(env, ""));
16
+ if (componentType !== void 0) {
16
17
  const global = globalStyleToAI(space.style, componentType);
17
18
  return global ? envelope(global) : null;
18
19
  }
19
- if (uri === `plitzi://style-variables/${env}`) return envelope(styleVariablesToAI(space.style));
20
- if (uri.startsWith(`plitzi://style-variables/${env}/`)) {
21
- const category = uri.slice(`plitzi://style-variables/${env}/`.length);
20
+ if (uri === idsUri(env)) return envelope(idStyleIds(space.style));
21
+ const targetId = afterPrefix(uri, idUri(env, ""));
22
+ if (targetId !== void 0) {
23
+ const idStyle = idStyleToAI(space.style, targetId);
24
+ return idStyle ? envelope(idStyle) : null;
25
+ }
26
+ if (uri === styleVarsUri(env)) return envelope(styleVariablesToAI(space.style));
27
+ const category = afterPrefix(uri, styleVarUri(env, ""));
28
+ if (category !== void 0) {
22
29
  const byCategory = styleVariablesToAI(space.style);
23
30
  return envelope(Object.hasOwn(byCategory, category) ? byCategory[category] : []);
24
31
  }