@openma/cli 0.2.0-beta.0 → 0.2.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 +15 -2
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -113,9 +113,22 @@ function loadConfigOptional() {
|
|
|
113
113
|
}
|
|
114
114
|
return { baseUrl: envBase || "https://openma.dev", apiKey: "", json: false, source: "missing" };
|
|
115
115
|
}
|
|
116
|
+
async function fetchWithRetry(url, init, maxRetries = 3) {
|
|
117
|
+
let attempt = 0;
|
|
118
|
+
while (true) {
|
|
119
|
+
const res = await fetch(url, init);
|
|
120
|
+
if (res.ok || res.status !== 503) return res;
|
|
121
|
+
const retryAfter = res.headers.get("retry-after");
|
|
122
|
+
if (!retryAfter || attempt >= maxRetries) return res;
|
|
123
|
+
const seconds = Math.min(Math.max(parseInt(retryAfter, 10) || 0, 1), 30);
|
|
124
|
+
await res.body?.cancel().catch(() => void 0);
|
|
125
|
+
await new Promise((r) => setTimeout(r, seconds * 1e3));
|
|
126
|
+
attempt += 1;
|
|
127
|
+
}
|
|
128
|
+
}
|
|
116
129
|
async function apiFetch(config, path, init) {
|
|
117
130
|
const url = `${config.baseUrl}${path}`;
|
|
118
|
-
const res = await
|
|
131
|
+
const res = await fetchWithRetry(url, {
|
|
119
132
|
...init,
|
|
120
133
|
headers: {
|
|
121
134
|
"x-api-key": config.apiKey,
|
|
@@ -135,7 +148,7 @@ async function apiFetch(config, path, init) {
|
|
|
135
148
|
return res.json();
|
|
136
149
|
}
|
|
137
150
|
async function rawStream(config, path, init) {
|
|
138
|
-
const res = await
|
|
151
|
+
const res = await fetchWithRetry(`${config.baseUrl}${path}`, {
|
|
139
152
|
...init,
|
|
140
153
|
headers: {
|
|
141
154
|
"x-api-key": config.apiKey,
|