langsmith 0.5.6 → 0.5.8

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.
Files changed (38) hide show
  1. package/dist/client.cjs +378 -3
  2. package/dist/client.d.ts +202 -2
  3. package/dist/client.js +378 -3
  4. package/dist/evaluation/evaluator.cjs +1 -1
  5. package/dist/evaluation/evaluator.js +2 -2
  6. package/dist/experimental/anthropic/index.cjs +15 -1
  7. package/dist/experimental/anthropic/index.js +15 -1
  8. package/dist/experimental/vercel/index.cjs +23 -5
  9. package/dist/experimental/vercel/index.js +23 -5
  10. package/dist/index.cjs +1 -1
  11. package/dist/index.d.ts +1 -1
  12. package/dist/index.js +1 -1
  13. package/dist/utils/error.cjs +16 -0
  14. package/dist/utils/error.d.ts +8 -0
  15. package/dist/utils/error.js +15 -0
  16. package/dist/utils/fs.browser.cjs +51 -0
  17. package/dist/utils/fs.browser.d.ts +25 -0
  18. package/dist/utils/fs.browser.js +37 -0
  19. package/dist/utils/fs.cjs +101 -0
  20. package/dist/utils/fs.d.ts +21 -0
  21. package/dist/utils/fs.js +54 -0
  22. package/dist/utils/jestlike/vendor/evaluatedBy.cjs +2 -2
  23. package/dist/utils/jestlike/vendor/evaluatedBy.js +3 -3
  24. package/dist/utils/prompt_cache/index.cjs +31 -5
  25. package/dist/utils/prompt_cache/index.d.ts +3 -2
  26. package/dist/utils/prompt_cache/index.js +31 -5
  27. package/dist/utils/prompts.cjs +4 -3
  28. package/dist/utils/prompts.js +4 -3
  29. package/dist/wrappers/anthropic.cjs +8 -3
  30. package/dist/wrappers/anthropic.d.ts +5 -0
  31. package/dist/wrappers/anthropic.js +8 -4
  32. package/package.json +4 -4
  33. package/dist/utils/prompt_cache/fs.browser.cjs +0 -24
  34. package/dist/utils/prompt_cache/fs.browser.d.ts +0 -16
  35. package/dist/utils/prompt_cache/fs.browser.js +0 -20
  36. package/dist/utils/prompt_cache/fs.cjs +0 -86
  37. package/dist/utils/prompt_cache/fs.d.ts +0 -16
  38. package/dist/utils/prompt_cache/fs.js +0 -49
package/dist/client.d.ts CHANGED
@@ -234,6 +234,24 @@ interface GroupRunsParams {
234
234
  */
235
235
  offset?: number;
236
236
  }
