result.ts 993 B

12345678910111213141516171819202122232425262728
  1. /** Client operation results spanning Session Remote calls and the legacy subagent carrier. */
  2. import type { RpcError } from '@deepseek-ai/dsh-client-connection/client'
  3. import type { SessionError } from '../../types.ts'
  4. /** Failure surfaced by the Client Session object layer. */
  5. export type ClientFailure = RpcError | SessionError
  6. /** Success or failure returned by a Client Session operation. */
  7. export type ClientResult<T> =
  8. | { readonly ok: true; readonly value: T }
  9. | { readonly ok: false; readonly error: ClientFailure }
  10. /**
  11. * Fold a rejected carrier operation into the Client Session failure vocabulary.
  12. * @param error - rejection from a legacy subagent or local carrier call.
  13. * @returns the failure branch of a Client Session result.
  14. */
  15. export function transportResult<T>(error: unknown): ClientResult<T> {
  16. return {
  17. ok: false,
  18. error: {
  19. code: 'internal',
  20. message: error instanceof Error ? error.message : String(error),
  21. details: {},
  22. },
  23. }
  24. }