aboutsummaryrefslogtreecommitdiff
path: root/modules/core/module-smartctx.js
diff options
context:
space:
mode:
Diffstat (limited to 'modules/core/module-smartctx.js')
-rw-r--r--modules/core/module-smartctx.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/modules/core/module-smartctx.js b/modules/core/module-smartctx.js
new file mode 100644
index 0000000..2b4712d
--- /dev/null
+++ b/modules/core/module-smartctx.js
@@ -0,0 +1,93 @@
+// Extracted from newOS4 index.html — SmartContextModule
+ class SmartContextModule {
+ constructor() {
+ this.commands = {}; this.terminal = null;
+ this.contextProfiles = this.loadProfiles(); this.activeProfile = null;
+ }
+ getHelpInfo() {
+ return {
+ 'context': 'context [name] — Set or view current context profile',
+ 'contexts': 'contexts — List all available context profiles',
+ 'context-new': 'context-new <name> <displayName> <systemPrompt> — Create a new context profile',
+ 'context-delete': 'context-delete <name> — Delete a context profile',
+ 'smart-ask': 'smart-ask <question> — Ask a question using the active context'
+ };
+ }
+ loadProfiles() {
+ try {
+ const saved = localStorage.getItem('webx11_context_profiles');
+ return saved ? JSON.parse(saved) : this.getDefaultProfiles();
+ } catch (e) { return this.getDefaultProfiles(); }
+ }
+ saveProfiles() {
+ localStorage.setItem('webx11_context_profiles', JSON.stringify(this.contextProfiles));
+ }
+ getDefaultProfiles() {
+ return {
+ 'coding': { name: 'Coding Assistant', systemPrompt: "You are an expert programmer.", temperature: 0.7 },
+ 'debug': { name: 'Debug Helper', systemPrompt: "You are a debugging expert.", temperature: 0.5 },
+ 'creative': { name: 'Creative Writer', systemPrompt: "You are a creative writer.", temperature: 0.9 },
+ 'technical': { name: 'Technical Docs', systemPrompt: "You are a technical writer.", temperature: 0.3 },
+ 'chat': { name: 'Casual Chat', systemPrompt: "You are a friendly assistant.", temperature: 0.8 }
+ };
+ }
+ registerCommands() {
+ this.commands['context'] = (args) => this.setContext(args);
+ this.commands['contexts'] = () => this.listContexts();
+ this.commands['context-new'] = (args) => this.createContext(args);
+ this.commands['context-delete'] = (args) => this.deleteContext(args);
+ this.commands['smart-ask'] = (args) => this.smartAsk(args);
+ }
+ setContext(args) {
+ if (!args[0]) {
+ this.terminal.print(`Current context: ${this.activeProfile || 'none'}`, "info"); return;
+ }
+ if (this.contextProfiles[args[0]]) {
+ this.activeProfile = args[0];
+ this.terminal.print(`Context set to: ${this.contextProfiles[args[0]].name}`, "success");
+ } else {
+ this.terminal.print(`Profile '${args[0]}' not found`, "error");
+ }
+ }
+ listContexts() {
+ this.terminal.print("=== Context Profiles ===", "info");
+ Object.entries(this.contextProfiles).forEach(([key, profile]) => {
+ const active = key === this.activeProfile ? ' ✅' : '';
+ this.terminal.print(`${key}: ${profile.name}${active}`);
+ });
+ }
+ createContext(args) {
+ if (args.length < 3) {
+ this.terminal.print("Usage: context-new <name> <displayName> <systemPrompt>", "warning"); return;
+ }
+ const name = args[0], displayName = args[1], systemPrompt = args.slice(2).join(' ');
+ this.contextProfiles[name] = { name: displayName, systemPrompt, temperature: 0.7 };
+ this.saveProfiles();
+ this.terminal.print(`Context profile '${name}' created`, "success");
+ }
+ deleteContext(args) {
+ if (!args[0]) {
+ this.terminal.print("Usage: context-delete <name>", "warning"); return;
+ }
+ if (this.contextProfiles[args[0]]) {
+ delete this.contextProfiles[args[0]];
+ this.saveProfiles();
+ if (this.activeProfile === args[0]) { this.activeProfile = null; }
+ this.terminal.print(`Context profile '${args[0]}' deleted`, "success");
+ } else {
+ this.terminal.print(`Profile '${args[0]}' not found`, "error");
+ }
+ }
+ async smartAsk(args) {
+ if (!args[0]) {
+ this.terminal.print("Usage: smart-ask <your-question>", "warning"); return;
+ }
+ let systemPrompt = "You are a helpful assistant.";
+ if (this.activeProfile && this.contextProfiles[this.activeProfile]) {
+ systemPrompt = this.contextProfiles[this.activeProfile].systemPrompt;
+ this.terminal.print(`Using context: ${this.contextProfiles[this.activeProfile].name}`, "info");
+ }
+ const fullPrompt = `${systemPrompt}\n\nUser: ${args.join(' ')}`;
+ await this.terminal.ollamaManager.chat(fullPrompt);
+ }
+ }