feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
81
frontend/packages/foundation/foundation-sdk/README.md
Normal file
81
frontend/packages/foundation/foundation-sdk/README.md
Normal file
@@ -0,0 +1,81 @@
|
||||
# @coze-foundation/foundation-sdk
|
||||
|
||||
基座提供sdk的具体实现package
|
||||
|
||||
## Overview
|
||||
|
||||
This package is part of the Coze Studio monorepo and provides architecture functionality. It includes sdk.
|
||||
|
||||
## Getting Started
|
||||
|
||||
### Installation
|
||||
|
||||
Add this package to your `package.json`:
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@coze-foundation/foundation-sdk": "workspace:*"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then run:
|
||||
|
||||
```bash
|
||||
rush update
|
||||
```
|
||||
|
||||
### Usage
|
||||
|
||||
```typescript
|
||||
import { /* exported functions/components */ } from '@coze-foundation/foundation-sdk';
|
||||
|
||||
// Example usage
|
||||
// TODO: Add specific usage examples
|
||||
```
|
||||
|
||||
## Features
|
||||
|
||||
- Sdk
|
||||
|
||||
## API Reference
|
||||
|
||||
### Exports
|
||||
|
||||
- `logoutOnly, uploadAvatar`
|
||||
- `getIsSettled,
|
||||
getIsLogined,
|
||||
getUserInfo,
|
||||
getUserAuthInfos,
|
||||
useIsSettled,
|
||||
useIsLogined,
|
||||
useUserInfo,
|
||||
useUserAuthInfo,
|
||||
useUserLabel,
|
||||
subscribeUserAuthInfos,
|
||||
refreshUserInfo,
|
||||
useLoginStatus,
|
||||
getLoginStatus,`
|
||||
- `BackButton, SideSheetMenu`
|
||||
- `useSpace`
|
||||
|
||||
|
||||
For detailed API documentation, please refer to the TypeScript definitions.
|
||||
|
||||
## Development
|
||||
|
||||
This package is built with:
|
||||
|
||||
- TypeScript
|
||||
- Modern JavaScript
|
||||
- Vitest for testing
|
||||
- ESLint for code quality
|
||||
|
||||
## Contributing
|
||||
|
||||
This package is part of the Coze Studio monorepo. Please follow the monorepo contribution guidelines.
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
describe('Hello World', () => {
|
||||
it('test', () => {
|
||||
expect(1).toBe(1);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["./dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'node',
|
||||
rules: {},
|
||||
});
|
||||
33
frontend/packages/foundation/foundation-sdk/package.json
Normal file
33
frontend/packages/foundation/foundation-sdk/package.json
Normal file
@@ -0,0 +1,33 @@
|
||||
{
|
||||
"name": "@coze-foundation/foundation-sdk",
|
||||
"version": "0.0.1",
|
||||
"description": "基座提供sdk的具体实现package",
|
||||
"license": "Apache-2.0",
|
||||
"author": "sunzhiyuan.evan@bytedance.com",
|
||||
"maintainers": [],
|
||||
"main": "src/index.ts",
|
||||
"scripts": {
|
||||
"build": "exit 0",
|
||||
"lint": "eslint ./ --cache",
|
||||
"test": "vitest --run --passWithNoTests",
|
||||
"test:cov": "npm run test -- --coverage"
|
||||
},
|
||||
"dependencies": {
|
||||
"@coze-arch/bot-api": "workspace:*",
|
||||
"@coze-arch/coze-design": "0.0.6-alpha.346d77",
|
||||
"@coze-foundation/account-adapter": "workspace:*",
|
||||
"@coze-foundation/layout": "workspace:*",
|
||||
"@coze-foundation/space-store": "workspace:*"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@coze-arch/eslint-config": "workspace:*",
|
||||
"@coze-arch/foundation-sdk": "workspace:*",
|
||||
"@coze-arch/ts-config": "workspace:*",
|
||||
"@coze-arch/vitest-config": "workspace:*",
|
||||
"@types/node": "^18",
|
||||
"@vitest/coverage-v8": "~3.0.5",
|
||||
"sucrase": "^3.32.0",
|
||||
"vitest": "~3.0.5"
|
||||
}
|
||||
}
|
||||
|
||||
43
frontend/packages/foundation/foundation-sdk/src/index.ts
Normal file
43
frontend/packages/foundation/foundation-sdk/src/index.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
/*
|
||||
* 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 useCurrentTheme as useCurrentThemeOfSDK } from '@coze-arch/foundation-sdk';
|
||||
import { useTheme } from '@coze-arch/coze-design';
|
||||
|
||||
export const useCurrentTheme: typeof useCurrentThemeOfSDK = () =>
|
||||
useTheme().theme;
|
||||
|
||||
export { logoutOnly, uploadAvatar } from './passport';
|
||||
|
||||
export {
|
||||
getIsSettled,
|
||||
getIsLogined,
|
||||
getUserInfo,
|
||||
getUserAuthInfos,
|
||||
useIsSettled,
|
||||
useIsLogined,
|
||||
useUserInfo,
|
||||
useUserAuthInfo,
|
||||
useUserLabel,
|
||||
subscribeUserAuthInfos,
|
||||
refreshUserInfo,
|
||||
useLoginStatus,
|
||||
getLoginStatus,
|
||||
} from './user';
|
||||
|
||||
export { BackButton, SideSheetMenu } from '@coze-foundation/layout';
|
||||
|
||||
export { useSpace } from './space';
|
||||
29
frontend/packages/foundation/foundation-sdk/src/passport.ts
Normal file
29
frontend/packages/foundation/foundation-sdk/src/passport.ts
Normal 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 {
|
||||
type logoutOnly as logoutOnlyOfSdk,
|
||||
type uploadAvatar as uploadAvatarOfSdk,
|
||||
} from '@coze-arch/foundation-sdk';
|
||||
import {
|
||||
logout as logoutOnlyImpl,
|
||||
passportApi,
|
||||
} from '@coze-foundation/account-adapter';
|
||||
|
||||
export const logoutOnly = logoutOnlyImpl satisfies typeof logoutOnlyOfSdk;
|
||||
|
||||
export const uploadAvatar: typeof uploadAvatarOfSdk = (avatar: File) =>
|
||||
passportApi.uploadAvatar({ avatar });
|
||||
24
frontend/packages/foundation/foundation-sdk/src/space.ts
Normal file
24
frontend/packages/foundation/foundation-sdk/src/space.ts
Normal 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 { type BotSpace } from '@coze-arch/bot-api/developer_api';
|
||||
import { useSpace as useInternalSpace } from '@coze-foundation/space-store';
|
||||
|
||||
export function useSpace(spaceId: string): BotSpace | undefined {
|
||||
const { space } = useInternalSpace(spaceId);
|
||||
|
||||
return space;
|
||||
}
|
||||
76
frontend/packages/foundation/foundation-sdk/src/user.ts
Normal file
76
frontend/packages/foundation/foundation-sdk/src/user.ts
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* 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 refreshUserInfo as refreshUserInfoOfSdk,
|
||||
type getIsSettled as getIsSettledOfSdk,
|
||||
type getIsLogined as getIsLoginedOfSdk,
|
||||
type getUserInfo as getUserInfoOfSdk,
|
||||
type useIsSettled as useIsSettledOfSdk,
|
||||
type useIsLogined as useIsLoginedOfSdk,
|
||||
type useUserInfo as useUserInfoOfSdk,
|
||||
type getLoginStatus as getLoginStatusOfSdk,
|
||||
type useLoginStatus as useLoginStatusOfSdk,
|
||||
type getUserAuthInfos as getUserAuthInfosOfSdk,
|
||||
type useUserAuthInfo as useUserAuthInfoOfSdk,
|
||||
type useUserLabel as useUserLabelOfSdk,
|
||||
type subscribeUserAuthInfos as subscribeUserAuthInfosOfSdk,
|
||||
} from '@coze-arch/foundation-sdk';
|
||||
import {
|
||||
refreshUserInfo as refreshUserInfoImpl,
|
||||
getLoginStatus as getLoginStatusImpl,
|
||||
useLoginStatus as useLoginStatusImpl,
|
||||
getUserInfo as getUserInfoImpl,
|
||||
useUserInfo as useUserInfoImpl,
|
||||
getUserAuthInfos as getUserAuthInfosImpl,
|
||||
useUserAuthInfo as useUserAuthInfoImpl,
|
||||
useUserLabel as useUserLabelImpl,
|
||||
subscribeUserAuthInfos as subscribeUserAuthInfosImpl,
|
||||
} from '@coze-foundation/account-adapter';
|
||||
|
||||
/** @deprecated 使用 getLoginStatus */
|
||||
export const getIsSettled = (() =>
|
||||
getLoginStatus() !== 'settling') satisfies typeof getIsSettledOfSdk;
|
||||
/** @deprecated 使用 getLoginStatus */
|
||||
export const getIsLogined = (() =>
|
||||
getLoginStatus() === 'logined') satisfies typeof getIsLoginedOfSdk;
|
||||
export const getUserInfo = getUserInfoImpl satisfies typeof getUserInfoOfSdk;
|
||||
export const getUserAuthInfos =
|
||||
getUserAuthInfosImpl satisfies typeof getUserAuthInfosOfSdk;
|
||||
/** @deprecated 使用 useLoginStatus */
|
||||
export const useIsSettled = (() => {
|
||||
const status = useLoginStatus();
|
||||
return status !== 'settling';
|
||||
}) satisfies typeof useIsSettledOfSdk;
|
||||
/** @deprecated 使用 useLoginStatus */
|
||||
export const useIsLogined = (() => {
|
||||
const status = useLoginStatus();
|
||||
return status === 'logined';
|
||||
}) satisfies typeof useIsLoginedOfSdk;
|
||||
export const useUserInfo = useUserInfoImpl satisfies typeof useUserInfoOfSdk;
|
||||
|
||||
export const useUserAuthInfo =
|
||||
useUserAuthInfoImpl satisfies typeof useUserAuthInfoOfSdk;
|
||||
export const useUserLabel = useUserLabelImpl satisfies typeof useUserLabelOfSdk;
|
||||
export const subscribeUserAuthInfos =
|
||||
subscribeUserAuthInfosImpl satisfies typeof subscribeUserAuthInfosOfSdk;
|
||||
|
||||
export const refreshUserInfo =
|
||||
refreshUserInfoImpl satisfies typeof refreshUserInfoOfSdk;
|
||||
export const useLoginStatus =
|
||||
useLoginStatusImpl satisfies typeof useLoginStatusOfSdk;
|
||||
export const getLoginStatus =
|
||||
getLoginStatusImpl satisfies typeof getLoginStatusOfSdk;
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"compilerOptions": {
|
||||
"types": [],
|
||||
"rootDir": "./src",
|
||||
"outDir": "./dist",
|
||||
"tsBuildInfoFile": "./dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../account-adapter/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-api/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/foundation-sdk/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/eslint-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/ts-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../../config/vitest-config/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../layout/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../space-store/tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
frontend/packages/foundation/foundation-sdk/tsconfig.json
Normal file
15
frontend/packages/foundation/foundation-sdk/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
],
|
||||
"exclude": ["**/*"]
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"include": ["__tests__", "vitest.config.ts"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
],
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"types": ["vitest/globals"]
|
||||
}
|
||||
}
|
||||
22
frontend/packages/foundation/foundation-sdk/vitest.config.ts
Normal file
22
frontend/packages/foundation/foundation-sdk/vitest.config.ts
Normal 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 { defineConfig } from '@coze-arch/vitest-config';
|
||||
|
||||
export default defineConfig({
|
||||
dirname: __dirname,
|
||||
preset: 'node',
|
||||
});
|
||||
Reference in New Issue
Block a user