send-to-paseo 2.6.1-beta.0 → 2.6.1-beta.1
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/package.json +2 -2
- package/server/bridge.ts +5 -1
- package/server/daemon-endpoint.ts +143 -0
- package/server/daemon.ts +54 -36
- package/server/shared-daemon.ts +25 -1
- package/shared/contracts.ts +1 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "send-to-paseo",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "2.6.1-beta.
|
|
4
|
+
"version": "2.6.1-beta.1",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"description": "Local HTTP bridge that dispatches PR work to the right Paseo workspace and agent.",
|
|
7
7
|
"repository": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
},
|
|
36
36
|
"scripts": {
|
|
37
37
|
"typecheck": "tsc --noEmit",
|
|
38
|
-
"test": "node check-deps.mjs && node --test client/hosts.test.mjs client/settings.test.mjs server/main-agent.test.mjs server/follow-up.test.mjs server/daemon-connection.test.mjs",
|
|
38
|
+
"test": "node check-deps.mjs && node --test client/hosts.test.mjs client/settings.test.mjs server/main-agent.test.mjs server/follow-up.test.mjs server/daemon-connection.test.mjs server/daemon-endpoint.test.mjs",
|
|
39
39
|
"verify": "npm run typecheck && npm test && node --test --experimental-strip-types agent-tools.test.mjs shared/chat.test.mjs && node --test native-tools.test.mjs && node --test display-feed.test.mjs && paseo-kit vendor --check settings-feed-client client/settings-feed && paseo-kit vendor --check settings-feed-server server/settings-feed"
|
|
40
40
|
},
|
|
41
41
|
"devDependencies": {
|
package/server/bridge.ts
CHANGED
|
@@ -335,7 +335,11 @@ async function ping(authenticated: boolean): Promise<PingResponse> {
|
|
|
335
335
|
} catch (error) {
|
|
336
336
|
// Ping reports status; it does not fail. An unreachable daemon already
|
|
337
337
|
// shows up in `daemon.reachable`.
|
|
338
|
-
|
|
338
|
+
// A connection that did not open is logged once, with its cause, by the
|
|
339
|
+
// shared daemon connection; logging it again here on every ping is noise.
|
|
340
|
+
if (!(error instanceof BridgeError && error.code === "daemon_unreachable")) {
|
|
341
|
+
console.error("[send-to-paseo] could not list providers for ping", String(error));
|
|
342
|
+
}
|
|
339
343
|
}
|
|
340
344
|
}
|
|
341
345
|
return {
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { request as httpRequest } from "node:http";
|
|
2
|
+
import { request as httpsRequest } from "node:https";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Where the plugin's daemon connection goes, for every way Paseo can listen
|
|
6
|
+
* (daemon-connection-reaches-every-listener, AGENTS.md).
|
|
7
|
+
*
|
|
8
|
+
* `daemon.listen` takes the same forms Paseo's own `parseListenString` does: a
|
|
9
|
+
* socket path (`/…`, `~/…`, `unix://…`), a Windows pipe (`\\.\pipe\…`,
|
|
10
|
+
* `pipe://…`), a bare port, `host:port`, `[v6]:port`, and a comma list whose
|
|
11
|
+
* first entry is the main listener. Both halves of the connection, the
|
|
12
|
+
* WebSocket (`webSocketFactory`) and the HTTP status read (`daemonHttpGet`),
|
|
13
|
+
* are built from this one value, so a form either works for both or neither.
|
|
14
|
+
*
|
|
15
|
+
* Before this the plugin built `ws://${listen}/ws`, which a socket path turned
|
|
16
|
+
* into `ws:///…/paseo.sock/ws` (host "…", not a socket) and a listener list
|
|
17
|
+
* into a URL with a comma in its host, and it opened that with Node's built-in
|
|
18
|
+
* WebSocket, which cannot reach a socket at all (`ws+unix://` is refused with
|
|
19
|
+
* "expected a ws: or wss: url"). Paseo itself worked; the plugin never
|
|
20
|
+
* connected, and the failure was not logged.
|
|
21
|
+
*/
|
|
22
|
+
export interface DaemonEndpoint {
|
|
23
|
+
/** What the WebSocket opens: `ws://host:port/ws`, or `ws+unix://<path>:/ws` for a socket. */
|
|
24
|
+
url: string;
|
|
25
|
+
/** The socket or pipe path, or null for TCP. */
|
|
26
|
+
socketPath: string | null;
|
|
27
|
+
/** Origin of the plain HTTP endpoints for TCP (`http://host:port`); unused for a socket. */
|
|
28
|
+
httpOrigin: string;
|
|
29
|
+
/** Safe to log: no credentials, no query. */
|
|
30
|
+
address: string;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const DEFAULT_LISTEN = "127.0.0.1:6767";
|
|
34
|
+
|
|
35
|
+
const bracket = (host: string) => (host.includes(":") && !host.startsWith("[") ? `[${host}]` : host);
|
|
36
|
+
|
|
37
|
+
/** The socket or pipe a listen value names, or null for TCP. Same rules as Paseo's `parseSocketTarget`. */
|
|
38
|
+
function socketTarget(listen: string, home: string): { path: string; pipe: boolean } | null {
|
|
39
|
+
if (listen.startsWith("\\\\.\\pipe\\")) return { path: listen, pipe: true };
|
|
40
|
+
if (listen.startsWith("pipe://")) return { path: listen.slice("pipe://".length), pipe: true };
|
|
41
|
+
const path = listen.startsWith("unix://") ? listen.slice("unix://".length) : listen.startsWith("/") || listen.startsWith("~") ? listen : null;
|
|
42
|
+
return path === null ? null : { path: path.replace(/^~(?=[/\\]|$)/, home), pipe: false };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function socketEndpoint(path: string, pipe: boolean): DaemonEndpoint {
|
|
46
|
+
// Paseo's CLI addresses a pipe as ws://localhost/ws plus the path; a UNIX socket needs ws+unix.
|
|
47
|
+
return { url: pipe ? "ws://localhost/ws" : `ws+unix://${path}:/ws`, socketPath: path, httpOrigin: "http://localhost", address: path };
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The endpoint for a `daemon.listen` value (undefined or blank is Paseo's default). */
|
|
51
|
+
export function endpointFromListen(listen: string | undefined, home: string): DaemonEndpoint {
|
|
52
|
+
const raw = listen?.trim() || DEFAULT_LISTEN;
|
|
53
|
+
const socket = socketTarget(raw, home);
|
|
54
|
+
if (socket) return socketEndpoint(socket.path, socket.pipe);
|
|
55
|
+
// Several listeners: the first is the main one (Paseo's getMainListenAddress); the rest are extra TCP addresses.
|
|
56
|
+
const main = raw.split(",", 1)[0]!.trim();
|
|
57
|
+
let hostPort: string;
|
|
58
|
+
if (/^\d+$/.test(main)) hostPort = `127.0.0.1:${main}`;
|
|
59
|
+
else {
|
|
60
|
+
const colon = main.lastIndexOf(":");
|
|
61
|
+
if (colon < 0) throw new Error(`Paseo's daemon.listen is not an address the plugin understands: ${main}`);
|
|
62
|
+
const host = main.slice(0, colon).replace(/^\[(.*)\]$/, "$1") || "127.0.0.1";
|
|
63
|
+
hostPort = `${bracket(host)}:${main.slice(colon + 1)}`;
|
|
64
|
+
}
|
|
65
|
+
return { url: `ws://${hostPort}/ws`, socketPath: null, httpOrigin: `http://${hostPort}`, address: hostPort };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/** Strips credentials, query and fragment from a URL for a log line or an error. */
|
|
69
|
+
export function safeAddress(url: string): string {
|
|
70
|
+
return url.replace(/\/\/[^/@]*@/, "//").replace(/[?#].*$/, "");
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* The endpoint for a `PASEO_DAEMON_URL` override: `ws://`/`wss://` as given, or a
|
|
75
|
+
* `ws+unix://<path>:/ws` socket address (what Paseo's CLI uses).
|
|
76
|
+
*/
|
|
77
|
+
export function endpointFromUrl(url: string): DaemonEndpoint {
|
|
78
|
+
if (url.startsWith("ws+unix://")) {
|
|
79
|
+
const path = url.slice("ws+unix://".length).replace(/:\/ws$/, "");
|
|
80
|
+
return socketEndpoint(path, false);
|
|
81
|
+
}
|
|
82
|
+
let httpOrigin = "http://127.0.0.1:6767";
|
|
83
|
+
try {
|
|
84
|
+
const parsed = new URL(url);
|
|
85
|
+
httpOrigin = `${parsed.protocol === "wss:" ? "https:" : "http:"}//${parsed.host}`;
|
|
86
|
+
} catch {
|
|
87
|
+
// An invalid override fails at connect, with the client's own reason in the log.
|
|
88
|
+
}
|
|
89
|
+
return { url, socketPath: null, httpOrigin, address: safeAddress(url) };
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The endpoint the plugin connects to: `PASEO_DAEMON_URL` when set, else `daemon.listen`. */
|
|
93
|
+
export function resolveEndpoint(listen: string | undefined, env: Record<string, string | undefined>, home: string): DaemonEndpoint {
|
|
94
|
+
const override = env.PASEO_DAEMON_URL;
|
|
95
|
+
return override ? endpointFromUrl(override) : endpointFromListen(listen, home);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
type WsConstructor = new (address: string, protocols: string[] | undefined, options: Record<string, unknown>) => unknown;
|
|
99
|
+
|
|
100
|
+
/**
|
|
101
|
+
* The WebSocket the daemon client opens: the `ws` package (the one Paseo's own
|
|
102
|
+
* client and CLI use), given the socket path for a socket or pipe. Node's
|
|
103
|
+
* built-in WebSocket, the client's default, cannot reach a socket.
|
|
104
|
+
*/
|
|
105
|
+
export function webSocketFactory(WebSocket: WsConstructor, endpoint: DaemonEndpoint) {
|
|
106
|
+
return (url: string, options?: { headers?: Record<string, string>; protocols?: string[] }) =>
|
|
107
|
+
new WebSocket(url, options?.protocols, {
|
|
108
|
+
headers: options?.headers,
|
|
109
|
+
...(endpoint.socketPath ? { socketPath: endpoint.socketPath } : {}),
|
|
110
|
+
maxPayload: 100 * 1024 * 1024,
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/** A failed connect as one log line: where, and the client's own reason. */
|
|
115
|
+
export function describeConnectFailure(endpoint: DaemonEndpoint, error: unknown): string {
|
|
116
|
+
const reason = String(error instanceof Error ? error.message : error ?? "")
|
|
117
|
+
.replace(/\s+/g, " ")
|
|
118
|
+
.trim()
|
|
119
|
+
.slice(0, 300);
|
|
120
|
+
return `can't connect to Paseo at ${endpoint.address}: ${reason || "unknown error"}`;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/** GET a plain HTTP endpoint of the daemon (`/api/status`, `/api/health`) over the same endpoint. */
|
|
124
|
+
export function daemonHttpGet(endpoint: DaemonEndpoint, path: string, timeoutMs: number): Promise<{ status: number; body: string }> {
|
|
125
|
+
return new Promise((resolve, reject) => {
|
|
126
|
+
const origin = new URL(endpoint.httpOrigin);
|
|
127
|
+
const request = origin.protocol === "https:" ? httpsRequest : httpRequest;
|
|
128
|
+
const req = request(
|
|
129
|
+
endpoint.socketPath
|
|
130
|
+
? { socketPath: endpoint.socketPath, path, method: "GET", headers: { host: "localhost" } }
|
|
131
|
+
: { protocol: origin.protocol, hostname: origin.hostname.replace(/^\[(.*)\]$/, "$1"), port: origin.port || undefined, path, method: "GET" },
|
|
132
|
+
(res) => {
|
|
133
|
+
const chunks: Buffer[] = [];
|
|
134
|
+
res.on("data", (chunk: Buffer) => chunks.push(chunk));
|
|
135
|
+
res.on("end", () => resolve({ status: res.statusCode ?? 0, body: Buffer.concat(chunks).toString("utf8") }));
|
|
136
|
+
res.on("error", reject);
|
|
137
|
+
},
|
|
138
|
+
);
|
|
139
|
+
req.setTimeout(timeoutMs, () => req.destroy(new Error(`timed out after ${timeoutMs} ms`)));
|
|
140
|
+
req.on("error", reject);
|
|
141
|
+
req.end();
|
|
142
|
+
});
|
|
143
|
+
}
|
package/server/daemon.ts
CHANGED
|
@@ -8,6 +8,7 @@ import { resolveDaemonPassword } from "./daemon-password";
|
|
|
8
8
|
import { settings } from "./settings";
|
|
9
9
|
import { invokeFollowUp } from "./follow-up-id";
|
|
10
10
|
import { sharedDaemon } from "./shared-daemon";
|
|
11
|
+
import { daemonHttpGet, describeConnectFailure, resolveEndpoint, webSocketFactory, type DaemonEndpoint } from "./daemon-endpoint";
|
|
11
12
|
|
|
12
13
|
/**
|
|
13
14
|
* The plugin's one held daemon connection (one-held-daemon-connection, AGENTS.md).
|
|
@@ -33,14 +34,6 @@ const STATUS_TIMEOUT_MS = 2_000;
|
|
|
33
34
|
const FOLLOW_UP_TIMEOUT_MS = 2_000;
|
|
34
35
|
const STATUS_TTL_MS = 15_000;
|
|
35
36
|
|
|
36
|
-
function timeoutSignal(ms: number): AbortSignal {
|
|
37
|
-
return (
|
|
38
|
-
AbortSignal as typeof AbortSignal & {
|
|
39
|
-
timeout(milliseconds: number): AbortSignal;
|
|
40
|
-
}
|
|
41
|
-
).timeout(ms);
|
|
42
|
-
}
|
|
43
|
-
|
|
44
37
|
type PaseoApi = PluginHandlerContext["paseo"];
|
|
45
38
|
|
|
46
39
|
/** The subset of Paseo's DaemonClient this plugin uses. */
|
|
@@ -62,10 +55,13 @@ interface ClientModule {
|
|
|
62
55
|
connectTimeoutMs: number;
|
|
63
56
|
suppressSendErrors: boolean;
|
|
64
57
|
password?: string;
|
|
58
|
+
webSocketFactory?: ReturnType<typeof webSocketFactory>;
|
|
65
59
|
}) => DaemonClient;
|
|
66
60
|
}
|
|
67
61
|
|
|
68
62
|
let clientModule: ClientModule | null = null;
|
|
63
|
+
/** The `ws` package Paseo's client ships with, or null when this host has none (the client then keeps its default). */
|
|
64
|
+
let wsModule: (new (...args: any[]) => unknown) | null | undefined;
|
|
69
65
|
|
|
70
66
|
/**
|
|
71
67
|
* Borrows Paseo's own SDK and daemon client from the host at runtime.
|
|
@@ -89,6 +85,22 @@ function loadClientModule(): ClientModule {
|
|
|
89
85
|
const { createPaseoApi } = load(sdk) as Pick<ClientModule, "createPaseoApi">;
|
|
90
86
|
const { DaemonClient } = load(internal) as Pick<ClientModule, "DaemonClient">;
|
|
91
87
|
clientModule = { createPaseoApi, DaemonClient };
|
|
88
|
+
// Resolved beside Paseo's own client, so the plugin still adds no dependency
|
|
89
|
+
// (daemon-connection-reaches-every-listener): Node's built-in WebSocket, the
|
|
90
|
+
// client's default, cannot open a UNIX socket or a pipe.
|
|
91
|
+
// Paseo's plugin runner (process.argv[1]) is the reliable base: inside the plugin
|
|
92
|
+
// process the compiled module's own `require.resolve` does not find the host's
|
|
93
|
+
// client (2026-12-02 harness: the socket still failed with "expected a ws: or wss: url").
|
|
94
|
+
wsModule = null;
|
|
95
|
+
for (const base of [() => createRequire(process.argv[1] ?? join(process.cwd(), "noop.cjs")).resolve(internal), () => load.resolve(internal)]) {
|
|
96
|
+
try {
|
|
97
|
+
const ws = createRequire(base())("ws") as { WebSocket?: new (...args: any[]) => unknown };
|
|
98
|
+
wsModule = ws.WebSocket ?? (ws as unknown as new (...args: any[]) => unknown);
|
|
99
|
+
break;
|
|
100
|
+
} catch {
|
|
101
|
+
// Try the next base; none means the client keeps its default WebSocket.
|
|
102
|
+
}
|
|
103
|
+
}
|
|
92
104
|
} catch (error) {
|
|
93
105
|
throw new BridgeError(
|
|
94
106
|
"daemon_unreachable",
|
|
@@ -100,29 +112,27 @@ function loadClientModule(): ClientModule {
|
|
|
100
112
|
return clientModule;
|
|
101
113
|
}
|
|
102
114
|
|
|
103
|
-
let
|
|
115
|
+
let cachedEndpoint: DaemonEndpoint | null = null;
|
|
104
116
|
|
|
105
|
-
/**
|
|
106
|
-
|
|
107
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Where the daemon is, from `PASEO_DAEMON_URL` or `daemon.listen` in config (Paseo's default when
|
|
119
|
+
* neither says). One value for the WebSocket and the HTTP status read
|
|
120
|
+
* (daemon-connection-reaches-every-listener, AGENTS.md).
|
|
121
|
+
*/
|
|
122
|
+
async function resolveDaemonEndpoint(): Promise<DaemonEndpoint> {
|
|
123
|
+
if (cachedEndpoint !== null) return cachedEndpoint;
|
|
108
124
|
const home = process.env.PASEO_HOME ?? join(homedir(), ".paseo");
|
|
109
125
|
let listen: string | undefined;
|
|
110
126
|
try {
|
|
111
127
|
const raw = JSON.parse(await readFile(join(home, "config.json"), "utf8")) as {
|
|
112
|
-
daemon?: { listen?:
|
|
128
|
+
daemon?: { listen?: unknown };
|
|
113
129
|
};
|
|
114
|
-
listen = raw.daemon
|
|
130
|
+
if (typeof raw.daemon?.listen === "string") listen = raw.daemon.listen;
|
|
115
131
|
} catch {
|
|
116
132
|
// Fall through to the documented default.
|
|
117
133
|
}
|
|
118
|
-
|
|
119
|
-
return
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
async function resolveUrl(): Promise<string> {
|
|
123
|
-
const fromEnv = process.env.PASEO_DAEMON_URL;
|
|
124
|
-
if (fromEnv !== undefined && fromEnv !== "") return fromEnv;
|
|
125
|
-
return `ws://${await resolveListen()}/ws`;
|
|
134
|
+
cachedEndpoint = resolveEndpoint(listen, process.env, homedir());
|
|
135
|
+
return cachedEndpoint;
|
|
126
136
|
}
|
|
127
137
|
|
|
128
138
|
/**
|
|
@@ -165,8 +175,9 @@ async function resolvePassword(): Promise<string | undefined> {
|
|
|
165
175
|
async function openDaemon(): Promise<DaemonClient> {
|
|
166
176
|
const { DaemonClient } = loadClientModule();
|
|
167
177
|
const password = await resolvePassword();
|
|
178
|
+
const endpoint = await resolveDaemonEndpoint();
|
|
168
179
|
const client = new DaemonClient({
|
|
169
|
-
url:
|
|
180
|
+
url: endpoint.url,
|
|
170
181
|
clientId: "send-to-paseo",
|
|
171
182
|
clientType: "cli",
|
|
172
183
|
reconnect: { enabled: false },
|
|
@@ -175,13 +186,15 @@ async function openDaemon(): Promise<DaemonClient> {
|
|
|
175
186
|
// Omitted rather than passed as "" when there is none, so a daemon without
|
|
176
187
|
// auth is unaffected.
|
|
177
188
|
...(password === undefined ? {} : { password }),
|
|
189
|
+
...(wsModule ? { webSocketFactory: webSocketFactory(wsModule, endpoint) } : {}),
|
|
178
190
|
});
|
|
179
191
|
try {
|
|
180
192
|
await client.connect();
|
|
181
193
|
return client;
|
|
182
194
|
} catch (error) {
|
|
183
195
|
await client.close().catch(() => undefined);
|
|
184
|
-
|
|
196
|
+
let detail = describeConnectFailure(endpoint, error);
|
|
197
|
+
if (endpoint.socketPath && !wsModule) detail += " (the ws package was not found beside Paseo's client, and Node's own WebSocket cannot open a socket)";
|
|
185
198
|
// A daemon that wants a password is REACHABLE and refusing, which is a
|
|
186
199
|
// different fix from "start Paseo". The hint has to say which.
|
|
187
200
|
if (/password/i.test(detail)) {
|
|
@@ -199,7 +212,16 @@ async function openDaemon(): Promise<DaemonClient> {
|
|
|
199
212
|
}
|
|
200
213
|
}
|
|
201
214
|
|
|
202
|
-
|
|
215
|
+
/**
|
|
216
|
+
* A failed open as one log line, the real cause included (the hint carries the
|
|
217
|
+
* client's own reason). sharedDaemon logs it once per cause.
|
|
218
|
+
*/
|
|
219
|
+
function connectFailureLine(error: unknown): string {
|
|
220
|
+
if (error instanceof BridgeError) return `[send-to-paseo] ${error.message}${error.hint ? ` ${error.hint}` : ""}`;
|
|
221
|
+
return `[send-to-paseo] ${error instanceof Error ? error.message : String(error)}`;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const shared = sharedDaemon(openDaemon, { keepWarm: true, describeFailure: connectFailureLine });
|
|
203
225
|
|
|
204
226
|
/** Opens the held connection in the background. The plugin calls it at start so no popover pays for the connect. */
|
|
205
227
|
export function warmDaemon(): void {
|
|
@@ -320,14 +342,12 @@ export async function readDaemonStatus(): Promise<DaemonStatus> {
|
|
|
320
342
|
if (statusCache !== null && Date.now() - statusCache.at < STATUS_TTL_MS) {
|
|
321
343
|
return statusCache.status;
|
|
322
344
|
}
|
|
323
|
-
const
|
|
345
|
+
const endpoint = await resolveDaemonEndpoint();
|
|
324
346
|
let status: DaemonStatus = { reachable: false, version: null, serverId: null };
|
|
325
347
|
try {
|
|
326
|
-
const response = await
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
if (response.ok) {
|
|
330
|
-
const body = (await response.json()) as { version?: unknown; serverId?: unknown };
|
|
348
|
+
const response = await daemonHttpGet(endpoint, "/api/status", STATUS_TIMEOUT_MS);
|
|
349
|
+
if (response.status >= 200 && response.status < 300) {
|
|
350
|
+
const body = JSON.parse(response.body) as { version?: unknown; serverId?: unknown };
|
|
331
351
|
status = {
|
|
332
352
|
reachable: true,
|
|
333
353
|
version: typeof body.version === "string" ? body.version : null,
|
|
@@ -336,11 +356,9 @@ export async function readDaemonStatus(): Promise<DaemonStatus> {
|
|
|
336
356
|
} else if (response.status === 401 || response.status === 403) {
|
|
337
357
|
// It answered. It just would not tell us. Liveness comes from the
|
|
338
358
|
// unauthenticated endpoint, and the id from disk.
|
|
339
|
-
const health = await
|
|
340
|
-
signal: timeoutSignal(STATUS_TIMEOUT_MS),
|
|
341
|
-
}).catch(() => null);
|
|
359
|
+
const health = await daemonHttpGet(endpoint, "/api/health", STATUS_TIMEOUT_MS).catch(() => null);
|
|
342
360
|
status = {
|
|
343
|
-
reachable: health
|
|
361
|
+
reachable: health !== null && health.status >= 200 && health.status < 300,
|
|
344
362
|
version: null,
|
|
345
363
|
serverId: await readServerIdFile(),
|
|
346
364
|
};
|
|
@@ -375,5 +393,5 @@ export async function requireServerId(): Promise<string> {
|
|
|
375
393
|
|
|
376
394
|
export function clearDaemonCaches(): void {
|
|
377
395
|
statusCache = null;
|
|
378
|
-
|
|
396
|
+
cachedEndpoint = null;
|
|
379
397
|
}
|
package/server/shared-daemon.ts
CHANGED
|
@@ -16,6 +16,11 @@
|
|
|
16
16
|
* keeps serving until its replacement is connected. `run(work, { ifConnected:
|
|
17
17
|
* true })` never waits on a connect: with no connected client it starts one and
|
|
18
18
|
* fails at once with `code: "not_connected"`.
|
|
19
|
+
*
|
|
20
|
+
* A failed open logs its real cause once (`describeFailure`, through `log`):
|
|
21
|
+
* the background reconnect retries on its backoff for as long as the daemon is
|
|
22
|
+
* unreachable, and every retry with the same cause stays quiet until a
|
|
23
|
+
* connection opens or the cause changes. Callers see only "unreachable".
|
|
19
24
|
*/
|
|
20
25
|
|
|
21
26
|
export interface Closable {
|
|
@@ -51,7 +56,17 @@ export class NotConnectedError extends Error {
|
|
|
51
56
|
|
|
52
57
|
export function sharedDaemon<C extends Closable>(
|
|
53
58
|
open: () => Promise<C>,
|
|
54
|
-
options: {
|
|
59
|
+
options: {
|
|
60
|
+
maxMs?: number;
|
|
61
|
+
now?: () => number;
|
|
62
|
+
backoffMs?: number;
|
|
63
|
+
backoffMaxMs?: number;
|
|
64
|
+
stopping?: () => Error;
|
|
65
|
+
keepWarm?: boolean;
|
|
66
|
+
/** One log line for a failed open, with its real cause. No secrets. */
|
|
67
|
+
describeFailure?: (error: unknown) => string;
|
|
68
|
+
log?: (line: string) => void;
|
|
69
|
+
} = {},
|
|
55
70
|
): SharedDaemon<C> {
|
|
56
71
|
const maxMs = options.maxMs ?? SHARED_CLIENT_MAX_MS;
|
|
57
72
|
const now = options.now ?? Date.now;
|
|
@@ -59,6 +74,10 @@ export function sharedDaemon<C extends Closable>(
|
|
|
59
74
|
const backoffMaxMs = options.backoffMaxMs ?? OPEN_BACKOFF_MAX_MS;
|
|
60
75
|
const stopping = options.stopping ?? (() => new Error("Send to Paseo is stopping."));
|
|
61
76
|
const keepWarm = options.keepWarm === true;
|
|
77
|
+
const describeFailure = options.describeFailure ?? ((error: unknown) => (error instanceof Error ? error.message : String(error)));
|
|
78
|
+
const log = options.log ?? ((line: string) => console.error(line));
|
|
79
|
+
/** The last failure line logged; cleared when a connection opens, so the next outage is logged again. */
|
|
80
|
+
let logged: string | null = null;
|
|
62
81
|
type Entry = { client: Promise<C>; ready: C | null; opened: number; users: number; retired: boolean; unsubscribe?: () => void };
|
|
63
82
|
let current: Entry | null = null;
|
|
64
83
|
/** The replacement for an aged `current`, opening while `current` keeps serving. */
|
|
@@ -103,6 +122,7 @@ export function sharedDaemon<C extends Closable>(
|
|
|
103
122
|
entry.client = open().then(
|
|
104
123
|
(client) => {
|
|
105
124
|
failures = 0;
|
|
125
|
+
logged = null;
|
|
106
126
|
if (stopped) {
|
|
107
127
|
void client.close().catch(() => undefined);
|
|
108
128
|
throw stopping();
|
|
@@ -123,6 +143,10 @@ export function sharedDaemon<C extends Closable>(
|
|
|
123
143
|
(error: unknown) => {
|
|
124
144
|
failures++;
|
|
125
145
|
lastError = error;
|
|
146
|
+
if (!stopped) {
|
|
147
|
+
const line = describeFailure(error);
|
|
148
|
+
if (line !== logged) { logged = line; log(line); }
|
|
149
|
+
}
|
|
126
150
|
retryAt = now() + Math.min(backoffMs * 2 ** (failures - 1), backoffMaxMs);
|
|
127
151
|
all.delete(entry);
|
|
128
152
|
if (current === entry) current = null;
|
package/shared/contracts.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { z } from "zod";
|
|
|
9
9
|
|
|
10
10
|
/** Advertised in `GET /v1/ping`. Keep in step with `package.json`. */
|
|
11
11
|
export const PLUGIN_NAME = "send-to-paseo";
|
|
12
|
-
export const PLUGIN_VERSION = "2.6.1-beta.
|
|
12
|
+
export const PLUGIN_VERSION = "2.6.1-beta.1";
|
|
13
13
|
/** Bumped only for an incompatible bridge API; the paths stay `/v1`. */
|
|
14
14
|
export const CONTRACT_VERSION = 1;
|
|
15
15
|
|