@mycadet/cli 0.13.0-dev.202611162029.012a930 → 0.13.0-dev.202611171301.b3e2e5c
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/assistant-api/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +7 -0
- 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/service-contracts/src/remote-web-pairing.ts +7 -0
- 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/guardian-token.ts +1 -1
- package/node_modules/@mycadet/local-mode/src/remotes/baseten/hatch.ts +0 -7
- package/node_modules/@mycadet/local-mode/src/remotes/docker/hatch.ts +2 -2
- package/node_modules/@mycadet/local-mode/src/remotes/local/hatch.ts +2 -2
- package/node_modules/@mycadet/service-contracts/package.json +1 -1
- package/node_modules/@mycadet/service-contracts/src/remote-web-pairing.ts +7 -0
- package/node_modules/@mycadet/shared/package.json +1 -1
- package/package.json +2 -2
- package/src/__tests__/client-token.test.ts +27 -31
- package/src/commands/client.ts +18 -86
- package/src/commands/confirm.ts +5 -1
- package/src/commands/devices.ts +2 -2
- package/src/commands/hatch.ts +3 -3
- package/src/commands/machine.ts +2 -1
- package/src/commands/message.ts +5 -4
- package/src/commands/pair.ts +4 -3
- package/src/commands/ps.ts +2 -9
- package/src/commands/setup.ts +1 -7
- package/src/commands/tunnel.ts +3 -2
- package/src/commands/upgrade.ts +4 -2
- package/src/components/DefaultMainScreen.tsx +20 -15
- package/src/index.ts +5 -1
- package/src/lib/cli-error.ts +25 -15
- package/src/lib/cloud-login.ts +1 -2
- package/src/lib/constants.ts +5 -0
- package/src/lib/live-voice/protocol.ts +3 -1
- package/src/lib/live-voice/tunnel.ts +9 -8
- package/src/lib/pair.ts +9 -2
- package/src/lib/tunnel.ts +5 -0
- package/src/lib/tunnels/tailscale.ts +12 -6
|
@@ -83,6 +83,13 @@ export interface RemoteWebPairingVerificationRequest {
|
|
|
83
83
|
* The gateway maps the `expired` / `invalid` outcomes to error responses, so
|
|
84
84
|
* the only success shape on the wire is the approved variant.
|
|
85
85
|
*/
|
|
86
|
+
export const RemoteWebPairingVerificationResponseSchema = z.object({
|
|
87
|
+
status: z.literal("approved"),
|
|
88
|
+
verificationUri: z.string(),
|
|
89
|
+
/** ISO-8601 instant the approved challenge expires. */
|
|
90
|
+
expiresAt: z.string(),
|
|
91
|
+
}) satisfies z.ZodType<RemoteWebPairingVerificationResponse>;
|
|
92
|
+
|
|
86
93
|
export interface RemoteWebPairingVerificationResponse {
|
|
87
94
|
status: "approved";
|
|
88
95
|
verificationUri: string;
|
|
@@ -83,6 +83,13 @@ export interface RemoteWebPairingVerificationRequest {
|
|
|
83
83
|
* The gateway maps the `expired` / `invalid` outcomes to error responses, so
|
|
84
84
|
* the only success shape on the wire is the approved variant.
|
|
85
85
|
*/
|
|
86
|
+
export const RemoteWebPairingVerificationResponseSchema = z.object({
|
|
87
|
+
status: z.literal("approved"),
|
|
88
|
+
verificationUri: z.string(),
|
|
89
|
+
/** ISO-8601 instant the approved challenge expires. */
|
|
90
|
+
expiresAt: z.string(),
|
|
91
|
+
}) satisfies z.ZodType<RemoteWebPairingVerificationResponse>;
|
|
92
|
+
|
|
86
93
|
export interface RemoteWebPairingVerificationResponse {
|
|
87
94
|
status: "approved";
|
|
88
95
|
verificationUri: string;
|
|
@@ -353,7 +353,7 @@ export function guardianTokenDueForRenewal(token: GuardianTokenData): boolean {
|
|
|
353
353
|
* host-scoped, so a remote gateway's origin (baseten's preview URL) can
|
|
354
354
|
* never see this jar.
|
|
355
355
|
*/
|
|
356
|
-
export function
|
|
356
|
+
export function getGuardianTokenAsCookies(token: GuardianTokenData): string[] {
|
|
357
357
|
return [
|
|
358
358
|
`cadet_web_access=${encodeURIComponent(token.accessToken)}; HttpOnly; Path=/; SameSite=Strict`,
|
|
359
359
|
`cadet_web_refresh=${encodeURIComponent(token.refreshToken)}; HttpOnly; Path=/; SameSite=Strict`,
|
|
@@ -232,13 +232,6 @@ export async function hatchBaseten(
|
|
|
232
232
|
log(
|
|
233
233
|
` Exec into it: baseten sandbox exec --name ${sandboxName} -- 'cadet ps'`,
|
|
234
234
|
);
|
|
235
|
-
// cookies stay empty on purpose: a Set-Cookie on the hatch response
|
|
236
|
-
// lands in the hatch host's jar, and a cookie is host-scoped — the
|
|
237
|
-
// baseten gateway answers on its preview origin, which this jar can
|
|
238
|
-
// never reach. The browser earns its baseten cookie with one
|
|
239
|
-
// authenticated open on the preview edge instead. The local and
|
|
240
|
-
// docker legs feed the jar because their gateways answer on the same
|
|
241
|
-
// loopback host as the hatch response.
|
|
242
235
|
return { ok: true, assistant: entry, ready: false, cookies: [] };
|
|
243
236
|
}
|
|
244
237
|
log(
|
|
@@ -27,7 +27,7 @@ import {
|
|
|
27
27
|
} from "../../ports";
|
|
28
28
|
import {
|
|
29
29
|
leaseGuardianToken,
|
|
30
|
-
|
|
30
|
+
getGuardianTokenAsCookies,
|
|
31
31
|
type GuardianTokenData,
|
|
32
32
|
} from "../../guardian-token";
|
|
33
33
|
import type { HatchAssistantResult } from "../../operations/types";
|
|
@@ -967,7 +967,7 @@ export async function hatchDocker(
|
|
|
967
967
|
// The lease's fresh pair IS the webview's jar, same as the local leg:
|
|
968
968
|
// the docker gateway answers on the same host as this response
|
|
969
969
|
// (loopback port map), so the host-scoped jar applies.
|
|
970
|
-
cookies: guardianToken ?
|
|
970
|
+
cookies: guardianToken ? getGuardianTokenAsCookies(guardianToken) : [],
|
|
971
971
|
};
|
|
972
972
|
} catch (error) {
|
|
973
973
|
return {
|
|
@@ -21,7 +21,7 @@ import { findAvailablePort, getDefaultPorts } from "../../ports";
|
|
|
21
21
|
import {
|
|
22
22
|
GuardianLeasePermanentError,
|
|
23
23
|
leaseGuardianToken,
|
|
24
|
-
|
|
24
|
+
getGuardianTokenAsCookies,
|
|
25
25
|
} from "../../guardian-token";
|
|
26
26
|
import { configureHatchProviderApiKey } from "../../provider-credentials";
|
|
27
27
|
import { readCloudToken } from "../../cloud-auth";
|
|
@@ -195,7 +195,7 @@ export async function hatchLocal(params: {
|
|
|
195
195
|
// hatch response so the page's requests authenticate through the
|
|
196
196
|
// gateway's own middleware. Same host as this response (loopback), so
|
|
197
197
|
// the host-scoped jar applies.
|
|
198
|
-
cookies.push(...
|
|
198
|
+
cookies.push(...getGuardianTokenAsCookies(tokenData));
|
|
199
199
|
break;
|
|
200
200
|
} catch (err) {
|
|
201
201
|
if (
|
|
@@ -83,6 +83,13 @@ export interface RemoteWebPairingVerificationRequest {
|
|
|
83
83
|
* The gateway maps the `expired` / `invalid` outcomes to error responses, so
|
|
84
84
|
* the only success shape on the wire is the approved variant.
|
|
85
85
|
*/
|
|
86
|
+
export const RemoteWebPairingVerificationResponseSchema = z.object({
|
|
87
|
+
status: z.literal("approved"),
|
|
88
|
+
verificationUri: z.string(),
|
|
89
|
+
/** ISO-8601 instant the approved challenge expires. */
|
|
90
|
+
expiresAt: z.string(),
|
|
91
|
+
}) satisfies z.ZodType<RemoteWebPairingVerificationResponse>;
|
|
92
|
+
|
|
86
93
|
export interface RemoteWebPairingVerificationResponse {
|
|
87
94
|
status: "approved";
|
|
88
95
|
verificationUri: string;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mycadet/cli",
|
|
3
|
-
"version": "0.13.0-dev.
|
|
3
|
+
"version": "0.13.0-dev.202611171301.b3e2e5c",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "git+https://github.com/vargasjr-dev/mycadet-temp.git"
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"scripts": {
|
|
18
18
|
"format": "prettier --write .",
|
|
19
19
|
"format:check": "prettier --check .",
|
|
20
|
-
"lint": "eslint --max-warnings
|
|
20
|
+
"lint": "eslint --max-warnings 111",
|
|
21
21
|
"lint:unused": "knip --include files,dependencies,unlisted",
|
|
22
22
|
"compile:check": "bun build --compile src/index.ts --outfile /dev/null",
|
|
23
23
|
"test": "bun run scripts/run-tests.ts",
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Tests for `cadet client
|
|
3
|
-
*
|
|
2
|
+
* Tests for `cadet client`'s arg parsing: the assistant comes from the
|
|
3
|
+
* positional name or the active assistant — there is no --url/--token escape
|
|
4
|
+
* hatch. What remains overridable is the assistant id segment.
|
|
4
5
|
*/
|
|
5
6
|
import {
|
|
6
7
|
afterAll,
|
|
@@ -17,24 +18,28 @@ import { join } from "node:path";
|
|
|
17
18
|
// NB: do NOT mock.module("../lib/guardian-token.js") here — that mock is
|
|
18
19
|
// process-global in Bun and leaks into other test files (it dropped the
|
|
19
20
|
// module's other exports and broke guardian-token-paths / setup suites in CI).
|
|
20
|
-
// The "--token skips the credential lookup" behavior is enforced structurally
|
|
21
|
-
// in parseArgs (the lookup is gated on the override) and reviewed there.
|
|
22
21
|
|
|
23
|
-
// An EMPTY temp dir so there is no lockfile entry — the ephemeral path must
|
|
24
|
-
// work without one. Env mutation is scoped to each test and restored after, so
|
|
25
|
-
// it can't leak into other test files in the same Bun run.
|
|
26
22
|
const testDir = mkdtempSync(join(tmpdir(), "client-token-test-"));
|
|
27
23
|
const ORIGINAL_XDG_CONFIG_HOME = process.env.XDG_CONFIG_HOME;
|
|
28
24
|
const ORIGINAL_ARGV = [...process.argv];
|
|
29
25
|
|
|
30
26
|
import { parseArgs } from "../commands/client.js";
|
|
27
|
+
import { saveLockfileAssistant } from "@mycadet/local-mode";
|
|
31
28
|
|
|
32
|
-
// A clearly non-local
|
|
33
|
-
|
|
29
|
+
// A clearly non-local recorded host so getGatewayUrl yields a remote URL
|
|
30
|
+
// and the test pins that the runtime URL comes from the ENTRY, not flags.
|
|
31
|
+
const ENTRY = {
|
|
32
|
+
assistantId: "remote-xyz",
|
|
33
|
+
name: "Remote Pal",
|
|
34
|
+
cloud: "custom" as const,
|
|
35
|
+
ipAddress: "192.0.2.50",
|
|
36
|
+
port: 7830,
|
|
37
|
+
};
|
|
34
38
|
|
|
35
|
-
describe("client
|
|
39
|
+
describe("client arg parsing", () => {
|
|
36
40
|
beforeEach(() => {
|
|
37
41
|
process.env.XDG_CONFIG_HOME = testDir;
|
|
42
|
+
saveLockfileAssistant(ENTRY);
|
|
38
43
|
});
|
|
39
44
|
|
|
40
45
|
afterEach(() => {
|
|
@@ -50,38 +55,29 @@ describe("client --token (ephemeral)", () => {
|
|
|
50
55
|
rmSync(testDir, { recursive: true, force: true });
|
|
51
56
|
});
|
|
52
57
|
|
|
53
|
-
test("
|
|
54
|
-
process.argv = [
|
|
55
|
-
"bun",
|
|
56
|
-
"cadet",
|
|
57
|
-
"client",
|
|
58
|
-
"--url",
|
|
59
|
-
REMOTE_URL,
|
|
60
|
-
"--token",
|
|
61
|
-
"test-jwt-token",
|
|
62
|
-
];
|
|
58
|
+
test("the runtime URL and bearer come from the entry's persisted state", () => {
|
|
59
|
+
process.argv = ["bun", "cadet", "client", "Remote Pal"];
|
|
63
60
|
const parsed = parseArgs();
|
|
64
61
|
|
|
65
|
-
expect(parsed.runtimeUrl).toBe(
|
|
66
|
-
expect(parsed.assistantId).toBe("
|
|
67
|
-
expect(parsed.
|
|
62
|
+
expect(parsed.runtimeUrl).toBe("https://192.0.2.50:7830");
|
|
63
|
+
expect(parsed.assistantId).toBe("remote-xyz");
|
|
64
|
+
expect(parsed.assistantName).toBe("Remote Pal");
|
|
65
|
+
// No stored guardian token was seeded, so no bearer is invented.
|
|
66
|
+
expect(parsed.bearerToken).toBeUndefined();
|
|
68
67
|
expect(parsed.cloudToken).toBeUndefined();
|
|
69
68
|
});
|
|
70
69
|
|
|
71
|
-
test("--assistant-id overrides the
|
|
70
|
+
test("--assistant-id overrides the entry's id segment", () => {
|
|
72
71
|
process.argv = [
|
|
73
72
|
"bun",
|
|
74
73
|
"cadet",
|
|
75
74
|
"client",
|
|
76
|
-
"
|
|
77
|
-
REMOTE_URL,
|
|
78
|
-
"--token",
|
|
79
|
-
"tok",
|
|
75
|
+
"Remote Pal",
|
|
80
76
|
"--assistant-id",
|
|
81
|
-
"remote-
|
|
77
|
+
"remote-abc",
|
|
82
78
|
];
|
|
83
79
|
const parsed = parseArgs();
|
|
84
|
-
expect(parsed.assistantId).toBe("remote-
|
|
85
|
-
expect(parsed.
|
|
80
|
+
expect(parsed.assistantId).toBe("remote-abc");
|
|
81
|
+
expect(parsed.assistantName).toBeUndefined();
|
|
86
82
|
});
|
|
87
83
|
});
|
package/src/commands/client.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { type LockfileAssistant } from "@mycadet/local-mode/contract";
|
|
2
2
|
import {
|
|
3
3
|
findAssistantByName,
|
|
4
|
-
resolveAssistant,
|
|
5
4
|
resolveConversationKey,
|
|
6
5
|
} from "../lib/assistant-config";
|
|
7
6
|
import {
|
|
@@ -15,7 +14,6 @@ import {
|
|
|
15
14
|
readCloudToken,
|
|
16
15
|
saveLockfileAssistant,
|
|
17
16
|
} from "@mycadet/local-mode";
|
|
18
|
-
import { DAEMON_INTERNAL_ASSISTANT_ID, GATEWAY_PORT } from "../lib/constants";
|
|
19
17
|
|
|
20
18
|
import { normalizeRuntimeUrl } from "../lib/runtime-url";
|
|
21
19
|
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
@@ -50,12 +48,8 @@ export function parseArgs(): ParsedArgs {
|
|
|
50
48
|
const args = process.argv.slice(3);
|
|
51
49
|
|
|
52
50
|
const positionalName = parseAssistantTargetArg(args, [
|
|
53
|
-
"--url",
|
|
54
|
-
"-u",
|
|
55
51
|
"--assistant-id",
|
|
56
52
|
"-a",
|
|
57
|
-
"--token",
|
|
58
|
-
"-t",
|
|
59
53
|
]);
|
|
60
54
|
const flagArgs: string[] = [];
|
|
61
55
|
for (let i = 0; i < args.length; i++) {
|
|
@@ -63,21 +57,12 @@ export function parseArgs(): ParsedArgs {
|
|
|
63
57
|
if (arg === "--help" || arg === "-h") {
|
|
64
58
|
printUsage();
|
|
65
59
|
process.exit(0);
|
|
66
|
-
} else if (
|
|
67
|
-
(arg === "--url" ||
|
|
68
|
-
arg === "-u" ||
|
|
69
|
-
arg === "--assistant-id" ||
|
|
70
|
-
arg === "-a" ||
|
|
71
|
-
arg === "--token" ||
|
|
72
|
-
arg === "-t") &&
|
|
73
|
-
args[i + 1]
|
|
74
|
-
) {
|
|
60
|
+
} else if ((arg === "--assistant-id" || arg === "-a") && args[i + 1]) {
|
|
75
61
|
flagArgs.push(arg, args[++i]);
|
|
76
62
|
}
|
|
77
63
|
}
|
|
78
64
|
|
|
79
65
|
let entry: LockfileAssistant | null = null;
|
|
80
|
-
const hasExplicitUrl = flagArgs.includes("--url") || flagArgs.includes("-u");
|
|
81
66
|
if (positionalName) {
|
|
82
67
|
const result = lookupAssistantByIdentifier(positionalName);
|
|
83
68
|
if (result.status !== "found") {
|
|
@@ -92,76 +77,44 @@ export function parseArgs(): ParsedArgs {
|
|
|
92
77
|
if (result.status === "found") {
|
|
93
78
|
entry = result.entry;
|
|
94
79
|
}
|
|
95
|
-
if (!entry
|
|
80
|
+
if (!entry) {
|
|
96
81
|
console.error(
|
|
97
82
|
`Active assistant '${active}' not found in lockfile. Set an active assistant with 'cadet use <name-or-id>'.`,
|
|
98
83
|
);
|
|
99
84
|
process.exit(1);
|
|
100
85
|
}
|
|
101
86
|
}
|
|
102
|
-
if (!entry
|
|
103
|
-
// URL provided but active assistant missing or unset — resolve for remaining defaults
|
|
104
|
-
entry = resolveAssistant();
|
|
105
|
-
} else if (!entry) {
|
|
87
|
+
if (!entry) {
|
|
106
88
|
console.error(
|
|
107
89
|
"No active assistant set. Set one with 'cadet use <name-or-id>' or specify one: 'cadet client <name-or-id>'.",
|
|
108
90
|
);
|
|
109
91
|
process.exit(1);
|
|
110
92
|
}
|
|
111
93
|
}
|
|
112
|
-
|
|
113
|
-
if (!entry && !hasExplicitUrl) {
|
|
94
|
+
if (!entry) {
|
|
114
95
|
console.error("No assistant found. Hatch one first with 'cadet hatch'.");
|
|
115
96
|
process.exit(1);
|
|
116
97
|
}
|
|
117
98
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
? getGatewayUrl(entry)
|
|
123
|
-
: `http://127.0.0.1:${GATEWAY_PORT}`;
|
|
124
|
-
let assistantId = entry?.assistantId ?? DAEMON_INTERNAL_ASSISTANT_ID;
|
|
125
|
-
let assistantName = entry ? getAssistantDisplayName(entry) : undefined;
|
|
126
|
-
const cloud = entry?.cloud;
|
|
127
|
-
|
|
128
|
-
// Ephemeral auth: a handed-over token (e.g. from `cadet pair`) used for this
|
|
129
|
-
// session only. Resolve it BEFORE the credential lookup below so an ephemeral
|
|
130
|
-
// session never reads (or writes) the local token store.
|
|
131
|
-
let bearerTokenOverride: string | undefined;
|
|
132
|
-
for (let i = 0; i < flagArgs.length; i++) {
|
|
133
|
-
if (
|
|
134
|
-
(flagArgs[i] === "--token" || flagArgs[i] === "-t") &&
|
|
135
|
-
flagArgs[i + 1]
|
|
136
|
-
) {
|
|
137
|
-
bearerTokenOverride = flagArgs[i + 1];
|
|
138
|
-
}
|
|
139
|
-
}
|
|
99
|
+
const runtimeUrl = getGatewayUrl(entry);
|
|
100
|
+
let assistantId = entry.assistantId;
|
|
101
|
+
let assistantName: string | undefined = getAssistantDisplayName(entry);
|
|
102
|
+
const cloud = entry.cloud;
|
|
140
103
|
|
|
141
104
|
// Platform-hosted assistants (cloud "cadet") use a session token; every
|
|
142
|
-
// other topology — local, docker, and "paired"
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
|
|
147
|
-
: cloud === "cloud"
|
|
148
|
-
? (readCloudToken() ?? undefined)
|
|
149
|
-
: undefined;
|
|
150
|
-
const bearerToken = bearerTokenOverride
|
|
151
|
-
? bearerTokenOverride
|
|
152
|
-
: cloud === "cloud"
|
|
105
|
+
// other topology — local, docker, and "paired" — uses a bearer guardian JWT.
|
|
106
|
+
const cloudToken =
|
|
107
|
+
cloud === "cloud" ? (readCloudToken() ?? undefined) : undefined;
|
|
108
|
+
const bearerToken =
|
|
109
|
+
cloud === "cloud"
|
|
153
110
|
? undefined
|
|
154
|
-
: (loadGuardianToken(entry
|
|
111
|
+
: (loadGuardianToken(entry.assistantId)?.accessToken ?? undefined);
|
|
155
112
|
|
|
156
113
|
for (let i = 0; i < flagArgs.length; i++) {
|
|
157
114
|
const flag = flagArgs[i];
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
(flag === "--assistant-id" || flag === "-a") &&
|
|
162
|
-
flagArgs[i + 1]
|
|
163
|
-
) {
|
|
164
|
-
assistantId = flagArgs[++i];
|
|
115
|
+
const value = flagArgs[i + 1];
|
|
116
|
+
if ((flag === "--assistant-id" || flag === "-a") && value) {
|
|
117
|
+
assistantId = value;
|
|
165
118
|
assistantName = undefined;
|
|
166
119
|
}
|
|
167
120
|
}
|
|
@@ -186,24 +139,12 @@ ${ANSI.bold}ARGUMENTS:${ANSI.reset}
|
|
|
186
139
|
[name-or-id] Assistant display name or ID (default: active)
|
|
187
140
|
|
|
188
141
|
${ANSI.bold}OPTIONS:${ANSI.reset}
|
|
189
|
-
-u, --url <url> Runtime URL
|
|
190
|
-
-t, --token <jwt> Bearer token to use for this session (e.g. from
|
|
191
|
-
'cadet pair'). Overrides the stored token and is
|
|
192
|
-
not persisted.
|
|
193
142
|
-a, --assistant-id <id> Assistant ID
|
|
194
143
|
-h, --help Show this help message
|
|
195
144
|
|
|
196
145
|
${ANSI.bold}EXAMPLES:${ANSI.reset}
|
|
197
146
|
cadet client
|
|
198
147
|
cadet client mycadet-foo
|
|
199
|
-
# Remote assistants must be reached over https (e.g. a tunnel) — the
|
|
200
|
-
# guardian refresh token is only sent over https or a loopback address:
|
|
201
|
-
cadet client --url https://your-tunnel.example
|
|
202
|
-
cadet client mycadet-foo --url http://localhost:${GATEWAY_PORT}
|
|
203
|
-
|
|
204
|
-
# Ephemeral: connect to another machine's assistant with a paired token
|
|
205
|
-
# (no lockfile entry, nothing persisted):
|
|
206
|
-
cadet client --url https://your-tunnel.example --token <jwt>
|
|
207
148
|
|
|
208
149
|
`);
|
|
209
150
|
}
|
|
@@ -280,16 +221,7 @@ export const client = Object.assign(
|
|
|
280
221
|
...getClientRegistrationHeaders(CLI_INTERFACE_ID),
|
|
281
222
|
};
|
|
282
223
|
} else {
|
|
283
|
-
//
|
|
284
|
-
// TUI, so launching after the access token expired renews transparently
|
|
285
|
-
// rather than erroring. The one door: a fresh stored lease comes back
|
|
286
|
-
// unchanged, a due one re-invokes the pair flow, and a failed re-pair
|
|
287
|
-
// still hands back the stored token when it has life left. A
|
|
288
|
-
// caller-supplied `--token` survives (the pair flow talks only to the
|
|
289
|
-
// lockfile's persisted entry, and a null door result falls back to it).
|
|
290
|
-
// (Mid-session expiry — the token dying while the TUI is already open —
|
|
291
|
-
// is a separate follow-up, since the TUI threads a static auth object
|
|
292
|
-
// through React.)
|
|
224
|
+
// Renew a stale stored lease through the one door before the TUI opens.
|
|
293
225
|
const fresh = await loadFreshGuardianToken(assistantId);
|
|
294
226
|
const token = fresh?.accessToken ?? bearerToken;
|
|
295
227
|
auth = {
|
package/src/commands/confirm.ts
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
* would otherwise hang waiting for an interactive user.
|
|
10
10
|
*/
|
|
11
11
|
|
|
12
|
+
import { z } from "zod";
|
|
13
|
+
|
|
12
14
|
import { extractFlag } from "../lib/arg-utils.js";
|
|
13
15
|
import { AssistantClient } from "../lib/assistant-client.js";
|
|
14
16
|
|
|
@@ -131,7 +133,9 @@ export const confirm = Object.assign(
|
|
|
131
133
|
process.exit(1);
|
|
132
134
|
}
|
|
133
135
|
|
|
134
|
-
const result =
|
|
136
|
+
const result = z
|
|
137
|
+
.object({ accepted: z.boolean() })
|
|
138
|
+
.parse(await response.json());
|
|
135
139
|
|
|
136
140
|
if (jsonOutput) {
|
|
137
141
|
console.log(JSON.stringify(result, null, 2));
|
package/src/commands/devices.ts
CHANGED
|
@@ -177,7 +177,7 @@ async function listDevices(
|
|
|
177
177
|
} catch (err) {
|
|
178
178
|
console.error(
|
|
179
179
|
`Error: could not reach the gateway for '${displayName}' at ${base}: ${
|
|
180
|
-
|
|
180
|
+
err instanceof Error ? err.message : String(err)
|
|
181
181
|
}`,
|
|
182
182
|
);
|
|
183
183
|
process.exit(1);
|
|
@@ -307,7 +307,7 @@ async function revokeDevice(
|
|
|
307
307
|
} catch (err) {
|
|
308
308
|
console.error(
|
|
309
309
|
`Error: could not reach the gateway for '${displayName}' at ${base}: ${
|
|
310
|
-
|
|
310
|
+
err instanceof Error ? err.message : String(err)
|
|
311
311
|
}`,
|
|
312
312
|
);
|
|
313
313
|
process.exit(1);
|
package/src/commands/hatch.ts
CHANGED
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
shouldPromptForHatchProvider,
|
|
23
23
|
} from "../lib/provider-secrets.js";
|
|
24
24
|
import { green } from "../lib/color";
|
|
25
|
-
import { HATCH_ART, HATCHED_EMOJI, VALID_REMOTE_HOSTS } from "../lib/constants";
|
|
25
|
+
import { HATCH_ART, HATCHED_EMOJI, VALID_REMOTE_HOSTS, isRemoteHost } from "../lib/constants";
|
|
26
26
|
import type { RemoteHost } from "../lib/constants";
|
|
27
27
|
import { logHatchNextSteps } from "../lib/hatch-next-steps.js";
|
|
28
28
|
import { printInstanceDetails } from "../lib/instance-details.js";
|
|
@@ -117,13 +117,13 @@ function parseArgs(): HatchArgs {
|
|
|
117
117
|
i++;
|
|
118
118
|
} else if (arg === "--remote") {
|
|
119
119
|
const next = args[i + 1];
|
|
120
|
-
if (!next || !
|
|
120
|
+
if (!next || !isRemoteHost(next)) {
|
|
121
121
|
console.error(
|
|
122
122
|
`Error: --remote requires one of: ${VALID_REMOTE_HOSTS.join(", ")}`,
|
|
123
123
|
);
|
|
124
124
|
process.exit(1);
|
|
125
125
|
}
|
|
126
|
-
remote = next
|
|
126
|
+
remote = next;
|
|
127
127
|
i++;
|
|
128
128
|
} else if (arg === "--config") {
|
|
129
129
|
const next = args[i + 1];
|
package/src/commands/machine.ts
CHANGED
|
@@ -130,7 +130,8 @@ export const machine = Object.assign(
|
|
|
130
130
|
`Machine policy for '${entry.assistantId}' (${entry.cloud} assistant):`,
|
|
131
131
|
);
|
|
132
132
|
for (const p of paths) {
|
|
133
|
-
const leaf = p.split(".")[1]
|
|
133
|
+
const leaf = p.split(".")[1];
|
|
134
|
+
if (leaf !== "max" && leaf !== "high") continue;
|
|
134
135
|
console.log(storedLine(p, result.machine?.memory?.[leaf]));
|
|
135
136
|
}
|
|
136
137
|
return;
|
package/src/commands/message.ts
CHANGED
|
@@ -8,6 +8,8 @@
|
|
|
8
8
|
|
|
9
9
|
import { readFileSync } from "node:fs";
|
|
10
10
|
|
|
11
|
+
import { z } from "zod";
|
|
12
|
+
|
|
11
13
|
import { extractFlag } from "../lib/arg-utils.js";
|
|
12
14
|
import { AssistantClient } from "../lib/assistant-client.js";
|
|
13
15
|
|
|
@@ -184,10 +186,9 @@ export const message = Object.assign(
|
|
|
184
186
|
process.exit(1);
|
|
185
187
|
}
|
|
186
188
|
|
|
187
|
-
const result =
|
|
188
|
-
accepted: boolean
|
|
189
|
-
|
|
190
|
-
};
|
|
189
|
+
const result = z
|
|
190
|
+
.object({ accepted: z.boolean(), messageId: z.string() })
|
|
191
|
+
.parse(await response.json());
|
|
191
192
|
|
|
192
193
|
if (jsonOutput) {
|
|
193
194
|
console.log(JSON.stringify(result, null, 2));
|
package/src/commands/pair.ts
CHANGED
|
@@ -26,9 +26,9 @@ import {
|
|
|
26
26
|
|
|
27
27
|
import {
|
|
28
28
|
buildRemoteWebPairingUrl,
|
|
29
|
+
RemoteWebPairingVerificationResponseSchema,
|
|
29
30
|
type RemoteWebPairingChallengeResponse,
|
|
30
31
|
type RemoteWebPairingVerificationRequest,
|
|
31
|
-
type RemoteWebPairingVerificationResponse,
|
|
32
32
|
} from "@mycadet/service-contracts/remote-web-pairing";
|
|
33
33
|
|
|
34
34
|
import {
|
|
@@ -357,8 +357,9 @@ export const pair = Object.assign(
|
|
|
357
357
|
);
|
|
358
358
|
process.exit(1);
|
|
359
359
|
}
|
|
360
|
-
const result =
|
|
361
|
-
|
|
360
|
+
const result = RemoteWebPairingVerificationResponseSchema.parse(
|
|
361
|
+
await response.json(),
|
|
362
|
+
);
|
|
362
363
|
if (jsonOutput) {
|
|
363
364
|
console.log(JSON.stringify(result, null, 2));
|
|
364
365
|
return;
|
package/src/commands/ps.ts
CHANGED
|
@@ -2,11 +2,7 @@ import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
|
2
2
|
import { getAppServerPaths } from "../lib/servers/common.js";
|
|
3
3
|
import { join } from "path";
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
TUNNEL_PROVIDERS,
|
|
7
|
-
type TunnelProviderName,
|
|
8
|
-
} from "@mycadet/service-contracts/ingress";
|
|
9
|
-
import { DEFAULT_TUNNEL_PROVIDER } from "../lib/tunnel.js";
|
|
5
|
+
import { DEFAULT_TUNNEL_PROVIDER, isTunnelProvider } from "../lib/tunnel.js";
|
|
10
6
|
import { loadNgrokDomain } from "../lib/tunnels/ngrok.js";
|
|
11
7
|
import {
|
|
12
8
|
checkHealth,
|
|
@@ -368,10 +364,7 @@ export async function printRootProcessDetail(
|
|
|
368
364
|
}
|
|
369
365
|
|
|
370
366
|
const provider: string | null = tunnel?.provider ?? null;
|
|
371
|
-
if (
|
|
372
|
-
name === "tunnel" ||
|
|
373
|
-
TUNNEL_PROVIDERS.includes(name as TunnelProviderName)
|
|
374
|
-
) {
|
|
367
|
+
if (name === "tunnel" || isTunnelProvider(name)) {
|
|
375
368
|
console.log(
|
|
376
369
|
name === "tunnel" ? "Tunnel agent:" : `Tunnel agent (${name}):`,
|
|
377
370
|
);
|
package/src/commands/setup.ts
CHANGED
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import { resolveAssistant } from "../lib/assistant-config.js";
|
|
2
2
|
import { getGatewayUrl } from "@mycadet/local-mode/contract";
|
|
3
3
|
import { cliCommand, loadFreshGuardianToken } from "@mycadet/local-mode";
|
|
4
|
-
import {
|
|
5
|
-
ensureProviderApiKey,
|
|
6
|
-
formatProviderName,
|
|
7
|
-
} from "@mycadet/local-mode";
|
|
4
|
+
import { ensureProviderApiKey, formatProviderName } from "@mycadet/local-mode";
|
|
8
5
|
import { yellow } from "../lib/color.js";
|
|
9
6
|
|
|
10
7
|
function parseSetupArgs(args: string[]): { provider?: string } {
|
|
@@ -126,9 +123,6 @@ export const setup = Object.assign(
|
|
|
126
123
|
}
|
|
127
124
|
|
|
128
125
|
const gatewayUrl = getGatewayUrl(entry);
|
|
129
|
-
// The one door: a fresh stored lease comes back unchanged; a due one
|
|
130
|
-
// re-invokes the pair flow and persists the fresh pair; a failed re-pair
|
|
131
|
-
// still hands back the stored token when it has life left.
|
|
132
126
|
const freshToken = await loadFreshGuardianToken(entry.assistantId);
|
|
133
127
|
const bearerToken = freshToken?.accessToken;
|
|
134
128
|
|
package/src/commands/tunnel.ts
CHANGED
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
DEFAULT_TUNNEL_PROVIDER,
|
|
11
11
|
PROVIDER_META,
|
|
12
12
|
clearReservedDomain,
|
|
13
|
+
isTunnelProvider,
|
|
13
14
|
providerSupportsReservedDomain,
|
|
14
15
|
runProviderTunnel,
|
|
15
16
|
stopTunnelProcess,
|
|
@@ -134,7 +135,7 @@ function parseArgs(): TunnelArgs {
|
|
|
134
135
|
);
|
|
135
136
|
process.exit(1);
|
|
136
137
|
}
|
|
137
|
-
if (!
|
|
138
|
+
if (!isTunnelProvider(next)) {
|
|
138
139
|
console.error(
|
|
139
140
|
`Error: unknown tunnel provider '${next}'. Valid providers: ${TUNNEL_PROVIDERS.join(", ")}.`,
|
|
140
141
|
);
|
|
@@ -143,7 +144,7 @@ function parseArgs(): TunnelArgs {
|
|
|
143
144
|
);
|
|
144
145
|
process.exit(1);
|
|
145
146
|
}
|
|
146
|
-
provider = next
|
|
147
|
+
provider = next;
|
|
147
148
|
i++;
|
|
148
149
|
} else if (arg === "--domain") {
|
|
149
150
|
const next = args[i + 1];
|
package/src/commands/upgrade.ts
CHANGED
|
@@ -23,7 +23,7 @@ import {
|
|
|
23
23
|
import {
|
|
24
24
|
emitCliError,
|
|
25
25
|
categorizeUpgradeError,
|
|
26
|
-
|
|
26
|
+
isCliErrorCategory,
|
|
27
27
|
} from "../lib/cli-error.js";
|
|
28
28
|
import { parseAssistantTargetArg } from "../lib/assistant-target-args.js";
|
|
29
29
|
|
|
@@ -209,7 +209,9 @@ function reportUpgradeFailure(result: {
|
|
|
209
209
|
const msg = `Error: Upgrade failed: ${result.error ?? "unknown error"}`;
|
|
210
210
|
console.error(`\n❌ ${msg}`);
|
|
211
211
|
emitCliError(
|
|
212
|
-
(result.code
|
|
212
|
+
isCliErrorCategory(result.code)
|
|
213
|
+
? result.code
|
|
214
|
+
: categorizeUpgradeError(result.error),
|
|
213
215
|
msg,
|
|
214
216
|
);
|
|
215
217
|
process.exit(1);
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
type ReactElement,
|
|
8
8
|
} from "react";
|
|
9
9
|
import { Box, render as inkRender, Text, useInput, useStdout } from "ink";
|
|
10
|
+
import { z } from "zod";
|
|
10
11
|
|
|
11
12
|
import { checkHealth, getAssistantDisplayName } from "@mycadet/local-mode";
|
|
12
13
|
import { HATCH_ART, HATCHED_EMOJI } from "../lib/constants";
|
|
@@ -165,9 +166,13 @@ interface HealthResponse {
|
|
|
165
166
|
/** Extract human-readable message from a daemon JSON error response. */
|
|
166
167
|
function friendlyErrorMessage(status: number, body: string): string {
|
|
167
168
|
try {
|
|
168
|
-
const parsed =
|
|
169
|
-
|
|
170
|
-
|
|
169
|
+
const parsed = z
|
|
170
|
+
.object({ error: z.object({ message: z.string() }).partial() })
|
|
171
|
+
.partial()
|
|
172
|
+
.safeParse(JSON.parse(body));
|
|
173
|
+
const message = parsed.success ? parsed.data.error?.message : undefined;
|
|
174
|
+
if (message) {
|
|
175
|
+
return message;
|
|
171
176
|
}
|
|
172
177
|
} catch {
|
|
173
178
|
// Not JSON — fall through
|
|
@@ -233,7 +238,9 @@ async function runtimeRequest<T>(
|
|
|
233
238
|
headers: {
|
|
234
239
|
"Content-Type": "application/json",
|
|
235
240
|
...auth,
|
|
236
|
-
...(init?.headers
|
|
241
|
+
...(init?.headers
|
|
242
|
+
? Object.fromEntries(new Headers(init?.headers).entries())
|
|
243
|
+
: undefined),
|
|
237
244
|
},
|
|
238
245
|
});
|
|
239
246
|
|
|
@@ -335,17 +342,17 @@ async function setRuntimeConfigValue(
|
|
|
335
342
|
}
|
|
336
343
|
|
|
337
344
|
/** Resolve a dotted config path within the fetched config object. */
|
|
345
|
+
function isRecord(value: unknown): value is Record<string, unknown> {
|
|
346
|
+
return typeof value === "object" && value !== null;
|
|
347
|
+
}
|
|
348
|
+
|
|
338
349
|
function resolveConfigPath(config: unknown, dottedPath: string): unknown {
|
|
339
350
|
let current: unknown = config;
|
|
340
351
|
for (const segment of dottedPath.split(".")) {
|
|
341
|
-
if (
|
|
342
|
-
current === null ||
|
|
343
|
-
typeof current !== "object" ||
|
|
344
|
-
!(segment in (current as Record<string, unknown>))
|
|
345
|
-
) {
|
|
352
|
+
if (!isRecord(current) || !(segment in current)) {
|
|
346
353
|
return undefined;
|
|
347
354
|
}
|
|
348
|
-
current =
|
|
355
|
+
current = current[segment];
|
|
349
356
|
}
|
|
350
357
|
return current;
|
|
351
358
|
}
|
|
@@ -1298,8 +1305,9 @@ function ChatApp({
|
|
|
1298
1305
|
|
|
1299
1306
|
const visibleWindow = useMemo(() => {
|
|
1300
1307
|
if (feed.length === 0) {
|
|
1308
|
+
const items: FeedItem[] = [];
|
|
1301
1309
|
return {
|
|
1302
|
-
items
|
|
1310
|
+
items,
|
|
1303
1311
|
startIndex: 0,
|
|
1304
1312
|
endIndex: 0,
|
|
1305
1313
|
hiddenAbove: 0,
|
|
@@ -2356,10 +2364,7 @@ function ChatApp({
|
|
|
2356
2364
|
}
|
|
2357
2365
|
if (item.type === "status") {
|
|
2358
2366
|
return (
|
|
2359
|
-
<Text
|
|
2360
|
-
key={feedIndex}
|
|
2361
|
-
color={item.color as "green" | "yellow" | "red" | undefined}
|
|
2362
|
-
>
|
|
2367
|
+
<Text key={feedIndex} color={item.color}>
|
|
2363
2368
|
{item.text}
|
|
2364
2369
|
</Text>
|
|
2365
2370
|
);
|
package/src/index.ts
CHANGED
|
@@ -86,6 +86,10 @@ const commands = {
|
|
|
86
86
|
|
|
87
87
|
type CommandName = keyof typeof commands;
|
|
88
88
|
|
|
89
|
+
function isCommandName(name: string): name is CommandName {
|
|
90
|
+
return name in commands;
|
|
91
|
+
}
|
|
92
|
+
|
|
89
93
|
function printHelp(): void {
|
|
90
94
|
console.log("Usage: cadet <command> [options]");
|
|
91
95
|
console.log("");
|
|
@@ -238,7 +242,7 @@ async function main() {
|
|
|
238
242
|
process.exit(0);
|
|
239
243
|
}
|
|
240
244
|
|
|
241
|
-
const command = commands[commandName
|
|
245
|
+
const command = isCommandName(commandName) ? commands[commandName] : undefined;
|
|
242
246
|
|
|
243
247
|
if (!command) {
|
|
244
248
|
console.error(red(`Unknown command: ${commandName}`));
|
package/src/lib/cli-error.ts
CHANGED
|
@@ -8,21 +8,31 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
/** Known error categories emitted by CLI commands. */
|
|
11
|
-
export
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
11
|
+
export const CLI_ERROR_CATEGORIES = [
|
|
12
|
+
"CLI_UPDATE_FAILED",
|
|
13
|
+
"DOCKER_NOT_RUNNING",
|
|
14
|
+
"IMAGE_PULL_FAILED",
|
|
15
|
+
"MISSING_VERSION",
|
|
16
|
+
"READINESS_TIMEOUT",
|
|
17
|
+
"ROLLBACK_FAILED",
|
|
18
|
+
"ROLLBACK_NO_STATE",
|
|
19
|
+
"VERSION_DIRECTION",
|
|
20
|
+
"AUTH_FAILED",
|
|
21
|
+
"NETWORK_ERROR",
|
|
22
|
+
"UNSUPPORTED_TOPOLOGY",
|
|
23
|
+
"ASSISTANT_NOT_FOUND",
|
|
24
|
+
"CLOUD_API_ERROR",
|
|
25
|
+
"UNKNOWN",
|
|
26
|
+
] as const;
|
|
27
|
+
|
|
28
|
+
export type CliErrorCategory = (typeof CLI_ERROR_CATEGORIES)[number];
|
|
29
|
+
|
|
30
|
+
/** Whether `value` is a category CLI commands may emit. */
|
|
31
|
+
export function isCliErrorCategory(
|
|
32
|
+
value: string | undefined,
|
|
33
|
+
): value is CliErrorCategory {
|
|
34
|
+
return CLI_ERROR_CATEGORIES.some((category) => category === value);
|
|
35
|
+
}
|
|
26
36
|
|
|
27
37
|
interface CliErrorPayload {
|
|
28
38
|
error: CliErrorCategory;
|
package/src/lib/cloud-login.ts
CHANGED
|
@@ -11,7 +11,6 @@ import { fetchCurrentUser, readCloudToken } from "@mycadet/local-mode";
|
|
|
11
11
|
import { getCloudBaseUrl } from "@mycadet/shared";
|
|
12
12
|
import { randomBytes } from "crypto";
|
|
13
13
|
import { createServer } from "http";
|
|
14
|
-
import type { AddressInfo } from "net";
|
|
15
14
|
|
|
16
15
|
import { openBrowser } from "./open-browser.js";
|
|
17
16
|
import { saveCloudToken } from "./cloud-client.js";
|
|
@@ -231,7 +230,7 @@ export function startLoopbackListener(
|
|
|
231
230
|
rejectListener(new Error("Failed to start local server."));
|
|
232
231
|
return;
|
|
233
232
|
}
|
|
234
|
-
const { port } = addr
|
|
233
|
+
const { port } = addr;
|
|
235
234
|
resolveListener({
|
|
236
235
|
redirectUri: `http://127.0.0.1:${port}${CALLBACK_PATH}`,
|
|
237
236
|
waitForCode,
|
package/src/lib/constants.ts
CHANGED
|
@@ -23,6 +23,11 @@ export const VALID_REMOTE_HOSTS = [
|
|
|
23
23
|
"baseten",
|
|
24
24
|
] as const;
|
|
25
25
|
export type RemoteHost = (typeof VALID_REMOTE_HOSTS)[number];
|
|
26
|
+
|
|
27
|
+
/** Whether `value` names a remote host the CLI can target. */
|
|
28
|
+
export function isRemoteHost(value: string): value is RemoteHost {
|
|
29
|
+
return VALID_REMOTE_HOSTS.some((host) => host === value);
|
|
30
|
+
}
|
|
26
31
|
const ANSI = {
|
|
27
32
|
reset: "\x1b[0m",
|
|
28
33
|
bold: "\x1b[1m",
|
|
@@ -14,6 +14,8 @@
|
|
|
14
14
|
* leniently, so a newer daemon adding fields never breaks an older CLI.
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
+
import { z } from "zod";
|
|
18
|
+
|
|
17
19
|
/**
|
|
18
20
|
* Capture format, declared on the `start` frame.
|
|
19
21
|
*
|
|
@@ -187,7 +189,7 @@ export function parseServerFrame(payload: string): LiveVoiceServerFrame {
|
|
|
187
189
|
if (typeof value !== "object" || value === null) {
|
|
188
190
|
return { type: "malformed", raw: payload };
|
|
189
191
|
}
|
|
190
|
-
const frameType = (
|
|
192
|
+
const frameType = z.object({ type: z.unknown() }).partial().catch({}).parse(value).type;
|
|
191
193
|
if (typeof frameType !== "string") {
|
|
192
194
|
return { type: "malformed", raw: payload };
|
|
193
195
|
}
|
|
@@ -30,6 +30,7 @@
|
|
|
30
30
|
|
|
31
31
|
import { tunnelHostForCloudHost } from "@mycadet/service-contracts/ingress";
|
|
32
32
|
import { cloudAuthHeaders } from "@mycadet/local-mode";
|
|
33
|
+
import { z } from "zod";
|
|
33
34
|
|
|
34
35
|
/** Production tunnel, when the cloud host implies nothing more specific. */
|
|
35
36
|
const DEFAULT_TUNNEL_HOST = "tunnel.mycadet.ai";
|
|
@@ -116,10 +117,10 @@ export function buildTunnelLiveVoiceUrl(args: {
|
|
|
116
117
|
return url.toString();
|
|
117
118
|
}
|
|
118
119
|
|
|
119
|
-
|
|
120
|
-
token
|
|
121
|
-
expiresAt
|
|
122
|
-
}
|
|
120
|
+
const LiveVoiceTokenResponseSchema = z.object({
|
|
121
|
+
token: z.string().optional(),
|
|
122
|
+
expiresAt: z.unknown(),
|
|
123
|
+
});
|
|
123
124
|
|
|
124
125
|
/**
|
|
125
126
|
* Mint a single-use tunnel WS token for one assistant.
|
|
@@ -170,10 +171,10 @@ export async function mintTunnelWsToken(args: {
|
|
|
170
171
|
);
|
|
171
172
|
}
|
|
172
173
|
|
|
173
|
-
const body =
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const token =
|
|
174
|
+
const body = LiveVoiceTokenResponseSchema.safeParse(
|
|
175
|
+
await response.json().catch(() => ({})),
|
|
176
|
+
);
|
|
177
|
+
const token = body.success ? (body.data.token?.trim() ?? "") : "";
|
|
177
178
|
if (!token) {
|
|
178
179
|
throw new TunnelWsTokenError(
|
|
179
180
|
response.status,
|
package/src/lib/pair.ts
CHANGED
|
@@ -10,6 +10,7 @@
|
|
|
10
10
|
|
|
11
11
|
import { resolveEnvironmentName } from "@mycadet/local-mode";
|
|
12
12
|
import { REMOTE_WEB_PAIRING_CODE_TTL_MS } from "@mycadet/service-contracts/remote-web-pairing";
|
|
13
|
+
import { z } from "zod";
|
|
13
14
|
|
|
14
15
|
const CODE_TTL_MINUTES = Math.round(REMOTE_WEB_PAIRING_CODE_TTL_MS / 60_000);
|
|
15
16
|
|
|
@@ -18,13 +19,19 @@ const CODE_TTL_MINUTES = Math.round(REMOTE_WEB_PAIRING_CODE_TTL_MS / 60_000);
|
|
|
18
19
|
* (`{"error":{"code":...,"message":...}}`). Returns null when the body is not
|
|
19
20
|
* JSON or carries no string code.
|
|
20
21
|
*/
|
|
22
|
+
const GatewayErrorEnvelopeSchema = z
|
|
23
|
+
.object({ error: z.object({ code: z.string() }).partial() })
|
|
24
|
+
.partial();
|
|
25
|
+
|
|
21
26
|
export function parseGatewayErrorCode(body: string): string | null {
|
|
27
|
+
let raw: unknown;
|
|
22
28
|
try {
|
|
23
|
-
|
|
24
|
-
return typeof parsed.error?.code === "string" ? parsed.error.code : null;
|
|
29
|
+
raw = JSON.parse(body);
|
|
25
30
|
} catch {
|
|
26
31
|
return null;
|
|
27
32
|
}
|
|
33
|
+
const parsed = GatewayErrorEnvelopeSchema.safeParse(raw);
|
|
34
|
+
return parsed.success ? (parsed.data.error?.code ?? null) : null;
|
|
28
35
|
}
|
|
29
36
|
|
|
30
37
|
/**
|
package/src/lib/tunnel.ts
CHANGED
|
@@ -120,6 +120,11 @@ const providers: Record<TunnelProviderName, TunnelProvider> = {
|
|
|
120
120
|
};
|
|
121
121
|
const providerNameSchema = z.enum(TUNNEL_PROVIDERS);
|
|
122
122
|
|
|
123
|
+
/** Whether `value` names a tunnel provider the CLI can drive. */
|
|
124
|
+
export function isTunnelProvider(value: string): value is TunnelProviderName {
|
|
125
|
+
return providerNameSchema.safeParse(value).success;
|
|
126
|
+
}
|
|
127
|
+
|
|
123
128
|
/**
|
|
124
129
|
* A tunnelable assistant plus the gateway port and workspace the app server fronts.
|
|
125
130
|
*/
|
|
@@ -10,6 +10,8 @@ import type {
|
|
|
10
10
|
import { spawnSync } from "node:child_process";
|
|
11
11
|
import { win32 } from "node:path";
|
|
12
12
|
|
|
13
|
+
import { z } from "zod";
|
|
14
|
+
|
|
13
15
|
import { GATEWAY_PORT } from "../constants.js";
|
|
14
16
|
import { cliCommand } from "@mycadet/local-mode";
|
|
15
17
|
import { ensureBinaryInstalled } from "../ensure-binary.js";
|
|
@@ -150,11 +152,6 @@ function realTailscaleDeps(): TailscaleDeps {
|
|
|
150
152
|
|
|
151
153
|
// ── Status parsing ──────────────────────────────────────────────────────────
|
|
152
154
|
|
|
153
|
-
interface TailscaleStatus {
|
|
154
|
-
BackendState?: string;
|
|
155
|
-
Self?: { DNSName?: string; Online?: boolean };
|
|
156
|
-
}
|
|
157
|
-
|
|
158
155
|
/** Trim the trailing dot tailscale appends to MagicDNS names. */
|
|
159
156
|
export function normalizeDnsName(dnsName: string): string {
|
|
160
157
|
return dnsName.replace(/\.$/, "");
|
|
@@ -165,10 +162,19 @@ export function normalizeDnsName(dnsName: string): string {
|
|
|
165
162
|
* (without trailing dot) this machine serves at. Throws a clear error when the
|
|
166
163
|
* daemon is logged out or otherwise not ready to serve.
|
|
167
164
|
*/
|
|
165
|
+
const TailscaleStatusSchema = z.looseObject({
|
|
166
|
+
BackendState: z.string().optional(),
|
|
167
|
+
Self: z
|
|
168
|
+
.looseObject({ DNSName: z.string().optional(), Online: z.boolean().optional() })
|
|
169
|
+
.optional(),
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
type TailscaleStatus = z.infer<typeof TailscaleStatusSchema>;
|
|
173
|
+
|
|
168
174
|
export function resolveServeHostname(statusJson: string): string {
|
|
169
175
|
let status: TailscaleStatus;
|
|
170
176
|
try {
|
|
171
|
-
status = JSON.parse(statusJson)
|
|
177
|
+
status = TailscaleStatusSchema.parse(JSON.parse(statusJson));
|
|
172
178
|
} catch {
|
|
173
179
|
throw new Error("Could not parse `tailscale status --json` output.");
|
|
174
180
|
}
|