@yejiming/dsh-data-agent 0.0.6 → 0.0.10

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 (39) hide show
  1. package/README.en.md +142 -119
  2. package/README.md +138 -118
  3. package/cordis.patch.yml +8 -9
  4. package/lib/client.js +42423 -524
  5. package/lib/client.js.map +1 -1
  6. package/lib/command-LFgLb6el.js +875 -0
  7. package/lib/command.js +2 -0
  8. package/lib/connections-WmjuUrDj.js +1608 -0
  9. package/lib/defaults-DP4RyRh1.js +21 -0
  10. package/lib/index.js +265 -68
  11. package/lib/routes.js +94 -170
  12. package/lib/tool-Dka6RyEp.js +1128 -0
  13. package/lib/tool.js +1 -426
  14. package/lib/types/analysis.d.ts +1071 -0
  15. package/lib/types/client/AnalysisChart.d.ts +26 -0
  16. package/lib/types/client/AnalysisDashboard.d.ts +30 -0
  17. package/lib/types/client/DataAgentWorkbench.d.ts +2 -2
  18. package/lib/types/client/analysis-charts.d.ts +40 -0
  19. package/lib/types/client/analysis-view-model.d.ts +44 -0
  20. package/lib/types/client/index.d.ts +3 -4
  21. package/lib/types/client/locales.d.ts +66 -0
  22. package/lib/types/client/persistence.d.ts +6 -1
  23. package/lib/types/client-discovery.d.ts +45 -0
  24. package/lib/types/clients.d.ts +17 -10
  25. package/lib/types/command.d.ts +41 -0
  26. package/lib/types/connections.d.ts +115 -40
  27. package/lib/types/defaults.d.ts +2 -0
  28. package/lib/types/index.d.ts +109 -63
  29. package/lib/types/routes.d.ts +25 -91
  30. package/lib/types/sql.d.ts +1 -1
  31. package/lib/types/storage.d.ts +70 -0
  32. package/lib/types/structured-read.d.ts +50 -0
  33. package/lib/types/tool.d.ts +29 -20
  34. package/lib/types/tui-connection-form.d.ts +98 -0
  35. package/package.json +65 -4
  36. package/preset/data-agent/agent.cordis.yml +22 -25
  37. package/preset/data-agent/preset.yml +1 -1
  38. package/lib/defaults-Bac6QvNt.js +0 -911
  39. package/lib/query-CmhTFklw.js +0 -86
