config.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. /** Configuration and stable diagnostics for session references. */
  2. /** Hard maximum references accepted by one message. */
  3. export const MAX_REFERENCES = 3
  4. /** Default number of discovery candidates returned to a host. */
  5. export const DEFAULT_CANDIDATE_LIMIT = 50
  6. /** Default UTF-8 budget for one rendered reference JSON object. */
  7. export const DEFAULT_MAX_REFERENCE_BYTES = 65_536
  8. /** Session-reference service configuration. */
  9. export interface Config {
  10. /** Maximum distinct source sessions referenced by one message, from one to three. */
  11. maxReferences?: number
  12. /** Default host candidate-list limit. */
  13. candidateLimit?: number
  14. /** Maximum rendered UTF-8 bytes for one source snapshot. */
  15. maxReferenceBytes?: number
  16. }
  17. /** Stable failure codes exposed to host adapters. */
  18. export type SessionReferenceErrorCode =
  19. | 'SESSION_REFERENCE_INVALID_CONFIG'
  20. | 'SESSION_REFERENCE_INVALID_REFERENCE'
  21. | 'SESSION_REFERENCE_SELF_REFERENCE'
  22. | 'SESSION_REFERENCE_TOO_MANY'
  23. | 'SESSION_REFERENCE_READ_FAILED'
  24. | 'SESSION_REFERENCE_BUDGET_EXCEEDED'
  25. | 'SESSION_REFERENCE_CANCELLED'
  26. /** Typed session-reference failure suitable for host protocol error mapping. */
  27. export class SessionReferenceError extends Error {
  28. /** @param message Human-readable diagnosis. @param code Stable routing code. @param options Optional cause. */
  29. constructor(
  30. message: string,
  31. readonly code: SessionReferenceErrorCode,
  32. options?: ErrorOptions,
  33. ) {
  34. super(message, options)
  35. this.name = 'SessionReferenceError'
  36. }
  37. }