@qikbar/qikbar 0.1.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +30 -1
- package/bin/qikbar.mjs +203 -0
- package/dist/ai/embeddings.d.ts +51 -0
- package/dist/ai/index.d.ts +4 -0
- package/dist/ai/mcp.d.ts +84 -0
- package/dist/ai.js +27 -9
- package/dist/chunks/{bar-D5CSPT3U.js → bar-P3SCR4SJ.js} +684 -160
- package/dist/chunks/bar-P3SCR4SJ.js.map +7 -0
- package/dist/chunks/chunk-24EBWTCF.js +271 -0
- package/dist/chunks/chunk-24EBWTCF.js.map +7 -0
- package/dist/chunks/{chunk-I77YSUJN.js → chunk-INTEVQYK.js} +7 -3
- package/dist/chunks/{chunk-I77YSUJN.js.map → chunk-INTEVQYK.js.map} +2 -2
- package/dist/chunks/{chunk-VXTYD56F.js → chunk-JHQAIXM7.js} +9 -4
- package/dist/chunks/{chunk-VXTYD56F.js.map → chunk-JHQAIXM7.js.map} +2 -2
- package/dist/chunks/{chunk-2ADXL7KQ.js → chunk-MRHKJ2FZ.js} +63 -2
- package/dist/chunks/{chunk-2ADXL7KQ.js.map → chunk-MRHKJ2FZ.js.map} +3 -3
- package/dist/chunks/{chunk-IJ3WUM3T.js → chunk-R2AY6LRL.js} +35 -4
- package/dist/chunks/chunk-R2AY6LRL.js.map +7 -0
- package/dist/chunks/chunk-TIM4VBM4.js +98 -0
- package/dist/chunks/chunk-TIM4VBM4.js.map +7 -0
- package/dist/chunks/{chunk-HBBSETRF.js → chunk-WO6XXQ3H.js} +47 -6
- package/dist/chunks/chunk-WO6XXQ3H.js.map +7 -0
- package/dist/chunks/launcher-B5MGOPEQ.js +37 -0
- package/dist/chunks/launcher-B5MGOPEQ.js.map +7 -0
- package/dist/core/labels.d.ts +98 -0
- package/dist/core/launcher.d.ts +8 -0
- package/dist/core/lazy.d.ts +12 -0
- package/dist/core/types.d.ts +138 -2
- package/dist/element/index.d.ts +56 -0
- package/dist/element.js +145 -0
- package/dist/element.js.map +7 -0
- package/dist/extensions.js +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +19 -7
- package/dist/locales/index.d.ts +24 -0
- package/dist/locales.js +812 -0
- package/dist/locales.js.map +7 -0
- package/dist/qikbar.global.js +68 -25
- package/dist/qikbar.global.js.map +4 -4
- package/dist/react.js +7 -6
- package/dist/react.js.map +2 -2
- package/dist/server/index.d.ts +19 -0
- package/dist/server.js +38 -2
- package/dist/server.js.map +2 -2
- package/dist/solid/index.d.ts +42 -0
- package/dist/solid.js +92 -0
- package/dist/solid.js.map +7 -0
- package/dist/styles.css +34 -3
- package/dist/svelte/index.d.ts +58 -0
- package/dist/svelte.js +54 -0
- package/dist/svelte.js.map +7 -0
- package/dist/theme.js +1 -1
- package/dist/ui/bar.d.ts +89 -3
- package/dist/ui/icons.d.ts +5 -0
- package/dist/ui/markdown.d.ts +3 -1
- package/dist/ui/views.d.ts +8 -0
- package/dist/ui/webmcp.d.ts +33 -0
- package/dist/utils.js +1 -1
- package/dist/vue/index.d.ts +74 -0
- package/dist/vue.js +121 -0
- package/dist/vue.js.map +7 -0
- package/package.json +45 -4
- package/dist/chunks/bar-D5CSPT3U.js.map +0 -7
- package/dist/chunks/chunk-6TC6G2C5.js +0 -107
- package/dist/chunks/chunk-6TC6G2C5.js.map +0 -7
- package/dist/chunks/chunk-HBBSETRF.js.map +0 -7
- package/dist/chunks/chunk-IJ3WUM3T.js.map +0 -7
|
@@ -4,12 +4,12 @@ import {
|
|
|
4
4
|
} from "./chunk-N4Y2Z6YD.js";
|
|
5
5
|
import {
|
|
6
6
|
action
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-INTEVQYK.js";
|
|
8
8
|
import {
|
|
9
9
|
css,
|
|
10
10
|
cssVarName,
|
|
11
11
|
resolveThemeVars
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-R2AY6LRL.js";
|
|
13
13
|
import {
|
|
14
14
|
Frecency,
|
|
15
15
|
copyText,
|
|
@@ -18,7 +18,7 @@ import {
|
|
|
18
18
|
matchItem,
|
|
19
19
|
rank,
|
|
20
20
|
renderMarkdown
|
|
21
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-JHQAIXM7.js";
|
|
22
22
|
import {
|
|
23
23
|
defaultStorage,
|
|
24
24
|
scopedStorage
|
|
@@ -30,6 +30,10 @@ import {
|
|
|
30
30
|
isEditable,
|
|
31
31
|
matchesHotkey
|
|
32
32
|
} from "./chunk-PQEHV3D4.js";
|
|
33
|
+
import {
|
|
34
|
+
en,
|
|
35
|
+
format
|
|
36
|
+
} from "./chunk-TIM4VBM4.js";
|
|
33
37
|
import {
|
|
34
38
|
__publicField
|
|
35
39
|
} from "./chunk-MPTP2EWW.js";
|
|
@@ -118,8 +122,88 @@ function uid(prefix = "qb") {
|
|
|
118
122
|
return `${prefix}-${(++idCounter).toString(36)}`;
|
|
119
123
|
}
|
|
120
124
|
|
|
125
|
+
// src/ui/webmcp.ts
|
|
126
|
+
function modelContext() {
|
|
127
|
+
let doc = typeof document < "u" ? document.modelContext : void 0, nav = typeof navigator < "u" ? navigator.modelContext : void 0, ctx = doc ?? nav;
|
|
128
|
+
return ctx && typeof ctx.registerTool == "function" ? ctx : void 0;
|
|
129
|
+
}
|
|
130
|
+
var safeName = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_").slice(0, 64);
|
|
131
|
+
function exposeWebMCP(bar, options = {}) {
|
|
132
|
+
let mc = modelContext();
|
|
133
|
+
if (!mc) return () => {
|
|
134
|
+
};
|
|
135
|
+
let prefix = safeName(options.prefix ?? "qikbar"), controller = new AbortController(), names = [], found = /* @__PURE__ */ new Map(), lookup = (id) => found.get(id) ?? bar.rootItems().find((i) => bar.idOf(i) === id), register = (tool) => {
|
|
136
|
+
try {
|
|
137
|
+
mc.registerTool(tool, { signal: controller.signal }), names.push(tool.name);
|
|
138
|
+
} catch (err) {
|
|
139
|
+
console.warn(`[qikbar] could not register WebMCP tool "${tool.name}"`, err);
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
if (register({
|
|
143
|
+
name: `${prefix}_list_commands`,
|
|
144
|
+
description: `List the commands and pages available in this app's command bar (${typeof document < "u" ? document.title : "this app"}). Returns ids you can pass to ${prefix}_run.`,
|
|
145
|
+
inputSchema: { type: "object", properties: {} },
|
|
146
|
+
annotations: { readOnlyHint: !0 },
|
|
147
|
+
execute: async () => JSON.stringify(
|
|
148
|
+
bar.rootItems().filter((i) => !bar.idOf(i).startsWith("qikbar.")).map((i) => ({ id: bar.idOf(i), title: i.title, subtitle: i.subtitle, section: i.section, description: i.description, href: i.href ?? i.url }))
|
|
149
|
+
)
|
|
150
|
+
}), register({
|
|
151
|
+
name: `${prefix}_search`,
|
|
152
|
+
description: `Search this app's commands, pages and records (including live data sources). Returns matching items with ids you can pass to ${prefix}_run.`,
|
|
153
|
+
inputSchema: { type: "object", properties: { query: { type: "string", description: "What to look for" } }, required: ["query"] },
|
|
154
|
+
annotations: { readOnlyHint: !0, untrustedContentHint: !0 },
|
|
155
|
+
execute: async (args, opts) => {
|
|
156
|
+
let results = await bar.searchForAgent(String(args.query ?? ""), void 0, opts?.signal ?? new AbortController().signal, found);
|
|
157
|
+
return results.length ? JSON.stringify(results) : "No results.";
|
|
158
|
+
}
|
|
159
|
+
}), options.run !== !1 && register({
|
|
160
|
+
name: `${prefix}_run`,
|
|
161
|
+
description: "Open a page or run a command in this app by id (from list_commands or search). Destructive commands ask the user first.",
|
|
162
|
+
inputSchema: {
|
|
163
|
+
type: "object",
|
|
164
|
+
properties: {
|
|
165
|
+
id: { type: "string" },
|
|
166
|
+
arguments: { type: "object", description: "Values for the command arguments, if it has any.", additionalProperties: { type: "string" } }
|
|
167
|
+
},
|
|
168
|
+
required: ["id"]
|
|
169
|
+
},
|
|
170
|
+
execute: async (args) => {
|
|
171
|
+
let item = lookup(String(args.id ?? ""));
|
|
172
|
+
if (!item) return `No item with id "${String(args.id)}". Call ${prefix}_search or ${prefix}_list_commands first.`;
|
|
173
|
+
try {
|
|
174
|
+
return await bar.runForAgent(item, args.arguments, void 0, "agent");
|
|
175
|
+
} catch (err) {
|
|
176
|
+
return `Error: ${err instanceof Error ? err.message : String(err)}`;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}), options.tools !== !1)
|
|
180
|
+
for (let { tool, rt, prefix: ext } of bar.toolList())
|
|
181
|
+
register({
|
|
182
|
+
name: safeName(`${prefix}_${ext ? `${ext}_` : ""}${tool.name}`),
|
|
183
|
+
description: tool.description,
|
|
184
|
+
inputSchema: tool.parameters ?? { type: "object", properties: {} },
|
|
185
|
+
annotations: tool.confirm ? { consequentialHint: !0 } : void 0,
|
|
186
|
+
execute: async (args) => {
|
|
187
|
+
if (tool.confirm) {
|
|
188
|
+
let msg = typeof tool.confirm == "function" ? tool.confirm(args) : bar.t("allowTool", { tool: tool.name });
|
|
189
|
+
if (!await bar.confirm({ title: msg, confirmLabel: bar.t("allow") })) return "The user declined.";
|
|
190
|
+
}
|
|
191
|
+
let result = await tool.run(args, bar.toolContext(rt));
|
|
192
|
+
return typeof result == "string" ? result : JSON.stringify(result ?? "Done.");
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
return () => {
|
|
196
|
+
if (controller.abort(), typeof mc.unregisterTool == "function")
|
|
197
|
+
for (let name of names)
|
|
198
|
+
try {
|
|
199
|
+
mc.unregisterTool(name);
|
|
200
|
+
} catch {
|
|
201
|
+
}
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
|
|
121
205
|
// src/ui/views.ts
|
|
122
|
-
var VIRTUAL_THRESHOLD = 150, OVERSCAN = 10, optionId = (bar, key) => `${bar.instanceId}-opt-${key.replace(/[^\w-]/g, "_")}`;
|
|
206
|
+
var LONG_PRESS_MS = 480, VIRTUAL_THRESHOLD = 150, OVERSCAN = 10, optionId = (bar, key) => `${bar.instanceId}-opt-${key.replace(/[^\w-]/g, "_")}`;
|
|
123
207
|
function px(value, fallback) {
|
|
124
208
|
let n = parseFloat(value);
|
|
125
209
|
return Number.isFinite(n) && n > 0 ? n : fallback;
|
|
@@ -143,12 +227,15 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
143
227
|
__publicField(this, "sectionHeight", 30);
|
|
144
228
|
__publicField(this, "rafId", 0);
|
|
145
229
|
__publicField(this, "detailFor");
|
|
230
|
+
__publicField(this, "press");
|
|
146
231
|
__publicField(this, "onScroll", () => {
|
|
147
232
|
!this.virtual || this.rafId || (this.rafId = requestAnimationFrame(() => {
|
|
148
233
|
this.rafId = 0, this.renderWindow();
|
|
149
234
|
}));
|
|
150
235
|
});
|
|
151
236
|
__publicField(this, "onPointerMove", (e) => {
|
|
237
|
+
let p = this.press;
|
|
238
|
+
if (p && !p.fired && Math.hypot(e.clientX - p.x, e.clientY - p.y) > 8 && this.cancelPress(), e.pointerType !== "mouse") return;
|
|
152
239
|
let el = e.target.closest?.("[data-index]");
|
|
153
240
|
if (!el) return;
|
|
154
241
|
let index = Number(el.dataset.index);
|
|
@@ -156,17 +243,56 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
156
243
|
});
|
|
157
244
|
__publicField(this, "onClick", (e) => {
|
|
158
245
|
let el = e.target.closest?.("[data-index]");
|
|
159
|
-
|
|
246
|
+
if (!el) return;
|
|
247
|
+
if (this.press?.fired) {
|
|
248
|
+
this.press = void 0, e.stopPropagation();
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
let index = Number(el.dataset.index);
|
|
252
|
+
this.select(index, !1);
|
|
253
|
+
let item = this.frame.itemRows[index]?.item;
|
|
254
|
+
if (item && this.bar.isMulti(this.frame)) {
|
|
255
|
+
if (e.shiftKey) return this.bar.markRange(this.frame, item);
|
|
256
|
+
if (e.metaKey || e.ctrlKey) return this.bar.toggleMark(this.frame, item);
|
|
257
|
+
if (this.frame.marked?.size) return this.bar.toggleMark(this.frame, item);
|
|
258
|
+
}
|
|
259
|
+
this.bar.runPrimary(this.frame, e.metaKey || e.ctrlKey ? 1 : 0, "click");
|
|
260
|
+
});
|
|
261
|
+
/** Keep focus in the search box; on touch, a long press opens the actions. */
|
|
262
|
+
__publicField(this, "onPointerDown", (e) => {
|
|
263
|
+
if (e.preventDefault(), this.cancelPress(), e.pointerType === "mouse") return;
|
|
264
|
+
let el = e.target.closest?.("[data-index]");
|
|
265
|
+
if (!el) return;
|
|
266
|
+
let index = Number(el.dataset.index), press = {
|
|
267
|
+
x: e.clientX,
|
|
268
|
+
y: e.clientY,
|
|
269
|
+
fired: !1,
|
|
270
|
+
timer: setTimeout(() => {
|
|
271
|
+
press.fired = !0, this.select(index, !1), this.bar.openPanel(), navigator.vibrate?.(8);
|
|
272
|
+
}, LONG_PRESS_MS)
|
|
273
|
+
};
|
|
274
|
+
this.press = press;
|
|
275
|
+
});
|
|
276
|
+
__publicField(this, "cancelPress", (e) => {
|
|
277
|
+
let p = this.press;
|
|
278
|
+
p && (clearTimeout(p.timer), (!p.fired || e?.type === "pointercancel") && (this.press = void 0));
|
|
279
|
+
});
|
|
280
|
+
__publicField(this, "onContextMenu", (e) => {
|
|
281
|
+
let el = e.target.closest?.("[data-index]");
|
|
282
|
+
el && (e.preventDefault(), !(this.press?.fired || this.bar.panel) && (this.select(Number(el.dataset.index), !1), this.bar.openPanel()));
|
|
160
283
|
});
|
|
161
284
|
this.inner = h("div", { class: "qb-list-inner" }), this.scroller = h(
|
|
162
285
|
"div",
|
|
163
|
-
{ class: `${bar.cls("qb-scroll qb-list", "list")}`, role: "listbox", id: `${bar.instanceId}-list`, "aria-label": "
|
|
286
|
+
{ class: `${bar.cls("qb-scroll qb-list", "list")}`, role: "listbox", id: `${bar.instanceId}-list`, "aria-label": bar.t("results"), tabindex: "-1" },
|
|
164
287
|
this.inner
|
|
165
|
-
), this.emptyEl = h("div", { class: "qb-empty", hidden: !0 }), frame.view.type === "list" && frame.view.detail ? (this.detailEl = h("div", { class: bar.cls("qb-detail qb-md", "detail") }), this.el = h("div", { class: "qb-split", style: "display:flex;flex:1;min-width:0;position:relative" }, this.scroller, this.detailEl, this.emptyEl)) : this.el = h("div", { style: "display:flex;flex:1;min-width:0;position:relative" }, this.scroller, this.emptyEl), this.scroller.addEventListener("pointermove", this.onPointerMove), this.scroller.addEventListener("click", this.onClick), this.scroller.addEventListener("pointerdown", (
|
|
288
|
+
), this.emptyEl = h("div", { class: "qb-empty", hidden: !0 }), frame.view.type === "list" && frame.view.detail ? (this.detailEl = h("div", { class: bar.cls("qb-detail qb-md", "detail") }), this.el = h("div", { class: "qb-split", style: "display:flex;flex:1;min-width:0;position:relative" }, this.scroller, this.detailEl, this.emptyEl)) : this.el = h("div", { style: "display:flex;flex:1;min-width:0;position:relative" }, this.scroller, this.emptyEl), this.scroller.addEventListener("pointermove", this.onPointerMove), this.scroller.addEventListener("click", this.onClick), this.scroller.addEventListener("pointerdown", this.onPointerDown), this.scroller.addEventListener("pointerup", this.cancelPress), this.scroller.addEventListener("pointercancel", this.cancelPress), this.scroller.addEventListener("contextmenu", this.onContextMenu), this.scroller.addEventListener("scroll", this.onScroll, { passive: !0 });
|
|
166
289
|
}
|
|
167
290
|
measure() {
|
|
168
291
|
let cs = getComputedStyle(this.bar.dom.root);
|
|
169
|
-
this.rowHeight = px(cs.getPropertyValue("--qb-row-height"), 42), this.sectionHeight = px(cs.getPropertyValue("--qb-section-height"), 30);
|
|
292
|
+
this.rowHeight = px(cs.getPropertyValue("--qb-row-height"), 42), this.sectionHeight = px(cs.getPropertyValue("--qb-section-height"), 30), this.bar.isTouch && (this.rowHeight = Math.max(this.rowHeight, 48));
|
|
293
|
+
}
|
|
294
|
+
refresh() {
|
|
295
|
+
this.cache.clear(), this.inner.replaceChildren(), this.renderedKeys = [], this.selectedEl = void 0, this.update();
|
|
170
296
|
}
|
|
171
297
|
update() {
|
|
172
298
|
let rows = this.frame.rows, wasVirtual = this.virtual;
|
|
@@ -204,7 +330,13 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
204
330
|
sameKeys(keys, this.renderedKeys) || (this.inner.replaceChildren(...els), this.renderedKeys = keys), this.updateSelection();
|
|
205
331
|
}
|
|
206
332
|
rowSig(row) {
|
|
207
|
-
|
|
333
|
+
if (row.kind === "section") return row.title;
|
|
334
|
+
let sig = `${row.index}|${row.positions?.join(",") ?? ""}`;
|
|
335
|
+
if (this.frame.view.type === "root" && this.bar.personalize) {
|
|
336
|
+
let id = this.bar.idOf(row.item);
|
|
337
|
+
sig += `|${this.bar.aliasOf(id) ?? ""}|${this.bar.pins().includes(id) ? "p" : ""}`;
|
|
338
|
+
}
|
|
339
|
+
return sig;
|
|
208
340
|
}
|
|
209
341
|
rowEl(row) {
|
|
210
342
|
let sig = this.rowSig(row), cached = this.cache.get(row.key);
|
|
@@ -217,6 +349,10 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
217
349
|
}
|
|
218
350
|
itemEl(row) {
|
|
219
351
|
let { item } = row, isRoot = this.frame.view.type === "root", right = [];
|
|
352
|
+
if (isRoot && this.bar.personalize) {
|
|
353
|
+
let id = this.bar.idOf(item), alias = this.bar.aliasOf(id);
|
|
354
|
+
alias && right.push(h("span", { class: "qb-alias", title: this.bar.t("alias") }, alias)), this.bar.pins().includes(id) && right.push(h("span", { class: "qb-pin", title: this.bar.t("pinned") }, renderIcon("pin", 13)));
|
|
355
|
+
}
|
|
220
356
|
return item.accessories?.length ? right.push(h("span", { class: "qb-item-accessories" }, ...item.accessories.map(renderAccessory))) : item.shortcut && right.push(h("span", { class: "qb-item-accessories" }, renderKbd(item.shortcut))), isRoot && !item.accessories?.length && !item.shortcut && right.push(h("span", { class: "qb-item-kind" }, this.kindOf(item))), h(
|
|
221
357
|
"div",
|
|
222
358
|
{
|
|
@@ -226,6 +362,7 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
226
362
|
"aria-selected": "false",
|
|
227
363
|
"data-index": String(row.index)
|
|
228
364
|
},
|
|
365
|
+
this.bar.isMulti(this.frame) ? h("span", { class: "qb-check", "aria-hidden": "true" }, renderIcon("check", 12)) : null,
|
|
229
366
|
h("span", { class: "qb-item-icon" }, renderIcon(item.icon ?? (isRoot ? "command" : void 0), 16)),
|
|
230
367
|
h(
|
|
231
368
|
"span",
|
|
@@ -237,11 +374,17 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
237
374
|
);
|
|
238
375
|
}
|
|
239
376
|
kindOf(item) {
|
|
240
|
-
return this.bar.itemExt.get(item) ? "
|
|
377
|
+
return this.bar.itemExt.get(item) ? this.bar.t("kindCommand") : item.href ? this.bar.t("kindPage") : item.url ? this.bar.t("kindLink") : this.bar.t("kindCommand");
|
|
241
378
|
}
|
|
242
379
|
updateSelection() {
|
|
243
380
|
let row = this.frame.itemRows[this.frame.selected], el = row ? this.cache.get(row.key)?.el : void 0;
|
|
244
|
-
this.selectedEl && this.selectedEl !== el && this.selectedEl.setAttribute("aria-selected", "false"), el && el.setAttribute("aria-selected", "true"), this.selectedEl = el
|
|
381
|
+
if (this.selectedEl && this.selectedEl !== el && this.selectedEl.setAttribute("aria-selected", "false"), el && el.setAttribute("aria-selected", "true"), this.selectedEl = el, this.bar.isMulti(this.frame))
|
|
382
|
+
for (let r of this.frame.itemRows) {
|
|
383
|
+
let rowEl = this.cache.get(r.key)?.el;
|
|
384
|
+
if (!rowEl) continue;
|
|
385
|
+
let marked = this.bar.isMarked(this.frame, r.key);
|
|
386
|
+
marked ? rowEl.dataset.marked = "" : delete rowEl.dataset.marked, rowEl.setAttribute("aria-checked", marked ? "true" : "false");
|
|
387
|
+
}
|
|
245
388
|
}
|
|
246
389
|
updateEmpty() {
|
|
247
390
|
let f = this.frame, empty = f.itemRows.length === 0;
|
|
@@ -249,8 +392,8 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
249
392
|
this.emptyEl.hidden = !0;
|
|
250
393
|
return;
|
|
251
394
|
}
|
|
252
|
-
let view = f.view, icon = "search", title = "
|
|
253
|
-
f.error ? (icon = "alert", title = "
|
|
395
|
+
let view = f.view, icon = "search", title = this.bar.t("noResults"), desc = f.query ? this.bar.t("nothingMatches", { query: f.query }) : null;
|
|
396
|
+
f.error ? (icon = "alert", title = this.bar.t("loadFailed"), desc = f.error) : view.emptyView ? (icon = view.emptyView.icon ?? icon, title = view.emptyView.title, desc = view.emptyView.description ?? null) : f.view.type === "root" && !f.query && (title = this.bar.t("startTyping"), desc = null), this.emptyEl.replaceChildren(
|
|
254
397
|
renderIcon(icon, 28) ?? "",
|
|
255
398
|
h("div", { class: "qb-empty-title" }, title),
|
|
256
399
|
desc ? h("div", { class: "qb-empty-desc" }, desc) : ""
|
|
@@ -262,7 +405,7 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
262
405
|
let item = this.bar.selectedItem(this.frame);
|
|
263
406
|
if (item === this.detailFor) return;
|
|
264
407
|
if (this.detailFor = item, !item?.detail) {
|
|
265
|
-
pane.innerHTML = item?.description ?
|
|
408
|
+
pane.innerHTML = item?.description ? this.bar.md(item.description) : "";
|
|
266
409
|
return;
|
|
267
410
|
}
|
|
268
411
|
let value = detailCache.get(item);
|
|
@@ -270,9 +413,9 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
270
413
|
let d = item.detail;
|
|
271
414
|
value = typeof d == "function" ? Promise.resolve(d()) : d, detailCache.set(item, value);
|
|
272
415
|
}
|
|
273
|
-
typeof value == "string" ? pane.innerHTML =
|
|
416
|
+
typeof value == "string" ? pane.innerHTML = this.bar.md(value) : (pane.innerHTML = "", value.then(
|
|
274
417
|
(md) => {
|
|
275
|
-
detailCache.set(item, md), this.detailFor === item && (pane.innerHTML =
|
|
418
|
+
detailCache.set(item, md), this.detailFor === item && (pane.innerHTML = this.bar.md(md));
|
|
276
419
|
},
|
|
277
420
|
(err) => {
|
|
278
421
|
this.detailFor === item && (pane.textContent = String(err?.message ?? err));
|
|
@@ -308,10 +451,17 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
308
451
|
}
|
|
309
452
|
onKey(e) {
|
|
310
453
|
let k = e.key, mod = e.metaKey || e.ctrlKey;
|
|
454
|
+
if ((k === "ArrowDown" || k === "ArrowUp") && e.shiftKey && !mod && this.bar.isMulti(this.frame)) {
|
|
455
|
+
let current = this.frame.itemRows[this.frame.selected]?.item;
|
|
456
|
+
current && this.bar.toggleMark(this.frame, current, !0), this.move(k === "ArrowDown" ? 1 : -1);
|
|
457
|
+
let next = this.frame.itemRows[this.frame.selected]?.item;
|
|
458
|
+
return next && this.bar.toggleMark(this.frame, next, !0), !0;
|
|
459
|
+
}
|
|
311
460
|
if (k === "ArrowDown" && mod) return this.select(this.frame.itemRows.length - 1), !0;
|
|
312
461
|
if (k === "ArrowUp" && mod) return this.select(0), !0;
|
|
313
|
-
|
|
314
|
-
if (k === "
|
|
462
|
+
let emacs = e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey;
|
|
463
|
+
if (k === "ArrowDown" || emacs && (k === "n" || k === "j")) return this.move(1), !0;
|
|
464
|
+
if (k === "ArrowUp" || emacs && k === "p") return this.move(-1), !0;
|
|
315
465
|
if (k === "PageDown") return this.move(8), !0;
|
|
316
466
|
if (k === "PageUp") return this.move(-8), !0;
|
|
317
467
|
if (k === "Enter" && !mod && !e.altKey)
|
|
@@ -336,7 +486,7 @@ var detailCache = /* @__PURE__ */ new WeakMap(), ListRenderer = class {
|
|
|
336
486
|
this.scroller.scrollTop = 0;
|
|
337
487
|
}
|
|
338
488
|
destroy() {
|
|
339
|
-
cancelAnimationFrame(this.rafId);
|
|
489
|
+
cancelAnimationFrame(this.rafId), this.press && clearTimeout(this.press.timer);
|
|
340
490
|
}
|
|
341
491
|
};
|
|
342
492
|
function sameKeys(a, b) {
|
|
@@ -372,6 +522,7 @@ var GridRenderer = class extends ListRenderer {
|
|
|
372
522
|
return h(
|
|
373
523
|
"div",
|
|
374
524
|
{ class: this.bar.cls("qb-cell", "item"), role: "option", id: optionId(this.bar, row.key), "aria-selected": "false", "data-index": String(row.index), title: item.title },
|
|
525
|
+
this.bar.isMulti(this.frame) ? h("span", { class: "qb-check", "aria-hidden": "true" }, renderIcon("check", 12)) : null,
|
|
375
526
|
media,
|
|
376
527
|
h("div", { class: "qb-cell-title" }, highlight(item.title, row.positions)),
|
|
377
528
|
item.subtitle ? h("div", { class: "qb-cell-subtitle" }, item.subtitle) : null
|
|
@@ -433,7 +584,7 @@ var GridRenderer = class extends ListRenderer {
|
|
|
433
584
|
let key = `${d.text.length}|${d.done}|${d.error ?? ""}`;
|
|
434
585
|
if (key === this.rendered) return;
|
|
435
586
|
this.rendered = key;
|
|
436
|
-
let stick = this.body.scrollTop + this.body.clientHeight >= this.body.scrollHeight - 24, html =
|
|
587
|
+
let stick = this.body.scrollTop + this.body.clientHeight >= this.body.scrollHeight - 24, html = this.bar.md(d.text);
|
|
437
588
|
d.done || (html += '<span class="qb-caret"></span>'), d.error && (html += `<p class="qb-msg-error">${d.error.replace(/</g, "<")}</p>`), this.body.innerHTML = html, stick && !d.done && (this.body.scrollTop = this.body.scrollHeight);
|
|
438
589
|
}
|
|
439
590
|
onKey(e) {
|
|
@@ -443,13 +594,13 @@ var GridRenderer = class extends ListRenderer {
|
|
|
443
594
|
let d = this.frame.detail;
|
|
444
595
|
return [
|
|
445
596
|
{
|
|
446
|
-
title: "
|
|
597
|
+
title: this.bar.t("copyContent"),
|
|
447
598
|
icon: "copy",
|
|
448
599
|
shortcut: "mod+shift+c",
|
|
449
600
|
keepOpen: !0,
|
|
450
601
|
run: async (ctx) => {
|
|
451
602
|
let ok = await ctx.copy(d?.text ?? "");
|
|
452
|
-
return ctx.toast({ title: ok ? "
|
|
603
|
+
return ctx.toast({ title: ok ? this.bar.t("copied") : this.bar.t("copyFailed"), style: ok ? "success" : "failure" }), !1;
|
|
453
604
|
}
|
|
454
605
|
}
|
|
455
606
|
];
|
|
@@ -522,7 +673,7 @@ var GridRenderer = class extends ListRenderer {
|
|
|
522
673
|
form.errors = {};
|
|
523
674
|
for (let f of v.fields) {
|
|
524
675
|
let value = form.values[f.name];
|
|
525
|
-
if (f.required && (value === "" || value == null || value === !1)) form.errors[f.name] =
|
|
676
|
+
if (f.required && (value === "" || value == null || value === !1)) form.errors[f.name] = this.bar.t("fieldRequired", { field: f.label ?? f.name });
|
|
526
677
|
else {
|
|
527
678
|
let msg = f.validate?.(value, form.values);
|
|
528
679
|
msg && (form.errors[f.name] = msg);
|
|
@@ -535,7 +686,7 @@ var GridRenderer = class extends ListRenderer {
|
|
|
535
686
|
return;
|
|
536
687
|
}
|
|
537
688
|
this.bar.runAction(this.frame, void 0, {
|
|
538
|
-
title: v.submitLabel ?? "
|
|
689
|
+
title: v.submitLabel ?? this.bar.t("submit"),
|
|
539
690
|
run: (ctx) => v.onSubmit({ ...form.values }, ctx)
|
|
540
691
|
});
|
|
541
692
|
}
|
|
@@ -548,7 +699,7 @@ var GridRenderer = class extends ListRenderer {
|
|
|
548
699
|
return e.key === "Enter" && t.tagName === "INPUT" && t.type !== "checkbox" ? (this.submit(), !0) : !1;
|
|
549
700
|
}
|
|
550
701
|
footerPrimary() {
|
|
551
|
-
return { title: this.frame.view.submitLabel ?? "
|
|
702
|
+
return { title: this.frame.view.submitLabel ?? this.bar.t("submit"), hotkey: "mod+enter", run: () => this.submit() };
|
|
552
703
|
}
|
|
553
704
|
focusTarget() {
|
|
554
705
|
return this.el.contains(document.activeElement) ? document.activeElement : this.el.querySelector("input,textarea,select") ?? this.el;
|
|
@@ -598,20 +749,20 @@ var GridRenderer = class extends ListRenderer {
|
|
|
598
749
|
let icon = renderIcon(t.state === "running" ? "loader" : t.state === "done" ? "check" : "x", 12);
|
|
599
750
|
return t.state === "running" && icon.classList.add("qb-spin"), h("span", { class: "qb-tool", "data-state": t.state }, icon, t.label);
|
|
600
751
|
})
|
|
601
|
-
) : null, md = h("div", { class: "qb-md" }), html =
|
|
752
|
+
) : null, md = h("div", { class: "qb-md" }), html = this.bar.md(turn.text);
|
|
602
753
|
turn.streaming && (html += turn.text || !turn.tools.length ? '<span class="qb-caret"></span>' : ""), md.innerHTML = html, el = h("div", { class: "qb-msg-ai" }, head, tools, md, turn.error ? h("div", { class: "qb-msg-error" }, turn.error) : null);
|
|
603
754
|
}
|
|
604
755
|
existing ? existing.el.replaceWith(el) : this.el.append(el), this.turnEls[i] = { el, sig };
|
|
605
756
|
}), stick && (this.el.scrollTop = this.el.scrollHeight);
|
|
606
757
|
}
|
|
607
758
|
empty() {
|
|
608
|
-
let suggestions = this.bar.aiOptions?.suggestions ?? [], defaults = suggestions.length ? suggestions :
|
|
759
|
+
let suggestions = this.bar.aiOptions?.suggestions ?? [], defaults = suggestions.length ? suggestions : this.bar.t("chatSuggestions").split("|");
|
|
609
760
|
return h(
|
|
610
761
|
"div",
|
|
611
762
|
{ class: "qb-chat-empty" },
|
|
612
763
|
renderIcon("sparkles", 26),
|
|
613
|
-
h("div", { class: "qb-empty-title" },
|
|
614
|
-
h("div", { class: "qb-empty-desc" },
|
|
764
|
+
h("div", { class: "qb-empty-title" }, this.bar.t("askAnything")),
|
|
765
|
+
h("div", { class: "qb-empty-desc" }, this.bar.t("chatHint")),
|
|
615
766
|
h(
|
|
616
767
|
"div",
|
|
617
768
|
{ class: "qb-suggestions" },
|
|
@@ -635,28 +786,28 @@ var GridRenderer = class extends ListRenderer {
|
|
|
635
786
|
return e.key === "ArrowUp" && !this.frame.query ? (this.el.scrollTop -= 60, !0) : e.key === "ArrowDown" && !this.frame.query ? (this.el.scrollTop += 60, !0) : !1;
|
|
636
787
|
}
|
|
637
788
|
placeholder() {
|
|
638
|
-
return this.frame.chat?.turns.length ?? 0 ? "
|
|
789
|
+
return this.frame.chat?.turns.length ?? 0 ? this.bar.t("followUp") : this.bar.t("askAnythingPlaceholder");
|
|
639
790
|
}
|
|
640
791
|
footerPrimary() {
|
|
641
|
-
return this.frame.chat?.controller ? { title: "
|
|
792
|
+
return this.frame.chat?.controller ? { title: this.bar.t("stop"), hotkey: "escape", run: () => {
|
|
642
793
|
this.bar.stopChat(this.frame);
|
|
643
|
-
} } : { title: "
|
|
794
|
+
} } : { title: this.bar.t("send"), hotkey: "enter", run: () => this.bar.sendChat(this.frame, this.frame.query) };
|
|
644
795
|
}
|
|
645
796
|
viewActions() {
|
|
646
797
|
let view = this.frame.view;
|
|
647
798
|
return [
|
|
648
799
|
{
|
|
649
|
-
title: "
|
|
800
|
+
title: this.bar.t("copyAnswer"),
|
|
650
801
|
icon: "copy",
|
|
651
802
|
shortcut: "mod+shift+c",
|
|
652
803
|
keepOpen: !0,
|
|
653
804
|
run: async (ctx) => {
|
|
654
805
|
let ok = await copyText(this.lastAnswer());
|
|
655
|
-
return ctx.toast({ title: ok ? "
|
|
806
|
+
return ctx.toast({ title: ok ? this.bar.t("copiedAnswer") : this.bar.t("nothingToCopy"), style: ok ? "success" : "failure" }), !1;
|
|
656
807
|
}
|
|
657
808
|
},
|
|
658
809
|
{
|
|
659
|
-
title: "
|
|
810
|
+
title: this.bar.t("newChat"),
|
|
660
811
|
icon: "plus",
|
|
661
812
|
shortcut: "mod+shift+o",
|
|
662
813
|
run: (ctx) => (ctx.render({ ...view, type: "chat", prompt: void 0 }), !1)
|
|
@@ -718,6 +869,12 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
718
869
|
__publicField(this, "closeTimer");
|
|
719
870
|
__publicField(this, "destroyed", !1);
|
|
720
871
|
__publicField(this, "styleEl");
|
|
872
|
+
__publicField(this, "searchEventTimer");
|
|
873
|
+
__publicField(this, "webmcpCleanup");
|
|
874
|
+
__publicField(this, "labelCache");
|
|
875
|
+
// ─── Semantic search ─────────────────────────────────────────────────────
|
|
876
|
+
__publicField(this, "vectors", /* @__PURE__ */ new Map());
|
|
877
|
+
__publicField(this, "semanticWarned", !1);
|
|
721
878
|
// ─── Keyboard ────────────────────────────────────────────────────────────
|
|
722
879
|
__publicField(this, "onGlobalKeyDown", (e) => {
|
|
723
880
|
if (this.destroyed || e.defaultPrevented || e.isComposing) return;
|
|
@@ -726,14 +883,20 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
726
883
|
e.preventDefault(), e.stopPropagation(), this.isInline ? (this.open(), this.focusInput()) : this.toggle();
|
|
727
884
|
return;
|
|
728
885
|
}
|
|
729
|
-
if (this._open && !this.isInline || this.isInline && this.dom?.root.contains(e.target)
|
|
886
|
+
if (this._open && !this.isInline || this.isInline && this.dom?.root.contains(e.target)) return;
|
|
887
|
+
let ta = this.toastState?.act;
|
|
888
|
+
if (ta?.shortcut && !inField && matchesHotkey(e, ta.shortcut)) {
|
|
889
|
+
e.preventDefault(), this.runToastAction();
|
|
890
|
+
return;
|
|
891
|
+
}
|
|
892
|
+
if (this.config.shortcuts === !1 || (this.rootItems(), !this.shortcutItems.length)) return;
|
|
730
893
|
let candidates = this.shortcutItems.map((i) => i.shortcut).filter((s) => !inField || allowedInInput(s)), matched = this.seq.feed(e, candidates);
|
|
731
894
|
if (!matched.length) return;
|
|
732
895
|
let item = this.shortcutItems.find((i) => i.shortcut === matched[0]);
|
|
733
896
|
if (!item) return;
|
|
734
897
|
e.preventDefault();
|
|
735
898
|
let frame = this.createFrame({ type: "root" }), act = this.actionsFor(item, frame)[0];
|
|
736
|
-
act && this.runAction(frame, item, act);
|
|
899
|
+
act && this.runAction(frame, item, act, void 0, "shortcut");
|
|
737
900
|
});
|
|
738
901
|
__publicField(this, "onGlobalClick", (e) => {
|
|
739
902
|
let trigger = e.target?.closest?.("[data-qikbar-open]");
|
|
@@ -755,6 +918,11 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
755
918
|
e.stopPropagation();
|
|
756
919
|
return;
|
|
757
920
|
}
|
|
921
|
+
let ta = this.toastState?.act;
|
|
922
|
+
if (ta?.shortcut && matchesHotkey(e, ta.shortcut) && !(isEditable(e.target) && e.target.value)) {
|
|
923
|
+
e.preventDefault(), this.runToastAction();
|
|
924
|
+
return;
|
|
925
|
+
}
|
|
758
926
|
if (this.panel) {
|
|
759
927
|
this.onPanelKey(e) && (e.preventDefault(), e.stopPropagation());
|
|
760
928
|
return;
|
|
@@ -797,7 +965,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
797
965
|
}
|
|
798
966
|
e.key === "Backspace" && this.stack.length > 1 && e.target === this.dom?.input && !this.dom.input.value && !e.repeat && (e.preventDefault(), this.pop());
|
|
799
967
|
});
|
|
800
|
-
if (this.config = { ...config }, this.storageAdapter = config.storage ?? defaultStorage(), this.storage = scopedStorage(this.storageAdapter, config.namespace ?? "qikbar"), this.frecency = new Frecency(this.storage), this.applyConfig(config, !0), !(typeof document > "u") && (this.listen(document, "keydown", this.onGlobalKeyDown, !0), this.listen(document, "click", this.onGlobalClick, !0), this.inlineTarget())) {
|
|
968
|
+
if (this.config = { ...config }, this.storageAdapter = config.storage ?? defaultStorage(), this.storage = scopedStorage(this.storageAdapter, config.namespace ?? "qikbar"), this.frecency = new Frecency(this.storage), this.applyConfig(config, !0), !(typeof document > "u") && (this.listen(document, "keydown", this.onGlobalKeyDown, !0), this.listen(document, "click", this.onGlobalClick, !0), this.applyWebMCP(), this.inlineTarget())) {
|
|
801
969
|
let start = () => this.open({ focus: !1 });
|
|
802
970
|
document.readyState === "loading" ? this.listen(document, "DOMContentLoaded", start) : start();
|
|
803
971
|
}
|
|
@@ -815,18 +983,53 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
815
983
|
get isInline() {
|
|
816
984
|
return !!this.config.inline;
|
|
817
985
|
}
|
|
986
|
+
/** Touch-friendly mode: no keyboard hints, long-press for actions, bigger targets. */
|
|
987
|
+
get isTouch() {
|
|
988
|
+
let t = this.config.touch ?? "auto";
|
|
989
|
+
return t !== "auto" ? t : typeof matchMedia < "u" && matchMedia("(hover: none) and (pointer: coarse)").matches;
|
|
990
|
+
}
|
|
991
|
+
applyTouch() {
|
|
992
|
+
let root = this.dom?.root;
|
|
993
|
+
root && (this.isTouch ? root.dataset.qbTouch = "" : delete root.dataset.qbTouch);
|
|
994
|
+
}
|
|
995
|
+
/** Track the visible viewport so the bar stays above the on-screen keyboard. */
|
|
996
|
+
watchViewport() {
|
|
997
|
+
let vv = typeof window < "u" ? window.visualViewport : void 0;
|
|
998
|
+
if (!vv || this.isInline) return;
|
|
999
|
+
let update = () => {
|
|
1000
|
+
this._open && this.dom && this.dom.root.style.setProperty("--qb-vvh", `${Math.round(vv.height)}px`);
|
|
1001
|
+
};
|
|
1002
|
+
vv.addEventListener("resize", update), vv.addEventListener("scroll", update), this.teardown.push(() => {
|
|
1003
|
+
vv.removeEventListener("resize", update), vv.removeEventListener("scroll", update);
|
|
1004
|
+
}), update();
|
|
1005
|
+
}
|
|
818
1006
|
get aiName() {
|
|
819
1007
|
return this.aiOptions?.name ?? "AI";
|
|
820
1008
|
}
|
|
821
1009
|
get actionsHotkey() {
|
|
822
1010
|
return this.config.actionsHotkey ?? DEFAULT_ACTIONS_HOTKEY;
|
|
823
1011
|
}
|
|
1012
|
+
/** The active labels (English merged with `config.labels`). */
|
|
1013
|
+
get labels() {
|
|
1014
|
+
let src = this.config.labels;
|
|
1015
|
+
return (!this.labelCache || this.labelCache.src !== src) && (this.labelCache = { src, labels: src ? { ...en, ...src } : en }), this.labelCache.labels;
|
|
1016
|
+
}
|
|
1017
|
+
/** A translated label with `{placeholders}` filled in. `{ai}` is always available. */
|
|
1018
|
+
t(key, vars = {}) {
|
|
1019
|
+
return format(this.labels[key], { ai: this.aiName, ...vars });
|
|
1020
|
+
}
|
|
1021
|
+
/** Title of an action, translated when it's an untouched built-in. */
|
|
1022
|
+
actionTitle(act) {
|
|
1023
|
+
return act.labelKey && act.title === en[act.labelKey] ? this.t(act.labelKey) : act.title;
|
|
1024
|
+
}
|
|
824
1025
|
open(options = {}) {
|
|
825
1026
|
if (this.destroyed || typeof document > "u") return;
|
|
826
1027
|
if (this.mount(), clearTimeout(this.closeTimer), !this._open) {
|
|
827
1028
|
this._open = !0, this.prevFocus = document.activeElement, this.rootCache = null, this.autoIndex(), this.resetToRoot(), this.applyTheme();
|
|
828
1029
|
let dom = this.dom;
|
|
829
|
-
dom.root.dataset.qbState = "open"
|
|
1030
|
+
dom.root.dataset.qbState = "open";
|
|
1031
|
+
let vv = typeof window < "u" ? window.visualViewport : void 0;
|
|
1032
|
+
vv && !this.isInline && dom.root.style.setProperty("--qb-vvh", `${Math.round(vv.height)}px`), dom.overlay.hidden = this.isInline, dom.dialog.hidden = !1, this.isInline || this.lockScroll(), this.emit("open", void 0), this.config.onOpen?.(), this.track({ type: "open" });
|
|
830
1033
|
}
|
|
831
1034
|
options.view && this.push(options.view), options.query != null && this.setQuery(options.query), this.flush(), options.focus !== !1 && this.focusInput(), this.emitChange();
|
|
832
1035
|
}
|
|
@@ -848,7 +1051,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
848
1051
|
};
|
|
849
1052
|
typeof matchMedia < "u" && matchMedia("(prefers-reduced-motion: reduce)").matches ? finish() : this.closeTimer = setTimeout(finish, 120), this.unlockScroll();
|
|
850
1053
|
let prev = this.prevFocus;
|
|
851
|
-
prev && typeof prev.focus == "function" && document.contains(prev) && prev.focus({ preventScroll: !0 }), this.toastState && this.renderToast(), this.emit("close", void 0), this.config.onClose?.(), this.emitChange();
|
|
1054
|
+
prev && typeof prev.focus == "function" && document.contains(prev) && prev.focus({ preventScroll: !0 }), this.toastState && this.renderToast(), this.emit("close", void 0), this.config.onClose?.(), this.track({ type: "close" }), this.emitChange();
|
|
852
1055
|
}
|
|
853
1056
|
toggle() {
|
|
854
1057
|
this._open && !this.isInline ? this.close() : this.open();
|
|
@@ -901,7 +1104,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
901
1104
|
}
|
|
902
1105
|
configure(partial) {
|
|
903
1106
|
let prev = this.config;
|
|
904
|
-
this.config = { ...this.config, ...partial }, this.applyConfig(partial, !1, prev), this.dom && (("theme" in partial || "appearance" in partial) && this.applyTheme(), "classNames" in partial && this.applyClassNames(), "dir" in partial && (this.dom.root.dir = this.config.dir ?? "")), this.invalidateRoot();
|
|
1107
|
+
this.config = { ...this.config, ...partial }, this.applyConfig(partial, !1, prev), ("webmcp" in partial || "tools" in partial) && this.applyWebMCP(), this.dom && (("theme" in partial || "appearance" in partial) && this.applyTheme(), "classNames" in partial && this.applyClassNames(), "dir" in partial && (this.dom.root.dir = this.config.dir ?? ""), "touch" in partial && this.applyTouch(), "labels" in partial && this.renderer?.refresh?.()), this.invalidateRoot();
|
|
905
1108
|
}
|
|
906
1109
|
push(view, ext) {
|
|
907
1110
|
if (!this._open && (this.open(), !this._open))
|
|
@@ -922,7 +1125,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
922
1125
|
}
|
|
923
1126
|
ask(prompt) {
|
|
924
1127
|
if (!this.ai) {
|
|
925
|
-
this.toast({ style: "failure", title: "
|
|
1128
|
+
this.toast({ style: "failure", title: this.t("aiNotConfigured"), message: "Pass `ai` to createQikbar()." });
|
|
926
1129
|
return;
|
|
927
1130
|
}
|
|
928
1131
|
this.push({ type: "chat", prompt: prompt?.trim() || void 0 });
|
|
@@ -930,6 +1133,66 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
930
1133
|
commands() {
|
|
931
1134
|
return this.rootItems();
|
|
932
1135
|
}
|
|
1136
|
+
// ─── Pins & aliases ──────────────────────────────────────────────────────
|
|
1137
|
+
get personalize() {
|
|
1138
|
+
return this.config.personalize !== !1;
|
|
1139
|
+
}
|
|
1140
|
+
pins() {
|
|
1141
|
+
return this.storage.get("pins") ?? [];
|
|
1142
|
+
}
|
|
1143
|
+
pin(id, pinned = !this.pins().includes(id)) {
|
|
1144
|
+
let list = this.pins().filter((x) => x !== id);
|
|
1145
|
+
pinned && list.unshift(id), this.storage.set("pins", list);
|
|
1146
|
+
let item = this.rootItems().find((i) => this.idOf(i) === id);
|
|
1147
|
+
item && this.track({ type: pinned ? "pin" : "unpin", item: this.eventItem(item) }), this.invalidateRoot();
|
|
1148
|
+
}
|
|
1149
|
+
aliases() {
|
|
1150
|
+
return this.storage.get("aliases") ?? {};
|
|
1151
|
+
}
|
|
1152
|
+
aliasOf(id) {
|
|
1153
|
+
for (let [alias, target] of Object.entries(this.aliases())) if (target === id) return alias;
|
|
1154
|
+
}
|
|
1155
|
+
setAlias(id, alias) {
|
|
1156
|
+
let map = { ...this.aliases() };
|
|
1157
|
+
for (let [k, v] of Object.entries(map)) v === id && delete map[k];
|
|
1158
|
+
let clean = alias == null ? "" : normalizeAlias(alias);
|
|
1159
|
+
clean && (map[clean] = id), this.storage.set("aliases", map);
|
|
1160
|
+
let item = this.rootItems().find((i) => this.idOf(i) === id);
|
|
1161
|
+
item && this.track({ type: "alias", item: this.eventItem(item), alias: clean || null }), this.invalidateRoot();
|
|
1162
|
+
}
|
|
1163
|
+
/** Whether pin/alias actions apply to this item. */
|
|
1164
|
+
personalizable(item, frame) {
|
|
1165
|
+
return !this.personalize || frame.view.type !== "root" || isFallback(item) ? !1 : !this.idOf(item).startsWith("qikbar.") && this.rootItems().includes(item);
|
|
1166
|
+
}
|
|
1167
|
+
aliasForm(item) {
|
|
1168
|
+
let id = this.idOf(item), current = this.aliasOf(id);
|
|
1169
|
+
return {
|
|
1170
|
+
type: "form",
|
|
1171
|
+
title: item.title,
|
|
1172
|
+
submitLabel: this.t("save"),
|
|
1173
|
+
fields: [
|
|
1174
|
+
{
|
|
1175
|
+
name: "alias",
|
|
1176
|
+
label: this.t("alias"),
|
|
1177
|
+
placeholder: this.t("aliasPlaceholder"),
|
|
1178
|
+
description: this.t("aliasDescription", { title: item.title }),
|
|
1179
|
+
required: !0,
|
|
1180
|
+
defaultValue: current ?? "",
|
|
1181
|
+
validate: (value) => {
|
|
1182
|
+
let alias = normalizeAlias(String(value ?? "")), owner = this.aliases()[alias];
|
|
1183
|
+
if (owner && owner !== id) {
|
|
1184
|
+
let other = this.rootItems().find((i) => this.idOf(i) === owner);
|
|
1185
|
+
return this.t("aliasTaken", { alias, title: other?.title ?? owner });
|
|
1186
|
+
}
|
|
1187
|
+
}
|
|
1188
|
+
}
|
|
1189
|
+
],
|
|
1190
|
+
onSubmit: (values) => {
|
|
1191
|
+
let alias = normalizeAlias(String(values.alias ?? ""));
|
|
1192
|
+
return this.setAlias(id, alias), this.toast({ style: "success", title: this.t("aliasSaved", { alias }) }), this.pop(), !1;
|
|
1193
|
+
}
|
|
1194
|
+
};
|
|
1195
|
+
}
|
|
933
1196
|
on(event, handler) {
|
|
934
1197
|
let set = this.listeners.get(event);
|
|
935
1198
|
return set || this.listeners.set(event, set = /* @__PURE__ */ new Set()), set.add(handler), () => set.delete(handler);
|
|
@@ -943,17 +1206,17 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
943
1206
|
this.stack = [];
|
|
944
1207
|
for (let e of this.extensions.values()) e.cleanup?.();
|
|
945
1208
|
for (let fn of this.teardown) fn();
|
|
946
|
-
this.teardown = [], this.dom?.root.remove(), this.hud?.remove(), this.dom = void 0, this.listeners.clear();
|
|
1209
|
+
this.teardown = [], this.webmcpCleanup?.(), this.webmcpCleanup = void 0, clearTimeout(this.searchEventTimer), clearTimeout(this.toastTimer), this.dom?.root.remove(), this.hud?.remove(), this.dom = void 0, this.listeners.clear();
|
|
947
1210
|
}
|
|
948
1211
|
// ─── Config ──────────────────────────────────────────────────────────────
|
|
949
1212
|
applyConfig(partial, initial, prev) {
|
|
950
|
-
if (("routes" in partial || initial) && (this.routeItems = (this.config.routes ?? []).map((r) => ({
|
|
1213
|
+
if (("routes" in partial || "labels" in partial || initial) && (this.routeItems = (this.config.routes ?? []).map((r) => ({
|
|
951
1214
|
id: `route:${r.path}`,
|
|
952
1215
|
title: r.title,
|
|
953
1216
|
subtitle: r.subtitle,
|
|
954
1217
|
icon: r.icon ?? "arrow-right",
|
|
955
1218
|
keywords: [...r.keywords ?? [], r.path],
|
|
956
|
-
section: r.section ?? "
|
|
1219
|
+
section: r.section ?? this.t("navigation"),
|
|
957
1220
|
href: r.path,
|
|
958
1221
|
shortcut: r.shortcut
|
|
959
1222
|
}))), ("sources" in partial || initial) && (initial || prev?.sources !== this.config.sources)) {
|
|
@@ -972,6 +1235,11 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
972
1235
|
}
|
|
973
1236
|
}
|
|
974
1237
|
}
|
|
1238
|
+
applyWebMCP() {
|
|
1239
|
+
this.webmcpCleanup?.(), this.webmcpCleanup = void 0;
|
|
1240
|
+
let opt = this.config.webmcp;
|
|
1241
|
+
!opt || this.destroyed || (this.webmcpCleanup = exposeWebMCP(this, opt === !0 ? {} : opt));
|
|
1242
|
+
}
|
|
975
1243
|
inlineTarget() {
|
|
976
1244
|
let t = this.config.inline;
|
|
977
1245
|
return !t || typeof document > "u" ? null : typeof t == "string" ? document.querySelector(t) : t;
|
|
@@ -990,6 +1258,34 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
990
1258
|
let state = { open: this._open, query: this.query, depth: this.stack.length, loading: !!this.top?.loading };
|
|
991
1259
|
this.emit("change", state);
|
|
992
1260
|
}
|
|
1261
|
+
/** Report a usage event to `onEvent` and `on('event')`. */
|
|
1262
|
+
track(event) {
|
|
1263
|
+
try {
|
|
1264
|
+
this.config.onEvent?.(event);
|
|
1265
|
+
} catch (err) {
|
|
1266
|
+
console.error(err);
|
|
1267
|
+
}
|
|
1268
|
+
this.emit("event", event);
|
|
1269
|
+
}
|
|
1270
|
+
eventItem(item) {
|
|
1271
|
+
return { id: this.idOf(item), title: item.title, section: item.section };
|
|
1272
|
+
}
|
|
1273
|
+
/** Report what the user searched for once they stop typing. */
|
|
1274
|
+
scheduleSearchEvent(frame) {
|
|
1275
|
+
clearTimeout(this.searchEventTimer);
|
|
1276
|
+
let q = frame.query.trim();
|
|
1277
|
+
if (!q || !this.config.onEvent && !this.listeners.get("event")?.size) return;
|
|
1278
|
+
let tries = 0, fire = () => {
|
|
1279
|
+
if (frame !== this.top || frame.query.trim() !== q) return;
|
|
1280
|
+
if (frame.loading > 0 && tries++ < 10) {
|
|
1281
|
+
this.searchEventTimer = setTimeout(fire, 300);
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
let results = frame.itemRows.filter((r) => !isFallback(r.item)).length, view = frame.view.type;
|
|
1285
|
+
this.track({ type: "search", query: q, results, view }), results || this.track({ type: "no_results", query: q, view });
|
|
1286
|
+
};
|
|
1287
|
+
this.searchEventTimer = setTimeout(fire, 800);
|
|
1288
|
+
}
|
|
993
1289
|
listen(target, type, fn, capture = !1) {
|
|
994
1290
|
target.addEventListener(type, fn, capture), this.teardown.push(() => target.removeEventListener(type, fn, capture));
|
|
995
1291
|
}
|
|
@@ -999,8 +1295,9 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
999
1295
|
}
|
|
1000
1296
|
invalidateRoot() {
|
|
1001
1297
|
if (this.rootCache = null, this._open) {
|
|
1002
|
-
for (let f of this.stack)
|
|
1003
|
-
|
|
1298
|
+
for (let f of this.stack)
|
|
1299
|
+
f.actionCache = void 0, f.view.type === "root" && this.computeRows(f);
|
|
1300
|
+
this.renderer?.refresh?.(), this.invalidate();
|
|
1004
1301
|
}
|
|
1005
1302
|
}
|
|
1006
1303
|
rootItems() {
|
|
@@ -1023,8 +1320,8 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1023
1320
|
return this.ai && this.aiOptions?.fallback !== !1 && add(
|
|
1024
1321
|
{
|
|
1025
1322
|
id: "qikbar.ask-ai",
|
|
1026
|
-
title:
|
|
1027
|
-
subtitle: "
|
|
1323
|
+
title: this.t("askAi"),
|
|
1324
|
+
subtitle: this.t("askAiSubtitle"),
|
|
1028
1325
|
icon: "sparkles",
|
|
1029
1326
|
section: "AI",
|
|
1030
1327
|
keywords: ["chat", "assistant", "ai", "help"],
|
|
@@ -1056,7 +1353,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1056
1353
|
id: `auto:${href}`,
|
|
1057
1354
|
title,
|
|
1058
1355
|
subtitle: external ? a.host : raw.startsWith("#") ? raw : a.pathname,
|
|
1059
|
-
section: sectionEl?.dataset.qikbarSection ?? sectionEl?.getAttribute("aria-label") ?? o.section ?? "
|
|
1356
|
+
section: sectionEl?.dataset.qikbarSection ?? sectionEl?.getAttribute("aria-label") ?? o.section ?? this.t("pages"),
|
|
1060
1357
|
icon: external ? "globe" : "file",
|
|
1061
1358
|
keywords: [href],
|
|
1062
1359
|
...external ? { url: href } : { href }
|
|
@@ -1071,7 +1368,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1071
1368
|
title,
|
|
1072
1369
|
subtitle: el.dataset.qikbarSubtitle,
|
|
1073
1370
|
keywords: el.dataset.qikbarKeywords?.split(",").map((k) => k.trim()),
|
|
1074
|
-
section: el.dataset.qikbarSection ?? "
|
|
1371
|
+
section: el.dataset.qikbarSection ?? this.t("actions"),
|
|
1075
1372
|
icon: el.dataset.qikbarIcon ?? "zap",
|
|
1076
1373
|
shortcut: el.dataset.qikbarShortcut,
|
|
1077
1374
|
run: () => {
|
|
@@ -1154,19 +1451,27 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1154
1451
|
let q = frame.query.trim(), items = this.rootItems(), groups = [], bySection = /* @__PURE__ */ new Map(), group = (title) => {
|
|
1155
1452
|
let g = bySection.get(title);
|
|
1156
1453
|
return g || (g = { title, entries: [] }, bySection.set(title, g), groups.push(g)), g;
|
|
1157
|
-
};
|
|
1454
|
+
}, byId = () => new Map(items.map((i) => [this.idOf(i), i]));
|
|
1158
1455
|
if (!q) {
|
|
1159
|
-
let shown = /* @__PURE__ */ new Set()
|
|
1456
|
+
let shown = /* @__PURE__ */ new Set();
|
|
1457
|
+
if (this.personalize) {
|
|
1458
|
+
let map = byId();
|
|
1459
|
+
for (let id of this.pins()) {
|
|
1460
|
+
let item = map.get(id);
|
|
1461
|
+
!item || shown.has(item) || (group(this.t("pinned")).entries.push({ item }), shown.add(item));
|
|
1462
|
+
}
|
|
1463
|
+
}
|
|
1464
|
+
let recentsLimit = this.config.recents === !1 ? 0 : typeof this.config.recents == "number" ? this.config.recents : 4;
|
|
1160
1465
|
if (recentsLimit) {
|
|
1161
|
-
let
|
|
1162
|
-
for (let id of this.frecency.top(recentsLimit * 2)) {
|
|
1163
|
-
let item =
|
|
1164
|
-
if (!(!item || item.searchOnly) && (group("
|
|
1466
|
+
let map = byId(), added = 0;
|
|
1467
|
+
for (let id of this.frecency.top(recentsLimit * 2 + shown.size)) {
|
|
1468
|
+
let item = map.get(id);
|
|
1469
|
+
if (!(!item || item.searchOnly || shown.has(item)) && (group(this.t("recent")).entries.push({ item }), shown.add(item), ++added >= recentsLimit))
|
|
1165
1470
|
break;
|
|
1166
1471
|
}
|
|
1167
1472
|
}
|
|
1168
1473
|
for (let item of items)
|
|
1169
|
-
item.searchOnly || shown.has(item) || group(item.section ?? "
|
|
1474
|
+
item.searchOnly || shown.has(item) || group(item.section ?? this.t("commands")).entries.push({ item });
|
|
1170
1475
|
return groups;
|
|
1171
1476
|
}
|
|
1172
1477
|
let addSources = (position) => {
|
|
@@ -1174,25 +1479,36 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1174
1479
|
if ((source.position ?? "bottom") !== position) continue;
|
|
1175
1480
|
let results = frame.sourceResults?.get(source.id);
|
|
1176
1481
|
if (!results?.length) continue;
|
|
1177
|
-
let g = group(source.title ?? "
|
|
1482
|
+
let g = group(source.title ?? this.t("results")), list = source.filter ? rank(results, q) : results.map((item) => ({ item, positions: matchItem(item, q)?.positions }));
|
|
1178
1483
|
for (let r of list.slice(0, source.limit ?? 8)) g.entries.push({ item: r.item, positions: r.positions });
|
|
1179
1484
|
}
|
|
1180
|
-
};
|
|
1181
|
-
addSources("top");
|
|
1182
|
-
let
|
|
1183
|
-
|
|
1485
|
+
}, aliased = this.personalize ? this.aliases()[normalizeAlias(q)] : void 0, aliasItem = aliased ? byId().get(aliased) : void 0;
|
|
1486
|
+
aliasItem && group(aliasItem.section ?? this.t("commands")).entries.push({ item: aliasItem }), addSources("top");
|
|
1487
|
+
let pins = this.personalize ? new Set(this.pins()) : void 0, ranked = rank(items, q, {
|
|
1488
|
+
boost: (i) => {
|
|
1489
|
+
let id = this.idOf(i);
|
|
1490
|
+
return this.frecency.score(id) * 0.3 + (pins?.has(id) ? 0.15 : 0);
|
|
1491
|
+
},
|
|
1492
|
+
limit: 300
|
|
1493
|
+
});
|
|
1494
|
+
for (let r of ranked) r.item !== aliasItem && group(r.item.section ?? this.t("commands")).entries.push({ item: r.item, positions: r.positions });
|
|
1495
|
+
let related = this.relatedResults(frame, ranked.map((r) => r.item));
|
|
1496
|
+
if (related.length) {
|
|
1497
|
+
let g = group(this.t("related"));
|
|
1498
|
+
for (let item of related) item !== aliasItem && g.entries.push({ item });
|
|
1499
|
+
}
|
|
1184
1500
|
addSources("bottom");
|
|
1185
1501
|
let fallbacks = (this.config.fallbacks ?? []).map((f, i) => ({ ...f, id: `fallback:${i}`, title: f.title.replaceAll("{query}", q), subtitle: f.subtitle?.replaceAll("{query}", q) }));
|
|
1186
1502
|
if (this.ai && this.aiOptions?.fallback !== !1 && fallbacks.unshift({
|
|
1187
1503
|
id: "qikbar.ask-ai-fallback",
|
|
1188
|
-
title:
|
|
1504
|
+
title: this.t("askAi"),
|
|
1189
1505
|
subtitle: `\u201C${q.length > 60 ? `${q.slice(0, 60)}\u2026` : q}\u201D`,
|
|
1190
1506
|
icon: "sparkles",
|
|
1191
1507
|
accessories: [{ kbd: "tab" }],
|
|
1192
1508
|
noHistory: !0,
|
|
1193
1509
|
run: () => ({ type: "chat", prompt: q })
|
|
1194
1510
|
}), fallbacks.length) {
|
|
1195
|
-
let g = group(
|
|
1511
|
+
let g = group(this.t("useQueryWith", { query: q.length > 24 ? `${q.slice(0, 24)}\u2026` : q }));
|
|
1196
1512
|
for (let item of fallbacks) g.entries.push({ item });
|
|
1197
1513
|
}
|
|
1198
1514
|
return groups;
|
|
@@ -1210,7 +1526,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1210
1526
|
if (frame.query === query) return;
|
|
1211
1527
|
frame.query = query;
|
|
1212
1528
|
let v = frame.view;
|
|
1213
|
-
(v.type === "root" || v.type === "list" || v.type === "grid") && (frame.selected = 0, frame.selectedKey = void 0, frame.userMoved = !1, v.type === "root" ? this.searchSources(frame) : typeof v.items == "function" && this.loadItems(frame, !1), this.computeRows(frame), this.renderer?.resetScroll?.()), this.invalidate(), this.emitChange();
|
|
1529
|
+
(v.type === "root" || v.type === "list" || v.type === "grid") && (frame.selected = 0, frame.selectedKey = void 0, frame.userMoved = !1, v.type === "root" ? (this.searchSources(frame), this.searchSemantic(frame)) : typeof v.items == "function" && this.loadItems(frame, !1), this.computeRows(frame), this.renderer?.resetScroll?.(), this.scheduleSearchEvent(frame)), this.invalidate(), this.emitChange();
|
|
1214
1530
|
}
|
|
1215
1531
|
searchSources(frame) {
|
|
1216
1532
|
frame.queryController?.abort();
|
|
@@ -1242,6 +1558,52 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1242
1558
|
controller.signal.addEventListener("abort", () => clearTimeout(timer));
|
|
1243
1559
|
}
|
|
1244
1560
|
}
|
|
1561
|
+
/** Find items by meaning, in the background, and show them as "Related". */
|
|
1562
|
+
searchSemantic(frame) {
|
|
1563
|
+
let opt = this.config.semantic;
|
|
1564
|
+
if (frame.related = void 0, !opt) return;
|
|
1565
|
+
let q = frame.query.trim();
|
|
1566
|
+
if (q.length < (opt.minQueryLength ?? 3)) return;
|
|
1567
|
+
let signal = (frame.queryController ?? new AbortController()).signal, timer = setTimeout(async () => {
|
|
1568
|
+
if (!signal.aborted) {
|
|
1569
|
+
frame.loading++, this.invalidate();
|
|
1570
|
+
try {
|
|
1571
|
+
let candidates = this.rootItems().filter((i) => !this.idOf(i).startsWith("qikbar."));
|
|
1572
|
+
if (opt.sources) for (let list of frame.sourceResults?.values() ?? []) candidates.push(...list);
|
|
1573
|
+
let keyOf = (i) => this.rootItems().includes(i) ? this.idOf(i) : `src:${i.id ?? i.title}`, missing = candidates.filter((i) => this.vectors.get(keyOf(i))?.text !== embedText(i));
|
|
1574
|
+
for (let i = 0; i < missing.length; i += 128) {
|
|
1575
|
+
let batch = missing.slice(i, i + 128), vecs = await opt.embed(batch.map(embedText), { signal });
|
|
1576
|
+
if (signal.aborted) return;
|
|
1577
|
+
batch.forEach((item, n) => {
|
|
1578
|
+
let v = vecs[n];
|
|
1579
|
+
v && this.vectors.set(keyOf(item), { text: embedText(item), vec: normalize(v) });
|
|
1580
|
+
});
|
|
1581
|
+
}
|
|
1582
|
+
let [qv] = await opt.embed([q], { signal });
|
|
1583
|
+
if (signal.aborted || !qv) return;
|
|
1584
|
+
let query = normalize(qv), threshold = opt.threshold ?? 0.35, scored = [];
|
|
1585
|
+
for (let item of candidates) {
|
|
1586
|
+
let v = this.vectors.get(keyOf(item));
|
|
1587
|
+
if (!v) continue;
|
|
1588
|
+
let score = dot(query, v.vec);
|
|
1589
|
+
score >= threshold && scored.push({ item, score });
|
|
1590
|
+
}
|
|
1591
|
+
scored.sort((a, b) => b.score - a.score), frame.related = scored.slice(0, (opt.limit ?? 5) * 3), this.stack.includes(frame) && this.computeRows(frame);
|
|
1592
|
+
} catch (err) {
|
|
1593
|
+
!signal.aborted && !this.semanticWarned && (this.semanticWarned = !0, console.warn("[qikbar] semantic search failed", err));
|
|
1594
|
+
} finally {
|
|
1595
|
+
frame.loading--, this.invalidate();
|
|
1596
|
+
}
|
|
1597
|
+
}
|
|
1598
|
+
}, opt.debounce ?? 250);
|
|
1599
|
+
signal.addEventListener("abort", () => clearTimeout(timer));
|
|
1600
|
+
}
|
|
1601
|
+
/** Related results that the fuzzy search didn't already find. */
|
|
1602
|
+
relatedResults(frame, found) {
|
|
1603
|
+
if (!frame.related?.length) return [];
|
|
1604
|
+
let seen = new Set(found);
|
|
1605
|
+
return frame.related.filter((r) => !seen.has(r.item) && !r.item.searchOnly).slice(0, this.config.semantic?.limit ?? 5).map((r) => r.item);
|
|
1606
|
+
}
|
|
1245
1607
|
loadItems(frame, immediate) {
|
|
1246
1608
|
let v = frame.view;
|
|
1247
1609
|
if (typeof v.items != "function") return;
|
|
@@ -1324,7 +1686,11 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1324
1686
|
confirm: (options) => this.confirm(options),
|
|
1325
1687
|
setQuery: (q) => {
|
|
1326
1688
|
frame === this.top ? this.setQuery(q) : frame.query = q;
|
|
1327
|
-
}
|
|
1689
|
+
},
|
|
1690
|
+
get selection() {
|
|
1691
|
+
return frame.marked ? [...frame.marked.values()] : [];
|
|
1692
|
+
},
|
|
1693
|
+
labels: this.labels
|
|
1328
1694
|
};
|
|
1329
1695
|
}
|
|
1330
1696
|
navigate(href, newTab = !1) {
|
|
@@ -1335,31 +1701,60 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1335
1701
|
}
|
|
1336
1702
|
// ─── Actions ─────────────────────────────────────────────────────────────
|
|
1337
1703
|
actionsFor(item, frame) {
|
|
1704
|
+
if (frame.marked?.size) return this.bulkActions(frame);
|
|
1338
1705
|
let builtIn = this.renderer?.frame === frame ? this.renderer.viewActions?.() ?? [] : [], viewActions = [...frame.view.actions ?? [], ...builtIn];
|
|
1339
1706
|
if (!item) return viewActions;
|
|
1340
1707
|
frame.actionCache ?? (frame.actionCache = /* @__PURE__ */ new WeakMap());
|
|
1341
1708
|
let cached = frame.actionCache.get(item);
|
|
1342
1709
|
if (cached) return cached;
|
|
1343
1710
|
let acts = [];
|
|
1344
|
-
if (item.run && acts.push({ title: frame.view.type === "root" ? "
|
|
1711
|
+
if (item.run && acts.push({ title: frame.view.type === "root" ? this.t("runCommand") : this.t("run"), icon: "corner-down-left", run: item.run }), item.view) {
|
|
1345
1712
|
let view = item.view;
|
|
1346
|
-
acts.push({ title: "
|
|
1713
|
+
acts.push({ title: this.t("open"), icon: "chevron-right", run: (ctx) => typeof view == "function" ? view(ctx) : view });
|
|
1347
1714
|
}
|
|
1348
1715
|
if (item.href) {
|
|
1349
1716
|
let href = item.href;
|
|
1350
|
-
acts.push(action.navigate(href
|
|
1717
|
+
acts.push(action.navigate(href)), acts.push(action.navigateNewTab(href)), acts.push(action.copy(() => new URL(href, location.href).href, { title: this.t("copyLink"), icon: "link", shortcut: "mod+shift+c" }));
|
|
1351
1718
|
}
|
|
1352
|
-
item.url && (acts.push(action.open(item.url)), acts.push(action.copy(item.url, { title: "
|
|
1719
|
+
item.url && (acts.push(action.open(item.url)), acts.push(action.copy(item.url, { title: this.t("copyUrl"), icon: "link", shortcut: "mod+shift+c" }))), item.actions && acts.push(...item.actions), acts.push(...viewActions);
|
|
1353
1720
|
let rt = this.itemExt.get(item);
|
|
1354
|
-
|
|
1355
|
-
title:
|
|
1721
|
+
if (frame.view.type === "root" && rt?.ext.preferences?.length && acts.push({
|
|
1722
|
+
title: this.t("configure", { name: rt.ext.title }),
|
|
1356
1723
|
icon: "settings",
|
|
1357
|
-
section: "
|
|
1724
|
+
section: this.t("extension"),
|
|
1358
1725
|
run: () => this.preferencesForm(rt)
|
|
1359
|
-
}),
|
|
1360
|
-
title: "
|
|
1726
|
+
}), this.isMulti(frame) && acts.push({
|
|
1727
|
+
title: this.t("select"),
|
|
1728
|
+
icon: "check-square",
|
|
1729
|
+
shortcut: "mod+shift+x",
|
|
1730
|
+
keepOpen: !0,
|
|
1731
|
+
run: () => (this.toggleMark(frame, item), !1)
|
|
1732
|
+
}), this.personalizable(item, frame)) {
|
|
1733
|
+
let id = this.idOf(item), pinned = this.pins().includes(id), alias = this.aliasOf(id);
|
|
1734
|
+
acts.push({
|
|
1735
|
+
title: pinned ? this.t("unpin") : this.t("pin"),
|
|
1736
|
+
icon: "pin",
|
|
1737
|
+
section: this.t("customize"),
|
|
1738
|
+
shortcut: "mod+shift+p",
|
|
1739
|
+
keepOpen: !0,
|
|
1740
|
+
run: () => (this.pin(id, !pinned), !1)
|
|
1741
|
+
}), acts.push({
|
|
1742
|
+
title: alias ? this.t("editAlias") : this.t("setAlias"),
|
|
1743
|
+
icon: "at-sign",
|
|
1744
|
+
section: this.t("customize"),
|
|
1745
|
+
run: () => this.aliasForm(item)
|
|
1746
|
+
}), alias && acts.push({
|
|
1747
|
+
title: this.t("removeAlias"),
|
|
1748
|
+
icon: "x",
|
|
1749
|
+
section: this.t("customize"),
|
|
1750
|
+
keepOpen: !0,
|
|
1751
|
+
run: () => (this.setAlias(id, null), this.toast({ title: this.t("aliasRemoved") }), !1)
|
|
1752
|
+
});
|
|
1753
|
+
}
|
|
1754
|
+
return frame.view.type === "root" && this.frecency.score(this.idOf(item)) > 0 && acts.push({
|
|
1755
|
+
title: this.t("clearHistory"),
|
|
1361
1756
|
icon: "history",
|
|
1362
|
-
section: "
|
|
1757
|
+
section: this.t("history"),
|
|
1363
1758
|
keepOpen: !0,
|
|
1364
1759
|
run: () => (this.frecency.clear(), this.computeRows(frame), this.invalidate(), !1)
|
|
1365
1760
|
}), frame.actionCache.set(item, acts), acts;
|
|
@@ -1368,8 +1763,9 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1368
1763
|
if (frame)
|
|
1369
1764
|
return frame.itemRows[frame.selected]?.item;
|
|
1370
1765
|
}
|
|
1371
|
-
async runAction(frame, item, act, args) {
|
|
1372
|
-
|
|
1766
|
+
async runAction(frame, item, act, args, via = "keyboard") {
|
|
1767
|
+
let many = act.runMany && frame.marked?.size ? [...frame.marked.values()] : void 0;
|
|
1768
|
+
if (many && (item = void 0), item?.arguments?.length && !args) {
|
|
1373
1769
|
this.enterArgMode(frame, item, act);
|
|
1374
1770
|
return;
|
|
1375
1771
|
}
|
|
@@ -1378,7 +1774,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1378
1774
|
this.push(this.preferencesForm(rt, () => this.runAction(frame, item, act, args)), rt);
|
|
1379
1775
|
return;
|
|
1380
1776
|
}
|
|
1381
|
-
item && frame.view.type === "root" && !item.noHistory && this.frecency.record(this.idOf(item)), item
|
|
1777
|
+
item && frame.view.type === "root" && !item.noHistory && this.frecency.record(this.idOf(item)), item ? (this.config.onRun?.(item, act), this.emit("run", { item, action: act }), this.track({ type: "run", item: this.eventItem(item), action: this.actionTitle(act), via })) : many && this.track({ type: "run", item: this.eventItem(many[0]), action: this.actionTitle(act), via, count: many.length });
|
|
1382
1778
|
let handled = !1, base = this.makeContext(frame, { ext: rt, args }), ctx = Object.create(base, {
|
|
1383
1779
|
push: { value: (v) => (handled = !0, base.push(v)) },
|
|
1384
1780
|
render: { value: (v) => (handled = !0, base.render(v)) },
|
|
@@ -1389,25 +1785,79 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1389
1785
|
});
|
|
1390
1786
|
frame.loading++, this.invalidate();
|
|
1391
1787
|
try {
|
|
1392
|
-
let result = await act.run(ctx);
|
|
1393
|
-
isView(result) ? this.push(result, rt) : result === !1 || act.keepOpen || handled || this.close();
|
|
1788
|
+
let result = many ? await act.runMany(many, ctx) : await act.run(ctx);
|
|
1789
|
+
many && this.stack.includes(frame) && this.clearMarks(frame), isView(result) ? this.push(result, rt) : result === !1 || act.keepOpen || handled || this.close();
|
|
1394
1790
|
} catch (err) {
|
|
1395
|
-
console.error(err)
|
|
1791
|
+
console.error(err);
|
|
1792
|
+
let message = err instanceof Error ? err.message : String(err);
|
|
1793
|
+
this.track({ type: "error", message }), this.toast({ style: "failure", title: this.t("somethingWentWrong"), message });
|
|
1396
1794
|
} finally {
|
|
1397
1795
|
frame.loading--, this.invalidate();
|
|
1398
1796
|
}
|
|
1399
1797
|
}
|
|
1400
|
-
runPrimary(frame = this.top, index = 0) {
|
|
1798
|
+
runPrimary(frame = this.top, index = 0, via = "keyboard") {
|
|
1401
1799
|
if (!frame) return;
|
|
1402
1800
|
let item = this.selectedItem(frame), act = this.actionsFor(item, frame)[index];
|
|
1403
|
-
act && this.runAction(frame, item, act);
|
|
1801
|
+
act && this.runAction(frame, item, act, void 0, via);
|
|
1802
|
+
}
|
|
1803
|
+
// ─── Multi-select ────────────────────────────────────────────────────────
|
|
1804
|
+
isMulti(frame) {
|
|
1805
|
+
let v = frame.view;
|
|
1806
|
+
return (v.type === "list" || v.type === "grid") && !!v.multiSelect;
|
|
1807
|
+
}
|
|
1808
|
+
rowKeyOf(frame, item) {
|
|
1809
|
+
return frame.itemRows.find((r) => r.item === item)?.key;
|
|
1810
|
+
}
|
|
1811
|
+
isMarked(frame, key) {
|
|
1812
|
+
return !!frame.marked?.has(key);
|
|
1813
|
+
}
|
|
1814
|
+
toggleMark(frame, item, on) {
|
|
1815
|
+
if (!this.isMulti(frame)) return;
|
|
1816
|
+
let key = this.rowKeyOf(frame, item);
|
|
1817
|
+
if (!key) return;
|
|
1818
|
+
frame.marked ?? (frame.marked = /* @__PURE__ */ new Map()), on ?? !frame.marked.has(key) ? frame.marked.set(key, item) : frame.marked.delete(key), frame.anchor = key, this.marksChanged(frame);
|
|
1819
|
+
}
|
|
1820
|
+
/** Mark every row between the anchor and `item` (Shift-click). */
|
|
1821
|
+
markRange(frame, item) {
|
|
1822
|
+
if (!this.isMulti(frame)) return;
|
|
1823
|
+
let rows = frame.itemRows, to = rows.findIndex((r) => r.item === item), from = frame.anchor ? rows.findIndex((r) => r.key === frame.anchor) : -1;
|
|
1824
|
+
if (to < 0) return;
|
|
1825
|
+
frame.marked ?? (frame.marked = /* @__PURE__ */ new Map());
|
|
1826
|
+
let [a, b] = from < 0 ? [to, to] : from < to ? [from, to] : [to, from];
|
|
1827
|
+
for (let i = a; i <= b; i++) frame.marked.set(rows[i].key, rows[i].item);
|
|
1828
|
+
frame.anchor = rows[to].key, this.marksChanged(frame);
|
|
1829
|
+
}
|
|
1830
|
+
markAll(frame) {
|
|
1831
|
+
frame.marked ?? (frame.marked = /* @__PURE__ */ new Map());
|
|
1832
|
+
for (let r of frame.itemRows) frame.marked.set(r.key, r.item);
|
|
1833
|
+
this.marksChanged(frame);
|
|
1834
|
+
}
|
|
1835
|
+
clearMarks(frame) {
|
|
1836
|
+
frame.marked?.size && (frame.marked.clear(), frame.anchor = void 0, this.marksChanged(frame));
|
|
1837
|
+
}
|
|
1838
|
+
marksChanged(frame) {
|
|
1839
|
+
frame.actionCache = void 0, this.panel && frame === this.top && this.closePanel(), this.renderer?.refresh?.(), this.invalidate();
|
|
1840
|
+
let n = frame.marked?.size ?? 0;
|
|
1841
|
+
n && this.announce(this.t("selected", { count: n }));
|
|
1842
|
+
}
|
|
1843
|
+
bulkActions(frame) {
|
|
1844
|
+
let first = [...frame.marked.values()][0], marks = frame.marked;
|
|
1845
|
+
frame.marked = void 0;
|
|
1846
|
+
let base;
|
|
1847
|
+
try {
|
|
1848
|
+
base = this.actionsFor(first, frame);
|
|
1849
|
+
} finally {
|
|
1850
|
+
frame.marked = marks;
|
|
1851
|
+
}
|
|
1852
|
+
let bulk = base.filter((a) => a.runMany), builtIn = [];
|
|
1853
|
+
return frame.marked.size < frame.itemRows.length && builtIn.push({ title: this.t("selectAll"), icon: "check-square", shortcut: "mod+shift+a", keepOpen: !0, run: () => (this.markAll(frame), !1) }), builtIn.push({ title: this.t("clearSelection"), icon: "x", keepOpen: !0, run: () => (this.clearMarks(frame), !1) }), [...bulk, ...builtIn];
|
|
1404
1854
|
}
|
|
1405
1855
|
preferencesForm(rt, then) {
|
|
1406
1856
|
let values = rt.prefs();
|
|
1407
1857
|
return {
|
|
1408
1858
|
type: "form",
|
|
1409
|
-
title:
|
|
1410
|
-
submitLabel: then ? "
|
|
1859
|
+
title: this.t("configure", { name: rt.ext.title }),
|
|
1860
|
+
submitLabel: then ? this.t("saveAndContinue") : this.t("save"),
|
|
1411
1861
|
fields: (rt.ext.preferences ?? []).map((p) => ({
|
|
1412
1862
|
name: p.name,
|
|
1413
1863
|
label: p.title,
|
|
@@ -1420,7 +1870,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1420
1870
|
})),
|
|
1421
1871
|
onSubmit: (vals) => {
|
|
1422
1872
|
let stored = rt.storage.get("preferences") ?? {};
|
|
1423
|
-
return rt.storage.set("preferences", { ...stored, ...vals }), this.toast({ style: "success", title: "
|
|
1873
|
+
return rt.storage.set("preferences", { ...stored, ...vals }), this.toast({ style: "success", title: this.t("preferencesSaved") }), this.pop(), then?.(), !1;
|
|
1424
1874
|
}
|
|
1425
1875
|
};
|
|
1426
1876
|
}
|
|
@@ -1447,13 +1897,15 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1447
1897
|
let turn = { role: "assistant", text: "", tools: [], streaming: !0 };
|
|
1448
1898
|
chat.turns.push(turn), frame === this.top && this.dom && (this.dom.input.value = "", frame.query = ""), frame.loading++, this.invalidate();
|
|
1449
1899
|
let view = frame.view, useTools = view.tools !== !1 && this.aiOptions.tools !== !1;
|
|
1450
|
-
(async () => {
|
|
1900
|
+
this.track({ type: "ask_ai", prompt: text }), (async () => {
|
|
1451
1901
|
try {
|
|
1902
|
+
let tools = useTools ? await this.agentTools(frame, controller.signal) : [];
|
|
1903
|
+
if (controller.signal.aborted) return;
|
|
1452
1904
|
for await (let ev of runAgent({
|
|
1453
1905
|
provider: this.aiOptions.provider,
|
|
1454
1906
|
messages: chat.messages,
|
|
1455
1907
|
system: view.system ?? this.systemPrompt(useTools),
|
|
1456
|
-
tools
|
|
1908
|
+
tools,
|
|
1457
1909
|
maxSteps: this.aiOptions.maxSteps ?? 6,
|
|
1458
1910
|
signal: controller.signal
|
|
1459
1911
|
})) {
|
|
@@ -1503,7 +1955,49 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1503
1955
|
return this.aiOptions?.system && lines.push("", this.aiOptions.system), lines.join(`
|
|
1504
1956
|
`);
|
|
1505
1957
|
}
|
|
1506
|
-
|
|
1958
|
+
/**
|
|
1959
|
+
* Run an item on behalf of an AI model (chat or WebMCP agent) and describe what happened.
|
|
1960
|
+
* Navigation happens without closing a chat; destructive primary actions ask first.
|
|
1961
|
+
*/
|
|
1962
|
+
async runForAgent(item, rawArgs, frame, via) {
|
|
1963
|
+
let ctxFrame = frame ?? this.createFrame({ type: "root" }), rt = this.itemExt.get(item);
|
|
1964
|
+
if (rt?.missing().length) throw new Error(`${rt.ext.title} needs to be configured first. Ask the user to open it from the command bar.`);
|
|
1965
|
+
let act = this.actionsFor(item, this.stack[0] ?? ctxFrame)[0];
|
|
1966
|
+
if (!act) throw new Error("This item has no action.");
|
|
1967
|
+
if (act.style === "destructive" && !await this.confirm({ title: `${this.actionTitle(act)}?`, message: item.title, destructive: !0, confirmLabel: this.actionTitle(act) }))
|
|
1968
|
+
return "The user cancelled.";
|
|
1969
|
+
if (this.track({ type: "run", item: this.eventItem(item), action: this.actionTitle(act), via }), item.href) {
|
|
1970
|
+
let nav = this.config.navigate;
|
|
1971
|
+
return nav ? nav(item.href, { newTab: !1 }) : defaultNavigate(item.href, !1), this.frecency.record(this.idOf(item)), `Navigated to ${item.href}.`;
|
|
1972
|
+
}
|
|
1973
|
+
if (item.url)
|
|
1974
|
+
return window.open(item.url, "_blank", "noopener,noreferrer"), `Opened ${item.url} in a new tab.`;
|
|
1975
|
+
let strArgs = Object.fromEntries(Object.entries(rawArgs ?? {}).map(([k, v]) => [k, String(v)])), ctx = Object.create(this.makeContext(ctxFrame, { ext: rt, args: strArgs }), {
|
|
1976
|
+
close: { value: () => {
|
|
1977
|
+
} }
|
|
1978
|
+
}), result = await act.run(ctx);
|
|
1979
|
+
return this.frecency.record(this.idOf(item)), isView(result) ? (this.push(result, rt), `Opened the "${item.title}" view for the user.`) : `Ran "${item.title}".`;
|
|
1980
|
+
}
|
|
1981
|
+
/** Search commands and sources for an AI model. Results carry ids for `run`. */
|
|
1982
|
+
async searchForAgent(q, frame, signal, found) {
|
|
1983
|
+
let ctxFrame = frame ?? this.createFrame({ type: "root" }), local = rank(this.rootItems(), q, { limit: 10 }).map((r) => r.item), remote = await Promise.all(
|
|
1984
|
+
[...this.sources].map(async (s) => {
|
|
1985
|
+
if (q.length < (s.minQueryLength ?? 1)) return [];
|
|
1986
|
+
try {
|
|
1987
|
+
let rt = this.sourceExt.get(s), items = await withTimeout(s.search({ query: q, signal, ctx: this.makeContext(ctxFrame, { ext: rt, signal }) }), 6e3);
|
|
1988
|
+
if (rt) for (let i of items) this.itemExt.set(i, rt);
|
|
1989
|
+
return items.slice(0, s.limit ?? 8).map((i) => ({ item: i, section: s.title ?? s.id }));
|
|
1990
|
+
} catch {
|
|
1991
|
+
return [];
|
|
1992
|
+
}
|
|
1993
|
+
})
|
|
1994
|
+
);
|
|
1995
|
+
return [...local.map((item) => ({ item, section: item.section ?? "Commands" })), ...remote.flat()].map(({ item, section }, n) => {
|
|
1996
|
+
let id = this.rootItems().includes(item) ? this.idOf(item) : item.id && !found.has(item.id) ? item.id : `${section}#${n}`;
|
|
1997
|
+
return found.set(id, item), { id, title: item.title, subtitle: item.subtitle, section, description: item.description, href: item.href ?? item.url };
|
|
1998
|
+
});
|
|
1999
|
+
}
|
|
2000
|
+
async agentTools(chatFrame, signal) {
|
|
1507
2001
|
let found = /* @__PURE__ */ new Map(), lookup = (id) => found.get(id) ?? this.rootItems().find((i) => this.idOf(i) === id), tools = [
|
|
1508
2002
|
{
|
|
1509
2003
|
definition: {
|
|
@@ -1512,23 +2006,9 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1512
2006
|
parameters: { type: "object", properties: { query: { type: "string", description: "What to look for" } }, required: ["query"] }
|
|
1513
2007
|
},
|
|
1514
2008
|
label: (a) => `Searching \u201C${String(a.query ?? "")}\u201D`,
|
|
1515
|
-
run: async (args,
|
|
1516
|
-
let
|
|
1517
|
-
|
|
1518
|
-
if (q.length < (s.minQueryLength ?? 1)) return [];
|
|
1519
|
-
try {
|
|
1520
|
-
let rt = this.sourceExt.get(s), items = await withTimeout(s.search({ query: q, signal, ctx: this.makeContext(chatFrame, { ext: rt, signal }) }), 6e3);
|
|
1521
|
-
if (rt) for (let i of items) this.itemExt.set(i, rt);
|
|
1522
|
-
return items.slice(0, s.limit ?? 8).map((i) => ({ item: i, section: s.title ?? s.id }));
|
|
1523
|
-
} catch {
|
|
1524
|
-
return [];
|
|
1525
|
-
}
|
|
1526
|
-
})
|
|
1527
|
-
), all = [...local.map((item) => ({ item, section: item.section ?? "Commands" })), ...remote.flat()];
|
|
1528
|
-
return all.length ? all.map(({ item, section }, n) => {
|
|
1529
|
-
let id = item.id && !found.has(item.id) ? item.id : `${section}#${n}`;
|
|
1530
|
-
return found.set(id, item), { id, title: item.title, subtitle: item.subtitle, section, description: item.description, href: item.href ?? item.url };
|
|
1531
|
-
}) : "No results.";
|
|
2009
|
+
run: async (args, signal2) => {
|
|
2010
|
+
let results = await this.searchForAgent(String(args.query ?? ""), chatFrame, signal2, found);
|
|
2011
|
+
return results.length ? results : "No results.";
|
|
1532
2012
|
}
|
|
1533
2013
|
},
|
|
1534
2014
|
{
|
|
@@ -1551,23 +2031,7 @@ var VIEW_TYPES = /* @__PURE__ */ new Set(["list", "grid", "detail", "form", "cha
|
|
|
1551
2031
|
run: async (args) => {
|
|
1552
2032
|
let item = lookup(String(args.id ?? ""));
|
|
1553
2033
|
if (!item) throw new Error(`No item with id "${String(args.id)}". Use search first.`);
|
|
1554
|
-
|
|
1555
|
-
if (rt?.missing().length) throw new Error(`${rt.ext.title} needs to be configured first. Ask the user to open it from the command bar.`);
|
|
1556
|
-
let act = this.actionsFor(item, this.stack[0] ?? chatFrame)[0];
|
|
1557
|
-
if (!act) throw new Error("This item has no action.");
|
|
1558
|
-
if (act.style === "destructive" && !await this.confirm({ title: `${act.title}?`, message: item.title, destructive: !0, confirmLabel: act.title }))
|
|
1559
|
-
return "The user cancelled.";
|
|
1560
|
-
if (item.href) {
|
|
1561
|
-
let nav = this.config.navigate;
|
|
1562
|
-
return nav ? nav(item.href, { newTab: !1 }) : defaultNavigate(item.href, !1), this.frecency.record(this.idOf(item)), `Navigated to ${item.href}.`;
|
|
1563
|
-
}
|
|
1564
|
-
if (item.url)
|
|
1565
|
-
return window.open(item.url, "_blank", "noopener,noreferrer"), `Opened ${item.url} in a new tab.`;
|
|
1566
|
-
let strArgs = Object.fromEntries(Object.entries(args.arguments ?? {}).map(([k, v]) => [k, String(v)])), ctx = Object.create(this.makeContext(chatFrame, { ext: rt, args: strArgs }), {
|
|
1567
|
-
close: { value: () => {
|
|
1568
|
-
} }
|
|
1569
|
-
}), result = await act.run(ctx);
|
|
1570
|
-
return this.frecency.record(this.idOf(item)), isView(result) ? (this.push(result, rt), `Opened the "${item.title}" view for the user.`) : `Ran "${item.title}".`;
|
|
2034
|
+
return this.runForAgent(item, args.arguments, chatFrame, "ai");
|
|
1571
2035
|
}
|
|
1572
2036
|
}
|
|
1573
2037
|
];
|
|
@@ -1599,8 +2063,8 @@ ${text.slice(0, 2e4)}`;
|
|
|
1599
2063
|
label: () => tool.description.split(/[.\n]/)[0].slice(0, 60),
|
|
1600
2064
|
run: async (args) => {
|
|
1601
2065
|
if (tool.confirm) {
|
|
1602
|
-
let msg = typeof tool.confirm == "function" ? tool.confirm(args) :
|
|
1603
|
-
if (!await this.confirm({ title: msg, confirmLabel: "
|
|
2066
|
+
let msg = typeof tool.confirm == "function" ? tool.confirm(args) : this.t("allowTool", { tool: tool.name });
|
|
2067
|
+
if (!await this.confirm({ title: msg, confirmLabel: this.t("allow") })) return "The user declined.";
|
|
1604
2068
|
}
|
|
1605
2069
|
return tool.run(args, this.makeContext(chatFrame, { ext: rt }));
|
|
1606
2070
|
}
|
|
@@ -1608,26 +2072,56 @@ ${text.slice(0, 2e4)}`;
|
|
|
1608
2072
|
};
|
|
1609
2073
|
addTools(this.config.tools ?? [], void 0, "");
|
|
1610
2074
|
for (let e of this.extensions.values()) addTools(e.rt.ext.tools ?? [], e.rt, e.rt.ext.name);
|
|
2075
|
+
for (let provider of this.aiOptions?.mcp ?? [])
|
|
2076
|
+
try {
|
|
2077
|
+
addTools(await withTimeout(provider.tools(signal), 1e4), void 0, provider.name);
|
|
2078
|
+
} catch (err) {
|
|
2079
|
+
signal?.aborted || console.warn(`[qikbar] tools from "${provider.name}" are unavailable`, err);
|
|
2080
|
+
}
|
|
1611
2081
|
return tools;
|
|
1612
2082
|
}
|
|
2083
|
+
/** Every tool from config and extensions, with the extension it belongs to. */
|
|
2084
|
+
toolList() {
|
|
2085
|
+
let out = (this.config.tools ?? []).map((tool) => ({ tool, prefix: "" }));
|
|
2086
|
+
for (let e of this.extensions.values()) for (let tool of e.rt.ext.tools ?? []) out.push({ tool, rt: e.rt, prefix: e.rt.ext.name });
|
|
2087
|
+
return out;
|
|
2088
|
+
}
|
|
2089
|
+
/** Make a context for running a tool outside a chat (WebMCP). */
|
|
2090
|
+
toolContext(rt) {
|
|
2091
|
+
return this.makeContext(this.top ?? this.createFrame({ type: "root" }), { ext: rt });
|
|
2092
|
+
}
|
|
1613
2093
|
// ─── Toasts & confirm ────────────────────────────────────────────────────
|
|
1614
2094
|
toast(options) {
|
|
1615
|
-
let opts = typeof options == "string" ? { title: options } : options, id = ++this.toastId, schedule = () => {
|
|
2095
|
+
let opts = typeof options == "string" ? { title: options } : options, id = ++this.toastId, resolveAct = (o) => o.action ?? (o.undo ? { title: this.t("undo"), shortcut: "mod+z", run: o.undo } : void 0), schedule = () => {
|
|
1616
2096
|
clearTimeout(this.toastTimer);
|
|
1617
2097
|
let s = this.toastState;
|
|
1618
2098
|
if (!s) return;
|
|
1619
|
-
let duration = s.duration ?? (s.style === "loading" ? 0 : 2600);
|
|
2099
|
+
let duration = s.duration ?? (s.style === "loading" ? 0 : s.act ? 6e3 : 2600);
|
|
1620
2100
|
duration > 0 && (this.toastTimer = setTimeout(() => hide(), duration));
|
|
1621
2101
|
}, hide = () => {
|
|
1622
2102
|
this.toastState?.id === id && (this.toastState = void 0, this.renderToast());
|
|
1623
2103
|
};
|
|
1624
|
-
return this.toastState = { ...opts, id }, schedule(), this.renderToast(), {
|
|
2104
|
+
return this.toastState = { ...opts, id, act: resolveAct(opts) }, schedule(), this.renderToast(), {
|
|
1625
2105
|
update: (p) => {
|
|
1626
|
-
this.toastState?.id
|
|
2106
|
+
if (this.toastState?.id !== id) return;
|
|
2107
|
+
let next = { ...this.toastState, ...p };
|
|
2108
|
+
this.toastState = { ...next, act: resolveAct(next) }, schedule(), this.renderToast();
|
|
1627
2109
|
},
|
|
1628
2110
|
hide
|
|
1629
2111
|
};
|
|
1630
2112
|
}
|
|
2113
|
+
/** Run the visible toast's action (e.g. Undo) and dismiss the toast. */
|
|
2114
|
+
async runToastAction() {
|
|
2115
|
+
let t = this.toastState, act = t?.act;
|
|
2116
|
+
if (!(!t || !act)) {
|
|
2117
|
+
clearTimeout(this.toastTimer), this.toastState = void 0, this.renderToast();
|
|
2118
|
+
try {
|
|
2119
|
+
await act.run(), t.undo && !t.action && this.track({ type: "undo", title: t.title });
|
|
2120
|
+
} catch (err) {
|
|
2121
|
+
console.error(err), this.toast({ style: "failure", title: this.t("somethingWentWrong"), message: err instanceof Error ? err.message : String(err) });
|
|
2122
|
+
}
|
|
2123
|
+
}
|
|
2124
|
+
}
|
|
1631
2125
|
confirm(options) {
|
|
1632
2126
|
let opts = typeof options == "string" ? { title: options } : options;
|
|
1633
2127
|
return !this._open || !this.dom ? Promise.resolve(typeof window < "u" ? window.confirm(opts.message ? `${opts.title}
|
|
@@ -1644,6 +2138,7 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1644
2138
|
escape() {
|
|
1645
2139
|
let frame = this.top;
|
|
1646
2140
|
if (frame && !(frame.chat && this.stopChat(frame))) {
|
|
2141
|
+
if (frame.marked?.size) return this.clearMarks(frame);
|
|
1647
2142
|
if (this.stack.length > 1) return this.pop();
|
|
1648
2143
|
if (frame.query) return this.setQuery("");
|
|
1649
2144
|
this.close();
|
|
@@ -1654,7 +2149,7 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1654
2149
|
let frame = this.top;
|
|
1655
2150
|
if (!frame || !this.dom) return;
|
|
1656
2151
|
if (this.panel) return this.closePanel();
|
|
1657
|
-
let item = this.selectedItem(frame), actions = this.actionsFor(item, frame);
|
|
2152
|
+
let item = frame.marked?.size ? void 0 : this.selectedItem(frame), actions = this.actionsFor(item, frame);
|
|
1658
2153
|
actions.length && (this.panel = { item, actions, filter: "", selected: 0 }, this.renderPanel());
|
|
1659
2154
|
}
|
|
1660
2155
|
closePanel() {
|
|
@@ -1668,9 +2163,10 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1668
2163
|
let p = this.panel, list = this.panelActions();
|
|
1669
2164
|
if (e.key === "Escape" || matchesHotkey(e, this.actionsHotkey))
|
|
1670
2165
|
return this.closePanel(), !0;
|
|
1671
|
-
|
|
2166
|
+
let emacs = e.ctrlKey && !e.metaKey && !e.altKey && !e.shiftKey;
|
|
2167
|
+
if (e.key === "ArrowDown" || emacs && e.key === "n")
|
|
1672
2168
|
return p.selected = (p.selected + 1) % Math.max(1, list.length), this.renderPanel(), !0;
|
|
1673
|
-
if (e.key === "ArrowUp" ||
|
|
2169
|
+
if (e.key === "ArrowUp" || emacs && e.key === "p")
|
|
1674
2170
|
return p.selected = (p.selected - 1 + list.length) % Math.max(1, list.length), this.renderPanel(), !0;
|
|
1675
2171
|
if (e.key === "Enter") {
|
|
1676
2172
|
let act = list[p.selected];
|
|
@@ -1683,15 +2179,15 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1683
2179
|
}
|
|
1684
2180
|
runFromPanel(act) {
|
|
1685
2181
|
let item = this.panel?.item, frame = this.top;
|
|
1686
|
-
this.closePanel(), this.runAction(frame, item, act);
|
|
2182
|
+
this.closePanel(), this.runAction(frame, item, act, void 0, "panel");
|
|
1687
2183
|
}
|
|
1688
2184
|
renderPanel() {
|
|
1689
2185
|
let p = this.panel, dom = this.dom;
|
|
1690
2186
|
if (!p || !dom) return;
|
|
1691
2187
|
p.el || (p.list = h("div", { class: "qb-actions-list", role: "listbox", id: `${this.instanceId}-actions` }), p.input = h("input", {
|
|
1692
2188
|
class: "qb-actions-input",
|
|
1693
|
-
placeholder: "
|
|
1694
|
-
"aria-label": "
|
|
2189
|
+
placeholder: this.t("searchActions"),
|
|
2190
|
+
"aria-label": this.t("searchActions"),
|
|
1695
2191
|
autocomplete: "off",
|
|
1696
2192
|
spellcheck: "false",
|
|
1697
2193
|
onInput: () => {
|
|
@@ -1699,13 +2195,13 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1699
2195
|
}
|
|
1700
2196
|
}), p.el = h(
|
|
1701
2197
|
"div",
|
|
1702
|
-
{ class: this.cls("qb-actions", "actions"), role: "dialog", "aria-label": "
|
|
1703
|
-
h("div", { class: "qb-actions-title" }, p.item?.title ?? "
|
|
2198
|
+
{ class: this.cls("qb-actions", "actions"), role: "dialog", "aria-label": this.t("actions") },
|
|
2199
|
+
h("div", { class: "qb-actions-title" }, p.item?.title ?? (this.top?.marked?.size ? this.t("selected", { count: this.top.marked.size }) : this.t("actions"))),
|
|
1704
2200
|
p.list,
|
|
1705
2201
|
p.input
|
|
1706
2202
|
), p.el.addEventListener("pointerdown", (e) => {
|
|
1707
2203
|
e.target !== p.input && e.preventDefault();
|
|
1708
|
-
}), dom.dialog.append(p.el), p.input.focus());
|
|
2204
|
+
}), dom.dialog.append(p.el), this.isTouch || p.input.focus());
|
|
1709
2205
|
let list = this.panelActions();
|
|
1710
2206
|
p.selected = Math.min(p.selected, Math.max(0, list.length - 1));
|
|
1711
2207
|
let children = [], section;
|
|
@@ -1725,11 +2221,11 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1725
2221
|
}
|
|
1726
2222
|
},
|
|
1727
2223
|
renderIcon(act.icon ?? "dot", 15),
|
|
1728
|
-
h("span", { class: "qb-action-title" }, act
|
|
2224
|
+
h("span", { class: "qb-action-title" }, this.actionTitle(act)),
|
|
1729
2225
|
shortcut ? renderKbd(shortcut) : null
|
|
1730
2226
|
);
|
|
1731
2227
|
children.push(el);
|
|
1732
|
-
}), list.length || children.push(h("div", { class: "qb-empty-desc", style: "padding:10px 8px" }, "
|
|
2228
|
+
}), list.length || children.push(h("div", { class: "qb-empty-desc", style: "padding:10px 8px" }, this.t("noMatchingActions"))), p.list.replaceChildren(...children), p.input.setAttribute("aria-activedescendant", `${this.instanceId}-action-${p.selected}`), p.list.querySelector("[aria-selected=true]")?.scrollIntoView({ block: "nearest" });
|
|
1733
2229
|
}
|
|
1734
2230
|
// ─── DOM ─────────────────────────────────────────────────────────────────
|
|
1735
2231
|
cls(base, slot) {
|
|
@@ -1756,13 +2252,13 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1756
2252
|
"aria-autocomplete": "list",
|
|
1757
2253
|
"aria-expanded": "true",
|
|
1758
2254
|
"aria-controls": `${id}-list`,
|
|
1759
|
-
"aria-label": "
|
|
2255
|
+
"aria-label": this.t("search")
|
|
1760
2256
|
});
|
|
1761
2257
|
input.addEventListener("input", () => {
|
|
1762
2258
|
let frame = this.top;
|
|
1763
2259
|
frame && this.onQueryChange(frame, input.value);
|
|
1764
2260
|
});
|
|
1765
|
-
let back = h("button", { class: "qb-back", type: "button", "aria-label": "
|
|
2261
|
+
let back = h("button", { class: "qb-back", type: "button", "aria-label": this.t("back"), title: this.t("back"), html: "" });
|
|
1766
2262
|
back.append(renderIcon("arrow-left", 15)), back.addEventListener("click", () => this.pop());
|
|
1767
2263
|
let hint = h("button", { class: "qb-hint", type: "button" });
|
|
1768
2264
|
hint.addEventListener("click", () => this.ask(this.top?.query));
|
|
@@ -1779,7 +2275,7 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1779
2275
|
progress
|
|
1780
2276
|
), body = h("div", { class: "qb-body" }), footerLeft = h("div", { class: "qb-footer-left", "aria-live": "polite" }), footerRight = h("div", { class: "qb-footer-right" }), footer = h("div", { class: this.cls("qb-footer", "footer") }, footerLeft, footerRight), layer = h("div", { style: "display:contents" }), dialog = h(
|
|
1781
2277
|
"div",
|
|
1782
|
-
{ class: this.cls("qb-dialog", "dialog"), role: "dialog", "aria-modal": this.isInline ? "false" : "true", "aria-label": "
|
|
2278
|
+
{ class: this.cls("qb-dialog", "dialog"), role: "dialog", "aria-modal": this.isInline ? "false" : "true", "aria-label": this.t("commandBar"), tabindex: "-1", hidden: !0 },
|
|
1783
2279
|
header,
|
|
1784
2280
|
body,
|
|
1785
2281
|
footer,
|
|
@@ -1794,7 +2290,7 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1794
2290
|
if (btn) {
|
|
1795
2291
|
let code = btn.closest(".qb-code")?.querySelector("code")?.textContent ?? "";
|
|
1796
2292
|
copyText(code).then((ok) => {
|
|
1797
|
-
btn.textContent = ok ? "
|
|
2293
|
+
btn.textContent = ok ? this.t("copiedShort") : this.t("failed"), setTimeout(() => btn.textContent = this.t("copy"), 1200);
|
|
1798
2294
|
});
|
|
1799
2295
|
}
|
|
1800
2296
|
this.panel && !e.target.closest?.(".qb-actions") && !e.target.closest?.(".qb-footer-btn") && this.closePanel();
|
|
@@ -1819,7 +2315,7 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1819
2315
|
footerRight,
|
|
1820
2316
|
layer,
|
|
1821
2317
|
live
|
|
1822
|
-
}, this.applyTheme(), this.watchAppearance(), this.listen(document, "focusin", ((e) => {
|
|
2318
|
+
}, this.applyTheme(), this.applyTouch(), this.watchAppearance(), this.watchViewport(), this.listen(document, "focusin", ((e) => {
|
|
1823
2319
|
this._open && !this.isInline && this.dom && !this.dom.root.contains(e.target) && this.focusInput();
|
|
1824
2320
|
}));
|
|
1825
2321
|
}
|
|
@@ -1921,7 +2417,7 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1921
2417
|
class: "qb-arg",
|
|
1922
2418
|
name: a.name,
|
|
1923
2419
|
type: a.type === "password" ? "password" : "text",
|
|
1924
|
-
placeholder: `${a.placeholder ?? a.name}${a.required ? "" :
|
|
2420
|
+
placeholder: `${a.placeholder ?? a.name}${a.required ? "" : ` ${this.t("optional")}`}`,
|
|
1925
2421
|
"aria-label": a.placeholder ?? a.name,
|
|
1926
2422
|
autocomplete: "off",
|
|
1927
2423
|
spellcheck: "false"
|
|
@@ -1933,23 +2429,25 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1933
2429
|
dom.args.hidden = !1;
|
|
1934
2430
|
} else {
|
|
1935
2431
|
dom.args.hidden = !0, delete dom.args.dataset.for, dom.args.replaceChildren(), dom.input.hidden = !hasInput, dom.title.hidden = hasInput, hasInput || (dom.title.textContent = v.title ?? "");
|
|
1936
|
-
let placeholder = this.renderer?.placeholder?.() ?? v.placeholder ?? (v.type === "root" ? this.config.placeholder ?? "
|
|
2432
|
+
let placeholder = this.renderer?.placeholder?.() ?? v.placeholder ?? (v.type === "root" ? this.config.placeholder ?? this.t("placeholder") : this.t("searchPlaceholder"));
|
|
1937
2433
|
dom.input.placeholder !== placeholder && (dom.input.placeholder = placeholder), dom.input.value !== frame.query && (dom.input.value = frame.query);
|
|
1938
2434
|
}
|
|
1939
2435
|
let selected = frame.itemRows[frame.selected];
|
|
1940
2436
|
selected && (v.type === "root" || v.type === "list" || v.type === "grid") ? dom.input.setAttribute("aria-activedescendant", `${this.instanceId}-opt-${selected.key.replace(/[^\w-]/g, "_")}`) : dom.input.removeAttribute("aria-activedescendant");
|
|
1941
2437
|
let showHint = !!this.ai && v.type === "root" && !this.argMode && this.aiOptions?.fallback !== !1;
|
|
1942
|
-
dom.hint.hidden = !showHint, showHint && !dom.hint.childElementCount && dom.hint.append(h("span", null,
|
|
2438
|
+
dom.hint.hidden = !showHint, showHint && !dom.hint.childElementCount && dom.hint.append(h("span", null, this.t("askAi")), renderKbd("tab")), frame.loading > 0 ? dom.progress.dataset.active = "" : delete dom.progress.dataset.active;
|
|
1943
2439
|
}
|
|
1944
2440
|
renderFooter(frame) {
|
|
1945
2441
|
let dom = this.dom;
|
|
1946
2442
|
!this.toastState || !this._open ? this.renderFooterLeft(frame) : this.renderToast();
|
|
1947
|
-
let right = [], custom = this.renderer?.footerPrimary?.(), actions = this.actionsFor(this.selectedItem(frame), frame), primary = custom ?? (actions[0] ? { title: actions[0]
|
|
1948
|
-
this.argMode ? right.push(this.footerButton(
|
|
2443
|
+
let right = [], custom = this.renderer?.footerPrimary?.(), actions = this.actionsFor(this.selectedItem(frame), frame), primary = custom ?? (actions[0] ? { title: this.actionTitle(actions[0]), hotkey: "enter", run: () => this.runPrimary(frame) } : void 0);
|
|
2444
|
+
this.argMode ? right.push(this.footerButton(this.t("runItem", { title: this.argMode.item.title }), "enter", () => this.submitArgs(), !0)) : primary && right.push(this.footerButton(primary.title, primary.hotkey, primary.run, !0)), actions.length > (custom ? 0 : 1) && !this.argMode && right.push(h("span", { class: "qb-footer-sep" }), this.footerButton(this.t("actions"), this.actionsHotkey, () => this.openPanel())), dom.footerRight.replaceChildren(...right);
|
|
1949
2445
|
}
|
|
1950
2446
|
renderFooterLeft(frame) {
|
|
1951
2447
|
let dom = this.dom, v = frame.view, left = [];
|
|
1952
|
-
if (
|
|
2448
|
+
if (frame.marked?.size)
|
|
2449
|
+
left.push(renderIcon("check-square", 14), h("span", null, this.t("selected", { count: frame.marked.size })));
|
|
2450
|
+
else if (this.stack.length > 1 && v.title) {
|
|
1953
2451
|
let icon = renderIcon(frame.ext?.ext.icon ?? "layers", 14);
|
|
1954
2452
|
icon && left.push(icon), left.push(h("span", null, v.title));
|
|
1955
2453
|
} else if (this.config.footer) left.push(h("span", null, this.config.footer));
|
|
@@ -1966,12 +2464,17 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1966
2464
|
renderToast() {
|
|
1967
2465
|
let t = this.toastState, iconFor = (style) => style === "success" ? "check-circle" : style === "failure" ? "x-circle" : style === "loading" ? "loader" : "info", build = (cls) => {
|
|
1968
2466
|
let icon = renderIcon(iconFor(t.style), 14);
|
|
1969
|
-
|
|
2467
|
+
t.style === "loading" && icon.classList.add("qb-spin");
|
|
2468
|
+
let button = null;
|
|
2469
|
+
return t.act && (button = h("button", { class: "qb-toast-action", type: "button" }, h("span", null, t.act.title), t.act.shortcut ? renderKbd(t.act.shortcut) : null), button.addEventListener("pointerdown", (e) => e.preventDefault()), button.addEventListener("click", (e) => {
|
|
2470
|
+
e.stopPropagation(), this.runToastAction();
|
|
2471
|
+
})), h(
|
|
1970
2472
|
"div",
|
|
1971
|
-
{ class: this.cls(cls, "toast"), "data-style": t.style ?? "info", role: "status" },
|
|
2473
|
+
{ class: this.cls(cls, "toast"), "data-style": t.style ?? "info", "data-action": t.act ? "" : null, role: "status" },
|
|
1972
2474
|
icon,
|
|
1973
2475
|
h("span", { class: "qb-toast-title" }, t.title),
|
|
1974
|
-
t.message ? h("span", { class: "qb-toast-msg" }, t.message) : null
|
|
2476
|
+
t.message ? h("span", { class: "qb-toast-msg" }, t.message) : null,
|
|
2477
|
+
button
|
|
1975
2478
|
);
|
|
1976
2479
|
};
|
|
1977
2480
|
if (this._open && this.dom) {
|
|
@@ -1989,7 +2492,7 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
1989
2492
|
return;
|
|
1990
2493
|
}
|
|
1991
2494
|
if (dom.layer.firstChild) return;
|
|
1992
|
-
let cancel = h("button", { class: "qb-btn", type: "button" }, c.cancelLabel ?? "
|
|
2495
|
+
let cancel = h("button", { class: "qb-btn", type: "button" }, c.cancelLabel ?? this.t("cancel")), ok = h("button", { class: `qb-btn ${c.destructive ? "qb-btn-danger" : "qb-btn-primary"}`, type: "button" }, c.confirmLabel ?? this.t("confirm"), renderKbd("enter"));
|
|
1993
2496
|
cancel.addEventListener("click", () => c.resolve(!1)), ok.addEventListener("click", () => c.resolve(!0)), ok.addEventListener("keydown", (e) => {
|
|
1994
2497
|
e.key === "Enter" && (e.preventDefault(), c.resolve(!0));
|
|
1995
2498
|
}), dom.layer.append(
|
|
@@ -2006,10 +2509,29 @@ ${opts.message}` : opts.title) : !1) : (this.confirmState?.resolve(!1), new Prom
|
|
|
2006
2509
|
)
|
|
2007
2510
|
), ok.focus();
|
|
2008
2511
|
}
|
|
2512
|
+
/** Render Markdown with translated UI strings. */
|
|
2513
|
+
md(text) {
|
|
2514
|
+
return renderMarkdown(text, { copyLabel: this.t("copy") });
|
|
2515
|
+
}
|
|
2009
2516
|
announce(text) {
|
|
2010
2517
|
this.dom && (this.dom.live.textContent = text);
|
|
2011
2518
|
}
|
|
2012
|
-
};
|
|
2519
|
+
}, isFallback = (item) => !!item.id && (item.id.startsWith("fallback:") || item.id === "qikbar.ask-ai-fallback"), normalizeAlias = (alias) => alias.trim().toLowerCase().replace(/\s+/g, " ");
|
|
2520
|
+
function embedText(item) {
|
|
2521
|
+
return [item.title, item.subtitle, item.section, item.keywords?.join(", "), item.description].filter(Boolean).join(" \xB7 ");
|
|
2522
|
+
}
|
|
2523
|
+
function normalize(v) {
|
|
2524
|
+
let n = 0;
|
|
2525
|
+
for (let x of v) n += x * x;
|
|
2526
|
+
let len = Math.sqrt(n) || 1, out = new Float32Array(v.length);
|
|
2527
|
+
for (let i = 0; i < v.length; i++) out[i] = v[i] / len;
|
|
2528
|
+
return out;
|
|
2529
|
+
}
|
|
2530
|
+
function dot(a, b) {
|
|
2531
|
+
let s = 0, n = Math.min(a.length, b.length);
|
|
2532
|
+
for (let i = 0; i < n; i++) s += a[i] * b[i];
|
|
2533
|
+
return s;
|
|
2534
|
+
}
|
|
2013
2535
|
function shallowEqual(a, b) {
|
|
2014
2536
|
if (a === b) return !0;
|
|
2015
2537
|
if (!a || !b) return !1;
|
|
@@ -2026,6 +2548,8 @@ async function withTimeout(p, ms) {
|
|
|
2026
2548
|
}
|
|
2027
2549
|
export {
|
|
2028
2550
|
Bar,
|
|
2029
|
-
|
|
2551
|
+
embedText,
|
|
2552
|
+
isView,
|
|
2553
|
+
normalizeAlias
|
|
2030
2554
|
};
|
|
2031
|
-
//# sourceMappingURL=bar-
|
|
2555
|
+
//# sourceMappingURL=bar-P3SCR4SJ.js.map
|