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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
// Extracted from newOS4 index.html — OllamaModule (merged with OllamaModelsModule)
// Commands: ollama, ollamaconnect, ollamadisconnect, ollamamodels, ollamasetmodel, ollamasetproxy, models, model-info, model-pull, model-delete, model-run, ai, ask
class OllamaModule {
constructor() { this.commands = {}; this.terminal = null; }
getHelpInfo() {
return {
'ollama': 'ollama — Open the Ollama model manager UI',
'ollamaconnect': 'ollamaconnect — Connect to the Ollama server',
'ollamadisconnect': 'ollamadisconnect — Disconnect from the Ollama server',
'ollamamodels': 'ollamamodels — List all available models from Ollama',
'models': 'models — List all available Ollama models (table format)',
'model-info': 'model-info <model-name> — Show details about a specific model',
'model-pull': 'model-pull <model-name> — Pull a model from Ollama registry',
'model-delete': 'model-delete <model-name> — Delete a model from local storage',
'model-run': 'model-run <model-name> [prompt] — Run inference with a model',
'ollamasetmodel': 'ollamasetmodel <name> — Set the active Ollama model',
'ollamasetproxy': 'ollamasetproxy [endpoint] — View or change the Ollama endpoint URL',
};
}
registerCommands() {
this.commands['ollama'] = () => { this.terminal.openOllamaManager(); };
this.commands['ollamaconnect'] = async () => {
await this.terminal.ollamaManager.connect();
this.terminal.updateOllamaStatus();
};
this.commands['ollamadisconnect'] = () => {
this.terminal.ollamaManager.connected = false;
this.terminal.ollamaManager.models = [];
this.terminal.print('Ollama disconnected', 'info');
this.terminal.updateOllamaStatus();
};
this.commands['ollamamodels'] = () => {
// Redirect to the consolidated models command
this.listModels();
};
this.commands['ollamasetmodel'] = (args) => {
if(!args[0]) return this.terminal.print("Usage: ollamasetmodel <name>", 'warning');
this.terminal.ollamaManager.setModel(args[0]);
};
this.commands['ollamasetproxy'] = (args) => {
if(!args[0]) {
const ep = this.terminal.ollamaManager.endpoint;
return this.terminal.print(`Current Ollama endpoint: ${ep}`, 'info');
}
this.terminal.ollamaManager.setEndpoint(args[0]);
this.terminal.print(`Ollama endpoint set to: ${args[0]}`, 'success');
};
this.commands['ai'] = async (args) => {
if(!args[0]) return this.terminal.print("Usage: ai <prompt>", 'warning');
await this.terminal.ollamaManager.chat(args.join(' '));
};
this.commands['ask'] = async (args) => {
if(!args[0]) return this.terminal.print("Usage: ask <prompt>", 'warning');
await this.terminal.ollamaManager.chat(args.join(' '));
};
// Merged from OllamaModelsModule
this.commands['models'] = () => this.listModels();
this.commands['model-info'] = (args) => this.modelInfo(args);
this.commands['model-pull'] = (args) => this.pullModel(args);
this.commands['model-delete'] = (args) => this.deleteModel(args);
this.commands['model-run'] = (args) => this.runModel(args);
}
async listModels() {
const endpoint = this.terminal?.ollamaManager?.endpoint || localStorage.getItem('webx11_ollama_endpoint') || 'http://localhost:11434';
try {
const response = await fetch(`${endpoint}/api/tags`);
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
const models = data.models || [];
if (models.length === 0) {
this.terminal.print("No models found. Run 'ollama pull <model>' first.", "warning"); return;
}
this.terminal.print("=== Available Ollama Models ===", "info");
this.terminal.printHTML(`<table style="width: 100%; border-collapse: collapse; margin: 10px 0;">
<tr style="border-bottom: 1px solid #005500;">
<th style="text-align: left; padding: 5px;">Name</th>
<th style="text-align: left; padding: 5px;">Size</th>
<th style="text-align: left; padding: 5px;">Family</th>
</tr>`);
models.forEach(m => {
const sizeGB = (m.size / 1e9).toFixed(2);
this.terminal.printHTML(`<tr style="border-bottom: 1px solid #111;">
<td style="padding: 5px; color: #00ff00;">${m.name}</td>
<td style="padding: 5px; color: #888888;">${sizeGB} GB</td>
<td style="padding: 5px; color: #00aaff;">${m.details?.family || 'N/A'}</td>
</tr>`);
});
this.terminal.printHTML(`</table>`);
} catch (e) {
this.terminal.print(`Failed to fetch models: ${e.message}`, "error");
}
}
async modelInfo(args) {
if (!args[0]) {
this.terminal.print("Usage: model-info <model-name>", "warning"); return;
}
const endpoint = this.terminal?.ollamaManager?.endpoint || localStorage.getItem('webx11_ollama_endpoint') || 'http://localhost:11434';
try {
const response = await fetch(`${endpoint}/api/show`, {
method: 'POST', headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ name: args[0] })
});
if (!response.ok) throw new Error(`HTTP ${response.status}`);
const data = await response.json();
this.terminal.print(`=== ${args[0]} ===`, "info");
this.terminal.print(`License: ${data.license || 'N/A'}`);
this.terminal.print(`Parameters: ${data.details?.parameter_size || 'N/A'}`);
this.terminal.print(`Family: ${data.details?.family || 'N/A'}`);
} catch (e) {
this.terminal.print(`Failed to get model info: ${e.message}`, "error");
}
}
pullModel(args) {
this.terminal.print("⚠️ Model pulling must be done via Ollama CLI", "warning");
this.terminal.print(`Run: ollama pull ${args[0] || '<model-name>'}`, "info");
}
deleteModel(args) {
this.terminal.print("⚠️ Model deletion must be done via Ollama CLI", "warning");
this.terminal.print(`Run: ollama rm ${args[0] || '<model-name>'}`, "info");
}
async runModel(args) {
if (!args[0]) {
this.terminal.print("Usage: model-run <model-name> [prompt]", "warning"); return;
}
const model = args[0];
const prompt = args.slice(1).join(' ') || 'Hello!';
this.terminal.print(`Running ${model}...`, "info");
await this.terminal.ollamaManager.chat(prompt, model);
}
}
|