@khanglvm/outline-cli 0.1.6 → 0.1.8
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/CHANGELOG.md +10 -0
- package/README.md +281 -9
- package/package.json +1 -1
- package/src/agent-skills.js +114 -28
- package/src/cli.js +2 -0
- package/src/entry-integrity-manifest.generated.js +14 -10
- package/src/memory-store.js +2368 -0
- package/src/outline-client.js +93 -0
- package/src/tool-arg-schemas.js +1697 -86
- package/src/tools.extended.js +2467 -115
- package/src/tools.js +224 -7
- package/src/tools.mutation.js +496 -90
- package/src/tools.navigation.js +547 -26
package/src/outline-client.js
CHANGED
|
@@ -39,6 +39,35 @@ export class OutlineClient {
|
|
|
39
39
|
throw lastErr;
|
|
40
40
|
}
|
|
41
41
|
|
|
42
|
+
async download(method, body = {}, options = {}) {
|
|
43
|
+
const apiMethod = method.startsWith("/") ? method.slice(1) : method;
|
|
44
|
+
const url = `${this.baseApiUrl}/${apiMethod}`;
|
|
45
|
+
const maxAttempts = Math.max(1, options.maxAttempts || 1);
|
|
46
|
+
|
|
47
|
+
let lastErr;
|
|
48
|
+
for (let attempt = 1; attempt <= maxAttempts; attempt += 1) {
|
|
49
|
+
try {
|
|
50
|
+
return await this.#downloadOnce(url, body, options);
|
|
51
|
+
} catch (err) {
|
|
52
|
+
lastErr = err;
|
|
53
|
+
const shouldRetry =
|
|
54
|
+
err instanceof ApiError &&
|
|
55
|
+
(err.details.status === 429 || err.details.status >= 500) &&
|
|
56
|
+
attempt < maxAttempts;
|
|
57
|
+
|
|
58
|
+
if (!shouldRetry) {
|
|
59
|
+
throw err;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const retryAfter = Number(err.details.retryAfter || 0);
|
|
63
|
+
const waitMs = retryAfter > 0 ? retryAfter * 1000 : attempt * 400;
|
|
64
|
+
await sleep(waitMs);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
throw lastErr;
|
|
69
|
+
}
|
|
70
|
+
|
|
42
71
|
async #callOnce(url, body, options) {
|
|
43
72
|
const bodyType = options.bodyType === "multipart" ? "multipart" : "json";
|
|
44
73
|
const requestBody = this.#buildRequestBody(bodyType, body);
|
|
@@ -96,6 +125,70 @@ export class OutlineClient {
|
|
|
96
125
|
};
|
|
97
126
|
}
|
|
98
127
|
|
|
128
|
+
async #downloadOnce(url, body, options) {
|
|
129
|
+
const requestBody = this.#buildRequestBody(options.bodyType === "multipart" ? "multipart" : "json", body);
|
|
130
|
+
const headers = await this.#buildHeaders(
|
|
131
|
+
{
|
|
132
|
+
Accept: "*/*",
|
|
133
|
+
...(options.headers || {}),
|
|
134
|
+
},
|
|
135
|
+
{ bodyType: options.bodyType === "multipart" ? "multipart" : "json" }
|
|
136
|
+
);
|
|
137
|
+
const controller = new AbortController();
|
|
138
|
+
const timeout = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
139
|
+
|
|
140
|
+
let res;
|
|
141
|
+
try {
|
|
142
|
+
res = await fetch(url, {
|
|
143
|
+
method: "POST",
|
|
144
|
+
headers,
|
|
145
|
+
body: requestBody,
|
|
146
|
+
signal: controller.signal,
|
|
147
|
+
});
|
|
148
|
+
} catch (err) {
|
|
149
|
+
if (err.name === "AbortError") {
|
|
150
|
+
throw new ApiError(`Request timeout after ${this.timeoutMs}ms`, {
|
|
151
|
+
status: 408,
|
|
152
|
+
url,
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
throw new ApiError(`Network error: ${err.message}`, {
|
|
156
|
+
status: 503,
|
|
157
|
+
url,
|
|
158
|
+
});
|
|
159
|
+
} finally {
|
|
160
|
+
clearTimeout(timeout);
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
if (!res.ok) {
|
|
164
|
+
const text = await res.text().catch(() => "");
|
|
165
|
+
let parsed;
|
|
166
|
+
try {
|
|
167
|
+
parsed = text ? JSON.parse(text) : {};
|
|
168
|
+
} catch {
|
|
169
|
+
parsed = { ok: false, message: text || res.statusText };
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
const status = parsed?.status || res.status;
|
|
173
|
+
const retryAfter = res.headers.get("retry-after");
|
|
174
|
+
throw new ApiError(parsed?.message || parsed?.error || res.statusText, {
|
|
175
|
+
status,
|
|
176
|
+
retryAfter,
|
|
177
|
+
body: parsed,
|
|
178
|
+
url,
|
|
179
|
+
});
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const buffer = Buffer.from(await res.arrayBuffer());
|
|
183
|
+
return {
|
|
184
|
+
ok: true,
|
|
185
|
+
status: res.status,
|
|
186
|
+
headers: Object.fromEntries(res.headers.entries()),
|
|
187
|
+
body: buffer,
|
|
188
|
+
url: res.url,
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
|
|
99
192
|
#buildRequestBody(bodyType, body) {
|
|
100
193
|
if (bodyType === "multipart") {
|
|
101
194
|
if (body instanceof FormData) {
|