@fusionkit/cli 0.1.2 → 0.1.4
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/dist/commands/fusion.js +17 -2
- package/dist/commands/plane.js +10 -2
- package/dist/fusion-config.d.ts +1 -0
- package/dist/fusion-config.js +5 -0
- package/dist/fusion-quickstart.d.ts +33 -34
- package/dist/fusion-quickstart.js +324 -278
- package/dist/shared/portless.d.ts +97 -0
- package/dist/shared/portless.js +253 -0
- package/dist/test/portless.test.d.ts +1 -0
- package/dist/test/portless.test.js +65 -0
- package/package.json +12 -9
- package/scope/.next/BUILD_ID +1 -1
- package/scope/.next/app-build-manifest.json +14 -14
- package/scope/.next/app-path-routes-manifest.json +4 -4
- package/scope/.next/build-manifest.json +2 -2
- package/scope/.next/prerender-manifest.json +13 -13
- package/scope/.next/required-server-files.json +4 -0
- package/scope/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/_not-found.html +1 -1
- package/scope/.next/server/app/_not-found.rsc +1 -1
- package/scope/.next/server/app/api/environments/route_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/api/ingest/route_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/api/models/route_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/api/replay/route_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/api/sessions/[traceId]/route_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/api/sessions/route_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/api/stream/route_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/environments/page_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/environments.html +1 -1
- package/scope/.next/server/app/environments.rsc +1 -1
- package/scope/.next/server/app/index.html +1 -1
- package/scope/.next/server/app/index.rsc +1 -1
- package/scope/.next/server/app/models/page_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/models.html +1 -1
- package/scope/.next/server/app/models.rsc +1 -1
- package/scope/.next/server/app/page_client-reference-manifest.js +1 -1
- package/scope/.next/server/app/sessions/[traceId]/page_client-reference-manifest.js +1 -1
- package/scope/.next/server/app-paths-manifest.json +4 -4
- package/scope/.next/server/functions-config-manifest.json +2 -2
- package/scope/.next/server/pages/404.html +1 -1
- package/scope/.next/server/pages/500.html +1 -1
- package/scope/.next/server/server-reference-manifest.json +1 -1
- package/scope/package.json +3 -1
- package/scope/server.js +1 -1
- /package/scope/.next/static/{hyFZFZhpE5yuTp_t6QAIZ → 5tnFLuvnSbNZNtqRgoot8}/_buildManifest.js +0 -0
- /package/scope/.next/static/{hyFZFZhpE5yuTp_t6QAIZ → 5tnFLuvnSbNZNtqRgoot8}/_ssgManifest.js +0 -0
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic portless integration for the fusion stack.
|
|
3
|
+
*
|
|
4
|
+
* Every dev server and CLI-spawned service the launcher starts is registered
|
|
5
|
+
* with portless as a stable, named `.localhost` route, so humans and external
|
|
6
|
+
* coding agents get clean HTTPS URLs instead of raw ports, and a service can be
|
|
7
|
+
* discovered + reused across runs (a singleton) via the shared route table.
|
|
8
|
+
*
|
|
9
|
+
* Routes are managed entirely against the `portless` *library* (its exported
|
|
10
|
+
* `RouteStore` writes the same file-locked `routes.json` the running proxy reads
|
|
11
|
+
* live) — we never shell out to the `portless` binary. The privileged TLS proxy
|
|
12
|
+
* daemon + CA trust are a one-time user setup (`portless service install` +
|
|
13
|
+
* `portless trust`); here we only detect that it is running and register routes.
|
|
14
|
+
*
|
|
15
|
+
* `portless` requires Node >= 24 and is declared an optional dependency, so on
|
|
16
|
+
* older Node (or when the package/proxy is absent) the session degrades to
|
|
17
|
+
* plain loopback URLs with no discovery — identical code paths, just unproxied.
|
|
18
|
+
*/
|
|
19
|
+
/** Resolve the portless state directory (honoring `PORTLESS_STATE_DIR`). */
|
|
20
|
+
export declare function stateDir(): string;
|
|
21
|
+
/** Path to the portless CA, for `NODE_EXTRA_CA_CERTS` / `SSL_CERT_FILE`. */
|
|
22
|
+
export declare function caCertPath(): string;
|
|
23
|
+
/** The TLD portless serves routes under (default `.localhost`). */
|
|
24
|
+
export declare function tld(): string;
|
|
25
|
+
/** A running portless proxy, as detected from on-disk state + a live probe. */
|
|
26
|
+
export type DetectedProxy = {
|
|
27
|
+
port: number;
|
|
28
|
+
tls: boolean;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Detect a running portless proxy: read `<stateDir>/proxy.port`, confirm the
|
|
32
|
+
* owning pid is alive, and probe the port for the `X-Portless` header (a plain
|
|
33
|
+
* HTTP probe works even against a TLS proxy, which 302-redirects to https and
|
|
34
|
+
* still stamps the header). Returns `undefined` when no proxy is reachable.
|
|
35
|
+
*/
|
|
36
|
+
export declare function detectProxy(): Promise<DetectedProxy | undefined>;
|
|
37
|
+
/** A service the launcher started, addressable through portless. */
|
|
38
|
+
export type SpawnedService = {
|
|
39
|
+
port: number;
|
|
40
|
+
/** Owning pid for the route (defaults to this process). */
|
|
41
|
+
pid?: number;
|
|
42
|
+
close: () => Promise<void> | void;
|
|
43
|
+
};
|
|
44
|
+
export type DiscoverOrSpawnInput = {
|
|
45
|
+
/** Short service name; the `.fusion` project suffix + TLD are added here. */
|
|
46
|
+
name: string;
|
|
47
|
+
/** Expected identity token of a reusable instance (model set, config hash, ...). */
|
|
48
|
+
identity: string;
|
|
49
|
+
/** Probe a candidate instance on its loopback URL; return its identity token. */
|
|
50
|
+
healthCheck: (loopbackUrl: string) => Promise<string | undefined>;
|
|
51
|
+
/** Start a fresh instance when none can be reused. */
|
|
52
|
+
spawn: () => Promise<SpawnedService>;
|
|
53
|
+
};
|
|
54
|
+
export type DiscoverOrSpawnResult = {
|
|
55
|
+
/** The URL callers should surface/inject (portless name, or loopback). */
|
|
56
|
+
url: string;
|
|
57
|
+
/** The loopback URL for in-process CLI fetches (avoids the CA-at-startup hazard). */
|
|
58
|
+
loopbackUrl: string;
|
|
59
|
+
port: number;
|
|
60
|
+
/** True when this run spawned the instance (and therefore owns teardown). */
|
|
61
|
+
owned: boolean;
|
|
62
|
+
/** Tear down only an owned instance; reused instances are left running. */
|
|
63
|
+
close: () => Promise<void> | void;
|
|
64
|
+
};
|
|
65
|
+
/**
|
|
66
|
+
* A live portless session threaded through the launcher. When `enabled` is
|
|
67
|
+
* false (portless off, package absent, or no proxy detected) every method
|
|
68
|
+
* degrades to plain loopback behavior with no proxy registration or discovery.
|
|
69
|
+
*/
|
|
70
|
+
export type PortlessSession = {
|
|
71
|
+
enabled: boolean;
|
|
72
|
+
/** Portless CA path when active, else undefined. */
|
|
73
|
+
caCertPath: string | undefined;
|
|
74
|
+
/** Register `127.0.0.1:<port>` under `<name>.<project>.localhost`; returns the URL. */
|
|
75
|
+
register(name: string, appPort: number): string;
|
|
76
|
+
/** Remove a route this process owns. */
|
|
77
|
+
unregister(name: string): void;
|
|
78
|
+
/** Reuse a compatible running instance, or spawn + register a new one. */
|
|
79
|
+
discoverOrSpawn(input: DiscoverOrSpawnInput): Promise<DiscoverOrSpawnResult>;
|
|
80
|
+
};
|
|
81
|
+
export type CreateSessionInput = {
|
|
82
|
+
/** Whether portless is requested (CLI flag / config / PORTLESS env). */
|
|
83
|
+
enabled: boolean;
|
|
84
|
+
log?: (line: string) => void;
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* Create a portless session. Returns a disabled (loopback) session when
|
|
88
|
+
* portless is off, the library is unavailable (Node < 24 / not installed), or
|
|
89
|
+
* no proxy is running; otherwise an active session backed by `RouteStore`.
|
|
90
|
+
*/
|
|
91
|
+
export declare function createPortlessSession(input: CreateSessionInput): Promise<PortlessSession>;
|
|
92
|
+
/**
|
|
93
|
+
* Reap fusion singleton services: terminate the owning pid of every registered
|
|
94
|
+
* `*.fusion.<tld>` / `scope.<tld>` route and drop the route. Returns the number
|
|
95
|
+
* of services stopped. A no-op when portless is unavailable.
|
|
96
|
+
*/
|
|
97
|
+
export declare function reapFusionServices(log?: (line: string) => void): Promise<number>;
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Programmatic portless integration for the fusion stack.
|
|
3
|
+
*
|
|
4
|
+
* Every dev server and CLI-spawned service the launcher starts is registered
|
|
5
|
+
* with portless as a stable, named `.localhost` route, so humans and external
|
|
6
|
+
* coding agents get clean HTTPS URLs instead of raw ports, and a service can be
|
|
7
|
+
* discovered + reused across runs (a singleton) via the shared route table.
|
|
8
|
+
*
|
|
9
|
+
* Routes are managed entirely against the `portless` *library* (its exported
|
|
10
|
+
* `RouteStore` writes the same file-locked `routes.json` the running proxy reads
|
|
11
|
+
* live) — we never shell out to the `portless` binary. The privileged TLS proxy
|
|
12
|
+
* daemon + CA trust are a one-time user setup (`portless service install` +
|
|
13
|
+
* `portless trust`); here we only detect that it is running and register routes.
|
|
14
|
+
*
|
|
15
|
+
* `portless` requires Node >= 24 and is declared an optional dependency, so on
|
|
16
|
+
* older Node (or when the package/proxy is absent) the session degrades to
|
|
17
|
+
* plain loopback URLs with no discovery — identical code paths, just unproxied.
|
|
18
|
+
*/
|
|
19
|
+
import { existsSync, readFileSync } from "node:fs";
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { join } from "node:path";
|
|
22
|
+
/** The npm scope-less project prefix for fusion service hostnames. */
|
|
23
|
+
const PROJECT = "fusion";
|
|
24
|
+
/** Resolve the portless state directory (honoring `PORTLESS_STATE_DIR`). */
|
|
25
|
+
export function stateDir() {
|
|
26
|
+
return process.env.PORTLESS_STATE_DIR ?? join(homedir(), ".portless");
|
|
27
|
+
}
|
|
28
|
+
/** Path to the portless CA, for `NODE_EXTRA_CA_CERTS` / `SSL_CERT_FILE`. */
|
|
29
|
+
export function caCertPath() {
|
|
30
|
+
return join(stateDir(), "ca.pem");
|
|
31
|
+
}
|
|
32
|
+
/** The TLD portless serves routes under (default `.localhost`). */
|
|
33
|
+
export function tld() {
|
|
34
|
+
return process.env.PORTLESS_TLD ?? "localhost";
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Detect a running portless proxy: read `<stateDir>/proxy.port`, confirm the
|
|
38
|
+
* owning pid is alive, and probe the port for the `X-Portless` header (a plain
|
|
39
|
+
* HTTP probe works even against a TLS proxy, which 302-redirects to https and
|
|
40
|
+
* still stamps the header). Returns `undefined` when no proxy is reachable.
|
|
41
|
+
*/
|
|
42
|
+
export async function detectProxy() {
|
|
43
|
+
const dir = stateDir();
|
|
44
|
+
const portFile = join(dir, "proxy.port");
|
|
45
|
+
if (!existsSync(portFile))
|
|
46
|
+
return undefined;
|
|
47
|
+
const port = Number.parseInt(readFileSync(portFile, "utf8").trim(), 10);
|
|
48
|
+
if (!Number.isInteger(port) || port <= 0)
|
|
49
|
+
return undefined;
|
|
50
|
+
const pidFile = join(dir, "proxy.pid");
|
|
51
|
+
if (existsSync(pidFile)) {
|
|
52
|
+
const pid = Number.parseInt(readFileSync(pidFile, "utf8").trim(), 10);
|
|
53
|
+
if (Number.isInteger(pid) && pid > 0 && !isAlive(pid))
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
// Prefer the proxy's recorded TLS mode; fall back to inferring it from the
|
|
57
|
+
// redirect a plain-HTTP probe gets (a TLS proxy 302s to https).
|
|
58
|
+
const tlsFile = join(dir, "proxy.tls");
|
|
59
|
+
const tlsFromFile = existsSync(tlsFile)
|
|
60
|
+
? ["1", "true"].includes(readFileSync(tlsFile, "utf8").trim().toLowerCase())
|
|
61
|
+
: undefined;
|
|
62
|
+
try {
|
|
63
|
+
const response = await fetch(`http://127.0.0.1:${port}/`, {
|
|
64
|
+
redirect: "manual",
|
|
65
|
+
signal: AbortSignal.timeout(1500)
|
|
66
|
+
});
|
|
67
|
+
if (response.headers.get("x-portless") === null)
|
|
68
|
+
return undefined;
|
|
69
|
+
const location = response.headers.get("location");
|
|
70
|
+
const tls = tlsFromFile ?? (port === 443 || (location !== null && location.startsWith("https://")));
|
|
71
|
+
return { port, tls };
|
|
72
|
+
}
|
|
73
|
+
catch {
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
function isAlive(pid) {
|
|
78
|
+
try {
|
|
79
|
+
process.kill(pid, 0);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
// EPERM means the process exists but is owned by another user (e.g. the
|
|
84
|
+
// portless proxy installed as a root LaunchDaemon) — still alive. Only
|
|
85
|
+
// ESRCH ("no such process") means it is actually gone.
|
|
86
|
+
return error?.code === "EPERM";
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
async function loadPortless() {
|
|
90
|
+
// Variable specifier + dynamic import: `portless` is an optional dependency
|
|
91
|
+
// (Node >= 24 only), so this must not be a static import — it would break the
|
|
92
|
+
// build/install on Node 22. Documented exception to the no-inline-imports rule.
|
|
93
|
+
const specifier = "portless";
|
|
94
|
+
try {
|
|
95
|
+
return (await import(specifier));
|
|
96
|
+
}
|
|
97
|
+
catch {
|
|
98
|
+
return undefined;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
/** Names that stay bare (`<name>.localhost`) instead of being namespaced under the project. */
|
|
102
|
+
const BARE_NAMES = new Set(["scope"]);
|
|
103
|
+
/** Map a short service name to its portless hostname. */
|
|
104
|
+
function hostnameFor(portless, name) {
|
|
105
|
+
// `scope` stays bare (`scope.localhost`); everything else is namespaced under
|
|
106
|
+
// the project (`gateway.fusion.localhost`). A name already containing a dot or
|
|
107
|
+
// equal to the project is treated as an explicit subdomain path.
|
|
108
|
+
const full = name === PROJECT || name.includes(".") || BARE_NAMES.has(name) ? name : `${name}.${PROJECT}`;
|
|
109
|
+
return portless.parseHostname(full, tld());
|
|
110
|
+
}
|
|
111
|
+
const loopback = (port) => `http://127.0.0.1:${port}`;
|
|
112
|
+
/** Build a disabled session: pure loopback, no proxy, no discovery. */
|
|
113
|
+
function disabledSession() {
|
|
114
|
+
return {
|
|
115
|
+
enabled: false,
|
|
116
|
+
caCertPath: undefined,
|
|
117
|
+
register: (_name, appPort) => loopback(appPort),
|
|
118
|
+
unregister: () => { },
|
|
119
|
+
discoverOrSpawn: async (input) => {
|
|
120
|
+
const service = await input.spawn();
|
|
121
|
+
const url = loopback(service.port);
|
|
122
|
+
return { url, loopbackUrl: url, port: service.port, owned: true, close: service.close };
|
|
123
|
+
}
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Create a portless session. Returns a disabled (loopback) session when
|
|
128
|
+
* portless is off, the library is unavailable (Node < 24 / not installed), or
|
|
129
|
+
* no proxy is running; otherwise an active session backed by `RouteStore`.
|
|
130
|
+
*/
|
|
131
|
+
export async function createPortlessSession(input) {
|
|
132
|
+
if (!input.enabled)
|
|
133
|
+
return disabledSession();
|
|
134
|
+
const portless = await loadPortless();
|
|
135
|
+
if (portless === undefined) {
|
|
136
|
+
input.log?.("fusion: portless not installed (needs Node >= 24); using loopback URLs");
|
|
137
|
+
return disabledSession();
|
|
138
|
+
}
|
|
139
|
+
const proxy = await detectProxy();
|
|
140
|
+
if (proxy === undefined) {
|
|
141
|
+
// Portless is installed but its proxy isn't running: degrade to loopback
|
|
142
|
+
// (never block a run) and point the user at the one-time setup for stable
|
|
143
|
+
// HTTPS names.
|
|
144
|
+
input.log?.("fusion: portless proxy not running; using loopback URLs " +
|
|
145
|
+
"(run `portless service install` + `portless trust` for stable https://*.localhost names)");
|
|
146
|
+
return disabledSession();
|
|
147
|
+
}
|
|
148
|
+
const store = new portless.RouteStore(stateDir(), {
|
|
149
|
+
onWarning: (message) => input.log?.(`fusion: portless: ${message}`)
|
|
150
|
+
});
|
|
151
|
+
const urlFor = (hostname) => portless.formatUrl(hostname, proxy.port, proxy.tls);
|
|
152
|
+
const register = (name, appPort) => {
|
|
153
|
+
try {
|
|
154
|
+
const hostname = hostnameFor(portless, name);
|
|
155
|
+
store.addRoute(hostname, appPort, process.pid, true);
|
|
156
|
+
return urlFor(hostname);
|
|
157
|
+
}
|
|
158
|
+
catch (error) {
|
|
159
|
+
// Never let a routing hiccup break a run; fall back to the raw port.
|
|
160
|
+
input.log?.(`fusion: portless register(${name}) failed: ${errorText(error)}`);
|
|
161
|
+
return loopback(appPort);
|
|
162
|
+
}
|
|
163
|
+
};
|
|
164
|
+
const unregister = (name) => {
|
|
165
|
+
try {
|
|
166
|
+
store.removeRoute(hostnameFor(portless, name), process.pid);
|
|
167
|
+
}
|
|
168
|
+
catch {
|
|
169
|
+
// best-effort
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
const discoverOrSpawn = async (req) => {
|
|
173
|
+
const hostname = hostnameFor(portless, req.name);
|
|
174
|
+
// Discover: is a compatible instance already registered and alive?
|
|
175
|
+
try {
|
|
176
|
+
const existing = store.loadRoutes().find((route) => route.hostname === hostname);
|
|
177
|
+
if (existing !== undefined) {
|
|
178
|
+
const candidate = loopback(existing.port);
|
|
179
|
+
const identity = await req.healthCheck(candidate);
|
|
180
|
+
if (identity === req.identity) {
|
|
181
|
+
return {
|
|
182
|
+
url: urlFor(hostname),
|
|
183
|
+
loopbackUrl: candidate,
|
|
184
|
+
port: existing.port,
|
|
185
|
+
owned: false,
|
|
186
|
+
close: () => { }
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
catch (error) {
|
|
192
|
+
input.log?.(`fusion: portless discover(${req.name}) failed: ${errorText(error)}`);
|
|
193
|
+
}
|
|
194
|
+
// Spawn + register a fresh instance, owned by the service pid so the proxy's
|
|
195
|
+
// liveness filter keeps the route across runs and only drops it when the
|
|
196
|
+
// service itself exits.
|
|
197
|
+
const service = await req.spawn();
|
|
198
|
+
let url = loopback(service.port);
|
|
199
|
+
try {
|
|
200
|
+
store.addRoute(hostname, service.port, service.pid ?? process.pid, true);
|
|
201
|
+
url = urlFor(hostname);
|
|
202
|
+
}
|
|
203
|
+
catch (error) {
|
|
204
|
+
input.log?.(`fusion: portless register(${req.name}) failed: ${errorText(error)}`);
|
|
205
|
+
}
|
|
206
|
+
return {
|
|
207
|
+
url,
|
|
208
|
+
loopbackUrl: loopback(service.port),
|
|
209
|
+
port: service.port,
|
|
210
|
+
owned: true,
|
|
211
|
+
close: service.close
|
|
212
|
+
};
|
|
213
|
+
};
|
|
214
|
+
return { enabled: true, caCertPath: caCertPath(), register, unregister, discoverOrSpawn };
|
|
215
|
+
}
|
|
216
|
+
function errorText(error) {
|
|
217
|
+
return error instanceof Error ? error.message : String(error);
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Reap fusion singleton services: terminate the owning pid of every registered
|
|
221
|
+
* `*.fusion.<tld>` / `scope.<tld>` route and drop the route. Returns the number
|
|
222
|
+
* of services stopped. A no-op when portless is unavailable.
|
|
223
|
+
*/
|
|
224
|
+
export async function reapFusionServices(log) {
|
|
225
|
+
const portless = await loadPortless();
|
|
226
|
+
if (portless === undefined)
|
|
227
|
+
return 0;
|
|
228
|
+
const store = new portless.RouteStore(stateDir(), {
|
|
229
|
+
onWarning: (message) => log?.(`fusion: portless: ${message}`)
|
|
230
|
+
});
|
|
231
|
+
const suffix = `.${PROJECT}.${tld()}`;
|
|
232
|
+
const scopeHost = portless.parseHostname("scope", tld());
|
|
233
|
+
let stopped = 0;
|
|
234
|
+
for (const route of store.loadRoutes()) {
|
|
235
|
+
if (!route.hostname.endsWith(suffix) && route.hostname !== scopeHost)
|
|
236
|
+
continue;
|
|
237
|
+
try {
|
|
238
|
+
process.kill(route.pid, "SIGTERM");
|
|
239
|
+
stopped += 1;
|
|
240
|
+
log?.(`fusion: stopped ${route.hostname} (pid ${route.pid})`);
|
|
241
|
+
}
|
|
242
|
+
catch {
|
|
243
|
+
// process already gone; still drop the stale route below
|
|
244
|
+
}
|
|
245
|
+
try {
|
|
246
|
+
store.removeRoute(route.hostname);
|
|
247
|
+
}
|
|
248
|
+
catch {
|
|
249
|
+
// best-effort
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
return stopped;
|
|
253
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { tmpdir } from "node:os";
|
|
4
|
+
import { join } from "node:path";
|
|
5
|
+
import { after, test } from "node:test";
|
|
6
|
+
import { caCertPath, createPortlessSession, detectProxy, stateDir } from "../shared/portless.js";
|
|
7
|
+
const tmpRoots = [];
|
|
8
|
+
function freshStateDir() {
|
|
9
|
+
const dir = mkdtempSync(join(tmpdir(), "portless-state-"));
|
|
10
|
+
tmpRoots.push(dir);
|
|
11
|
+
process.env.PORTLESS_STATE_DIR = dir;
|
|
12
|
+
return dir;
|
|
13
|
+
}
|
|
14
|
+
after(() => {
|
|
15
|
+
delete process.env.PORTLESS_STATE_DIR;
|
|
16
|
+
for (const dir of tmpRoots)
|
|
17
|
+
rmSync(dir, { recursive: true, force: true });
|
|
18
|
+
});
|
|
19
|
+
test("stateDir + caCertPath honor PORTLESS_STATE_DIR", () => {
|
|
20
|
+
const dir = freshStateDir();
|
|
21
|
+
assert.equal(stateDir(), dir);
|
|
22
|
+
assert.equal(caCertPath(), join(dir, "ca.pem"));
|
|
23
|
+
});
|
|
24
|
+
test("detectProxy returns undefined when no proxy.port file exists", async () => {
|
|
25
|
+
freshStateDir();
|
|
26
|
+
assert.equal(await detectProxy(), undefined);
|
|
27
|
+
});
|
|
28
|
+
test("detectProxy returns undefined for a dead proxy pid", async () => {
|
|
29
|
+
const dir = freshStateDir();
|
|
30
|
+
writeFileSync(join(dir, "proxy.port"), "443");
|
|
31
|
+
// pid 1 is alive but won't answer a portless probe; a clearly-dead pid keeps
|
|
32
|
+
// this deterministic without binding a port.
|
|
33
|
+
writeFileSync(join(dir, "proxy.pid"), "999999999");
|
|
34
|
+
assert.equal(await detectProxy(), undefined);
|
|
35
|
+
});
|
|
36
|
+
test("a disabled session uses loopback URLs and never registers", async () => {
|
|
37
|
+
const session = await createPortlessSession({ enabled: false });
|
|
38
|
+
assert.equal(session.enabled, false);
|
|
39
|
+
assert.equal(session.caCertPath, undefined);
|
|
40
|
+
assert.equal(session.register("scope", 4317), "http://127.0.0.1:4317");
|
|
41
|
+
assert.equal(session.register("gateway", 5123), "http://127.0.0.1:5123");
|
|
42
|
+
session.unregister("scope"); // no throw
|
|
43
|
+
let spawned = 0;
|
|
44
|
+
const result = await session.discoverOrSpawn({
|
|
45
|
+
name: "router",
|
|
46
|
+
identity: "gpt,sonnet",
|
|
47
|
+
healthCheck: async () => "gpt,sonnet",
|
|
48
|
+
spawn: async () => {
|
|
49
|
+
spawned += 1;
|
|
50
|
+
return { port: 6001, close: () => { } };
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
assert.equal(spawned, 1, "a disabled session always spawns (no discovery)");
|
|
54
|
+
assert.equal(result.owned, true);
|
|
55
|
+
assert.equal(result.url, "http://127.0.0.1:6001");
|
|
56
|
+
assert.equal(result.loopbackUrl, "http://127.0.0.1:6001");
|
|
57
|
+
});
|
|
58
|
+
test("enabled session with no reachable proxy degrades to loopback", async () => {
|
|
59
|
+
freshStateDir(); // empty: no proxy.port
|
|
60
|
+
const session = await createPortlessSession({ enabled: true });
|
|
61
|
+
// Whether or not portless is installed, an unreachable proxy degrades to
|
|
62
|
+
// loopback (never a hard failure) so a fresh install always runs.
|
|
63
|
+
assert.equal(session.enabled, false, "no proxy detected -> disabled");
|
|
64
|
+
assert.equal(session.register("scope", 4317), "http://127.0.0.1:4317");
|
|
65
|
+
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fusionkit/cli",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.1.
|
|
4
|
+
"version": "0.1.4",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/velum-labs/handoffkit.git",
|
|
@@ -34,14 +34,17 @@
|
|
|
34
34
|
},
|
|
35
35
|
"dependencies": {
|
|
36
36
|
"commander": "14.0.3",
|
|
37
|
-
"@fusionkit/ensemble": "0.1.
|
|
38
|
-
"@fusionkit/handoff": "0.1.
|
|
39
|
-
"@fusionkit/model-gateway": "0.1.
|
|
40
|
-
"@fusionkit/
|
|
41
|
-
"@fusionkit/
|
|
42
|
-
"@fusionkit/
|
|
43
|
-
"@fusionkit/
|
|
44
|
-
"@fusionkit/
|
|
37
|
+
"@fusionkit/ensemble": "0.1.4",
|
|
38
|
+
"@fusionkit/handoff": "0.1.4",
|
|
39
|
+
"@fusionkit/model-gateway": "0.1.4",
|
|
40
|
+
"@fusionkit/plane": "0.1.4",
|
|
41
|
+
"@fusionkit/protocol": "0.1.4",
|
|
42
|
+
"@fusionkit/runner": "0.1.4",
|
|
43
|
+
"@fusionkit/workspace": "0.1.4",
|
|
44
|
+
"@fusionkit/sdk": "0.1.4"
|
|
45
|
+
},
|
|
46
|
+
"optionalDependencies": {
|
|
47
|
+
"portless": "0.14.0"
|
|
45
48
|
},
|
|
46
49
|
"devDependencies": {
|
|
47
50
|
"@fusionkit/testkit": "0.1.0"
|
package/scope/.next/BUILD_ID
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
5tnFLuvnSbNZNtqRgoot8
|
|
@@ -24,6 +24,13 @@
|
|
|
24
24
|
"static/chunks/main-app-2a6b1f94de31f96f.js",
|
|
25
25
|
"static/chunks/app/api/environments/route-95e822afbebe548b.js"
|
|
26
26
|
],
|
|
27
|
+
"/api/models/route": [
|
|
28
|
+
"static/chunks/webpack-4501ec292abda191.js",
|
|
29
|
+
"static/chunks/4bd1b696-409494caf8c83275.js",
|
|
30
|
+
"static/chunks/255-69a4a78fac9becef.js",
|
|
31
|
+
"static/chunks/main-app-2a6b1f94de31f96f.js",
|
|
32
|
+
"static/chunks/app/api/models/route-95e822afbebe548b.js"
|
|
33
|
+
],
|
|
27
34
|
"/api/ingest/route": [
|
|
28
35
|
"static/chunks/webpack-4501ec292abda191.js",
|
|
29
36
|
"static/chunks/4bd1b696-409494caf8c83275.js",
|
|
@@ -31,12 +38,12 @@
|
|
|
31
38
|
"static/chunks/main-app-2a6b1f94de31f96f.js",
|
|
32
39
|
"static/chunks/app/api/ingest/route-95e822afbebe548b.js"
|
|
33
40
|
],
|
|
34
|
-
"/api/
|
|
41
|
+
"/api/replay/route": [
|
|
35
42
|
"static/chunks/webpack-4501ec292abda191.js",
|
|
36
43
|
"static/chunks/4bd1b696-409494caf8c83275.js",
|
|
37
44
|
"static/chunks/255-69a4a78fac9becef.js",
|
|
38
45
|
"static/chunks/main-app-2a6b1f94de31f96f.js",
|
|
39
|
-
"static/chunks/app/api/
|
|
46
|
+
"static/chunks/app/api/replay/route-95e822afbebe548b.js"
|
|
40
47
|
],
|
|
41
48
|
"/api/sessions/route": [
|
|
42
49
|
"static/chunks/webpack-4501ec292abda191.js",
|
|
@@ -52,13 +59,6 @@
|
|
|
52
59
|
"static/chunks/main-app-2a6b1f94de31f96f.js",
|
|
53
60
|
"static/chunks/app/api/sessions/[traceId]/route-95e822afbebe548b.js"
|
|
54
61
|
],
|
|
55
|
-
"/api/replay/route": [
|
|
56
|
-
"static/chunks/webpack-4501ec292abda191.js",
|
|
57
|
-
"static/chunks/4bd1b696-409494caf8c83275.js",
|
|
58
|
-
"static/chunks/255-69a4a78fac9becef.js",
|
|
59
|
-
"static/chunks/main-app-2a6b1f94de31f96f.js",
|
|
60
|
-
"static/chunks/app/api/replay/route-95e822afbebe548b.js"
|
|
61
|
-
],
|
|
62
62
|
"/api/stream/route": [
|
|
63
63
|
"static/chunks/webpack-4501ec292abda191.js",
|
|
64
64
|
"static/chunks/4bd1b696-409494caf8c83275.js",
|
|
@@ -83,26 +83,26 @@
|
|
|
83
83
|
"static/chunks/873-9351d1edaa9d58ef.js",
|
|
84
84
|
"static/chunks/app/models/page-d9b7d19485e9a640.js"
|
|
85
85
|
],
|
|
86
|
-
"/
|
|
86
|
+
"/page": [
|
|
87
87
|
"static/chunks/webpack-4501ec292abda191.js",
|
|
88
88
|
"static/chunks/4bd1b696-409494caf8c83275.js",
|
|
89
89
|
"static/chunks/255-69a4a78fac9becef.js",
|
|
90
90
|
"static/chunks/main-app-2a6b1f94de31f96f.js",
|
|
91
91
|
"static/chunks/239-1c69ce437d02745f.js",
|
|
92
92
|
"static/chunks/989-1c7081e9fd5c9b9d.js",
|
|
93
|
-
"static/chunks/425-9a1b036b5fdd8b06.js",
|
|
94
93
|
"static/chunks/22-1934dc9c2e544aa9.js",
|
|
95
|
-
"static/chunks/app/
|
|
94
|
+
"static/chunks/app/page-57dce47ff6c00ddd.js"
|
|
96
95
|
],
|
|
97
|
-
"/page": [
|
|
96
|
+
"/sessions/[traceId]/page": [
|
|
98
97
|
"static/chunks/webpack-4501ec292abda191.js",
|
|
99
98
|
"static/chunks/4bd1b696-409494caf8c83275.js",
|
|
100
99
|
"static/chunks/255-69a4a78fac9becef.js",
|
|
101
100
|
"static/chunks/main-app-2a6b1f94de31f96f.js",
|
|
102
101
|
"static/chunks/239-1c69ce437d02745f.js",
|
|
103
102
|
"static/chunks/989-1c7081e9fd5c9b9d.js",
|
|
103
|
+
"static/chunks/425-9a1b036b5fdd8b06.js",
|
|
104
104
|
"static/chunks/22-1934dc9c2e544aa9.js",
|
|
105
|
-
"static/chunks/app/page-
|
|
105
|
+
"static/chunks/app/sessions/[traceId]/page-209dfd895566db6f.js"
|
|
106
106
|
]
|
|
107
107
|
}
|
|
108
108
|
}
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"/_not-found/page": "/_not-found",
|
|
3
3
|
"/api/environments/route": "/api/environments",
|
|
4
|
-
"/api/ingest/route": "/api/ingest",
|
|
5
4
|
"/api/models/route": "/api/models",
|
|
5
|
+
"/api/ingest/route": "/api/ingest",
|
|
6
|
+
"/api/replay/route": "/api/replay",
|
|
6
7
|
"/api/sessions/route": "/api/sessions",
|
|
7
8
|
"/api/sessions/[traceId]/route": "/api/sessions/[traceId]",
|
|
8
|
-
"/api/replay/route": "/api/replay",
|
|
9
9
|
"/api/stream/route": "/api/stream",
|
|
10
10
|
"/environments/page": "/environments",
|
|
11
11
|
"/models/page": "/models",
|
|
12
|
-
"/
|
|
13
|
-
"/page": "/"
|
|
12
|
+
"/page": "/",
|
|
13
|
+
"/sessions/[traceId]/page": "/sessions/[traceId]"
|
|
14
14
|
}
|
|
@@ -5,8 +5,8 @@
|
|
|
5
5
|
"devFiles": [],
|
|
6
6
|
"ampDevFiles": [],
|
|
7
7
|
"lowPriorityFiles": [
|
|
8
|
-
"static/
|
|
9
|
-
"static/
|
|
8
|
+
"static/5tnFLuvnSbNZNtqRgoot8/_buildManifest.js",
|
|
9
|
+
"static/5tnFLuvnSbNZNtqRgoot8/_ssgManifest.js"
|
|
10
10
|
],
|
|
11
11
|
"rootMainFiles": [
|
|
12
12
|
"static/chunks/webpack-4501ec292abda191.js",
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 4,
|
|
3
3
|
"routes": {
|
|
4
|
-
"/
|
|
5
|
-
"initialStatus": 404,
|
|
4
|
+
"/environments": {
|
|
6
5
|
"experimentalBypassFor": [
|
|
7
6
|
{
|
|
8
7
|
"type": "header",
|
|
@@ -15,8 +14,8 @@
|
|
|
15
14
|
}
|
|
16
15
|
],
|
|
17
16
|
"initialRevalidateSeconds": false,
|
|
18
|
-
"srcRoute": "/
|
|
19
|
-
"dataRoute": "/
|
|
17
|
+
"srcRoute": "/environments",
|
|
18
|
+
"dataRoute": "/environments.rsc",
|
|
20
19
|
"allowHeader": [
|
|
21
20
|
"host",
|
|
22
21
|
"x-matched-path",
|
|
@@ -50,7 +49,8 @@
|
|
|
50
49
|
"x-next-revalidate-tag-token"
|
|
51
50
|
]
|
|
52
51
|
},
|
|
53
|
-
"/
|
|
52
|
+
"/_not-found": {
|
|
53
|
+
"initialStatus": 404,
|
|
54
54
|
"experimentalBypassFor": [
|
|
55
55
|
{
|
|
56
56
|
"type": "header",
|
|
@@ -63,8 +63,8 @@
|
|
|
63
63
|
}
|
|
64
64
|
],
|
|
65
65
|
"initialRevalidateSeconds": false,
|
|
66
|
-
"srcRoute": "/
|
|
67
|
-
"dataRoute": "/
|
|
66
|
+
"srcRoute": "/_not-found",
|
|
67
|
+
"dataRoute": "/_not-found.rsc",
|
|
68
68
|
"allowHeader": [
|
|
69
69
|
"host",
|
|
70
70
|
"x-matched-path",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"x-next-revalidate-tag-token"
|
|
75
75
|
]
|
|
76
76
|
},
|
|
77
|
-
"/
|
|
77
|
+
"/models": {
|
|
78
78
|
"experimentalBypassFor": [
|
|
79
79
|
{
|
|
80
80
|
"type": "header",
|
|
@@ -87,8 +87,8 @@
|
|
|
87
87
|
}
|
|
88
88
|
],
|
|
89
89
|
"initialRevalidateSeconds": false,
|
|
90
|
-
"srcRoute": "/
|
|
91
|
-
"dataRoute": "/
|
|
90
|
+
"srcRoute": "/models",
|
|
91
|
+
"dataRoute": "/models.rsc",
|
|
92
92
|
"allowHeader": [
|
|
93
93
|
"host",
|
|
94
94
|
"x-matched-path",
|
|
@@ -102,8 +102,8 @@
|
|
|
102
102
|
"dynamicRoutes": {},
|
|
103
103
|
"notFoundRoutes": [],
|
|
104
104
|
"preview": {
|
|
105
|
-
"previewModeId": "
|
|
106
|
-
"previewModeSigningKey": "
|
|
107
|
-
"previewModeEncryptionKey": "
|
|
105
|
+
"previewModeId": "effae3e9acd85706afc099ae8638302b",
|
|
106
|
+
"previewModeSigningKey": "c391010c73d6e7db27b3e132573063849eef3972f19ce0282cdbf15ddf64efdd",
|
|
107
|
+
"previewModeEncryptionKey": "66d3bfe283a3f90c8c2031d2f3ecf302014e63a3a211c0cdaceaedbbecd3c9db"
|
|
108
108
|
}
|
|
109
109
|
}
|