Refactor pipeline task handling and UI flows

This commit is contained in:
2026-06-13 21:09:49 +02:00
parent 21c7e4c9a4
commit ff4c572157
24 changed files with 1346 additions and 236 deletions

View File

@@ -7,7 +7,7 @@ import {
normalizeListLimit,
} from "./domain";
import type { Id } from "./_generated/dataModel";
import { internalMutation, mutation, query } from "./_generated/server";
import { internalMutation, internalQuery, mutation, query } from "./_generated/server";
import type { MutationCtx, QueryCtx } from "./_generated/server";
const runType = v.union(...RUN_TYPES.map((type) => v.literal(type)));
@@ -127,6 +127,112 @@ export const updateStatus = mutation({
},
});
export const updateProgressInternal = internalMutation({
args: {
id: v.id("agentRuns"),
status: v.optional(runStatus),
currentStep: v.optional(v.string()),
errorSummary: v.optional(v.string()),
workflowId: v.optional(v.string()),
attempt: v.optional(v.number()),
maxAttempts: v.optional(v.number()),
progressStep: v.optional(v.number()),
progressTotal: v.optional(v.number()),
progressLabel: v.optional(v.string()),
progressPercent: v.optional(v.number()),
lastRetryReason: v.optional(v.string()),
},
handler: async (ctx, args) => {
const now = Date.now();
const patch: {
status?: (typeof RUN_STATUSES)[number];
updatedAt: number;
currentStep?: string;
errorSummary?: string;
workflowId?: string;
attempt?: number;
maxAttempts?: number;
progressStep?: number;
progressTotal?: number;
progressLabel?: string;
progressPercent?: number;
lastRetryReason?: string;
startedAt?: number;
finishedAt?: number;
} = {
updatedAt: now,
};
if (args.status !== undefined) {
patch.status = args.status;
if (args.status === "running") {
patch.startedAt = now;
patch.finishedAt = undefined;
}
if (
args.status === "succeeded" ||
args.status === "failed" ||
args.status === "canceled"
) {
patch.finishedAt = now;
}
}
if (args.currentStep !== undefined) {
patch.currentStep = args.currentStep;
}
if (args.errorSummary !== undefined) {
patch.errorSummary = args.errorSummary;
}
if (args.workflowId !== undefined) {
patch.workflowId = args.workflowId;
}
if (args.attempt !== undefined) {
patch.attempt = args.attempt;
}
if (args.maxAttempts !== undefined) {
patch.maxAttempts = args.maxAttempts;
}
if (args.progressStep !== undefined) {
patch.progressStep = args.progressStep;
}
if (args.progressTotal !== undefined) {
patch.progressTotal = args.progressTotal;
}
if (args.progressLabel !== undefined) {
patch.progressLabel = args.progressLabel;
}
if (args.progressPercent !== undefined) {
patch.progressPercent = args.progressPercent;
}
if (args.lastRetryReason !== undefined) {
patch.lastRetryReason = args.lastRetryReason;
}
await ctx.db.patch(args.id, patch);
return args.id;
},
});
export const getAuditRunForWorkflowInternal = internalQuery({
args: {
id: v.id("agentRuns"),
},
handler: async (ctx, args) => {
const run = await ctx.db.get(args.id);
if (!run || run.type !== "audit") {
return null;
}
return {
_id: run._id,
leadId: run.leadId ?? null,
auditId: run.auditId ?? null,
status: run.status,
currentStep: run.currentStep ?? null,
};
},
});
export const list = query({
args: {
status: v.optional(runStatus),