mirror of
https://github.com/bitbaum/loki.git
synced 2026-12-05 17:07:17 +01:00
feat/parallel-implement
2
Commits
| Author | SHA1 | Message | Date | |
|---|---|---|---|---|
|
|
39aae9a651 |
fix(widget): don't offer a mic the site's policy forbids (#474)
Reported: "Microphone permission denied" on both FleetCrown and OrangeCat.
Measured in the browser rather than guessed:
orangecat.ch featurePolicyAllowsMic: false
permissionState: "denied" (not "prompt")
getUserMedia -> NotAllowedError
fleetcrown featurePolicyAllowsMic: true
permissionState: "prompt" (works)
Two different situations behind one error message. OrangeCat sends
`permissions-policy: camera=(), microphone=(), geolocation=()` from
next.config.js. `microphone=()` is an EMPTY allowlist — denied for every
origin including the site itself — so the browser never shows a prompt at
all. There is nothing the visitor can allow.
The bug is ours: navigator.mediaDevices.getUserMedia still EXISTS in that
state, so isVoiceSupported() passed and we drew a "Speak" button that could
only ever fail, then blamed the visitor's permissions for it.
isVoiceSupported now consults document.featurePolicy, so a policy-blocked
site simply never sees the button — the same progressive enhancement the
function already applied to a missing MediaRecorder or an insecure origin.
An unknown answer means ALLOWED, deliberately: featurePolicy is
non-standard and absent in some browsers, and hiding a working mic there
would be a worse failure than a click that fails with a readable message.
This is the half that is centrally fixable — one bundle, every customer
site, including sites we will never see. The other half is not, and cannot
be: Permissions-Policy is the host document's decision by design and no
script can override it. So the customer-facing docs now say plainly that
the mic needs `microphone=(self)`, what the symptom looks like, and that
everything else in the widget works regardless.
Pinned by four assertions in scripts/test/widget-voice.ts covering denied,
allowed, API-absent and API-throwing. Proven by mutation: making the check
always return true turns exactly the "denies the microphone" assertion red.
Co-authored-by: Mao Nakamoto <41178744+maonakamoto@users.noreply.github.com>
|
||
|
|
c41c1809e2 |
feat(widget): speak your feedback — plus the signals, escaping and docs that were lying (#462)
* fix(email): escape visitor text before it reaches an email body feedbackShippedTemplate interpolated `excerpt` and `page` raw. Both are visitor-authored — excerpt is the free-prose suggestion typed into the widget on a customer's site, page is location.pathname read off that site — and the resulting HTML is mailed from our own domain to an address the same visitor supplied. operatorMailTemplate, four lines below, escaped correctly with an inline replace-chain. That is the tell: escaping was something each template had to remember separately, and this one forgot. rss.xml had a third copy of the same chain. So the escape is now a named helper both callers share, covering the five XML predefined entities (the two extra quote forms make it safe in an attribute as well as a text node, so no caller has to pick a variant). Also makes the templates importable without a database. logSend's debug-logs import opened a DB client at module load, which every pure template in the file inherited — the reason none of them had tests. It is deferred into the function now; sending logs exactly as before. Proven by mutation: reverting the escape turns exactly the three injection assertions red, not the whole file. * fix(feedback): stop a failed request from answering "nothing needs you" Three surfaces read an empty array as an empty queue. An empty array is also what a failed fetch leaves behind, so a 500 or a timeout rendered as the confident answer "there is nothing here" — on the exact screens an operator checks to be sure nothing is waiting. - ControlInbox returned null when total === 0, so both fetches failing produced total silence. It now stays quiet while requests are still in flight (a failure that resolves fast should not flash), and once they settle with nothing, says which of the two happened. When one list loads and the other does not, the count renders with a note that it may be low rather than presenting a partial total as complete. - FeedbackInbox dropped `error` from useFetch entirely and fell through to "No feedback yet". The load error is now aliased `loadError` — `error` was already the mutation error from useFeedbackActions, and that collision is how the load error came to be dropped. - ProjectFeedbackSection treated a failed token GET as "no token", which offered "Enable & install" for a widget that may already be live on the customer's site. Not knowing is now its own state. Every new branch is reachable only when a request actually failed; the genuine empty states are untouched. * feat(widget): let visitors speak their feedback instead of typing it Typing a bug report on a phone, on someone else's site, is where most reports die. The widget now offers a mic: record, the clip is transcribed, and the text lands in the same textarea appended to whatever was already typed. The visitor still presses Send — speech-to-text mishears things, and a mic that auto-sent would file those mistakes under their name. FleetCrown already had working transcription (terminal, Loki composer, command palette) but the widget never got it. Two things were missing: - CORS. /api/beacon/transcribe is public but answers no preflight and sets no ACAO, so a cross-origin caller can never read the response. - Authorization. That route takes no token — it is guarded only by a per-IP limiter. Opening it cross-origin would have made it an anonymous endpoint that spends our Groq quota for anyone with the URL. So this adds /api/widget/transcribe rather than widening the beacon route: same fcw_* token that already authorizes ingest, same per-token origin allowlist, per-IP and per-token rate limits, and Groq only — the local-Whisper fallback spawns ffmpeg + python3 on the host, which is not something to expose to anonymous traffic. The Groq step itself moved to lib/transcribe.ts so both routes share one implementation instead of growing two copies of the error mapping. Also in the widget, from the same audit: - Recording stops and the mic is released when the panel closes, so the browser's recording indicator never outlives the panel on a host site. - Sub-44px touch targets (the 18px remove-image dot, attach button) get a coarse-pointer hit area without changing how they look. - The pulsing record dot honours prefers-reduced-motion. Progressive enhancement throughout: no MediaRecorder, or an insecure origin where getUserMedia is undefined, renders no button at all rather than a control that cannot work. Bundle 16.3KB -> 20.8KB. /api/widget is classified "spend" in the demo sandbox — the repo's own gate caught that omission before this commit existed. * docs(claude): correct the claims that were sending agents the wrong way CLAUDE.md is loaded into every agent session, so a false line in it is not a stale doc — it is an instruction. Each of these was verified against the code in both directions before editing. - Session helpers. It named `getCurrentUserId()` and `DEFAULT_USER_ID`; neither has existed since |