mirror of
https://github.com/getpaseo/paseo.git
synced 2026-11-23 08:45:14 +00:00
Compare commits
2
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
cf1fed7b67 | ||
|
|
7317ee1c7f |
@@ -1325,7 +1325,6 @@ export class PiRpcAgentSession implements AgentSession {
|
||||
if (this.closed) throw new Error("Pi session is closed");
|
||||
if (this.activeTurnId !== turnId) return { turnId };
|
||||
this.activeNoTurnPromptText = payload.text;
|
||||
const shouldProbeForNoTurnPrompt = this.parseSlashCommandInput(payload.text) !== null;
|
||||
|
||||
void (async () => {
|
||||
try {
|
||||
@@ -1351,7 +1350,11 @@ export class PiRpcAgentSession implements AgentSession {
|
||||
await this.completeNoTurnPrompt(turnId);
|
||||
return;
|
||||
}
|
||||
if (agentInvoked === undefined && shouldProbeForNoTurnPrompt) {
|
||||
// Pi can acknowledge a prompt as handled even when the extension starts a run.
|
||||
if (
|
||||
agentInvoked === undefined &&
|
||||
(ack.handledByExtension || this.parseSlashCommandInput(payload.text) !== null)
|
||||
) {
|
||||
await this.completePromptIfHandledWithoutTurn(turnId);
|
||||
}
|
||||
} catch (error) {
|
||||
|
||||
@@ -3,9 +3,11 @@ import path from "node:path";
|
||||
import type { ChildProcessWithoutNullStreams } from "node:child_process";
|
||||
import { EventEmitter } from "node:events";
|
||||
import { PassThrough } from "node:stream";
|
||||
import { setImmediate as waitForImmediate } from "node:timers/promises";
|
||||
import pino from "pino";
|
||||
import { describe, expect, test, vi } from "vitest";
|
||||
import { describe, expect, onTestFinished, test, vi } from "vitest";
|
||||
|
||||
import { PiRpcAgentClient } from "./agent.js";
|
||||
import { PiCliRuntime } from "./cli-runtime.js";
|
||||
import type { PiRuntimeLaunch } from "./runtime.js";
|
||||
|
||||
@@ -417,6 +419,97 @@ describe("PiCliRuntime", () => {
|
||||
expect(command.images).toBeUndefined();
|
||||
});
|
||||
|
||||
test.each([
|
||||
{ disposition: "started", agentInvoked: true },
|
||||
{ disposition: "queued", agentInvoked: true },
|
||||
])(
|
||||
"maps a $disposition prompt disposition to agentInvoked $agentInvoked",
|
||||
async ({ disposition, agentInvoked }) => {
|
||||
const child = createPiChild();
|
||||
replyToCommands(child, (command) => (command.type === "prompt" ? { disposition } : {}));
|
||||
const session = await createRuntime(child).startSession({ cwd: "/workspace/project" });
|
||||
|
||||
await expect(session.prompt("summarize README.md")).resolves.toMatchObject({ agentInvoked });
|
||||
},
|
||||
);
|
||||
|
||||
test("preserves an explicit agentInvoked result in a prompt response", async () => {
|
||||
const child = createPiChild();
|
||||
replyToCommands(child, () => ({ disposition: "started", agentInvoked: false }));
|
||||
const session = await createRuntime(child).startSession({ cwd: "/workspace/project" });
|
||||
|
||||
await expect(session.prompt("hello")).resolves.toEqual({
|
||||
requestId: expect.any(String),
|
||||
agentInvoked: false,
|
||||
});
|
||||
});
|
||||
|
||||
test("completes when an input extension handles a prompt without a model run", async () => {
|
||||
const child = createPiChild();
|
||||
replyToCommands(child, (command) => {
|
||||
if (command.type === "prompt") {
|
||||
const notification = {
|
||||
type: "extension_ui_request",
|
||||
id: "handled",
|
||||
method: "notify",
|
||||
message: "Handled by extension",
|
||||
};
|
||||
child.stdout.write(`${JSON.stringify(notification)}\n`);
|
||||
return { disposition: "handled" };
|
||||
}
|
||||
return { sessionId: "pi-session-1", isStreaming: false };
|
||||
});
|
||||
const client = new PiRpcAgentClient({
|
||||
logger: pino({ level: "silent" }),
|
||||
runtime: createRuntime(child),
|
||||
});
|
||||
const session = await client.createSession({ provider: "pi", cwd: "/workspace/project" });
|
||||
onTestFinished(() => session.close());
|
||||
|
||||
await expect(session.run("hello")).resolves.toMatchObject({
|
||||
timeline: expect.arrayContaining([
|
||||
expect.objectContaining({ type: "notification", message: "Handled by extension" }),
|
||||
]),
|
||||
});
|
||||
});
|
||||
|
||||
test("waits for the reply when a handled slash command starts a model run", async () => {
|
||||
const child = createPiChild();
|
||||
let isStreaming = false;
|
||||
replyToCommands(child, (command) => {
|
||||
if (command.type === "prompt") {
|
||||
isStreaming = true;
|
||||
return { disposition: "handled" };
|
||||
}
|
||||
return { sessionId: "pi-session-1", isStreaming };
|
||||
});
|
||||
const client = new PiRpcAgentClient({
|
||||
logger: pino({ level: "silent" }),
|
||||
runtime: createRuntime(child),
|
||||
});
|
||||
const session = await client.createSession({ provider: "pi", cwd: "/workspace/project" });
|
||||
onTestFinished(() => session.close());
|
||||
|
||||
const reply = session.run("/ask hello");
|
||||
// Pi acknowledges the command while its model run is starting, before agent_start.
|
||||
await waitForImmediate();
|
||||
await waitForImmediate();
|
||||
child.stdout.write(`${JSON.stringify({ type: "agent_start" })}\n`);
|
||||
const message = { role: "assistant", content: [{ type: "text", text: "Hello" }] };
|
||||
const update = {
|
||||
type: "message_update",
|
||||
message,
|
||||
assistantMessageEvent: { type: "text_delta", delta: "Hello" },
|
||||
};
|
||||
child.stdout.write(`${JSON.stringify(update)}\n`);
|
||||
child.stdout.write(
|
||||
`${JSON.stringify({ type: "agent_end", messages: [message], willRetry: false })}\n`,
|
||||
);
|
||||
child.stdout.write(`${JSON.stringify({ type: "agent_settled" })}\n`);
|
||||
|
||||
await expect(reply).resolves.toMatchObject({ finalText: "Hello" });
|
||||
});
|
||||
|
||||
test("sends the clear_queue RPC frame", async () => {
|
||||
const child = createPiChild();
|
||||
replyToCommands(child, () => ({}));
|
||||
|
||||
@@ -130,10 +130,16 @@ class PiCliRuntimeSession implements PiRuntimeSession {
|
||||
});
|
||||
const data = await promise;
|
||||
if (typeof data === "object" && data !== null && !Array.isArray(data)) {
|
||||
const { agentInvoked } = data as Record<string, unknown>;
|
||||
const { agentInvoked, disposition } = data as Record<string, unknown>;
|
||||
if (typeof agentInvoked === "boolean") {
|
||||
return { requestId, agentInvoked };
|
||||
}
|
||||
if (disposition === "handled") {
|
||||
return { requestId, handledByExtension: true };
|
||||
}
|
||||
if (disposition === "started" || disposition === "queued") {
|
||||
return { requestId, agentInvoked: true };
|
||||
}
|
||||
}
|
||||
return { requestId };
|
||||
}
|
||||
|
||||
@@ -5,13 +5,10 @@ export interface PiImageContent {
|
||||
data: string;
|
||||
mimeType: string;
|
||||
}
|
||||
export interface PiPromptAck {
|
||||
agentInvoked?: boolean;
|
||||
}
|
||||
|
||||
export interface PiPromptAck {
|
||||
requestId?: string;
|
||||
agentInvoked?: boolean;
|
||||
handledByExtension?: true;
|
||||
}
|
||||
|
||||
export interface PiTextContent {
|
||||
|
||||
Reference in New Issue
Block a user