@perkyzz/emvb 0.9.0 → 1.0.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/README.md +1 -1
- package/package.json +2 -2
- package/src/admin/agents-api.ts +45 -0
- package/src/admin/editor/A11yCopilot.tsx +1 -1
- package/src/admin/editor/Editor.tsx +297 -248
- package/src/admin/editor/Timeline.tsx +2 -1
- package/src/admin/editor/TopBar.tsx +4 -2
- package/src/admin/editor/canvas/CanvasFrame.tsx +2 -2
- package/src/admin/editor/canvas/DeviceBar.tsx +17 -9
- package/src/admin/editor/canvas/canvas-scale.ts +2 -2
- package/src/admin/editor/canvas/use-canvas-session.ts +2 -2
- package/src/admin/editor/co-design.ts +190 -0
- package/src/admin/editor/dnd/new-element.ts +26 -4
- package/src/admin/editor/editor-chrome.tsx +3 -3
- package/src/admin/editor/editor-commands.ts +8 -3
- package/src/admin/editor/element-chrome.ts +3 -1
- package/src/admin/editor/extension-manifests.ts +20 -0
- package/src/admin/editor/extensions/ExtensionPanels.tsx +26 -0
- package/src/admin/editor/extensions-context.tsx +27 -0
- package/src/admin/editor/feature-css.ts +17 -0
- package/src/admin/editor/palette-items.ts +2 -2
- package/src/admin/editor/panels/AddPanel.tsx +31 -1
- package/src/admin/editor/panels/AgentRequestBox.tsx +116 -0
- package/src/admin/editor/panels/ClassesSection.tsx +9 -6
- package/src/admin/editor/panels/CoDesignPanel.tsx +170 -0
- package/src/admin/editor/panels/ColorControl.tsx +2 -2
- package/src/admin/editor/panels/ElementPanel.tsx +49 -14
- package/src/admin/editor/panels/LanguagesSection.tsx +152 -0
- package/src/admin/editor/panels/LayersPanel.tsx +10 -6
- package/src/admin/editor/panels/LeftPanel.tsx +33 -5
- package/src/admin/editor/panels/PageSettings.tsx +4 -0
- package/src/admin/editor/panels/SettingsPanel.tsx +21 -2
- package/src/admin/editor/panels/SiteStylesDrawer.tsx +7 -7
- package/src/admin/editor/panels/settings/BackgroundControls.tsx +72 -15
- package/src/admin/editor/panels/settings/BackgroundFill.tsx +8 -6
- package/src/admin/editor/panels/settings/BoxControl.tsx +5 -5
- package/src/admin/editor/panels/settings/EffectsControls.tsx +104 -9
- package/src/admin/editor/panels/settings/FieldControl.tsx +9 -3
- package/src/admin/editor/panels/settings/IconControls.tsx +14 -11
- package/src/admin/editor/panels/settings/LengthRow.tsx +27 -16
- package/src/admin/editor/panels/settings/LoopControl.tsx +269 -0
- package/src/admin/editor/panels/settings/LoopItemBindControl.tsx +1 -1
- package/src/admin/editor/panels/settings/MotionControl.tsx +12 -11
- package/src/admin/editor/panels/settings/QueryStyleRows.tsx +7 -4
- package/src/admin/editor/panels/settings/StyleRow.tsx +113 -13
- package/src/admin/editor/panels/settings/TextMarksControl.tsx +247 -0
- package/src/admin/editor/panels/settings/VariableBinding.tsx +2 -2
- package/src/admin/editor/panels/settings/background-mode.ts +14 -11
- package/src/admin/editor/panels/settings/box-link-name.ts +1 -1
- package/src/admin/editor/panels/settings/box-sides.ts +22 -14
- package/src/admin/editor/panels/settings/heading-warning.ts +5 -1
- package/src/admin/editor/panels/settings/length-units.ts +53 -1
- package/src/admin/editor/panels/settings/query-style.ts +3 -3
- package/src/admin/editor/panels/settings/style-sections.ts +51 -10
- package/src/admin/editor/panels/style-target.ts +9 -7
- package/src/admin/editor/presence.ts +60 -0
- package/src/admin/editor/store.ts +6 -2
- package/src/admin/editor/useCoDesign.ts +177 -0
- package/src/admin/editor/useEditorCommands.ts +4 -4
- package/src/admin/editor/useExtensions.ts +45 -0
- package/src/admin/editor/useNodeActions.ts +15 -6
- package/src/admin/editor/useProposals.ts +81 -0
- package/src/admin/languages-api.ts +61 -0
- package/src/admin/pages/AgentSetup.tsx +148 -0
- package/src/admin/pages/AgentsPage.tsx +9 -26
- package/src/admin/pages/CreateDialog.tsx +15 -0
- package/src/admin/pages/ImportButton.tsx +18 -0
- package/src/admin/pages/ImportElementorDialog.tsx +669 -0
- package/src/admin/pages/ImportPageLinks.tsx +86 -0
- package/src/admin/pages/PageList.tsx +15 -1
- package/src/admin/pages/ThemePartList.tsx +15 -1
- package/src/admin/pages/section-head.tsx +27 -0
- package/src/admin/proposals-api.ts +91 -0
- package/src/admin/ui.ts +39 -2
- package/src/astro/content-port.ts +14 -1
- package/src/astro/resolve-theme.ts +14 -1
- package/src/astro/resolve.ts +89 -2
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +44 -14
- package/src/core/arrange.ts +5 -1
- package/src/core/bounded-array.ts +31 -0
- package/src/core/clipboard.ts +9 -0
- package/src/core/contract.ts +285 -0
- package/src/core/css/generate.ts +89 -20
- package/src/core/css/trace.ts +18 -9
- package/src/core/css-keywords.ts +51 -1
- package/src/core/design/cascade.ts +12 -9
- package/src/core/design/classes.ts +4 -5
- package/src/core/design/devices.ts +13 -13
- package/src/core/design/states.ts +5 -3
- package/src/core/design/transfer.ts +5 -0
- package/src/core/design/variables.ts +17 -4
- package/src/core/elements/dynamic-elements.ts +3 -3
- package/src/core/elements/index.ts +73 -9
- package/src/core/extensions/define.ts +13 -0
- package/src/core/extensions/index.ts +41 -0
- package/src/core/extensions/namespace.ts +82 -0
- package/src/core/extensions/normalize.ts +141 -0
- package/src/core/extensions/placeholder.ts +41 -0
- package/src/core/extensions/registry.ts +94 -0
- package/src/core/extensions/render-ext.ts +118 -0
- package/src/core/extensions/safe-nodes.ts +93 -0
- package/src/core/extensions/schema.ts +112 -0
- package/src/core/extensions/types.ts +159 -0
- package/src/core/forms/binding.ts +1 -1
- package/src/core/history/diff.ts +1 -1
- package/src/core/import/elementor/atomic.ts +1595 -0
- package/src/core/import/elementor/classes.ts +127 -0
- package/src/core/import/elementor/context.ts +429 -0
- package/src/core/import/elementor/counter-steps.ts +72 -0
- package/src/core/import/elementor/css.ts +445 -0
- package/src/core/import/elementor/html.ts +500 -0
- package/src/core/import/elementor/index.ts +949 -0
- package/src/core/import/elementor/inline-marks.ts +81 -0
- package/src/core/import/elementor/snapshots.ts +48 -0
- package/src/core/import/elementor/style.ts +409 -0
- package/src/core/import/elementor/values.ts +241 -0
- package/src/core/import/elementor/widgets.ts +1897 -0
- package/src/core/index.ts +82 -0
- package/src/core/json-schema.ts +107 -0
- package/src/core/limits.ts +19 -0
- package/src/core/migrate/index.ts +6 -1
- package/src/core/migrate/v18.ts +222 -0
- package/src/core/perf/meter.ts +5 -5
- package/src/core/proposals-safety.ts +102 -0
- package/src/core/proposals.ts +357 -0
- package/src/core/recipes/index.ts +2 -2
- package/src/core/render/extras.ts +3 -3
- package/src/core/render/index.ts +140 -20
- package/src/core/render/loop.ts +1 -1
- package/src/core/render/section.ts +4 -4
- package/src/core/render/vnode.ts +1 -1
- package/src/core/sanitize/css.ts +125 -10
- package/src/core/sanitize/motion.ts +116 -0
- package/src/core/saved-sections.ts +6 -0
- package/src/core/schema/descriptors.ts +3 -1
- package/src/core/schema/design.ts +2 -1
- package/src/core/schema/layout.ts +82 -14
- package/src/core/schema/style.ts +251 -114
- package/src/core/text-marks.ts +227 -0
- package/src/core/theme/dynamic.ts +9 -4
- package/src/core/theme/float.ts +1 -0
- package/src/core/theme/popup-rules.ts +17 -1
- package/src/core/translatable.ts +34 -0
- package/src/core/validate.ts +13 -1
- package/src/index.ts +24 -0
- package/src/mcp/errors.ts +3 -1
- package/src/mcp/ports.ts +67 -0
- package/src/mcp/prompts.ts +1 -11
- package/src/mcp/proposals.ts +281 -0
- package/src/mcp/read.ts +10 -9
- package/src/mcp/tools.ts +71 -3
- package/src/mcp/write.ts +66 -11
- package/src/server/agent-settings.ts +5 -1
- package/src/server/mcp-routes.ts +15 -0
- package/src/server/plugin.ts +35 -2
- package/src/server/presence.ts +78 -0
- package/src/server/proposals.ts +261 -0
- package/src/server/requests.ts +196 -0
- package/src/server/tools-served.ts +45 -0
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import type { DesignSystem } from "../../core/schema/design.ts";
|
|
3
|
+
import {
|
|
4
|
+
cancelRequest,
|
|
5
|
+
createRequest,
|
|
6
|
+
recordAccepted,
|
|
7
|
+
withdrawProposal,
|
|
8
|
+
type PendingProposal,
|
|
9
|
+
} from "../proposals-api.ts";
|
|
10
|
+
import { ApiError, type Fetcher } from "../api.ts";
|
|
11
|
+
import { acceptOps, ghostCss, ghostOf, type EditorBase, type Ghost } from "./co-design.ts";
|
|
12
|
+
import type { EditorAction, EditorState } from "./store.ts";
|
|
13
|
+
import { useProposals, type ProposalsState } from "./useProposals.ts";
|
|
14
|
+
|
|
15
|
+
export type Decision = "accepted" | "rejected";
|
|
16
|
+
|
|
17
|
+
export type CoDesign = {
|
|
18
|
+
proposals: ProposalsState;
|
|
19
|
+
/** Per proposal id, per op index. Undecided ops are pending. */
|
|
20
|
+
decisions: Record<string, Record<number, Decision>>;
|
|
21
|
+
pending: (p: PendingProposal) => number[];
|
|
22
|
+
accept: (p: PendingProposal, indexes: readonly number[]) => void;
|
|
23
|
+
reject: (p: PendingProposal, indexes: readonly number[]) => void;
|
|
24
|
+
/** The proposal shown as a ghost on the canvas, if any. */
|
|
25
|
+
previewId: string | null;
|
|
26
|
+
setPreviewId: (id: string | null) => void;
|
|
27
|
+
ghost: (Ghost & { css: string }) | null;
|
|
28
|
+
/** Why the last accept was refused, in the editor's words. */
|
|
29
|
+
error: string | null;
|
|
30
|
+
clearError: () => void;
|
|
31
|
+
/** Changes accepted since the last save. */
|
|
32
|
+
unsaved: number;
|
|
33
|
+
/** W-931: sends a request to the person's agent; resolves to an error message, or null. */
|
|
34
|
+
ask: (prompt: string) => Promise<string | null>;
|
|
35
|
+
cancel: (requestId: string) => Promise<void>;
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
/** The editor state as a proposal base, with the style revision the server compares against. */
|
|
39
|
+
const editorBase = (state: EditorState): EditorBase => ({
|
|
40
|
+
rev: state.rev,
|
|
41
|
+
layout: state.page.layout,
|
|
42
|
+
design: state.design,
|
|
43
|
+
designRevision: state.designRevision ?? state.publishedRevision ?? null,
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const stalePage =
|
|
47
|
+
"This proposal was made for an earlier version of the page. Ask the agent to propose again.";
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* W-930: review state for the co-design panel. Accepted page changes are one undoable edit each
|
|
51
|
+
* (`apply-arranged`); accepted class and variable changes go through the normal style draft save.
|
|
52
|
+
* A proposal is withdrawn once every change in it is decided, and the next Save draft after any
|
|
53
|
+
* accept is labelled "Via agent" in the timeline.
|
|
54
|
+
*/
|
|
55
|
+
export function useCoDesign({
|
|
56
|
+
fetcher,
|
|
57
|
+
collection,
|
|
58
|
+
state,
|
|
59
|
+
dispatch,
|
|
60
|
+
changeDesign,
|
|
61
|
+
onError,
|
|
62
|
+
enabled = true,
|
|
63
|
+
}: {
|
|
64
|
+
fetcher: Fetcher;
|
|
65
|
+
collection: string;
|
|
66
|
+
state: EditorState;
|
|
67
|
+
dispatch: (action: EditorAction) => void;
|
|
68
|
+
changeDesign: (design: DesignSystem) => Promise<unknown>;
|
|
69
|
+
onError: (message: string) => void;
|
|
70
|
+
/** Off in field mode: agents propose to EmVB pages only. */
|
|
71
|
+
enabled?: boolean;
|
|
72
|
+
}): CoDesign {
|
|
73
|
+
const proposals = useProposals(fetcher, collection, state.id, enabled);
|
|
74
|
+
const [decisions, setDecisions] = React.useState<CoDesign["decisions"]>({});
|
|
75
|
+
const [previewId, setPreviewId] = React.useState<string | null>(null);
|
|
76
|
+
const [error, setError] = React.useState<string | null>(null);
|
|
77
|
+
const [unsaved, setUnsaved] = React.useState(0);
|
|
78
|
+
const latest = React.useRef(state);
|
|
79
|
+
latest.current = state;
|
|
80
|
+
|
|
81
|
+
const pending = React.useCallback(
|
|
82
|
+
(p: PendingProposal) =>
|
|
83
|
+
p.proposal.ops.map((_, i) => i).filter((i) => decisions[p.id]?.[i] === undefined),
|
|
84
|
+
[decisions],
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
const decide = (p: PendingProposal, indexes: readonly number[], decision: Decision) => {
|
|
88
|
+
const next = { ...decisions[p.id] };
|
|
89
|
+
for (const i of indexes) next[i] = decision;
|
|
90
|
+
setDecisions((all) => ({ ...all, [p.id]: next }));
|
|
91
|
+
if (p.proposal.ops.every((_, i) => next[i] !== undefined)) {
|
|
92
|
+
if (previewId === p.id) setPreviewId(null);
|
|
93
|
+
const decided = Object.values(next);
|
|
94
|
+
withdrawProposal(fetcher, p.id, {
|
|
95
|
+
accepted: decided.filter((d) => d === "accepted").length,
|
|
96
|
+
rejected: decided.filter((d) => d === "rejected").length,
|
|
97
|
+
}).then(proposals.refresh, () => undefined);
|
|
98
|
+
}
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const accept = (p: PendingProposal, indexes: readonly number[]) => {
|
|
102
|
+
const current = latest.current;
|
|
103
|
+
const result = acceptOps(editorBase(current), p.proposal, indexes);
|
|
104
|
+
if (!result.ok) {
|
|
105
|
+
setError(result.code === "STALE_BASE" ? stalePage : result.reason);
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
setError(null);
|
|
109
|
+
dispatch({
|
|
110
|
+
type: "apply-arranged",
|
|
111
|
+
layout: result.layout,
|
|
112
|
+
selected: current.selectedId ?? result.layout.root.id,
|
|
113
|
+
});
|
|
114
|
+
if (result.designChanged) {
|
|
115
|
+
changeDesign(result.design).catch((e: unknown) =>
|
|
116
|
+
onError(e instanceof Error ? e.message : "Couldn't save the accepted site styles."),
|
|
117
|
+
);
|
|
118
|
+
}
|
|
119
|
+
setUnsaved((n) => n + indexes.length);
|
|
120
|
+
decide(p, indexes, "accepted");
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
const reject = (p: PendingProposal, indexes: readonly number[]) => {
|
|
124
|
+
setError(null);
|
|
125
|
+
decide(p, indexes, "rejected");
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// The next save after an accept is a normal version, labelled "Via agent" (W-930).
|
|
129
|
+
const savedRev = React.useRef(state.rev);
|
|
130
|
+
const unsavedRef = React.useRef(unsaved);
|
|
131
|
+
unsavedRef.current = unsaved;
|
|
132
|
+
React.useEffect(() => {
|
|
133
|
+
if (state.rev === savedRev.current) return;
|
|
134
|
+
savedRev.current = state.rev;
|
|
135
|
+
const accepted = unsavedRef.current;
|
|
136
|
+
if (accepted <= 0) return;
|
|
137
|
+
setUnsaved(0);
|
|
138
|
+
recordAccepted(fetcher, collection, state.id, accepted).catch(() => undefined);
|
|
139
|
+
}, [state.rev, fetcher, collection, state.id]);
|
|
140
|
+
|
|
141
|
+
const previewed = proposals.items.find((p) => p.id === previewId) ?? null;
|
|
142
|
+
const ghost = React.useMemo(() => {
|
|
143
|
+
if (!previewed) return null;
|
|
144
|
+
const g = ghostOf(editorBase(state), previewed.proposal, pending(previewed));
|
|
145
|
+
return g ? { ...g, css: ghostCss(g) } : null;
|
|
146
|
+
}, [previewed, state, pending]);
|
|
147
|
+
|
|
148
|
+
const ask = async (prompt: string) => {
|
|
149
|
+
try {
|
|
150
|
+
await createRequest(fetcher, collection, state.id, prompt);
|
|
151
|
+
proposals.refresh();
|
|
152
|
+
return null;
|
|
153
|
+
} catch (e) {
|
|
154
|
+
return e instanceof ApiError ? e.message : "Couldn't send the request. Try again.";
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
const cancel = async (requestId: string) => {
|
|
158
|
+
await cancelRequest(fetcher, requestId).catch(() => undefined);
|
|
159
|
+
proposals.refresh();
|
|
160
|
+
};
|
|
161
|
+
|
|
162
|
+
return {
|
|
163
|
+
ask,
|
|
164
|
+
cancel,
|
|
165
|
+
proposals,
|
|
166
|
+
decisions,
|
|
167
|
+
pending,
|
|
168
|
+
accept,
|
|
169
|
+
reject,
|
|
170
|
+
previewId: previewed ? previewId : null,
|
|
171
|
+
setPreviewId,
|
|
172
|
+
ghost,
|
|
173
|
+
error,
|
|
174
|
+
clearError: () => setError(null),
|
|
175
|
+
unsaved,
|
|
176
|
+
};
|
|
177
|
+
}
|
|
@@ -5,7 +5,7 @@ import {
|
|
|
5
5
|
DEVICE_PREVIEW_PX,
|
|
6
6
|
mergeDesign,
|
|
7
7
|
type DesignSystem,
|
|
8
|
-
type
|
|
8
|
+
type Device,
|
|
9
9
|
} from "../../core/index.ts";
|
|
10
10
|
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../../constants.ts";
|
|
11
11
|
import { ApiError, type Fetcher } from "../api.ts";
|
|
@@ -19,13 +19,13 @@ const publicPath = (pattern: string | null | undefined, slug: string) =>
|
|
|
19
19
|
(pattern || "/{slug}").replace("{slug}", encodeURIComponent(slug));
|
|
20
20
|
|
|
21
21
|
/** Window heights for the sized Tablet and Mobile previews (W-158); widths are the canvas's. */
|
|
22
|
-
const PREVIEW_HEIGHT = { tablet: 1024, mobile: 844 } as const;
|
|
22
|
+
const PREVIEW_HEIGHT = { laptop: 800, tablet: 1024, mobile: 844 } as const;
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
25
|
* `window.open` features for a device preview (W-158): Desktop is an ordinary tab; Tablet and
|
|
26
26
|
* Mobile open a window whose page area is the device width, so the page's own media queries apply.
|
|
27
27
|
*/
|
|
28
|
-
export function previewWindowFeatures(device:
|
|
28
|
+
export function previewWindowFeatures(device: Device): string | undefined {
|
|
29
29
|
if (device === "desktop") return undefined;
|
|
30
30
|
return `popup,width=${DEVICE_PREVIEW_PX[device]},height=${PREVIEW_HEIGHT[device]}`;
|
|
31
31
|
}
|
|
@@ -137,7 +137,7 @@ export function useEditorCommands({
|
|
|
137
137
|
});
|
|
138
138
|
};
|
|
139
139
|
|
|
140
|
-
const preview = (device:
|
|
140
|
+
const preview = (device: Device = "desktop") =>
|
|
141
141
|
void openInNewTab(
|
|
142
142
|
async () => {
|
|
143
143
|
if (isDirty(latest.current) && !(await save())) return null;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { PLUGIN_ID } from "../../constants.ts";
|
|
3
|
+
import type { ExtensionManifest } from "../../core/index.ts";
|
|
4
|
+
import { requestJson, type Fetcher } from "../api.ts";
|
|
5
|
+
import { setAdminExtensionManifests } from "./extension-manifests.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* W-927: extension manifests from `emvb({ extensions })`, via the plugin's editor/config route.
|
|
9
|
+
* Empty while loading and when the route fails or no extensions are registered.
|
|
10
|
+
*/
|
|
11
|
+
export function useExtensionManifests(fetcher: Fetcher): readonly ExtensionManifest[] {
|
|
12
|
+
const [loaded, setLoaded] = React.useState<readonly ExtensionManifest[]>([]);
|
|
13
|
+
React.useEffect(() => {
|
|
14
|
+
let cancelled = false;
|
|
15
|
+
void requestJson<{ extensions?: unknown }>(
|
|
16
|
+
fetcher,
|
|
17
|
+
`/_emdash/api/plugins/${PLUGIN_ID}/editor/config`,
|
|
18
|
+
)
|
|
19
|
+
.then((body) => {
|
|
20
|
+
if (cancelled) return;
|
|
21
|
+
const list = Array.isArray(body?.extensions) ? body.extensions : [];
|
|
22
|
+
const ok: ExtensionManifest[] = [];
|
|
23
|
+
for (const item of list) {
|
|
24
|
+
if (!item || typeof item !== "object") continue;
|
|
25
|
+
const m = item as ExtensionManifest;
|
|
26
|
+
if (m.extensionApi !== 1 || typeof m.id !== "string") continue;
|
|
27
|
+
ok.push(m);
|
|
28
|
+
}
|
|
29
|
+
setAdminExtensionManifests(ok);
|
|
30
|
+
setLoaded(ok);
|
|
31
|
+
})
|
|
32
|
+
.catch(() => undefined);
|
|
33
|
+
return () => {
|
|
34
|
+
cancelled = true;
|
|
35
|
+
};
|
|
36
|
+
}, [fetcher]);
|
|
37
|
+
return loaded;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Flat list of element manifests for Add panel and inspector. */
|
|
41
|
+
export function extensionElementManifests(
|
|
42
|
+
extensions: readonly ExtensionManifest[],
|
|
43
|
+
): ExtensionManifest["elements"][number][] {
|
|
44
|
+
return extensions.flatMap((ext) => [...ext.elements]);
|
|
45
|
+
}
|
|
@@ -24,7 +24,8 @@ import {
|
|
|
24
24
|
type Layout,
|
|
25
25
|
type LayoutNode,
|
|
26
26
|
} from "../../core/index.ts";
|
|
27
|
-
import {
|
|
27
|
+
import { adminExtensionDefaults } from "./extension-manifests.ts";
|
|
28
|
+
import { newElement, withPageHeadingLevel } from "./dnd/new-element.ts";
|
|
28
29
|
import { ELEMENT_NAMES } from "./element-chrome.ts";
|
|
29
30
|
import type { ItemActions } from "./panels/settings/ItemList.tsx";
|
|
30
31
|
import type { EditorAction, EditorState } from "./store.ts";
|
|
@@ -222,7 +223,7 @@ export function useNodeActions({
|
|
|
222
223
|
announce(`${label} added inside ${nameOf(result.parentId) ?? "Container"}`);
|
|
223
224
|
};
|
|
224
225
|
|
|
225
|
-
const addFromPanel = (type: ElementType) => {
|
|
226
|
+
const addFromPanel = (type: ElementType | string) => {
|
|
226
227
|
const current = latest.current.page.layout;
|
|
227
228
|
if (!current && type === "container") {
|
|
228
229
|
dispatch({ type: "add-root-container" });
|
|
@@ -231,9 +232,17 @@ export function useNodeActions({
|
|
|
231
232
|
// UX-094: an empty page (one made outside EmVB has no layout) gets its container first, so
|
|
232
233
|
// a click or palette insert lands instead of doing nothing.
|
|
233
234
|
const layout = current ?? startingLayout();
|
|
234
|
-
const
|
|
235
|
-
if (!
|
|
236
|
-
|
|
235
|
+
const added = newElement(type, undefined, adminExtensionDefaults(type));
|
|
236
|
+
if (!added) return;
|
|
237
|
+
// W-946: a click or palette insert picks the heading level the way a drop does.
|
|
238
|
+
const node = withPageHeadingLevel(added, layout, latest.current.page.partType);
|
|
239
|
+
const builtInName = ELEMENT_DESCRIPTORS.find((d) => d.type === type)?.name;
|
|
240
|
+
const label = builtInName
|
|
241
|
+
? builtInName
|
|
242
|
+
: type.startsWith("ext:")
|
|
243
|
+
? type.slice(type.lastIndexOf("/") + 1)
|
|
244
|
+
: type;
|
|
245
|
+
place(layout, node, label);
|
|
237
246
|
};
|
|
238
247
|
|
|
239
248
|
/** A section recipe built from the site's styles (W-320). */
|
|
@@ -241,7 +250,7 @@ export function useNodeActions({
|
|
|
241
250
|
const layout = latest.current.page.layout ?? startingLayout();
|
|
242
251
|
const node = recipeNode(id, latest.current.design, layout);
|
|
243
252
|
if (!node) return;
|
|
244
|
-
place(layout, withFreshIds(layout, node), `${node.
|
|
253
|
+
place(layout, withFreshIds(layout, node), `${node.editorLabel ?? "Section"} section`, true);
|
|
245
254
|
};
|
|
246
255
|
|
|
247
256
|
return {
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import {
|
|
3
|
+
listProposals,
|
|
4
|
+
listRequests,
|
|
5
|
+
type AgentRequest,
|
|
6
|
+
type PendingProposal,
|
|
7
|
+
} from "../proposals-api.ts";
|
|
8
|
+
import type { Fetcher } from "../api.ts";
|
|
9
|
+
|
|
10
|
+
/** How often the open editor asks for new proposals (D-063: EmDash's MCP has no push). */
|
|
11
|
+
const POLL_MS = 5_000;
|
|
12
|
+
|
|
13
|
+
export type ProposalsState = {
|
|
14
|
+
items: PendingProposal[];
|
|
15
|
+
/** True once the first request answered; false while loading or after a failure. */
|
|
16
|
+
ready: boolean;
|
|
17
|
+
failed: boolean;
|
|
18
|
+
refresh: () => void;
|
|
19
|
+
/** W-931: the page's requests for agents, newest first. */
|
|
20
|
+
requests: AgentRequest[];
|
|
21
|
+
/** When an agent last checked for requests (any page), or null if none has yet. */
|
|
22
|
+
agentSeenAt: string | null;
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* W-930: polls the page's proposals while the tab is visible. A failed poll keeps the last list
|
|
27
|
+
* and says so; the next tick retries.
|
|
28
|
+
*/
|
|
29
|
+
export function useProposals(
|
|
30
|
+
fetcher: Fetcher,
|
|
31
|
+
collection: string,
|
|
32
|
+
id: string,
|
|
33
|
+
enabled = true,
|
|
34
|
+
): ProposalsState {
|
|
35
|
+
const [items, setItems] = React.useState<PendingProposal[]>([]);
|
|
36
|
+
const [ready, setReady] = React.useState(false);
|
|
37
|
+
const [failed, setFailed] = React.useState(false);
|
|
38
|
+
const [tick, setTick] = React.useState(0);
|
|
39
|
+
const [requests, setRequests] = React.useState<AgentRequest[]>([]);
|
|
40
|
+
const [agentSeenAt, setAgentSeenAt] = React.useState<string | null>(null);
|
|
41
|
+
const refresh = React.useCallback(() => setTick((t) => t + 1), []);
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (!enabled) return;
|
|
44
|
+
let cancelled = false;
|
|
45
|
+
const load = () => {
|
|
46
|
+
if (typeof document !== "undefined" && document.visibilityState === "hidden") return;
|
|
47
|
+
listRequests(fetcher, collection, id).then(
|
|
48
|
+
(next) => {
|
|
49
|
+
if (cancelled) return;
|
|
50
|
+
setRequests((prev) => (sameRequests(prev, next.items) ? prev : next.items));
|
|
51
|
+
setAgentSeenAt(next.agentSeenAt);
|
|
52
|
+
},
|
|
53
|
+
() => undefined,
|
|
54
|
+
);
|
|
55
|
+
listProposals(fetcher, collection, id).then(
|
|
56
|
+
(next) => {
|
|
57
|
+
if (cancelled) return;
|
|
58
|
+
setItems((prev) => (sameList(prev, next) ? prev : next));
|
|
59
|
+
setReady(true);
|
|
60
|
+
setFailed(false);
|
|
61
|
+
},
|
|
62
|
+
() => {
|
|
63
|
+
if (!cancelled) setFailed(true);
|
|
64
|
+
},
|
|
65
|
+
);
|
|
66
|
+
};
|
|
67
|
+
load();
|
|
68
|
+
const timer = setInterval(load, POLL_MS);
|
|
69
|
+
return () => {
|
|
70
|
+
cancelled = true;
|
|
71
|
+
clearInterval(timer);
|
|
72
|
+
};
|
|
73
|
+
}, [fetcher, collection, id, tick, enabled]);
|
|
74
|
+
return { items, ready, failed, refresh, requests, agentSeenAt };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const sameList = (a: PendingProposal[], b: PendingProposal[]) =>
|
|
78
|
+
a.length === b.length && a.every((p, i) => p.id === b[i]?.id);
|
|
79
|
+
|
|
80
|
+
const sameRequests = (a: AgentRequest[], b: AgentRequest[]) =>
|
|
81
|
+
a.length === b.length && a.every((r, i) => r.id === b[i]?.id && r.status === b[i]?.status);
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { Layout } from "../core/schema/layout.ts";
|
|
2
|
+
import { requestJson, type Fetcher } from "./api.ts";
|
|
3
|
+
|
|
4
|
+
/** W-936: the site's languages, from EmDash's manifest; null when the site has no i18n. */
|
|
5
|
+
export async function siteLocales(
|
|
6
|
+
fetcher: Fetcher,
|
|
7
|
+
): Promise<{ defaultLocale: string; locales: string[] } | null> {
|
|
8
|
+
const data = await requestJson<{ i18n?: { defaultLocale?: string; locales?: string[] } }>(
|
|
9
|
+
fetcher,
|
|
10
|
+
"/_emdash/api/manifest",
|
|
11
|
+
);
|
|
12
|
+
const locales = data.i18n?.locales ?? [];
|
|
13
|
+
if (locales.length < 2 || !data.i18n?.defaultLocale) return null;
|
|
14
|
+
return { defaultLocale: data.i18n.defaultLocale, locales };
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export type Translation = { id: string; locale: string; slug: string; status: string };
|
|
18
|
+
|
|
19
|
+
/** Every language of an entry (EmDash's translation group), this one included. */
|
|
20
|
+
export async function listTranslations(
|
|
21
|
+
fetcher: Fetcher,
|
|
22
|
+
collection: string,
|
|
23
|
+
id: string,
|
|
24
|
+
): Promise<Translation[]> {
|
|
25
|
+
const data = await requestJson<{ translations?: Translation[] }>(
|
|
26
|
+
fetcher,
|
|
27
|
+
`/_emdash/api/content/${collection}/${encodeURIComponent(id)}/translations`,
|
|
28
|
+
);
|
|
29
|
+
return data.translations ?? [];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Creates the `locale` draft of an entry (D-068: a row per locale, linked by `translationOf`)
|
|
34
|
+
* holding a copy of the layout to translate. Returns the new entry's id.
|
|
35
|
+
*/
|
|
36
|
+
export async function createTranslation(
|
|
37
|
+
fetcher: Fetcher,
|
|
38
|
+
input: {
|
|
39
|
+
collection: string;
|
|
40
|
+
sourceId: string;
|
|
41
|
+
locale: string;
|
|
42
|
+
title: string;
|
|
43
|
+
slug: string;
|
|
44
|
+
layout: Layout;
|
|
45
|
+
},
|
|
46
|
+
): Promise<string> {
|
|
47
|
+
const data = await requestJson<{ item: { id: string } }>(
|
|
48
|
+
fetcher,
|
|
49
|
+
`/_emdash/api/content/${input.collection}`,
|
|
50
|
+
{
|
|
51
|
+
method: "POST",
|
|
52
|
+
body: {
|
|
53
|
+
data: { title: input.title, layout: input.layout },
|
|
54
|
+
slug: input.slug,
|
|
55
|
+
locale: input.locale,
|
|
56
|
+
translationOf: input.sourceId,
|
|
57
|
+
},
|
|
58
|
+
},
|
|
59
|
+
);
|
|
60
|
+
return data.item.id;
|
|
61
|
+
}
|
|
@@ -0,0 +1,148 @@
|
|
|
1
|
+
import { Button } from "@cloudflare/kumo";
|
|
2
|
+
import {
|
|
3
|
+
ArrowsClockwiseIcon,
|
|
4
|
+
CheckCircleIcon,
|
|
5
|
+
ListChecksIcon,
|
|
6
|
+
QuestionIcon,
|
|
7
|
+
WarningCircleIcon,
|
|
8
|
+
} from "@phosphor-icons/react";
|
|
9
|
+
import type { ReactNode } from "react";
|
|
10
|
+
import { useEffect, useState } from "react";
|
|
11
|
+
import type { Fetcher } from "../api.ts";
|
|
12
|
+
import { checkAgentSetup, type AgentSetup } from "../agents-api.ts";
|
|
13
|
+
import { SectionHead } from "./section-head.tsx";
|
|
14
|
+
|
|
15
|
+
type Step = { key: string; state: "done" | "todo" | "unknown"; title: string; detail: ReactNode };
|
|
16
|
+
|
|
17
|
+
const ICONS = {
|
|
18
|
+
done: <CheckCircleIcon size={18} weight="fill" aria-hidden="true" />,
|
|
19
|
+
todo: <WarningCircleIcon size={18} weight="fill" aria-hidden="true" />,
|
|
20
|
+
unknown: <QuestionIcon size={18} aria-hidden="true" />,
|
|
21
|
+
};
|
|
22
|
+
const STATUS = { done: "Done", todo: "To do", unknown: "Couldn't check" };
|
|
23
|
+
|
|
24
|
+
/** W-932: the steps a site needs before an agent can connect, each checked where it can be. */
|
|
25
|
+
function setupSteps(setup: AgentSetup | null, agentsOn: boolean): Step[] {
|
|
26
|
+
const endpoint = setup?.endpoint ?? "unknown";
|
|
27
|
+
const tools = setup?.tools ?? "unknown";
|
|
28
|
+
return [
|
|
29
|
+
{
|
|
30
|
+
key: "endpoint",
|
|
31
|
+
state: endpoint === "on" ? "done" : endpoint === "off" ? "todo" : "unknown",
|
|
32
|
+
title: "EmDash's MCP endpoint is on",
|
|
33
|
+
detail:
|
|
34
|
+
endpoint === "off" ? (
|
|
35
|
+
<>
|
|
36
|
+
Add <code>mcp: true</code> to <code>emdash()</code> in <code>astro.config.mjs</code> and
|
|
37
|
+
redeploy.
|
|
38
|
+
</>
|
|
39
|
+
) : (
|
|
40
|
+
"Agents connect to EmDash's own endpoint; EmVB adds its tools there."
|
|
41
|
+
),
|
|
42
|
+
},
|
|
43
|
+
{
|
|
44
|
+
key: "tools",
|
|
45
|
+
state: tools === "served" ? "done" : tools === "off" ? "todo" : "unknown",
|
|
46
|
+
title: "EmVB's tools are approved",
|
|
47
|
+
detail:
|
|
48
|
+
tools === "approved" ? (
|
|
49
|
+
<>
|
|
50
|
+
Approved, but no agent has used this version's tools yet. EmDash hides them again
|
|
51
|
+
whenever an EmVB update changes them: if your agent doesn't see EmVB's tools, approve
|
|
52
|
+
them again in <a href="/_emdash/admin/plugins-manager">Plugins</a>.
|
|
53
|
+
</>
|
|
54
|
+
) : tools === "off" ? (
|
|
55
|
+
<>
|
|
56
|
+
Approve them for Pages VisualBuilder in{" "}
|
|
57
|
+
<a href="/_emdash/admin/plugins-manager">Plugins</a>.
|
|
58
|
+
</>
|
|
59
|
+
) : tools === "served" ? (
|
|
60
|
+
"An agent has used this version's tools."
|
|
61
|
+
) : (
|
|
62
|
+
"EmDash lists EmVB's tools to agents only after an admin approves them."
|
|
63
|
+
),
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
key: "access",
|
|
67
|
+
state: agentsOn ? "done" : "todo",
|
|
68
|
+
title: "Agent access is on",
|
|
69
|
+
detail: agentsOn
|
|
70
|
+
? "Turn it off below to refuse every agent call at once."
|
|
71
|
+
: "Turn on “Let AI agents edit EmVB pages” below.",
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
key: "token",
|
|
75
|
+
state: "unknown",
|
|
76
|
+
title: "A token for the agent",
|
|
77
|
+
detail: (
|
|
78
|
+
<>
|
|
79
|
+
In <a href="/_emdash/admin/settings/api-tokens">API tokens</a>, create one with the scope{" "}
|
|
80
|
+
<code>mcp:tools:emvb</code> for an editor, not an admin. EmVB never sees or stores it.
|
|
81
|
+
</>
|
|
82
|
+
),
|
|
83
|
+
},
|
|
84
|
+
];
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function AgentSetupCard({
|
|
88
|
+
fetcher,
|
|
89
|
+
agentsOn,
|
|
90
|
+
toolsServed = false,
|
|
91
|
+
}: {
|
|
92
|
+
fetcher: Fetcher;
|
|
93
|
+
agentsOn: boolean;
|
|
94
|
+
toolsServed?: boolean;
|
|
95
|
+
}) {
|
|
96
|
+
const [setup, setSetup] = useState<AgentSetup | null>(null);
|
|
97
|
+
const [attempt, setAttempt] = useState(0);
|
|
98
|
+
useEffect(() => {
|
|
99
|
+
let cancelled = false;
|
|
100
|
+
setSetup(null);
|
|
101
|
+
checkAgentSetup(fetcher, toolsServed).then(
|
|
102
|
+
(next) => !cancelled && setSetup(next),
|
|
103
|
+
() => !cancelled && setSetup({ endpoint: "unknown", tools: "unknown" }),
|
|
104
|
+
);
|
|
105
|
+
return () => {
|
|
106
|
+
cancelled = true;
|
|
107
|
+
};
|
|
108
|
+
}, [fetcher, toolsServed, attempt]);
|
|
109
|
+
const steps = setupSteps(setup, agentsOn);
|
|
110
|
+
return (
|
|
111
|
+
<section
|
|
112
|
+
className="emvb-surface-card emvb-agents-section"
|
|
113
|
+
aria-labelledby="emvb-agents-setup"
|
|
114
|
+
aria-busy={setup === null || undefined}
|
|
115
|
+
data-emvb-agent-setup={setup === null ? "checking" : "ready"}
|
|
116
|
+
>
|
|
117
|
+
<SectionHead id="emvb-agents-setup" icon={ListChecksIcon} title="Setup">
|
|
118
|
+
What this site needs before an agent can connect. People then ask their agent from the
|
|
119
|
+
editor's Agent tab and review what it proposes.
|
|
120
|
+
</SectionHead>
|
|
121
|
+
<ol className="emvb-agents-steps">
|
|
122
|
+
{steps.map((step) => (
|
|
123
|
+
<li key={step.key} data-emvb-setup-step={step.key} data-state={step.state}>
|
|
124
|
+
<span className="emvb-agents-step-icon">{ICONS[step.state]}</span>
|
|
125
|
+
<div>
|
|
126
|
+
<h3>
|
|
127
|
+
{step.title}
|
|
128
|
+
<span className="emvb-sr-only">: {STATUS[step.state]}</span>
|
|
129
|
+
</h3>
|
|
130
|
+
<p>{step.detail}</p>
|
|
131
|
+
</div>
|
|
132
|
+
</li>
|
|
133
|
+
))}
|
|
134
|
+
</ol>
|
|
135
|
+
<div>
|
|
136
|
+
<Button
|
|
137
|
+
size="sm"
|
|
138
|
+
variant="secondary"
|
|
139
|
+
icon={<ArrowsClockwiseIcon aria-hidden="true" />}
|
|
140
|
+
onClick={() => setAttempt((n) => n + 1)}
|
|
141
|
+
data-emvb-setup-recheck=""
|
|
142
|
+
>
|
|
143
|
+
Check again
|
|
144
|
+
</Button>
|
|
145
|
+
</div>
|
|
146
|
+
</section>
|
|
147
|
+
);
|
|
148
|
+
}
|
|
@@ -11,7 +11,6 @@ import {
|
|
|
11
11
|
TerminalWindowIcon,
|
|
12
12
|
UploadSimpleIcon,
|
|
13
13
|
WarningCircleIcon,
|
|
14
|
-
type Icon,
|
|
15
14
|
} from "@phosphor-icons/react";
|
|
16
15
|
import type { ReactNode } from "react";
|
|
17
16
|
import { useEffect, useRef, useState } from "react";
|
|
@@ -22,6 +21,10 @@ import { editorUrl } from "../editor/exit.ts";
|
|
|
22
21
|
import type { AgentSettings } from "../../mcp/settings.ts";
|
|
23
22
|
import { ListError, ListLoading } from "./list-kit.tsx";
|
|
24
23
|
import { UI_CSS } from "../ui.ts";
|
|
24
|
+
import { AgentSetupCard } from "./AgentSetup.tsx";
|
|
25
|
+
import { SectionHead } from "./section-head.tsx";
|
|
26
|
+
|
|
27
|
+
export { SectionHead };
|
|
25
28
|
|
|
26
29
|
const ADMIN_ROLE = 50;
|
|
27
30
|
|
|
@@ -44,31 +47,6 @@ const stdioSnippet = (site: string) =>
|
|
|
44
47
|
const remoteSnippet = (endpoint: string) =>
|
|
45
48
|
JSON.stringify({ mcpServers: { emvb: { url: endpoint } } }, null, 2);
|
|
46
49
|
|
|
47
|
-
/** A card's heading row: an icon tile, the title and one line on what the card is for (W-477). */
|
|
48
|
-
export function SectionHead({
|
|
49
|
-
id,
|
|
50
|
-
icon: SectionIcon,
|
|
51
|
-
title,
|
|
52
|
-
children,
|
|
53
|
-
}: {
|
|
54
|
-
id: string;
|
|
55
|
-
icon: Icon;
|
|
56
|
-
title: string;
|
|
57
|
-
children: ReactNode;
|
|
58
|
-
}) {
|
|
59
|
-
return (
|
|
60
|
-
<div className="emvb-agents-head">
|
|
61
|
-
<span className="emvb-agents-icon" aria-hidden="true">
|
|
62
|
-
<SectionIcon size={18} />
|
|
63
|
-
</span>
|
|
64
|
-
<div>
|
|
65
|
-
<h2 id={id}>{title}</h2>
|
|
66
|
-
<p>{children}</p>
|
|
67
|
-
</div>
|
|
68
|
-
</div>
|
|
69
|
-
);
|
|
70
|
-
}
|
|
71
|
-
|
|
72
50
|
/** AI agents (`/agents`, W-463): the master switch, publishing, how to connect, recent activity. */
|
|
73
51
|
/**
|
|
74
52
|
* W-756: on a phone the setup JSON scrolls sideways, and keyboard users could not reach it to
|
|
@@ -185,6 +163,11 @@ export function AgentsPage({ fetcher = defaultFetcher }: { fetcher?: Fetcher })
|
|
|
185
163
|
description={saveError}
|
|
186
164
|
/>
|
|
187
165
|
)}
|
|
166
|
+
<AgentSetupCard
|
|
167
|
+
fetcher={fetcher}
|
|
168
|
+
agentsOn={settings.mcpEnabled}
|
|
169
|
+
toolsServed={state.toolsServed === true}
|
|
170
|
+
/>
|
|
188
171
|
<section
|
|
189
172
|
className="emvb-surface-card emvb-agents-section"
|
|
190
173
|
aria-labelledby="emvb-agents-access"
|