@hazeljs/ai 0.2.0-beta.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.
Files changed (53) hide show
  1. package/README.md +496 -0
  2. package/dist/ai-enhanced.service.d.ts +108 -0
  3. package/dist/ai-enhanced.service.d.ts.map +1 -0
  4. package/dist/ai-enhanced.service.js +345 -0
  5. package/dist/ai-enhanced.types.d.ts +269 -0
  6. package/dist/ai-enhanced.types.d.ts.map +1 -0
  7. package/dist/ai-enhanced.types.js +2 -0
  8. package/dist/ai.decorator.d.ts +4 -0
  9. package/dist/ai.decorator.d.ts.map +1 -0
  10. package/dist/ai.decorator.js +57 -0
  11. package/dist/ai.module.d.ts +12 -0
  12. package/dist/ai.module.d.ts.map +1 -0
  13. package/dist/ai.module.js +44 -0
  14. package/dist/ai.service.d.ts +10 -0
  15. package/dist/ai.service.d.ts.map +1 -0
  16. package/dist/ai.service.js +261 -0
  17. package/dist/ai.types.d.ts +30 -0
  18. package/dist/ai.types.d.ts.map +1 -0
  19. package/dist/ai.types.js +2 -0
  20. package/dist/context/context.manager.d.ts +69 -0
  21. package/dist/context/context.manager.d.ts.map +1 -0
  22. package/dist/context/context.manager.js +168 -0
  23. package/dist/decorators/ai-function.decorator.d.ts +42 -0
  24. package/dist/decorators/ai-function.decorator.d.ts.map +1 -0
  25. package/dist/decorators/ai-function.decorator.js +80 -0
  26. package/dist/decorators/ai-validate.decorator.d.ts +46 -0
  27. package/dist/decorators/ai-validate.decorator.d.ts.map +1 -0
  28. package/dist/decorators/ai-validate.decorator.js +83 -0
  29. package/dist/index.d.ts +17 -0
  30. package/dist/index.d.ts.map +1 -0
  31. package/dist/index.js +38 -0
  32. package/dist/providers/anthropic.provider.d.ts +48 -0
  33. package/dist/providers/anthropic.provider.d.ts.map +1 -0
  34. package/dist/providers/anthropic.provider.js +194 -0
  35. package/dist/providers/cohere.provider.d.ts +57 -0
  36. package/dist/providers/cohere.provider.d.ts.map +1 -0
  37. package/dist/providers/cohere.provider.js +230 -0
  38. package/dist/providers/gemini.provider.d.ts +45 -0
  39. package/dist/providers/gemini.provider.d.ts.map +1 -0
  40. package/dist/providers/gemini.provider.js +180 -0
  41. package/dist/providers/ollama.provider.d.ts +45 -0
  42. package/dist/providers/ollama.provider.d.ts.map +1 -0
  43. package/dist/providers/ollama.provider.js +232 -0
  44. package/dist/providers/openai.provider.d.ts +47 -0
  45. package/dist/providers/openai.provider.d.ts.map +1 -0
  46. package/dist/providers/openai.provider.js +273 -0
  47. package/dist/tracking/token.tracker.d.ts +72 -0
  48. package/dist/tracking/token.tracker.d.ts.map +1 -0
  49. package/dist/tracking/token.tracker.js +222 -0
  50. package/dist/vector/vector.service.d.ts +50 -0
  51. package/dist/vector/vector.service.d.ts.map +1 -0
  52. package/dist/vector/vector.service.js +163 -0
  53. package/package.json +52 -0
