@moxt-ai/cli 0.4.0-beta.0 → 0.4.0-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +39 -7
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -24,7 +24,9 @@ function printError(message) {
|
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
// src/utils/runtime-context.ts
|
|
27
|
+
import { readFileSync } from "fs";
|
|
27
28
|
var DEFAULT_USER_HOST = "api.moxt.ai";
|
|
29
|
+
var SANDBOX_ENV_FILE_KEY = "SANDBOX_ENV_FILE";
|
|
28
30
|
var SANDBOX_ENV_KEYS = [
|
|
29
31
|
"BASE_API_HOST",
|
|
30
32
|
"SANDBOX_TOOL_API_TOKEN",
|
|
@@ -52,18 +54,48 @@ function resolveRuntimeContext(env = process.env) {
|
|
|
52
54
|
throw new RuntimeContextError("Missing auth. Set sandbox environment variables or MOXT_API_KEY.");
|
|
53
55
|
}
|
|
54
56
|
function resolveSandboxRuntimeContext(env = process.env) {
|
|
55
|
-
const
|
|
57
|
+
const directRepoPayload = readNonEmptyEnv(env, "MOXT_REPO_PAYLOAD");
|
|
58
|
+
const sandboxEnvFile = readNonEmptyEnv(env, SANDBOX_ENV_FILE_KEY);
|
|
59
|
+
const missingKeys = SANDBOX_ENV_KEYS.filter((key) => {
|
|
60
|
+
if (key === "MOXT_REPO_PAYLOAD") return !directRepoPayload && !sandboxEnvFile;
|
|
61
|
+
return !readNonEmptyEnv(env, key);
|
|
62
|
+
});
|
|
56
63
|
if (missingKeys.length > 0) {
|
|
57
64
|
throw new RuntimeContextError(`Incomplete sandbox environment. Missing: ${missingKeys.join(", ")}.`);
|
|
58
65
|
}
|
|
66
|
+
let repoPayload = directRepoPayload;
|
|
67
|
+
if (!repoPayload) {
|
|
68
|
+
if (!sandboxEnvFile) {
|
|
69
|
+
throw new RuntimeContextError("MOXT_REPO_PAYLOAD is required.");
|
|
70
|
+
}
|
|
71
|
+
repoPayload = readRepoPayloadFromSandboxEnvFile(sandboxEnvFile);
|
|
72
|
+
}
|
|
59
73
|
return {
|
|
60
74
|
mode: "sandbox",
|
|
61
75
|
baseApiHost: normalizeBaseApiHost(readRequiredEnv(env, "BASE_API_HOST")),
|
|
62
76
|
sandboxToolApiToken: readRequiredEnv(env, "SANDBOX_TOOL_API_TOKEN"),
|
|
63
77
|
workspaceId: readRequiredEnv(env, "MOXT_WORKSPACE_ID"),
|
|
64
|
-
repoPayload: parseRepoPayload(
|
|
78
|
+
repoPayload: parseRepoPayload(repoPayload)
|
|
65
79
|
};
|
|
66
80
|
}
|
|
81
|
+
function readRepoPayloadFromSandboxEnvFile(path2) {
|
|
82
|
+
let parsed;
|
|
83
|
+
try {
|
|
84
|
+
parsed = JSON.parse(readFileSync(path2, "utf8"));
|
|
85
|
+
} catch (error) {
|
|
86
|
+
throw new RuntimeContextError(
|
|
87
|
+
`Failed to read SANDBOX_ENV_FILE: ${error instanceof Error ? error.message : String(error)}`
|
|
88
|
+
);
|
|
89
|
+
}
|
|
90
|
+
if (!isRecord(parsed)) {
|
|
91
|
+
throw new RuntimeContextError("SANDBOX_ENV_FILE must contain a JSON object.");
|
|
92
|
+
}
|
|
93
|
+
const repoPayload = parsed.MOXT_REPO_PAYLOAD;
|
|
94
|
+
if (typeof repoPayload !== "string" || repoPayload.trim().length === 0) {
|
|
95
|
+
throw new RuntimeContextError("MOXT_REPO_PAYLOAD is missing from SANDBOX_ENV_FILE.");
|
|
96
|
+
}
|
|
97
|
+
return repoPayload.trim();
|
|
98
|
+
}
|
|
67
99
|
function parseRepoPayload(raw) {
|
|
68
100
|
let parsed;
|
|
69
101
|
try {
|
|
@@ -342,7 +374,7 @@ function getApiKeyOrUndefined() {
|
|
|
342
374
|
|
|
343
375
|
// src/utils/http.ts
|
|
344
376
|
function getUserAgent() {
|
|
345
|
-
return `moxt-cli/${"0.4.0-beta.
|
|
377
|
+
return `moxt-cli/${"0.4.0-beta.1"} (${platform()}/${arch()}) node/${process.versions.node}`;
|
|
346
378
|
}
|
|
347
379
|
async function fetchApi(method, path2, body) {
|
|
348
380
|
const apiKey = getApiKey();
|
|
@@ -2831,7 +2863,7 @@ var FLUSH_TIMEOUT_MS = 3e3;
|
|
|
2831
2863
|
var MAX_BATCH_SIZE = 100;
|
|
2832
2864
|
function commonLabels() {
|
|
2833
2865
|
return {
|
|
2834
|
-
cli_version: "0.4.0-beta.
|
|
2866
|
+
cli_version: "0.4.0-beta.1",
|
|
2835
2867
|
node_version: process.versions.node,
|
|
2836
2868
|
os: platform2(),
|
|
2837
2869
|
arch: arch2(),
|
|
@@ -2877,7 +2909,7 @@ async function flush() {
|
|
|
2877
2909
|
}
|
|
2878
2910
|
const batch = buffer.splice(0, MAX_BATCH_SIZE);
|
|
2879
2911
|
const payload = {
|
|
2880
|
-
release_id: "0.4.0-beta.
|
|
2912
|
+
release_id: "0.4.0-beta.1",
|
|
2881
2913
|
client_type: "cli",
|
|
2882
2914
|
metric_data_list: batch.map((m) => ({
|
|
2883
2915
|
profile: "cli",
|
|
@@ -3018,9 +3050,9 @@ function installExitHandler() {
|
|
|
3018
3050
|
|
|
3019
3051
|
// src/index.ts
|
|
3020
3052
|
updateNotifier({
|
|
3021
|
-
pkg: { name: "@moxt-ai/cli", version: "0.4.0-beta.
|
|
3053
|
+
pkg: { name: "@moxt-ai/cli", version: "0.4.0-beta.1" }
|
|
3022
3054
|
}).notify();
|
|
3023
|
-
var program = createProgram("0.4.0-beta.
|
|
3055
|
+
var program = createProgram("0.4.0-beta.1");
|
|
3024
3056
|
instrumentProgram(program);
|
|
3025
3057
|
installExitHandler();
|
|
3026
3058
|
program.parseAsync(process.argv).then(async () => {
|