@umituz/react-native-ai-groq-provider 1.0.3 → 1.0.4
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/domain/entities/error.types.d.ts +34 -0
- package/dist/domain/entities/error.types.d.ts.map +1 -0
- package/dist/domain/entities/error.types.js +57 -0
- package/dist/domain/entities/error.types.js.map +1 -0
- package/dist/domain/entities/groq.types.d.ts +222 -0
- package/dist/domain/entities/groq.types.d.ts.map +1 -0
- package/dist/domain/entities/groq.types.js +37 -0
- package/dist/domain/entities/groq.types.js.map +1 -0
- package/dist/domain/entities/index.d.ts +7 -0
- package/dist/domain/entities/index.d.ts.map +1 -0
- package/dist/domain/entities/index.js +23 -0
- package/dist/domain/entities/index.js.map +1 -0
- package/dist/domain/entities/models.d.ts +50 -0
- package/dist/domain/entities/models.d.ts.map +1 -0
- package/dist/domain/entities/models.js +178 -0
- package/dist/domain/entities/models.js.map +1 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +73 -0
- package/dist/index.js.map +1 -0
- package/dist/infrastructure/services/ChatSession.d.ts +95 -0
- package/dist/infrastructure/services/ChatSession.d.ts.map +1 -0
- package/dist/infrastructure/services/ChatSession.js +177 -0
- package/dist/infrastructure/services/ChatSession.js.map +1 -0
- package/dist/infrastructure/services/GroqClient.d.ts +52 -0
- package/dist/infrastructure/services/GroqClient.d.ts.map +1 -0
- package/dist/infrastructure/services/GroqClient.js +205 -0
- package/dist/infrastructure/services/GroqClient.js.map +1 -0
- package/dist/infrastructure/services/Streaming.d.ts +27 -0
- package/dist/infrastructure/services/Streaming.d.ts.map +1 -0
- package/dist/infrastructure/services/Streaming.js +84 -0
- package/dist/infrastructure/services/Streaming.js.map +1 -0
- package/dist/infrastructure/services/StructuredText.d.ts +20 -0
- package/dist/infrastructure/services/StructuredText.d.ts.map +1 -0
- package/dist/infrastructure/services/StructuredText.js +122 -0
- package/dist/infrastructure/services/StructuredText.js.map +1 -0
- package/dist/infrastructure/services/TextGeneration.d.ts +18 -0
- package/dist/infrastructure/services/TextGeneration.d.ts.map +1 -0
- package/dist/infrastructure/services/TextGeneration.js +64 -0
- package/dist/infrastructure/services/TextGeneration.js.map +1 -0
- package/dist/infrastructure/services/index.d.ts +9 -0
- package/dist/infrastructure/services/index.d.ts.map +1 -0
- package/dist/infrastructure/services/index.js +24 -0
- package/dist/infrastructure/services/index.js.map +1 -0
- package/dist/infrastructure/telemetry/TelemetryHooks.d.ts +48 -0
- package/dist/infrastructure/telemetry/TelemetryHooks.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/TelemetryHooks.js +70 -0
- package/dist/infrastructure/telemetry/TelemetryHooks.js.map +1 -0
- package/dist/infrastructure/telemetry/index.d.ts +5 -0
- package/dist/infrastructure/telemetry/index.d.ts.map +1 -0
- package/dist/infrastructure/telemetry/index.js +10 -0
- package/dist/infrastructure/telemetry/index.js.map +1 -0
- package/dist/infrastructure/utils/async/execute-state.util.d.ts +27 -0
- package/dist/infrastructure/utils/async/execute-state.util.d.ts.map +1 -0
- package/dist/infrastructure/utils/async/execute-state.util.js +50 -0
- package/dist/infrastructure/utils/async/execute-state.util.js.map +1 -0
- package/dist/infrastructure/utils/async/index.d.ts +6 -0
- package/dist/infrastructure/utils/async/index.d.ts.map +1 -0
- package/dist/infrastructure/utils/async/index.js +10 -0
- package/dist/infrastructure/utils/async/index.js.map +1 -0
- package/dist/infrastructure/utils/content-mapper.util.d.ts +34 -0
- package/dist/infrastructure/utils/content-mapper.util.d.ts.map +1 -0
- package/dist/infrastructure/utils/content-mapper.util.js +84 -0
- package/dist/infrastructure/utils/content-mapper.util.js.map +1 -0
- package/dist/infrastructure/utils/error-mapper.util.d.ts +21 -0
- package/dist/infrastructure/utils/error-mapper.util.d.ts.map +1 -0
- package/dist/infrastructure/utils/error-mapper.util.js +73 -0
- package/dist/infrastructure/utils/error-mapper.util.js.map +1 -0
- package/dist/infrastructure/utils/index.d.ts +7 -0
- package/dist/infrastructure/utils/index.d.ts.map +1 -0
- package/dist/infrastructure/utils/index.js +23 -0
- package/dist/infrastructure/utils/index.js.map +1 -0
- package/dist/presentation/hooks/useGroq.d.ts +42 -0
- package/dist/presentation/hooks/useGroq.d.ts.map +1 -0
- package/dist/presentation/hooks/useGroq.js +153 -0
- package/dist/presentation/hooks/useGroq.js.map +1 -0
- package/dist/presentation/hooks/useOperationManager.d.ts +34 -0
- package/dist/presentation/hooks/useOperationManager.d.ts.map +1 -0
- package/dist/presentation/hooks/useOperationManager.js +76 -0
- package/dist/presentation/hooks/useOperationManager.js.map +1 -0
- package/dist/providers/ConfigBuilder.d.ts +86 -0
- package/dist/providers/ConfigBuilder.d.ts.map +1 -0
- package/dist/providers/ConfigBuilder.js +147 -0
- package/dist/providers/ConfigBuilder.js.map +1 -0
- package/dist/providers/ProviderFactory.d.ts +56 -0
- package/dist/providers/ProviderFactory.d.ts.map +1 -0
- package/dist/providers/ProviderFactory.js +75 -0
- package/dist/providers/ProviderFactory.js.map +1 -0
- package/dist/providers/index.d.ts +7 -0
- package/dist/providers/index.d.ts.map +1 -0
- package/dist/providers/index.js +15 -0
- package/dist/providers/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Async State Utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.executeWithState = executeWithState;
|
|
7
|
+
exports.executeWithRetry = executeWithRetry;
|
|
8
|
+
/**
|
|
9
|
+
* Execute async function with state management
|
|
10
|
+
*/
|
|
11
|
+
async function executeWithState(setters, asyncFn, callbacks) {
|
|
12
|
+
const { setLoading, setError, setData } = setters;
|
|
13
|
+
try {
|
|
14
|
+
setLoading(true);
|
|
15
|
+
setError(null);
|
|
16
|
+
const result = await asyncFn();
|
|
17
|
+
setData?.(result);
|
|
18
|
+
callbacks?.onSuccess?.(result);
|
|
19
|
+
return result;
|
|
20
|
+
}
|
|
21
|
+
catch (error) {
|
|
22
|
+
const errorMessage = error instanceof Error ? error.message : "Unknown error";
|
|
23
|
+
setError(errorMessage);
|
|
24
|
+
callbacks?.onError?.(error);
|
|
25
|
+
throw error;
|
|
26
|
+
}
|
|
27
|
+
finally {
|
|
28
|
+
setLoading(false);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Execute async function with retry logic
|
|
33
|
+
*/
|
|
34
|
+
async function executeWithRetry(asyncFn, maxRetries = 3, delayMs = 1000) {
|
|
35
|
+
let lastError = null;
|
|
36
|
+
for (let attempt = 0; attempt < maxRetries; attempt++) {
|
|
37
|
+
try {
|
|
38
|
+
return await asyncFn();
|
|
39
|
+
}
|
|
40
|
+
catch (error) {
|
|
41
|
+
lastError = error;
|
|
42
|
+
if (attempt < maxRetries - 1) {
|
|
43
|
+
// Wait before retrying with exponential backoff
|
|
44
|
+
await new Promise((resolve) => setTimeout(resolve, delayMs * Math.pow(2, attempt)));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
throw lastError;
|
|
49
|
+
}
|
|
50
|
+
//# sourceMappingURL=execute-state.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"execute-state.util.js","sourceRoot":"","sources":["../../../../src/infrastructure/utils/async/execute-state.util.ts"],"names":[],"mappings":";AAAA;;GAEG;;AAsBH,4CAyBC;AAKD,4CAqBC;AAtDD;;GAEG;AACI,KAAK,UAAU,gBAAgB,CACpC,OAA6B,EAC7B,OAAyB,EACzB,SAA6B;IAE7B,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,OAAO,CAAC;IAElD,IAAI,CAAC;QACH,UAAU,CAAC,IAAI,CAAC,CAAC;QACjB,QAAQ,CAAC,IAAI,CAAC,CAAC;QAEf,MAAM,MAAM,GAAG,MAAM,OAAO,EAAE,CAAC;QAE/B,OAAO,E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AEH,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,sBAAsB,CAAC;AAC1E,YAAY,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Async utilities
|
|
4
|
+
*/
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.executeWithRetry = exports.executeWithState = void 0;
|
|
7
|
+
var execute_state_util_1 = require("./execute-state.util");
|
|
8
|
+
Object.defineProperty(exports, "executeWithState", { enumerable: true, get: function () { return execute_state_util_1.executeWithState; } });
|
|
9
|
+
Object.defineProperty(exports, "executeWithRetry", { enumerable: true, get: function () { return execute_state_util_1.executeWithRetry; } });
|
|
10
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/infrastructure/utils/async/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,2DAA0E;AAAjE,sHAAA,gBAAgB,OAAA;AAAE,sHAAA,gBAAgB,OAAA"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Content Mapper Utility
|
|
3
|
+
* Utilities for working with message content
|
|
4
|
+
*/
|
|
5
|
+
import type { GroqMessage } from "../../domain/entities";
|
|
6
|
+
/**
|
|
7
|
+
* Create a user message
|
|
8
|
+
*/
|
|
9
|
+
export declare function createUserMessage(content: string): GroqMessage;
|
|
10
|
+
/**
|
|
11
|
+
* Create an assistant message
|
|
12
|
+
*/
|
|
13
|
+
export declare function createAssistantMessage(content: string): GroqMessage;
|
|
14
|
+
/**
|
|
15
|
+
* Create a system message
|
|
16
|
+
*/
|
|
17
|
+
export declare function createSystemMessage(content: string): GroqMessage;
|
|
18
|
+
/**
|
|
19
|
+
* Create a text message (defaults to user role)
|
|
20
|
+
*/
|
|
21
|
+
export declare function createTextMessage(content: string, role?: "user" | "assistant" | "system"): GroqMessage;
|
|
22
|
+
/**
|
|
23
|
+
* Convert a simple prompt string to an array of messages
|
|
24
|
+
*/
|
|
25
|
+
export declare function promptToMessages(prompt: string, systemPrompt?: string): GroqMessage[];
|
|
26
|
+
/**
|
|
27
|
+
* Extract text content from an array of messages
|
|
28
|
+
*/
|
|
29
|
+
export declare function extractTextFromMessages(messages: GroqMessage[]): string;
|
|
30
|
+
/**
|
|
31
|
+
* Format messages for display in UI
|
|
32
|
+
*/
|
|
33
|
+
export declare function formatMessagesForDisplay(messages: GroqMessage[]): string;
|
|
34
|
+
//# sourceMappingURL=content-mapper.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-mapper.util.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/utils/content-mapper.util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAEzD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAK9D;AAED;;GAEG;AACH,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAKnE;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,MAAM,GAAG,WAAW,CAKhE;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,GAAE,MAAM,GAAG,WAAW,GAAG,QAAiB,GAAG,WAAW,CAK9G;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,EAAE,YAAY,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE,CAgBrF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAEvE;AAED;;GAEG;AACH,wBAAgB,wBAAwB,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,MAAM,CAOxE"}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Content Mapper Utility
|
|
4
|
+
* Utilities for working with message content
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.createUserMessage = createUserMessage;
|
|
8
|
+
exports.createAssistantMessage = createAssistantMessage;
|
|
9
|
+
exports.createSystemMessage = createSystemMessage;
|
|
10
|
+
exports.createTextMessage = createTextMessage;
|
|
11
|
+
exports.promptToMessages = promptToMessages;
|
|
12
|
+
exports.extractTextFromMessages = extractTextFromMessages;
|
|
13
|
+
exports.formatMessagesForDisplay = formatMessagesForDisplay;
|
|
14
|
+
/**
|
|
15
|
+
* Create a user message
|
|
16
|
+
*/
|
|
17
|
+
function createUserMessage(content) {
|
|
18
|
+
return {
|
|
19
|
+
role: "user",
|
|
20
|
+
content,
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Create an assistant message
|
|
25
|
+
*/
|
|
26
|
+
function createAssistantMessage(content) {
|
|
27
|
+
return {
|
|
28
|
+
role: "assistant",
|
|
29
|
+
content,
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Create a system message
|
|
34
|
+
*/
|
|
35
|
+
function createSystemMessage(content) {
|
|
36
|
+
return {
|
|
37
|
+
role: "system",
|
|
38
|
+
content,
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a text message (defaults to user role)
|
|
43
|
+
*/
|
|
44
|
+
function createTextMessage(content, role = "user") {
|
|
45
|
+
return {
|
|
46
|
+
role,
|
|
47
|
+
content,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Convert a simple prompt string to an array of messages
|
|
52
|
+
*/
|
|
53
|
+
function promptToMessages(prompt, systemPrompt) {
|
|
54
|
+
const messages = [];
|
|
55
|
+
if (systemPrompt) {
|
|
56
|
+
messages.push({
|
|
57
|
+
role: "system",
|
|
58
|
+
content: systemPrompt,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
messages.push({
|
|
62
|
+
role: "user",
|
|
63
|
+
content: prompt,
|
|
64
|
+
});
|
|
65
|
+
return messages;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Extract text content from an array of messages
|
|
69
|
+
*/
|
|
70
|
+
function extractTextFromMessages(messages) {
|
|
71
|
+
return messages.map((m) => `[${m.role}]: ${m.content}`).join("\n\n");
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Format messages for display in UI
|
|
75
|
+
*/
|
|
76
|
+
function formatMessagesForDisplay(messages) {
|
|
77
|
+
return messages
|
|
78
|
+
.map((m) => {
|
|
79
|
+
const role = m.role === "system" ? "System" : m.role === "user" ? "You" : "Assistant";
|
|
80
|
+
return `${role}:\n${m.content}`;
|
|
81
|
+
})
|
|
82
|
+
.join("\n\n---\n\n");
|
|
83
|
+
}
|
|
84
|
+
//# sourceMappingURL=content-mapper.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"content-mapper.util.js","sourceRoot":"","sources":["../../../src/infrastructure/utils/content-mapper.util.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAOH,8CAKC;AAKD,wDAKC;AAKD,kDAKC;AAKD,8CAKC;AAKD,4CAgBC;AAKD,0DAEC;AAKD,4DAOC;AA9ED;;GAEG;AACH,SAAgB,iBAAiB,CAAC,OAAe;IAC/C,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,sBAAsB,CAAC,OAAe;IACpD,OAAO;QACL,IAAI,EAAE,WAAW;QACjB,OAAO;KACR,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,SAAgB,mBAAmB,CAAC,OAAe;IACjD,OAAO;QACL,IAAI,EA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Error Mapper Utility
|
|
3
|
+
* Utilities for handling and mapping errors
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* Get user-friendly error message
|
|
7
|
+
*/
|
|
8
|
+
export declare function getUserFriendlyError(error: unknown): string;
|
|
9
|
+
/**
|
|
10
|
+
* Check if error is retryable
|
|
11
|
+
*/
|
|
12
|
+
export declare function isRetryableError(error: unknown): boolean;
|
|
13
|
+
/**
|
|
14
|
+
* Check if error is authentication related
|
|
15
|
+
*/
|
|
16
|
+
export declare function isAuthError(error: unknown): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Format error for logging
|
|
19
|
+
*/
|
|
20
|
+
export declare function formatErrorForLogging(error: unknown): string;
|
|
21
|
+
//# sourceMappingURL=error-mapper.util.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-mapper.util.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/utils/error-mapper.util.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CA2B3D;AAED;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CASxD;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAKnD;AAED;;GAEG;AACH,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,OAAO,GAAG,MAAM,CAU5D"}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Error Mapper Utility
|
|
4
|
+
* Utilities for handling and mapping errors
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.getUserFriendlyError = getUserFriendlyError;
|
|
8
|
+
exports.isRetryableError = isRetryableError;
|
|
9
|
+
exports.isAuthError = isAuthError;
|
|
10
|
+
exports.formatErrorForLogging = formatErrorForLogging;
|
|
11
|
+
const error_types_1 = require("../../domain/entities/error.types");
|
|
12
|
+
/**
|
|
13
|
+
* Get user-friendly error message
|
|
14
|
+
*/
|
|
15
|
+
function getUserFriendlyError(error) {
|
|
16
|
+
if (error instanceof error_types_1.GroqError) {
|
|
17
|
+
switch (error.type) {
|
|
18
|
+
case error_types_1.GroqErrorType.INVALID_API_KEY:
|
|
19
|
+
return "Invalid API key. Please check your Groq API credentials.";
|
|
20
|
+
case error_types_1.GroqErrorType.MISSING_CONFIG:
|
|
21
|
+
return "Configuration missing. Please initialize the Groq provider.";
|
|
22
|
+
case error_types_1.GroqErrorType.NETWORK_ERROR:
|
|
23
|
+
return "Network error. Please check your internet connection.";
|
|
24
|
+
case error_types_1.GroqErrorType.ABORT_ERROR:
|
|
25
|
+
return "Request was cancelled.";
|
|
26
|
+
case error_types_1.GroqErrorType.RATE_LIMIT_ERROR:
|
|
27
|
+
return "Rate limit exceeded. Please wait a moment and try again.";
|
|
28
|
+
case error_types_1.GroqErrorType.QUOTA_EXCEEDED:
|
|
29
|
+
return "API quota exceeded. Please check your Groq account.";
|
|
30
|
+
case error_types_1.GroqErrorType.SERVER_ERROR:
|
|
31
|
+
return "Groq server error. Please try again later.";
|
|
32
|
+
default:
|
|
33
|
+
return error.message || "An unknown error occurred.";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
if (error instanceof Error) {
|
|
37
|
+
return error.message;
|
|
38
|
+
}
|
|
39
|
+
return "An unknown error occurred.";
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Check if error is retryable
|
|
43
|
+
*/
|
|
44
|
+
function isRetryableError(error) {
|
|
45
|
+
if (error instanceof error_types_1.GroqError) {
|
|
46
|
+
return (error.type === error_types_1.GroqErrorType.RATE_LIMIT_ERROR ||
|
|
47
|
+
error.type === error_types_1.GroqErrorType.SERVER_ERROR ||
|
|
48
|
+
error.type === error_types_1.GroqErrorType.NETWORK_ERROR);
|
|
49
|
+
}
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Check if error is authentication related
|
|
54
|
+
*/
|
|
55
|
+
function isAuthError(error) {
|
|
56
|
+
if (error instanceof error_types_1.GroqError) {
|
|
57
|
+
return error.type === error_types_1.GroqErrorType.INVALID_API_KEY;
|
|
58
|
+
}
|
|
59
|
+
return false;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Format error for logging
|
|
63
|
+
*/
|
|
64
|
+
function formatErrorForLogging(error) {
|
|
65
|
+
if (error instanceof error_types_1.GroqError) {
|
|
66
|
+
return `[GroqError:${error.type}] ${error.message}`;
|
|
67
|
+
}
|
|
68
|
+
if (error instanceof Error) {
|
|
69
|
+
return `[${error.name}] ${error.message}`;
|
|
70
|
+
}
|
|
71
|
+
return String(error);
|
|
72
|
+
}
|
|
73
|
+
//# sourceMappingURL=error-mapper.util.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"error-mapper.util.js","sourceRoot":"","sources":["../../../src/infrastructure/utils/error-mapper.util.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAOH,oDA2BC;AAKD,4CASC;AAKD,kCAKC;AAKD,sDAUC;AAvED,mEAA6E;AAE7E;;GAEG;AACH,SAAgB,oBAAoB,CAAC,KAAc;IACjD,IAAI,KAAK,YAAY,uBAAS,EAAE,CAAC;QAC/B,QAAQ,KAAK,CAAC,IAAI,EAAE,CAAC;YACnB,KAAK,2BAAa,CAAC,eAAe;gBAChC,OAAO,0DAA0D,CAAC;YACpE,KAAK,2BAAa,CAAC,cAAc;gBAC/B,OAAO,6DAA6D,CAAC;YACvE,KAAK,2BAAa,CAAC,aAAa;gBAC9B,OAAO,uDAAuD,CAAC;YACjE,KAAK,2BAAa,CAAC,WAAW;gBAC5B,OAAO,wBAAwB,CAAC;YAClC,KAAK,2BAAa,CAAC,gBAAgB;gBACjC,OAAO,0DAA0D,CAAC;YACpE,KAAK,2BAAa,CAAC,cAAc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../../../src/infrastructure/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,cAAc,uBAAuB,CAAC;AACtC,cAAc,qBAAqB,CAAC;AACpC,cAAc,SAAS,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Infrastructure Utilities
|
|
4
|
+
*/
|
|
5
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
6
|
+
if (k2 === undefined) k2 = k;
|
|
7
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
8
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
9
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
10
|
+
}
|
|
11
|
+
Object.defineProperty(o, k2, desc);
|
|
12
|
+
}) : (function(o, m, k, k2) {
|
|
13
|
+
if (k2 === undefined) k2 = k;
|
|
14
|
+
o[k2] = m[k];
|
|
15
|
+
}));
|
|
16
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
17
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
18
|
+
};
|
|
19
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
20
|
+
__exportStar(require("./content-mapper.util"), exports);
|
|
21
|
+
__exportStar(require("./error-mapper.util"), exports);
|
|
22
|
+
__exportStar(require("./async"), exports);
|
|
23
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/infrastructure/utils/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;;;;;;;;;;;;;;AAEH,wDAAsC;AACtC,sDAAoC;AACpC,0CAAwB"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useGroq Hook
|
|
3
|
+
* Main React hook for Groq text generation
|
|
4
|
+
*/
|
|
5
|
+
import type { GroqGenerationConfig } from "../../domain/entities";
|
|
6
|
+
export interface UseGroqOptions {
|
|
7
|
+
/** Initial model to use */
|
|
8
|
+
model?: string;
|
|
9
|
+
/** Default generation config */
|
|
10
|
+
generationConfig?: GroqGenerationConfig;
|
|
11
|
+
/** Callback when generation starts */
|
|
12
|
+
onStart?: () => void;
|
|
13
|
+
/** Callback when generation completes */
|
|
14
|
+
onSuccess?: (result: string) => void;
|
|
15
|
+
/** Callback when generation fails */
|
|
16
|
+
onError?: (error: string) => void;
|
|
17
|
+
}
|
|
18
|
+
export interface UseGroqReturn {
|
|
19
|
+
/** Loading state */
|
|
20
|
+
isLoading: boolean;
|
|
21
|
+
/** Error message */
|
|
22
|
+
error: string | null;
|
|
23
|
+
/** Generated result */
|
|
24
|
+
result: string | null;
|
|
25
|
+
/** Generate text from a prompt */
|
|
26
|
+
generate: (prompt: string, options?: GroqGenerationConfig) => Promise<string>;
|
|
27
|
+
/** Generate structured JSON output */
|
|
28
|
+
generateJSON: <T = Record<string, unknown>>(prompt: string, options?: GroqGenerationConfig & {
|
|
29
|
+
schema?: Record<string, unknown>;
|
|
30
|
+
}) => Promise<T>;
|
|
31
|
+
/** Stream text generation */
|
|
32
|
+
stream: (prompt: string, onChunk: (chunk: string) => void, options?: GroqGenerationConfig) => Promise<void>;
|
|
33
|
+
/** Reset state */
|
|
34
|
+
reset: () => void;
|
|
35
|
+
/** Clear error */
|
|
36
|
+
clearError: () => void;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Hook for Groq text generation
|
|
40
|
+
*/
|
|
41
|
+
export declare function useGroq(options?: UseGroqOptions): UseGroqReturn;
|
|
42
|
+
//# sourceMappingURL=useGroq.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGroq.d.ts","sourceRoot":"","sources":["../../../src/presentation/hooks/useGroq.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAGH,OAAO,KAAK,EAAE,o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AC;CACxB;AAED;;GAEG;AACH,wBAAgB,OAAO,CAAC,OAAO,GAAE,cAAmB,GAAG,aAAa,CAsKnE"}
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* useGroq Hook
|
|
4
|
+
* Main React hook for Groq text generation
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.useGroq = useGroq;
|
|
8
|
+
const react_1 = require("react");
|
|
9
|
+
const TextGeneration_1 = require("../../infrastructure/services/TextGeneration");
|
|
10
|
+
const StructuredText_1 = require("../../infrastructure/services/StructuredText");
|
|
11
|
+
const Streaming_1 = require("../../infrastructure/services/Streaming");
|
|
12
|
+
const error_mapper_util_1 = require("../../infrastructure/utils/error-mapper.util");
|
|
13
|
+
const telemetry_1 = require("../../infrastructure/telemetry");
|
|
14
|
+
/**
|
|
15
|
+
* Hook for Groq text generation
|
|
16
|
+
*/
|
|
17
|
+
function useGroq(options = {}) {
|
|
18
|
+
const [isLoading, setIsLoading] = (0, react_1.useState)(false);
|
|
19
|
+
const [error, setError] = (0, react_1.useState)(null);
|
|
20
|
+
const [result, setResult] = (0, react_1.useState)(null);
|
|
21
|
+
const abortControllerRef = (0, react_1.useRef)(null);
|
|
22
|
+
const generate = (0, react_1.useCallback)(async (prompt, config) => {
|
|
23
|
+
// Cancel any ongoing request
|
|
24
|
+
if (abortControllerRef.current) {
|
|
25
|
+
abortControllerRef.current.abort();
|
|
26
|
+
}
|
|
27
|
+
abortControllerRef.current = new AbortController();
|
|
28
|
+
setIsLoading(true);
|
|
29
|
+
setError(null);
|
|
30
|
+
setResult(null);
|
|
31
|
+
telemetry_1.telemetry.log("groq_generate_start", { prompt: prompt.substring(0, 100) });
|
|
32
|
+
options.onStart?.();
|
|
33
|
+
try {
|
|
34
|
+
const response = await (0, TextGeneration_1.textGeneration)(prompt, {
|
|
35
|
+
model: options.model,
|
|
36
|
+
generationConfig: { ...options.generationConfig, ...config },
|
|
37
|
+
});
|
|
38
|
+
setResult(response);
|
|
39
|
+
options.onSuccess?.(response);
|
|
40
|
+
telemetry_1.telemetry.log("groq_generate_success", { responseLength: response.length });
|
|
41
|
+
return response;
|
|
42
|
+
}
|
|
43
|
+
catch (err) {
|
|
44
|
+
const errorMessage = (0, error_mapper_util_1.getUserFriendlyError)(err);
|
|
45
|
+
setError(errorMessage);
|
|
46
|
+
options.onError?.(errorMessage);
|
|
47
|
+
telemetry_1.telemetry.log("groq_generate_error", { error: errorMessage });
|
|
48
|
+
throw err;
|
|
49
|
+
}
|
|
50
|
+
finally {
|
|
51
|
+
setIsLoading(false);
|
|
52
|
+
abortControllerRef.current = null;
|
|
53
|
+
}
|
|
54
|
+
}, [options]);
|
|
55
|
+
const generateJSON = (0, react_1.useCallback)(async (prompt, config) => {
|
|
56
|
+
// Cancel any ongoing request
|
|
57
|
+
if (abortControllerRef.current) {
|
|
58
|
+
abortControllerRef.current.abort();
|
|
59
|
+
}
|
|
60
|
+
abortControllerRef.current = new AbortController();
|
|
61
|
+
setIsLoading(true);
|
|
62
|
+
setError(null);
|
|
63
|
+
setResult(null);
|
|
64
|
+
telemetry_1.telemetry.log("groq_generate_json_start", { prompt: prompt.substring(0, 100) });
|
|
65
|
+
options.onStart?.();
|
|
66
|
+
try {
|
|
67
|
+
const response = await (0, StructuredText_1.structuredText)(prompt, {
|
|
68
|
+
model: options.model,
|
|
69
|
+
generationConfig: { ...options.generationConfig, ...config },
|
|
70
|
+
schema: config?.schema,
|
|
71
|
+
});
|
|
72
|
+
setResult(JSON.stringify(response, null, 2));
|
|
73
|
+
options.onSuccess?.(JSON.stringify(response, null, 2));
|
|
74
|
+
telemetry_1.telemetry.log("groq_generate_json_success");
|
|
75
|
+
return response;
|
|
76
|
+
}
|
|
77
|
+
catch (err) {
|
|
78
|
+
const errorMessage = (0, error_mapper_util_1.getUserFriendlyError)(err);
|
|
79
|
+
setError(errorMessage);
|
|
80
|
+
options.onError?.(errorMessage);
|
|
81
|
+
telemetry_1.telemetry.log("groq_generate_json_error", { error: errorMessage });
|
|
82
|
+
throw err;
|
|
83
|
+
}
|
|
84
|
+
finally {
|
|
85
|
+
setIsLoading(false);
|
|
86
|
+
abortControllerRef.current = null;
|
|
87
|
+
}
|
|
88
|
+
}, [options]);
|
|
89
|
+
const stream = (0, react_1.useCallback)(async (prompt, onChunk, config) => {
|
|
90
|
+
// Cancel any ongoing request
|
|
91
|
+
if (abortControllerRef.current) {
|
|
92
|
+
abortControllerRef.current.abort();
|
|
93
|
+
}
|
|
94
|
+
abortControllerRef.current = new AbortController();
|
|
95
|
+
setIsLoading(true);
|
|
96
|
+
setError(null);
|
|
97
|
+
setResult(null);
|
|
98
|
+
let fullContent = "";
|
|
99
|
+
telemetry_1.telemetry.log("groq_stream_start", { prompt: prompt.substring(0, 100) });
|
|
100
|
+
options.onStart?.();
|
|
101
|
+
try {
|
|
102
|
+
for await (const chunk of (0, Streaming_1.streaming)(prompt, {
|
|
103
|
+
model: options.model,
|
|
104
|
+
generationConfig: { ...options.generationConfig, ...config },
|
|
105
|
+
callbacks: {
|
|
106
|
+
onChunk: (c) => {
|
|
107
|
+
fullContent += c;
|
|
108
|
+
onChunk(c);
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
})) {
|
|
112
|
+
// Streamed via callback
|
|
113
|
+
}
|
|
114
|
+
setResult(fullContent);
|
|
115
|
+
options.onSuccess?.(fullContent);
|
|
116
|
+
telemetry_1.telemetry.log("groq_stream_success", { contentLength: fullContent.length });
|
|
117
|
+
}
|
|
118
|
+
catch (err) {
|
|
119
|
+
const errorMessage = (0, error_mapper_util_1.getUserFriendlyError)(err);
|
|
120
|
+
setError(errorMessage);
|
|
121
|
+
options.onError?.(errorMessage);
|
|
122
|
+
telemetry_1.telemetry.log("groq_stream_error", { error: errorMessage });
|
|
123
|
+
throw err;
|
|
124
|
+
}
|
|
125
|
+
finally {
|
|
126
|
+
setIsLoading(false);
|
|
127
|
+
abortControllerRef.current = null;
|
|
128
|
+
}
|
|
129
|
+
}, [options]);
|
|
130
|
+
const reset = (0, react_1.useCallback)(() => {
|
|
131
|
+
if (abortControllerRef.current) {
|
|
132
|
+
abortControllerRef.current.abort();
|
|
133
|
+
abortControllerRef.current = null;
|
|
134
|
+
}
|
|
135
|
+
setIsLoading(false);
|
|
136
|
+
setError(null);
|
|
137
|
+
setResult(null);
|
|
138
|
+
}, []);
|
|
139
|
+
const clearError = (0, react_1.useCallback)(() => {
|
|
140
|
+
setError(null);
|
|
141
|
+
}, []);
|
|
142
|
+
return {
|
|
143
|
+
isLoading,
|
|
144
|
+
error,
|
|
145
|
+
result,
|
|
146
|
+
generate,
|
|
147
|
+
generateJSON,
|
|
148
|
+
stream,
|
|
149
|
+
reset,
|
|
150
|
+
clearError,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
//# sourceMappingURL=useGroq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useGroq.js","sourceRoot":"","sources":["../../../src/presentation/hooks/useGroq.ts"],"names":[],"mappings":";AAAA;;;GAGG;;AAsDH,0BAsKC;AA1ND,iCAAsD;AAItD,iFAA8F;AAC9F,iFAA8E;AAC9E,uEAAoE;AACpE,oFAAoF;AACpF,8DAA2D;AAyC3D;;GAEG;AACH,SAAgB,OAAO,CAAC,UAA0B,EAAE;IAClD,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,IAAA,gBAAQ,EAAC,KAAK,CAAC,CAAC;IAClD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAgB,IAAI,CAAC,CAAC;IACxD,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAA,gBAAQ,EAAgB,IAAI,CAAC,CAAC;IAC1D,MAAM,kBAAkB,GAAG,IAAA,cAAM,EAAyB,IAAI,CAAC,CAAC;IAEhE,MAAM,QAAQ,GAAG,IAAA,mBAAW,EAC1B,KAAK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,CAAC;IAClB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,MAAM,UAAU,GAAG,IAAA,mBAAW,EAAC,GAAG,EAAE;QAClC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO;QACL,SAAS;QACT,KAAK;QACL,MAAM;QACN,QAAQ;QACR,YAAY;QACZ,MAAM;QACN,KAAK;QACL,UAAU;KACX,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* useOperationManager Hook
|
|
3
|
+
* Manages async operations with loading, error, and success states
|
|
4
|
+
*/
|
|
5
|
+
export interface OperationState<T> {
|
|
6
|
+
isLoading: boolean;
|
|
7
|
+
error: string | null;
|
|
8
|
+
data: T | null;
|
|
9
|
+
}
|
|
10
|
+
export interface UseOperationManagerOptions<T> {
|
|
11
|
+
/** Initial data */
|
|
12
|
+
initialData?: T | null;
|
|
13
|
+
/** Callback when operation starts */
|
|
14
|
+
onStart?: () => void;
|
|
15
|
+
/** Callback when operation succeeds */
|
|
16
|
+
onSuccess?: (data: T) => void;
|
|
17
|
+
/** Callback when operation fails */
|
|
18
|
+
onError?: (error: string) => void;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Hook for managing async operations
|
|
22
|
+
*/
|
|
23
|
+
export declare function useOperationManager<T = unknown>(options?: UseOperationManagerOptions<T>): {
|
|
24
|
+
execute: <R = T>(operationName: string, asyncFn: (signal?: AbortSignal) => Promise<R>, config?: {
|
|
25
|
+
abortPrevious?: boolean;
|
|
26
|
+
}) => Promise<R>;
|
|
27
|
+
reset: () => void;
|
|
28
|
+
clearError: () => void;
|
|
29
|
+
setData: (data: T | null) => void;
|
|
30
|
+
isLoading: boolean;
|
|
31
|
+
error: string | null;
|
|
32
|
+
data: T;
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=useOperationManager.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useOperationManager.d.ts","sourceRoot":"","sources":["../../../src/presentation/hooks/useOperationManager.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAMH,MAAM,WAAW,cAAc,CAAC,CAAC;IAC/B,SAAS,EAAE,OAAO,CAAC;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,IAAI,EAAE,CAAC,GAAG,IAAI,CAAC;CAChB;AAED,MAAM,WAAW,0BAA0B,CAAC,CAAC;IAC3C,mBAAmB;IACnB,WAAW,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC;IACvB,qCAAqC;IACrC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB,uCAAuC;IACvC,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,IAAI,CAAC;IAC9B,oCAAoC;IACpC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;CACnC;AAED;;GAEG;AACH,wBAAgB,mBAAmB,CAAC,CAAC,GAAG,OAAO,EAC7C,OAAO,GAAE,0BAA0B,CAAC,CAAC,CAAM;cAYlC,CAAC,qBACS,MAAM,WACZ,CAAC,MAAM,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,CAAC,CAAC,WACpC;QAAE,aAAa,CAAC,EAAE,OAAO,CAAA;KAAE,KACnC,OAAO,CAAC,CAAC,CAAC;;;oBAoDoB,CAAC,GAAG,IAAI;eAxFhC,OAAO;WACX,MAAM,GAAG,IAAI;;EAkGrB"}
|