CodexEx.AppServer.Thread (codex_ex v0.1.0)

Copy Markdown View Source

Public thread service object for the app-server client.

The struct keeps the owning client plus the latest typed thread snapshot. Operations that mutate server state return a fresh %Thread{} with an updated snapshot when the server returns one.

Summary

Types

t()

@type t() :: %CodexEx.AppServer.Thread{
  client: CodexEx.AppServer.Client.t(),
  id: binary(),
  settings: CodexEx.AppServer.ThreadSettings.t() | nil,
  snapshot: CodexEx.AppServer.ThreadSnapshot.t()
}

Functions

archive(thread)

@spec archive(%CodexEx.AppServer.Thread{
  client: term(),
  id: term(),
  settings: term(),
  snapshot: term()
}) ::
  :ok | {:error, term()}

clear_goal(thread)

@spec clear_goal(%CodexEx.AppServer.Thread{
  client: term(),
  id: term(),
  settings: term(),
  snapshot: term()
}) :: :ok | {:error, term()}

fork(thread, overrides \\ %{})

@spec fork(
  %CodexEx.AppServer.Thread{
    client: term(),
    id: term(),
    settings: term(),
    snapshot: term()
  },
  map()
) ::
  {:ok,
   %CodexEx.AppServer.Thread{
     client: term(),
     id: term(),
     settings: term(),
     snapshot: term()
   }}
  | {:error, term()}

get_goal(thread)

@spec get_goal(%CodexEx.AppServer.Thread{
  client: term(),
  id: term(),
  settings: term(),
  snapshot: term()
}) :: {:ok, CodexEx.AppServer.ThreadGoal.t() | nil} | {:error, term()}

list_turns_page(thread, opts \\ [])

@spec list_turns_page(
  %CodexEx.AppServer.Thread{
    client: term(),
    id: term(),
    settings: term(),
    snapshot: term()
  },
  keyword()
) :: {:ok, CodexEx.AppServer.Client.thread_turns_page()} | {:error, term()}

Lists one backwards page of full turns for a paginated thread.

new(client, snapshot, settings \\ nil)

@spec new(
  CodexEx.AppServer.Client.t(),
  CodexEx.AppServer.ThreadSnapshot.t(),
  CodexEx.AppServer.ThreadSettings.t() | nil
) :: %CodexEx.AppServer.Thread{
  client: term(),
  id: term(),
  settings: term(),
  snapshot: term()
}

refresh(thread, opts \\ [])

@spec refresh(
  %CodexEx.AppServer.Thread{
    client: term(),
    id: term(),
    settings: term(),
    snapshot: term()
  },
  keyword()
) ::
  {:ok,
   %CodexEx.AppServer.Thread{
     client: term(),
     id: term(),
     settings: term(),
     snapshot: term()
   }}
  | {:error, term()}

run(thread, input, opts \\ %{})

@spec run(
  %CodexEx.AppServer.Thread{
    client: term(),
    id: term(),
    settings: term(),
    snapshot: term()
  },
  list(),
  map()
) :: {:ok, CodexEx.AppServer.TurnStream.t()} | {:error, term()}

run_json(thread, text, output_schema, opts \\ %{})

@spec run_json(
  %CodexEx.AppServer.Thread{
    client: term(),
    id: term(),
    settings: term(),
    snapshot: term()
  },
  binary(),
  map(),
  map()
) :: {:ok, term()} | {:error, term()}

run_text(thread, text, opts \\ %{})

@spec run_text(
  %CodexEx.AppServer.Thread{
    client: term(),
    id: term(),
    settings: term(),
    snapshot: term()
  },
  binary(),
  map()
) :: {:ok, binary()} | {:error, term()}

set_goal(thread, attrs)

@spec set_goal(
  %CodexEx.AppServer.Thread{
    client: term(),
    id: term(),
    settings: term(),
    snapshot: term()
  },
  map()
) :: {:ok, CodexEx.AppServer.ThreadGoal.t()} | {:error, term()}

unarchive(thread)

@spec unarchive(%CodexEx.AppServer.Thread{
  client: term(),
  id: term(),
  settings: term(),
  snapshot: term()
}) ::
  {:ok,
   %CodexEx.AppServer.Thread{
     client: term(),
     id: term(),
     settings: term(),
     snapshot: term()
   }}
  | {:error, term()}