@myrialabs/clopen 0.3.8 → 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 +66 -2
- package/backend/auth/session-cleanup.ts +58 -0
- package/backend/chat/stream-manager.ts +143 -13
- 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 +29 -1
- package/backend/database/queries/db-client-connection-queries.ts +160 -54
- package/backend/database/queries/engine-queries.ts +12 -0
- package/backend/database/queries/project-queries.ts +10 -5
- package/backend/db-client/connection-manager.ts +9 -3
- 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 +570 -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 +8 -114
- 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 +379 -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/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/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/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/README.md +128 -3
- package/backend/ws/access.ts +56 -0
- 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 +139 -22
- package/backend/ws/db-client/access.ts +19 -0
- package/backend/ws/db-client/connections.ts +31 -17
- package/backend/ws/db-client/io.ts +7 -9
- package/backend/ws/db-client/query.ts +86 -32
- package/backend/ws/db-client/schema.ts +9 -4
- package/backend/ws/db-client/structure.ts +22 -10
- 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/path-access.ts +101 -0
- package/backend/ws/files/read.ts +26 -11
- package/backend/ws/files/search.ts +10 -6
- package/backend/ws/files/state.ts +3 -0
- package/backend/ws/files/watch.ts +7 -1
- package/backend/ws/files/write.ts +109 -15
- 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/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 +7 -42
- 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 +15 -16
- package/backend/ws/projects/status.ts +5 -1
- package/backend/ws/sessions/crud.ts +31 -36
- 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 +13 -7
- package/backend/ws/terminal/session.ts +35 -14
- package/backend/ws/terminal/stream.ts +4 -1
- package/dist/assets/{index-DqAGCTFT.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 +5 -1
- package/shared/constants/engines.ts +45 -140
- package/shared/types/database/schema.ts +1 -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/ws-server.ts +14 -0
- package/dist/assets/main-DsED0rLr.js +0 -304
- package/dist/assets/main-eWY9R8g9.css +0 -1
|
@@ -6,13 +6,15 @@ import { t } from 'elysia';
|
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { connectionManager } from '../../db-client/connection-manager';
|
|
8
8
|
import { runSafely } from '../../db-client/query-executor';
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
9
|
+
import { dbClientQueryHistoryQueries } from '../../database/queries';
|
|
10
|
+
import { getDbClientPrincipal, requireDbClientConnectionAccess } from './access';
|
|
11
|
+
import { debug } from '$shared/utils/logger';
|
|
11
12
|
|
|
12
13
|
const HISTORY_KEEP_PER_CONNECTION = 200;
|
|
13
14
|
|
|
14
15
|
function recordHistory(input: {
|
|
15
16
|
connectionId: string;
|
|
17
|
+
userId: string | null;
|
|
16
18
|
query: string;
|
|
17
19
|
status: 'success' | 'error';
|
|
18
20
|
durationMs: number | null;
|
|
@@ -22,7 +24,7 @@ function recordHistory(input: {
|
|
|
22
24
|
try {
|
|
23
25
|
dbClientQueryHistoryQueries.insert({
|
|
24
26
|
connectionId: input.connectionId,
|
|
25
|
-
userId:
|
|
27
|
+
userId: input.userId,
|
|
26
28
|
query: input.query,
|
|
27
29
|
durationMs: input.durationMs,
|
|
28
30
|
rowCount: input.rowCount,
|
|
@@ -32,8 +34,9 @@ function recordHistory(input: {
|
|
|
32
34
|
if (Math.random() < 0.05) {
|
|
33
35
|
dbClientQueryHistoryQueries.prune(input.connectionId, HISTORY_KEEP_PER_CONNECTION);
|
|
34
36
|
}
|
|
35
|
-
} catch {
|
|
37
|
+
} catch (err) {
|
|
36
38
|
// history must never break query execution
|
|
39
|
+
debug.warn('db-client', 'Failed to record query history:', err);
|
|
37
40
|
}
|
|
38
41
|
}
|
|
39
42
|
|
|
@@ -47,19 +50,42 @@ export const queryHandler = createRouter()
|
|
|
47
50
|
limit: t.Optional(t.Number())
|
|
48
51
|
}),
|
|
49
52
|
response: t.Any()
|
|
50
|
-
}, async ({ data }) => {
|
|
51
|
-
const
|
|
52
|
-
|
|
53
|
+
}, async ({ data, conn }) => {
|
|
54
|
+
const { userId } = getDbClientPrincipal(conn);
|
|
55
|
+
const connection = requireDbClientConnectionAccess(conn, data.connectionId);
|
|
53
56
|
const adapter = await connectionManager.get(data.connectionId);
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
try {
|
|
58
|
+
const result = await runSafely({
|
|
59
|
+
driver: connection.driver,
|
|
60
|
+
adapter,
|
|
61
|
+
query: data.query,
|
|
62
|
+
params: data.params,
|
|
63
|
+
mode: 'read',
|
|
64
|
+
database: data.database,
|
|
65
|
+
limit: data.limit
|
|
66
|
+
});
|
|
67
|
+
recordHistory({
|
|
68
|
+
connectionId: data.connectionId,
|
|
69
|
+
userId,
|
|
70
|
+
query: data.query,
|
|
71
|
+
status: 'success',
|
|
72
|
+
durationMs: result.durationMs ?? null,
|
|
73
|
+
rowCount: result.rowCount ?? null,
|
|
74
|
+
error: null
|
|
75
|
+
});
|
|
76
|
+
return result;
|
|
77
|
+
} catch (error) {
|
|
78
|
+
recordHistory({
|
|
79
|
+
connectionId: data.connectionId,
|
|
80
|
+
userId,
|
|
81
|
+
query: data.query,
|
|
82
|
+
status: 'error',
|
|
83
|
+
durationMs: null,
|
|
84
|
+
rowCount: null,
|
|
85
|
+
error: error instanceof Error ? error.message : String(error)
|
|
86
|
+
});
|
|
87
|
+
throw error;
|
|
88
|
+
}
|
|
63
89
|
})
|
|
64
90
|
|
|
65
91
|
.http('db-client:execute-write', {
|
|
@@ -70,18 +96,41 @@ export const queryHandler = createRouter()
|
|
|
70
96
|
database: t.Optional(t.String())
|
|
71
97
|
}),
|
|
72
98
|
response: t.Any()
|
|
73
|
-
}, async ({ data }) => {
|
|
74
|
-
const
|
|
75
|
-
|
|
99
|
+
}, async ({ data, conn }) => {
|
|
100
|
+
const { userId } = getDbClientPrincipal(conn);
|
|
101
|
+
const connection = requireDbClientConnectionAccess(conn, data.connectionId);
|
|
76
102
|
const adapter = await connectionManager.get(data.connectionId);
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
103
|
+
try {
|
|
104
|
+
const result = await runSafely({
|
|
105
|
+
driver: connection.driver,
|
|
106
|
+
adapter,
|
|
107
|
+
query: data.query,
|
|
108
|
+
params: data.params,
|
|
109
|
+
mode: 'write',
|
|
110
|
+
database: data.database
|
|
111
|
+
});
|
|
112
|
+
recordHistory({
|
|
113
|
+
connectionId: data.connectionId,
|
|
114
|
+
userId,
|
|
115
|
+
query: data.query,
|
|
116
|
+
status: 'success',
|
|
117
|
+
durationMs: result.durationMs ?? null,
|
|
118
|
+
rowCount: result.rowCount ?? null,
|
|
119
|
+
error: null
|
|
120
|
+
});
|
|
121
|
+
return result;
|
|
122
|
+
} catch (error) {
|
|
123
|
+
recordHistory({
|
|
124
|
+
connectionId: data.connectionId,
|
|
125
|
+
userId,
|
|
126
|
+
query: data.query,
|
|
127
|
+
status: 'error',
|
|
128
|
+
durationMs: null,
|
|
129
|
+
rowCount: null,
|
|
130
|
+
error: error instanceof Error ? error.message : String(error)
|
|
131
|
+
});
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
85
134
|
})
|
|
86
135
|
|
|
87
136
|
.http('db-client:explain', {
|
|
@@ -91,7 +140,8 @@ export const queryHandler = createRouter()
|
|
|
91
140
|
database: t.Optional(t.String())
|
|
92
141
|
}),
|
|
93
142
|
response: t.Any()
|
|
94
|
-
}, async ({ data }) => {
|
|
143
|
+
}, async ({ data, conn }) => {
|
|
144
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
95
145
|
const adapter = await connectionManager.get(data.connectionId);
|
|
96
146
|
if (!adapter.explain) throw new Error('Driver does not support EXPLAIN');
|
|
97
147
|
return adapter.explain(data.query, { database: data.database });
|
|
@@ -100,7 +150,8 @@ export const queryHandler = createRouter()
|
|
|
100
150
|
.http('db-client:cancel', {
|
|
101
151
|
data: t.Object({ connectionId: t.String({ minLength: 1 }) }),
|
|
102
152
|
response: t.Object({ ok: t.Boolean() })
|
|
103
|
-
}, async ({ data }) => {
|
|
153
|
+
}, async ({ data, conn }) => {
|
|
154
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
104
155
|
const adapter = await connectionManager.get(data.connectionId);
|
|
105
156
|
if (adapter.cancel) await adapter.cancel();
|
|
106
157
|
return { ok: true };
|
|
@@ -115,7 +166,8 @@ export const queryHandler = createRouter()
|
|
|
115
166
|
row: t.Record(t.String(), t.Any())
|
|
116
167
|
}),
|
|
117
168
|
response: t.Any()
|
|
118
|
-
}, async ({ data }) => {
|
|
169
|
+
}, async ({ data, conn }) => {
|
|
170
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
119
171
|
const adapter = await connectionManager.get(data.connectionId);
|
|
120
172
|
if (!adapter.insertRow) throw new Error('Driver does not support insertRow');
|
|
121
173
|
return adapter.insertRow(data.table, data.row, {
|
|
@@ -134,7 +186,8 @@ export const queryHandler = createRouter()
|
|
|
134
186
|
changes: t.Record(t.String(), t.Any())
|
|
135
187
|
}),
|
|
136
188
|
response: t.Any()
|
|
137
|
-
}, async ({ data }) => {
|
|
189
|
+
}, async ({ data, conn }) => {
|
|
190
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
138
191
|
const adapter = await connectionManager.get(data.connectionId);
|
|
139
192
|
if (!adapter.updateRow) throw new Error('Driver does not support updateRow');
|
|
140
193
|
return adapter.updateRow(data.table, data.pk, data.changes, {
|
|
@@ -152,7 +205,8 @@ export const queryHandler = createRouter()
|
|
|
152
205
|
pks: t.Array(t.Record(t.String(), t.Any()))
|
|
153
206
|
}),
|
|
154
207
|
response: t.Any()
|
|
155
|
-
}, async ({ data }) => {
|
|
208
|
+
}, async ({ data, conn }) => {
|
|
209
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
156
210
|
const adapter = await connectionManager.get(data.connectionId);
|
|
157
211
|
if (!adapter.deleteRows) throw new Error('Driver does not support deleteRows');
|
|
158
212
|
return adapter.deleteRows(data.table, data.pks, {
|
|
@@ -6,6 +6,7 @@ import { t } from 'elysia';
|
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { connectionManager } from '../../db-client/connection-manager';
|
|
8
8
|
import type { DbClientSchemaNodeType } from '$shared/types/db-client';
|
|
9
|
+
import { requireDbClientConnectionAccess } from './access';
|
|
9
10
|
|
|
10
11
|
const nodeTypeSchema = t.Union([
|
|
11
12
|
t.Literal('database'),
|
|
@@ -22,7 +23,8 @@ export const schemaHandler = createRouter()
|
|
|
22
23
|
.http('db-client:list-databases', {
|
|
23
24
|
data: t.Object({ connectionId: t.String({ minLength: 1 }) }),
|
|
24
25
|
response: t.Array(t.Any())
|
|
25
|
-
}, async ({ data }) => {
|
|
26
|
+
}, async ({ data, conn }) => {
|
|
27
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
26
28
|
const adapter = await connectionManager.get(data.connectionId);
|
|
27
29
|
if (!adapter.listDatabases) return [];
|
|
28
30
|
return adapter.listDatabases();
|
|
@@ -34,7 +36,8 @@ export const schemaHandler = createRouter()
|
|
|
34
36
|
database: t.Optional(t.String())
|
|
35
37
|
}),
|
|
36
38
|
response: t.Array(t.Any())
|
|
37
|
-
}, async ({ data }) => {
|
|
39
|
+
}, async ({ data, conn }) => {
|
|
40
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
38
41
|
const adapter = await connectionManager.get(data.connectionId);
|
|
39
42
|
if (!adapter.listSchemas) return [];
|
|
40
43
|
return adapter.listSchemas(data.database);
|
|
@@ -47,7 +50,8 @@ export const schemaHandler = createRouter()
|
|
|
47
50
|
schema: t.Optional(t.String())
|
|
48
51
|
}),
|
|
49
52
|
response: t.Array(t.Any())
|
|
50
|
-
}, async ({ data }) => {
|
|
53
|
+
}, async ({ data, conn }) => {
|
|
54
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
51
55
|
const adapter = await connectionManager.get(data.connectionId);
|
|
52
56
|
if (!adapter.listObjects) return [];
|
|
53
57
|
return adapter.listObjects(data.database, data.schema);
|
|
@@ -62,7 +66,8 @@ export const schemaHandler = createRouter()
|
|
|
62
66
|
type: nodeTypeSchema
|
|
63
67
|
}),
|
|
64
68
|
response: t.Any()
|
|
65
|
-
}, async ({ data }) => {
|
|
69
|
+
}, async ({ data, conn }) => {
|
|
70
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
66
71
|
const adapter = await connectionManager.get(data.connectionId);
|
|
67
72
|
if (!adapter.getObjectDetails) {
|
|
68
73
|
throw new Error('Driver does not support object details');
|
|
@@ -6,6 +6,7 @@ import { t } from 'elysia';
|
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { connectionManager } from '../../db-client/connection-manager';
|
|
8
8
|
import type { AlterOperation, IndexDefinition, TableDefinition } from '../../db-client/drivers/types';
|
|
9
|
+
import { requireDbClientConnectionAccess } from './access';
|
|
9
10
|
|
|
10
11
|
const columnDefinitionSchema = t.Object({
|
|
11
12
|
name: t.String({ minLength: 1 }),
|
|
@@ -43,7 +44,8 @@ export const structureHandler = createRouter()
|
|
|
43
44
|
name: t.String({ minLength: 1 })
|
|
44
45
|
}),
|
|
45
46
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
46
|
-
}, async ({ data }) => {
|
|
47
|
+
}, async ({ data, conn }) => {
|
|
48
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
47
49
|
const adapter = await connectionManager.get(data.connectionId);
|
|
48
50
|
if (!adapter.createDatabase) throw new Error('Driver does not support database creation');
|
|
49
51
|
const ddl = await adapter.createDatabase(data.name);
|
|
@@ -58,7 +60,8 @@ export const structureHandler = createRouter()
|
|
|
58
60
|
definition: tableDefinitionSchema
|
|
59
61
|
}),
|
|
60
62
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
61
|
-
}, async ({ data }) => {
|
|
63
|
+
}, async ({ data, conn }) => {
|
|
64
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
62
65
|
const adapter = await connectionManager.get(data.connectionId);
|
|
63
66
|
if (!adapter.createTable) throw new Error('Driver does not support createTable');
|
|
64
67
|
const ddl = await adapter.createTable(data.definition as TableDefinition, {
|
|
@@ -77,7 +80,8 @@ export const structureHandler = createRouter()
|
|
|
77
80
|
operations: t.Array(alterOpSchema)
|
|
78
81
|
}),
|
|
79
82
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
80
|
-
}, async ({ data }) => {
|
|
83
|
+
}, async ({ data, conn }) => {
|
|
84
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
81
85
|
const adapter = await connectionManager.get(data.connectionId);
|
|
82
86
|
if (!adapter.alterTable) throw new Error('Driver does not support alterTable');
|
|
83
87
|
const ddl = await adapter.alterTable(data.name, data.operations as AlterOperation[], {
|
|
@@ -95,7 +99,8 @@ export const structureHandler = createRouter()
|
|
|
95
99
|
name: t.String({ minLength: 1 })
|
|
96
100
|
}),
|
|
97
101
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
98
|
-
}, async ({ data }) => {
|
|
102
|
+
}, async ({ data, conn }) => {
|
|
103
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
99
104
|
const adapter = await connectionManager.get(data.connectionId);
|
|
100
105
|
if (!adapter.dropTable) throw new Error('Driver does not support dropTable');
|
|
101
106
|
const ddl = await adapter.dropTable(data.name, {
|
|
@@ -113,7 +118,8 @@ export const structureHandler = createRouter()
|
|
|
113
118
|
name: t.String({ minLength: 1 })
|
|
114
119
|
}),
|
|
115
120
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
116
|
-
}, async ({ data }) => {
|
|
121
|
+
}, async ({ data, conn }) => {
|
|
122
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
117
123
|
const adapter = await connectionManager.get(data.connectionId);
|
|
118
124
|
if (!adapter.truncateTable) throw new Error('Driver does not support truncateTable');
|
|
119
125
|
const ddl = await adapter.truncateTable(data.name, {
|
|
@@ -132,7 +138,8 @@ export const structureHandler = createRouter()
|
|
|
132
138
|
newName: t.String({ minLength: 1 })
|
|
133
139
|
}),
|
|
134
140
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
135
|
-
}, async ({ data }) => {
|
|
141
|
+
}, async ({ data, conn }) => {
|
|
142
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
136
143
|
const adapter = await connectionManager.get(data.connectionId);
|
|
137
144
|
if (!adapter.renameTable) throw new Error('Driver does not support renameTable');
|
|
138
145
|
const ddl = await adapter.renameTable(data.name, data.newName, {
|
|
@@ -151,7 +158,8 @@ export const structureHandler = createRouter()
|
|
|
151
158
|
indexDef: indexDefinitionSchema
|
|
152
159
|
}),
|
|
153
160
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
154
|
-
}, async ({ data }) => {
|
|
161
|
+
}, async ({ data, conn }) => {
|
|
162
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
155
163
|
const adapter = await connectionManager.get(data.connectionId);
|
|
156
164
|
if (!adapter.createIndex) throw new Error('Driver does not support createIndex');
|
|
157
165
|
const ddl = await adapter.createIndex(data.tableName, data.indexDef as IndexDefinition, {
|
|
@@ -170,7 +178,8 @@ export const structureHandler = createRouter()
|
|
|
170
178
|
indexName: t.String({ minLength: 1 })
|
|
171
179
|
}),
|
|
172
180
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
173
|
-
}, async ({ data }) => {
|
|
181
|
+
}, async ({ data, conn }) => {
|
|
182
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
174
183
|
const adapter = await connectionManager.get(data.connectionId);
|
|
175
184
|
if (!adapter.dropIndex) throw new Error('Driver does not support dropIndex');
|
|
176
185
|
const ddl = await adapter.dropIndex(data.tableName, data.indexName, {
|
|
@@ -189,7 +198,8 @@ export const structureHandler = createRouter()
|
|
|
189
198
|
query: t.String({ minLength: 1 })
|
|
190
199
|
}),
|
|
191
200
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
192
|
-
}, async ({ data }) => {
|
|
201
|
+
}, async ({ data, conn }) => {
|
|
202
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
193
203
|
const adapter = await connectionManager.get(data.connectionId);
|
|
194
204
|
if (!adapter.createView) throw new Error('Driver does not support createView');
|
|
195
205
|
const ddl = await adapter.createView(data.name, data.query, {
|
|
@@ -207,7 +217,8 @@ export const structureHandler = createRouter()
|
|
|
207
217
|
name: t.String({ minLength: 1 })
|
|
208
218
|
}),
|
|
209
219
|
response: t.Object({ ok: t.Boolean(), ddl: t.String() })
|
|
210
|
-
}, async ({ data }) => {
|
|
220
|
+
}, async ({ data, conn }) => {
|
|
221
|
+
requireDbClientConnectionAccess(conn, data.connectionId);
|
|
211
222
|
const adapter = await connectionManager.get(data.connectionId);
|
|
212
223
|
if (!adapter.dropView) throw new Error('Driver does not support dropView');
|
|
213
224
|
const ddl = await adapter.dropView(data.name, {
|
|
@@ -216,3 +227,4 @@ export const structureHandler = createRouter()
|
|
|
216
227
|
});
|
|
217
228
|
return { ok: true, ddl };
|
|
218
229
|
});
|
|
230
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Engine access guards.
|
|
3
|
+
*
|
|
4
|
+
* Engine accounts (Claude, Codex, Copilot, Qwen, OpenCode) are global system
|
|
5
|
+
* credentials. Mutations are gated to admins at the router level via
|
|
6
|
+
* `ADMIN_ONLY_ROUTES`. This file covers the leftover concern: setup-flow
|
|
7
|
+
* PTY sessions belong to the admin who started them, so other admins cannot
|
|
8
|
+
* submit codes or cancel into someone else's flow.
|
|
9
|
+
*
|
|
10
|
+
* Each engine keeps its own `Map<setupId, SetupProcess>` (Claude, Codex, …).
|
|
11
|
+
* The shape varies, but every entry tracks `userId` + a `disposed` flag, so
|
|
12
|
+
* we type the helper against that minimal contract.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
import type { WSConnection } from '$shared/utils/ws-server';
|
|
16
|
+
import { ws } from '$backend/utils/ws';
|
|
17
|
+
|
|
18
|
+
export interface SetupProcessLike {
|
|
19
|
+
userId: string;
|
|
20
|
+
disposed: boolean;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Resolve a setup-flow session and verify the caller owns it. Throws with the
|
|
25
|
+
* same generic error for "missing", "expired", and "owned by another user" so
|
|
26
|
+
* we don't leak existence of another admin's setup.
|
|
27
|
+
*/
|
|
28
|
+
export function requireSetupSessionAccess<T extends SetupProcessLike>(
|
|
29
|
+
conn: WSConnection,
|
|
30
|
+
setupId: string,
|
|
31
|
+
setupProcesses: Map<string, T>
|
|
32
|
+
): T {
|
|
33
|
+
const userId = ws.getUserId(conn);
|
|
34
|
+
const entry = setupProcesses.get(setupId);
|
|
35
|
+
if (!entry || entry.disposed || entry.userId !== userId) {
|
|
36
|
+
throw new Error('Setup session not found or expired');
|
|
37
|
+
}
|
|
38
|
+
return entry;
|
|
39
|
+
}
|
|
@@ -22,6 +22,7 @@ import { resetEnvironment, getClaudeUserConfigDir } from '../../../engine/adapte
|
|
|
22
22
|
import { resolveBinaryWithRefresh } from '../../../utils/cli';
|
|
23
23
|
import { debug } from '$shared/utils/logger';
|
|
24
24
|
import { getCleanSpawnEnv } from '../../../utils/env';
|
|
25
|
+
import { requireSetupSessionAccess } from '../access';
|
|
25
26
|
|
|
26
27
|
// ── Helpers ──
|
|
27
28
|
|
|
@@ -95,7 +96,7 @@ interface SetupProcess {
|
|
|
95
96
|
const setupProcesses = new Map<string, SetupProcess>();
|
|
96
97
|
const userSetups = new Map<string, string>();
|
|
97
98
|
|
|
98
|
-
const SETUP_TIMEOUT_MS =
|
|
99
|
+
const SETUP_TIMEOUT_MS = 15 * 60 * 1000;
|
|
99
100
|
|
|
100
101
|
function cleanupSetup(setupId: string): void {
|
|
101
102
|
const entry = setupProcesses.get(setupId);
|
|
@@ -210,12 +211,12 @@ export const accountsHandler = createRouter()
|
|
|
210
211
|
return;
|
|
211
212
|
}
|
|
212
213
|
|
|
213
|
-
//
|
|
214
|
+
// 15-minute timeout — matches the OAuth code expiry window shown in the UI
|
|
214
215
|
const timer = setTimeout(() => {
|
|
215
216
|
debug.warn('engine', `[${setupId}] Setup-token timeout`);
|
|
216
217
|
ws.emit.user(userId, 'engine:claude-account-setup-error', {
|
|
217
218
|
setupId,
|
|
218
|
-
message: 'Setup timed out after
|
|
219
|
+
message: 'Setup timed out after 15 minutes'
|
|
219
220
|
});
|
|
220
221
|
cleanupSetup(setupId);
|
|
221
222
|
}, SETUP_TIMEOUT_MS);
|
|
@@ -353,9 +354,10 @@ export const accountsHandler = createRouter()
|
|
|
353
354
|
})
|
|
354
355
|
}, async ({ data, conn }) => {
|
|
355
356
|
const userId = ws.getUserId(conn);
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
357
|
+
let entry: SetupProcess;
|
|
358
|
+
try {
|
|
359
|
+
entry = requireSetupSessionAccess(conn, data.setupId, setupProcesses);
|
|
360
|
+
} catch {
|
|
359
361
|
ws.emit.user(userId, 'engine:claude-account-setup-error', {
|
|
360
362
|
setupId: data.setupId,
|
|
361
363
|
message: 'Setup session not found or expired'
|
|
@@ -385,11 +387,14 @@ export const accountsHandler = createRouter()
|
|
|
385
387
|
data: t.Object({
|
|
386
388
|
setupId: t.String()
|
|
387
389
|
})
|
|
388
|
-
}, async ({ data }) => {
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
390
|
+
}, async ({ data, conn }) => {
|
|
391
|
+
try {
|
|
392
|
+
requireSetupSessionAccess(conn, data.setupId, setupProcesses);
|
|
393
|
+
} catch {
|
|
394
|
+
return;
|
|
392
395
|
}
|
|
396
|
+
debug.log('engine', `[${data.setupId}] Setup cancelled by user`);
|
|
397
|
+
cleanupSetup(data.setupId);
|
|
393
398
|
})
|
|
394
399
|
|
|
395
400
|
// ═══════════════════════════════════════
|