graphlit-client 1.0.20260602001 → 1.0.20260603001

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/client.js CHANGED
@@ -11,7 +11,7 @@ import { getServiceType, getModelName, getModelEnum, isAnthropicAdaptiveThinking
11
11
  import { StuckDetector } from "./helpers/stuck-detector.js";
12
12
  import { TurnEvaluator } from "./helpers/turn-evaluator.js";
13
13
  import { TokenBudgetTracker, truncateToolResult, windowToolRounds, estimateTokens, DEFAULT_CONTEXT_STRATEGY, } from "./helpers/context-management.js";
14
- import { ProviderError } from "./types/internal.js";
14
+ import { isRetryableGraphQLTransportError, ProviderError, } from "./types/internal.js";
15
15
  import { UIEventAdapter } from "./streaming/ui-event-adapter.js";
16
16
  import { formatMessagesForOpenAI, formatMessagesForOpenAIResponsesInitialRound, extractInstructionsForOpenAIResponses, extractSystemInstructionParts, buildResponsesFunctionCallOutputItems, formatToolsForOpenAIResponses, formatMessagesForAnthropic, formatMessagesForGoogle, formatMessagesForMistral, formatMessagesForBedrock, } from "./streaming/llm-formatters.js";
17
17
  import { streamWithOpenAIResponses, } from "./streaming/openai-responses.js";
@@ -528,7 +528,9 @@ class Graphlit {
528
528
  }
529
529
  refreshClient() {
530
530
  this.client = undefined;
531
- this.generateToken();
531
+ if (this.jwtSecret) {
532
+ this.generateToken();
533
+ }
532
534
  this.setupApolloClient();
533
535
  }
534
536
  setupApolloClient() {
@@ -548,28 +550,15 @@ class Graphlit {
548
550
  // Check if we should retry this error
549
551
  if (!error)
550
552
  return false;
551
- // Check for network errors
552
- const hasNetworkError = !!error.networkError;
553
- if (!hasNetworkError)
554
- return false;
555
- // Get status code from different possible locations
556
- const statusCode = error.networkError?.statusCode ||
557
- error.networkError?.response?.status ||
558
- error.statusCode;
559
- // Check if status code is retryable
560
- if (statusCode && this.retryConfig.retryableStatusCodes) {
561
- const shouldRetry = this.retryConfig.retryableStatusCodes.includes(statusCode);
562
- // Call onRetry callback if provided
563
- if (shouldRetry &&
564
- this.retryConfig.onRetry &&
565
- _operation.getContext().retryCount !== undefined) {
566
- const attempt = _operation.getContext().retryCount + 1;
567
- this.retryConfig.onRetry(attempt, error, _operation);
568
- }
569
- return shouldRetry;
553
+ const shouldRetry = isRetryableGraphQLTransportError(error, this.retryConfig.retryableStatusCodes);
554
+ // Call onRetry callback if provided
555
+ if (shouldRetry &&
556
+ this.retryConfig.onRetry &&
557
+ _operation.getContext().retryCount !== undefined) {
558
+ const attempt = _operation.getContext().retryCount + 1;
559
+ this.retryConfig.onRetry(attempt, error, _operation);
570
560
  }
571
- // Default: retry on network errors without specific status codes
572
- return true;
561
+ return shouldRetry;
573
562
  },
574
563
  },
575
564
  });
@@ -117,6 +117,19 @@ export declare class ProviderError extends Error {
117
117
  * Used as a catch-all after provider-specific error classification.
118
118
  */
119
119
  export declare function isRetryableServerError(error: any): boolean;
120
+ /**
121
+ * Extract an HTTP status code from common Apollo/network error shapes.
122
+ */
123
+ export declare function getErrorStatusCode(error: any): number | undefined;
124
+ /**
125
+ * Detect retryable GraphQL transport errors from Apollo RetryLink.
126
+ *
127
+ * RetryLink can receive either:
128
+ * - an ApolloError with `networkError`
129
+ * - a raw HttpLink `ServerError` with `statusCode` / `response.status`
130
+ * - a nested network/cause error from undici/fetch
131
+ */
132
+ export declare function isRetryableGraphQLTransportError(error: any, retryableStatusCodes?: number[]): boolean;
120
133
  /**
121
134
  * Detect rate-limit / overloaded errors across providers.
122
135
  */
@@ -37,6 +37,49 @@ export function isRetryableServerError(error) {
37
37
  msg.includes("bad gateway") ||
38
38
  msg.includes("gateway timeout"));
39
39
  }
40
+ /**
41
+ * Extract an HTTP status code from common Apollo/network error shapes.
42
+ */
43
+ export function getErrorStatusCode(error) {
44
+ if (!error || typeof error !== "object")
45
+ return undefined;
46
+ const status = typeof error.status === "number"
47
+ ? error.status
48
+ : typeof error.statusCode === "number"
49
+ ? error.statusCode
50
+ : undefined;
51
+ if (typeof status === "number")
52
+ return status;
53
+ const responseStatus = typeof error.response?.status === "number"
54
+ ? error.response.status
55
+ : undefined;
56
+ if (typeof responseStatus === "number")
57
+ return responseStatus;
58
+ return (getErrorStatusCode(error.networkError) ?? getErrorStatusCode(error.cause));
59
+ }
60
+ /**
61
+ * Detect retryable GraphQL transport errors from Apollo RetryLink.
62
+ *
63
+ * RetryLink can receive either:
64
+ * - an ApolloError with `networkError`
65
+ * - a raw HttpLink `ServerError` with `statusCode` / `response.status`
66
+ * - a nested network/cause error from undici/fetch
67
+ */
68
+ export function isRetryableGraphQLTransportError(error, retryableStatusCodes = [429, 500, 502, 503, 504]) {
69
+ if (!error)
70
+ return false;
71
+ const statusCode = getErrorStatusCode(error);
72
+ if (typeof statusCode === "number") {
73
+ return retryableStatusCodes.includes(statusCode);
74
+ }
75
+ if (Array.isArray(error.graphQLErrors) && error.graphQLErrors.length > 0) {
76
+ return false;
77
+ }
78
+ return (!!error.networkError ||
79
+ isNetworkError(error) ||
80
+ isRetryableServerError(error) ||
81
+ isRetryableGraphQLTransportError(error.cause, retryableStatusCodes));
82
+ }
40
83
  /**
41
84
  * Detect rate-limit / overloaded errors across providers.
42
85
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "graphlit-client",
3
- "version": "1.0.20260602001",
3
+ "version": "1.0.20260603001",
4
4
  "description": "Graphlit API Client for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/client.js",