@hedeqiang/dsh-nl2sql 0.0.0-stage → 0.11.1
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/CHANGELOG.md +52 -0
- package/LICENSE +21 -0
- package/README.en.md +63 -0
- package/README.md +88 -2
- package/analysis.js +888 -0
- package/channels/dingtalk.js +574 -0
- package/channels/http.js +63 -0
- package/channels/index.js +138 -0
- package/channels/lark.js +1180 -0
- package/channels/message.js +267 -0
- package/channels/telegram.js +663 -0
- package/channels/wecom.js +585 -0
- package/cordis.patch.yml +68 -0
- package/docs/CHANNELS.md +184 -0
- package/drivers.js +694 -0
- package/filters.js +237 -0
- package/icon.svg +13 -0
- package/im.js +8 -0
- package/index.js +658 -0
- package/lark-bot.js +9 -0
- package/lib/client.echarts.js +57 -0
- package/lib/client.js +5757 -0
- package/locale/en.json +1 -0
- package/locale/zh.json +1 -0
- package/package.json +95 -4
- package/policy.js +362 -0
- package/service/access.js +239 -0
- package/service/admin.js +555 -0
- package/service/alerts.js +233 -0
- package/service/bots.js +665 -0
- package/service/channels.js +363 -0
- package/service/dashboards.js +359 -0
- package/service/datasources.js +415 -0
- package/service/evaluation.js +121 -0
- package/service/push.js +163 -0
- package/service/query.js +411 -0
- package/service/schema.js +507 -0
- package/service/shared.js +424 -0
- package/service/suggestions.js +772 -0
- package/service/uploads.js +258 -0
- package/sql-guard.js +222 -0
- package/sqlite-driver.js +677 -0
- package/store.js +225 -0
- package/xlsx.js +1001 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# 更新日志
|
|
2
|
+
|
|
3
|
+
格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/),版本号遵循 [语义化版本](https://semver.org/lang/zh-CN/)。
|
|
4
|
+
|
|
5
|
+
## [未发布]
|
|
6
|
+
|
|
7
|
+
## [0.11.1] - 2026-11-12
|
|
8
|
+
|
|
9
|
+
### 修复
|
|
10
|
+
- 中文界面下渠道类型、配置说明、推荐问题等显示为英文:读取 Harness 语言设置的方式有误(LocaleSnapshot 的 `active` 字段),已修正并加了回归测试。
|
|
11
|
+
|
|
12
|
+
### 新增
|
|
13
|
+
- GitHub Actions 发布流程:推送 `v*` 版本标签后自动检查、打包,并通过 npm 可信发布(OIDC,带来源证明)发布到 npm,同时创建 GitHub Release。
|
|
14
|
+
|
|
15
|
+
## [0.11.0] - 2026-11-12
|
|
16
|
+
|
|
17
|
+
### 新增
|
|
18
|
+
- 渠道架构:IM 平台改为适配器(`channels/`),统一的消息模型、能力声明、表单定义和机器人接口,详见 [docs/CHANNELS.md](docs/CHANNELS.md)。
|
|
19
|
+
- 新平台:Telegram(推送、长轮询机器人、按钮)、企业微信(群机器人推送;智能机器人长连接问答与推送)、钉钉(自定义机器人推送;企业内部应用机器人 Stream 模式问答与推送)。以上新平台仅用模拟服务测试,尚未在真实账号上验证。
|
|
20
|
+
- 成员身份支持多平台(`identities`),机器人按渠道配置,可同时运行多个。
|
|
21
|
+
- 页面:「渠道」按平台分组、两步添加(选平台与类型 → 按表单填写),能力标签、配置步骤、选择群聊、测试;成员页「机器人」总览;成员身份编辑;设置「渠道与机器人」。
|
|
22
|
+
- 问答页「试试这些问题」支持「换一批」;删除单条历史记录;「最近的提问」可删除并支持「显示更多」。
|
|
23
|
+
|
|
24
|
+
### 兼容
|
|
25
|
+
- 旧的飞书渠道、机器人配置、成员字段和设置在首次加载时自动迁移;旧的 RPC 与数据格式继续可用。
|
|
26
|
+
|
|
27
|
+
## [0.10.0] - 2026-11-12
|
|
28
|
+
|
|
29
|
+
### 新增
|
|
30
|
+
- 飞书回复卡片上的交互按钮:按维度拆分、为什么变化、明细、固定到看板(经长连接回传,服务端校验权限)。
|
|
31
|
+
- 业务知识「建议」:从 👍 反馈、重复出现的查询、常用聚合和取值映射中自动生成样例、指标、备注和词表建议,人工确认后采纳。
|
|
32
|
+
- 开源准备:MIT 许可证、README、贡献指南、安全策略、CI。
|
|
33
|
+
|
|
34
|
+
### 修复
|
|
35
|
+
- `token_code` 等加密货币业务字段不再被误判为敏感字段。
|
|
36
|
+
- 评测比对能识别同一组数字的不同排布(一行多列 / 多行一列)。
|
|
37
|
+
|
|
38
|
+
## [0.9.0] - 2026-11-12
|
|
39
|
+
- 页面改为 5 个常用页签 + 「管理」区;设置分组(说明、未保存提示、恢复默认、配置导出导入)。
|
|
40
|
+
- 首次使用引导;问答页推荐问题与最近提问。
|
|
41
|
+
- 看板拖拽排序、三档宽度、刷新与缓存状态;页面内提示替代浏览器弹窗;英文界面完整翻译。
|
|
42
|
+
- 上传分块暂存;MySQL / PostgreSQL 大结果流式截断;大库按问题挑选相关表;日志保留条数可配置。
|
|
43
|
+
|
|
44
|
+
## [0.8.0] - 2026-11-12
|
|
45
|
+
- 只读角色、行级权限、调度器补查与状态、日志迁移到 SQLite、代码拆分为 `service/` 与 `client-src/`、测试套件。
|
|
46
|
+
- 安全修复:按方言词法的只读检查(修复 PostgreSQL 可写入问题)、访问控制绕过、飞书成员数据源范围、飞书回答错位。
|
|
47
|
+
|
|
48
|
+
## [0.7.0] - 2026-11-11
|
|
49
|
+
- 指标告警、飞书 @机器人问答、下钻与归因、准确率评测、表结构变更检测、指标工具、多看板、Excel 导出、CSV / Excel 上传、结果持久化与缓存、业务知识导入导出、多用户权限与审计。
|
|
50
|
+
|
|
51
|
+
## [0.6.0] 及更早
|
|
52
|
+
- 界面重设计;飞书推送(Markdown 与原生图表);访问控制、反馈闭环、看板全局筛选;PostgreSQL / Elasticsearch、SSH 隧道、隐私设置、自动概览、定时报告;语义层、关系图、扫描保护、历史与审计、看板;MVP。
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 hedeqiang
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.en.md
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
# dsh-nl2sql · Data Q&A
|
|
2
|
+
|
|
3
|
+
An enterprise NL2SQL plugin for DeepSeek Harness: connect databases, ask in plain language, and the agent writes read-only SQL, runs it and charts the result in the conversation. Pin results to dashboards, push them to Lark / Feishu, or ask the bot directly in a Lark group.
|
|
4
|
+
|
|
5
|
+
[中文](README.md)
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- **Data sources:** MySQL 5.7+, PostgreSQL, Elasticsearch SQL (optionally over SSH), and CSV / Excel uploads stored as local SQLite.
|
|
10
|
+
- **Schema analysis:** table roles, column semantics (time / measure / enum / sensitive), inferred relations, ER view.
|
|
11
|
+
- **Asking:** in a Harness conversation through the `nl2sql_*` tools; results render as ECharts charts or tables.
|
|
12
|
+
- **Drill-down and "why did it change":** split by a dimension, show rows, rank dimensions by their contribution to a change.
|
|
13
|
+
- **Metric library and business knowledge:** glossary, governed metrics (`nl2sql_metric`), column notes, verified examples; import / export; accuracy evaluation against the examples.
|
|
14
|
+
- **Dashboards:** multiple boards, global filters, drag-to-reorder, three widths, snapshots, Excel export.
|
|
15
|
+
- **Channels:** Lark / Feishu, Telegram, WeCom and DingTalk through pluggable adapters ([docs/CHANNELS.md](docs/CHANNELS.md)); push Markdown and results (native charts, images or tables per platform), and @-mention bots that need no public URL.
|
|
16
|
+
- **Automation:** scheduled reports, metric alerts (threshold / change / anomaly / missing), schema change detection.
|
|
17
|
+
- **Safety:**
|
|
18
|
+
- read-only admission with per-dialect lexing, read-only transactions, server-side timeouts, streamed truncation;
|
|
19
|
+
- table / column access policies with masking, full-scan guard;
|
|
20
|
+
- member scopes, viewer role and row-level rules for Lark users;
|
|
21
|
+
- a setting for what result data reaches the model (column statistics by default); audit attributed to people.
|
|
22
|
+
|
|
23
|
+
## Install
|
|
24
|
+
|
|
25
|
+
Requires DeepSeek Harness (desktop or `dsh web`).
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
git clone <this repo> dsh-nl2sql && cd dsh-nl2sql
|
|
29
|
+
pnpm install --ignore-scripts
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
Install the directory as a bundle (plugin manager `install_bundle` with the absolute path), or add `@hedeqiang/dsh-nl2sql` to your profile's `dsh.profile.bundles` with a `link:` dependency. Once published, install `@hedeqiang/dsh-nl2sql` from npm.
|
|
33
|
+
|
|
34
|
+
## Use
|
|
35
|
+
|
|
36
|
+
1. Sidebar → **Data Q&A** → **Manage → Data sources**: add a database (a read-only account is recommended) or upload a file.
|
|
37
|
+
2. **Schema** → analyze.
|
|
38
|
+
3. Ask on the **Ask** page, or pick the Data Q&A preset in any conversation.
|
|
39
|
+
4. Pin useful charts to a **Dashboard**; add glossary terms, metrics and examples under **Knowledge**.
|
|
40
|
+
5. **Manage → Push channels / Alerts & reports / Members & access** for Lark push, automation and the Lark bot.
|
|
41
|
+
|
|
42
|
+
## Data and privacy
|
|
43
|
+
|
|
44
|
+
- **Configuration:** `~/.dsh/nl2sql/state.json`.
|
|
45
|
+
- **Results, cache and logs:** `~/.dsh/nl2sql/results.sqlite`.
|
|
46
|
+
- **Uploaded files:** `~/.dsh/nl2sql/files/`.
|
|
47
|
+
- **Passwords and app secrets:** the Harness credential store.
|
|
48
|
+
- **What reaches the model:** **Settings → Data shown to the model** decides this; by default it is schema, enum values and per-column result statistics.
|
|
49
|
+
- **Lark:** content pushed to Lark leaves the machine.
|
|
50
|
+
|
|
51
|
+
## Development
|
|
52
|
+
|
|
53
|
+
```bash
|
|
54
|
+
npm test # whole suite; local MySQL / PostgreSQL optional (skipped when absent)
|
|
55
|
+
npm test -- --fast # unit + UI tests only
|
|
56
|
+
node scripts/build-client.mjs # regenerate lib/client.js after editing client-src/
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
See [DEVELOPMENT.md](DEVELOPMENT.md) and [eval/README.md](eval/README.md).
|
|
60
|
+
|
|
61
|
+
## License
|
|
62
|
+
|
|
63
|
+
[MIT](LICENSE)
|
package/README.md
CHANGED
|
@@ -1,3 +1,89 @@
|
|
|
1
|
-
#
|
|
1
|
+
# dsh-nl2sql · 数据问答
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[DeepSeek Harness](https://github.com/deepseek-ai) 的企业级 NL2SQL 插件:连接数据库,用自然语言提问,Agent 写只读 SQL、执行并在对话中画图;结果可以固定到看板、推送到飞书,还能在飞书群里直接 @机器人提问。
|
|
4
|
+
|
|
5
|
+
[English](README.en.md)
|
|
6
|
+
|
|
7
|
+
## 功能
|
|
8
|
+
|
|
9
|
+
**问答与分析**
|
|
10
|
+
- 数据源:MySQL 5.7+、PostgreSQL、Elasticsearch(SQL),支持 SSH 隧道;也可以上传 CSV / Excel(存为本机 SQLite)。
|
|
11
|
+
- 表结构分析:识别表的角色、字段语义(时间 / 度量 / 枚举 / 敏感)、推断表间关系,提供关系图。
|
|
12
|
+
- 自然语言提问:在 Harness 对话中进行,Agent 使用 `nl2sql_*` 工具查询,结果在对话中渲染为 ECharts 图表或表格。
|
|
13
|
+
- 下钻与归因:按维度拆分、查看明细、「为什么变化」——比较两个时段并按维度贡献排序。
|
|
14
|
+
- 指标库与业务知识:词表、指标口径(Agent 用 `nl2sql_metric` 按口径查询)、字段备注、样例问答;支持导入导出。
|
|
15
|
+
- 准确率评测:用样例问答作为评测集,Agent 从零作答后与样例结果比对。
|
|
16
|
+
|
|
17
|
+
**看板与推送**
|
|
18
|
+
- 多看板、全局筛选(时间范围 / 维度)、拖拽排序、三档宽度、快照、Excel 导出。
|
|
19
|
+
- IM 渠道:飞书 / Lark、Telegram、企业微信、钉钉(推送 Markdown 与结果,图表按平台能力用原生图表、图片或表格);架构见 [docs/CHANNELS.md](docs/CHANNELS.md),新增平台只需实现一个适配器。
|
|
20
|
+
- 定时报告(基于 Harness 定时任务)、指标告警(阈值 / 环比 / 异常 / 无数据)、表结构变更检测。
|
|
21
|
+
- 群聊 @机器人提问:飞书长连接、Telegram 长轮询、企业微信智能机器人长连接、钉钉 Stream 模式,都不需要公网地址。
|
|
22
|
+
|
|
23
|
+
**安全与治理**
|
|
24
|
+
- 只读执行:按方言词法检查语句(MySQL / PostgreSQL / SQLite / ES),只读事务,PostgreSQL 使用扩展协议拒绝多语句,服务端超时,大结果流式截断。
|
|
25
|
+
- 访问控制:按表允许 / 排除、隐藏列、脱敏列;大表全表扫描保护。
|
|
26
|
+
- 成员与权限:飞书用户 / 群的数据源范围、只读角色(只能用指标库、已验证样例和看板)、行级权限(自动注入过滤,无法安全改写的查询直接拒绝)。
|
|
27
|
+
- 隐私:可设置发给模型的内容(不发 / 统计摘要 / 前 N 行),敏感字段默认脱敏;审计记录归属到具体的人。
|
|
28
|
+
|
|
29
|
+
## 安装
|
|
30
|
+
|
|
31
|
+
需要 DeepSeek Harness 桌面版或 `dsh web`。
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
# 从源码(开发)
|
|
35
|
+
git clone <this repo> dsh-nl2sql && cd dsh-nl2sql
|
|
36
|
+
pnpm install --ignore-scripts # 依赖:mysql2、pg、ssh2、echarts、@larksuiteoapi/node-sdk、@resvg/resvg-js
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
然后在 Harness 中让 Agent 安装本地目录(插件管理器 `install_bundle`,目标为本目录的绝对路径),或在 profile 的 `package.json` 中加入:
|
|
40
|
+
|
|
41
|
+
```json
|
|
42
|
+
{ "dsh": { "profile": { "bundles": ["@hedeqiang/dsh-nl2sql"] } },
|
|
43
|
+
"dependencies": { "@hedeqiang/dsh-nl2sql": "link:/path/to/dsh-nl2sql" } }
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
发布到 npm 后可直接安装 `@hedeqiang/dsh-nl2sql`。
|
|
47
|
+
|
|
48
|
+
## 使用
|
|
49
|
+
|
|
50
|
+
1. 左侧栏打开「数据问答」→「管理 → 数据源」,添加数据库(建议使用只读账号)或上传文件。
|
|
51
|
+
2. 「表结构」→ 分析表结构。
|
|
52
|
+
3. 「问答」页提问,或在任意对话中选择「数据问答」预设直接提问。
|
|
53
|
+
4. 把满意的图表固定到「看板」;在「业务知识」补充词表、指标和样例,提高准确率。
|
|
54
|
+
5. 「管理 → 推送渠道」添加飞书机器人;「告警与报告」配置自动任务;「成员与权限」开通飞书群提问。
|
|
55
|
+
|
|
56
|
+
飞书应用机器人所需权限与长连接配置步骤见页面「成员与权限 → 飞书机器人 → 飞书开放平台配置步骤」。
|
|
57
|
+
|
|
58
|
+
## 数据与隐私
|
|
59
|
+
|
|
60
|
+
| 内容 | 位置 |
|
|
61
|
+
|---|---|
|
|
62
|
+
| 配置(数据源、看板、知识、告警、成员、设置) | `~/.dsh/nl2sql/state.json` |
|
|
63
|
+
| 查询结果、缓存、快照、日志(历史 / 审计 / 反馈 / 推送 / 告警) | `~/.dsh/nl2sql/results.sqlite` |
|
|
64
|
+
| 上传的文件 | `~/.dsh/nl2sql/files/` |
|
|
65
|
+
| 数据库密码、飞书密钥 | Harness 凭据库 |
|
|
66
|
+
|
|
67
|
+
发给模型的内容由「设置 → 模型可见数据」决定:默认只发表结构、枚举字段取值和查询结果的统计摘要,不发明细行。推送到飞书的内容会离开本机。
|
|
68
|
+
|
|
69
|
+
## 开发
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
npm test # 全部测试(需要 Harness 桌面版作为 Node 运行时;本机 MySQL / PostgreSQL 可选,不可用时跳过)
|
|
73
|
+
npm test -- --fast # 仅单元测试和界面测试
|
|
74
|
+
node scripts/build-client.mjs # 修改 client-src/ 后生成 lib/client.js
|
|
75
|
+
node scripts/build-echarts.mjs
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
目录结构与约定见 [DEVELOPMENT.md](DEVELOPMENT.md);隔离的准确率评测环境见 [eval/README.md](eval/README.md)。
|
|
79
|
+
|
|
80
|
+
## 已知限制
|
|
81
|
+
|
|
82
|
+
- 告警和每日表结构检查在 Harness 进程内调度:Harness 关闭期间不检查,重新打开后补查一次。
|
|
83
|
+
- 行级权限只对飞书成员生效;本机页面始终是所有者权限,没有登录机制。
|
|
84
|
+
- 行级权限下不支持子查询、CTE、UNION(会被拒绝)。
|
|
85
|
+
- 不支持旧版 `.xls`。
|
|
86
|
+
|
|
87
|
+
## 许可证
|
|
88
|
+
|
|
89
|
+
[MIT](LICENSE)
|