@@ -0,0 +1,98 @@
1
+ /**
2
+ * Short-lived ANSI connection form used by `/database connect` in dsh-tui.
3
+ *
4
+ * dsh-tui 0.6.x exposes commands but no public custom-form/sensitive-input
5
+ * slot. This adapter therefore owns a small terminal form and only activates
6
+ * for an interactive `dsh-tui` profile. It snapshots the host's `readable`
7
+ * listeners, consumes input for the lifetime of the form, then restores the
8
+ * listeners exactly. It never imports dsh-tui, React, or Ink.
9
+ * @module @yejiming/dsh-data-agent/tui-connection-form
10
+ */
11
+ import type { ConnectionFormDraft, DatabaseConnectionInput, DatabaseType } from './connections.ts';
12
+ export declare const TUI_DATABASE_TYPES: readonly ["mysql", "postgres", "sqlite", "oracle", "hive", "impala"];
13
+ export type TuiConnectionField = 'type' | 'host' | 'port' | 'user' | 'database' | 'password' | 'readonly' | 'confirm' | 'cancel';
14
+ export interface TuiConnectionFormState {
15
+ type: DatabaseType;
16
+ host: string;
17
+ port: string;
18
+ user: string;
19
+ database: string;
20
+ password: string;
21
+ readonly: boolean;
22
+ focus: TuiConnectionField;
23
+ cursor: number;
24
+ selector?: {
25
+ field: 'type' | 'readonly';
26
+ index: number;
27
+ };
28
+ error?: string;
29
+ }
30
+ export type TuiFormKey = {
31
+ name: 'text';
32
+ text: string;
33
+ } | {
34
+ name: 'tab' | 'backtab' | 'enter' | 'escape' | 'backspace' | 'delete';
35
+ } | {
36
+ name: 'left' | 'right' | 'up' | 'down' | 'home' | 'end' | 'space';
37
+ };
38
+ export type TuiFormTransition = {
39
+ kind: 'editing';
40
+ state: TuiConnectionFormState;
41
+ } | {
42
+ kind: 'submitted';
43
+ state: TuiConnectionFormState;
44
+ input: DatabaseConnectionInput;
45
+ } | {
46
+ kind: 'cancelled';
47
+ state: TuiConnectionFormState;
48
+ };
49
+ type StreamListener = (...args: unknown[]) => void;
50
+ export interface TuiFormInput {
51
+ isTTY?: boolean;
52
+ isRaw?: boolean;
53
+ read(): unknown;
54
+ listeners(event: string): Function[];
55
+ on(event: string, listener: StreamListener): unknown;
56
+ emit?(event: string): unknown;
57
+ push?(value: string): unknown;
58
+ removeListener(event: string, listener: StreamListener): unknown;
59
+ setRawMode?(mode: boolean): unknown;
60
+ ref?(): unknown;
61
+ }
62
+ export interface TuiFormOutput {
63
+ isTTY?: boolean;
64
+ columns?: number;
65
+ write(value: string): unknown;
66
+ on?(event: string, listener: StreamListener): unknown;
67
+ removeListener?(event: string, listener: StreamListener): unknown;
68
+ emit?(event: string): unknown;
69
+ }
70
+ export interface RunTuiConnectionFormOptions {
71
+ input?: TuiFormInput;
72
+ output?: TuiFormOutput;
73
+ signal?: AbortSignal;
74
+ initialDraft?: ConnectionFormDraft;
75
+ persistDraft?: (draft: ConnectionFormDraft) => void | Promise<void>;
76
+ }
77
+ /** Initial form intentionally leaves host/port empty so placeholders are real defaults. */
78
+ export declare function createTuiConnectionFormState(initialDraft?: ConnectionFormDraft): TuiConnectionFormState;
79
+ /** Project form state onto the only values allowed to cross the durable seam. */
80
+ export declare function connectionFormDraft(state: TuiConnectionFormState): ConnectionFormDraft;
81
+ /** Relevant focus order for the selected database kind. */
82
+ export declare function tuiConnectionFields(type: DatabaseType): readonly TuiConnectionField[];
83
+ /** Default network port shown as a placeholder and applied only at submit time. */
84
+ export declare function defaultDatabasePort(type: Exclude<DatabaseType, 'sqlite'>): number;
85
+ /** Detect the supported host without coupling to dsh-tui modules. */
86
+ export declare function isDshTuiTerminal(argv?: readonly string[], input?: Pick<TuiFormInput, 'isTTY'>, output?: Pick<TuiFormOutput, 'isTTY'>): boolean;
87
+ /** Pure keyboard reducer, kept separate from terminal ownership for regression tests. */
88
+ export declare function updateTuiConnectionForm(current: TuiConnectionFormState, key: TuiFormKey): TuiFormTransition;
89
+ /** Rendered value is masked before it reaches the ANSI string. */
90
+ export declare function renderTuiConnectionForm(state: TuiConnectionFormState, columns?: number): string;
91
+ /**
92
+ * Own the terminal only for the form lifetime. `undefined` means user cancel.
93
+ * The returned password has never crossed stdout, argv, env, or a DSH event.
94
+ */
95
+ export declare function runTuiConnectionForm(options?: RunTuiConnectionFormOptions): Promise<DatabaseConnectionInput | undefined>;
96
+ /** Decode the keyboard subset owned by the form; unknown terminal reports are ignored. */
97
+ export declare function decodeTuiFormInput(value: string): TuiFormKey[];
98
+ export {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@yejiming/dsh-data-agent",
3
- "description": "Data Agent for the dsh web GUI: session-scoped database connections (MySQL/PostgreSQL/SQLite), the sqlcmd tool, the data-agent agent preset, and the database conversation-view tab",
4
- "version": "0.0.6",
3
+ "description": "Data Agent for DSH Web and TUI: shared database connections, a masked TUI form, secure credential references, SQL tools, and the data-agent preset",
4
+ "version": "0.0.10",
5
5
  "publishConfig": {
6
6
  "access": "public"
7
7
  },
@@ -28,6 +28,10 @@
28
28
  "types": "./lib/types/tool.d.ts",
29
29
  "default": "./lib/tool.js"
30
30
  },
