Skip to content

Commit

Permalink
new cookie names
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Oct 17, 2024
1 parent f5f0625 commit 269ccb1
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 6 deletions.
5 changes: 3 additions & 2 deletions frontend/app/hooks/useGraph.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { getCookie, setCookie } from "../utils/cookies";
import { ThreadActual, useThreads } from "./useThreads";
import { ModelOptions } from "../types";
import { useRuns } from "./useRuns";
import { ASSISTANT_ID_COOKIE_NAME } from "../utils/constants";

export const createClient = () => {
const apiUrl = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:3000/api";
Expand Down Expand Up @@ -73,7 +74,7 @@ export function useGraph(inputArgs: UseGraphInput) {
}, []);

const getOrCreateAssistant = async () => {
const assistantIdCookie = getCookie("clc_py_assistant_id");
const assistantIdCookie = getCookie(ASSISTANT_ID_COOKIE_NAME);
if (assistantIdCookie) {
setAssistantId(assistantIdCookie);
return;
Expand All @@ -83,7 +84,7 @@ export function useGraph(inputArgs: UseGraphInput) {
graphId: "chat",
});
setAssistantId(assistant.assistant_id);
setCookie("clc_py_assistant_id", assistant.assistant_id);
setCookie(ASSISTANT_ID_COOKIE_NAME, assistant.assistant_id);
};

const streamMessage = async (params: GraphInput) => {
Expand Down
5 changes: 3 additions & 2 deletions frontend/app/hooks/useThreads.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useEffect, useState } from "react";
import { Client, Thread } from "@langchain/langgraph-sdk";
import { getCookie, setCookie } from "../utils/cookies";
import { useToast } from "./use-toast";
import { THREAD_ID_COOKIE_NAME } from "../utils/constants";

export const createClient = () => {
const apiUrl = process.env.NEXT_PUBLIC_API_URL ?? "http://localhost:3000/api";
Expand Down Expand Up @@ -34,7 +35,7 @@ export function useThreads(userId: string | undefined) {
}, [userId]);

const searchOrCreateThread = async (id: string) => {
const threadIdCookie = getCookie("clc_py_thread_id");
const threadIdCookie = getCookie(THREAD_ID_COOKIE_NAME);
if (!threadIdCookie) {
await createThread(id);
return;
Expand Down Expand Up @@ -66,7 +67,7 @@ export function useThreads(userId: string | undefined) {
throw new Error("Thread creation failed.");
}
setThreadId(thread.thread_id);
setCookie("clc_py_thread_id", thread.thread_id);
setCookie(THREAD_ID_COOKIE_NAME, thread.thread_id);
} catch (e) {
console.error("Error creating thread", e);
toast({
Expand Down
5 changes: 3 additions & 2 deletions frontend/app/hooks/useUser.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import { useEffect, useState } from "react";
import { v4 as uuidv4 } from "uuid";
import { getCookie, setCookie } from "../utils/cookies";
import { USER_ID_COOKIE_NAME } from "../utils/constants";

export function useUser() {
const [userId, setUserId] = useState<string>();

useEffect(() => {
if (userId) return;

const userIdCookie = getCookie("clc_user_id");
const userIdCookie = getCookie(USER_ID_COOKIE_NAME);
if (userIdCookie) {
setUserId(userIdCookie);
} else {
const newUserId = uuidv4();
setUserId(newUserId);
setCookie("clc_user_id", newUserId);
setCookie(USER_ID_COOKIE_NAME, newUserId);
}
}, []);

Expand Down
3 changes: 3 additions & 0 deletions frontend/app/utils/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
export const RESPONSE_FEEDBACK_KEY = "user_score";
export const SOURCE_CLICK_KEY = "user_click";
export const ASSISTANT_ID_COOKIE_NAME = "clc_assistant_id_v3";
export const THREAD_ID_COOKIE_NAME = "clc_thread_id_v3";
export const USER_ID_COOKIE_NAME = "clc_user_id_v3";

0 comments on commit 269ccb1

Please sign in to comment.