@blokkli/editor 2.0.0-alpha.39 → 2.0.0-alpha.40

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 (160) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/module.mjs +15 -105
  3. package/dist/modules/agent/index.d.mts +1 -0
  4. package/dist/modules/agent/index.mjs +81 -8
  5. package/dist/modules/agent/runtime/app/composables/agentProvider.d.ts +8 -3
  6. package/dist/modules/agent/runtime/app/composables/agentProvider.js +108 -13
  7. package/dist/modules/agent/runtime/app/features/agent/Panel/DebugGallery/index.vue +7 -6
  8. package/dist/modules/agent/runtime/app/features/agent/Panel/index.d.vue.ts +2 -2
  9. package/dist/modules/agent/runtime/app/features/agent/Panel/index.vue +12 -10
  10. package/dist/modules/agent/runtime/app/features/agent/Panel/index.vue.d.ts +2 -2
  11. package/dist/modules/agent/runtime/app/features/agent/index.vue +29 -5
  12. package/dist/modules/agent/runtime/app/helpers/pageStructure.js +7 -17
  13. package/dist/modules/agent/runtime/app/prompts/fixReadability.d.ts +2 -0
  14. package/dist/modules/agent/runtime/app/prompts/fixReadability.js +49 -0
  15. package/dist/modules/agent/runtime/app/tools/add_paragraphs/index.js +1 -0
  16. package/dist/modules/agent/runtime/app/tools/check_readability/index.js +24 -15
  17. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/Component.d.vue.ts +46 -0
  18. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/Component.vue +739 -0
  19. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/Component.vue.d.ts +46 -0
  20. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/Details/index.d.vue.ts +6 -0
  21. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/Details/index.vue +38 -0
  22. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/Details/index.vue.d.ts +6 -0
  23. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/index.d.ts +38 -0
  24. package/dist/modules/agent/runtime/app/tools/delegate_text_rewrite/index.js +115 -0
  25. package/dist/modules/agent/runtime/app/tools/delete_paragraphs/index.js +1 -0
  26. package/dist/modules/agent/runtime/app/tools/get_all_page_content/index.js +3 -5
  27. package/dist/modules/agent/runtime/app/tools/get_bundle_info/index.js +1 -0
  28. package/dist/modules/agent/runtime/app/tools/get_child_paragraphs/index.js +1 -0
  29. package/dist/modules/agent/runtime/app/tools/get_content_fields/index.js +4 -7
  30. package/dist/modules/agent/runtime/app/tools/get_page_structure/index.js +1 -0
  31. package/dist/modules/agent/runtime/app/tools/get_paragraph_context/index.js +10 -17
  32. package/dist/modules/agent/runtime/app/tools/get_paragraph_options/index.js +1 -0
  33. package/dist/modules/agent/runtime/app/tools/get_paragraphs_in_viewport/index.js +1 -0
  34. package/dist/modules/agent/runtime/app/tools/get_readability_issues/index.js +17 -70
  35. package/dist/modules/agent/runtime/app/tools/get_selected_paragraphs/index.js +1 -0
  36. package/dist/modules/agent/runtime/app/tools/helpers.d.ts +38 -10
  37. package/dist/modules/agent/runtime/app/tools/helpers.js +90 -27
  38. package/dist/modules/agent/runtime/app/tools/move_paragraphs/index.js +1 -0
  39. package/dist/modules/agent/runtime/app/tools/rearrange_paragraphs/index.js +1 -0
  40. package/dist/modules/agent/runtime/app/tools/schemas.d.ts +1 -1
  41. package/dist/modules/agent/runtime/app/tools/update_text_fields/Component.vue +66 -84
  42. package/dist/modules/agent/runtime/app/tools/update_text_fields/index.d.ts +8 -1
  43. package/dist/modules/agent/runtime/app/tools/update_text_fields/index.js +21 -14
  44. package/dist/modules/agent/runtime/app/types/index.d.ts +41 -0
  45. package/dist/modules/agent/runtime/server/Session.d.ts +8 -1
  46. package/dist/modules/agent/runtime/server/Session.js +154 -6
  47. package/dist/modules/agent/runtime/server/agent.js +5 -1
  48. package/dist/modules/agent/runtime/server/default-skills/fixReadability.js +31 -51
  49. package/dist/modules/agent/runtime/server/default-skills/rewriteAndTranslate.js +45 -4
  50. package/dist/modules/agent/runtime/server/providers/anthropic.js +2 -1
  51. package/dist/modules/agent/runtime/server/providers/openai.js +2 -1
  52. package/dist/modules/agent/runtime/server/providers/types.d.ts +2 -0
  53. package/dist/modules/agent/runtime/server/route.d.ts +2 -0
  54. package/dist/modules/agent/runtime/server/route.js +40 -0
  55. package/dist/modules/agent/runtime/server/routing.d.ts +18 -0
  56. package/dist/modules/agent/runtime/server/routing.js +111 -0
  57. package/dist/modules/agent/runtime/server/skills/types.d.ts +10 -0
  58. package/dist/modules/agent/runtime/server/stream.d.ts +2 -0
  59. package/dist/modules/agent/runtime/server/stream.js +190 -0
  60. package/dist/modules/agent/runtime/server/streamParser.d.ts +85 -0
  61. package/dist/modules/agent/runtime/server/streamParser.js +227 -0
  62. package/dist/modules/agent/runtime/server/templates/defineStreamTemplate.d.ts +21 -0
  63. package/dist/modules/agent/runtime/server/templates/defineStreamTemplate.js +3 -0
  64. package/dist/modules/agent/runtime/server/templates/definitions/fixReadability.d.ts +26 -0
  65. package/dist/modules/agent/runtime/server/templates/definitions/fixReadability.js +84 -0
  66. package/dist/modules/agent/runtime/server/templates/definitions/generateContent.d.ts +6 -0
  67. package/dist/modules/agent/runtime/server/templates/definitions/generateContent.js +29 -0
  68. package/dist/modules/agent/runtime/server/templates/definitions/rewrite.d.ts +5 -0
  69. package/dist/modules/agent/runtime/server/templates/definitions/rewrite.js +14 -0
  70. package/dist/modules/agent/runtime/server/templates/definitions/translate.d.ts +5 -0
  71. package/dist/modules/agent/runtime/server/templates/definitions/translate.js +23 -0
  72. package/dist/modules/agent/runtime/server/templates/index.d.ts +37 -0
  73. package/dist/modules/agent/runtime/server/templates/index.js +25 -0
  74. package/dist/modules/agent/runtime/server/templates/types.d.ts +17 -0
  75. package/dist/modules/agent/runtime/server/templates/types.js +0 -0
  76. package/dist/modules/agent/runtime/server/templates/utils.d.ts +5 -0
  77. package/dist/modules/agent/runtime/server/templates/utils.js +69 -0
  78. package/dist/modules/agent/runtime/shared/types.d.ts +18 -0
  79. package/dist/modules/agent/runtime/shared/types.js +16 -1
  80. package/dist/runtime/components/BlokkliItem.d.vue.ts +1 -1
  81. package/dist/runtime/components/BlokkliItem.vue +34 -3
  82. package/dist/runtime/components/BlokkliItem.vue.d.ts +1 -1
  83. package/dist/runtime/editor/components/Actions/index.vue +2 -2
  84. package/dist/runtime/editor/components/AnimationCanvas/index.vue +23 -2
  85. package/dist/runtime/editor/components/DiffApproval/Highlight/Item.d.vue.ts +19 -0
  86. package/dist/runtime/editor/components/DiffApproval/Highlight/Item.vue +106 -0
  87. package/dist/runtime/editor/components/DiffApproval/Highlight/Item.vue.d.ts +19 -0
  88. package/dist/runtime/editor/components/DiffApproval/Highlight/index.d.vue.ts +22 -0
  89. package/dist/runtime/editor/components/DiffApproval/Highlight/index.vue +50 -0
  90. package/dist/runtime/editor/components/DiffApproval/Highlight/index.vue.d.ts +22 -0
  91. package/dist/runtime/editor/components/DiffApproval/Toolbar/index.d.vue.ts +24 -0
  92. package/dist/runtime/editor/components/DiffApproval/Toolbar/index.vue +113 -0
  93. package/dist/runtime/editor/components/DiffApproval/Toolbar/index.vue.d.ts +24 -0
  94. package/dist/runtime/editor/components/DiffApproval/index.d.vue.ts +19 -0
  95. package/dist/runtime/editor/components/DiffApproval/index.vue +158 -0
  96. package/dist/runtime/editor/components/DiffApproval/index.vue.d.ts +19 -0
  97. package/dist/runtime/editor/components/DiffApproval/types.d.ts +7 -0
  98. package/dist/runtime/editor/components/DiffApproval/types.js +0 -0
  99. package/dist/runtime/editor/components/DiffViewer/DiffValue.vue +2 -11
  100. package/dist/runtime/editor/components/DraggableList.vue +1 -1
  101. package/dist/runtime/editor/components/EditProvider.vue +18 -1
  102. package/dist/runtime/editor/components/ShortcutIndicator/index.d.vue.ts +2 -2
  103. package/dist/runtime/editor/components/ShortcutIndicator/index.vue +27 -33
  104. package/dist/runtime/editor/components/ShortcutIndicator/index.vue.d.ts +2 -2
  105. package/dist/runtime/editor/components/index.d.ts +2 -1
  106. package/dist/runtime/editor/components/index.js +2 -0
  107. package/dist/runtime/editor/composables/useEditableFieldOverride.d.ts +2 -0
  108. package/dist/runtime/editor/composables/useEditableFieldOverride.js +21 -15
  109. package/dist/runtime/editor/css/output.css +1 -1
  110. package/dist/runtime/editor/events/index.d.ts +3 -0
  111. package/dist/runtime/editor/features/add-list/index.vue +1 -0
  112. package/dist/runtime/editor/features/analyze/Main.vue +1 -1
  113. package/dist/runtime/editor/features/analyze/analyzers/helpers/Context.d.ts +7 -2
  114. package/dist/runtime/editor/features/analyze/analyzers/helpers/Context.js +6 -1
  115. package/dist/runtime/editor/features/analyze/analyzers/readability.js +52 -222
  116. package/dist/runtime/editor/features/analyze/analyzers/types.d.ts +2 -2
  117. package/dist/runtime/editor/features/analyze/readability/adapterTypes.d.ts +9 -0
  118. package/dist/runtime/editor/features/analyze/readability/adapterTypes.js +0 -0
  119. package/dist/runtime/editor/features/analyze/readability/builtinAnalyzer.d.ts +6 -0
  120. package/dist/runtime/editor/features/analyze/readability/builtinAnalyzer.js +200 -0
  121. package/dist/runtime/editor/features/analyze/readability/chunkHtml.d.ts +15 -0
  122. package/dist/runtime/editor/features/analyze/readability/chunkHtml.js +97 -0
  123. package/dist/runtime/editor/features/analyze/readability/types.d.ts +72 -0
  124. package/dist/runtime/editor/features/analyze/readability/types.js +0 -0
  125. package/dist/runtime/editor/features/artboard/Renderer.vue +9 -5
  126. package/dist/runtime/editor/features/breadcrumbs/index.vue +1 -1
  127. package/dist/runtime/editor/features/dragging-overlay/index.vue +1 -1
  128. package/dist/runtime/editor/features/editable-field/index.vue +1 -1
  129. package/dist/runtime/editor/features/hover/index.vue +1 -1
  130. package/dist/runtime/editor/features/options/index.vue +1 -1
  131. package/dist/runtime/editor/features/selection/AddButtons/Renderer/index.vue +1 -1
  132. package/dist/runtime/editor/features/selection/index.vue +2 -2
  133. package/dist/runtime/editor/features/structure/List/Item/index.vue +1 -3
  134. package/dist/runtime/editor/helpers/diff/index.d.ts +11 -0
  135. package/dist/runtime/editor/helpers/diff/index.js +227 -0
  136. package/dist/runtime/editor/plugins/Sidebar/index.vue +1 -1
  137. package/dist/runtime/editor/providers/analyze.d.ts +2 -1
  138. package/dist/runtime/editor/providers/analyze.js +6 -3
  139. package/dist/runtime/editor/providers/directive.js +1 -0
  140. package/dist/runtime/editor/providers/fieldValue.d.ts +54 -0
  141. package/dist/runtime/editor/providers/fieldValue.js +126 -0
  142. package/dist/runtime/editor/providers/fieldValueAdapterTypes.d.ts +13 -0
  143. package/dist/runtime/editor/providers/fieldValueAdapterTypes.js +0 -0
  144. package/dist/runtime/editor/providers/readability.d.ts +23 -0
  145. package/dist/runtime/editor/providers/readability.js +130 -0
  146. package/dist/runtime/editor/providers/state.d.ts +16 -0
  147. package/dist/runtime/editor/providers/state.js +19 -1
  148. package/dist/runtime/editor/providers/ui.d.ts +7 -0
  149. package/dist/runtime/editor/providers/ui.js +7 -1
  150. package/dist/runtime/editor/translations/de.json +80 -8
  151. package/dist/runtime/editor/translations/fr.json +80 -8
  152. package/dist/runtime/editor/translations/gsw_CH.json +80 -8
  153. package/dist/runtime/editor/translations/it.json +80 -8
  154. package/dist/runtime/editor/types/app.d.ts +4 -0
  155. package/dist/shared/editor.9vf8ZnOp.mjs +288 -0
  156. package/package.json +2 -2
  157. package/dist/modules/agent/runtime/app/tools/update_text_fields/Item.d.vue.ts +0 -22
  158. package/dist/modules/agent/runtime/app/tools/update_text_fields/Item.vue +0 -95
  159. package/dist/modules/agent/runtime/app/tools/update_text_fields/Item.vue.d.ts +0 -22
  160. package/dist/shared/editor.BFIzNSQM.mjs +0 -146
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.39",
4
+ "version": "2.0.0-alpha.40",
5
5
  "compatibility": {
6
6
  "nuxt": ">=3.15.0"
7
7
  },
