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.js59
1 files changed, 54 insertions, 5 deletions
diff --git a/modules/core/module-smartctx.js b/modules/core/module-smartctx.js
index 2b4712d..81929f8 100644
--- a/modules/core/module-smartctx.js
+++ b/modules/core/module-smartctx.js
@@ -2,7 +2,7 @@
class SmartContextModule {
constructor() {
this.commands = {}; this.terminal = null;
- this.contextProfiles = this.loadProfiles(); this.activeProfile = null;
+ this.contextProfiles = this.loadProfiles(); this.activeProfile = this.loadActiveProfile();
}
getHelpInfo() {
return {
@@ -22,6 +22,22 @@
saveProfiles() {
localStorage.setItem('webx11_context_profiles', JSON.stringify(this.contextProfiles));
}
+ loadActiveProfile() {
+ try {
+ const saved = localStorage.getItem('webx11_active_context_profile');
+ if (saved && this.contextProfiles[saved]) return saved;
+ } catch (e) {}
+ return null;
+ }
+ saveActiveProfile() {
+ try {
+ if (this.activeProfile) {
+ localStorage.setItem('webx11_active_context_profile', this.activeProfile);
+ } else {
+ localStorage.removeItem('webx11_active_context_profile');
+ }
+ } catch (e) {}
+ }
getDefaultProfiles() {
return {
'coding': { name: 'Coding Assistant', systemPrompt: "You are an expert programmer.", temperature: 0.7 },
@@ -44,6 +60,7 @@
}
if (this.contextProfiles[args[0]]) {
this.activeProfile = args[0];
+ this.saveActiveProfile();
this.terminal.print(`Context set to: ${this.contextProfiles[args[0]].name}`, "success");
} else {
this.terminal.print(`Profile '${args[0]}' not found`, "error");
@@ -83,11 +100,43 @@
this.terminal.print("Usage: smart-ask <your-question>", "warning"); return;
}
let systemPrompt = "You are a helpful assistant.";
+ let temperature = 0.7;
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 profile = this.contextProfiles[this.activeProfile];
+ systemPrompt = profile.systemPrompt;
+ temperature = profile.temperature || 0.7;
+ this.terminal.print(`Using context: ${profile.name} (temp: ${temperature})`, "info");
+ }
+ // Use agentic loop via the AI assistant module for tool-enabled responses
+ const aiModule = this.terminal?.moduleManager?.modules?.WebX11AIAssistantModule;
+ if (aiModule) {
+ // Set temperature on ollamaManager modelParams temporarily
+ const om = this.terminal.ollamaManager;
+ const savedTemp = om.modelParams ? om.modelParams.temperature : undefined;
+ if (om.modelParams) {
+ om.modelParams.temperature = temperature;
+ }
+ try {
+ const messages = [
+ { role: 'system', content: systemPrompt },
+ { role: 'user', content: args.join(' ') }
+ ];
+ const result = await om.chatWithTools(messages, aiModule.getToolDefinitions());
+ if (result && result.message) {
+ this.terminal.printAIResponse(result.message.content || '(no response)');
+ } else if (result && result.error) {
+ this.terminal.print(`⚠️ AI error: ${result.error}`, 'error');
+ }
+ } finally {
+ if (om.modelParams && savedTemp !== undefined) {
+ om.modelParams.temperature = savedTemp;
+ }
+ }
+ } else {
+ // Fallback: simple chat with temperature
+ const om = this.terminal.ollamaManager;
+ const fullPrompt = `${systemPrompt}\n\nUser: ${args.join(' ')}`;
+ await om.chat(fullPrompt);
}
- const fullPrompt = `${systemPrompt}\n\nUser: ${args.join(' ')}`;
- await this.terminal.ollamaManager.chat(fullPrompt);
}
}