index.ts 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /**
  2. * File-reference discovery seam shared by host-backed user interfaces.
  3. *
  4. * @module @deepseek-ai/dsh-file-reference
  5. */
  6. import { Service, type Context } from '@deepseek-ai/cordis'
  7. import type { Agent } from '@deepseek-ai/dsh-agent'
  8. import type { FileReferenceCandidate } from './types.ts'
  9. export { activeAtToken, formatFileMention } from './grammar.ts'
  10. export type { ActiveAtToken } from './grammar.ts'
  11. export type { FileReferenceCandidate } from './types.ts'
  12. /** Model guidance for path-only references selected by a user interface. */
  13. export const FILE_REFERENCE_PROMPT = 'Tokens prefixed with @ are workspace paths the user explicitly referenced, relative to the workspace root. A trailing slash marks a directory: list it when its contents matter. Anything else is a file: use the read tool when its contents are needed, and do not claim to have inspected it before reading. @"..." quotes a path containing spaces.'
  14. declare module '@deepseek-ai/cordis' {
  15. interface Context {
  16. fileReferences: FileReferenceService
  17. }
  18. }
  19. /** Host capability for cancellable file-reference discovery. */
  20. export abstract class FileReferenceService extends Service {
  21. constructor(ctx: Context) {
  22. super(ctx, 'fileReferences')
  23. }
  24. /**
  25. * List file and directory candidates for one agent's working directory.
  26. * @param agent - target agent whose session cwd bounds discovery.
  27. * @param query - path text following `@` or `@"`.
  28. * @param signal - caller cancellation.
  29. * @returns deterministic path-only candidates.
  30. */
  31. abstract list(
  32. agent: Agent,
  33. query: string,
  34. signal: AbortSignal,
  35. ): Promise<FileReferenceCandidate[]>
  36. }
  37. export default FileReferenceService