logoassistant-ui
Migrations

Migration to v0.7

This guide serves as a reference for users facing breaking changes during upgrade to v0.7. You do not need to read this guide to upgrade to v0.7.

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 are now neatly organized under the component itself.

-import { ThreadPrimitiveMessagesProps } from "@assistant-ui/react";
+import { ThreadPrimitive } from "@assistant-ui/react";
 
-type Props = ThreadPrimitiveMessagesProps;
+type Props = ThreadPrimitive.Messages.Props;

Context API simplifications

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;

-const { useThread } = useThreadContext();
 
+import { useThread } from "@assistant-ui/react";

Assistant Context API simplifications

useAssistantActions replaced with useAssistantRuntime

useAssistantActions has been removed in favor of useAssistantRuntime.

-const switchToNewThread = useAssistantActions(a => a.switchToNewThread);
+const runtime = useAssistantRuntime();
+runtime.switchToNewThread();

switchToThread(null) replaced with switchToNewThread()

-useThreadRuntime().switchToThread(null);
+useThreadRuntime().switchToNewThread();

useSwtichToNewThread() moved to useAssistantRuntime().switchToNewThread()

-useSwitchToNewThread();
+const runtime = useAssistantRuntime()
+runtime.switchToNewThread(); 

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

useAppendMessage moved to useThreadRuntime().append()

-const append = useAppendMessage();
+const threadRuntime = useThreadRuntime();
-append("hello world");
+threadRuntime.append("hello world");

useThreadActions replaced with useThreadRuntime

useThreadActions has been removed in favor of useThreadRuntime.

-const reload = useThreadActions(a => a.reload);
+const threadRuntime = useThreadRuntime();
+threadRuntime.reload();

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 useThreadRuntime have been moved to threadRuntime.getState().

-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 has been removed in favor of useThreadRuntime().getState().

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

A few methods from useThreadRuntime have been moved to useMessageRuntime().

  • threadRuntime.switchToBranch() has been removed in favor of useThreadRuntime().getMessageByIndex(idx).switchToBranch().
  • 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().getMessageById(id).getMessageByIndex(idx).composer.
  • threadRuntime.beginEdit() has been removed in favor of useThreadRuntime().getMessageById(id).getMessageByIndex(idx).composer.beginEdit().

Composer Runtime API simplifications

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 has been removed in favor of useComposerRuntime().getState().

value setValue replaced with text setText

-useComposer(c => c.value);
+useComposer(c => c.text);

focus, onFocus methods removed

These methods have been removed.

Message Context API simplifications

Flattened context values useMessage().message -> useMessage()

MessageState is now itself a message, so you no longer need to access the nested useMessage().message field.

-useMessage(m => m.message.content);
+useMessage(m => m.content);

useMessageStore replaced with useMessageRuntime().getState()

useMessageStore has been removed in favor of useMessageRuntime().getState().

Content Part Context API simplifications

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.

-useContentPart(c => c.part.type);
+useContentPart(c => c.type);

This also applies to tool UI render functions:

 makeAssistantToolUI({
   ...
-  render: ({ part: { args } }) => <>{args}</>,
+  render: ({ args }) => <>{args}</>,
 });

Attachment Context API simplifications

Flattened context values useAttachment().attachment -> useAttachment()

AttachmentState is now itself an attachment, so you no longer need to access the nested useAttachment().attachment field.

-useAttachment(a => a.attachment.type);
+useAttachment(a => a.type);

Roundtrips renamed to steps

AssistantMessage.roundtrips was renamed to AssistantMessage.metadata.steps.

Edge runtime's maxToolRoundtrips was replaced with maxSteps (which is maxToolRoundtrips + 1; if you had maxToolRoundtrips at 2, set maxSteps to 3).

On this page

Edit on Github