session.ts 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * The outward session face. Feature packages never see the concrete Session
  3. * class: components read conversation state through `useSession` (the
  4. * ObservableSnapshot half), and orchestration code calls the behavior verbs
  5. * below — nothing else. Widening this interface is the explicit act of
  6. * widening what features may do to a session (and what every test fixture
  7. * must stub); runtime-internal entry points (history staging, wire-frame
  8. * dispatch) stay on the class, invisible out here.
  9. */
  10. import type { ContentBlock } from '@deepseek-ai/dsh-llm/types'
  11. import type {
  12. InboxItemId, QueueAction, RpcResult, SessionId,
  13. } from '@deepseek-ai/dsh-client-connection/client'
  14. import type { ConversationSnapshot } from '../sessions/conversation.ts'
  15. import type { ObservableSnapshot } from './store.ts'
  16. /** Key-addressed projection read face (the useProjection resolution path; see ProjectionValueStore). */
  17. export interface ProjectionsFace {
  18. /**
  19. * The identity-stable bare observable for one projection key (absence is
  20. * an `undefined` snapshot, never a missing face).
  21. * @param key - projection key.
  22. * @returns the key's value face.
  23. */
  24. faceOf(key: string): ObservableSnapshot<unknown>
  25. }
  26. /** Identity plus the behavior verbs features may invoke on a session. */
  27. export interface ISession {
  28. /** The session's host identity (agent id — same axis). */
  29. readonly sessionId: SessionId
  30. /** Host-computed projection values by key (the useProjection seat). */
  31. readonly projections: ProjectionsFace
  32. /**
  33. * Send a prompt into the session.
  34. * @param content - model-facing content blocks.
  35. * @param mode - 'queue' appends a turn; 'steer' interrupts the running one.
  36. * @returns acceptance, or the business error (also mirrored into snapshot.promptError).
  37. */
  38. prompt(content: ContentBlock[], mode: 'queue' | 'steer'): Promise<RpcResult<{ accepted: true }>>
  39. /**
  40. * Apply one edit, remove, or strict steer action to a still-pending queue occurrence.
  41. * @param itemId - agent-owned inbox occurrence identity.
  42. * @param action - requested queue operation.
  43. * @returns acceptance, or a business/transport error.
  44. */
  45. updateQueue(itemId: InboxItemId, action: QueueAction): Promise<RpcResult<{ accepted: true }>>
  46. /**
  47. * Cancel the running turn. Pending queued work remains and resumes in FIFO
  48. * order after the Host reaches cancellation quiescence.
  49. * @returns acceptance, or the business error.
  50. */
  51. cancel(): Promise<RpcResult<{ accepted: true }>>
  52. /**
  53. * Rename this session (explicit user title; pins it against automatic
  54. * regeneration).
  55. * @param title - raw title text (the host normalizes acceptance).
  56. * @returns the normalized accepted title and its event seq, or the business error.
  57. */
  58. rename(title: string): Promise<RpcResult<{ title: string; seq: number }>>
  59. /**
  60. * Extend the history window backwards (older messages pagination).
  61. * @returns completion; failures land in snapshot.openState/loadingOlder.
  62. */
  63. loadOlder(): Promise<void>
  64. /**
  65. * Execute one slash-command line against this session's agent — pure
  66. * admission semantics (the host executor durably logs the lifecycle).
  67. * @param line - the full command line, leading slash included.
  68. * @returns the admission result, or the error branch on transport failure.
  69. */
  70. command(line: string): Promise<RpcResult<{ matched: boolean }>>
  71. }
  72. /**
  73. * The full outward face: behavior verbs plus the conversation read side
  74. * (the `useSession` hook source). This is the type carried by
  75. * `SessionBinding.session` and the provide channel.
  76. */
  77. export type SessionFace = ISession & ObservableSnapshot<ConversationSnapshot>