plugin-elastic-report 0.7.0 → 0.9.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 (70) hide show
  1. package/client-v2.d.ts +2 -2
  2. package/client-v2.js +1 -1
  3. package/client.d.ts +2 -2
  4. package/client.js +1 -1
  5. package/{ai → dist/ai}/skills/elastic-report/SKILLS.md +52 -34
  6. package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
  7. package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
  8. package/dist/client-v2/index.js +1 -1
  9. package/dist/externalVersion.js +2 -1
  10. package/dist/locale/en-US.json +213 -198
  11. package/dist/locale/vi-VN.json +213 -198
  12. package/dist/locale/zh-CN.json +213 -198
  13. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
  14. package/dist/server/mcp/ElasticReportToolCatalog.js +6 -4
  15. package/dist/server/plugin.js +4 -4
  16. package/dist/server/report-block-tools.js +340 -0
  17. package/dist/server/services/ElasticReportService.js +12 -6
  18. package/dist/shared/constants.js +9 -0
  19. package/package.json +2 -3
  20. package/server.d.ts +2 -2
  21. package/server.js +1 -1
  22. package/src/ai/skills/elastic-report/SKILLS.md +52 -0
  23. package/src/client/index.tsx +34 -34
  24. package/src/client/workflow-instructions.tsx +44 -44
  25. package/src/client-v2/__tests__/elastic-report.test.tsx +879 -791
  26. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -178
  27. package/src/client-v2/api.ts +320 -320
  28. package/src/client-v2/bus/DashboardFilterBus.ts +212 -212
  29. package/src/client-v2/components/ElasticBasicCharts.tsx +652 -652
  30. package/src/client-v2/components/ElasticFilterBar.tsx +372 -372
  31. package/src/client-v2/components/ElasticKqlInput.tsx +421 -421
  32. package/src/client-v2/components/ElasticReportBlock.tsx +306 -306
  33. package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -1257
  34. package/src/client-v2/components/HighlightText.tsx +50 -50
  35. package/src/client-v2/components/ReportSelect.tsx +85 -85
  36. package/src/client-v2/index.tsx +14 -14
  37. package/src/client-v2/locale.ts +23 -23
  38. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -115
  39. package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -118
  40. package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1453
  41. package/src/client-v2/plugin.tsx +107 -72
  42. package/src/client-v2/report-destination.tsx +126 -0
  43. package/src/client-v2/utils/kqlAutocomplete.ts +861 -861
  44. package/src/client-v2/workflow/instructions.tsx +149 -149
  45. package/src/index.ts +11 -11
  46. package/src/locale/en-US.json +213 -198
  47. package/src/locale/vi-VN.json +213 -198
  48. package/src/locale/zh-CN.json +213 -198
  49. package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
  50. package/src/server/__tests__/query-compiler.test.ts +620 -620
  51. package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -645
  52. package/src/server/acl-guard.ts +194 -194
  53. package/src/server/collections/es-report-data-views.ts +64 -64
  54. package/src/server/collections/es-reports.ts +80 -80
  55. package/src/server/index.ts +15 -15
  56. package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
  57. package/src/server/mcp/ElasticReportToolCatalog.ts +667 -663
  58. package/src/server/plugin.ts +599 -599
  59. package/src/server/report-block-tools.ts +400 -0
  60. package/src/server/services/ElasticReportService.ts +494 -486
  61. package/src/server/services/ElasticsearchConnectionService.ts +728 -728
  62. package/src/server/services/ReportExportService.ts +282 -282
  63. package/src/server/services/ReportQueryCompiler.ts +1552 -1552
  64. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -124
  65. package/src/shared/constants.ts +39 -36
  66. package/src/shared/types.ts +272 -272
  67. package/dist/client-v2/851.142c93fc6d666b28.js +0 -10
  68. package/dist/client-v2/877.f4095a3dbcadf98f.js +0 -10
  69. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +0 -15
  70. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +0 -7
