@arabold/docs-mcp-server 1.10.0 → 1.12.0
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/README.md +152 -232
- package/db/migrations/000-initial-schema.sql +57 -0
- package/db/migrations/001-add-indexed-at-column.sql +6 -0
- package/dist/DocumentManagementService-_qCZ1Hi2.js +3409 -0
- package/dist/DocumentManagementService-_qCZ1Hi2.js.map +1 -0
- package/dist/EmbeddingFactory-BJMbJvje.js +174 -0
- package/dist/EmbeddingFactory-BJMbJvje.js.map +1 -0
- package/dist/FindVersionTool-CH1c3Tyu.js +170 -0
- package/dist/FindVersionTool-CH1c3Tyu.js.map +1 -0
- package/dist/RemoveTool-DmB1YJTA.js +65 -0
- package/dist/RemoveTool-DmB1YJTA.js.map +1 -0
- package/dist/assets/main.css +1 -0
- package/dist/assets/main.js +8097 -0
- package/dist/assets/main.js.map +1 -0
- package/dist/cli.js +49 -143
- package/dist/cli.js.map +1 -1
- package/dist/server.js +684 -388
- package/dist/server.js.map +1 -1
- package/dist/web.js +937 -0
- package/dist/web.js.map +1 -0
- package/package.json +35 -11
- package/public/assets/main.css +1 -0
- package/public/assets/main.js +8097 -0
- package/public/assets/main.js.map +1 -0
- package/dist/EmbeddingFactory-6UEXNF44.js +0 -1177
- package/dist/EmbeddingFactory-6UEXNF44.js.map +0 -1
- package/dist/chunk-VTO2ED43.js +0 -12098
- package/dist/chunk-VTO2ED43.js.map +0 -1
- package/dist/chunk-YCXNASA6.js +0 -124
- package/dist/chunk-YCXNASA6.js.map +0 -1
- package/dist/cli.d.ts +0 -1
- package/dist/server.d.ts +0 -1
|
@@ -1,1177 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
DimensionError,
|
|
3
|
-
VECTOR_DIMENSION,
|
|
4
|
-
__commonJS,
|
|
5
|
-
__toESM
|
|
6
|
-
} from "./chunk-YCXNASA6.js";
|
|
7
|
-
|
|
8
|
-
// node_modules/retry/lib/retry_operation.js
|
|
9
|
-
var require_retry_operation = __commonJS({
|
|
10
|
-
"node_modules/retry/lib/retry_operation.js"(exports, module) {
|
|
11
|
-
"use strict";
|
|
12
|
-
function RetryOperation(timeouts, options) {
|
|
13
|
-
if (typeof options === "boolean") {
|
|
14
|
-
options = { forever: options };
|
|
15
|
-
}
|
|
16
|
-
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
17
|
-
this._timeouts = timeouts;
|
|
18
|
-
this._options = options || {};
|
|
19
|
-
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
20
|
-
this._fn = null;
|
|
21
|
-
this._errors = [];
|
|
22
|
-
this._attempts = 1;
|
|
23
|
-
this._operationTimeout = null;
|
|
24
|
-
this._operationTimeoutCb = null;
|
|
25
|
-
this._timeout = null;
|
|
26
|
-
this._operationStart = null;
|
|
27
|
-
this._timer = null;
|
|
28
|
-
if (this._options.forever) {
|
|
29
|
-
this._cachedTimeouts = this._timeouts.slice(0);
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
module.exports = RetryOperation;
|
|
33
|
-
RetryOperation.prototype.reset = function() {
|
|
34
|
-
this._attempts = 1;
|
|
35
|
-
this._timeouts = this._originalTimeouts.slice(0);
|
|
36
|
-
};
|
|
37
|
-
RetryOperation.prototype.stop = function() {
|
|
38
|
-
if (this._timeout) {
|
|
39
|
-
clearTimeout(this._timeout);
|
|
40
|
-
}
|
|
41
|
-
if (this._timer) {
|
|
42
|
-
clearTimeout(this._timer);
|
|
43
|
-
}
|
|
44
|
-
this._timeouts = [];
|
|
45
|
-
this._cachedTimeouts = null;
|
|
46
|
-
};
|
|
47
|
-
RetryOperation.prototype.retry = function(err) {
|
|
48
|
-
if (this._timeout) {
|
|
49
|
-
clearTimeout(this._timeout);
|
|
50
|
-
}
|
|
51
|
-
if (!err) {
|
|
52
|
-
return false;
|
|
53
|
-
}
|
|
54
|
-
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
55
|
-
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
56
|
-
this._errors.push(err);
|
|
57
|
-
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
58
|
-
return false;
|
|
59
|
-
}
|
|
60
|
-
this._errors.push(err);
|
|
61
|
-
var timeout = this._timeouts.shift();
|
|
62
|
-
if (timeout === void 0) {
|
|
63
|
-
if (this._cachedTimeouts) {
|
|
64
|
-
this._errors.splice(0, this._errors.length - 1);
|
|
65
|
-
timeout = this._cachedTimeouts.slice(-1);
|
|
66
|
-
} else {
|
|
67
|
-
return false;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
var self = this;
|
|
71
|
-
this._timer = setTimeout(function() {
|
|
72
|
-
self._attempts++;
|
|
73
|
-
if (self._operationTimeoutCb) {
|
|
74
|
-
self._timeout = setTimeout(function() {
|
|
75
|
-
self._operationTimeoutCb(self._attempts);
|
|
76
|
-
}, self._operationTimeout);
|
|
77
|
-
if (self._options.unref) {
|
|
78
|
-
self._timeout.unref();
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
self._fn(self._attempts);
|
|
82
|
-
}, timeout);
|
|
83
|
-
if (this._options.unref) {
|
|
84
|
-
this._timer.unref();
|
|
85
|
-
}
|
|
86
|
-
return true;
|
|
87
|
-
};
|
|
88
|
-
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
89
|
-
this._fn = fn;
|
|
90
|
-
if (timeoutOps) {
|
|
91
|
-
if (timeoutOps.timeout) {
|
|
92
|
-
this._operationTimeout = timeoutOps.timeout;
|
|
93
|
-
}
|
|
94
|
-
if (timeoutOps.cb) {
|
|
95
|
-
this._operationTimeoutCb = timeoutOps.cb;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
var self = this;
|
|
99
|
-
if (this._operationTimeoutCb) {
|
|
100
|
-
this._timeout = setTimeout(function() {
|
|
101
|
-
self._operationTimeoutCb();
|
|
102
|
-
}, self._operationTimeout);
|
|
103
|
-
}
|
|
104
|
-
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
105
|
-
this._fn(this._attempts);
|
|
106
|
-
};
|
|
107
|
-
RetryOperation.prototype.try = function(fn) {
|
|
108
|
-
console.log("Using RetryOperation.try() is deprecated");
|
|
109
|
-
this.attempt(fn);
|
|
110
|
-
};
|
|
111
|
-
RetryOperation.prototype.start = function(fn) {
|
|
112
|
-
console.log("Using RetryOperation.start() is deprecated");
|
|
113
|
-
this.attempt(fn);
|
|
114
|
-
};
|
|
115
|
-
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
116
|
-
RetryOperation.prototype.errors = function() {
|
|
117
|
-
return this._errors;
|
|
118
|
-
};
|
|
119
|
-
RetryOperation.prototype.attempts = function() {
|
|
120
|
-
return this._attempts;
|
|
121
|
-
};
|
|
122
|
-
RetryOperation.prototype.mainError = function() {
|
|
123
|
-
if (this._errors.length === 0) {
|
|
124
|
-
return null;
|
|
125
|
-
}
|
|
126
|
-
var counts = {};
|
|
127
|
-
var mainError = null;
|
|
128
|
-
var mainErrorCount = 0;
|
|
129
|
-
for (var i = 0; i < this._errors.length; i++) {
|
|
130
|
-
var error = this._errors[i];
|
|
131
|
-
var message = error.message;
|
|
132
|
-
var count = (counts[message] || 0) + 1;
|
|
133
|
-
counts[message] = count;
|
|
134
|
-
if (count >= mainErrorCount) {
|
|
135
|
-
mainError = error;
|
|
136
|
-
mainErrorCount = count;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return mainError;
|
|
140
|
-
};
|
|
141
|
-
}
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
// node_modules/retry/lib/retry.js
|
|
145
|
-
var require_retry = __commonJS({
|
|
146
|
-
"node_modules/retry/lib/retry.js"(exports) {
|
|
147
|
-
"use strict";
|
|
148
|
-
var RetryOperation = require_retry_operation();
|
|
149
|
-
exports.operation = function(options) {
|
|
150
|
-
var timeouts = exports.timeouts(options);
|
|
151
|
-
return new RetryOperation(timeouts, {
|
|
152
|
-
forever: options && (options.forever || options.retries === Infinity),
|
|
153
|
-
unref: options && options.unref,
|
|
154
|
-
maxRetryTime: options && options.maxRetryTime
|
|
155
|
-
});
|
|
156
|
-
};
|
|
157
|
-
exports.timeouts = function(options) {
|
|
158
|
-
if (options instanceof Array) {
|
|
159
|
-
return [].concat(options);
|
|
160
|
-
}
|
|
161
|
-
var opts = {
|
|
162
|
-
retries: 10,
|
|
163
|
-
factor: 2,
|
|
164
|
-
minTimeout: 1 * 1e3,
|
|
165
|
-
maxTimeout: Infinity,
|
|
166
|
-
randomize: false
|
|
167
|
-
};
|
|
168
|
-
for (var key in options) {
|
|
169
|
-
opts[key] = options[key];
|
|
170
|
-
}
|
|
171
|
-
if (opts.minTimeout > opts.maxTimeout) {
|
|
172
|
-
throw new Error("minTimeout is greater than maxTimeout");
|
|
173
|
-
}
|
|
174
|
-
var timeouts = [];
|
|
175
|
-
for (var i = 0; i < opts.retries; i++) {
|
|
176
|
-
timeouts.push(this.createTimeout(i, opts));
|
|
177
|
-
}
|
|
178
|
-
if (options && options.forever && !timeouts.length) {
|
|
179
|
-
timeouts.push(this.createTimeout(i, opts));
|
|
180
|
-
}
|
|
181
|
-
timeouts.sort(function(a, b) {
|
|
182
|
-
return a - b;
|
|
183
|
-
});
|
|
184
|
-
return timeouts;
|
|
185
|
-
};
|
|
186
|
-
exports.createTimeout = function(attempt, opts) {
|
|
187
|
-
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
188
|
-
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
189
|
-
timeout = Math.min(timeout, opts.maxTimeout);
|
|
190
|
-
return timeout;
|
|
191
|
-
};
|
|
192
|
-
exports.wrap = function(obj, options, methods) {
|
|
193
|
-
if (options instanceof Array) {
|
|
194
|
-
methods = options;
|
|
195
|
-
options = null;
|
|
196
|
-
}
|
|
197
|
-
if (!methods) {
|
|
198
|
-
methods = [];
|
|
199
|
-
for (var key in obj) {
|
|
200
|
-
if (typeof obj[key] === "function") {
|
|
201
|
-
methods.push(key);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
}
|
|
205
|
-
for (var i = 0; i < methods.length; i++) {
|
|
206
|
-
var method = methods[i];
|
|
207
|
-
var original = obj[method];
|
|
208
|
-
obj[method] = function retryWrapper(original2) {
|
|
209
|
-
var op = exports.operation(options);
|
|
210
|
-
var args = Array.prototype.slice.call(arguments, 1);
|
|
211
|
-
var callback = args.pop();
|
|
212
|
-
args.push(function(err) {
|
|
213
|
-
if (op.retry(err)) {
|
|
214
|
-
return;
|
|
215
|
-
}
|
|
216
|
-
if (err) {
|
|
217
|
-
arguments[0] = op.mainError();
|
|
218
|
-
}
|
|
219
|
-
callback.apply(this, arguments);
|
|
220
|
-
});
|
|
221
|
-
op.attempt(function() {
|
|
222
|
-
original2.apply(obj, args);
|
|
223
|
-
});
|
|
224
|
-
}.bind(obj, original);
|
|
225
|
-
obj[method].options = options;
|
|
226
|
-
}
|
|
227
|
-
};
|
|
228
|
-
}
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
// node_modules/retry/index.js
|
|
232
|
-
var require_retry2 = __commonJS({
|
|
233
|
-
"node_modules/retry/index.js"(exports, module) {
|
|
234
|
-
"use strict";
|
|
235
|
-
module.exports = require_retry();
|
|
236
|
-
}
|
|
237
|
-
});
|
|
238
|
-
|
|
239
|
-
// node_modules/p-retry/index.js
|
|
240
|
-
var require_p_retry = __commonJS({
|
|
241
|
-
"node_modules/p-retry/index.js"(exports, module) {
|
|
242
|
-
"use strict";
|
|
243
|
-
var retry = require_retry2();
|
|
244
|
-
var networkErrorMsgs = [
|
|
245
|
-
"Failed to fetch",
|
|
246
|
-
// Chrome
|
|
247
|
-
"NetworkError when attempting to fetch resource.",
|
|
248
|
-
// Firefox
|
|
249
|
-
"The Internet connection appears to be offline.",
|
|
250
|
-
// Safari
|
|
251
|
-
"Network request failed"
|
|
252
|
-
// `cross-fetch`
|
|
253
|
-
];
|
|
254
|
-
var AbortError = class extends Error {
|
|
255
|
-
constructor(message) {
|
|
256
|
-
super();
|
|
257
|
-
if (message instanceof Error) {
|
|
258
|
-
this.originalError = message;
|
|
259
|
-
({ message } = message);
|
|
260
|
-
} else {
|
|
261
|
-
this.originalError = new Error(message);
|
|
262
|
-
this.originalError.stack = this.stack;
|
|
263
|
-
}
|
|
264
|
-
this.name = "AbortError";
|
|
265
|
-
this.message = message;
|
|
266
|
-
}
|
|
267
|
-
};
|
|
268
|
-
var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
269
|
-
const retriesLeft = options.retries - (attemptNumber - 1);
|
|
270
|
-
error.attemptNumber = attemptNumber;
|
|
271
|
-
error.retriesLeft = retriesLeft;
|
|
272
|
-
return error;
|
|
273
|
-
};
|
|
274
|
-
var isNetworkError = (errorMessage) => networkErrorMsgs.includes(errorMessage);
|
|
275
|
-
var pRetry2 = (input, options) => new Promise((resolve, reject) => {
|
|
276
|
-
options = {
|
|
277
|
-
onFailedAttempt: () => {
|
|
278
|
-
},
|
|
279
|
-
retries: 10,
|
|
280
|
-
...options
|
|
281
|
-
};
|
|
282
|
-
const operation = retry.operation(options);
|
|
283
|
-
operation.attempt(async (attemptNumber) => {
|
|
284
|
-
try {
|
|
285
|
-
resolve(await input(attemptNumber));
|
|
286
|
-
} catch (error) {
|
|
287
|
-
if (!(error instanceof Error)) {
|
|
288
|
-
reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
|
|
289
|
-
return;
|
|
290
|
-
}
|
|
291
|
-
if (error instanceof AbortError) {
|
|
292
|
-
operation.stop();
|
|
293
|
-
reject(error.originalError);
|
|
294
|
-
} else if (error instanceof TypeError && !isNetworkError(error.message)) {
|
|
295
|
-
operation.stop();
|
|
296
|
-
reject(error);
|
|
297
|
-
} else {
|
|
298
|
-
decorateErrorWithCounts(error, attemptNumber, options);
|
|
299
|
-
try {
|
|
300
|
-
await options.onFailedAttempt(error);
|
|
301
|
-
} catch (error2) {
|
|
302
|
-
reject(error2);
|
|
303
|
-
return;
|
|
304
|
-
}
|
|
305
|
-
if (!operation.retry(error)) {
|
|
306
|
-
reject(operation.mainError());
|
|
307
|
-
}
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
});
|
|
311
|
-
});
|
|
312
|
-
module.exports = pRetry2;
|
|
313
|
-
module.exports.default = pRetry2;
|
|
314
|
-
module.exports.AbortError = AbortError;
|
|
315
|
-
}
|
|
316
|
-
});
|
|
317
|
-
|
|
318
|
-
// node_modules/eventemitter3/index.js
|
|
319
|
-
var require_eventemitter3 = __commonJS({
|
|
320
|
-
"node_modules/eventemitter3/index.js"(exports, module) {
|
|
321
|
-
"use strict";
|
|
322
|
-
var has = Object.prototype.hasOwnProperty;
|
|
323
|
-
var prefix = "~";
|
|
324
|
-
function Events() {
|
|
325
|
-
}
|
|
326
|
-
if (Object.create) {
|
|
327
|
-
Events.prototype = /* @__PURE__ */ Object.create(null);
|
|
328
|
-
if (!new Events().__proto__) prefix = false;
|
|
329
|
-
}
|
|
330
|
-
function EE(fn, context, once) {
|
|
331
|
-
this.fn = fn;
|
|
332
|
-
this.context = context;
|
|
333
|
-
this.once = once || false;
|
|
334
|
-
}
|
|
335
|
-
function addListener(emitter, event, fn, context, once) {
|
|
336
|
-
if (typeof fn !== "function") {
|
|
337
|
-
throw new TypeError("The listener must be a function");
|
|
338
|
-
}
|
|
339
|
-
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
340
|
-
if (!emitter._events[evt]) emitter._events[evt] = listener, emitter._eventsCount++;
|
|
341
|
-
else if (!emitter._events[evt].fn) emitter._events[evt].push(listener);
|
|
342
|
-
else emitter._events[evt] = [emitter._events[evt], listener];
|
|
343
|
-
return emitter;
|
|
344
|
-
}
|
|
345
|
-
function clearEvent(emitter, evt) {
|
|
346
|
-
if (--emitter._eventsCount === 0) emitter._events = new Events();
|
|
347
|
-
else delete emitter._events[evt];
|
|
348
|
-
}
|
|
349
|
-
function EventEmitter() {
|
|
350
|
-
this._events = new Events();
|
|
351
|
-
this._eventsCount = 0;
|
|
352
|
-
}
|
|
353
|
-
EventEmitter.prototype.eventNames = function eventNames() {
|
|
354
|
-
var names = [], events, name;
|
|
355
|
-
if (this._eventsCount === 0) return names;
|
|
356
|
-
for (name in events = this._events) {
|
|
357
|
-
if (has.call(events, name)) names.push(prefix ? name.slice(1) : name);
|
|
358
|
-
}
|
|
359
|
-
if (Object.getOwnPropertySymbols) {
|
|
360
|
-
return names.concat(Object.getOwnPropertySymbols(events));
|
|
361
|
-
}
|
|
362
|
-
return names;
|
|
363
|
-
};
|
|
364
|
-
EventEmitter.prototype.listeners = function listeners(event) {
|
|
365
|
-
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
366
|
-
if (!handlers) return [];
|
|
367
|
-
if (handlers.fn) return [handlers.fn];
|
|
368
|
-
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
369
|
-
ee[i] = handlers[i].fn;
|
|
370
|
-
}
|
|
371
|
-
return ee;
|
|
372
|
-
};
|
|
373
|
-
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
374
|
-
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
375
|
-
if (!listeners) return 0;
|
|
376
|
-
if (listeners.fn) return 1;
|
|
377
|
-
return listeners.length;
|
|
378
|
-
};
|
|
379
|
-
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
380
|
-
var evt = prefix ? prefix + event : event;
|
|
381
|
-
if (!this._events[evt]) return false;
|
|
382
|
-
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
383
|
-
if (listeners.fn) {
|
|
384
|
-
if (listeners.once) this.removeListener(event, listeners.fn, void 0, true);
|
|
385
|
-
switch (len) {
|
|
386
|
-
case 1:
|
|
387
|
-
return listeners.fn.call(listeners.context), true;
|
|
388
|
-
case 2:
|
|
389
|
-
return listeners.fn.call(listeners.context, a1), true;
|
|
390
|
-
case 3:
|
|
391
|
-
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
392
|
-
case 4:
|
|
393
|
-
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
394
|
-
case 5:
|
|
395
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
396
|
-
case 6:
|
|
397
|
-
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
398
|
-
}
|
|
399
|
-
for (i = 1, args = new Array(len - 1); i < len; i++) {
|
|
400
|
-
args[i - 1] = arguments[i];
|
|
401
|
-
}
|
|
402
|
-
listeners.fn.apply(listeners.context, args);
|
|
403
|
-
} else {
|
|
404
|
-
var length = listeners.length, j;
|
|
405
|
-
for (i = 0; i < length; i++) {
|
|
406
|
-
if (listeners[i].once) this.removeListener(event, listeners[i].fn, void 0, true);
|
|
407
|
-
switch (len) {
|
|
408
|
-
case 1:
|
|
409
|
-
listeners[i].fn.call(listeners[i].context);
|
|
410
|
-
break;
|
|
411
|
-
case 2:
|
|
412
|
-
listeners[i].fn.call(listeners[i].context, a1);
|
|
413
|
-
break;
|
|
414
|
-
case 3:
|
|
415
|
-
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
416
|
-
break;
|
|
417
|
-
case 4:
|
|
418
|
-
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
419
|
-
break;
|
|
420
|
-
default:
|
|
421
|
-
if (!args) for (j = 1, args = new Array(len - 1); j < len; j++) {
|
|
422
|
-
args[j - 1] = arguments[j];
|
|
423
|
-
}
|
|
424
|
-
listeners[i].fn.apply(listeners[i].context, args);
|
|
425
|
-
}
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
return true;
|
|
429
|
-
};
|
|
430
|
-
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
431
|
-
return addListener(this, event, fn, context, false);
|
|
432
|
-
};
|
|
433
|
-
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
434
|
-
return addListener(this, event, fn, context, true);
|
|
435
|
-
};
|
|
436
|
-
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
437
|
-
var evt = prefix ? prefix + event : event;
|
|
438
|
-
if (!this._events[evt]) return this;
|
|
439
|
-
if (!fn) {
|
|
440
|
-
clearEvent(this, evt);
|
|
441
|
-
return this;
|
|
442
|
-
}
|
|
443
|
-
var listeners = this._events[evt];
|
|
444
|
-
if (listeners.fn) {
|
|
445
|
-
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
446
|
-
clearEvent(this, evt);
|
|
447
|
-
}
|
|
448
|
-
} else {
|
|
449
|
-
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
450
|
-
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
451
|
-
events.push(listeners[i]);
|
|
452
|
-
}
|
|
453
|
-
}
|
|
454
|
-
if (events.length) this._events[evt] = events.length === 1 ? events[0] : events;
|
|
455
|
-
else clearEvent(this, evt);
|
|
456
|
-
}
|
|
457
|
-
return this;
|
|
458
|
-
};
|
|
459
|
-
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
460
|
-
var evt;
|
|
461
|
-
if (event) {
|
|
462
|
-
evt = prefix ? prefix + event : event;
|
|
463
|
-
if (this._events[evt]) clearEvent(this, evt);
|
|
464
|
-
} else {
|
|
465
|
-
this._events = new Events();
|
|
466
|
-
this._eventsCount = 0;
|
|
467
|
-
}
|
|
468
|
-
return this;
|
|
469
|
-
};
|
|
470
|
-
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
471
|
-
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
472
|
-
EventEmitter.prefixed = prefix;
|
|
473
|
-
EventEmitter.EventEmitter = EventEmitter;
|
|
474
|
-
if ("undefined" !== typeof module) {
|
|
475
|
-
module.exports = EventEmitter;
|
|
476
|
-
}
|
|
477
|
-
}
|
|
478
|
-
});
|
|
479
|
-
|
|
480
|
-
// node_modules/p-finally/index.js
|
|
481
|
-
var require_p_finally = __commonJS({
|
|
482
|
-
"node_modules/p-finally/index.js"(exports, module) {
|
|
483
|
-
"use strict";
|
|
484
|
-
module.exports = (promise, onFinally) => {
|
|
485
|
-
onFinally = onFinally || (() => {
|
|
486
|
-
});
|
|
487
|
-
return promise.then(
|
|
488
|
-
(val) => new Promise((resolve) => {
|
|
489
|
-
resolve(onFinally());
|
|
490
|
-
}).then(() => val),
|
|
491
|
-
(err) => new Promise((resolve) => {
|
|
492
|
-
resolve(onFinally());
|
|
493
|
-
}).then(() => {
|
|
494
|
-
throw err;
|
|
495
|
-
})
|
|
496
|
-
);
|
|
497
|
-
};
|
|
498
|
-
}
|
|
499
|
-
});
|
|
500
|
-
|
|
501
|
-
// node_modules/p-timeout/index.js
|
|
502
|
-
var require_p_timeout = __commonJS({
|
|
503
|
-
"node_modules/p-timeout/index.js"(exports, module) {
|
|
504
|
-
"use strict";
|
|
505
|
-
var pFinally = require_p_finally();
|
|
506
|
-
var TimeoutError = class extends Error {
|
|
507
|
-
constructor(message) {
|
|
508
|
-
super(message);
|
|
509
|
-
this.name = "TimeoutError";
|
|
510
|
-
}
|
|
511
|
-
};
|
|
512
|
-
var pTimeout = (promise, milliseconds, fallback) => new Promise((resolve, reject) => {
|
|
513
|
-
if (typeof milliseconds !== "number" || milliseconds < 0) {
|
|
514
|
-
throw new TypeError("Expected `milliseconds` to be a positive number");
|
|
515
|
-
}
|
|
516
|
-
if (milliseconds === Infinity) {
|
|
517
|
-
resolve(promise);
|
|
518
|
-
return;
|
|
519
|
-
}
|
|
520
|
-
const timer = setTimeout(() => {
|
|
521
|
-
if (typeof fallback === "function") {
|
|
522
|
-
try {
|
|
523
|
-
resolve(fallback());
|
|
524
|
-
} catch (error) {
|
|
525
|
-
reject(error);
|
|
526
|
-
}
|
|
527
|
-
return;
|
|
528
|
-
}
|
|
529
|
-
const message = typeof fallback === "string" ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
|
530
|
-
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
|
531
|
-
if (typeof promise.cancel === "function") {
|
|
532
|
-
promise.cancel();
|
|
533
|
-
}
|
|
534
|
-
reject(timeoutError);
|
|
535
|
-
}, milliseconds);
|
|
536
|
-
pFinally(
|
|
537
|
-
// eslint-disable-next-line promise/prefer-await-to-then
|
|
538
|
-
promise.then(resolve, reject),
|
|
539
|
-
() => {
|
|
540
|
-
clearTimeout(timer);
|
|
541
|
-
}
|
|
542
|
-
);
|
|
543
|
-
});
|
|
544
|
-
module.exports = pTimeout;
|
|
545
|
-
module.exports.default = pTimeout;
|
|
546
|
-
module.exports.TimeoutError = TimeoutError;
|
|
547
|
-
}
|
|
548
|
-
});
|
|
549
|
-
|
|
550
|
-
// node_modules/p-queue/dist/lower-bound.js
|
|
551
|
-
var require_lower_bound = __commonJS({
|
|
552
|
-
"node_modules/p-queue/dist/lower-bound.js"(exports) {
|
|
553
|
-
"use strict";
|
|
554
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
555
|
-
function lowerBound(array, value, comparator) {
|
|
556
|
-
let first = 0;
|
|
557
|
-
let count = array.length;
|
|
558
|
-
while (count > 0) {
|
|
559
|
-
const step = count / 2 | 0;
|
|
560
|
-
let it = first + step;
|
|
561
|
-
if (comparator(array[it], value) <= 0) {
|
|
562
|
-
first = ++it;
|
|
563
|
-
count -= step + 1;
|
|
564
|
-
} else {
|
|
565
|
-
count = step;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
return first;
|
|
569
|
-
}
|
|
570
|
-
exports.default = lowerBound;
|
|
571
|
-
}
|
|
572
|
-
});
|
|
573
|
-
|
|
574
|
-
// node_modules/p-queue/dist/priority-queue.js
|
|
575
|
-
var require_priority_queue = __commonJS({
|
|
576
|
-
"node_modules/p-queue/dist/priority-queue.js"(exports) {
|
|
577
|
-
"use strict";
|
|
578
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
579
|
-
var lower_bound_1 = require_lower_bound();
|
|
580
|
-
var PriorityQueue = class {
|
|
581
|
-
constructor() {
|
|
582
|
-
this._queue = [];
|
|
583
|
-
}
|
|
584
|
-
enqueue(run, options) {
|
|
585
|
-
options = Object.assign({ priority: 0 }, options);
|
|
586
|
-
const element = {
|
|
587
|
-
priority: options.priority,
|
|
588
|
-
run
|
|
589
|
-
};
|
|
590
|
-
if (this.size && this._queue[this.size - 1].priority >= options.priority) {
|
|
591
|
-
this._queue.push(element);
|
|
592
|
-
return;
|
|
593
|
-
}
|
|
594
|
-
const index = lower_bound_1.default(this._queue, element, (a, b) => b.priority - a.priority);
|
|
595
|
-
this._queue.splice(index, 0, element);
|
|
596
|
-
}
|
|
597
|
-
dequeue() {
|
|
598
|
-
const item = this._queue.shift();
|
|
599
|
-
return item === null || item === void 0 ? void 0 : item.run;
|
|
600
|
-
}
|
|
601
|
-
filter(options) {
|
|
602
|
-
return this._queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
603
|
-
}
|
|
604
|
-
get size() {
|
|
605
|
-
return this._queue.length;
|
|
606
|
-
}
|
|
607
|
-
};
|
|
608
|
-
exports.default = PriorityQueue;
|
|
609
|
-
}
|
|
610
|
-
});
|
|
611
|
-
|
|
612
|
-
// node_modules/p-queue/dist/index.js
|
|
613
|
-
var require_dist = __commonJS({
|
|
614
|
-
"node_modules/p-queue/dist/index.js"(exports) {
|
|
615
|
-
"use strict";
|
|
616
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
617
|
-
var EventEmitter = require_eventemitter3();
|
|
618
|
-
var p_timeout_1 = require_p_timeout();
|
|
619
|
-
var priority_queue_1 = require_priority_queue();
|
|
620
|
-
var empty = () => {
|
|
621
|
-
};
|
|
622
|
-
var timeoutError = new p_timeout_1.TimeoutError();
|
|
623
|
-
var PQueue = class extends EventEmitter {
|
|
624
|
-
constructor(options) {
|
|
625
|
-
var _a, _b, _c, _d;
|
|
626
|
-
super();
|
|
627
|
-
this._intervalCount = 0;
|
|
628
|
-
this._intervalEnd = 0;
|
|
629
|
-
this._pendingCount = 0;
|
|
630
|
-
this._resolveEmpty = empty;
|
|
631
|
-
this._resolveIdle = empty;
|
|
632
|
-
options = Object.assign({ carryoverConcurrencyCount: false, intervalCap: Infinity, interval: 0, concurrency: Infinity, autoStart: true, queueClass: priority_queue_1.default }, options);
|
|
633
|
-
if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
|
|
634
|
-
throw new TypeError(`Expected \`intervalCap\` to be a number from 1 and up, got \`${(_b = (_a = options.intervalCap) === null || _a === void 0 ? void 0 : _a.toString()) !== null && _b !== void 0 ? _b : ""}\` (${typeof options.intervalCap})`);
|
|
635
|
-
}
|
|
636
|
-
if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
637
|
-
throw new TypeError(`Expected \`interval\` to be a finite number >= 0, got \`${(_d = (_c = options.interval) === null || _c === void 0 ? void 0 : _c.toString()) !== null && _d !== void 0 ? _d : ""}\` (${typeof options.interval})`);
|
|
638
|
-
}
|
|
639
|
-
this._carryoverConcurrencyCount = options.carryoverConcurrencyCount;
|
|
640
|
-
this._isIntervalIgnored = options.intervalCap === Infinity || options.interval === 0;
|
|
641
|
-
this._intervalCap = options.intervalCap;
|
|
642
|
-
this._interval = options.interval;
|
|
643
|
-
this._queue = new options.queueClass();
|
|
644
|
-
this._queueClass = options.queueClass;
|
|
645
|
-
this.concurrency = options.concurrency;
|
|
646
|
-
this._timeout = options.timeout;
|
|
647
|
-
this._throwOnTimeout = options.throwOnTimeout === true;
|
|
648
|
-
this._isPaused = options.autoStart === false;
|
|
649
|
-
}
|
|
650
|
-
get _doesIntervalAllowAnother() {
|
|
651
|
-
return this._isIntervalIgnored || this._intervalCount < this._intervalCap;
|
|
652
|
-
}
|
|
653
|
-
get _doesConcurrentAllowAnother() {
|
|
654
|
-
return this._pendingCount < this._concurrency;
|
|
655
|
-
}
|
|
656
|
-
_next() {
|
|
657
|
-
this._pendingCount--;
|
|
658
|
-
this._tryToStartAnother();
|
|
659
|
-
this.emit("next");
|
|
660
|
-
}
|
|
661
|
-
_resolvePromises() {
|
|
662
|
-
this._resolveEmpty();
|
|
663
|
-
this._resolveEmpty = empty;
|
|
664
|
-
if (this._pendingCount === 0) {
|
|
665
|
-
this._resolveIdle();
|
|
666
|
-
this._resolveIdle = empty;
|
|
667
|
-
this.emit("idle");
|
|
668
|
-
}
|
|
669
|
-
}
|
|
670
|
-
_onResumeInterval() {
|
|
671
|
-
this._onInterval();
|
|
672
|
-
this._initializeIntervalIfNeeded();
|
|
673
|
-
this._timeoutId = void 0;
|
|
674
|
-
}
|
|
675
|
-
_isIntervalPaused() {
|
|
676
|
-
const now = Date.now();
|
|
677
|
-
if (this._intervalId === void 0) {
|
|
678
|
-
const delay = this._intervalEnd - now;
|
|
679
|
-
if (delay < 0) {
|
|
680
|
-
this._intervalCount = this._carryoverConcurrencyCount ? this._pendingCount : 0;
|
|
681
|
-
} else {
|
|
682
|
-
if (this._timeoutId === void 0) {
|
|
683
|
-
this._timeoutId = setTimeout(() => {
|
|
684
|
-
this._onResumeInterval();
|
|
685
|
-
}, delay);
|
|
686
|
-
}
|
|
687
|
-
return true;
|
|
688
|
-
}
|
|
689
|
-
}
|
|
690
|
-
return false;
|
|
691
|
-
}
|
|
692
|
-
_tryToStartAnother() {
|
|
693
|
-
if (this._queue.size === 0) {
|
|
694
|
-
if (this._intervalId) {
|
|
695
|
-
clearInterval(this._intervalId);
|
|
696
|
-
}
|
|
697
|
-
this._intervalId = void 0;
|
|
698
|
-
this._resolvePromises();
|
|
699
|
-
return false;
|
|
700
|
-
}
|
|
701
|
-
if (!this._isPaused) {
|
|
702
|
-
const canInitializeInterval = !this._isIntervalPaused();
|
|
703
|
-
if (this._doesIntervalAllowAnother && this._doesConcurrentAllowAnother) {
|
|
704
|
-
const job = this._queue.dequeue();
|
|
705
|
-
if (!job) {
|
|
706
|
-
return false;
|
|
707
|
-
}
|
|
708
|
-
this.emit("active");
|
|
709
|
-
job();
|
|
710
|
-
if (canInitializeInterval) {
|
|
711
|
-
this._initializeIntervalIfNeeded();
|
|
712
|
-
}
|
|
713
|
-
return true;
|
|
714
|
-
}
|
|
715
|
-
}
|
|
716
|
-
return false;
|
|
717
|
-
}
|
|
718
|
-
_initializeIntervalIfNeeded() {
|
|
719
|
-
if (this._isIntervalIgnored || this._intervalId !== void 0) {
|
|
720
|
-
return;
|
|
721
|
-
}
|
|
722
|
-
this._intervalId = setInterval(() => {
|
|
723
|
-
this._onInterval();
|
|
724
|
-
}, this._interval);
|
|
725
|
-
this._intervalEnd = Date.now() + this._interval;
|
|
726
|
-
}
|
|
727
|
-
_onInterval() {
|
|
728
|
-
if (this._intervalCount === 0 && this._pendingCount === 0 && this._intervalId) {
|
|
729
|
-
clearInterval(this._intervalId);
|
|
730
|
-
this._intervalId = void 0;
|
|
731
|
-
}
|
|
732
|
-
this._intervalCount = this._carryoverConcurrencyCount ? this._pendingCount : 0;
|
|
733
|
-
this._processQueue();
|
|
734
|
-
}
|
|
735
|
-
/**
|
|
736
|
-
Executes all queued functions until it reaches the limit.
|
|
737
|
-
*/
|
|
738
|
-
_processQueue() {
|
|
739
|
-
while (this._tryToStartAnother()) {
|
|
740
|
-
}
|
|
741
|
-
}
|
|
742
|
-
get concurrency() {
|
|
743
|
-
return this._concurrency;
|
|
744
|
-
}
|
|
745
|
-
set concurrency(newConcurrency) {
|
|
746
|
-
if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) {
|
|
747
|
-
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
|
|
748
|
-
}
|
|
749
|
-
this._concurrency = newConcurrency;
|
|
750
|
-
this._processQueue();
|
|
751
|
-
}
|
|
752
|
-
/**
|
|
753
|
-
Adds a sync or async task to the queue. Always returns a promise.
|
|
754
|
-
*/
|
|
755
|
-
async add(fn, options = {}) {
|
|
756
|
-
return new Promise((resolve, reject) => {
|
|
757
|
-
const run = async () => {
|
|
758
|
-
this._pendingCount++;
|
|
759
|
-
this._intervalCount++;
|
|
760
|
-
try {
|
|
761
|
-
const operation = this._timeout === void 0 && options.timeout === void 0 ? fn() : p_timeout_1.default(Promise.resolve(fn()), options.timeout === void 0 ? this._timeout : options.timeout, () => {
|
|
762
|
-
if (options.throwOnTimeout === void 0 ? this._throwOnTimeout : options.throwOnTimeout) {
|
|
763
|
-
reject(timeoutError);
|
|
764
|
-
}
|
|
765
|
-
return void 0;
|
|
766
|
-
});
|
|
767
|
-
resolve(await operation);
|
|
768
|
-
} catch (error) {
|
|
769
|
-
reject(error);
|
|
770
|
-
}
|
|
771
|
-
this._next();
|
|
772
|
-
};
|
|
773
|
-
this._queue.enqueue(run, options);
|
|
774
|
-
this._tryToStartAnother();
|
|
775
|
-
this.emit("add");
|
|
776
|
-
});
|
|
777
|
-
}
|
|
778
|
-
/**
|
|
779
|
-
Same as `.add()`, but accepts an array of sync or async functions.
|
|
780
|
-
|
|
781
|
-
@returns A promise that resolves when all functions are resolved.
|
|
782
|
-
*/
|
|
783
|
-
async addAll(functions, options) {
|
|
784
|
-
return Promise.all(functions.map(async (function_) => this.add(function_, options)));
|
|
785
|
-
}
|
|
786
|
-
/**
|
|
787
|
-
Start (or resume) executing enqueued tasks within concurrency limit. No need to call this if queue is not paused (via `options.autoStart = false` or by `.pause()` method.)
|
|
788
|
-
*/
|
|
789
|
-
start() {
|
|
790
|
-
if (!this._isPaused) {
|
|
791
|
-
return this;
|
|
792
|
-
}
|
|
793
|
-
this._isPaused = false;
|
|
794
|
-
this._processQueue();
|
|
795
|
-
return this;
|
|
796
|
-
}
|
|
797
|
-
/**
|
|
798
|
-
Put queue execution on hold.
|
|
799
|
-
*/
|
|
800
|
-
pause() {
|
|
801
|
-
this._isPaused = true;
|
|
802
|
-
}
|
|
803
|
-
/**
|
|
804
|
-
Clear the queue.
|
|
805
|
-
*/
|
|
806
|
-
clear() {
|
|
807
|
-
this._queue = new this._queueClass();
|
|
808
|
-
}
|
|
809
|
-
/**
|
|
810
|
-
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
811
|
-
|
|
812
|
-
@returns A promise that settles when the queue becomes empty.
|
|
813
|
-
*/
|
|
814
|
-
async onEmpty() {
|
|
815
|
-
if (this._queue.size === 0) {
|
|
816
|
-
return;
|
|
817
|
-
}
|
|
818
|
-
return new Promise((resolve) => {
|
|
819
|
-
const existingResolve = this._resolveEmpty;
|
|
820
|
-
this._resolveEmpty = () => {
|
|
821
|
-
existingResolve();
|
|
822
|
-
resolve();
|
|
823
|
-
};
|
|
824
|
-
});
|
|
825
|
-
}
|
|
826
|
-
/**
|
|
827
|
-
The difference with `.onEmpty` is that `.onIdle` guarantees that all work from the queue has finished. `.onEmpty` merely signals that the queue is empty, but it could mean that some promises haven't completed yet.
|
|
828
|
-
|
|
829
|
-
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
|
|
830
|
-
*/
|
|
831
|
-
async onIdle() {
|
|
832
|
-
if (this._pendingCount === 0 && this._queue.size === 0) {
|
|
833
|
-
return;
|
|
834
|
-
}
|
|
835
|
-
return new Promise((resolve) => {
|
|
836
|
-
const existingResolve = this._resolveIdle;
|
|
837
|
-
this._resolveIdle = () => {
|
|
838
|
-
existingResolve();
|
|
839
|
-
resolve();
|
|
840
|
-
};
|
|
841
|
-
});
|
|
842
|
-
}
|
|
843
|
-
/**
|
|
844
|
-
Size of the queue.
|
|
845
|
-
*/
|
|
846
|
-
get size() {
|
|
847
|
-
return this._queue.size;
|
|
848
|
-
}
|
|
849
|
-
/**
|
|
850
|
-
Size of the queue, filtered by the given options.
|
|
851
|
-
|
|
852
|
-
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
|
|
853
|
-
*/
|
|
854
|
-
sizeBy(options) {
|
|
855
|
-
return this._queue.filter(options).length;
|
|
856
|
-
}
|
|
857
|
-
/**
|
|
858
|
-
Number of pending promises.
|
|
859
|
-
*/
|
|
860
|
-
get pending() {
|
|
861
|
-
return this._pendingCount;
|
|
862
|
-
}
|
|
863
|
-
/**
|
|
864
|
-
Whether the queue is currently paused.
|
|
865
|
-
*/
|
|
866
|
-
get isPaused() {
|
|
867
|
-
return this._isPaused;
|
|
868
|
-
}
|
|
869
|
-
get timeout() {
|
|
870
|
-
return this._timeout;
|
|
871
|
-
}
|
|
872
|
-
/**
|
|
873
|
-
Set the timeout for future operations.
|
|
874
|
-
*/
|
|
875
|
-
set timeout(milliseconds) {
|
|
876
|
-
this._timeout = milliseconds;
|
|
877
|
-
}
|
|
878
|
-
};
|
|
879
|
-
exports.default = PQueue;
|
|
880
|
-
}
|
|
881
|
-
});
|
|
882
|
-
|
|
883
|
-
// src/store/embeddings/EmbeddingFactory.ts
|
|
884
|
-
import { BedrockEmbeddings } from "@langchain/aws";
|
|
885
|
-
import { GoogleGenerativeAIEmbeddings } from "@langchain/google-genai";
|
|
886
|
-
import { VertexAIEmbeddings } from "@langchain/google-vertexai";
|
|
887
|
-
import {
|
|
888
|
-
AzureOpenAIEmbeddings,
|
|
889
|
-
OpenAIEmbeddings
|
|
890
|
-
} from "@langchain/openai";
|
|
891
|
-
|
|
892
|
-
// node_modules/@langchain/core/dist/utils/async_caller.js
|
|
893
|
-
var import_p_retry = __toESM(require_p_retry(), 1);
|
|
894
|
-
var import_p_queue = __toESM(require_dist(), 1);
|
|
895
|
-
var STATUS_NO_RETRY = [
|
|
896
|
-
400,
|
|
897
|
-
401,
|
|
898
|
-
402,
|
|
899
|
-
403,
|
|
900
|
-
404,
|
|
901
|
-
405,
|
|
902
|
-
406,
|
|
903
|
-
407,
|
|
904
|
-
409
|
|
905
|
-
// Conflict
|
|
906
|
-
];
|
|
907
|
-
var defaultFailedAttemptHandler = (error) => {
|
|
908
|
-
if (error.message.startsWith("Cancel") || error.message.startsWith("AbortError") || error.name === "AbortError") {
|
|
909
|
-
throw error;
|
|
910
|
-
}
|
|
911
|
-
if (error?.code === "ECONNABORTED") {
|
|
912
|
-
throw error;
|
|
913
|
-
}
|
|
914
|
-
const status = (
|
|
915
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
916
|
-
error?.response?.status ?? error?.status
|
|
917
|
-
);
|
|
918
|
-
if (status && STATUS_NO_RETRY.includes(+status)) {
|
|
919
|
-
throw error;
|
|
920
|
-
}
|
|
921
|
-
if (error?.error?.code === "insufficient_quota") {
|
|
922
|
-
const err = new Error(error?.message);
|
|
923
|
-
err.name = "InsufficientQuotaError";
|
|
924
|
-
throw err;
|
|
925
|
-
}
|
|
926
|
-
};
|
|
927
|
-
var AsyncCaller = class {
|
|
928
|
-
constructor(params) {
|
|
929
|
-
Object.defineProperty(this, "maxConcurrency", {
|
|
930
|
-
enumerable: true,
|
|
931
|
-
configurable: true,
|
|
932
|
-
writable: true,
|
|
933
|
-
value: void 0
|
|
934
|
-
});
|
|
935
|
-
Object.defineProperty(this, "maxRetries", {
|
|
936
|
-
enumerable: true,
|
|
937
|
-
configurable: true,
|
|
938
|
-
writable: true,
|
|
939
|
-
value: void 0
|
|
940
|
-
});
|
|
941
|
-
Object.defineProperty(this, "onFailedAttempt", {
|
|
942
|
-
enumerable: true,
|
|
943
|
-
configurable: true,
|
|
944
|
-
writable: true,
|
|
945
|
-
value: void 0
|
|
946
|
-
});
|
|
947
|
-
Object.defineProperty(this, "queue", {
|
|
948
|
-
enumerable: true,
|
|
949
|
-
configurable: true,
|
|
950
|
-
writable: true,
|
|
951
|
-
value: void 0
|
|
952
|
-
});
|
|
953
|
-
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
954
|
-
this.maxRetries = params.maxRetries ?? 6;
|
|
955
|
-
this.onFailedAttempt = params.onFailedAttempt ?? defaultFailedAttemptHandler;
|
|
956
|
-
const PQueue = "default" in import_p_queue.default ? import_p_queue.default.default : import_p_queue.default;
|
|
957
|
-
this.queue = new PQueue({ concurrency: this.maxConcurrency });
|
|
958
|
-
}
|
|
959
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
960
|
-
call(callable, ...args) {
|
|
961
|
-
return this.queue.add(() => (0, import_p_retry.default)(() => callable(...args).catch((error) => {
|
|
962
|
-
if (error instanceof Error) {
|
|
963
|
-
throw error;
|
|
964
|
-
} else {
|
|
965
|
-
throw new Error(error);
|
|
966
|
-
}
|
|
967
|
-
}), {
|
|
968
|
-
onFailedAttempt: this.onFailedAttempt,
|
|
969
|
-
retries: this.maxRetries,
|
|
970
|
-
randomize: true
|
|
971
|
-
// If needed we can change some of the defaults here,
|
|
972
|
-
// but they're quite sensible.
|
|
973
|
-
}), { throwOnTimeout: true });
|
|
974
|
-
}
|
|
975
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
976
|
-
callWithOptions(options, callable, ...args) {
|
|
977
|
-
if (options.signal) {
|
|
978
|
-
return Promise.race([
|
|
979
|
-
this.call(callable, ...args),
|
|
980
|
-
new Promise((_, reject) => {
|
|
981
|
-
options.signal?.addEventListener("abort", () => {
|
|
982
|
-
reject(new Error("AbortError"));
|
|
983
|
-
});
|
|
984
|
-
})
|
|
985
|
-
]);
|
|
986
|
-
}
|
|
987
|
-
return this.call(callable, ...args);
|
|
988
|
-
}
|
|
989
|
-
fetch(...args) {
|
|
990
|
-
return this.call(() => fetch(...args).then((res) => res.ok ? res : Promise.reject(res)));
|
|
991
|
-
}
|
|
992
|
-
};
|
|
993
|
-
|
|
994
|
-
// node_modules/@langchain/core/dist/embeddings.js
|
|
995
|
-
var Embeddings = class {
|
|
996
|
-
constructor(params) {
|
|
997
|
-
Object.defineProperty(this, "caller", {
|
|
998
|
-
enumerable: true,
|
|
999
|
-
configurable: true,
|
|
1000
|
-
writable: true,
|
|
1001
|
-
value: void 0
|
|
1002
|
-
});
|
|
1003
|
-
this.caller = new AsyncCaller(params ?? {});
|
|
1004
|
-
}
|
|
1005
|
-
};
|
|
1006
|
-
|
|
1007
|
-
// src/store/embeddings/FixedDimensionEmbeddings.ts
|
|
1008
|
-
var FixedDimensionEmbeddings = class extends Embeddings {
|
|
1009
|
-
constructor(embeddings, targetDimension, providerAndModel, allowTruncate = false) {
|
|
1010
|
-
super({});
|
|
1011
|
-
this.embeddings = embeddings;
|
|
1012
|
-
this.targetDimension = targetDimension;
|
|
1013
|
-
this.allowTruncate = allowTruncate;
|
|
1014
|
-
const [providerOrModel, modelName] = providerAndModel.split(":");
|
|
1015
|
-
this.provider = modelName ? providerOrModel : "openai";
|
|
1016
|
-
this.model = modelName || providerOrModel;
|
|
1017
|
-
}
|
|
1018
|
-
provider;
|
|
1019
|
-
model;
|
|
1020
|
-
/**
|
|
1021
|
-
* Normalize a vector to the target dimension by truncating (for MRL models) or padding.
|
|
1022
|
-
* @throws {DimensionError} If vector is too large and provider doesn't support MRL
|
|
1023
|
-
*/
|
|
1024
|
-
normalizeVector(vector) {
|
|
1025
|
-
const dimension = vector.length;
|
|
1026
|
-
if (dimension > this.targetDimension) {
|
|
1027
|
-
if (this.allowTruncate) {
|
|
1028
|
-
return vector.slice(0, this.targetDimension);
|
|
1029
|
-
}
|
|
1030
|
-
throw new DimensionError(
|
|
1031
|
-
`${this.provider}:${this.model}`,
|
|
1032
|
-
dimension,
|
|
1033
|
-
this.targetDimension
|
|
1034
|
-
);
|
|
1035
|
-
}
|
|
1036
|
-
if (dimension < this.targetDimension) {
|
|
1037
|
-
return [...vector, ...new Array(this.targetDimension - dimension).fill(0)];
|
|
1038
|
-
}
|
|
1039
|
-
return vector;
|
|
1040
|
-
}
|
|
1041
|
-
async embedQuery(text) {
|
|
1042
|
-
const vector = await this.embeddings.embedQuery(text);
|
|
1043
|
-
return this.normalizeVector(vector);
|
|
1044
|
-
}
|
|
1045
|
-
async embedDocuments(documents) {
|
|
1046
|
-
const vectors = await this.embeddings.embedDocuments(documents);
|
|
1047
|
-
return vectors.map((vector) => this.normalizeVector(vector));
|
|
1048
|
-
}
|
|
1049
|
-
};
|
|
1050
|
-
|
|
1051
|
-
// src/store/embeddings/EmbeddingFactory.ts
|
|
1052
|
-
var UnsupportedProviderError = class extends Error {
|
|
1053
|
-
constructor(provider) {
|
|
1054
|
-
super(`Unsupported embedding provider: ${provider}`);
|
|
1055
|
-
this.name = "UnsupportedProviderError";
|
|
1056
|
-
}
|
|
1057
|
-
};
|
|
1058
|
-
var ModelConfigurationError = class extends Error {
|
|
1059
|
-
constructor(message) {
|
|
1060
|
-
super(message);
|
|
1061
|
-
this.name = "ModelConfigurationError";
|
|
1062
|
-
}
|
|
1063
|
-
};
|
|
1064
|
-
function createEmbeddingModel(providerAndModel) {
|
|
1065
|
-
const [providerOrModel, modelName] = providerAndModel.split(":");
|
|
1066
|
-
const provider = modelName ? providerOrModel : "openai";
|
|
1067
|
-
const model = modelName || providerOrModel;
|
|
1068
|
-
const baseConfig = { stripNewLines: true };
|
|
1069
|
-
switch (provider) {
|
|
1070
|
-
case "openai": {
|
|
1071
|
-
const config = {
|
|
1072
|
-
...baseConfig,
|
|
1073
|
-
modelName: model,
|
|
1074
|
-
batchSize: 512
|
|
1075
|
-
// OpenAI supports large batches
|
|
1076
|
-
};
|
|
1077
|
-
const baseURL = process.env.OPENAI_API_BASE;
|
|
1078
|
-
if (baseURL) {
|
|
1079
|
-
config.configuration = { baseURL };
|
|
1080
|
-
}
|
|
1081
|
-
return new OpenAIEmbeddings(config);
|
|
1082
|
-
}
|
|
1083
|
-
case "vertex": {
|
|
1084
|
-
if (!process.env.GOOGLE_APPLICATION_CREDENTIALS) {
|
|
1085
|
-
throw new ModelConfigurationError(
|
|
1086
|
-
"GOOGLE_APPLICATION_CREDENTIALS environment variable is required for Google Cloud Vertex AI"
|
|
1087
|
-
);
|
|
1088
|
-
}
|
|
1089
|
-
return new VertexAIEmbeddings({
|
|
1090
|
-
...baseConfig,
|
|
1091
|
-
model
|
|
1092
|
-
// e.g., "text-embedding-004"
|
|
1093
|
-
});
|
|
1094
|
-
}
|
|
1095
|
-
case "gemini": {
|
|
1096
|
-
if (!process.env.GOOGLE_API_KEY) {
|
|
1097
|
-
throw new ModelConfigurationError(
|
|
1098
|
-
"GOOGLE_API_KEY environment variable is required for Google AI (Gemini)"
|
|
1099
|
-
);
|
|
1100
|
-
}
|
|
1101
|
-
const baseEmbeddings = new GoogleGenerativeAIEmbeddings({
|
|
1102
|
-
...baseConfig,
|
|
1103
|
-
apiKey: process.env.GOOGLE_API_KEY,
|
|
1104
|
-
model
|
|
1105
|
-
// e.g., "gemini-embedding-exp-03-07"
|
|
1106
|
-
});
|
|
1107
|
-
return new FixedDimensionEmbeddings(
|
|
1108
|
-
baseEmbeddings,
|
|
1109
|
-
VECTOR_DIMENSION,
|
|
1110
|
-
providerAndModel,
|
|
1111
|
-
true
|
|
1112
|
-
);
|
|
1113
|
-
}
|
|
1114
|
-
case "aws": {
|
|
1115
|
-
const region = process.env.BEDROCK_AWS_REGION || process.env.AWS_REGION;
|
|
1116
|
-
if (!region) {
|
|
1117
|
-
throw new ModelConfigurationError(
|
|
1118
|
-
"BEDROCK_AWS_REGION or AWS_REGION environment variable is required for AWS Bedrock"
|
|
1119
|
-
);
|
|
1120
|
-
}
|
|
1121
|
-
if (!process.env.AWS_ACCESS_KEY_ID || !process.env.AWS_SECRET_ACCESS_KEY) {
|
|
1122
|
-
throw new ModelConfigurationError(
|
|
1123
|
-
"AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables are required for AWS Bedrock"
|
|
1124
|
-
);
|
|
1125
|
-
}
|
|
1126
|
-
return new BedrockEmbeddings({
|
|
1127
|
-
...baseConfig,
|
|
1128
|
-
model,
|
|
1129
|
-
// e.g., "amazon.titan-embed-text-v1"
|
|
1130
|
-
region,
|
|
1131
|
-
credentials: {
|
|
1132
|
-
accessKeyId: process.env.AWS_ACCESS_KEY_ID,
|
|
1133
|
-
secretAccessKey: process.env.AWS_SECRET_ACCESS_KEY,
|
|
1134
|
-
sessionToken: process.env.AWS_SESSION_TOKEN
|
|
1135
|
-
}
|
|
1136
|
-
});
|
|
1137
|
-
}
|
|
1138
|
-
case "microsoft": {
|
|
1139
|
-
if (!process.env.AZURE_OPENAI_API_KEY) {
|
|
1140
|
-
throw new ModelConfigurationError(
|
|
1141
|
-
"AZURE_OPENAI_API_KEY environment variable is required for Azure OpenAI"
|
|
1142
|
-
);
|
|
1143
|
-
}
|
|
1144
|
-
if (!process.env.AZURE_OPENAI_API_INSTANCE_NAME) {
|
|
1145
|
-
throw new ModelConfigurationError(
|
|
1146
|
-
"AZURE_OPENAI_API_INSTANCE_NAME environment variable is required for Azure OpenAI"
|
|
1147
|
-
);
|
|
1148
|
-
}
|
|
1149
|
-
if (!process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME) {
|
|
1150
|
-
throw new ModelConfigurationError(
|
|
1151
|
-
"AZURE_OPENAI_API_DEPLOYMENT_NAME environment variable is required for Azure OpenAI"
|
|
1152
|
-
);
|
|
1153
|
-
}
|
|
1154
|
-
if (!process.env.AZURE_OPENAI_API_VERSION) {
|
|
1155
|
-
throw new ModelConfigurationError(
|
|
1156
|
-
"AZURE_OPENAI_API_VERSION environment variable is required for Azure OpenAI"
|
|
1157
|
-
);
|
|
1158
|
-
}
|
|
1159
|
-
return new AzureOpenAIEmbeddings({
|
|
1160
|
-
...baseConfig,
|
|
1161
|
-
azureOpenAIApiKey: process.env.AZURE_OPENAI_API_KEY,
|
|
1162
|
-
azureOpenAIApiInstanceName: process.env.AZURE_OPENAI_API_INSTANCE_NAME,
|
|
1163
|
-
azureOpenAIApiDeploymentName: process.env.AZURE_OPENAI_API_DEPLOYMENT_NAME,
|
|
1164
|
-
azureOpenAIApiVersion: process.env.AZURE_OPENAI_API_VERSION,
|
|
1165
|
-
deploymentName: model
|
|
1166
|
-
});
|
|
1167
|
-
}
|
|
1168
|
-
default:
|
|
1169
|
-
throw new UnsupportedProviderError(provider);
|
|
1170
|
-
}
|
|
1171
|
-
}
|
|
1172
|
-
export {
|
|
1173
|
-
ModelConfigurationError,
|
|
1174
|
-
UnsupportedProviderError,
|
|
1175
|
-
createEmbeddingModel
|
|
1176
|
-
};
|
|
1177
|
-
//# sourceMappingURL=EmbeddingFactory-6UEXNF44.js.map
|