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,5 @@
const { defineConfig } = require('@coze-arch/stylelint-config');
module.exports = defineConfig({
extends: [],
});

View File

@@ -0,0 +1,16 @@
# @coze-studio/premium-store-adapter
> Project template for react component with storybook.
## Features
- [x] eslint & ts
- [x] esm bundle
- [x] umd bundle
- [x] storybook
## Commands
- init: `rush update`
- dev: `npm run dev`
- build: `npm run build`

View File

@@ -0,0 +1,12 @@
{
"operationSettings": [
{
"operationName": "test:cov",
"outputFolderNames": ["coverage"]
},
{
"operationName": "ts-check",
"outputFolderNames": ["./dist"]
}
]
}

View File

@@ -0,0 +1,7 @@
const { defineConfig } = require('@coze-arch/eslint-config');
module.exports = defineConfig({
packageRoot: __dirname,
preset: 'web',
rules: {},
});

View File

@@ -0,0 +1,53 @@
{
"name": "@coze-studio/premium-components-adapter",
"version": "0.0.1",
"description": "token store",
"license": "Apache-2.0",
"author": "fengguocai@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/bot-utils": "workspace:*",
"@coze-arch/i18n": "workspace:*",
"@coze-arch/idl": "workspace:*",
"@coze-arch/logger": "workspace:*",
"classnames": "^2.3.2",
"dayjs": "^1.11.7",
"immer": "^10.0.3",
"lodash-es": "^4.17.21",
"query-string": "^8.1.0",
"zustand": "^4.4.7"
},
"devDependencies": {
"@coze-arch/bot-typings": "workspace:*",
"@coze-arch/eslint-config": "workspace:*",
"@coze-arch/stylelint-config": "workspace:*",
"@coze-arch/ts-config": "workspace:*",
"@coze-arch/vitest-config": "workspace:*",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@testing-library/react-hooks": "^8.0.1",
"@types/lodash-es": "^4.17.10",
"@types/react": "18.2.37",
"@types/react-dom": "18.2.15",
"@vitest/coverage-v8": "~3.0.5",
"react": "~18.2.0",
"react-dom": "~18.2.0",
"stylelint": "^15.11.0",
"vite": "^4.3.9",
"vite-plugin-svgr": "~3.3.0",
"vitest": "~3.0.5"
},
"peerDependencies": {
"react": ">=18.2.0",
"react-dom": ">=18.2.0"
},
"// deps": "immer@^10.0.3 为脚本自动补齐,请勿改动"
}

View File

