@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
|
@@ -7,11 +7,11 @@
|
|
|
7
7
|
import { t } from 'elysia';
|
|
8
8
|
import { createRouter } from '$shared/utils/ws-server';
|
|
9
9
|
import { execGit } from '../../git/git-executor';
|
|
10
|
-
import { projectQueries } from '../../database/queries/project-queries';
|
|
11
10
|
import { initializeEngine } from '../../engine';
|
|
12
11
|
import type { EngineType } from '$shared/types/unified';
|
|
13
12
|
import type { GeneratedCommitMessage } from '$shared/types/git';
|
|
14
13
|
import { debug } from '$shared/utils/logger';
|
|
14
|
+
import { requireProjectAccess } from '../access';
|
|
15
15
|
|
|
16
16
|
const COMMIT_MESSAGE_SCHEMA = {
|
|
17
17
|
type: 'object',
|
|
@@ -49,9 +49,8 @@ export const commitMessageHandler = createRouter()
|
|
|
49
49
|
response: t.Object({
|
|
50
50
|
message: t.String()
|
|
51
51
|
})
|
|
52
|
-
}, async ({ data }) => {
|
|
53
|
-
const project =
|
|
54
|
-
if (!project) throw new Error('Project not found');
|
|
52
|
+
}, async ({ data, conn }) => {
|
|
53
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
55
54
|
|
|
56
55
|
// Get raw staged diff text
|
|
57
56
|
const diffResult = await execGit(['diff', '--cached'], project.path);
|
package/backend/ws/git/commit.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { gitService } from '../../git/git-service';
|
|
8
|
-
import {
|
|
8
|
+
import { requireProjectAccess } from '../access';
|
|
9
9
|
|
|
10
10
|
export const commitHandler = createRouter()
|
|
11
11
|
.http('git:commit', {
|
|
@@ -16,9 +16,8 @@ export const commitHandler = createRouter()
|
|
|
16
16
|
response: t.Object({
|
|
17
17
|
hash: t.String()
|
|
18
18
|
})
|
|
19
|
-
}, async ({ data }) => {
|
|
20
|
-
const project =
|
|
21
|
-
if (!project) throw new Error('Project not found');
|
|
19
|
+
}, async ({ data, conn }) => {
|
|
20
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
22
21
|
const hash = await gitService.commit(project.path, data.message);
|
|
23
22
|
return { hash };
|
|
24
23
|
})
|
|
@@ -31,9 +30,8 @@ export const commitHandler = createRouter()
|
|
|
31
30
|
response: t.Object({
|
|
32
31
|
hash: t.String()
|
|
33
32
|
})
|
|
34
|
-
}, async ({ data }) => {
|
|
35
|
-
const project =
|
|
36
|
-
if (!project) throw new Error('Project not found');
|
|
33
|
+
}, async ({ data, conn }) => {
|
|
34
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
37
35
|
const hash = await gitService.amendCommit(project.path, data.message);
|
|
38
36
|
return { hash };
|
|
39
37
|
});
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { gitService } from '../../git/git-service';
|
|
8
|
-
import {
|
|
8
|
+
import { requireProjectAccess } from '../access';
|
|
9
9
|
|
|
10
10
|
const ConflictMarkerSchema = t.Object({
|
|
11
11
|
ourStart: t.Number(),
|
|
@@ -29,9 +29,8 @@ export const conflictHandler = createRouter()
|
|
|
29
29
|
content: t.String(),
|
|
30
30
|
markers: t.Array(ConflictMarkerSchema)
|
|
31
31
|
}))
|
|
32
|
-
}, async ({ data }) => {
|
|
33
|
-
const project =
|
|
34
|
-
if (!project) throw new Error('Project not found');
|
|
32
|
+
}, async ({ data, conn }) => {
|
|
33
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
35
34
|
return await gitService.getConflictFiles(project.path);
|
|
36
35
|
})
|
|
37
36
|
|
|
@@ -43,9 +42,8 @@ export const conflictHandler = createRouter()
|
|
|
43
42
|
customContent: t.Optional(t.String())
|
|
44
43
|
}),
|
|
45
44
|
response: t.Object({ ok: t.Boolean() })
|
|
46
|
-
}, async ({ data }) => {
|
|
47
|
-
const project =
|
|
48
|
-
if (!project) throw new Error('Project not found');
|
|
45
|
+
}, async ({ data, conn }) => {
|
|
46
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
49
47
|
await gitService.resolveConflict(
|
|
50
48
|
project.path,
|
|
51
49
|
data.filePath,
|
|
@@ -60,9 +58,8 @@ export const conflictHandler = createRouter()
|
|
|
60
58
|
projectId: t.String()
|
|
61
59
|
}),
|
|
62
60
|
response: t.Object({ ok: t.Boolean() })
|
|
63
|
-
}, async ({ data }) => {
|
|
64
|
-
const project =
|
|
65
|
-
if (!project) throw new Error('Project not found');
|
|
61
|
+
}, async ({ data, conn }) => {
|
|
62
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
66
63
|
await gitService.abortMerge(project.path);
|
|
67
64
|
return { ok: true };
|
|
68
65
|
});
|
package/backend/ws/git/diff.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { gitService } from '../../git/git-service';
|
|
8
|
-
import {
|
|
8
|
+
import { requireProjectAccess } from '../access';
|
|
9
9
|
|
|
10
10
|
const DiffHunkLineSchema = t.Object({
|
|
11
11
|
type: t.Union([t.Literal('add'), t.Literal('delete'), t.Literal('context'), t.Literal('header')]),
|
|
@@ -38,9 +38,8 @@ export const diffHandler = createRouter()
|
|
|
38
38
|
filePath: t.Optional(t.String())
|
|
39
39
|
}),
|
|
40
40
|
response: t.Array(FileDiffSchema)
|
|
41
|
-
}, async ({ data }) => {
|
|
42
|
-
const project =
|
|
43
|
-
if (!project) throw new Error('Project not found');
|
|
41
|
+
}, async ({ data, conn }) => {
|
|
42
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
44
43
|
return await gitService.getDiffUnstaged(project.path, data.filePath);
|
|
45
44
|
})
|
|
46
45
|
|
|
@@ -50,9 +49,8 @@ export const diffHandler = createRouter()
|
|
|
50
49
|
filePath: t.Optional(t.String())
|
|
51
50
|
}),
|
|
52
51
|
response: t.Array(FileDiffSchema)
|
|
53
|
-
}, async ({ data }) => {
|
|
54
|
-
const project =
|
|
55
|
-
if (!project) throw new Error('Project not found');
|
|
52
|
+
}, async ({ data, conn }) => {
|
|
53
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
56
54
|
return await gitService.getDiffStaged(project.path, data.filePath);
|
|
57
55
|
})
|
|
58
56
|
|
|
@@ -62,8 +60,7 @@ export const diffHandler = createRouter()
|
|
|
62
60
|
commitHash: t.String()
|
|
63
61
|
}),
|
|
64
62
|
response: t.Array(FileDiffSchema)
|
|
65
|
-
}, async ({ data }) => {
|
|
66
|
-
const project =
|
|
67
|
-
if (!project) throw new Error('Project not found');
|
|
63
|
+
}, async ({ data, conn }) => {
|
|
64
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
68
65
|
return await gitService.getDiffCommit(project.path, data.commitHash);
|
|
69
66
|
});
|
package/backend/ws/git/log.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { gitService } from '../../git/git-service';
|
|
8
|
-
import {
|
|
8
|
+
import { requireProjectAccess } from '../access';
|
|
9
9
|
|
|
10
10
|
export const logHandler = createRouter()
|
|
11
11
|
.http('git:log', {
|
|
@@ -29,9 +29,8 @@ export const logHandler = createRouter()
|
|
|
29
29
|
total: t.Number(),
|
|
30
30
|
hasMore: t.Boolean()
|
|
31
31
|
})
|
|
32
|
-
}, async ({ data }) => {
|
|
33
|
-
const project =
|
|
34
|
-
if (!project) throw new Error('Project not found');
|
|
32
|
+
}, async ({ data, conn }) => {
|
|
33
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
35
34
|
return await gitService.getLog(
|
|
36
35
|
project.path,
|
|
37
36
|
data.limit ?? 50,
|
package/backend/ws/git/remote.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { gitService } from '../../git/git-service';
|
|
8
|
-
import {
|
|
8
|
+
import { requireProjectAccess } from '../access';
|
|
9
9
|
|
|
10
10
|
export const remoteHandler = createRouter()
|
|
11
11
|
.http('git:remotes', {
|
|
@@ -17,9 +17,8 @@ export const remoteHandler = createRouter()
|
|
|
17
17
|
fetchUrl: t.String(),
|
|
18
18
|
pushUrl: t.String()
|
|
19
19
|
}))
|
|
20
|
-
}, async ({ data }) => {
|
|
21
|
-
const project =
|
|
22
|
-
if (!project) throw new Error('Project not found');
|
|
20
|
+
}, async ({ data, conn }) => {
|
|
21
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
23
22
|
return await gitService.getRemotes(project.path);
|
|
24
23
|
})
|
|
25
24
|
|
|
@@ -31,9 +30,8 @@ export const remoteHandler = createRouter()
|
|
|
31
30
|
response: t.Object({
|
|
32
31
|
message: t.String()
|
|
33
32
|
})
|
|
34
|
-
}, async ({ data }) => {
|
|
35
|
-
const project =
|
|
36
|
-
if (!project) throw new Error('Project not found');
|
|
33
|
+
}, async ({ data, conn }) => {
|
|
34
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
37
35
|
const message = await gitService.fetch(project.path, data.remote);
|
|
38
36
|
return { message };
|
|
39
37
|
})
|
|
@@ -48,9 +46,8 @@ export const remoteHandler = createRouter()
|
|
|
48
46
|
success: t.Boolean(),
|
|
49
47
|
message: t.String()
|
|
50
48
|
})
|
|
51
|
-
}, async ({ data }) => {
|
|
52
|
-
const project =
|
|
53
|
-
if (!project) throw new Error('Project not found');
|
|
49
|
+
}, async ({ data, conn }) => {
|
|
50
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
54
51
|
return await gitService.pull(project.path, data.remote, data.branch);
|
|
55
52
|
})
|
|
56
53
|
|
|
@@ -65,9 +62,8 @@ export const remoteHandler = createRouter()
|
|
|
65
62
|
success: t.Boolean(),
|
|
66
63
|
message: t.String()
|
|
67
64
|
})
|
|
68
|
-
}, async ({ data }) => {
|
|
69
|
-
const project =
|
|
70
|
-
if (!project) throw new Error('Project not found');
|
|
65
|
+
}, async ({ data, conn }) => {
|
|
66
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
71
67
|
return await gitService.push(project.path, data.remote, data.branch, data.force);
|
|
72
68
|
})
|
|
73
69
|
|
|
@@ -78,9 +74,8 @@ export const remoteHandler = createRouter()
|
|
|
78
74
|
url: t.String()
|
|
79
75
|
}),
|
|
80
76
|
response: t.Object({ ok: t.Boolean() })
|
|
81
|
-
}, async ({ data }) => {
|
|
82
|
-
const project =
|
|
83
|
-
if (!project) throw new Error('Project not found');
|
|
77
|
+
}, async ({ data, conn }) => {
|
|
78
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
84
79
|
await gitService.addRemote(project.path, data.name, data.url);
|
|
85
80
|
return { ok: true };
|
|
86
81
|
})
|
|
@@ -91,9 +86,8 @@ export const remoteHandler = createRouter()
|
|
|
91
86
|
name: t.String()
|
|
92
87
|
}),
|
|
93
88
|
response: t.Object({ ok: t.Boolean() })
|
|
94
|
-
}, async ({ data }) => {
|
|
95
|
-
const project =
|
|
96
|
-
if (!project) throw new Error('Project not found');
|
|
89
|
+
}, async ({ data, conn }) => {
|
|
90
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
97
91
|
await gitService.removeRemote(project.path, data.name);
|
|
98
92
|
return { ok: true };
|
|
99
93
|
})
|
|
@@ -107,9 +101,8 @@ export const remoteHandler = createRouter()
|
|
|
107
101
|
message: t.String(),
|
|
108
102
|
date: t.String()
|
|
109
103
|
}))
|
|
110
|
-
}, async ({ data }) => {
|
|
111
|
-
const project =
|
|
112
|
-
if (!project) throw new Error('Project not found');
|
|
104
|
+
}, async ({ data, conn }) => {
|
|
105
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
113
106
|
return await gitService.stashList(project.path);
|
|
114
107
|
})
|
|
115
108
|
|
|
@@ -119,9 +112,8 @@ export const remoteHandler = createRouter()
|
|
|
119
112
|
message: t.Optional(t.String())
|
|
120
113
|
}),
|
|
121
114
|
response: t.Object({ ok: t.Boolean() })
|
|
122
|
-
}, async ({ data }) => {
|
|
123
|
-
const project =
|
|
124
|
-
if (!project) throw new Error('Project not found');
|
|
115
|
+
}, async ({ data, conn }) => {
|
|
116
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
125
117
|
await gitService.stashSave(project.path, data.message);
|
|
126
118
|
return { ok: true };
|
|
127
119
|
})
|
|
@@ -132,9 +124,8 @@ export const remoteHandler = createRouter()
|
|
|
132
124
|
index: t.Optional(t.Number())
|
|
133
125
|
}),
|
|
134
126
|
response: t.Object({ ok: t.Boolean() })
|
|
135
|
-
}, async ({ data }) => {
|
|
136
|
-
const project =
|
|
137
|
-
if (!project) throw new Error('Project not found');
|
|
127
|
+
}, async ({ data, conn }) => {
|
|
128
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
138
129
|
await gitService.stashPop(project.path, data.index);
|
|
139
130
|
return { ok: true };
|
|
140
131
|
})
|
|
@@ -145,9 +136,8 @@ export const remoteHandler = createRouter()
|
|
|
145
136
|
index: t.Optional(t.Number())
|
|
146
137
|
}),
|
|
147
138
|
response: t.Object({ ok: t.Boolean() })
|
|
148
|
-
}, async ({ data }) => {
|
|
149
|
-
const project =
|
|
150
|
-
if (!project) throw new Error('Project not found');
|
|
139
|
+
}, async ({ data, conn }) => {
|
|
140
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
151
141
|
await gitService.stashDrop(project.path, data.index);
|
|
152
142
|
return { ok: true };
|
|
153
143
|
})
|
|
@@ -163,9 +153,8 @@ export const remoteHandler = createRouter()
|
|
|
163
153
|
date: t.String(),
|
|
164
154
|
isAnnotated: t.Boolean()
|
|
165
155
|
}))
|
|
166
|
-
}, async ({ data }) => {
|
|
167
|
-
const project =
|
|
168
|
-
if (!project) throw new Error('Project not found');
|
|
156
|
+
}, async ({ data, conn }) => {
|
|
157
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
169
158
|
return await gitService.getTags(project.path);
|
|
170
159
|
})
|
|
171
160
|
|
|
@@ -177,9 +166,8 @@ export const remoteHandler = createRouter()
|
|
|
177
166
|
commitHash: t.Optional(t.String())
|
|
178
167
|
}),
|
|
179
168
|
response: t.Object({ ok: t.Boolean() })
|
|
180
|
-
}, async ({ data }) => {
|
|
181
|
-
const project =
|
|
182
|
-
if (!project) throw new Error('Project not found');
|
|
169
|
+
}, async ({ data, conn }) => {
|
|
170
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
183
171
|
await gitService.createTag(project.path, data.name, data.message, data.commitHash);
|
|
184
172
|
return { ok: true };
|
|
185
173
|
})
|
|
@@ -190,9 +178,8 @@ export const remoteHandler = createRouter()
|
|
|
190
178
|
name: t.String()
|
|
191
179
|
}),
|
|
192
180
|
response: t.Object({ ok: t.Boolean() })
|
|
193
|
-
}, async ({ data }) => {
|
|
194
|
-
const project =
|
|
195
|
-
if (!project) throw new Error('Project not found');
|
|
181
|
+
}, async ({ data, conn }) => {
|
|
182
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
196
183
|
await gitService.deleteTag(project.path, data.name);
|
|
197
184
|
return { ok: true };
|
|
198
185
|
})
|
|
@@ -207,8 +194,8 @@ export const remoteHandler = createRouter()
|
|
|
207
194
|
success: t.Boolean(),
|
|
208
195
|
message: t.String()
|
|
209
196
|
})
|
|
210
|
-
}, async ({ data }) => {
|
|
211
|
-
const project =
|
|
212
|
-
if (!project) throw new Error('Project not found');
|
|
197
|
+
}, async ({ data, conn }) => {
|
|
198
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
213
199
|
return await gitService.pushTag(project.path, data.name, data.remote);
|
|
214
200
|
});
|
|
201
|
+
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { gitService } from '../../git/git-service';
|
|
8
|
-
import {
|
|
8
|
+
import { requireProjectAccess } from '../access';
|
|
9
9
|
|
|
10
10
|
export const stagingHandler = createRouter()
|
|
11
11
|
.http('git:stage', {
|
|
@@ -14,9 +14,8 @@ export const stagingHandler = createRouter()
|
|
|
14
14
|
filePath: t.String()
|
|
15
15
|
}),
|
|
16
16
|
response: t.Object({ ok: t.Boolean() })
|
|
17
|
-
}, async ({ data }) => {
|
|
18
|
-
const project =
|
|
19
|
-
if (!project) throw new Error('Project not found');
|
|
17
|
+
}, async ({ data, conn }) => {
|
|
18
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
20
19
|
await gitService.stageFile(project.path, data.filePath);
|
|
21
20
|
return { ok: true };
|
|
22
21
|
})
|
|
@@ -26,9 +25,8 @@ export const stagingHandler = createRouter()
|
|
|
26
25
|
projectId: t.String()
|
|
27
26
|
}),
|
|
28
27
|
response: t.Object({ ok: t.Boolean() })
|
|
29
|
-
}, async ({ data }) => {
|
|
30
|
-
const project =
|
|
31
|
-
if (!project) throw new Error('Project not found');
|
|
28
|
+
}, async ({ data, conn }) => {
|
|
29
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
32
30
|
await gitService.stageAll(project.path);
|
|
33
31
|
return { ok: true };
|
|
34
32
|
})
|
|
@@ -39,9 +37,8 @@ export const stagingHandler = createRouter()
|
|
|
39
37
|
filePath: t.String()
|
|
40
38
|
}),
|
|
41
39
|
response: t.Object({ ok: t.Boolean() })
|
|
42
|
-
}, async ({ data }) => {
|
|
43
|
-
const project =
|
|
44
|
-
if (!project) throw new Error('Project not found');
|
|
40
|
+
}, async ({ data, conn }) => {
|
|
41
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
45
42
|
await gitService.unstageFile(project.path, data.filePath);
|
|
46
43
|
return { ok: true };
|
|
47
44
|
})
|
|
@@ -51,9 +48,8 @@ export const stagingHandler = createRouter()
|
|
|
51
48
|
projectId: t.String()
|
|
52
49
|
}),
|
|
53
50
|
response: t.Object({ ok: t.Boolean() })
|
|
54
|
-
}, async ({ data }) => {
|
|
55
|
-
const project =
|
|
56
|
-
if (!project) throw new Error('Project not found');
|
|
51
|
+
}, async ({ data, conn }) => {
|
|
52
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
57
53
|
await gitService.unstageAll(project.path);
|
|
58
54
|
return { ok: true };
|
|
59
55
|
})
|
|
@@ -64,9 +60,8 @@ export const stagingHandler = createRouter()
|
|
|
64
60
|
filePath: t.String()
|
|
65
61
|
}),
|
|
66
62
|
response: t.Object({ ok: t.Boolean() })
|
|
67
|
-
}, async ({ data }) => {
|
|
68
|
-
const project =
|
|
69
|
-
if (!project) throw new Error('Project not found');
|
|
63
|
+
}, async ({ data, conn }) => {
|
|
64
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
70
65
|
await gitService.discardFile(project.path, data.filePath);
|
|
71
66
|
return { ok: true };
|
|
72
67
|
})
|
|
@@ -76,9 +71,8 @@ export const stagingHandler = createRouter()
|
|
|
76
71
|
projectId: t.String()
|
|
77
72
|
}),
|
|
78
73
|
response: t.Object({ ok: t.Boolean() })
|
|
79
|
-
}, async ({ data }) => {
|
|
80
|
-
const project =
|
|
81
|
-
if (!project) throw new Error('Project not found');
|
|
74
|
+
}, async ({ data, conn }) => {
|
|
75
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
82
76
|
await gitService.discardAll(project.path);
|
|
83
77
|
return { ok: true };
|
|
84
78
|
});
|
package/backend/ws/git/status.ts
CHANGED
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
import { t } from 'elysia';
|
|
6
6
|
import { createRouter } from '$shared/utils/ws-server';
|
|
7
7
|
import { gitService } from '../../git/git-service';
|
|
8
|
-
import {
|
|
9
|
-
import { ws as wsServer } from '../../utils/ws';
|
|
8
|
+
import { requireProjectAccess } from '../access';
|
|
10
9
|
|
|
11
10
|
export const statusHandler = createRouter()
|
|
12
11
|
.http('git:status', {
|
|
@@ -40,9 +39,8 @@ export const statusHandler = createRouter()
|
|
|
40
39
|
oldPath: t.Optional(t.String())
|
|
41
40
|
}))
|
|
42
41
|
})
|
|
43
|
-
}, async ({ data }) => {
|
|
44
|
-
const project =
|
|
45
|
-
if (!project) throw new Error('Project not found');
|
|
42
|
+
}, async ({ data, conn }) => {
|
|
43
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
46
44
|
|
|
47
45
|
const isRepo = await gitService.isRepo(project.path);
|
|
48
46
|
if (!isRepo) {
|
|
@@ -65,9 +63,8 @@ export const statusHandler = createRouter()
|
|
|
65
63
|
defaultBranch: t.Optional(t.String())
|
|
66
64
|
}),
|
|
67
65
|
response: t.Object({ ok: t.Boolean() })
|
|
68
|
-
}, async ({ data }) => {
|
|
69
|
-
const project =
|
|
70
|
-
if (!project) throw new Error('Project not found');
|
|
66
|
+
}, async ({ data, conn }) => {
|
|
67
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
71
68
|
await gitService.init(project.path, data.defaultBranch);
|
|
72
69
|
return { ok: true };
|
|
73
70
|
})
|
|
@@ -80,9 +77,8 @@ export const statusHandler = createRouter()
|
|
|
80
77
|
isRepo: t.Boolean(),
|
|
81
78
|
root: t.Optional(t.String())
|
|
82
79
|
})
|
|
83
|
-
}, async ({ data }) => {
|
|
84
|
-
const project =
|
|
85
|
-
if (!project) throw new Error('Project not found');
|
|
80
|
+
}, async ({ data, conn }) => {
|
|
81
|
+
const project = requireProjectAccess(conn, data.projectId);
|
|
86
82
|
|
|
87
83
|
const isRepo = await gitService.isRepo(project.path);
|
|
88
84
|
const root = isRepo ? await gitService.getRoot(project.path) : undefined;
|
package/backend/ws/index.ts
CHANGED
|
@@ -29,6 +29,7 @@ import { tunnelRouter } from './tunnel';
|
|
|
29
29
|
import { gitRouter } from './git';
|
|
30
30
|
import { engineRouter } from './engine';
|
|
31
31
|
import { systemToolsRouter } from './system-tools';
|
|
32
|
+
import { dbClientRouter } from './db-client';
|
|
32
33
|
|
|
33
34
|
// ============================================
|
|
34
35
|
// Main App Router - Merge All Module Routers
|
|
@@ -67,7 +68,10 @@ export const wsRouter = createRouter()
|
|
|
67
68
|
.merge(engineRouter)
|
|
68
69
|
|
|
69
70
|
// System Tools (install Git, Claude Code, OpenCode, Chrome binaries)
|
|
70
|
-
.merge(systemToolsRouter)
|
|
71
|
+
.merge(systemToolsRouter)
|
|
72
|
+
|
|
73
|
+
// DB Client (global database management)
|
|
74
|
+
.merge(dbClientRouter);
|
|
71
75
|
|
|
72
76
|
// Export API type for frontend type-safe access
|
|
73
77
|
export type WSAPI = typeof wsRouter['$api'];
|
|
@@ -11,6 +11,7 @@ import { t } from 'elysia';
|
|
|
11
11
|
import { createRouter } from '$shared/utils/ws-server';
|
|
12
12
|
import { messageQueries } from '../../database/queries';
|
|
13
13
|
import { loadMessage } from '$shared/utils/message-formatter';
|
|
14
|
+
import { requireMessageAccess, requireSessionAccess } from '../access';
|
|
14
15
|
|
|
15
16
|
export const crudHandler = createRouter()
|
|
16
17
|
// List messages
|
|
@@ -20,7 +21,8 @@ export const crudHandler = createRouter()
|
|
|
20
21
|
include_all: t.Optional(t.Boolean())
|
|
21
22
|
}),
|
|
22
23
|
response: t.Array(t.Any())
|
|
23
|
-
}, async ({ data }) => {
|
|
24
|
+
}, async ({ data, conn }) => {
|
|
25
|
+
requireSessionAccess(conn, data.session_id);
|
|
24
26
|
if (data.include_all) {
|
|
25
27
|
// Return all messages including those in other branches (for History view)
|
|
26
28
|
const allMessages = messageQueries.getAllBySessionId(data.session_id);
|
|
@@ -37,13 +39,8 @@ export const crudHandler = createRouter()
|
|
|
37
39
|
messageId: t.String({ minLength: 1 })
|
|
38
40
|
}),
|
|
39
41
|
response: t.Any()
|
|
40
|
-
}, async ({ data }) => {
|
|
41
|
-
const message =
|
|
42
|
-
|
|
43
|
-
if (!message) {
|
|
44
|
-
throw new Error('Message not found');
|
|
45
|
-
}
|
|
46
|
-
|
|
42
|
+
}, async ({ data, conn }) => {
|
|
43
|
+
const message = requireMessageAccess(conn, data.messageId);
|
|
47
44
|
return loadMessage(message);
|
|
48
45
|
})
|
|
49
46
|
|
|
@@ -55,12 +52,9 @@ export const crudHandler = createRouter()
|
|
|
55
52
|
response: t.Object({
|
|
56
53
|
message: t.String()
|
|
57
54
|
})
|
|
58
|
-
}, async ({ data }) => {
|
|
55
|
+
}, async ({ data, conn }) => {
|
|
59
56
|
// Check if message exists first
|
|
60
|
-
|
|
61
|
-
if (!message) {
|
|
62
|
-
throw new Error('Message not found');
|
|
63
|
-
}
|
|
57
|
+
requireMessageAccess(conn, data.messageId);
|
|
64
58
|
|
|
65
59
|
// Delete the message
|
|
66
60
|
messageQueries.delete(data.messageId);
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Preview access guards.
|
|
3
|
+
*
|
|
4
|
+
* Browser preview handlers all read `projectId` from the connection and grab a
|
|
5
|
+
* project-scoped `BrowserPreviewService` from the manager. Without an explicit
|
|
6
|
+
* project-membership check, a connection that managed to land in another
|
|
7
|
+
* project's room could drive that project's browser. These helpers compose the
|
|
8
|
+
* membership guard with the service lookup so handlers cannot forget either.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import type { WSConnection } from '$shared/utils/ws-server';
|
|
12
|
+
import { requireCurrentProjectAccess } from '../access';
|
|
13
|
+
import { browserPreviewServiceManager } from '../../preview/index';
|
|
14
|
+
|
|
15
|
+
type PreviewService = ReturnType<typeof browserPreviewServiceManager.getService>;
|
|
16
|
+
type Tab = NonNullable<ReturnType<PreviewService['getActiveTab']>>;
|
|
17
|
+
|
|
18
|
+
export interface BrowserPreviewContext {
|
|
19
|
+
userId: string;
|
|
20
|
+
projectId: string;
|
|
21
|
+
previewService: PreviewService;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function requireBrowserPreviewAccess(conn: WSConnection): BrowserPreviewContext {
|
|
25
|
+
const { userId, projectId } = requireCurrentProjectAccess(conn);
|
|
26
|
+
const previewService = browserPreviewServiceManager.getService(projectId);
|
|
27
|
+
return { userId, projectId, previewService };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Resolve a tab in the caller's project. If `tabId` is omitted the active tab
|
|
32
|
+
* is returned. Throws if the caller can't access the project, or if no tab
|
|
33
|
+
* matches.
|
|
34
|
+
*/
|
|
35
|
+
export function requireBrowserTabAccess(
|
|
36
|
+
conn: WSConnection,
|
|
37
|
+
tabId?: string
|
|
38
|
+
): BrowserPreviewContext & { tab: Tab } {
|
|
39
|
+
const ctx = requireBrowserPreviewAccess(conn);
|
|
40
|
+
const tab = tabId ? ctx.previewService.getTab(tabId) : ctx.previewService.getActiveTab();
|
|
41
|
+
if (!tab) {
|
|
42
|
+
throw new Error(tabId ? `Tab not found: ${tabId}` : 'No active tab');
|
|
43
|
+
}
|
|
44
|
+
return { ...ctx, tab };
|
|
45
|
+
}
|
|
@@ -6,9 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
import { t } from 'elysia';
|
|
8
8
|
import { createRouter } from '$shared/utils/ws-server';
|
|
9
|
-
import {
|
|
10
|
-
import { ws } from '$backend/utils/ws';
|
|
11
|
-
import { debug } from '$shared/utils/logger';
|
|
9
|
+
import { requireBrowserPreviewAccess } from '../access';
|
|
12
10
|
|
|
13
11
|
export const cleanupPreviewHandler = createRouter()
|
|
14
12
|
// Get cleanup status
|
|
@@ -26,10 +24,7 @@ export const cleanupPreviewHandler = createRouter()
|
|
|
26
24
|
}))
|
|
27
25
|
})
|
|
28
26
|
}, async ({ conn }) => {
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
// Get project-specific preview service
|
|
32
|
-
const previewService = browserPreviewServiceManager.getService(projectId);
|
|
27
|
+
const { previewService } = requireBrowserPreviewAccess(conn);
|
|
33
28
|
const status = previewService.getTabsStatus();
|
|
34
29
|
|
|
35
30
|
return {
|
|
@@ -75,10 +70,7 @@ export const cleanupPreviewHandler = createRouter()
|
|
|
75
70
|
})
|
|
76
71
|
}, async ({ data, conn }) => {
|
|
77
72
|
const mode = data.mode || 'inactive';
|
|
78
|
-
const projectId =
|
|
79
|
-
|
|
80
|
-
// Get project-specific preview service
|
|
81
|
-
const previewService = browserPreviewServiceManager.getService(projectId);
|
|
73
|
+
const { projectId, previewService } = requireBrowserPreviewAccess(conn);
|
|
82
74
|
|
|
83
75
|
// Get tab status before cleanup
|
|
84
76
|
const statusBefore = previewService.getTabsStatus();
|