Skip to content

armgit / fx0

Public Imported from GitHub
0

A lightweight design agent built with libfx. Describe a page and an agent writes it as one HTML file.

TypeScript

Merge remote-tracking branch 'origin/main' into fazxes/show-thinking-on-accept

Pranit5c4b2b8ea43b
diff --cc components/chat-app.tsx
index e70f09e,e599259..a418da5
--- a/components/chat-app.tsx
+++ b/components/chat-app.tsx
@@@ -281,12 -285,10 +285,13 @@@ export default function ChatApp({ accou
const [activeTurnId, setActiveTurnId] = useState<number | null>(initialState.activeTurnId)
const [turnStartedAt, setTurnStartedAt] = useState<number | null>(initialState.activeTurnStartedAt)
// The wait the user feels starts at send, not at the server's turn_start, so the
- // counter runs through "sending" and "thinking" instead of sitting at 0s.
- const [sentAt, setSentAt] = useState<number | null>(null)
+ // counter runs through "sending" and "thinking" instead of sitting at 0s. Kept
+ // per chat, so switching to another chat and back doesn't restart it.
+ const [activityStarts, setActivityStarts] = useState<ActivityStarts>(() => new Map())
const [awaiting, setAwaiting] = useState(false)
+ // The server accepted the awaited prompt: it is stored and its turn is
+ // starting, so the activity line says "thinking" before turn_start arrives.
+ const [sendAccepted, setSendAccepted] = useState(false)
const [authStatus, setAuthStatus] = useState<401 | 403 | null>(null)
const [signOutStatus, setSignOutStatus] = useState<'pending' | 'failed' | null>(null)
const signOutPending = useRef(false)
@@@ -1218,8 -1241,7 +1244,8 @@@
const designPick = targetSession === 'draft' ? composerRef.current?.getDesignMd() ?? null : null
// The bubble shows at once, before a draft's chat is reserved on the server.
setAwaiting(true)
+ setSendAccepted(false)
- setSentAt((current) => current ?? Date.now())
+ setActivityStarts((starts) => startActivity(starts, targetSession, Date.now()))
setInteractionNotice(null)
setEntries((prev) => [
...prev,
diff --cc lib/agent.ts
index 95ab664,1f13cc9..8c1c75b
--- a/lib/agent.ts
+++ b/lib/agent.ts
@@@ -232,13 -218,12 +239,15 @@@ export async function submitPrompt
log(host.id, 'prompt:submitted', { id: submitted.id, clientId, imageCount: images?.length ?? 0, idle: submitted.idle })
const id = submitted.id
try {
+ // Pinned before libfx sees the message: whether it starts a turn or joins
+ // the running one, no turn can run without its funding record.
if (funding) await saveTrialCredential(host.id, funding, id)
- else await saveTurnCredential(host.id, sender!, submitted.trialChat ? id : undefined)
+ else await saveTurnCredential(host.id, sender!, id)
+ stages.mark('credential')
const stored = await hydrateSession(host)
+ stages.mark('hydrate')
const { session } = await chatSession(agent(), host, stored?.libfxSessionId ?? null, agentInstructions(host), id, !!funding)
+ stages.mark('bind')
const input = images?.length ? [{ type: 'text' as const, text: `[${author}] ${text}` }, ...images] : `[${author}] ${text}`
// prompt() runs the turn in this request; steer() always goes through
// Vercel Queues, which delays the turn's start by seconds. So a message to