@@ -0,0 +1,4 @@
<svg width="53" height="52" viewBox="0 0 53 52" fill="none" xmlns="http://www.w3.org/2000/svg">
<rect x="0.5" width="52" height="52" rx="26" fill="#5865F2"/>
<path d="M40.1025 14.3715C40.0913 14.3513 40.0727 14.3355 40.05 14.327C37.4344 13.2151 34.674 12.4222 31.8382 11.9683C31.8124 11.9638 31.7858 11.967 31.7621 11.9774C31.7384 11.9878 31.7189 12.0048 31.7063 12.0261C31.3304 12.6581 30.9892 13.3073 30.6839 13.9712C27.6271 13.5413 24.5176 13.5413 21.4608 13.9712C21.1535 13.3057 20.8068 12.6563 20.4223 12.0261C20.4091 12.0053 20.3895 11.9886 20.3659 11.9783C20.3424 11.968 20.316 11.9645 20.2903 11.9683C17.4542 12.4213 14.6937 13.2142 12.0783 14.327C12.0559 14.3358 12.037 14.3508 12.0243 14.37C6.79407 21.6063 5.36132 28.6647 6.06418 35.6356C6.06615 35.6527 6.07182 35.6692 6.08084 35.6843C6.08985 35.6993 6.10204 35.7125 6.11667 35.723C9.16216 37.8122 12.5686 39.4068 16.1906 40.439C16.2161 40.4461 16.2433 40.4457 16.2686 40.4381C16.2939 40.4304 16.3161 40.4157 16.3321 40.396C17.11 39.4153 17.7993 38.3769 18.393 37.2913C18.4012 37.2764 18.4058 37.26 18.4067 37.2434C18.4075 37.2267 18.4045 37.21 18.3979 37.1945C18.3913 37.1789 18.3812 37.1649 18.3683 37.1532C18.3554 37.1415 18.34 37.1325 18.3231 37.1268C17.2361 36.7414 16.1838 36.277 15.176 35.7376C15.1577 35.7277 15.1423 35.7137 15.1312 35.6969C15.1202 35.6801 15.1137 35.6611 15.1124 35.6414C15.1112 35.6218 15.1152 35.6022 15.124 35.5843C15.1329 35.5664 15.1464 35.5508 15.1633 35.5389C15.3754 35.3922 15.5838 35.2409 15.7883 35.0853C15.8062 35.0716 15.8279 35.0628 15.851 35.0599C15.874 35.057 15.8974 35.0602 15.9187 35.069C22.5211 37.8606 29.6691 37.8606 36.1934 35.069C36.2146 35.0596 36.2383 35.056 36.2617 35.0587C36.2851 35.0613 36.3072 35.07 36.3254 35.0838C36.5302 35.2403 36.7391 35.392 36.952 35.5389C36.969 35.5507 36.9826 35.5662 36.9916 35.584C37.0006 35.6018 37.0047 35.6214 37.0036 35.641C37.0025 35.6607 36.9962 35.6798 36.9853 35.6966C36.9743 35.7135 36.9591 35.7276 36.9408 35.7376C35.9353 36.2815 34.8821 36.7457 33.7923 37.1253C33.7753 37.1313 33.76 37.1405 33.7471 37.1523C33.7343 37.1642 33.7243 37.1784 33.7179 37.1941C33.7114 37.2097 33.7086 37.2265 33.7096 37.2432C33.7106 37.26 33.7154 37.2764 33.7236 37.2913C34.3272 38.3709 35.0155 39.408 35.783 40.3943C35.7985 40.4145 35.8206 40.4297 35.846 40.4377C35.8714 40.4457 35.8988 40.446 35.9245 40.4388C39.553 39.4101 42.9654 37.8153 46.0147 35.723C46.0295 35.713 46.0419 35.7001 46.0509 35.6853C46.06 35.6705 46.0655 35.654 46.0672 35.6371C46.9086 27.5779 44.6584 20.5774 40.1025 14.3715ZM19.379 31.391C17.3912 31.391 15.7533 29.701 15.7533 27.6254C15.7533 25.5498 17.3594 23.8597 19.379 23.8597C21.4144 23.8597 23.0364 25.5645 23.0047 27.6253C23.0047 29.701 21.3985 31.391 19.379 31.391ZM32.7843 31.391C30.7966 31.391 29.1587 29.701 29.1587 27.6254C29.1587 25.5498 30.7648 23.8597 32.7843 23.8597C34.8199 23.8597 36.4418 25.5645 36.4101 27.6253C36.4101 29.701 34.8199 31.391 32.7843 31.391Z" fill="white"/>
</svg>

After

Width:  |  Height:  |  Size: 2.9 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 62 KiB

View File

@@ -0,0 +1,20 @@
/*
* 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 FC } from 'react';
export { useInitOpenPremiumManage } from './use-init-open-premium-manage';
export { usePremiumManageModal } from './use-premium-manage-modal';
export const PremiumManage: FC<unknown> = () => <></>;

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 function useInitOpenPremiumManage(_props: { open: () => void }) {}

View File

@@ -0,0 +1,26 @@
/*
* 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.
*/
const voidFunc = () => {
console.log('unImplement void func');
};
export function usePremiumManageModal(_props?: unknown) {
return {
node: <></>,
open: voidFunc,
close: voidFunc,
};
}

View File

