config.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. /** Minimum automatic 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. /** Explicit maximum rendered UTF-8 bytes per source; absent uses the model-relative budget with a 64 KiB floor. */
  15. maxReferenceBytes?: number
  16. /** Fraction of the model context window per source, estimated at four bytes per token; between zero and one. */
  17. referenceContextFraction?: number
  18. }
  19. /** Stable failure codes exposed to host adapters. */
  20. export type SessionReferenceErrorCode =
  21. | 'SESSION_REFERENCE_INVALID_CONFIG'
  22. | 'SESSION_REFERENCE_INVALID_REFERENCE'
  23. | 'SESSION_REFERENCE_SELF_REFERENCE'
  24. | 'SESSION_REFERENCE_TOO_MANY'
  25. | 'SESSION_REFERENCE_READ_FAILED'
  26. | 'SESSION_REFERENCE_BUDGET_EXCEEDED'
  27. | 'SESSION_REFERENCE_CANCELLED'
  28. /** Typed session-reference failure suitable for host protocol error mapping. */
  29. export class SessionReferenceError extends Error {
  30. /** @param message Human-readable diagnosis. @param code Stable routing code. @param options Optional cause. */
  31. constructor(
  32. message: string,
  33. readonly code: SessionReferenceErrorCode,
  34. options?: ErrorOptions,
  35. ) {
  36. super(message, options)
  37. this.name = 'SessionReferenceError'
  38. }
  39. }