31
+ "./command": {
32
+ "types": "./lib/types/command.d.ts",
33
+ "default": "./lib/command.js"
34
+ },
31
35
  "./invariant": {
32
36
  "types": "./lib/types/invariant.d.ts",
33
37
  "default": "./lib/invariant.js"
@@ -48,6 +52,7 @@
48
52
  "inject": [
49
53
  "@deepseek-ai/dsh-client-locale",
50
54
  "@deepseek-ai/dsh-client-runtime",
55
+ "@deepseek-ai/dsh-client-ui-tool",
51
56
  "@deepseek-ai/dsh-client-ui-conversation"
52
57
  ],
53
58
  "platform": "web"
@@ -67,36 +72,92 @@
67
72
  ],
68
73
  "license": "MIT",
69
74
  "dependencies": {
70
- "schemastery": "^3.18.0"
75
+ "echarts": "^6.1.0",
76
+ "schemastery": "^3.18.0",
77
+ "zod": "^4.4.3"
71
78
  },
72
79
  "peerDependencies": {
73
80
  "@deepseek-ai/cordis": "^4.0.1",
81
+ "@deepseek-ai/dsh-agent": "^0.1.0-rc.6",
82
+ "@deepseek-ai/dsh-agent-presets": "^0.1.0-rc.6",
74
83
  "@deepseek-ai/dsh-client-locale": "^0.1.0-rc.6",
75
84
  "@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.6",
76
85
  "@deepseek-ai/dsh-client-ui-conversation": "^0.1.0-rc.6",
77
86
  "@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.6",
78
87
  "@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.6",
88
+ "@deepseek-ai/dsh-client-ui-tool": "^0.1.0-rc.6",
89
+ "@deepseek-ai/dsh-commands": "^0.1.0-rc.6",
90
+ "@deepseek-ai/dsh-credentials": "^0.1.0-rc.6",
79
91
  "@deepseek-ai/dsh-host-webserver": "^0.1.0-rc.6",
80
92
  "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
93
+ "@deepseek-ai/dsh-scope": "^0.1.0-rc.6",
94
+ "@deepseek-ai/dsh-storage": "^0.1.0-rc.6",
95
+ "@deepseek-ai/dsh-storage-domain": "^0.1.0-rc.6",
96
+ "@deepseek-ai/dsh-storage-json": "^0.1.0-rc.6",
81
97
  "@deepseek-ai/dsh-subprocess": "^0.1.0-rc.6",
82
98
  "@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
83
- "react": "^18.2.0"
99
+ "@deepseek-ai/dsh-user-questions": "^0.1.0-rc.6",
100
+ "react": "^18.2.0 || ^19.0.0"
101
+ },
102
+ "peerDependenciesMeta": {
103
+ "@deepseek-ai/dsh-client-locale": {
104
+ "optional": true
105
+ },
106
+ "@deepseek-ai/dsh-client-runtime": {
107
+ "optional": true
108
+ },
109
+ "@deepseek-ai/dsh-client-ui-conversation": {
110
+ "optional": true
111
+ },
112
+ "@deepseek-ai/dsh-client-ui-primitives": {
113
+ "optional": true
114
+ },
115
+ "@deepseek-ai/dsh-client-ui-slots": {
116
+ "optional": true
117
+ },
118
+ "@deepseek-ai/dsh-host-webserver": {
119
+ "optional": true
120
+ },
121
+ "@deepseek-ai/dsh-user-questions": {
122
+ "optional": true
123
+ },
124
+ "react": {
125
+ "optional": true
126
+ },
127
+ "@deepseek-ai/dsh-client-ui-tool": {
128
+ "optional": true
129
+ }
84
130
  },
