@umituz/react-native-ai-groq-provider 1.0.23 → 1.0.25
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 +1 -1
- package/src/application/use-cases/chat-session.usecase.ts +19 -9
- package/src/application/use-cases/streaming.usecase.ts +13 -7
- package/src/application/use-cases/structured-generation.usecase.ts +17 -5
- package/src/application/use-cases/text-generation.usecase.ts +4 -3
- package/src/domain/entities/error.types.ts +17 -2
- package/src/index.ts +26 -68
- package/src/infrastructure/http/groq-http-client.ts +68 -12
- package/src/infrastructure/http/streaming-client.ts +135 -84
- package/src/infrastructure/telemetry/TelemetryHooks.ts +40 -23
- package/src/infrastructure/utils/calculation.util.ts +46 -14
- package/src/infrastructure/utils/content-mapper.util.ts +1 -1
- package/src/presentation/hooks/use-groq.hook.ts +14 -22
- package/src/providers/ConfigBuilder.ts +2 -73
- package/src/providers/ProviderFactory.ts +7 -62
- package/src/shared/request-builder.ts +8 -4
- package/src/shared/response-handler.ts +81 -0
- package/src/types/react-native-global.d.ts +12 -0
- package/src/application/use-cases/index.ts +0 -19
- package/src/domain/entities/index.ts +0 -7
- package/src/infrastructure/http/index.ts +0 -7
- package/src/infrastructure/telemetry/index.ts +0 -5
- package/src/infrastructure/utils/async/index.ts +0 -6
- package/src/infrastructure/utils/index.ts +0 -8
- package/src/presentation/hooks/index.ts +0 -7
- package/src/presentation/hooks/useGroq.ts +0 -235
- package/src/presentation/hooks/useOperationManager.ts +0 -119
- package/src/presentation/index.ts +0 -6
- package/src/providers/index.ts +0 -16
- package/src/shared/index.ts +0 -16
|
@@ -1,119 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* useOperationManager Hook
|
|
3
|
-
* Manages async operations with loading, error, and success states
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { useState, useCallback, useRef, useMemo } from "react";
|
|
7
|
-
import { getUserFriendlyError } from "../../infrastructure/utils/error-mapper.util";
|
|
8
|
-
import { telemetry } from "../../infrastructure/telemetry";
|
|
9
|
-
|
|
10
|
-
export interface OperationState<T> {
|
|
11
|
-
isLoading: boolean;
|
|
12
|
-
error: string | null;
|
|
13
|
-
data: T | null;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export interface UseOperationManagerOptions<T> {
|
|
17
|
-
/** Initial data */
|
|
18
|
-
initialData?: T | null;
|
|
19
|
-
/** Callback when operation starts */
|
|
20
|
-
onStart?: () => void;
|
|
21
|
-
/** Callback when operation succeeds */
|
|
22
|
-
onSuccess?: (data: T) => void;
|
|
23
|
-
/** Callback when operation fails */
|
|
24
|
-
onError?: (error: string) => void;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Hook for managing async operations
|
|
29
|
-
* Optimized to prevent unnecessary re-renders
|
|
30
|
-
*/
|
|
31
|
-
export function useOperationManager<T = unknown>(
|
|
32
|
-
options: UseOperationManagerOptions<T> = {}
|
|
33
|
-
) {
|
|
34
|
-
// Memoize options to prevent unnecessary callback recreations
|
|
35
|
-
const stableOptions = useMemo(() => options, [
|
|
36
|
-
options.initialData,
|
|
37
|
-
options.onStart,
|
|
38
|
-
options.onSuccess,
|
|
39
|
-
options.onError,
|
|
40
|
-
]);
|
|
41
|
-
|
|
42
|
-
const [state, setState] = useState<OperationState<T>>({
|
|
43
|
-
isLoading: false,
|
|
44
|
-
error: null,
|
|
45
|
-
data: stableOptions.initialData ?? null,
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
const abortControllerRef = useRef<AbortController | null>(null);
|
|
49
|
-
const operationNameRef = useRef<string>("");
|
|
50
|
-
|
|
51
|
-
const execute = useCallback(
|
|
52
|
-
async <R = T,>(
|
|
53
|
-
operationName: string,
|
|
54
|
-
asyncFn: (signal?: AbortSignal) => Promise<R>,
|
|
55
|
-
config?: { abortPrevious?: boolean }
|
|
56
|
-
): Promise<R> => {
|
|
57
|
-
// Cancel previous operation if configured
|
|
58
|
-
if (config?.abortPrevious && abortControllerRef.current) {
|
|
59
|
-
abortControllerRef.current.abort();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
abortControllerRef.current = new AbortController();
|
|
63
|
-
operationNameRef.current = operationName;
|
|
64
|
-
|
|
65
|
-
setState((prev) => ({ ...prev, isLoading: true, error: null }));
|
|
66
|
-
|
|
67
|
-
telemetry.log(`${operationName}_start`);
|
|
68
|
-
stableOptions.onStart?.();
|
|
69
|
-
|
|
70
|
-
try {
|
|
71
|
-
const result = await asyncFn(abortControllerRef.current.signal);
|
|
72
|
-
|
|
73
|
-
setState((prev) => ({ ...prev, isLoading: false, data: result as unknown as T }));
|
|
74
|
-
stableOptions.onSuccess?.(result as unknown as T);
|
|
75
|
-
telemetry.log(`${operationName}_success`);
|
|
76
|
-
|
|
77
|
-
return result;
|
|
78
|
-
} catch (error) {
|
|
79
|
-
const errorMessage = getUserFriendlyError(error);
|
|
80
|
-
setState((prev) => ({ ...prev, isLoading: false, error: errorMessage }));
|
|
81
|
-
stableOptions.onError?.(errorMessage);
|
|
82
|
-
telemetry.log(`${operationName}_error`, { error: errorMessage });
|
|
83
|
-
throw error;
|
|
84
|
-
} finally {
|
|
85
|
-
abortControllerRef.current = null;
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
[stableOptions]
|
|
89
|
-
);
|
|
90
|
-
|
|
91
|
-
const reset = useCallback(() => {
|
|
92
|
-
if (abortControllerRef.current) {
|
|
93
|
-
abortControllerRef.current.abort();
|
|
94
|
-
abortControllerRef.current = null;
|
|
95
|
-
}
|
|
96
|
-
setState((prev) => ({
|
|
97
|
-
...prev,
|
|
98
|
-
isLoading: false,
|
|
99
|
-
error: null,
|
|
100
|
-
data: stableOptions.initialData ?? null,
|
|
101
|
-
}));
|
|
102
|
-
}, [stableOptions.initialData]);
|
|
103
|
-
|
|
104
|
-
const clearError = useCallback(() => {
|
|
105
|
-
setState((prev) => ({ ...prev, error: null }));
|
|
106
|
-
}, []);
|
|
107
|
-
|
|
108
|
-
const setData = useCallback((data: T | null) => {
|
|
109
|
-
setState((prev) => ({ ...prev, data }));
|
|
110
|
-
}, []);
|
|
111
|
-
|
|
112
|
-
return {
|
|
113
|
-
...state,
|
|
114
|
-
execute,
|
|
115
|
-
reset,
|
|
116
|
-
clearError,
|
|
117
|
-
setData,
|
|
118
|
-
};
|
|
119
|
-
}
|
package/src/providers/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Providers
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
export { ConfigBuilder, GenerationConfigBuilder } from "./ConfigBuilder";
|
|
6
|
-
export {
|
|
7
|
-
providerFactory,
|
|
8
|
-
initializeProvider,
|
|
9
|
-
configureProvider,
|
|
10
|
-
resetProvider,
|
|
11
|
-
} from "./ProviderFactory";
|
|
12
|
-
|
|
13
|
-
export type {
|
|
14
|
-
ProviderConfig,
|
|
15
|
-
ProviderFactoryOptions,
|
|
16
|
-
} from "./ProviderFactory";
|
package/src/shared/index.ts
DELETED
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Shared Utilities
|
|
3
|
-
* Common utilities used across all layers
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
export { logger, LogLevel } from "./logger";
|
|
7
|
-
export type { LogContext } from "./logger";
|
|
8
|
-
|
|
9
|
-
export { Timer } from "./timer";
|
|
10
|
-
export type { TimerResult } from "./timer";
|
|
11
|
-
|
|
12
|
-
export { RequestBuilder } from "./request-builder";
|
|
13
|
-
export type { RequestBuilderOptions } from "./request-builder";
|
|
14
|
-
|
|
15
|
-
export { ResponseHandler } from "./response-handler";
|
|
16
|
-
export type { ResponseHandlerResult } from "./response-handler";
|