@myrialabs/clopen 0.4.5 → 0.4.7
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 +14 -1
- package/backend/auth/session-invalidation.test.ts +17 -21
- package/backend/auth/session-invalidation.ts +10 -11
- package/backend/database/migrations/044_create_skills_table.ts +29 -0
- package/backend/database/migrations/index.ts +7 -0
- package/backend/database/queries/index.ts +3 -1
- package/backend/database/queries/skill-queries.ts +105 -0
- package/backend/engine/adapters/claude/models.ts +46 -3
- package/backend/engine/adapters/claude/stream.ts +5 -0
- package/backend/engine/adapters/codex/credential.ts +114 -13
- package/backend/engine/adapters/codex/stream.ts +34 -8
- package/backend/engine/adapters/copilot/stream.ts +4 -0
- package/backend/engine/adapters/opencode/stream.ts +4 -0
- package/backend/engine/adapters/qwen/stream.ts +3 -0
- package/backend/engine/docs/lessons-learned.md +54 -50
- package/backend/files/file-archive.test.ts +86 -26
- package/backend/files/file-archive.ts +214 -134
- package/backend/index.ts +10 -1
- package/backend/mcp/README.md +77 -24
- package/backend/mcp/external/config.ts +82 -101
- package/backend/mcp/external/proxy.ts +202 -0
- package/backend/mcp/index.ts +4 -3
- package/backend/mcp/internal/remote-server.ts +103 -55
- package/backend/skills/index.ts +21 -0
- package/backend/skills/marketplace.ts +172 -0
- package/backend/skills/service.ts +245 -0
- package/backend/skills/spec.ts +214 -0
- package/backend/skills/store.ts +99 -0
- package/backend/skills/sync.ts +187 -0
- package/backend/terminal/index.ts +2 -5
- package/backend/terminal/ptykit.ts +64 -0
- package/backend/tunnel/tunnel-config.ts +1 -1
- package/backend/utils/ws.ts +14 -0
- package/backend/ws/files/write.ts +23 -7
- package/backend/ws/index.ts +5 -1
- package/backend/ws/projects/crud.ts +4 -4
- package/backend/ws/skills/catalog.ts +79 -0
- package/backend/ws/skills/crud.ts +123 -0
- package/backend/ws/skills/index.ts +15 -0
- package/backend/ws/system/operations.ts +23 -0
- package/backend/ws/terminal/index.ts +6 -33
- package/backend/ws/terminal/tunnel.ts +76 -0
- package/dist/assets/index-xrB3zcfA.js +1 -0
- package/dist/assets/main-BXS8bjJ6.css +1 -0
- package/dist/assets/{main-zXKH_C5O.js → main-LBI3a0n5.js} +304 -261
- package/dist/index.html +2 -2
- package/package.json +7 -11
- package/shared/constants/engines.ts +4 -4
- package/shared/utils/logger.ts +1 -0
- package/backend/terminal/helpers.ts +0 -14
- package/backend/terminal/pty-manager.ts +0 -4
- package/backend/terminal/pty-session-manager.ts +0 -349
- package/backend/terminal/stream-manager.ts +0 -300
- package/backend/ws/terminal/access.ts +0 -56
- package/backend/ws/terminal/persistence.ts +0 -145
- package/backend/ws/terminal/session.ts +0 -470
- package/backend/ws/terminal/stream.ts +0 -82
- package/dist/assets/main-gNUEJAC5.css +0 -1
package/backend/ws/index.ts
CHANGED
|
@@ -32,6 +32,7 @@ import { engineRouter } from './engine';
|
|
|
32
32
|
import { systemToolsRouter } from './system-tools';
|
|
33
33
|
import { dbClientRouter } from './db-client';
|
|
34
34
|
import { mcpRouter } from './mcp';
|
|
35
|
+
import { skillsRouter } from './skills';
|
|
35
36
|
|
|
36
37
|
// ============================================
|
|
37
38
|
// Main App Router - Merge All Module Routers
|
|
@@ -77,7 +78,10 @@ export const wsRouter = createRouter()
|
|
|
77
78
|
.merge(dbClientRouter)
|
|
78
79
|
|
|
79
80
|
// External MCP server management (install from the official registry)
|
|
80
|
-
.merge(mcpRouter)
|
|
81
|
+
.merge(mcpRouter)
|
|
82
|
+
|
|
83
|
+
// Agent Skills management (create, import, install from a marketplace)
|
|
84
|
+
.merge(skillsRouter);
|
|
81
85
|
|
|
82
86
|
// Export API type for frontend type-safe access
|
|
83
87
|
export type WSAPI = typeof wsRouter['$api'];
|
|
@@ -17,7 +17,7 @@ import { ws } from '$backend/utils/ws';
|
|
|
17
17
|
import { snapshotService } from '../../snapshot/snapshot-service';
|
|
18
18
|
import { blobStore } from '../../snapshot/blob-store';
|
|
19
19
|
import { streamManager } from '../../chat/stream-manager';
|
|
20
|
-
import {
|
|
20
|
+
import { cleanupProjectSessions } from '../../terminal/ptykit';
|
|
21
21
|
import { broadcastPresence } from '../projects/status';
|
|
22
22
|
import { debug } from '$shared/utils/logger';
|
|
23
23
|
import { requireProjectAccess } from '../access';
|
|
@@ -106,9 +106,9 @@ export const crudHandler = createRouter()
|
|
|
106
106
|
|
|
107
107
|
const mode = data.mode ?? 'remove';
|
|
108
108
|
|
|
109
|
-
// Clean up terminal
|
|
110
|
-
const cleanedStreams =
|
|
111
|
-
debug.log('project', `Cleaned up ${cleanedStreams} terminal
|
|
109
|
+
// Clean up terminal (PTY) sessions for this project
|
|
110
|
+
const cleanedStreams = cleanupProjectSessions(data.id);
|
|
111
|
+
debug.log('project', `Cleaned up ${cleanedStreams} terminal sessions for project ${data.id}`);
|
|
112
112
|
|
|
113
113
|
if (mode === 'full') {
|
|
114
114
|
// Full delete: remove sessions with blob cleanup, then the project itself
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill Marketplace Handlers
|
|
3
|
+
*
|
|
4
|
+
* - skills:catalog — browse the skill catalog (paginated, searchable)
|
|
5
|
+
* - skills:install — install a skill from the catalog into the canonical store
|
|
6
|
+
*
|
|
7
|
+
* Skills come from the community registry. See backend/skills/marketplace.ts.
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { t } from 'elysia';
|
|
11
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
12
|
+
import { debug } from '$shared/utils/logger';
|
|
13
|
+
import { listMarketplaceSkills, skillService } from '$backend/skills';
|
|
14
|
+
|
|
15
|
+
const MARKETPLACE_SKILL_SCHEMA = t.Object({
|
|
16
|
+
ref: t.String(),
|
|
17
|
+
name: t.String(),
|
|
18
|
+
slug: t.String(),
|
|
19
|
+
description: t.String(),
|
|
20
|
+
stars: t.Optional(t.Number()),
|
|
21
|
+
verified: t.Optional(t.Boolean()),
|
|
22
|
+
homepage: t.Optional(t.String())
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const SKILL_SCHEMA = t.Object({
|
|
26
|
+
id: t.Number(),
|
|
27
|
+
slug: t.String(),
|
|
28
|
+
name: t.String(),
|
|
29
|
+
description: t.String(),
|
|
30
|
+
source: t.Union([t.Literal('custom'), t.Literal('imported'), t.Literal('marketplace')]),
|
|
31
|
+
marketplaceRef: t.Union([t.String(), t.Null()]),
|
|
32
|
+
version: t.Union([t.String(), t.Null()]),
|
|
33
|
+
license: t.Union([t.String(), t.Null()]),
|
|
34
|
+
enabled: t.Boolean(),
|
|
35
|
+
present: t.Boolean(),
|
|
36
|
+
createdAt: t.String()
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const skillCatalogHandler = createRouter()
|
|
40
|
+
.http('skills:catalog', {
|
|
41
|
+
data: t.Object({
|
|
42
|
+
search: t.Optional(t.String()),
|
|
43
|
+
cursor: t.Optional(t.String())
|
|
44
|
+
}),
|
|
45
|
+
response: t.Object({
|
|
46
|
+
skills: t.Array(MARKETPLACE_SKILL_SCHEMA),
|
|
47
|
+
nextCursor: t.Union([t.String(), t.Null()])
|
|
48
|
+
})
|
|
49
|
+
}, async ({ data }) => {
|
|
50
|
+
debug.log('path', `skills:catalog q="${data.search ?? ''}"`);
|
|
51
|
+
return listMarketplaceSkills(data.search ?? '', data.cursor ?? null);
|
|
52
|
+
})
|
|
53
|
+
.http('skills:marketplace-detail', {
|
|
54
|
+
data: t.Object({ ref: t.String() }),
|
|
55
|
+
response: t.Object({
|
|
56
|
+
name: t.String(),
|
|
57
|
+
description: t.String(),
|
|
58
|
+
license: t.Union([t.String(), t.Null()]),
|
|
59
|
+
body: t.String()
|
|
60
|
+
})
|
|
61
|
+
}, async ({ data }) => {
|
|
62
|
+
debug.log('path', `skills:marketplace-detail ${data.ref}`);
|
|
63
|
+
return skillService.previewInstall(data.ref);
|
|
64
|
+
})
|
|
65
|
+
.http('skills:install', {
|
|
66
|
+
data: t.Object({
|
|
67
|
+
ref: t.String(),
|
|
68
|
+
name: t.Optional(t.String()),
|
|
69
|
+
description: t.Optional(t.String()),
|
|
70
|
+
license: t.Optional(t.Union([t.String(), t.Null()])),
|
|
71
|
+
body: t.Optional(t.String())
|
|
72
|
+
}),
|
|
73
|
+
response: t.Object({ skill: SKILL_SCHEMA })
|
|
74
|
+
}, async ({ data }) => {
|
|
75
|
+
debug.log('path', `skills:install ${data.ref}`);
|
|
76
|
+
const { ref, ...override } = data;
|
|
77
|
+
const skill = await skillService.install(ref, override);
|
|
78
|
+
return { skill };
|
|
79
|
+
});
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skill CRUD Handlers
|
|
3
|
+
*
|
|
4
|
+
* Manage user Agent Skills (Settings → Skills):
|
|
5
|
+
* - skills:list — installed skills (DB metadata + on-disk presence)
|
|
6
|
+
* - skills:get — one skill plus its SKILL.md body (for the editor)
|
|
7
|
+
* - skills:create — author a skill from editor fields
|
|
8
|
+
* - skills:update — edit an existing skill
|
|
9
|
+
* - skills:parse-import — preview a pasted/uploaded SKILL.md before importing
|
|
10
|
+
* - skills:import — persist a pasted/uploaded SKILL.md
|
|
11
|
+
* - skills:toggle — enable / disable
|
|
12
|
+
* - skills:delete — remove
|
|
13
|
+
*
|
|
14
|
+
* Mutations are admin-gated (see backend/auth/permissions.ts). Changes take
|
|
15
|
+
* effect on the next chat stream, when each engine re-syncs its skills.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
import { t } from 'elysia';
|
|
19
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
20
|
+
import { debug } from '$shared/utils/logger';
|
|
21
|
+
import { skillService } from '$backend/skills';
|
|
22
|
+
|
|
23
|
+
const SOURCE_SCHEMA = t.Union([t.Literal('custom'), t.Literal('imported'), t.Literal('marketplace')]);
|
|
24
|
+
|
|
25
|
+
const SKILL_SCHEMA = t.Object({
|
|
26
|
+
id: t.Number(),
|
|
27
|
+
slug: t.String(),
|
|
28
|
+
name: t.String(),
|
|
29
|
+
description: t.String(),
|
|
30
|
+
source: SOURCE_SCHEMA,
|
|
31
|
+
marketplaceRef: t.Union([t.String(), t.Null()]),
|
|
32
|
+
version: t.Union([t.String(), t.Null()]),
|
|
33
|
+
license: t.Union([t.String(), t.Null()]),
|
|
34
|
+
enabled: t.Boolean(),
|
|
35
|
+
present: t.Boolean(),
|
|
36
|
+
createdAt: t.String()
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
export const skillCrudHandler = createRouter()
|
|
40
|
+
.http('skills:list', {
|
|
41
|
+
data: t.Object({}),
|
|
42
|
+
response: t.Object({ skills: t.Array(SKILL_SCHEMA) })
|
|
43
|
+
}, async () => {
|
|
44
|
+
debug.log('path', 'skills:list');
|
|
45
|
+
return { skills: await skillService.list() };
|
|
46
|
+
})
|
|
47
|
+
.http('skills:get', {
|
|
48
|
+
data: t.Object({ id: t.Number() }),
|
|
49
|
+
response: t.Object({ skill: SKILL_SCHEMA, body: t.String() })
|
|
50
|
+
}, async ({ data }) => {
|
|
51
|
+
debug.log('path', `skills:get ${data.id}`);
|
|
52
|
+
const result = await skillService.get(data.id);
|
|
53
|
+
if (!result) throw new Error('Skill not found');
|
|
54
|
+
return result;
|
|
55
|
+
})
|
|
56
|
+
.http('skills:create', {
|
|
57
|
+
data: t.Object({
|
|
58
|
+
name: t.String(),
|
|
59
|
+
description: t.String(),
|
|
60
|
+
body: t.String(),
|
|
61
|
+
license: t.Optional(t.String())
|
|
62
|
+
}),
|
|
63
|
+
response: t.Object({ skill: SKILL_SCHEMA })
|
|
64
|
+
}, async ({ data }) => {
|
|
65
|
+
debug.log('path', `skills:create ${data.name}`);
|
|
66
|
+
if (!data.name.trim()) throw new Error('A skill name is required');
|
|
67
|
+
if (!data.description.trim()) throw new Error('A skill description is required');
|
|
68
|
+
const skill = await skillService.create(data);
|
|
69
|
+
return { skill };
|
|
70
|
+
})
|
|
71
|
+
.http('skills:update', {
|
|
72
|
+
data: t.Object({
|
|
73
|
+
id: t.Number(),
|
|
74
|
+
name: t.String(),
|
|
75
|
+
description: t.String(),
|
|
76
|
+
body: t.String(),
|
|
77
|
+
license: t.Optional(t.String())
|
|
78
|
+
}),
|
|
79
|
+
response: t.Object({ skill: SKILL_SCHEMA })
|
|
80
|
+
}, async ({ data }) => {
|
|
81
|
+
debug.log('path', `skills:update ${data.id}`);
|
|
82
|
+
if (!data.name.trim()) throw new Error('A skill name is required');
|
|
83
|
+
if (!data.description.trim()) throw new Error('A skill description is required');
|
|
84
|
+
const skill = await skillService.update(data.id, data);
|
|
85
|
+
return { skill };
|
|
86
|
+
})
|
|
87
|
+
.http('skills:parse-import', {
|
|
88
|
+
// Preview a pasted/uploaded SKILL.md. Pure transform — nothing persisted.
|
|
89
|
+
data: t.Object({ text: t.String() }),
|
|
90
|
+
response: t.Object({
|
|
91
|
+
name: t.String(),
|
|
92
|
+
description: t.String(),
|
|
93
|
+
license: t.Union([t.String(), t.Null()]),
|
|
94
|
+
body: t.String(),
|
|
95
|
+
warnings: t.Array(t.String())
|
|
96
|
+
})
|
|
97
|
+
}, async ({ data }) => {
|
|
98
|
+
debug.log('path', 'skills:parse-import');
|
|
99
|
+
return skillService.parsePreview(data.text);
|
|
100
|
+
})
|
|
101
|
+
.http('skills:import', {
|
|
102
|
+
data: t.Object({ text: t.String() }),
|
|
103
|
+
response: t.Object({ skill: SKILL_SCHEMA })
|
|
104
|
+
}, async ({ data }) => {
|
|
105
|
+
debug.log('path', 'skills:import');
|
|
106
|
+
const skill = await skillService.import(data.text);
|
|
107
|
+
return { skill };
|
|
108
|
+
})
|
|
109
|
+
.http('skills:toggle', {
|
|
110
|
+
data: t.Object({ id: t.Number(), enabled: t.Boolean() }),
|
|
111
|
+
response: t.Object({ skill: SKILL_SCHEMA })
|
|
112
|
+
}, async ({ data }) => {
|
|
113
|
+
debug.log('path', `skills:toggle ${data.id} → ${data.enabled}`);
|
|
114
|
+
return { skill: skillService.toggle(data.id, data.enabled) };
|
|
115
|
+
})
|
|
116
|
+
.http('skills:delete', {
|
|
117
|
+
data: t.Object({ id: t.Number() }),
|
|
118
|
+
response: t.Object({ success: t.Boolean() })
|
|
119
|
+
}, async ({ data }) => {
|
|
120
|
+
debug.log('path', `skills:delete ${data.id}`);
|
|
121
|
+
await skillService.remove(data.id);
|
|
122
|
+
return { success: true };
|
|
123
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Skills Router
|
|
3
|
+
*
|
|
4
|
+
* Entry point for user Agent Skill management (Settings → Skills):
|
|
5
|
+
* - skills:list / get / create / update / import / toggle / delete — CRUD
|
|
6
|
+
* - skills:catalog / install — browse + install from a marketplace provider
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
10
|
+
import { skillCrudHandler } from './crud';
|
|
11
|
+
import { skillCatalogHandler } from './catalog';
|
|
12
|
+
|
|
13
|
+
export const skillsRouter = createRouter()
|
|
14
|
+
.merge(skillCrudHandler)
|
|
15
|
+
.merge(skillCatalogHandler);
|
|
@@ -88,6 +88,29 @@ export const operationsHandler = createRouter()
|
|
|
88
88
|
};
|
|
89
89
|
})
|
|
90
90
|
|
|
91
|
+
// Fetch release notes from GitHub
|
|
92
|
+
.http('system:get-release-notes', {
|
|
93
|
+
data: t.Object({}),
|
|
94
|
+
response: t.Object({
|
|
95
|
+
tag_name: t.String(),
|
|
96
|
+
body: t.String(),
|
|
97
|
+
html_url: t.String(),
|
|
98
|
+
published_at: t.String()
|
|
99
|
+
})
|
|
100
|
+
}, async () => {
|
|
101
|
+
const response = await fetch('https://api.github.com/repos/myrialabs/clopen/releases/latest');
|
|
102
|
+
if (!response.ok) {
|
|
103
|
+
throw new Error(`GitHub API returned ${response.status}`);
|
|
104
|
+
}
|
|
105
|
+
const data = await response.json() as { tag_name: string; body: string; html_url: string; published_at: string };
|
|
106
|
+
return {
|
|
107
|
+
tag_name: data.tag_name,
|
|
108
|
+
body: data.body || '',
|
|
109
|
+
html_url: data.html_url,
|
|
110
|
+
published_at: data.published_at
|
|
111
|
+
};
|
|
112
|
+
})
|
|
113
|
+
|
|
91
114
|
// Run package update
|
|
92
115
|
.http('system:run-update', {
|
|
93
116
|
data: t.Object({}),
|
|
@@ -1,40 +1,13 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Terminal Router
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
* - session.ts: HTTP endpoints for session management (create, resize, kill, cancel, check-shell, pty-status)
|
|
9
|
-
* - stream.ts: Real-time events for terminal I/O (input, output, exit, directory, ready)
|
|
10
|
-
* - persistence.ts: Stream persistence and reconnection (stream-status, missed-output, reconnect)
|
|
4
|
+
* Terminal PTY sessions run on @myrialabs/ptykit. Its embedded WebSocket server
|
|
5
|
+
* is tunneled over Clopen's app-wide socket — see `tunnel.ts`. All session
|
|
6
|
+
* lifecycle, I/O, scrollback reattach, rooms, and reconnect are handled by the
|
|
7
|
+
* PtyKit wire protocol carried on `terminal:pty` / `terminal:pty-out`.
|
|
11
8
|
*/
|
|
12
9
|
|
|
13
|
-
import { t } from 'elysia';
|
|
14
10
|
import { createRouter } from '$shared/utils/ws-server';
|
|
15
|
-
import {
|
|
16
|
-
import { streamHandler } from './stream';
|
|
17
|
-
import { persistenceHandler } from './persistence';
|
|
18
|
-
|
|
19
|
-
export const terminalRouter = createRouter()
|
|
20
|
-
// Session Management (HTTP)
|
|
21
|
-
.merge(sessionHandler)
|
|
22
|
-
|
|
23
|
-
// Stream Events (Real-time I/O)
|
|
24
|
-
.merge(streamHandler)
|
|
25
|
-
|
|
26
|
-
// Stream Persistence (HTTP + Events)
|
|
27
|
-
.merge(persistenceHandler)
|
|
11
|
+
import { terminalTunnelHandler } from './tunnel';
|
|
28
12
|
|
|
29
|
-
|
|
30
|
-
.emit('terminal:tab-created', t.Object({
|
|
31
|
-
sessionId: t.String(),
|
|
32
|
-
streamId: t.String(),
|
|
33
|
-
pid: t.Number(),
|
|
34
|
-
currentDirectory: t.String(),
|
|
35
|
-
cols: t.Number(),
|
|
36
|
-
rows: t.Number()
|
|
37
|
-
}))
|
|
38
|
-
.emit('terminal:tab-closed', t.Object({
|
|
39
|
-
sessionId: t.String()
|
|
40
|
-
}));
|
|
13
|
+
export const terminalRouter = createRouter().merge(terminalTunnelHandler);
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Terminal tunnel — carries the PtyKit wire protocol over Clopen's app-wide
|
|
3
|
+
* WebSocket instead of a dedicated `/pty` socket.
|
|
4
|
+
*
|
|
5
|
+
* Inbound client frames arrive on `terminal:pty`; each Clopen connection gets one
|
|
6
|
+
* embedded `PtyKitConnection` whose `send` unicasts frames back on
|
|
7
|
+
* `terminal:pty-out` (RPC responses + reattach replay) while PtyKit's own room
|
|
8
|
+
* registry fans collaborative output out to every viewer. Identity (`userId`) is
|
|
9
|
+
* carried on the connection so `authorize` can enforce project access.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { t } from 'elysia';
|
|
13
|
+
import { createRouter } from '$shared/utils/ws-server';
|
|
14
|
+
import type { WSConnection } from '$shared/utils/ws-server';
|
|
15
|
+
import type { PtyKitConnection } from '@myrialabs/ptykit/server';
|
|
16
|
+
import type { WireFrame } from '@myrialabs/ptykit';
|
|
17
|
+
import { ws } from '$backend/utils/ws';
|
|
18
|
+
import { ptyKitServer } from '../../terminal/ptykit';
|
|
19
|
+
import { debug } from '$shared/utils/logger';
|
|
20
|
+
|
|
21
|
+
/** One embedded PtyKit connection per Clopen ws connection (by stable id). */
|
|
22
|
+
const ptyConnections = new Map<string, PtyKitConnection>();
|
|
23
|
+
|
|
24
|
+
/** Resolve (or lazily create) the PtyKit connection backing a Clopen connection. */
|
|
25
|
+
function getPtyConnection(conn: WSConnection): PtyKitConnection {
|
|
26
|
+
const connId = ws.getConnectionId(conn);
|
|
27
|
+
if (!connId) {
|
|
28
|
+
throw new Error('Connection not registered');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const existing = ptyConnections.get(connId);
|
|
32
|
+
if (existing) return existing;
|
|
33
|
+
|
|
34
|
+
const userId = ws.getUserId(conn);
|
|
35
|
+
const ptyConn = ptyKitServer.createConnection({
|
|
36
|
+
data: { userId, connId },
|
|
37
|
+
send: (frame) => {
|
|
38
|
+
ws.sendToConnectionId(connId, JSON.stringify({ action: 'terminal:pty-out', payload: frame }));
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
ptyKitServer.handleOpen(ptyConn);
|
|
42
|
+
ptyConnections.set(connId, ptyConn);
|
|
43
|
+
|
|
44
|
+
// Tear the PtyKit connection down (leave rooms) when the socket closes.
|
|
45
|
+
ws.addCleanup(conn, () => {
|
|
46
|
+
ptyKitServer.handleClose(ptyConn);
|
|
47
|
+
ptyConnections.delete(connId);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
debug.log('terminal', `🔌 PtyKit connection opened for ${connId}`);
|
|
51
|
+
return ptyConn;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const terminalTunnelHandler = createRouter()
|
|
55
|
+
// Client → server: one PtyKit wire frame.
|
|
56
|
+
.on('terminal:pty', {
|
|
57
|
+
data: t.Object({
|
|
58
|
+
action: t.String(),
|
|
59
|
+
payload: t.Any()
|
|
60
|
+
})
|
|
61
|
+
}, ({ conn, data }) => {
|
|
62
|
+
const ptyConn = getPtyConnection(conn);
|
|
63
|
+
void ptyKitServer.handleFrame(ptyConn, data as WireFrame);
|
|
64
|
+
})
|
|
65
|
+
// Server → client: PtyKit wire frames (RPC responses + broadcast events,
|
|
66
|
+
// including PtyKit's own room-level `tab-created` / `tab-closed`). Declared for
|
|
67
|
+
// the typed WSAPI; actually sent via ws.sendToConnectionId above.
|
|
68
|
+
//
|
|
69
|
+
// Collaborative tab-list sync rides this same stream: the frontend subscribes
|
|
70
|
+
// to PtyKit's tab events via `ptyClient.onSessionCreated` / `onSessionClosed`
|
|
71
|
+
// (see frontend/services/terminal/project.service.ts), so there are no
|
|
72
|
+
// Clopen-native tab events to declare here.
|
|
73
|
+
.emit('terminal:pty-out', t.Object({
|
|
74
|
+
action: t.String(),
|
|
75
|
+
payload: t.Any()
|
|
76
|
+
}));
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{s as _,_ as d,r as s,a as u}from"./main-LBI3a0n5.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-LBI3a0n5.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};
|