langsmith 0.4.5 → 0.4.7

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,4 +1,3 @@
1
- import type { LanguageModelV2DataContent, LanguageModelV2Message } from "@ai-sdk/provider";
2
- import type { ModelMessage } from "ai";
1
+ import type { LanguageModelV2DataContent } from "@ai-sdk/provider";
3
2
  export declare const normalizeFileDataAsDataURL: (fileData: LanguageModelV2DataContent | ArrayBuffer, mimeType?: string) => string;
4
- export declare const convertMessageToTracedFormat: (message: LanguageModelV2Message | ModelMessage, responseMetadata?: Record<string, unknown>) => Record<string, unknown>;
3
+ export declare const convertMessageToTracedFormat: (message: Record<string, unknown>, responseMetadata?: Record<string, unknown>) => Record<string, unknown>;
package/dist/index.cjs CHANGED
@@ -15,4 +15,4 @@ Object.defineProperty(exports, "uuid7FromTime", { enumerable: true, get: functio
15
15
  var prompts_cache_js_1 = require("./utils/prompts_cache.cjs");
16
16
  Object.defineProperty(exports, "Cache", { enumerable: true, get: function () { return prompts_cache_js_1.Cache; } });
17
17
  // Update using yarn bump-version
18
- exports.__version__ = "0.4.5";
18
+ exports.__version__ = "0.4.7";
package/dist/index.d.ts CHANGED
@@ -5,4 +5,4 @@ export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
6
  export { uuid7, uuid7FromTime } from "./uuid.js";
7
7
  export { Cache, type CacheConfig, type CacheMetrics, } from "./utils/prompts_cache.js";
8
- export declare const __version__ = "0.4.5";
8
+ export declare const __version__ = "0.4.7";
package/dist/index.js CHANGED
@@ -5,4 +5,4 @@ export { getDefaultProjectName } from "./utils/project.js";
5
5
  export { uuid7, uuid7FromTime } from "./uuid.js";
6
6
  export { Cache, } from "./utils/prompts_cache.js";
7
7
  // Update using yarn bump-version
8
- export const __version__ = "0.4.5";
8
+ export const __version__ = "0.4.7";
@@ -44,6 +44,20 @@ function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
44
44
  microsecondPrecisionDatestring,
45
45
  };
46
46
  }
47
+ const HEADER_SAFE_REPLICA_FIELDS = new Set([
48
+ "projectName",
49
+ "updates",
50
+ "reroot",
51
+ ]);
52
+ function filterReplicaForHeaders(replica) {
53
+ const filtered = {};
54
+ for (const key of Object.keys(replica)) {
55
+ if (HEADER_SAFE_REPLICA_FIELDS.has(key)) {
56
+ filtered[key] = replica[key];
57
+ }
58
+ }
59
+ return filtered;
60
+ }
47
61
  /**
48
62
  * Baggage header information
49
63
  */
@@ -97,7 +111,13 @@ class Baggage {
97
111
  project_name = value;
98
112
  }
99
113
  else if (key === "langsmith-replicas") {
100
- replicas = JSON.parse(value);
114
+ const parsed = JSON.parse(value);
115
+ replicas = parsed.map((replica) => {
116
+ if (Array.isArray(replica)) {
117
+ return replica;
118
+ }
119
+ return filterReplicaForHeaders(replica);
120
+ });
101
121
  }
102
122
  }
103
123
  return new Baggage(metadata, tags, project_name, replicas);
package/dist/run_trees.js CHANGED
@@ -38,6 +38,20 @@ export function convertToDottedOrderFormat(epoch, runId, executionOrder = 1) {
38
38
  microsecondPrecisionDatestring,
39
39
  };
40
40
  }
41
+ const HEADER_SAFE_REPLICA_FIELDS = new Set([
42
+ "projectName",
43
+ "updates",
44
+ "reroot",
45
+ ]);
46
+ function filterReplicaForHeaders(replica) {
47
+ const filtered = {};
48
+ for (const key of Object.keys(replica)) {
49
+ if (HEADER_SAFE_REPLICA_FIELDS.has(key)) {
50
+ filtered[key] = replica[key];
51
+ }
52
+ }
53
+ return filtered;
54
+ }
41
55
  /**
42
56
  * Baggage header information
43
57
  */
@@ -91,7 +105,13 @@ class Baggage {
91
105
  project_name = value;
92
106
  }
