@lensmcp/cluster 1.12.0 → 1.14.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.
- package/executors/gateway/gateway.lib.d.ts +15 -167
- package/executors/gateway/gateway.lib.d.ts.map +1 -1
- package/executors/gateway/gateway.lib.js +24 -1041
- package/executors/gateway/main.prod-gateway.js +74 -2
- package/executors/gateway/prod-gateway.lib.d.ts +19 -151
- package/executors/gateway/prod-gateway.lib.d.ts.map +1 -1
- package/executors/gateway/prod-gateway.lib.js +16 -863
- package/executors/gateway/prod-runtime/access-log.d.ts +9 -0
- package/executors/gateway/prod-runtime/access-log.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/access-log.js +24 -0
- package/executors/gateway/prod-runtime/app.d.ts +23 -0
- package/executors/gateway/prod-runtime/app.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/app.js +123 -0
- package/executors/gateway/prod-runtime/auth.d.ts +30 -0
- package/executors/gateway/prod-runtime/auth.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/auth.js +51 -0
- package/executors/gateway/prod-runtime/cors.d.ts +19 -0
- package/executors/gateway/prod-runtime/cors.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/cors.js +40 -0
- package/executors/gateway/prod-runtime/edge.d.ts +16 -0
- package/executors/gateway/prod-runtime/edge.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/edge.js +65 -0
- package/executors/gateway/prod-runtime/handler.d.ts +32 -0
- package/executors/gateway/prod-runtime/handler.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/handler.js +226 -0
- package/executors/gateway/prod-runtime/hooks.d.ts +20 -0
- package/executors/gateway/prod-runtime/hooks.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/hooks.js +42 -0
- package/executors/gateway/prod-runtime/observability.d.ts +23 -0
- package/executors/gateway/prod-runtime/observability.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/observability.js +125 -0
- package/executors/gateway/prod-runtime/rollout.d.ts +18 -0
- package/executors/gateway/prod-runtime/rollout.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/rollout.js +103 -0
- package/executors/gateway/prod-runtime/routing.d.ts +4 -0
- package/executors/gateway/prod-runtime/routing.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/routing.js +40 -0
- package/executors/gateway/prod-runtime/server.d.ts +3 -0
- package/executors/gateway/prod-runtime/server.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/server.js +79 -0
- package/executors/gateway/prod-runtime/trust.d.ts +12 -0
- package/executors/gateway/prod-runtime/trust.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/trust.js +32 -0
- package/executors/gateway/prod-runtime/types.d.ts +241 -0
- package/executors/gateway/prod-runtime/types.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/types.js +2 -0
- package/executors/gateway/prod-runtime/upgrade.d.ts +21 -0
- package/executors/gateway/prod-runtime/upgrade.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/upgrade.js +116 -0
- package/executors/gateway/prod-runtime/upstream.d.ts +13 -0
- package/executors/gateway/prod-runtime/upstream.d.ts.map +1 -0
- package/executors/gateway/prod-runtime/upstream.js +21 -0
- package/executors/gateway/runtime/auth.d.ts +8 -0
- package/executors/gateway/runtime/auth.d.ts.map +1 -0
- package/executors/gateway/runtime/auth.js +60 -0
- package/executors/gateway/runtime/dev-auth.d.ts +9 -0
- package/executors/gateway/runtime/dev-auth.d.ts.map +1 -0
- package/executors/gateway/runtime/dev-auth.js +79 -0
- package/executors/gateway/runtime/discovery.d.ts +17 -0
- package/executors/gateway/runtime/discovery.d.ts.map +1 -0
- package/executors/gateway/runtime/discovery.js +111 -0
- package/executors/gateway/runtime/edge.d.ts +31 -0
- package/executors/gateway/runtime/edge.d.ts.map +1 -0
- package/executors/gateway/runtime/edge.js +47 -0
- package/executors/gateway/runtime/handler.d.ts +24 -0
- package/executors/gateway/runtime/handler.d.ts.map +1 -0
- package/executors/gateway/runtime/handler.js +165 -0
- package/executors/gateway/runtime/hooks.d.ts +23 -0
- package/executors/gateway/runtime/hooks.d.ts.map +1 -0
- package/executors/gateway/runtime/hooks.js +55 -0
- package/executors/gateway/runtime/lens-children.d.ts +13 -0
- package/executors/gateway/runtime/lens-children.d.ts.map +1 -0
- package/executors/gateway/runtime/lens-children.js +136 -0
- package/executors/gateway/runtime/lifecycle.d.ts +13 -0
- package/executors/gateway/runtime/lifecycle.d.ts.map +1 -0
- package/executors/gateway/runtime/lifecycle.js +179 -0
- package/executors/gateway/runtime/observability.d.ts +17 -0
- package/executors/gateway/runtime/observability.d.ts.map +1 -0
- package/executors/gateway/runtime/observability.js +107 -0
- package/executors/gateway/runtime/proxy.d.ts +20 -0
- package/executors/gateway/runtime/proxy.d.ts.map +1 -0
- package/executors/gateway/runtime/proxy.js +113 -0
- package/executors/gateway/runtime/scope.d.ts +16 -0
- package/executors/gateway/runtime/scope.d.ts.map +1 -0
- package/executors/gateway/runtime/scope.js +68 -0
- package/executors/gateway/runtime/server.d.ts +3 -0
- package/executors/gateway/runtime/server.d.ts.map +1 -0
- package/executors/gateway/runtime/server.js +168 -0
- package/executors/gateway/runtime/service-keys.d.ts +11 -0
- package/executors/gateway/runtime/service-keys.d.ts.map +1 -0
- package/executors/gateway/runtime/service-keys.js +49 -0
- package/executors/gateway/runtime/types.d.ts +234 -0
- package/executors/gateway/runtime/types.d.ts.map +1 -0
- package/executors/gateway/runtime/types.js +2 -0
- package/executors/gateway/runtime/upgrade.d.ts +22 -0
- package/executors/gateway/runtime/upgrade.d.ts.map +1 -0
- package/executors/gateway/runtime/upgrade.js +63 -0
- package/package.json +3 -3
|
@@ -1,171 +1,19 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Public facade for the dev gateway runtime.
|
|
3
|
+
*
|
|
4
|
+
* The implementation now lives in `./runtime/*` as composable LAYERS — see
|
|
5
|
+
* `runtime/server.ts` for the composition root (`startGateway`), `runtime/types.ts`
|
|
6
|
+
* for the shared types + the customer **hooks** API, and the sibling modules for
|
|
7
|
+
* each layer (discovery, dev-auth, observability, lifecycle, lens-children, proxy,
|
|
8
|
+
* auth, hooks, handler, upgrade). This barrel preserves the original module's
|
|
9
|
+
* public surface so the executor wrapper (`gateway.impl.ts`) and the existing
|
|
10
|
+
* specs keep importing from one stable path, and additionally exposes the new
|
|
11
|
+
* hooks types so customers can author typed layers on top of the gateway.
|
|
5
12
|
*/
|
|
6
|
-
import { type ChildProcess } from 'node:child_process';
|
|
7
|
-
import * as http from 'node:http';
|
|
8
|
-
import type { GatewayExecutorSchema } from './schema';
|
|
9
|
-
import { type AuthPolicy } from './manifest';
|
|
10
13
|
export { hostMatches } from './manifest';
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export declare function verifyDevJwt(req: http.IncomingMessage): Record<string, unknown> | undefined;
|
|
17
|
-
/** Stamp verified identity onto the forwarded request — tenant from the `tid` CLAIM, never a client header. */
|
|
18
|
-
export declare function stampIdentity(req: http.IncomingMessage, claims: Record<string, unknown>): void;
|
|
19
|
-
export interface GatewayContext {
|
|
20
|
-
root: string;
|
|
21
|
-
projectName?: string;
|
|
22
|
-
projectsConfigurations?: {
|
|
23
|
-
projects: Record<string, {
|
|
24
|
-
root: string;
|
|
25
|
-
}>;
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
/** Per-project declaration: top-level `cluster` field in project.json (`davnx` legacy). */
|
|
29
|
-
export interface ClusterProjectDecl {
|
|
30
|
-
/** Public dev hostname (e.g. `api.tetros.ai.local`). */
|
|
31
|
-
host?: string;
|
|
32
|
-
/** Mount PATH under the host — backend services share api.<domain> path-routed (e.g. `/channels`). */
|
|
33
|
-
path?: string;
|
|
34
|
-
/**
|
|
35
|
-
* Socket-pool mode (the "pods" model): the cluster devserver's service
|
|
36
|
-
* name. The gateway round-robins DIRECTLY over its children's unix
|
|
37
|
-
* sockets (`$TMPDIR/<service>-devserver/child-*.sock`) — one load
|
|
38
|
-
* balancer in front of N pods, like production. Also auto-exposes
|
|
39
|
-
* `internal.<host>` for east-west calls that SKIP the middleware (JWT).
|
|
40
|
-
*/
|
|
41
|
-
service?: string;
|
|
42
|
-
/** TCP mode (vite apps etc.): where the dev server listens. */
|
|
43
|
-
upstream?: string;
|
|
44
|
-
/** Shorthand for upstream. */
|
|
45
|
-
port?: number;
|
|
46
|
-
/** Prepend to forwarded URLs (e.g. `/api` for an app mounted under a prefix). */
|
|
47
|
-
prependPrefix?: string;
|
|
48
|
-
/** This project also serves unmatched hostnames (the catch-all). */
|
|
49
|
-
default?: boolean;
|
|
50
|
-
/** Override the auto `internal.<host>` name, or `false` to disable it. */
|
|
51
|
-
internalHost?: string | false;
|
|
52
|
-
/** Edge auth policy (default + per-path overrides) — generated from controller decorators
|
|
53
|
-
* by @tetros-server/gateway-sync; the gateway verifies + injects identity + enforces it.
|
|
54
|
-
* Absent ⇒ the service is unguarded at the edge (current behavior — opt-in enforcement). */
|
|
55
|
-
auth?: AuthPolicy;
|
|
56
|
-
/** Start at gateway boot (true) or on first request — scale from zero (false, default). */
|
|
57
|
-
eager?: boolean;
|
|
58
|
-
/** Pod range: spawn with min, autoscale up to max while requests overlap. */
|
|
59
|
-
minPods?: number;
|
|
60
|
-
maxPods?: number;
|
|
61
|
-
/** Kill a gateway-spawned (non-eager) service after this many idle seconds. */
|
|
62
|
-
idleKillSec?: number;
|
|
63
|
-
/** Nx target that runs the service. Default serve-hmr. */
|
|
64
|
-
serveTarget?: string;
|
|
65
|
-
/** Devserver admin endpoint for scaling (default from port: http(s)://localhost:<port>). */
|
|
66
|
-
adminUrl?: string;
|
|
67
|
-
/**
|
|
68
|
-
* FRONTEND apps only: run this app UNDER the lens. When true, the gateway
|
|
69
|
-
* SPAWNS the app's own Vite dev server with `@lensmcp/vite-plugin`
|
|
70
|
-
* instrumentation + a browser-capture sidecar (via the shared
|
|
71
|
-
* `spawnLensFrontend` helper) and routes THAT as the upstream — instead of
|
|
72
|
-
* assuming an external Vite already runs on `port`/`upstream`. The
|
|
73
|
-
* cluster-wide singletons (dashboard + MCP) are owned by the gateway, so a
|
|
74
|
-
* `lens:true` app never spawns its own. Absent/false ⇒ today's behavior
|
|
75
|
-
* (plain TCP upstream; bring-your-own Vite). Ignored for pod (`service`) decls.
|
|
76
|
-
*/
|
|
77
|
-
lens?: boolean;
|
|
78
|
-
}
|
|
79
|
-
export interface SockPool {
|
|
80
|
-
dir: string;
|
|
81
|
-
socks: string[];
|
|
82
|
-
idx: number;
|
|
83
|
-
scannedAt: number;
|
|
84
|
-
}
|
|
85
|
-
export interface Route {
|
|
86
|
-
host?: string;
|
|
87
|
-
prefix?: string;
|
|
88
|
-
project: string;
|
|
89
|
-
prependPrefix?: string;
|
|
90
|
-
target?: string;
|
|
91
|
-
pool?: SockPool;
|
|
92
|
-
svc?: ServiceCtl;
|
|
93
|
-
internal?: boolean;
|
|
94
|
-
auth?: AuthPolicy;
|
|
95
|
-
/** Frontend `lens:true` route: the gateway spawns this app's Vite + lens
|
|
96
|
-
* instrumentation as the upstream (see `LensFrontend`). */
|
|
97
|
-
lens?: LensFrontend;
|
|
98
|
-
}
|
|
99
|
-
/** A frontend app the gateway runs UNDER the lens (`cluster.lens: true`). The
|
|
100
|
-
* gateway spawns its Vite + browser capture as the upstream, deterministically
|
|
101
|
-
* on `port`, and never spawns the per-app dashboard/MCP (those are singletons
|
|
102
|
-
* the gateway owns). */
|
|
103
|
-
export interface LensFrontend {
|
|
104
|
-
project: string;
|
|
105
|
-
/** Absolute project root (holds vite.config.*). */
|
|
106
|
-
projectRoot: string;
|
|
107
|
-
/** The pinned Vite dev port (also the upstream target's port). */
|
|
108
|
-
port: number;
|
|
109
|
-
/** Set once the Vite child has been spawned (idempotency guard). */
|
|
110
|
-
started?: boolean;
|
|
111
|
-
}
|
|
112
|
-
export interface ServiceCtl {
|
|
113
|
-
project: string;
|
|
114
|
-
decl: ClusterProjectDecl;
|
|
115
|
-
pool: SockPool;
|
|
116
|
-
proc?: ChildProcess;
|
|
117
|
-
state: 'down' | 'starting' | 'up';
|
|
118
|
-
lastUsed: number;
|
|
119
|
-
inflight: number;
|
|
120
|
-
lastScaleAt: number;
|
|
121
|
-
spawnAt?: number;
|
|
122
|
-
lastErrors?: string[];
|
|
123
|
-
buildFailed?: boolean;
|
|
124
|
-
}
|
|
125
|
-
/** Test-tunable knobs on top of the user-facing schema. */
|
|
126
|
-
export interface GatewayRuntimeOptions extends GatewayExecutorSchema {
|
|
127
|
-
/** Traffic-edge flush period (ms). Default 5000. */
|
|
128
|
-
trafficFlushMs?: number;
|
|
129
|
-
/** Idle sweeper period (ms). Default 10000. */
|
|
130
|
-
sweepMs?: number;
|
|
131
|
-
/** Sock-dir rescan TTL (ms). Default 1500. */
|
|
132
|
-
scanTtlMs?: number;
|
|
133
|
-
/** Cold-start wait budget (ms). Default 120000. */
|
|
134
|
-
startupTimeoutMs?: number;
|
|
135
|
-
}
|
|
136
|
-
export interface GatewayHandle {
|
|
137
|
-
/** Ports actually bound (resolves `0` to the assigned ephemeral port). */
|
|
138
|
-
ports: number[];
|
|
139
|
-
routes: Route[];
|
|
140
|
-
services: ServiceCtl[];
|
|
141
|
-
stop: () => Promise<void>;
|
|
142
|
-
}
|
|
143
|
-
/** The base domain for the lens dashboard host — the longest common dotted
|
|
144
|
-
* suffix of the declared cluster hosts (e.g. ['api.tetros.ai.local',
|
|
145
|
-
* 'tetros.ai.local'] → 'tetros.ai.local'). Falls back to the first host, then
|
|
146
|
-
* to 'lens.local' if no host is declared. */
|
|
147
|
-
export declare function baseDomainOf(hosts: string[]): string;
|
|
148
|
-
/** Per-workspace lens scope (key + dashboard port + mount path). Prefers the
|
|
149
|
-
* CLI-written `.lensmcp/config.json` (so the gateway agrees with `lensmcp gateway`
|
|
150
|
-
* / `lensmcp dashboard`); falls back to deriving from the workspace. Mirrors the
|
|
151
|
-
* derivation in the `lensmcp` CLI's `workspace-scope` (kept in lock-step). */
|
|
152
|
-
export declare function readLensScope(root: string): {
|
|
153
|
-
key: string;
|
|
154
|
-
dashboardPort: number;
|
|
155
|
-
basePath: string;
|
|
156
|
-
};
|
|
157
|
-
/** Round-robin over the pool's sockets, rescanning the dir when the cache ages out. */
|
|
158
|
-
export declare function pickSock(pool: SockPool, scanTtlMs?: number): string | undefined;
|
|
159
|
-
/**
|
|
160
|
-
* Read every project's `cluster` (or legacy `davnx`) declaration and build
|
|
161
|
-
* the route table: host routes first (plus auto `internal.<host>` for pod
|
|
162
|
-
* services), the `default` catch-all last.
|
|
163
|
-
*/
|
|
164
|
-
export declare function discoverRoutes(rootDir: string, projects: Record<string, {
|
|
165
|
-
root: string;
|
|
166
|
-
}>, sockBaseDir?: string): {
|
|
167
|
-
routes: Route[];
|
|
168
|
-
services: ServiceCtl[];
|
|
169
|
-
};
|
|
170
|
-
export declare function startGateway(options: GatewayRuntimeOptions, context: GatewayContext): Promise<GatewayHandle>;
|
|
14
|
+
export { startGateway } from './runtime/server';
|
|
15
|
+
export { verifyDevJwt, stampIdentity } from './runtime/dev-auth';
|
|
16
|
+
export { baseDomainOf, readLensScope } from './runtime/scope';
|
|
17
|
+
export { pickSock, discoverRoutes } from './runtime/discovery';
|
|
18
|
+
export type { GatewayContext, ClusterProjectDecl, SockPool, Route, LensFrontend, ServiceCtl, GatewayRuntimeOptions, GatewayHandle, GatewayHooks, GatewayPhase, HookHandler, HookContext, } from './runtime/types';
|
|
171
19
|
//# sourceMappingURL=gateway.lib.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"gateway.lib.d.ts","sourceRoot":"","sources":["../../../../../libs/cluster/src/executors/gateway/gateway.lib.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"gateway.lib.d.ts","sourceRoot":"","sources":["../../../../../libs/cluster/src/executors/gateway/gateway.lib.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEzC,OAAO,EAAE,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,QAAQ,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAE/D,YAAY,EACV,cAAc,EACd,kBAAkB,EAClB,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,UAAU,EACV,qBAAqB,EACrB,aAAa,EAEb,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,WAAW,GACZ,MAAM,iBAAiB,CAAC"}
|