langsmith 0.0.39 → 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 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 (isLocalhost(this.apiUrl)) {
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,13 +247,38 @@ class Client {
227
247
  }
228
248
  return run;
229
249
  }
230
- async getRunUrl({ runId, }) {
231
- const run = await this.readRun(runId);
232
- if (!run.app_path) {
233
- return undefined;
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 }));
@@ -400,6 +445,17 @@ class Client {
400
445
  }
401
446
  return result;
402
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
+ }
403
459
  async *listProjects({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, referenceFree, } = {}) {
404
460
  const params = new URLSearchParams();
405
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: string;
80
- }): Promise<string | undefined>;
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 (isLocalhost(this.apiUrl)) {
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,13 +221,38 @@ export class Client {
201
221
  }
202
222
  return run;
203
223
  }
204
- async getRunUrl({ runId, }) {
205
- const run = await this.readRun(runId);
206
- if (!run.app_path) {
207
- return undefined;
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 }));
@@ -374,6 +419,17 @@ export class Client {
374
419
  }
375
420
  return result;
376
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
+ }
377
433
  async *listProjects({ projectIds, name, nameContains, referenceDatasetId, referenceDatasetName, referenceFree, } = {}) {
378
434
  const params = new URLSearchParams();
379
435
  if (projectIds !== undefined) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.0.39",
3
+ "version": "0.0.40",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "files": [
6
6
  "dist/",