# `Jidoka.Session`
[🔗](https://github.com/agentjido/jidoka/blob/v0.9.0/lib/jidoka/session.ex#L1)

Ergonomic session facade backed by `Jidoka.Session.Data`.

`Jidoka.Session.Data` is the durable data contract. This module is the
developer-facing API for starting, running, resuming, and inspecting sessions
without reaching into lower-level execution modules for common workflows.

# `agent_input`

```elixir
@type agent_input() :: Jidoka.Turn.Plan.input()
```

# `async_result`

```elixir
@type async_result() :: {:ok, Jidoka.Chat.Request.t()} | {:error, term()}
```

# `chat_result`

```elixir
@type chat_result() ::
  {:ok, t(), String.t()}
  | {:hibernate, t(), Jidoka.Snapshot.t()}
  | {:cancelled, Jidoka.Cancellation.t()}
  | {:error, term()}
```

# `opts`

```elixir
@type opts() :: keyword()
```

# `request_input`

```elixir
@type request_input() :: Jidoka.Turn.Request.input()
```

# `run_result`

```elixir
@type run_result() ::
  {:ok, t(), Jidoka.Turn.Result.t()}
  | {:hibernate, t(), Jidoka.Snapshot.t()}
  | {:error, term()}
```

# `session_input`

```elixir
@type session_input() :: t() | String.t()
```

# `t`

```elixir
@type t() :: Jidoka.Session.Data.t()
```

# `await`

```elixir
@spec await(Jidoka.Chat.Request.t(), opts()) :: chat_result()
```

Waits for a request handle returned by `chat_async/3`.

# `cancel`

```elixir
@spec cancel(Jidoka.Chat.Request.t(), opts()) ::
  {:ok, Jidoka.Cancellation.t()} | {:error, term()}
```

Cancels an active asynchronous session request.

# `chat`

```elixir
@spec chat(session_input(), String.t(), opts()) :: chat_result()
```

Runs one turn for a session and returns final assistant text.

The updated session is returned with the text so caller-managed sessions do
not lose durable state when no store is configured.

# `chat_async`

```elixir
@spec chat_async(session_input(), String.t(), opts()) :: async_result()
```

Starts one session chat turn asynchronously.

Pass `stream: true` to stream request-scoped `Jidoka.Event` values to the
caller mailbox while the request is running.

# `fork`

```elixir
@spec fork(session_input(), opts()) :: {:ok, t()} | {:error, term()}
```

Creates a new session from a safe snapshot in an existing session.

The source session stays unchanged. By default, this function forks the
latest snapshot. Pass `snapshot:` to select another stored snapshot.

# `get`

```elixir
@spec get(Jidoka.Session.Store.store(), String.t()) :: {:ok, t()} | {:error, term()}
```

Fetches a persisted session from a configured session store.

# `list`

```elixir
@spec list(Jidoka.Session.Store.store()) :: {:ok, [t()]} | {:error, term()}
```

Lists persisted sessions from a configured session store.

# `pending_reviews`

```elixir
@spec pending_reviews(t() | Jidoka.Session.Store.store()) ::
  {:ok, [Jidoka.Review.Request.t()]} | {:error, term()}
```

Lists pending human-review requests from a session or session store.

# `recover`

```elixir
@spec recover(String.t(), opts()) :: run_result()
```

Recovers a session after its durable worker lease expires.

# `recoverable`

```elixir
@spec recoverable(Jidoka.Session.Store.store(), opts()) ::
  {:ok, [t()]} | {:error, term()}
```

Lists stored sessions that are ready for crash recovery.

# `replay`

```elixir
@spec replay(t()) :: {:ok, Jidoka.Session.Replay.t()} | {:error, term()}
```

Returns a data-only replay view for a session.

# `resume`

```elixir
@spec resume(session_input(), opts()) :: run_result()
```

Resumes the latest hibernated snapshot for a session.

# `run`

```elixir
@spec run(session_input(), request_input(), opts()) :: run_result()
```

Runs one turn for a session and returns the full session result.

# `start`

```elixir
@spec start(agent_input(), opts() | String.t()) :: {:ok, t()} | {:error, term()}
```

Starts a new session for an agent, spec, or plan.

The returned value is a `Jidoka.Session.Data` struct. A DSL agent module is
accepted directly:

    {:ok, session} = Jidoka.Session.start(MyApp.SupportAgent, "support-123")

Pass `store: ...` to persist the session immediately.

# `start`

```elixir
@spec start(agent_input(), String.t(), opts()) :: {:ok, t()} | {:error, term()}
```

Starts a new session with an explicit session id.

# `write_memory`

```elixir
@spec write_memory(t(), String.t(), opts()) ::
  {:ok, Jidoka.Memory.WriteResult.t()} | {:error, term()}
```

Writes one memory entry through the configured memory store.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
