config.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * dsh-sdk config command composition.
  3. *
  4. * @module @deepseek-ai/dsh-scripts/config
  5. */
  6. import {
  7. ClackPromptPort,
  8. SdkProject,
  9. createBuiltinRegistry,
  10. type PromptPort,
  11. } from '@deepseek-ai/dsh-helper'
  12. import { ConfigWorkflow, type ConfigWorkflowResult } from './config/config-workflow.ts'
  13. /** Process stream slice required by dsh-sdk config. */
  14. export interface ConfigCommandContext {
  15. cwd: string
  16. stdin: NodeJS.ReadStream
  17. stdout: NodeJS.WriteStream
  18. port?: PromptPort
  19. install?: (project: SdkProject) => Promise<void>
  20. }
  21. /** Open and interactively edit one existing SDK project. */
  22. export async function runConfigCommand(context: ConfigCommandContext): Promise<ConfigWorkflowResult> {
  23. if (!context.port && (!context.stdin.isTTY || !context.stdout.isTTY)) {
  24. throw new Error('dsh-sdk config requires an interactive TTY')
  25. }
  26. const project = await SdkProject.open(context.cwd)
  27. const registry = createBuiltinRegistry(project.profile)
  28. return new ConfigWorkflow(
  29. /* v8 ignore next -- production TTY wiring is exercised by the built-bin smoke */
  30. context.port ?? new ClackPromptPort(context.stdin, context.stdout),
  31. context.stdout,
  32. context.install,
  33. ).run(project, registry)
  34. }