blob: 34c15826812218e74af885a72d6721ae93222647 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
// Extracted from newOS4 index.html — WebXAIAliasModule
class WebXAIAliasModule {
constructor() { this.commands = {}; this.terminal = null; }
getHelpInfo() {
return {
'webxai': 'webxai <question> — Send a question to the AI assistant',
'wx': 'wx <question> — Alias for webxai',
'webx': 'webx <question> — Alias for webxai'
};
}
registerCommands() {
this.commands['webxai'] = (args) => this.forwardToAI(args);
this.commands['wx'] = (args) => this.forwardToAI(args);
this.commands['webx'] = (args) => this.forwardToAI(args);
}
forwardToAI(args) {
if (!args[0]) {
this.terminal.print("Usage: webxai <your-question>", "warning"); return;
}
const ai = this.terminal.moduleManager.modules['WebX11AIAssistantModule'];
let p;
try {
p = ai ? ai.chat(args) : this.terminal.ollamaManager.chat(args.join(' '));
} catch (e) {
// Synchronous throw — report it through the same path as a rejection.
p = Promise.reject(e);
}
// Chat-lock timeouts are normal UX (user sent twice). Print, don't let the rejection
// reach window.unhandledrejection → debug-supervisor auto-report. chat() releases its
// own lock in finally, so nothing is cleared here.
return Promise.resolve(p).catch((e) => {
this.terminal.print('AI error: ' + (e && e.message ? e.message : e), 'error');
});
}
}
|