langsmith 0.8.7 → 0.8.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 (71) hide show
  1. package/dist/_openapi_client/client.cjs +8 -0
  2. package/dist/_openapi_client/client.d.ts +3 -0
  3. package/dist/_openapi_client/client.js +8 -0
  4. package/dist/_openapi_client/resources/annotation-queues/annotation-queues.cjs +147 -0
  5. package/dist/_openapi_client/resources/annotation-queues/annotation-queues.d.ts +372 -0
  6. package/dist/_openapi_client/resources/annotation-queues/annotation-queues.js +110 -0
  7. package/dist/_openapi_client/resources/annotation-queues/items.cjs +84 -0
  8. package/dist/_openapi_client/resources/annotation-queues/items.d.ts +207 -0
  9. package/dist/_openapi_client/resources/annotation-queues/items.js +80 -0
  10. package/dist/_openapi_client/resources/annotation-queues/runs.cjs +61 -0
  11. package/dist/_openapi_client/resources/annotation-queues/runs.d.ts +185 -0
  12. package/dist/_openapi_client/resources/annotation-queues/runs.js +57 -0
  13. package/dist/_openapi_client/resources/datasets/experiment-runs.cjs +1 -1
  14. package/dist/_openapi_client/resources/datasets/experiment-runs.js +1 -1
  15. package/dist/_openapi_client/resources/index.cjs +3 -1
  16. package/dist/_openapi_client/resources/index.d.ts +1 -0
  17. package/dist/_openapi_client/resources/index.js +1 -0
  18. package/dist/_openapi_client/resources/info.cjs +3 -1
  19. package/dist/_openapi_client/resources/info.d.ts +16 -22
  20. package/dist/_openapi_client/resources/info.js +3 -1
  21. package/dist/_openapi_client/resources/issues.cjs +2 -2
  22. package/dist/_openapi_client/resources/issues.js +2 -2
  23. package/dist/_openapi_client/resources/online-evaluators.cjs +7 -7
  24. package/dist/_openapi_client/resources/online-evaluators.d.ts +8 -0
  25. package/dist/_openapi_client/resources/online-evaluators.js +7 -7
  26. package/dist/_openapi_client/resources/public/runs.cjs +2 -2
  27. package/dist/_openapi_client/resources/public/runs.d.ts +1 -1
  28. package/dist/_openapi_client/resources/public/runs.js +2 -2
  29. package/dist/_openapi_client/resources/runs/runs.cjs +3 -3
  30. package/dist/_openapi_client/resources/runs/runs.d.ts +9 -4
  31. package/dist/_openapi_client/resources/runs/runs.js +3 -3
  32. package/dist/_openapi_client/resources/runs/share.cjs +2 -2
  33. package/dist/_openapi_client/resources/runs/share.js +2 -2
  34. package/dist/_openapi_client/resources/sandboxes/boxes.cjs +10 -10
  35. package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +40 -0
  36. package/dist/_openapi_client/resources/sandboxes/boxes.js +10 -10
  37. package/dist/_openapi_client/resources/sandboxes/registries.cjs +5 -5
  38. package/dist/_openapi_client/resources/sandboxes/registries.js +5 -5
  39. package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +17 -0
  40. package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +4 -4
  41. package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +12 -0
  42. package/dist/_openapi_client/resources/sandboxes/snapshots.js +4 -4
  43. package/dist/_openapi_client/resources/threads.cjs +3 -3
  44. package/dist/_openapi_client/resources/threads.d.ts +2 -1
  45. package/dist/_openapi_client/resources/threads.js +3 -3
  46. package/dist/_openapi_client/resources/traces.cjs +2 -2
  47. package/dist/_openapi_client/resources/traces.d.ts +1 -1
  48. package/dist/_openapi_client/resources/traces.js +2 -2
  49. package/dist/client.cjs +57 -21
  50. package/dist/client.d.ts +58 -22
  51. package/dist/client.js +57 -21
  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/sandbox/command_handle.cjs +4 -4
  56. package/dist/sandbox/command_handle.js +5 -5
  57. package/dist/sandbox/errors.cjs +16 -1
  58. package/dist/sandbox/errors.d.ts +11 -0
  59. package/dist/sandbox/errors.js +14 -0
  60. package/dist/sandbox/index.cjs +2 -1
  61. package/dist/sandbox/index.d.ts +1 -1
  62. package/dist/sandbox/index.js +1 -1
  63. package/dist/sandbox/sandbox.cjs +22 -4
  64. package/dist/sandbox/sandbox.js +24 -6
  65. package/dist/sandbox/ws_execute.cjs +75 -8
  66. package/dist/sandbox/ws_execute.d.ts +8 -0
  67. package/dist/sandbox/ws_execute.js +72 -8
  68. package/package.json +1 -1
  69. package/dist/utils/constants.cjs +0 -4
  70. package/dist/utils/constants.d.ts +0 -1
  71. package/dist/utils/constants.js +0 -1
