index.ts 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * File-reference discovery seam shared by host-backed user interfaces.
  3. *
  4. * @module @deepseek-ai/dsh-file-reference
  5. */
  6. import type { Context } from '@deepseek-ai/cordis'
  7. import type { Agent } from '@deepseek-ai/dsh-agent'
  8. import { Remote, TypertRemoteService } from '@deepseek-ai/dsh-typert-protocol'
  9. import type { FileReferenceCandidate } from './types.ts'
  10. export { activeAtToken, formatFileMention } from './grammar.ts'
  11. export type { ActiveAtToken } from './grammar.ts'
  12. export type { FileReferenceCandidate } from './types.ts'
  13. /** Model guidance for path-only references selected by a user interface. */
  14. export const FILE_REFERENCE_PROMPT = 'Paths prefixed with @ are files explicitly referenced by the user. Use the read tool when their contents are needed; do not claim to have inspected a file before reading it.'
  15. declare module '@deepseek-ai/cordis' {
  16. interface Context {
  17. fileReferences: FileReferenceService
  18. }
  19. }
  20. /** Host capability for cancellable file-reference discovery. */
  21. export abstract class FileReferenceService extends TypertRemoteService {
  22. constructor(ctx: Context) {
  23. super(ctx, 'fileReferences')
  24. }
  25. /**
  26. * List file and directory candidates for one agent's working directory.
  27. * @param agent - target agent whose session cwd bounds discovery.
  28. * @param query - path text following `@` or `@"`.
  29. * @param signal - caller cancellation.
  30. * @returns deterministic path-only candidates.
  31. */
  32. abstract list(
  33. agent: Agent,
  34. query: string,
  35. signal: AbortSignal,
  36. ): Promise<FileReferenceCandidate[]>
  37. /**
  38. * Remote face of {@link list}; the decorator cannot mark the abstract
  39. * member, so this concrete adapter carries the identical contract.
  40. * @param agent - target agent whose session cwd bounds discovery.
  41. * @param query - path text following `@` or `@"`.
  42. * @param signal - caller cancellation.
  43. * @returns deterministic path-only candidates.
  44. */
  45. @Remote('list')
  46. remoteExportList(
  47. agent: Agent,
  48. query: string,
  49. signal: AbortSignal,
  50. ): Promise<FileReferenceCandidate[]> {
  51. return this.list(agent, query, signal)
  52. }
  53. }
  54. export default FileReferenceService