@hazeljs/ai 0.2.0-alpha.1
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/LICENSE +192 -0
- package/README.md +497 -0
- package/dist/ai-enhanced.service.d.ts +108 -0
- package/dist/ai-enhanced.service.d.ts.map +1 -0
- package/dist/ai-enhanced.service.js +345 -0
- package/dist/ai-enhanced.service.test.d.ts +2 -0
- package/dist/ai-enhanced.service.test.d.ts.map +1 -0
- package/dist/ai-enhanced.service.test.js +501 -0
- package/dist/ai-enhanced.test.d.ts +2 -0
- package/dist/ai-enhanced.test.d.ts.map +1 -0
- package/dist/ai-enhanced.test.js +587 -0
- package/dist/ai-enhanced.types.d.ts +277 -0
- package/dist/ai-enhanced.types.d.ts.map +1 -0
- package/dist/ai-enhanced.types.js +2 -0
- package/dist/ai.decorator.d.ts +4 -0
- package/dist/ai.decorator.d.ts.map +1 -0
- package/dist/ai.decorator.js +57 -0
- package/dist/ai.decorator.test.d.ts +2 -0
- package/dist/ai.decorator.test.d.ts.map +1 -0
- package/dist/ai.decorator.test.js +189 -0
- package/dist/ai.module.d.ts +12 -0
- package/dist/ai.module.d.ts.map +1 -0
- package/dist/ai.module.js +44 -0
- package/dist/ai.module.test.d.ts +2 -0
- package/dist/ai.module.test.d.ts.map +1 -0
- package/dist/ai.module.test.js +23 -0
- package/dist/ai.service.d.ts +11 -0
- package/dist/ai.service.d.ts.map +1 -0
- package/dist/ai.service.js +266 -0
- package/dist/ai.service.test.d.ts +2 -0
- package/dist/ai.service.test.d.ts.map +1 -0
- package/dist/ai.service.test.js +222 -0
- package/dist/ai.types.d.ts +30 -0
- package/dist/ai.types.d.ts.map +1 -0
- package/dist/ai.types.js +2 -0
- package/dist/context/context.manager.d.ts +69 -0
- package/dist/context/context.manager.d.ts.map +1 -0
- package/dist/context/context.manager.js +168 -0
- package/dist/context/context.manager.test.d.ts +2 -0
- package/dist/context/context.manager.test.d.ts.map +1 -0
- package/dist/context/context.manager.test.js +180 -0
- package/dist/decorators/ai-function.decorator.d.ts +42 -0
- package/dist/decorators/ai-function.decorator.d.ts.map +1 -0
- package/dist/decorators/ai-function.decorator.js +80 -0
- package/dist/decorators/ai-validate.decorator.d.ts +46 -0
- package/dist/decorators/ai-validate.decorator.d.ts.map +1 -0
- package/dist/decorators/ai-validate.decorator.js +83 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +40 -0
- package/dist/prompts/task.prompt.d.ts +12 -0
- package/dist/prompts/task.prompt.d.ts.map +1 -0
- package/dist/prompts/task.prompt.js +12 -0
- package/dist/providers/anthropic.provider.d.ts +48 -0
- package/dist/providers/anthropic.provider.d.ts.map +1 -0
- package/dist/providers/anthropic.provider.js +194 -0
- package/dist/providers/anthropic.provider.test.d.ts +2 -0
- package/dist/providers/anthropic.provider.test.d.ts.map +1 -0
- package/dist/providers/anthropic.provider.test.js +222 -0
- package/dist/providers/cohere.provider.d.ts +57 -0
- package/dist/providers/cohere.provider.d.ts.map +1 -0
- package/dist/providers/cohere.provider.js +230 -0
- package/dist/providers/cohere.provider.test.d.ts +2 -0
- package/dist/providers/cohere.provider.test.d.ts.map +1 -0
- package/dist/providers/cohere.provider.test.js +267 -0
- package/dist/providers/gemini.provider.d.ts +45 -0
- package/dist/providers/gemini.provider.d.ts.map +1 -0
- package/dist/providers/gemini.provider.js +180 -0
- package/dist/providers/gemini.provider.test.d.ts +2 -0
- package/dist/providers/gemini.provider.test.d.ts.map +1 -0
- package/dist/providers/gemini.provider.test.js +219 -0
- package/dist/providers/ollama.provider.d.ts +45 -0
- package/dist/providers/ollama.provider.d.ts.map +1 -0
- package/dist/providers/ollama.provider.js +232 -0
- package/dist/providers/ollama.provider.test.d.ts +2 -0
- package/dist/providers/ollama.provider.test.d.ts.map +1 -0
- package/dist/providers/ollama.provider.test.js +267 -0
- package/dist/providers/openai.provider.d.ts +57 -0
- package/dist/providers/openai.provider.d.ts.map +1 -0
- package/dist/providers/openai.provider.js +320 -0
- package/dist/providers/openai.provider.test.d.ts +2 -0
- package/dist/providers/openai.provider.test.d.ts.map +1 -0
- package/dist/providers/openai.provider.test.js +364 -0
- package/dist/tracking/token.tracker.d.ts +72 -0
- package/dist/tracking/token.tracker.d.ts.map +1 -0
- package/dist/tracking/token.tracker.js +222 -0
- package/dist/tracking/token.tracker.test.d.ts +2 -0
- package/dist/tracking/token.tracker.test.d.ts.map +1 -0
- package/dist/tracking/token.tracker.test.js +272 -0
- package/dist/vector/vector.service.d.ts +50 -0
- package/dist/vector/vector.service.d.ts.map +1 -0
- package/dist/vector/vector.service.js +163 -0
- package/package.json +60 -0
|
@@ -0,0 +1,277 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI Provider types
|
|
3
|
+
*/
|
|
4
|
+
export type AIProvider = 'openai' | 'anthropic' | 'gemini' | 'cohere' | 'ollama' | 'huggingface';
|
|
5
|
+
/**
|
|
6
|
+
* AI model configuration
|
|
7
|
+
*/
|
|
8
|
+
export interface AIModelConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Provider name
|
|
11
|
+
*/
|
|
12
|
+
provider: AIProvider;
|
|
13
|
+
/**
|
|
14
|
+
* Model name
|
|
15
|
+
*/
|
|
16
|
+
model: string;
|
|
17
|
+
/**
|
|
18
|
+
* API key
|
|
19
|
+
*/
|
|
20
|
+
apiKey?: string;
|
|
21
|
+
/**
|
|
22
|
+
* Temperature (0-1)
|
|
23
|
+
*/
|
|
24
|
+
temperature?: number;
|
|
25
|
+
/**
|
|
26
|
+
* Max tokens
|
|
27
|
+
*/
|
|
28
|
+
maxTokens?: number;
|
|
29
|
+
/**
|
|
30
|
+
* Top P
|
|
31
|
+
*/
|
|
32
|
+
topP?: number;
|
|
33
|
+
/**
|
|
34
|
+
* Enable streaming
|
|
35
|
+
*/
|
|
36
|
+
streaming?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* Custom endpoint
|
|
39
|
+
*/
|
|
40
|
+
endpoint?: string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* AI message role
|
|
44
|
+
*/
|
|
45
|
+
export type AIMessageRole = 'system' | 'user' | 'assistant' | 'function' | 'tool';
|
|
46
|
+
/**
|
|
47
|
+
* AI message
|
|
48
|
+
*/
|
|
49
|
+
export interface AIToolCall {
|
|
50
|
+
id: string;
|
|
51
|
+
type: 'function';
|
|
52
|
+
function: {
|
|
53
|
+
name: string;
|
|
54
|
+
arguments: string;
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
export interface AIMessage {
|
|
58
|
+
role: AIMessageRole;
|
|
59
|
+
content: string;
|
|
60
|
+
name?: string;
|
|
61
|
+
toolCallId?: string;
|
|
62
|
+
functionCall?: {
|
|
63
|
+
name: string;
|
|
64
|
+
arguments: string;
|
|
65
|
+
};
|
|
66
|
+
toolCalls?: AIToolCall[];
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* AI completion request
|
|
70
|
+
*/
|
|
71
|
+
export interface AICompletionRequest {
|
|
72
|
+
messages: AIMessage[];
|
|
73
|
+
model?: string;
|
|
74
|
+
temperature?: number;
|
|
75
|
+
maxTokens?: number;
|
|
76
|
+
topP?: number;
|
|
77
|
+
stream?: boolean;
|
|
78
|
+
functions?: AIFunction[];
|
|
79
|
+
functionCall?: 'auto' | 'none' | {
|
|
80
|
+
name: string;
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
* AI completion response
|
|
85
|
+
*/
|
|
86
|
+
export interface AICompletionResponse {
|
|
87
|
+
id: string;
|
|
88
|
+
content: string;
|
|
89
|
+
role: AIMessageRole;
|
|
90
|
+
model: string;
|
|
91
|
+
usage?: {
|
|
92
|
+
promptTokens: number;
|
|
93
|
+
completionTokens: number;
|
|
94
|
+
totalTokens: number;
|
|
95
|
+
};
|
|
96
|
+
functionCall?: {
|
|
97
|
+
name: string;
|
|
98
|
+
arguments: string;
|
|
99
|
+
};
|
|
100
|
+
toolCalls?: AIToolCall[];
|
|
101
|
+
finishReason?: string;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* AI streaming chunk
|
|
105
|
+
*/
|
|
106
|
+
export interface AIStreamChunk {
|
|
107
|
+
id: string;
|
|
108
|
+
content: string;
|
|
109
|
+
delta: string;
|
|
110
|
+
done: boolean;
|
|
111
|
+
usage?: {
|
|
112
|
+
promptTokens: number;
|
|
113
|
+
completionTokens: number;
|
|
114
|
+
totalTokens: number;
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* AI function definition
|
|
119
|
+
*/
|
|
120
|
+
export interface AIFunction {
|
|
121
|
+
name: string;
|
|
122
|
+
description: string;
|
|
123
|
+
parameters: {
|
|
124
|
+
type: 'object';
|
|
125
|
+
properties: Record<string, {
|
|
126
|
+
type: string;
|
|
127
|
+
description?: string;
|
|
128
|
+
enum?: string[];
|
|
129
|
+
}>;
|
|
130
|
+
required?: string[];
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* AI embedding request
|
|
135
|
+
*/
|
|
136
|
+
export interface AIEmbeddingRequest {
|
|
137
|
+
input: string | string[];
|
|
138
|
+
model?: string;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* AI embedding response
|
|
142
|
+
*/
|
|
143
|
+
export interface AIEmbeddingResponse {
|
|
144
|
+
embeddings: number[][];
|
|
145
|
+
model: string;
|
|
146
|
+
usage?: {
|
|
147
|
+
promptTokens: number;
|
|
148
|
+
totalTokens: number;
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* AI provider interface
|
|
153
|
+
*/
|
|
154
|
+
export interface IAIProvider {
|
|
155
|
+
/**
|
|
156
|
+
* Provider name
|
|
157
|
+
*/
|
|
158
|
+
readonly name: AIProvider;
|
|
159
|
+
/**
|
|
160
|
+
* Generate completion
|
|
161
|
+
*/
|
|
162
|
+
complete(request: AICompletionRequest): Promise<AICompletionResponse>;
|
|
163
|
+
/**
|
|
164
|
+
* Generate streaming completion
|
|
165
|
+
*/
|
|
166
|
+
streamComplete(request: AICompletionRequest): AsyncGenerator<AIStreamChunk>;
|
|
167
|
+
/**
|
|
168
|
+
* Generate embeddings
|
|
169
|
+
*/
|
|
170
|
+
embed(request: AIEmbeddingRequest): Promise<AIEmbeddingResponse>;
|
|
171
|
+
/**
|
|
172
|
+
* Check if provider is available
|
|
173
|
+
*/
|
|
174
|
+
isAvailable(): Promise<boolean>;
|
|
175
|
+
/**
|
|
176
|
+
* Generate speech from text (TTS). Optional; supported by OpenAI and compatible providers.
|
|
177
|
+
*/
|
|
178
|
+
speech?(input: string, options?: {
|
|
179
|
+
voice?: string;
|
|
180
|
+
model?: string;
|
|
181
|
+
format?: 'mp3' | 'opus';
|
|
182
|
+
}): Promise<Buffer>;
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Vector database types
|
|
186
|
+
*/
|
|
187
|
+
export type VectorDatabase = 'pinecone' | 'weaviate' | 'qdrant' | 'chroma';
|
|
188
|
+
/**
|
|
189
|
+
* Vector store configuration
|
|
190
|
+
*/
|
|
191
|
+
export interface VectorStoreConfig {
|
|
192
|
+
database: VectorDatabase;
|
|
193
|
+
apiKey?: string;
|
|
194
|
+
endpoint?: string;
|
|
195
|
+
index?: string;
|
|
196
|
+
namespace?: string;
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Vector document
|
|
200
|
+
*/
|
|
201
|
+
export interface VectorDocument {
|
|
202
|
+
id: string;
|
|
203
|
+
content: string;
|
|
204
|
+
embedding?: number[];
|
|
205
|
+
metadata?: Record<string, unknown>;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Vector search request
|
|
209
|
+
*/
|
|
210
|
+
export interface VectorSearchRequest {
|
|
211
|
+
query: string;
|
|
212
|
+
topK?: number;
|
|
213
|
+
filter?: Record<string, unknown>;
|
|
214
|
+
namespace?: string;
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Vector search result
|
|
218
|
+
*/
|
|
219
|
+
export interface VectorSearchResult {
|
|
220
|
+
id: string;
|
|
221
|
+
content: string;
|
|
222
|
+
score: number;
|
|
223
|
+
metadata?: Record<string, unknown>;
|
|
224
|
+
}
|
|
225
|
+
/**
|
|
226
|
+
* AI context manager
|
|
227
|
+
*/
|
|
228
|
+
export interface AIContext {
|
|
229
|
+
messages: AIMessage[];
|
|
230
|
+
maxTokens: number;
|
|
231
|
+
currentTokens: number;
|
|
232
|
+
addMessage(message: AIMessage): void;
|
|
233
|
+
getMessages(): AIMessage[];
|
|
234
|
+
clear(): void;
|
|
235
|
+
trimToLimit(): void;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Token usage tracker
|
|
239
|
+
*/
|
|
240
|
+
export interface TokenUsage {
|
|
241
|
+
userId?: string;
|
|
242
|
+
promptTokens: number;
|
|
243
|
+
completionTokens: number;
|
|
244
|
+
totalTokens: number;
|
|
245
|
+
cost?: number;
|
|
246
|
+
timestamp: number;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Token limit configuration
|
|
250
|
+
*/
|
|
251
|
+
export interface TokenLimitConfig {
|
|
252
|
+
maxTokensPerRequest?: number;
|
|
253
|
+
maxTokensPerDay?: number;
|
|
254
|
+
maxTokensPerMonth?: number;
|
|
255
|
+
costPerToken?: number;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* AI function decorator options
|
|
259
|
+
*/
|
|
260
|
+
export interface AIFunctionOptions {
|
|
261
|
+
provider: AIProvider;
|
|
262
|
+
model: string;
|
|
263
|
+
streaming?: boolean;
|
|
264
|
+
temperature?: number;
|
|
265
|
+
maxTokens?: number;
|
|
266
|
+
systemPrompt?: string;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* AI validation options
|
|
270
|
+
*/
|
|
271
|
+
export interface AIValidationOptions {
|
|
272
|
+
provider: AIProvider;
|
|
273
|
+
model?: string;
|
|
274
|
+
instruction: string;
|
|
275
|
+
failOnInvalid?: boolean;
|
|
276
|
+
}
|
|
277
|
+
//# sourceMappingURL=ai-enhanced.types.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai-enhanced.types.d.ts","sourceRoot":"","sources":["../src/ai-enhanced.types.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,MAAM,UAAU,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,aAAa,CAAC;AAEjG;;GAEG;AACH,MAAM,WAAW,aAAa;IAC5B;;OAEG;IACH,QAAQ,EAAE,UAAU,CAAC;IAErB;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAEhB;;OAEG;IACH,WAAW,CAAC,EAAE,MAAM,CAAC;IAErB;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB;;OAEG;IACH,IAAI,CAAC,EAAE,MAAM,CAAC;IAEd;;OAEG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,MAAM,aAAa,GAAG,QAAQ,GAAG,MAAM,GAAG,WAAW,GAAG,UAAU,GAAG,MAAM,CAAC;AAElF;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,UAAU,CAAC;IACjB,QAAQ,EAAE;QACR,IAAI,EAAE,MAAM,CAAC;QACb,SAAS,EAAE,MAAM,CAAC;KACnB,CAAC;CACH;AAED,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,aAAa,CAAC;IACpB,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,YAAY,CAAC,EAAE;QACb,I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AAe,CA2D5D"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.AITask = AITask;
|
|
7
|
+
require("reflect-metadata");
|
|
8
|
+
const core_1 = __importDefault(require("@hazeljs/core"));
|
|
9
|
+
const AI_TASK_METADATA_KEY = 'hazel:ai-task';
|
|
10
|
+
function AITask(config) {
|
|
11
|
+
return (target, propertyKey, descriptor) => {
|
|
12
|
+
// Store the AI task configuration in metadata
|
|
13
|
+
Reflect.defineMetadata(AI_TASK_METADATA_KEY, config, target, propertyKey);
|
|
14
|
+
// Replace the method with our AI-powered version
|
|
15
|
+
descriptor.value = async function (...args) {
|
|
16
|
+
try {
|
|
17
|
+
// Get the AI task configuration from metadata
|
|
18
|
+
const taskConfig = Reflect.getMetadata(AI_TASK_METADATA_KEY, target, propertyKey);
|
|
19
|
+
if (!taskConfig) {
|
|
20
|
+
throw new Error('AI task configuration not found');
|
|
21
|
+
}
|
|
22
|
+
// Get the AI service from the container
|
|
23
|
+
const aiService = this.aiService;
|
|
24
|
+
if (!aiService) {
|
|
25
|
+
throw new Error('AI service not found. Make sure to inject AIService in the constructor.');
|
|
26
|
+
}
|
|
27
|
+
core_1.default.debug('Executing AI task with config:', {
|
|
28
|
+
name: taskConfig.name,
|
|
29
|
+
stream: taskConfig.stream,
|
|
30
|
+
});
|
|
31
|
+
// Execute the AI task
|
|
32
|
+
const result = await aiService.executeTask(taskConfig, args[0]);
|
|
33
|
+
// If streaming is enabled and a stream is returned, return the stream directly
|
|
34
|
+
if (taskConfig.stream && result.stream) {
|
|
35
|
+
core_1.default.debug('Returning stream from AI task');
|
|
36
|
+
return result.stream;
|
|
37
|
+
}
|
|
38
|
+
// If there's an error, throw it
|
|
39
|
+
if (result.error) {
|
|
40
|
+
core_1.default.error('AI task error:', result.error);
|
|
41
|
+
throw new Error(result.error);
|
|
42
|
+
}
|
|
43
|
+
// For non-streaming responses, return the data
|
|
44
|
+
core_1.default.debug('Returning data from AI task:', result.data);
|
|
45
|
+
return result.data;
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
core_1.default.error('AI task execution failed:', error);
|
|
49
|
+
if (error instanceof Error) {
|
|
50
|
+
throw new Error(`AI task execution failed: ${error.message}`);
|
|
51
|
+
}
|
|
52
|
+
throw new Error('AI task execution failed: Unknown error');
|
|
53
|
+
}
|
|
54
|
+
};
|
|
55
|
+
return descriptor;
|
|
56
|
+
};
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.decorator.test.d.ts","sourceRoot":"","sources":["../src/ai.decorator.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var __metadata = (this && this.__metadata) || function (k, v) {
|
|
9
|
+
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
const ai_decorator_1 = require("./ai.decorator");
|
|
13
|
+
const ai_service_1 = require("./ai.service");
|
|
14
|
+
const core_1 = require("@hazeljs/core");
|
|
15
|
+
const core_2 = require("@hazeljs/core");
|
|
16
|
+
// Mock the AIService
|
|
17
|
+
jest.mock('./ai.service', () => {
|
|
18
|
+
const mockAIService = jest.fn().mockImplementation(() => ({
|
|
19
|
+
executeTask: jest.fn().mockImplementation(async (config, input) => ({
|
|
20
|
+
data: `Processed: ${input}`,
|
|
21
|
+
})),
|
|
22
|
+
}));
|
|
23
|
+
return {
|
|
24
|
+
AIService: mockAIService,
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
describe('AITask Decorator', () => {
|
|
28
|
+
let container;
|
|
29
|
+
let mockAIService;
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
container = core_1.Container.getInstance();
|
|
32
|
+
container.clear();
|
|
33
|
+
// Create a mock instance
|
|
34
|
+
mockAIService = new ai_service_1.AIService();
|
|
35
|
+
// Register AIService with the mock instance
|
|
36
|
+
container.register(ai_service_1.AIService, mockAIService);
|
|
37
|
+
});
|
|
38
|
+
afterEach(() => {
|
|
39
|
+
container.clear();
|
|
40
|
+
jest.clearAllMocks();
|
|
41
|
+
});
|
|
42
|
+
it('should inject AIService', () => {
|
|
43
|
+
let TestClass = class TestClass {
|
|
44
|
+
constructor(aiService) {
|
|
45
|
+
this.aiService = aiService;
|
|
46
|
+
}
|
|
47
|
+
async testMethod(input) {
|
|
48
|
+
return input;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
__decorate([
|
|
52
|
+
(0, ai_decorator_1.AITask)({
|
|
53
|
+
name: 'test-task',
|
|
54
|
+
prompt: 'Test prompt',
|
|
55
|
+
provider: 'openai',
|
|
56
|
+
model: 'gpt-3.5-turbo',
|
|
57
|
+
outputType: 'string',
|
|
58
|
+
}),
|
|
59
|
+
__metadata("design:type", Function),
|
|
60
|
+
__metadata("design:paramtypes", [String]),
|
|
61
|
+
__metadata("design:returntype", Promise)
|
|
62
|
+
], TestClass.prototype, "testMethod", null);
|
|
63
|
+
TestClass = __decorate([
|
|
64
|
+
(0, core_2.Injectable)(),
|
|
65
|
+
__metadata("design:paramtypes", [ai_service_1.AIService])
|
|
66
|
+
], TestClass);
|
|
67
|
+
// Register the test class
|
|
68
|
+
container.register(TestClass, new TestClass(mockAIService));
|
|
69
|
+
const instance = container.resolve(TestClass);
|
|
70
|
+
expect(instance.aiService).toBeDefined();
|
|
71
|
+
expect(instance.aiService).toBe(mockAIService);
|
|
72
|
+
});
|
|
73
|
+
it('should work with multiple dependencies', () => {
|
|
74
|
+
let OtherService = class OtherService {
|
|
75
|
+
};
|
|
76
|
+
OtherService = __decorate([
|
|
77
|
+
(0, core_2.Injectable)()
|
|
78
|
+
], OtherService);
|
|
79
|
+
let TestClass = class TestClass {
|
|
80
|
+
constructor(aiService, otherService) {
|
|
81
|
+
this.aiService = aiService;
|
|
82
|
+
this.otherService = otherService;
|
|
83
|
+
}
|
|
84
|
+
async testMethod(input) {
|
|
85
|
+
return input;
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
__decorate([
|
|
89
|
+
(0, ai_decorator_1.AITask)({
|
|
90
|
+
name: 'test-task',
|
|
91
|
+
prompt: 'Test prompt',
|
|
92
|
+
provider: 'openai',
|
|
93
|
+
model: 'gpt-3.5-turbo',
|
|
94
|
+
outputType: 'string',
|
|
95
|
+
}),
|
|
96
|
+
__metadata("design:type", Function),
|
|
97
|
+
__metadata("design:paramtypes", [String]),
|
|
98
|
+
__metadata("design:returntype", Promise)
|
|
99
|
+
], TestClass.prototype, "testMethod", null);
|
|
100
|
+
TestClass = __decorate([
|
|
101
|
+
(0, core_2.Injectable)(),
|
|
102
|
+
__metadata("design:paramtypes", [ai_service_1.AIService,
|
|
103
|
+
OtherService])
|
|
104
|
+
], TestClass);
|
|
105
|
+
// Register both services
|
|
106
|
+
const otherService = new OtherService();
|
|
107
|
+
container.register(OtherService, otherService);
|
|
108
|
+
container.register(TestClass, new TestClass(mockAIService, otherService));
|
|
109
|
+
const instance = container.resolve(TestClass);
|
|
110
|
+
expect(instance.aiService).toBeDefined();
|
|
111
|
+
expect(instance.aiService).toBe(mockAIService);
|
|
112
|
+
expect(instance.otherService).toBeDefined();
|
|
113
|
+
expect(instance.otherService).toBe(otherService);
|
|
114
|
+
});
|
|
115
|
+
it('should throw error if AIService is not registered', async () => {
|
|
116
|
+
let TestClass = class TestClass {
|
|
117
|
+
constructor(aiService) {
|
|
118
|
+
this.aiService = aiService;
|
|
119
|
+
}
|
|
120
|
+
async testMethod(input) {
|
|
121
|
+
return input;
|
|
122
|
+
}
|
|
123
|
+
};
|
|
124
|
+
__decorate([
|
|
125
|
+
(0, ai_decorator_1.AITask)({
|
|
126
|
+
name: 'test-task',
|
|
127
|
+
prompt: 'Test prompt',
|
|
128
|
+
provider: 'openai',
|
|
129
|
+
model: 'gpt-3.5-turbo',
|
|
130
|
+
outputType: 'string',
|
|
131
|
+
}),
|
|
132
|
+
__metadata("design:type", Function),
|
|
133
|
+
__metadata("design:paramtypes", [String]),
|
|
134
|
+
__metadata("design:returntype", Promise)
|
|
135
|
+
], TestClass.prototype, "testMethod", null);
|
|
136
|
+
TestClass = __decorate([
|
|
137
|
+
(0, core_2.Injectable)(),
|
|
138
|
+
__metadata("design:paramtypes", [ai_service_1.AIService])
|
|
139
|
+
], TestClass);
|
|
140
|
+
container.clear();
|
|
141
|
+
// Don't register AIService
|
|
142
|
+
const instance = new TestClass(null);
|
|
143
|
+
container.register(TestClass, instance);
|
|
144
|
+
const resolved = container.resolve(TestClass);
|
|
145
|
+
// The error should be thrown when trying to execute the decorated method
|
|
146
|
+
await expect(resolved.testMethod('test')).rejects.toThrow('AI task execution failed: AI service not found. Make sure to inject AIService in the constructor.');
|
|
147
|
+
});
|
|
148
|
+
it('should execute AI task', async () => {
|
|
149
|
+
let TestClass = class TestClass {
|
|
150
|
+
constructor(aiService) {
|
|
151
|
+
this.aiService = aiService;
|
|
152
|
+
}
|
|
153
|
+
async testMethod(input) {
|
|
154
|
+
return input;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
__decorate([
|
|
158
|
+
(0, ai_decorator_1.AITask)({
|
|
159
|
+
name: 'test-task',
|
|
160
|
+
prompt: 'Test prompt',
|
|
161
|
+
provider: 'openai',
|
|
162
|
+
model: 'gpt-4',
|
|
163
|
+
temperature: 0.7,
|
|
164
|
+
outputType: 'string',
|
|
165
|
+
}),
|
|
166
|
+
__metadata("design:type", Function),
|
|
167
|
+
__metadata("design:paramtypes", [String]),
|
|
168
|
+
__metadata("design:returntype", Promise)
|
|
169
|
+
], TestClass.prototype, "testMethod", null);
|
|
170
|
+
TestClass = __decorate([
|
|
171
|
+
(0, core_2.Injectable)(),
|
|
172
|
+
__metadata("design:paramtypes", [ai_service_1.AIService])
|
|
173
|
+
], TestClass);
|
|
174
|
+
// Register the test class with AIService
|
|
175
|
+
container.register(TestClass, new TestClass(mockAIService));
|
|
176
|
+
const instance = container.resolve(TestClass);
|
|
177
|
+
const result = await instance.testMethod('test input');
|
|
178
|
+
expect(result).toBeDefined();
|
|
179
|
+
expect(result).toBe('Processed: test input');
|
|
180
|
+
expect(mockAIService.executeTask).toHaveBeenCalledWith(expect.objectContaining({
|
|
181
|
+
name: 'test-task',
|
|
182
|
+
provider: 'openai',
|
|
183
|
+
model: 'gpt-4',
|
|
184
|
+
temperature: 0.7,
|
|
185
|
+
prompt: 'Test prompt',
|
|
186
|
+
outputType: 'string',
|
|
187
|
+
}), 'test input');
|
|
188
|
+
});
|
|
189
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { AIProvider } from './ai-enhanced.types';
|
|
2
|
+
export interface AIModuleOptions {
|
|
3
|
+
defaultProvider?: AIProvider;
|
|
4
|
+
providers?: AIProvider[];
|
|
5
|
+
apiKeys?: Partial<Record<AIProvider, string>>;
|
|
6
|
+
}
|
|
7
|
+
export declare class AIModule {
|
|
8
|
+
private static options;
|
|
9
|
+
static register(options: AIModuleOptions): typeof AIModule;
|
|
10
|
+
static getOptions(): AIModuleOptions;
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=ai.module.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.module.d.ts","sourceRoot":"","sources":["../src/ai.module.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAEjD,MAAM,WAAW,eAAe;IAC9B,eAAe,CAAC,EAAE,UAAU,CAAC;IAC7B,SAAS,CAAC,EAAE,UAAU,EAAE,CAAC;IACzB,OAAO,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,CAAC,CAAC,CAAC;CAC/C;AAED,qBAIa,QAAQ;IACnB,OAAO,CAAC,MAAM,CAAC,OAAO,CAAuB;IAE7C,MAAM,CAAC,QAAQ,CAAC,OAAO,EAAE,eAAe,GAAG,OAAO,QAAQ;IAqB1D,MAAM,CAAC,UAAU,IAAI,eAAe;CAGrC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
|
3
|
+
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
4
|
+
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
5
|
+
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
|
6
|
+
return c > 3 && r && Object.defineProperty(target, key, r), r;
|
|
7
|
+
};
|
|
8
|
+
var AIModule_1;
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.AIModule = void 0;
|
|
11
|
+
const core_1 = require("@hazeljs/core");
|
|
12
|
+
const ai_service_1 = require("./ai.service");
|
|
13
|
+
const ai_enhanced_service_1 = require("./ai-enhanced.service");
|
|
14
|
+
let AIModule = AIModule_1 = class AIModule {
|
|
15
|
+
static register(options) {
|
|
16
|
+
AIModule_1.options = options;
|
|
17
|
+
// Set API keys in environment if provided (allows runtime configuration)
|
|
18
|
+
if (options.apiKeys) {
|
|
19
|
+
const keyMap = {
|
|
20
|
+
openai: 'OPENAI_API_KEY',
|
|
21
|
+
anthropic: 'ANTHROPIC_API_KEY',
|
|
22
|
+
gemini: 'GEMINI_API_KEY',
|
|
23
|
+
cohere: 'COHERE_API_KEY',
|
|
24
|
+
};
|
|
25
|
+
for (const [provider, key] of Object.entries(options.apiKeys)) {
|
|
26
|
+
if (key && keyMap[provider]) {
|
|
27
|
+
process.env[keyMap[provider]] = key;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
return AIModule_1;
|
|
32
|
+
}
|
|
33
|
+
static getOptions() {
|
|
34
|
+
return AIModule_1.options;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
exports.AIModule = AIModule;
|
|
38
|
+
AIModule.options = {};
|
|
39
|
+
exports.AIModule = AIModule = AIModule_1 = __decorate([
|
|
40
|
+
(0, core_1.HazelModule)({
|
|
41
|
+
providers: [ai_service_1.AIService, ai_enhanced_service_1.AIEnhancedService],
|
|
42
|
+
exports: [ai_service_1.AIService, ai_enhanced_service_1.AIEnhancedService],
|
|
43
|
+
})
|
|
44
|
+
], AIModule);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.module.test.d.ts","sourceRoot":"","sources":["../src/ai.module.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const ai_module_1 = require("./ai.module");
|
|
4
|
+
const ai_service_1 = require("./ai.service");
|
|
5
|
+
const core_1 = require("@hazeljs/core");
|
|
6
|
+
describe('AIModule', () => {
|
|
7
|
+
it('should be defined', () => {
|
|
8
|
+
expect(ai_module_1.AIModule).toBeDefined();
|
|
9
|
+
});
|
|
10
|
+
it('should provide AIService', () => {
|
|
11
|
+
const app = new core_1.HazelApp(ai_module_1.AIModule);
|
|
12
|
+
const container = app.getContainer();
|
|
13
|
+
const aiService = container.resolve(ai_service_1.AIService);
|
|
14
|
+
expect(aiService).toBeInstanceOf(ai_service_1.AIService);
|
|
15
|
+
});
|
|
16
|
+
it('should provide AIService as singleton', () => {
|
|
17
|
+
const app = new core_1.HazelApp(ai_module_1.AIModule);
|
|
18
|
+
const container = app.getContainer();
|
|
19
|
+
const service1 = container.resolve(ai_service_1.AIService);
|
|
20
|
+
const service2 = container.resolve(ai_service_1.AIService);
|
|
21
|
+
expect(service1).toBe(service2);
|
|
22
|
+
});
|
|
23
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { AITaskConfig, AITaskResult } from './ai.types';
|
|
2
|
+
import './prompts/task.prompt';
|
|
3
|
+
export declare class AIService {
|
|
4
|
+
private providers;
|
|
5
|
+
constructor();
|
|
6
|
+
private initializeProviders;
|
|
7
|
+
private formatPrompt;
|
|
8
|
+
private parseResponse;
|
|
9
|
+
executeTask(config: AITaskConfig, input: unknown): Promise<AITaskResult>;
|
|
10
|
+
}
|
|
11
|
+
//# sourceMappingURL=ai.service.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ai.service.d.ts","sourceRoot":"","sources":["../src/ai.service.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAiB,YAAY,EAAE,MAAM,YAAY,CAAC;AAIvE,OAAO,uBAAuB,CAAC;AAW/B,qBACa,SAAS;IACpB,OAAO,CAAC,SAAS,CAAsC;;IAOvD,OAAO,CAAC,mBAAmB;IAoL3B,OAAO,CAAC,YAAY;IAmBpB,OAAO,CAAC,aAAa;IAkBf,WAAW,CAAC,MAAM,EAAE,YAAY,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAAC,YAAY,CAAC;CAkC/E"}
|