@myrialabs/clopen 0.3.9 → 0.3.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -19
- package/backend/auth/auth-service.ts +56 -1
- package/backend/auth/permissions.ts +26 -1
- package/backend/auth/session-cleanup.ts +58 -0
- package/backend/chat/stream-manager.ts +72 -13
- package/backend/db-client/connection-manager.ts +9 -3
- package/backend/engine/adapters/codex/error-handler.ts +2 -2
- package/backend/engine/adapters/codex/stream.ts +2 -2
- package/backend/engine/adapters/copilot/stream.ts +5 -8
- package/backend/engine/adapters/opencode/presets.ts +1 -1
- package/backend/engine/adapters/opencode/stream.ts +5 -1
- package/backend/engine/adapters/qwen/stream.ts +1 -2
- package/backend/files/path-browsing.ts +20 -0
- package/backend/git/git-service.ts +81 -11
- package/backend/git/git-spawn-validation.test.ts +75 -0
- package/backend/git/git-spawn-validation.ts +77 -0
- package/backend/index.ts +5 -0
- package/backend/preview/browser/browser-tab-manager.ts +23 -3
- package/backend/snapshot/gitignore.ts +4 -9
- package/backend/tunnel/cloudflared/binary.ts +2 -2
- package/backend/tunnel/global-tunnel-manager.ts +9 -3
- package/backend/utils/ws.ts +5 -1
- package/backend/ws/access.ts +5 -5
- package/backend/ws/auth/index.ts +14 -0
- package/backend/ws/auth/login.ts +3 -0
- package/backend/ws/auth/users.ts +61 -1
- package/backend/ws/chat/stream.ts +103 -10
- package/backend/ws/db-client/query.ts +3 -1
- package/backend/ws/files/path-access.ts +101 -0
- package/backend/ws/files/read.ts +23 -10
- package/backend/ws/files/search.ts +10 -6
- package/backend/ws/files/watch.ts +1 -1
- package/backend/ws/files/write.ts +109 -15
- package/backend/ws/preview/browser/console.ts +2 -2
- package/backend/ws/projects/crud.ts +11 -6
- package/backend/ws/projects/status.ts +3 -1
- package/backend/ws/sessions/crud.ts +10 -4
- package/backend/ws/terminal/access.ts +3 -3
- package/backend/ws/terminal/persistence.ts +1 -1
- package/backend/ws/terminal/session.ts +2 -2
- package/dist/assets/{index-D8V2wj9B.js → index-C1afGwHY.js} +2 -2
- package/dist/assets/main-CZb3Y_Z_.js +315 -0
- package/dist/assets/main-Cn8cX2DY.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +2 -1
- package/dist/assets/main-C9nYVmnw.js +0 -312
- package/dist/assets/main-hspyFOoK.css +0 -1
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
<p align="center">
|
|
8
8
|
<strong>Build more. Switch less.</strong><br />
|
|
9
|
-
All-in-one workspace for
|
|
9
|
+
All-in-one workspace for AI coding agents
|
|
10
10
|
</p>
|
|
11
11
|
|
|
12
12
|
<p align="center">
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
<img src="https://clopen.myrialabs.dev/images/workspace-overview.webp" alt="Clopen workspace overview" />
|
|
27
27
|
</p>
|
|
28
28
|
|
|
29
|
-
All-in-one workspace for Claude Code
|
|
29
|
+
All-in-one workspace for AI coding agents — Claude Code, OpenCode, Codex, Copilot, and Qwen Code. Chat, terminal, git, browser preview, database client, and real-time collaboration, built for multi-project and multi-session workflows.
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
@@ -46,20 +46,20 @@ All-in-one workspace for Claude Code & OpenCode. Chat, terminal, git, browser pr
|
|
|
46
46
|
|
|
47
47
|
A complete development environment designed around AI-assisted workflows, built to disappear into the background and just work.
|
|
48
48
|
|
|
49
|
-
- **Multi-
|
|
50
|
-
- **Multi-Engine
|
|
51
|
-
- **Integrated Terminal** —
|
|
52
|
-
- **Full Git Management** — Stage, commit, branch, push, pull, stash, log, and resolve conflicts, all from a clean UI
|
|
49
|
+
- **Multi-Engine Support** — Switch between Claude Code, OpenCode, Codex, GitHub Copilot, and Qwen Code as your AI engine, per session
|
|
50
|
+
- **Multi-Account Per Engine** — Manage multiple accounts per engine (personal, work, or team) and switch between them instantly per chat session
|
|
51
|
+
- **Integrated Terminal** — Multi-tab xterm.js terminal with full keyboard control and complete ANSI/VT support, right inside your workspace
|
|
52
|
+
- **Full Git Management** — Stage, commit, branch, push, pull, stash, log, and resolve conflicts, all from a clean UI
|
|
53
53
|
- **Real Browser Preview** — A live browser preview streams directly into your workspace. Interact with your app manually, or let the AI drive: clicking, typing, and scrolling for autonomous visual testing
|
|
54
|
+
- **Database Client** — Connect to PostgreSQL, MySQL, SQLite, MongoDB, and Redis. Browse schemas, run queries, and inspect data, with optional SSH tunneling for databases behind a bastion
|
|
54
55
|
- **Git-Like Checkpoints** — Multi-branch undo/redo with full file snapshots. Roll back to any point in your AI conversation without touching your actual git history
|
|
55
|
-
- **Real-Time Collaboration** —
|
|
56
|
-
- **Monaco File Editor** — VS Code's editor
|
|
56
|
+
- **Real-Time Collaboration** — See who's working on which project, and collaborate live in the same codebase
|
|
57
|
+
- **Monaco File Editor** — VS Code's editor right in the browser. Full syntax highlighting, autocomplete, and live file watching, beside your AI chat
|
|
57
58
|
- **Cloudflare Tunnel** — One-click public HTTPS URL for your local dev server. Built-in QR code for instant mobile access. Share your work without deploying
|
|
58
59
|
- **MCP Support** — Full Model Context Protocol integration. Connect AI tools, external APIs, and custom capabilities to your AI agents with zero friction
|
|
59
60
|
- **Flexible Authentication** — No Login or With Login mode with admin/member roles, invite links, rate-limited login, and CLI token recovery
|
|
60
|
-
- **System Tools Installer** — Install Git, Claude Code, OpenCode, Chrome, and Cloudflared (for Public Tunnel)
|
|
61
|
+
- **System Tools Installer** — Install Git, Claude Code, OpenCode, Codex, Copilot, Qwen Code, Chrome, and Cloudflared (for Public Tunnel) from a one-click admin panel
|
|
61
62
|
- **Background Processing** — Chat, terminal, and other processes continue running even when you close the browser — come back later and pick up where you left off
|
|
62
|
-
- **Database Management** — Browse tables, run queries, and inspect your database directly from the workspace *(coming soon)*
|
|
63
63
|
|
|
64
64
|
---
|
|
65
65
|
|
|
@@ -68,7 +68,7 @@ A complete development environment designed around AI-assisted workflows, built
|
|
|
68
68
|
### Prerequisites
|
|
69
69
|
|
|
70
70
|
- [Bun.js](https://bun.sh/) v1.2.12+
|
|
71
|
-
- [Claude Code](https://github.com/anthropics/claude-code)
|
|
71
|
+
- At least one supported AI engine — [Claude Code](https://github.com/anthropics/claude-code), [OpenCode](https://opencode.ai), [Codex](https://github.com/openai/codex), [GitHub Copilot CLI](https://github.com/github/copilot-cli), or [Qwen Code](https://github.com/QwenLM/qwen-code). All are installable from **Settings → System Tools** after first launch
|
|
72
72
|
|
|
73
73
|
### Installation
|
|
74
74
|
|
|
@@ -88,7 +88,7 @@ Or manually via Bun:
|
|
|
88
88
|
bun add -g @myrialabs/clopen
|
|
89
89
|
```
|
|
90
90
|
|
|
91
|
-
You can also update from the **Settings → Maintenance
|
|
91
|
+
You can also update from the **Settings → Maintenance → Updates** section in the web UI.
|
|
92
92
|
|
|
93
93
|
### Usage
|
|
94
94
|
|
|
@@ -104,12 +104,13 @@ On first launch, a setup wizard guides you through:
|
|
|
104
104
|
|
|
105
105
|
1. **Authentication mode** — Choose between **No Login** (no authentication required, ideal for personal/local use) or **With Login** (login with Personal Access Token, supports team collaboration)
|
|
106
106
|
2. **Admin account** — If With Login mode is selected, create your admin account and save the generated PAT
|
|
107
|
-
3. **
|
|
108
|
-
4. **
|
|
107
|
+
3. **System Tools** — Install Git, Chrome, Cloudflared, and any AI engine you don't have yet — straight from the wizard, no terminal needed
|
|
108
|
+
4. **AI Engines** — Check installation status for Claude Code, OpenCode, Codex, Copilot, and Qwen Code, and sign in to the engines you'll use
|
|
109
|
+
5. **Preferences** — Set dark mode, font size, sound notifications, and message layout (Classic cards or Compact lines)
|
|
109
110
|
|
|
110
|
-
You can change the authentication mode anytime in **Settings → Security
|
|
111
|
+
You can change the authentication mode anytime in **Settings → Security → Authentication**.
|
|
111
112
|
|
|
112
|
-
To invite team members (With Login mode), go to **Settings → Team
|
|
113
|
+
To invite team members (With Login mode), go to **Settings → Team → Invite** and generate an invite link (valid for 15 minutes).
|
|
113
114
|
|
|
114
115
|
If you lose your admin token:
|
|
115
116
|
|
|
@@ -149,9 +150,8 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines and [DECISIONS.md](DECISIO
|
|
|
149
150
|
| Styling | Tailwind CSS v4 |
|
|
150
151
|
| Database | SQLite with migrations |
|
|
151
152
|
| Terminal | bun-pty |
|
|
152
|
-
| AI Engines | Claude Code
|
|
153
|
-
|
|
154
|
-
Clopen uses an engine-agnostic adapter pattern — both engines normalize output to a unified message format (`shared/types/unified`), ensuring a consistent experience regardless of which engine is selected.
|
|
153
|
+
| AI Engines | Claude Code, OpenCode, Codex, Copilot, Qwen Code |
|
|
154
|
+
| DB Client | Postgres, MySQL, SQLite, MongoDB, Redis (+ SSH tunnel) |
|
|
155
155
|
|
|
156
156
|
---
|
|
157
157
|
|
|
@@ -185,6 +185,9 @@ MIT License - see [LICENSE](LICENSE) for details.
|
|
|
185
185
|
|
|
186
186
|
- [Claude Code](https://github.com/anthropics/claude-code) by Anthropic
|
|
187
187
|
- [OpenCode](https://opencode.ai) by Anomaly
|
|
188
|
+
- [Codex](https://github.com/openai/codex) by OpenAI
|
|
189
|
+
- [GitHub Copilot CLI](https://github.com/github/copilot-cli) by GitHub
|
|
190
|
+
- [Qwen Code](https://github.com/QwenLM/qwen-code) by Alibaba Qwen
|
|
188
191
|
- [Bun](https://bun.sh/) runtime
|
|
189
192
|
- [Svelte](https://svelte.dev/) framework
|
|
190
193
|
|
|
@@ -4,7 +4,8 @@
|
|
|
4
4
|
* Core authentication logic: user creation, session management, invite handling.
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
|
-
import { authQueries, settingsQueries } from '$backend/database/queries';
|
|
7
|
+
import { authQueries, projectQueries, settingsQueries } from '$backend/database/queries';
|
|
8
|
+
import type { Project } from '$shared/types/database/schema';
|
|
8
9
|
import { generateSessionToken, generatePAT, generateInviteToken, hashToken, getTokenType } from './tokens';
|
|
9
10
|
import { generateColorFromString, getInitials } from '$backend/utils/user-helpers';
|
|
10
11
|
import { debug } from '$shared/utils/logger';
|
|
@@ -472,6 +473,60 @@ export function logoutAllSessions(): number {
|
|
|
472
473
|
return count;
|
|
473
474
|
}
|
|
474
475
|
|
|
476
|
+
/**
|
|
477
|
+
* List projects assigned to a specific user (admin view)
|
|
478
|
+
*/
|
|
479
|
+
export function listUserProjects(userId: string): Project[] {
|
|
480
|
+
const user = authQueries.getUserById(userId);
|
|
481
|
+
if (!user) {
|
|
482
|
+
throw new Error('User not found');
|
|
483
|
+
}
|
|
484
|
+
return projectQueries.getAllForUser(userId);
|
|
485
|
+
}
|
|
486
|
+
|
|
487
|
+
/**
|
|
488
|
+
* Assign a project to a user. Admins are implicitly assigned to all projects
|
|
489
|
+
* they create, but this is used to grant a member access to a project.
|
|
490
|
+
* Returns true if a new assignment was added, false if user already had access.
|
|
491
|
+
*/
|
|
492
|
+
export function assignProjectToUser(userId: string, projectId: string): boolean {
|
|
493
|
+
const user = authQueries.getUserById(userId);
|
|
494
|
+
if (!user) {
|
|
495
|
+
throw new Error('Access denied');
|
|
496
|
+
}
|
|
497
|
+
const project = projectQueries.getById(projectId);
|
|
498
|
+
if (!project) {
|
|
499
|
+
throw new Error('Access denied');
|
|
500
|
+
}
|
|
501
|
+
if (projectQueries.userHasProject(userId, projectId)) {
|
|
502
|
+
return false;
|
|
503
|
+
}
|
|
504
|
+
projectQueries.addUserProject(userId, projectId);
|
|
505
|
+
debug.log('auth', `Project ${projectId} assigned to user ${userId}`);
|
|
506
|
+
return true;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
/**
|
|
510
|
+
* Revoke a user's access to a project. Refuses to remove the last admin
|
|
511
|
+
* association to avoid orphaning the project.
|
|
512
|
+
*/
|
|
513
|
+
export function unassignProjectFromUser(userId: string, projectId: string): boolean {
|
|
514
|
+
const user = authQueries.getUserById(userId);
|
|
515
|
+
if (!user) {
|
|
516
|
+
throw new Error('Access denied');
|
|
517
|
+
}
|
|
518
|
+
const project = projectQueries.getById(projectId);
|
|
519
|
+
if (!project) {
|
|
520
|
+
throw new Error('Access denied');
|
|
521
|
+
}
|
|
522
|
+
if (!projectQueries.userHasProject(userId, projectId)) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
projectQueries.removeUserProject(userId, projectId);
|
|
526
|
+
debug.log('auth', `Project ${projectId} unassigned from user ${userId}`);
|
|
527
|
+
return true;
|
|
528
|
+
}
|
|
529
|
+
|
|
475
530
|
/**
|
|
476
531
|
* Cleanup expired sessions
|
|
477
532
|
*/
|
|
@@ -26,6 +26,13 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
26
26
|
'auth:revoke-invite',
|
|
27
27
|
'auth:list-users',
|
|
28
28
|
'auth:remove-user',
|
|
29
|
+
'auth:list-user-projects',
|
|
30
|
+
'auth:assign-project',
|
|
31
|
+
'auth:unassign-project',
|
|
32
|
+
// Project lifecycle — members can only access projects they are assigned to
|
|
33
|
+
// by an admin. Create/delete remain admin-only operations.
|
|
34
|
+
'projects:create',
|
|
35
|
+
'projects:delete',
|
|
29
36
|
'settings:update',
|
|
30
37
|
'settings:update-batch',
|
|
31
38
|
'system:run-update',
|
|
@@ -70,7 +77,25 @@ export const ADMIN_ONLY_ROUTES = new Set([
|
|
|
70
77
|
'engine:opencode-account-delete',
|
|
71
78
|
'engine:opencode-account-rename',
|
|
72
79
|
'engine:opencode-server-restart',
|
|
73
|
-
'engine:opencode-models-dev-fetch'
|
|
80
|
+
'engine:opencode-models-dev-fetch',
|
|
81
|
+
// Tunnel — remote/local management mutates global Cloudflare credentials,
|
|
82
|
+
// cloudflared auth, and ingress rules. Quick Tunnel is ephemeral and stays
|
|
83
|
+
// open. Read-only routes (status, *-list, ingress, auth-status) stay open so
|
|
84
|
+
// any authenticated user can see what is active.
|
|
85
|
+
'tunnel:remote:config:add',
|
|
86
|
+
'tunnel:remote:config:remove',
|
|
87
|
+
'tunnel:remote:start',
|
|
88
|
+
'tunnel:remote:stop',
|
|
89
|
+
'tunnel:local:login-start',
|
|
90
|
+
'tunnel:local:login-cancel',
|
|
91
|
+
'tunnel:local:logout',
|
|
92
|
+
'tunnel:local:set-zone',
|
|
93
|
+
'tunnel:local:create',
|
|
94
|
+
'tunnel:local:delete',
|
|
95
|
+
'tunnel:local:ingress:add',
|
|
96
|
+
'tunnel:local:ingress:remove',
|
|
97
|
+
'tunnel:local:start',
|
|
98
|
+
'tunnel:local:stop'
|
|
74
99
|
]);
|
|
75
100
|
|
|
76
101
|
/**
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expired Session Cleanup Scheduler
|
|
3
|
+
*
|
|
4
|
+
* Periodically removes expired auth sessions from the database.
|
|
5
|
+
* Without this, the auth_sessions table grows unbounded as expired
|
|
6
|
+
* sessions are never purged in long-running deployments.
|
|
7
|
+
*
|
|
8
|
+
* Pattern: same timer + dispose() approach as AuthRateLimiter.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import { authQueries } from '../database/queries';
|
|
12
|
+
import { debug } from '$shared/utils/logger';
|
|
13
|
+
|
|
14
|
+
/** How often to sweep for expired sessions (1 hour) */
|
|
15
|
+
const CLEANUP_INTERVAL_MS = 60 * 60_000;
|
|
16
|
+
|
|
17
|
+
class SessionCleanupScheduler {
|
|
18
|
+
private timer: ReturnType<typeof setInterval> | null = null;
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
// Timer is started in start(), not here — database may not be initialized yet.
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Start the periodic cleanup timer and run an initial sweep.
|
|
26
|
+
* Must be called AFTER database initialization.
|
|
27
|
+
*/
|
|
28
|
+
start(): void {
|
|
29
|
+
if (this.timer) return; // Already started
|
|
30
|
+
this.timer = setInterval(() => this.cleanup(), CLEANUP_INTERVAL_MS);
|
|
31
|
+
// Run once at startup so long-stale sessions are cleared immediately
|
|
32
|
+
this.cleanup();
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
private cleanup(): void {
|
|
36
|
+
try {
|
|
37
|
+
const deleted = authQueries.deleteExpiredSessions();
|
|
38
|
+
if (deleted > 0) {
|
|
39
|
+
debug.log('auth', `Session cleanup: removed ${deleted} expired session(s)`);
|
|
40
|
+
}
|
|
41
|
+
} catch (error) {
|
|
42
|
+
debug.warn('auth', 'Session cleanup failed:', error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Dispose — stop cleanup timer. Called during graceful shutdown.
|
|
48
|
+
*/
|
|
49
|
+
dispose(): void {
|
|
50
|
+
if (this.timer) {
|
|
51
|
+
clearInterval(this.timer);
|
|
52
|
+
this.timer = null;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** Singleton instance — started when the module is imported */
|
|
58
|
+
export const sessionCleanupScheduler = new SessionCleanupScheduler();
|
|
@@ -50,6 +50,7 @@ export interface StreamState {
|
|
|
50
50
|
projectPath?: string;
|
|
51
51
|
processId: string;
|
|
52
52
|
engine: EngineType;
|
|
53
|
+
accountId?: number;
|
|
53
54
|
status: 'active' | 'completed' | 'error' | 'cancelled';
|
|
54
55
|
startedAt: Date;
|
|
55
56
|
completedAt?: Date;
|
|
@@ -156,6 +157,7 @@ export type StreamEventType =
|
|
|
156
157
|
| 'message'
|
|
157
158
|
| 'partial'
|
|
158
159
|
| 'notification'
|
|
160
|
+
| 'rate_limit'
|
|
159
161
|
| 'complete'
|
|
160
162
|
| 'error'
|
|
161
163
|
| 'cancelled';
|
|
@@ -173,11 +175,57 @@ export interface StreamEvent {
|
|
|
173
175
|
// Stream Manager
|
|
174
176
|
// ============================================================================
|
|
175
177
|
|
|
178
|
+
export interface RateLimitSnapshot {
|
|
179
|
+
engine: EngineType;
|
|
180
|
+
accountId: number;
|
|
181
|
+
status: 'allowed_warning' | 'rejected';
|
|
182
|
+
utilization: number;
|
|
183
|
+
resetsAt: number | null;
|
|
184
|
+
receivedAt: string;
|
|
185
|
+
}
|
|
186
|
+
|
|
176
187
|
class StreamManager extends EventEmitter {
|
|
177
188
|
private activeStreams = new Map<string, StreamState>();
|
|
178
189
|
private sessionStreams = new Map<string, string>(); // composite key -> streamId
|
|
179
190
|
/** Guard against duplicate lifecycle events (e.g. if both inner and outer error paths fire) */
|
|
180
191
|
private lifecycleEmitted = new Set<string>();
|
|
192
|
+
/** Latest rate-limit snapshot per `${engine}:${accountId}`. Persists across refresh so the UI banner can rehydrate on join. */
|
|
193
|
+
private activeRateLimits = new Map<string, RateLimitSnapshot>();
|
|
194
|
+
|
|
195
|
+
private getAccountKey(engine: EngineType, accountId: number): string {
|
|
196
|
+
return `${engine}:${accountId}`;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
/** Return active rate limit for an account, purging it lazily if `resetsAt` has passed. */
|
|
200
|
+
getRateLimitForAccount(engine: EngineType, accountId: number): RateLimitSnapshot | null {
|
|
201
|
+
const key = this.getAccountKey(engine, accountId);
|
|
202
|
+
const snap = this.activeRateLimits.get(key);
|
|
203
|
+
if (!snap) return null;
|
|
204
|
+
if (snap.resetsAt && snap.resetsAt * 1000 < Date.now()) {
|
|
205
|
+
this.activeRateLimits.delete(key);
|
|
206
|
+
return null;
|
|
207
|
+
}
|
|
208
|
+
return snap;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/** Return every active rate-limit snapshot, lazily purging expired entries. */
|
|
212
|
+
getAllActiveRateLimits(): RateLimitSnapshot[] {
|
|
213
|
+
const now = Date.now();
|
|
214
|
+
const active: RateLimitSnapshot[] = [];
|
|
215
|
+
for (const [key, snap] of this.activeRateLimits) {
|
|
216
|
+
if (snap.resetsAt && snap.resetsAt * 1000 < now) {
|
|
217
|
+
this.activeRateLimits.delete(key);
|
|
218
|
+
continue;
|
|
219
|
+
}
|
|
220
|
+
active.push(snap);
|
|
221
|
+
}
|
|
222
|
+
return active;
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
/** Clear an active rate limit (called when the user dismisses the banner). */
|
|
226
|
+
dismissRateLimit(engine: EngineType, accountId: number): void {
|
|
227
|
+
this.activeRateLimits.delete(this.getAccountKey(engine, accountId));
|
|
228
|
+
}
|
|
181
229
|
|
|
182
230
|
constructor() {
|
|
183
231
|
super();
|
|
@@ -244,6 +292,7 @@ class StreamManager extends EventEmitter {
|
|
|
244
292
|
projectPath: request.projectPath,
|
|
245
293
|
processId,
|
|
246
294
|
engine: request.engine.type,
|
|
295
|
+
accountId: request.engine.account?.id || undefined,
|
|
247
296
|
status: 'active',
|
|
248
297
|
startedAt: new Date(),
|
|
249
298
|
messages: [],
|
|
@@ -651,19 +700,29 @@ class StreamManager extends EventEmitter {
|
|
|
651
700
|
// ── Rate Limit ─────────────────────────────────────────
|
|
652
701
|
case 'rate_limit': {
|
|
653
702
|
const rl = output as RateLimitEvent;
|
|
654
|
-
const
|
|
655
|
-
const
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
:
|
|
665
|
-
|
|
666
|
-
|
|
703
|
+
const accountId = streamState.accountId;
|
|
704
|
+
const nowIso = new Date().toISOString();
|
|
705
|
+
if (accountId) {
|
|
706
|
+
this.activeRateLimits.set(
|
|
707
|
+
this.getAccountKey(streamState.engine, accountId),
|
|
708
|
+
{
|
|
709
|
+
engine: streamState.engine,
|
|
710
|
+
accountId,
|
|
711
|
+
status: rl.status,
|
|
712
|
+
utilization: rl.utilization,
|
|
713
|
+
resetsAt: rl.resetsAt,
|
|
714
|
+
receivedAt: nowIso
|
|
715
|
+
}
|
|
716
|
+
);
|
|
717
|
+
}
|
|
718
|
+
this.emitStreamEvent(streamState, 'rate_limit', {
|
|
719
|
+
chatSessionId: streamState.chatSessionId,
|
|
720
|
+
engine: streamState.engine,
|
|
721
|
+
accountId: accountId ?? 0,
|
|
722
|
+
status: rl.status,
|
|
723
|
+
utilization: rl.utilization,
|
|
724
|
+
resetsAt: rl.resetsAt,
|
|
725
|
+
timestamp: nowIso
|
|
667
726
|
});
|
|
668
727
|
continue;
|
|
669
728
|
}
|
|
@@ -73,7 +73,9 @@ class ConnectionManager {
|
|
|
73
73
|
try {
|
|
74
74
|
await adapter.connect(conn, tunnel?.localPort);
|
|
75
75
|
} catch (err) {
|
|
76
|
-
if (tunnel) await tunnel.close().catch(() => {
|
|
76
|
+
if (tunnel) await tunnel.close().catch((err) => {
|
|
77
|
+
debug.warn('db-client', 'Failed to close SSH tunnel after adapter connect error:', err);
|
|
78
|
+
});
|
|
77
79
|
throw err;
|
|
78
80
|
}
|
|
79
81
|
|
|
@@ -164,8 +166,12 @@ class ConnectionManager {
|
|
|
164
166
|
error: err instanceof Error ? err.message : String(err)
|
|
165
167
|
};
|
|
166
168
|
} finally {
|
|
167
|
-
if (adapter) await adapter.close().catch(() => {
|
|
168
|
-
|
|
169
|
+
if (adapter) await adapter.close().catch((err) => {
|
|
170
|
+
debug.warn('db-client', 'Transient adapter close error during health test:', err);
|
|
171
|
+
});
|
|
172
|
+
if (tunnel) await tunnel.close().catch((err) => {
|
|
173
|
+
debug.warn('db-client', 'Transient tunnel close error during health test:', err);
|
|
174
|
+
});
|
|
169
175
|
}
|
|
170
176
|
}
|
|
171
177
|
|
|
@@ -28,7 +28,7 @@ export function handleStreamError(error: unknown): void {
|
|
|
28
28
|
}
|
|
29
29
|
|
|
30
30
|
if (error.message.includes('OPENAI_API_KEY') || error.message.includes('not authenticated')) {
|
|
31
|
-
throw new Error('Codex is not authenticated. Add an API key or sign in with ChatGPT in Settings → Engines.');
|
|
31
|
+
throw new Error('Codex is not authenticated. Add an OpenAI API key or sign in with ChatGPT in Settings → Engines → Codex.');
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
if (error.message.includes('insufficient_quota') || error.message.includes('quota')) {
|
|
@@ -36,7 +36,7 @@ export function handleStreamError(error: unknown): void {
|
|
|
36
36
|
}
|
|
37
37
|
|
|
38
38
|
if (error.message.includes('401') || error.message.toLowerCase().includes('unauthorized')) {
|
|
39
|
-
throw new Error('Codex authentication failed. Re-authenticate in Settings → Engines.');
|
|
39
|
+
throw new Error('Codex authentication failed. Re-authenticate in Settings → Engines → Codex.');
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
throw new Error(extractDetailedError(error));
|
|
@@ -76,12 +76,12 @@ export class CodexEngine implements AIEngine {
|
|
|
76
76
|
? engineQueries.getAccount(accountId)
|
|
77
77
|
: engineQueries.getActiveAccountForEngine('codex');
|
|
78
78
|
if (!account) {
|
|
79
|
-
throw new Error('
|
|
79
|
+
throw new Error('Codex is not configured. Add an OpenAI API key or sign in with ChatGPT in Settings → Engines → Codex.');
|
|
80
80
|
}
|
|
81
81
|
|
|
82
82
|
const credential = parseCodexCredential(account.credential);
|
|
83
83
|
if (!credential) {
|
|
84
|
-
throw new Error(`Codex account "${account.name}" has
|
|
84
|
+
throw new Error(`Codex account "${account.name}" has invalid credentials. Re-add it in Settings → Engines → Codex.`);
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
// For ChatGPT mode, ensure ~/.codex/auth.json reflects this account
|
|
@@ -117,7 +117,7 @@ export class CopilotEngine implements AIEngine {
|
|
|
117
117
|
? engineQueries.getAccount(accountId)
|
|
118
118
|
: engineQueries.getActiveAccountForEngine('copilot');
|
|
119
119
|
if (!account) {
|
|
120
|
-
throw new Error('
|
|
120
|
+
throw new Error('Copilot is not configured. Add a Personal Access Token in Settings → Engines → Copilot.');
|
|
121
121
|
}
|
|
122
122
|
|
|
123
123
|
this.client = new CopilotClient({
|
|
@@ -160,14 +160,11 @@ export class CopilotEngine implements AIEngine {
|
|
|
160
160
|
|
|
161
161
|
async getAvailableModels(): Promise<EngineModel[]> {
|
|
162
162
|
if (!this.client) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return [];
|
|
168
|
-
}
|
|
163
|
+
await this.initialize();
|
|
164
|
+
}
|
|
165
|
+
if (!this.client) {
|
|
166
|
+
throw new Error('Copilot client unavailable.');
|
|
169
167
|
}
|
|
170
|
-
if (!this.client) return [];
|
|
171
168
|
|
|
172
169
|
const result = await fetchCopilotModels(this.client, this.modelsCache);
|
|
173
170
|
this.modelsCache = result.cache;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Multi-provider preset metadata for OpenCode — fetched from
|
|
5
5
|
* `models.dev/api.json` and cached in the settings table. Drives the
|
|
6
|
-
* "Add Provider" picker in Settings → Engines →
|
|
6
|
+
* "Add Provider" picker in Settings → Engines → Open Code.
|
|
7
7
|
*
|
|
8
8
|
* This file mirrors `qwen/presets.ts` (the canonical name for multi-provider
|
|
9
9
|
* preset catalogs — see README §4.5). The runtime config builder that turns
|
|
@@ -90,7 +90,11 @@ export class OpenCodeEngine implements AIEngine {
|
|
|
90
90
|
|
|
91
91
|
async getAvailableModels(): Promise<EngineModel[]> {
|
|
92
92
|
const client = await ensureClient();
|
|
93
|
-
|
|
93
|
+
const models = await fetchOpenCodeModels(client);
|
|
94
|
+
if (models.length === 0) {
|
|
95
|
+
throw new Error('Open Code is not configured. Add a provider in Settings → Engines → Open Code.');
|
|
96
|
+
}
|
|
97
|
+
return models;
|
|
94
98
|
}
|
|
95
99
|
|
|
96
100
|
/**
|
|
@@ -107,8 +107,7 @@ export class QwenEngine implements AIEngine {
|
|
|
107
107
|
async getAvailableModels(): Promise<EngineModel[]> {
|
|
108
108
|
const env = getEngineEnv();
|
|
109
109
|
if (!env) {
|
|
110
|
-
|
|
111
|
-
return [];
|
|
110
|
+
throw new Error('Qwen Code is not configured. Add an API key in Settings → Engines → Qwen Code.');
|
|
112
111
|
}
|
|
113
112
|
const dynamic = await fetchQwenModels(env);
|
|
114
113
|
debug.log('engine', `Qwen getAvailableModels: ${dynamic.length} models from ${env.preset}`);
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { join, extname } from 'path';
|
|
2
|
+
import { existsSync } from 'fs';
|
|
2
3
|
|
|
3
4
|
import { debug } from '$shared/utils/logger';
|
|
4
5
|
|
|
@@ -367,6 +368,25 @@ export async function handleWindowsDrives(): Promise<PathBrowseData> {
|
|
|
367
368
|
});
|
|
368
369
|
}
|
|
369
370
|
|
|
371
|
+
if (drives.length === 0) {
|
|
372
|
+
for (let code = 65; code <= 90; code++) {
|
|
373
|
+
const drive = String.fromCharCode(code) + ':';
|
|
374
|
+
const drivePath = drive + '\\';
|
|
375
|
+
try {
|
|
376
|
+
if (existsSync(drivePath)) {
|
|
377
|
+
drives.push({
|
|
378
|
+
name: `${drive} Drive`,
|
|
379
|
+
type: 'directory',
|
|
380
|
+
path: drivePath,
|
|
381
|
+
modified: new Date().toISOString()
|
|
382
|
+
});
|
|
383
|
+
}
|
|
384
|
+
} catch {
|
|
385
|
+
// Skip unavailable drives.
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
|
|
370
390
|
// If no drives found, throw error
|
|
371
391
|
if (drives.length === 0) {
|
|
372
392
|
throw new Error('Unable to list drives');
|