langsmith 0.5.19 → 0.6.0

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 (161) hide show
  1. package/dist/client.cjs +460 -22
  2. package/dist/client.d.ts +165 -1
  3. package/dist/client.js +464 -26
  4. package/dist/evaluation/_runner.cjs +4 -7
  5. package/dist/evaluation/_runner.js +2 -5
  6. package/dist/evaluation/evaluate_comparative.cjs +10 -10
  7. package/dist/evaluation/evaluate_comparative.js +1 -1
  8. package/dist/evaluation/evaluator.cjs +2 -2
  9. package/dist/evaluation/evaluator.js +1 -1
  10. package/dist/experimental/anthropic/context.cjs +419 -49
  11. package/dist/experimental/anthropic/context.js +420 -50
  12. package/dist/experimental/anthropic/index.cjs +78 -10
  13. package/dist/experimental/anthropic/index.js +80 -12
  14. package/dist/experimental/anthropic/messages.cjs +53 -0
  15. package/dist/experimental/anthropic/messages.d.ts +6 -0
  16. package/dist/experimental/anthropic/messages.js +52 -0
  17. package/dist/experimental/anthropic/transcripts.cjs +144 -0
  18. package/dist/experimental/anthropic/transcripts.d.ts +22 -0
  19. package/dist/experimental/anthropic/transcripts.js +141 -0
  20. package/dist/experimental/anthropic/types.d.ts +1 -0
  21. package/dist/experimental/anthropic/usage.cjs +19 -20
  22. package/dist/experimental/anthropic/usage.d.ts +2 -1
  23. package/dist/experimental/anthropic/usage.js +18 -20
  24. package/dist/experimental/opencode/index.cjs +36 -0
  25. package/dist/experimental/opencode/index.d.ts +3 -0
  26. package/dist/experimental/opencode/index.js +32 -0
  27. package/dist/experimental/opencode/tracer.cjs +389 -0
  28. package/dist/experimental/opencode/tracer.d.ts +30 -0
  29. package/dist/experimental/opencode/tracer.js +385 -0
  30. package/dist/experimental/otel/setup.cjs +1 -1
  31. package/dist/experimental/otel/setup.js +1 -1
  32. package/dist/experimental/sandbox/client.cjs +308 -409
  33. package/dist/experimental/sandbox/client.d.ts +136 -157
  34. package/dist/experimental/sandbox/client.js +310 -411
  35. package/dist/experimental/sandbox/errors.cjs +1 -2
  36. package/dist/experimental/sandbox/errors.d.ts +1 -2
  37. package/dist/experimental/sandbox/errors.js +1 -2
  38. package/dist/experimental/sandbox/helpers.cjs +8 -98
  39. package/dist/experimental/sandbox/helpers.d.ts +0 -29
  40. package/dist/experimental/sandbox/helpers.js +9 -95
  41. package/dist/experimental/sandbox/index.cjs +6 -1
  42. package/dist/experimental/sandbox/index.d.ts +7 -2
  43. package/dist/experimental/sandbox/index.js +6 -1
  44. package/dist/experimental/sandbox/sandbox.cjs +71 -13
  45. package/dist/experimental/sandbox/sandbox.d.ts +39 -9
  46. package/dist/experimental/sandbox/sandbox.js +71 -13
  47. package/dist/experimental/sandbox/types.d.ts +147 -137
  48. package/dist/experimental/vercel/index.cjs +1 -1
  49. package/dist/experimental/vercel/index.js +1 -1
  50. package/dist/experimental/vercel/middleware.cjs +2 -1
  51. package/dist/experimental/vercel/middleware.js +2 -1
  52. package/dist/index.cjs +1 -1
  53. package/dist/index.d.ts +1 -1
  54. package/dist/index.js +1 -1
  55. package/dist/run_trees.cjs +8 -7
  56. package/dist/run_trees.d.ts +7 -0
  57. package/dist/run_trees.js +7 -6
  58. package/dist/schemas.d.ts +58 -0
  59. package/dist/singletons/otel.cjs +3 -2
  60. package/dist/singletons/otel.js +4 -3
  61. package/dist/singletons/traceable.cjs +1 -3
  62. package/dist/singletons/traceable.js +1 -3
  63. package/dist/traceable.cjs +2 -5
  64. package/dist/traceable.js +2 -5
  65. package/dist/utils/_git.cjs +2 -2
  66. package/dist/utils/_git.js +2 -2
  67. package/dist/utils/_uuid.cjs +2 -2
  68. package/dist/utils/_uuid.js +1 -1
  69. package/dist/utils/env.cjs +35 -2
  70. package/dist/utils/env.d.ts +9 -0
  71. package/dist/utils/env.js +34 -2
  72. package/dist/utils/error.cjs +9 -2
  73. package/dist/utils/error.d.ts +1 -0
  74. package/dist/utils/error.js +8 -2
  75. package/dist/utils/fast-safe-stringify/index.cjs +203 -0
  76. package/dist/utils/fast-safe-stringify/index.d.ts +46 -0
  77. package/dist/utils/fast-safe-stringify/index.js +202 -0
  78. package/dist/utils/jestlike/index.cjs +5 -5
  79. package/dist/utils/jestlike/index.js +1 -1
  80. package/dist/utils/jestlike/reporter.cjs +1 -1
  81. package/dist/utils/jestlike/reporter.js +1 -1
  82. package/dist/utils/jestlike/vendor/chain.cjs +2 -3
  83. package/dist/utils/jestlike/vendor/chain.js +2 -3
  84. package/dist/utils/jestlike/vendor/evaluatedBy.cjs +3 -3
  85. package/dist/utils/jestlike/vendor/evaluatedBy.js +1 -1
  86. package/dist/utils/prompts.cjs +7 -2
  87. package/dist/utils/prompts.d.ts +6 -1
  88. package/dist/utils/prompts.js +6 -1
  89. package/dist/utils/serialize_worker.cjs +388 -0
  90. package/dist/utils/serialize_worker.d.ts +66 -0
  91. package/dist/utils/serialize_worker.js +382 -0
  92. package/dist/utils/uuid/src/index.cjs +24 -0
  93. package/dist/utils/uuid/src/index.d.ts +10 -0
  94. package/dist/utils/uuid/src/index.js +9 -0
  95. package/dist/utils/uuid/src/max.cjs +3 -0
  96. package/dist/utils/uuid/src/max.d.ts +2 -0
  97. package/dist/utils/uuid/src/max.js +1 -0
  98. package/dist/utils/uuid/src/nil.cjs +3 -0
  99. package/dist/utils/uuid/src/nil.d.ts +2 -0
  100. package/dist/utils/uuid/src/nil.js +1 -0
  101. package/dist/utils/uuid/src/parse.cjs +23 -0
  102. package/dist/utils/uuid/src/parse.d.ts +3 -0
  103. package/dist/utils/uuid/src/parse.js +18 -0
  104. package/dist/utils/uuid/src/regex.cjs +3 -0
  105. package/dist/utils/uuid/src/regex.d.ts +2 -0
  106. package/dist/utils/uuid/src/regex.js +1 -0
  107. package/dist/utils/uuid/src/rng.cjs +10 -0
  108. package/dist/utils/uuid/src/rng.d.ts +1 -0
  109. package/dist/utils/uuid/src/rng.js +7 -0
  110. package/dist/utils/uuid/src/sha1.cjs +75 -0
  111. package/dist/utils/uuid/src/sha1.d.ts +2 -0
  112. package/dist/utils/uuid/src/sha1.js +73 -0
  113. package/dist/utils/uuid/src/stringify.cjs +55 -0
  114. package/dist/utils/uuid/src/stringify.d.ts +3 -0
  115. package/dist/utils/uuid/src/stringify.js +49 -0
  116. package/dist/utils/uuid/src/types.cjs +2 -0
  117. package/dist/utils/uuid/src/types.d.ts +22 -0
  118. package/dist/utils/uuid/src/types.js +1 -0
  119. package/dist/utils/uuid/src/v35.cjs +52 -0
  120. package/dist/utils/uuid/src/v35.d.ts +7 -0
  121. package/dist/utils/uuid/src/v35.js +44 -0
  122. package/dist/utils/uuid/src/v4.cjs +40 -0
  123. package/dist/utils/uuid/src/v4.d.ts +4 -0
  124. package/dist/utils/uuid/src/v4.js +35 -0
  125. package/dist/utils/uuid/src/v5.cjs +50 -0
  126. package/dist/utils/uuid/src/v5.d.ts +9 -0
  127. package/dist/utils/uuid/src/v5.js +9 -0
  128. package/dist/utils/uuid/src/v7.cjs +88 -0
  129. package/dist/utils/uuid/src/v7.d.ts +9 -0
  130. package/dist/utils/uuid/src/v7.js +82 -0
  131. package/dist/utils/uuid/src/validate.cjs +10 -0
  132. package/dist/utils/uuid/src/validate.d.ts +2 -0
  133. package/dist/utils/uuid/src/validate.js +5 -0
  134. package/dist/utils/uuid/src/version.cjs +13 -0
  135. package/dist/utils/uuid/src/version.d.ts +2 -0
  136. package/dist/utils/uuid/src/version.js +8 -0
  137. package/dist/utils/worker_threads.browser.cjs +16 -0
  138. package/dist/utils/worker_threads.browser.d.ts +14 -0
  139. package/dist/utils/worker_threads.browser.js +13 -0
  140. package/dist/utils/worker_threads.cjs +16 -0
  141. package/dist/utils/worker_threads.d.ts +13 -0
  142. package/dist/utils/worker_threads.js +13 -0
  143. package/dist/uuid.cjs +2 -2
  144. package/dist/uuid.js +1 -1
  145. package/dist/vitest/utils/esm.mjs +4 -4
  146. package/dist/wrappers/gemini.cjs +1 -1
  147. package/dist/wrappers/gemini.js +1 -1
  148. package/dist/wrappers/openai.cjs +2 -6
  149. package/dist/wrappers/openai.js +2 -6
  150. package/dist/wrappers/openai_agents.cjs +849 -0
  151. package/dist/wrappers/openai_agents.d.ts +92 -0
  152. package/dist/wrappers/openai_agents.js +845 -0
  153. package/experimental/opencode.cjs +1 -0
  154. package/experimental/opencode.d.cts +1 -0
  155. package/experimental/opencode.d.ts +1 -0
  156. package/experimental/opencode.js +1 -0
  157. package/package.json +47 -25
  158. package/wrappers/openai_agents.cjs +1 -0
  159. package/wrappers/openai_agents.d.cts +1 -0
  160. package/wrappers/openai_agents.d.ts +1 -0
  161. package/wrappers/openai_agents.js +1 -0
