Skip to content
Merged
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
7 changes: 6 additions & 1 deletion apps/web/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,16 @@ type Validator<T> = (data: unknown) => T | ArkErrors;
* call sites that still pass `""` when a tenant is unresolved cannot hit
* the network with a broken URL.
*/
export function useAPIQuery<T>(path: string, schema: Validator<T>): APIQuery<T> {
export function useAPIQuery<T>(
path: string,
schema: Validator<T>,
options?: { readonly refetchInterval?: number | false },
): APIQuery<T> {
const enabled = path !== "";
const result = useQuery({
queryKey: pathToQueryKey(path),
enabled,
...(options?.refetchInterval === undefined ? {} : { refetchInterval: options.refetchInterval }),
queryFn: async () => {
const response = await fetch(path, {
headers: { accept: "application/json" },
Expand Down
4 changes: 3 additions & 1 deletion apps/web/src/pages/chat-thread-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,10 @@ function ChatTranscript({

// Only this agent's asks belong in this transcript; the bench-wide list
// is filtered down to the run address this chat talks to.
const approvalsQuery = usePendingApprovals(tenantId);
const liveAddress = chat?.agent.liveAddress ?? null;
const approvalsQuery = usePendingApprovals(tenantId, {
refetchInterval: liveAddress !== null ? 3000 : false,
});
const approvals =
approvalsQuery.kind === "ready" && liveAddress !== null
? approvalsQuery.data.filter((item) => item.agentAddress === liveAddress)
Expand Down
5 changes: 4 additions & 1 deletion apps/web/src/pages/workbench-room-page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,10 @@ function RoomInfoColumn({
readonly latestMessage: RoomMessage | undefined;
readonly participants: readonly RoomParticipant[];
}) {
const approvalsQuery = usePendingApprovals(roomTenantId);
const anyAgentLive = participants.some((p) => p.kind === "agent" && p.address !== "");
const approvalsQuery = usePendingApprovals(roomTenantId, {
refetchInterval: anyAgentLive ? 3000 : false,
});
const artifactsQuery = useAPIQuery(
`/api/tenants/${roomTenantId}/artifacts`,
ArtifactListPageSchema,
Expand Down
6 changes: 5 additions & 1 deletion apps/web/src/pending-approvals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,15 @@ function composeApproval(row: ApprovalRow, agentName: string): ApprovalDisplay {
* them. One naming read per distinct run, cached by react-query, so a run
* with several pending asks is named once.
*/
export function usePendingApprovals(tenantId: string | null): APIQuery<readonly PendingApproval[]> {
export function usePendingApprovals(
tenantId: string | null,
options?: { readonly refetchInterval?: number | false },
): APIQuery<readonly PendingApproval[]> {
const { memberships } = useBench();
const list = useAPIQuery(
tenantId === null ? "" : pendingApprovalsPath(tenantId),
TenantApprovalsSchema,
options,
);
const rows = list.kind === "ready" ? list.data.data : [];
const runIds = [...new Set(rows.map((row) => row.runId))];
Expand Down
Loading