@@ -1,149 +1,149 @@
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 {
12
- Instruction,
13
- NodeDefaultView,
14
- type FlowNodeModel,
15
- type VariableOption,
16
- } from '@nocobase/plugin-workflow/client-v2';
17
- import { Form, Input, InputNumber, Select, Space, Tag } from 'antd';
18
- import React from 'react';
19
- import { WORKFLOW_GROUP_KEY, WORKFLOW_INSTRUCTION_TYPE } from '../../shared/constants';
20
- import type { ElasticWorkflowNodeConfig } from '../../shared/types';
21
- import { ReportSelect } from '../components/ReportSelect';
22
- import { tExpr, useT } from '../locale';
23
-
24
- export interface WorkflowClientRegistry {
25
- registerInstructionGroup(key: string, group: { key: string; label: string }): void;
26
- registerInstruction(type: string, instruction: { new (): Instruction }): void;
27
- }
28
-
29
- export function buildElasticReportWorkflowVariables(node: { key: string; title: string }): VariableOption {
30
- return {
31
- value: node.key,
32
- label: node.title,
33
- children: [
34
- { value: 'total', label: tExpr('Total Hits') },
35
- { value: 'metricValue', label: tExpr('Metric Value') },
36
- { value: 'deltaPercent', label: tExpr('Delta (%)') },
37
- { value: 'breached', label: tExpr('Threshold Breached') },
38
- { value: 'topBuckets', label: tExpr('Top Buckets') },
39
- { value: 'sampleRows', label: tExpr('Sample Rows') },
40
- { value: 'executedAt', label: tExpr('Executed At') },
41
- ],
42
- };
43
- }
44
-
45
- export function ElasticReportQueryFieldset() {
46
- const t = useT();
47
-
48
- return (
49
- <div>
50
- <Form.Item name={['config', 'reportId']} label={t('Report')} rules={[{ required: true }]}>
51
- <ReportSelect />
52
- </Form.Item>
53
- <Form.Item name={['config', 'queryOverride']} label={t('KQL / Search Query')}>
54
- <Input placeholder={t('Search KQL, e.g. status >= 500 AND service: "api"')} />
55
- </Form.Item>
56
- <Form.Item name={['config', 'timePreset']} label={t('Time Field')}>
57
- <Select
58
- allowClear
59
- placeholder={t('Auto')}
60
- options={[
61
- { label: t('Last 15 minutes'), value: 'last_15m' },
62
- { label: t('Last 1 hour'), value: 'last_1h' },
63
- { label: t('Last 24 hours'), value: 'last_24h' },
64
- { label: t('Last 7 days'), value: 'last_7d' },
65
- { label: t('Last 30 days'), value: 'last_30d' },
66
- { label: t('Last 90 days'), value: 'last_90d' },
67
- { label: t('All time'), value: 'all' },
68
- ]}
69
- />
70
- </Form.Item>
71
- <Form.Item name={['config', 'thresholdField']} label={t('Threshold Metric')}>
72
- <Select
73
- allowClear
74
- options={[
75
- { label: t('Total Hits'), value: 'total' },
76
- { label: t('Metric Value'), value: 'metricValue' },
77
- { label: t('Delta (%)'), value: 'deltaPercent' },
78
- ]}
79
- />
80
- </Form.Item>
81
- <Form.Item name={['config', 'thresholdOperator']} label={t('Threshold Operator')}>
82
- <Select
83
- allowClear
84
- options={[
85
- { label: '>', value: 'gt' },
86
- { label: '>=', value: 'gte' },
87
- { label: '<', value: 'lt' },
88
- { label: '<=', value: 'lte' },
89
- { label: '=', value: 'eq' },
90
- { label: '!=', value: 'ne' },
91
- ]}
92
- />
93
- </Form.Item>
94
- <Form.Item name={['config', 'thresholdValue']} label={t('Threshold Value')}>
95
- <InputNumber style={{ width: '100%' }} />
96
- </Form.Item>
97
- </div>
98
- );
99
- }
100
-
101
- function ElasticReportQueryNodeCard({ data }: { data: FlowNodeModel }) {
102
- const t = useT();
103
- const cfg = (data?.config ?? {}) as ElasticWorkflowNodeConfig;
104
- return (
105
- <NodeDefaultView
106
- data={data}
107
- cardExtra={
108
- cfg.reportId !== undefined ? (
109
- <Space size={[4, 4]} wrap style={{ marginTop: 4 }}>
110
- <Tag color="blue" style={{ marginInlineEnd: 0 }}>
111
- {t('Report')} #{String(cfg.reportId)}
112
- </Tag>
113
- {cfg.thresholdOperator && cfg.thresholdValue !== undefined && (
114
- <Tag color="gold" style={{ marginInlineEnd: 0 }}>
115
- {cfg.thresholdField || 'total'} {cfg.thresholdOperator} {cfg.thresholdValue}
116
- </Tag>
117
- )}
118
- </Space>
119
- ) : null
120
- }
121
- />
122
- );
123
- }
124
-
125
- export function registerElasticReportWorkflowInstructions(workflow: WorkflowClientRegistry): void {
126
- workflow.registerInstructionGroup(WORKFLOW_GROUP_KEY, {
127
- key: WORKFLOW_GROUP_KEY,
128
- label: tExpr('Elastic Report'),
129
- });
130
-
131
- workflow.registerInstruction(
132
- WORKFLOW_INSTRUCTION_TYPE,
133
- class extends Instruction {
134
- type = WORKFLOW_INSTRUCTION_TYPE;
135
- title = tExpr('Query Elasticsearch Report');
136
- description = tExpr(
137
- 'Execute a Saved Elasticsearch Report and evaluate threshold conditions for scheduled alerts or reports.',
138
- );
139
- group = WORKFLOW_GROUP_KEY;
140
- icon = (<BarChartOutlined />);
141
- ComponentLoader = async () => ({ default: ElasticReportQueryNodeCard });
142
- FieldsetLoader = async () => ({ default: ElasticReportQueryFieldset });
143
-
144
- useVariables(node: { key: string; title: string }): VariableOption {
145
- return buildElasticReportWorkflowVariables(node);
146
- }
147
- },
148
- );
149
- }
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 {
12
+ Instruction,
13
+ NodeDefaultView,
14
+ type FlowNodeModel,
15
+ type VariableOption,
16
+ } from '@nocobase/plugin-workflow/client-v2';
17
+ import { Form, Input, InputNumber, Select, Space, Tag } from 'antd';
18
+ import React from 'react';
19
+ import { WORKFLOW_GROUP_KEY, WORKFLOW_INSTRUCTION_TYPE } from '../../shared/constants';
20
+ import type { ElasticWorkflowNodeConfig } from '../../shared/types';
21
+ import { ReportSelect } from '../components/ReportSelect';
22
+ import { tExpr, useT } from '../locale';
23
+
24
+ export interface WorkflowClientRegistry {
25
+ registerInstructionGroup(key: string, group: { key: string; label: string }): void;
26
+ registerInstruction(type: string, instruction: { new (): Instruction }): void;
27
+ }
28
+
29
+ export function buildElasticReportWorkflowVariables(node: { key: string; title: string }): VariableOption {
30
+ return {
31
+ value: node.key,
32
+ label: node.title,
33
+ children: [
34
+ { value: 'total', label: tExpr('Total Hits') },
35
+ { value: 'metricValue', label: tExpr('Metric Value') },
36
+ { value: 'deltaPercent', label: tExpr('Delta (%)') },
37
+ { value: 'breached', label: tExpr('Threshold Breached') },
38
+ { value: 'topBuckets', label: tExpr('Top Buckets') },
39
+ { value: 'sampleRows', label: tExpr('Sample Rows') },
40
+ { value: 'executedAt', label: tExpr('Executed At') },
41
+ ],
42
+ };
43
+ }
44
+
45
+ export function ElasticReportQueryFieldset() {
46
+ const t = useT();
47
+
48
+ return (
49
+ <div>
50
+ <Form.Item name={['config', 'reportId']} label={t('Report')} rules={[{ required: true }]}>
51
+ <ReportSelect />
52
+ </Form.Item>
53
+ <Form.Item name={['config', 'queryOverride']} label={t('KQL / Search Query')}>
54
+ <Input placeholder={t('Search KQL, e.g. status >= 500 AND service: "api"')} />
55
+ </Form.Item>
56
+ <Form.Item name={['config', 'timePreset']} label={t('Time Field')}>
57
+ <Select
58
+ allowClear
59
+ placeholder={t('Auto')}
60
+ options={[
61
+ { label: t('Last 15 minutes'), value: 'last_15m' },
62
+ { label: t('Last 1 hour'), value: 'last_1h' },
63
+ { label: t('Last 24 hours'), value: 'last_24h' },
64
+ { label: t('Last 7 days'), value: 'last_7d' },
65
+ { label: t('Last 30 days'), value: 'last_30d' },
66
+ { label: t('Last 90 days'), value: 'last_90d' },
67
+ { label: t('All time'), value: 'all' },
68
+ ]}
69
+ />
70
+ </Form.Item>
71
+ <Form.Item name={['config', 'thresholdField']} label={t('Threshold Metric')}>
72
+ <Select
73
+ allowClear
74
+ options={[
75
+ { label: t('Total Hits'), value: 'total' },
76
+ { label: t('Metric Value'), value: 'metricValue' },
77
+ { label: t('Delta (%)'), value: 'deltaPercent' },
78
+ ]}
79
+ />
80
+ </Form.Item>
81
+ <Form.Item name={['config', 'thresholdOperator']} label={t('Threshold Operator')}>
82
+ <Select
83
+ allowClear
84
+ options={[
85
+ { label: '>', value: 'gt' },
86
+ { label: '>=', value: 'gte' },
87
+ { label: '<', value: 'lt' },
88
+ { label: '<=', value: 'lte' },
89
+ { label: '=', value: 'eq' },
90
+ { label: '!=', value: 'ne' },
91
+ ]}
92
+ />
93
+ </Form.Item>
94
+ <Form.Item name={['config', 'thresholdValue']} label={t('Threshold Value')}>
95
+ <InputNumber style={{ width: '100%' }} />
96
+ </Form.Item>
97
+ </div>
98
+ );
99
+ }
100
+
101
+ function ElasticReportQueryNodeCard({ data }: { data: FlowNodeModel }) {
102
+ const t = useT();
103
+ const cfg = (data?.config ?? {}) as ElasticWorkflowNodeConfig;
104
+ return (
105
+ <NodeDefaultView
106
+ data={data}
107
+ cardExtra={
108
+ cfg.reportId !== undefined ? (
109
+ <Space size={[4, 4]} wrap style={{ marginTop: 4 }}>
110
+ <Tag color="blue" style={{ marginInlineEnd: 0 }}>
111
+ {t('Report')} #{String(cfg.reportId)}
112
+ </Tag>
113
+ {cfg.thresholdOperator && cfg.thresholdValue !== undefined && (
114
+ <Tag color="gold" style={{ marginInlineEnd: 0 }}>
115
+ {cfg.thresholdField || 'total'} {cfg.thresholdOperator} {cfg.thresholdValue}
116
+ </Tag>
117
+ )}
118
+ </Space>
119
+ ) : null
120
+ }
121
+ />
122
+ );
123
+ }
124
+
125
+ export function registerElasticReportWorkflowInstructions(workflow: WorkflowClientRegistry): void {
126
+ workflow.registerInstructionGroup(WORKFLOW_GROUP_KEY, {
127
+ key: WORKFLOW_GROUP_KEY,
128
+ label: tExpr('Elastic Report'),
129
+ });
130
+
131
+ workflow.registerInstruction(
132
+ WORKFLOW_INSTRUCTION_TYPE,
133
+ class extends Instruction {
134
+ type = WORKFLOW_INSTRUCTION_TYPE;
135
+ title = tExpr('Query Elasticsearch Report');
136
+ description = tExpr(
137
+ 'Execute a Saved Elasticsearch Report and evaluate threshold conditions for scheduled alerts or reports.',
138
+ );
139
+ group = WORKFLOW_GROUP_KEY;
140
+ icon = (<BarChartOutlined />);
141
+ ComponentLoader = async () => ({ default: ElasticReportQueryNodeCard });
142
+ FieldsetLoader = async () => ({ default: ElasticReportQueryFieldset });
143
+
144
+ useVariables(node: { key: string; title: string }): VariableOption {
145
+ return buildElasticReportWorkflowVariables(node);
146
+ }
147
+ },
148
+ );
149
+ }
package/src/index.ts CHANGED
@@ -1,11 +1,11 @@
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
- export { default } from './server';
11
- export * from './server';
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
+ export { default } from './server';
11
+ export * from './server';