index.ts 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Agent-plane presentation selector: the row an agent preset carries to say
  3. * which form of its tools the model sees.
  4. *
  5. * The tool registry itself stays on the host plane — the agent loop's
  6. * scheduler, the API proxy's presenters, and every tool plugin are all its
  7. * consumers, so it cannot move into a preset. What a preset CAN own is the
  8. * presentation: `ctx.tools.presentAs()` declares it for the mounting SCOPE,
  9. * which is the preset's standing mount, so the declaration covers every agent
  10. * joined to that preset and a PTC mode preset runs beside native ones in one
  11. * process. One row per composition, not one per session.
  12. *
  13. * A PTC mode needs a TypeScript code runtime, which is a host-plane service
  14. * ([`dsh-code-runtime-worker-thread`](../../code-runtime/code-runtime-worker/README.md)).
  15. * This row therefore waits for it rather than assuming it: a preset selecting
  16. * PTC mode against a deployment that composes no runtime fails at mount, named
  17. * in the preset's own activation audit, instead of at the first prompt.
  18. * @module @deepseek-ai/dsh-agent-tool-presentation
  19. */
  20. import type { Context } from '@deepseek-ai/cordis'
  21. import z from '@deepseek-ai/schemastery'
  22. import type { ToolPresentationMode } from '@deepseek-ai/dsh-tools'
  23. // Type-only: brings the `ctx.tools` Context merge into this program.
  24. import type {} from '@deepseek-ai/dsh-tools'
  25. /** Cordis plugin name. */
  26. export const name = 'tool-presentation'
  27. /**
  28. * Required services. `codeRuntime` is NOT listed: a `native` row must mount in
  29. * a deployment that composes no runtime, and the mode-dependent wait is
  30. * declared inside {@link apply} instead.
  31. */
  32. export const inject = ['tools']
  33. /** Plugin config. */
  34. export interface Config {
  35. /**
  36. * The form this agent's model sees. `native` sends every visible schema,
  37. * `ptc` sends only `run_code` plus a generated SDK, `both` sends both.
  38. * Required rather than defaulted: the deployment default is what a preset
  39. * without this row already gets, so an omitted value would mean the row was
  40. * composed for nothing.
  41. */
  42. mode: ToolPresentationMode
  43. }
  44. /** Runtime schema. */
  45. export const Config: z<Config> = z.object({
  46. mode: z.union(['native', 'ptc', 'both'] as const).required(),
  47. })
  48. /**
  49. * Declare the tool presentation for every agent this composition covers.
  50. * @param ctx - the mounting composition's scope context (a preset's standing scope).
  51. * @param config - the selected presentation.
  52. */
  53. export function apply(ctx: Context, config: Config): void {
  54. // `presentAs` is itself the effect — it registers through the calling
  55. // context and hands back that exact disposer — so the declaration unwinds
  56. // with this row without a second wrapper owning it.
  57. if (config.mode === 'native') {
  58. ctx.tools.presentAs('native')
  59. return
  60. }
  61. // The wait is the loud failure: an entry still pending on `codeRuntime` is
  62. // what `dsh-agent-presets` reports as an unusable row, naming this id.
  63. ctx.inject(['codeRuntime'], (runtimeCtx: Context) => {
  64. runtimeCtx.tools.presentAs(config.mode)
  65. })
  66. }