feat: add project-grouped agent fetch with checkout-lite placement
This commit is contained in:
@@ -151,6 +151,56 @@ describe("DaemonClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test("fetches project-grouped agents via RPC", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
const client = new DaemonClient({
|
||||
url: "ws://test",
|
||||
logger,
|
||||
reconnect: { enabled: false },
|
||||
transportFactory: () => mock.transport,
|
||||
});
|
||||
clients.push(client);
|
||||
|
||||
const connectPromise = client.connect();
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const promise = client.fetchAgentsGroupedByProject({
|
||||
filter: { labels: { ui: "true" } },
|
||||
});
|
||||
|
||||
expect(mock.sent).toHaveLength(1);
|
||||
const request = JSON.parse(mock.sent[0]) as {
|
||||
type: "session";
|
||||
message: {
|
||||
type: "fetch_agents_grouped_by_project_request";
|
||||
requestId: string;
|
||||
filter?: { labels?: Record<string, string> };
|
||||
};
|
||||
};
|
||||
expect(request.message.type).toBe("fetch_agents_grouped_by_project_request");
|
||||
|
||||
mock.triggerMessage(
|
||||
JSON.stringify({
|
||||
type: "session",
|
||||
message: {
|
||||
type: "fetch_agents_grouped_by_project_response",
|
||||
payload: {
|
||||
requestId: request.message.requestId,
|
||||
groups: [],
|
||||
},
|
||||
},
|
||||
})
|
||||
);
|
||||
|
||||
await expect(promise).resolves.toEqual({
|
||||
requestId: request.message.requestId,
|
||||
groups: [],
|
||||
});
|
||||
});
|
||||
|
||||
test("cancels waiters when send fails (no leaked timeouts)", async () => {
|
||||
vi.useFakeTimers();
|
||||
const logger = createMockLogger();
|
||||
|
||||
@@ -117,9 +117,7 @@ export type DaemonEvent =
|
||||
| {
|
||||
type: "agent_update";
|
||||
agentId: string;
|
||||
payload:
|
||||
| { kind: "upsert"; agent: AgentSnapshotPayload }
|
||||
| { kind: "remove"; agentId: string };
|
||||
payload: Extract<SessionOutboundMessage, { type: "agent_update" }>["payload"];
|
||||
}
|
||||
| {
|
||||
type: "agent_stream";
|
||||
@@ -218,6 +216,10 @@ type AgentRefreshedStatusPayload = z.infer<
|
||||
type RestartRequestedStatusPayload = z.infer<
|
||||
typeof RestartRequestedStatusPayloadSchema
|
||||
>;
|
||||
type FetchAgentsGroupedByProjectPayload = Extract<
|
||||
SessionOutboundMessage,
|
||||
{ type: "fetch_agents_grouped_by_project_response" }
|
||||
>["payload"];
|
||||
|
||||
export type WaitForFinishResult = {
|
||||
status: "idle" | "error" | "permission" | "timeout";
|
||||
@@ -854,6 +856,33 @@ export class DaemonClient {
|
||||
});
|
||||
}
|
||||
|
||||
async fetchAgentsGroupedByProject(options?: {
|
||||
filter?: { labels?: Record<string, string> };
|
||||
requestId?: string;
|
||||
}): Promise<FetchAgentsGroupedByProjectPayload> {
|
||||
const resolvedRequestId = this.createRequestId(options?.requestId);
|
||||
const message = SessionInboundMessageSchema.parse({
|
||||
type: "fetch_agents_grouped_by_project_request",
|
||||
requestId: resolvedRequestId,
|
||||
...(options?.filter ? { filter: options.filter } : {}),
|
||||
});
|
||||
return this.sendRequest({
|
||||
requestId: resolvedRequestId,
|
||||
message,
|
||||
timeout: 15000,
|
||||
options: { skipQueue: true },
|
||||
select: (msg) => {
|
||||
if (msg.type !== "fetch_agents_grouped_by_project_response") {
|
||||
return null;
|
||||
}
|
||||
if (msg.payload.requestId !== resolvedRequestId) {
|
||||
return null;
|
||||
}
|
||||
return msg.payload;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
async fetchAgent(agentId: string, requestId?: string): Promise<AgentSnapshotPayload | null> {
|
||||
const resolvedRequestId = this.createRequestId(requestId);
|
||||
const message = SessionInboundMessageSchema.parse({
|
||||
|
||||
Reference in New Issue
Block a user