@plitzi/sdk-mcp 0.33.2 → 0.34.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +62 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +3 -2
- package/dist/modules/mcp/catalogs/index.d.ts +2 -7
- package/dist/modules/mcp/catalogs/index.js +4 -0
- package/dist/modules/mcp/catalogs/observed.d.ts +1 -1
- package/dist/modules/mcp/catalogs/observed.js +2 -5
- package/dist/modules/mcp/catalogs/pluginCatalog.d.ts +17 -0
- package/dist/modules/mcp/catalogs/pluginCatalog.js +91 -0
- package/dist/modules/mcp/catalogs/registry.js +2 -3
- package/dist/modules/mcp/helpers/agentPrompt.js +9 -9
- package/dist/modules/mcp/helpers/guide.d.ts +2 -2
- package/dist/modules/mcp/helpers/guide.js +117 -50
- package/dist/modules/mcp/helpers/interactions.d.ts +5 -1
- package/dist/modules/mcp/helpers/interactions.js +15 -6
- package/dist/modules/mcp/helpers/space.d.ts +45 -28
- package/dist/modules/mcp/helpers/space.js +87 -87
- package/dist/modules/mcp/helpers/uris.d.ts +9 -0
- package/dist/modules/mcp/helpers/uris.js +10 -1
- package/dist/modules/mcp/index.d.ts +2 -0
- package/dist/modules/mcp/localScreenshotClient.d.ts +51 -0
- package/dist/modules/mcp/localScreenshotClient.js +106 -0
- package/dist/modules/mcp/proxy/rewrite.js +15 -1
- package/dist/modules/mcp/resources/actions.d.ts +25 -0
- package/dist/modules/mcp/resources/actions.js +54 -0
- package/dist/modules/mcp/resources/canonical.d.ts +1 -1
- package/dist/modules/mcp/resources/canonical.js +1 -1
- package/dist/modules/mcp/resources/connectors.d.ts +1 -1
- package/dist/modules/mcp/resources/core.js +1 -1
- package/dist/modules/mcp/resources/index.d.ts +1 -0
- package/dist/modules/mcp/resources/primer.d.ts +8 -1
- package/dist/modules/mcp/resources/primer.js +139 -15
- package/dist/modules/mcp/resources/register.js +24 -4
- package/dist/modules/mcp/resources/renderGuide.js +66 -14
- package/dist/modules/mcp/resources/router.js +3 -1
- package/dist/modules/mcp/resources/schema.js +6 -5
- package/dist/modules/mcp/resources/style.d.ts +2 -1
- package/dist/modules/mcp/resources/style.js +10 -3
- package/dist/modules/mcp/screenshotClient.js +3 -2
- package/dist/modules/mcp/server.js +12 -6
- package/dist/modules/mcp/tests/agentRoundtrip.test.d.ts +1 -0
- package/dist/modules/mcp/tests/layouts.test.d.ts +1 -0
- package/dist/modules/mcp/tools/apply/dispatch.js +30 -1
- package/dist/modules/mcp/tools/apply/index.d.ts +149 -15
- package/dist/modules/mcp/tools/apply/index.js +12 -2
- package/dist/modules/mcp/tools/operations/actions/actions.test.d.ts +1 -0
- package/dist/modules/mcp/tools/operations/actions/deleteAction.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/actions/deleteAction.js +20 -0
- package/dist/modules/mcp/tools/operations/actions/document.d.ts +69 -0
- package/dist/modules/mcp/tools/operations/actions/document.js +73 -0
- package/dist/modules/mcp/tools/operations/actions/index.d.ts +90 -0
- package/dist/modules/mcp/tools/operations/actions/index.js +12 -0
- package/dist/modules/mcp/tools/operations/actions/patchAction.d.ts +45 -0
- package/dist/modules/mcp/tools/operations/actions/patchAction.js +71 -0
- package/dist/modules/mcp/tools/operations/actions/upsertAction.d.ts +47 -0
- package/dist/modules/mcp/tools/operations/actions/upsertAction.js +83 -0
- package/dist/modules/mcp/tools/operations/connectors/index.d.ts +10 -10
- package/dist/modules/mcp/tools/operations/connectors/manifest.d.ts +5 -5
- package/dist/modules/mcp/tools/operations/connectors/patchConnector.d.ts +5 -5
- package/dist/modules/mcp/tools/operations/connectors/upsertConnector.d.ts +5 -5
- package/dist/modules/mcp/tools/operations/index.d.ts +415 -40
- package/dist/modules/mcp/tools/operations/index.js +11 -2
- package/dist/modules/mcp/tools/operations/schema/bindings/deleteBinding.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/bindings/patchBinding.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/bindings/upsertBinding.js +4 -4
- package/dist/modules/mcp/tools/operations/schema/elements/deleteElement.js +5 -5
- package/dist/modules/mcp/tools/operations/schema/elements/moveElement.js +6 -6
- package/dist/modules/mcp/tools/operations/schema/elements/patchElement.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/elements/patchElement.js +11 -12
- package/dist/modules/mcp/tools/operations/schema/elements/repeatElement.js +1 -1
- package/dist/modules/mcp/tools/operations/schema/elements/upsertElement.js +4 -4
- package/dist/modules/mcp/tools/operations/schema/index.d.ts +2 -0
- package/dist/modules/mcp/tools/operations/schema/interactions/deleteInteraction.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/interactions/patchInteractionNode.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.d.ts +1 -1
- package/dist/modules/mcp/tools/operations/schema/interactions/upsertInteractionFlow.js +4 -4
- package/dist/modules/mcp/tools/operations/schema/operations.d.ts +28 -5
- package/dist/modules/mcp/tools/operations/schema/operations.js +4 -0
- package/dist/modules/mcp/tools/operations/schema/pages/deleteLayout.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/schema/pages/deleteLayout.js +33 -0
- package/dist/modules/mcp/tools/operations/schema/pages/deletePage.js +1 -1
- package/dist/modules/mcp/tools/operations/schema/pages/upsertLayout.d.ts +22 -0
- package/dist/modules/mcp/tools/operations/schema/pages/upsertLayout.js +61 -0
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.d.ts +2 -0
- package/dist/modules/mcp/tools/operations/schema/pages/upsertPage.js +53 -18
- package/dist/modules/mcp/tools/operations/schema/shared.d.ts +5 -1
- package/dist/modules/mcp/tools/operations/schema/shared.js +2 -2
- package/dist/modules/mcp/tools/operations/schema/translator.d.ts +2 -1
- package/dist/modules/mcp/tools/operations/schema/translator.js +21 -9
- package/dist/modules/mcp/tools/operations/schema/write.d.ts +9 -22
- package/dist/modules/mcp/tools/operations/schema/write.js +23 -43
- package/dist/modules/mcp/tools/operations/schemaIds.js +7 -1
- package/dist/modules/mcp/tools/operations/style/fonts/deleteFont.d.ts +9 -0
- package/dist/modules/mcp/tools/operations/style/fonts/deleteFont.js +21 -0
- package/dist/modules/mcp/tools/operations/style/fonts/fonts.test.d.ts +1 -0
- package/dist/modules/mcp/tools/operations/style/fonts/upsertFont.d.ts +35 -0
- package/dist/modules/mcp/tools/operations/style/fonts/upsertFont.js +66 -0
- package/dist/modules/mcp/tools/operations/style/index.d.ts +2 -0
- package/dist/modules/mcp/tools/operations/style/operations.d.ts +34 -0
- package/dist/modules/mcp/tools/operations/style/operations.js +5 -1
- package/dist/modules/mcp/tools/operations/style/translator.d.ts +13 -1
- package/dist/modules/mcp/tools/operations/style/translator.js +18 -1
- package/dist/modules/mcp/tools/operations/style/write.js +1 -1
- package/dist/modules/mcp/tools/preview.d.ts +58 -5
- package/dist/modules/mcp/tools/preview.js +1 -1
- package/dist/modules/mcp/tools/render.d.ts +61 -5
- package/dist/modules/mcp/tools/render.js +10 -3
- package/dist/modules/mcp/tools/screenshot.d.ts +151 -16
- package/dist/modules/mcp/tools/screenshot.js +22 -13
- package/dist/modules/mcp/tools/search.js +3 -3
- package/dist/modules/mcp/tools/shared/interactionReport.d.ts +7 -0
- package/dist/modules/mcp/tools/shared/interactionReport.js +48 -0
- package/dist/modules/mcp/tools/shared/validator/audit.js +4 -4
- package/dist/modules/mcp/tools/shared/validator/batch.d.ts +1 -0
- package/dist/modules/mcp/tools/shared/validator/batch.js +11 -2
- package/dist/modules/mcp/tools/shared/validator/bindings.js +6 -6
- package/dist/modules/mcp/tools/shared/validator/connectors.js +1 -1
- package/dist/modules/mcp/tools/shared/validator/context.d.ts +3 -0
- package/dist/modules/mcp/tools/shared/validator/css.js +1 -1
- package/dist/modules/mcp/tools/shared/validator/index.js +29 -9
- package/dist/modules/mcp/tools/shared/validator/interactions.js +41 -7
- package/dist/modules/mcp/tools/shared/validator/refs.js +4 -4
- package/dist/modules/mcp/tools/validate.d.ts +149 -15
- package/dist/modules/mcp/types/aiSchema.d.ts +33 -4
- package/dist/modules/mcp/types/previewTypes.d.ts +19 -0
- package/dist/modules/mcp/types/screenshotTypes.d.ts +1 -0
- package/dist/modules/mcp/types/toolTypes.d.ts +6 -1
- package/dist/pipeline.js +1 -1
- package/dist/preview/createPreview.d.ts +4 -2
- package/dist/preview/createPreview.js +16 -6
- package/dist/server.d.ts +3 -0
- package/dist/server.js +3 -1
- package/dist/stages/preview.js +20 -1
- package/dist/tests/httpRequest.d.ts +2 -0
- package/package.json +20 -16
- package/skills/plitzi-render/SKILL.md +84 -11
- package/dist/modules/mcp/catalogs/builtinCallbacks.d.ts +0 -19
- package/dist/modules/mcp/catalogs/builtinCallbacks.js +0 -139
- package/dist/modules/mcp/catalogs/builtinComponents.d.ts +0 -4
- package/dist/modules/mcp/catalogs/builtinComponents.js +0 -165
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.d.ts +0 -17
- package/dist/modules/mcp/catalogs/builtinElementCallbacks.js +0 -50
- package/dist/modules/mcp/catalogs/builtinTransformers.d.ts +0 -28
- package/dist/modules/mcp/catalogs/builtinTransformers.js +0 -148
- package/dist/modules/mcp/catalogs/builtinUtilities.d.ts +0 -15
- package/dist/modules/mcp/catalogs/builtinUtilities.js +0 -90
- package/dist/modules/mcp/catalogs/cssCatalog/border.d.ts +0 -4
- package/dist/modules/mcp/catalogs/cssCatalog/border.js +0 -30
- package/dist/modules/mcp/catalogs/cssCatalog/box.d.ts +0 -4
- package/dist/modules/mcp/catalogs/cssCatalog/box.js +0 -31
- package/dist/modules/mcp/catalogs/cssCatalog/helpers.d.ts +0 -34
- package/dist/modules/mcp/catalogs/cssCatalog/helpers.js +0 -185
- package/dist/modules/mcp/catalogs/cssCatalog/index.d.ts +0 -18
- package/dist/modules/mcp/catalogs/cssCatalog/index.js +0 -131
- package/dist/modules/mcp/catalogs/cssCatalog/layout.d.ts +0 -9
- package/dist/modules/mcp/catalogs/cssCatalog/layout.js +0 -99
- package/dist/modules/mcp/catalogs/cssCatalog/visual.d.ts +0 -8
- package/dist/modules/mcp/catalogs/cssCatalog/visual.js +0 -147
- package/dist/modules/mcp/catalogs/paramSpec.d.ts +0 -39
- package/dist/modules/mcp/catalogs/paramSpec.js +0 -69
- package/dist/modules/oauth/authorize.d.ts +0 -7
- package/dist/modules/oauth/authorize.js +0 -177
- package/dist/modules/oauth/challenge.d.ts +0 -11
- package/dist/modules/oauth/challenge.js +0 -33
- package/dist/modules/oauth/consentPage.d.ts +0 -7
- package/dist/modules/oauth/consentPage.js +0 -118
- package/dist/modules/oauth/metadata.d.ts +0 -40
- package/dist/modules/oauth/metadata.js +0 -69
- package/dist/modules/oauth/params.d.ts +0 -5
- package/dist/modules/oauth/params.js +0 -5
- package/dist/modules/oauth/pkce.d.ts +0 -6
- package/dist/modules/oauth/pkce.js +0 -15
- package/dist/modules/oauth/records.d.ts +0 -71
- package/dist/modules/oauth/records.js +0 -46
- package/dist/modules/oauth/register.d.ts +0 -5
- package/dist/modules/oauth/register.js +0 -55
- package/dist/modules/oauth/respond.d.ts +0 -13
- package/dist/modules/oauth/respond.js +0 -44
- package/dist/modules/oauth/token.d.ts +0 -5
- package/dist/modules/oauth/token.js +0 -100
- package/dist/stages/oauth.d.ts +0 -19
- package/dist/stages/oauth.js +0 -114
- /package/dist/modules/mcp/catalogs/{builtinTransformers.test.d.ts → pluginCatalog.test.d.ts} +0 -0
- /package/dist/modules/mcp/{catalogs/cssCatalog/cssCatalog.test.d.ts → localScreenshotClient.test.d.ts} +0 -0
|
@@ -3,6 +3,8 @@ var cloneSpace = (space) => ({
|
|
|
3
3
|
schema: structuredClone(space.schema),
|
|
4
4
|
style: structuredClone(space.style),
|
|
5
5
|
connectors: structuredClone(space.connectors),
|
|
6
|
+
actions: structuredClone(space.actions),
|
|
7
|
+
...space.actionTasks ? { actionTasks: space.actionTasks } : {},
|
|
6
8
|
...space.catalog ? { catalog: space.catalog } : {}
|
|
7
9
|
});
|
|
8
10
|
var emptySpace = () => ({
|
|
@@ -28,68 +30,57 @@ var emptySpace = () => ({
|
|
|
28
30
|
schemes: ["light", "dark"]
|
|
29
31
|
},
|
|
30
32
|
variables: {},
|
|
33
|
+
fonts: [],
|
|
31
34
|
cache: ""
|
|
32
35
|
},
|
|
33
|
-
connectors: []
|
|
36
|
+
connectors: [],
|
|
37
|
+
actions: []
|
|
34
38
|
});
|
|
35
39
|
/** A connector by the identifier a provider element stores in its `connector` attribute. */
|
|
36
40
|
var findConnectorEntry = (space, ref) => space.connectors.find((entry) => entry.id === ref);
|
|
41
|
+
/** An action by the identifier a `runServerAction` step stores. */
|
|
42
|
+
var findActionEntry = (space, ref) => space.actions.find((entry) => entry.id === ref);
|
|
37
43
|
var slugify = (value) => value.toLowerCase().replace(/[^a-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "") || "";
|
|
38
44
|
/** A value when it is a string, otherwise undefined — for the many attributes typed as `unknown` that are strings
|
|
39
45
|
* in practice (name, slug, subType, dom id…). */
|
|
40
46
|
var strOr = (value) => typeof value === "string" ? value : void 0;
|
|
41
47
|
/** Display name of a page or element: its `name` attribute when set, otherwise its definition label. */
|
|
42
48
|
var nameOf = (el) => strOr(el.attributes.name) ?? el.definition.label;
|
|
43
|
-
/** Stable, human-readable ref for a page: its idRef, then slug, then a slugified label. A page without an idRef is
|
|
44
|
-
* still addressable — unlike a data source, a page ref has meaningful fallbacks the agent can read off the tree. */
|
|
45
|
-
var pageRefOf = (el) => {
|
|
46
|
-
if (el.idRef) return el.idRef;
|
|
47
|
-
const slug = strOr(el.attributes.slug)?.trim();
|
|
48
|
-
if (slug) return slugify(slug);
|
|
49
|
-
if (el.attributes.default === true) return "home";
|
|
50
|
-
return slugify(nameOf(el)) || el.id;
|
|
51
|
-
};
|
|
52
|
-
/** Stable ref for ADDRESSING a non-page element in the tree: its idRef when present, otherwise the opaque id so an
|
|
53
|
-
* element without one is still reachable — the agent needs to name it to give it an idRef in the first place.
|
|
54
|
-
* This is not the wiring key: the runtime wires interactions and data sources by idRef only, so an element
|
|
55
|
-
* addressed here by its id alone publishes no source and takes no interactions (see `getSourceName`). */
|
|
56
|
-
var elementRefOf = (el) => el.idRef ?? el.id;
|
|
57
49
|
var buildIndex = (schema) => {
|
|
58
50
|
const flat = schema.flat;
|
|
59
51
|
const lookup = (id) => flat[id];
|
|
60
52
|
const pageIds = new Set(schema.pages);
|
|
61
53
|
for (const el of Object.values(flat)) if (el.definition.type === "page") pageIds.add(el.id);
|
|
62
54
|
const pageElements = [];
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}
|
|
55
|
+
for (const el of Object.values(flat)) if (pageIds.has(el.id)) pageElements.push(el);
|
|
56
|
+
/**
|
|
57
|
+
* The layout shells: a `layoutContainer` with no parent.
|
|
58
|
+
*
|
|
59
|
+
* The type alone is not the test — a layoutContainer nested inside another element is an ordinary element of that
|
|
60
|
+
* tree. What makes one a root is that nothing owns it, which is also what makes a page reference it by name
|
|
61
|
+
* instead of containing it.
|
|
62
|
+
*/
|
|
63
|
+
const layoutElements = [];
|
|
64
|
+
for (const el of Object.values(flat)) if (el.definition.type === "layoutContainer" && !el.definition.parentId) layoutElements.push(el);
|
|
65
|
+
const layoutIds = new Set(layoutElements.map((el) => el.id));
|
|
75
66
|
const pageOf = /* @__PURE__ */ new Map();
|
|
76
|
-
for (const
|
|
77
|
-
pageOf.set(
|
|
78
|
-
const stack = [...
|
|
67
|
+
for (const root of [...pageElements, ...layoutElements]) {
|
|
68
|
+
pageOf.set(root.id, root.id);
|
|
69
|
+
const stack = [...root.definition.items ?? []];
|
|
79
70
|
while (stack.length > 0) {
|
|
80
71
|
const id = stack.pop();
|
|
81
72
|
if (id === void 0 || pageOf.has(id)) continue;
|
|
82
73
|
const el = lookup(id);
|
|
83
74
|
if (!el) continue;
|
|
84
|
-
pageOf.set(id,
|
|
75
|
+
pageOf.set(id, root.id);
|
|
85
76
|
for (const childId of el.definition.items ?? []) stack.push(childId);
|
|
86
77
|
}
|
|
87
78
|
}
|
|
88
79
|
return {
|
|
89
80
|
pageIds,
|
|
90
81
|
pageElements,
|
|
91
|
-
|
|
92
|
-
|
|
82
|
+
layoutIds,
|
|
83
|
+
layoutElements,
|
|
93
84
|
pageOf,
|
|
94
85
|
detailCache: /* @__PURE__ */ new Map()
|
|
95
86
|
};
|
|
@@ -104,13 +95,17 @@ var spaceIndex = (schema) => {
|
|
|
104
95
|
}
|
|
105
96
|
return index;
|
|
106
97
|
};
|
|
98
|
+
/** Drop the memoized index wholesale. A correctness fallback for a mutation with no dedicated incremental updater;
|
|
99
|
+
* the next scanner rebuilds against current state. Prefer the index* helpers below, which keep a built index in
|
|
100
|
+
* step in O(1) — a large structural batch would otherwise pay an O(flat) rebuild after every op. */
|
|
101
|
+
var invalidateIndex = (schema) => {
|
|
102
|
+
indexCache.delete(schema);
|
|
103
|
+
};
|
|
107
104
|
var cachedIndex = (schema) => indexCache.get(schema);
|
|
108
105
|
/** A new non-page element was created under `pageId`. */
|
|
109
106
|
var indexAddElement = (schema, el, pageId) => {
|
|
110
107
|
const index = cachedIndex(schema);
|
|
111
108
|
if (!index) return;
|
|
112
|
-
index.elementByRef.set(el.id, el);
|
|
113
|
-
if (el.idRef) index.elementByRef.set(el.idRef, el);
|
|
114
109
|
index.pageOf.set(el.id, pageId);
|
|
115
110
|
index.detailCache.clear();
|
|
116
111
|
};
|
|
@@ -118,18 +113,7 @@ var indexAddElement = (schema, el, pageId) => {
|
|
|
118
113
|
var indexRemoveElements = (schema, els) => {
|
|
119
114
|
const index = cachedIndex(schema);
|
|
120
115
|
if (!index) return;
|
|
121
|
-
for (const el of els)
|
|
122
|
-
index.elementByRef.delete(el.id);
|
|
123
|
-
if (el.idRef) index.elementByRef.delete(el.idRef);
|
|
124
|
-
index.pageOf.delete(el.id);
|
|
125
|
-
}
|
|
126
|
-
index.detailCache.clear();
|
|
127
|
-
};
|
|
128
|
-
/** An existing element was just given an idRef (it had none), so it becomes addressable by that ref. */
|
|
129
|
-
var indexReRefElement = (schema, el) => {
|
|
130
|
-
const index = cachedIndex(schema);
|
|
131
|
-
if (!index) return;
|
|
132
|
-
if (el.idRef) index.elementByRef.set(el.idRef, el);
|
|
116
|
+
for (const el of els) index.pageOf.delete(el.id);
|
|
133
117
|
index.detailCache.clear();
|
|
134
118
|
};
|
|
135
119
|
/** A new page element was created. */
|
|
@@ -138,11 +122,29 @@ var indexAddPage = (schema, page) => {
|
|
|
138
122
|
if (!index) return;
|
|
139
123
|
index.pageIds.add(page.id);
|
|
140
124
|
index.pageElements.push(page);
|
|
141
|
-
index.pageByRef.set(page.id, page);
|
|
142
|
-
index.pageByRef.set(pageRefOf(page), page);
|
|
143
125
|
index.pageOf.set(page.id, page.id);
|
|
144
126
|
index.detailCache.clear();
|
|
145
127
|
};
|
|
128
|
+
/** A new layout shell was created. */
|
|
129
|
+
var indexAddLayout = (schema, layout) => {
|
|
130
|
+
const index = cachedIndex(schema);
|
|
131
|
+
if (!index) return;
|
|
132
|
+
index.layoutIds.add(layout.id);
|
|
133
|
+
index.layoutElements.push(layout);
|
|
134
|
+
index.pageOf.set(layout.id, layout.id);
|
|
135
|
+
index.detailCache.clear();
|
|
136
|
+
};
|
|
137
|
+
/** A layout shell and its `descendants` were deleted. */
|
|
138
|
+
var indexRemoveLayout = (schema, layout, descendants) => {
|
|
139
|
+
const index = cachedIndex(schema);
|
|
140
|
+
if (!index) return;
|
|
141
|
+
index.layoutIds.delete(layout.id);
|
|
142
|
+
const at = index.layoutElements.findIndex((entry) => entry.id === layout.id);
|
|
143
|
+
if (at >= 0) index.layoutElements.splice(at, 1);
|
|
144
|
+
index.pageOf.delete(layout.id);
|
|
145
|
+
for (const el of descendants) index.pageOf.delete(el.id);
|
|
146
|
+
index.detailCache.clear();
|
|
147
|
+
};
|
|
146
148
|
/** A page and its `descendants` (its non-page elements) were deleted. */
|
|
147
149
|
var indexRemovePage = (schema, page, descendants) => {
|
|
148
150
|
const index = cachedIndex(schema);
|
|
@@ -150,39 +152,44 @@ var indexRemovePage = (schema, page, descendants) => {
|
|
|
150
152
|
index.pageIds.delete(page.id);
|
|
151
153
|
const at = index.pageElements.findIndex((p) => p.id === page.id);
|
|
152
154
|
if (at >= 0) index.pageElements.splice(at, 1);
|
|
153
|
-
index.pageByRef.delete(page.id);
|
|
154
|
-
index.pageByRef.delete(pageRefOf(page));
|
|
155
155
|
index.pageOf.delete(page.id);
|
|
156
|
-
for (const el of descendants)
|
|
157
|
-
index.elementByRef.delete(el.id);
|
|
158
|
-
if (el.idRef) index.elementByRef.delete(el.idRef);
|
|
159
|
-
index.pageOf.delete(el.id);
|
|
160
|
-
}
|
|
156
|
+
for (const el of descendants) index.pageOf.delete(el.id);
|
|
161
157
|
index.detailCache.clear();
|
|
162
158
|
};
|
|
163
|
-
/** A
|
|
164
|
-
*
|
|
165
|
-
var indexReRefPage = (schema, page, oldRef) => {
|
|
166
|
-
const index = cachedIndex(schema);
|
|
167
|
-
if (!index) return;
|
|
168
|
-
const newRef = pageRefOf(page);
|
|
169
|
-
if (newRef !== oldRef) {
|
|
170
|
-
index.pageByRef.delete(oldRef);
|
|
171
|
-
index.pageByRef.set(newRef, page);
|
|
172
|
-
index.detailCache.clear();
|
|
173
|
-
}
|
|
174
|
-
};
|
|
175
|
-
/** A move reparented an element within its page: the ref/page maps are unchanged, but the moved element's
|
|
176
|
-
* parentRef and both parents' childRefs did change, so their memoized detail must be dropped. */
|
|
159
|
+
/** A move reparented an element within its page: the page map is unchanged, but the moved element's parent and
|
|
160
|
+
* both parents' children did change, so their memoized detail must be dropped. */
|
|
177
161
|
var indexInvalidateDetails = (schema) => {
|
|
178
162
|
cachedIndex(schema)?.detailCache.clear();
|
|
179
163
|
};
|
|
180
164
|
var isPageElement = (schema, el) => spaceIndex(schema).pageIds.has(el.id) || el.definition.type === "page";
|
|
181
165
|
var getPageElements = (schema) => spaceIndex(schema).pageElements;
|
|
182
|
-
/**
|
|
183
|
-
var findPageByRef = (schema,
|
|
184
|
-
|
|
185
|
-
|
|
166
|
+
/** A page by the one name it answers to, which is also its key in `flat`. */
|
|
167
|
+
var findPageByRef = (schema, pageId) => {
|
|
168
|
+
const el = schema.flat[pageId];
|
|
169
|
+
return el && spaceIndex(schema).pageIds.has(el.id) ? el : void 0;
|
|
170
|
+
};
|
|
171
|
+
/** A non-page element by the one name it answers to, anywhere in the space. */
|
|
172
|
+
var findElementByRef = (schema, id) => {
|
|
173
|
+
const el = schema.flat[id];
|
|
174
|
+
return el && !spaceIndex(schema).pageIds.has(el.id) ? el : void 0;
|
|
175
|
+
};
|
|
176
|
+
/** A layout SHELL by name — the root a page names in its `layout` attribute. */
|
|
177
|
+
var findLayoutByRef = (schema, id) => {
|
|
178
|
+
const el = schema.flat[id];
|
|
179
|
+
return el && spaceIndex(schema).layoutIds.has(el.id) ? el : void 0;
|
|
180
|
+
};
|
|
181
|
+
/**
|
|
182
|
+
* The root an element operation addresses — a page, or a layout shell.
|
|
183
|
+
*
|
|
184
|
+
* `pageRef` names either: the header of a space lives in a layout and is edited exactly like anything on a page, so
|
|
185
|
+
* every op that resolves an element resolves it from here. Reading them apart is only for the operations that are
|
|
186
|
+
* about pages as pages (routes, folders, the default page).
|
|
187
|
+
*/
|
|
188
|
+
var findRootByRef = (schema, id) => findPageByRef(schema, id) ?? findLayoutByRef(schema, id);
|
|
189
|
+
/** The layout shells of a space, in schema.flat insertion order. */
|
|
190
|
+
var getLayoutElements = (schema) => spaceIndex(schema).layoutElements;
|
|
191
|
+
/** The pages rendered inside a given layout shell, by the `layout` attribute that names it. */
|
|
192
|
+
var pagesUsingLayout = (schema, layoutId) => spaceIndex(schema).pageElements.filter((page) => page.attributes.layout === layoutId);
|
|
186
193
|
var pageFoldersOf = (schema) => {
|
|
187
194
|
schema.pageFolders ??= [];
|
|
188
195
|
return schema.pageFolders;
|
|
@@ -263,12 +270,12 @@ var descendantIds = (schema, pageRootId) => {
|
|
|
263
270
|
collectDescendants(schema, pageRootId, acc);
|
|
264
271
|
return acc;
|
|
265
272
|
};
|
|
266
|
-
/** Resolve a
|
|
267
|
-
*
|
|
273
|
+
/** Resolve a name to a concrete element within a page subtree (or the page root itself). The name is the element's
|
|
274
|
+
* key in `flat`; what this adds is the check that it really belongs to this page. */
|
|
268
275
|
var resolveRef = (schema, page, ref) => {
|
|
269
|
-
if (
|
|
276
|
+
if (page.id === ref) return page;
|
|
270
277
|
const index = spaceIndex(schema);
|
|
271
|
-
const el =
|
|
278
|
+
const el = schema.flat[ref];
|
|
272
279
|
return el && index.pageOf.get(el.id) === page.id ? el : void 0;
|
|
273
280
|
};
|
|
274
281
|
/** Ordered children of an element, honoring definition.items and skipping dangling ids. */
|
|
@@ -276,11 +283,7 @@ var orderedChildren = (schema, el) => {
|
|
|
276
283
|
return (el.definition.items ?? []).map((id) => schema.flat[id]).filter((child) => Boolean(child));
|
|
277
284
|
};
|
|
278
285
|
/** The page ref an element belongs to. 'unknown' when it has no page ancestor. */
|
|
279
|
-
var pageRefOfElement = (schema, el) =>
|
|
280
|
-
const pageId = spaceIndex(schema).pageOf.get(el.id);
|
|
281
|
-
const page = pageId ? schema.flat[pageId] : void 0;
|
|
282
|
-
return page ? pageRefOf(page) : "unknown";
|
|
283
|
-
};
|
|
286
|
+
var pageRefOfElement = (schema, el) => spaceIndex(schema).pageOf.get(el.id) ?? "unknown";
|
|
284
287
|
/** Total number of descendant elements under a subtree (excluding the root). */
|
|
285
288
|
var descendantCount = (schema, rootId) => descendantIds(schema, rootId).length;
|
|
286
289
|
var emptySpaceMessage = "Space data not available";
|
|
@@ -307,8 +310,5 @@ var ReadOnlyGrantError = class extends Error {
|
|
|
307
310
|
this.name = "ReadOnlyGrantError";
|
|
308
311
|
}
|
|
309
312
|
};
|
|
310
|
-
var generateObjectId = () => {
|
|
311
|
-
return `${Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0")}${Array.from({ length: 16 }, () => Math.floor(Math.random() * 16).toString(16)).join("")}`;
|
|
312
|
-
};
|
|
313
313
|
//#endregion
|
|
314
|
-
export { NoSpaceError, ReadOnlyGrantError, cloneSpace, descendantCount, descendantIds, elementById,
|
|
314
|
+
export { NoSpaceError, ReadOnlyGrantError, cloneSpace, descendantCount, descendantIds, elementById, emptySpace, emptySpaceMessage, findActionEntry, findConnectorEntry, findElementByRef, findFolderByRef, findLayoutByRef, findPageByRef, findRootByRef, folderAncestorIds, getLayoutElements, getPageElements, indexAddElement, indexAddLayout, indexAddPage, indexInvalidateDetails, indexRemoveElements, indexRemoveLayout, indexRemovePage, invalidateIndex, isPageElement, nameOf, noSpaceErrorCode, orderedChildren, pageFoldersOf, pageRefOfElement, pagesUsingLayout, readOnlyGrantErrorCode, readOnlyGrantMessage, resolveRef, routeParamNames, slugRouteParams, slugify, sortFolders, spaceIndex, strOr, unauthorizedSpaceMessage };
|
|
@@ -6,6 +6,8 @@ export declare const primerUri: (env: Env) => string;
|
|
|
6
6
|
export declare const pagesUri: (env: Env) => string;
|
|
7
7
|
export declare const pageUri: (env: Env, ref: string) => string;
|
|
8
8
|
export declare const pageStylesUri: (env: Env, ref: string) => string;
|
|
9
|
+
/** The shared layout shells. One of them is read as a page is — `pages/{ref}` resolves either root. */
|
|
10
|
+
export declare const layoutsUri: (env: Env) => string;
|
|
9
11
|
export declare const elementUri: (env: Env, ref: string) => string;
|
|
10
12
|
export declare const schemaVarsUri: (env: Env) => string;
|
|
11
13
|
export declare const settingsUri: (env: Env) => string;
|
|
@@ -16,6 +18,11 @@ export declare const dataSourcesUri: (env: Env) => string;
|
|
|
16
18
|
export declare const connectorPresetsUri = "plitzi://connector-presets";
|
|
17
19
|
export declare const connectorsUri: (env: Env) => string;
|
|
18
20
|
export declare const connectorUri: (env: Env, ref: string) => string;
|
|
21
|
+
export declare const actionsUri: (env: Env) => string;
|
|
22
|
+
export declare const actionUri: (env: Env, ref: string) => string;
|
|
23
|
+
/** The step vocabulary. Under the actions root because that is where an author looks for it, and resolved before
|
|
24
|
+
* the `{ref}` shape so an action can never be named `tasks`. */
|
|
25
|
+
export declare const actionTasksUri: (env: Env) => string;
|
|
19
26
|
export declare const foldersUri: (env: Env) => string;
|
|
20
27
|
export declare const folderUri: (env: Env, ref: string) => string;
|
|
21
28
|
export declare const defsUri: (env: Env) => string;
|
|
@@ -24,6 +31,8 @@ export declare const globalsUri: (env: Env) => string;
|
|
|
24
31
|
export declare const globalUri: (env: Env, componentType: string) => string;
|
|
25
32
|
export declare const idsUri: (env: Env) => string;
|
|
26
33
|
export declare const idUri: (env: Env, targetId: string) => string;
|
|
34
|
+
export declare const fontsUri: (env: Env) => string;
|
|
35
|
+
export declare const fontUri: (env: Env, family: string) => string;
|
|
27
36
|
export declare const styleVarsUri: (env: Env) => string;
|
|
28
37
|
export declare const styleVarUri: (env: Env, category: string) => string;
|
|
29
38
|
export declare const aliasedRoots: string[];
|
|
@@ -5,6 +5,8 @@ var cssPropertiesUri = "plitzi://css-properties";
|
|
|
5
5
|
var primerUri = (env) => `plitzi://primer/${env}`;
|
|
6
6
|
var pagesUri = (env) => `plitzi://schema/${env}/pages`;
|
|
7
7
|
var pageUri = (env, ref) => `plitzi://schema/${env}/pages/${ref}`;
|
|
8
|
+
/** The shared layout shells. One of them is read as a page is — `pages/{ref}` resolves either root. */
|
|
9
|
+
var layoutsUri = (env) => `plitzi://schema/${env}/layouts`;
|
|
8
10
|
var elementUri = (env, ref) => `plitzi://schema/${env}/elements/${ref}`;
|
|
9
11
|
var schemaVarsUri = (env) => `plitzi://schema-variables/${env}`;
|
|
10
12
|
var settingsUri = (env) => `plitzi://settings/${env}`;
|
|
@@ -15,6 +17,11 @@ var dataSourcesUri = (env) => `plitzi://data-sources/${env}`;
|
|
|
15
17
|
var connectorPresetsUri = "plitzi://connector-presets";
|
|
16
18
|
var connectorsUri = (env) => `plitzi://connectors/${env}`;
|
|
17
19
|
var connectorUri = (env, ref) => `plitzi://connectors/${env}/${ref}`;
|
|
20
|
+
var actionsUri = (env) => `plitzi://actions/${env}`;
|
|
21
|
+
var actionUri = (env, ref) => `plitzi://actions/${env}/${ref}`;
|
|
22
|
+
/** The step vocabulary. Under the actions root because that is where an author looks for it, and resolved before
|
|
23
|
+
* the `{ref}` shape so an action can never be named `tasks`. */
|
|
24
|
+
var actionTasksUri = (env) => `plitzi://actions/${env}/tasks`;
|
|
18
25
|
var foldersUri = (env) => `plitzi://folders/${env}`;
|
|
19
26
|
var folderUri = (env, ref) => `plitzi://folders/${env}/${ref}`;
|
|
20
27
|
var defsUri = (env) => `plitzi://definitions/${env}`;
|
|
@@ -23,6 +30,8 @@ var globalsUri = (env) => `plitzi://global-styles/${env}`;
|
|
|
23
30
|
var globalUri = (env, componentType) => `plitzi://global-styles/${env}/${componentType}`;
|
|
24
31
|
var idsUri = (env) => `plitzi://id-styles/${env}`;
|
|
25
32
|
var idUri = (env, targetId) => `plitzi://id-styles/${env}/${targetId}`;
|
|
33
|
+
var fontsUri = (env) => `plitzi://fonts/${env}`;
|
|
34
|
+
var fontUri = (env, family) => `plitzi://fonts/${env}/${family}`;
|
|
26
35
|
var styleVarsUri = (env) => `plitzi://style-variables/${env}`;
|
|
27
36
|
var styleVarUri = (env, category) => `plitzi://style-variables/${env}/${category}`;
|
|
28
37
|
var aliasedRoots = [
|
|
@@ -47,4 +56,4 @@ var itemTemplates = (env) => [
|
|
|
47
56
|
* family and extracts its ref in one step, without repeating the prefix string for both the startsWith and slice. */
|
|
48
57
|
var afterPrefix = (uri, prefix) => uri.startsWith(prefix) ? uri.slice(prefix.length) : void 0;
|
|
49
58
|
//#endregion
|
|
50
|
-
export { afterPrefix, aliasedRoots, connectorPresetsUri, connectorUri, connectorsUri, cssPropertiesUri, dataSourcesUri, defUri, defsUri, elementUri, folderUri, foldersUri, globalUri, globalsUri, guideUri, idUri, idsUri, interactionsUri, itemTemplates, pageUri, pagesUri, primerUri, schemaVarsUri, settingsUri, styleVarUri, styleVarsUri, typesUri };
|
|
59
|
+
export { actionTasksUri, actionUri, actionsUri, afterPrefix, aliasedRoots, connectorPresetsUri, connectorUri, connectorsUri, cssPropertiesUri, dataSourcesUri, defUri, defsUri, elementUri, folderUri, foldersUri, fontUri, fontsUri, globalUri, globalsUri, guideUri, idUri, idsUri, interactionsUri, itemTemplates, layoutsUri, pageUri, pagesUri, primerUri, schemaVarsUri, settingsUri, styleVarUri, styleVarsUri, typesUri };
|
|
@@ -3,9 +3,11 @@ export { readResource, resourceVersion, registerResources, buildTypeRegistry, cs
|
|
|
3
3
|
export { apply, validate, search, read, validateOperations, operation, tools } from './tools';
|
|
4
4
|
export { computeVersion, buildAgentGuide } from './helpers';
|
|
5
5
|
export { createHttpPreviewClient } from './previewClient';
|
|
6
|
+
export { createLocalScreenshotClient, resolveLocalBrowser } from './localScreenshotClient';
|
|
6
7
|
export { createHttpScreenshotClient } from './screenshotClient';
|
|
7
8
|
export type { McpRequestOptions } from './handler';
|
|
8
9
|
export type { HttpPreviewClientConfig } from './previewClient';
|
|
10
|
+
export type { LocalScreenshotClientConfig } from './localScreenshotClient';
|
|
9
11
|
export type { HttpScreenshotClientConfig } from './screenshotClient';
|
|
10
12
|
export type { McpServerContext } from './server';
|
|
11
13
|
export type { ApplyInput, WriteResponse, Persisters, SearchInput, ReadInput, ReadResponse, ValidateInput, Operation, ToolDef, ToolContext } from './tools';
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { ScreenshotClient } from './types';
|
|
2
|
+
/**
|
|
3
|
+
* A capture that needs no service to be running.
|
|
4
|
+
*
|
|
5
|
+
* The HTTP client beside this one talks to a dedicated browser pod, which is the right answer in a cluster: the SSR
|
|
6
|
+
* and MCP images stay small, and the one workload carrying Chromium is separate and disposable. It is the wrong
|
|
7
|
+
* answer for everybody else. Somebody self-hosting `@plitzi/sdk-server` who wants to look at what they just changed
|
|
8
|
+
* had to stand up a second service first, and the loop that was supposed to take a second took an afternoon.
|
|
9
|
+
*
|
|
10
|
+
* So the browser is resolved at RUN time from whatever the host already has — Playwright, then Puppeteer — and the
|
|
11
|
+
* whole thing is absent when it has neither. Nothing is added to this package's dependency tree, nothing is
|
|
12
|
+
* downloaded on install, and a deployment that never captures anything never loads a line of it.
|
|
13
|
+
*/
|
|
14
|
+
/** The narrow slice of a browser driver this uses. Both drivers satisfy it; neither is imported at build time. */
|
|
15
|
+
type Page = {
|
|
16
|
+
goto: (url: string, options?: Record<string, unknown>) => Promise<unknown>;
|
|
17
|
+
setViewportSize?: (size: {
|
|
18
|
+
width: number;
|
|
19
|
+
height: number;
|
|
20
|
+
}) => Promise<void>;
|
|
21
|
+
setViewport?: (size: {
|
|
22
|
+
width: number;
|
|
23
|
+
height: number;
|
|
24
|
+
}) => Promise<void>;
|
|
25
|
+
evaluate: <T>(fn: () => T) => Promise<T>;
|
|
26
|
+
screenshot: (options: Record<string, unknown>) => Promise<Buffer | Uint8Array>;
|
|
27
|
+
};
|
|
28
|
+
type Browser = {
|
|
29
|
+
newPage: () => Promise<Page>;
|
|
30
|
+
close: () => Promise<void>;
|
|
31
|
+
};
|
|
32
|
+
type Launcher = {
|
|
33
|
+
launch: (options?: Record<string, unknown>) => Promise<Browser>;
|
|
34
|
+
};
|
|
35
|
+
/** Which driver this host has, if any. Playwright first: it is what the visual suites already install. */
|
|
36
|
+
export declare const resolveLocalBrowser: () => Promise<Launcher | undefined>;
|
|
37
|
+
export type LocalScreenshotClientConfig = {
|
|
38
|
+
/** SSR base the browser navigates to; the page path and the preview token are appended. */
|
|
39
|
+
renderBaseUrl: string;
|
|
40
|
+
/** A dev certificate is signed by a local CA no browser has a reason to know about. */
|
|
41
|
+
ignoreHttpsErrors?: boolean;
|
|
42
|
+
};
|
|
43
|
+
/**
|
|
44
|
+
* A `ScreenshotClient` backed by a browser on this machine, or `undefined` when there is none.
|
|
45
|
+
*
|
|
46
|
+
* Undefined rather than a client that fails on every call: "no browser here" is a fact about the deployment that
|
|
47
|
+
* whoever wires the tools should act on once — by not offering the tool — instead of a failure every caller has to
|
|
48
|
+
* interpret. It is the same shape the HTTP client returns, so the two are interchangeable at the call site.
|
|
49
|
+
*/
|
|
50
|
+
export declare const createLocalScreenshotClient: ({ renderBaseUrl, ignoreHttpsErrors }: LocalScreenshotClientConfig) => Promise<ScreenshotClient | undefined>;
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { PREVIEW_TOKEN_PARAM } from "@plitzi/sdk-server/kernel";
|
|
2
|
+
//#region src/modules/mcp/localScreenshotClient.ts
|
|
3
|
+
/**
|
|
4
|
+
* Grow the window to whatever actually scrolls before shooting.
|
|
5
|
+
*
|
|
6
|
+
* The SDK renders into `.plitzi-sdk` with an inner `overflow: auto` column, so the DOCUMENT never scrolls and a
|
|
7
|
+
* driver's `fullPage` has nothing to extend — it returns exactly one viewport of a page that may be ten. The height
|
|
8
|
+
* has to come from the scrolling descendant, and the window has to be made that tall before the shot.
|
|
9
|
+
*/
|
|
10
|
+
var CONTENT_HEIGHT = () => {
|
|
11
|
+
const scrollers = [...document.querySelectorAll("*")].filter((element) => element.scrollHeight > element.clientHeight + 1 && element.clientHeight > 0);
|
|
12
|
+
return Math.max(document.documentElement.scrollHeight, ...scrollers.map((element) => element.scrollHeight));
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* Wait for the web fonts before shooting.
|
|
16
|
+
*
|
|
17
|
+
* `networkidle0` says the requests are done; it does not say the faces are USABLE, and a page captured in between
|
|
18
|
+
* is a picture of the fallback — different metrics, different line breaks, a thumbnail that does not look like the
|
|
19
|
+
* space it is of. The race is only ever lost by a hair, so a short ceiling is enough: a font that has not arrived
|
|
20
|
+
* by then was not going to make the shot anyway, and a picture in a fallback beats no picture at all.
|
|
21
|
+
*/
|
|
22
|
+
var FONTS_READY = () => Promise.race([document.fonts.ready, new Promise((resolve) => setTimeout(resolve, 3e3))]);
|
|
23
|
+
/** Guard against a runaway page turning one screenshot into a hundred-megabyte PNG. */
|
|
24
|
+
var MAX_HEIGHT = 8e3;
|
|
25
|
+
var importDriver = async (name) => {
|
|
26
|
+
try {
|
|
27
|
+
const module = await import(
|
|
28
|
+
/* @vite-ignore */
|
|
29
|
+
name
|
|
30
|
+
);
|
|
31
|
+
return module.chromium ?? module.default;
|
|
32
|
+
} catch {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
/** Which driver this host has, if any. Playwright first: it is what the visual suites already install. */
|
|
37
|
+
var resolveLocalBrowser = async () => await importDriver("playwright") ?? await importDriver("puppeteer");
|
|
38
|
+
var setViewport = async (page, size) => {
|
|
39
|
+
await (page.setViewportSize ? page.setViewportSize(size) : page.setViewport?.(size));
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* A `ScreenshotClient` backed by a browser on this machine, or `undefined` when there is none.
|
|
43
|
+
*
|
|
44
|
+
* Undefined rather than a client that fails on every call: "no browser here" is a fact about the deployment that
|
|
45
|
+
* whoever wires the tools should act on once — by not offering the tool — instead of a failure every caller has to
|
|
46
|
+
* interpret. It is the same shape the HTTP client returns, so the two are interchangeable at the call site.
|
|
47
|
+
*/
|
|
48
|
+
var createLocalScreenshotClient = async ({ renderBaseUrl, ignoreHttpsErrors = true }) => {
|
|
49
|
+
const driver = await resolveLocalBrowser();
|
|
50
|
+
if (!driver) return;
|
|
51
|
+
return { async capture({ pagePath, token, viewports, fullPage = true }) {
|
|
52
|
+
const url = new URL(pagePath, renderBaseUrl);
|
|
53
|
+
if (token) url.searchParams.set(PREVIEW_TOKEN_PARAM, token);
|
|
54
|
+
/**
|
|
55
|
+
* One browser per capture, closed in `finally`.
|
|
56
|
+
*
|
|
57
|
+
* A pooled instance would save a second per call and cost a process that outlives every request, a page that
|
|
58
|
+
* leaks when a capture throws, and a crashed browser that every later call inherits. This runs while somebody
|
|
59
|
+
* is waiting for one picture, so the second is worth not owning any of that.
|
|
60
|
+
*/
|
|
61
|
+
let browser;
|
|
62
|
+
try {
|
|
63
|
+
browser = await driver.launch({
|
|
64
|
+
args: ["--no-sandbox"],
|
|
65
|
+
...ignoreHttpsErrors ? { ignoreHTTPSErrors: true } : {}
|
|
66
|
+
});
|
|
67
|
+
const images = [];
|
|
68
|
+
for (const viewport of viewports) {
|
|
69
|
+
const page = await browser.newPage();
|
|
70
|
+
await setViewport(page, viewport);
|
|
71
|
+
await page.goto(url.toString(), { waitUntil: "networkidle0" });
|
|
72
|
+
await page.evaluate(FONTS_READY);
|
|
73
|
+
if (fullPage) {
|
|
74
|
+
const height = Math.min(await page.evaluate(CONTENT_HEIGHT), MAX_HEIGHT);
|
|
75
|
+
if (height > viewport.height) await setViewport(page, {
|
|
76
|
+
width: viewport.width,
|
|
77
|
+
height
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
const shot = await page.screenshot({
|
|
81
|
+
type: "png",
|
|
82
|
+
fullPage
|
|
83
|
+
});
|
|
84
|
+
images.push({
|
|
85
|
+
label: viewport.label,
|
|
86
|
+
mimeType: "image/png",
|
|
87
|
+
data: Buffer.from(shot).toString("base64")
|
|
88
|
+
});
|
|
89
|
+
}
|
|
90
|
+
return {
|
|
91
|
+
ok: true,
|
|
92
|
+
images
|
|
93
|
+
};
|
|
94
|
+
} catch (err) {
|
|
95
|
+
return {
|
|
96
|
+
ok: false,
|
|
97
|
+
error: "SCREENSHOT_FAILED",
|
|
98
|
+
message: `Local browser capture failed: ${String(err)}`
|
|
99
|
+
};
|
|
100
|
+
} finally {
|
|
101
|
+
await browser?.close();
|
|
102
|
+
}
|
|
103
|
+
} };
|
|
104
|
+
};
|
|
105
|
+
//#endregion
|
|
106
|
+
export { createLocalScreenshotClient, resolveLocalBrowser };
|
|
@@ -106,7 +106,7 @@ var rewriteSchema = (schema, proxy, warnings) => {
|
|
|
106
106
|
if (element.definition.type !== FETCHING_TYPE || typeof query !== "string" || !isRemote(query)) continue;
|
|
107
107
|
const blocked = unproxyableFetch(attributes);
|
|
108
108
|
if (blocked) {
|
|
109
|
-
warnings.push(`The ${FETCHING_TYPE} "${element.
|
|
109
|
+
warnings.push(`The ${FETCHING_TYPE} "${element.id}" calls its endpoint directly because ${blocked}, so that request is subject to the network policy of the surface it renders in, and to the CORS headers of the API, and may not run. A plain GET with no headers is fetched by the widget server instead, which always works.`);
|
|
110
110
|
continue;
|
|
111
111
|
}
|
|
112
112
|
if (!isGranted(query, proxy)) attributes.query = grantUrl(query, proxy, "data");
|
|
@@ -121,6 +121,20 @@ var rewriteStyle = (style, proxy) => {
|
|
|
121
121
|
if (item.cache.includes("url(")) item.cache = rewriteText(item.cache, proxy);
|
|
122
122
|
}
|
|
123
123
|
if (style.cache.includes("url(")) style.cache = rewriteText(style.cache, proxy);
|
|
124
|
+
/**
|
|
125
|
+
* The font manifest, whose URLs are not in the CSS: the resolver turns them into links and `@font-face` blocks
|
|
126
|
+
* at render time, so the widget fetches them itself and a host that enforces a strict CSP would block them.
|
|
127
|
+
*
|
|
128
|
+
* `google` entries are left alone and cannot be otherwise: the resolver builds one `css2` URL from the families
|
|
129
|
+
* at render time, and which files that stylesheet then names is Google's answer, not something written here.
|
|
130
|
+
* They are also the one external origin no host blocks. Uploaded faces are paths, resolved against whichever
|
|
131
|
+
* deployment renders them, so there is nothing to rewrite either.
|
|
132
|
+
*/
|
|
133
|
+
for (const font of style.fonts ?? []) {
|
|
134
|
+
if (font.source !== "remote") continue;
|
|
135
|
+
if (font.stylesheet) font.stylesheet = toProxy(font.stylesheet, proxy);
|
|
136
|
+
for (const file of font.files ?? []) file.url = toProxy(file.url, proxy);
|
|
137
|
+
}
|
|
124
138
|
};
|
|
125
139
|
/** Point everything an authored widget loads from outside — images, media, fonts, the data an apiContainer fetches
|
|
126
140
|
* and the URLs its interactions swap in later — at this server's endpoint, in place. The AGENT never sees this: it
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Space } from '../helpers';
|
|
2
|
+
import { Env, ResourceEnvelope } from '../types';
|
|
3
|
+
export declare const actionSummaries: (space: Space) => {
|
|
4
|
+
actions: {
|
|
5
|
+
enabled: boolean;
|
|
6
|
+
triggers: {
|
|
7
|
+
input: Record<string, import('@plitzi/sdk-shared').ActionField>;
|
|
8
|
+
access?: import('@plitzi/sdk-shared').ActionAccess | undefined;
|
|
9
|
+
kind: string;
|
|
10
|
+
enabled: boolean;
|
|
11
|
+
}[];
|
|
12
|
+
output: Record<string, import('@plitzi/sdk-shared').ActionField> | undefined;
|
|
13
|
+
description?: string | undefined;
|
|
14
|
+
ref: string;
|
|
15
|
+
name: string;
|
|
16
|
+
}[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Action reads: the space's action listing and one document in full.
|
|
20
|
+
*
|
|
21
|
+
* The item read returns the document verbatim, steps included. That is server-side state a browser never sees, and
|
|
22
|
+
* an agent authoring one has to read back what it wrote — the document holds no secret either way: a step NAMES a
|
|
23
|
+
* credential, it does not carry one.
|
|
24
|
+
*/
|
|
25
|
+
export declare const readActionResource: (space: Space, env: Env, uri: string) => ResourceEnvelope<unknown> | null | undefined;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { findActionEntry } from "../helpers/space.js";
|
|
2
|
+
import { actionTasksUri, actionUri, actionsUri, afterPrefix } from "../helpers/uris.js";
|
|
3
|
+
import { envelope } from "./envelope.js";
|
|
4
|
+
import { actionTriggers, isActionEnabled, triggerAccess, triggerInput } from "@plitzi/sdk-shared/actions";
|
|
5
|
+
//#region src/modules/mcp/resources/actions.ts
|
|
6
|
+
/**
|
|
7
|
+
* What a `runServerAction` step needs to know without opening the flow: what the action is called, whether it can
|
|
8
|
+
* run at all, and — per way in — who may use it and what it takes. The steps themselves are one read away: they
|
|
9
|
+
* are the longest part and the part a caller never has to know.
|
|
10
|
+
*
|
|
11
|
+
* Derived from the trigger STEPS rather than read off the document, because that is where they live now: an action
|
|
12
|
+
* open to a signed webhook and to a session-only page call says so once per entry point.
|
|
13
|
+
*/
|
|
14
|
+
var summarize = (entry) => {
|
|
15
|
+
const { document } = entry;
|
|
16
|
+
const triggers = actionTriggers(document).map((node) => {
|
|
17
|
+
const params = node.params;
|
|
18
|
+
return {
|
|
19
|
+
kind: node.action,
|
|
20
|
+
enabled: node.enabled,
|
|
21
|
+
...params.access === void 0 ? {} : { access: triggerAccess(params) },
|
|
22
|
+
input: triggerInput(params)
|
|
23
|
+
};
|
|
24
|
+
});
|
|
25
|
+
return {
|
|
26
|
+
ref: entry.id,
|
|
27
|
+
name: document.name,
|
|
28
|
+
...document.description === void 0 ? {} : { description: document.description },
|
|
29
|
+
enabled: isActionEnabled(document),
|
|
30
|
+
triggers,
|
|
31
|
+
output: document.output
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
var actionSummaries = (space) => ({ actions: space.actions.map(summarize) });
|
|
35
|
+
/**
|
|
36
|
+
* Action reads: the space's action listing and one document in full.
|
|
37
|
+
*
|
|
38
|
+
* The item read returns the document verbatim, steps included. That is server-side state a browser never sees, and
|
|
39
|
+
* an agent authoring one has to read back what it wrote — the document holds no secret either way: a step NAMES a
|
|
40
|
+
* credential, it does not carry one.
|
|
41
|
+
*/
|
|
42
|
+
var readActionResource = (space, env, uri) => {
|
|
43
|
+
if (uri === actionsUri(env)) return envelope(actionSummaries(space));
|
|
44
|
+
if (uri === actionTasksUri(env)) return envelope({ tasks: space.actionTasks ?? [] });
|
|
45
|
+
const ref = afterPrefix(uri, actionUri(env, ""));
|
|
46
|
+
if (ref === void 0) return;
|
|
47
|
+
const entry = findActionEntry(space, ref);
|
|
48
|
+
return entry ? envelope({
|
|
49
|
+
ref: entry.id,
|
|
50
|
+
document: entry.document
|
|
51
|
+
}) : null;
|
|
52
|
+
};
|
|
53
|
+
//#endregion
|
|
54
|
+
export { actionSummaries, readActionResource };
|
|
@@ -2,5 +2,5 @@ import { Env } from '../types';
|
|
|
2
2
|
export declare const canonicalUri: (env: Env, uri: string) => string;
|
|
3
3
|
/** Teachable message for a URI that read as null. Distinguishes a well-formed URI whose ref does not resolve (the
|
|
4
4
|
* resource may be stale/deleted) from a URI whose shape matches no template at all (malformed — echo the valid
|
|
5
|
-
* templates so the agent stops hand-building URIs).
|
|
5
|
+
* templates so the agent stops hand-building URIs). */
|
|
6
6
|
export declare const resourceErrorMessage: (env: Env, uri: string) => string;
|
|
@@ -11,7 +11,7 @@ var canonicalUri = (env, uri) => {
|
|
|
11
11
|
};
|
|
12
12
|
/** Teachable message for a URI that read as null. Distinguishes a well-formed URI whose ref does not resolve (the
|
|
13
13
|
* resource may be stale/deleted) from a URI whose shape matches no template at all (malformed — echo the valid
|
|
14
|
-
* templates so the agent stops hand-building URIs).
|
|
14
|
+
* templates so the agent stops hand-building URIs). */
|
|
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({
|