langsmith 0.5.5 → 0.5.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.
@@ -254,8 +254,19 @@ function LangSmithMiddleware(config) {
254
254
  role: "assistant",
255
255
  tool_calls: [],
256
256
  });
257
- const outputFormatter = lsConfig?.processOutputs ?? utils_js_1.convertMessageToTracedFormat;
258
- const formattedOutputs = await outputFormatter(output);
257
+ // Add raw request/response for tracing only (not part of aggregated output)
258
+ const outputForTracing = {
259
+ ...output,
260
+ request: rest.request,
261
+ response: rest.response,
262
+ };
263
+ let formattedOutputs;
264
+ if (lsConfig?.processOutputs) {
265
+ formattedOutputs = await lsConfig.processOutputs(outputForTracing);
266
+ }
267
+ else {
268
+ formattedOutputs = _formatTracedOutputs(outputForTracing, lsConfig?.traceRawHttp);
269
+ }
259
270
  await runTree?.end(formattedOutputs);
260
271
  }
261
272
  catch (error) {
@@ -251,8 +251,19 @@ export function LangSmithMiddleware(config) {
251
251
  role: "assistant",
252
252
  tool_calls: [],
253
253
  });
254
- const outputFormatter = lsConfig?.processOutputs ?? convertMessageToTracedFormat;
255
- const formattedOutputs = await outputFormatter(output);
254
+ // Add raw request/response for tracing only (not part of aggregated output)
255
+ const outputForTracing = {
256
+ ...output,
257
+ request: rest.request,
258
+ response: rest.response,
259
+ };
260
+ let formattedOutputs;
261
+ if (lsConfig?.processOutputs) {
262
+ formattedOutputs = await lsConfig.processOutputs(outputForTracing);
263
+ }
264
+ else {
265
+ formattedOutputs = _formatTracedOutputs(outputForTracing, lsConfig?.traceRawHttp);
266
+ }
256
267
  await runTree?.end(formattedOutputs);
257
268
  }
