@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.
- package/CHANGELOG.md +20 -0
- package/dist/core/services/mcp.js +1 -1
- package/dist/helpers/buildServerInfo.js +3 -9
- package/dist/index.js +2 -1
- package/dist/modules/ai/toolkit.js +1 -0
- package/dist/modules/mcp/catalogs/builtinCallbacks.js +204 -0
- package/dist/modules/mcp/catalogs/builtinComponents.js +170 -0
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +50 -0
- package/dist/modules/mcp/catalogs/builtinTransformers.js +148 -0
- package/dist/modules/mcp/catalogs/builtinUtilities.js +90 -0
- package/dist/modules/mcp/{tools/operations/style → catalogs}/cssCatalog.js +75 -2
- package/dist/modules/mcp/catalogs/observed.js +90 -0
- package/dist/modules/mcp/catalogs/paramSpec.js +69 -0
- package/dist/modules/mcp/catalogs/registry.js +89 -0
- package/dist/modules/mcp/handler.js +41 -13
- package/dist/modules/mcp/helpers/agentPrompt.js +104 -0
- package/dist/modules/mcp/helpers/guide.js +334 -15
- package/dist/modules/mcp/helpers/interactions.js +123 -0
- package/dist/modules/mcp/helpers/log.js +54 -0
- package/dist/modules/mcp/helpers/space.js +184 -33
- package/dist/modules/mcp/helpers/uris.js +44 -0
- package/dist/modules/mcp/resources/canonical.js +6 -21
- package/dist/modules/mcp/resources/core.js +4 -3
- package/dist/modules/mcp/resources/primer.js +13 -8
- package/dist/modules/mcp/resources/register.js +37 -5
- package/dist/modules/mcp/resources/schema.js +30 -20
- package/dist/modules/mcp/resources/style.js +18 -11
- package/dist/modules/mcp/server.js +29 -8
- package/dist/modules/mcp/tools/apply/dispatch.js +38 -18
- package/dist/modules/mcp/tools/apply/index.js +19 -4
- package/dist/modules/mcp/tools/apply/writeResult.js +2 -1
- package/dist/modules/mcp/tools/index.js +3 -1
- package/dist/modules/mcp/tools/operations/index.js +13 -2
- package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +32 -0
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +36 -0
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +47 -0
- package/dist/modules/mcp/tools/operations/schema/{deleteElement.js → elements/deleteElement.js} +10 -6
- package/dist/modules/mcp/tools/operations/schema/{moveElement.js → elements/moveElement.js} +8 -6
- package/dist/modules/mcp/tools/operations/schema/{patchElement.js → elements/patchElement.js} +19 -7
- package/dist/modules/mcp/tools/operations/schema/{upsertElement.js → elements/upsertElement.js} +11 -5
- package/dist/modules/mcp/tools/operations/schema/{deleteFolder.js → folders/deleteFolder.js} +4 -4
- package/dist/modules/mcp/tools/operations/schema/{upsertFolder.js → folders/upsertFolder.js} +4 -4
- package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +52 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +47 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +43 -0
- package/dist/modules/mcp/tools/operations/schema/operations.js +25 -11
- package/dist/modules/mcp/tools/operations/schema/{deletePage.js → pages/deletePage.js} +8 -5
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +75 -0
- package/dist/modules/mcp/tools/operations/schema/settings/patchSettings.js +45 -0
- package/dist/modules/mcp/tools/operations/schema/shared.js +94 -2
- package/dist/modules/mcp/tools/operations/schema/translator.js +77 -10
- package/dist/modules/mcp/tools/operations/schema/{deleteVariable.js → variables/deleteVariable.js} +3 -3
- package/dist/modules/mcp/tools/operations/schema/{upsertVariable.js → variables/upsertVariable.js} +4 -4
- package/dist/modules/mcp/tools/operations/schema/write.js +78 -13
- package/dist/modules/mcp/tools/operations/style/{deleteDefinition.js → definitions/deleteDefinition.js} +4 -3
- package/dist/modules/mcp/tools/operations/style/{patchDefinition.js → definitions/patchDefinition.js} +6 -5
- package/dist/modules/mcp/tools/operations/style/{upsertDefinition.js → definitions/upsertDefinition.js} +5 -4
- package/dist/modules/mcp/tools/operations/style/{deleteGlobalStyle.js → globalStyles/deleteGlobalStyle.js} +4 -3
- package/dist/modules/mcp/tools/operations/style/{patchGlobalStyle.js → globalStyles/patchGlobalStyle.js} +6 -5
- package/dist/modules/mcp/tools/operations/style/{upsertGlobalStyle.js → globalStyles/upsertGlobalStyle.js} +5 -4
- package/dist/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.js +21 -0
- package/dist/modules/mcp/tools/operations/style/idStyles/patchIdStyle.js +28 -0
- package/dist/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.js +24 -0
- package/dist/modules/mcp/tools/operations/style/operations.js +14 -8
- package/dist/modules/mcp/tools/operations/style/translator.js +25 -1
- package/dist/modules/mcp/tools/operations/style/{deleteStyleVariable.js → variables/deleteStyleVariable.js} +4 -4
- package/dist/modules/mcp/tools/operations/style/{upsertStyleVariable.js → variables/upsertStyleVariable.js} +4 -4
- package/dist/modules/mcp/tools/operations/style/write.js +19 -11
- package/dist/modules/mcp/tools/read.js +1 -1
- package/dist/modules/mcp/tools/render.js +114 -0
- package/dist/modules/mcp/tools/search.js +34 -27
- package/dist/modules/mcp/tools/shared/tool.js +1 -0
- package/dist/modules/mcp/tools/shared/validator/audit.js +124 -0
- package/dist/modules/mcp/tools/shared/validator/batch.js +30 -0
- package/dist/modules/mcp/tools/shared/validator/bindings.js +70 -0
- package/dist/modules/mcp/tools/shared/validator/context.js +35 -0
- package/dist/modules/mcp/tools/shared/validator/css.js +47 -0
- package/dist/modules/mcp/tools/shared/validator/elements.js +55 -0
- package/dist/modules/mcp/tools/shared/validator/index.js +226 -0
- package/dist/modules/mcp/tools/shared/validator/interactions.js +106 -0
- package/dist/modules/mcp/tools/shared/validator/refs.js +28 -0
- package/dist/modules/mcp/tools/validate.js +23 -3
- package/dist/modules/ssr/preview.js +1 -1
- package/dist/modules/ssr/views/template.ejs +2 -0
- package/dist/src/index.d.ts +1 -1
- package/dist/src/modules/mcp/catalogs/builtinCallbacks.d.ts +23 -0
- package/dist/src/modules/mcp/catalogs/builtinComponents.d.ts +4 -0
- package/dist/src/modules/mcp/catalogs/builtinElementCallbacks.d.ts +20 -0
- package/dist/src/modules/mcp/catalogs/builtinTransformers.d.ts +28 -0
- package/dist/src/modules/mcp/catalogs/builtinTransformers.test.d.ts +1 -0
- package/dist/src/modules/mcp/catalogs/builtinUtilities.d.ts +18 -0
- package/dist/src/modules/mcp/{tools/operations/style → catalogs}/cssCatalog.d.ts +5 -1
- package/dist/src/modules/mcp/catalogs/index.d.ts +9 -0
- package/dist/src/modules/mcp/catalogs/observed.d.ts +48 -0
- package/dist/src/modules/mcp/catalogs/paramSpec.d.ts +42 -0
- package/dist/src/modules/mcp/catalogs/registry.d.ts +35 -0
- package/dist/src/modules/mcp/handler.d.ts +2 -2
- package/dist/src/modules/mcp/helpers/agentPrompt.d.ts +4 -0
- package/dist/src/modules/mcp/helpers/guide.d.ts +2 -1
- package/dist/src/modules/mcp/helpers/index.d.ts +4 -0
- package/dist/src/modules/mcp/helpers/interactions.d.ts +30 -0
- package/dist/src/modules/mcp/helpers/log.d.ts +8 -0
- package/dist/src/modules/mcp/helpers/log.test.d.ts +1 -0
- package/dist/src/modules/mcp/helpers/space.d.ts +68 -11
- package/dist/src/modules/mcp/helpers/uris.d.ts +28 -0
- package/dist/src/modules/mcp/index.d.ts +1 -1
- package/dist/src/modules/mcp/mcp.bench.d.ts +1 -0
- package/dist/src/modules/mcp/resources/canonical.d.ts +0 -1
- package/dist/src/modules/mcp/resources/index.d.ts +2 -3
- package/dist/src/modules/mcp/resources/primer.d.ts +2 -1
- package/dist/src/modules/mcp/resources/register.d.ts +2 -2
- package/dist/src/modules/mcp/server.d.ts +5 -2
- package/dist/src/modules/mcp/tools/apply/index.d.ts +191 -2
- package/dist/src/modules/mcp/tools/index.d.ts +1 -0
- package/dist/src/modules/mcp/tools/operations/index.d.ts +383 -4
- package/dist/src/modules/mcp/tools/operations/schema/bindings/deleteBinding.d.ts +17 -0
- package/dist/src/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +25 -0
- package/dist/src/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +27 -0
- package/dist/src/modules/mcp/tools/operations/schema/{deleteElement.d.ts → elements/deleteElement.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/schema/{moveElement.d.ts → elements/moveElement.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/schema/{patchElement.d.ts → elements/patchElement.d.ts} +7 -2
- package/dist/src/modules/mcp/tools/operations/schema/{upsertElement.d.ts → elements/upsertElement.d.ts} +3 -3
- package/dist/src/modules/mcp/tools/operations/schema/{deleteFolder.d.ts → folders/deleteFolder.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/schema/{upsertFolder.d.ts → folders/upsertFolder.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/schema/index.d.ts +17 -11
- package/dist/src/modules/mcp/tools/operations/schema/interactions/deleteInteraction.d.ts +12 -0
- package/dist/src/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +18 -0
- package/dist/src/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +27 -0
- package/dist/src/modules/mcp/tools/operations/schema/operations.d.ts +131 -0
- package/dist/src/modules/mcp/tools/operations/schema/{deletePage.d.ts → pages/deletePage.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/schema/{upsertPage.d.ts → pages/upsertPage.d.ts} +3 -2
- package/dist/src/modules/mcp/tools/operations/schema/settings/patchSettings.d.ts +34 -0
- package/dist/src/modules/mcp/tools/operations/schema/shared.d.ts +53 -0
- package/dist/src/modules/mcp/tools/operations/schema/translator.d.ts +5 -2
- package/dist/src/modules/mcp/tools/operations/schema/{deleteVariable.d.ts → variables/deleteVariable.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/schema/{upsertVariable.d.ts → variables/upsertVariable.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/schema/write.d.ts +38 -8
- package/dist/src/modules/mcp/tools/operations/style/{deleteDefinition.d.ts → definitions/deleteDefinition.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/style/{patchDefinition.d.ts → definitions/patchDefinition.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/style/{upsertDefinition.d.ts → definitions/upsertDefinition.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/style/{deleteGlobalStyle.d.ts → globalStyles/deleteGlobalStyle.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/style/{patchGlobalStyle.d.ts → globalStyles/patchGlobalStyle.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/style/{upsertGlobalStyle.d.ts → globalStyles/upsertGlobalStyle.d.ts} +2 -2
- package/dist/src/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.d.ts +9 -0
- package/dist/src/modules/mcp/tools/operations/style/idStyles/patchIdStyle.d.ts +37 -0
- package/dist/src/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.d.ts +37 -0
- package/dist/src/modules/mcp/tools/operations/style/index.d.ts +11 -9
- package/dist/src/modules/mcp/tools/operations/style/operations.d.ts +70 -2
- package/dist/src/modules/mcp/tools/operations/style/shared.d.ts +1 -1
- package/dist/src/modules/mcp/tools/operations/style/translator.d.ts +4 -1
- package/dist/src/modules/mcp/tools/operations/style/{deleteStyleVariable.d.ts → variables/deleteStyleVariable.d.ts} +3 -3
- package/dist/src/modules/mcp/tools/operations/style/{upsertStyleVariable.d.ts → variables/upsertStyleVariable.d.ts} +3 -3
- package/dist/src/modules/mcp/tools/operations/style/write.d.ts +2 -7
- package/dist/src/modules/mcp/tools/preview.d.ts +191 -2
- package/dist/src/modules/mcp/tools/render.d.ts +434 -0
- package/dist/src/modules/mcp/tools/render.test.d.ts +1 -0
- package/dist/src/modules/mcp/tools/screenshot.d.ts +191 -2
- package/dist/src/modules/mcp/tools/shared/tool.d.ts +4 -0
- package/dist/src/modules/mcp/tools/shared/validator/audit.d.ts +4 -0
- package/dist/src/modules/mcp/tools/shared/validator/batch.d.ts +5 -0
- package/dist/src/modules/mcp/tools/shared/validator/bindings.d.ts +6 -0
- package/dist/src/modules/mcp/tools/shared/validator/context.d.ts +34 -0
- package/dist/src/modules/mcp/tools/shared/validator/css.d.ts +4 -0
- package/dist/src/modules/mcp/tools/shared/validator/elements.d.ts +6 -0
- package/dist/src/modules/mcp/tools/shared/validator/index.d.ts +8 -0
- package/dist/src/modules/mcp/tools/shared/validator/interactions.d.ts +3 -0
- package/dist/src/modules/mcp/tools/shared/validator/refs.d.ts +4 -0
- package/dist/src/modules/mcp/tools/validate.d.ts +191 -2
- package/dist/src/modules/mcp/types/aiSchema.d.ts +93 -1
- package/package.json +12 -10
- package/dist/modules/mcp/tools/operations/schema/registry.js +0 -55
- package/dist/modules/mcp/tools/operations/schema/upsertPage.js +0 -64
- package/dist/modules/mcp/tools/shared/validator.js +0 -262
- package/dist/src/modules/mcp/tools/operations/schema/registry.d.ts +0 -22
- package/dist/src/modules/mcp/tools/shared/validator.d.ts +0 -4
|
@@ -1,18 +1,51 @@
|
|
|
1
|
-
import { generateObjectId } from "../../../helpers/space.js";
|
|
1
|
+
import { findElementByRef, findPageByRef, generateObjectId, indexAddElement, indexReRefElement, resolveRef, spaceIndex } from "../../../helpers/space.js";
|
|
2
|
+
import { folderUri, foldersUri, pageUri, pagesUri, schemaVarsUri, settingsUri } from "../../../helpers/uris.js";
|
|
3
|
+
import { fail } from "../../../helpers/opResult.js";
|
|
4
|
+
import { isValidIdRef, makeIdRef } from "@plitzi/sdk-schema/helpers/idRef";
|
|
2
5
|
//#region src/modules/mcp/tools/operations/schema/write.ts
|
|
3
|
-
var
|
|
4
|
-
var
|
|
5
|
-
|
|
6
|
-
var
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
var ID_REF_HINT = "Start with a letter, then letters, numbers, hyphens and underscores (e.g. \"hero-cta\" or \"food_item\"). The ref becomes the element idRef, which the runtime embeds in source names like `apiContainer_<idRef>.field` and in interaction targets — a dot would split those paths (an underscore is fine: the FIRST `_` separates the type from the idRef, and element types carry none, so extra underscores are unambiguous).";
|
|
7
|
+
var TAKEN_HINT = "An idRef must be unique across the space — pick a different ref, or address the existing element by this ref.";
|
|
8
|
+
/** Every ref in an element input tree (the element plus its nested children) — each becomes a new element's idRef. */
|
|
9
|
+
var collectInputRefs = (input) => [input.ref, ...(input.children ?? []).flatMap(collectInputRefs)];
|
|
10
|
+
/** Validate a ref that is about to become an element's idRef: the charset, then whether anything already answers
|
|
11
|
+
* to it. The charset rule is sdk-schema's `isValidIdRef` — never a regex restated here, so the MCP cannot drift
|
|
12
|
+
* from what the builder and the schema validator enforce.
|
|
13
|
+
*
|
|
14
|
+
* Uniqueness is checked with the ref lookups rather than `FlatMap.idRefConflict`, and deliberately so: these are
|
|
15
|
+
* a superset of it. FlatMap asks whether another element holds this idRef; the MCP must also refuse a ref that
|
|
16
|
+
* shadows a raw id or a page slug, because its handlers resolve refs through those too — calling both would just
|
|
17
|
+
* run the same rule twice. Null when the ref is usable.
|
|
18
|
+
*
|
|
19
|
+
* Enforced here, at every point a ref BECOMES an idRef — addressing an existing element by its raw id is not
|
|
20
|
+
* charset-checked, which is why the validator cannot simply tighten its own REF_RE for every ref it sees. */
|
|
21
|
+
var guardNewRef = (space, ref, field) => {
|
|
22
|
+
if (!isValidIdRef(ref)) return fail(field, `"${ref}" is not a valid idRef`, ID_REF_HINT);
|
|
23
|
+
if (findElementByRef(space.schema, ref) || findPageByRef(space.schema, ref)) return fail(field, `"${ref}" is already used by another element in this space`, TAKEN_HINT);
|
|
24
|
+
return null;
|
|
25
|
+
};
|
|
26
|
+
var removeFromParent = (space, child) => {
|
|
27
|
+
const parent = child.definition.parentId ? space.schema.flat[child.definition.parentId] : void 0;
|
|
28
|
+
if (parent?.definition.items) parent.definition.items = parent.definition.items.filter((id) => id !== child.id);
|
|
10
29
|
};
|
|
11
30
|
var placeChild = (parent, childId, index) => {
|
|
12
31
|
const items = parent.definition.items ?? (parent.definition.items = []);
|
|
13
32
|
if (index === void 0 || index < 0 || index >= items.length) items.push(childId);
|
|
14
33
|
else items.splice(index, 0, childId);
|
|
15
34
|
};
|
|
35
|
+
var writeInitialState = (el, input, merge) => {
|
|
36
|
+
const current = el.definition.initialState ?? {};
|
|
37
|
+
const next = { ...current };
|
|
38
|
+
if (input.styleVariant !== void 0) if (merge) {
|
|
39
|
+
const merged = { ...current.styleVariant };
|
|
40
|
+
for (const [cls, selectors] of Object.entries(input.styleVariant)) merged[cls] = {
|
|
41
|
+
...merged[cls],
|
|
42
|
+
...selectors
|
|
43
|
+
};
|
|
44
|
+
next.styleVariant = merged;
|
|
45
|
+
} else next.styleVariant = input.styleVariant;
|
|
46
|
+
if (input.visibility !== void 0) next.visibility = input.visibility;
|
|
47
|
+
el.definition.initialState = next;
|
|
48
|
+
};
|
|
16
49
|
var createElement = (space, page, input, parent, index) => {
|
|
17
50
|
const id = generateObjectId();
|
|
18
51
|
const { subType, ...props } = {
|
|
@@ -21,8 +54,9 @@ var createElement = (space, page, input, parent, index) => {
|
|
|
21
54
|
};
|
|
22
55
|
const styleSelectors = { base: (input.style?.base ?? []).join(" ") };
|
|
23
56
|
for (const [slot, classes] of Object.entries(input.style?.slots ?? {})) styleSelectors[slot] = classes.join(" ");
|
|
24
|
-
|
|
57
|
+
const el = {
|
|
25
58
|
id,
|
|
59
|
+
idRef: input.ref,
|
|
26
60
|
attributes: subType === void 0 ? props : {
|
|
27
61
|
subType,
|
|
28
62
|
...props
|
|
@@ -33,12 +67,43 @@ var createElement = (space, page, input, parent, index) => {
|
|
|
33
67
|
label: input.label ?? input.ref,
|
|
34
68
|
type: input.type,
|
|
35
69
|
items: [],
|
|
36
|
-
styleSelectors
|
|
37
|
-
aiRef: input.ref
|
|
70
|
+
styleSelectors
|
|
38
71
|
}
|
|
39
72
|
};
|
|
73
|
+
space.schema.flat[id] = el;
|
|
40
74
|
placeChild(parent, id, index);
|
|
41
|
-
|
|
75
|
+
indexAddElement(space.schema, el, page.id);
|
|
76
|
+
if (input.initialState) writeInitialState(el, input.initialState, false);
|
|
77
|
+
for (const child of input.children ?? []) createElement(space, page, child, el, void 0);
|
|
78
|
+
};
|
|
79
|
+
/** The idRef an element is wired by, minting one when it has none. Interactions are keyed by idRef, so an element
|
|
80
|
+
* that is about to host or be targeted by a flow must have one — rather than make the agent assign it with a
|
|
81
|
+
* separate patchElement, the MCP gives it a free `<type>-<n>` ref (unique across the space) and proceeds. An
|
|
82
|
+
* element that already has an idRef keeps it. Mutates the element in place and returns the ref. */
|
|
83
|
+
var ensureIdRef = (space, el) => {
|
|
84
|
+
if (el.idRef) return el.idRef;
|
|
85
|
+
const index = spaceIndex(space.schema);
|
|
86
|
+
el.idRef = makeIdRef(el.definition.type, (candidate) => index.elementByRef.has(candidate) || index.pageByRef.has(candidate));
|
|
87
|
+
indexReRefElement(space.schema, el);
|
|
88
|
+
return el.idRef;
|
|
89
|
+
};
|
|
90
|
+
/** The key an interaction node must store to reach a target element. Every ref field also accepts a raw id, so a
|
|
91
|
+
* target given as an id is resolved to the element's idRef — the key the runtime registers callbacks under. A
|
|
92
|
+
* target that has no idRef is given one (see `ensureIdRef`), since it must be reachable to be wired to. A target
|
|
93
|
+
* that resolves to no element is left as written — it is already a ref, or a key only a plugin knows. */
|
|
94
|
+
var resolveTargetRef = (space, elementId) => {
|
|
95
|
+
const el = space.schema.flat[elementId] ?? findElementByRef(space.schema, elementId);
|
|
96
|
+
return el ? ensureIdRef(space, el) : elementId;
|
|
97
|
+
};
|
|
98
|
+
/** Resolve a non-page element within a page for the element-scoped ops (bindings, interactions). Returns the
|
|
99
|
+
* element, or a teachable OpResult when the page or element ref does not resolve — so each op reports the same
|
|
100
|
+
* errors as patchElement without repeating them. */
|
|
101
|
+
var resolveElement = (space, env, pageRef, ref) => {
|
|
102
|
+
const page = findPageByRef(space.schema, pageRef);
|
|
103
|
+
if (!page) return { error: fail("pageRef", `Page "${pageRef}" not found`, `Read plitzi://schema/${env}/pages for valid refs`) };
|
|
104
|
+
const el = resolveRef(space.schema, page, ref);
|
|
105
|
+
if (!el || el.id === page.id) return { error: fail("ref", `Element "${ref}" not found in page "${pageRef}"`, "Use an existing element ref or id") };
|
|
106
|
+
return { el };
|
|
42
107
|
};
|
|
43
108
|
//#endregion
|
|
44
|
-
export { createElement, folderUri, foldersUri, pageUri, pagesUri, placeChild, removeFromParent, schemaVarsUri };
|
|
109
|
+
export { ID_REF_HINT, collectInputRefs, createElement, ensureIdRef, folderUri, foldersUri, guardNewRef, pageUri, pagesUri, placeChild, removeFromParent, resolveElement, resolveTargetRef, schemaVarsUri, settingsUri, writeInitialState };
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { defUri, defsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { MODES, guardKind } from "../write.js";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
//#region src/modules/mcp/tools/operations/style/deleteDefinition.ts
|
|
5
|
+
//#region src/modules/mcp/tools/operations/style/definitions/deleteDefinition.ts
|
|
5
6
|
var deleteDefinitionOp = z.object({
|
|
6
7
|
type: z.literal("deleteDefinition"),
|
|
7
8
|
ref: z.string().describe("Class ref of the definition to delete")
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { defUri, defsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty, fail } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { definitionToAI } from "../translator.js";
|
|
4
|
+
import { guardKind, mergePatch, writeStyleItem } from "../write.js";
|
|
5
|
+
import { patchCssShape } from "../shared.js";
|
|
5
6
|
import { z } from "zod";
|
|
6
|
-
//#region src/modules/mcp/tools/operations/style/patchDefinition.ts
|
|
7
|
+
//#region src/modules/mcp/tools/operations/style/definitions/patchDefinition.ts
|
|
7
8
|
var patchDefinitionOp = z.object({
|
|
8
9
|
type: z.literal("patchDefinition"),
|
|
9
10
|
ref: z.string().describe("Existing class ref to patch"),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { defUri, defsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { guardKind, writeStyleItem } from "../write.js";
|
|
4
|
+
import { upsertCssShape } from "../shared.js";
|
|
4
5
|
import { z } from "zod";
|
|
5
|
-
//#region src/modules/mcp/tools/operations/style/upsertDefinition.ts
|
|
6
|
+
//#region src/modules/mcp/tools/operations/style/definitions/upsertDefinition.ts
|
|
6
7
|
var upsertDefinitionOp = z.object({
|
|
7
8
|
type: z.literal("upsertDefinition"),
|
|
8
9
|
ref: z.string().describe("Class name you choose (kebab-case), or an existing class ref to fully replace"),
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { globalUri, globalsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { MODES, guardKind } from "../write.js";
|
|
3
4
|
import { z } from "zod";
|
|
4
|
-
//#region src/modules/mcp/tools/operations/style/deleteGlobalStyle.ts
|
|
5
|
+
//#region src/modules/mcp/tools/operations/style/globalStyles/deleteGlobalStyle.ts
|
|
5
6
|
var deleteGlobalStyleOp = z.object({
|
|
6
7
|
type: z.literal("deleteGlobalStyle"),
|
|
7
8
|
componentType: z.string().describe("Element type whose site-wide style to remove")
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import { globalUri, globalsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty, fail } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { globalStyleToAI } from "../translator.js";
|
|
4
|
+
import { guardKind, mergePatch, writeStyleItem } from "../write.js";
|
|
5
|
+
import { patchCssShape } from "../shared.js";
|
|
5
6
|
import { z } from "zod";
|
|
6
|
-
//#region src/modules/mcp/tools/operations/style/patchGlobalStyle.ts
|
|
7
|
+
//#region src/modules/mcp/tools/operations/style/globalStyles/patchGlobalStyle.ts
|
|
7
8
|
var patchGlobalStyleOp = z.object({
|
|
8
9
|
type: z.literal("patchGlobalStyle"),
|
|
9
10
|
componentType: z.string().describe("Element type whose global style to merge into; affects ALL of that type"),
|
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { globalUri, globalsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { guardKind, writeStyleItem } from "../write.js";
|
|
4
|
+
import { upsertCssShape } from "../shared.js";
|
|
4
5
|
import { z } from "zod";
|
|
5
|
-
//#region src/modules/mcp/tools/operations/style/upsertGlobalStyle.ts
|
|
6
|
+
//#region src/modules/mcp/tools/operations/style/globalStyles/upsertGlobalStyle.ts
|
|
6
7
|
var upsertGlobalStyleOp = z.object({
|
|
7
8
|
type: z.literal("upsertGlobalStyle"),
|
|
8
9
|
componentType: z.string().describe("Element type to style site-wide (e.g. \"button\"); affects ALL of that type"),
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { idUri, idsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { MODES, guardKind } from "../write.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
//#region src/modules/mcp/tools/operations/style/idStyles/deleteIdStyle.ts
|
|
6
|
+
var deleteIdStyleOp = z.object({
|
|
7
|
+
type: z.literal("deleteIdStyle"),
|
|
8
|
+
targetId: z.string().describe("DOM id whose id rule to remove (without the # prefix)")
|
|
9
|
+
}).describe("Remove the id rule (`#id`) for a single element (the element keeps its own classes).");
|
|
10
|
+
var deleteIdStyle = (space, env, op) => {
|
|
11
|
+
const guard = guardKind(space.style, op.targetId, "id");
|
|
12
|
+
if (guard) return guard;
|
|
13
|
+
for (const mode of MODES) Reflect.deleteProperty(space.style.platform[mode], op.targetId);
|
|
14
|
+
return {
|
|
15
|
+
...empty(),
|
|
16
|
+
deleted: 1,
|
|
17
|
+
staleResources: [idUri(env, op.targetId), idsUri(env)]
|
|
18
|
+
};
|
|
19
|
+
};
|
|
20
|
+
//#endregion
|
|
21
|
+
export { deleteIdStyle, deleteIdStyleOp };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { idUri, idsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty, fail } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { idStyleToAI } from "../translator.js";
|
|
4
|
+
import { guardKind, mergePatch, writeStyleItem } from "../write.js";
|
|
5
|
+
import { patchCssShape } from "../shared.js";
|
|
6
|
+
import { z } from "zod";
|
|
7
|
+
//#region src/modules/mcp/tools/operations/style/idStyles/patchIdStyle.ts
|
|
8
|
+
var patchIdStyleOp = z.object({
|
|
9
|
+
type: z.literal("patchIdStyle"),
|
|
10
|
+
targetId: z.string().describe("DOM id whose id rule to merge into (without the # prefix)"),
|
|
11
|
+
...patchCssShape
|
|
12
|
+
}).describe("Partially update the CSS of an id rule (`#id`): CSS is merged (a null value removes a property). Never creates — use upsertIdStyle for that.");
|
|
13
|
+
var patchIdStyle = (space, env, op) => {
|
|
14
|
+
const guard = guardKind(space.style, op.targetId, "id");
|
|
15
|
+
if (guard) return guard;
|
|
16
|
+
const existing = idStyleToAI(space.style, op.targetId);
|
|
17
|
+
if (!existing) return fail("targetId", `No id rule for "${op.targetId}"`, "patchIdStyle only updates an existing id rule; use upsertIdStyle to create one");
|
|
18
|
+
const { type, targetId, slots: slotsPatch, ...basePatch } = op;
|
|
19
|
+
const { base, slots } = mergePatch(existing, basePatch, slotsPatch);
|
|
20
|
+
writeStyleItem(space.style, targetId, base, slots, "id", void 0);
|
|
21
|
+
return {
|
|
22
|
+
...empty(),
|
|
23
|
+
updated: 1,
|
|
24
|
+
staleResources: [idUri(env, targetId), idsUri(env)]
|
|
25
|
+
};
|
|
26
|
+
};
|
|
27
|
+
//#endregion
|
|
28
|
+
export { patchIdStyle, patchIdStyleOp };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { idUri, idsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { guardKind, writeStyleItem } from "../write.js";
|
|
4
|
+
import { upsertCssShape } from "../shared.js";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
//#region src/modules/mcp/tools/operations/style/idStyles/upsertIdStyle.ts
|
|
7
|
+
var upsertIdStyleOp = z.object({
|
|
8
|
+
type: z.literal("upsertIdStyle"),
|
|
9
|
+
targetId: z.string().describe("DOM id of the element to style (without the # prefix); matches its `id` attribute"),
|
|
10
|
+
...upsertCssShape
|
|
11
|
+
}).describe("Create or fully replace the CSS for a single element addressed by its DOM id (`#id`). The element must carry that `id` attribute. To style by reusable class instead, use upsertDefinition. Use patchIdStyle for a partial change.");
|
|
12
|
+
var upsertIdStyle = (space, env, op) => {
|
|
13
|
+
const { type, targetId, slots, ...base } = op;
|
|
14
|
+
const guard = guardKind(space.style, targetId, "id");
|
|
15
|
+
if (guard) return guard;
|
|
16
|
+
writeStyleItem(space.style, targetId, base, slots, "id", void 0);
|
|
17
|
+
return {
|
|
18
|
+
...empty(),
|
|
19
|
+
updated: 1,
|
|
20
|
+
staleResources: [idUri(env, targetId), idsUri(env)]
|
|
21
|
+
};
|
|
22
|
+
};
|
|
23
|
+
//#endregion
|
|
24
|
+
export { upsertIdStyle, upsertIdStyleOp };
|
|
@@ -1,11 +1,14 @@
|
|
|
1
|
-
import { deleteDefinitionOp } from "./deleteDefinition.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { patchGlobalStyleOp } from "./patchGlobalStyle.js";
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { deleteDefinitionOp } from "./definitions/deleteDefinition.js";
|
|
2
|
+
import { patchDefinitionOp } from "./definitions/patchDefinition.js";
|
|
3
|
+
import { upsertDefinitionOp } from "./definitions/upsertDefinition.js";
|
|
4
|
+
import { deleteGlobalStyleOp } from "./globalStyles/deleteGlobalStyle.js";
|
|
5
|
+
import { patchGlobalStyleOp } from "./globalStyles/patchGlobalStyle.js";
|
|
6
|
+
import { upsertGlobalStyleOp } from "./globalStyles/upsertGlobalStyle.js";
|
|
7
|
+
import { deleteIdStyleOp } from "./idStyles/deleteIdStyle.js";
|
|
8
|
+
import { patchIdStyleOp } from "./idStyles/patchIdStyle.js";
|
|
9
|
+
import { upsertIdStyleOp } from "./idStyles/upsertIdStyle.js";
|
|
10
|
+
import { deleteStyleVariableOp } from "./variables/deleteStyleVariable.js";
|
|
11
|
+
import { upsertStyleVariableOp } from "./variables/upsertStyleVariable.js";
|
|
9
12
|
//#region src/modules/mcp/tools/operations/style/operations.ts
|
|
10
13
|
var styleOps = {
|
|
11
14
|
upsertDefinition: upsertDefinitionOp,
|
|
@@ -14,6 +17,9 @@ var styleOps = {
|
|
|
14
17
|
upsertGlobalStyle: upsertGlobalStyleOp,
|
|
15
18
|
patchGlobalStyle: patchGlobalStyleOp,
|
|
16
19
|
deleteGlobalStyle: deleteGlobalStyleOp,
|
|
20
|
+
upsertIdStyle: upsertIdStyleOp,
|
|
21
|
+
patchIdStyle: patchIdStyleOp,
|
|
22
|
+
deleteIdStyle: deleteIdStyleOp,
|
|
17
23
|
upsertStyleVariable: upsertStyleVariableOp,
|
|
18
24
|
deleteStyleVariable: deleteStyleVariableOp
|
|
19
25
|
};
|
|
@@ -38,6 +38,18 @@ var projectItem = (style, ref, accept) => {
|
|
|
38
38
|
return found ? def : void 0;
|
|
39
39
|
};
|
|
40
40
|
var definitionToAI = (style, ref) => projectItem(style, ref, isClassDefinition);
|
|
41
|
+
var definitionVariantNames = (style, ref) => {
|
|
42
|
+
const def = definitionToAI(style, ref);
|
|
43
|
+
if (!def) return;
|
|
44
|
+
const result = {};
|
|
45
|
+
const baseVariants = Object.keys(def.variants ?? {});
|
|
46
|
+
if (baseVariants.length > 0) result.base = baseVariants.sort();
|
|
47
|
+
for (const [slot, slotDef] of Object.entries(def.slots ?? {})) {
|
|
48
|
+
const variants = Object.keys(slotDef.variants ?? {});
|
|
49
|
+
if (variants.length > 0) result[slot] = variants.sort();
|
|
50
|
+
}
|
|
51
|
+
return Object.keys(result).length > 0 ? result : void 0;
|
|
52
|
+
};
|
|
41
53
|
var globalStylesForType = (style, componentType) => {
|
|
42
54
|
const isGlobal = (item) => item.type === "element" && item.componentType === componentType;
|
|
43
55
|
const refs = /* @__PURE__ */ new Set();
|
|
@@ -64,6 +76,18 @@ var globalStyleTypes = (style) => {
|
|
|
64
76
|
for (const mode of DISPLAY_MODES) for (const item of Object.values(style.platform[mode])) if (item.type === "element" && item.componentType) types.add(item.componentType);
|
|
65
77
|
return Array.from(types).sort();
|
|
66
78
|
};
|
|
79
|
+
var idStyleIds = (style) => {
|
|
80
|
+
const ids = /* @__PURE__ */ new Set();
|
|
81
|
+
for (const mode of DISPLAY_MODES) for (const [name, item] of Object.entries(style.platform[mode])) if (item.type === "id") ids.add(name);
|
|
82
|
+
return Array.from(ids).sort();
|
|
83
|
+
};
|
|
84
|
+
var idStyleToAI = (style, targetId) => {
|
|
85
|
+
const def = projectItem(style, targetId, (item) => item.type === "id");
|
|
86
|
+
return def ? {
|
|
87
|
+
...def,
|
|
88
|
+
targetId
|
|
89
|
+
} : void 0;
|
|
90
|
+
};
|
|
67
91
|
var styleVariablesToAI = (style) => {
|
|
68
92
|
const data = {};
|
|
69
93
|
for (const [category, group] of Object.entries(style.variables)) data[category] = Object.entries(group).map(([name, value]) => ({
|
|
@@ -74,4 +98,4 @@ var styleVariablesToAI = (style) => {
|
|
|
74
98
|
return data;
|
|
75
99
|
};
|
|
76
100
|
//#endregion
|
|
77
|
-
export { definitionRefs, definitionToAI, globalStyleToAI, globalStyleTypes, globalStylesForType, isClassDefinition, styleVariablesToAI };
|
|
101
|
+
export { definitionRefs, definitionToAI, definitionVariantNames, globalStyleToAI, globalStyleTypes, globalStylesForType, idStyleIds, idStyleToAI, isClassDefinition, styleVariablesToAI };
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { styleCategory } from "
|
|
1
|
+
import { styleVarUri, styleVarsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { styleCategory } from "../shared.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
//#region src/modules/mcp/tools/operations/style/deleteStyleVariable.ts
|
|
5
|
+
//#region src/modules/mcp/tools/operations/style/variables/deleteStyleVariable.ts
|
|
6
6
|
var deleteStyleVariableOp = z.object({
|
|
7
7
|
type: z.literal("deleteStyleVariable"),
|
|
8
8
|
category: styleCategory,
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { styleCategory, themeValue } from "
|
|
1
|
+
import { styleVarUri, styleVarsUri } from "../../../../helpers/uris.js";
|
|
2
|
+
import { empty } from "../../../../helpers/opResult.js";
|
|
3
|
+
import { styleCategory, themeValue } from "../shared.js";
|
|
4
4
|
import { z } from "zod";
|
|
5
|
-
//#region src/modules/mcp/tools/operations/style/upsertStyleVariable.ts
|
|
5
|
+
//#region src/modules/mcp/tools/operations/style/variables/upsertStyleVariable.ts
|
|
6
6
|
var upsertStyleVariableOp = z.object({
|
|
7
7
|
type: z.literal("upsertStyleVariable"),
|
|
8
8
|
category: styleCategory,
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { expandShorthand } from "../../../catalogs/cssCatalog.js";
|
|
2
|
+
import { defUri, defsUri, globalUri, globalsUri, idUri, idsUri, styleVarUri, styleVarsUri } from "../../../helpers/uris.js";
|
|
1
3
|
import { fail } from "../../../helpers/opResult.js";
|
|
2
|
-
import { expandShorthand } from "./cssCatalog.js";
|
|
3
4
|
import processSelector from "@plitzi/sdk-style/helpers/processSelector";
|
|
4
5
|
//#region src/modules/mcp/tools/operations/style/write.ts
|
|
5
6
|
var MODES = [
|
|
@@ -7,18 +8,25 @@ var MODES = [
|
|
|
7
8
|
"tablet",
|
|
8
9
|
"mobile"
|
|
9
10
|
];
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
var
|
|
16
|
-
|
|
11
|
+
var KIND_LABEL = {
|
|
12
|
+
class: "a reusable class definition",
|
|
13
|
+
element: "a global style for an element type",
|
|
14
|
+
id: "an id rule targeting a single element"
|
|
15
|
+
};
|
|
16
|
+
var KIND_TOOL = {
|
|
17
|
+
class: "upsertDefinition/patchDefinition",
|
|
18
|
+
element: "upsertGlobalStyle/patchGlobalStyle",
|
|
19
|
+
id: "upsertIdStyle/patchIdStyle"
|
|
20
|
+
};
|
|
21
|
+
var KIND_FIELD = {
|
|
22
|
+
class: "ref",
|
|
23
|
+
element: "componentType",
|
|
24
|
+
id: "targetId"
|
|
25
|
+
};
|
|
17
26
|
var guardKind = (style, ref, want) => {
|
|
18
27
|
const clash = MODES.map((mode) => style.platform[mode][ref]).find((item) => item !== void 0 && item.type !== want);
|
|
19
28
|
if (!clash) return null;
|
|
20
|
-
|
|
21
|
-
return fail(wantIsClass ? "ref" : "componentType", `"${ref}" is already ${describeKind(clash)}; it cannot be edited as ${wantIsClass ? "a class definition" : "a global element style"}`, wantIsClass ? "To restyle every element of a type on purpose, use upsertGlobalStyle/patchGlobalStyle with its componentType. Otherwise pick a different class name." : "That name is a class definition — edit it with upsertDefinition/patchDefinition, or choose a different componentType.");
|
|
29
|
+
return fail(KIND_FIELD[want], `"${ref}" is already ${KIND_LABEL[clash.type]}; it cannot be edited as ${KIND_LABEL[want]}`, `Edit it with ${KIND_TOOL[clash.type]}, or choose a different ${KIND_FIELD[want]}.`);
|
|
22
30
|
};
|
|
23
31
|
var slotToBlocks = (slot) => {
|
|
24
32
|
const perMode = {};
|
|
@@ -97,4 +105,4 @@ var mergePatch = (existing, basePatch, slotsPatch) => {
|
|
|
97
105
|
};
|
|
98
106
|
};
|
|
99
107
|
//#endregion
|
|
100
|
-
export { MODES, defUri, defsUri, globalUri, globalsUri, guardKind, mergePatch, styleVarUri, styleVarsUri, writeStyleItem };
|
|
108
|
+
export { MODES, defUri, defsUri, globalUri, globalsUri, guardKind, idUri, idsUri, mergePatch, styleVarUri, styleVarsUri, writeStyleItem };
|
|
@@ -24,7 +24,7 @@ var read = (input, space, env) => {
|
|
|
24
24
|
var readTool = defineTool({
|
|
25
25
|
name: "plitzi_read",
|
|
26
26
|
title: "Batch read",
|
|
27
|
-
description: "
|
|
27
|
+
description: "Batch-fetch resource content for URIs you ALREADY HOLD (from plitzi_search or a write response) — the tool form of opening MCP resources, for many at once. Pass an array of URIs (pages, elements, definitions, variables) and get them all in one call. NOT for finding things: to locate an element by label/type use plitzi_search; to browse what exists, list the plitzi:// resources. Each result is { uri, stateVersion, data } or a teachable error, so one bad URI never fails the batch. Never hand-build a URI to guess your way to an element — search for it.",
|
|
28
28
|
inputShape: readShape,
|
|
29
29
|
access: "read",
|
|
30
30
|
run: (input, ctx) => read(input, ctx.space, ctx.env)
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
import { emptySpace } from "../helpers/space.js";
|
|
2
|
+
import { operations } from "./operations/index.js";
|
|
3
|
+
import { applyOperations } from "./apply/dispatch.js";
|
|
4
|
+
import { defineTool } from "./shared/tool.js";
|
|
5
|
+
import { validateOperations } from "./shared/validator/index.js";
|
|
6
|
+
import { auditResources } from "./shared/validator/audit.js";
|
|
7
|
+
import { validateSchema } from "@plitzi/sdk-schema";
|
|
8
|
+
import { generateCache } from "@plitzi/sdk-style";
|
|
9
|
+
//#region src/modules/mcp/tools/render.ts
|
|
10
|
+
var HOST_PAGE_REF = "render";
|
|
11
|
+
var seedSpace = () => {
|
|
12
|
+
const space = emptySpace();
|
|
13
|
+
space.schema.definition.name = "Widget";
|
|
14
|
+
space.schema.flat[HOST_PAGE_REF] = {
|
|
15
|
+
id: HOST_PAGE_REF,
|
|
16
|
+
idRef: HOST_PAGE_REF,
|
|
17
|
+
attributes: {
|
|
18
|
+
slug: "",
|
|
19
|
+
name: "Render",
|
|
20
|
+
default: true
|
|
21
|
+
},
|
|
22
|
+
definition: {
|
|
23
|
+
rootId: HOST_PAGE_REF,
|
|
24
|
+
label: "Page",
|
|
25
|
+
type: "page",
|
|
26
|
+
items: [],
|
|
27
|
+
styleSelectors: { base: "" }
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
space.schema.pages = [HOST_PAGE_REF];
|
|
31
|
+
return space;
|
|
32
|
+
};
|
|
33
|
+
var noWarnings = (warnings) => warnings.length > 0 ? warnings : void 0;
|
|
34
|
+
var renderShape = { operations };
|
|
35
|
+
var render = (input) => {
|
|
36
|
+
const space = seedSpace();
|
|
37
|
+
const validation = validateOperations(space, input.operations);
|
|
38
|
+
if (!validation.valid) return {
|
|
39
|
+
rendered: false,
|
|
40
|
+
errors: validation.errors,
|
|
41
|
+
warnings: noWarnings(validation.warnings)
|
|
42
|
+
};
|
|
43
|
+
const outcome = applyOperations(space, "main", input.operations);
|
|
44
|
+
if (outcome.errors.length > 0) return {
|
|
45
|
+
rendered: false,
|
|
46
|
+
errors: outcome.errors,
|
|
47
|
+
warnings: noWarnings(validation.warnings)
|
|
48
|
+
};
|
|
49
|
+
const integrity = validateSchema(space.schema);
|
|
50
|
+
if (!integrity.valid) return {
|
|
51
|
+
rendered: false,
|
|
52
|
+
errors: integrity.errors.map((error) => ({
|
|
53
|
+
path: error.elementId ? `schema.${error.elementId}` : "schema",
|
|
54
|
+
message: error.message,
|
|
55
|
+
hint: "The authored widget is structurally inconsistent (broken parent/child link or a cycle)."
|
|
56
|
+
})),
|
|
57
|
+
warnings: noWarnings(validation.warnings)
|
|
58
|
+
};
|
|
59
|
+
const audit = auditResources(space, input.operations);
|
|
60
|
+
const warnings = [...validation.warnings, ...audit.warnings];
|
|
61
|
+
if (audit.errors.length > 0) return {
|
|
62
|
+
rendered: false,
|
|
63
|
+
errors: audit.errors,
|
|
64
|
+
warnings: noWarnings(warnings)
|
|
65
|
+
};
|
|
66
|
+
space.style.cache = generateCache(space.style);
|
|
67
|
+
return {
|
|
68
|
+
rendered: true,
|
|
69
|
+
rootRef: HOST_PAGE_REF,
|
|
70
|
+
elementCount: Object.keys(space.schema.flat).length - 1,
|
|
71
|
+
offlineData: {
|
|
72
|
+
schema: space.schema,
|
|
73
|
+
style: space.style
|
|
74
|
+
},
|
|
75
|
+
warnings: noWarnings(warnings)
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
var toRenderResult = (res) => {
|
|
79
|
+
if (!res.rendered) return { content: [{
|
|
80
|
+
type: "text",
|
|
81
|
+
text: JSON.stringify({
|
|
82
|
+
rendered: false,
|
|
83
|
+
errors: res.errors,
|
|
84
|
+
warnings: res.warnings
|
|
85
|
+
})
|
|
86
|
+
}] };
|
|
87
|
+
const summary = {
|
|
88
|
+
rendered: true,
|
|
89
|
+
rootRef: res.rootRef,
|
|
90
|
+
elementCount: res.elementCount,
|
|
91
|
+
warnings: res.warnings
|
|
92
|
+
};
|
|
93
|
+
return {
|
|
94
|
+
content: [{
|
|
95
|
+
type: "text",
|
|
96
|
+
text: JSON.stringify(summary)
|
|
97
|
+
}],
|
|
98
|
+
structuredContent: {
|
|
99
|
+
...summary,
|
|
100
|
+
offlineData: res.offlineData
|
|
101
|
+
}
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
var renderTool = defineTool({
|
|
105
|
+
name: "plitzi_render",
|
|
106
|
+
title: "Render widget",
|
|
107
|
+
description: "Render a small self-contained UI widget the user can SEE, with the Plitzi SDK offline (no backend). Reach for it in two cases: (1) the user asks you to create/design/build/show a piece of UI (a card, hero, form, button, banner, pricing table…); (2) you are answering a content question and a visual layout communicates better than prose — render the ANSWER as a widget (a recipe as a card, a comparison as a table, steps as a checklist, a profile, a menu). Prefer showing it over a long text answer whenever the content is naturally visual. You author the widget as operations targeting the pre-seeded host page `pageRef: \"render\"` (same vocabulary as plitzi_apply: upsertElement, upsertDefinition, …). Returns a compact summary; the rendered widget is shown to the user. To edit an existing space page instead, use plitzi_preview.",
|
|
108
|
+
inputShape: renderShape,
|
|
109
|
+
access: "read",
|
|
110
|
+
spaceless: true,
|
|
111
|
+
run: (input) => toRenderResult(render(input))
|
|
112
|
+
});
|
|
113
|
+
//#endregion
|
|
114
|
+
export { render, renderShape, renderTool };
|