feat: manually mirror opencoze's code from bytedance
Change-Id: I09a73aadda978ad9511264a756b2ce51f5761adf
This commit is contained in:
@@ -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;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user