93
107
  else if (key === "langsmith-replicas") {
94
- replicas = JSON.parse(value);
108
+ const parsed = JSON.parse(value);
109
+ replicas = parsed.map((replica) => {
110
+ if (Array.isArray(replica)) {
111
+ return replica;
112
+ }
113
+ return filterReplicaForHeaders(replica);
114
+ });
95
115
  }
96
116
  }
97
117
  return new Baggage(metadata, tags, project_name, replicas);
@@ -109,29 +109,38 @@ class AsyncCaller {
109
109
  throw new Error(error);
110
110
  }
111
111
  }), {
112
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
113
112
  async onFailedAttempt({ error }) {
114
- if (error.message.startsWith("Cancel") ||
115
- error.message.startsWith("TimeoutError") ||
116
- error.name === "TimeoutError" ||
117
- error.message.startsWith("AbortError")) {
113
+ // Rethrow the value if it's not an object
114
+ if (typeof error !== "object" || error == null)
115
+ throw error;
116
+ const errorMessage = "message" in error && typeof error.message === "string"
117
+ ? error.message
118
+ : undefined;
119
+ if (errorMessage?.startsWith("Cancel") ||
120
+ errorMessage?.startsWith("TimeoutError") ||
121
+ errorMessage?.startsWith("AbortError")) {
118
122
  throw error;
119
123
  }
120
- if (error?.code === "ECONNABORTED") {
124
+ if ("name" in error && error.name === "TimeoutError") {
121
125
  throw error;
122
126
  }
123
- const response = error?.response;
127
+ if ("code" in error && error.code === "ECONNABORTED") {
128
+ throw error;
129
+ }
130
+ const response = "response" in error
131
+ ? error.response
132
+ : undefined;
124
133
  if (onFailedResponseHook) {
125
134
  const handled = await onFailedResponseHook(response);
126
- if (handled) {
135
+ if (handled)
127
136
  return;
128
- }
129
137
  }
130
- const status = response?.status ?? error?.status;
131
- if (status) {
132
- if (!STATUS_RETRYABLE.includes(+status)) {
133
- throw error;
134
- }
138
+ const status = response?.status ??
139
+ ("status" in error ? error.status : undefined);
140
+ if (status != null &&
141
+ (typeof status === "number" || typeof status === "string") &&
142
+ !STATUS_RETRYABLE.includes(+status)) {
143
+ throw error;
135
144
  }
136
145
  },
137
146
  retries: this.maxRetries,
@@ -103,29 +103,38 @@ export class AsyncCaller {
103
103
  throw new Error(error);
104
104
  }
105
105
  }), {
106
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
107
106
  async onFailedAttempt({ error }) {
108
- if (error.message.startsWith("Cancel") ||
109
- error.message.startsWith("TimeoutError") ||
110
- error.name === "TimeoutError" ||
111
- error.message.startsWith("AbortError")) {
107
+ // Rethrow the value if it's not an object
108
+ if (typeof error !== "object" || error == null)
109
+ throw error;
110
+ const errorMessage = "message" in error && typeof error.message === "string"
111
+ ? error.message
112
+ : undefined;
113
+ if (errorMessage?.startsWith("Cancel") ||
114
+ errorMessage?.startsWith("TimeoutError") ||
115
+ errorMessage?.startsWith("AbortError")) {
112
116
  throw error;
113
117
  }
114
- if (error?.code === "ECONNABORTED") {
118
+ if ("name" in error && error.name === "TimeoutError") {
115
119
  throw error;
116
120
  }
117
- const response = error?.response;
121
+ if ("code" in error && error.code === "ECONNABORTED") {
122
+ throw error;
123
+ }
124
+ const response = "response" in error
125
+ ? error.response
126
+ : undefined;
118
127
  if (onFailedResponseHook) {
119
128
  const handled = await onFailedResponseHook(response);
120
- if (handled) {
129
+ if (handled)
121
130
  return;
122
- }
123
131
  }
124
- const status = response?.status ?? error?.status;
125
- if (status) {
126
- if (!STATUS_RETRYABLE.includes(+status)) {
127
- throw error;
128
- }
132
+ const status = response?.status ??
133
+ ("status" in error ? error.status : undefined);
134
+ if (status != null &&
135
+ (typeof status === "number" || typeof status === "string") &&
136
+ !STATUS_RETRYABLE.includes(+status)) {
137
+ throw error;
129
138
  }
130
139
  },
131
140
  retries: this.maxRetries,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.4.5",
3
+ "version": "0.4.7",
4
4
  "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [