Skip to content
Open
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
27 changes: 26 additions & 1 deletion src/components/builder/BuilderAssistant.client.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@ export const BuilderAssistant = React.forwardRef<
const [queueAnnouncement, setQueueAnnouncement] = React.useState('')
const [showLatest, setShowLatest] = React.useState(false)
const abortRef = React.useRef<AbortController>(null)
const unlockingRef = React.useRef(false)
const onRunningChangeRef = React.useRef(onRunningChange)
const abortIntentRef = React.useRef<'steer' | 'stop' | undefined>(undefined)
const agentStreamingRef = React.useRef(false)
Expand Down Expand Up @@ -1388,8 +1389,32 @@ export const BuilderAssistant = React.forwardRef<
discardUnrecordedPrompt()
}

function submit(event: React.FormEvent) {
async function submit(event: React.FormEvent) {
event.preventDefault()
// Unlock the passkey-encrypted BYOK key here, on the click, while the
// user activation is still fresh. Safari and Dia suppress the WebAuthn
// prompt (it silently never resolves) if the unlock runs later in the
// async send pipeline, past the activation window.
if (selectedModel.connection === 'byok') {
// Guard the async unlock window: ignore repeat submits while the passkey
// ceremony is pending (a second ceremony would be rejected anyway), and
// read the model once so a mid-await model change cannot alter the target.
if (unlockingRef.current) return
const provider = selectedModel.provider
unlockingRef.current = true
try {
await unlockApiKey(provider)
} finally {
unlockingRef.current = false
}
// Bail if it is still locked (unlock cancelled or failed) — the run
// pipeline can no longer surface the WebAuthn prompt itself.
const client = byokConnection.getClient(provider, { allowUnlock: false })
if (!client) {
setError('Could not unlock the API key. Try again.')
return
}
}
submitInstruction(prompt, sendMode, true)
}

Expand Down
Loading