Linger is An Open-Source Personal Agent That Runs Fully on Your PC. We aim to break Big Tech’s grip on AI by bringing powerful local AI to everyday computers through efficient model–harness co-design, so everyone can run their own.
feat(web): open a background Task's conversation and cancel it there
LeoXing34b6d81f26f6
diff --git a/apps/web/src/features/rooms/chat/background-tasks-indicator.tsx b/apps/web/src/features/rooms/chat/background-tasks-indicator.tsxindex 7608809e..29263fc9 100644--- a/apps/web/src/features/rooms/chat/background-tasks-indicator.tsx+++ b/apps/web/src/features/rooms/chat/background-tasks-indicator.tsx@@ -1,22 +1,21 @@import { ArrowUp01Icon } from "@hugeicons/core-free-icons";-import { useQueryClient } from "@tanstack/react-query";import { useEffect, useId, useRef, useState } from "react";-import { Button } from "@/components/ui/button";import { Icon } from "@/components/ui/icon";import { cn } from "@/lib/cn";-import { teamHubData } from "@/features/teamhub/teamhub-api";import type { TeamHubClient } from "@/features/teamhub/teamhub-client";import type { TeamHubRoomBackgroundTask } from "@/features/teamhub/teamhub-types";+import { TaskConversationDialog } from "../task-sidebar/adapters/task-conversation-dialog";+import { CancelTaskButton } from "./cancel-task-button";import {- roomBackgroundTasksQueryKey,+ useCancelRoomBackgroundTask,useRoomBackgroundTasks,} from "./use-room-background-tasks";/*** One floating line above the composer while this Room's Meta has background* Tasks running. It opens a short list of what each one is doing, where- * each can be canceled, and disappears once every Task is done.+ * each can be opened or canceled, and disappears once every Task is done.*/export function BackgroundTasksIndicator({client,@@ -27,35 +26,46 @@ export function BackgroundTasksIndicator({roomId: string;tenantId: string;}) {- const queryClient = useQueryClient();const tasks = useRoomBackgroundTasks({ client, roomId, tenantId });- if (!tasks.length) return null;- const cancel = async (taskId: string) => {- await teamHubData(- client.api.POST("/v0/rooms/{roomId}/background-tasks/{taskId}/cancel", {- params: { path: { roomId, taskId } },- }),- );- await queryClient.invalidateQueries({- queryKey: roomBackgroundTasksQueryKey(tenantId, roomId),- });- };+ const cancel = useCancelRoomBackgroundTask({ client, roomId, tenantId });+ // The opened Task stays open after it finishes and leaves the list.+ const [opened, setOpened] = useState<TeamHubRoomBackgroundTask>();return (- // Floats over the bottom of the timeline instead of pushing the composer.- <div className="relative h-0">- <BackgroundTasksPill onCancel={cancel} tasks={tasks} />- </div>+ <>+ {tasks.length ? (+ // Floats over the bottom of the timeline instead of pushing the composer.+ <div className="relative h-0">+ <BackgroundTasksPill+ onCancel={cancel}+ onOpen={setOpened}+ tasks={tasks}+ />+ </div>+ ) : null}+ {opened ? (+ <TaskConversationDialog+ onClose={() => setOpened(undefined)}+ originRoomId={roomId}+ taskId={opened.id}+ tenantId={tenantId}+ title={opened.title}+ />+ ) : null}+ </>);}export function BackgroundTasksPill({now = Date.now(),onCancel,+ onOpen,tasks,}: {now?: number;/** Stops one Task; it settles once the Task has left the list. */onCancel?: (taskId: string) => Promise<void>;+ /** Opens one Task's conversation. */+ onOpen?: (task: TeamHubRoomBackgroundTask) => void;tasks: readonly TeamHubRoomBackgroundTask[];}) {const [open, setOpen] = useState(false);@@ -94,30 +104,41 @@ export function BackgroundTasksPill({<ul className="flex flex-col">{tasks.map((task) => (<li- className="grid grid-cols-[6px_minmax(0,1fr)_auto_auto] items-baseline gap-x-2.5 rounded-md px-2 py-1.5 hover:bg-muted"+ className="flex items-center gap-1 rounded-md hover:bg-muted"key={task.id}>- <span- aria-hidden="true"- className="size-1.5 self-center rounded-full bg-app-link"- />- <span className="truncate text-sm leading-5 text-app-ink">- {task.title}- </span>- <span className="text-[12px] leading-[18px] text-app-muted tabular-nums">- {runningFor(task.created_at, now)}- </span>- <span className="row-span-2 self-center">- {onCancel ? (+ <button+ aria-label={`Open task ${task.title}`}+ className="grid min-w-0 flex-1 grid-cols-[6px_minmax(0,1fr)_auto] items-baseline gap-x-2.5 rounded-md py-1.5 pl-2 text-left focus-visible:outline-2 focus-visible:outline-offset-[-2px] focus-visible:outline-app-focus disabled:cursor-default"+ disabled={!onOpen}+ onClick={() => {+ setOpen(false);+ onOpen?.(task);+ }}+ type="button"+ >+ <span+ aria-hidden="true"+ className="size-1.5 self-center rounded-full bg-app-link"+ />+ <span className="truncate text-sm leading-5 text-app-ink">+ {task.title}+ </span>+ <span className="text-[12px] leading-[18px] text-app-muted tabular-nums">+ {runningFor(task.created_at, now)}+ </span>+ <span className="col-span-2 col-start-2 truncate text-[12px] leading-[18px] text-app-muted">+ {task.requirement}+ </span>+ </button>+ {onCancel ? (+ <span className="shrink-0 pr-1"><CancelTaskButtoncancel={() => onCancel(task.id)}title={task.title}/>- ) : null}- </span>- <span className="col-span-2 col-start-2 truncate text-[12px] leading-[18px] text-app-muted">- {task.requirement}- </span>+ </span>+ ) : null}</li>))}</ul>@@ -150,50 +171,6 @@ export function BackgroundTasksPill({);}-/**- * Cancels one Task's current turn. The Room's Meta is told and can resume- * it later, so no confirmation is asked.- */-function CancelTaskButton({- cancel,- title,-}: {- cancel: () => Promise<void>;- title: string;-}) {- const [state, setState] = useState<"idle" | "pending" | "error">("idle");- return (- <Button- aria-label={- state === "error"- ? `Cancel of ${title} was not confirmed; retry`- : `Cancel ${title}`- }- className={cn(- "h-7 px-1.5 text-[12px] font-medium hover:bg-transparent hover:text-app-danger",- state === "error" ? "text-app-danger" : "text-app-muted",- )}- disabled={state === "pending"}- onClick={() => {- setState("pending");- cancel().then(- () => setState("idle"),- () => setState("error"),- );- }}- size="compact"- tone="ghost"- type="button"- >- {state === "pending"- ? "Canceling"- : state === "error"- ? "Retry"- : "Cancel"}- </Button>- );-}-/** How long a Task has been running, in the coarsest unit that fits. */export function runningFor(createdAt: string, now: number) {const minutes = Math.max(diff --git a/apps/web/src/features/rooms/chat/cancel-task-button.tsx b/apps/web/src/features/rooms/chat/cancel-task-button.tsxnew file mode 100644index 00000000..3e7ea4ab--- /dev/null+++ b/apps/web/src/features/rooms/chat/cancel-task-button.tsx@@ -0,0 +1,48 @@+import { useState } from "react";++import { Button } from "@/components/ui/button";+import { cn } from "@/lib/cn";++/**+ * Cancels one Task's current turn. The Room's Meta is told and can resume+ * it later, so no confirmation is asked.+ */+export function CancelTaskButton({+ cancel,+ title,+}: {+ cancel: () => Promise<void>;+ title: string;+}) {+ const [state, setState] = useState<"idle" | "pending" | "error">("idle");+ return (+ <Button+ aria-label={+ state === "error"+ ? `Cancel of ${title} was not confirmed; retry`+ : `Cancel ${title}`+ }+ className={cn(+ "h-7 px-1.5 text-[12px] font-medium hover:bg-transparent hover:text-app-danger",+ state === "error" ? "text-app-danger" : "text-app-muted",+ )}+ disabled={state === "pending"}+ onClick={() => {+ setState("pending");+ cancel().then(+ () => setState("idle"),+ () => setState("error"),+ );+ }}+ size="compact"+ tone="ghost"+ type="button"+ >+ {state === "pending"+ ? "Canceling"+ : state === "error"+ ? "Retry"+ : "Cancel"}+ </Button>+ );+}diff --git a/apps/web/src/features/rooms/chat/use-room-background-tasks.ts b/apps/web/src/features/rooms/chat/use-room-background-tasks.tsindex 26cb9f9d..28d50fb9 100644--- a/apps/web/src/features/rooms/chat/use-room-background-tasks.ts+++ b/apps/web/src/features/rooms/chat/use-room-background-tasks.ts@@ -1,4 +1,4 @@-import { useQuery } from "@tanstack/react-query";+import { useQuery, useQueryClient } from "@tanstack/react-query";import { teamHubData } from "@/features/teamhub/teamhub-api";import type { TeamHubClient } from "@/features/teamhub/teamhub-client";import type { TeamHubRoomBackgroundTask } from "@/features/teamhub/teamhub-types";@@ -37,3 +37,29 @@ export function useRoomBackgroundTasks({});return tasks.data?.items ?? EMPTY_BACKGROUND_TASKS;}++/**+ * Cancels one of this Room's background Tasks, as its list and the Task's+ * conversation both offer. It settles once the list has refreshed.+ */+export function useCancelRoomBackgroundTask({+ client,+ roomId,+ tenantId,+}: {+ client: TeamHubClient;+ roomId: string;+ tenantId: string;+}) {+ const queryClient = useQueryClient();+ return async (taskId: string) => {+ await teamHubData(+ client.api.POST("/v0/rooms/{roomId}/background-tasks/{taskId}/cancel", {+ params: { path: { roomId, taskId } },+ }),+ );+ await queryClient.invalidateQueries({+ queryKey: roomBackgroundTasksQueryKey(tenantId, roomId),+ });+ };+}diff --git a/apps/web/src/features/rooms/task-sidebar/adapters/agent-live-activity-panel-tab.tsx b/apps/web/src/features/rooms/task-sidebar/adapters/agent-live-activity-panel-tab.tsxindex 215c8045..87387643 100644--- a/apps/web/src/features/rooms/task-sidebar/adapters/agent-live-activity-panel-tab.tsx+++ b/apps/web/src/features/rooms/task-sidebar/adapters/agent-live-activity-panel-tab.tsx@@ -65,7 +65,7 @@ export function AgentLiveActivityPanelTab({const pending = events.pending;return (- <TaskConversationProvider tenantId={tenantId}>+ <TaskConversationProvider roomId={roomId} tenantId={tenantId}><divclassName={hidden ? "hidden" : "flex h-full min-h-0 flex-col bg-card"}data-testid="agent-live-activity-panel"diff --git a/apps/web/src/features/rooms/task-sidebar/adapters/message-activities-panel-tab.tsx b/apps/web/src/features/rooms/task-sidebar/adapters/message-activities-panel-tab.tsxindex 90434642..59a793d6 100644--- a/apps/web/src/features/rooms/task-sidebar/adapters/message-activities-panel-tab.tsx+++ b/apps/web/src/features/rooms/task-sidebar/adapters/message-activities-panel-tab.tsx@@ -77,7 +77,7 @@ export function MessageActivitiesPanelTab({}, [activationKey, hidden, message.id, activities.data?.records.length]);return (- <TaskConversationProvider tenantId={tenantId}>+ <TaskConversationProvider roomId={roomId} tenantId={tenantId}><divclassName={hidden ? "hidden" : "flex h-full min-h-0 flex-col bg-card"}data-testid="message-activities-panel"diff --git a/apps/web/src/features/rooms/task-sidebar/adapters/task-conversation-dialog.tsx b/apps/web/src/features/rooms/task-sidebar/adapters/task-conversation-dialog.tsxindex 89d07088..1dbc7c59 100644--- a/apps/web/src/features/rooms/task-sidebar/adapters/task-conversation-dialog.tsx+++ b/apps/web/src/features/rooms/task-sidebar/adapters/task-conversation-dialog.tsx@@ -10,7 +10,9 @@ import type {TeamHubTaskExecution,} from "@/features/teamhub/teamhub-types";+import { CancelTaskButton } from "../../chat/cancel-task-button";import { MessageMarkdown } from "../../chat/message-markdown";+import { useCancelRoomBackgroundTask } from "../../chat/use-room-background-tasks";import { createRoomCardDecisionController } from "../../cards/room-card-decision-controller";import {knownRoomMessageCard,@@ -28,9 +30,12 @@ import { useTaskActivityView } from "./task-activities-panel-tab";/** Lets the task blocks in an activity log open their Task's conversation. */export function TaskConversationProvider({children,+ roomId,tenantId,}: {children: ReactNode;+ /** The Room whose Meta delegated these Tasks. */+ roomId: string;tenantId: string;}) {const [task, setTask] = useState<{ id: string; title: string }>();@@ -43,6 +48,7 @@ export function TaskConversationProvider({{task ? (<TaskConversationDialogonClose={() => setTask(undefined)}+ originRoomId={roomId}taskId={task.id}tenantId={tenantId}title={task.title}@@ -57,19 +63,27 @@ export function TaskConversationProvider({* on the left everything its AlterEgo thought, ran and replied, with the cards* it raised, answerable here.*/-function TaskConversationDialog({+export function TaskConversationDialog({onClose,+ originRoomId,taskId,tenantId,title,}: {onClose: () => void;+ /** The Room whose Meta delegated the Task; its members can cancel it. */+ originRoomId: string;taskId: string;tenantId: string;title: string;}) {const { client } = useTeamHubRuntime();- const { data, execution } = useTaskActivityView({+ const cancel = useCancelRoomBackgroundTask({+ client,+ roomId: originRoomId,+ tenantId,+ });+ const { data, execution, refresh } = useTaskActivityView({hidden: false,taskId,tenantId,@@ -117,7 +131,20 @@ function TaskConversationDialog({<ModalDialogcloseOnBackdropdescription={- execution ? <TaskConversationState execution={execution} /> : undefined+ execution ? (+ <span className="inline-flex items-center gap-1">+ <TaskConversationState execution={execution} />+ {live ? (+ <CancelTaskButton+ cancel={async () => {+ await cancel(taskId);+ refresh();+ }}+ title={title}+ />+ ) : null}+ </span>+ ) : undefined}onClose={onClose}size="lg"