feat: update sidebar agent workflow and host filter UI
This commit is contained in:
@@ -455,7 +455,7 @@ describe("DaemonClient", () => {
|
||||
expect(request.message.requestId.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
test("fetches project-grouped agents via RPC", async () => {
|
||||
test("fetches agents via RPC with filters, sort, and pagination", async () => {
|
||||
const logger = createMockLogger();
|
||||
const mock = createMockTransport();
|
||||
|
||||
@@ -471,29 +471,49 @@ describe("DaemonClient", () => {
|
||||
mock.triggerOpen();
|
||||
await connectPromise;
|
||||
|
||||
const promise = client.fetchAgentsGroupedByProject({
|
||||
const promise = client.fetchAgents({
|
||||
filter: { labels: { ui: "true" } },
|
||||
sort: [
|
||||
{ key: "status_priority", direction: "asc" },
|
||||
{ key: "created_at", direction: "desc" },
|
||||
],
|
||||
page: { limit: 25, cursor: "cursor-1" },
|
||||
});
|
||||
|
||||
expect(mock.sent).toHaveLength(1);
|
||||
const request = JSON.parse(mock.sent[0]) as {
|
||||
type: "session";
|
||||
message: {
|
||||
type: "fetch_agents_grouped_by_project_request";
|
||||
type: "fetch_agents_request";
|
||||
requestId: string;
|
||||
filter?: { labels?: Record<string, string> };
|
||||
sort?: Array<{
|
||||
key: "status_priority" | "created_at" | "updated_at" | "title";
|
||||
direction: "asc" | "desc";
|
||||
}>;
|
||||
page?: { limit: number; cursor?: string };
|
||||
};
|
||||
};
|
||||
expect(request.message.type).toBe("fetch_agents_grouped_by_project_request");
|
||||
expect(request.message.type).toBe("fetch_agents_request");
|
||||
expect(request.message.sort).toEqual([
|
||||
{ key: "status_priority", direction: "asc" },
|
||||
{ key: "created_at", direction: "desc" },
|
||||
]);
|
||||
expect(request.message.page).toEqual({ limit: 25, cursor: "cursor-1" });
|
||||
|
||||
mock.triggerMessage(
|
||||
JSON.stringify({
|
||||
type: "session",
|
||||
message: {
|
||||
type: "fetch_agents_grouped_by_project_response",
|
||||
type: "fetch_agents_response",
|
||||
payload: {
|
||||
requestId: request.message.requestId,
|
||||
groups: [],
|
||||
entries: [],
|
||||
pageInfo: {
|
||||
nextCursor: null,
|
||||
prevCursor: "cursor-1",
|
||||
hasMore: false,
|
||||
},
|
||||
},
|
||||
},
|
||||
})
|
||||
@@ -501,7 +521,12 @@ describe("DaemonClient", () => {
|
||||
|
||||
await expect(promise).resolves.toEqual({
|
||||
requestId: request.message.requestId,
|
||||
groups: [],
|
||||
entries: [],
|
||||
pageInfo: {
|
||||
nextCursor: null,
|
||||
prevCursor: "cursor-1",
|
||||
hasMore: false,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@@ -244,10 +244,19 @@ type AgentRefreshedStatusPayload = z.infer<
|
||||
type RestartRequestedStatusPayload = z.infer<
|
||||
typeof RestartRequestedStatusPayloadSchema
|
||||
>;
|
||||
type FetchAgentsGroupedByProjectPayload = Extract<
|
||||
type FetchAgentsPayload = Extract<
|
||||
SessionOutboundMessage,
|
||||
{ type: "fetch_agents_grouped_by_project_response" }
|
||||
{ type: "fetch_agents_response" }
|
||||
>["payload"];
|
||||
type FetchAgentsRequest = Extract<
|
||||
SessionInboundMessage,
|
||||
{ type: "fetch_agents_request" }
|
||||
>;
|
||||
export type FetchAgentsOptions = Omit<FetchAgentsRequest, "type" | "requestId"> & {
|
||||
requestId?: string;
|
||||
};
|
||||
export type FetchAgentsEntry = FetchAgentsPayload["entries"][number];
|
||||
export type FetchAgentsPageInfo = FetchAgentsPayload["pageInfo"];
|
||||
|
||||
export type WaitForFinishResult = {
|
||||
status: "idle" | "error" | "permission" | "timeout";
|
||||
@@ -976,15 +985,14 @@ export class DaemonClient {
|
||||
// Agent RPCs (requestId-correlated)
|
||||
// ============================================================================
|
||||
|
||||
async fetchAgents(options?: {
|
||||
filter?: { labels?: Record<string, string> };
|
||||
requestId?: string;
|
||||
}): Promise<AgentSnapshotPayload[]> {
|
||||
async fetchAgents(options?: FetchAgentsOptions): Promise<FetchAgentsPayload> {
|
||||
const resolvedRequestId = this.createRequestId(options?.requestId);
|
||||
const message = SessionInboundMessageSchema.parse({
|
||||
type: "fetch_agents_request",
|
||||
requestId: resolvedRequestId,
|
||||
...(options?.filter ? { filter: options.filter } : {}),
|
||||
...(options?.sort ? { sort: options.sort } : {}),
|
||||
...(options?.page ? { page: options.page } : {}),
|
||||
});
|
||||
return this.sendRequest({
|
||||
requestId: resolvedRequestId,
|
||||
@@ -998,33 +1006,6 @@ export class DaemonClient {
|
||||
if (msg.payload.requestId !== resolvedRequestId) {
|
||||
return null;
|
||||
}
|
||||
return msg.payload.agents;
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
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;
|
||||
},
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user