trajectories-sh 1.18.3 → 1.18.5
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/cli.js
CHANGED
|
@@ -98,7 +98,7 @@ async function uploadTrajectoryAction(pathArg, opts) {
|
|
|
98
98
|
);
|
|
99
99
|
}
|
|
100
100
|
if (isZip) {
|
|
101
|
-
const { uploadZip } = await import("./upload-
|
|
101
|
+
const { uploadZip } = await import("./upload-NBHAW2LV.js");
|
|
102
102
|
const slug2 = opts.slug ?? pathArg.replace(/\.zip$/i, "").replace(/\/+$/, "").split("/").pop();
|
|
103
103
|
console.log(chalk.bold(`
|
|
104
104
|
Uploading ZIP ${pathArg} \u2192 ${chalk.cyan(slug2)}
|
|
@@ -127,7 +127,7 @@ async function uploadTrajectoryAction(pathArg, opts) {
|
|
|
127
127
|
Uploading trajectory ${pathArg} \u2192 ${chalk.cyan(slug)}
|
|
128
128
|
`));
|
|
129
129
|
try {
|
|
130
|
-
const { uploadJob } = await import("./upload-
|
|
130
|
+
const { uploadJob } = await import("./upload-NBHAW2LV.js");
|
|
131
131
|
const result = await uploadJob(pathArg, {
|
|
132
132
|
slug,
|
|
133
133
|
name: opts.name
|
|
@@ -51,72 +51,88 @@ async function apiPost(path, body, timeout = 3e5) {
|
|
|
51
51
|
});
|
|
52
52
|
}
|
|
53
53
|
async function uploadZip(zipPath, opts) {
|
|
54
|
-
const { readFileSync: readFileSync2, statSync:
|
|
55
|
-
const
|
|
56
|
-
const
|
|
54
|
+
const { readFileSync: readFileSync2, statSync: _statSync } = await import("fs");
|
|
55
|
+
const fileStat = _statSync(zipPath);
|
|
56
|
+
const sizeBytes = fileStat.size;
|
|
57
|
+
const sizeMB = (sizeBytes / (1024 * 1024)).toFixed(1);
|
|
58
|
+
const sizeGB = (sizeBytes / 1024 ** 3).toFixed(2);
|
|
59
|
+
console.log(` ZIP size: ${sizeBytes > 1024 ** 3 ? sizeGB + " GB" : sizeMB + " MB"}`);
|
|
60
|
+
const auth = await getAuthHeader();
|
|
57
61
|
if (!auth) throw new Error("Not authenticated. Run: trajectories auth login");
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
console.log(" Uploading to server (server-side extraction)...");
|
|
62
|
-
const fileData = readFileSync2(zipPath);
|
|
63
|
-
const formData = new FormData();
|
|
64
|
-
formData.append("file", new Blob([fileData]), zipPath.split("/").pop() ?? "upload.zip");
|
|
65
|
-
if (opts.slug) formData.append("slug", opts.slug);
|
|
66
|
-
if (opts.name) formData.append("name", opts.name);
|
|
67
|
-
formData.append("visibility", "unlisted");
|
|
68
|
-
const apiUrl = _getApiUrl();
|
|
69
|
-
const resp = await fetch(`${apiUrl}/api/cli/push/zip`, {
|
|
62
|
+
const apiUrl = getApiUrl();
|
|
63
|
+
console.log(" Requesting upload URL...");
|
|
64
|
+
const urlResp = await fetch(`${apiUrl}/api/cli/push/zip/upload-url`, {
|
|
70
65
|
method: "POST",
|
|
71
|
-
headers: { Authorization: auth },
|
|
72
|
-
body:
|
|
73
|
-
signal: AbortSignal.timeout(
|
|
66
|
+
headers: { Authorization: auth, "Content-Type": "application/json" },
|
|
67
|
+
body: "{}",
|
|
68
|
+
signal: AbortSignal.timeout(3e4)
|
|
74
69
|
});
|
|
75
|
-
if (!
|
|
76
|
-
|
|
77
|
-
try {
|
|
78
|
-
const body = await resp.json();
|
|
79
|
-
detail = body.detail || JSON.stringify(body);
|
|
80
|
-
} catch {
|
|
81
|
-
detail = await resp.text();
|
|
82
|
-
}
|
|
83
|
-
throw new Error(`ZIP upload failed (${resp.status}): ${detail}`);
|
|
70
|
+
if (!urlResp.ok) {
|
|
71
|
+
throw new Error(`Failed to get upload URL: ${await urlResp.text()}`);
|
|
84
72
|
}
|
|
85
|
-
const
|
|
86
|
-
console.log(`
|
|
73
|
+
const { task_id, signed_url } = await urlResp.json();
|
|
74
|
+
console.log(` Uploading ZIP to storage...`);
|
|
75
|
+
const zipData = readFileSync2(zipPath);
|
|
76
|
+
const putResp = await fetch(signed_url, {
|
|
77
|
+
method: "PUT",
|
|
78
|
+
headers: { "Content-Type": "application/zip" },
|
|
79
|
+
body: zipData,
|
|
80
|
+
signal: AbortSignal.timeout(36e5)
|
|
81
|
+
});
|
|
82
|
+
if (!putResp.ok) {
|
|
83
|
+
const body = await putResp.text().catch(() => "");
|
|
84
|
+
throw new Error(`ZIP upload to storage failed (${putResp.status}): ${body.slice(0, 200)}`);
|
|
85
|
+
}
|
|
86
|
+
console.log(" ZIP uploaded to storage.");
|
|
87
|
+
console.log(" Enqueuing for server-side extraction...");
|
|
88
|
+
const enqueueResp = await fetch(`${apiUrl}/api/cli/push/zip/enqueue`, {
|
|
89
|
+
method: "POST",
|
|
90
|
+
headers: { Authorization: auth, "Content-Type": "application/json" },
|
|
91
|
+
body: JSON.stringify({
|
|
92
|
+
task_id,
|
|
93
|
+
slug: opts.slug || "",
|
|
94
|
+
name: opts.name || "",
|
|
95
|
+
visibility: "unlisted"
|
|
96
|
+
}),
|
|
97
|
+
signal: AbortSignal.timeout(3e4)
|
|
98
|
+
});
|
|
99
|
+
if (!enqueueResp.ok) {
|
|
100
|
+
const detail = await enqueueResp.text().catch(() => "");
|
|
101
|
+
throw new Error(`Enqueue failed (${enqueueResp.status}): ${detail.slice(0, 300)}`);
|
|
102
|
+
}
|
|
103
|
+
console.log(" Waiting for background extraction...");
|
|
87
104
|
let lastStatus = "";
|
|
88
105
|
while (true) {
|
|
89
|
-
await new Promise((r) => setTimeout(r,
|
|
90
|
-
const statusResp = await fetch(`${apiUrl}/api/cli/push/zip/${
|
|
106
|
+
await new Promise((r) => setTimeout(r, 5e3));
|
|
107
|
+
const statusResp = await fetch(`${apiUrl}/api/cli/push/zip/${task_id}/status`, {
|
|
91
108
|
headers: { Authorization: auth },
|
|
92
109
|
signal: AbortSignal.timeout(3e4)
|
|
93
110
|
});
|
|
94
111
|
if (!statusResp.ok) {
|
|
95
|
-
|
|
112
|
+
console.log(` \u26A0 Status check failed (${statusResp.status}), retrying...`);
|
|
113
|
+
continue;
|
|
96
114
|
}
|
|
97
115
|
const status = await statusResp.json();
|
|
98
116
|
if (status.status !== lastStatus) {
|
|
99
|
-
|
|
117
|
+
const progress = status.total_jobs > 0 ? ` [${status.completed_jobs}/${status.total_jobs}]` : "";
|
|
118
|
+
const jobLabel = status.current_job ? ` (${status.current_job})` : "";
|
|
119
|
+
console.log(` ${status.status}${jobLabel}${progress}`);
|
|
100
120
|
lastStatus = status.status;
|
|
101
121
|
}
|
|
102
122
|
if (status.status === "done") {
|
|
103
|
-
const
|
|
104
|
-
|
|
105
|
-
|
|
123
|
+
const siteUrl = apiUrl.includes("localhost") ? "http://localhost:3000" : apiUrl.replace("api.", "").replace(/\/$/, "");
|
|
124
|
+
return status.jobs.map((j) => ({
|
|
125
|
+
jobId: j.job_id,
|
|
126
|
+
slug: j.slug,
|
|
127
|
+
nTrials: j.n_trials,
|
|
128
|
+
meanReward: j.mean_reward ?? void 0,
|
|
129
|
+
viewerUrl: `${siteUrl}/t/${j.job_id}`
|
|
130
|
+
}));
|
|
106
131
|
}
|
|
107
132
|
if (status.status === "error") {
|
|
108
133
|
throw new Error(`Server-side extraction failed: ${status.error}`);
|
|
109
134
|
}
|
|
110
135
|
}
|
|
111
|
-
const result = finalResult;
|
|
112
|
-
const siteUrl = apiUrl.includes("localhost") ? "http://localhost:3000" : apiUrl.replace("api.", "").replace(/\/$/, "");
|
|
113
|
-
return result.jobs.map((j) => ({
|
|
114
|
-
jobId: j.job_id,
|
|
115
|
-
slug: j.slug,
|
|
116
|
-
nTrials: j.n_trials,
|
|
117
|
-
meanReward: j.mean_reward ?? void 0,
|
|
118
|
-
viewerUrl: `${siteUrl}/t/${j.job_id}`
|
|
119
|
-
}));
|
|
120
136
|
}
|
|
121
137
|
async function convertToWebP(dir) {
|
|
122
138
|
const { files } = collectFiles(dir);
|