feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
132
frontend/packages/agent-ide/bot-audit-base/README.md
Normal file
132
frontend/packages/agent-ide/bot-audit-base/README.md
Normal file
@@ -0,0 +1,132 @@
|
||||
# @coze-studio/bot-audit-base
|
||||
|
||||
> Audit base package for bot content validation and error handling
|
||||
|
||||
## Project Overview
|
||||
|
||||
This package provides foundational components and interfaces for bot content auditing within the Coze Studio platform. It includes UI components for displaying audit error messages and TypeScript interfaces for audit functionality integration.
|
||||
|
||||
## Features
|
||||
|
||||
- **AuditErrorMessage Component**: Pre-styled React component for displaying audit failure messages with customizable documentation links
|
||||
- **Type Definitions**: Comprehensive TypeScript interfaces for bot audit hooks and functions
|
||||
- **Internationalization Support**: Built-in i18n support for error messages
|
||||
- **Storybook Integration**: Component documentation and testing environment
|
||||
|
||||
## Get Started
|
||||
|
||||
### Installation
|
||||
|
||||
Add this package to your `package.json` dependencies and set it to `workspace:*` version:
|
||||
|
||||
```json
|
||||
{
|
||||
"dependencies": {
|
||||
"@coze-studio/bot-audit-base": "workspace:*"
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
Then run:
|
||||
```bash
|
||||
rush update
|
||||
```
|
||||
|
||||
### Basic Usage
|
||||
|
||||
#### Using the AuditErrorMessage Component
|
||||
|
||||
```tsx
|
||||
import { AuditErrorMessage } from '@coze-studio/bot-audit-base';
|
||||
|
||||
function MyComponent() {
|
||||
return (
|
||||
<AuditErrorMessage
|
||||
link="/docs/custom-guidelines"
|
||||
/>
|
||||
);
|
||||
}
|
||||
```
|
||||
|
||||
#### Implementing Audit Functionality
|
||||
|
||||
```tsx
|
||||
import type { UseBotInfoAuditorHook, BotInfoAuditFunc } from '@coze-studio/bot-audit-base';
|
||||
|
||||
// Example hook implementation
|
||||
const useBotAuditor: UseBotInfoAuditorHook = () => {
|
||||
const [pass, setPass] = useState(false);
|
||||
|
||||
const check: BotInfoAuditFunc = async (params) => {
|
||||
// Your audit logic here
|
||||
const result = await performAudit(params);
|
||||
setPass(result.success);
|
||||
return result;
|
||||
};
|
||||
|
||||
const reset = () => setPass(false);
|
||||
|
||||
return { check, pass, setPass, reset };
|
||||
};
|
||||
```
|
||||
|
||||
## API Reference
|
||||
|
||||
### Components
|
||||
|
||||
#### `AuditErrorMessage`
|
||||
|
||||
Displays standardized audit error messages with documentation links.
|
||||
|
||||
**Props:**
|
||||
- `link` (optional): Custom documentation link URL. Defaults to `/docs/guides/content_principles`
|
||||
|
||||
### Types
|
||||
|
||||
#### `UseBotInfoAuditorHook`
|
||||
|
||||
Hook interface for bot audit functionality.
|
||||
|
||||
**Returns:**
|
||||
- `check`: Function to perform audit checks
|
||||
- `pass`: Boolean indicating audit status
|
||||
- `setPass`: State setter for audit status
|
||||
- `reset`: Function to reset audit state
|
||||
|
||||
#### `BotInfoAuditFunc`
|
||||
|
||||
Function type for audit operations.
|
||||
|
||||
**Parameters:**
|
||||
- `params`: `BotAuditInfo` - Audit parameters
|
||||
**Returns:** `Promise<BotInfoAuditData>` - Audit result data
|
||||
|
||||
## Development
|
||||
|
||||
### Available Scripts
|
||||
|
||||
- `npm run dev` - Start Storybook development server
|
||||
- `npm run build` - Build the package
|
||||
- `npm run lint` - Run ESLint
|
||||
- `npm run test` - Run tests with Vitest
|
||||
|
||||
### Project Structure
|
||||
|
||||
```
|
||||
src/
|
||||
├── components/
|
||||
│ └── audit-error-message/ # AuditErrorMessage component
|
||||
├── interfaces/ # TypeScript type definitions
|
||||
└── index.ts # Main export file
|
||||
```
|
||||
|
||||
## Dependencies
|
||||
|
||||
This package depends on:
|
||||
- `@coze-arch/bot-api` - Bot API types and interfaces
|
||||
- `@coze-arch/i18n` - Internationalization utilities
|
||||
- `classnames` - CSS class utility
|
||||
|
||||
## License
|
||||
|
||||
Apache-2.0
|
||||
@@ -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: 'web',
|
||||
rules: {},
|
||||
});
|
||||
43
frontend/packages/agent-ide/bot-audit-base/package.json
Normal file
43
frontend/packages/agent-ide/bot-audit-base/package.json
Normal file
@@ -0,0 +1,43 @@
|
||||
{
|
||||
"name": "@coze-studio/bot-audit-base",
|
||||
"version": "0.0.1",
|
||||
"description": "audit base 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/i18n": "workspace:*",
|
||||
"classnames": "^2.3.2"
|
||||
},
|
||||
"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/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-plugin-svgr": "~3.3.0",
|
||||
"vitest": "~3.0.5"
|
||||
},
|
||||
"peerDependencies": {
|
||||
"react": ">=18.2.0",
|
||||
"react-dom": ">=18.2.0"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
.error-message {
|
||||
@apply text-left;
|
||||
|
||||
color: rgb(255, 68, 30);
|
||||
|
||||
.link {
|
||||
color: #4d53e8;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
/*
|
||||
* 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 React from 'react';
|
||||
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
|
||||
import styles from './index.module.less';
|
||||
|
||||
export function AuditErrorMessage({
|
||||
link = '/docs/guides/content_principles',
|
||||
}: {
|
||||
link?: string;
|
||||
}) {
|
||||
return (
|
||||
<div className={styles['error-message']}>
|
||||
{I18n.t('audit_unsuccess_general_type', {
|
||||
link: (
|
||||
<a
|
||||
rel="noreferrer noopener"
|
||||
href={link}
|
||||
target="_blank"
|
||||
className={styles.link}
|
||||
>
|
||||
{I18n.t('audit_unsuccess_general_type_url')}
|
||||
</a>
|
||||
),
|
||||
})}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
18
frontend/packages/agent-ide/bot-audit-base/src/index.ts
Normal file
18
frontend/packages/agent-ide/bot-audit-base/src/index.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
/*
|
||||
* 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 { AuditErrorMessage } from './components/audit-error-message';
|
||||
export { UseBotInfoAuditorHook, BotInfoAuditFunc } from './interfaces';
|
||||
@@ -0,0 +1,33 @@
|
||||
/*
|
||||
* 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 React from 'react';
|
||||
|
||||
import {
|
||||
type BotAuditInfo,
|
||||
type BotInfoAuditData,
|
||||
} from '@coze-arch/bot-api/playground_api';
|
||||
|
||||
export declare type UseBotInfoAuditorHook = () => {
|
||||
check: (params: BotAuditInfo) => Promise<BotInfoAuditData>;
|
||||
pass: boolean;
|
||||
setPass: React.Dispatch<React.SetStateAction<boolean>>;
|
||||
reset: () => void;
|
||||
};
|
||||
|
||||
export declare type BotInfoAuditFunc = (
|
||||
params: BotAuditInfo,
|
||||
) => Promise<BotInfoAuditData>;
|
||||
17
frontend/packages/agent-ide/bot-audit-base/src/typings.d.ts
vendored
Normal file
17
frontend/packages/agent-ide/bot-audit-base/src/typings.d.ts
vendored
Normal 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' />
|
||||
@@ -0,0 +1,37 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"outDir": "dist",
|
||||
"rootDir": "src",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"target": "ES2020",
|
||||
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../arch/bot-api/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-typings/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/i18n/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"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
frontend/packages/agent-ide/bot-audit-base/tsconfig.json
Normal file
15
frontend/packages/agent-ide/bot-audit-base/tsconfig.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"exclude": ["**/*"],
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "./tsconfig.misc.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"target": "ES2020"
|
||||
},
|
||||
"include": ["__tests__", "vitest.config.ts", "stories"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
22
frontend/packages/agent-ide/bot-audit-base/vitest.config.ts
Normal file
22
frontend/packages/agent-ide/bot-audit-base/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: 'web',
|
||||
});
|
||||
Reference in New Issue
Block a user