@lockllm/sdk 1.0.0

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 (72) hide show
  1. package/CHANGELOG.md +81 -0
  2. package/CODE_OF_CONDUCT.md +130 -0
  3. package/CONTRIBUTING.md +259 -0
  4. package/LICENSE +21 -0
  5. package/README.md +928 -0
  6. package/SECURITY.md +261 -0
  7. package/dist/client.d.ts +39 -0
  8. package/dist/client.d.ts.map +1 -0
  9. package/dist/client.js +65 -0
  10. package/dist/client.js.map +1 -0
  11. package/dist/client.mjs +61 -0
  12. package/dist/errors.d.ts +60 -0
  13. package/dist/errors.d.ts.map +1 -0
  14. package/dist/errors.js +175 -0
  15. package/dist/errors.js.map +1 -0
  16. package/dist/errors.mjs +164 -0
  17. package/dist/index.d.ts +17 -0
  18. package/dist/index.d.ts.map +1 -0
  19. package/dist/index.js +49 -0
  20. package/dist/index.js.map +1 -0
  21. package/dist/index.mjs +17 -0
  22. package/dist/scan.d.ts +32 -0
  23. package/dist/scan.d.ts.map +1 -0
  24. package/dist/scan.js +40 -0
  25. package/dist/scan.js.map +1 -0
  26. package/dist/scan.mjs +36 -0
  27. package/dist/types/common.d.ts +31 -0
  28. package/dist/types/common.d.ts.map +1 -0
  29. package/dist/types/common.js +6 -0
  30. package/dist/types/common.js.map +1 -0
  31. package/dist/types/common.mjs +5 -0
  32. package/dist/types/errors.d.ts +22 -0
  33. package/dist/types/errors.d.ts.map +1 -0
  34. package/dist/types/errors.js +6 -0
  35. package/dist/types/errors.js.map +1 -0
  36. package/dist/types/errors.mjs +5 -0
  37. package/dist/types/providers.d.ts +24 -0
  38. package/dist/types/providers.d.ts.map +1 -0
  39. package/dist/types/providers.js +26 -0
  40. package/dist/types/providers.js.map +1 -0
  41. package/dist/types/providers.mjs +23 -0
  42. package/dist/types/scan.d.ts +36 -0
  43. package/dist/types/scan.d.ts.map +1 -0
  44. package/dist/types/scan.js +6 -0
  45. package/dist/types/scan.js.map +1 -0
  46. package/dist/types/scan.mjs +5 -0
  47. package/dist/utils.d.ts +84 -0
  48. package/dist/utils.d.ts.map +1 -0
  49. package/dist/utils.js +225 -0
  50. package/dist/utils.js.map +1 -0
  51. package/dist/utils.mjs +215 -0
  52. package/dist/wrappers/anthropic-wrapper.d.ts +72 -0
  53. package/dist/wrappers/anthropic-wrapper.d.ts.map +1 -0
  54. package/dist/wrappers/anthropic-wrapper.js +78 -0
  55. package/dist/wrappers/anthropic-wrapper.js.map +1 -0
  56. package/dist/wrappers/anthropic-wrapper.mjs +74 -0
  57. package/dist/wrappers/generic-wrapper.d.ts +180 -0
  58. package/dist/wrappers/generic-wrapper.d.ts.map +1 -0
  59. package/dist/wrappers/generic-wrapper.js +246 -0
  60. package/dist/wrappers/generic-wrapper.js.map +1 -0
  61. package/dist/wrappers/generic-wrapper.mjs +225 -0
  62. package/dist/wrappers/index.d.ts +27 -0
  63. package/dist/wrappers/index.d.ts.map +1 -0
  64. package/dist/wrappers/index.js +48 -0
  65. package/dist/wrappers/index.js.map +1 -0
  66. package/dist/wrappers/index.mjs +26 -0
  67. package/dist/wrappers/openai-wrapper.d.ts +70 -0
  68. package/dist/wrappers/openai-wrapper.d.ts.map +1 -0
  69. package/dist/wrappers/openai-wrapper.js +76 -0
  70. package/dist/wrappers/openai-wrapper.js.map +1 -0
  71. package/dist/wrappers/openai-wrapper.mjs +72 -0
  72. package/package.json +106 -0