85
131
  "devDependencies": {
86
132
  "@deepseek-ai/cordis": "^4.0.1",
133
+ "@deepseek-ai/dsh-agent": "^0.1.0-rc.6",
134
+ "@deepseek-ai/dsh-agent-presets": "^0.1.0-rc.6",
87
135
  "@deepseek-ai/dsh-client-locale": "^0.1.0-rc.6",
88
136
  "@deepseek-ai/dsh-client-runtime": "^0.1.0-rc.6",
89
137
  "@deepseek-ai/dsh-client-ui-conversation": "^0.1.0-rc.6",
90
138
  "@deepseek-ai/dsh-client-ui-primitives": "^0.1.0-rc.6",
91
139
  "@deepseek-ai/dsh-client-ui-slots": "^0.1.0-rc.6",
140
+ "@deepseek-ai/dsh-client-ui-tool": "0.1.0-rc.6",
141
+ "@deepseek-ai/dsh-commands": "^0.1.0-rc.6",
142
+ "@deepseek-ai/dsh-credentials": "^0.1.0-rc.6",
92
143
  "@deepseek-ai/dsh-host-webserver": "^0.1.0-rc.6",
93
144
  "@deepseek-ai/dsh-invariants": "^0.1.0-rc.6",
145
+ "@deepseek-ai/dsh-scope": "^0.1.0-rc.6",
146
+ "@deepseek-ai/dsh-storage": "^0.1.0-rc.6",
147
+ "@deepseek-ai/dsh-storage-domain": "^0.1.0-rc.6",
148
+ "@deepseek-ai/dsh-storage-json": "^0.1.0-rc.6",
94
149
  "@deepseek-ai/dsh-subprocess": "^0.1.0-rc.6",
150
+ "@deepseek-ai/dsh-subprocess-local": "0.1.0-rc.6",
95
151
  "@deepseek-ai/dsh-tools": "^0.1.0-rc.6",
152
+ "@deepseek-ai/dsh-user-questions": "^0.1.0-rc.6",
153
+ "@testing-library/dom": "^10.4.1",
154
+ "@testing-library/react": "^16.3.2",
96
155
  "@types/node": "^25.0.0",
97
156
  "@types/react": "~18.3.1",
157
+ "jsdom": "^30.0.1",
98
158
  "lightningcss": "^1.32.0",
99
159
  "react": "^18.2.0",
160
+ "react-dom": "^18.3.1",
100
161
  "schemastery": "^3.18.0",
101
162
  "tsdown": "^0.22.2",
102
163
  "typescript": "^6.0.3",
@@ -8,15 +8,13 @@
8
8
  # the registries themselves, the sandbox and approval stack, persistence, and
9
9
  # the model route.
10
10
  #
11
- # A preset composes what an agent HAS instead of subtracting from a shared
12
- # default: every model-facing tool row absent from this file is simply not
13
- # registered for agents on this preset. The database row below registers
14
- # sql-query / sql-write / sqlcmd and the fs row registers read / write / edit;
15
- # bash, glob/grep, str_replace_editor, skill, todo, goal, plan, web, subagent,
16
- # workflow, tasks, and the rest are all absent, i.e. disabled.
11
+ # The editor row registers DSH's native str_replace_editor. The database tools,
12
+ # /database command, and inherited-tool restriction are statically imported by
13
+ # the profile's `@yejiming/dsh-data-agent` bundle entry and registered under
14
+ # this preset's standing key. Selecting the preset therefore performs no
15
+ # dynamic import of this package (important for DSH Desktop's ASAR runtime).
17
16
  #
18
- # All three rows only CONSUME host services (the tools registry, subprocess,
19
- # the dataAgentConnections connection store), so no `isolate` realm is needed.
17
+ # Both rows only consume host services and remain safe for standing mounting.
20
18
 
21
19
  # ── identity ────────────────────────────────────────────────────────────────
22
20
 
@@ -27,23 +25,22 @@
27
25
  config:
28
26
  text: >-
29
27
  你是数据工程师 Agent。工作目录 {{cwd}}。可用工具:sql-query(只读 SQL,返回结构化
30
- JSON 结果)、sql-write(写/管理 SQL,单条自动提交)、sqlcmd(原始客户端输出,兼容
31
- SHOW TABLES、DESCRIBE users 等命令)、read、write、edit(读写改本地文件)。工作流:
32
- 先用 sql-query 探查表结构与样例数据(禁止臆造表名与列名),把 SQL 写入 .sql 文件
33
- (write/edit),再用 sql-query 执行只读查询或 sql-write 执行写入并核对结果;
34
- 结果可疑时缩小查询范围重试。每次数据库工具调用只允许一条 SQL 语句。
28
+ JSON 结果)、sql-write(写/管理 SQL,单条自动提交)、sql-cmd(原始客户端输出,兼容
29
+ SHOW TABLES、DESCRIBE users 等命令)、str_replace_editor(查看、创建和修改本地文件)。
30
+ Web 界面可用时另有 render-analysis:把一次调用渲染成一份版本化分析报告(1-6 个只读
31
+ 数据集、1-8 metric/line/bar/pie/scatter/table 视图,同一数据集可被多个视图通过
32
+ datasetId 复用)。是否生成分析由你自主判断:先用 sql-query 探查表结构与样例数据并
33
+ 核对事实(禁止臆造表名与列名);schema 探查、单标量或原始明细等无视觉增益的查询
34
+ 直接回答、不强制画图;简单关系可生成一个主图,涉及多指标、时间或分群的复杂问题可
35
+ 生成 3-6 个互补视图。聚合、Top N、排序必须写在 SQL 中,line/time 数据需 ORDER BY。
36
+ 工作流:先用 str_replace_editor 把 SQL 写入 .sql 文件,再用 sql-query 执行只读查询或
37
+ sql-write 执行写入并核对结果;结果可疑时缩小查询范围重试。每次数据库工具调用
38
+ 只允许一条 SQL 语句。
35
39
 
