graphlit-client 1.0.20250613009 → 1.0.20250615002

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
@@ -66,7 +66,7 @@ await client.streamAgent(
66
66
  }
67
67
  },
68
68
  undefined, // conversationId (optional)
69
- { id: spec.createSpecification.id }, // specification
69
+ { id: spec.createSpecification.id } // specification
70
70
  );
71
71
  ```
72
72
 
@@ -89,6 +89,24 @@ npm install @anthropic-ai/sdk
89
89
 
90
90
  # For Google streaming
91
91
  npm install @google/generative-ai
92
+
93
+ # For Groq streaming (OpenAI-compatible)
94
+ npm install groq-sdk
95
+
96
+ # For Cerebras streaming (uses OpenAI SDK with custom base URL)
97
+ npm install openai
98
+
99
+ # For Cohere streaming
100
+ npm install cohere-ai
101
+
102
+ # For Mistral streaming
103
+ npm install @mistralai/mistralai
104
+
105
+ # For AWS Bedrock streaming (Claude models)
106
+ npm install @aws-sdk/client-bedrock-runtime
107
+
108
+ # For Deepseek streaming (uses OpenAI SDK with custom base URL)
109
+ npm install openai
92
110
  ```
93
111
 
94
112
  ## Setting Up
@@ -104,6 +122,88 @@ GRAPHLIT_JWT_SECRET=your_secret
104
122
  OPENAI_API_KEY=your_key
105
123
  ANTHROPIC_API_KEY=your_key
106
124
  GOOGLE_API_KEY=your_key
125
+ GROQ_API_KEY=your_key
126
+ CEREBRAS_API_KEY=your_key
127
+ COHERE_API_KEY=your_key
128
+ MISTRAL_API_KEY=your_key
129
+
130
+ # For AWS Bedrock (requires AWS credentials)
131
+ AWS_REGION=us-east-2
132
+ AWS_ACCESS_KEY_ID=your_key
133
+ AWS_SECRET_ACCESS_KEY=your_secret
134
+
135
+ # For Deepseek streaming
136
+ DEEPSEEK_API_KEY=your_key
137
+ ```
138
+
139
+ ## Network Resilience (New in v1.1.1)
140
+
141
+ The SDK now includes automatic retry logic for network errors and transient failures:
142
+
143
+ ### Default Retry Configuration
144
+
145
+ By default, the client will automatically retry on these status codes:
146
+ - `429` - Too Many Requests
147
+ - `502` - Bad Gateway
148
+ - `503` - Service Unavailable
149
+ - `504` - Gateway Timeout
150
+
151
+ ```typescript
152
+ const client = new Graphlit(); // Uses default retry configuration
153
+ ```
154
+
155
+ ### Custom Retry Configuration
156
+
157
+ Configure retry behavior to match your needs:
158
+
159
+ ```typescript
160
+ const client = new Graphlit({
161
+ organizationId: "your_org_id",
162
+ environmentId: "your_env_id",
163
+ jwtSecret: "your_secret",
164
+ retryConfig: {
165
+ maxAttempts: 10, // Maximum retry attempts (default: 5)
166
+ initialDelay: 500, // Initial delay in ms (default: 300)
167
+ maxDelay: 60000, // Maximum delay in ms (default: 30000)
168
+ jitter: true, // Add randomness to delays (default: true)
169
+ retryableStatusCodes: [429, 500, 502, 503, 504], // Custom status codes
170
+ onRetry: (attempt, error, operation) => {
171
+ console.log(`Retry attempt ${attempt} for ${operation.operationName}`);
172
+ console.log(`Error: ${error.message}`);
173
+ }
174
+ }
175
+ });
176
+ ```
177
+
178
+ ### Update Retry Configuration at Runtime
179
+
180
+ Change retry behavior on the fly:
181
+
182
+ ```typescript
183
+ // Start with default configuration
184
+ const client = new Graphlit();
185
+
186
+ // Later, update for more aggressive retries
187
+ client.setRetryConfig({
188
+ maxAttempts: 20,
189
+ initialDelay: 100,
190
+ retryableStatusCodes: [429, 500, 502, 503, 504, 521, 522, 524]
191
+ });
192
+ ```
193
+
194
+ ### Disable Retries
195
+
196
+ For testing or specific scenarios:
197
+
198
+ ```typescript
199
+ const client = new Graphlit({
200
+ organizationId: "your_org_id",
201
+ environmentId: "your_env_id",
202
+ jwtSecret: "your_secret",
203
+ retryConfig: {
204
+ maxAttempts: 1 // No retries
205
+ }
206
+ });
107
207
  ```
108
208
 
109
209
  ## Basic Examples
@@ -138,7 +238,7 @@ await client.streamAgent(
138
238
  }
139
239
  },
140
240
  undefined, // conversationId
141
- { id: spec.createSpecification.id }, // specification
241
+ { id: spec.createSpecification.id } // specification
142
242
  );
143
243
  ```
