@retrivora-ai/rag-engine 2.5.7 → 2.5.9

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 (51) hide show
  1. package/dist/{ILLMProvider-DwFj0h2u.d.mts → ILLMProvider-B2N3lMBc.d.mts} +10 -1
  2. package/dist/{ILLMProvider-DwFj0h2u.d.ts → ILLMProvider-B2N3lMBc.d.ts} +10 -1
  3. package/dist/handlers/index.d.mts +2 -2
  4. package/dist/handlers/index.d.ts +2 -2
  5. package/dist/handlers/index.js +962 -193
  6. package/dist/handlers/index.mjs +12821 -24
  7. package/dist/{index-Cb0GsT16.d.ts → index-37V810a-.d.mts} +3 -3
  8. package/dist/{index-D1jN8KSF.d.mts → index-BxzDv2jd.d.ts} +3 -3
  9. package/dist/{index-9h_ENWQn.d.mts → index-CAGGPyI7.d.mts} +6 -2
  10. package/dist/{index-Xci6GfpI.d.ts → index-DdQxoIpu.d.ts} +6 -2
  11. package/dist/index.css +76 -4
  12. package/dist/index.d.mts +6 -6
  13. package/dist/index.d.ts +6 -6
  14. package/dist/index.js +138 -96
  15. package/dist/index.min.css +1 -1
  16. package/dist/index.mjs +1554 -130
  17. package/dist/server.d.mts +100 -9
  18. package/dist/server.d.ts +100 -9
  19. package/dist/server.js +964 -193
  20. package/dist/server.mjs +13378 -372
  21. package/package.json +5 -2
  22. package/dist/ChromaDBProvider-4RPJN7Y3.mjs +0 -8
  23. package/dist/MilvusProvider-WJLLZ6TW.mjs +0 -8
  24. package/dist/MongoDBProvider-QSERELZX.mjs +0 -8
  25. package/dist/MultiTablePostgresProvider-JF2HEUDZ.mjs +0 -9
  26. package/dist/PineconeProvider-HLZL7HKU.mjs +0 -10
  27. package/dist/PostgreSQLProvider-JQMCNHRO.mjs +0 -8
  28. package/dist/QdrantProvider-6MNFPEVC.mjs +0 -8
  29. package/dist/RedisProvider-ERQL6AEB.mjs +0 -8
  30. package/dist/SimpleGraphProvider-OP3HAJJM.mjs +0 -70
  31. package/dist/UniversalVectorProvider-INM3KH5F.mjs +0 -9
  32. package/dist/WeaviateProvider-VHWWICCC.mjs +0 -8
  33. package/dist/chunk-366EFBZC.mjs +0 -165
  34. package/dist/chunk-6MGVQTU4.mjs +0 -8883
  35. package/dist/chunk-B4AXIUM7.mjs +0 -49
  36. package/dist/chunk-BEPLYQBS.mjs +0 -89
  37. package/dist/chunk-BNOPQCZW.mjs +0 -238
  38. package/dist/chunk-FJ43J4FW.mjs +0 -654
  39. package/dist/chunk-GP2AJQRQ.mjs +0 -107
  40. package/dist/chunk-IMP6FUCY.mjs +0 -30
  41. package/dist/chunk-JRQWSJNF.mjs +0 -202
  42. package/dist/chunk-LYHCKUNF.mjs +0 -112
  43. package/dist/chunk-MFIWWUC7.mjs +0 -152
  44. package/dist/chunk-MWICNCB2.mjs +0 -157
  45. package/dist/chunk-N54YTFBN.mjs +0 -76
  46. package/dist/chunk-POOWU2HR.mjs +0 -211
  47. package/dist/chunk-QGDGPOZH.mjs +0 -217
  48. package/dist/chunk-QI3FTN6G.mjs +0 -281
  49. package/dist/chunk-QJIDGVG6.mjs +0 -334
  50. package/dist/chunk-W2DKVD3G.mjs +0 -81
  51. package/dist/chunk-XHSDHPKI.mjs +0 -336
