langsmith 0.1.43 → 0.1.44

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.
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.printErrorStackTrace = void 0;
3
+ exports.raiseForStatus = exports.LangSmithConflictError = exports.printErrorStackTrace = void 0;
4
4
  function getErrorStackTrace(e) {
5
5
  if (typeof e !== "object" || e == null)
6
6
  return undefined;
@@ -23,3 +23,67 @@ function printErrorStackTrace(e) {
23
23
  console.error(stack);
24
24
  }
25
25
  exports.printErrorStackTrace = printErrorStackTrace;
26
+ /**
27
+ * LangSmithConflictError
28
+ *
29
+ * Represents an error that occurs when there's a conflict during an operation,
30
+ * typically corresponding to HTTP 409 status code responses.
31
+ *
32
+ * This error is thrown when an attempt to create or modify a resource conflicts
33
+ * with the current state of the resource on the server. Common scenarios include:
34
+ * - Attempting to create a resource that already exists
35
+ * - Trying to update a resource that has been modified by another process
36
+ * - Violating a uniqueness constraint in the data
37
+ *
38
+ * @extends Error
39
+ *
40
+ * @example
41
+ * try {
42
+ * await createProject("existingProject");
43
+ * } catch (error) {
44
+ * if (error instanceof ConflictError) {
45
+ * console.log("A conflict occurred:", error.message);
46
+ * // Handle the conflict, e.g., by suggesting a different project name
47
+ * } else {
48
+ * // Handle other types of errors
49
+ * }
50
+ * }
51
+ *
52
+ * @property {string} name - Always set to 'ConflictError' for easy identification
53
+ * @property {string} message - Detailed error message including server response
54
+ *
55
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409
56
+ */
57
+ class LangSmithConflictError extends Error {
58
+ constructor(message) {
59
+ super(message);
60
+ this.name = "LangSmithConflictError";
61
+ }
62
+ }
63
+ exports.LangSmithConflictError = LangSmithConflictError;
64
+ /**
65
+ * Throws an appropriate error based on the response status and body.
66
+ *
67
+ * @param response - The fetch Response object
68
+ * @param context - Additional context to include in the error message (e.g., operation being performed)
69
+ * @throws {LangSmithConflictError} When the response status is 409
70
+ * @throws {Error} For all other non-ok responses
71
+ */
72
+ async function raiseForStatus(response, context, consume) {
73
+ // consume the response body to release the connection
74
+ // https://undici.nodejs.org/#/?id=garbage-collection
75
+ let errorBody;
76
+ if (response.ok) {
77
+ if (consume) {
78
+ errorBody = await response.text();
79
+ }
80
+ return;
81
+ }
82
+ errorBody = await response.text();
83
+ const fullMessage = `Failed to ${context}. Received status [${response.status}]: ${response.statusText}. Server response: ${errorBody}`;
84
+ if (response.status === 409) {
85
+ throw new LangSmithConflictError(fullMessage);
86
+ }
87
+ throw new Error(fullMessage);
88
+ }
89
+ exports.raiseForStatus = raiseForStatus;
@@ -1 +1,44 @@
1
1
  export declare function printErrorStackTrace(e: unknown): void;
2
+ /**
3
+ * LangSmithConflictError
4
+ *
5
+ * Represents an error that occurs when there's a conflict during an operation,
6
+ * typically corresponding to HTTP 409 status code responses.
7
+ *
8
+ * This error is thrown when an attempt to create or modify a resource conflicts
9
+ * with the current state of the resource on the server. Common scenarios include:
10
+ * - Attempting to create a resource that already exists
11
+ * - Trying to update a resource that has been modified by another process
12
+ * - Violating a uniqueness constraint in the data
13
+ *
14
+ * @extends Error
15
+ *
16
+ * @example
17
+ * try {
18
+ * await createProject("existingProject");
19
+ * } catch (error) {
20
+ * if (error instanceof ConflictError) {
21
+ * console.log("A conflict occurred:", error.message);
22
+ * // Handle the conflict, e.g., by suggesting a different project name
23
+ * } else {
24
+ * // Handle other types of errors
25
+ * }
26
+ * }
27
+ *
28
+ * @property {string} name - Always set to 'ConflictError' for easy identification
29
+ * @property {string} message - Detailed error message including server response
30
+ *
31
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409
32
+ */
33
+ export declare class LangSmithConflictError extends Error {
34
+ constructor(message: string);
35
+ }
36
+ /**
37
+ * Throws an appropriate error based on the response status and body.
38
+ *
39
+ * @param response - The fetch Response object
40
+ * @param context - Additional context to include in the error message (e.g., operation being performed)
41
+ * @throws {LangSmithConflictError} When the response status is 409
42
+ * @throws {Error} For all other non-ok responses
43
+ */
44
+ export declare function raiseForStatus(response: Response, context: string, consume?: boolean): Promise<void>;
@@ -19,3 +19,65 @@ export function printErrorStackTrace(e) {
19
19
  return;
20
20
  console.error(stack);
21
21
  }
22
+ /**
23
+ * LangSmithConflictError
24
+ *
25
+ * Represents an error that occurs when there's a conflict during an operation,
26
+ * typically corresponding to HTTP 409 status code responses.
27
+ *
28
+ * This error is thrown when an attempt to create or modify a resource conflicts
29
+ * with the current state of the resource on the server. Common scenarios include:
30
+ * - Attempting to create a resource that already exists
31
+ * - Trying to update a resource that has been modified by another process
32
+ * - Violating a uniqueness constraint in the data
33
+ *
34
+ * @extends Error
35
+ *
36
+ * @example
37
+ * try {
38
+ * await createProject("existingProject");
39
+ * } catch (error) {
40
+ * if (error instanceof ConflictError) {
41
+ * console.log("A conflict occurred:", error.message);
42
+ * // Handle the conflict, e.g., by suggesting a different project name
43
+ * } else {
44
+ * // Handle other types of errors
45
+ * }
46
+ * }
47
+ *
48
+ * @property {string} name - Always set to 'ConflictError' for easy identification
49
+ * @property {string} message - Detailed error message including server response
50
+ *
51
+ * @see https://developer.mozilla.org/en-US/docs/Web/HTTP/Status/409
52
+ */
53
+ export class LangSmithConflictError extends Error {
54
+ constructor(message) {
55
+ super(message);
56
+ this.name = "LangSmithConflictError";
57
+ }
58
+ }
59
+ /**
60
+ * Throws an appropriate error based on the response status and body.
61
+ *
62
+ * @param response - The fetch Response object
63
+ * @param context - Additional context to include in the error message (e.g., operation being performed)
64
+ * @throws {LangSmithConflictError} When the response status is 409
65
+ * @throws {Error} For all other non-ok responses
66
+ */
67
+ export async function raiseForStatus(response, context, consume) {
68
+ // consume the response body to release the connection
69
+ // https://undici.nodejs.org/#/?id=garbage-collection
70
+ let errorBody;
71
+ if (response.ok) {
72
+ if (consume) {
73
+ errorBody = await response.text();
74
+ }
75
+ return;
76
+ }
77
+ errorBody = await response.text();
78
+ const fullMessage = `Failed to ${context}. Received status [${response.status}]: ${response.statusText}. Server response: ${errorBody}`;
79
+ if (response.status === 409) {
80
+ throw new LangSmithConflictError(fullMessage);
81
+ }
82
+ throw new Error(fullMessage);
83
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.1.43",
3
+ "version": "0.1.44",
4
4
  "description": "Client library to connect to the LangSmith LLM Tracing and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [