Add AI browser prompt api#33
Conversation
Greptile SummaryThis PR wires up Chrome's on-device Prompt API as a All previously flagged issues — Confidence Score: 5/5Safe to merge — only P2 findings remain; no runtime crashes or data-loss paths identified All previously flagged P1 issues (tool message drops, tool_calls field, availability cache staleness, no-op download callback) are resolved. The two remaining findings are P2: an incorrect null-output serialization in tool results and a transient wizard-flash when browser AI is already downloaded, neither of which blocks core functionality. ui/src/service-worker/browser-ai.ts (null output serialization at line 788) and ui/src/components/WasmSetup/WasmSetupGuard.tsx (availability initialisation timing) Important Files Changed
Prompt To Fix All With AIFix the following 2 code review issues. Work through them one at a time, proposing concise fixes.
---
### Issue 1 of 2
ui/src/service-worker/browser-ai.ts:788-790
**Null tool output serialized as `""` not as empty string**
`JSON.stringify(item.output ?? "")` handles a `null`/`undefined` `output` field by substituting `""`, then JSON-encodes it to the literal `"\"\""` (two double-quote characters). The injected markup becomes `<tool_result name="tool">""</tool_result>`, which the model reads as the string `""` rather than an empty result. A `null` output should produce an empty tag body.
```suggestion
const output =
typeof item.output === "string"
? item.output
: item.output != null
? JSON.stringify(item.output)
: "";
```
### Issue 2 of 2
ui/src/components/WasmSetup/WasmSetupGuard.tsx:344-374
**Transient wizard flash when Browser AI is already downloaded**
`browserAi` state is initialised with `availability: "unavailable"` regardless of the actual on-device state. If the model list query settles before the `getAvailability()` promise (which talks to the bridge), `needsOnboarding` will briefly be `true` — opening the wizard — even when the browser AI model is already ready. Once `getAvailability()` resolves, `browserAiCounts` becomes true and the modal closes, but the flash is visible.
Consider initialising `availability` via a synchronous check if the API exposes one, or at minimum ensure `isLoading` stays true until both the model-list query and the availability check have settled.
Reviews (3): Last reviewed commit: "Review fixes" | Re-trigger Greptile |
No description provided.