Skip to content

Commit

Permalink
docs: update context API docs (#1162)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yonom authored Nov 13, 2024
1 parent 4fd56db commit b45c8f1
Showing 1 changed file with 64 additions and 13 deletions.
77 changes: 64 additions & 13 deletions apps/docs/content/docs/reference/context.mdx
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
---
title: Context API
title: Runtime API
---

assistant-ui components and APIs use React Context to store information and interact with the runtime.

The context is split into four hierarchies:

- **Assistant Context**: Wraps your entire app. An app can contain multiple threads.
- **Thread Context**: Provides access to the thread state. A thread can contain multiple messages.
- **Message Context**: Provides access to the message state. A message can contain multiple content parts.
- **Content Part Context**: Provides access to the content part state.
The runtime API allows you to interact with the runtime in a standardized way.
This API is used internaly by the components. You can also use it to build your own UI components or functionality.

import { ParametersTable } from "@/components/docs";
import {
AssistantToolUIsState,
ThreadState,
ThreadMessagesState,
ThreadRuntimeState,
ComposerState,
Expand All @@ -26,9 +18,20 @@ import {
ComposerAttachmentState,
MessageAttachmentState,
} from "@/components/docs/parameters/context";
import { AssistantRuntime, ThreadRuntime } from "@/generated/typeDocs";
import {
AssistantRuntime,
ThreadListRuntime,
ThreadListState,
ThreadListItemRuntime,
ThreadListItemState,
ThreadRuntime,
ThreadState,
AssistantToolUIsState,
} from "@/generated/typeDocs";

## Assistant Context
## AssistantRuntime

The `AssistantRuntime` is the root runtime.

### `useAssistantRuntime`

Expand All @@ -40,6 +43,10 @@ const runtime = useAssistantRuntime();

<ParametersTable {...AssistantRuntime} />

## Tool UI Registry

The tool UI registry is used to display custom UI for tool calls, enabling generative UI.

### `useToolUIs`

```tsx
Expand All @@ -51,6 +58,50 @@ const webSearchToolUI = useToolUIs((m) => m.getToolUI("web_search"));

<ParametersTable {...AssistantToolUIsState} />

## ThreadListRuntime

### `threadList`

```tsx
import { useAssistantRuntime } from "@assistant-ui/react";

const threadListRuntime = useAssistantRuntime().threadList;
```

<ParametersTable {...ThreadListRuntime} />

### `useThreadList`

```tsx
import { useThreadList } from "@assistant-ui/react";

const threadList = useThreadList();
const threads = useThreadList((m) => m.threads);
```

## ThreadListItemRuntime

### `useThreadListItemRuntime`

```tsx
import { useThreadListItemRuntime } from "@assistant-ui/react";

const threadListItemRuntime = useThreadListItemRuntime();
```

<ParametersTable {...ThreadListItemRuntime} />

### `useThreadListItem`

```tsx
import { useThreadListItem } from "@assistant-ui/react";

const threadListItem = useThreadListItem();
const title = useThreadListItem((m) => m.title);
```

<ParametersTable {...ThreadListItemState} />

## Thread Context

### `useThreadRuntime`
Expand Down

0 comments on commit b45c8f1

Please sign in to comment.