22< html lang ="en ">
33< head >
44 < meta charset ="UTF-8 " />
5- <!-- Content Security Policy - Fallback for local development and non-Amplify deployments -->
6- <!-- Note: Amplify server headers take precedence when deployed -->
7- < meta http-equiv ="Content-Security-Policy " content ="
8- script-src 'self' 'unsafe-eval' 'unsafe-inline' https: data: blob:;
9- style-src 'self' 'unsafe-inline' https: data:;
10- connect-src 'self' https: wss: http://localhost:1234 http://localhost:11434;
11- img-src 'self' data: https: blob:;
12- font-src 'self' data: https:;
13- worker-src 'self' blob: data:;
14- object-src 'none';
15- ">
16- < title > Canvas - TimeCapsule-SLM</ title >
17- < link rel ="icon " type ="image/png " href ="lib/Media/TimeCapsule_04.png ">
18- < link rel ="shortcut icon " type ="image/png " href ="lib/Media/TimeCapsule_04.png ">
5+ <!-- Load Common Meta Configuration -->
6+ < script src ="lib/common-meta.js "> </ script >
7+ < script >
8+ document . write ( `
9+ <!-- Content Security Policy - Fallback for local development and non-Amplify deployments -->
10+ <meta http-equiv="Content-Security-Policy" content="${ COMMON_META . csp } ">
11+ <title>Canvas - ${ COMMON_META . appSuffix } </title>
12+ <link rel="icon" type="image/png" href="${ COMMON_META . favicon } ">
13+ <link rel="shortcut icon" type="image/png" href="${ COMMON_META . favicon } ">
14+ ` ) ;
15+ </ script >
1916 < style >
2017 * {
2118 margin : 0 ;
@@ -2013,11 +2010,25 @@ <h2 style="color: white; margin-bottom: 20px; text-align: center;">🏠 LM Studi
20132010 <h2 style="color: white; margin-bottom: 20px; text-align: center;">🦙 Ollama Connection</h2>
20142011
20152012 <div style="margin-bottom: 20px;">
2016- <button id="connectOllama" class="ai-option-btn">
2017- 🔌 Connect to Ollama
2013+ <label style="color: white; display: block; margin-bottom: 8px; font-weight: 600;">Ollama Server URL:</label>
2014+ <input
2015+ type="text"
2016+ id="ollamaUrl"
2017+ value="http://localhost:11434"
2018+ placeholder="http://localhost:11434"
2019+ style="width: 100%; padding: 12px; border: 1px solid rgba(255,255,255,0.3);
2020+ border-radius: 8px; background: rgba(255,255,255,0.1); color: white;
2021+ font-size: 14px; margin-bottom: 10px;"
2022+ />
2023+ <p style="color: rgba(255,255,255,0.7); font-size: 11px; margin-bottom: 15px;">
2024+ 💡 Examples: http://localhost:11434, http://192.168.1.100:11434, https://my-ollama-server.com
2025+ </p>
2026+
2027+ <button id="connectOllama" class="ai-option-btn">
2028+ 🔌 Connect to Ollama
20182029 </button>
20192030 <p style="color: rgba(255,255,255,0.8); font-size: 12px; margin-top: 5px;">
2020- Connects to Ollama running on localhost:11434
2031+ Will connect to the URL specified above
20212032 </p>
20222033 </div>
20232034
@@ -2257,9 +2268,27 @@ <h2 style="color: white; margin-bottom: 20px; text-align: center;">🤖 Local Qw
22572268 updateStatus ( '🦙 Connecting to Ollama...' ) ;
22582269 document . getElementById ( 'aiStatus' ) . textContent = 'AI: Connecting to Ollama...' ;
22592270
2271+ // Get custom URL from input field, fallback to default
2272+ let ollamaUrl = 'http://localhost:11434' ;
2273+ const urlInput = document . getElementById ( 'ollamaUrl' ) ;
2274+ if ( urlInput && urlInput . value . trim ( ) ) {
2275+ ollamaUrl = urlInput . value . trim ( ) ;
2276+ // Ensure URL doesn't end with slash
2277+ if ( ollamaUrl . endsWith ( '/' ) ) {
2278+ ollamaUrl = ollamaUrl . slice ( 0 , - 1 ) ;
2279+ }
2280+ // Validate URL format
2281+ try {
2282+ new URL ( ollamaUrl ) ;
2283+ } catch ( e ) {
2284+ throw new Error ( `Invalid URL format: ${ ollamaUrl } . Please use format like http://localhost:11434` ) ;
2285+ }
2286+ }
2287+
2288+ console . log ( `🔍 Attempting to connect to Ollama at: ${ ollamaUrl } ` ) ;
2289+
22602290 // Test Ollama connection by fetching models
2261- console . log ( '🔍 Testing Ollama connection...' ) ;
2262- const testResponse = await fetch ( 'http://localhost:11434/api/tags' , {
2291+ const testResponse = await fetch ( `${ ollamaUrl } /api/tags` , {
22632292 method : 'GET' ,
22642293 headers : {
22652294 'Content-Type' : 'application/json'
@@ -2269,7 +2298,7 @@ <h2 style="color: white; margin-bottom: 20px; text-align: center;">🤖 Local Qw
22692298
22702299 if ( ! testResponse . ok ) {
22712300 console . error ( '❌ Ollama connection test failed:' , testResponse . status , testResponse . statusText ) ;
2272- throw new Error ( `Ollama connection failed: ${ testResponse . status } ${ testResponse . statusText } . Make sure Ollama is running on port 11434 .` ) ;
2301+ throw new Error ( `Ollama connection failed: ${ testResponse . status } ${ testResponse . statusText } . Make sure Ollama is running at ${ ollamaUrl } .` ) ;
22732302 }
22742303
22752304 const modelsData = await testResponse . json ( ) ;
@@ -2292,7 +2321,7 @@ <h2 style="color: white; margin-bottom: 20px; text-align: center;">🤖 Local Qw
22922321 selectedModel = modelsData . models ?. [ 0 ] ?. name || 'qwen2.5:0.5b' ;
22932322 }
22942323
2295- aiSession = { type : 'ollama' , model : selectedModel , baseURL : 'http://localhost:11434' } ;
2324+ aiSession = { type : 'ollama' , model : selectedModel , baseURL : ollamaUrl } ;
22962325 document . getElementById ( 'aiStatus' ) . textContent = `AI: Ollama (${ selectedModel } ) ✅` ;
22972326 document . getElementById ( 'generateBtn' ) . disabled = false ;
22982327 document . getElementById ( 'initAIBtn' ) . textContent = `🦙 Ollama Ready` ;
@@ -2301,8 +2330,8 @@ <h2 style="color: white; margin-bottom: 20px; text-align: center;">🤖 Local Qw
23012330 updateHeaderAIStatus ( ) ;
23022331
23032332 console . log ( `🦙 Ollama session initialized successfully with model: ${ selectedModel } ` ) ;
2304- updateStatus ( `🦙 Ollama connected successfully!` ) ;
2305- addChatMessage ( 'system' , `🦙 Ollama connected! Using model: ${ selectedModel } . Fully local processing with GGUF models - no API costs.` ) ;
2333+ updateStatus ( `🦙 Ollama connected successfully at ${ ollamaUrl } !` ) ;
2334+ addChatMessage ( 'system' , `🦙 Ollama connected at ${ ollamaUrl } ! Using model: ${ selectedModel } . Fully local processing with GGUF models - no API costs.` ) ;
23062335
23072336 // Track Ollama connection
23082337 if ( window . AppConfig ) {
@@ -2314,7 +2343,7 @@ <h2 style="color: white; margin-bottom: 20px; text-align: center;">🤖 Local Qw
23142343
23152344 let errorMessage = `❌ Failed to connect to Ollama: ${ error . message } ` ;
23162345 if ( error . message . includes ( 'Failed to fetch' ) ) {
2317- errorMessage += `\n\n💡 Make sure Ollama is installed and running: \n1. Install Ollama from https://ollama.ai\n2. Run: ollama serve\n3. Pull a Qwen model: ollama pull qwen2.5:0.5b` ;
2346+ errorMessage += `\n\n💡 Make sure Ollama is installed and running: \n1. Install Ollama from https://ollama.ai\n2. Run: ollama serve\n3. Pull a Qwen model: ollama pull qwen2.5:0.5b\n4. Ensure CORS is enabled with OLLAMA_ORIGINS ` ;
23182347 }
23192348
23202349 addChatMessage ( 'system' , errorMessage ) ;
0 commit comments