@mycadet/credential-executor 0.13.0-dev.202611041208.2540870 → 0.13.0-dev.202611121243.82bf60e

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.
@@ -48,7 +48,7 @@ describe("parseRemoteWebPairingParams", () => {
48
48
  describe("parsePairingAddress", () => {
49
49
  test("splits a pairing link into its base and device code", () => {
50
50
  const link = buildRemoteWebPairingUrl({
51
- verificationUri: "https://assistant.example.com/assistant/pair",
51
+ verificationUri: "https://assistant.example.com/account/pair",
52
52
  deviceCode: "device-1",
53
53
  });
54
54
 
@@ -62,7 +62,7 @@ describe("parsePairingAddress", () => {
62
62
  test("accepts the device code in the query string", () => {
63
63
  expect(
64
64
  parsePairingAddress(
65
- "https://assistant.example.com/assistant/pair?deviceCode=device-2",
65
+ "https://assistant.example.com/account/pair?deviceCode=device-2",
66
66
  ),
67
67
  ).toEqual({
68
68
  ok: true,
@@ -71,25 +71,28 @@ describe("parsePairingAddress", () => {
71
71
  });
72
72
  });
73
73
 
74
- test("preserves a path prefix while dropping the app-route suffix", () => {
75
- expect(
76
- parsePairingAddress(
77
- "https://host.example.com/assistant-123/assistant/pair#device_code=device-3",
78
- ),
79
- ).toEqual({
74
+ test("splits an app-shell pairing link (the pair page lives at /account/pair)", () => {
75
+ const link = buildRemoteWebPairingUrl({
76
+ verificationUri: "https://assistant.example.com/account/pair",
77
+ deviceCode: "device-4",
78
+ });
79
+
80
+ expect(parsePairingAddress(link)).toEqual({
80
81
  ok: true,
81
- publicBaseUrl: "https://host.example.com/assistant-123",
82
- deviceCode: "device-3",
82
+ publicBaseUrl: "https://assistant.example.com",
83
+ deviceCode: "device-4",
83
84
  });
84
85
  });
85
86
 
86
- test("drops a trailing app-route suffix from a bare address", () => {
87
+ test("preserves a path prefix on an app-shell pairing link", () => {
87
88
  expect(
88
- parsePairingAddress("https://assistant.example.com/assistant/pair"),
89
+ parsePairingAddress(
90
+ "https://host.example.com/assistant-123/account/pair#device_code=device-5",
91
+ ),
89
92
  ).toEqual({
90
93
  ok: true,
91
- publicBaseUrl: "https://assistant.example.com",
92
- deviceCode: null,
94
+ publicBaseUrl: "https://host.example.com/assistant-123",
95
+ deviceCode: "device-5",
93
96
  });
94
97
  });
95
98
 
@@ -3,10 +3,14 @@
3
3
  * deployment naming convention (`cloud.mycadet.ai` → `tunnel.mycadet.ai`,
4
4
  * `{env}-cloud.mycadet.ai` → `{env}-tunnel.mycadet.ai`). Returns null for
5
5
  * hosts outside that convention (localhost, custom domains). Shared by the
6
- * gateway speech relay and the web live-voice client so the two ends of the
7
- * cloud-speech transport can't drift.
6
+ * gateway speech relay (which passes the request's own host) and the web
7
+ * live-voice client (which defaults to the page's origin) so the two ends
8
+ * of the cloud-speech transport can't drift.
8
9
  */
9
- export function tunnelHostForCloudHost(host: string): string | null {
10
+ export function tunnelHostForCloudHost(
11
+ host: string = (globalThis as { location?: { hostname?: string } }).location
12
+ ?.hostname ?? "",
13
+ ): string | null {
10
14
  if (host === "cloud.mycadet.ai") {
11
15
  return "tunnel.mycadet.ai";
12
16
  }
@@ -78,60 +78,6 @@ export interface RemoteWebPairingVerificationResponse {
78
78
  expiresAt: string;
79
79
  }
80
80
 
81
- /**
82
- * One pending challenge as shown on a host approval surface.
83
- *
84
- * The requesting device already sees the plaintext `userCode` in its own
85
- * challenge response ({@link RemoteWebPairingChallengeResponse.userCode});
86
- * the loopback-gated list route is the only host-side re-exposure. Displaying
87
- * it there is what lets the approver match the code against the requesting
88
- * device's screen: the device-flow anti-phishing binding.
89
- */
90
- export interface RemoteWebPairingRequestSummary {
91
- /** Opaque server-side id used to approve or deny this request. */
92
- requestId: string;
93
- /** The human-readable code the requesting device is displaying (e.g. "ABCD-EFGH"). */
94
- userCode: string;
95
- /** Public base URL the challenge was minted for. */
96
- publicBaseUrl: string;
97
- /** ISO-8601 instant the challenge was minted. */
98
- requestedAt: string;
99
- /** ISO-8601 instant the challenge expires. */
100
- expiresAt: string;
101
- /**
102
- * Client IP of the mint request: the loopback/host address when minted
103
- * locally, or the edge-observed client address when the mint arrived
104
- * through the nginx app server (which stamps it via `proxy_set_header`,
105
- * so a remote client cannot smuggle a value).
106
- */
107
- requesterIp: string;
108
- /** User-Agent header of the mint request, or null when absent. */
109
- requesterUserAgent: string | null;
110
- /**
111
- * Whether the mint arrived through the public app server rather than the
112
- * host itself.
113
- */
114
- viaEdgeProxy: boolean;
115
- }
116
-
117
- /** `GET /v1/remote-web/pairing-requests` success response body (200). */
118
- export interface RemoteWebPairingRequestListResponse {
119
- requests: RemoteWebPairingRequestSummary[];
120
- }
121
-
122
- /**
123
- * Request body for the pairing-request approve and deny routes. The approve
124
- * route's success body reuses {@link RemoteWebPairingVerificationResponse}.
125
- */
126
- export interface RemoteWebPairingRequestActionRequest {
127
- requestId: string;
128
- }
129
-
130
- /** `POST /v1/remote-web/pairing-requests/deny` success response body (200). */
131
- export interface RemoteWebPairingRequestDenyResponse {
132
- status: "denied";
133
- }
134
-
135
81
  /**
136
82
  * Platforms a device-bound pairing exchange may declare for itself. The value
137
83
  * is what the host's `Paired devices` list renders for the new pairing.
@@ -535,18 +481,18 @@ export function isPrivateNetworkPublicUrl(url: string): boolean {
535
481
 
536
482
  /**
537
483
  * Normalize an address to the public base a scanning device opens:
538
- * query/hash stripped, the `assistant` path segment (and everything after it)
539
- * removed so a pasted pair-page URL collapses to its base, and trailing
540
- * slashes trimmed. Throws if the value is not a parseable URL.
484
+ * query/hash stripped, the pair page's `account` path segment (and everything
485
+ * after it) removed so a pasted pair-page URL collapses to its base, and
486
+ * trailing slashes trimmed. Throws if the value is not a parseable URL.
541
487
  */
542
488
  export function normalizePairingBaseUrl(value: string): string {
543
489
  const url = new URL(value);
544
490
  url.search = "";
545
491
  url.hash = "";
546
492
  const parts = url.pathname.split("/").filter(Boolean);
547
- const assistantIndex = parts.indexOf("assistant");
548
- if (assistantIndex >= 0) {
549
- parts.splice(assistantIndex);
493
+ const cutIndex = parts.indexOf("account");
494
+ if (cutIndex >= 0) {
495
+ parts.splice(cutIndex);
550
496
  }
551
497
  url.pathname = parts.length ? `/${parts.join("/")}` : "/";
552
498
  return url.toString().replace(/\/+$/, "");
@@ -689,10 +635,7 @@ export function parsePairingAddress(raw: string): ParsePairingAddressResult {
689
635
  }
690
636
 
691
637
  /**
692
- * What a pairing attempt failed on, for callers picking recovery copy. Every
693
- * pairing surface reports one of these: the host-side sessions in
694
- * `@mycadet/local-mode`, the Electron bridge, the desktop connect dialog, and
695
- * the `cadet connect import` CLI.
638
+ * What a pairing attempt failed on, for callers picking recovery copy
696
639
  */
697
640
  export type PairingFailureReason =
698
641
  /** The pasted address is not a usable assistant address. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mycadet/credential-executor",
3
- "version": "0.13.0-dev.202611041208.2540870",
3
+ "version": "0.13.0-dev.202611121243.82bf60e",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
package/src/logger.ts CHANGED
@@ -74,7 +74,7 @@ function buildLogger(config: LogFileConfig | null): pino.Logger {
74
74
  const filePath = logFilePathForDate(config.dir, new Date());
75
75
  const fileStream = pino.destination({
76
76
  dest: filePath,
77
- sync: false,
77
+ sync: true,
78
78
  mkdir: true,
79
79
  mode: 0o600,
80
80
  });
package/src/main.ts CHANGED
@@ -242,75 +242,88 @@ function startHealthServer(
242
242
  port: number,
243
243
  signal: AbortSignal,
244
244
  credentialDeps: CredentialRouteDeps | null,
245
- ): ReturnType<typeof Bun.serve> {
245
+ ): ReturnType<typeof Bun.serve> | null {
246
246
  // Listen on every interface so kubelet httpGet probes can hit the pod IP.
247
247
  // Credential CRUD, metadata, and log export stay loopback-only: assistant
248
248
  // and gateway in this pod call http://localhost:<CES_HEALTH_PORT>.
249
- const server = Bun.serve({
250
- port,
251
- async fetch(req, httpServer) {
252
- const url = new URL(req.url);
253
- if (url.pathname === "/healthz") {
254
- return new Response(JSON.stringify({ status: "ok" }), {
255
- headers: { "Content-Type": "application/json" },
256
- });
257
- }
258
- if (url.pathname === "/readyz") {
259
- // Always return 200: pod readiness must not depend on whether the
260
- // assistant has connected. When the CES feature flag is off the
261
- // assistant never connects, and a 503 here would block pod
262
- // scheduling during dark-launch. The sidecar can't do useful work
263
- // without a connection anyway, so readiness is purely about the
264
- // process being up and able to accept a future connection.
265
- return new Response(
266
- JSON.stringify({
267
- status: "ok",
268
- connections: connectionCount,
269
- rpcConnected: connectionCount > 0,
270
- }),
271
- {
272
- status: 200,
249
+ let server: ReturnType<typeof Bun.serve>;
250
+ try {
251
+ server = Bun.serve({
252
+ port,
253
+ async fetch(req, httpServer) {
254
+ const url = new URL(req.url);
255
+ if (url.pathname === "/healthz") {
256
+ return new Response(JSON.stringify({ status: "ok" }), {
273
257
  headers: { "Content-Type": "application/json" },
274
- },
275
- );
276
- }
258
+ });
259
+ }
260
+ if (url.pathname === "/readyz") {
261
+ // Always return 200: pod readiness must not depend on whether the
262
+ // assistant has connected. When the CES feature flag is off the
263
+ // assistant never connects, and a 503 here would block pod
264
+ // scheduling during dark-launch. The sidecar can't do useful work
265
+ // without a connection anyway, so readiness is purely about the
266
+ // process being up and able to accept a future connection.
267
+ return new Response(
268
+ JSON.stringify({
269
+ status: "ok",
270
+ connections: connectionCount,
271
+ rpcConnected: connectionCount > 0,
272
+ }),
273
+ {
274
+ status: 200,
275
+ headers: { "Content-Type": "application/json" },
276
+ },
277
+ );
278
+ }
277
279
 
278
- const peer = httpServer.requestIP(req)?.address;
279
- if (!peer || !isLoopbackAddress(peer)) {
280
- return new Response("Not Found", { status: 404 });
281
- }
280
+ const peer = httpServer.requestIP(req)?.address;
281
+ if (!peer || !isLoopbackAddress(peer)) {
282
+ return new Response("Not Found", { status: 404 });
283
+ }
282
284
 
283
- return withCesHttpErrorLogging(
284
- req,
285
- async () => {
286
- // Credential CRUD routes (only if service token is configured)
287
- if (credentialDeps) {
288
- const metadataResponse = await handleMetadataRoute(req);
289
- if (metadataResponse) {
290
- return metadataResponse;
285
+ return withCesHttpErrorLogging(
286
+ req,
287
+ async () => {
288
+ // Credential CRUD routes (only if service token is configured)
289
+ if (credentialDeps) {
290
+ const metadataResponse = await handleMetadataRoute(req);
291
+ if (metadataResponse) {
292
+ return metadataResponse;
293
+ }
294
+ const credentialResponse = await handleCredentialRoute(
295
+ req,
296
+ credentialDeps,
297
+ );
298
+ if (credentialResponse) {
299
+ return credentialResponse;
300
+ }
291
301
  }
292
- const credentialResponse = await handleCredentialRoute(
302
+
303
+ // Log export route
304
+ const logExportResponse = await handleLogExportRoute(
293
305
  req,
294
- credentialDeps,
306
+ getCesLogDir(),
295
307
  );
296
- if (credentialResponse) {
297
- return credentialResponse;
298
- }
299
- }
300
-
301
- // Log export route
302
- const logExportResponse = await handleLogExportRoute(
303
- req,
304
- getCesLogDir(),
305
- );
306
- if (logExportResponse) return logExportResponse;
308
+ if (logExportResponse) return logExportResponse;
307
309
 
308
- return new Response("Not Found", { status: 404 });
309
- },
310
- log,
311
- );
312
- },
310
+ return new Response("Not Found", { status: 404 });
311
+ },
312
+ log,
313
+ );
314
+ },
313
315
  });
316
+ } catch (err) {
317
+ // A health-port collision must never take the credential store down:
318
+ // local callers reach the CES over the Unix socket, so a failed HTTP
319
+ // surface degrades to socket-only service. An EADDRINUSE here used to
320
+ // kill the CES milliseconds into boot — with the async log
321
+ // destination swallowing the fatal — which surfaced downstream as
322
+ // "credential-executor socket not ready" and a 502 for every
323
+ // credential read during hatch.
324
+ log.error({ err, port }, "CES health server failed to bind — continuing socket-only");
325
+ return null;
326
+ }
314
327
 
315
328
  signal.addEventListener(
316
329
  "abort",