Spaces:
Running
Running
Sync from felladrin/MiniSearch@bcf089f
Browse filesFiles changed (6)
17e8885e1bcf089f
3 unmodified lines4567893 unmodified lines## 2026-11-27- `/status` now says what kind of software its rejections come from, under `authorization.rejectedByClient`: `bot`, `curl`, `wget`, `python`, `node`, `java`, `go`, `browser` or `other`. A high rate of token rejections used to tell you something was hammering the instance and nothing more; now it tells you what that something claims to be, which is usually enough to tell a script from a browser tab. The client's own user-agent string is sorted into one of those labels and dropped, so the page still publishes no address, no token and no visitor string.- `/status` and the app version now report the commit the code came from, even on a Hugging Face Space. A Space is built from a copy of the repository, so its build used to name a commit of that copy, which nobody could look up in the source repository. The deploy workflow now records the source commit with the copy, and the build reports that.- Images found by a follow-up question are no longer lost when a second follow-up is sent before they arrive. The second follow-up's image search took over, so when the first one's images landed they were dropped, on screen and in history. They are now added to the list either way.3 unmodified lines45678910113 unmodified lines## 2026-11-27- Pressing Stop while dictating with the browser's speech recognition no longer loses the last words. The browser sends its final result for the speech already heard after Stop is pressed, but dictation ignored anything that arrived after Stop, so the last words, or a correction to the text shown so far, never reached the search field. Stop now waits for that final result, for up to three seconds. Turning dictation off, or sending a follow-up, still ends it at once.- Image search no longer comes back short, or empty, when the top results have no preview. It cut the list down to the limit first and only then dropped images without a preview, so when the top results had none, they took every slot and the usable images just below them were never shown. With a limit of 5, a search could end with "No image results found" while a limit of 10 found images. Images without a preview are now dropped before the limit applies.- `/status` now says what kind of software its rejections come from, under `authorization.rejectedByClient`: `bot`, `curl`, `wget`, `python`, `node`, `java`, `go`, `browser` or `other`. A high rate of token rejections used to tell you something was hammering the instance and nothing more; now it tells you what that something claims to be, which is usually enough to tell a script from a browser tab. The client's own user-agent string is sorted into one of those labels and dropped, so the page still publishes no address, no token and no visitor string.- `/status` and the app version now report the commit the code came from, even on a Hugging Face Space. A Space is built from a copy of the repository, so its build used to name a commit of that copy, which nobody could look up in the source repository. The deploy workflow now records the source commit with the copy, and the build reports that.- Images found by a follow-up question are no longer lost when a second follow-up is sent before they arrive. The second follow-up's image search took over, so when the first one's images landed they were dropped, on screen and in history. They are now added to the list either way.
7 unmodified lines8910111213116 unmodified lines130131132133134135481 unmodified lines6176186196206216226235 unmodified lines629630631632633634102 unmodified lines7377387397407417427 unmodified linestype SpeechRecognitionLike,startDictation,stripLanguageTag,} from "@/modules/speechToText";import { createWllamaInstance } from "@/modules/wllama";116 unmodified lines});afterEach(() => {vi.unstubAllGlobals();Object.defineProperty(navigator, "mediaDevices", {configurable: true,481 unmodified lineslet instance: RecognitionFake | undefined;function installRecognitionFake(startImpl: () => void = () => {}) {class FakeRecognition {continuous = false;interimResults = false;5 unmodified linesstart: () => void;stop = () => {this.stopped = true;};constructor() {this.start = startImpl;102 unmodified linesexpect(onError).not.toHaveBeenCalled();expect(onEnd).not.toHaveBeenCalled();});});describe("startDictation without any engine", () => {7 unmodified lines891011121314116 unmodified lines131132133134135136137481 unmodified lines6196206216226236246256266276286296306316326336345 unmodified lines640641642643644645646102 unmodified lines7497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658667 unmodified linestype SpeechRecognitionLike,startDictation,stripLanguageTag,WEB_SPEECH_STOP_TIMEOUT_MS,} from "@/modules/speechToText";import { createWllamaInstance } from "@/modules/wllama";116 unmodified lines});afterEach(() => {vi.useRealTimers();vi.unstubAllGlobals();Object.defineProperty(navigator, "mediaDevices", {configurable: true,481 unmodified lineslet instance: RecognitionFake | undefined;/*** `stopImpl` runs after the fake marks itself stopped. By default it ends on* a later task, as a browser does once it has delivered the last result.*/function installRecognitionFake(startImpl: () => void = () => {},stopImpl: (fake: RecognitionFake) => void = (fake) => {setTimeout(() => fake.onend?.(), 0);},) {class FakeRecognition {continuous = false;interimResults = false;5 unmodified linesstart: () => void;stop = () => {this.stopped = true;stopImpl(this as unknown as RecognitionFake);};constructor() {this.start = startImpl;102 unmodified linesexpect(onError).not.toHaveBeenCalled();expect(onEnd).not.toHaveBeenCalled();});/*** A recognizer whose `stop()` delivers "fresh basil" as a final result after* 25 ms and fires `end` 25 ms later, as the spec allows.*/async function startSessionWithLateFinalResult() {vi.useFakeTimers();installRecognitionFake(undefined, (fake) => {setTimeout(() => {fake.onresult?.({resultIndex: 0,results: [{ isFinal: true, 0: { transcript: "fresh basil" } }],});setTimeout(() => fake.onend?.(), 25);}, 25);});const transcripts: string[] = [];const onEnd = vi.fn();const session = await startDictation({ onTranscript: (text) => transcripts.push(text), onEnd },true,);instance?.onresult?.({resultIndex: 0,results: [{ isFinal: false, 0: { transcript: "fresh" } }],});return { session, transcripts, onEnd };}it("keeps the final result the recognizer delivers after stop", async () => {const { session, transcripts, onEnd } =await startSessionWithLateFinalResult();let stopped = false;const stopping = session.stop().then(() => {stopped = true;});await vi.advanceTimersByTimeAsync(25);expect(transcripts).toEqual(["fresh", "fresh basil"]);// The recognizer has not ended yet, so the stop must still be waiting.expect(stopped).toBe(false);await vi.advanceTimersByTimeAsync(25);await stopping;expect(stopped).toBe(true);// The end belongs to the stop, not to a recognizer that gave up.expect(onEnd).not.toHaveBeenCalled();});it("gives up waiting when the recognizer never ends after stop", async () => {vi.useFakeTimers();installRecognitionFake(undefined, () => {});const session = await startDictation({ onTranscript: vi.fn() }, true);let stopped = false;void session.stop().then(() => {stopped = true;});await vi.advanceTimersByTimeAsync(WEB_SPEECH_STOP_TIMEOUT_MS - 1);expect(stopped).toBe(false);await vi.advanceTimersByTimeAsync(1);expect(stopped).toBe(true);});it("ends the stop quietly when the recognizer fails while it waits", async () => {vi.useFakeTimers();installRecognitionFake(undefined, () => {});const onError = vi.fn();const session = await startDictation({ onTranscript: vi.fn(), onError },true,);let stopped = false;void session.stop().then(() => {stopped = true;});instance?.onerror?.({ error: "no-speech" });await vi.advanceTimersByTimeAsync(0);expect(stopped).toBe(true);expect(onError).not.toHaveBeenCalled();});it("drops the late result and ends the stop at once when cancelled", async () => {const { session, transcripts } = await startSessionWithLateFinalResult();let stopped = false;void session.stop().then(() => {stopped = true;});session.cancel();await vi.advanceTimersByTimeAsync(0);expect(stopped).toBe(true);await vi.advanceTimersByTimeAsync(50);expect(transcripts).toEqual(["fresh"]);});it("drops the late result of a session cancelled without a stop", async () => {const { session, transcripts, onEnd } =await startSessionWithLateFinalResult();session.cancel();await vi.advanceTimersByTimeAsync(50);expect(instance?.stopped).toBe(true);expect(transcripts).toEqual(["fresh"]);expect(onEnd).not.toHaveBeenCalled();});});describe("startDictation without any engine", () => {
43 unmodified lines444546474849407 unmodified lines45745845946046146246346446513 unmodified lines47948048148248348411 unmodified lines4964974984995005017 unmodified lines50951051151251351451551651751851952052143 unmodified lines*/export const MAX_RECORDING_SECONDS = 120;/*** Room for `MAX_RECORDING_SECONDS` of audio, the prompt and the transcript.* The audio encoder emits about 13 tokens per second of speech.407 unmodified lineslet finalText = "";/** The returned promise has resolved, so rejecting it would be a no-op. */let resolved = false;// `recognition.stop()` emits one last `result` by spec, and the caller has// already forgotten what it appended by then.let stopped = false;return new Promise<DictationSession>((resolve, reject) => {recognition.onresult = (event) => {13 unmodified linesrecognition.onerror = (event) => {if (stopped) return;const denied =event.error === "not-allowed" || event.error === "service-not-allowed";const failure = denied11 unmodified linesrecognition.onend = () => {if (stopped) return;// The recognizer ends on its own after silence even with `continuous`.// That is not a failure worth a notification, but the session is over, so// the button has to come back from Listening.7 unmodified linestry {recognition.start();resolved = true;// The recognizer delivers its text as it goes, so stopping it and// dropping its last result is all either one needs to do.const end = () => {stopped = true;recognition.stop();};resolve({ stop: async () => end(), cancel: end });} catch (error) {reject(new DictationError(43 unmodified lines44454647484950515253545556407 unmodified lines46446546646746846947047147247347447547647747847913 unmodified lines49349449549649749849950050150250350411 unmodified lines5165175185195205215225235245255267 unmodified lines53453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157243 unmodified lines*/export const MAX_RECORDING_SECONDS = 120;/*** How long a stopped browser recognizer gets to deliver its last result and* fire `end` before the stop resolves without it, so a recognizer that never* ends cannot leave the button transcribing forever.*/export const WEB_SPEECH_STOP_TIMEOUT_MS = 3000;/*** Room for `MAX_RECORDING_SECONDS` of audio, the prompt and the transcript.* The audio encoder emits about 13 tokens per second of speech.407 unmodified lineslet finalText = "";/** The returned promise has resolved, so rejecting it would be a no-op. */let resolved = false;/*** Cancelled, or done stopping. What the recognizer sends from now on is* for a caller that has already forgotten what it appended.*/let stopped = false;/** The recognizer fired `end`, so a stop has nothing left to wait for. */let ended = false;/** Settles a pending `stop`; set only while one waits for `end`. */let settleStop: (() => void) | null = null;let stopping: Promise<void> | null = null;return new Promise<DictationSession>((resolve, reject) => {recognition.onresult = (event) => {13 unmodified linesrecognition.onerror = (event) => {if (stopped) return;// The user already asked to stop, so a failure while the last result// was on its way only means there is no more text to wait for.if (settleStop) {settleStop();return;}const denied =event.error === "not-allowed" || event.error === "service-not-allowed";const failure = denied11 unmodified linesrecognition.onend = () => {if (stopped) return;ended = true;if (settleStop) {settleStop();return;}// The recognizer ends on its own after silence even with `continuous`.// That is not a failure worth a notification, but the session is over, so// the button has to come back from Listening.7 unmodified linestry {recognition.start();resolved = true;resolve({// `recognition.stop()` still tries to return a result for the audio// already captured, and the browser delivers it on a later task, so// the stop waits for `end` instead of dropping the last words.stop: () => {if (stopped || ended) return Promise.resolve();stopping ??= new Promise<void>((settle) => {const timeout = setTimeout(() => settleStop?.(),WEB_SPEECH_STOP_TIMEOUT_MS,);settleStop = () => {clearTimeout(timeout);stopped = true;settleStop = null;settle();};recognition.stop();});return stopping;},// The field cannot take more text, so the last result is dropped and// a stop still waiting for it resolves now.cancel: () => {if (stopped) return;if (settleStop) {settleStop();return;}stopped = true;recognition.stop();},});} catch (error) {reject(new DictationError(
237 unmodified lines238239240241242243244237 unmodified linesThe response never waits on a thumbnail host; the client loads each tilethrough `/thumbnail`. A result SearXNG returned without a thumbnail URL isdropped before the response, since the grid would have nothing to show for it.### `GET /page-content`237 unmodified lines238239240241242243244245237 unmodified linesThe response never waits on a thumbnail host; the client loads each tilethrough `/thumbnail`. A result SearXNG returned without a thumbnail URL isdropped before `limit` applies, since the grid would have nothing to show forit, so it never takes the place of one that has a thumbnail.### `GET /page-content`
97 unmodified lines989910010110210397 unmodified lines| Microphone permission is denied | A notification says so instead of the press failing quietly, no fallback asks again, and the loaded model is unloaded | `client/components/DictationButton.test.tsx` › shows a notification when microphone permission is denied, `client/modules/speechToText.test.ts` › reports a permission error and unloads the model when the microphone is denied || The browser recognizer is denied after the session started | Reported through the error callback, since the promise it would have rejected has already resolved | `client/modules/speechToText.test.ts` › reports a denial that arrives after the session resolved || The browser recognizer ends on its own after silence | The session ends and the button leaves its recording state, with no notification, because nothing failed | `client/modules/speechToText.test.ts` › ends the session quietly when the recognizer stops on its own, `client/components/DictationButton.test.tsx` › leaves the recording state quietly when the engine ends on its own || An on-device recording reaches its two-minute cap | The microphone is released and the recording is transcribed up to the cap, because more audio would not fit the model's context | `client/modules/speechToText.test.ts` › ends the recording at the cap and transcribes exactly that much || The dictation engine fails after it loaded, or the transcription fails after the recording stopped | A notification says so and the session ends, instead of the UI listening or transcribing forever, and the model is unloaded | `client/modules/speechToText.test.ts` › reports a transcription that fails after stop, `client/components/DictationButton.test.tsx` › notifies and stops when the engine fails after it loaded || The search form unmounts while dictation is recording | The microphone track, the AudioContext and the model are all released | `client/components/DictationButton.test.tsx` › releases the microphone when the button unmounts mid-recording |97 unmodified lines989910010110210310497 unmodified lines| Microphone permission is denied | A notification says so instead of the press failing quietly, no fallback asks again, and the loaded model is unloaded | `client/components/DictationButton.test.tsx` › shows a notification when microphone permission is denied, `client/modules/speechToText.test.ts` › reports a permission error and unloads the model when the microphone is denied || The browser recognizer is denied after the session started | Reported through the error callback, since the promise it would have rejected has already resolved | `client/modules/speechToText.test.ts` › reports a denial that arrives after the session resolved || The browser recognizer ends on its own after silence | The session ends and the button leaves its recording state, with no notification, because nothing failed | `client/modules/speechToText.test.ts` › ends the session quietly when the recognizer stops on its own, `client/components/DictationButton.test.tsx` › leaves the recording state quietly when the engine ends on its own || The browser recognizer never fires `end` after the user presses Stop | The stop resolves after three seconds with whatever text arrived, instead of the button transcribing forever | `client/modules/speechToText.test.ts` › gives up waiting when the recognizer never ends after stop || An on-device recording reaches its two-minute cap | The microphone is released and the recording is transcribed up to the cap, because more audio would not fit the model's context | `client/modules/speechToText.test.ts` › ends the recording at the cap and transcribes exactly that much || The dictation engine fails after it loaded, or the transcription fails after the recording stopped | A notification says so and the session ends, instead of the UI listening or transcribing forever, and the model is unloaded | `client/modules/speechToText.test.ts` › reports a transcription that fails after stop, `client/components/DictationButton.test.tsx` › notifies and stops when the engine fails after it loaded || The search form unmounts while dictation is recording | The microphone track, the AudioContext and the model are all released | `client/components/DictationButton.test.tsx` › releases the microphone when the button unmounts mid-recording |
.source-commit+1-1
changelog.md+2
client/modules/speechToText.test.ts+125-1
client/modules/speechToText.ts+60-9
docs/api.md+2-1
docs/failure-injection.md+1