@oxygen-agent/cli 1.146.1 → 1.160.18

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/README.md CHANGED
@@ -32,6 +32,6 @@ oxygen update
32
32
 
33
33
  `oxygen update` runs `npm install -g @oxygen-agent/cli@latest`, preserves npm prefixes on macOS, Linux, and Windows, and runs npm through `cmd.exe` on Windows.
34
34
 
35
- For product documentation and support, visit https://oxygen-agent.com.
35
+ For product documentation, visit https://oxygen-agent.com/docs. For support, visit https://oxygen-agent.com.
36
36
 
37
- Version: 1.146.1
37
+ Version: 1.160.18
@@ -86,9 +86,10 @@ path, options = {}) {
86
86
  if (!response.ok || !envelope.ok) {
87
87
  const failure = envelope;
88
88
  const responseTraceId = response.headers.get("x-oxygen-trace-id") ?? traceId;
89
+ const details = withRetryAfterDetails(failure.error.details, response);
89
90
  throw new OxygenError(failure.error.code, failure.error.message, {
90
- details: withTraceDetails(failure.error.details, responseTraceId, compatibility, apiUrl),
91
- exitCode: response.status >= 500 ? 1 : 1,
91
+ details: withTraceDetails(details, responseTraceId, compatibility, apiUrl),
92
+ exitCode: 1,
92
93
  });
93
94
  }
94
95
  return envelope.data;
@@ -200,6 +201,43 @@ function readEnvelopeCompatibility(envelope) {
200
201
  }
201
202
  return compatibility;
202
203
  }
204
+ // Surface the server's 429 backoff as a first-class `retry_after_seconds` detail
205
+ // so loop-driving callers can wait the right amount of time instead of dead-
206
+ // reckoning. Prefers a value the API already put in details; otherwise derives
207
+ // it from the RFC 6585 Retry-After header (or reset_at). Non-429 responses and
208
+ // unparseable values pass through untouched.
209
+ function withRetryAfterDetails(details, response) {
210
+ if (response.status !== 429)
211
+ return details;
212
+ const record = details && typeof details === "object" && !Array.isArray(details)
213
+ ? details
214
+ : null;
215
+ if (record && typeof record.retry_after_seconds === "number")
216
+ return details;
217
+ const retryAfterSeconds = retryAfterSecondsFromResponse(response, record);
218
+ if (retryAfterSeconds === null)
219
+ return details;
220
+ if (record)
221
+ return { ...record, retry_after_seconds: retryAfterSeconds };
222
+ if (details === undefined)
223
+ return { retry_after_seconds: retryAfterSeconds };
224
+ return { details, retry_after_seconds: retryAfterSeconds };
225
+ }
226
+ function retryAfterSecondsFromResponse(response, details) {
227
+ const header = response.headers.get("retry-after");
228
+ if (header) {
229
+ const seconds = Number(header);
230
+ if (Number.isFinite(seconds) && seconds >= 0)
231
+ return Math.ceil(seconds);
232
+ }
233
+ const resetAt = details?.reset_at;
234
+ if (typeof resetAt === "string") {
235
+ const resetMs = Date.parse(resetAt);
236
+ if (!Number.isNaN(resetMs))
237
+ return Math.max(0, Math.ceil((resetMs - Date.now()) / 1000));
238
+ }
239
+ return null;
240
+ }
203
241
  function withTraceDetails(details, traceId, compatibility, apiUrl) {
204
242
  const serverVersion = compatibility.version;
205
243
  const fields = {