Skip to content

Where people and agents ship software together. The open-source git platform for the whole job: issues, agents, checks and deploys to the edge.

35 linesCodeBlameRaw
1/**
2 * Home's Summarize card (components/home-summary.tsx), its pure parts:
3 * what one request to chat's `ask_g1t` (routes/workspace/chat/api.ts)
4 * leaves the card showing, and how often the card reads the conversation
5 * again while the answer comes.
6 */
7import type { Result } from "@g1t/contracts";
8
9import type { LiveState } from "../components/chat/live";
10
11/** What the card shows: asking, the answer to one question, or why there is none. */
12export type SummaryState =
13 | { step: "asking" }
14 | { step: "answering"; channelId: string; questionId: string }
15 | { step: "problem"; message: string; setup: boolean; owner: boolean };
16
17/** What `ask_g1t` answers: the question asked, or why Ask cannot answer yet and whether the viewer can fix that. */
18export type AskedG1t = { channel_id: string; question_id: string } | { problem: string; owner: boolean };
19
20/** The card after `ask_g1t` answered; null when it could not be reached. */
21export function summaryAsked(answer: Result<AskedG1t> | null): SummaryState {
22 if (!answer) return { step: "problem", message: "Ask could not be reached. Try again in a moment.", setup: false, owner: false };
23 if (!answer.ok) return { step: "problem", message: answer.error.message, setup: false, owner: false };
24 if ("problem" in answer.value) return { step: "problem", message: answer.value.problem, setup: true, owner: answer.value.owner };
25 return { step: "answering", channelId: answer.value.channel_id, questionId: answer.value.question_id };
26}
27
28/**
29 * How often the card reads the conversation again while the answer comes.
30 * The socket brings the answer as it streams: with it open, reading is only
31 * a fallback, now and then; while it connects or comes back, more often.
32 */
33export function summaryPollMs(live: LiveState): number {
34 return live === "open" ? 10_000 : 2_500;
35}