Rewild Your Web
web
browser
dweb
1// SPDX-License-Identifier: AGPL-3.0-or-later
2
3export class FendProvider {
4 constructor() {
5 this.name = "Fend";
6 this.icon = "pencil-ruler";
7 this.initialized = false;
8 }
9
10 async init() {
11 if (!this.initialized) {
12 // Use absolute URL so it works from any origin (homescreen, system, etc.)
13 await fend_wasm("//system.localhost:8888/third_party/fend/fend_wasm_bg.wasm");
14 fend_wasm.initSync();
15 this.initialized = true;
16 }
17 }
18
19 // Returns a Promise that resolves to a result set.
20 async query(text) {
21 await this.init();
22
23 let result = await fend_wasm.evaluateFendWithTimeout(text, 500);
24 if (!result.startsWith("Error:") && result.length > 0) {
25 return [{ kind: "text", value: result, score: 1 }];
26 } else {
27 return [];
28 }
29 }
30}