plugin-elastic-report 0.0.0-stage → 0.1.1

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 (257) hide show
  1. package/ai/skills/elastic-report/SKILLS.md +32 -0
  2. package/client-v2.d.ts +2 -0
  3. package/client-v2.js +1 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/index.js +10 -0
  7. package/dist/client-v2/851.488fdbf5bc5b6a36.js +10 -0
  8. package/dist/client-v2/index.js +10 -0
  9. package/dist/externalVersion.js +20 -0
  10. package/dist/index.js +48 -0
  11. package/dist/locale/en-US.json +99 -0
  12. package/dist/locale/vi-VN.json +99 -0
  13. package/dist/locale/zh-CN.json +99 -0
  14. package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
  15. package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
  16. package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
  17. package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
  18. package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
  19. package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
  20. package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
  21. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
  22. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
  23. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
  24. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
  25. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
  26. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
  27. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
  28. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
  29. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
  30. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
  31. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
  32. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
  33. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
  34. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
  35. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
  36. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
  37. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
  38. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
  39. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
  40. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
  41. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
  42. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
  43. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
  44. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
  45. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
  46. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
  47. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
  48. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
  49. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
  50. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
  51. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
  52. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
  53. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
  54. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
  55. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
  56. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
  57. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
  58. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
  59. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
  60. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
  61. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
  62. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
  63. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
  64. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
  65. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
  66. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
  67. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
  68. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
  69. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
  70. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
  71. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
  72. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
  73. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
  74. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
  75. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
  76. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
  77. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
  78. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
  79. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
  80. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
  81. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
  82. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
  83. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
  84. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
  85. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
  86. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
  87. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
  88. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
  89. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
  90. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
  91. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
  92. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
  93. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
  94. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
  95. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
  96. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
  97. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
  98. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
  99. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
  100. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
  101. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
  102. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
  103. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
  104. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
  105. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
  106. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
  107. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
  108. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
  109. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
  110. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
  111. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
  112. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
  113. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
  114. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
  115. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
  116. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
  117. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
  118. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
  119. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
  120. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
  121. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
  122. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
  123. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
  124. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
  125. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
  126. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
  127. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
  128. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
  129. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
  130. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
  131. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
  132. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
  133. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
  134. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
  135. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
  136. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
  137. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
  138. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
  139. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
  140. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
  141. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
  142. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
  143. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
  144. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
  145. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
  146. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
  147. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
  148. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
  149. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
  150. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
  151. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
  152. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
  153. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
  154. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
  155. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
  156. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
  157. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
  158. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
  159. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
  160. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
  161. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
  162. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
  163. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
  164. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
  165. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
  166. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
  167. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
  168. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
  169. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
  170. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
  171. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
  172. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
  173. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
  174. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
  175. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
  176. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
  177. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
  178. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
  179. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
  180. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
  181. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
  182. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
  183. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
  184. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
  185. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
  186. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
  187. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
  188. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
  189. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
  190. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
  191. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
  192. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
  193. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
  194. package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
  195. package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
  196. package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
  197. package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
  198. package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
  199. package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
  200. package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
  201. package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
  202. package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
  203. package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
  204. package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
  205. package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
  206. package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
  207. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
  208. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
  209. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
  210. package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
  211. package/dist/server/acl-guard.js +107 -0
  212. package/dist/server/collections/es-report-data-views.js +79 -0
  213. package/dist/server/collections/es-reports.js +95 -0
  214. package/dist/server/index.js +58 -0
  215. package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
  216. package/dist/server/mcp/ElasticReportToolCatalog.js +417 -0
  217. package/dist/server/plugin.js +395 -0
  218. package/dist/server/services/ElasticReportService.js +263 -0
  219. package/dist/server/services/ElasticsearchConnectionService.js +332 -0
  220. package/dist/server/services/ReportQueryCompiler.js +858 -0
  221. package/dist/shared/constants.js +81 -0
  222. package/dist/shared/types.js +24 -0
  223. package/package.json +61 -4
  224. package/server.d.ts +2 -0
  225. package/server.js +1 -0
  226. package/src/client/index.tsx +19 -0
  227. package/src/client-v2/__tests__/elastic-report.test.tsx +311 -0
  228. package/src/client-v2/api.ts +224 -0
  229. package/src/client-v2/components/ElasticBasicCharts.tsx +399 -0
  230. package/src/client-v2/components/ElasticReportBlock.tsx +160 -0
  231. package/src/client-v2/components/ElasticReportRenderer.tsx +707 -0
  232. package/src/client-v2/components/HighlightText.tsx +50 -0
  233. package/src/client-v2/components/ReportSelect.tsx +72 -0
  234. package/src/client-v2/index.tsx +14 -0
  235. package/src/client-v2/locale.ts +23 -0
  236. package/src/client-v2/models/ElasticReportBlockModel.tsx +85 -0
  237. package/src/client-v2/pages/ElasticReportManager.tsx +1047 -0
  238. package/src/client-v2/plugin.tsx +52 -0
  239. package/src/index.ts +11 -0
  240. package/src/locale/en-US.json +99 -0
  241. package/src/locale/vi-VN.json +99 -0
  242. package/src/locale/zh-CN.json +99 -0
  243. package/src/server/__tests__/query-compiler.test.ts +231 -0
  244. package/src/server/__tests__/report-mcp-acl.integration.test.ts +377 -0
  245. package/src/server/acl-guard.ts +103 -0
  246. package/src/server/collections/es-report-data-views.ts +58 -0
  247. package/src/server/collections/es-reports.ts +74 -0
  248. package/src/server/index.ts +15 -0
  249. package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
  250. package/src/server/mcp/ElasticReportToolCatalog.ts +417 -0
  251. package/src/server/plugin.ts +431 -0
  252. package/src/server/services/ElasticReportService.ts +326 -0
  253. package/src/server/services/ElasticsearchConnectionService.ts +401 -0
  254. package/src/server/services/ReportQueryCompiler.ts +1017 -0
  255. package/src/shared/constants.ts +29 -0
  256. package/src/shared/types.ts +175 -0
  257. package/README.md +0 -3