237
+ export interface ReadThreadParams {
238
+ threadId: string;
239
+ projectId?: string;
240
+ projectName?: string;
241
+ isRoot?: boolean;
242
+ limit?: number;
243
+ filter?: string;
244
+ order?: "asc" | "desc";
245
+ }
246
+ export interface ListThreadsParams {
247
+ projectId?: string;
248
+ projectName?: string;
249
+ limit?: number;
250
+ offset?: number;
251
+ filter?: string;
252
+ startTime?: Date;
253
+ isRoot?: boolean;
254
+ }
237
255
  interface UploadCSVParams {
238
256
  csvFile: Blob;
239
257
  fileName: string;
@@ -317,11 +335,15 @@ type Thread = {
317
335
  latency_p50: number;
318
336
  latency_p99: number;
319
337
  feedback_stats: any | null;
320
- group_key: string;
338
+ thread_id: string;
321
339
  first_inputs: string;
322
340
  last_outputs: string;
323
341
  last_error: string | null;
324
342
  };
343
+ /** Item returned by {@link Client.listThreads}. */
344
+ export interface ListThreadsItem extends Thread {
345
+ runs: Run[];
346
+ }
325
347
  export declare function mergeRuntimeEnvIntoRun<T extends RunCreate | RunUpdate>(run: T, cachedEnvVars?: Record<string, string>, omitTracedRuntimeInfo?: boolean): T;
326
348
  export declare const DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES: number;
327
349
  /** Default maximum memory (1GB) for queue size limits. */
@@ -391,6 +413,9 @@ export declare class Client implements LangSmithTracingClientInterface {
391
413
  private multipartStreamingDisabled;
392
414
  private _multipartDisabled;
393
415
  private _runCompressionDisabled;
416
+ private failedTracesDir;
417
+ private failedTracesMaxBytes;
418
+ private static _fallbackDirsCreated;
394
419
  debug: boolean;
395
420
  constructor(config?: ClientConfig);
396
421
  static getDefaultClientConfig(): {
@@ -419,6 +444,19 @@ export declare class Client implements LangSmithTracingClientInterface {
419
444
  private _getBatchSizeLimit;
420
445
  private _getDatasetExamplesMultiPartSupport;
421
446
  private drainAutoBatchQueue;
447
+ /**
448
+ * Persist a failed trace payload to a local fallback directory.
449
+ *
450
+ * Saves a self-contained JSON file containing the endpoint path, the HTTP
451
+ * headers required for replay, and the base64-encoded request body.
452
+ * Can be replayed later with a simple POST:
453
+ *
454
+ * POST /<endpoint>
455
+ * Content-Type: <value from saved headers>
456
+ * [Content-Encoding: <value from saved headers>]
457
+ * <decoded body>
458
+ */
459
+ private static _writeTraceToFallbackDir;
422
460
  private _processBatch;
423
461
  private _sendBatchToOTELTranslator;
424
462
  private processRunOperation;
@@ -562,6 +600,8 @@ export declare class Client implements LangSmithTracingClientInterface {
562
600
  */
563
601
  listRuns(props: ListRunsParams): AsyncIterable<Run>;
564
602
  listGroupRuns(props: GroupRunsParams): AsyncIterable<Thread>;
603
+ readThread(props: ReadThreadParams): AsyncIterable<Run>;
604
+ listThreads(props: ListThreadsParams): Promise<ListThreadsItem[]>;
565
605
  getRunStats({ id, trace, parentRun, runType, projectNames, projectIds, referenceExampleIds, startTime, endTime, error, query, filter, traceFilter, treeFilter, isRoot, dataSourceType, }: {
566
606
  id?: string[];
567
607
  trace?: string;
@@ -1045,23 +1085,183 @@ export declare class Client implements LangSmithTracingClientInterface {
1045
1085
  protected _getLatestCommitHash(promptOwnerAndName: string): Promise<string | undefined>;
1046
1086
  protected _likeOrUnlikePrompt(promptIdentifier: string, like: boolean): Promise<LikePromptResponse>;
1047
1087
  protected _getPromptUrl(promptIdentifier: string): Promise<string>;
1088
+ /**
1089
+ * Check if a prompt exists.
1090
+ * @param promptIdentifier - The identifier of the prompt. Can be in the format:
1091
+ * - "promptName" (for private prompts, owner defaults to "-")
1092
+ * - "owner/promptName" (for prompts with explicit owner)
1093
+ * @returns A Promise that resolves to true if the prompt exists, false otherwise
1094
+ * @example
1095
+ * ```typescript
1096
+ * // Check if a prompt exists before creating a commit
1097
+ * if (await client.promptExists("my-prompt")) {
1098
+ * await client.createCommit("my-prompt", template);
1099
+ * } else {
1100
+ * await client.createPrompt("my-prompt");
1101
+ * }
1102
+ * ```
1103
+ */
1048
1104
  promptExists(promptIdentifier: string): Promise<boolean>;
1105
+ /**
1106
+ * Like a prompt.
1107
+ * @param promptIdentifier - The identifier of the prompt. Can be in the format:
1108
+ * - "promptName" (for private prompts, owner defaults to "-")
1109
+ * - "owner/promptName" (for prompts with explicit owner)
1110
+ * @returns A Promise that resolves to the like response containing the updated like count
1111
+ * @example
1112
+ * ```typescript
1113
+ * // Like a prompt
1114
+ * const response = await client.likePrompt("owner/useful-prompt");
1115
+ * console.log(`Prompt now has ${response.likes} likes`);
1116
+ * ```
1117
+ */
1049
1118
  likePrompt(promptIdentifier: string): Promise<LikePromptResponse>;
1119
+ /**
1120
+ * Unlike a prompt (remove a previously added like).
1121
+ * @param promptIdentifier - The identifier of the prompt. Can be in the format:
1122
+ * - "promptName" (for private prompts, owner defaults to "-")
1123
+ * - "owner/promptName" (for prompts with explicit owner)
1124
+ * @returns A Promise that resolves to the like response containing the updated like count
1125
+ * @example
1126
+ * ```typescript
1127
+ * // Unlike a prompt
1128
+ * const response = await client.unlikePrompt("owner/useful-prompt");
1129
+ * console.log(`Prompt now has ${response.likes} likes`);
1130
+ * ```
1131
+ */
1050
1132
  unlikePrompt(promptIdentifier: string): Promise<LikePromptResponse>;
1051
- listCommits(promptOwnerAndName: string): AsyncIterableIterator<PromptCommit>;
1133
+ /**
1134
+ * List all commits for a prompt.
1135
+ * @param promptIdentifier - The identifier of the prompt. Can be in the format:
1136
+ * - "promptName" (for private prompts, owner defaults to "-")
1137
+ * - "owner/promptName" (for prompts with explicit owner)
1138
+ * - "promptName:commitHash" (commit hash is ignored, all commits are returned)
1139
+ * @returns An async iterable iterator of PromptCommit objects
1140
+ * @example
1141
+ * ```typescript
1142
+ * // List commits for a private prompt
1143
+ * for await (const commit of client.listCommits("my-prompt")) {
1144
+ * console.log(commit);
1145
+ * }
1146
+ *
1147
+ * // List commits for a prompt with explicit owner
1148
+ * for await (const commit of client.listCommits("owner/my-prompt")) {
1149
+ * console.log(commit);
1150
+ * }
1151
+ * ```
1152
+ */
1153
+ listCommits(promptIdentifier: string): AsyncIterableIterator<PromptCommit>;
1154
+ /**
1155
+ * List prompts by filter.
1156
+ * @param options - Optional filters for listing prompts
1157
+ * @param options.isPublic - Filter by public/private prompts. If undefined, returns all prompts.
1158
+ * @param options.isArchived - Filter by archived status. Defaults to false (non-archived prompts only).
1159
+ * @param options.sortField - Field to sort by. Defaults to "updated_at".
1160
+ * @param options.query - Search query to filter prompts by name or description.
1161
+ * @returns An async iterable iterator of Prompt objects
1162
+ * @example
1163
+ * ```typescript
1164
+ * // List all prompts
1165
+ * for await (const prompt of client.listPrompts()) {
1166
+ * console.log(prompt);
1167
+ * }
1168
+ *
1169
+ * // List only public prompts
1170
+ * for await (const prompt of client.listPrompts({ isPublic: true })) {
1171
+ * console.log(prompt);
1172
+ * }
1173
+ *
1174
+ * // Search for prompts
1175
+ * for await (const prompt of client.listPrompts({ query: "translation" })) {
1176
+ * console.log(prompt);
1177
+ * }
1178
+ * ```
1179
+ */
1052
1180
  listPrompts(options?: {
1053
1181
  isPublic?: boolean;
1054
1182
  isArchived?: boolean;
1055
1183
  sortField?: PromptSortField;
1056
1184
  query?: string;
1057
1185
  }): AsyncIterableIterator<Prompt>;
1186
+ /**
1187
+ * Get a prompt by its identifier.
1188
+ * @param promptIdentifier - The identifier of the prompt. Can be in the format:
1189
+ * - "promptName" (for private prompts, owner defaults to "-")
1190
+ * - "owner/promptName" (for prompts with explicit owner)
1191
+ * - "promptName:commitHash" (commit hash is ignored, latest version is returned)
1192
+ * @returns A Promise that resolves to the Prompt object, or null if not found
1193
+ * @example
1194
+ * ```typescript
1195
+ * // Get a private prompt
1196
+ * const prompt = await client.getPrompt("my-prompt");
1197
+ *
1198
+ * // Get a public prompt
1199
+ * const publicPrompt = await client.getPrompt("owner/public-prompt");
1200
+ * ```
1201
+ */
1058
1202
  getPrompt(promptIdentifier: string): Promise<Prompt | null>;
1203
+ /**
1204
+ * Create a new prompt.
1205
+ * @param promptIdentifier - The identifier for the new prompt. Can be in the format:
1206
+ * - "promptName" (creates a private prompt)
1207
+ * - "owner/promptName" (creates a prompt under a specific owner, must match your tenant)
1208
+ * @param options - Optional configuration for the prompt
1209
+ * @param options.description - A description of the prompt
1210
+ * @param options.readme - Markdown content for the prompt's README
1211
+ * @param options.tags - Array of tags to categorize the prompt
1212
+ * @param options.isPublic - Whether the prompt should be public. Requires a LangChain Hub handle.
1213
+ * @returns A Promise that resolves to the created Prompt object
1214
+ * @throws {Error} If creating a public prompt without a LangChain Hub handle, or if owner doesn't match current tenant
1215
+ * @example
1216
+ * ```typescript
1217
+ * // Create a private prompt
1218
+ * const prompt = await client.createPrompt("my-new-prompt", {
1219
+ * description: "A prompt for translations",
1220
+ * tags: ["translation", "language"]
1221
+ * });
1222
+ *
1223
+ * // Create a public prompt
1224
+ * const publicPrompt = await client.createPrompt("my-public-prompt", {
1225
+ * description: "A public translation prompt",
1226
+ * isPublic: true
1227
+ * });
1228
+ * ```
1229
+ */
1059
1230
  createPrompt(promptIdentifier: string, options?: {
1060
1231
  description?: string;
1061
1232
  readme?: string;
1062
1233
  tags?: string[];
1063
1234
  isPublic?: boolean;
1064
1235
  }): Promise<Prompt>;
1236
+ /**
1237
+ * Create a new commit for an existing prompt.
1238
+ * @param promptIdentifier - The identifier of the prompt. Can be in the format:
1239
+ * - "promptName" (for private prompts, owner defaults to "-")
1240
+ * - "owner/promptName" (for prompts with explicit owner)
1241
+ * @param object - The prompt object/manifest to commit (e.g., ChatPromptTemplate, messages array, etc.)
1242
+ * @param options - Optional configuration for the commit
1243
+ * @param options.parentCommitHash - The parent commit hash. Defaults to "latest" (the most recent commit).
1244
+ * @returns A Promise that resolves to the URL of the newly created commit
1245
+ * @throws {Error} If the prompt does not exist
1246
+ * @example
1247
+ * ```typescript
1248
+ * import { ChatPromptTemplate } from "@langchain/core/prompts";
1249
+ *
1250
+ * // Create a commit with a new version of the prompt
1251
+ * const template = ChatPromptTemplate.fromMessages([
1252
+ * ["system", "You are a helpful assistant."],
1253
+ * ["human", "{input}"]
1254
+ * ]);
1255
+ *
1256
+ * const commitUrl = await client.createCommit("my-prompt", template);
1257
+ * console.log(`Commit created: ${commitUrl}`);
1258
+ *
1259
+ * // Create a commit based on a specific parent commit
1260
+ * const commitUrl2 = await client.createCommit("my-prompt", template, {
1261
+ * parentCommitHash: "abc123def456"
1262
+ * });
1263
+ * ```
1264
+ */
1065
1265
  createCommit(promptIdentifier: string, object: any, options?: {
1066
1266
  parentCommitHash?: string;
1067
1267
  }): Promise<string>;