fix(voice): address review of typed AI chat

Typed chat sessions no longer end on the voice inactivity timeout, and a
failed or stopped reply keeps the conversation: Stop cancels only the
reply in progress, and map actions that already ran stay in the model's
context. Each upstream request and map action gets its own deadline, old
tool results shrink instead of the history overflowing, and step limits,
a missing or rejected key, the OAuth lock and throttling each get their
own message.

- Server: OpenAI chat is off under GEV_PREFER_CODEX_OAUTH; chat throttles
  default to the provider's throttle; replies carry API_KEY_MISSING,
  API_KEY_REJECTED, CODEX_OAUTH_REQUIRED and RATE_LIMITED codes; upstream
  Retry-After passes through, and a rejected key (Gemini's invalid-key 400
  included) cools down for a minute
- Pinokio forwards the chat throttle settings
- UI: the reply reveal publishes only the message list; the border orbit
  runs only while busy; layers attach with a button or Enter; the log is
  aria-busy while a reply types out; auto-scroll respects a reader who
  scrolled up; Escape closes the attach menu; the chat gear says Settings;
  a note says chat bills the OpenAI key when voice uses ChatGPT sign-in
- Layout does less work while panel height animates; unused blurs removed
- Gemini voice start ends chat; the voice preview clears on every new
  session
- Tests for the route gates, client limits, attachments and the fixes
This commit is contained in:
manjunath22466 committed 2026-11-03 22:01:08 +05:30
1 parent 11cd0142ac
commit da8b0dd8cd
49 files changed
+2121 -160

No files matched your search

+139
View File
@@ -0,0 +1,139 @@
// src/voice/chatAttachments.test.mjs — the chat's draft attachments: what
// they accept and refuse, and how their menu closes.
import '../testSupport/registerDom.mjs';
import test from 'node:test';
import assert from 'node:assert/strict';
import { bindChatAttachments } from './chatAttachments.js';
import { createTestVoiceUi } from '../testSupport/voiceUi.mjs';
import { mountVoiceView } from '../testSupport/voiceView.mjs';
const $ = (selector) => document.querySelector(selector);
function layers(count) {
return new Map(
Array.from({ length: count }, (_, index) => [
`layer-${index + 1}`,
{ module: { name: `Layer ${index + 1}` } },
]),
);
}
function attachments(t, { ui = createTestVoiceUi({ panel: true }) } = {}) {
const statuses = [];
const bound = bindChatAttachments({
ui,
dataManager: { layers: layers(6), isEnabled: () => true },
onChange() {},
setStatus: (text) => statuses.push(text),
});
t.after(() => bound.destroy());
const names = () => ui.state.chat.attachments.map((item) => item.name);
// The file input as the view hands it over; the reading is asynchronous.
const choose = async (...files) => {
const input = { files, value: 'C:\\fakepath\\file' };
ui.emit('chat-files', input);
for (let i = 0; i < 5; i++) await new Promise((r) => setTimeout(r, 0));
return input;
};
return { ui, bound, statuses, names, choose };
}
const file = (name, content) => new File([content], name);
test('a fifth attachment is refused: the limit is four', (t) => {
const { ui, statuses, names } = attachments(t);
for (let i = 1; i <= 4; i++) ui.emit('chat-layer', `layer-${i}`);
assert.deepEqual(names(), ['Layer 1', 'Layer 2', 'Layer 3', 'Layer 4']);
assert.deepEqual(statuses, []);
ui.emit('chat-layer', 'layer-5');
assert.equal(names().length, 4);
assert.deepEqual(statuses, ['You can attach up to four items.']);
// Choosing an attached layer again replaces it and is not a fifth.
ui.emit('chat-layer', 'layer-2');
assert.equal(names().length, 4);
assert.equal(statuses.length, 1);
});
test('a 10,001-byte file is refused: each file may be up to 10 KB', async (t) => {
const { statuses, names, choose } = attachments(t);
const input = await choose(file('big.txt', 'a'.repeat(10001)));
assert.deepEqual(names(), []);
assert.deepEqual(statuses, ['Each file must be 10 KB or smaller.']);
// The input clears so the same file can be chosen again.
assert.equal(input.value, '');
await choose(file('notes.txt', 'a'.repeat(9000)));
assert.deepEqual(names(), ['notes.txt']);
assert.equal(statuses.length, 1);
});
test('only text file types are accepted', async (t) => {
const { statuses, names, choose } = attachments(t);
await choose(file('setup.exe', 'MZ'));
assert.deepEqual(names(), []);
assert.deepEqual(statuses, [
'Choose a TXT, Markdown, CSV, JSON or GeoJSON file.',
]);
await choose(file('places.GeoJSON', '{"type":"FeatureCollection"}'));
assert.deepEqual(names(), ['places.GeoJSON']);
});
test('a file that is not UTF-8 is refused in the person’s words', async (t) => {
const { statuses, names, choose } = attachments(t);
await choose(file('latin1.csv', new Uint8Array([0x63, 0x61, 0x66, 0xe9])));
assert.deepEqual(names(), []);
assert.deepEqual(statuses, ['Choose a non-empty UTF-8 text file.']);
});
test('control characters and empty files are refused; tabs and line breaks are text', async (t) => {
const { statuses, names, choose } = attachments(t);
await choose(file('binary.txt', 'name\u0001value'));
await choose(file('blank.md', ' \n\t '));
assert.deepEqual(names(), []);
assert.deepEqual(statuses, [
'Choose a non-empty UTF-8 text file.',
'Choose a non-empty UTF-8 text file.',
]);
await choose(file('table.csv', 'a\tb\r\nc\td\n'));
assert.deepEqual(names(), ['table.csv']);
assert.equal(statuses.length, 2);
});
test('attachments over 10 KB together are refused', async (t) => {
const { statuses, names, choose } = attachments(t);
await choose(file('one.txt', 'a'.repeat(6000)));
await choose(file('two.txt', 'b'.repeat(6000)));
assert.deepEqual(names(), ['one.txt']);
assert.deepEqual(statuses, [
'Attachments are too large together. Use smaller files.',
]);
});
test('Escape closes the attach menu and returns to the Attach button', async (t) => {
const { pinia, settle } = mountVoiceView(t);
const ui = createTestVoiceUi({ panel: true, pinia });
attachments(t, { ui });
ui.update('chat', { open: true });
await settle();
$('#gev-chat-attach').click();
await settle();
assert.equal($('#gev-chat-attach-menu').hidden, false);
assert.equal(document.activeElement?.id, 'gev-chat-layer');
const escape = new KeyboardEvent('keydown', {
key: 'Escape',
bubbles: true,
cancelable: true,
});
$('#gev-chat-layer').dispatchEvent(escape);
await settle();
assert.equal(escape.defaultPrevented, true);
assert.equal($('#gev-chat-attach-menu').hidden, true);
assert.equal(document.activeElement?.id, 'gev-chat-attach');
// With the menu closed, Escape is left to whatever else handles it.
const again = new KeyboardEvent('keydown', {
key: 'Escape',
bubbles: true,
cancelable: true,
});
$('#gev-chat-attach').dispatchEvent(again);
assert.equal(again.defaultPrevented, false);
});