plugin-elastic-report 0.1.1 → 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.
Files changed (60) hide show
  1. package/ai/skills/elastic-report/SKILLS.md +5 -3
  2. package/dist/client/357.0dd385384cab5dbf.js +10 -0
  3. package/dist/client/index.js +1 -1
  4. package/dist/client-v2/851.142c93fc6d666b28.js +10 -0
  5. package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
  6. package/dist/client-v2/877.f4095a3dbcadf98f.js +10 -0
  7. package/dist/client-v2/index.js +1 -1
  8. package/dist/externalVersion.js +3 -2
  9. package/dist/locale/en-US.json +100 -1
  10. package/dist/locale/vi-VN.json +100 -1
  11. package/dist/locale/zh-CN.json +100 -1
  12. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
  13. package/dist/server/acl-guard.js +97 -25
  14. package/dist/server/collections/es-report-data-views.js +6 -0
  15. package/dist/server/collections/es-reports.js +6 -0
  16. package/dist/server/mcp/ElasticReportToolCatalog.js +232 -10
  17. package/dist/server/plugin.js +153 -19
  18. package/dist/server/services/ElasticReportService.js +125 -11
  19. package/dist/server/services/ElasticsearchConnectionService.js +274 -34
  20. package/dist/server/services/ReportExportService.js +243 -0
  21. package/dist/server/services/ReportQueryCompiler.js +532 -91
  22. package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
  23. package/dist/shared/constants.js +17 -2
  24. package/package.json +3 -2
  25. package/src/client/index.tsx +16 -1
  26. package/src/client/workflow-instructions.tsx +44 -0
  27. package/src/client-v2/__tests__/elastic-report.test.tsx +519 -39
  28. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
  29. package/src/client-v2/api.ts +96 -0
  30. package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
  31. package/src/client-v2/components/ElasticBasicCharts.tsx +345 -92
  32. package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
  33. package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
  34. package/src/client-v2/components/ElasticReportBlock.tsx +157 -11
  35. package/src/client-v2/components/ElasticReportRenderer.tsx +621 -71
  36. package/src/client-v2/components/ReportSelect.tsx +39 -26
  37. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
  38. package/src/client-v2/models/ElasticReportBlockModel.tsx +36 -3
  39. package/src/client-v2/pages/ElasticReportManager.tsx +432 -26
  40. package/src/client-v2/plugin.tsx +20 -0
  41. package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
  42. package/src/client-v2/workflow/instructions.tsx +149 -0
  43. package/src/locale/en-US.json +100 -1
  44. package/src/locale/vi-VN.json +100 -1
  45. package/src/locale/zh-CN.json +100 -1
  46. package/src/server/__tests__/query-compiler.test.ts +390 -1
  47. package/src/server/__tests__/report-mcp-acl.integration.test.ts +271 -3
  48. package/src/server/acl-guard.ts +119 -28
  49. package/src/server/collections/es-report-data-views.ts +6 -0
  50. package/src/server/collections/es-reports.ts +6 -0
  51. package/src/server/mcp/ElasticReportToolCatalog.ts +255 -9
  52. package/src/server/plugin.ts +189 -21
  53. package/src/server/services/ElasticReportService.ts +165 -5
  54. package/src/server/services/ElasticsearchConnectionService.ts +375 -48
  55. package/src/server/services/ReportExportService.ts +282 -0
  56. package/src/server/services/ReportQueryCompiler.ts +629 -94
  57. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
  58. package/src/shared/constants.ts +7 -0
  59. package/src/shared/types.ts +98 -1
  60. package/dist/client-v2/851.488fdbf5bc5b6a36.js +0 -10
