Gateway: multi-select answers and a summary endpoint for the complication
Gateway / check (push) Successful in 10s
Gateway / image (push) Successful in 13s

This commit is contained in:
gib committed 2026-11-01 10:49:36 -05:00
1 parent 69858d4719
commit 830bf4f139
5 files changed
+98 -7

No files matched your search

+26 -1
View File
@@ -4,7 +4,7 @@
// the thread's `updatedAt` moves.
import { threadPhase, type Phase } from "./awareness.ts";
import type { Feed, FeedItem, HostSummary, Message, PendingRequest, ThreadDetail } from "./contract.ts";
import type { Feed, FeedItem, HostSummary, Message, PendingRequest, Summary, ThreadDetail } from "./contract.ts";
import type { T3Host } from "./t3/host.ts";
import {
isApprovalRequest,
@@ -80,6 +80,7 @@ function pendingRequest(thread: ThreadShell, turnItems: BoundedThread["projectio
question: question.question,
options: question.options.map((option) => ({ label: option.label, value: option.value ?? option.label })),
allowCustomAnswer: question.allowCustomAnswer ?? false,
multiSelect: question.multiSelect ?? false,
})),
};
}
@@ -155,6 +156,30 @@ function feedItem(host: T3Host, thread: ThreadShell, phase: Phase, summary: Thre
};
}
/** Counts for the complication, from thread shells alone. */
export function buildSummary(hosts: T3Host[]): Summary {
let needsYou = 0;
let working = 0;
let next: { host: T3Host; thread: ThreadShell } | null = null;
for (const host of hosts) {
for (const thread of host.threads.values()) {
if (thread.archivedAt || thread.deletedAt) continue;
const phase = threadPhase(thread);
if (phase === "starting" || phase === "running") working++;
if (phase !== "waiting_for_approval" && phase !== "waiting_for_input") continue;
needsYou++;
const waitingSince = thread.pendingRuntimeRequest?.createdAt ?? "";
if (!next || waitingSince < (next.thread.pendingRuntimeRequest?.createdAt ?? "")) next = { host, thread };
}
}
return {
needsYou,
working,
next: next && { hostId: next.host.id, threadId: next.thread.id, title: next.thread.title, hostLabel: next.host.label },
hostsOffline: hosts.filter((host) => host.status !== "online").length,
};
}
/** Builds the feed across every host, waiting briefly for summaries it has not read yet. */
export async function buildFeed(hosts: T3Host[], cache: SummaryCache, now = Date.now()): Promise<Feed> {
const candidates: Array<{ host: T3Host; thread: ThreadShell; phase: Phase }> = [];