-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathjob.ts
More file actions
59 lines (56 loc) · 1.99 KB
/
Copy pathjob.ts
File metadata and controls
59 lines (56 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import { defineCommand } from "citty";
import { loadContext } from "../context.js";
import { request } from "../http.js";
import { emit } from "../output.js";
import { type Job, JobSchema } from "../types.js";
/**
* Pure renderer for `aiw job status` — pulled out so the layout is
* unit-testable without spinning up the citty wrapper.
*/
export function renderJob(j: Job): string {
const lines: string[] = [];
lines.push(`id ${j.jobId}`);
if (j.kind) lines.push(`kind ${j.kind}`);
lines.push(`status ${j.status ?? "unknown"}`);
if (typeof j.processed === "number") {
const total = j.total ?? null;
lines.push(`progress ${j.processed}${total !== null ? `/${total}` : ""}`);
}
if (j.knowledgeBaseId) lines.push(`kb ${j.knowledgeBaseId}`);
if (j.documentId) lines.push(`document ${j.documentId}`);
if (j.createdAt) lines.push(`created ${j.createdAt}`);
if (j.updatedAt) lines.push(`updated ${j.updatedAt}`);
if (j.errorMessage) lines.push(`error ${j.errorMessage}`);
return lines.join("\n");
}
const status = defineCommand({
meta: { name: "status", description: "Show the status of an async job." },
args: {
id: { type: "positional", required: true, description: "Job ID" },
workspace: {
type: "string",
description: "Workspace ID (defaults to profile.defaultWorkspace)",
},
profile: { type: "string" },
url: { type: "string" },
output: { type: "string", description: "human | json" },
},
async run({ args }) {
const ctx = await loadContext(args);
const ws = args.workspace?.trim() || ctx.resolved.profile.defaultWorkspace;
if (!ws)
throw new Error(
"--workspace is required (or set defaultWorkspace in your profile).",
);
const job = await request(
ctx.request,
`/api/v1/workspaces/${encodeURIComponent(ws)}/jobs/${encodeURIComponent(args.id)}`,
JobSchema,
);
emit(ctx.output, job, renderJob);
},
});
export const jobCommand = defineCommand({
meta: { name: "job", description: "Inspect async jobs." },
subCommands: { status },
});