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.
- 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/dist/ai/skills/elastic-report/SKILLS.md +52 -0
- package/dist/client/357.0dd385384cab5dbf.js +10 -0
- package/dist/client/index.js +1 -1
- package/dist/client-v2/851.35e416bfb3fb565f.js +10 -0
- package/dist/client-v2/857.a5bf9637d5fd4ef5.js +10 -0
- package/dist/client-v2/877.81b10beb7b7f4bd7.js +10 -0
- package/dist/client-v2/index.js +1 -1
- package/dist/externalVersion.js +5 -3
- package/dist/locale/en-US.json +213 -99
- package/dist/locale/vi-VN.json +213 -99
- package/dist/locale/zh-CN.json +213 -99
- package/dist/node_modules/@elastic/elasticsearch/package.json +1 -1
- package/dist/server/acl-guard.js +97 -25
- package/dist/server/collections/es-report-data-views.js +6 -0
- package/dist/server/collections/es-reports.js +6 -0
- package/dist/server/mcp/ElasticReportToolCatalog.js +238 -14
- package/dist/server/plugin.js +156 -22
- package/dist/server/report-block-tools.js +340 -0
- package/dist/server/services/ElasticReportService.js +137 -17
- package/dist/server/services/ElasticsearchConnectionService.js +274 -34
- package/dist/server/services/ReportExportService.js +243 -0
- package/dist/server/services/ReportQueryCompiler.js +532 -91
- package/dist/server/workflow/ElasticReportQueryInstruction.js +123 -0
- package/dist/shared/constants.js +26 -2
- package/package.json +3 -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 -19
- package/src/client/workflow-instructions.tsx +44 -0
- package/src/client-v2/__tests__/elastic-report.test.tsx +879 -311
- package/src/client-v2/__tests__/kql-autocomplete.test.ts +178 -0
- package/src/client-v2/api.ts +320 -224
- package/src/client-v2/bus/DashboardFilterBus.ts +212 -0
- package/src/client-v2/components/ElasticBasicCharts.tsx +652 -399
- package/src/client-v2/components/ElasticFilterBar.tsx +372 -0
- package/src/client-v2/components/ElasticKqlInput.tsx +421 -0
- package/src/client-v2/components/ElasticReportBlock.tsx +306 -160
- package/src/client-v2/components/ElasticReportRenderer.tsx +1257 -707
- package/src/client-v2/components/HighlightText.tsx +50 -50
- package/src/client-v2/components/ReportSelect.tsx +85 -72
- package/src/client-v2/index.tsx +14 -14
- package/src/client-v2/locale.ts +23 -23
- package/src/client-v2/models/ElasticFilterBarBlockModel.tsx +115 -0
- package/src/client-v2/models/ElasticReportBlockModel.tsx +118 -85
- package/src/client-v2/pages/ElasticReportManager.tsx +1453 -1047
- package/src/client-v2/plugin.tsx +107 -52
- package/src/client-v2/report-destination.tsx +126 -0
- package/src/client-v2/utils/kqlAutocomplete.ts +861 -0
- package/src/client-v2/workflow/instructions.tsx +149 -0
- package/src/index.ts +11 -11
- package/src/locale/en-US.json +213 -99
- package/src/locale/vi-VN.json +213 -99
- package/src/locale/zh-CN.json +213 -99
- package/src/server/__tests__/ai-blocks.integration.test.ts +292 -0
- package/src/server/__tests__/query-compiler.test.ts +620 -231
- package/src/server/__tests__/report-mcp-acl.integration.test.ts +645 -377
- package/src/server/acl-guard.ts +194 -103
- package/src/server/collections/es-report-data-views.ts +64 -58
- package/src/server/collections/es-reports.ts +80 -74
- package/src/server/index.ts +15 -15
- package/src/server/mcp/ElasticReportMcpServer.ts +391 -391
- package/src/server/mcp/ElasticReportToolCatalog.ts +667 -417
- package/src/server/plugin.ts +599 -431
- package/src/server/report-block-tools.ts +400 -0
- package/src/server/services/ElasticReportService.ts +494 -326
- package/src/server/services/ElasticsearchConnectionService.ts +728 -401
- package/src/server/services/ReportExportService.ts +282 -0
- package/src/server/services/ReportQueryCompiler.ts +1552 -1017
- package/src/server/workflow/ElasticReportQueryInstruction.ts +124 -0
- package/src/shared/constants.ts +39 -29
- package/src/shared/types.ts +272 -175
- package/ai/skills/elastic-report/SKILLS.md +0 -32
- package/dist/client-v2/851.488fdbf5bc5b6a36.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
package/src/locale/zh-CN.json
CHANGED
|
@@ -1,99 +1,213 @@
|
|
|
1
|
-
{
|
|
2
|
-
"
|
|
3
|
-
"
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
-
"
|
|
18
|
-
"
|
|
19
|
-
"
|
|
20
|
-
"
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"
|
|
24
|
-
"
|
|
25
|
-
"
|
|
26
|
-
"
|
|
27
|
-
"
|
|
28
|
-
"
|
|
29
|
-
"
|
|
30
|
-
"
|
|
31
|
-
"
|
|
32
|
-
"
|
|
33
|
-
"
|
|
34
|
-
"
|
|
35
|
-
"
|
|
36
|
-
"
|
|
37
|
-
"
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"
|
|
42
|
-
"
|
|
43
|
-
"
|
|
44
|
-
"
|
|
45
|
-
"
|
|
46
|
-
"
|
|
47
|
-
"
|
|
48
|
-
"
|
|
49
|
-
"
|
|
50
|
-
"
|
|
51
|
-
"
|
|
52
|
-
"
|
|
53
|
-
"
|
|
54
|
-
"
|
|
55
|
-
"
|
|
56
|
-
"
|
|
57
|
-
"
|
|
58
|
-
"
|
|
59
|
-
"
|
|
60
|
-
"
|
|
61
|
-
"
|
|
62
|
-
"
|
|
63
|
-
"
|
|
64
|
-
"
|
|
65
|
-
"
|
|
66
|
-
"
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"
|
|
73
|
-
"
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"
|
|
77
|
-
"
|
|
78
|
-
"
|
|
79
|
-
"
|
|
80
|
-
"
|
|
81
|
-
"
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
86
|
-
"
|
|
87
|
-
"
|
|
88
|
-
"
|
|
89
|
-
"
|
|
90
|
-
"
|
|
91
|
-
"
|
|
92
|
-
"
|
|
93
|
-
"
|
|
94
|
-
"
|
|
95
|
-
"
|
|
96
|
-
"
|
|
97
|
-
"
|
|
98
|
-
"
|
|
99
|
-
|
|
1
|
+
{
|
|
2
|
+
"Add report block": "添加报表区块",
|
|
3
|
+
"Report block destination": "报表区块目标位置",
|
|
4
|
+
"Page and tab": "页面和标签页",
|
|
5
|
+
"Attach destination": "附加目标位置",
|
|
6
|
+
"Select report block destination": "请通过“报表区块目标位置”选择一个页面、标签页和报表。",
|
|
7
|
+
"Inspect selected Elastic Report block": "查看所选 Elastic Report 区块",
|
|
8
|
+
"Configure selected Elastic Report block": "配置所选 Elastic Report 区块",
|
|
9
|
+
"Pick one Elastic Report block": "请使用“选择区块”附加一个 Elastic Report 区块。",
|
|
10
|
+
"Block page unavailable": "当前页面上的所选区块不可用。",
|
|
11
|
+
"Block editing unavailable": "当前角色无法编辑此区块实例。",
|
|
12
|
+
"Invalid block changes": "请提供支持的设置及其原始值。",
|
|
13
|
+
"Report unavailable for this block": "请选择当前角色可访问的已发布报表。",
|
|
14
|
+
"Block settings changed": "区块已更改。请重新读取设置再应用更改。",
|
|
15
|
+
"Published report ready for blocks": "报表已发布,可在区块中选择。",
|
|
16
|
+
"Draft saved in Settings": "草稿已保存至 Elastic Report 设置。",
|
|
17
|
+
"Elastic Report": "Elasticsearch 报表",
|
|
18
|
+
"Elastic report settings": "Elasticsearch 报表配置",
|
|
19
|
+
"Select report": "选择报表",
|
|
20
|
+
"Report": "报表",
|
|
21
|
+
"Show interactive toolbar": "显示交互式检索工具栏",
|
|
22
|
+
"Compact layout": "紧凑布局",
|
|
23
|
+
"Reports": "报表管理",
|
|
24
|
+
"Data Views": "数据视图 (Data Views)",
|
|
25
|
+
"MCP & AI Employee": "MCP 与 AI 员工",
|
|
26
|
+
"New Report": "新建报表",
|
|
27
|
+
"Edit Report": "编辑报表",
|
|
28
|
+
"New Data View": "新建数据视图",
|
|
29
|
+
"Edit Data View": "编辑数据视图",
|
|
30
|
+
"Title": "标题",
|
|
31
|
+
"Description": "描述",
|
|
32
|
+
"Data Source (Elasticsearch)": "数据源 (Elasticsearch)",
|
|
33
|
+
"Index Pattern": "索引模式 (Index Pattern)",
|
|
34
|
+
"Time Field": "时间字段",
|
|
35
|
+
"Browse Indices": "查看匹配索引",
|
|
36
|
+
"Matching Indices": "匹配的索引",
|
|
37
|
+
"Fields": "字段数",
|
|
38
|
+
"Refresh Fields": "刷新字段元数据",
|
|
39
|
+
"Visualization": "可视化类型",
|
|
40
|
+
"Table (Discover)": "数据表 (Discover)",
|
|
41
|
+
"Bar Chart": "柱状图",
|
|
42
|
+
"Line Chart": "折线图",
|
|
43
|
+
"Area Chart": "面积图",
|
|
44
|
+
"Pie Chart": "饼图",
|
|
45
|
+
"Metric KPI": "指标卡 (KPI)",
|
|
46
|
+
"Data View": "数据视图",
|
|
47
|
+
"Published": "已发布",
|
|
48
|
+
"Draft": "草稿",
|
|
49
|
+
"Allow interactive search/filter on block": "允许在区块中交互式搜索与筛选",
|
|
50
|
+
"Show time histogram above table": "在表格上方显示时间直方图",
|
|
51
|
+
"KQL / Search Query": "KQL / 搜索语句",
|
|
52
|
+
"Search KQL, e.g. status >= 500 AND service: \"api\"": "输入 KQL,例如 status >= 500 AND service: \"api\"",
|
|
53
|
+
"Search": "检索",
|
|
54
|
+
"Reset": "重置",
|
|
55
|
+
"Refresh": "刷新",
|
|
56
|
+
"Inspect DSL": "查看 DSL",
|
|
57
|
+
"Elasticsearch Query DSL": "Elasticsearch 查询 DSL",
|
|
58
|
+
"Add Filter": "添加筛选",
|
|
59
|
+
"Edit Filter": "编辑筛选",
|
|
60
|
+
"Field": "字段",
|
|
61
|
+
"Operator": "操作符",
|
|
62
|
+
"Value": "值",
|
|
63
|
+
"To Value": "结束值",
|
|
64
|
+
"Apply": "应用",
|
|
65
|
+
"Cancel": "取消",
|
|
66
|
+
"Save": "保存",
|
|
67
|
+
"Delete": "删除",
|
|
68
|
+
"Edit": "编辑",
|
|
69
|
+
"Preview": "预览",
|
|
70
|
+
"Run Preview": "运行预览",
|
|
71
|
+
"Sort": "排序",
|
|
72
|
+
"Add Sort": "添加排序",
|
|
73
|
+
"Ascending": "升序",
|
|
74
|
+
"Descending": "降序",
|
|
75
|
+
"Columns": "显示列",
|
|
76
|
+
"Auto-detect columns from documents": "自动从文档提取列",
|
|
77
|
+
"Page Size": "每页条数",
|
|
78
|
+
"Bucket Type": "分桶方式",
|
|
79
|
+
"Date Histogram": "时间直方图",
|
|
80
|
+
"Top Terms": "分组统计 (Terms)",
|
|
81
|
+
"Bucket Field": "分组字段",
|
|
82
|
+
"Interval": "时间间隔",
|
|
83
|
+
"Top N": "前 N 项",
|
|
84
|
+
"Metric": "指标聚合",
|
|
85
|
+
"Metric Field": "指标字段",
|
|
86
|
+
"Metric Label": "指标名称",
|
|
87
|
+
"Last 15 minutes": "最近 15 分钟",
|
|
88
|
+
"Last 1 hour": "最近 1 小时",
|
|
89
|
+
"Last 24 hours": "最近 24 小时",
|
|
90
|
+
"Last 7 days": "最近 7 天",
|
|
91
|
+
"Last 30 days": "最近 30 天",
|
|
92
|
+
"Last 90 days": "最近 90 天",
|
|
93
|
+
"All time": "全部时间",
|
|
94
|
+
"Custom range": "自定义时间范围",
|
|
95
|
+
"From": "开始时间",
|
|
96
|
+
"To": "结束时间",
|
|
97
|
+
"Allowed Roles": "允许访问的角色",
|
|
98
|
+
"Leave empty to allow all authenticated users": "留空则允许所有登录用户查看",
|
|
99
|
+
"All roles": "全部角色",
|
|
100
|
+
"Locked Security Filters (Server-enforced)": "服务端强制安全筛选 (不可被访客覆盖)",
|
|
101
|
+
"Add Locked Filter": "添加强制筛选",
|
|
102
|
+
"Locked filter": "强制筛选",
|
|
103
|
+
"Partial results warning": "部分分片或超时告警",
|
|
104
|
+
"Query timed out; displayed results may be incomplete.": "查询超时,当前展示的数据可能不完整。",
|
|
105
|
+
"Failed shards": "失败分片",
|
|
106
|
+
"Elastic Filter Bar": "Elasticsearch 仪表盘筛选栏",
|
|
107
|
+
"Elastic filter bar settings": "Elasticsearch 筛选栏配置",
|
|
108
|
+
"Sync Group": "同步分组 (Sync Group)",
|
|
109
|
+
"Subscribe to dashboard filter bar": "联动同页筛选栏",
|
|
110
|
+
"Filter Fields (comma-separated, e.g. service, region)": "下拉筛选字段 (逗号分隔,如 service, region)",
|
|
111
|
+
"Show global KQL input": "显示全局 KQL 输入框",
|
|
112
|
+
"Show global time range": "显示全局时间范围",
|
|
113
|
+
"Dashboard filter": "全局筛选",
|
|
114
|
+
"Clear dashboard filters": "清空全局筛选",
|
|
115
|
+
"Auto refresh": "自动刷新",
|
|
116
|
+
"Off": "关闭",
|
|
117
|
+
"Fields Explorer": "字段探查",
|
|
118
|
+
"Top values": "高频值分布",
|
|
119
|
+
"Filter for value": "筛选等于该值 (+)",
|
|
120
|
+
"Filter out value": "排除该值 (-)",
|
|
121
|
+
"Visible Columns": "显示列调整",
|
|
122
|
+
"Move up": "上移",
|
|
123
|
+
"Move down": "下移",
|
|
124
|
+
"Split Series Field": "二次分组字段 (Split Series)",
|
|
125
|
+
"Stack Mode": "堆叠模式",
|
|
126
|
+
"Grouped": "并列分组",
|
|
127
|
+
"Stacked": "数值堆叠",
|
|
128
|
+
"100% Stacked": "百分比堆叠 (100%)",
|
|
129
|
+
"Compare previous period": "对比上一周期",
|
|
130
|
+
"vs previous period": "较上一周期",
|
|
131
|
+
"Field Formats": "字段显示格式",
|
|
132
|
+
"Add Field Format": "添加格式规则",
|
|
133
|
+
"Format": "格式",
|
|
134
|
+
"Auto": "自动",
|
|
135
|
+
"Duration (ms)": "耗时 (ms)",
|
|
136
|
+
"Bytes": "字节 (Bytes)",
|
|
137
|
+
"Percent (%)": "百分比 (%)",
|
|
138
|
+
"Number": "千分位数字",
|
|
139
|
+
"Status Badge": "状态徽章",
|
|
140
|
+
"URL Link": "超链接",
|
|
141
|
+
"Record Context Bindings": "当前记录上下文绑定",
|
|
142
|
+
"Add Context Binding": "添加上下文绑定",
|
|
143
|
+
"Record Field Path": "NocoBase 记录字段路径",
|
|
144
|
+
"Allow data export on block": "允许在区块中导出数据",
|
|
145
|
+
"Export CSV": "导出 CSV",
|
|
146
|
+
"Export NDJSON": "导出 NDJSON",
|
|
147
|
+
"Query Elasticsearch Report": "查询 Elasticsearch 报表",
|
|
148
|
+
"Execute a Saved Elasticsearch Report and evaluate threshold conditions for scheduled alerts or reports.": "执行已保存的 Elasticsearch 报表并评估阈值条件,用于定时报表或告警工作流。",
|
|
149
|
+
"Threshold Metric": "阈值评估指标",
|
|
150
|
+
"Threshold Operator": "阈值比较符",
|
|
151
|
+
"Threshold Value": "阈值数值",
|
|
152
|
+
"Total Hits": "总命中数",
|
|
153
|
+
"Metric Value": "聚合指标值",
|
|
154
|
+
"Delta (%)": "环比变化 (%)",
|
|
155
|
+
"Threshold Breached": "是否触发阈值",
|
|
156
|
+
"Top Buckets": "前序分桶结果",
|
|
157
|
+
"Sample Rows": "样本记录",
|
|
158
|
+
"Executed At": "执行时间",
|
|
159
|
+
"Document Details": "文档详情",
|
|
160
|
+
"Table View": "字段表格",
|
|
161
|
+
"JSON View": "原始 JSON",
|
|
162
|
+
"Show data table": "查看数据表",
|
|
163
|
+
"Show chart": "查看图表",
|
|
164
|
+
"Select a saved Elastic Report in block settings to display data": "请在区块配置中选择已保存的 Elasticsearch 报表",
|
|
165
|
+
"No matching documents": "没有匹配的文档",
|
|
166
|
+
"Saved successfully": "保存成功",
|
|
167
|
+
"Deleted successfully": "删除成功",
|
|
168
|
+
"Copied to clipboard": "已复制到剪贴板",
|
|
169
|
+
"Copy": "复制",
|
|
170
|
+
"Confirm delete?": "确认删除?",
|
|
171
|
+
"Hits": "命中数",
|
|
172
|
+
"Next cursor page": "下一页 (游标)",
|
|
173
|
+
"First page": "返回首页",
|
|
174
|
+
"Dedicated MCP Endpoint": "插件专属 MCP 端点",
|
|
175
|
+
"MCP Server Name": "MCP 服务名称",
|
|
176
|
+
"Exposed MCP Tools": "已暴露的 MCP 工具",
|
|
177
|
+
"AI Employee Usage": "AI 员工使用说明",
|
|
178
|
+
"This plugin automatically registers the elastic-report MCP server (with user context) and AI Employee tools so AI agents can inspect fields, preview Elasticsearch queries, and publish Saved Reports ready to select in blocks.": "本插件会自动注册携带用户上下文的 elastic-report MCP 服务与 AI 员工工具,支持 AI 自动探查字段、预览 Elasticsearch 查询并发布可在页面区块中直接选用的报表。",
|
|
179
|
+
"Type keywords freely or select a field below": "可直接输入关键字,或从下方选择字段引导构建查询",
|
|
180
|
+
"Suggested Fields": "推荐字段",
|
|
181
|
+
"Comparisons & Operators": "比较与操作符",
|
|
182
|
+
"Suggested Values": "推荐字段值",
|
|
183
|
+
"Combine Conditions": "组合条件",
|
|
184
|
+
"Free-text Search": "全文自由检索",
|
|
185
|
+
"Loading field values...": "正在加载字段高频值...",
|
|
186
|
+
"Choose comparison (=, >=, <=...)": "选择比较符号 (=, >=, <=...)",
|
|
187
|
+
"Filter by field value": "按该字段值筛选",
|
|
188
|
+
"Equals (=)": "等于 (=)",
|
|
189
|
+
"Equals or contains (: )": "等于或包含 (: )",
|
|
190
|
+
"Greater than or equal (>=)": "大于等于 (>=)",
|
|
191
|
+
"Less than or equal (<=)": "小于等于 (<=)",
|
|
192
|
+
"Greater than (>)": "大于 (>)",
|
|
193
|
+
"Less than (<)": "小于 (<)",
|
|
194
|
+
"Match multiple values (OR)": "匹配多个值之一 (OR)",
|
|
195
|
+
"Has any value (exists)": "字段非空 (exists)",
|
|
196
|
+
"Exclude matching records": "排除匹配记录",
|
|
197
|
+
"Search text across all fields (Press Enter)": "跨所有字段自由搜索 (按回车)",
|
|
198
|
+
"Boolean true": "布尔真 (true)",
|
|
199
|
+
"Boolean false": "布尔假 (false)",
|
|
200
|
+
"Suggested value from data": "来自 Elasticsearch 的高频值",
|
|
201
|
+
"Sample value from loaded rows": "来自当前表格的样本值",
|
|
202
|
+
"Finish value group": "结束多值分组",
|
|
203
|
+
"Add another value to group": "在分组中追加其他值 (OR)",
|
|
204
|
+
"Exclude value in group": "在分组中排除值",
|
|
205
|
+
"Combine another condition (both match)": "并且满足下一条件 (AND)",
|
|
206
|
+
"Match either condition": "或者满足另一条件 (OR)",
|
|
207
|
+
"Exclude next condition": "并且排除下一条件 (AND NOT)",
|
|
208
|
+
"Close condition group": "闭合条件括号",
|
|
209
|
+
"Test Connection": "测试连接",
|
|
210
|
+
"Connection verified": "连接已验证",
|
|
211
|
+
"Index-scoped role": "索引级受限权限",
|
|
212
|
+
"Configure Elasticsearch 8.x TLS, CA Fingerprint, API Key, or Bearer Token in Data Source Manager": "可在数据源管理中配置 Elasticsearch 8.x 的 TLS、CA 指纹、API 密钥或 Bearer 令牌"
|
|
213
|
+
}
|
|
@@ -0,0 +1,292 @@
|
|
|
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 type { Context } from '@nocobase/actions';
|
|
11
|
+
import type { FlowModelRepository } from '../../../../@nocobase/plugin-flow-engine/src/server/repository';
|
|
12
|
+
import { createMockServer, type MockServer } from '@nocobase/test';
|
|
13
|
+
import { afterAll, beforeAll, describe, expect, it, vi } from 'vitest';
|
|
14
|
+
import { REPORT_DESTINATION_CONTEXT } from '../../shared/constants';
|
|
15
|
+
import PluginElasticReportServer from '../plugin';
|
|
16
|
+
|
|
17
|
+
describe('Elastic Report native AI tools', () => {
|
|
18
|
+
let app: MockServer;
|
|
19
|
+
beforeAll(async () => {
|
|
20
|
+
app = await createMockServer({
|
|
21
|
+
acl: true,
|
|
22
|
+
plugins: [
|
|
23
|
+
'error-handler',
|
|
24
|
+
'users',
|
|
25
|
+
'auth',
|
|
26
|
+
'client',
|
|
27
|
+
'ui-layout',
|
|
28
|
+
'field-sort',
|
|
29
|
+
'acl',
|
|
30
|
+
'ui-schema-storage',
|
|
31
|
+
'flow-engine',
|
|
32
|
+
'system-settings',
|
|
33
|
+
'data-source-main',
|
|
34
|
+
'data-source-manager',
|
|
35
|
+
[PluginElasticReportServer, { name: 'plugin-elastic-report' }],
|
|
36
|
+
],
|
|
37
|
+
});
|
|
38
|
+
await app.db.getRepository('roles').create({ values: { name: 'report-builder', snippets: ['pm.elastic-report'] } });
|
|
39
|
+
});
|
|
40
|
+
afterAll(async () => {
|
|
41
|
+
await app?.destroy();
|
|
42
|
+
});
|
|
43
|
+
it('adds the selected report to the attached tab once and checks both report and page permissions on retries', async () => {
|
|
44
|
+
const routes = app.db.getRepository('desktopRoutes');
|
|
45
|
+
const flows = app.db.getRepository<FlowModelRepository>('flowModels');
|
|
46
|
+
const uiLayouts = ['admin-layout-model'];
|
|
47
|
+
const page = await routes.create({ values: { type: 'flowPage', schemaUid: 'new-page', uiLayouts } });
|
|
48
|
+
const tabs = [];
|
|
49
|
+
for (const schemaUid of ['first-tab', 'target-tab']) {
|
|
50
|
+
tabs.push(await routes.create({ values: { type: 'tabs', parentId: page.get('id'), schemaUid, uiLayouts } }));
|
|
51
|
+
}
|
|
52
|
+
const dv = await app.db.getRepository('esReportDataViews').create({
|
|
53
|
+
values: { title: 'QA', dataSourceKey: 'qa', indexPattern: 'qa-*', allowedRoles: ['add-designer'] },
|
|
54
|
+
});
|
|
55
|
+
const reports = app.db.getRepository('esReports');
|
|
56
|
+
const report = await reports.create({
|
|
57
|
+
values: { title: 'Chosen', dataViewId: dv.get('id'), published: false, spec: { visualization: 'metric' } },
|
|
58
|
+
});
|
|
59
|
+
const target = { pageUid: 'new-page', tabUid: 'target-tab', reportId: report.get('id') };
|
|
60
|
+
const selection = { type: REPORT_DESTINATION_CONTEXT, uid: target.tabUid, content: target };
|
|
61
|
+
const tool = await app.aiManager.toolsManager.getTools('elastic-report-es_add_report_block');
|
|
62
|
+
expect(tool.defaultPermission).toBe('ASK');
|
|
63
|
+
const invoke = (role: string, args = target, workContext = [selection]) =>
|
|
64
|
+
tool.invoke(
|
|
65
|
+
{
|
|
66
|
+
state: { currentUser: { id: 7 }, currentRole: role, currentRoles: [role] },
|
|
67
|
+
action: { params: { values: { messages: [{ role: 'user', workContext }] } } },
|
|
68
|
+
} as unknown as Context,
|
|
69
|
+
args,
|
|
70
|
+
{ toolCallId: 'add', writer: vi.fn() },
|
|
71
|
+
);
|
|
72
|
+
for (const role of ['add-designer', 'add-viewer']) {
|
|
73
|
+
await app.db
|
|
74
|
+
.getRepository('roles')
|
|
75
|
+
.create({ values: { name: role, snippets: role === 'add-designer' ? ['ui.flowModels'] : [] } });
|
|
76
|
+
for (const route of [page, tabs[0]]) {
|
|
77
|
+
await app.db
|
|
78
|
+
.getRepository('rolesDesktopRoutes')
|
|
79
|
+
.create({ values: { roleName: role, desktopRouteId: route.get('id') } });
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
await expect(invoke('add-designer')).rejects.toMatchObject({ status: 403 });
|
|
83
|
+
for (const roleName of ['add-designer', 'add-viewer']) {
|
|
84
|
+
await app.db
|
|
85
|
+
.getRepository('rolesDesktopRoutes')
|
|
86
|
+
.create({ values: { roleName, desktopRouteId: tabs[1].get('id') } });
|
|
87
|
+
}
|
|
88
|
+
await expect(invoke('add-designer')).rejects.toMatchObject({ status: 403 }); // draft
|
|
89
|
+
await reports.update({ filterByTk: report.get('id'), values: { published: true } });
|
|
90
|
+
await expect(invoke('add-viewer')).rejects.toMatchObject({ status: 403 });
|
|
91
|
+
await expect(invoke('add-designer', target, [])).rejects.toMatchObject({ status: 400 });
|
|
92
|
+
await expect(invoke('add-designer', target, [selection, selection])).rejects.toMatchObject({ status: 400 });
|
|
93
|
+
await expect(invoke('add-designer', { ...target, tabUid: 'first-tab' })).rejects.toMatchObject({ status: 400 });
|
|
94
|
+
await expect(invoke('add-designer', { ...target, reportId: 'other' })).rejects.toMatchObject({ status: 400 });
|
|
95
|
+
const wrongPage = { ...target, pageUid: 'another-page' };
|
|
96
|
+
await expect(invoke('add-designer', wrongPage, [{ ...selection, content: wrongPage }])).rejects.toMatchObject({
|
|
97
|
+
status: 403,
|
|
98
|
+
});
|
|
99
|
+
expect(await flows.findModelByParentId('target-tab', { subKey: 'grid' })).toBeNull();
|
|
100
|
+
const results = app.db.inDialect('sqlite')
|
|
101
|
+
? [await invoke('add-designer'), await invoke('add-designer')]
|
|
102
|
+
: await Promise.all([invoke('add-designer'), invoke('add-designer')]);
|
|
103
|
+
expect(results.map((x) => x.created).sort()).toEqual([false, true]);
|
|
104
|
+
const { gridUid, blockUid } = results[0];
|
|
105
|
+
expect(results[1]).toMatchObject({ ...target, gridUid, blockUid });
|
|
106
|
+
const grid = await flows.findModelByParentId('target-tab', { subKey: 'grid' });
|
|
107
|
+
expect(grid.subModels.items).toHaveLength(1);
|
|
108
|
+
expect(grid.subModels.items[0]).toMatchObject({
|
|
109
|
+
uid: blockUid,
|
|
110
|
+
use: 'ElasticReportBlockModel',
|
|
111
|
+
stepParams: { elasticReportBlockSettings: { editReport: { reportId: report.get('id') } } },
|
|
112
|
+
});
|
|
113
|
+
expect(await flows.findModelByParentId('first-tab', { subKey: 'grid' })).toBeNull();
|
|
114
|
+
await app.db
|
|
115
|
+
.getRepository('esReportDataViews')
|
|
116
|
+
.update({ filterByTk: dv.get('id'), values: { allowedRoles: ['finance'] } });
|
|
117
|
+
await expect(invoke('add-designer')).rejects.toMatchObject({ status: 403 });
|
|
118
|
+
});
|
|
119
|
+
it('saves native-tool drafts in Settings and reconfigures only the picked block on its authorized page', async () => {
|
|
120
|
+
const pick = [{ type: 'flow-model', uid: 'picked' }];
|
|
121
|
+
const context = (role: string, workContext = pick) =>
|
|
122
|
+
({
|
|
123
|
+
state: { currentUser: { id: 1 }, currentRole: role, currentRoles: [role] },
|
|
124
|
+
action: { params: { values: { messages: [{ role: 'user', workContext }] } } },
|
|
125
|
+
}) as unknown as Context;
|
|
126
|
+
const invoke = async (name: string, ctx: Context, args: Record<string, unknown>) => {
|
|
127
|
+
const tool = await app.aiManager.toolsManager.getTools('elastic-report-es_' + name);
|
|
128
|
+
return tool.invoke(ctx, args, { toolCallId: 'test', writer: vi.fn() });
|
|
129
|
+
};
|
|
130
|
+
const dataView = await app.db.getRepository('esReportDataViews').create({
|
|
131
|
+
values: { title: 'Native tool view', dataSourceKey: 'es_logs_cluster', indexPattern: 'logs-*' },
|
|
132
|
+
});
|
|
133
|
+
const builder = context('report-builder');
|
|
134
|
+
const inputs = { title: 'Native tool draft', dataViewId: dataView.get('id'), spec: { visualization: 'table' } };
|
|
135
|
+
await expect(invoke('save_report', context('report-viewer'), inputs)).rejects.toMatchObject({ status: 403 });
|
|
136
|
+
const { report } = await invoke('save_report', builder, { ...inputs, published: false, description: 'Keep me' });
|
|
137
|
+
const updated = await invoke('save_report', builder, { ...inputs, id: report.id, title: 'Updated draft' });
|
|
138
|
+
expect(updated.report).toMatchObject({ published: false, description: 'Keep me' });
|
|
139
|
+
const persisted = await app.db.getRepository('esReports').findOne({ filterByTk: report.id });
|
|
140
|
+
expect(persisted.toJSON()).toMatchObject({ title: 'Updated draft', published: false });
|
|
141
|
+
|
|
142
|
+
const routes = app.db.getRepository('desktopRoutes');
|
|
143
|
+
const uiLayouts = ['admin-layout-model'];
|
|
144
|
+
const page = await routes.create({ values: { type: 'flowPage', schemaUid: 'sales', title: 'Sales', uiLayouts } });
|
|
145
|
+
const tab = await routes.create({
|
|
146
|
+
values: { type: 'tabs', schemaUid: 'sales-tab', parentId: page.get('id'), uiLayouts },
|
|
147
|
+
});
|
|
148
|
+
const flows = app.db.getRepository<FlowModelRepository>('flowModels');
|
|
149
|
+
const stepParams = {
|
|
150
|
+
anotherFlow: { anotherStep: { keep: true } },
|
|
151
|
+
elasticReportBlockSettings: { editReport: { reportId: report.id } },
|
|
152
|
+
};
|
|
153
|
+
await flows.upsertModel({
|
|
154
|
+
uid: 'sales-tab',
|
|
155
|
+
use: 'RootPageTabModel',
|
|
156
|
+
subModels: {
|
|
157
|
+
grid: {
|
|
158
|
+
uid: 'grid',
|
|
159
|
+
use: 'BlockGridModel',
|
|
160
|
+
subModels: {
|
|
161
|
+
items: ['picked', 'sibling', 'empty'].map((uid) => ({
|
|
162
|
+
uid,
|
|
163
|
+
use: 'ElasticReportBlockModel',
|
|
164
|
+
stepParams: uid === 'empty' ? {} : stepParams,
|
|
165
|
+
})),
|
|
166
|
+
},
|
|
167
|
+
},
|
|
168
|
+
},
|
|
169
|
+
});
|
|
170
|
+
await app.db.getRepository('roles').create({ values: { name: 'block-designer', snippets: ['ui.flowModels'] } });
|
|
171
|
+
const designer = context('block-designer');
|
|
172
|
+
const args = {
|
|
173
|
+
blockUid: 'picked',
|
|
174
|
+
pageUid: 'sales',
|
|
175
|
+
expected: { showToolbar: true },
|
|
176
|
+
changes: { showToolbar: false },
|
|
177
|
+
};
|
|
178
|
+
await expect(invoke('describe_block', designer, { blockUid: 'picked' })).rejects.toMatchObject({ status: 403 });
|
|
179
|
+
for (const roleName of ['block-designer', 'report-builder']) {
|
|
180
|
+
await app.db.getRepository('rolesDesktopRoutes').firstOrCreate({
|
|
181
|
+
filterKeys: ['roleName', 'desktopRouteId'],
|
|
182
|
+
values: { roleName, desktopRouteId: page.get('id') },
|
|
183
|
+
});
|
|
184
|
+
await app.db.getRepository('rolesDesktopRoutes').firstOrCreate({
|
|
185
|
+
filterKeys: ['roleName', 'desktopRouteId'],
|
|
186
|
+
values: { roleName, desktopRouteId: tab.get('id') },
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
expect(await invoke('describe_block', designer, { blockUid: 'picked' })).toMatchObject({
|
|
190
|
+
pageUid: 'sales',
|
|
191
|
+
canConfigure: true,
|
|
192
|
+
settings: { reportId: null, showToolbar: true },
|
|
193
|
+
});
|
|
194
|
+
await expect(
|
|
195
|
+
invoke('configure_block', designer, { ...args, changes: { reportId: report.id }, expected: { reportId: null } }),
|
|
196
|
+
).rejects.toMatchObject({ status: 403 });
|
|
197
|
+
await invoke('save_report', builder, { ...inputs, id: report.id, published: true });
|
|
198
|
+
const empty = context('block-designer', [{ type: 'flow-model', uid: 'empty' }]);
|
|
199
|
+
const bind = {
|
|
200
|
+
blockUid: 'empty',
|
|
201
|
+
pageUid: 'sales',
|
|
202
|
+
expected: { reportId: null },
|
|
203
|
+
changes: { reportId: report.id },
|
|
204
|
+
};
|
|
205
|
+
await invoke('configure_block', empty, bind);
|
|
206
|
+
expect((await flows.findModelById('empty')).stepParams.elasticReportBlockSettings.editReport.reportId).toBe(
|
|
207
|
+
report.id,
|
|
208
|
+
);
|
|
209
|
+
await invoke('save_report', builder, { ...inputs, id: report.id, allowedRoles: ['finance-viewer'] });
|
|
210
|
+
await expect(invoke('configure_block', empty, bind)).rejects.toMatchObject({ status: 403 });
|
|
211
|
+
await expect(invoke('configure_block', builder, args)).rejects.toMatchObject({ status: 403 });
|
|
212
|
+
await expect(invoke('configure_block', designer, { ...args, pageUid: 'wrong' })).rejects.toMatchObject({
|
|
213
|
+
status: 403,
|
|
214
|
+
});
|
|
215
|
+
await expect(invoke('configure_block', designer, { ...args, blockUid: 'sibling' })).rejects.toMatchObject({
|
|
216
|
+
status: 400,
|
|
217
|
+
});
|
|
218
|
+
await expect(invoke('configure_block', context('block-designer', []), args)).rejects.toMatchObject({ status: 400 });
|
|
219
|
+
await invoke('configure_block', designer, args);
|
|
220
|
+
await invoke('configure_block', designer, args);
|
|
221
|
+
const picked = await flows.findModelById('picked');
|
|
222
|
+
expect(picked.stepParams).toEqual({
|
|
223
|
+
...stepParams,
|
|
224
|
+
elasticReportBlockSettings: { editReport: { reportId: report.id, showToolbar: false } },
|
|
225
|
+
});
|
|
226
|
+
expect((await flows.findModelById('sibling')).stepParams).toEqual(stepParams);
|
|
227
|
+
await expect(
|
|
228
|
+
invoke('configure_block', designer, {
|
|
229
|
+
...args,
|
|
230
|
+
changes: { use: 'OtherModel' },
|
|
231
|
+
expected: { use: 'ElasticReportBlockModel' },
|
|
232
|
+
}),
|
|
233
|
+
).rejects.toMatchObject({ status: 400 });
|
|
234
|
+
await expect(
|
|
235
|
+
invoke('configure_block', designer, { ...args, expected: { syncGroup: 'stale' }, changes: { syncGroup: 'new' } }),
|
|
236
|
+
).rejects.toMatchObject({ status: 409 });
|
|
237
|
+
|
|
238
|
+
// ASK resumes from the stored user turn, even if another user message has since selected the sibling.
|
|
239
|
+
for (const [name, fields] of Object.entries({
|
|
240
|
+
aiConversations: [
|
|
241
|
+
{ name: 'sessionId', type: 'string' },
|
|
242
|
+
{ name: 'userId', type: 'integer' },
|
|
243
|
+
],
|
|
244
|
+
aiMessages: [
|
|
245
|
+
{ name: 'sessionId', type: 'string' },
|
|
246
|
+
{ name: 'messageId', type: 'integer' },
|
|
247
|
+
{ name: 'role', type: 'string' },
|
|
248
|
+
{ name: 'workContext', type: 'json' },
|
|
249
|
+
],
|
|
250
|
+
})) {
|
|
251
|
+
await app.db.collection({ name, fields }).model.sync();
|
|
252
|
+
}
|
|
253
|
+
await app.db.getRepository('aiConversations').create({ values: { sessionId: 'chat', userId: 1 } });
|
|
254
|
+
await app.db.getRepository('aiMessages').create({
|
|
255
|
+
values: [
|
|
256
|
+
{ sessionId: 'chat', messageId: 10, role: 'user', workContext: pick },
|
|
257
|
+
{ sessionId: 'chat', messageId: 11, role: 'assistant' },
|
|
258
|
+
{ sessionId: 'chat', messageId: 12, role: 'user', workContext: [{ type: 'flow-model', uid: 'sibling' }] },
|
|
259
|
+
],
|
|
260
|
+
});
|
|
261
|
+
const resumed = context('block-designer');
|
|
262
|
+
resumed.action.params.values = { sessionId: 'chat', messageId: 11 };
|
|
263
|
+
await invoke('configure_block', resumed, { ...args, changes: { compact: true }, expected: { compact: false } });
|
|
264
|
+
expect((await flows.findModelById('picked')).stepParams.elasticReportBlockSettings.editReport.compact).toBe(true);
|
|
265
|
+
await expect(invoke('configure_block', resumed, { ...args, blockUid: 'sibling' })).rejects.toMatchObject({
|
|
266
|
+
status: 400,
|
|
267
|
+
});
|
|
268
|
+
resumed.state.currentUser.id = 2;
|
|
269
|
+
await expect(invoke('configure_block', resumed, args)).rejects.toMatchObject({ status: 400 });
|
|
270
|
+
const destination = { pageUid: 'sales', tabUid: 'sales-tab', reportId: report.id };
|
|
271
|
+
await app.db.getRepository('aiMessages').create({
|
|
272
|
+
values: {
|
|
273
|
+
sessionId: 'chat',
|
|
274
|
+
messageId: 14,
|
|
275
|
+
role: 'user',
|
|
276
|
+
workContext: [{ type: REPORT_DESTINATION_CONTEXT, uid: destination.tabUid, content: destination }],
|
|
277
|
+
},
|
|
278
|
+
});
|
|
279
|
+
await app.db.getRepository('aiMessages').create({
|
|
280
|
+
values: { sessionId: 'chat', messageId: 16, role: 'user', workContext: [] },
|
|
281
|
+
});
|
|
282
|
+
resumed.action.params.values = { sessionId: 'chat', messageId: 15 };
|
|
283
|
+
await expect(invoke('add_report_block', resumed, destination)).rejects.toMatchObject({ status: 400 });
|
|
284
|
+
resumed.state.currentUser.id = 1;
|
|
285
|
+
await expect(invoke('add_report_block', resumed, destination)).rejects.toMatchObject({ status: 403 });
|
|
286
|
+
await invoke('save_report', builder, { ...inputs, id: report.id, allowedRoles: ['block-designer'] });
|
|
287
|
+
expect(await invoke('add_report_block', resumed, destination)).toMatchObject({ ...destination, created: false });
|
|
288
|
+
expect((await flows.findModelById('grid')).subModels.items).toHaveLength(3);
|
|
289
|
+
await app.db.getRepository('desktopRoutesUiLayouts').destroy({ filter: { desktopRouteId: tab.get('id') } });
|
|
290
|
+
await expect(invoke('configure_block', designer, args)).rejects.toMatchObject({ status: 403 });
|
|
291
|
+
});
|
|
292
|
+
});
|