-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathutils.ts
More file actions
76 lines (65 loc) · 2.29 KB
/
utils.ts
File metadata and controls
76 lines (65 loc) · 2.29 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import type { Task, TaskPermissions, TaskStatus } from "./types";
export function getTaskLabel(task: Task): string {
return task.display_name || task.name || task.id;
}
const PAUSABLE_STATUSES: readonly TaskStatus[] = [
"active",
"initializing",
"pending",
"error",
"unknown",
];
const PAUSE_DISABLED_STATUSES: readonly TaskStatus[] = [
"pending",
"initializing",
];
const RESUMABLE_STATUSES: readonly TaskStatus[] = [
"paused",
"error",
"unknown",
];
export function getTaskPermissions(task: Task): TaskPermissions {
const hasWorkspace = task.workspace_id !== null;
const status = task.status;
const canSendMessage =
task.status === "active" && task.current_state?.state !== "working";
return {
canPause: hasWorkspace && PAUSABLE_STATUSES.includes(status),
pauseDisabled: PAUSE_DISABLED_STATUSES.includes(status),
canResume: hasWorkspace && RESUMABLE_STATUSES.includes(status),
canSendMessage,
};
}
/** Whether the agent is actively working (status is active and state is working). */
export function isTaskWorking(task: Task): boolean {
return task.status === "active" && task.current_state?.state === "working";
}
/**
* Task statuses where logs won't change (stable/terminal states).
* "complete" is a TaskState (sub-state of active), checked separately.
*/
const STABLE_STATUSES: readonly TaskStatus[] = ["error", "paused"];
/** Whether a task is in a stable state where its logs won't change. */
export function isStableTask(task: Task): boolean {
return (
STABLE_STATUSES.includes(task.status) ||
(task.current_state !== null && task.current_state.state !== "working")
);
}
/** Whether the task's workspace is building (provisioner running). */
export function isBuildingWorkspace(task: Task): boolean {
const ws = task.workspace_status;
return ws === "pending" || ws === "starting";
}
/** Whether the workspace is running but the agent hasn't reached "ready" yet. */
export function isAgentStarting(task: Task): boolean {
if (task.workspace_status !== "running") {
return false;
}
const lc = task.workspace_agent_lifecycle;
return lc === "created" || lc === "starting";
}
/** Whether the task's workspace is still starting up (building or agent initializing). */
export function isWorkspaceStarting(task: Task): boolean {
return isBuildingWorkspace(task) || isAgentStarting(task);
}