feat: support conversation isolation (#2443)
Co-authored-by: yangyu.1 <tomasyu985@gmail.com>
This commit is contained in:
@ -34,6 +34,7 @@ import {
|
||||
type SortedConversationItem,
|
||||
} from '@/types/conversations';
|
||||
import { Layout } from '@/types/client';
|
||||
import { useUserInfo } from '@/components/studio-open-chat/hooks';
|
||||
|
||||
import {
|
||||
PcConversationItem,
|
||||
@ -93,6 +94,8 @@ export const ConversationList = forwardRef<
|
||||
})),
|
||||
);
|
||||
|
||||
const userInfo = useUserInfo();
|
||||
|
||||
const conversationRef = useRef<ChatState['currentConversationInfo']>();
|
||||
const [addLoading, setAddLoading] = useState(false);
|
||||
const {
|
||||
@ -114,6 +117,7 @@ export const ConversationList = forwardRef<
|
||||
bot_id: botId,
|
||||
// @ts-expect-error: 有这个属性,但是 openapi 没有暴露
|
||||
connector_id: connectorId,
|
||||
user_id: IS_OPEN_SOURCE ? userInfo?.id : undefined,
|
||||
});
|
||||
if (res?.id) {
|
||||
conversationRef.current = {
|
||||
|
||||
@ -27,11 +27,13 @@ import {
|
||||
|
||||
import { type ChatState } from '../store/store';
|
||||
import { useChatAppProps, useChatAppStore } from '../store';
|
||||
import { useUserInfo } from './use-user-info';
|
||||
import { usePaginationRequest } from './use-pagination-request';
|
||||
|
||||
// 扩展ListConversationReq类型以满足PaginationParams约束
|
||||
type ExtendedListConversationReq = ListConversationReq & {
|
||||
sort_field: 'created_at' | 'updated_at';
|
||||
user_id?: string; // 开源专有
|
||||
[key: string]: unknown;
|
||||
};
|
||||
|
||||
@ -76,6 +78,8 @@ export const useConversationList = (
|
||||
})),
|
||||
);
|
||||
|
||||
const userInfo = useUserInfo();
|
||||
|
||||
const { data, hasMore, loadMore, loading } = usePaginationRequest<
|
||||
Conversation,
|
||||
ExtendedListConversationReq
|
||||
@ -99,6 +103,7 @@ export const useConversationList = (
|
||||
bot_id: botId,
|
||||
connector_id: connectorId,
|
||||
sort_field: order,
|
||||
user_id: IS_OPEN_SOURCE ? userInfo?.id : undefined,
|
||||
},
|
||||
pageSize,
|
||||
initialPageNum,
|
||||
|
||||
@ -20,6 +20,7 @@ import { type SceneConfig } from '@coze-common/chat-core';
|
||||
|
||||
import { OpenApiSource } from '@/types/open';
|
||||
import { useChatAppProps } from '@/components/studio-open-chat/store';
|
||||
import { useUserInfo } from '@/components/studio-open-chat/hooks';
|
||||
|
||||
import { type ChatProviderFunc } from '../type';
|
||||
export const useClearHistoryAdapter = ({
|
||||
@ -29,6 +30,7 @@ export const useClearHistoryAdapter = ({
|
||||
}): SceneConfig => {
|
||||
const { chatConfig } = useChatAppProps();
|
||||
const refConnectorId = useRef('');
|
||||
const userInfo = useUserInfo();
|
||||
refConnectorId.current = chatConfig?.auth?.connectorId || '';
|
||||
|
||||
return useMemo(() => {
|
||||
@ -60,7 +62,11 @@ export const useClearHistoryAdapter = ({
|
||||
const botId = requestConfig.data.bot_id;
|
||||
return {
|
||||
...requestConfig,
|
||||
data: { bot_id: botId, connector_id: refConnectorId.current },
|
||||
data: {
|
||||
bot_id: botId,
|
||||
connector_id: refConnectorId.current,
|
||||
user_id: IS_OPEN_SOURCE ? userInfo?.id : undefined,
|
||||
},
|
||||
};
|
||||
},
|
||||
],
|
||||
|
||||
@ -17,7 +17,10 @@
|
||||
import { useCallback } from 'react';
|
||||
|
||||
import { type ShortCutCommand } from '@coze-common/chat-area-plugins-chat-shortcuts';
|
||||
import { type MixInitResponse } from '@coze-common/chat-area';
|
||||
import {
|
||||
type UserSenderInfo,
|
||||
type MixInitResponse,
|
||||
} from '@coze-common/chat-area';
|
||||
import i18n from '@coze-arch/i18n/intl';
|
||||
import { type BotInfo, type CozeAPI } from '@coze/api';
|
||||
|
||||
@ -134,12 +137,14 @@ const getConversationInfo = async ({
|
||||
connectorId,
|
||||
defaultHistoryMessage,
|
||||
onDefaultHistoryClear,
|
||||
userInfo,
|
||||
}: GetRequestInfoProps & {
|
||||
conversationId?: string;
|
||||
sectionId?: string;
|
||||
connectorId: string;
|
||||
defaultHistoryMessage?: MixInitResponse['messageList'];
|
||||
onDefaultHistoryClear?: () => void;
|
||||
userInfo: UserSenderInfo | null;
|
||||
}): Promise<
|
||||
Pick<
|
||||
MixInitResponse,
|
||||
@ -161,6 +166,7 @@ const getConversationInfo = async ({
|
||||
connector_id: connectorId,
|
||||
page_num: 1,
|
||||
page_size: 1,
|
||||
user_id: IS_OPEN_SOURCE ? userInfo?.id : undefined,
|
||||
},
|
||||
)) as {
|
||||
data: {
|
||||
@ -185,6 +191,7 @@ const getConversationInfo = async ({
|
||||
messages: historyMessage,
|
||||
// @ts-expect-error: connector_id is not in the type
|
||||
connector_id: connectorId,
|
||||
user_id: IS_OPEN_SOURCE ? userInfo?.id : undefined,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@ -204,6 +211,7 @@ const getConversationInfo = async ({
|
||||
bot_id: botId,
|
||||
// @ts-expect-error: connector_id is not in the type
|
||||
connector_id: connectorId,
|
||||
user_id: IS_OPEN_SOURCE ? userInfo?.id : undefined,
|
||||
},
|
||||
{
|
||||
headers: {
|
||||
@ -329,6 +337,7 @@ export const useRequestInit = () => {
|
||||
connectorId,
|
||||
onDefaultHistoryClear,
|
||||
defaultHistoryMessage,
|
||||
userInfo,
|
||||
}),
|
||||
]);
|
||||
const prologue = (requestDataBotInfo.prologue || '').replaceAll(
|
||||
|
||||
Reference in New Issue
Block a user