package/dist/module.mjs CHANGED
@@ -4,11 +4,9 @@ import MagicString from 'magic-string';
4
4
  import { walk } from 'estree-walker-ts';
5
5
  import { pathToFileURL } from 'node:url';
6
6
  import { parseURL, parseQuery } from 'ufo';
7
- import * as ts from 'typescript';
8
- import { parseAndWalk } from 'oxc-walker';
7
+ import { C as Collector, a as CollectedFile, b as extractObjectLiteral, p as parseTsObject, t as toValidVariableName, o as onlyUnique, f as falsy, s as sortObjectKeys } from './shared/editor.9vf8ZnOp.mjs';
9
8
  import path__default, { basename, dirname as dirname$1 } from 'node:path';
10
9
  import { dirname, resolve, relative } from 'pathe';
11
- import { C as Collector, a as CollectedFile } from './shared/editor.BFIzNSQM.mjs';
12
10
  import micromatch from 'micromatch';
13
11
  import { hash } from 'ohash';
14
12
  import fs__default, { readFileSync, existsSync, readdirSync } from 'node:fs';
@@ -16,109 +14,11 @@ import { LANGUAGES, BK_VISIBLE_LANGUAGES, BK_HIDDEN_GLOBALLY } from './global/co
16
14
  import { createRequire } from 'node:module';
