n8n-nodes-vercel-ai-sdk-universal-temp 0.1.71 → 0.2.29
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/nodes/UniversalAI/UniversalAI.node.js +5 -13
- package/dist/nodes/UniversalAI/UniversalAI.node.js.map +1 -1
- package/dist/nodes/UniversalEmbedding/UniversalEmbedding.node.js +1 -1
- package/dist/nodes/UniversalEmbedding/UniversalEmbedding.node.js.map +1 -1
- package/dist/nodes/UniversalImageGen/UniversalImageGen.node.js +1 -1
- package/dist/nodes/UniversalImageGen/UniversalImageGen.node.js.map +1 -1
- package/dist/nodes/UniversalSpeechGen/UniversalSpeechGen.node.js +1 -1
- package/dist/nodes/UniversalSpeechGen/UniversalSpeechGen.node.js.map +1 -1
- package/dist/nodes/UniversalTranscription/UniversalTranscription.node.js +1 -1
- package/dist/nodes/UniversalTranscription/UniversalTranscription.node.js.map +1 -1
- package/dist/nodes/shared/builders/descriptions.d.ts +103 -0
- package/dist/nodes/shared/builders/descriptions.js +713 -0
- package/dist/nodes/shared/builders/descriptions.js.map +1 -0
- package/dist/nodes/shared/builders/index.d.ts +1 -0
- package/dist/nodes/shared/builders/index.js +18 -0
- package/dist/nodes/shared/builders/index.js.map +1 -0
- package/dist/nodes/shared/builders/options.d.ts +22 -0
- package/dist/nodes/shared/builders/options.js +86 -0
- package/dist/nodes/shared/builders/options.js.map +1 -0
- package/dist/nodes/shared/cache/cache.d.ts +27 -0
- package/dist/nodes/shared/cache/cache.js +129 -0
- package/dist/nodes/shared/cache/cache.js.map +1 -0
- package/dist/nodes/shared/cache/index.d.ts +1 -0
- package/dist/nodes/shared/cache/index.js +6 -0
- package/dist/nodes/shared/cache/index.js.map +1 -0
- package/dist/nodes/shared/constants.d.ts +1 -4
- package/dist/nodes/shared/constants.js +3 -6
- package/dist/nodes/shared/constants.js.map +1 -1
- package/dist/nodes/shared/google/index.d.ts +14 -0
- package/dist/nodes/shared/google/index.js +165 -0
- package/dist/nodes/shared/google/index.js.map +1 -0
- package/dist/nodes/shared/helpers.d.ts +9 -53
- package/dist/nodes/shared/helpers.js +25 -494
- package/dist/nodes/shared/helpers.js.map +1 -1
- package/dist/nodes/shared/providers/factory.d.ts +11 -0
- package/dist/nodes/shared/providers/factory.js +106 -0
- package/dist/nodes/shared/providers/factory.js.map +1 -0
- package/dist/nodes/shared/providers/index.d.ts +2 -0
- package/dist/nodes/shared/providers/index.js +19 -0
- package/dist/nodes/shared/providers/index.js.map +1 -0
- package/dist/nodes/shared/providers/registry.d.ts +41 -0
- package/dist/nodes/shared/providers/registry.js +135 -0
- package/dist/nodes/shared/providers/registry.js.map +1 -0
- package/dist/nodes/shared/validation/index.d.ts +1 -0
- package/dist/nodes/shared/validation/index.js +18 -0
- package/dist/nodes/shared/validation/index.js.map +1 -0
- package/dist/nodes/shared/validation/options.d.ts +18 -0
- package/dist/nodes/shared/validation/options.js +50 -0
- package/dist/nodes/shared/validation/options.js.map +1 -0
- package/dist/package.json +9 -3
- package/dist/tsconfig.tsbuildinfo +1 -1
- package/package.json +9 -3
|
@@ -1,60 +1,16 @@
|
|
|
1
|
-
import { IExecuteFunctions } from 'n8n-workflow';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
private tail;
|
|
7
|
-
private readonly maxSize;
|
|
8
|
-
private readonly ttl;
|
|
9
|
-
private totalHits;
|
|
10
|
-
private totalMisses;
|
|
11
|
-
private totalEvictions;
|
|
12
|
-
constructor(maxSize: number, ttl?: number);
|
|
13
|
-
get(key: string): T | undefined;
|
|
14
|
-
set(key: string, value: T, customTTL?: number): void;
|
|
15
|
-
delete(key: string): boolean;
|
|
16
|
-
clear(): void;
|
|
17
|
-
getStats(): {
|
|
18
|
-
size: number;
|
|
19
|
-
maxSize: number;
|
|
20
|
-
hitRate: number;
|
|
21
|
-
totalHits: number;
|
|
22
|
-
totalMisses: number;
|
|
23
|
-
totalEvictions: number;
|
|
24
|
-
ttl: number;
|
|
25
|
-
};
|
|
26
|
-
private addToFront;
|
|
27
|
-
private moveToFront;
|
|
28
|
-
private remove;
|
|
29
|
-
}
|
|
30
|
-
export declare function getProviderCredentials(exec: IExecuteFunctions, provider: string, credentialName: string): Promise<{
|
|
31
|
-
apiKey: string;
|
|
32
|
-
baseUrl?: string;
|
|
33
|
-
}>;
|
|
34
|
-
export declare const modelCache: LRUCache<any[]>;
|
|
35
|
-
export declare const providerCache: LRUCache<ProviderInstance>;
|
|
1
|
+
import { IExecuteFunctions, INodePropertyOptions } from 'n8n-workflow';
|
|
2
|
+
import { ProcessingInput } from './types';
|
|
3
|
+
import { LRUCache } from './cache/cache';
|
|
4
|
+
export declare const modelCache: LRUCache<INodePropertyOptions[]>;
|
|
5
|
+
export declare const providerCache: LRUCache<any>;
|
|
36
6
|
export declare const schemaCache: LRUCache<Record<string, any>>;
|
|
37
|
-
export declare const googleCacheClients: LRUCache<any>;
|
|
38
|
-
export declare const googleCachedContexts: LRUCache<{
|
|
39
|
-
name: string;
|
|
40
|
-
}>;
|
|
41
7
|
export declare function restoreCacheableContent(params: Record<string, any>, input: ProcessingInput): void;
|
|
42
|
-
export declare function
|
|
43
|
-
export declare function getProvider(exec: IExecuteFunctions, provider: SupportedProvider, apiKey: string, baseURL?: string, customHeaders?: Record<string, string>): Promise<ProviderInstance>;
|
|
44
|
-
export declare function createGoogleCache(exec: IExecuteFunctions, index: number, apiKey: string, cacheableContent: CacheableContent[], modelId: string, thinkingBudgetValue: number, includeThoughts: boolean, tools?: Record<string, any>, ttlSeconds?: number): Promise<string | null>;
|
|
45
|
-
export declare function buildGoogleProviderOptions(exec: IExecuteFunctions, index: number, cachedContentName?: string, thinkingBudgetOverride?: number, includeThoughtsOverride?: boolean): GoogleProviderOptions | undefined;
|
|
46
|
-
export declare function buildGoogleTools(exec: IExecuteFunctions, index: number): Promise<Record<string, any> | undefined>;
|
|
47
|
-
export declare function createSpeechProvider(provider: 'google' | 'openai', apiKey: string, baseURL?: string): Promise<any>;
|
|
8
|
+
export declare function getProvider(exec: IExecuteFunctions, provider: string, apiKey: string, baseURL?: string, customHeaders?: Record<string, string>): Promise<any>;
|
|
48
9
|
export declare function getCredentials(exec: IExecuteFunctions, provider: 'google' | 'openai' | 'deepseek' | 'groq' | 'openrouter'): Promise<{
|
|
49
10
|
apiKey: string;
|
|
50
11
|
baseUrl?: string;
|
|
51
12
|
}>;
|
|
52
|
-
export declare function buildEmbeddingProviderOptions(provider: 'google' | 'openai', options: import('../shared/types').EmbeddingOptions): any;
|
|
53
|
-
export declare function buildImageProviderOptions(provider: 'google' | 'openai', options: import('../shared/types').ImageGenOptions): any;
|
|
54
|
-
export declare function validateEmbeddingOptions(options: import('../shared/types').EmbeddingOptions): void;
|
|
55
|
-
export declare function validateImageOptions(options: import('../shared/types').ImageGenOptions): void;
|
|
56
13
|
export declare function handleNodeError(exec: IExecuteFunctions, error: unknown, itemIndex?: number): never;
|
|
57
|
-
export
|
|
58
|
-
export
|
|
59
|
-
export
|
|
60
|
-
export declare function setupGoogleProviderOptions(exec: IExecuteFunctions, index: number, input: ProcessingInput, model: string, apiKey: string): Promise<GoogleProviderOptions | undefined>;
|
|
14
|
+
export { getGoogleCacheManager, createGoogleCache, buildGoogleProviderOptions, buildGoogleTools, setupGoogleProviderOptions } from './google/index';
|
|
15
|
+
export { validateEmbeddingOptions, validateImageOptions, validateRange, validateTextOptions } from './validation';
|
|
16
|
+
export { buildEmbeddingProviderOptions, buildImageProviderOptions, buildSpeechProviderOptions, buildTranscriptionProviderOptions } from './builders';
|
|
@@ -1,198 +1,17 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.
|
|
37
|
-
exports.getProviderCredentials = getProviderCredentials;
|
|
3
|
+
exports.buildTranscriptionProviderOptions = exports.buildSpeechProviderOptions = exports.buildImageProviderOptions = exports.buildEmbeddingProviderOptions = exports.validateTextOptions = exports.validateRange = exports.validateImageOptions = exports.validateEmbeddingOptions = exports.setupGoogleProviderOptions = exports.buildGoogleTools = exports.buildGoogleProviderOptions = exports.createGoogleCache = exports.getGoogleCacheManager = exports.schemaCache = exports.providerCache = exports.modelCache = void 0;
|
|
38
4
|
exports.restoreCacheableContent = restoreCacheableContent;
|
|
39
|
-
exports.getGoogleCacheManager = getGoogleCacheManager;
|
|
40
5
|
exports.getProvider = getProvider;
|
|
41
|
-
exports.createGoogleCache = createGoogleCache;
|
|
42
|
-
exports.buildGoogleProviderOptions = buildGoogleProviderOptions;
|
|
43
|
-
exports.buildGoogleTools = buildGoogleTools;
|
|
44
|
-
exports.createSpeechProvider = createSpeechProvider;
|
|
45
6
|
exports.getCredentials = getCredentials;
|
|
46
|
-
exports.buildEmbeddingProviderOptions = buildEmbeddingProviderOptions;
|
|
47
|
-
exports.buildImageProviderOptions = buildImageProviderOptions;
|
|
48
|
-
exports.validateEmbeddingOptions = validateEmbeddingOptions;
|
|
49
|
-
exports.validateImageOptions = validateImageOptions;
|
|
50
7
|
exports.handleNodeError = handleNodeError;
|
|
51
|
-
exports.createTranscriptionProvider = createTranscriptionProvider;
|
|
52
|
-
exports.createImageProvider = createImageProvider;
|
|
53
|
-
exports.createEmbeddingProvider = createEmbeddingProvider;
|
|
54
|
-
exports.setupGoogleProviderOptions = setupGoogleProviderOptions;
|
|
55
8
|
const n8n_workflow_1 = require("n8n-workflow");
|
|
56
9
|
const constants_1 = require("./constants");
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
this.totalHits = 0;
|
|
63
|
-
this.totalMisses = 0;
|
|
64
|
-
this.totalEvictions = 0;
|
|
65
|
-
this.maxSize = maxSize;
|
|
66
|
-
this.ttl = ttl;
|
|
67
|
-
}
|
|
68
|
-
get(key) {
|
|
69
|
-
const node = this.cache.get(key);
|
|
70
|
-
if (!node) {
|
|
71
|
-
this.totalMisses++;
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
if (node.expiresAt && Date.now() > node.expiresAt) {
|
|
75
|
-
this.remove(node);
|
|
76
|
-
this.totalEvictions++;
|
|
77
|
-
this.totalMisses++;
|
|
78
|
-
return undefined;
|
|
79
|
-
}
|
|
80
|
-
this.moveToFront(node);
|
|
81
|
-
node.hits++;
|
|
82
|
-
this.totalHits++;
|
|
83
|
-
return node.value;
|
|
84
|
-
}
|
|
85
|
-
set(key, value, customTTL) {
|
|
86
|
-
const existingNode = this.cache.get(key);
|
|
87
|
-
if (existingNode) {
|
|
88
|
-
existingNode.value = value;
|
|
89
|
-
existingNode.expiresAt = customTTL ? Date.now() + customTTL : (this.ttl > 0 ? Date.now() + this.ttl : undefined);
|
|
90
|
-
this.moveToFront(existingNode);
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
if (this.cache.size >= this.maxSize && this.tail) {
|
|
94
|
-
this.remove(this.tail);
|
|
95
|
-
this.totalEvictions++;
|
|
96
|
-
}
|
|
97
|
-
const newNode = {
|
|
98
|
-
key,
|
|
99
|
-
value,
|
|
100
|
-
expiresAt: customTTL ? Date.now() + customTTL : (this.ttl > 0 ? Date.now() + this.ttl : undefined),
|
|
101
|
-
hits: 0,
|
|
102
|
-
prev: null,
|
|
103
|
-
next: null,
|
|
104
|
-
};
|
|
105
|
-
this.cache.set(key, newNode);
|
|
106
|
-
this.addToFront(newNode);
|
|
107
|
-
}
|
|
108
|
-
delete(key) {
|
|
109
|
-
const node = this.cache.get(key);
|
|
110
|
-
if (!node)
|
|
111
|
-
return false;
|
|
112
|
-
this.remove(node);
|
|
113
|
-
return true;
|
|
114
|
-
}
|
|
115
|
-
clear() {
|
|
116
|
-
this.cache.clear();
|
|
117
|
-
this.head = null;
|
|
118
|
-
this.tail = null;
|
|
119
|
-
this.totalHits = 0;
|
|
120
|
-
this.totalMisses = 0;
|
|
121
|
-
this.totalEvictions = 0;
|
|
122
|
-
}
|
|
123
|
-
getStats() {
|
|
124
|
-
return {
|
|
125
|
-
size: this.cache.size,
|
|
126
|
-
maxSize: this.maxSize,
|
|
127
|
-
hitRate: this.totalHits / (this.totalHits + this.totalMisses) || 0,
|
|
128
|
-
totalHits: this.totalHits,
|
|
129
|
-
totalMisses: this.totalMisses,
|
|
130
|
-
totalEvictions: this.totalEvictions,
|
|
131
|
-
ttl: this.ttl,
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
addToFront(node) {
|
|
135
|
-
node.next = this.head;
|
|
136
|
-
node.prev = null;
|
|
137
|
-
if (this.head) {
|
|
138
|
-
this.head.prev = node;
|
|
139
|
-
}
|
|
140
|
-
this.head = node;
|
|
141
|
-
if (!this.tail) {
|
|
142
|
-
this.tail = node;
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
moveToFront(node) {
|
|
146
|
-
if (node === this.head)
|
|
147
|
-
return;
|
|
148
|
-
if (node.prev) {
|
|
149
|
-
node.prev.next = node.next;
|
|
150
|
-
}
|
|
151
|
-
if (node.next) {
|
|
152
|
-
node.next.prev = node.prev;
|
|
153
|
-
}
|
|
154
|
-
if (node === this.tail) {
|
|
155
|
-
this.tail = node.prev;
|
|
156
|
-
}
|
|
157
|
-
node.next = this.head;
|
|
158
|
-
node.prev = null;
|
|
159
|
-
if (this.head) {
|
|
160
|
-
this.head.prev = node;
|
|
161
|
-
}
|
|
162
|
-
this.head = node;
|
|
163
|
-
}
|
|
164
|
-
remove(node) {
|
|
165
|
-
if (node.prev) {
|
|
166
|
-
node.prev.next = node.next;
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
this.head = node.next;
|
|
170
|
-
}
|
|
171
|
-
if (node.next) {
|
|
172
|
-
node.next.prev = node.prev;
|
|
173
|
-
}
|
|
174
|
-
else {
|
|
175
|
-
this.tail = node.prev;
|
|
176
|
-
}
|
|
177
|
-
this.cache.delete(node.key);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
exports.LRUCache = LRUCache;
|
|
181
|
-
async function getProviderCredentials(exec, provider, credentialName) {
|
|
182
|
-
const credentials = await exec.getCredentials(credentialName);
|
|
183
|
-
if (!(credentials === null || credentials === void 0 ? void 0 : credentials.apiKey)) {
|
|
184
|
-
throw new n8n_workflow_1.NodeOperationError(exec.getNode(), `No API key provided in ${credentialName} credentials`);
|
|
185
|
-
}
|
|
186
|
-
return {
|
|
187
|
-
apiKey: credentials.apiKey,
|
|
188
|
-
baseUrl: credentials.baseUrl,
|
|
189
|
-
};
|
|
190
|
-
}
|
|
191
|
-
exports.modelCache = new LRUCache(constants_1.CACHE_SIZE.MODEL);
|
|
192
|
-
exports.providerCache = new LRUCache(constants_1.CACHE_SIZE.PROVIDER);
|
|
193
|
-
exports.schemaCache = new LRUCache(constants_1.CACHE_SIZE.SCHEMA);
|
|
194
|
-
exports.googleCacheClients = new LRUCache(constants_1.CACHE_SIZE.GOOGLE_CLIENT, constants_1.CACHE_TTL.GOOGLE_CLIENT);
|
|
195
|
-
exports.googleCachedContexts = new LRUCache(constants_1.CACHE_SIZE.GOOGLE_CONTEXT, constants_1.CACHE_TTL.GOOGLE_CONTEXT);
|
|
10
|
+
const cache_1 = require("./cache/cache");
|
|
11
|
+
const providers_1 = require("./providers");
|
|
12
|
+
exports.modelCache = new cache_1.LRUCache(constants_1.CACHE_SIZE.MODEL);
|
|
13
|
+
exports.providerCache = new cache_1.LRUCache(constants_1.CACHE_SIZE.PROVIDER);
|
|
14
|
+
exports.schemaCache = new cache_1.LRUCache(constants_1.CACHE_SIZE.SCHEMA);
|
|
196
15
|
function restoreCacheableContent(params, input) {
|
|
197
16
|
if (!input.cacheableContent || input.cacheableContent.length === 0) {
|
|
198
17
|
return;
|
|
@@ -230,15 +49,6 @@ function restoreCacheableContent(params, input) {
|
|
|
230
49
|
}
|
|
231
50
|
}
|
|
232
51
|
}
|
|
233
|
-
async function getGoogleCacheManager(apiKey) {
|
|
234
|
-
let client = exports.googleCacheClients.get(apiKey);
|
|
235
|
-
if (!client) {
|
|
236
|
-
const { GoogleGenAI } = await Promise.resolve().then(() => __importStar(require('@google/genai')));
|
|
237
|
-
client = new GoogleGenAI({ apiKey });
|
|
238
|
-
exports.googleCacheClients.set(apiKey, client);
|
|
239
|
-
}
|
|
240
|
-
return client;
|
|
241
|
-
}
|
|
242
52
|
async function getProvider(exec, provider, apiKey, baseURL, customHeaders) {
|
|
243
53
|
const headersKey = customHeaders
|
|
244
54
|
? JSON.stringify(Object.keys(customHeaders)
|
|
@@ -249,41 +59,8 @@ async function getProvider(exec, provider, apiKey, baseURL, customHeaders) {
|
|
|
249
59
|
const cached = exports.providerCache.get(cacheKey);
|
|
250
60
|
if (cached)
|
|
251
61
|
return cached;
|
|
252
|
-
let providerInstance;
|
|
253
62
|
try {
|
|
254
|
-
|
|
255
|
-
case 'google':
|
|
256
|
-
const { createGoogleGenerativeAI } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/google')));
|
|
257
|
-
providerInstance = createGoogleGenerativeAI({
|
|
258
|
-
apiKey,
|
|
259
|
-
...(baseURL && { baseURL }),
|
|
260
|
-
...(customHeaders && Object.keys(customHeaders).length > 0 && { headers: customHeaders }),
|
|
261
|
-
});
|
|
262
|
-
break;
|
|
263
|
-
case 'deepseek':
|
|
264
|
-
const { createDeepSeek } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/deepseek')));
|
|
265
|
-
providerInstance = createDeepSeek({
|
|
266
|
-
apiKey,
|
|
267
|
-
...(baseURL && { baseURL }),
|
|
268
|
-
});
|
|
269
|
-
break;
|
|
270
|
-
case 'groq':
|
|
271
|
-
const { createGroq } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/groq')));
|
|
272
|
-
providerInstance = createGroq({
|
|
273
|
-
apiKey,
|
|
274
|
-
...(baseURL && { baseURL }),
|
|
275
|
-
});
|
|
276
|
-
break;
|
|
277
|
-
case 'openrouter':
|
|
278
|
-
const { createOpenRouter } = await Promise.resolve().then(() => __importStar(require('@openrouter/ai-sdk-provider')));
|
|
279
|
-
providerInstance = createOpenRouter({
|
|
280
|
-
apiKey,
|
|
281
|
-
...(baseURL && { baseURL }),
|
|
282
|
-
});
|
|
283
|
-
break;
|
|
284
|
-
default:
|
|
285
|
-
throw new Error(`Unsupported provider: ${provider}`);
|
|
286
|
-
}
|
|
63
|
+
const providerInstance = await (0, providers_1.createProvider)(provider, apiKey, baseURL, customHeaders);
|
|
287
64
|
exports.providerCache.set(cacheKey, providerInstance);
|
|
288
65
|
return providerInstance;
|
|
289
66
|
}
|
|
@@ -292,111 +69,6 @@ async function getProvider(exec, provider, apiKey, baseURL, customHeaders) {
|
|
|
292
69
|
throw new n8n_workflow_1.NodeOperationError(exec.getNode(), `Failed to create ${provider} provider: ${errorMessage}`);
|
|
293
70
|
}
|
|
294
71
|
}
|
|
295
|
-
async function createGoogleCache(exec, index, apiKey, cacheableContent, modelId, thinkingBudgetValue, includeThoughts, tools, ttlSeconds) {
|
|
296
|
-
try {
|
|
297
|
-
if (!cacheableContent || cacheableContent.length === 0) {
|
|
298
|
-
return null;
|
|
299
|
-
}
|
|
300
|
-
const googleCacheManager = await getGoogleCacheManager(apiKey);
|
|
301
|
-
const cacheKeyData = {
|
|
302
|
-
content: JSON.stringify(cacheableContent),
|
|
303
|
-
tools: tools ? Object.keys(tools).sort() : [],
|
|
304
|
-
model: modelId,
|
|
305
|
-
thinkingBudgetValue,
|
|
306
|
-
includeThoughts,
|
|
307
|
-
};
|
|
308
|
-
const cacheKey = JSON.stringify(cacheKeyData, Object.keys(cacheKeyData).sort());
|
|
309
|
-
const existingCache = exports.googleCachedContexts.get(cacheKey);
|
|
310
|
-
if (existingCache) {
|
|
311
|
-
console.log(`UniversalAI: Reusing existing cache: ${existingCache.name}`);
|
|
312
|
-
return existingCache.name;
|
|
313
|
-
}
|
|
314
|
-
const ttl = ttlSeconds || constants_1.GOOGLE_CACHE.DEFAULT_TTL_SECONDS;
|
|
315
|
-
const displayName = `universal_ai_cache_${Date.now()}`;
|
|
316
|
-
const cacheConfig = {
|
|
317
|
-
model: modelId,
|
|
318
|
-
config: {
|
|
319
|
-
displayName,
|
|
320
|
-
ttl: `${ttl}s`,
|
|
321
|
-
contents: cacheableContent,
|
|
322
|
-
},
|
|
323
|
-
};
|
|
324
|
-
if (tools && Object.keys(tools).length > 0) {
|
|
325
|
-
cacheConfig.config.tools = Object.values(tools);
|
|
326
|
-
}
|
|
327
|
-
console.log(`UniversalAI: Creating new cache...`);
|
|
328
|
-
const result = await googleCacheManager.caches.create(cacheConfig);
|
|
329
|
-
const cachedContentName = result === null || result === void 0 ? void 0 : result.name;
|
|
330
|
-
if (!cachedContentName) {
|
|
331
|
-
throw new Error('Cache creation returned no name identifier');
|
|
332
|
-
}
|
|
333
|
-
console.log(`UniversalAI: Cache created successfully: ${cachedContentName}`);
|
|
334
|
-
exports.googleCachedContexts.set(cacheKey, { name: cachedContentName }, (ttl - constants_1.GOOGLE_CACHE.MIN_REFRESH_BUFFER_SECONDS) * 1000);
|
|
335
|
-
return cachedContentName;
|
|
336
|
-
}
|
|
337
|
-
catch (error) {
|
|
338
|
-
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
339
|
-
console.error('UniversalAI: Google cache creation failed:', errorMessage);
|
|
340
|
-
if (errorMessage.includes('INVALID_ARGUMENT') || errorMessage.includes('content is too small')) {
|
|
341
|
-
console.warn('UniversalAI: Content may be below minimum token requirement (1,024 tokens (~4800 symbols) for 2.5 Flash and 2,048 tokens (~9600 symbols) for 2.5 Pro)');
|
|
342
|
-
}
|
|
343
|
-
return null;
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
function buildGoogleProviderOptions(exec, index, cachedContentName, thinkingBudgetOverride, includeThoughtsOverride) {
|
|
347
|
-
const thinkingBudgetValue = thinkingBudgetOverride !== null && thinkingBudgetOverride !== void 0 ? thinkingBudgetOverride : Number(exec.getNodeParameter('thinkingBudget', index, -1));
|
|
348
|
-
const includeThoughts = includeThoughtsOverride !== null && includeThoughtsOverride !== void 0 ? includeThoughtsOverride : exec.getNodeParameter('includeThoughts', index, false);
|
|
349
|
-
const options = {};
|
|
350
|
-
if (!Number.isNaN(thinkingBudgetValue) && thinkingBudgetValue > -1) {
|
|
351
|
-
options.thinkingConfig = {
|
|
352
|
-
thinkingBudget: Math.max(0, thinkingBudgetValue),
|
|
353
|
-
includeThoughts,
|
|
354
|
-
};
|
|
355
|
-
}
|
|
356
|
-
if (cachedContentName) {
|
|
357
|
-
options.cachedContent = cachedContentName;
|
|
358
|
-
}
|
|
359
|
-
return Object.keys(options).length > 0 ? options : undefined;
|
|
360
|
-
}
|
|
361
|
-
async function buildGoogleTools(exec, index) {
|
|
362
|
-
const googleTools = exec.getNodeParameter('googleTools', index, []);
|
|
363
|
-
if (!googleTools || googleTools.length === 0) {
|
|
364
|
-
return undefined;
|
|
365
|
-
}
|
|
366
|
-
const tools = {};
|
|
367
|
-
const { google } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/google')));
|
|
368
|
-
const toolSet = new Set(googleTools);
|
|
369
|
-
if (toolSet.has('google_search')) {
|
|
370
|
-
tools.google_search = google.tools.googleSearch({});
|
|
371
|
-
}
|
|
372
|
-
if (toolSet.has('url_context')) {
|
|
373
|
-
tools.url_context = google.tools.urlContext({});
|
|
374
|
-
}
|
|
375
|
-
if (toolSet.has('code_execution')) {
|
|
376
|
-
tools.code_execution = google.tools.codeExecution({});
|
|
377
|
-
}
|
|
378
|
-
return tools;
|
|
379
|
-
}
|
|
380
|
-
async function createSpeechProvider(provider, apiKey, baseURL) {
|
|
381
|
-
switch (provider) {
|
|
382
|
-
case 'google':
|
|
383
|
-
const { createGoogleGenerativeAI } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/google')));
|
|
384
|
-
const google = createGoogleGenerativeAI({
|
|
385
|
-
apiKey,
|
|
386
|
-
...(baseURL && { baseURL }),
|
|
387
|
-
});
|
|
388
|
-
return google;
|
|
389
|
-
case 'openai':
|
|
390
|
-
const { createOpenAI } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/openai')));
|
|
391
|
-
const openai = createOpenAI({
|
|
392
|
-
apiKey,
|
|
393
|
-
...(baseURL && { baseURL }),
|
|
394
|
-
});
|
|
395
|
-
return openai;
|
|
396
|
-
default:
|
|
397
|
-
throw new Error(`Unsupported speech provider: ${provider}`);
|
|
398
|
-
}
|
|
399
|
-
}
|
|
400
72
|
async function getCredentials(exec, provider) {
|
|
401
73
|
let credentials = null;
|
|
402
74
|
switch (provider) {
|
|
@@ -424,165 +96,24 @@ async function getCredentials(exec, provider) {
|
|
|
424
96
|
baseUrl: credentials.baseUrl,
|
|
425
97
|
};
|
|
426
98
|
}
|
|
427
|
-
function buildEmbeddingProviderOptions(provider, options) {
|
|
428
|
-
const providerOptions = {};
|
|
429
|
-
if (provider === 'google') {
|
|
430
|
-
if (options.outputDimensionality && options.outputDimensionality > 0) {
|
|
431
|
-
providerOptions.google = {
|
|
432
|
-
outputDimensionality: options.outputDimensionality,
|
|
433
|
-
};
|
|
434
|
-
}
|
|
435
|
-
if (options.taskType) {
|
|
436
|
-
providerOptions.google = {
|
|
437
|
-
...providerOptions.google,
|
|
438
|
-
taskType: options.taskType,
|
|
439
|
-
};
|
|
440
|
-
}
|
|
441
|
-
}
|
|
442
|
-
else if (provider === 'openai') {
|
|
443
|
-
if (options.dimensions && options.dimensions > 0) {
|
|
444
|
-
providerOptions.openai = {
|
|
445
|
-
dimensions: options.dimensions,
|
|
446
|
-
};
|
|
447
|
-
}
|
|
448
|
-
}
|
|
449
|
-
return Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
|
|
450
|
-
}
|
|
451
|
-
function buildImageProviderOptions(provider, options) {
|
|
452
|
-
const providerOptions = {};
|
|
453
|
-
if (provider === 'google') {
|
|
454
|
-
providerOptions.google = {};
|
|
455
|
-
if (options.aspectRatio) {
|
|
456
|
-
providerOptions.google.aspectRatio = options.aspectRatio;
|
|
457
|
-
}
|
|
458
|
-
if (options.negativePrompt) {
|
|
459
|
-
providerOptions.google.negativePrompt = options.negativePrompt;
|
|
460
|
-
}
|
|
461
|
-
if (options.safetyFilterLevel) {
|
|
462
|
-
providerOptions.google.safetyFilterLevel = options.safetyFilterLevel;
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
else if (provider === 'openai') {
|
|
466
|
-
providerOptions.openai = {};
|
|
467
|
-
if (options.size) {
|
|
468
|
-
providerOptions.openai.size = options.size;
|
|
469
|
-
}
|
|
470
|
-
if (options.quality) {
|
|
471
|
-
providerOptions.openai.quality = options.quality;
|
|
472
|
-
}
|
|
473
|
-
if (options.style) {
|
|
474
|
-
providerOptions.openai.style = options.style;
|
|
475
|
-
}
|
|
476
|
-
}
|
|
477
|
-
return Object.keys(providerOptions).length > 0 ? providerOptions : undefined;
|
|
478
|
-
}
|
|
479
|
-
function validateEmbeddingOptions(options) {
|
|
480
|
-
const { AI_VALIDATION } = require('./constants');
|
|
481
|
-
if (options.dimensions !== undefined) {
|
|
482
|
-
if (options.dimensions < AI_VALIDATION.MIN_DIMENSIONS || options.dimensions > AI_VALIDATION.MAX_DIMENSIONS) {
|
|
483
|
-
throw new Error(`Dimensions must be between ${AI_VALIDATION.MIN_DIMENSIONS} and ${AI_VALIDATION.MAX_DIMENSIONS}`);
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
if (options.outputDimensionality !== undefined) {
|
|
487
|
-
if (options.outputDimensionality < AI_VALIDATION.MIN_OUTPUT_DIMENSIONALITY || options.outputDimensionality > AI_VALIDATION.MAX_OUTPUT_DIMENSIONALITY) {
|
|
488
|
-
throw new Error(`Output dimensionality must be between ${AI_VALIDATION.MIN_OUTPUT_DIMENSIONALITY} and ${AI_VALIDATION.MAX_OUTPUT_DIMENSIONALITY}`);
|
|
489
|
-
}
|
|
490
|
-
}
|
|
491
|
-
if (options.maxParallelCalls !== undefined && options.maxParallelCalls < 1) {
|
|
492
|
-
throw new Error('maxParallelCalls must be greater than 0');
|
|
493
|
-
}
|
|
494
|
-
if (options.maxRetries !== undefined && options.maxRetries < 0) {
|
|
495
|
-
throw new Error('maxRetries must be greater than or equal to 0');
|
|
496
|
-
}
|
|
497
|
-
}
|
|
498
|
-
function validateImageOptions(options) {
|
|
499
|
-
const { AI_VALIDATION } = require('./constants');
|
|
500
|
-
if (options.n !== undefined) {
|
|
501
|
-
if (options.n < 1 || options.n > AI_VALIDATION.MAX_IMAGE_COUNT) {
|
|
502
|
-
throw new Error(`Image count must be between 1 and ${AI_VALIDATION.MAX_IMAGE_COUNT}`);
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
99
|
function handleNodeError(exec, error, itemIndex) {
|
|
507
100
|
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
}
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
const { createGoogleGenerativeAI } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/google')));
|
|
527
|
-
const google = createGoogleGenerativeAI({
|
|
528
|
-
apiKey,
|
|
529
|
-
...(baseURL && { baseURL }),
|
|
530
|
-
});
|
|
531
|
-
return google;
|
|
532
|
-
case 'openai':
|
|
533
|
-
const { createOpenAI } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/openai')));
|
|
534
|
-
const openai = createOpenAI({
|
|
535
|
-
apiKey,
|
|
536
|
-
...(baseURL && { baseURL }),
|
|
537
|
-
});
|
|
538
|
-
return openai;
|
|
539
|
-
default:
|
|
540
|
-
throw new Error(`Unsupported image provider: ${provider}`);
|
|
541
|
-
}
|
|
542
|
-
}
|
|
543
|
-
async function createEmbeddingProvider(provider, apiKey, baseURL) {
|
|
544
|
-
switch (provider) {
|
|
545
|
-
case 'google':
|
|
546
|
-
const { createGoogleGenerativeAI } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/google')));
|
|
547
|
-
const google = createGoogleGenerativeAI({
|
|
548
|
-
apiKey,
|
|
549
|
-
...(baseURL && { baseURL }),
|
|
550
|
-
});
|
|
551
|
-
return google;
|
|
552
|
-
case 'openai':
|
|
553
|
-
const { createOpenAI } = await Promise.resolve().then(() => __importStar(require('@ai-sdk/openai')));
|
|
554
|
-
const openai = createOpenAI({
|
|
555
|
-
apiKey,
|
|
556
|
-
...(baseURL && { baseURL }),
|
|
557
|
-
});
|
|
558
|
-
return openai;
|
|
559
|
-
default:
|
|
560
|
-
throw new Error(`Unsupported embedding provider: ${provider}`);
|
|
561
|
-
}
|
|
562
|
-
}
|
|
563
|
-
async function setupGoogleProviderOptions(exec, index, input, model, apiKey) {
|
|
564
|
-
const tools = await buildGoogleTools(exec, index);
|
|
565
|
-
let googleProviderOptions;
|
|
566
|
-
let thinkingBudgetValue;
|
|
567
|
-
let includeThoughts;
|
|
568
|
-
if (thinkingBudgetValue === undefined) {
|
|
569
|
-
thinkingBudgetValue = Number(exec.getNodeParameter('thinkingBudget', index, -1));
|
|
570
|
-
includeThoughts = exec.getNodeParameter('includeThoughts', index, false);
|
|
571
|
-
}
|
|
572
|
-
if (input.cacheableContent && input.cacheableContent.length > 0) {
|
|
573
|
-
const cacheTTL = exec.getNodeParameter('cacheTTL', index, constants_1.GOOGLE_CACHE.DEFAULT_TTL_SECONDS);
|
|
574
|
-
const cachedContentName = await createGoogleCache(exec, index, apiKey, input.cacheableContent, model, thinkingBudgetValue !== null && thinkingBudgetValue !== void 0 ? thinkingBudgetValue : -1, includeThoughts !== null && includeThoughts !== void 0 ? includeThoughts : false, tools, cacheTTL);
|
|
575
|
-
if (cachedContentName) {
|
|
576
|
-
googleProviderOptions = buildGoogleProviderOptions(exec, index, cachedContentName, thinkingBudgetValue, includeThoughts);
|
|
577
|
-
}
|
|
578
|
-
else {
|
|
579
|
-
googleProviderOptions = buildGoogleProviderOptions(exec, index, undefined, thinkingBudgetValue, includeThoughts);
|
|
580
|
-
console.log('UniversalAI: Cache creation failed, falling back to regular content');
|
|
581
|
-
}
|
|
582
|
-
}
|
|
583
|
-
else {
|
|
584
|
-
googleProviderOptions = buildGoogleProviderOptions(exec, index, undefined, thinkingBudgetValue, includeThoughts);
|
|
585
|
-
}
|
|
586
|
-
return googleProviderOptions;
|
|
587
|
-
}
|
|
101
|
+
throw new n8n_workflow_1.NodeOperationError(exec.getNode(), errorMessage, { itemIndex });
|
|
102
|
+
}
|
|
103
|
+
var index_1 = require("./google/index");
|
|
104
|
+
Object.defineProperty(exports, "getGoogleCacheManager", { enumerable: true, get: function () { return index_1.getGoogleCacheManager; } });
|
|
105
|
+
Object.defineProperty(exports, "createGoogleCache", { enumerable: true, get: function () { return index_1.createGoogleCache; } });
|
|
106
|
+
Object.defineProperty(exports, "buildGoogleProviderOptions", { enumerable: true, get: function () { return index_1.buildGoogleProviderOptions; } });
|
|
107
|
+
Object.defineProperty(exports, "buildGoogleTools", { enumerable: true, get: function () { return index_1.buildGoogleTools; } });
|
|
108
|
+
Object.defineProperty(exports, "setupGoogleProviderOptions", { enumerable: true, get: function () { return index_1.setupGoogleProviderOptions; } });
|
|
109
|
+
var validation_1 = require("./validation");
|
|
110
|
+
Object.defineProperty(exports, "validateEmbeddingOptions", { enumerable: true, get: function () { return validation_1.validateEmbeddingOptions; } });
|
|
111
|
+
Object.defineProperty(exports, "validateImageOptions", { enumerable: true, get: function () { return validation_1.validateImageOptions; } });
|
|
112
|
+
Object.defineProperty(exports, "validateRange", { enumerable: true, get: function () { return validation_1.validateRange; } });
|
|
113
|
+
Object.defineProperty(exports, "validateTextOptions", { enumerable: true, get: function () { return validation_1.validateTextOptions; } });
|
|
114
|
+
var builders_1 = require("./builders");
|
|
115
|
+
Object.defineProperty(exports, "buildEmbeddingProviderOptions", { enumerable: true, get: function () { return builders_1.buildEmbeddingProviderOptions; } });
|
|
116
|
+
Object.defineProperty(exports, "buildImageProviderOptions", { enumerable: true, get: function () { return builders_1.buildImageProviderOptions; } });
|
|
117
|
+
Object.defineProperty(exports, "buildSpeechProviderOptions", { enumerable: true, get: function () { return builders_1.buildSpeechProviderOptions; } });
|
|
118
|
+
Object.defineProperty(exports, "buildTranscriptionProviderOptions", { enumerable: true, get: function () { return builders_1.buildTranscriptionProviderOptions; } });
|
|
588
119
|
//# sourceMappingURL=helpers.js.map
|