@@ -0,0 +1,1047 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
10
+ import {
11
+ CopyOutlined,
12
+ DeleteOutlined,
13
+ EditOutlined,
14
+ EyeOutlined,
15
+ PlayCircleOutlined,
16
+ PlusOutlined,
17
+ ReloadOutlined,
18
+ } from '@ant-design/icons';
19
+ import { useApp } from '@nocobase/client-v2';
20
+ import {
21
+ Alert,
22
+ App,
23
+ Button,
24
+ Card,
25
+ Col,
26
+ Descriptions,
27
+ Divider,
28
+ Drawer,
29
+ Form,
30
+ Input,
31
+ InputNumber,
32
+ Modal,
33
+ Popconfirm,
34
+ Row,
35
+ Select,
36
+ Space,
37
+ Switch,
38
+ Table,
39
+ Tabs,
40
+ Tag,
41
+ Typography,
42
+ } from 'antd';
43
+ import type { TableColumnsType } from 'antd';
44
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
45
+ import type {
46
+ BucketAggType,
47
+ CalendarIntervalOption,
48
+ EsConnectionSummary,
49
+ EsDataViewRecord,
50
+ EsFieldCapability,
51
+ EsReportRecord,
52
+ FilterOperator,
53
+ ID,
54
+ MetricAggType,
55
+ ReportExecutionResult,
56
+ ReportFilterItem,
57
+ ReportRuntimeOverrides,
58
+ ReportSortItem,
59
+ ReportSpec,
60
+ ReportVisualizationType,
61
+ TimeRangePreset,
62
+ } from '../../shared/types';
63
+ import {
64
+ executeReportPreview,
65
+ fetchAllReports,
66
+ fetchDataViewFields,
67
+ fetchDataViews,
68
+ fetchEsConnections,
69
+ fetchEsIndices,
70
+ fetchMcpInfo,
71
+ persistReport,
72
+ removeDataView,
73
+ removeReport,
74
+ saveDataView,
75
+ type ApiClientLike,
76
+ type McpInfoPayload,
77
+ } from '../api';
78
+ import { ElasticReportRenderer } from '../components/ElasticReportRenderer';
79
+ import { useT } from '../locale';
80
+
81
+ const { Paragraph, Text } = Typography;
82
+
83
+ interface ReportEditorFormValues {
84
+ title: string;
85
+ description?: string;
86
+ dataViewId: ID;
87
+ published: boolean;
88
+ visualization: ReportVisualizationType;
89
+ query?: string;
90
+ timePreset: TimeRangePreset;
91
+ filters?: Array<{
92
+ field: string;
93
+ operator: FilterOperator;
94
+ value?: string;
95
+ valueTo?: string;
96
+ }>;
97
+ sort?: Array<{
98
+ field: string;
99
+ order: 'asc' | 'desc';
100
+ }>;
101
+ columns?: string[];
102
+ pageSize: number;
103
+ showHistogram: boolean;
104
+ allowInteractiveControls: boolean;
105
+ bucketType: BucketAggType;
106
+ bucketField?: string;
107
+ calendarInterval: CalendarIntervalOption;
108
+ topN: number;
109
+ metricType: MetricAggType;
110
+ metricField?: string;
111
+ metricLabel?: string;
112
+ }
113
+
114
+ interface DataViewFormValues {
115
+ title: string;
116
+ dataSourceKey: string;
117
+ indexPattern: string;
118
+ timeField?: string;
119
+ description?: string;
120
+ }
121
+
122
+ const FILTER_OPERATOR_ITEMS: Array<{ label: string; value: FilterOperator }> = [
123
+ { label: 'is (=)', value: 'eq' },
124
+ { label: 'is not (!=)', value: 'ne' },
125
+ { label: 'contains', value: 'contains' },
126
+ { label: 'in (comma-separated)', value: 'in' },
127
+ { label: 'not in', value: 'not_in' },
128
+ { label: '>', value: 'gt' },
129
+ { label: '>=', value: 'gte' },
130
+ { label: '<', value: 'lt' },
131
+ { label: '<=', value: 'lte' },
132
+ { label: 'between', value: 'between' },
133
+ { label: 'exists', value: 'exists' },
134
+ { label: 'does not exist', value: 'not_exists' },
135
+ ];
136
+
137
+ function formValuesToSpec(values: ReportEditorFormValues): ReportSpec {
138
+ const filters: ReportFilterItem[] = (values.filters ?? [])
139
+ .filter((f) => Boolean(f?.field))
140
+ .map((f, idx) => ({
141
+ id: `flt-${idx}`,
142
+ field: f.field,
143
+ operator: f.operator || 'eq',
144
+ ...(f.value !== undefined && f.value !== '' ? { value: f.value } : {}),
145
+ ...(f.valueTo !== undefined && f.valueTo !== '' ? { valueTo: f.valueTo } : {}),
146
+ enabled: true,
147
+ }));
148
+
149
+ const sort: ReportSortItem[] = (values.sort ?? [])
150
+ .filter((s) => Boolean(s?.field))
151
+ .map((s) => ({
152
+ field: s.field,
153
+ order: s.order === 'asc' ? 'asc' : 'desc',
154
+ }));
155
+
156
+ return {
157
+ visualization: values.visualization || 'table',
158
+ query: values.query?.trim() ?? '',
159
+ queryMode: 'kql',
160
+ filters,
161
+ sort,
162
+ timeRange: { preset: values.timePreset || 'last_24h' },
163
+ columns: values.columns ?? [],
164
+ pageSize: values.pageSize || 20,
165
+ allowInteractiveControls: values.allowInteractiveControls !== false,
166
+ chart: {
167
+ bucketType: values.bucketType || 'date_histogram',
168
+ ...(values.bucketField ? { bucketField: values.bucketField } : {}),
169
+ calendarInterval: values.calendarInterval || 'auto',
170
+ topN: values.topN || 10,
171
+ metricType: values.metricType || 'count',
172
+ ...(values.metricField ? { metricField: values.metricField } : {}),
173
+ ...(values.metricLabel ? { metricLabel: values.metricLabel } : {}),
174
+ showHistogram: values.showHistogram !== false,
175
+ },
176
+ };
177
+ }
178
+
179
+ export const ElasticReportManager: React.FC = () => {
180
+ const t = useT();
181
+ const app = useApp();
182
+ const api = app.apiClient as unknown as ApiClientLike;
183
+ const { message } = App.useApp();
184
+
185
+ const [connections, setConnections] = useState<EsConnectionSummary[]>([]);
186
+ const [dataViews, setDataViews] = useState<EsDataViewRecord[]>([]);
187
+ const [reports, setReports] = useState<EsReportRecord[]>([]);
188
+ const [mcpInfo, setMcpInfo] = useState<McpInfoPayload | null>(null);
189
+ const [loadingList, setLoadingList] = useState(false);
190
+
191
+ // Data View modal state
192
+ const [dvModalOpen, setDvModalOpen] = useState(false);
193
+ const [editingDataView, setEditingDataView] = useState<EsDataViewRecord | null>(null);
194
+ const [dvSaving, setDvSaving] = useState(false);
195
+ const [matchedIndices, setMatchedIndices] = useState<string[]>([]);
196
+ const [loadingIndices, setLoadingIndices] = useState(false);
197
+ const [dvForm] = Form.useForm<DataViewFormValues>();
198
+
199
+ // Report Studio drawer state
200
+ const [studioOpen, setStudioOpen] = useState(false);
201
+ const [editingReport, setEditingReport] = useState<EsReportRecord | null>(null);
202
+ const [studioFields, setStudioFields] = useState<EsFieldCapability[]>([]);
203
+ const [studioPreviewSpec, setStudioPreviewSpec] = useState<ReportSpec>({ visualization: 'table' });
204
+ const [previewResult, setPreviewResult] = useState<ReportExecutionResult | null>(null);
205
+ const [previewLoading, setPreviewLoading] = useState(false);
206
+ const [previewError, setPreviewError] = useState<string | null>(null);
207
+ const [savingReport, setSavingReport] = useState(false);
208
+ const [reportForm] = Form.useForm<ReportEditorFormValues>();
209
+
210
+ const watchedVisualization = Form.useWatch('visualization', reportForm) ?? 'table';
211
+ const watchedDataViewId = Form.useWatch('dataViewId', reportForm);
212
+ const watchedBucketType = Form.useWatch('bucketType', reportForm) ?? 'date_histogram';
213
+ const watchedMetricType = Form.useWatch('metricType', reportForm) ?? 'count';
214
+
215
+ const loadAll = useCallback(async () => {
216
+ setLoadingList(true);
217
+ try {
218
+ const [connList, dvList, reportList, mcpData] = await Promise.all([
219
+ fetchEsConnections(api).catch(() => []),
220
+ fetchDataViews(api).catch(() => []),
221
+ fetchAllReports(api).catch(() => []),
222
+ fetchMcpInfo(api).catch(() => null),
223
+ ]);
224
+ setConnections(connList);
225
+ setDataViews(dvList);
226
+ setReports(reportList);
227
+ setMcpInfo(mcpData);
228
+ } finally {
229
+ setLoadingList(false);
230
+ }
231
+ }, [api]);
232
+
233
+ useEffect(() => {
234
+ loadAll();
235
+ }, [loadAll]);
236
+
237
+ useEffect(() => {
238
+ if (!studioOpen || watchedDataViewId === undefined || watchedDataViewId === null) {
239
+ setStudioFields([]);
240
+ return;
241
+ }
242
+ let cancelled = false;
243
+ fetchDataViewFields(api, watchedDataViewId, false)
244
+ .then((res) => {
245
+ if (!cancelled) setStudioFields(res.fields ?? []);
246
+ })
247
+ .catch(() => {
248
+ if (!cancelled) setStudioFields([]);
249
+ });
250
+ return () => {
251
+ cancelled = true;
252
+ };
253
+ }, [api, studioOpen, watchedDataViewId]);
254
+
255
+ const selectedDataView = useMemo(
256
+ () => dataViews.find((dv) => String(dv.id) === String(watchedDataViewId)) ?? null,
257
+ [dataViews, watchedDataViewId],
258
+ );
259
+
260
+ const aggregatableStudioFields = useMemo(
261
+ () => studioFields.filter((f) => f.aggregatable || Boolean(f.keywordSubfield)),
262
+ [studioFields],
263
+ );
264
+
265
+ const numericStudioFields = useMemo(
266
+ () =>
267
+ studioFields.filter((f) =>
268
+ ['long', 'integer', 'short', 'byte', 'double', 'float', 'half_float', 'scaled_float'].includes(f.type),
269
+ ),
270
+ [studioFields],
271
+ );
272
+
273
+ const openNewDataViewModal = () => {
274
+ setEditingDataView(null);
275
+ setMatchedIndices([]);
276
+ dvForm.resetFields();
277
+ dvForm.setFieldsValue({
278
+ dataSourceKey: connections[0]?.key,
279
+ indexPattern: '*',
280
+ timeField: '@timestamp',
281
+ });
282
+ setDvModalOpen(true);
283
+ };
284
+
285
+ const openEditDataViewModal = (record: EsDataViewRecord) => {
286
+ setEditingDataView(record);
287
+ setMatchedIndices([]);
288
+ dvForm.setFieldsValue({
289
+ title: record.title,
290
+ dataSourceKey: record.dataSourceKey,
291
+ indexPattern: record.indexPattern,
292
+ timeField: record.timeField ?? '',
293
+ description: record.description ?? '',
294
+ });
295
+ setDvModalOpen(true);
296
+ };
297
+
298
+ const handleBrowseIndices = async () => {
299
+ const dsKey = dvForm.getFieldValue('dataSourceKey');
300
+ const pattern = dvForm.getFieldValue('indexPattern') || '*';
301
+ if (!dsKey) return;
302
+ setLoadingIndices(true);
303
+ try {
304
+ const list = await fetchEsIndices(api, dsKey, pattern);
305
+ setMatchedIndices(list);
306
+ } catch (err) {
307
+ message.error(err instanceof Error ? err.message : String(err));
308
+ } finally {
309
+ setLoadingIndices(false);
310
+ }
311
+ };
312
+
313
+ const handleSaveDataView = async () => {
314
+ try {
315
+ const values = await dvForm.validateFields();
316
+ setDvSaving(true);
317
+ await saveDataView(api, {
318
+ ...(editingDataView ? { id: editingDataView.id } : {}),
319
+ title: values.title,
320
+ dataSourceKey: values.dataSourceKey,
321
+ indexPattern: values.indexPattern,
322
+ timeField: values.timeField || null,
323
+ description: values.description || null,
324
+ });
325
+ message.success(t('Saved successfully'));
326
+ setDvModalOpen(false);
327
+ await loadAll();
328
+ } catch (err) {
329
+ if (err instanceof Error && 'message' in err) {
330
+ message.error(err.message);
331
+ }
332
+ } finally {
333
+ setDvSaving(false);
334
+ }
335
+ };
336
+
337
+ const openNewReportStudio = () => {
338
+ setEditingReport(null);
339
+ setPreviewResult(null);
340
+ setPreviewError(null);
341
+ reportForm.resetFields();
342
+ reportForm.setFieldsValue({
343
+ title: '',
344
+ dataViewId: dataViews[0]?.id,
345
+ published: true,
346
+ visualization: 'table',
347
+ query: '',
348
+ timePreset: 'last_24h',
349
+ filters: [],
350
+ sort: [],
351
+ columns: [],
352
+ pageSize: 20,
353
+ showHistogram: true,
354
+ allowInteractiveControls: true,
355
+ bucketType: 'date_histogram',
356
+ calendarInterval: 'auto',
357
+ topN: 10,
358
+ metricType: 'count',
359
+ });
360
+ setStudioPreviewSpec({
361
+ visualization: 'table',
362
+ query: '',
363
+ queryMode: 'kql',
364
+ filters: [],
365
+ sort: [],
366
+ timeRange: { preset: 'last_24h' },
367
+ columns: [],
368
+ pageSize: 20,
369
+ allowInteractiveControls: true,
370
+ chart: {
371
+ bucketType: 'date_histogram',
372
+ calendarInterval: 'auto',
373
+ topN: 10,
374
+ metricType: 'count',
375
+ showHistogram: true,
376
+ },
377
+ });
378
+ setStudioOpen(true);
379
+ };
380
+
381
+ const openEditReportStudio = (record: EsReportRecord) => {
382
+ setEditingReport(record);
383
+ setPreviewResult(null);
384
+ setPreviewError(null);
385
+ const spec = record.spec;
386
+ setStudioPreviewSpec(spec);
387
+ reportForm.setFieldsValue({
388
+ title: record.title,
389
+ description: record.description ?? '',
390
+ dataViewId: record.dataViewId,
391
+ published: record.published !== false,
392
+ visualization: spec.visualization ?? 'table',
393
+ query: spec.query ?? '',
394
+ timePreset: spec.timeRange?.preset ?? 'last_24h',
395
+ filters: (spec.filters ?? []).map((f) => ({
396
+ field: f.field,
397
+ operator: f.operator,
398
+ value: Array.isArray(f.value) ? f.value.join(', ') : f.value !== undefined ? String(f.value) : '',
399
+ valueTo: f.valueTo !== undefined ? String(f.valueTo) : '',
400
+ })),
401
+ sort: spec.sort ?? [],
402
+ columns: spec.columns ?? [],
403
+ pageSize: spec.pageSize ?? 20,
404
+ showHistogram: spec.chart?.showHistogram !== false,
405
+ allowInteractiveControls: spec.allowInteractiveControls !== false,
406
+ bucketType: spec.chart?.bucketType ?? 'date_histogram',
407
+ bucketField: spec.chart?.bucketField,
408
+ calendarInterval: spec.chart?.calendarInterval ?? 'auto',
409
+ topN: spec.chart?.topN ?? 10,
410
+ metricType: spec.chart?.metricType ?? 'count',
411
+ metricField: spec.chart?.metricField,
412
+ metricLabel: spec.chart?.metricLabel,
413
+ });
414
+ setStudioOpen(true);
415
+ };
416
+
417
+ const handleRunStudioPreview = async (overrides?: ReportRuntimeOverrides) => {
418
+ const values = reportForm.getFieldsValue(true) as ReportEditorFormValues;
419
+ if (values.dataViewId === undefined || values.dataViewId === null) {
420
+ return;
421
+ }
422
+ setPreviewLoading(true);
423
+ setPreviewError(null);
424
+ try {
425
+ const spec = formValuesToSpec(values);
426
+ if (!overrides) {
427
+ setStudioPreviewSpec(spec);
428
+ }
429
+ const res = await executeReportPreview(api, values.dataViewId, spec, overrides);
430
+ setPreviewResult(res.result);
431
+ } catch (err) {
432
+ setPreviewError(err instanceof Error ? err.message : String(err));
433
+ } finally {
434
+ setPreviewLoading(false);
435
+ }
436
+ };
437
+
438
+ const handleSaveReport = async () => {
439
+ try {
440
+ const values = await reportForm.validateFields();
441
+ setSavingReport(true);
442
+ const spec = formValuesToSpec(values);
443
+ await persistReport(api, {
444
+ ...(editingReport ? { id: editingReport.id } : {}),
445
+ title: values.title,
446
+ description: values.description || null,
447
+ dataViewId: values.dataViewId,
448
+ published: values.published !== false,
449
+ spec,
450
+ });
451
+ message.success(t('Saved successfully'));
452
+ setStudioOpen(false);
453
+ await loadAll();
454
+ } catch (err) {
455
+ if (err instanceof Error && 'message' in err) {
456
+ message.error(err.message);
457
+ }
458
+ } finally {
459
+ setSavingReport(false);
460
+ }
461
+ };
462
+
463
+ const reportColumns: TableColumnsType<EsReportRecord> = [
464
+ {
465
+ title: t('Title'),
466
+ dataIndex: 'title',
467
+ key: 'title',
468
+ render: (val: string, row) => (
469
+ <Space direction="vertical" size={0}>
470
+ <Text strong>{val}</Text>
471
+ {row.description && (
472
+ <Text type="secondary" style={{ fontSize: 12 }}>
473
+ {row.description}
474
+ </Text>
475
+ )}
476
+ </Space>
477
+ ),
478
+ },
479
+ {
480
+ title: t('Visualization'),
481
+ dataIndex: 'visualization',
482
+ key: 'visualization',
483
+ width: 140,
484
+ render: (val: string) => <Tag color="blue">{String(val).toUpperCase()}</Tag>,
485
+ },
486
+ {
487
+ title: t('Data View'),
488
+ key: 'dataView',
489
+ render: (_: unknown, row) =>
490
+ row.dataView ? `${row.dataView.title} (${row.dataView.indexPattern})` : String(row.dataViewId),
491
+ },
492
+ {
493
+ title: t('Published'),
494
+ dataIndex: 'published',
495
+ key: 'published',
496
+ width: 120,
497
+ render: (pub: boolean) => <Tag color={pub ? 'success' : 'default'}>{pub ? t('Published') : t('Draft')}</Tag>,
498
+ },
499
+ {
500
+ title: '',
501
+ key: 'actions',
502
+ width: 180,
503
+ render: (_: unknown, row) => (
504
+ <Space>
505
+ <Button size="small" icon={<EditOutlined />} onClick={() => openEditReportStudio(row)}>
506
+ {t('Edit')}
507
+ </Button>
508
+ <Popconfirm
509
+ title={t('Confirm delete?')}
510
+ onConfirm={async () => {
511
+ await removeReport(api, row.id);
512
+ message.success(t('Deleted successfully'));
513
+ await loadAll();
514
+ }}
515
+ >
516
+ <Button size="small" danger icon={<DeleteOutlined />}>
517
+ {t('Delete')}
518
+ </Button>
519
+ </Popconfirm>
520
+ </Space>
521
+ ),
522
+ },
523
+ ];
524
+
525
+ const dataViewColumns: TableColumnsType<EsDataViewRecord> = [
526
+ { title: t('Title'), dataIndex: 'title', key: 'title' },
527
+ { title: t('Data Source (Elasticsearch)'), dataIndex: 'dataSourceKey', key: 'dataSourceKey' },
528
+ {
529
+ title: t('Index Pattern'),
530
+ dataIndex: 'indexPattern',
531
+ key: 'indexPattern',
532
+ render: (val: string) => <Tag>{val}</Tag>,
533
+ },
534
+ { title: t('Time Field'), dataIndex: 'timeField', key: 'timeField', render: (v?: string | null) => v || '—' },
535
+ {
536
+ title: t('Fields'),
537
+ key: 'fieldCount',
538
+ width: 110,
539
+ render: (_: unknown, row) => row.cachedFields?.length ?? 0,
540
+ },
541
+ {
542
+ title: '',
543
+ key: 'actions',
544
+ width: 260,
545
+ render: (_: unknown, row) => (
546
+ <Space>
547
+ <Button
548
+ size="small"
549
+ icon={<ReloadOutlined />}
550
+ onClick={async () => {
551
+ await fetchDataViewFields(api, row.id, true);
552
+ message.success(t('Saved successfully'));
553
+ await loadAll();
554
+ }}
555
+ >
556
+ {t('Refresh Fields')}
557
+ </Button>
558
+ <Button size="small" icon={<EditOutlined />} onClick={() => openEditDataViewModal(row)}>
559
+ {t('Edit')}
560
+ </Button>
561
+ <Popconfirm
562
+ title={t('Confirm delete?')}
563
+ onConfirm={async () => {
564
+ await removeDataView(api, row.id);
565
+ message.success(t('Deleted successfully'));
566
+ await loadAll();
567
+ }}
568
+ >
569
+ <Button size="small" danger icon={<DeleteOutlined />} aria-label={t('Delete')} />
570
+ </Popconfirm>
571
+ </Space>
572
+ ),
573
+ },
574
+ ];
575
+
576
+ return (
577
+ <Card bordered={false}>
578
+ <Tabs
579
+ items={[
580
+ {
581
+ key: 'reports',
582
+ label: t('Reports'),
583
+ children: (
584
+ <div>
585
+ <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
586
+ <Space>
587
+ <Button type="primary" icon={<PlusOutlined />} onClick={openNewReportStudio}>
588
+ {t('New Report')}
589
+ </Button>
590
+ <Button icon={<ReloadOutlined />} onClick={loadAll}>
591
+ {t('Refresh')}
592
+ </Button>
593
+ </Space>
594
+ </div>
595
+ <Table<EsReportRecord> rowKey="id" loading={loadingList} columns={reportColumns} dataSource={reports} />
596
+ </div>
597
+ ),
598
+ },
599
+ {
600
+ key: 'dataViews',
601
+ label: t('Data Views'),
602
+ children: (
603
+ <div>
604
+ <div style={{ display: 'flex', justifyContent: 'space-between', marginBottom: 16 }}>
605
+ <Space>
606
+ <Button type="primary" icon={<PlusOutlined />} onClick={openNewDataViewModal}>
607
+ {t('New Data View')}
608
+ </Button>
609
+ <Button icon={<ReloadOutlined />} onClick={loadAll}>
610
+ {t('Refresh')}
611
+ </Button>
612
+ </Space>
613
+ </div>
614
+ <Table<EsDataViewRecord>
615
+ rowKey="id"
616
+ loading={loadingList}
617
+ columns={dataViewColumns}
618
+ dataSource={dataViews}
619
+ />
620
+ </div>
621
+ ),
622
+ },
623
+ {
624
+ key: 'mcp',
625
+ label: t('MCP & AI Employee'),
626
+ children: (
627
+ <Space direction="vertical" size={16} style={{ width: '100%' }}>
628
+ <Alert
629
+ type="info"
630
+ showIcon
631
+ message={t('AI Employee Usage')}
632
+ description={t(
633
+ 'This plugin automatically registers the elastic-report MCP server (with user context) and AI Employee tools so AI agents can inspect fields, preview Elasticsearch queries, and publish Saved Reports ready to select in blocks.',
634
+ )}
635
+ />
636
+ {mcpInfo && (
637
+ <Descriptions bordered column={1} size="small">
638
+ <Descriptions.Item label={t('MCP Server Name')}>
639
+ <Tag color="purple">{mcpInfo.serverName}</Tag>
640
+ </Descriptions.Item>
641
+ <Descriptions.Item label={t('Dedicated MCP Endpoint')}>
642
+ <Space>
643
+ <code>{mcpInfo.endpointPath}</code>
644
+ <Button
645
+ size="small"
646
+ icon={<CopyOutlined />}
647
+ onClick={() => {
648
+ navigator.clipboard?.writeText(window.location.origin + mcpInfo.endpointPath);
649
+ message.success(t('Copied to clipboard'));
650
+ }}
651
+ >
652
+ {t('Copy')}
653
+ </Button>
654
+ </Space>
655
+ </Descriptions.Item>
656
+ </Descriptions>
657
+ )}
658
+ <Card size="small" title={t('Exposed MCP Tools')}>
659
+ <Table
660
+ size="small"
661
+ rowKey="name"
662
+ pagination={false}
663
+ dataSource={mcpInfo?.tools ?? []}
664
+ columns={[
665
+ {
666
+ title: 'Tool',
667
+ dataIndex: 'name',
668
+ key: 'name',
669
+ width: 220,
670
+ render: (v: string) => <code>{v}</code>,
671
+ },
672
+ { title: t('Description'), dataIndex: 'description', key: 'description' },
673
+ ]}
674
+ />
675
+ </Card>
676
+ </Space>
677
+ ),
678
+ },
679
+ ]}
680
+ />
681
+
682
+ {/* Data View Modal */}
683
+ <Modal
684
+ title={editingDataView ? t('Edit Data View') : t('New Data View')}
685
+ open={dvModalOpen}
686
+ confirmLoading={dvSaving}
687
+ onCancel={() => setDvModalOpen(false)}
688
+ onOk={handleSaveDataView}
689
+ width={600}
690
+ >
691
+ <Form form={dvForm} layout="vertical">
692
+ <Form.Item name="title" label={t('Title')} rules={[{ required: true }]}>
693
+ <Input placeholder="Application Logs" />
694
+ </Form.Item>
695
+ <Form.Item name="dataSourceKey" label={t('Data Source (Elasticsearch)')} rules={[{ required: true }]}>
696
+ <Select
697
+ options={connections.map((c) => ({
698
+ label: `${c.displayName} (${c.key})`,
699
+ value: c.key,
700
+ }))}
701
+ />
702
+ </Form.Item>
703
+ <Form.Item name="indexPattern" label={t('Index Pattern')} rules={[{ required: true }]}>
704
+ <Space.Compact style={{ width: '100%' }}>
705
+ <Input placeholder="logs-*" />
706
+ <Button loading={loadingIndices} icon={<EyeOutlined />} onClick={handleBrowseIndices}>
707
+ {t('Browse Indices')}
708
+ </Button>
709
+ </Space.Compact>
710
+ </Form.Item>
711
+ {matchedIndices.length > 0 && (
712
+ <Paragraph style={{ fontSize: 12 }}>
713
+ <Text strong>{t('Matching Indices')}: </Text>
714
+ {matchedIndices.slice(0, 20).map((idx) => (
715
+ <Tag key={idx} style={{ marginBottom: 4 }}>
716
+ {idx}
717
+ </Tag>
718
+ ))}
719
+ </Paragraph>
720
+ )}
721
+ <Form.Item name="timeField" label={t('Time Field')}>
722
+ <Input placeholder="@timestamp" />
723
+ </Form.Item>
724
+ <Form.Item name="description" label={t('Description')}>
725
+ <Input.TextArea rows={2} />
726
+ </Form.Item>
727
+ </Form>
728
+ </Modal>
729
+
730
+ {/* Report Studio Drawer */}
731
+ <Drawer
732
+ title={editingReport ? t('Edit Report') : t('New Report')}
733
+ open={studioOpen}
734
+ onClose={() => setStudioOpen(false)}
735
+ width={1080}
736
+ extra={
737
+ <Space>
738
+ <Button icon={<PlayCircleOutlined />} loading={previewLoading} onClick={() => handleRunStudioPreview()}>
739
+ {t('Run Preview')}
740
+ </Button>
741
+ <Button type="primary" loading={savingReport} onClick={handleSaveReport}>
742
+ {t('Save')}
743
+ </Button>
744
+ </Space>
745
+ }
746
+ >
747
+ <Form form={reportForm} layout="vertical">
748
+ <Row gutter={16}>
749
+ <Col xs={24} md={10}>
750
+ <Form.Item name="title" label={t('Title')} rules={[{ required: true }]}>
751
+ <Input placeholder="HTTP 5xx Error Logs" />
752
+ </Form.Item>
753
+ </Col>
754
+ <Col xs={24} md={7}>
755
+ <Form.Item name="dataViewId" label={t('Data View')} rules={[{ required: true }]}>
756
+ <Select
757
+ options={dataViews.map((dv) => ({
758
+ label: `${dv.title} (${dv.indexPattern})`,
759
+ value: dv.id,
760
+ }))}
761
+ />
762
+ </Form.Item>
763
+ </Col>
764
+ <Col xs={24} md={7}>
765
+ <Form.Item name="visualization" label={t('Visualization')} rules={[{ required: true }]}>
766
+ <Select
767
+ options={[
768
+ { label: t('Table (Discover)'), value: 'table' },
769
+ { label: t('Bar Chart'), value: 'bar' },
770
+ { label: t('Line Chart'), value: 'line' },
771
+ { label: t('Area Chart'), value: 'area' },
772
+ { label: t('Pie Chart'), value: 'pie' },
773
+ { label: t('Metric KPI'), value: 'metric' },
774
+ ]}
775
+ />
776
+ </Form.Item>
777
+ </Col>
778
+ </Row>
779
+
780
+ <Row gutter={16}>
781
+ <Col xs={24} md={14}>
782
+ <Form.Item name="query" label={t('KQL / Search Query')}>
783
+ <Input placeholder={t('Search KQL, e.g. status >= 500 AND service: "api"')} />
784
+ </Form.Item>
785
+ </Col>
786
+ <Col xs={12} md={5}>
787
+ <Form.Item name="timePreset" label={t('Time Field')}>
788
+ <Select
789
+ options={[
790
+ { label: t('Last 15 minutes'), value: 'last_15m' },
791
+ { label: t('Last 1 hour'), value: 'last_1h' },
792
+ { label: t('Last 24 hours'), value: 'last_24h' },
793
+ { label: t('Last 7 days'), value: 'last_7d' },
794
+ { label: t('Last 30 days'), value: 'last_30d' },
795
+ { label: t('Last 90 days'), value: 'last_90d' },
796
+ { label: t('All time'), value: 'all' },
797
+ ]}
798
+ />
799
+ </Form.Item>
800
+ </Col>
801
+ <Col xs={12} md={5}>
802
+ <Form.Item name="published" label={t('Published')} valuePropName="checked">
803
+ <Switch />
804
+ </Form.Item>
805
+ </Col>
806
+ </Row>
807
+
808
+ {/* Structured Filters Builder */}
809
+ <Card size="small" title={t('Add Filter')} style={{ marginBottom: 12 }}>
810
+ <Form.List name="filters">
811
+ {(fieldsList, { add, remove }) => (
812
+ <Space direction="vertical" style={{ width: '100%' }}>
813
+ {fieldsList.map(({ key, name }) => (
814
+ <Space key={key} wrap align="baseline">
815
+ <Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 190 }}>
816
+ <Select
817
+ showSearch
818
+ placeholder={t('Field')}
819
+ options={studioFields.map((f) => ({ label: `${f.name} (${f.type})`, value: f.name }))}
820
+ />
821
+ </Form.Item>
822
+ <Form.Item name={[name, 'operator']} style={{ marginBottom: 0, minWidth: 160 }}>
823
+ <Select options={FILTER_OPERATOR_ITEMS} />
824
+ </Form.Item>
825
+ <Form.Item name={[name, 'value']} style={{ marginBottom: 0 }}>
826
+ <Input placeholder={t('Value')} />
827
+ </Form.Item>
828
+ <Form.Item name={[name, 'valueTo']} style={{ marginBottom: 0 }}>
829
+ <Input placeholder={t('To Value')} style={{ width: 120 }} />
830
+ </Form.Item>
831
+ <Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
832
+ </Space>
833
+ ))}
834
+ <Button size="small" type="dashed" icon={<PlusOutlined />} onClick={() => add({ operator: 'eq' })}>
835
+ {t('Add Filter')}
836
+ </Button>
837
+ </Space>
838
+ )}
839
+ </Form.List>
840
+ </Card>
841
+
842
+ {watchedVisualization === 'table' ? (
843
+ <Row gutter={16}>
844
+ <Col xs={24} md={12}>
845
+ <Form.Item name="columns" label={t('Columns')}>
846
+ <Select
847
+ mode="multiple"
848
+ allowClear
849
+ placeholder={t('Auto-detect columns from documents')}
850
+ options={studioFields.filter((f) => !f.isSubfield).map((f) => ({ label: f.name, value: f.name }))}
851
+ />
852
+ </Form.Item>
853
+ <Card size="small" title={t('Sort')} style={{ marginBottom: 12 }}>
854
+ <Form.List name="sort">
855
+ {(sortList, { add, remove }) => (
856
+ <Space direction="vertical" style={{ width: '100%' }}>
857
+ {sortList.map(({ key, name }) => (
858
+ <Space key={key} align="baseline">
859
+ <Form.Item name={[name, 'field']} style={{ marginBottom: 0, minWidth: 200 }}>
860
+ <Select
861
+ showSearch
862
+ placeholder={t('Field')}
863
+ options={aggregatableStudioFields.map((f) => ({
864
+ label: f.keywordSubfield ? `${f.name} (${f.keywordSubfield})` : f.name,
865
+ value: f.keywordSubfield || f.name,
866
+ }))}
867
+ />
868
+ </Form.Item>
869
+ <Form.Item name={[name, 'order']} style={{ marginBottom: 0, minWidth: 130 }}>
870
+ <Select
871
+ options={[
872
+ { label: t('Descending'), value: 'desc' },
873
+ { label: t('Ascending'), value: 'asc' },
874
+ ]}
875
+ />
876
+ </Form.Item>
877
+ <Button size="small" danger icon={<DeleteOutlined />} onClick={() => remove(name)} />
878
+ </Space>
879
+ ))}
880
+ <Button
881
+ size="small"
882
+ type="dashed"
883
+ icon={<PlusOutlined />}
884
+ onClick={() => add({ order: 'desc' })}
885
+ >
886
+ {t('Add Sort')}
887
+ </Button>
888
+ </Space>
889
+ )}
890
+ </Form.List>
891
+ </Card>
892
+ </Col>
893
+ <Col xs={24} md={12}>
894
+ <Row gutter={12}>
895
+ <Col span={8}>
896
+ <Form.Item name="pageSize" label={t('Page Size')}>
897
+ <InputNumber min={5} max={200} style={{ width: '100%' }} />
898
+ </Form.Item>
899
+ </Col>
900
+ <Col span={8}>
901
+ <Form.Item
902
+ name="showHistogram"
903
+ label={t('Show time histogram above table')}
904
+ valuePropName="checked"
905
+ >
906
+ <Switch />
907
+ </Form.Item>
908
+ </Col>
909
+ <Col span={8}>
910
+ <Form.Item
911
+ name="allowInteractiveControls"
912
+ label={t('Allow interactive search/filter on block')}
913
+ valuePropName="checked"
914
+ >
915
+ <Switch />
916
+ </Form.Item>
917
+ </Col>
918
+ </Row>
919
+ <Form.Item name="description" label={t('Description')}>
920
+ <Input.TextArea rows={2} />
921
+ </Form.Item>
922
+ </Col>
923
+ </Row>
924
+ ) : (
925
+ <Card size="small" style={{ marginBottom: 12 }}>
926
+ <Row gutter={16}>
927
+ {watchedVisualization !== 'metric' && (
928
+ <>
929
+ <Col xs={12} md={6}>
930
+ <Form.Item name="bucketType" label={t('Bucket Type')}>
931
+ <Select
932
+ options={[
933
+ { label: t('Date Histogram'), value: 'date_histogram' },
934
+ { label: t('Top Terms'), value: 'terms' },
935
+ ]}
936
+ />
937
+ </Form.Item>
938
+ </Col>
939
+ <Col xs={12} md={6}>
940
+ <Form.Item name="bucketField" label={t('Bucket Field')}>
941
+ <Select
942
+ showSearch
943
+ allowClear
944
+ options={aggregatableStudioFields.map((f) => ({
945
+ label: f.keywordSubfield ? `${f.name} → ${f.keywordSubfield}` : f.name,
946
+ value: f.keywordSubfield || f.name,
947
+ }))}
948
+ />
949
+ </Form.Item>
950
+ </Col>
951
+ {watchedBucketType === 'date_histogram' ? (
952
+ <Col xs={12} md={4}>
953
+ <Form.Item name="calendarInterval" label={t('Interval')}>
954
+ <Select
955
+ options={[
956
+ { label: 'Auto', value: 'auto' },
957
+ { label: '1m', value: '1m' },
958
+ { label: '5m', value: '5m' },
959
+ { label: '15m', value: '15m' },
960
+ { label: '1h', value: '1h' },
961
+ { label: '1d', value: '1d' },
962
+ { label: '1w', value: '1w' },
963
+ { label: '1M', value: '1M' },
964
+ ]}
965
+ />
966
+ </Form.Item>
967
+ </Col>
968
+ ) : (
969
+ <Col xs={12} md={4}>
970
+ <Form.Item name="topN" label={t('Top N')}>
971
+ <InputNumber min={1} max={50} style={{ width: '100%' }} />
972
+ </Form.Item>
973
+ </Col>
974
+ )}
975
+ </>
976
+ )}
977
+ <Col xs={12} md={4}>
978
+ <Form.Item name="metricType" label={t('Metric')}>
979
+ <Select
980
+ options={[
981
+ { label: 'Count', value: 'count' },
982
+ { label: 'Sum', value: 'sum' },
983
+ { label: 'Average', value: 'avg' },
984
+ { label: 'Min', value: 'min' },
985
+ { label: 'Max', value: 'max' },
986
+ { label: 'Unique (Cardinality)', value: 'cardinality' },
987
+ ]}
988
+ />
989
+ </Form.Item>
990
+ </Col>
991
+ {watchedMetricType !== 'count' && (
992
+ <Col xs={12} md={4}>
993
+ <Form.Item name="metricField" label={t('Metric Field')}>
994
+ <Select
995
+ showSearch
996
+ options={(watchedMetricType === 'cardinality'
997
+ ? aggregatableStudioFields
998
+ : numericStudioFields.length > 0
999
+ ? numericStudioFields
1000
+ : aggregatableStudioFields
1001
+ ).map((f) => ({
1002
+ label: f.name,
1003
+ value: f.keywordSubfield || f.name,
1004
+ }))}
1005
+ />
1006
+ </Form.Item>
1007
+ </Col>
1008
+ )}
1009
+ <Col xs={12} md={6}>
1010
+ <Form.Item name="metricLabel" label={t('Metric Label')}>
1011
+ <Input placeholder="Requests / Latency (ms)" />
1012
+ </Form.Item>
1013
+ </Col>
1014
+ <Col xs={12} md={6}>
1015
+ <Form.Item
1016
+ name="allowInteractiveControls"
1017
+ label={t('Allow interactive search/filter on block')}
1018
+ valuePropName="checked"
1019
+ >
1020
+ <Switch />
1021
+ </Form.Item>
1022
+ </Col>
1023
+ </Row>
1024
+ </Card>
1025
+ )}
1026
+ </Form>
1027
+
1028
+ <Divider orientation="left">{t('Preview')}</Divider>
1029
+ <ElasticReportRenderer
1030
+ title={reportForm.getFieldValue('title') || t('Preview')}
1031
+ spec={studioPreviewSpec}
1032
+ dataView={selectedDataView}
1033
+ fields={studioFields}
1034
+ result={previewResult}
1035
+ loading={previewLoading}
1036
+ error={previewError}
1037
+ showToolbar={true}
1038
+ onExecute={(overrides) => {
1039
+ handleRunStudioPreview(overrides);
1040
+ }}
1041
+ />
1042
+ </Drawer>
1043
+ </Card>
1044
+ );
1045
+ };
1046
+
1047
+ export default ElasticReportManager;