@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
@@ -1,86 +0,0 @@
1
- import { c as buildIntrospectTemplate, l as buildStructuredQueryTemplate, s as buildClientTemplate } from "./defaults-Bac6QvNt.js";
2
- //#region src/query.ts
3
- /** Read one collected stream from offset 0. */
4
- function readCaptured(reader) {
5
- if (reader === void 0) return {
6
- text: "",
7
- truncated: false
8
- };
9
- const read = reader.readFrom(0);
10
- return {
11
- text: read.text,
12
- truncated: read.lossy
13
- };
14
- }
15
- /**
16
- * Run one SQL text through the type's CLI client. The SQL is written to the
17
- * child's stdin (`{ data }` batch disposition) so it never appears in argv;
18
- * passwords travel in the env entries built by the template.
19
- *
20
- * Failure classification:
21
- * - the caller's external signal (e.g. the tool exec signal) aborts → the
22
- * abort reason propagates;
23
- * - the internal timeout fires → an Error naming the deadline is thrown;
24
- * - the executable cannot be resolved → an Error naming the command is thrown;
25
- * - the process runs to completion → `{ exitCode, stdout, stderr, truncated }`
26
- * is returned even for a non-zero exit (the caller decides what that means).
27
- * @param ctx - context exposing the subprocess service.
28
- * @param connection - the stored connection (password included).
29
- * @param sql - the SQL text (or client command) to run.
30
- * @param options - timeouts, caps, client overrides.
31
- * @param externalSignal - caller-owned cancellation (the tool exec signal).
32
- * @param introspect - use the machine-readable introspection flag set.
33
- * @returns the captured outcome.
34
- */
35
- async function runClientQuery(ctx, connection, sql, options, externalSignal, introspect = false) {
36
- const template = options.mode === "structured" ? buildStructuredQueryTemplate(connection.type, connection, options.clients[connection.type]) : options.mode === "introspect" || introspect ? buildIntrospectTemplate(connection.type, connection, options.clients[connection.type]) : buildClientTemplate(connection.type, connection, options.clients[connection.type]);
37
- const controller = new AbortController();
38
- const timer = setTimeout(() => controller.abort(/* @__PURE__ */ new Error(`查询超过 ${options.timeoutMs}ms 未完成,已终止客户端进程`)), options.timeoutMs);
39
- const onExternalAbort = () => {
40
- controller.abort(externalSignal.reason);
41
- };
42
- if (externalSignal.aborted) controller.abort(externalSignal.reason);
43
- else externalSignal.addEventListener("abort", onExternalAbort, { once: true });
44
- try {
45
- let executable;
46
- try {
47
- executable = await ctx.subprocess.resolveExecutable(template.command, template.env, controller.signal);
48
- } catch (error) {
49
- controller.signal.throwIfAborted();
50
- throw new Error(`无法解析数据库客户端 "${template.command}"(${error instanceof Error ? error.message : String(error)});请确认客户端已安装,或在 data-agent 插件配置的 clients 中覆盖命令名/路径`);
51
- }
52
- const handle = ctx.subprocess.spawn({
53
- argv: [executable, ...template.args],
54
- cwd: process.cwd(),
55
- stdio: {
56
- stdin: { data: `${template.stdinPrefix}${sql}\n` },
57
- stdout: { maxBytes: options.maxResultChars },
58
- stderr: { maxBytes: options.maxResultChars }
59
- },
60
- graceMs: options.graceMs ?? 5e3,
61
- signal: controller.signal,
62
- env: template.env
63
- });
64
- let outcome;
65
- try {
66
- outcome = await handle.done;
67
- } catch (error) {
68
- controller.signal.throwIfAborted();
69
- throw new Error(`启动数据库客户端失败:${error instanceof Error ? error.message : String(error)}`);
70
- }
71
- if (controller.signal.aborted) controller.signal.throwIfAborted();
72
- const stdout = readCaptured(handle.collected.stdout);
73
- const stderr = readCaptured(handle.collected.stderr);
74
- return {
75
- exitCode: outcome.exitCode,
76
- stdout: stdout.text,
77
- stderr: stderr.text,
78
- truncated: stdout.truncated || stderr.truncated
79
- };
80
- } finally {
81
- clearTimeout(timer);
82
- externalSignal.removeEventListener("abort", onExternalAbort);
83
- }
84
- }
85
- //#endregion
86
- export { runClientQuery as t };