logoassistant-ui

External Store Runtime

Overview

Use the ExternalStoreRuntime if you want to manage the message state yourself via any react state management library.

This runtime requires a ExternalStoreAdapter<TMessage> handles communication between assistant-uiand your state. Unless you are storing messages as ThreadMessage, you need to define a convertMessage function to convert your messages to ThreadMessage.

@/app/MyRuntimeProvider.tsx
import { ,  } from "react";
import {
  ,
  ,
  ,
  ,
} from "@assistant-ui/react";
 
const  = (: ):  => {
  return {
    : .,
    : [{ : "text", : . }],
  };
};
 
export function ({
  ,
}: <{
  : ;
}>) {
  const [, ] = (false);
  const [, ] = <[]>([]);
 
  const  = async (: ) => {
    if (.[0]?. !== "text")
      throw new ("Only text messages are supported");
 
    const  = .[0].;
    (() => [
      ...,
      { : "user", :  },
    ]);
 
    (true);
    const  = await ();
    (() => [
      ...,
      ,
    ]);
    (false);
  };
 
  const  = ({
    ,
    ,
    ,
    ,
  });
 
  return (
    < ={}>
      {}
    </>
  );
}

On this page

Edit on Github