@@ -0,0 +1,78 @@
1
+ "use strict";
2
+ /**
3
+ * Anthropic SDK wrapper - Drop-in replacement
4
+ *
5
+ * This wrapper allows you to use the official Anthropic SDK with LockLLM protection
6
+ * by simply changing how you initialize the client.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * // Replace this:
11
+ * // import Anthropic from '@anthropic-ai/sdk';
12
+ * // const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
13
+ *
14
+ * // With this:
15
+ * import { createAnthropic } from '@lockllm/sdk/wrappers';
16
+ * const anthropic = createAnthropic({
17
+ * apiKey: process.env.LOCKLLM_API_KEY
18
+ * });
19
+ *
20
+ * // Everything else stays the same!
21
+ * const message = await anthropic.messages.create({
22
+ * model: "claude-3-5-sonnet-20241022",
23
+ * max_tokens: 1024,
24
+ * messages: [{ role: "user", content: "Hello!" }]
25
+ * });
26
+ * ```
27
+ */
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.getAnthropicConstructor = getAnthropicConstructor;
30
+ exports.createAnthropic = createAnthropic;
31
+ /**
32
+ * Create an Anthropic client that routes through LockLLM proxy
33
+ *
34
+ * All requests are automatically scanned for prompt injection before being
35
+ * forwarded to Anthropic. Your Anthropic API key should be configured in the
36
+ * LockLLM dashboard at https://www.lockllm.com/dashboard
37
+ *
38
+ * @param config - Configuration options
39
+ * @returns Anthropic client instance
40
+ *
41
+ * @example
42
+ * ```typescript
43
+ * const anthropic = createAnthropic({
44
+ * apiKey: process.env.LOCKLLM_API_KEY
45
+ * });
46
+ *
47
+ * const message = await anthropic.messages.create({
48
+ * model: "claude-3-5-sonnet-20241022",
49
+ * max_tokens: 1024,
50
+ * messages: [{ role: "user", content: "Hello!" }]
51
+ * });
52
+ * ```
53
+ */
54
+ /**
55
+ * Lazy-load Anthropic SDK constructor
56
+ * @internal - exposed for testing purposes
57
+ */
58
+ function getAnthropicConstructor(requireFn = require) {
59
+ try {
60
+ const anthropicModule = requireFn('@anthropic-ai/sdk');
61
+ return anthropicModule.default || anthropicModule.Anthropic || anthropicModule;
62
+ }
63
+ catch (error) {
64
+ throw new Error('Anthropic SDK not found. Please install it with: npm install @anthropic-ai/sdk');
65
+ }
66
+ }
67
+ function createAnthropic(config) {
68
+ // Get Anthropic SDK constructor
69
+ const AnthropicConstructor = getAnthropicConstructor();
70
+ const { apiKey, baseURL, ...otherOptions } = config;
71
+ // Create Anthropic client with LockLLM proxy
72
+ return new AnthropicConstructor({
73
+ apiKey,
74
+ baseURL: baseURL || 'https://api.lockllm.com/v1/proxy/anthropic',
75
+ ...otherOptions,
76
+ });
77
+ }
78
+ //# sourceMappingURL=anthropic-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"anthropic-wrapper.js","sourceRoot":"","sources":["../../src/wrappers/anthropic-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAqBH;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;;;GAGG;AACH,MAAM,UAAU,uBAAuB,CAAC,SAAS,GAAG,OAAO;IACzD,IAAI,CAAC;QACH,MAAM,eAAe,GAAG,SAAS,CAAC,mBAAmB,CAAC,CAAC;QACvD,OAAO,eAAe,CAAC,OAAO,IAAI,eAAe,CAAC,SAAS,IAAI,eAAe,CAAC;IACjF,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,gFAAgF,CACjF,CAAC;IACJ,CAAC;AACH,CAAC;AAED,MAAM,UAAU,eAAe,CAAC,MAA6B;IAC3D,gCAAgC;IAChC,MAAM,oBAAoB,GAAG,uBAAuB,EAAE,CAAC;IAEvD,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAEpD,6CAA6C;IAC7C,OAAO,IAAI,oBAAoB,CAAC;QAC9B,MAAM;QACN,OAAO,EAAE,OAAO,IAAI,4CAA4C;QAChE,GAAG,YAAY;KAChB,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,74 @@
1
+ /**
2
+ * Anthropic SDK wrapper - Drop-in replacement
3
+ *
4
+ * This wrapper allows you to use the official Anthropic SDK with LockLLM protection
5
+ * by simply changing how you initialize the client.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * // Replace this:
10
+ * // import Anthropic from '@anthropic-ai/sdk';
11
+ * // const anthropic = new Anthropic({ apiKey: process.env.ANTHROPIC_API_KEY });
12
+ *
13
+ * // With this:
14
+ * import { createAnthropic } from '@lockllm/sdk/wrappers';
15
+ * const anthropic = createAnthropic({
16
+ * apiKey: process.env.LOCKLLM_API_KEY
17
+ * });
18
+ *
19
+ * // Everything else stays the same!
20
+ * const message = await anthropic.messages.create({
21
+ * model: "claude-3-5-sonnet-20241022",
22
+ * max_tokens: 1024,
23
+ * messages: [{ role: "user", content: "Hello!" }]
24
+ * });
25
+ * ```
26
+ */
27
+ /**
28
+ * Create an Anthropic client that routes through LockLLM proxy
29
+ *
30
+ * All requests are automatically scanned for prompt injection before being
31
+ * forwarded to Anthropic. Your Anthropic API key should be configured in the
32
+ * LockLLM dashboard at https://www.lockllm.com/dashboard
33
+ *
34
+ * @param config - Configuration options
35
+ * @returns Anthropic client instance
36
+ *
37
+ * @example
38
+ * ```typescript
39
+ * const anthropic = createAnthropic({
40
+ * apiKey: process.env.LOCKLLM_API_KEY
41
+ * });
42
+ *
43
+ * const message = await anthropic.messages.create({
44
+ * model: "claude-3-5-sonnet-20241022",
45
+ * max_tokens: 1024,
46
+ * messages: [{ role: "user", content: "Hello!" }]
47
+ * });
48
+ * ```
49
+ */
50
+ /**
51
+ * Lazy-load Anthropic SDK constructor
52
+ * @internal - exposed for testing purposes
53
+ */
54
+ export function getAnthropicConstructor(requireFn = require) {
55
+ try {
56
+ const anthropicModule = requireFn('@anthropic-ai/sdk');
57
+ return anthropicModule.default || anthropicModule.Anthropic || anthropicModule;
58
+ }
59
+ catch (error) {
60
+ throw new Error('Anthropic SDK not found. Please install it with: npm install @anthropic-ai/sdk');
61
+ }
62
+ }
63
+ export function createAnthropic(config) {
64
+ // Get Anthropic SDK constructor
65
+ const AnthropicConstructor = getAnthropicConstructor();
66
+ const { apiKey, baseURL, ...otherOptions } = config;
67
+ // Create Anthropic client with LockLLM proxy
68
+ return new AnthropicConstructor({
69
+ apiKey,
70
+ baseURL: baseURL || 'https://api.lockllm.com/v1/proxy/anthropic',
71
+ ...otherOptions,
72
+ });
73
+ }
74
+ //# sourceMappingURL=anthropic-wrapper.js.map
@@ -0,0 +1,180 @@
1
+ /**
2
+ * Generic SDK wrapper for any provider
3
+ *
4
+ * This wrapper provides a generic way to create clients for any LLM provider
5
+ * by routing requests through the LockLLM proxy.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { createClient } from '@lockllm/sdk/wrappers';
10
+ *
11
+ * // For providers with official SDKs
12
+ * const mistral = createClient('mistral', MistralClient, {
13
+ * apiKey: process.env.LOCKLLM_API_KEY
14
+ * });
15
+ *
16
+ * // For providers with OpenAI-compatible APIs
17
+ * const groq = createClient('groq', OpenAI, {
18
+ * apiKey: process.env.LOCKLLM_API_KEY
19
+ * });
20
+ * ```
21
+ */
22
+ import type { ProviderName } from '../types/providers';
23
+ export interface GenericClientConfig {
24
+ /**
25
+ * Your LockLLM API key
26
+ * Get it from: https://www.lockllm.com/dashboard
27
+ */
28
+ apiKey: string;
29
+ /**
30
+ * Base URL override (optional)
31
+ * By default, uses LockLLM proxy URL for the provider
32
+ */
33
+ baseURL?: string;
34
+ /**
35
+ * Other client-specific options
36
+ */
37
+ [key: string]: any;
38
+ }
39
+ /**
40
+ * Create a client for any provider using their official SDK
41
+ *
42
+ * This is a generic factory function that works with any LLM provider SDK
43
+ * by configuring it to use the LockLLM proxy.
44
+ *
45
+ * @param provider - The provider name (e.g., 'openai', 'anthropic', 'mistral')
46
+ * @param ClientConstructor - The provider's SDK client constructor
47
+ * @param config - Configuration options
48
+ * @returns Configured client instance
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * // Mistral AI
53
+ * import MistralClient from '@mistralai/mistralai';
54
+ * const mistral = createClient('mistral', MistralClient, {
55
+ * apiKey: process.env.LOCKLLM_API_KEY
56
+ * });
57
+ *
58
+ * // Groq (OpenAI-compatible)
59
+ * import OpenAI from 'openai';
60
+ * const groq = createClient('groq', OpenAI, {
61
+ * apiKey: process.env.LOCKLLM_API_KEY
62
+ * });
63
+ *
64
+ * // Cohere
65
+ * import { CohereClient } from 'cohere-ai';
66
+ * const cohere = createClient('cohere', CohereClient, {
67
+ * apiKey: process.env.LOCKLLM_API_KEY
68
+ * });
69
+ * ```
70
+ */
71
+ export declare function createClient<T = any>(provider: ProviderName, ClientConstructor: new (config: any) => T, config: GenericClientConfig): T;
72
+ /**
73
+ * Lazy-load OpenAI SDK constructor
74
+ * @internal - exposed for testing purposes
75
+ */
76
+ export declare function getGenericOpenAIConstructor(requireFn?: NodeJS.Require): any;
77
+ /**
78
+ * Helper to create OpenAI-compatible clients for providers
79
+ *
80
+ * Many providers (Groq, DeepSeek, Perplexity, etc.) use OpenAI-compatible APIs.
81
+ * This helper makes it easy to create clients for these providers.
82
+ *
83
+ * @param provider - The provider name
84
+ * @param config - Configuration options
85
+ * @returns OpenAI client configured for the provider
86
+ *
87
+ * @example
88
+ * ```typescript
89
+ * // Groq
90
+ * const groq = createOpenAICompatible('groq', {
91
+ * apiKey: process.env.LOCKLLM_API_KEY
92
+ * });
93
+ *
94
+ * // DeepSeek
95
+ * const deepseek = createOpenAICompatible('deepseek', {
96
+ * apiKey: process.env.LOCKLLM_API_KEY
97
+ * });
98
+ *
99
+ * // Use like OpenAI
100
+ * const response = await groq.chat.completions.create({
101
+ * model: 'llama-3.1-70b-versatile',
102
+ * messages: [{ role: 'user', content: 'Hello!' }]
103
+ * });
104
+ * ```
105
+ */
106
+ export declare function createOpenAICompatible(provider: ProviderName, config: GenericClientConfig): any;
107
+ /**
108
+ * Pre-configured factory functions for specific providers
109
+ */
110
+ /**
111
+ * Create a Groq client (OpenAI-compatible)
112
+ */
113
+ export declare function createGroq(config: GenericClientConfig): any;
114
+ /**
115
+ * Create a DeepSeek client (OpenAI-compatible)
116
+ */
117
+ export declare function createDeepSeek(config: GenericClientConfig): any;
118
+ /**
119
+ * Create a Perplexity client (OpenAI-compatible)
120
+ */
121
+ export declare function createPerplexity(config: GenericClientConfig): any;
122
+ /**
123
+ * Create a Mistral AI client (OpenAI-compatible)
124
+ */
125
+ export declare function createMistral(config: GenericClientConfig): any;
126
+ /**
127
+ * Create an OpenRouter client (OpenAI-compatible)
128
+ */
129
+ export declare function createOpenRouter(config: GenericClientConfig): any;
130
+ /**
131
+ * Create a Together AI client (OpenAI-compatible)
132
+ */
133
+ export declare function createTogether(config: GenericClientConfig): any;
134
+ /**
135
+ * Create an xAI (Grok) client (OpenAI-compatible)
136
+ */
137
+ export declare function createXAI(config: GenericClientConfig): any;
138
+ /**
139
+ * Create a Fireworks AI client (OpenAI-compatible)
140
+ */
141
+ export declare function createFireworks(config: GenericClientConfig): any;
142
+ /**
143
+ * Create an Anyscale client (OpenAI-compatible)
144
+ */
145
+ export declare function createAnyscale(config: GenericClientConfig): any;
146
+ /**
147
+ * Create a Hugging Face client (OpenAI-compatible)
148
+ */
149
+ export declare function createHuggingFace(config: GenericClientConfig): any;
150
+ /**
151
+ * Create a Google Gemini client
152
+ *
153
+ * Note: For Gemini, you should use the @google/generative-ai SDK
154
+ * or an OpenAI-compatible wrapper if available.
155
+ */
156
+ export declare function createGemini(config: GenericClientConfig): any;
157
+ /**
158
+ * Get Cohere SDK constructor
159
+ * @internal - exposed for testing purposes
160
+ */
161
+ export declare function getCohereConstructor(requireFn?: NodeJS.Require): any;
162
+ /**
163
+ * Create a Cohere client
164
+ *
165
+ * Note: For Cohere, you should use the cohere-ai SDK
166
+ */
167
+ export declare function createCohere(config: GenericClientConfig): any;
168
+ /**
169
+ * Create an Azure OpenAI client
170
+ */
171
+ export declare function createAzure(config: GenericClientConfig): any;
172
+ /**
173
+ * Create an AWS Bedrock client
174
+ */
175
+ export declare function createBedrock(config: GenericClientConfig): any;
176
+ /**
177
+ * Create a Google Vertex AI client
178
+ */
179
+ export declare function createVertexAI(config: GenericClientConfig): any;
180
+ //# sourceMappingURL=generic-wrapper.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-wrapper.d.ts","sourceRoot":"","sources":["../../src/wrappers/generic-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAGH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAEv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GAAG,CAEhE;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,mBAAmB,GAAG,GAAG,CAE/D;AAED;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,MAAM,EAAE,mBAAmB,GAAG,GAAG,CAElE;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,GAAG,CAE7D;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAAC,SAAS,iBAAU,GAAG,GAAG,CAS7D;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,MAAM,EAAE,mBAAmB,GAAG,GAAG,CAI7D;AAED;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,mBAAmB,GAAG,GAAG,CAE5D;AAED;;GAEG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,mBAAmB,GAAG,GAAG,CAE9D;AAED;;GAEG;AACH,wBAAgB,cAAc,CAAC,MAAM,EAAE,mBAAmB,GAAG,GAAG,CAE/D"}
@@ -0,0 +1,246 @@
1
+ "use strict";
2
+ /**
3
+ * Generic SDK wrapper for any provider
4
+ *
5
+ * This wrapper provides a generic way to create clients for any LLM provider
6
+ * by routing requests through the LockLLM proxy.
7
+ *
8
+ * @example
9
+ * ```typescript
10
+ * import { createClient } from '@lockllm/sdk/wrappers';
11
+ *
12
+ * // For providers with official SDKs
13
+ * const mistral = createClient('mistral', MistralClient, {
14
+ * apiKey: process.env.LOCKLLM_API_KEY
15
+ * });
16
+ *
17
+ * // For providers with OpenAI-compatible APIs
18
+ * const groq = createClient('groq', OpenAI, {
19
+ * apiKey: process.env.LOCKLLM_API_KEY
20
+ * });
21
+ * ```
22
+ */
23
+ Object.defineProperty(exports, "__esModule", { value: true });
24
+ exports.createClient = createClient;
25
+ exports.getGenericOpenAIConstructor = getGenericOpenAIConstructor;
26
+ exports.createOpenAICompatible = createOpenAICompatible;
27
+ exports.createGroq = createGroq;
28
+ exports.createDeepSeek = createDeepSeek;
29
+ exports.createPerplexity = createPerplexity;
30
+ exports.createMistral = createMistral;
31
+ exports.createOpenRouter = createOpenRouter;
32
+ exports.createTogether = createTogether;
33
+ exports.createXAI = createXAI;
34
+ exports.createFireworks = createFireworks;
35
+ exports.createAnyscale = createAnyscale;
36
+ exports.createHuggingFace = createHuggingFace;
37
+ exports.createGemini = createGemini;
38
+ exports.getCohereConstructor = getCohereConstructor;
39
+ exports.createCohere = createCohere;
40
+ exports.createAzure = createAzure;
41
+ exports.createBedrock = createBedrock;
42
+ exports.createVertexAI = createVertexAI;
43
+ const utils_1 = require("../utils");
44
+ /**
45
+ * Create a client for any provider using their official SDK
46
+ *
47
+ * This is a generic factory function that works with any LLM provider SDK
48
+ * by configuring it to use the LockLLM proxy.
49
+ *
50
+ * @param provider - The provider name (e.g., 'openai', 'anthropic', 'mistral')
51
+ * @param ClientConstructor - The provider's SDK client constructor
52
+ * @param config - Configuration options
53
+ * @returns Configured client instance
54
+ *
55
+ * @example
56
+ * ```typescript
57
+ * // Mistral AI
58
+ * import MistralClient from '@mistralai/mistralai';
59
+ * const mistral = createClient('mistral', MistralClient, {
60
+ * apiKey: process.env.LOCKLLM_API_KEY
61
+ * });
62
+ *
63
+ * // Groq (OpenAI-compatible)
64
+ * import OpenAI from 'openai';
65
+ * const groq = createClient('groq', OpenAI, {
66
+ * apiKey: process.env.LOCKLLM_API_KEY
67
+ * });
68
+ *
69
+ * // Cohere
70
+ * import { CohereClient } from 'cohere-ai';
71
+ * const cohere = createClient('cohere', CohereClient, {
72
+ * apiKey: process.env.LOCKLLM_API_KEY
73
+ * });
74
+ * ```
75
+ */
76
+ function createClient(provider, ClientConstructor, config) {
77
+ const { apiKey, baseURL, ...otherOptions } = config;
78
+ // Use provided baseURL or default to LockLLM proxy
79
+ const clientBaseURL = baseURL || (0, utils_1.getProxyURL)(provider);
80
+ // Create client with LockLLM proxy configuration
81
+ return new ClientConstructor({
82
+ apiKey,
83
+ baseURL: clientBaseURL,
84
+ ...otherOptions,
85
+ });
86
+ }
87
+ /**
88
+ * Lazy-load OpenAI SDK constructor
89
+ * @internal - exposed for testing purposes
90
+ */
91
+ function getGenericOpenAIConstructor(requireFn = require) {
92
+ try {
93
+ const openaiModule = requireFn('openai');
94
+ return openaiModule.default || openaiModule.OpenAI || openaiModule;
95
+ }
96
+ catch (error) {
97
+ throw new Error('OpenAI SDK not found. Please install it with: npm install openai');
98
+ }
99
+ }
100
+ /**
101
+ * Helper to create OpenAI-compatible clients for providers
102
+ *
103
+ * Many providers (Groq, DeepSeek, Perplexity, etc.) use OpenAI-compatible APIs.
104
+ * This helper makes it easy to create clients for these providers.
105
+ *
106
+ * @param provider - The provider name
107
+ * @param config - Configuration options
108
+ * @returns OpenAI client configured for the provider
109
+ *
110
+ * @example
111
+ * ```typescript
112
+ * // Groq
113
+ * const groq = createOpenAICompatible('groq', {
114
+ * apiKey: process.env.LOCKLLM_API_KEY
115
+ * });
116
+ *
117
+ * // DeepSeek
118
+ * const deepseek = createOpenAICompatible('deepseek', {
119
+ * apiKey: process.env.LOCKLLM_API_KEY
120
+ * });
121
+ *
122
+ * // Use like OpenAI
123
+ * const response = await groq.chat.completions.create({
124
+ * model: 'llama-3.1-70b-versatile',
125
+ * messages: [{ role: 'user', content: 'Hello!' }]
126
+ * });
127
+ * ```
128
+ */
129
+ function createOpenAICompatible(provider, config) {
130
+ const OpenAIConstructor = getGenericOpenAIConstructor();
131
+ return createClient(provider, OpenAIConstructor, config);
132
+ }
133
+ /**
134
+ * Pre-configured factory functions for specific providers
135
+ */
136
+ /**
137
+ * Create a Groq client (OpenAI-compatible)
138
+ */
139
+ function createGroq(config) {
140
+ return createOpenAICompatible('groq', config);
141
+ }
142
+ /**
143
+ * Create a DeepSeek client (OpenAI-compatible)
144
+ */
145
+ function createDeepSeek(config) {
146
+ return createOpenAICompatible('deepseek', config);
147
+ }
148
+ /**
149
+ * Create a Perplexity client (OpenAI-compatible)
150
+ */
151
+ function createPerplexity(config) {
152
+ return createOpenAICompatible('perplexity', config);
153
+ }
154
+ /**
155
+ * Create a Mistral AI client (OpenAI-compatible)
156
+ */
157
+ function createMistral(config) {
158
+ return createOpenAICompatible('mistral', config);
159
+ }
160
+ /**
161
+ * Create an OpenRouter client (OpenAI-compatible)
162
+ */
163
+ function createOpenRouter(config) {
164
+ return createOpenAICompatible('openrouter', config);
165
+ }
166
+ /**
167
+ * Create a Together AI client (OpenAI-compatible)
168
+ */
169
+ function createTogether(config) {
170
+ return createOpenAICompatible('together', config);
171
+ }
172
+ /**
173
+ * Create an xAI (Grok) client (OpenAI-compatible)
174
+ */
175
+ function createXAI(config) {
176
+ return createOpenAICompatible('xai', config);
177
+ }
178
+ /**
179
+ * Create a Fireworks AI client (OpenAI-compatible)
180
+ */
181
+ function createFireworks(config) {
182
+ return createOpenAICompatible('fireworks', config);
183
+ }
184
+ /**
185
+ * Create an Anyscale client (OpenAI-compatible)
186
+ */
187
+ function createAnyscale(config) {
188
+ return createOpenAICompatible('anyscale', config);
189
+ }
190
+ /**
191
+ * Create a Hugging Face client (OpenAI-compatible)
192
+ */
193
+ function createHuggingFace(config) {
194
+ return createOpenAICompatible('huggingface', config);
195
+ }
196
+ /**
197
+ * Create a Google Gemini client
198
+ *
199
+ * Note: For Gemini, you should use the @google/generative-ai SDK
200
+ * or an OpenAI-compatible wrapper if available.
201
+ */
202
+ function createGemini(config) {
203
+ return createOpenAICompatible('gemini', config);
204
+ }
205
+ /**
206
+ * Get Cohere SDK constructor
207
+ * @internal - exposed for testing purposes
208
+ */
209
+ function getCohereConstructor(requireFn = require) {
210
+ try {
211
+ const cohereModule = requireFn('cohere-ai');
212
+ return cohereModule.CohereClient || cohereModule;
213
+ }
214
+ catch (error) {
215
+ throw new Error('Cohere SDK not found. Please install it with: npm install cohere-ai');
216
+ }
217
+ }
218
+ /**
219
+ * Create a Cohere client
220
+ *
221
+ * Note: For Cohere, you should use the cohere-ai SDK
222
+ */
223
+ function createCohere(config) {
224
+ // Check if Cohere SDK is installed
225
+ const CohereConstructor = getCohereConstructor();
226
+ return createClient('cohere', CohereConstructor, config);
227
+ }
228
+ /**
229
+ * Create an Azure OpenAI client
230
+ */
231
+ function createAzure(config) {
232
+ return createOpenAICompatible('azure', config);
233
+ }
234
+ /**
235
+ * Create an AWS Bedrock client
236
+ */
237
+ function createBedrock(config) {
238
+ return createOpenAICompatible('bedrock', config);
239
+ }
240
+ /**
241
+ * Create a Google Vertex AI client
242
+ */
243
+ function createVertexAI(config) {
244
+ return createOpenAICompatible('vertex-ai', config);
245
+ }
246
+ //# sourceMappingURL=generic-wrapper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generic-wrapper.js","sourceRoot":"","sources":["../../src/wrappers/generic-wrapper.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;GAoBG;AAEH,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAsBvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,MAAM,UAAU,YAAY,CAC1B,QAAsB,EACtB,iBAAyC,EACzC,MAA2B;IAE3B,MAAM,EAAE,MAAM,EAAE,OAAO,EAAE,GAAG,YAAY,EAAE,GAAG,MAAM,CAAC;IAEpD,mDAAmD;IACnD,MAAM,aAAa,GAAG,OAAO,IAAI,WAAW,CAAC,QAAQ,CAAC,CAAC;IAEvD,iDAAiD;IACjD,OAAO,IAAI,iBAAiB,CAAC;QAC3B,MAAM;QACN,OAAO,EAAE,aAAa;QACtB,GAAG,YAAY;KAChB,CAAC,CAAC;AACL,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,2BAA2B,CAAC,SAAS,GAAG,OAAO;IAC7D,IAAI,CAAC;QACH,MAAM,YAAY,GAAG,SAAS,CAAC,QAAQ,CAAC,CAAC;QACzC,OAAO,YAAY,CAAC,OAAO,IAAI,YAAY,CAAC,MAAM,IAAI,YAAY,CAAC;IACrE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CAC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