PluginProbe
Extendify / 3.2.2
Extendify v3.2.2
3.2.2 3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 All 128 releases
← All changes | src/Agent/api.js +43 -15 3.2.1 → 3.2.2 View file →
@@ -7,12 +7,14 @@
7 7 } from '@agent/lib/classify-block-edit';
8 8 import { getClientTools } from '@agent/lib/client-tools';
9 9 import { isExtendableHeader } from '@agent/lib/extendable-header';
10 10 import { INSERTABLE_BLOCK_TYPES } from '@agent/lib/insertable-blocks';
11 +import { fetchLinkablePages } from '@agent/lib/linkable-pages';
11 12 import { ensureCoreBlocksRegistered } from '@agent/lib/register-blocks';
12 13 import {
13 14 buildSubtreeManifest,
14 15 buildSubtreeTree,
16 + ownerAncestorFor,
15 17 } from '@agent/lib/subtree-manifest';
16 18 import { activeCanvasStep } from '@agent/state/canvas';
17 19 import { useChatStore } from '@agent/state/chat';
18 20 import { useGlobalStore } from '@agent/state/global';
@@ -23,9 +25,14 @@
23 25 import { reqDataBasics } from '@shared/lib/data';
24 26 import { getBlockType } from '@wordpress/blocks';
25 27
26 28 // page-templates:v1 declares that find-blocks and stage-block reach into parts.
27 -export const API_FEATURES = ['qa-tool', 'page-templates:v1'];
29 +// block-duplicate:v1 declares that update-blocks applies the duplicate op.
30 +export const API_FEATURES = [
31 + 'qa-tool',
32 + 'page-templates:v1',
33 + 'block-duplicate:v1',
34 +];
28 35
29 36 const rootFor = (block) =>
30 37 block?.id && block?.target
31 38 ? findBlockEl(block.id, document, scopeOf(block))
@@ -37,14 +44,21 @@
37 44 // The staged selection's attribute schemas, with the install's palette baked in.
38 45 export const blockSchemasFor = async (block) => {
39 46 const root = rootFor(block);
40 47 const { bucket } = classifyBlockEdit({ block, root });
41 - const types =
42 - bucket === 'single'
43 - ? [block.blockType]
44 - : IGNORED_BLOCKS.has(block?.blockType)
45 - ? []
46 - : [...new Set(buildSubtreeManifest(root).map(({ type }) => type))];
48 + const owner = ownerAncestorFor(root);
49 + const types = [
50 + ...new Set(
51 + [
52 + ...(bucket === 'single'
53 + ? [block.blockType]
54 + : IGNORED_BLOCKS.has(block?.blockType)
55 + ? []
56 + : buildSubtreeManifest(root).map(({ type }) => type)),
57 + owner?.type,
58 + ].filter(Boolean),
59 + ),
60 + ];
47 61 if (!types.length || types.length > EAGER_LOAD_MAX) return [];
48 62 await ensureCoreBlocksRegistered();
49 63 return types
50 64 .map((type) => ({ type, schema: buildBlockSchema(getBlockType(type)) }))
@@ -50,11 +64,28 @@
50 64 .map((type) => ({ type, schema: buildBlockSchema(getBlockType(type)) }))
51 65 .filter(({ schema }) => schema);
52 66 };
53 67
68 +// Without the site's addresses the model links a named page to "#".
69 +const withLinkablePages = async (data) => {
70 + if (!data.blockSchemas?.some(({ type }) => type === 'core/navigation-link')) {
71 + return data;
72 + }
73 + const pages = await fetchLinkablePages();
74 + return {
75 + ...data,
76 + linkablePages: pages.map(({ title, url }) => ({ title, url })),
77 + };
78 +};
79 +
54 80 // Only consumed for a multi-block edit; inert for single/combo.
55 -export const subtreeManifestFor = (block) =>
56 - buildSubtreeManifest(rootFor(block));
81 +export const subtreeManifestFor = (block) => {
82 + const root = rootFor(block);
83 + const owner = ownerAncestorFor(root);
84 + const manifest = buildSubtreeManifest(root);
85 + // buildSubtreeManifest treats the first entry as the selection's baseline.
86 + return owner ? [...manifest, owner] : manifest;
87 +};
57 88
58 89 // Selection hierarchy for the backend's positional edits.
59 90 export const subtreeTreeFor = (block) => buildSubtreeTree(rootFor(block));
60 91
@@ -119,12 +150,9 @@
119 150 });
120 151
121 152 if (!response.ok) {
122 153 digest({
123 - error: {
124 - name: response.statusText,
125 - messages: response.statusMessage,
126 - },
154 + error: response,
127 155 details: { source: 'agent', caller: 'pick-workflow' },
128 156 });
129 157 const error = new Error('Bad response from server');
130 158 error.response = response;
@@ -143,14 +171,14 @@
143 171 const { blockSearch: _spent, ...carried } = workflowData ?? {};
144 172 // Schemas: pinned up front when the selection is small enough; otherwise
145 173 // empty until get-block-schemas fetches them into the same field.
146 174 const data = isBlockPatching
147 - ? {
175 + ? await withLinkablePages({
148 176 ...carried,
149 177 blockSchemas: workflowData?.blockSchemas?.length
150 178 ? workflowData.blockSchemas
151 179 : await blockSchemasFor(block),
152 - }
180 + })
153 181 : workflowData;
154 182 const response = await fetch(`${AI_HOST}/api/agent/handle-workflow`, {
155 183 method: 'POST',
156 184 headers: { 'Content-Type': 'application/json' },