@midscene/core 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/ai-model.js +4207 -5
- package/dist/es/image.js +26 -12
- package/dist/es/index.js +4190 -5
- package/dist/lib/ai-model.js +4223 -41
- package/dist/lib/image.js +33 -19
- package/dist/lib/index.js +4174 -9
- package/dist/types/image.d.ts +3 -4
- package/package.json +1 -1
package/dist/lib/index.js
CHANGED
|
@@ -9,6 +9,11 @@ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
|
9
9
|
var __getProtoOf = Object.getPrototypeOf;
|
|
10
10
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
11
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __knownSymbol = (name, symbol) => {
|
|
13
|
+
if (symbol = Symbol[name])
|
|
14
|
+
return symbol;
|
|
15
|
+
throw Error("Symbol." + name + " is not defined");
|
|
16
|
+
};
|
|
12
17
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
18
|
var __spreadValues = (a, b) => {
|
|
14
19
|
for (var prop in b || (b = {}))
|
|
@@ -22,6 +27,7 @@ var __spreadValues = (a, b) => {
|
|
|
22
27
|
return a;
|
|
23
28
|
};
|
|
24
29
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
30
|
+
var __restKey = (key) => typeof key === "symbol" ? key : key + "";
|
|
25
31
|
var __objRest = (source, exclude) => {
|
|
26
32
|
var target = {};
|
|
27
33
|
for (var prop in source)
|
|
@@ -34,6 +40,9 @@ var __objRest = (source, exclude) => {
|
|
|
34
40
|
}
|
|
35
41
|
return target;
|
|
36
42
|
};
|
|
43
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
44
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
45
|
+
};
|
|
37
46
|
var __export = (target, all) => {
|
|
38
47
|
for (var name in all)
|
|
39
48
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -59,6 +68,951 @@ var __publicField = (obj, key, value) => {
|
|
|
59
68
|
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
60
69
|
return value;
|
|
61
70
|
};
|
|
71
|
+
var __await = function(promise, isYieldStar) {
|
|
72
|
+
this[0] = promise;
|
|
73
|
+
this[1] = isYieldStar;
|
|
74
|
+
};
|
|
75
|
+
var __asyncGenerator = (__this, __arguments, generator) => {
|
|
76
|
+
var resume = (k, v, yes, no) => {
|
|
77
|
+
try {
|
|
78
|
+
var x = generator[k](v), isAwait = (v = x.value) instanceof __await, done = x.done;
|
|
79
|
+
Promise.resolve(isAwait ? v[0] : v).then((y) => isAwait ? resume(k === "return" ? k : "next", v[1] ? { done: y.done, value: y.value } : y, yes, no) : yes({ value: y, done })).catch((e) => resume("throw", e, yes, no));
|
|
80
|
+
} catch (e) {
|
|
81
|
+
no(e);
|
|
82
|
+
}
|
|
83
|
+
};
|
|
84
|
+
var method = (k) => it[k] = (x) => new Promise((yes, no) => resume(k, x, yes, no));
|
|
85
|
+
var it = {};
|
|
86
|
+
return generator = generator.apply(__this, __arguments), it[Symbol.asyncIterator] = () => it, method("next"), method("throw"), method("return"), it;
|
|
87
|
+
};
|
|
88
|
+
var __yieldStar = (value) => {
|
|
89
|
+
var obj = value[__knownSymbol("asyncIterator")];
|
|
90
|
+
var isAwait = false;
|
|
91
|
+
var method;
|
|
92
|
+
var it = {};
|
|
93
|
+
if (obj == null) {
|
|
94
|
+
obj = value[__knownSymbol("iterator")]();
|
|
95
|
+
method = (k) => it[k] = (x) => obj[k](x);
|
|
96
|
+
} else {
|
|
97
|
+
obj = obj.call(value);
|
|
98
|
+
method = (k) => it[k] = (v) => {
|
|
99
|
+
if (isAwait) {
|
|
100
|
+
isAwait = false;
|
|
101
|
+
if (k === "throw")
|
|
102
|
+
throw v;
|
|
103
|
+
return v;
|
|
104
|
+
}
|
|
105
|
+
isAwait = true;
|
|
106
|
+
return {
|
|
107
|
+
done: false,
|
|
108
|
+
value: new __await(new Promise((resolve) => {
|
|
109
|
+
var x = obj[k](v);
|
|
110
|
+
if (!(x instanceof Object))
|
|
111
|
+
throw TypeError("Object expected");
|
|
112
|
+
resolve(x);
|
|
113
|
+
}), 1)
|
|
114
|
+
};
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
return it[__knownSymbol("iterator")] = () => it, method("next"), "throw" in obj ? method("throw") : it.throw = (x) => {
|
|
118
|
+
throw x;
|
|
119
|
+
}, "return" in obj && method("return"), it;
|
|
120
|
+
};
|
|
121
|
+
var __forAwait = (obj, it, method) => (it = obj[__knownSymbol("asyncIterator")]) ? it.call(obj) : (obj = obj[__knownSymbol("iterator")](), it = {}, method = (key, fn) => (fn = obj[key]) && (it[key] = (arg) => new Promise((yes, no, done) => (arg = fn.call(obj, arg), done = arg.done, Promise.resolve(arg.value).then((value) => yes({ value, done }), no)))), method("next"), method("return"), it);
|
|
122
|
+
|
|
123
|
+
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js
|
|
124
|
+
var require_retry_operation = __commonJS({
|
|
125
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry_operation.js"(exports, module2) {
|
|
126
|
+
"use strict";
|
|
127
|
+
function RetryOperation(timeouts, options) {
|
|
128
|
+
if (typeof options === "boolean") {
|
|
129
|
+
options = { forever: options };
|
|
130
|
+
}
|
|
131
|
+
this._originalTimeouts = JSON.parse(JSON.stringify(timeouts));
|
|
132
|
+
this._timeouts = timeouts;
|
|
133
|
+
this._options = options || {};
|
|
134
|
+
this._maxRetryTime = options && options.maxRetryTime || Infinity;
|
|
135
|
+
this._fn = null;
|
|
136
|
+
this._errors = [];
|
|
137
|
+
this._attempts = 1;
|
|
138
|
+
this._operationTimeout = null;
|
|
139
|
+
this._operationTimeoutCb = null;
|
|
140
|
+
this._timeout = null;
|
|
141
|
+
this._operationStart = null;
|
|
142
|
+
this._timer = null;
|
|
143
|
+
if (this._options.forever) {
|
|
144
|
+
this._cachedTimeouts = this._timeouts.slice(0);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
module2.exports = RetryOperation;
|
|
148
|
+
RetryOperation.prototype.reset = function() {
|
|
149
|
+
this._attempts = 1;
|
|
150
|
+
this._timeouts = this._originalTimeouts.slice(0);
|
|
151
|
+
};
|
|
152
|
+
RetryOperation.prototype.stop = function() {
|
|
153
|
+
if (this._timeout) {
|
|
154
|
+
clearTimeout(this._timeout);
|
|
155
|
+
}
|
|
156
|
+
if (this._timer) {
|
|
157
|
+
clearTimeout(this._timer);
|
|
158
|
+
}
|
|
159
|
+
this._timeouts = [];
|
|
160
|
+
this._cachedTimeouts = null;
|
|
161
|
+
};
|
|
162
|
+
RetryOperation.prototype.retry = function(err) {
|
|
163
|
+
if (this._timeout) {
|
|
164
|
+
clearTimeout(this._timeout);
|
|
165
|
+
}
|
|
166
|
+
if (!err) {
|
|
167
|
+
return false;
|
|
168
|
+
}
|
|
169
|
+
var currentTime = (/* @__PURE__ */ new Date()).getTime();
|
|
170
|
+
if (err && currentTime - this._operationStart >= this._maxRetryTime) {
|
|
171
|
+
this._errors.push(err);
|
|
172
|
+
this._errors.unshift(new Error("RetryOperation timeout occurred"));
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
this._errors.push(err);
|
|
176
|
+
var timeout = this._timeouts.shift();
|
|
177
|
+
if (timeout === void 0) {
|
|
178
|
+
if (this._cachedTimeouts) {
|
|
179
|
+
this._errors.splice(0, this._errors.length - 1);
|
|
180
|
+
timeout = this._cachedTimeouts.slice(-1);
|
|
181
|
+
} else {
|
|
182
|
+
return false;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
var self = this;
|
|
186
|
+
this._timer = setTimeout(function() {
|
|
187
|
+
self._attempts++;
|
|
188
|
+
if (self._operationTimeoutCb) {
|
|
189
|
+
self._timeout = setTimeout(function() {
|
|
190
|
+
self._operationTimeoutCb(self._attempts);
|
|
191
|
+
}, self._operationTimeout);
|
|
192
|
+
if (self._options.unref) {
|
|
193
|
+
self._timeout.unref();
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
self._fn(self._attempts);
|
|
197
|
+
}, timeout);
|
|
198
|
+
if (this._options.unref) {
|
|
199
|
+
this._timer.unref();
|
|
200
|
+
}
|
|
201
|
+
return true;
|
|
202
|
+
};
|
|
203
|
+
RetryOperation.prototype.attempt = function(fn, timeoutOps) {
|
|
204
|
+
this._fn = fn;
|
|
205
|
+
if (timeoutOps) {
|
|
206
|
+
if (timeoutOps.timeout) {
|
|
207
|
+
this._operationTimeout = timeoutOps.timeout;
|
|
208
|
+
}
|
|
209
|
+
if (timeoutOps.cb) {
|
|
210
|
+
this._operationTimeoutCb = timeoutOps.cb;
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
var self = this;
|
|
214
|
+
if (this._operationTimeoutCb) {
|
|
215
|
+
this._timeout = setTimeout(function() {
|
|
216
|
+
self._operationTimeoutCb();
|
|
217
|
+
}, self._operationTimeout);
|
|
218
|
+
}
|
|
219
|
+
this._operationStart = (/* @__PURE__ */ new Date()).getTime();
|
|
220
|
+
this._fn(this._attempts);
|
|
221
|
+
};
|
|
222
|
+
RetryOperation.prototype.try = function(fn) {
|
|
223
|
+
console.log("Using RetryOperation.try() is deprecated");
|
|
224
|
+
this.attempt(fn);
|
|
225
|
+
};
|
|
226
|
+
RetryOperation.prototype.start = function(fn) {
|
|
227
|
+
console.log("Using RetryOperation.start() is deprecated");
|
|
228
|
+
this.attempt(fn);
|
|
229
|
+
};
|
|
230
|
+
RetryOperation.prototype.start = RetryOperation.prototype.try;
|
|
231
|
+
RetryOperation.prototype.errors = function() {
|
|
232
|
+
return this._errors;
|
|
233
|
+
};
|
|
234
|
+
RetryOperation.prototype.attempts = function() {
|
|
235
|
+
return this._attempts;
|
|
236
|
+
};
|
|
237
|
+
RetryOperation.prototype.mainError = function() {
|
|
238
|
+
if (this._errors.length === 0) {
|
|
239
|
+
return null;
|
|
240
|
+
}
|
|
241
|
+
var counts = {};
|
|
242
|
+
var mainError = null;
|
|
243
|
+
var mainErrorCount = 0;
|
|
244
|
+
for (var i = 0; i < this._errors.length; i++) {
|
|
245
|
+
var error = this._errors[i];
|
|
246
|
+
var message = error.message;
|
|
247
|
+
var count = (counts[message] || 0) + 1;
|
|
248
|
+
counts[message] = count;
|
|
249
|
+
if (count >= mainErrorCount) {
|
|
250
|
+
mainError = error;
|
|
251
|
+
mainErrorCount = count;
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
return mainError;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
});
|
|
258
|
+
|
|
259
|
+
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js
|
|
260
|
+
var require_retry = __commonJS({
|
|
261
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/lib/retry.js"(exports) {
|
|
262
|
+
"use strict";
|
|
263
|
+
var RetryOperation = require_retry_operation();
|
|
264
|
+
exports.operation = function(options) {
|
|
265
|
+
var timeouts = exports.timeouts(options);
|
|
266
|
+
return new RetryOperation(timeouts, {
|
|
267
|
+
forever: options && (options.forever || options.retries === Infinity),
|
|
268
|
+
unref: options && options.unref,
|
|
269
|
+
maxRetryTime: options && options.maxRetryTime
|
|
270
|
+
});
|
|
271
|
+
};
|
|
272
|
+
exports.timeouts = function(options) {
|
|
273
|
+
if (options instanceof Array) {
|
|
274
|
+
return [].concat(options);
|
|
275
|
+
}
|
|
276
|
+
var opts = {
|
|
277
|
+
retries: 10,
|
|
278
|
+
factor: 2,
|
|
279
|
+
minTimeout: 1 * 1e3,
|
|
280
|
+
maxTimeout: Infinity,
|
|
281
|
+
randomize: false
|
|
282
|
+
};
|
|
283
|
+
for (var key in options) {
|
|
284
|
+
opts[key] = options[key];
|
|
285
|
+
}
|
|
286
|
+
if (opts.minTimeout > opts.maxTimeout) {
|
|
287
|
+
throw new Error("minTimeout is greater than maxTimeout");
|
|
288
|
+
}
|
|
289
|
+
var timeouts = [];
|
|
290
|
+
for (var i = 0; i < opts.retries; i++) {
|
|
291
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
292
|
+
}
|
|
293
|
+
if (options && options.forever && !timeouts.length) {
|
|
294
|
+
timeouts.push(this.createTimeout(i, opts));
|
|
295
|
+
}
|
|
296
|
+
timeouts.sort(function(a, b) {
|
|
297
|
+
return a - b;
|
|
298
|
+
});
|
|
299
|
+
return timeouts;
|
|
300
|
+
};
|
|
301
|
+
exports.createTimeout = function(attempt, opts) {
|
|
302
|
+
var random = opts.randomize ? Math.random() + 1 : 1;
|
|
303
|
+
var timeout = Math.round(random * Math.max(opts.minTimeout, 1) * Math.pow(opts.factor, attempt));
|
|
304
|
+
timeout = Math.min(timeout, opts.maxTimeout);
|
|
305
|
+
return timeout;
|
|
306
|
+
};
|
|
307
|
+
exports.wrap = function(obj, options, methods) {
|
|
308
|
+
if (options instanceof Array) {
|
|
309
|
+
methods = options;
|
|
310
|
+
options = null;
|
|
311
|
+
}
|
|
312
|
+
if (!methods) {
|
|
313
|
+
methods = [];
|
|
314
|
+
for (var key in obj) {
|
|
315
|
+
if (typeof obj[key] === "function") {
|
|
316
|
+
methods.push(key);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
for (var i = 0; i < methods.length; i++) {
|
|
321
|
+
var method = methods[i];
|
|
322
|
+
var original = obj[method];
|
|
323
|
+
obj[method] = function retryWrapper(original2) {
|
|
324
|
+
var op = exports.operation(options);
|
|
325
|
+
var args = Array.prototype.slice.call(arguments, 1);
|
|
326
|
+
var callback = args.pop();
|
|
327
|
+
args.push(function(err) {
|
|
328
|
+
if (op.retry(err)) {
|
|
329
|
+
return;
|
|
330
|
+
}
|
|
331
|
+
if (err) {
|
|
332
|
+
arguments[0] = op.mainError();
|
|
333
|
+
}
|
|
334
|
+
callback.apply(this, arguments);
|
|
335
|
+
});
|
|
336
|
+
op.attempt(function() {
|
|
337
|
+
original2.apply(obj, args);
|
|
338
|
+
});
|
|
339
|
+
}.bind(obj, original);
|
|
340
|
+
obj[method].options = options;
|
|
341
|
+
}
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
});
|
|
345
|
+
|
|
346
|
+
// ../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js
|
|
347
|
+
var require_retry2 = __commonJS({
|
|
348
|
+
"../../node_modules/.pnpm/retry@0.13.1/node_modules/retry/index.js"(exports, module2) {
|
|
349
|
+
"use strict";
|
|
350
|
+
module2.exports = require_retry();
|
|
351
|
+
}
|
|
352
|
+
});
|
|
353
|
+
|
|
354
|
+
// ../../node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js
|
|
355
|
+
var require_p_retry = __commonJS({
|
|
356
|
+
"../../node_modules/.pnpm/p-retry@4.6.2/node_modules/p-retry/index.js"(exports, module2) {
|
|
357
|
+
"use strict";
|
|
358
|
+
var retry = require_retry2();
|
|
359
|
+
var networkErrorMsgs = [
|
|
360
|
+
"Failed to fetch",
|
|
361
|
+
// Chrome
|
|
362
|
+
"NetworkError when attempting to fetch resource.",
|
|
363
|
+
// Firefox
|
|
364
|
+
"The Internet connection appears to be offline.",
|
|
365
|
+
// Safari
|
|
366
|
+
"Network request failed"
|
|
367
|
+
// `cross-fetch`
|
|
368
|
+
];
|
|
369
|
+
var AbortError = class extends Error {
|
|
370
|
+
constructor(message) {
|
|
371
|
+
super();
|
|
372
|
+
if (message instanceof Error) {
|
|
373
|
+
this.originalError = message;
|
|
374
|
+
({ message } = message);
|
|
375
|
+
} else {
|
|
376
|
+
this.originalError = new Error(message);
|
|
377
|
+
this.originalError.stack = this.stack;
|
|
378
|
+
}
|
|
379
|
+
this.name = "AbortError";
|
|
380
|
+
this.message = message;
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
var decorateErrorWithCounts = (error, attemptNumber, options) => {
|
|
384
|
+
const retriesLeft = options.retries - (attemptNumber - 1);
|
|
385
|
+
error.attemptNumber = attemptNumber;
|
|
386
|
+
error.retriesLeft = retriesLeft;
|
|
387
|
+
return error;
|
|
388
|
+
};
|
|
389
|
+
var isNetworkError = (errorMessage) => networkErrorMsgs.includes(errorMessage);
|
|
390
|
+
var pRetry2 = (input, options) => new Promise((resolve, reject) => {
|
|
391
|
+
options = __spreadValues({
|
|
392
|
+
onFailedAttempt: () => {
|
|
393
|
+
},
|
|
394
|
+
retries: 10
|
|
395
|
+
}, options);
|
|
396
|
+
const operation = retry.operation(options);
|
|
397
|
+
operation.attempt(async (attemptNumber) => {
|
|
398
|
+
try {
|
|
399
|
+
resolve(await input(attemptNumber));
|
|
400
|
+
} catch (error) {
|
|
401
|
+
if (!(error instanceof Error)) {
|
|
402
|
+
reject(new TypeError(`Non-error was thrown: "${error}". You should only throw errors.`));
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
if (error instanceof AbortError) {
|
|
406
|
+
operation.stop();
|
|
407
|
+
reject(error.originalError);
|
|
408
|
+
} else if (error instanceof TypeError && !isNetworkError(error.message)) {
|
|
409
|
+
operation.stop();
|
|
410
|
+
reject(error);
|
|
411
|
+
} else {
|
|
412
|
+
decorateErrorWithCounts(error, attemptNumber, options);
|
|
413
|
+
try {
|
|
414
|
+
await options.onFailedAttempt(error);
|
|
415
|
+
} catch (error2) {
|
|
416
|
+
reject(error2);
|
|
417
|
+
return;
|
|
418
|
+
}
|
|
419
|
+
if (!operation.retry(error)) {
|
|
420
|
+
reject(operation.mainError());
|
|
421
|
+
}
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
});
|
|
425
|
+
});
|
|
426
|
+
module2.exports = pRetry2;
|
|
427
|
+
module2.exports.default = pRetry2;
|
|
428
|
+
module2.exports.AbortError = AbortError;
|
|
429
|
+
}
|
|
430
|
+
});
|
|
431
|
+
|
|
432
|
+
// ../../node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js
|
|
433
|
+
var require_eventemitter3 = __commonJS({
|
|
434
|
+
"../../node_modules/.pnpm/eventemitter3@4.0.7/node_modules/eventemitter3/index.js"(exports, module2) {
|
|
435
|
+
"use strict";
|
|
436
|
+
var has = Object.prototype.hasOwnProperty;
|
|
437
|
+
var prefix = "~";
|
|
438
|
+
function Events() {
|
|
439
|
+
}
|
|
440
|
+
if (Object.create) {
|
|
441
|
+
Events.prototype = /* @__PURE__ */ Object.create(null);
|
|
442
|
+
if (!new Events().__proto__)
|
|
443
|
+
prefix = false;
|
|
444
|
+
}
|
|
445
|
+
function EE(fn, context, once) {
|
|
446
|
+
this.fn = fn;
|
|
447
|
+
this.context = context;
|
|
448
|
+
this.once = once || false;
|
|
449
|
+
}
|
|
450
|
+
function addListener(emitter, event, fn, context, once) {
|
|
451
|
+
if (typeof fn !== "function") {
|
|
452
|
+
throw new TypeError("The listener must be a function");
|
|
453
|
+
}
|
|
454
|
+
var listener = new EE(fn, context || emitter, once), evt = prefix ? prefix + event : event;
|
|
455
|
+
if (!emitter._events[evt])
|
|
456
|
+
emitter._events[evt] = listener, emitter._eventsCount++;
|
|
457
|
+
else if (!emitter._events[evt].fn)
|
|
458
|
+
emitter._events[evt].push(listener);
|
|
459
|
+
else
|
|
460
|
+
emitter._events[evt] = [emitter._events[evt], listener];
|
|
461
|
+
return emitter;
|
|
462
|
+
}
|
|
463
|
+
function clearEvent(emitter, evt) {
|
|
464
|
+
if (--emitter._eventsCount === 0)
|
|
465
|
+
emitter._events = new Events();
|
|
466
|
+
else
|
|
467
|
+
delete emitter._events[evt];
|
|
468
|
+
}
|
|
469
|
+
function EventEmitter() {
|
|
470
|
+
this._events = new Events();
|
|
471
|
+
this._eventsCount = 0;
|
|
472
|
+
}
|
|
473
|
+
EventEmitter.prototype.eventNames = function eventNames() {
|
|
474
|
+
var names = [], events, name;
|
|
475
|
+
if (this._eventsCount === 0)
|
|
476
|
+
return names;
|
|
477
|
+
for (name in events = this._events) {
|
|
478
|
+
if (has.call(events, name))
|
|
479
|
+
names.push(prefix ? name.slice(1) : name);
|
|
480
|
+
}
|
|
481
|
+
if (Object.getOwnPropertySymbols) {
|
|
482
|
+
return names.concat(Object.getOwnPropertySymbols(events));
|
|
483
|
+
}
|
|
484
|
+
return names;
|
|
485
|
+
};
|
|
486
|
+
EventEmitter.prototype.listeners = function listeners(event) {
|
|
487
|
+
var evt = prefix ? prefix + event : event, handlers = this._events[evt];
|
|
488
|
+
if (!handlers)
|
|
489
|
+
return [];
|
|
490
|
+
if (handlers.fn)
|
|
491
|
+
return [handlers.fn];
|
|
492
|
+
for (var i = 0, l = handlers.length, ee = new Array(l); i < l; i++) {
|
|
493
|
+
ee[i] = handlers[i].fn;
|
|
494
|
+
}
|
|
495
|
+
return ee;
|
|
496
|
+
};
|
|
497
|
+
EventEmitter.prototype.listenerCount = function listenerCount(event) {
|
|
498
|
+
var evt = prefix ? prefix + event : event, listeners = this._events[evt];
|
|
499
|
+
if (!listeners)
|
|
500
|
+
return 0;
|
|
501
|
+
if (listeners.fn)
|
|
502
|
+
return 1;
|
|
503
|
+
return listeners.length;
|
|
504
|
+
};
|
|
505
|
+
EventEmitter.prototype.emit = function emit(event, a1, a2, a3, a4, a5) {
|
|
506
|
+
var evt = prefix ? prefix + event : event;
|
|
507
|
+
if (!this._events[evt])
|
|
508
|
+
return false;
|
|
509
|
+
var listeners = this._events[evt], len = arguments.length, args, i;
|
|
510
|
+
if (listeners.fn) {
|
|
511
|
+
if (listeners.once)
|
|
512
|
+
this.removeListener(event, listeners.fn, void 0, true);
|
|
513
|
+
switch (len) {
|
|
514
|
+
case 1:
|
|
515
|
+
return listeners.fn.call(listeners.context), true;
|
|
516
|
+
case 2:
|
|
517
|
+
return listeners.fn.call(listeners.context, a1), true;
|
|
518
|
+
case 3:
|
|
519
|
+
return listeners.fn.call(listeners.context, a1, a2), true;
|
|
520
|
+
case 4:
|
|
521
|
+
return listeners.fn.call(listeners.context, a1, a2, a3), true;
|
|
522
|
+
case 5:
|
|
523
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4), true;
|
|
524
|
+
case 6:
|
|
525
|
+
return listeners.fn.call(listeners.context, a1, a2, a3, a4, a5), true;
|
|
526
|
+
}
|
|
527
|
+
for (i = 1, args = new Array(len - 1); i < len; i++) {
|
|
528
|
+
args[i - 1] = arguments[i];
|
|
529
|
+
}
|
|
530
|
+
listeners.fn.apply(listeners.context, args);
|
|
531
|
+
} else {
|
|
532
|
+
var length = listeners.length, j;
|
|
533
|
+
for (i = 0; i < length; i++) {
|
|
534
|
+
if (listeners[i].once)
|
|
535
|
+
this.removeListener(event, listeners[i].fn, void 0, true);
|
|
536
|
+
switch (len) {
|
|
537
|
+
case 1:
|
|
538
|
+
listeners[i].fn.call(listeners[i].context);
|
|
539
|
+
break;
|
|
540
|
+
case 2:
|
|
541
|
+
listeners[i].fn.call(listeners[i].context, a1);
|
|
542
|
+
break;
|
|
543
|
+
case 3:
|
|
544
|
+
listeners[i].fn.call(listeners[i].context, a1, a2);
|
|
545
|
+
break;
|
|
546
|
+
case 4:
|
|
547
|
+
listeners[i].fn.call(listeners[i].context, a1, a2, a3);
|
|
548
|
+
break;
|
|
549
|
+
default:
|
|
550
|
+
if (!args)
|
|
551
|
+
for (j = 1, args = new Array(len - 1); j < len; j++) {
|
|
552
|
+
args[j - 1] = arguments[j];
|
|
553
|
+
}
|
|
554
|
+
listeners[i].fn.apply(listeners[i].context, args);
|
|
555
|
+
}
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
return true;
|
|
559
|
+
};
|
|
560
|
+
EventEmitter.prototype.on = function on(event, fn, context) {
|
|
561
|
+
return addListener(this, event, fn, context, false);
|
|
562
|
+
};
|
|
563
|
+
EventEmitter.prototype.once = function once(event, fn, context) {
|
|
564
|
+
return addListener(this, event, fn, context, true);
|
|
565
|
+
};
|
|
566
|
+
EventEmitter.prototype.removeListener = function removeListener(event, fn, context, once) {
|
|
567
|
+
var evt = prefix ? prefix + event : event;
|
|
568
|
+
if (!this._events[evt])
|
|
569
|
+
return this;
|
|
570
|
+
if (!fn) {
|
|
571
|
+
clearEvent(this, evt);
|
|
572
|
+
return this;
|
|
573
|
+
}
|
|
574
|
+
var listeners = this._events[evt];
|
|
575
|
+
if (listeners.fn) {
|
|
576
|
+
if (listeners.fn === fn && (!once || listeners.once) && (!context || listeners.context === context)) {
|
|
577
|
+
clearEvent(this, evt);
|
|
578
|
+
}
|
|
579
|
+
} else {
|
|
580
|
+
for (var i = 0, events = [], length = listeners.length; i < length; i++) {
|
|
581
|
+
if (listeners[i].fn !== fn || once && !listeners[i].once || context && listeners[i].context !== context) {
|
|
582
|
+
events.push(listeners[i]);
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
if (events.length)
|
|
586
|
+
this._events[evt] = events.length === 1 ? events[0] : events;
|
|
587
|
+
else
|
|
588
|
+
clearEvent(this, evt);
|
|
589
|
+
}
|
|
590
|
+
return this;
|
|
591
|
+
};
|
|
592
|
+
EventEmitter.prototype.removeAllListeners = function removeAllListeners(event) {
|
|
593
|
+
var evt;
|
|
594
|
+
if (event) {
|
|
595
|
+
evt = prefix ? prefix + event : event;
|
|
596
|
+
if (this._events[evt])
|
|
597
|
+
clearEvent(this, evt);
|
|
598
|
+
} else {
|
|
599
|
+
this._events = new Events();
|
|
600
|
+
this._eventsCount = 0;
|
|
601
|
+
}
|
|
602
|
+
return this;
|
|
603
|
+
};
|
|
604
|
+
EventEmitter.prototype.off = EventEmitter.prototype.removeListener;
|
|
605
|
+
EventEmitter.prototype.addListener = EventEmitter.prototype.on;
|
|
606
|
+
EventEmitter.prefixed = prefix;
|
|
607
|
+
EventEmitter.EventEmitter = EventEmitter;
|
|
608
|
+
if ("undefined" !== typeof module2) {
|
|
609
|
+
module2.exports = EventEmitter;
|
|
610
|
+
}
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
|
|
614
|
+
// ../../node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.js
|
|
615
|
+
var require_p_finally = __commonJS({
|
|
616
|
+
"../../node_modules/.pnpm/p-finally@1.0.0/node_modules/p-finally/index.js"(exports, module2) {
|
|
617
|
+
"use strict";
|
|
618
|
+
module2.exports = (promise, onFinally) => {
|
|
619
|
+
onFinally = onFinally || (() => {
|
|
620
|
+
});
|
|
621
|
+
return promise.then(
|
|
622
|
+
(val) => new Promise((resolve) => {
|
|
623
|
+
resolve(onFinally());
|
|
624
|
+
}).then(() => val),
|
|
625
|
+
(err) => new Promise((resolve) => {
|
|
626
|
+
resolve(onFinally());
|
|
627
|
+
}).then(() => {
|
|
628
|
+
throw err;
|
|
629
|
+
})
|
|
630
|
+
);
|
|
631
|
+
};
|
|
632
|
+
}
|
|
633
|
+
});
|
|
634
|
+
|
|
635
|
+
// ../../node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.js
|
|
636
|
+
var require_p_timeout = __commonJS({
|
|
637
|
+
"../../node_modules/.pnpm/p-timeout@3.2.0/node_modules/p-timeout/index.js"(exports, module2) {
|
|
638
|
+
"use strict";
|
|
639
|
+
var pFinally = require_p_finally();
|
|
640
|
+
var TimeoutError = class extends Error {
|
|
641
|
+
constructor(message) {
|
|
642
|
+
super(message);
|
|
643
|
+
this.name = "TimeoutError";
|
|
644
|
+
}
|
|
645
|
+
};
|
|
646
|
+
var pTimeout = (promise, milliseconds, fallback) => new Promise((resolve, reject) => {
|
|
647
|
+
if (typeof milliseconds !== "number" || milliseconds < 0) {
|
|
648
|
+
throw new TypeError("Expected `milliseconds` to be a positive number");
|
|
649
|
+
}
|
|
650
|
+
if (milliseconds === Infinity) {
|
|
651
|
+
resolve(promise);
|
|
652
|
+
return;
|
|
653
|
+
}
|
|
654
|
+
const timer = setTimeout(() => {
|
|
655
|
+
if (typeof fallback === "function") {
|
|
656
|
+
try {
|
|
657
|
+
resolve(fallback());
|
|
658
|
+
} catch (error) {
|
|
659
|
+
reject(error);
|
|
660
|
+
}
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
const message = typeof fallback === "string" ? fallback : `Promise timed out after ${milliseconds} milliseconds`;
|
|
664
|
+
const timeoutError = fallback instanceof Error ? fallback : new TimeoutError(message);
|
|
665
|
+
if (typeof promise.cancel === "function") {
|
|
666
|
+
promise.cancel();
|
|
667
|
+
}
|
|
668
|
+
reject(timeoutError);
|
|
669
|
+
}, milliseconds);
|
|
670
|
+
pFinally(
|
|
671
|
+
// eslint-disable-next-line promise/prefer-await-to-then
|
|
672
|
+
promise.then(resolve, reject),
|
|
673
|
+
() => {
|
|
674
|
+
clearTimeout(timer);
|
|
675
|
+
}
|
|
676
|
+
);
|
|
677
|
+
});
|
|
678
|
+
module2.exports = pTimeout;
|
|
679
|
+
module2.exports.default = pTimeout;
|
|
680
|
+
module2.exports.TimeoutError = TimeoutError;
|
|
681
|
+
}
|
|
682
|
+
});
|
|
683
|
+
|
|
684
|
+
// ../../node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.js
|
|
685
|
+
var require_lower_bound = __commonJS({
|
|
686
|
+
"../../node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/lower-bound.js"(exports) {
|
|
687
|
+
"use strict";
|
|
688
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
689
|
+
function lowerBound(array, value, comparator) {
|
|
690
|
+
let first = 0;
|
|
691
|
+
let count = array.length;
|
|
692
|
+
while (count > 0) {
|
|
693
|
+
const step = count / 2 | 0;
|
|
694
|
+
let it = first + step;
|
|
695
|
+
if (comparator(array[it], value) <= 0) {
|
|
696
|
+
first = ++it;
|
|
697
|
+
count -= step + 1;
|
|
698
|
+
} else {
|
|
699
|
+
count = step;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
return first;
|
|
703
|
+
}
|
|
704
|
+
exports.default = lowerBound;
|
|
705
|
+
}
|
|
706
|
+
});
|
|
707
|
+
|
|
708
|
+
// ../../node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.js
|
|
709
|
+
var require_priority_queue = __commonJS({
|
|
710
|
+
"../../node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/priority-queue.js"(exports) {
|
|
711
|
+
"use strict";
|
|
712
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
713
|
+
var lower_bound_1 = require_lower_bound();
|
|
714
|
+
var PriorityQueue = class {
|
|
715
|
+
constructor() {
|
|
716
|
+
this._queue = [];
|
|
717
|
+
}
|
|
718
|
+
enqueue(run, options) {
|
|
719
|
+
options = Object.assign({ priority: 0 }, options);
|
|
720
|
+
const element = {
|
|
721
|
+
priority: options.priority,
|
|
722
|
+
run
|
|
723
|
+
};
|
|
724
|
+
if (this.size && this._queue[this.size - 1].priority >= options.priority) {
|
|
725
|
+
this._queue.push(element);
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
const index = lower_bound_1.default(this._queue, element, (a, b) => b.priority - a.priority);
|
|
729
|
+
this._queue.splice(index, 0, element);
|
|
730
|
+
}
|
|
731
|
+
dequeue() {
|
|
732
|
+
const item = this._queue.shift();
|
|
733
|
+
return item === null || item === void 0 ? void 0 : item.run;
|
|
734
|
+
}
|
|
735
|
+
filter(options) {
|
|
736
|
+
return this._queue.filter((element) => element.priority === options.priority).map((element) => element.run);
|
|
737
|
+
}
|
|
738
|
+
get size() {
|
|
739
|
+
return this._queue.length;
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
exports.default = PriorityQueue;
|
|
743
|
+
}
|
|
744
|
+
});
|
|
745
|
+
|
|
746
|
+
// ../../node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js
|
|
747
|
+
var require_dist = __commonJS({
|
|
748
|
+
"../../node_modules/.pnpm/p-queue@6.6.2/node_modules/p-queue/dist/index.js"(exports) {
|
|
749
|
+
"use strict";
|
|
750
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
751
|
+
var EventEmitter = require_eventemitter3();
|
|
752
|
+
var p_timeout_1 = require_p_timeout();
|
|
753
|
+
var priority_queue_1 = require_priority_queue();
|
|
754
|
+
var empty = () => {
|
|
755
|
+
};
|
|
756
|
+
var timeoutError = new p_timeout_1.TimeoutError();
|
|
757
|
+
var PQueue = class extends EventEmitter {
|
|
758
|
+
constructor(options) {
|
|
759
|
+
var _a, _b, _c, _d;
|
|
760
|
+
super();
|
|
761
|
+
this._intervalCount = 0;
|
|
762
|
+
this._intervalEnd = 0;
|
|
763
|
+
this._pendingCount = 0;
|
|
764
|
+
this._resolveEmpty = empty;
|
|
765
|
+
this._resolveIdle = empty;
|
|
766
|
+
options = Object.assign({ carryoverConcurrencyCount: false, intervalCap: Infinity, interval: 0, concurrency: Infinity, autoStart: true, queueClass: priority_queue_1.default }, options);
|
|
767
|
+
if (!(typeof options.intervalCap === "number" && options.intervalCap >= 1)) {
|
|
768
|
+
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})`);
|
|
769
|
+
}
|
|
770
|
+
if (options.interval === void 0 || !(Number.isFinite(options.interval) && options.interval >= 0)) {
|
|
771
|
+
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})`);
|
|
772
|
+
}
|
|
773
|
+
this._carryoverConcurrencyCount = options.carryoverConcurrencyCount;
|
|
774
|
+
this._isIntervalIgnored = options.intervalCap === Infinity || options.interval === 0;
|
|
775
|
+
this._intervalCap = options.intervalCap;
|
|
776
|
+
this._interval = options.interval;
|
|
777
|
+
this._queue = new options.queueClass();
|
|
778
|
+
this._queueClass = options.queueClass;
|
|
779
|
+
this.concurrency = options.concurrency;
|
|
780
|
+
this._timeout = options.timeout;
|
|
781
|
+
this._throwOnTimeout = options.throwOnTimeout === true;
|
|
782
|
+
this._isPaused = options.autoStart === false;
|
|
783
|
+
}
|
|
784
|
+
get _doesIntervalAllowAnother() {
|
|
785
|
+
return this._isIntervalIgnored || this._intervalCount < this._intervalCap;
|
|
786
|
+
}
|
|
787
|
+
get _doesConcurrentAllowAnother() {
|
|
788
|
+
return this._pendingCount < this._concurrency;
|
|
789
|
+
}
|
|
790
|
+
_next() {
|
|
791
|
+
this._pendingCount--;
|
|
792
|
+
this._tryToStartAnother();
|
|
793
|
+
this.emit("next");
|
|
794
|
+
}
|
|
795
|
+
_resolvePromises() {
|
|
796
|
+
this._resolveEmpty();
|
|
797
|
+
this._resolveEmpty = empty;
|
|
798
|
+
if (this._pendingCount === 0) {
|
|
799
|
+
this._resolveIdle();
|
|
800
|
+
this._resolveIdle = empty;
|
|
801
|
+
this.emit("idle");
|
|
802
|
+
}
|
|
803
|
+
}
|
|
804
|
+
_onResumeInterval() {
|
|
805
|
+
this._onInterval();
|
|
806
|
+
this._initializeIntervalIfNeeded();
|
|
807
|
+
this._timeoutId = void 0;
|
|
808
|
+
}
|
|
809
|
+
_isIntervalPaused() {
|
|
810
|
+
const now = Date.now();
|
|
811
|
+
if (this._intervalId === void 0) {
|
|
812
|
+
const delay = this._intervalEnd - now;
|
|
813
|
+
if (delay < 0) {
|
|
814
|
+
this._intervalCount = this._carryoverConcurrencyCount ? this._pendingCount : 0;
|
|
815
|
+
} else {
|
|
816
|
+
if (this._timeoutId === void 0) {
|
|
817
|
+
this._timeoutId = setTimeout(() => {
|
|
818
|
+
this._onResumeInterval();
|
|
819
|
+
}, delay);
|
|
820
|
+
}
|
|
821
|
+
return true;
|
|
822
|
+
}
|
|
823
|
+
}
|
|
824
|
+
return false;
|
|
825
|
+
}
|
|
826
|
+
_tryToStartAnother() {
|
|
827
|
+
if (this._queue.size === 0) {
|
|
828
|
+
if (this._intervalId) {
|
|
829
|
+
clearInterval(this._intervalId);
|
|
830
|
+
}
|
|
831
|
+
this._intervalId = void 0;
|
|
832
|
+
this._resolvePromises();
|
|
833
|
+
return false;
|
|
834
|
+
}
|
|
835
|
+
if (!this._isPaused) {
|
|
836
|
+
const canInitializeInterval = !this._isIntervalPaused();
|
|
837
|
+
if (this._doesIntervalAllowAnother && this._doesConcurrentAllowAnother) {
|
|
838
|
+
const job = this._queue.dequeue();
|
|
839
|
+
if (!job) {
|
|
840
|
+
return false;
|
|
841
|
+
}
|
|
842
|
+
this.emit("active");
|
|
843
|
+
job();
|
|
844
|
+
if (canInitializeInterval) {
|
|
845
|
+
this._initializeIntervalIfNeeded();
|
|
846
|
+
}
|
|
847
|
+
return true;
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
return false;
|
|
851
|
+
}
|
|
852
|
+
_initializeIntervalIfNeeded() {
|
|
853
|
+
if (this._isIntervalIgnored || this._intervalId !== void 0) {
|
|
854
|
+
return;
|
|
855
|
+
}
|
|
856
|
+
this._intervalId = setInterval(() => {
|
|
857
|
+
this._onInterval();
|
|
858
|
+
}, this._interval);
|
|
859
|
+
this._intervalEnd = Date.now() + this._interval;
|
|
860
|
+
}
|
|
861
|
+
_onInterval() {
|
|
862
|
+
if (this._intervalCount === 0 && this._pendingCount === 0 && this._intervalId) {
|
|
863
|
+
clearInterval(this._intervalId);
|
|
864
|
+
this._intervalId = void 0;
|
|
865
|
+
}
|
|
866
|
+
this._intervalCount = this._carryoverConcurrencyCount ? this._pendingCount : 0;
|
|
867
|
+
this._processQueue();
|
|
868
|
+
}
|
|
869
|
+
/**
|
|
870
|
+
Executes all queued functions until it reaches the limit.
|
|
871
|
+
*/
|
|
872
|
+
_processQueue() {
|
|
873
|
+
while (this._tryToStartAnother()) {
|
|
874
|
+
}
|
|
875
|
+
}
|
|
876
|
+
get concurrency() {
|
|
877
|
+
return this._concurrency;
|
|
878
|
+
}
|
|
879
|
+
set concurrency(newConcurrency) {
|
|
880
|
+
if (!(typeof newConcurrency === "number" && newConcurrency >= 1)) {
|
|
881
|
+
throw new TypeError(`Expected \`concurrency\` to be a number from 1 and up, got \`${newConcurrency}\` (${typeof newConcurrency})`);
|
|
882
|
+
}
|
|
883
|
+
this._concurrency = newConcurrency;
|
|
884
|
+
this._processQueue();
|
|
885
|
+
}
|
|
886
|
+
/**
|
|
887
|
+
Adds a sync or async task to the queue. Always returns a promise.
|
|
888
|
+
*/
|
|
889
|
+
async add(fn, options = {}) {
|
|
890
|
+
return new Promise((resolve, reject) => {
|
|
891
|
+
const run = async () => {
|
|
892
|
+
this._pendingCount++;
|
|
893
|
+
this._intervalCount++;
|
|
894
|
+
try {
|
|
895
|
+
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, () => {
|
|
896
|
+
if (options.throwOnTimeout === void 0 ? this._throwOnTimeout : options.throwOnTimeout) {
|
|
897
|
+
reject(timeoutError);
|
|
898
|
+
}
|
|
899
|
+
return void 0;
|
|
900
|
+
});
|
|
901
|
+
resolve(await operation);
|
|
902
|
+
} catch (error) {
|
|
903
|
+
reject(error);
|
|
904
|
+
}
|
|
905
|
+
this._next();
|
|
906
|
+
};
|
|
907
|
+
this._queue.enqueue(run, options);
|
|
908
|
+
this._tryToStartAnother();
|
|
909
|
+
this.emit("add");
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
/**
|
|
913
|
+
Same as `.add()`, but accepts an array of sync or async functions.
|
|
914
|
+
|
|
915
|
+
@returns A promise that resolves when all functions are resolved.
|
|
916
|
+
*/
|
|
917
|
+
async addAll(functions, options) {
|
|
918
|
+
return Promise.all(functions.map(async (function_) => this.add(function_, options)));
|
|
919
|
+
}
|
|
920
|
+
/**
|
|
921
|
+
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.)
|
|
922
|
+
*/
|
|
923
|
+
start() {
|
|
924
|
+
if (!this._isPaused) {
|
|
925
|
+
return this;
|
|
926
|
+
}
|
|
927
|
+
this._isPaused = false;
|
|
928
|
+
this._processQueue();
|
|
929
|
+
return this;
|
|
930
|
+
}
|
|
931
|
+
/**
|
|
932
|
+
Put queue execution on hold.
|
|
933
|
+
*/
|
|
934
|
+
pause() {
|
|
935
|
+
this._isPaused = true;
|
|
936
|
+
}
|
|
937
|
+
/**
|
|
938
|
+
Clear the queue.
|
|
939
|
+
*/
|
|
940
|
+
clear() {
|
|
941
|
+
this._queue = new this._queueClass();
|
|
942
|
+
}
|
|
943
|
+
/**
|
|
944
|
+
Can be called multiple times. Useful if you for example add additional items at a later time.
|
|
945
|
+
|
|
946
|
+
@returns A promise that settles when the queue becomes empty.
|
|
947
|
+
*/
|
|
948
|
+
async onEmpty() {
|
|
949
|
+
if (this._queue.size === 0) {
|
|
950
|
+
return;
|
|
951
|
+
}
|
|
952
|
+
return new Promise((resolve) => {
|
|
953
|
+
const existingResolve = this._resolveEmpty;
|
|
954
|
+
this._resolveEmpty = () => {
|
|
955
|
+
existingResolve();
|
|
956
|
+
resolve();
|
|
957
|
+
};
|
|
958
|
+
});
|
|
959
|
+
}
|
|
960
|
+
/**
|
|
961
|
+
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.
|
|
962
|
+
|
|
963
|
+
@returns A promise that settles when the queue becomes empty, and all promises have completed; `queue.size === 0 && queue.pending === 0`.
|
|
964
|
+
*/
|
|
965
|
+
async onIdle() {
|
|
966
|
+
if (this._pendingCount === 0 && this._queue.size === 0) {
|
|
967
|
+
return;
|
|
968
|
+
}
|
|
969
|
+
return new Promise((resolve) => {
|
|
970
|
+
const existingResolve = this._resolveIdle;
|
|
971
|
+
this._resolveIdle = () => {
|
|
972
|
+
existingResolve();
|
|
973
|
+
resolve();
|
|
974
|
+
};
|
|
975
|
+
});
|
|
976
|
+
}
|
|
977
|
+
/**
|
|
978
|
+
Size of the queue.
|
|
979
|
+
*/
|
|
980
|
+
get size() {
|
|
981
|
+
return this._queue.size;
|
|
982
|
+
}
|
|
983
|
+
/**
|
|
984
|
+
Size of the queue, filtered by the given options.
|
|
985
|
+
|
|
986
|
+
For example, this can be used to find the number of items remaining in the queue with a specific priority level.
|
|
987
|
+
*/
|
|
988
|
+
sizeBy(options) {
|
|
989
|
+
return this._queue.filter(options).length;
|
|
990
|
+
}
|
|
991
|
+
/**
|
|
992
|
+
Number of pending promises.
|
|
993
|
+
*/
|
|
994
|
+
get pending() {
|
|
995
|
+
return this._pendingCount;
|
|
996
|
+
}
|
|
997
|
+
/**
|
|
998
|
+
Whether the queue is currently paused.
|
|
999
|
+
*/
|
|
1000
|
+
get isPaused() {
|
|
1001
|
+
return this._isPaused;
|
|
1002
|
+
}
|
|
1003
|
+
get timeout() {
|
|
1004
|
+
return this._timeout;
|
|
1005
|
+
}
|
|
1006
|
+
/**
|
|
1007
|
+
Set the timeout for future operations.
|
|
1008
|
+
*/
|
|
1009
|
+
set timeout(milliseconds) {
|
|
1010
|
+
this._timeout = milliseconds;
|
|
1011
|
+
}
|
|
1012
|
+
};
|
|
1013
|
+
exports.default = PQueue;
|
|
1014
|
+
}
|
|
1015
|
+
});
|
|
62
1016
|
|
|
63
1017
|
// src/index.ts
|
|
64
1018
|
var src_exports = {};
|
|
@@ -83,7 +1037,7 @@ var import_assert2 = __toESM(require("assert"));
|
|
|
83
1037
|
|
|
84
1038
|
// src/image/info.ts
|
|
85
1039
|
var import_node_assert = __toESM(require("assert"));
|
|
86
|
-
var
|
|
1040
|
+
var import_node_buffer = require("buffer");
|
|
87
1041
|
var import_node_fs = require("fs");
|
|
88
1042
|
var import_sharp = __toESM(require("sharp"));
|
|
89
1043
|
async function imageInfo(image) {
|
|
@@ -93,15 +1047,15 @@ async function imageInfo(image) {
|
|
|
93
1047
|
}
|
|
94
1048
|
async function imageInfoOfBase64(imageBase64) {
|
|
95
1049
|
const base64Data = imageBase64.replace(/^data:image\/\w+;base64,/, "");
|
|
96
|
-
return imageInfo(
|
|
1050
|
+
return imageInfo(import_node_buffer.Buffer.from(base64Data, "base64"));
|
|
97
1051
|
}
|
|
98
1052
|
|
|
99
1053
|
// src/image/transform.ts
|
|
100
|
-
var
|
|
1054
|
+
var import_node_buffer2 = require("buffer");
|
|
101
1055
|
var import_sharp2 = __toESM(require("sharp"));
|
|
102
1056
|
|
|
103
1057
|
// src/image/visualization.ts
|
|
104
|
-
var
|
|
1058
|
+
var import_buffer = require("buffer");
|
|
105
1059
|
var import_sharp3 = __toESM(require("sharp"));
|
|
106
1060
|
|
|
107
1061
|
// src/utils.ts
|
|
@@ -459,7 +1413,3218 @@ function expandLiteSection(liteSection, elementById) {
|
|
|
459
1413
|
// src/ai-model/openai.ts
|
|
460
1414
|
var import_assert4 = __toESM(require("assert"));
|
|
461
1415
|
var import_openai = __toESM(require("openai"));
|
|
462
|
-
|
|
1416
|
+
|
|
1417
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/traceable.js
|
|
1418
|
+
var import_node_async_hooks = require("async_hooks");
|
|
1419
|
+
|
|
1420
|
+
// ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-node/rng.js
|
|
1421
|
+
var import_crypto3 = __toESM(require("crypto"));
|
|
1422
|
+
var rnds8Pool = new Uint8Array(256);
|
|
1423
|
+
var poolPtr = rnds8Pool.length;
|
|
1424
|
+
function rng() {
|
|
1425
|
+
if (poolPtr > rnds8Pool.length - 16) {
|
|
1426
|
+
import_crypto3.default.randomFillSync(rnds8Pool);
|
|
1427
|
+
poolPtr = 0;
|
|
1428
|
+
}
|
|
1429
|
+
return rnds8Pool.slice(poolPtr, poolPtr += 16);
|
|
1430
|
+
}
|
|
1431
|
+
|
|
1432
|
+
// ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-node/regex.js
|
|
1433
|
+
var regex_default = /^(?:[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}|00000000-0000-0000-0000-000000000000)$/i;
|
|
1434
|
+
|
|
1435
|
+
// ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-node/validate.js
|
|
1436
|
+
function validate(uuid) {
|
|
1437
|
+
return typeof uuid === "string" && regex_default.test(uuid);
|
|
1438
|
+
}
|
|
1439
|
+
var validate_default = validate;
|
|
1440
|
+
|
|
1441
|
+
// ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-node/stringify.js
|
|
1442
|
+
var byteToHex = [];
|
|
1443
|
+
for (let i = 0; i < 256; ++i) {
|
|
1444
|
+
byteToHex.push((i + 256).toString(16).slice(1));
|
|
1445
|
+
}
|
|
1446
|
+
function unsafeStringify(arr, offset = 0) {
|
|
1447
|
+
return byteToHex[arr[offset + 0]] + byteToHex[arr[offset + 1]] + byteToHex[arr[offset + 2]] + byteToHex[arr[offset + 3]] + "-" + byteToHex[arr[offset + 4]] + byteToHex[arr[offset + 5]] + "-" + byteToHex[arr[offset + 6]] + byteToHex[arr[offset + 7]] + "-" + byteToHex[arr[offset + 8]] + byteToHex[arr[offset + 9]] + "-" + byteToHex[arr[offset + 10]] + byteToHex[arr[offset + 11]] + byteToHex[arr[offset + 12]] + byteToHex[arr[offset + 13]] + byteToHex[arr[offset + 14]] + byteToHex[arr[offset + 15]];
|
|
1448
|
+
}
|
|
1449
|
+
|
|
1450
|
+
// ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-node/native.js
|
|
1451
|
+
var import_crypto4 = __toESM(require("crypto"));
|
|
1452
|
+
var native_default = {
|
|
1453
|
+
randomUUID: import_crypto4.default.randomUUID
|
|
1454
|
+
};
|
|
1455
|
+
|
|
1456
|
+
// ../../node_modules/.pnpm/uuid@9.0.1/node_modules/uuid/dist/esm-node/v4.js
|
|
1457
|
+
function v4(options, buf, offset) {
|
|
1458
|
+
if (native_default.randomUUID && !buf && !options) {
|
|
1459
|
+
return native_default.randomUUID();
|
|
1460
|
+
}
|
|
1461
|
+
options = options || {};
|
|
1462
|
+
const rnds = options.random || (options.rng || rng)();
|
|
1463
|
+
rnds[6] = rnds[6] & 15 | 64;
|
|
1464
|
+
rnds[8] = rnds[8] & 63 | 128;
|
|
1465
|
+
if (buf) {
|
|
1466
|
+
offset = offset || 0;
|
|
1467
|
+
for (let i = 0; i < 16; ++i) {
|
|
1468
|
+
buf[offset + i] = rnds[i];
|
|
1469
|
+
}
|
|
1470
|
+
return buf;
|
|
1471
|
+
}
|
|
1472
|
+
return unsafeStringify(rnds);
|
|
1473
|
+
}
|
|
1474
|
+
var v4_default = v4;
|
|
1475
|
+
|
|
1476
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/utils/async_caller.js
|
|
1477
|
+
var import_p_retry = __toESM(require_p_retry());
|
|
1478
|
+
var import_p_queue = __toESM(require_dist());
|
|
1479
|
+
var STATUS_NO_RETRY = [
|
|
1480
|
+
400,
|
|
1481
|
+
// Bad Request
|
|
1482
|
+
401,
|
|
1483
|
+
// Unauthorized
|
|
1484
|
+
403,
|
|
1485
|
+
// Forbidden
|
|
1486
|
+
404,
|
|
1487
|
+
// Not Found
|
|
1488
|
+
405,
|
|
1489
|
+
// Method Not Allowed
|
|
1490
|
+
406,
|
|
1491
|
+
// Not Acceptable
|
|
1492
|
+
407,
|
|
1493
|
+
// Proxy Authentication Required
|
|
1494
|
+
408
|
|
1495
|
+
// Request Timeout
|
|
1496
|
+
];
|
|
1497
|
+
var STATUS_IGNORE = [
|
|
1498
|
+
409
|
|
1499
|
+
// Conflict
|
|
1500
|
+
];
|
|
1501
|
+
var AsyncCaller = class {
|
|
1502
|
+
constructor(params) {
|
|
1503
|
+
var _a, _b;
|
|
1504
|
+
Object.defineProperty(this, "maxConcurrency", {
|
|
1505
|
+
enumerable: true,
|
|
1506
|
+
configurable: true,
|
|
1507
|
+
writable: true,
|
|
1508
|
+
value: void 0
|
|
1509
|
+
});
|
|
1510
|
+
Object.defineProperty(this, "maxRetries", {
|
|
1511
|
+
enumerable: true,
|
|
1512
|
+
configurable: true,
|
|
1513
|
+
writable: true,
|
|
1514
|
+
value: void 0
|
|
1515
|
+
});
|
|
1516
|
+
Object.defineProperty(this, "queue", {
|
|
1517
|
+
enumerable: true,
|
|
1518
|
+
configurable: true,
|
|
1519
|
+
writable: true,
|
|
1520
|
+
value: void 0
|
|
1521
|
+
});
|
|
1522
|
+
Object.defineProperty(this, "onFailedResponseHook", {
|
|
1523
|
+
enumerable: true,
|
|
1524
|
+
configurable: true,
|
|
1525
|
+
writable: true,
|
|
1526
|
+
value: void 0
|
|
1527
|
+
});
|
|
1528
|
+
this.maxConcurrency = (_a = params.maxConcurrency) != null ? _a : Infinity;
|
|
1529
|
+
this.maxRetries = (_b = params.maxRetries) != null ? _b : 6;
|
|
1530
|
+
if ("default" in import_p_queue.default) {
|
|
1531
|
+
this.queue = new import_p_queue.default.default({
|
|
1532
|
+
concurrency: this.maxConcurrency
|
|
1533
|
+
});
|
|
1534
|
+
} else {
|
|
1535
|
+
this.queue = new import_p_queue.default({ concurrency: this.maxConcurrency });
|
|
1536
|
+
}
|
|
1537
|
+
this.onFailedResponseHook = params == null ? void 0 : params.onFailedResponseHook;
|
|
1538
|
+
}
|
|
1539
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1540
|
+
call(callable, ...args) {
|
|
1541
|
+
const onFailedResponseHook = this.onFailedResponseHook;
|
|
1542
|
+
return this.queue.add(() => (0, import_p_retry.default)(() => callable(...args).catch((error) => {
|
|
1543
|
+
if (error instanceof Error) {
|
|
1544
|
+
throw error;
|
|
1545
|
+
} else {
|
|
1546
|
+
throw new Error(error);
|
|
1547
|
+
}
|
|
1548
|
+
}), {
|
|
1549
|
+
async onFailedAttempt(error) {
|
|
1550
|
+
if (error.message.startsWith("Cancel") || error.message.startsWith("TimeoutError") || error.message.startsWith("AbortError")) {
|
|
1551
|
+
throw error;
|
|
1552
|
+
}
|
|
1553
|
+
if ((error == null ? void 0 : error.code) === "ECONNABORTED") {
|
|
1554
|
+
throw error;
|
|
1555
|
+
}
|
|
1556
|
+
const response = error == null ? void 0 : error.response;
|
|
1557
|
+
const status = response == null ? void 0 : response.status;
|
|
1558
|
+
if (status) {
|
|
1559
|
+
if (STATUS_NO_RETRY.includes(+status)) {
|
|
1560
|
+
throw error;
|
|
1561
|
+
} else if (STATUS_IGNORE.includes(+status)) {
|
|
1562
|
+
return;
|
|
1563
|
+
}
|
|
1564
|
+
if (onFailedResponseHook) {
|
|
1565
|
+
await onFailedResponseHook(response);
|
|
1566
|
+
}
|
|
1567
|
+
}
|
|
1568
|
+
},
|
|
1569
|
+
// If needed we can change some of the defaults here,
|
|
1570
|
+
// but they're quite sensible.
|
|
1571
|
+
retries: this.maxRetries,
|
|
1572
|
+
randomize: true
|
|
1573
|
+
}), { throwOnTimeout: true });
|
|
1574
|
+
}
|
|
1575
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
1576
|
+
callWithOptions(options, callable, ...args) {
|
|
1577
|
+
if (options.signal) {
|
|
1578
|
+
return Promise.race([
|
|
1579
|
+
this.call(callable, ...args),
|
|
1580
|
+
new Promise((_, reject) => {
|
|
1581
|
+
var _a;
|
|
1582
|
+
(_a = options.signal) == null ? void 0 : _a.addEventListener("abort", () => {
|
|
1583
|
+
reject(new Error("AbortError"));
|
|
1584
|
+
});
|
|
1585
|
+
})
|
|
1586
|
+
]);
|
|
1587
|
+
}
|
|
1588
|
+
return this.call(callable, ...args);
|
|
1589
|
+
}
|
|
1590
|
+
fetch(...args) {
|
|
1591
|
+
return this.call(() => fetch(...args).then((res) => res.ok ? res : Promise.reject(res)));
|
|
1592
|
+
}
|
|
1593
|
+
};
|
|
1594
|
+
|
|
1595
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/utils/messages.js
|
|
1596
|
+
function isLangChainMessage(message) {
|
|
1597
|
+
return typeof (message == null ? void 0 : message._getType) === "function";
|
|
1598
|
+
}
|
|
1599
|
+
function convertLangChainMessageToExample(message) {
|
|
1600
|
+
const converted = {
|
|
1601
|
+
type: message._getType(),
|
|
1602
|
+
data: { content: message.content }
|
|
1603
|
+
};
|
|
1604
|
+
if ((message == null ? void 0 : message.additional_kwargs) && Object.keys(message.additional_kwargs).length > 0) {
|
|
1605
|
+
converted.data.additional_kwargs = __spreadValues({}, message.additional_kwargs);
|
|
1606
|
+
}
|
|
1607
|
+
return converted;
|
|
1608
|
+
}
|
|
1609
|
+
|
|
1610
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/utils/_uuid.js
|
|
1611
|
+
function assertUuid(str) {
|
|
1612
|
+
if (!validate_default(str)) {
|
|
1613
|
+
throw new Error(`Invalid UUID: ${str}`);
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/utils/warn.js
|
|
1618
|
+
var warnedMessages = {};
|
|
1619
|
+
function warnOnce(message) {
|
|
1620
|
+
if (!warnedMessages[message]) {
|
|
1621
|
+
console.warn(message);
|
|
1622
|
+
warnedMessages[message] = true;
|
|
1623
|
+
}
|
|
1624
|
+
}
|
|
1625
|
+
|
|
1626
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/client.js
|
|
1627
|
+
async function mergeRuntimeEnvIntoRunCreates(runs) {
|
|
1628
|
+
const runtimeEnv = await getRuntimeEnvironment();
|
|
1629
|
+
const envVars = getLangChainEnvVarsMetadata();
|
|
1630
|
+
return runs.map((run) => {
|
|
1631
|
+
var _a, _b;
|
|
1632
|
+
const extra = (_a = run.extra) != null ? _a : {};
|
|
1633
|
+
const metadata = extra.metadata;
|
|
1634
|
+
run.extra = __spreadProps(__spreadValues({}, extra), {
|
|
1635
|
+
runtime: __spreadValues(__spreadValues({}, runtimeEnv), extra == null ? void 0 : extra.runtime),
|
|
1636
|
+
metadata: __spreadValues(__spreadValues(__spreadValues({}, envVars), envVars.revision_id || run.revision_id ? { revision_id: (_b = run.revision_id) != null ? _b : envVars.revision_id } : {}), metadata)
|
|
1637
|
+
});
|
|
1638
|
+
return run;
|
|
1639
|
+
});
|
|
1640
|
+
}
|
|
1641
|
+
var getTracingSamplingRate = () => {
|
|
1642
|
+
const samplingRateStr = getEnvironmentVariable("LANGCHAIN_TRACING_SAMPLING_RATE");
|
|
1643
|
+
if (samplingRateStr === void 0) {
|
|
1644
|
+
return void 0;
|
|
1645
|
+
}
|
|
1646
|
+
const samplingRate = parseFloat(samplingRateStr);
|
|
1647
|
+
if (samplingRate < 0 || samplingRate > 1) {
|
|
1648
|
+
throw new Error(`LANGCHAIN_TRACING_SAMPLING_RATE must be between 0 and 1 if set. Got: ${samplingRate}`);
|
|
1649
|
+
}
|
|
1650
|
+
return samplingRate;
|
|
1651
|
+
};
|
|
1652
|
+
var isLocalhost = (url) => {
|
|
1653
|
+
const strippedUrl = url.replace("http://", "").replace("https://", "");
|
|
1654
|
+
const hostname = strippedUrl.split("/")[0].split(":")[0];
|
|
1655
|
+
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "::1";
|
|
1656
|
+
};
|
|
1657
|
+
var raiseForStatus = async (response, operation) => {
|
|
1658
|
+
const body = await response.text();
|
|
1659
|
+
if (!response.ok) {
|
|
1660
|
+
throw new Error(`Failed to ${operation}: ${response.status} ${response.statusText} ${body}`);
|
|
1661
|
+
}
|
|
1662
|
+
};
|
|
1663
|
+
async function toArray(iterable) {
|
|
1664
|
+
const result = [];
|
|
1665
|
+
try {
|
|
1666
|
+
for (var iter = __forAwait(iterable), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
|
|
1667
|
+
const item = temp.value;
|
|
1668
|
+
result.push(item);
|
|
1669
|
+
}
|
|
1670
|
+
} catch (temp) {
|
|
1671
|
+
error = [temp];
|
|
1672
|
+
} finally {
|
|
1673
|
+
try {
|
|
1674
|
+
more && (temp = iter.return) && await temp.call(iter);
|
|
1675
|
+
} finally {
|
|
1676
|
+
if (error)
|
|
1677
|
+
throw error[0];
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1680
|
+
return result;
|
|
1681
|
+
}
|
|
1682
|
+
function trimQuotes(str) {
|
|
1683
|
+
if (str === void 0) {
|
|
1684
|
+
return void 0;
|
|
1685
|
+
}
|
|
1686
|
+
return str.trim().replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1");
|
|
1687
|
+
}
|
|
1688
|
+
var handle429 = async (response) => {
|
|
1689
|
+
var _a;
|
|
1690
|
+
if ((response == null ? void 0 : response.status) === 429) {
|
|
1691
|
+
const retryAfter = parseInt((_a = response.headers.get("retry-after")) != null ? _a : "30", 10) * 1e3;
|
|
1692
|
+
if (retryAfter > 0) {
|
|
1693
|
+
await new Promise((resolve) => setTimeout(resolve, retryAfter));
|
|
1694
|
+
return true;
|
|
1695
|
+
}
|
|
1696
|
+
}
|
|
1697
|
+
return false;
|
|
1698
|
+
};
|
|
1699
|
+
var Queue = class {
|
|
1700
|
+
constructor() {
|
|
1701
|
+
Object.defineProperty(this, "items", {
|
|
1702
|
+
enumerable: true,
|
|
1703
|
+
configurable: true,
|
|
1704
|
+
writable: true,
|
|
1705
|
+
value: []
|
|
1706
|
+
});
|
|
1707
|
+
}
|
|
1708
|
+
get size() {
|
|
1709
|
+
return this.items.length;
|
|
1710
|
+
}
|
|
1711
|
+
push(item) {
|
|
1712
|
+
return new Promise((resolve) => {
|
|
1713
|
+
this.items.push([item, resolve]);
|
|
1714
|
+
});
|
|
1715
|
+
}
|
|
1716
|
+
pop(upToN) {
|
|
1717
|
+
if (upToN < 1) {
|
|
1718
|
+
throw new Error("Number of items to pop off may not be less than 1.");
|
|
1719
|
+
}
|
|
1720
|
+
const popped = [];
|
|
1721
|
+
while (popped.length < upToN && this.items.length) {
|
|
1722
|
+
const item = this.items.shift();
|
|
1723
|
+
if (item) {
|
|
1724
|
+
popped.push(item);
|
|
1725
|
+
} else {
|
|
1726
|
+
break;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1729
|
+
return [popped.map((it) => it[0]), () => popped.forEach((it) => it[1]())];
|
|
1730
|
+
}
|
|
1731
|
+
};
|
|
1732
|
+
var DEFAULT_BATCH_SIZE_LIMIT_BYTES = 20971520;
|
|
1733
|
+
var Client = class _Client {
|
|
1734
|
+
constructor(config = {}) {
|
|
1735
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m;
|
|
1736
|
+
Object.defineProperty(this, "apiKey", {
|
|
1737
|
+
enumerable: true,
|
|
1738
|
+
configurable: true,
|
|
1739
|
+
writable: true,
|
|
1740
|
+
value: void 0
|
|
1741
|
+
});
|
|
1742
|
+
Object.defineProperty(this, "apiUrl", {
|
|
1743
|
+
enumerable: true,
|
|
1744
|
+
configurable: true,
|
|
1745
|
+
writable: true,
|
|
1746
|
+
value: void 0
|
|
1747
|
+
});
|
|
1748
|
+
Object.defineProperty(this, "webUrl", {
|
|
1749
|
+
enumerable: true,
|
|
1750
|
+
configurable: true,
|
|
1751
|
+
writable: true,
|
|
1752
|
+
value: void 0
|
|
1753
|
+
});
|
|
1754
|
+
Object.defineProperty(this, "caller", {
|
|
1755
|
+
enumerable: true,
|
|
1756
|
+
configurable: true,
|
|
1757
|
+
writable: true,
|
|
1758
|
+
value: void 0
|
|
1759
|
+
});
|
|
1760
|
+
Object.defineProperty(this, "batchIngestCaller", {
|
|
1761
|
+
enumerable: true,
|
|
1762
|
+
configurable: true,
|
|
1763
|
+
writable: true,
|
|
1764
|
+
value: void 0
|
|
1765
|
+
});
|
|
1766
|
+
Object.defineProperty(this, "timeout_ms", {
|
|
1767
|
+
enumerable: true,
|
|
1768
|
+
configurable: true,
|
|
1769
|
+
writable: true,
|
|
1770
|
+
value: void 0
|
|
1771
|
+
});
|
|
1772
|
+
Object.defineProperty(this, "_tenantId", {
|
|
1773
|
+
enumerable: true,
|
|
1774
|
+
configurable: true,
|
|
1775
|
+
writable: true,
|
|
1776
|
+
value: null
|
|
1777
|
+
});
|
|
1778
|
+
Object.defineProperty(this, "hideInputs", {
|
|
1779
|
+
enumerable: true,
|
|
1780
|
+
configurable: true,
|
|
1781
|
+
writable: true,
|
|
1782
|
+
value: void 0
|
|
1783
|
+
});
|
|
1784
|
+
Object.defineProperty(this, "hideOutputs", {
|
|
1785
|
+
enumerable: true,
|
|
1786
|
+
configurable: true,
|
|
1787
|
+
writable: true,
|
|
1788
|
+
value: void 0
|
|
1789
|
+
});
|
|
1790
|
+
Object.defineProperty(this, "tracingSampleRate", {
|
|
1791
|
+
enumerable: true,
|
|
1792
|
+
configurable: true,
|
|
1793
|
+
writable: true,
|
|
1794
|
+
value: void 0
|
|
1795
|
+
});
|
|
1796
|
+
Object.defineProperty(this, "sampledPostUuids", {
|
|
1797
|
+
enumerable: true,
|
|
1798
|
+
configurable: true,
|
|
1799
|
+
writable: true,
|
|
1800
|
+
value: /* @__PURE__ */ new Set()
|
|
1801
|
+
});
|
|
1802
|
+
Object.defineProperty(this, "autoBatchTracing", {
|
|
1803
|
+
enumerable: true,
|
|
1804
|
+
configurable: true,
|
|
1805
|
+
writable: true,
|
|
1806
|
+
value: true
|
|
1807
|
+
});
|
|
1808
|
+
Object.defineProperty(this, "batchEndpointSupported", {
|
|
1809
|
+
enumerable: true,
|
|
1810
|
+
configurable: true,
|
|
1811
|
+
writable: true,
|
|
1812
|
+
value: void 0
|
|
1813
|
+
});
|
|
1814
|
+
Object.defineProperty(this, "autoBatchQueue", {
|
|
1815
|
+
enumerable: true,
|
|
1816
|
+
configurable: true,
|
|
1817
|
+
writable: true,
|
|
1818
|
+
value: new Queue()
|
|
1819
|
+
});
|
|
1820
|
+
Object.defineProperty(this, "pendingAutoBatchedRunLimit", {
|
|
1821
|
+
enumerable: true,
|
|
1822
|
+
configurable: true,
|
|
1823
|
+
writable: true,
|
|
1824
|
+
value: 100
|
|
1825
|
+
});
|
|
1826
|
+
Object.defineProperty(this, "autoBatchTimeout", {
|
|
1827
|
+
enumerable: true,
|
|
1828
|
+
configurable: true,
|
|
1829
|
+
writable: true,
|
|
1830
|
+
value: void 0
|
|
1831
|
+
});
|
|
1832
|
+
Object.defineProperty(this, "autoBatchInitialDelayMs", {
|
|
1833
|
+
enumerable: true,
|
|
1834
|
+
configurable: true,
|
|
1835
|
+
writable: true,
|
|
1836
|
+
value: 250
|
|
1837
|
+
});
|
|
1838
|
+
Object.defineProperty(this, "autoBatchAggregationDelayMs", {
|
|
1839
|
+
enumerable: true,
|
|
1840
|
+
configurable: true,
|
|
1841
|
+
writable: true,
|
|
1842
|
+
value: 50
|
|
1843
|
+
});
|
|
1844
|
+
Object.defineProperty(this, "serverInfo", {
|
|
1845
|
+
enumerable: true,
|
|
1846
|
+
configurable: true,
|
|
1847
|
+
writable: true,
|
|
1848
|
+
value: void 0
|
|
1849
|
+
});
|
|
1850
|
+
Object.defineProperty(this, "fetchOptions", {
|
|
1851
|
+
enumerable: true,
|
|
1852
|
+
configurable: true,
|
|
1853
|
+
writable: true,
|
|
1854
|
+
value: void 0
|
|
1855
|
+
});
|
|
1856
|
+
const defaultConfig = _Client.getDefaultClientConfig();
|
|
1857
|
+
this.tracingSampleRate = getTracingSamplingRate();
|
|
1858
|
+
this.apiUrl = (_b = trimQuotes((_a = config.apiUrl) != null ? _a : defaultConfig.apiUrl)) != null ? _b : "";
|
|
1859
|
+
this.apiKey = trimQuotes((_c = config.apiKey) != null ? _c : defaultConfig.apiKey);
|
|
1860
|
+
this.webUrl = trimQuotes((_d = config.webUrl) != null ? _d : defaultConfig.webUrl);
|
|
1861
|
+
this.timeout_ms = (_e = config.timeout_ms) != null ? _e : 12e3;
|
|
1862
|
+
this.caller = new AsyncCaller((_f = config.callerOptions) != null ? _f : {});
|
|
1863
|
+
this.batchIngestCaller = new AsyncCaller(__spreadProps(__spreadValues({}, (_g = config.callerOptions) != null ? _g : {}), {
|
|
1864
|
+
onFailedResponseHook: handle429
|
|
1865
|
+
}));
|
|
1866
|
+
this.hideInputs = (_i = (_h = config.hideInputs) != null ? _h : config.anonymizer) != null ? _i : defaultConfig.hideInputs;
|
|
1867
|
+
this.hideOutputs = (_k = (_j = config.hideOutputs) != null ? _j : config.anonymizer) != null ? _k : defaultConfig.hideOutputs;
|
|
1868
|
+
this.autoBatchTracing = (_l = config.autoBatchTracing) != null ? _l : this.autoBatchTracing;
|
|
1869
|
+
this.pendingAutoBatchedRunLimit = (_m = config.pendingAutoBatchedRunLimit) != null ? _m : this.pendingAutoBatchedRunLimit;
|
|
1870
|
+
this.fetchOptions = config.fetchOptions || {};
|
|
1871
|
+
}
|
|
1872
|
+
static getDefaultClientConfig() {
|
|
1873
|
+
var _a;
|
|
1874
|
+
const apiKey = getEnvironmentVariable("LANGCHAIN_API_KEY");
|
|
1875
|
+
const apiUrl = (_a = getEnvironmentVariable("LANGCHAIN_ENDPOINT")) != null ? _a : "https://api.smith.langchain.com";
|
|
1876
|
+
const hideInputs = getEnvironmentVariable("LANGCHAIN_HIDE_INPUTS") === "true";
|
|
1877
|
+
const hideOutputs = getEnvironmentVariable("LANGCHAIN_HIDE_OUTPUTS") === "true";
|
|
1878
|
+
return {
|
|
1879
|
+
apiUrl,
|
|
1880
|
+
apiKey,
|
|
1881
|
+
webUrl: void 0,
|
|
1882
|
+
hideInputs,
|
|
1883
|
+
hideOutputs
|
|
1884
|
+
};
|
|
1885
|
+
}
|
|
1886
|
+
getHostUrl() {
|
|
1887
|
+
if (this.webUrl) {
|
|
1888
|
+
return this.webUrl;
|
|
1889
|
+
} else if (isLocalhost(this.apiUrl)) {
|
|
1890
|
+
this.webUrl = "http://localhost:3000";
|
|
1891
|
+
return this.webUrl;
|
|
1892
|
+
} else if (this.apiUrl.includes("/api") && !this.apiUrl.split(".", 1)[0].endsWith("api")) {
|
|
1893
|
+
this.webUrl = this.apiUrl.replace("/api", "");
|
|
1894
|
+
return this.webUrl;
|
|
1895
|
+
} else if (this.apiUrl.split(".", 1)[0].includes("dev")) {
|
|
1896
|
+
this.webUrl = "https://dev.smith.langchain.com";
|
|
1897
|
+
return this.webUrl;
|
|
1898
|
+
} else {
|
|
1899
|
+
this.webUrl = "https://smith.langchain.com";
|
|
1900
|
+
return this.webUrl;
|
|
1901
|
+
}
|
|
1902
|
+
}
|
|
1903
|
+
get headers() {
|
|
1904
|
+
const headers = {
|
|
1905
|
+
"User-Agent": `langsmith-js/${__version__}`
|
|
1906
|
+
};
|
|
1907
|
+
if (this.apiKey) {
|
|
1908
|
+
headers["x-api-key"] = `${this.apiKey}`;
|
|
1909
|
+
}
|
|
1910
|
+
return headers;
|
|
1911
|
+
}
|
|
1912
|
+
processInputs(inputs) {
|
|
1913
|
+
if (this.hideInputs === false) {
|
|
1914
|
+
return inputs;
|
|
1915
|
+
}
|
|
1916
|
+
if (this.hideInputs === true) {
|
|
1917
|
+
return {};
|
|
1918
|
+
}
|
|
1919
|
+
if (typeof this.hideInputs === "function") {
|
|
1920
|
+
return this.hideInputs(inputs);
|
|
1921
|
+
}
|
|
1922
|
+
return inputs;
|
|
1923
|
+
}
|
|
1924
|
+
processOutputs(outputs) {
|
|
1925
|
+
if (this.hideOutputs === false) {
|
|
1926
|
+
return outputs;
|
|
1927
|
+
}
|
|
1928
|
+
if (this.hideOutputs === true) {
|
|
1929
|
+
return {};
|
|
1930
|
+
}
|
|
1931
|
+
if (typeof this.hideOutputs === "function") {
|
|
1932
|
+
return this.hideOutputs(outputs);
|
|
1933
|
+
}
|
|
1934
|
+
return outputs;
|
|
1935
|
+
}
|
|
1936
|
+
prepareRunCreateOrUpdateInputs(run) {
|
|
1937
|
+
const runParams = __spreadValues({}, run);
|
|
1938
|
+
if (runParams.inputs !== void 0) {
|
|
1939
|
+
runParams.inputs = this.processInputs(runParams.inputs);
|
|
1940
|
+
}
|
|
1941
|
+
if (runParams.outputs !== void 0) {
|
|
1942
|
+
runParams.outputs = this.processOutputs(runParams.outputs);
|
|
1943
|
+
}
|
|
1944
|
+
return runParams;
|
|
1945
|
+
}
|
|
1946
|
+
async _getResponse(path, queryParams) {
|
|
1947
|
+
var _a;
|
|
1948
|
+
const paramsString = (_a = queryParams == null ? void 0 : queryParams.toString()) != null ? _a : "";
|
|
1949
|
+
const url = `${this.apiUrl}${path}?${paramsString}`;
|
|
1950
|
+
const response = await this.caller.call(fetch, url, __spreadValues({
|
|
1951
|
+
method: "GET",
|
|
1952
|
+
headers: this.headers,
|
|
1953
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
1954
|
+
}, this.fetchOptions));
|
|
1955
|
+
if (!response.ok) {
|
|
1956
|
+
throw new Error(`Failed to fetch ${path}: ${response.status} ${response.statusText}`);
|
|
1957
|
+
}
|
|
1958
|
+
return response;
|
|
1959
|
+
}
|
|
1960
|
+
async _get(path, queryParams) {
|
|
1961
|
+
const response = await this._getResponse(path, queryParams);
|
|
1962
|
+
return response.json();
|
|
1963
|
+
}
|
|
1964
|
+
_getPaginated(_0) {
|
|
1965
|
+
return __asyncGenerator(this, arguments, function* (path, queryParams = new URLSearchParams()) {
|
|
1966
|
+
let offset = Number(queryParams.get("offset")) || 0;
|
|
1967
|
+
const limit = Number(queryParams.get("limit")) || 100;
|
|
1968
|
+
while (true) {
|
|
1969
|
+
queryParams.set("offset", String(offset));
|
|
1970
|
+
queryParams.set("limit", String(limit));
|
|
1971
|
+
const url = `${this.apiUrl}${path}?${queryParams}`;
|
|
1972
|
+
const response = yield new __await(this.caller.call(fetch, url, __spreadValues({
|
|
1973
|
+
method: "GET",
|
|
1974
|
+
headers: this.headers,
|
|
1975
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
1976
|
+
}, this.fetchOptions)));
|
|
1977
|
+
if (!response.ok) {
|
|
1978
|
+
throw new Error(`Failed to fetch ${path}: ${response.status} ${response.statusText}`);
|
|
1979
|
+
}
|
|
1980
|
+
const items = yield new __await(response.json());
|
|
1981
|
+
if (items.length === 0) {
|
|
1982
|
+
break;
|
|
1983
|
+
}
|
|
1984
|
+
yield items;
|
|
1985
|
+
if (items.length < limit) {
|
|
1986
|
+
break;
|
|
1987
|
+
}
|
|
1988
|
+
offset += items.length;
|
|
1989
|
+
}
|
|
1990
|
+
});
|
|
1991
|
+
}
|
|
1992
|
+
_getCursorPaginatedList(path, body = null, requestMethod = "POST", dataKey = "runs") {
|
|
1993
|
+
return __asyncGenerator(this, null, function* () {
|
|
1994
|
+
const bodyParams = body ? __spreadValues({}, body) : {};
|
|
1995
|
+
while (true) {
|
|
1996
|
+
const response = yield new __await(this.caller.call(fetch, `${this.apiUrl}${path}`, __spreadProps(__spreadValues({
|
|
1997
|
+
method: requestMethod,
|
|
1998
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
1999
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2000
|
+
}, this.fetchOptions), {
|
|
2001
|
+
body: JSON.stringify(bodyParams)
|
|
2002
|
+
})));
|
|
2003
|
+
const responseBody = yield new __await(response.json());
|
|
2004
|
+
if (!responseBody) {
|
|
2005
|
+
break;
|
|
2006
|
+
}
|
|
2007
|
+
if (!responseBody[dataKey]) {
|
|
2008
|
+
break;
|
|
2009
|
+
}
|
|
2010
|
+
yield responseBody[dataKey];
|
|
2011
|
+
const cursors = responseBody.cursors;
|
|
2012
|
+
if (!cursors) {
|
|
2013
|
+
break;
|
|
2014
|
+
}
|
|
2015
|
+
if (!cursors.next) {
|
|
2016
|
+
break;
|
|
2017
|
+
}
|
|
2018
|
+
bodyParams.cursor = cursors.next;
|
|
2019
|
+
}
|
|
2020
|
+
});
|
|
2021
|
+
}
|
|
2022
|
+
_filterForSampling(runs, patch = false) {
|
|
2023
|
+
if (this.tracingSampleRate === void 0) {
|
|
2024
|
+
return runs;
|
|
2025
|
+
}
|
|
2026
|
+
if (patch) {
|
|
2027
|
+
const sampled = [];
|
|
2028
|
+
for (const run of runs) {
|
|
2029
|
+
if (this.sampledPostUuids.has(run.id)) {
|
|
2030
|
+
sampled.push(run);
|
|
2031
|
+
this.sampledPostUuids.delete(run.id);
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
return sampled;
|
|
2035
|
+
} else {
|
|
2036
|
+
const sampled = [];
|
|
2037
|
+
for (const run of runs) {
|
|
2038
|
+
if (Math.random() < this.tracingSampleRate) {
|
|
2039
|
+
sampled.push(run);
|
|
2040
|
+
this.sampledPostUuids.add(run.id);
|
|
2041
|
+
}
|
|
2042
|
+
}
|
|
2043
|
+
return sampled;
|
|
2044
|
+
}
|
|
2045
|
+
}
|
|
2046
|
+
async drainAutoBatchQueue() {
|
|
2047
|
+
while (this.autoBatchQueue.size >= 0) {
|
|
2048
|
+
const [batch, done] = this.autoBatchQueue.pop(this.pendingAutoBatchedRunLimit);
|
|
2049
|
+
if (!batch.length) {
|
|
2050
|
+
done();
|
|
2051
|
+
return;
|
|
2052
|
+
}
|
|
2053
|
+
try {
|
|
2054
|
+
await this.batchIngestRuns({
|
|
2055
|
+
runCreates: batch.filter((item) => item.action === "create").map((item) => item.item),
|
|
2056
|
+
runUpdates: batch.filter((item) => item.action === "update").map((item) => item.item)
|
|
2057
|
+
});
|
|
2058
|
+
} finally {
|
|
2059
|
+
done();
|
|
2060
|
+
}
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
async processRunOperation(item, immediatelyTriggerBatch) {
|
|
2064
|
+
const oldTimeout = this.autoBatchTimeout;
|
|
2065
|
+
clearTimeout(this.autoBatchTimeout);
|
|
2066
|
+
this.autoBatchTimeout = void 0;
|
|
2067
|
+
const itemPromise = this.autoBatchQueue.push(item);
|
|
2068
|
+
if (immediatelyTriggerBatch || this.autoBatchQueue.size > this.pendingAutoBatchedRunLimit) {
|
|
2069
|
+
await this.drainAutoBatchQueue();
|
|
2070
|
+
}
|
|
2071
|
+
if (this.autoBatchQueue.size > 0) {
|
|
2072
|
+
this.autoBatchTimeout = setTimeout(() => {
|
|
2073
|
+
this.autoBatchTimeout = void 0;
|
|
2074
|
+
void this.drainAutoBatchQueue().catch(console.error);
|
|
2075
|
+
}, oldTimeout ? this.autoBatchAggregationDelayMs : this.autoBatchInitialDelayMs);
|
|
2076
|
+
}
|
|
2077
|
+
return itemPromise;
|
|
2078
|
+
}
|
|
2079
|
+
async _getServerInfo() {
|
|
2080
|
+
const response = await fetch(`${this.apiUrl}/info`, __spreadValues({
|
|
2081
|
+
method: "GET",
|
|
2082
|
+
headers: { Accept: "application/json" },
|
|
2083
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2084
|
+
}, this.fetchOptions));
|
|
2085
|
+
if (!response.ok) {
|
|
2086
|
+
await response.text();
|
|
2087
|
+
throw new Error("Failed to retrieve server info.");
|
|
2088
|
+
}
|
|
2089
|
+
return response.json();
|
|
2090
|
+
}
|
|
2091
|
+
async batchEndpointIsSupported() {
|
|
2092
|
+
try {
|
|
2093
|
+
this.serverInfo = await this._getServerInfo();
|
|
2094
|
+
} catch (e) {
|
|
2095
|
+
return false;
|
|
2096
|
+
}
|
|
2097
|
+
return true;
|
|
2098
|
+
}
|
|
2099
|
+
async createRun(run) {
|
|
2100
|
+
var _a;
|
|
2101
|
+
if (!this._filterForSampling([run]).length) {
|
|
2102
|
+
return;
|
|
2103
|
+
}
|
|
2104
|
+
const headers = __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" });
|
|
2105
|
+
const session_name = run.project_name;
|
|
2106
|
+
delete run.project_name;
|
|
2107
|
+
const runCreate = this.prepareRunCreateOrUpdateInputs(__spreadProps(__spreadValues({
|
|
2108
|
+
session_name
|
|
2109
|
+
}, run), {
|
|
2110
|
+
start_time: (_a = run.start_time) != null ? _a : Date.now()
|
|
2111
|
+
}));
|
|
2112
|
+
if (this.autoBatchTracing && runCreate.trace_id !== void 0 && runCreate.dotted_order !== void 0) {
|
|
2113
|
+
void this.processRunOperation({
|
|
2114
|
+
action: "create",
|
|
2115
|
+
item: runCreate
|
|
2116
|
+
}).catch(console.error);
|
|
2117
|
+
return;
|
|
2118
|
+
}
|
|
2119
|
+
const mergedRunCreateParams = await mergeRuntimeEnvIntoRunCreates([
|
|
2120
|
+
runCreate
|
|
2121
|
+
]);
|
|
2122
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/runs`, __spreadValues({
|
|
2123
|
+
method: "POST",
|
|
2124
|
+
headers,
|
|
2125
|
+
body: JSON.stringify(mergedRunCreateParams[0]),
|
|
2126
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2127
|
+
}, this.fetchOptions));
|
|
2128
|
+
await raiseForStatus(response, "create run");
|
|
2129
|
+
}
|
|
2130
|
+
/**
|
|
2131
|
+
* Batch ingest/upsert multiple runs in the Langsmith system.
|
|
2132
|
+
* @param runs
|
|
2133
|
+
*/
|
|
2134
|
+
async batchIngestRuns({ runCreates, runUpdates }) {
|
|
2135
|
+
var _a, _b, _c, _d, _e;
|
|
2136
|
+
if (runCreates === void 0 && runUpdates === void 0) {
|
|
2137
|
+
return;
|
|
2138
|
+
}
|
|
2139
|
+
let preparedCreateParams = (_a = runCreates == null ? void 0 : runCreates.map((create) => this.prepareRunCreateOrUpdateInputs(create))) != null ? _a : [];
|
|
2140
|
+
let preparedUpdateParams = (_b = runUpdates == null ? void 0 : runUpdates.map((update) => this.prepareRunCreateOrUpdateInputs(update))) != null ? _b : [];
|
|
2141
|
+
if (preparedCreateParams.length > 0 && preparedUpdateParams.length > 0) {
|
|
2142
|
+
const createById = preparedCreateParams.reduce((params, run) => {
|
|
2143
|
+
if (!run.id) {
|
|
2144
|
+
return params;
|
|
2145
|
+
}
|
|
2146
|
+
params[run.id] = run;
|
|
2147
|
+
return params;
|
|
2148
|
+
}, {});
|
|
2149
|
+
const standaloneUpdates = [];
|
|
2150
|
+
for (const updateParam of preparedUpdateParams) {
|
|
2151
|
+
if (updateParam.id !== void 0 && createById[updateParam.id]) {
|
|
2152
|
+
createById[updateParam.id] = __spreadValues(__spreadValues({}, createById[updateParam.id]), updateParam);
|
|
2153
|
+
} else {
|
|
2154
|
+
standaloneUpdates.push(updateParam);
|
|
2155
|
+
}
|
|
2156
|
+
}
|
|
2157
|
+
preparedCreateParams = Object.values(createById);
|
|
2158
|
+
preparedUpdateParams = standaloneUpdates;
|
|
2159
|
+
}
|
|
2160
|
+
const rawBatch = {
|
|
2161
|
+
post: this._filterForSampling(preparedCreateParams),
|
|
2162
|
+
patch: this._filterForSampling(preparedUpdateParams, true)
|
|
2163
|
+
};
|
|
2164
|
+
if (!rawBatch.post.length && !rawBatch.patch.length) {
|
|
2165
|
+
return;
|
|
2166
|
+
}
|
|
2167
|
+
preparedCreateParams = await mergeRuntimeEnvIntoRunCreates(preparedCreateParams);
|
|
2168
|
+
if (this.batchEndpointSupported === void 0) {
|
|
2169
|
+
this.batchEndpointSupported = await this.batchEndpointIsSupported();
|
|
2170
|
+
}
|
|
2171
|
+
if (!this.batchEndpointSupported) {
|
|
2172
|
+
this.autoBatchTracing = false;
|
|
2173
|
+
for (const preparedCreateParam of rawBatch.post) {
|
|
2174
|
+
await this.createRun(preparedCreateParam);
|
|
2175
|
+
}
|
|
2176
|
+
for (const preparedUpdateParam of rawBatch.patch) {
|
|
2177
|
+
if (preparedUpdateParam.id !== void 0) {
|
|
2178
|
+
await this.updateRun(preparedUpdateParam.id, preparedUpdateParam);
|
|
2179
|
+
}
|
|
2180
|
+
}
|
|
2181
|
+
return;
|
|
2182
|
+
}
|
|
2183
|
+
const sizeLimitBytes = (_e = (_d = (_c = this.serverInfo) == null ? void 0 : _c.batch_ingest_config) == null ? void 0 : _d.size_limit_bytes) != null ? _e : DEFAULT_BATCH_SIZE_LIMIT_BYTES;
|
|
2184
|
+
const batchChunks = {
|
|
2185
|
+
post: [],
|
|
2186
|
+
patch: []
|
|
2187
|
+
};
|
|
2188
|
+
let currentBatchSizeBytes = 0;
|
|
2189
|
+
for (const k of ["post", "patch"]) {
|
|
2190
|
+
const key = k;
|
|
2191
|
+
const batchItems = rawBatch[key].reverse();
|
|
2192
|
+
let batchItem = batchItems.pop();
|
|
2193
|
+
while (batchItem !== void 0) {
|
|
2194
|
+
const stringifiedBatchItem = JSON.stringify(batchItem);
|
|
2195
|
+
if (currentBatchSizeBytes > 0 && currentBatchSizeBytes + stringifiedBatchItem.length > sizeLimitBytes) {
|
|
2196
|
+
await this._postBatchIngestRuns(JSON.stringify(batchChunks));
|
|
2197
|
+
currentBatchSizeBytes = 0;
|
|
2198
|
+
batchChunks.post = [];
|
|
2199
|
+
batchChunks.patch = [];
|
|
2200
|
+
}
|
|
2201
|
+
currentBatchSizeBytes += stringifiedBatchItem.length;
|
|
2202
|
+
batchChunks[key].push(batchItem);
|
|
2203
|
+
batchItem = batchItems.pop();
|
|
2204
|
+
}
|
|
2205
|
+
}
|
|
2206
|
+
if (batchChunks.post.length > 0 || batchChunks.patch.length > 0) {
|
|
2207
|
+
await this._postBatchIngestRuns(JSON.stringify(batchChunks));
|
|
2208
|
+
}
|
|
2209
|
+
}
|
|
2210
|
+
async _postBatchIngestRuns(body) {
|
|
2211
|
+
const headers = __spreadProps(__spreadValues({}, this.headers), {
|
|
2212
|
+
"Content-Type": "application/json",
|
|
2213
|
+
Accept: "application/json"
|
|
2214
|
+
});
|
|
2215
|
+
const response = await this.batchIngestCaller.call(fetch, `${this.apiUrl}/runs/batch`, __spreadValues({
|
|
2216
|
+
method: "POST",
|
|
2217
|
+
headers,
|
|
2218
|
+
body,
|
|
2219
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2220
|
+
}, this.fetchOptions));
|
|
2221
|
+
await raiseForStatus(response, "batch create run");
|
|
2222
|
+
}
|
|
2223
|
+
async updateRun(runId, run) {
|
|
2224
|
+
assertUuid(runId);
|
|
2225
|
+
if (run.inputs) {
|
|
2226
|
+
run.inputs = this.processInputs(run.inputs);
|
|
2227
|
+
}
|
|
2228
|
+
if (run.outputs) {
|
|
2229
|
+
run.outputs = this.processOutputs(run.outputs);
|
|
2230
|
+
}
|
|
2231
|
+
const data = __spreadProps(__spreadValues({}, run), { id: runId });
|
|
2232
|
+
if (!this._filterForSampling([data], true).length) {
|
|
2233
|
+
return;
|
|
2234
|
+
}
|
|
2235
|
+
if (this.autoBatchTracing && data.trace_id !== void 0 && data.dotted_order !== void 0) {
|
|
2236
|
+
if (run.end_time !== void 0 && data.parent_run_id === void 0) {
|
|
2237
|
+
await this.processRunOperation({ action: "update", item: data }, true);
|
|
2238
|
+
return;
|
|
2239
|
+
} else {
|
|
2240
|
+
void this.processRunOperation({ action: "update", item: data }).catch(console.error);
|
|
2241
|
+
}
|
|
2242
|
+
return;
|
|
2243
|
+
}
|
|
2244
|
+
const headers = __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" });
|
|
2245
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}`, __spreadValues({
|
|
2246
|
+
method: "PATCH",
|
|
2247
|
+
headers,
|
|
2248
|
+
body: JSON.stringify(run),
|
|
2249
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2250
|
+
}, this.fetchOptions));
|
|
2251
|
+
await raiseForStatus(response, "update run");
|
|
2252
|
+
}
|
|
2253
|
+
async readRun(runId, { loadChildRuns } = { loadChildRuns: false }) {
|
|
2254
|
+
assertUuid(runId);
|
|
2255
|
+
let run = await this._get(`/runs/${runId}`);
|
|
2256
|
+
if (loadChildRuns && run.child_run_ids) {
|
|
2257
|
+
run = await this._loadChildRuns(run);
|
|
2258
|
+
}
|
|
2259
|
+
return run;
|
|
2260
|
+
}
|
|
2261
|
+
async getRunUrl({ runId, run, projectOpts }) {
|
|
2262
|
+
if (run !== void 0) {
|
|
2263
|
+
let sessionId;
|
|
2264
|
+
if (run.session_id) {
|
|
2265
|
+
sessionId = run.session_id;
|
|
2266
|
+
} else if (projectOpts == null ? void 0 : projectOpts.projectName) {
|
|
2267
|
+
sessionId = (await this.readProject({ projectName: projectOpts == null ? void 0 : projectOpts.projectName })).id;
|
|
2268
|
+
} else if (projectOpts == null ? void 0 : projectOpts.projectId) {
|
|
2269
|
+
sessionId = projectOpts == null ? void 0 : projectOpts.projectId;
|
|
2270
|
+
} else {
|
|
2271
|
+
const project = await this.readProject({
|
|
2272
|
+
projectName: getEnvironmentVariable("LANGCHAIN_PROJECT") || "default"
|
|
2273
|
+
});
|
|
2274
|
+
sessionId = project.id;
|
|
2275
|
+
}
|
|
2276
|
+
const tenantId = await this._getTenantId();
|
|
2277
|
+
return `${this.getHostUrl()}/o/${tenantId}/projects/p/${sessionId}/r/${run.id}?poll=true`;
|
|
2278
|
+
} else if (runId !== void 0) {
|
|
2279
|
+
const run_ = await this.readRun(runId);
|
|
2280
|
+
if (!run_.app_path) {
|
|
2281
|
+
throw new Error(`Run ${runId} has no app_path`);
|
|
2282
|
+
}
|
|
2283
|
+
const baseUrl = this.getHostUrl();
|
|
2284
|
+
return `${baseUrl}${run_.app_path}`;
|
|
2285
|
+
} else {
|
|
2286
|
+
throw new Error("Must provide either runId or run");
|
|
2287
|
+
}
|
|
2288
|
+
}
|
|
2289
|
+
async _loadChildRuns(run) {
|
|
2290
|
+
const childRuns = await toArray(this.listRuns({ id: run.child_run_ids }));
|
|
2291
|
+
const treemap = {};
|
|
2292
|
+
const runs = {};
|
|
2293
|
+
childRuns.sort((a, b) => {
|
|
2294
|
+
var _a, _b;
|
|
2295
|
+
return ((_a = a == null ? void 0 : a.dotted_order) != null ? _a : "").localeCompare((_b = b == null ? void 0 : b.dotted_order) != null ? _b : "");
|
|
2296
|
+
});
|
|
2297
|
+
for (const childRun of childRuns) {
|
|
2298
|
+
if (childRun.parent_run_id === null || childRun.parent_run_id === void 0) {
|
|
2299
|
+
throw new Error(`Child run ${childRun.id} has no parent`);
|
|
2300
|
+
}
|
|
2301
|
+
if (!(childRun.parent_run_id in treemap)) {
|
|
2302
|
+
treemap[childRun.parent_run_id] = [];
|
|
2303
|
+
}
|
|
2304
|
+
treemap[childRun.parent_run_id].push(childRun);
|
|
2305
|
+
runs[childRun.id] = childRun;
|
|
2306
|
+
}
|
|
2307
|
+
run.child_runs = treemap[run.id] || [];
|
|
2308
|
+
for (const runId in treemap) {
|
|
2309
|
+
if (runId !== run.id) {
|
|
2310
|
+
runs[runId].child_runs = treemap[runId];
|
|
2311
|
+
}
|
|
2312
|
+
}
|
|
2313
|
+
return run;
|
|
2314
|
+
}
|
|
2315
|
+
/**
|
|
2316
|
+
* List runs from the LangSmith server.
|
|
2317
|
+
* @param projectId - The ID of the project to filter by.
|
|
2318
|
+
* @param projectName - The name of the project to filter by.
|
|
2319
|
+
* @param parentRunId - The ID of the parent run to filter by.
|
|
2320
|
+
* @param traceId - The ID of the trace to filter by.
|
|
2321
|
+
* @param referenceExampleId - The ID of the reference example to filter by.
|
|
2322
|
+
* @param startTime - The start time to filter by.
|
|
2323
|
+
* @param isRoot - Indicates whether to only return root runs.
|
|
2324
|
+
* @param runType - The run type to filter by.
|
|
2325
|
+
* @param error - Indicates whether to filter by error runs.
|
|
2326
|
+
* @param id - The ID of the run to filter by.
|
|
2327
|
+
* @param query - The query string to filter by.
|
|
2328
|
+
* @param filter - The filter string to apply to the run spans.
|
|
2329
|
+
* @param traceFilter - The filter string to apply on the root run of the trace.
|
|
2330
|
+
* @param limit - The maximum number of runs to retrieve.
|
|
2331
|
+
* @returns {AsyncIterable<Run>} - The runs.
|
|
2332
|
+
*
|
|
2333
|
+
* @example
|
|
2334
|
+
* // List all runs in a project
|
|
2335
|
+
* const projectRuns = client.listRuns({ projectName: "<your_project>" });
|
|
2336
|
+
*
|
|
2337
|
+
* @example
|
|
2338
|
+
* // List LLM and Chat runs in the last 24 hours
|
|
2339
|
+
* const todaysLLMRuns = client.listRuns({
|
|
2340
|
+
* projectName: "<your_project>",
|
|
2341
|
+
* start_time: new Date(Date.now() - 24 * 60 * 60 * 1000),
|
|
2342
|
+
* run_type: "llm",
|
|
2343
|
+
* });
|
|
2344
|
+
*
|
|
2345
|
+
* @example
|
|
2346
|
+
* // List traces in a project
|
|
2347
|
+
* const rootRuns = client.listRuns({
|
|
2348
|
+
* projectName: "<your_project>",
|
|
2349
|
+
* execution_order: 1,
|
|
2350
|
+
* });
|
|
2351
|
+
*
|
|
2352
|
+
* @example
|
|
2353
|
+
* // List runs without errors
|
|
2354
|
+
* const correctRuns = client.listRuns({
|
|
2355
|
+
* projectName: "<your_project>",
|
|
2356
|
+
* error: false,
|
|
2357
|
+
* });
|
|
2358
|
+
*
|
|
2359
|
+
* @example
|
|
2360
|
+
* // List runs by run ID
|
|
2361
|
+
* const runIds = [
|
|
2362
|
+
* "a36092d2-4ad5-4fb4-9c0d-0dba9a2ed836",
|
|
2363
|
+
* "9398e6be-964f-4aa4-8ae9-ad78cd4b7074",
|
|
2364
|
+
* ];
|
|
2365
|
+
* const selectedRuns = client.listRuns({ run_ids: runIds });
|
|
2366
|
+
*
|
|
2367
|
+
* @example
|
|
2368
|
+
* // List all "chain" type runs that took more than 10 seconds and had `total_tokens` greater than 5000
|
|
2369
|
+
* const chainRuns = client.listRuns({
|
|
2370
|
+
* projectName: "<your_project>",
|
|
2371
|
+
* filter: 'and(eq(run_type, "chain"), gt(latency, 10), gt(total_tokens, 5000))',
|
|
2372
|
+
* });
|
|
2373
|
+
*
|
|
2374
|
+
* @example
|
|
2375
|
+
* // List all runs called "extractor" whose root of the trace was assigned feedback "user_score" score of 1
|
|
2376
|
+
* const goodExtractorRuns = client.listRuns({
|
|
2377
|
+
* projectName: "<your_project>",
|
|
2378
|
+
* filter: 'eq(name, "extractor")',
|
|
2379
|
+
* traceFilter: 'and(eq(feedback_key, "user_score"), eq(feedback_score, 1))',
|
|
2380
|
+
* });
|
|
2381
|
+
*
|
|
2382
|
+
* @example
|
|
2383
|
+
* // List all runs that started after a specific timestamp and either have "error" not equal to null or a "Correctness" feedback score equal to 0
|
|
2384
|
+
* const complexRuns = client.listRuns({
|
|
2385
|
+
* projectName: "<your_project>",
|
|
2386
|
+
* filter: 'and(gt(start_time, "2023-07-15T12:34:56Z"), or(neq(error, null), and(eq(feedback_key, "Correctness"), eq(feedback_score, 0.0))))',
|
|
2387
|
+
* });
|
|
2388
|
+
*
|
|
2389
|
+
* @example
|
|
2390
|
+
* // List all runs where `tags` include "experimental" or "beta" and `latency` is greater than 2 seconds
|
|
2391
|
+
* const taggedRuns = client.listRuns({
|
|
2392
|
+
* projectName: "<your_project>",
|
|
2393
|
+
* filter: 'and(or(has(tags, "experimental"), has(tags, "beta")), gt(latency, 2))',
|
|
2394
|
+
* });
|
|
2395
|
+
*/
|
|
2396
|
+
listRuns(props) {
|
|
2397
|
+
return __asyncGenerator(this, null, function* () {
|
|
2398
|
+
const { projectId, projectName, parentRunId, traceId, referenceExampleId, startTime, executionOrder, isRoot, runType, error, id, query, filter, traceFilter, treeFilter, limit, select } = props;
|
|
2399
|
+
let projectIds = [];
|
|
2400
|
+
if (projectId) {
|
|
2401
|
+
projectIds = Array.isArray(projectId) ? projectId : [projectId];
|
|
2402
|
+
}
|
|
2403
|
+
if (projectName) {
|
|
2404
|
+
const projectNames = Array.isArray(projectName) ? projectName : [projectName];
|
|
2405
|
+
const projectIds_ = yield new __await(Promise.all(projectNames.map((name) => this.readProject({ projectName: name }).then((project) => project.id))));
|
|
2406
|
+
projectIds.push(...projectIds_);
|
|
2407
|
+
}
|
|
2408
|
+
const default_select = [
|
|
2409
|
+
"app_path",
|
|
2410
|
+
"child_run_ids",
|
|
2411
|
+
"completion_cost",
|
|
2412
|
+
"completion_tokens",
|
|
2413
|
+
"dotted_order",
|
|
2414
|
+
"end_time",
|
|
2415
|
+
"error",
|
|
2416
|
+
"events",
|
|
2417
|
+
"extra",
|
|
2418
|
+
"feedback_stats",
|
|
2419
|
+
"first_token_time",
|
|
2420
|
+
"id",
|
|
2421
|
+
"inputs",
|
|
2422
|
+
"name",
|
|
2423
|
+
"outputs",
|
|
2424
|
+
"parent_run_id",
|
|
2425
|
+
"parent_run_ids",
|
|
2426
|
+
"prompt_cost",
|
|
2427
|
+
"prompt_tokens",
|
|
2428
|
+
"reference_example_id",
|
|
2429
|
+
"run_type",
|
|
2430
|
+
"session_id",
|
|
2431
|
+
"start_time",
|
|
2432
|
+
"status",
|
|
2433
|
+
"tags",
|
|
2434
|
+
"total_cost",
|
|
2435
|
+
"total_tokens",
|
|
2436
|
+
"trace_id"
|
|
2437
|
+
];
|
|
2438
|
+
const body = {
|
|
2439
|
+
session: projectIds.length ? projectIds : null,
|
|
2440
|
+
run_type: runType,
|
|
2441
|
+
reference_example: referenceExampleId,
|
|
2442
|
+
query,
|
|
2443
|
+
filter,
|
|
2444
|
+
trace_filter: traceFilter,
|
|
2445
|
+
tree_filter: treeFilter,
|
|
2446
|
+
execution_order: executionOrder,
|
|
2447
|
+
parent_run: parentRunId,
|
|
2448
|
+
start_time: startTime ? startTime.toISOString() : null,
|
|
2449
|
+
error,
|
|
2450
|
+
id,
|
|
2451
|
+
limit,
|
|
2452
|
+
trace: traceId,
|
|
2453
|
+
select: select ? select : default_select,
|
|
2454
|
+
is_root: isRoot
|
|
2455
|
+
};
|
|
2456
|
+
let runsYielded = 0;
|
|
2457
|
+
try {
|
|
2458
|
+
for (var iter = __forAwait(this._getCursorPaginatedList("/runs/query", body)), more, temp, error2; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
2459
|
+
const runs = temp.value;
|
|
2460
|
+
if (limit) {
|
|
2461
|
+
if (runsYielded >= limit) {
|
|
2462
|
+
break;
|
|
2463
|
+
}
|
|
2464
|
+
if (runs.length + runsYielded > limit) {
|
|
2465
|
+
const newRuns = runs.slice(0, limit - runsYielded);
|
|
2466
|
+
yield* __yieldStar(newRuns);
|
|
2467
|
+
break;
|
|
2468
|
+
}
|
|
2469
|
+
runsYielded += runs.length;
|
|
2470
|
+
yield* __yieldStar(runs);
|
|
2471
|
+
} else {
|
|
2472
|
+
yield* __yieldStar(runs);
|
|
2473
|
+
}
|
|
2474
|
+
}
|
|
2475
|
+
} catch (temp) {
|
|
2476
|
+
error2 = [temp];
|
|
2477
|
+
} finally {
|
|
2478
|
+
try {
|
|
2479
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2480
|
+
} finally {
|
|
2481
|
+
if (error2)
|
|
2482
|
+
throw error2[0];
|
|
2483
|
+
}
|
|
2484
|
+
}
|
|
2485
|
+
});
|
|
2486
|
+
}
|
|
2487
|
+
async shareRun(runId, { shareId } = {}) {
|
|
2488
|
+
const data = {
|
|
2489
|
+
run_id: runId,
|
|
2490
|
+
share_token: shareId || v4_default()
|
|
2491
|
+
};
|
|
2492
|
+
assertUuid(runId);
|
|
2493
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, __spreadValues({
|
|
2494
|
+
method: "PUT",
|
|
2495
|
+
headers: this.headers,
|
|
2496
|
+
body: JSON.stringify(data),
|
|
2497
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2498
|
+
}, this.fetchOptions));
|
|
2499
|
+
const result = await response.json();
|
|
2500
|
+
if (result === null || !("share_token" in result)) {
|
|
2501
|
+
throw new Error("Invalid response from server");
|
|
2502
|
+
}
|
|
2503
|
+
return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
|
|
2504
|
+
}
|
|
2505
|
+
async unshareRun(runId) {
|
|
2506
|
+
assertUuid(runId);
|
|
2507
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, __spreadValues({
|
|
2508
|
+
method: "DELETE",
|
|
2509
|
+
headers: this.headers,
|
|
2510
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2511
|
+
}, this.fetchOptions));
|
|
2512
|
+
await raiseForStatus(response, "unshare run");
|
|
2513
|
+
}
|
|
2514
|
+
async readRunSharedLink(runId) {
|
|
2515
|
+
assertUuid(runId);
|
|
2516
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/runs/${runId}/share`, __spreadValues({
|
|
2517
|
+
method: "GET",
|
|
2518
|
+
headers: this.headers,
|
|
2519
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2520
|
+
}, this.fetchOptions));
|
|
2521
|
+
const result = await response.json();
|
|
2522
|
+
if (result === null || !("share_token" in result)) {
|
|
2523
|
+
return void 0;
|
|
2524
|
+
}
|
|
2525
|
+
return `${this.getHostUrl()}/public/${result["share_token"]}/r`;
|
|
2526
|
+
}
|
|
2527
|
+
async listSharedRuns(shareToken, { runIds } = {}) {
|
|
2528
|
+
const queryParams = new URLSearchParams({
|
|
2529
|
+
share_token: shareToken
|
|
2530
|
+
});
|
|
2531
|
+
if (runIds !== void 0) {
|
|
2532
|
+
for (const runId of runIds) {
|
|
2533
|
+
queryParams.append("id", runId);
|
|
2534
|
+
}
|
|
2535
|
+
}
|
|
2536
|
+
assertUuid(shareToken);
|
|
2537
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/runs${queryParams}`, __spreadValues({
|
|
2538
|
+
method: "GET",
|
|
2539
|
+
headers: this.headers,
|
|
2540
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2541
|
+
}, this.fetchOptions));
|
|
2542
|
+
const runs = await response.json();
|
|
2543
|
+
return runs;
|
|
2544
|
+
}
|
|
2545
|
+
async readDatasetSharedSchema(datasetId, datasetName) {
|
|
2546
|
+
if (!datasetId && !datasetName) {
|
|
2547
|
+
throw new Error("Either datasetId or datasetName must be given");
|
|
2548
|
+
}
|
|
2549
|
+
if (!datasetId) {
|
|
2550
|
+
const dataset = await this.readDataset({ datasetName });
|
|
2551
|
+
datasetId = dataset.id;
|
|
2552
|
+
}
|
|
2553
|
+
assertUuid(datasetId);
|
|
2554
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, __spreadValues({
|
|
2555
|
+
method: "GET",
|
|
2556
|
+
headers: this.headers,
|
|
2557
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2558
|
+
}, this.fetchOptions));
|
|
2559
|
+
const shareSchema = await response.json();
|
|
2560
|
+
shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
|
|
2561
|
+
return shareSchema;
|
|
2562
|
+
}
|
|
2563
|
+
async shareDataset(datasetId, datasetName) {
|
|
2564
|
+
if (!datasetId && !datasetName) {
|
|
2565
|
+
throw new Error("Either datasetId or datasetName must be given");
|
|
2566
|
+
}
|
|
2567
|
+
if (!datasetId) {
|
|
2568
|
+
const dataset = await this.readDataset({ datasetName });
|
|
2569
|
+
datasetId = dataset.id;
|
|
2570
|
+
}
|
|
2571
|
+
const data = {
|
|
2572
|
+
dataset_id: datasetId
|
|
2573
|
+
};
|
|
2574
|
+
assertUuid(datasetId);
|
|
2575
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, __spreadValues({
|
|
2576
|
+
method: "PUT",
|
|
2577
|
+
headers: this.headers,
|
|
2578
|
+
body: JSON.stringify(data),
|
|
2579
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2580
|
+
}, this.fetchOptions));
|
|
2581
|
+
const shareSchema = await response.json();
|
|
2582
|
+
shareSchema.url = `${this.getHostUrl()}/public/${shareSchema.share_token}/d`;
|
|
2583
|
+
return shareSchema;
|
|
2584
|
+
}
|
|
2585
|
+
async unshareDataset(datasetId) {
|
|
2586
|
+
assertUuid(datasetId);
|
|
2587
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${datasetId}/share`, __spreadValues({
|
|
2588
|
+
method: "DELETE",
|
|
2589
|
+
headers: this.headers,
|
|
2590
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2591
|
+
}, this.fetchOptions));
|
|
2592
|
+
await raiseForStatus(response, "unshare dataset");
|
|
2593
|
+
}
|
|
2594
|
+
async readSharedDataset(shareToken) {
|
|
2595
|
+
assertUuid(shareToken);
|
|
2596
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/public/${shareToken}/datasets`, __spreadValues({
|
|
2597
|
+
method: "GET",
|
|
2598
|
+
headers: this.headers,
|
|
2599
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2600
|
+
}, this.fetchOptions));
|
|
2601
|
+
const dataset = await response.json();
|
|
2602
|
+
return dataset;
|
|
2603
|
+
}
|
|
2604
|
+
async createProject({ projectName, description = null, metadata = null, upsert = false, projectExtra = null, referenceDatasetId = null }) {
|
|
2605
|
+
const upsert_ = upsert ? `?upsert=true` : "";
|
|
2606
|
+
const endpoint = `${this.apiUrl}/sessions${upsert_}`;
|
|
2607
|
+
const extra = projectExtra || {};
|
|
2608
|
+
if (metadata) {
|
|
2609
|
+
extra["metadata"] = metadata;
|
|
2610
|
+
}
|
|
2611
|
+
const body = {
|
|
2612
|
+
name: projectName,
|
|
2613
|
+
extra,
|
|
2614
|
+
description
|
|
2615
|
+
};
|
|
2616
|
+
if (referenceDatasetId !== null) {
|
|
2617
|
+
body["reference_dataset_id"] = referenceDatasetId;
|
|
2618
|
+
}
|
|
2619
|
+
const response = await this.caller.call(fetch, endpoint, __spreadValues({
|
|
2620
|
+
method: "POST",
|
|
2621
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
2622
|
+
body: JSON.stringify(body),
|
|
2623
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2624
|
+
}, this.fetchOptions));
|
|
2625
|
+
const result = await response.json();
|
|
2626
|
+
if (!response.ok) {
|
|
2627
|
+
throw new Error(`Failed to create session ${projectName}: ${response.status} ${response.statusText}`);
|
|
2628
|
+
}
|
|
2629
|
+
return result;
|
|
2630
|
+
}
|
|
2631
|
+
async updateProject(projectId, { name = null, description = null, metadata = null, projectExtra = null, endTime = null }) {
|
|
2632
|
+
const endpoint = `${this.apiUrl}/sessions/${projectId}`;
|
|
2633
|
+
let extra = projectExtra;
|
|
2634
|
+
if (metadata) {
|
|
2635
|
+
extra = __spreadProps(__spreadValues({}, extra || {}), { metadata });
|
|
2636
|
+
}
|
|
2637
|
+
const body = {
|
|
2638
|
+
name,
|
|
2639
|
+
extra,
|
|
2640
|
+
description,
|
|
2641
|
+
end_time: endTime ? new Date(endTime).toISOString() : null
|
|
2642
|
+
};
|
|
2643
|
+
const response = await this.caller.call(fetch, endpoint, __spreadValues({
|
|
2644
|
+
method: "PATCH",
|
|
2645
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
2646
|
+
body: JSON.stringify(body),
|
|
2647
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2648
|
+
}, this.fetchOptions));
|
|
2649
|
+
const result = await response.json();
|
|
2650
|
+
if (!response.ok) {
|
|
2651
|
+
throw new Error(`Failed to update project ${projectId}: ${response.status} ${response.statusText}`);
|
|
2652
|
+
}
|
|
2653
|
+
return result;
|
|
2654
|
+
}
|
|
2655
|
+
async hasProject({ projectId, projectName }) {
|
|
2656
|
+
let path = "/sessions";
|
|
2657
|
+
const params = new URLSearchParams();
|
|
2658
|
+
if (projectId !== void 0 && projectName !== void 0) {
|
|
2659
|
+
throw new Error("Must provide either projectName or projectId, not both");
|
|
2660
|
+
} else if (projectId !== void 0) {
|
|
2661
|
+
assertUuid(projectId);
|
|
2662
|
+
path += `/${projectId}`;
|
|
2663
|
+
} else if (projectName !== void 0) {
|
|
2664
|
+
params.append("name", projectName);
|
|
2665
|
+
} else {
|
|
2666
|
+
throw new Error("Must provide projectName or projectId");
|
|
2667
|
+
}
|
|
2668
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}${path}?${params}`, __spreadValues({
|
|
2669
|
+
method: "GET",
|
|
2670
|
+
headers: this.headers,
|
|
2671
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2672
|
+
}, this.fetchOptions));
|
|
2673
|
+
try {
|
|
2674
|
+
const result = await response.json();
|
|
2675
|
+
if (!response.ok) {
|
|
2676
|
+
return false;
|
|
2677
|
+
}
|
|
2678
|
+
if (Array.isArray(result)) {
|
|
2679
|
+
return result.length > 0;
|
|
2680
|
+
}
|
|
2681
|
+
return true;
|
|
2682
|
+
} catch (e) {
|
|
2683
|
+
return false;
|
|
2684
|
+
}
|
|
2685
|
+
}
|
|
2686
|
+
async readProject({ projectId, projectName, includeStats }) {
|
|
2687
|
+
let path = "/sessions";
|
|
2688
|
+
const params = new URLSearchParams();
|
|
2689
|
+
if (projectId !== void 0 && projectName !== void 0) {
|
|
2690
|
+
throw new Error("Must provide either projectName or projectId, not both");
|
|
2691
|
+
} else if (projectId !== void 0) {
|
|
2692
|
+
assertUuid(projectId);
|
|
2693
|
+
path += `/${projectId}`;
|
|
2694
|
+
} else if (projectName !== void 0) {
|
|
2695
|
+
params.append("name", projectName);
|
|
2696
|
+
} else {
|
|
2697
|
+
throw new Error("Must provide projectName or projectId");
|
|
2698
|
+
}
|
|
2699
|
+
if (includeStats !== void 0) {
|
|
2700
|
+
params.append("include_stats", includeStats.toString());
|
|
2701
|
+
}
|
|
2702
|
+
const response = await this._get(path, params);
|
|
2703
|
+
let result;
|
|
2704
|
+
if (Array.isArray(response)) {
|
|
2705
|
+
if (response.length === 0) {
|
|
2706
|
+
throw new Error(`Project[id=${projectId}, name=${projectName}] not found`);
|
|
2707
|
+
}
|
|
2708
|
+
result = response[0];
|
|
2709
|
+
} else {
|
|
2710
|
+
result = response;
|
|
2711
|
+
}
|
|
2712
|
+
return result;
|
|
2713
|
+
}
|
|
2714
|
+
async getProjectUrl({ projectId, projectName }) {
|
|
2715
|
+
if (projectId === void 0 && projectName === void 0) {
|
|
2716
|
+
throw new Error("Must provide either projectName or projectId");
|
|
2717
|
+
}
|
|
2718
|
+
const project = await this.readProject({ projectId, projectName });
|
|
2719
|
+
const tenantId = await this._getTenantId();
|
|
2720
|
+
return `${this.getHostUrl()}/o/${tenantId}/projects/p/${project.id}`;
|
|
2721
|
+
}
|
|
2722
|
+
async getDatasetUrl({ datasetId, datasetName }) {
|
|
2723
|
+
if (datasetId === void 0 && datasetName === void 0) {
|
|
2724
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
2725
|
+
}
|
|
2726
|
+
const dataset = await this.readDataset({ datasetId, datasetName });
|
|
2727
|
+
const tenantId = await this._getTenantId();
|
|
2728
|
+
return `${this.getHostUrl()}/o/${tenantId}/datasets/${dataset.id}`;
|
|
2729
|
+
}
|
|
2730
|
+
async _getTenantId() {
|
|
2731
|
+
if (this._tenantId !== null) {
|
|
2732
|
+
return this._tenantId;
|
|
2733
|
+
}
|
|
2734
|
+
const queryParams = new URLSearchParams({ limit: "1" });
|
|
2735
|
+
try {
|
|
2736
|
+
for (var iter = __forAwait(this._getPaginated("/sessions", queryParams)), more, temp, error; more = !(temp = await iter.next()).done; more = false) {
|
|
2737
|
+
const projects = temp.value;
|
|
2738
|
+
this._tenantId = projects[0].tenant_id;
|
|
2739
|
+
return projects[0].tenant_id;
|
|
2740
|
+
}
|
|
2741
|
+
} catch (temp) {
|
|
2742
|
+
error = [temp];
|
|
2743
|
+
} finally {
|
|
2744
|
+
try {
|
|
2745
|
+
more && (temp = iter.return) && await temp.call(iter);
|
|
2746
|
+
} finally {
|
|
2747
|
+
if (error)
|
|
2748
|
+
throw error[0];
|
|
2749
|
+
}
|
|
2750
|
+
}
|
|
2751
|
+
throw new Error("No projects found to resolve tenant.");
|
|
2752
|
+
}
|
|
2753
|
+
listProjects() {
|
|
2754
|
+
return __asyncGenerator(this, arguments, function* ({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, referenceFree } = {}) {
|
|
2755
|
+
const params = new URLSearchParams();
|
|
2756
|
+
if (projectIds !== void 0) {
|
|
2757
|
+
for (const projectId of projectIds) {
|
|
2758
|
+
params.append("id", projectId);
|
|
2759
|
+
}
|
|
2760
|
+
}
|
|
2761
|
+
if (name !== void 0) {
|
|
2762
|
+
params.append("name", name);
|
|
2763
|
+
}
|
|
2764
|
+
if (nameContains !== void 0) {
|
|
2765
|
+
params.append("name_contains", nameContains);
|
|
2766
|
+
}
|
|
2767
|
+
if (referenceDatasetId !== void 0) {
|
|
2768
|
+
params.append("reference_dataset", referenceDatasetId);
|
|
2769
|
+
} else if (referenceDatasetName !== void 0) {
|
|
2770
|
+
const dataset = yield new __await(this.readDataset({
|
|
2771
|
+
datasetName: referenceDatasetName
|
|
2772
|
+
}));
|
|
2773
|
+
params.append("reference_dataset", dataset.id);
|
|
2774
|
+
}
|
|
2775
|
+
if (referenceFree !== void 0) {
|
|
2776
|
+
params.append("reference_free", referenceFree.toString());
|
|
2777
|
+
}
|
|
2778
|
+
try {
|
|
2779
|
+
for (var iter = __forAwait(this._getPaginated("/sessions", params)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
2780
|
+
const projects = temp.value;
|
|
2781
|
+
yield* __yieldStar(projects);
|
|
2782
|
+
}
|
|
2783
|
+
} catch (temp) {
|
|
2784
|
+
error = [temp];
|
|
2785
|
+
} finally {
|
|
2786
|
+
try {
|
|
2787
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2788
|
+
} finally {
|
|
2789
|
+
if (error)
|
|
2790
|
+
throw error[0];
|
|
2791
|
+
}
|
|
2792
|
+
}
|
|
2793
|
+
});
|
|
2794
|
+
}
|
|
2795
|
+
async deleteProject({ projectId, projectName }) {
|
|
2796
|
+
let projectId_;
|
|
2797
|
+
if (projectId === void 0 && projectName === void 0) {
|
|
2798
|
+
throw new Error("Must provide projectName or projectId");
|
|
2799
|
+
} else if (projectId !== void 0 && projectName !== void 0) {
|
|
2800
|
+
throw new Error("Must provide either projectName or projectId, not both");
|
|
2801
|
+
} else if (projectId === void 0) {
|
|
2802
|
+
projectId_ = (await this.readProject({ projectName })).id;
|
|
2803
|
+
} else {
|
|
2804
|
+
projectId_ = projectId;
|
|
2805
|
+
}
|
|
2806
|
+
assertUuid(projectId_);
|
|
2807
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/sessions/${projectId_}`, __spreadValues({
|
|
2808
|
+
method: "DELETE",
|
|
2809
|
+
headers: this.headers,
|
|
2810
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2811
|
+
}, this.fetchOptions));
|
|
2812
|
+
await raiseForStatus(response, `delete session ${projectId_} (${projectName})`);
|
|
2813
|
+
}
|
|
2814
|
+
async uploadCsv({ csvFile, fileName, inputKeys, outputKeys, description, dataType, name }) {
|
|
2815
|
+
const url = `${this.apiUrl}/datasets/upload`;
|
|
2816
|
+
const formData = new FormData();
|
|
2817
|
+
formData.append("file", csvFile, fileName);
|
|
2818
|
+
inputKeys.forEach((key) => {
|
|
2819
|
+
formData.append("input_keys", key);
|
|
2820
|
+
});
|
|
2821
|
+
outputKeys.forEach((key) => {
|
|
2822
|
+
formData.append("output_keys", key);
|
|
2823
|
+
});
|
|
2824
|
+
if (description) {
|
|
2825
|
+
formData.append("description", description);
|
|
2826
|
+
}
|
|
2827
|
+
if (dataType) {
|
|
2828
|
+
formData.append("data_type", dataType);
|
|
2829
|
+
}
|
|
2830
|
+
if (name) {
|
|
2831
|
+
formData.append("name", name);
|
|
2832
|
+
}
|
|
2833
|
+
const response = await this.caller.call(fetch, url, __spreadValues({
|
|
2834
|
+
method: "POST",
|
|
2835
|
+
headers: this.headers,
|
|
2836
|
+
body: formData,
|
|
2837
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2838
|
+
}, this.fetchOptions));
|
|
2839
|
+
if (!response.ok) {
|
|
2840
|
+
const result2 = await response.json();
|
|
2841
|
+
if (result2.detail && result2.detail.includes("already exists")) {
|
|
2842
|
+
throw new Error(`Dataset ${fileName} already exists`);
|
|
2843
|
+
}
|
|
2844
|
+
throw new Error(`Failed to upload CSV: ${response.status} ${response.statusText}`);
|
|
2845
|
+
}
|
|
2846
|
+
const result = await response.json();
|
|
2847
|
+
return result;
|
|
2848
|
+
}
|
|
2849
|
+
async createDataset(name, { description, dataType } = {}) {
|
|
2850
|
+
const body = {
|
|
2851
|
+
name,
|
|
2852
|
+
description
|
|
2853
|
+
};
|
|
2854
|
+
if (dataType) {
|
|
2855
|
+
body.data_type = dataType;
|
|
2856
|
+
}
|
|
2857
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/datasets`, __spreadValues({
|
|
2858
|
+
method: "POST",
|
|
2859
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
2860
|
+
body: JSON.stringify(body),
|
|
2861
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2862
|
+
}, this.fetchOptions));
|
|
2863
|
+
if (!response.ok) {
|
|
2864
|
+
const result2 = await response.json();
|
|
2865
|
+
if (result2.detail && result2.detail.includes("already exists")) {
|
|
2866
|
+
throw new Error(`Dataset ${name} already exists`);
|
|
2867
|
+
}
|
|
2868
|
+
throw new Error(`Failed to create dataset ${response.status} ${response.statusText}`);
|
|
2869
|
+
}
|
|
2870
|
+
const result = await response.json();
|
|
2871
|
+
return result;
|
|
2872
|
+
}
|
|
2873
|
+
async readDataset({ datasetId, datasetName }) {
|
|
2874
|
+
let path = "/datasets";
|
|
2875
|
+
const params = new URLSearchParams({ limit: "1" });
|
|
2876
|
+
if (datasetId !== void 0 && datasetName !== void 0) {
|
|
2877
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
2878
|
+
} else if (datasetId !== void 0) {
|
|
2879
|
+
assertUuid(datasetId);
|
|
2880
|
+
path += `/${datasetId}`;
|
|
2881
|
+
} else if (datasetName !== void 0) {
|
|
2882
|
+
params.append("name", datasetName);
|
|
2883
|
+
} else {
|
|
2884
|
+
throw new Error("Must provide datasetName or datasetId");
|
|
2885
|
+
}
|
|
2886
|
+
const response = await this._get(path, params);
|
|
2887
|
+
let result;
|
|
2888
|
+
if (Array.isArray(response)) {
|
|
2889
|
+
if (response.length === 0) {
|
|
2890
|
+
throw new Error(`Dataset[id=${datasetId}, name=${datasetName}] not found`);
|
|
2891
|
+
}
|
|
2892
|
+
result = response[0];
|
|
2893
|
+
} else {
|
|
2894
|
+
result = response;
|
|
2895
|
+
}
|
|
2896
|
+
return result;
|
|
2897
|
+
}
|
|
2898
|
+
async hasDataset({ datasetId, datasetName }) {
|
|
2899
|
+
try {
|
|
2900
|
+
await this.readDataset({ datasetId, datasetName });
|
|
2901
|
+
return true;
|
|
2902
|
+
} catch (e) {
|
|
2903
|
+
if (
|
|
2904
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
2905
|
+
e instanceof Error && e.message.toLocaleLowerCase().includes("not found")
|
|
2906
|
+
) {
|
|
2907
|
+
return false;
|
|
2908
|
+
}
|
|
2909
|
+
throw e;
|
|
2910
|
+
}
|
|
2911
|
+
}
|
|
2912
|
+
async diffDatasetVersions({ datasetId, datasetName, fromVersion, toVersion }) {
|
|
2913
|
+
let datasetId_ = datasetId;
|
|
2914
|
+
if (datasetId_ === void 0 && datasetName === void 0) {
|
|
2915
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
2916
|
+
} else if (datasetId_ !== void 0 && datasetName !== void 0) {
|
|
2917
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
2918
|
+
} else if (datasetId_ === void 0) {
|
|
2919
|
+
const dataset = await this.readDataset({ datasetName });
|
|
2920
|
+
datasetId_ = dataset.id;
|
|
2921
|
+
}
|
|
2922
|
+
const urlParams = new URLSearchParams({
|
|
2923
|
+
from_version: typeof fromVersion === "string" ? fromVersion : fromVersion.toISOString(),
|
|
2924
|
+
to_version: typeof toVersion === "string" ? toVersion : toVersion.toISOString()
|
|
2925
|
+
});
|
|
2926
|
+
const response = await this._get(`/datasets/${datasetId_}/versions/diff`, urlParams);
|
|
2927
|
+
return response;
|
|
2928
|
+
}
|
|
2929
|
+
async readDatasetOpenaiFinetuning({ datasetId, datasetName }) {
|
|
2930
|
+
const path = "/datasets";
|
|
2931
|
+
if (datasetId !== void 0) {
|
|
2932
|
+
} else if (datasetName !== void 0) {
|
|
2933
|
+
datasetId = (await this.readDataset({ datasetName })).id;
|
|
2934
|
+
} else {
|
|
2935
|
+
throw new Error("Must provide datasetName or datasetId");
|
|
2936
|
+
}
|
|
2937
|
+
const response = await this._getResponse(`${path}/${datasetId}/openai_ft`);
|
|
2938
|
+
const datasetText = await response.text();
|
|
2939
|
+
const dataset = datasetText.trim().split("\n").map((line) => JSON.parse(line));
|
|
2940
|
+
return dataset;
|
|
2941
|
+
}
|
|
2942
|
+
listDatasets() {
|
|
2943
|
+
return __asyncGenerator(this, arguments, function* ({ limit = 100, offset = 0, datasetIds, datasetName, datasetNameContains } = {}) {
|
|
2944
|
+
const path = "/datasets";
|
|
2945
|
+
const params = new URLSearchParams({
|
|
2946
|
+
limit: limit.toString(),
|
|
2947
|
+
offset: offset.toString()
|
|
2948
|
+
});
|
|
2949
|
+
if (datasetIds !== void 0) {
|
|
2950
|
+
for (const id_ of datasetIds) {
|
|
2951
|
+
params.append("id", id_);
|
|
2952
|
+
}
|
|
2953
|
+
}
|
|
2954
|
+
if (datasetName !== void 0) {
|
|
2955
|
+
params.append("name", datasetName);
|
|
2956
|
+
}
|
|
2957
|
+
if (datasetNameContains !== void 0) {
|
|
2958
|
+
params.append("name_contains", datasetNameContains);
|
|
2959
|
+
}
|
|
2960
|
+
try {
|
|
2961
|
+
for (var iter = __forAwait(this._getPaginated(path, params)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
2962
|
+
const datasets = temp.value;
|
|
2963
|
+
yield* __yieldStar(datasets);
|
|
2964
|
+
}
|
|
2965
|
+
} catch (temp) {
|
|
2966
|
+
error = [temp];
|
|
2967
|
+
} finally {
|
|
2968
|
+
try {
|
|
2969
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
2970
|
+
} finally {
|
|
2971
|
+
if (error)
|
|
2972
|
+
throw error[0];
|
|
2973
|
+
}
|
|
2974
|
+
}
|
|
2975
|
+
});
|
|
2976
|
+
}
|
|
2977
|
+
/**
|
|
2978
|
+
* Update a dataset
|
|
2979
|
+
* @param props The dataset details to update
|
|
2980
|
+
* @returns The updated dataset
|
|
2981
|
+
*/
|
|
2982
|
+
async updateDataset(props) {
|
|
2983
|
+
const _a = props, { datasetId, datasetName } = _a, update = __objRest(_a, ["datasetId", "datasetName"]);
|
|
2984
|
+
if (!datasetId && !datasetName) {
|
|
2985
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
2986
|
+
}
|
|
2987
|
+
const _datasetId = datasetId != null ? datasetId : (await this.readDataset({ datasetName })).id;
|
|
2988
|
+
assertUuid(_datasetId);
|
|
2989
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/${_datasetId}`, __spreadValues({
|
|
2990
|
+
method: "PATCH",
|
|
2991
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
2992
|
+
body: JSON.stringify(update),
|
|
2993
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
2994
|
+
}, this.fetchOptions));
|
|
2995
|
+
if (!response.ok) {
|
|
2996
|
+
throw new Error(`Failed to update dataset ${_datasetId}: ${response.status} ${response.statusText}`);
|
|
2997
|
+
}
|
|
2998
|
+
return await response.json();
|
|
2999
|
+
}
|
|
3000
|
+
async deleteDataset({ datasetId, datasetName }) {
|
|
3001
|
+
let path = "/datasets";
|
|
3002
|
+
let datasetId_ = datasetId;
|
|
3003
|
+
if (datasetId !== void 0 && datasetName !== void 0) {
|
|
3004
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
3005
|
+
} else if (datasetName !== void 0) {
|
|
3006
|
+
const dataset = await this.readDataset({ datasetName });
|
|
3007
|
+
datasetId_ = dataset.id;
|
|
3008
|
+
}
|
|
3009
|
+
if (datasetId_ !== void 0) {
|
|
3010
|
+
assertUuid(datasetId_);
|
|
3011
|
+
path += `/${datasetId_}`;
|
|
3012
|
+
} else {
|
|
3013
|
+
throw new Error("Must provide datasetName or datasetId");
|
|
3014
|
+
}
|
|
3015
|
+
const response = await this.caller.call(fetch, this.apiUrl + path, __spreadValues({
|
|
3016
|
+
method: "DELETE",
|
|
3017
|
+
headers: this.headers,
|
|
3018
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3019
|
+
}, this.fetchOptions));
|
|
3020
|
+
if (!response.ok) {
|
|
3021
|
+
throw new Error(`Failed to delete ${path}: ${response.status} ${response.statusText}`);
|
|
3022
|
+
}
|
|
3023
|
+
await response.json();
|
|
3024
|
+
}
|
|
3025
|
+
async createExample(inputs, outputs, { datasetId, datasetName, createdAt, exampleId, metadata, split }) {
|
|
3026
|
+
let datasetId_ = datasetId;
|
|
3027
|
+
if (datasetId_ === void 0 && datasetName === void 0) {
|
|
3028
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
3029
|
+
} else if (datasetId_ !== void 0 && datasetName !== void 0) {
|
|
3030
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
3031
|
+
} else if (datasetId_ === void 0) {
|
|
3032
|
+
const dataset = await this.readDataset({ datasetName });
|
|
3033
|
+
datasetId_ = dataset.id;
|
|
3034
|
+
}
|
|
3035
|
+
const createdAt_ = createdAt || /* @__PURE__ */ new Date();
|
|
3036
|
+
const data = {
|
|
3037
|
+
dataset_id: datasetId_,
|
|
3038
|
+
inputs,
|
|
3039
|
+
outputs,
|
|
3040
|
+
created_at: createdAt_ == null ? void 0 : createdAt_.toISOString(),
|
|
3041
|
+
id: exampleId,
|
|
3042
|
+
metadata,
|
|
3043
|
+
split
|
|
3044
|
+
};
|
|
3045
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/examples`, __spreadValues({
|
|
3046
|
+
method: "POST",
|
|
3047
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
3048
|
+
body: JSON.stringify(data),
|
|
3049
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3050
|
+
}, this.fetchOptions));
|
|
3051
|
+
if (!response.ok) {
|
|
3052
|
+
throw new Error(`Failed to create example: ${response.status} ${response.statusText}`);
|
|
3053
|
+
}
|
|
3054
|
+
const result = await response.json();
|
|
3055
|
+
return result;
|
|
3056
|
+
}
|
|
3057
|
+
async createExamples(props) {
|
|
3058
|
+
const { inputs, outputs, metadata, sourceRunIds, exampleIds, datasetId, datasetName } = props;
|
|
3059
|
+
let datasetId_ = datasetId;
|
|
3060
|
+
if (datasetId_ === void 0 && datasetName === void 0) {
|
|
3061
|
+
throw new Error("Must provide either datasetName or datasetId");
|
|
3062
|
+
} else if (datasetId_ !== void 0 && datasetName !== void 0) {
|
|
3063
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
3064
|
+
} else if (datasetId_ === void 0) {
|
|
3065
|
+
const dataset = await this.readDataset({ datasetName });
|
|
3066
|
+
datasetId_ = dataset.id;
|
|
3067
|
+
}
|
|
3068
|
+
const formattedExamples = inputs.map((input, idx) => {
|
|
3069
|
+
return {
|
|
3070
|
+
dataset_id: datasetId_,
|
|
3071
|
+
inputs: input,
|
|
3072
|
+
outputs: outputs ? outputs[idx] : void 0,
|
|
3073
|
+
metadata: metadata ? metadata[idx] : void 0,
|
|
3074
|
+
split: props.splits ? props.splits[idx] : void 0,
|
|
3075
|
+
id: exampleIds ? exampleIds[idx] : void 0,
|
|
3076
|
+
source_run_id: sourceRunIds ? sourceRunIds[idx] : void 0
|
|
3077
|
+
};
|
|
3078
|
+
});
|
|
3079
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/examples/bulk`, __spreadValues({
|
|
3080
|
+
method: "POST",
|
|
3081
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
3082
|
+
body: JSON.stringify(formattedExamples),
|
|
3083
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3084
|
+
}, this.fetchOptions));
|
|
3085
|
+
if (!response.ok) {
|
|
3086
|
+
throw new Error(`Failed to create examples: ${response.status} ${response.statusText}`);
|
|
3087
|
+
}
|
|
3088
|
+
const result = await response.json();
|
|
3089
|
+
return result;
|
|
3090
|
+
}
|
|
3091
|
+
async createLLMExample(input, generation, options) {
|
|
3092
|
+
return this.createExample({ input }, { output: generation }, options);
|
|
3093
|
+
}
|
|
3094
|
+
async createChatExample(input, generations, options) {
|
|
3095
|
+
const finalInput = input.map((message) => {
|
|
3096
|
+
if (isLangChainMessage(message)) {
|
|
3097
|
+
return convertLangChainMessageToExample(message);
|
|
3098
|
+
}
|
|
3099
|
+
return message;
|
|
3100
|
+
});
|
|
3101
|
+
const finalOutput = isLangChainMessage(generations) ? convertLangChainMessageToExample(generations) : generations;
|
|
3102
|
+
return this.createExample({ input: finalInput }, { output: finalOutput }, options);
|
|
3103
|
+
}
|
|
3104
|
+
async readExample(exampleId) {
|
|
3105
|
+
assertUuid(exampleId);
|
|
3106
|
+
const path = `/examples/${exampleId}`;
|
|
3107
|
+
return await this._get(path);
|
|
3108
|
+
}
|
|
3109
|
+
listExamples() {
|
|
3110
|
+
return __asyncGenerator(this, arguments, function* ({ datasetId, datasetName, exampleIds, asOf, splits, inlineS3Urls, metadata, limit, offset, filter } = {}) {
|
|
3111
|
+
let datasetId_;
|
|
3112
|
+
if (datasetId !== void 0 && datasetName !== void 0) {
|
|
3113
|
+
throw new Error("Must provide either datasetName or datasetId, not both");
|
|
3114
|
+
} else if (datasetId !== void 0) {
|
|
3115
|
+
datasetId_ = datasetId;
|
|
3116
|
+
} else if (datasetName !== void 0) {
|
|
3117
|
+
const dataset = yield new __await(this.readDataset({ datasetName }));
|
|
3118
|
+
datasetId_ = dataset.id;
|
|
3119
|
+
} else {
|
|
3120
|
+
throw new Error("Must provide a datasetName or datasetId");
|
|
3121
|
+
}
|
|
3122
|
+
const params = new URLSearchParams({ dataset: datasetId_ });
|
|
3123
|
+
const dataset_version = asOf ? typeof asOf === "string" ? asOf : asOf == null ? void 0 : asOf.toISOString() : void 0;
|
|
3124
|
+
if (dataset_version) {
|
|
3125
|
+
params.append("as_of", dataset_version);
|
|
3126
|
+
}
|
|
3127
|
+
const inlineS3Urls_ = inlineS3Urls != null ? inlineS3Urls : true;
|
|
3128
|
+
params.append("inline_s3_urls", inlineS3Urls_.toString());
|
|
3129
|
+
if (exampleIds !== void 0) {
|
|
3130
|
+
for (const id_ of exampleIds) {
|
|
3131
|
+
params.append("id", id_);
|
|
3132
|
+
}
|
|
3133
|
+
}
|
|
3134
|
+
if (splits !== void 0) {
|
|
3135
|
+
for (const split of splits) {
|
|
3136
|
+
params.append("splits", split);
|
|
3137
|
+
}
|
|
3138
|
+
}
|
|
3139
|
+
if (metadata !== void 0) {
|
|
3140
|
+
const serializedMetadata = JSON.stringify(metadata);
|
|
3141
|
+
params.append("metadata", serializedMetadata);
|
|
3142
|
+
}
|
|
3143
|
+
if (limit !== void 0) {
|
|
3144
|
+
params.append("limit", limit.toString());
|
|
3145
|
+
}
|
|
3146
|
+
if (offset !== void 0) {
|
|
3147
|
+
params.append("offset", offset.toString());
|
|
3148
|
+
}
|
|
3149
|
+
if (filter !== void 0) {
|
|
3150
|
+
params.append("filter", filter);
|
|
3151
|
+
}
|
|
3152
|
+
let i = 0;
|
|
3153
|
+
try {
|
|
3154
|
+
for (var iter = __forAwait(this._getPaginated("/examples", params)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
3155
|
+
const examples = temp.value;
|
|
3156
|
+
for (const example of examples) {
|
|
3157
|
+
yield example;
|
|
3158
|
+
i++;
|
|
3159
|
+
}
|
|
3160
|
+
if (limit !== void 0 && i >= limit) {
|
|
3161
|
+
break;
|
|
3162
|
+
}
|
|
3163
|
+
}
|
|
3164
|
+
} catch (temp) {
|
|
3165
|
+
error = [temp];
|
|
3166
|
+
} finally {
|
|
3167
|
+
try {
|
|
3168
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
3169
|
+
} finally {
|
|
3170
|
+
if (error)
|
|
3171
|
+
throw error[0];
|
|
3172
|
+
}
|
|
3173
|
+
}
|
|
3174
|
+
});
|
|
3175
|
+
}
|
|
3176
|
+
async deleteExample(exampleId) {
|
|
3177
|
+
assertUuid(exampleId);
|
|
3178
|
+
const path = `/examples/${exampleId}`;
|
|
3179
|
+
const response = await this.caller.call(fetch, this.apiUrl + path, __spreadValues({
|
|
3180
|
+
method: "DELETE",
|
|
3181
|
+
headers: this.headers,
|
|
3182
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3183
|
+
}, this.fetchOptions));
|
|
3184
|
+
if (!response.ok) {
|
|
3185
|
+
throw new Error(`Failed to delete ${path}: ${response.status} ${response.statusText}`);
|
|
3186
|
+
}
|
|
3187
|
+
await response.json();
|
|
3188
|
+
}
|
|
3189
|
+
async updateExample(exampleId, update) {
|
|
3190
|
+
assertUuid(exampleId);
|
|
3191
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/examples/${exampleId}`, __spreadValues({
|
|
3192
|
+
method: "PATCH",
|
|
3193
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
3194
|
+
body: JSON.stringify(update),
|
|
3195
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3196
|
+
}, this.fetchOptions));
|
|
3197
|
+
if (!response.ok) {
|
|
3198
|
+
throw new Error(`Failed to update example ${exampleId}: ${response.status} ${response.statusText}`);
|
|
3199
|
+
}
|
|
3200
|
+
const result = await response.json();
|
|
3201
|
+
return result;
|
|
3202
|
+
}
|
|
3203
|
+
/**
|
|
3204
|
+
* @deprecated This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.
|
|
3205
|
+
*/
|
|
3206
|
+
async evaluateRun(run, evaluator, { sourceInfo, loadChildRuns, referenceExample } = { loadChildRuns: false }) {
|
|
3207
|
+
warnOnce("This method is deprecated and will be removed in future LangSmith versions, use `evaluate` from `langsmith/evaluation` instead.");
|
|
3208
|
+
let run_;
|
|
3209
|
+
if (typeof run === "string") {
|
|
3210
|
+
run_ = await this.readRun(run, { loadChildRuns });
|
|
3211
|
+
} else if (typeof run === "object" && "id" in run) {
|
|
3212
|
+
run_ = run;
|
|
3213
|
+
} else {
|
|
3214
|
+
throw new Error(`Invalid run type: ${typeof run}`);
|
|
3215
|
+
}
|
|
3216
|
+
if (run_.reference_example_id !== null && run_.reference_example_id !== void 0) {
|
|
3217
|
+
referenceExample = await this.readExample(run_.reference_example_id);
|
|
3218
|
+
}
|
|
3219
|
+
const feedbackResult = await evaluator.evaluateRun(run_, referenceExample);
|
|
3220
|
+
const [_, feedbacks] = await this._logEvaluationFeedback(feedbackResult, run_, sourceInfo);
|
|
3221
|
+
return feedbacks[0];
|
|
3222
|
+
}
|
|
3223
|
+
async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId }) {
|
|
3224
|
+
var _a;
|
|
3225
|
+
if (!runId && !projectId) {
|
|
3226
|
+
throw new Error("One of runId or projectId must be provided");
|
|
3227
|
+
}
|
|
3228
|
+
if (runId && projectId) {
|
|
3229
|
+
throw new Error("Only one of runId or projectId can be provided");
|
|
3230
|
+
}
|
|
3231
|
+
const feedback_source = {
|
|
3232
|
+
type: feedbackSourceType != null ? feedbackSourceType : "api",
|
|
3233
|
+
metadata: sourceInfo != null ? sourceInfo : {}
|
|
3234
|
+
};
|
|
3235
|
+
if (sourceRunId !== void 0 && (feedback_source == null ? void 0 : feedback_source.metadata) !== void 0 && !feedback_source.metadata["__run"]) {
|
|
3236
|
+
feedback_source.metadata["__run"] = { run_id: sourceRunId };
|
|
3237
|
+
}
|
|
3238
|
+
if ((feedback_source == null ? void 0 : feedback_source.metadata) !== void 0 && ((_a = feedback_source.metadata["__run"]) == null ? void 0 : _a.run_id) !== void 0) {
|
|
3239
|
+
assertUuid(feedback_source.metadata["__run"].run_id);
|
|
3240
|
+
}
|
|
3241
|
+
const feedback = {
|
|
3242
|
+
id: feedbackId != null ? feedbackId : v4_default(),
|
|
3243
|
+
run_id: runId,
|
|
3244
|
+
key,
|
|
3245
|
+
score,
|
|
3246
|
+
value,
|
|
3247
|
+
correction,
|
|
3248
|
+
comment,
|
|
3249
|
+
feedback_source,
|
|
3250
|
+
comparative_experiment_id: comparativeExperimentId,
|
|
3251
|
+
feedbackConfig,
|
|
3252
|
+
session_id: projectId
|
|
3253
|
+
};
|
|
3254
|
+
const url = `${this.apiUrl}/feedback`;
|
|
3255
|
+
const response = await this.caller.call(fetch, url, __spreadValues({
|
|
3256
|
+
method: "POST",
|
|
3257
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
3258
|
+
body: JSON.stringify(feedback),
|
|
3259
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3260
|
+
}, this.fetchOptions));
|
|
3261
|
+
await raiseForStatus(response, "create feedback");
|
|
3262
|
+
return feedback;
|
|
3263
|
+
}
|
|
3264
|
+
async updateFeedback(feedbackId, { score, value, correction, comment }) {
|
|
3265
|
+
const feedbackUpdate = {};
|
|
3266
|
+
if (score !== void 0 && score !== null) {
|
|
3267
|
+
feedbackUpdate["score"] = score;
|
|
3268
|
+
}
|
|
3269
|
+
if (value !== void 0 && value !== null) {
|
|
3270
|
+
feedbackUpdate["value"] = value;
|
|
3271
|
+
}
|
|
3272
|
+
if (correction !== void 0 && correction !== null) {
|
|
3273
|
+
feedbackUpdate["correction"] = correction;
|
|
3274
|
+
}
|
|
3275
|
+
if (comment !== void 0 && comment !== null) {
|
|
3276
|
+
feedbackUpdate["comment"] = comment;
|
|
3277
|
+
}
|
|
3278
|
+
assertUuid(feedbackId);
|
|
3279
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/${feedbackId}`, __spreadValues({
|
|
3280
|
+
method: "PATCH",
|
|
3281
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
3282
|
+
body: JSON.stringify(feedbackUpdate),
|
|
3283
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3284
|
+
}, this.fetchOptions));
|
|
3285
|
+
await raiseForStatus(response, "update feedback");
|
|
3286
|
+
}
|
|
3287
|
+
async readFeedback(feedbackId) {
|
|
3288
|
+
assertUuid(feedbackId);
|
|
3289
|
+
const path = `/feedback/${feedbackId}`;
|
|
3290
|
+
const response = await this._get(path);
|
|
3291
|
+
return response;
|
|
3292
|
+
}
|
|
3293
|
+
async deleteFeedback(feedbackId) {
|
|
3294
|
+
assertUuid(feedbackId);
|
|
3295
|
+
const path = `/feedback/${feedbackId}`;
|
|
3296
|
+
const response = await this.caller.call(fetch, this.apiUrl + path, __spreadValues({
|
|
3297
|
+
method: "DELETE",
|
|
3298
|
+
headers: this.headers,
|
|
3299
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3300
|
+
}, this.fetchOptions));
|
|
3301
|
+
if (!response.ok) {
|
|
3302
|
+
throw new Error(`Failed to delete ${path}: ${response.status} ${response.statusText}`);
|
|
3303
|
+
}
|
|
3304
|
+
await response.json();
|
|
3305
|
+
}
|
|
3306
|
+
listFeedback() {
|
|
3307
|
+
return __asyncGenerator(this, arguments, function* ({ runIds, feedbackKeys, feedbackSourceTypes } = {}) {
|
|
3308
|
+
const queryParams = new URLSearchParams();
|
|
3309
|
+
if (runIds) {
|
|
3310
|
+
queryParams.append("run", runIds.join(","));
|
|
3311
|
+
}
|
|
3312
|
+
if (feedbackKeys) {
|
|
3313
|
+
for (const key of feedbackKeys) {
|
|
3314
|
+
queryParams.append("key", key);
|
|
3315
|
+
}
|
|
3316
|
+
}
|
|
3317
|
+
if (feedbackSourceTypes) {
|
|
3318
|
+
for (const type of feedbackSourceTypes) {
|
|
3319
|
+
queryParams.append("source", type);
|
|
3320
|
+
}
|
|
3321
|
+
}
|
|
3322
|
+
try {
|
|
3323
|
+
for (var iter = __forAwait(this._getPaginated("/feedback", queryParams)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
3324
|
+
const feedbacks = temp.value;
|
|
3325
|
+
yield* __yieldStar(feedbacks);
|
|
3326
|
+
}
|
|
3327
|
+
} catch (temp) {
|
|
3328
|
+
error = [temp];
|
|
3329
|
+
} finally {
|
|
3330
|
+
try {
|
|
3331
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
3332
|
+
} finally {
|
|
3333
|
+
if (error)
|
|
3334
|
+
throw error[0];
|
|
3335
|
+
}
|
|
3336
|
+
}
|
|
3337
|
+
});
|
|
3338
|
+
}
|
|
3339
|
+
/**
|
|
3340
|
+
* Creates a presigned feedback token and URL.
|
|
3341
|
+
*
|
|
3342
|
+
* The token can be used to authorize feedback metrics without
|
|
3343
|
+
* needing an API key. This is useful for giving browser-based
|
|
3344
|
+
* applications the ability to submit feedback without needing
|
|
3345
|
+
* to expose an API key.
|
|
3346
|
+
*
|
|
3347
|
+
* @param runId - The ID of the run.
|
|
3348
|
+
* @param feedbackKey - The feedback key.
|
|
3349
|
+
* @param options - Additional options for the token.
|
|
3350
|
+
* @param options.expiration - The expiration time for the token.
|
|
3351
|
+
*
|
|
3352
|
+
* @returns A promise that resolves to a FeedbackIngestToken.
|
|
3353
|
+
*/
|
|
3354
|
+
async createPresignedFeedbackToken(runId, feedbackKey, { expiration, feedbackConfig } = {}) {
|
|
3355
|
+
const body = {
|
|
3356
|
+
run_id: runId,
|
|
3357
|
+
feedback_key: feedbackKey,
|
|
3358
|
+
feedback_config: feedbackConfig
|
|
3359
|
+
};
|
|
3360
|
+
if (expiration) {
|
|
3361
|
+
if (typeof expiration === "string") {
|
|
3362
|
+
body["expires_at"] = expiration;
|
|
3363
|
+
} else if ((expiration == null ? void 0 : expiration.hours) || (expiration == null ? void 0 : expiration.minutes) || (expiration == null ? void 0 : expiration.days)) {
|
|
3364
|
+
body["expires_in"] = expiration;
|
|
3365
|
+
}
|
|
3366
|
+
} else {
|
|
3367
|
+
body["expires_in"] = {
|
|
3368
|
+
hours: 3
|
|
3369
|
+
};
|
|
3370
|
+
}
|
|
3371
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/feedback/tokens`, __spreadValues({
|
|
3372
|
+
method: "POST",
|
|
3373
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
3374
|
+
body: JSON.stringify(body),
|
|
3375
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3376
|
+
}, this.fetchOptions));
|
|
3377
|
+
const result = await response.json();
|
|
3378
|
+
return result;
|
|
3379
|
+
}
|
|
3380
|
+
async createComparativeExperiment({ name, experimentIds, referenceDatasetId, createdAt, description, metadata, id }) {
|
|
3381
|
+
var _a;
|
|
3382
|
+
if (experimentIds.length === 0) {
|
|
3383
|
+
throw new Error("At least one experiment is required");
|
|
3384
|
+
}
|
|
3385
|
+
if (!referenceDatasetId) {
|
|
3386
|
+
referenceDatasetId = (await this.readProject({
|
|
3387
|
+
projectId: experimentIds[0]
|
|
3388
|
+
})).reference_dataset_id;
|
|
3389
|
+
}
|
|
3390
|
+
if (!referenceDatasetId == null) {
|
|
3391
|
+
throw new Error("A reference dataset is required");
|
|
3392
|
+
}
|
|
3393
|
+
const body = {
|
|
3394
|
+
id,
|
|
3395
|
+
name,
|
|
3396
|
+
experiment_ids: experimentIds,
|
|
3397
|
+
reference_dataset_id: referenceDatasetId,
|
|
3398
|
+
description,
|
|
3399
|
+
created_at: (_a = createdAt != null ? createdAt : /* @__PURE__ */ new Date()) == null ? void 0 : _a.toISOString(),
|
|
3400
|
+
extra: {}
|
|
3401
|
+
};
|
|
3402
|
+
if (metadata)
|
|
3403
|
+
body.extra["metadata"] = metadata;
|
|
3404
|
+
const response = await this.caller.call(fetch, `${this.apiUrl}/datasets/comparative`, __spreadValues({
|
|
3405
|
+
method: "POST",
|
|
3406
|
+
headers: __spreadProps(__spreadValues({}, this.headers), { "Content-Type": "application/json" }),
|
|
3407
|
+
body: JSON.stringify(body),
|
|
3408
|
+
signal: AbortSignal.timeout(this.timeout_ms)
|
|
3409
|
+
}, this.fetchOptions));
|
|
3410
|
+
return await response.json();
|
|
3411
|
+
}
|
|
3412
|
+
/**
|
|
3413
|
+
* Retrieves a list of presigned feedback tokens for a given run ID.
|
|
3414
|
+
* @param runId The ID of the run.
|
|
3415
|
+
* @returns An async iterable of FeedbackIngestToken objects.
|
|
3416
|
+
*/
|
|
3417
|
+
listPresignedFeedbackTokens(runId) {
|
|
3418
|
+
return __asyncGenerator(this, null, function* () {
|
|
3419
|
+
assertUuid(runId);
|
|
3420
|
+
const params = new URLSearchParams({ run_id: runId });
|
|
3421
|
+
try {
|
|
3422
|
+
for (var iter = __forAwait(this._getPaginated("/feedback/tokens", params)), more, temp, error; more = !(temp = yield new __await(iter.next())).done; more = false) {
|
|
3423
|
+
const tokens = temp.value;
|
|
3424
|
+
yield* __yieldStar(tokens);
|
|
3425
|
+
}
|
|
3426
|
+
} catch (temp) {
|
|
3427
|
+
error = [temp];
|
|
3428
|
+
} finally {
|
|
3429
|
+
try {
|
|
3430
|
+
more && (temp = iter.return) && (yield new __await(temp.call(iter)));
|
|
3431
|
+
} finally {
|
|
3432
|
+
if (error)
|
|
3433
|
+
throw error[0];
|
|
3434
|
+
}
|
|
3435
|
+
}
|
|
3436
|
+
});
|
|
3437
|
+
}
|
|
3438
|
+
_selectEvalResults(results) {
|
|
3439
|
+
let results_;
|
|
3440
|
+
if ("results" in results) {
|
|
3441
|
+
results_ = results.results;
|
|
3442
|
+
} else {
|
|
3443
|
+
results_ = [results];
|
|
3444
|
+
}
|
|
3445
|
+
return results_;
|
|
3446
|
+
}
|
|
3447
|
+
async _logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
|
|
3448
|
+
const evalResults = this._selectEvalResults(evaluatorResponse);
|
|
3449
|
+
const feedbacks = [];
|
|
3450
|
+
for (const res of evalResults) {
|
|
3451
|
+
let sourceInfo_ = sourceInfo || {};
|
|
3452
|
+
if (res.evaluatorInfo) {
|
|
3453
|
+
sourceInfo_ = __spreadValues(__spreadValues({}, res.evaluatorInfo), sourceInfo_);
|
|
3454
|
+
}
|
|
3455
|
+
let runId_ = null;
|
|
3456
|
+
if (res.targetRunId) {
|
|
3457
|
+
runId_ = res.targetRunId;
|
|
3458
|
+
} else if (run) {
|
|
3459
|
+
runId_ = run.id;
|
|
3460
|
+
}
|
|
3461
|
+
feedbacks.push(await this.createFeedback(runId_, res.key, {
|
|
3462
|
+
score: res.score,
|
|
3463
|
+
value: res.value,
|
|
3464
|
+
comment: res.comment,
|
|
3465
|
+
correction: res.correction,
|
|
3466
|
+
sourceInfo: sourceInfo_,
|
|
3467
|
+
sourceRunId: res.sourceRunId,
|
|
3468
|
+
feedbackConfig: res.feedbackConfig,
|
|
3469
|
+
feedbackSourceType: "model"
|
|
3470
|
+
}));
|
|
3471
|
+
}
|
|
3472
|
+
return [evalResults, feedbacks];
|
|
3473
|
+
}
|
|
3474
|
+
async logEvaluationFeedback(evaluatorResponse, run, sourceInfo) {
|
|
3475
|
+
const [results] = await this._logEvaluationFeedback(evaluatorResponse, run, sourceInfo);
|
|
3476
|
+
return results;
|
|
3477
|
+
}
|
|
3478
|
+
};
|
|
3479
|
+
|
|
3480
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/index.js
|
|
3481
|
+
var __version__ = "0.1.36";
|
|
3482
|
+
|
|
3483
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/utils/env.js
|
|
3484
|
+
var globalEnv;
|
|
3485
|
+
var isBrowser = () => typeof window !== "undefined" && typeof window.document !== "undefined";
|
|
3486
|
+
var isWebWorker = () => typeof globalThis === "object" && globalThis.constructor && globalThis.constructor.name === "DedicatedWorkerGlobalScope";
|
|
3487
|
+
var isJsDom = () => typeof window !== "undefined" && window.name === "nodejs" || typeof navigator !== "undefined" && (navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom"));
|
|
3488
|
+
var isDeno = () => typeof Deno !== "undefined";
|
|
3489
|
+
var isNode = () => typeof process !== "undefined" && typeof process.versions !== "undefined" && typeof process.versions.node !== "undefined" && !isDeno();
|
|
3490
|
+
var getEnv = () => {
|
|
3491
|
+
if (globalEnv) {
|
|
3492
|
+
return globalEnv;
|
|
3493
|
+
}
|
|
3494
|
+
if (isBrowser()) {
|
|
3495
|
+
globalEnv = "browser";
|
|
3496
|
+
} else if (isNode()) {
|
|
3497
|
+
globalEnv = "node";
|
|
3498
|
+
} else if (isWebWorker()) {
|
|
3499
|
+
globalEnv = "webworker";
|
|
3500
|
+
} else if (isJsDom()) {
|
|
3501
|
+
globalEnv = "jsdom";
|
|
3502
|
+
} else if (isDeno()) {
|
|
3503
|
+
globalEnv = "deno";
|
|
3504
|
+
} else {
|
|
3505
|
+
globalEnv = "other";
|
|
3506
|
+
}
|
|
3507
|
+
return globalEnv;
|
|
3508
|
+
};
|
|
3509
|
+
var runtimeEnvironment;
|
|
3510
|
+
async function getRuntimeEnvironment() {
|
|
3511
|
+
if (runtimeEnvironment === void 0) {
|
|
3512
|
+
const env = getEnv();
|
|
3513
|
+
const releaseEnv = getShas();
|
|
3514
|
+
runtimeEnvironment = __spreadValues({
|
|
3515
|
+
library: "langsmith",
|
|
3516
|
+
runtime: env,
|
|
3517
|
+
sdk: "langsmith-js",
|
|
3518
|
+
sdk_version: __version__
|
|
3519
|
+
}, releaseEnv);
|
|
3520
|
+
}
|
|
3521
|
+
return runtimeEnvironment;
|
|
3522
|
+
}
|
|
3523
|
+
function getLangChainEnvVarsMetadata() {
|
|
3524
|
+
const allEnvVars = getEnvironmentVariables() || {};
|
|
3525
|
+
const envVars = {};
|
|
3526
|
+
const excluded = [
|
|
3527
|
+
"LANGCHAIN_API_KEY",
|
|
3528
|
+
"LANGCHAIN_ENDPOINT",
|
|
3529
|
+
"LANGCHAIN_TRACING_V2",
|
|
3530
|
+
"LANGCHAIN_PROJECT",
|
|
3531
|
+
"LANGCHAIN_SESSION"
|
|
3532
|
+
];
|
|
3533
|
+
for (const [key, value] of Object.entries(allEnvVars)) {
|
|
3534
|
+
if (key.startsWith("LANGCHAIN_") && typeof value === "string" && !excluded.includes(key) && !key.toLowerCase().includes("key") && !key.toLowerCase().includes("secret") && !key.toLowerCase().includes("token")) {
|
|
3535
|
+
if (key === "LANGCHAIN_REVISION_ID") {
|
|
3536
|
+
envVars["revision_id"] = value;
|
|
3537
|
+
} else {
|
|
3538
|
+
envVars[key] = value;
|
|
3539
|
+
}
|
|
3540
|
+
}
|
|
3541
|
+
}
|
|
3542
|
+
return envVars;
|
|
3543
|
+
}
|
|
3544
|
+
function getEnvironmentVariables() {
|
|
3545
|
+
try {
|
|
3546
|
+
if (typeof process !== "undefined" && process.env) {
|
|
3547
|
+
return Object.entries(process.env).reduce((acc, [key, value]) => {
|
|
3548
|
+
acc[key] = String(value);
|
|
3549
|
+
return acc;
|
|
3550
|
+
}, {});
|
|
3551
|
+
}
|
|
3552
|
+
return void 0;
|
|
3553
|
+
} catch (e) {
|
|
3554
|
+
return void 0;
|
|
3555
|
+
}
|
|
3556
|
+
}
|
|
3557
|
+
function getEnvironmentVariable(name) {
|
|
3558
|
+
var _a;
|
|
3559
|
+
try {
|
|
3560
|
+
return typeof process !== "undefined" ? (
|
|
3561
|
+
// eslint-disable-next-line no-process-env
|
|
3562
|
+
(_a = process.env) == null ? void 0 : _a[name]
|
|
3563
|
+
) : void 0;
|
|
3564
|
+
} catch (e) {
|
|
3565
|
+
return void 0;
|
|
3566
|
+
}
|
|
3567
|
+
}
|
|
3568
|
+
var cachedCommitSHAs;
|
|
3569
|
+
function getShas() {
|
|
3570
|
+
if (cachedCommitSHAs !== void 0) {
|
|
3571
|
+
return cachedCommitSHAs;
|
|
3572
|
+
}
|
|
3573
|
+
const common_release_envs = [
|
|
3574
|
+
"VERCEL_GIT_COMMIT_SHA",
|
|
3575
|
+
"NEXT_PUBLIC_VERCEL_GIT_COMMIT_SHA",
|
|
3576
|
+
"COMMIT_REF",
|
|
3577
|
+
"RENDER_GIT_COMMIT",
|
|
3578
|
+
"CI_COMMIT_SHA",
|
|
3579
|
+
"CIRCLE_SHA1",
|
|
3580
|
+
"CF_PAGES_COMMIT_SHA",
|
|
3581
|
+
"REACT_APP_GIT_SHA",
|
|
3582
|
+
"SOURCE_VERSION",
|
|
3583
|
+
"GITHUB_SHA",
|
|
3584
|
+
"TRAVIS_COMMIT",
|
|
3585
|
+
"GIT_COMMIT",
|
|
3586
|
+
"BUILD_VCS_NUMBER",
|
|
3587
|
+
"bamboo_planRepository_revision",
|
|
3588
|
+
"Build.SourceVersion",
|
|
3589
|
+
"BITBUCKET_COMMIT",
|
|
3590
|
+
"DRONE_COMMIT_SHA",
|
|
3591
|
+
"SEMAPHORE_GIT_SHA",
|
|
3592
|
+
"BUILDKITE_COMMIT"
|
|
3593
|
+
];
|
|
3594
|
+
const shas = {};
|
|
3595
|
+
for (const env of common_release_envs) {
|
|
3596
|
+
const envVar = getEnvironmentVariable(env);
|
|
3597
|
+
if (envVar !== void 0) {
|
|
3598
|
+
shas[env] = envVar;
|
|
3599
|
+
}
|
|
3600
|
+
}
|
|
3601
|
+
cachedCommitSHAs = shas;
|
|
3602
|
+
return shas;
|
|
3603
|
+
}
|
|
3604
|
+
|
|
3605
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/env.js
|
|
3606
|
+
var isTracingEnabled = (tracingEnabled) => {
|
|
3607
|
+
if (tracingEnabled !== void 0) {
|
|
3608
|
+
return tracingEnabled;
|
|
3609
|
+
}
|
|
3610
|
+
const envVars = [
|
|
3611
|
+
"LANGSMITH_TRACING_V2",
|
|
3612
|
+
"LANGCHAIN_TRACING_V2",
|
|
3613
|
+
"LANGSMITH_TRACING",
|
|
3614
|
+
"LANGCHAIN_TRACING"
|
|
3615
|
+
];
|
|
3616
|
+
return !!envVars.find((envVar) => getEnvironmentVariable(envVar) === "true");
|
|
3617
|
+
};
|
|
3618
|
+
|
|
3619
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/run_trees.js
|
|
3620
|
+
function stripNonAlphanumeric(input) {
|
|
3621
|
+
return input.replace(/[-:.]/g, "");
|
|
3622
|
+
}
|
|
3623
|
+
function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
|
|
3624
|
+
const paddedOrder = executionOrder.toFixed(0).slice(0, 3).padStart(3, "0");
|
|
3625
|
+
return stripNonAlphanumeric(`${new Date(epoch).toISOString().slice(0, -1)}${paddedOrder}Z`) + runId;
|
|
3626
|
+
}
|
|
3627
|
+
var Baggage = class _Baggage {
|
|
3628
|
+
constructor(metadata, tags) {
|
|
3629
|
+
Object.defineProperty(this, "metadata", {
|
|
3630
|
+
enumerable: true,
|
|
3631
|
+
configurable: true,
|
|
3632
|
+
writable: true,
|
|
3633
|
+
value: void 0
|
|
3634
|
+
});
|
|
3635
|
+
Object.defineProperty(this, "tags", {
|
|
3636
|
+
enumerable: true,
|
|
3637
|
+
configurable: true,
|
|
3638
|
+
writable: true,
|
|
3639
|
+
value: void 0
|
|
3640
|
+
});
|
|
3641
|
+
this.metadata = metadata;
|
|
3642
|
+
this.tags = tags;
|
|
3643
|
+
}
|
|
3644
|
+
static fromHeader(value) {
|
|
3645
|
+
const items = value.split(",");
|
|
3646
|
+
let metadata = {};
|
|
3647
|
+
let tags = [];
|
|
3648
|
+
for (const item of items) {
|
|
3649
|
+
const [key, uriValue] = item.split("=");
|
|
3650
|
+
const value2 = decodeURIComponent(uriValue);
|
|
3651
|
+
if (key === "langsmith-metadata") {
|
|
3652
|
+
metadata = JSON.parse(value2);
|
|
3653
|
+
} else if (key === "langsmith-tags") {
|
|
3654
|
+
tags = value2.split(",");
|
|
3655
|
+
}
|
|
3656
|
+
}
|
|
3657
|
+
return new _Baggage(metadata, tags);
|
|
3658
|
+
}
|
|
3659
|
+
toHeader() {
|
|
3660
|
+
const items = [];
|
|
3661
|
+
if (this.metadata && Object.keys(this.metadata).length > 0) {
|
|
3662
|
+
items.push(`langsmith-metadata=${encodeURIComponent(JSON.stringify(this.metadata))}`);
|
|
3663
|
+
}
|
|
3664
|
+
if (this.tags && this.tags.length > 0) {
|
|
3665
|
+
items.push(`langsmith-tags=${encodeURIComponent(this.tags.join(","))}`);
|
|
3666
|
+
}
|
|
3667
|
+
return items.join(",");
|
|
3668
|
+
}
|
|
3669
|
+
};
|
|
3670
|
+
var RunTree = class _RunTree {
|
|
3671
|
+
constructor(originalConfig) {
|
|
3672
|
+
var _b, _c, _d, _e, _f;
|
|
3673
|
+
Object.defineProperty(this, "id", {
|
|
3674
|
+
enumerable: true,
|
|
3675
|
+
configurable: true,
|
|
3676
|
+
writable: true,
|
|
3677
|
+
value: void 0
|
|
3678
|
+
});
|
|
3679
|
+
Object.defineProperty(this, "name", {
|
|
3680
|
+
enumerable: true,
|
|
3681
|
+
configurable: true,
|
|
3682
|
+
writable: true,
|
|
3683
|
+
value: void 0
|
|
3684
|
+
});
|
|
3685
|
+
Object.defineProperty(this, "run_type", {
|
|
3686
|
+
enumerable: true,
|
|
3687
|
+
configurable: true,
|
|
3688
|
+
writable: true,
|
|
3689
|
+
value: void 0
|
|
3690
|
+
});
|
|
3691
|
+
Object.defineProperty(this, "project_name", {
|
|
3692
|
+
enumerable: true,
|
|
3693
|
+
configurable: true,
|
|
3694
|
+
writable: true,
|
|
3695
|
+
value: void 0
|
|
3696
|
+
});
|
|
3697
|
+
Object.defineProperty(this, "parent_run", {
|
|
3698
|
+
enumerable: true,
|
|
3699
|
+
configurable: true,
|
|
3700
|
+
writable: true,
|
|
3701
|
+
value: void 0
|
|
3702
|
+
});
|
|
3703
|
+
Object.defineProperty(this, "child_runs", {
|
|
3704
|
+
enumerable: true,
|
|
3705
|
+
configurable: true,
|
|
3706
|
+
writable: true,
|
|
3707
|
+
value: void 0
|
|
3708
|
+
});
|
|
3709
|
+
Object.defineProperty(this, "start_time", {
|
|
3710
|
+
enumerable: true,
|
|
3711
|
+
configurable: true,
|
|
3712
|
+
writable: true,
|
|
3713
|
+
value: void 0
|
|
3714
|
+
});
|
|
3715
|
+
Object.defineProperty(this, "end_time", {
|
|
3716
|
+
enumerable: true,
|
|
3717
|
+
configurable: true,
|
|
3718
|
+
writable: true,
|
|
3719
|
+
value: void 0
|
|
3720
|
+
});
|
|
3721
|
+
Object.defineProperty(this, "extra", {
|
|
3722
|
+
enumerable: true,
|
|
3723
|
+
configurable: true,
|
|
3724
|
+
writable: true,
|
|
3725
|
+
value: void 0
|
|
3726
|
+
});
|
|
3727
|
+
Object.defineProperty(this, "tags", {
|
|
3728
|
+
enumerable: true,
|
|
3729
|
+
configurable: true,
|
|
3730
|
+
writable: true,
|
|
3731
|
+
value: void 0
|
|
3732
|
+
});
|
|
3733
|
+
Object.defineProperty(this, "error", {
|
|
3734
|
+
enumerable: true,
|
|
3735
|
+
configurable: true,
|
|
3736
|
+
writable: true,
|
|
3737
|
+
value: void 0
|
|
3738
|
+
});
|
|
3739
|
+
Object.defineProperty(this, "serialized", {
|
|
3740
|
+
enumerable: true,
|
|
3741
|
+
configurable: true,
|
|
3742
|
+
writable: true,
|
|
3743
|
+
value: void 0
|
|
3744
|
+
});
|
|
3745
|
+
Object.defineProperty(this, "inputs", {
|
|
3746
|
+
enumerable: true,
|
|
3747
|
+
configurable: true,
|
|
3748
|
+
writable: true,
|
|
3749
|
+
value: void 0
|
|
3750
|
+
});
|
|
3751
|
+
Object.defineProperty(this, "outputs", {
|
|
3752
|
+
enumerable: true,
|
|
3753
|
+
configurable: true,
|
|
3754
|
+
writable: true,
|
|
3755
|
+
value: void 0
|
|
3756
|
+
});
|
|
3757
|
+
Object.defineProperty(this, "reference_example_id", {
|
|
3758
|
+
enumerable: true,
|
|
3759
|
+
configurable: true,
|
|
3760
|
+
writable: true,
|
|
3761
|
+
value: void 0
|
|
3762
|
+
});
|
|
3763
|
+
Object.defineProperty(this, "client", {
|
|
3764
|
+
enumerable: true,
|
|
3765
|
+
configurable: true,
|
|
3766
|
+
writable: true,
|
|
3767
|
+
value: void 0
|
|
3768
|
+
});
|
|
3769
|
+
Object.defineProperty(this, "events", {
|
|
3770
|
+
enumerable: true,
|
|
3771
|
+
configurable: true,
|
|
3772
|
+
writable: true,
|
|
3773
|
+
value: void 0
|
|
3774
|
+
});
|
|
3775
|
+
Object.defineProperty(this, "trace_id", {
|
|
3776
|
+
enumerable: true,
|
|
3777
|
+
configurable: true,
|
|
3778
|
+
writable: true,
|
|
3779
|
+
value: void 0
|
|
3780
|
+
});
|
|
3781
|
+
Object.defineProperty(this, "dotted_order", {
|
|
3782
|
+
enumerable: true,
|
|
3783
|
+
configurable: true,
|
|
3784
|
+
writable: true,
|
|
3785
|
+
value: void 0
|
|
3786
|
+
});
|
|
3787
|
+
Object.defineProperty(this, "tracingEnabled", {
|
|
3788
|
+
enumerable: true,
|
|
3789
|
+
configurable: true,
|
|
3790
|
+
writable: true,
|
|
3791
|
+
value: void 0
|
|
3792
|
+
});
|
|
3793
|
+
Object.defineProperty(this, "execution_order", {
|
|
3794
|
+
enumerable: true,
|
|
3795
|
+
configurable: true,
|
|
3796
|
+
writable: true,
|
|
3797
|
+
value: void 0
|
|
3798
|
+
});
|
|
3799
|
+
Object.defineProperty(this, "child_execution_order", {
|
|
3800
|
+
enumerable: true,
|
|
3801
|
+
configurable: true,
|
|
3802
|
+
writable: true,
|
|
3803
|
+
value: void 0
|
|
3804
|
+
});
|
|
3805
|
+
const defaultConfig = _RunTree.getDefaultConfig();
|
|
3806
|
+
const _a = originalConfig, { metadata } = _a, config = __objRest(_a, ["metadata"]);
|
|
3807
|
+
const client = (_b = config.client) != null ? _b : new Client();
|
|
3808
|
+
const dedupedMetadata = __spreadValues(__spreadValues({}, metadata), (_c = config == null ? void 0 : config.extra) == null ? void 0 : _c.metadata);
|
|
3809
|
+
config.extra = __spreadProps(__spreadValues({}, config.extra), { metadata: dedupedMetadata });
|
|
3810
|
+
Object.assign(this, __spreadProps(__spreadValues(__spreadValues({}, defaultConfig), config), { client }));
|
|
3811
|
+
if (!this.trace_id) {
|
|
3812
|
+
if (this.parent_run) {
|
|
3813
|
+
this.trace_id = (_d = this.parent_run.trace_id) != null ? _d : this.id;
|
|
3814
|
+
} else {
|
|
3815
|
+
this.trace_id = this.id;
|
|
3816
|
+
}
|
|
3817
|
+
}
|
|
3818
|
+
(_e = this.execution_order) != null ? _e : this.execution_order = 1;
|
|
3819
|
+
(_f = this.child_execution_order) != null ? _f : this.child_execution_order = 1;
|
|
3820
|
+
if (!this.dotted_order) {
|
|
3821
|
+
const currentDottedOrder = convertToDottedOrderFormat(this.start_time, this.id, this.execution_order);
|
|
3822
|
+
if (this.parent_run) {
|
|
3823
|
+
this.dotted_order = this.parent_run.dotted_order + "." + currentDottedOrder;
|
|
3824
|
+
} else {
|
|
3825
|
+
this.dotted_order = currentDottedOrder;
|
|
3826
|
+
}
|
|
3827
|
+
}
|
|
3828
|
+
}
|
|
3829
|
+
static getDefaultConfig() {
|
|
3830
|
+
var _a, _b, _c;
|
|
3831
|
+
return {
|
|
3832
|
+
id: v4_default(),
|
|
3833
|
+
run_type: "chain",
|
|
3834
|
+
project_name: (_b = (_a = getEnvironmentVariable("LANGCHAIN_PROJECT")) != null ? _a : getEnvironmentVariable("LANGCHAIN_SESSION")) != null ? _b : (
|
|
3835
|
+
// TODO: Deprecate
|
|
3836
|
+
"default"
|
|
3837
|
+
),
|
|
3838
|
+
child_runs: [],
|
|
3839
|
+
api_url: (_c = getEnvironmentVariable("LANGCHAIN_ENDPOINT")) != null ? _c : "http://localhost:1984",
|
|
3840
|
+
api_key: getEnvironmentVariable("LANGCHAIN_API_KEY"),
|
|
3841
|
+
caller_options: {},
|
|
3842
|
+
start_time: Date.now(),
|
|
3843
|
+
serialized: {},
|
|
3844
|
+
inputs: {},
|
|
3845
|
+
extra: {}
|
|
3846
|
+
};
|
|
3847
|
+
}
|
|
3848
|
+
createChild(config) {
|
|
3849
|
+
const child_execution_order = this.child_execution_order + 1;
|
|
3850
|
+
const child = new _RunTree(__spreadProps(__spreadValues({}, config), {
|
|
3851
|
+
parent_run: this,
|
|
3852
|
+
project_name: this.project_name,
|
|
3853
|
+
client: this.client,
|
|
3854
|
+
tracingEnabled: this.tracingEnabled,
|
|
3855
|
+
execution_order: child_execution_order,
|
|
3856
|
+
child_execution_order
|
|
3857
|
+
}));
|
|
3858
|
+
const visited = /* @__PURE__ */ new Set();
|
|
3859
|
+
let current = this;
|
|
3860
|
+
while (current != null && !visited.has(current.id)) {
|
|
3861
|
+
visited.add(current.id);
|
|
3862
|
+
current.child_execution_order = Math.max(current.child_execution_order, child_execution_order);
|
|
3863
|
+
current = current.parent_run;
|
|
3864
|
+
}
|
|
3865
|
+
this.child_runs.push(child);
|
|
3866
|
+
return child;
|
|
3867
|
+
}
|
|
3868
|
+
async end(outputs, error, endTime = Date.now()) {
|
|
3869
|
+
var _a, _b, _c;
|
|
3870
|
+
this.outputs = (_a = this.outputs) != null ? _a : outputs;
|
|
3871
|
+
this.error = (_b = this.error) != null ? _b : error;
|
|
3872
|
+
this.end_time = (_c = this.end_time) != null ? _c : endTime;
|
|
3873
|
+
}
|
|
3874
|
+
_convertToCreate(run, runtimeEnv, excludeChildRuns = true) {
|
|
3875
|
+
var _a, _b;
|
|
3876
|
+
const runExtra = (_a = run.extra) != null ? _a : {};
|
|
3877
|
+
if (!runExtra.runtime) {
|
|
3878
|
+
runExtra.runtime = {};
|
|
3879
|
+
}
|
|
3880
|
+
if (runtimeEnv) {
|
|
3881
|
+
for (const [k, v] of Object.entries(runtimeEnv)) {
|
|
3882
|
+
if (!runExtra.runtime[k]) {
|
|
3883
|
+
runExtra.runtime[k] = v;
|
|
3884
|
+
}
|
|
3885
|
+
}
|
|
3886
|
+
}
|
|
3887
|
+
let child_runs;
|
|
3888
|
+
let parent_run_id;
|
|
3889
|
+
if (!excludeChildRuns) {
|
|
3890
|
+
child_runs = run.child_runs.map((child_run) => this._convertToCreate(child_run, runtimeEnv, excludeChildRuns));
|
|
3891
|
+
parent_run_id = void 0;
|
|
3892
|
+
} else {
|
|
3893
|
+
parent_run_id = (_b = run.parent_run) == null ? void 0 : _b.id;
|
|
3894
|
+
child_runs = [];
|
|
3895
|
+
}
|
|
3896
|
+
const persistedRun = {
|
|
3897
|
+
id: run.id,
|
|
3898
|
+
name: run.name,
|
|
3899
|
+
start_time: run.start_time,
|
|
3900
|
+
end_time: run.end_time,
|
|
3901
|
+
run_type: run.run_type,
|
|
3902
|
+
reference_example_id: run.reference_example_id,
|
|
3903
|
+
extra: runExtra,
|
|
3904
|
+
serialized: run.serialized,
|
|
3905
|
+
error: run.error,
|
|
3906
|
+
inputs: run.inputs,
|
|
3907
|
+
outputs: run.outputs,
|
|
3908
|
+
session_name: run.project_name,
|
|
3909
|
+
child_runs,
|
|
3910
|
+
parent_run_id,
|
|
3911
|
+
trace_id: run.trace_id,
|
|
3912
|
+
dotted_order: run.dotted_order,
|
|
3913
|
+
tags: run.tags
|
|
3914
|
+
};
|
|
3915
|
+
return persistedRun;
|
|
3916
|
+
}
|
|
3917
|
+
async postRun(excludeChildRuns = true) {
|
|
3918
|
+
const runtimeEnv = await getRuntimeEnvironment();
|
|
3919
|
+
const runCreate = await this._convertToCreate(this, runtimeEnv, true);
|
|
3920
|
+
await this.client.createRun(runCreate);
|
|
3921
|
+
if (!excludeChildRuns) {
|
|
3922
|
+
warnOnce("Posting with excludeChildRuns=false is deprecated and will be removed in a future version.");
|
|
3923
|
+
for (const childRun of this.child_runs) {
|
|
3924
|
+
await childRun.postRun(false);
|
|
3925
|
+
}
|
|
3926
|
+
}
|
|
3927
|
+
}
|
|
3928
|
+
async patchRun() {
|
|
3929
|
+
var _a;
|
|
3930
|
+
const runUpdate = {
|
|
3931
|
+
end_time: this.end_time,
|
|
3932
|
+
error: this.error,
|
|
3933
|
+
inputs: this.inputs,
|
|
3934
|
+
outputs: this.outputs,
|
|
3935
|
+
parent_run_id: (_a = this.parent_run) == null ? void 0 : _a.id,
|
|
3936
|
+
reference_example_id: this.reference_example_id,
|
|
3937
|
+
extra: this.extra,
|
|
3938
|
+
events: this.events,
|
|
3939
|
+
dotted_order: this.dotted_order,
|
|
3940
|
+
trace_id: this.trace_id,
|
|
3941
|
+
tags: this.tags
|
|
3942
|
+
};
|
|
3943
|
+
await this.client.updateRun(this.id, runUpdate);
|
|
3944
|
+
}
|
|
3945
|
+
toJSON() {
|
|
3946
|
+
return this._convertToCreate(this, void 0, false);
|
|
3947
|
+
}
|
|
3948
|
+
static fromRunnableConfig(parentConfig, props) {
|
|
3949
|
+
var _a, _b, _c, _d, _e, _f, _g;
|
|
3950
|
+
const callbackManager = parentConfig == null ? void 0 : parentConfig.callbacks;
|
|
3951
|
+
let parentRun;
|
|
3952
|
+
let projectName;
|
|
3953
|
+
let client;
|
|
3954
|
+
let tracingEnabled = isTracingEnabled();
|
|
3955
|
+
if (callbackManager) {
|
|
3956
|
+
const parentRunId = (_b = (_a = callbackManager == null ? void 0 : callbackManager.getParentRunId) == null ? void 0 : _a.call(callbackManager)) != null ? _b : "";
|
|
3957
|
+
const langChainTracer = (_c = callbackManager == null ? void 0 : callbackManager.handlers) == null ? void 0 : _c.find((handler) => (handler == null ? void 0 : handler.name) == "langchain_tracer");
|
|
3958
|
+
parentRun = (_d = langChainTracer == null ? void 0 : langChainTracer.getRun) == null ? void 0 : _d.call(langChainTracer, parentRunId);
|
|
3959
|
+
projectName = langChainTracer == null ? void 0 : langChainTracer.projectName;
|
|
3960
|
+
client = langChainTracer == null ? void 0 : langChainTracer.client;
|
|
3961
|
+
tracingEnabled = tracingEnabled || !!langChainTracer;
|
|
3962
|
+
}
|
|
3963
|
+
if (!parentRun) {
|
|
3964
|
+
return new _RunTree(__spreadProps(__spreadValues({}, props), {
|
|
3965
|
+
client,
|
|
3966
|
+
tracingEnabled,
|
|
3967
|
+
project_name: projectName
|
|
3968
|
+
}));
|
|
3969
|
+
}
|
|
3970
|
+
const parentRunTree = new _RunTree({
|
|
3971
|
+
name: parentRun.name,
|
|
3972
|
+
id: parentRun.id,
|
|
3973
|
+
client,
|
|
3974
|
+
tracingEnabled,
|
|
3975
|
+
project_name: projectName,
|
|
3976
|
+
tags: [
|
|
3977
|
+
...new Set(((_e = parentRun == null ? void 0 : parentRun.tags) != null ? _e : []).concat((_f = parentConfig == null ? void 0 : parentConfig.tags) != null ? _f : []))
|
|
3978
|
+
],
|
|
3979
|
+
extra: {
|
|
3980
|
+
metadata: __spreadValues(__spreadValues({}, (_g = parentRun == null ? void 0 : parentRun.extra) == null ? void 0 : _g.metadata), parentConfig == null ? void 0 : parentConfig.metadata)
|
|
3981
|
+
}
|
|
3982
|
+
});
|
|
3983
|
+
return parentRunTree.createChild(props);
|
|
3984
|
+
}
|
|
3985
|
+
static fromDottedOrder(dottedOrder) {
|
|
3986
|
+
return this.fromHeaders({ "langsmith-trace": dottedOrder });
|
|
3987
|
+
}
|
|
3988
|
+
static fromHeaders(headers, inheritArgs) {
|
|
3989
|
+
var _a, _b, _c, _d;
|
|
3990
|
+
const rawHeaders = "get" in headers && typeof headers.get === "function" ? {
|
|
3991
|
+
"langsmith-trace": headers.get("langsmith-trace"),
|
|
3992
|
+
baggage: headers.get("baggage")
|
|
3993
|
+
} : headers;
|
|
3994
|
+
const headerTrace = rawHeaders["langsmith-trace"];
|
|
3995
|
+
if (!headerTrace || typeof headerTrace !== "string")
|
|
3996
|
+
return void 0;
|
|
3997
|
+
const parentDottedOrder = headerTrace.trim();
|
|
3998
|
+
const parsedDottedOrder = parentDottedOrder.split(".").map((part) => {
|
|
3999
|
+
const [strTime, uuid] = part.split("Z");
|
|
4000
|
+
return { strTime, time: Date.parse(strTime + "Z"), uuid };
|
|
4001
|
+
});
|
|
4002
|
+
const traceId = parsedDottedOrder[0].uuid;
|
|
4003
|
+
const config = __spreadProps(__spreadValues({}, inheritArgs), {
|
|
4004
|
+
name: (_a = inheritArgs == null ? void 0 : inheritArgs["name"]) != null ? _a : "parent",
|
|
4005
|
+
run_type: (_b = inheritArgs == null ? void 0 : inheritArgs["run_type"]) != null ? _b : "chain",
|
|
4006
|
+
start_time: (_c = inheritArgs == null ? void 0 : inheritArgs["start_time"]) != null ? _c : Date.now(),
|
|
4007
|
+
id: (_d = parsedDottedOrder.at(-1)) == null ? void 0 : _d.uuid,
|
|
4008
|
+
trace_id: traceId,
|
|
4009
|
+
dotted_order: parentDottedOrder
|
|
4010
|
+
});
|
|
4011
|
+
if (rawHeaders["baggage"] && typeof rawHeaders["baggage"] === "string") {
|
|
4012
|
+
const baggage = Baggage.fromHeader(rawHeaders["baggage"]);
|
|
4013
|
+
config.metadata = baggage.metadata;
|
|
4014
|
+
config.tags = baggage.tags;
|
|
4015
|
+
}
|
|
4016
|
+
return new _RunTree(config);
|
|
4017
|
+
}
|
|
4018
|
+
toHeaders(headers) {
|
|
4019
|
+
var _a;
|
|
4020
|
+
const result = {
|
|
4021
|
+
"langsmith-trace": this.dotted_order,
|
|
4022
|
+
baggage: new Baggage((_a = this.extra) == null ? void 0 : _a.metadata, this.tags).toHeader()
|
|
4023
|
+
};
|
|
4024
|
+
if (headers) {
|
|
4025
|
+
for (const [key, value] of Object.entries(result)) {
|
|
4026
|
+
headers.set(key, value);
|
|
4027
|
+
}
|
|
4028
|
+
}
|
|
4029
|
+
return result;
|
|
4030
|
+
}
|
|
4031
|
+
};
|
|
4032
|
+
function isRunTree(x) {
|
|
4033
|
+
return x !== void 0 && typeof x.createChild === "function" && typeof x.postRun === "function";
|
|
4034
|
+
}
|
|
4035
|
+
function containsLangChainTracerLike(x) {
|
|
4036
|
+
return Array.isArray(x) && x.some((callback) => {
|
|
4037
|
+
return typeof callback.name === "string" && callback.name === "langchain_tracer";
|
|
4038
|
+
});
|
|
4039
|
+
}
|
|
4040
|
+
function isRunnableConfigLike(x) {
|
|
4041
|
+
var _a;
|
|
4042
|
+
return x !== void 0 && typeof x.callbacks === "object" && // Callback manager with a langchain tracer
|
|
4043
|
+
(containsLangChainTracerLike((_a = x.callbacks) == null ? void 0 : _a.handlers) || // Or it's an array with a LangChainTracerLike object within it
|
|
4044
|
+
containsLangChainTracerLike(x.callbacks));
|
|
4045
|
+
}
|
|
4046
|
+
|
|
4047
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/singletons/traceable.js
|
|
4048
|
+
var MockAsyncLocalStorage = class {
|
|
4049
|
+
getStore() {
|
|
4050
|
+
return void 0;
|
|
4051
|
+
}
|
|
4052
|
+
run(_, callback) {
|
|
4053
|
+
return callback();
|
|
4054
|
+
}
|
|
4055
|
+
};
|
|
4056
|
+
var AsyncLocalStorageProvider = class {
|
|
4057
|
+
constructor() {
|
|
4058
|
+
Object.defineProperty(this, "asyncLocalStorage", {
|
|
4059
|
+
enumerable: true,
|
|
4060
|
+
configurable: true,
|
|
4061
|
+
writable: true,
|
|
4062
|
+
value: new MockAsyncLocalStorage()
|
|
4063
|
+
});
|
|
4064
|
+
Object.defineProperty(this, "hasBeenInitialized", {
|
|
4065
|
+
enumerable: true,
|
|
4066
|
+
configurable: true,
|
|
4067
|
+
writable: true,
|
|
4068
|
+
value: false
|
|
4069
|
+
});
|
|
4070
|
+
}
|
|
4071
|
+
getInstance() {
|
|
4072
|
+
return this.asyncLocalStorage;
|
|
4073
|
+
}
|
|
4074
|
+
initializeGlobalInstance(instance) {
|
|
4075
|
+
if (!this.hasBeenInitialized) {
|
|
4076
|
+
this.hasBeenInitialized = true;
|
|
4077
|
+
this.asyncLocalStorage = instance;
|
|
4078
|
+
}
|
|
4079
|
+
}
|
|
4080
|
+
};
|
|
4081
|
+
var AsyncLocalStorageProviderSingleton = new AsyncLocalStorageProvider();
|
|
4082
|
+
var ROOT = Symbol.for("langsmith:traceable:root");
|
|
4083
|
+
function isTraceableFunction(x) {
|
|
4084
|
+
return typeof x === "function" && "langsmith:traceable" in x;
|
|
4085
|
+
}
|
|
4086
|
+
|
|
4087
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/utils/asserts.js
|
|
4088
|
+
function isPromiseMethod(x) {
|
|
4089
|
+
if (x === "then" || x === "catch" || x === "finally") {
|
|
4090
|
+
return true;
|
|
4091
|
+
}
|
|
4092
|
+
return false;
|
|
4093
|
+
}
|
|
4094
|
+
function isKVMap(x) {
|
|
4095
|
+
if (typeof x !== "object" || x == null) {
|
|
4096
|
+
return false;
|
|
4097
|
+
}
|
|
4098
|
+
const prototype = Object.getPrototypeOf(x);
|
|
4099
|
+
return (prototype === null || prototype === Object.prototype || Object.getPrototypeOf(prototype) === null) && !(Symbol.toStringTag in x) && !(Symbol.iterator in x);
|
|
4100
|
+
}
|
|
4101
|
+
var isAsyncIterable = (x) => x != null && typeof x === "object" && // eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
4102
|
+
typeof x[Symbol.asyncIterator] === "function";
|
|
4103
|
+
var isIteratorLike = (x) => x != null && typeof x === "object" && "next" in x && typeof x.next === "function";
|
|
4104
|
+
var GeneratorFunction = function* () {
|
|
4105
|
+
}.constructor;
|
|
4106
|
+
var isGenerator = (x) => (
|
|
4107
|
+
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
4108
|
+
x != null && typeof x === "function" && x instanceof GeneratorFunction
|
|
4109
|
+
);
|
|
4110
|
+
var isThenable = (x) => x != null && typeof x === "object" && "then" in x && typeof x.then === "function";
|
|
4111
|
+
var isReadableStream = (x) => x != null && typeof x === "object" && "getReader" in x && typeof x.getReader === "function";
|
|
4112
|
+
|
|
4113
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/traceable.js
|
|
4114
|
+
AsyncLocalStorageProviderSingleton.initializeGlobalInstance(new import_node_async_hooks.AsyncLocalStorage());
|
|
4115
|
+
var handleRunInputs = (rawInputs) => {
|
|
4116
|
+
const firstInput = rawInputs[0];
|
|
4117
|
+
if (firstInput == null) {
|
|
4118
|
+
return {};
|
|
4119
|
+
}
|
|
4120
|
+
if (rawInputs.length > 1) {
|
|
4121
|
+
return { args: rawInputs };
|
|
4122
|
+
}
|
|
4123
|
+
if (isKVMap(firstInput)) {
|
|
4124
|
+
return firstInput;
|
|
4125
|
+
}
|
|
4126
|
+
return { input: firstInput };
|
|
4127
|
+
};
|
|
4128
|
+
var handleRunOutputs = (rawOutputs) => {
|
|
4129
|
+
if (isKVMap(rawOutputs)) {
|
|
4130
|
+
return rawOutputs;
|
|
4131
|
+
}
|
|
4132
|
+
return { outputs: rawOutputs };
|
|
4133
|
+
};
|
|
4134
|
+
var getTracingRunTree = (runTree, inputs, getInvocationParams) => {
|
|
4135
|
+
var _a;
|
|
4136
|
+
if (!isTracingEnabled(runTree.tracingEnabled)) {
|
|
4137
|
+
return void 0;
|
|
4138
|
+
}
|
|
4139
|
+
runTree.inputs = handleRunInputs(inputs);
|
|
4140
|
+
const invocationParams = getInvocationParams == null ? void 0 : getInvocationParams(...inputs);
|
|
4141
|
+
if (invocationParams != null) {
|
|
4142
|
+
(_a = runTree.extra) != null ? _a : runTree.extra = {};
|
|
4143
|
+
runTree.extra.metadata = __spreadValues(__spreadValues({}, invocationParams), runTree.extra.metadata);
|
|
4144
|
+
}
|
|
4145
|
+
return runTree;
|
|
4146
|
+
};
|
|
4147
|
+
var getSerializablePromise = (arg) => {
|
|
4148
|
+
const proxyState = { current: void 0 };
|
|
4149
|
+
const promiseProxy = new Proxy(arg, {
|
|
4150
|
+
get(target, prop, receiver) {
|
|
4151
|
+
if (prop === "then") {
|
|
4152
|
+
const boundThen = arg[prop].bind(arg);
|
|
4153
|
+
return (resolve, reject = (x) => {
|
|
4154
|
+
throw x;
|
|
4155
|
+
}) => {
|
|
4156
|
+
return boundThen((value) => {
|
|
4157
|
+
proxyState.current = ["resolve", value];
|
|
4158
|
+
return resolve(value);
|
|
4159
|
+
}, (error) => {
|
|
4160
|
+
proxyState.current = ["reject", error];
|
|
4161
|
+
return reject(error);
|
|
4162
|
+
});
|
|
4163
|
+
};
|
|
4164
|
+
}
|
|
4165
|
+
if (prop === "catch") {
|
|
4166
|
+
const boundCatch = arg[prop].bind(arg);
|
|
4167
|
+
return (reject) => {
|
|
4168
|
+
return boundCatch((error) => {
|
|
4169
|
+
proxyState.current = ["reject", error];
|
|
4170
|
+
return reject(error);
|
|
4171
|
+
});
|
|
4172
|
+
};
|
|
4173
|
+
}
|
|
4174
|
+
if (prop === "toJSON") {
|
|
4175
|
+
return () => {
|
|
4176
|
+
var _a;
|
|
4177
|
+
if (!proxyState.current)
|
|
4178
|
+
return void 0;
|
|
4179
|
+
const [type, value] = (_a = proxyState.current) != null ? _a : [];
|
|
4180
|
+
if (type === "resolve")
|
|
4181
|
+
return value;
|
|
4182
|
+
return { error: value };
|
|
4183
|
+
};
|
|
4184
|
+
}
|
|
4185
|
+
return Reflect.get(target, prop, receiver);
|
|
4186
|
+
}
|
|
4187
|
+
});
|
|
4188
|
+
return promiseProxy;
|
|
4189
|
+
};
|
|
4190
|
+
var convertSerializableArg = (arg) => {
|
|
4191
|
+
if (isReadableStream(arg)) {
|
|
4192
|
+
const proxyState = [];
|
|
4193
|
+
const transform = new TransformStream({
|
|
4194
|
+
start: () => void 0,
|
|
4195
|
+
transform: (chunk, controller) => {
|
|
4196
|
+
proxyState.push(chunk);
|
|
4197
|
+
controller.enqueue(chunk);
|
|
4198
|
+
},
|
|
4199
|
+
flush: () => void 0
|
|
4200
|
+
});
|
|
4201
|
+
const pipeThrough = arg.pipeThrough(transform);
|
|
4202
|
+
Object.assign(pipeThrough, { toJSON: () => proxyState });
|
|
4203
|
+
return pipeThrough;
|
|
4204
|
+
}
|
|
4205
|
+
if (isAsyncIterable(arg)) {
|
|
4206
|
+
const proxyState = { current: [] };
|
|
4207
|
+
return new Proxy(arg, {
|
|
4208
|
+
get(target, prop, receiver) {
|
|
4209
|
+
if (prop === Symbol.asyncIterator) {
|
|
4210
|
+
return () => {
|
|
4211
|
+
const boundIterator = arg[Symbol.asyncIterator].bind(arg);
|
|
4212
|
+
const iterator = boundIterator();
|
|
4213
|
+
return new Proxy(iterator, {
|
|
4214
|
+
get(target2, prop2, receiver2) {
|
|
4215
|
+
if (prop2 === "next" || prop2 === "return" || prop2 === "throw") {
|
|
4216
|
+
const bound = iterator.next.bind(iterator);
|
|
4217
|
+
return (...args) => {
|
|
4218
|
+
const wrapped = getSerializablePromise(bound(...args));
|
|
4219
|
+
proxyState.current.push(wrapped);
|
|
4220
|
+
return wrapped;
|
|
4221
|
+
};
|
|
4222
|
+
}
|
|
4223
|
+
if (prop2 === "return" || prop2 === "throw") {
|
|
4224
|
+
return iterator.next.bind(iterator);
|
|
4225
|
+
}
|
|
4226
|
+
return Reflect.get(target2, prop2, receiver2);
|
|
4227
|
+
}
|
|
4228
|
+
});
|
|
4229
|
+
};
|
|
4230
|
+
}
|
|
4231
|
+
if (prop === "toJSON") {
|
|
4232
|
+
return () => {
|
|
4233
|
+
const onlyNexts = proxyState.current;
|
|
4234
|
+
const serialized = onlyNexts.map((next) => next.toJSON());
|
|
4235
|
+
const chunks = serialized.reduce((memo, next) => {
|
|
4236
|
+
if (next == null ? void 0 : next.value)
|
|
4237
|
+
memo.push(next.value);
|
|
4238
|
+
return memo;
|
|
4239
|
+
}, []);
|
|
4240
|
+
return chunks;
|
|
4241
|
+
};
|
|
4242
|
+
}
|
|
4243
|
+
return Reflect.get(target, prop, receiver);
|
|
4244
|
+
}
|
|
4245
|
+
});
|
|
4246
|
+
}
|
|
4247
|
+
if (!Array.isArray(arg) && isIteratorLike(arg)) {
|
|
4248
|
+
const proxyState = [];
|
|
4249
|
+
return new Proxy(arg, {
|
|
4250
|
+
get(target, prop, receiver) {
|
|
4251
|
+
var _a;
|
|
4252
|
+
if (prop === "next" || prop === "return" || prop === "throw") {
|
|
4253
|
+
const bound = (_a = arg[prop]) == null ? void 0 : _a.bind(arg);
|
|
4254
|
+
return (...args) => {
|
|
4255
|
+
const next = bound == null ? void 0 : bound(...args);
|
|
4256
|
+
if (next != null)
|
|
4257
|
+
proxyState.push(next);
|
|
4258
|
+
return next;
|
|
4259
|
+
};
|
|
4260
|
+
}
|
|
4261
|
+
if (prop === "toJSON") {
|
|
4262
|
+
return () => {
|
|
4263
|
+
const chunks = proxyState.reduce((memo, next) => {
|
|
4264
|
+
if (next.value)
|
|
4265
|
+
memo.push(next.value);
|
|
4266
|
+
return memo;
|
|
4267
|
+
}, []);
|
|
4268
|
+
return chunks;
|
|
4269
|
+
};
|
|
4270
|
+
}
|
|
4271
|
+
return Reflect.get(target, prop, receiver);
|
|
4272
|
+
}
|
|
4273
|
+
});
|
|
4274
|
+
}
|
|
4275
|
+
if (isThenable(arg)) {
|
|
4276
|
+
return getSerializablePromise(arg);
|
|
4277
|
+
}
|
|
4278
|
+
return arg;
|
|
4279
|
+
};
|
|
4280
|
+
function traceable(wrappedFunc, config) {
|
|
4281
|
+
const _a = config != null ? config : {}, { aggregator, argsConfigPath } = _a, runTreeConfig = __objRest(_a, ["aggregator", "argsConfigPath"]);
|
|
4282
|
+
const traceableFunc = (...args) => {
|
|
4283
|
+
var _b, _c, _d;
|
|
4284
|
+
let ensuredConfig;
|
|
4285
|
+
try {
|
|
4286
|
+
let runtimeConfig;
|
|
4287
|
+
if (argsConfigPath) {
|
|
4288
|
+
const [index, path] = argsConfigPath;
|
|
4289
|
+
if (index === args.length - 1 && !path) {
|
|
4290
|
+
runtimeConfig = args.pop();
|
|
4291
|
+
} else if (index <= args.length && typeof args[index] === "object" && args[index] !== null) {
|
|
4292
|
+
if (path) {
|
|
4293
|
+
const _a2 = args[index], { [path]: extracted } = _a2, rest = __objRest(_a2, [__restKey(path)]);
|
|
4294
|
+
runtimeConfig = extracted;
|
|
4295
|
+
args[index] = rest;
|
|
4296
|
+
} else {
|
|
4297
|
+
runtimeConfig = args[index];
|
|
4298
|
+
args.splice(index, 1);
|
|
4299
|
+
}
|
|
4300
|
+
}
|
|
4301
|
+
}
|
|
4302
|
+
ensuredConfig = __spreadProps(__spreadValues(__spreadValues({
|
|
4303
|
+
name: wrappedFunc.name || "<lambda>"
|
|
4304
|
+
}, runTreeConfig), runtimeConfig), {
|
|
4305
|
+
tags: [
|
|
4306
|
+
.../* @__PURE__ */ new Set([
|
|
4307
|
+
...(_b = runTreeConfig == null ? void 0 : runTreeConfig.tags) != null ? _b : [],
|
|
4308
|
+
...(_c = runtimeConfig == null ? void 0 : runtimeConfig.tags) != null ? _c : []
|
|
4309
|
+
])
|
|
4310
|
+
],
|
|
4311
|
+
metadata: __spreadValues(__spreadValues({}, runTreeConfig == null ? void 0 : runTreeConfig.metadata), runtimeConfig == null ? void 0 : runtimeConfig.metadata)
|
|
4312
|
+
});
|
|
4313
|
+
} catch (err) {
|
|
4314
|
+
console.warn(`Failed to extract runtime config from args for ${(_d = runTreeConfig == null ? void 0 : runTreeConfig.name) != null ? _d : wrappedFunc.name}`, err);
|
|
4315
|
+
ensuredConfig = __spreadValues({
|
|
4316
|
+
name: wrappedFunc.name || "<lambda>"
|
|
4317
|
+
}, runTreeConfig);
|
|
4318
|
+
}
|
|
4319
|
+
const asyncLocalStorage = AsyncLocalStorageProviderSingleton.getInstance();
|
|
4320
|
+
const processedArgs = args;
|
|
4321
|
+
for (let i = 0; i < processedArgs.length; i++) {
|
|
4322
|
+
processedArgs[i] = convertSerializableArg(processedArgs[i]);
|
|
4323
|
+
}
|
|
4324
|
+
const [currentRunTree, rawInputs] = (() => {
|
|
4325
|
+
const [firstArg, ...restArgs] = processedArgs;
|
|
4326
|
+
if (isRunnableConfigLike(firstArg)) {
|
|
4327
|
+
return [
|
|
4328
|
+
getTracingRunTree(RunTree.fromRunnableConfig(firstArg, ensuredConfig), restArgs, config == null ? void 0 : config.getInvocationParams),
|
|
4329
|
+
restArgs
|
|
4330
|
+
];
|
|
4331
|
+
}
|
|
4332
|
+
if (isRunTree(firstArg) && "callbackManager" in firstArg && firstArg.callbackManager != null) {
|
|
4333
|
+
return [firstArg, restArgs];
|
|
4334
|
+
}
|
|
4335
|
+
if (firstArg === ROOT || isRunTree(firstArg)) {
|
|
4336
|
+
const currentRunTree3 = getTracingRunTree(firstArg === ROOT ? new RunTree(ensuredConfig) : firstArg.createChild(ensuredConfig), restArgs, config == null ? void 0 : config.getInvocationParams);
|
|
4337
|
+
return [currentRunTree3, [currentRunTree3, ...restArgs]];
|
|
4338
|
+
}
|
|
4339
|
+
const prevRunFromStore = asyncLocalStorage.getStore();
|
|
4340
|
+
if (prevRunFromStore) {
|
|
4341
|
+
return [
|
|
4342
|
+
getTracingRunTree(prevRunFromStore.createChild(ensuredConfig), processedArgs, config == null ? void 0 : config.getInvocationParams),
|
|
4343
|
+
processedArgs
|
|
4344
|
+
];
|
|
4345
|
+
}
|
|
4346
|
+
const currentRunTree2 = getTracingRunTree(new RunTree(ensuredConfig), processedArgs, config == null ? void 0 : config.getInvocationParams);
|
|
4347
|
+
return [currentRunTree2, processedArgs];
|
|
4348
|
+
})();
|
|
4349
|
+
return asyncLocalStorage.run(currentRunTree, () => {
|
|
4350
|
+
const postRunPromise = currentRunTree == null ? void 0 : currentRunTree.postRun();
|
|
4351
|
+
async function handleChunks(chunks) {
|
|
4352
|
+
if (aggregator !== void 0) {
|
|
4353
|
+
try {
|
|
4354
|
+
return await aggregator(chunks);
|
|
4355
|
+
} catch (e) {
|
|
4356
|
+
console.error(`[ERROR]: LangSmith aggregation failed: `, e);
|
|
4357
|
+
}
|
|
4358
|
+
}
|
|
4359
|
+
return chunks;
|
|
4360
|
+
}
|
|
4361
|
+
function wrapAsyncGeneratorForTracing(iterable, snapshot) {
|
|
4362
|
+
return __asyncGenerator(this, null, function* () {
|
|
4363
|
+
let finished = false;
|
|
4364
|
+
const chunks = [];
|
|
4365
|
+
try {
|
|
4366
|
+
const iterator = iterable[Symbol.asyncIterator]();
|
|
4367
|
+
while (true) {
|
|
4368
|
+
const { value, done } = yield new __await(snapshot ? snapshot(() => iterator.next()) : iterator.next());
|
|
4369
|
+
if (done) {
|
|
4370
|
+
finished = true;
|
|
4371
|
+
break;
|
|
4372
|
+
}
|
|
4373
|
+
chunks.push(value);
|
|
4374
|
+
yield value;
|
|
4375
|
+
}
|
|
4376
|
+
} catch (e) {
|
|
4377
|
+
yield new __await(currentRunTree == null ? void 0 : currentRunTree.end(void 0, String(e)));
|
|
4378
|
+
throw e;
|
|
4379
|
+
} finally {
|
|
4380
|
+
if (!finished)
|
|
4381
|
+
yield new __await(currentRunTree == null ? void 0 : currentRunTree.end(void 0, "Cancelled"));
|
|
4382
|
+
yield new __await(currentRunTree == null ? void 0 : currentRunTree.end(handleRunOutputs(yield new __await(handleChunks(chunks)))));
|
|
4383
|
+
yield new __await(handleEnd());
|
|
4384
|
+
}
|
|
4385
|
+
});
|
|
4386
|
+
}
|
|
4387
|
+
async function handleEnd() {
|
|
4388
|
+
const onEnd = config == null ? void 0 : config.on_end;
|
|
4389
|
+
if (onEnd) {
|
|
4390
|
+
if (!currentRunTree) {
|
|
4391
|
+
console.warn("Can not call 'on_end' if currentRunTree is undefined");
|
|
4392
|
+
} else {
|
|
4393
|
+
onEnd(currentRunTree);
|
|
4394
|
+
}
|
|
4395
|
+
}
|
|
4396
|
+
await postRunPromise;
|
|
4397
|
+
await (currentRunTree == null ? void 0 : currentRunTree.patchRun());
|
|
4398
|
+
}
|
|
4399
|
+
function gatherAll(iterator) {
|
|
4400
|
+
const chunks = [];
|
|
4401
|
+
while (true) {
|
|
4402
|
+
const next = iterator.next();
|
|
4403
|
+
chunks.push(next);
|
|
4404
|
+
if (next.done)
|
|
4405
|
+
break;
|
|
4406
|
+
}
|
|
4407
|
+
return chunks;
|
|
4408
|
+
}
|
|
4409
|
+
let returnValue;
|
|
4410
|
+
try {
|
|
4411
|
+
returnValue = wrappedFunc(...rawInputs);
|
|
4412
|
+
} catch (err) {
|
|
4413
|
+
returnValue = Promise.reject(err);
|
|
4414
|
+
}
|
|
4415
|
+
if (isAsyncIterable(returnValue)) {
|
|
4416
|
+
const snapshot = import_node_async_hooks.AsyncLocalStorage.snapshot();
|
|
4417
|
+
return wrapAsyncGeneratorForTracing(returnValue, snapshot);
|
|
4418
|
+
}
|
|
4419
|
+
const tracedPromise = new Promise((resolve, reject) => {
|
|
4420
|
+
Promise.resolve(returnValue).then(async (rawOutput) => {
|
|
4421
|
+
if (isAsyncIterable(rawOutput)) {
|
|
4422
|
+
const snapshot = import_node_async_hooks.AsyncLocalStorage.snapshot();
|
|
4423
|
+
return resolve(wrapAsyncGeneratorForTracing(rawOutput, snapshot));
|
|
4424
|
+
}
|
|
4425
|
+
if (isGenerator(wrappedFunc) && isIteratorLike(rawOutput)) {
|
|
4426
|
+
const chunks = gatherAll(rawOutput);
|
|
4427
|
+
await (currentRunTree == null ? void 0 : currentRunTree.end(handleRunOutputs(await handleChunks(chunks.reduce((memo, { value, done }) => {
|
|
4428
|
+
if (!done || typeof value !== "undefined") {
|
|
4429
|
+
memo.push(value);
|
|
4430
|
+
}
|
|
4431
|
+
return memo;
|
|
4432
|
+
}, [])))));
|
|
4433
|
+
await handleEnd();
|
|
4434
|
+
return function* () {
|
|
4435
|
+
for (const ret of chunks) {
|
|
4436
|
+
if (ret.done)
|
|
4437
|
+
return ret.value;
|
|
4438
|
+
yield ret.value;
|
|
4439
|
+
}
|
|
4440
|
+
}();
|
|
4441
|
+
}
|
|
4442
|
+
try {
|
|
4443
|
+
await (currentRunTree == null ? void 0 : currentRunTree.end(handleRunOutputs(rawOutput)));
|
|
4444
|
+
await handleEnd();
|
|
4445
|
+
} finally {
|
|
4446
|
+
return rawOutput;
|
|
4447
|
+
}
|
|
4448
|
+
}, async (error) => {
|
|
4449
|
+
await (currentRunTree == null ? void 0 : currentRunTree.end(void 0, String(error)));
|
|
4450
|
+
await handleEnd();
|
|
4451
|
+
throw error;
|
|
4452
|
+
}).then(resolve, reject);
|
|
4453
|
+
});
|
|
4454
|
+
if (typeof returnValue !== "object" || returnValue === null) {
|
|
4455
|
+
return tracedPromise;
|
|
4456
|
+
}
|
|
4457
|
+
return new Proxy(returnValue, {
|
|
4458
|
+
get(target, prop, receiver) {
|
|
4459
|
+
if (isPromiseMethod(prop)) {
|
|
4460
|
+
return tracedPromise[prop].bind(tracedPromise);
|
|
4461
|
+
}
|
|
4462
|
+
return Reflect.get(target, prop, receiver);
|
|
4463
|
+
}
|
|
4464
|
+
});
|
|
4465
|
+
});
|
|
4466
|
+
};
|
|
4467
|
+
Object.defineProperty(traceableFunc, "langsmith:traceable", {
|
|
4468
|
+
value: runTreeConfig
|
|
4469
|
+
});
|
|
4470
|
+
return traceableFunc;
|
|
4471
|
+
}
|
|
4472
|
+
|
|
4473
|
+
// ../../node_modules/.pnpm/langsmith@0.1.36_openai@4.47.1/node_modules/langsmith/dist/wrappers/openai.js
|
|
4474
|
+
function _combineChatCompletionChoices(choices) {
|
|
4475
|
+
var _a, _b;
|
|
4476
|
+
const reversedChoices = choices.slice().reverse();
|
|
4477
|
+
const message = {
|
|
4478
|
+
role: "assistant",
|
|
4479
|
+
content: ""
|
|
4480
|
+
};
|
|
4481
|
+
for (const c of reversedChoices) {
|
|
4482
|
+
if (c.delta.role) {
|
|
4483
|
+
message["role"] = c.delta.role;
|
|
4484
|
+
break;
|
|
4485
|
+
}
|
|
4486
|
+
}
|
|
4487
|
+
const toolCalls = {};
|
|
4488
|
+
for (const c of choices) {
|
|
4489
|
+
if (c.delta.content) {
|
|
4490
|
+
message.content = message.content.concat(c.delta.content);
|
|
4491
|
+
}
|
|
4492
|
+
if (c.delta.function_call) {
|
|
4493
|
+
if (!message.function_call) {
|
|
4494
|
+
message.function_call = { name: "", arguments: "" };
|
|
4495
|
+
}
|
|
4496
|
+
if (c.delta.function_call.name) {
|
|
4497
|
+
message.function_call.name += c.delta.function_call.name;
|
|
4498
|
+
}
|
|
4499
|
+
if (c.delta.function_call.arguments) {
|
|
4500
|
+
message.function_call.arguments += c.delta.function_call.arguments;
|
|
4501
|
+
}
|
|
4502
|
+
}
|
|
4503
|
+
if (c.delta.tool_calls) {
|
|
4504
|
+
for (const tool_call of c.delta.tool_calls) {
|
|
4505
|
+
if (!toolCalls[c.index]) {
|
|
4506
|
+
toolCalls[c.index] = [];
|
|
4507
|
+
}
|
|
4508
|
+
toolCalls[c.index].push(tool_call);
|
|
4509
|
+
}
|
|
4510
|
+
}
|
|
4511
|
+
}
|
|
4512
|
+
if (Object.keys(toolCalls).length > 0) {
|
|
4513
|
+
message.tool_calls = [...Array(Object.keys(toolCalls).length)];
|
|
4514
|
+
for (const [index, toolCallChunks] of Object.entries(toolCalls)) {
|
|
4515
|
+
const idx = parseInt(index);
|
|
4516
|
+
message.tool_calls[idx] = {
|
|
4517
|
+
index: idx,
|
|
4518
|
+
id: ((_a = toolCallChunks.find((c) => c.id)) == null ? void 0 : _a.id) || null,
|
|
4519
|
+
type: ((_b = toolCallChunks.find((c) => c.type)) == null ? void 0 : _b.type) || null
|
|
4520
|
+
};
|
|
4521
|
+
for (const chunk of toolCallChunks) {
|
|
4522
|
+
if (chunk.function) {
|
|
4523
|
+
if (!message.tool_calls[idx].function) {
|
|
4524
|
+
message.tool_calls[idx].function = {
|
|
4525
|
+
name: "",
|
|
4526
|
+
arguments: ""
|
|
4527
|
+
};
|
|
4528
|
+
}
|
|
4529
|
+
if (chunk.function.name) {
|
|
4530
|
+
message.tool_calls[idx].function.name += chunk.function.name;
|
|
4531
|
+
}
|
|
4532
|
+
if (chunk.function.arguments) {
|
|
4533
|
+
message.tool_calls[idx].function.arguments += chunk.function.arguments;
|
|
4534
|
+
}
|
|
4535
|
+
}
|
|
4536
|
+
}
|
|
4537
|
+
}
|
|
4538
|
+
}
|
|
4539
|
+
return {
|
|
4540
|
+
index: choices[0].index,
|
|
4541
|
+
finish_reason: reversedChoices.find((c) => c.finish_reason) || null,
|
|
4542
|
+
message
|
|
4543
|
+
};
|
|
4544
|
+
}
|
|
4545
|
+
var chatAggregator = (chunks) => {
|
|
4546
|
+
if (!chunks || chunks.length === 0) {
|
|
4547
|
+
return { choices: [{ message: { role: "assistant", content: "" } }] };
|
|
4548
|
+
}
|
|
4549
|
+
const choicesByIndex = {};
|
|
4550
|
+
for (const chunk of chunks) {
|
|
4551
|
+
for (const choice of chunk.choices) {
|
|
4552
|
+
if (choicesByIndex[choice.index] === void 0) {
|
|
4553
|
+
choicesByIndex[choice.index] = [];
|
|
4554
|
+
}
|
|
4555
|
+
choicesByIndex[choice.index].push(choice);
|
|
4556
|
+
}
|
|
4557
|
+
}
|
|
4558
|
+
const aggregatedOutput = chunks[chunks.length - 1];
|
|
4559
|
+
aggregatedOutput.choices = Object.values(choicesByIndex).map((choices) => _combineChatCompletionChoices(choices));
|
|
4560
|
+
return aggregatedOutput;
|
|
4561
|
+
};
|
|
4562
|
+
var textAggregator = (allChunks) => {
|
|
4563
|
+
if (allChunks.length === 0) {
|
|
4564
|
+
return { choices: [{ text: "" }] };
|
|
4565
|
+
}
|
|
4566
|
+
const allContent = [];
|
|
4567
|
+
for (const chunk of allChunks) {
|
|
4568
|
+
const content2 = chunk.choices[0].text;
|
|
4569
|
+
if (content2 != null) {
|
|
4570
|
+
allContent.push(content2);
|
|
4571
|
+
}
|
|
4572
|
+
}
|
|
4573
|
+
const content = allContent.join("");
|
|
4574
|
+
const aggregatedOutput = allChunks[allChunks.length - 1];
|
|
4575
|
+
aggregatedOutput.choices = [
|
|
4576
|
+
__spreadProps(__spreadValues({}, aggregatedOutput.choices[0]), { text: content })
|
|
4577
|
+
];
|
|
4578
|
+
return aggregatedOutput;
|
|
4579
|
+
};
|
|
4580
|
+
var wrapOpenAI = (openai, options) => {
|
|
4581
|
+
if (isTraceableFunction(openai.chat.completions.create) || isTraceableFunction(openai.completions.create)) {
|
|
4582
|
+
throw new Error("This instance of OpenAI client has been already wrapped once.");
|
|
4583
|
+
}
|
|
4584
|
+
openai.chat.completions.create = traceable(openai.chat.completions.create.bind(openai.chat.completions), __spreadValues({
|
|
4585
|
+
name: "ChatOpenAI",
|
|
4586
|
+
run_type: "llm",
|
|
4587
|
+
aggregator: chatAggregator,
|
|
4588
|
+
argsConfigPath: [1, "langsmithExtra"],
|
|
4589
|
+
getInvocationParams: (payload) => {
|
|
4590
|
+
var _a, _b, _c;
|
|
4591
|
+
if (typeof payload !== "object" || payload == null)
|
|
4592
|
+
return void 0;
|
|
4593
|
+
const params = payload;
|
|
4594
|
+
const ls_stop = (_a = typeof params.stop === "string" ? [params.stop] : params.stop) != null ? _a : void 0;
|
|
4595
|
+
return {
|
|
4596
|
+
ls_provider: "openai",
|
|
4597
|
+
ls_model_type: "chat",
|
|
4598
|
+
ls_model_name: params.model,
|
|
4599
|
+
ls_max_tokens: (_b = params.max_tokens) != null ? _b : void 0,
|
|
4600
|
+
ls_temperature: (_c = params.temperature) != null ? _c : void 0,
|
|
4601
|
+
ls_stop
|
|
4602
|
+
};
|
|
4603
|
+
}
|
|
4604
|
+
}, options));
|
|
4605
|
+
openai.completions.create = traceable(openai.completions.create.bind(openai.completions), __spreadValues({
|
|
4606
|
+
name: "OpenAI",
|
|
4607
|
+
run_type: "llm",
|
|
4608
|
+
aggregator: textAggregator,
|
|
4609
|
+
argsConfigPath: [1, "langsmithExtra"],
|
|
4610
|
+
getInvocationParams: (payload) => {
|
|
4611
|
+
var _a, _b, _c;
|
|
4612
|
+
if (typeof payload !== "object" || payload == null)
|
|
4613
|
+
return void 0;
|
|
4614
|
+
const params = payload;
|
|
4615
|
+
const ls_stop = (_a = typeof params.stop === "string" ? [params.stop] : params.stop) != null ? _a : void 0;
|
|
4616
|
+
return {
|
|
4617
|
+
ls_provider: "openai",
|
|
4618
|
+
ls_model_type: "text",
|
|
4619
|
+
ls_model_name: params.model,
|
|
4620
|
+
ls_max_tokens: (_b = params.max_tokens) != null ? _b : void 0,
|
|
4621
|
+
ls_temperature: (_c = params.temperature) != null ? _c : void 0,
|
|
4622
|
+
ls_stop
|
|
4623
|
+
};
|
|
4624
|
+
}
|
|
4625
|
+
}, options));
|
|
4626
|
+
return openai;
|
|
4627
|
+
};
|
|
463
4628
|
|
|
464
4629
|
// src/types.ts
|
|
465
4630
|
var BaseElement = class {
|
|
@@ -478,19 +4643,19 @@ var envModelKey = "MIDSCENE_MODEL_NAME";
|
|
|
478
4643
|
var envSmithDebug = "MIDSCENE_LANGSMITH_DEBUG";
|
|
479
4644
|
var extraConfig = {};
|
|
480
4645
|
if (typeof process.env[envConfigKey] === "string") {
|
|
481
|
-
console.log("
|
|
4646
|
+
console.log("config for openai loaded");
|
|
482
4647
|
extraConfig = JSON.parse(process.env[envConfigKey]);
|
|
483
4648
|
}
|
|
484
4649
|
var model = "gpt-4o";
|
|
485
4650
|
if (typeof process.env[envModelKey] === "string") {
|
|
486
|
-
console.log(`
|
|
4651
|
+
console.log(`model: ${process.env[envModelKey]}`);
|
|
487
4652
|
model = process.env[envModelKey];
|
|
488
4653
|
}
|
|
489
4654
|
async function createOpenAI() {
|
|
490
4655
|
const openai = new import_openai.default(extraConfig);
|
|
491
4656
|
if (process.env[envSmithDebug]) {
|
|
492
|
-
console.log("DEBUGGING MODE:
|
|
493
|
-
const openai2 =
|
|
4657
|
+
console.log("DEBUGGING MODE: langsmith wrapper enabled");
|
|
4658
|
+
const openai2 = wrapOpenAI(new import_openai.default());
|
|
494
4659
|
return openai2;
|
|
495
4660
|
}
|
|
496
4661
|
return openai;
|