@umituz/react-native-ai-groq-provider 1.0.3 → 1.0.5

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.
Files changed (96) hide show
  1. package/dist/domain/entities/error.types.d.ts +34 -0
  2. package/dist/domain/entities/error.types.d.ts.map +1 -0
  3. package/dist/domain/entities/error.types.js +57 -0
  4. package/dist/domain/entities/error.types.js.map +1 -0
  5. package/dist/domain/entities/groq.types.d.ts +222 -0
  6. package/dist/domain/entities/groq.types.d.ts.map +1 -0
  7. package/dist/domain/entities/groq.types.js +37 -0
  8. package/dist/domain/entities/groq.types.js.map +1 -0
  9. package/dist/domain/entities/index.d.ts +7 -0
  10. package/dist/domain/entities/index.d.ts.map +1 -0
  11. package/dist/domain/entities/index.js +23 -0
  12. package/dist/domain/entities/index.js.map +1 -0
  13. package/dist/domain/entities/models.d.ts +50 -0
  14. package/dist/domain/entities/models.d.ts.map +1 -0
  15. package/dist/domain/entities/models.js +178 -0
  16. package/dist/domain/entities/models.js.map +1 -0
  17. package/dist/index.d.ts +27 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +73 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/infrastructure/services/ChatSession.d.ts +95 -0
  22. package/dist/infrastructure/services/ChatSession.d.ts.map +1 -0
  23. package/dist/infrastructure/services/ChatSession.js +177 -0
  24. package/dist/infrastructure/services/ChatSession.js.map +1 -0
  25. package/dist/infrastructure/services/GroqClient.d.ts +52 -0
  26. package/dist/infrastructure/services/GroqClient.d.ts.map +1 -0
  27. package/dist/infrastructure/services/GroqClient.js +258 -0
  28. package/dist/infrastructure/services/GroqClient.js.map +1 -0
  29. package/dist/infrastructure/services/Streaming.d.ts +27 -0
  30. package/dist/infrastructure/services/Streaming.d.ts.map +1 -0
  31. package/dist/infrastructure/services/Streaming.js +84 -0
  32. package/dist/infrastructure/services/Streaming.js.map +1 -0
  33. package/dist/infrastructure/services/StructuredText.d.ts +20 -0
  34. package/dist/infrastructure/services/StructuredText.d.ts.map +1 -0
  35. package/dist/infrastructure/services/StructuredText.js +204 -0
  36. package/dist/infrastructure/services/StructuredText.js.map +1 -0
  37. package/dist/infrastructure/services/TextGeneration.d.ts +18 -0
  38. package/dist/infrastructure/services/TextGeneration.d.ts.map +1 -0
  39. package/dist/infrastructure/services/TextGeneration.js +127 -0
  40. package/dist/infrastructure/services/TextGeneration.js.map +1 -0
  41. package/dist/infrastructure/services/index.d.ts +9 -0
  42. package/dist/infrastructure/services/index.d.ts.map +1 -0
  43. package/dist/infrastructure/services/index.js +24 -0
  44. package/dist/infrastructure/services/index.js.map +1 -0
  45. package/dist/infrastructure/telemetry/TelemetryHooks.d.ts +48 -0
  46. package/dist/infrastructure/telemetry/TelemetryHooks.d.ts.map +1 -0
  47. package/dist/infrastructure/telemetry/TelemetryHooks.js +70 -0
  48. package/dist/infrastructure/telemetry/TelemetryHooks.js.map +1 -0
  49. package/dist/infrastructure/telemetry/index.d.ts +5 -0
  50. package/dist/infrastructure/telemetry/index.d.ts.map +1 -0
  51. package/dist/infrastructure/telemetry/index.js +10 -0
  52. package/dist/infrastructure/telemetry/index.js.map +1 -0
  53. package/dist/infrastructure/utils/async/execute-state.util.d.ts +27 -0
  54. package/dist/infrastructure/utils/async/execute-state.util.d.ts.map +1 -0
  55. package/dist/infrastructure/utils/async/execute-state.util.js +50 -0
  56. package/dist/infrastructure/utils/async/execute-state.util.js.map +1 -0
  57. package/dist/infrastructure/utils/async/index.d.ts +6 -0
  58. package/dist/infrastructure/utils/async/index.d.ts.map +1 -0
  59. package/dist/infrastructure/utils/async/index.js +10 -0
  60. package/dist/infrastructure/utils/async/index.js.map +1 -0
  61. package/dist/infrastructure/utils/content-mapper.util.d.ts +34 -0
  62. package/dist/infrastructure/utils/content-mapper.util.d.ts.map +1 -0
  63. package/dist/infrastructure/utils/content-mapper.util.js +84 -0
  64. package/dist/infrastructure/utils/content-mapper.util.js.map +1 -0
  65. package/dist/infrastructure/utils/error-mapper.util.d.ts +21 -0
  66. package/dist/infrastructure/utils/error-mapper.util.d.ts.map +1 -0
  67. package/dist/infrastructure/utils/error-mapper.util.js +73 -0
  68. package/dist/infrastructure/utils/error-mapper.util.js.map +1 -0
  69. package/dist/infrastructure/utils/index.d.ts +7 -0
  70. package/dist/infrastructure/utils/index.d.ts.map +1 -0
  71. package/dist/infrastructure/utils/index.js +23 -0
  72. package/dist/infrastructure/utils/index.js.map +1 -0
  73. package/dist/presentation/hooks/useGroq.d.ts +42 -0
  74. package/dist/presentation/hooks/useGroq.d.ts.map +1 -0
  75. package/dist/presentation/hooks/useGroq.js +153 -0
  76. package/dist/presentation/hooks/useGroq.js.map +1 -0
  77. package/dist/presentation/hooks/useOperationManager.d.ts +34 -0
  78. package/dist/presentation/hooks/useOperationManager.d.ts.map +1 -0
  79. package/dist/presentation/hooks/useOperationManager.js +76 -0
  80. package/dist/presentation/hooks/useOperationManager.js.map +1 -0
  81. package/dist/providers/ConfigBuilder.d.ts +86 -0
  82. package/dist/providers/ConfigBuilder.d.ts.map +1 -0
  83. package/dist/providers/ConfigBuilder.js +147 -0
  84. package/dist/providers/ConfigBuilder.js.map +1 -0
  85. package/dist/providers/ProviderFactory.d.ts +56 -0
  86. package/dist/providers/ProviderFactory.d.ts.map +1 -0
  87. package/dist/providers/ProviderFactory.js +75 -0
  88. package/dist/providers/ProviderFactory.js.map +1 -0
  89. package/dist/providers/index.d.ts +7 -0
  90. package/dist/providers/index.d.ts.map +1 -0
  91. package/dist/providers/index.js +15 -0
  92. package/dist/providers/index.js.map +1 -0
  93. package/package.json +1 -1
  94. package/src/infrastructure/services/GroqClient.ts +61 -1
  95. package/src/infrastructure/services/StructuredText.ts +94 -1
  96. package/src/infrastructure/services/TextGeneration.ts +70 -0
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ /**
3
+ * Configuration Builder
4
+ * Builder pattern for Groq configuration
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.GenerationConfigBuilder = exports.ConfigBuilder = void 0;
8
+ const entities_1 = require("../domain/entities");
9
+ /**
10
+ * Builder for Groq configuration
11
+ */
12
+ class ConfigBuilder {
13
+ constructor() {
14
+ this.config = {};
15
+ }
16
+ /**
17
+ * Set API key
18
+ */
19
+ withApiKey(apiKey) {
20
+ this.config.apiKey = apiKey;
21
+ return this;
22
+ }
23
+ /**
24
+ * Set base URL
25
+ */
26
+ withBaseUrl(baseUrl) {
27
+ this.config.baseUrl = baseUrl;
28
+ return this;
29
+ }
30
+ /**
31
+ * Set timeout
32
+ */
33
+ withTimeout(timeoutMs) {
34
+ this.config.timeoutMs = timeoutMs;
35
+ return this;
36
+ }
37
+ /**
38
+ * Set default text model
39
+ */
40
+ withTextModel(model) {
41
+ this.config.textModel = model;
42
+ return this;
43
+ }
44
+ /**
45
+ * Build configuration
46
+ */
47
+ build() {
48
+ if (!this.config.apiKey) {
49
+ throw new Error("API key is required. Use withApiKey() to set it.");
50
+ }
51
+ return {
52
+ apiKey: this.config.apiKey,
53
+ baseUrl: this.config.baseUrl,
54
+ timeoutMs: this.config.timeoutMs,
55
+ textModel: this.config.textModel || entities_1.DEFAULT_MODELS.TEXT,
56
+ };
57
+ }
58
+ /**
59
+ * Create a new builder instance
60
+ */
61
+ static create() {
62
+ return new ConfigBuilder();
63
+ }
64
+ }
65
+ exports.ConfigBuilder = ConfigBuilder;
66
+ /**
67
+ * Builder for generation configuration
68
+ */
69
+ class GenerationConfigBuilder {
70
+ constructor() {
71
+ this.config = {};
72
+ }
73
+ /**
74
+ * Set temperature
75
+ */
76
+ withTemperature(temperature) {
77
+ this.config.temperature = temperature;
78
+ return this;
79
+ }
80
+ /**
81
+ * Set max tokens
82
+ */
83
+ withMaxTokens(maxTokens) {
84
+ this.config.maxTokens = maxTokens;
85
+ return this;
86
+ }
87
+ /**
88
+ * Set top P
89
+ */
90
+ withTopP(topP) {
91
+ this.config.topP = topP;
92
+ return this;
93
+ }
94
+ /**
95
+ * Set frequency penalty
96
+ */
97
+ withFrequencyPenalty(penalty) {
98
+ this.config.frequencyPenalty = penalty;
99
+ return this;
100
+ }
101
+ /**
102
+ * Set presence penalty
103
+ */
104
+ withPresencePenalty(penalty) {
105
+ this.config.presencePenalty = penalty;
106
+ return this;
107
+ }
108
+ /**
109
+ * Set stop sequences
110
+ */
111
+ withStop(stop) {
112
+ this.config.stop = stop;
113
+ return this;
114
+ }
115
+ /**
116
+ * Build configuration
117
+ */
118
+ build() {
119
+ return { ...this.config };
120
+ }
121
+ /**
122
+ * Create a new builder instance
123
+ */
124
+ static create() {
125
+ return new GenerationConfigBuilder();
126
+ }
127
+ /**
128
+ * Create a balanced configuration
129
+ */
130
+ static balanced() {
131
+ return new GenerationConfigBuilder().withTemperature(0.7);
132
+ }
133
+ /**
134
+ * Create a creative configuration
135
+ */
136
+ static creative() {
137
+ return new GenerationConfigBuilder().withTemperature(1.0);
138
+ }
139
+ /**
140
+ * Create a precise configuration
141
+ */
142
+ static precise() {
143
+ return new GenerationConfigBuilder().withTemperature(0.3);
144
+ }
145
+ }
146
+ exports.GenerationConfigBuilder = GenerationConfigBuilder;
147
+ //# sourceMappingURL=ConfigBuilder.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ConfigBuilder.js","sourceRoot":"","sources":["../../src/providers/ConfigBuilder.ts"],"names":[],"mappings":"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"}
@@ -0,0 +1,56 @@
1
+ /**
2
+ * Provider Factory
3
+ * Factory for creating configured Groq provider instances
4
+ */
5
+ import { ConfigBuilder, GenerationConfigBuilder } from "./ConfigBuilder";
6
+ /**
7
+ * Provider configuration options
8
+ */
9
+ export interface ProviderConfig {
10
+ apiKey: string;
11
+ baseUrl?: string;
12
+ timeoutMs?: number;
13
+ defaultModel?: string;
14
+ }
15
+ /**
16
+ * Provider factory options
17
+ */
18
+ export interface ProviderFactoryOptions {
19
+ enableTelemetry?: boolean;
20
+ onError?: (error: Error) => void;
21
+ }
22
+ /**
23
+ * Initialize Groq provider with configuration
24
+ */
25
+ export declare function initializeProvider(config: ProviderConfig): void;
26
+ /**
27
+ * Provider factory - creates configured provider instances
28
+ */
29
+ export declare const providerFactory: {
30
+ /**
31
+ * Create a new provider instance
32
+ */
33
+ create(config: ProviderConfig): void;
34
+ /**
35
+ * Create provider from environment variables
36
+ */
37
+ fromEnv(): void;
38
+ /**
39
+ * Reset provider (clear configuration)
40
+ */
41
+ reset(): void;
42
+ /**
43
+ * Check if provider is initialized
44
+ */
45
+ isInitialized(): boolean;
46
+ };
47
+ /**
48
+ * Convenience function to initialize provider
49
+ */
50
+ export declare function configureProvider(config: ProviderConfig): void;
51
+ /**
52
+ * Convenience function to reset provider
53
+ */
54
+ export declare function resetProvider(): void;
55
+ export { ConfigBuilder, GenerationConfigBuilder };
56
+ //# sourceMappingURL=ProviderFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderFactory.d.ts","sourceRoot":"","sources":["../../src/providers/ProviderFactory.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAIH,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AAEzE;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAO/D;AAED;;GAEG;AACH,eAAO,MAAM,eAAe;IAC1B;;OAEG;mBACY,cAAc,GAAG,IAAI;IAIpC;;OAEG;eACQ,IAAI;IAcf;;OAEG;aACM,IAAI;IAIb;;OAEG;qBACc,OAAO;CAGzB,CAAC;AAEF;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,cAAc,GAAG,IAAI,CAE9D;AAED;;GAEG;AACH,wBAAgB,aAAa,IAAI,IAAI,CAEpC;AAGD,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,CAAC"}
@@ -0,0 +1,75 @@
1
+ "use strict";
2
+ /**
3
+ * Provider Factory
4
+ * Factory for creating configured Groq provider instances
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.GenerationConfigBuilder = exports.ConfigBuilder = exports.providerFactory = void 0;
8
+ exports.initializeProvider = initializeProvider;
9
+ exports.configureProvider = configureProvider;
10
+ exports.resetProvider = resetProvider;
11
+ const GroqClient_1 = require("../infrastructure/services/GroqClient");
12
+ const ConfigBuilder_1 = require("./ConfigBuilder");
13
+ Object.defineProperty(exports, "ConfigBuilder", { enumerable: true, get: function () { return ConfigBuilder_1.ConfigBuilder; } });
14
+ Object.defineProperty(exports, "GenerationConfigBuilder", { enumerable: true, get: function () { return ConfigBuilder_1.GenerationConfigBuilder; } });
15
+ /**
16
+ * Initialize Groq provider with configuration
17
+ */
18
+ function initializeProvider(config) {
19
+ GroqClient_1.groqHttpClient.initialize({
20
+ apiKey: config.apiKey,
21
+ baseUrl: config.baseUrl,
22
+ timeoutMs: config.timeoutMs,
23
+ textModel: config.defaultModel,
24
+ });
25
+ }
26
+ /**
27
+ * Provider factory - creates configured provider instances
28
+ */
29
+ exports.providerFactory = {
30
+ /**
31
+ * Create a new provider instance
32
+ */
33
+ create(config) {
34
+ initializeProvider(config);
35
+ },
36
+ /**
37
+ * Create provider from environment variables
38
+ */
39
+ fromEnv() {
40
+ const apiKey = process.env.GROQ_API_KEY;
41
+ if (!apiKey) {
42
+ throw new Error("GROQ_API_KEY environment variable is not set");
43
+ }
44
+ initializeProvider({
45
+ apiKey,
46
+ baseUrl: process.env.GROQ_BASE_URL,
47
+ timeoutMs: process.env.GROQ_TIMEOUT_MS ? parseInt(process.env.GROQ_TIMEOUT_MS) : undefined,
48
+ });
49
+ },
50
+ /**
51
+ * Reset provider (clear configuration)
52
+ */
53
+ reset() {
54
+ GroqClient_1.groqHttpClient.reset();
55
+ },
56
+ /**
57
+ * Check if provider is initialized
58
+ */
59
+ isInitialized() {
60
+ return GroqClient_1.groqHttpClient.isInitialized();
61
+ },
62
+ };
63
+ /**
64
+ * Convenience function to initialize provider
65
+ */
66
+ function configureProvider(config) {
67
+ exports.providerFactory.create(config);
68
+ }
69
+ /**
70
+ * Convenience function to reset provider
71
+ */
72
+ function resetProvider() {
73
+ exports.providerFactory.reset();
74
+ }
75
+ //# sourceMappingURL=ProviderFactory.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProviderFactory.js","sourceRoot":"","sources":["../../src/providers/ProviderFactory.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AA2BH,gDAOC;AAgDD,8CAEC;AAKD,sCAEC;AAxFD,sEAAuE;AACvE,mDAAyE;AA0FhE,8FA1FA,6BAAa,OA0FA;AAAE,wGA1FA,uCAAuB,OA0FA;AAtE/C;;GAEG;AACH,SAAgB,kBAAkB,CAAC,MAAsB;IACvD,2BAAc,CAAC,UAAU,CAAC;QACxB,MAAM,EAAE,MAAM,CAAC,MAAM;QACrB,OAAO,EAAE,MAAM,CAAC,OAAO;QACvB,SAAS,EAAE,MAAM,CAAC,SAAS;QAC3B,SAAS,EAAE,MAAM,CAAC,YAAY;KAC/B,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACU,QAAA,eAAe,GAAG;IAC7B;;OAEG;IACH,MAAM,CAAC,MAAsB;QAC3B,kBAAkB,CAAC,MAAM,CAAC,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,OAAO;QACL,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,YAAY,CAAC;QAExC,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,8CAA8C,CAAC,CAAC;QAClE,CAAC;QAED,kBAAkB,CAAC;YACjB,MAAM;YACN,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,aAAa;YAClC,SAAS,EAAE,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,SAAS;SAC3F,CAAC,CAAC;IACL,CAAC;IAED;;OAEG;IACH,KAAK;QACH,2BAAc,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC;IAED;;OAEG;IACH,aAAa;QACX,OAAO,2BAAc,CAAC,aAAa,EAAE,CAAC;IACxC,CAAC;CACF,CAAC;AAEF;;GAEG;AACH,SAAgB,iBAAiB,CAAC,MAAsB;IACtD,uBAAe,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;AACjC,CAAC;AAED;;GAEG;AACH,SAAgB,aAAa;IAC3B,uBAAe,CAAC,KAAK,EAAE,CAAC;AAC1B,CAAC"}
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Providers
3
+ */
4
+ export { ConfigBuilder, GenerationConfigBuilder } from "./ConfigBuilder";
5
+ export { providerFactory, initializeProvider, configureProvider, resetProvider, } from "./ProviderFactory";
6
+ export type { ProviderConfig, ProviderFactoryOptions, } from "./ProviderFactory";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,OAAO,EAAE,aAAa,EAAE,uBAAuB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EACL,eAAe,EACf,kBAAkB,EAClB,iBAAiB,EACjB,aAAa,GACd,MAAM,mBAAmB,CAAC;AAE3B,YAAY,EACV,cAAc,EACd,sBAAsB,GACvB,MAAM,mBAAmB,CAAC"}
@@ -0,0 +1,15 @@
1
+ "use strict";
2
+ /**
3
+ * Providers
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.resetProvider = exports.configureProvider = exports.initializeProvider = exports.providerFactory = exports.GenerationConfigBuilder = exports.ConfigBuilder = void 0;
7
+ var ConfigBuilder_1 = require("./ConfigBuilder");
8
+ Object.defineProperty(exports, "ConfigBuilder", { enumerable: true, get: function () { return ConfigBuilder_1.ConfigBuilder; } });
9
+ Object.defineProperty(exports, "GenerationConfigBuilder", { enumerable: true, get: function () { return ConfigBuilder_1.GenerationConfigBuilder; } });
10
+ var ProviderFactory_1 = require("./ProviderFactory");
11
+ Object.defineProperty(exports, "providerFactory", { enumerable: true, get: function () { return ProviderFactory_1.providerFactory; } });
12
+ Object.defineProperty(exports, "initializeProvider", { enumerable: true, get: function () { return ProviderFactory_1.initializeProvider; } });
13
+ Object.defineProperty(exports, "configureProvider", { enumerable: true, get: function () { return ProviderFactory_1.configureProvider; } });
14
+ Object.defineProperty(exports, "resetProvider", { enumerable: true, get: function () { return ProviderFactory_1.resetProvider; } });
15
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/providers/index.ts"],"names":[],"mappings":";AAAA;;GAEG;;;AAEH,iDAAyE;AAAhE,8GAAA,aAAa,OAAA;AAAE,wHAAA,uBAAuB,OAAA;AAC/C,qDAK2B;AAJzB,kHAAA,eAAe,OAAA;AACf,qHAAA,kBAAkB,OAAA;AAClB,oHAAA,iBAAiB,OAAA;AACjB,gHAAA,aAAa,OAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@umituz/react-native-ai-groq-provider",
3
- "version": "1.0.3",
3
+ "version": "1.0.5",
4
4
  "description": "Groq text generation provider for React Native applications",
5
5
  "main": "./src/index.ts",
6
6
  "types": "./dist/index.d.ts",
@@ -25,6 +25,17 @@ class GroqHttpClient {
25
25
  initialize(config: GroqConfig): void {
26
26
  const apiKey = config.apiKey?.trim();
27
27
 
28
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
29
+ console.log("[GroqClient] Initializing:", {
30
+ hasApiKey: !!apiKey,
31
+ keyLength: apiKey?.length,
32
+ keyPrefix: apiKey ? apiKey.substring(0, 10) + "..." : "",
33
+ baseUrl: config.baseUrl || DEFAULT_BASE_URL,
34
+ timeoutMs: config.timeoutMs || DEFAULT_TIMEOUT,
35
+ textModel: config.textModel,
36
+ });
37
+ }
38
+
28
39
  if (!apiKey || apiKey.length < 10) {
29
40
  throw new GroqError(
30
41
  GroqErrorType.INVALID_API_KEY,
@@ -39,6 +50,13 @@ class GroqHttpClient {
39
50
  textModel: config.textModel,
40
51
  };
41
52
  this.initialized = true;
53
+
54
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
55
+ console.log("[GroqClient] Initialization complete:", {
56
+ initialized: this.initialized,
57
+ baseUrl: this.config.baseUrl,
58
+ });
59
+ }
42
60
  }
43
61
 
44
62
  /**
@@ -79,6 +97,17 @@ class GroqHttpClient {
79
97
  const url = `${this.config.baseUrl}${endpoint}`;
80
98
  const timeout = this.config.timeoutMs || DEFAULT_TIMEOUT;
81
99
 
100
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
101
+ console.log("[GroqClient] API Request:", {
102
+ url,
103
+ endpoint,
104
+ method: "POST",
105
+ timeout: `${timeout}ms`,
106
+ hasBody: !!body,
107
+ bodyKeys: body ? Object.keys(body) : [],
108
+ });
109
+ }
110
+
82
111
  try {
83
112
  // Create AbortController for timeout
84
113
  const controller = new AbortController();
@@ -89,6 +118,7 @@ class GroqHttpClient {
89
118
  signal.addEventListener("abort", () => controller.abort());
90
119
  }
91
120
 
121
+ const fetchStartTime = Date.now();
92
122
  const response = await fetch(url, {
93
123
  method: "POST",
94
124
  headers: {
@@ -99,14 +129,44 @@ class GroqHttpClient {
99
129
  signal: controller.signal,
100
130
  });
101
131
 
132
+ const fetchDuration = Date.now() - fetchStartTime;
102
133
  clearTimeout(timeoutId);
103
134
 
135
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
136
+ console.log("[GroqClient] API Response:", {
137
+ status: response.status,
138
+ ok: response.ok,
139
+ fetchDuration: `${fetchDuration}ms`,
140
+ contentType: response.headers.get("content-type"),
141
+ });
142
+ }
143
+
104
144
  if (!response.ok) {
105
145
  await this.handleErrorResponse(response);
106
146
  }
107
147
 
108
- return (await response.json()) as T;
148
+ const jsonStart = Date.now();
149
+ const jsonData = (await response.json()) as T;
150
+ const parseDuration = Date.now() - jsonStart;
151
+
152
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
153
+ console.log("[GroqClient] JSON parsed:", {
154
+ parseDuration: `${parseDuration}ms`,
155
+ hasData: !!jsonData,
156
+ dataKeys: jsonData ? Object.keys(jsonData) : [],
157
+ });
158
+ }
159
+
160
+ return jsonData;
109
161
  } catch (error) {
162
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
163
+ console.error("[GroqClient] Request error:", {
164
+ error,
165
+ errorMessage: error instanceof Error ? error.message : String(error),
166
+ errorName: error instanceof Error ? error.name : undefined,
167
+ });
168
+ }
169
+
110
170
  throw this.handleRequestError(error);
111
171
  }
112
172
  }
@@ -26,8 +26,20 @@ export async function structuredText<T = Record<string, unknown>>(
26
26
  prompt: string,
27
27
  options: StructuredTextOptions<T> = {}
28
28
  ): Promise<T> {
29
+ const startTime = Date.now();
29
30
  const model = options.model || DEFAULT_MODELS.TEXT;
30
31
 
32
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
33
+ console.log("[Groq] structuredText called:", {
34
+ model,
35
+ promptLength: prompt.length,
36
+ promptPreview: prompt.substring(0, 150) + "...",
37
+ hasSchema: !!options.schema,
38
+ hasExample: !!options.example,
39
+ generationConfig: options.generationConfig,
40
+ });
41
+ }
42
+
31
43
  let systemPrompt = "You are a helpful assistant that generates valid JSON output.";
32
44
 
33
45
  if (options.schema) {
@@ -59,7 +71,30 @@ export async function structuredText<T = Record<string, unknown>>(
59
71
  top_p: options.generationConfig?.topP || 0.9,
60
72
  };
61
73
 
74
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
75
+ console.log("[Groq] Sending structured request:", {
76
+ endpoint: "/v1/chat/completions",
77
+ requestBody: {
78
+ model: request.model,
79
+ temperature: request.temperature,
80
+ max_tokens: request.max_tokens,
81
+ top_p: request.top_p,
82
+ },
83
+ });
84
+ }
85
+
86
+ const apiStartTime = Date.now();
62
87
  const response = await groqHttpClient.chatCompletion(request);
88
+ const apiDuration = Date.now() - apiStartTime;
89
+
90
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
91
+ console.log("[Groq] Structured API response:", {
92
+ apiDuration: `${apiDuration}ms`,
93
+ usage: response.usage,
94
+ finishReason: response.choices?.[0]?.finish_reason,
95
+ hasContent: !!response.choices?.[0]?.message?.content,
96
+ });
97
+ }
63
98
 
64
99
  let content = response.choices[0]?.message?.content;
65
100
  if (!content) {
@@ -69,6 +104,13 @@ export async function structuredText<T = Record<string, unknown>>(
69
104
  );
70
105
  }
71
106
 
107
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
108
+ console.log("[Groq] Raw response content:", {
109
+ length: content.length,
110
+ preview: content.substring(0, 300) + "...",
111
+ });
112
+ }
113
+
72
114
  // Clean up the response: remove markdown code blocks if present
73
115
  content = content.trim();
74
116
  if (content.startsWith("```json")) {
@@ -81,9 +123,33 @@ export async function structuredText<T = Record<string, unknown>>(
81
123
  }
82
124
  content = content.trim();
83
125
 
126
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
127
+ console.log("[Groq] Attempting JSON parse...");
128
+ }
129
+
84
130
  try {
85
- return JSON.parse(content) as T;
131
+ const parsed = JSON.parse(content) as T;
132
+ const totalDuration = Date.now() - startTime;
133
+
134
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
135
+ console.log("[Groq] structuredText complete:", {
136
+ totalDuration: `${totalDuration}ms`,
137
+ apiDuration: `${apiDuration}ms`,
138
+ parseDuration: `${totalDuration - apiDuration}ms`,
139
+ parsedKeys: Object.keys(parsed),
140
+ });
141
+ }
142
+
143
+ return parsed;
86
144
  } catch (error) {
145
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
146
+ console.error("[Groq] JSON parse failed:", {
147
+ error,
148
+ contentLength: content.length,
149
+ contentPreview: content.substring(0, 500) + "...",
150
+ });
151
+ }
152
+
87
153
  throw new GroqError(
88
154
  GroqErrorType.UNKNOWN_ERROR,
89
155
  `Failed to parse JSON response: ${content}`,
@@ -99,8 +165,18 @@ export async function structuredChat<T = Record<string, unknown>>(
99
165
  messages: GroqMessage[],
100
166
  options: StructuredTextOptions<T> = {}
101
167
  ): Promise<T> {
168
+ const startTime = Date.now();
102
169
  const model = options.model || DEFAULT_MODELS.TEXT;
103
170
 
171
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
172
+ console.log("[Groq] structuredChat called:", {
173
+ model,
174
+ messageCount: messages.length,
175
+ hasSchema: !!options.schema,
176
+ hasExample: !!options.example,
177
+ });
178
+ }
179
+
104
180
  let systemMessage: GroqMessage | null = null;
105
181
 
106
182
  // Check if there's already a system message
@@ -137,7 +213,16 @@ export async function structuredChat<T = Record<string, unknown>>(
137
213
  top_p: options.generationConfig?.topP || 0.9,
138
214
  };
139
215
 
216
+ const apiStartTime = Date.now();
140
217
  const response = await groqHttpClient.chatCompletion(request);
218
+ const apiDuration = Date.now() - apiStartTime;
219
+
220
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
221
+ console.log("[Groq] structuredChat API response:", {
222
+ apiDuration: `${apiDuration}ms`,
223
+ usage: response.usage,
224
+ });
225
+ }
141
226
 
142
227
  let content = response.choices[0]?.message?.content;
143
228
  if (!content) {
@@ -159,6 +244,14 @@ export async function structuredChat<T = Record<string, unknown>>(
159
244
  }
160
245
  content = content.trim();
161
246
 
247
+ const totalDuration = Date.now() - startTime;
248
+ if (typeof __DEV__ !== "undefined" && __DEV__) {
249
+ console.log("[Groq] structuredChat complete:", {
250
+ totalDuration: `${totalDuration}ms`,
251
+ responseLength: content.length,
252
+ });
253
+ }
254
+
162
255
  try {
163
256
  return JSON.parse(content) as T;
164
257
  } catch (error) {