npm-ai-hooks 2.0.3 → 2.0.5
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/dist/cjs/errors.js +3 -0
- package/dist/cjs/providers/base/BaseProvider.js +37 -5
- package/dist/cjs/providers/base/ProviderConfig.js +3 -2
- package/dist/cjs/providers/base/ProviderConfigs.js +9 -9
- package/dist/cjs/providers/base/ProviderRegistry.js +2 -4
- package/dist/cjs/providers/index.js +1 -1
- package/dist/cjs/wrap.js +1 -1
- package/dist/esm/errors.js +3 -0
- package/dist/esm/providers/base/BaseProvider.js +37 -2
- package/dist/esm/providers/base/ProviderConfig.js +3 -2
- package/dist/esm/providers/base/ProviderConfigs.js +9 -9
- package/dist/esm/providers/base/ProviderRegistry.js +2 -4
- package/dist/esm/providers/index.js +1 -1
- package/dist/esm/wrap.js +1 -1
- package/dist/providers/base/BaseProvider.d.ts +13 -5
- package/dist/providers/base/SpecializedProviders.d.ts +4 -64
- package/package.json +9 -9
package/dist/cjs/errors.js
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.BaseProvider = void 0;
|
|
7
|
-
const axios_1 = __importDefault(require("axios"));
|
|
8
4
|
const errors_1 = require("../../errors");
|
|
9
5
|
class BaseProvider {
|
|
6
|
+
config;
|
|
10
7
|
constructor(config) {
|
|
11
8
|
this.config = config;
|
|
12
9
|
}
|
|
@@ -54,7 +51,42 @@ class BaseProvider {
|
|
|
54
51
|
};
|
|
55
52
|
}
|
|
56
53
|
async makeRequest(config) {
|
|
57
|
-
|
|
54
|
+
try {
|
|
55
|
+
const response = await fetch(config.url, {
|
|
56
|
+
method: config.method || "POST",
|
|
57
|
+
headers: config.headers,
|
|
58
|
+
body: config.data ? JSON.stringify(config.data) : undefined,
|
|
59
|
+
});
|
|
60
|
+
let data;
|
|
61
|
+
try {
|
|
62
|
+
data = await response.json();
|
|
63
|
+
}
|
|
64
|
+
catch (e) {
|
|
65
|
+
data = await response.text();
|
|
66
|
+
}
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
// Emulate axios error shape for the error handler
|
|
69
|
+
throw Object.assign(new Error(`Request failed with status code ${response.status}`), {
|
|
70
|
+
response: {
|
|
71
|
+
status: response.status,
|
|
72
|
+
statusText: response.statusText,
|
|
73
|
+
data: data
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
}
|
|
77
|
+
return { data };
|
|
78
|
+
}
|
|
79
|
+
catch (error) {
|
|
80
|
+
// If it's already an HTTP error we just threw, rethrow it
|
|
81
|
+
if (error.response) {
|
|
82
|
+
throw error;
|
|
83
|
+
}
|
|
84
|
+
// Otherwise, it's a network error (e.g. fetch failed entirely)
|
|
85
|
+
// Emulate axios network error shape
|
|
86
|
+
throw Object.assign(new Error(error.message || "Network Error"), {
|
|
87
|
+
request: {}
|
|
88
|
+
});
|
|
89
|
+
}
|
|
58
90
|
}
|
|
59
91
|
parseResponse(response) {
|
|
60
92
|
const output = this.config.responseParser(response);
|
|
@@ -6,9 +6,10 @@ const BaseProvider_1 = require("./BaseProvider");
|
|
|
6
6
|
const ProviderConfigs_1 = require("./ProviderConfigs");
|
|
7
7
|
const SpecializedProviders_1 = require("./SpecializedProviders");
|
|
8
8
|
class ProviderManager {
|
|
9
|
+
providers = new Map();
|
|
10
|
+
defaultProvider;
|
|
11
|
+
providerFunctions = new Map();
|
|
9
12
|
constructor(options) {
|
|
10
|
-
this.providers = new Map();
|
|
11
|
-
this.providerFunctions = new Map();
|
|
12
13
|
this.initializeProviders(options);
|
|
13
14
|
}
|
|
14
15
|
initializeProviders(options) {
|
|
@@ -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,
|
|
@@ -2,10 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.providerRegistry = exports.ProviderRegistry = void 0;
|
|
4
4
|
class ProviderRegistry {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
this.providerFunctions = new Map();
|
|
8
|
-
}
|
|
5
|
+
providers = new Map();
|
|
6
|
+
providerFunctions = new Map();
|
|
9
7
|
register(name, provider) {
|
|
10
8
|
this.providers.set(name, provider);
|
|
11
9
|
this.providerFunctions.set(name, this.createProviderFunction(provider));
|
|
@@ -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();
|
package/dist/esm/errors.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import axios from "axios";
|
|
2
1
|
import { AIHookError } from "../../errors";
|
|
3
2
|
export class BaseProvider {
|
|
3
|
+
config;
|
|
4
4
|
constructor(config) {
|
|
5
5
|
this.config = config;
|
|
6
6
|
}
|
|
@@ -48,7 +48,42 @@ export class BaseProvider {
|
|
|
48
48
|
};
|
|
49
49
|
}
|
|
50
50
|
async makeRequest(config) {
|
|
51
|
-
|
|
51
|
+
try {
|
|
52
|
+
const response = await fetch(config.url, {
|
|
53
|
+
method: config.method || "POST",
|
|
54
|
+
headers: config.headers,
|
|
55
|
+
body: config.data ? JSON.stringify(config.data) : undefined,
|
|
56
|
+
});
|
|
57
|
+
let data;
|
|
58
|
+
try {
|
|
59
|
+
data = await response.json();
|
|
60
|
+
}
|
|
61
|
+
catch (e) {
|
|
62
|
+
data = await response.text();
|
|
63
|
+
}
|
|
64
|
+
if (!response.ok) {
|
|
65
|
+
// Emulate axios error shape for the error handler
|
|
66
|
+
throw Object.assign(new Error(`Request failed with status code ${response.status}`), {
|
|
67
|
+
response: {
|
|
68
|
+
status: response.status,
|
|
69
|
+
statusText: response.statusText,
|
|
70
|
+
data: data
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
return { data };
|
|
75
|
+
}
|
|
76
|
+
catch (error) {
|
|
77
|
+
// If it's already an HTTP error we just threw, rethrow it
|
|
78
|
+
if (error.response) {
|
|
79
|
+
throw error;
|
|
80
|
+
}
|
|
81
|
+
// Otherwise, it's a network error (e.g. fetch failed entirely)
|
|
82
|
+
// Emulate axios network error shape
|
|
83
|
+
throw Object.assign(new Error(error.message || "Network Error"), {
|
|
84
|
+
request: {}
|
|
85
|
+
});
|
|
86
|
+
}
|
|
52
87
|
}
|
|
53
88
|
parseResponse(response) {
|
|
54
89
|
const output = this.config.responseParser(response);
|
|
@@ -3,9 +3,10 @@ import { BaseProvider } from "./BaseProvider";
|
|
|
3
3
|
import { providerConfigs } from "./ProviderConfigs";
|
|
4
4
|
import { ClaudeProvider, GeminiProvider, OpenRouterProvider } from "./SpecializedProviders";
|
|
5
5
|
export class ProviderManager {
|
|
6
|
+
providers = new Map();
|
|
7
|
+
defaultProvider;
|
|
8
|
+
providerFunctions = new Map();
|
|
6
9
|
constructor(options) {
|
|
7
|
-
this.providers = new Map();
|
|
8
|
-
this.providerFunctions = new Map();
|
|
9
10
|
this.initializeProviders(options);
|
|
10
11
|
}
|
|
11
12
|
initializeProviders(options) {
|
|
@@ -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,
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
export class ProviderRegistry {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
this.providerFunctions = new Map();
|
|
5
|
-
}
|
|
2
|
+
providers = new Map();
|
|
3
|
+
providerFunctions = new Map();
|
|
6
4
|
register(name, provider) {
|
|
7
5
|
this.providers.set(name, provider);
|
|
8
6
|
this.providerFunctions.set(name, this.createProviderFunction(provider));
|
|
@@ -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();
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
import { AxiosRequestConfig, AxiosResponse } from "axios";
|
|
2
1
|
import { AIHookError } from "../../errors";
|
|
2
|
+
export interface FetchRequestConfig {
|
|
3
|
+
url: string;
|
|
4
|
+
method?: string;
|
|
5
|
+
data?: any;
|
|
6
|
+
headers?: Record<string, string>;
|
|
7
|
+
}
|
|
8
|
+
export interface FetchResponse {
|
|
9
|
+
data: any;
|
|
10
|
+
}
|
|
3
11
|
export interface ProviderConfig {
|
|
4
12
|
name: string;
|
|
5
13
|
baseUrl: string;
|
|
6
14
|
envKey: string;
|
|
7
15
|
headers: Record<string, string>;
|
|
8
16
|
requestBody: (prompt: string, model: string) => any;
|
|
9
|
-
responseParser: (response:
|
|
17
|
+
responseParser: (response: FetchResponse) => string;
|
|
10
18
|
errorMessages: {
|
|
11
19
|
missingKey: string;
|
|
12
20
|
emptyResponse: string;
|
|
@@ -23,10 +31,10 @@ export declare class BaseProvider {
|
|
|
23
31
|
call(prompt: string, model: string): Promise<string>;
|
|
24
32
|
protected getApiKey(): string | undefined;
|
|
25
33
|
protected validateApiKey(apiKey: string | undefined): void;
|
|
26
|
-
protected buildRequestConfig(prompt: string, model: string, apiKey: string):
|
|
34
|
+
protected buildRequestConfig(prompt: string, model: string, apiKey: string): FetchRequestConfig;
|
|
27
35
|
protected buildAuthHeaders(apiKey: string): Record<string, string>;
|
|
28
|
-
protected makeRequest(config:
|
|
29
|
-
protected parseResponse(response:
|
|
36
|
+
protected makeRequest(config: FetchRequestConfig): Promise<FetchResponse>;
|
|
37
|
+
protected parseResponse(response: FetchResponse): string;
|
|
30
38
|
protected handleError(error: any): AIHookError;
|
|
31
39
|
protected getCapitalizedProviderName(): string;
|
|
32
40
|
protected handleHttpError(error: any): AIHookError;
|
|
@@ -8,71 +8,11 @@ export declare class GeminiProvider extends BaseProvider {
|
|
|
8
8
|
constructor();
|
|
9
9
|
protected buildRequestConfig(prompt: string, model: string, apiKey: string): {
|
|
10
10
|
url: string;
|
|
11
|
-
headers: {
|
|
12
|
-
|
|
13
|
-
baseURL?: string;
|
|
14
|
-
allowAbsoluteUrls?: boolean;
|
|
15
|
-
transformRequest?: import("axios").AxiosRequestTransformer | import("axios").AxiosRequestTransformer[];
|
|
16
|
-
transformResponse?: import("axios").AxiosResponseTransformer | import("axios").AxiosResponseTransformer[];
|
|
17
|
-
params?: any;
|
|
18
|
-
paramsSerializer?: import("axios").ParamsSerializerOptions | import("axios").CustomParamsSerializer;
|
|
19
|
-
data?: any;
|
|
20
|
-
timeout?: number;
|
|
21
|
-
timeoutErrorMessage?: string;
|
|
22
|
-
withCredentials?: boolean;
|
|
23
|
-
adapter?: (import("axios").AxiosAdapter | ((string & {}) | "xhr" | "http" | "fetch")) | (import("axios").AxiosAdapter | ((string & {}) | "xhr" | "http" | "fetch"))[];
|
|
24
|
-
auth?: import("axios").AxiosBasicCredentials;
|
|
25
|
-
responseType?: import("axios").ResponseType;
|
|
26
|
-
responseEncoding?: (string & {}) | import("axios").responseEncoding;
|
|
27
|
-
xsrfCookieName?: string;
|
|
28
|
-
xsrfHeaderName?: string;
|
|
29
|
-
onUploadProgress?: (progressEvent: import("axios").AxiosProgressEvent) => void;
|
|
30
|
-
onDownloadProgress?: (progressEvent: import("axios").AxiosProgressEvent) => void;
|
|
31
|
-
maxContentLength?: number;
|
|
32
|
-
validateStatus?: ((status: number) => boolean) | null;
|
|
33
|
-
maxBodyLength?: number;
|
|
34
|
-
maxRedirects?: number;
|
|
35
|
-
maxRate?: number | [number, number];
|
|
36
|
-
beforeRedirect?: (options: Record<string, any>, responseDetails: {
|
|
37
|
-
headers: Record<string, string>;
|
|
38
|
-
statusCode: import("axios").HttpStatusCode;
|
|
39
|
-
}, requestDetails: {
|
|
40
|
-
headers: Record<string, string>;
|
|
41
|
-
url: string;
|
|
42
|
-
method: string;
|
|
43
|
-
}) => void;
|
|
44
|
-
socketPath?: string | null;
|
|
45
|
-
allowedSocketPaths?: string | string[] | null;
|
|
46
|
-
transport?: any;
|
|
47
|
-
httpAgent?: any;
|
|
48
|
-
httpsAgent?: any;
|
|
49
|
-
proxy?: import("axios").AxiosProxyConfig | false;
|
|
50
|
-
cancelToken?: import("axios").CancelToken | undefined;
|
|
51
|
-
decompress?: boolean;
|
|
52
|
-
transitional?: import("axios").TransitionalOptions;
|
|
53
|
-
signal?: import("axios").GenericAbortSignal;
|
|
54
|
-
insecureHTTPParser?: boolean;
|
|
55
|
-
env?: {
|
|
56
|
-
FormData?: new (...args: any[]) => object;
|
|
57
|
-
fetch?: (input: URL | Request | string, init?: RequestInit) => Promise<Response>;
|
|
58
|
-
Request?: new (input: URL | Request | string, init?: RequestInit) => Request;
|
|
59
|
-
Response?: new (body?: ArrayBuffer | ArrayBufferView | Blob | FormData | URLSearchParams | string | null, init?: ResponseInit) => Response;
|
|
60
|
-
};
|
|
61
|
-
formSerializer?: import("axios").FormSerializerOptions;
|
|
62
|
-
family?: import("axios").AddressFamily;
|
|
63
|
-
lookup?: ((hostname: string, options: object, cb: (err: Error | null, address: import("axios").LookupAddress | import("axios").LookupAddress[], family?: import("axios").AddressFamily) => void) => void) | ((hostname: string, options: object) => Promise<[address: import("axios").LookupAddressEntry | import("axios").LookupAddressEntry[], family?: import("axios").AddressFamily] | import("axios").LookupAddress>);
|
|
64
|
-
withXSRFToken?: boolean | ((config: import("axios").InternalAxiosRequestConfig) => boolean | undefined);
|
|
65
|
-
parseReviver?: (this: any, key: string, value: any, context?: {
|
|
66
|
-
source?: string;
|
|
67
|
-
}) => any;
|
|
68
|
-
fetchOptions?: Omit<RequestInit, "body" | "headers" | "method" | "signal"> | Record<string, any>;
|
|
69
|
-
httpVersion?: 1 | 2;
|
|
70
|
-
http2Options?: Record<string, any> & {
|
|
71
|
-
sessionTimeout?: number;
|
|
11
|
+
headers: {
|
|
12
|
+
[x: string]: string;
|
|
72
13
|
};
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
sensitiveHeaders?: string[];
|
|
14
|
+
method?: string;
|
|
15
|
+
data?: any;
|
|
76
16
|
};
|
|
77
17
|
protected buildAuthHeaders(): Record<string, string>;
|
|
78
18
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "npm-ai-hooks",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.5",
|
|
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",
|
|
@@ -48,20 +48,16 @@
|
|
|
48
48
|
"url": "git+https://github.com/iTeebot/npm-ai-hooks.git"
|
|
49
49
|
},
|
|
50
50
|
"license": "MIT",
|
|
51
|
-
"dependencies": {
|
|
52
|
-
"axios": "^1.12.2"
|
|
53
|
-
},
|
|
54
51
|
"devDependencies": {
|
|
55
52
|
"@types/jest": "^30.0.0",
|
|
56
|
-
"@types/node": "^
|
|
57
|
-
"
|
|
58
|
-
"eslint": "^9.37.0",
|
|
53
|
+
"@types/node": "^25.9.3",
|
|
54
|
+
"eslint": "^10.5.0",
|
|
59
55
|
"jest": "^30.2.0",
|
|
60
56
|
"prettier": "^3.6.2",
|
|
61
57
|
"rimraf": "^6.0.1",
|
|
62
58
|
"ts-jest": "^29.4.4",
|
|
63
59
|
"ts-node": "^10.9.2",
|
|
64
|
-
"typescript": "^
|
|
60
|
+
"typescript": "^6.0.3"
|
|
65
61
|
},
|
|
66
62
|
"keywords": [
|
|
67
63
|
"ai",
|
|
@@ -90,5 +86,9 @@
|
|
|
90
86
|
},
|
|
91
87
|
"publishConfig": {
|
|
92
88
|
"access": "public"
|
|
89
|
+
},
|
|
90
|
+
"allowScripts": {
|
|
91
|
+
"fsevents@2.3.3": true,
|
|
92
|
+
"unrs-resolver@1.12.2": true
|
|
93
93
|
}
|
|
94
|
-
}
|
|
94
|
+
}
|