@blokkli/editor 2.0.0-alpha.60 → 2.0.0-alpha.62

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.
Files changed (130) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +1 -1
  3. package/dist/modules/agent/index.mjs +2 -5
  4. package/dist/modules/agent/runtime/app/features/agent/Container.vue +3 -3
  5. package/dist/modules/agent/runtime/app/features/agent/Panel/index.vue +15 -3
  6. package/dist/modules/agent/runtime/app/features/agent/index.vue +5 -1
  7. package/dist/modules/agent/runtime/app/features/agent/types.d.ts +2 -1
  8. package/dist/modules/agent/runtime/app/helpers/mutationResult.d.ts +38 -0
  9. package/dist/modules/agent/runtime/app/helpers/mutationResult.js +49 -0
  10. package/dist/modules/agent/runtime/app/prompts/fixReadability.js +3 -3
  11. package/dist/modules/agent/runtime/app/providers/agentProvider.d.ts +2 -1
  12. package/dist/modules/agent/runtime/app/providers/agentProvider.js +6 -6
  13. package/dist/modules/agent/runtime/app/providers/toolsProvider.js +3 -13
  14. package/dist/modules/agent/runtime/app/tools/add_content_search_paragraphs/index.d.ts +25 -0
  15. package/dist/modules/agent/runtime/app/tools/add_content_search_paragraphs/index.js +3 -2
  16. package/dist/modules/agent/runtime/app/tools/add_fragment/index.d.ts +22 -0
  17. package/dist/modules/agent/runtime/app/tools/add_fragment/index.js +3 -2
  18. package/dist/modules/agent/runtime/app/tools/add_media_paragraph/index.d.ts +24 -0
  19. package/dist/modules/agent/runtime/app/tools/add_media_paragraph/index.js +3 -2
  20. package/dist/modules/agent/runtime/app/tools/add_paragraphs/index.d.ts +32 -0
  21. package/dist/modules/agent/runtime/app/tools/add_paragraphs/index.js +6 -4
  22. package/dist/modules/agent/runtime/app/tools/add_reusable_paragraph/index.d.ts +22 -0
  23. package/dist/modules/agent/runtime/app/tools/add_reusable_paragraph/index.js +3 -2
  24. package/dist/modules/agent/runtime/app/tools/add_template/index.d.ts +22 -0
  25. package/dist/modules/agent/runtime/app/tools/add_template/index.js +5 -3
  26. package/dist/modules/agent/runtime/app/tools/ask_question/index.d.ts +3 -3
  27. package/dist/modules/agent/runtime/app/tools/ask_question/index.js +7 -6
  28. package/dist/modules/agent/runtime/app/tools/auto_translate_paragraphs/index.d.ts +10 -1
  29. package/dist/modules/agent/runtime/app/tools/auto_translate_paragraphs/index.js +4 -4
  30. package/dist/modules/agent/runtime/app/tools/check_readability_for_texts/index.d.ts +17 -0
  31. package/dist/modules/agent/runtime/app/tools/check_readability_for_texts/index.js +2 -2
  32. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/index.d.ts +10 -1
  33. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/index.js +3 -2
  34. package/dist/modules/agent/runtime/app/tools/delete_paragraphs/index.d.ts +16 -0
  35. package/dist/modules/agent/runtime/app/tools/delete_paragraphs/index.js +3 -2
  36. package/dist/modules/agent/runtime/app/tools/detach_reusable_paragraph/index.d.ts +16 -0
  37. package/dist/modules/agent/runtime/app/tools/detach_reusable_paragraph/index.js +3 -2
  38. package/dist/modules/agent/runtime/app/tools/duplicate_paragraphs/index.d.ts +22 -0
  39. package/dist/modules/agent/runtime/app/tools/duplicate_paragraphs/index.js +5 -3
  40. package/dist/modules/agent/runtime/app/tools/find_paragraphs/index.d.ts +31 -0
  41. package/dist/modules/agent/runtime/app/tools/find_paragraphs/index.js +7 -7
  42. package/dist/modules/agent/runtime/app/tools/get_all_fragments/index.d.ts +7 -0
  43. package/dist/modules/agent/runtime/app/tools/get_all_fragments/index.js +2 -2
  44. package/dist/modules/agent/runtime/app/tools/get_all_page_content/index.d.ts +10 -0
  45. package/dist/modules/agent/runtime/app/tools/get_all_page_content/index.js +2 -2
  46. package/dist/modules/agent/runtime/app/tools/get_bundle_info/index.d.ts +35 -0
  47. package/dist/modules/agent/runtime/app/tools/get_bundle_info/index.js +2 -2
  48. package/dist/modules/agent/runtime/app/tools/get_child_paragraphs/index.d.ts +20 -0
  49. package/dist/modules/agent/runtime/app/tools/get_child_paragraphs/index.js +2 -2
  50. package/dist/modules/agent/runtime/app/tools/get_content_fields/index.d.ts +30 -0
  51. package/dist/modules/agent/runtime/app/tools/get_content_fields/index.js +7 -6
  52. package/dist/modules/agent/runtime/app/tools/get_mutation_history/index.d.ts +25 -0
  53. package/dist/modules/agent/runtime/app/tools/get_mutation_history/index.js +2 -2
  54. package/dist/modules/agent/runtime/app/tools/get_page_structure/index.d.ts +8 -0
  55. package/dist/modules/agent/runtime/app/tools/get_page_structure/index.js +2 -2
  56. package/dist/modules/agent/runtime/app/tools/get_page_text/index.d.ts +6 -0
  57. package/dist/modules/agent/runtime/app/tools/get_page_text/index.js +2 -2
  58. package/dist/modules/agent/runtime/app/tools/get_paragraph_context/index.d.ts +81 -0
  59. package/dist/modules/agent/runtime/app/tools/get_paragraph_context/index.js +20 -12
  60. package/dist/modules/agent/runtime/app/tools/get_paragraph_options/index.d.ts +14 -0
  61. package/dist/modules/agent/runtime/app/tools/get_paragraph_options/index.js +2 -2
  62. package/dist/modules/agent/runtime/app/tools/get_paragraphs_in_viewport/index.d.ts +38 -0
  63. package/dist/modules/agent/runtime/app/tools/get_paragraphs_in_viewport/index.js +7 -6
  64. package/dist/modules/agent/runtime/app/tools/get_readability_issues/index.d.ts +12 -0
  65. package/dist/modules/agent/runtime/app/tools/get_readability_issues/index.js +2 -2
  66. package/dist/modules/agent/runtime/app/tools/get_referenced_entities/index.d.ts +14 -0
  67. package/dist/modules/agent/runtime/app/tools/get_referenced_entities/index.js +2 -2
  68. package/dist/modules/agent/runtime/app/tools/get_selected_paragraphs/index.d.ts +9 -0
  69. package/dist/modules/agent/runtime/app/tools/get_selected_paragraphs/index.js +2 -2
  70. package/dist/modules/agent/runtime/app/tools/go_to_history_index/index.d.ts +16 -0
  71. package/dist/modules/agent/runtime/app/tools/go_to_history_index/index.js +3 -2
  72. package/dist/modules/agent/runtime/app/tools/move_paragraphs/index.d.ts +22 -0
  73. package/dist/modules/agent/runtime/app/tools/move_paragraphs/index.js +3 -2
  74. package/dist/modules/agent/runtime/app/tools/rearrange_paragraphs/index.d.ts +21 -0
  75. package/dist/modules/agent/runtime/app/tools/rearrange_paragraphs/index.js +3 -2
  76. package/dist/modules/agent/runtime/app/tools/replace_content_search_item/index.d.ts +20 -0
  77. package/dist/modules/agent/runtime/app/tools/replace_content_search_item/index.js +3 -2
  78. package/dist/modules/agent/runtime/app/tools/replace_media_field/index.d.ts +19 -0
  79. package/dist/modules/agent/runtime/app/tools/replace_media_field/index.js +3 -2
  80. package/dist/modules/agent/runtime/app/tools/schemas.d.ts +13 -5
  81. package/dist/modules/agent/runtime/app/tools/schemas.js +17 -10
  82. package/dist/modules/agent/runtime/app/tools/search_content/index.d.ts +15 -0
  83. package/dist/modules/agent/runtime/app/tools/search_content/index.js +8 -7
  84. package/dist/modules/agent/runtime/app/tools/search_media/index.d.ts +5 -1
  85. package/dist/modules/agent/runtime/app/tools/search_media/index.js +2 -2
  86. package/dist/modules/agent/runtime/app/tools/search_reusable_paragraphs/index.d.ts +16 -0
  87. package/dist/modules/agent/runtime/app/tools/search_reusable_paragraphs/index.js +2 -2
  88. package/dist/modules/agent/runtime/app/tools/search_templates/index.d.ts +13 -0
  89. package/dist/modules/agent/runtime/app/tools/search_templates/index.js +2 -2
  90. package/dist/modules/agent/runtime/app/tools/search_text/index.d.ts +15 -0
  91. package/dist/modules/agent/runtime/app/tools/search_text/index.js +2 -2
  92. package/dist/modules/agent/runtime/app/tools/select_media/index.d.ts +2 -2
  93. package/dist/modules/agent/runtime/app/tools/select_media/index.js +2 -2
  94. package/dist/modules/agent/runtime/app/tools/set_paragraph_options/index.d.ts +19 -0
  95. package/dist/modules/agent/runtime/app/tools/set_paragraph_options/index.js +3 -2
  96. package/dist/modules/agent/runtime/app/tools/swap_paragraphs/index.d.ts +17 -0
  97. package/dist/modules/agent/runtime/app/tools/swap_paragraphs/index.js +3 -2
  98. package/dist/modules/agent/runtime/app/tools/update_text_fields/index.d.ts +13 -4
  99. package/dist/modules/agent/runtime/app/tools/update_text_fields/index.js +8 -7
  100. package/dist/modules/agent/runtime/app/tools/web_fetch/index.d.ts +17 -0
  101. package/dist/modules/agent/runtime/app/tools/web_fetch/index.js +2 -2
  102. package/dist/modules/agent/runtime/app/types/index.d.ts +6 -9
  103. package/dist/modules/agent/runtime/app/types/index.js +4 -3
  104. package/dist/modules/agent/runtime/server/agent.js +1 -1
  105. package/dist/modules/agent/runtime/server/classes/Session/index.d.ts +2 -2
  106. package/dist/modules/agent/runtime/server/classes/Session/index.js +6 -5
  107. package/dist/modules/agent/runtime/server/default-system-prompts/important-rules.js +2 -1
  108. package/dist/modules/agent/runtime/shared/toolParams.d.ts +19 -0
  109. package/dist/modules/agent/runtime/shared/toolParams.js +6 -0
  110. package/dist/modules/agent/runtime/shared/types.d.ts +23 -4
  111. package/dist/modules/agent/runtime/shared/types.js +6 -1
  112. package/dist/modules/charts/runtime/features/charts/Editor/ColorDropdown/index.vue +4 -13
  113. package/dist/modules/drupal/runtime/adapter/index.js +36 -26
  114. package/dist/runtime/editor/components/Actions/Title/index.vue +7 -6
  115. package/dist/runtime/editor/components/DiffApproval/index.vue +2 -2
  116. package/dist/runtime/editor/components/Dropdown/index.vue +0 -39
  117. package/dist/runtime/editor/components/DropdownItem/index.d.vue.ts +12 -2
  118. package/dist/runtime/editor/components/DropdownItem/index.vue +46 -2
  119. package/dist/runtime/editor/components/DropdownItem/index.vue.d.ts +12 -2
  120. package/dist/runtime/editor/components/FlexTextarea/index.d.vue.ts +1 -1
  121. package/dist/runtime/editor/components/FlexTextarea/index.vue.d.ts +1 -1
  122. package/dist/runtime/editor/css/output.css +1 -1
  123. package/dist/runtime/editor/features/changelog/changelog.json +9 -1
  124. package/dist/runtime/editor/plugins/Sidebar/Detached/index.d.vue.ts +1 -1
  125. package/dist/runtime/editor/plugins/Sidebar/Detached/index.vue.d.ts +1 -1
  126. package/dist/runtime/editor/plugins/Sidebar/index.d.vue.ts +2 -2
  127. package/dist/runtime/editor/plugins/Sidebar/index.vue.d.ts +2 -2
  128. package/dist/runtime/editor/translations/de.json +2 -0
  129. package/dist/runtime/editor/translations/gsw_CH.json +9 -0
  130. package/package.json +3 -2
