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.
- package/client-v2.d.ts +2 -2
- package/client-v2.js +1 -1
- package/client.d.ts +2 -2
- package/client.js +1 -1
- package/{ai → dist/ai}/skills/elastic-report/SKILLS.md +52 -34
- package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
- package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +2 -1
- package/dist/locale/en-US.json +213 -198
- package/dist/locale/vi-VN.json +213 -198
- package/dist/locale/zh-CN.json +213 -198
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
- package/dist/server/mcp/ElasticReportToolCatalog.js +6 -4
- package/dist/server/plugin.js +4 -4
- package/dist/server/report-block-tools.js +340 -0
- package/dist/server/services/ElasticReportService.js +12 -6
- package/dist/shared/constants.js +9 -0
- package/package.json +2 -3
- package/server.d.ts +2 -2
- package/server.js +1 -1
- package/src/ai/skills/elastic-report/SKILLS.md +52 -0
- package/src/client/index.tsx +34 -34
- package/src/client/workflow-instructions.tsx +44 -44
- package/src/client-v2/__tests__/elastic-report.test.tsx +879 -791
- package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -178
- package/src/client-v2/api.ts +320 -320
- package/src/client-v2/bus/DashboardFilterBus.ts +212 -212
- package/src/client-v2/components/ElasticBasicCharts.tsx +652 -652
- package/src/client-v2/components/ElasticFilterBar.tsx +372 -372
- package/src/client-v2/components/ElasticKqlInput.tsx +421 -421
- package/src/client-v2/components/ElasticReportBlock.tsx +306 -306
- package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -1257
- package/src/client-v2/components/HighlightText.tsx +50 -50
- package/src/client-v2/components/ReportSelect.tsx +85 -85
- package/src/client-v2/index.tsx +14 -14
- package/src/client-v2/locale.ts +23 -23
- package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -115
- package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -118
- package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1453
- package/src/client-v2/plugin.tsx +107 -72
- package/src/client-v2/report-destination.tsx +126 -0
- package/src/client-v2/utils/kqlAutocomplete.ts +861 -861
- package/src/client-v2/workflow/instructions.tsx +149 -149
- package/src/index.ts +11 -11
- package/src/locale/en-US.json +213 -198
- package/src/locale/vi-VN.json +213 -198
- package/src/locale/zh-CN.json +213 -198
- package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
- package/src/server/__tests__/query-compiler.test.ts +620 -620
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -645
- package/src/server/acl-guard.ts +194 -194
- package/src/server/collections/es-report-data-views.ts +64 -64
- package/src/server/collections/es-reports.ts +80 -80
- package/src/server/index.ts +15 -15
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
- package/src/server/mcp/ElasticReportToolCatalog.ts +667 -663
- package/src/server/plugin.ts +599 -599
- package/src/server/report-block-tools.ts +400 -0
- package/src/server/services/ElasticReportService.ts +494 -486
- package/src/server/services/ElasticsearchConnectionService.ts +728 -728
- package/src/server/services/ReportExportService.ts +282 -282
- package/src/server/services/ReportQueryCompiler.ts +1552 -1552
- package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -124
- package/src/shared/constants.ts +39 -36
- package/src/shared/types.ts +272 -272
- package/dist/client-v2/851.142c93fc6d666b28.js +0 -10
- package/dist/client-v2/877.f4095a3dbcadf98f.js +0 -10
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +0 -15
- package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +0 -7
|
@@ -1,124 +1,124 @@
|
|
|
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 WorkflowPlugin, { Instruction, JOB_STATUS, type FlowNodeModel, type Processor } from '@nocobase/plugin-workflow';
|
|
11
|
-
import type { ElasticWorkflowNodeConfig, ThresholdOperator, TimeRangePreset } from '../../shared/types';
|
|
12
|
-
import type { ElasticReportService } from '../services/ElasticReportService';
|
|
13
|
-
|
|
14
|
-
export function evaluateThreshold(
|
|
15
|
-
actual: number | null | undefined,
|
|
16
|
-
operator: ThresholdOperator | undefined,
|
|
17
|
-
threshold: number | undefined,
|
|
18
|
-
): boolean {
|
|
19
|
-
if (actual === null || actual === undefined || !Number.isFinite(actual)) return false;
|
|
20
|
-
if (!operator || threshold === undefined || !Number.isFinite(threshold)) return false;
|
|
21
|
-
switch (operator) {
|
|
22
|
-
case 'gt':
|
|
23
|
-
return actual > threshold;
|
|
24
|
-
case 'gte':
|
|
25
|
-
return actual >= threshold;
|
|
26
|
-
case 'lt':
|
|
27
|
-
return actual < threshold;
|
|
28
|
-
case 'lte':
|
|
29
|
-
return actual <= threshold;
|
|
30
|
-
case 'eq':
|
|
31
|
-
return actual === threshold;
|
|
32
|
-
case 'ne':
|
|
33
|
-
return actual !== threshold;
|
|
34
|
-
default:
|
|
35
|
-
return false;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export class ElasticReportQueryInstruction extends Instruction {
|
|
40
|
-
constructor(
|
|
41
|
-
workflow: WorkflowPlugin,
|
|
42
|
-
private readonly reportService: ElasticReportService,
|
|
43
|
-
) {
|
|
44
|
-
super(workflow);
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
async run(node: FlowNodeModel, _input: unknown, processor: Processor) {
|
|
48
|
-
const rawConfig = (node.config ?? {}) as ElasticWorkflowNodeConfig;
|
|
49
|
-
const parsedConfig = processor.getParsedValue(rawConfig, node.id) as ElasticWorkflowNodeConfig;
|
|
50
|
-
const reportId = parsedConfig?.reportId;
|
|
51
|
-
|
|
52
|
-
if (reportId === undefined || reportId === null || String(reportId).trim() === '') {
|
|
53
|
-
return {
|
|
54
|
-
status: JOB_STATUS.ERROR,
|
|
55
|
-
result: {
|
|
56
|
-
error: 'reportId is required in Elastic Report workflow node configuration',
|
|
57
|
-
},
|
|
58
|
-
};
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
try {
|
|
62
|
-
const overrides: {
|
|
63
|
-
query?: string;
|
|
64
|
-
timeRange?: { preset: TimeRangePreset };
|
|
65
|
-
} = {};
|
|
66
|
-
if (typeof parsedConfig.queryOverride === 'string' && parsedConfig.queryOverride.trim()) {
|
|
67
|
-
overrides.query = parsedConfig.queryOverride.trim();
|
|
68
|
-
}
|
|
69
|
-
if (typeof parsedConfig.timePreset === 'string' && parsedConfig.timePreset.trim()) {
|
|
70
|
-
overrides.timeRange = { preset: parsedConfig.timePreset };
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
const { report, result } = await this.reportService.runSavedReport({
|
|
74
|
-
reportId,
|
|
75
|
-
overrides: Object.keys(overrides).length > 0 ? overrides : undefined,
|
|
76
|
-
requirePublished: false,
|
|
77
|
-
forMcp: true,
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
const targetField = parsedConfig.thresholdField ?? 'total';
|
|
81
|
-
const comparedValue =
|
|
82
|
-
targetField === 'metricValue'
|
|
83
|
-
? result.metricValue ?? result.total
|
|
84
|
-
: targetField === 'deltaPercent'
|
|
85
|
-
? result.deltaPercent ?? null
|
|
86
|
-
: result.total;
|
|
87
|
-
|
|
88
|
-
const breached = evaluateThreshold(
|
|
89
|
-
comparedValue,
|
|
90
|
-
parsedConfig.thresholdOperator,
|
|
91
|
-
typeof parsedConfig.thresholdValue === 'number'
|
|
92
|
-
? parsedConfig.thresholdValue
|
|
93
|
-
: parsedConfig.thresholdValue !== undefined
|
|
94
|
-
? Number(parsedConfig.thresholdValue)
|
|
95
|
-
: undefined,
|
|
96
|
-
);
|
|
97
|
-
|
|
98
|
-
return {
|
|
99
|
-
status: JOB_STATUS.RESOLVED,
|
|
100
|
-
result: {
|
|
101
|
-
reportId: report.id,
|
|
102
|
-
title: report.title,
|
|
103
|
-
visualization: report.visualization,
|
|
104
|
-
total: result.total,
|
|
105
|
-
totalRelation: result.totalRelation,
|
|
106
|
-
metricValue: result.metricValue ?? result.total,
|
|
107
|
-
previousMetricValue: result.previousMetricValue ?? null,
|
|
108
|
-
deltaPercent: result.deltaPercent ?? null,
|
|
109
|
-
breached,
|
|
110
|
-
topBuckets: result.series.slice(0, 10),
|
|
111
|
-
sampleRows: result.rows.slice(0, 10).map((r) => r.source),
|
|
112
|
-
executedAt: new Date().toISOString(),
|
|
113
|
-
},
|
|
114
|
-
};
|
|
115
|
-
} catch (error) {
|
|
116
|
-
return {
|
|
117
|
-
status: JOB_STATUS.ERROR,
|
|
118
|
-
result: {
|
|
119
|
-
error: error instanceof Error ? error.message : String(error),
|
|
120
|
-
},
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
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 WorkflowPlugin, { Instruction, JOB_STATUS, type FlowNodeModel, type Processor } from '@nocobase/plugin-workflow';
|
|
11
|
+
import type { ElasticWorkflowNodeConfig, ThresholdOperator, TimeRangePreset } from '../../shared/types';
|
|
12
|
+
import type { ElasticReportService } from '../services/ElasticReportService';
|
|
13
|
+
|
|
14
|
+
export function evaluateThreshold(
|
|
15
|
+
actual: number | null | undefined,
|
|
16
|
+
operator: ThresholdOperator | undefined,
|
|
17
|
+
threshold: number | undefined,
|
|
18
|
+
): boolean {
|
|
19
|
+
if (actual === null || actual === undefined || !Number.isFinite(actual)) return false;
|
|
20
|
+
if (!operator || threshold === undefined || !Number.isFinite(threshold)) return false;
|
|
21
|
+
switch (operator) {
|
|
22
|
+
case 'gt':
|
|
23
|
+
return actual > threshold;
|
|
24
|
+
case 'gte':
|
|
25
|
+
return actual >= threshold;
|
|
26
|
+
case 'lt':
|
|
27
|
+
return actual < threshold;
|
|
28
|
+
case 'lte':
|
|
29
|
+
return actual <= threshold;
|
|
30
|
+
case 'eq':
|
|
31
|
+
return actual === threshold;
|
|
32
|
+
case 'ne':
|
|
33
|
+
return actual !== threshold;
|
|
34
|
+
default:
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export class ElasticReportQueryInstruction extends Instruction {
|
|
40
|
+
constructor(
|
|
41
|
+
workflow: WorkflowPlugin,
|
|
42
|
+
private readonly reportService: ElasticReportService,
|
|
43
|
+
) {
|
|
44
|
+
super(workflow);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async run(node: FlowNodeModel, _input: unknown, processor: Processor) {
|
|
48
|
+
const rawConfig = (node.config ?? {}) as ElasticWorkflowNodeConfig;
|
|
49
|
+
const parsedConfig = processor.getParsedValue(rawConfig, node.id) as ElasticWorkflowNodeConfig;
|
|
50
|
+
const reportId = parsedConfig?.reportId;
|
|
51
|
+
|
|
52
|
+
if (reportId === undefined || reportId === null || String(reportId).trim() === '') {
|
|
53
|
+
return {
|
|
54
|
+
status: JOB_STATUS.ERROR,
|
|
55
|
+
result: {
|
|
56
|
+
error: 'reportId is required in Elastic Report workflow node configuration',
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
try {
|
|
62
|
+
const overrides: {
|
|
63
|
+
query?: string;
|
|
64
|
+
timeRange?: { preset: TimeRangePreset };
|
|
65
|
+
} = {};
|
|
66
|
+
if (typeof parsedConfig.queryOverride === 'string' && parsedConfig.queryOverride.trim()) {
|
|
67
|
+
overrides.query = parsedConfig.queryOverride.trim();
|
|
68
|
+
}
|
|
69
|
+
if (typeof parsedConfig.timePreset === 'string' && parsedConfig.timePreset.trim()) {
|
|
70
|
+
overrides.timeRange = { preset: parsedConfig.timePreset };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
const { report, result } = await this.reportService.runSavedReport({
|
|
74
|
+
reportId,
|
|
75
|
+
overrides: Object.keys(overrides).length > 0 ? overrides : undefined,
|
|
76
|
+
requirePublished: false,
|
|
77
|
+
forMcp: true,
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
const targetField = parsedConfig.thresholdField ?? 'total';
|
|
81
|
+
const comparedValue =
|
|
82
|
+
targetField === 'metricValue'
|
|
83
|
+
? result.metricValue ?? result.total
|
|
84
|
+
: targetField === 'deltaPercent'
|
|
85
|
+
? result.deltaPercent ?? null
|
|
86
|
+
: result.total;
|
|
87
|
+
|
|
88
|
+
const breached = evaluateThreshold(
|
|
89
|
+
comparedValue,
|
|
90
|
+
parsedConfig.thresholdOperator,
|
|
91
|
+
typeof parsedConfig.thresholdValue === 'number'
|
|
92
|
+
? parsedConfig.thresholdValue
|
|
93
|
+
: parsedConfig.thresholdValue !== undefined
|
|
94
|
+
? Number(parsedConfig.thresholdValue)
|
|
95
|
+
: undefined,
|
|
96
|
+
);
|
|
97
|
+
|
|
98
|
+
return {
|
|
99
|
+
status: JOB_STATUS.RESOLVED,
|
|
100
|
+
result: {
|
|
101
|
+
reportId: report.id,
|
|
102
|
+
title: report.title,
|
|
103
|
+
visualization: report.visualization,
|
|
104
|
+
total: result.total,
|
|
105
|
+
totalRelation: result.totalRelation,
|
|
106
|
+
metricValue: result.metricValue ?? result.total,
|
|
107
|
+
previousMetricValue: result.previousMetricValue ?? null,
|
|
108
|
+
deltaPercent: result.deltaPercent ?? null,
|
|
109
|
+
breached,
|
|
110
|
+
topBuckets: result.series.slice(0, 10),
|
|
111
|
+
sampleRows: result.rows.slice(0, 10).map((r) => r.source),
|
|
112
|
+
executedAt: new Date().toISOString(),
|
|
113
|
+
},
|
|
114
|
+
};
|
|
115
|
+
} catch (error) {
|
|
116
|
+
return {
|
|
117
|
+
status: JOB_STATUS.ERROR,
|
|
118
|
+
result: {
|
|
119
|
+
error: error instanceof Error ? error.message : String(error),
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
}
|
package/src/shared/constants.ts
CHANGED
|
@@ -1,36 +1,39 @@
|
|
|
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 const PLUGIN_NAME = 'plugin-elastic-report';
|
|
11
|
-
export const SETTINGS_MENU_KEY = 'elastic-report';
|
|
12
|
-
export const
|
|
13
|
-
|
|
14
|
-
export const
|
|
15
|
-
export const
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
export const
|
|
19
|
-
export const
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
export const
|
|
23
|
-
export const
|
|
24
|
-
|
|
25
|
-
export const
|
|
26
|
-
export const
|
|
27
|
-
|
|
28
|
-
export const
|
|
29
|
-
export const
|
|
30
|
-
export const
|
|
31
|
-
|
|
32
|
-
export const
|
|
33
|
-
export const
|
|
34
|
-
|
|
35
|
-
export const
|
|
36
|
-
export const
|
|
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 const PLUGIN_NAME = 'plugin-elastic-report';
|
|
11
|
+
export const SETTINGS_MENU_KEY = 'elastic-report';
|
|
12
|
+
export const BLOCK_SETTINGS_EVENT = 'elastic-report:block-settings';
|
|
13
|
+
export const BLOCK_ADDED_EVENT = 'elastic-report:block-added';
|
|
14
|
+
export const REPORT_DESTINATION_CONTEXT = 'elastic-report-destination';
|
|
15
|
+
export const ACL_SNIPPET = 'pm.elastic-report';
|
|
16
|
+
|
|
17
|
+
export const DATA_VIEWS_COLLECTION = 'esReportDataViews';
|
|
18
|
+
export const REPORTS_COLLECTION = 'esReports';
|
|
19
|
+
export const SERVICE_RESOURCE = 'esReportService';
|
|
20
|
+
|
|
21
|
+
export const MCP_SERVER_NAME = 'elastic-report';
|
|
22
|
+
export const MCP_RESOURCE_NAME = 'elastic-report-mcp';
|
|
23
|
+
export const MCP_RELATIVE_PATH = '/elastic-report-mcp';
|
|
24
|
+
|
|
25
|
+
export const HIGHLIGHT_PRE_TAG = '__ES_HL_START__';
|
|
26
|
+
export const HIGHLIGHT_POST_TAG = '__ES_HL_END__';
|
|
27
|
+
|
|
28
|
+
export const DEFAULT_PAGE_SIZE = 20;
|
|
29
|
+
export const MAX_UI_PAGE_SIZE = 200;
|
|
30
|
+
export const MAX_MCP_PREVIEW_SIZE = 20;
|
|
31
|
+
export const MAX_RESULT_WINDOW = 10000;
|
|
32
|
+
export const MAX_TERMS_BUCKETS = 50;
|
|
33
|
+
export const MAX_SPLIT_SERIES = 10;
|
|
34
|
+
|
|
35
|
+
export const DEFAULT_MAX_EXPORT_ROWS = 50000;
|
|
36
|
+
export const EXPORT_BATCH_SIZE = 500;
|
|
37
|
+
|
|
38
|
+
export const WORKFLOW_GROUP_KEY = 'elastic-report';
|
|
39
|
+
export const WORKFLOW_INSTRUCTION_TYPE = 'elastic-report-query';
|