harness.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import { Context } from 'cordis'
  2. import LlmService from '@deepseek-ai/dsh-llm'
  3. import SessionStore from '@deepseek-ai/dsh-session'
  4. import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
  5. import ToolRegistry from '@deepseek-ai/dsh-tools'
  6. import AgentRegistry, { type Agent } from '@deepseek-ai/dsh-agent'
  7. import AgentLoop from '@deepseek-ai/dsh-agent-loop'
  8. import { LocalBashExecutor } from '@deepseek-ai/dsh-bash-local'
  9. import * as ToolBash from '@deepseek-ai/dsh-tool-bash'
  10. import * as LlmDeepSeek from '@deepseek-ai/dsh-llm-deepseek'
  11. import SubagentService from '@deepseek-ai/dsh-subagent'
  12. import * as Spawn from '../src/index.ts'
  13. import * as ToolSubagent from '@deepseek-ai/dsh-tool-subagent'
  14. /**
  15. * Shared harness for the spawn-backend e2e: the full real stack (DeepSeek
  16. * adapter + real bash tool + the subagent tool bound to the spawn backend), so
  17. * a real parent agent can delegate to a real in-process child that does real
  18. * work (writes a file). Lives outside the *.e2e.ts pattern so importing it never
  19. * re-registers another file's tests.
  20. */
  21. export async function spawnHarness(workdir: string): Promise<Context> {
  22. const ctx = new Context()
  23. await ctx.plugin(LlmService)
  24. await ctx.plugin(SessionStore)
  25. await ctx.plugin(SystemPrompt)
  26. await ctx.plugin(ToolRegistry)
  27. await ctx.plugin(AgentRegistry)
  28. await ctx.plugin(AgentLoop, { agents: [] })
  29. await ctx.plugin(LlmDeepSeek, { models: ['deepseek-v4-flash'] })
  30. await ctx.plugin(LocalBashExecutor, { cwd: workdir, timeoutMs: 30_000 })
  31. await ctx.plugin(ToolBash)
  32. await ctx.plugin(SubagentService)
  33. await ctx.plugin(Spawn, { providerName: 'spawn' })
  34. // The model-facing subagent tool, bound to the spawn backend.
  35. await ctx.plugin(ToolSubagent, { provider: 'spawn' })
  36. return ctx
  37. }
  38. export function waitForIdle(ctx: Context, agent: Agent): Promise<void> {
  39. return new Promise((resolve) => {
  40. const dispose = ctx.on('agent/status', (subject, status) => {
  41. if (subject === agent && status === 'idle') {
  42. dispose()
  43. resolve()
  44. }
  45. })
  46. })
  47. }