graphlit-client 1.0.20260601002 → 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";
@@ -382,6 +382,19 @@ function mapAnthropicEffort(effort) {
382
382
  return undefined;
383
383
  }
384
384
  }
385
+ function supportsAnthropicThinkingDisplay(specification) {
386
+ if (specification.serviceType !== Types.ModelServiceTypes.Anthropic) {
387
+ return false;
388
+ }
389
+ const modelName = getModelName(specification);
390
+ if (!modelName) {
391
+ return false;
392
+ }
393
+ return (modelName.startsWith("claude-opus-4") ||
394
+ modelName.startsWith("claude-sonnet-4") ||
395
+ modelName.startsWith("claude-haiku-4") ||
396
+ modelName === "claude-mythos-preview");
397
+ }
385
398
  // Define the Graphlit class
386
399
  class Graphlit {
387
400
  client;
@@ -515,7 +528,9 @@ class Graphlit {
515
528
  }
516
529
  refreshClient() {
517
530
  this.client = undefined;
518
- this.generateToken();
531
+ if (this.jwtSecret) {
532
+ this.generateToken();
533
+ }
519
534
  this.setupApolloClient();
520
535
  }
521
536
  setupApolloClient() {
@@ -535,28 +550,15 @@ class Graphlit {
535
550
  // Check if we should retry this error
536
551
  if (!error)
537
552
  return false;
538
- // Check for network errors
539
- const hasNetworkError = !!error.networkError;
540
- if (!hasNetworkError)
541
- return false;
542
- // Get status code from different possible locations
543
- const statusCode = error.networkError?.statusCode ||
544
- error.networkError?.response?.status ||
545
- error.statusCode;
546
- // Check if status code is retryable
547
- if (statusCode && this.retryConfig.retryableStatusCodes) {
548
- const shouldRetry = this.retryConfig.retryableStatusCodes.includes(statusCode);
549
- // Call onRetry callback if provided
550
- if (shouldRetry &&
551
- this.retryConfig.onRetry &&
552
- _operation.getContext().retryCount !== undefined) {
553
- const attempt = _operation.getContext().retryCount + 1;
554
- this.retryConfig.onRetry(attempt, error, _operation);
555
- }
556
- 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);
557
560
  }
558
- // Default: retry on network errors without specific status codes
559
- return true;
561
+ return shouldRetry;
560
562
  },
561
563
  },
562
564
  });
@@ -8335,16 +8337,21 @@ class Graphlit {
8335
8337
  if (specification.serviceType === Types.ModelServiceTypes.Anthropic) {
8336
8338
  const anthropic = specification.anthropic;
8337
8339
  if (anthropic?.enableThinking) {
8340
+ const display = supportsAnthropicThinkingDisplay(specification)
8341
+ ? "summarized"
8342
+ : undefined;
8338
8343
  // Claude Opus 4.7/4.8 only support adaptive thinking with output_config.effort
8339
8344
  if (isAnthropicAdaptiveThinkingOnlyModel(specification)) {
8340
8345
  return {
8341
8346
  type: "adaptive",
8342
8347
  effort: mapAnthropicEffort(anthropic.effort),
8348
+ display,
8343
8349
  };
8344
8350
  }
8345
8351
  return {
8346
8352
  type: "enabled",
8347
8353
  budget_tokens: anthropic.thinkingTokenLimit || 10000,
8354
+ display,
8348
8355
  };
8349
8356
  }
8350
8357
  }
@@ -19,9 +19,11 @@ export declare function streamWithAnthropic(specification: Specification, messag
19
19
  onEvent: (event: StreamEvent) => void, onComplete: (message: string, toolCalls: ConversationToolCall[], usage?: any, reasoning?: ReasoningMetadata) => void, abortSignal?: AbortSignal, thinkingConfig?: {
20
20
  type: "enabled";
21
21
  budget_tokens: number;
22
+ display?: "summarized";
22
23
  } | {
23
24
  type: "adaptive";
24
25
  effort?: "low" | "medium" | "high" | "xhigh";
26
+ display?: "summarized";
25
27
  }): Promise<void>;
26
28
  /**
27
29
  * Stream with Google SDK
@@ -551,7 +551,9 @@ onEvent, onComplete, abortSignal, thinkingConfig) {
551
551
  if (thinkingConfig) {
552
552
  if (thinkingConfig.type === "adaptive") {
553
553
  // Claude Opus 4.7/4.8: adaptive thinking, effort controls depth via output_config
554
- streamConfig.thinking = { type: "adaptive" };
554
+ streamConfig.thinking = thinkingConfig.display
555
+ ? { type: "adaptive", display: thinkingConfig.display }
556
+ : { type: "adaptive" };
555
557
  if (thinkingConfig.effort) {
556
558
  streamConfig.output_config = { effort: thinkingConfig.effort };
557
559
  }
@@ -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.20260601002",
3
+ "version": "1.0.20260603001",
4
4
  "description": "Graphlit API Client for TypeScript",
5
5
  "type": "module",
6
6
  "main": "./dist/client.js",