plugin-elastic-report 0.1.1 → 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 (80) 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/dist/ai/skills/elastic-report/SKILLS.md +52 -0
  6. package/dist/client/357.0dd385384cab5dbf.js +10 -0
  7. package/dist/client/index.js +1 -1
  8. package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
  9. package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
  10. package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
  11. package/dist/client-v2/index.js +1 -1
  12. package/dist/externalVersion.js +5 -3
  13. package/dist/locale/en-US.json +213 -99
  14. package/dist/locale/vi-VN.json +213 -99
  15. package/dist/locale/zh-CN.json +213 -99
  16. package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
  17. package/dist/server/acl-guard.js +97 -25
  18. package/dist/server/collections/es-report-data-views.js +6 -0
  19. package/dist/server/collections/es-reports.js +6 -0
  20. package/dist/server/mcp/ElasticReportToolCatalog.js +238 -14
  21. package/dist/server/plugin.js +156 -22
  22. package/dist/server/report-block-tools.js +340 -0
  23. package/dist/server/services/ElasticReportService.js +137 -17
  24. package/dist/server/services/ElasticsearchConnectionService.js +274 -34
  25. package/dist/server/services/ReportExportService.js +243 -0
  26. package/dist/server/services/ReportQueryCompiler.js +532 -91
  27. package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
  28. package/dist/shared/constants.js +26 -2
  29. package/package.json +3 -3
  30. package/server.d.ts +2 -2
  31. package/server.js +1 -1
  32. package/src/ai/skills/elastic-report/SKILLS.md +52 -0
  33. package/src/client/index.tsx +34 -19
  34. package/src/client/workflow-instructions.tsx +44 -0
  35. package/src/client-v2/__tests__/elastic-report.test.tsx +879 -311
  36. package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
  37. package/src/client-v2/api.ts +320 -224
  38. package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
  39. package/src/client-v2/components/ElasticBasicCharts.tsx +652 -399
  40. package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
  41. package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
  42. package/src/client-v2/components/ElasticReportBlock.tsx +306 -160
  43. package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -707
  44. package/src/client-v2/components/HighlightText.tsx +50 -50
  45. package/src/client-v2/components/ReportSelect.tsx +85 -72
  46. package/src/client-v2/index.tsx +14 -14
  47. package/src/client-v2/locale.ts +23 -23
  48. package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
  49. package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -85
  50. package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1047
  51. package/src/client-v2/plugin.tsx +107 -52
  52. package/src/client-v2/report-destination.tsx +126 -0
  53. package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
  54. package/src/client-v2/workflow/instructions.tsx +149 -0
  55. package/src/index.ts +11 -11
  56. package/src/locale/en-US.json +213 -99
  57. package/src/locale/vi-VN.json +213 -99
  58. package/src/locale/zh-CN.json +213 -99
  59. package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
  60. package/src/server/__tests__/query-compiler.test.ts +620 -231
  61. package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -377
  62. package/src/server/acl-guard.ts +194 -103
  63. package/src/server/collections/es-report-data-views.ts +64 -58
  64. package/src/server/collections/es-reports.ts +80 -74
  65. package/src/server/index.ts +15 -15
  66. package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
  67. package/src/server/mcp/ElasticReportToolCatalog.ts +667 -417
  68. package/src/server/plugin.ts +599 -431
  69. package/src/server/report-block-tools.ts +400 -0
  70. package/src/server/services/ElasticReportService.ts +494 -326
  71. package/src/server/services/ElasticsearchConnectionService.ts +728 -401
  72. package/src/server/services/ReportExportService.ts +282 -0
  73. package/src/server/services/ReportQueryCompiler.ts +1552 -1017
  74. package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
  75. package/src/shared/constants.ts +39 -29
  76. package/src/shared/types.ts +272 -175
  77. package/ai/skills/elastic-report/SKILLS.md +0 -32
  78. package/dist/client-v2/851.488fdbf5bc5b6a36.js +0 -10
  79. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv +0 -15
  80. package/dist/node_modules/@elastic/elasticsearch/node_modules/.bin/arrow2csv.cmd +0 -7
