index.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. /**
  2. * Shared mounting for the services required before tests load the concrete
  3. * agent loop. The caller retains ownership of the context, loop, adapters,
  4. * optional plugins, and teardown.
  5. * @module @deepseek-ai/dsh-agent-loop-testkit
  6. */
  7. import type { Context } from '@deepseek-ai/cordis'
  8. import AgentRegistry from '@deepseek-ai/dsh-agent'
  9. import LlmRuntime from '@deepseek-ai/dsh-llm'
  10. import SessionStore from '@deepseek-ai/dsh-session'
  11. import SystemPrompt from '@deepseek-ai/dsh-system-prompt'
  12. import type { Config as SystemPromptConfig } from '@deepseek-ai/dsh-system-prompt'
  13. import ToolRuntime from '@deepseek-ai/dsh-tools'
  14. import type { Config as ToolRuntimeConfig } from '@deepseek-ai/dsh-tools'
  15. /** Configuration forwarded to the prerequisite service plugins. */
  16. export interface AgentLoopTestDependenciesOptions {
  17. /** Configuration for the system-prompt registry. */
  18. readonly systemPrompt?: SystemPromptConfig
  19. /** Configuration for the tool registry. */
  20. readonly tools?: ToolRuntimeConfig
  21. }
  22. /**
  23. * Mount the standard prerequisite services for an AgentLoop test.
  24. *
  25. * The function deliberately does not mount AgentLoop or register an adapter,
  26. * so tests retain control of load order and the topology under test. The
  27. * context owns every mounted service and remains responsible for disposal. A
  28. * plugin-load failure rejects the promise; services activated earlier in the
  29. * sequence remain context-owned and unwind with that context.
  30. * @param ctx - test context that owns the mounted services.
  31. * @param options - optional service configuration forwarded without mutation.
  32. * @returns after every prerequisite service has activated.
  33. */
  34. export async function mountAgentLoopTestDependencies(
  35. ctx: Context,
  36. options: AgentLoopTestDependenciesOptions = {},
  37. ): Promise<void> {
  38. await ctx.plugin(LlmRuntime)
  39. await ctx.plugin(SessionStore)
  40. await ctx.plugin(SystemPrompt, options.systemPrompt ?? {})
  41. await ctx.plugin(ToolRuntime, options.tools ?? {})
  42. await ctx.plugin(AgentRegistry)
  43. }