harness.ts 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import { Context } from 'cordis'
  2. import type { Agent } from '@deepseek-ai/dsh-agent'
  3. import AgentLoop from '@deepseek-ai/dsh-agent-loop'
  4. import { mountAgentLoopTestDependencies } from '@deepseek-ai/dsh-agent-loop-testkit'
  5. import * as LlmDeepSeek from '@deepseek-ai/dsh-llm-deepseek'
  6. import * as ToolCordis from '@deepseek-ai/dsh-tool-cordis'
  7. /**
  8. * Shared harness for the cordis-agent e2e suite: the agent spine with the real
  9. * DeepSeek adapter and the real `@deepseek-ai/dsh-tool-cordis` plugin, so a
  10. * live model can mount plugins into the very context the test observes. Lives
  11. * outside the *.e2e.ts pattern so importing it never re-registers another
  12. * file's tests.
  13. */
  14. const PERSONA = 'You are cordis-agent, a self-referential harness demo. '
  15. + 'Your cordis_* tools operate on the live cordis runtime you run inside: '
  16. + 'cordis_inspect to look around, cordis_mount to mount a temporary Plugin, cordis_unmount '
  17. + 'to unmount one. Follow the tool descriptions exactly and report results briefly.'
  18. export async function cordisHarness(): Promise<Context> {
  19. const ctx = new Context()
  20. await mountAgentLoopTestDependencies(ctx, {
  21. systemPrompt: { persona: PERSONA },
  22. })
  23. await ctx.plugin(AgentLoop, { agents: [] })
  24. await ctx.plugin(LlmDeepSeek)
  25. await ctx.plugin(ToolCordis)
  26. return ctx
  27. }
  28. export function waitForIdle(ctx: Context, agent: Agent): Promise<void> {
  29. return new Promise((resolve) => {
  30. const dispose = ctx.on('agent/status', (subject, status) => {
  31. if (subject === agent && status === 'idle') {
  32. dispose()
  33. resolve()
  34. }
  35. })
  36. })
  37. }