G2 only: You can pair the glasses with a bluetooth keyboard. It will relay key events, and you can use it to type in some apps and to navigate the UI.
172 lines
8.1 KiB
JavaScript
172 lines
8.1 KiB
JavaScript
const test = require('node:test');
|
|
const assert = require('node:assert/strict');
|
|
const { loader } = require('./helpers/load-typescript.cjs');
|
|
|
|
function settingsEnv(initialUrl = '', initialModel = 'openai-compatible', glassesType = 'g2') {
|
|
let url = initialUrl;
|
|
let model = initialModel;
|
|
let webSearch = false;
|
|
const dummySetting = {
|
|
id: 'setting', label: 'Setting', get: () => '', set() {}, displayValue: () => '',
|
|
};
|
|
const urlSetting = {
|
|
id: 'compatible-url', label: 'Compatible API URL', get: () => url, set: value => { url = value; },
|
|
displayValue: () => url,
|
|
};
|
|
const modelSetting = {
|
|
id: 'assistant-model', label: 'Assistant model', get: () => model, set: value => { model = value; },
|
|
displayValue: () => model,
|
|
};
|
|
const searchSetting = {
|
|
id: 'venice-web-search', label: 'Venice web search', get: () => webSearch,
|
|
set: value => { webSearch = value; }, toggle: () => { webSearch = !webSearch; },
|
|
defaultValue: false, description: 'Venice-only web search.',
|
|
};
|
|
const row = setting => ({ label: setting.label, description: setting.description, onSelect() {} });
|
|
const dashboardSettings = new Proxy({
|
|
assistantModelSetting: modelSetting,
|
|
assistantOpenAiCompatibleUrlSetting: urlSetting,
|
|
assistantOpenAiCompatibleKeySetting: { ...dummySetting, id: 'compatible-key', label: 'Compatible API key' },
|
|
assistantOpenAiCompatibleModelSetting: { ...dummySetting, id: 'compatible-model', label: 'Compatible model ID' },
|
|
assistantHermesUrlSetting: { ...dummySetting, id: 'assistant-hermes-url', label: 'Hermes URL' },
|
|
assistantHermesKeySetting: { ...dummySetting, id: 'assistant-hermes-key', label: 'Hermes key' },
|
|
veniceWebSearchSetting: searchSetting,
|
|
glassesTypeSetting: { ...dummySetting, id: 'glasses-type', get: () => (typeof glassesType === 'function' ? glassesType() : glassesType) },
|
|
enumSettingMenuItem: row,
|
|
textSettingMenuItem: row,
|
|
toggleSettingMenuItem: row,
|
|
}, {
|
|
get(target, property) {
|
|
return property in target ? target[property] : dummySetting;
|
|
},
|
|
});
|
|
const load = loader({ global: { isIOS: false, isAndroid: true } }, {
|
|
'./remote-input-menu': { remoteInputMenuItem: () => ({ label: 'Remote input' }) },
|
|
'@nativescript/core': { knownFolders: {} },
|
|
'../../graphics/ui-fonts': { getDefaultSmallFont: () => ({}) },
|
|
'../../graphics/logo': { getDashboardLogo: () => null },
|
|
'../../graphics/textwrap': { wrapText: () => [] },
|
|
'../../version': { FACECLAW_VERSION: 'test' },
|
|
'../../native/local-llm': {
|
|
cancelLocalModelDownload() {}, deleteLocalModel() {}, startLocalModelDownload() {},
|
|
LOCAL_MODEL: { label: 'Qwen', sizeBytes: 1_000_000_000 },
|
|
localModelState: () => ({ status: 'missing' }), onLocalModelStateChanged: () => () => {},
|
|
},
|
|
'../../native/asr-model': {
|
|
ASR_MODELS: {
|
|
moonshine: { label: 'Moonshine', sizeBytes: 1 },
|
|
'whisper-base-en': { label: 'Whisper Base English', sizeBytes: 1 },
|
|
},
|
|
asrModelState: () => ({}), cancelAsrModelDownload() {},
|
|
deleteAsrModel() {}, startAsrModelDownload() {}, onAsrModelStateChanged: () => () => {},
|
|
},
|
|
'../../apps/files/text-viewer': { TextViewerLayer: class {} },
|
|
'../menu': {
|
|
drawRightValueMenuItem() {}, openModalMenu() {},
|
|
submenuItem: label => ({ label, onSelect() {} }),
|
|
},
|
|
'../shell/shell': { shell: { noteUserActivity() {} } },
|
|
'../dashboard-settings': dashboardSettings,
|
|
'../../native/wear-bridge': { wearBridge: {} },
|
|
'./settings-panel': {
|
|
SettingsPanelLayer: class { constructor(sections) { this.sections = sections; } },
|
|
openSettingsSubMenu() {},
|
|
},
|
|
'../font-picker': { uiFontPickerMenuItem: () => ({ label: 'Font' }) },
|
|
'../notification-filter': { NotificationFilterLayer: class {} },
|
|
'../keyboard-settings': { keyboardSettingsMenuItem: () => ({ label: 'Bluetooth keyboard' }) },
|
|
'../openai-compatible-model-picker': {
|
|
compatibleModelDiscoveryMenuItem: () => ({ label: 'Discover models' }),
|
|
},
|
|
'./sse': {},
|
|
});
|
|
const panel = load('app/ui/dashboard/settings-menus.ts').createSettingsPanelLayer();
|
|
const section = panel.sections.find(item => item.label === 'Assistant');
|
|
assert.ok(section);
|
|
return {
|
|
section,
|
|
sections: panel.sections,
|
|
labels: () => section.items.map(item => item.label),
|
|
setUrl: value => { url = value; },
|
|
setModel: value => { model = value; },
|
|
searchSetting,
|
|
};
|
|
}
|
|
|
|
test('Venice web search row follows the current URL and never appears for other providers', () => {
|
|
const env = settingsEnv();
|
|
assert.equal(env.labels().includes('Venice web search'), false);
|
|
assert.equal(env.searchSetting.defaultValue, false);
|
|
assert.equal(env.searchSetting.get(), false);
|
|
|
|
env.setUrl(' https://api.venice.ai/api/v1/ ');
|
|
assert.equal(env.labels().includes('Venice web search'), true);
|
|
|
|
env.setUrl('https://openwebui.example/api');
|
|
assert.equal(env.labels().includes('Venice web search'), false);
|
|
|
|
env.setUrl('https://api.venice.ai/api/v1/chat/completions');
|
|
assert.equal(env.labels().includes('Venice web search'), true);
|
|
|
|
env.setUrl('https://api.venice.ai.evil.example/api/v1');
|
|
assert.equal(env.labels().includes('Venice web search'), false);
|
|
|
|
env.setUrl('http://api.venice.ai/api/v1');
|
|
assert.equal(env.labels().includes('Venice web search'), false);
|
|
});
|
|
|
|
test('Venice web search row also requires the OpenAI-compatible model to be selected', () => {
|
|
const env = settingsEnv('https://api.venice.ai/api/v1', 'sonnet');
|
|
assert.equal(env.labels().includes('Venice web search'), false);
|
|
env.setModel('hermes');
|
|
assert.equal(env.labels().includes('Venice web search'), false);
|
|
env.setModel('openai-compatible');
|
|
assert.equal(env.labels().includes('Venice web search'), true);
|
|
});
|
|
|
|
test('Hermes URL and key rows appear only while Hermes agent is the selected model', () => {
|
|
const env = settingsEnv('', 'auto');
|
|
// Labels come from the module's VM realm; compare by value.
|
|
const hermesRows = () => JSON.stringify(env.labels().filter(label => label.startsWith('Hermes')));
|
|
assert.equal(hermesRows(), '[]');
|
|
env.setModel('openai-compatible');
|
|
assert.equal(hermesRows(), '[]');
|
|
env.setModel('hermes');
|
|
assert.equal(hermesRows(), JSON.stringify(['Hermes URL', 'Hermes key']));
|
|
const labels = env.labels();
|
|
assert.equal(labels.indexOf('Hermes URL'), labels.indexOf('Assistant model') + 1, 'Hermes rows follow the model row');
|
|
});
|
|
|
|
test('OpenAI-compatible rows appear only while OpenAI-compatible is the selected model', () => {
|
|
const env = settingsEnv('https://api.venice.ai/api/v1', 'auto');
|
|
const compatibleRows = () => JSON.stringify(env.labels().filter(label =>
|
|
label.startsWith('Compatible') || label === 'Discover models' || label === 'Venice web search'));
|
|
assert.equal(compatibleRows(), '[]');
|
|
env.setModel('hermes');
|
|
assert.equal(compatibleRows(), '[]');
|
|
env.setModel('openai-compatible');
|
|
assert.equal(compatibleRows(), JSON.stringify([
|
|
'Compatible API URL', 'Compatible API key', 'Discover models', 'Compatible model ID', 'Venice web search',
|
|
]));
|
|
const labels = env.labels();
|
|
assert.equal(labels.indexOf('Compatible API URL'), labels.indexOf('Assistant model') + 1, 'compatible rows follow the model row');
|
|
});
|
|
|
|
test('the Keyboard section, with its pairing row, follows the glasses type while Settings stays open', () => {
|
|
let glassesType = 'g1';
|
|
const sections = settingsEnv('', 'openai-compatible', () => glassesType).sections;
|
|
const labels = sections.map(section => section.label);
|
|
// Always in the list, between the other input devices and the developer
|
|
// options; whether it shows is asked again on every paint.
|
|
assert.equal(labels.indexOf('Keyboard'), labels.indexOf('Watch') + 1);
|
|
const keyboard = sections.find(section => section.label === 'Keyboard');
|
|
assert.equal(keyboard.items.map(item => item.label).join(), 'Bluetooth keyboard');
|
|
assert.equal(keyboard.hidden(), true);
|
|
glassesType = 'rayneo-io';
|
|
assert.equal(keyboard.hidden(), true);
|
|
glassesType = 'g2';
|
|
assert.equal(keyboard.hidden(), false);
|
|
// Nothing else is conditional this way.
|
|
assert.equal(sections.filter(section => section.hidden).length, 1);
|
|
});
|