36
40
  # ── filesystem ──────────────────────────────────────────────────────────────
37
41
 
38
- # The project's own fs tools: read / write / edit (no search tools here).
39
- - id: tool-fs
40
- name: '@deepseek-ai/dsh-tool-fs'
41
-
42
- # ── database ────────────────────────────────────────────────────────────────
43
-
44
- # This package's database tool half; injects the host's subprocess service and
45
- # the dataAgentConnections connection store (see the data-agent host row).
46
- # Registers sql-query (structured read), sql-write (explicit write), and the
47
- # legacy sqlcmd raw-terminal tool.
48
- - id: tool-sqlcmd
49
- name: '@yejiming/dsh-data-agent/tool'
42
+ # DSH's native all-in-one file editor (no separate read/write/edit tools).
43
+ - id: tool-str-replace-editor
44
+ name: '@deepseek-ai/dsh-tool-str-replace-editor'
45
+ config:
46
+ maxOutputChars: 16000
@@ -1,3 +1,3 @@
1
1
  name: 数据模式
2
- description: 数据工程师 Agent:连接 MySQL/PostgreSQL/SQLite 数据库,用 sql-query/sql-write/sqlcmd 与 read/write/edit 工具探查 schema、编写并执行 SQL
2
+ description: 连接数据库,用自然语言完成数据探索、SQL编写与业务分析。
3
3
  order: 4