@myrialabs/clopen 0.4.6 → 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/session-invalidation.test.ts +17 -21
- package/backend/auth/session-invalidation.ts +10 -11
- package/backend/engine/adapters/claude/models.ts +46 -3
- package/backend/files/file-archive.test.ts +86 -26
- package/backend/files/file-archive.ts +214 -134
- 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/projects/crud.ts +4 -4
- 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-TYNK6Orl.js → main-LBI3a0n5.js} +294 -266
- package/dist/index.html +2 -2
- package/package.json +7 -11
- package/shared/constants/engines.ts +4 -4
- 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-BkMrek4_.css +0 -1
|
@@ -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};
|