langsmith 0.1.20 → 0.1.22
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/client.cjs +71 -31
- package/dist/client.d.ts +7 -3
- package/dist/client.js +48 -8
- package/dist/evaluation/_random_name.cjs +730 -0
- package/dist/evaluation/_random_name.d.ts +5 -0
- package/dist/evaluation/_random_name.js +726 -0
- package/dist/evaluation/_runner.cjs +709 -0
- package/dist/evaluation/_runner.d.ts +158 -0
- package/dist/evaluation/_runner.js +705 -0
- package/dist/evaluation/evaluator.cjs +86 -0
- package/dist/evaluation/evaluator.d.ts +31 -27
- package/dist/evaluation/evaluator.js +83 -1
- package/dist/evaluation/index.cjs +3 -1
- package/dist/evaluation/index.d.ts +1 -0
- package/dist/evaluation/index.js +1 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/run_trees.cjs +4 -4
- package/dist/run_trees.d.ts +2 -1
- package/dist/run_trees.js +4 -4
- package/dist/schemas.d.ts +22 -1
- package/dist/traceable.cjs +237 -62
- package/dist/traceable.d.ts +7 -3
- package/dist/traceable.js +235 -61
- package/dist/utils/_git.cjs +72 -0
- package/dist/utils/_git.d.ts +14 -0
- package/dist/utils/_git.js +67 -0
- package/dist/utils/_uuid.cjs +33 -0
- package/dist/utils/_uuid.d.ts +1 -0
- package/dist/utils/_uuid.js +6 -0
- package/dist/utils/async_caller.cjs +17 -9
- package/dist/utils/async_caller.js +17 -9
- package/dist/utils/atee.cjs +24 -0
- package/dist/utils/atee.d.ts +1 -0
- package/dist/utils/atee.js +20 -0
- package/dist/wrappers/openai.cjs +53 -74
- package/dist/wrappers/openai.d.ts +10 -11
- package/dist/wrappers/openai.js +53 -74
- package/package.json +4 -4
package/dist/traceable.js
CHANGED
|
@@ -1,15 +1,32 @@
|
|
|
1
1
|
import { AsyncLocalStorage } from "async_hooks";
|
|
2
2
|
import { RunTree, isRunTree, isRunnableConfigLike, } from "./run_trees.js";
|
|
3
3
|
import { getEnvironmentVariable } from "./utils/env.js";
|
|
4
|
+
function isPromiseMethod(x) {
|
|
5
|
+
if (x === "then" || x === "catch" || x === "finally") {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
4
10
|
const asyncLocalStorage = new AsyncLocalStorage();
|
|
5
11
|
const isAsyncIterable = (x) => x != null &&
|
|
6
12
|
typeof x === "object" &&
|
|
7
13
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
8
14
|
typeof x[Symbol.asyncIterator] === "function";
|
|
9
|
-
const
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
15
|
+
const tracingIsEnabled = (tracingEnabled) => {
|
|
16
|
+
if (tracingEnabled !== undefined) {
|
|
17
|
+
return tracingEnabled;
|
|
18
|
+
}
|
|
19
|
+
const envVars = [
|
|
20
|
+
"LANGSMITH_TRACING_V2",
|
|
21
|
+
"LANGCHAIN_TRACING_V2",
|
|
22
|
+
"LANGSMITH_TRACING",
|
|
23
|
+
"LANGCHAIN_TRACING",
|
|
24
|
+
];
|
|
25
|
+
return Boolean(envVars.find((envVar) => getEnvironmentVariable(envVar) === "true"));
|
|
26
|
+
};
|
|
27
|
+
const getTracingRunTree = (runTree, tracingEnabled) => {
|
|
28
|
+
const tracingEnabled_ = tracingIsEnabled(tracingEnabled);
|
|
29
|
+
if (!tracingEnabled_) {
|
|
13
30
|
return undefined;
|
|
14
31
|
}
|
|
15
32
|
return runTree;
|
|
@@ -30,14 +47,55 @@ const getTracingRunTree = (runTree) => {
|
|
|
30
47
|
*/
|
|
31
48
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
49
|
export function traceable(wrappedFunc, config) {
|
|
33
|
-
const { aggregator, ...runTreeConfig } = config ?? {};
|
|
34
|
-
const traceableFunc =
|
|
50
|
+
const { aggregator, argsConfigPath, tracingEnabled, ...runTreeConfig } = config ?? {};
|
|
51
|
+
const traceableFunc = (...args) => {
|
|
35
52
|
let currentRunTree;
|
|
36
53
|
let rawInputs;
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
54
|
+
let ensuredConfig;
|
|
55
|
+
try {
|
|
56
|
+
let runtimeConfig;
|
|
57
|
+
if (argsConfigPath) {
|
|
58
|
+
const [index, path] = argsConfigPath;
|
|
59
|
+
if (index === args.length - 1 && !path) {
|
|
60
|
+
runtimeConfig = args.pop();
|
|
61
|
+
}
|
|
62
|
+
else if (index <= args.length &&
|
|
63
|
+
typeof args[index] === "object" &&
|
|
64
|
+
args[index] !== null) {
|
|
65
|
+
if (path) {
|
|
66
|
+
const { [path]: extracted, ...rest } = args[index];
|
|
67
|
+
runtimeConfig = extracted;
|
|
68
|
+
args[index] = rest;
|
|
69
|
+
}
|
|
70
|
+
else {
|
|
71
|
+
runtimeConfig = args[index];
|
|
72
|
+
args.splice(index, 1);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
ensuredConfig = {
|
|
77
|
+
name: wrappedFunc.name || "<lambda>",
|
|
78
|
+
...runTreeConfig,
|
|
79
|
+
...runtimeConfig,
|
|
80
|
+
tags: [
|
|
81
|
+
...new Set([
|
|
82
|
+
...(runTreeConfig?.tags ?? []),
|
|
83
|
+
...(runtimeConfig?.tags ?? []),
|
|
84
|
+
]),
|
|
85
|
+
],
|
|
86
|
+
metadata: {
|
|
87
|
+
...runTreeConfig?.metadata,
|
|
88
|
+
...runtimeConfig?.metadata,
|
|
89
|
+
},
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
catch (err) {
|
|
93
|
+
console.warn(`Failed to extract runtime config from args for ${runTreeConfig?.name ?? wrappedFunc.name}`, err);
|
|
94
|
+
ensuredConfig = {
|
|
95
|
+
name: wrappedFunc.name || "<lambda>",
|
|
96
|
+
...runTreeConfig,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
41
99
|
const previousRunTree = asyncLocalStorage.getStore();
|
|
42
100
|
if (isRunTree(args[0])) {
|
|
43
101
|
currentRunTree = args[0];
|
|
@@ -48,14 +106,14 @@ export function traceable(wrappedFunc, config) {
|
|
|
48
106
|
rawInputs = args.slice(1);
|
|
49
107
|
}
|
|
50
108
|
else if (previousRunTree !== undefined) {
|
|
51
|
-
currentRunTree =
|
|
109
|
+
currentRunTree = previousRunTree.createChild(ensuredConfig);
|
|
52
110
|
rawInputs = args;
|
|
53
111
|
}
|
|
54
112
|
else {
|
|
55
113
|
currentRunTree = new RunTree(ensuredConfig);
|
|
56
114
|
rawInputs = args;
|
|
57
115
|
}
|
|
58
|
-
currentRunTree = getTracingRunTree(currentRunTree);
|
|
116
|
+
currentRunTree = getTracingRunTree(currentRunTree, tracingEnabled);
|
|
59
117
|
let inputs;
|
|
60
118
|
const firstInput = rawInputs[0];
|
|
61
119
|
if (firstInput == null) {
|
|
@@ -73,74 +131,181 @@ export function traceable(wrappedFunc, config) {
|
|
|
73
131
|
if (currentRunTree) {
|
|
74
132
|
currentRunTree.inputs = inputs;
|
|
75
133
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
134
|
+
return asyncLocalStorage.run(currentRunTree, () => {
|
|
135
|
+
const postRunPromise = currentRunTree?.postRun();
|
|
136
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
137
|
+
let returnValue;
|
|
138
|
+
try {
|
|
139
|
+
returnValue = wrappedFunc(...rawInputs);
|
|
140
|
+
}
|
|
141
|
+
catch (err) {
|
|
142
|
+
returnValue = Promise.reject(err);
|
|
143
|
+
}
|
|
144
|
+
if (isAsyncIterable(returnValue)) {
|
|
145
|
+
// eslint-disable-next-line no-inner-declarations
|
|
146
|
+
async function* wrapOutputForTracing() {
|
|
147
|
+
let finished = false;
|
|
148
|
+
const chunks = [];
|
|
149
|
+
try {
|
|
150
|
+
for await (const chunk of returnValue) {
|
|
151
|
+
chunks.push(chunk);
|
|
152
|
+
yield chunk;
|
|
153
|
+
}
|
|
154
|
+
finished = true;
|
|
155
|
+
}
|
|
156
|
+
catch (e) {
|
|
157
|
+
await currentRunTree?.end(undefined, String(e));
|
|
158
|
+
throw e;
|
|
159
|
+
}
|
|
160
|
+
finally {
|
|
161
|
+
if (!finished) {
|
|
162
|
+
await currentRunTree?.end(undefined, "Cancelled");
|
|
163
|
+
}
|
|
164
|
+
let finalOutputs;
|
|
165
|
+
if (aggregator !== undefined) {
|
|
166
|
+
try {
|
|
167
|
+
finalOutputs = await aggregator(chunks);
|
|
168
|
+
}
|
|
169
|
+
catch (e) {
|
|
170
|
+
console.error(`[ERROR]: LangSmith aggregation failed: `, e);
|
|
171
|
+
finalOutputs = chunks;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
else {
|
|
175
|
+
finalOutputs = chunks;
|
|
176
|
+
}
|
|
177
|
+
if (typeof finalOutputs === "object" &&
|
|
178
|
+
!Array.isArray(finalOutputs)) {
|
|
179
|
+
await currentRunTree?.end(finalOutputs);
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
await currentRunTree?.end({ outputs: finalOutputs });
|
|
183
|
+
}
|
|
184
|
+
const onEnd = config?.on_end;
|
|
185
|
+
if (onEnd) {
|
|
186
|
+
if (!currentRunTree) {
|
|
187
|
+
console.warn("Can not call 'on_end' if currentRunTree is undefined");
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
onEnd(currentRunTree);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
await postRunPromise;
|
|
194
|
+
await currentRunTree?.patchRun();
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return wrapOutputForTracing();
|
|
198
|
+
}
|
|
199
|
+
const tracedPromise = new Promise((resolve, reject) => {
|
|
200
|
+
Promise.resolve(returnValue)
|
|
201
|
+
.then(
|
|
202
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
203
|
+
async (rawOutput) => {
|
|
83
204
|
if (isAsyncIterable(rawOutput)) {
|
|
84
205
|
// eslint-disable-next-line no-inner-declarations
|
|
85
206
|
async function* wrapOutputForTracing() {
|
|
207
|
+
let finished = false;
|
|
86
208
|
const chunks = [];
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
209
|
+
try {
|
|
210
|
+
// TypeScript thinks this is unsafe
|
|
211
|
+
for await (const chunk of rawOutput) {
|
|
212
|
+
chunks.push(chunk);
|
|
213
|
+
yield chunk;
|
|
214
|
+
}
|
|
215
|
+
finished = true;
|
|
216
|
+
}
|
|
217
|
+
catch (e) {
|
|
218
|
+
await currentRunTree?.end(undefined, String(e));
|
|
219
|
+
throw e;
|
|
91
220
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
finalOutputs = await aggregator(chunks);
|
|
221
|
+
finally {
|
|
222
|
+
if (!finished) {
|
|
223
|
+
await currentRunTree?.end(undefined, "Cancelled");
|
|
96
224
|
}
|
|
97
|
-
|
|
98
|
-
|
|
225
|
+
let finalOutputs;
|
|
226
|
+
if (aggregator !== undefined) {
|
|
227
|
+
try {
|
|
228
|
+
finalOutputs = await aggregator(chunks);
|
|
229
|
+
}
|
|
230
|
+
catch (e) {
|
|
231
|
+
console.error(`[ERROR]: LangSmith aggregation failed: `, e);
|
|
232
|
+
finalOutputs = chunks;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
else {
|
|
99
236
|
finalOutputs = chunks;
|
|
100
237
|
}
|
|
238
|
+
if (typeof finalOutputs === "object" &&
|
|
239
|
+
!Array.isArray(finalOutputs)) {
|
|
240
|
+
await currentRunTree?.end(finalOutputs);
|
|
241
|
+
}
|
|
242
|
+
else {
|
|
243
|
+
await currentRunTree?.end({ outputs: finalOutputs });
|
|
244
|
+
}
|
|
245
|
+
const onEnd = config?.on_end;
|
|
246
|
+
if (onEnd) {
|
|
247
|
+
if (!currentRunTree) {
|
|
248
|
+
console.warn("Can not call 'on_end' if currentRunTree is undefined");
|
|
249
|
+
}
|
|
250
|
+
else {
|
|
251
|
+
onEnd(currentRunTree);
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
await postRunPromise;
|
|
255
|
+
await currentRunTree?.patchRun();
|
|
101
256
|
}
|
|
102
|
-
else {
|
|
103
|
-
finalOutputs = chunks;
|
|
104
|
-
}
|
|
105
|
-
if (typeof finalOutputs === "object" &&
|
|
106
|
-
!Array.isArray(finalOutputs)) {
|
|
107
|
-
await currentRunTree?.end(finalOutputs);
|
|
108
|
-
}
|
|
109
|
-
else {
|
|
110
|
-
await currentRunTree?.end({ outputs: finalOutputs });
|
|
111
|
-
}
|
|
112
|
-
await currentRunTree?.patchRun();
|
|
113
257
|
}
|
|
114
258
|
return resolve(wrapOutputForTracing());
|
|
115
259
|
}
|
|
116
260
|
else {
|
|
117
|
-
|
|
118
|
-
? rawOutput
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
261
|
+
try {
|
|
262
|
+
await currentRunTree?.end(isKVMap(rawOutput) ? rawOutput : { outputs: rawOutput });
|
|
263
|
+
const onEnd = config?.on_end;
|
|
264
|
+
if (onEnd) {
|
|
265
|
+
if (!currentRunTree) {
|
|
266
|
+
console.warn("Can not call 'on_end' if currentRunTree is undefined");
|
|
267
|
+
}
|
|
268
|
+
else {
|
|
269
|
+
onEnd(currentRunTree);
|
|
270
|
+
}
|
|
126
271
|
}
|
|
272
|
+
await postRunPromise;
|
|
273
|
+
await currentRunTree?.patchRun();
|
|
274
|
+
}
|
|
275
|
+
finally {
|
|
276
|
+
// eslint-disable-next-line no-unsafe-finally
|
|
277
|
+
return rawOutput;
|
|
127
278
|
}
|
|
128
|
-
await currentRunTree?.patchRun();
|
|
129
|
-
return resolve(rawOutput);
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
catch (error) {
|
|
133
|
-
if (initialError === currentRunTree?.error) {
|
|
134
|
-
await currentRunTree?.end(initialOutputs, String(error));
|
|
135
279
|
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
280
|
+
},
|
|
281
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
282
|
+
async (error) => {
|
|
283
|
+
await currentRunTree?.end(undefined, String(error));
|
|
284
|
+
const onEnd = config?.on_end;
|
|
285
|
+
if (onEnd) {
|
|
286
|
+
if (!currentRunTree) {
|
|
287
|
+
console.warn("Can not call 'on_end' if currentRunTree is undefined");
|
|
288
|
+
}
|
|
289
|
+
else {
|
|
290
|
+
onEnd(currentRunTree);
|
|
139
291
|
}
|
|
140
292
|
}
|
|
293
|
+
await postRunPromise;
|
|
141
294
|
await currentRunTree?.patchRun();
|
|
142
|
-
|
|
143
|
-
}
|
|
295
|
+
throw error;
|
|
296
|
+
})
|
|
297
|
+
.then(resolve, reject);
|
|
298
|
+
});
|
|
299
|
+
if (typeof returnValue !== "object" || returnValue === null) {
|
|
300
|
+
return tracedPromise;
|
|
301
|
+
}
|
|
302
|
+
return new Proxy(returnValue, {
|
|
303
|
+
get(target, prop, receiver) {
|
|
304
|
+
if (isPromiseMethod(prop)) {
|
|
305
|
+
return tracedPromise[prop].bind(tracedPromise);
|
|
306
|
+
}
|
|
307
|
+
return Reflect.get(target, prop, receiver);
|
|
308
|
+
},
|
|
144
309
|
});
|
|
145
310
|
});
|
|
146
311
|
};
|
|
@@ -178,3 +343,12 @@ function isKVMap(x) {
|
|
|
178
343
|
// eslint-disable-next-line no-instanceof/no-instanceof
|
|
179
344
|
!(x instanceof Date));
|
|
180
345
|
}
|
|
346
|
+
export function wrapFunctionAndEnsureTraceable(target, options, name = "target") {
|
|
347
|
+
if (typeof target === "function") {
|
|
348
|
+
return traceable(target, {
|
|
349
|
+
...options,
|
|
350
|
+
name,
|
|
351
|
+
});
|
|
352
|
+
}
|
|
353
|
+
throw new Error("Target must be runnable function");
|
|
354
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.getDefaultRevisionId = exports.getGitInfo = void 0;
|
|
4
|
+
async function importChildProcess() {
|
|
5
|
+
const { exec } = await import("child_process");
|
|
6
|
+
return { exec };
|
|
7
|
+
}
|
|
8
|
+
const execGit = (command, exec) => {
|
|
9
|
+
return new Promise((resolve) => {
|
|
10
|
+
exec(`git ${command.join(" ")}`, (error, stdout) => {
|
|
11
|
+
if (error) {
|
|
12
|
+
resolve(null);
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
resolve(stdout.trim());
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
});
|
|
19
|
+
};
|
|
20
|
+
const getGitInfo = async (remote = "origin") => {
|
|
21
|
+
let exec;
|
|
22
|
+
try {
|
|
23
|
+
const execImport = await importChildProcess();
|
|
24
|
+
exec = execImport.exec;
|
|
25
|
+
}
|
|
26
|
+
catch (e) {
|
|
27
|
+
// no-op
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
const isInsideWorkTree = await execGit(["rev-parse", "--is-inside-work-tree"], exec);
|
|
31
|
+
if (!isInsideWorkTree) {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
const [remoteUrl, commit, commitTime, branch, tags, dirty, authorName, authorEmail,] = await Promise.all([
|
|
35
|
+
execGit(["remote", "get-url", remote], exec),
|
|
36
|
+
execGit(["rev-parse", "HEAD"], exec),
|
|
37
|
+
execGit(["log", "-1", "--format=%ct"], exec),
|
|
38
|
+
execGit(["rev-parse", "--abbrev-ref", "HEAD"], exec),
|
|
39
|
+
execGit(["describe", "--tags", "--exact-match", "--always", "--dirty"], exec),
|
|
40
|
+
execGit(["status", "--porcelain"], exec).then((output) => output !== ""),
|
|
41
|
+
execGit(["log", "-1", "--format=%an"], exec),
|
|
42
|
+
execGit(["log", "-1", "--format=%ae"], exec),
|
|
43
|
+
]);
|
|
44
|
+
return {
|
|
45
|
+
remoteUrl,
|
|
46
|
+
commit,
|
|
47
|
+
commitTime,
|
|
48
|
+
branch,
|
|
49
|
+
tags,
|
|
50
|
+
dirty,
|
|
51
|
+
authorName,
|
|
52
|
+
authorEmail,
|
|
53
|
+
};
|
|
54
|
+
};
|
|
55
|
+
exports.getGitInfo = getGitInfo;
|
|
56
|
+
const getDefaultRevisionId = async () => {
|
|
57
|
+
let exec;
|
|
58
|
+
try {
|
|
59
|
+
const execImport = await importChildProcess();
|
|
60
|
+
exec = execImport.exec;
|
|
61
|
+
}
|
|
62
|
+
catch (e) {
|
|
63
|
+
// no-op
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
const commit = await execGit(["rev-parse", "HEAD"], exec);
|
|
67
|
+
if (!commit) {
|
|
68
|
+
return null;
|
|
69
|
+
}
|
|
70
|
+
return commit;
|
|
71
|
+
};
|
|
72
|
+
exports.getDefaultRevisionId = getDefaultRevisionId;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface GitInfo {
|
|
2
|
+
remoteUrl?: string | null;
|
|
3
|
+
commit?: string | null;
|
|
4
|
+
branch?: string | null;
|
|
5
|
+
authorName?: string | null;
|
|
6
|
+
authorEmail?: string | null;
|
|
7
|
+
commitMessage?: string | null;
|
|
8
|
+
commitTime?: string | null;
|
|
9
|
+
dirty?: boolean | null;
|
|
10
|
+
tags?: string | null;
|
|
11
|
+
}
|
|
12
|
+
export declare const getGitInfo: (remote?: string) => Promise<GitInfo | null>;
|
|
13
|
+
export declare const getDefaultRevisionId: () => Promise<string | null>;
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
async function importChildProcess() {
|
|
2
|
+
const { exec } = await import("child_process");
|
|
3
|
+
return { exec };
|
|
4
|
+
}
|
|
5
|
+
const execGit = (command, exec) => {
|
|
6
|
+
return new Promise((resolve) => {
|
|
7
|
+
exec(`git ${command.join(" ")}`, (error, stdout) => {
|
|
8
|
+
if (error) {
|
|
9
|
+
resolve(null);
|
|
10
|
+
}
|
|
11
|
+
else {
|
|
12
|
+
resolve(stdout.trim());
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export const getGitInfo = async (remote = "origin") => {
|
|
18
|
+
let exec;
|
|
19
|
+
try {
|
|
20
|
+
const execImport = await importChildProcess();
|
|
21
|
+
exec = execImport.exec;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
// no-op
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
const isInsideWorkTree = await execGit(["rev-parse", "--is-inside-work-tree"], exec);
|
|
28
|
+
if (!isInsideWorkTree) {
|
|
29
|
+
return null;
|
|
30
|
+
}
|
|
31
|
+
const [remoteUrl, commit, commitTime, branch, tags, dirty, authorName, authorEmail,] = await Promise.all([
|
|
32
|
+
execGit(["remote", "get-url", remote], exec),
|
|
33
|
+
execGit(["rev-parse", "HEAD"], exec),
|
|
34
|
+
execGit(["log", "-1", "--format=%ct"], exec),
|
|
35
|
+
execGit(["rev-parse", "--abbrev-ref", "HEAD"], exec),
|
|
36
|
+
execGit(["describe", "--tags", "--exact-match", "--always", "--dirty"], exec),
|
|
37
|
+
execGit(["status", "--porcelain"], exec).then((output) => output !== ""),
|
|
38
|
+
execGit(["log", "-1", "--format=%an"], exec),
|
|
39
|
+
execGit(["log", "-1", "--format=%ae"], exec),
|
|
40
|
+
]);
|
|
41
|
+
return {
|
|
42
|
+
remoteUrl,
|
|
43
|
+
commit,
|
|
44
|
+
commitTime,
|
|
45
|
+
branch,
|
|
46
|
+
tags,
|
|
47
|
+
dirty,
|
|
48
|
+
authorName,
|
|
49
|
+
authorEmail,
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export const getDefaultRevisionId = async () => {
|
|
53
|
+
let exec;
|
|
54
|
+
try {
|
|
55
|
+
const execImport = await importChildProcess();
|
|
56
|
+
exec = execImport.exec;
|
|
57
|
+
}
|
|
58
|
+
catch (e) {
|
|
59
|
+
// no-op
|
|
60
|
+
return null;
|
|
61
|
+
}
|
|
62
|
+
const commit = await execGit(["rev-parse", "HEAD"], exec);
|
|
63
|
+
if (!commit) {
|
|
64
|
+
return null;
|
|
65
|
+
}
|
|
66
|
+
return commit;
|
|
67
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.assertUuid = void 0;
|
|
27
|
+
const uuid = __importStar(require("uuid"));
|
|
28
|
+
function assertUuid(str) {
|
|
29
|
+
if (!uuid.validate(str)) {
|
|
30
|
+
throw new Error(`Invalid UUID: ${str}`);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
exports.assertUuid = assertUuid;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function assertUuid(str: string): void;
|
|
@@ -7,13 +7,13 @@ exports.AsyncCaller = void 0;
|
|
|
7
7
|
const p_retry_1 = __importDefault(require("p-retry"));
|
|
8
8
|
const p_queue_1 = __importDefault(require("p-queue"));
|
|
9
9
|
const STATUS_NO_RETRY = [
|
|
10
|
-
400,
|
|
11
|
-
401,
|
|
12
|
-
403,
|
|
13
|
-
404,
|
|
14
|
-
405,
|
|
15
|
-
406,
|
|
16
|
-
407,
|
|
10
|
+
400, // Bad Request
|
|
11
|
+
401, // Unauthorized
|
|
12
|
+
403, // Forbidden
|
|
13
|
+
404, // Not Found
|
|
14
|
+
405, // Method Not Allowed
|
|
15
|
+
406, // Not Acceptable
|
|
16
|
+
407, // Proxy Authentication Required
|
|
17
17
|
408, // Request Timeout
|
|
18
18
|
];
|
|
19
19
|
const STATUS_IGNORE = [
|
|
@@ -60,8 +60,16 @@ class AsyncCaller {
|
|
|
60
60
|
});
|
|
61
61
|
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
62
62
|
this.maxRetries = params.maxRetries ?? 6;
|
|
63
|
-
|
|
64
|
-
|
|
63
|
+
if ("default" in p_queue_1.default) {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
this.queue = new p_queue_1.default.default({
|
|
66
|
+
concurrency: this.maxConcurrency,
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
else {
|
|
70
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
71
|
+
this.queue = new p_queue_1.default({ concurrency: this.maxConcurrency });
|
|
72
|
+
}
|
|
65
73
|
this.onFailedResponseHook = params?.onFailedResponseHook;
|
|
66
74
|
}
|
|
67
75
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import pRetry from "p-retry";
|
|
2
2
|
import PQueueMod from "p-queue";
|
|
3
3
|
const STATUS_NO_RETRY = [
|
|
4
|
-
400,
|
|
5
|
-
401,
|
|
6
|
-
403,
|
|
7
|
-
404,
|
|
8
|
-
405,
|
|
9
|
-
406,
|
|
10
|
-
407,
|
|
4
|
+
400, // Bad Request
|
|
5
|
+
401, // Unauthorized
|
|
6
|
+
403, // Forbidden
|
|
7
|
+
404, // Not Found
|
|
8
|
+
405, // Method Not Allowed
|
|
9
|
+
406, // Not Acceptable
|
|
10
|
+
407, // Proxy Authentication Required
|
|
11
11
|
408, // Request Timeout
|
|
12
12
|
];
|
|
13
13
|
const STATUS_IGNORE = [
|
|
@@ -54,8 +54,16 @@ export class AsyncCaller {
|
|
|
54
54
|
});
|
|
55
55
|
this.maxConcurrency = params.maxConcurrency ?? Infinity;
|
|
56
56
|
this.maxRetries = params.maxRetries ?? 6;
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
if ("default" in PQueueMod) {
|
|
58
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
59
|
+
this.queue = new PQueueMod.default({
|
|
60
|
+
concurrency: this.maxConcurrency,
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
65
|
+
this.queue = new PQueueMod({ concurrency: this.maxConcurrency });
|
|
66
|
+
}
|
|
59
67
|
this.onFailedResponseHook = params?.onFailedResponseHook;
|
|
60
68
|
}
|
|
61
69
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.atee = void 0;
|
|
4
|
+
function atee(iter, length = 2) {
|
|
5
|
+
const buffers = Array.from({ length }, () => []);
|
|
6
|
+
return buffers.map(async function* makeIter(buffer) {
|
|
7
|
+
while (true) {
|
|
8
|
+
if (buffer.length === 0) {
|
|
9
|
+
const result = await iter.next();
|
|
10
|
+
for (const buffer of buffers) {
|
|
11
|
+
buffer.push(result);
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
else if (buffer[0].done) {
|
|
15
|
+
return;
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
19
|
+
yield buffer.shift().value;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
exports.atee = atee;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function atee<T>(iter: AsyncGenerator<T>, length?: number): AsyncGenerator<T>[];
|