@j-ho/agents-office 0.1.2 → 0.1.3
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/cli/agents-office.mjs +37 -3
- package/package.json +1 -1
package/cli/agents-office.mjs
CHANGED
|
@@ -9,6 +9,7 @@ import { spawnSync } from "node:child_process";
|
|
|
9
9
|
const GITHUB_OWNER = "awesomelon";
|
|
10
10
|
const GITHUB_REPO = "agents-office";
|
|
11
11
|
const USER_AGENT = "agents-office-cli";
|
|
12
|
+
const GITHUB_TOKEN = process.env.GITHUB_TOKEN || null;
|
|
12
13
|
|
|
13
14
|
const CACHE_DIR = process.env.AGENTS_OFFICE_CACHE_DIR
|
|
14
15
|
? path.resolve(process.env.AGENTS_OFFICE_CACHE_DIR)
|
|
@@ -87,6 +88,14 @@ function withLock(lockPath, fn) {
|
|
|
87
88
|
}
|
|
88
89
|
}
|
|
89
90
|
|
|
91
|
+
function toHttpError(statusCode, url, body) {
|
|
92
|
+
const err = new Error(`HTTP ${statusCode} from ${url}: ${String(body).slice(0, 200)}`);
|
|
93
|
+
err.statusCode = statusCode;
|
|
94
|
+
err.url = url;
|
|
95
|
+
err.body = body;
|
|
96
|
+
return err;
|
|
97
|
+
}
|
|
98
|
+
|
|
90
99
|
function httpsGetJson(url) {
|
|
91
100
|
return new Promise((resolve, reject) => {
|
|
92
101
|
const req = https.request(
|
|
@@ -96,6 +105,7 @@ function httpsGetJson(url) {
|
|
|
96
105
|
headers: {
|
|
97
106
|
"User-Agent": USER_AGENT,
|
|
98
107
|
Accept: "application/vnd.github+json",
|
|
108
|
+
...(GITHUB_TOKEN ? { Authorization: `Bearer ${GITHUB_TOKEN}` } : {}),
|
|
99
109
|
},
|
|
100
110
|
},
|
|
101
111
|
(res) => {
|
|
@@ -110,7 +120,7 @@ function httpsGetJson(url) {
|
|
|
110
120
|
reject(new Error(`Failed to parse JSON from ${url}: ${e.message}`));
|
|
111
121
|
}
|
|
112
122
|
} else {
|
|
113
|
-
reject(
|
|
123
|
+
reject(toHttpError(res.statusCode, url, body));
|
|
114
124
|
}
|
|
115
125
|
});
|
|
116
126
|
}
|
|
@@ -133,6 +143,7 @@ function downloadToFile(url, destPath, { quiet }) {
|
|
|
133
143
|
headers: {
|
|
134
144
|
"User-Agent": USER_AGENT,
|
|
135
145
|
Accept: "application/octet-stream",
|
|
146
|
+
...(GITHUB_TOKEN ? { Authorization: `Bearer ${GITHUB_TOKEN}` } : {}),
|
|
136
147
|
},
|
|
137
148
|
},
|
|
138
149
|
(res) => {
|
|
@@ -147,7 +158,7 @@ function downloadToFile(url, destPath, { quiet }) {
|
|
|
147
158
|
if (!res.statusCode || res.statusCode < 200 || res.statusCode >= 300) {
|
|
148
159
|
file.close(() => {
|
|
149
160
|
fs.rmSync(tmpPath, { force: true });
|
|
150
|
-
reject(
|
|
161
|
+
reject(toHttpError(res.statusCode, url, ""));
|
|
151
162
|
});
|
|
152
163
|
return;
|
|
153
164
|
}
|
|
@@ -218,12 +229,35 @@ function openApp(appPath) {
|
|
|
218
229
|
return r.status ?? 1;
|
|
219
230
|
}
|
|
220
231
|
|
|
232
|
+
async function fetchLatestReleaseOrExplain() {
|
|
233
|
+
const url = `https://api.github.com/repos/${GITHUB_OWNER}/${GITHUB_REPO}/releases/latest`;
|
|
234
|
+
try {
|
|
235
|
+
return await httpsGetJson(url);
|
|
236
|
+
} catch (err) {
|
|
237
|
+
// GitHub returns 404 if there are no releases, or if the repo is private without auth.
|
|
238
|
+
if (err?.statusCode === 404) {
|
|
239
|
+
throw new Error(
|
|
240
|
+
[
|
|
241
|
+
`GitHub Releases latest not found for ${GITHUB_OWNER}/${GITHUB_REPO}.`,
|
|
242
|
+
`This usually means either:`,
|
|
243
|
+
`- There is no GitHub Release yet (recommended: create a release like v0.1.3 with Agents-Office-macos.zip), or`,
|
|
244
|
+
`- The repo is private and you need to set GITHUB_TOKEN for API access.`,
|
|
245
|
+
``,
|
|
246
|
+
`You can also run with a specific tag once releases exist:`,
|
|
247
|
+
` npx @j-ho/agents-office --version 0.1.3`,
|
|
248
|
+
].join("\n")
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
throw err;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
|
|
221
255
|
async function resolveReleaseTag(requestedVersion) {
|
|
222
256
|
if (requestedVersion) {
|
|
223
257
|
const v = requestedVersion.startsWith("v") ? requestedVersion.slice(1) : requestedVersion;
|
|
224
258
|
return `v${v}`;
|
|
225
259
|
}
|
|
226
|
-
const latest = await
|
|
260
|
+
const latest = await fetchLatestReleaseOrExplain();
|
|
227
261
|
if (!latest?.tag_name) throw new Error("GitHub latest release has no tag_name");
|
|
228
262
|
return latest.tag_name;
|
|
229
263
|
}
|