@linxin666/dsh-ssh 0.4.20 → 0.4.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,6 +7,7 @@
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 { hasClusterSelector } from './engine/cluster.ts'
10
11
  import type { ClusterResult, ExecResult, SshAuthKind, SshHostSummary, TunnelInfo } from './protocol.ts'
11
12
 
12
13
  /** One text content block (the only render shape these tools emit). */
@@ -336,7 +337,7 @@ export function sshTunnelTool(engine: SshEngine) {
336
337
  remoteHost: args.remoteHost,
337
338
  localPort: args.localPort,
338
339
  })
339
- return { ok: true, tunnel }
340
+ return { ok: tunnel.state !== 'failed', tunnel }
340
341
  } catch (error) {
341
342
  return { ok: false, tunnel: { id: '', alias: args.alias, localPort: 0, remoteHost: args.remoteHost ?? '127.0.0.1', remotePort: args.remotePort, state: 'failed' as const, error: error instanceof Error ? error.message : String(error), startedAt: Date.now() } }
342
343
  }
@@ -398,10 +399,7 @@ export function sshClusterTool(engine: SshEngine) {
398
399
  render: (_args, value: { results?: ClusterResult[] }) => text(renderCluster(value.results ?? [])),
399
400
  },
400
401
  async execute(args, exec) {
401
- const hasSelector = (Array.isArray(args.aliases) && args.aliases.some((alias) => typeof alias === 'string' && alias.trim() !== '')) ||
402
- (typeof args.environment === 'string' && args.environment.trim() !== '') ||
403
- (Array.isArray(args.tags) && args.tags.some((tag) => typeof tag === 'string' && tag.trim() !== ''))
404
- if (!hasSelector) throw new Error('ssh_cluster requires aliases, environment, or tags to limit the target set')
402
+ if (!hasClusterSelector(args)) throw new Error('ssh_cluster requires aliases, environment, or tags to limit the target set')
405
403
  // Cancellation reaches every host's in-flight command.
406
404
  return { results: await engine.cluster({ ...args, signal: exec.signal }) }
407
405
  },