langsmith 0.0.38 → 0.0.40
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/client.cjs +65 -8
- package/dist/client.d.ts +14 -3
- package/dist/client.js +65 -8
- package/dist/schemas.d.ts +15 -0
- package/package.json +1 -1
package/dist/client.cjs
CHANGED
|
@@ -84,6 +84,12 @@ class Client {
|
|
|
84
84
|
writable: true,
|
|
85
85
|
value: void 0
|
|
86
86
|
});
|
|
87
|
+
Object.defineProperty(this, "webUrl", {
|
|
88
|
+
enumerable: true,
|
|
89
|
+
configurable: true,
|
|
90
|
+
writable: true,
|
|
91
|
+
value: void 0
|
|
92
|
+
});
|
|
87
93
|
Object.defineProperty(this, "caller", {
|
|
88
94
|
enumerable: true,
|
|
89
95
|
configurable: true,
|
|
@@ -96,9 +102,16 @@ class Client {
|
|
|
96
102
|
writable: true,
|
|
97
103
|
value: void 0
|
|
98
104
|
});
|
|
105
|
+
Object.defineProperty(this, "_tenantId", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
configurable: true,
|
|
108
|
+
writable: true,
|
|
109
|
+
value: null
|
|
110
|
+
});
|
|
99
111
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
100
112
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
101
113
|
this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
|
|
114
|
+
this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
|
|
102
115
|
this.validateApiKeyIfHosted();
|
|
103
116
|
this.timeout_ms = config.timeout_ms ?? 4000;
|
|
104
117
|
this.caller = new async_caller_js_1.AsyncCaller(config.callerOptions ?? {});
|
|
@@ -110,6 +123,7 @@ class Client {
|
|
|
110
123
|
return {
|
|
111
124
|
apiUrl: apiUrl,
|
|
112
125
|
apiKey: apiKey,
|
|
126
|
+
webUrl: undefined,
|
|
113
127
|
};
|
|
114
128
|
}
|
|
115
129
|
validateApiKeyIfHosted() {
|
|
@@ -119,13 +133,19 @@ class Client {
|
|
|
119
133
|
}
|
|
120
134
|
}
|
|
121
135
|
getHostUrl() {
|
|
122
|
-
if (
|
|
136
|
+
if (this.webUrl) {
|
|
137
|
+
return this.webUrl;
|
|
138
|
+
}
|
|
139
|
+
else if (isLocalhost(this.apiUrl)) {
|
|
140
|
+
this.webUrl = "http://localhost";
|
|
123
141
|
return "http://localhost";
|
|
124
142
|
}
|
|
125
143
|
else if (this.apiUrl.split(".", 1)[0].includes("dev")) {
|
|
144
|
+
this.webUrl = "https://dev.smith.langchain.com";
|
|
126
145
|
return "https://dev.smith.langchain.com";
|
|
127
146
|
}
|
|
128
147
|
else {
|
|
148
|
+
this.webUrl = "https://smith.langchain.com";
|
|
129
149
|
return "https://smith.langchain.com";
|
|
130
150
|
}
|
|
131
151
|
}
|
|
@@ -227,19 +247,45 @@ class Client {
|
|
|
227
247
|
}
|
|
228
248
|
return run;
|
|
229
249
|
}
|
|
230
|
-
async getRunUrl({ runId, }) {
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
250
|
+
async getRunUrl({ runId, run, projectOpts, }) {
|
|
251
|
+
if (run !== undefined) {
|
|
252
|
+
let sessionId;
|
|
253
|
+
if (run.session_id) {
|
|
254
|
+
sessionId = run.session_id;
|
|
255
|
+
}
|
|
256
|
+
else if (projectOpts?.projectName) {
|
|
257
|
+
sessionId = (await this.readProject({ projectName: projectOpts?.projectName })).id;
|
|
258
|
+
}
|
|
259
|
+
else if (projectOpts?.projectId) {
|
|
260
|
+
sessionId = projectOpts?.projectId;
|
|
261
|
+
}
|
|
262
|
+
else {
|
|
263
|
+
const project = await this.readProject({
|
|
264
|
+
projectName: (0, env_js_1.getEnvironmentVariable)("LANGCHAIN_PROJECT") || "default",
|
|
265
|
+
});
|
|
266
|
+
sessionId = project.id;
|
|
267
|
+
}
|
|
268
|
+
const tenantId = await this._getTenantId();
|
|
269
|
+
return `${this.getHostUrl()}/o/${tenantId}/projects/p/${sessionId}/r/${run.id}?poll=true`;
|
|
270
|
+
}
|
|
271
|
+
else if (runId !== undefined) {
|
|
272
|
+
const run_ = await this.readRun(runId);
|
|
273
|
+
if (!run_.app_path) {
|
|
274
|
+
throw new Error(`Run ${runId} has no app_path`);
|
|
275
|
+
}
|
|
276
|
+
const baseUrl = this.getHostUrl();
|
|
277
|
+
return `${baseUrl}${run_.app_path}`;
|
|
278
|
+
}
|
|
279
|
+
else {
|
|
280
|
+
throw new Error("Must provide either runId or run");
|
|
234
281
|
}
|
|
235
|
-
const baseUrl = this.getHostUrl();
|
|
236
|
-
return `${baseUrl}${run.app_path}`;
|
|
237
282
|
}
|
|
238
283
|
async _loadChildRuns(run) {
|
|
239
284
|
const childRuns = await toArray(this.listRuns({ id: run.child_run_ids }));
|
|
240
285
|
const treemap = {};
|
|
241
286
|
const runs = {};
|
|
242
|
-
|
|
287
|
+
// TODO: make dotted order required when the migration finishes
|
|
288
|
+
childRuns.sort((a, b) => (a?.dotted_order ?? "").localeCompare(b?.dotted_order ?? ""));
|
|
243
289
|
for (const childRun of childRuns) {
|
|
244
290
|
if (childRun.parent_run_id === null ||
|
|
245
291
|
childRun.parent_run_id === undefined) {
|
|
@@ -399,6 +445,17 @@ class Client {
|
|
|
399
445
|
}
|
|
400
446
|
return result;
|
|
401
447
|
}
|
|
448
|
+
async _getTenantId() {
|
|
449
|
+
if (this._tenantId !== null) {
|
|
450
|
+
return this._tenantId;
|
|
451
|
+
}
|
|
452
|
+
const queryParams = new URLSearchParams({ limit: "1" });
|
|
453
|
+
for await (const projects of this._getPaginated("/sessions", queryParams)) {
|
|
454
|
+
this._tenantId = projects[0].tenant_id;
|
|
455
|
+
return projects[0].tenant_id;
|
|
456
|
+
}
|
|
457
|
+
throw new Error("No projects found to resolve tenant.");
|
|
458
|
+
}
|
|
402
459
|
async *listProjects({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, referenceFree, } = {}) {
|
|
403
460
|
const params = new URLSearchParams();
|
|
404
461
|
if (projectIds !== undefined) {
|
package/dist/client.d.ts
CHANGED
|
@@ -6,6 +6,7 @@ interface ClientConfig {
|
|
|
6
6
|
apiKey?: string;
|
|
7
7
|
callerOptions?: AsyncCallerParams;
|
|
8
8
|
timeout_ms?: number;
|
|
9
|
+
webUrl?: string;
|
|
9
10
|
}
|
|
10
11
|
interface ListRunsParams {
|
|
11
12
|
projectId?: string;
|
|
@@ -48,6 +49,10 @@ interface CreateRunParams {
|
|
|
48
49
|
parent_run_id?: string;
|
|
49
50
|
project_name?: string;
|
|
50
51
|
}
|
|
52
|
+
interface projectOptions {
|
|
53
|
+
projectName?: string;
|
|
54
|
+
projectId?: string;
|
|
55
|
+
}
|
|
51
56
|
export type FeedbackSourceType = "model" | "api" | "app";
|
|
52
57
|
export type CreateExampleOptions = {
|
|
53
58
|
datasetId?: string;
|
|
@@ -58,12 +63,15 @@ export type CreateExampleOptions = {
|
|
|
58
63
|
export declare class Client {
|
|
59
64
|
private apiKey?;
|
|
60
65
|
private apiUrl;
|
|
66
|
+
private webUrl?;
|
|
61
67
|
private caller;
|
|
62
68
|
private timeout_ms;
|
|
69
|
+
private _tenantId;
|
|
63
70
|
constructor(config?: ClientConfig);
|
|
64
71
|
static getDefaultClientConfig(): {
|
|
65
72
|
apiUrl: string;
|
|
66
73
|
apiKey?: string;
|
|
74
|
+
webUrl?: string;
|
|
67
75
|
};
|
|
68
76
|
private validateApiKeyIfHosted;
|
|
69
77
|
private getHostUrl;
|
|
@@ -75,9 +83,11 @@ export declare class Client {
|
|
|
75
83
|
readRun(runId: string, { loadChildRuns }?: {
|
|
76
84
|
loadChildRuns: boolean;
|
|
77
85
|
}): Promise<Run>;
|
|
78
|
-
getRunUrl({ runId, }: {
|
|
79
|
-
runId
|
|
80
|
-
|
|
86
|
+
getRunUrl({ runId, run, projectOpts, }: {
|
|
87
|
+
runId?: string;
|
|
88
|
+
run?: Run;
|
|
89
|
+
projectOpts?: projectOptions;
|
|
90
|
+
}): Promise<string>;
|
|
81
91
|
private _loadChildRuns;
|
|
82
92
|
listRuns({ projectId, projectName, parentRunId, referenceExampleId, startTime, executionOrder, runType, error, id, limit, offset, query, filter, }: ListRunsParams): AsyncIterable<Run>;
|
|
83
93
|
shareRun(runId: string, { shareId }?: {
|
|
@@ -95,6 +105,7 @@ export declare class Client {
|
|
|
95
105
|
projectId?: string;
|
|
96
106
|
projectName?: string;
|
|
97
107
|
}): Promise<TracerSessionResult>;
|
|
108
|
+
private _getTenantId;
|
|
98
109
|
listProjects({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, referenceFree, }?: {
|
|
99
110
|
projectIds?: string[];
|
|
100
111
|
name?: string;
|
package/dist/client.js
CHANGED
|
@@ -58,6 +58,12 @@ export class Client {
|
|
|
58
58
|
writable: true,
|
|
59
59
|
value: void 0
|
|
60
60
|
});
|
|
61
|
+
Object.defineProperty(this, "webUrl", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
configurable: true,
|
|
64
|
+
writable: true,
|
|
65
|
+
value: void 0
|
|
66
|
+
});
|
|
61
67
|
Object.defineProperty(this, "caller", {
|
|
62
68
|
enumerable: true,
|
|
63
69
|
configurable: true,
|
|
@@ -70,9 +76,16 @@ export class Client {
|
|
|
70
76
|
writable: true,
|
|
71
77
|
value: void 0
|
|
72
78
|
});
|
|
79
|
+
Object.defineProperty(this, "_tenantId", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
configurable: true,
|
|
82
|
+
writable: true,
|
|
83
|
+
value: null
|
|
84
|
+
});
|
|
73
85
|
const defaultConfig = Client.getDefaultClientConfig();
|
|
74
86
|
this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
|
|
75
87
|
this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
|
|
88
|
+
this.webUrl = trimQuotes(config.webUrl ?? defaultConfig.webUrl);
|
|
76
89
|
this.validateApiKeyIfHosted();
|
|
77
90
|
this.timeout_ms = config.timeout_ms ?? 4000;
|
|
78
91
|
this.caller = new AsyncCaller(config.callerOptions ?? {});
|
|
@@ -84,6 +97,7 @@ export class Client {
|
|
|
84
97
|
return {
|
|
85
98
|
apiUrl: apiUrl,
|
|
86
99
|
apiKey: apiKey,
|
|
100
|
+
webUrl: undefined,
|
|
87
101
|
};
|
|
88
102
|
}
|
|
89
103
|
validateApiKeyIfHosted() {
|
|
@@ -93,13 +107,19 @@ export class Client {
|
|
|
93
107
|
}
|
|
94
108
|
}
|
|
95
109
|
getHostUrl() {
|
|
96
|
-
if (
|
|
110
|
+
if (this.webUrl) {
|
|
111
|
+
return this.webUrl;
|
|
112
|
+
}
|
|
113
|
+
else if (isLocalhost(this.apiUrl)) {
|
|
114
|
+
this.webUrl = "http://localhost";
|
|
97
115
|
return "http://localhost";
|
|
98
116
|
}
|
|
99
117
|
else if (this.apiUrl.split(".", 1)[0].includes("dev")) {
|
|
118
|
+
this.webUrl = "https://dev.smith.langchain.com";
|
|
100
119
|
return "https://dev.smith.langchain.com";
|
|
101
120
|
}
|
|
102
121
|
else {
|
|
122
|
+
this.webUrl = "https://smith.langchain.com";
|
|
103
123
|
return "https://smith.langchain.com";
|
|
104
124
|
}
|
|
105
125
|
}
|
|
@@ -201,19 +221,45 @@ export class Client {
|
|
|
201
221
|
}
|
|
202
222
|
return run;
|
|
203
223
|
}
|
|
204
|
-
async getRunUrl({ runId, }) {
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
224
|
+
async getRunUrl({ runId, run, projectOpts, }) {
|
|
225
|
+
if (run !== undefined) {
|
|
226
|
+
let sessionId;
|
|
227
|
+
if (run.session_id) {
|
|
228
|
+
sessionId = run.session_id;
|
|
229
|
+
}
|
|
230
|
+
else if (projectOpts?.projectName) {
|
|
231
|
+
sessionId = (await this.readProject({ projectName: projectOpts?.projectName })).id;
|
|
232
|
+
}
|
|
233
|
+
else if (projectOpts?.projectId) {
|
|
234
|
+
sessionId = projectOpts?.projectId;
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const project = await this.readProject({
|
|
238
|
+
projectName: getEnvironmentVariable("LANGCHAIN_PROJECT") || "default",
|
|
239
|
+
});
|
|
240
|
+
sessionId = project.id;
|
|
241
|
+
}
|
|
242
|
+
const tenantId = await this._getTenantId();
|
|
243
|
+
return `${this.getHostUrl()}/o/${tenantId}/projects/p/${sessionId}/r/${run.id}?poll=true`;
|
|
244
|
+
}
|
|
245
|
+
else if (runId !== undefined) {
|
|
246
|
+
const run_ = await this.readRun(runId);
|
|
247
|
+
if (!run_.app_path) {
|
|
248
|
+
throw new Error(`Run ${runId} has no app_path`);
|
|
249
|
+
}
|
|
250
|
+
const baseUrl = this.getHostUrl();
|
|
251
|
+
return `${baseUrl}${run_.app_path}`;
|
|
252
|
+
}
|
|
253
|
+
else {
|
|
254
|
+
throw new Error("Must provide either runId or run");
|
|
208
255
|
}
|
|
209
|
-
const baseUrl = this.getHostUrl();
|
|
210
|
-
return `${baseUrl}${run.app_path}`;
|
|
211
256
|
}
|
|
212
257
|
async _loadChildRuns(run) {
|
|
213
258
|
const childRuns = await toArray(this.listRuns({ id: run.child_run_ids }));
|
|
214
259
|
const treemap = {};
|
|
215
260
|
const runs = {};
|
|
216
|
-
|
|
261
|
+
// TODO: make dotted order required when the migration finishes
|
|
262
|
+
childRuns.sort((a, b) => (a?.dotted_order ?? "").localeCompare(b?.dotted_order ?? ""));
|
|
217
263
|
for (const childRun of childRuns) {
|
|
218
264
|
if (childRun.parent_run_id === null ||
|
|
219
265
|
childRun.parent_run_id === undefined) {
|
|
@@ -373,6 +419,17 @@ export class Client {
|
|
|
373
419
|
}
|
|
374
420
|
return result;
|
|
375
421
|
}
|
|
422
|
+
async _getTenantId() {
|
|
423
|
+
if (this._tenantId !== null) {
|
|
424
|
+
return this._tenantId;
|
|
425
|
+
}
|
|
426
|
+
const queryParams = new URLSearchParams({ limit: "1" });
|
|
427
|
+
for await (const projects of this._getPaginated("/sessions", queryParams)) {
|
|
428
|
+
this._tenantId = projects[0].tenant_id;
|
|
429
|
+
return projects[0].tenant_id;
|
|
430
|
+
}
|
|
431
|
+
throw new Error("No projects found to resolve tenant.");
|
|
432
|
+
}
|
|
376
433
|
async *listProjects({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, referenceFree, } = {}) {
|
|
377
434
|
const params = new URLSearchParams();
|
|
378
435
|
if (projectIds !== undefined) {
|
package/dist/schemas.d.ts
CHANGED
|
@@ -95,6 +95,21 @@ export interface Run extends BaseRun {
|
|
|
95
95
|
first_token_time?: number;
|
|
96
96
|
/** IDs of parent runs, if multiple exist. */
|
|
97
97
|
parent_run_ids?: string[];
|
|
98
|
+
/**Unique ID assigned to every run within this nested trace.**/
|
|
99
|
+
trace_id?: string;
|
|
100
|
+
/**
|
|
101
|
+
* The dotted order for the run.
|
|
102
|
+
*
|
|
103
|
+
* This is a string composed of {time}{run-uuid}.* so that a trace can be
|
|
104
|
+
* sorted in the order it was executed.
|
|
105
|
+
*
|
|
106
|
+
* Example:
|
|
107
|
+
* - Parent: 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8
|
|
108
|
+
* - Children:
|
|
109
|
+
* - 20230914T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155649Z809ed3a2-0172-4f4d-8a02-a64e9b7a0f8a
|
|
110
|
+
* - 20230915T223155647Z1b64098b-4ab7-43f6-afee-992304f198d8.20230914T223155650Zc8d9f4c5-6c5a-4b2d-9b1c-3d9d7a7c5c7c
|
|
111
|
+
*/
|
|
112
|
+
dotted_order?: string;
|
|
98
113
|
}
|
|
99
114
|
export interface RunCreate extends BaseRun {
|
|
100
115
|
child_runs?: this[];
|