index.ts 2.1 KB

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