1
1
import { parsePartialJson } from "@langchain/core/output_parsers" ;
2
- import { useEffect , useState } from "react" ;
2
+ import { useState } from "react" ;
3
3
import { AIMessage , BaseMessage , HumanMessage } from "@langchain/core/messages" ;
4
4
import { useToast } from "./use-toast" ;
5
5
import { v4 as uuidv4 } from "uuid" ;
6
6
7
7
import { Client } from "@langchain/langgraph-sdk" ;
8
- import { getCookie , setCookie } from "../utils/cookies" ;
9
8
import { ThreadActual , useThreads } from "./useThreads" ;
10
9
import { ModelOptions } from "../types" ;
11
10
import { useRuns } from "./useRuns" ;
12
- import { ASSISTANT_ID_COOKIE_NAME } from "../utils/constants" ;
13
11
14
12
export const createClient = ( ) => {
15
13
const apiUrl = process . env . NEXT_PUBLIC_API_URL ?? "http://localhost:3000/api" ;
@@ -61,32 +59,12 @@ interface UseGraphInput {
61
59
62
60
export function useGraph ( inputArgs : UseGraphInput ) {
63
61
const { toast } = useToast ( ) ;
64
- const { getThreadById , setThreadId } = useThreads ( inputArgs . userId ) ;
62
+ const { setThreadId } = useThreads ( inputArgs . userId ) ;
65
63
const { shareRun } = useRuns ( ) ;
66
64
const [ messages , setMessages ] = useState < BaseMessage [ ] > ( [ ] ) ;
67
- const [ assistantId , setAssistantId ] = useState < string > ( ) ;
68
65
const [ selectedModel , setSelectedModel ] =
69
66
useState < ModelOptions > ( "openai/gpt-4o-mini" ) ;
70
67
71
- useEffect ( ( ) => {
72
- if ( assistantId || typeof window === "undefined" ) return ;
73
- getOrCreateAssistant ( ) ;
74
- } , [ ] ) ;
75
-
76
- const getOrCreateAssistant = async ( ) => {
77
- const assistantIdCookie = getCookie ( ASSISTANT_ID_COOKIE_NAME ) ;
78
- if ( assistantIdCookie ) {
79
- setAssistantId ( assistantIdCookie ) ;
80
- return ;
81
- }
82
- const client = createClient ( ) ;
83
- const assistant = await client . assistants . create ( {
84
- graphId : "chat" ,
85
- } ) ;
86
- setAssistantId ( assistant . assistant_id ) ;
87
- setCookie ( ASSISTANT_ID_COOKIE_NAME , assistant . assistant_id ) ;
88
- } ;
89
-
90
68
const streamMessage = async ( params : GraphInput ) => {
91
69
if ( ! inputArgs . threadId ) {
92
70
toast ( {
@@ -95,13 +73,6 @@ export function useGraph(inputArgs: UseGraphInput) {
95
73
} ) ;
96
74
return undefined ;
97
75
}
98
- if ( ! assistantId ) {
99
- toast ( {
100
- title : "Error" ,
101
- description : "Assistant ID not found" ,
102
- } ) ;
103
- return undefined ;
104
- }
105
76
106
77
const client = createClient ( ) ;
107
78
@@ -122,7 +93,7 @@ export function useGraph(inputArgs: UseGraphInput) {
122
93
} ) ,
123
94
} ;
124
95
125
- const stream = client . runs . stream ( inputArgs . threadId , assistantId , {
96
+ const stream = client . runs . stream ( inputArgs . threadId , "chat" , {
126
97
input,
127
98
streamMode : "events" ,
128
99
config : {
@@ -682,7 +653,6 @@ export function useGraph(inputArgs: UseGraphInput) {
682
653
683
654
return {
684
655
messages,
685
- assistantId,
686
656
selectedModel,
687
657
setSelectedModel,
688
658
setMessages,
0 commit comments