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,178 +1,178 @@
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 { describe, expect, it } from 'vitest';
11
- import { buildFieldCapabilityMap, compileKqlToQueryDsl } from '../../server/services/ReportQueryCompiler';
12
- import type { EsFieldCapability } from '../../shared/types';
13
- import {
14
- type KqlSuggestionItem,
15
- analyzeKqlCursorContext,
16
- buildKqlSuggestions,
17
- formatKqlValueLiteral,
18
- } from '../utils/kqlAutocomplete';
19
-
20
- const SAMPLE_FIELDS: EsFieldCapability[] = [
21
- { name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
22
- { name: 'service', type: 'keyword', searchable: true, aggregatable: true },
23
- { name: 'service.keyword', type: 'keyword', searchable: true, aggregatable: true, isSubfield: true },
24
- { name: 'status', type: 'integer', searchable: true, aggregatable: true },
25
- { name: 'latency_ms', type: 'double', searchable: true, aggregatable: true },
26
- { name: 'published', type: 'boolean', searchable: true, aggregatable: true },
27
- { name: 'message', type: 'text', searchable: true, aggregatable: false },
28
- ];
29
-
30
- const identityT = (k: string) => k;
31
-
32
- function mustFind(items: KqlSuggestionItem[], token: string): KqlSuggestionItem {
33
- const found = items.find((i) => i.displayToken === token);
34
- if (!found) {
35
- throw new Error(`Expected suggestion "${token}" in [${items.map((i) => i.displayToken).join(', ')}]`);
36
- }
37
- return found;
38
- }
39
-
40
- describe('kqlAutocomplete', () => {
41
- it('guides a beginner step-by-step from empty input through numeric, connector, keyword, and group clauses', () => {
42
- const fieldMap = buildFieldCapabilityMap(SAMPLE_FIELDS);
43
-
44
- // 1. Empty input -> primary fields (hiding .keyword subfield)
45
- const step1 = buildKqlSuggestions({ input: '', fields: SAMPLE_FIELDS, t: identityT });
46
- expect(step1.context.stage).toBe('field');
47
- expect(step1.items.some((i) => i.displayToken === 'service')).toBe(true);
48
- expect(step1.items.some((i) => i.displayToken === 'service.keyword')).toBe(false);
49
-
50
- // Pick numeric field `status` -> inserts `status ` and enters `operator` stage
51
- const pickStatus = mustFind(step1.items, 'status');
52
- expect(pickStatus.nextQuery).toBe('status ');
53
-
54
- // 2. Operator stage for `status `
55
- const step2 = buildKqlSuggestions({ input: pickStatus.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
56
- expect(step2.context.stage).toBe('operator');
57
- const pickGte = mustFind(step2.items, 'status >=');
58
- expect(pickGte.nextQuery).toBe('status >= ');
59
-
60
- // 3. Value stage for `status >= ` with real top values
61
- const step3 = buildKqlSuggestions({
62
- input: pickGte.nextQuery,
63
- fields: SAMPLE_FIELDS,
64
- topValueBuckets: [
65
- { value: '500', count: 42 },
66
- { value: '404', count: 15 },
67
- ],
68
- t: identityT,
69
- });
70
- expect(step3.context.stage).toBe('value');
71
- const pick500 = mustFind(step3.items, '500');
72
- expect(pick500.nextQuery).toBe('status >= 500 ');
73
-
74
- // 4. Connector stage after completed clause `status >= 500 `
75
- const step4 = buildKqlSuggestions({ input: pick500.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
76
- expect(step4.context.stage).toBe('connector');
77
- const pickAnd = mustFind(step4.items, 'AND');
78
- expect(pickAnd.nextQuery).toBe('status >= 500 AND ');
79
-
80
- // 5. Pick keyword field `service` -> jumps straight to `service: `
81
- const step5 = buildKqlSuggestions({ input: pickAnd.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
82
- const pickService = mustFind(step5.items, 'service');
83
- expect(pickService.nextQuery).toBe('status >= 500 AND service: ');
84
-
85
- // 6. Pick multi-value group `(` -> `status >= 500 AND service: (`
86
- const step6 = buildKqlSuggestions({
87
- input: pickService.nextQuery,
88
- fields: SAMPLE_FIELDS,
89
- topValueBuckets: [
90
- { value: 'api gateway', count: 30 },
91
- { value: 'auth:v2', count: 12 },
92
- ],
93
- t: identityT,
94
- });
95
- const pickGroup = mustFind(step6.items, '(');
96
- expect(pickGroup.nextQuery).toBe('status >= 500 AND service: (');
97
-
98
- // 7. Inside group, pick value containing space -> quoted safely
99
- const step7 = buildKqlSuggestions({
100
- input: pickGroup.nextQuery,
101
- fields: SAMPLE_FIELDS,
102
- topValueBuckets: [
103
- { value: 'api gateway', count: 30 },
104
- { value: 'auth:v2', count: 12 },
105
- ],
106
- t: identityT,
107
- });
108
- expect(step7.context.insideFieldGroup).toBe(true);
109
- const pickFirstGroupVal = mustFind(step7.items, '"api gateway"');
110
- expect(pickFirstGroupVal.nextQuery).toBe('status >= 500 AND service: ("api gateway" ');
111
-
112
- // 8. Group connector -> `OR ` -> second value with colon -> close `)`
113
- const step8 = buildKqlSuggestions({ input: pickFirstGroupVal.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
114
- expect(step8.context.stage).toBe('group_connector');
115
- const pickGroupOr = mustFind(step8.items, 'OR');
116
- const step9 = buildKqlSuggestions({
117
- input: pickGroupOr.nextQuery,
118
- fields: SAMPLE_FIELDS,
119
- topValueBuckets: [{ value: 'auth:v2', count: 12 }],
120
- t: identityT,
121
- });
122
- const pickSecondGroupVal = mustFind(step9.items, '"auth:v2"');
123
- const step10 = buildKqlSuggestions({ input: pickSecondGroupVal.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
124
- const pickCloseGroup = mustFind(step10.items, ')');
125
- expect(pickCloseGroup.nextQuery).toBe('status >= 500 AND service: ("api gateway" OR "auth:v2") ');
126
-
127
- // Resulting KQL must compile cleanly through ReportQueryCompiler without syntax errors
128
- const compiled = compileKqlToQueryDsl(pickCloseGroup.nextQuery, fieldMap);
129
- expect(compiled).toEqual({
130
- bool: {
131
- must: [
132
- { range: { status: { gte: 500 } } },
133
- {
134
- bool: {
135
- should: [{ term: { service: 'api gateway' } }, { term: { service: 'auth:v2' } }],
136
- minimum_should_match: 1,
137
- },
138
- },
139
- ],
140
- },
141
- });
142
- });
143
-
144
- it('auto-inserts AND when user starts typing a new field after a completed clause without a boolean connector', () => {
145
- const res = buildKqlSuggestions({
146
- input: 'status >= 500 ser',
147
- fields: SAMPLE_FIELDS,
148
- t: identityT,
149
- });
150
- expect(res.context.stage).toBe('connector');
151
- expect(res.context.needsLeadingAnd).toBe(true);
152
- const autoAndService = mustFind(res.items, 'AND service');
153
- expect(autoAndService.nextQuery).toBe('status >= 500 AND service: ');
154
- });
155
-
156
- it('consumes adjacent closing quote when editing inside an existing quoted value and formats literals safely', () => {
157
- const input = 'service: "gat" AND status >= 400';
158
- // Cursor right after `gat` (index 13, before closing `"`)
159
- const ctx = analyzeKqlCursorContext(input, 13, SAMPLE_FIELDS);
160
- expect(ctx.stage).toBe('value');
161
- expect(ctx.field).toBe('service');
162
- expect(ctx.partial).toBe('gat');
163
-
164
- const res = buildKqlSuggestions({
165
- input,
166
- cursorPos: 13,
167
- fields: SAMPLE_FIELDS,
168
- topValueBuckets: [{ value: 'gateway', count: 10 }],
169
- t: identityT,
170
- });
171
- const pickGateway = mustFind(res.items, '"gateway"');
172
- expect(pickGateway.nextQuery).toBe('service: "gateway" AND status >= 400');
173
-
174
- expect(formatKqlValueLiteral('true', SAMPLE_FIELDS[5])).toBe('true');
175
- expect(formatKqlValueLiteral('250.5', SAMPLE_FIELDS[4])).toBe('250.5');
176
- expect(formatKqlValueLiteral('say "hi"', SAMPLE_FIELDS[1])).toBe('"say \\"hi\\""');
177
- });
178
- });
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 { describe, expect, it } from 'vitest';
11
+ import { buildFieldCapabilityMap, compileKqlToQueryDsl } from '../../server/services/ReportQueryCompiler';
12
+ import type { EsFieldCapability } from '../../shared/types';
13
+ import {
14
+ type KqlSuggestionItem,
15
+ analyzeKqlCursorContext,
16
+ buildKqlSuggestions,
17
+ formatKqlValueLiteral,
18
+ } from '../utils/kqlAutocomplete';
19
+
20
+ const SAMPLE_FIELDS: EsFieldCapability[] = [
21
+ { name: '@timestamp', type: 'date', searchable: true, aggregatable: true },
22
+ { name: 'service', type: 'keyword', searchable: true, aggregatable: true },
23
+ { name: 'service.keyword', type: 'keyword', searchable: true, aggregatable: true, isSubfield: true },
24
+ { name: 'status', type: 'integer', searchable: true, aggregatable: true },
25
+ { name: 'latency_ms', type: 'double', searchable: true, aggregatable: true },
26
+ { name: 'published', type: 'boolean', searchable: true, aggregatable: true },
27
+ { name: 'message', type: 'text', searchable: true, aggregatable: false },
28
+ ];
29
+
30
+ const identityT = (k: string) => k;
31
+
32
+ function mustFind(items: KqlSuggestionItem[], token: string): KqlSuggestionItem {
33
+ const found = items.find((i) => i.displayToken === token);
34
+ if (!found) {
35
+ throw new Error(`Expected suggestion "${token}" in [${items.map((i) => i.displayToken).join(', ')}]`);
36
+ }
37
+ return found;
38
+ }
39
+
40
+ describe('kqlAutocomplete', () => {
41
+ it('guides a beginner step-by-step from empty input through numeric, connector, keyword, and group clauses', () => {
42
+ const fieldMap = buildFieldCapabilityMap(SAMPLE_FIELDS);
43
+
44
+ // 1. Empty input -> primary fields (hiding .keyword subfield)
45
+ const step1 = buildKqlSuggestions({ input: '', fields: SAMPLE_FIELDS, t: identityT });
46
+ expect(step1.context.stage).toBe('field');
47
+ expect(step1.items.some((i) => i.displayToken === 'service')).toBe(true);
48
+ expect(step1.items.some((i) => i.displayToken === 'service.keyword')).toBe(false);
49
+
50
+ // Pick numeric field `status` -> inserts `status ` and enters `operator` stage
51
+ const pickStatus = mustFind(step1.items, 'status');
52
+ expect(pickStatus.nextQuery).toBe('status ');
53
+
54
+ // 2. Operator stage for `status `
55
+ const step2 = buildKqlSuggestions({ input: pickStatus.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
56
+ expect(step2.context.stage).toBe('operator');
57
+ const pickGte = mustFind(step2.items, 'status >=');
58
+ expect(pickGte.nextQuery).toBe('status >= ');
59
+
60
+ // 3. Value stage for `status >= ` with real top values
61
+ const step3 = buildKqlSuggestions({
62
+ input: pickGte.nextQuery,
63
+ fields: SAMPLE_FIELDS,
64
+ topValueBuckets: [
65
+ { value: '500', count: 42 },
66
+ { value: '404', count: 15 },
67
+ ],
68
+ t: identityT,
69
+ });
70
+ expect(step3.context.stage).toBe('value');
71
+ const pick500 = mustFind(step3.items, '500');
72
+ expect(pick500.nextQuery).toBe('status >= 500 ');
73
+
74
+ // 4. Connector stage after completed clause `status >= 500 `
75
+ const step4 = buildKqlSuggestions({ input: pick500.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
76
+ expect(step4.context.stage).toBe('connector');
77
+ const pickAnd = mustFind(step4.items, 'AND');
78
+ expect(pickAnd.nextQuery).toBe('status >= 500 AND ');
79
+
80
+ // 5. Pick keyword field `service` -> jumps straight to `service: `
81
+ const step5 = buildKqlSuggestions({ input: pickAnd.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
82
+ const pickService = mustFind(step5.items, 'service');
83
+ expect(pickService.nextQuery).toBe('status >= 500 AND service: ');
84
+
85
+ // 6. Pick multi-value group `(` -> `status >= 500 AND service: (`
86
+ const step6 = buildKqlSuggestions({
87
+ input: pickService.nextQuery,
88
+ fields: SAMPLE_FIELDS,
89
+ topValueBuckets: [
90
+ { value: 'api gateway', count: 30 },
91
+ { value: 'auth:v2', count: 12 },
92
+ ],
93
+ t: identityT,
94
+ });
95
+ const pickGroup = mustFind(step6.items, '(');
96
+ expect(pickGroup.nextQuery).toBe('status >= 500 AND service: (');
97
+
98
+ // 7. Inside group, pick value containing space -> quoted safely
99
+ const step7 = buildKqlSuggestions({
100
+ input: pickGroup.nextQuery,
101
+ fields: SAMPLE_FIELDS,
102
+ topValueBuckets: [
103
+ { value: 'api gateway', count: 30 },
104
+ { value: 'auth:v2', count: 12 },
105
+ ],
106
+ t: identityT,
107
+ });
108
+ expect(step7.context.insideFieldGroup).toBe(true);
109
+ const pickFirstGroupVal = mustFind(step7.items, '"api gateway"');
110
+ expect(pickFirstGroupVal.nextQuery).toBe('status >= 500 AND service: ("api gateway" ');
111
+
112
+ // 8. Group connector -> `OR ` -> second value with colon -> close `)`
113
+ const step8 = buildKqlSuggestions({ input: pickFirstGroupVal.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
114
+ expect(step8.context.stage).toBe('group_connector');
115
+ const pickGroupOr = mustFind(step8.items, 'OR');
116
+ const step9 = buildKqlSuggestions({
117
+ input: pickGroupOr.nextQuery,
118
+ fields: SAMPLE_FIELDS,
119
+ topValueBuckets: [{ value: 'auth:v2', count: 12 }],
120
+ t: identityT,
121
+ });
122
+ const pickSecondGroupVal = mustFind(step9.items, '"auth:v2"');
123
+ const step10 = buildKqlSuggestions({ input: pickSecondGroupVal.nextQuery, fields: SAMPLE_FIELDS, t: identityT });
124
+ const pickCloseGroup = mustFind(step10.items, ')');
125
+ expect(pickCloseGroup.nextQuery).toBe('status >= 500 AND service: ("api gateway" OR "auth:v2") ');
126
+
127
+ // Resulting KQL must compile cleanly through ReportQueryCompiler without syntax errors
128
+ const compiled = compileKqlToQueryDsl(pickCloseGroup.nextQuery, fieldMap);
129
+ expect(compiled).toEqual({
130
+ bool: {
131
+ must: [
132
+ { range: { status: { gte: 500 } } },
133
+ {
134
+ bool: {
135
+ should: [{ term: { service: 'api gateway' } }, { term: { service: 'auth:v2' } }],
136
+ minimum_should_match: 1,
137
+ },
138
+ },
139
+ ],
140
+ },
141
+ });
142
+ });
143
+
144
+ it('auto-inserts AND when user starts typing a new field after a completed clause without a boolean connector', () => {
145
+ const res = buildKqlSuggestions({
146
+ input: 'status >= 500 ser',
147
+ fields: SAMPLE_FIELDS,
148
+ t: identityT,
149
+ });
150
+ expect(res.context.stage).toBe('connector');
151
+ expect(res.context.needsLeadingAnd).toBe(true);
152
+ const autoAndService = mustFind(res.items, 'AND service');
153
+ expect(autoAndService.nextQuery).toBe('status >= 500 AND service: ');
154
+ });
155
+
156
+ it('consumes adjacent closing quote when editing inside an existing quoted value and formats literals safely', () => {
157
+ const input = 'service: "gat" AND status >= 400';
158
+ // Cursor right after `gat` (index 13, before closing `"`)
159
+ const ctx = analyzeKqlCursorContext(input, 13, SAMPLE_FIELDS);
160
+ expect(ctx.stage).toBe('value');
161
+ expect(ctx.field).toBe('service');
162
+ expect(ctx.partial).toBe('gat');
163
+
164
+ const res = buildKqlSuggestions({
165
+ input,
166
+ cursorPos: 13,
167
+ fields: SAMPLE_FIELDS,
168
+ topValueBuckets: [{ value: 'gateway', count: 10 }],
169
+ t: identityT,
170
+ });
171
+ const pickGateway = mustFind(res.items, '"gateway"');
172
+ expect(pickGateway.nextQuery).toBe('service: "gateway" AND status >= 400');
173
+
174
+ expect(formatKqlValueLiteral('true', SAMPLE_FIELDS[5])).toBe('true');
175
+ expect(formatKqlValueLiteral('250.5', SAMPLE_FIELDS[4])).toBe('250.5');
176
+ expect(formatKqlValueLiteral('say "hi"', SAMPLE_FIELDS[1])).toBe('"say \\"hi\\""');
177
+ });
178
+ });