fix code queue enqueue view preservation
This commit is contained in:
@@ -2215,6 +2215,99 @@ export function CodeQueuePage({ microservices, onRaw, apiBaseUrl = "/api", initi
|
||||
};
|
||||
}
|
||||
|
||||
function taskVisibleInQueueFilter(task: any, queueFilterId: string): boolean {
|
||||
return isAllQueues(queueFilterId) || taskQueueLabel(task) === queueFilterId;
|
||||
}
|
||||
|
||||
function taskMatchesCurrentSearch(task: any): boolean {
|
||||
const query = normalizedSearchQuery.toLowerCase();
|
||||
if (query.length === 0) return true;
|
||||
const haystack = [
|
||||
task?.id,
|
||||
task?.status,
|
||||
task?.queueId,
|
||||
task?.providerId,
|
||||
task?.model,
|
||||
task?.cwd,
|
||||
task?.displayPrompt,
|
||||
task?.basePrompt,
|
||||
task?.prompt,
|
||||
task?.finalResponse,
|
||||
task?.lastError?.message,
|
||||
].map((value) => String(value || "").toLowerCase()).join("\n");
|
||||
return haystack.includes(query);
|
||||
}
|
||||
|
||||
function mergeCreatedTasksIntoCurrentView(createdTasks: any[], queuePatch: any): void {
|
||||
const rows = createdTasks.filter((task) => String(task?.id || "").length > 0);
|
||||
if (rows.length === 0 && !queuePatch) return;
|
||||
const firstTask = rows[0] || null;
|
||||
const firstId = String(firstTask?.id || "");
|
||||
const filteredRows = rows.filter((task) => taskVisibleInQueueFilter(task, selectedQueueId));
|
||||
const searchableRows = filteredRows.filter(taskMatchesCurrentSearch);
|
||||
const activeSortId = String(queuePatch?.activeTaskId || activeTaskIds(queuePatch)[0] || firstId || activeTaskId || "");
|
||||
for (const task of rows) {
|
||||
const taskId = String(task?.id || "");
|
||||
if (!taskId) continue;
|
||||
const transcript = Array.isArray(task?.transcript) ? task.transcript : [];
|
||||
sessionCacheRef.current.set(taskId, {
|
||||
...(sessionCacheRef.current.get(taskId) || {}),
|
||||
task: {
|
||||
...task,
|
||||
_summaryLoaded: true,
|
||||
_detailLoaded: transcript.length > 0,
|
||||
_transcriptComplete: false,
|
||||
_transcriptPreview: false,
|
||||
},
|
||||
maxSeq: transcriptMaxSeq(transcript),
|
||||
complete: false,
|
||||
completeUpdatedAt: "",
|
||||
});
|
||||
}
|
||||
setTasksData((previous: any) => {
|
||||
if (!previous && (filteredRows.length === 0 || !queuePatch)) return previous;
|
||||
const previousRows = taskRows(previous);
|
||||
const mergedRows = applyLocalReadStateToRows(mergeTaskRowsPreferLatest([previousRows, filteredRows], activeSortId));
|
||||
return {
|
||||
...(previous || {}),
|
||||
queue: queuePatch || previous?.queue,
|
||||
tasks: mergedRows,
|
||||
pagination: previous?.pagination ? { ...taskPagination(previous), returned: mergedRows.length } : previous?.pagination,
|
||||
};
|
||||
});
|
||||
if (searchActive) {
|
||||
setSearchTasksData((previous: any) => {
|
||||
if (!previous || searchableRows.length === 0) return previous;
|
||||
const mergedRows = applyLocalReadStateToRows(mergeTaskRowsPreferLatest([taskRows(previous), searchableRows], activeSortId));
|
||||
return {
|
||||
...previous,
|
||||
queue: queuePatch || previous.queue,
|
||||
tasks: mergedRows,
|
||||
pagination: previous.pagination ? { ...taskPagination(previous), returned: mergedRows.length } : previous.pagination,
|
||||
};
|
||||
});
|
||||
}
|
||||
if (firstTask && taskVisibleInQueueFilter(firstTask, selectedQueueId) && taskMatchesCurrentSearch(firstTask)) {
|
||||
detailLoadTokenRef.current += 1;
|
||||
selectedIdRef.current = firstId;
|
||||
setSelectedId(firstId);
|
||||
setSelectedTask(sessionCacheRef.current.get(firstId)?.task || firstTask);
|
||||
setSelectedDetailLoading(false);
|
||||
setLoadStats({
|
||||
phase: "complete",
|
||||
taskId: firstId,
|
||||
queueMs: 0,
|
||||
detailMs: 0,
|
||||
totalMs: 0,
|
||||
chunks: 1,
|
||||
transcriptRows: Array.isArray(firstTask?.transcript) ? firstTask.transcript.length : 0,
|
||||
partial: true,
|
||||
completedAt: new Date(),
|
||||
});
|
||||
}
|
||||
setRefreshedAt(new Date());
|
||||
}
|
||||
|
||||
function changeSubmitProvider(nextProviderId: string): void {
|
||||
const next = String(nextProviderId || queue?.mainProviderId || "D601").trim() || "D601";
|
||||
setProviderId(next);
|
||||
@@ -3194,15 +3287,16 @@ export function CodeQueuePage({ microservices, onRaw, apiBaseUrl = "/api", initi
|
||||
const firstId = result?.tasks?.[0]?.id || "";
|
||||
const ids = Array.isArray(result?.tasks) ? result.tasks.map((task: any) => String(task?.id || "")).filter(Boolean) : [];
|
||||
const msg = `已创建 ${ids.length || submittingItems.length} 个任务${ids.length > 0 ? `:${ids.join(" / ")}` : ""}`;
|
||||
mergeCreatedTasksIntoCurrentView(Array.isArray(result?.tasks) ? result.tasks : [], result?.queue || null);
|
||||
setNotice(msg);
|
||||
addNotification("success", msg);
|
||||
setPrompt("");
|
||||
setReferenceTaskId("");
|
||||
setBatchConfirmed(false);
|
||||
selectedIdRef.current = firstId;
|
||||
if (selectedQueueId !== submitQueueId) setTasksData(null);
|
||||
setQueueId(submitQueueId);
|
||||
await load(firstId, true, submitQueueId);
|
||||
if (firstId && taskVisibleInQueueFilter(result?.tasks?.[0], selectedQueueId) && taskMatchesCurrentSearch(result?.tasks?.[0])) {
|
||||
void ensureTraceSummary(String(firstId), false).catch((err) => setError(errorText(err, "加载 Codex Trace Summary 失败")));
|
||||
}
|
||||
}, "Codex 任务入队失败");
|
||||
enqueueInFlightRef.current = false;
|
||||
setSubmitting(false);
|
||||
|
||||
Reference in New Issue
Block a user