Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.
TypeScript agentai-agentai-agentsai-assistantandroidautomationchatgptcoding-agentcomputer-usedesktop-appelectronllmlocal-firstmcpmulti-agentollamaopenaiprivacyself-hostedtypescript
import { abortable } from "../../core/abort.ts";
import type { ChatRun } from "./chat-run.ts";
/**
* Abort the agent session and wait for the run to end. Callers decide what a failure means: a
* session that will not stop leaves the Bot busy, so this never swallows the error or the timeout.
*/
export async function stopSession(
run: Pick<ChatRun, "session" | "aborting" | "finished">,
ms = 5_000,
): Promise<void> {
if (run.session) {
run.aborting ??= run.session.abort();
await abortable(run.aborting, AbortSignal.timeout(ms));
}
await abortable(run.finished, AbortSignal.timeout(ms));
}