fix: 收敛 AgentRun 事件摘要输出
This commit is contained in:
@@ -456,9 +456,33 @@ function runnerJobObservationIdentity(managerResource: Record<string, unknown>,
|
||||
export async function resourceEvents(config: UniDeskConfig | null, command: string, action: string | undefined, args: string[], options: AgentRunResourceOptions): Promise<RenderedCliResult> {
|
||||
const ref = parseResourceRef(action, args, "run");
|
||||
const runId = ref.kind === "run" ? ref.name : options.runId ?? requiredContext("events", "--run <runId>");
|
||||
const eventArgs = ["events", runId, "--after-seq", String(options.afterSeq ?? 0), "--limit", String(options.limit), "--tail-summary"];
|
||||
const requestedLimit = Math.max(1, options.limit);
|
||||
const effectiveLimit = options.full || options.raw ? requestedLimit : Math.min(requestedLimit, 20);
|
||||
const requestLimit = options.full || options.raw ? effectiveLimit : Math.min(500, effectiveLimit + 1);
|
||||
const eventArgs = ["events", runId, "--after-seq", String(options.afterSeq ?? 0), "--limit", String(requestLimit)];
|
||||
const result = await runAgentRunRestCommand(config, "runs", eventArgs);
|
||||
return renderEventLike(command, result, options, "Event", normalizeEventItems(innerData(result)), runId);
|
||||
if (options.raw) return renderMachine(command, result, "json", result.ok !== false);
|
||||
if (options.full) return renderMachine(command, result, options.output === "yaml" ? "yaml" : "json", result.ok !== false);
|
||||
|
||||
const fetchedItems = arrayRecords(record(innerData(result)).items ?? innerData(result));
|
||||
const visibleItems = fetchedItems.slice(0, effectiveLimit);
|
||||
const hasMore = fetchedItems.length > visibleItems.length;
|
||||
const lastVisibleSeq = visibleItems.length === 0 ? null : nonNegativeIntegerOrNull(visibleItems.at(-1)?.seq);
|
||||
const responseNextAfterSeq = nonNegativeIntegerOrNull(record(innerData(result)).nextAfterSeq);
|
||||
const nextAfterSeq = hasMore ? lastVisibleSeq : responseNextAfterSeq;
|
||||
const targetArgs = [
|
||||
options.node === null ? null : `--node ${options.node}`,
|
||||
options.lane === null ? null : `--lane ${options.lane}`,
|
||||
].filter((value): value is string => value !== null).join(" ");
|
||||
const detailCommand = `bun scripts/cli.ts agentrun events run/${runId} --after-seq <item.seq-1> --limit 1 --full -o json${targetArgs.length === 0 ? "" : ` ${targetArgs}`}`;
|
||||
return renderEventLike(command, result, options, "Event", normalizeEventItems({ items: visibleItems }, runId), runId, {
|
||||
requestedLimit,
|
||||
effectiveLimit,
|
||||
fetchedCount: fetchedItems.length,
|
||||
hasMore,
|
||||
nextAfterSeq,
|
||||
detailCommand,
|
||||
});
|
||||
}
|
||||
|
||||
export async function resourceLogs(config: UniDeskConfig | null, command: string, action: string | undefined, args: string[], options: AgentRunResourceOptions): Promise<RenderedCliResult> {
|
||||
|
||||
Reference in New Issue
Block a user