index.ts 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * Browser half: the `file` resource provider over `remote.workspaceFiles`.
  3. *
  4. * `types.ts` is what the protocol publishes, `change-feed.ts` shares one Host
  5. * `changes` stream per session, `provider.ts` turns it and `stat` into a value
  6. * stream, and this module only wires them into `ctx.resources`.
  7. */
  8. import type { Context as ClientContext } from '@deepseek-ai/cordis'
  9. import type {} from '@deepseek-ai/dsh-api-gateway/client'
  10. // The `sessions` service face supplies the current Session for absolute addresses.
  11. import type {} from '@deepseek-ai/dsh-api-session-controller/client'
  12. import type {} from '@deepseek-ai/dsh-client-resources/client'
  13. import { ChangeFeed } from './change-feed.ts'
  14. import { createFileResourceProvider, type SessionLookup } from './provider.ts'
  15. export type { SessionLookup } from './provider.ts'
  16. export type { WorkspaceFileParams, WorkspaceFileResource } from './types.ts'
  17. /** Required browser services: the resource model, the Remote carrier and its namespace, and the Session list. */
  18. export const inject = ['resources', 'remote', 'remote.workspaceFiles', 'sessions']
  19. /**
  20. * Client plugin body: register the `file` provider for this plugin's lifetime.
  21. * @param ctx - client root context carrying `resources`, the Remote face, and `sessions`.
  22. */
  23. export function apply(ctx: ClientContext): void {
  24. // The current Session changes with navigation; absolute addresses read it on demand.
  25. const sessions: SessionLookup = {
  26. current: () => ctx.sessions.list.getSnapshot().current,
  27. }
  28. const changes = new ChangeFeed(ctx.remote)
  29. const provider = createFileResourceProvider(ctx.remote, changes, sessions)
  30. ctx.effect(() => {
  31. const release = ctx.resources.register(provider)
  32. // Teardown waits for every session stream still closing, so the plugin
  33. // leaves no Host stream behind.
  34. return async () => {
  35. release()
  36. await changes.settle()
  37. }
  38. }, 'workspace-files: file resource provider')
  39. }