Mead.Deck.Events (mead v0.1.1)

Copy Markdown View Source

The wire vocabulary of the deck protocol: building the envelope of a server event and validating a client message.

Pure. A malformed message is an error value, never an exception, because the bytes come from a socket and any of them may be garbage.

Summary

Types

client_message()

@type client_message() ::
  {:prompt_send, %{client_message_id: String.t(), text: String.t()}}
  | {:permission_respond, %{request_id: String.t(), option_id: String.t()}}
  | {:choice_respond, %{request_id: String.t(), option_id: String.t()}}
  | {:tool_call_cancel, %{tool_call_id: String.t()}}
  | {:session_resume,
     %{last_sequence: non_neg_integer(), device_id: String.t() | nil}}
  | {:permission_forget, %{tool: String.t()}}
  | {:policy_set, %{level: :ask_always | :ask_for_risky | :allow_all}}

decode_error()

@type decode_error() ::
  :too_large | :not_json | :not_object | :unknown_type | :invalid_payload

Functions

decode_client(frame)

@spec decode_client(term()) :: {:ok, client_message()} | {:error, decode_error()}

encode(envelope)

@spec encode(map()) :: binary()

envelope(sequence, session_id, type, payload, occurred_at)

@spec envelope(non_neg_integer() | nil, String.t(), String.t(), map(), DateTime.t()) ::
  map()

maximum_frame_bytes()

@spec maximum_frame_bytes() :: pos_integer()

The largest client frame accepted, in bytes.

parse_policy_level(name)

@spec parse_policy_level(term()) :: {:ok, atom()} | :error

policy_level_name(level)

@spec policy_level_name(atom()) :: String.t()

server_event_types()

@spec server_event_types() :: [String.t()]

The names of every event the server sends.