157 lines
4.1 KiB
TypeScript
157 lines
4.1 KiB
TypeScript
import type {
|
|
PluginAgentSnapshot,
|
|
PluginTheme,
|
|
PluginWorkspaceSnapshot,
|
|
WorkspaceIndicator,
|
|
} from "@getpaseo/plugin";
|
|
import type { PluginHostSummary } from "@getpaseo/plugin/client";
|
|
|
|
export function isWorkspaceActive(workspace: PluginWorkspaceSnapshot): boolean {
|
|
return (
|
|
workspace.indicator === "running" ||
|
|
workspace.indicator === "needs_input" ||
|
|
workspace.indicator === "attention" ||
|
|
workspace.indicator === "failed"
|
|
);
|
|
}
|
|
|
|
export function compareWorkspaces(
|
|
left: PluginWorkspaceSnapshot,
|
|
right: PluginWorkspaceSnapshot,
|
|
): number {
|
|
const leftPinned = left.pinnedAt !== null;
|
|
const rightPinned = right.pinnedAt !== null;
|
|
if (leftPinned !== rightPinned) {
|
|
return leftPinned ? -1 : 1;
|
|
}
|
|
if (leftPinned && rightPinned && left.pinnedAt !== right.pinnedAt) {
|
|
return (right.pinnedAt ?? "").localeCompare(left.pinnedAt ?? "");
|
|
}
|
|
|
|
const leftTime = left.lastPromptAt ?? left.createdAt ?? "";
|
|
const rightTime = right.lastPromptAt ?? right.createdAt ?? "";
|
|
if (leftTime !== rightTime) {
|
|
return rightTime.localeCompare(leftTime);
|
|
}
|
|
|
|
const leftLabel = left.title ?? left.name;
|
|
const rightLabel = right.title ?? right.name;
|
|
return leftLabel.localeCompare(rightLabel);
|
|
}
|
|
|
|
export function compareAgents(
|
|
left: PluginAgentSnapshot,
|
|
right: PluginAgentSnapshot,
|
|
): number {
|
|
const leftPriority = agentPriority(left);
|
|
const rightPriority = agentPriority(right);
|
|
if (leftPriority !== rightPriority) {
|
|
return leftPriority - rightPriority;
|
|
}
|
|
if (left.lastActivityAt !== right.lastActivityAt) {
|
|
return right.lastActivityAt.localeCompare(left.lastActivityAt);
|
|
}
|
|
return left.createdAt.localeCompare(right.createdAt);
|
|
}
|
|
|
|
function agentPriority(agent: PluginAgentSnapshot): number {
|
|
if (agent.requiresAttention) return 0;
|
|
if (agent.status === "running" || agent.status === "initializing") return 1;
|
|
if (agent.status === "error") return 2;
|
|
if (agent.status === "idle") return 3;
|
|
return 4;
|
|
}
|
|
|
|
export function getHostStatusColor(
|
|
status: PluginHostSummary["status"],
|
|
theme: PluginTheme,
|
|
): string {
|
|
switch (status) {
|
|
case "online":
|
|
return theme.colors.statusSuccess;
|
|
case "connecting":
|
|
return theme.colors.statusWarning;
|
|
case "error":
|
|
return theme.colors.statusDanger;
|
|
case "offline":
|
|
case "idle":
|
|
return theme.colors.foregroundMuted;
|
|
}
|
|
}
|
|
|
|
export function getHostStatusLabel(
|
|
status: PluginHostSummary["status"],
|
|
): string | null {
|
|
switch (status) {
|
|
case "online":
|
|
return null;
|
|
case "connecting":
|
|
return "Connecting";
|
|
case "offline":
|
|
return "Offline";
|
|
case "error":
|
|
return "Error";
|
|
case "idle":
|
|
return "Idle";
|
|
}
|
|
}
|
|
|
|
export function getWorkspaceIndicatorColor(
|
|
indicator: WorkspaceIndicator,
|
|
theme: PluginTheme,
|
|
): string | null {
|
|
switch (indicator) {
|
|
case "needs_input":
|
|
return theme.colors.statusWarning;
|
|
case "failed":
|
|
return theme.colors.statusDanger;
|
|
case "running":
|
|
return theme.colors.statusSuccess;
|
|
case "attention":
|
|
return theme.colors.accent;
|
|
case "done":
|
|
return null;
|
|
}
|
|
}
|
|
|
|
export function getAgentStatusColor(
|
|
agent: PluginAgentSnapshot,
|
|
theme: PluginTheme,
|
|
): string {
|
|
if (agent.requiresAttention) {
|
|
return agent.attentionReason === "error"
|
|
? theme.colors.statusDanger
|
|
: theme.colors.statusWarning;
|
|
}
|
|
switch (agent.status) {
|
|
case "running":
|
|
case "initializing":
|
|
return theme.colors.statusSuccess;
|
|
case "error":
|
|
return theme.colors.statusDanger;
|
|
case "idle":
|
|
case "closed":
|
|
return theme.colors.foregroundMuted;
|
|
}
|
|
}
|
|
|
|
export function getAgentSubtitle(agent: PluginAgentSnapshot): string {
|
|
if (agent.requiresAttention && agent.attentionReason) {
|
|
switch (agent.attentionReason) {
|
|
case "permission":
|
|
return "Needs permission";
|
|
case "error":
|
|
return "Error";
|
|
case "finished":
|
|
return "Finished";
|
|
}
|
|
}
|
|
if (agent.status === "running") {
|
|
return agent.model ? `${agent.provider} · ${agent.model}` : `${agent.provider} · Running`;
|
|
}
|
|
if (agent.status === "initializing") {
|
|
return "Starting";
|
|
}
|
|
return agent.model ?? agent.provider;
|
|
}
|