plugin-elastic-report 0.0.0-stage → 0.7.0
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.
- package/ai/skills/elastic-report/SKILLS.md +34 -0
- package/client-v2.d.ts +2 -0
- package/client-v2.js +1 -0
- package/client.d.ts +2 -0
- package/client.js +1 -0
- package/dist/client/357.0dd385384cab5dbf.js +10 -0
- package/dist/client/index.js +10 -0
- package/dist/client-v2/851.142c93fc6d666b28.js +10 -0
- package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
- package/dist/client-v2/877.f4095a3dbcadf98f.js +10 -0
- package/dist/client-v2/index.js +10 -0
- package/dist/externalVersion.js +21 -0
- package/dist/index.js +48 -0
- package/dist/locale/en-US.json +198 -0
- package/dist/locale/vi-VN.json +198 -0
- package/dist/locale/zh-CN.json +198 -0
- package/dist/node_modules/@elastic/elasticsearch/.dockerignore +11 -0
- package/dist/node_modules/@elastic/elasticsearch/LICENSE +202 -0
- package/dist/node_modules/@elastic/elasticsearch/NOTICE.txt +2 -0
- package/dist/node_modules/@elastic/elasticsearch/catalog-info.yaml +50 -0
- package/dist/node_modules/@elastic/elasticsearch/codecov.yml +14 -0
- package/dist/node_modules/@elastic/elasticsearch/index.d.ts +28 -0
- package/dist/node_modules/@elastic/elasticsearch/index.js +85525 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/async_search.js +155 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/autoscaling.js +130 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/bulk.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/capabilities.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.d.ts +193 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cat.js +766 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ccr.js +395 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/clear_scroll.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/close_point_in_time.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.d.ts +123 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/cluster.js +482 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.d.ts +245 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/connector.js +1121 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/count.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/create.js +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/dangling_indices.js +100 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/delete_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/enrich.js +169 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/eql.js +139 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.d.ts +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/esql.js +170 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/exists_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/explain.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/features.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/field_caps.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.d.ts +50 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/fleet.js +211 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_context.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_script_languages.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/get_source.js +46 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/graph.js +70 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/health_report.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.d.ts +88 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ilm.js +329 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/index.js +61 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.d.ts +494 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/indices.js +2133 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.d.ts +221 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/inference.js +1167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/info.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.d.ts +95 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ingest.js +389 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/knn_search.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/license.js +194 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/logstash.js +118 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mget.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/migration.js +107 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.d.ts +522 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ml.js +2468 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/monitoring.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/msearch_template.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/mtermvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/nodes.js +290 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/open_point_in_time.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ping.js +43 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/profiling.js +135 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/put_script.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/query_rules.js +260 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rank_eval.js +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/reindex_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/render_search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.d.ts +67 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/rollup.js +263 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scripts_painless_execute.js +57 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/scroll.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.d.ts +81 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_application.js +313 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_mvt.js +63 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_shards.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/search_template.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/searchable_snapshots.js +167 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.d.ts +459 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/security.js +1982 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/shutdown.js +125 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/simulate.js +78 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.d.ts +74 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/slm.js +253 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/snapshot.js +410 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.d.ts +53 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/sql.js +205 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.d.ts +18 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/ssl.js +54 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/streams.js +96 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.d.ts +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/synonyms.js +223 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.d.ts +32 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/tasks.js +109 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/terms_enum.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/termvectors.js +68 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.d.ts +39 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/text_structure.js +148 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.d.ts +101 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/transform.js +386 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update.js +60 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query.js +59 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.d.ts +14 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/update_by_query_rethrottle.js +45 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.d.ts +102 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/watcher.js +405 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.d.ts +25 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/api/xpack.js +75 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.d.ts +265 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/index.js +632 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.d.ts +19933 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/types.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.d.ts +20606 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/api/typesWithBodyKey.js +21 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.d.ts +152 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/client.js +369 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.d.ts +184 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/helpers.js +889 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.d.ts +4 -0
- package/dist/node_modules/@elastic/elasticsearch/lib/sniffingTransport.js +56 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +15 -0
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +7 -0
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -0
- package/dist/node_modules/@elastic/elasticsearch/tsconfig.json +38 -0
- package/dist/server/acl-guard.js +179 -0
- package/dist/server/collections/es-report-data-views.js +85 -0
- package/dist/server/collections/es-reports.js +101 -0
- package/dist/server/index.js +58 -0
- package/dist/server/mcp/ElasticReportMcpServer.js +344 -0
- package/dist/server/mcp/ElasticReportToolCatalog.js +639 -0
- package/dist/server/plugin.js +529 -0
- package/dist/server/services/ElasticReportService.js +377 -0
- package/dist/server/services/ElasticsearchConnectionService.js +572 -0
- package/dist/server/services/ReportExportService.js +243 -0
- package/dist/server/services/ReportQueryCompiler.js +1299 -0
- package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
- package/dist/shared/constants.js +96 -0
- package/dist/shared/types.js +24 -0
- package/package.json +62 -4
- package/server.d.ts +2 -0
- package/server.js +1 -0
- package/src/client/index.tsx +34 -0
- package/src/client/workflow-instructions.tsx +44 -0
- package/src/client-v2/__tests__/elastic-report.test.tsx +791 -0
- package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
- package/src/client-v2/api.ts +320 -0
- package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
- package/src/client-v2/components/ElasticBasicCharts.tsx +652 -0
- package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
- package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
- package/src/client-v2/components/ElasticReportBlock.tsx +306 -0
- package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -0
- package/src/client-v2/components/HighlightText.tsx +50 -0
- package/src/client-v2/components/ReportSelect.tsx +85 -0
- package/src/client-v2/index.tsx +14 -0
- package/src/client-v2/locale.ts +23 -0
- package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
- package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -0
- package/src/client-v2/pages/ElasticReportManager.tsx +1453 -0
- package/src/client-v2/plugin.tsx +72 -0
- package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
- package/src/client-v2/workflow/instructions.tsx +149 -0
- package/src/index.ts +11 -0
- package/src/locale/en-US.json +198 -0
- package/src/locale/vi-VN.json +198 -0
- package/src/locale/zh-CN.json +198 -0
- package/src/server/__tests__/query-compiler.test.ts +620 -0
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -0
- package/src/server/acl-guard.ts +194 -0
- package/src/server/collections/es-report-data-views.ts +64 -0
- package/src/server/collections/es-reports.ts +80 -0
- package/src/server/index.ts +15 -0
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -0
- package/src/server/mcp/ElasticReportToolCatalog.ts +663 -0
- package/src/server/plugin.ts +599 -0
- package/src/server/services/ElasticReportService.ts +486 -0
- package/src/server/services/ElasticsearchConnectionService.ts +728 -0
- package/src/server/services/ReportExportService.ts +282 -0
- package/src/server/services/ReportQueryCompiler.ts +1552 -0
- package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
- package/src/shared/constants.ts +36 -0
- package/src/shared/types.ts +272 -0
- package/README.md +0 -3
|
@@ -0,0 +1,529 @@
|
|
|
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
|
+
var __defProp = Object.defineProperty;
|
|
11
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
12
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
13
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
14
|
+
var __export = (target, all) => {
|
|
15
|
+
for (var name in all)
|
|
16
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
17
|
+
};
|
|
18
|
+
var __copyProps = (to, from, except, desc) => {
|
|
19
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
+
for (let key of __getOwnPropNames(from))
|
|
21
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
22
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
23
|
+
}
|
|
24
|
+
return to;
|
|
25
|
+
};
|
|
26
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
27
|
+
var plugin_exports = {};
|
|
28
|
+
__export(plugin_exports, {
|
|
29
|
+
PluginElasticReportServer: () => PluginElasticReportServer,
|
|
30
|
+
default: () => plugin_default
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(plugin_exports);
|
|
33
|
+
var import_path = require("path");
|
|
34
|
+
var import_server = require("@nocobase/server");
|
|
35
|
+
var import_constants = require("../shared/constants");
|
|
36
|
+
var import_acl_guard = require("./acl-guard");
|
|
37
|
+
var import_ElasticReportMcpServer = require("./mcp/ElasticReportMcpServer");
|
|
38
|
+
var import_ElasticReportToolCatalog = require("./mcp/ElasticReportToolCatalog");
|
|
39
|
+
var import_ElasticsearchConnectionService = require("./services/ElasticsearchConnectionService");
|
|
40
|
+
var import_ElasticReportService = require("./services/ElasticReportService");
|
|
41
|
+
var import_ReportExportService = require("./services/ReportExportService");
|
|
42
|
+
var import_ElasticReportQueryInstruction = require("./workflow/ElasticReportQueryInstruction");
|
|
43
|
+
function isRecord(value) {
|
|
44
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
45
|
+
}
|
|
46
|
+
function getActionPayload(ctx) {
|
|
47
|
+
var _a, _b, _c;
|
|
48
|
+
const query = isRecord((_a = ctx.request) == null ? void 0 : _a.query) ? ctx.request.query : {};
|
|
49
|
+
const actionParams = isRecord((_b = ctx.action) == null ? void 0 : _b.params) ? ctx.action.params : {};
|
|
50
|
+
const body = isRecord((_c = ctx.request) == null ? void 0 : _c.body) ? ctx.request.body : {};
|
|
51
|
+
const paramValues = isRecord(actionParams.values) ? actionParams.values : {};
|
|
52
|
+
return {
|
|
53
|
+
...query,
|
|
54
|
+
...actionParams,
|
|
55
|
+
...body,
|
|
56
|
+
...paramValues
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function parseIdParam(value, label) {
|
|
60
|
+
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
61
|
+
if (typeof value === "string" && value.trim()) return value.trim();
|
|
62
|
+
const err = new Error(`${label} is required`);
|
|
63
|
+
err.status = 400;
|
|
64
|
+
throw err;
|
|
65
|
+
}
|
|
66
|
+
function parseOverridesParam(raw) {
|
|
67
|
+
if (isRecord(raw)) {
|
|
68
|
+
return raw;
|
|
69
|
+
}
|
|
70
|
+
if (typeof raw === "string" && raw.trim()) {
|
|
71
|
+
try {
|
|
72
|
+
const parsed = JSON.parse(raw);
|
|
73
|
+
return isRecord(parsed) ? parsed : void 0;
|
|
74
|
+
} catch {
|
|
75
|
+
return void 0;
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
class PluginElasticReportServer extends import_server.Plugin {
|
|
81
|
+
connectionService;
|
|
82
|
+
reportService;
|
|
83
|
+
exportService;
|
|
84
|
+
mcpServer;
|
|
85
|
+
toolsCatalog = [];
|
|
86
|
+
schemaCollections = [import_constants.DATA_VIEWS_COLLECTION, import_constants.REPORTS_COLLECTION];
|
|
87
|
+
async beforeLoad() {
|
|
88
|
+
var _a;
|
|
89
|
+
await this.db.import({
|
|
90
|
+
directory: (0, import_path.resolve)(__dirname, "collections")
|
|
91
|
+
});
|
|
92
|
+
this.connectionService = new import_ElasticsearchConnectionService.ElasticsearchConnectionService(this.app);
|
|
93
|
+
this.reportService = new import_ElasticReportService.ElasticReportService(this.app, this.connectionService);
|
|
94
|
+
this.exportService = new import_ReportExportService.ReportExportService(this.connectionService, this.reportService);
|
|
95
|
+
this.toolsCatalog = (0, import_ElasticReportToolCatalog.createElasticReportToolCatalog)(this.app, this.reportService);
|
|
96
|
+
this.mcpServer = new import_ElasticReportMcpServer.ElasticReportMcpServer({
|
|
97
|
+
version: ((_a = this.options) == null ? void 0 : _a.version) || "0.7.0",
|
|
98
|
+
tools: this.toolsCatalog,
|
|
99
|
+
logger: this.app.logger
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
async load() {
|
|
103
|
+
this.registerServiceResource();
|
|
104
|
+
this.registerMcpEndpoint();
|
|
105
|
+
this.registerAclRules();
|
|
106
|
+
this.registerWorkflowInstructions();
|
|
107
|
+
this.registerAITools();
|
|
108
|
+
await this.registerPluginMcpClientEntry();
|
|
109
|
+
this.app.on("beforeStop", async () => {
|
|
110
|
+
var _a;
|
|
111
|
+
await ((_a = this.connectionService) == null ? void 0 : _a.close());
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
registerWorkflowInstructions() {
|
|
115
|
+
const workflow = this.app.pm.get("workflow");
|
|
116
|
+
if (!workflow || typeof workflow.registerInstruction !== "function") {
|
|
117
|
+
return;
|
|
118
|
+
}
|
|
119
|
+
workflow.registerInstruction(
|
|
120
|
+
import_constants.WORKFLOW_INSTRUCTION_TYPE,
|
|
121
|
+
new import_ElasticReportQueryInstruction.ElasticReportQueryInstruction(workflow, this.reportService)
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
async install(_options) {
|
|
125
|
+
await this.ensureSchema();
|
|
126
|
+
}
|
|
127
|
+
async upgrade() {
|
|
128
|
+
await this.ensureSchema();
|
|
129
|
+
}
|
|
130
|
+
getApiBasePath() {
|
|
131
|
+
var _a, _b;
|
|
132
|
+
const rawPrefix = ((_b = (_a = this.app.resourcer) == null ? void 0 : _a.options) == null ? void 0 : _b.prefix) ?? process.env.API_BASE_PATH ?? "/api";
|
|
133
|
+
const cleaned = rawPrefix.replace(/\/+/g, "/").replace(/\/$/, "");
|
|
134
|
+
return cleaned;
|
|
135
|
+
}
|
|
136
|
+
getMcpEndpointPath() {
|
|
137
|
+
return `${this.getApiBasePath()}${import_constants.MCP_RELATIVE_PATH}`;
|
|
138
|
+
}
|
|
139
|
+
resolveInternalMcpUrl() {
|
|
140
|
+
const port = process.env.APP_PORT || "13000";
|
|
141
|
+
const host = process.env.ELASTIC_REPORT_MCP_INTERNAL_HOST || `http://127.0.0.1:${port}`;
|
|
142
|
+
return `${host.replace(/\/$/, "")}${this.getMcpEndpointPath()}`;
|
|
143
|
+
}
|
|
144
|
+
registerServiceResource() {
|
|
145
|
+
this.app.resourceManager.define({
|
|
146
|
+
name: import_constants.SERVICE_RESOURCE,
|
|
147
|
+
actions: {
|
|
148
|
+
listConnections: async (ctx, next) => {
|
|
149
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
150
|
+
ctx.body = await this.reportService.listConnections();
|
|
151
|
+
await next();
|
|
152
|
+
},
|
|
153
|
+
testConnection: async (ctx, next) => {
|
|
154
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
155
|
+
const payload = getActionPayload(ctx);
|
|
156
|
+
const dataSourceKey = typeof payload.dataSourceKey === "string" ? payload.dataSourceKey.trim() : "";
|
|
157
|
+
if (!dataSourceKey) {
|
|
158
|
+
ctx.throw(400, "dataSourceKey is required");
|
|
159
|
+
}
|
|
160
|
+
const indexPattern = typeof payload.indexPattern === "string" && payload.indexPattern.trim() ? payload.indexPattern.trim() : "*";
|
|
161
|
+
try {
|
|
162
|
+
ctx.body = await this.reportService.testConnection(dataSourceKey, indexPattern);
|
|
163
|
+
} catch (error) {
|
|
164
|
+
ctx.throw(400, error instanceof Error ? error.message : String(error));
|
|
165
|
+
}
|
|
166
|
+
await next();
|
|
167
|
+
},
|
|
168
|
+
listRoles: async (ctx, next) => {
|
|
169
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
170
|
+
ctx.body = await this.reportService.listAvailableRoles();
|
|
171
|
+
await next();
|
|
172
|
+
},
|
|
173
|
+
listIndices: async (ctx, next) => {
|
|
174
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
175
|
+
const payload = getActionPayload(ctx);
|
|
176
|
+
const dataSourceKey = typeof payload.dataSourceKey === "string" ? payload.dataSourceKey.trim() : "";
|
|
177
|
+
if (!dataSourceKey) {
|
|
178
|
+
ctx.throw(400, "dataSourceKey is required");
|
|
179
|
+
}
|
|
180
|
+
const indexPattern = typeof payload.indexPattern === "string" && payload.indexPattern.trim() ? payload.indexPattern.trim() : "*";
|
|
181
|
+
try {
|
|
182
|
+
ctx.body = await this.reportService.listIndices(dataSourceKey, indexPattern);
|
|
183
|
+
} catch (error) {
|
|
184
|
+
ctx.throw(400, error instanceof Error ? error.message : String(error));
|
|
185
|
+
}
|
|
186
|
+
await next();
|
|
187
|
+
},
|
|
188
|
+
inspectFields: async (ctx, next) => {
|
|
189
|
+
const payload = getActionPayload(ctx);
|
|
190
|
+
try {
|
|
191
|
+
if (payload.dataViewId !== void 0 && payload.dataViewId !== null && String(payload.dataViewId).trim()) {
|
|
192
|
+
const dvId = parseIdParam(payload.dataViewId, "dataViewId");
|
|
193
|
+
const refresh = payload.refresh === true || payload.refresh === "true";
|
|
194
|
+
if (refresh) {
|
|
195
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
196
|
+
} else {
|
|
197
|
+
const dv = await this.reportService.getDataView(dvId);
|
|
198
|
+
(0, import_acl_guard.assertCanAccessDataView)(this.app, ctx, dv);
|
|
199
|
+
}
|
|
200
|
+
ctx.body = await this.reportService.inspectDataViewFields(dvId, refresh);
|
|
201
|
+
} else {
|
|
202
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
203
|
+
const dataSourceKey = typeof payload.dataSourceKey === "string" ? payload.dataSourceKey.trim() : "";
|
|
204
|
+
const indexPattern = typeof payload.indexPattern === "string" ? payload.indexPattern.trim() : "";
|
|
205
|
+
if (!dataSourceKey || !indexPattern) {
|
|
206
|
+
ctx.throw(400, "Either dataViewId or (dataSourceKey + indexPattern) is required");
|
|
207
|
+
}
|
|
208
|
+
const fields = await this.reportService.inspectFieldsBySource(dataSourceKey, indexPattern);
|
|
209
|
+
ctx.body = { fields };
|
|
210
|
+
}
|
|
211
|
+
} catch (error) {
|
|
212
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
213
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
214
|
+
}
|
|
215
|
+
await next();
|
|
216
|
+
},
|
|
217
|
+
upsertDataView: async (ctx, next) => {
|
|
218
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
219
|
+
const payload = getActionPayload(ctx);
|
|
220
|
+
try {
|
|
221
|
+
ctx.body = await this.reportService.upsertDataView(
|
|
222
|
+
{
|
|
223
|
+
...payload.id !== void 0 && payload.id !== null && String(payload.id).trim() !== "" ? { id: parseIdParam(payload.id, "id") } : {},
|
|
224
|
+
title: typeof payload.title === "string" ? payload.title : "",
|
|
225
|
+
dataSourceKey: typeof payload.dataSourceKey === "string" ? payload.dataSourceKey : "",
|
|
226
|
+
indexPattern: typeof payload.indexPattern === "string" ? payload.indexPattern : "",
|
|
227
|
+
timeField: typeof payload.timeField === "string" ? payload.timeField : null,
|
|
228
|
+
description: typeof payload.description === "string" ? payload.description : null,
|
|
229
|
+
...payload.allowedRoles !== void 0 ? { allowedRoles: (0, import_acl_guard.normalizeRoleList)(payload.allowedRoles) } : {}
|
|
230
|
+
},
|
|
231
|
+
(0, import_ElasticReportService.extractCurrentUserId)(ctx)
|
|
232
|
+
);
|
|
233
|
+
} catch (error) {
|
|
234
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
235
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
236
|
+
}
|
|
237
|
+
await next();
|
|
238
|
+
},
|
|
239
|
+
previewReport: async (ctx, next) => {
|
|
240
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
241
|
+
const payload = getActionPayload(ctx);
|
|
242
|
+
try {
|
|
243
|
+
const dataViewId = parseIdParam(payload.dataViewId, "dataViewId");
|
|
244
|
+
ctx.body = await this.reportService.previewReport({
|
|
245
|
+
dataViewId,
|
|
246
|
+
spec: payload.spec,
|
|
247
|
+
overrides: parseOverridesParam(payload.overrides),
|
|
248
|
+
userContext: (0, import_ElasticReportService.extractServerUserContext)(ctx)
|
|
249
|
+
});
|
|
250
|
+
} catch (error) {
|
|
251
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
252
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
253
|
+
}
|
|
254
|
+
await next();
|
|
255
|
+
},
|
|
256
|
+
saveReport: async (ctx, next) => {
|
|
257
|
+
(0, import_acl_guard.assertCanManageReports)(this.app, ctx);
|
|
258
|
+
const payload = getActionPayload(ctx);
|
|
259
|
+
try {
|
|
260
|
+
ctx.body = await this.reportService.saveReport(
|
|
261
|
+
{
|
|
262
|
+
...payload.id !== void 0 && payload.id !== null && String(payload.id).trim() !== "" ? { id: parseIdParam(payload.id, "id") } : {},
|
|
263
|
+
title: typeof payload.title === "string" ? payload.title : "",
|
|
264
|
+
description: typeof payload.description === "string" ? payload.description : null,
|
|
265
|
+
dataViewId: parseIdParam(payload.dataViewId, "dataViewId"),
|
|
266
|
+
spec: payload.spec,
|
|
267
|
+
published: payload.published !== false,
|
|
268
|
+
...payload.allowedRoles !== void 0 ? { allowedRoles: (0, import_acl_guard.normalizeRoleList)(payload.allowedRoles) } : {}
|
|
269
|
+
},
|
|
270
|
+
(0, import_ElasticReportService.extractCurrentUserId)(ctx)
|
|
271
|
+
);
|
|
272
|
+
} catch (error) {
|
|
273
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
274
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
275
|
+
}
|
|
276
|
+
await next();
|
|
277
|
+
},
|
|
278
|
+
listPublishedReports: async (ctx, next) => {
|
|
279
|
+
const payload = getActionPayload(ctx);
|
|
280
|
+
const search = typeof payload.search === "string" ? payload.search : void 0;
|
|
281
|
+
const publishedReports = await this.reportService.listReports({
|
|
282
|
+
publishedOnly: true,
|
|
283
|
+
search
|
|
284
|
+
});
|
|
285
|
+
ctx.body = publishedReports.filter((report) => (0, import_acl_guard.canAccessReport)(this.app, ctx, report, report.dataView));
|
|
286
|
+
await next();
|
|
287
|
+
},
|
|
288
|
+
getReportMeta: async (ctx, next) => {
|
|
289
|
+
var _a, _b;
|
|
290
|
+
const payload = getActionPayload(ctx);
|
|
291
|
+
const rawId = payload.reportId ?? ((_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.filterByTk);
|
|
292
|
+
try {
|
|
293
|
+
const reportId = parseIdParam(rawId, "reportId");
|
|
294
|
+
const report = await this.reportService.getReport(reportId);
|
|
295
|
+
const { dataView, fields } = await this.reportService.inspectDataViewFields(report.dataViewId, false);
|
|
296
|
+
(0, import_acl_guard.assertCanAccessReport)(this.app, ctx, report, dataView);
|
|
297
|
+
ctx.body = { report, dataView, fields };
|
|
298
|
+
} catch (error) {
|
|
299
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
300
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
301
|
+
}
|
|
302
|
+
await next();
|
|
303
|
+
},
|
|
304
|
+
runReport: async (ctx, next) => {
|
|
305
|
+
var _a, _b;
|
|
306
|
+
const payload = getActionPayload(ctx);
|
|
307
|
+
const rawId = payload.reportId ?? ((_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.filterByTk);
|
|
308
|
+
try {
|
|
309
|
+
const reportId = parseIdParam(rawId, "reportId");
|
|
310
|
+
const report = await this.reportService.getReport(reportId);
|
|
311
|
+
const dataView = report.dataView ?? await this.reportService.getDataView(report.dataViewId);
|
|
312
|
+
(0, import_acl_guard.assertCanAccessReport)(this.app, ctx, report, dataView);
|
|
313
|
+
ctx.body = await this.reportService.runSavedReport({
|
|
314
|
+
reportId,
|
|
315
|
+
overrides: parseOverridesParam(payload.overrides),
|
|
316
|
+
requirePublished: false,
|
|
317
|
+
userContext: (0, import_ElasticReportService.extractServerUserContext)(ctx)
|
|
318
|
+
});
|
|
319
|
+
} catch (error) {
|
|
320
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
321
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
322
|
+
}
|
|
323
|
+
await next();
|
|
324
|
+
},
|
|
325
|
+
inspectTopValues: async (ctx, next) => {
|
|
326
|
+
const payload = getActionPayload(ctx);
|
|
327
|
+
try {
|
|
328
|
+
const field = typeof payload.field === "string" ? payload.field.trim() : "";
|
|
329
|
+
if (!field) {
|
|
330
|
+
ctx.throw(400, "field is required");
|
|
331
|
+
}
|
|
332
|
+
let dataViewId;
|
|
333
|
+
let reportId;
|
|
334
|
+
if (payload.reportId !== void 0 && payload.reportId !== null && String(payload.reportId).trim() !== "") {
|
|
335
|
+
reportId = parseIdParam(payload.reportId, "reportId");
|
|
336
|
+
const report = await this.reportService.getReport(reportId);
|
|
337
|
+
const dataView = report.dataView ?? await this.reportService.getDataView(report.dataViewId);
|
|
338
|
+
(0, import_acl_guard.assertCanAccessReport)(this.app, ctx, report, dataView);
|
|
339
|
+
dataViewId = report.dataViewId;
|
|
340
|
+
} else {
|
|
341
|
+
dataViewId = parseIdParam(payload.dataViewId, "dataViewId");
|
|
342
|
+
const dataView = await this.reportService.getDataView(dataViewId);
|
|
343
|
+
(0, import_acl_guard.assertCanAccessDataView)(this.app, ctx, dataView);
|
|
344
|
+
}
|
|
345
|
+
ctx.body = await this.reportService.inspectFieldTopValues({
|
|
346
|
+
dataViewId,
|
|
347
|
+
...reportId !== void 0 ? { reportId } : {},
|
|
348
|
+
field,
|
|
349
|
+
size: typeof payload.size === "number" ? payload.size : Number(payload.size) || 10,
|
|
350
|
+
overrides: parseOverridesParam(payload.overrides),
|
|
351
|
+
userContext: (0, import_ElasticReportService.extractServerUserContext)(ctx)
|
|
352
|
+
});
|
|
353
|
+
} catch (error) {
|
|
354
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
355
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
356
|
+
}
|
|
357
|
+
await next();
|
|
358
|
+
},
|
|
359
|
+
exportReport: async (ctx, next) => {
|
|
360
|
+
var _a, _b;
|
|
361
|
+
const payload = getActionPayload(ctx);
|
|
362
|
+
const rawId = payload.reportId ?? ((_b = (_a = ctx.action) == null ? void 0 : _a.params) == null ? void 0 : _b.filterByTk);
|
|
363
|
+
try {
|
|
364
|
+
const reportId = parseIdParam(rawId, "reportId");
|
|
365
|
+
const report = await this.reportService.getReport(reportId);
|
|
366
|
+
const dataView = report.dataView ?? await this.reportService.getDataView(report.dataViewId);
|
|
367
|
+
(0, import_acl_guard.assertCanAccessReport)(this.app, ctx, report, dataView);
|
|
368
|
+
const format = payload.format === "ndjson" ? "ndjson" : "csv";
|
|
369
|
+
const columns = Array.isArray(payload.columns) ? payload.columns.filter((c) => typeof c === "string" && Boolean(c.trim())) : typeof payload.columns === "string" && payload.columns.trim() ? payload.columns.split(",").map((c) => c.trim()).filter(Boolean) : void 0;
|
|
370
|
+
const maxRows = typeof payload.maxRows === "number" ? payload.maxRows : payload.maxRows !== void 0 ? Number(payload.maxRows) : void 0;
|
|
371
|
+
const { stream, filename, contentType } = await this.exportService.createExportStream({
|
|
372
|
+
reportId,
|
|
373
|
+
format,
|
|
374
|
+
overrides: parseOverridesParam(payload.overrides),
|
|
375
|
+
...columns ? { columns } : {},
|
|
376
|
+
...maxRows !== void 0 && Number.isFinite(maxRows) ? { maxRows } : {},
|
|
377
|
+
userContext: (0, import_ElasticReportService.extractServerUserContext)(ctx)
|
|
378
|
+
});
|
|
379
|
+
ctx.withoutDataWrapping = true;
|
|
380
|
+
ctx.status = 200;
|
|
381
|
+
ctx.type = contentType;
|
|
382
|
+
ctx.set("Content-Disposition", `attachment; filename="${filename}"`);
|
|
383
|
+
ctx.body = stream;
|
|
384
|
+
} catch (error) {
|
|
385
|
+
const status = (error == null ? void 0 : error.status) ?? 400;
|
|
386
|
+
ctx.throw(status, error instanceof Error ? error.message : String(error));
|
|
387
|
+
}
|
|
388
|
+
await next();
|
|
389
|
+
},
|
|
390
|
+
getMcpInfo: async (ctx, next) => {
|
|
391
|
+
ctx.body = {
|
|
392
|
+
serverName: import_constants.MCP_SERVER_NAME,
|
|
393
|
+
endpointPath: this.getMcpEndpointPath(),
|
|
394
|
+
internalUrl: this.resolveInternalMcpUrl(),
|
|
395
|
+
useUserContext: true,
|
|
396
|
+
tools: this.mcpServer.getToolsMetadata()
|
|
397
|
+
};
|
|
398
|
+
await next();
|
|
399
|
+
}
|
|
400
|
+
}
|
|
401
|
+
});
|
|
402
|
+
}
|
|
403
|
+
registerMcpEndpoint() {
|
|
404
|
+
const mcpActionHandler = async (ctx) => {
|
|
405
|
+
await this.mcpServer.handleRequest(ctx);
|
|
406
|
+
};
|
|
407
|
+
this.app.resourceManager.define({
|
|
408
|
+
name: import_constants.MCP_RESOURCE_NAME,
|
|
409
|
+
actions: {
|
|
410
|
+
list: mcpActionHandler,
|
|
411
|
+
create: mcpActionHandler
|
|
412
|
+
},
|
|
413
|
+
only: ["list", "create"]
|
|
414
|
+
});
|
|
415
|
+
}
|
|
416
|
+
registerAclRules() {
|
|
417
|
+
this.app.acl.allow(
|
|
418
|
+
import_constants.SERVICE_RESOURCE,
|
|
419
|
+
["listPublishedReports", "getReportMeta", "runReport", "inspectTopValues", "exportReport"],
|
|
420
|
+
"loggedIn"
|
|
421
|
+
);
|
|
422
|
+
this.app.acl.allow(import_constants.MCP_RESOURCE_NAME, "*", "loggedIn");
|
|
423
|
+
this.app.acl.registerSnippet({
|
|
424
|
+
name: import_constants.ACL_SNIPPET,
|
|
425
|
+
actions: [
|
|
426
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:list`,
|
|
427
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:get`,
|
|
428
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:create`,
|
|
429
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:update`,
|
|
430
|
+
`${import_constants.DATA_VIEWS_COLLECTION}:destroy`,
|
|
431
|
+
`${import_constants.REPORTS_COLLECTION}:list`,
|
|
432
|
+
`${import_constants.REPORTS_COLLECTION}:get`,
|
|
433
|
+
`${import_constants.REPORTS_COLLECTION}:create`,
|
|
434
|
+
`${import_constants.REPORTS_COLLECTION}:update`,
|
|
435
|
+
`${import_constants.REPORTS_COLLECTION}:destroy`,
|
|
436
|
+
`${import_constants.SERVICE_RESOURCE}:*`
|
|
437
|
+
]
|
|
438
|
+
});
|
|
439
|
+
}
|
|
440
|
+
registerAITools() {
|
|
441
|
+
var _a, _b, _c;
|
|
442
|
+
const toolsManager = (_a = this.app.aiManager) == null ? void 0 : _a.toolsManager;
|
|
443
|
+
if (!toolsManager) {
|
|
444
|
+
(_c = (_b = this.app.logger) == null ? void 0 : _b.info) == null ? void 0 : _c.call(
|
|
445
|
+
_b,
|
|
446
|
+
"[plugin-elastic-report] aiManager.toolsManager is not present; skipping direct AI tool registration"
|
|
447
|
+
);
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
toolsManager.registerTools(
|
|
451
|
+
this.toolsCatalog.map((tool) => ({
|
|
452
|
+
scope: "CUSTOM",
|
|
453
|
+
defaultPermission: tool.defaultPermission,
|
|
454
|
+
execution: "backend",
|
|
455
|
+
introduction: {
|
|
456
|
+
title: tool.title,
|
|
457
|
+
about: tool.description
|
|
458
|
+
},
|
|
459
|
+
definition: {
|
|
460
|
+
name: `${import_constants.MCP_SERVER_NAME}-${tool.name}`,
|
|
461
|
+
description: tool.description,
|
|
462
|
+
schema: tool.inputSchema
|
|
463
|
+
},
|
|
464
|
+
invoke: async (ctx, args) => {
|
|
465
|
+
return tool.execute(isRecord(args) ? args : {}, ctx);
|
|
466
|
+
}
|
|
467
|
+
}))
|
|
468
|
+
);
|
|
469
|
+
}
|
|
470
|
+
async registerPluginMcpClientEntry() {
|
|
471
|
+
var _a, _b, _c;
|
|
472
|
+
const mcpManager = (_a = this.app.aiManager) == null ? void 0 : _a.mcpManager;
|
|
473
|
+
if (!mcpManager || typeof mcpManager.registerMCP !== "function") {
|
|
474
|
+
return;
|
|
475
|
+
}
|
|
476
|
+
try {
|
|
477
|
+
await mcpManager.registerMCP({
|
|
478
|
+
[import_constants.MCP_SERVER_NAME]: {
|
|
479
|
+
title: "Elastic Report MCP",
|
|
480
|
+
description: "Dedicated MCP server for Kibana-style Elasticsearch reports and Data Views",
|
|
481
|
+
transport: "http",
|
|
482
|
+
url: this.resolveInternalMcpUrl(),
|
|
483
|
+
headers: {
|
|
484
|
+
Authorization: "Bearer {{ctx.request.token}}",
|
|
485
|
+
"X-Role": "{{ctx.request.headers.x-role}}"
|
|
486
|
+
},
|
|
487
|
+
useUserContext: true,
|
|
488
|
+
enabled: true
|
|
489
|
+
}
|
|
490
|
+
});
|
|
491
|
+
} catch (error) {
|
|
492
|
+
(_c = (_b = this.app.logger) == null ? void 0 : _b.warn) == null ? void 0 : _c.call(_b, "[plugin-elastic-report] Could not pre-register MCP client entry:", error);
|
|
493
|
+
}
|
|
494
|
+
}
|
|
495
|
+
async ensureCollectionSchema(collectionName) {
|
|
496
|
+
const collection = this.db.getCollection(collectionName);
|
|
497
|
+
if (!collection) return;
|
|
498
|
+
const queryInterface = this.db.sequelize.getQueryInterface();
|
|
499
|
+
const tableName = collection.getTableNameWithSchema();
|
|
500
|
+
let columns = null;
|
|
501
|
+
try {
|
|
502
|
+
columns = await queryInterface.describeTable(tableName);
|
|
503
|
+
} catch {
|
|
504
|
+
await collection.model.sync();
|
|
505
|
+
columns = await queryInterface.describeTable(tableName);
|
|
506
|
+
}
|
|
507
|
+
const attributes = collection.model.rawAttributes;
|
|
508
|
+
for (const [attributeName, attribute] of Object.entries(attributes)) {
|
|
509
|
+
const columnName = attribute.field || attributeName;
|
|
510
|
+
if (columns && columnName in columns) {
|
|
511
|
+
continue;
|
|
512
|
+
}
|
|
513
|
+
const columnDefinition = { ...attribute };
|
|
514
|
+
delete columnDefinition.Model;
|
|
515
|
+
delete columnDefinition.fieldName;
|
|
516
|
+
await queryInterface.addColumn(tableName, columnName, columnDefinition);
|
|
517
|
+
}
|
|
518
|
+
}
|
|
519
|
+
async ensureSchema() {
|
|
520
|
+
for (const collectionName of this.schemaCollections) {
|
|
521
|
+
await this.ensureCollectionSchema(collectionName);
|
|
522
|
+
}
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
var plugin_default = PluginElasticReportServer;
|
|
526
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
527
|
+
0 && (module.exports = {
|
|
528
|
+
PluginElasticReportServer
|
|
529
|
+
});
|