@perkyzz/emvb 1.1.0 → 1.3.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/THIRD_PARTY_NOTICES.md +3 -2
- package/package.json +11 -10
- package/src/admin/agents-api.ts +5 -1
- package/src/admin/content-api.ts +29 -0
- package/src/admin/editor/Editor.tsx +6 -1
- package/src/admin/editor/ScheduleDialog.tsx +167 -0
- package/src/admin/editor/TopBar.tsx +33 -1
- package/src/admin/editor/canvas/vnode-react.tsx +3 -0
- package/src/admin/editor/dnd/new-element.ts +106 -0
- package/src/admin/editor/editor-chrome.tsx +9 -0
- package/src/admin/editor/element-chrome.ts +50 -0
- package/src/admin/editor/panels/ElementPanel.tsx +5 -1
- package/src/admin/editor/panels/settings/DraftTextField.tsx +33 -1
- package/src/admin/editor/panels/settings/FieldBindControl.tsx +6 -1
- package/src/admin/editor/panels/settings/FieldControl.tsx +10 -1
- package/src/admin/editor/panels/settings/IconPicker.tsx +4 -1
- package/src/admin/editor/panels/settings/ItemList.tsx +69 -2
- package/src/admin/editor/panels/settings/advanced-rules.ts +3 -0
- package/src/admin/editor/store.ts +7 -1
- package/src/admin/editor/useEditorData.ts +4 -0
- package/src/admin/editor/useSave.ts +47 -3
- package/src/admin/export-api.ts +20 -3
- package/src/admin/menus-api.ts +113 -0
- package/src/admin/pages/ImportElementorDialog.tsx +25 -1
- package/src/astro/EmVBPage.astro +3 -0
- package/src/astro/render.ts +43 -18
- package/src/astro/request-data.ts +9 -0
- package/src/astro/resolve-theme.ts +77 -44
- package/src/astro/resolve.ts +9 -0
- package/src/astro/visitor.ts +23 -4
- package/src/astro/widgets/EmVBAlertsRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCarouselRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCountdownRuntime.astro +8 -0
- package/src/astro/widgets/EmVBCounterRuntime.astro +8 -0
- package/src/astro/widgets/EmVBHeadlineRuntime.astro +9 -0
- package/src/astro/widgets/EmVBLightboxRuntime.astro +8 -0
- package/src/astro/widgets/EmVBMapRuntime.astro +8 -0
- package/src/astro/widgets/EmVBShareRuntime.astro +9 -0
- package/src/astro/widgets/EmVBWidgetRuntimes.astro +29 -0
- package/src/astro/widgets/alerts.ts +37 -0
- package/src/astro/widgets/carousel.ts +167 -0
- package/src/astro/widgets/countdown.ts +80 -0
- package/src/astro/widgets/counter.ts +98 -0
- package/src/astro/widgets/headline.ts +90 -0
- package/src/astro/widgets/index.ts +1 -0
- package/src/astro/widgets/lightbox.ts +123 -0
- package/src/astro/widgets/map.ts +37 -0
- package/src/astro/widgets/share.ts +21 -0
- package/src/constants.ts +1 -1
- package/src/core/a11y/audit.ts +127 -5
- package/src/core/arrange.ts +109 -1
- package/src/core/bounded-array.ts +16 -13
- package/src/core/canvas-collections.ts +28 -0
- package/src/core/contract.ts +4 -1
- package/src/core/elements/counter-format.ts +15 -0
- package/src/core/elements/icon-svg.ts +135 -0
- package/src/core/elements/index.ts +63 -127
- package/src/core/elements/marketing.ts +1490 -0
- package/src/core/elements/widgets.ts +932 -0
- package/src/core/export/runtimes.generated.ts +8 -0
- package/src/core/export/site.ts +25 -3
- package/src/core/extensions/schema.ts +2 -1
- package/src/core/geo-trust.ts +18 -0
- package/src/core/icons/social.generated.ts +29 -0
- package/src/core/image-edit/schema.ts +2 -1
- package/src/core/import/elementor/context.ts +18 -0
- package/src/core/import/elementor/index.ts +50 -7
- package/src/core/import/elementor/widgets.ts +783 -385
- package/src/core/issue-cap.ts +19 -0
- package/src/core/limits.ts +12 -0
- package/src/core/loop-collections.ts +33 -0
- package/src/core/proposals.ts +8 -2
- package/src/core/render/index.ts +48 -5
- package/src/core/render/vnode.ts +44 -6
- package/src/core/sanitize/svg-upload.ts +276 -23
- package/src/core/sanitize/svg.ts +3 -3
- package/src/core/schema/descriptors.ts +4 -0
- package/src/core/schema/design.ts +6 -5
- package/src/core/schema/layout.ts +798 -15
- package/src/core/schema/style.ts +2 -1
- package/src/core/shadowing-ids.ts +41 -0
- package/src/core/theme/conditions.ts +2 -1
- package/src/core/theme/dynamic.ts +2 -0
- package/src/core/theme/parse-doc.ts +10 -5
- package/src/core/theme/triggers.ts +3 -2
- package/src/core/validate.ts +3 -2
- package/src/index.ts +23 -2
- package/src/mcp/ports.ts +18 -7
- package/src/mcp/proposals.ts +36 -11
- package/src/mcp/tools.ts +1 -1
- package/src/server/agent-settings.ts +12 -1
- package/src/server/hooks.ts +41 -6
- package/src/server/mcp-routes.ts +11 -5
- package/src/server/plugin.ts +29 -3
- package/src/server/presence.ts +5 -1
- package/src/server/proposals.ts +16 -4
- package/src/server/requests.ts +60 -11
- package/src/server/site-origin.ts +13 -0
- package/src/server/targets.ts +26 -0
package/src/server/requests.ts
CHANGED
|
@@ -5,12 +5,17 @@ import { ProposalTarget } from "../core/proposals.ts";
|
|
|
5
5
|
import { isRecord } from "../core/record.ts";
|
|
6
6
|
import type { AgentRequest, RequestsPort } from "../mcp/ports.ts";
|
|
7
7
|
import { queued } from "../mcp/queue.ts";
|
|
8
|
+
import { isEmvbTarget } from "./targets.ts";
|
|
8
9
|
|
|
9
10
|
/**
|
|
10
11
|
* W-931 prompt relay (D-063: bring-your-own agent). A person writes a request in the editor's
|
|
11
12
|
* Agent tab; their own agent reads it with get_requests and answers with propose_changes. Nothing
|
|
12
13
|
* here calls a model or holds a key. Requests are the person's words for their agent: they are
|
|
13
14
|
* shown back as plain text and never reach a page.
|
|
15
|
+
*
|
|
16
|
+
* W-990 (S-01): a request is private to its author. Only an agent signed in as that person (its
|
|
17
|
+
* token) reads it, answers it or sees it listed; a row without an author goes to nobody. Any
|
|
18
|
+
* editor's text reached whoever ran `emvb-mcp watch` before, as if they had written it.
|
|
14
19
|
*/
|
|
15
20
|
|
|
16
21
|
const COLLECTION = "emvb_requests";
|
|
@@ -18,12 +23,19 @@ const ID = /^[0-9a-f]{16}$/;
|
|
|
18
23
|
/** Requests older than this are no longer offered to agents. */
|
|
19
24
|
const REQUEST_TTL_MS = 24 * 3_600_000;
|
|
20
25
|
const SEEN_KEY = "relay:seen";
|
|
26
|
+
/** S-09 (W-998): open requests one person may have across the site. */
|
|
27
|
+
const MAX_OPEN_REQUESTS_PER_USER = 20;
|
|
28
|
+
/** Expired requests deleted per new request. */
|
|
29
|
+
const PURGE_BATCH = 50;
|
|
30
|
+
/** EmDash's admin role: may cancel anyone's request. */
|
|
31
|
+
const ADMIN_ROLE = 50;
|
|
21
32
|
|
|
22
33
|
type Target = z.infer<typeof ProposalTarget>;
|
|
23
34
|
type Stored = {
|
|
24
35
|
target: Target;
|
|
25
36
|
prompt: string;
|
|
26
37
|
createdAt: string;
|
|
38
|
+
/** The author; a row without one (written before W-990 by a signed-out call) goes to nobody. */
|
|
27
39
|
userId: string | null;
|
|
28
40
|
status: "open" | "answered";
|
|
29
41
|
proposalId?: string;
|
|
@@ -74,6 +86,7 @@ const nextCreatedAt = (nowMs: number) => {
|
|
|
74
86
|
};
|
|
75
87
|
|
|
76
88
|
const sameTarget = (a: Target, b: Target) => a.collection === b.collection && a.id === b.id;
|
|
89
|
+
const ownedBy = (s: Stored, userId: string | null) => userId !== null && s.userId === userId;
|
|
77
90
|
|
|
78
91
|
/** Same per-isolate write queue pattern as proposals; `now` is injectable for tests. */
|
|
79
92
|
export function requestsPort(store: Store, kv: Kv, now: () => number = Date.now): RequestsPort {
|
|
@@ -88,14 +101,14 @@ export function requestsPort(store: Store, kv: Kv, now: () => number = Date.now)
|
|
|
88
101
|
};
|
|
89
102
|
const live = (s: Stored) => now() - Date.parse(s.createdAt) < REQUEST_TTL_MS;
|
|
90
103
|
return {
|
|
91
|
-
async list(target) {
|
|
104
|
+
async list(target, userId) {
|
|
92
105
|
return (await all())
|
|
93
|
-
.filter((r) => sameTarget(r.stored.target, target))
|
|
106
|
+
.filter((r) => ownedBy(r.stored, userId) && sameTarget(r.stored.target, target))
|
|
94
107
|
.map((r) => toRequest(r.id, r.stored));
|
|
95
108
|
},
|
|
96
|
-
async open(target) {
|
|
109
|
+
async open(userId, target) {
|
|
97
110
|
return (await all())
|
|
98
|
-
.filter((r) => r.stored.status === "open" && live(r.stored))
|
|
111
|
+
.filter((r) => r.stored.status === "open" && live(r.stored) && ownedBy(r.stored, userId))
|
|
99
112
|
.filter((r) => !target || sameTarget(r.stored.target, target))
|
|
100
113
|
.map((r) => toRequest(r.id, r.stored))
|
|
101
114
|
.toSorted((a, b) => a.createdAt.localeCompare(b.createdAt));
|
|
@@ -109,9 +122,26 @@ export function requestsPort(store: Store, kv: Kv, now: () => number = Date.now)
|
|
|
109
122
|
ok: false as const,
|
|
110
123
|
reason: `Keep a request under ${MAX_REQUEST_PROMPT} characters.`,
|
|
111
124
|
};
|
|
112
|
-
|
|
125
|
+
if (userId === null)
|
|
126
|
+
return { ok: false as const, reason: "Sign in to write a request for your agent." };
|
|
127
|
+
const rows = await all();
|
|
128
|
+
// S-09 (W-998): expired requests are deleted as new ones come in, a few at a time.
|
|
129
|
+
const expired = rows.filter((r) => !live(r.stored)).slice(0, PURGE_BATCH);
|
|
130
|
+
await Promise.all(expired.map((r) => store.delete(r.id)));
|
|
131
|
+
const mine = rows.filter(
|
|
132
|
+
(r) => r.stored.status === "open" && live(r.stored) && ownedBy(r.stored, userId),
|
|
133
|
+
);
|
|
134
|
+
if (mine.length >= MAX_OPEN_REQUESTS_PER_USER)
|
|
135
|
+
return {
|
|
136
|
+
ok: false as const,
|
|
137
|
+
reason: `You already have ${MAX_OPEN_REQUESTS_PER_USER} requests waiting. Cancel one or wait for answers.`,
|
|
138
|
+
};
|
|
139
|
+
const open = rows.filter(
|
|
113
140
|
(r) =>
|
|
114
|
-
r.stored.status === "open" &&
|
|
141
|
+
r.stored.status === "open" &&
|
|
142
|
+
live(r.stored) &&
|
|
143
|
+
ownedBy(r.stored, userId) &&
|
|
144
|
+
sameTarget(r.stored.target, target),
|
|
115
145
|
);
|
|
116
146
|
if (open.length >= MAX_OPEN_REQUESTS_PER_PAGE)
|
|
117
147
|
return {
|
|
@@ -129,12 +159,25 @@ export function requestsPort(store: Store, kv: Kv, now: () => number = Date.now)
|
|
|
129
159
|
await store.put(id, stored);
|
|
130
160
|
return { ok: true as const, request: toRequest(id, stored) };
|
|
131
161
|
}),
|
|
132
|
-
cancel: (id
|
|
133
|
-
|
|
162
|
+
cancel: (id, userId, isAdmin) =>
|
|
163
|
+
queued("requests", async () => {
|
|
164
|
+
if (!ID.test(id)) return false;
|
|
165
|
+
const stored = read(await store.get(id));
|
|
166
|
+
// S-01: the author or an admin; anyone else sees no such request.
|
|
167
|
+
if (!stored || !(isAdmin || ownedBy(stored, userId))) return false;
|
|
168
|
+
return store.delete(id);
|
|
169
|
+
}),
|
|
170
|
+
answer: (id, target, proposalId, userId) =>
|
|
134
171
|
queued("requests", async () => {
|
|
135
172
|
if (!ID.test(id)) return false;
|
|
136
173
|
const stored = read(await store.get(id));
|
|
137
|
-
if (
|
|
174
|
+
if (
|
|
175
|
+
!stored ||
|
|
176
|
+
stored.status !== "open" ||
|
|
177
|
+
!ownedBy(stored, userId) ||
|
|
178
|
+
!sameTarget(stored.target, target)
|
|
179
|
+
)
|
|
180
|
+
return false;
|
|
138
181
|
await store.put(id, {
|
|
139
182
|
...stored,
|
|
140
183
|
status: "answered",
|
|
@@ -162,7 +205,10 @@ export const requestsRoute: PluginRoute<z.infer<typeof ProposalTarget>> = {
|
|
|
162
205
|
input: ProposalTarget,
|
|
163
206
|
handler: async (ctx) => {
|
|
164
207
|
const port = requestsPortOf(ctx);
|
|
165
|
-
return {
|
|
208
|
+
return {
|
|
209
|
+
items: await port.list(ctx.input, ctx.user?.id ?? null),
|
|
210
|
+
agentSeenAt: await port.lastSeen(),
|
|
211
|
+
};
|
|
166
212
|
},
|
|
167
213
|
};
|
|
168
214
|
|
|
@@ -174,6 +220,8 @@ export const requestCreateRoute: PluginRoute<z.infer<typeof CreateInput>> = {
|
|
|
174
220
|
permission: "content:edit_any",
|
|
175
221
|
input: CreateInput,
|
|
176
222
|
handler: async (ctx) => {
|
|
223
|
+
if (!(await isEmvbTarget(ctx, ctx.input.target)))
|
|
224
|
+
throw new PluginRouteError("NOT_FOUND", "No such page.", 404);
|
|
177
225
|
const made = await requestsPortOf(ctx).create(
|
|
178
226
|
ctx.input.target,
|
|
179
227
|
ctx.input.prompt,
|
|
@@ -189,7 +237,8 @@ export const requestCancelRoute: PluginRoute<z.infer<typeof IdInput>> = {
|
|
|
189
237
|
permission: "content:edit_any",
|
|
190
238
|
input: IdInput,
|
|
191
239
|
handler: async (ctx) => {
|
|
192
|
-
|
|
240
|
+
const isAdmin = Number(ctx.user?.role ?? 0) >= ADMIN_ROLE;
|
|
241
|
+
if (!(await requestsPortOf(ctx).cancel(ctx.input.id, ctx.user?.id ?? null, isAdmin)))
|
|
193
242
|
throw new PluginRouteError("NOT_FOUND", "No such request.", 404);
|
|
194
243
|
return { id: ctx.input.id };
|
|
195
244
|
},
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* S-05 (W-995): the site's own origin from its configuration (EmDash's site URL setting), never
|
|
3
|
+
* from the request: the Host header is the caller's to choose. Undefined when none is set.
|
|
4
|
+
*/
|
|
5
|
+
export function trustedOrigin(siteUrl: unknown): string | undefined {
|
|
6
|
+
if (typeof siteUrl !== "string" || !siteUrl) return undefined;
|
|
7
|
+
try {
|
|
8
|
+
const url = new URL(siteUrl);
|
|
9
|
+
return url.protocol === "https:" || url.protocol === "http:" ? url.origin : undefined;
|
|
10
|
+
} catch {
|
|
11
|
+
return undefined;
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { PluginContext, RouteContext } from "emdash";
|
|
2
|
+
import type { z } from "zod";
|
|
3
|
+
import { PAGES_COLLECTION, THEME_PARTS_COLLECTION } from "../constants.ts";
|
|
4
|
+
import type { ProposalTarget } from "../core/proposals.ts";
|
|
5
|
+
import { canvasFieldSlugs } from "./hooks.ts";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* S-09 (W-998): a request or an editor presence may name only an entry that exists in an EmVB
|
|
9
|
+
* collection or in a collection with an emvb:canvas field. Routes took any slug and id, so junk
|
|
10
|
+
* targets filled storage and hid real requests.
|
|
11
|
+
*/
|
|
12
|
+
export async function isEmvbTarget(
|
|
13
|
+
ctx: RouteContext<unknown>,
|
|
14
|
+
target: z.infer<typeof ProposalTarget>,
|
|
15
|
+
): Promise<boolean> {
|
|
16
|
+
const owned =
|
|
17
|
+
target.collection === PAGES_COLLECTION || target.collection === THEME_PARTS_COLLECTION;
|
|
18
|
+
if (!owned) {
|
|
19
|
+
const slugs = await canvasFieldSlugs(ctx as unknown as PluginContext, target.collection).catch(
|
|
20
|
+
() => [],
|
|
21
|
+
);
|
|
22
|
+
if (slugs.length === 0) return false;
|
|
23
|
+
}
|
|
24
|
+
const found = await ctx.content?.get(target.collection, target.id).catch(() => null);
|
|
25
|
+
return Boolean(found);
|
|
26
|
+
}
|