chore: replace all cn comments of fe to en version by volc api (#320)

This commit is contained in:
tecvan
2025-07-31 10:32:15 +08:00
committed by GitHub
parent 716ec0cba8
commit 71f6245a01
2960 changed files with 15545 additions and 15545 deletions

View File

@@ -61,17 +61,17 @@ export const AutoGenerateButton: React.FC<AutoGenerateButtonProps> = ({
onProgress(false);
}
};
// 如果没有 caption则不用confirm
// If there is no caption, do not confirm
if (!currentValue) {
await generateCaption();
return;
}
UIModal.warning({
// 必填参数,统一 confirm modal 的样式
// Required parameters to confirm modal style
className: styles['confirm-modal'],
closeIcon: <IconCloseKnowledge />,
// 自定义参数
// custom parameters
title: I18n.t('knowledge_photo_021'),
content: I18n.t('knowledge_photo_022'),
icon: <IconWarningSize24 />,

View File

@@ -94,14 +94,14 @@ export const HeaderTags = ({
</Tag>
)}
{/* 图片来源 */}
{/* Image source */}
{formatType === FormatType.Image && (
<Tag size="mini" color="primary">
{I18n.t('dataset_detail_source_local')}
</Tag>
)}
{/* 图片数量 */}
{/* number of pictures */}
{formatType === FormatType.Image && !!dataSetDetail?.doc_count && (
<Tag size="mini" color="primary">
{I18n.t('knowledge_photo_015', {
@@ -110,7 +110,7 @@ export const HeaderTags = ({
</Tag>
)}
{/* 未添加文档时不展示 */}
{/* Do not display when no document is added */}
{formatType !== FormatType.Image && !!dataSetDetail?.doc_count && (
<>
{/* slice count */}

View File

@@ -111,7 +111,7 @@ export const KnowledgeModalNavBar: React.FC<KnowledgeModalNavBarProps> = ({
<div className={styles.toolbar}>
<Space spacing={12}>
{isImageFormat ? <PhotoFilter /> : null}
{/* 导入按钮 */}
{/* import button */}
{canEdit ? importKnowledgeSourceButton : null}
{actionButtons}
</Space>

View File

@@ -124,7 +124,7 @@ export const KnowledgeIDENavBar = ({
].includes(unitType),
[unitType],
);
// link 或者 action 二选一存在时才展示
// Link or action will only be displayed when one exists
const showTableConfigButton =
(isShowLinkUrl || canEdit) && isTableFormat && documentList?.length;

View File

@@ -73,7 +73,7 @@ export const usePhotoDetailModal = (params: UsePhotoDetailModalParams) => {
const status = progressMap[document_id || '']?.status || originStatus;
// 处理中获处理失败的photo不允许更新 caption
// The photo that failed to be processed is not allowed to update the caption.
const disableUpdate =
status === DocumentStatus.Processing ||
status === DocumentStatus.Failed ||
@@ -86,7 +86,7 @@ export const usePhotoDetailModal = (params: UsePhotoDetailModalParams) => {
}
}, [
visible,
// 切换图片时需要更新初始状态
// The initial state needs to be updated when switching pictures.
document_id,
]);
@@ -136,12 +136,12 @@ export const usePhotoDetailModal = (params: UsePhotoDetailModalParams) => {
<div className={styles['modal-content']}>
<div className={styles['photo-large']}>
<Image
// 仅设置高度,宽度会按图片原比例自动缩放
// Only set the height, and the width will be automatically scaled according to the original scale of the picture.
height={300}
src={photo.url}
/>
{
// 未找到,或者为第一个,不展示 pre 按钮
// Not found, or for the first one, the pre button is not displayed
currentIndex < 1 ? null : (
<IconButton
icon={<Icon svg={<SvgArrowLeft />} />}
@@ -158,7 +158,7 @@ export const usePhotoDetailModal = (params: UsePhotoDetailModalParams) => {
)
}
{
// 未找到,或者为最后一个,不展示 pre 按钮
// Not found, or for the last one, the pre button is not displayed
currentIndex === -1 ||
currentIndex === photoList.length - 1 ? null : (
<IconButton

View File

@@ -20,7 +20,7 @@ import { IconUnitsTable, IconUnitsFile } from '@coze-arch/bot-icons';
import { IconWithSuffix } from './suffix';
// 获取 icon
// Get icon
export const RenderDocumentIcon = ({
formatType,
sourceType,

View File

@@ -121,7 +121,7 @@ export const ImageKnowledgeWorkspace: FC<
setCurrentPhotoId,
reload: reloadAsync,
onCancel: () => {
// 重置url参数
// Reset url parameters
resetUrlQueryParams();
},
onSubmit: () => {
@@ -129,12 +129,12 @@ export const ImageKnowledgeWorkspace: FC<
},
});
// 手动控制 data 加载时机
// Manually control data loading timing
useEffect(() => {
if (dataSetDetail?.dataset_id) {
reloadAsync();
// 重新加载时,回到最顶部
// When reloading, return to the top
ref.current?.scrollTo?.({
top: 0,
behavior: 'smooth',
@@ -142,7 +142,7 @@ export const ImageKnowledgeWorkspace: FC<
}
}, [searchValue, photoFilterValue, dataSetDetail?.dataset_id]);
// 自动打开编辑弹窗
// Automatically open the editing pop-up window
useEffect(() => {
if (shouldAutoOpenDetailModal) {
if (firstAutoOpenEditDocumentId) {
@@ -182,10 +182,10 @@ export const ImageKnowledgeWorkspace: FC<
caption: originCaption,
status: originStatus,
} = item;
// 此处使用 progressMap 可以保持不断刷新直至完成
// Use progressMap here to keep refreshing until completion
// @ts-expect-error -- linter-disable-autofix
const status = progressMap[document_id]?.status || originStatus;
// 使用 progressMap 获取最新的caption
// Use progressMap to get the latest caption
const caption =
// @ts-expect-error -- linter-disable-autofix
(progressMap[document_id] as ProgressItem & PhotoInfo)
@@ -202,11 +202,11 @@ export const ImageKnowledgeWorkspace: FC<
const handleDelete = () => {
UIModal.error({
// 必填参数,统一 confirm modal 的样式
// Required parameters to confirm modal style
className: styles['confirm-modal'],
closeIcon: <IconCloseKnowledge />,
// 自定义参数
// custom parameters
title: I18n.t('kl2_007'),
content: I18n.t(
'dataset_detail_table_deleteModel_description',
@@ -247,7 +247,7 @@ export const ImageKnowledgeWorkspace: FC<
const isAudiFailed =
originStatus === DocumentStatus.AuditFailed;
const getCaption = () => {
// 违规图片
// Illegal pictures
if (isAudiFailed) {
return (
<span>
@@ -256,7 +256,7 @@ export const ImageKnowledgeWorkspace: FC<
);
}
// 处理失败
// Processing failed
if (status === DocumentStatus.Failed) {
return (
<span className={styles['failed-tag']}>
@@ -265,7 +265,7 @@ export const ImageKnowledgeWorkspace: FC<
);
}
// 处理中
// Processing
if (status === DocumentStatus.Processing) {
return (
<span className={styles['processing-tag']}>
@@ -274,12 +274,12 @@ export const ImageKnowledgeWorkspace: FC<
);
}
// 已标注
// marked
if (hasCaption) {
return caption;
}
// 未标注
// unmarked
return I18n.t('knowledge_photo_016');
};
@@ -295,7 +295,7 @@ export const ImageKnowledgeWorkspace: FC<
) : (
<Image
src={url}
// 仅设置宽度,高度会按图片原比例自动缩放
// Only set the width, and the height will be automatically scaled according to the original scale of the picture.
width={222}
preview={false}
onClick={handleEdit}

View File

@@ -60,7 +60,7 @@ export const usePhotoList = (
? true
: filterPhotoType === FilterPhotoType.NoCaption
? false
: // undefined 代表返回全部
: // Pass undefined to return all
undefined,
},
});

View File

@@ -78,7 +78,7 @@ export const ImportKnowledgeSourceButton = ({
onSourceChange(unitType);
return;
}
/** 默认跳转到upload */
/** Default jump to upload */
const formatType = dataSetDetail?.format_type;
const docID = documentList?.[0]?.document_id;
const params: Record<string, string> = {

View File

@@ -23,7 +23,7 @@ import { type Dataset, type DocumentInfo } from '@coze-arch/bot-api/knowledge';
import { DocumentStatus, FormatType } from '@coze-arch/bot-api/knowledge';
/**
* 处理表格类型数据集的禁用提示
* Disable hints for working with table-type datasets
*/
export const getTableFormatTooltip = (documentList: DocumentInfo[]): string => {
const docInfo = documentList?.[0];
@@ -44,7 +44,7 @@ export const getTableFormatTooltip = (documentList: DocumentInfo[]): string => {
};
/**
* 处理默认类型数据集的禁用提示
* Disable hints for handling default type datasets
*/
export const getDefaultFormatTooltip = (dataSetDetail: Dataset): string => {
// @ts-expect-error -- linter-disable-autofix
@@ -60,10 +60,10 @@ export const getDefaultFormatTooltip = (dataSetDetail: Dataset): string => {
};
/**
* 创建按钮禁用时的提示文本
* @param dataSetDetail - 数据集详情
* @param documentList - 文档列表
* @returns 提示文本
* Create prompt text when button is disabled
* @param dataSetDetail - Dataset Details
* @param documentList - Document List
* @Returns prompt text
*/
export const createBtnDisableToolTip = (
dataSetDetail: Dataset,

View File

@@ -121,12 +121,12 @@ export const getUpdatedDataset = (
actionType: ActionType,
dataSetDetail: Dataset,
): KnowledgeInfo[] => {
// 更新后的bot知识库
// Updated bot knowledge base
let updatedDatasetList: KnowledgeInfo[] = [];
// 原本的bot知识库内容
// The original bot knowledge base content
let originDataset: KnowledgeInfo[] = [];
// 兼容json版本的datasetFG全量后删除
// Compatible with the json version of dataset, delete it after FG is full
if ('dataset' in dataset) {
originDataset = dataset?.dataset ?? [];
} else {
@@ -147,7 +147,7 @@ export const getUpdatedDataset = (
return updatedDatasetList;
};
// 更新bot知识库逻辑
// Update bot knowledge base logic
export const handleDatasetUpdate = async ({
botInfo,
botId,
@@ -181,7 +181,7 @@ export const handleDatasetUpdate = async ({
updateSuccess();
};
// 根据不同botInfo信息 获取不同的bot原有的dataset
// Get the original dataset of different bots according to different botInfo information
export const getDatasetInfo = (
botInfo: GetDraftBotInfoAgwData | undefined,
agentId: string,

View File

@@ -96,7 +96,7 @@ export const useBeforeKnowledgeIDEClose = ({
};
const handleBotIdeBack = () => {
// Bot IDE检查是否有绑定knowledge如果有绑定知识库正常关闭没有绑定确认提示处理
// Bot IDE checks whether there is binding knowledge. If there is binding knowledge base, it will be closed normally, and there is no binding confirmation prompt.
if (hasAddDataset) {
Modal.confirm({
title: I18n.t('bot_ide_knowledge_confirm_title'),
@@ -124,17 +124,17 @@ export const useBeforeKnowledgeIDEClose = ({
console.error(error);
} finally {
setLoading(false);
// 无论成功无论都跳转一次
// Jump once regardless of success
handleFullModalBack();
}
},
onCancel: () => {
// 取消,正常跳转
// Cancel, jump normally
handleFullModalBack();
},
});
} else {
// 正常绑定不做弹窗拦截
// Normal binding does not do pop-up interception
handleFullModalBack();
}
};

View File

@@ -92,7 +92,7 @@ export const TableKnowledgeWorkspace = ({
slices,
]);
// 创建 UI Context
// Creating UI Context Values
const uiContextValue = {
tableViewRef,
isLoadingMoreSliceList,
@@ -100,7 +100,7 @@ export const TableKnowledgeWorkspace = ({
isShowAddBtn,
};
// 创建数据 Context
// Creating Data Context Values
const dataContextValue = {
sliceListData: sliceListData || { list: [], total: 0 },
curIndex,
@@ -108,7 +108,7 @@ export const TableKnowledgeWorkspace = ({
delSliceIds,
};
// 创建操作 Context
// Create Action Context Value
const actionsContextValue = {
setCurIndex,
setCurSliceId,

View File

@@ -38,7 +38,7 @@ import { useTableUI } from '../context/table-ui-context';
import { useTableData } from '../context/table-data-context';
import { useTableActions } from '../context/table-actions-context';
// 表格内容组件
// Table Content Component
const TableContent = () => {
const knowledgeIDEBiz = useKnowledgeParamsStore(state => state.params.biz);
const documentList = useKnowledgeStore(state => state.documentList);
@@ -55,14 +55,14 @@ const TableContent = () => {
const canEdit = Boolean(useKnowledgeStore(state => state.canEdit));
// 删除切片弹窗
// Delete slice pop-up
const { deleteSliceModalNode, openDeleteSliceModal } = useDeleteSliceModal();
// 编辑slice弹窗
// Edit slice pop-up
const { tableSegmentModalNode, openTableSegmentModal } =
useTableSegmentModal();
// 获取表格操作方法
// Get table manipulation method
const { deleteSlice, rowUpdateSliceData, modalEditSlice } =
useTableSliceOperations({
openDeleteSliceModal,
@@ -71,7 +71,7 @@ const TableContent = () => {
const { tableH } = useTableHeight();
// 如果没有数据,直接返回空
// If there is no data, return to empty directly
if (!slices?.length) {
return null;
}
@@ -132,7 +132,7 @@ const TableContent = () => {
);
};
// 添加行按钮组件
// Add line button component
const AddRowButton = () => {
const { isShowAddBtn } = useTableUI();
const documentList = useKnowledgeStore(state => state.documentList);
@@ -164,12 +164,12 @@ const AddRowButton = () => {
);
};
// 主组件
// main component
export const TableDataView = () => {
const { sliceListData } = useTableData();
const slices = sliceListData?.list;
// 如果没有数据,只显示添加按钮
// If there is no data, only the add button is displayed.
if (!slices?.length) {
return <AddRowButton />;
}

View File

@@ -18,7 +18,7 @@ import { createContext, useContext } from 'react';
import { type DatasetDataScrollList } from '@/service';
// 表格操作相关的 Context
// Context related to table manipulation
interface TableActionsContextType {
setCurIndex: (index: number | ((prev: number) => number)) => void;
setCurSliceId: (id: string | ((prev: string) => string)) => void;

View File

@@ -18,7 +18,7 @@ import { createContext, useContext } from 'react';
import { type DatasetDataScrollList } from '@/service';
// 表格数据相关的 Context
// Context related to tabular data
interface TableDataContextType {
sliceListData: DatasetDataScrollList;
curIndex: number;

View File

@@ -19,7 +19,7 @@ import { type MutableRefObject } from 'react';
import { type TableViewMethods } from '@coze-common/table-view';
// 表格 UI 相关的 Context
// Context related to table UI
interface TableUIContextType {
tableViewRef: MutableRefObject<TableViewMethods | null>;
isLoadingMoreSliceList: boolean;

View File

@@ -30,7 +30,7 @@ export const useCreateSlice = () => {
const documentList = useKnowledgeStore(state => state.documentList);
const curDoc = documentList?.[0];
// 创建切片
// Create slice
const { createSlice } = useCreateSliceService({
onReload: (createItem: ISliceInfo) => {
const list =

View File

@@ -25,7 +25,7 @@ import { useScrollListSliceReq } from '@/service';
export const useGetSliceListData = () => {
const documentList = useKnowledgeStore(state => state.documentList);
const curDocId = documentList?.[0]?.document_id;
// 加载数据
// load data
const {
data: sliceListData,
mutate: mutateSliceListData,

View File

@@ -20,7 +20,7 @@ const ADD_BTN_HEIGHT = 56;
export const useScroll = () => {
const { sliceListData } = useTableData();
// 滚动表格到底部
// Scroll table to the bottom
const scrollTableBodyToBottom = () => {
const bodyDom = document.querySelector(
'.table-view-box .semi-table-container>.semi-table-body',

View File

@@ -24,7 +24,7 @@ export const useTableHeight = () => {
const { sliceListData } = useTableData();
const [tableH, setTableHeight] = useState<number | string>(0);
// 更新表格高度
// Update table height
useEffect(() => {
const h = tableViewRef?.current?.getTableHeight();
if (h) {

View File

@@ -35,7 +35,7 @@ export const useAddRow = ({
const { sliceListData } = useTableData();
const { mutateSliceListData } = useTableActions();
const handleAddRow = () => {
/** 先增加容器的高度 */
/** Increase the height of the container first */
increaseTableHeight(ADD_BTN_HEIGHT);
const items = JSON.parse(sliceListData?.list[0]?.content ?? '[]');

View File

@@ -28,12 +28,12 @@ import { useTableData } from '../../context/table-data-context';
import { useTableActions } from '../../context/table-actions-context';
export const useDeleteSliceModal = () => {
// 外部数据
// external data
const dataSetDetail = useKnowledgeStore(state => state.dataSetDetail);
const setDataSetDetail = useKnowledgeStore(state => state.setDataSetDetail);
const documentList = useKnowledgeStore(state => state.documentList);
// 内部数据
// internal data
const { sliceListData, delSliceIds } = useTableData();
const { tableViewRef } = useTableUI();
const { mutateSliceListData } = useTableActions();
@@ -41,7 +41,7 @@ export const useDeleteSliceModal = () => {
const curDoc = documentList?.[0];
const slices = sliceListData?.list;
// 删除切片弹窗
// Delete slice pop-up
const { node: deleteSliceModalNode, delete: openDeleteSliceModal } =
useSliceDeleteModal({
onDel: async () => {

View File

@@ -33,7 +33,7 @@ export const useTableSegmentModal = () => {
const { mutateSliceListData } = useTableActions();
const curDoc = documentList?.[0];
// 表格分段弹窗
// table segmentation pop-up
const {
node: tableSegmentModalNode,
edit: openTableSegmentModal,

View File

@@ -48,11 +48,11 @@ export const useTableSliceOperations = ({
return;
}
/** 新增的行 */
/** new row */
const addIndex = indexs.filter(i => !slices[i].slice_id);
const addIds = addIndex.map(i => slices[i]?.addId);
const oldIndex = indexs.filter(v => !addIndex.includes(v));
// 确保过滤掉undefined
// Make sure to filter out undefined values
const sliceIds = oldIndex
.map(i => slices[i].slice_id)
.filter(Boolean) as string[];
@@ -129,12 +129,12 @@ export const useTableSliceOperations = ({
if (sliceId) {
await updateSlice(sliceId as string, updateContent, updateValue);
} else {
/** 新增分片 */
/** Add sharding */
const createParams = await handleCreateSlice(updateContent);
if (createParams && createSlice && curDoc?.document_id) {
// 调用传入的createSlice方法创建新的分片
// Call the createSlice method passed in to create a new sharding.
try {
// 这里需要使用props中传入的createSlice方法来调用API
// Here you need to use the createSlice method passed in the props to call the API.
await createSlice({
document_id: curDoc.document_id,
raw_text: updateContent,
@@ -145,7 +145,7 @@ export const useTableSliceOperations = ({
}
}
// 改为接口请求成功后才更新
// Change to update after the interface request is successful
if (slices) {
return true;
}
@@ -156,7 +156,7 @@ export const useTableSliceOperations = ({
}
};
/** 弹窗编辑切片 */
/** Pop-up editing slice */
const handleModalEditSlice = (_record: TableViewRecord, index: number) => {
if (!slices || index < 0 || index >= slices.length) {
return;

View File

@@ -16,6 +16,6 @@
import { TableKnowledgeWorkspace } from './components/main';
// 导出组件
// export component
export { TableKnowledgeWorkspace };
export type { TableKnowledgeWorkspaceProps } from './components/main';

View File

@@ -66,7 +66,7 @@ const getTableCacheWidthMap = (tableKey: string) => {
};
/**
* slice 数据转换为 TableView 组件接收的数据类型
* Slice data to the data type received by the TableView component
*/
export const getTableRenderColumnsData = ({
@@ -158,7 +158,7 @@ export const getTableRenderColumnsData = ({
/>
);
}
// 针对违规内容高亮处理
// Highlighting violations
const isAudiFailed = record?.status === SliceStatus.AuditFailed;
const textRender = () => (
<div className={`w-full ${isAudiFailed ? 'text-red-500' : ''}`}>

View File

@@ -75,7 +75,7 @@ export const DocSelector = ({
}
try {
const regx = new RegExp(searchValue);
// 搜索结果不展示「全部内容」选项
// Search results do not show the "All Content" option
return (
(op.value !== 'all' && op.value === value) ||
(op?.text as string)?.match(regx)

View File

@@ -48,7 +48,7 @@ export const LevelContent: React.FC<LevelContentProps> = ({
const canEdit = useKnowledgeStore(state => state.canEdit);
const searchValue = useKnowledgeStore(state => state.searchValue);
// 转换层级分段数据为编辑器可用格式
// Convert hierarchical segmented data into an editor-usable format
const renderLevelSegmentsData = levelSegments.map(item =>
createLevelDocumentChunkByLevelSegment(item),
);

View File

@@ -76,10 +76,10 @@ export const TextKnowledgeWorkspace = ({
const documentList = useKnowledgeStore(state => state.documentList);
const resourceNavigate = useDataNavigate();
// 初始化选择第一个文档
// Initialize to select the first document
useInitSelectFirstDoc();
// 文档管理
// Document Management
const {
handleSelectDocument,
handleRenameDocument,
@@ -89,15 +89,15 @@ export const TextKnowledgeWorkspace = ({
reloadDataset,
});
// 文档基本信息
// Documentation basic information
const { curDoc, curDocId, isProcessing, processFinished, datasetId } =
useDocumentInfo(progressMap);
// 文件预览
// file preview
const { showOriginalFile, handleToggleOriginalFile } =
useFilePreview(curDocId);
// 文档片段数据
// document fragment data
const { loading, renderData, handleContentChange, reload } = useSliceData({
curDocId,
datasetId,
@@ -107,7 +107,7 @@ export const TextKnowledgeWorkspace = ({
rollbackDocumentSelection,
});
// 层级分段数据
// hierarchical segmented data
const {
levelSegments,
selectionIDs,
@@ -119,11 +119,11 @@ export const TextKnowledgeWorkspace = ({
curDoc,
});
// 片段计数器
// fragment counter
const { handleIncreaseSliceCount, handleDecreaseSliceCount } =
useSliceCounter();
// 模态框
// modal box
const {
deleteModalNode,
showDeleteModal,
@@ -153,10 +153,10 @@ export const TextKnowledgeWorkspace = ({
},
});
// 文档选项
// Document Options
const docOptions = getDocumentOptions(documentList, progressMap);
// 处理重新分段
// Handle re-segmentation
const handleResegment = () => {
const isLocalText = Boolean(
curDoc?.source_type === DocumentSource.Document,

View File

@@ -39,7 +39,7 @@ import {
import { DocTag } from './doc-tag';
import { DocSelector } from './doc-selector';
// 文档基本信息
// Documentation basic information
export interface DocumentData {
curDoc?: DocumentInfo;
curDocId: string;
@@ -47,13 +47,13 @@ export interface DocumentData {
docOptions: OptionProps[];
}
// 文件预览相关
// File preview related
export interface FilePreviewData {
showOriginalFile: boolean;
fileUrl?: string;
}
// 文档操作回调
// document action callback
export interface DocumentActions {
onChangeDoc: (docId: string) => void;
onRenameDoc: (docId: string, newName: string) => void;
@@ -64,7 +64,7 @@ export interface DocumentActions {
reloadDataset?: () => void;
}
// 自定义UI元素
// Custom UI elements
export interface CustomUIElements {
linkOriginUrlButton?: ReactNode;
fetchSliceButton?: ReactNode;
@@ -92,7 +92,7 @@ export const TextToolbar: React.FC<TextToolbarProps> = ({
}) => {
const canEdit = useKnowledgeStore(state => state.canEdit);
// 控制按钮显示逻辑
// Control button display logic
const showUpdateFreBtn =
canEdit &&
curDoc &&

View File

@@ -80,7 +80,7 @@ export const DocSelector = ({
const regx = new RegExp(searchValue);
const newOptions = options.filter(
op =>
// 搜索结果不展示「全部内容」选项
// Search results do not show the "All Content" option
(op.value !== 'all' && op.value === value) ||
(op?.text as string)?.match(regx),
);
@@ -107,7 +107,7 @@ export const DocSelector = ({
const handleEditDocName = e => {
e.stopPropagation();
setVisible(true);
// TODO 打开弹框
// TODO opens the box
};
const triggerRender = ({ value: values }) => (
<Popover
@@ -200,7 +200,7 @@ export const DocSelector = ({
</Popover>
);
// TODO: 交互改版,这里做了个假的
// TODO: Interactive revision, made a fake here
return (
<Select
clickToHide={true}

View File

@@ -15,26 +15,26 @@
*/
/**
* 按照功能导出所有 hooks
* Export all hooks by function
*/
// 文档管理
// Document Management
export { useDocumentManagement } from './use-case/use-document-management';
// 文档信息
// Document information
export { useDocumentInfo } from './life-cycle/use-document-info';
// 文档片段数据
// document fragment data
export { useSliceData } from './life-cycle/use-slice-data';
// 层级分段数据
// hierarchical segmented data
export { useLevelSegments } from './use-case/use-level-segments';
// 文档片段计数
// Document fragment count
export { useSliceCounter } from './use-case/use-slice-counter';
// 文件预览
// file preview
export { useFilePreview } from './use-case/use-file-preview';
// 模态框
// modal box
export { useModals } from './use-case/use-modals';

View File

@@ -21,7 +21,7 @@ import { DocumentStatus } from '@coze-arch/bot-api/knowledge';
import { type ProgressMap } from '@/types';
/**
* 处理文档基本信息的 hook
* Hooks that handle basic information about documents
*/
export const useDocumentInfo = (progressMap: ProgressMap) => {
const { documentList, dataSetDetail, curDocId } = useKnowledgeStore(
@@ -32,16 +32,16 @@ export const useDocumentInfo = (progressMap: ProgressMap) => {
})),
);
// 当前文档
// current document
const curDoc = documentList?.find(i => i.document_id === curDocId);
// 处理状态
// processing state
const isProcessing = curDoc?.status === DocumentStatus.Processing;
const processFinished = curDocId
? progressMap[curDocId]?.status === DocumentStatus.Enable
: false;
// 数据集ID
// Dataset ID
const datasetId = dataSetDetail?.dataset_id ?? '';
return {

View File

@@ -40,7 +40,7 @@ interface UseSliceDataParams {
}
/**
* 处理文档片段数据获取的 hook
* Hooks for processing document fragment data acquisition
*/
export const useSliceData = ({
curDocId,
@@ -56,7 +56,7 @@ export const useSliceData = ({
})),
);
// 获取文档内容
// Get document content
const {
loading,
data: sliceData,
@@ -67,12 +67,12 @@ export const useSliceData = ({
params: {
keyword: searchValue,
document_id:
// 如果是层级分段则不请求
// If it is a hierarchical segmentation, it is not requested.
curChunkType !== ChunkType.LevelChunk ? curDocId : '',
},
reloadDeps: [searchValue, curDocId, datasetId, processFinished],
onError: error => {
/** 拉取 slice 失败时,回退 curDocId避免文档标题和内容不一致用户迷惑 */
/** When pulling a slice fails, roll back curDocId to avoid inconsistencies between the document title and content, and user confusion */
dataReporter.errorEvent(DataNamespace.KNOWLEDGE, {
eventName: ReportEventNames.KnowledgeGetSliceList,
error,
@@ -83,7 +83,7 @@ export const useSliceData = ({
},
});
// 使用 useMemo 缓存 chunks 数组,避免因 progressMap 更新导致不必要的重新创建
// Use useMemo to cache the chunks array to avoid unnecessary recreations due to progressMap updates
const renderData = useMemo(
() =>
sliceData?.list.map(item => createBaseDocumentChunkBySliceInfo(item)) ??
@@ -91,7 +91,7 @@ export const useSliceData = ({
[sliceData?.list],
);
// 处理内容变化
// Handling content changes
const handleContentChange = (chunks: DocumentChunk[]) => {
mutate({
...sliceData,

View File

@@ -35,10 +35,10 @@ export const useDocumentManagement = (props?: {
})),
);
// 缓存上一个文档ID用于加载失败后回滚
// Cache the previous document ID for rollback after load failure
const prevDocIdRef = useRef<string | null>(null);
// 更新文档名称
// Update document name
const { run: updateDocument } = useUpdateDocument({
onSuccess: () => {
Toast.success(I18n.t('Update_success'));
@@ -46,13 +46,13 @@ export const useDocumentManagement = (props?: {
},
});
// 选择文档
// Select document
const handleSelectDocument = (docId: string) => {
prevDocIdRef.current = curDocId || null;
setCurDocId(docId);
};
// 重命名文档
// rename document
const handleRenameDocument = (docId: string, newName: string) => {
updateDocument({
document_id: docId,
@@ -60,7 +60,7 @@ export const useDocumentManagement = (props?: {
});
};
// 更新文档频率
// Update document frequency
const handleUpdateDocumentFrequency = (
docId: string,
formData: { updateInterval?: number; updateType?: UpdateType },
@@ -85,7 +85,7 @@ export const useDocumentManagement = (props?: {
return updatedDocList;
};
// 回滚文档选择
// Rollback document selection
const rollbackDocumentSelection = () => {
if (prevDocIdRef.current) {
setCurDocId(prevDocIdRef.current);

View File

@@ -19,7 +19,7 @@ import { useState, useEffect } from 'react';
export const useFilePreview = (curDocId: string) => {
const [showOriginalFile, setShowOriginalFile] = useState(false);
// 切换文档时,重置预览状态
// Reset the preview state when switching documents
useEffect(() => {
if (showOriginalFile) {
setShowOriginalFile(false);

View File

@@ -30,10 +30,10 @@ interface UseLevelSegmentsParams {
}
/**
* 处理层级分段数据的 hook
* Hooks for processing hierarchical segmented data
*/
export const useLevelSegments = ({ curDoc }: UseLevelSegmentsParams) => {
// 用于层级分段选中滚动
// Scroll selected for hierarchical segmentation
const [selectionIDs, setSelectionIDs] = useState<string[]>([]);
const { levelSegments, setLevelSegments } = useKnowledgeStore(
@@ -43,33 +43,33 @@ export const useLevelSegments = ({ curDoc }: UseLevelSegmentsParams) => {
})),
);
// 获取层级分段 slice 列表
// Get a list of hierarchical segments and slices
const { content: treeContent, loading: tosLoading } = useTosContent(
curDoc?.chunk_strategy?.chunk_type === ChunkType.LevelChunk
? curDoc?.doc_tree_tos_url
: undefined,
);
// 使用 useMemo 缓存转换后的层级分段数据
// Use useMemo to cache hierarchical segmented data after conversion
const renderLevelSegmentsData = useMemo(
() =>
levelSegments.map(item => createLevelDocumentChunkByLevelSegment(item)),
[levelSegments],
);
// 处理层级分段变更
// Handling hierarchy segmentation changes
const handleLevelSegmentsChange = (chunks: ILevelSegment[]) => {
setLevelSegments(chunks);
};
// 处理删除层级分段
// Handling deletion of hierarchical segmentation
const handleLevelSegmentDelete = (chunk: ILevelSegment) => {
setLevelSegments(
levelSegments.filter(item => item.slice_id !== chunk.slice_id),
);
};
// 初始化时加载层级分段
// Load hierarchical segmentation during initialization
useEffect(() => {
setLevelSegments(withTitle(treeContent?.chunks ?? [], curDoc?.name ?? ''));
}, [treeContent]);

View File

@@ -51,7 +51,7 @@ export const useModals = (props: UseModalsProps): UseModalsReturn => {
const { docId, documentType, documentSource, onDelete, onUpdateFrequency } =
props;
// 删除模态框
// Delete modal box
const { node: deleteModalNode, delete: showDeleteModal } = useDeleteUnitModal(
{
docId,
@@ -61,7 +61,7 @@ export const useModals = (props: UseModalsProps): UseModalsReturn => {
},
);
// 更新频率模态框
// Update frequency mode box
const { node: updateFrequencyModalNode, edit: showUpdateFrequencyModal } =
useUpdateFrequencyModal({
docId,

View File

@@ -18,7 +18,7 @@ import { useShallow } from 'zustand/react/shallow';
import { useKnowledgeStore } from '@coze-data/knowledge-stores';
/**
* 处理文档片段计数的 hook
* Hooks that handle document fragment counting
*/
export const useSliceCounter = () => {
const { dataSetDetail, setDataSetDetail } = useKnowledgeStore(
@@ -28,7 +28,7 @@ export const useSliceCounter = () => {
})),
);
// 处理添加块时更新计数
// Update count when processing added blocks
const handleIncreaseSliceCount = () => {
if (!dataSetDetail) {
return;
@@ -45,7 +45,7 @@ export const useSliceCounter = () => {
});
};
// 处理删除块时更新计数
// Update count when processing deleted blocks
const handleDecreaseSliceCount = () => {
if (!dataSetDetail) {
return;

View File

@@ -35,7 +35,7 @@ import { type ProgressMap } from '@/types';
const FINISH_PROGRESS = 100;
/**
* 创建基础文档块
* Create base document block
*/
export const createBaseDocumentChunkBySliceInfo = (
props: SliceInfo,
@@ -45,7 +45,7 @@ export const createBaseDocumentChunkBySliceInfo = (
});
/**
* 创建层级文档块
* Create hierarchical document blocks
*/
export const createLevelDocumentChunkByLevelSegment = (
props: ILevelSegment,
@@ -57,7 +57,7 @@ export const createLevelDocumentChunkByLevelSegment = (
});
/**
* 获取文档选项
* Get document options
*/
export const getDocumentOptions = (
documentList: DocumentInfo[],

View File

@@ -22,7 +22,7 @@ import { useKnowledgeParams, useKnowledgeStore } from '@coze-data/knowledge-stor
import { useDataSetDetailReq } from '@/service/dataset';
export const useGetKnowledgeType = () => {
const { datasetID = '' } = useKnowledgeParams();
// 知识库详情
// Knowledge Base Details
const { data: dataSetDetail, run: fetchDataSetDetail } =
useDataSetDetailReq();
const { setDataSetDetail, dataSetDetail: storeDataSetDetail } =

View File

@@ -45,7 +45,7 @@ export const useReloadKnowledgeIDE = () => {
})),
);
// 监听数据变化并更新 store
// Monitor data changes and update store
useEffect(() => {
if (!isDataSetLoading && dataSetDetail) {
setDataSetDetail(dataSetDetail);

View File

@@ -59,14 +59,14 @@ export const KnowledgeIDEBaseLayout = ({
const pollingTaskProgressInternal = usePollingTaskProgress();
const { reload, loading: isReloading, reset } = useReloadKnowledgeIDE();
// 初始化
// initialization
useEffect(() => {
reload();
return () => {
reset();
};
}, []);
// 回调 project IDE tab
// Callback to project IDE tab
useEffect(() => {
if (dataSetDetail?.name) {
onUpdateDisplayName?.(dataSetDetail.name);
@@ -92,7 +92,7 @@ export const KnowledgeIDEBaseLayout = ({
}
}, [dataSetDetail]);
// 构建渲染上下文
// Build the rendering context
const renderContext: KnowledgeRenderContext = {
layoutProps: {
keepDocTitle,
@@ -114,7 +114,7 @@ export const KnowledgeIDEBaseLayout = ({
},
};
// 编辑简介
// Editor Profile
return (
<DataErrorBoundary namespace={DataNamespace.KNOWLEDGE}>
<Layout
@@ -127,9 +127,9 @@ export const KnowledgeIDEBaseLayout = ({
)}
keepDocTitle={keepDocTitle}
>
{/* 导航栏 */}
{/* navigation bar */}
{renderNavBar?.(renderContext)}
{/* 内容区 */}
{/* content area */}
{renderContent?.(renderContext)}
</Layout>
</DataErrorBoundary>

View File

@@ -28,47 +28,47 @@ export interface KnowledgeIDEBaseLayoutProps {
}
/**
* 知识库查询相关操作
* Knowledge base query related operations
*/
export interface KnowledgeDataActions {
/** 重新加载知识库数据与文档列表 */
/** Reload the knowledge base data and document list */
refreshData: () => void;
/** 更新知识库数据集详情 */
/** Update Knowledge Base Dataset Details */
updateDataSetDetail: (data: Dataset) => void;
/** 更新文档列表数据 */
/** Update document list data */
updateDocumentList: (data: DocumentInfo[]) => void;
}
/**
* 知识库状态信息
* Knowledge Base Status Information
*/
export interface KnowledgeStatusInfo {
/** 知识库是否正在加载 */
/** Is the knowledge base loading? */
isReloading: boolean;
/** 文件处理进度信息 */
/** File processing progress information */
progressMap: ProgressMap;
}
/**
* 知识库数据信息
* Knowledge base data information
*/
export interface KnowledgeDataInfo {
/** 知识库数据集详情 */
/** Knowledge Base Dataset Details */
dataSetDetail: Dataset;
/** 文档列表 */
/** document list */
documentList: DocumentInfo[];
}
/**
* 知识库渲染上下文
* knowledge base rendering context
*/
export interface KnowledgeRenderContext {
/** 组件属性配置 */
/** Component property configuration */
layoutProps: KnowledgeIDEBaseLayoutProps;
/** 知识库数据信息 */
/** Knowledge base data information */
dataInfo: KnowledgeDataInfo;
/** 知识库状态信息 */
/** Knowledge Base Status Information */
statusInfo: KnowledgeStatusInfo;
/** 知识库数据操作 */
/** Knowledge base data manipulation */
dataActions: KnowledgeDataActions;
}

View File

@@ -100,7 +100,7 @@ export const useDataSetDetailReq = (
}
},
{
// 不自动请求
// No automatic request
manual: true,
onError: error => {
Toast.error({
@@ -156,7 +156,7 @@ export const usePollingDatasetProcess = () => {
}
},
{
// 不自动请求
// No automatic request
manual: true,
pollingInterval: POLLING_TIME,
onError: error => {

View File

@@ -82,7 +82,7 @@ export const useListDocumentReq = (
}
},
{
// 不自动请求
// No automatic request
manual: true,
onError: error => {
Toast.error({
@@ -113,7 +113,7 @@ export const usePollingTaskProgress = () => {
dataSetId?: string;
},
) => {
// 开启新的轮询前需要中止进行中的轮询
// An ongoing poll needs to be aborted before starting a new poll
if (pollingId.current) {
clearPolling(pollingId);
}
@@ -125,7 +125,7 @@ export const usePollingTaskProgress = () => {
let photoInfos: PhotoDetailResponse['photo_infos'];
// 单独查询 photo detail
// Check photo details separately
if (options.isImage) {
photoInfos = (
await KnowledgeApi.PhotoDetail({
@@ -136,7 +136,7 @@ export const usePollingTaskProgress = () => {
)?.photo_infos;
}
const updatedProgressMap = data.reduce((res, item) => {
// 单独添加 photo detail
// Add photo details separately
// @ts-expect-error -- linter-disable-autofix
const detail = photoInfos?.[item.document_id] || {};
// @ts-expect-error -- linter-disable-autofix
@@ -157,7 +157,7 @@ export const usePollingTaskProgress = () => {
}
};
// 立即执行一次
// Execute once immediately
const immediatelyExecuteFunction = () => {
fetchProgress();
return fetchProgress;

View File

@@ -29,15 +29,15 @@ export enum ActionType {
export enum FilterPhotoType {
/**
* 全部
* all
*/
All = 'All',
/**
* 已标注
* marked
*/
HasCaption = 'HasCaption',
/**
* 未标注
* unmarked
*/
NoCaption = 'NoCaption',
}

View File

@@ -30,5 +30,5 @@ export interface TranSliceListParams {
onUpdate?: (record: TableViewRecord, index: number, value?: string) => void;
}
/** 切片插入的位置 */
/** Where the slice is inserted */
export type TPosition = 'top' | 'bottom';

View File

@@ -84,7 +84,7 @@ export const DOCUMENT_SOURCE_TYPE_MAP: Record<DocumentSource, string> = {
[DocumentSource.Document]: I18n.t('dataset_detail_source_local'),
[DocumentSource.Web]: I18n.t('dataset_detail_source_online'),
[DocumentSource.Custom]: I18n.t('dataset_detail_source_custom'),
[DocumentSource.ThirdParty]: '', // todo 三方,后端 idl 有此类型,但是无 i18n
[DocumentSource.ThirdParty]: '', // Todo three-way, the backend idl has this type, but no i18n.
[DocumentSource.FrontCrawl]: I18n.t('dataset_detail_source_online'),
[DocumentSource.GoogleDrive]: I18n.t('knowledge-3rd-party-google-drive'),
[DocumentSource.Notion]: I18n.t('knowledge-3rd-party-notion'),
@@ -95,13 +95,13 @@ export const DOCUMENT_SOURCE_TYPE_MAP: Record<DocumentSource, string> = {
};
/**
* 获取 source name
* Get source name
*/
export const getSourceName = (docInfo: DocumentInfo) => {
const { format_type: formatType, source_type: sourceType } = docInfo || {};
if (formatType === FormatType.Table && sourceType === DocumentSource.Web) {
return 'Api';
// 如果是三方数据源
// If it is a third-party data source
}
return DOCUMENT_SOURCE_TYPE_MAP[sourceType || 0] || '-';
};
@@ -135,7 +135,7 @@ interface JumpToAddDocParams {
formatType: FormatType;
docID?: string;
type?: UnitType;
/** 作用是跳转上传页时能在 url 里带上抖音标记,以在上传页做视图区分 */
/** The function is to bring the Douyin mark in the url when jumping to the upload page to distinguish the views on the upload page */
isDouyinBot?: boolean;
}

View File

@@ -13,7 +13,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
import { UnitType } from '@coze-data/knowledge-resource-processor-core';
import { I18n } from '@coze-arch/i18n';
import {
@@ -129,7 +129,7 @@ export const getBasicConfig = () => ({
},
[UnitType.TEXT_WECHAT]: {
unitType: UnitType.TEXT_WECHAT,
// @ts-expect-error -- 暂时没有翻译 TODO: hzf
// @ts-expect-error -- no translation yet TODO: hzf
name: I18n.t('公众号'),
icon: <IconCozWechatFill className="w-4 h-4 [&>path]:fill-current" />,
},