A desktop coding agent with free access to frontier models.
TypeScript
// Shared pure helpers for the workspace-scoped routes (session-route,
// settings-route). These were duplicated in both route files and had drifted:
// settings-route was missing the remote-workspace clobber fix in
// mergeRouteWorkspaces and used older session-status logic. One copy now.
import type { Session } from "@opencode-ai/sdk/v2/client";
import { unwrap } from "@/app/lib/opencode";
import { createClientV2, mapV2Session } from "@/app/lib/opencode-v2-adapter";
import { deleteNativeSession, unwrapNativeSessionResult } from "@/app/lib/opencode-session-native";
import { OmniRushServerError, type OmniRushWorkspaceInfo } from "@/app/lib/omnirush-server";
import type { ResolvedWorkspaceEndpoint } from "@/app/lib/workspace-endpoint";
import type { WorkspaceInfo } from "@/app/lib/desktop-types";
import type { WorkspaceSessionGroup } from "@/app/types";
import {
normalizeDirectoryPath,
normalizeSessionStatus,
safeStringify,
} from "@/app/utils";
import { t } from "@/i18n";
export type RouteWorkspace = OmniRushWorkspaceInfo & {
displayNameResolved: string;
};
/**
* Sessions as the routes handle them: native SDK sessions, optionally enriched with run-status
* fields that the sidebar probes defensively via getSessionStatus.
*/
export type RouteSession = Session & {
status?: unknown;
state?: unknown;
runStatus?: unknown;
slug?: string | null;
};
type RouteSessionListResult =
| { data: RouteSession[]; error?: undefined; request: Request; response: Response }
// No response when fetch itself rejected (server down, transport timeout).
| { data?: undefined; error: unknown; request: Request; response?: Response };
export type RouteSessionListTransport = (input: {
endpoint: ResolvedWorkspaceEndpoint;
limit: number;
/** The workspace folder, for a list that is not scoped to it yet. */
directory?: string;
}) => Promise<RouteSessionListResult>;
const nativeRouteSessionList: RouteSessionListTransport = async ({ endpoint, limit }) => {
const client = createClientV2(endpoint.opencodeBaseUrl, undefined, { token: endpoint.token });
// The engine's /session list only returns sessions filed under the folder's
// current project id, which changes when an agent turns the folder into a
// git repo or adds a remote, and it matches the folder byte for byte. The
// local server's by-folder list has every session of the folder, so both
// are merged; a server without it (older or remote) answers 404.
const [byProject, byFolder] = await Promise.all([
client.session.list({ limit }),
endpoint.isRemote
? Promise.resolve(null)
: endpoint.client.listWorkspaceSessionsByFolder(endpoint.workspaceId, limit).catch(() => null),
]);
return mergeRouteSessionLists(byProject, byFolder as RouteSession[] | null, limit);
};
/**
* One list from the engine's session list and the folder's sessions: every
* session once, most recently updated first, at most `limit`. The result fails
* only when neither list answered.
*/
export function mergeRouteSessionLists(
byProject: RouteSessionListResult,
byFolder: RouteSession[] | null,
limit: number,
): RouteSessionListResult {
if (!Array.isArray(byFolder)) return byProject;
const listed = Array.isArray(byProject.data) ? byProject.data : [];
if (!Array.isArray(byProject.data) && byFolder.length === 0) return byProject;
const seen = new Set<string>();
const merged: RouteSession[] = [];
for (const session of [...listed, ...byFolder]) {
if (!session?.id || seen.has(session.id)) continue;
seen.add(session.id);
merged.push(session);
}
merged.sort((a, b) => (b.time?.updated ?? 0) - (a.time?.updated ?? 0));
return { data: merged.slice(0, limit), request: byProject.request, response: byProject.response ?? new Response(null, { status: 200 }) };
}
/**
* The 2.x engine's chats of this folder: its list (every folder, newest first)
* kept to the folder, merged with the local server's by-folder list, which
* also matches the folder by real path and scans further back.
*/
export const v2RouteSessionList: RouteSessionListTransport = async ({ endpoint, limit, directory }) => {
const [listed, byFolder] = await Promise.all([
createClientV2(`${endpoint.mountedBaseUrl}/opencode2`, undefined, { token: endpoint.token }).session.list({ limit }),
endpoint.isRemote
? Promise.resolve(null)
: endpoint.client.listWorkspaceSessionsByFolder(endpoint.workspaceId, limit, "v2").catch(() => null),
]);
const root = normalizeDirectoryPath(directory ?? "");
const scoped: RouteSessionListResult = root && listed.data
? { data: listed.data.filter((session) => normalizeDirectoryPath(session?.directory ?? "") === root), request: listed.request, response: listed.response }
: listed as RouteSessionListResult;
const folder = Array.isArray(byFolder)
? byFolder.flatMap((item) => mapV2Session(item, directory) ?? []) as RouteSession[]
: null;
return mergeRouteSessionLists(scoped, folder, limit);
};
/** Resolve the owning server's engine even when this workspace isn't selected. */
async function routeSessionEndpoint(endpoint: ResolvedWorkspaceEndpoint): Promise<ResolvedWorkspaceEndpoint> {
const status = await endpoint.client.getEngineV2PreviewStatus().catch((error: unknown) => {
// Servers predating the preview endpoint still use v1.
if (error instanceof OmniRushServerError && error.status === 404) return null;
throw error;
});
return status?.enabled && status.chatRouting
? { ...endpoint, opencodeBaseUrl: `${endpoint.mountedBaseUrl}/opencode2` }
: endpoint;
}
export async function createRouteSession(endpoint: ResolvedWorkspaceEndpoint, directory?: string): Promise<Session> {
const native = await routeSessionEndpoint(endpoint);
const client = createClientV2(native.opencodeBaseUrl, directory, { token: native.token });
return unwrap(await client.session.create({ directory }));
}
const DELETE_SESSION_RETRY_DELAYS_MS = [500, 1_500, 3_000];
/**
* Delete a session so that the result is the person's intent, not one
* request's fate: a session that is already gone (a delete whose answer was
* lost, a second click, another window) counts as deleted, and a transient
* engine gap (restart, rollover, a slow instance boot) is retried. Anything
* else is thrown for the caller to show.
*/
export async function deleteRouteSession(
endpoint: ResolvedWorkspaceEndpoint,
sessionId: string,
options: { retryDelaysMs?: readonly number[] } = {},
): Promise<boolean> {
try {
return await withTransientEngineRetry({
load: async () => deleteNativeSession(await routeSessionEndpoint(endpoint), sessionId),
retryDelaysMs: options.retryDelaysMs ?? DELETE_SESSION_RETRY_DELAYS_MS,
wait: (delayMs) => new Promise<void>((resolve) => setTimeout(resolve, delayMs)),
});
} catch (error) {
if (classifyRouteSessionReadError(error) === "not-found") return true;
throw error;
}
}
/**
* Remove a workspace from the local server's registry and the desktop's list,
* or throw so the person sees why. Neither failure may be swallowed: the
* server's list is merged into the sidebar and is what the next start
* loads, so a half-removed workspace comes back. A workspace the server does
* not register (remote, or already removed) only leaves the desktop list.
*/
export async function removeRouteWorkspace(input: {
workspaceId: string;
deleteFromServer: ((workspaceId: string) => Promise<unknown>) | null;
forgetOnDesktop: ((workspaceId: string) => Promise<unknown>) | null;
/** Ends the workspace's terminal shells first: an open shell keeps its folder busy (and locked on Windows). */
closeTerminals?: ((workspaceId: string) => Promise<unknown>) | null;
}): Promise<void> {
await input.closeTerminals?.(input.workspaceId);
if (input.deleteFromServer) {
try {
await input.deleteFromServer(input.workspaceId);
} catch (error) {
if (!(error instanceof OmniRushServerError && error.status === 404)) throw error;
}
}
await input.forgetOnDesktop?.(input.workspaceId);
}
export async function listRouteSessions(
endpoint: ResolvedWorkspaceEndpoint,
transport: RouteSessionListTransport = nativeRouteSessionList,
directory?: string,
): Promise<RouteSession[]> {
return unwrapNativeSessionResult(await transport({ endpoint, limit: 200, ...(directory ? { directory } : {}) }));
}
export function mapDesktopWorkspace(workspace: WorkspaceInfo): RouteWorkspace {
return {
...workspace,
displayNameResolved:
workspace.displayName?.trim() ||
workspace.name?.trim() ||
workspace.path?.trim() ||
t("session.workspace_fallback"),
};
}
export function workspaceLabel(workspace: OmniRushWorkspaceInfo) {
const label = (
workspace.displayName?.trim() ||
workspace.omnirushWorkspaceName?.trim() ||
workspace.name?.trim() ||
workspace.path?.trim() ||
t("session.workspace_fallback")
);
return /^(?:OmniRush\.ai Chat|omnirush\.ai)$/i.test(label) ? "omnirush.ai" : label;
}
export function workspaceExportFilename(workspace: OmniRushWorkspaceInfo) {
const slug = workspaceLabel(workspace).replace(/[^A-Za-z0-9._-]+/g, "-").replace(/^-+|-+$/g, "");
return `${slug || "workspace"}-omnirush-export.json`;
}
export function downloadWorkspaceJson(filename: string, payload: unknown) {
if (typeof document === "undefined") return;
const blob = new Blob([`${JSON.stringify(payload, null, 2)}\n`], { type: "application/json" });
const url = URL.createObjectURL(blob);
const anchor = document.createElement("a");
anchor.href = url;
anchor.download = filename;
document.body.appendChild(anchor);
anchor.click();
anchor.remove();
URL.revokeObjectURL(url);
}
export function folderNameFromPath(path: string) {
const normalized = path.replace(/\\/g, "/").replace(/\/+$/, "");
const parts = normalized.split("/").filter(Boolean);
return parts[parts.length - 1] ?? "workspace";
}
export function isTransientStartupError(message: string | null | undefined) {
const value = (message ?? "").toLowerCase();
return (
value.includes("timed out") ||
value.includes("failed to fetch") ||
value.includes("connection") ||
value.includes("not ready")
);
}
export function describeRouteError(error: unknown) {
if (error instanceof Error) {
return error.message;
}
const serialized = safeStringify(error);
return serialized && serialized !== "{}" ? serialized : t("app.unknown_error");
}
export function classifyRouteSessionReadError(error: unknown): "not-found" | "retryable" | "error" {
const status = error instanceof Error && "status" in error && typeof error.status === "number"
? error.status
: null;
const code = error instanceof Error && "code" in error && typeof error.code === "string"
? error.code
: "";
if (code === "session_not_found") return "not-found";
if (
code === "opencode_unconfigured" ||
code === "opencode_engine_unreachable" ||
status === 502 ||
status === 503 ||
status === 504 ||
isTransientStartupError(describeRouteError(error))
) {
return "retryable";
}
return "error";
}
/**
* Engine calls can briefly fail while the desktop server is up but the
* workspace engine is not answering: startup, a blue/green rollover, or an
* overloaded event loop that misses the 10 s request timeout. Keep that gap
* inside a bounded retry instead of a dead-end error. Terminal authorization
* and workspace errors still fail immediately. `onRetry` fires before each
* wait with the 1-based attempt that just failed.
*/
export async function withTransientEngineRetry<T>(input: {
load: () => Promise<T>;
retryDelaysMs?: readonly number[];
wait?: (delayMs: number) => Promise<void>;
onRetry?: (attempt: number, error: unknown) => void;
}): Promise<T> {
const retryDelaysMs = input.retryDelaysMs ?? [];
const wait = input.wait ?? ((delayMs: number) => new Promise<void>((resolve) => {
window.setTimeout(resolve, delayMs);
}));
for (let attempt = 0; ; attempt += 1) {
try {
return await input.load();
} catch (error) {
const retryDelayMs = retryDelaysMs[attempt];
if (retryDelayMs === undefined || classifyRouteSessionReadError(error) !== "retryable") {
throw error;
}
input.onRetry?.(attempt + 1, error);
await wait(retryDelayMs);
}
}
}
export const readRouteSessionsWithRetry = withTransientEngineRetry;
/** Waits between reads of a routed session the engine could not answer yet; the last one repeats. */
export const ROUTE_SESSION_RETRY_DELAYS_MS: readonly number[] = [500, 1_000, 2_000, 4_000, 8_000, 15_000];
export type RouteSessionLoadOutcome<T> =
| { status: "loaded"; value: T }
| { status: "not-found" | "error"; message: string; error: unknown }
| { status: "cancelled" };
/**
* Loads the session named by the route. Transient failures (built-in server
* restarting, engine still starting, request timeout) keep retrying with
* backoff while the caller still wants the session, so a restart window never
* ends in a terminal "Session could not be loaded". A missing session and
* terminal errors (auth, bad request) resolve at once.
*/
export async function loadRouteSessionWithRetry<T>(input: {
load: () => Promise<T>;
isCancelled: () => boolean;
retryDelaysMs?: readonly number[];
/** Total attempts including the first; unbounded by default. */
maxAttempts?: number;
wait?: (delayMs: number) => Promise<void>;
}): Promise<RouteSessionLoadOutcome<T>> {
const retryDelaysMs = input.retryDelaysMs ?? ROUTE_SESSION_RETRY_DELAYS_MS;
const maxAttempts = input.maxAttempts ?? Number.POSITIVE_INFINITY;
const wait = input.wait ?? ((delayMs: number) => new Promise<void>((resolve) => {
window.setTimeout(resolve, delayMs);
}));
for (let attempt = 0; ; attempt += 1) {
if (input.isCancelled()) return { status: "cancelled" };
try {
const value = await input.load();
return input.isCancelled() ? { status: "cancelled" } : { status: "loaded", value };
} catch (error) {
if (input.isCancelled()) return { status: "cancelled" };
const kind = classifyRouteSessionReadError(error);
if (kind !== "retryable" || attempt + 1 >= maxAttempts) {
return { status: kind === "not-found" ? "not-found" : "error", message: describeRouteError(error), error };
}
const delayMs = retryDelaysMs[Math.min(attempt, retryDelaysMs.length - 1)] ?? 0;
await wait(delayMs);
}
}
}
/** Waits between task-creation attempts; each attempt itself may take the 10 s request timeout. */
export const TASK_CREATE_RETRY_DELAYS_MS: readonly number[] = [1_000, 2_000, 4_000];
export type TaskCreateFailure = {
kind: "not_responding" | "unavailable";
title: string;
description: string;
};
/**
* A stalled engine (timeouts, connection blips, 5xx from the proxy) is a
* different situation from a misconfigured or missing one: it usually comes
* back on its own or after a reload, and the person should not have to reload
* the whole app to find out.
*/
export function describeTaskCreateFailure(error: unknown, attempts: number): TaskCreateFailure {
const message = describeRouteError(error);
if (classifyRouteSessionReadError(error) === "retryable") {
return {
kind: "not_responding",
title: t("session.engine_not_responding_title"),
description: t("session.engine_not_responding_detail", { attempts: String(attempts) }),
};
}
return { kind: "unavailable", title: t("session.engine_unavailable_title"), description: message };
}
export type TaskCreateRetryNotice = { title: string; description: string };
/** Retry countdown wording; engine internals stay behind developer mode. */
export function describeTaskCreateRetry(input: {
developerMode: boolean;
attempt: number;
attempts: number;
}): TaskCreateRetryNotice {
if (input.developerMode) {
return {
title: t("session.engine_catching_up_title"),
description: t("session.engine_catching_up_detail", { attempt: input.attempt, total: input.attempts }),
};
}
return {
title: t("session.still_loading_title"),
description: t("session.still_loading_detail"),
};
}
function isRecord(value: unknown): value is Record<string, unknown> {
return typeof value === "object" && value !== null;
}
function isOmniRushWorkspaceArray(value: unknown): value is OmniRushWorkspaceInfo[] {
return Array.isArray(value);
}
function routeListActiveId(list: unknown) {
if (!isRecord(list)) return null;
return typeof list.activeId === "string" ? list.activeId.trim() || null : null;
}
export type RouteWorkspaceListState = {
activeId: string | null;
error: unknown | null;
usable: boolean;
workspaces: RouteWorkspace[];
};
export function resolveRouteWorkspaceListState(input: {
list: unknown;
desktopWorkspaces: RouteWorkspace[];
previousWorkspaces: RouteWorkspace[];
orderIds: string[];
}): RouteWorkspaceListState {
const serverItems = isRecord(input.list) && isOmniRushWorkspaceArray(input.list.items) ? input.list.items : null;
const workspaces = serverItems
? mergeRouteWorkspaces(serverItems, input.desktopWorkspaces)
: input.previousWorkspaces.length > 0
? input.previousWorkspaces
: input.desktopWorkspaces;
return {
activeId: routeListActiveId(input.list),
error: null,
usable: serverItems !== null,
workspaces: orderRouteWorkspaces(workspaces, input.orderIds),
};
}
export async function refreshRouteWorkspaceListState(input: {
load: () => Promise<unknown>;
desktopWorkspaces: RouteWorkspace[];
previousWorkspaces: RouteWorkspace[];
orderIds: string[];
/** Optional startup backoff. Route callers opt in when their local server
* can briefly accept connections before its workspace API is ready. */
retryDelaysMs?: readonly number[];
wait?: (delayMs: number) => Promise<void>;
}): Promise<RouteWorkspaceListState> {
const retryDelaysMs = input.retryDelaysMs ?? [];
const wait = input.wait ?? ((delayMs: number) => new Promise<void>((resolve) => {
window.setTimeout(resolve, delayMs);
}));
for (let attempt = 0; ; attempt += 1) {
try {
return resolveRouteWorkspaceListState({
list: await input.load(),
desktopWorkspaces: input.desktopWorkspaces,
previousWorkspaces: input.previousWorkspaces,
orderIds: input.orderIds,
});
} catch (error) {
const retryDelayMs = retryDelaysMs[attempt];
if (retryDelayMs !== undefined && isTransientStartupError(describeRouteError(error))) {
await wait(retryDelayMs);
continue;
}
const state = resolveRouteWorkspaceListState({
list: null,
desktopWorkspaces: input.desktopWorkspaces,
previousWorkspaces: input.previousWorkspaces,
orderIds: input.orderIds,
});
return { ...state, error };
}
}
}
export function describeWorkspaceCreateError(error: unknown) {
const message = describeRouteError(error);
const lower = message.toLowerCase();
if (
lower.includes("operation timed out") ||
lower.includes("os error 60") ||
lower.includes("etimedout")
) {
return `${message}\n\nOmniRush could not read the workspace config before the filesystem timed out. This often happens when the folder is still syncing from iCloud Drive or another remote folder. Wait for the folder to finish downloading, move the workspace to a local folder, or try again.`;
}
return message;
}
export function mergeRouteWorkspaces(
serverWorkspaces: unknown,
desktopWorkspaces: RouteWorkspace[],
): RouteWorkspace[] {
const serverWorkspaceList = isOmniRushWorkspaceArray(serverWorkspaces) ? serverWorkspaces : [];
const desktopById = new Map(desktopWorkspaces.map((workspace) => [workspace.id, workspace]));
const desktopByPath = new Map(
desktopWorkspaces.flatMap((workspace) => {
const path = normalizeDirectoryPath(workspace.path ?? "");
return path ? [[path, workspace] as const] : [];
}),
);
// If a server workspace's id matches a desktop workspace marked as remote,
// skip the server's view entirely. The local omnirush.ai server may have stale
// registrations from earlier (buggy) activate calls that show up here as
// `workspaceType: "local"`, which would otherwise clobber the desktop's
// remote routing fields and send workspace-scoped requests back to the
// local server.
const remoteDesktopIds = new Set(
desktopWorkspaces.flatMap((workspace) => workspace.workspaceType === "remote" ? [workspace.id] : []),
);
const filteredServer = serverWorkspaceList.filter((workspace) => !remoteDesktopIds.has(workspace.id));
const mergedServer = filteredServer.map((workspace) => {
const match =
desktopById.get(workspace.id) ??
desktopByPath.get(normalizeDirectoryPath(workspace.path ?? ""));
// For local workspaces, prefer the server's view (which knows things like
// `path` and per-workspace runtime fields) and only fall back to the
// desktop's display name when the server doesn't provide one.
const merged = match
? {
...workspace,
displayName: workspace.displayName?.trim()
? workspace.displayName
: match.displayName,
name: match.name?.trim() ? match.name : workspace.name,
}
: workspace;
return {
...merged,
displayNameResolved: workspaceLabel(merged),
};
});
const mergedIds = new Set(mergedServer.map((workspace) => workspace.id));
const mergedPaths = new Set(
mergedServer.flatMap((workspace) => {
const path = normalizeDirectoryPath(workspace.path ?? "");
return path ? [path] : [];
}),
);
const missingDesktop = desktopWorkspaces.filter((workspace) => {
if (mergedIds.has(workspace.id)) return false;
const normalizedPath = normalizeDirectoryPath(workspace.path ?? "");
if (normalizedPath && mergedPaths.has(normalizedPath)) return false;
return true;
});
return [...mergedServer, ...missingDesktop];
}
export function orderRouteWorkspaces(workspaces: RouteWorkspace[], orderIds: string[]): RouteWorkspace[] {
if (orderIds.length === 0) return workspaces;
const workspaceById = new Map(workspaces.map((workspace) => [workspace.id, workspace]));
const ordered: RouteWorkspace[] = [];
const usedIds = new Set<string>();
for (const id of orderIds) {
const workspace = workspaceById.get(id);
if (!workspace || usedIds.has(id)) continue;
ordered.push(workspace);
usedIds.add(id);
}
for (const workspace of workspaces) {
if (usedIds.has(workspace.id)) continue;
ordered.push(workspace);
}
return ordered;
}
/**
* Capture the first visible workspace order and extend it without letting the
* server's active-workspace-first list reshuffle existing sidebar entries.
* IDs that are temporarily absent stay in the preference so a transient
* discovery gap cannot move them when they return.
*/
export function stabilizeRouteWorkspaceOrder(
workspaces: RouteWorkspace[],
orderIds: string[],
): { orderIds: string[]; workspaces: RouteWorkspace[] } {
const stableOrderIds: string[] = [];
const seenIds = new Set<string>();
for (const value of orderIds) {
const id = value.trim();
if (!id || seenIds.has(id)) continue;
stableOrderIds.push(id);
seenIds.add(id);
}
for (const workspace of workspaces) {
const id = workspace.id.trim();
if (!id || seenIds.has(id)) continue;
stableOrderIds.push(id);
seenIds.add(id);
}
return {
orderIds: stableOrderIds,
workspaces: orderRouteWorkspaces(workspaces, stableOrderIds),
};
}
export function toSessionGroups(
workspaces: RouteWorkspace[],
sessionsByWorkspaceId: Record<string, RouteSession[]>,
errorsByWorkspaceId: Record<string, string | null>,
loadingWorkspaceIds: Set<string>,
listErrorsByWorkspaceId: Record<string, string | null> = {},
): WorkspaceSessionGroup[] {
return workspaces.map((workspace) => ({
workspace,
sessions: sessionsByWorkspaceId[workspace.id] ?? [],
status: loadingWorkspaceIds.has(workspace.id)
? "loading"
: errorsByWorkspaceId[workspace.id]
? "error"
: "ready",
error: errorsByWorkspaceId[workspace.id],
listError: listErrorsByWorkspaceId[workspace.id] ?? null,
}));
}
/**
* Pause before each further round of automatic session-list reloads once a
* round's own quick retries failed. The last value repeats: a workspace whose
* list cannot load keeps being retried until it loads or disappears.
*/
export const SESSION_LIST_RECOVERY_DELAYS_MS: readonly number[] = [5_000, 10_000, 20_000, 30_000, 60_000];
export function sessionListRecoveryDelayMs(round: number): number {
const delays = SESSION_LIST_RECOVERY_DELAYS_MS;
return delays[Math.min(Math.max(0, round), delays.length - 1)] ?? 60_000;
}
/**
* Sessions to show after a list load failed: never swap known sessions for an
* empty list. A list that was loaded in this window stays as it is. Otherwise
* the few sessions already present (just created, or opened from the route)
* are completed with the last saved list for the workspace.
*/
export function sessionsAfterListFailure<T extends { id: string }>(input: {
current: readonly T[] | undefined;
cached: readonly T[] | null | undefined;
currentIsListed: boolean;
}): T[] {
const current = input.current ?? [];
if (input.currentIsListed && current.length > 0) return [...current];
const currentIds = new Set(current.map((session) => session.id));
return [...current, ...(input.cached ?? []).filter((session) => !currentIds.has(session.id))];
}
/**
* Consecutive empty lists a workspace may return, while the renderer still
* knows sessions for it, before the empty list replaces them. Each recheck
* waits one step of the recovery schedule, so the known sessions stay shown
* for about two minutes of empty answers.
*/
export const SESSION_LIST_EMPTY_RECHECKS = 5;
/**
* An empty list that loaded fine is confirmed before it replaces sessions the
* sidebar already knows (listed earlier in this window, or saved from an
* earlier run). Until then the known sessions stay and the list is asked for
* again, instead of the group dropping to "No tasks yet".
*/
export function shouldRecheckEmptySessionList(input: {
fetchedCount: number;
knownCount: number;
recheckCount: number;
}): boolean {
return input.fetchedCount === 0 && input.knownCount > 0 && input.recheckCount < SESSION_LIST_EMPTY_RECHECKS;
}
export function isActiveSessionStatus(status: unknown) {
return status === "running" || status === "retry" || status === "busy" || status === "streaming";
}
export function getSessionStatus(session: RouteSession | null | undefined) {
const status = session?.status ?? session?.state ?? session?.runStatus ?? null;
return typeof status === "string" ? status : normalizeSessionStatus(status);
}