@@ -0,0 +1,32 @@
/*
* 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 { useFetchKnowledgeBenefit } from './use-fetch-knowledge-benefit';
export enum PremiumPaywallBannerScene {
Knowledge, // 知识库场景
Token, // 其余 Token 消耗场景
}
export function PremiumPaywallBanner(_props: {
scene: PremiumPaywallBannerScene;
knowledgeBenefit?: {
total: number;
used: number;
};
center?: boolean;
}) {
return <></>;
}

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.
*/
export function useFetchKnowledgeBenefit(_props: unknown = {}) {
return {
data: {
total: 0,
used: 0,
},
loading: false,
};
}

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.
*/
export enum PremiumPaywallScene {
// 创建新空间
AddSpace,
// 新模型体验
NewModel,
// 付费用户模板
ProTemplate,
// 添加空间成员
AddSpaceMember,
// 协作
Collaborate,
// 跨空间资源复制
CopyResourceCrossSpace,
// 发布到API或者SDK
API,
// 添加音色资源
AddVoice,
// 实时语音对话
RTC,
// 导出日志
ExportLog,
// 查询日志
FilterLog,
}
export function useBenefitAvailable(_props: unknown) {
return true;
}
const voidFunc = () => {
console.log('unImplement void func');
};
export function usePremiumPaywallModal(_props: unknown) {
return {
node: <></>,
open: voidFunc,
close: voidFunc,
};
}

View File

@@ -0,0 +1,37 @@
/*
* 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 {
useInitOpenPremiumManage,
usePremiumManageModal,
PremiumManage,
} from './components/premium-manage';
export {
PremiumPaywallScene,
useBenefitAvailable,
usePremiumPaywallModal,
} from './components/premium-paywall';
export {
useFetchKnowledgeBenefit,
PremiumPaywallBannerScene,
PremiumPaywallBanner,
} from './components/premium-paywall-banner';
import TelegramImage from './components/premium-manage/assets/telegram.svg';
import DiscordImage from './components/premium-manage/assets/discord.svg';
export { TelegramImage, DiscordImage };

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.
*/
/// <reference types='@coze-arch/bot-typings' />

View File

@@ -0,0 +1,45 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@coze-arch/ts-config/tsconfig.web.json",
"compilerOptions": {
"types": [],
"strictNullChecks": true,
"noImplicitAny": true,
"rootDir": "./src",
"outDir": "./dist",
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
},
"include": ["src"],
"references": [
{
"path": "../../../arch/bot-api/tsconfig.build.json"
},
{
"path": "../../../arch/bot-typings/tsconfig.build.json"
},
{
"path": "../../../arch/bot-utils/tsconfig.build.json"
},
{
"path": "../../../arch/i18n/tsconfig.build.json"
},
{
"path": "../../../arch/idl/tsconfig.build.json"
},
{
"path": "../../../arch/logger/tsconfig.build.json"
},
{
"path": "../../../../config/eslint-config/tsconfig.build.json"
},
{
"path": "../../../../config/stylelint-config/tsconfig.build.json"
},
{
"path": "../../../../config/ts-config/tsconfig.build.json"
},
{
"path": "../../../../config/vitest-config/tsconfig.build.json"
}
]
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": true
},
"references": [
{
"path": "./tsconfig.build.json"
},
{
"path": "./tsconfig.misc.json"
}
],
"exclude": ["**/*"]
}

View File

@@ -0,0 +1,24 @@
{
"extends": "@coze-arch/ts-config/tsconfig.web.json",
"$schema": "https://json.schemastore.org/tsconfig",
"include": [
"__tests__",
"stories",
"vitest.config.ts",
"tailwind.config.ts",
"vitest.setup.ts"
],
"exclude": ["./dist"],
"references": [
{
"path": "./tsconfig.build.json"
}
],
"compilerOptions": {
"rootDir": "./",
"outDir": "./dist",
"types": ["vitest/globals"],
"strictNullChecks": true,
"noImplicitAny": true
}
}

View File

@@ -0,0 +1,28 @@
/*
* 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: 'web',
test: {
setupFiles: ['vitest.setup.ts'],
coverage: {
all: true,
},
},
});

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.
*/
vi.stubGlobal('IS_DEV_MODE', false);
vi.mock('@coze-arch/i18n', () => ({
I18n: {
t: vi.fn(),
},
}));
vi.mock('@coze-arch/logger', () => ({
logger: {
error: vi.fn(),
},
}));

View File

@@ -0,0 +1,5 @@
const { defineConfig } = require('@coze-arch/stylelint-config');
module.exports = defineConfig({
extends: [],
});

View File

@@ -0,0 +1,16 @@
# @coze-studio/premium-store-adapter
> Project template for react component with storybook.
## Features
- [x] eslint & ts
- [x] esm bundle
- [x] umd bundle
- [x] storybook
## Commands
- init: `rush update`
- dev: `npm run dev`
- build: `npm run build`

