setIsEditModalOpen(false)}
+ workspaceId={workspaceId}
+ />
{" "}
diff --git a/apps/web/ee/components/pi-chat/system-prompts.tsx b/apps/web/ee/components/pi-chat/system-prompts.tsx
index 58538aa41c..f9a3a84025 100644
--- a/apps/web/ee/components/pi-chat/system-prompts.tsx
+++ b/apps/web/ee/components/pi-chat/system-prompts.tsx
@@ -50,11 +50,11 @@ const SystemPrompts = (props: TSystemPrompt) => {
entityType: projectId ? "project_id" : "workspace_id",
entityIdentifier: projectId?.toString() || workspaceId?.toString() || "",
};
- const newChatId = await createNewChat(focus, isProjectLevel, workspaceId || "");
+ const newChatId = await createNewChat(focus, isProjectLevel, workspaceId);
setIsInitializing("");
// Don't redirect if we are in the floating chat window
if (shouldRedirect) router.push(`/${workspaceSlug}/${isProjectLevel ? "projects/" : ""}pi-chat/${newChatId}`);
- getAnswer(newChatId, prompt.text, focus, isProjectLevel);
+ getAnswer(newChatId, prompt.text, focus, isProjectLevel, workspaceSlug?.toString(), workspaceId?.toString());
};
const promptIcon = getIcon(prompt.type);
diff --git a/apps/web/ee/services/pi-chat.service.ts b/apps/web/ee/services/pi-chat.service.ts
index 48a05a904d..659a6863dc 100644
--- a/apps/web/ee/services/pi-chat.service.ts
+++ b/apps/web/ee/services/pi-chat.service.ts
@@ -70,8 +70,12 @@ export class PiChatService extends APIService {
}
// fetch templates
- async listTemplates(): Promise {
- return this.get(`/api/v1/chat/get-templates/`)
+ async listTemplates(workspaceId: string | undefined): Promise {
+ return this.get(`/api/v1/chat/get-templates/`, {
+ params: {
+ ...(workspaceId && { workspace_id: workspaceId }),
+ },
+ })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
@@ -79,8 +83,11 @@ export class PiChatService extends APIService {
}
// generate title
- async retrieveTitle(chatId: string): Promise {
- return this.post(`/api/v1/chat/generate-title/`, { chat_id: chatId })
+ async retrieveTitle(chatId: string, workspaceId: string | undefined): Promise {
+ return this.post(`/api/v1/chat/generate-title/`, {
+ chat_id: chatId,
+ ...(workspaceId && { workspace_id: workspaceId }),
+ })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
@@ -106,10 +113,11 @@ export class PiChatService extends APIService {
}
// get chat by id
- async retrieveChat(chatId: string): Promise {
+ async retrieveChat(chatId: string, workspaceId: string | undefined): Promise {
return this.get(`/api/v1/chat/get-chat-history-object/`, {
params: {
chat_id: chatId,
+ ...(workspaceId && { workspace_id: workspaceId }),
},
})
.then((response) => response?.data)
@@ -120,16 +128,16 @@ export class PiChatService extends APIService {
// get user threads
async listUserThreads(
- workspaceId: string,
+ workspaceId: string | undefined,
is_project_chat: boolean,
cursor: string = "0"
): Promise {
return this.get(`/api/v1/chat/get-user-threads/`, {
params: {
per_page: 100,
- workspace_id: workspaceId,
is_project_chat,
cursor,
+ ...(workspaceId && { workspace_id: workspaceId }),
},
})
.then((response) => response?.data)
@@ -139,8 +147,12 @@ export class PiChatService extends APIService {
}
// get recent chats
- async listRecentChats(): Promise {
- return this.get(`/api/v1/chat/get-recent-user-threads/`)
+ async listRecentChats(workspaceId: string | undefined): Promise {
+ return this.get(`/api/v1/chat/get-recent-user-threads/`, {
+ params: {
+ ...(workspaceId && { workspace_id: workspaceId }),
+ },
+ })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
@@ -148,8 +160,12 @@ export class PiChatService extends APIService {
}
// get models
- async listAiModels(): Promise {
- return this.get(`/api/v1/chat/get-models/`)
+ async listAiModels(workspaceId?: string): Promise {
+ return this.get(`/api/v1/chat/get-models/`, {
+ params: {
+ ...(workspaceId && { workspace_id: workspaceId }),
+ },
+ })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
@@ -157,8 +173,11 @@ export class PiChatService extends APIService {
}
// favorite chat
- async favoriteChat(chatId: string): Promise {
- return this.post(`/api/v1/chat/favorite-chat/`, { chat_id: chatId })
+ async favoriteChat(chatId: string, workspaceId: string | undefined): Promise {
+ return this.post(`/api/v1/chat/favorite-chat/`, {
+ chat_id: chatId,
+ ...(workspaceId && { workspace_id: workspaceId }),
+ })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
@@ -166,8 +185,11 @@ export class PiChatService extends APIService {
}
// unfavorite chat
- async unfavoriteChat(chatId: string): Promise {
- return this.post(`/api/v1/chat/unfavorite-chat/`, { chat_id: chatId })
+ async unfavoriteChat(chatId: string, workspaceId: string | undefined): Promise {
+ return this.post(`/api/v1/chat/unfavorite-chat/`, {
+ chat_id: chatId,
+ ...(workspaceId && { workspace_id: workspaceId }),
+ })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
@@ -175,9 +197,11 @@ export class PiChatService extends APIService {
}
// get favorite chats
- async listFavoriteChats(workspaceId: string): Promise {
+ async listFavoriteChats(workspaceId: string | undefined): Promise {
return this.get(`/api/v1/chat/get-favorite-chats/`, {
- params: { workspace_id: workspaceId },
+ params: {
+ ...(workspaceId && { workspace_id: workspaceId }),
+ },
})
.then((response) => response?.data)
.catch((error) => {
@@ -186,8 +210,12 @@ export class PiChatService extends APIService {
}
// rename chat
- async renameChat(chatId: string, title: string): Promise {
- return this.post(`/api/v1/chat/rename-chat/`, { chat_id: chatId, title })
+ async renameChat(chatId: string, title: string, workspaceId: string | undefined): Promise {
+ return this.post(`/api/v1/chat/rename-chat/`, {
+ chat_id: chatId,
+ title,
+ ...(workspaceId && { workspace_id: workspaceId }),
+ })
.then((response) => response?.data)
.catch((error) => {
throw error?.response?.data;
diff --git a/apps/web/ee/store/pi-chat/pi-chat.ts b/apps/web/ee/store/pi-chat/pi-chat.ts
index e7aac4bcd6..f46cd7bed7 100644
--- a/apps/web/ee/store/pi-chat/pi-chat.ts
+++ b/apps/web/ee/store/pi-chat/pi-chat.ts
@@ -41,26 +41,39 @@ export interface IPiChatStore {
isPiChatDrawerOpen: boolean;
// computed fn
geUserThreads: () => TUserThreads[];
- geUserThreadsByWorkspaceId: (workspaceId: string) => TUserThreads[];
+ geUserThreadsByWorkspaceId: (workspaceId: string | undefined) => TUserThreads[];
geFavoriteChats: () => TUserThreads[];
getChatById: (chatId: string) => TChatHistory;
// actions
initPiChat: (chatId?: string) => void;
- fetchChatById: (chatId: string) => void;
- getAnswer: (chatId: string, query: string, focus: TFocus, isProjectChat: boolean) => Promise;
- getTemplates: () => Promise;
- fetchUserThreads: (workspaceId: string, isProjectChat: boolean) => void;
+ fetchChatById: (chatId: string, workspaceId: string | undefined) => void;
+ getAnswer: (
+ chatId: string,
+ query: string,
+ focus: TFocus,
+ isProjectChat: boolean,
+ workspaceSlug: string,
+ workspaceId: string | undefined
+ ) => Promise;
+ getTemplates: (workspaceId: string | undefined) => Promise;
+ fetchUserThreads: (workspaceId: string | undefined, isProjectChat: boolean) => void;
searchCallback: (workspace: string, query: string, focus: TFocus) => Promise;
- sendFeedback: (chatId: string, message_index: number, feedback: EFeedback, feedbackMessage?: string) => Promise;
- fetchModels: () => Promise;
+ sendFeedback: (
+ chatId: string,
+ message_index: number,
+ feedback: EFeedback,
+ workspaceId?: string,
+ feedbackMessage?: string
+ ) => Promise;
+ fetchModels: (workspaceId?: string) => Promise;
setActiveModel: (model: TAiModels) => void;
- createNewChat: (focus: TFocus, isProjectChat: boolean, workspaceId: string) => Promise;
- renameChat: (chatId: string, title: string) => Promise;
+ createNewChat: (focus: TFocus, isProjectChat: boolean, workspaceId: string | undefined) => Promise;
+ renameChat: (chatId: string, title: string, workspaceId: string | undefined) => Promise;
deleteChat: (chatId: string, workspaceSlug: string) => Promise;
- favoriteChat: (chatId: string) => Promise;
- unfavoriteChat: (chatId: string) => Promise;
- fetchRecentChats: (isProjectChat: boolean) => Promise;
- fetchFavoriteChats: (workspaceId: string) => Promise;
+ favoriteChat: (chatId: string, workspaceId: string | undefined) => Promise;
+ unfavoriteChat: (chatId: string, workspaceId: string | undefined) => Promise;
+ fetchRecentChats: (workspaceId: string | undefined, isProjectChat: boolean) => Promise;
+ fetchFavoriteChats: (workspaceId: string | undefined) => Promise;
togglePiChatDrawer: (value?: boolean) => void;
}
@@ -158,7 +171,7 @@ export class PiChatStore implements IPiChatStore {
// computed
geUserThreads = computedFn(() => this.piThreads.map((chatId) => this.chatMap[chatId]) || []);
- geUserThreadsByWorkspaceId = computedFn((workspaceId: string) => {
+ geUserThreadsByWorkspaceId = computedFn((workspaceId: string | undefined) => {
if (!workspaceId) return [];
return (
this.projectThreads
@@ -186,7 +199,7 @@ export class PiChatStore implements IPiChatStore {
this.isAuthorized = true;
};
- createNewChat = async (focus: TFocus, isProjectChat: boolean = false, workspaceId: string) => {
+ createNewChat = async (focus: TFocus, isProjectChat: boolean = false, workspaceId: string | undefined) => {
this.isNewChat = true;
let payload: TInitPayload = {
workspace_in_context: focus.isInWorkspaceContext,
@@ -216,8 +229,8 @@ export class PiChatStore implements IPiChatStore {
return newChatId;
};
- getTemplates = async () => {
- const response = await this.piChatService.listTemplates();
+ getTemplates = async (workspaceId: string | undefined) => {
+ const response = await this.piChatService.listTemplates(workspaceId);
return response?.templates;
};
@@ -225,6 +238,7 @@ export class PiChatStore implements IPiChatStore {
isNewChat: boolean,
chatId: string,
payload: TQuery,
+ workspaceId: string | undefined,
callback: (property: "answer" | "reasoning", value: string) => void
) => {
const token = await this.piChatService.retrieveToken(payload);
@@ -263,7 +277,7 @@ export class PiChatStore implements IPiChatStore {
this.isPiTypingMap[chatId] = false;
// Call the title api if its a new chat
if (isNewChat) {
- const title = await this.piChatService.retrieveTitle(chatId);
+ const title = await this.piChatService.retrieveTitle(chatId, workspaceId);
runInAction(() => {
this.isNewChat = false;
update(this.chatMap, chatId, (chat) => ({
@@ -281,7 +295,14 @@ export class PiChatStore implements IPiChatStore {
};
};
- getAnswer = async (chatId: string, query: string, focus: TFocus, isProjectChat: boolean = false) => {
+ getAnswer = async (
+ chatId: string,
+ query: string,
+ focus: TFocus,
+ isProjectChat: boolean = false,
+ workspaceSlug: string,
+ workspaceId: string | undefined
+ ) => {
if (!chatId) {
throw new Error("Chat not initialized");
}
@@ -333,13 +354,15 @@ export class PiChatStore implements IPiChatStore {
}
: {},
is_project_chat: isProjectChat,
+ workspace_slug: workspaceSlug,
+ workspace_id: workspaceId,
};
if (focus.isInWorkspaceContext) {
payload = { ...payload, [focus.entityType]: focus.entityIdentifier };
}
// Api call here
- this.getStreamingAnswer(isNewChat, chatId, payload, (property, value) => {
+ this.getStreamingAnswer(isNewChat, chatId, payload, workspaceId, (property, value) => {
newDialogue[property] += value;
runInAction(() => {
update(this.chatMap, chatId, (chat) => ({
@@ -364,14 +387,14 @@ export class PiChatStore implements IPiChatStore {
}
};
- fetchChatById = async (chatId: string) => {
+ fetchChatById = async (chatId: string, workspaceId: string | undefined) => {
if (this.isNewChat) return;
try {
// Call api here
runInAction(() => {
this.isLoadingMap[chatId] = true;
});
- const response = await this.piChatService.retrieveChat(chatId);
+ const response = await this.piChatService.retrieveChat(chatId, workspaceId);
runInAction(() => {
update(this.chatMap, chatId, (chat) => ({
...chat,
@@ -391,7 +414,7 @@ export class PiChatStore implements IPiChatStore {
}
};
- fetchUserThreads = async (workspaceId: string, isProjectChat: boolean = false) => {
+ fetchUserThreads = async (workspaceId: string | undefined, isProjectChat: boolean = false) => {
const threads = isProjectChat ? this.projectThreads : this.piThreads;
try {
runInAction(() => {
@@ -419,13 +442,13 @@ export class PiChatStore implements IPiChatStore {
}
};
- fetchRecentChats = async (isProjectChat: boolean = false) => {
+ fetchRecentChats = async (workspaceId: string | undefined, isProjectChat: boolean = false) => {
try {
const threads = isProjectChat ? this.projectThreads : this.piThreads;
runInAction(() => {
this.isLoadingThreads = true;
});
- const response = await this.piChatService.listRecentChats();
+ const response = await this.piChatService.listRecentChats(workspaceId);
runInAction(() => {
response.results.forEach((chat) => {
update(this.chatMap, chat.chat_id, (prev) => ({
@@ -446,9 +469,9 @@ export class PiChatStore implements IPiChatStore {
}
};
- fetchModels = async () => {
+ fetchModels = async (workspaceId: string | undefined) => {
try {
- const response = await this.piChatService.listAiModels();
+ const response = await this.piChatService.listAiModels(workspaceId);
runInAction(() => {
this.models = response.models;
response.models.forEach((model) => {
@@ -476,7 +499,13 @@ export class PiChatStore implements IPiChatStore {
return response.results;
};
- sendFeedback = async (chatId: string, message_index: number, feedback: EFeedback, feedbackMessage?: string) => {
+ sendFeedback = async (
+ chatId: string,
+ message_index: number,
+ feedback: EFeedback,
+ workspaceId?: string,
+ feedbackMessage?: string
+ ) => {
const initialState = this.chatMap[chatId]?.dialogue?.[message_index]?.feedback;
runInAction(() => {
runInAction(() => {
@@ -491,6 +520,7 @@ export class PiChatStore implements IPiChatStore {
chat_id: chatId,
feedback,
feedback_message: feedbackMessage,
+ ...(workspaceId && { workspace_id: workspaceId }),
});
return response;
} catch (e) {
@@ -503,7 +533,7 @@ export class PiChatStore implements IPiChatStore {
}
};
- fetchFavoriteChats = async (workspaceId: string) => {
+ fetchFavoriteChats = async (workspaceId: string | undefined) => {
this.isLoadingFavoriteChats = true;
const response = await this.piChatService.listFavoriteChats(workspaceId);
runInAction(() => {
@@ -520,7 +550,7 @@ export class PiChatStore implements IPiChatStore {
});
};
- favoriteChat = async (chatId: string) => {
+ favoriteChat = async (chatId: string, workspaceId: string | undefined) => {
const favoriteChats = this.favoriteChats;
try {
runInAction(() => {
@@ -530,7 +560,7 @@ export class PiChatStore implements IPiChatStore {
}));
this.favoriteChats = [...this.favoriteChats, chatId];
});
- await this.piChatService.favoriteChat(chatId);
+ await this.piChatService.favoriteChat(chatId, workspaceId);
} catch (e) {
runInAction(() => {
update(this.chatMap, chatId, (chat) => ({
@@ -542,7 +572,7 @@ export class PiChatStore implements IPiChatStore {
}
};
- unfavoriteChat = async (chatId: string) => {
+ unfavoriteChat = async (chatId: string, workspaceId: string | undefined) => {
const favoriteChats = this.favoriteChats;
try {
runInAction(() => {
@@ -552,7 +582,7 @@ export class PiChatStore implements IPiChatStore {
}));
this.favoriteChats = favoriteChats.filter((id) => id !== chatId);
});
- await this.piChatService.unfavoriteChat(chatId);
+ await this.piChatService.unfavoriteChat(chatId, workspaceId);
} catch (e) {
runInAction(() => {
update(this.chatMap, chatId, (chat) => ({
@@ -564,7 +594,7 @@ export class PiChatStore implements IPiChatStore {
}
};
- renameChat = async (chatId: string, title: string) => {
+ renameChat = async (chatId: string, title: string, workspaceId: string | undefined) => {
const initialState = this.chatMap[chatId]?.title;
try {
runInAction(() => {
@@ -573,7 +603,7 @@ export class PiChatStore implements IPiChatStore {
title,
}));
});
- await this.piChatService.renameChat(chatId, title);
+ await this.piChatService.renameChat(chatId, title, workspaceId);
} catch (e) {
runInAction(() => {
update(this.chatMap, chatId, (chat) => ({
diff --git a/apps/web/ee/types/pi-chat.d.ts b/apps/web/ee/types/pi-chat.d.ts
index a97ed0cb91..7a3a63c3ee 100644
--- a/apps/web/ee/types/pi-chat.d.ts
+++ b/apps/web/ee/types/pi-chat.d.ts
@@ -25,8 +25,12 @@ export type TQuery = {
[key: string]: string;
};
is_project_chat?: boolean;
+ workspace_slug?: string;
};
-export type TInitPayload = Pick;
+export type TInitPayload = Pick<
+ TQuery,
+ "workspace_in_context" | "workspace_id" | "project_id" | "is_project_chat" | "workspace_slug"
+>;
export type TSearchQuery = {
query: string;
};
@@ -36,6 +40,7 @@ export type TFeedback = {
message_index: number;
feedback: EFeedback;
feedback_message?: string;
+ workspace_id?: string;
};
export type TFocus = {