# Client and sessions

The client you connect with, and the session each test runs in. Every handle on the platform pages is reached from here.

Each call is shown in every SDK's language, with its required options (the table under it lists them all). Arguments go first; options are TypeScript's trailing object, Python's keyword arguments and Rust's builder setters. The variable names are the ones the calls return elsewhere on these pages, so `user` is a `user` handle.

Besides the errors listed with each method, most methods can fail with [`action_requires`](https://channelstack.dev/docs/reference/api/errors#action-requires), [`cross_workspace_credential`](https://channelstack.dev/docs/reference/api/errors#cross-workspace-credential), [`fake_actor_in_live_world`](https://channelstack.dev/docs/reference/api/errors#fake-actor-in-live-world), [`internal`](https://channelstack.dev/docs/reference/api/errors#internal), [`invalid_argument`](https://channelstack.dev/docs/reference/api/errors#invalid-argument), [`live_misconfigured`](https://channelstack.dev/docs/reference/api/errors#live-misconfigured), [`live_not_allowlisted`](https://channelstack.dev/docs/reference/api/errors#live-not-allowlisted), [`not_found`](https://channelstack.dev/docs/reference/api/errors#not-found), [`session_not_found`](https://channelstack.dev/docs/reference/api/errors#session-not-found), [`unauthorized`](https://channelstack.dev/docs/reference/api/errors#unauthorized), [`unsupported_in_live`](https://channelstack.dev/docs/reference/api/errors#unsupported-in-live): a bad request, a closed session, or live mode refusing or misconfigured.

## Channelstack

### status()

Server health, version and loaded drivers.

```ts title="TypeScript"
const status = await channelstack.status();
```

```python title="Python"
status = await channelstack.status()
```

```rust title="Rust"
let status = channelstack.status().await?;
```

**Returns** [`Status`](https://channelstack.dev/docs/reference/api/client#status-1).

### openSession()

Open a session: a scope in the shared world that owns what it creates.

```ts title="TypeScript"
const session = await channelstack.openSession({ name: "…" });
```

```python title="Python"
session = await channelstack.open_session(name="…")
```

```rust title="Rust"
let session = channelstack.open_session().name("…").await?;
```

| Parameter | Type     | Required |        |
| --------- | -------- | -------- | ------ |
| `name`    | `string` | no       | option |

**Returns** [`Session`](https://channelstack.dev/docs/reference/api/client#session).

### reset()

Drop the whole world. Avoid in parallel suites.

```ts title="TypeScript"
await channelstack.reset();
```

```python title="Python"
await channelstack.reset()
```

```rust title="Rust"
channelstack.reset().await?;
```

**Returns** nothing.

### env()

Env vars for the agent: fake tokens, signing secrets and API URLs (what `channelstack env` prints). With `proxy`, the proxy and the CA instead of the API URLs.

```ts title="TypeScript"
const env = await channelstack.env({ proxy });
```

```python title="Python"
env = await channelstack.env(proxy=proxy)
```

```rust title="Rust"
let env = channelstack.env().proxy(proxy).await?;
```

| Parameter | Type      | Required |        |
| --------- | --------- | -------- | ------ |
| `proxy`   | `boolean` | no       | option |
| `app`     | `string`  | no       | option |
| `channel` | `string`  | no       | option |

**Returns** [`Env`](https://channelstack.dev/docs/reference/api/client#env-1).

### uiLoginLink()

A new one-time link that opens the UI in a browser (what `channelstack ui` prints).

```ts title="TypeScript"
const uiLoginLink = await channelstack.uiLoginLink();
```

```python title="Python"
ui_login_link = await channelstack.ui_login_link()
```

```rust title="Rust"
let ui_login_link = channelstack.ui_login_link().await?;
```

**Returns** [`UiLoginLink`](https://channelstack.dev/docs/reference/api/client#uiloginlink-1).

## Session

Returned by [`Channelstack.openSession()`](https://channelstack.dev/docs/reference/api/client#opensession).

| Field       | Python / Rust | Type       |
| ----------- | ------------- | ---------- |
| `sessionId` | `session_id`  | `string`   |
| `drivers`   | `drivers`     | `string[]` |

### close()

Close a session and remove everything it created.

```ts title="TypeScript"
await session.close();
```

```python title="Python"
await session.close()
```

```rust title="Rust"
session.close().await?;
```

**Returns** nothing. Disposing the handle calls it.

### events()

The session's event log: actions, deliveries with every attempt, and the agent's API calls.

```ts title="TypeScript"
const eventPage = await session.events({ since: "…" });
```

```python title="Python"
event_page = await session.events(since="…")
```

```rust title="Rust"
let event_page = session.events().since("…").await?;
```

| Parameter | Type     | Required |        |
| --------- | -------- | -------- | ------ |
| `since`   | `string` | no       | option |

**Returns** [`EventPage`](https://channelstack.dev/docs/reference/api/client#eventpage).

### quiet()

Is the agent idle in this session, and for how long? Negative and exact-count matchers wait for this.

```ts title="TypeScript"
const quiet = await session.quiet();
```

```python title="Python"
quiet = await session.quiet()
```

```rust title="Rust"
let quiet = session.quiet().await?;
```

**Returns** [`Quiet`](https://channelstack.dev/docs/reference/api/client#quiet-1).

### echo()

The echo fixture: the agent's app and where it reaches the fake.

```ts title="TypeScript"
const echoFixture = await session.echo();
```

```python title="Python"
echo_fixture = await session.echo()
```

```rust title="Rust"
let echo_fixture = session.echo().await?;
```

**Returns** `EchoFixture`.

### slack()

The Slack fixture: the agent's app, the workspace, and where the agent reaches the fake.

```ts title="TypeScript"
const slack = await session.slack();
```

```python title="Python"
slack = await session.slack()
```

```rust title="Rust"
let slack = session.slack().await?;
```

**Returns** [`SlackFixture`](https://channelstack.dev/docs/reference/api/slack#slackfixture).

### github()

The GitHub fixture: the agent's App, the org, and where the agent reaches the fake.

```ts title="TypeScript"
const github = await session.github();
```

```python title="Python"
github = await session.github()
```

```rust title="Rust"
let github = session.github().await?;
```

**Returns** [`GitHubFixture`](https://channelstack.dev/docs/reference/api/github#githubfixture).

### linear()

The Linear fixture: the agent's app, and where the agent reaches the fake.

```ts title="TypeScript"
const linear = await session.linear();
```

```python title="Python"
linear = await session.linear()
```

```rust title="Rust"
let linear = session.linear().await?;
```

**Returns** [`LinearFixture`](https://channelstack.dev/docs/reference/api/linear#linearfixture).

### notion()

The Notion fixture: the agent's integration, and where the agent reaches the fake.

```ts title="TypeScript"
const notion = await session.notion();
```

```python title="Python"
notion = await session.notion()
```

```rust title="Rust"
let notion = session.notion().await?;
```

**Returns** [`NotionFixture`](https://channelstack.dev/docs/reference/api/notion#notionfixture).

### resend()

The Resend fixture: the agent's team, and where the agent reaches the fake.

```ts title="TypeScript"
const resend = await session.resend();
```

```python title="Python"
resend = await session.resend()
```

```rust title="Rust"
let resend = session.resend().await?;
```

**Returns** [`ResendFixture`](https://channelstack.dev/docs/reference/api/resend#resendfixture).

### google()

The Google fixture: the agent's mailbox, and where the agent reaches the fake.

```ts title="TypeScript"
const google = await session.google();
```

```python title="Python"
google = await session.google()
```

```rust title="Rust"
let google = session.google().await?;
```

**Returns** [`GoogleFixture`](https://channelstack.dev/docs/reference/api/google#googlefixture).

### discord()

The Discord fixture: the agent's app, the guild, and where the agent reaches the fake.

```ts title="TypeScript"
const discord = await session.discord();
```

```python title="Python"
discord = await session.discord()
```

```rust title="Rust"
let discord = session.discord().await?;
```

**Returns** [`DiscordFixture`](https://channelstack.dev/docs/reference/api/discord#discordfixture).

### openai()

The OpenAI fixture: where the agent reaches the fake model.

```ts title="TypeScript"
const openai = await session.openai();
```

```python title="Python"
openai = await session.openai()
```

```rust title="Rust"
let openai = session.openai().await?;
```

**Returns** [`OpenAIFixture`](https://channelstack.dev/docs/reference/api/openai#openaifixture).

### places()

Every channel's places in the session, as the dev tools name them (a Slack channel, a GitHub issue, a Notion page, an email thread, a Discord channel), the most recently active last.

```ts title="TypeScript"
const places = await session.places();
```

```python title="Python"
places = await session.places()
```

```rust title="Rust"
let places = session.places().await?;
```

**Returns** [`Places`](https://channelstack.dev/docs/reference/api/client#places-1).

## Place

| Field     | Type                  |
| --------- | --------------------- |
| `channel` | `string`              |
| `title`   | `string`              |
| `id`      | `string`              |
| `name`    | `string`              |
| `active`  | `string \| undefined` |

### transcript()

A place as a person reads it: the transcript its channel's own transcript route has.

```ts title="TypeScript"
const placeTranscript = await place.transcript();
```

```python title="Python"
place_transcript = await place.transcript()
```

```rust title="Rust"
let place_transcript = place.transcript().await?;
```

**Returns** [`PlaceTranscript`](https://channelstack.dev/docs/reference/api/client#placetranscript).

## Types

Plain values the handles return and take.

### Status

| Field     | Type       |
| --------- | ---------- |
| `ready`   | `boolean`  |
| `version` | `string`   |
| `drivers` | `string[]` |

### EventPage

| Field    | Type         |
| -------- | ------------ |
| `events` | `LogEvent[]` |
| `cursor` | `string`     |

### LogEvent

| Field     | Type                                                                       |
| --------- | -------------------------------------------------------------------------- |
| `at`      | `string`                                                                   |
| `driver`  | `string`                                                                   |
| `kind`    | `"action" \| "delivery" \| "delivery_attempt" \| "api_call" \| "bot_loop"` |
| `data`    | `Record<string, unknown>`                                                  |
| `summary` | `{ text: string; outcome: string; ok: boolean } \| undefined`              |

### Quiet

| Field        | Python / Rust  | Type                    |
| ------------ | -------------- | ----------------------- |
| `busy`       | `busy`         | `boolean`               |
| `quietForMs` | `quiet_for_ms` | `number`                |
| `open`       | `open`         | `string[]`              |
| `problems`   | `problems`     | `string[]`              |
| `loops`      | `loops`        | `string[] \| undefined` |

### Env

```ts
type Env = Record<string, string>;
```

### Capabilities

```ts
type Capabilities = Record<string, Capability>;
```

### Capability

| Field          | Python / Rust   | Type       |
| -------------- | --------------- | ---------- |
| `fake`         | `fake`          | `boolean`  |
| `live`         | `live`          | `boolean`  |
| `liveRequires` | `live_requires` | `string[]` |

### DeliveryAttempt

| Field             | Python / Rust      | Type                                                                      |
| ----------------- | ------------------ | ------------------------------------------------------------------------- |
| `number`          | `number`           | `number`                                                                  |
| `sentAt`          | `sent_at`          | `string`                                                                  |
| `transport`       | `transport`        | `"http" \| "socket"`                                                      |
| `url`             | `url`              | `string \| undefined`                                                     |
| `requestHeaders`  | `request_headers`  | `Record<string, string>`                                                  |
| `status`          | `status`           | `"pending" \| "acknowledged" \| "failed" \| "timed_out" \| "unreachable"` |
| `responseStatus`  | `response_status`  | `number \| undefined`                                                     |
| `responseBody`    | `response_body`    | `string \| undefined`                                                     |
| `durationMs`      | `duration_ms`      | `number \| undefined`                                                     |
| `forgedSignature` | `forged_signature` | `boolean`                                                                 |

### Places

```ts
type Places = Place[];
```

### PlaceTranscript

| Field     | Type                     |
| --------- | ------------------------ |
| `entries` | `PlaceTranscriptEntry[]` |
| `text`    | `string`                 |

### PlaceTranscriptEntry

| Field       | Python / Rust | Type                                              |
| ----------- | ------------- | ------------------------------------------------- |
| `id`        | `id`          | `string`                                          |
| `author`    | `author`      | `PlacePrincipal`                                  |
| `at`        | `at`          | `string`                                          |
| `text`      | `text`        | `string`                                          |
| `controls`  | `controls`    | `string[]`                                        |
| `edited`    | `edited`      | `boolean`                                         |
| `depth`     | `depth`       | `number`                                          |
| `streaming` | `streaming`   | `"open" \| "stopped" \| "completed" \| undefined` |
| `visibleTo` | `visible_to`  | `PlacePrincipal \| undefined`                     |

### PlacePrincipal

| Field  | Type              |
| ------ | ----------------- |
| `id`   | `string`          |
| `name` | `string`          |
| `kind` | `"user" \| "app"` |

### UiLoginLink

| Field | Type     |
| ----- | -------- |
| `url` | `string` |
