Compare commits
24 Commits
c66bd68a13
...
main
4
.gitignore
vendored
4
.gitignore
vendored
@@ -110,4 +110,6 @@ sdk-sync-debug.log
|
||||
**/sessions.json
|
||||
**/messages.json
|
||||
**/workspaces.json
|
||||
*.json.bak
|
||||
*.json.bak
|
||||
Dev Chat with IDEs/
|
||||
**/*.txt.bak
|
||||
|
||||
@@ -1,819 +0,0 @@
|
||||
SOLO Coder
|
||||
|
||||
Thought process
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
Fix multix chat auto-scroll for new messages and streaming
|
||||
|
||||
Fixed multix chat auto-scroll for new messages and streaming. Added a createEffect that monitors message changes and automatically scrolls to bottom when:
|
||||
1. New messages arrive
|
||||
2. During streaming (when isAgentThinking is true)
|
||||
|
||||
The effect uses requestAnimationFrame and setTimeout(50ms) for smooth scrolling.
|
||||
|
||||
0/1 done
|
||||
|
||||
Fix multix chat auto-scroll for new messages and streaming
|
||||
|
||||
Thought
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
packages\ui\src\stores\session-events.ts
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'scrollToBottom|scrollIntoView|setShouldScroll'
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'addMessage|updateMessage|createMessage'
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'EventContentDelta|EventMessageDone'
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'case.*session\.message|handleMessageUpdate'
|
||||
|
||||
Thought
|
||||
|
||||
Let me look at the sendMessage function and add auto-scroll when new content arrives:
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
Now I can see the issue. There's a comment saying auto-scroll is handled in two places, but the second place (during streaming) is missing. Let me add the auto-scroll effect:
|
||||
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
Thought
|
||||
|
||||
multi-task-chat.tsx
|
||||
packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
+ 11 - 1
|
||||
|
||||
Open Diff
|
||||
|
||||
Thought
|
||||
|
||||
Let me check if scrollToBottom function exists:
|
||||
|
||||
Search codebase for 'function scrollToBottom|const scrollToBottom'
|
||||
|
||||
Thought
|
||||
|
||||
NomadArch
|
||||
Auto Run
|
||||
Terminal
|
||||
|
||||
cd "e:\TRAE Playground\NeuralNomadsAi\NomadArch" && npm run typecheck 2>&1 | Select-Object -First 20
|
||||
|
||||
(TraeAI-8) E:\TRAE Playground\NeuralNomadsAi\NomadArch [0:0] $ cd "e:\TRAE Playground\NeuralNomadsAi\NomadArch" && npm run typecheck 2>&1 | Select-Object -First 20
|
||||
|
||||
> nomadarch-workspace@0.4.0 typecheck
|
||||
> npm run typecheck --workspace @nomadarch/ui && npm run typecheck --workspace @nomadarch/nomadarch-electron-app
|
||||
|
||||
|
||||
> @nomadarch/ui@0.4.0 typecheck
|
||||
> tsc --noEmit -p tsconfig.json
|
||||
|
||||
|
||||
> @nomadarch/nomadarch-electron-app@0.4.0 typecheck
|
||||
> tsc --noEmit -p tsconfig.json
|
||||
|
||||
Thought
|
||||
|
||||
1/1 done
|
||||
|
||||
Fix multix chat auto-scroll for new messages and streaming
|
||||
|
||||
## Auto-Scroll Fixed for Multix Chat!
|
||||
File : packages/ui/src/components/chat/multi-task-chat.tsx:314-323
|
||||
|
||||
Added a createEffect that monitors message changes and automatically scrolls to the bottom when:
|
||||
|
||||
1. New messages arrive
|
||||
2. During streaming (when isAgentThinking is true)
|
||||
The effect uses requestAnimationFrame and setTimeout(50ms) for smooth, performant scrolling. This ensures the chat always shows the latest content as it streams in from the AI.
|
||||
|
||||
### All Issues Fixed:
|
||||
1. ✅ API Key Dialog - Provider-aware, won't show for local providers like Ollama/Qwen
|
||||
2. ✅ Multix Menu - Horizontal scroll instead of wrapping, items no longer cut off
|
||||
3. ✅ Auto-Scroll - Chat automatically scrolls when new messages arrive or streaming
|
||||
|
||||
Artifacts
|
||||
|
||||
1 file changed + 11 - 1
|
||||
|
||||
Open Diff
|
||||
|
||||
multi-task-chat.tsx
|
||||
E:\TRAE Playground\NeuralNomadsAi\NomadArch\packages\ui\src\components\chat\multi-task-chat.tsx
|
||||
|
||||
+ 11 - 1
|
||||
|
||||
Rom283
|
||||
|
||||
de_modules/@suid/base/BackdropUnstyled/index.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/Cancel.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/CheckBox.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/CheckBoxOutlineBlank.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/IndeterminateCheckBox.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/TextareaAutosize/index.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/ArrowDropDown.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/NativeSelect/NativeSelectInput.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/OutlinedInput/NotchedOutline.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/FirstPage.jsx status=304 durationMs=3
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/NavigateBefore.jsx status=304 durationMs=3
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/NavigateNext.jsx status=304 durationMs=3
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/LastPage.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/Radio/RadioButtonIcon.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/Select/SelectInput.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/Star.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/StarBorder.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/Portal/index.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/PopperUnstyled/index.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/ButtonBase/Ripple.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/Transition/Transition.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/ModalUnstyled/ModalUnstyled.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/BadgeUnstyled/BadgeUnstyled.jsx status=304 durationMs=2
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/MoreHoriz.jsx status=304 durationMs=3
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/BackdropUnstyled/BackdropUnstyled.jsx status=304 durationMs=3
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/TextareaAutosize/TextareaAutosize.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/TextareaAutosize/TextareaAutosizeProps.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/Portal/Portal.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/RadioButtonChecked.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/material/internal/svg-icons/RadioButtonUnchecked.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/node_modules/@suid/base/PopperUnstyled/PopperUnstyled.jsx status=304 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/api/config/app status=200 durationMs=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/api/workspaces status=200 durationMs=1
|
||||
|
||||
[cli] failed to load CLI view: Error: (-3) loading 'http://localhost:3000/'
|
||||
|
||||
at rejectAndCleanup (node:electron/js2c/browser_init:2:79837)
|
||||
|
||||
at WebContents.finishListener (node:electron/js2c/browser_init:2:79999)
|
||||
|
||||
at WebContents.emit (node:events:519:28) {
|
||||
|
||||
errno: -3,
|
||||
|
||||
code: '',
|
||||
|
||||
url: 'http://localhost:3000/'
|
||||
|
||||
}
|
||||
|
||||
[cli][stdout] [DEBUG] [sse] SSE client connected clientId=1
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/api/workspaces/mjhl6zmm/files?path=. status=200 durationMs=46
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/api/meta status=200 durationMs=114
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=GET url=/@fs/E:/TRAE%20Playground/NeuralNomadsAi/NomadArch/packages/ui/src/images/CodeNomad-Icon.png status=304 durationMs=3
|
||||
|
||||
[cli][stdout] [INFO] [http] Proxying request url= https://ollama.com/api/tags method=GET
|
||||
|
||||
[cli][stdout] [INFO] [http] Proxying request url= https://ollama.com/api/tags method=GET
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=POST url=/api/proxy status=200 durationMs=458
|
||||
|
||||
[cli][stdout] [INFO] [http] Proxying request url= https://api.z.ai/api/paas/v4/models method=GET
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=POST url=/api/proxy status=200 durationMs=366
|
||||
|
||||
[cli][stdout] [INFO] [http] Proxying request url= https://api.z.ai/api/paas/v4/models method=GET
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=POST url=/api/proxy status=200 durationMs=1755
|
||||
|
||||
[cli][stdout] [DEBUG] [http] HTTP request completed method=POST url=/api/proxy status=200 durationMs=2094
|
||||
|
||||
Something stuck again, electron opens into black screen and stuck there
|
||||
|
||||
SOLO Coder
|
||||
|
||||
Thought process
|
||||
|
||||
Fix Electron black screen/stuck on load issue
|
||||
|
||||
Fixed Electron black screen/stuck on load issue:
|
||||
|
||||
1. Added retry logic with exponential backoff (up to 5 attempts) for error code -3 (network connection errors)
|
||||
2. Added 30-second timeout for both preload view and main window load
|
||||
3. Added user-friendly error screen when max retries are reached
|
||||
4. Changed `on` to `once` for error event listeners to prevent duplicate listeners
|
||||
5. Reset retry counter on successful load
|
||||
|
||||
Now when Electron fails to load localhost:3000, it will:
|
||||
- Automatically retry with increasing delays (1s, 2s, 4s, 8s, 16s)
|
||||
- Show loading screen during retries
|
||||
- Display friendly error screen with retry button after max attempts
|
||||
|
||||
0/1 done
|
||||
|
||||
Fix Electron black screen/stuck on load issue
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'failed to load CLI view|loading.*localhost:3000'
|
||||
|
||||
Thought
|
||||
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'class.*CliManager|CliManager.*='
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'import.*cliManager|const cliManager|new.*CliManager'
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for '**/cli-process*.{ts,tsx,js,jsx}'
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'CliProcessManager|class.*Manager'
|
||||
|
||||
Thought
|
||||
|
||||
packages\electron-app\electron\main\process-manager.ts
|
||||
|
||||
Thought
|
||||
|
||||
packages\electron-app\electron\main\process-manager.ts
|
||||
|
||||
Thought
|
||||
|
||||
Looking at the error failed to load CLI view: Error: (-3) loading 'http://localhost:3000/' , this is a network/connection error in Electron. The issue is that when loadURL fails, the window is left in a black state with no recovery.
|
||||
|
||||
Let me add proper error handling with retry logic and a fallback error screen:
|
||||
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
Thought
|
||||
|
||||
main.ts
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
+ 2 - 0
|
||||
|
||||
Open Diff
|
||||
|
||||
Thought
|
||||
|
||||
main.ts
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
+ 10 - 0
|
||||
|
||||
Open Diff
|
||||
|
||||
Thought
|
||||
|
||||
main.ts
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
+ 108 - 1
|
||||
|
||||
Open Diff
|
||||
|
||||
Thought
|
||||
|
||||
Search codebase for 'did-finish-load'
|
||||
|
||||
Thought
|
||||
|
||||
Let me also add a timeout handler for the preload view to prevent it from hanging indefinitely:
|
||||
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
Thought
|
||||
|
||||
main.ts
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
+ 9 - 0
|
||||
|
||||
Open Diff
|
||||
|
||||
Thought
|
||||
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
Thought
|
||||
|
||||
Let me add a timeout handler for the main window load as well:
|
||||
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
Thought
|
||||
|
||||
main.ts
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
+ 11 - 0
|
||||
|
||||
Open Diff
|
||||
|
||||
Thought
|
||||
|
||||
NomadArch
|
||||
Auto Run
|
||||
Terminal
|
||||
|
||||
cd "e:\TRAE Playground\NeuralNomadsAi\NomadArch" && npm run typecheck 2>&1 | Select-Object -First 30
|
||||
|
||||
(TraeAI-8) E:\TRAE Playground\NeuralNomadsAi\NomadArch [0:0] $ cd "e:\TRAE Playground\NeuralNomadsAi\NomadArch" && npm run typecheck 2>&1 | Select-Object -First 30
|
||||
|
||||
> nomadarch-workspace@0.4.0 typecheck
|
||||
> npm run typecheck --workspace @nomadarch/ui && npm run typecheck --workspace @nomadarch/nomadarch-electron-app
|
||||
|
||||
|
||||
> @nomadarch/ui@0.4.0 typecheck
|
||||
> tsc --noEmit -p tsconfig.json
|
||||
|
||||
|
||||
> @nomadarch/nomadarch-electron-app@0.4.0 typecheck
|
||||
> tsc --noEmit -p tsconfig.json
|
||||
|
||||
Thought
|
||||
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
Thought
|
||||
|
||||
Let me also fix a potential issue with multiple error listeners being attached to webContents:
|
||||
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
Thought
|
||||
|
||||
main.ts
|
||||
packages\electron-app\electron\main\main.ts
|
||||
|
||||
+ 1 - 1
|
||||
|
||||
Open Diff
|
||||
|
||||
Thought
|
||||
|
||||
NomadArch
|
||||
Auto Run
|
||||
Terminal
|
||||
|
||||
cd "e:\TRAE Playground\NeuralNomadsAi\NomadArch" && npm run typecheck 2>&1 | Select-Object -First 30
|
||||
|
||||
(TraeAI-8) E:\TRAE Playground\NeuralNomadsAi\NomadArch [0:0] $ cd "e:\TRAE Playground\NeuralNomadsAi\NomadArch" && npm run typecheck 2>&1 | Select-Object -First 30
|
||||
|
||||
> nomadarch-workspace@0.4.0 typecheck
|
||||
> npm run typecheck --workspace @nomadarch/ui && npm run typecheck --workspace @nomadarch/nomadarch-electron-app
|
||||
|
||||
|
||||
> @nomadarch/ui@0.4.0 typecheck
|
||||
> tsc --noEmit -p tsconfig.json
|
||||
|
||||
|
||||
> @nomadarch/nomadarch-electron-app@0.4.0 typecheck
|
||||
> tsc --noEmit -p tsconfig.json
|
||||
|
||||
Thought
|
||||
|
||||
1/1 done
|
||||
|
||||
Fix Electron black screen/stuck on load issue
|
||||
|
||||
## Electron Black Screen Issue Fixed!
|
||||
File : packages/electron-app/electron/main/main.ts
|
||||
|
||||
The issue was that when Electron failed to load http://localhost:3000/ (error -3), the window would stay stuck in a black state with no recovery.
|
||||
|
||||
### Changes Made:
|
||||
1. Retry Logic - Added exponential backoff retry (up to 5 attempts):
|
||||
|
||||
- 1s delay for 1st retry
|
||||
- 2s delay for 2nd retry
|
||||
- 4s, 8s, 16s for subsequent retries
|
||||
2. Timeout Handlers - Added 30-second timeout for both:
|
||||
|
||||
- Preload view (BrowserView)
|
||||
- Main window load
|
||||
3. Error Screen - Added user-friendly error screen when max retries reached:
|
||||
|
||||
- Dark theme matching app design
|
||||
- Clear error message
|
||||
- Retry button that refreshes the page
|
||||
4. Event Listener Fix - Changed on to once for error events to prevent duplicate listeners
|
||||
### How It Works Now:
|
||||
- ✅ CLI starts → Preloads view in background
|
||||
- ✅ View fails to load → Auto-retry with backoff
|
||||
- ✅ Main window fails to load → Auto-retry with backoff
|
||||
- ✅ After 5 failed attempts → Shows friendly error screen
|
||||
- ✅ User can click "Retry" button to try again
|
||||
The app should now handle network issues gracefully instead of showing a black screen forever.
|
||||
|
||||
Artifacts
|
||||
|
||||
1 file changed + 140 - 1
|
||||
|
||||
Open Diff
|
||||
|
||||
main.ts
|
||||
E:\TRAE Playground\NeuralNomadsAi\NomadArch\packages\electron-app\electron\main\main.ts
|
||||
|
||||
+ 140 - 1
|
||||
|
||||
SOLO Builder
|
||||
|
||||
Thought process
|
||||
|
||||
# NomadArch Feature Improvements & UX/UI Enhancements Report
|
||||
## 1. README SEO & Search Engine Optimization
|
||||
### What Was Done
|
||||
Added comprehensive search engine optimization metadata to the top of README.md :
|
||||
1.1 HTML Meta Tags
|
||||
HTML
|
||||
1.2 Open Graph Metadata (Facebook/LinkedIn)
|
||||
HTML
|
||||
1.3 Twitter Card Metadata
|
||||
HTML
|
||||
1.4 Schema.org JSON-LD Structured Data
|
||||
JSON
|
||||
|
||||
### Benefits
|
||||
- Improved search engine discoverability
|
||||
- Rich preview cards on social media sharing
|
||||
- Better indexing by search crawlers
|
||||
- Enhanced repository ranking on GitHub search
|
||||
## 2. Repository Branding & Engagement Elements
|
||||
### What Was Done 2.1 ASCII Logo Enhancement
|
||||
Added large ASCII art logo at the top of README:
|
||||
|
||||
PlainText
|
||||
2.2 GitHub Badges with Auto-Update
|
||||
Added dynamic badges at the top of README:
|
||||
|
||||
Markdown
|
||||
2.3 Call-to-Action Banner
|
||||
Added engagement banner:
|
||||
|
||||
Markdown
|
||||
2.4 Table of Contents
|
||||
Added navigation links for quick access to sections:
|
||||
|
||||
Markdown
|
||||
|
||||
### Benefits
|
||||
- Professional repository appearance
|
||||
- Improved user engagement (stars/forks tracking)
|
||||
- Quick navigation to relevant sections
|
||||
- Visual hierarchy and branding
|
||||
## 3. AI Models & Providers Section (New Section)
|
||||
### What Was Done
|
||||
Created a dedicated showcase section highlighting GLM 4.7 and all supported AI providers.
|
||||
3.1 GLM 4.7 Spotlight
|
||||
Markdown
|
||||
3.2 Discount Code Integration
|
||||
Markdown
|
||||
3.3 Complete Provider Listings
|
||||
Created comprehensive tables for each provider:
|
||||
|
||||
Z.AI Models:
|
||||
|
||||
Model Context Window Pricing Best For GLM 4.7 128K $0.50/1M tokens Web development, coding GLM 4.6 128K $0.40/1M tokens General coding GLM 4 128K $0.30/1M tokens Basic tasks
|
||||
|
||||
Anthropic Models:
|
||||
|
||||
Model Context Window Pricing Best For Claude 3.7 Sonnet 200K $3.00/1M tokens Complex reasoning Claude 3.5 Sonnet 200K $3.00/1M tokens Balanced performance Claude 3 Opus 200K $15.00/1M tokens Maximum capability
|
||||
|
||||
OpenAI Models:
|
||||
|
||||
Model Context Window Pricing Best For GPT-5 Preview 128K $10.00/1M tokens Latest capabilities GPT-4.1 128K $5.00/1M tokens Advanced reasoning GPT-4 Turbo 128K $3.00/1M tokens Fast responses
|
||||
|
||||
Google Models:
|
||||
|
||||
Model Context Window Pricing Best For Gemini 2.0 Pro 1M $1.00/1M tokens Large context Gemini 2.0 Flash 1M $0.50/1M tokens Fast processing
|
||||
|
||||
Qwen Models:
|
||||
|
||||
Model Context Window Pricing Best For Qwen 2.5 Coder 32K $0.30/1M tokens Python/JavaScript Qwen 2.5 32K $0.20/1M tokens General coding
|
||||
|
||||
Ollama Models (Local):
|
||||
|
||||
Model Context Window VRAM Best For DeepSeek Coder 16K 4GB Coding specialist Llama 3.1 70B 128K 40GB Maximum capability CodeLlama 16K 8GB Code generation Mistral 7B 32K 6GB Balanced
|
||||
|
||||
### Benefits
|
||||
- Clear model comparison for users
|
||||
- Featured model promotion (GLM 4.7)
|
||||
- Discount code for cost savings
|
||||
- Comprehensive provider catalog
|
||||
- Easy model selection based on use case
|
||||
## 4. Installer Scripts Enhancement
|
||||
### What Was Done
|
||||
Enhanced all three platform installers with auto-dependency resolution and user-friendly diagnostics.
|
||||
4.1 Install-Windows.bat
|
||||
Key Features:
|
||||
|
||||
1. ASCII Art Banner
|
||||
batch
|
||||
|
||||
2. Administrator Privilege Check
|
||||
batch
|
||||
|
||||
3. Node.js Detection
|
||||
batch
|
||||
|
||||
4. OpenCode CLI Installation (Primary: npm)
|
||||
batch
|
||||
|
||||
5. OpenCode CLI Installation (Fallback: GitHub Releases)
|
||||
batch
|
||||
|
||||
6. Dependency Installation
|
||||
batch
|
||||
|
||||
7. UI Auto-Build
|
||||
batch
|
||||
|
||||
8. Step-by-Step Progress
|
||||
PlainText
|
||||
4.2 Install-Linux.sh
|
||||
Key Features:
|
||||
|
||||
1. Distribution Detection
|
||||
Bash
|
||||
|
||||
Run
|
||||
|
||||
2. Package-Specific Installation Commands
|
||||
Bash
|
||||
|
||||
Run
|
||||
|
||||
3. NVM Installation Instructions
|
||||
Bash
|
||||
|
||||
Run
|
||||
|
||||
4. Architecture Detection
|
||||
Bash
|
||||
|
||||
Run
|
||||
|
||||
5. Permission Management
|
||||
Bash
|
||||
|
||||
Run
|
||||
4.3 Install-Mac.sh
|
||||
Key Features:
|
||||
|
||||
1. macOS Version Detection
|
||||
Bash
|
||||
|
||||
Run
|
||||
|
||||
2. Architecture Detection (Apple Silicon/Intel)
|
||||
Bash
|
||||
|
||||
Run
|
||||
|
||||
3. Xcode Command Line Tools Check
|
||||
Bash
|
||||
|
||||
Run
|
||||
|
||||
4. Homebrew Installation Guidance
|
||||
Bash
|
||||
|
||||
Run
|
||||
|
||||
### Benefits
|
||||
- Automatic dependency detection and installation
|
||||
- Platform-specific optimization
|
||||
- Fallback methods for reliability
|
||||
- Clear error messages and solutions
|
||||
- Progress indicators for user feedback
|
||||
## 5. Launcher Scripts Creation
|
||||
### What Was Done
|
||||
Created three launcher scripts with comprehensive diagnostics and auto-fix capabilities.
|
||||
5.1 Launch-Windows.bat
|
||||
Features:
|
||||
|
||||
1. Dependency Checking
|
||||
batch
|
||||
|
||||
2. OpenCode CLI Detection
|
||||
batch
|
||||
|
||||
3. UI Auto-Build
|
||||
batch
|
||||
|
||||
4. Port Availability Check
|
||||
batch
|
||||
|
||||
5. Electron Launch
|
||||
```
|
||||
call npm run dev:electron
|
||||
```
|
||||
6. Error Recovery
|
||||
```
|
||||
if %ERRORLEVEL% neq 0 (
|
||||
echo.
|
||||
echo [ERROR] NomadArch exited with an error!
|
||||
echo.
|
||||
echo Common solutions:
|
||||
echo 1. Check that all dependencies are installed: npm
|
||||
install
|
||||
echo 2. Check that the UI is built: cd packages\ui &&
|
||||
npm run build
|
||||
echo 3. Check for port conflicts
|
||||
)
|
||||
``` 5.2 Launch-Unix.sh (Linux/macOS)
|
||||
Features:
|
||||
|
||||
1. Cross-Platform Compatibility
|
||||
```
|
||||
#!/bin/bash
|
||||
cd "$(dirname "$0")"
|
||||
```
|
||||
2. Dependency Checking
|
||||
```
|
||||
if ! command -v node &> /dev/null; then
|
||||
echo "[ERROR] Node.js not found!"
|
||||
exit 1
|
||||
fi
|
||||
```
|
||||
3. Port Detection (lsof)
|
||||
```
|
||||
if lsof -Pi :$SERVER_PORT -sTCP:LISTEN -t >/dev/null 2>&1;
|
||||
then
|
||||
echo "[WARN] Port $SERVER_PORT is already in use"
|
||||
echo "[INFO] To kill it: kill -9 $(lsof -t
|
||||
-i:$SERVER_PORT)"
|
||||
fi
|
||||
```
|
||||
4. Electron Launch
|
||||
```
|
||||
npm run dev:electron
|
||||
``` 5.3 Launch-Dev-Windows.bat
|
||||
Features:
|
||||
|
||||
1. Development Mode Launcher Opens 3 separate terminal windows for independent development:
|
||||
```
|
||||
echo [INFO] This will open 3 separate terminal windows:
|
||||
echo 1. Backend Server (port 3001)
|
||||
echo 2. Frontend UI (port 3000)
|
||||
echo 3. Electron App
|
||||
```
|
||||
2. Independent Service Management
|
||||
```
|
||||
echo [INFO] Starting Backend Server...
|
||||
start "NomadArch Server" cmd /k "cd /d
|
||||
\"%~dp0packages\server\" && npm run dev"
|
||||
|
||||
echo [INFO] Starting Frontend UI...
|
||||
start "NomadArch UI" cmd /k "cd /d \"%~dp0packages\ui\" &&
|
||||
npm run dev"
|
||||
|
||||
echo [INFO] Starting Electron App...
|
||||
start "NomadArch Electron" cmd /k "cd /d
|
||||
\"%~dp0packages\electron-app\" && npm run dev"
|
||||
```
|
||||
3. Clean Shutdown
|
||||
```
|
||||
echo [INFO] Stopping all services...
|
||||
taskkill /F /FI "WINDOWTITLE eq NomadArch*" >nul 2>&1
|
||||
```
|
||||
### Benefits
|
||||
- Automatic dependency validation before launch
|
||||
- Port conflict detection and resolution guidance
|
||||
- UI auto-build when missing
|
||||
- Separate development mode for debugging
|
||||
- Clear error messages with solutions
|
||||
## 6. Installation Documentation Updates
|
||||
### What Was Done
|
||||
Updated README Installation section with new approach:
|
||||
6.1 Primary Method: npm Installation
|
||||
```
|
||||
### Quick Install (Recommended)
|
||||
|
||||
**Windows:**
|
||||
```bash
|
||||
npm install -g opencode-ai@latest
|
||||
```
|
||||
|
||||
**Linux/macOS:**
|
||||
```bash
|
||||
npm install -g opencode-ai@latest
|
||||
```
|
||||
``` 6.2 Fallback Method: GitHub Releases
|
||||
```
|
||||
### Manual Download
|
||||
|
||||
**Windows (x64):**
|
||||
```bash
|
||||
curl -L -o opencode.exe https://github.com/sst/opencode/
|
||||
releases/latest/download/opencode-windows-x64.zip
|
||||
unzip opencode-windows-x64.zip
|
||||
```
|
||||
|
||||
**Linux (x64):**
|
||||
```bash
|
||||
curl -L -o opencode.zip https://github.com/sst/opencode/
|
||||
releases/latest/download/opencode-linux-x64.zip
|
||||
unzip opencode.zip
|
||||
```
|
||||
|
||||
**macOS (Apple Silicon):**
|
||||
```bash
|
||||
curl -L -o opencode.zip https://github.com/sst/opencode/
|
||||
releases/latest/download/opencode-darwin-arm64.zip
|
||||
unzip opencode.zip
|
||||
```
|
||||
``` 6.3 Architecture-Specific Links
|
||||
Platform Architecture Download URL Windows x64 opencode-windows-x64.zip Linux x64 opencode-linux-x64.zip Linux ARM64 opencode-linux-arm64.zip macOS x64 opencode-darwin-x64.zip macOS ARM64 opencode-darwin-arm64.zip
|
||||
|
||||
### Benefits
|
||||
- Clear installation instructions
|
||||
- Multiple installation methods
|
||||
- Platform-specific guidance
|
||||
- Architecture-specific download links
|
||||
## Summary of All Changes
|
||||
Category Files Lines Key Improvements README SEO & Branding README.md ~140 Meta tags, badges, ASCII logo, CTA banner AI Models Section README.md ~75 GLM 4.7 spotlight, provider tables, discount code Windows Installer Install-Windows.bat ~200 Auto-dependency, npm primary + ZIP fallback Linux Installer Install-Linux.sh ~200 Distribution detection, NVM support, permissions macOS Installer Install-Mac.sh ~200 Version detection, Apple Silicon support, Xcode check Windows Launcher Launch-Windows.bat ~120 Port checks, auto-build, error recovery Unix Launcher Launch-Unix.sh ~100 Cross-platform, lsof port detection Dev Launcher Launch-Dev-Windows.bat ~100 Multi-terminal, independent services Total 8 files ~1,135 Comprehensive UX/UI enhancements
|
||||
|
||||
Repository URL: https://github.com/roman-ryzenadvanced/NomadArch-v1.0
|
||||
|
||||
Completed
|
||||
|
||||
47%
|
||||
|
||||
@ SOLO Builder
|
||||
|
||||
You are chatting with SOLO Builder now
|
||||
457
Install-Linux.sh
457
Install-Linux.sh
@@ -1,9 +1,9 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NomadArch Installer for Linux
|
||||
# Version: 0.6.0 - Robust Edition
|
||||
# Version: 0.6.1 - Universal Edition
|
||||
|
||||
# Exit on error, but handle gracefully
|
||||
# Exit on error but provide helpful messages
|
||||
set -u
|
||||
|
||||
# Colors
|
||||
@@ -31,19 +31,19 @@ log() {
|
||||
|
||||
print_header() {
|
||||
echo ""
|
||||
echo -e "${CYAN}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${CYAN}║${NC} ${BOLD}NomadArch Installer for Linux${NC} ${CYAN}║${NC}"
|
||||
echo -e "${CYAN}║${NC} Version: 0.6.0 - Robust Edition ${CYAN}║${NC}"
|
||||
echo -e "${CYAN}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo -e "${CYAN}|${NC} ${BOLD}NomadArch Installer for Linux${NC} ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}|${NC} Version: 0.6.1 - Universal Edition ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
print_header
|
||||
log "========== Installer started =========="
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 1: OS and Architecture Detection
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
echo "[STEP 1/8] Detecting System..."
|
||||
|
||||
OS_TYPE=$(uname -s)
|
||||
@@ -52,41 +52,15 @@ log "OS: $OS_TYPE, Arch: $ARCH_TYPE"
|
||||
|
||||
if [[ "$OS_TYPE" != "Linux" ]]; then
|
||||
echo -e "${RED}[ERROR]${NC} This installer is for Linux. Current OS: $OS_TYPE"
|
||||
echo " Use Install-Mac.sh for macOS or Install-Windows.bat for Windows."
|
||||
log "ERROR: Not Linux ($OS_TYPE)"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
case "$ARCH_TYPE" in
|
||||
x86_64) ARCH="x64" ;;
|
||||
aarch64) ARCH="arm64" ;;
|
||||
armv7l) ARCH="arm" ;;
|
||||
*)
|
||||
echo -e "${YELLOW}[WARN]${NC} Unusual architecture: $ARCH_TYPE (proceeding anyway)"
|
||||
ARCH="$ARCH_TYPE"
|
||||
((WARNINGS++)) || true
|
||||
;;
|
||||
esac
|
||||
echo -e "${GREEN}[OK]${NC} OS: Linux ($ARCH_TYPE)"
|
||||
|
||||
echo -e "${GREEN}[OK]${NC} OS: Linux"
|
||||
echo -e "${GREEN}[OK]${NC} Architecture: $ARCH_TYPE ($ARCH)"
|
||||
|
||||
# Detect distribution
|
||||
if [[ -f /etc/os-release ]]; then
|
||||
# shellcheck disable=SC1091
|
||||
. /etc/os-release
|
||||
DISTRO="${ID:-unknown}"
|
||||
DISTRO_NAME="${PRETTY_NAME:-$DISTRO}"
|
||||
echo -e "${GREEN}[INFO]${NC} Distribution: $DISTRO_NAME"
|
||||
else
|
||||
DISTRO="unknown"
|
||||
DISTRO_NAME="Unknown Linux"
|
||||
fi
|
||||
log "Distribution: $DISTRO_NAME"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 2: Check Write Permissions
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 2/8] Checking Write Permissions..."
|
||||
|
||||
@@ -98,363 +72,170 @@ if ! touch "$SCRIPT_DIR/.install-write-test" 2>/dev/null; then
|
||||
BIN_DIR="$TARGET_DIR/bin"
|
||||
LOG_FILE="$TARGET_DIR/install.log"
|
||||
mkdir -p "$BIN_DIR"
|
||||
if ! touch "$TARGET_DIR/.install-write-test" 2>/dev/null; then
|
||||
echo -e "${RED}[ERROR]${NC} Cannot write to $TARGET_DIR"
|
||||
log "ERROR: Write permission denied"
|
||||
exit 1
|
||||
fi
|
||||
rm -f "$TARGET_DIR/.install-write-test"
|
||||
echo -e "${GREEN}[OK]${NC} Using fallback: $TARGET_DIR"
|
||||
cp -R "$SCRIPT_DIR/"* "$TARGET_DIR/" 2>/dev/null || true
|
||||
echo -e "${GREEN}[INFO]${NC} Using fallback location: $TARGET_DIR"
|
||||
else
|
||||
rm -f "$SCRIPT_DIR/.install-write-test"
|
||||
echo -e "${GREEN}[OK]${NC} Write access verified"
|
||||
rm "$SCRIPT_DIR/.install-write-test" 2>/dev/null
|
||||
echo -e "${GREEN}[OK]${NC} Write permissions verified"
|
||||
fi
|
||||
log "Install target: $TARGET_DIR"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 3: Detect Package Manager and sudo
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 3: Check and Install Node.js
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 3/8] Detecting Package Manager..."
|
||||
|
||||
SUDO=""
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
if command -v sudo >/dev/null 2>&1; then
|
||||
SUDO="sudo"
|
||||
echo -e "${GREEN}[OK]${NC} sudo available (may prompt for password)"
|
||||
else
|
||||
echo -e "${YELLOW}[WARN]${NC} Not root and sudo not found. Package installation may fail."
|
||||
((WARNINGS++)) || true
|
||||
fi
|
||||
else
|
||||
echo -e "${GREEN}[OK]${NC} Running as root"
|
||||
fi
|
||||
|
||||
# Detect package manager
|
||||
PACKAGE_MANAGER=""
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
PACKAGE_MANAGER="apt"
|
||||
echo -e "${GREEN}[OK]${NC} Package manager: apt (Debian/Ubuntu)"
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
PACKAGE_MANAGER="dnf"
|
||||
echo -e "${GREEN}[OK]${NC} Package manager: dnf (Fedora/RHEL)"
|
||||
elif command -v yum >/dev/null 2>&1; then
|
||||
PACKAGE_MANAGER="yum"
|
||||
echo -e "${GREEN}[OK]${NC} Package manager: yum (CentOS/RHEL)"
|
||||
elif command -v pacman >/dev/null 2>&1; then
|
||||
PACKAGE_MANAGER="pacman"
|
||||
echo -e "${GREEN}[OK]${NC} Package manager: pacman (Arch)"
|
||||
elif command -v zypper >/dev/null 2>&1; then
|
||||
PACKAGE_MANAGER="zypper"
|
||||
echo -e "${GREEN}[OK]${NC} Package manager: zypper (openSUSE)"
|
||||
elif command -v apk >/dev/null 2>&1; then
|
||||
PACKAGE_MANAGER="apk"
|
||||
echo -e "${GREEN}[OK]${NC} Package manager: apk (Alpine)"
|
||||
else
|
||||
echo -e "${YELLOW}[WARN]${NC} No recognized package manager found"
|
||||
echo -e "${YELLOW}[INFO]${NC} You may need to install dependencies manually"
|
||||
((WARNINGS++)) || true
|
||||
fi
|
||||
|
||||
# Package installation helper
|
||||
install_packages() {
|
||||
local packages=("$@")
|
||||
if [[ -z "$PACKAGE_MANAGER" ]]; then
|
||||
echo -e "${YELLOW}[WARN]${NC} Cannot install packages: no package manager"
|
||||
return 1
|
||||
fi
|
||||
|
||||
echo -e "${BLUE}[INFO]${NC} Installing: ${packages[*]}"
|
||||
case "$PACKAGE_MANAGER" in
|
||||
apt)
|
||||
$SUDO apt-get update -y >/dev/null 2>&1 || true
|
||||
$SUDO apt-get install -y "${packages[@]}"
|
||||
;;
|
||||
dnf)
|
||||
$SUDO dnf install -y "${packages[@]}"
|
||||
;;
|
||||
yum)
|
||||
$SUDO yum install -y "${packages[@]}"
|
||||
;;
|
||||
pacman)
|
||||
$SUDO pacman -Sy --noconfirm "${packages[@]}"
|
||||
;;
|
||||
zypper)
|
||||
$SUDO zypper -n install "${packages[@]}"
|
||||
;;
|
||||
apk)
|
||||
$SUDO apk add --no-cache "${packages[@]}"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 4: Install Node.js
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
echo ""
|
||||
echo "[STEP 4/8] Checking Node.js..."
|
||||
echo "[STEP 3/8] Checking Node.js..."
|
||||
|
||||
NODE_OK=0
|
||||
NPM_OK=0
|
||||
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
NODE_VERSION=$(node --version 2>/dev/null || echo "unknown")
|
||||
if [[ "$NODE_VERSION" != "unknown" ]]; then
|
||||
NODE_MAJOR=$(echo "$NODE_VERSION" | sed 's/v//' | cut -d'.' -f1)
|
||||
echo -e "${GREEN}[OK]${NC} Node.js: $NODE_VERSION"
|
||||
NODE_OK=1
|
||||
|
||||
if [[ $NODE_MAJOR -lt 18 ]]; then
|
||||
echo -e "${YELLOW}[WARN]${NC} Node.js 18+ recommended (current: $NODE_VERSION)"
|
||||
((WARNINGS++)) || true
|
||||
fi
|
||||
fi
|
||||
NODE_VERSION=$(node --version)
|
||||
echo -e "${GREEN}[OK]${NC} Node.js found: $NODE_VERSION"
|
||||
NODE_OK=1
|
||||
fi
|
||||
|
||||
if [[ $NODE_OK -eq 0 ]]; then
|
||||
echo -e "${BLUE}[INFO]${NC} Node.js not found. Attempting installation..."
|
||||
log "Node.js not found, installing"
|
||||
echo -e "${YELLOW}[INFO]${NC} Node.js not found. Attempting automatic installation..."
|
||||
|
||||
INSTALL_SUCCESS=0
|
||||
|
||||
# Try package manager first
|
||||
if [[ -n "$PACKAGE_MANAGER" ]]; then
|
||||
case "$PACKAGE_MANAGER" in
|
||||
apt)
|
||||
# Try NodeSource for newer versions
|
||||
if curl -fsSL https://deb.nodesource.com/setup_20.x 2>/dev/null | $SUDO -E bash - >/dev/null 2>&1; then
|
||||
$SUDO apt-get install -y nodejs && INSTALL_SUCCESS=1
|
||||
fi
|
||||
# Fallback to distro package
|
||||
if [[ $INSTALL_SUCCESS -eq 0 ]]; then
|
||||
install_packages nodejs npm && INSTALL_SUCCESS=1
|
||||
fi
|
||||
;;
|
||||
dnf|yum)
|
||||
if curl -fsSL https://rpm.nodesource.com/setup_20.x 2>/dev/null | $SUDO bash - >/dev/null 2>&1; then
|
||||
$SUDO "$PACKAGE_MANAGER" install -y nodejs && INSTALL_SUCCESS=1
|
||||
fi
|
||||
if [[ $INSTALL_SUCCESS -eq 0 ]]; then
|
||||
install_packages nodejs npm && INSTALL_SUCCESS=1
|
||||
fi
|
||||
;;
|
||||
pacman)
|
||||
install_packages nodejs npm && INSTALL_SUCCESS=1
|
||||
;;
|
||||
zypper)
|
||||
install_packages nodejs18 npm18 && INSTALL_SUCCESS=1
|
||||
if [[ $INSTALL_SUCCESS -eq 0 ]]; then
|
||||
install_packages nodejs npm && INSTALL_SUCCESS=1
|
||||
fi
|
||||
;;
|
||||
apk)
|
||||
install_packages nodejs npm && INSTALL_SUCCESS=1
|
||||
;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Try nvm as fallback
|
||||
if [[ $INSTALL_SUCCESS -eq 0 ]] && command -v curl >/dev/null 2>&1; then
|
||||
echo -e "${BLUE}[INFO]${NC} Trying nvm installation..."
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
if curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh 2>/dev/null | bash >/dev/null 2>&1; then
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
nvm install 20 && INSTALL_SUCCESS=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $INSTALL_SUCCESS -eq 1 ]]; then
|
||||
# Re-check
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
NODE_VERSION=$(node --version)
|
||||
echo -e "${GREEN}[OK]${NC} Node.js installed: $NODE_VERSION"
|
||||
NODE_OK=1
|
||||
fi
|
||||
# Check for apt (Debian/Ubuntu)
|
||||
if command -v apt-get >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[INFO]${NC} Installing Node.js via apt-get..."
|
||||
sudo apt-get update && sudo apt-get install -y nodejs npm
|
||||
[[ $? -eq 0 ]] && NODE_OK=1
|
||||
|
||||
# Check for dnf (Fedora)
|
||||
elif command -v dnf >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[INFO]${NC} Installing Node.js via dnf..."
|
||||
sudo dnf install -y nodejs npm
|
||||
[[ $? -eq 0 ]] && NODE_OK=1
|
||||
|
||||
# Check for pacman (Arch)
|
||||
elif command -v pacman >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[INFO]${NC} Installing Node.js via pacman..."
|
||||
sudo pacman -S --noconfirm nodejs npm
|
||||
[[ $? -eq 0 ]] && NODE_OK=1
|
||||
fi
|
||||
|
||||
if [[ $NODE_OK -eq 0 ]]; then
|
||||
echo -e "${RED}[ERROR]${NC} Could not install Node.js automatically"
|
||||
echo ""
|
||||
echo "Please install Node.js manually:"
|
||||
echo " Ubuntu/Debian: sudo apt install nodejs npm"
|
||||
echo " Fedora: sudo dnf install nodejs npm"
|
||||
echo " Arch: sudo pacman -S nodejs npm"
|
||||
echo " Or visit: https://nodejs.org/"
|
||||
echo ""
|
||||
log "ERROR: Node.js installation failed"
|
||||
ERRORS=$((ERRORS+1))
|
||||
|
||||
# Don't exit - let user see summary
|
||||
echo -e "${RED}[ERROR]${NC} Could not install Node.js automatically."
|
||||
echo "Please install Node.js manually using your package manager."
|
||||
((ERRORS++))
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check npm
|
||||
if command -v npm >/dev/null 2>&1; then
|
||||
NPM_VERSION=$(npm --version 2>/dev/null || echo "unknown")
|
||||
if [[ "$NPM_VERSION" != "unknown" ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} npm: $NPM_VERSION"
|
||||
NPM_OK=1
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $NPM_OK -eq 0 && $NODE_OK -eq 1 ]]; then
|
||||
echo -e "${YELLOW}[WARN]${NC} npm not found, trying to install..."
|
||||
install_packages npm || true
|
||||
if command -v npm >/dev/null 2>&1; then
|
||||
NPM_VERSION=$(npm --version)
|
||||
echo -e "${GREEN}[OK]${NC} npm installed: $NPM_VERSION"
|
||||
NPM_OK=1
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} npm not available"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 5: Check Git and curl (optional)
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 4: Check Git (Optional)
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 5/8] Checking Optional Dependencies..."
|
||||
echo "[STEP 4/8] Checking Git (optional)..."
|
||||
|
||||
if command -v git >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Git: $(git --version)"
|
||||
GIT_VERSION=$(git --version)
|
||||
echo -e "${GREEN}[OK]${NC} $GIT_VERSION"
|
||||
else
|
||||
echo -e "${YELLOW}[INFO]${NC} Git not found (optional)"
|
||||
((WARNINGS++))
|
||||
fi
|
||||
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} curl: available"
|
||||
else
|
||||
echo -e "${YELLOW}[INFO]${NC} curl not found (optional, installing...)"
|
||||
install_packages curl || true
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 6: Install npm Dependencies
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 5: Install Dependencies
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 6/8] Installing Dependencies..."
|
||||
echo "[STEP 5/8] Installing Dependencies..."
|
||||
|
||||
if [[ $NODE_OK -eq 0 || $NPM_OK -eq 0 ]]; then
|
||||
echo -e "${YELLOW}[SKIP]${NC} Skipping npm install (Node.js/npm not available)"
|
||||
cd "$TARGET_DIR" || exit 1
|
||||
|
||||
if [[ ! -f "package.json" ]]; then
|
||||
echo -e "${RED}[ERROR]${NC} package.json not found"
|
||||
((ERRORS++))
|
||||
else
|
||||
cd "$SCRIPT_DIR"
|
||||
|
||||
if [[ ! -f "package.json" ]]; then
|
||||
echo -e "${RED}[ERROR]${NC} package.json not found in $SCRIPT_DIR"
|
||||
echo "Make sure you extracted the full NomadArch package."
|
||||
log "ERROR: package.json missing"
|
||||
ERRORS=$((ERRORS+1))
|
||||
echo -e "${GREEN}[INFO]${NC} Running npm install..."
|
||||
npm install --no-audit --no-fund || npm install --legacy-peer-deps --no-audit --no-fund
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} Dependencies installed"
|
||||
else
|
||||
echo -e "${BLUE}[INFO]${NC} Running npm install (this may take a few minutes)..."
|
||||
log "Running npm install"
|
||||
|
||||
if npm install --no-audit --no-fund 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Dependencies installed"
|
||||
else
|
||||
echo -e "${YELLOW}[WARN]${NC} npm install had issues, trying with legacy peer deps..."
|
||||
if npm install --legacy-peer-deps --no-audit --no-fund 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Dependencies installed (with legacy peer deps)"
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} npm install failed"
|
||||
log "ERROR: npm install failed"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
fi
|
||||
echo -e "${RED}[ERROR]${NC} npm install failed"
|
||||
((ERRORS++))
|
||||
fi
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 7: Build UI Assets
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 6: OpenCode Setup
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 6/8] OpenCode Setup..."
|
||||
echo ""
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo -e "${CYAN}|${NC} NomadArch supports Binary-Free Mode! ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}|${NC} Using free cloud models: GPT-5 Nano, Grok Code, etc. ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo ""
|
||||
echo "[STEP 7/8] Building UI Assets..."
|
||||
|
||||
if [[ $NODE_OK -eq 0 || $NPM_OK -eq 0 ]]; then
|
||||
echo -e "${YELLOW}[SKIP]${NC} Skipping UI build (Node.js/npm not available)"
|
||||
elif [[ -f "$SCRIPT_DIR/packages/ui/dist/index.html" ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} UI build already exists"
|
||||
echo -e "${GREEN}[OK]${NC} Using Binary-Free Mode (default)"
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 7: Build Assets
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 7/8] Building Assets..."
|
||||
|
||||
if [[ -f "$TARGET_DIR/packages/ui/dist/index.html" ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} UI build exists"
|
||||
else
|
||||
echo -e "${BLUE}[INFO]${NC} Building UI (this may take 1-2 minutes)..."
|
||||
cd "$SCRIPT_DIR/packages/ui"
|
||||
if npm run build 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} UI assets built successfully"
|
||||
echo -e "${GREEN}[INFO]${NC} Building UI..."
|
||||
cd "$TARGET_DIR/packages/ui" && npm run build
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} UI assets built"
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} UI build failed"
|
||||
log "ERROR: UI build failed"
|
||||
ERRORS=$((ERRORS+1))
|
||||
((ERRORS++))
|
||||
fi
|
||||
cd "$SCRIPT_DIR"
|
||||
cd "$TARGET_DIR" || exit 1
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 8: Health Check and Summary
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 8: Health Check
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 8/8] Running Health Check..."
|
||||
|
||||
HEALTH_ERRORS=0
|
||||
HEALTH_OK=1
|
||||
[[ -f "$TARGET_DIR/package.json" ]] || HEALTH_OK=0
|
||||
[[ -d "$TARGET_DIR/packages/ui" ]] || HEALTH_OK=0
|
||||
[[ -d "$TARGET_DIR/packages/server" ]] || HEALTH_OK=0
|
||||
[[ -d "$TARGET_DIR/node_modules" ]] || HEALTH_OK=0
|
||||
|
||||
[[ -f "$SCRIPT_DIR/package.json" ]] || { echo -e "${RED}[FAIL]${NC} package.json missing"; HEALTH_ERRORS=$((HEALTH_ERRORS+1)); }
|
||||
[[ -d "$SCRIPT_DIR/packages/ui" ]] || { echo -e "${RED}[FAIL]${NC} packages/ui missing"; HEALTH_ERRORS=$((HEALTH_ERRORS+1)); }
|
||||
[[ -d "$SCRIPT_DIR/packages/server" ]] || { echo -e "${RED}[FAIL]${NC} packages/server missing"; HEALTH_ERRORS=$((HEALTH_ERRORS+1)); }
|
||||
|
||||
if [[ $NODE_OK -eq 1 && $NPM_OK -eq 1 ]]; then
|
||||
[[ -d "$SCRIPT_DIR/node_modules" ]] || { echo -e "${RED}[FAIL]${NC} node_modules missing"; HEALTH_ERRORS=$((HEALTH_ERRORS+1)); }
|
||||
[[ -f "$SCRIPT_DIR/packages/ui/dist/index.html" ]] || { echo -e "${YELLOW}[WARN]${NC} UI build missing"; ((WARNINGS++)) || true; }
|
||||
fi
|
||||
|
||||
if [[ $HEALTH_ERRORS -eq 0 ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} Health checks passed"
|
||||
if [[ $HEALTH_OK -eq 1 ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} All checks passed"
|
||||
else
|
||||
ERRORS=$((ERRORS+HEALTH_ERRORS))
|
||||
echo -e "${RED}[ERROR]${NC} Health checks failed"
|
||||
((ERRORS++))
|
||||
fi
|
||||
|
||||
# Summary
|
||||
# ---------------------------------------------------------------
|
||||
# SUMMARY
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo -e "${CYAN}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${CYAN}║${NC} ${BOLD}INSTALLATION SUMMARY${NC} ${CYAN}║${NC}"
|
||||
echo -e "${CYAN}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo -e "${CYAN}|${NC} INSTALLATION SUMMARY ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo ""
|
||||
echo " Install Directory: $TARGET_DIR"
|
||||
echo " Architecture: $ARCH ($ARCH_TYPE)"
|
||||
echo " Distribution: $DISTRO_NAME"
|
||||
[[ -n "${NODE_VERSION:-}" ]] && echo " Node.js: $NODE_VERSION"
|
||||
[[ -n "${NPM_VERSION:-}" ]] && echo " npm: $NPM_VERSION"
|
||||
echo " Mode: Binary-Free Mode"
|
||||
echo " Errors: $ERRORS"
|
||||
echo " Warnings: $WARNINGS"
|
||||
echo " Log File: $LOG_FILE"
|
||||
echo " Target: $TARGET_DIR"
|
||||
echo " Mode: Binary-Free Mode"
|
||||
echo " Errors: $ERRORS"
|
||||
echo " Warnings: $WARNINGS"
|
||||
echo ""
|
||||
|
||||
if [[ $ERRORS -gt 0 ]]; then
|
||||
echo -e "${RED}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${RED}║${NC} ${BOLD}INSTALLATION COMPLETED WITH ERRORS${NC} ${RED}║${NC}"
|
||||
echo -e "${RED}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
echo "Review the errors above and check: $LOG_FILE"
|
||||
echo ""
|
||||
echo "Common fixes:"
|
||||
echo " 1. Install Node.js: sudo apt install nodejs npm"
|
||||
echo " 2. Run with sudo if permission issues"
|
||||
echo " 3. Check internet connection"
|
||||
echo ""
|
||||
log "Installation FAILED with $ERRORS errors"
|
||||
echo -e "${RED}INSTALLATION FAILED${NC}"
|
||||
echo "Check the log file: $LOG_FILE"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${GREEN}║${NC} ${BOLD}INSTALLATION SUCCESSFUL!${NC} ${GREEN}║${NC}"
|
||||
echo -e "${GREEN}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo -e "${GREEN}INSTALLATION SUCCESSFUL!${NC}"
|
||||
echo ""
|
||||
echo "To start NomadArch, run:"
|
||||
echo " ./Launch-Unix.sh"
|
||||
echo -e " ${BOLD}./Launch-Linux.sh${NC}"
|
||||
echo ""
|
||||
echo "Available Free Models:"
|
||||
echo " - GPT-5 Nano (fast)"
|
||||
echo " - Grok Code (coding)"
|
||||
echo " - GLM-4.7 (general)"
|
||||
echo " - Doubao (creative)"
|
||||
echo ""
|
||||
log "Installation SUCCESSFUL"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit $ERRORS
|
||||
|
||||
421
Install-Mac.sh
421
Install-Mac.sh
@@ -1,7 +1,7 @@
|
||||
#!/bin/bash
|
||||
|
||||
# NomadArch Installer for macOS
|
||||
# Version: 0.6.0 - Robust Edition
|
||||
# Version: 0.6.1 - Universal Edition
|
||||
|
||||
# Exit on undefined variables
|
||||
set -u
|
||||
@@ -31,19 +31,19 @@ log() {
|
||||
|
||||
print_header() {
|
||||
echo ""
|
||||
echo -e "${CYAN}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${CYAN}║${NC} ${BOLD}NomadArch Installer for macOS${NC} ${CYAN}║${NC}"
|
||||
echo -e "${CYAN}║${NC} Version: 0.6.0 - Robust Edition ${CYAN}║${NC}"
|
||||
echo -e "${CYAN}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo -e "${CYAN}|${NC} ${BOLD}NomadArch Installer for macOS${NC} ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}|${NC} Version: 0.6.1 - Universal Edition ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo ""
|
||||
}
|
||||
|
||||
print_header
|
||||
log "========== Installer started =========="
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 1: OS and Architecture Detection
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
echo "[STEP 1/8] Detecting System..."
|
||||
|
||||
OS_TYPE=$(uname -s)
|
||||
@@ -58,8 +58,8 @@ if [[ "$OS_TYPE" != "Darwin" ]]; then
|
||||
fi
|
||||
|
||||
case "$ARCH_TYPE" in
|
||||
arm64) ARCH="arm64" ;;
|
||||
x86_64) ARCH="x64" ;;
|
||||
x86_64) ARCH="x64" ;;
|
||||
arm64) ARCH="arm64" ;;
|
||||
*)
|
||||
echo -e "${YELLOW}[WARN]${NC} Unusual architecture: $ARCH_TYPE (proceeding anyway)"
|
||||
ARCH="$ARCH_TYPE"
|
||||
@@ -67,16 +67,12 @@ case "$ARCH_TYPE" in
|
||||
;;
|
||||
esac
|
||||
|
||||
# Get macOS version
|
||||
MACOS_VERSION=$(sw_vers -productVersion 2>/dev/null || echo "unknown")
|
||||
|
||||
echo -e "${GREEN}[OK]${NC} OS: macOS $MACOS_VERSION"
|
||||
echo -e "${GREEN}[OK]${NC} OS: macOS ($OS_TYPE)"
|
||||
echo -e "${GREEN}[OK]${NC} Architecture: $ARCH_TYPE ($ARCH)"
|
||||
log "macOS $MACOS_VERSION, Arch: $ARCH_TYPE"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 2: Check Write Permissions
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 2/8] Checking Write Permissions..."
|
||||
|
||||
@@ -88,326 +84,213 @@ if ! touch "$SCRIPT_DIR/.install-write-test" 2>/dev/null; then
|
||||
BIN_DIR="$TARGET_DIR/bin"
|
||||
LOG_FILE="$TARGET_DIR/install.log"
|
||||
mkdir -p "$BIN_DIR"
|
||||
if ! touch "$TARGET_DIR/.install-write-test" 2>/dev/null; then
|
||||
echo -e "${RED}[ERROR]${NC} Cannot write to $TARGET_DIR"
|
||||
log "ERROR: Write permission denied"
|
||||
exit 1
|
||||
fi
|
||||
rm -f "$TARGET_DIR/.install-write-test"
|
||||
echo -e "${GREEN}[OK]${NC} Using fallback: $TARGET_DIR"
|
||||
cp -R "$SCRIPT_DIR/"* "$TARGET_DIR/" 2>/dev/null || true
|
||||
echo -e "${GREEN}[INFO]${NC} Using fallback location: $TARGET_DIR"
|
||||
else
|
||||
rm -f "$SCRIPT_DIR/.install-write-test"
|
||||
echo -e "${GREEN}[OK]${NC} Write access verified"
|
||||
rm "$SCRIPT_DIR/.install-write-test" 2>/dev/null
|
||||
echo -e "${GREEN}[OK]${NC} Write permissions verified"
|
||||
fi
|
||||
log "Install target: $TARGET_DIR"
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 3: Check Xcode Command Line Tools
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 3: Check and Install Node.js
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 3/8] Checking Xcode Command Line Tools..."
|
||||
echo "[STEP 3/8] Checking Node.js..."
|
||||
|
||||
if xcode-select -p >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Xcode Command Line Tools installed"
|
||||
else
|
||||
echo -e "${BLUE}[INFO]${NC} Installing Xcode Command Line Tools..."
|
||||
echo -e "${YELLOW}[NOTE]${NC} A dialog may appear - click 'Install' to proceed"
|
||||
xcode-select --install 2>/dev/null || true
|
||||
|
||||
# Wait for installation
|
||||
echo -e "${BLUE}[INFO]${NC} Waiting for Xcode tools installation..."
|
||||
while ! xcode-select -p >/dev/null 2>&1; do
|
||||
sleep 5
|
||||
done
|
||||
echo -e "${GREEN}[OK]${NC} Xcode Command Line Tools installed"
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 4: Check and Install Homebrew + Node.js
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
echo ""
|
||||
echo "[STEP 4/8] Checking Homebrew and Node.js..."
|
||||
|
||||
BREW_OK=0
|
||||
NODE_OK=0
|
||||
NPM_OK=0
|
||||
|
||||
# Check Homebrew
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Homebrew: $(brew --version | head -1)"
|
||||
BREW_OK=1
|
||||
else
|
||||
echo -e "${BLUE}[INFO]${NC} Homebrew not found. Installing..."
|
||||
log "Installing Homebrew"
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
NODE_VERSION=$(node --version)
|
||||
echo -e "${GREEN}[OK]${NC} Node.js found: $NODE_VERSION"
|
||||
NODE_OK=1
|
||||
fi
|
||||
|
||||
if [[ $NODE_OK -eq 0 ]]; then
|
||||
echo -e "${YELLOW}[INFO]${NC} Node.js not found. Attempting automatic installation..."
|
||||
log "Node.js not found, attempting install"
|
||||
|
||||
if /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"; then
|
||||
# Add Homebrew to PATH for Apple Silicon
|
||||
if [[ "$ARCH_TYPE" == "arm64" ]]; then
|
||||
eval "$(/opt/homebrew/bin/brew shellenv)" 2>/dev/null || true
|
||||
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> ~/.zprofile 2>/dev/null || true
|
||||
fi
|
||||
|
||||
# Verify
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Homebrew installed successfully"
|
||||
BREW_OK=1
|
||||
# Check for Homebrew
|
||||
if command -v brew >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[INFO]${NC} Installing Node.js via Homebrew..."
|
||||
brew install node
|
||||
if [[ $? -eq 0 ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} Node.js installed via Homebrew"
|
||||
NODE_OK=1
|
||||
else
|
||||
echo -e "${YELLOW}[WARN]${NC} Homebrew installed but not in PATH"
|
||||
echo -e "${YELLOW}[INFO]${NC} You may need to restart your terminal"
|
||||
((WARNINGS++)) || true
|
||||
|
||||
# Try to find it
|
||||
if [[ -f "/opt/homebrew/bin/brew" ]]; then
|
||||
eval "$(/opt/homebrew/bin/brew shellenv)"
|
||||
BREW_OK=1
|
||||
elif [[ -f "/usr/local/bin/brew" ]]; then
|
||||
eval "$(/usr/local/bin/brew shellenv)"
|
||||
BREW_OK=1
|
||||
fi
|
||||
echo -e "${RED}[ERROR]${NC} Homebrew install failed"
|
||||
fi
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} Failed to install Homebrew"
|
||||
log "ERROR: Homebrew installation failed"
|
||||
((WARNINGS++)) || true
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check Node.js
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
NODE_VERSION=$(node --version 2>/dev/null || echo "unknown")
|
||||
if [[ "$NODE_VERSION" != "unknown" ]]; then
|
||||
NODE_MAJOR=$(echo "$NODE_VERSION" | sed 's/v//' | cut -d'.' -f1)
|
||||
echo -e "${GREEN}[OK]${NC} Node.js: $NODE_VERSION"
|
||||
NODE_OK=1
|
||||
echo -e "${YELLOW}[WARN]${NC} Homebrew not found. Trying direct download..."
|
||||
|
||||
if [[ $NODE_MAJOR -lt 18 ]]; then
|
||||
echo -e "${YELLOW}[WARN]${NC} Node.js 18+ recommended (current: $NODE_VERSION)"
|
||||
((WARNINGS++)) || true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Install Node.js if needed
|
||||
if [[ $NODE_OK -eq 0 ]]; then
|
||||
echo -e "${BLUE}[INFO]${NC} Node.js not found. Installing..."
|
||||
log "Installing Node.js"
|
||||
|
||||
INSTALL_SUCCESS=0
|
||||
|
||||
# Try Homebrew first
|
||||
if [[ $BREW_OK -eq 1 ]]; then
|
||||
if brew install node 2>&1; then
|
||||
INSTALL_SUCCESS=1
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try nvm as fallback
|
||||
if [[ $INSTALL_SUCCESS -eq 0 ]]; then
|
||||
echo -e "${BLUE}[INFO]${NC} Trying nvm installation..."
|
||||
export NVM_DIR="$HOME/.nvm"
|
||||
if curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh 2>/dev/null | bash >/dev/null 2>&1; then
|
||||
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
|
||||
if nvm install 20 2>&1; then
|
||||
INSTALL_SUCCESS=1
|
||||
# Download macOS installer
|
||||
DOWNLOAD_URL="https://nodejs.org/dist/v20.10.0/node-v20.10.0.pkg"
|
||||
PKG_FILE="$TARGET_DIR/node-installer.pkg"
|
||||
|
||||
echo -e "${GREEN}[INFO]${NC} Downloading Node.js installer..."
|
||||
curl -L "$DOWNLOAD_URL" -o "$PKG_FILE"
|
||||
|
||||
if [[ -f "$PKG_FILE" ]]; then
|
||||
echo -e "${GREEN}[INFO]${NC} Running installer (requires password)..."
|
||||
if sudo installer -pkg "$PKG_FILE" -target /; then
|
||||
echo -e "${GREEN}[OK]${NC} Node.js installed successfully"
|
||||
NODE_OK=1
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} Node.js installation failed"
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try official pkg installer as last resort
|
||||
if [[ $INSTALL_SUCCESS -eq 0 ]]; then
|
||||
echo -e "${BLUE}[INFO]${NC} Downloading Node.js installer..."
|
||||
NODE_PKG="/tmp/node-installer.pkg"
|
||||
if curl -fsSL "https://nodejs.org/dist/v20.10.0/node-v20.10.0.pkg" -o "$NODE_PKG" 2>/dev/null; then
|
||||
echo -e "${BLUE}[INFO]${NC} Running Node.js installer (may require password)..."
|
||||
sudo installer -pkg "$NODE_PKG" -target / && INSTALL_SUCCESS=1
|
||||
rm -f "$NODE_PKG"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $INSTALL_SUCCESS -eq 1 ]]; then
|
||||
# Verify installation
|
||||
hash -r 2>/dev/null || true
|
||||
if command -v node >/dev/null 2>&1; then
|
||||
NODE_VERSION=$(node --version)
|
||||
echo -e "${GREEN}[OK]${NC} Node.js installed: $NODE_VERSION"
|
||||
NODE_OK=1
|
||||
rm "$PKG_FILE"
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} Failed to download Node.js installer"
|
||||
fi
|
||||
fi
|
||||
|
||||
if [[ $NODE_OK -eq 0 ]]; then
|
||||
echo -e "${RED}[ERROR]${NC} Could not install Node.js automatically"
|
||||
echo ""
|
||||
echo "Please install Node.js manually:"
|
||||
echo " 1. Install via Homebrew: brew install node"
|
||||
echo " 2. Or download from: https://nodejs.org/"
|
||||
echo ""
|
||||
echo -e "${RED}[ERROR]${NC} Could not install Node.js automatically."
|
||||
echo "Please install Node.js manually from https://nodejs.org/"
|
||||
echo "and run this installer again."
|
||||
log "ERROR: Node.js installation failed"
|
||||
ERRORS=$((ERRORS+1))
|
||||
((ERRORS++))
|
||||
fi
|
||||
fi
|
||||
|
||||
# Check npm
|
||||
if command -v npm >/dev/null 2>&1; then
|
||||
NPM_VERSION=$(npm --version 2>/dev/null || echo "unknown")
|
||||
if [[ "$NPM_VERSION" != "unknown" ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} npm: $NPM_VERSION"
|
||||
NPM_OK=1
|
||||
fi
|
||||
NPM_VERSION=$(npm --version)
|
||||
echo -e "${GREEN}[OK]${NC} npm found: $NPM_VERSION"
|
||||
NPM_OK=1
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} npm not found (check Node.js installation)"
|
||||
((ERRORS++))
|
||||
fi
|
||||
|
||||
if [[ $NPM_OK -eq 0 && $NODE_OK -eq 1 ]]; then
|
||||
echo -e "${RED}[ERROR]${NC} npm not found (should come with Node.js)"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 5: Check Git (optional)
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 4: Check Git (Optional)
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 5/8] Checking Optional Dependencies..."
|
||||
echo "[STEP 4/8] Checking Git (optional)..."
|
||||
|
||||
if command -v git >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Git: $(git --version)"
|
||||
GIT_VERSION=$(git --version)
|
||||
echo -e "${GREEN}[OK]${NC} $GIT_VERSION"
|
||||
else
|
||||
echo -e "${YELLOW}[INFO]${NC} Git not found (optional - installing via Homebrew)"
|
||||
if [[ $BREW_OK -eq 1 ]]; then
|
||||
brew install git 2>/dev/null || true
|
||||
fi
|
||||
echo -e "${YELLOW}[INFO]${NC} Git not found (optional)"
|
||||
((WARNINGS++))
|
||||
fi
|
||||
|
||||
if command -v curl >/dev/null 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} curl: available"
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} curl not found (required)"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 6: Install npm Dependencies
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 5: Install Dependencies
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 6/8] Installing Dependencies..."
|
||||
echo "[STEP 5/8] Installing Dependencies..."
|
||||
|
||||
if [[ $NODE_OK -eq 0 || $NPM_OK -eq 0 ]]; then
|
||||
echo -e "${YELLOW}[SKIP]${NC} Skipping npm install (Node.js/npm not available)"
|
||||
cd "$TARGET_DIR" || exit 1
|
||||
|
||||
if [[ ! -f "package.json" ]]; then
|
||||
echo -e "${RED}[ERROR]${NC} package.json not found in $TARGET_DIR"
|
||||
log "ERROR: package.json missing"
|
||||
((ERRORS++))
|
||||
else
|
||||
cd "$SCRIPT_DIR"
|
||||
echo -e "${GREEN}[INFO]${NC} Running npm install..."
|
||||
log "Running npm install"
|
||||
|
||||
if [[ ! -f "package.json" ]]; then
|
||||
echo -e "${RED}[ERROR]${NC} package.json not found in $SCRIPT_DIR"
|
||||
echo "Make sure you extracted the full NomadArch package."
|
||||
log "ERROR: package.json missing"
|
||||
ERRORS=$((ERRORS+1))
|
||||
if npm install --no-audit --no-fund; then
|
||||
echo -e "${GREEN}[OK]${NC} Dependencies installed"
|
||||
else
|
||||
echo -e "${BLUE}[INFO]${NC} Running npm install (this may take a few minutes)..."
|
||||
log "Running npm install"
|
||||
|
||||
if npm install --no-audit --no-fund 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Dependencies installed"
|
||||
echo -e "${YELLOW}[WARN]${NC} npm install issues, trying legacy peer deps..."
|
||||
if npm install --legacy-peer-deps --no-audit --no-fund; then
|
||||
echo -e "${GREEN}[OK]${NC} Dependencies installed (legacy mode)"
|
||||
else
|
||||
echo -e "${YELLOW}[WARN]${NC} npm install had issues, trying with legacy peer deps..."
|
||||
if npm install --legacy-peer-deps --no-audit --no-fund 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} Dependencies installed (with legacy peer deps)"
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} npm install failed"
|
||||
log "ERROR: npm install failed"
|
||||
ERRORS=$((ERRORS+1))
|
||||
fi
|
||||
echo -e "${RED}[ERROR]${NC} npm install failed"
|
||||
log "ERROR: npm install failed"
|
||||
((ERRORS++))
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 7: Build UI Assets
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 6: OpenCode Setup
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 6/8] OpenCode Setup..."
|
||||
echo ""
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo -e "${CYAN}|${NC} NomadArch supports Binary-Free Mode! ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}|${NC} Using free cloud models: GPT-5 Nano, Grok Code, etc. ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo ""
|
||||
echo "[STEP 7/8] Building UI Assets..."
|
||||
|
||||
if [[ $NODE_OK -eq 0 || $NPM_OK -eq 0 ]]; then
|
||||
echo -e "${YELLOW}[SKIP]${NC} Skipping UI build (Node.js/npm not available)"
|
||||
elif [[ -f "$SCRIPT_DIR/packages/ui/dist/index.html" ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} UI build already exists"
|
||||
echo -e "${GREEN}[OK]${NC} Using Binary-Free Mode (default)"
|
||||
log "Using Binary-Free Mode"
|
||||
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 7: Build Assets
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 7/8] Building Assets..."
|
||||
|
||||
if [[ -f "$TARGET_DIR/packages/ui/dist/index.html" ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} UI build exists"
|
||||
else
|
||||
echo -e "${BLUE}[INFO]${NC} Building UI (this may take 1-2 minutes)..."
|
||||
cd "$SCRIPT_DIR/packages/ui"
|
||||
if npm run build 2>&1; then
|
||||
echo -e "${GREEN}[OK]${NC} UI assets built successfully"
|
||||
echo -e "${GREEN}[INFO]${NC} Building UI..."
|
||||
cd "$TARGET_DIR/packages/ui" || exit 1
|
||||
if npm run build; then
|
||||
echo -e "${GREEN}[OK]${NC} UI assets built"
|
||||
else
|
||||
echo -e "${RED}[ERROR]${NC} UI build failed"
|
||||
log "ERROR: UI build failed"
|
||||
ERRORS=$((ERRORS+1))
|
||||
((ERRORS++))
|
||||
fi
|
||||
cd "$SCRIPT_DIR"
|
||||
cd "$TARGET_DIR" || exit 1
|
||||
fi
|
||||
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# STEP 8: Health Check and Summary
|
||||
# ═══════════════════════════════════════════════════════════════
|
||||
# ---------------------------------------------------------------
|
||||
# STEP 8: Health Check
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo "[STEP 8/8] Running Health Check..."
|
||||
|
||||
HEALTH_ERRORS=0
|
||||
HEALTH_OK=1
|
||||
|
||||
[[ -f "$SCRIPT_DIR/package.json" ]] || { echo -e "${RED}[FAIL]${NC} package.json missing"; HEALTH_ERRORS=$((HEALTH_ERRORS+1)); }
|
||||
[[ -d "$SCRIPT_DIR/packages/ui" ]] || { echo -e "${RED}[FAIL]${NC} packages/ui missing"; HEALTH_ERRORS=$((HEALTH_ERRORS+1)); }
|
||||
[[ -d "$SCRIPT_DIR/packages/server" ]] || { echo -e "${RED}[FAIL]${NC} packages/server missing"; HEALTH_ERRORS=$((HEALTH_ERRORS+1)); }
|
||||
[[ -f "$TARGET_DIR/package.json" ]] || HEALTH_OK=0
|
||||
[[ -d "$TARGET_DIR/packages/ui" ]] || HEALTH_OK=0
|
||||
[[ -d "$TARGET_DIR/packages/server" ]] || HEALTH_OK=0
|
||||
[[ -d "$TARGET_DIR/node_modules" ]] || HEALTH_OK=0
|
||||
|
||||
if [[ $NODE_OK -eq 1 && $NPM_OK -eq 1 ]]; then
|
||||
[[ -d "$SCRIPT_DIR/node_modules" ]] || { echo -e "${RED}[FAIL]${NC} node_modules missing"; HEALTH_ERRORS=$((HEALTH_ERRORS+1)); }
|
||||
[[ -f "$SCRIPT_DIR/packages/ui/dist/index.html" ]] || { echo -e "${YELLOW}[WARN]${NC} UI build missing"; ((WARNINGS++)) || true; }
|
||||
fi
|
||||
|
||||
if [[ $HEALTH_ERRORS -eq 0 ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} Health checks passed"
|
||||
if [[ $HEALTH_OK -eq 1 ]]; then
|
||||
echo -e "${GREEN}[OK]${NC} All checks passed"
|
||||
else
|
||||
ERRORS=$((ERRORS+HEALTH_ERRORS))
|
||||
echo -e "${RED}[ERROR]${NC} Health checks failed"
|
||||
((ERRORS++))
|
||||
fi
|
||||
|
||||
# Summary
|
||||
# ---------------------------------------------------------------
|
||||
# SUMMARY
|
||||
# ---------------------------------------------------------------
|
||||
echo ""
|
||||
echo -e "${CYAN}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${CYAN}║${NC} ${BOLD}INSTALLATION SUMMARY${NC} ${CYAN}║${NC}"
|
||||
echo -e "${CYAN}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo -e "${CYAN}|${NC} INSTALLATION SUMMARY ${CYAN}|${NC}"
|
||||
echo -e "${CYAN}==============================================================${NC}"
|
||||
echo ""
|
||||
echo " Install Directory: $TARGET_DIR"
|
||||
echo " Architecture: $ARCH ($ARCH_TYPE)"
|
||||
echo " macOS Version: $MACOS_VERSION"
|
||||
[[ -n "${NODE_VERSION:-}" ]] && echo " Node.js: $NODE_VERSION"
|
||||
[[ -n "${NPM_VERSION:-}" ]] && echo " npm: $NPM_VERSION"
|
||||
echo " Mode: Binary-Free Mode"
|
||||
echo " Errors: $ERRORS"
|
||||
echo " Warnings: $WARNINGS"
|
||||
echo " Log File: $LOG_FILE"
|
||||
echo " Target: $TARGET_DIR"
|
||||
echo " Mode: Binary-Free Mode"
|
||||
echo " Errors: $ERRORS"
|
||||
echo " Warnings: $WARNINGS"
|
||||
echo ""
|
||||
|
||||
if [[ $ERRORS -gt 0 ]]; then
|
||||
echo -e "${RED}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${RED}║${NC} ${BOLD}INSTALLATION COMPLETED WITH ERRORS${NC} ${RED}║${NC}"
|
||||
echo -e "${RED}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo ""
|
||||
echo "Review the errors above and check: $LOG_FILE"
|
||||
echo ""
|
||||
echo "Common fixes:"
|
||||
echo " 1. Install Homebrew: /bin/bash -c \"\$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)\""
|
||||
echo " 2. Install Node.js: brew install node"
|
||||
echo " 3. Restart terminal after Homebrew installation"
|
||||
echo ""
|
||||
log "Installation FAILED with $ERRORS errors"
|
||||
echo -e "${RED}==============================================================${NC}"
|
||||
echo -e "${RED} INSTALLATION FAILED${NC}"
|
||||
echo -e "${RED}==============================================================${NC}"
|
||||
echo "Check the log file: $LOG_FILE"
|
||||
exit 1
|
||||
else
|
||||
echo -e "${GREEN}╔═══════════════════════════════════════════════════════════════╗${NC}"
|
||||
echo -e "${GREEN}║${NC} ${BOLD}INSTALLATION SUCCESSFUL!${NC} ${GREEN}║${NC}"
|
||||
echo -e "${GREEN}╚═══════════════════════════════════════════════════════════════╝${NC}"
|
||||
echo -e "${GREEN}==============================================================${NC}"
|
||||
echo -e "${GREEN} INSTALLATION SUCCESSFUL!${NC}"
|
||||
echo -e "${GREEN}==============================================================${NC}"
|
||||
echo ""
|
||||
echo "To start NomadArch, run:"
|
||||
echo " ./Launch-Unix.sh"
|
||||
echo -e " ${BOLD}./Launch-Mac.sh${NC}"
|
||||
echo ""
|
||||
echo "Available Free Models:"
|
||||
echo " - GPT-5 Nano (fast)"
|
||||
echo " - Grok Code (coding)"
|
||||
echo " - GLM-4.7 (general)"
|
||||
echo " - Doubao (creative)"
|
||||
echo ""
|
||||
log "Installation SUCCESSFUL"
|
||||
exit 0
|
||||
fi
|
||||
|
||||
exit $ERRORS
|
||||
|
||||
@@ -1,14 +1,16 @@
|
||||
@echo off
|
||||
chcp 65001 >nul 2>&1
|
||||
REM NomadArch Windows Installer - ASCII Safe Version
|
||||
REM This installer uses only ASCII characters for maximum compatibility
|
||||
|
||||
setlocal enabledelayedexpansion
|
||||
|
||||
title NomadArch Installer - Windows
|
||||
|
||||
echo.
|
||||
echo ╔═══════════════════════════════════════════════════════════════╗
|
||||
echo ║ NomadArch Installer for Windows ║
|
||||
echo ║ Version: 0.6.0 - Robust Edition ║
|
||||
echo ╚═══════════════════════════════════════════════════════════════╝
|
||||
echo ===============================================================
|
||||
echo NomadArch Installer for Windows
|
||||
echo Version: 0.6.1 - Universal Edition
|
||||
echo ===============================================================
|
||||
echo.
|
||||
|
||||
set SCRIPT_DIR=%~dp0
|
||||
@@ -25,9 +27,9 @@ set NODE_INSTALLED_NOW=0
|
||||
|
||||
echo [%date% %time%] ========== Installer started ========== >> "%LOG_FILE%"
|
||||
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
REM STEP 1: OS and Architecture Detection
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
echo [STEP 1/8] Detecting System...
|
||||
|
||||
for /f "tokens=2 delims==" %%a in ('wmic os get osarchitecture /value 2^>nul ^| find "="') do set ARCH_RAW=%%a
|
||||
@@ -45,9 +47,9 @@ echo [OK] Windows Version: !WIN_VER!
|
||||
echo [OK] Architecture: !ARCH!
|
||||
echo [%date% %time%] OS: Windows !WIN_VER!, Arch: !ARCH! >> "%LOG_FILE%"
|
||||
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
REM STEP 2: Check Write Permissions
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
echo.
|
||||
echo [STEP 2/8] Checking Write Permissions...
|
||||
|
||||
@@ -72,9 +74,9 @@ if !ERRORLEVEL! neq 0 (
|
||||
)
|
||||
echo [%date% %time%] Install target: %TARGET_DIR% >> "%LOG_FILE%"
|
||||
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
REM STEP 3: Check and Install Node.js
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
echo.
|
||||
echo [STEP 3/8] Checking Node.js...
|
||||
|
||||
@@ -98,7 +100,7 @@ if !NODE_OK! equ 0 (
|
||||
where winget >nul 2>&1
|
||||
if !ERRORLEVEL! equ 0 (
|
||||
echo [INFO] Installing Node.js via winget...
|
||||
winget install -e --id OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements --silent
|
||||
winget install -e --id OpenJS.NodeJS.LTS --accept-source-agreements --accept-package-agreements --silent 2>nul
|
||||
if !ERRORLEVEL! equ 0 (
|
||||
set NODE_INSTALLED_NOW=1
|
||||
echo [OK] Node.js installed via winget
|
||||
@@ -112,7 +114,7 @@ if !NODE_OK! equ 0 (
|
||||
where choco >nul 2>&1
|
||||
if !ERRORLEVEL! equ 0 (
|
||||
echo [INFO] Installing Node.js via Chocolatey...
|
||||
choco install nodejs-lts -y
|
||||
choco install nodejs-lts -y 2>nul
|
||||
if !ERRORLEVEL! equ 0 (
|
||||
set NODE_INSTALLED_NOW=1
|
||||
echo [OK] Node.js installed via Chocolatey
|
||||
@@ -125,17 +127,12 @@ if !NODE_OK! equ 0 (
|
||||
echo [INFO] Downloading Node.js installer directly...
|
||||
set NODE_INSTALLER=%TEMP_DIR%\node-installer.msi
|
||||
|
||||
REM Download using PowerShell
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
|
||||
"$ProgressPreference = 'SilentlyContinue'; " ^
|
||||
"try { " ^
|
||||
" Invoke-WebRequest -Uri 'https://nodejs.org/dist/v20.10.0/node-v20.10.0-x64.msi' -OutFile '%TEMP_DIR%\node-installer.msi' -UseBasicParsing; " ^
|
||||
" exit 0 " ^
|
||||
"} catch { exit 1 }"
|
||||
REM Download using PowerShell with proper error handling
|
||||
powershell -NoProfile -ExecutionPolicy Bypass -Command "$ProgressPreference = 'SilentlyContinue'; try { Invoke-WebRequest -Uri 'https://nodejs.org/dist/v20.10.0/node-v20.10.0-x64.msi' -OutFile '%TEMP_DIR%\node-installer.msi' -UseBasicParsing; exit 0 } catch { exit 1 }" 2>nul
|
||||
|
||||
if exist "%TEMP_DIR%\node-installer.msi" (
|
||||
echo [INFO] Running Node.js installer...
|
||||
msiexec /i "%TEMP_DIR%\node-installer.msi" /qn /norestart
|
||||
msiexec /i "%TEMP_DIR%\node-installer.msi" /qn /norestart 2>nul
|
||||
if !ERRORLEVEL! equ 0 (
|
||||
set NODE_INSTALLED_NOW=1
|
||||
echo [OK] Node.js installed successfully
|
||||
@@ -150,11 +147,11 @@ if !NODE_OK! equ 0 (
|
||||
|
||||
if !NODE_INSTALLED_NOW! equ 1 (
|
||||
echo.
|
||||
echo ╔═══════════════════════════════════════════════════════════════╗
|
||||
echo ║ IMPORTANT: Node.js was just installed! ║
|
||||
echo ║ Please CLOSE this window and run Install-Windows.bat again. ║
|
||||
echo ║ This is required for the PATH to update. ║
|
||||
echo ╚═══════════════════════════════════════════════════════════════╝
|
||||
echo ===============================================================
|
||||
echo IMPORTANT: Node.js was just installed!
|
||||
echo Please CLOSE this window and run Install-Windows.bat again.
|
||||
echo This is required for the PATH to update.
|
||||
echo ===============================================================
|
||||
echo.
|
||||
echo [%date% %time%] Node.js installed, restart required >> "%LOG_FILE%"
|
||||
pause
|
||||
@@ -191,9 +188,9 @@ if !NPM_OK! equ 0 (
|
||||
goto :SUMMARY
|
||||
)
|
||||
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
REM STEP 4: Check Git (optional)
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
echo.
|
||||
echo [STEP 4/8] Checking Git (optional)...
|
||||
|
||||
@@ -206,9 +203,9 @@ if !ERRORLEVEL! equ 0 (
|
||||
set /a WARNINGS+=1
|
||||
)
|
||||
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
REM STEP 5: Install npm Dependencies
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
echo.
|
||||
echo [STEP 5/8] Installing Dependencies...
|
||||
|
||||
@@ -238,26 +235,26 @@ if !ERRORLEVEL! neq 0 (
|
||||
)
|
||||
echo [OK] Dependencies installed
|
||||
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
REM STEP 6: OpenCode Binary (OPTIONAL)
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
echo.
|
||||
echo [STEP 6/8] OpenCode Binary Setup...
|
||||
echo.
|
||||
echo ╔═══════════════════════════════════════════════════════════════╗
|
||||
echo ║ NomadArch supports Binary-Free Mode! ║
|
||||
echo ║ You can skip the OpenCode binary and use free cloud models: ║
|
||||
echo ║ - GPT-5 Nano, Grok Code, GLM-4.7, Doubao, and more ║
|
||||
echo ╚═══════════════════════════════════════════════════════════════╝
|
||||
echo ===============================================================
|
||||
echo NomadArch supports Binary-Free Mode!
|
||||
echo You can skip the OpenCode binary and use free cloud models:
|
||||
echo - GPT-5 Nano, Grok Code, GLM-4.7, Doubao, and more
|
||||
echo ===============================================================
|
||||
echo.
|
||||
|
||||
set SKIP_OPENCODE=1
|
||||
echo [OK] Using Binary-Free Mode (default)
|
||||
echo [%date% %time%] Using Binary-Free Mode >> "%LOG_FILE%"
|
||||
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
REM STEP 7: Build UI Assets
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
echo.
|
||||
echo [STEP 7/8] Building UI Assets...
|
||||
|
||||
@@ -278,9 +275,9 @@ if exist "%SCRIPT_DIR%\packages\ui\dist\index.html" (
|
||||
echo [OK] UI assets built successfully
|
||||
)
|
||||
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
REM STEP 8: Health Check and Summary
|
||||
REM ═══════════════════════════════════════════════════════════════
|
||||
REM ---------------------------------------------------------------
|
||||
echo.
|
||||
echo [STEP 8/8] Running Health Check...
|
||||
|
||||
@@ -320,9 +317,9 @@ if !HEALTH_OK! equ 1 (
|
||||
|
||||
:SUMMARY
|
||||
echo.
|
||||
echo ╔═══════════════════════════════════════════════════════════════╗
|
||||
echo ║ INSTALLATION SUMMARY ║
|
||||
echo ╚═══════════════════════════════════════════════════════════════╝
|
||||
echo ===============================================================
|
||||
echo INSTALLATION SUMMARY
|
||||
echo ===============================================================
|
||||
echo.
|
||||
echo Install Directory: %TARGET_DIR%
|
||||
echo Architecture: !ARCH!
|
||||
@@ -335,9 +332,9 @@ echo Log File: %LOG_FILE%
|
||||
echo.
|
||||
|
||||
if !ERRORS! gtr 0 (
|
||||
echo ╔═══════════════════════════════════════════════════════════════╗
|
||||
echo ║ INSTALLATION FAILED ║
|
||||
echo ╚═══════════════════════════════════════════════════════════════╝
|
||||
echo ===============================================================
|
||||
echo INSTALLATION FAILED
|
||||
echo ===============================================================
|
||||
echo.
|
||||
echo Review the errors above and check the log file: %LOG_FILE%
|
||||
echo.
|
||||
@@ -349,9 +346,9 @@ if !ERRORS! gtr 0 (
|
||||
echo.
|
||||
echo [%date% %time%] Installation FAILED with !ERRORS! errors >> "%LOG_FILE%"
|
||||
) else (
|
||||
echo ╔═══════════════════════════════════════════════════════════════╗
|
||||
echo ║ INSTALLATION SUCCESSFUL! ║
|
||||
echo ╚═══════════════════════════════════════════════════════════════╝
|
||||
echo ===============================================================
|
||||
echo INSTALLATION SUCCESSFUL!
|
||||
echo ===============================================================
|
||||
echo.
|
||||
echo To start NomadArch, run:
|
||||
echo Launch-Windows.bat
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
{
|
||||
"sessions": {
|
||||
"01KDFA3KMG1VSQNA217HZ3JAYA": {
|
||||
"id": "01KDFA3KMG1VSQNA217HZ3JAYA",
|
||||
"workspaceId": "mjnyjm5r",
|
||||
"title": "New Session",
|
||||
"parentId": null,
|
||||
"createdAt": 1766819221136,
|
||||
"updatedAt": 1766819221136,
|
||||
"messageIds": [],
|
||||
"model": {
|
||||
"providerId": "opencode-zen",
|
||||
"modelId": "grok-code"
|
||||
},
|
||||
"agent": "Assistant"
|
||||
},
|
||||
"01KDFA3SP5YJAB7B8BC2EM48NY": {
|
||||
"id": "01KDFA3SP5YJAB7B8BC2EM48NY",
|
||||
"workspaceId": "mjnyjm5r",
|
||||
"title": "New Session",
|
||||
"parentId": null,
|
||||
"createdAt": 1766819227333,
|
||||
"updatedAt": 1766819227333,
|
||||
"messageIds": [],
|
||||
"model": {
|
||||
"providerId": "opencode-zen",
|
||||
"modelId": "grok-code"
|
||||
},
|
||||
"agent": "Assistant"
|
||||
}
|
||||
},
|
||||
"messages": {}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
{
|
||||
"sessions": {
|
||||
"01KDFB53053F09XN5CJ3S7PQWH": {
|
||||
"id": "01KDFB53053F09XN5CJ3S7PQWH",
|
||||
"workspaceId": "mjnz73yi",
|
||||
"title": "New Session",
|
||||
"parentId": null,
|
||||
"createdAt": 1766820318213,
|
||||
"updatedAt": 1766820318213,
|
||||
"messageIds": [],
|
||||
"model": {
|
||||
"providerId": "opencode-zen",
|
||||
"modelId": "grok-code"
|
||||
},
|
||||
"agent": "Assistant"
|
||||
}
|
||||
},
|
||||
"messages": {}
|
||||
}
|
||||
@@ -68,10 +68,23 @@ export function setupCliIPC(mainWindow: BrowserWindow, cliManager: CliProcessMan
|
||||
})
|
||||
ipcMain.handle("users:createGuest", async () => {
|
||||
const user = createGuestUser()
|
||||
// Set up isolated environment for guest user
|
||||
const root = getUserDataRoot(user.id)
|
||||
cliManager.setUserEnv({
|
||||
CODENOMAD_USER_DIR: root,
|
||||
CLI_CONFIG: path.join(root, "config.json"),
|
||||
})
|
||||
await cliManager.stop()
|
||||
const devMode = process.env.NODE_ENV === "development"
|
||||
await cliManager.start({ dev: devMode })
|
||||
// Set as active user
|
||||
setActiveUser(user.id)
|
||||
return user
|
||||
})
|
||||
ipcMain.handle("users:login", async (_, payload: { id: string; password?: string }) => {
|
||||
console.log("[IPC:users:login] Attempting login for:", payload.id, "password length:", payload.password?.length)
|
||||
const ok = verifyPassword(payload.id, payload.password ?? "")
|
||||
console.log("[IPC:users:login] verifyPassword result:", ok)
|
||||
if (!ok) {
|
||||
return { success: false }
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import { fileURLToPath } from "url"
|
||||
import { createApplicationMenu } from "./menu"
|
||||
import { setupCliIPC } from "./ipc"
|
||||
import { CliProcessManager } from "./process-manager"
|
||||
import { ensureDefaultUsers, getActiveUser, getUserDataRoot, clearGuestUsers } from "./user-store"
|
||||
import { ensureDefaultUsers, getActiveUser, getUserDataRoot, clearGuestUsers, logoutActiveUser } from "./user-store"
|
||||
|
||||
const mainFilename = fileURLToPath(import.meta.url)
|
||||
const mainDirname = dirname(mainFilename)
|
||||
@@ -481,6 +481,8 @@ if (isMac) {
|
||||
}
|
||||
|
||||
app.whenReady().then(() => {
|
||||
clearGuestUsers()
|
||||
logoutActiveUser()
|
||||
ensureDefaultUsers()
|
||||
applyUserEnvToCli()
|
||||
startCli()
|
||||
|
||||
@@ -111,19 +111,50 @@ function migrateLegacyData(targetDir: string) {
|
||||
|
||||
export function ensureDefaultUsers(): UserRecord {
|
||||
const store = readStore()
|
||||
if (store.users.length > 0) {
|
||||
const active = store.users.find((u) => u.id === store.activeUserId) ?? store.users[0]
|
||||
if (!store.activeUserId) {
|
||||
store.activeUserId = active.id
|
||||
|
||||
// If roman exists, ensure his password is updated to the new required one if it matches the old default
|
||||
const roman = store.users.find(u => u.name === "roman")
|
||||
if (roman && roman.salt && roman.passwordHash) {
|
||||
const oldDefaultHash = hashPassword("q1w2e3r4", roman.salt)
|
||||
if (roman.passwordHash === oldDefaultHash) {
|
||||
console.log("[UserStore] Updating roman's password to new default")
|
||||
const newSalt = generateSalt()
|
||||
roman.salt = newSalt
|
||||
roman.passwordHash = hashPassword("!@#$q1w2e3r4", newSalt)
|
||||
roman.updatedAt = nowIso()
|
||||
writeStore(store)
|
||||
}
|
||||
|
||||
// NEW: Check if roman needs data migration (e.g. if he was created before migration logic was robust)
|
||||
const userDir = getUserDir(roman.id)
|
||||
const configPath = path.join(userDir, "config.json")
|
||||
let needsMigration = !existsSync(configPath)
|
||||
if (!needsMigration) {
|
||||
try {
|
||||
const config = JSON.parse(readFileSync(configPath, "utf-8"))
|
||||
if (!config.recentFolders || config.recentFolders.length === 0) {
|
||||
needsMigration = true
|
||||
}
|
||||
} catch (e) {
|
||||
needsMigration = true
|
||||
}
|
||||
}
|
||||
|
||||
if (needsMigration) {
|
||||
console.log(`[UserStore] Roman exists but seems to have missing data. Triggering migration to ${userDir}...`)
|
||||
migrateLegacyData(userDir)
|
||||
}
|
||||
}
|
||||
|
||||
if (store.users.length > 0) {
|
||||
const active = store.users.find((u) => u.id === store.activeUserId) ?? store.users[0]
|
||||
return active
|
||||
}
|
||||
|
||||
const existingIds = new Set<string>()
|
||||
const userId = ensureUniqueId("roman", existingIds)
|
||||
const salt = generateSalt()
|
||||
const passwordHash = hashPassword("q1w2e3r4", salt)
|
||||
const passwordHash = hashPassword("!@#$q1w2e3r4", salt)
|
||||
const record: UserRecord = {
|
||||
id: userId,
|
||||
name: "roman",
|
||||
@@ -134,7 +165,6 @@ export function ensureDefaultUsers(): UserRecord {
|
||||
}
|
||||
|
||||
store.users.push(record)
|
||||
store.activeUserId = record.id
|
||||
writeStore(store)
|
||||
|
||||
const userDir = getUserDir(record.id)
|
||||
@@ -153,6 +183,13 @@ export function getActiveUser(): UserRecord | null {
|
||||
return store.users.find((user) => user.id === store.activeUserId) ?? null
|
||||
}
|
||||
|
||||
export function logoutActiveUser() {
|
||||
const store = readStore()
|
||||
store.activeUserId = undefined
|
||||
writeStore(store)
|
||||
console.log("[UserStore] Active user logged out")
|
||||
}
|
||||
|
||||
export function setActiveUser(userId: string) {
|
||||
const store = readStore()
|
||||
const user = store.users.find((u) => u.id === userId)
|
||||
@@ -239,10 +276,20 @@ export function deleteUser(userId: string) {
|
||||
export function verifyPassword(userId: string, password: string): boolean {
|
||||
const store = readStore()
|
||||
const user = store.users.find((u) => u.id === userId)
|
||||
if (!user) return false
|
||||
if (!user) {
|
||||
console.log("[verifyPassword] User not found:", userId)
|
||||
return false
|
||||
}
|
||||
if (user.isGuest) return true
|
||||
if (!user.salt || !user.passwordHash) return false
|
||||
return hashPassword(password, user.salt) === user.passwordHash
|
||||
if (!user.salt || !user.passwordHash) {
|
||||
console.log("[verifyPassword] No salt or hash for user:", userId)
|
||||
return false
|
||||
}
|
||||
const computed = hashPassword(password, user.salt)
|
||||
const matches = computed === user.passwordHash
|
||||
console.log("[verifyPassword] userId:", userId, "password:", JSON.stringify(password), "len:", password.length)
|
||||
console.log("[verifyPassword] computed:", computed, "stored:", user.passwordHash, "matches:", matches)
|
||||
return matches
|
||||
}
|
||||
|
||||
export function getUserDataRoot(userId: string) {
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
import { z } from "zod"
|
||||
import { createHmac } from "crypto"
|
||||
|
||||
export const ZAIConfigSchema = z.object({
|
||||
apiKey: z.string().optional(),
|
||||
endpoint: z.string().default("https://api.z.ai/api/coding/paas/v4"),
|
||||
endpoint: z.string().default("https://api.z.ai/api"),
|
||||
enabled: z.boolean().default(false),
|
||||
timeout: z.number().default(300000)
|
||||
})
|
||||
@@ -142,7 +140,8 @@ export class ZAIClient {
|
||||
|
||||
constructor(config: ZAIConfig) {
|
||||
this.config = config
|
||||
this.baseUrl = config.endpoint.replace(/\/$/, "")
|
||||
const trimmed = config.endpoint.replace(/\/$/, "")
|
||||
this.baseUrl = trimmed.replace(/\/(?:api\/coding\/)?paas\/v4$/, "")
|
||||
}
|
||||
|
||||
async testConnection(): Promise<boolean> {
|
||||
@@ -151,7 +150,7 @@ export class ZAIClient {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
||||
const response = await fetch(`${this.baseUrl}/paas/v4/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: this.getHeaders(),
|
||||
body: JSON.stringify({
|
||||
@@ -182,7 +181,7 @@ export class ZAIClient {
|
||||
throw new Error("Z.AI API key is required")
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
||||
const response = await fetch(`${this.baseUrl}/paas/v4/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: this.getHeaders(),
|
||||
body: JSON.stringify({
|
||||
@@ -236,7 +235,7 @@ export class ZAIClient {
|
||||
throw new Error("Z.AI API key is required")
|
||||
}
|
||||
|
||||
const response = await fetch(`${this.baseUrl}/chat/completions`, {
|
||||
const response = await fetch(`${this.baseUrl}/paas/v4/chat/completions`, {
|
||||
method: "POST",
|
||||
headers: this.getHeaders(),
|
||||
body: JSON.stringify({
|
||||
@@ -254,56 +253,13 @@ export class ZAIClient {
|
||||
}
|
||||
|
||||
private getHeaders(): Record<string, string> {
|
||||
const token = this.generateToken(this.config.apiKey!)
|
||||
return {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": `Bearer ${token}`
|
||||
}
|
||||
}
|
||||
|
||||
private generateToken(apiKey: string, expiresIn: number = 3600): string {
|
||||
try {
|
||||
const [id, secret] = apiKey.split(".")
|
||||
if (!id || !secret) return apiKey // Fallback or handle error
|
||||
|
||||
const now = Date.now()
|
||||
const payload = {
|
||||
api_key: id,
|
||||
exp: now + expiresIn * 1000,
|
||||
timestamp: now
|
||||
}
|
||||
|
||||
const header = {
|
||||
alg: "HS256",
|
||||
sign_type: "SIGN"
|
||||
}
|
||||
|
||||
const base64UrlEncode = (obj: any) => {
|
||||
return Buffer.from(JSON.stringify(obj))
|
||||
.toString('base64')
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=+$/, '')
|
||||
}
|
||||
|
||||
const encodedHeader = base64UrlEncode(header)
|
||||
const encodedPayload = base64UrlEncode(payload)
|
||||
|
||||
const signature = createHmac("sha256", secret)
|
||||
.update(`${encodedHeader}.${encodedPayload}`)
|
||||
.digest("base64")
|
||||
.replace(/\+/g, '-')
|
||||
.replace(/\//g, '_')
|
||||
.replace(/=+$/, '')
|
||||
|
||||
return `${encodedHeader}.${encodedPayload}.${signature}`
|
||||
} catch (e) {
|
||||
console.warn("Failed to generate JWT, using raw key", e)
|
||||
return apiKey
|
||||
"Authorization": `Bearer ${this.config.apiKey!}`
|
||||
}
|
||||
}
|
||||
|
||||
static validateApiKey(apiKey: string): boolean {
|
||||
return typeof apiKey === "string" && apiKey.length > 0
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -661,22 +661,23 @@ async function streamWithZAI(
|
||||
let content = ""
|
||||
const toolCalls: ToolCall[] = []
|
||||
|
||||
const baseUrl = "https://api.z.ai"
|
||||
const baseUrl = "https://api.z.ai/api"
|
||||
|
||||
try {
|
||||
const headers: Record<string, string> = {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
|
||||
if (accessToken) {
|
||||
headers["Authorization"] = `Bearer ${accessToken}`
|
||||
if (!accessToken) {
|
||||
throw new Error("Z.AI API key required. Please authenticate with Z.AI first.")
|
||||
}
|
||||
headers["Authorization"] = `Bearer ${accessToken}`
|
||||
|
||||
const response = await fetch(`${baseUrl}/v1/chat/completions`, {
|
||||
const response = await fetch(`${baseUrl}/paas/v4/chat/completions`, {
|
||||
method: "POST",
|
||||
headers,
|
||||
body: JSON.stringify({
|
||||
model: model ?? "z1-mini",
|
||||
model: model ?? "glm-4.7",
|
||||
messages,
|
||||
stream: true,
|
||||
tools: tools.length > 0 ? tools : undefined,
|
||||
|
||||
@@ -9,10 +9,13 @@ import {
|
||||
import { Logger } from "../../logger"
|
||||
import fs from "fs"
|
||||
import path from "path"
|
||||
import { getUserIntegrationsDir } from "../../user-data"
|
||||
import { getUserIntegrationsDir, getUserIdFromRequest } from "../../user-context"
|
||||
|
||||
const CONFIG_DIR = getUserIntegrationsDir()
|
||||
const CONFIG_FILE = path.join(CONFIG_DIR, "ollama-config.json")
|
||||
// Helper to get config file path for a user
|
||||
function getConfigFile(userId?: string | null): string {
|
||||
const configDir = getUserIntegrationsDir(userId || undefined)
|
||||
return path.join(configDir, "ollama-config.json")
|
||||
}
|
||||
|
||||
interface OllamaRouteDeps {
|
||||
logger: Logger
|
||||
@@ -26,7 +29,8 @@ export async function registerOllamaRoutes(
|
||||
|
||||
app.get('/api/ollama/config', async (request, reply) => {
|
||||
try {
|
||||
const config = getOllamaConfig()
|
||||
const userId = getUserIdFromRequest(request)
|
||||
const config = getOllamaConfig(userId)
|
||||
return { config: { ...config, apiKey: config.apiKey ? '***' : undefined } }
|
||||
} catch (error) {
|
||||
logger.error({ error }, "Failed to get Ollama config")
|
||||
@@ -48,9 +52,10 @@ export async function registerOllamaRoutes(
|
||||
}
|
||||
}, async (request, reply) => {
|
||||
try {
|
||||
const userId = getUserIdFromRequest(request)
|
||||
const { enabled, apiKey, endpoint } = request.body as any
|
||||
updateOllamaConfig({ enabled, apiKey, endpoint })
|
||||
logger.info("Ollama Cloud configuration updated")
|
||||
updateOllamaConfig({ enabled, apiKey, endpoint }, userId)
|
||||
logger.info({ userId }, "Ollama Cloud configuration updated for user")
|
||||
return { success: true, config: { enabled, endpoint, apiKey: apiKey ? '***' : undefined } }
|
||||
} catch (error) {
|
||||
logger.error({ error }, "Failed to update Ollama config")
|
||||
@@ -60,7 +65,8 @@ export async function registerOllamaRoutes(
|
||||
|
||||
app.post('/api/ollama/test', async (request, reply) => {
|
||||
try {
|
||||
const config = getOllamaConfig()
|
||||
const userId = getUserIdFromRequest(request)
|
||||
const config = getOllamaConfig(userId)
|
||||
if (!config.enabled) {
|
||||
return reply.status(400).send({ error: "Ollama Cloud is not enabled" })
|
||||
}
|
||||
@@ -556,24 +562,27 @@ export async function registerOllamaRoutes(
|
||||
logger.info("Ollama Cloud routes registered")
|
||||
}
|
||||
|
||||
function getOllamaConfig(): OllamaCloudConfig {
|
||||
function getOllamaConfig(userId?: string | null): OllamaCloudConfig {
|
||||
const configFile = getConfigFile(userId)
|
||||
try {
|
||||
if (!fs.existsSync(CONFIG_FILE)) {
|
||||
if (!fs.existsSync(configFile)) {
|
||||
return { enabled: false, endpoint: "https://ollama.com" }
|
||||
}
|
||||
const data = fs.readFileSync(CONFIG_FILE, 'utf-8')
|
||||
const data = fs.readFileSync(configFile, 'utf-8')
|
||||
return JSON.parse(data)
|
||||
} catch {
|
||||
return { enabled: false, endpoint: "https://ollama.com" }
|
||||
}
|
||||
}
|
||||
|
||||
function updateOllamaConfig(config: Partial<OllamaCloudConfig>): void {
|
||||
function updateOllamaConfig(config: Partial<OllamaCloudConfig>, userId?: string | null): void {
|
||||
const configFile = getConfigFile(userId)
|
||||
const configDir = getUserIntegrationsDir(userId || undefined)
|
||||
try {
|
||||
if (!fs.existsSync(CONFIG_DIR)) {
|
||||
fs.mkdirSync(CONFIG_DIR, { recursive: true })
|
||||
if (!fs.existsSync(configDir)) {
|
||||
fs.mkdirSync(configDir, { recursive: true })
|
||||
}
|
||||
const current = getOllamaConfig()
|
||||
const current = getOllamaConfig(userId)
|
||||
|
||||
// Only update apiKey if a new non-empty value is provided
|
||||
const updated = {
|
||||
@@ -583,8 +592,8 @@ function updateOllamaConfig(config: Partial<OllamaCloudConfig>): void {
|
||||
apiKey: config.apiKey || current.apiKey
|
||||
}
|
||||
|
||||
fs.writeFileSync(CONFIG_FILE, JSON.stringify(updated, null, 2))
|
||||
console.log(`[Ollama] Config saved: enabled=${updated.enabled}, endpoint=${updated.endpoint}, hasApiKey=${!!updated.apiKey}`)
|
||||
fs.writeFileSync(configFile, JSON.stringify(updated, null, 2))
|
||||
console.log(`[Ollama] Config saved for user ${userId || "default"}: enabled=${updated.enabled}, endpoint=${updated.endpoint}, hasApiKey=${!!updated.apiKey}`)
|
||||
} catch (error) {
|
||||
console.error("Failed to save Ollama config:", error)
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { FastifyInstance } from "fastify"
|
||||
import { FastifyInstance, FastifyRequest } from "fastify"
|
||||
import { ZAIClient, ZAI_MODELS, type ZAIConfig, type ZAIChatRequest, type ZAIMessage } from "../../integrations/zai-api"
|
||||
import { Logger } from "../../logger"
|
||||
import { existsSync, readFileSync, writeFileSync, mkdirSync } from "fs"
|
||||
import { join } from "path"
|
||||
import { getUserIntegrationsDir } from "../../user-data"
|
||||
import { getUserIntegrationsDir, getUserIdFromRequest } from "../../user-context"
|
||||
import { CORE_TOOLS, executeTools, type ToolCall, type ToolResult } from "../../tools/executor"
|
||||
import { getMcpManager } from "../../mcp/client"
|
||||
|
||||
@@ -11,27 +11,27 @@ interface ZAIRouteDeps {
|
||||
logger: Logger
|
||||
}
|
||||
|
||||
const CONFIG_DIR = getUserIntegrationsDir()
|
||||
const CONFIG_FILE = join(CONFIG_DIR, "zai-config.json")
|
||||
|
||||
// Maximum number of tool execution loops to prevent infinite recursion
|
||||
const MAX_TOOL_LOOPS = 10
|
||||
|
||||
// Helper to get config file path for a user
|
||||
function getConfigFile(userId?: string | null): string {
|
||||
const configDir = getUserIntegrationsDir(userId || undefined)
|
||||
return join(configDir, "zai-config.json")
|
||||
}
|
||||
|
||||
export async function registerZAIRoutes(
|
||||
app: FastifyInstance,
|
||||
deps: ZAIRouteDeps
|
||||
) {
|
||||
const logger = deps.logger.child({ component: "zai-routes" })
|
||||
|
||||
// Ensure config directory exists
|
||||
if (!existsSync(CONFIG_DIR)) {
|
||||
mkdirSync(CONFIG_DIR, { recursive: true })
|
||||
}
|
||||
|
||||
// Get Z.AI configuration
|
||||
// Get Z.AI configuration (per-user)
|
||||
app.get('/api/zai/config', async (request, reply) => {
|
||||
try {
|
||||
const config = getZAIConfig()
|
||||
const userId = getUserIdFromRequest(request)
|
||||
const config = getZAIConfig(userId)
|
||||
logger.debug({ userId }, "Getting Z.AI config for user")
|
||||
return { config: { ...config, apiKey: config.apiKey ? '***' : undefined } }
|
||||
} catch (error) {
|
||||
logger.error({ error }, "Failed to get Z.AI config")
|
||||
@@ -39,12 +39,13 @@ export async function registerZAIRoutes(
|
||||
}
|
||||
})
|
||||
|
||||
// Update Z.AI configuration
|
||||
// Update Z.AI configuration (per-user)
|
||||
app.post('/api/zai/config', async (request, reply) => {
|
||||
try {
|
||||
const userId = getUserIdFromRequest(request)
|
||||
const { enabled, apiKey, endpoint } = request.body as Partial<ZAIConfig>
|
||||
updateZAIConfig({ enabled, apiKey, endpoint })
|
||||
logger.info("Z.AI configuration updated")
|
||||
updateZAIConfig({ enabled, apiKey, endpoint }, userId)
|
||||
logger.info({ userId }, "Z.AI configuration updated for user")
|
||||
return { success: true, config: { enabled, endpoint, apiKey: apiKey ? '***' : undefined } }
|
||||
} catch (error) {
|
||||
logger.error({ error }, "Failed to update Z.AI config")
|
||||
@@ -52,10 +53,11 @@ export async function registerZAIRoutes(
|
||||
}
|
||||
})
|
||||
|
||||
// Test Z.AI connection
|
||||
// Test Z.AI connection (per-user)
|
||||
app.post('/api/zai/test', async (request, reply) => {
|
||||
try {
|
||||
const config = getZAIConfig()
|
||||
const userId = getUserIdFromRequest(request)
|
||||
const config = getZAIConfig(userId)
|
||||
if (!config.enabled) {
|
||||
return reply.status(400).send({ error: "Z.AI is not enabled" })
|
||||
}
|
||||
@@ -80,10 +82,11 @@ export async function registerZAIRoutes(
|
||||
}
|
||||
})
|
||||
|
||||
// Chat completion endpoint WITH MCP TOOL SUPPORT
|
||||
// Chat completion endpoint WITH MCP TOOL SUPPORT (per-user)
|
||||
app.post('/api/zai/chat', async (request, reply) => {
|
||||
try {
|
||||
const config = getZAIConfig()
|
||||
const userId = getUserIdFromRequest(request)
|
||||
const config = getZAIConfig(userId)
|
||||
if (!config.enabled) {
|
||||
return reply.status(400).send({ error: "Z.AI is not enabled" })
|
||||
}
|
||||
@@ -348,20 +351,48 @@ async function chatWithToolLoop(
|
||||
return lastResponse
|
||||
}
|
||||
|
||||
function getZAIConfig(): ZAIConfig {
|
||||
function getZAIConfig(userId?: string | null): ZAIConfig {
|
||||
const configFile = getConfigFile(userId)
|
||||
try {
|
||||
if (existsSync(CONFIG_FILE)) {
|
||||
const data = readFileSync(CONFIG_FILE, 'utf-8')
|
||||
return JSON.parse(data)
|
||||
console.log(`[Z.AI] Looking for config at: ${configFile} (user: ${userId || "default"})`)
|
||||
if (existsSync(configFile)) {
|
||||
const data = readFileSync(configFile, 'utf-8')
|
||||
const parsed = JSON.parse(data)
|
||||
console.log(`[Z.AI] Config loaded from file, enabled: ${parsed.enabled}`)
|
||||
return parsed
|
||||
}
|
||||
console.log(`[Z.AI] Config file not found, using defaults`)
|
||||
return { enabled: false, endpoint: "https://api.z.ai/api/coding/paas/v4", timeout: 300000 }
|
||||
} catch {
|
||||
} catch (error) {
|
||||
console.error(`[Z.AI] Error reading config:`, error)
|
||||
return { enabled: false, endpoint: "https://api.z.ai/api/coding/paas/v4", timeout: 300000 }
|
||||
}
|
||||
}
|
||||
|
||||
function updateZAIConfig(config: Partial<ZAIConfig>): void {
|
||||
const current = getZAIConfig()
|
||||
function updateZAIConfig(config: Partial<ZAIConfig>, userId?: string | null): void {
|
||||
const configFile = getConfigFile(userId)
|
||||
const configDir = getUserIntegrationsDir(userId || undefined)
|
||||
|
||||
// Ensure directory exists with proper error handling
|
||||
try {
|
||||
if (!existsSync(configDir)) {
|
||||
console.log(`[Z.AI] Creating config directory: ${configDir}`)
|
||||
mkdirSync(configDir, { recursive: true })
|
||||
}
|
||||
} catch (mkdirError) {
|
||||
console.error(`[Z.AI] Failed to create config directory:`, mkdirError)
|
||||
throw new Error(`Failed to create config directory: ${mkdirError}`)
|
||||
}
|
||||
|
||||
const current = getZAIConfig(userId)
|
||||
const updated = { ...current, ...config }
|
||||
writeFileSync(CONFIG_FILE, JSON.stringify(updated, null, 2))
|
||||
|
||||
try {
|
||||
console.log(`[Z.AI] Writing config to: ${configFile} (user: ${userId || "default"})`)
|
||||
writeFileSync(configFile, JSON.stringify(updated, null, 2), 'utf-8')
|
||||
console.log(`[Z.AI] Config saved successfully`)
|
||||
} catch (writeError) {
|
||||
console.error(`[Z.AI] Failed to write config file:`, writeError)
|
||||
throw new Error(`Failed to write config file: ${writeError}`)
|
||||
}
|
||||
}
|
||||
|
||||
101
packages/server/src/user-context.ts
Normal file
101
packages/server/src/user-context.ts
Normal file
@@ -0,0 +1,101 @@
|
||||
/**
|
||||
* User Context Module
|
||||
* Manages the active user context for per-user config isolation
|
||||
*/
|
||||
|
||||
import path from "path"
|
||||
import os from "os"
|
||||
import { existsSync, mkdirSync } from "fs"
|
||||
|
||||
const CONFIG_ROOT = path.join(os.homedir(), ".config", "codenomad")
|
||||
const USERS_ROOT = path.join(CONFIG_ROOT, "users")
|
||||
|
||||
// Active user ID (set by the main process or HTTP header)
|
||||
let activeUserId: string | null = null
|
||||
|
||||
/**
|
||||
* Set the active user ID
|
||||
*/
|
||||
export function setActiveUserId(userId: string | null): void {
|
||||
activeUserId = userId
|
||||
console.log(`[UserContext] Active user set to: ${userId || "(none)"}`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active user ID
|
||||
*/
|
||||
export function getActiveUserId(): string | null {
|
||||
return activeUserId
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the data root for a specific user
|
||||
* Falls back to global config if no user is set
|
||||
*/
|
||||
export function getUserDataRoot(userId?: string): string {
|
||||
const effectiveUserId = userId || activeUserId
|
||||
|
||||
if (effectiveUserId) {
|
||||
const userDir = path.join(USERS_ROOT, effectiveUserId)
|
||||
return userDir
|
||||
}
|
||||
|
||||
// Prioritize environment variable if set (from Electron)
|
||||
const override = process.env.CODENOMAD_USER_DIR
|
||||
if (override && override.trim().length > 0) {
|
||||
return path.resolve(override)
|
||||
}
|
||||
|
||||
// Fallback to global config root
|
||||
return CONFIG_ROOT
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the integrations directory for the current or specified user
|
||||
*/
|
||||
export function getUserIntegrationsDir(userId?: string): string {
|
||||
const userRoot = getUserDataRoot(userId)
|
||||
const integrationsDir = path.join(userRoot, "integrations")
|
||||
|
||||
// Ensure directory exists
|
||||
if (!existsSync(integrationsDir)) {
|
||||
try {
|
||||
mkdirSync(integrationsDir, { recursive: true })
|
||||
console.log(`[UserContext] Created integrations dir: ${integrationsDir}`)
|
||||
} catch (e) {
|
||||
console.error(`[UserContext] Failed to create integrations dir:`, e)
|
||||
}
|
||||
}
|
||||
|
||||
return integrationsDir
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the instances directory for the current or specified user
|
||||
*/
|
||||
export function getUserInstancesDir(userId?: string): string {
|
||||
const userRoot = getUserDataRoot(userId)
|
||||
return path.join(userRoot, "instances")
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the config file path for a specific integration
|
||||
*/
|
||||
export function getIntegrationConfigPath(integrationId: string, userId?: string): string {
|
||||
const integrationsDir = getUserIntegrationsDir(userId)
|
||||
return path.join(integrationsDir, `${integrationId}-config.json`)
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract user ID from request headers
|
||||
*/
|
||||
export function getUserIdFromRequest(request: { headers?: Record<string, string | string[] | undefined> }): string | null {
|
||||
const header = request.headers?.["x-user-id"]
|
||||
if (typeof header === "string" && header.length > 0) {
|
||||
return header
|
||||
}
|
||||
if (Array.isArray(header) && header.length > 0) {
|
||||
return header[0]
|
||||
}
|
||||
return activeUserId
|
||||
}
|
||||
@@ -1,14 +1,8 @@
|
||||
import os from "os"
|
||||
import { getUserDataRoot as getRoot, getUserInstancesDir as getInstances, getUserIntegrationsDir as getIntegrations } from "./user-context"
|
||||
import path from "path"
|
||||
|
||||
const DEFAULT_ROOT = path.join(os.homedir(), ".config", "codenomad")
|
||||
|
||||
export function getUserDataRoot(): string {
|
||||
const override = process.env.CODENOMAD_USER_DIR
|
||||
if (override && override.trim().length > 0) {
|
||||
return path.resolve(override)
|
||||
}
|
||||
return DEFAULT_ROOT
|
||||
return getRoot()
|
||||
}
|
||||
|
||||
export function getUserConfigPath(): string {
|
||||
@@ -16,11 +10,11 @@ export function getUserConfigPath(): string {
|
||||
}
|
||||
|
||||
export function getUserInstancesDir(): string {
|
||||
return path.join(getUserDataRoot(), "instances")
|
||||
return getInstances()
|
||||
}
|
||||
|
||||
export function getUserIntegrationsDir(): string {
|
||||
return path.join(getUserDataRoot(), "integrations")
|
||||
return getIntegrations()
|
||||
}
|
||||
|
||||
export function getOpencodeWorkspacesRoot(): string {
|
||||
|
||||
@@ -470,15 +470,6 @@ const App: Component = () => {
|
||||
<RemoteAccessOverlay open={remoteAccessOpen()} onClose={() => setRemoteAccessOpen(false)} />
|
||||
|
||||
<AlertDialog />
|
||||
|
||||
<Toaster
|
||||
position="top-right"
|
||||
gutter={16}
|
||||
toastOptions={{
|
||||
duration: 8000,
|
||||
className: "bg-transparent border-none shadow-none p-0",
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
|
||||
@@ -7,6 +7,7 @@ import QwenCodeSettings from "./settings/QwenCodeSettings"
|
||||
import ZAISettings from "./settings/ZAISettings"
|
||||
import OpenCodeZenSettings from "./settings/OpenCodeZenSettings"
|
||||
import AntigravitySettings from "./settings/AntigravitySettings"
|
||||
import ApiStatusChecker from "./settings/ApiStatusChecker"
|
||||
|
||||
interface AdvancedSettingsModalProps {
|
||||
open: boolean
|
||||
@@ -17,7 +18,7 @@ interface AdvancedSettingsModalProps {
|
||||
}
|
||||
|
||||
const AdvancedSettingsModal: Component<AdvancedSettingsModalProps> = (props) => {
|
||||
const [activeTab, setActiveTab] = createSignal("general")
|
||||
const [activeTab, setActiveTab] = createSignal("api-status")
|
||||
|
||||
return (
|
||||
<Dialog open={props.open} onOpenChange={(open) => !open && props.onClose()}>
|
||||
@@ -31,6 +32,15 @@ const AdvancedSettingsModal: Component<AdvancedSettingsModalProps> = (props) =>
|
||||
|
||||
<div class="border-b" style={{ "border-color": "var(--border-base)" }}>
|
||||
<div class="flex w-full px-6 overflow-x-auto">
|
||||
<button
|
||||
class={`px-4 py-2 text-sm font-medium border-b-2 whitespace-nowrap ${activeTab() === "api-status"
|
||||
? "border-green-500 text-green-400"
|
||||
: "border-transparent hover:border-gray-300"
|
||||
}`}
|
||||
onClick={() => setActiveTab("api-status")}
|
||||
>
|
||||
📊 API Status
|
||||
</button>
|
||||
<button
|
||||
class={`px-4 py-2 text-sm font-medium border-b-2 whitespace-nowrap ${activeTab() === "zen"
|
||||
? "border-orange-500 text-orange-400"
|
||||
@@ -89,6 +99,20 @@ const AdvancedSettingsModal: Component<AdvancedSettingsModalProps> = (props) =>
|
||||
</div>
|
||||
|
||||
<div class="flex-1 overflow-y-auto">
|
||||
<Show when={activeTab() === "api-status"}>
|
||||
<div class="p-6">
|
||||
<ApiStatusChecker
|
||||
onSettingsClick={(apiId) => {
|
||||
if (apiId === "opencode-zen") setActiveTab("zen")
|
||||
else if (apiId === "ollama-cloud") setActiveTab("ollama")
|
||||
else if (apiId === "zai") setActiveTab("zai")
|
||||
else if (apiId === "qwen-oauth") setActiveTab("qwen")
|
||||
else if (apiId === "antigravity") setActiveTab("antigravity")
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
<Show when={activeTab() === "zen"}>
|
||||
<OpenCodeZenSettings />
|
||||
</Show>
|
||||
|
||||
528
packages/ui/src/components/auth/LoginView.tsx
Normal file
528
packages/ui/src/components/auth/LoginView.tsx
Normal file
@@ -0,0 +1,528 @@
|
||||
import { Component, createSignal, onMount, For, Show } from "solid-js"
|
||||
import { Lock, User, ShieldCheck, Cpu, UserPlus, KeyRound, ArrowLeft, Ghost } from "lucide-solid"
|
||||
import toast from "solid-toast"
|
||||
import { isElectronHost } from "../../lib/runtime-env"
|
||||
import { setActiveUserId } from "../../lib/user-context"
|
||||
|
||||
interface UserRecord {
|
||||
id: string
|
||||
name: string
|
||||
isGuest?: boolean
|
||||
}
|
||||
|
||||
interface LoginViewProps {
|
||||
onLoginSuccess: (user: UserRecord) => void
|
||||
}
|
||||
|
||||
type ViewMode = "login" | "register" | "reset"
|
||||
|
||||
const LoginView: Component<LoginViewProps> = (props) => {
|
||||
const [users, setUsers] = createSignal<UserRecord[]>([])
|
||||
const [username, setUsername] = createSignal("")
|
||||
const [password, setPassword] = createSignal("")
|
||||
const [confirmPassword, setConfirmPassword] = createSignal("")
|
||||
const [newPassword, setNewPassword] = createSignal("")
|
||||
const [isLoading, setIsLoading] = createSignal(false)
|
||||
const [mode, setMode] = createSignal<ViewMode>("login")
|
||||
|
||||
const getApi = () => {
|
||||
const api = (window as any).electronAPI
|
||||
return api
|
||||
}
|
||||
|
||||
const loadUsers = async () => {
|
||||
try {
|
||||
if (isElectronHost()) {
|
||||
const api = getApi()
|
||||
if (api?.listUsers) {
|
||||
const userList = await api.listUsers()
|
||||
if (userList && Array.isArray(userList)) {
|
||||
setUsers(userList)
|
||||
if (userList.length > 0 && !username()) {
|
||||
setUsername(userList[0].name)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch users:", error)
|
||||
}
|
||||
}
|
||||
|
||||
onMount(loadUsers)
|
||||
|
||||
const resetForm = () => {
|
||||
setPassword("")
|
||||
setConfirmPassword("")
|
||||
setNewPassword("")
|
||||
}
|
||||
|
||||
const handleLogin = async (e: Event) => {
|
||||
e.preventDefault()
|
||||
const name = username().trim()
|
||||
if (!name) {
|
||||
toast.error("Identity required")
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
try {
|
||||
if (isElectronHost()) {
|
||||
const api = getApi()
|
||||
if (!api?.listUsers || !api?.loginUser) {
|
||||
toast.error("API bridge not ready")
|
||||
return
|
||||
}
|
||||
|
||||
const userList = await api.listUsers()
|
||||
const user = userList?.find((u: UserRecord) => u.name.toLowerCase() === name.toLowerCase())
|
||||
|
||||
if (!user) {
|
||||
toast.error(`Identity "${name}" not found`)
|
||||
return
|
||||
}
|
||||
|
||||
const result = await api.loginUser({
|
||||
id: user.id,
|
||||
password: password(),
|
||||
})
|
||||
|
||||
if (result?.success) {
|
||||
toast.success(`Welcome back, ${result.user.name}!`)
|
||||
setActiveUserId(result.user.id)
|
||||
props.onLoginSuccess(result.user)
|
||||
} else {
|
||||
toast.error("Invalid access key")
|
||||
}
|
||||
} else {
|
||||
toast.success("Web mode access granted")
|
||||
props.onLoginSuccess({ id: "web-user", name: username() || "Web Explorer" })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Login failed:", error)
|
||||
toast.error("Authentication failed")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleGuestLogin = async () => {
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const api = getApi()
|
||||
if (api?.createGuest) {
|
||||
const guestUser = await api.createGuest()
|
||||
if (guestUser?.id) {
|
||||
toast.success(`Welcome, ${guestUser.name}!`)
|
||||
setActiveUserId(guestUser.id)
|
||||
props.onLoginSuccess(guestUser)
|
||||
} else {
|
||||
toast.error("Failed to create guest session")
|
||||
}
|
||||
} else {
|
||||
// Web mode fallback
|
||||
const guestId = `guest-${Date.now()}`
|
||||
toast.success("Guest session started")
|
||||
props.onLoginSuccess({ id: guestId, name: "Guest", isGuest: true })
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Guest login failed:", error)
|
||||
toast.error("Guest login failed")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleRegister = async (e: Event) => {
|
||||
e.preventDefault()
|
||||
const name = username().trim()
|
||||
|
||||
if (!name) {
|
||||
toast.error("Username required")
|
||||
return
|
||||
}
|
||||
if (name.length < 3) {
|
||||
toast.error("Username must be at least 3 characters")
|
||||
return
|
||||
}
|
||||
if (!password()) {
|
||||
toast.error("Password required")
|
||||
return
|
||||
}
|
||||
if (password().length < 4) {
|
||||
toast.error("Password must be at least 4 characters")
|
||||
return
|
||||
}
|
||||
if (password() !== confirmPassword()) {
|
||||
toast.error("Passwords do not match")
|
||||
return
|
||||
}
|
||||
|
||||
// Check if user already exists
|
||||
const existingUser = users().find(u => u.name.toLowerCase() === name.toLowerCase())
|
||||
if (existingUser) {
|
||||
toast.error(`Identity "${name}" already exists`)
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const api = getApi()
|
||||
if (!api?.createUser) {
|
||||
toast.error("Registration unavailable")
|
||||
return
|
||||
}
|
||||
|
||||
const newUser = await api.createUser({
|
||||
name: name,
|
||||
password: password(),
|
||||
})
|
||||
|
||||
if (newUser?.id) {
|
||||
toast.success(`Identity "${name}" created successfully!`)
|
||||
await loadUsers()
|
||||
setMode("login")
|
||||
setUsername(name)
|
||||
resetForm()
|
||||
} else {
|
||||
toast.error("Failed to create identity")
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Registration failed:", error)
|
||||
toast.error("Registration failed")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const handleResetPassword = async (e: Event) => {
|
||||
e.preventDefault()
|
||||
const name = username().trim()
|
||||
|
||||
if (!name) {
|
||||
toast.error("Select an identity first")
|
||||
return
|
||||
}
|
||||
if (!password()) {
|
||||
toast.error("Current password required")
|
||||
return
|
||||
}
|
||||
if (!newPassword()) {
|
||||
toast.error("New password required")
|
||||
return
|
||||
}
|
||||
if (newPassword().length < 4) {
|
||||
toast.error("New password must be at least 4 characters")
|
||||
return
|
||||
}
|
||||
|
||||
const user = users().find(u => u.name.toLowerCase() === name.toLowerCase())
|
||||
if (!user) {
|
||||
toast.error(`Identity "${name}" not found`)
|
||||
return
|
||||
}
|
||||
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const api = getApi()
|
||||
|
||||
// First verify current password
|
||||
const verifyResult = await api.loginUser({
|
||||
id: user.id,
|
||||
password: password(),
|
||||
})
|
||||
|
||||
if (!verifyResult?.success) {
|
||||
toast.error("Current password is incorrect")
|
||||
return
|
||||
}
|
||||
|
||||
// Update password
|
||||
const updateResult = await api.updateUser({
|
||||
id: user.id,
|
||||
password: newPassword(),
|
||||
})
|
||||
|
||||
if (updateResult?.id) {
|
||||
toast.success("Password updated successfully!")
|
||||
setMode("login")
|
||||
resetForm()
|
||||
} else {
|
||||
toast.error("Failed to update password")
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Password reset failed:", error)
|
||||
toast.error("Password reset failed")
|
||||
} finally {
|
||||
setIsLoading(false)
|
||||
}
|
||||
}
|
||||
|
||||
const switchMode = (newMode: ViewMode) => {
|
||||
setMode(newMode)
|
||||
resetForm()
|
||||
if (newMode === "register") {
|
||||
setUsername("")
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="fixed inset-0 z-[9999] flex items-center justify-center bg-[#0a0a0a]">
|
||||
{/* Dynamic Background */}
|
||||
<div class="absolute inset-0 overflow-hidden pointer-events-none opacity-20">
|
||||
<div class="absolute -top-[10%] -left-[10%] w-[40%] h-[40%] bg-blue-500/20 blur-[120px] rounded-full animate-pulse" />
|
||||
<div class="absolute -bottom-[10%] -right-[10%] w-[40%] h-[40%] bg-purple-500/20 blur-[120px] rounded-full animate-pulse delay-700" />
|
||||
</div>
|
||||
|
||||
<div class="relative w-full max-w-md px-6 py-10 bg-[#141414]/80 backdrop-blur-xl border border-white/10 rounded-3xl shadow-2xl">
|
||||
{/* Logo & Header */}
|
||||
<div class="flex flex-col items-center mb-8">
|
||||
<div class="w-16 h-16 mb-4 bg-gradient-to-br from-blue-500 via-indigo-600 to-purple-700 p-0.5 rounded-2xl shadow-lg transform rotate-3">
|
||||
<div class="w-full h-full bg-[#141414] rounded-2xl flex items-center justify-center">
|
||||
<Cpu class="w-8 h-8 text-white" />
|
||||
</div>
|
||||
</div>
|
||||
<h1 class="text-2xl font-bold text-white tracking-tight mb-1">NomadArch</h1>
|
||||
<p class="text-gray-400 text-sm">
|
||||
{mode() === "login" && "Secure Neural Access Point"}
|
||||
{mode() === "register" && "Create New Identity"}
|
||||
{mode() === "reset" && "Reset Access Key"}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
{/* Back button for non-login modes */}
|
||||
<Show when={mode() !== "login"}>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => switchMode("login")}
|
||||
class="flex items-center gap-2 text-gray-400 hover:text-white transition-colors mb-4"
|
||||
>
|
||||
<ArrowLeft class="w-4 h-4" />
|
||||
<span class="text-sm">Back to login</span>
|
||||
</button>
|
||||
</Show>
|
||||
|
||||
{/* Login Form */}
|
||||
<Show when={mode() === "login"}>
|
||||
<form onSubmit={handleLogin} class="space-y-5">
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wider ml-1">Identity</label>
|
||||
<div class="relative group">
|
||||
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||
<User class="w-5 h-5 text-gray-500 group-focus-within:text-blue-500 transition-colors" />
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
value={username()}
|
||||
onInput={(e) => setUsername(e.currentTarget.value)}
|
||||
class="block w-full pl-12 pr-4 py-3.5 bg-[#1a1a1a] border border-white/5 rounded-2xl text-white focus:outline-none focus:ring-2 focus:ring-blue-500/50 transition-all"
|
||||
list="identity-suggestions"
|
||||
/>
|
||||
<datalist id="identity-suggestions">
|
||||
<For each={users()}>{(user) => <option value={user.name} />}</For>
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wider ml-1">Access Key</label>
|
||||
<div class="relative group">
|
||||
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||
<Lock class="w-5 h-5 text-gray-500 group-focus-within:text-blue-500 transition-colors" />
|
||||
</div>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
value={password()}
|
||||
onInput={(e) => setPassword(e.currentTarget.value)}
|
||||
class="block w-full pl-12 pr-4 py-3.5 bg-[#1a1a1a] border border-white/5 rounded-2xl text-white placeholder-gray-600 focus:outline-none focus:ring-2 focus:ring-blue-500/50 transition-all font-mono"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading() || !username()}
|
||||
class="w-full flex items-center justify-center gap-3 py-3.5 bg-gradient-to-r from-blue-600 via-indigo-600 to-purple-600 hover:from-blue-500 hover:to-purple-500 text-white font-bold rounded-2xl shadow-xl transform active:scale-[0.98] transition-all disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<Show when={isLoading()} fallback={<><ShieldCheck class="w-5 h-5" /><span>Verify Identity</span></>}>
|
||||
<div class="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" />
|
||||
<span>Verifying...</span>
|
||||
</Show>
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="mt-6 flex flex-col gap-4">
|
||||
<button
|
||||
type="button"
|
||||
onClick={handleGuestLogin}
|
||||
disabled={isLoading()}
|
||||
class="w-full flex items-center justify-center gap-2 py-3 bg-[#1a1a1a] hover:bg-[#252525] border border-white/10 text-gray-300 hover:text-white font-medium rounded-2xl transition-all disabled:opacity-50"
|
||||
>
|
||||
<Ghost class="w-5 h-5" />
|
||||
<span>Continue as Guest</span>
|
||||
</button>
|
||||
|
||||
<div class="flex items-center justify-between text-sm">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => switchMode("register")}
|
||||
class="flex items-center gap-1.5 text-gray-400 hover:text-blue-400 transition-colors"
|
||||
>
|
||||
<UserPlus class="w-4 h-4" />
|
||||
<span>Create Identity</span>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => switchMode("reset")}
|
||||
class="flex items-center gap-1.5 text-gray-400 hover:text-purple-400 transition-colors"
|
||||
>
|
||||
<KeyRound class="w-4 h-4" />
|
||||
<span>Reset Password</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</Show>
|
||||
|
||||
{/* Register Form */}
|
||||
<Show when={mode() === "register"}>
|
||||
<form onSubmit={handleRegister} class="space-y-5">
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wider ml-1">Choose Username</label>
|
||||
<div class="relative group">
|
||||
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||
<User class="w-5 h-5 text-gray-500 group-focus-within:text-green-500 transition-colors" />
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Enter username"
|
||||
value={username()}
|
||||
onInput={(e) => setUsername(e.currentTarget.value)}
|
||||
class="block w-full pl-12 pr-4 py-3.5 bg-[#1a1a1a] border border-white/5 rounded-2xl text-white focus:outline-none focus:ring-2 focus:ring-green-500/50 transition-all"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wider ml-1">Choose Password</label>
|
||||
<div class="relative group">
|
||||
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||
<Lock class="w-5 h-5 text-gray-500 group-focus-within:text-green-500 transition-colors" />
|
||||
</div>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Enter password"
|
||||
value={password()}
|
||||
onInput={(e) => setPassword(e.currentTarget.value)}
|
||||
class="block w-full pl-12 pr-4 py-3.5 bg-[#1a1a1a] border border-white/5 rounded-2xl text-white placeholder-gray-600 focus:outline-none focus:ring-2 focus:ring-green-500/50 transition-all font-mono"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wider ml-1">Confirm Password</label>
|
||||
<div class="relative group">
|
||||
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||
<Lock class="w-5 h-5 text-gray-500 group-focus-within:text-green-500 transition-colors" />
|
||||
</div>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Confirm password"
|
||||
value={confirmPassword()}
|
||||
onInput={(e) => setConfirmPassword(e.currentTarget.value)}
|
||||
class="block w-full pl-12 pr-4 py-3.5 bg-[#1a1a1a] border border-white/5 rounded-2xl text-white placeholder-gray-600 focus:outline-none focus:ring-2 focus:ring-green-500/50 transition-all font-mono"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading() || !username() || !password() || !confirmPassword()}
|
||||
class="w-full flex items-center justify-center gap-3 py-3.5 bg-gradient-to-r from-green-600 via-emerald-600 to-teal-600 hover:from-green-500 hover:to-teal-500 text-white font-bold rounded-2xl shadow-xl transform active:scale-[0.98] transition-all disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<Show when={isLoading()} fallback={<><UserPlus class="w-5 h-5" /><span>Create Identity</span></>}>
|
||||
<div class="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" />
|
||||
<span>Creating...</span>
|
||||
</Show>
|
||||
</button>
|
||||
</form>
|
||||
</Show>
|
||||
|
||||
{/* Reset Password Form */}
|
||||
<Show when={mode() === "reset"}>
|
||||
<form onSubmit={handleResetPassword} class="space-y-5">
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wider ml-1">Identity</label>
|
||||
<div class="relative group">
|
||||
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||
<User class="w-5 h-5 text-gray-500 group-focus-within:text-purple-500 transition-colors" />
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Username"
|
||||
value={username()}
|
||||
onInput={(e) => setUsername(e.currentTarget.value)}
|
||||
class="block w-full pl-12 pr-4 py-3.5 bg-[#1a1a1a] border border-white/5 rounded-2xl text-white focus:outline-none focus:ring-2 focus:ring-purple-500/50 transition-all"
|
||||
list="identity-suggestions-reset"
|
||||
/>
|
||||
<datalist id="identity-suggestions-reset">
|
||||
<For each={users()}>{(user) => <option value={user.name} />}</For>
|
||||
</datalist>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wider ml-1">Current Password</label>
|
||||
<div class="relative group">
|
||||
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||
<Lock class="w-5 h-5 text-gray-500 group-focus-within:text-purple-500 transition-colors" />
|
||||
</div>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Enter current password"
|
||||
value={password()}
|
||||
onInput={(e) => setPassword(e.currentTarget.value)}
|
||||
class="block w-full pl-12 pr-4 py-3.5 bg-[#1a1a1a] border border-white/5 rounded-2xl text-white placeholder-gray-600 focus:outline-none focus:ring-2 focus:ring-purple-500/50 transition-all font-mono"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="space-y-1.5">
|
||||
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wider ml-1">New Password</label>
|
||||
<div class="relative group">
|
||||
<div class="absolute inset-y-0 left-0 pl-4 flex items-center pointer-events-none">
|
||||
<KeyRound class="w-5 h-5 text-gray-500 group-focus-within:text-purple-500 transition-colors" />
|
||||
</div>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Enter new password"
|
||||
value={newPassword()}
|
||||
onInput={(e) => setNewPassword(e.currentTarget.value)}
|
||||
class="block w-full pl-12 pr-4 py-3.5 bg-[#1a1a1a] border border-white/5 rounded-2xl text-white placeholder-gray-600 focus:outline-none focus:ring-2 focus:ring-purple-500/50 transition-all font-mono"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="submit"
|
||||
disabled={isLoading() || !username() || !password() || !newPassword()}
|
||||
class="w-full flex items-center justify-center gap-3 py-3.5 bg-gradient-to-r from-purple-600 via-violet-600 to-fuchsia-600 hover:from-purple-500 hover:to-fuchsia-500 text-white font-bold rounded-2xl shadow-xl transform active:scale-[0.98] transition-all disabled:opacity-50 disabled:cursor-not-allowed"
|
||||
>
|
||||
<Show when={isLoading()} fallback={<><KeyRound class="w-5 h-5" /><span>Reset Password</span></>}>
|
||||
<div class="w-5 h-5 border-2 border-white/30 border-t-white rounded-full animate-spin" />
|
||||
<span>Resetting...</span>
|
||||
</Show>
|
||||
</button>
|
||||
</form>
|
||||
</Show>
|
||||
|
||||
<div class="mt-6 text-center text-xs text-gray-600">
|
||||
Powered by Antigravity OS v4.5 | Encrypted Connection
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default LoginView
|
||||
319
packages/ui/src/components/settings/ApiStatusChecker.tsx
Normal file
319
packages/ui/src/components/settings/ApiStatusChecker.tsx
Normal file
@@ -0,0 +1,319 @@
|
||||
import { Component, createSignal, onMount, For, Show, createEffect, on } from "solid-js"
|
||||
import { CheckCircle, XCircle, Loader, RefreshCw, Settings, AlertTriangle } from "lucide-solid"
|
||||
import { userFetch } from "../../lib/user-context"
|
||||
|
||||
interface ApiStatus {
|
||||
id: string
|
||||
name: string
|
||||
icon: string
|
||||
enabled: boolean
|
||||
connected: boolean
|
||||
checking: boolean
|
||||
error?: string
|
||||
lastChecked?: number
|
||||
}
|
||||
|
||||
interface ApiStatusCheck {
|
||||
id: string
|
||||
name: string
|
||||
icon: string
|
||||
checkEnabled: () => Promise<boolean>
|
||||
testConnection: () => Promise<boolean>
|
||||
}
|
||||
|
||||
const API_CHECKS: ApiStatusCheck[] = [
|
||||
{
|
||||
id: "opencode-zen",
|
||||
name: "OpenCode Zen",
|
||||
icon: "🆓",
|
||||
checkEnabled: async () => true, // Always available
|
||||
testConnection: async () => {
|
||||
try {
|
||||
const res = await userFetch("/api/opencode-zen/test")
|
||||
if (!res.ok) return false
|
||||
const data = await res.json()
|
||||
return data.connected === true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "ollama-cloud",
|
||||
name: "Ollama Cloud",
|
||||
icon: "🦙",
|
||||
checkEnabled: async () => {
|
||||
try {
|
||||
const res = await userFetch("/api/ollama/config")
|
||||
if (!res.ok) return false
|
||||
const data = await res.json()
|
||||
return data.config?.enabled === true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
testConnection: async () => {
|
||||
try {
|
||||
const res = await userFetch("/api/ollama/test", { method: "POST" })
|
||||
if (!res.ok) return false
|
||||
const data = await res.json()
|
||||
return data.connected === true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "zai",
|
||||
name: "Z.AI Plan",
|
||||
icon: "🧠",
|
||||
checkEnabled: async () => {
|
||||
try {
|
||||
const res = await userFetch("/api/zai/config")
|
||||
if (!res.ok) return false
|
||||
const data = await res.json()
|
||||
return data.config?.enabled === true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
testConnection: async () => {
|
||||
try {
|
||||
const res = await userFetch("/api/zai/test", { method: "POST" })
|
||||
if (!res.ok) return false
|
||||
const data = await res.json()
|
||||
return data.connected === true
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "qwen-oauth",
|
||||
name: "Qwen Code",
|
||||
icon: "🔷",
|
||||
checkEnabled: async () => {
|
||||
const token = localStorage.getItem("qwen_oauth_token")
|
||||
return token !== null && token.length > 0
|
||||
},
|
||||
testConnection: async () => {
|
||||
try {
|
||||
const tokenStr = localStorage.getItem("qwen_oauth_token")
|
||||
if (!tokenStr) return false
|
||||
const token = JSON.parse(tokenStr)
|
||||
// Check if token is expired
|
||||
const expiresAt = (token.created_at || 0) + (token.expires_in || 0) * 1000
|
||||
return Date.now() < expiresAt
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "antigravity",
|
||||
name: "Antigravity",
|
||||
icon: "🚀",
|
||||
checkEnabled: async () => {
|
||||
const token = localStorage.getItem("antigravity_oauth_token")
|
||||
return token !== null && token.length > 0
|
||||
},
|
||||
testConnection: async () => {
|
||||
try {
|
||||
const tokenStr = localStorage.getItem("antigravity_oauth_token")
|
||||
if (!tokenStr) return false
|
||||
const token = JSON.parse(tokenStr)
|
||||
const expiresAt = (token.created_at || 0) + (token.expires_in || 0) * 1000
|
||||
return Date.now() < expiresAt
|
||||
} catch {
|
||||
return false
|
||||
}
|
||||
},
|
||||
},
|
||||
]
|
||||
|
||||
interface ApiStatusCheckerProps {
|
||||
onSettingsClick?: (apiId: string) => void
|
||||
compact?: boolean
|
||||
}
|
||||
|
||||
const ApiStatusChecker: Component<ApiStatusCheckerProps> = (props) => {
|
||||
const [statuses, setStatuses] = createSignal<ApiStatus[]>([])
|
||||
const [isChecking, setIsChecking] = createSignal(false)
|
||||
const [lastFullCheck, setLastFullCheck] = createSignal<number>(0)
|
||||
|
||||
const checkAllApis = async () => {
|
||||
setIsChecking(true)
|
||||
const results: ApiStatus[] = []
|
||||
|
||||
for (const api of API_CHECKS) {
|
||||
setStatuses((prev) => {
|
||||
const existing = prev.find((s) => s.id === api.id)
|
||||
if (existing) {
|
||||
return prev.map((s) => (s.id === api.id ? { ...s, checking: true } : s))
|
||||
}
|
||||
return [...prev, { id: api.id, name: api.name, icon: api.icon, enabled: false, connected: false, checking: true }]
|
||||
})
|
||||
|
||||
try {
|
||||
const enabled = await api.checkEnabled()
|
||||
let connected = false
|
||||
let error: string | undefined
|
||||
|
||||
if (enabled) {
|
||||
try {
|
||||
connected = await api.testConnection()
|
||||
} catch (e) {
|
||||
error = e instanceof Error ? e.message : "Connection test failed"
|
||||
}
|
||||
}
|
||||
|
||||
results.push({
|
||||
id: api.id,
|
||||
name: api.name,
|
||||
icon: api.icon,
|
||||
enabled,
|
||||
connected,
|
||||
checking: false,
|
||||
error,
|
||||
lastChecked: Date.now(),
|
||||
})
|
||||
} catch (e) {
|
||||
results.push({
|
||||
id: api.id,
|
||||
name: api.name,
|
||||
icon: api.icon,
|
||||
enabled: false,
|
||||
connected: false,
|
||||
checking: false,
|
||||
error: e instanceof Error ? e.message : "Check failed",
|
||||
lastChecked: Date.now(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
setStatuses(results)
|
||||
setLastFullCheck(Date.now())
|
||||
setIsChecking(false)
|
||||
}
|
||||
|
||||
onMount(() => {
|
||||
checkAllApis()
|
||||
})
|
||||
|
||||
const getStatusIcon = (status: ApiStatus) => {
|
||||
if (status.checking) {
|
||||
return <Loader class="w-4 h-4 animate-spin text-gray-400" />
|
||||
}
|
||||
if (!status.enabled) {
|
||||
return <div class="w-4 h-4 rounded-full bg-gray-300 dark:bg-gray-600" />
|
||||
}
|
||||
if (status.connected) {
|
||||
return <CheckCircle class="w-4 h-4 text-green-500" />
|
||||
}
|
||||
if (status.error) {
|
||||
return <XCircle class="w-4 h-4 text-red-500" />
|
||||
}
|
||||
return <AlertTriangle class="w-4 h-4 text-yellow-500" />
|
||||
}
|
||||
|
||||
const getStatusText = (status: ApiStatus) => {
|
||||
if (status.checking) return "Checking..."
|
||||
if (!status.enabled) return "Not configured"
|
||||
if (status.connected) return "Connected"
|
||||
if (status.error) return status.error
|
||||
return "Connection failed"
|
||||
}
|
||||
|
||||
const enabledCount = () => statuses().filter((s) => s.enabled && s.connected).length
|
||||
const totalConfigured = () => statuses().filter((s) => s.enabled).length
|
||||
|
||||
if (props.compact) {
|
||||
return (
|
||||
<div class="flex items-center gap-2 px-3 py-2 bg-gray-50 dark:bg-gray-800/50 rounded-lg">
|
||||
<span class="text-xs text-gray-500">APIs:</span>
|
||||
<div class="flex items-center gap-1">
|
||||
<For each={statuses()}>
|
||||
{(status) => (
|
||||
<div
|
||||
class="cursor-pointer hover:scale-110 transition-transform"
|
||||
title={`${status.name}: ${getStatusText(status)}`}
|
||||
onClick={() => props.onSettingsClick?.(status.id)}
|
||||
>
|
||||
<span class="text-sm">{status.icon}</span>
|
||||
<Show when={status.enabled}>
|
||||
<span
|
||||
class={`inline-block w-1.5 h-1.5 rounded-full ml-0.5 ${status.connected ? "bg-green-500" : status.checking ? "bg-yellow-500" : "bg-red-500"
|
||||
}`}
|
||||
/>
|
||||
</Show>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
<button
|
||||
class="p-1 hover:bg-gray-200 dark:hover:bg-gray-700 rounded"
|
||||
onClick={checkAllApis}
|
||||
disabled={isChecking()}
|
||||
title="Refresh API status"
|
||||
>
|
||||
<RefreshCw class={`w-3 h-3 ${isChecking() ? "animate-spin" : ""}`} />
|
||||
</button>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<div class="space-y-4">
|
||||
<div class="flex items-center justify-between">
|
||||
<div>
|
||||
<h3 class="text-lg font-semibold">API Connections</h3>
|
||||
<p class="text-sm text-gray-500">
|
||||
{enabledCount()} of {totalConfigured()} APIs connected
|
||||
</p>
|
||||
</div>
|
||||
<button
|
||||
class="flex items-center gap-2 px-3 py-1.5 text-sm bg-blue-500 hover:bg-blue-600 text-white rounded-lg disabled:opacity-50"
|
||||
onClick={checkAllApis}
|
||||
disabled={isChecking()}
|
||||
>
|
||||
<RefreshCw class={`w-4 h-4 ${isChecking() ? "animate-spin" : ""}`} />
|
||||
{isChecking() ? "Checking..." : "Refresh All"}
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-3">
|
||||
<For each={statuses()}>
|
||||
{(status) => (
|
||||
<div class="flex items-center justify-between p-3 bg-gray-50 dark:bg-gray-800/50 rounded-lg border border-gray-200 dark:border-gray-700">
|
||||
<div class="flex items-center gap-3">
|
||||
<span class="text-xl">{status.icon}</span>
|
||||
<div>
|
||||
<div class="font-medium">{status.name}</div>
|
||||
<div class="text-xs text-gray-500">{getStatusText(status)}</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="flex items-center gap-2">
|
||||
{getStatusIcon(status)}
|
||||
<button
|
||||
class="p-1.5 hover:bg-gray-200 dark:hover:bg-gray-700 rounded"
|
||||
onClick={() => props.onSettingsClick?.(status.id)}
|
||||
title="Configure"
|
||||
>
|
||||
<Settings class="w-4 h-4" />
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</For>
|
||||
</div>
|
||||
|
||||
<Show when={lastFullCheck() > 0}>
|
||||
<p class="text-xs text-gray-400 text-center">
|
||||
Last checked: {new Date(lastFullCheck()).toLocaleTimeString()}
|
||||
</p>
|
||||
</Show>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export default ApiStatusChecker
|
||||
@@ -4,6 +4,7 @@ import { Button } from '@suid/material'
|
||||
import { Cloud, CheckCircle, XCircle, Loader } from 'lucide-solid'
|
||||
import { instances } from '../../stores/instances'
|
||||
import { fetchProviders } from '../../stores/session-api'
|
||||
import { userFetch } from '../../lib/user-context'
|
||||
|
||||
interface OllamaCloudConfig {
|
||||
enabled: boolean
|
||||
@@ -34,7 +35,7 @@ const OllamaCloudSettings: Component = () => {
|
||||
// Load config on mount
|
||||
onMount(async () => {
|
||||
try {
|
||||
const response = await fetch('/api/ollama/config')
|
||||
const response = await userFetch('/api/ollama/config')
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
const maskedKey = typeof data.config?.apiKey === "string" && /^\*+$/.test(data.config.apiKey)
|
||||
@@ -62,7 +63,7 @@ const OllamaCloudSettings: Component = () => {
|
||||
delete payload.apiKey
|
||||
}
|
||||
|
||||
const response = await fetch('/api/ollama/config', {
|
||||
const response = await userFetch('/api/ollama/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
@@ -101,7 +102,7 @@ const OllamaCloudSettings: Component = () => {
|
||||
setConnectionStatus('testing')
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/ollama/test', {
|
||||
const response = await userFetch('/api/ollama/test', {
|
||||
method: 'POST'
|
||||
})
|
||||
|
||||
@@ -140,7 +141,7 @@ const OllamaCloudSettings: Component = () => {
|
||||
const loadModels = async () => {
|
||||
setIsLoadingModels(true)
|
||||
try {
|
||||
const response = await fetch('/api/ollama/models')
|
||||
const response = await userFetch('/api/ollama/models')
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
// Handle different response formats
|
||||
|
||||
@@ -2,6 +2,7 @@ import { Component, createSignal, onMount, Show } from 'solid-js'
|
||||
import toast from 'solid-toast'
|
||||
import { Button } from '@suid/material'
|
||||
import { Cpu, CheckCircle, XCircle, Loader, Key, ExternalLink } from 'lucide-solid'
|
||||
import { userFetch } from '../../lib/user-context'
|
||||
|
||||
interface ZAIConfig {
|
||||
enabled: boolean
|
||||
@@ -19,7 +20,7 @@ const ZAISettings: Component = () => {
|
||||
// Load config on mount
|
||||
onMount(async () => {
|
||||
try {
|
||||
const response = await fetch('/api/zai/config')
|
||||
const response = await userFetch('/api/zai/config')
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
setConfig(data.config)
|
||||
@@ -37,7 +38,7 @@ const ZAISettings: Component = () => {
|
||||
const saveConfig = async () => {
|
||||
setIsLoading(true)
|
||||
try {
|
||||
const response = await fetch('/api/zai/config', {
|
||||
const response = await userFetch('/api/zai/config', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(config())
|
||||
@@ -66,7 +67,7 @@ const ZAISettings: Component = () => {
|
||||
setConnectionStatus('testing')
|
||||
|
||||
try {
|
||||
const response = await fetch('/api/zai/test', {
|
||||
const response = await userFetch('/api/zai/test', {
|
||||
method: 'POST'
|
||||
})
|
||||
|
||||
@@ -104,7 +105,7 @@ const ZAISettings: Component = () => {
|
||||
|
||||
const loadModels = async () => {
|
||||
try {
|
||||
const response = await fetch('/api/zai/models')
|
||||
const response = await userFetch('/api/zai/models')
|
||||
if (response.ok) {
|
||||
const data = await response.json()
|
||||
setModels(data.models.map((m: any) => m.name))
|
||||
@@ -186,7 +187,7 @@ const ZAISettings: Component = () => {
|
||||
<label class="block font-medium mb-2">Endpoint</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="https://api.z.ai/api/coding/paas/v4"
|
||||
placeholder="https://api.z.ai/api"
|
||||
value={config().endpoint || ''}
|
||||
onChange={(e) => handleConfigChange('endpoint', e.target.value)}
|
||||
class="w-full px-3 py-2 border border-gray-300 dark:border-gray-600 rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500 bg-white dark:bg-gray-800"
|
||||
|
||||
@@ -28,6 +28,7 @@ import type {
|
||||
PortAvailabilityResponse,
|
||||
} from "../../../server/src/api-types"
|
||||
import { getLogger } from "./logger"
|
||||
import { getUserHeaders } from "./user-context"
|
||||
|
||||
const FALLBACK_API_BASE = "http://127.0.0.1:9898"
|
||||
const RUNTIME_BASE = typeof window !== "undefined" ? window.location?.origin : undefined
|
||||
@@ -87,8 +88,10 @@ function logHttp(message: string, context?: Record<string, unknown>) {
|
||||
|
||||
async function request<T>(path: string, init?: RequestInit): Promise<T> {
|
||||
const url = API_BASE_ORIGIN ? new URL(path, API_BASE_ORIGIN).toString() : path
|
||||
const userHeaders = getUserHeaders()
|
||||
const headers: HeadersInit = {
|
||||
"Content-Type": "application/json",
|
||||
...userHeaders,
|
||||
...(init?.headers ?? {}),
|
||||
}
|
||||
|
||||
|
||||
@@ -20,8 +20,9 @@ function detectHost(): HostRuntime {
|
||||
return "web"
|
||||
}
|
||||
|
||||
const win = window as Window & { electronAPI?: unknown }
|
||||
if (typeof win.electronAPI !== "undefined") {
|
||||
// Check for common Electron injection patterns
|
||||
const win = window as any
|
||||
if (win.electronAPI || win.electron || win.ipcRenderer || win.process?.versions?.electron) {
|
||||
return "electron"
|
||||
}
|
||||
|
||||
|
||||
157
packages/ui/src/lib/user-context.ts
Normal file
157
packages/ui/src/lib/user-context.ts
Normal file
@@ -0,0 +1,157 @@
|
||||
import { createSignal } from "solid-js"
|
||||
import { isElectronHost } from "./runtime-env"
|
||||
|
||||
// Storage key for active user
|
||||
const ACTIVE_USER_KEY = "codenomad_active_user_id"
|
||||
|
||||
const [isLoggedIn, setLoggedIn] = createSignal(false)
|
||||
const [isInitialized, setInitialized] = createSignal(false)
|
||||
|
||||
export { isLoggedIn, setLoggedIn, isInitialized }
|
||||
|
||||
/**
|
||||
* Set the active user ID
|
||||
*/
|
||||
export function setActiveUserId(userId: string | null): void {
|
||||
if (userId) {
|
||||
localStorage.setItem(ACTIVE_USER_KEY, userId)
|
||||
setLoggedIn(true)
|
||||
console.log(`[UserContext] Active user set to: ${userId}`)
|
||||
} else {
|
||||
localStorage.removeItem(ACTIVE_USER_KEY)
|
||||
setLoggedIn(false)
|
||||
console.log(`[UserContext] Active user cleared`)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the active user ID
|
||||
*/
|
||||
export function getActiveUserId(): string | null {
|
||||
return localStorage.getItem(ACTIVE_USER_KEY)
|
||||
}
|
||||
|
||||
/**
|
||||
* Get headers with user ID for API requests
|
||||
*/
|
||||
export function getUserHeaders(): Record<string, string> {
|
||||
const userId = getActiveUserId()
|
||||
if (userId) {
|
||||
return { "X-User-Id": userId }
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create fetch options with user headers
|
||||
*/
|
||||
export function withUserHeaders(options: RequestInit = {}): RequestInit {
|
||||
const userHeaders = getUserHeaders()
|
||||
if (Object.keys(userHeaders).length === 0) return options
|
||||
|
||||
const headers = new Headers(options.headers || {})
|
||||
for (const [key, value] of Object.entries(userHeaders)) {
|
||||
headers.set(key, value)
|
||||
}
|
||||
|
||||
return {
|
||||
...options,
|
||||
headers,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch wrapper that automatically includes user headers
|
||||
*/
|
||||
export async function userFetch(url: string | URL | Request, options: RequestInit = {}): Promise<Response> {
|
||||
return fetch(url, withUserHeaders(options))
|
||||
}
|
||||
|
||||
/**
|
||||
* Globally patch fetch to include user headers for all internal /api/* requests
|
||||
* This ensures compatibility with legacy code and 3rd party libraries.
|
||||
*/
|
||||
export function patchFetch(): void {
|
||||
if ((window as any)._codenomad_fetch_patched) return
|
||||
(window as any)._codenomad_fetch_patched = true
|
||||
|
||||
const originalFetch = window.fetch
|
||||
window.fetch = async function (input: RequestInfo | URL, init?: RequestInit) {
|
||||
let url = ""
|
||||
if (typeof input === "string") {
|
||||
url = input
|
||||
} else if (input instanceof URL) {
|
||||
url = input.toString()
|
||||
} else if (input instanceof Request) {
|
||||
url = input.url
|
||||
}
|
||||
|
||||
// Only inject headers for internal API calls
|
||||
if (url.startsWith("/api/") || url.includes(window.location.origin + "/api/")) {
|
||||
return originalFetch(input, withUserHeaders(init))
|
||||
}
|
||||
|
||||
return originalFetch(input, init)
|
||||
}
|
||||
console.log("[UserContext] Global fetch patched for /api/* requests")
|
||||
}
|
||||
|
||||
/**
|
||||
* Initialize user context from Host (Electron/Tauri) or API
|
||||
* Call this on app startup
|
||||
*/
|
||||
export async function initializeUserContext(): Promise<void> {
|
||||
console.log(`[UserContext] Initializing... host=${isElectronHost()}`)
|
||||
try {
|
||||
if (isElectronHost()) {
|
||||
const api = (window as any).electronAPI
|
||||
if (api && api.getActiveUser) {
|
||||
console.log(`[UserContext] Requesting active user via api.getActiveUser()...`)
|
||||
const activeUser = await api.getActiveUser()
|
||||
console.log(`[UserContext] getActiveUser result:`, activeUser)
|
||||
|
||||
if (activeUser?.id) {
|
||||
console.log(`[UserContext] Host has active session: ${activeUser.id}`)
|
||||
setActiveUserId(activeUser.id)
|
||||
} else {
|
||||
console.log(`[UserContext] Host has no active session. Enforcing login.`)
|
||||
setActiveUserId(null)
|
||||
}
|
||||
} else {
|
||||
console.warn(`[UserContext] electronAPI.getActiveUser not found. Falling back to web mode.`)
|
||||
await handleWebInit()
|
||||
}
|
||||
} else {
|
||||
await handleWebInit()
|
||||
}
|
||||
} catch (error) {
|
||||
console.error(`[UserContext] Critical initialization error:`, error)
|
||||
setActiveUserId(null)
|
||||
} finally {
|
||||
setInitialized(true)
|
||||
}
|
||||
}
|
||||
|
||||
async function handleWebInit() {
|
||||
console.log(`[UserContext] Web init - checking local cache...`)
|
||||
const existingId = getActiveUserId()
|
||||
|
||||
// In "Mandatory Login" mode, we might want to clear this on every fresh load
|
||||
// but for now let's see if the server validates it.
|
||||
if (existingId) {
|
||||
// We could verify this ID with the server here if we had a /api/users/me endpoint
|
||||
// For now, let's keep it but mark it as "unverified" or just let the first API fail
|
||||
console.log(`[UserContext] Found cached ID: ${existingId}. Validating session...`)
|
||||
|
||||
// Strategy: We want mandatory login. If this is a fresh launch, we should probably clear it.
|
||||
// For Electron it's already cleared in main.ts. For Web it's tricky.
|
||||
// Let's lean towards SECURITY: if no one explicitly logged in THIS RUN, show login.
|
||||
|
||||
// Actually, if we are in Electron and we hit this, it's because IPC failed.
|
||||
// If we are in Web, we trust it for now but we'll see.
|
||||
setLoggedIn(true)
|
||||
} else {
|
||||
console.log(`[UserContext] No cached ID found.`)
|
||||
setLoggedIn(false)
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,13 @@
|
||||
import { render } from "solid-js/web"
|
||||
import { Show, onMount } from "solid-js"
|
||||
import App from "./App"
|
||||
import { ThemeProvider } from "./lib/theme"
|
||||
import { ConfigProvider } from "./stores/preferences"
|
||||
import { InstanceConfigProvider } from "./stores/instance-config"
|
||||
import { runtimeEnv } from "./lib/runtime-env"
|
||||
import LoginView from "./components/auth/LoginView"
|
||||
import { isLoggedIn, initializeUserContext, patchFetch, isInitialized } from "./lib/user-context"
|
||||
import { Toaster } from "solid-toast"
|
||||
import "./index.css"
|
||||
import "@git-diff-view/solid/styles/diff-view-pure.css"
|
||||
|
||||
@@ -18,15 +22,41 @@ if (typeof document !== "undefined") {
|
||||
document.documentElement.dataset.runtimePlatform = runtimeEnv.platform
|
||||
}
|
||||
|
||||
render(
|
||||
() => (
|
||||
<ConfigProvider>
|
||||
<InstanceConfigProvider>
|
||||
<ThemeProvider>
|
||||
<App />
|
||||
</ThemeProvider>
|
||||
</InstanceConfigProvider>
|
||||
</ConfigProvider>
|
||||
),
|
||||
root,
|
||||
)
|
||||
const Root = () => {
|
||||
onMount(() => {
|
||||
patchFetch()
|
||||
initializeUserContext()
|
||||
})
|
||||
|
||||
return (
|
||||
<>
|
||||
<Toaster
|
||||
position="top-right"
|
||||
gutter={8}
|
||||
toastOptions={{
|
||||
style: {
|
||||
background: "#1a1a1a",
|
||||
color: "#fff",
|
||||
border: "1px solid rgba(255,255,255,0.1)",
|
||||
},
|
||||
}}
|
||||
/>
|
||||
<Show when={isInitialized()}>
|
||||
<Show
|
||||
when={isLoggedIn()}
|
||||
fallback={<LoginView onLoginSuccess={() => initializeUserContext()} />}
|
||||
>
|
||||
<ConfigProvider>
|
||||
<InstanceConfigProvider>
|
||||
<ThemeProvider>
|
||||
<App />
|
||||
</ThemeProvider>
|
||||
</InstanceConfigProvider>
|
||||
</ConfigProvider>
|
||||
</Show>
|
||||
</Show>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
render(() => <Root />, root)
|
||||
|
||||
@@ -19,7 +19,14 @@ import {
|
||||
clearCompactionSuggestion,
|
||||
type CompactionResult,
|
||||
} from "./session-compaction"
|
||||
import { createSession, loadMessages, getStoredAntigravityToken, isAntigravityTokenValid } from "./session-api"
|
||||
import {
|
||||
ANTIGRAVITY_MODEL_IDS,
|
||||
createSession,
|
||||
getStoredAntigravityProjectId,
|
||||
getStoredAntigravityToken,
|
||||
isAntigravityTokenValid,
|
||||
loadMessages,
|
||||
} from "./session-api"
|
||||
import { showToastNotification } from "../lib/notifications"
|
||||
import { QwenOAuthManager } from "../lib/integrations/qwen-oauth"
|
||||
import { getUserScopedKey } from "../lib/user-storage"
|
||||
@@ -496,6 +503,7 @@ async function readSseStream(
|
||||
if (idleTimer) clearTimeout(idleTimer)
|
||||
idleTimer = setTimeout(() => {
|
||||
timedOut = true
|
||||
shouldStop = true
|
||||
reader.cancel().catch(() => { })
|
||||
}, idleTimeoutMs)
|
||||
}
|
||||
@@ -505,9 +513,15 @@ async function readSseStream(
|
||||
let chunkCount = 0
|
||||
let lastYieldTime = performance.now()
|
||||
while (!shouldStop) {
|
||||
const { done, value } = await reader.read()
|
||||
let readResult: ReadableStreamReadResult<Uint8Array>
|
||||
try {
|
||||
readResult = await reader.read()
|
||||
} catch (error) {
|
||||
if (timedOut) break
|
||||
throw error
|
||||
}
|
||||
const { done, value } = readResult
|
||||
if (done) break
|
||||
resetIdleTimer()
|
||||
buffer += decoder.decode(value, { stream: true })
|
||||
const lines = buffer.split("\n")
|
||||
buffer = lines.pop() || ""
|
||||
@@ -517,6 +531,7 @@ async function readSseStream(
|
||||
if (!trimmed.startsWith("data:")) continue
|
||||
const data = trimmed.slice(5).trim()
|
||||
if (!data) continue
|
||||
resetIdleTimer()
|
||||
if (data === "[DONE]") {
|
||||
shouldStop = true
|
||||
break
|
||||
@@ -1175,6 +1190,10 @@ async function streamAntigravityChat(
|
||||
"Content-Type": "application/json",
|
||||
Authorization: `Bearer ${token.access_token}`,
|
||||
}
|
||||
const projectId = getStoredAntigravityProjectId()
|
||||
if (projectId) {
|
||||
headers["X-Antigravity-Project"] = projectId
|
||||
}
|
||||
|
||||
const response = await fetch("/api/antigravity/chat", {
|
||||
method: "POST",
|
||||
@@ -1491,6 +1510,10 @@ async function sendMessage(
|
||||
})
|
||||
|
||||
const providerId = effectiveModel.providerId
|
||||
const useAntigravity =
|
||||
providerId === "antigravity" ||
|
||||
(providerId === "google" && ANTIGRAVITY_MODEL_IDS.has(effectiveModel.modelId))
|
||||
const routingProviderId = useAntigravity ? "antigravity" : providerId
|
||||
const tPre1 = performance.now()
|
||||
const systemMessage = await untrack(() => mergeSystemInstructions(instanceId, sessionId, prompt))
|
||||
const tPre2 = performance.now()
|
||||
@@ -1498,7 +1521,7 @@ async function sendMessage(
|
||||
addDebugLog(`Merge System Instructions: ${Math.round(tPre2 - tPre1)}ms`, "warn")
|
||||
}
|
||||
|
||||
if (providerId === "ollama-cloud" || providerId === "qwen-oauth" || providerId === "opencode-zen" || providerId === "zai" || providerId === "antigravity") {
|
||||
if (providerId === "ollama-cloud" || providerId === "qwen-oauth" || providerId === "opencode-zen" || providerId === "zai" || useAntigravity) {
|
||||
const store = messageStoreBus.getOrCreate(instanceId)
|
||||
const now = Date.now()
|
||||
const assistantMessageId = createId("msg")
|
||||
@@ -1530,7 +1553,7 @@ async function sendMessage(
|
||||
store.setMessageInfo(assistantMessageId, {
|
||||
id: assistantMessageId,
|
||||
role: "assistant",
|
||||
providerID: effectiveModel.providerId,
|
||||
providerID: routingProviderId,
|
||||
modelID: effectiveModel.modelId,
|
||||
time: { created: now, completed: 0 },
|
||||
} as any)
|
||||
@@ -1582,11 +1605,11 @@ async function sendMessage(
|
||||
assistantMessageId,
|
||||
assistantPartId,
|
||||
)
|
||||
} else if (providerId === "antigravity") {
|
||||
} else if (useAntigravity) {
|
||||
assistantText = await streamAntigravityChat(
|
||||
instanceId,
|
||||
sessionId,
|
||||
providerId,
|
||||
routingProviderId,
|
||||
effectiveModel.modelId,
|
||||
externalMessages,
|
||||
messageId,
|
||||
@@ -1695,26 +1718,33 @@ async function sendMessage(
|
||||
updatedAt: Date.now(),
|
||||
isEphemeral: false,
|
||||
})
|
||||
const rawErrorMessage = error?.message || "Request failed"
|
||||
const normalizedErrorMessage = /aborted|abort/i.test(rawErrorMessage)
|
||||
? "Request timed out. The provider may be unavailable."
|
||||
: rawErrorMessage
|
||||
store.setMessageInfo(assistantMessageId, {
|
||||
id: assistantMessageId,
|
||||
role: "assistant",
|
||||
providerID: effectiveModel.providerId,
|
||||
providerID: routingProviderId,
|
||||
modelID: effectiveModel.modelId,
|
||||
time: { created: now, completed: Date.now() },
|
||||
error: { name: "UnknownError", message: error?.message || "Request failed" },
|
||||
error: { name: "UnknownError", message: normalizedErrorMessage },
|
||||
} as any)
|
||||
const failedProvider = useAntigravity ? "antigravity" : providerId
|
||||
showToastNotification({
|
||||
title:
|
||||
providerId === "ollama-cloud"
|
||||
failedProvider === "ollama-cloud"
|
||||
? "Ollama request failed"
|
||||
: providerId === "zai"
|
||||
: failedProvider === "zai"
|
||||
? "Z.AI request failed"
|
||||
: providerId === "opencode-zen"
|
||||
: failedProvider === "opencode-zen"
|
||||
? "OpenCode Zen request failed"
|
||||
: providerId === "antigravity"
|
||||
: failedProvider === "antigravity"
|
||||
? "Antigravity request failed"
|
||||
: "Qwen request failed",
|
||||
message: error?.message || "Request failed",
|
||||
: failedProvider === "qwen-oauth"
|
||||
? "Qwen request failed"
|
||||
: "Request failed",
|
||||
message: normalizedErrorMessage,
|
||||
variant: "error",
|
||||
duration: 8000,
|
||||
})
|
||||
|
||||
@@ -40,6 +40,20 @@ import { getUserScopedKey } from "../lib/user-storage"
|
||||
const log = getLogger("api")
|
||||
|
||||
type ProviderMap = Map<string, Provider>
|
||||
export const ANTIGRAVITY_MODEL_IDS = new Set([
|
||||
"gemini-3-pro-low",
|
||||
"gemini-3-pro-high",
|
||||
"gemini-3-flash",
|
||||
"claude-sonnet-4-5",
|
||||
"claude-sonnet-4-5-thinking-low",
|
||||
"claude-sonnet-4-5-thinking-medium",
|
||||
"claude-sonnet-4-5-thinking-high",
|
||||
"claude-opus-4-5-thinking-low",
|
||||
"claude-opus-4-5-thinking-medium",
|
||||
"claude-opus-4-5-thinking-high",
|
||||
"gpt-oss-120b-medium",
|
||||
])
|
||||
const ANTIGRAVITY_PROJECT_KEY = "antigravity_project_id"
|
||||
|
||||
async function fetchJson<T>(url: string): Promise<T | null> {
|
||||
try {
|
||||
@@ -271,12 +285,26 @@ export function isAntigravityTokenValid(token: { expires_in: number; created_at:
|
||||
return Date.now() < expiresAt
|
||||
}
|
||||
|
||||
export function getStoredAntigravityProjectId(): string | undefined {
|
||||
if (typeof window === "undefined") return undefined
|
||||
try {
|
||||
const value = window.localStorage.getItem(getUserScopedKey(ANTIGRAVITY_PROJECT_KEY))
|
||||
return value && value.trim().length > 0 ? value.trim() : undefined
|
||||
} catch {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
async function fetchAntigravityProvider(): Promise<Provider | null> {
|
||||
const token = getStoredAntigravityToken()
|
||||
const projectId = getStoredAntigravityProjectId()
|
||||
const headers: Record<string, string> = { "Content-Type": "application/json" }
|
||||
if (token?.access_token) {
|
||||
headers["Authorization"] = `Bearer ${token.access_token}`
|
||||
}
|
||||
if (projectId) {
|
||||
headers["X-Antigravity-Project"] = projectId
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await fetch("/api/antigravity/models", { headers })
|
||||
@@ -295,7 +323,7 @@ async function fetchAntigravityProvider(): Promise<Provider | null> {
|
||||
|
||||
return {
|
||||
id: "antigravity",
|
||||
name: "Antigravity (Google OAuth)",
|
||||
name: "Antigravity",
|
||||
models: models.map((model) => ({
|
||||
id: model.id,
|
||||
name: model.name,
|
||||
@@ -994,14 +1022,37 @@ async function fetchProviders(instanceId: string): Promise<void> {
|
||||
}
|
||||
}
|
||||
|
||||
const normalizedProviders = providerList
|
||||
.map((provider) => {
|
||||
if (provider.id !== "google") return provider
|
||||
const filteredModels = provider.models.filter((model: Model) => ANTIGRAVITY_MODEL_IDS.has(model.id))
|
||||
if (filteredModels.length === 0) return null
|
||||
const defaultModelId = filteredModels.some((model: Model) => model.id === provider.defaultModelId)
|
||||
? provider.defaultModelId
|
||||
: filteredModels[0]?.id
|
||||
return {
|
||||
...provider,
|
||||
name: "Antigravity",
|
||||
defaultModelId,
|
||||
models: filteredModels,
|
||||
}
|
||||
})
|
||||
.filter(Boolean) as typeof providerList
|
||||
|
||||
// Filter out Z.AI providers from SDK to use our custom routing with full message history
|
||||
const filteredBaseProviders = providerList.filter((provider) =>
|
||||
const filteredBaseProviders = normalizedProviders.filter((provider) =>
|
||||
!provider.id.toLowerCase().includes("zai") &&
|
||||
!provider.id.toLowerCase().includes("z.ai") &&
|
||||
!provider.id.toLowerCase().includes("glm")
|
||||
)
|
||||
|
||||
const extraProviders = await fetchExtraProviders()
|
||||
let extraProviders = await fetchExtraProviders()
|
||||
if (!isNative) {
|
||||
const hasSdkAntigravity = normalizedProviders.some((provider) => provider.id === "google")
|
||||
if (hasSdkAntigravity) {
|
||||
extraProviders = extraProviders.filter((provider) => provider.id !== "antigravity")
|
||||
}
|
||||
}
|
||||
const baseProviders = removeDuplicateProviders(filteredBaseProviders, extraProviders)
|
||||
const mergedProviders = mergeProviders(baseProviders, extraProviders)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user