feat: add prompt attachment support across sessions
This commit is contained in:
@@ -344,6 +344,145 @@ describe("DaemonClient", () => {
|
||||
await expect(createPromise).rejects.toThrow("compat test sentinel");
|
||||
});
|
||||
|
||||
test("sends structured attachments with create_agent_request", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
clientId: "clsk_unit_test",
|
||||
logger,
|
||||
reconnect: { enabled: false },
|
||||
transportFactory: () => mock.transport,
|
||||
});
|
||||
clients.push(client);
|
||||
|
||||
const connectPromise = client.connect();
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const createPromise = client.createAgent({
|
||||
provider: "codex",
|
||||
cwd: "/tmp/project",
|
||||
initialPrompt: "Review this PR",
|
||||
attachments: [
|
||||
{
|
||||
type: "github_pr",
|
||||
mimeType: "application/github-pr",
|
||||
number: 123,
|
||||
title: "Fix race in worktree setup",
|
||||
url: "https://github.com/getpaseo/paseo/pull/123",
|
||||
baseRefName: "main",
|
||||
headRefName: "fix/worktree-race",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.sent).toHaveLength(1);
|
||||
const request = JSON.parse(String(mock.sent[0])) as {
|
||||
type: "session";
|
||||
message: {
|
||||
type: "create_agent_request";
|
||||
requestId: string;
|
||||
attachments: Array<{ type: string; mimeType: string; number: number }>;
|
||||
};
|
||||
};
|
||||
expect(request.message.attachments).toEqual([
|
||||
{
|
||||
type: "github_pr",
|
||||
mimeType: "application/github-pr",
|
||||
number: 123,
|
||||
title: "Fix race in worktree setup",
|
||||
url: "https://github.com/getpaseo/paseo/pull/123",
|
||||
baseRefName: "main",
|
||||
headRefName: "fix/worktree-race",
|
||||
},
|
||||
]);
|
||||
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "status",
|
||||
payload: {
|
||||
status: "agent_create_failed",
|
||||
requestId: request.message.requestId,
|
||||
error: "attachment test sentinel",
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(createPromise).rejects.toThrow("attachment test sentinel");
|
||||
});
|
||||
|
||||
test("sends structured attachments with create_paseo_worktree_request", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
clientId: "clsk_unit_test",
|
||||
logger,
|
||||
reconnect: { enabled: false },
|
||||
transportFactory: () => mock.transport,
|
||||
});
|
||||
clients.push(client);
|
||||
|
||||
const connectPromise = client.connect();
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const createPromise = client.createPaseoWorktree({
|
||||
cwd: "/tmp/project",
|
||||
worktreeSlug: "review-pr-123",
|
||||
attachments: [
|
||||
{
|
||||
type: "github_pr",
|
||||
mimeType: "application/github-pr",
|
||||
number: 123,
|
||||
title: "Fix race in worktree setup",
|
||||
url: "https://github.com/getpaseo/paseo/pull/123",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(mock.sent).toHaveLength(1);
|
||||
const request = JSON.parse(String(mock.sent[0])) as {
|
||||
type: "session";
|
||||
message: {
|
||||
type: "create_paseo_worktree_request";
|
||||
requestId: string;
|
||||
attachments: Array<{ type: string; mimeType: string; number: number }>;
|
||||
};
|
||||
};
|
||||
expect(request.message.attachments).toEqual([
|
||||
{
|
||||
type: "github_pr",
|
||||
mimeType: "application/github-pr",
|
||||
number: 123,
|
||||
title: "Fix race in worktree setup",
|
||||
url: "https://github.com/getpaseo/paseo/pull/123",
|
||||
},
|
||||
]);
|
||||
|
||||
mock.triggerMessage(
|
||||
wrapSessionMessage({
|
||||
type: "create_paseo_worktree_response",
|
||||
payload: {
|
||||
requestId: request.message.requestId,
|
||||
workspace: null,
|
||||
error: "worktree attachment sentinel",
|
||||
setupTerminalId: null,
|
||||
},
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(createPromise).resolves.toEqual({
|
||||
requestId: request.message.requestId,
|
||||
workspace: null,
|
||||
error: "worktree attachment sentinel",
|
||||
setupTerminalId: null,
|
||||
});
|
||||
});
|
||||
|
||||
test("sends explicit shutdown_server_request via shutdownServer", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
@@ -16,6 +16,7 @@ import type {
|
||||
AgentSnapshotPayload,
|
||||
ProjectPlacementPayload,
|
||||
AgentPermissionResolvedMessage,
|
||||
AgentAttachment,
|
||||
CreateAgentRequestMessage,
|
||||
FileDownloadTokenResponse,
|
||||
FileExplorerResponse,
|
||||
@@ -63,6 +64,7 @@ import type {
|
||||
TerminalInput,
|
||||
SessionInboundMessage,
|
||||
SessionOutboundMessage,
|
||||
SendAgentMessageRequest,
|
||||
EditorTargetId,
|
||||
} from "../shared/messages.js";
|
||||
import type {
|
||||
@@ -198,6 +200,7 @@ export type DaemonClientConfig = {
|
||||
export type SendMessageOptions = {
|
||||
messageId?: string;
|
||||
images?: Array<{ data: string; mimeType: string }>;
|
||||
attachments?: SendAgentMessageRequest["attachments"];
|
||||
};
|
||||
|
||||
type AgentConfigOverrides = Partial<Omit<AgentSessionConfig, "provider" | "cwd">>;
|
||||
@@ -211,6 +214,7 @@ export type CreateAgentRequestOptions = {
|
||||
clientMessageId?: string;
|
||||
outputSchema?: Record<string, unknown>;
|
||||
images?: CreateAgentRequestMessage["images"];
|
||||
attachments?: CreateAgentRequestMessage["attachments"];
|
||||
git?: GitSetupOptions;
|
||||
worktreeName?: string;
|
||||
requestId?: string;
|
||||
@@ -1494,6 +1498,9 @@ export class DaemonClient {
|
||||
...(options.clientMessageId ? { clientMessageId: options.clientMessageId } : {}),
|
||||
...(options.outputSchema ? { outputSchema: options.outputSchema } : {}),
|
||||
...(options.images && options.images.length > 0 ? { images: options.images } : {}),
|
||||
...(options.attachments && options.attachments.length > 0
|
||||
? { attachments: options.attachments }
|
||||
: {}),
|
||||
...(options.git ? { git: options.git } : {}),
|
||||
...(options.worktreeName ? { worktreeName: options.worktreeName } : {}),
|
||||
...(options.labels && Object.keys(options.labels).length > 0
|
||||
@@ -1723,6 +1730,7 @@ export class DaemonClient {
|
||||
text,
|
||||
...(messageId ? { messageId } : {}),
|
||||
...(options?.images ? { images: options.images } : {}),
|
||||
...(options?.attachments ? { attachments: options.attachments } : {}),
|
||||
});
|
||||
const payload = await this.sendRequest({
|
||||
requestId,
|
||||
@@ -2544,7 +2552,11 @@ export class DaemonClient {
|
||||
}
|
||||
|
||||
async createPaseoWorktree(
|
||||
input: { cwd: string; worktreeSlug?: string },
|
||||
input: {
|
||||
cwd: string;
|
||||
worktreeSlug?: string;
|
||||
attachments?: AgentAttachment[];
|
||||
},
|
||||
requestId?: string,
|
||||
): Promise<CreatePaseoWorktreePayload> {
|
||||
return this.sendCorrelatedSessionRequest({
|
||||
@@ -2553,6 +2565,9 @@ export class DaemonClient {
|
||||
type: "create_paseo_worktree_request",
|
||||
cwd: input.cwd,
|
||||
worktreeSlug: input.worktreeSlug,
|
||||
...(input.attachments && input.attachments.length > 0
|
||||
? { attachments: input.attachments }
|
||||
: {}),
|
||||
},
|
||||
responseType: "create_paseo_worktree_response",
|
||||
timeout: 60000,
|
||||
|
||||
Reference in New Issue
Block a user