View File

@@ -0,0 +1,381 @@
/*
* 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 SubscriptionDetailV2 } from '@coze-arch/bot-api/trade';
export const mockUserBenefit = {
user_basic_info: {
user_level: 0,
volc_account_info: {
account_id: 12345,
is_volcano_pro_account: false,
instance_id: 'mock_instance_id',
coze_instance_status: 1,
instance_status: 1,
volcano_user_type: 0,
},
},
benefit_type_infos: {
101: {
used: 5,
total: 10,
strategy: 3,
unit: 1,
start_at: 1690000000,
end_at: 1700000000,
},
102: {
used: 5,
total: 10,
strategy: 3,
unit: 1,
start_at: 1690000000,
end_at: 1700000000,
},
},
resource_packages: [
{
package_name: 'Doubao pro 32k TPM扩容包',
package_type: 1,
start_at: '1690000000',
end_at: '1700000000',
total_quota: 100,
remain_quota: 50,
input_quota: 20,
output_quota: 30,
},
],
} as SubscriptionDetailV2;
export const mockPremiumPlansCN = [
{
member_version: 0,
configuration_name: '免费版',
configuration_remark: '团队提效或中小型应用PoC开发',
price_info: {
monthly_price: 69,
annual_price: 690,
annual_discount: 83,
},
right_overview: [
'500资源点/天,不可增购',
'模型每分钟请求数300',
'工作空间数量1人数50',
'知识库空间1GB',
'API累计500次调用',
'日志存储3天',
],
right_list: [
{
right_type_code: 'ModelAndResource',
right_type_name: '模型和资源',
right_type_remark: '',
right: [
{
right_code: 'ResourcePackage',
right_name: '资源点',
right_remark: '备注',
right_value_type: 'string',
right_show_value: [{ type: 'string', value: '500/天' }],
right_value_list: [
{
code: 'Quota',
name: '资源点',
value: '500',
unit: '天',
},
],
},
{
right_code: 'IncreaseModelRpm',
right_name: '提升模型 RPM',
right_remark: '备注',
right_value_type: 'bool',
right_show_value: [{ type: 'bool', value: 'false' }],
right_value_list: [
{
code: 'Support',
name: '是否支持',
value: 'false',
unit: '',
},
],
},
],
},
],
},
{
member_version: 110,
configuration_name: '个人旗舰版',
configuration_remark: '企业提效或大模型应用开发',
price_info: {
monthly_price: 69,
annual_price: 690,
annual_discount: 83,
},
right_overview: [
'500资源点/天,不可增购',
'模型每分钟请求数300',
'工作空间数量1人数50',
'知识库空间1GB',
'API调用不限额度',
'日志存储3天',
'新模型尝鲜',
],
right_list: [
{
right_type_code: 'ModelAndResource',
right_type_name: '模型和资源',
right_type_remark: '',
right: [
{
right_code: 'ResourcePackage',
right_name: '资源点',
right_remark: '备注',
right_value_type: 'string',
right_show_value: [{ type: 'string', value: '500/天' }],
right_value_list: [
{
code: 'Quota',
name: '资源点',
value: '500',
unit: '天',
},
],
},
{
right_code: 'IncreaseModelRpm',
right_name: '提升模型 RPM',
right_remark: '备注',
right_value_type: 'bool',
right_show_value: [{ type: 'bool', value: 'false' }],
right_value_list: [
{
code: 'Support',
name: '是否支持',
value: 'false',
unit: '',
},
],
},
],
},
],
},
{
member_version: 120,
configuration_name: '团队版',
configuration_remark: '适合团队提效或中小型应用 PoC 开发',
price_info: {
monthly_price: 69,
annual_price: 690,
annual_discount: 83,
},
right_overview: [
'500资源点/天,不可增购',
'模型每分钟请求数300',
'工作空间数量1人数50',
'知识库空间1GB',
'API调用不限额度',
'日志存储3天',
'新模型尝鲜',
'支持多人协同编辑',
'支持SSO登录',
'人工客服',
],
right_list: [
{
right_type_code: 'ModelAndResource',
right_type_name: '模型和资源',
right_type_remark: '',
right: [
{
right_code: 'ResourcePackage',
right_name: '资源点',
right_remark: '备注',
right_value_type: 'string',
right_show_value: [{ type: 'string', value: '500/天' }],
right_value_list: [
{
code: 'Quota',
name: '资源点',
value: '500',
unit: '天',
},
],
},
{
right_code: 'IncreaseModelRpm',
right_name: '提升模型 RPM',
right_remark: '备注',
right_value_type: 'bool',
right_show_value: [{ type: 'bool', value: 'false' }],
right_value_list: [
{
code: 'Support',
name: '是否支持',
value: 'false',
unit: '',
},
],
},
],
},
],
},
{
member_version: 130,
configuration_name: '企业版',
configuration_remark: '使用企业提效或大型应用开发',
price_info: {
monthly_price: 69,
annual_price: 690,
annual_discount: 83,
},
right_overview: [
'500资源点/天,不可增购',
'模型每分钟请求数300',
'工作空间数量1人数50',
'知识库空间1GB',
'API调用不限额度',
'日志存储3天',
'新模型尝鲜',
'支持企业用户',
'跨空间的资源迁移',
'成员发布和操作权限管控',
'支持企业用户',
'跨空间的资源迁移',
'成员发布和操作权限管控',
],
right_list: [
{
right_type_code: 'ModelAndResource',
right_type_name: '模型和资源',
right_type_remark: '',
right: [
{
right_code: 'ResourcePackage',
right_name: '资源点',
right_remark: '备注',
right_value_type: 'string',
right_show_value: [{ type: 'string', value: '500/天' }],
right_value_list: [
{
code: 'Quota',
name: '资源点',
value: '500',
unit: '天',
},
],
},
{
right_code: 'IncreaseModelRpm',
right_name: '提升模型 RPM',
right_remark: '备注',
right_value_type: 'bool',
right_show_value: [{ type: 'bool', value: 'false' }],
right_value_list: [
{
code: 'Support',
name: '是否支持',
value: 'false',
unit: '',
},
],
},
],
},
{
right_type_code: 'develop',
right_type_name: '开发调试',
right_type_remark: '',
right: [
{
right_code: 'develop_prompt',
right_name: '提示词调试',
right_remark: '备注',
right_value_type: 'bool',
right_show_value: [{ type: 'string', value: '500/天' }],
right_value_list: [
{
code: 'Quota',
name: '资源点',
value: '500',
unit: '天',
},
],
},
{
right_code: 'develop_knowledge',
right_name: '知识库空间',
right_remark: '备注',
right_value_type: 'string',
right_show_value: [{ type: 'string', value: '2T' }],
right_value_list: [
{
code: 'Support',
name: '是否支持',
value: 'false',
unit: '',
},
],
},
],
},
{
right_type_code: 'prompts',
right_type_name: '开发调试',
right_type_remark: '扣子罗盘',
right: [
{
right_code: 'prompts_version',
right_name: 'Prompts 版本管理',
right_remark: '备注',
right_value_type: 'bool',
right_show_value: [{ type: 'string', value: '500/天' }],
right_value_list: [
{
code: 'Quota',
name: '资源点',
value: '500',
unit: '天',
},
],
},
{
right_code: 'prompts_diff',
right_name: 'Prompts 对比模式',
right_remark: '备注',
right_value_type: 'bool',
right_show_value: [
{ type: 'bool', value: '2T' },
{ type: 'string', value: '2T' },
],
right_value_list: [
{
code: 'Support',
name: '是否支持',
value: 'false',
unit: '',
},
],
},
],
},
],
},
];

View File

@@ -0,0 +1,12 @@
{
"operationSettings": [
{
"operationName": "test:cov",
"outputFolderNames": ["coverage"]
},
{
"operationName": "ts-check",
"outputFolderNames": ["./dist"]
}
]
}

View File

@@ -0,0 +1,7 @@
const { defineConfig } = require('@coze-arch/eslint-config');
module.exports = defineConfig({
packageRoot: __dirname,
preset: 'web',
rules: {},
});

View File

@@ -0,0 +1,46 @@
{
"name": "@coze-studio/premium-store-adapter",
"version": "0.0.1",
"description": "token store",
"license": "Apache-2.0",
"author": "fengguocai@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/idl": "workspace:*",
"zustand": "^4.4.7"
},
"devDependencies": {
"@coze-arch/bot-api": "workspace:*",
"@coze-arch/bot-typings": "workspace:*",
"@coze-arch/eslint-config": "workspace:*",
"@coze-arch/stylelint-config": "workspace:*",
"@coze-arch/ts-config": "workspace:*",
"@coze-arch/vitest-config": "workspace:*",
"@testing-library/jest-dom": "^6.1.5",
"@testing-library/react": "^14.1.2",
"@testing-library/react-hooks": "^8.0.1",
"@types/lodash-es": "^4.17.10",
"@types/react": "18.2.37",
"@types/react-dom": "18.2.15",
"@vitest/coverage-v8": "~3.0.5",
"react": "~18.2.0",
"react-dom": "~18.2.0",
"stylelint": "^15.11.0",
"vite": "^4.3.9",
"vite-plugin-svgr": "~3.3.0",
"vitest": "~3.0.5"
},
"peerDependencies": {
"react": ">=18.2.0",
"react-dom": ">=18.2.0"
},
"// deps": "immer@^10.0.3 为脚本自动补齐,请勿改动"
}

View File

@@ -0,0 +1,51 @@
/*
* 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 { UserLevel, type MemberVersionRights } from '../types';
interface UseBenefitBasicResult {
name: string; // 当前用户套餐名称
level: UserLevel; // 当前工作空间:用户的套餐级别
compareLevel: UserLevel; // 当前工作空间:如果是专业版,值是 UserLevel.ProPersonal其他场景同 level
currPlan: MemberVersionRights; // 当前套餐信息
nextPlan: MemberVersionRights; // 下一个套餐信息。如果当前已经是最高套餐级别,则值为最高级别套餐
accountPlan: MemberVersionRights; // 账号维度的套餐信息
instanceStatus: unknown; // 当前套餐状态,可以用来判断退订/到期状态
isOverdue: boolean; // 是否欠费
isExpired: boolean; // 是否过期
isTerminated: boolean; // 是否退订
maxMember: number; //成员上限
}
const defaultData = {
name: '',
level: UserLevel.Free,
compareLevel: UserLevel.Free,
currPlan: {},
nextPlan: {},
accountPlan: {},
instanceStatus: 1,
isOverdue: false,
isExpired: false,
isTerminated: false,
maxMember: -1,
};
/**
* 获取国内权益基础信息
*/
export function useBenefitBasic(): UseBenefitBasicResult {
return defaultData;
}

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.
*/
const quota = {
/** 当前消耗的额度,对应到套餐内每天刷新的 */
remain: 0,
total: 0,
used: 0,
/** 额外购买的额度,目前只处理国内 */
extraRemain: 0,
extraTotal: 0,
extraUsed: 0,
};
export function usePremiumQuota() {
return quota;
}

