Skip to content

The Open Standard for Generative UI

Add API reference documentation (#105)

Hrijul Bhatnagar52e928c6663b
diff --git a/docs/custom/plugins/inject-custom-docs.mjs b/docs/custom/plugins/inject-custom-docs.mjs
index 913d9cf0f..fc010e2ac 100644
--- a/docs/custom/plugins/inject-custom-docs.mjs
+++ b/docs/custom/plugins/inject-custom-docs.mjs
@@ -9,13 +9,11 @@ export function load(app) {
app.renderer.markdownHooks.on("page.begin", (page) => {
const dirname = path.dirname(new URL(import.meta.url).pathname);
const customFilePath = page.page.filename.split("/").slice(-5).join("/"); // -5 because we want the path starting from the reference directory
- const filePath = path.resolve(
- dirname,
- "..",
- customFilePath
- );
+ const filePath = path.resolve(dirname, "..", customFilePath);
if (fs.existsSync(filePath)) {
- return fs.readFileSync(filePath, "utf-8");
+ const fileContent = fs.readFileSync(filePath, "utf-8");
+ const separatedFileContent = fileContent.concat("\n---\n");
+ return separatedFileContent;
}
});
}
diff --git a/docs/custom/reference/js/react-core/functions/ChatProvider.md b/docs/custom/reference/js/react-core/functions/ChatProvider.md
new file mode 100644
index 000000000..6d5fca314
--- /dev/null
+++ b/docs/custom/reference/js/react-core/functions/ChatProvider.md
@@ -0,0 +1,20 @@
+ChatProvider is a top-level React context provider component that makes it possible for hooks like the [`useThreadListManager`](../functions/useThreadListManager.md) and
+[`useThreadManager`](../functions/useThreadManager) to work. It contains the entire application context, including the [`ThreadManager`](../type-aliases/ThreadManager.md)
+and [`ThreadListManager`](../type-aliases/ThreadListManager.md).
+
+## Props
+
+| Prop | Description |
+| ------------------- | ------------------------------------------------------------------------------------------------------------ |
+| `threadManager` | The [ThreadManager](../type-aliases/ThreadManager.md) instance for handling individual chat threads |
+| `threadListManager` | The [ThreadListManager](../type-aliases/ThreadListManager.md) instance for handling the list of chat threads |
+| `children` | The child components that will be provided and will have access to this chat context |
+
+## Example
+
+```tsx
+<ChatProvider
+ threadManager={myThreadManager}
+ threadListManager={myThreadListManager}
+>
+```
diff --git a/docs/custom/reference/js/react-core/functions/processStreamedMessage.md b/docs/custom/reference/js/react-core/functions/processStreamedMessage.md
new file mode 100644
index 000000000..a2424b3f2
--- /dev/null
+++ b/docs/custom/reference/js/react-core/functions/processStreamedMessage.md
@@ -0,0 +1,14 @@
+A utility function that helps process a streamed assistant message from the server. It takes functions to create, update and delete messages,
+and calls them as necessary on the required message when a streamed response is received. Generally helpful when defining the `processMessage`
+function in [`ThreadManager`](../type-aliases/ThreadManager.md) using [`useThreadManager`](../functions/useThreadManager.md).
+
+## Example
+
+```ts
+await processStreamedMessage({
+ response,
+ createMessage: threadManager.appendMessages,
+ updateMessage: threadManager.updateMessage,
+ deleteMessage: threadManager.deleteMessage,
+});
+```
diff --git a/docs/custom/reference/js/react-core/functions/useThreadManagerSelector.md b/docs/custom/reference/js/react-core/functions/useThreadManagerSelector.md
new file mode 100644
index 000000000..34a1653e2
--- /dev/null
+++ b/docs/custom/reference/js/react-core/functions/useThreadManagerSelector.md
@@ -0,0 +1,18 @@
+`useThreadManagerSelector` allows you to efficiently extract one or more values from the [`ThreadManager`](../type-aliases/ThreadManager.md) instance
+without having to access the entire [`ThreadManager`](../type-aliases/ThreadManager.md).
+
+## Example:
+
+```ts
+interface MessagesAndTemplates {
+ messages: Message[];
+ templates: ResponseTemplate[];
+}
+
+const { messages, templates } = useThreadManagerSelector<MessagesAndTemplates>(
+ (threadManager) => ({
+ messages: threadManager.messages,
+ templates: Object.values(threadManager.responseTemplates),
+ })
+);
+```
diff --git a/docs/custom/reference/js/react-core/interfaces/ResponseTemplate.md b/docs/custom/reference/js/react-core/interfaces/ResponseTemplate.md
new file mode 100644
index 000000000..70c0db275
--- /dev/null
+++ b/docs/custom/reference/js/react-core/interfaces/ResponseTemplate.md
@@ -0,0 +1,3 @@
+A type that contains information about the name of the response template and the React component required to render the response template with that name.
+For detailed information on response templates, see [Core Concepts](../../../../concepts/001-core-concepts.md#response-templates), and for a guide on how to implement and use response templates,
+see [Creating Response Templates](../../../../guides/customization/007-response-templates.mdx).
diff --git a/docs/custom/reference/js/react-core/type-aliases/ThreadListManager.md b/docs/custom/reference/js/react-core/type-aliases/ThreadListManager.md
new file mode 100644
index 000000000..f64889e27
--- /dev/null
+++ b/docs/custom/reference/js/react-core/type-aliases/ThreadListManager.md
@@ -0,0 +1,2 @@
+The Thread List Manager is an entity that encapsulates the [`ThreadListState`](./ThreadListState.md) and actions ([`ThreadListActions`](./ThreadListActions.md)) that help modify the state.
+It can be passed to the `ChatProvider` or the `CrayonChat` component to dictate how a thread list should be managed, and what APIs should be called on each event.
diff --git a/docs/custom/reference/js/react-core/type-aliases/ThreadManager.md b/docs/custom/reference/js/react-core/type-aliases/ThreadManager.md
new file mode 100644
index 000000000..68976fa39
--- /dev/null
+++ b/docs/custom/reference/js/react-core/type-aliases/ThreadManager.md
@@ -0,0 +1,2 @@
+The Thread Manager is an entity that encapsulates the [`ThreadState`](./ThreadState.md) and actions ([`ThreadActions`](./ThreadActions.md)) that help modify the state.
+It can be passed to the `ChatProvider` or the `CrayonChat` component to dictate how a thread should be managed, and what APIs should be called on each event.
diff --git a/docs/docs/reference/js/react-core/functions/ChatProvider.md b/docs/docs/reference/js/react-core/functions/ChatProvider.md
index 4d197661d..90391643c 100644
--- a/docs/docs/reference/js/react-core/functions/ChatProvider.md
+++ b/docs/docs/reference/js/react-core/functions/ChatProvider.md
@@ -1,10 +1,33 @@
+ChatProvider is a top-level React context provider component that makes it possible for hooks like the [`useThreadListManager`](../functions/useThreadListManager.md) and
+[`useThreadManager`](../functions/useThreadManager) to work. It contains the entire application context, including the [`ThreadManager`](../type-aliases/ThreadManager.md)
+and [`ThreadListManager`](../type-aliases/ThreadListManager.md).
+
+## Props
+
+| Prop | Description |
+| ------------------- | ------------------------------------------------------------------------------------------------------------ |
+| `threadManager` | The [ThreadManager](../type-aliases/ThreadManager.md) instance for handling individual chat threads |
+| `threadListManager` | The [ThreadListManager](../type-aliases/ThreadListManager.md) instance for handling the list of chat threads |
+| `children` | The child components that will be provided and will have access to this chat context |
+
+## Example
+
+```tsx
+<ChatProvider
+ threadManager={myThreadManager}
+ threadListManager={myThreadListManager}
+>
+```
+
+---
+
```ts
function ChatProvider(
props: PropsWithChildren<ChatManager>,
): ReactNode | Promise<ReactNode>;
```
-Defined in: [packages/react-core/src/ChatProvider.tsx:30](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/ChatProvider.tsx#L30)
+Defined in: [js/packages/react-core/src/ChatProvider.tsx:10](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/ChatProvider.tsx#L10)
## Parameters
@@ -12,26 +35,6 @@ Defined in: [packages/react-core/src/ChatProvider.tsx:30](https://github.com/the
`PropsWithChildren`\<[`ChatManager`](../type-aliases/ChatManager.md)\>
-The component props
-
## Returns
`ReactNode` \| `Promise`\<`ReactNode`\>
-
-A ChatContext.Provider wrapping the children components
-
-## Remarks
-
-ChatProvider is a React component that provides chat management context to its children.
-It serves as the top-level provider for thread and thread list management functionality.
-
-## Example
-
-```tsx
-<ChatProvider
- threadManager={myThreadManager}
- threadListManager={myThreadListManager}
->
- <App />
-</ChatProvider>
-```
diff --git a/docs/docs/reference/js/react-core/functions/MessageContext.md b/docs/docs/reference/js/react-core/functions/MessageContext.md
index 44135e5e9..1b6d45629 100644
--- a/docs/docs/reference/js/react-core/functions/MessageContext.md
+++ b/docs/docs/reference/js/react-core/functions/MessageContext.md
@@ -6,7 +6,7 @@ function MessageContext(
): ReactNode;
```
-Defined in: [packages/react-core/src/hooks/useMessage.tsx:8](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/hooks/useMessage.tsx#L8)
+Defined in: [js/packages/react-core/src/hooks/useMessage.tsx:8](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useMessage.tsx#L8)
## Parameters
diff --git a/docs/docs/reference/js/react-core/functions/MessageProvider.md b/docs/docs/reference/js/react-core/functions/MessageProvider.md
index 7b9d323fe..fe3203f0c 100644
--- a/docs/docs/reference/js/react-core/functions/MessageProvider.md
+++ b/docs/docs/reference/js/react-core/functions/MessageProvider.md
@@ -5,7 +5,7 @@ function MessageProvider(__namedParameters: {
}): Element;
```
-Defined in: [packages/react-core/src/hooks/useMessage.tsx:25](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/hooks/useMessage.tsx#L25)
+Defined in: [js/packages/react-core/src/hooks/useMessage.tsx:25](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useMessage.tsx#L25)
## Parameters
diff --git a/docs/docs/reference/js/react-core/functions/processStreamedMessage.md b/docs/docs/reference/js/react-core/functions/processStreamedMessage.md
index 34d0840dd..a399b8780 100644
--- a/docs/docs/reference/js/react-core/functions/processStreamedMessage.md
+++ b/docs/docs/reference/js/react-core/functions/processStreamedMessage.md
@@ -1,3 +1,20 @@
+A utility function that helps process a streamed assistant message from the server. It takes functions to create, update and delete messages,
+and calls them as necessary on the required message when a streamed response is received. Generally helpful when defining the `processMessage`
+function in [`ThreadManager`](../type-aliases/ThreadManager.md) using [`useThreadManager`](../functions/useThreadManager.md).
+
+## Example
+
+```ts
+await processStreamedMessage({
+ response,
+ createMessage: threadManager.appendMessages,
+ updateMessage: threadManager.updateMessage,
+ deleteMessage: threadManager.deleteMessage,
+});
+```
+
+---
+
```ts
function processStreamedMessage(__namedParameters: {
createMessage: (message: AssistantMessage) => void;
@@ -7,7 +24,7 @@ function processStreamedMessage(__namedParameters: {
}): Promise<void>;
```
-Defined in: [packages/react-core/src/stream/processStreamedMessage.ts:16](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/stream/processStreamedMessage.ts#L16)
+Defined in: [js/packages/react-core/src/stream/processStreamedMessage.ts:29](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/stream/processStreamedMessage.ts#L29)
## Parameters
@@ -17,10 +34,14 @@ Defined in: [packages/react-core/src/stream/processStreamedMessage.ts:16](https:
(`message`: [`AssistantMessage`](../type-aliases/AssistantMessage.md)) => `void`
+A function that creates a new assistant message in the thread
+
#### deleteMessage
(`messageId`: `string`) => `void`
+A function that deletes an assistant message from the thread
+
#### response
`Response`
@@ -29,6 +50,8 @@ Defined in: [packages/react-core/src/stream/processStreamedMessage.ts:16](https:
(`message`: [`AssistantMessage`](../type-aliases/AssistantMessage.md)) => `void`
+A function that updates an existing assistant message in the thread
+
## Returns
`Promise`\<`void`\>
diff --git a/docs/docs/reference/js/react-core/functions/useMessage.md b/docs/docs/reference/js/react-core/functions/useMessage.md
index 45ea1284d..9f9f49821 100644
--- a/docs/docs/reference/js/react-core/functions/useMessage.md
+++ b/docs/docs/reference/js/react-core/functions/useMessage.md
@@ -4,7 +4,7 @@ function useMessage(): {
};
```
-Defined in: [packages/react-core/src/hooks/useMessage.tsx:14](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/hooks/useMessage.tsx#L14)
+Defined in: [js/packages/react-core/src/hooks/useMessage.tsx:14](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useMessage.tsx#L14)
## Returns
@@ -16,8 +16,6 @@ Defined in: [packages/react-core/src/hooks/useMessage.tsx:14](https://github.com
The current message. See [Message](../type-aliases/Message.md) for more information.
-### message
-
-```ts
-message: Message;
-```
+| Name | Type | Defined in |
+| ------------------------------ | --------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------- |
+| <a id="message"></a> `message` | [`Message`](../type-aliases/Message.md) | [js/packages/react-core/src/hooks/useMessage.tsx:8](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useMessage.tsx#L8) |
diff --git a/docs/docs/reference/js/react-core/functions/useThreadActions.md b/docs/docs/reference/js/react-core/functions/useThreadActions.md
index 88058989c..b8701b3a5 100644
--- a/docs/docs/reference/js/react-core/functions/useThreadActions.md
+++ b/docs/docs/reference/js/react-core/functions/useThreadActions.md
@@ -2,7 +2,9 @@
function useThreadActions(): ThreadActions;
```
-Defined in: [packages/react-core/src/hooks/useThreadActions.ts:8](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/hooks/useThreadActions.ts#L8)
+Defined in: [js/packages/react-core/src/hooks/useThreadActions.ts:10](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useThreadActions.ts#L10)
+
+`useThreadActions` allows you to modify the [ThreadState](../type-aliases/ThreadState.md) by providing access to [ThreadActions](../type-aliases/ThreadActions.md) which contains methods to modify the state.
## Returns
diff --git a/docs/docs/reference/js/react-core/functions/useThreadListActions.md b/docs/docs/reference/js/react-core/functions/useThreadListActions.md
index 3e3d35bf4..841a9bd2e 100644
--- a/docs/docs/reference/js/react-core/functions/useThreadListActions.md
+++ b/docs/docs/reference/js/react-core/functions/useThreadListActions.md
@@ -2,12 +2,10 @@
function useThreadListActions(): ThreadListActions;
```
-Defined in: [packages/react-core/src/hooks/useThreadListActions.ts:11](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/hooks/useThreadListActions.ts#L11)
+Defined in: [js/packages/react-core/src/hooks/useThreadListActions.ts:10](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useThreadListActions.ts#L10)
+
+`useThreadListActions` allows you to modify the [ThreadListState](../type-aliases/ThreadListState.md) by providing access to [ThreadListActions](../type-aliases/ThreadListActions.md) which contains methods to modify the state.
## Returns
[`ThreadListActions`](../type-aliases/ThreadListActions.md)
-
-## Remarks
-
-useThreadListActions
diff --git a/docs/docs/reference/js/react-core/functions/useThreadListManager.md b/docs/docs/reference/js/react-core/functions/useThreadListManager.md
index eb0b5eb03..1bead3aa8 100644
--- a/docs/docs/reference/js/react-core/functions/useThreadListManager.md
+++ b/docs/docs/reference/js/react-core/functions/useThreadListManager.md
@@ -9,7 +9,10 @@ function useThreadListManager(params: {
}): ThreadListManager;
```
-Defined in: [packages/react-core/src/useThreadListManager.ts:28](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/useThreadListManager.ts#L28)
+Defined in: [js/packages/react-core/src/useThreadListManager.ts:35](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadListManager.ts#L35)
+
+`useThreadListManager` takes the necessary arguments and helps create a [ThreadListManager](../type-aliases/ThreadListManager.md) instance. This instance is necessary to define how a thread list should
+be fetched, updated, deleted, and selected and which backend APIs should be called at any of these events or actions.
## Parameters
@@ -19,30 +22,38 @@ Defined in: [packages/react-core/src/useThreadListManager.ts:28](https://github.
(`firstMessage`: [`UserMessage`](../type-aliases/UserMessage.md)) => `Promise`\<[`Thread`](../type-aliases/Thread.md)\>
-Creates a new thread when user sends the first message
+Creates a new thread when the user sends the first message. Useful for integrating a backend API to create a new thread.
#### deleteThread
(`id`: `string`) => `Promise`\<`void`\>
+A function that defines how a thread should be deleted. Useful for integrating a backend API to delete a thread.
+
#### fetchThreadList
() => `Promise`\<[`Thread`](../type-aliases/Thread.md)[]\>
+A function that defines how the thread list should be fetched. Useful for integrating a backend API to fetch the thread list.
+
#### onSelectThread
(`threadId`: `string`) => `void`
+Runs when the user selects a thread
+
#### onSwitchToNew
() => `void`
-Allows user to clear chat state when switched to new thread
+Runs when the user switches to a new thread
#### updateThread
(`updated`: [`Thread`](../type-aliases/Thread.md)) => `Promise`\<[`Thread`](../type-aliases/Thread.md)\>
+A function that defines how a thread should be updated. Useful for integrating a backend API to update a thread.
+
## Returns
[`ThreadListManager`](../type-aliases/ThreadListManager.md)
diff --git a/docs/docs/reference/js/react-core/functions/useThreadListState.md b/docs/docs/reference/js/react-core/functions/useThreadListState.md
index e08a17029..92367ce42 100644
--- a/docs/docs/reference/js/react-core/functions/useThreadListState.md
+++ b/docs/docs/reference/js/react-core/functions/useThreadListState.md
@@ -2,12 +2,13 @@
function useThreadListState(): ThreadListState;
```
-Defined in: [packages/react-core/src/hooks/useThreadListState.ts:11](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/hooks/useThreadListState.ts#L11)
+Defined in: [js/packages/react-core/src/hooks/useThreadListState.ts:13](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useThreadListState.ts#L13)
-## Returns
+`useThreadListState` allows you to access the [ThreadListState](../type-aliases/ThreadListState.md). This is helpful for multiple reasons, including but not limited to:
-[`ThreadListState`](../type-aliases/ThreadListState.md)
+- You can use the state to render the thread list UI
+- You can use the state to trigger actions on the thread list
-## Remarks
+## Returns
-useThreadListState
+[`ThreadListState`](../type-aliases/ThreadListState.md)
diff --git a/docs/docs/reference/js/react-core/functions/useThreadManager.md b/docs/docs/reference/js/react-core/functions/useThreadManager.md
index 38daefda9..f5763124e 100644
--- a/docs/docs/reference/js/react-core/functions/useThreadManager.md
+++ b/docs/docs/reference/js/react-core/functions/useThreadManager.md
@@ -2,7 +2,15 @@
function useThreadManager(params: UseThreadManagerParams): ThreadManager;
```
-Defined in: [packages/react-core/src/useThreadManager.ts:27](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/useThreadManager.ts#L27)
+Defined in: [js/packages/react-core/src/useThreadManager.ts:41](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadManager.ts#L41)
+
+`useThreadManager` takes the necessary arguments and helps create a [ThreadManager](../type-aliases/ThreadManager.md) instance. This instance is necessary to define how a thread should
+be loaded and how a message in the thread should be processed or updated. This can be useful for multiple reasons, including but not limited to:
+
+- The hook makes it incredibly easy to manage the thread and does not require you to implement a thread manager from scratch manually
+- You can use the thread manager to load a thread from a backend API
+- You can use the thread manager to process a message and request the agent for the response
+- You can use the thread manager to update a message
## Parameters
diff --git a/docs/docs/reference/js/react-core/functions/useThreadManagerSelector.md b/docs/docs/reference/js/react-core/functions/useThreadManagerSelector.md
index 13d489963..c52b38dbb 100644
--- a/docs/docs/reference/js/react-core/functions/useThreadManagerSelector.md
+++ b/docs/docs/reference/js/react-core/functions/useThreadManagerSelector.md
@@ -1,23 +1,54 @@
+`useThreadManagerSelector` allows you to efficiently extract one or more values from the [`ThreadManager`](../type-aliases/ThreadManager.md) instance
+without having to access the entire [`ThreadManager`](../type-aliases/ThreadManager.md).
+
+## Example:
+
+```ts
+interface MessagesAndTemplates {
+ messages: Message[];
+ templates: ResponseTemplate[];
+}
+
+const { messages, templates } = useThreadManagerSelector<MessagesAndTemplates>(
+ (threadManager) => ({
+ messages: threadManager.messages,
+ templates: Object.values(threadManager.responseTemplates),
+ }),
+);
+```
+
+---
+
```ts
function useThreadManagerSelector<R>(accessor: AtomicAccessor<R>): R;
```
-Defined in: [packages/react-core/src/hooks/useThreadManagerSelector.ts:13](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/hooks/useThreadManagerSelector.ts#L13)
+Defined in: [js/packages/react-core/src/hooks/useThreadManagerSelector.ts:18](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useThreadManagerSelector.ts#L18)
## Type Parameters
• **R**
+The type of the value to be extracted from the [ThreadManager](../type-aliases/ThreadManager.md) instance. For example, `boolean | undefined`:
+
+```ts
+const isRunning = useThreadManagerSelector<boolean | undefined>(
+ (threadManager) => threadManager.isRunning,
+); // returning any other type throws an error
+```
+
+If no type is passed, one is inferred from the accessor function.
+
## Parameters
### accessor
`AtomicAccessor`\<`R`\>
+A function that is passed the [ThreadManager](../type-aliases/ThreadManager.md) instance as an argument and returns the value to be extracted.
+
## Returns
`R`
-## Remarks
-
-useThreadManager
+The value returned by the accessor function.
diff --git a/docs/docs/reference/js/react-core/functions/useThreadState.md b/docs/docs/reference/js/react-core/functions/useThreadState.md
index d45d8fb95..66a844584 100644
--- a/docs/docs/reference/js/react-core/functions/useThreadState.md
+++ b/docs/docs/reference/js/react-core/functions/useThreadState.md
@@ -2,12 +2,13 @@
function useThreadState(): ThreadState;
```
-Defined in: [packages/react-core/src/hooks/useThreadState.ts:11](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/hooks/useThreadState.ts#L11)
+Defined in: [js/packages/react-core/src/hooks/useThreadState.ts:13](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/hooks/useThreadState.ts#L13)
-## Returns
+`useThreadState` allows you to access the [ThreadState](../type-aliases/ThreadState.md). This is helpful for multiple reasons, including but not limited to:
-[`ThreadState`](../type-aliases/ThreadState.md)
+- You can use the state to render the thread UI
+- You can use the state to trigger actions on the thread
-## Remarks
+## Returns
-useThreadState
+[`ThreadState`](../type-aliases/ThreadState.md)
diff --git a/docs/docs/reference/js/react-core/index.md b/docs/docs/reference/js/react-core/index.md
index 2058d1aa3..b0200cd84 100644
--- a/docs/docs/reference/js/react-core/index.md
+++ b/docs/docs/reference/js/react-core/index.md
@@ -20,21 +20,7 @@ This package provides the core framework and hooks for managing state and agents
</td>
<td>
-**Remarks**
-
-ChatProvider is a React component that provides chat management context to its children.
-It serves as the top-level provider for thread and thread list management functionality.
-
-**Example**
-
-```tsx
-<ChatProvider
- threadManager={myThreadManager}
- threadListManager={myThreadListManager}
->
- <App />
-</ChatProvider>
-```
+&hyphen;
</td>
</tr>
@@ -108,7 +94,7 @@ It serves as the top-level provider for thread and thread list management functi
</td>
<td>
-&hyphen;
+`useThreadActions` allows you to modify the [ThreadState](type-aliases/ThreadState.md) by providing access to [ThreadActions](type-aliases/ThreadActions.md) which contains methods to modify the state.
</td>
</tr>
@@ -120,9 +106,7 @@ It serves as the top-level provider for thread and thread list management functi
</td>
<td>
-**Remarks**
-
-useThreadListActions
+`useThreadListActions` allows you to modify the [ThreadListState](type-aliases/ThreadListState.md) by providing access to [ThreadListActions](type-aliases/ThreadListActions.md) which contains methods to modify the state.
</td>
</tr>
@@ -134,7 +118,8 @@ useThreadListActions
</td>
<td>
-&hyphen;
+`useThreadListManager` takes the necessary arguments and helps create a [ThreadListManager](type-aliases/ThreadListManager.md) instance. This instance is necessary to define how a thread list should
+be fetched, updated, deleted, and selected and which backend APIs should be called at any of these events or actions.
</td>
</tr>
@@ -146,9 +131,10 @@ useThreadListActions
</td>
<td>
-**Remarks**
+`useThreadListState` allows you to access the [ThreadListState](type-aliases/ThreadListState.md). This is helpful for multiple reasons, including but not limited to:
-useThreadListState
+- You can use the state to render the thread list UI
+- You can use the state to trigger actions on the thread list
</td>
</tr>
@@ -160,7 +146,13 @@ useThreadListState
</td>
<td>
-&hyphen;
+`useThreadManager` takes the necessary arguments and helps create a [ThreadManager](type-aliases/ThreadManager.md) instance. This instance is necessary to define how a thread should
+be loaded and how a message in the thread should be processed or updated. This can be useful for multiple reasons, including but not limited to:
+
+- The hook makes it incredibly easy to manage the thread and does not require you to implement a thread manager from scratch manually
+- You can use the thread manager to load a thread from a backend API
+- You can use the thread manager to process a message and request the agent for the response
+- You can use the thread manager to update a message
</td>
</tr>
@@ -172,9 +164,7 @@ useThreadListState
</td>
<td>
-**Remarks**
-
-useThreadManager
+&hyphen;
</td>
</tr>
@@ -186,9 +176,10 @@ useThreadManager
</td>
<td>
-**Remarks**
+`useThreadState` allows you to access the [ThreadState](type-aliases/ThreadState.md). This is helpful for multiple reasons, including but not limited to:
-useThreadState
+- You can use the state to render the thread UI
+- You can use the state to trigger actions on the thread
</td>
</tr>
@@ -225,7 +216,7 @@ useThreadState
</td>
<td>
-&hyphen;
+A type that represents a message sent by the assistant / agent
</td>
</tr>
@@ -249,7 +240,7 @@ Main chat manager combining thread and thread list management
</td>
<td>
-Represents a message being created, with an optional ID
+Contains all of the information required to create a message. Usually passed to the [ThreadManager](type-aliases/ThreadManager.md)'s `processMessage` method.
</td>
</tr>
@@ -261,7 +252,7 @@ Represents a message being created, with an optional ID
</td>
<td>
-See [UserMessage](type-aliases/UserMessage.md) and [AssistantMessage](type-aliases/AssistantMessage.md) for more information.
+Represents a message in a [Thread](type-aliases/Thread.md). See [UserMessage](type-aliases/UserMessage.md) and [AssistantMessage](type-aliases/AssistantMessage.md) for more information.
</td>
</tr>
@@ -285,11 +276,7 @@ Represents a chat thread
</td>
<td>
-Actions available for managing a thread
-
-**Template**
-
-The message type used in the thread
+Actions available for managing the state of a thread
</td>
</tr>
@@ -301,7 +288,7 @@ The message type used in the thread
</td>
<td>
-Actions available for managing the thread list
+Actions available for managing the state of a thread list
</td>
</tr>
@@ -313,7 +300,7 @@ Actions available for managing the thread list
</td>
<td>
-Combines thread list state and actions
+&hyphen;
</td>
</tr>
@@ -337,11 +324,7 @@ Represents the state of the thread list
</td>
<td>
-Combines thread state and actions
-
-**Template**
-
-The message type used in the thread
+&hyphen;
</td>
</tr>
@@ -365,7 +348,7 @@ Represents the state of a thread
</td>
<td>
-&hyphen;
+A type that represents a message sent by the user
</td>
</tr>
diff --git a/docs/docs/reference/js/react-core/interfaces/ResponseTemplate.md b/docs/docs/reference/js/react-core/interfaces/ResponseTemplate.md
index ead9c3a35..2264226a9 100644
--- a/docs/docs/reference/js/react-core/interfaces/ResponseTemplate.md
+++ b/docs/docs/reference/js/react-core/interfaces/ResponseTemplate.md
@@ -1,8 +1,14 @@
-Defined in: [packages/react-core/src/types/responseTemplate.ts:4](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/responseTemplate.ts#L4)
+A type that contains information about the name of the response template and the React component required to render the response template with that name.
+For detailed information on response templates, see [Core Concepts](../../../../concepts/001-core-concepts.md#response-templates), and for a guide on how to implement and use response templates,
+see [Creating Response Templates](../../../../guides/customization/007-response-templates.mdx).
+
+---
+
+Defined in: [js/packages/react-core/src/types/responseTemplate.ts:4](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/responseTemplate.ts#L4)
## Properties
-| Property | Type | Defined in |
-| ---------------------------------- | ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
-| <a id="component"></a> `Component` | `ComponentType`\<`any`\> | [packages/react-core/src/types/responseTemplate.ts:6](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/responseTemplate.ts#L6) |
-| <a id="name"></a> `name` | `string` | [packages/react-core/src/types/responseTemplate.ts:5](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/responseTemplate.ts#L5) |
+| Property | Type | Defined in |
+| ---------------------------------- | ------------------------ | --------------------------------------------------------------------------------------------------------------------------------------------------------------- |
+| <a id="component"></a> `Component` | `ComponentType`\<`any`\> | [js/packages/react-core/src/types/responseTemplate.ts:6](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/responseTemplate.ts#L6) |
+| <a id="name"></a> `name` | `string` | [js/packages/react-core/src/types/responseTemplate.ts:5](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/responseTemplate.ts#L5) |
diff --git a/docs/docs/reference/js/react-core/type-aliases/AssistantMessage.md b/docs/docs/reference/js/react-core/type-aliases/AssistantMessage.md
index ec3849880..cd1eb81de 100644
--- a/docs/docs/reference/js/react-core/type-aliases/AssistantMessage.md
+++ b/docs/docs/reference/js/react-core/type-aliases/AssistantMessage.md
@@ -19,47 +19,155 @@ type AssistantMessage = {
};
```
-Defined in: [packages/react-core/src/types/message.ts:25](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/message.ts#L25)
+Defined in: [js/packages/react-core/src/types/message.ts:33](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L33)
+
+A type that represents a message sent by the assistant / agent
## Type declaration
-### id
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-id: string;
-```
+`id`
-### isVisuallyHidden?
+</td>
+<td>
-```ts
-optional isVisuallyHidden: boolean;
-```
+`string`
+
+</td>
+<td>
+
+The unique identifier of the message
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:8](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L8)
+
+</td>
+</tr>
+<tr>
+<td>
+
+`isVisuallyHidden`?
+
+</td>
+<td>
+
+`boolean`
+
+</td>
+<td>
+
+Whether the message should be visually hidden from the user on the UI
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:10](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L10)
+
+</td>
+</tr>
+</tbody>
+</table>
## Type declaration
-### context?
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-optional context: JSONValue[];
-```
+`context`?
-### message?
+</td>
+<td>
-```ts
-optional message: (
- | {
- text: string;
- type: "text";
- }
- | {
- name: string;
- templateProps: any;
- type: "template";
- })[];
-```
+`JSONValue`[]
-### role
+</td>
+<td>
-```ts
-role: "assistant";
-```
+Additional data associated with the message
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:36](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L36)
+
+</td>
+</tr>
+<tr>
+<td>
+
+`message`?
+
+</td>
+<td>
+
+(
+\| \{
+`text`: `string`;
+`type`: `"text"`;
+\}
+\| \{
+`name`: `string`;
+`templateProps`: `any`;
+`type`: `"template"`;
+\})[]
+
+</td>
+<td>
+
+The message content, either in a text format or a template (with the name of the response template and the props of the component that renders the template)
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:38](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L38)
+
+</td>
+</tr>
+<tr>
+<td>
+
+`role`
+
+</td>
+<td>
+
+`"assistant"`
+
+</td>
+<td>
+
+&hyphen;
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:34](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L34)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/ChatManager.md b/docs/docs/reference/js/react-core/type-aliases/ChatManager.md
index 419ce883c..51d7371a4 100644
--- a/docs/docs/reference/js/react-core/type-aliases/ChatManager.md
+++ b/docs/docs/reference/js/react-core/type-aliases/ChatManager.md
@@ -5,20 +5,65 @@ type ChatManager = {
};
```
-Defined in: [packages/react-core/src/types/chatManager.ts:99](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/chatManager.ts#L99)
+Defined in: [js/packages/react-core/src/types/chatManager.ts:116](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L116)
Main chat manager combining thread and thread list management
## Type declaration
-### threadListManager
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-threadListManager: ThreadListManager;
-```
+<a id="threadlistmanager"></a> `threadListManager`
-### threadManager
+</td>
+<td>
-```ts
-threadManager: ThreadManager;
-```
+[`ThreadListManager`](ThreadListManager.md)
+
+</td>
+<td>
+
+The thread list manager, a combination of thread list state and actions
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:118](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L118)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="threadmanager"></a> `threadManager`
+
+</td>
+<td>
+
+[`ThreadManager`](ThreadManager.md)
+
+</td>
+<td>
+
+The thread manager, a combination of thread state and actions
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:120](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L120)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/CreateMessage.md b/docs/docs/reference/js/react-core/type-aliases/CreateMessage.md
index aadff024d..9f70c3d51 100644
--- a/docs/docs/reference/js/react-core/type-aliases/CreateMessage.md
+++ b/docs/docs/reference/js/react-core/type-aliases/CreateMessage.md
@@ -1,7 +1,138 @@
```ts
-type CreateMessage = Omit<UserMessage, "id">;
+type CreateMessage = {
+ context: JSONValue[];
+ isVisuallyHidden: boolean;
+ message: string;
+ role: "user";
+ type: "prompt";
+};
```
-Defined in: [packages/react-core/src/types/message.ts:54](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/message.ts#L54)
+Defined in: [js/packages/react-core/src/types/message.ts:66](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L66)
-Represents a message being created, with an optional ID
+Contains all of the information required to create a message. Usually passed to the [ThreadManager](ThreadManager.md)'s `processMessage` method.
+
+## Type declaration
+
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
+
+<a id="context"></a> `context`?
+
+</td>
+<td>
+
+`JSONValue`[]
+
+</td>
+<td>
+
+Additional data associated with the message
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:25](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L25)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="isvisuallyhidden"></a> `isVisuallyHidden`?
+
+</td>
+<td>
+
+`boolean`
+
+</td>
+<td>
+
+Whether the message should be visually hidden from the user on the UI
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:10](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L10)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="message"></a> `message`?
+
+</td>
+<td>
+
+`string`
+
+</td>
+<td>
+
+The message content as a string
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:23](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L23)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="role"></a> `role`
+
+</td>
+<td>
+
+`"user"`
+
+</td>
+<td>
+
+&hyphen;
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:19](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L19)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="type"></a> `type`
+
+</td>
+<td>
+
+`"prompt"`
+
+</td>
+<td>
+
+&hyphen;
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:21](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L21)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/Message.md b/docs/docs/reference/js/react-core/type-aliases/Message.md
index 197b6da40..a9a82bdb0 100644
--- a/docs/docs/reference/js/react-core/type-aliases/Message.md
+++ b/docs/docs/reference/js/react-core/type-aliases/Message.md
@@ -2,6 +2,6 @@
type Message = UserMessage | AssistantMessage;
```
-Defined in: [packages/react-core/src/types/message.ts:46](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/message.ts#L46)
+Defined in: [js/packages/react-core/src/types/message.ts:58](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L58)
-See [UserMessage](UserMessage.md) and [AssistantMessage](AssistantMessage.md) for more information.
+Represents a message in a [Thread](Thread.md). See [UserMessage](UserMessage.md) and [AssistantMessage](AssistantMessage.md) for more information.
diff --git a/docs/docs/reference/js/react-core/type-aliases/Thread.md b/docs/docs/reference/js/react-core/type-aliases/Thread.md
index 004b1df0f..df87aaf91 100644
--- a/docs/docs/reference/js/react-core/type-aliases/Thread.md
+++ b/docs/docs/reference/js/react-core/type-aliases/Thread.md
@@ -7,40 +7,109 @@ type Thread = {
};
```
-Defined in: [packages/react-core/src/types/chatManager.ts:9](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/chatManager.ts#L9)
+Defined in: [js/packages/react-core/src/types/chatManager.ts:9](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L9)
Represents a chat thread
## Type declaration
-### createdAt
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-createdAt: Date;
-```
+<a id="createdat"></a> `createdAt`
+
+</td>
+<td>
+
+`Date`
+
+</td>
+<td>
Creation timestamp
-### isRunning?
+</td>
+<td>
-```ts
-optional isRunning: boolean;
-```
+[js/packages/react-core/src/types/chatManager.ts:15](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L15)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="isrunning"></a> `isRunning`?
+
+</td>
+<td>
+
+`boolean`
+
+</td>
+<td>
Indicates if the thread is currently processing
-### threadId
+</td>
+<td>
-```ts
-threadId: string;
-```
+[js/packages/react-core/src/types/chatManager.ts:17](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L17)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="threadid"></a> `threadId`
+
+</td>
+<td>
+
+`string`
+
+</td>
+<td>
Unique identifier for the thread
-### title
+</td>
+<td>
-```ts
-title: string;
-```
+[js/packages/react-core/src/types/chatManager.ts:11](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L11)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="title"></a> `title`
+
+</td>
+<td>
+
+`string`
+
+</td>
+<td>
Title of the thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:13](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L13)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/ThreadActions.md b/docs/docs/reference/js/react-core/type-aliases/ThreadActions.md
index 7d23b233a..423cb04cf 100644
--- a/docs/docs/reference/js/react-core/type-aliases/ThreadActions.md
+++ b/docs/docs/reference/js/react-core/type-aliases/ThreadActions.md
@@ -9,48 +9,154 @@ type ThreadActions = {
};
```
-Defined in: [packages/react-core/src/types/chatManager.ts:26](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/chatManager.ts#L26)
+Defined in: [js/packages/react-core/src/types/chatManager.ts:25](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L25)
-Actions available for managing a thread
+Actions available for managing the state of a thread
## Type declaration
-### appendMessages()
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-(...messages: Message[]) => void
-```
+<a id="appendmessages"></a> `appendMessages`
-### deleteMessage()
+</td>
+<td>
-```ts
-(messageId: string) => void
-```
+(...`messages`: [`Message`](Message.md)[]) => `void`
-### onCancel()
+</td>
+<td>
-```ts
-() => void
-```
+Appends a new message to the thread
-### processMessage()
+</td>
+<td>
-```ts
-(message: CreateMessage) => Promise<void>;
-```
+[js/packages/react-core/src/types/chatManager.ts:31](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L31)
-### setMessages()
+</td>
+</tr>
+<tr>
+<td>
-```ts
-(messages: Message[]) => void
-```
+<a id="deletemessage"></a> `deleteMessage`
-### updateMessage()
+</td>
+<td>
-```ts
-(message: Message, shouldTriggerCallback?: boolean) => void
-```
+(`messageId`: `string`) => `void`
+
+</td>
+<td>
+
+Deletes a message from the thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:39](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L39)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="oncancel"></a> `onCancel`
+
+</td>
+<td>
+
+() => `void`
+
+</td>
+<td>
+
+Cancels the current message processing
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:35](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L35)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="processmessage"></a> `processMessage`
+
+</td>
+<td>
+
+(`message`: [`CreateMessage`](CreateMessage.md)) => `Promise`\<`void`\>
+
+</td>
+<td>
+
+Calls the `processMessage` method of the `ThreadManager` to process a new user message and request a response from the agent. If
+the `useThreadManager` hook was used to create a `ThreadManager`, this method is the same one as the `processMessage` method provided to the hook.
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:29](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L29)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="setmessages"></a> `setMessages`
+
+</td>
+<td>
+
+(`messages`: [`Message`](Message.md)[]) => `void`
+
+</td>
+<td>
+
+Sets the messages in the thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:37](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L37)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="updatemessage"></a> `updateMessage`
+
+</td>
+<td>
+
+(`message`: [`Message`](Message.md), `shouldTriggerCallback`?: `boolean`) => `void`
+
+</td>
+<td>
+
+Updates a message in the thread
+
+</td>
+<td>
-## Template
+[js/packages/react-core/src/types/chatManager.ts:33](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L33)
-The message type used in the thread
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/ThreadListActions.md b/docs/docs/reference/js/react-core/type-aliases/ThreadListActions.md
index 6c8b5fbe7..bbb47079d 100644
--- a/docs/docs/reference/js/react-core/type-aliases/ThreadListActions.md
+++ b/docs/docs/reference/js/react-core/type-aliases/ThreadListActions.md
@@ -9,44 +9,153 @@ type ThreadListActions = {
};
```
-Defined in: [packages/react-core/src/types/chatManager.ts:78](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/chatManager.ts#L78)
+Defined in: [js/packages/react-core/src/types/chatManager.ts:91](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L91)
-Actions available for managing the thread list
+Actions available for managing the state of a thread list
## Type declaration
-### createThread()
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-(firstMessage: UserMessage) => Promise<Thread>;
-```
+<a id="createthread"></a> `createThread`
-### deleteThread()
+</td>
+<td>
-```ts
-(threadId: string) => void
-```
+(`firstMessage`: [`UserMessage`](UserMessage.md)) => `Promise`\<[`Thread`](Thread.md)\>
-### load()
+</td>
+<td>
-```ts
-() => void
-```
+Creates a new thread with given `firstMessage` as the user message
-### selectThread()
+</td>
+<td>
-```ts
-(threadId: string, shouldResetThreadState?: boolean) => void
-```
+[js/packages/react-core/src/types/chatManager.ts:97](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L97)
-### switchToNewThread()
+</td>
+</tr>
+<tr>
+<td>
-```ts
-() => void
-```
+<a id="deletethread"></a> `deleteThread`
-### updateThread()
+</td>
+<td>
-```ts
-(thread: Thread) => void
-```
+(`threadId`: `string`) => `void`
+
+</td>
+<td>
+
+Deletes a thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:103](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L103)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="load"></a> `load`
+
+</td>
+<td>
+
+() => `void`
+
+</td>
+<td>
+
+Loads the thread list
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:93](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L93)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="selectthread"></a> `selectThread`
+
+</td>
+<td>
+
+(`threadId`: `string`, `shouldResetThreadState`?: `boolean`) => `void`
+
+</td>
+<td>
+
+Selects a thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:99](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L99)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="switchtonewthread"></a> `switchToNewThread`
+
+</td>
+<td>
+
+() => `void`
+
+</td>
+<td>
+
+Clears the thread state so that the user can start a new thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:95](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L95)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="updatethread"></a> `updateThread`
+
+</td>
+<td>
+
+(`thread`: [`Thread`](Thread.md)) => `void`
+
+</td>
+<td>
+
+Updates a thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:101](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L101)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/ThreadListManager.md b/docs/docs/reference/js/react-core/type-aliases/ThreadListManager.md
index 8853d1aca..b4e0b58a9 100644
--- a/docs/docs/reference/js/react-core/type-aliases/ThreadListManager.md
+++ b/docs/docs/reference/js/react-core/type-aliases/ThreadListManager.md
@@ -1,7 +1,10 @@
+The Thread List Manager is an entity that encapsulates the [`ThreadListState`](./ThreadListState.md) and actions ([`ThreadListActions`](./ThreadListActions.md)) that help modify the state.
+It can be passed to the `ChatProvider` or the `CrayonChat` component to dictate how a thread list should be managed, and what APIs should be called on each event.
+
+---
+
```ts
type ThreadListManager = ThreadListState & ThreadListActions;
```
-Defined in: [packages/react-core/src/types/chatManager.ts:92](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/chatManager.ts#L92)
-
-Combines thread list state and actions
+Defined in: [js/packages/react-core/src/types/chatManager.ts:109](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L109)
diff --git a/docs/docs/reference/js/react-core/type-aliases/ThreadListState.md b/docs/docs/reference/js/react-core/type-aliases/ThreadListState.md
index 4ceff8385..2c3fb3ab3 100644
--- a/docs/docs/reference/js/react-core/type-aliases/ThreadListState.md
+++ b/docs/docs/reference/js/react-core/type-aliases/ThreadListState.md
@@ -8,38 +8,132 @@ type ThreadListState = {
};
```
-Defined in: [packages/react-core/src/types/chatManager.ts:65](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/chatManager.ts#L65)
+Defined in: [js/packages/react-core/src/types/chatManager.ts:72](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L72)
Represents the state of the thread list
## Type declaration
-### error
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-error: Error | null | undefined;
-```
+<a id="error"></a> `error`
-### isLoading
+</td>
+<td>
-```ts
-isLoading: boolean;
-```
+`Error` \| `null` \| `undefined`
-### selectedThreadId
+</td>
+<td>
-```ts
-selectedThreadId: string | null;
-```
+The error that occurred while fetching the thread list
-### shouldResetThreadState
+</td>
+<td>
-```ts
-shouldResetThreadState: boolean;
-```
+[js/packages/react-core/src/types/chatManager.ts:78](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L78)
-### threads
+</td>
+</tr>
+<tr>
+<td>
-```ts
-threads: Thread[];
-```
+<a id="isloading"></a> `isLoading`
+
+</td>
+<td>
+
+`boolean`
+
+</td>
+<td>
+
+Indicates if the thread list is currently loading
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:76](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L76)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="selectedthreadid"></a> `selectedThreadId`
+
+</td>
+<td>
+
+`string` \| `null`
+
+</td>
+<td>
+
+The id of the selected / active thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:80](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L80)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="shouldresetthreadstate"></a> `shouldResetThreadState`
+
+</td>
+<td>
+
+`boolean`
+
+</td>
+<td>
+
+Indicates if the thread state should be reset when the selected thread changes. This helps clear and update the list of messages on the screen when switching
+between threads.
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:83](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L83)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="threads"></a> `threads`
+
+</td>
+<td>
+
+[`Thread`](Thread.md)[]
+
+</td>
+<td>
+
+The list of threads
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:74](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L74)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/ThreadManager.md b/docs/docs/reference/js/react-core/type-aliases/ThreadManager.md
index 0a3ee8c07..26a4fc3e1 100644
--- a/docs/docs/reference/js/react-core/type-aliases/ThreadManager.md
+++ b/docs/docs/reference/js/react-core/type-aliases/ThreadManager.md
@@ -1,11 +1,10 @@
+The Thread Manager is an entity that encapsulates the [`ThreadState`](./ThreadState.md) and actions ([`ThreadActions`](./ThreadActions.md)) that help modify the state.
+It can be passed to the `ChatProvider` or the `CrayonChat` component to dictate how a thread should be managed, and what APIs should be called on each event.
+
+---
+
```ts
type ThreadManager = ThreadState & ThreadActions;
```
-Defined in: [packages/react-core/src/types/chatManager.ts:58](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/chatManager.ts#L58)
-
-Combines thread state and actions
-
-## Template
-
-The message type used in the thread
+Defined in: [js/packages/react-core/src/types/chatManager.ts:65](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L65)
diff --git a/docs/docs/reference/js/react-core/type-aliases/ThreadState.md b/docs/docs/reference/js/react-core/type-aliases/ThreadState.md
index d475fe945..bf20a83da 100644
--- a/docs/docs/reference/js/react-core/type-aliases/ThreadState.md
+++ b/docs/docs/reference/js/react-core/type-aliases/ThreadState.md
@@ -4,47 +4,136 @@ type ThreadState = {
isLoadingMessages: boolean | undefined;
isRunning: boolean;
messages: Message[];
- responseTemplates: {};
+ responseTemplates: Record<string, ResponseTemplate>;
};
```
-Defined in: [packages/react-core/src/types/chatManager.ts:40](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/chatManager.ts#L40)
+Defined in: [js/packages/react-core/src/types/chatManager.ts:47](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L47)
Represents the state of a thread
## Type declaration
-### error
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-error: Error | null | undefined;
-```
+<a id="error"></a> `error`
-### isLoadingMessages
+</td>
+<td>
-```ts
-isLoadingMessages: boolean | undefined;
-```
+`Error` \| `null` \| `undefined`
+
+</td>
+<td>
+
+The error that occurred during the last message processing
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:55](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L55)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="isloadingmessages"></a> `isLoadingMessages`
+
+</td>
+<td>
+
+`boolean` \| `undefined`
+
+</td>
+<td>
Indicates if the messages are currently loading
-### isRunning?
+</td>
+<td>
-```ts
-optional isRunning: boolean;
-```
+[js/packages/react-core/src/types/chatManager.ts:51](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L51)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="isrunning"></a> `isRunning`?
+
+</td>
+<td>
+
+`boolean`
+
+</td>
+<td>
Indicates if the thread is currently processing and controls should be disabled
-### messages
+</td>
+<td>
-```ts
-messages: Message[];
-```
+[js/packages/react-core/src/types/chatManager.ts:49](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L49)
-### responseTemplates
+</td>
+</tr>
+<tr>
+<td>
-```ts
-{
-}
-```
+<a id="messages"></a> `messages`
+
+</td>
+<td>
+
+[`Message`](Message.md)[]
+
+</td>
+<td>
+
+The messages in the thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:53](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L53)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="responsetemplates"></a> `responseTemplates`
+
+</td>
+<td>
+
+`Record`\<`string`, [`ResponseTemplate`](../interfaces/ResponseTemplate.md)\>
+
+</td>
+<td>
+
+The response templates available for the thread. If the [useThreadManager](../functions/useThreadManager.md) hook was used to create the [ThreadManager](ThreadManager.md), this property is the same one as the
+`responseTemplates` property provided to the hook.
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/chatManager.ts:59](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/chatManager.ts#L59)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/UseThreadListManagerParams.md b/docs/docs/reference/js/react-core/type-aliases/UseThreadListManagerParams.md
index 889238cbd..c3b93dec9 100644
--- a/docs/docs/reference/js/react-core/type-aliases/UseThreadListManagerParams.md
+++ b/docs/docs/reference/js/react-core/type-aliases/UseThreadListManagerParams.md
@@ -9,48 +9,153 @@ type UseThreadListManagerParams = {
};
```
-Defined in: [packages/react-core/src/useThreadListManager.ts:11](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/useThreadListManager.ts#L11)
+Defined in: [js/packages/react-core/src/useThreadListManager.ts:11](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadListManager.ts#L11)
Parameters to be passed to the [useThreadListManager](../functions/useThreadListManager.md) hook
## Type declaration
-### createThread()
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-(firstMessage: UserMessage) => Promise<Thread>;
-```
+<a id="createthread"></a> `createThread`
-Creates a new thread when user sends the first message
+</td>
+<td>
-### deleteThread()
+(`firstMessage`: [`UserMessage`](UserMessage.md)) => `Promise`\<[`Thread`](Thread.md)\>
-```ts
-(id: string) => Promise<void>;
-```
+</td>
+<td>
-### fetchThreadList()
+Creates a new thread when the user sends the first message. Useful for integrating a backend API to create a new thread.
-```ts
-() => Promise<Thread[]>;
-```
+</td>
+<td>
-### onSelectThread()
+[js/packages/react-core/src/useThreadListManager.ts:23](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadListManager.ts#L23)
-```ts
-(threadId: string) => void
-```
+</td>
+</tr>
+<tr>
+<td>
-### onSwitchToNew()
+<a id="deletethread"></a> `deleteThread`
-```ts
-() => void
-```
+</td>
+<td>
-Allows user to clear chat state when switched to new thread
+(`id`: `string`) => `Promise`\<`void`\>
-### updateThread()
+</td>
+<td>
-```ts
-(updated: Thread) => Promise<Thread>;
-```
+A function that defines how a thread should be deleted. Useful for integrating a backend API to delete a thread.
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadListManager.ts:15](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadListManager.ts#L15)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="fetchthreadlist"></a> `fetchThreadList`
+
+</td>
+<td>
+
+() => `Promise`\<[`Thread`](Thread.md)[]\>
+
+</td>
+<td>
+
+A function that defines how the thread list should be fetched. Useful for integrating a backend API to fetch the thread list.
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadListManager.ts:13](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadListManager.ts#L13)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="onselectthread"></a> `onSelectThread`
+
+</td>
+<td>
+
+(`threadId`: `string`) => `void`
+
+</td>
+<td>
+
+Runs when the user selects a thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadListManager.ts:21](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadListManager.ts#L21)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="onswitchtonew"></a> `onSwitchToNew`
+
+</td>
+<td>
+
+() => `void`
+
+</td>
+<td>
+
+Runs when the user switches to a new thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadListManager.ts:19](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadListManager.ts#L19)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="updatethread"></a> `updateThread`
+
+</td>
+<td>
+
+(`updated`: [`Thread`](Thread.md)) => `Promise`\<[`Thread`](Thread.md)\>
+
+</td>
+<td>
+
+A function that defines how a thread should be updated. Useful for integrating a backend API to update a thread.
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadListManager.ts:17](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadListManager.ts#L17)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/UseThreadManagerParams.md b/docs/docs/reference/js/react-core/type-aliases/UseThreadManagerParams.md
index f6f365b93..cca16545c 100644
--- a/docs/docs/reference/js/react-core/type-aliases/UseThreadManagerParams.md
+++ b/docs/docs/reference/js/react-core/type-aliases/UseThreadManagerParams.md
@@ -13,50 +13,159 @@ type UseThreadManagerParams = {
};
```
-Defined in: [packages/react-core/src/useThreadManager.ts:10](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/useThreadManager.ts#L10)
+Defined in: [js/packages/react-core/src/useThreadManager.ts:10](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadManager.ts#L10)
Parameters to be passed to the [useThreadManager](../functions/useThreadManager.md) hook
## Type declaration
-### loadThread()
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-(threadId: string) => Promise<Message[]>;
-```
+<a id="loadthread"></a> `loadThread`
-### onProcessMessage()
+</td>
+<td>
-```ts
-(props: {
- abortController: AbortController;
- message: CreateMessage;
- threadManager: ThreadManager;
-}) => Promise<Message[]>;
-```
+(`threadId`: `string`) => `Promise`\<[`Message`](Message.md)[]\>
-### onUpdateMessage()?
+</td>
+<td>
-```ts
-(props: {
- message: Message;
- }) => void
-```
+A function that defines how the thread should be loaded. Useful for integrating a backend API to load a thread.
-### responseTemplates
+</td>
+<td>
-```ts
-responseTemplates: ResponseTemplate[];
-```
+[js/packages/react-core/src/useThreadManager.ts:16](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadManager.ts#L16)
-### shouldResetThreadState?
+</td>
+</tr>
+<tr>
+<td>
-```ts
-optional shouldResetThreadState: boolean;
-```
+<a id="onprocessmessage"></a> `onProcessMessage`
-### threadId
+</td>
+<td>
-```ts
-threadId: string | null;
-```
+(`props`: \{
+`abortController`: `AbortController`;
+`message`: [`CreateMessage`](CreateMessage.md);
+`threadManager`: [`ThreadManager`](ThreadManager.md);
+\}) => `Promise`\<[`Message`](Message.md)[]\>
+
+</td>
+<td>
+
+A function that defines how message should be processed. Useful for integrating a backend API to process a message and request the agent for the response
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadManager.ts:18](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadManager.ts#L18)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="onupdatemessage"></a> `onUpdateMessage`?
+
+</td>
+<td>
+
+(`props`: \{
+`message`: [`Message`](Message.md);
+\}) => `void`
+
+</td>
+<td>
+
+A function that defines how a message should be updated. Useful for integrating a backend API to update a message.
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadManager.ts:24](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadManager.ts#L24)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="responsetemplates"></a> `responseTemplates`
+
+</td>
+<td>
+
+[`ResponseTemplate`](../interfaces/ResponseTemplate.md)[]
+
+</td>
+<td>
+
+A list of response templates available to the thread.
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadManager.ts:26](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadManager.ts#L26)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="shouldresetthreadstate"></a> `shouldResetThreadState`?
+
+</td>
+<td>
+
+`boolean`
+
+</td>
+<td>
+
+Whether to reset the thread state when switching to a new thread
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadManager.ts:14](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadManager.ts#L14)
+
+</td>
+</tr>
+<tr>
+<td>
+
+<a id="threadid-1"></a> `threadId`
+
+</td>
+<td>
+
+`string` \| `null`
+
+</td>
+<td>
+
+Unique identifier for the thread. If the thread is not created yet, the value should be `null`
+
+</td>
+<td>
+
+[js/packages/react-core/src/useThreadManager.ts:12](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/useThreadManager.ts#L12)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/docs/docs/reference/js/react-core/type-aliases/UserMessage.md b/docs/docs/reference/js/react-core/type-aliases/UserMessage.md
index 4a5888550..dc5d7bb67 100644
--- a/docs/docs/reference/js/react-core/type-aliases/UserMessage.md
+++ b/docs/docs/reference/js/react-core/type-aliases/UserMessage.md
@@ -11,46 +11,177 @@ type UserMessage = {
};
```
-Defined in: [packages/react-core/src/types/message.ts:14](https://github.com/thesysdev/crayon/blob/cbecbe8e16fae54d735cb8e1fe31b72f51300d52/js/packages/react-core/src/types/message.ts#L14)
+Defined in: [js/packages/react-core/src/types/message.ts:18](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L18)
+
+A type that represents a message sent by the user
## Type declaration
-### id
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-id: string;
-```
+`id`
-### isVisuallyHidden?
+</td>
+<td>
-```ts
-optional isVisuallyHidden: boolean;
-```
+`string`
+
+</td>
+<td>
+
+The unique identifier of the message
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:8](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L8)
+
+</td>
+</tr>
+<tr>
+<td>
+
+`isVisuallyHidden`?
+
+</td>
+<td>
+
+`boolean`
+
+</td>
+<td>
+
+Whether the message should be visually hidden from the user on the UI
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:10](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L10)
+
+</td>
+</tr>
+</tbody>
+</table>
## Type declaration
-### role
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-role: "user";
-```
+`role`
+
+</td>
+<td>
+
+`"user"`
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:19](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L19)
+
+</td>
+</tr>
+</tbody>
+</table>
## Type declaration
-### context?
+<table>
+<thead>
+<tr>
+<th>Name</th>
+<th>Type</th>
+<th>Description</th>
+<th>Defined in</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td>
-```ts
-optional context: JSONValue[];
-```
+`context`?
-### message?
+</td>
+<td>
-```ts
-optional message: string;
-```
+`JSONValue`[]
-### type
+</td>
+<td>
-```ts
-type: "prompt";
-```
+Additional data associated with the message
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:25](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L25)
+
+</td>
+</tr>
+<tr>
+<td>
+
+`message`?
+
+</td>
+<td>
+
+`string`
+
+</td>
+<td>
+
+The message content as a string
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:23](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L23)
+
+</td>
+</tr>
+<tr>
+<td>
+
+`type`
+
+</td>
+<td>
+
+`"prompt"`
+
+</td>
+<td>
+
+&hyphen;
+
+</td>
+<td>
+
+[js/packages/react-core/src/types/message.ts:21](https://github.com/thesysdev/crayon/blob/main/js/packages/react-core/src/types/message.ts#L21)
+
+</td>
+</tr>
+</tbody>
+</table>
diff --git a/js/packages/react-core/src/ChatProvider.tsx b/js/packages/react-core/src/ChatProvider.tsx
index 27cf99e95..2c59d2f0f 100644
--- a/js/packages/react-core/src/ChatProvider.tsx
+++ b/js/packages/react-core/src/ChatProvider.tsx
@@ -6,26 +6,6 @@ import { ChatManager } from "./types";
/**
* @category Components
- *
- * @remarks
- * ChatProvider is a React component that provides chat management context to its children.
- * It serves as the top-level provider for thread and thread list management functionality.
- *
- * @example
- * ```tsx
- * <ChatProvider
- * threadManager={myThreadManager}
- * threadListManager={myThreadListManager}
- * >
- * <App />
- * </ChatProvider>
- * ```
- *
- * @param props - The component props
- * @param props.threadManager - The thread manager instance for handling individual chat threads
- * @param props.threadListManager - The thread list manager instance for handling multiple chat threads
- * @param props.children - The child components that will have access to the chat context
- * @returns A ChatContext.Provider wrapping the children components
*/
export const ChatProvider: FC<React.PropsWithChildren<ChatManager>> = ({
threadManager: inputThreadManager,
diff --git a/js/packages/react-core/src/hooks/useThreadActions.ts b/js/packages/react-core/src/hooks/useThreadActions.ts
index 38c55c35f..4dba8bf74 100644
--- a/js/packages/react-core/src/hooks/useThreadActions.ts
+++ b/js/packages/react-core/src/hooks/useThreadActions.ts
@@ -3,6 +3,8 @@ import { useChatContext } from "../internal/ChatContext";
import { ThreadActions } from "../types";
/**
+ * `useThreadActions` allows you to modify the {@link ThreadState} by providing access to {@link ThreadActions} which contains methods to modify the state.
+ *
* @category Hooks
*/
export const useThreadActions = (): ThreadActions => {
diff --git a/js/packages/react-core/src/hooks/useThreadListActions.ts b/js/packages/react-core/src/hooks/useThreadListActions.ts
index 4b213903f..1baa207e3 100644
--- a/js/packages/react-core/src/hooks/useThreadListActions.ts
+++ b/js/packages/react-core/src/hooks/useThreadListActions.ts
@@ -3,10 +3,9 @@ import { useChatContext } from "../internal/ChatContext";
import { ThreadListActions } from "../types";
/**
- * @category Hooks
+ * `useThreadListActions` allows you to modify the {@link ThreadListState} by providing access to {@link ThreadListActions} which contains methods to modify the state.
*
- * @remarks
- * useThreadListActions
+ * @category Hooks
*/
export const useThreadListActions = (): ThreadListActions => {
const { threadListManager } = useChatContext();
diff --git a/js/packages/react-core/src/hooks/useThreadListState.ts b/js/packages/react-core/src/hooks/useThreadListState.ts
index 3e7f4e164..6f36b8cef 100644
--- a/js/packages/react-core/src/hooks/useThreadListState.ts
+++ b/js/packages/react-core/src/hooks/useThreadListState.ts
@@ -3,10 +3,12 @@ import { useChatContext } from "../internal/ChatContext";
import { ThreadListState } from "../types";
/**
- * @category Hooks
+ * `useThreadListState` allows you to access the {@link ThreadListState}. This is helpful for multiple reasons, including but not limited to:
+ *
+ * - You can use the state to render the thread list UI
+ * - You can use the state to trigger actions on the thread list
*
- * @remarks
- * useThreadListState
+ * @category Hooks
*/
export const useThreadListState = (): ThreadListState => {
const { threadListManager } = useChatContext();
diff --git a/js/packages/react-core/src/hooks/useThreadManagerSelector.ts b/js/packages/react-core/src/hooks/useThreadManagerSelector.ts
index 0bad4c8b9..74c11a0fc 100644
--- a/js/packages/react-core/src/hooks/useThreadManagerSelector.ts
+++ b/js/packages/react-core/src/hooks/useThreadManagerSelector.ts
@@ -5,10 +5,15 @@ import { ThreadManager } from "../types";
type AtomicAccessor<T> = (store: ThreadManager) => T;
/**
- * @category Hooks
+ * @typeParam R - The type of the value to be extracted from the {@link ThreadManager} instance. For example, `boolean | undefined`:
+ * ```ts
+ * const isRunning = useThreadManagerSelector<boolean | undefined>((threadManager) => threadManager.isRunning); // returning any other type throws an error
+ * ```
+ * If no type is passed, one is inferred from the accessor function.
*
- * @remarks
- * useThreadManager
+ * @param accessor - A function that is passed the {@link ThreadManager} instance as an argument and returns the value to be extracted.
+ * @returns The value returned by the accessor function.
+ * @category Hooks
*/
export const useThreadManagerSelector = <R>(accessor: AtomicAccessor<R>): R => {
const { threadManager } = useChatContext();
diff --git a/js/packages/react-core/src/hooks/useThreadState.ts b/js/packages/react-core/src/hooks/useThreadState.ts
index d7d8e5b79..898228e8d 100644
--- a/js/packages/react-core/src/hooks/useThreadState.ts
+++ b/js/packages/react-core/src/hooks/useThreadState.ts
@@ -3,10 +3,12 @@ import { useChatContext } from "../internal/ChatContext";
import { ThreadState } from "../types";
/**
- * @category Hooks
+ * `useThreadState` allows you to access the {@link ThreadState}. This is helpful for multiple reasons, including but not limited to:
+ *
+ * - You can use the state to render the thread UI
+ * - You can use the state to trigger actions on the thread
*
- * @remarks
- * useThreadState
+ * @category Hooks
*/
export const useThreadState = (): ThreadState => {
const { threadManager } = useChatContext();
diff --git a/js/packages/react-core/src/stream/processStreamedMessage.ts b/js/packages/react-core/src/stream/processStreamedMessage.ts
index 91d1914ef..8f304dfdc 100644
--- a/js/packages/react-core/src/stream/processStreamedMessage.ts
+++ b/js/packages/react-core/src/stream/processStreamedMessage.ts
@@ -10,6 +10,19 @@ import { createParser } from "eventsource-parser";
import invariant from "tiny-invariant";
import { AssistantMessage } from "../types";
+/**
+ * @inline
+ */
+interface Parameters {
+ response: Response;
+ /** A function that creates a new assistant message in the thread */
+ createMessage: (message: AssistantMessage) => void;
+ /** A function that updates an existing assistant message in the thread */
+ updateMessage: (message: AssistantMessage) => void;
+ /** A function that deletes an assistant message from the thread */
+ deleteMessage: (messageId: string) => void;
+}
+
/**
* @category Utilities
*/
@@ -18,12 +31,7 @@ export const processStreamedMessage = async ({
createMessage,
updateMessage,
deleteMessage,
-}: {
- response: Response;
- createMessage: (message: AssistantMessage) => void;
- updateMessage: (message: AssistantMessage) => void;
- deleteMessage: (messageId: string) => void;
-}) => {
+}: Parameters) => {
const stream = response.body?.getReader();
if (!stream) {
throw new Error("No stream");
diff --git a/js/packages/react-core/src/types/chatManager.ts b/js/packages/react-core/src/types/chatManager.ts
index 2858e9168..30c217e8a 100644
--- a/js/packages/react-core/src/types/chatManager.ts
+++ b/js/packages/react-core/src/types/chatManager.ts
@@ -18,17 +18,24 @@ export type Thread = {
};
/**
- * Actions available for managing a thread
- * @template T - The message type used in the thread
+ * Actions available for managing the state of a thread
*
* @category Types
*/
export type ThreadActions = {
+ /** Calls the `processMessage` method of the `ThreadManager` to process a new user message and request a response from the agent. If
+ * the `useThreadManager` hook was used to create a `ThreadManager`, this method is the same one as the `processMessage` method provided to the hook.
+ */
processMessage: (message: CreateMessage) => Promise<void>;
+ /** Appends a new message to the thread */
appendMessages: (...messages: Message[]) => void;
+ /** Updates a message in the thread */
updateMessage: (message: Message, shouldTriggerCallback?: boolean) => void;
+ /** Cancels the current message processing */
onCancel: () => void;
+ /** Sets the messages in the thread */
setMessages: (messages: Message[]) => void;
+ /** Deletes a message from the thread */
deleteMessage: (messageId: string) => void;
};
@@ -42,17 +49,17 @@ export type ThreadState = {
isRunning?: boolean | undefined;
/** Indicates if the messages are currently loading */
isLoadingMessages: boolean | undefined;
+ /** The messages in the thread */
messages: Message[];
+ /** The error that occurred during the last message processing */
error: Error | null | undefined;
- responseTemplates: {
- [name: string]: ResponseTemplate;
- };
+ /** The response templates available for the thread. If the {@link useThreadManager} hook was used to create the {@link ThreadManager}, this property is the same one as the
+ * `responseTemplates` property provided to the hook.
+ */
+ responseTemplates: Record<string, ResponseTemplate>;
};
/**
- * Combines thread state and actions
- * @template T - The message type used in the thread
- *
* @category Types
*/
export type ThreadManager = ThreadState & ThreadActions;
@@ -63,30 +70,40 @@ export type ThreadManager = ThreadState & ThreadActions;
* @category Types
*/
export type ThreadListState = {
+ /** The list of threads */
threads: Thread[];
+ /** Indicates if the thread list is currently loading */
isLoading: boolean;
+ /** The error that occurred while fetching the thread list */
error: Error | null | undefined;
+ /** The id of the selected / active thread */
selectedThreadId: string | null;
+ /** Indicates if the thread state should be reset when the selected thread changes. This helps clear and update the list of messages on the screen when switching
+ * between threads. */
shouldResetThreadState: boolean;
};
/**
- * Actions available for managing the thread list
+ * Actions available for managing the state of a thread list
*
* @category Types
*/
export type ThreadListActions = {
+ /** Loads the thread list */
load: () => void;
+ /** Clears the thread state so that the user can start a new thread */
switchToNewThread: () => void;
+ /** Creates a new thread with given `firstMessage` as the user message */
createThread: (firstMessage: UserMessage) => Promise<Thread>;
+ /** Selects a thread */
selectThread: (threadId: string, shouldResetThreadState?: boolean) => void;
+ /** Updates a thread */
updateThread: (thread: Thread) => void;
+ /** Deletes a thread */
deleteThread: (threadId: string) => void;
};
/**
- * Combines thread list state and actions
- *
* @category Types
*/
export type ThreadListManager = ThreadListState & ThreadListActions;
@@ -97,6 +114,8 @@ export type ThreadListManager = ThreadListState & ThreadListActions;
* @category Types
*/
export type ChatManager = {
+ /** The thread list manager, a combination of thread list state and actions */
threadListManager: ThreadListManager;
+ /** The thread manager, a combination of thread state and actions */
threadManager: ThreadManager;
};
diff --git a/js/packages/react-core/src/types/message.ts b/js/packages/react-core/src/types/message.ts
index b2b846f12..ee83b1233 100644
--- a/js/packages/react-core/src/types/message.ts
+++ b/js/packages/react-core/src/types/message.ts
@@ -4,27 +4,37 @@ import { JSONValue } from "@crayonai/stream";
* @inline
*/
type Common = {
+ /** The unique identifier of the message */
id: string;
+ /** Whether the message should be visually hidden from the user on the UI */
isVisuallyHidden?: boolean;
};
/**
+ * A type that represents a message sent by the user
+ *
* @category Types
*/
export type UserMessage = Common & {
role: "user";
} & {
type: "prompt";
+ /** The message content as a string */
message?: string;
+ /** Additional data associated with the message */
context?: JSONValue[];
};
/**
+ * A type that represents a message sent by the assistant / agent
+ *
* @category Types
*/
export type AssistantMessage = Common & {
role: "assistant";
+ /** Additional data associated with the message */
context?: JSONValue[];
+ /** The message content, either in a text format or a template (with the name of the response template and the props of the component that renders the template) */
message?: (
| {
type: "text";
@@ -32,23 +42,25 @@ export type AssistantMessage = Common & {
}
| {
type: "template";
+ /** The name of the response template to be rendered */
name: string;
+ /** The props to be passed to the component that renders the response template with the given name */
templateProps: any;
}
)[];
};
/**
- * See {@link UserMessage} and {@link AssistantMessage} for more information.
+ * Represents a message in a {@link Thread}. See {@link UserMessage} and {@link AssistantMessage} for more information.
*
* @category Types
*/
export type Message = UserMessage | AssistantMessage;
/**
- * Represents a message being created, with an optional ID
- * @extends Omit<Message, "id">
+ * Contains all of the information required to create a message. Usually passed to the {@link ThreadManager}'s `processMessage` method.
*
* @category Types
+ * @useDeclaredType @inline
*/
export type CreateMessage = Omit<UserMessage, "id">;
diff --git a/js/packages/react-core/src/useThreadListManager.ts b/js/packages/react-core/src/useThreadListManager.ts
index 2e28caa52..93fac0d9b 100644
--- a/js/packages/react-core/src/useThreadListManager.ts
+++ b/js/packages/react-core/src/useThreadListManager.ts
@@ -9,19 +9,26 @@ import { Thread, ThreadListManager, UserMessage } from "./types";
* @category Types
*/
export type UseThreadListManagerParams = {
+ /** A function that defines how the thread list should be fetched. Useful for integrating a backend API to fetch the thread list. */
fetchThreadList: () => Promise<Thread[]>;
+ /** A function that defines how a thread should be deleted. Useful for integrating a backend API to delete a thread. */
deleteThread: (id: string) => Promise<void>;
+ /** A function that defines how a thread should be updated. Useful for integrating a backend API to update a thread. */
updateThread: (updated: Thread) => Promise<Thread>;
- /** Allows user to clear chat state when switched to new thread */
+ /** Runs when the user switches to a new thread */
onSwitchToNew: () => void;
+ /** Runs when the user selects a thread */
onSelectThread: (threadId: string) => void;
- /** Creates a new thread when user sends the first message */
+ /** Creates a new thread when the user sends the first message. Useful for integrating a backend API to create a new thread. */
createThread: (firstMessage: UserMessage) => Promise<Thread>;
};
type DefaultManager = ThreadListManager;
/**
+ * `useThreadListManager` takes the necessary arguments and helps create a {@link ThreadListManager} instance. This instance is necessary to define how a thread list should
+ * be fetched, updated, deleted, and selected and which backend APIs should be called at any of these events or actions.
+ *
* @category Hooks
* @returns A ThreadListManager instance
*/
diff --git a/js/packages/react-core/src/useThreadManager.ts b/js/packages/react-core/src/useThreadManager.ts
index 40dd7f273..fa33e3225 100644
--- a/js/packages/react-core/src/useThreadManager.ts
+++ b/js/packages/react-core/src/useThreadManager.ts
@@ -8,19 +8,33 @@ import { CreateMessage, Message, ResponseTemplate, ThreadManager } from "./types
* @category Types
*/
export type UseThreadManagerParams = {
+ /** Unique identifier for the thread. If the thread is not created yet, the value should be `null` */
threadId: string | null;
+ /** Whether to reset the thread state when switching to a new thread */
shouldResetThreadState?: boolean;
+ /** A function that defines how the thread should be loaded. Useful for integrating a backend API to load a thread. */
loadThread: (threadId: string) => Promise<Message[]>;
+ /** A function that defines how message should be processed. Useful for integrating a backend API to process a message and request the agent for the response */
onProcessMessage: (props: {
message: CreateMessage;
threadManager: ThreadManager;
abortController: AbortController;
}) => Promise<Message[]>;
+ /** A function that defines how a message should be updated. Useful for integrating a backend API to update a message. */
onUpdateMessage?: (props: { message: Message }) => void;
+ /** A list of response templates available to the thread. */
responseTemplates: ResponseTemplate[];
};
/**
+ * `useThreadManager` takes the necessary arguments and helps create a {@link ThreadManager} instance. This instance is necessary to define how a thread should
+ * be loaded and how a message in the thread should be processed or updated. This can be useful for multiple reasons, including but not limited to:
+ *
+ * - The hook makes it incredibly easy to manage the thread and does not require you to implement a thread manager from scratch manually
+ * - You can use the thread manager to load a thread from a backend API
+ * - You can use the thread manager to process a message and request the agent for the response
+ * - You can use the thread manager to update a message
+ *
* @category Hooks
* @returns The thread manager
*/