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,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 const PERSONAL_ENTERPRISE_ID = 'personal';

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.
*/
/**
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
*/
import { useCallback } from 'react';
import { useShallow } from 'zustand/react/shallow';
import { useEnterpriseStore } from '../stores/enterprise';
export const useCheckEnterpriseExist = () => {
const { isEnterpriseExist } = useEnterpriseStore(
useShallow(store => ({
isEnterpriseExist: store.isEnterpriseExist,
})),
);
const checkEnterpriseExist = useCallback(() => {
console.log('checkEnterpriseExist');
}, []);
return {
checkEnterpriseExist,
checkEnterpriseExistLoading: false,
isEnterpriseExist,
};
};

View File

@@ -0,0 +1,69 @@
/*
* 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.
*/
/**
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
*/
import { type GetEnterpriseResponseData } from '@coze-arch/bot-api/pat_permission_api';
import { useEnterpriseStore } from '../stores/enterprise';
export interface CurrentEnterpriseInfoProps extends GetEnterpriseResponseData {
organization_id: string | undefined;
}
/**
* 获取当前企业信息。
* 如果当前企业为个人版则返回null。
* 否则返回当前企业信息包括企业信息和组织ID。
* @example
* const { organization_id, enterprise_id } = useCurrentEnterpriseInfo();
* @returns {(GetEnterpriseResponseData & { organization_id: string | undefined }) | null} 当前企业信息或null
*/
export const useCurrentEnterpriseInfo: () => CurrentEnterpriseInfoProps | null =
() => null;
/**
* 获取当前企业ID。
* 如果当前企业类型为个人版,则返回约定的字符串。
* 否则返回当前企业的ID。
* @returns {string} 当前企业ID
*/
export const useCurrentEnterpriseId = () =>
useEnterpriseStore(store => store.enterpriseId);
/**
* 检查当前企业是否为个人版。
* @returns {boolean} 如果当前企业为个人版则返回true否则返回false。
*/
export const useIsCurrentPersonalEnterprise = () => true;
/**
* 获取当前企业的角色列表。
* 如果当前企业类型为个人版,则返回空数组。
* 否则,返回当前企业的角色类型列表,如果列表不存在,则返回空数组。
* @returns {Array} 当前企业的角色列表
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
export const useCurrentEnterpriseRoles = (): any[] => [];
/** 是否是企业版 */
export const useIsEnterpriseLevel = () => false;
/** 是否是团队版 */
export const useIsTeamLevel = () => false;
export const useIsCurrentEnterpriseInit = () =>
useEnterpriseStore(store => store.isCurrentEnterpriseInit);

View File

@@ -0,0 +1,31 @@
/*
* 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.
*/
/**
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
*/
import { useEnterpriseStore } from '../stores/enterprise';
/**
* 获取企业列表的hook。
* 从企业store中获取企业列表并返回企业信息列表。
* @returns {Array} 企业信息列表
*/
export const useEnterpriseList = () => {
const list = useEnterpriseStore(store => store.enterpriseList);
return list?.enterprise_info_list ?? [];
};

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.
*/
/**
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
*/
export { PERSONAL_ENTERPRISE_ID } from './constants';
export { useEnterpriseStore } from './stores/enterprise';
export { useEnterpriseList } from './hooks/use-enterprise-list';
export { useCheckEnterpriseExist } from './hooks/use-check-enterprise-exist';
export {
useCurrentEnterpriseInfo,
useCurrentEnterpriseId,
useIsCurrentPersonalEnterprise,
useCurrentEnterpriseRoles,
useIsEnterpriseLevel,
useIsTeamLevel,
useIsCurrentEnterpriseInit,
CurrentEnterpriseInfoProps,
} from './hooks/use-current-enterprise-info';
// 工具方法
export { switchEnterprise } from './utils/switch-enterprise';
export { isPersonalEnterprise } from './utils/personal';

View File

@@ -0,0 +1,85 @@
/*
* 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.
*/
/**
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
*/
/* eslint-disable @typescript-eslint/no-empty-function */
import { devtools } from 'zustand/middleware';
import { create } from 'zustand';
import {
type GetEnterpriseResponseData,
type ListEnterpriseResponseData,
} from '@coze-arch/bot-api/pat_permission_api';
import { PERSONAL_ENTERPRISE_ID } from '../constants';
interface EnterpriseStoreState {
currentEnterprise?: GetEnterpriseResponseData;
isCurrentEnterpriseInit: boolean;
enterpriseList?: ListEnterpriseResponseData;
isEnterpriseListInit: boolean;
enterpriseId: string;
isEnterpriseExist: boolean;
}
interface EnterpriseStoreAction {
setEnterprise: (enterpriseInfo: GetEnterpriseResponseData) => void;
updateEnterpriseByImmer: (
update: (enterpriseInfo: GetEnterpriseResponseData) => void,
) => void;
setEnterpriseList: (enterpriseList: ListEnterpriseResponseData) => void;
setIsCurrentEnterpriseInit: (isInit: boolean) => void;
setIsEnterpriseListInit: (isInit: boolean) => void;
setEnterpriseId: (enterpriseId: string) => void;
clearEnterprise: () => void;
fetchEnterprise: (enterpriseId: string) => Promise<void>;
setIsEnterpriseExist: (isExist: boolean) => void;
}
export const defaultState: EnterpriseStoreState = {
isCurrentEnterpriseInit: true,
isEnterpriseListInit: true,
enterpriseId: PERSONAL_ENTERPRISE_ID,
isEnterpriseExist: true,
};
export const useEnterpriseStore = create<
EnterpriseStoreState & EnterpriseStoreAction
>()(
// @ts-expect-error skip
devtools(
() => ({
...defaultState,
setEnterprise: (_: GetEnterpriseResponseData) => {},
updateEnterpriseByImmer: (
_: (enterpriseInfo: GetEnterpriseResponseData) => void,
) => {},
clearEnterprise: () => {},
setEnterpriseId: (_: string) => {},
setIsCurrentEnterpriseInit: (_: boolean) => {},
setIsEnterpriseListInit: (_: boolean) => {},
setEnterpriseList: (_: ListEnterpriseResponseData) => {},
setIsEnterpriseExist: (_: boolean) => {},
// 获取企业信息,可连续调用,不存在异步竞争问题。
fetchEnterprise: (_: string) => {},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.enterpriseStore',
},
),
);

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.
*/
/// <reference types='@coze-arch/bot-typings' />
declare const IS_DEV_MODE: boolean;

View File

@@ -0,0 +1,25 @@
/*
* 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.
*/
/**
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
*/
import { PERSONAL_ENTERPRISE_ID } from '../constants';
// 检查企业是否为个人版
export const isPersonalEnterprise = (enterpriseId?: string) =>
enterpriseId === PERSONAL_ENTERPRISE_ID;

View File

@@ -0,0 +1,25 @@
/*
* 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.
*/
/**
* @file 社区版暂时不提供企业管理功能,本文件中导出的方法用于未来拓展使用。
*/
/**
* 切换企业
* @param {string} enterpriseId - 企业ID
*/
export const switchEnterprise = (_: string) => Promise.resolve();