@@ -0,0 +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,29 +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 ACL_SNIPPET = 'pm.elastic-report';
13
-
14
- export const DATA_VIEWS_COLLECTION = 'esReportDataViews';
15
- export const REPORTS_COLLECTION = 'esReports';
16
- export const SERVICE_RESOURCE = 'esReportService';
17
-
18
- export const MCP_SERVER_NAME = 'elastic-report';
19
- export const MCP_RESOURCE_NAME = 'elastic-report-mcp';
20
- export const MCP_RELATIVE_PATH = '/elastic-report-mcp';
21
-
22
- export const HIGHLIGHT_PRE_TAG = '__ES_HL_START__';
23
- export const HIGHLIGHT_POST_TAG = '__ES_HL_END__';
24
-
25
- export const DEFAULT_PAGE_SIZE = 20;
26
- export const MAX_UI_PAGE_SIZE = 200;
27
- export const MAX_MCP_PREVIEW_SIZE = 20;
28
- export const MAX_RESULT_WINDOW = 10000;
29
- export const MAX_TERMS_BUCKETS = 50;
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';
@@ -1,175 +1,272 @@
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 type ID = string | number;
11
-
12
- export type ReportVisualizationType = 'table' | 'bar' | 'line' | 'area' | 'pie' | 'metric';
13
-
14
- export type FilterOperator =
15
- | 'eq'
16
- | 'ne'
17
- | 'in'
18
- | 'not_in'
19
- | 'gt'
20
- | 'gte'
21
- | 'lt'
22
- | 'lte'
23
- | 'between'
24
- | 'contains'
25
- | 'exists'
26
- | 'not_exists';
27
-
28
- export type ScalarFilterValue = string | number | boolean;
29
-
30
- export interface ReportFilterItem {
31
- id?: string;
32
- field: string;
33
- operator: FilterOperator;
34
- value?: ScalarFilterValue | ScalarFilterValue[];
35
- valueTo?: ScalarFilterValue;
36
- enabled?: boolean;
37
- }
38
-
39
- export interface ReportSortItem {
40
- field: string;
41
- order: 'asc' | 'desc';
42
- }
43
-
44
- export type TimeRangePreset =
45
- | 'last_15m'
46
- | 'last_1h'
47
- | 'last_24h'
48
- | 'last_7d'
49
- | 'last_30d'
50
- | 'last_90d'
51
- | 'all'
52
- | 'custom';
53
-
54
- export interface ReportTimeRange {
55
- preset: TimeRangePreset;
56
- from?: string;
57
- to?: string;
58
- }
59
-
60
- export type BucketAggType = 'date_histogram' | 'terms';
61
- export type MetricAggType = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'cardinality';
62
- export type CalendarIntervalOption = 'auto' | '1m' | '5m' | '15m' | '1h' | '1d' | '1w' | '1M';
63
-
64
- export interface ReportChartConfig {
65
- bucketType?: BucketAggType;
66
- bucketField?: string;
67
- calendarInterval?: CalendarIntervalOption;
68
- topN?: number;
69
- metricType?: MetricAggType;
70
- metricField?: string;
71
- metricLabel?: string;
72
- showHistogram?: boolean;
73
- }
74
-
75
- export interface ReportSpec {
76
- query?: string;
77
- queryMode?: 'kql' | 'simple';
78
- filters?: ReportFilterItem[];
79
- sort?: ReportSortItem[];
80
- timeRange?: ReportTimeRange;
81
- columns?: string[];
82
- pageSize?: number;
83
- visualization: ReportVisualizationType;
84
- chart?: ReportChartConfig;
85
- allowInteractiveControls?: boolean;
86
- }
87
-
88
- export interface EsFieldCapability {
89
- name: string;
90
- type: string;
91
- searchable: boolean;
92
- aggregatable: boolean;
93
- keywordSubfield?: string;
94
- isSubfield?: boolean;
95
- }
96
-
97
- export interface EsConnectionSummary {
98
- key: string;
99
- displayName: string;
100
- status?: string;
101
- indexPattern?: string;
102
- nodes?: string;
103
- }
104
-
105
- export interface EsDataViewRecord {
106
- id: ID;
107
- title: string;
108
- dataSourceKey: string;
109
- indexPattern: string;
110
- timeField?: string | null;
111
- description?: string | null;
112
- cachedFields?: EsFieldCapability[] | null;
113
- createdAt?: string;
114
- updatedAt?: string;
115
- }
116
-
117
- export interface EsReportRecord {
118
- id: ID;
119
- title: string;
120
- description?: string | null;
121
- dataViewId: ID;
122
- dataView?: EsDataViewRecord | null;
123
- visualization: ReportVisualizationType;
124
- spec: ReportSpec;
125
- published: boolean;
126
- createdAt?: string;
127
- updatedAt?: string;
128
- }
129
-
130
- export interface ReportRuntimeOverrides {
131
- query?: string;
132
- filters?: ReportFilterItem[];
133
- sort?: ReportSortItem[];
134
- timeRange?: ReportTimeRange;
135
- page?: number;
136
- pageSize?: number;
137
- searchAfter?: Array<string | number | boolean | null>;
138
- }
139
-
140
- export interface ReportRowHit {
141
- _id: string;
142
- _index: string;
143
- _score?: number | null;
144
- _sort?: Array<string | number | boolean | null>;
145
- source: Record<string, unknown>;
146
- highlights?: Record<string, string[]>;
147
- }
148
-
149
- export interface ReportSeriesPoint {
150
- key: string;
151
- label: string;
152
- value: number;
153
- count: number;
154
- }
155
-
156
- export interface ReportHistogramBucket {
157
- key: string;
158
- timestamp?: number;
159
- count: number;
160
- }
161
-
162
- export interface ReportExecutionResult {
163
- total: number;
164
- totalRelation: 'eq' | 'gte';
165
- tookMs: number;
166
- visualization: ReportVisualizationType;
167
- rows: ReportRowHit[];
168
- columns: string[];
169
- nextSearchAfter?: Array<string | number | boolean | null>;
170
- series: ReportSeriesPoint[];
171
- histogram: ReportHistogramBucket[];
172
- metricValue: number | null;
173
- metricLabel: string;
174
- compiledDsl: Record<string, unknown>;
175
- }
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 type ID = string | number;
11
+
12
+ export type ReportVisualizationType = 'table' | 'bar' | 'line' | 'area' | 'pie' | 'metric';
13
+
14
+ export type FilterOperator =
15
+ | 'eq'
16
+ | 'ne'
17
+ | 'in'
18
+ | 'not_in'
19
+ | 'gt'
20
+ | 'gte'
21
+ | 'lt'
22
+ | 'lte'
23
+ | 'between'
24
+ | 'contains'
25
+ | 'exists'
26
+ | 'not_exists';
27
+
28
+ export type ScalarFilterValue = string | number | boolean;
29
+
30
+ export interface ReportFilterItem {
31
+ id?: string;
32
+ field: string;
33
+ operator: FilterOperator;
34
+ value?: ScalarFilterValue | ScalarFilterValue[];
35
+ valueTo?: ScalarFilterValue;
36
+ enabled?: boolean;
37
+ }
38
+
39
+ export interface ReportSortItem {
40
+ field: string;
41
+ order: 'asc' | 'desc';
42
+ }
43
+
44
+ export type TimeRangePreset =
45
+ | 'last_15m'
46
+ | 'last_1h'
47
+ | 'last_24h'
48
+ | 'last_7d'
49
+ | 'last_30d'
50
+ | 'last_90d'
51
+ | 'all'
52
+ | 'custom';
53
+
54
+ export interface ReportTimeRange {
55
+ preset: TimeRangePreset;
56
+ from?: string;
57
+ to?: string;
58
+ timeZone?: string;
59
+ }
60
+
61
+ export type BucketAggType = 'date_histogram' | 'terms';
62
+ export type MetricAggType = 'count' | 'sum' | 'avg' | 'min' | 'max' | 'cardinality' | 'p50' | 'p95' | 'p99';
63
+ export type CalendarIntervalOption = 'auto' | '1m' | '5m' | '15m' | '1h' | '1d' | '1w' | '1M';
64
+ export type ChartStackMode = 'none' | 'stacked' | 'percent';
65
+ export type FieldFormatType = 'auto' | 'duration_ms' | 'bytes' | 'percent' | 'number' | 'status_badge' | 'url';
66
+ export type AutoRefreshInterval = 0 | 10 | 30 | 60 | 300;
67
+ export type ExportFormat = 'csv' | 'ndjson';
68
+ export type ThresholdOperator = 'gt' | 'gte' | 'lt' | 'lte' | 'eq' | 'ne';
69
+
70
+ export interface RecordContextBinding {
71
+ esField: string;
72
+ recordFieldPath: string;
73
+ }
74
+
75
+ export interface DashboardFilterControlSpec {
76
+ field: string;
77
+ label?: string;
78
+ dataViewId: ID;
79
+ }
80
+
81
+ export interface SharedDashboardState {
82
+ query?: string;
83
+ timeRange?: ReportTimeRange;
84
+ filters: ReportFilterItem[];
85
+ autoRefreshSec?: AutoRefreshInterval;
86
+ refreshTick: number;
87
+ updatedAt: number;
88
+ }
89
+
90
+ export interface FieldTopValuesResult {
91
+ field: string;
92
+ resolvedField: string;
93
+ totalDocs: number;
94
+ buckets: Array<{
95
+ value: string;
96
+ count: number;
97
+ percentage: number;
98
+ }>;
99
+ }
100
+
101
+ export interface ReportChartConfig {
102
+ bucketType?: BucketAggType;
103
+ bucketField?: string;
104
+ calendarInterval?: CalendarIntervalOption;
105
+ topN?: number;
106
+ metricType?: MetricAggType;
107
+ metricField?: string;
108
+ metricLabel?: string;
109
+ showHistogram?: boolean;
110
+ splitSeriesField?: string;
111
+ splitSeriesTopN?: number;
112
+ stackMode?: ChartStackMode;
113
+ comparePreviousPeriod?: boolean;
114
+ }
115
+
116
+ export interface ReportSpec {
117
+ query?: string;
118
+ queryMode?: 'kql' | 'simple';
119
+ filters?: ReportFilterItem[];
120
+ lockedFilters?: ReportFilterItem[];
121
+ sort?: ReportSortItem[];
122
+ timeRange?: ReportTimeRange;
123
+ columns?: string[];
124
+ fieldFormats?: Record<string, FieldFormatType>;
125
+ contextBindings?: RecordContextBinding[];
126
+ pageSize?: number;
127
+ visualization: ReportVisualizationType;
128
+ chart?: ReportChartConfig;
129
+ allowInteractiveControls?: boolean;
130
+ allowExport?: boolean;
131
+ }
132
+
133
+ export interface RoleSummary {
134
+ name: string;
135
+ title: string;
136
+ }
137
+
138
+ export interface EsFieldCapability {
139
+ name: string;
140
+ type: string;
141
+ searchable: boolean;
142
+ aggregatable: boolean;
143
+ keywordSubfield?: string;
144
+ isSubfield?: boolean;
145
+ }
146
+
147
+ export interface EsConnectionSummary {
148
+ key: string;
149
+ displayName: string;
150
+ status?: string;
151
+ indexPattern?: string;
152
+ nodes?: string;
153
+ endpointMode?: 'nodes' | 'cloud';
154
+ authMode?: 'none' | 'basic' | 'apiKey' | 'bearer';
155
+ tlsMode?: 'verify' | 'caFingerprint' | 'caCert' | 'skip';
156
+ cloudConfigured?: boolean;
157
+ }
158
+
159
+ export interface EsConnectionHealthResult {
160
+ ok: boolean;
161
+ clusterName?: string;
162
+ version?: string;
163
+ limitedPrivileges?: boolean;
164
+ }
165
+
166
+ export interface EsDataViewRecord {
167
+ id: ID;
168
+ title: string;
169
+ dataSourceKey: string;
170
+ indexPattern: string;
171
+ timeField?: string | null;
172
+ description?: string | null;
173
+ allowedRoles?: string[];
174
+ cachedFields?: EsFieldCapability[] | null;
175
+ createdAt?: string;
176
+ updatedAt?: string;
177
+ }
178
+
179
+ export interface EsReportRecord {
180
+ id: ID;
181
+ title: string;
182
+ description?: string | null;
183
+ dataViewId: ID;
184
+ dataView?: EsDataViewRecord | null;
185
+ visualization: ReportVisualizationType;
186
+ spec: ReportSpec;
187
+ published: boolean;
188
+ allowedRoles?: string[];
189
+ createdAt?: string;
190
+ updatedAt?: string;
191
+ }
192
+
193
+ export interface ReportRuntimeOverrides {
194
+ query?: string;
195
+ filters?: ReportFilterItem[];
196
+ sharedFilters?: ReportFilterItem[];
197
+ contextFilters?: ReportFilterItem[];
198
+ sort?: ReportSortItem[];
199
+ timeRange?: ReportTimeRange;
200
+ timeZone?: string;
201
+ page?: number;
202
+ pageSize?: number;
203
+ searchAfter?: Array<string | number | boolean | null>;
204
+ pitId?: string;
205
+ }
206
+
207
+ export interface ReportRowHit {
208
+ _id: string;
209
+ _index: string;
210
+ _score?: number | null;
211
+ _sort?: Array<string | number | boolean | null>;
212
+ source: Record<string, unknown>;
213
+ highlights?: Record<string, string[]>;
214
+ }
215
+
216
+ export interface ReportSubSeriesPoint {
217
+ seriesKey: string;
218
+ value: number;
219
+ count: number;
220
+ }
221
+
222
+ export interface ReportSeriesPoint {
223
+ key: string;
224
+ label: string;
225
+ value: number;
226
+ count: number;
227
+ breakdown?: ReportSubSeriesPoint[];
228
+ }
229
+
230
+ export interface ReportHistogramBucket {
231
+ key: string;
232
+ timestamp?: number;
233
+ count: number;
234
+ }
235
+
236
+ export interface ReportShardStats {
237
+ total: number;
238
+ successful: number;
239
+ skipped: number;
240
+ failed: number;
241
+ }
242
+
243
+ export interface ReportExecutionResult {
244
+ total: number;
245
+ totalRelation: 'eq' | 'gte';
246
+ tookMs: number;
247
+ timedOut?: boolean;
248
+ shards?: ReportShardStats;
249
+ warnings?: string[];
250
+ visualization: ReportVisualizationType;
251
+ rows: ReportRowHit[];
252
+ columns: string[];
253
+ nextSearchAfter?: Array<string | number | boolean | null>;
254
+ pitId?: string;
255
+ series: ReportSeriesPoint[];
256
+ seriesKeys?: string[];
257
+ histogram: ReportHistogramBucket[];
258
+ metricValue: number | null;
259
+ previousMetricValue?: number | null;
260
+ deltaPercent?: number | null;
261
+ metricLabel: string;
262
+ compiledDsl: Record<string, unknown>;
263
+ }
264
+
265
+ export interface ElasticWorkflowNodeConfig {
266
+ reportId?: ID;
267
+ queryOverride?: string;
268
+ timePreset?: TimeRangePreset;
269
+ thresholdField?: 'metricValue' | 'total' | 'deltaPercent';
270
+ thresholdOperator?: ThresholdOperator;
271
+ thresholdValue?: number;
272
+ }
@@ -1,32 +0,0 @@
1
- ---
2
- name: elastic-report-builder
3
- title: Elasticsearch Kibana Report Builder
4
- description: Discover Elasticsearch data views, inspect field capabilities, preview KQL/filter/sort/aggregation queries, and create Saved Elasticsearch Reports for NocoBase blocks.
5
- tools:
6
- - elastic-report-es_list_connections
7
- - elastic-report-es_list_data_views
8
- - elastic-report-es_upsert_data_view
9
- - elastic-report-es_inspect_fields
10
- - elastic-report-es_preview_report
11
- - elastic-report-es_save_report
12
- - elastic-report-es_list_reports
13
- ---
14
-
15
- # Elasticsearch Report Builder Guide
16
-
17
- Use these tools (or their `mcp-elastic-report-*` equivalents) whenever a user asks to explore Elasticsearch logs/metrics/documents or build a Kibana-style Table or Chart report in NocoBase.
18
-
19
- ## Mandatory 4-Step Workflow
20
-
21
- 1. **Locate or Create a Data View**:
22
- - Call `es_list_data_views` first.
23
- - If no matching Data View exists yet, call `es_list_connections` to check available Elasticsearch connections and index names, then call `es_upsert_data_view` with `dataSourceKey` and `indexPattern` (for example `logs-*`).
24
- 2. **Inspect Field Capabilities (`_field_caps`)**:
25
- - Always call `es_inspect_fields` for the chosen `dataViewId` before writing filters, sorts, or chart buckets.
26
- - Never guess field names. When sorting or grouping (`terms` bucket) on a `text` field, prefer its `keywordSubfield` (for example `service.keyword`) or a field marked `aggregatable: true`.
27
- 3. **Preview Before Saving**:
28
- - Call `es_preview_report` with your proposed `spec` (`visualization`: `'table' | 'bar' | 'line' | 'area' | 'pie' | 'metric'`, `query` in KQL, `filters`, `sort`, `timeRange`, `columns` or `chart`).
29
- - Verify `total` hits and sample rows/series look accurate; adjust filters or field names if `total` is unexpectedly 0 or an error occurs.
30
- 4. **Save the Report**:
31
- - Call `es_save_report` with `published: true` and a clear `title`.
32
- - Tell the user the saved report title so they can click **Add Block -> Elastic Report** on any `/v/` page and select it immediately.