package/dist/module.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@blokkli/editor",
3
3
  "configKey": "blokkli",
4
- "version": "2.0.0-alpha.60",
4
+ "version": "2.0.0-alpha.62",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.15.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -19,7 +19,7 @@ import 'typescript';
19
19
  import 'oxc-walker';
20
20
 
21
21
  const name = "@blokkli/editor";
22
- const version = "2.0.0-alpha.60";
22
+ const version = "2.0.0-alpha.62";
23
23
 
24
24
  function validateOption(optionKey, option, icons) {
25
25
  const errors = [];
@@ -176,8 +176,8 @@ function createClientTemplate(toolCollector, skillsCollector, options, routes) {
176
176
  const entries = toolsWithNames.map((t) => {
177
177
  const importPath = rel(t.filePath);
178
178
  return ` '${t.name}': {
179
- params: _ToolParams<typeof import('${importPath}')['default']>
180
- result: _ToolResult<typeof import('${importPath}')['default']>
179
+ params: z.infer<typeof import('${importPath}')['paramsSchema']>
180
+ result: z.infer<typeof import('${importPath}')['resultSchema']>
181
181
  }`;
182
182
  }).join("\n");
183
183
  toolMapBlock = `export interface AgentToolMap {
@@ -192,9 +192,6 @@ ${entries}
192
192
  import type { McpToolDefinition } from '#blokkli/agent/app/types'
193
193
  import type { AgentModelDefinition } from '#blokkli/agent/shared/types'
194
194
 
195
- type _ToolParams<T> = T extends { paramsSchema: infer P extends z.ZodType } ? z.infer<P> : never
196
- type _ToolResult<T> = T extends { resultSchema: infer R extends z.ZodType } ? z.infer<R> : never
197
-
198
195
  ${toolMapBlock}
199
196
 
200
197
  export type AgentToolName = ${agentToolNameType}
@@ -78,7 +78,7 @@ const agentApp = {
78
78
  provide(INJECT_AGENT_APP, agentApp);
79
79
  async function consumePromptRequest(request) {
80
80
  emit("consumed");
81
- const { prompt, selectedUuids } = request;
81
+ const { prompt, selectedBlocks } = request;
82
82
  const promptText = prompt.getPrompt(blokkli);
83
83
  const userPromptText = prompt.getUserPrompt?.(blokkli);
84
84
  let preSeededResults = void 0;
@@ -86,7 +86,7 @@ async function consumePromptRequest(request) {
86
86
  if (prompt.preExecute) {
87
87
  const preResult = await prompt.preExecute({
88
88
  app: blokkli,
89
- selectedUuids,
89
+ selectedBlocks,
90
90
  runTool: tools.runForPrompt
91
91
  });
92
92
  if (preResult) {
@@ -97,7 +97,7 @@ async function consumePromptRequest(request) {
97
97
  agent.sendPrompt({
98
98
  prompt: promptText,
99
99
  displayPrompt: userPromptText,
100
- selectedUuids,
100
+ selectedBlocks,
101
101
  autoLoadTools: prompt.tools,
102
102
  autoLoadSkills: prompt.skills,
103
103
  preSeededResults,
@@ -243,16 +243,27 @@ function scrollToBottomOnSend() {
243
243
  isAtBottom.value = true;
244
244
  nextTick(scrollToBottom);
245
245
  }
246
+ function snapshotInitialSelection() {
247
+ if (conversation.value.length) return void 0;
248
+ const items = app.selection.items.value;
249
+ if (!items.length) return void 0;
250
+ return items.map((item) => ({
251
+ uuid: item.uuid,
252
+ bundle: item.bundle,
253
+ label: app.types.getBlockLabel(item.bundle)
254
+ }));
255
+ }
246
256
  function onWelcomePrompt(prompt) {
247
- agent.sendPrompt({ prompt });
257
+ agent.sendPrompt({ prompt, selectedBlocks: snapshotInitialSelection() });
248
258
  scrollToBottomOnSend();
249
259
  }
250
260
  function onSubmit(submitAttachments) {
251
261
  const text = inputValue.value.trim();
252
262
  if (!text && !submitAttachments.length || isProcessing.value || !isConnected.value)
253
263
  return;
264
+ const selectedBlocks = snapshotInitialSelection();
254
265
  if (!submitAttachments.length) {
255
- agent.sendPrompt({ prompt: inputValue.value });
266
+ agent.sendPrompt({ prompt: inputValue.value, selectedBlocks });
256
267
  } else {
257
268
  const attachmentBlocks = submitAttachments.map(
258
269
  (att) => `<attachment type="${att.type}">
@@ -265,7 +276,8 @@ ${attachmentBlocks}` : attachmentBlocks;
265
276
  agent.sendPrompt({
266
277
  prompt,
267
278
  displayPrompt: text,
268
- attachments: submitAttachments
279
+ attachments: submitAttachments,
280
+ selectedBlocks
269
281
  });
270
282
  }
271
283
  inputValue.value = "";
@@ -149,7 +149,11 @@ defineItemDropdownAction(() => {
149
149
  app.eventBus.emit("sidebar:open", "agent");
150
150
  pendingPromptRequest.value = {
151
151
  prompt,
152
- selectedUuids: [...app.selection.uuids.value]
152
+ selectedBlocks: app.selection.items.value.map((item) => ({
153
+ uuid: item.uuid,
154
+ bundle: item.bundle,
155
+ label: app.types.getBlockLabel(item.bundle)
156
+ }))
153
157
  };
154
158
  }
155
159
  };
@@ -2,13 +2,14 @@ import type { AgentPromptDefinition } from '#blokkli/agent/app/types';
2
2
  import type { BlokkliUser } from '#blokkli/editor/types/user';
3
3
  import type { AdapterSearchArguments } from '#blokkli/editor/adapter';
4
4
  import type { PluginConfigInput } from '#blokkli/editor/types/pluginConfig';
5
+ import type { SelectedBlock } from '#blokkli/agent/shared/types';
5
6
  /**
6
7
  * A pending request from the outer feature's item-dropdown action that the
7
8
  * inner container consumes on mount (or on change if already mounted).
8
9
  */
9
10
  export type PendingPromptRequest = {
10
11
  prompt: AgentPromptDefinition;
11
- selectedUuids: string[];
12
+ selectedBlocks: SelectedBlock[];
12
13
  };
13
14
  export type AgentConversationHostInfo = {
14
15
  entityType: string;
@@ -0,0 +1,38 @@
1
+ import type { BlokkliApp } from '#blokkli/editor/types/app';
2
+ /**
3
+ * Tree-shaped entry in the `newParagraphs` payload returned by mutation tools.
4
+ *
5
+ * Mirrors the input shape of `add_paragraphs` — nested children are grouped by
6
+ * paragraph field name so the LLM can verify the structure round-tripped. A
7
+ * flat list was previously emitted; the model could not tell whether a child
8
+ * UUID was actually a sibling that got placed at the top level by mistake.
9
+ */
10
+ export type NewParagraphNode = {
11
+ uuid: string;
12
+ bundle: string;
13
+ paragraphFields?: string[];
14
+ children?: Record<string, NewParagraphNode[]>;
15
+ };
16
+ /**
17
+ * Build the tree-shaped `newParagraphs` payload from a flat list of newly
18
+ * created block UUIDs (computed as the set diff of `getAllUuids()` before vs
19
+ * after a mutation).
20
+ *
21
+ * A block whose host is ALSO in `newUuids` is nested under that parent's
22
+ * `children[fieldName]`. Top-level entries are blocks whose parent already
23
+ * existed before the mutation — these were inserted into the target field.
24
+ *
25
+ * Per-block lookup uses `app.blocks.getBlock` (host metadata) and
26
+ * `app.types.fieldConfig` (paragraph-field discovery), so no extra adapter
27
+ * round-trips are needed.
28
+ */
29
+ export declare function buildNewParagraphsTree(newUuids: string[], app: BlokkliApp, itemEntityType: string): NewParagraphNode[];
30
+ /**
31
+ * Count every node in a `newParagraphs` tree, including nested children.
32
+ *
33
+ * The tree-shaped envelope means a top-level array of length 1 can still
34
+ * represent dozens of added blocks (one parent with many children). Callers
35
+ * that report "added N paragraphs" should count recursively so the figure
36
+ * stays honest.
37
+ */
38
+ export declare function countNewParagraphs(nodes: NewParagraphNode[]): number;
@@ -0,0 +1,49 @@
1
+ export function buildNewParagraphsTree(newUuids, app, itemEntityType) {
2
+ if (!newUuids.length) return [];
3
+ const newSet = new Set(newUuids);
4
+ const nodes = /* @__PURE__ */ new Map();
5
+ const roots = [];
6
+ const pendingChildren = /* @__PURE__ */ new Map();
7
+ for (const uuid of newUuids) {
8
+ const block = app.blocks.getBlock(uuid);
9
+ if (!block) continue;
10
+ const paragraphFields = app.types.fieldConfig.forEntityTypeAndBundle(itemEntityType, block.bundle).map((f) => f.name);
11
+ const node = {
12
+ uuid,
13
+ bundle: block.bundle,
14
+ ...paragraphFields.length ? { paragraphFields } : {}
15
+ };
16
+ nodes.set(uuid, node);
17
+ const host = block.host;
18
+ if (host.type === itemEntityType && newSet.has(host.uuid)) {
19
+ let perField = pendingChildren.get(host.uuid);
20
+ if (!perField) {
21
+ perField = /* @__PURE__ */ new Map();
22
+ pendingChildren.set(host.uuid, perField);
23
+ }
24
+ const bucket = perField.get(host.fieldName) ?? [];
25
+ bucket.push(node);
26
+ perField.set(host.fieldName, bucket);
27
+ } else {
28
+ roots.push(node);
29
+ }
30
+ }
31
+ for (const [parentUuid, perField] of pendingChildren) {
32
+ const parent = nodes.get(parentUuid);
33
+ if (!parent) continue;
34
+ parent.children = Object.fromEntries(perField);
35
+ }
36
+ return roots;
37
+ }
38
+ export function countNewParagraphs(nodes) {
39
+ let total = 0;
40
+ for (const node of nodes) {
41
+ total += 1;
42
+ if (node.children) {
43
+ for (const childList of Object.values(node.children)) {
44
+ total += countNewParagraphs(childList);
45
+ }
46
+ }
47
+ }
48
+ return total;
49
+ }
@@ -28,11 +28,11 @@ export default defineBlokkliAgentPrompt({
28
28
  "Fix the readability of the selected paragraphs."
29
29
  );
30
30
  },
31
- async preExecute({ selectedUuids, runTool }) {
31
+ async preExecute({ selectedBlocks, runTool }) {
32
32
  const readability = await runTool(
33
33
  "get_readability_issues",
34
- selectedUuids.length ? {
35
- uuids: selectedUuids
34
+ selectedBlocks.length ? {
35
+ uuids: selectedBlocks.map((b) => b.uuid)
36
36
  } : {}
37
37
  );
38
38
  const fields = Object.entries(readability.result).flatMap(
@@ -1,5 +1,6 @@
1
1
  import { type Ref } from '#imports';
2
2
  import type { Attachment, PreSeededToolResult, AutoExecuteTool } from '#blokkli/agent/app/types';
3
+ import type { SelectedBlock } from '#blokkli/agent/shared/types';
3
4
  import type { BlokkliApp } from '#blokkli/editor/types/app';
4
5
  import type { FullBlokkliAdapter } from '#blokkli/editor/adapter';
5
6
  import type { SocketProvider } from './socketProvider.js';
@@ -9,7 +10,7 @@ import type { ToolsProvider } from './toolsProvider.js';
9
10
  export type SendPromptOptions = {
10
11
  prompt: string;
11
12
  displayPrompt?: string;
12
- selectedUuids?: string[];
13
+ selectedBlocks?: SelectedBlock[];
13
14
  attachments?: Attachment[];
14
15
  autoLoadTools?: string[];
15
16
  autoLoadSkills?: string[];
@@ -9,19 +9,19 @@ function buildSendContext(options) {
9
9
  const {
10
10
  prompt,
11
11
  displayPrompt,
12
- selectedUuids,
12
+ selectedBlocks,
13
13
  autoLoadTools,
14
14
  autoLoadSkills,
15
15
  preSeededResults,
16
16
  autoExecuteTools,
17
17
  promptId
18
18
  } = options;
19
- const hasData = !!promptId || displayPrompt !== void 0 && displayPrompt !== prompt || !!selectedUuids?.length || !!autoLoadTools?.length || !!autoLoadSkills?.length || !!preSeededResults?.length || !!autoExecuteTools?.length;
19
+ const hasData = !!promptId || displayPrompt !== void 0 && displayPrompt !== prompt || !!selectedBlocks?.length || !!autoLoadTools?.length || !!autoLoadSkills?.length || !!preSeededResults?.length || !!autoExecuteTools?.length;
20
20
  if (!hasData) return void 0;
21
21
  return {
22
22
  promptId,
23
23
  serverPrompt: displayPrompt !== void 0 && displayPrompt !== prompt ? prompt : void 0,
24
- selectedUuids: selectedUuids?.length ? [...selectedUuids] : void 0,
24
+ selectedBlocks: selectedBlocks?.length ? [...selectedBlocks] : void 0,
25
25
  autoLoadTools: autoLoadTools?.length ? [...autoLoadTools] : void 0,
26
26
  autoLoadSkills: autoLoadSkills?.length ? [...autoLoadSkills] : void 0,
27
27
  preSeededResults: preSeededResults?.length ? preSeededResults : void 0,
@@ -217,7 +217,7 @@ export default function agentProvider({
217
217
  const {
218
218
  prompt,
219
219
  displayPrompt,
220
- selectedUuids,
220
+ selectedBlocks,
221
221
  attachments,
222
222
  autoLoadTools,
223
223
  autoLoadSkills,
@@ -280,7 +280,7 @@ export default function agentProvider({
280
280
  socket.send({
281
281
  type: "start",
282
282
  prompt,
283
- selectedUuids: selectedUuids?.length ? selectedUuids : void 0,
283
+ selectedBlocks: selectedBlocks?.length ? selectedBlocks : void 0,
284
284
  autoLoadTools: resolvedAutoLoadTools?.length ? resolvedAutoLoadTools : void 0,
285
285
  autoLoadSkills: resolvedAutoLoadSkills?.length ? resolvedAutoLoadSkills : void 0,
286
286
  preSeededResults: serverPreSeeded,
@@ -323,7 +323,7 @@ export default function agentProvider({
323
323
  displayPrompt: isEdit ? void 0 : displayedText,
324
324
  attachments: target.attachments,
325
325
  rollbackToUserMessageIndex: userMessageIndex,
326
- selectedUuids: ctx?.selectedUuids,
326
+ selectedBlocks: ctx?.selectedBlocks,
327
327
  autoLoadTools: ctx?.autoLoadTools,
328
328
  autoLoadSkills: ctx?.autoLoadSkills,
329
329
  preSeededResults: isEdit ? void 0 : ctx?.preSeededResults,
@@ -11,6 +11,7 @@ import {
11
11
  asRecord,
12
12
  splitMeta
13
13
  } from "#blokkli/agent/app/helpers";
14
+ import { buildNewParagraphsTree } from "#blokkli/agent/app/helpers/mutationResult";
14
15
  import { mcpTools } from "#blokkli-build/agent-client";
15
16
  import { itemEntityType } from "#blokkli-build/config";
16
17
  import { generateId } from "#blokkli/agent/app/helpers/id";
@@ -104,22 +105,11 @@ export default function toolsProvider({
104
105
  return newUuids;
105
106
  }
106
107
  function buildMutationResult(newUuids) {
107
- const newParagraphs = action.type === "add" && newUuids.length ? newUuids.map((uuid) => {
108
- const block = app.blocks.getBlock(uuid);
109
- if (!block) return null;
110
- const blockFieldNames = app.types.fieldConfig.forEntityTypeAndBundle(itemEntityType, block.bundle).map((f) => f.name);
111
- return {
112
- uuid,
113
- bundle: block.bundle,
114
- ...blockFieldNames.length ? { paragraphFields: blockFieldNames } : {}
115
- };
116
- }).filter(
117
- (b) => b !== null
118
- ) : void 0;
108
+ const newParagraphs = action.type === "add" ? buildNewParagraphsTree(newUuids, app, itemEntityType) : [];
119
109
  return {
120
110
  success: true,
121
111
  historyIndex: state.currentMutationIndex.value,
122
- newParagraphs: newParagraphs?.length ? newParagraphs : void 0,
112
+ newParagraphs: newParagraphs.length ? newParagraphs : void 0,
123
113
  ...action.result
124
114
  };
125
115
  }
@@ -1,2 +1,27 @@
1
+ import { z } from 'zod';
2
+ export declare const paramsSchema: z.ZodObject<{
3
+ itemId: z.ZodString;
4
+ itemEntityType: z.ZodString;
5
+ itemEntityBundle: z.ZodString;
6
+ targetBundle: z.ZodString;
7
+ parent: z.ZodObject<{
8
+ type: z.ZodString;
9
+ uuid: z.ZodString;
10
+ field: z.ZodString;
11
+ }, z.core.$strip>;
12
+ position: z.ZodDefault<z.ZodOptional<z.ZodString>>;
13
+ }, z.core.$strip>;
14
+ export declare const resultSchema: z.ZodUnion<readonly [z.ZodObject<{
15
+ type: z.ZodEnum<{
16
+ rewrite: "rewrite";
17
+ delete: "delete";
18
+ add: "add";
19
+ move: "move";
20
+ options: "options";
21
+ }>;
22
+ label: z.ZodString;
23
+ }, z.core.$strip>, z.ZodObject<{
24
+ error: z.ZodString;
25
+ }, z.core.$strip>]>;
1
26
  declare const _default: any;
2
27
  export default _default;
@@ -3,7 +3,7 @@ import { defineBlokkliAgentTool } from "#blokkli/agent/app/composables";
3
3
  import { mutationResultSchema, parentSchema, positionSchema } from "../schemas.js";
4
4
  import { resolvePosition } from "../helpers.js";
5
5
  import { requireBundlePermission } from "../../helpers/validation.js";
6
- const paramsSchema = z.object({
6
+ export const paramsSchema = z.object({
7
7
  itemId: z.string().describe("Content item ID from search_content results"),
8
8
  itemEntityType: z.string().describe("Entity type of the content item"),
9
9
  itemEntityBundle: z.string().describe("Entity bundle of the content item"),
@@ -13,6 +13,7 @@ const paramsSchema = z.object({
13
13
  parent: parentSchema.describe("The parent entity to add the paragraph to"),
14
14
  position: positionSchema
15
15
  });
16
+ export const resultSchema = mutationResultSchema;
16
17
  export default defineBlokkliAgentTool({
17
18
  name: "add_content_search_paragraphs",
18
19
  description: "Add a paragraph using a content item from search results. Use search_content first to find content items, then use this tool to add one to the page.",
@@ -28,7 +29,7 @@ export default defineBlokkliAgentTool({
28
29
  );
29
30
  },
30
31
  paramsSchema,
31
- resultSchema: mutationResultSchema,
32
+ resultSchema,
32
33
  requiredAdapterMethods: ["addContentSearchItem"],
33
34
  execute(ctx, params) {
34
35
  const denied = requireBundlePermission(
@@ -1,2 +1,24 @@
1
+ import { z } from 'zod';
2
+ export declare const paramsSchema: z.ZodObject<{
3
+ name: z.ZodString;
4
+ parent: z.ZodObject<{
5
+ type: z.ZodString;
6
+ uuid: z.ZodString;
7
+ field: z.ZodString;
8
+ }, z.core.$strip>;
9
+ position: z.ZodDefault<z.ZodOptional<z.ZodString>>;
10
+ }, z.core.$strip>;
11
+ export declare const resultSchema: z.ZodUnion<readonly [z.ZodObject<{
12
+ type: z.ZodEnum<{
13
+ rewrite: "rewrite";
14
+ delete: "delete";
15
+ add: "add";
16
+ move: "move";
17
+ options: "options";
18
+ }>;
19
+ label: z.ZodString;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ error: z.ZodString;
22
+ }, z.core.$strip>]>;
1
23
  declare const _default: any;
2
24
  export default _default;
@@ -3,11 +3,12 @@ import { defineBlokkliAgentTool } from "#blokkli/agent/app/composables";
3
3
  import { mutationResultSchema, parentSchema, positionSchema } from "../schemas.js";
4
4
  import { resolvePosition } from "../helpers.js";
5
5
  import { fragmentBlockBundle } from "#blokkli-build/config";
6
- const paramsSchema = z.object({
6
+ export const paramsSchema = z.object({
7
7
  name: z.string().describe("The fragment name to add"),
8
8
  parent: parentSchema.describe("The parent entity to add the fragment to"),
9
9
  position: positionSchema
10
10
  });
11
+ export const resultSchema = mutationResultSchema;
11
12
  export default defineBlokkliAgentTool({
12
13
  name: "add_fragment",
13
14
  description: "Add a fragment paragraph to the page.",
@@ -19,7 +20,7 @@ export default defineBlokkliAgentTool({
19
20
  return $t("aiAgentAddFragmentRunning", "Adding fragment", { more: true });
20
21
  },
21
22
  paramsSchema,
22
- resultSchema: mutationResultSchema,
23
+ resultSchema,
23
24
  requiredAdapterMethods: ["fragmentsAddBlock"],
24
25
  execute(ctx, params) {
25
26
  const { fields, definitions, permissions } = ctx.app;
@@ -1,2 +1,26 @@
1
+ import { z } from 'zod';
2
+ export declare const paramsSchema: z.ZodObject<{
3
+ mediaId: z.ZodString;
4
+ mediaBundle: z.ZodString;
5
+ targetBundle: z.ZodString;
6
+ parent: z.ZodObject<{
7
+ type: z.ZodString;
8
+ uuid: z.ZodString;
9
+ field: z.ZodString;
10
+ }, z.core.$strip>;
11
+ position: z.ZodDefault<z.ZodOptional<z.ZodString>>;
12
+ }, z.core.$strip>;
13
+ export declare const resultSchema: z.ZodUnion<readonly [z.ZodObject<{
14
+ type: z.ZodEnum<{
15
+ rewrite: "rewrite";
16
+ delete: "delete";
17
+ add: "add";
18
+ move: "move";
19
+ options: "options";
20
+ }>;
21
+ label: z.ZodString;
22
+ }, z.core.$strip>, z.ZodObject<{
23
+ error: z.ZodString;
24
+ }, z.core.$strip>]>;
1
25
  declare const _default: any;
2
26
  export default _default;
@@ -3,7 +3,7 @@ import { defineBlokkliAgentTool } from "#blokkli/agent/app/composables";
3
3
  import { mutationResultSchema, parentSchema, positionSchema } from "../schemas.js";
4
4
  import { resolvePosition } from "../helpers.js";
5
5
  import { requireBundlePermission } from "../../helpers/validation.js";
6
- const paramsSchema = z.object({
6
+ export const paramsSchema = z.object({
7
7
  mediaId: z.string().describe("Media item ID from search_media results"),
8
8
  mediaBundle: z.string().describe('Media bundle type (e.g., "image")'),
9
9
  targetBundle: z.string().describe(
@@ -12,6 +12,7 @@ const paramsSchema = z.object({
12
12
  parent: parentSchema.describe("The parent entity to add the paragraph to"),
13
13
  position: positionSchema
14
14
  });
15
+ export const resultSchema = mutationResultSchema;
15
16
  export default defineBlokkliAgentTool({
16
17
  name: "add_media_paragraph",
17
18
  description: "Add a paragraph using a media item from the library. Use search_media first to find media items, then use this tool to add one to the page.",
@@ -25,7 +26,7 @@ export default defineBlokkliAgentTool({
25
26
  });
26
27
  },
27
28
  paramsSchema,
28
- resultSchema: mutationResultSchema,
29
+ resultSchema,
29
30
  requiredAdapterMethods: ["mediaLibraryAddBlock"],
30
31
  execute(ctx, params) {
31
32
  const denied = requireBundlePermission(
@@ -1,2 +1,34 @@
1
+ import { z } from 'zod';
2
+ type OptionValue = string | boolean | number | string[];
3
+ type BlockInput = {
4
+ bundle: string;
5
+ contentFields?: Record<string, string | {
6
+ entityType: string;
7
+ entityId: string;
8
+ }>;
9
+ options?: Record<string, OptionValue>;
10
+ children?: Record<string, BlockInput[]>;
11
+ };
12
+ export declare const paramsSchema: z.ZodObject<{
13
+ paragraphs: z.ZodArray<z.ZodType<BlockInput, unknown, z.core.$ZodTypeInternals<BlockInput, unknown>>>;
14
+ parent: z.ZodObject<{
15
+ type: z.ZodString;
16
+ uuid: z.ZodString;
17
+ field: z.ZodString;
18
+ }, z.core.$strip>;
19
+ position: z.ZodDefault<z.ZodOptional<z.ZodString>>;
20
+ }, z.core.$strip>;
21
+ export declare const resultSchema: z.ZodUnion<readonly [z.ZodObject<{
22
+ type: z.ZodEnum<{
23
+ rewrite: "rewrite";
24
+ delete: "delete";
25
+ add: "add";
26
+ move: "move";
27
+ options: "options";
28
+ }>;
29
+ label: z.ZodString;
30
+ }, z.core.$strip>, z.ZodObject<{
31
+ error: z.ZodString;
32
+ }, z.core.$strip>]>;
1
33
  declare const _default: any;
2
34
  export default _default;
@@ -16,6 +16,7 @@ import {
16
16
  import { validateFieldCardinality } from "../../helpers/validation.js";
17
17
  import { getFieldKey } from "#blokkli/helpers";
18
18
  import { optionValueToStorable } from "#blokkli/editor/helpers/options";
19
+ import { countNewParagraphs } from "#blokkli/agent/app/helpers/mutationResult";
19
20
  const contentFieldValueSchema = z.union([
20
21
  z.string().describe(
21
22
  "Text value for plain/markup content fields, or a URL string (starting with http) for link content fields"
@@ -46,7 +47,7 @@ const blockSchema = z.object({
46
47
  "Nested child paragraphs keyed by paragraph field name. Recursive \u2014 children can also have children."
47
48
  )
48
49
  });
49
- const paramsSchema = z.object({
50
+ export const paramsSchema = z.object({
50
51
  paragraphs: z.array(blockSchema).min(1).describe("Array of paragraphs to add, in order"),
51
52
  parent: parentSchema.describe("The parent entity to add the paragraphs to"),
52
53
  position: positionSchema
@@ -225,18 +226,19 @@ function collectAllUuids(blocks) {
225
226
  }
226
227
  return uuids;
227
228
  }
229
+ export const resultSchema = mutationResultSchema;
228
230
  export default defineBlokkliAgentTool({
229
231
  name: "add_paragraphs",
230
- description: "Add one or more new paragraphs to the page. Supports nested structures via the `children` property \u2014 define entire paragraph trees in a single call. IMPORTANT: Always provide content field values (text, media/entity references) directly via contentFields, instead of adding empty paragraphs! For reference content fields (media), set the value to { entityType, entityId } from search_media results. NOTE: You can ONLY provide content fields, NOT paragraph fields! For nested paragraphs, use the `children` property keyed by paragraph field name. You can also set paragraph options inline via the `options` property (key-value pairs).",
232
+ description: "Add one or more new paragraphs to the page. Supports nested structures via the `children` property \u2014 define entire paragraph trees in a single call. IMPORTANT: Always provide content field values (text, media/entity references) directly via contentFields, instead of adding empty paragraphs! For reference content fields (media), set the value to { entityType, entityId } from search_media results. NOTE: You can ONLY provide content fields, NOT paragraph fields! For nested paragraphs, use the `children` property keyed by paragraph field name. You can also set paragraph options inline via the `options` property (key-value pairs). The success result mirrors the input shape: each top-level entry in `newParagraphs` includes its own `children` keyed by paragraph field, so the structure round-trips and a nested child does NOT appear as a sibling \u2014 treat the tree as the source of truth instead of guessing from order.",
231
233
  category: "mutation",
232
234
  lazy: false,
233
- prunedSummary: (r) => r.success ? `added ${r.newParagraphs?.length || 0} paragraphs` : "rejected",
235
+ prunedSummary: (r) => r.success ? `added ${countNewParagraphs(r.newParagraphs ?? [])} paragraphs` : "rejected",
234
236
  modes: ["editing"],
235
237
  label($t) {
236
238
  return $t("aiAgentAddBlocksRunning", "Adding blocks", { more: true });
237
239
  },
238
240
  paramsSchema,
239
- resultSchema: mutationResultSchema,
241
+ resultSchema,
240
242
  requiredAdapterMethods: ["addNewBlocks"],
241
243
  execute(ctx, params) {
242
244
  const { types } = ctx.app;
@@ -1,2 +1,24 @@
1
+ import { z } from 'zod';
2
+ export declare const paramsSchema: z.ZodObject<{
3
+ libraryItemUuid: z.ZodString;
4
+ parent: z.ZodObject<{
5
+ type: z.ZodString;
6
+ uuid: z.ZodString;
7
+ field: z.ZodString;
8
+ }, z.core.$strip>;
9
+ position: z.ZodDefault<z.ZodOptional<z.ZodString>>;
10
+ }, z.core.$strip>;
11
+ export declare const resultSchema: z.ZodUnion<readonly [z.ZodObject<{
12
+ type: z.ZodEnum<{
13
+ rewrite: "rewrite";
14
+ delete: "delete";
15
+ add: "add";
16
+ move: "move";
17
+ options: "options";
18
+ }>;
19
+ label: z.ZodString;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ error: z.ZodString;
22
+ }, z.core.$strip>]>;
1
23
  declare const _default: any;
2
24
  export default _default;
@@ -4,7 +4,7 @@ import { mutationResultSchema, parentSchema, positionSchema } from "../schemas.j
4
4
  import { resolvePosition, resolveHost } from "../helpers.js";
5
5
  import { requireBundlePermission } from "../../helpers/validation.js";
6
6
  import { fromLibraryBlockBundle } from "#blokkli-build/config";
7
- const paramsSchema = z.object({
7
+ export const paramsSchema = z.object({
8
8
  libraryItemUuid: z.string().describe(
9
9
  "The UUID of the reusable paragraph to add (from search_reusable_paragraphs results)"
10
10
  ),
@@ -13,6 +13,7 @@ const paramsSchema = z.object({
13
13
  ),
14
14
  position: positionSchema
15
15
  });
16
+ export const resultSchema = mutationResultSchema;
16
17
  export default defineBlokkliAgentTool({
17
18
  name: "add_reusable_paragraph",
18
19
  description: "Add a reusable paragraph to the page. Reusable paragraphs stay linked to the original: edits to the paragraph are reflected everywhere it is used. Use search_reusable_paragraphs first to find available paragraphs.",
@@ -26,7 +27,7 @@ export default defineBlokkliAgentTool({
26
27
  });
27
28
  },
28
29
  paramsSchema,
29
- resultSchema: mutationResultSchema,
30
+ resultSchema,
30
31
  requiredAdapterMethods: ["addLibraryItem"],
31
32
  execute(ctx, params) {
32
33
  const denied = requireBundlePermission(
@@ -1,2 +1,24 @@
1
+ import { z } from 'zod';
2
+ export declare const paramsSchema: z.ZodObject<{
3
+ templateUuid: z.ZodString;
4
+ parent: z.ZodObject<{
5
+ type: z.ZodString;
6
+ uuid: z.ZodString;
7
+ field: z.ZodString;
8
+ }, z.core.$strip>;
9
+ position: z.ZodDefault<z.ZodOptional<z.ZodString>>;
10
+ }, z.core.$strip>;
11
+ export declare const resultSchema: z.ZodUnion<readonly [z.ZodObject<{
12
+ type: z.ZodEnum<{
13
+ rewrite: "rewrite";
14
+ delete: "delete";
15
+ add: "add";
16
+ move: "move";
17
+ options: "options";
18
+ }>;
19
+ label: z.ZodString;
20
+ }, z.core.$strip>, z.ZodObject<{
21
+ error: z.ZodString;
22
+ }, z.core.$strip>]>;
1
23
  declare const _default: any;
2
24
  export default _default;