@credal/sdk 0.1.5 → 0.1.6

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.
Files changed (27) hide show
  1. package/dist/cjs/Client.d.ts +2 -2
  2. package/dist/cjs/Client.js +2 -2
  3. package/dist/cjs/api/resources/copilots/client/Client.d.ts +2 -2
  4. package/dist/cjs/api/resources/documentCatalog/client/Client.d.ts +2 -2
  5. package/dist/cjs/api/resources/documentCatalog/client/requests/UploadDocumentContentsRequest.d.ts +2 -2
  6. package/dist/cjs/api/resources/documentCollections/client/Client.d.ts +2 -2
  7. package/dist/cjs/api/resources/search/client/Client.d.ts +2 -2
  8. package/dist/cjs/api/resources/users/client/Client.d.ts +2 -2
  9. package/dist/cjs/core/fetcher/Fetcher.d.ts +1 -1
  10. package/dist/cjs/core/fetcher/requestWithRetries.js +34 -2
  11. package/dist/cjs/core/headers.d.ts +2 -2
  12. package/dist/cjs/version.d.ts +1 -1
  13. package/dist/cjs/version.js +1 -1
  14. package/dist/esm/Client.d.mts +2 -2
  15. package/dist/esm/Client.mjs +2 -2
  16. package/dist/esm/api/resources/copilots/client/Client.d.mts +2 -2
  17. package/dist/esm/api/resources/documentCatalog/client/Client.d.mts +2 -2
  18. package/dist/esm/api/resources/documentCatalog/client/requests/UploadDocumentContentsRequest.d.mts +2 -2
  19. package/dist/esm/api/resources/documentCollections/client/Client.d.mts +2 -2
  20. package/dist/esm/api/resources/search/client/Client.d.mts +2 -2
  21. package/dist/esm/api/resources/users/client/Client.d.mts +2 -2
  22. package/dist/esm/core/fetcher/Fetcher.d.mts +1 -1
  23. package/dist/esm/core/fetcher/requestWithRetries.mjs +34 -2
  24. package/dist/esm/core/headers.d.mts +2 -2
  25. package/dist/esm/version.d.mts +1 -1
  26. package/dist/esm/version.mjs +1 -1
  27. package/package.json +1 -1
@@ -15,7 +15,7 @@ export declare namespace CredalClient {
15
15
  baseUrl?: core.Supplier<string>;
16
16
  apiKey?: core.Supplier<core.BearerToken | undefined>;
17
17
  /** Additional headers to include in requests. */
18
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
18
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
19
19
  fetcher?: core.FetchFunction;
20
20
  }
21
21
  interface RequestOptions {
@@ -28,7 +28,7 @@ export declare namespace CredalClient {
28
28
  /** Additional query string parameters to include in the request. */
29
29
  queryParams?: Record<string, unknown>;
30
30
  /** Additional headers to include in the request. */
31
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
31
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
32
32
  }
33
33
  }
