Skip to content

armgit / pibot

Public Imported from GitHub
0

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.

836 B
Raw Blame
import type { MethodResults, RoutineHistoryView } from "@pibot/protocol";
import type { Peer } from "@pibot/renderer-kit";
import { routineRunTarget } from "@pibot/routines/ui";

export function locateRoutineRun(peer: Peer, run: RoutineHistoryView, signal: AbortSignal) {
  if (!run.triggerMessageId || run.taskDeleted) throw new Error("Run target unavailable");
  // Reject a deletion after the history snapshot without changing other callers' topic rules.
  const currentPeer: Peer = {
    ...peer,
    call: async (method, params, options) => {
      const result = await peer.call(method, params, options);
      if (method === "routines.get" && (result as MethodResults["routines.get"]).deletedAt)
        throw new Error("Run task deleted");
      return result;
    },
  };
  return routineRunTarget(currentPeer, run, signal);
}