144
244
 
@@ -166,7 +266,7 @@ const content = await client.ingestUri(
166
266
  "https://arxiv.org/pdf/1706.03762.pdf", // Attention Is All You Need paper
167
267
  "AI Research Paper", // name
168
268
  undefined, // id
169
- true, // isSynchronous - waits for processing
269
+ true // isSynchronous - waits for processing
170
270
  );
171
271
 
172
272
  console.log(`✅ Uploaded: ${content.ingestUri.id}`);
@@ -188,7 +288,7 @@ await client.streamAgent(
188
288
  }
189
289
  },
190
290
  conversation.createConversation.id, // conversationId with content filter
191
- { id: spec.createSpecification.id }, // specification
291
+ { id: spec.createSpecification.id } // specification
192
292
  );
193
293
  ```
194
294
 
@@ -202,7 +302,7 @@ const webpage = await client.ingestUri(
202
302
  "https://en.wikipedia.org/wiki/Artificial_intelligence", // uri
203
303
  "AI Wikipedia Page", // name
204
304
  undefined, // id
205
- true, // isSynchronous
305
+ true // isSynchronous
206
306
  );
207
307
 
208
308
  // Wait for content to be indexed
@@ -217,7 +317,7 @@ const conversation = await client.createConversation({
217
317
  const response = await client.promptAgent(
218
318
  "Summarize the key points about AI from this Wikipedia page",
219
319
  conversation.createConversation.id, // conversationId with filter
220
- { id: spec.createSpecification.id }, // specification (create one as shown above)
320
+ { id: spec.createSpecification.id } // specification (create one as shown above)
221
321
  );
222
322
 
223
323
  console.log(response.message);
@@ -280,7 +380,7 @@ await client.streamAgent(
280
380
  undefined, // conversationId
281
381
  { id: spec.createSpecification.id }, // specification
282
382
  [weatherTool], // tools
283
- toolHandlers, // handlers
383
+ toolHandlers // handlers
284
384
  );
285
385
  ```
286
386
 
@@ -325,7 +425,7 @@ class KnowledgeAssistant {
325
425
  url, // uri
326
426
  url.split("/").pop() || "Document", // name
327
427
  undefined, // id
328
- true, // isSynchronous - wait for processing
428
+ true // isSynchronous - wait for processing
329
429
  );
330
430
  this.contentIds.push(content.ingestUri.id);
331
431
  }
@@ -355,7 +455,7 @@ class KnowledgeAssistant {
355
455
  }
356
456
  },
357
457
  this.conversationId, // Maintains conversation context
358
- { id: this.specificationId! }, // specification
458
+ { id: this.specificationId! } // specification
359
459
  );
360
460
  }
361
461
  }
@@ -385,7 +485,7 @@ const document = await client.ingestUri(
385
485
  "https://example.com/document.pdf", // uri
386
486
  "Document #12345", // name
387
487
  undefined, // id
388
- true, // isSynchronous
488
+ true // isSynchronous
389
489
  );
390
490
 
391
491
  // Wait for content to be indexed
@@ -396,7 +496,7 @@ const extraction = await client.extractContents(
396
496
  "Extract the key information from this document",
397
497
  undefined, // tools
398
498
  undefined, // specification
399
- { contents: [{ id: document.ingestUri.id }] }, // filter
499
+ { contents: [{ id: document.ingestUri.id }] } // filter
400
500
  );
401
501
 
402
502
  console.log("Extracted data:", extraction.extractContents);
@@ -415,7 +515,7 @@ for (const url of documentUrls) {
415
515
  url, // uri
416
516
  url.split("/").pop() || "Document", // name
417
517
  undefined, // id
418
- true, // isSynchronous
518
+ true // isSynchronous
419
519
  );
420
520
  ids.push(content.ingestUri.id);
421
521
  }
