# extendify/trunk/src/Agent/workflows/block-selector/tools/get-block-schemas.js

Extendify, version trunk. 44 lines.

- Page: https://pluginprobe.com/plugins/extendify/trunk/code/src/Agent/workflows/block-selector/tools/get-block-schemas.js
- Raw: https://pluginprobe.com/plugins/extendify/trunk/raw/src/Agent/workflows/block-selector/tools/get-block-schemas.js
- Modified: 2026-08-12T16:23:58+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/extendify/trunk/code/src/Agent/workflows/block-selector/tools/get-block-schemas.js#L10-L20`.

```javascript
import { fetchBlockCodeById } from '@agent/lib/block-code';
import { buildBlockSchema } from '@agent/lib/block-schema';
import { INSERTABLE_BLOCK_TYPES } from '@agent/lib/insertable-blocks';
import { ensureCoreBlocksRegistered } from '@agent/lib/register-blocks';
import { useQuickEditStore } from '@quick-edit/state/store';
import { getBlockType, parse } from '@wordpress/blocks';

// Each picked block's code + per-type schemas, the same shape the single path
// ships up front; `blockTypes` fetches by name for adds not yet on the page.
export default async ({ blockIds = [], blockTypes = [] }) => {
	await ensureCoreBlocksRegistered();
	const { agentBlock } = useQuickEditStore.getState();
	const postId = window.extAgentData?.context?.postId;

	const blocks = (
		await Promise.all(
			blockIds.map(async (blockId) => {
				const code = await fetchBlockCodeById(
					blockId,
					agentBlock?.source,
					postId,
				);
				return { blockId, type: parse(code)[0]?.name, code };
			}),
		)
	).filter(({ type }) => type);

	const schemaByType = {};
	for (const { type } of blocks) {
		schemaByType[type] ??= buildBlockSchema(getBlockType(type));
	}
	for (const type of blockTypes) {
		if (!INSERTABLE_BLOCK_TYPES.includes(type)) continue;
		schemaByType[type] ??= buildBlockSchema(getBlockType(type));
	}
	// Typed so each patch validates against its own block's fields.
	return {
		blocks,
		blockSchemas: Object.entries(schemaByType)
			.filter(([, schema]) => schema)
			.map(([type, schema]) => ({ type, schema })),
	};
};

```