View File

@@ -0,0 +1,35 @@
/*
* 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 SubscriptionDetail } from '../types';
const defaultData = {
isFree: false,
isPremiumPlus: false,
hasLowLevelActive: false,
hasHighLevelActive: false,
sub: {},
activeSub: {},
};
export function usePremiumType(): {
isFree: boolean;
isPremiumPlus: boolean;
hasLowLevelActive: boolean;
hasHighLevelActive: boolean;
sub: SubscriptionDetail;
activeSub: SubscriptionDetail;
} {
return defaultData;
}

View File

@@ -0,0 +1,30 @@
/*
* 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 {
usePremiumStore,
PremiumPlanLevel,
PremiumChannel,
} from './stores/premium';
export { useBenefitBasic } from './hooks/use-benefit-basic';
export { usePremiumType } from './hooks/use-premium-type';
export { usePremiumQuota } from './hooks/use-premium-quota';
export { formatPremiumType } from './utils/premium-type';
export { UserLevel } from '@coze-arch/idl/benefit';
export type { PremiumPlan, PremiumSubs, MemberVersionRights } from './types';

View File

@@ -0,0 +1,189 @@
/*
* 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 {
UserLevel,
type PremiumPlan,
type PremiumSubs,
type SubscriptionDetail,
type BindConnection,
type SubscriptionDetailV2,
type MemberVersionRights,
} from '../types';
// 只处理最低和最高订阅服务档位
export enum PremiumPlanLevel {
Free = 0,
PremiumPlus = 20,
}
export enum PremiumChannel {
Coze = '10000010',
Telegram = '11000007',
Discord = '10000028',
}
export interface VolcanoInfo {
authInstanceId?: string;
authUserId?: string;
loading?: boolean;
}
interface PremiumStoreState {
polling: boolean; // 是否开启订阅数据自动轮询
plans: PremiumPlan[]; // 付费订阅计划列表
subs: PremiumSubs; // 所有订阅数据
currentPlan: SubscriptionDetail; // 当前订阅详情
hasTrial: boolean;
connections: BindConnection[]; // 第三方账号连接数据
benefit: SubscriptionDetailV2; // 用户权益数据
plansCN: Array<MemberVersionRights>; // 国内订阅套餐列表
volcanoInfo: VolcanoInfo; // oauth跳转到火山需要用到的参数
}
interface PremiumStoreAction {
/**
* 重置状态
*/
reset: () => void;
/**
* 设置是否轮询获取订阅数据,以下场景需要:
* - Bot详情判断是否需要显示订阅卡片
* - 左侧菜单栏判断是否需要显示'coze premium'
* - 左侧菜单栏展示credits数量信息
*/
setPolling: (polling: boolean) => void;
/**
* 获取海外订阅套餐列表
*/
fetchPremiumPlans: () => Promise<{
plans: PremiumPlan[];
subs: PremiumSubs;
hasTrial: boolean;
}>;
/**
* 设置国内套餐列表
*/
setPremiumPlansCN: (plans: Array<MemberVersionRights>) => void;
/**
* 恢复订阅,暂时只有海外
*/
renewCurrentPlan: (plan: SubscriptionDetail) => void;
/**
* 获取当前用户订阅详情,暂时只有海外
*/
fetchPremiumPlan: () => Promise<SubscriptionDetail>;
/**
* 取消订阅,暂时只有海外
*/
cancelCurrentPlan: () => void;
/**
* 获取渠道绑定信息,暂时只有海外
*/
fetchConnections: () => Promise<void>;
/**
* 取消渠道用户绑定,暂时只有海外
*/
disconnectUser: (connectorId: string) => void;
/**
* 设置当前登录用户权益信息,海内外通用
*/
setUserBenefit: (benefit: unknown) => void;
/**
* 设置当前账号相关火山信息
*/
setVolcanoInfo: (info: VolcanoInfo) => void;
}
const defaultState: PremiumStoreState = {
polling: false,
plans: [],
subs: {},
currentPlan: {},
hasTrial: false,
connections: [],
benefit: {
user_basic_info: {
user_level: UserLevel.Free,
},
},
plansCN: [],
volcanoInfo: {},
};
export const usePremiumStore = create<PremiumStoreState & PremiumStoreAction>()(
devtools(
(set, get) => ({
...defaultState,
reset: () => {
console.log('unImplement usePremiumStore reset ');
},
setPolling: _polling => {
console.log('unImplement usePremiumStore setPolling ');
},
fetchPremiumPlans: async () => {
const { plans, subs, hasTrial } = get();
await 0;
return { plans, subs, hasTrial };
},
setPremiumPlansCN: (plans = []) => {
set({ plansCN: plans });
},
fetchPremiumPlan: async () => {
await 0;
return get().currentPlan;
},
cancelCurrentPlan: () => {
console.log('unImplement usePremiumStore cancelCurrentPlan ');
},
renewCurrentPlan: _detail => {
console.log('unImplement usePremiumStore renewCurrentPlan ');
},
fetchConnections: async () => {
await 0;
console.log('unImplement usePremiumStore fetchConnections ');
},
disconnectUser: _connectorId => {
console.log('unImplement usePremiumStore disconnectUser ');
},
setUserBenefit: _benefit => {
console.log('unImplement usePremiumStore setUserBenefit ');
},
setVolcanoInfo: _volcanoInfo => {
console.log('unImplement usePremiumStore setVolcanoInfo ');
},
}),
{
enabled: IS_DEV_MODE,
name: 'botStudio.premiumStore',
},
),
);

