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,113 @@
/*
* 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 { devtools } from 'zustand/middleware';
import { create } from 'zustand';
import {
ListBotDraftType,
OrderBy,
PublishStatus,
type GetDraftBotListRequest,
} from '@coze-arch/bot-api/developer_api';
type TParams = Pick<
GetDraftBotListRequest,
| 'order_by'
| 'bot_name'
| 'team_bot_type'
| 'is_publish'
| 'is_fav'
| 'cursor_id'
> & {
pageSize: number;
};
interface BotListFilterStoreState {
requestParams: TParams;
}
type TSetParamAction<ParamsKey extends keyof TParams> = (
value: TParams[ParamsKey],
) => void;
interface BotListFilterStoreAction {
reset: () => void;
setBotName: TSetParamAction<'bot_name'>;
setOrder: TSetParamAction<'order_by'>;
setTeamBotType: TSetParamAction<'team_bot_type'>;
setPageSize: TSetParamAction<'pageSize'>;
setPublishStatus: TSetParamAction<'is_publish'>;
setIsFavorite: TSetParamAction<'is_fav'>;
setCursorID: TSetParamAction<'cursor_id'>;
}
const defaultState = {
requestParams: {
order_by: OrderBy.UpdateTime,
team_bot_type: ListBotDraftType.TeamBots,
bot_name: void 0,
pageSize: 24,
is_publish: PublishStatus.All,
is_fav: false,
cursor_id: '',
},
} as const;
export const useBotListFilterStore = create<
BotListFilterStoreState & BotListFilterStoreAction
>()(
devtools(
(set, get) => ({
...defaultState,
reset: () => {
set(defaultState);
},
setBotName: name => {
set({ requestParams: { ...get().requestParams, bot_name: name } });
},
setOrder: orderBy => {
set({ requestParams: { ...get().requestParams, order_by: orderBy } });
},
setTeamBotType: teamBotType => {
set({
requestParams: { ...get().requestParams, team_bot_type: teamBotType },
});
},
setPageSize: pageSize => {
set({ requestParams: { ...get().requestParams, pageSize } });
},
setPublishStatus: publishStatus => {
set({
requestParams: { ...get().requestParams, is_publish: publishStatus },
});
},
setIsFavorite: payload => {
set({
requestParams: { ...get().requestParams, is_fav: payload },
});
},
setCursorID: payload => {
set({
requestParams: { ...get().requestParams, cursor_id: payload },
});
},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.botListFilterStore',
},
),
);

View File

@@ -0,0 +1,49 @@
/*
* 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 { devtools } from 'zustand/middleware';
import { create } from 'zustand';
interface BotModeStore {
isCollaboration: boolean;
}
interface BotModeAction {
setIsCollaboration: (isCollaboration: boolean) => void;
}
export const initialStore: BotModeStore = {
isCollaboration: false,
};
//TODO 后续改成context或者迁移到package内。
export const useBotModeStore = create<BotModeStore & BotModeAction>()(
devtools(
(set, get) => ({
...initialStore,
reset: () => {
set(initialStore);
},
setIsCollaboration: isCollaboration => {
set({ isCollaboration });
},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.botMode',
},
),
);

View File

@@ -0,0 +1,75 @@
/*
* 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 { devtools } from 'zustand/middleware';
import { create } from 'zustand';
interface WorkflowState {
showModalDefault: boolean;
}
interface BotState {
previousBotID: string;
modeSwitching: boolean;
}
interface BotPageState {
bot: BotState;
tools: {
workflow: WorkflowState;
};
}
interface BotPageAction {
setBotState: (state: Partial<BotState>) => void;
setWorkflowState: (state: Partial<WorkflowState>) => void;
}
const initialStoreState: BotPageState = {
bot: { previousBotID: '', modeSwitching: false },
tools: {
workflow: {
showModalDefault: false,
},
},
};
const useBotPageStore = create<BotPageState & BotPageAction>()(
devtools(
(set, get) => ({
...initialStoreState,
setBotState: nextState => {
const prevState = get().bot;
set({
bot: { ...prevState, ...nextState },
});
},
setWorkflowState: nextState => {
const prevState = get().tools.workflow;
set({
tools: { workflow: { ...prevState, ...nextState } },
});
},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.botPage',
},
),
);
export { useBotPageStore };

View File

@@ -0,0 +1,17 @@
/*
* 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 { useDebugStore } from './store';

View File

@@ -0,0 +1,53 @@
/*
* 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 { devtools } from 'zustand/middleware';
import { create } from 'zustand';
interface DebugPanelStore {
/** debug panel 展示状态 */
isDebugPanelShow: boolean;
/** 当前选中的debug query id */
currentDebugQueryId: string;
}
interface DebugPanelAction {
setIsDebugPanelShow: (isDebugPanelShow: boolean) => void;
setCurrentDebugQueryId: (currentDebugQueryId: string) => void;
}
const DEFAULT_DEBUG_PANEL_STORE = (): DebugPanelStore => ({
isDebugPanelShow: false,
currentDebugQueryId: '',
});
export const useDebugStore = create<DebugPanelStore & DebugPanelAction>()(
devtools(
set => ({
...DEFAULT_DEBUG_PANEL_STORE(),
setIsDebugPanelShow: isDebugPanelShow => {
set({ isDebugPanelShow });
},
setCurrentDebugQueryId: currentDebugQueryId => {
set({ currentDebugQueryId });
},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.debugPanelStore',
},
),
);

View File

@@ -0,0 +1,17 @@
/*
* 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 { useEvaluationPanelStore } from './store';

View File

@@ -0,0 +1,47 @@
/*
* 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 { devtools } from 'zustand/middleware';
import { create } from 'zustand';
interface EvaluationPaneState {
isEvaluationPanelVisible: boolean;
}
interface EvaluationPaneAction {
setIsEvaluationPanelVisible: (visible: boolean) => void;
}
const DEFAULT_EVALUATION_PANEL_STORE = (): EvaluationPaneState => ({
isEvaluationPanelVisible: false,
});
export const useEvaluationPanelStore = create<
EvaluationPaneState & EvaluationPaneAction
>()(
devtools(
set => ({
...DEFAULT_EVALUATION_PANEL_STORE(),
setIsEvaluationPanelVisible: visible => {
set({ isEvaluationPanelVisible: visible });
},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.evaluationPanelStore',
},
),
);

View File

@@ -0,0 +1,56 @@
/*
* 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 { devtools } from 'zustand/middleware';
import { create } from 'zustand';
import { I18n } from '@coze-arch/i18n';
import { type ExploreBotCategory } from '@coze-arch/bot-api/developer_api';
interface ExploreStore {
selectedCategory: ExploreBotCategory;
}
interface ExploreAction {
reset: () => void;
setSelectedCategory: (category: ExploreBotCategory) => void;
}
export const getDefaultCategory: () => ExploreBotCategory = () => ({
id: 'all',
name: I18n.t('explore_bot_category_all'),
});
const initialStore: ExploreStore = {
selectedCategory: getDefaultCategory(),
};
export const useExploreStore = create<ExploreStore & ExploreAction>()(
devtools(
set => ({
...initialStore,
reset: () => {
set(initialStore);
},
setSelectedCategory: category => {
set({ selectedCategory: category });
},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.exploreStore',
},
),
);

View File

@@ -0,0 +1,23 @@
/*
* 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.
*/
/**store */
export { useBotListFilterStore } from './bot-list-filter';
export { useRiskWarningStore } from './risk-warning/store';
export { useBotPageStore } from './bot-page/store';
export { useDebugStore } from './debug-panel';
export { useBotModeStore } from './bot-mode';
export { useEvaluationPanelStore } from './evaluation-panel';

View File

@@ -0,0 +1,58 @@
/*
* 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 { devtools } from 'zustand/middleware';
import { create } from 'zustand';
interface RiskStore {
pluginRiskIsRead: boolean;
toolHiddenModeNewbieGuideIsRead: boolean;
}
interface RiskAction {
reset: () => void;
setPluginRiskIsRead: (flag: boolean) => void;
setToolHiddenModeNewbieGuideIsRead: (flag: boolean) => void;
}
const initialStore: RiskStore = {
pluginRiskIsRead: true,
toolHiddenModeNewbieGuideIsRead: true,
// 支持扩展其它风险提示...
};
export const useRiskWarningStore = create<RiskStore & RiskAction>()(
devtools(
set => ({
...initialStore,
reset: () => {
set(initialStore);
},
setPluginRiskIsRead: flag => {
set({ pluginRiskIsRead: flag });
},
setToolHiddenModeNewbieGuideIsRead: flag => {
set({
toolHiddenModeNewbieGuideIsRead: flag,
});
},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.riskWarningStore',
},
),
);