17
15
  import { d as defineCodeTemplate, a as defineFileTemplate, w as withHelper } from './shared/editor.6D5vApr0.mjs';
18
16
  import { defu, createDefu } from 'defu';
17
+ import 'typescript';
18
+ import 'oxc-walker';
19
19
 
20
20
  const name = "@blokkli/editor";
21
- const version = "2.0.0-alpha.39";
22
-
23
- function sortObjectKeys(obj) {
24
- if (Array.isArray(obj)) {
25
- return obj.map(sortObjectKeys);
26
- } else if (obj && typeof obj === "object") {
27
- const sortedObj = {};
28
- const keys = Object.keys(obj).sort();
29
- for (const key of keys) {
30
- sortedObj[key] = sortObjectKeys(obj[key]);
31
- }
32
- return sortedObj;
33
- }
34
- return obj;
35
- }
36
- function toValidVariableName(input) {
37
- let result = input.replace(/\W/g, "_");
38
- if (/^\d/.test(result)) {
39
- result = "_" + result;
40
- }
41
- if (result === "") {
42
- result = "_empty";
43
- }
44
- return result;
45
- }
46
- function parseTsObject(tsObjectStr) {
47
- const source = `(${tsObjectStr})`;
48
- const result = ts.transpileModule(source, {
49
- compilerOptions: {
50
- target: ts.ScriptTarget.ESNext,
51
- module: ts.ModuleKind.None,
52
- removeComments: true
53
- }
54
- });
55
- const jsCode = result.outputText.trim();
56
- const createObj = new Function(`return ${jsCode}`);
57
- const object = createObj();
58
- return { object, source: jsCode };
59
- }
60
- function falsy(value) {
61
- return value !== null && value !== void 0;
62
- }
63
- const SFC_SCRIPT_RE = /<script(?<attrs>[^>]*)>(?<content>[\s\S]*?)<\/script[^>]*>/gi;
64
- function extractScriptContent(sfc) {
65
- const contents = [];
66
- let hasMatch = false;
67
- for (const match of sfc.matchAll(SFC_SCRIPT_RE)) {
68
- hasMatch = true;
69
- if (match?.groups?.content) {
70
- contents.push({
71
- loader: match.groups.attrs && /[tj]sx/.test(match.groups.attrs) ? "tsx" : "ts",
72
- code: match.groups.content.trim()
73
- });
74
- }
75
- }
76
- if (!hasMatch) {
77
- contents.push({
78
- loader: "ts",
79
- code: sfc.trim()
80
- });
81
- }
82
- return contents;
83
- }
84
- function extractObjectLiteral(fileContents, composables) {
85
- if (!composables.some((composable) => fileContents.includes(composable))) {
86
- return void 0;
87
- }
88
- const scripts = extractScriptContent(fileContents);
89
- for (const script of scripts) {
90
- try {
91
- let result;
92
- const filename = script.loader === "tsx" ? "temp.tsx" : "temp.ts";
93
- parseAndWalk(script.code, filename, {
94
- parseOptions: {
95
- range: true
96
- },
97
- enter(node) {
98
- if (result) return;
99
- if (node.type === "CallExpression" && node.callee.type === "Identifier" && composables.includes(node.callee.name)) {
100
- for (const arg of node.arguments) {
101
- if (arg.type === "ObjectExpression" && arg.range) {
102
- result = script.code.substring(arg.range[0], arg.range[1]);
103
- break;
104
- }
105
- }
106
- }
107
- }
108
- });
109
- if (result) {
110
- return result;
111
- }
112
- } catch (error) {
113
- console.log(error);
114
- continue;
115
- }
116
- }
117
- return void 0;
118
- }
119
- function onlyUnique(value, index, self) {
120
- return self.indexOf(value) === index;
121
- }
21
+ const version = "2.0.0-alpha.40";
122
22
 