View File

@@ -0,0 +1,61 @@
/*
* 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 SubscriptionBenefitDetail,
type SKUInfo,
type SubscriptionUserInfo,
type SubscriptionDetail,
type SubscriptionRelateBenefit,
type MemberVersionRights,
type SubscriptionDetailV2,
} from '@coze-arch/bot-api/trade';
import { type BindConnection } from '@coze-arch/bot-api/developer_api';
export enum UserLevel {
/** 免费版。 */
Free = 0,
/** 海外
PremiumLite */
PremiumLite = 10,
/** Premium */
Premium = 15,
PremiumPlus = 20,
/** 国内
V1火山专业版 */
V1ProInstance = 100,
/** 个人旗舰版 */
ProPersonal = 110,
/** 团队版 */
Team = 120,
/** 企业版 */
Enterprise = 130,
}
export type {
MemberVersionRights,
SubscriptionDetail,
BindConnection,
SubscriptionDetailV2,
SubscriptionUserInfo,
SKUInfo,
};
export type PremiumPlan = SKUInfo & {
benefit_info?: SubscriptionBenefitDetail;
relate_benefit?: SubscriptionRelateBenefit;
};
export type PremiumSubs = Record<string, SubscriptionUserInfo>;

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.
*/
/// <reference types='@coze-arch/bot-typings' />

