@linxin666/dsh-ssh 0.3.19 → 0.3.21

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/src/tools.ts CHANGED
@@ -7,15 +7,43 @@
7
7
  import { defineTool } from '@deepseek-ai/dsh-tools'
8
8
  import type { ContentBlock } from '@deepseek-ai/dsh-llm'
9
9
  import type { SshEngine } from './engine.ts'
10
- import type { ClusterResult, ExecResult, SshHostSummary, TunnelInfo } from './protocol.ts'
10
+ import type { ClusterResult, ExecResult, SshAuthKind, SshHostSummary, TunnelInfo } from './protocol.ts'
11
11
 
12
12
  /** One text content block (the only render shape these tools emit). */
13
13
  function text(value: string): ContentBlock[] {
14
14
  return [{ type: 'text', text: value }]
15
15
  }
16
16
 
17
+ /**
18
+ * One host row for the agent surface. The ProxyCommand STRING is deliberately
19
+ * projected to a boolean: the command may embed credentials for a bastion
20
+ * client, and the model only needs to know that the host goes through one.
21
+ */
22
+ export interface AgentHostRow {
23
+ alias: string
24
+ host: string
25
+ port: number
26
+ user: string
27
+ auth: SshAuthKind
28
+ keyReady: boolean
29
+ proxyJump: string[]
30
+ proxyCommandConfigured: boolean
31
+ description?: string
32
+ environment?: string
33
+ tags: string[]
34
+ location?: string
35
+ createdAt: number
36
+ updatedAt: number
37
+ }
38
+
39
+ /** Project one summary onto the agent-facing row shape. */
40
+ export function toAgentHostRow(host: SshHostSummary): AgentHostRow {
41
+ const { proxyCommand, ...rest } = host
42
+ return { ...rest, proxyCommandConfigured: proxyCommand !== undefined }
43
+ }
44
+
17
45
  /** Host table render shared by list surfaces. */
18
- function renderHosts(hosts: SshHostSummary[]): string {
46
+ function renderHosts(hosts: AgentHostRow[]): string {
19
47
  if (hosts.length === 0) return 'no hosts configured'
20
48
  const rows = hosts.map(host => [
21
49
  host.alias,
@@ -23,11 +51,12 @@ function renderHosts(hosts: SshHostSummary[]): string {
23
51
  String(host.port),
24
52
  host.user,
25
53
  host.auth,
54
+ host.proxyJump.length > 0 ? 'jump:' + host.proxyJump.join(',') : host.proxyCommandConfigured ? 'proxy-command' : '-',
26
55
  host.environment ?? '-',
27
56
  (host.tags.length > 0 ? host.tags.join(',') : '-'),
28
57
  host.description ?? '',
29
58
  ].join(' | '))
30
- return ['alias | host | port | user | auth | environment | tags | description', '--- | --- | --- | --- | --- | --- | --- | ---', ...rows].join('\n')
59
+ return ['alias | host | port | user | auth | proxy | environment | tags | description', '--- | --- | --- | --- | --- | --- | --- | --- | ---', ...rows].join('\n')
31
60
  }
32
61
 
33
62
  /** Render one exec result (mirrors the bash-tool exit-code convention). */
@@ -86,6 +115,7 @@ export function sshListTool(engine: SshEngine) {
86
115
  auth: { type: 'string', enum: ['key', 'password', 'agent'], required: true },
87
116
  keyReady: { type: 'boolean', required: true },
88
117
  proxyJump: { type: 'array', items: { type: 'string' }, required: true },
118
+ proxyCommandConfigured: { type: 'boolean', required: true },
89
119
  description: { type: 'string' },
90
120
  environment: { type: 'string' },
91
121
  tags: { type: 'array', items: { type: 'string' }, required: true },
@@ -97,10 +127,10 @@ export function sshListTool(engine: SshEngine) {
97
127
  },
98
128
  },
99
129
  },
100
- render: (_args, value: { hosts?: SshHostSummary[] }) => text(renderHosts(value.hosts ?? [])),
130
+ render: (_args, value: { hosts?: AgentHostRow[] }) => text(renderHosts(value.hosts ?? [])),
101
131
  },
102
132
  async execute(args) {
103
- return { hosts: engine.list(args.query) }
133
+ return { hosts: engine.list(args.query).map(toAgentHostRow) }
104
134
  },
105
135
  })
106
136
  }