34
34
  export declare class CredalClient {
@@ -49,8 +49,8 @@ class CredalClient {
49
49
  this._options = Object.assign(Object.assign({}, _options), { headers: (0, headers_js_1.mergeHeaders)({
50
50
  "X-Fern-Language": "JavaScript",
51
51
  "X-Fern-SDK-Name": "@credal/sdk",
52
- "X-Fern-SDK-Version": "0.1.5",
53
- "User-Agent": "@credal/sdk/0.1.5",
52
+ "X-Fern-SDK-Version": "0.1.6",
53
+ "User-Agent": "@credal/sdk/0.1.6",
54
54
  "X-Fern-Runtime": core.RUNTIME.type,
55
55
  "X-Fern-Runtime-Version": core.RUNTIME.version,
56
56
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -11,7 +11,7 @@ export declare namespace Copilots {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Copilots {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Copilots {
@@ -11,7 +11,7 @@ export declare namespace DocumentCatalog {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace DocumentCatalog {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class DocumentCatalog {
@@ -27,12 +27,12 @@ export interface UploadDocumentContentsRequest {
27
27
  documentExternalUrl?: string;
28
28
  /** Optional JSON representing any custom metadata for this document */
29
29
  customMetadata?: Record<string, Credal.CustomMetadataValue>;
30
- /** If specified, the document will also be added to the provided document collection. The document does not immediately start appearing in searches of that collection due to an asynchronous embedding process. To await this process and have this endpoint return only when that embedding process is complete, use the `awaitVectorStoreSync` parameter. */
30
+ /** If specified, the document will also be added to the provided document collection. This operation is eventually consistent, meaning the document does not immediately start appearing in searches of that collection due to an asynchronous embedding process. To achieve strong consistency use the `awaitVectorStoreSync` parameter. */
31
31
  collectionId?: string;
32
32
  /** If specified, document contents will be re-uploaded and re-embedded even if the document already exists in Credal */
33
33
  forceUpdate?: boolean;
34
34
  /** If specified, document will be accessible to everyone within the organization of the uploader */
35
35
  internalPublic?: boolean;
36
- /** If specified, the API will wait for the vector store to be updated before returning. This is useful if you want to ensure that the document is immediately searchable after this call returns. */
36
+ /** Document uploads are eventually consistent by default. If specified `true` the API will wait for the vector store to be updated before returning. This is useful if you want to ensure that the document is immediately searchable after this call returns. */
37
37
  awaitVectorStoreSync?: boolean;
38
38
  }
@@ -11,7 +11,7 @@ export declare namespace DocumentCollections {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace DocumentCollections {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class DocumentCollections {
@@ -11,7 +11,7 @@ export declare namespace Search {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Search {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Search {
@@ -11,7 +11,7 @@ export declare namespace Users {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Users {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Users {
@@ -6,7 +6,7 @@ export declare namespace Fetcher {
6
6
  url: string;
7
7
  method: string;
8
8
  contentType?: string;
9
- headers?: Record<string, string | Supplier<string | undefined> | undefined>;
9
+ headers?: Record<string, string | Supplier<string | null | undefined> | null | undefined>;
10
10
  queryParameters?: Record<string, unknown>;
11
11
  body?: unknown;
12
12
  timeoutMs?: number;
@@ -19,13 +19,45 @@ function addJitter(delay) {
19
19
  const jitterMultiplier = 1 + (Math.random() * 2 - 1) * JITTER_FACTOR;
20
20
  return delay * jitterMultiplier;
21
21
  }
22
+ function getRetryDelayFromHeaders(response, retryAttempt) {
23
+ // Check for Retry-After header first (RFC 7231)
24
+ const retryAfter = response.headers.get("Retry-After");
25
+ if (retryAfter) {
26
+ // Parse as number of seconds...
27
+ const retryAfterSeconds = parseInt(retryAfter, 10);
28
+ if (!isNaN(retryAfterSeconds)) {
29
+ // Convert seconds to milliseconds and cap at MAX_RETRY_DELAY
30
+ return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
31
+ }
32
+ // ...or as an HTTP date; both are valid
33
+ const retryAfterDate = new Date(retryAfter);
34
+ if (!isNaN(retryAfterDate.getTime())) {
35
+ const delay = retryAfterDate.getTime() - Date.now();
36
+ return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
37
+ }
38
+ }
39
+ // Then check for industry-standard X-RateLimit-Reset header
40
+ const rateLimitReset = response.headers.get("X-RateLimit-Reset");
41
+ if (rateLimitReset) {
42
+ const resetTime = parseInt(rateLimitReset, 10);
43
+ if (!isNaN(resetTime)) {
44
+ // Assume Unix timestamp in epoch seconds
45
+ const delay = resetTime * 1000 - Date.now();
46
+ if (delay > 0) {
47
+ return Math.min(delay, MAX_RETRY_DELAY);
48
+ }
49
+ }
50
+ }
51
+ // Fall back to exponential backoff
52
+ return Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY);
53
+ }
22
54
  function requestWithRetries(requestFn_1) {
23
55
  return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
24
56
  let response = yield requestFn();
25
57
  for (let i = 0; i < maxRetries; ++i) {
26
58
  if ([408, 429].includes(response.status) || response.status >= 500) {
27
- // Calculate base delay using exponential backoff (in milliseconds)
28
- const baseDelay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, i), MAX_RETRY_DELAY);
59
+ // Get delay from headers or fall back to exponential backoff
60
+ const baseDelay = getRetryDelayFromHeaders(response, i);
29
61
  // Add jitter to the delay
30
62
  const delayWithJitter = addJitter(baseDelay);
31
63
  yield new Promise((resolve) => setTimeout(resolve, delayWithJitter));
@@ -1,3 +1,3 @@
1
1
  import * as core from "./index.js";
2
- export declare function mergeHeaders(...headersArray: (Record<string, string | core.Supplier<string | undefined> | undefined> | undefined)[]): Record<string, string | core.Supplier<string | undefined>>;
3
- export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | undefined> | undefined> | undefined)[]): Record<string, string | core.Supplier<string | undefined>>;
2
+ export declare function mergeHeaders(...headersArray: (Record<string, string | core.Supplier<string | null | undefined> | null | undefined> | null | undefined)[]): Record<string, string | core.Supplier<string | null | undefined>>;
3
+ export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | null | undefined> | null | undefined> | null | undefined)[]): Record<string, string | core.Supplier<string | null | undefined>>;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.5";
1
+ export declare const SDK_VERSION = "0.1.6";
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDK_VERSION = void 0;
4
- exports.SDK_VERSION = "0.1.5";
4
+ exports.SDK_VERSION = "0.1.6";
@@ -15,7 +15,7 @@ export declare namespace CredalClient {
15
15
  baseUrl?: core.Supplier<string>;
16
16
  apiKey?: core.Supplier<core.BearerToken | undefined>;
17
17
  /** Additional headers to include in requests. */
18
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
18
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
19
19
  fetcher?: core.FetchFunction;
20
20
  }
21
21
  interface RequestOptions {
@@ -28,7 +28,7 @@ export declare namespace CredalClient {
28
28
  /** Additional query string parameters to include in the request. */
29
29
  queryParams?: Record<string, unknown>;
30
30
  /** Additional headers to include in the request. */
31
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
31
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
32
32
  }
33
33
  }
34
34
  export declare class CredalClient {
@@ -13,8 +13,8 @@ export class CredalClient {
13
13
  this._options = Object.assign(Object.assign({}, _options), { headers: mergeHeaders({
14
14
  "X-Fern-Language": "JavaScript",
15
15
  "X-Fern-SDK-Name": "@credal/sdk",
16
- "X-Fern-SDK-Version": "0.1.5",
17
- "User-Agent": "@credal/sdk/0.1.5",
16
+ "X-Fern-SDK-Version": "0.1.6",
17
+ "User-Agent": "@credal/sdk/0.1.6",
18
18
  "X-Fern-Runtime": core.RUNTIME.type,
19
19
  "X-Fern-Runtime-Version": core.RUNTIME.version,
20
20
  }, _options === null || _options === void 0 ? void 0 : _options.headers) });
@@ -11,7 +11,7 @@ export declare namespace Copilots {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Copilots {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Copilots {
@@ -11,7 +11,7 @@ export declare namespace DocumentCatalog {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace DocumentCatalog {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class DocumentCatalog {
@@ -27,12 +27,12 @@ export interface UploadDocumentContentsRequest {
27
27
  documentExternalUrl?: string;
28
28
  /** Optional JSON representing any custom metadata for this document */
29
29
  customMetadata?: Record<string, Credal.CustomMetadataValue>;
30
- /** If specified, the document will also be added to the provided document collection. The document does not immediately start appearing in searches of that collection due to an asynchronous embedding process. To await this process and have this endpoint return only when that embedding process is complete, use the `awaitVectorStoreSync` parameter. */
30
+ /** If specified, the document will also be added to the provided document collection. This operation is eventually consistent, meaning the document does not immediately start appearing in searches of that collection due to an asynchronous embedding process. To achieve strong consistency use the `awaitVectorStoreSync` parameter. */
31
31
  collectionId?: string;
32
32
  /** If specified, document contents will be re-uploaded and re-embedded even if the document already exists in Credal */
33
33
  forceUpdate?: boolean;
34
34
  /** If specified, document will be accessible to everyone within the organization of the uploader */
35
35
  internalPublic?: boolean;
36
- /** If specified, the API will wait for the vector store to be updated before returning. This is useful if you want to ensure that the document is immediately searchable after this call returns. */
36
+ /** Document uploads are eventually consistent by default. If specified `true` the API will wait for the vector store to be updated before returning. This is useful if you want to ensure that the document is immediately searchable after this call returns. */
37
37
  awaitVectorStoreSync?: boolean;
38
38
  }
@@ -11,7 +11,7 @@ export declare namespace DocumentCollections {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace DocumentCollections {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class DocumentCollections {
@@ -11,7 +11,7 @@ export declare namespace Search {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Search {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Search {
@@ -11,7 +11,7 @@ export declare namespace Users {
11
11
  baseUrl?: core.Supplier<string>;
12
12
  apiKey?: core.Supplier<core.BearerToken | undefined>;
13
13
  /** Additional headers to include in requests. */
14
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
14
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
15
15
  fetcher?: core.FetchFunction;
16
16
  }
17
17
  interface RequestOptions {
@@ -24,7 +24,7 @@ export declare namespace Users {
24
24
  /** Additional query string parameters to include in the request. */
25
25
  queryParams?: Record<string, unknown>;
26
26
  /** Additional headers to include in the request. */
27
- headers?: Record<string, string | core.Supplier<string | undefined> | undefined>;
27
+ headers?: Record<string, string | core.Supplier<string | null | undefined> | null | undefined>;
28
28
  }
29
29
  }
30
30
  export declare class Users {
@@ -6,7 +6,7 @@ export declare namespace Fetcher {
6
6
  url: string;
7
7
  method: string;
8
8
  contentType?: string;
9
- headers?: Record<string, string | Supplier<string | undefined> | undefined>;
9
+ headers?: Record<string, string | Supplier<string | null | undefined> | null | undefined>;
10
10
  queryParameters?: Record<string, unknown>;
11
11
  body?: unknown;
12
12
  timeoutMs?: number;
@@ -16,13 +16,45 @@ function addJitter(delay) {
16
16
  const jitterMultiplier = 1 + (Math.random() * 2 - 1) * JITTER_FACTOR;
17
17
  return delay * jitterMultiplier;
18
18
  }
19
+ function getRetryDelayFromHeaders(response, retryAttempt) {
20
+ // Check for Retry-After header first (RFC 7231)
21
+ const retryAfter = response.headers.get("Retry-After");
22
+ if (retryAfter) {
23
+ // Parse as number of seconds...
24
+ const retryAfterSeconds = parseInt(retryAfter, 10);
25
+ if (!isNaN(retryAfterSeconds)) {
26
+ // Convert seconds to milliseconds and cap at MAX_RETRY_DELAY
27
+ return Math.min(retryAfterSeconds * 1000, MAX_RETRY_DELAY);
28
+ }
29
+ // ...or as an HTTP date; both are valid
30
+ const retryAfterDate = new Date(retryAfter);
31
+ if (!isNaN(retryAfterDate.getTime())) {
32
+ const delay = retryAfterDate.getTime() - Date.now();
33
+ return Math.min(Math.max(delay, 0), MAX_RETRY_DELAY);
34
+ }
35
+ }
36
+ // Then check for industry-standard X-RateLimit-Reset header
37
+ const rateLimitReset = response.headers.get("X-RateLimit-Reset");
38
+ if (rateLimitReset) {
39
+ const resetTime = parseInt(rateLimitReset, 10);
40
+ if (!isNaN(resetTime)) {
41
+ // Assume Unix timestamp in epoch seconds
42
+ const delay = resetTime * 1000 - Date.now();
43
+ if (delay > 0) {
44
+ return Math.min(delay, MAX_RETRY_DELAY);
45
+ }
46
+ }
47
+ }
48
+ // Fall back to exponential backoff
49
+ return Math.min(INITIAL_RETRY_DELAY * Math.pow(2, retryAttempt), MAX_RETRY_DELAY);
50
+ }
19
51
  export function requestWithRetries(requestFn_1) {
20
52
  return __awaiter(this, arguments, void 0, function* (requestFn, maxRetries = DEFAULT_MAX_RETRIES) {
21
53
  let response = yield requestFn();
22
54
  for (let i = 0; i < maxRetries; ++i) {
23
55
  if ([408, 429].includes(response.status) || response.status >= 500) {
24
- // Calculate base delay using exponential backoff (in milliseconds)
25
- const baseDelay = Math.min(INITIAL_RETRY_DELAY * Math.pow(2, i), MAX_RETRY_DELAY);
56
+ // Get delay from headers or fall back to exponential backoff
57
+ const baseDelay = getRetryDelayFromHeaders(response, i);
26
58
  // Add jitter to the delay
27
59
  const delayWithJitter = addJitter(baseDelay);
28
60
  yield new Promise((resolve) => setTimeout(resolve, delayWithJitter));
@@ -1,3 +1,3 @@
1
1
  import * as core from "./index.mjs";
2
- export declare function mergeHeaders(...headersArray: (Record<string, string | core.Supplier<string | undefined> | undefined> | undefined)[]): Record<string, string | core.Supplier<string | undefined>>;
3
- export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | undefined> | undefined> | undefined)[]): Record<string, string | core.Supplier<string | undefined>>;
2
+ export declare function mergeHeaders(...headersArray: (Record<string, string | core.Supplier<string | null | undefined> | null | undefined> | null | undefined)[]): Record<string, string | core.Supplier<string | null | undefined>>;
3
+ export declare function mergeOnlyDefinedHeaders(...headersArray: (Record<string, string | core.Supplier<string | null | undefined> | null | undefined> | null | undefined)[]): Record<string, string | core.Supplier<string | null | undefined>>;
@@ -1 +1 @@
1
- export declare const SDK_VERSION = "0.1.5";
1
+ export declare const SDK_VERSION = "0.1.6";
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.1.5";
1
+ export const SDK_VERSION = "0.1.6";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@credal/sdk",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "private": false,
5
5
  "repository": "github:credal-ai/credal-typescript-sdk",
6
6
  "type": "commonjs",