Merge branch 'main' into fix/chat-provider-switch-keeps-context

This commit is contained in:
Sameh Khamis authored and GitHub committed 2026-11-05 13:43:40 -08:00
commit a75b495cf9
82 files changed
+4157 -444

No files matched your search

+11 -11
View File
@@ -1,4 +1,4 @@
import { t } from '../i18n/index.js';
import { msg, t } from '../i18n/index.js';
/**
* Chat suggestions and the one chat preference (quick commands), written to
@@ -17,11 +17,15 @@ export function bindChatPreferences({ ui, getDraft, setDraft }) {
};
const quickCommands = () =>
[
'Fly to Tokyo',
'Show live flights',
'Reset to globe view',
'Show earthquakes',
msg('Fly to Tokyo'),
msg('Show live flights'),
msg('Reset to globe view'),
msg('Show earthquakes'),
].map((text) => t(text));
// Arabic short vowels and shadda are optional in writing: typing "تتبع"
// still finds "تتبّع".
const fold = (text) =>
text.toLowerCase().replace(/[\u064B-\u065F\u0670]/g, '');
try {
const stored = JSON.parse(localStorage.getItem(key));
if (typeof stored?.quick === 'boolean') quick = stored.quick;
@@ -31,18 +35,14 @@ export function bindChatPreferences({ ui, getDraft, setDraft }) {
function render() {
const draft = getDraft();
if (historyIndex >= 0 && draft !== recent[historyIndex]) resetHistory();
const query = draft.trim().toLowerCase();
const query = fold(draft.trim());
const groups = [];
if (query) {
const candidates = [...recent, ...(quick ? quickCommands() : [])];
groups.push({
label: t('Suggestions'),
items: [...new Set(candidates)]
.filter(
(text) =>
text.toLowerCase().includes(query) &&
text.toLowerCase() !== query,
)
.filter((text) => fold(text).includes(query) && fold(text) !== query)
.slice(0, 4),
});
} else {
+19
View File
@@ -1,5 +1,6 @@
import test from 'node:test';
import assert from 'node:assert/strict';
import { setLocale } from '../i18n/index.js';
import { bindChatPreferences } from './chatPreferences.js';
import { createTestVoiceUi } from '../testSupport/voiceUi.mjs';
@@ -99,3 +100,21 @@ test('editing a recalled message ends recall, and sending resets it', (t) => {
press('ArrowUp');
assert.equal(field.value, 'Show live flights now');
});
test('autocomplete ignores Arabic short vowels and shadda', (t) => {
setLocale('ar');
t.after(() => setLocale('en'));
const ui = createTestVoiceUi();
let draft = '';
const prefs = bindChatPreferences({ ui, getDraft: () => draft });
t.after(() => prefs.destroy());
const suggested = (text) => {
draft = text;
prefs.render();
return ui.state.chat.suggestions.flatMap((group) => group.items);
};
// The quick command is written "تتبّع", with a shadda.
assert.deepEqual(suggested('تتبع'), ['اعرض تتبّع الرحلات المباشر']);
prefs.remember('انتقل إلى طوكيو');
assert.deepEqual(suggested('طُوكيو'), ['انتقل إلى طوكيو']);
});