@mycadet/cli 0.13.0-dev.202610261745.ff07088 → 0.13.0-dev.202610262105.8c45cc2
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/node_modules/@mycadet/assistant-api/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/environments/package.json +1 -1
- package/node_modules/@mycadet/ipc-server-utils/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/avatar-manifest/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +1 -1
- package/node_modules/@mycadet/local-mode/package.json +1 -1
- package/node_modules/@mycadet/local-mode/src/gateway-proxy.ts +13 -5
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +5 -0
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +55 -0
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/package.json +1 -1
- package/package.json +1 -1
- package/src/__tests__/cloud-releases.test.ts +0 -7
- package/src/__tests__/guardian-token.test.ts +7 -2
- package/src/__tests__/runtime-url.test.ts +3 -4
- package/src/__tests__/upgrade-local.test.ts +4 -3
- package/src/commands/client.ts +2 -5
- package/src/commands/debug.ts +3 -19
- package/src/commands/devices.ts +1 -1
- package/src/commands/gateway/token.ts +2 -2
- package/src/commands/hatch.ts +0 -4
- package/src/commands/pair.ts +1 -1
- package/src/commands/ps.ts +13 -17
- package/src/commands/restore.ts +7 -6
- package/src/commands/retire.ts +6 -9
- package/src/commands/setup.ts +2 -10
- package/src/commands/sleep.ts +1 -1
- package/src/commands/upgrade.ts +17 -46
- package/src/index.ts +1 -1
- package/src/lib/__tests__/cloud-client-signed-url.test.ts +6 -6
- package/src/lib/__tests__/port-heal.test.ts +1 -2
- package/src/lib/__tests__/runtime-url.test.ts +4 -4
- package/src/lib/assistant-client.ts +2 -8
- package/src/lib/assistant-config.ts +7 -7
- package/src/lib/cloud-client.ts +1 -1
- package/src/lib/cloud-login.ts +2 -7
- package/src/lib/cloud-releases.ts +5 -7
- package/src/lib/docker.ts +28 -48
- package/src/lib/environments/__tests__/paths.test.ts +8 -27
- package/src/lib/environments/__tests__/seeds.test.ts +15 -10
- package/src/lib/environments/paths.ts +4 -3
- package/src/lib/guardian-token.ts +8 -3
- package/src/lib/hatch-local.ts +4 -11
- package/src/lib/health-check.ts +9 -10
- package/src/lib/host-teleport.ts +9 -14
- package/src/lib/live-voice/connection.ts +5 -6
- package/src/lib/port-heal.ts +3 -19
- package/src/lib/runtime-url.ts +15 -45
- package/src/lib/tunnels/gateway-notify.ts +1 -1
- package/src/lib/upgrade-lifecycle.ts +3 -7
|
@@ -3,7 +3,9 @@ import fs from "node:fs";
|
|
|
3
3
|
import type { TokenResult } from "./guardian-token";
|
|
4
4
|
import {
|
|
5
5
|
FLATTENED_FIRST_SEGMENTS,
|
|
6
|
+
getGatewayUrl,
|
|
6
7
|
getLoopbackGatewayPort,
|
|
8
|
+
isCloudHome,
|
|
7
9
|
isLoopbackGatewayCloud,
|
|
8
10
|
isUsableRuntimeUrl,
|
|
9
11
|
LockfileAssistantSchema,
|
|
@@ -209,18 +211,24 @@ export function gatewayTargetsFromLockfile(lockfile: {
|
|
|
209
211
|
if (!parsed.success) {
|
|
210
212
|
continue;
|
|
211
213
|
}
|
|
212
|
-
const { assistantId
|
|
214
|
+
const { assistantId } = parsed.data;
|
|
213
215
|
if (!assistantId) {
|
|
214
216
|
continue;
|
|
215
217
|
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
+
const gatewayUrl = getGatewayUrl(parsed.data);
|
|
219
|
+
// Cloud assistants are driven through the platform session, never
|
|
220
|
+
// forwarded over this machine's proxy.
|
|
221
|
+
if (isCloudHome(parsed.data.cloud)) {
|
|
218
222
|
continue;
|
|
219
223
|
}
|
|
220
|
-
if (!
|
|
224
|
+
if (isUsableRuntimeUrl(gatewayUrl) && !isLoopbackPublicUrl(gatewayUrl)) {
|
|
225
|
+
targets.set(assistantId, { kind: "remote", runtimeUrl: gatewayUrl });
|
|
221
226
|
continue;
|
|
222
227
|
}
|
|
223
|
-
|
|
228
|
+
if (!isLoopbackGatewayCloud(parsed.data.cloud)) {
|
|
229
|
+
continue;
|
|
230
|
+
}
|
|
231
|
+
const port = getLoopbackGatewayPort(parsed.data);
|
|
224
232
|
if (port != null && port >= MIN_GATEWAY_PORT && port <= MAX_GATEWAY_PORT) {
|
|
225
233
|
targets.set(assistantId, { kind: "loopback", port });
|
|
226
234
|
}
|
|
@@ -27,6 +27,11 @@ describe("parseLockfile", () => {
|
|
|
27
27
|
cloudBaseUrl: "https://platform.example.com",
|
|
28
28
|
cloudOrganizationId: "org_1",
|
|
29
29
|
resources: { gatewayPort: 7777, daemonPort: 7778 },
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
assistantId: "asst_2",
|
|
33
|
+
name: "Bob",
|
|
34
|
+
cloud: "custom",
|
|
30
35
|
ipAddress: "203.0.113.9",
|
|
31
36
|
port: 7831,
|
|
32
37
|
},
|
|
@@ -24,8 +24,12 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import { isLoopbackPublicUrl } from "@mycadet/service-contracts/remote-web-pairing";
|
|
26
26
|
import { TUNNEL_PROVIDERS } from "@mycadet/service-contracts/ingress";
|
|
27
|
+
import { SEEDS } from "@mycadet/environments";
|
|
27
28
|
import { z } from "zod";
|
|
28
29
|
|
|
30
|
+
import { resolveEnvironmentName } from "./environment";
|
|
31
|
+
import { readLockfile } from "./lockfile";
|
|
32
|
+
|
|
29
33
|
/**
|
|
30
34
|
* Known deployment topologies of a Cadet:
|
|
31
35
|
* - `local` — on-machine bare-metal processes
|
|
@@ -187,6 +191,57 @@ export function getLoopbackGatewayPort(entry: {
|
|
|
187
191
|
}
|
|
188
192
|
}
|
|
189
193
|
|
|
194
|
+
/**
|
|
195
|
+
* The gateway port a freshly hatched assistant's gateway listens on, with
|
|
196
|
+
* the `GATEWAY_PORT` env override the CLI tooling honors.
|
|
197
|
+
*/
|
|
198
|
+
export const GATEWAY_PORT = process.env.GATEWAY_PORT
|
|
199
|
+
? Number(process.env.GATEWAY_PORT)
|
|
200
|
+
: 7830;
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* The cloud URL stack: the lockfile's platform base url (what the active
|
|
204
|
+
* assistant was last hatched/waked against), else the `CADET_CLOUD_URL`
|
|
205
|
+
* override, else the resolved environment's cloud url.
|
|
206
|
+
*/
|
|
207
|
+
function getCloudUrl(): string {
|
|
208
|
+
const lockfileUrl = readLockfile().cloudBaseUrl;
|
|
209
|
+
return (
|
|
210
|
+
(typeof lockfileUrl === "string" && lockfileUrl.trim()) ||
|
|
211
|
+
process.env.CADET_CLOUD_URL?.trim() ||
|
|
212
|
+
SEEDS[resolveEnvironmentName()]?.cloudUrl ||
|
|
213
|
+
SEEDS.production!.cloudUrl
|
|
214
|
+
);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* The URL to dial an entry's gateway on, derived from the entry's canonical
|
|
219
|
+
* fields — the one seam every consumer addresses a gateway through:
|
|
220
|
+
*
|
|
221
|
+
* - `custom` remotes: their recorded host and port.
|
|
222
|
+
* - cloud-managed: the recorded platform URL, else the cloud URL stack.
|
|
223
|
+
* - loopback topologies (`local`, `docker`, `apple-container`): the
|
|
224
|
+
* recorded loopback gateway port, else the default gateway port.
|
|
225
|
+
*
|
|
226
|
+
* The recorded `runtimeUrl` only survives as a last resort for entries
|
|
227
|
+
* whose canonical fields predate this resolver; it is scheduled to die
|
|
228
|
+
* once every consumer reads through here.
|
|
229
|
+
*/
|
|
230
|
+
export function getGatewayUrl(entry: LockfileAssistant): string {
|
|
231
|
+
if (entry.cloud === "custom" && entry.ipAddress && entry.port) {
|
|
232
|
+
return `http://${entry.ipAddress}:${entry.port}`;
|
|
233
|
+
}
|
|
234
|
+
if (isCloudHome(entry.cloud)) {
|
|
235
|
+
return (entry.runtimeUrl || getCloudUrl()).replace(/\/+$/, "");
|
|
236
|
+
}
|
|
237
|
+
const port = getLoopbackGatewayPort(entry);
|
|
238
|
+
if (port) return `http://127.0.0.1:${port}`;
|
|
239
|
+
return (entry.runtimeUrl || `http://127.0.0.1:${GATEWAY_PORT}`).replace(
|
|
240
|
+
/\/+$/,
|
|
241
|
+
"",
|
|
242
|
+
);
|
|
243
|
+
}
|
|
244
|
+
|
|
190
245
|
/**
|
|
191
246
|
* Per-instance resources for a local assistant: the renderer-facing ports,
|
|
192
247
|
* the instance directory, the local runtime install metadata, and the
|
package/package.json
CHANGED
|
@@ -58,13 +58,6 @@ describe("fetchReleases", () => {
|
|
|
58
58
|
expect(url).toContain("limit=100");
|
|
59
59
|
});
|
|
60
60
|
|
|
61
|
-
test("uses the cloudUrl override over the resolved default", async () => {
|
|
62
|
-
const fetchMock = mockFetchJson([RELEASE]);
|
|
63
|
-
await fetchReleases({ cloudUrl: "https://other-platform.test" });
|
|
64
|
-
const url = String(fetchMock.mock.calls[0][0]);
|
|
65
|
-
expect(url).toContain("https://other-platform.test/v1/releases/");
|
|
66
|
-
});
|
|
67
|
-
|
|
68
61
|
test("returns null on non-OK response", async () => {
|
|
69
62
|
mockFetchJson({ detail: "nope" }, 500);
|
|
70
63
|
expect(await fetchReleases()).toBeNull();
|
|
@@ -26,6 +26,7 @@ import {
|
|
|
26
26
|
} from "../lib/guardian-token.js";
|
|
27
27
|
import { getCurrentEnvironment } from "../lib/environments/resolve.js";
|
|
28
28
|
import { withPreconnect } from "./helpers/http.js";
|
|
29
|
+
import { makeEntry } from "./helpers/lockfile-entry.js";
|
|
29
30
|
|
|
30
31
|
function makeTokenData(suffix: string): GuardianTokenData {
|
|
31
32
|
const now = new Date().toISOString();
|
|
@@ -290,7 +291,9 @@ describe("refreshGuardianToken", () => {
|
|
|
290
291
|
);
|
|
291
292
|
});
|
|
292
293
|
|
|
293
|
-
const leased = await leaseGuardianToken(
|
|
294
|
+
const leased = await leaseGuardianToken(
|
|
295
|
+
makeEntry({ assistantId: "px" }),
|
|
296
|
+
);
|
|
294
297
|
|
|
295
298
|
expect(leased.accessToken).toBe("access-lease");
|
|
296
299
|
expect(leased.refreshAfter).toBeDefined();
|
|
@@ -315,7 +318,9 @@ describe("refreshGuardianToken", () => {
|
|
|
315
318
|
);
|
|
316
319
|
});
|
|
317
320
|
|
|
318
|
-
const err = await leaseGuardianToken(
|
|
321
|
+
const err = await leaseGuardianToken(
|
|
322
|
+
makeEntry({ assistantId: "px" }),
|
|
323
|
+
).then(
|
|
319
324
|
() => null,
|
|
320
325
|
(e: unknown) => e,
|
|
321
326
|
);
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { describe, expect, test } from "bun:test";
|
|
2
2
|
|
|
3
3
|
import { GATEWAY_PORT } from "../lib/constants.js";
|
|
4
|
-
import { getGatewayUrl } from "
|
|
5
|
-
import { getCloudUrl } from "../lib/cloud-client.js";
|
|
4
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
6
5
|
import type { LockfileAssistant } from "../lib/assistant-config.js";
|
|
7
6
|
|
|
8
7
|
const entry = (overrides: Partial<LockfileAssistant>): LockfileAssistant =>
|
|
@@ -36,8 +35,8 @@ describe("getGatewayUrl", () => {
|
|
|
36
35
|
).toBe("https://cloud.example.com");
|
|
37
36
|
});
|
|
38
37
|
|
|
39
|
-
test("cloud-managed entries without a recorded URL resolve through the
|
|
40
|
-
expect(getGatewayUrl(entry({ cloud: "cloud" }))).
|
|
38
|
+
test("cloud-managed entries without a recorded URL resolve through the cloud-url stack", () => {
|
|
39
|
+
expect(getGatewayUrl(entry({ cloud: "cloud" }))).toMatch(/^https?:\/\//);
|
|
41
40
|
});
|
|
42
41
|
|
|
43
42
|
test("loopback topologies derive from the recorded gateway port", () => {
|
|
@@ -431,9 +431,10 @@ describe("cadet upgrade local", () => {
|
|
|
431
431
|
"existing-bootstrap-secret",
|
|
432
432
|
);
|
|
433
433
|
expect(leaseGuardianTokenMock).toHaveBeenCalledWith(
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
434
|
+
expect.objectContaining({
|
|
435
|
+
assistantId: "local-assistant",
|
|
436
|
+
guardianBootstrapSecret: "existing-bootstrap-secret",
|
|
437
|
+
}),
|
|
437
438
|
);
|
|
438
439
|
expect(runNgrokTunnelMock).toHaveBeenCalledWith({
|
|
439
440
|
port: 7830,
|
package/src/commands/client.ts
CHANGED
|
@@ -18,11 +18,8 @@ import {
|
|
|
18
18
|
refreshGuardianToken,
|
|
19
19
|
guardianTokenDueForRenewal,
|
|
20
20
|
} from "../lib/guardian-token";
|
|
21
|
-
import {
|
|
22
|
-
|
|
23
|
-
normalizeRuntimeUrl,
|
|
24
|
-
trustedRefreshUrl,
|
|
25
|
-
} from "../lib/runtime-url";
|
|
21
|
+
import { normalizeRuntimeUrl, trustedRefreshUrl } from "../lib/runtime-url";
|
|
22
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
26
23
|
import {
|
|
27
24
|
CLI_INTERFACE_ID,
|
|
28
25
|
getClientRegistrationHeaders,
|
package/src/commands/debug.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
2
3
|
import { cliCommand } from "../lib/cli-name.js";
|
|
3
4
|
import { isCloudHome } from "../lib/cloud-values.js";
|
|
4
5
|
import {
|
|
@@ -73,12 +74,6 @@ export const debug = Object.assign(
|
|
|
73
74
|
console.error(`Not logged in. Run '${cliCommand()} login' first.`);
|
|
74
75
|
process.exit(1);
|
|
75
76
|
}
|
|
76
|
-
if (!entry.runtimeUrl) {
|
|
77
|
-
console.error(
|
|
78
|
-
`Error: '${reference}' has no recorded gateway URL to export logs from.`,
|
|
79
|
-
);
|
|
80
|
-
process.exit(1);
|
|
81
|
-
}
|
|
82
77
|
const cloudAssistantId = entry.cloudAssistantId?.trim();
|
|
83
78
|
if (!cloudAssistantId) {
|
|
84
79
|
console.error(
|
|
@@ -114,7 +109,7 @@ export const debug = Object.assign(
|
|
|
114
109
|
.object({ url: z.string().url() })
|
|
115
110
|
.parse(await urlResponse.json());
|
|
116
111
|
const logs = await loopbackSafeFetch(
|
|
117
|
-
`${entry
|
|
112
|
+
`${getGatewayUrl(entry)}/v1/logs/export`,
|
|
118
113
|
{
|
|
119
114
|
method: "POST",
|
|
120
115
|
signal: AbortSignal.timeout(180_000),
|
|
@@ -155,19 +150,8 @@ async function daemonAccessToken(
|
|
|
155
150
|
return cached.accessToken;
|
|
156
151
|
}
|
|
157
152
|
}
|
|
158
|
-
if (!entry.runtimeUrl) {
|
|
159
|
-
throw new Error(
|
|
160
|
-
`No recorded gateway URL to lease a guardian token from for ${reference}.`,
|
|
161
|
-
);
|
|
162
|
-
}
|
|
163
153
|
try {
|
|
164
|
-
return (
|
|
165
|
-
await leaseGuardianToken(
|
|
166
|
-
entry.runtimeUrl,
|
|
167
|
-
entry.assistantId,
|
|
168
|
-
entry.guardianBootstrapSecret,
|
|
169
|
-
)
|
|
170
|
-
).accessToken;
|
|
154
|
+
return (await leaseGuardianToken(entry)).accessToken;
|
|
171
155
|
} catch (err) {
|
|
172
156
|
const msg = err instanceof Error ? err.message : String(err);
|
|
173
157
|
if (msg.includes("ECONNREFUSED") || msg.includes("fetch failed")) {
|
package/src/commands/devices.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
12
|
import { z } from "zod";
|
|
13
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
13
14
|
import { createHash } from "node:crypto";
|
|
14
15
|
import { hostname } from "node:os";
|
|
15
16
|
|
|
@@ -38,7 +39,6 @@ import { GATEWAY_INTERNAL_PORT } from "../lib/environments/paths.js";
|
|
|
38
39
|
import { execOutput } from "../lib/step-runner.js";
|
|
39
40
|
import { dockerResourceNames } from "../lib/docker.js";
|
|
40
41
|
import { loopbackSafeFetch } from "../lib/loopback-fetch.js";
|
|
41
|
-
import { getGatewayUrl } from "../lib/runtime-url.js";
|
|
42
42
|
|
|
43
43
|
const dockerGatewayResponseSchema = z.object({
|
|
44
44
|
status: z.number().int().min(200).max(599),
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { formatGuardianRefreshCliFailure } from "@mycadet/local-mode";
|
|
2
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
2
3
|
import { cliCommand } from "../../lib/cli-name.js";
|
|
3
|
-
import { getGatewayUrl } from "../../lib/runtime-url.js";
|
|
4
4
|
|
|
5
5
|
import {
|
|
6
6
|
type LockfileAssistant,
|
|
@@ -55,7 +55,7 @@ async function repairGuardianCredential(
|
|
|
55
55
|
for (let attempt = 1; attempt <= maxAttempts; attempt++) {
|
|
56
56
|
try {
|
|
57
57
|
await resetGuardianBootstrap(gatewayUrl, bootstrapSecret);
|
|
58
|
-
await leaseGuardianToken(
|
|
58
|
+
await leaseGuardianToken(entry);
|
|
59
59
|
return true;
|
|
60
60
|
} catch (err) {
|
|
61
61
|
if (err instanceof GuardianLeasePermanentError) return false;
|
package/src/commands/hatch.ts
CHANGED
|
@@ -11,7 +11,6 @@ import type { RemoteHost } from "../lib/constants";
|
|
|
11
11
|
import { hatchDocker } from "../lib/docker";
|
|
12
12
|
import { hatchLocal } from "../lib/hatch-local";
|
|
13
13
|
import {
|
|
14
|
-
getCloudUrl,
|
|
15
14
|
hatchAssistant,
|
|
16
15
|
readCloudToken,
|
|
17
16
|
} from "../lib/cloud-client";
|
|
@@ -287,11 +286,8 @@ async function hatchCadetPlatform(): Promise<void> {
|
|
|
287
286
|
|
|
288
287
|
const { assistant: result } = await hatchAssistant(token);
|
|
289
288
|
|
|
290
|
-
const cloudUrl = getCloudUrl();
|
|
291
|
-
|
|
292
289
|
saveLockfileAssistant({
|
|
293
290
|
assistantId: result.id,
|
|
294
|
-
runtimeUrl: cloudUrl,
|
|
295
291
|
cloud: "cloud",
|
|
296
292
|
hatchedAt: new Date().toISOString(),
|
|
297
293
|
});
|
package/src/commands/pair.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
// Call `qrcodeTerminal.generate` as a method — the library reads its default
|
|
18
18
|
// error-correction level off `this`, so a destructured import renders nothing.
|
|
19
19
|
import qrcodeTerminal from "qrcode-terminal";
|
|
20
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
20
21
|
|
|
21
22
|
import {
|
|
22
23
|
buildRemoteWebPairingUrl,
|
|
@@ -35,7 +36,6 @@ import {
|
|
|
35
36
|
type LockfileAssistant,
|
|
36
37
|
} from "../lib/assistant-config.js";
|
|
37
38
|
import { getCurrentEnvironment } from "../lib/environments/resolve.js";
|
|
38
|
-
import { getGatewayUrl } from "../lib/runtime-url.js";
|
|
39
39
|
import { loopbackSafeFetch } from "../lib/loopback-fetch.js";
|
|
40
40
|
import { dockerResourceNames } from "../lib/docker.js";
|
|
41
41
|
import { gatewayCliInvocation } from "../lib/local.js";
|
package/src/commands/ps.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { getNginxIngressPort } from "../lib/nginx-ingress.js";
|
|
2
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
2
3
|
import { getIngressPaths, readIngressState } from "../lib/nginx-ingress.js";
|
|
3
4
|
import { cliCommand } from "../lib/cli-name.js";
|
|
4
5
|
import { isCloudHome } from "../lib/cloud-values.js";
|
|
@@ -26,7 +27,6 @@ import {
|
|
|
26
27
|
readRootProcesses,
|
|
27
28
|
type LockfileAssistant,
|
|
28
29
|
} from "../lib/assistant-config";
|
|
29
|
-
import { getGatewayUrl } from "../lib/runtime-url.js";
|
|
30
30
|
import { parseAssistantTargetArg } from "../lib/assistant-target-args.js";
|
|
31
31
|
import { resolveEnvironmentSource } from "../lib/environments/resolve";
|
|
32
32
|
import { loadGuardianToken } from "../lib/guardian-token";
|
|
@@ -469,7 +469,7 @@ function locationFor(entry: LockfileAssistant): string {
|
|
|
469
469
|
if (entry.cloud === "docker") {
|
|
470
470
|
return `docker container ${dockerResourceNames(entry.assistantId).assistantContainer}`;
|
|
471
471
|
}
|
|
472
|
-
return entry
|
|
472
|
+
return getGatewayUrl(entry);
|
|
473
473
|
}
|
|
474
474
|
|
|
475
475
|
async function getAssistantProcessRows(
|
|
@@ -520,16 +520,14 @@ async function getAssistantProcessRows(
|
|
|
520
520
|
: "management socket not found",
|
|
521
521
|
},
|
|
522
522
|
];
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
});
|
|
532
|
-
}
|
|
523
|
+
const token = loadGuardianToken(entry.assistantId)?.accessToken;
|
|
524
|
+
const health = await checkHealth(getGatewayUrl(entry), token);
|
|
525
|
+
rows.push({
|
|
526
|
+
name: "gateway",
|
|
527
|
+
type: ASSISTANT_TYPE,
|
|
528
|
+
status: withStatusEmoji(health.status),
|
|
529
|
+
info: getGatewayUrl(entry) + (health.detail ? ` | ${health.detail}` : ""),
|
|
530
|
+
});
|
|
533
531
|
return rows;
|
|
534
532
|
}
|
|
535
533
|
|
|
@@ -782,11 +780,9 @@ async function getAssistantListHealth(
|
|
|
782
780
|
|
|
783
781
|
if (entry.cloud === "apple-container") {
|
|
784
782
|
// Apple containers are managed by the macOS app. Probe the gateway
|
|
785
|
-
// (
|
|
783
|
+
// (the macOS app records its loopback port on the entry).
|
|
786
784
|
const token = loadGuardianToken(entry.assistantId)?.accessToken;
|
|
787
|
-
return entry
|
|
788
|
-
? checkHealth(entry.runtimeUrl, token)
|
|
789
|
-
: { status: "unknown", detail: "no runtime URL" };
|
|
785
|
+
return checkHealth(getGatewayUrl(entry), token);
|
|
790
786
|
}
|
|
791
787
|
|
|
792
788
|
if (isCloudHome(entry.cloud)) {
|
|
@@ -803,7 +799,7 @@ function formatAssistantListRow(
|
|
|
803
799
|
health: AssistantHealth,
|
|
804
800
|
): TableRow {
|
|
805
801
|
const infoParts: string[] = [];
|
|
806
|
-
|
|
802
|
+
infoParts.push(getGatewayUrl(entry));
|
|
807
803
|
if (entry.cloud) infoParts.push(`remote: ${entry.cloud}`);
|
|
808
804
|
if (health.detail) infoParts.push(health.detail);
|
|
809
805
|
|
package/src/commands/restore.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { isCloudHome } from "../lib/cloud-values.js";
|
|
2
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
2
3
|
import { cliCommand } from "../lib/cli-name.js";
|
|
3
4
|
import {
|
|
4
5
|
existsSync,
|
|
@@ -30,7 +31,7 @@ import {
|
|
|
30
31
|
platformUploadToSignedUrl,
|
|
31
32
|
platformImportPreflightFromGcs,
|
|
32
33
|
platformImportBundleFromGcs,
|
|
33
|
-
|
|
34
|
+
cloudPollJobStatus,
|
|
34
35
|
} from "../lib/cloud-client.js";
|
|
35
36
|
import { restoreRootBackup, validateRootArchive } from "../lib/root-backup.js";
|
|
36
37
|
|
|
@@ -171,7 +172,7 @@ async function restorePlatform(
|
|
|
171
172
|
contentLength: bundleData.length,
|
|
172
173
|
},
|
|
173
174
|
token,
|
|
174
|
-
entry
|
|
175
|
+
getGatewayUrl(entry),
|
|
175
176
|
);
|
|
176
177
|
console.log("Uploading bundle...");
|
|
177
178
|
await platformUploadToSignedUrl(uploadUrl, new Uint8Array(bundleData));
|
|
@@ -185,7 +186,7 @@ async function restorePlatform(
|
|
|
185
186
|
preflightResult = await platformImportPreflightFromGcs(
|
|
186
187
|
bundleKey,
|
|
187
188
|
token,
|
|
188
|
-
entry
|
|
189
|
+
getGatewayUrl(entry),
|
|
189
190
|
);
|
|
190
191
|
} catch (err) {
|
|
191
192
|
if (err instanceof Error && err.name === "TimeoutError") {
|
|
@@ -298,7 +299,7 @@ async function restorePlatform(
|
|
|
298
299
|
importResult = await platformImportBundleFromGcs(
|
|
299
300
|
bundleKey,
|
|
300
301
|
token,
|
|
301
|
-
entry
|
|
302
|
+
getGatewayUrl(entry),
|
|
302
303
|
);
|
|
303
304
|
} catch (err) {
|
|
304
305
|
if (err instanceof Error && err.name === "TimeoutError") {
|
|
@@ -362,9 +363,9 @@ async function restorePlatform(
|
|
|
362
363
|
while (Date.now() < deadline) {
|
|
363
364
|
await new Promise((resolve) => setTimeout(resolve, POLL_INTERVAL_MS));
|
|
364
365
|
|
|
365
|
-
let status: Awaited<ReturnType<typeof
|
|
366
|
+
let status: Awaited<ReturnType<typeof cloudPollJobStatus>>;
|
|
366
367
|
try {
|
|
367
|
-
status = await
|
|
368
|
+
status = await cloudPollJobStatus(jobId, token, getGatewayUrl(entry));
|
|
368
369
|
} catch (err) {
|
|
369
370
|
const msg = err instanceof Error ? err.message : String(err);
|
|
370
371
|
if (msg.includes("not found")) {
|
package/src/commands/retire.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { isCloudHome } from "../lib/cloud-values.js";
|
|
2
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
2
3
|
import { cliCommand } from "../lib/cli-name.js";
|
|
3
|
-
import { getGatewayUrl } from "../lib/runtime-url.js";
|
|
4
4
|
import { existsSync, unlinkSync } from "fs";
|
|
5
5
|
import { join } from "path";
|
|
6
6
|
|
|
@@ -152,10 +152,7 @@ async function retireCustom(entry: LockfileAssistant): Promise<void> {
|
|
|
152
152
|
console.log(`\u2705 Custom instance retired.`);
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
async function
|
|
156
|
-
assistantId: string,
|
|
157
|
-
runtimeUrl?: string,
|
|
158
|
-
): Promise<void> {
|
|
155
|
+
async function retireCloud(entry: LockfileAssistant): Promise<void> {
|
|
159
156
|
console.log("\u{1F5D1}\ufe0f Retiring Cadet Cloud-hosted instance...\n");
|
|
160
157
|
|
|
161
158
|
const token = readPlatformRetireToken();
|
|
@@ -167,9 +164,9 @@ async function retireCadet(
|
|
|
167
164
|
}
|
|
168
165
|
|
|
169
166
|
try {
|
|
170
|
-
await deleteCloudAssistant(assistantId, {
|
|
167
|
+
await deleteCloudAssistant(entry.assistantId, {
|
|
171
168
|
token,
|
|
172
|
-
cloudUrl:
|
|
169
|
+
cloudUrl: getGatewayUrl(entry),
|
|
173
170
|
label: "Platform retire",
|
|
174
171
|
successMessage: "\u2705 Platform-hosted instance retired.",
|
|
175
172
|
alreadyGoneMessage:
|
|
@@ -363,9 +360,9 @@ async function retireInner(): Promise<void> {
|
|
|
363
360
|
} else if (cloud === "custom") {
|
|
364
361
|
await retireCustom(entry);
|
|
365
362
|
} else if (isCloudHome(cloud)) {
|
|
366
|
-
await
|
|
363
|
+
await retireCloud(entry);
|
|
367
364
|
} else {
|
|
368
|
-
console.error(`Error: Unknown
|
|
365
|
+
console.error(`Error: Unknown remote type '${cloud}'.`);
|
|
369
366
|
process.exit(1);
|
|
370
367
|
}
|
|
371
368
|
|
package/src/commands/setup.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { resolveAssistant } from "../lib/assistant-config.js";
|
|
2
|
+
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
2
3
|
import { cliCommand } from "../lib/cli-name.js";
|
|
3
|
-
import { getGatewayUrl } from "../lib/runtime-url.js";
|
|
4
4
|
import {
|
|
5
5
|
leaseGuardianToken,
|
|
6
6
|
loadGuardianToken,
|
|
@@ -120,15 +120,7 @@ async function resolveSetupBearerToken(
|
|
|
120
120
|
entry.cloud === "local" || entry.cloud === "docker";
|
|
121
121
|
if (canLeaseGuardianToken) {
|
|
122
122
|
try {
|
|
123
|
-
const
|
|
124
|
-
typeof entry.guardianBootstrapSecret === "string"
|
|
125
|
-
? entry.guardianBootstrapSecret
|
|
126
|
-
: undefined;
|
|
127
|
-
const leasedToken = await leaseGuardianToken(
|
|
128
|
-
gatewayUrl,
|
|
129
|
-
entry.assistantId,
|
|
130
|
-
bootstrapSecret,
|
|
131
|
-
);
|
|
123
|
+
const leasedToken = await leaseGuardianToken(entry);
|
|
132
124
|
if (isGuardianAccessTokenUsable(leasedToken)) {
|
|
133
125
|
return leasedToken.accessToken;
|
|
134
126
|
}
|