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,72 @@
# @coze-studio/tea-interface
interface that descripts how to use tea
## Overview
This package is part of the Coze Studio monorepo and provides architecture functionality. It includes hook, plugin, api and more.
## Getting Started
### Installation
Add this package to your `package.json`:
```json
{
"dependencies": {
"@coze-studio/tea-interface": "workspace:*"
}
}
```
Then run:
```bash
rush update
```
### Usage
```typescript
import { /* exported functions/components */ } from '@coze-studio/tea-interface';
// Example usage
// TODO: Add specific usage examples
```
## Features
- Hook
- Plugin
- Api
- Sdk
## API Reference
### Exports
- `type SdkOption = Omit<IInitParam, 'app_id'>;`
- `type SdkHookListener = (hookInfo?: any) => void;`
- `const Collector: SdkConstructor;`
- `default Sdk;`
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

View File

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

View File

@@ -0,0 +1,15 @@
const { defineConfig } = require('@coze-arch/eslint-config');
module.exports = defineConfig({
packageRoot: __dirname,
preset: 'node',
rules: {
'@typescript-eslint/no-explicit-any': 'off',
'@typescript-eslint/naming-convention': 'off',
'@typescript-eslint/method-signature-style': 'off',
'@stylistic/ts/comma-dangle': 'off',
'@typescript-eslint/adjacent-overload-signatures': 'off',
'@typescript-eslint/unified-signatures': 'off',
'eslint-comments/require-description': 'off',
},
});

View File

@@ -0,0 +1,39 @@
{
"name": "@coze-studio/tea-interface",
"version": "0.0.1",
"description": "interface that descripts how to use tea ",
"license": "Apache-2.0",
"author": "chenjiawei.inizio@bytedance.com",
"maintainers": [],
"exports": {
".": "./src/index.ts",
"./events": "./src/events.ts"
},
"main": "src/index.ts",
"typesVersions": {
"*": {
"events": [
"./src/events.ts"
]
}
},
"scripts": {
"build": "exit 0",
"lint": "eslint ./ --cache",
"test": "vitest --run --passWithNoTests",
"test:cov": "npm run test -- --coverage"
},
"dependencies": {
"@coze-arch/bot-api": "workspace:*"
},
"devDependencies": {
"@coze-arch/eslint-config": "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"
}
}

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.
*/
export type SecondEnvironment = 'cn-coze-pro' | 'cn-coze-basic';
export interface TeamInviteParams {
second_environment?: SecondEnvironment;
}

File diff suppressed because it is too large Load Diff

View File

