@sparkleideas/providers 3.0.0-alpha.6-patch.17 → 3.0.0-alpha.6-patch.19
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/package.json +1 -1
- package/dist/anthropic-provider.d.ts +0 -26
- package/dist/anthropic-provider.d.ts.map +0 -1
- package/dist/anthropic-provider.js +0 -513
- package/dist/base-provider.d.ts +0 -174
- package/dist/base-provider.d.ts.map +0 -1
- package/dist/base-provider.js +0 -636
- package/dist/cohere-provider.d.ts +0 -26
- package/dist/cohere-provider.d.ts.map +0 -1
- package/dist/cohere-provider.js +0 -501
- package/dist/google-provider.d.ts +0 -25
- package/dist/google-provider.d.ts.map +0 -1
- package/dist/google-provider.js +0 -498
- package/dist/index.d.ts +0 -33
- package/dist/index.d.ts.map +0 -1
- package/dist/index.js +0 -62
- package/dist/ollama-provider.d.ts +0 -26
- package/dist/ollama-provider.d.ts.map +0 -1
- package/dist/ollama-provider.js +0 -489
- package/dist/openai-provider.d.ts +0 -26
- package/dist/openai-provider.d.ts.map +0 -1
- package/dist/openai-provider.js +0 -543
- package/dist/provider-manager.d.ts +0 -117
- package/dist/provider-manager.d.ts.map +0 -1
- package/dist/provider-manager.js +0 -712
- package/dist/ruvector-provider.d.ts +0 -65
- package/dist/ruvector-provider.d.ts.map +0 -1
- package/dist/ruvector-provider.js +0 -813
- package/dist/types.d.ts +0 -280
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -108
|
@@ -1,813 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/**
|
|
3
|
-
* V3 RuVector Provider (via @ruvector/ruvllm)
|
|
4
|
-
*
|
|
5
|
-
* Self-learning LLM orchestration with:
|
|
6
|
-
* - SONA adaptive learning
|
|
7
|
-
* - HNSW vector memory
|
|
8
|
-
* - FastGRNN intelligent routing
|
|
9
|
-
* - SIMD inference optimization
|
|
10
|
-
* - Local model execution (free)
|
|
11
|
-
*
|
|
12
|
-
* @module @sparkleideas/providers/ruvector-provider
|
|
13
|
-
*/
|
|
14
|
-
var __extends = (this && this.__extends) || (function () {
|
|
15
|
-
var extendStatics = function (d, b) {
|
|
16
|
-
extendStatics = Object.setPrototypeOf ||
|
|
17
|
-
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
18
|
-
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
19
|
-
return extendStatics(d, b);
|
|
20
|
-
};
|
|
21
|
-
return function (d, b) {
|
|
22
|
-
if (typeof b !== "function" && b !== null)
|
|
23
|
-
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
24
|
-
extendStatics(d, b);
|
|
25
|
-
function __() { this.constructor = d; }
|
|
26
|
-
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
27
|
-
};
|
|
28
|
-
})();
|
|
29
|
-
var __assign = (this && this.__assign) || function () {
|
|
30
|
-
__assign = Object.assign || function(t) {
|
|
31
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
32
|
-
s = arguments[i];
|
|
33
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
34
|
-
t[p] = s[p];
|
|
35
|
-
}
|
|
36
|
-
return t;
|
|
37
|
-
};
|
|
38
|
-
return __assign.apply(this, arguments);
|
|
39
|
-
};
|
|
40
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
41
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
42
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
43
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
44
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
45
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
46
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
50
|
-
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
51
|
-
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
52
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
53
|
-
function step(op) {
|
|
54
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
55
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
56
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
57
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
58
|
-
switch (op[0]) {
|
|
59
|
-
case 0: case 1: t = op; break;
|
|
60
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
61
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
62
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
63
|
-
default:
|
|
64
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
65
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
66
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
67
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
68
|
-
if (t[2]) _.ops.pop();
|
|
69
|
-
_.trys.pop(); continue;
|
|
70
|
-
}
|
|
71
|
-
op = body.call(thisArg, _);
|
|
72
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
73
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
var __await = (this && this.__await) || function (v) { return this instanceof __await ? (this.v = v, this) : new __await(v); }
|
|
77
|
-
var __asyncGenerator = (this && this.__asyncGenerator) || function (thisArg, _arguments, generator) {
|
|
78
|
-
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
|
|
79
|
-
var g = generator.apply(thisArg, _arguments || []), i, q = [];
|
|
80
|
-
return i = Object.create((typeof AsyncIterator === "function" ? AsyncIterator : Object).prototype), verb("next"), verb("throw"), verb("return", awaitReturn), i[Symbol.asyncIterator] = function () { return this; }, i;
|
|
81
|
-
function awaitReturn(f) { return function (v) { return Promise.resolve(v).then(f, reject); }; }
|
|
82
|
-
function verb(n, f) { if (g[n]) { i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; if (f) i[n] = f(i[n]); } }
|
|
83
|
-
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
|
|
84
|
-
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
|
|
85
|
-
function fulfill(value) { resume("next", value); }
|
|
86
|
-
function reject(value) { resume("throw", value); }
|
|
87
|
-
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
|
|
88
|
-
};
|
|
89
|
-
var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
90
|
-
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
|
|
91
|
-
if (ar || !(i in from)) {
|
|
92
|
-
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
93
|
-
ar[i] = from[i];
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
return to.concat(ar || Array.prototype.slice.call(from));
|
|
97
|
-
};
|
|
98
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
99
|
-
exports.RuVectorProvider = void 0;
|
|
100
|
-
var base_provider_js_1 = require("./base-provider.js");
|
|
101
|
-
var types_js_1 = require("./types.js");
|
|
102
|
-
var RuVectorProvider = /** @class */ (function (_super) {
|
|
103
|
-
__extends(RuVectorProvider, _super);
|
|
104
|
-
function RuVectorProvider(options) {
|
|
105
|
-
var _this = _super.call(this, options) || this;
|
|
106
|
-
_this.name = 'ruvector';
|
|
107
|
-
_this.capabilities = {
|
|
108
|
-
supportedModels: [
|
|
109
|
-
// RuVector-managed models
|
|
110
|
-
'ruvector-auto', // Auto-selects best model
|
|
111
|
-
'ruvector-fast', // Optimized for speed
|
|
112
|
-
'ruvector-quality', // Optimized for quality
|
|
113
|
-
'ruvector-balanced', // Balanced speed/quality
|
|
114
|
-
// Local models via ruvLLM or Ollama fallback
|
|
115
|
-
'llama3.2',
|
|
116
|
-
'mistral',
|
|
117
|
-
'phi-4',
|
|
118
|
-
'deepseek-coder',
|
|
119
|
-
'codellama',
|
|
120
|
-
'qwen2.5',
|
|
121
|
-
'qwen2.5:0.5b', // CPU-friendly Qwen
|
|
122
|
-
'qwen2.5:1.5b',
|
|
123
|
-
'smollm:135m', // SmolLM models
|
|
124
|
-
'smollm:360m',
|
|
125
|
-
'tinyllama',
|
|
126
|
-
],
|
|
127
|
-
maxContextLength: {
|
|
128
|
-
'ruvector-auto': 128000,
|
|
129
|
-
'ruvector-fast': 32000,
|
|
130
|
-
'ruvector-quality': 128000,
|
|
131
|
-
'ruvector-balanced': 64000,
|
|
132
|
-
'llama3.2': 128000,
|
|
133
|
-
'mistral': 32000,
|
|
134
|
-
'phi-4': 16000,
|
|
135
|
-
'deepseek-coder': 16000,
|
|
136
|
-
'codellama': 16000,
|
|
137
|
-
'qwen2.5': 32000,
|
|
138
|
-
},
|
|
139
|
-
maxOutputTokens: {
|
|
140
|
-
'ruvector-auto': 8192,
|
|
141
|
-
'ruvector-fast': 4096,
|
|
142
|
-
'ruvector-quality': 8192,
|
|
143
|
-
'ruvector-balanced': 8192,
|
|
144
|
-
'llama3.2': 8192,
|
|
145
|
-
'mistral': 8192,
|
|
146
|
-
'phi-4': 4096,
|
|
147
|
-
'deepseek-coder': 8192,
|
|
148
|
-
'codellama': 8192,
|
|
149
|
-
'qwen2.5': 8192,
|
|
150
|
-
},
|
|
151
|
-
supportsStreaming: true,
|
|
152
|
-
supportsToolCalling: true,
|
|
153
|
-
supportsSystemMessages: true,
|
|
154
|
-
supportsVision: false,
|
|
155
|
-
supportsAudio: false,
|
|
156
|
-
supportsFineTuning: true, // SONA self-learning
|
|
157
|
-
supportsEmbeddings: true, // HNSW
|
|
158
|
-
supportsBatching: true,
|
|
159
|
-
rateLimit: {
|
|
160
|
-
requestsPerMinute: 10000, // Local - no rate limit
|
|
161
|
-
tokensPerMinute: 10000000,
|
|
162
|
-
concurrentRequests: 100,
|
|
163
|
-
},
|
|
164
|
-
// Free - local execution with SONA optimization
|
|
165
|
-
pricing: {
|
|
166
|
-
'ruvector-auto': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
167
|
-
'ruvector-fast': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
168
|
-
'ruvector-quality': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
169
|
-
'ruvector-balanced': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
170
|
-
'llama3.2': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
171
|
-
'mistral': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
172
|
-
'phi-4': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
173
|
-
'deepseek-coder': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
174
|
-
'codellama': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
175
|
-
'qwen2.5': { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
176
|
-
},
|
|
177
|
-
};
|
|
178
|
-
_this.baseUrl = 'http://localhost:3000'; // ruvLLM default port
|
|
179
|
-
_this.ollamaUrl = 'http://localhost:11434';
|
|
180
|
-
_this.ruvectorConfig = {};
|
|
181
|
-
_this.useOllamaFallback = false;
|
|
182
|
-
_this.ruvllmAvailable = false;
|
|
183
|
-
_this.ruvectorConfig = options.config.providerOptions || {};
|
|
184
|
-
return _this;
|
|
185
|
-
}
|
|
186
|
-
RuVectorProvider.prototype.doInitialize = function () {
|
|
187
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
188
|
-
var _a, _b, health, ollamaHealth, _c;
|
|
189
|
-
var _d;
|
|
190
|
-
return __generator(this, function (_e) {
|
|
191
|
-
switch (_e.label) {
|
|
192
|
-
case 0:
|
|
193
|
-
// Configure URLs from options
|
|
194
|
-
this.baseUrl = this.config.apiUrl || 'http://localhost:3000';
|
|
195
|
-
this.ollamaUrl = ((_d = this.config.providerOptions) === null || _d === void 0 ? void 0 : _d.ollamaUrl) || 'http://localhost:11434';
|
|
196
|
-
_e.label = 1;
|
|
197
|
-
case 1:
|
|
198
|
-
_e.trys.push([1, 3, , 4]);
|
|
199
|
-
_a = this;
|
|
200
|
-
return [4 /*yield*/, Promise.resolve().then(function () { return require('@ruvector/ruvllm'); }).catch(function () { return null; })];
|
|
201
|
-
case 2:
|
|
202
|
-
_a.ruvllm = _e.sent();
|
|
203
|
-
if (this.ruvllm) {
|
|
204
|
-
this.logger.info('RuVector ruvLLM native module loaded');
|
|
205
|
-
this.ruvllmAvailable = true;
|
|
206
|
-
}
|
|
207
|
-
return [3 /*break*/, 4];
|
|
208
|
-
case 3:
|
|
209
|
-
_b = _e.sent();
|
|
210
|
-
this.logger.debug('RuVector ruvLLM native module not available');
|
|
211
|
-
return [3 /*break*/, 4];
|
|
212
|
-
case 4: return [4 /*yield*/, this.doHealthCheck()];
|
|
213
|
-
case 5:
|
|
214
|
-
health = _e.sent();
|
|
215
|
-
if (health.healthy) {
|
|
216
|
-
this.logger.info('RuVector server connected');
|
|
217
|
-
return [2 /*return*/];
|
|
218
|
-
}
|
|
219
|
-
_e.label = 6;
|
|
220
|
-
case 6:
|
|
221
|
-
_e.trys.push([6, 8, , 9]);
|
|
222
|
-
return [4 /*yield*/, fetch("".concat(this.ollamaUrl, "/api/tags"), {
|
|
223
|
-
signal: AbortSignal.timeout(3000),
|
|
224
|
-
})];
|
|
225
|
-
case 7:
|
|
226
|
-
ollamaHealth = _e.sent();
|
|
227
|
-
if (ollamaHealth.ok) {
|
|
228
|
-
this.useOllamaFallback = true;
|
|
229
|
-
this.logger.info('Using Ollama as fallback for local model execution');
|
|
230
|
-
}
|
|
231
|
-
return [3 /*break*/, 9];
|
|
232
|
-
case 8:
|
|
233
|
-
_c = _e.sent();
|
|
234
|
-
this.logger.warn('Neither RuVector nor Ollama available. Provider may not work.');
|
|
235
|
-
return [3 /*break*/, 9];
|
|
236
|
-
case 9: return [2 /*return*/];
|
|
237
|
-
}
|
|
238
|
-
});
|
|
239
|
-
});
|
|
240
|
-
};
|
|
241
|
-
RuVectorProvider.prototype.doComplete = function (request) {
|
|
242
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
243
|
-
var ruvectorRequest, controller, timeout, response, data, error_1;
|
|
244
|
-
return __generator(this, function (_a) {
|
|
245
|
-
switch (_a.label) {
|
|
246
|
-
case 0:
|
|
247
|
-
// Use Ollama fallback if RuVector server isn't available
|
|
248
|
-
if (this.useOllamaFallback) {
|
|
249
|
-
return [2 /*return*/, this.completeWithOllama(request)];
|
|
250
|
-
}
|
|
251
|
-
ruvectorRequest = this.buildRuvectorQuery(request);
|
|
252
|
-
controller = new AbortController();
|
|
253
|
-
timeout = setTimeout(function () { return controller.abort(); }, this.config.timeout || 120000);
|
|
254
|
-
_a.label = 1;
|
|
255
|
-
case 1:
|
|
256
|
-
_a.trys.push([1, 6, , 7]);
|
|
257
|
-
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/query"), {
|
|
258
|
-
method: 'POST',
|
|
259
|
-
headers: __assign({ 'Content-Type': 'application/json' }, (this.config.apiKey && { Authorization: "Bearer ".concat(this.config.apiKey) })),
|
|
260
|
-
body: JSON.stringify(ruvectorRequest),
|
|
261
|
-
signal: controller.signal,
|
|
262
|
-
})];
|
|
263
|
-
case 2:
|
|
264
|
-
response = _a.sent();
|
|
265
|
-
clearTimeout(timeout);
|
|
266
|
-
if (!!response.ok) return [3 /*break*/, 4];
|
|
267
|
-
return [4 /*yield*/, this.handleErrorResponse(response)];
|
|
268
|
-
case 3:
|
|
269
|
-
_a.sent();
|
|
270
|
-
_a.label = 4;
|
|
271
|
-
case 4: return [4 /*yield*/, response.json()];
|
|
272
|
-
case 5:
|
|
273
|
-
data = _a.sent();
|
|
274
|
-
return [2 /*return*/, this.transformResponse(data, request)];
|
|
275
|
-
case 6:
|
|
276
|
-
error_1 = _a.sent();
|
|
277
|
-
clearTimeout(timeout);
|
|
278
|
-
// Auto-fallback to Ollama on connection error
|
|
279
|
-
if (error_1 instanceof Error && (error_1.message.includes('ECONNREFUSED') || error_1.message.includes('fetch failed'))) {
|
|
280
|
-
this.useOllamaFallback = true;
|
|
281
|
-
this.logger.info('RuVector connection failed, falling back to Ollama');
|
|
282
|
-
return [2 /*return*/, this.completeWithOllama(request)];
|
|
283
|
-
}
|
|
284
|
-
throw this.transformError(error_1);
|
|
285
|
-
case 7: return [2 /*return*/];
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
};
|
|
290
|
-
/**
|
|
291
|
-
* Fallback completion using Ollama API
|
|
292
|
-
*/
|
|
293
|
-
RuVectorProvider.prototype.completeWithOllama = function (request) {
|
|
294
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
295
|
-
var model, ollamaRequest, controller, timeout, response, errorText, data, promptTokens, completionTokens, error_2;
|
|
296
|
-
var _a, _b, _c, _d;
|
|
297
|
-
return __generator(this, function (_e) {
|
|
298
|
-
switch (_e.label) {
|
|
299
|
-
case 0:
|
|
300
|
-
model = request.model || this.config.model;
|
|
301
|
-
ollamaRequest = {
|
|
302
|
-
model: model,
|
|
303
|
-
messages: request.messages.map(function (msg) { return ({
|
|
304
|
-
role: msg.role === 'tool' ? 'assistant' : msg.role,
|
|
305
|
-
content: typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content),
|
|
306
|
-
}); }),
|
|
307
|
-
stream: false,
|
|
308
|
-
options: {
|
|
309
|
-
temperature: (_b = (_a = request.temperature) !== null && _a !== void 0 ? _a : this.config.temperature) !== null && _b !== void 0 ? _b : 0.7,
|
|
310
|
-
num_predict: request.maxTokens || this.config.maxTokens || 2048,
|
|
311
|
-
},
|
|
312
|
-
};
|
|
313
|
-
controller = new AbortController();
|
|
314
|
-
timeout = setTimeout(function () { return controller.abort(); }, this.config.timeout || 120000);
|
|
315
|
-
_e.label = 1;
|
|
316
|
-
case 1:
|
|
317
|
-
_e.trys.push([1, 6, , 7]);
|
|
318
|
-
return [4 /*yield*/, fetch("".concat(this.ollamaUrl, "/api/chat"), {
|
|
319
|
-
method: 'POST',
|
|
320
|
-
headers: { 'Content-Type': 'application/json' },
|
|
321
|
-
body: JSON.stringify(ollamaRequest),
|
|
322
|
-
signal: controller.signal,
|
|
323
|
-
})];
|
|
324
|
-
case 2:
|
|
325
|
-
response = _e.sent();
|
|
326
|
-
clearTimeout(timeout);
|
|
327
|
-
if (!!response.ok) return [3 /*break*/, 4];
|
|
328
|
-
return [4 /*yield*/, response.text()];
|
|
329
|
-
case 3:
|
|
330
|
-
errorText = _e.sent();
|
|
331
|
-
throw new types_js_1.LLMProviderError("Ollama error: ".concat(errorText), "OLLAMA_".concat(response.status), 'ruvector', response.status, true);
|
|
332
|
-
case 4: return [4 /*yield*/, response.json()];
|
|
333
|
-
case 5:
|
|
334
|
-
data = _e.sent();
|
|
335
|
-
promptTokens = data.prompt_eval_count || this.estimateTokens(JSON.stringify(request.messages));
|
|
336
|
-
completionTokens = data.eval_count || this.estimateTokens(((_c = data.message) === null || _c === void 0 ? void 0 : _c.content) || '');
|
|
337
|
-
return [2 /*return*/, {
|
|
338
|
-
id: "ruvector-ollama-".concat(Date.now()),
|
|
339
|
-
model: model,
|
|
340
|
-
provider: 'ruvector',
|
|
341
|
-
content: ((_d = data.message) === null || _d === void 0 ? void 0 : _d.content) || '',
|
|
342
|
-
usage: {
|
|
343
|
-
promptTokens: promptTokens,
|
|
344
|
-
completionTokens: completionTokens,
|
|
345
|
-
totalTokens: promptTokens + completionTokens,
|
|
346
|
-
},
|
|
347
|
-
cost: {
|
|
348
|
-
promptCost: 0,
|
|
349
|
-
completionCost: 0,
|
|
350
|
-
totalCost: 0,
|
|
351
|
-
currency: 'USD',
|
|
352
|
-
},
|
|
353
|
-
finishReason: 'stop',
|
|
354
|
-
metadata: {
|
|
355
|
-
backend: 'ollama',
|
|
356
|
-
sona: { enabled: false },
|
|
357
|
-
},
|
|
358
|
-
}];
|
|
359
|
-
case 6:
|
|
360
|
-
error_2 = _e.sent();
|
|
361
|
-
clearTimeout(timeout);
|
|
362
|
-
throw this.transformError(error_2);
|
|
363
|
-
case 7: return [2 /*return*/];
|
|
364
|
-
}
|
|
365
|
-
});
|
|
366
|
-
});
|
|
367
|
-
};
|
|
368
|
-
RuVectorProvider.prototype.doStreamComplete = function (request) {
|
|
369
|
-
return __asyncGenerator(this, arguments, function doStreamComplete_1() {
|
|
370
|
-
var ruvectorRequest, controller, timeout, response, reader, decoder, buffer, promptTokens, completionTokens, _a, done, value, lines, _i, lines_1, line, data, chunk, _b, chunk, _c, error_3;
|
|
371
|
-
return __generator(this, function (_d) {
|
|
372
|
-
switch (_d.label) {
|
|
373
|
-
case 0:
|
|
374
|
-
ruvectorRequest = this.buildRequest(request, true);
|
|
375
|
-
controller = new AbortController();
|
|
376
|
-
timeout = setTimeout(function () { return controller.abort(); }, (this.config.timeout || 120000) * 2);
|
|
377
|
-
_d.label = 1;
|
|
378
|
-
case 1:
|
|
379
|
-
_d.trys.push([1, 29, 30, 31]);
|
|
380
|
-
return [4 /*yield*/, __await(fetch("".concat(this.baseUrl, "/v1/chat/completions"), {
|
|
381
|
-
method: 'POST',
|
|
382
|
-
headers: __assign({ 'Content-Type': 'application/json' }, (this.config.apiKey && { Authorization: "Bearer ".concat(this.config.apiKey) })),
|
|
383
|
-
body: JSON.stringify(ruvectorRequest),
|
|
384
|
-
signal: controller.signal,
|
|
385
|
-
}))];
|
|
386
|
-
case 2:
|
|
387
|
-
response = _d.sent();
|
|
388
|
-
if (!!response.ok) return [3 /*break*/, 4];
|
|
389
|
-
return [4 /*yield*/, __await(this.handleErrorResponse(response))];
|
|
390
|
-
case 3:
|
|
391
|
-
_d.sent();
|
|
392
|
-
_d.label = 4;
|
|
393
|
-
case 4:
|
|
394
|
-
reader = response.body.getReader();
|
|
395
|
-
decoder = new TextDecoder();
|
|
396
|
-
buffer = '';
|
|
397
|
-
promptTokens = 0;
|
|
398
|
-
completionTokens = 0;
|
|
399
|
-
_d.label = 5;
|
|
400
|
-
case 5:
|
|
401
|
-
if (!true) return [3 /*break*/, 25];
|
|
402
|
-
return [4 /*yield*/, __await(reader.read())];
|
|
403
|
-
case 6:
|
|
404
|
-
_a = _d.sent(), done = _a.done, value = _a.value;
|
|
405
|
-
if (done)
|
|
406
|
-
return [3 /*break*/, 25];
|
|
407
|
-
buffer += decoder.decode(value, { stream: true });
|
|
408
|
-
lines = buffer.split('\n');
|
|
409
|
-
buffer = lines.pop() || '';
|
|
410
|
-
_i = 0, lines_1 = lines;
|
|
411
|
-
_d.label = 7;
|
|
412
|
-
case 7:
|
|
413
|
-
if (!(_i < lines_1.length)) return [3 /*break*/, 24];
|
|
414
|
-
line = lines_1[_i];
|
|
415
|
-
if (!line.startsWith('data: ')) return [3 /*break*/, 17];
|
|
416
|
-
data = line.slice(6);
|
|
417
|
-
if (data === '[DONE]')
|
|
418
|
-
return [3 /*break*/, 23];
|
|
419
|
-
_d.label = 8;
|
|
420
|
-
case 8:
|
|
421
|
-
_d.trys.push([8, 15, , 16]);
|
|
422
|
-
chunk = JSON.parse(data);
|
|
423
|
-
if (!chunk.content) return [3 /*break*/, 11];
|
|
424
|
-
return [4 /*yield*/, __await({
|
|
425
|
-
type: 'content',
|
|
426
|
-
delta: { content: chunk.content },
|
|
427
|
-
})];
|
|
428
|
-
case 9: return [4 /*yield*/, _d.sent()];
|
|
429
|
-
case 10:
|
|
430
|
-
_d.sent();
|
|
431
|
-
_d.label = 11;
|
|
432
|
-
case 11:
|
|
433
|
-
if (!(chunk.done && chunk.usage)) return [3 /*break*/, 14];
|
|
434
|
-
promptTokens = chunk.usage.prompt_tokens;
|
|
435
|
-
completionTokens = chunk.usage.completion_tokens;
|
|
436
|
-
return [4 /*yield*/, __await({
|
|
437
|
-
type: 'done',
|
|
438
|
-
usage: {
|
|
439
|
-
promptTokens: promptTokens,
|
|
440
|
-
completionTokens: completionTokens,
|
|
441
|
-
totalTokens: promptTokens + completionTokens,
|
|
442
|
-
},
|
|
443
|
-
cost: {
|
|
444
|
-
promptCost: 0,
|
|
445
|
-
completionCost: 0,
|
|
446
|
-
totalCost: 0,
|
|
447
|
-
currency: 'USD',
|
|
448
|
-
},
|
|
449
|
-
})];
|
|
450
|
-
case 12: return [4 /*yield*/, _d.sent()];
|
|
451
|
-
case 13:
|
|
452
|
-
_d.sent();
|
|
453
|
-
_d.label = 14;
|
|
454
|
-
case 14: return [3 /*break*/, 16];
|
|
455
|
-
case 15:
|
|
456
|
-
_b = _d.sent();
|
|
457
|
-
return [3 /*break*/, 16];
|
|
458
|
-
case 16: return [3 /*break*/, 23];
|
|
459
|
-
case 17:
|
|
460
|
-
if (!(line.trim() && !line.startsWith(':'))) return [3 /*break*/, 23];
|
|
461
|
-
_d.label = 18;
|
|
462
|
-
case 18:
|
|
463
|
-
_d.trys.push([18, 22, , 23]);
|
|
464
|
-
chunk = JSON.parse(line);
|
|
465
|
-
if (!chunk.content) return [3 /*break*/, 21];
|
|
466
|
-
return [4 /*yield*/, __await({
|
|
467
|
-
type: 'content',
|
|
468
|
-
delta: { content: chunk.content },
|
|
469
|
-
})];
|
|
470
|
-
case 19: return [4 /*yield*/, _d.sent()];
|
|
471
|
-
case 20:
|
|
472
|
-
_d.sent();
|
|
473
|
-
_d.label = 21;
|
|
474
|
-
case 21: return [3 /*break*/, 23];
|
|
475
|
-
case 22:
|
|
476
|
-
_c = _d.sent();
|
|
477
|
-
return [3 /*break*/, 23];
|
|
478
|
-
case 23:
|
|
479
|
-
_i++;
|
|
480
|
-
return [3 /*break*/, 7];
|
|
481
|
-
case 24: return [3 /*break*/, 5];
|
|
482
|
-
case 25:
|
|
483
|
-
if (!(completionTokens === 0)) return [3 /*break*/, 28];
|
|
484
|
-
return [4 /*yield*/, __await({
|
|
485
|
-
type: 'done',
|
|
486
|
-
usage: {
|
|
487
|
-
promptTokens: this.estimateTokens(JSON.stringify(request.messages)),
|
|
488
|
-
completionTokens: 100,
|
|
489
|
-
totalTokens: this.estimateTokens(JSON.stringify(request.messages)) + 100,
|
|
490
|
-
},
|
|
491
|
-
cost: { promptCost: 0, completionCost: 0, totalCost: 0, currency: 'USD' },
|
|
492
|
-
})];
|
|
493
|
-
case 26: return [4 /*yield*/, _d.sent()];
|
|
494
|
-
case 27:
|
|
495
|
-
_d.sent();
|
|
496
|
-
_d.label = 28;
|
|
497
|
-
case 28: return [3 /*break*/, 31];
|
|
498
|
-
case 29:
|
|
499
|
-
error_3 = _d.sent();
|
|
500
|
-
clearTimeout(timeout);
|
|
501
|
-
throw this.transformError(error_3);
|
|
502
|
-
case 30:
|
|
503
|
-
clearTimeout(timeout);
|
|
504
|
-
return [7 /*endfinally*/];
|
|
505
|
-
case 31: return [2 /*return*/];
|
|
506
|
-
}
|
|
507
|
-
});
|
|
508
|
-
});
|
|
509
|
-
};
|
|
510
|
-
RuVectorProvider.prototype.listModels = function () {
|
|
511
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
512
|
-
var response, data, _a;
|
|
513
|
-
var _b;
|
|
514
|
-
return __generator(this, function (_c) {
|
|
515
|
-
switch (_c.label) {
|
|
516
|
-
case 0:
|
|
517
|
-
_c.trys.push([0, 3, , 4]);
|
|
518
|
-
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/v1/models"))];
|
|
519
|
-
case 1:
|
|
520
|
-
response = _c.sent();
|
|
521
|
-
if (!response.ok) {
|
|
522
|
-
return [2 /*return*/, this.capabilities.supportedModels];
|
|
523
|
-
}
|
|
524
|
-
return [4 /*yield*/, response.json()];
|
|
525
|
-
case 2:
|
|
526
|
-
data = _c.sent();
|
|
527
|
-
return [2 /*return*/, ((_b = data.data) === null || _b === void 0 ? void 0 : _b.map(function (m) { return m.id; })) || this.capabilities.supportedModels];
|
|
528
|
-
case 3:
|
|
529
|
-
_a = _c.sent();
|
|
530
|
-
return [2 /*return*/, this.capabilities.supportedModels];
|
|
531
|
-
case 4: return [2 /*return*/];
|
|
532
|
-
}
|
|
533
|
-
});
|
|
534
|
-
});
|
|
535
|
-
};
|
|
536
|
-
RuVectorProvider.prototype.getModelInfo = function (model) {
|
|
537
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
538
|
-
var descriptions;
|
|
539
|
-
return __generator(this, function (_a) {
|
|
540
|
-
descriptions = {
|
|
541
|
-
'ruvector-auto': 'Auto-selects optimal model with SONA learning',
|
|
542
|
-
'ruvector-fast': 'Optimized for speed with FastGRNN routing',
|
|
543
|
-
'ruvector-quality': 'Highest quality with full SONA adaptation',
|
|
544
|
-
'ruvector-balanced': 'Balanced speed and quality',
|
|
545
|
-
'llama3.2': 'Meta Llama 3.2 via RuVector',
|
|
546
|
-
'mistral': 'Mistral 7B via RuVector',
|
|
547
|
-
'phi-4': 'Microsoft Phi-4 via RuVector',
|
|
548
|
-
'deepseek-coder': 'DeepSeek Coder via RuVector',
|
|
549
|
-
'codellama': 'Code Llama via RuVector',
|
|
550
|
-
'qwen2.5': 'Qwen 2.5 via RuVector',
|
|
551
|
-
};
|
|
552
|
-
return [2 /*return*/, {
|
|
553
|
-
model: model,
|
|
554
|
-
name: model,
|
|
555
|
-
description: descriptions[model] || 'RuVector-managed local model',
|
|
556
|
-
contextLength: this.capabilities.maxContextLength[model] || 32000,
|
|
557
|
-
maxOutputTokens: this.capabilities.maxOutputTokens[model] || 4096,
|
|
558
|
-
supportedFeatures: [
|
|
559
|
-
'chat',
|
|
560
|
-
'completion',
|
|
561
|
-
'local',
|
|
562
|
-
'self-learning',
|
|
563
|
-
'sona',
|
|
564
|
-
'hnsw-memory',
|
|
565
|
-
],
|
|
566
|
-
pricing: { promptCostPer1k: 0, completionCostPer1k: 0, currency: 'USD' },
|
|
567
|
-
}];
|
|
568
|
-
});
|
|
569
|
-
});
|
|
570
|
-
};
|
|
571
|
-
RuVectorProvider.prototype.doHealthCheck = function () {
|
|
572
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
573
|
-
var response, data, error_4;
|
|
574
|
-
var _a, _b;
|
|
575
|
-
return __generator(this, function (_c) {
|
|
576
|
-
switch (_c.label) {
|
|
577
|
-
case 0:
|
|
578
|
-
_c.trys.push([0, 4, , 5]);
|
|
579
|
-
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/health"))];
|
|
580
|
-
case 1:
|
|
581
|
-
response = _c.sent();
|
|
582
|
-
if (!response.ok) return [3 /*break*/, 3];
|
|
583
|
-
return [4 /*yield*/, response.json()];
|
|
584
|
-
case 2:
|
|
585
|
-
data = _c.sent();
|
|
586
|
-
return [2 /*return*/, {
|
|
587
|
-
healthy: true,
|
|
588
|
-
timestamp: new Date(),
|
|
589
|
-
details: {
|
|
590
|
-
server: 'ruvector',
|
|
591
|
-
sona: (_a = data.sona) !== null && _a !== void 0 ? _a : false,
|
|
592
|
-
hnsw: (_b = data.hnsw) !== null && _b !== void 0 ? _b : false,
|
|
593
|
-
local: true,
|
|
594
|
-
},
|
|
595
|
-
}];
|
|
596
|
-
case 3: return [2 /*return*/, {
|
|
597
|
-
healthy: false,
|
|
598
|
-
error: "HTTP ".concat(response.status),
|
|
599
|
-
timestamp: new Date(),
|
|
600
|
-
}];
|
|
601
|
-
case 4:
|
|
602
|
-
error_4 = _c.sent();
|
|
603
|
-
return [2 /*return*/, {
|
|
604
|
-
healthy: false,
|
|
605
|
-
error: error_4 instanceof Error ? error_4.message : 'RuVector server not reachable',
|
|
606
|
-
timestamp: new Date(),
|
|
607
|
-
details: {
|
|
608
|
-
hint: 'Start RuVector server: npx @ruvector/ruvllm serve',
|
|
609
|
-
},
|
|
610
|
-
}];
|
|
611
|
-
case 5: return [2 /*return*/];
|
|
612
|
-
}
|
|
613
|
-
});
|
|
614
|
-
});
|
|
615
|
-
};
|
|
616
|
-
/**
|
|
617
|
-
* Build ruvLLM native API query format
|
|
618
|
-
* See: https://github.com/ruvnet/ruvector/tree/main/examples/ruvLLM
|
|
619
|
-
*/
|
|
620
|
-
RuVectorProvider.prototype.buildRuvectorQuery = function (request) {
|
|
621
|
-
// ruvLLM uses simple query format, not OpenAI-compatible
|
|
622
|
-
var lastUserMessage = __spreadArray([], request.messages, true).reverse().find(function (m) { return m.role === 'user'; });
|
|
623
|
-
var systemPrompt = request.messages.find(function (m) { return m.role === 'system'; });
|
|
624
|
-
var query = '';
|
|
625
|
-
if (systemPrompt) {
|
|
626
|
-
query += "[System]: ".concat(typeof systemPrompt.content === 'string' ? systemPrompt.content : JSON.stringify(systemPrompt.content), "\n\n");
|
|
627
|
-
}
|
|
628
|
-
query += typeof (lastUserMessage === null || lastUserMessage === void 0 ? void 0 : lastUserMessage.content) === 'string'
|
|
629
|
-
? lastUserMessage.content
|
|
630
|
-
: JSON.stringify((lastUserMessage === null || lastUserMessage === void 0 ? void 0 : lastUserMessage.content) || '');
|
|
631
|
-
return {
|
|
632
|
-
query: query,
|
|
633
|
-
session_id: request.requestId,
|
|
634
|
-
};
|
|
635
|
-
};
|
|
636
|
-
RuVectorProvider.prototype.buildRequest = function (request, stream) {
|
|
637
|
-
var _a, _b;
|
|
638
|
-
if (stream === void 0) { stream = false; }
|
|
639
|
-
var ruvectorRequest = {
|
|
640
|
-
model: request.model || this.config.model,
|
|
641
|
-
messages: request.messages.map(function (msg) { return ({
|
|
642
|
-
role: msg.role === 'tool' ? 'assistant' : msg.role,
|
|
643
|
-
content: typeof msg.content === 'string' ? msg.content : JSON.stringify(msg.content),
|
|
644
|
-
}); }),
|
|
645
|
-
stream: stream,
|
|
646
|
-
};
|
|
647
|
-
if (request.temperature !== undefined || this.config.temperature !== undefined) {
|
|
648
|
-
ruvectorRequest.temperature = (_a = request.temperature) !== null && _a !== void 0 ? _a : this.config.temperature;
|
|
649
|
-
}
|
|
650
|
-
if (request.maxTokens || this.config.maxTokens) {
|
|
651
|
-
ruvectorRequest.max_tokens = request.maxTokens || this.config.maxTokens;
|
|
652
|
-
}
|
|
653
|
-
if (request.topP !== undefined || this.config.topP !== undefined) {
|
|
654
|
-
ruvectorRequest.top_p = (_b = request.topP) !== null && _b !== void 0 ? _b : this.config.topP;
|
|
655
|
-
}
|
|
656
|
-
// SONA options
|
|
657
|
-
if (this.ruvectorConfig.enableSona !== false) {
|
|
658
|
-
ruvectorRequest.sona_options = {
|
|
659
|
-
enabled: true,
|
|
660
|
-
learning_rate: this.ruvectorConfig.sonaLearningRate || 0.01,
|
|
661
|
-
adapt_on_response: true,
|
|
662
|
-
};
|
|
663
|
-
}
|
|
664
|
-
// Router options
|
|
665
|
-
if (this.ruvectorConfig.enableFastGrnn !== false) {
|
|
666
|
-
ruvectorRequest.router_options = {
|
|
667
|
-
strategy: this.ruvectorConfig.routerStrategy || 'balanced',
|
|
668
|
-
fallback_models: ['llama3.2', 'mistral', 'phi-4'],
|
|
669
|
-
};
|
|
670
|
-
}
|
|
671
|
-
return ruvectorRequest;
|
|
672
|
-
};
|
|
673
|
-
RuVectorProvider.prototype.transformResponse = function (data, request) {
|
|
674
|
-
var _a, _b, _c;
|
|
675
|
-
var model = request.model || this.config.model;
|
|
676
|
-
return {
|
|
677
|
-
id: data.id || "ruvector-".concat(Date.now()),
|
|
678
|
-
model: (data.model || model),
|
|
679
|
-
provider: 'custom',
|
|
680
|
-
content: data.content,
|
|
681
|
-
usage: {
|
|
682
|
-
promptTokens: ((_a = data.usage) === null || _a === void 0 ? void 0 : _a.prompt_tokens) || 0,
|
|
683
|
-
completionTokens: ((_b = data.usage) === null || _b === void 0 ? void 0 : _b.completion_tokens) || 0,
|
|
684
|
-
totalTokens: ((_c = data.usage) === null || _c === void 0 ? void 0 : _c.total_tokens) || 0,
|
|
685
|
-
},
|
|
686
|
-
cost: {
|
|
687
|
-
promptCost: 0,
|
|
688
|
-
completionCost: 0,
|
|
689
|
-
totalCost: 0,
|
|
690
|
-
currency: 'USD',
|
|
691
|
-
},
|
|
692
|
-
finishReason: data.done ? 'stop' : 'length',
|
|
693
|
-
metadata: {
|
|
694
|
-
sona: data.sona_metrics,
|
|
695
|
-
router: data.router_metrics,
|
|
696
|
-
},
|
|
697
|
-
};
|
|
698
|
-
};
|
|
699
|
-
RuVectorProvider.prototype.handleErrorResponse = function (response) {
|
|
700
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
701
|
-
var errorText, errorData, message;
|
|
702
|
-
return __generator(this, function (_a) {
|
|
703
|
-
switch (_a.label) {
|
|
704
|
-
case 0: return [4 /*yield*/, response.text()];
|
|
705
|
-
case 1:
|
|
706
|
-
errorText = _a.sent();
|
|
707
|
-
try {
|
|
708
|
-
errorData = JSON.parse(errorText);
|
|
709
|
-
}
|
|
710
|
-
catch (_b) {
|
|
711
|
-
errorData = { error: errorText };
|
|
712
|
-
}
|
|
713
|
-
message = errorData.error || 'Unknown error';
|
|
714
|
-
if (response.status === 0 || message.includes('connection')) {
|
|
715
|
-
throw new types_js_1.ProviderUnavailableError('custom', {
|
|
716
|
-
message: message,
|
|
717
|
-
hint: 'Start RuVector server: npx @ruvector/ruvllm serve',
|
|
718
|
-
});
|
|
719
|
-
}
|
|
720
|
-
throw new types_js_1.LLMProviderError(message, "RUVECTOR_".concat(response.status), 'custom', response.status, true, errorData);
|
|
721
|
-
}
|
|
722
|
-
});
|
|
723
|
-
});
|
|
724
|
-
};
|
|
725
|
-
/**
|
|
726
|
-
* Get SONA learning metrics
|
|
727
|
-
*/
|
|
728
|
-
RuVectorProvider.prototype.getSonaMetrics = function () {
|
|
729
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
730
|
-
var response, _a;
|
|
731
|
-
return __generator(this, function (_b) {
|
|
732
|
-
switch (_b.label) {
|
|
733
|
-
case 0:
|
|
734
|
-
_b.trys.push([0, 4, , 5]);
|
|
735
|
-
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/v1/sona/metrics"))];
|
|
736
|
-
case 1:
|
|
737
|
-
response = _b.sent();
|
|
738
|
-
if (!response.ok) return [3 /*break*/, 3];
|
|
739
|
-
return [4 /*yield*/, response.json()];
|
|
740
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
741
|
-
case 3: return [3 /*break*/, 5];
|
|
742
|
-
case 4:
|
|
743
|
-
_a = _b.sent();
|
|
744
|
-
return [3 /*break*/, 5];
|
|
745
|
-
case 5: return [2 /*return*/, {
|
|
746
|
-
enabled: false,
|
|
747
|
-
adaptationsApplied: 0,
|
|
748
|
-
qualityScore: 0,
|
|
749
|
-
patternsLearned: 0,
|
|
750
|
-
}];
|
|
751
|
-
}
|
|
752
|
-
});
|
|
753
|
-
});
|
|
754
|
-
};
|
|
755
|
-
/**
|
|
756
|
-
* Trigger SONA learning from a conversation
|
|
757
|
-
*/
|
|
758
|
-
RuVectorProvider.prototype.triggerSonaLearning = function (conversationId) {
|
|
759
|
-
return __awaiter(this, void 0, void 0, function () {
|
|
760
|
-
var response, _a;
|
|
761
|
-
return __generator(this, function (_b) {
|
|
762
|
-
switch (_b.label) {
|
|
763
|
-
case 0:
|
|
764
|
-
_b.trys.push([0, 2, , 3]);
|
|
765
|
-
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/v1/sona/learn"), {
|
|
766
|
-
method: 'POST',
|
|
767
|
-
headers: { 'Content-Type': 'application/json' },
|
|
768
|
-
body: JSON.stringify({ conversation_id: conversationId }),
|
|
769
|
-
})];
|
|
770
|
-
case 1:
|
|
771
|
-
response = _b.sent();
|
|
772
|
-
return [2 /*return*/, response.ok];
|
|
773
|
-
case 2:
|
|
774
|
-
_a = _b.sent();
|
|
775
|
-
return [2 /*return*/, false];
|
|
776
|
-
case 3: return [2 /*return*/];
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
});
|
|
780
|
-
};
|
|
781
|
-
/**
|
|
782
|
-
* Search HNSW memory for similar patterns
|
|
783
|
-
*/
|
|
784
|
-
RuVectorProvider.prototype.searchMemory = function (query_1) {
|
|
785
|
-
return __awaiter(this, arguments, void 0, function (query, limit) {
|
|
786
|
-
var response, _a;
|
|
787
|
-
if (limit === void 0) { limit = 5; }
|
|
788
|
-
return __generator(this, function (_b) {
|
|
789
|
-
switch (_b.label) {
|
|
790
|
-
case 0:
|
|
791
|
-
_b.trys.push([0, 4, , 5]);
|
|
792
|
-
return [4 /*yield*/, fetch("".concat(this.baseUrl, "/v1/hnsw/search"), {
|
|
793
|
-
method: 'POST',
|
|
794
|
-
headers: { 'Content-Type': 'application/json' },
|
|
795
|
-
body: JSON.stringify({ query: query, limit: limit }),
|
|
796
|
-
})];
|
|
797
|
-
case 1:
|
|
798
|
-
response = _b.sent();
|
|
799
|
-
if (!response.ok) return [3 /*break*/, 3];
|
|
800
|
-
return [4 /*yield*/, response.json()];
|
|
801
|
-
case 2: return [2 /*return*/, _b.sent()];
|
|
802
|
-
case 3: return [3 /*break*/, 5];
|
|
803
|
-
case 4:
|
|
804
|
-
_a = _b.sent();
|
|
805
|
-
return [3 /*break*/, 5];
|
|
806
|
-
case 5: return [2 /*return*/, []];
|
|
807
|
-
}
|
|
808
|
-
});
|
|
809
|
-
});
|
|
810
|
-
};
|
|
811
|
-
return RuVectorProvider;
|
|
812
|
-
}(base_provider_js_1.BaseProvider));
|
|
813
|
-
exports.RuVectorProvider = RuVectorProvider;
|