演示目录只保留可重建的源码。运行密钥、数据卷、依赖和带口令的本地配置不进入仓库。 Co-authored-by: Cursor <cursoragent@cursor.com>
68 lines
2.3 KiB
TypeScript
68 lines
2.3 KiB
TypeScript
import type { DocumentFilter } from './query-state'
|
|
import { consoleQuery } from '@/service/console'
|
|
import { getHttpErrorStatus } from '@/service/http-error'
|
|
import { taskGraphIsActive } from './model'
|
|
import { backgroundTaskFromApi } from './models'
|
|
import { TASK_PAGE_SIZE } from './tasks/recovery'
|
|
|
|
export function logicalDocumentsInfiniteOptions(
|
|
knowledgeSpaceId: string,
|
|
{ search = '', filter = 'all' }: { search?: string; filter?: DocumentFilter } = {},
|
|
) {
|
|
return consoleQuery.knowledgeFs.spaces.byControlSpaceId.logicalDocuments.get.infiniteOptions({
|
|
input: (pageParam) => ({
|
|
params: { control_space_id: knowledgeSpaceId },
|
|
query: {
|
|
...(search.trim() ? { query: search.trim() } : {}),
|
|
...(filter !== 'all' ? { status: filter } : {}),
|
|
...(typeof pageParam === 'string' ? { cursor: pageParam } : {}),
|
|
},
|
|
}),
|
|
getNextPageParam: (lastPage) => lastPage.next_cursor,
|
|
initialPageParam: null as string | null,
|
|
})
|
|
}
|
|
|
|
export function documentTasksInfiniteOptions(
|
|
knowledgeSpaceId: string,
|
|
{ enabled }: { enabled: boolean },
|
|
) {
|
|
return consoleQuery.knowledgeFs.spaces.byControlSpaceId.backgroundTasks.get.infiniteOptions({
|
|
enabled,
|
|
input: (pageParam) => ({
|
|
params: { control_space_id: knowledgeSpaceId },
|
|
query: {
|
|
limit: TASK_PAGE_SIZE,
|
|
...(typeof pageParam === 'string' ? { cursor: pageParam } : {}),
|
|
},
|
|
}),
|
|
getNextPageParam: (lastPage) => lastPage.next_cursor,
|
|
refetchInterval: (query) => {
|
|
if (getHttpErrorStatus(query.state.error) === 403) return false
|
|
return query.state.data?.pages.some((page) =>
|
|
page.data.some((task) => taskGraphIsActive(backgroundTaskFromApi(task))),
|
|
)
|
|
? 5000
|
|
: false
|
|
},
|
|
initialPageParam: null as string | null,
|
|
})
|
|
}
|
|
|
|
export function documentSourcesInfiniteOptions(
|
|
knowledgeSpaceId: string,
|
|
{ enabled }: { enabled: boolean },
|
|
) {
|
|
return consoleQuery.knowledgeFs.spaces.byControlSpaceId.sources.get.infiniteOptions({
|
|
enabled,
|
|
input: (pageParam) => ({
|
|
params: { control_space_id: knowledgeSpaceId },
|
|
query: {
|
|
...(typeof pageParam === 'string' ? { cursor: pageParam } : {}),
|
|
},
|
|
}),
|
|
getNextPageParam: (lastPage) => lastPage.next_cursor,
|
|
initialPageParam: null as string | null,
|
|
})
|
|
}
|