feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type PropsWithChildren } from 'react';
|
||||
|
||||
import { AnswerActionStoreContext } from '../store/context';
|
||||
import { AnswerActionPreferenceContext } from '../preference/context';
|
||||
import { useInitStoreSet } from '../../hooks/use-init-store-set';
|
||||
|
||||
export const AnswerActionProvider: React.FC<
|
||||
PropsWithChildren<{
|
||||
enableBotTriggerControl: boolean;
|
||||
}>
|
||||
> = ({ children, enableBotTriggerControl }) => {
|
||||
const storeSet = useInitStoreSet();
|
||||
|
||||
return (
|
||||
<AnswerActionStoreContext.Provider value={storeSet}>
|
||||
<AnswerActionPreferenceContext.Provider
|
||||
value={{ enableBotTriggerControl }}
|
||||
>
|
||||
{children}
|
||||
</AnswerActionPreferenceContext.Provider>
|
||||
</AnswerActionStoreContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createContext } from 'react';
|
||||
|
||||
import { type ChatAnswerActionPreference } from './type';
|
||||
|
||||
export const AnswerActionPreferenceContext =
|
||||
createContext<ChatAnswerActionPreference>({
|
||||
enableBotTriggerControl: false,
|
||||
});
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { AnswerActionPreferenceContext } from './context';
|
||||
|
||||
export const useAnswerActionPreference = () =>
|
||||
useContext(AnswerActionPreferenceContext);
|
||||
@@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export interface ChatAnswerActionPreference {
|
||||
enableBotTriggerControl: boolean;
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createContext, type PropsWithChildren } from 'react';
|
||||
|
||||
import { useRequest } from 'ahooks';
|
||||
|
||||
import {
|
||||
type ReportMessageFeedbackFn,
|
||||
type ReportMessageFeedbackFnProviderProps,
|
||||
} from './type';
|
||||
|
||||
export const ReportMessageFeedbackFnContext =
|
||||
createContext<ReportMessageFeedbackFn | null>(null);
|
||||
|
||||
export const ReportMessageFeedbackFnProvider: React.FC<
|
||||
PropsWithChildren<ReportMessageFeedbackFnProviderProps>
|
||||
> = ({ children, reportMessageFeedback }) => {
|
||||
const { runAsync: asyncReportMessage } = useRequest(reportMessageFeedback, {
|
||||
manual: true,
|
||||
});
|
||||
|
||||
return (
|
||||
<ReportMessageFeedbackFnContext.Provider value={asyncReportMessage}>
|
||||
{children}
|
||||
</ReportMessageFeedbackFnContext.Provider>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { ReportMessageFeedbackFnContext } from './context';
|
||||
|
||||
export { ReportMessageFeedbackFnProvider } from './context';
|
||||
|
||||
export const useReportMessageFeedbackFn = () => {
|
||||
const reportMessageFeedbackFn = useContext(ReportMessageFeedbackFnContext);
|
||||
if (!reportMessageFeedbackFn) {
|
||||
throw new Error('reportMessageFeedbackFn not provided');
|
||||
}
|
||||
return reportMessageFeedbackFn;
|
||||
};
|
||||
@@ -0,0 +1,22 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type ChatCore } from '@coze-common/chat-core';
|
||||
export type ReportMessageFeedbackFn = ChatCore['reportMessage'];
|
||||
|
||||
export interface ReportMessageFeedbackFnProviderProps {
|
||||
reportMessageFeedback: ReportMessageFeedbackFn;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { createContext } from 'react';
|
||||
|
||||
import { type StoreSet } from './type';
|
||||
|
||||
export const AnswerActionStoreContext = createContext<StoreSet | null>(null);
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { useContext } from 'react';
|
||||
|
||||
import { AnswerActionStoreContext } from './context';
|
||||
|
||||
export const useAnswerActionStore = () => {
|
||||
const storeSet = useContext(AnswerActionStoreContext);
|
||||
if (!storeSet) {
|
||||
throw new Error('answer action store not provided');
|
||||
}
|
||||
return storeSet;
|
||||
};
|
||||
@@ -0,0 +1,21 @@
|
||||
/*
|
||||
* Copyright 2025 coze-dev Authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { type FavoriteBotTriggerConfigStore } from '../../store/favorite-bot-trigger-config';
|
||||
|
||||
export interface StoreSet {
|
||||
useFavoriteBotTriggerConfigStore: FavoriteBotTriggerConfigStore;
|
||||
}
|
||||
Reference in New Issue
Block a user