@@ -0,0 +1,80 @@
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.AIFunction = AIFunction;
7
+ exports.getAIFunctionMetadata = getAIFunctionMetadata;
8
+ exports.hasAIFunctionMetadata = hasAIFunctionMetadata;
9
+ exports.AIPrompt = AIPrompt;
10
+ exports.getAIPromptMetadata = getAIPromptMetadata;
11
+ require("reflect-metadata");
12
+ const core_1 = __importDefault(require("@hazeljs/core"));
13
+ const AI_FUNCTION_METADATA_KEY = 'hazel:ai:function';
14
+ const AI_PROMPT_METADATA_KEY = 'hazel:ai:prompt';
15
+ /**
16
+ * AIFunction decorator for AI-powered methods
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * @AIFunction({
21
+ * provider: 'openai',
22
+ * model: 'gpt-4',
23
+ * streaming: true
24
+ * })
25
+ * async generateContent(@AIPrompt() prompt: string) {
26
+ * // Auto-handled by framework
27
+ * }
28
+ * ```
29
+ */
30
+ function AIFunction(options) {
31
+ return (target, propertyKey, descriptor) => {
32
+ const defaults = {
33
+ streaming: false,
34
+ temperature: 0.7,
35
+ maxTokens: 1000,
36
+ ...options,
37
+ };
38
+ Reflect.defineMetadata(AI_FUNCTION_METADATA_KEY, defaults, target, propertyKey);
39
+ core_1.default.debug(`AIFunction decorator applied to ${target.constructor.name}.${String(propertyKey)}`);
40
+ return descriptor;
41
+ };
42
+ }
43
+ /**
44
+ * Get AI function metadata
45
+ */
46
+ function getAIFunctionMetadata(target, propertyKey) {
47
+ return Reflect.getMetadata(AI_FUNCTION_METADATA_KEY, target, propertyKey);
48
+ }
49
+ /**
50
+ * Check if method has AI function metadata
51
+ */
52
+ function hasAIFunctionMetadata(target, propertyKey) {
53
+ return Reflect.hasMetadata(AI_FUNCTION_METADATA_KEY, target, propertyKey);
54
+ }
55
+ /**
56
+ * AIPrompt parameter decorator
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * async generateContent(@AIPrompt() prompt: string) {
61
+ * // prompt parameter is marked for AI processing
62
+ * }
63
+ * ```
64
+ */
65
+ function AIPrompt() {
66
+ return (target, propertyKey, parameterIndex) => {
67
+ const existingParams = Reflect.getMetadata(AI_PROMPT_METADATA_KEY, target, propertyKey) || [];
68
+ existingParams[parameterIndex] = 'prompt';
69
+ Reflect.defineMetadata(AI_PROMPT_METADATA_KEY, existingParams, target, propertyKey);
70
+ };
71
+ }
72
+ /**
73
+ * Get AI prompt parameter metadata
74
+ */
75
+ function getAIPromptMetadata(target, propertyKey) {
76
+ const params = Reflect.getMetadata(AI_PROMPT_METADATA_KEY, target, propertyKey) || [];
77
+ return params
78
+ .map((p, index) => (p === 'prompt' ? index : -1))
79
+ .filter((i) => i !== -1);
80
+ }
@@ -0,0 +1,46 @@
1
+ import 'reflect-metadata';
2
+ import { AIValidationOptions } from '../ai-enhanced.types';
3
+ /**
4
+ * AIValidate decorator for AI-powered validation
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * @AIValidate({
9
+ * provider: 'openai',
10
+ * instruction: 'Validate if this is a professional email'
11
+ * })
12
+ * export class ContactDto {
13
+ * @IsEmail()
14
+ * email: string;
15
+ * }
16
+ * ```
17
+ */
18
+ export declare function AIValidate(options: AIValidationOptions): ClassDecorator;
19
+ /**
20
+ * Get AI validation metadata
21
+ */
22
+ export declare function getAIValidationMetadata(target: object): AIValidationOptions | undefined;
23
+ /**
24
+ * Check if class has AI validation metadata
25
+ */
26
+ export declare function hasAIValidationMetadata(target: object): boolean;
27
+ /**
28
+ * AIValidateProperty decorator for property-level validation
29
+ *
30
+ * @example
31
+ * ```typescript
32
+ * export class UserDto {
33
+ * @AIValidateProperty({
34
+ * provider: 'openai',
35
+ * instruction: 'Check if this username is appropriate'
36
+ * })
37
+ * username: string;
38
+ * }
39
+ * ```
40
+ */
41
+ export declare function AIValidateProperty(options: AIValidationOptions): PropertyDecorator;
42
+ /**
43
+ * Get AI property validation metadata
44
+ */
45
+ export declare function getAIPropertyValidationMetadata(target: object, propertyKey: string | symbol): AIValidationOptions | undefined;
46
+ //# sourceMappingURL=ai-validate.decorator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ai-validate.decorator.d.ts","sourceRoot":"","sources":["../../src/decorators/ai-validate.decorator.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAC1B,OAAO,EAAE,mBAAmB,EAAE,MAAM,sBAAsB,CAAC;AAK3D;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,mBAAmB,GAAG,cAAc,CAYvE;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,mBAAmB,GAAG,SAAS,CAEvF;AAED;;GAEG;AACH,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,OAAO,CAE/D;AAED;;;;;;;;;;;;;GAaG;AACH,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,mBAAmB,GAAG,iBAAiB,CAalF;AAED;;GAEG;AACH,wBAAgB,+BAA+B,CAC7C,MAAM,EAAE,MAAM,EACd,WAAW,EAAE,MAAM,GAAG,MAAM,GAC3B,mBAAmB,GAAG,SAAS,CAEjC"}
@@ -0,0 +1,83 @@
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.AIValidate = AIValidate;
7
+ exports.getAIValidationMetadata = getAIValidationMetadata;
8
+ exports.hasAIValidationMetadata = hasAIValidationMetadata;
9
+ exports.AIValidateProperty = AIValidateProperty;
10
+ exports.getAIPropertyValidationMetadata = getAIPropertyValidationMetadata;
11
+ require("reflect-metadata");
12
+ const core_1 = __importDefault(require("@hazeljs/core"));
13
+ const AI_VALIDATE_METADATA_KEY = 'hazel:ai:validate';
14
+ /**
15
+ * AIValidate decorator for AI-powered validation
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * @AIValidate({
20
+ * provider: 'openai',
21
+ * instruction: 'Validate if this is a professional email'
22
+ * })
23
+ * export class ContactDto {
24
+ * @IsEmail()
25
+ * email: string;
26
+ * }
27
+ * ```
28
+ */
29
+ function AIValidate(options) {
30
+ return (target) => {
31
+ const defaults = {
32
+ model: 'gpt-3.5-turbo',
33
+ failOnInvalid: true,
34
+ ...options,
35
+ };
36
+ Reflect.defineMetadata(AI_VALIDATE_METADATA_KEY, defaults, target);
37
+ const className = target.name || 'Unknown';
38
+ core_1.default.debug(`AIValidate decorator applied to ${className}`);
39
+ };
40
+ }
41
+ /**
42
+ * Get AI validation metadata
43
+ */
44
+ function getAIValidationMetadata(target) {
45
+ return Reflect.getMetadata(AI_VALIDATE_METADATA_KEY, target);
46
+ }
47
+ /**
48
+ * Check if class has AI validation metadata
49
+ */
50
+ function hasAIValidationMetadata(target) {
51
+ return Reflect.hasMetadata(AI_VALIDATE_METADATA_KEY, target);
52
+ }
53
+ /**
54
+ * AIValidateProperty decorator for property-level validation
55
+ *
56
+ * @example
57
+ * ```typescript
58
+ * export class UserDto {
59
+ * @AIValidateProperty({
60
+ * provider: 'openai',
61
+ * instruction: 'Check if this username is appropriate'
62
+ * })
63
+ * username: string;
64
+ * }
65
+ * ```
66
+ */
67
+ function AIValidateProperty(options) {
68
+ return (target, propertyKey) => {
69
+ const defaults = {
70
+ model: 'gpt-3.5-turbo',
71
+ failOnInvalid: true,
72
+ ...options,
73
+ };
74
+ Reflect.defineMetadata(`${AI_VALIDATE_METADATA_KEY}:${String(propertyKey)}`, defaults, target);
75
+ core_1.default.debug(`AIValidateProperty decorator applied to ${target.constructor.name}.${String(propertyKey)}`);
76
+ };
77
+ }
78
+ /**
79
+ * Get AI property validation metadata
80
+ */
81
+ function getAIPropertyValidationMetadata(target, propertyKey) {
82
+ return Reflect.getMetadata(`${AI_VALIDATE_METADATA_KEY}:${String(propertyKey)}`, target);
83
+ }
@@ -0,0 +1,17 @@
1
+ /**
2
+ * @hazeljs/ai - AI integration module for HazelJS
3
+ */
4
+ export { AIModule } from './ai.module';
5
+ export { AIService } from './ai.service';
6
+ export type { AITaskConfig, AITaskContext, AITaskResult } from './ai.types';
7
+ export { AITask } from './ai.decorator';
8
+ export { OpenAIProvider } from './providers/openai.provider';
9
+ export { AnthropicProvider } from './providers/anthropic.provider';
10
+ export { GeminiProvider } from './providers/gemini.provider';
11
+ export { CohereProvider } from './providers/cohere.provider';
12
+ export { OllamaProvider } from './providers/ollama.provider';
13
+ export { AIFunction, AIPrompt, getAIFunctionMetadata, hasAIFunctionMetadata, getAIPromptMetadata, } from './decorators/ai-function.decorator';
14
+ export { AIValidate, AIValidateProperty, getAIValidationMetadata, hasAIValidationMetadata, getAIPropertyValidationMetadata, } from './decorators/ai-validate.decorator';
15
+ export { VectorService } from './vector/vector.service';
16
+ export { type AIProvider, type AIModelConfig, type AIMessageRole, type AIMessage, type AICompletionRequest, type AICompletionResponse, type AIStreamChunk, type AIFunction as AIFunctionType, type AIEmbeddingRequest, type AIEmbeddingResponse, type IAIProvider, type VectorDatabase, type VectorStoreConfig, type VectorDocument, type VectorSearchRequest, type VectorSearchResult, type AIContext, type TokenUsage, type TokenLimitConfig, type AIFunctionOptions, type AIValidationOptions, } from './ai-enhanced.types';
17
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACvC,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,YAAY,EAAE,YAAY,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC5E,OAAO,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAGxC,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CAAC;AACnE,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AAC7D,OAAO,EACL,UAAU,EACV,QAAQ,EACR,qBAAqB,EACrB,qBAAqB,EACrB,mBAAmB,GACpB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EACL,UAAU,EACV,kBAAkB,EAClB,uBAAuB,EACvB,uBAAuB,EACvB,+BAA+B,GAChC,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAE,aAAa,EAAE,MAAM,yBAAyB,CAAC;AACxD,OAAO,EACL,KAAK,UAAU,EACf,KAAK,aAAa,EAClB,KAAK,aAAa,EAClB,KAAK,SAAS,EACd,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,UAAU,IAAI,cAAc,EACjC,KAAK,kBAAkB,EACvB,KAAK,mBAAmB,EACxB,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,iBAAiB,EACtB,KAAK,cAAc,EACnB,KAAK,mBAAmB,EACxB,KAAK,kBAAkB,EACvB,KAAK,SAAS,EACd,KAAK,UAAU,EACf,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,KAAK,mBAAmB,GACzB,MAAM,qBAAqB,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,38 @@
1
+ "use strict";
2
+ /**
3
+ * @hazeljs/ai - AI integration module for HazelJS
4
+ */
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.VectorService = exports.getAIPropertyValidationMetadata = exports.hasAIValidationMetadata = exports.getAIValidationMetadata = exports.AIValidateProperty = exports.AIValidate = exports.getAIPromptMetadata = exports.hasAIFunctionMetadata = exports.getAIFunctionMetadata = exports.AIPrompt = exports.AIFunction = exports.OllamaProvider = exports.CohereProvider = exports.GeminiProvider = exports.AnthropicProvider = exports.OpenAIProvider = exports.AITask = exports.AIService = exports.AIModule = void 0;
7
+ // AI Module
8
+ var ai_module_1 = require("./ai.module");
9
+ Object.defineProperty(exports, "AIModule", { enumerable: true, get: function () { return ai_module_1.AIModule; } });
10
+ var ai_service_1 = require("./ai.service");
11
+ Object.defineProperty(exports, "AIService", { enumerable: true, get: function () { return ai_service_1.AIService; } });
12
+ var ai_decorator_1 = require("./ai.decorator");
13
+ Object.defineProperty(exports, "AITask", { enumerable: true, get: function () { return ai_decorator_1.AITask; } });
14
+ // Enhanced AI
15
+ var openai_provider_1 = require("./providers/openai.provider");
16
+ Object.defineProperty(exports, "OpenAIProvider", { enumerable: true, get: function () { return openai_provider_1.OpenAIProvider; } });
17
+ var anthropic_provider_1 = require("./providers/anthropic.provider");
18
+ Object.defineProperty(exports, "AnthropicProvider", { enumerable: true, get: function () { return anthropic_provider_1.AnthropicProvider; } });
19
+ var gemini_provider_1 = require("./providers/gemini.provider");
20
+ Object.defineProperty(exports, "GeminiProvider", { enumerable: true, get: function () { return gemini_provider_1.GeminiProvider; } });
21
+ var cohere_provider_1 = require("./providers/cohere.provider");
22
+ Object.defineProperty(exports, "CohereProvider", { enumerable: true, get: function () { return cohere_provider_1.CohereProvider; } });
23
+ var ollama_provider_1 = require("./providers/ollama.provider");
24
+ Object.defineProperty(exports, "OllamaProvider", { enumerable: true, get: function () { return ollama_provider_1.OllamaProvider; } });
25
+ var ai_function_decorator_1 = require("./decorators/ai-function.decorator");
26
+ Object.defineProperty(exports, "AIFunction", { enumerable: true, get: function () { return ai_function_decorator_1.AIFunction; } });
27
+ Object.defineProperty(exports, "AIPrompt", { enumerable: true, get: function () { return ai_function_decorator_1.AIPrompt; } });
28
+ Object.defineProperty(exports, "getAIFunctionMetadata", { enumerable: true, get: function () { return ai_function_decorator_1.getAIFunctionMetadata; } });
29
+ Object.defineProperty(exports, "hasAIFunctionMetadata", { enumerable: true, get: function () { return ai_function_decorator_1.hasAIFunctionMetadata; } });
30
+ Object.defineProperty(exports, "getAIPromptMetadata", { enumerable: true, get: function () { return ai_function_decorator_1.getAIPromptMetadata; } });
31
+ var ai_validate_decorator_1 = require("./decorators/ai-validate.decorator");
32
+ Object.defineProperty(exports, "AIValidate", { enumerable: true, get: function () { return ai_validate_decorator_1.AIValidate; } });
33
+ Object.defineProperty(exports, "AIValidateProperty", { enumerable: true, get: function () { return ai_validate_decorator_1.AIValidateProperty; } });
34
+ Object.defineProperty(exports, "getAIValidationMetadata", { enumerable: true, get: function () { return ai_validate_decorator_1.getAIValidationMetadata; } });
35
+ Object.defineProperty(exports, "hasAIValidationMetadata", { enumerable: true, get: function () { return ai_validate_decorator_1.hasAIValidationMetadata; } });
36
+ Object.defineProperty(exports, "getAIPropertyValidationMetadata", { enumerable: true, get: function () { return ai_validate_decorator_1.getAIPropertyValidationMetadata; } });
37
+ var vector_service_1 = require("./vector/vector.service");
38
+ Object.defineProperty(exports, "VectorService", { enumerable: true, get: function () { return vector_service_1.VectorService; } });
@@ -0,0 +1,48 @@
1
+ import { IAIProvider, AIProvider, AICompletionRequest, AICompletionResponse, AIStreamChunk, AIEmbeddingRequest, AIEmbeddingResponse } from '../ai-enhanced.types';
2
+ /**
3
+ * Anthropic Claude AI Provider
4
+ *
5
+ * Production-ready implementation using Anthropic SDK.
6
+ *
7
+ * Setup:
8
+ * 1. Install the SDK: `npm install @anthropic-ai/sdk`
9
+ * 2. Set ANTHROPIC_API_KEY environment variable
10
+ * 3. Use the provider in your application
11
+ *
12
+ * Supported models:
13
+ * - claude-3-5-sonnet-20241022: Latest and most intelligent model
14
+ * - claude-3-opus-20240229: Most powerful for complex tasks
15
+ * - claude-3-sonnet-20240229: Balanced performance
16
+ * - claude-3-haiku-20240307: Fast and cost-effective
17
+ *
18
+ * Note: Anthropic does not provide embeddings API. Use OpenAI or Cohere for embeddings.
19
+ */
20
+ export declare class AnthropicProvider implements IAIProvider {
21
+ readonly name: AIProvider;
22
+ private apiKey;
23
+ private anthropic;
24
+ private endpoint;
25
+ constructor(apiKey?: string, endpoint?: string);
26
+ /**
27
+ * Generate completion
28
+ */
29
+ complete(request: AICompletionRequest): Promise<AICompletionResponse>;
30
+ /**
31
+ * Generate streaming completion
32
+ */
33
+ streamComplete(request: AICompletionRequest): AsyncGenerator<AIStreamChunk>;
34
+ /**
35
+ * Generate embeddings
36
+ * Note: Anthropic doesn't provide embeddings API
37
+ */
38
+ embed(_request: AIEmbeddingRequest): Promise<AIEmbeddingResponse>;
39
+ /**
40
+ * Check if provider is available
41
+ */
42
+ isAvailable(): Promise<boolean>;
43
+ /**
44
+ * Get supported models
45
+ */
46
+ getSupportedModels(): string[];
47
+ }
48
+ //# sourceMappingURL=anthropic.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic.provider.d.ts","sourceRoot":"","sources":["../../src/providers/anthropic.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAI9B;;;;;;;;;;;;;;;;;GAiBG;AACH,qBAAa,iBAAkB,YAAW,WAAW;IACnD,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAe;IACxC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,SAAS,CAAY;IAC7B,OAAO,CAAC,QAAQ,CAAS;gBAEb,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;IAY9C;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAiD3E;;OAEG;IACI,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,cAAc,CAAC,aAAa,CAAC;IAsElF;;;OAGG;IACG,KAAK,CAAC,QAAQ,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAIvE;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAoBrC;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;CAW/B"}
@@ -0,0 +1,194 @@
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.AnthropicProvider = void 0;
7
+ const core_1 = __importDefault(require("@hazeljs/core"));
8
+ const sdk_1 = __importDefault(require("@anthropic-ai/sdk"));
9
+ /**
10
+ * Anthropic Claude AI Provider
11
+ *
12
+ * Production-ready implementation using Anthropic SDK.
13
+ *
14
+ * Setup:
15
+ * 1. Install the SDK: `npm install @anthropic-ai/sdk`
16
+ * 2. Set ANTHROPIC_API_KEY environment variable
17
+ * 3. Use the provider in your application
18
+ *
19
+ * Supported models:
20
+ * - claude-3-5-sonnet-20241022: Latest and most intelligent model
21
+ * - claude-3-opus-20240229: Most powerful for complex tasks
22
+ * - claude-3-sonnet-20240229: Balanced performance
23
+ * - claude-3-haiku-20240307: Fast and cost-effective
24
+ *
25
+ * Note: Anthropic does not provide embeddings API. Use OpenAI or Cohere for embeddings.
26
+ */
27
+ class AnthropicProvider {
28
+ constructor(apiKey, endpoint) {
29
+ this.name = 'anthropic';
30
+ this.apiKey = apiKey || process.env.ANTHROPIC_API_KEY || '';
31
+ this.endpoint = endpoint || 'https://api.anthropic.com/v1';
32
+ if (!this.apiKey) {
33
+ core_1.default.warn('Anthropic API key not provided. Set ANTHROPIC_API_KEY environment variable.');
34
+ }
35
+ this.anthropic = new sdk_1.default({ apiKey: this.apiKey });
36
+ core_1.default.info('Anthropic provider initialized');
37
+ }
38
+ /**
39
+ * Generate completion
40
+ */
41
+ async complete(request) {
42
+ const modelName = request.model || 'claude-3-5-sonnet-20241022';
43
+ core_1.default.debug(`Anthropic completion request for model: ${modelName}`);
44
+ try {
45
+ // Separate system messages from conversation messages
46
+ const systemMessages = request.messages.filter((m) => m.role === 'system');
47
+ const conversationMessages = request.messages.filter((m) => m.role !== 'system');
48
+ const systemPrompt = systemMessages.map((m) => m.content).join('\n\n');
49
+ // Create message request
50
+ const response = await this.anthropic.messages.create({
51
+ model: modelName,
52
+ max_tokens: request.maxTokens || 4096,
53
+ temperature: request.temperature,
54
+ system: systemPrompt || undefined,
55
+ messages: conversationMessages.map((m) => ({
56
+ role: m.role,
57
+ content: m.content,
58
+ })),
59
+ });
60
+ // Extract text content
61
+ const textContent = response.content
62
+ .filter((block) => block.type === 'text')
63
+ .map((block) => block.text)
64
+ .join('');
65
+ return {
66
+ id: response.id,
67
+ content: textContent,
68
+ role: 'assistant',
69
+ model: response.model,
70
+ usage: {
71
+ promptTokens: response.usage.input_tokens,
72
+ completionTokens: response.usage.output_tokens,
73
+ totalTokens: response.usage.input_tokens + response.usage.output_tokens,
74
+ },
75
+ finishReason: response.stop_reason || 'end_turn',
76
+ };
77
+ }
78
+ catch (error) {
79
+ core_1.default.error('Anthropic completion error:', error);
80
+ throw new Error(`Anthropic API error: ${error instanceof Error ? error.message : 'Unknown error'}`);
81
+ }
82
+ }
83
+ /**
84
+ * Generate streaming completion
85
+ */
86
+ async *streamComplete(request) {
87
+ const modelName = request.model || 'claude-3-5-sonnet-20241022';
88
+ core_1.default.debug('Anthropic streaming completion started');
89
+ try {
90
+ // Separate system messages from conversation messages
91
+ const systemMessages = request.messages.filter((m) => m.role === 'system');
92
+ const conversationMessages = request.messages.filter((m) => m.role !== 'system');
93
+ const systemPrompt = systemMessages.map((m) => m.content).join('\n\n');
94
+ // Create streaming request
95
+ const stream = await this.anthropic.messages.stream({
96
+ model: modelName,
97
+ max_tokens: request.maxTokens || 4096,
98
+ temperature: request.temperature,
99
+ system: systemPrompt || undefined,
100
+ messages: conversationMessages.map((m) => ({
101
+ role: m.role,
102
+ content: m.content,
103
+ })),
104
+ });
105
+ let fullContent = '';
106
+ let messageId = '';
107
+ let inputTokens = 0;
108
+ let outputTokens = 0;
109
+ for await (const event of stream) {
110
+ if (event.type === 'message_start') {
111
+ messageId = event.message.id;
112
+ inputTokens = event.message.usage.input_tokens;
113
+ }
114
+ else if (event.type === 'content_block_delta') {
115
+ if (event.delta.type === 'text_delta') {
116
+ const text = event.delta.text;
117
+ fullContent += text;
118
+ yield {
119
+ id: messageId || `claude-stream-${Date.now()}`,
120
+ content: fullContent,
121
+ delta: text,
122
+ done: false,
123
+ };
124
+ }
125
+ }
126
+ else if (event.type === 'message_delta') {
127
+ outputTokens = event.usage.output_tokens;
128
+ }
129
+ else if (event.type === 'message_stop') {
130
+ yield {
131
+ id: messageId || `claude-stream-${Date.now()}`,
132
+ content: fullContent,
133
+ delta: '',
134
+ done: true,
135
+ usage: {
136
+ promptTokens: inputTokens,
137
+ completionTokens: outputTokens,
138
+ totalTokens: inputTokens + outputTokens,
139
+ },
140
+ };
141
+ }
142
+ }
143
+ core_1.default.debug('Anthropic streaming completed');
144
+ }
145
+ catch (error) {
146
+ core_1.default.error('Anthropic streaming error:', error);
147
+ throw new Error(`Anthropic streaming error: ${error instanceof Error ? error.message : 'Unknown error'}`);
148
+ }
149
+ }
150
+ /**
151
+ * Generate embeddings
152
+ * Note: Anthropic doesn't provide embeddings API
153
+ */
154
+ async embed(_request) {
155
+ throw new Error('Anthropic does not support embeddings. Use OpenAI or Cohere instead.');
156
+ }
157
+ /**
158
+ * Check if provider is available
159
+ */
160
+ async isAvailable() {
161
+ if (!this.apiKey) {
162
+ core_1.default.warn('Anthropic API key not configured');
163
+ return false;
164
+ }
165
+ try {
166
+ // Test with a minimal request using fastest model
167
+ await this.anthropic.messages.create({
168
+ model: 'claude-3-haiku-20240307',
169
+ max_tokens: 10,
170
+ messages: [{ role: 'user', content: 'test' }],
171
+ });
172
+ return true;
173
+ }
174
+ catch (error) {
175
+ core_1.default.error('Anthropic availability check failed:', error);
176
+ return false;
177
+ }
178
+ }
179
+ /**
180
+ * Get supported models
181
+ */
182
+ getSupportedModels() {
183
+ return [
184
+ 'claude-3-5-sonnet-20241022',
185
+ 'claude-3-5-sonnet-20240620',
186
+ 'claude-3-opus-20240229',
187
+ 'claude-3-sonnet-20240229',
188
+ 'claude-3-haiku-20240307',
189
+ 'claude-2.1',
190
+ 'claude-2.0',
191
+ ];
192
+ }
193
+ }
194
+ exports.AnthropicProvider = AnthropicProvider;
@@ -0,0 +1,57 @@
1
+ import { IAIProvider, AIProvider, AICompletionRequest, AICompletionResponse, AIStreamChunk, AIEmbeddingRequest, AIEmbeddingResponse } from '../ai-enhanced.types';
2
+ /**
3
+ * Cohere AI Provider
4
+ *
5
+ * Production-ready implementation using Cohere AI SDK.
6
+ *
7
+ * Setup:
8
+ * 1. Install the SDK: `npm install cohere-ai`
9
+ * 2. Set COHERE_API_KEY environment variable
10
+ * 3. Use the provider in your application
11
+ *
12
+ * Supported models:
13
+ * - command-r-plus: Most powerful model for complex tasks
14
+ * - command-r: Balanced performance and cost
15
+ * - command: Standard text generation
16
+ * - command-light: Fast, cost-effective model
17
+ * - embed-english-v3.0: English text embeddings
18
+ * - embed-multilingual-v3.0: Multilingual embeddings
19
+ * - rerank-english-v3.0: Document reranking
20
+ */
21
+ export declare class CohereProvider implements IAIProvider {
22
+ readonly name: AIProvider;
23
+ private apiKey;
24
+ private cohere;
25
+ private endpoint;
26
+ constructor(apiKey?: string, endpoint?: string);
27
+ /**
28
+ * Generate completion
29
+ */
30
+ complete(request: AICompletionRequest): Promise<AICompletionResponse>;
31
+ /**
32
+ * Generate streaming completion
33
+ */
34
+ streamComplete(request: AICompletionRequest): AsyncGenerator<AIStreamChunk>;
35
+ /**
36
+ * Generate embeddings
37
+ */
38
+ embed(request: AIEmbeddingRequest): Promise<AIEmbeddingResponse>;
39
+ /**
40
+ * Check if provider is available
41
+ */
42
+ isAvailable(): Promise<boolean>;
43
+ /**
44
+ * Get supported models
45
+ */
46
+ getSupportedModels(): string[];
47
+ /**
48
+ * Rerank documents (Cohere-specific feature)
49
+ * Useful for RAG applications to improve retrieval quality
50
+ */
51
+ rerank(query: string, documents: string[], topN?: number, model?: string): Promise<Array<{
52
+ index: number;
53
+ score: number;
54
+ document: string;
55
+ }>>;
56
+ }
57
+ //# sourceMappingURL=cohere.provider.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cohere.provider.d.ts","sourceRoot":"","sources":["../../src/providers/cohere.provider.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,WAAW,EACX,UAAU,EACV,mBAAmB,EACnB,oBAAoB,EACpB,aAAa,EACb,kBAAkB,EAClB,mBAAmB,EACpB,MAAM,sBAAsB,CAAC;AAI9B;;;;;;;;;;;;;;;;;;GAkBG;AACH,qBAAa,cAAe,YAAW,WAAW;IAChD,QAAQ,CAAC,IAAI,EAAE,UAAU,CAAY;IACrC,OAAO,CAAC,MAAM,CAAS;IACvB,OAAO,CAAC,MAAM,CAAe;IAC7B,OAAO,CAAC,QAAQ,CAAS;gBAEb,MAAM,CAAC,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM;IAY9C;;OAEG;IACG,QAAQ,CAAC,OAAO,EAAE,mBAAmB,GAAG,OAAO,CAAC,oBAAoB,CAAC;IAuC3E;;OAEG;IACI,cAAc,CAAC,OAAO,EAAE,mBAAmB,GAAG,cAAc,CAAC,aAAa,CAAC;IA4DlF;;OAEG;IACG,KAAK,CAAC,OAAO,EAAE,kBAAkB,GAAG,OAAO,CAAC,mBAAmB,CAAC;IAsCtE;;OAEG;IACG,WAAW,IAAI,OAAO,CAAC,OAAO,CAAC;IAoBrC;;OAEG;IACH,kBAAkB,IAAI,MAAM,EAAE;IAgB9B;;;OAGG;IACG,MAAM,CACV,KAAK,EAAE,MAAM,EACb,SAAS,EAAE,MAAM,EAAE,EACnB,IAAI,CAAC,EAAE,MAAM,EACb,KAAK,CAAC,EAAE,MAAM,GACb,OAAO,CAAC,KAAK,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAC,CAAC;CAwBtE"}