@@ -108,7 +108,7 @@ export interface TraceListRunsParams {
108
108
  * (repeatable query parameter). Accepts any value of the `RunSelectField` enum. If
109
109
  * omitted, only `id` is returned.
110
110
  */
111
- selects?: Array<'ID' | 'NAME' | 'RUN_TYPE' | 'STATUS' | 'START_TIME' | 'END_TIME' | 'LATENCY_SECONDS' | 'FIRST_TOKEN_TIME' | 'ERROR' | 'ERROR_PREVIEW' | 'EXTRA' | 'METADATA' | 'EVENTS' | 'INPUTS' | 'INPUTS_PREVIEW' | 'OUTPUTS' | 'OUTPUTS_PREVIEW' | 'MANIFEST' | 'PARENT_RUN_IDS' | 'PROJECT_ID' | 'TRACE_ID' | 'THREAD_ID' | 'DOTTED_ORDER' | 'IS_ROOT' | 'REFERENCE_EXAMPLE_ID' | 'REFERENCE_DATASET_ID' | 'TOTAL_TOKENS' | 'PROMPT_TOKENS' | 'COMPLETION_TOKENS' | 'TOTAL_COST' | 'PROMPT_COST' | 'COMPLETION_COST' | 'PROMPT_TOKEN_DETAILS' | 'COMPLETION_TOKEN_DETAILS' | 'PROMPT_COST_DETAILS' | 'COMPLETION_COST_DETAILS' | 'PRICE_MODEL_ID' | 'TAGS' | 'APP_PATH' | 'ATTACHMENTS' | 'THREAD_EVALUATION_TIME' | 'IS_IN_DATASET' | 'SHARE_URL' | 'FEEDBACK_STATS'>;
111
+ selects?: Array<'ID' | 'NAME' | 'RUN_TYPE' | 'STATUS' | 'START_TIME' | 'END_TIME' | 'LATENCY_SECONDS' | 'FIRST_TOKEN_TIME' | 'ERROR' | 'ERROR_PREVIEW' | 'EXTRA' | 'METADATA' | 'EVENTS' | 'INPUTS' | 'INPUTS_PREVIEW' | 'OUTPUTS' | 'OUTPUTS_PREVIEW' | 'MANIFEST' | 'PARENT_RUN_IDS' | 'PROJECT_ID' | 'TRACE_ID' | 'THREAD_ID' | 'DOTTED_ORDER' | 'IS_ROOT' | 'REFERENCE_EXAMPLE_ID' | 'REFERENCE_DATASET_ID' | 'TOTAL_TOKENS' | 'PROMPT_TOKENS' | 'COMPLETION_TOKENS' | 'TOTAL_COST' | 'PROMPT_COST' | 'COMPLETION_COST' | 'PROMPT_TOKEN_DETAILS' | 'COMPLETION_TOKEN_DETAILS' | 'PROMPT_COST_DETAILS' | 'COMPLETION_COST_DETAILS' | 'PRICE_MODEL_ID' | 'TAGS' | 'APP_PATH' | 'ATTACHMENTS' | 'THREAD_EVALUATION_TIME' | 'IS_IN_DATASET' | 'LAST_QUEUED_AT' | 'SHARE_URL' | 'FEEDBACK_STATS'>;
112
112
  /**
113
113
  * Header param: application/json
114
114
  */
@@ -20,7 +20,7 @@ export class Traces extends APIResource {
20
20
  */
21
21
  listRuns(traceID, params, options) {
22
22
  const { Accept, ...query } = params;
23
- return this._client.get(path `/v2/traces/${traceID}/runs`, {
23
+ return this._client.get(path `/api/v2/traces/${traceID}/runs`, {
24
24
  query,
25
25
  ...options,
26
26
  headers: buildHeaders([{ ...(Accept != null ? { Accept: Accept } : undefined) }, options?.headers]),
@@ -48,7 +48,7 @@ export class Traces extends APIResource {
48
48
  * ```
49
49
  */
50
50
  query(body, options) {
51
- return this._client.getAPIList('/v2/traces/query', (ItemsCursorPostPagination), {
51
+ return this._client.getAPIList('/api/v2/traces/query', (ItemsCursorPostPagination), {
52
52
  body,
53
53
  method: 'post',
54
54
  ...options,
package/dist/client.cjs CHANGED
@@ -46,7 +46,6 @@ const index_js_1 = require("./index.cjs");
46
46
  const index_js_2 = require("./_openapi_client/index.cjs");
47
47
  const _uuid_js_1 = require("./utils/_uuid.cjs");
48
48
  const warn_js_1 = require("./utils/warn.cjs");
49
- const constants_js_1 = require("./utils/constants.cjs");
50
49
  const prompts_js_1 = require("./utils/prompts.cjs");
51
50
  const error_js_1 = require("./utils/error.cjs");
52
51
  const index_js_3 = require("./utils/prompt_cache/index.cjs");
@@ -161,9 +160,13 @@ function _formatFeedbackScore(score) {
161
160
  }
162
161
  return score;
163
162
  }
164
- function _checkBackendVersion(version, minVersion = constants_js_1._MIN_BACKEND_VERSION) {
163
+ function _checkBackendVersion(backendVersion, minVersion) {
164
+ if (!backendVersion) {
165
+ // /info was unreachable (or skipped): nothing to compare against.
166
+ return;
167
+ }
165
168
  const parse = (v) => v.split(".").map((s) => parseInt(s, 10));
166
- const [maj, min, pat] = parse(version);
169
+ const [maj, min, pat] = parse(backendVersion);
167
170
  const [rMaj, rMin, rPat] = parse(minVersion);
168
171
  if (isNaN(maj) ||
169
172
  isNaN(min) ||
@@ -171,13 +174,16 @@ function _checkBackendVersion(version, minVersion = constants_js_1._MIN_BACKEND_
171
174
  isNaN(rMaj) ||
172
175
  isNaN(rMin) ||
173
176
  isNaN(rPat)) {
174
- console.warn(`[LANGSMITH]: Could not parse backend version ${JSON.stringify(version)} for compatibility check.`);
177
+ console.warn(`[LANGSMITH]: Could not parse backend version ${JSON.stringify(backendVersion)} for compatibility check.`);
175
178
  return;
176
179
  }
177
180
  if (maj < rMaj ||
178
181
  (maj === rMaj && min < rMin) ||
179
182
  (maj === rMaj && min === rMin && pat < rPat)) {
180
- console.warn(`[LANGSMITH]: Backend version ${JSON.stringify(version)} is older than the minimum version required by this SDK (${JSON.stringify(minVersion)}). Some features may not work as expected.`);
183
+ console.warn(`[LANGSMITH]: Backend version ${JSON.stringify(backendVersion)} is older than ` +
184
+ `the minimum version required by this SDK (${JSON.stringify(minVersion)}). ` +
185
+ "Some features may not work as expected. See " +
186
+ "https://docs.langchain.com/langsmith/smithdb-sdk-migration");
181
187
  }
182
188
  }
183
189
  exports.DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
@@ -648,11 +654,11 @@ class Client {
648
654
  writable: true,
649
655
  value: void 0
650
656
  });
651
- Object.defineProperty(this, "_stainlessVersionChecked", {
657
+ Object.defineProperty(this, "_stainlessVersionsChecked", {
652
658
  enumerable: true,
653
659
  configurable: true,
654
660
  writable: true,
655
- value: false
661
+ value: new Set()
656
662
  });
657
663
  Object.defineProperty(this, "manualFlushMode", {
658
664
  enumerable: true,
@@ -958,7 +964,12 @@ class Client {
958
964
  this._customHeaders = value ?? {};
959
965
  }
960
966
  _getOpenAPIBaseUrl() {
961
- return this.apiUrl.endsWith("/v1") ? this.apiUrl.slice(0, -3) : this.apiUrl;
967
+ const url = this.apiUrl.replace(/\/$/, "");
968
+ for (const suffix of ["/api/v1", "/api"]) {
969
+ if (url.endsWith(suffix))
970
+ return url.slice(0, -suffix.length);
971
+ }
972
+ return url;
962
973
  }
963
974
  _newOpenAPIClient() {
964
975
  const defaultHeaders = this.apiKey === undefined && this.workspaceId === undefined
@@ -981,35 +992,42 @@ class Client {
981
992
  return needsV1Prefix ? `/v1/platform/${path}` : `/platform/${path}`;
982
993
  }
983
994
  get evaluators() {
984
- this._checkStainlessVersion();
995
+ this._checkStainlessVersion("0.16.0");
985
996
  return this.openAPIClient.onlineEvaluators;
986
997
  }
987
998
  get runs() {
988
- this._checkStainlessVersion();
999
+ this._checkStainlessVersion("0.16.0");
989
1000
  return this.openAPIClient.runs;
990
1001
  }
991
1002
  /** Access the v2 sandboxes resource (registries, snapshots, boxes). */
992
1003
  get sandboxes() {
993
- this._checkStainlessVersion();
1004
+ this._checkStainlessVersion("0.16.0");
994
1005
  return this.openAPIClient.sandboxes;
995
1006
  }
996
1007
  /** Access the v2 datasets resource (experimentRuns, etc.). */
997
1008
  get datasets() {
998
- this._checkStainlessVersion();
1009
+ this._checkStainlessVersion("0.16.0");
999
1010
  return this.openAPIClient.datasets;
1000
1011
  }
1012
+ /** Access the annotation queues resource (runs, items). */
1013
+ get annotationQueues() {
1014
+ // The items endpoints landed in backend 0.16.14; the rest are older.
1015
+ this._checkStainlessVersion("0.16.14");
1016
+ return this.openAPIClient.annotationQueues;
1017
+ }
1001
1018
  /** Access the threads resource (query, stats, listTraces). */
1002
1019
  get threads() {
1003
- this._checkStainlessVersion();
1020
+ this._checkStainlessVersion("0.16.0");
1004
1021
  return this.openAPIClient.threads;
1005
1022
  }
1006
1023
  /** Access the traces resource (query, listRuns). */
1007
1024
  get traces() {
1008
- this._checkStainlessVersion();
1025
+ this._checkStainlessVersion("0.16.0");
1009
1026
  return this.openAPIClient.traces;
1010
1027
  }
1011
1028
  /** Access the public shared-run resource. */
1012
1029
  get public() {
1030
+ this._checkStainlessVersion("0.16.0");
1013
1031
  return this.openAPIClient.public;
1014
1032
  }
1015
1033
  async processInputs(inputs) {
@@ -1498,15 +1516,13 @@ class Client {
1498
1516
  }
1499
1517
  return json;
1500
1518
  }
1501
- _checkStainlessVersion() {
1502
- if (this._stainlessVersionChecked)
1519
+ _checkStainlessVersion(minVersion) {
1520
+ if (this._stainlessVersionsChecked.has(minVersion))
1503
1521
  return;
1504
- this._stainlessVersionChecked = true;
1522
+ this._stainlessVersionsChecked.add(minVersion);
1505
1523
  this._ensureServerInfo()
1506
1524
  .then((serverInfo) => {
1507
- if (serverInfo?.version) {
1508
- _checkBackendVersion(serverInfo.version);
1509
- }
1525
+ _checkBackendVersion(serverInfo?.version, minVersion);
1510
1526
  })
1511
1527
  .catch(() => {
1512
1528
  // _ensureServerInfo handles and logs its own errors
@@ -1537,6 +1553,20 @@ class Client {
1537
1553
  const serverInfo = await this._ensureServerInfo();
1538
1554
  return serverInfo.instance_flags?.sdb_query_enabled === true;
1539
1555
  }
1556
+ /**
1557
+ * Throw on SmithDB-only deployments, warn elsewhere. Call only when run-level
1558
+ * feedback has no sessionId.
1559
+ */
1560
+ async _checkFeedbackSessionId() {
1561
+ const docs = "https://docs.langchain.com/langsmith/smithdb-sdk-migration#feedback-create";
1562
+ const serverInfo = await this._ensureServerInfo();
1563
+ if (serverInfo.instance_flags?.ch_query_enabled === false) {
1564
+ throw new Error(`sessionId must be provided when creating feedback for a run: this ` +
1565
+ `deployment cannot locate the run without it. See ${docs}`);
1566
+ }
1567
+ (0, warn_js_1.warnOnce)(`Creating feedback for a run without sessionId is deprecated and will ` +
1568
+ `stop working in a future release. See ${docs}`);
1569
+ }
1540
1570
  async _getSettings() {
1541
1571
  if (!this.settings) {
1542
1572
  this.settings = this._get("/settings");
@@ -3631,13 +3661,19 @@ class Client {
3631
3661
  return res;
3632
3662
  });
3633
3663
  }
3634
- async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, extendTraceRetention, }) {
3664
+ async createFeedback(runIdOrParams, keyArg, optionsArg) {
3665
+ const { runId = null, key, score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, extendTraceRetention, } = typeof runIdOrParams === "object" && runIdOrParams !== null
3666
+ ? runIdOrParams
3667
+ : { runId: runIdOrParams, key: keyArg, ...optionsArg };
3635
3668
  if (!runId && !projectId) {
3636
3669
  throw new Error("One of runId or projectId must be provided");
3637
3670
  }
3638
3671
  if (runId && projectId) {
3639
3672
  throw new Error("Only one of runId or projectId can be provided");
3640
3673
  }
3674
+ if (runId && sessionId === undefined) {
3675
+ await this._checkFeedbackSessionId();
3676
+ }
3641
3677
  const feedback_source = {
3642
3678
  type: feedbackSourceType ?? "api",
3643
3679
  metadata: sourceInfo ?? {},
package/dist/client.d.ts CHANGED
@@ -7,6 +7,7 @@ import { OnlineEvaluators as Evaluators } from "./_openapi_client/resources/onli
7
7
  import { Runs as OpenAPIRuns } from "./_openapi_client/resources/runs.js";
8
8
  import { Sandboxes } from "./_openapi_client/resources/sandboxes/sandboxes.js";
9
9
  import { Datasets } from "./_openapi_client/resources/datasets/datasets.js";
10
+ import { AnnotationQueues } from "./_openapi_client/resources/annotation-queues/annotation-queues.js";
10
11
  import { Threads } from "./_openapi_client/resources/threads.js";
11
12
  import { Traces } from "./_openapi_client/resources/traces.js";
12
13
  import { Public } from "./_openapi_client/resources/public/public.js";
@@ -335,6 +336,51 @@ interface ProjectOptions {
335
336
  }
336
337
  type RecordStringAny = Record<string, any>;
337
338
  export type FeedbackSourceType = "model" | "api" | "app";
339
+ export type CreateFeedbackOptions = {
340
+ /** The metric name, tag, or aspect to provide feedback on. */
341
+ key: string;
342
+ score?: ScoreType;
343
+ value?: ValueType;
344
+ correction?: object;
345
+ comment?: string;
346
+ sourceInfo?: object;
347
+ feedbackSourceType?: FeedbackSourceType;
348
+ feedbackConfig?: FeedbackConfig;
349
+ sourceRunId?: string;
350
+ feedbackId?: string;
351
+ comparativeExperimentId?: string;
352
+ /**
353
+ * The run's start time, ISO string or epoch ms. Better performance if provided.
354
+ */
355
+ startTime?: number | string;
356
+ /** If false, create feedback without extending the trace's retention tier. */
357
+ extendTraceRetention?: boolean;
358
+ };
359
+ /** @deprecated Pass all params within an object and populate sessionId. */
360
+ export type CreateFeedbackLegacyOptions = Omit<CreateFeedbackOptions, "key"> & {
361
+ /** @deprecated This option is no longer used. */
362
+ eager?: boolean;
363
+ /**
364
+ * The session (project) ID of the run. Required for run-level feedback;
365
+ * omitting it is deprecated. See
366
+ * https://docs.langchain.com/langsmith/smithdb-sdk-migration#feedback-create
367
+ */
368
+ sessionId?: string;
369
+ /** The project (or experiment) to provide feedback on, for session-level feedback. */
370
+ projectId?: string;
371
+ };
372
+ export type CreateFeedbackParams = CreateFeedbackOptions & ({
373
+ /** The run to provide feedback on. */
374
+ runId: string;
375
+ /** The session (project) ID of the run. */
376
+ sessionId: string;
377
+ projectId?: never;
378
+ } | {
379
+ runId?: null;
380
+ /** The project (or experiment) to provide feedback on. */
381
+ projectId: string;
382
+ sessionId?: never;
383
+ });
338
384
  export type CreateExampleOptions = {
339
385
  /** The ID of the dataset to create the example in. */
340
386
  datasetId?: string;
@@ -397,7 +443,7 @@ export interface ListThreadsItem extends Thread {
397
443
  runs: Run[];
398
444
  }
399
445
  export declare function mergeRuntimeEnvIntoRun<T extends RunCreate | RunUpdate>(run: T, cachedEnvVars?: Record<string, string>, omitTracedRuntimeInfo?: boolean): T;
400
- export declare function _checkBackendVersion(version: string, minVersion?: string): void;
446
+ export declare function _checkBackendVersion(backendVersion: string, minVersion: string): void;
401
447
  export declare const DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES: number;
402
448
  /** Default maximum memory (1GB) for queue size limits. */
403
449
  export declare const DEFAULT_MAX_SIZE_BYTES: number;
@@ -462,7 +508,7 @@ export declare class Client implements LangSmithTracingClientInterface {
462
508
  private traceBatchConcurrency;
463
509
  private _serverInfo;
464
510
  private _getServerInfoPromise?;
465
- private _stainlessVersionChecked;
511
+ private _stainlessVersionsChecked;
466
512
  private manualFlushMode;
467
513
  private _serializeWorker?;
468
514
  /**
@@ -526,6 +572,8 @@ export declare class Client implements LangSmithTracingClientInterface {
526
572
  get sandboxes(): Sandboxes;
527
573
  /** Access the v2 datasets resource (experimentRuns, etc.). */
528
574
  get datasets(): Datasets;
575
+ /** Access the annotation queues resource (runs, items). */
576
+ get annotationQueues(): AnnotationQueues;
529
577
  /** Access the threads resource (query, stats, listTraces). */
530
578
  get threads(): Threads;
531
579
  /** Access the traces resource (query, listRuns). */
@@ -587,6 +635,11 @@ export declare class Client implements LangSmithTracingClientInterface {
587
635
  private _checkStainlessVersion;
588
636
  protected _ensureServerInfo(): Promise<Record<string, any>>;
589
637
  _supportsSDBQuery(): Promise<boolean>;
638
+ /**
639
+ * Throw on SmithDB-only deployments, warn elsewhere. Call only when run-level
640
+ * feedback has no sessionId.
641
+ */
642
+ private _checkFeedbackSessionId;
590
643
  protected _getSettings(): Promise<LangSmithSettings>;
591
644
  /**
592
645
  * Flushes current queued traces.
@@ -963,26 +1016,9 @@ export declare class Client implements LangSmithTracingClientInterface {
963
1016
  exampleIds: string[];
964
1017
  remove?: boolean;
965
1018
  }): Promise<void>;
966
- createFeedback(runId: string | null, key: string, { score, value, correction, comment, sourceInfo, feedbackSourceType, sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, extendTraceRetention, }: {
967
- score?: ScoreType;
968
- value?: ValueType;
969
- correction?: object;
970
- comment?: string;
971
- sourceInfo?: object;
972
- feedbackSourceType?: FeedbackSourceType;
973
- feedbackConfig?: FeedbackConfig;
974
- sourceRunId?: string;
975
- feedbackId?: string;
976
- eager?: boolean;
977
- projectId?: string;
978
- comparativeExperimentId?: string;
979
- /** The session (project) ID of the run this feedback is for. */
980
- sessionId?: string;
981
- /** The start time of the run this feedback is for. Accepts ISO string or epoch ms. */
982
- startTime?: number | string;
983
- /** If false, create feedback without extending the trace's retention tier. */
984
- extendTraceRetention?: boolean;
985
- }): Promise<Feedback>;
1019
+ createFeedback(params: CreateFeedbackParams): Promise<Feedback>;
1020
+ /** @deprecated Pass all params within an object and populate sessionId. */
1021
+ createFeedback(runId: string | null, key: string, options: CreateFeedbackLegacyOptions): Promise<Feedback>;
986
1022
  updateFeedback(feedbackId: string, { score, value, correction, comment, }: {
987
1023
  score?: number | boolean | null;
988
1024
  value?: number | boolean | string | object | null;
package/dist/client.js CHANGED
@@ -8,7 +8,6 @@ import { __version__ } from "./index.js";
8
8
  import { Langsmith as OpenAPILangsmith } from "./_openapi_client/index.js";
9
9
  import { assertUuid } from "./utils/_uuid.js";
10
10
  import { warnOnce } from "./utils/warn.js";
11
- import { _MIN_BACKEND_VERSION } from "./utils/constants.js";
12
11
  import { parseHubIdentifier } from "./utils/prompts.js";
13
12
  import { raiseForStatus, isLangSmithNotFoundError, isLangSmithConflictError, } from "./utils/error.js";
14
13
  import { promptCacheSingleton, } from "./utils/prompt_cache/index.js";
@@ -123,9 +122,13 @@ function _formatFeedbackScore(score) {
123
122
  }
124
123
  return score;
125
124
  }
126
- export function _checkBackendVersion(version, minVersion = _MIN_BACKEND_VERSION) {
125
+ export function _checkBackendVersion(backendVersion, minVersion) {
126
+ if (!backendVersion) {
127
+ // /info was unreachable (or skipped): nothing to compare against.
128
+ return;
129
+ }
127
130
  const parse = (v) => v.split(".").map((s) => parseInt(s, 10));
128
- const [maj, min, pat] = parse(version);
131
+ const [maj, min, pat] = parse(backendVersion);
129
132
  const [rMaj, rMin, rPat] = parse(minVersion);
130
133
  if (isNaN(maj) ||
131
134
  isNaN(min) ||
@@ -133,13 +136,16 @@ export function _checkBackendVersion(version, minVersion = _MIN_BACKEND_VERSION)
133
136
  isNaN(rMaj) ||
134
137
  isNaN(rMin) ||
135
138
  isNaN(rPat)) {
136
- console.warn(`[LANGSMITH]: Could not parse backend version ${JSON.stringify(version)} for compatibility check.`);
139
+ console.warn(`[LANGSMITH]: Could not parse backend version ${JSON.stringify(backendVersion)} for compatibility check.`);
137
140
  return;
138
141
  }
139
142
  if (maj < rMaj ||
140
143
  (maj === rMaj && min < rMin) ||
141
144
  (maj === rMaj && min === rMin && pat < rPat)) {
142
- console.warn(`[LANGSMITH]: Backend version ${JSON.stringify(version)} is older than the minimum version required by this SDK (${JSON.stringify(minVersion)}). Some features may not work as expected.`);
145
+ console.warn(`[LANGSMITH]: Backend version ${JSON.stringify(backendVersion)} is older than ` +
146
+ `the minimum version required by this SDK (${JSON.stringify(minVersion)}). ` +
147
+ "Some features may not work as expected. See " +
148
+ "https://docs.langchain.com/langsmith/smithdb-sdk-migration");
143
149
  }
144
150
  }
145
151
  export const DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES = 24 * 1024 * 1024;
@@ -609,11 +615,11 @@ export class Client {
609
615
  writable: true,
610
616
  value: void 0
611
617
  });
612
- Object.defineProperty(this, "_stainlessVersionChecked", {
618
+ Object.defineProperty(this, "_stainlessVersionsChecked", {
613
619
  enumerable: true,
614
620
  configurable: true,
615
621
  writable: true,
616
- value: false
622
+ value: new Set()
617
623
  });
618
624
  Object.defineProperty(this, "manualFlushMode", {
619
625
  enumerable: true,
@@ -919,7 +925,12 @@ export class Client {
919
925
  this._customHeaders = value ?? {};
920
926
  }
921
927
  _getOpenAPIBaseUrl() {
922
- return this.apiUrl.endsWith("/v1") ? this.apiUrl.slice(0, -3) : this.apiUrl;
928
+ const url = this.apiUrl.replace(/\/$/, "");
929
+ for (const suffix of ["/api/v1", "/api"]) {
930
+ if (url.endsWith(suffix))
931
+ return url.slice(0, -suffix.length);
932
+ }
933
+ return url;
923
934
  }
924
935
  _newOpenAPIClient() {
925
936
  const defaultHeaders = this.apiKey === undefined && this.workspaceId === undefined
@@ -942,35 +953,42 @@ export class Client {
942
953
  return needsV1Prefix ? `/v1/platform/${path}` : `/platform/${path}`;
943
954
  }
944
955
  get evaluators() {
945
- this._checkStainlessVersion();
956
+ this._checkStainlessVersion("0.16.0");
946
957
  return this.openAPIClient.onlineEvaluators;
947
958
  }
948
959
  get runs() {
949
- this._checkStainlessVersion();
960
+ this._checkStainlessVersion("0.16.0");
950
961
  return this.openAPIClient.runs;
951
962
  }
952
963
  /** Access the v2 sandboxes resource (registries, snapshots, boxes). */
953
964
  get sandboxes() {
954
- this._checkStainlessVersion();
965
+ this._checkStainlessVersion("0.16.0");
955
966
  return this.openAPIClient.sandboxes;
956
967
  }
957
968
  /** Access the v2 datasets resource (experimentRuns, etc.). */
958
969
  get datasets() {
959
- this._checkStainlessVersion();
970
+ this._checkStainlessVersion("0.16.0");
960
971
  return this.openAPIClient.datasets;
961
972
  }
973
+ /** Access the annotation queues resource (runs, items). */
974
+ get annotationQueues() {
975
+ // The items endpoints landed in backend 0.16.14; the rest are older.
976
+ this._checkStainlessVersion("0.16.14");
977
+ return this.openAPIClient.annotationQueues;
978
+ }
962
979
  /** Access the threads resource (query, stats, listTraces). */
963
980
  get threads() {
964
- this._checkStainlessVersion();
981
+ this._checkStainlessVersion("0.16.0");
965
982
  return this.openAPIClient.threads;
966
983
  }
967
984
  /** Access the traces resource (query, listRuns). */
968
985
  get traces() {
969
- this._checkStainlessVersion();
986
+ this._checkStainlessVersion("0.16.0");
970
987
  return this.openAPIClient.traces;
971
988
  }
972
989
  /** Access the public shared-run resource. */
973
990
  get public() {
991
+ this._checkStainlessVersion("0.16.0");
974
992
  return this.openAPIClient.public;
975
993
  }
976
994
  async processInputs(inputs) {
@@ -1459,15 +1477,13 @@ export class Client {
1459
1477
  }
1460
1478
  return json;
1461
1479
  }
1462
- _checkStainlessVersion() {
1463
- if (this._stainlessVersionChecked)
1480
+ _checkStainlessVersion(minVersion) {
1481
+ if (this._stainlessVersionsChecked.has(minVersion))
1464
1482
  return;
1465
- this._stainlessVersionChecked = true;
1483
+ this._stainlessVersionsChecked.add(minVersion);
1466
1484
  this._ensureServerInfo()
1467
1485
  .then((serverInfo) => {
1468
- if (serverInfo?.version) {
1469
- _checkBackendVersion(serverInfo.version);
1470
- }
1486
+ _checkBackendVersion(serverInfo?.version, minVersion);
1471
1487
  })
1472
1488
  .catch(() => {
1473
1489
  // _ensureServerInfo handles and logs its own errors
@@ -1498,6 +1514,20 @@ export class Client {
1498
1514
  const serverInfo = await this._ensureServerInfo();
1499
1515
  return serverInfo.instance_flags?.sdb_query_enabled === true;
1500
1516
  }
1517
+ /**
1518
+ * Throw on SmithDB-only deployments, warn elsewhere. Call only when run-level
1519
+ * feedback has no sessionId.
1520
+ */
1521
+ async _checkFeedbackSessionId() {
1522
+ const docs = "https://docs.langchain.com/langsmith/smithdb-sdk-migration#feedback-create";
1523
+ const serverInfo = await this._ensureServerInfo();
1524
+ if (serverInfo.instance_flags?.ch_query_enabled === false) {
1525
+ throw new Error(`sessionId must be provided when creating feedback for a run: this ` +
1526
+ `deployment cannot locate the run without it. See ${docs}`);
1527
+ }
1528
+ warnOnce(`Creating feedback for a run without sessionId is deprecated and will ` +
1529
+ `stop working in a future release. See ${docs}`);
1530
+ }
1501
1531
  async _getSettings() {
1502
1532
  if (!this.settings) {
1503
1533
  this.settings = this._get("/settings");
@@ -3592,13 +3622,19 @@ export class Client {
3592
3622
  return res;
3593
3623
  });
3594
3624
  }
3595
- async createFeedback(runId, key, { score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, extendTraceRetention, }) {
3625
+ async createFeedback(runIdOrParams, keyArg, optionsArg) {
3626
+ const { runId = null, key, score, value, correction, comment, sourceInfo, feedbackSourceType = "api", sourceRunId, feedbackId, feedbackConfig, projectId, comparativeExperimentId, sessionId, startTime, extendTraceRetention, } = typeof runIdOrParams === "object" && runIdOrParams !== null
3627
+ ? runIdOrParams
3628
+ : { runId: runIdOrParams, key: keyArg, ...optionsArg };
3596
3629
  if (!runId && !projectId) {
3597
3630
  throw new Error("One of runId or projectId must be provided");
3598
3631
  }
3599
3632
  if (runId && projectId) {
3600
3633
  throw new Error("Only one of runId or projectId can be provided");
3601
3634
  }
3635
+ if (runId && sessionId === undefined) {
3636
+ await this._checkFeedbackSessionId();
3637
+ }
3602
3638
  const feedback_source = {
3603
3639
  type: feedbackSourceType ?? "api",
3604
3640
  metadata: sourceInfo ?? {},
package/dist/index.cjs CHANGED
@@ -35,6 +35,6 @@ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, g
35
35
  Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_js_1.RateLimitError; } });
36
36
  Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_js_1.InternalServerError; } });
37
37
  // Update using pnpm bump-version
38
- exports.__version__ = "0.8.7";
38
+ exports.__version__ = "0.8.8";
39
39
  // Metadata key to hide a traced run from LangSmith's Messages View.
40
40
  exports.LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
package/dist/index.d.ts CHANGED
@@ -7,5 +7,5 @@ export { computeRunIdForSecondaryReplica, uuid7, uuid7FromTime, } from "./uuid.j
7
7
  export { isTracingEnabled } from "./utils/guard.js";
8
8
  export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
9
9
  export { LangsmithError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./_openapi_client/core/error.js";
10
- export declare const __version__ = "0.8.7";
10
+ export declare const __version__ = "0.8.8";
11
11
  export declare const LS_MESSAGE_VIEW_EXCLUDE: "ls_message_view_exclude";
package/dist/index.js CHANGED
@@ -7,6 +7,6 @@ export { isTracingEnabled } from "./utils/guard.js";
7
7
  export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
8
8
  export { LangsmithError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./_openapi_client/core/error.js";
9
9
  // Update using pnpm bump-version
10
- export const __version__ = "0.8.7";
10
+ export const __version__ = "0.8.8";
11
11
  // Metadata key to hide a traced run from LangSmith's Messages View.
12
12
  export const LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
@@ -247,9 +247,9 @@ class CommandHandle {
247
247
  return; // Stream ended normally (exit message received)
248
248
  }
249
249
  catch (e) {
250
- const eName = e != null && typeof e === "object" ? e.name : "";
251
- if (eName !== "LangSmithSandboxConnectionError" &&
252
- eName !== "LangSmithSandboxServerReloadError") {
250
+ // instanceof, not a name check: subclasses (connect timeout, server
251
+ // reload) must stay retryable here.
252
+ if (!(e instanceof errors_js_1.LangSmithSandboxConnectionError)) {
253
253
  throw e;
254
254
  }
255
255
  if (this._control && this._control.killed) {
@@ -259,7 +259,7 @@ class CommandHandle {
259
259
  if (reconnectAttempts > CommandHandle.MAX_AUTO_RECONNECTS) {
260
260
  throw new errors_js_1.LangSmithSandboxConnectionError(`Lost connection ${reconnectAttempts} times in succession, giving up`);
261
261
  }
262
- const isHotReload = eName === "LangSmithSandboxServerReloadError";
262
+ const isHotReload = e instanceof errors_js_1.LangSmithSandboxServerReloadError;
263
263
  if (!isHotReload) {
264
264
  const delay = Math.min(CommandHandle.BACKOFF_BASE * 2 ** (reconnectAttempts - 1), CommandHandle.BACKOFF_MAX);
265
265
  await new Promise((r) => setTimeout(r, delay * 1000));
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Port of Python's AsyncCommandHandle to TypeScript.
6
6
  */
7
- import { LangSmithSandboxConnectionError, LangSmithSandboxOperationError, LangSmithStreamEndedBeforeStartedError, } from "./errors.js";
7
+ import { LangSmithSandboxConnectionError, LangSmithSandboxServerReloadError, LangSmithSandboxOperationError, LangSmithStreamEndedBeforeStartedError, } from "./errors.js";
8
8
  /**
9
9
  * Async handle to a running command with streaming output and auto-reconnect.
10
10
  *
@@ -244,9 +244,9 @@ export class CommandHandle {
244
244
  return; // Stream ended normally (exit message received)
245
245
  }
246
246
  catch (e) {
247
- const eName = e != null && typeof e === "object" ? e.name : "";
248
- if (eName !== "LangSmithSandboxConnectionError" &&
249
- eName !== "LangSmithSandboxServerReloadError") {
247
+ // instanceof, not a name check: subclasses (connect timeout, server
248
+ // reload) must stay retryable here.
249
+ if (!(e instanceof LangSmithSandboxConnectionError)) {
250
250
  throw e;
251
251
  }
252
252
  if (this._control && this._control.killed) {
@@ -256,7 +256,7 @@ export class CommandHandle {
256
256
  if (reconnectAttempts > CommandHandle.MAX_AUTO_RECONNECTS) {
257
257
  throw new LangSmithSandboxConnectionError(`Lost connection ${reconnectAttempts} times in succession, giving up`);
258
258
  }
259
- const isHotReload = eName === "LangSmithSandboxServerReloadError";
259
+ const isHotReload = e instanceof LangSmithSandboxServerReloadError;
260
260
  if (!isHotReload) {
261
261
  const delay = Math.min(CommandHandle.BACKOFF_BASE * 2 ** (reconnectAttempts - 1), CommandHandle.BACKOFF_MAX);
262
262
  await new Promise((r) => setTimeout(r, delay * 1000));
@@ -7,7 +7,7 @@
7
7
  * properties for specific handling when needed.
8
8
  */
9
9
  Object.defineProperty(exports, "__esModule", { value: true });
10
- exports.LangSmithSandboxServerReloadError = exports.LangSmithStreamEndedBeforeStartedError = exports.LangSmithCommandTimeoutError = exports.LangSmithSandboxOperationError = exports.LangSmithSandboxNotReadyError = exports.LangSmithDataplaneNotConfiguredError = exports.LangSmithSandboxCreationError = exports.LangSmithResourceCreationError = exports.LangSmithQuotaExceededError = exports.LangSmithValidationError = exports.LangSmithResourceNameConflictError = exports.LangSmithResourceAlreadyExistsError = exports.LangSmithResourceInUseError = exports.LangSmithResourceTimeoutError = exports.LangSmithResourceNotFoundError = exports.LangSmithSandboxConnectionError = exports.LangSmithSandboxAuthenticationError = exports.LangSmithSandboxAPIError = exports.LangSmithSandboxError = void 0;
10
+ exports.LangSmithSandboxServerReloadError = exports.LangSmithSandboxConnectTimeoutError = exports.LangSmithStreamEndedBeforeStartedError = exports.LangSmithCommandTimeoutError = exports.LangSmithSandboxOperationError = exports.LangSmithSandboxNotReadyError = exports.LangSmithDataplaneNotConfiguredError = exports.LangSmithSandboxCreationError = exports.LangSmithResourceCreationError = exports.LangSmithQuotaExceededError = exports.LangSmithValidationError = exports.LangSmithResourceNameConflictError = exports.LangSmithResourceAlreadyExistsError = exports.LangSmithResourceInUseError = exports.LangSmithResourceTimeoutError = exports.LangSmithResourceNotFoundError = exports.LangSmithSandboxConnectionError = exports.LangSmithSandboxAuthenticationError = exports.LangSmithSandboxAPIError = exports.LangSmithSandboxError = void 0;
11
11
  /**
12
12
  * Base exception for sandbox client errors.
13
13
  */
@@ -372,6 +372,21 @@ class LangSmithStreamEndedBeforeStartedError extends LangSmithSandboxOperationEr
372
372
  }
373
373
  }
374
374
  exports.LangSmithStreamEndedBeforeStartedError = LangSmithStreamEndedBeforeStartedError;
375
+ /**
376
+ * Thrown when the socket fails or times out before the WebSocket handshake.
377
+ *
378
+ * Distinct from its parent because it is safely retryable: the execute frame
379
+ * was never sent, so re-issuing the same command_id cannot double-run a
380
+ * command. run() retries this with backoff; a plain connection error (a
381
+ * rejected handshake) is permanent and propagates immediately.
382
+ */
383
+ class LangSmithSandboxConnectTimeoutError extends LangSmithSandboxConnectionError {
384
+ constructor(message) {
385
+ super(message);
386
+ this.name = "LangSmithSandboxConnectTimeoutError";
387
+ }
388
+ }
389
+ exports.LangSmithSandboxConnectTimeoutError = LangSmithSandboxConnectTimeoutError;
375
390
  /**
376
391
  * Raised when the sandbox server is reloading (close code 1001).
377
392
  *
@@ -165,6 +165,17 @@ export declare class LangSmithCommandTimeoutError extends LangSmithSandboxOperat
165
165
  export declare class LangSmithStreamEndedBeforeStartedError extends LangSmithSandboxOperationError {
166
166
  constructor(message: string);
167
167
  }
168
+ /**
169
+ * Thrown when the socket fails or times out before the WebSocket handshake.
170
+ *
171
+ * Distinct from its parent because it is safely retryable: the execute frame
172
+ * was never sent, so re-issuing the same command_id cannot double-run a
173
+ * command. run() retries this with backoff; a plain connection error (a
174
+ * rejected handshake) is permanent and propagates immediately.
175
+ */
176
+ export declare class LangSmithSandboxConnectTimeoutError extends LangSmithSandboxConnectionError {
177
+ constructor(message: string);
178
+ }
168
179
  /**
169
180
  * Raised when the sandbox server is reloading (close code 1001).
170
181
  *