258
269
  catch (error) {
package/dist/index.cjs CHANGED
@@ -18,4 +18,4 @@ Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function
18
18
  Object.defineProperty(exports, "configureGlobalPromptCache", { enumerable: true, get: function () { return index_js_1.configureGlobalPromptCache; } });
19
19
  Object.defineProperty(exports, "promptCacheSingleton", { enumerable: true, get: function () { return index_js_1.promptCacheSingleton; } });
20
20
  // Update using yarn bump-version
21
- exports.__version__ = "0.5.5";
21
+ exports.__version__ = "0.5.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, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
8
- export declare const __version__ = "0.5.5";
8
+ export declare const __version__ = "0.5.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, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
7
7
  // Update using yarn bump-version
8
- export const __version__ = "0.5.5";
8
+ export const __version__ = "0.5.7";
@@ -1,10 +1,26 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConflictingEndpointsError = exports.LangSmithNotFoundError = exports.LangSmithConflictError = void 0;
4
+ exports.getInvalidPromptIdentifierMsg = getInvalidPromptIdentifierMsg;
4
5
  exports.printErrorStackTrace = printErrorStackTrace;
5
6
  exports.isLangSmithNotFoundError = isLangSmithNotFoundError;
6
7
  exports.raiseForStatus = raiseForStatus;
7
8
  exports.isConflictingEndpointsError = isConflictingEndpointsError;
9
+ /**
10
+ * Get the error message for an invalid prompt identifier.
11
+ * Used consistently across the codebase when parsing prompt identifiers fails.
12
+ *
13
+ * @param identifier - The invalid identifier that was provided
14
+ * @returns A formatted error message explaining the valid formats
15
+ */
16
+ function getInvalidPromptIdentifierMsg(identifier) {
17
+ return (`Invalid prompt identifier format: "${identifier}". ` +
18
+ `Expected one of:\n` +
19
+ ` - "prompt-name" (for private prompts)\n` +
20
+ ` - "owner/prompt-name" (for prompts with explicit owner)\n` +
21
+ ` - "prompt-name:commit-hash" (with commit reference)\n` +
22
+ ` - "owner/prompt-name:commit-hash" (with owner and commit)`);
23
+ }
8
24
  function getErrorStackTrace(e) {
9
25
  if (typeof e !== "object" || e == null)
10
26
  return undefined;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * Get the error message for an invalid prompt identifier.
3
+ * Used consistently across the codebase when parsing prompt identifiers fails.
4
+ *
5
+ * @param identifier - The invalid identifier that was provided
6
+ * @returns A formatted error message explaining the valid formats
7
+ */
8
+ export declare function getInvalidPromptIdentifierMsg(identifier: string): string;
1
9
  export declare function printErrorStackTrace(e: unknown): void;
2
10
  /**
3
11
  * LangSmithConflictError
@@ -1,3 +1,18 @@
1
+ /**
2
+ * Get the error message for an invalid prompt identifier.
3
+ * Used consistently across the codebase when parsing prompt identifiers fails.
4
+ *
5
+ * @param identifier - The invalid identifier that was provided
6
+ * @returns A formatted error message explaining the valid formats
7
+ */
8
+ export function getInvalidPromptIdentifierMsg(identifier) {
9
+ return (`Invalid prompt identifier format: "${identifier}". ` +
10
+ `Expected one of:\n` +
11
+ ` - "prompt-name" (for private prompts)\n` +
12
+ ` - "owner/prompt-name" (for prompts with explicit owner)\n` +
13
+ ` - "prompt-name:commit-hash" (with commit reference)\n` +
14
+ ` - "owner/prompt-name:commit-hash" (with owner and commit)`);
15
+ }
1
16
  function getErrorStackTrace(e) {
2
17
  if (typeof e !== "object" || e == null)
3
18
  return undefined;
@@ -0,0 +1,51 @@
1
+ "use strict";
2
+ /**
3
+ * File system abstraction (browser stub).
4
+ *
5
+ * This stub is used in browser/bundler builds via the package.json browser
6
+ * field. Async operations are no-ops; sync operations are no-ops that return
7
+ * safe defaults. Higher-level consumers (e.g. prompt_cache/fs.browser.ts) may
8
+ * still throw on their own if browser use is unsupported at that layer.
9
+ */
10
+ Object.defineProperty(exports, "__esModule", { value: true });
11
+ exports.path = void 0;
12
+ exports.mkdir = mkdir;
13
+ exports.writeFileAtomic = writeFileAtomic;
14
+ exports.readdir = readdir;
15
+ exports.stat = stat;
16
+ exports.unlink = unlink;
17
+ exports.existsSync = existsSync;
18
+ exports.mkdirSync = mkdirSync;
19
+ exports.writeFileSync = writeFileSync;
20
+ exports.renameSync = renameSync;
21
+ exports.unlinkSync = unlinkSync;
22
+ exports.readFileSync = readFileSync;
23
+ exports.path = {
24
+ join: (...parts) => parts.join("/"),
25
+ dirname: (p) => p.split("/").slice(0, -1).join("/"),
26
+ };
27
+ // ---------------------------------------------------------------------------
28
+ // Async operations – no-op in browser
29
+ // ---------------------------------------------------------------------------
30
+ async function mkdir(_dir) { }
31
+ async function writeFileAtomic(_filePath, _content) { }
32
+ async function readdir(_dir) {
33
+ return [];
34
+ }
35
+ async function stat(_filePath) {
36
+ return { size: 0 };
37
+ }
38
+ async function unlink(_filePath) { }
39
+ // ---------------------------------------------------------------------------
40
+ // Sync operations – no-op / safe defaults in browser
41
+ // ---------------------------------------------------------------------------
42
+ function existsSync(_p) {
43
+ return false;
44
+ }
45
+ function mkdirSync(_dir) { }
46
+ function writeFileSync(_filePath, _content) { }
47
+ function renameSync(_oldPath, _newPath) { }
48
+ function unlinkSync(_filePath) { }
49
+ function readFileSync(_filePath) {
50
+ return "";
51
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * File system abstraction (browser stub).
3
+ *
4
+ * This stub is used in browser/bundler builds via the package.json browser
5
+ * field. Async operations are no-ops; sync operations are no-ops that return
6
+ * safe defaults. Higher-level consumers (e.g. prompt_cache/fs.browser.ts) may
7
+ * still throw on their own if browser use is unsupported at that layer.
8
+ */
9
+ export declare const path: {
10
+ join: (...parts: string[]) => string;
11
+ dirname: (p: string) => string;
12
+ };
13
+ export declare function mkdir(_dir: string): Promise<void>;
14
+ export declare function writeFileAtomic(_filePath: string, _content: string): Promise<void>;
15
+ export declare function readdir(_dir: string): Promise<string[]>;
16
+ export declare function stat(_filePath: string): Promise<{
17
+ size: number;
18
+ }>;
19
+ export declare function unlink(_filePath: string): Promise<void>;
20
+ export declare function existsSync(_p: string): boolean;
21
+ export declare function mkdirSync(_dir: string): void;
22
+ export declare function writeFileSync(_filePath: string, _content: string): void;
23
+ export declare function renameSync(_oldPath: string, _newPath: string): void;
24
+ export declare function unlinkSync(_filePath: string): void;
25
+ export declare function readFileSync(_filePath: string): string;
@@ -0,0 +1,37 @@
1
+ /**
2
+ * File system abstraction (browser stub).
3
+ *
4
+ * This stub is used in browser/bundler builds via the package.json browser
5
+ * field. Async operations are no-ops; sync operations are no-ops that return
6
+ * safe defaults. Higher-level consumers (e.g. prompt_cache/fs.browser.ts) may
7
+ * still throw on their own if browser use is unsupported at that layer.
8
+ */
9
+ export const path = {
10
+ join: (...parts) => parts.join("/"),
11
+ dirname: (p) => p.split("/").slice(0, -1).join("/"),
12
+ };
13
+ // ---------------------------------------------------------------------------
14
+ // Async operations – no-op in browser
15
+ // ---------------------------------------------------------------------------
16
+ export async function mkdir(_dir) { }
17
+ export async function writeFileAtomic(_filePath, _content) { }
18
+ export async function readdir(_dir) {
19
+ return [];
20
+ }
21
+ export async function stat(_filePath) {
22
+ return { size: 0 };
23
+ }
24
+ export async function unlink(_filePath) { }
25
+ // ---------------------------------------------------------------------------
26
+ // Sync operations – no-op / safe defaults in browser
27
+ // ---------------------------------------------------------------------------
28
+ export function existsSync(_p) {
29
+ return false;
30
+ }
31
+ export function mkdirSync(_dir) { }
32
+ export function writeFileSync(_filePath, _content) { }
33
+ export function renameSync(_oldPath, _newPath) { }
34
+ export function unlinkSync(_filePath) { }
35
+ export function readFileSync(_filePath) {
36
+ return "";
37
+ }
@@ -0,0 +1,101 @@
1
+ "use strict";
2
+ /**
3
+ * File system abstraction (Node.js version).
4
+ *
5
+ * This file is swapped with fs.browser.ts for browser builds
6
+ * via the package.json browser field.
7
+ */
8
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
9
+ if (k2 === undefined) k2 = k;
10
+ var desc = Object.getOwnPropertyDescriptor(m, k);
11
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
12
+ desc = { enumerable: true, get: function() { return m[k]; } };
13
+ }
14
+ Object.defineProperty(o, k2, desc);
15
+ }) : (function(o, m, k, k2) {
16
+ if (k2 === undefined) k2 = k;
17
+ o[k2] = m[k];
18
+ }));
19
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
20
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
21
+ }) : function(o, v) {
22
+ o["default"] = v;
23
+ });
24
+ var __importStar = (this && this.__importStar) || (function () {
25
+ var ownKeys = function(o) {
26
+ ownKeys = Object.getOwnPropertyNames || function (o) {
27
+ var ar = [];
28
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
29
+ return ar;
30
+ };
31
+ return ownKeys(o);
32
+ };
33
+ return function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ })();
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.path = void 0;
43
+ exports.mkdir = mkdir;
44
+ exports.writeFileAtomic = writeFileAtomic;
45
+ exports.readdir = readdir;
46
+ exports.stat = stat;
47
+ exports.unlink = unlink;
48
+ exports.existsSync = existsSync;
49
+ exports.mkdirSync = mkdirSync;
50
+ exports.writeFileSync = writeFileSync;
51
+ exports.renameSync = renameSync;
52
+ exports.unlinkSync = unlinkSync;
53
+ exports.readFileSync = readFileSync;
54
+ const nodeFs = __importStar(require("node:fs"));
55
+ const nodeFsPromises = __importStar(require("node:fs/promises"));
56
+ const nodePath = __importStar(require("node:path"));
57
+ exports.path = nodePath;
58
+ // ---------------------------------------------------------------------------
59
+ // Async operations (used by trace dump fallback)
60
+ // ---------------------------------------------------------------------------
61
+ async function mkdir(dir) {
62
+ await nodeFsPromises.mkdir(dir, { recursive: true });
63
+ }
64
+ async function writeFileAtomic(filePath, content) {
65
+ const tempPath = `${filePath}.tmp`;
66
+ await nodeFsPromises.writeFile(tempPath, content, {
67
+ encoding: "utf8",
68
+ mode: 0o600,
69
+ });
70
+ await nodeFsPromises.rename(tempPath, filePath);
71
+ }
72
+ async function readdir(dir) {
73
+ return nodeFsPromises.readdir(dir);
74
+ }
75
+ async function stat(filePath) {
76
+ return nodeFsPromises.stat(filePath);
77
+ }
78
+ async function unlink(filePath) {
79
+ await nodeFsPromises.unlink(filePath);
80
+ }
81
+ // ---------------------------------------------------------------------------
82
+ // Sync operations (used by prompt cache)
83
+ // ---------------------------------------------------------------------------
84
+ function existsSync(p) {
85
+ return nodeFs.existsSync(p);
86
+ }
87
+ function mkdirSync(dir) {
88
+ nodeFs.mkdirSync(dir, { recursive: true });
89
+ }
90
+ function writeFileSync(filePath, content) {
91
+ nodeFs.writeFileSync(filePath, content);
92
+ }
93
+ function renameSync(oldPath, newPath) {
94
+ nodeFs.renameSync(oldPath, newPath);
95
+ }
96
+ function unlinkSync(filePath) {
97
+ nodeFs.unlinkSync(filePath);
98
+ }
99
+ function readFileSync(filePath) {
100
+ return nodeFs.readFileSync(filePath, "utf-8");
101
+ }
@@ -0,0 +1,21 @@
1
+ /**
2
+ * File system abstraction (Node.js version).
3
+ *
4
+ * This file is swapped with fs.browser.ts for browser builds
5
+ * via the package.json browser field.
6
+ */
7
+ import * as nodePath from "node:path";
8
+ export declare const path: nodePath.PlatformPath;
9
+ export declare function mkdir(dir: string): Promise<void>;
10
+ export declare function writeFileAtomic(filePath: string, content: string): Promise<void>;
11
+ export declare function readdir(dir: string): Promise<string[]>;
12
+ export declare function stat(filePath: string): Promise<{
13
+ size: number;
14
+ }>;
15
+ export declare function unlink(filePath: string): Promise<void>;
16
+ export declare function existsSync(p: string): boolean;
17
+ export declare function mkdirSync(dir: string): void;
18
+ export declare function writeFileSync(filePath: string, content: string): void;
19
+ export declare function renameSync(oldPath: string, newPath: string): void;
20
+ export declare function unlinkSync(filePath: string): void;
21
+ export declare function readFileSync(filePath: string): string;
@@ -0,0 +1,54 @@
1
+ /**
2
+ * File system abstraction (Node.js version).
3
+ *
4
+ * This file is swapped with fs.browser.ts for browser builds
5
+ * via the package.json browser field.
6
+ */
7
+ import * as nodeFs from "node:fs";
8
+ import * as nodeFsPromises from "node:fs/promises";
9
+ import * as nodePath from "node:path";
10
+ export const path = nodePath;
11
+ // ---------------------------------------------------------------------------
12
+ // Async operations (used by trace dump fallback)
13
+ // ---------------------------------------------------------------------------
14
+ export async function mkdir(dir) {
15
+ await nodeFsPromises.mkdir(dir, { recursive: true });
16
+ }
17
+ export async function writeFileAtomic(filePath, content) {
18
+ const tempPath = `${filePath}.tmp`;
19
+ await nodeFsPromises.writeFile(tempPath, content, {
20
+ encoding: "utf8",
21
+ mode: 0o600,
22
+ });
23
+ await nodeFsPromises.rename(tempPath, filePath);
24
+ }
25
+ export async function readdir(dir) {
26
+ return nodeFsPromises.readdir(dir);
27
+ }
28
+ export async function stat(filePath) {
29
+ return nodeFsPromises.stat(filePath);
30
+ }
31
+ export async function unlink(filePath) {
32
+ await nodeFsPromises.unlink(filePath);
33
+ }
34
+ // ---------------------------------------------------------------------------
35
+ // Sync operations (used by prompt cache)
36
+ // ---------------------------------------------------------------------------
37
+ export function existsSync(p) {
38
+ return nodeFs.existsSync(p);
39
+ }
40
+ export function mkdirSync(dir) {
41
+ nodeFs.mkdirSync(dir, { recursive: true });
42
+ }
43
+ export function writeFileSync(filePath, content) {
44
+ nodeFs.writeFileSync(filePath, content);
45
+ }
46
+ export function renameSync(oldPath, newPath) {
47
+ nodeFs.renameSync(oldPath, newPath);
48
+ }
49
+ export function unlinkSync(filePath) {
50
+ nodeFs.unlinkSync(filePath);
51
+ }
52
+ export function readFileSync(filePath) {
53
+ return nodeFs.readFileSync(filePath, "utf-8");
54
+ }
@@ -5,13 +5,14 @@
5
5
  * Provides an LRU cache with background refresh for prompt caching.