package/dist/client.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import type { OTELContext } from "./experimental/otel/types.js";
2
2
  import { AsyncCallerParams } from "./utils/async_caller.js";
3
- import { ComparativeExperiment, DataType, Dataset, DatasetDiffInfo, DatasetShareSchema, Example, ExampleCreate, ExampleUpdate, ExampleUpdateWithoutId, Feedback, FeedbackConfig, FeedbackIngestToken, KVMap, LangChainBaseMessage, LangSmithSettings, LikePromptResponse, Prompt, PromptCommit, PromptSortField, Run, RunCreate, RunUpdate, ScoreType, TimeDelta, TracerSession, TracerSessionResult, ValueType, AnnotationQueue, RunWithAnnotationQueueInfo, Attachments, UploadExamplesResponse, UpdateExamplesResponse, DatasetVersion, AnnotationQueueWithDetails, AnnotationQueueRubricItem, FeedbackConfigSchema } from "./schemas.js";
3
+ import { ComparativeExperiment, DataType, Dataset, DatasetDiffInfo, DatasetShareSchema, Example, ExampleCreate, ExampleUpdate, ExampleUpdateWithoutId, Feedback, FeedbackConfig, FeedbackIngestToken, KVMap, LangChainBaseMessage, LangSmithSettings, LikePromptResponse, Prompt, PromptCommit, PromptSortField, Run, RunCreate, RunUpdate, ScoreType, TimeDelta, TracerSession, TracerSessionResult, ValueType, AnnotationQueue, RunWithAnnotationQueueInfo, Attachments, UploadExamplesResponse, UpdateExamplesResponse, DatasetVersion, AnnotationQueueWithDetails, AnnotationQueueRubricItem, FeedbackConfigSchema, AgentContext, SkillContext, Entry } from "./schemas.js";
4
+ import { type TracingMode } from "./utils/env.js";
4
5
  import { EvaluationResult, EvaluationResults } from "./evaluation/evaluator.js";
5
6
  import { PromptCache } from "./utils/prompt_cache/index.js";
6
7
  export interface ClientConfig {
@@ -12,6 +13,7 @@ export interface ClientConfig {
12
13
  anonymizer?: (values: KVMap) => KVMap | Promise<KVMap>;
13
14
  hideInputs?: boolean | ((inputs: KVMap) => KVMap | Promise<KVMap>);
14
15
  hideOutputs?: boolean | ((outputs: KVMap) => KVMap | Promise<KVMap>);
16
+ hideMetadata?: boolean | ((metadata: KVMap) => KVMap | Promise<KVMap>);
15
17
  /**
16
18
  * Whether to omit runtime information from traced runs.
17
19
  * If true, runtime information (SDK version, platform, etc.) and
@@ -55,6 +57,17 @@ export interface ClientConfig {
55
57
  * By default, prompt caching is enabled globally.
56
58
  */
57
59
  disablePromptCache?: boolean;
60
+ /**
61
+ * Where to send traces. One of:
62
+ *
63
+ * - `"langsmith"` (default) — LangSmith REST API only.
64
+ * - `"otel"` — OpenTelemetry export only.
65
+ *
66
+ * Falls back to the `LANGSMITH_TRACING_MODE` env var, then to the
67
+ * legacy `OTEL_ENABLED` / `LANGSMITH_OTEL_ENABLED` env vars, then to
68
+ * `"langsmith"`.
69
+ */
70
+ tracingMode?: TracingMode;
58
71
  /**
59
72
  * Additional HTTP headers to include in all requests.
60
73
  * These headers will be merged with the default headers (User-Agent,
@@ -396,6 +409,7 @@ export declare class Client implements LangSmithTracingClientInterface {
396
409
  private _tenantId;
397
410
  private hideInputs?;
398
411
  private hideOutputs?;
412
+ private hideMetadata?;
399
413
  private omitTracedRuntimeInfo?;
400
414
  private tracingSampleRate?;
401
415
  private filteredPostUuids;
@@ -412,11 +426,35 @@ export declare class Client implements LangSmithTracingClientInterface {
412
426
  private _serverInfo;
413
427
  private _getServerInfoPromise?;
414
428
  private manualFlushMode;
429
+ private _serializeWorker?;
430
+ /**
431
+ * Tracks in-flight drainAutoBatchQueue promises so awaitPendingTraceBatches
432
+ * can wait on them even if the flush involves async work (worker-thread
433
+ * serialize) that hasn't yet registered with batchIngestCaller.queue.
434
+ */
435
+ private _pendingDrains;
415
436
  private langSmithToOTELTranslator?;
437
+ private _tracingMode;
438
+ get tracingMode(): TracingMode;
416
439
  private fetchImplementation?;
417
440
  private cachedLSEnvVarsForMetadata?;
418
441
  private _promptCache?;
419
442
  private get _fetch();
443
+ /**
444
+ * Serialize a payload for tracing, optionally offloading the work to a
445
+ * Node worker thread when the runtime supports worker_threads.
446
+ *
447
+ * Falls back to synchronous serialization when:
448
+ * - manualFlushMode is enabled (serverless: worker boot cost > benefit)
449
+ * - worker_threads is unavailable (non-Node runtimes)
450
+ * - the payload contains values that can't be structured-cloned across
451
+ * threads (functions, non-cloneable class instances, streams, etc.)
452
+ * - the worker throws for any other reason
453
+ *
454
+ * In all fallback cases the returned bytes are identical to the sync path.
455
+ */
456
+ private _trackDrain;
457
+ private _serializeBody;
420
458
  private multipartStreamingDisabled;
421
459
  private _multipartDisabled;
422
460
  private _runCompressionDisabled;
@@ -432,6 +470,7 @@ export declare class Client implements LangSmithTracingClientInterface {
432
470
  webUrl?: string;
433
471
  hideInputs?: boolean;
434
472
  hideOutputs?: boolean;
473
+ hideMetadata?: boolean;
435
474
  };
436
475
  getHostUrl(): string;
437
476
  private get _mergedHeaders();
@@ -445,6 +484,7 @@ export declare class Client implements LangSmithTracingClientInterface {
445
484
  private _getPlatformEndpointPath;
446
485
  private processInputs;
447
486
  private processOutputs;
487
+ private processMetadata;
448
488
  /**
449
489
  * Filter content from new_token events to prevent streaming LLM output
450
490
  * from being uploaded via events.
@@ -1280,18 +1320,57 @@ export declare class Client implements LangSmithTracingClientInterface {
1280
1320
  * Fetch a prompt commit directly from the API (bypassing cache).
1281
1321
  */
1282
1322
  private _fetchPromptFromApi;
1323
+ /**
1324
+ * Pull a prompt commit from the LangSmith API.
1325
+ *
1326
+ * Public prompts referenced by owner/name cross a trust boundary because the
1327
+ * prompt manifest may contain serialized LangChain objects and configuration
1328
+ * that affect runtime behavior. For example, a prompt can intentionally
1329
+ * configure a model with a custom base URL, headers, model name, or other
1330
+ * constructor arguments. These are supported features, but they also mean the
1331
+ * prompt contents should be treated as executable configuration rather than
1332
+ * plain text.
1333
+ *
1334
+ * Set `dangerouslyPullPublicPrompt: true` only after reviewing and trusting
1335
+ * the prompt contents, not merely the publishing account. Prompts from your
1336
+ * own or your organization's account can still be unsafe if that account or
1337
+ * prompt was compromised.
1338
+ */
1283
1339
  pullPromptCommit(promptIdentifier: string, options?: {
1284
1340
  includeModel?: boolean;
1285
1341
  skipCache?: boolean;
1342
+ /**
1343
+ * Set to `true` to allow pulling a public prompt by owner/name, for
1344
+ * example `username/promptname`. Defaults to `false`.
1345
+ */
1346
+ dangerouslyPullPublicPrompt?: boolean;
1286
1347
  }): Promise<PromptCommit>;
1287
1348
  /**
1288
1349
  * This method should not be used directly, use `import { pull } from "langchain/hub"` instead.
1289
1350
  * Using this method directly returns the JSON string of the prompt rather than a LangChain object.
1351
+ *
1352
+ * Public prompts referenced by owner/name cross a trust boundary because the
1353
+ * prompt manifest may contain serialized LangChain objects and configuration
1354
+ * that affect runtime behavior. For example, a prompt can intentionally
1355
+ * configure a model with a custom base URL, headers, model name, or other
1356
+ * constructor arguments. These are supported features, but they also mean the
1357
+ * prompt contents should be treated as executable configuration rather than
1358
+ * plain text.
1359
+ *
1360
+ * Set `dangerouslyPullPublicPrompt: true` only after reviewing and trusting
1361
+ * the prompt contents, not merely the publishing account. Prompts from your
1362
+ * own or your organization's account can still be unsafe if that account or
1363
+ * prompt was compromised.
1290
1364
  * @private
1291
1365
  */
1292
1366
  _pullPrompt(promptIdentifier: string, options?: {
1293
1367
  includeModel?: boolean;
1294
1368
  skipCache?: boolean;
1369
+ /**
1370
+ * Set to `true` to allow pulling a public prompt by owner/name, for
1371
+ * example `username/promptname`. Defaults to `false`.
1372
+ */
1373
+ dangerouslyPullPublicPrompt?: boolean;
1295
1374
  }): Promise<any>;
1296
1375
  pushPrompt(promptIdentifier: string, options?: {
1297
1376
  object?: any;
@@ -1302,6 +1381,83 @@ export declare class Client implements LangSmithTracingClientInterface {
1302
1381
  tags?: string[];
1303
1382
  commitDescription?: string;
1304
1383
  }): Promise<string>;
1384
+ /**
1385
+ * Check if an agent repo exists.
1386
+ */
1387
+ agentExists(identifier: string): Promise<boolean>;
1388
+ /**
1389
+ * Check if a skill repo exists.
1390
+ */
1391
+ skillExists(identifier: string): Promise<boolean>;
1392
+ /**
1393
+ * Pull an agent directory from Hub.
1394
+ * @param identifier The identifier (owner/name[:version]).
1395
+ * @param options.version Commit hash or tag; overrides identifier's version.
1396
+ */
1397
+ pullAgent(identifier: string, options?: {
1398
+ version?: string;
1399
+ }): Promise<AgentContext>;
1400
+ /**
1401
+ * Pull a skill directory from Hub.
1402
+ */
1403
+ pullSkill(identifier: string, options?: {
1404
+ version?: string;
1405
+ }): Promise<SkillContext>;
1406
+ /**
1407
+ * Push an agent to Hub. Creates the repo if missing, patches metadata if
1408
+ * provided, then commits the given files.
1409
+ * @returns The URL of the resulting commit.
1410
+ */
1411
+ pushAgent(identifier: string, options: {
1412
+ files: Record<string, Entry | null>;
1413
+ parentCommit?: string;
1414
+ description?: string;
1415
+ readme?: string;
1416
+ tags?: string[];
1417
+ isPublic?: boolean;
1418
+ }): Promise<string>;
1419
+ /**
1420
+ * Push a skill to Hub.
1421
+ */
1422
+ pushSkill(identifier: string, options: {
1423
+ files: Record<string, Entry | null>;
1424
+ parentCommit?: string;
1425
+ description?: string;
1426
+ readme?: string;
1427
+ tags?: string[];
1428
+ isPublic?: boolean;
1429
+ }): Promise<string>;
1430
+ /**
1431
+ * Delete an agent and all its owned child file repos.
1432
+ */
1433
+ deleteAgent(identifier: string): Promise<void>;
1434
+ /**
1435
+ * Delete a skill and all its owned child file repos.
1436
+ */
1437
+ deleteSkill(identifier: string): Promise<void>;
1438
+ /**
1439
+ * List agent repos. Yields one at a time, auto-paginating.
1440
+ */
1441
+ listAgents(options?: {
1442
+ isPublic?: boolean;
1443
+ isArchived?: boolean;
1444
+ query?: string;
1445
+ }): AsyncIterableIterator<Prompt>;
1446
+ /**
1447
+ * List skill repos. Yields one at a time, auto-paginating.
1448
+ */
1449
+ listSkills(options?: {
1450
+ isPublic?: boolean;
1451
+ isArchived?: boolean;
1452
+ query?: string;
1453
+ }): AsyncIterableIterator<Prompt>;
1454
+ private _listReposByType;
1455
+ private _pullDirectory;
1456
+ private _pushDirectory;
1457
+ private _deleteDirectory;
1458
+ private _repoExists;
1459
+ private _createRepo;
1460
+ private _updateRepoMetadata;
1305
1461
  /**
1306
1462
  * Clone a public dataset to your own langsmith tenant.
1307
1463
  * This operation is idempotent. If you already have a dataset with the given name,
@@ -1345,6 +1501,14 @@ export declare class Client implements LangSmithTracingClientInterface {
1345
1501
  * @returns A promise that resolves once all currently pending traces have sent.
1346
1502
  */
1347
1503
  awaitPendingTraceBatches(): Promise<void>;
1504
+ /**
1505
+ * Returns a string representation of the Client instance.
1506
+ * This method is called when the object is converted to a string
1507
+ * or logged, ensuring sensitive information like API keys is not exposed.
1508
+ *
1509
+ * @returns A string representation of the Client.
1510
+ */
1511
+ toString(): string;
1348
1512
  }
1349
1513
  export interface LangSmithTracingClientInterface {
1350
1514
  createRun: (run: CreateRunParams) => Promise<void>;