import type { Dispatch, SetStateAction } from 'react' import { ChevronLeft, ChevronRight, Loader2, RefreshCw, Upload } from 'lucide-react' import { MemoryMiniTabs } from '@/components/memory/MemoryMiniTabs' import { MemoryProgressIndicator } from '@/components/memory/MemoryProgressIndicator' import { Alert, AlertDescription } from '@/components/ui/alert' import { Badge } from '@/components/ui/badge' import { Button } from '@/components/ui/button' import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card' import { Checkbox } from '@/components/ui/checkbox' import { Input } from '@/components/ui/input' import { Label } from '@/components/ui/label' import { Progress } from '@/components/ui/progress' import { ScrollArea } from '@/components/ui/scroll-area' import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select' import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from '@/components/ui/table' import { Tabs, TabsContent } from '@/components/ui/tabs' import { Textarea } from '@/components/ui/textarea' import { cn } from '@/lib/utils' import type { MemoryImportChunkPayload, MemoryImportFilePayload, MemoryImportInputMode, MemoryImportRetrySummary, MemoryImportSettings, MemoryImportTaskKind, MemoryImportTaskPayload, } from '@/lib/memory-api' import { IMPORT_CHUNK_PAGE_SIZE, IMPORT_KIND_OPTIONS, RUNNING_IMPORT_STATUS } from '../constants' import { formatImportTime, getImportStatusLabel, getImportStatusVariant, getImportStepLabel, normalizeImportInputMode, normalizeProgress, } from '../utils' export interface ImportTabProps { importCreateMode: MemoryImportTaskKind setImportCreateMode: Dispatch> importSettings: MemoryImportSettings importCommonFileConcurrency: string setImportCommonFileConcurrency: Dispatch> importCommonChunkConcurrency: string setImportCommonChunkConcurrency: Dispatch> importCommonLlmEnabled: boolean setImportCommonLlmEnabled: Dispatch> importCommonChatLog: boolean setImportCommonChatLog: Dispatch> importCommonStrategyOverride: string setImportCommonStrategyOverride: Dispatch> importCommonDedupePolicy: string setImportCommonDedupePolicy: Dispatch> importCommonChatReferenceTime: string setImportCommonChatReferenceTime: Dispatch> importCommonForce: boolean setImportCommonForce: Dispatch> importCommonClearManifest: boolean setImportCommonClearManifest: Dispatch> uploadInputMode: MemoryImportInputMode setUploadInputMode: Dispatch> uploadFiles: File[] setUploadFiles: Dispatch> pasteName: string setPasteName: Dispatch> pasteMode: MemoryImportInputMode setPasteMode: Dispatch> pasteContent: string setPasteContent: Dispatch> rawAlias: string setRawAlias: Dispatch> rawInputMode: MemoryImportInputMode setRawInputMode: Dispatch> rawRelativePath: string setRawRelativePath: Dispatch> rawGlob: string setRawGlob: Dispatch> rawRecursive: boolean setRawRecursive: Dispatch> openieAlias: string setOpenieAlias: Dispatch> openieRelativePath: string setOpenieRelativePath: Dispatch> openieIncludeAllJson: boolean setOpenieIncludeAllJson: Dispatch> convertAlias: string setConvertAlias: Dispatch> convertTargetAlias: string setConvertTargetAlias: Dispatch> convertRelativePath: string setConvertRelativePath: Dispatch> convertTargetRelativePath: string setConvertTargetRelativePath: Dispatch> convertDimension: string setConvertDimension: Dispatch> convertBatchSize: string setConvertBatchSize: Dispatch> backfillAlias: string setBackfillAlias: Dispatch> backfillLimit: string setBackfillLimit: Dispatch> backfillRelativePath: string setBackfillRelativePath: Dispatch> backfillDryRun: boolean setBackfillDryRun: Dispatch> backfillNoCreatedFallback: boolean setBackfillNoCreatedFallback: Dispatch> maibotSourceDb: string setMaibotSourceDb: Dispatch> maibotTimeFrom: string setMaibotTimeFrom: Dispatch> maibotTimeTo: string setMaibotTimeTo: Dispatch> maibotStartId: string setMaibotStartId: Dispatch> maibotEndId: string setMaibotEndId: Dispatch> maibotStreamIds: string setMaibotStreamIds: Dispatch> maibotGroupIds: string setMaibotGroupIds: Dispatch> maibotUserIds: string setMaibotUserIds: Dispatch> maibotReadBatchSize: string setMaibotReadBatchSize: Dispatch> maibotCommitWindowRows: string setMaibotCommitWindowRows: Dispatch> maibotEmbedWorkers: string setMaibotEmbedWorkers: Dispatch> maibotNoResume: boolean setMaibotNoResume: Dispatch> maibotResetState: boolean setMaibotResetState: Dispatch> maibotDryRun: boolean setMaibotDryRun: Dispatch> maibotVerifyOnly: boolean setMaibotVerifyOnly: Dispatch> submitImportByMode: () => Promise creatingImport: boolean pathResolveAlias: string setPathResolveAlias: Dispatch> importAliasKeys: string[] pathResolveRelativePath: string setPathResolveRelativePath: Dispatch> pathResolveMustExist: boolean setPathResolveMustExist: Dispatch> resolveImportPath: () => Promise resolvingPath: boolean pathResolveOutput: string refreshImportQueue: () => Promise runningImportTasks: MemoryImportTaskPayload[] queuedImportTasks: MemoryImportTaskPayload[] recentImportTasks: MemoryImportTaskPayload[] selectedImportTaskId: string selectImportTask: (taskId: string) => Promise importAutoPolling: boolean setImportAutoPolling: Dispatch> importPollInterval: number importErrorText: string cancelSelectedImportTask: () => Promise retrySelectedImportTask: () => Promise selectedImportTaskLoading: boolean selectedImportTaskResolved: MemoryImportTaskPayload | null | undefined selectedImportRetrySummary: MemoryImportRetrySummary | null | undefined selectedImportTaskErrorText: string selectedImportFiles: MemoryImportFilePayload[] selectedImportFileId: string selectImportFile: (fileId: string) => Promise importChunkTotal: number importChunkOffset: number moveImportChunkPage: (direction: -1 | 1) => Promise canImportChunkPrev: boolean canImportChunkNext: boolean importChunksLoading: boolean selectedImportChunks: MemoryImportChunkPayload[] } export function ImportTab(props: ImportTabProps) { const { importCreateMode, setImportCreateMode, importSettings, importCommonFileConcurrency, setImportCommonFileConcurrency, importCommonChunkConcurrency, setImportCommonChunkConcurrency, importCommonLlmEnabled, setImportCommonLlmEnabled, importCommonChatLog, setImportCommonChatLog, importCommonStrategyOverride, setImportCommonStrategyOverride, importCommonDedupePolicy, setImportCommonDedupePolicy, importCommonChatReferenceTime, setImportCommonChatReferenceTime, importCommonForce, setImportCommonForce, importCommonClearManifest, setImportCommonClearManifest, uploadInputMode, setUploadInputMode, uploadFiles, setUploadFiles, pasteName, setPasteName, pasteMode, setPasteMode, pasteContent, setPasteContent, rawAlias, setRawAlias, rawInputMode, setRawInputMode, rawRelativePath, setRawRelativePath, rawGlob, setRawGlob, rawRecursive, setRawRecursive, openieAlias, setOpenieAlias, openieRelativePath, setOpenieRelativePath, openieIncludeAllJson, setOpenieIncludeAllJson, convertAlias, setConvertAlias, convertTargetAlias, setConvertTargetAlias, convertRelativePath, setConvertRelativePath, convertTargetRelativePath, setConvertTargetRelativePath, convertDimension, setConvertDimension, convertBatchSize, setConvertBatchSize, backfillAlias, setBackfillAlias, backfillLimit, setBackfillLimit, backfillRelativePath, setBackfillRelativePath, backfillDryRun, setBackfillDryRun, backfillNoCreatedFallback, setBackfillNoCreatedFallback, maibotSourceDb, setMaibotSourceDb, maibotTimeFrom, setMaibotTimeFrom, maibotTimeTo, setMaibotTimeTo, maibotStartId, setMaibotStartId, maibotEndId, setMaibotEndId, maibotStreamIds, setMaibotStreamIds, maibotGroupIds, setMaibotGroupIds, maibotUserIds, setMaibotUserIds, maibotReadBatchSize, setMaibotReadBatchSize, maibotCommitWindowRows, setMaibotCommitWindowRows, maibotEmbedWorkers, setMaibotEmbedWorkers, maibotNoResume, setMaibotNoResume, maibotResetState, setMaibotResetState, maibotDryRun, setMaibotDryRun, maibotVerifyOnly, setMaibotVerifyOnly, submitImportByMode, creatingImport, pathResolveAlias, setPathResolveAlias, importAliasKeys, pathResolveRelativePath, setPathResolveRelativePath, pathResolveMustExist, setPathResolveMustExist, resolveImportPath, resolvingPath, pathResolveOutput, refreshImportQueue, runningImportTasks, queuedImportTasks, recentImportTasks, selectedImportTaskId, selectImportTask, importAutoPolling, setImportAutoPolling, importPollInterval, importErrorText, cancelSelectedImportTask, retrySelectedImportTask, selectedImportTaskLoading, selectedImportTaskResolved, selectedImportRetrySummary, selectedImportTaskErrorText, selectedImportFiles, selectedImportFileId, selectImportFile, importChunkTotal, importChunkOffset, moveImportChunkPage, canImportChunkPrev, canImportChunkNext, importChunksLoading, selectedImportChunks, } = props return (
创建导入任务 按“选择导入方式 → 检查公共参数 → 创建任务”的顺序完成导入。 setImportCreateMode(value as MemoryImportTaskKind)} className="space-y-4" >
公共参数
这些设置会应用到当前导入任务。一般保持默认即可,只在批量导入或排查问题时调整。
同时处理多少个文件;文件很多时再适当调高。
setImportCommonFileConcurrency(event.target.value)} />
单个文件内并行处理多少个分块;过高会增加资源占用。
setImportCommonChunkConcurrency(event.target.value)} />
setImportCommonLlmEnabled(Boolean(value))} /> 启用 LLM 抽取
需要模型参与抽取,质量更高但耗时更长。
setImportCommonChatLog(Boolean(value))} /> 按聊天日志解析
适合导入聊天记录,会尽量保留时间和对话上下文。
高级参数(通常不用修改)
setImportCommonStrategyOverride(event.target.value)} />
setImportCommonDedupePolicy(event.target.value)} />
setImportCommonChatReferenceTime(event.target.value)} />
setImportCommonForce(Boolean(value))} /> 强制导入
setImportCommonClearManifest(Boolean(value))} /> 清空导入清单
选择一个或多个本地文件创建导入任务,适合批量导入资料或聊天记录。
setUploadFiles(Array.from(event.target.files ?? []))} />
已选择 {uploadFiles.length} 个文件
直接粘贴少量文本或 JSON,适合临时补充一段资料。
setPasteName(event.target.value)} />