feat: manually mirror opencoze's code from bytedance

Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
fanlv
2025-07-20 17:36:12 +08:00
commit 890153324f
14811 changed files with 1923430 additions and 0 deletions

View File

@@ -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>
);
};

View File

@@ -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,
});

View File

@@ -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);

View File

@@ -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;
}

View File

@@ -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>
);
};

View File

@@ -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;
};

View File

@@ -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;
}

View File

@@ -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);

View File

@@ -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;
};

View File

@@ -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;
}