Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions src/bundled/pi/index.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// @vitest-environment jsdom
import { expect, it, vi } from "vitest";
import { appliedType } from "../../features/agents/plugin-testing";
import * as pi from "./index";

vi.mock("@tauri-apps/api/core", () => ({ isTauri: () => true }));

it("shows the Pi type's screens from the runtime its agent entry registers", () => {
// The UI needs no host; only the runtime starts Pi.
expect(pi.inject).toEqual(["agents"]);
expect(pi.agent.inject).toEqual(["agents", "host"]);
const type = appliedType(pi, {
pluginOwner: { id: "buzz.pi", revision: "r1" },
host: { request: vi.fn() },
agents: { relay: () => undefined },
effect: vi.fn(),
});
expect(type).toMatchObject({ id: "pi", title: "Pi", timeoutMs: 120_000 });
expect(type?.Create).toBeTypeOf("function");
expect(type?.CreateModel).toBeTypeOf("function");
expect(type?.icon).toBeDefined();
expect(type?.tabs?.map((tab) => tab.id)).toEqual(["settings", "activity"]);
});
63 changes: 39 additions & 24 deletions src/bundled/pi/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,45 @@ export const TYPE_ID = "pi";
* which includes the first install of Pi's packages. */
const HANDOVER_MS = 2 * 60_000;

export const inject = ["agents", "host"];
/** What the type's UI reaches of its runtime. */
type PiExposed = Parameters<typeof createTabs>[0];

export const inject = ["agents"];
export const apply: PluginModule["apply"] = (ctx) => {
// Only the desktop app can start the Pi host; no unusable type elsewhere.
if (!isTauri()) return;
ctx.agents.present<PiExposed, Config>(TYPE_ID, (exposed) => {
const { ActivityTab, Create, CreateModel, SettingsTab } =
createTabs(exposed);
return {
icon: PiLogoIcon,
Create,
CreateModel,
tabs: [
{
id: "settings",
title: "Settings",
role: "settings",
splitSettings: true,
component: SettingsTab,
},
{
id: "activity",
title: "Activity",
role: "activity",
component: ActivityTab,
},
],
};
});
};

// The runtime, which runs where the agents do.
export const agent: NonNullable<PluginModule["agent"]> = {
inject: ["agents", "host"],
apply: (ctx) => applyAgent(ctx),
};
function applyAgent(ctx: Parameters<PluginModule["apply"]>[0]) {
if (!isTauri()) return;
const { agents, host } = ctx;
const typeKey = `${ctx.pluginOwner?.id ?? "buzz.pi"}/${TYPE_ID}`;
Expand All @@ -30,10 +66,6 @@ export const apply: PluginModule["apply"] = (ctx) => {
repositoriesContext,
(key) => agents.handle(key),
);
const { ActivityTab, Create, CreateModel, SettingsTab } = createTabs({
setup: runtime.setup,
runtime,
});
const sync = () => {
const snapshot = agents.snapshot();
if (snapshot.status === "loading") return;
Expand All @@ -51,12 +83,10 @@ export const apply: PluginModule["apply"] = (ctx) => {
agents.register<Config>({
id: TYPE_ID,
title: "Pi",
icon: PiLogoIcon,
description:
"Pi on this computer, with any provider Pi supports. Each thread it is mentioned in is one continuing conversation.",
defaults: () => ({ config: DEFAULT_CONFIG }),
Create,
CreateModel,
expose: { setup: runtime.setup, runtime } satisfies PiExposed,
adopt: (carry, saved) => ({
...saved,
instructions: carry.instructions ?? saved.instructions,
Expand All @@ -81,21 +111,6 @@ export const apply: PluginModule["apply"] = (ctx) => {
list: (key) => runtime.sessions(key),
subscribe: (listener) => runtime.subscribe(listener),
},
tabs: [
{
id: "settings",
title: "Settings",
role: "settings",
splitSettings: true,
component: SettingsTab,
},
{
id: "activity",
title: "Activity",
role: "activity",
component: ActivityTab,
},
],
sessionControls: {
scope: (agent) => config(agent.config).scope,
state: (agent, place) => runtime.sessionState(agent, place),
Expand All @@ -107,4 +122,4 @@ export const apply: PluginModule["apply"] = (ctx) => {
runOnce: (turn) => runtime.runOnce(turn),
timeoutMs: HANDOVER_MS,
});
};
}
2 changes: 1 addition & 1 deletion src/bundled/pi/tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ export function createTabs({
setup,
runtime,
}: Readonly<{
setup: PiSetup;
setup: Pick<PiSetup, "providers" | "models" | "login" | "test">;
runtime: Pick<PiRuntime, "places" | "working" | "transcript" | "subscribe">;
}>) {
/** The provider, its key and its model, and a test that they answer. As
Expand Down
Loading