@myrialabs/clopen 0.4.34 → 0.4.35
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 +7 -0
- package/backend/containers/actions.ts +316 -0
- package/backend/containers/disk-usage.test.ts +68 -0
- package/backend/containers/disk-usage.ts +170 -0
- package/backend/containers/logs.ts +335 -0
- package/backend/containers/monitor.ts +410 -0
- package/backend/containers/parse.test.ts +599 -0
- package/backend/containers/parse.ts +905 -0
- package/backend/containers/port-index.test.ts +91 -0
- package/backend/containers/port-index.ts +198 -0
- package/backend/containers/prune-job.test.ts +148 -0
- package/backend/containers/prune-job.ts +129 -0
- package/backend/containers/pty-backend.ts +337 -0
- package/backend/containers/pty.ts +114 -0
- package/backend/containers/runtime.ts +218 -0
- package/backend/containers/scan.ts +293 -0
- package/backend/files/file-watcher.test.ts +105 -0
- package/backend/files/file-watcher.ts +45 -1
- package/backend/git/git-service.test.ts +33 -0
- package/backend/git/git-service.ts +7 -3
- package/backend/git/nested-repos.test.ts +292 -1
- package/backend/git/nested-repos.ts +330 -17
- package/backend/{ports → host}/runner.ts +19 -10
- package/backend/index.ts +11 -2
- package/backend/ports/attribute.ts +1 -1
- package/backend/ports/kill.ts +1 -1
- package/backend/ports/monitor.ts +1 -1
- package/backend/ports/processes.ts +1 -1
- package/backend/ports/scan-host.ts +77 -8
- package/backend/ports/scan.test.ts +1 -1
- package/backend/ports/scan.ts +1 -1
- package/backend/ports/ssh-lineage.ts +1 -1
- package/backend/preview/browser/browser-video-capture.ts +84 -31
- package/backend/ws/containers/actions.ts +156 -0
- package/backend/ws/containers/index.ts +43 -0
- package/backend/ws/containers/list.ts +146 -0
- package/backend/ws/containers/logs.ts +43 -0
- package/backend/ws/containers/tunnel.ts +101 -0
- package/backend/ws/git/log.ts +3 -1
- package/backend/ws/git/status.ts +37 -27
- package/backend/ws/index.ts +2 -0
- package/backend/ws/message-rate-limiter.test.ts +45 -0
- package/backend/ws/message-rate-limiter.ts +34 -3
- package/backend/ws/ssh/connections.ts +8 -0
- package/backend/ws/system/device-info.ts +99 -43
- package/dist/assets/{index-vW2RpdHu.js → index-B0iIhSO9.js} +1 -1
- package/dist/assets/{index-gGTMFUa8.js → index-BRJqss6F.js} +1 -1
- package/dist/assets/main-Buko4D0t.css +1 -0
- package/dist/assets/{main-ZCojSzvW.js → main-C_iGUZyL.js} +467 -449
- package/dist/index.html +2 -2
- package/dist/manifest.json +9 -2
- package/package.json +1 -1
- package/shared/types/containers/container.ts +366 -0
- package/shared/types/containers/index.ts +5 -0
- package/shared/types/host/index.ts +18 -0
- package/shared/types/ports/port.ts +47 -9
- package/shared/utils/logger.ts +2 -0
- package/shared/utils/ws-client.ts +67 -12
- package/shared/utils/ws-server.ts +64 -13
- package/dist/assets/main-CYCMEbXB.css +0 -1
|
@@ -281,7 +281,12 @@ export class WSRouter<
|
|
|
281
281
|
|
|
282
282
|
/** Optional auth middleware — called before every route handler */
|
|
283
283
|
private authMiddleware: ((conn: WSConnection, action: string) => Promise<{ allowed: boolean; error?: string }>) | null = null;
|
|
284
|
-
|
|
284
|
+
/**
|
|
285
|
+
* Optional rate limiter. `isRequest` tells it whether a caller is blocked
|
|
286
|
+
* waiting on a reply, so throttling can shed fire-and-forget floods without
|
|
287
|
+
* killing the low-volume calls panels depend on.
|
|
288
|
+
*/
|
|
289
|
+
private rateLimiter: ((conn: WSConnection, action: string, isRequest: boolean) => boolean) | null = null;
|
|
285
290
|
|
|
286
291
|
constructor() {
|
|
287
292
|
this.registerContextHandler();
|
|
@@ -291,7 +296,7 @@ export class WSRouter<
|
|
|
291
296
|
this.authMiddleware = fn;
|
|
292
297
|
}
|
|
293
298
|
|
|
294
|
-
setRateLimiter(fn: (conn: WSConnection, action: string) => boolean): void {
|
|
299
|
+
setRateLimiter(fn: (conn: WSConnection, action: string, isRequest: boolean) => boolean): void {
|
|
295
300
|
this.rateLimiter = fn;
|
|
296
301
|
}
|
|
297
302
|
|
|
@@ -531,16 +536,30 @@ export class WSRouter<
|
|
|
531
536
|
data: validatedData
|
|
532
537
|
});
|
|
533
538
|
|
|
534
|
-
//
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
539
|
+
// The response is NOT re-validated.
|
|
540
|
+
//
|
|
541
|
+
// `route.responseSchema` stays declared because it is what gives
|
|
542
|
+
// `ws.http()` its return type on the client — but checking the value
|
|
543
|
+
// against it at runtime bought nothing and cost the whole server.
|
|
544
|
+
// A response is produced by our own handler, not by a peer: it is not
|
|
545
|
+
// untrusted input, so the only thing validation could catch is a bug
|
|
546
|
+
// we would rather surface as a wrong field than as a route that fails
|
|
547
|
+
// outright for the user.
|
|
548
|
+
//
|
|
549
|
+
// The cost was not theoretical. `Value.Decode` walks the entire value
|
|
550
|
+
// synchronously on the main thread, and the worst offender is exactly
|
|
551
|
+
// the biggest payload: `files:list-tree` declares a RECURSIVE UNION
|
|
552
|
+
// (backend/ws/files/read.ts), so TypeBox tries both branches at every
|
|
553
|
+
// node of the tree. On a large project that locked the event loop for
|
|
554
|
+
// hundreds of milliseconds per load — during which every other panel's
|
|
555
|
+
// request, every other project's, and the preview watchdog all waited.
|
|
556
|
+
// That is what made one slow Files load feel like the whole app hanging.
|
|
557
|
+
//
|
|
558
|
+
// Measured against what it protects: `Value.Decode` returns the very
|
|
559
|
+
// same object reference and strips nothing (there is not one
|
|
560
|
+
// `t.Transform` in the codebase), so removing it cannot change a
|
|
561
|
+
// successful response by even one byte.
|
|
562
|
+
const validatedResponse = result;
|
|
544
563
|
|
|
545
564
|
// Check if response contains binary data
|
|
546
565
|
if (isBinaryAction(responseAction, validatedResponse)) {
|
|
@@ -628,7 +647,39 @@ export class WSRouter<
|
|
|
628
647
|
// ═══ END AUTH GATE ═══
|
|
629
648
|
|
|
630
649
|
// ═══ RATE LIMIT GATE ═══
|
|
631
|
-
|
|
650
|
+
// A request-response route has a caller blocked on its reply; an event
|
|
651
|
+
// does not. The limiter needs that distinction to shed the right half
|
|
652
|
+
// of a flood, and the answer below needs it to know whether anyone is
|
|
653
|
+
// listening for one.
|
|
654
|
+
const isRequest = this.httpRoutes.has(action);
|
|
655
|
+
if (this.rateLimiter && !this.rateLimiter(conn, action, isRequest)) {
|
|
656
|
+
// A dropped request must still be ANSWERED. Returning silently here
|
|
657
|
+
// left `ws.http()` waiting on a reply that was never coming, so the
|
|
658
|
+
// caller hung for its full 30s timeout and then tore the whole
|
|
659
|
+
// socket down to "heal" it — which re-ran every panel's reconnect
|
|
660
|
+
// handler at once, producing the very burst that tripped the limiter
|
|
661
|
+
// again. Telling the client no is what breaks that loop: the request
|
|
662
|
+
// fails immediately, the caller retries on its own terms, and the
|
|
663
|
+
// connection survives.
|
|
664
|
+
//
|
|
665
|
+
// The auth gate directly above has always done this; the two gates
|
|
666
|
+
// only differed because this one was written to `return` on a path
|
|
667
|
+
// where nothing was waiting for an answer. Fire-and-forget events
|
|
668
|
+
// have no requestId and still just drop.
|
|
669
|
+
if (isRequest) {
|
|
670
|
+
try {
|
|
671
|
+
conn.send(JSON.stringify({
|
|
672
|
+
action: `${action}:response`,
|
|
673
|
+
payload: {
|
|
674
|
+
success: false,
|
|
675
|
+
error: 'Rate limit exceeded — request dropped',
|
|
676
|
+
requestId: payload?.requestId
|
|
677
|
+
}
|
|
678
|
+
}));
|
|
679
|
+
} catch {
|
|
680
|
+
// Connection may already be closing.
|
|
681
|
+
}
|
|
682
|
+
}
|
|
632
683
|
return;
|
|
633
684
|
}
|
|
634
685
|
// ═══ END RATE LIMIT GATE ═══
|