@myrialabs/clopen 0.3.7 → 0.3.9
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/backend/auth/permissions.ts +41 -2
- package/backend/chat/stream-manager.ts +71 -0
- package/backend/database/migrations/030_add_files_panel_state_to_user_projects.ts +34 -0
- package/backend/database/migrations/031_create_db_client_tables.ts +74 -0
- package/backend/database/migrations/032_seed_copilot_provider.ts +19 -0
- package/backend/database/migrations/033_seed_codex_provider.ts +19 -0
- package/backend/database/migrations/034_seed_qwen_provider.ts +119 -0
- package/backend/database/migrations/035_add_owner_to_db_client_connections.ts +34 -0
- package/backend/database/migrations/index.ts +43 -1
- package/backend/database/queries/db-client-connection-queries.ts +343 -0
- package/backend/database/queries/db-client-query-history-queries.ts +113 -0
- package/backend/database/queries/engine-queries.ts +12 -0
- package/backend/database/queries/index.ts +3 -1
- package/backend/database/queries/project-queries.ts +28 -0
- package/backend/db-client/connection-manager.ts +257 -0
- package/backend/db-client/drivers/bun-sql-helpers.ts +41 -0
- package/backend/db-client/drivers/mongodb.ts +358 -0
- package/backend/db-client/drivers/mysql.ts +385 -0
- package/backend/db-client/drivers/postgres.ts +446 -0
- package/backend/db-client/drivers/redis.ts +267 -0
- package/backend/db-client/drivers/sql-builders.ts +215 -0
- package/backend/db-client/drivers/sqlite.ts +346 -0
- package/backend/db-client/drivers/types.ts +92 -0
- package/backend/db-client/query-executor.ts +126 -0
- package/backend/db-client/ssh-tunnel.ts +122 -0
- package/backend/engine/README.md +1702 -0
- package/backend/engine/adapters/claude/models.ts +141 -0
- package/backend/engine/adapters/claude/stream.ts +1 -1
- package/backend/engine/adapters/codex/credential.ts +179 -0
- package/backend/engine/adapters/codex/error-handler.ts +65 -0
- package/backend/engine/adapters/codex/index.ts +1 -0
- package/backend/engine/adapters/codex/message-converter.ts +646 -0
- package/backend/engine/adapters/codex/models.ts +105 -0
- package/backend/engine/adapters/codex/patch-rollout.ts +169 -0
- package/backend/engine/adapters/codex/session-fork.ts +149 -0
- package/backend/engine/adapters/codex/stream.ts +310 -0
- package/backend/engine/adapters/codex/usage-rollout.ts +145 -0
- package/backend/engine/adapters/copilot/error-handler.ts +94 -0
- package/backend/engine/adapters/copilot/index.ts +1 -0
- package/backend/engine/adapters/copilot/message-converter.ts +973 -0
- package/backend/engine/adapters/copilot/models.ts +92 -0
- package/backend/engine/adapters/copilot/session-fork.ts +111 -0
- package/backend/engine/adapters/copilot/stream.ts +573 -0
- package/backend/engine/adapters/opencode/config.ts +56 -104
- package/backend/engine/adapters/opencode/error-handler.ts +71 -0
- package/backend/engine/adapters/opencode/models.ts +79 -0
- package/backend/engine/adapters/opencode/presets.ts +91 -0
- package/backend/engine/adapters/opencode/stream.ts +5 -115
- package/backend/engine/adapters/qwen/credential.ts +78 -0
- package/backend/engine/adapters/qwen/environment.ts +84 -0
- package/backend/engine/adapters/qwen/error-handler.ts +71 -0
- package/backend/engine/adapters/qwen/index.ts +1 -0
- package/backend/engine/adapters/qwen/message-converter.ts +1055 -0
- package/backend/engine/adapters/qwen/models.ts +81 -0
- package/backend/engine/adapters/qwen/presets.ts +51 -0
- package/backend/engine/adapters/qwen/session-fork.ts +97 -0
- package/backend/engine/adapters/qwen/stream.ts +380 -0
- package/backend/engine/index.ts +35 -0
- package/backend/engine/install-recipes.ts +80 -1
- package/backend/engine/install-runner.ts +4 -0
- package/backend/git/git-service.ts +12 -0
- package/backend/mcp/README.md +84 -14
- package/backend/mcp/config.ts +218 -17
- package/backend/mcp/index.ts +2 -0
- package/backend/mcp/project-context.ts +55 -0
- package/backend/mcp/servers/browser-automation/actions.ts +6 -1
- package/backend/mcp/servers/helper.ts +13 -0
- package/backend/middleware/error-handler.ts +16 -2
- package/backend/preview/browser/browser-preview-service.ts +4 -4
- package/backend/preview/browser/scripts/video-stream.ts +9 -3
- package/backend/ws/README.md +128 -3
- package/backend/ws/access.ts +56 -0
- package/backend/ws/chat/stream.ts +36 -12
- package/backend/ws/db-client/access.ts +19 -0
- package/backend/ws/db-client/connections.ts +194 -0
- package/backend/ws/db-client/index.ts +17 -0
- package/backend/ws/db-client/io.ts +456 -0
- package/backend/ws/db-client/query.ts +214 -0
- package/backend/ws/db-client/schema.ts +81 -0
- package/backend/ws/db-client/structure.ts +230 -0
- package/backend/ws/engine/access.ts +39 -0
- package/backend/ws/engine/claude/accounts.ts +15 -10
- package/backend/ws/engine/codex/accounts.ts +516 -0
- package/backend/ws/engine/codex/index.ts +14 -0
- package/backend/ws/engine/codex/status.ts +87 -0
- package/backend/ws/engine/copilot/accounts.ts +122 -0
- package/backend/ws/engine/copilot/index.ts +13 -0
- package/backend/ws/engine/copilot/status.ts +54 -0
- package/backend/ws/engine/index.ts +7 -1
- package/backend/ws/engine/opencode/providers.ts +1 -1
- package/backend/ws/engine/qwen/accounts.ts +137 -0
- package/backend/ws/engine/qwen/index.ts +15 -0
- package/backend/ws/engine/qwen/presets.ts +40 -0
- package/backend/ws/engine/qwen/status.ts +54 -0
- package/backend/ws/files/index.ts +5 -1
- package/backend/ws/files/read.ts +34 -0
- package/backend/ws/files/state.ts +42 -0
- package/backend/ws/files/watch.ts +7 -1
- package/backend/ws/git/branch.ts +13 -19
- package/backend/ws/git/commit-message.ts +3 -4
- package/backend/ws/git/commit.ts +5 -7
- package/backend/ws/git/conflict.ts +7 -10
- package/backend/ws/git/diff.ts +7 -10
- package/backend/ws/git/log.ts +3 -4
- package/backend/ws/git/remote.ts +30 -43
- package/backend/ws/git/staging.ts +13 -19
- package/backend/ws/git/status.ts +7 -11
- package/backend/ws/index.ts +5 -1
- package/backend/ws/messages/crud.ts +7 -13
- package/backend/ws/preview/access.ts +45 -0
- package/backend/ws/preview/browser/cleanup.ts +3 -11
- package/backend/ws/preview/browser/console.ts +5 -40
- package/backend/ws/preview/browser/interact.ts +2 -6
- package/backend/ws/preview/browser/native-ui.ts +5 -18
- package/backend/ws/preview/browser/stats.ts +2 -12
- package/backend/ws/preview/browser/tab-info.ts +4 -20
- package/backend/ws/preview/browser/tab.ts +4 -27
- package/backend/ws/preview/browser/webcodecs.ts +6 -47
- package/backend/ws/projects/crud.ts +4 -10
- package/backend/ws/projects/status.ts +2 -0
- package/backend/ws/sessions/crud.ts +22 -33
- package/backend/ws/settings/crud.ts +13 -13
- package/backend/ws/snapshot/restore.ts +5 -2
- package/backend/ws/snapshot/timeline.ts +3 -1
- package/backend/ws/system-tools/access.ts +28 -0
- package/backend/ws/system-tools/install.ts +13 -4
- package/backend/ws/system-tools/status.ts +5 -2
- package/backend/ws/terminal/access.ts +56 -0
- package/backend/ws/terminal/persistence.ts +12 -6
- package/backend/ws/terminal/session.ts +35 -14
- package/backend/ws/terminal/stream.ts +4 -1
- package/dist/assets/{index-C86jwBxR.js → index-D8V2wj9B.js} +2 -2
- package/dist/assets/{main-DhLx8wD1.js → main-C9nYVmnw.js} +222 -195
- package/dist/assets/main-hspyFOoK.css +1 -0
- package/dist/index.html +2 -2
- package/package.json +7 -1
- package/shared/constants/engines.ts +45 -140
- package/shared/types/database/schema.ts +49 -1
- package/shared/types/db-client/connection.ts +60 -0
- package/shared/types/db-client/index.ts +6 -0
- package/shared/types/db-client/query.ts +77 -0
- package/shared/types/unified/common.ts +1 -1
- package/shared/types/unified/engine.ts +29 -1
- package/shared/types/unified/index.ts +2 -0
- package/shared/types/unified/message.ts +1 -1
- package/shared/types/unified/tool.ts +17 -2
- package/shared/utils/logger.ts +1 -0
- package/shared/utils/ws-server.ts +14 -0
- package/dist/assets/main-jTnmAoXS.css +0 -1
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Environment configuration for the Qwen Code engine.
|
|
3
|
+
*
|
|
4
|
+
* Builds an env dictionary to pass via the SDK's `env` option (the SDK
|
|
5
|
+
* forwards it into the spawned `qwen` subprocess). We intentionally do NOT
|
|
6
|
+
* mutate `process.env` — multiple projects can stream concurrently.
|
|
7
|
+
*
|
|
8
|
+
* Auth model: paste-token, per-account.
|
|
9
|
+
* `engine_accounts.credential` carries a JSON blob (see ./credential.ts):
|
|
10
|
+
* `{ apiKey, preset }`. The chosen preset (DashScope CN/INTL, OpenRouter,
|
|
11
|
+
* Fireworks) decides the base URL — there's no per-account override.
|
|
12
|
+
*
|
|
13
|
+
* `qwen-oauth` (the CLI's browser sign-in flow that writes `~/.qwen/`) is
|
|
14
|
+
* intentionally not wired into the SDK path: the SDK README states it isn't
|
|
15
|
+
* recommended because credentials need periodic refresh, and Alibaba
|
|
16
|
+
* deprecated the free-tier OAuth in April 2026.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import { engineQueries } from '$backend/database/queries/engine-queries';
|
|
20
|
+
import type { EngineAccount } from '$backend/database/queries/engine-queries';
|
|
21
|
+
import { getCleanSpawnEnv } from '$backend/utils/index.js';
|
|
22
|
+
import { debug } from '$shared/utils/logger';
|
|
23
|
+
import { parseQwenCredential, resolveQwenBaseUrl } from './credential';
|
|
24
|
+
|
|
25
|
+
export interface QwenEnvResolution {
|
|
26
|
+
env: Record<string, string>;
|
|
27
|
+
accountName: string;
|
|
28
|
+
preset: string;
|
|
29
|
+
baseUrl: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Build the env dictionary to forward to the Qwen Code subprocess.
|
|
34
|
+
*
|
|
35
|
+
* When `accountId` is provided, that specific account's credential is used;
|
|
36
|
+
* otherwise the active account for the engine is read from the DB.
|
|
37
|
+
*
|
|
38
|
+
* Returns `null` when no account is available or the API key is empty —
|
|
39
|
+
* caller should surface a friendly error rather than spawning the CLI with
|
|
40
|
+
* bad/empty credentials.
|
|
41
|
+
*/
|
|
42
|
+
export function getEngineEnv(accountId?: number): QwenEnvResolution | null {
|
|
43
|
+
const env = getCleanSpawnEnv();
|
|
44
|
+
|
|
45
|
+
let account: EngineAccount | null;
|
|
46
|
+
if (accountId !== undefined) {
|
|
47
|
+
account = engineQueries.getAccount(accountId);
|
|
48
|
+
} else {
|
|
49
|
+
account = engineQueries.getActiveAccountForEngine('qwen');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (!account) {
|
|
53
|
+
debug.warn('engine', 'Qwen Code: no active account configured');
|
|
54
|
+
return null;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const credential = parseQwenCredential(account.credential);
|
|
58
|
+
if (!credential.apiKey) {
|
|
59
|
+
debug.warn('engine', `Qwen Code: account "${account.name}" has no API key`);
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
const baseUrl = resolveQwenBaseUrl(credential);
|
|
64
|
+
if (!baseUrl) {
|
|
65
|
+
debug.warn('engine', `Qwen Code: account "${account.name}" uses preset "${credential.preset}" but has no base URL configured`);
|
|
66
|
+
return null;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
env['OPENAI_API_KEY'] = credential.apiKey;
|
|
70
|
+
env['OPENAI_BASE_URL'] = baseUrl;
|
|
71
|
+
// Strip any inherited Qwen OAuth hints — if the host shell exports them
|
|
72
|
+
// the bundled CLI prefers the OAuth path even when API-key env vars are
|
|
73
|
+
// present, surfacing the "OAuth free tier discontinued" error.
|
|
74
|
+
delete env['QWEN_OAUTH_TOKEN'];
|
|
75
|
+
delete env['QWEN_AUTH_TYPE'];
|
|
76
|
+
|
|
77
|
+
debug.log('engine', `Qwen Code: using account "${account.name}" (preset ${credential.preset})`);
|
|
78
|
+
return {
|
|
79
|
+
env,
|
|
80
|
+
accountName: account.name,
|
|
81
|
+
preset: credential.preset,
|
|
82
|
+
baseUrl,
|
|
83
|
+
};
|
|
84
|
+
}
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Qwen Code SDK error handler.
|
|
3
|
+
*
|
|
4
|
+
* Mirrors the Claude/Codex pattern: swallow abort errors, normalise the
|
|
5
|
+
* common categories (missing CLI, missing API key, quota, auth) and otherwise
|
|
6
|
+
* surface a sanitised message.
|
|
7
|
+
*
|
|
8
|
+
* The SDK reports CLI subprocess failures as a generic
|
|
9
|
+
* `CLI process exited with code N` Error — without the CLI's stderr the
|
|
10
|
+
* underlying cause is invisible. The adapter buffers the last few stderr
|
|
11
|
+
* lines and feeds them in via `stderrTail` so the user-facing message
|
|
12
|
+
* carries something actionable.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
export function handleStreamError(error: unknown, stderrTail?: string): void {
|
|
16
|
+
if (!(error instanceof Error)) {
|
|
17
|
+
throw error;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
if (
|
|
21
|
+
error.name === 'AbortError'
|
|
22
|
+
|| error.message.includes('aborted')
|
|
23
|
+
|| error.message.includes('abort')
|
|
24
|
+
|| error.message === 'Operation aborted'
|
|
25
|
+
) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const tail = (stderrTail ?? '').trim();
|
|
30
|
+
const tailLower = tail.toLowerCase();
|
|
31
|
+
|
|
32
|
+
if (error.message.includes('ENOENT') || error.message.includes('spawn qwen')) {
|
|
33
|
+
throw new Error('Qwen Code CLI not found. Install it via Settings → System Tools (or `bun add -g @qwen-code/qwen-code`).');
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
if (
|
|
37
|
+
error.message.includes('OPENAI_API_KEY')
|
|
38
|
+
|| error.message.includes('not authenticated')
|
|
39
|
+
|| error.message.includes('401')
|
|
40
|
+
|| tailLower.includes('invalid api key')
|
|
41
|
+
|| tailLower.includes('unauthorized')
|
|
42
|
+
) {
|
|
43
|
+
throw new Error('Qwen Code is not authenticated. Check the API key and base URL in Settings → Engines → Qwen Code.');
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
if (error.message.includes('insufficient_quota') || error.message.includes('quota') || tailLower.includes('insufficient_quota')) {
|
|
47
|
+
throw new Error('Qwen Code quota exceeded. Check your API balance or switch account.');
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (tailLower.includes('model not found') || tailLower.includes('does not exist') || tailLower.includes('unsupported model')) {
|
|
51
|
+
throw new Error(`Qwen Code endpoint rejected the selected model. Pick a model supported by your provider.${tail ? `\n\nCLI: ${tail}` : ''}`);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
throw new Error(buildDetailedError(error, tail));
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function buildDetailedError(error: Error, stderrTail: string): string {
|
|
58
|
+
const err = error as unknown as Record<string, unknown>;
|
|
59
|
+
let message = (typeof err.message === 'string' ? err.message : '').replace(/^Error:\s*/, '');
|
|
60
|
+
if (!message) {
|
|
61
|
+
message = typeof err.name === 'string' && err.name !== 'Error' ? err.name : 'Unknown error';
|
|
62
|
+
}
|
|
63
|
+
if (err.status && !message.includes(String(err.status))) {
|
|
64
|
+
message += ` (status ${String(err.status)})`;
|
|
65
|
+
}
|
|
66
|
+
const base = message || error.message || 'Unknown error';
|
|
67
|
+
if (stderrTail && !base.includes(stderrTail)) {
|
|
68
|
+
return `${base}\n\nCLI: ${stderrTail}`;
|
|
69
|
+
}
|
|
70
|
+
return base;
|
|
71
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { QwenEngine } from './stream';
|