@claxedo/workspace-relay 0.8.0 → 0.10.0

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.
@@ -1,60 +0,0 @@
1
- /**
2
- * T10: Synthetic end-to-end probe.
3
- *
4
- * Liveness depends on metrics; metrics can lie. A synthetic probe periodically
5
- * exercises the relay's HTTP path and records RTT so we have an independent
6
- * signal that the data path actually works.
7
- *
8
- * Implementation notes
9
- * --------------------
10
- * - The probe targets `${relayUrl}/health` rather than minting a Runtime
11
- * Access Token and hitting `/workspaces/<id>/...`. `/health` validates HTTP
12
- * connectivity end-to-end without pretending the Relay owns Control Plane
13
- * token issuance.
14
- * - All clocks, timers and `fetch` are injectable so tests stay deterministic.
15
- * - "Loud" logs after 3 consecutive failures use `console.error` by default;
16
- * pageability (PagerDuty / equivalent) is wired separately.
17
- */
18
- export type SyntheticProbeStats = {
19
- successCount: number;
20
- failureCount: number;
21
- consecutiveFailures: number;
22
- /** RTT (ms) of the most recent probe attempt. Undefined before the first probe completes. */
23
- lastRttMs?: number;
24
- /** p50 / p99 over the rolling RTT window. Undefined if no successes yet. */
25
- p50?: number;
26
- p99?: number;
27
- /** Number of RTTs currently in the rolling window. */
28
- windowSize: number;
29
- };
30
- export type SyntheticProbe = {
31
- stop(): void;
32
- stats(): SyntheticProbeStats;
33
- };
34
- export type SyntheticProbeOptions = {
35
- /** Base URL of the relay, e.g. `http://127.0.0.1:7777`. No trailing slash required. */
36
- relayUrl: string;
37
- /** Probe cadence. Default 60_000 (60 s). */
38
- intervalMs?: number;
39
- /** Summary log cadence (p50/p99). Default 300_000 (5 min). */
40
- summaryIntervalMs?: number;
41
- /** Path to probe. Default `/health`. */
42
- probePath?: string;
43
- /** Rolling window size for RTT percentile calculation. Default 100. */
44
- rttWindowSize?: number;
45
- /** Number of consecutive failures that triggers a loud log. Default 3. */
46
- loudFailureThreshold?: number;
47
- /** Override `fetch`. Defaults to global `fetch`. */
48
- fetch?: typeof fetch;
49
- /** Override clock for tests. Defaults to `Date.now`. */
50
- now?: () => number;
51
- /** Override `setInterval` for tests. Defaults to global `setInterval`. */
52
- setInterval?: typeof setInterval;
53
- /** Override `clearInterval` for tests. Defaults to global `clearInterval`. */
54
- clearInterval?: typeof clearInterval;
55
- /** Loud-failure logger. Defaults to `console.error`. */
56
- logError?: (msg: string, fields?: Record<string, unknown>) => void;
57
- /** Periodic summary logger (p50/p99). Defaults to `console.log`. */
58
- logSummary?: (msg: string, fields?: Record<string, unknown>) => void;
59
- };
60
- export declare function startSyntheticProbe(options: SyntheticProbeOptions): SyntheticProbe;
@@ -1,34 +0,0 @@
1
- /**
2
- * The relay's upstream WebSocket constructor, and the one place that names it.
3
- *
4
- * A relay client socket is proxied to a workspace runtime over a second,
5
- * outbound WebSocket that must carry the runtime's auth headers. Bun's global
6
- * `WebSocket` really does accept `(url, { headers })` — but that shape is not
7
- * expressible in this package's type program, for a reason that is worth
8
- * writing down once rather than rediscovering at the call site:
9
- *
10
- * `bun-types` yields its own `WebSocket` declaration to `lib.dom` whenever
11
- * `lib.dom` is loaded (`Bun.__internal.UseLibDomIfAvailable`), and `lib.dom`
12
- * declares only the `(url, protocols)` overload — on a `declare var`, which
13
- * cannot be augmented. So while `lib.dom` is in `tsconfig.json`, the real
14
- * constructor is unreachable through the global's type.
15
- *
16
- * Dropping `lib.dom` (as `bench/tsconfig.json` does) fixes THIS and breaks more
17
- * than it fixes: `bun-types`' `Request` constructor declares `string`,
18
- * `RequestInit & { url }` and `Request` inputs and no `URL` input at all, which
19
- * this package and its tests rely on.
20
- *
21
- * The assertion is therefore genuine — the type system cannot express the
22
- * value — and it is confined to this module so that the lint override excusing
23
- * it covers ~40 lines whose only job is this constructor, rather than blinding
24
- * the 4,000-line `bun.ts` that consumes it.
25
- */
26
- export type UpstreamWebSocketConstructor = {
27
- new (url: string, options: Bun.WebSocketOptions): WebSocket;
28
- };
29
- /**
30
- * The constructor used to open the upstream socket: the caller's override when
31
- * one is supplied (tests inject fakes to drive open timeouts, pre-open queue
32
- * limits and abnormal closes), otherwise Bun's global `WebSocket`.
33
- */
34
- export declare function resolveUpstreamWebSocket(override?: UpstreamWebSocketConstructor): UpstreamWebSocketConstructor;
@@ -1,40 +0,0 @@
1
- import type { RelayAccess } from "./auth";
2
- /**
3
- * The canonical "is this relay target user-hosted" rule.
4
- *
5
- * A user-hosted workspace runs on the user's own laptop (backing:
6
- * "local-worktree"); a cloud workspace runs on a dedicated cloud VM
7
- * (backing: "cloud-vm"). `RelayAccess` has exactly these two members, so
8
- * `access === "user-hosted"` and `access !== "cloud"` are equivalent — but
9
- * spelling the check either way at each call site invites drift if a third
10
- * access kind is ever added. Every caller that needs to branch on this
11
- * (choosing a forwarding path, tagging a socket, deciding whether to strip
12
- * Cookie) should go through this one predicate instead.
13
- */
14
- export declare function isUserHostedTarget(target: {
15
- access: RelayAccess;
16
- }): boolean;
17
- export type WorkspaceRelaySocketKind = "user-hosted-client" | "client";
18
- /**
19
- * The socket-kind tag applied when a relay client is admitted against
20
- * `target`. A user-hosted target is multiplexed over the host tunnel
21
- * (`"user-hosted-client"`); a cloud target gets a direct upstream socket
22
- * (`"client"`).
23
- */
24
- export declare function socketKindFor(target: {
25
- access: RelayAccess;
26
- }): WorkspaceRelaySocketKind;
27
- /**
28
- * Privacy rule: never forward the browser's `Cookie` header into a
29
- * user-hosted workspace. Its host process runs on the user's own laptop and
30
- * may share a cookie jar with the browser (e.g. localhost dev tooling), so
31
- * passing cookies through verbatim risks leaking session data to the host.
32
- * Cloud-vm workspaces sit behind a dedicated network boundary where session
33
- * cookies may legitimately be needed (e.g. workspace dashboards), so cloud
34
- * targets pass `Cookie` through unchanged.
35
- *
36
- * Returns a new `Headers` instance; `headers` is not mutated.
37
- */
38
- export declare function forwardHeadersFor(target: {
39
- access: RelayAccess;
40
- }, headers: Headers): Headers;