@@ -0,0 +1,123 @@
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 ElasticReportQueryInstruction_exports = {};
28
+ __export(ElasticReportQueryInstruction_exports, {
29
+ ElasticReportQueryInstruction: () => ElasticReportQueryInstruction,
30
+ evaluateThreshold: () => evaluateThreshold
31
+ });
32
+ module.exports = __toCommonJS(ElasticReportQueryInstruction_exports);
33
+ var import_plugin_workflow = require("@nocobase/plugin-workflow");
34
+ function evaluateThreshold(actual, operator, threshold) {
35
+ if (actual === null || actual === void 0 || !Number.isFinite(actual)) return false;
36
+ if (!operator || threshold === void 0 || !Number.isFinite(threshold)) return false;
37
+ switch (operator) {
38
+ case "gt":
39
+ return actual > threshold;
40
+ case "gte":
41
+ return actual >= threshold;
42
+ case "lt":
43
+ return actual < threshold;
44
+ case "lte":
45
+ return actual <= threshold;
46
+ case "eq":
47
+ return actual === threshold;
48
+ case "ne":
49
+ return actual !== threshold;
50
+ default:
51
+ return false;
52
+ }
53
+ }
54
+ class ElasticReportQueryInstruction extends import_plugin_workflow.Instruction {
55
+ constructor(workflow, reportService) {
56
+ super(workflow);
57
+ this.reportService = reportService;
58
+ }
59
+ async run(node, _input, processor) {
60
+ const rawConfig = node.config ?? {};
61
+ const parsedConfig = processor.getParsedValue(rawConfig, node.id);
62
+ const reportId = parsedConfig == null ? void 0 : parsedConfig.reportId;
63
+ if (reportId === void 0 || reportId === null || String(reportId).trim() === "") {
64
+ return {
65
+ status: import_plugin_workflow.JOB_STATUS.ERROR,
66
+ result: {
67
+ error: "reportId is required in Elastic Report workflow node configuration"
68
+ }
69
+ };
70
+ }
71
+ try {
72
+ const overrides = {};
73
+ if (typeof parsedConfig.queryOverride === "string" && parsedConfig.queryOverride.trim()) {
74
+ overrides.query = parsedConfig.queryOverride.trim();
75
+ }
76
+ if (typeof parsedConfig.timePreset === "string" && parsedConfig.timePreset.trim()) {
77
+ overrides.timeRange = { preset: parsedConfig.timePreset };
78
+ }
79
+ const { report, result } = await this.reportService.runSavedReport({
80
+ reportId,
81
+ overrides: Object.keys(overrides).length > 0 ? overrides : void 0,
82
+ requirePublished: false,
83
+ forMcp: true
84
+ });
85
+ const targetField = parsedConfig.thresholdField ?? "total";
86
+ const comparedValue = targetField === "metricValue" ? result.metricValue ?? result.total : targetField === "deltaPercent" ? result.deltaPercent ?? null : result.total;
87
+ const breached = evaluateThreshold(
88
+ comparedValue,
89
+ parsedConfig.thresholdOperator,
90
+ typeof parsedConfig.thresholdValue === "number" ? parsedConfig.thresholdValue : parsedConfig.thresholdValue !== void 0 ? Number(parsedConfig.thresholdValue) : void 0
91
+ );
92
+ return {
93
+ status: import_plugin_workflow.JOB_STATUS.RESOLVED,
94
+ result: {
95
+ reportId: report.id,
96
+ title: report.title,
97
+ visualization: report.visualization,
98
+ total: result.total,
99
+ totalRelation: result.totalRelation,
100
+ metricValue: result.metricValue ?? result.total,
101
+ previousMetricValue: result.previousMetricValue ?? null,
102
+ deltaPercent: result.deltaPercent ?? null,
103
+ breached,
104
+ topBuckets: result.series.slice(0, 10),
105
+ sampleRows: result.rows.slice(0, 10).map((r) => r.source),
106
+ executedAt: (/* @__PURE__ */ new Date()).toISOString()
107
+ }
108
+ };
109
+ } catch (error) {
110
+ return {
111
+ status: import_plugin_workflow.JOB_STATUS.ERROR,
112
+ result: {
113
+ error: error instanceof Error ? error.message : String(error)
114
+ }
115
+ };
116
+ }
117
+ }
118
+ }
119
+ // Annotate the CommonJS export names for ESM import in node:
120
+ 0 && (module.exports = {
121
+ ElasticReportQueryInstruction,
122
+ evaluateThreshold
123
+ });
@@ -28,11 +28,14 @@ var constants_exports = {};
28
28
  __export(constants_exports, {
29
29
  ACL_SNIPPET: () => ACL_SNIPPET,
30
30
  DATA_VIEWS_COLLECTION: () => DATA_VIEWS_COLLECTION,
31
+ DEFAULT_MAX_EXPORT_ROWS: () => DEFAULT_MAX_EXPORT_ROWS,
31
32
  DEFAULT_PAGE_SIZE: () => DEFAULT_PAGE_SIZE,
33
+ EXPORT_BATCH_SIZE: () => EXPORT_BATCH_SIZE,
32
34
  HIGHLIGHT_POST_TAG: () => HIGHLIGHT_POST_TAG,
33
35
  HIGHLIGHT_PRE_TAG: () => HIGHLIGHT_PRE_TAG,
34
36
  MAX_MCP_PREVIEW_SIZE: () => MAX_MCP_PREVIEW_SIZE,
35
37
  MAX_RESULT_WINDOW: () => MAX_RESULT_WINDOW,
38
+ MAX_SPLIT_SERIES: () => MAX_SPLIT_SERIES,
36
39
  MAX_TERMS_BUCKETS: () => MAX_TERMS_BUCKETS,
37
40
  MAX_UI_PAGE_SIZE: () => MAX_UI_PAGE_SIZE,
38
41
  MCP_RELATIVE_PATH: () => MCP_RELATIVE_PATH,
@@ -41,7 +44,9 @@ __export(constants_exports, {
41
44
  PLUGIN_NAME: () => PLUGIN_NAME,
42
45
  REPORTS_COLLECTION: () => REPORTS_COLLECTION,
43
46
  SERVICE_RESOURCE: () => SERVICE_RESOURCE,
44
- SETTINGS_MENU_KEY: () => SETTINGS_MENU_KEY
47
+ SETTINGS_MENU_KEY: () => SETTINGS_MENU_KEY,
48
+ WORKFLOW_GROUP_KEY: () => WORKFLOW_GROUP_KEY,
49
+ WORKFLOW_INSTRUCTION_TYPE: () => WORKFLOW_INSTRUCTION_TYPE
45
50
  });
46
51
  module.exports = __toCommonJS(constants_exports);
47
52
  const PLUGIN_NAME = "plugin-elastic-report";
@@ -60,15 +65,23 @@ const MAX_UI_PAGE_SIZE = 200;
60
65
  const MAX_MCP_PREVIEW_SIZE = 20;
61
66
  const MAX_RESULT_WINDOW = 1e4;
62
67
  const MAX_TERMS_BUCKETS = 50;
68
+ const MAX_SPLIT_SERIES = 10;
69
+ const DEFAULT_MAX_EXPORT_ROWS = 5e4;
70
+ const EXPORT_BATCH_SIZE = 500;
71
+ const WORKFLOW_GROUP_KEY = "elastic-report";
72
+ const WORKFLOW_INSTRUCTION_TYPE = "elastic-report-query";
63
73
  // Annotate the CommonJS export names for ESM import in node:
64
74
  0 && (module.exports = {
65
75
  ACL_SNIPPET,
66
76
  DATA_VIEWS_COLLECTION,
77
+ DEFAULT_MAX_EXPORT_ROWS,
67
78
  DEFAULT_PAGE_SIZE,
79
+ EXPORT_BATCH_SIZE,
68
80
  HIGHLIGHT_POST_TAG,
69
81
  HIGHLIGHT_PRE_TAG,
70
82
  MAX_MCP_PREVIEW_SIZE,
71
83
  MAX_RESULT_WINDOW,
84
+ MAX_SPLIT_SERIES,
72
85
  MAX_TERMS_BUCKETS,
73
86
  MAX_UI_PAGE_SIZE,
74
87
  MCP_RELATIVE_PATH,
@@ -77,5 +90,7 @@ const MAX_TERMS_BUCKETS = 50;
77
90
  PLUGIN_NAME,
78
91
  REPORTS_COLLECTION,
79
92
  SERVICE_RESOURCE,
80
- SETTINGS_MENU_KEY
93
+ SETTINGS_MENU_KEY,
94
+ WORKFLOW_GROUP_KEY,
95
+ WORKFLOW_INSTRUCTION_TYPE
81
96
  });
package/package.json CHANGED
@@ -6,7 +6,7 @@
6
6
  "description": "Kibana-style Elasticsearch Discover & Visualization reports with reusable blocks and a dedicated MCP server for AI Employees.",
7
7
  "description.vi-VN": "Tạo báo cáo bảng và biểu đồ từ dữ liệu Elasticsearch theo phong cách Kibana, gắn dưới dạng Block và cung cấp MCP riêng cho AI Employee.",
8
8
  "description.zh-CN": "连接 Elasticsearch 构建类 Kibana 的检索、筛选、排序与基础图表报表区块,并提供专属 MCP 服务供 AI 员工调用。",
9
- "version": "0.1.1",
9
+ "version": "0.7.0",
10
10
  "license": "Apache-2.0",
11
11
  "main": "dist/server/index.js",
12
12
  "keywords": [
@@ -48,6 +48,7 @@
48
48
  "@nocobase/flow-engine": "2.x",
49
49
  "@nocobase/plugin-ai": "2.x",
50
50
  "@nocobase/plugin-data-source-manager": "2.x",
51
+ "@nocobase/plugin-workflow": "2.x",
51
52
  "@nocobase/server": "2.x"
52
53
  },
53
54
  "repository": {
@@ -55,7 +56,7 @@
55
56
  "url": "git+https://github.com/OrgGem/nocobase-beta.git",
56
57
  "directory": "packages/plugins/plugin-elastic-report"
57
58
  },
58
- "gitHead": "321fce51621d4b8d6b5995e448fc66ce4cb67f58",
59
+ "gitHead": "3680e22db0068952760bb3b869a054cef57a6d77",
59
60
  "publishConfig": {
60
61
  "access": "public",
61
62
  "registry": "https://registry.npmjs.org/"
@@ -8,11 +8,26 @@
8
8
  */
9
9
 
10
10
  import { Plugin } from '@nocobase/client';
11
+ import { ElasticFilterBarBlockModel } from '../client-v2/models/ElasticFilterBarBlockModel';
11
12
  import { ElasticReportBlockModel } from '../client-v2/models/ElasticReportBlockModel';
13
+ import type { WorkflowClientRegistry } from '../client-v2/workflow/instructions';
12
14
 
13
15
  export class PluginElasticReportLegacyClient extends Plugin {
14
16
  async load() {
15
- this.flowEngine?.registerModels?.({ ElasticReportBlockModel });
17
+ this.flowEngine?.registerModels?.({
18
+ ElasticReportBlockModel,
19
+ ElasticFilterBarBlockModel,
20
+ });
21
+
22
+ const workflow = (
23
+ this.app as unknown as {
24
+ pm?: { get?: (name: string) => WorkflowClientRegistry | undefined };
25
+ }
26
+ ).pm?.get?.('workflow');
27
+ if (workflow && typeof workflow.registerInstruction === 'function') {
28
+ const { registerLegacyWorkflowInstructions } = await import('./workflow-instructions');
29
+ registerLegacyWorkflowInstructions(workflow);
30
+ }
16
31
  }
17
32
  }
18
33
 
@@ -0,0 +1,44 @@
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 { BarChartOutlined } from '@ant-design/icons';
11
+ import { Instruction, type VariableOption } from '@nocobase/plugin-workflow/client';
12
+ import React from 'react';
13
+ import {
14
+ ElasticReportQueryFieldset,
15
+ buildElasticReportWorkflowVariables,
16
+ type WorkflowClientRegistry,
17
+ } from '../client-v2/workflow/instructions';
18
+ import { tExpr } from '../client-v2/locale';
19
+ import { WORKFLOW_GROUP_KEY, WORKFLOW_INSTRUCTION_TYPE } from '../shared/constants';
20
+
21
+ export function registerLegacyWorkflowInstructions(workflow: WorkflowClientRegistry): void {
22
+ workflow.registerInstructionGroup(WORKFLOW_GROUP_KEY, {
23
+ key: WORKFLOW_GROUP_KEY,
24
+ label: tExpr('Elastic Report'),
25
+ });
26
+
27
+ workflow.registerInstruction(
28
+ WORKFLOW_INSTRUCTION_TYPE,
29
+ class extends Instruction {
30
+ type = WORKFLOW_INSTRUCTION_TYPE;
31
+ title = tExpr('Query Elasticsearch Report');
32
+ description = tExpr(
33
+ 'Execute a Saved Elasticsearch Report and evaluate threshold conditions for scheduled alerts or reports.',
34
+ );
35
+ group = WORKFLOW_GROUP_KEY;
36
+ icon = (<BarChartOutlined />);
37
+ FieldsetLoader = async () => ({ default: ElasticReportQueryFieldset });
38
+
39
+ useVariables(node: { key: string; title: string }): VariableOption {
40
+ return buildElasticReportWorkflowVariables(node);
41
+ }
42
+ },
43
+ );
44
+ }