diff --git a/apps/docs/content/docs/migrations/v0-7.mdx b/apps/docs/content/docs/migrations/v0-7.mdx index 6e240960a..923487059 100644 --- a/apps/docs/content/docs/migrations/v0-7.mdx +++ b/apps/docs/content/docs/migrations/v0-7.mdx @@ -8,7 +8,7 @@ This guide serves as a reference for users facing breaking changes during upgrad All breaking changes in v0.7 are renames or removals of existing APIs. Therefore, all breaking changes should cause a Typescript error, so you can simply check for errors after upgrading. -# Component Property Types moved to `Component.Props` +### Component Property Types moved to `Component.Props` Component property types are now neatly organized under the component itself. @@ -20,9 +20,9 @@ Component property types are now neatly organized under the component itself. +type Props = ThreadPrimitive.Messages.Props; ``` -# Context API simplifications +## Context API simplifications -## `useThreadContext`, `useMessageContext`, ... replaced with direct imports of stores +### `useThreadContext`, `useMessageContext`, ... replaced with direct imports of stores `useAssistantContext`, `useThreadContext`, `useMessageContext` and `useContentPartContext` have been removed in favor of direct exports from `@assistant-ui/react`; @@ -34,7 +34,7 @@ Component property types are now neatly organized under the component itself. # Assistant Context API simplifications -## `useAssistantActions` replaced with `useAssistantRuntime` +### `useAssistantActions` replaced with `useAssistantRuntime` `useAssistantActions` has been removed in favor of `useAssistantRuntime`. @@ -44,27 +44,28 @@ Component property types are now neatly organized under the component itself. +runtime.switchToNewThread(); ``` -## `switchToThread(null)` replaced with `switchToNewThread()` +### `switchToThread(null)` replaced with `switchToNewThread()` ```diff -useThreadRuntime().switchToThread(null); +useThreadRuntime().switchToNewThread(); ``` -## useSwtichToNewThread() moved to useRuntimeActions().switchToNewThread() +### useSwtichToNewThread() moved to useAssistantRuntime().switchToNewThread() ```diff -useSwitchToNewThread(); -+useRuntimeActions().switchToNewThread(); ++const runtime = useAssistantRuntime() ++runtime.switchToNewThread(); ``` -## `runtime.subscribe` removed, `subscribeToMainThread` removed +### `runtime.subscribe` removed, `subscribeToMainThread` removed Previously, you needed to subscribe to the runtime to receive updates whenever the main thread changed and resubscribe to the main thread whenever you switched to a new thread. The `runtime.thread` value now always refers to the current main thread, there is no need to subscribe to the runtime anymore. -# ThreadRuntime API simplifications +## ThreadRuntime API simplifications -## `useAppendMessage` moved to `useThreadRuntime().append()` +### `useAppendMessage` moved to `useThreadRuntime().append()` ```diff -const append = useAppendMessage(); @@ -73,7 +74,7 @@ Previously, you needed to subscribe to the runtime to receive updates whenever t +threadRuntime.append("hello world"); ``` -## `useThreadActions` replaced with `useThreadRuntime` +### `useThreadActions` replaced with `useThreadRuntime` `useThreadActions` has been removed in favor of `useThreadRuntime`. @@ -83,24 +84,24 @@ Previously, you needed to subscribe to the runtime to receive updates whenever t +threadRuntime.reload(); ``` -## State values moved to `threadRuntime.getState()` +### State values moved to `threadRuntime.getState()` -In order to make it clear that accessing the state only provides a snapshot of the current state and will not cause a re-render on changes, the state values of `useThreadRutnime` have been moved to `threadRuntime.getState()`. +In order to make it clear that accessing the state only provides a snapshot of the current state and will not cause a re-render on changes, the state values of `useThreadRuntime` have been moved to `threadRuntime.getState()`. ```diff -const isRunning = useThreadRuntime().isRunning; // anti-pattern, your code will not update on change +const isRunning = useThread(t => t.isRunning); ``` -## `useThreadStore` replaced with `useThreadRuntime().getState()` +### `useThreadStore` replaced with `useThreadRuntime().getState()` `useThreadStore` has been removed in favor of `useThreadRuntime().getState()`. -## `threadRuntime.getBranches()` replaced with `useThreadRuntime().getMessageByIndex(idx).getState().branchNumber/Count` +### `threadRuntime.getBranches()` replaced with `useThreadRuntime().getMessageByIndex(idx).getState().branchNumber/Count` The branch IDs are an internal implementation detail. The new Message Runtime API provides `branchNumber` and `branchCount` state fields that can be used instead. -## New Message Runtime API replaces several methods from `useThreadRuntime` +### New Message Runtime API replaces several methods from `useThreadRuntime` A few methods from `useThreadRuntime` have been moved to `useMessageRuntime()`. @@ -108,34 +109,34 @@ A few methods from `useThreadRuntime` have been moved to `useMessageRuntime()`. - `threadRuntime.addToolResult()` has been removed in favor of `useThreadRuntime().getMessageByIndex(idx).getContentPartByToolCallId(toolCallId).addToolResult()`. - `threadRuntime.speak()` has been removed in favor of `useThreadRuntime().getMessageByIndex(idx).speak()`. - `threadRuntime.submitFeedback()` has been removed in favor of `useThreadRuntime().getMessageByIndex(idx).submitFeedback()`. -- `threadRuntime.getEditComposer()` has been removed in favor of `useThreadRuntime().getMesssageById(id).getMessageByIndex(idx).composer`. -- `threadRuntime.beginEdit()` has been removed in favor of `useThreadRuntime().getMesssageById(id).getMessageByIndex(idx).composer.beginEdit()`. +- `threadRuntime.getEditComposer()` has been removed in favor of `useThreadRuntime().getMessageById(id).getMessageByIndex(idx).composer`. +- `threadRuntime.beginEdit()` has been removed in favor of `useThreadRuntime().getMessageById(id).getMessageByIndex(idx).composer.beginEdit()`. -# Composer Runtime API simplifications +## Composer Runtime API simplifications -## Methods inside `useComposer` moved to `useComposerRuntime` +### Methods inside `useComposer` moved to `useComposerRuntime` `useComposer()` used to provide several methods such as `setText`, `addAttachment`, `send`, `edit`, `cancel`, ... These methods have been moved to `useComposerRuntime()`. -## `useComposerStore` replaced with `useComposerRuntime().getState()` +### `useComposerStore` replaced with `useComposerRuntime().getState()` `useComposerStore` has been removed in favor of `useComposerRuntime().getState()`. -## `value` `setValue` replaced with `text` `setText` +### `value` `setValue` replaced with `text` `setText` ```diff -useComposer(c => c.value); +useComposer(c => c.text); ``` -## `reset`, `focus`, `onFocus` methods removed +### `reset`, `focus`, `onFocus` methods removed These methods have been removed. -# Message Context API simplifications +## Message Context API simplifications -## Flattened context values `useMessage().message` -> `useMessage()` +### Flattened context values `useMessage().message` -> `useMessage()` `MessageState` is now itself a message, so you no longer need to access the nested `useMessage().message` field. @@ -144,13 +145,13 @@ These methods have been removed. +useMessage(m => m.content); ``` -## `useMessageStore` replaced with `useMessageRuntime().getState()` +### `useMessageStore` replaced with `useMessageRuntime().getState()` `useMessageStore` has been removed in favor of `useMessageRuntime().getState()`. -# Content Part Context API simplifications +## Content Part Context API simplifications -## Flattened context values `useContentPart().part` -> `useContentPart()` +### Flattened context values `useContentPart().part` -> `useContentPart()` `ContentPartState` is now itself a content part, so you no longer need to access the nested `useContentPart().part` field. @@ -169,9 +170,9 @@ This also applies to tool UI render functions: }); ``` -# Attachment Context API simplifications +## Attachment Context API simplifications -## Flattened context values `useAttachment().attachment` -> `useAttachment()` +### Flattened context values `useAttachment().attachment` -> `useAttachment()` `AttachmentState` is now itself an attachment, so you no longer need to access the nested `useAttachment().attachment` field. @@ -180,7 +181,7 @@ This also applies to tool UI render functions: +useAttachment(a => a.type); ``` -# Roundtrips rename to steps +## Roundtrips renamed to steps `AssistantMessage.roundtrips` was renamed to `AssistantMessage.metadata.steps`.