6
6
  * Uses stale-while-revalidate pattern for optimal performance.
7
7
  *
8
- * Works in all environments. File operations (dump/load) use helpers
9
- * that are swapped for browser builds via package.json browser field.
8
+ * Works in all environments. File operations (dump/load) use the shared
9
+ * fs abstraction which is swapped for browser builds via package.json
10
+ * browser field (no-ops in browser — cache just doesn't persist).
10
11
  */
11
12
  Object.defineProperty(exports, "__esModule", { value: true });
12
13
  exports.Cache = exports.promptCacheSingleton = exports.PromptCache = void 0;
13
14
  exports.configureGlobalPromptCache = configureGlobalPromptCache;
14
- const fs_js_1 = require("./fs.cjs");
15
+ const fs_js_1 = require("../fs.cjs");
15
16
  /**
16
17
  * Check if a cache entry is stale based on TTL.
17
18
  */
@@ -208,7 +209,21 @@ class PromptCache {
208
209
  for (const [key, entry] of this.cache.entries()) {
209
210
  entries[key] = entry.value;
210
211
  }
211
- (0, fs_js_1.dumpCache)(filePath, entries);
212
+ const dir = fs_js_1.path.dirname(filePath);
213
+ if (!(0, fs_js_1.existsSync)(dir)) {
214
+ (0, fs_js_1.mkdirSync)(dir);
215
+ }
216
+ const tempPath = `${filePath}.tmp`;
217
+ try {
218
+ (0, fs_js_1.writeFileSync)(tempPath, JSON.stringify({ entries }, null, 2));
219
+ (0, fs_js_1.renameSync)(tempPath, filePath);
220
+ }
221
+ catch (e) {
222
+ if ((0, fs_js_1.existsSync)(tempPath)) {
223
+ (0, fs_js_1.unlinkSync)(tempPath);
224
+ }
225
+ throw e;
226
+ }
212
227
  }
213
228
  /**
214
229
  * Load cache contents from a JSON file.
@@ -218,7 +233,18 @@ class PromptCache {
218
233
  * @returns Number of entries loaded.
219
234
  */
220
235
  load(filePath) {
221
- const entries = (0, fs_js_1.loadCache)(filePath);
236
+ if (!(0, fs_js_1.existsSync)(filePath)) {
237
+ return 0;
238
+ }
239
+ let entries;
240
+ try {
241
+ const content = (0, fs_js_1.readFileSync)(filePath);
242
+ const data = JSON.parse(content);
243
+ entries = data.entries ?? null;
244
+ }
245
+ catch {
246
+ return 0;
247
+ }
222
248
  if (!entries) {
223
249
  return 0;
224
250
  }
@@ -4,8 +4,9 @@
4
4
  * Provides an LRU cache with background refresh for prompt caching.
5
5
  * Uses stale-while-revalidate pattern for optimal performance.
6
6
  *
7
- * Works in all environments. File operations (dump/load) use helpers
8
- * that are swapped for browser builds via package.json browser field.
7
+ * Works in all environments. File operations (dump/load) use the shared
8
+ * fs abstraction which is swapped for browser builds via package.json
9
+ * browser field (no-ops in browser — cache just doesn't persist).
9
10
  */
10
11
  import type { PromptCommit } from "../../schemas.js";
11
12
  /**
@@ -4,10 +4,11 @@
4
4
  * Provides an LRU cache with background refresh for prompt caching.
5
5
  * Uses stale-while-revalidate pattern for optimal performance.
6
6
  *
7
- * Works in all environments. File operations (dump/load) use helpers
8
- * that are swapped for browser builds via package.json browser field.
7
+ * Works in all environments. File operations (dump/load) use the shared
8
+ * fs abstraction which is swapped for browser builds via package.json
9
+ * browser field (no-ops in browser — cache just doesn't persist).
9
10
  */
10
- import { dumpCache, loadCache } from "./fs.js";
11
+ import { path, existsSync, mkdirSync, writeFileSync, renameSync, unlinkSync, readFileSync, } from "../fs.js";
11
12
  /**
12
13
  * Check if a cache entry is stale based on TTL.
13
14
  */
@@ -204,7 +205,21 @@ export class PromptCache {
204
205
  for (const [key, entry] of this.cache.entries()) {
205
206
  entries[key] = entry.value;
206
207
  }
207
- dumpCache(filePath, entries);
208
+ const dir = path.dirname(filePath);
209
+ if (!existsSync(dir)) {
210
+ mkdirSync(dir);
211
+ }
212
+ const tempPath = `${filePath}.tmp`;
213
+ try {
214
+ writeFileSync(tempPath, JSON.stringify({ entries }, null, 2));
215
+ renameSync(tempPath, filePath);
216
+ }
217
+ catch (e) {
218
+ if (existsSync(tempPath)) {
219
+ unlinkSync(tempPath);
220
+ }
221
+ throw e;
222
+ }
208
223
  }
209
224
  /**
210
225
  * Load cache contents from a JSON file.
@@ -214,7 +229,18 @@ export class PromptCache {
214
229
  * @returns Number of entries loaded.
215
230
  */
216
231
  load(filePath) {
217
- const entries = loadCache(filePath);
232
+ if (!existsSync(filePath)) {
233
+ return 0;
234
+ }
235
+ let entries;
236
+ try {
237
+ const content = readFileSync(filePath);
238
+ const data = JSON.parse(content);
239
+ entries = data.entries ?? null;
240
+ }
241
+ catch {
242
+ return 0;
243
+ }
218
244
  if (!entries) {
219
245
  return 0;
220
246
  }
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.isVersionGreaterOrEqual = isVersionGreaterOrEqual;
4
4
  exports.parsePromptIdentifier = parsePromptIdentifier;
5
5
  const semver_1 = require("semver");
6
+ const error_js_1 = require("./error.cjs");
6
7
  function isVersionGreaterOrEqual(current_version, target_version) {
7
8
  const current = (0, semver_1.parse)(current_version);
8
9
  const target = (0, semver_1.parse)(target_version);
@@ -17,20 +18,20 @@ function parsePromptIdentifier(identifier) {
17
18
  identifier.startsWith("/") ||
18
19
  identifier.endsWith("/") ||
19
20
  identifier.split(":").length > 2) {
20
- throw new Error(`Invalid identifier format: ${identifier}`);
21
+ throw new Error((0, error_js_1.getInvalidPromptIdentifierMsg)(identifier));
21
22
  }
22
23
  const [ownerNamePart, commitPart] = identifier.split(":");
23
24
  const commit = commitPart || "latest";
24
25
  if (ownerNamePart.includes("/")) {
25
26
  const [owner, name] = ownerNamePart.split("/", 2);
26
27
  if (!owner || !name) {
27
- throw new Error(`Invalid identifier format: ${identifier}`);
28
+ throw new Error((0, error_js_1.getInvalidPromptIdentifierMsg)(identifier));
28
29
  }
29
30
  return [owner, name, commit];
30
31
  }
31
32
  else {
32
33
  if (!ownerNamePart) {
33
- throw new Error(`Invalid identifier format: ${identifier}`);
34
+ throw new Error((0, error_js_1.getInvalidPromptIdentifierMsg)(identifier));
34
35
  }
35
36
  return ["-", ownerNamePart, commit];
36
37
  }
@@ -1,4 +1,5 @@
1
1
  import { parse as parseVersion } from "semver";
2
+ import { getInvalidPromptIdentifierMsg } from "./error.js";
2
3
  export function isVersionGreaterOrEqual(current_version, target_version) {
3
4
  const current = parseVersion(current_version);
4
5
  const target = parseVersion(target_version);
@@ -13,20 +14,20 @@ export function parsePromptIdentifier(identifier) {
13
14
  identifier.startsWith("/") ||
14
15
  identifier.endsWith("/") ||
15
16
  identifier.split(":").length > 2) {
16
- throw new Error(`Invalid identifier format: ${identifier}`);
17
+ throw new Error(getInvalidPromptIdentifierMsg(identifier));
17
18
  }
18
19
  const [ownerNamePart, commitPart] = identifier.split(":");
19
20
  const commit = commitPart || "latest";
20
21
  if (ownerNamePart.includes("/")) {
21
22
  const [owner, name] = ownerNamePart.split("/", 2);
22
23
  if (!owner || !name) {
23
- throw new Error(`Invalid identifier format: ${identifier}`);
24
+ throw new Error(getInvalidPromptIdentifierMsg(identifier));
24
25
  }
25
26
  return [owner, name, commit];
26
27
  }
27
28
  else {
28
29
  if (!ownerNamePart) {
29
- throw new Error(`Invalid identifier format: ${identifier}`);
30
+ throw new Error(getInvalidPromptIdentifierMsg(identifier));
30
31
  }
31
32
  return ["-", ownerNamePart, commit];
32
33
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.5.5",
3
+ "version": "0.5.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": [
@@ -449,6 +449,6 @@
449
449
  "rimraf/**/glob": "10.5.0"
450
450
  },
451
451
  "browser": {
452
- "./dist/utils/prompt_cache/fs.js": "./dist/utils/prompt_cache/fs.browser.js"
452
+ "./dist/utils/fs.js": "./dist/utils/fs.browser.js"
453
453
  }
454
454
  }
@@ -1,24 +0,0 @@
1
- "use strict";
2
- /**
3
- * File system operations for prompt cache (Browser version).
4
- *
5
- * This stub is used in browser builds via the package.json browser field.
6
- * File operations are not supported in browser environments.
7
- */
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.dumpCache = dumpCache;
10
- exports.loadCache = loadCache;
11
- /**
12
- * Dump cache entries to a JSON file.
13
- * @throws Error - Always throws in browser environments.
14
- */
15
- function dumpCache(_filePath, _entries) {
16
- throw new Error("dump() is not supported in browser environments.");
17
- }
18
- /**
19
- * Load cache entries from a JSON file.
20
- * @throws Error - Always throws in browser environments.
21
- */
22
- function loadCache(_filePath) {
23
- throw new Error("load() is not supported in browser environments.");
24
- }