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.

711 B
Raw Blame
import type { Reply } from "./scenario.ts";

/** Scripted models must discover deferred tools through the same gate as real models. */
export function withToolDiscovery(
  replies: Reply[],
  groupFor: (name: string) => { id: string } | undefined,
): Reply[] {
  return replies.flatMap((reply) => {
    const groups = [
      ...new Set(
        (reply.toolCalls ?? []).flatMap((call) => {
          const group = groupFor(call.name);
          return group ? [group.id] : [];
        }),
      ),
    ];
    if (!groups.length) return [reply];
    return [
      {
        toolCalls: [{ name: "tool_discover", arguments: { groups } }],
        delayMs: reply.delayMs ?? 0,
      },
      reply,
    ];
  });
}