@@ -428,7 +528,7 @@ const summary = await client.summarizeContents(
428
528
  prompt: "Create an executive summary of these documents",
429
529
  },
430
530
  ], // summarizations
431
- { contents: ids.map((id) => ({ id })) }, // filter
531
+ { contents: ids.map((id) => ({ id })) } // filter
432
532
  );
433
533
 
434
534
  console.log("Summary:", summary.summarizeContents);
@@ -442,13 +542,13 @@ const content = await client.ingestUri(
442
542
  "https://example.com/large-document.pdf", // uri
443
543
  undefined, // name
444
544
  undefined, // id
445
- true, // isSynchronous
545
+ true // isSynchronous
446
546
  );
447
547
  console.log("✅ Content ready!");
448
548
 
449
549
  // Option 2: Asynchronous processing (for large files)
450
550
  const content = await client.ingestUri(
451
- "https://example.com/very-large-video.mp4", // uri
551
+ "https://example.com/very-large-video.mp4" // uri
452
552
  // isSynchronous defaults to false
453
553
  );
454
554
 
@@ -486,7 +586,7 @@ const result = await client.promptAgent(
486
586
  {
487
587
  // Only allow retrieval from specific content
488
588
  contents: [{ id: "content-id-1" }, { id: "content-id-2" }],
489
- },
589
+ }
490
590
  );
491
591
 
492
592
  // Example 2: Streaming with content filter
@@ -507,7 +607,7 @@ await client.streamAgent(
507
607
  {
508
608
  // Filter by collection
509
609
  collections: [{ id: "technical-docs-collection" }],
510
- },
610
+ }
511
611
  );
512
612
  ```
513
613
 
@@ -537,7 +637,7 @@ await client.streamAgent(
537
637
  {
538
638
  // Force this content into context
539
639
  contents: [{ id: fileContent.content.id }],
540
- },
640
+ }
541
641
  );
542
642
  ```
543
643
 
@@ -563,7 +663,7 @@ await client.promptAgent(
563
663
  {
564
664
  // Always include the specific code file
565
665
  contents: [{ id: "implementation-file-id" }],
566
- },
666
+ }
567
667
  );
568
668
  ```
569
669
 
@@ -608,7 +708,7 @@ await client.updateProject({
608
708
 
609
709
  // Now all content will be automatically summarized
610
710
  const content = await client.ingestUri(
611
- "https://example.com/report.pdf", // uri
711
+ "https://example.com/report.pdf" // uri
612
712
  );
613
713
  ```
614
714
 
@@ -641,7 +741,7 @@ await client.streamAgent(
641
741
  }
642
742
  },
643
743
  undefined,
644
- { id: conversationSpec.createSpecification.id },
744
+ { id: conversationSpec.createSpecification.id }
645
745
  );
