@mycadet/cli 0.13.0-dev.202611140220.fac72d3 → 0.13.0-dev.202611141723.98995ee
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/knip.json +0 -3
- package/node_modules/@mycadet/assistant-api/constants/codex-models.ts +22 -0
- package/node_modules/@mycadet/assistant-api/index.ts +1 -0
- 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/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/ipc-server-utils/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/index.ts +11 -0
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/package.json +7 -6
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/shared/seeds.ts +151 -0
- package/node_modules/@mycadet/local-mode/package.json +1 -2
- package/node_modules/@mycadet/local-mode/src/__tests__/cloud-backup.test.ts +5 -9
- package/node_modules/@mycadet/local-mode/src/__tests__/environment-base-url.test.ts +67 -0
- package/node_modules/@mycadet/local-mode/src/__tests__/helpers/lockfile-entry.ts +0 -1
- package/node_modules/@mycadet/local-mode/src/__tests__/operations-doctor.test.ts +16 -6
- package/node_modules/@mycadet/local-mode/src/__tests__/operations-retire.test.ts +3 -4
- package/node_modules/@mycadet/local-mode/src/__tests__/remotes-local-retire.test.ts +4 -10
- package/node_modules/@mycadet/local-mode/src/cloud-auth.ts +9 -31
- package/node_modules/@mycadet/local-mode/src/cloud-registration.ts +7 -18
- package/node_modules/@mycadet/local-mode/src/cloud-releases.ts +2 -3
- package/node_modules/@mycadet/local-mode/src/config.ts +2 -7
- package/node_modules/@mycadet/local-mode/src/daemon-readiness.ts +3 -5
- package/node_modules/@mycadet/local-mode/src/index.ts +0 -1
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.test.ts +0 -1
- package/node_modules/@mycadet/local-mode/src/lockfile-contract.ts +4 -22
- package/node_modules/@mycadet/local-mode/src/operations/cloud-proxy.ts +3 -3
- package/node_modules/@mycadet/local-mode/src/operations/exec.ts +3 -2
- package/node_modules/@mycadet/local-mode/src/ports.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/backup.ts +4 -4
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/exec.ts +0 -10
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/hatch.ts +5 -8
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/migrations.ts +11 -18
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/restore.ts +3 -8
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/retire.ts +3 -6
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/terminal-client.ts +13 -16
- package/node_modules/@mycadet/local-mode/src/remotes/cloud/upgrade.ts +11 -17
- package/node_modules/@mycadet/local-mode/src/remotes/local/common.ts +20 -41
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/shared/index.ts +11 -0
- package/node_modules/@mycadet/shared/package.json +7 -6
- package/node_modules/@mycadet/shared/seeds.ts +151 -0
- package/package.json +1 -3
- package/src/__tests__/cloud-client.test.ts +49 -90
- package/src/__tests__/debug.test.ts +7 -1
- package/src/__tests__/helpers/lockfile-entry.ts +0 -1
- package/src/__tests__/pair.test.ts +11 -12
- package/src/__tests__/ps-cloud-status.test.ts +6 -3
- package/src/__tests__/servers/bun.test.ts +1 -1
- package/src/__tests__/setup.test.ts +16 -10
- package/src/commands/debug.ts +3 -3
- package/src/commands/login.ts +1 -2
- package/src/commands/ps.ts +3 -1
- package/src/commands/terminal.ts +2 -5
- package/src/lib/__tests__/cloud-client-signed-url.test.ts +24 -19
- package/src/lib/assistant-client.ts +2 -2
- package/src/lib/assistant-config.ts +1 -17
- package/src/lib/cloud-client.ts +11 -16
- package/src/lib/cloud-login.ts +7 -9
- package/src/lib/live-voice/tunnel.ts +1 -1
- package/src/lib/remotes/cloud.ts +3 -3
- package/src/lib/servers/common.ts +1 -2
- package/src/lib/sync-cloud-assistants.ts +2 -2
- package/src/lib/terminal-session.ts +3 -2
- package/node_modules/@mycadet/environments/package.json +0 -21
- package/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -76
- package/node_modules/@mycadet/environments/src/__tests__/install-layout.test.ts +0 -98
- package/node_modules/@mycadet/environments/src/__tests__/package-boundary.test.ts +0 -95
- package/node_modules/@mycadet/environments/src/__tests__/test-path-guard.test.ts +0 -89
- package/node_modules/@mycadet/environments/src/index.ts +0 -21
- package/node_modules/@mycadet/environments/src/install-layout.ts +0 -49
- package/node_modules/@mycadet/environments/src/seeds.ts +0 -89
- package/node_modules/@mycadet/environments/src/shell.test.ts +0 -89
- package/node_modules/@mycadet/environments/src/shell.ts +0 -110
- package/node_modules/@mycadet/environments/src/test-path-guard.ts +0 -113
- package/node_modules/@mycadet/environments/src/types.ts +0 -70
- package/node_modules/@mycadet/environments/tsconfig.json +0 -20
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/package.json +0 -21
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/cloud-assistant-hub-url.test.ts +0 -76
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/install-layout.test.ts +0 -98
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/package-boundary.test.ts +0 -95
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/__tests__/test-path-guard.test.ts +0 -89
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/index.ts +0 -21
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/install-layout.ts +0 -49
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/seeds.ts +0 -89
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/shell.test.ts +0 -89
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/shell.ts +0 -110
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/test-path-guard.ts +0 -113
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/src/types.ts +0 -70
- package/node_modules/@mycadet/local-mode/node_modules/@mycadet/environments/tsconfig.json +0 -20
- package/src/lib/environments/__tests__/seeds.test.ts +0 -78
|
@@ -2,9 +2,9 @@ import { readFileSync } from "node:fs";
|
|
|
2
2
|
import { join } from "node:path";
|
|
3
3
|
import { z } from "zod";
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
6
|
+
import { resolveConfigDir } from "./config";
|
|
6
7
|
import { cliCommand } from "./environment";
|
|
7
|
-
import { readLockfile } from "./lockfile";
|
|
8
8
|
import { loopbackSafeFetch } from "./loopback-fetch";
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -33,23 +33,6 @@ export function readCloudToken(): string | null {
|
|
|
33
33
|
}
|
|
34
34
|
}
|
|
35
35
|
|
|
36
|
-
/**
|
|
37
|
-
* Resolve the cloud API base URL. Resolution order:
|
|
38
|
-
* 1. `cloudBaseUrl` persisted on the lockfile when the active assistant
|
|
39
|
-
* was last hatched/waked — the source of truth for "what URL does the
|
|
40
|
-
* currently-active assistant target".
|
|
41
|
-
* 2. `CADET_CLOUD_URL` env var (explicit override, e.g. in CI).
|
|
42
|
-
* 3. The current environment's seed URL (e.g. `https://dev-cloud.mycadet.ai`
|
|
43
|
-
* for `CADET_ENVIRONMENT=dev`, `https://cloud.mycadet.ai` for prod).
|
|
44
|
-
*/
|
|
45
|
-
export function resolveCloudUrl(): string {
|
|
46
|
-
const url = readLockfile().cloudBaseUrl;
|
|
47
|
-
const lockfileUrl = typeof url === "string" ? url.trim() : undefined;
|
|
48
|
-
return (
|
|
49
|
-
(lockfileUrl && lockfileUrl) || resolveLocalConfigFromEnv().cloudUrl.trim()
|
|
50
|
-
);
|
|
51
|
-
}
|
|
52
|
-
|
|
53
36
|
const VAK_PREFIX = "vak_";
|
|
54
37
|
|
|
55
38
|
/**
|
|
@@ -91,19 +74,16 @@ const ORG_ID_CACHE_TTL_MS = 60_000; // 60 seconds
|
|
|
91
74
|
* orgs in another tab). Clearing the entry forces the next auth-headers
|
|
92
75
|
* call to refetch the org ID from the cloud.
|
|
93
76
|
*/
|
|
94
|
-
export function invalidateOrgIdCache(token: string
|
|
95
|
-
orgIdCache.delete(`${token}
|
|
77
|
+
export function invalidateOrgIdCache(token: string): void {
|
|
78
|
+
orgIdCache.delete(`${token}::`);
|
|
96
79
|
}
|
|
97
80
|
|
|
98
81
|
const OrganizationListResponseSchema = z.object({
|
|
99
82
|
results: z.array(z.object({ id: z.string(), name: z.string() })).optional(),
|
|
100
83
|
});
|
|
101
84
|
|
|
102
|
-
export async function fetchOrganizationId(
|
|
103
|
-
|
|
104
|
-
cloudUrl?: string,
|
|
105
|
-
): Promise<string> {
|
|
106
|
-
const resolvedUrl = cloudUrl || resolveCloudUrl();
|
|
85
|
+
export async function fetchOrganizationId(token: string): Promise<string> {
|
|
86
|
+
const resolvedUrl = getCloudBaseUrl();
|
|
107
87
|
const url = `${resolvedUrl}/v1/organizations/`;
|
|
108
88
|
|
|
109
89
|
const controller = new AbortController();
|
|
@@ -150,10 +130,9 @@ export async function fetchOrganizationId(
|
|
|
150
130
|
*/
|
|
151
131
|
export async function cloudAuthHeaders(
|
|
152
132
|
token: string,
|
|
153
|
-
cloudUrl?: string,
|
|
154
133
|
): Promise<Record<string, string>> {
|
|
155
134
|
try {
|
|
156
|
-
return await resolveAuthHeaders(token
|
|
135
|
+
return await resolveAuthHeaders(token);
|
|
157
136
|
} catch (err) {
|
|
158
137
|
const msg = err instanceof Error ? err.message : String(err);
|
|
159
138
|
if (msg.includes("401") || msg.includes("403")) {
|
|
@@ -167,7 +146,6 @@ export async function cloudAuthHeaders(
|
|
|
167
146
|
|
|
168
147
|
async function resolveAuthHeaders(
|
|
169
148
|
token: string,
|
|
170
|
-
cloudUrl?: string,
|
|
171
149
|
): Promise<Record<string, string>> {
|
|
172
150
|
const base: Record<string, string> = {
|
|
173
151
|
"Content-Type": "application/json",
|
|
@@ -179,13 +157,13 @@ async function resolveAuthHeaders(
|
|
|
179
157
|
return base;
|
|
180
158
|
}
|
|
181
159
|
|
|
182
|
-
const cacheKey = `${token}
|
|
160
|
+
const cacheKey = `${token}::`;
|
|
183
161
|
const cached = orgIdCache.get(cacheKey);
|
|
184
162
|
if (cached && Date.now() < cached.expiresAt) {
|
|
185
163
|
return { ...base, "Cadet-Organization-Id": cached.orgId };
|
|
186
164
|
}
|
|
187
165
|
|
|
188
|
-
const orgId = await fetchOrganizationId(token
|
|
166
|
+
const orgId = await fetchOrganizationId(token);
|
|
189
167
|
orgIdCache.set(cacheKey, {
|
|
190
168
|
orgId,
|
|
191
169
|
expiresAt: Date.now() + ORG_ID_CACHE_TTL_MS,
|
|
@@ -12,11 +12,8 @@ import {
|
|
|
12
12
|
} from "@mycadet/service-contracts/cloud-credential";
|
|
13
13
|
import { z } from "zod";
|
|
14
14
|
|
|
15
|
-
import {
|
|
16
|
-
|
|
17
|
-
readCloudToken,
|
|
18
|
-
resolveCloudUrl,
|
|
19
|
-
} from "./cloud-auth";
|
|
15
|
+
import { fetchOrganizationId, readCloudToken } from "./cloud-auth";
|
|
16
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
20
17
|
import { computeDeviceId, loadGuardianToken } from "./guardian-token";
|
|
21
18
|
import { saveLockfileAssistant } from "./lockfile";
|
|
22
19
|
import { getGatewayUrl, type LockfileAssistant } from "./lockfile-contract";
|
|
@@ -71,10 +68,9 @@ export async function ensureSelfHostedLocalRegistration(
|
|
|
71
68
|
runtimeAssistantId: string,
|
|
72
69
|
clientPlatform: string,
|
|
73
70
|
assistantVersion?: string,
|
|
74
|
-
cloudUrl?: string,
|
|
75
71
|
publicBaseUrl?: string,
|
|
76
72
|
): Promise<EnsureRegistrationResponse> {
|
|
77
|
-
const resolvedUrl =
|
|
73
|
+
const resolvedUrl = getCloudBaseUrl();
|
|
78
74
|
const body: Record<string, string> = {
|
|
79
75
|
client_installation_id: clientInstallationId,
|
|
80
76
|
runtime_assistant_id: runtimeAssistantId,
|
|
@@ -136,9 +132,8 @@ export async function reprovisionAssistantApiKey(
|
|
|
136
132
|
clientInstallationId: string,
|
|
137
133
|
runtimeAssistantId: string,
|
|
138
134
|
clientPlatform: string,
|
|
139
|
-
cloudUrl?: string,
|
|
140
135
|
): Promise<ReprovisionApiKeyResponse> {
|
|
141
|
-
const resolvedUrl =
|
|
136
|
+
const resolvedUrl = getCloudBaseUrl();
|
|
142
137
|
const body: Record<string, string> = {
|
|
143
138
|
client_installation_id: clientInstallationId,
|
|
144
139
|
runtime_assistant_id: runtimeAssistantId,
|
|
@@ -490,11 +485,8 @@ const AllauthSessionResponseSchema = z.object({
|
|
|
490
485
|
|
|
491
486
|
const PLATFORM_FETCH_TIMEOUT_MS = 10_000;
|
|
492
487
|
|
|
493
|
-
export async function fetchCurrentUser(
|
|
494
|
-
|
|
495
|
-
cloudUrl?: string,
|
|
496
|
-
): Promise<PlatformUser> {
|
|
497
|
-
const resolvedUrl = cloudUrl || resolveCloudUrl();
|
|
488
|
+
export async function fetchCurrentUser(token: string): Promise<PlatformUser> {
|
|
489
|
+
const resolvedUrl = getCloudBaseUrl();
|
|
498
490
|
const url = `${resolvedUrl}/_allauth/app/v1/auth/session`;
|
|
499
491
|
|
|
500
492
|
const controller = new AbortController();
|
|
@@ -518,7 +510,7 @@ export async function fetchCurrentUser(
|
|
|
518
510
|
throw new Error("Invalid or expired token. Please login again.");
|
|
519
511
|
}
|
|
520
512
|
throw new Error(
|
|
521
|
-
`
|
|
513
|
+
`Cloud API error: ${response.status} ${response.statusText}`,
|
|
522
514
|
);
|
|
523
515
|
}
|
|
524
516
|
|
|
@@ -557,7 +549,6 @@ export async function registerLocalAssistantWithCloud(
|
|
|
557
549
|
(await checkHealth(entry)).version,
|
|
558
550
|
fetchAssistantIngressUrl(gatewayUrl, guardianBearer(entry.assistantId)),
|
|
559
551
|
]);
|
|
560
|
-
const cloudUrl = resolveCloudUrl();
|
|
561
552
|
const registration = await ensureSelfHostedLocalRegistration(
|
|
562
553
|
token,
|
|
563
554
|
orgId,
|
|
@@ -565,13 +556,11 @@ export async function registerLocalAssistantWithCloud(
|
|
|
565
556
|
entry.assistantId,
|
|
566
557
|
"cli",
|
|
567
558
|
assistantVersion,
|
|
568
|
-
cloudUrl,
|
|
569
559
|
ingressUrl,
|
|
570
560
|
);
|
|
571
561
|
saveLockfileAssistant({
|
|
572
562
|
...entry,
|
|
573
563
|
cloudAssistantId: registration.assistant.id,
|
|
574
|
-
cloudBaseUrl: cloudUrl,
|
|
575
564
|
cloudOrganizationId: orgId,
|
|
576
565
|
});
|
|
577
566
|
log(
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
2
|
|
|
3
|
-
import { CADET_GITHUB_REPOSITORY } from "@mycadet/shared";
|
|
3
|
+
import { CADET_GITHUB_REPOSITORY, getCloudBaseUrl } from "@mycadet/shared";
|
|
4
4
|
import { loopbackSafeFetch } from "./loopback-fetch";
|
|
5
|
-
import { resolveCloudUrl as getCloudUrl } from "./cloud-auth";
|
|
6
5
|
|
|
7
6
|
const ReleaseListItemSchema = z.object({
|
|
8
7
|
version: z.string().min(1),
|
|
@@ -57,7 +56,7 @@ const RELEASES_FETCH_LIMIT = 100;
|
|
|
57
56
|
*/
|
|
58
57
|
export async function fetchReleases(): Promise<ReleaseListItem[] | null> {
|
|
59
58
|
try {
|
|
60
|
-
const cloudUrl =
|
|
59
|
+
const cloudUrl = getCloudBaseUrl();
|
|
61
60
|
const response = await loopbackSafeFetch(
|
|
62
61
|
`${cloudUrl}/v1/releases/?stable=true&limit=${RELEASES_FETCH_LIMIT}`,
|
|
63
62
|
{ signal: AbortSignal.timeout(10_000) },
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
2
2
|
|
|
3
3
|
import { resolveEnvironmentName } from "./environment";
|
|
4
4
|
import {
|
|
@@ -9,8 +9,6 @@ import {
|
|
|
9
9
|
resolveDataHome,
|
|
10
10
|
} from "./paths";
|
|
11
11
|
|
|
12
|
-
const PRODUCTION_ENVIRONMENT_NAME = "production";
|
|
13
|
-
|
|
14
12
|
export interface LocalEndpointConfig {
|
|
15
13
|
lockfilePath: string;
|
|
16
14
|
configDir: string;
|
|
@@ -21,13 +19,10 @@ export interface LocalEndpointConfig {
|
|
|
21
19
|
* Resolve the local endpoint config from the process environment.
|
|
22
20
|
*/
|
|
23
21
|
export function resolveLocalConfigFromEnv(): LocalEndpointConfig {
|
|
24
|
-
const cadetEnv = resolveEnvironmentName();
|
|
25
|
-
const seed = SEEDS[cadetEnv] ?? SEEDS[PRODUCTION_ENVIRONMENT_NAME]!;
|
|
26
|
-
|
|
27
22
|
return {
|
|
28
23
|
lockfilePath: resolveLockfilePath(),
|
|
29
24
|
configDir: resolveConfigDir(),
|
|
30
|
-
cloudUrl:
|
|
25
|
+
cloudUrl: getCloudBaseUrl(),
|
|
31
26
|
};
|
|
32
27
|
}
|
|
33
28
|
|
|
@@ -2,9 +2,7 @@ import { z } from "zod";
|
|
|
2
2
|
import type { IncomingHttpHeaders } from "node:http";
|
|
3
3
|
|
|
4
4
|
import { cloudAuthHeaders, readCloudToken } from "./cloud-auth";
|
|
5
|
-
import {
|
|
6
|
-
readBasetenPreviewToken,
|
|
7
|
-
} from "./guardian-token";
|
|
5
|
+
import { readBasetenPreviewToken } from "./guardian-token";
|
|
8
6
|
import { loopbackSafeFetch } from "./loopback-fetch";
|
|
9
7
|
import { getGatewayUrl, isCloudEntry } from "./lockfile-contract";
|
|
10
8
|
import type { LockfileAssistant } from "./lockfile-contract";
|
|
@@ -286,7 +284,7 @@ async function gatewayAuthHeaders(
|
|
|
286
284
|
const token = readCloudToken();
|
|
287
285
|
if (!token) return {};
|
|
288
286
|
try {
|
|
289
|
-
return await cloudAuthHeaders(token
|
|
287
|
+
return await cloudAuthHeaders(token);
|
|
290
288
|
} catch {
|
|
291
289
|
return {};
|
|
292
290
|
}
|
|
@@ -417,7 +415,7 @@ export async function fetchCloudPs(
|
|
|
417
415
|
|
|
418
416
|
let headers: Record<string, string>;
|
|
419
417
|
try {
|
|
420
|
-
headers = await cloudAuthHeaders(token
|
|
418
|
+
headers = await cloudAuthHeaders(token);
|
|
421
419
|
} catch {
|
|
422
420
|
return null;
|
|
423
421
|
}
|
|
@@ -22,11 +22,10 @@
|
|
|
22
22
|
* on disk; see `lockfile.ts`); the validated value carries only the modeled
|
|
23
23
|
* shape.
|
|
24
24
|
*/
|
|
25
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
25
26
|
import { TUNNEL_PROVIDERS } from "@mycadet/service-contracts/ingress";
|
|
26
|
-
import { SEEDS } from "@mycadet/environments";
|
|
27
27
|
import { z } from "zod";
|
|
28
28
|
|
|
29
|
-
import { resolveEnvironmentName } from "./environment";
|
|
30
29
|
import { readLockfile } from "./lockfile";
|
|
31
30
|
|
|
32
31
|
/**
|
|
@@ -151,27 +150,12 @@ export const GATEWAY_PORT = process.env.GATEWAY_PORT
|
|
|
151
150
|
? Number(process.env.GATEWAY_PORT)
|
|
152
151
|
: 7830;
|
|
153
152
|
|
|
154
|
-
/**
|
|
155
|
-
* The cloud URL stack: the lockfile's platform base url (what the active
|
|
156
|
-
* assistant was last hatched/waked against), else the `CADET_CLOUD_URL`
|
|
157
|
-
* override, else the resolved environment's cloud url.
|
|
158
|
-
*/
|
|
159
|
-
function getCloudUrl(): string {
|
|
160
|
-
const lockfileUrl = readLockfile().cloudBaseUrl;
|
|
161
|
-
return (
|
|
162
|
-
(typeof lockfileUrl === "string" && lockfileUrl.trim()) ||
|
|
163
|
-
process.env.CADET_CLOUD_URL?.trim() ||
|
|
164
|
-
SEEDS[resolveEnvironmentName()]?.cloudUrl ||
|
|
165
|
-
SEEDS.production!.cloudUrl
|
|
166
|
-
);
|
|
167
|
-
}
|
|
168
|
-
|
|
169
153
|
/**
|
|
170
154
|
* The URL to dial an entry's gateway on, derived from the entry's canonical
|
|
171
155
|
* fields — the one seam every consumer addresses a gateway through:
|
|
172
156
|
*
|
|
173
157
|
* - `custom` remotes: their recorded host and port.
|
|
174
|
-
* - cloud-managed: the
|
|
158
|
+
* - cloud-managed: the environment's base url (`getCloudBaseUrl()`).
|
|
175
159
|
* - loopback topologies (`local`, `docker`, `apple-container`): the
|
|
176
160
|
* recorded loopback gateway port, else the default gateway port.
|
|
177
161
|
*/
|
|
@@ -194,7 +178,7 @@ export function getGatewayUrl(entry: LockfileAssistant): string {
|
|
|
194
178
|
return `https://${entry.ipAddress}${elided ? "" : `:${entry.port}`}`;
|
|
195
179
|
}
|
|
196
180
|
if (isCloudEntry(entry)) {
|
|
197
|
-
return
|
|
181
|
+
return getCloudBaseUrl().replace(/\/+$/, "");
|
|
198
182
|
}
|
|
199
183
|
return `http://127.0.0.1:${entry.port}`;
|
|
200
184
|
}
|
|
@@ -283,8 +267,6 @@ const BaseAssistantSchema = z.object({
|
|
|
283
267
|
assistantId: z.string(),
|
|
284
268
|
/** Platform assistant UUID for this assistant's registration. */
|
|
285
269
|
cloudAssistantId: z.string().optional(),
|
|
286
|
-
/** Platform base URL this assistant was registered against. */
|
|
287
|
-
cloudBaseUrl: z.string().optional(),
|
|
288
270
|
/** Platform organization the entry belongs to. */
|
|
289
271
|
cloudOrganizationId: z.string().optional(),
|
|
290
272
|
name: z.string().optional(),
|
|
@@ -535,7 +517,7 @@ export const LockfileSchema = z.looseObject({
|
|
|
535
517
|
/**
|
|
536
518
|
* A validated, normalized lockfile — this schema's own output. Loose at the
|
|
537
519
|
* root so the CLI's read-modify-write round-trip preserves the root keys it
|
|
538
|
-
* owns
|
|
520
|
+
* owns and anything a newer writer added; readers key on the
|
|
539
521
|
* modeled fields.
|
|
540
522
|
*/
|
|
541
523
|
export type Lockfile = z.infer<typeof LockfileSchema>;
|
|
@@ -7,9 +7,9 @@
|
|
|
7
7
|
* fetch with the fixed timeout the non-streaming rows use.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import {
|
|
10
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
11
|
+
import { authHeadersForKnownOrganization, readCloudToken } from "../cloud-auth";
|
|
11
12
|
import type { LockfileAssistant } from "../lockfile-contract";
|
|
12
|
-
import { readCloudToken, resolveCloudUrl } from "../cloud-auth";
|
|
13
13
|
|
|
14
14
|
export const UPSTREAM_TIMEOUT_MS = 10_000;
|
|
15
15
|
|
|
@@ -42,5 +42,5 @@ export function operatorCloudHeaders(
|
|
|
42
42
|
|
|
43
43
|
/** The cloud root the proxies dial, without a trailing slash. */
|
|
44
44
|
export function cloudOrigin(): string {
|
|
45
|
-
return
|
|
45
|
+
return getCloudBaseUrl().replace(/\/+$/, "");
|
|
46
46
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import { readCloudToken
|
|
1
|
+
import { readCloudToken } from "../cloud-auth";
|
|
2
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
2
3
|
import { cliCommand } from "../environment";
|
|
3
4
|
import type { LockfileAssistant } from "../lockfile-contract";
|
|
4
5
|
import { execBasetenSandbox } from "../remotes/baseten/exec";
|
|
@@ -82,7 +83,7 @@ export async function execCommand(
|
|
|
82
83
|
const assistant = {
|
|
83
84
|
assistantId: entry.assistantId,
|
|
84
85
|
token,
|
|
85
|
-
cloudUrl:
|
|
86
|
+
cloudUrl: getCloudBaseUrl(),
|
|
86
87
|
};
|
|
87
88
|
const serviceParam =
|
|
88
89
|
opts.service === "assistant" ? undefined : opts.service;
|
|
@@ -12,13 +12,13 @@ import {
|
|
|
12
12
|
type ManagedBackupEntry,
|
|
13
13
|
} from "../../teleport-backup-policy";
|
|
14
14
|
|
|
15
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
15
16
|
import type { LockfileAssistant } from "../../lockfile-contract";
|
|
16
17
|
import { z } from "zod";
|
|
17
18
|
import {
|
|
18
19
|
cloudAuthHeaders,
|
|
19
20
|
invalidateOrgIdCache,
|
|
20
21
|
readCloudToken,
|
|
21
|
-
resolveCloudUrl,
|
|
22
22
|
} from "../../cloud-auth";
|
|
23
23
|
import { loopbackSafeFetch } from "../../loopback-fetch";
|
|
24
24
|
import { cliCommand } from "../../environment";
|
|
@@ -39,7 +39,7 @@ const CreatedBackupResponseSchema = z.object({
|
|
|
39
39
|
});
|
|
40
40
|
|
|
41
41
|
function cloudBackupsUrl(entry: LockfileAssistant): string {
|
|
42
|
-
return `${
|
|
42
|
+
return `${getCloudBaseUrl()}/v1/assistants/${entry.assistantId}/backups/`;
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
async function errorSuffix(response: Response): Promise<string> {
|
|
@@ -61,13 +61,13 @@ async function cloudBackupRequest(
|
|
|
61
61
|
loopbackSafeFetch(cloudBackupsUrl(entry), {
|
|
62
62
|
method,
|
|
63
63
|
headers: {
|
|
64
|
-
...(await cloudAuthHeaders(token
|
|
64
|
+
...(await cloudAuthHeaders(token)),
|
|
65
65
|
Accept: "application/json",
|
|
66
66
|
},
|
|
67
67
|
});
|
|
68
68
|
let response = await doRequest();
|
|
69
69
|
if (response.status === 401) {
|
|
70
|
-
invalidateOrgIdCache(token
|
|
70
|
+
invalidateOrgIdCache(token);
|
|
71
71
|
response = await doRequest();
|
|
72
72
|
}
|
|
73
73
|
return response;
|
|
@@ -47,7 +47,6 @@ export async function interactiveSession(
|
|
|
47
47
|
assistant.assistantId,
|
|
48
48
|
cols,
|
|
49
49
|
rows,
|
|
50
|
-
assistant.cloudUrl,
|
|
51
50
|
service,
|
|
52
51
|
);
|
|
53
52
|
|
|
@@ -83,7 +82,6 @@ export async function interactiveSession(
|
|
|
83
82
|
assistant.token,
|
|
84
83
|
assistant.assistantId,
|
|
85
84
|
sessionId,
|
|
86
|
-
assistant.cloudUrl,
|
|
87
85
|
);
|
|
88
86
|
} catch {
|
|
89
87
|
// Best-effort cleanup
|
|
@@ -110,7 +108,6 @@ export async function interactiveSession(
|
|
|
110
108
|
sessionId,
|
|
111
109
|
newCols,
|
|
112
110
|
newRows,
|
|
113
|
-
assistant.cloudUrl,
|
|
114
111
|
).catch(() => {
|
|
115
112
|
// Resize failures are non-fatal
|
|
116
113
|
});
|
|
@@ -131,7 +128,6 @@ export async function interactiveSession(
|
|
|
131
128
|
assistant.assistantId,
|
|
132
129
|
sessionId,
|
|
133
130
|
data,
|
|
134
|
-
assistant.cloudUrl,
|
|
135
131
|
).catch((err) => {
|
|
136
132
|
if (!exiting) {
|
|
137
133
|
console.error(`\r\nInput error: ${err.message}\r\n`);
|
|
@@ -155,7 +151,6 @@ export async function interactiveSession(
|
|
|
155
151
|
assistant.assistantId,
|
|
156
152
|
sessionId,
|
|
157
153
|
initialCommand + "\r",
|
|
158
|
-
assistant.cloudUrl,
|
|
159
154
|
);
|
|
160
155
|
}
|
|
161
156
|
|
|
@@ -165,7 +160,6 @@ export async function interactiveSession(
|
|
|
165
160
|
assistant.token,
|
|
166
161
|
assistant.assistantId,
|
|
167
162
|
sessionId,
|
|
168
|
-
assistant.cloudUrl,
|
|
169
163
|
abortController.signal,
|
|
170
164
|
)) {
|
|
171
165
|
if (exiting) break;
|
|
@@ -259,7 +253,6 @@ export async function execViaTerminalSession(
|
|
|
259
253
|
assistant.assistantId,
|
|
260
254
|
120,
|
|
261
255
|
24,
|
|
262
|
-
assistant.cloudUrl,
|
|
263
256
|
options?.service,
|
|
264
257
|
);
|
|
265
258
|
|
|
@@ -292,7 +285,6 @@ export async function execViaTerminalSession(
|
|
|
292
285
|
assistant.token,
|
|
293
286
|
assistant.assistantId,
|
|
294
287
|
sessionId,
|
|
295
|
-
assistant.cloudUrl,
|
|
296
288
|
abortController.signal,
|
|
297
289
|
)) {
|
|
298
290
|
eventCount++;
|
|
@@ -328,7 +320,6 @@ export async function execViaTerminalSession(
|
|
|
328
320
|
assistant.assistantId,
|
|
329
321
|
sessionId,
|
|
330
322
|
fullCmd,
|
|
331
|
-
assistant.cloudUrl,
|
|
332
323
|
);
|
|
333
324
|
}
|
|
334
325
|
}
|
|
@@ -362,7 +353,6 @@ export async function execViaTerminalSession(
|
|
|
362
353
|
assistant.token,
|
|
363
354
|
assistant.assistantId,
|
|
364
355
|
sessionId,
|
|
365
|
-
assistant.cloudUrl,
|
|
366
356
|
).catch(() => {});
|
|
367
357
|
}
|
|
368
358
|
|
|
@@ -6,11 +6,8 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import { z } from "zod";
|
|
9
|
-
import {
|
|
10
|
-
|
|
11
|
-
readCloudToken,
|
|
12
|
-
resolveCloudUrl,
|
|
13
|
-
} from "../../cloud-auth";
|
|
9
|
+
import { cloudAuthHeaders, readCloudToken } from "../../cloud-auth";
|
|
10
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
14
11
|
import { loopbackSafeFetch } from "../../loopback-fetch";
|
|
15
12
|
import { saveLockfileAssistant } from "../../lockfile";
|
|
16
13
|
import type { LockfileAssistant } from "../../lockfile-contract";
|
|
@@ -47,13 +44,13 @@ export async function hatchCloud(): Promise<HatchCloudResult> {
|
|
|
47
44
|
error: "Not logged in. Run `cadet login --token <token>` first.",
|
|
48
45
|
};
|
|
49
46
|
}
|
|
50
|
-
const cloudUrl =
|
|
47
|
+
const cloudUrl = getCloudBaseUrl();
|
|
51
48
|
const url = `${cloudUrl}/v1/assistants/hatch/`;
|
|
52
49
|
|
|
53
50
|
try {
|
|
54
51
|
const response = await loopbackSafeFetch(url, {
|
|
55
52
|
method: "POST",
|
|
56
|
-
headers: await cloudAuthHeaders(token
|
|
53
|
+
headers: await cloudAuthHeaders(token),
|
|
57
54
|
body: JSON.stringify({}),
|
|
58
55
|
signal: AbortSignal.timeout(300_000),
|
|
59
56
|
});
|
|
@@ -102,7 +99,7 @@ export async function hatchCloud(): Promise<HatchCloudResult> {
|
|
|
102
99
|
status: response.status,
|
|
103
100
|
error:
|
|
104
101
|
errorBody.detail ??
|
|
105
|
-
`
|
|
102
|
+
`Cloud API error: ${response.status} ${response.statusText}`,
|
|
106
103
|
};
|
|
107
104
|
} catch (error) {
|
|
108
105
|
return {
|
|
@@ -8,11 +8,8 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { z } from "zod";
|
|
11
|
-
import {
|
|
12
|
-
|
|
13
|
-
invalidateOrgIdCache,
|
|
14
|
-
resolveCloudUrl,
|
|
15
|
-
} from "../../cloud-auth";
|
|
11
|
+
import { cloudAuthHeaders, invalidateOrgIdCache } from "../../cloud-auth";
|
|
12
|
+
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
16
13
|
import { loopbackSafeFetch } from "../../loopback-fetch";
|
|
17
14
|
|
|
18
15
|
const PassthroughBodySchema = z.record(z.string(), z.unknown()).catch({});
|
|
@@ -75,14 +72,13 @@ export async function cloudUploadToSignedUrl(
|
|
|
75
72
|
export async function cloudImportPreflightFromGcs(
|
|
76
73
|
bundleKey: string,
|
|
77
74
|
token: string,
|
|
78
|
-
cloudUrl?: string,
|
|
79
75
|
): Promise<{ statusCode: number; body: Record<string, unknown> }> {
|
|
80
|
-
const resolvedUrl =
|
|
76
|
+
const resolvedUrl = getCloudBaseUrl();
|
|
81
77
|
const response = await loopbackSafeFetch(
|
|
82
78
|
`${resolvedUrl}/v1/migrations/import-preflight-from-gcs/`,
|
|
83
79
|
{
|
|
84
80
|
method: "POST",
|
|
85
|
-
headers: await cloudAuthHeaders(token
|
|
81
|
+
headers: await cloudAuthHeaders(token),
|
|
86
82
|
signal: AbortSignal.timeout(30 * 60_000),
|
|
87
83
|
body: JSON.stringify({ bundle_key: bundleKey }),
|
|
88
84
|
},
|
|
@@ -97,14 +93,13 @@ export async function cloudImportPreflightFromGcs(
|
|
|
97
93
|
export async function cloudImportBundleFromGcs(
|
|
98
94
|
bundleKey: string,
|
|
99
95
|
token: string,
|
|
100
|
-
cloudUrl?: string,
|
|
101
96
|
): Promise<{ statusCode: number; body: Record<string, unknown> }> {
|
|
102
|
-
const resolvedUrl =
|
|
97
|
+
const resolvedUrl = getCloudBaseUrl();
|
|
103
98
|
const response = await loopbackSafeFetch(
|
|
104
99
|
`${resolvedUrl}/v1/migrations/import-from-gcs/`,
|
|
105
100
|
{
|
|
106
101
|
method: "POST",
|
|
107
|
-
headers: await cloudAuthHeaders(token
|
|
102
|
+
headers: await cloudAuthHeaders(token),
|
|
108
103
|
body: JSON.stringify({ bundle_key: bundleKey }),
|
|
109
104
|
signal: AbortSignal.timeout(30 * 60_000),
|
|
110
105
|
},
|
|
@@ -257,14 +252,13 @@ export async function cloudRequestSignedUrl(
|
|
|
257
252
|
consumer?: "client" | "runtime";
|
|
258
253
|
},
|
|
259
254
|
token: string,
|
|
260
|
-
cloudUrl?: string,
|
|
261
255
|
): Promise<{
|
|
262
256
|
url: string;
|
|
263
257
|
bundleKey: string;
|
|
264
258
|
expiresAt: string;
|
|
265
259
|
maxContentLength?: number;
|
|
266
260
|
}> {
|
|
267
|
-
const resolvedUrl =
|
|
261
|
+
const resolvedUrl = getCloudBaseUrl();
|
|
268
262
|
const body: Record<string, unknown> = { operation: params.operation };
|
|
269
263
|
if (params.bundleKey !== undefined) body.bundle_key = params.bundleKey;
|
|
270
264
|
if (params.contentType !== undefined) body.content_type = params.contentType;
|
|
@@ -289,7 +283,7 @@ export async function cloudRequestSignedUrl(
|
|
|
289
283
|
const doRequest = async (): Promise<Response> =>
|
|
290
284
|
loopbackSafeFetch(`${resolvedUrl}/v1/migrations/signed-url/`, {
|
|
291
285
|
method: "POST",
|
|
292
|
-
headers: await cloudAuthHeaders(token
|
|
286
|
+
headers: await cloudAuthHeaders(token),
|
|
293
287
|
body: JSON.stringify(body),
|
|
294
288
|
});
|
|
295
289
|
|
|
@@ -300,7 +294,7 @@ export async function cloudRequestSignedUrl(
|
|
|
300
294
|
// lookup. For session-token callers, a 401 frequently means the
|
|
301
295
|
// cached org ID is stale — calling doRequest() again without clearing
|
|
302
296
|
// the cache would just send the same stale header and fail again.
|
|
303
|
-
invalidateOrgIdCache(token
|
|
297
|
+
invalidateOrgIdCache(token);
|
|
304
298
|
response = await doRequest();
|
|
305
299
|
}
|
|
306
300
|
|
|
@@ -346,13 +340,12 @@ export async function cloudRequestSignedUrl(
|
|
|
346
340
|
export async function cloudPollJobStatus(
|
|
347
341
|
jobId: string,
|
|
348
342
|
token: string,
|
|
349
|
-
cloudUrl?: string,
|
|
350
343
|
): Promise<UnifiedJobStatus> {
|
|
351
|
-
const resolvedUrl =
|
|
344
|
+
const resolvedUrl = getCloudBaseUrl();
|
|
352
345
|
const response = await loopbackSafeFetch(
|
|
353
346
|
`${resolvedUrl}/v1/migrations/jobs/${jobId}/`,
|
|
354
347
|
{
|
|
355
|
-
headers: await cloudAuthHeaders(token
|
|
348
|
+
headers: await cloudAuthHeaders(token),
|
|
356
349
|
},
|
|
357
350
|
);
|
|
358
351
|
|
|
@@ -179,7 +179,6 @@ export async function restoreCloud(
|
|
|
179
179
|
contentLength: bundleData.length,
|
|
180
180
|
},
|
|
181
181
|
token,
|
|
182
|
-
gatewayUrl,
|
|
183
182
|
);
|
|
184
183
|
bundleKey = key;
|
|
185
184
|
await cloudUploadToSignedUrl(url, new Uint8Array(bundleData));
|
|
@@ -198,11 +197,7 @@ export async function restoreCloud(
|
|
|
198
197
|
body: Record<string, unknown>;
|
|
199
198
|
};
|
|
200
199
|
try {
|
|
201
|
-
preflightResult = await cloudImportPreflightFromGcs(
|
|
202
|
-
bundleKey,
|
|
203
|
-
token,
|
|
204
|
-
gatewayUrl,
|
|
205
|
-
);
|
|
200
|
+
preflightResult = await cloudImportPreflightFromGcs(bundleKey, token);
|
|
206
201
|
} catch (err) {
|
|
207
202
|
if (isTimeout(err)) {
|
|
208
203
|
return {
|
|
@@ -261,7 +256,7 @@ export async function restoreCloud(
|
|
|
261
256
|
// Data import — may be async (202 + job id), in which case poll.
|
|
262
257
|
let importResult: { statusCode: number; body: Record<string, unknown> };
|
|
263
258
|
try {
|
|
264
|
-
importResult = await cloudImportBundleFromGcs(bundleKey, token
|
|
259
|
+
importResult = await cloudImportBundleFromGcs(bundleKey, token);
|
|
265
260
|
} catch (err) {
|
|
266
261
|
if (isTimeout(err)) {
|
|
267
262
|
return {
|
|
@@ -305,7 +300,7 @@ export async function restoreCloud(
|
|
|
305
300
|
|
|
306
301
|
let status: Awaited<ReturnType<typeof cloudPollJobStatus>>;
|
|
307
302
|
try {
|
|
308
|
-
status = await cloudPollJobStatus(jobId, token
|
|
303
|
+
status = await cloudPollJobStatus(jobId, token);
|
|
309
304
|
} catch (err) {
|
|
310
305
|
const msg = err instanceof Error ? err.message : String(err);
|
|
311
306
|
// Terminal: missing job, auth failures, any 4xx. Transient
|