View File

@@ -0,0 +1,45 @@
/*
* 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 {
PremiumPlan,
PremiumSubs,
SKUInfo,
SubscriptionUserInfo,
} from '../types';
const result = {
isFree: false,
isPremiumPlus: false,
hasLowLevelActive: false,
hasHighLevelActive: false,
sub: {},
activeSub: {},
};
export function formatPremiumType(_props: {
currentPlan?: SKUInfo;
plans: PremiumPlan[];
subs: PremiumSubs;
}): {
isFree: boolean;
isPremiumPlus: boolean;
hasLowLevelActive: boolean;
hasHighLevelActive: boolean;
sub: SubscriptionUserInfo;
activeSub: SubscriptionUserInfo;
} {
return result;
}

View File

@@ -0,0 +1,36 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"extends": "@coze-arch/ts-config/tsconfig.web.json",
"compilerOptions": {
"types": [],
"strictNullChecks": true,
"noImplicitAny": true,
"rootDir": "./src",
"outDir": "./dist",
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
},
"include": ["src"],
"references": [
{
"path": "../../../arch/bot-api/tsconfig.build.json"
},
{
"path": "../../../arch/bot-typings/tsconfig.build.json"
},
{
"path": "../../../arch/idl/tsconfig.build.json"
},
{
"path": "../../../../config/eslint-config/tsconfig.build.json"
},
{
"path": "../../../../config/stylelint-config/tsconfig.build.json"
},
{
"path": "../../../../config/ts-config/tsconfig.build.json"
},
{
"path": "../../../../config/vitest-config/tsconfig.build.json"
}
]
}

View File

@@ -0,0 +1,15 @@
{
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"composite": true
},
"references": [
{
"path": "./tsconfig.build.json"
},
{
"path": "./tsconfig.misc.json"
}
],
"exclude": ["**/*"]
}

View File

@@ -0,0 +1,24 @@
{
"extends": "@coze-arch/ts-config/tsconfig.web.json",
"$schema": "https://json.schemastore.org/tsconfig",
"include": [
"__tests__",
"stories",
"vitest.config.ts",
"tailwind.config.ts",
"vitest.setup.ts"
],
"exclude": ["./dist"],
"references": [
{
"path": "./tsconfig.build.json"
}
],
"compilerOptions": {
"rootDir": "./",
"outDir": "./dist",
"types": ["vitest/globals"],
"strictNullChecks": true,
"noImplicitAny": true
}
}

View File

@@ -0,0 +1,28 @@
/*
* 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: 'web',
test: {
setupFiles: ['vitest.setup.ts'],
coverage: {
all: true,
},
},
});

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.
*/
vi.stubGlobal('IS_DEV_MODE', false);
vi.mock('@coze-arch/i18n', () => ({
I18n: {
t: vi.fn(),
},
}));
vi.mock('@coze-arch/logger', () => ({
logger: {
error: vi.fn(),
},
}));