@@ -0,0 +1,324 @@
/*
* 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 IInitParam {
app_id: number;
channel?: 'cn' | 'va' | 'sg';
channel_domain?: string;
app_key?: string;
caller?: string;
log?: boolean;
disable_webid?: boolean;
disable_sdk_monitor?: boolean;
disable_storage?: boolean;
autotrack?: any;
enable_stay_duration?: any;
disable_route_report?: boolean;
disable_session?: boolean;
disable_heartbeat?: boolean;
disable_auto_pv?: boolean;
enable_tracer?: boolean;
enable_spa?: boolean;
event_verify_url?: string;
enable_ttwebid?: boolean;
user_unique_type?: string;
enable_ab_test?: boolean;
enable_storage?: boolean;
enable_cookie?: boolean;
enable_ab_visual?: boolean;
cross_subdomain?: boolean;
cookie_domain?: string;
enable_multilink?: boolean;
multilink_timeout_ms?: number;
reportTime?: number;
report_time?: number;
timeout?: number;
max_report?: number;
report_url?: string;
maxDuration?: number;
max_duration?: number;
ab_channel_domain?: string;
configPersist?: number;
config_persist?: number;
extend?: any;
ab_timeout?: number;
disable_tracer?: boolean;
filter?: any;
cep?: boolean;
cep_url?: string;
spa?: boolean;
cookie_expire?: number;
enable_custom_webid?: boolean;
disable_track_event?: boolean;
visual_container_id?: number;
visual_domain?: string;
exposure_limit?: number;
ab_batch_time?: number;
allow_hash?: boolean;
enable_native?: boolean;
enable_pageid?: boolean;
enable_spider?: boolean;
enable_debug?: boolean;
visual_catch_api?: boolean;
request_type?: string;
}
export interface IConfigParam {
_staging_flag?: 0 | 1;
user_unique_id?: string;
web_id?: string;
disable_auto_pv?: boolean;
user_type?: number;
os_name?: string;
os_version?: string;
device_model?: string;
ab_client?: string;
ab_version?: string;
ab_sdk_version?: string;
traffic_type?: string;
utm_source?: string;
utm_medium?: string;
utm_campaign?: string;
utm_term?: string;
utm_content?: string;
platform?: string;
browser?: string;
browser_version?: string;
region?: string;
province?: string;
city?: string;
language?: string;
timezone?: number;
tz_offset?: number;
screen_height?: number;
screen_width?: number;
referrer?: string;
referrer_host?: string;
os_api?: number;
creative_id?: number;
ad_id?: number;
campaign_id?: number;
ip_addr_id?: number;
user_agent?: string;
verify_type?: string;
sdk_version?: string;
channel?: string;
app_id?: number;
app_name?: string;
app_version?: string;
app_install_id?: number;
user_id?: any;
device_id?: any;
wechat_openid?: string;
wechat_unionid?: string;
evtParams?: EventParams;
reportErrorCallback?(eventData: any, errorCode: any): void;
[key: string]: any;
}
type EventParams = Record<string, any>;
export type SdkOption = Omit<IInitParam, 'app_id'>;
export type SdkHookListener = (hookInfo?: any) => void;
export interface Plugin {
apply(sdk: Sdk, options: SdkOption): void;
}
export interface PluginConstructor {
new (): Plugin;
pluginName?: string;
init?(Sdk: SdkConstructor): void;
}
export declare enum SdkHook {
Init = 'init',
Config = 'config',
Start = 'start',
Ready = 'ready',
TokenComplete = 'token-complete',
TokenStorage = 'token-storage',
TokenFetch = 'token-fetch',
TokenError = 'token-error',
ConfigUuid = 'config-uuid',
ConfigWebId = 'config-webid',
CustomWebId = 'custom-webid',
TokenChange = 'token-change',
RouteChange = 'route-change',
ConfigTransform = 'config-transform',
EnvTransform = 'env-transform',
SessionReset = 'session-reset',
SessionResetTime = 'session-reset-time',
Event = 'event',
Events = 'events',
CleanEvents = 'clean-events',
BeconEvent = 'becon-event',
SubmitBefore = 'submit-before',
SubmitAfter = 'submit-after',
SubmitError = 'submit-error',
Stay = 'stay',
ResetStay = 'reset-stay',
Ab = 'ab',
AbVar = 'ab-var',
AbAllVars = 'ab-all-vars',
AbConfig = 'ab-config',
AbExternalVersion = 'ab-external-version',
AbVersionChangeOn = 'ab-version-change-on',
AbVersionChangeOff = 'ab-version-change-off',
AbOpenLayer = 'ab-open-layer',
AbCloseLayer = 'ab-close-layer',
Profile = 'profile',
ProfileSet = 'profile-set',
ProfileSetOnce = 'profile-set-once',
ProfileUnset = 'profile-unset',
ProfileIncrement = 'profile-increment',
ProfileAppend = 'profile-append',
ProfileClear = 'profile-clear',
Autotrack = 'autotrack',
}
interface SdkConstructor {
new (name: string): Sdk;
instances: Array<Sdk>;
usePlugin: (
plugin: PluginConstructor,
pluginName?: string,
options?: any,
) => void;
}
interface Sdk {
Types: typeof SdkHook;
sdkReady: boolean;
inited: boolean;
started: boolean;
sended: boolean;
on(type: string, hook: SdkHookListener): void;
once(type: string, hook: SdkHookListener): void;
off(type: string, hook?: SdkHookListener): void;
emit(type: string, info?: any, wait?: string): void;
init(options: IInitParam): void;
config(configs?: IConfigParam): void;
setUserUniqueID(user_unique_id: any): void;
setHeaderInfo(key: string, value: any): void;
removeHeaderInfo(key: string): void;
setDomain(domain: string): void;
getConfig(key?: string): Record<string, any>;
start(): void;
send(): void;
stop(): void;
reStart(): void;
set(type: string): void;
event(event: string, params?: EventParams): void;
beconEvent(event: string, params?: EventParams): void;
event(
events: Array<[string, EventParams] | [string, EventParams, number]>,
): void;
filterEvent(filter: any): void;
predefinePageView(params: any): void;
clearEventCache(): void;
setWebIDviaUnionID(unionId: string): void;
setWebIDviaOpenID(openId): void;
getToken(
callback: (info: Record<string, string | number>) => void,
timeout?: number,
): void;
resetStayDuration(url_path?: string, title?: string, url?: string): void;
resetStayParams(url_path?: string, title?: string, url?: string): void;
profileSet(profile: any): void;
profileSetOnce(profile: any): void;
profileIncrement(profile: any): void;
profileUnset(key: string): void;
profileAppend(profile: any): void;
setExternalAbVersion(vids: string): void;
getVar(name: string, defaultValue: any, callback: (value: any) => void): void;
getAllVars(callback: (value: any) => void): void;
getAbSdkVersion(): string;
onAbSdkVersionChange(callback: (vids: string) => void): () => void;
offAbSdkVersionChange(callback: (vids: string) => void): void;
setExternalAbVersion(vids: string | null): void;
getABConfig(
params: Record<string, any>,
callback: (value: any) => void,
): void;
openOverlayer(): void;
closeOverlayer(): void;
destoryInstace(): void;
destroyInstance(): void;
}
declare const Sdk: Sdk;
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
// @ts-ignore
export const Collector: SdkConstructor;
export default Sdk;
export interface IConfigParamOversea {
_staging_flag?: 0 | 1;
user_unique_id?: string;
disable_auto_pv?: boolean;
web_id?: string;
user_type?: number;
os_name?: string;
os_version?: string;
device_model?: string;
ab_client?: string;
ab_version?: string;
ab_sdk_version?: string;
traffic_type?: string;
utm_source?: string;
utm_medium?: string;
utm_campaign?: string;
utm_term?: string;
utm_content?: string;
platform?: string;
browser?: string;
browser_version?: string;
region?: string;
province?: string;
city?: string;
language?: string;
timezone?: number;
tz_offset?: number;
screen_height?: number;
screen_width?: number;
referrer?: string;
referrer_host?: string;
os_api?: number;
creative_id?: number;
ad_id?: number;
campaign_id?: number;
ip_addr_id?: number;
user_agent?: string;
verify_type?: string;
sdk_version?: string;
channel?: string;
app_id?: number;
app_name?: string;
app_version?: string;
app_install_id?: number;
user_id?: any;
device_id?: any;
evtParams?: EventParams;
reportErrorCallback?(eventData: any, errorCode: any): void;
[key: string]: any;
}

View File

@@ -0,0 +1,40 @@
/*
* 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 PlaygroundSettingParams {
user_id: string;
action: 'page_view' | 'run';
full_url: string;
result?: 'incomplete' | 'success' | 'fail';
detail?: string;
}
export interface PlaygroundAuthorizeParams {
user_id: string;
action:
| 'page_view'
| 'create'
| 'forbid'
| 'edit'
| 'delete'
| 'download'
| 'know'
| 'check'
| 'cancel';
full_url: string;
result?: 'true' | 'false';
detail?: string;
}

View File

@@ -0,0 +1,80 @@
/*
* 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 type ProductEventSource =
| 'add_plugin_menu'
| 'bots_card'
| 'explore_card'
| 'plugin_card'
| 'project_card'
| 'top_card'
| 'bots_detailpage'
| 'explore_bot_detailpage'
| 'workflow_card'
| 'plugin_detailpage'
| 'project_detailpage'
| 'imageflow_card'
| 'home_recommend'
| 'home_feed'
| 'store_search_suggestion'
| 'store_search_resultspage'
| 'user_profile';
export type ProductEventFilterTag = 'all' | 'recommend' | 'recent';
export type ProductEventEntityType =
| 'bot'
| 'plugin'
| 'workflow'
| 'imageflow'
| 'project';
export interface ProductShowFrontParams {
product_id: string;
product_name: string;
entity_type: ProductEventEntityType;
bot_id?: string;
plugin_id?: string;
project_id?: string;
c_position: number;
filter_tag: string;
source: ProductEventSource;
from?: ProductEventSource;
}
export type ProductActionType = 'run';
export interface ProductRunFrontParams {
product_id: string;
product_name: string;
entity_id?: string;
entity_type: ProductEventEntityType;
action: ProductActionType;
}
export interface ProductClickFrontParams {
bot_id?: string;
plugin_id?: string;
entity_type: ProductEventEntityType;
product_name: string;
product_id: string;
c_position: number;
filter_tag: string;
source: ProductEventSource;
from?: string;
action: 'enter_detailpage' | 'expand_tools';
access_entrance?: string;
}

View File

@@ -0,0 +1,28 @@
{
"extends": "@coze-arch/ts-config/tsconfig.node.json",
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"outDir": "dist",
"rootDir": "src",
"module": "CommonJS",
"target": "ES2020",
"moduleResolution": "node",
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
},
"include": ["src"],
"exclude": ["node_modules", "dist"],
"references": [
{
"path": "../bot-api/tsconfig.build.json"
},
{
"path": "../../../config/eslint-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",
"exclude": ["**/*"],
"compilerOptions": {
"composite": true
},
"references": [
{
"path": "./tsconfig.build.json"
},
{
"path": "./tsconfig.misc.json"
}
]
}

View File

@@ -0,0 +1,18 @@
{
"extends": "@coze-arch/ts-config/tsconfig.node.json",
"$schema": "https://json.schemastore.org/tsconfig",
"compilerOptions": {
"rootDir": "./",
"outDir": "./dist",
"module": "CommonJS",
"target": "ES2020",
"moduleResolution": "node"
},
"include": ["__tests__", "vitest.config.ts"],
"exclude": ["./dist"],
"references": [
{
"path": "./tsconfig.build.json"
}
]
}

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 { defineConfig } from '@coze-arch/vitest-config';
export default defineConfig({
dirname: __dirname,
preset: 'node',
});