Skip to content

armgit / qm

Public Imported from GitHub
0

Multiplayer agent harness for work.

1.4 KB
Raw Blame
import type { View } from "./shell-state";

interface TitledSession {
  id: string;
  threadRef: string;
}

interface ActiveConversation {
  openingKey: string | null;
  sessionId: string | null;
  threadRef: string | null;
}

export const PRODUCT_TITLE = "QM · Web";

const VIEW_TITLES: Record<View, string> = {
  chats: "Chats",
  inbox: "Inbox",
  calendar: "Calendar",
  contexts: "Projects",
  crons: "Crons",
  loops: "Loops",
  webhooks: "Webhooks",
  files: "Files",
  keychain: "Keychain",
  deploys: "Apps",
  memory: "Memory",
  skills: "Skills",
  settings: "Settings",
};

export function documentTitle(view?: View, conversationTitle?: string | null, conversationOpen = false): string {
  const title =
    view === "chats" && conversationOpen ? conversationTitle?.trim() || "New chat" : view && VIEW_TITLES[view];
  return title ? `${title} · ${PRODUCT_TITLE}` : PRODUCT_TITLE;
}

export function updateDocumentTitle(view?: View, conversationTitle?: string | null, conversationOpen = false): void {
  document.title = documentTitle(view, conversationTitle, conversationOpen);
}

export function activeSessionForDocumentTitle<T extends TitledSession>(
  sessions: T[],
  active: ActiveConversation,
): T | undefined {
  if (active.openingKey) return sessions.find((session) => session.id === active.openingKey);
  return sessions.find(
    (session) => session.id === active.sessionId || (!active.sessionId && session.threadRef === active.threadRef),
  );
}