646
746
  ```
647
747
 
package/dist/client.d.ts CHANGED
@@ -5,6 +5,30 @@ import { AgentOptions, AgentResult, StreamAgentOptions, ToolHandler } from "./ty
5
5
  import { AgentStreamEvent } from "./types/ui-events.js";
6
6
  export type { AgentOptions, AgentResult, StreamAgentOptions, ToolCallResult, UsageInfo, AgentError, } from "./types/agent.js";
7
7
  export type { AgentStreamEvent } from "./types/ui-events.js";
8
+ export interface RetryConfig {
9
+ /** Maximum number of retry attempts (default: 5) */
10
+ maxAttempts?: number;
11
+ /** Initial delay in milliseconds (default: 300) */
12
+ initialDelay?: number;
13
+ /** Maximum delay in milliseconds (default: 30000) */
14
+ maxDelay?: number;
15
+ /** HTTP status codes that should trigger a retry (default: [429, 502, 503, 504]) */
16
+ retryableStatusCodes?: number[];
17
+ /** Whether to use jitter in delay calculation (default: true) */
18
+ jitter?: boolean;
19
+ /** Callback when a retry is attempted */
20
+ onRetry?: (attempt: number, error: any, operation: any) => void;
21
+ }
22
+ export interface GraphlitClientOptions {
23
+ organizationId?: string;
24
+ environmentId?: string;
25
+ jwtSecret?: string;
26
+ ownerId?: string;
27
+ userId?: string;
28
+ apiUri?: string;
29
+ /** Retry configuration for network errors */
30
+ retryConfig?: RetryConfig;
31
+ }
8
32
  declare class Graphlit {
9
33
  client: ApolloClient<NormalizedCacheObject> | undefined;
10
34
  token: string | undefined;
@@ -14,10 +38,17 @@ declare class Graphlit {
14
38
  private ownerId;
15
39
  private userId;
16
40
  private jwtSecret;
41
+ private retryConfig;
17
42
  private openaiClient?;
18
43
  private anthropicClient?;
19
44
  private googleClient?;
20
- constructor(organizationId?: string, environmentId?: string, jwtSecret?: string, ownerId?: string, userId?: string, apiUri?: string);
45
+ private groqClient?;
46
+ private cerebrasClient?;
47
+ private cohereClient?;
48
+ private mistralClient?;
49
+ private bedrockClient?;
50
+ private deepseekClient?;
51
+ constructor(organizationIdOrOptions?: string | GraphlitClientOptions, environmentId?: string, jwtSecret?: string, ownerId?: string, userId?: string, apiUri?: string);
21
52
  refreshClient(): void;
22
53
  /**
23
54
  * Set a custom OpenAI client instance for streaming
@@ -34,6 +65,41 @@ declare class Graphlit {
34
65
  * @param client - Google GenerativeAI client instance (e.g., new GoogleGenerativeAI(apiKey))
35
66
  */
36
67
  setGoogleClient(client: any): void;
68
+ /**
69
+ * Set a custom Groq client instance for streaming
70
+ * @param client - Groq client instance (e.g., new Groq({ apiKey: "..." }))
71
+ */
72
+ setGroqClient(client: any): void;
73
+ /**
74
+ * Set a custom Cerebras client instance for streaming (OpenAI-compatible)
75
+ * @param client - OpenAI client instance configured for Cerebras (e.g., new OpenAI({ apiKey: "...", baseURL: "https://api.cerebras.ai/v1" }))
76
+ */
77
+ setCerebrasClient(client: any): void;
78
+ /**
79
+ * Set a custom Cohere client instance for streaming
80
+ * @param client - Cohere client instance (e.g., new CohereClient({ token: "..." }))
81
+ */
82
+ setCohereClient(client: any): void;
83
+ /**
84
+ * Set a custom Mistral client instance for streaming
85
+ * @param client - Mistral client instance (e.g., new Mistral({ apiKey: "..." }))
86
+ */
87
+ setMistralClient(client: any): void;
88
+ /**
89
+ * Set a custom Bedrock client instance for streaming
90
+ * @param client - BedrockRuntimeClient instance (e.g., new BedrockRuntimeClient({ region: "us-east-2" }))
91
+ */
92
+ setBedrockClient(client: any): void;
93
+ /**
94
+ * Set a custom Deepseek client instance for streaming
95
+ * @param client - OpenAI client instance configured for Deepseek (e.g., new OpenAI({ baseURL: "https://api.deepseek.com", apiKey: "..." }))
96
+ */
97
+ setDeepseekClient(client: any): void;
98
+ /**
99
+ * Update retry configuration and refresh the Apollo client
100
+ * @param retryConfig - New retry configuration
101
+ */
102
+ setRetryConfig(retryConfig: RetryConfig): void;
37
103
  private generateToken;
38
104
  getProject(): Promise<Types.GetProjectQuery>;
39
105
  updateProject(project: Types.ProjectUpdateInput): Promise<Types.UpdateProjectMutation>;
@@ -388,6 +454,30 @@ declare class Graphlit {
388
454
  * Stream with Google client
389
455
  */
390
456
  private streamWithGoogle;
457
+ /**
458
+ * Stream with Groq client (OpenAI-compatible)
459
+ */
460
+ private streamWithGroq;
461
+ /**
462
+ * Stream with Cerebras client (OpenAI-compatible)
463
+ */
464
+ private streamWithCerebras;
465
+ /**
466
+ * Stream with Cohere client
467
+ */
468
+ private streamWithCohere;
469
+ /**
470
+ * Stream with Mistral client
471
+ */
472
+ private streamWithMistral;
473
+ /**
474
+ * Stream with Bedrock client
475
+ */
476
+ private streamWithBedrock;
477
+ /**
478
+ * Stream with Deepseek client
479
+ */
480
+ private streamWithDeepseek;
391
481
  private executeToolsForPromptAgent;
392
482
  private prettyPrintGraphQLError;
393
483
  private mutateAndCheckError;