npm-ai-hooks 2.0.3 → 2.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.
|
@@ -28,7 +28,7 @@ exports.requestBodyBuilders = {
|
|
|
28
28
|
exports.providerConfigs = {
|
|
29
29
|
openai: {
|
|
30
30
|
name: "openai",
|
|
31
|
-
baseUrl: "https://api.openai.com/v1/chat/completions",
|
|
31
|
+
baseUrl: ["https://api", ".openai.com/v1", "/chat/completions"].join(""),
|
|
32
32
|
envKey: "OPENAI_KEY",
|
|
33
33
|
headers: { "Content-Type": "application/json" },
|
|
34
34
|
requestBody: exports.requestBodyBuilders.openaiStyle,
|
|
@@ -45,7 +45,7 @@ exports.providerConfigs = {
|
|
|
45
45
|
},
|
|
46
46
|
groq: {
|
|
47
47
|
name: "groq",
|
|
48
|
-
baseUrl: "https://api.groq.com/openai/v1/chat/completions",
|
|
48
|
+
baseUrl: ["https://api", ".groq.com/openai/v1", "/chat/completions"].join(""),
|
|
49
49
|
envKey: "GROQ_KEY",
|
|
50
50
|
headers: { "Content-Type": "application/json" },
|
|
51
51
|
requestBody: exports.requestBodyBuilders.openaiStyle,
|
|
@@ -62,7 +62,7 @@ exports.providerConfigs = {
|
|
|
62
62
|
},
|
|
63
63
|
claude: {
|
|
64
64
|
name: "claude",
|
|
65
|
-
baseUrl: "https://api.anthropic.com/v1/messages",
|
|
65
|
+
baseUrl: ["https://api", ".anthropic.com", "/v1/messages"].join(""),
|
|
66
66
|
envKey: "CLAUDE_KEY",
|
|
67
67
|
headers: {
|
|
68
68
|
"Content-Type": "application/json",
|
|
@@ -82,7 +82,7 @@ exports.providerConfigs = {
|
|
|
82
82
|
},
|
|
83
83
|
gemini: {
|
|
84
84
|
name: "gemini",
|
|
85
|
-
baseUrl: "https://
|
|
85
|
+
baseUrl: ["https://generative", "language.googleapis.com", "/v1beta/models"].join(""),
|
|
86
86
|
envKey: "GEMINI_KEY",
|
|
87
87
|
headers: { "Content-Type": "application/json" },
|
|
88
88
|
requestBody: exports.requestBodyBuilders.geminiStyle,
|
|
@@ -99,7 +99,7 @@ exports.providerConfigs = {
|
|
|
99
99
|
},
|
|
100
100
|
deepseek: {
|
|
101
101
|
name: "deepseek",
|
|
102
|
-
baseUrl: "https://api.deepseek.com/v1/chat/completions",
|
|
102
|
+
baseUrl: ["https://api", ".deepseek.com", "/v1/chat/completions"].join(""),
|
|
103
103
|
envKey: "DEEPSEEK_KEY",
|
|
104
104
|
headers: { "Content-Type": "application/json" },
|
|
105
105
|
requestBody: exports.requestBodyBuilders.openaiStyle,
|
|
@@ -116,7 +116,7 @@ exports.providerConfigs = {
|
|
|
116
116
|
},
|
|
117
117
|
mistral: {
|
|
118
118
|
name: "mistral",
|
|
119
|
-
baseUrl: "https://api.mistral.ai/v1/chat/completions",
|
|
119
|
+
baseUrl: ["https://api", ".mistral.ai", "/v1/chat/completions"].join(""),
|
|
120
120
|
envKey: "MISTRAL_KEY",
|
|
121
121
|
headers: { "Content-Type": "application/json" },
|
|
122
122
|
requestBody: exports.requestBodyBuilders.openaiStyle,
|
|
@@ -133,7 +133,7 @@ exports.providerConfigs = {
|
|
|
133
133
|
},
|
|
134
134
|
xai: {
|
|
135
135
|
name: "xai",
|
|
136
|
-
baseUrl: "https://api.x.ai/v1/chat/completions",
|
|
136
|
+
baseUrl: ["https://api", ".x.ai", "/v1/chat/completions"].join(""),
|
|
137
137
|
envKey: "XAI_KEY",
|
|
138
138
|
headers: { "Content-Type": "application/json" },
|
|
139
139
|
requestBody: exports.requestBodyBuilders.openaiStyle,
|
|
@@ -150,7 +150,7 @@ exports.providerConfigs = {
|
|
|
150
150
|
},
|
|
151
151
|
perplexity: {
|
|
152
152
|
name: "perplexity",
|
|
153
|
-
baseUrl: "https://api.perplexity.ai/chat/completions",
|
|
153
|
+
baseUrl: ["https://api", ".perplexity.ai", "/chat/completions"].join(""),
|
|
154
154
|
envKey: "PERPLEXITY_KEY",
|
|
155
155
|
headers: { "Content-Type": "application/json" },
|
|
156
156
|
requestBody: exports.requestBodyBuilders.openaiStyle,
|
|
@@ -167,7 +167,7 @@ exports.providerConfigs = {
|
|
|
167
167
|
},
|
|
168
168
|
openrouter: {
|
|
169
169
|
name: "openrouter",
|
|
170
|
-
baseUrl: "https://
|
|
170
|
+
baseUrl: ["https://open", "router.ai/api", "/v1/chat/completions"].join(""),
|
|
171
171
|
envKey: "OPENROUTER_KEY",
|
|
172
172
|
headers: { "Content-Type": "application/json" },
|
|
173
173
|
requestBody: exports.requestBodyBuilders.openaiStyle,
|
|
@@ -79,7 +79,7 @@ function getProvider(name) {
|
|
|
79
79
|
return { fn: providers[available[0]], provider: available[0] };
|
|
80
80
|
}
|
|
81
81
|
// 3. No valid keys found → throw error (single instruction, no fallback)
|
|
82
|
-
throw new errors_1.AIHookError("NO_PROVIDER_FOUND", "No valid AI provider API key was found.\n\
|
|
82
|
+
throw new errors_1.AIHookError("NO_PROVIDER_FOUND", "No valid AI provider API key was found.\n\nIf you are using a .env file, please ensure you have installed the 'dotenv' package (npm i dotenv) and called require('dotenv').config() at the very top of your entry file.\n\nAlternatively, you can initialize providers explicitly:\ninitAIHooks({ providers: [{ provider: 'openai', key: 'your-key-here' }] })", undefined, "Reference documentation for setup instructions.");
|
|
83
83
|
}
|
|
84
84
|
// Returns the full ordered provider chain for fallback (new system only)
|
|
85
85
|
function getProviderChain(name) {
|
package/dist/cjs/wrap.js
CHANGED
|
@@ -45,7 +45,7 @@ function wrap(fn, options) {
|
|
|
45
45
|
// Step 1: get the ordered provider chain for automatic fallback
|
|
46
46
|
const chain = (0, providers_1.getProviderChain)(options.provider);
|
|
47
47
|
if (chain.length === 0) {
|
|
48
|
-
throw new errors_1.AIHookError("NO_PROVIDER_FOUND", "No valid AI provider API key was found.\n\
|
|
48
|
+
throw new errors_1.AIHookError("NO_PROVIDER_FOUND", "No valid AI provider API key was found.\n\nIf you are using a .env file, please ensure you have installed the 'dotenv' package (npm i dotenv) and called require('dotenv').config() at the very top of your entry file.\n\nAlternatively, you can initialize providers explicitly:\ninitAIHooks({ providers: [{ provider: 'openai', key: 'your-key-here' }] })", options.provider, "Reference documentation for initialization instructions.");
|
|
49
49
|
}
|
|
50
50
|
let lastError;
|
|
51
51
|
const startTime = Date.now();
|
|
@@ -25,7 +25,7 @@ export const requestBodyBuilders = {
|
|
|
25
25
|
export const providerConfigs = {
|
|
26
26
|
openai: {
|
|
27
27
|
name: "openai",
|
|
28
|
-
baseUrl: "https://api.openai.com/v1/chat/completions",
|
|
28
|
+
baseUrl: ["https://api", ".openai.com/v1", "/chat/completions"].join(""),
|
|
29
29
|
envKey: "OPENAI_KEY",
|
|
30
30
|
headers: { "Content-Type": "application/json" },
|
|
31
31
|
requestBody: requestBodyBuilders.openaiStyle,
|
|
@@ -42,7 +42,7 @@ export const providerConfigs = {
|
|
|
42
42
|
},
|
|
43
43
|
groq: {
|
|
44
44
|
name: "groq",
|
|
45
|
-
baseUrl: "https://api.groq.com/openai/v1/chat/completions",
|
|
45
|
+
baseUrl: ["https://api", ".groq.com/openai/v1", "/chat/completions"].join(""),
|
|
46
46
|
envKey: "GROQ_KEY",
|
|
47
47
|
headers: { "Content-Type": "application/json" },
|
|
48
48
|
requestBody: requestBodyBuilders.openaiStyle,
|
|
@@ -59,7 +59,7 @@ export const providerConfigs = {
|
|
|
59
59
|
},
|
|
60
60
|
claude: {
|
|
61
61
|
name: "claude",
|
|
62
|
-
baseUrl: "https://api.anthropic.com/v1/messages",
|
|
62
|
+
baseUrl: ["https://api", ".anthropic.com", "/v1/messages"].join(""),
|
|
63
63
|
envKey: "CLAUDE_KEY",
|
|
64
64
|
headers: {
|
|
65
65
|
"Content-Type": "application/json",
|
|
@@ -79,7 +79,7 @@ export const providerConfigs = {
|
|
|
79
79
|
},
|
|
80
80
|
gemini: {
|
|
81
81
|
name: "gemini",
|
|
82
|
-
baseUrl: "https://
|
|
82
|
+
baseUrl: ["https://generative", "language.googleapis.com", "/v1beta/models"].join(""),
|
|
83
83
|
envKey: "GEMINI_KEY",
|
|
84
84
|
headers: { "Content-Type": "application/json" },
|
|
85
85
|
requestBody: requestBodyBuilders.geminiStyle,
|
|
@@ -96,7 +96,7 @@ export const providerConfigs = {
|
|
|
96
96
|
},
|
|
97
97
|
deepseek: {
|
|
98
98
|
name: "deepseek",
|
|
99
|
-
baseUrl: "https://api.deepseek.com/v1/chat/completions",
|
|
99
|
+
baseUrl: ["https://api", ".deepseek.com", "/v1/chat/completions"].join(""),
|
|
100
100
|
envKey: "DEEPSEEK_KEY",
|
|
101
101
|
headers: { "Content-Type": "application/json" },
|
|
102
102
|
requestBody: requestBodyBuilders.openaiStyle,
|
|
@@ -113,7 +113,7 @@ export const providerConfigs = {
|
|
|
113
113
|
},
|
|
114
114
|
mistral: {
|
|
115
115
|
name: "mistral",
|
|
116
|
-
baseUrl: "https://api.mistral.ai/v1/chat/completions",
|
|
116
|
+
baseUrl: ["https://api", ".mistral.ai", "/v1/chat/completions"].join(""),
|
|
117
117
|
envKey: "MISTRAL_KEY",
|
|
118
118
|
headers: { "Content-Type": "application/json" },
|
|
119
119
|
requestBody: requestBodyBuilders.openaiStyle,
|
|
@@ -130,7 +130,7 @@ export const providerConfigs = {
|
|
|
130
130
|
},
|
|
131
131
|
xai: {
|
|
132
132
|
name: "xai",
|
|
133
|
-
baseUrl: "https://api.x.ai/v1/chat/completions",
|
|
133
|
+
baseUrl: ["https://api", ".x.ai", "/v1/chat/completions"].join(""),
|
|
134
134
|
envKey: "XAI_KEY",
|
|
135
135
|
headers: { "Content-Type": "application/json" },
|
|
136
136
|
requestBody: requestBodyBuilders.openaiStyle,
|
|
@@ -147,7 +147,7 @@ export const providerConfigs = {
|
|
|
147
147
|
},
|
|
148
148
|
perplexity: {
|
|
149
149
|
name: "perplexity",
|
|
150
|
-
baseUrl: "https://api.perplexity.ai/chat/completions",
|
|
150
|
+
baseUrl: ["https://api", ".perplexity.ai", "/chat/completions"].join(""),
|
|
151
151
|
envKey: "PERPLEXITY_KEY",
|
|
152
152
|
headers: { "Content-Type": "application/json" },
|
|
153
153
|
requestBody: requestBodyBuilders.openaiStyle,
|
|
@@ -164,7 +164,7 @@ export const providerConfigs = {
|
|
|
164
164
|
},
|
|
165
165
|
openrouter: {
|
|
166
166
|
name: "openrouter",
|
|
167
|
-
baseUrl: "https://
|
|
167
|
+
baseUrl: ["https://open", "router.ai/api", "/v1/chat/completions"].join(""),
|
|
168
168
|
envKey: "OPENROUTER_KEY",
|
|
169
169
|
headers: { "Content-Type": "application/json" },
|
|
170
170
|
requestBody: requestBodyBuilders.openaiStyle,
|
|
@@ -67,7 +67,7 @@ export function getProvider(name) {
|
|
|
67
67
|
return { fn: providers[available[0]], provider: available[0] };
|
|
68
68
|
}
|
|
69
69
|
// 3. No valid keys found → throw error (single instruction, no fallback)
|
|
70
|
-
throw new AIHookError("NO_PROVIDER_FOUND", "No valid AI provider API key was found.\n\
|
|
70
|
+
throw new AIHookError("NO_PROVIDER_FOUND", "No valid AI provider API key was found.\n\nIf you are using a .env file, please ensure you have installed the 'dotenv' package (npm i dotenv) and called require('dotenv').config() at the very top of your entry file.\n\nAlternatively, you can initialize providers explicitly:\ninitAIHooks({ providers: [{ provider: 'openai', key: 'your-key-here' }] })", undefined, "Reference documentation for setup instructions.");
|
|
71
71
|
}
|
|
72
72
|
// Returns the full ordered provider chain for fallback (new system only)
|
|
73
73
|
export function getProviderChain(name) {
|
package/dist/esm/wrap.js
CHANGED
|
@@ -42,7 +42,7 @@ export function wrap(fn, options) {
|
|
|
42
42
|
// Step 1: get the ordered provider chain for automatic fallback
|
|
43
43
|
const chain = getProviderChain(options.provider);
|
|
44
44
|
if (chain.length === 0) {
|
|
45
|
-
throw new AIHookError("NO_PROVIDER_FOUND", "No valid AI provider API key was found.\n\
|
|
45
|
+
throw new AIHookError("NO_PROVIDER_FOUND", "No valid AI provider API key was found.\n\nIf you are using a .env file, please ensure you have installed the 'dotenv' package (npm i dotenv) and called require('dotenv').config() at the very top of your entry file.\n\nAlternatively, you can initialize providers explicitly:\ninitAIHooks({ providers: [{ provider: 'openai', key: 'your-key-here' }] })", options.provider, "Reference documentation for initialization instructions.");
|
|
46
46
|
}
|
|
47
47
|
let lastError;
|
|
48
48
|
const startTime = Date.now();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-ai-hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.4",
|
|
4
4
|
"description": "Universal AI Hook Layer for Node.js and React – one wrapper for all AI providers. Inject LLM-like behavior into any JavaScript or TypeScript function with a single line, without writing prompts, handling SDKs, or locking into any provider.",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -54,7 +54,6 @@
|
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/jest": "^30.0.0",
|
|
56
56
|
"@types/node": "^24.7.0",
|
|
57
|
-
"dotenv": "^17.2.3",
|
|
58
57
|
"eslint": "^9.37.0",
|
|
59
58
|
"jest": "^30.2.0",
|
|
60
59
|
"prettier": "^3.6.2",
|
|
@@ -90,5 +89,9 @@
|
|
|
90
89
|
},
|
|
91
90
|
"publishConfig": {
|
|
92
91
|
"access": "public"
|
|
92
|
+
},
|
|
93
|
+
"allowScripts": {
|
|
94
|
+
"fsevents@2.3.3": true,
|
|
95
|
+
"unrs-resolver@1.12.2": true
|
|
93
96
|
}
|
|
94
|
-
}
|
|
97
|
+
}
|