@@ -1,281 +0,0 @@
1
- import {
2
- ConfigFetcher
3
- } from "./chunk-QJIDGVG6.mjs";
4
- import {
5
- BaseVectorProvider
6
- } from "./chunk-IMP6FUCY.mjs";
7
- import {
8
- __spreadValues
9
- } from "./chunk-N54YTFBN.mjs";
10
-
11
- // src/providers/vectordb/PineconeProvider.ts
12
- import { Pinecone } from "@pinecone-database/pinecone";
13
- var PineconeProvider = class extends BaseVectorProvider {
14
- constructor(config) {
15
- super(config);
16
- const opts = config.options || {};
17
- this.apiKey = opts.apiKey || process.env.PINECONE_API_KEY || "";
18
- }
19
- getControlPlaneUrl() {
20
- const urls = [
21
- process.env.RETRIVORA_CONTROL_PLANE_URL,
22
- process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
23
- "https://www.retrivora.com"
24
- ].filter((url) => Boolean(url));
25
- return urls[0].replace(/\/$/, "");
26
- }
27
- static getValidator() {
28
- return {
29
- validate(config) {
30
- const errors = [];
31
- const opts = config.options || {};
32
- const hasLicenseKey = Boolean(
33
- config.licenseKey || process.env.RETRIVORA_LICENSE_KEY
34
- );
35
- if (!opts.apiKey && !hasLicenseKey) {
36
- errors.push({
37
- field: "vectorDb.options.apiKey",
38
- message: "Pinecone API key is required when RETRIVORA_LICENSE_KEY is not set",
39
- suggestion: "Set PINECONE_API_KEY environment variable or supply RETRIVORA_LICENSE_KEY for keyless vector storage",
40
- severity: "error"
41
- });
42
- }
43
- return errors;
44
- }
45
- };
46
- }
47
- static getHealthChecker() {
48
- return {
49
- async check(config) {
50
- var _a, _b;
51
- const opts = config.options || {};
52
- const indexName = config.indexName;
53
- const timestamp = Date.now();
54
- try {
55
- const { Pinecone: Pinecone2 } = await import("@pinecone-database/pinecone");
56
- const client = new Pinecone2({ apiKey: opts.apiKey });
57
- const indexes = await client.listIndexes();
58
- const indexNames = (_b = (_a = indexes.indexes) == null ? void 0 : _a.map((i) => i.name)) != null ? _b : [];
59
- if (!indexNames.includes(indexName)) {
60
- return {
61
- healthy: false,
62
- provider: "pinecone",
63
- error: `Index "${indexName}" not found. Available: ${indexNames.join(", ")}`,
64
- timestamp
65
- };
66
- }
67
- return {
68
- healthy: true,
69
- provider: "pinecone",
70
- capabilities: { indexes: indexNames.length, targetIndex: indexName },
71
- timestamp
72
- };
73
- } catch (error) {
74
- return {
75
- healthy: false,
76
- provider: "pinecone",
77
- error: `Connection failed: ${error instanceof Error ? error.message : String(error)}`,
78
- timestamp
79
- };
80
- }
81
- }
82
- };
83
- }
84
- async initialize() {
85
- var _a, _b;
86
- if (this.client) return;
87
- let key = this.apiKey || process.env.PINECONE_API_KEY || "";
88
- if (!key) {
89
- const licenseKey = process.env.RETRIVORA_LICENSE_KEY;
90
- this.licenseKey = licenseKey;
91
- const projectId = process.env.RAG_PROJECT_ID || process.env.NEXT_PUBLIC_RAG_PROJECT_ID || this.projectId || "default";
92
- this.projectId = projectId;
93
- const remoteConfig = await ConfigFetcher.fetchRemoteVectorConfig(projectId, licenseKey);
94
- if (remoteConfig) {
95
- if (remoteConfig.apiKey) {
96
- key = remoteConfig.apiKey;
97
- this.apiKey = key;
98
- }
99
- if (remoteConfig.indexName) {
100
- this.indexName = remoteConfig.indexName;
101
- }
102
- if (remoteConfig.projectId) {
103
- this.projectId = remoteConfig.projectId;
104
- }
105
- if (remoteConfig.namespace) {
106
- this.namespace = remoteConfig.namespace;
107
- }
108
- }
109
- }
110
- if (!key) {
111
- console.warn(
112
- "[PineconeProvider] Warning: No Pinecone API key available. Set PINECONE_API_KEY in your environment, or ensure the Retrivora Control Plane (https://www.retrivora.com) is reachable for proxy-based vector operations."
113
- );
114
- return;
115
- }
116
- this.client = new Pinecone({ apiKey: key });
117
- try {
118
- const indexes = await this.client.listIndexes();
119
- const names = (_b = (_a = indexes.indexes) == null ? void 0 : _a.map((i) => i.name)) != null ? _b : [];
120
- if (!names.includes(this.indexName)) {
121
- console.warn(`[PineconeProvider] Target index "${this.indexName}" not listed. Proceeding with configured index name.`);
122
- }
123
- } catch (err) {
124
- console.warn("[PineconeProvider] List index verification warning:", err instanceof Error ? err.message : String(err));
125
- }
126
- }
127
- async getActiveIndex(namespace) {
128
- if (!this.client) {
129
- await this.initialize();
130
- }
131
- if (!this.client) {
132
- throw new Error("[PineconeProvider] Cannot execute vector operation: Pinecone client failed to initialize.");
133
- }
134
- const idx = this.client.index(this.indexName);
135
- return namespace ? idx.namespace(namespace) : idx.namespace("");
136
- }
137
- async upsert(doc, namespace) {
138
- var _a, _b;
139
- if (!this.client) {
140
- if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
141
- const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
142
- method: "POST",
143
- headers: __spreadValues({
144
- "Content-Type": "application/json",
145
- "x-license-key": this.licenseKey
146
- }, this.projectId ? { "x-project-id": this.projectId } : {}),
147
- body: JSON.stringify({
148
- projectId: this.projectId,
149
- indexName: this.indexName,
150
- namespace: namespace || this.projectId,
151
- records: [{ id: String(doc.id), values: doc.vector, metadata: __spreadValues({ content: doc.content }, (_a = doc.metadata) != null ? _a : {}) }]
152
- })
153
- });
154
- if (!res.ok) throw new Error(`[PineconeProvider] Proxy upsert failed: ${await res.text()}`);
155
- return;
156
- }
157
- const targetIdx = await this.getActiveIndex(namespace);
158
- await targetIdx.upsert({
159
- records: [{
160
- id: String(doc.id),
161
- values: doc.vector,
162
- metadata: __spreadValues({ content: doc.content }, (_b = doc.metadata) != null ? _b : {})
163
- }]
164
- });
165
- }
166
- async batchUpsert(docs, namespace) {
167
- const BATCH = 100;
168
- if (!this.client) {
169
- if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
170
- for (let i = 0; i < docs.length; i += BATCH) {
171
- const records = docs.slice(i, i + BATCH).map((d) => {
172
- var _a;
173
- return {
174
- id: String(d.id),
175
- values: d.vector,
176
- metadata: __spreadValues({ content: d.content }, (_a = d.metadata) != null ? _a : {})
177
- };
178
- });
179
- const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/upsert`, {
180
- method: "POST",
181
- headers: __spreadValues({
182
- "Content-Type": "application/json",
183
- "x-license-key": this.licenseKey
184
- }, this.projectId ? { "x-project-id": this.projectId } : {}),
185
- body: JSON.stringify({
186
- projectId: this.projectId,
187
- indexName: this.indexName,
188
- namespace: namespace || this.projectId,
189
- records
190
- })
191
- });
192
- if (!res.ok) throw new Error(`[PineconeProvider] Proxy batch upsert failed: ${await res.text()}`);
193
- }
194
- return;
195
- }
196
- const targetIdx = await this.getActiveIndex(namespace);
197
- for (let i = 0; i < docs.length; i += BATCH) {
198
- const records = docs.slice(i, i + BATCH).map((d) => {
199
- var _a;
200
- return {
201
- id: String(d.id),
202
- values: d.vector,
203
- metadata: __spreadValues({ content: d.content }, (_a = d.metadata) != null ? _a : {})
204
- };
205
- });
206
- await targetIdx.upsert({ records });
207
- }
208
- }
209
- async query(vector, topK, namespace, filter) {
210
- var _a, _b;
211
- const pineconeFilter = this.sanitizeFilter(filter);
212
- if (!this.client) {
213
- if (!this.licenseKey) throw new Error("[PineconeProvider] Cannot execute vector operation: Missing API key and License key.");
214
- const res = await fetch(`${this.getControlPlaneUrl()}/api/v1/vectors/query`, {
215
- method: "POST",
216
- headers: __spreadValues({
217
- "Content-Type": "application/json",
218
- "x-license-key": this.licenseKey
219
- }, this.projectId ? { "x-project-id": this.projectId } : {}),
220
- body: JSON.stringify({
221
- projectId: this.projectId,
222
- indexName: this.indexName,
223
- namespace: namespace || this.projectId,
224
- vector,
225
- topK,
226
- filter: pineconeFilter
227
- })
228
- });
229
- if (!res.ok) throw new Error(`[PineconeProvider] Proxy query failed: ${await res.text()}`);
230
- const data = await res.json();
231
- return ((_a = data.matches) != null ? _a : []).map((m) => {
232
- var _a2, _b2;
233
- return {
234
- id: m.id,
235
- score: (_a2 = m.score) != null ? _a2 : 0,
236
- content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
237
- metadata: m.metadata
238
- };
239
- });
240
- }
241
- const targetIdx = await this.getActiveIndex(namespace);
242
- const result = await targetIdx.query(__spreadValues({
243
- vector,
244
- topK,
245
- includeMetadata: true
246
- }, Object.keys(pineconeFilter).length > 0 ? { filter: pineconeFilter } : {}));
247
- return ((_b = result.matches) != null ? _b : []).map((m) => {
248
- var _a2, _b2;
249
- return {
250
- id: m.id,
251
- score: (_a2 = m.score) != null ? _a2 : 0,
252
- content: ((_b2 = m.metadata) == null ? void 0 : _b2.content) || "",
253
- metadata: m.metadata
254
- };
255
- });
256
- }
257
- async delete(id, namespace) {
258
- const targetIdx = await this.getActiveIndex(namespace);
259
- await targetIdx.deleteOne({ id: String(id) });
260
- }
261
- async deleteNamespace(namespace) {
262
- const targetIdx = await this.getActiveIndex(namespace);
263
- await targetIdx.deleteAll();
264
- }
265
- async ping() {
266
- try {
267
- if (!this.client) await this.initialize();
268
- if (!this.client) return false;
269
- await this.client.listIndexes();
270
- return true;
271
- } catch (e) {
272
- return false;
273
- }
274
- }
275
- async disconnect() {
276
- }
277
- };
278
-
279
- export {
280
- PineconeProvider
281
- };
@@ -1,334 +0,0 @@
1
- import {
2
- SDK_VERSION
3
- } from "./chunk-366EFBZC.mjs";
4
- import {
5
- __spreadValues
6
- } from "./chunk-N54YTFBN.mjs";
7
-
8
- // src/core/ProjectSettings.ts
9
- var DEFAULT_LIFECYCLE_HOOKS = [
10
- "beforeInitialize",
11
- "afterInitialize",
12
- "beforeSend",
13
- "afterResponse",
14
- "onMessage",
15
- "onCitationClick",
16
- "onFeedback",
17
- "onError",
18
- "onReconnect",
19
- "onFileUpload"
20
- ];
21
- var DEFAULT_CONVERSATION_FEATURES = [
22
- "History",
23
- "Resume",
24
- "Search",
25
- "Export",
26
- "Rename",
27
- "Delete",
28
- "Tags",
29
- "Pinned",
30
- "Unread",
31
- "Ratings"
32
- ];
33
- function createDefaultProjectSettings(projectId) {
34
- return {
35
- projectId,
36
- branding: {
37
- companyName: "Retrivora AI",
38
- botName: "Retrivora Assistant",
39
- welcomeMessage: "Hi, I can help you search your knowledge base.",
40
- primaryColor: "#6366f1",
41
- secondaryColor: "#8b5cf6",
42
- fontFamily: "Inter",
43
- borderRadius: 14,
44
- logoUrl: "",
45
- avatarUrl: "",
46
- customCss: ""
47
- },
48
- ai: {
49
- defaultModel: "llama-3.1-8b-instant",
50
- embeddingModel: "text-embedding-3-small",
51
- systemPrompt: "Answer using the connected knowledge base. Cite sources when available.",
52
- memoryEnabled: true,
53
- multiModelEnabled: true,
54
- citationsEnabled: true,
55
- fileUploadEnabled: true
56
- },
57
- auth: {
58
- mode: "public",
59
- allowedOrigins: [],
60
- requireVerifiedEmail: false,
61
- sessionTtlMinutes: 1440
62
- },
63
- widget: {
64
- position: "bottom-right",
65
- theme: "light",
66
- lazyLoad: true,
67
- autoReconnect: true,
68
- persistConversations: true,
69
- showRetrivoraBranding: false
70
- },
71
- telemetry: {
72
- enabled: true,
73
- collectBrowser: true,
74
- collectCountry: false,
75
- redactPii: true,
76
- retentionDays: 30
77
- },
78
- lifecycleHooks: DEFAULT_LIFECYCLE_HOOKS,
79
- conversationFeatures: DEFAULT_CONVERSATION_FEATURES
80
- };
81
- }
82
- function cleanString(value, fallback, maxLength = 2e3) {
83
- if (typeof value !== "string") return fallback;
84
- return value.trim().slice(0, maxLength);
85
- }
86
- function cleanBoolean(value, fallback) {
87
- return typeof value === "boolean" ? value : fallback;
88
- }
89
- function cleanNumber(value, fallback, min, max) {
90
- const num = typeof value === "number" ? value : Number(value);
91
- if (!Number.isFinite(num)) return fallback;
92
- return Math.min(Math.max(Math.round(num), min), max);
93
- }
94
- function cleanEnum(value, fallback, allowed) {
95
- return typeof value === "string" && allowed.includes(value) ? value : fallback;
96
- }
97
- function cleanStringList(value, fallback, maxItems = 20) {
98
- if (!Array.isArray(value)) return fallback;
99
- const cleaned = value.filter((item) => typeof item === "string").map((item) => item.trim()).filter(Boolean).slice(0, maxItems);
100
- return cleaned.length > 0 ? Array.from(new Set(cleaned)) : fallback;
101
- }
102
- function normalizeProjectSettings(projectId, input) {
103
- const defaults = createDefaultProjectSettings(projectId);
104
- const branding = (input == null ? void 0 : input.branding) || {};
105
- const ai = (input == null ? void 0 : input.ai) || {};
106
- const auth = (input == null ? void 0 : input.auth) || {};
107
- const widget = (input == null ? void 0 : input.widget) || {};
108
- const telemetry = (input == null ? void 0 : input.telemetry) || {};
109
- return {
110
- projectId,
111
- branding: {
112
- companyName: cleanString(branding.companyName, defaults.branding.companyName, 120),
113
- botName: cleanString(branding.botName, defaults.branding.botName, 120),
114
- welcomeMessage: cleanString(branding.welcomeMessage, defaults.branding.welcomeMessage, 500),
115
- primaryColor: cleanString(branding.primaryColor, defaults.branding.primaryColor, 32),
116
- secondaryColor: cleanString(branding.secondaryColor, defaults.branding.secondaryColor, 32),
117
- fontFamily: cleanString(branding.fontFamily, defaults.branding.fontFamily, 80),
118
- borderRadius: cleanNumber(branding.borderRadius, defaults.branding.borderRadius, 0, 32),
119
- logoUrl: cleanString(branding.logoUrl, defaults.branding.logoUrl, 500),
120
- avatarUrl: cleanString(branding.avatarUrl, defaults.branding.avatarUrl, 500),
121
- customCss: cleanString(branding.customCss, defaults.branding.customCss, 5e3)
122
- },
123
- ai: {
124
- defaultModel: cleanString(ai.defaultModel, defaults.ai.defaultModel, 120),
125
- embeddingModel: cleanString(ai.embeddingModel, defaults.ai.embeddingModel, 120),
126
- systemPrompt: cleanString(ai.systemPrompt, defaults.ai.systemPrompt, 5e3),
127
- memoryEnabled: cleanBoolean(ai.memoryEnabled, defaults.ai.memoryEnabled),
128
- multiModelEnabled: cleanBoolean(ai.multiModelEnabled, defaults.ai.multiModelEnabled),
129
- citationsEnabled: cleanBoolean(ai.citationsEnabled, defaults.ai.citationsEnabled),
130
- fileUploadEnabled: cleanBoolean(ai.fileUploadEnabled, defaults.ai.fileUploadEnabled)
131
- },
132
- auth: {
133
- mode: cleanEnum(auth.mode, defaults.auth.mode, ["public", "anonymous", "jwt", "oauth", "okta", "auth0", "supabase", "firebase", "sso", "custom_token"]),
134
- allowedOrigins: cleanStringList(auth.allowedOrigins, defaults.auth.allowedOrigins, 25),
135
- requireVerifiedEmail: cleanBoolean(auth.requireVerifiedEmail, defaults.auth.requireVerifiedEmail),
136
- sessionTtlMinutes: cleanNumber(auth.sessionTtlMinutes, defaults.auth.sessionTtlMinutes, 15, 43200)
137
- },
138
- widget: {
139
- position: cleanEnum(widget.position, defaults.widget.position, ["bottom-right", "bottom-left", "top-right", "top-left"]),
140
- theme: cleanEnum(widget.theme, defaults.widget.theme, ["light", "dark", "system"]),
141
- lazyLoad: cleanBoolean(widget.lazyLoad, defaults.widget.lazyLoad),
142
- autoReconnect: cleanBoolean(widget.autoReconnect, defaults.widget.autoReconnect),
143
- persistConversations: cleanBoolean(widget.persistConversations, defaults.widget.persistConversations),
144
- showRetrivoraBranding: cleanBoolean(widget.showRetrivoraBranding, defaults.widget.showRetrivoraBranding)
145
- },
146
- telemetry: {
147
- enabled: cleanBoolean(telemetry.enabled, defaults.telemetry.enabled),
148
- collectBrowser: cleanBoolean(telemetry.collectBrowser, defaults.telemetry.collectBrowser),
149
- collectCountry: cleanBoolean(telemetry.collectCountry, defaults.telemetry.collectCountry),
150
- redactPii: cleanBoolean(telemetry.redactPii, defaults.telemetry.redactPii),
151
- retentionDays: cleanNumber(telemetry.retentionDays, defaults.telemetry.retentionDays, 1, 365)
152
- },
153
- lifecycleHooks: cleanStringList(input == null ? void 0 : input.lifecycleHooks, defaults.lifecycleHooks, 30),
154
- conversationFeatures: cleanStringList(input == null ? void 0 : input.conversationFeatures, defaults.conversationFeatures, 30),
155
- updatedAt: input == null ? void 0 : input.updatedAt
156
- };
157
- }
158
- function projectSettingsToUiConfig(settings) {
159
- return {
160
- title: settings.branding.botName,
161
- subtitle: settings.branding.companyName,
162
- primaryColor: settings.branding.primaryColor,
163
- accentColor: settings.branding.secondaryColor,
164
- logoUrl: settings.branding.logoUrl || settings.branding.avatarUrl,
165
- welcomeMessage: settings.branding.welcomeMessage,
166
- poweredBy: settings.widget.showRetrivoraBranding ? "Retrivora AI" : "",
167
- allowUpload: settings.ai.fileUploadEnabled,
168
- showSources: settings.ai.citationsEnabled,
169
- borderRadius: settings.branding.borderRadius <= 4 ? "sm" : settings.branding.borderRadius <= 8 ? "md" : settings.branding.borderRadius <= 16 ? "xl" : "full"
170
- };
171
- }
172
-
173
- // src/core/ConfigFetcher.ts
174
- var CONTROL_PLANE_URL = "https://www.retrivora.com";
175
- var LLM_PROXY_BASE_URL = "https://www.retrivora.com/api/v1";
176
- var ConfigFetcher = class {
177
- // 5-minute in-memory session cache
178
- /**
179
- * Fetch full project configuration (vectorDb + embedding + llm + workspace) from Retrivora Control Plane.
180
- *
181
- * The SDK calls https://www.retrivora.com/api/v1/config with the project ID and license key.
182
- * The server validates the license against the database and returns:
183
- * - validity (tier, isActive, expiresAt)
184
- * - LLM model info
185
- * - embedding model info
186
- * - Pinecone index name and workspace/namespace
187
- *
188
- * The Pinecone API key is NOT returned (server-only). The SDK uses local
189
- * PINECONE_API_KEY if available, or vector operations are handled server-side.
190
- */
191
- static async fetchRemoteConfig(projectId, licenseKey) {
192
- const cacheKey = `${projectId}:${licenseKey || ""}`;
193
- const now = Date.now();
194
- const cached = this.cache.get(cacheKey);
195
- if (cached && now - cached.cachedAt < this.TTL_MS) {
196
- return cached.config;
197
- }
198
- const existingInflight = this.inflight.get(cacheKey);
199
- if (existingInflight) {
200
- return existingInflight;
201
- }
202
- const promise = this._doFetch(projectId, licenseKey, cacheKey, now);
203
- this.inflight.set(cacheKey, promise);
204
- try {
205
- return await promise;
206
- } finally {
207
- this.inflight.delete(cacheKey);
208
- }
209
- }
210
- /** Internal: performs the actual HTTP fetch. Shared by all callers via inflight dedup. */
211
- static async _doFetch(projectId, licenseKey, cacheKey, now) {
212
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
213
- const controlPlaneUrls = [
214
- process.env.RETRIVORA_CONTROL_PLANE_URL,
215
- process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL,
216
- CONTROL_PLANE_URL
217
- ].filter((url) => {
218
- if (!url) return false;
219
- const isEnvVar = url === process.env.RETRIVORA_CONTROL_PLANE_URL || url === process.env.NEXT_PUBLIC_RETRIVORA_CONTROL_PLANE_URL;
220
- if (!isEnvVar && (url.includes("localhost") || url.includes("127.0.0.1"))) return false;
221
- return true;
222
- }).map((url) => url.replace(/\/$/, ""));
223
- for (const baseUrl of controlPlaneUrls) {
224
- try {
225
- const url = `${baseUrl}/api/v1/config?projectId=${encodeURIComponent(projectId)}`;
226
- const res = await fetch(url, {
227
- method: "GET",
228
- headers: __spreadValues(__spreadValues({
229
- "Content-Type": "application/json",
230
- "x-sdk-version": SDK_VERSION
231
- }, licenseKey ? { "x-license-key": licenseKey } : {}), projectId ? { "x-project-id": projectId } : {})
232
- });
233
- if (!res.ok) {
234
- console.warn(`[ConfigFetcher] Error text: ${await res.text()}`);
235
- }
236
- if (res.ok) {
237
- const data = await res.json();
238
- if ((data == null ? void 0 : data.success) && (data == null ? void 0 : data.vectorDb)) {
239
- const fetchedProjectId = data.projectId || projectId;
240
- const config = {
241
- projectId: fetchedProjectId,
242
- tier: data.tier,
243
- isActive: data.isActive,
244
- expiresAt: data.expiresAt,
245
- vectorDb: {
246
- // Fetch apiKey from credentials API if available, else fallback to empty
247
- apiKey: data.vectorDb.apiKey || "",
248
- indexName: data.vectorDb.indexName || "retrivora-free",
249
- provider: data.vectorDb.provider || "pinecone",
250
- projectId: fetchedProjectId,
251
- namespace: ((_a = data.workspace) == null ? void 0 : _a.namespace) || data.vectorDb.namespace || fetchedProjectId
252
- },
253
- embedding: {
254
- provider: ((_b = data.embedding) == null ? void 0 : _b.provider) || "universal_rest",
255
- model: ((_c = data.embedding) == null ? void 0 : _c.model) || "text-embedding-004",
256
- // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
257
- baseUrl: ((_d = data.embedding) == null ? void 0 : _d.baseUrl) || LLM_PROXY_BASE_URL,
258
- apiKey: ((_e = data.embedding) == null ? void 0 : _e.apiKey) || licenseKey || "",
259
- profile: ((_f = data.embedding) == null ? void 0 : _f.profile) || "litellm"
260
- },
261
- llm: {
262
- provider: ((_g = data.llm) == null ? void 0 : _g.provider) || "universal_rest",
263
- model: ((_h = data.llm) == null ? void 0 : _h.model) || "llama-3.1-8b-instant",
264
- // Route through www.retrivora.com proxy, not llm.retrivora.com directly.
265
- baseUrl: ((_i = data.llm) == null ? void 0 : _i.baseUrl) || LLM_PROXY_BASE_URL,
266
- apiKey: ((_j = data.llm) == null ? void 0 : _j.apiKey) || licenseKey || "",
267
- profile: ((_k = data.llm) == null ? void 0 : _k.profile) || "litellm"
268
- },
269
- workspace: data.workspace || {
270
- namespace: fetchedProjectId,
271
- indexName: data.vectorDb.indexName || "retrivora-free"
272
- },
273
- projectSettings: normalizeProjectSettings(
274
- fetchedProjectId,
275
- data.projectSettings || data.settings
276
- )
277
- };
278
- if (licenseKey) {
279
- try {
280
- const credUrl = `${baseUrl}/api/v1/credentials`;
281
- const credRes = await fetch(credUrl, {
282
- method: "POST",
283
- headers: __spreadValues(__spreadValues({
284
- "Content-Type": "application/json"
285
- }, licenseKey ? { "x-license-key": licenseKey } : {}), fetchedProjectId ? { "x-project-id": fetchedProjectId } : {}),
286
- body: JSON.stringify({ licenseKey, projectId: fetchedProjectId })
287
- });
288
- if (credRes.ok) {
289
- const credData = await credRes.json();
290
- if ((credData == null ? void 0 : credData.success) && (credData == null ? void 0 : credData.credentials)) {
291
- if (credData.credentials.pineconeApiKey && !config.vectorDb.apiKey) {
292
- config.vectorDb.apiKey = credData.credentials.pineconeApiKey;
293
- }
294
- if (credData.credentials.litellmApiKey) {
295
- config.llm.apiKey = credData.credentials.litellmApiKey;
296
- config.embedding.apiKey = credData.credentials.litellmApiKey;
297
- }
298
- }
299
- }
300
- } catch (e) {
301
- console.warn("[ConfigFetcher] Failed to fetch credentials:", e);
302
- }
303
- }
304
- this.cache.set(cacheKey, { config, cachedAt: now });
305
- return config;
306
- }
307
- }
308
- } catch (err) {
309
- console.warn(
310
- `[ConfigFetcher] Failed to fetch config from ${baseUrl}:`,
311
- err instanceof Error ? err.message : String(err)
312
- );
313
- }
314
- }
315
- return null;
316
- }
317
- /** Convenience: fetch only vector DB config (backwards compat). */
318
- static async fetchRemoteVectorConfig(projectId, licenseKey) {
319
- var _a;
320
- const config = await this.fetchRemoteConfig(projectId, licenseKey);
321
- return (_a = config == null ? void 0 : config.vectorDb) != null ? _a : null;
322
- }
323
- };
324
- ConfigFetcher.cache = /* @__PURE__ */ new Map();
325
- /** In-flight deduplication: concurrent callers for the same key share one network request */
326
- ConfigFetcher.inflight = /* @__PURE__ */ new Map();
327
- ConfigFetcher.TTL_MS = 5 * 60 * 1e3;
328
-
329
- export {
330
- createDefaultProjectSettings,
331
- normalizeProjectSettings,
332
- projectSettingsToUiConfig,
333
- ConfigFetcher
334
- };
@@ -1,81 +0,0 @@
1
- import {
2
- BaseVectorProvider
3
- } from "./chunk-IMP6FUCY.mjs";
4
- import {
5
- __spreadValues
6
- } from "./chunk-N54YTFBN.mjs";
7
-
8
- // src/providers/vectordb/RedisProvider.ts
9
- import axios from "axios";
10
- var RedisProvider = class extends BaseVectorProvider {
11
- constructor(config) {
12
- super(config);
13
- const opts = config.options;
14
- const baseUrl = opts.baseUrl || opts.url || (opts.host ? `http://${opts.host}:${opts.port || 6379}` : void 0);
15
- if (!baseUrl) throw new Error("[RedisProvider] options.baseUrl is required");
16
- this.http = axios.create({
17
- baseURL: baseUrl,
18
- headers: __spreadValues({
19
- "Content-Type": "application/json"
20
- }, opts.apiKey ? { Authorization: `Bearer ${opts.apiKey}` } : {})
21
- });
22
- }
23
- async initialize() {
24
- await this.ping();
25
- }
26
- async upsert(doc, namespace) {
27
- await this.batchUpsert([doc], namespace);
28
- }
29
- async batchUpsert(docs, namespace) {
30
- const payload = docs.map((doc) => __spreadValues({
31
- id: String(doc.id),
32
- vector: doc.vector,
33
- data: doc.content,
34
- metadata: doc.metadata || {}
35
- }, namespace ? { namespace } : {}));
36
- await this.http.post("/upsert", payload);
37
- }
38
- async query(vector, topK, namespace, _filter) {
39
- const payload = {
40
- index: this.indexName,
41
- vector,
42
- topK,
43
- namespace
44
- };
45
- const { data } = await this.http.post("/search", payload);
46
- return (data.results || []).map((res) => ({
47
- id: res["id"],
48
- score: res["score"],
49
- content: res["content"],
50
- metadata: res["metadata"] || {}
51
- }));
52
- }
53
- async delete(id, namespace) {
54
- await this.http.post("/delete", __spreadValues({
55
- ids: [id]
56
- }, namespace ? { namespace } : {}));
57
- }
58
- async deleteNamespace(namespace) {
59
- if (!namespace) {
60
- throw new Error("[RedisProvider] namespace is required for deleteNamespace");
61
- }
62
- await this.http.post("/reset", { namespace });
63
- }
64
- /**
65
- * Check reachability of the Upstash Vector API.
66
- */
67
- async ping() {
68
- try {
69
- await this.http.get("/");
70
- return true;
71
- } catch (e) {
72
- return false;
73
- }
74
- }
75
- async disconnect() {
76
- }
77
- };
78
-
79
- export {
80
- RedisProvider
81
- };