langsmith 0.0.9 → 0.0.11

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 CHANGED
@@ -46,7 +46,7 @@ Tracing can be activated by setting the following environment variables or by ma
46
46
 
47
47
  ```typescript
48
48
  process.env["LANGCHAIN_TRACING_V2"] = "true";
49
- process.env["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com"; // or your own server
49
+ process.env["LANGCHAIN_ENDPOINT"] = "https://api.smith.langchain.com";
50
50
  process.env["LANGCHAIN_API_KEY"] = "<YOUR-LANGSMITH-API-KEY>";
51
51
  // process.env["LANGCHAIN_PROJECT"] = "My Project Name"; // Optional: "default" is used if not set
52
52
  ```
package/dist/client.cjs CHANGED
@@ -48,6 +48,15 @@ async function toArray(iterable) {
48
48
  }
49
49
  return result;
50
50
  }
51
+ function trimQuotes(str) {
52
+ if (str === undefined) {
53
+ return undefined;
54
+ }
55
+ return str
56
+ .trim()
57
+ .replace(/^"(.*)"$/, "$1")
58
+ .replace(/^'(.*)'$/, "$1");
59
+ }
51
60
  class Client {
52
61
  constructor(config = {}) {
53
62
  Object.defineProperty(this, "apiKey", {
@@ -75,8 +84,8 @@ class Client {
75
84
  value: void 0
76
85
  });
77
86
  const defaultConfig = Client.getDefaultClientConfig();
78
- this.apiUrl = config.apiUrl ?? defaultConfig.apiUrl;
79
- this.apiKey = config.apiKey ?? defaultConfig.apiKey;
87
+ this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
88
+ this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
80
89
  this.validateApiKeyIfHosted();
81
90
  this.timeout_ms = config.timeout_ms ?? 4000;
82
91
  this.caller = new async_caller_js_1.AsyncCaller(config.callerOptions ?? {});
@@ -96,6 +105,17 @@ class Client {
96
105
  throw new Error("API key must be provided when using hosted LangSmith API");
97
106
  }
98
107
  }
108
+ getHostUrl() {
109
+ if (isLocalhost(this.apiUrl)) {
110
+ return "http://localhost";
111
+ }
112
+ else if (this.apiUrl.split(".", 1)[0].includes("dev")) {
113
+ return "https://dev.smith.langchain.com";
114
+ }
115
+ else {
116
+ return "https://smith.langchain.com";
117
+ }
118
+ }
99
119
  get headers() {
100
120
  const headers = {};
101
121
  if (this.apiKey) {
@@ -184,6 +204,14 @@ class Client {
184
204
  }
185
205
  return run;
186
206
  }
207
+ async getRunUrl({ runId, }) {
208
+ const run = await this.readRun(runId);
209
+ if (!run.app_path) {
210
+ return undefined;
211
+ }
212
+ const baseUrl = this.getHostUrl();
213
+ return `${baseUrl}${run.app_path}`;
214
+ }
187
215
  async _loadChildRuns(run) {
188
216
  const childRuns = await toArray(this.listRuns({ id: run.child_run_ids }));
189
217
  const treemap = {};
package/dist/client.d.ts CHANGED
@@ -62,6 +62,7 @@ export declare class Client {
62
62
  apiKey?: string;
63
63
  };
64
64
  private validateApiKeyIfHosted;
65
+ private getHostUrl;
65
66
  private get headers();
66
67
  private _get;
67
68
  private _getPaginated;
@@ -70,6 +71,9 @@ export declare class Client {
70
71
  readRun(runId: string, { loadChildRuns }?: {
71
72
  loadChildRuns: boolean;
72
73
  }): Promise<Run>;
74
+ getRunUrl({ runId, }: {
75
+ runId: string;
76
+ }): Promise<string | undefined>;
73
77
  private _loadChildRuns;
74
78
  listRuns({ projectId, projectName, parentRunId, referenceExampleId, datasetId, startTime, endTime, executionOrder, runType, error, id, limit, offset, query, filter, orderBy, }: ListRunsParams): AsyncIterable<Run>;
75
79
  deleteRun(runId: string): Promise<void>;
package/dist/client.js CHANGED
@@ -22,6 +22,15 @@ async function toArray(iterable) {
22
22
  }
23
23
  return result;
24
24
  }
25
+ function trimQuotes(str) {
26
+ if (str === undefined) {
27
+ return undefined;
28
+ }
29
+ return str
30
+ .trim()
31
+ .replace(/^"(.*)"$/, "$1")
32
+ .replace(/^'(.*)'$/, "$1");
33
+ }
25
34
  export class Client {
26
35
  constructor(config = {}) {
27
36
  Object.defineProperty(this, "apiKey", {
@@ -49,8 +58,8 @@ export class Client {
49
58
  value: void 0
50
59
  });
51
60
  const defaultConfig = Client.getDefaultClientConfig();
52
- this.apiUrl = config.apiUrl ?? defaultConfig.apiUrl;
53
- this.apiKey = config.apiKey ?? defaultConfig.apiKey;
61
+ this.apiUrl = trimQuotes(config.apiUrl ?? defaultConfig.apiUrl) ?? "";
62
+ this.apiKey = trimQuotes(config.apiKey ?? defaultConfig.apiKey);
54
63
  this.validateApiKeyIfHosted();
55
64
  this.timeout_ms = config.timeout_ms ?? 4000;
56
65
  this.caller = new AsyncCaller(config.callerOptions ?? {});
@@ -70,6 +79,17 @@ export class Client {
70
79
  throw new Error("API key must be provided when using hosted LangSmith API");
71
80
  }
72
81
  }
82
+ getHostUrl() {
83
+ if (isLocalhost(this.apiUrl)) {
84
+ return "http://localhost";
85
+ }
86
+ else if (this.apiUrl.split(".", 1)[0].includes("dev")) {
87
+ return "https://dev.smith.langchain.com";
88
+ }
89
+ else {
90
+ return "https://smith.langchain.com";
91
+ }
92
+ }
73
93
  get headers() {
74
94
  const headers = {};
75
95
  if (this.apiKey) {
@@ -158,6 +178,14 @@ export class Client {
158
178
  }
159
179
  return run;
160
180
  }
181
+ async getRunUrl({ runId, }) {
182
+ const run = await this.readRun(runId);
183
+ if (!run.app_path) {
184
+ return undefined;
185
+ }
186
+ const baseUrl = this.getHostUrl();
187
+ return `${baseUrl}${run.app_path}`;
188
+ }
161
189
  async _loadChildRuns(run) {
162
190
  const childRuns = await toArray(this.listRuns({ id: run.child_run_ids }));
163
191
  const treemap = {};
package/dist/schemas.d.ts CHANGED
@@ -51,6 +51,7 @@ export interface Run extends BaseRun {
51
51
  child_run_ids?: string[];
52
52
  feedback_stats?: KVMap;
53
53
  child_runs?: Run[];
54
+ app_path?: string;
54
55
  }
55
56
  export interface RunCreate extends BaseRun {
56
57
  child_runs?: this[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.0.9",
3
+ "version": "0.0.11",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "files": [
6
6
  "dist/",