fix: unify codex queues json shape
This commit is contained in:
@@ -144,6 +144,7 @@ interface CodexTasksDegraded {
|
||||
interface CodexQueuesOptions {
|
||||
full: boolean;
|
||||
limit: number;
|
||||
limitExplicit: boolean;
|
||||
}
|
||||
|
||||
type CodexRequestInit = { method?: string; body?: unknown };
|
||||
@@ -989,6 +990,7 @@ function parseQueuesOptions(args: string[]): CodexQueuesOptions {
|
||||
return {
|
||||
full: hasFlag(args, "--full") || hasFlag(args, "--all"),
|
||||
limit: positiveIntegerOption(args, ["--limit"], defaultTasksLimit, maxTasksLimit),
|
||||
limitExplicit: args.includes("--limit"),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1675,13 +1677,14 @@ function compactQueuesResponse(body: Record<string, unknown>, options: CodexQueu
|
||||
const runnableQueues = queues.filter((row) => row.runnableTaskId !== null && row.runnableTaskId !== undefined);
|
||||
const activeQueues = queues.filter((row) => typeof row.id === "string" && activeIds.includes(row.id));
|
||||
const selected = options.full ? queues : Array.from(new Map([...activeQueues, ...unreadQueues, ...runnableQueues, ...nonemptyQueues].map((row) => [String(row.id), row])).values());
|
||||
const visible = selected.slice(0, options.limit);
|
||||
const limitApplied = !options.full || options.limitExplicit;
|
||||
const visible = limitApplied ? selected.slice(0, options.limit) : selected;
|
||||
const diagnostics = compactExecutionDiagnostics(queue.executionDiagnostics);
|
||||
return {
|
||||
upstream,
|
||||
queues: {
|
||||
view: options.full ? "full" : "summary",
|
||||
bounded: true,
|
||||
bounded: limitApplied,
|
||||
count: selected.length,
|
||||
returned: visible.length,
|
||||
hasMore: selected.length > visible.length,
|
||||
@@ -1700,6 +1703,17 @@ function compactQueuesResponse(body: Record<string, unknown>, options: CodexQueu
|
||||
unreadTerminal: queue.unreadTerminal ?? 0,
|
||||
executionDiagnostics: diagnostics,
|
||||
items: visible,
|
||||
...(options.full
|
||||
? {
|
||||
deprecatedFullArray: asArray(body.queues),
|
||||
compatibility: {
|
||||
deprecated: true,
|
||||
deprecatedPath: "data.queues.deprecatedFullArray[]",
|
||||
stablePath: "data.queues.items[]",
|
||||
message: "Use data.queues.items[] for both codex queues and codex queues --full.",
|
||||
},
|
||||
}
|
||||
: {}),
|
||||
commands: {
|
||||
refresh: `bun scripts/cli.ts codex queues${options.limit === defaultTasksLimit ? "" : ` --limit ${options.limit}`}`,
|
||||
full: `bun scripts/cli.ts codex queues --full${options.limit === defaultTasksLimit ? "" : ` --limit ${options.limit}`}`,
|
||||
@@ -1711,13 +1725,16 @@ function compactQueuesResponse(body: Record<string, unknown>, options: CodexQueu
|
||||
};
|
||||
}
|
||||
|
||||
function codeQueues(optionArgs: string[] = []): unknown {
|
||||
export function codexQueuesQueryForTest(optionArgs: string[], fetcher: CodexResponseFetcher): unknown {
|
||||
const options = parseQueuesOptions(optionArgs);
|
||||
const response = unwrapCodexResponse(coreInternalFetch(codeQueueProxyPath("/api/queues")));
|
||||
if (options.full) return { upstream: response.upstream, queues: response.body.queues ?? [], queue: compactQueueMutationSummary(response.body.queue), commands: { summary: "bun scripts/cli.ts codex queues" } };
|
||||
const response = unwrapCodexResponse(fetcher(codeQueueProxyPath("/api/queues")));
|
||||
return compactQueuesResponse(response.body, options, response.upstream);
|
||||
}
|
||||
|
||||
function codeQueues(optionArgs: string[] = []): unknown {
|
||||
return codexQueuesQueryForTest(optionArgs, coreInternalFetch);
|
||||
}
|
||||
|
||||
function codexCreateQueue(queueId: string): unknown {
|
||||
return unwrapCodexResponse(coreInternalFetch(codeQueueProxyPath("/api/queues"), { method: "POST", body: { queueId } }));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user