Skip to content

How cloud it cooperator with useRemoteThreadListRuntime #8

@Adeshen

Description

@Adeshen

I want to use threadlist with it. It is useless when clicking the threadlist. it could not find change message-box

import { useRef } from "react";
import { AssistantRuntimeProvider } from "@assistant-ui/react";
import {
  useLocalRuntime,
  unstable_useRemoteThreadListRuntime as useRemoteThreadListRuntime,
  type unstable_RemoteThreadListAdapter as RemoteThreadListAdapter,
} from "@assistant-ui/react";
import { useLangGraphRuntime } from "@assistant-ui/react-langgraph";

import { createThread, getThreadState, sendMessage } from "@/lib/chatApi";
import { Thread } from "@/components/assistant-ui/thread";
import { ThreadListSidebar } from "@/components/assistant-ui/threadlist-sidebar";
import { 
  SidebarProvider, 
  SidebarInset,
  SidebarTrigger 
} from "@/components/ui/sidebar";
import { threadListAdapter } from "@/lib/threadmanage";
import { ThreadList } from "@/components/assistant-ui/thread-list";

export function MyAssistant() {
  const threadIdRef = useRef<string | undefined>(undefined);
  
  const graphRuntime = useLangGraphRuntime({
    stream: async (messages, { command }) => {

      if (!threadIdRef.current) {
        const { thread_id } = await createThread();
        threadIdRef.current = thread_id;
      }
      const threadId = threadIdRef.current;
      return sendMessage({
        threadId,
        messages,
        command,
      });
    },
    onSwitchToNewThread: async () => {
      const { thread_id } = await createThread();
      threadIdRef.current = thread_id;
    },
    onSwitchToThread: async (threadId) => {
      // console.log("onSwitchToThread", threadId);
      const state = await getThreadState(threadId);
      threadIdRef.current = threadId;
      return { messages: state.values.messages, interrupts:[] };
    },
  });

  const runtime = useRemoteThreadListRuntime({
    runtimeHook: () => graphRuntime,
    adapter: threadListAdapter,
  });
  
  return (
    <AssistantRuntimeProvider runtime={runtime}>
      <SidebarProvider defaultOpen={true}>
        <div className="flex h-dvh w-full">
          <ThreadListSidebar/>
          <SidebarInset>
            <SidebarTrigger />
            <Thread/>
          </SidebarInset>
        </div>
      </SidebarProvider>
    </AssistantRuntimeProvider>
  );
}



Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions