|
1 | | -import { RetrieveRunResponse, RetrieveRunTraceResponseBody } from "@trigger.dev/core/v3/schemas"; |
| 1 | +import { |
| 2 | + ListRunResponseItem, |
| 3 | + RetrieveRunResponse, |
| 4 | + RetrieveRunTraceResponseBody, |
| 5 | +} from "@trigger.dev/core/v3/schemas"; |
| 6 | +import { CursorPageResponse } from "@trigger.dev/core/v3/zodfetch"; |
2 | 7 |
|
3 | 8 | export function formatRun(run: RetrieveRunResponse): string { |
4 | 9 | const lines: string[] = []; |
@@ -276,3 +281,100 @@ function getStatusIndicator( |
276 | 281 | if (spanData.isPartial) return "[PARTIAL]"; |
277 | 282 | return "[COMPLETED]"; |
278 | 283 | } |
| 284 | + |
| 285 | +export function formatRunList(runsPage: CursorPageResponse<ListRunResponseItem>): string { |
| 286 | + const lines: string[] = []; |
| 287 | + |
| 288 | + // Header with count info |
| 289 | + const totalRuns = runsPage.data.length; |
| 290 | + lines.push(`Found ${totalRuns} run${totalRuns === 1 ? "" : "s"}`); |
| 291 | + lines.push(""); |
| 292 | + |
| 293 | + if (totalRuns === 0) { |
| 294 | + lines.push("No runs found."); |
| 295 | + return lines.join("\n"); |
| 296 | + } |
| 297 | + |
| 298 | + // Format each run in a compact table-like format |
| 299 | + runsPage.data.forEach((run, index) => { |
| 300 | + lines.push(`${index + 1}. ${formatRunSummary(run)}`); |
| 301 | + }); |
| 302 | + |
| 303 | + // Pagination info |
| 304 | + lines.push(""); |
| 305 | + const paginationInfo = []; |
| 306 | + if (runsPage.pagination.previous) { |
| 307 | + paginationInfo.push("← Previous page available"); |
| 308 | + } |
| 309 | + if (runsPage.pagination.next) { |
| 310 | + paginationInfo.push("Next page available →"); |
| 311 | + } |
| 312 | + |
| 313 | + if (paginationInfo.length > 0) { |
| 314 | + lines.push(`Pagination: ${paginationInfo.join(" | ")}`); |
| 315 | + if (runsPage.pagination.next) { |
| 316 | + lines.push(`Next cursor: ${runsPage.pagination.next}`); |
| 317 | + } |
| 318 | + if (runsPage.pagination.previous) { |
| 319 | + lines.push(`Previous cursor: ${runsPage.pagination.previous}`); |
| 320 | + } |
| 321 | + } |
| 322 | + |
| 323 | + return lines.join("\n"); |
| 324 | +} |
| 325 | + |
| 326 | +function formatRunSummary(run: ListRunResponseItem): string { |
| 327 | + const parts: string[] = []; |
| 328 | + |
| 329 | + // Basic info: ID, task, status |
| 330 | + parts.push(`${run.id}`); |
| 331 | + parts.push(`${run.taskIdentifier}`); |
| 332 | + parts.push(`${formatStatus(run.status)}`); |
| 333 | + |
| 334 | + // Environment |
| 335 | + parts.push(`env:${run.env.name}`); |
| 336 | + |
| 337 | + // Timing - show the most relevant time |
| 338 | + let timeInfo = ""; |
| 339 | + if (run.finishedAt) { |
| 340 | + timeInfo = `finished ${formatDateTime(run.finishedAt)}`; |
| 341 | + } else if (run.startedAt) { |
| 342 | + timeInfo = `started ${formatDateTime(run.startedAt)}`; |
| 343 | + } else if (run.delayedUntil) { |
| 344 | + timeInfo = `delayed until ${formatDateTime(run.delayedUntil)}`; |
| 345 | + } else { |
| 346 | + timeInfo = `created ${formatDateTime(run.createdAt)}`; |
| 347 | + } |
| 348 | + parts.push(timeInfo); |
| 349 | + |
| 350 | + // Duration if available |
| 351 | + if (run.durationMs > 0) { |
| 352 | + parts.push(`took ${formatDuration(run.durationMs)}`); |
| 353 | + } |
| 354 | + |
| 355 | + // Cost if significant |
| 356 | + if (run.costInCents > 0) { |
| 357 | + parts.push(`$${(run.costInCents / 100).toFixed(4)}`); |
| 358 | + } |
| 359 | + |
| 360 | + // Tags if present |
| 361 | + if (run.tags && run.tags.length > 0) { |
| 362 | + const tagStr = |
| 363 | + run.tags.length > 2 |
| 364 | + ? `${run.tags.slice(0, 2).join(", ")}+${run.tags.length - 2}` |
| 365 | + : run.tags.join(", "); |
| 366 | + parts.push(`tags:[${tagStr}]`); |
| 367 | + } |
| 368 | + |
| 369 | + // Test flag |
| 370 | + if (run.isTest) { |
| 371 | + parts.push("[TEST]"); |
| 372 | + } |
| 373 | + |
| 374 | + // Version if available |
| 375 | + if (run.version) { |
| 376 | + parts.push(`v${run.version}`); |
| 377 | + } |
| 378 | + |
| 379 | + return parts.join(" | "); |
| 380 | +} |
0 commit comments