feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
31
frontend/packages/agent-ide/commons/.storybook/main.js
Normal file
31
frontend/packages/agent-ide/commons/.storybook/main.js
Normal file
@@ -0,0 +1,31 @@
|
||||
import { mergeConfig } from 'vite';
|
||||
import svgr from 'vite-plugin-svgr';
|
||||
|
||||
/** @type { import('@storybook/react-vite').StorybookConfig } */
|
||||
const config = {
|
||||
stories: ['../stories/**/*.mdx', '../stories/**/*.stories.tsx'],
|
||||
addons: [
|
||||
'@storybook/addon-links',
|
||||
'@storybook/addon-essentials',
|
||||
'@storybook/addon-onboarding',
|
||||
'@storybook/addon-interactions',
|
||||
],
|
||||
framework: {
|
||||
name: '@storybook/react-vite',
|
||||
options: {},
|
||||
},
|
||||
docs: {
|
||||
autodocs: 'tag',
|
||||
},
|
||||
viteFinal: config =>
|
||||
mergeConfig(config, {
|
||||
plugins: [
|
||||
svgr({
|
||||
svgrOptions: {
|
||||
native: false,
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
};
|
||||
export default config;
|
||||
14
frontend/packages/agent-ide/commons/.storybook/preview.js
Normal file
14
frontend/packages/agent-ide/commons/.storybook/preview.js
Normal file
@@ -0,0 +1,14 @@
|
||||
/** @type { import('@storybook/react').Preview } */
|
||||
const preview = {
|
||||
parameters: {
|
||||
actions: { argTypesRegex: "^on[A-Z].*" },
|
||||
controls: {
|
||||
matchers: {
|
||||
color: /(background|color)$/i,
|
||||
date: /Date$/i,
|
||||
},
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export default preview;
|
||||
5
frontend/packages/agent-ide/commons/.stylelintrc.js
Normal file
5
frontend/packages/agent-ide/commons/.stylelintrc.js
Normal file
@@ -0,0 +1,5 @@
|
||||
const { defineConfig } = require('@coze-arch/stylelint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
extends: [],
|
||||
});
|
||||
16
frontend/packages/agent-ide/commons/README.md
Normal file
16
frontend/packages/agent-ide/commons/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
# @coze-agent-ide/agent-ide-commons
|
||||
|
||||
> 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`
|
||||
12
frontend/packages/agent-ide/commons/config/rush-project.json
Normal file
12
frontend/packages/agent-ide/commons/config/rush-project.json
Normal file
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"operationSettings": [
|
||||
{
|
||||
"operationName": "test:cov",
|
||||
"outputFolderNames": ["coverage"]
|
||||
},
|
||||
{
|
||||
"operationName": "ts-check",
|
||||
"outputFolderNames": ["dist"]
|
||||
}
|
||||
]
|
||||
}
|
||||
7
frontend/packages/agent-ide/commons/eslint.config.js
Normal file
7
frontend/packages/agent-ide/commons/eslint.config.js
Normal file
@@ -0,0 +1,7 @@
|
||||
const { defineConfig } = require('@coze-arch/eslint-config');
|
||||
|
||||
module.exports = defineConfig({
|
||||
packageRoot: __dirname,
|
||||
preset: 'web',
|
||||
rules: {},
|
||||
});
|
||||
52
frontend/packages/agent-ide/commons/package.json
Normal file
52
frontend/packages/agent-ide/commons/package.json
Normal file
@@ -0,0 +1,52 @@
|
||||
{
|
||||
"name": "@coze-agent-ide/agent-ide-commons",
|
||||
"version": "0.0.1",
|
||||
"description": "agent ide utils, componets, constants...",
|
||||
"license": "Apache-2.0",
|
||||
"author": "gaoyuanhan.duty@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-semi": "workspace:*",
|
||||
"@coze-arch/bot-studio-store": "workspace:*",
|
||||
"@coze-arch/bot-tea": "workspace:*",
|
||||
"@coze-arch/coze-design": "0.0.6-alpha.346d77",
|
||||
"@coze-arch/i18n": "workspace:*",
|
||||
"@coze-studio/bot-detail-store": "workspace:*",
|
||||
"@coze-studio/user-store": "workspace:*",
|
||||
"@monaco-editor/react": "^4.5.2",
|
||||
"classnames": "^2.3.2",
|
||||
"dayjs": "^1.11.7",
|
||||
"react-router-dom": "^6.22.0"
|
||||
},
|
||||
"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,178 @@
|
||||
/* stylelint-disable */
|
||||
.multiline-text {
|
||||
word-break: break-word;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
.multiline-container {
|
||||
overflow: hidden;
|
||||
display: grid;
|
||||
grid-template-columns: 100px 36px 100px;
|
||||
flex: 1;
|
||||
}
|
||||
|
||||
.editor-container {
|
||||
overflow: hidden;
|
||||
|
||||
min-height: 400px;
|
||||
margin-top: 20px;
|
||||
|
||||
border: 1px solid var(--Stroke-COZ-stroke-primary, rgba(6, 7, 9, 10%));
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.editor-header{
|
||||
display: flex;
|
||||
width: 100%;
|
||||
border-bottom: 1px solid var(--Stroke-COZ-stroke-primary, rgba(6, 7, 9, 10%));
|
||||
}
|
||||
|
||||
.editor-title {
|
||||
overflow: hidden;
|
||||
flex: 1;
|
||||
|
||||
padding: 12px;
|
||||
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
color: var(--Fg-COZ-fg-primary, rgba(6, 7, 9, 80%));
|
||||
}
|
||||
|
||||
.editor-divider {
|
||||
width: 1px;
|
||||
height: 46px;
|
||||
color: var(--Stroke-COZ-stroke-primary, rgba(6, 7, 9, 10%));
|
||||
}
|
||||
|
||||
.editor {
|
||||
min-height: 400px;
|
||||
max-height: 600px;
|
||||
background-color: transparent;
|
||||
// pointer-events: none;
|
||||
:global {
|
||||
.monaco-editor-background {
|
||||
background-color: #f9f9f9 !important;
|
||||
}
|
||||
|
||||
.monaco-editor .vertical{
|
||||
box-shadow: 0 0 0 0 var(--guide-color) inset !important;
|
||||
}
|
||||
|
||||
.margin {
|
||||
background-color: #f9f9f9 !important;
|
||||
// border-right: 1px solid
|
||||
// var(--Stroke-COZ-stroke-primary, rgba(6, 7, 9, 0.1));
|
||||
}
|
||||
|
||||
.monaco-diff-editor.side-by-side .editor.modified{
|
||||
border-left: 1px solid var(--Stroke-COZ-stroke-primary, rgba(6, 7, 9, 10%));
|
||||
box-shadow: none !important;
|
||||
}
|
||||
|
||||
|
||||
.mtk1{
|
||||
color: var(--Fg-COZ-fg-dim, rgba(6, 7, 9, 60%));
|
||||
}
|
||||
|
||||
.margin-view-overlays .line-numbers {
|
||||
width: 24px !important;
|
||||
color: var(--Fg-COZ-fg-dim, rgba(6, 7, 9, 30%));
|
||||
}
|
||||
|
||||
.monaco-editor .diagonal-fill{
|
||||
background-image: linear-gradient(-45deg, rgba(34, 34, 34, 10%) 12.5%, #0000 12.5%, #0000 50%, rgba(34, 34, 34, 10%) 50%, rgba(34, 34, 34, 10%) 62.5%, #0000 62.5%, #0000 100%) !important;
|
||||
background-size: 8px 8px;
|
||||
}
|
||||
|
||||
.margin-view-overlays::after{
|
||||
pointer-events: none;
|
||||
content: ' ' !important;
|
||||
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 3px;
|
||||
bottom: 0;
|
||||
|
||||
width: 1px;
|
||||
|
||||
background: var(--Stroke-COZ-stroke-primary, rgba(6, 7, 9, 10%));
|
||||
}
|
||||
|
||||
.line-numbers.active-line-number {
|
||||
color: var(--Fg-COZ-fg-primary, rgba(6, 7, 9, 80%)) !important;
|
||||
}
|
||||
|
||||
.monaco-editor .delete-sign,.monaco-editor .insert-sign {
|
||||
left: 29px !important;
|
||||
font-size: 8px !important;
|
||||
font-weight: 900 !important;
|
||||
color: var(--Fg-COZ-fg-dim, rgba(6, 7, 9, 30%)) !important;
|
||||
}
|
||||
|
||||
.monaco-editor .view-overlays .current-line{
|
||||
border: 0 !important;
|
||||
}
|
||||
|
||||
.monaco-editor .wordHighlightText{
|
||||
|
||||
}
|
||||
|
||||
.monaco-scrollable-element>.scrollbar>.slider{
|
||||
width: 8px !important;
|
||||
background: var(--Fg-COZ-fg-dim, rgba(6, 7, 9, 30%));
|
||||
border-radius: 3px;
|
||||
}
|
||||
|
||||
.decorationsOverviewRuler{
|
||||
display: none !important;
|
||||
}
|
||||
|
||||
.modified {
|
||||
.slider{
|
||||
left: 6px !important;
|
||||
}
|
||||
|
||||
.presentation{
|
||||
right: -4px !important;
|
||||
width: 12px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.original {
|
||||
.slider{
|
||||
left: 6px !important;
|
||||
}
|
||||
|
||||
.presentation{
|
||||
left: 3px !important;
|
||||
width: 12px !important;
|
||||
}
|
||||
}
|
||||
|
||||
.gutter-insert{
|
||||
// background-color: #E7F0E5 !important;
|
||||
background-color: var(--vscode-diffEditor-insertedLineBackground, var(--vscode-diffEditor-insertedTextBackground)) !important;
|
||||
}
|
||||
|
||||
.gutter-delete{
|
||||
background-color: var(--vscode-diffEditor-removedLineBackground, var(--vscode-diffEditor-removedTextBackground)) !important;
|
||||
}
|
||||
// .line-insert{
|
||||
// background-color: #E7F0E5 !important;
|
||||
// }
|
||||
// .char-insert{
|
||||
// background: #C7DDC2 !important;
|
||||
// }
|
||||
// .line-delete{
|
||||
// background: #F6E4E5 !important;
|
||||
// }
|
||||
// .char-delete{
|
||||
// background: #F3CDD0 !important;
|
||||
// }
|
||||
|
||||
|
||||
// .decorationsOverviewRuler{
|
||||
// display: none !important;
|
||||
// }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
/*
|
||||
* 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 { useState } from 'react';
|
||||
|
||||
import { DiffEditor } from '@monaco-editor/react';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { Modal } from '@coze-arch/coze-design';
|
||||
import { Divider, Spin, Typography } from '@coze-arch/bot-semi';
|
||||
import {
|
||||
DiffStyle,
|
||||
type DiffDisplayNode,
|
||||
} from '@coze-arch/bot-api/dp_manage_api';
|
||||
|
||||
import { transTimestampText } from '../../utils';
|
||||
import { useSendDiffEvent } from '../../hooks/use-send-diff-event';
|
||||
|
||||
import styles from './index.module.less';
|
||||
|
||||
interface DiffNodeRenderProps {
|
||||
left: string;
|
||||
right: string;
|
||||
node?: DiffDisplayNode;
|
||||
type?: 'diff' | 'publish';
|
||||
}
|
||||
|
||||
/* eslint-disable-next-line @typescript-eslint/no-explicit-any */
|
||||
const safeJSONParse = (data: any) => {
|
||||
try {
|
||||
return JSON.parse(data);
|
||||
} catch (e) {
|
||||
return '';
|
||||
}
|
||||
};
|
||||
|
||||
export const DiffNodeRender: React.FC<DiffNodeRenderProps> = props => {
|
||||
const { left, right, node } = props;
|
||||
if (node?.diff_res?.diff_style === DiffStyle.TextDetail) {
|
||||
return <TextDiffView {...props} />;
|
||||
}
|
||||
const displayLeft = transTimestampText(left);
|
||||
const displayRight = transTimestampText(right);
|
||||
|
||||
const isMultiLine = displayLeft?.includes('template_NewLine');
|
||||
const dealLineBreak = (text: string) => (
|
||||
<Typography.Text
|
||||
className={styles['multiline-text']}
|
||||
type="secondary"
|
||||
size="small"
|
||||
>
|
||||
{text.replaceAll('template_NewLine', '\n')}
|
||||
</Typography.Text>
|
||||
);
|
||||
return isMultiLine ? (
|
||||
<Typography.Text
|
||||
className={styles['multiline-container']}
|
||||
type="secondary"
|
||||
size="small"
|
||||
>
|
||||
{dealLineBreak(displayLeft ?? '')}
|
||||
<Typography.Text className="mx-2" type="secondary" size="small">
|
||||
{'->'}
|
||||
</Typography.Text>
|
||||
{dealLineBreak(displayRight ?? '')}
|
||||
</Typography.Text>
|
||||
) : (
|
||||
<Typography.Text
|
||||
type="secondary"
|
||||
size="small"
|
||||
ellipsis={{
|
||||
showTooltip: {
|
||||
opts: {
|
||||
content: `${displayLeft} -> ${displayRight}`,
|
||||
style: { wordBreak: 'break-word' },
|
||||
},
|
||||
},
|
||||
}}
|
||||
>{`${displayLeft} -> ${displayRight}`}</Typography.Text>
|
||||
);
|
||||
};
|
||||
|
||||
export const TextDiffView: React.FC<DiffNodeRenderProps> = ({
|
||||
node,
|
||||
type = 'diff',
|
||||
}) => {
|
||||
const isDiffView = type === 'diff';
|
||||
const [visible, setVisible] = useState(false);
|
||||
const { sendViewDiffEvent } = useSendDiffEvent();
|
||||
const originText = safeJSONParse(
|
||||
safeJSONParse(node?.diff_res?.origin_left)?.OriginStr,
|
||||
);
|
||||
const modifyText = safeJSONParse(
|
||||
safeJSONParse(node?.diff_res?.origin_right)?.OriginStr,
|
||||
);
|
||||
return (
|
||||
<div>
|
||||
<Typography.Text
|
||||
link
|
||||
onClick={() => {
|
||||
setVisible(true);
|
||||
sendViewDiffEvent();
|
||||
}}
|
||||
className="text-xs"
|
||||
>
|
||||
{I18n.t('coze_bot_diff_btn_view_diff')}
|
||||
</Typography.Text>
|
||||
<Modal
|
||||
visible={visible}
|
||||
title={
|
||||
<div className="flex gap-1 items-center">
|
||||
{I18n.t('coze_bot_diff_diffdetail_pagetitle')}
|
||||
</div>
|
||||
}
|
||||
footer={null}
|
||||
width={1000}
|
||||
onCancel={() => {
|
||||
setVisible(false);
|
||||
}}
|
||||
>
|
||||
<div className={styles['editor-container']}>
|
||||
<div className={styles['editor-header']}>
|
||||
<div className={styles['editor-title']}>
|
||||
{I18n.t(
|
||||
isDiffView
|
||||
? 'coze_bot_diff_diffdetail_latestversion'
|
||||
: 'coze_bot_diff_diffdetail_onlineversion',
|
||||
)}
|
||||
</div>
|
||||
<Divider className={styles['editor-divider']} layout="vertical" />
|
||||
<div className={styles['editor-title']}>
|
||||
{I18n.t(
|
||||
isDiffView
|
||||
? 'coze_bot_diff_diffdetail_mydraft'
|
||||
: 'coze_bot_diff_diffdetail_tobereleasedversion',
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
<div className="h-[600px]">
|
||||
<DiffEditor
|
||||
theme="light"
|
||||
className={styles.editor}
|
||||
original={originText}
|
||||
modified={modifyText}
|
||||
language="text"
|
||||
options={{
|
||||
minimap: { enabled: false },
|
||||
wordWrap: 'on',
|
||||
diffWordWrap: 'on',
|
||||
lineNumbers: 'on',
|
||||
readOnly: true,
|
||||
scrollBeyondLastLine: false,
|
||||
renderOverviewRuler: false,
|
||||
// You can optionally disable the resizing
|
||||
enableSplitViewResizing: false,
|
||||
unicodeHighlight: { ambiguousCharacters: false },
|
||||
suggestLineHeight: 32,
|
||||
lineHeight: 20,
|
||||
fontSize: 12,
|
||||
}}
|
||||
loading={
|
||||
<div className="h-[100%] w-[100%] flex items-center justify-center">
|
||||
<Spin />
|
||||
</div>
|
||||
}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
</Modal>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
import classNames from 'classnames';
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import { Typography } from '@coze-arch/coze-design';
|
||||
|
||||
import {
|
||||
useTermServiceModal,
|
||||
type TermServiceInfo,
|
||||
} from './term-service-modal';
|
||||
|
||||
export const PublishTermService = ({
|
||||
termServiceData,
|
||||
scene = 'bot',
|
||||
className,
|
||||
}: {
|
||||
termServiceData: TermServiceInfo[];
|
||||
scene?: 'bot' | 'project';
|
||||
className?: string;
|
||||
}) => {
|
||||
const { node: termServiceModal, open: openTermServiceModal } =
|
||||
useTermServiceModal({
|
||||
dataSource: termServiceData,
|
||||
});
|
||||
|
||||
const BotScene = scene === 'bot';
|
||||
return (
|
||||
<>
|
||||
{termServiceModal}
|
||||
<Typography.Text
|
||||
className={classNames(
|
||||
'py-[12px] coz-fg-primary leading-[16px]',
|
||||
className,
|
||||
)}
|
||||
>
|
||||
{I18n.t(
|
||||
BotScene
|
||||
? 'bot_publish_select_desc_compliance_new'
|
||||
: 'project_publish_select_desc_compliance_new',
|
||||
{
|
||||
publish_terms_title: (
|
||||
<Typography.Text
|
||||
link
|
||||
onClick={openTermServiceModal}
|
||||
className="!coz-fg-hglt !font-normal"
|
||||
>
|
||||
{I18n.t('publish_terms_title')}
|
||||
</Typography.Text>
|
||||
),
|
||||
},
|
||||
)}
|
||||
</Typography.Text>
|
||||
</>
|
||||
);
|
||||
};
|
||||
@@ -0,0 +1,9 @@
|
||||
.list {
|
||||
@apply p-3 pr-0;
|
||||
|
||||
:global {
|
||||
.semi-list-item-body-header {
|
||||
@apply flex-1 w-0 overflow-hidden;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
/*
|
||||
* 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 { useState } from 'react';
|
||||
|
||||
import { I18n } from '@coze-arch/i18n';
|
||||
import {
|
||||
List,
|
||||
UIButton,
|
||||
UIModal,
|
||||
Image,
|
||||
Typography,
|
||||
Space,
|
||||
} from '@coze-arch/bot-semi';
|
||||
|
||||
import styles from './index.module.less';
|
||||
|
||||
interface TermServiceModalReturnType {
|
||||
node: JSX.Element;
|
||||
open: () => void;
|
||||
close: () => void;
|
||||
}
|
||||
|
||||
export interface TermServiceInfo {
|
||||
name: string;
|
||||
icon: string;
|
||||
privacy_policy?: string;
|
||||
user_agreement?: string;
|
||||
}
|
||||
|
||||
export const useTermServiceModal = ({
|
||||
dataSource,
|
||||
}: {
|
||||
dataSource: TermServiceInfo[];
|
||||
}): TermServiceModalReturnType => {
|
||||
const [visible, setVisible] = useState(false);
|
||||
const handleClose = () => {
|
||||
setVisible(false);
|
||||
};
|
||||
|
||||
const handleOpen = () => {
|
||||
setVisible(true);
|
||||
};
|
||||
|
||||
return {
|
||||
node: (
|
||||
<UIModal
|
||||
type="info"
|
||||
title={I18n.t('publish_terms_title')}
|
||||
visible={visible}
|
||||
centered
|
||||
footer={
|
||||
<UIButton onClick={handleClose} theme="solid">
|
||||
{I18n.t('got_it')}
|
||||
</UIButton>
|
||||
}
|
||||
onCancel={handleClose}
|
||||
>
|
||||
<List
|
||||
dataSource={dataSource}
|
||||
renderItem={item => (
|
||||
<List.Item
|
||||
className={styles.list}
|
||||
align="center"
|
||||
header={
|
||||
<div className="flex items-center w-full">
|
||||
<Image
|
||||
className={'border-1'}
|
||||
src={item.icon}
|
||||
width={24}
|
||||
height={24}
|
||||
preview={false}
|
||||
style={{ flexShrink: 0 }}
|
||||
></Image>
|
||||
<Typography.Text
|
||||
className="ml-2 font-semibold "
|
||||
style={{ minWidth: 90 }}
|
||||
ellipsis={{
|
||||
showTooltip: {
|
||||
opts: {
|
||||
content: item.name,
|
||||
},
|
||||
},
|
||||
}}
|
||||
>
|
||||
{item.name}
|
||||
</Typography.Text>
|
||||
</div>
|
||||
}
|
||||
main={
|
||||
<Space spacing={0} className="justify-end">
|
||||
{item.privacy_policy ? (
|
||||
<UIButton theme="borderless" className="!px-2">
|
||||
<Typography.Text
|
||||
link={{ href: item.privacy_policy, target: '_blank' }}
|
||||
>
|
||||
{I18n.t('about_privacy_policy')}
|
||||
</Typography.Text>
|
||||
</UIButton>
|
||||
) : null}
|
||||
{item.user_agreement ? (
|
||||
<UIButton theme="borderless" className="!px-2">
|
||||
<Typography.Text
|
||||
link={{ href: item.user_agreement, target: '_blank' }}
|
||||
>
|
||||
{I18n.t('terms_of_service')}
|
||||
</Typography.Text>
|
||||
</UIButton>
|
||||
) : null}
|
||||
</Space>
|
||||
}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</UIModal>
|
||||
),
|
||||
close: handleClose,
|
||||
open: handleOpen,
|
||||
};
|
||||
};
|
||||
21
frontend/packages/agent-ide/commons/src/constants/index.ts
Normal file
21
frontend/packages/agent-ide/commons/src/constants/index.ts
Normal 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.
|
||||
*/
|
||||
|
||||
// diff表格缩进的长度
|
||||
// diff表格子节点缩进的长度
|
||||
export const DIFF_TABLE_INDENT_LENGTH = 20;
|
||||
// diff表格缩进的基础长度
|
||||
export const DIFF_TABLE_INDENT_BASE = 8;
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
import { useParams } from 'react-router-dom';
|
||||
|
||||
import { EVENT_NAMES, sendTeaEvent } from '@coze-arch/bot-tea';
|
||||
export const useSendDiffEvent = () => {
|
||||
const params = useParams();
|
||||
const spaceId = params.space_id || '';
|
||||
const botId = params.bot_id || '';
|
||||
const sendViewDiffEvent = () => {
|
||||
sendTeaEvent(EVENT_NAMES.bot_diff_viewdetail, {
|
||||
workspace_id: spaceId,
|
||||
bot_id: botId,
|
||||
});
|
||||
};
|
||||
const sendManualMergeEvent = (isSubmit: boolean) => {
|
||||
sendTeaEvent(EVENT_NAMES.bot_merge_manual, {
|
||||
workspace_id: spaceId,
|
||||
bot_id: botId,
|
||||
submit_or_not: isSubmit,
|
||||
});
|
||||
};
|
||||
return {
|
||||
sendViewDiffEvent,
|
||||
sendManualMergeEvent,
|
||||
};
|
||||
};
|
||||
25
frontend/packages/agent-ide/commons/src/index.ts
Normal file
25
frontend/packages/agent-ide/commons/src/index.ts
Normal 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 { DiffNodeRender } from './components/diff-node-render';
|
||||
|
||||
export { PublishTermService } from './components/term-service';
|
||||
|
||||
export { useSendDiffEvent } from './hooks/use-send-diff-event';
|
||||
|
||||
export { sendTeaEventInBot, transTimestampText } from './utils';
|
||||
|
||||
export { DIFF_TABLE_INDENT_BASE, DIFF_TABLE_INDENT_LENGTH } from './constants';
|
||||
17
frontend/packages/agent-ide/commons/src/typings.d.ts
vendored
Normal file
17
frontend/packages/agent-ide/commons/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' />
|
||||
68
frontend/packages/agent-ide/commons/src/utils/index.ts
Normal file
68
frontend/packages/agent-ide/commons/src/utils/index.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* 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 dayjs from 'dayjs';
|
||||
import { userStoreService } from '@coze-studio/user-store';
|
||||
import { useBotInfoStore } from '@coze-studio/bot-detail-store/bot-info';
|
||||
import { sendTeaEvent, type EVENT_NAMES } from '@coze-arch/bot-tea';
|
||||
import { useSpaceStore } from '@coze-arch/bot-studio-store';
|
||||
import { SpaceType } from '@coze-arch/bot-api/developer_api';
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
export function sendTeaEventInBot(event: EVENT_NAMES, params?: any) {
|
||||
const { botId: botID } = useBotInfoStore.getState();
|
||||
const userInfo = userStoreService.getUserInfo();
|
||||
|
||||
const {
|
||||
space: { id: spaceId, space_type },
|
||||
} = useSpaceStore.getState();
|
||||
const isPersonal = space_type === SpaceType.Personal;
|
||||
const timestamp = Date.now();
|
||||
sendTeaEvent(event, {
|
||||
user_id: userInfo?.user_id_str,
|
||||
timestamp,
|
||||
bot_id: botID,
|
||||
workspace_id: spaceId,
|
||||
workspace_type: isPersonal ? 'personal_workspace' : 'team_workspace',
|
||||
...params,
|
||||
});
|
||||
}
|
||||
|
||||
const UNIX_LEN = 10;
|
||||
const UNIX_LEN2 = 13;
|
||||
|
||||
export const transTimestampText = (text: string | undefined) => {
|
||||
try {
|
||||
if (!text) {
|
||||
return text;
|
||||
}
|
||||
const regex = /timestamp:"(\d{10,13})"/;
|
||||
const match = text.match(regex);
|
||||
if (match) {
|
||||
const timestamp = match?.[1];
|
||||
const format = 'YYYY-MM-DD HH:mm:ss';
|
||||
const strLen = `${timestamp}`.length;
|
||||
if (strLen === UNIX_LEN) {
|
||||
return `"${dayjs.unix(Number(timestamp)).format(format)}"`;
|
||||
} else if (strLen === UNIX_LEN2) {
|
||||
return `"${dayjs(Number(timestamp)).format(format)}"`;
|
||||
}
|
||||
}
|
||||
return text;
|
||||
} catch (error) {
|
||||
return text;
|
||||
}
|
||||
};
|
||||
54
frontend/packages/agent-ide/commons/tsconfig.build.json
Normal file
54
frontend/packages/agent-ide/commons/tsconfig.build.json
Normal file
@@ -0,0 +1,54 @@
|
||||
{
|
||||
"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"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler",
|
||||
"tsBuildInfoFile": "dist/tsconfig.build.tsbuildinfo"
|
||||
},
|
||||
"include": ["src"],
|
||||
"exclude": ["node_modules", "dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "../../arch/bot-api/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-store/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-tea/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/bot-typings/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../arch/i18n/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../components/bot-semi/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"
|
||||
},
|
||||
{
|
||||
"path": "../../studio/stores/bot-detail/tsconfig.build.json"
|
||||
},
|
||||
{
|
||||
"path": "../../studio/user-store/tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
15
frontend/packages/agent-ide/commons/tsconfig.json
Normal file
15
frontend/packages/agent-ide/commons/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"
|
||||
}
|
||||
]
|
||||
}
|
||||
20
frontend/packages/agent-ide/commons/tsconfig.misc.json
Normal file
20
frontend/packages/agent-ide/commons/tsconfig.misc.json
Normal file
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"extends": "@coze-arch/ts-config/tsconfig.web.json",
|
||||
"$schema": "https://json.schemastore.org/tsconfig",
|
||||
"compilerOptions": {
|
||||
"rootDir": "./",
|
||||
"outDir": "./dist",
|
||||
"jsx": "react-jsx",
|
||||
"lib": ["DOM", "ESNext"],
|
||||
"module": "ESNext",
|
||||
"target": "ES2020",
|
||||
"moduleResolution": "bundler"
|
||||
},
|
||||
"include": ["__tests__", "vitest.config.ts", "stories"],
|
||||
"exclude": ["./dist"],
|
||||
"references": [
|
||||
{
|
||||
"path": "./tsconfig.build.json"
|
||||
}
|
||||
]
|
||||
}
|
||||
22
frontend/packages/agent-ide/commons/vitest.config.ts
Normal file
22
frontend/packages/agent-ide/commons/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