Codex.IO.Transport behaviour (Codex SDK v0.14.0)

Copy Markdown View Source

Behaviour for subprocess I/O transport implementations.

Event model:

Legacy dispatch:

  • {:transport_message, line}
  • {:transport_error, reason}
  • {:transport_stderr, data}
  • {:transport_exit, reason}

Tagged dispatch:

  • {:codex_io_transport, ref, {:message, line}}
  • {:codex_io_transport, ref, {:error, reason}}
  • {:codex_io_transport, ref, {:stderr, data}}
  • {:codex_io_transport, ref, {:exit, reason}}

Summary

Types

message()

@type message() ::
  {:transport_message, String.t()}
  | {:transport_error, term()}
  | {:transport_stderr, binary()}
  | {:transport_exit, term()}
  | {:codex_io_transport, reference(), {:message, String.t()}}
  | {:codex_io_transport, reference(), {:error, term()}}
  | {:codex_io_transport, reference(), {:stderr, binary()}}
  | {:codex_io_transport, reference(), {:exit, term()}}

opts()

@type opts() :: keyword()

subscription_tag()

@type subscription_tag() :: :legacy | reference()

t()

@type t() :: pid() | GenServer.server()

Callbacks

close(t)

@callback close(t()) :: :ok

end_input(t)

@callback end_input(t()) :: :ok | {:error, term()}

force_close(t)

@callback force_close(t()) :: :ok | {:error, term()}

interrupt(t)

@callback interrupt(t()) :: :ok | {:error, term()}

send(t, iodata)

@callback send(t(), iodata()) :: :ok | {:error, term()}

start(opts)

@callback start(opts()) :: {:ok, t()} | {:error, term()}

start_link(opts)

@callback start_link(opts()) :: {:ok, t()} | {:error, term()}

status(t)

@callback status(t()) :: :connected | :disconnected | :error

stderr(t)

@callback stderr(t()) :: binary()

subscribe(t, pid)

@callback subscribe(t(), pid()) :: :ok | {:error, term()}

subscribe(t, pid, subscription_tag)

@callback subscribe(t(), pid(), subscription_tag()) :: :ok | {:error, term()}