123
23
  function validateOption(optionKey, option, icons) {
124
24
  const errors = [];
@@ -854,7 +754,12 @@ const BlokkliEditingPlugin = (nuxt) => {
854
754
  if (search && pathname.endsWith(".vue")) {
855
755
  const query = parseQuery(search);
856
756
  if (query.blokkliEditing === "true") {
857
- return pathname.replace(/\.vue$/, `${EDITING_MARKER}.vue`);
757
+ let resolved = pathname;
758
+ if (importer && pathname.startsWith(".")) {
759
+ const importerBase2 = importer.split("?")[0] || "";
760
+ resolved = resolve(dirname(importerBase2), pathname);
761
+ }
762
+ return resolved.replace(/\.vue$/, `${EDITING_MARKER}.vue`);
858
763
  }
859
764
  }
860
765
  if (!importer || !importer.includes(EDITING_MARKER) || !id.endsWith(".vue")) {
@@ -1527,6 +1432,8 @@ const USED_MATERIAL_ICONS = [
1527
1432
  "bk_mdi_check_box_outline_blank",
1528
1433
  "bk_mdi_chevron_backward",
1529
1434
  "bk_mdi_chevron_forward",
1435
+ "bk_mdi_chevron_left",
1436
+ "bk_mdi_chevron_right",
1530
1437
  "bk_mdi_close",
1531
1438
  "bk_mdi_collapse_all",
1532
1439
  "bk_mdi_comment",
@@ -1541,6 +1448,7 @@ const USED_MATERIAL_ICONS = [
1541
1448
  "bk_mdi_donut_large",
1542
1449
  "bk_mdi_drag_pan",
1543
1450
  "bk_mdi_edit",
1451
+ "bk_mdi_error",
1544
1452
  "bk_mdi_exit_to_app",
1545
1453
  "bk_mdi_expand_all",
1546
1454
  "bk_mdi_extension",
@@ -1551,6 +1459,7 @@ const USED_MATERIAL_ICONS = [
1551
1459
  "bk_mdi_help",
1552
1460
  "bk_mdi_help-fill",
1553
1461
  "bk_mdi_history",
1462
+ "bk_mdi_hourglass_empty",
1554
1463
  "bk_mdi_image",
1555
1464
  "bk_mdi_info-fill",
1556
1465
  "bk_mdi_ink_selection",
@@ -1591,6 +1500,7 @@ const USED_MATERIAL_ICONS = [
1591
1500
  "bk_mdi_speed",
1592
1501
  "bk_mdi_stack_group",
1593
1502
  "bk_mdi_stop",
1503
+ "bk_mdi_stream",
1594
1504
  "bk_mdi_swap_horiz",
1595
1505
  "bk_mdi_swap_horizontal_circle",
1596
1506
  "bk_mdi_text_compare",
@@ -11,6 +11,7 @@ type AgentModelDefinition = {
11
11
  name: string;
12
12
  label: string;
13
13
  isDefault?: boolean;
14
+ routing?: boolean;
14
15
  pricing?: {
15
16
  input: number;
16
17
  cacheWrite: number;
@@ -3,12 +3,14 @@ import { fileURLToPath } from 'node:url';
3
3
  import * as path from 'node:path';
4
4
  import { d as defineBlokkliModule } from '../../shared/editor.CGf7C_0M.mjs';
5
5
  import * as fs from 'node:fs';
6
- import { C as Collector, a as CollectedFile } from '../../shared/editor.BFIzNSQM.mjs';
6
+ import { C as Collector, a as CollectedFile, e as extractStringProperty } from '../../shared/editor.9vf8ZnOp.mjs';
7
7
  import { d as defineCodeTemplate } from '../../shared/editor.6D5vApr0.mjs';
8
8
  import MagicString from 'magic-string';
9
9
  import { parse } from 'acorn';
10
10
  import { walk } from 'estree-walker-ts';
11
11
  import { transformSync, buildSync } from 'esbuild';
12
+ import 'typescript';
13
+ import 'oxc-walker';
12
14
 
13
15
  function toImportName(prefix, fileName) {
14
16
  const name = fileName.split(/[-_]/).map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("");
@@ -30,9 +32,15 @@ class CollectedAgentFile extends CollectedFile {
30
32
  const fileName = path.basename(this.filePath, ext);
31
33
  const baseName = fileName === "index" ? path.basename(path.dirname(this.filePath)) : fileName;
32
34
  const importName = toImportName(this.importPrefix, baseName);
35
+ const name = extractStringProperty(
36
+ this.fileContents,
37
+ [this.composable],
38
+ "name"
39
+ );
33
40
  this.item = {
34
41
  filePath: this.filePath,
35
- importName
42
+ importName,
43
+ name
36
44
  };
37
45
  return true;
38
46
  }
@@ -93,9 +101,15 @@ class AgentCollector extends Collector {
93
101
  getItems() {
94
102
  return [...this.files.values()].filter((v) => v.isValid()).map((v) => v.getItem());
95
103
  }
104
+ /**
105
+ * Get the extracted `name` values from all valid items.
106
+ */
107
+ getNames() {
108
+ return this.getItems().filter((item) => item.name !== void 0).map((item) => item.name);
109
+ }
96
110
  }
97
111
 
98
- function createClientTemplate(toolCollector, promptCollector, options) {
112
+ function createClientTemplate(toolCollector, promptCollector, skillsCollector, options) {
99
113
  return defineCodeTemplate(
100
114
  "agent-client",
101
115
  (ctx) => {
@@ -140,6 +154,12 @@ function createClientTemplate(toolCollector, promptCollector, options) {
140
154
  exports$1.push(
141
155
  `export const hasWebFetch = ${JSON.stringify(!!options.allowedFetchOrigins)}`
142
156
  );
157
+ exports$1.push(
158
+ `export const toolNames = ${JSON.stringify(toolCollector.getNames())}`
159
+ );
160
+ exports$1.push(
161
+ `export const skillNames = ${JSON.stringify(skillsCollector.getNames())}`
162
+ );
143
163
  const parts = [];
144
164
  if (imports.length > 0) {
145
165
  parts.push(imports.join("\n"));
@@ -147,16 +167,50 @@ function createClientTemplate(toolCollector, promptCollector, options) {
147
167
  parts.push(exports$1.join("\n"));
148
168
  return parts.join("\n\n") + "\n";
149
169
  },
150
- () => {
151
- return `import type { McpToolDefinition, AgentPromptItem } from '#blokkli/agent/app/types'
170
+ (ctx) => {
171
+ const tools = toolCollector.getItems();
172
+ const skillNamesList = skillsCollector.getNames();
173
+ const rel = (p) => ctx.helper.toModuleBuildRelative(p).replace(/\.ts$/, "");
174
+ const agentSkillNameType = skillNamesList.length > 0 ? skillNamesList.map((n) => `'${n}'`).join(" | ") : "string";
175
+ const toolsWithNames = tools.filter((t) => t.name !== void 0);
176
+ let toolMapBlock;
177
+ let agentToolNameType;
178
+ if (toolsWithNames.length > 0) {
179
+ const entries = toolsWithNames.map((t) => {
180
+ const importPath = rel(t.filePath);
181
+ return ` '${t.name}': {
182
+ params: _ToolParams<typeof import('${importPath}')['default']>
183
+ result: _ToolResult<typeof import('${importPath}')['default']>
184
+ }`;
185
+ }).join("\n");
186
+ toolMapBlock = `export interface AgentToolMap {
187
+ ${entries}
188
+ }`;
189
+ agentToolNameType = "keyof AgentToolMap";
190
+ } else {
191
+ toolMapBlock = `export type AgentToolMap = Record<string, { params: Record<string, unknown>; result: unknown }>`;
192
+ agentToolNameType = "string";
193
+ }
194
+ return `import type { z } from 'zod'
195
+ import type { McpToolDefinition, AgentPromptItem } from '#blokkli/agent/app/types'
152
196
  import type { AgentModelDefinition } from '#blokkli/agent/shared/types'
153
197
 
198
+ type _ToolParams<T> = T extends { paramsSchema: infer P extends z.ZodType } ? z.infer<P> : never
199
+ type _ToolResult<T> = T extends { resultSchema: infer R extends z.ZodType } ? z.infer<R> : never
200
+
201
+ ${toolMapBlock}
202
+
203
+ export type AgentToolName = ${agentToolNameType}
204
+ export type AgentSkillName = ${agentSkillNameType}
205
+
154
206
  export const mcpTools: McpToolDefinition[]
155
207
  export const agentPrompts: AgentPromptItem[]
156
208
  export const defaultPrompts: string[]
157
209
  export const agentName: string
158
210
  export const models: AgentModelDefinition[]
159
211
  export const hasWebFetch: boolean
212
+ export const toolNames: readonly AgentToolName[]
213
+ export const skillNames: readonly AgentSkillName[]
160
214
  `;
161
215
  }
162
216
  );
@@ -494,6 +548,8 @@ function transformToolSource(source, filePath) {
494
548
 
495
549
  const AGENT_ROUTE = "/api/blokkli/agent";
496
550
  const FETCH_ROUTE = "/api/blokkli/agent/fetch";
551
+ const STREAM_ROUTE = "/api/blokkli/agent/stream";
552
+ const ROUTE_ROUTE = "/api/blokkli/agent/route";
497
553
  const index = defineBlokkliModule({
498
554
  alterOptions: (options) => {
499
555
  options.featureImports ||= [];
@@ -561,6 +617,7 @@ export default defineNuxtConfig({
561
617
  ]
562
618
  });
563
619
  ctx.context.addCollector(mcpTools);
620
+ const modulePromptsDir = moduleResolver.resolve("./runtime/app/prompts");
564
621
  const projectPromptsDir = path.resolve(
565
622
  nuxt.options.rootDir,
566
623
  "blokkli/prompts"
@@ -570,14 +627,12 @@ export default defineNuxtConfig({
570
627
  importPrefix: "prompt",
571
628
  dependency: "agent-prompts",
572
629
  dirs: [
630
+ modulePromptsDir,
573
631
  projectPromptsDir,
574
632
  ...moduleBlokkliDirs.map((d) => path.join(d, "prompts"))
575
633
  ]
576
634
  });
577
635
  ctx.context.addCollector(promptsCollector);
578
- ctx.context.addTemplate(
579
- createClientTemplate(mcpTools, promptsCollector, options)
580
- );
581
636
  const relativeToolsDir = path.relative(
582
637
  nuxt.options.buildDir,
583
638
  projectToolsDir
@@ -613,6 +668,14 @@ export default defineNuxtConfig({
613
668
  ]
614
669
  });
615
670
  ctx.context.addCollector(skillsCollector);
671
+ ctx.context.addTemplate(
672
+ createClientTemplate(
673
+ mcpTools,
674
+ promptsCollector,
675
+ skillsCollector,
676
+ options
677
+ )
678
+ );
616
679
  const moduleSystemPromptsDir = moduleResolver.resolve(
617
680
  "./runtime/server/default-system-prompts"
618
681
  );
@@ -656,6 +719,14 @@ export default defineNuxtConfig({
656
719
  route: FETCH_ROUTE,
657
720
  handler: moduleResolver.resolve("./runtime/server/fetch")
658
721
  });
722
+ addServerHandler({
723
+ route: STREAM_ROUTE,
724
+ handler: moduleResolver.resolve("./runtime/server/stream")
725
+ });
726
+ addServerHandler({
727
+ route: ROUTE_ROUTE,
728
+ handler: moduleResolver.resolve("./runtime/server/route")
729
+ });
659
730
  const relativeSkillsDir = path.relative(
660
731
  nuxt.options.buildDir,
661
732
  projectSkillsDir
@@ -687,6 +758,8 @@ export default defineNuxtConfig({
687
758
  nitro.hooks.hook("types:extend", (types) => {
688
759
  Reflect.deleteProperty(types.routes, AGENT_ROUTE);
689
760
  Reflect.deleteProperty(types.routes, FETCH_ROUTE);
761
+ Reflect.deleteProperty(types.routes, STREAM_ROUTE);
762
+ Reflect.deleteProperty(types.routes, ROUTE_ROUTE);
690
763
  });
691
764
  });
692
765
  }
@@ -1,7 +1,8 @@
1
1
  import { type Ref } from '#imports';
2
- import { type Attachment, type ConversationItem, type ActiveItem, type MutationAction } from '#blokkli/agent/app/types';
3
- import type { ClientPlanState, UsageTurn, Transcript } from '#blokkli/agent/shared/types';
2
+ import { type Attachment, type ConversationItem, type ActiveItem, type MutationAction, type PreSeededToolResult, type AutoExecuteTool } from '#blokkli/agent/app/types';
3
+ import type { ClientPlanState, UsageTurn, PageContext, Transcript } from '#blokkli/agent/shared/types';
4
4
  import type { AgentConversationSummary } from '#blokkli/agent/app/features/agent/types';
5
+ import type { AgentToolName, AgentToolMap } from '#blokkli-build/agent-client';
5
6
  import type { BlokkliApp } from '#blokkli/editor/types/app';
6
7
  import type { FullBlokkliAdapter } from '#blokkli/editor/adapter';
7
8
  export type PendingMutationState = {
@@ -34,7 +35,10 @@ export type AgentProvider = {
34
35
  approvePlan: () => void;
35
36
  rejectPlan: () => void;
36
37
  usageTurns: Ref<UsageTurn[]>;
37
- sendPrompt: (text: string, displayPrompt?: string, selectedUuids?: string[], attachments?: Attachment[]) => void;
38
+ sendPrompt: (text: string, displayPrompt?: string, selectedUuids?: string[], attachments?: Attachment[], autoLoadTools?: string[], autoLoadSkills?: string[], preSeededResults?: PreSeededToolResult[], autoExecuteTools?: AutoExecuteTool[]) => void;
39
+ runToolForPrompt: <T extends AgentToolName>(toolName: T, params: AgentToolMap[T]['params']) => Promise<PreSeededToolResult & {
40
+ result: AgentToolMap[T]['result'];
41
+ }>;
38
42
  retry: () => void;
39
43
  approve: () => void;
40
44
  reject: () => void;
@@ -52,5 +56,6 @@ export type AgentProvider = {
52
56
  switchConversation: (id: string) => void;
53
57
  deleteConversation: (id: string) => void;
54
58
  refreshConversationList: () => Promise<void>;
59
+ pageContext: Ref<PageContext | null>;
55
60
  };
56
61
  export default function (app: BlokkliApp, adapter: FullBlokkliAdapter<any>, agentName: string): AgentProvider;
@@ -1,4 +1,4 @@
1
- import { ref, readonly, reactive, watch } from "#imports";
1
+ import { ref, shallowRef, readonly, reactive, watch } from "#imports";
2
2
  import {
3
3
  conversationItemSchema
4
4
  } from "#blokkli/agent/app/types";
@@ -29,6 +29,8 @@ export default function(app, adapter, agentName) {
29
29
  let pendingPrompt = null;
30
30
  let pendingInit = null;
31
31
  let toolMap = {};
32
+ let sentToolNames = [];
33
+ const storedPageContext = shallowRef(null);
32
34
  const isProcessing = ref(false);
33
35
  const isThinking = ref(false);
34
36
  const usageTurns = ref([]);
@@ -302,17 +304,21 @@ export default function(app, adapter, agentName) {
302
304
  disconnect();
303
305
  return;
304
306
  }
305
- const pageContext = await buildPageContext(contentSearchTabs);
306
- pendingInit = { toolNames, pageContext };
307
+ const pageContext2 = await buildPageContext(contentSearchTabs);
308
+ storedPageContext.value = pageContext2;
309
+ pendingInit = { toolNames, pageContext: pageContext2 };
307
310
  send({ type: "authenticate", authToken });
308
311
  return;
309
312
  } catch (e) {
310
313
  console.error("Failed to obtain agent auth token:", e);
311
314
  }
312
315
  }
313
- sendInit(toolNames, await buildPageContext(contentSearchTabs));
316
+ const pageContext = await buildPageContext(contentSearchTabs);
317
+ storedPageContext.value = pageContext;
318
+ sendInit(toolNames, pageContext);
314
319
  }
315
320
  async function sendInit(toolNames, pageContext) {
321
+ sentToolNames = toolNames;
316
322
  send({ type: "init", toolNames, pageContext });
317
323
  isReady.value = true;
318
324
  hasBeenReady.value = true;
@@ -333,9 +339,27 @@ export default function(app, adapter, agentName) {
333
339
  }
334
340
  }
335
341
  if (pendingPrompt) {
336
- const { prompt, displayPrompt, selectedUuids, attachments } = pendingPrompt;
342
+ const {
343
+ prompt,
344
+ displayPrompt,
345
+ selectedUuids,
346
+ attachments,
347
+ autoLoadTools,
348
+ autoLoadSkills,
349
+ preSeededResults,
350
+ autoExecuteTools
351
+ } = pendingPrompt;
337
352
  pendingPrompt = null;
338
- sendPrompt(prompt, displayPrompt, selectedUuids, attachments);
353
+ sendPrompt(
354
+ prompt,
355
+ displayPrompt,
356
+ selectedUuids,
357
+ attachments,
358
+ autoLoadTools,
359
+ autoLoadSkills,
360
+ preSeededResults,
361
+ autoExecuteTools
362
+ );
339
363
  }
340
364
  }
341
365
  async function buildPageContext(contentSearchTabs) {
@@ -621,8 +645,12 @@ export default function(app, adapter, agentName) {
621
645
  }
622
646
  let resultForServer = result;
623
647
  if (typeof result === "object" && result !== null) {
624
- if ("_details" in result) {
625
- const { _details: _, ...rest } = result;
648
+ const rec = result;
649
+ if ("_usage" in rec && rec._usage) {
650
+ usageTurns.value = [...usageTurns.value, rec._usage];
651
+ }
652
+ if ("_details" in rec || "_usage" in rec) {
653
+ const { _details: _, _usage: __, ...rest } = rec;
626
654
  resultForServer = rest;
627
655
  }
628
656
  }
@@ -667,9 +695,18 @@ export default function(app, adapter, agentName) {
667
695
  return {
668
696
  app,
669
697
  itemEntityType,
670
- adapter
698
+ adapter,
699
+ pageContext: storedPageContext.value
671
700
  };
672
701
  }
702
+ async function runToolForPrompt(toolName, params) {
703
+ const ctx = createToolContext();
704
+ const toolDef = getToolDefinition(toolMap, toolName);
705
+ const rawResult = await executeTool(toolMap, toolName, ctx, params);
706
+ const label = isQueryResult(rawResult) ? rawResult.label : toolDef.label($t);
707
+ const result = isQueryResult(rawResult) ? rawResult.result : rawResult;
708
+ return { toolName, params, result, label };
709
+ }
673
710
  function waitForToolComponent(toolName, params) {
674
711
  return new Promise((resolve) => {
675
712
  pendingToolCall.value = { toolName, params };
@@ -774,16 +811,62 @@ export default function(app, adapter, agentName) {
774
811
  pendingMutation.value = { action, resolve };
775
812
  });
776
813
  }
777
- function sendPrompt(prompt, displayPrompt, selectedUuids, attachments) {
814
+ async function sendPrompt(prompt, displayPrompt, selectedUuids, attachments, autoLoadTools, autoLoadSkills, preSeededResults, autoExecuteTools) {
778
815
  if (!prompt.trim() || isProcessing.value) return;
779
816
  if (!isReady.value) {
780
- pendingPrompt = { prompt, displayPrompt, selectedUuids, attachments };
817
+ pendingPrompt = {
818
+ prompt,
819
+ displayPrompt,
820
+ selectedUuids,
821
+ attachments,
822
+ autoLoadTools,
823
+ autoLoadSkills,
824
+ preSeededResults,
825
+ autoExecuteTools
826
+ };
781
827
  return;
782
828
  }
783
829
  isProcessing.value = true;
784
830
  if (!activeConversationId.value) {
785
831
  activeConversationId.value = generateUUID();
786
832
  }
833
+ const isFirstMessage = !conversation.value.some(
834
+ (item2) => item2.type === "user"
835
+ );
836
+ const hasClientDirectives = !!(autoLoadTools?.length || autoLoadSkills?.length);
837
+ let resolvedAutoLoadTools = autoLoadTools;
838
+ let resolvedAutoLoadSkills = autoLoadSkills;
839
+ if (isFirstMessage && !hasClientDirectives && storedPageContext.value) {
840
+ try {
841
+ const routingResult = await fetch("/api/blokkli/agent/route", {
842
+ method: "POST",
843
+ headers: { "Content-Type": "application/json" },
844
+ body: JSON.stringify({
845
+ prompt,
846
+ toolNames: sentToolNames,
847
+ pageContext: storedPageContext.value
848
+ })
849
+ }).then(
850
+ (r) => r.json()
851
+ );
852
+ if (routingResult.usage) {
853
+ usageTurns.value = [...usageTurns.value, routingResult.usage];
854
+ }
855
+ if (routingResult.tools?.length) {
856
+ resolvedAutoLoadTools = [
857
+ ...resolvedAutoLoadTools || [],
858
+ ...routingResult.tools
859
+ ];
860
+ }
861
+ if (routingResult.skills?.length) {
862
+ resolvedAutoLoadSkills = [
863
+ ...resolvedAutoLoadSkills || [],
864
+ ...routingResult.skills
865
+ ];
866
+ }
867
+ } catch {
868
+ }
869
+ }
787
870
  const item = {
788
871
  type: "user",
789
872
  id: generateId(),
@@ -795,10 +878,19 @@ export default function(app, adapter, agentName) {
795
878
  item.attachments = attachments;
796
879
  }
797
880
  conversation.value.push(item);
881
+ const serverPreSeeded = preSeededResults?.length ? preSeededResults.map(({ toolName, params, result }) => ({
882
+ toolName,
883
+ params,
884
+ result
885
+ })) : void 0;
798
886
  send({
799
887
  type: "start",
800
888
  prompt,
801
- selectedUuids: selectedUuids?.length ? selectedUuids : void 0
889
+ selectedUuids: selectedUuids?.length ? selectedUuids : void 0,
890
+ autoLoadTools: resolvedAutoLoadTools?.length ? resolvedAutoLoadTools : void 0,
891
+ autoLoadSkills: resolvedAutoLoadSkills?.length ? resolvedAutoLoadSkills : void 0,
892
+ preSeededResults: serverPreSeeded,
893
+ autoExecuteTools: autoExecuteTools?.length ? autoExecuteTools : void 0
802
894
  });
803
895
  }
804
896
  function retry() {
@@ -912,6 +1004,7 @@ export default function(app, adapter, agentName) {
912
1004
  usageTurns,
913
1005
  // Actions
914
1006
  sendPrompt,
1007
+ runToolForPrompt,
915
1008
  retry,
916
1009
  approve,
917
1010
  reject,
@@ -931,6 +1024,8 @@ export default function(app, adapter, agentName) {
931
1024
  activeConversationId: readonly(activeConversationId),
932
1025
  switchConversation,
933
1026
  deleteConversation,
934
- refreshConversationList
1027
+ refreshConversationList,
1028
+ // Page context (built once during connection)
1029
+ pageContext: storedPageContext
935
1030
  };
936
1031
  }
@@ -51,7 +51,8 @@ import { mcpTools } from "#blokkli-build/agent-client";
51
51
  const mockContext = {
52
52
  app: null,
53
53
  itemEntityType: "paragraph",
54
- adapter: {}
54
+ adapter: {},
55
+ pageContext: null
55
56
  };
56
57
  const mockHistory = [
57
58
  {
@@ -145,12 +146,12 @@ const mockMutations = [
145
146
  type: "move",
146
147
  label: "Move card block after hero section",
147
148
  apply: () => void 0
148
- },
149
- {
150
- type: "rewrite",
151
- label: "Rewrite title field content",
152
- apply: () => void 0
153
149
  }
150
+ // {
151
+ // type: 'rewrite',
152
+ // label: 'Rewrite title field content',
153
+ // apply: () => undefined,
154
+ // },
154
155
  ];
155
156
  const toolsWithMockParams = computed(
156
157
  () => mcpTools.filter(
@@ -1,10 +1,9 @@
1
1
  import type { AgentConversationSummary, PendingMutationState, PendingToolCall } from '#blokkli/agent/app/composables';
2
2
  import type { ConversationItem, ActiveItem } from '#blokkli/agent/app/types';
3
- import type { ClientPlanState, UsageTurn } from '#blokkli/agent/shared/types';
3
+ import type { ClientPlanState, PageContext, UsageTurn } from '#blokkli/agent/shared/types';
4
4
  type __VLS_Props = {
5
5
  agentName: string;
6
6
  isShown: boolean;
7
- debugStyling?: boolean;
8
7
  conversation: ConversationItem[];
9
8
  activeItem: ActiveItem | null;
10
9
  isThinking: boolean;
@@ -19,6 +18,7 @@ type __VLS_Props = {
19
18
  showConversationList: boolean;
20
19
  plan: ClientPlanState | null;
21
20
  usageTurns: UsageTurn[];
21
+ pageContext: PageContext | null;
22
22
  };
23
23
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
24
24
  cancel: () => any;