@umituz/web-ai-groq-provider 1.1.6 → 1.1.7

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/web-ai-groq-provider",
3
- "version": "1.1.6",
3
+ "version": "1.1.7",
4
4
  "description": "Groq AI text generation provider for React web applications",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./src/index.ts",
@@ -53,7 +53,7 @@ export function useChat(options: UseChatOptions): UseChatReturn {
53
53
  const loaded = await storage.getMessages(conversationId);
54
54
  setMessages(loaded);
55
55
  } catch (err) {
56
- console.error("[useChat] Failed to load messages:", err);
56
+ // Silently fail - errors are handled through onError callback if needed
57
57
  }
58
58
  };
59
59
 
@@ -68,7 +68,7 @@ export function useChat(options: UseChatOptions): UseChatReturn {
68
68
  try {
69
69
  await storage.saveMessage(conversationId, message);
70
70
  } catch (err) {
71
- console.error("[useChat] Failed to save message:", err);
71
+ // Silently fail - errors are handled through onError callback if needed
72
72
  }
73
73
  },
74
74
  [conversationId, storage, autoSave]
@@ -110,15 +110,40 @@ class TextGenerationService implements IGroqChatService {
110
110
  const request = this.buildRequest(model, messages, options.generationConfig);
111
111
 
112
112
  try {
113
- const response = await groqHttpClient.postChatCompletion({
114
- ...request,
115
- stream: true,
116
- });
117
-
118
- // Note: The actual streaming implementation would need to be handled
119
- // by the streamChatCompletion method returning a ReadableStream
120
- // This is a simplified version
121
- callbacks.onComplete?.(response.choices[0]?.message?.content || "");
113
+ const stream = await groqHttpClient.streamChatCompletion(request);
114
+ const reader = stream.getReader();
115
+ const decoder = new TextDecoder();
116
+ let fullContent = "";
117
+
118
+ while (true) {
119
+ const { done, value } = await reader.read();
120
+ if (done) break;
121
+
122
+ const chunk = decoder.decode(value);
123
+ const lines = chunk.split("\n").filter(line => line.trim() !== "");
124
+
125
+ for (const line of lines) {
126
+ if (line.startsWith("data: ")) {
127
+ const data = line.slice(6);
128
+ if (data === "[DONE]") continue;
129
+
130
+ try {
131
+ const parsed = JSON.parse(data) as {
132
+ choices?: Array<{ delta?: { content?: string } }>;
133
+ };
134
+ const content = parsed.choices?.[0]?.delta?.content;
135
+ if (content) {
136
+ fullContent += content;
137
+ callbacks.onChunk?.(content);
138
+ }
139
+ } catch {
140
+ // Skip invalid JSON chunks
141
+ }
142
+ }
143
+ }
144
+ }
145
+
146
+ callbacks.onComplete?.(fullContent);
122
147
  } catch (error) {
123
148
  callbacks.onError?.(error as Error);
124
149
  throw error;
@@ -31,23 +31,9 @@ export function getUserFriendlyError(error: Error): string {
31
31
  return error.message || "An unexpected error occurred. Please try again.";
32
32
  }
33
33
 
34
- /**
35
- * Check if error is retryable
36
- */
37
- export function isRetryableError(errorType: GroqErrorType): boolean {
38
- return [
39
- GroqErrorType.NETWORK_ERROR,
40
- GroqErrorType.RATE_LIMIT_ERROR,
41
- GroqErrorType.SERVER_ERROR,
42
- ].includes(errorType);
43
- }
44
-
45
- /**
46
- * Check if error is auth-related
47
- */
48
- export function isAuthError(errorType: GroqErrorType): boolean {
49
- return errorType === GroqErrorType.INVALID_API_KEY;
50
- }
34
+ // isRetryableError and isAuthError are exported from ../constants/error.constants.ts
35
+ // Re-export them here for backward compatibility
36
+ export { isRetryableError, isAuthError } from "../constants/error.constants";
51
37
 
52
38
  /**
53
39
  * Format error for logging
package/src/index.ts CHANGED
@@ -5,12 +5,11 @@
5
5
  * @author umituz
6
6
  * @license MIT
7
7
  *
8
- * IMPORTANT: Apps should NOT use this root barrel import.
9
- * Use subpath imports instead:
8
+ * For better tree-shaking, use subpath imports:
10
9
  * - @umituz/web-ai-groq-provider/groq - Groq API client
11
10
  * - @umituz/web-ai-groq-provider/chat - Chat functionality
12
11
  */
13
12
 
14
- // Re-export domains for backward compatibility
13
+ // Re-export all domains
15
14
  export * from "./domains/groq/index";
16
15
  export * from "./domains/chat/index";