@umituz/react-native-ai-groq-provider 1.0.1 → 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.
Files changed (93) 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 +205 -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 +122 -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 +64 -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
@@ -0,0 +1,27 @@
1
+ /**
2
+ * @umituz/react-native-ai-groq-provider
3
+ * Groq text generation provider for React Native applications
4
+ *
5
+ * @author umituz
6
+ * @license MIT
7
+ */
8
+ export type { GroqConfig, GroqGenerationConfig, GroqMessageRole, GroqMessage, GroqChatRequest, GroqChatResponse, GroqChoice, GroqFinishReason, GroqUsage, GroqChatChunk, GroqChunkChoice, GroqErrorResponse, GroqChatConfig, } from "./domain/entities";
9
+ export { GROQ_MODELS, DEFAULT_MODELS, } from "./domain/entities";
10
+ export { GroqError, GroqErrorType, mapHttpStatusToErrorType, } from "./domain/entities/error.types";
11
+ export { MODEL_REGISTRY, getModelInfo, modelSupports, type ModelCapabilities, type ModelInfo, } from "./domain/entities/models";
12
+ export { groqHttpClient } from "./infrastructure/services/GroqClient";
13
+ export { textGeneration, chatGeneration } from "./infrastructure/services/TextGeneration";
14
+ export { structuredText, structuredChat } from "./infrastructure/services/StructuredText";
15
+ export { streaming, streamingChat } from "./infrastructure/services/Streaming";
16
+ export { chatSessionService, createChatSession, sendChatMessage, buildChatHistory, trimChatHistory, type ChatSession, type SendChatMessageOptions, type ChatSendResult, type ChatHistoryMessage, } from "./infrastructure/services";
17
+ export type { StreamingCallbacks, StreamingOptions } from "./infrastructure/services/Streaming";
18
+ export { useGroq } from "./presentation/hooks/useGroq";
19
+ export type { UseGroqOptions, UseGroqReturn } from "./presentation/hooks/useGroq";
20
+ export { useOperationManager } from "./presentation/hooks/useOperationManager";
21
+ export { ConfigBuilder, GenerationConfigBuilder, providerFactory, initializeProvider, configureProvider, resetProvider, } from "./providers/ProviderFactory";
22
+ export type { ProviderConfig, ProviderFactoryOptions, } from "./providers/ProviderFactory";
23
+ export { createUserMessage, createAssistantMessage, createSystemMessage, createTextMessage, promptToMessages, extractTextFromMessages, formatMessagesForDisplay, } from "./infrastructure/utils/content-mapper.util";
24
+ export { getUserFriendlyError, isRetryableError, isAuthError, formatErrorForLogging, } from "./infrastructure/utils/error-mapper.util";
25
+ export { executeWithState, executeWithRetry, type AsyncStateSetters, type AsyncCallbacks, } from "./infrastructure/utils/async";
26
+ export { telemetry, useTelemetry, } from "./infrastructure/telemetry";
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAGH,YA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AAsB,GACvB,MAAM,6BAA6B,CAAC;AAGrC,OAAO,EACL,iBAAiB,EACjB,sBAAsB,EACtB,mBAAmB,EACnB,iBAAiB,EACjB,gBAAgB,EAChB,uBAAuB,EACvB,wBAAwB,GACzB,MAAM,4CAA4C,CAAC;AAEpD,OAAO,EACL,oBAAoB,EACpB,gBAAgB,EAChB,WAAW,EACX,qBAAqB,GACtB,MAAM,0CAA0C,CAAC;AAElD,OAAO,EACL,gBAAgB,EAChB,gBAAgB,EAChB,KAAK,iBAAiB,EACtB,KAAK,cAAc,GACpB,MAAM,8BAA8B,CAAC;AAEtC,OAAO,EACL,SAAS,EACT,YAAY,GACb,MAAM,4BAA4B,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,73 @@
1
+ "use strict";
2
+ /**
3
+ * @umituz/react-native-ai-groq-provider
4
+ * Groq text generation provider for React Native applications
5
+ *
6
+ * @author umituz
7
+ * @license MIT
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.useTelemetry = exports.telemetry = exports.executeWithRetry = exports.executeWithState = exports.formatErrorForLogging = exports.isAuthError = exports.isRetryableError = exports.getUserFriendlyError = exports.formatMessagesForDisplay = exports.extractTextFromMessages = exports.promptToMessages = exports.createTextMessage = exports.createSystemMessage = exports.createAssistantMessage = exports.createUserMessage = exports.resetProvider = exports.configureProvider = exports.initializeProvider = exports.providerFactory = exports.GenerationConfigBuilder = exports.ConfigBuilder = exports.useOperationManager = exports.useGroq = exports.trimChatHistory = exports.buildChatHistory = exports.sendChatMessage = exports.createChatSession = exports.chatSessionService = exports.streamingChat = exports.streaming = exports.structuredChat = exports.structuredText = exports.chatGeneration = exports.textGeneration = exports.groqHttpClient = exports.modelSupports = exports.getModelInfo = exports.MODEL_REGISTRY = exports.mapHttpStatusToErrorType = exports.GroqErrorType = exports.GroqError = exports.DEFAULT_MODELS = exports.GROQ_MODELS = void 0;
11
+ var entities_1 = require("./domain/entities");
12
+ Object.defineProperty(exports, "GROQ_MODELS", { enumerable: true, get: function () { return entities_1.GROQ_MODELS; } });
13
+ Object.defineProperty(exports, "DEFAULT_MODELS", { enumerable: true, get: function () { return entities_1.DEFAULT_MODELS; } });
14
+ var error_types_1 = require("./domain/entities/error.types");
15
+ Object.defineProperty(exports, "GroqError", { enumerable: true, get: function () { return error_types_1.GroqError; } });
16
+ Object.defineProperty(exports, "GroqErrorType", { enumerable: true, get: function () { return error_types_1.GroqErrorType; } });
17
+ Object.defineProperty(exports, "mapHttpStatusToErrorType", { enumerable: true, get: function () { return error_types_1.mapHttpStatusToErrorType; } });
18
+ var models_1 = require("./domain/entities/models");
19
+ Object.defineProperty(exports, "MODEL_REGISTRY", { enumerable: true, get: function () { return models_1.MODEL_REGISTRY; } });
20
+ Object.defineProperty(exports, "getModelInfo", { enumerable: true, get: function () { return models_1.getModelInfo; } });
21
+ Object.defineProperty(exports, "modelSupports", { enumerable: true, get: function () { return models_1.modelSupports; } });
22
+ // Services
23
+ var GroqClient_1 = require("./infrastructure/services/GroqClient");
24
+ Object.defineProperty(exports, "groqHttpClient", { enumerable: true, get: function () { return GroqClient_1.groqHttpClient; } });
25
+ var TextGeneration_1 = require("./infrastructure/services/TextGeneration");
26
+ Object.defineProperty(exports, "textGeneration", { enumerable: true, get: function () { return TextGeneration_1.textGeneration; } });
27
+ Object.defineProperty(exports, "chatGeneration", { enumerable: true, get: function () { return TextGeneration_1.chatGeneration; } });
28
+ var StructuredText_1 = require("./infrastructure/services/StructuredText");
29
+ Object.defineProperty(exports, "structuredText", { enumerable: true, get: function () { return StructuredText_1.structuredText; } });
30
+ Object.defineProperty(exports, "structuredChat", { enumerable: true, get: function () { return StructuredText_1.structuredChat; } });
31
+ var Streaming_1 = require("./infrastructure/services/Streaming");
32
+ Object.defineProperty(exports, "streaming", { enumerable: true, get: function () { return Streaming_1.streaming; } });
33
+ Object.defineProperty(exports, "streamingChat", { enumerable: true, get: function () { return Streaming_1.streamingChat; } });
34
+ var services_1 = require("./infrastructure/services");
35
+ Object.defineProperty(exports, "chatSessionService", { enumerable: true, get: function () { return services_1.chatSessionService; } });
36
+ Object.defineProperty(exports, "createChatSession", { enumerable: true, get: function () { return services_1.createChatSession; } });
37
+ Object.defineProperty(exports, "sendChatMessage", { enumerable: true, get: function () { return services_1.sendChatMessage; } });
38
+ Object.defineProperty(exports, "buildChatHistory", { enumerable: true, get: function () { return services_1.buildChatHistory; } });
39
+ Object.defineProperty(exports, "trimChatHistory", { enumerable: true, get: function () { return services_1.trimChatHistory; } });
40
+ // React Hooks
41
+ var useGroq_1 = require("./presentation/hooks/useGroq");
42
+ Object.defineProperty(exports, "useGroq", { enumerable: true, get: function () { return useGroq_1.useGroq; } });
43
+ var useOperationManager_1 = require("./presentation/hooks/useOperationManager");
44
+ Object.defineProperty(exports, "useOperationManager", { enumerable: true, get: function () { return useOperationManager_1.useOperationManager; } });
45
+ // Provider Configuration & Factory
46
+ var ProviderFactory_1 = require("./providers/ProviderFactory");
47
+ Object.defineProperty(exports, "ConfigBuilder", { enumerable: true, get: function () { return ProviderFactory_1.ConfigBuilder; } });
48
+ Object.defineProperty(exports, "GenerationConfigBuilder", { enumerable: true, get: function () { return ProviderFactory_1.GenerationConfigBuilder; } });
49
+ Object.defineProperty(exports, "providerFactory", { enumerable: true, get: function () { return ProviderFactory_1.providerFactory; } });
50
+ Object.defineProperty(exports, "initializeProvider", { enumerable: true, get: function () { return ProviderFactory_1.initializeProvider; } });
51
+ Object.defineProperty(exports, "configureProvider", { enumerable: true, get: function () { return ProviderFactory_1.configureProvider; } });
52
+ Object.defineProperty(exports, "resetProvider", { enumerable: true, get: function () { return ProviderFactory_1.resetProvider; } });
53
+ // Utilities
54
+ var content_mapper_util_1 = require("./infrastructure/utils/content-mapper.util");
55
+ Object.defineProperty(exports, "createUserMessage", { enumerable: true, get: function () { return content_mapper_util_1.createUserMessage; } });
56
+ Object.defineProperty(exports, "createAssistantMessage", { enumerable: true, get: function () { return content_mapper_util_1.createAssistantMessage; } });
57
+ Object.defineProperty(exports, "createSystemMessage", { enumerable: true, get: function () { return content_mapper_util_1.createSystemMessage; } });
58
+ Object.defineProperty(exports, "createTextMessage", { enumerable: true, get: function () { return content_mapper_util_1.createTextMessage; } });
59
+ Object.defineProperty(exports, "promptToMessages", { enumerable: true, get: function () { return content_mapper_util_1.promptToMessages; } });
60
+ Object.defineProperty(exports, "extractTextFromMessages", { enumerable: true, get: function () { return content_mapper_util_1.extractTextFromMessages; } });
61
+ Object.defineProperty(exports, "formatMessagesForDisplay", { enumerable: true, get: function () { return content_mapper_util_1.formatMessagesForDisplay; } });
62
+ var error_mapper_util_1 = require("./infrastructure/utils/error-mapper.util");
63
+ Object.defineProperty(exports, "getUserFriendlyError", { enumerable: true, get: function () { return error_mapper_util_1.getUserFriendlyError; } });
64
+ Object.defineProperty(exports, "isRetryableError", { enumerable: true, get: function () { return error_mapper_util_1.isRetryableError; } });
65
+ Object.defineProperty(exports, "isAuthError", { enumerable: true, get: function () { return error_mapper_util_1.isAuthError; } });
66
+ Object.defineProperty(exports, "formatErrorForLogging", { enumerable: true, get: function () { return error_mapper_util_1.formatErrorForLogging; } });
67
+ var async_1 = require("./infrastructure/utils/async");
68
+ Object.defineProperty(exports, "executeWithState", { enumerable: true, get: function () { return async_1.executeWithState; } });
69
+ Object.defineProperty(exports, "executeWithRetry", { enumerable: true, get: function () { return async_1.executeWithRetry; } });
70
+ var telemetry_1 = require("./infrastructure/telemetry");
71
+ Object.defineProperty(exports, "telemetry", { enumerable: true, get: function () { return telemetry_1.telemetry; } });
72
+ Object.defineProperty(exports, "useTelemetry", { enumerable: true, get: function () { return telemetry_1.useTelemetry; } });
73
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;;GAMG;;;AAmBH,8CAG2B;AAFzB,uGAAA,WAAW,OAAA;AACX,0GAAA,cAAc,OAAA;AAGhB,6DAIuC;AAHrC,wGAAA,SA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,gBAAgB,OAAA;AAKlB,wDAGoC;AAFlC,sGAAA,SAAS,OAAA;AACT,yGAAA,YAAY,OAAA"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Chat Session Service
3
+ * Manages multi-turn chat conversations with Groq API
4
+ */
5
+ import type { GroqMessage, GroqChatConfig, GroqGenerationConfig } from "../../domain/entities";
6
+ /**
7
+ * Chat session state
8
+ */
9
+ export interface ChatSession {
10
+ id: string;
11
+ model: string;
12
+ systemInstruction?: string;
13
+ messages: GroqMessage[];
14
+ generationConfig?: GroqGenerationConfig;
15
+ createdAt: Date;
16
+ updatedAt: Date;
17
+ }
18
+ /**
19
+ * Result of sending a chat message
20
+ */
21
+ export interface ChatSendResult {
22
+ response: string;
23
+ usage: {
24
+ promptTokens: number;
25
+ completionTokens: number;
26
+ totalTokens: number;
27
+ };
28
+ finishReason: string;
29
+ }
30
+ /**
31
+ * Options for sending a chat message
32
+ */
33
+ export interface SendChatMessageOptions {
34
+ /** Stream the response (not yet implemented) */
35
+ stream?: boolean;
36
+ }
37
+ /**
38
+ * Message format for chat history (simplified)
39
+ */
40
+ export type ChatHistoryMessage = {
41
+ role: "system" | "user" | "assistant";
42
+ content: string;
43
+ };
44
+ /**
45
+ * Create a new chat session
46
+ */
47
+ export declare function createChatSession(config?: GroqChatConfig): ChatSession;
48
+ /**
49
+ * Chat session service
50
+ */
51
+ declare class ChatSessionService {
52
+ private sessions;
53
+ /**
54
+ * Create a new chat session
55
+ */
56
+ create(config?: GroqChatConfig): ChatSession;
57
+ /**
58
+ * Get a session by ID
59
+ */
60
+ get(sessionId: string): ChatSession | undefined;
61
+ /**
62
+ * Delete a session
63
+ */
64
+ delete(sessionId: string): boolean;
65
+ /**
66
+ * Send a message in a chat session
67
+ */
68
+ send(sessionId: string, content: string, options?: SendChatMessageOptions): Promise<ChatSendResult>;
69
+ /**
70
+ * Reset a chat session (clear messages except system instruction)
71
+ */
72
+ reset(sessionId: string): ChatSession;
73
+ /**
74
+ * Update a chat session's config
75
+ */
76
+ updateConfig(sessionId: string, config: Partial<GroqChatConfig>): ChatSession;
77
+ }
78
+ /**
79
+ * Singleton instance
80
+ */
81
+ export declare const chatSessionService: ChatSessionService;
82
+ /**
83
+ * Convenience function to send a chat message
84
+ */
85
+ export declare function sendChatMessage(sessionId: string, content: string, options?: SendChatMessageOptions): Promise<ChatSendResult>;
86
+ /**
87
+ * Build chat history for API request
88
+ */
89
+ export declare function buildChatHistory(session: ChatSession): GroqMessage[];
90
+ /**
91
+ * Trim chat history to fit within token limit
92
+ */
93
+ export declare function trimChatHistory(messages: GroqMessage[], maxTokens?: number): GroqMessage[];
94
+ export {};
95
+ //# sourceMappingURL=ChatSession.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatSession.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/services/ChatSession.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,WAAW,EACX,cAAc,EACd,oBAAoB,EACrB,MAAM,uBAAuB,CAAC;AAK/B;;GAEG;AACH,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,iBAAiB,CAAC,EAAE,MAAM,CAAC;IAC3B,QAAQ,EAAE,WAAW,EAAE,CAAC;IACxB,gBAAgB,CAAC,EAAE,oBAAoB,CAAC;IACxC,SAAS,EAAE,IAAI,CAAC;IAChB,SAAS,EAAE,IAAI,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE;QACL,YAAY,EAAE,MAAM,CAAC;QACrB,gBAAgB,EAAE,MAAM,CAAC;QACzB,WAAW,EAAE,MAAM,CAAC;KACrB,CAAC;IACF,YAAY,EAAE,MAAM,CAAC;CACtB;AAED;;GAEG;AACH,MAAM,WAAW,sBAAsB;IACrC,gDAAgD;IAChD,MAAM,CAAC,EAAE,OAAO,CAAC;CAClB;AA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Service
4
+ * Manages multi-turn chat conversations with Groq API
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.chatSessionService = void 0;
8
+ exports.createChatSession = createChatSession;
9
+ exports.sendChatMessage = sendChatMessage;
10
+ exports.buildChatHistory = buildChatHistory;
11
+ exports.trimChatHistory = trimChatHistory;
12
+ const GroqClient_1 = require("./GroqClient");
13
+ const entities_1 = require("../../domain/entities");
14
+ const error_types_1 = require("../../domain/entities/error.types");
15
+ /**
16
+ * Create a new chat session
17
+ */
18
+ function createChatSession(config = {}) {
19
+ return {
20
+ id: `groq-chat-${Date.now()}-${Math.random().toString(36).substr(2, 9)}`,
21
+ model: config.model || entities_1.DEFAULT_MODELS.TEXT,
22
+ systemInstruction: config.systemInstruction,
23
+ messages: config.history ? [...config.history] : [],
24
+ generationConfig: config.generationConfig,
25
+ createdAt: new Date(),
26
+ updatedAt: new Date(),
27
+ };
28
+ }
29
+ /**
30
+ * Chat session service
31
+ */
32
+ class ChatSessionService {
33
+ constructor() {
34
+ this.sessions = new Map();
35
+ }
36
+ /**
37
+ * Create a new chat session
38
+ */
39
+ create(config = {}) {
40
+ const session = createChatSession(config);
41
+ this.sessions.set(session.id, session);
42
+ return session;
43
+ }
44
+ /**
45
+ * Get a session by ID
46
+ */
47
+ get(sessionId) {
48
+ return this.sessions.get(sessionId);
49
+ }
50
+ /**
51
+ * Delete a session
52
+ */
53
+ delete(sessionId) {
54
+ return this.sessions.delete(sessionId);
55
+ }
56
+ /**
57
+ * Send a message in a chat session
58
+ */
59
+ async send(sessionId, content, options = {}) {
60
+ const session = this.sessions.get(sessionId);
61
+ if (!session) {
62
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.MISSING_CONFIG, `Chat session ${sessionId} not found`);
63
+ }
64
+ // Add user message to history
65
+ const userMessage = {
66
+ role: "user",
67
+ content,
68
+ };
69
+ session.messages.push(userMessage);
70
+ // Build messages array for API
71
+ const messagesForApi = buildChatHistory(session);
72
+ // Call API
73
+ const response = await GroqClient_1.groqHttpClient.chatCompletion({
74
+ model: session.model,
75
+ messages: messagesForApi,
76
+ temperature: session.generationConfig?.temperature || 0.7,
77
+ max_tokens: session.generationConfig?.maxTokens || 1024,
78
+ top_p: session.generationConfig?.topP,
79
+ });
80
+ // Extract assistant response
81
+ const assistantContent = response.choices[0]?.message?.content;
82
+ if (!assistantContent) {
83
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.UNKNOWN_ERROR, "No content generated from Groq API");
84
+ }
85
+ // Add assistant message to history
86
+ const assistantMessage = {
87
+ role: "assistant",
88
+ content: assistantContent,
89
+ };
90
+ session.messages.push(assistantMessage);
91
+ // Update timestamp
92
+ session.updatedAt = new Date();
93
+ return {
94
+ response: assistantContent,
95
+ usage: {
96
+ promptTokens: response.usage?.prompt_tokens || 0,
97
+ completionTokens: response.usage?.completion_tokens || 0,
98
+ totalTokens: response.usage?.total_tokens || 0,
99
+ },
100
+ finishReason: response.choices[0]?.finish_reason || "unknown",
101
+ };
102
+ }
103
+ /**
104
+ * Reset a chat session (clear messages except system instruction)
105
+ */
106
+ reset(sessionId) {
107
+ const session = this.sessions.get(sessionId);
108
+ if (!session) {
109
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.MISSING_CONFIG, `Chat session ${sessionId} not found`);
110
+ }
111
+ session.messages = [];
112
+ session.updatedAt = new Date();
113
+ return session;
114
+ }
115
+ /**
116
+ * Update a chat session's config
117
+ */
118
+ updateConfig(sessionId, config) {
119
+ const session = this.sessions.get(sessionId);
120
+ if (!session) {
121
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.MISSING_CONFIG, `Chat session ${sessionId} not found`);
122
+ }
123
+ if (config.model !== undefined)
124
+ session.model = config.model;
125
+ if (config.systemInstruction !== undefined)
126
+ session.systemInstruction = config.systemInstruction;
127
+ if (config.generationConfig !== undefined)
128
+ session.generationConfig = config.generationConfig;
129
+ if (config.history)
130
+ session.messages = [...config.history];
131
+ session.updatedAt = new Date();
132
+ return session;
133
+ }
134
+ }
135
+ /**
136
+ * Singleton instance
137
+ */
138
+ exports.chatSessionService = new ChatSessionService();
139
+ /**
140
+ * Convenience function to send a chat message
141
+ */
142
+ async function sendChatMessage(sessionId, content, options) {
143
+ return exports.chatSessionService.send(sessionId, content, options);
144
+ }
145
+ /**
146
+ * Build chat history for API request
147
+ */
148
+ function buildChatHistory(session) {
149
+ const messages = [];
150
+ // Add system instruction if present
151
+ if (session.systemInstruction) {
152
+ messages.push({
153
+ role: "system",
154
+ content: session.systemInstruction,
155
+ });
156
+ }
157
+ // Add conversation history
158
+ messages.push(...session.messages);
159
+ return messages;
160
+ }
161
+ /**
162
+ * Trim chat history to fit within token limit
163
+ */
164
+ function trimChatHistory(messages, maxTokens = 4000) {
165
+ // Simple heuristic: assume average of 4 tokens per message
166
+ // For production, use a proper token counter
167
+ const maxMessages = Math.floor(maxTokens / 100);
168
+ if (messages.length <= maxMessages) {
169
+ return messages;
170
+ }
171
+ // Keep system messages and trim from oldest to newest
172
+ const systemMessages = messages.filter((m) => m.role === "system");
173
+ const nonSystemMessages = messages.filter((m) => m.role !== "system");
174
+ const trimmed = nonSystemMessages.slice(-maxMessages);
175
+ return [...systemMessages, ...trimmed];
176
+ }
177
+ //# sourceMappingURL=ChatSession.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ChatSession.js","sourceRoot":"","sources":["../../../src/infrastructure/services/ChatSession.ts"],"names":[],"mappings":";AAAA;;;GAGG;;;AAwDH,8CAUC;AAiJD,0CAMC;AAKD,4CAeC;AAKD,0CAmBC;AA9PD,6CAA8C;AAC9C,oDAAuD;AACvD,mEAA6E;AA4C7E;;GAEG;AACH,SAAgB,iBAAiB,CAAC,SAAyB,EAAE;IAC3D,OAAO;QACL,EAAE,EAAE,aAAa,IAAI,CAAC,GAAG,EAAE,IAAI,IAAI,CAAC,MAAM,EAAE,CAAC,QAAQ,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE;QACxE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AAC,KAAK,CAAC,CAAC,WAAW,CAAC,CAAC;IAEtD,OAAO,CAAC,GAAG,cAAc,EAAE,GAAG,OAAO,CAAC,CAAC;AACzC,CAAC"}
@@ -0,0 +1,52 @@
1
+ /**
2
+ * Groq HTTP Client
3
+ * Handles all HTTP communication with Groq API
4
+ */
5
+ import type { GroqConfig, GroqChatRequest, GroqChatResponse, GroqChatChunk } from "../../domain/entities";
6
+ declare class GroqHttpClient {
7
+ private config;
8
+ private initialized;
9
+ /**
10
+ * Initialize the client with configuration
11
+ */
12
+ initialize(config: GroqConfig): void;
13
+ /**
14
+ * Check if client is initialized
15
+ */
16
+ isInitialized(): boolean;
17
+ /**
18
+ * Get current configuration
19
+ */
20
+ getConfig(): GroqConfig;
21
+ /**
22
+ * Make an HTTP request to Groq API
23
+ */
24
+ private request;
25
+ /**
26
+ * Handle HTTP error responses
27
+ */
28
+ private handleErrorResponse;
29
+ /**
30
+ * Handle request errors (network, timeout, abort)
31
+ */
32
+ private handleRequestError;
33
+ /**
34
+ * Send chat completion request (non-streaming)
35
+ */
36
+ chatCompletion(request: GroqChatRequest, signal?: AbortSignal): Promise<GroqChatResponse>;
37
+ /**
38
+ * Send chat completion request (streaming)
39
+ * Returns an async generator of chunks
40
+ */
41
+ chatCompletionStream(request: GroqChatRequest, signal?: AbortSignal): AsyncGenerator<GroqChatChunk>;
42
+ /**
43
+ * Reset the client
44
+ */
45
+ reset(): void;
46
+ }
47
+ /**
48
+ * Singleton instance
49
+ */
50
+ export declare const groqHttpClient: GroqHttpClient;
51
+ export {};
52
+ //# sourceMappingURL=GroqClient.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GroqClient.d.ts","sourceRoot":"","sources":["../../../src/infrastructure/services/GroqClient.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EACV,UAAU,EACV,eAAe,EACf,gBAAgB,EAChB,aAAa,EACd,MAAM,uBAAuB,CAAC;AAO/B,cAAM,cAAc;IAClB,OAAO,CAAC,MAAM,CAA2B;IACzC,OAAO,CAAC,WAAW,CAAS;IAE5B;;OAEG;IACH,UAAU,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI;IAmBpC;;OAEG;IACH,aAAa,IAAI,OAAO;IAIxB;;OAEG;IACH,SAAS,IAAI,UAAU;IAUvB;;OAEG;YACW,OAAO;IA+CrB;;OAEG;YACW,mBAAmB;IAmBjC;;OAEG;IACH,OAAO,CAAC,kBAAkB;IA8B1B;;OAEG;IACG,cAAc,CAClB,OAAO,EAAE,eAAe,EACxB,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,gBAAgB,CAAC;IAQ5B;;;OAGG;IACI,oBAAoB,CACzB,OAAO,EAAE,eAAe,EACxB,MAAM,CAAC,EAAE,WAAW,GACnB,cAAc,CAAC,aAAa,CAAC;IA8EhC;;OAEG;IACH,KAAK,IAAI,IAAI;CAId;AAED;;GAEG;AACH,eAAO,MAAM,cAAc,gBAAuB,CAAC"}
@@ -0,0 +1,205 @@
1
+ "use strict";
2
+ /**
3
+ * Groq HTTP Client
4
+ * Handles all HTTP communication with Groq API
5
+ */
6
+ Object.defineProperty(exports, "__esModule", { value: true });
7
+ exports.groqHttpClient = void 0;
8
+ const error_types_1 = require("../../domain/entities/error.types");
9
+ const DEFAULT_BASE_URL = "https://api.groq.com/openai/v1";
10
+ const DEFAULT_TIMEOUT = 60000; // 60 seconds
11
+ const CHAT_COMPLETIONS_ENDPOINT = "/chat/completions";
12
+ class GroqHttpClient {
13
+ constructor() {
14
+ this.config = null;
15
+ this.initialized = false;
16
+ }
17
+ /**
18
+ * Initialize the client with configuration
19
+ */
20
+ initialize(config) {
21
+ const apiKey = config.apiKey?.trim();
22
+ if (!apiKey || apiKey.length < 10) {
23
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.INVALID_API_KEY, "API key is required and must be at least 10 characters");
24
+ }
25
+ this.config = {
26
+ apiKey,
27
+ baseUrl: config.baseUrl || DEFAULT_BASE_URL,
28
+ timeoutMs: config.timeoutMs || DEFAULT_TIMEOUT,
29
+ textModel: config.textModel,
30
+ };
31
+ this.initialized = true;
32
+ }
33
+ /**
34
+ * Check if client is initialized
35
+ */
36
+ isInitialized() {
37
+ return this.initialized && this.config !== null;
38
+ }
39
+ /**
40
+ * Get current configuration
41
+ */
42
+ getConfig() {
43
+ if (!this.config || !this.initialized) {
44
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.MISSING_CONFIG, "Client not initialized. Call initialize() first.");
45
+ }
46
+ return this.config;
47
+ }
48
+ /**
49
+ * Make an HTTP request to Groq API
50
+ */
51
+ async request(endpoint, body, signal) {
52
+ if (!this.config || !this.initialized) {
53
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.MISSING_CONFIG, "Client not initialized. Call initialize() first.");
54
+ }
55
+ const url = `${this.config.baseUrl}${endpoint}`;
56
+ const timeout = this.config.timeoutMs || DEFAULT_TIMEOUT;
57
+ try {
58
+ // Create AbortController for timeout
59
+ const controller = new AbortController();
60
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
61
+ // Use provided signal if available
62
+ if (signal) {
63
+ signal.addEventListener("abort", () => controller.abort());
64
+ }
65
+ const response = await fetch(url, {
66
+ method: "POST",
67
+ headers: {
68
+ "Content-Type": "application/json",
69
+ "Authorization": `Bearer ${this.config.apiKey}`,
70
+ },
71
+ body: JSON.stringify(body),
72
+ signal: controller.signal,
73
+ });
74
+ clearTimeout(timeoutId);
75
+ if (!response.ok) {
76
+ await this.handleErrorResponse(response);
77
+ }
78
+ return (await response.json());
79
+ }
80
+ catch (error) {
81
+ throw this.handleRequestError(error);
82
+ }
83
+ }
84
+ /**
85
+ * Handle HTTP error responses
86
+ */
87
+ async handleErrorResponse(response) {
88
+ let errorMessage = `HTTP ${response.status}`;
89
+ let errorType = (0, error_types_1.mapHttpStatusToErrorType)(response.status);
90
+ try {
91
+ const errorData = (await response.json());
92
+ if (errorData.error?.message) {
93
+ errorMessage = errorData.error.message;
94
+ }
95
+ }
96
+ catch {
97
+ // If parsing fails, use default message
98
+ }
99
+ throw new error_types_1.GroqError(errorType, errorMessage, {
100
+ status: response.status,
101
+ url: response.url,
102
+ });
103
+ }
104
+ /**
105
+ * Handle request errors (network, timeout, abort)
106
+ */
107
+ handleRequestError(error) {
108
+ if (error instanceof error_types_1.GroqError) {
109
+ return error;
110
+ }
111
+ if (error instanceof Error) {
112
+ if (error.name === "AbortError") {
113
+ return new error_types_1.GroqError(error_types_1.GroqErrorType.ABORT_ERROR, "Request was aborted by the client", error);
114
+ }
115
+ if (error.name === "TypeError" && error.message.includes("network")) {
116
+ return new error_types_1.GroqError(error_types_1.GroqErrorType.NETWORK_ERROR, "Network error: Unable to connect to Groq API", error);
117
+ }
118
+ }
119
+ return new error_types_1.GroqError(error_types_1.GroqErrorType.UNKNOWN_ERROR, error instanceof Error ? error.message : "Unknown error occurred", error);
120
+ }
121
+ /**
122
+ * Send chat completion request (non-streaming)
123
+ */
124
+ async chatCompletion(request, signal) {
125
+ return this.request(CHAT_COMPLETIONS_ENDPOINT, { ...request, stream: false }, signal);
126
+ }
127
+ /**
128
+ * Send chat completion request (streaming)
129
+ * Returns an async generator of chunks
130
+ */
131
+ async *chatCompletionStream(request, signal) {
132
+ if (!this.config || !this.initialized) {
133
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.MISSING_CONFIG, "Client not initialized. Call initialize() first.");
134
+ }
135
+ const url = `${this.config.baseUrl}${CHAT_COMPLETIONS_ENDPOINT}`;
136
+ const timeout = this.config.timeoutMs || DEFAULT_TIMEOUT;
137
+ // Create AbortController for timeout
138
+ const controller = new AbortController();
139
+ const timeoutId = setTimeout(() => controller.abort(), timeout);
140
+ // Use provided signal if available
141
+ if (signal) {
142
+ signal.addEventListener("abort", () => controller.abort());
143
+ }
144
+ try {
145
+ const response = await fetch(url, {
146
+ method: "POST",
147
+ headers: {
148
+ "Content-Type": "application/json",
149
+ "Authorization": `Bearer ${this.config.apiKey}`,
150
+ },
151
+ body: JSON.stringify({ ...request, stream: true }),
152
+ signal: controller.signal,
153
+ });
154
+ clearTimeout(timeoutId);
155
+ if (!response.ok) {
156
+ await this.handleErrorResponse(response);
157
+ }
158
+ if (!response.body) {
159
+ throw new error_types_1.GroqError(error_types_1.GroqErrorType.NETWORK_ERROR, "Response body is null");
160
+ }
161
+ // Read and parse Server-Sent Events
162
+ const reader = response.body.getReader();
163
+ const decoder = new TextDecoder();
164
+ let buffer = "";
165
+ while (true) {
166
+ const { done, value } = await reader.read();
167
+ if (done)
168
+ break;
169
+ buffer += decoder.decode(value, { stream: true });
170
+ const lines = buffer.split("\n");
171
+ buffer = lines.pop() || "";
172
+ for (const line of lines) {
173
+ const trimmed = line.trim();
174
+ if (!trimmed || trimmed === "data: [DONE]")
175
+ continue;
176
+ if (trimmed.startsWith("data: ")) {
177
+ const jsonStr = trimmed.slice(6);
178
+ try {
179
+ const chunk = JSON.parse(jsonStr);
180
+ yield chunk;
181
+ }
182
+ catch (error) {
183
+ console.error("Failed to parse SSE chunk:", error);
184
+ }
185
+ }
186
+ }
187
+ }
188
+ }
189
+ catch (error) {
190
+ throw this.handleRequestError(error);
191
+ }
192
+ }
193
+ /**
194
+ * Reset the client
195
+ */
196
+ reset() {
197
+ this.config = null;
198
+ this.initialized = false;
199
+ }
200
+ }
201
+ /**
202
+ * Singleton instance
203
+ */
204
+ exports.groqHttpClient = new GroqHttpClient();
205
+ //# sourceMappingURL=GroqClient.js.map