langsmith 0.7.12 → 0.7.14
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.
- package/dist/_openapi_client/client.cjs +9 -1
- package/dist/_openapi_client/client.d.ts +5 -2
- package/dist/_openapi_client/client.js +9 -1
- package/dist/_openapi_client/resources/datasets/datasets.cjs +5 -14
- package/dist/_openapi_client/resources/datasets/datasets.d.ts +6 -10
- package/dist/_openapi_client/resources/datasets/datasets.js +5 -14
- package/dist/_openapi_client/resources/datasets/experiment-runs.cjs +18 -0
- package/dist/_openapi_client/resources/datasets/experiment-runs.d.ts +109 -0
- package/dist/_openapi_client/resources/datasets/experiment-runs.js +14 -0
- package/dist/_openapi_client/resources/datasets/runs.cjs +0 -7
- package/dist/_openapi_client/resources/datasets/runs.d.ts +1 -45
- package/dist/_openapi_client/resources/datasets/runs.js +0 -7
- package/dist/_openapi_client/resources/index.cjs +4 -2
- package/dist/_openapi_client/resources/index.d.ts +2 -1
- package/dist/_openapi_client/resources/index.js +2 -1
- package/dist/_openapi_client/resources/runs/runs.d.ts +1 -1
- package/dist/_openapi_client/resources/sandboxes/boxes.cjs +86 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +465 -0
- package/dist/_openapi_client/resources/sandboxes/boxes.js +82 -0
- package/dist/_openapi_client/resources/sandboxes/registries.cjs +44 -0
- package/dist/_openapi_client/resources/sandboxes/registries.d.ts +67 -0
- package/dist/_openapi_client/resources/sandboxes/registries.js +40 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.cjs +72 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +309 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.js +35 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +39 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +62 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.js +35 -0
- package/dist/_openapi_client/resources/sessions.cjs +53 -0
- package/dist/_openapi_client/resources/{sessions/sessions.d.ts → sessions.d.ts} +13 -51
- package/dist/_openapi_client/resources/sessions.js +49 -0
- package/dist/client.cjs +44 -0
- package/dist/client.d.ts +31 -0
- package/dist/client.js +44 -0
- package/dist/experimental/anthropic/context.cjs +5 -1
- package/dist/experimental/anthropic/context.js +5 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/sandbox/client.cjs +58 -15
- package/dist/sandbox/client.d.ts +27 -1
- package/dist/sandbox/client.js +54 -11
- package/dist/sandbox/sandbox.cjs +7 -6
- package/dist/sandbox/sandbox.d.ts +7 -2
- package/dist/sandbox/sandbox.js +8 -7
- package/dist/sandbox/types.d.ts +1 -7
- package/package.json +1 -1
- package/dist/_openapi_client/resources/datasets/experiments.cjs +0 -16
- package/dist/_openapi_client/resources/datasets/experiments.d.ts +0 -23
- package/dist/_openapi_client/resources/datasets/experiments.js +0 -12
- package/dist/_openapi_client/resources/datasets/group.cjs +0 -17
- package/dist/_openapi_client/resources/datasets/group.d.ts +0 -160
- package/dist/_openapi_client/resources/datasets/group.js +0 -13
- package/dist/_openapi_client/resources/sessions/insights.cjs +0 -54
- package/dist/_openapi_client/resources/sessions/insights.d.ts +0 -246
- package/dist/_openapi_client/resources/sessions/insights.js +0 -50
- package/dist/_openapi_client/resources/sessions/sessions.cjs +0 -109
- package/dist/_openapi_client/resources/sessions/sessions.js +0 -72
|
@@ -1,35 +1,28 @@
|
|
|
1
|
-
import { APIResource } from '
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { OffsetPaginationTopLevelArray, type OffsetPaginationTopLevelArrayParams, PagePromise } from '../../core/pagination.js';
|
|
6
|
-
import { RequestOptions } from '../../internal/request-options.js';
|
|
1
|
+
import { APIResource } from '../core/resource.js';
|
|
2
|
+
import { APIPromise } from '../core/api-promise.js';
|
|
3
|
+
import { OffsetPaginationTopLevelArray, type OffsetPaginationTopLevelArrayParams, PagePromise } from '../core/pagination.js';
|
|
4
|
+
import { RequestOptions } from '../internal/request-options.js';
|
|
7
5
|
export declare class Sessions extends APIResource {
|
|
8
|
-
insights: InsightsAPI.Insights;
|
|
9
6
|
/**
|
|
10
|
-
* Create a new
|
|
7
|
+
* Create a new project.
|
|
11
8
|
*/
|
|
12
9
|
create(params: SessionCreateParams, options?: RequestOptions): APIPromise<TracerSessionWithoutVirtualFields>;
|
|
13
10
|
/**
|
|
14
|
-
* Get a specific
|
|
11
|
+
* Get a specific project.
|
|
15
12
|
*/
|
|
16
|
-
retrieve(
|
|
13
|
+
retrieve(project_id: string, params?: SessionRetrieveParams | null | undefined, options?: RequestOptions): APIPromise<TracerSession>;
|
|
17
14
|
/**
|
|
18
|
-
* Update a
|
|
15
|
+
* Update a project.
|
|
19
16
|
*/
|
|
20
|
-
update(
|
|
17
|
+
update(project_id: string, body: SessionUpdateParams, options?: RequestOptions): APIPromise<TracerSessionWithoutVirtualFields>;
|
|
21
18
|
/**
|
|
22
|
-
*
|
|
19
|
+
* List all projects.
|
|
23
20
|
*/
|
|
24
21
|
list(params?: SessionListParams | null | undefined, options?: RequestOptions): PagePromise<TracerSessionsOffsetPaginationTopLevelArray, TracerSession>;
|
|
25
22
|
/**
|
|
26
|
-
* Delete a specific
|
|
23
|
+
* Delete a specific project.
|
|
27
24
|
*/
|
|
28
|
-
delete(
|
|
29
|
-
/**
|
|
30
|
-
* Get a prebuilt dashboard for a tracing project.
|
|
31
|
-
*/
|
|
32
|
-
dashboard(sessionID: string, params: SessionDashboardParams, options?: RequestOptions): APIPromise<CustomChartsSection>;
|
|
25
|
+
delete(project_id: string, options?: RequestOptions): APIPromise<unknown>;
|
|
33
26
|
}
|
|
34
27
|
export type TracerSessionsOffsetPaginationTopLevelArray = OffsetPaginationTopLevelArray<TracerSession>;
|
|
35
28
|
export interface CustomChartsSection {
|
|
@@ -638,37 +631,6 @@ export interface SessionListParams extends OffsetPaginationTopLevelArrayParams {
|
|
|
638
631
|
*/
|
|
639
632
|
accept?: string;
|
|
640
633
|
}
|
|
641
|
-
export interface SessionDashboardParams {
|
|
642
|
-
/**
|
|
643
|
-
* Body param
|
|
644
|
-
*/
|
|
645
|
-
end_time?: string | null;
|
|
646
|
-
/**
|
|
647
|
-
* Body param: Group by param for run stats.
|
|
648
|
-
*/
|
|
649
|
-
group_by?: RunStatsGroupBy | null;
|
|
650
|
-
/**
|
|
651
|
-
* Body param
|
|
652
|
-
*/
|
|
653
|
-
omit_data?: boolean;
|
|
654
|
-
/**
|
|
655
|
-
* Body param
|
|
656
|
-
*/
|
|
657
|
-
start_time?: string | null;
|
|
658
|
-
/**
|
|
659
|
-
* Body param: Timedelta input.
|
|
660
|
-
*/
|
|
661
|
-
stride?: TimedeltaInput;
|
|
662
|
-
/**
|
|
663
|
-
* Body param
|
|
664
|
-
*/
|
|
665
|
-
timezone?: string;
|
|
666
|
-
/**
|
|
667
|
-
* Header param
|
|
668
|
-
*/
|
|
669
|
-
accept?: string;
|
|
670
|
-
}
|
|
671
634
|
export declare namespace Sessions {
|
|
672
|
-
export { type CustomChartsSection as CustomChartsSection, type CustomChartsSectionRequest as CustomChartsSectionRequest, type RunStatsGroupBy as RunStatsGroupBy, type SessionSortableColumns as SessionSortableColumns, type TimedeltaInput as TimedeltaInput, type TracerSession as TracerSession, type TracerSessionWithoutVirtualFields as TracerSessionWithoutVirtualFields, type SessionDeleteResponse as SessionDeleteResponse, type TracerSessionsOffsetPaginationTopLevelArray as TracerSessionsOffsetPaginationTopLevelArray, type SessionCreateParams as SessionCreateParams, type SessionRetrieveParams as SessionRetrieveParams, type SessionUpdateParams as SessionUpdateParams, type SessionListParams as SessionListParams,
|
|
673
|
-
export { Insights as Insights, type CreateRunClusteringJobRequest as CreateRunClusteringJobRequest, type InsightCreateResponse as InsightCreateResponse, type InsightUpdateResponse as InsightUpdateResponse, type InsightListResponse as InsightListResponse, type InsightDeleteResponse as InsightDeleteResponse, type InsightRetrieveJobResponse as InsightRetrieveJobResponse, type InsightRetrieveRunsResponse as InsightRetrieveRunsResponse, type InsightListResponsesOffsetPaginationInsightsClusteringJobs as InsightListResponsesOffsetPaginationInsightsClusteringJobs, type InsightCreateParams as InsightCreateParams, type InsightUpdateParams as InsightUpdateParams, type InsightListParams as InsightListParams, type InsightDeleteParams as InsightDeleteParams, type InsightRetrieveJobParams as InsightRetrieveJobParams, type InsightRetrieveRunsParams as InsightRetrieveRunsParams, };
|
|
635
|
+
export { type CustomChartsSection as CustomChartsSection, type CustomChartsSectionRequest as CustomChartsSectionRequest, type RunStatsGroupBy as RunStatsGroupBy, type SessionSortableColumns as SessionSortableColumns, type TimedeltaInput as TimedeltaInput, type TracerSession as TracerSession, type TracerSessionWithoutVirtualFields as TracerSessionWithoutVirtualFields, type SessionDeleteResponse as SessionDeleteResponse, type TracerSessionsOffsetPaginationTopLevelArray as TracerSessionsOffsetPaginationTopLevelArray, type SessionCreateParams as SessionCreateParams, type SessionRetrieveParams as SessionRetrieveParams, type SessionUpdateParams as SessionUpdateParams, type SessionListParams as SessionListParams, };
|
|
674
636
|
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
import { APIResource } from '../core/resource.js';
|
|
4
|
+
import { OffsetPaginationTopLevelArray, } from '../core/pagination.js';
|
|
5
|
+
import { buildHeaders } from '../internal/headers.js';
|
|
6
|
+
import { path } from '../internal/utils/path.js';
|
|
7
|
+
export class Sessions extends APIResource {
|
|
8
|
+
/**
|
|
9
|
+
* Create a new project.
|
|
10
|
+
*/
|
|
11
|
+
create(params, options) {
|
|
12
|
+
const { upsert, ...body } = params;
|
|
13
|
+
return this._client.post('/api/v1/sessions', { query: { upsert }, body, ...options });
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Get a specific project.
|
|
17
|
+
*/
|
|
18
|
+
retrieve(project_id, params = {}, options) {
|
|
19
|
+
const { accept, ...query } = params ?? {};
|
|
20
|
+
return this._client.get(path `/api/v1/sessions/${project_id}`, {
|
|
21
|
+
query,
|
|
22
|
+
...options,
|
|
23
|
+
headers: buildHeaders([{ ...(accept != null ? { accept: accept } : undefined) }, options?.headers]),
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Update a project.
|
|
28
|
+
*/
|
|
29
|
+
update(project_id, body, options) {
|
|
30
|
+
return this._client.patch(path `/api/v1/sessions/${project_id}`, { body, ...options });
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* List all projects.
|
|
34
|
+
*/
|
|
35
|
+
list(params = {}, options) {
|
|
36
|
+
const { accept, ...query } = params ?? {};
|
|
37
|
+
return this._client.getAPIList('/api/v1/sessions', (OffsetPaginationTopLevelArray), {
|
|
38
|
+
query,
|
|
39
|
+
...options,
|
|
40
|
+
headers: buildHeaders([{ ...(accept != null ? { accept: accept } : undefined) }, options?.headers]),
|
|
41
|
+
});
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
* Delete a specific project.
|
|
45
|
+
*/
|
|
46
|
+
delete(project_id, options) {
|
|
47
|
+
return this._client.delete(path `/api/v1/sessions/${project_id}`, options);
|
|
48
|
+
}
|
|
49
|
+
}
|
package/dist/client.cjs
CHANGED
|
@@ -543,6 +543,12 @@ class Client {
|
|
|
543
543
|
writable: true,
|
|
544
544
|
value: void 0
|
|
545
545
|
});
|
|
546
|
+
Object.defineProperty(this, "anonymizer", {
|
|
547
|
+
enumerable: true,
|
|
548
|
+
configurable: true,
|
|
549
|
+
writable: true,
|
|
550
|
+
value: void 0
|
|
551
|
+
});
|
|
546
552
|
Object.defineProperty(this, "omitTracedRuntimeInfo", {
|
|
547
553
|
enumerable: true,
|
|
548
554
|
configurable: true,
|
|
@@ -794,6 +800,7 @@ class Client {
|
|
|
794
800
|
this.hideOutputs =
|
|
795
801
|
config.hideOutputs ?? config.anonymizer ?? defaultConfig.hideOutputs;
|
|
796
802
|
this.hideMetadata = config.hideMetadata ?? defaultConfig.hideMetadata;
|
|
803
|
+
this.anonymizer = config.anonymizer;
|
|
797
804
|
this.omitTracedRuntimeInfo = config.omitTracedRuntimeInfo ?? false;
|
|
798
805
|
this.autoBatchTracing = config.autoBatchTracing ?? this.autoBatchTracing;
|
|
799
806
|
this.autoBatchQueue = new AutoBatchQueue(maxMemory);
|
|
@@ -971,6 +978,18 @@ class Client {
|
|
|
971
978
|
get runs() {
|
|
972
979
|
return this.openAPIClient.runs;
|
|
973
980
|
}
|
|
981
|
+
/** Access the v2 sandboxes resource (registries, snapshots, boxes). */
|
|
982
|
+
get sandboxes() {
|
|
983
|
+
return this.openAPIClient.sandboxes;
|
|
984
|
+
}
|
|
985
|
+
/** Access the projects resource. */
|
|
986
|
+
get projects() {
|
|
987
|
+
return this.openAPIClient.sessions;
|
|
988
|
+
}
|
|
989
|
+
/** Access the v2 datasets resource (experimentRuns, etc.). */
|
|
990
|
+
get datasets() {
|
|
991
|
+
return this.openAPIClient.datasets;
|
|
992
|
+
}
|
|
974
993
|
async processInputs(inputs) {
|
|
975
994
|
if (this.hideInputs === false) {
|
|
976
995
|
return inputs;
|
|
@@ -1007,6 +1026,25 @@ class Client {
|
|
|
1007
1026
|
}
|
|
1008
1027
|
return metadata;
|
|
1009
1028
|
}
|
|
1029
|
+
/**
|
|
1030
|
+
* Apply the configured anonymizer to a run's error string.
|
|
1031
|
+
*
|
|
1032
|
+
* Unlike inputs/outputs, `error` is a plain string (an exception message or
|
|
1033
|
+
* traceback) that can carry credentials the user never explicitly logged --
|
|
1034
|
+
* e.g. an HTTP-client error whose message embeds an `Authorization` header.
|
|
1035
|
+
* The anonymizer is typed `(KVMap) => KVMap`, so the string is wrapped as
|
|
1036
|
+
* `{ error }`, scrubbed, and unwrapped. Mirrors the Python SDK's
|
|
1037
|
+
* `Client._hide_run_error`.
|
|
1038
|
+
*
|
|
1039
|
+
* TODO: Update anonymizer to always nest inputs/outputs/error for consistency
|
|
1040
|
+
*/
|
|
1041
|
+
async processError(error) {
|
|
1042
|
+
if (this.anonymizer == null) {
|
|
1043
|
+
return error;
|
|
1044
|
+
}
|
|
1045
|
+
const result = await this.anonymizer({ error });
|
|
1046
|
+
return typeof result?.error === "string" ? result.error : error;
|
|
1047
|
+
}
|
|
1010
1048
|
/**
|
|
1011
1049
|
* Filter content from new_token events to prevent streaming LLM output
|
|
1012
1050
|
* from being uploaded via events.
|
|
@@ -1033,6 +1071,9 @@ class Client {
|
|
|
1033
1071
|
if (runParams.outputs !== undefined) {
|
|
1034
1072
|
runParams.outputs = await this.processOutputs(runParams.outputs);
|
|
1035
1073
|
}
|
|
1074
|
+
if (runParams.error !== undefined) {
|
|
1075
|
+
runParams.error = await this.processError(runParams.error);
|
|
1076
|
+
}
|
|
1036
1077
|
if (runParams.extra != null && "metadata" in runParams.extra) {
|
|
1037
1078
|
runParams.extra = {
|
|
1038
1079
|
...runParams.extra,
|
|
@@ -1889,6 +1930,9 @@ class Client {
|
|
|
1889
1930
|
if (run.outputs) {
|
|
1890
1931
|
run.outputs = await this.processOutputs(run.outputs);
|
|
1891
1932
|
}
|
|
1933
|
+
if (run.error) {
|
|
1934
|
+
run.error = await this.processError(run.error);
|
|
1935
|
+
}
|
|
1892
1936
|
if (run.extra != null && "metadata" in run.extra) {
|
|
1893
1937
|
run.extra = {
|
|
1894
1938
|
...run.extra,
|
package/dist/client.d.ts
CHANGED
|
@@ -5,6 +5,9 @@ import { type TracingMode } from "./utils/env.js";
|
|
|
5
5
|
import { EvaluationResult, EvaluationResults } from "./evaluation/evaluator.js";
|
|
6
6
|
import { OnlineEvaluators } from "./_openapi_client/resources/online-evaluators.js";
|
|
7
7
|
import { Runs as OpenAPIRuns } from "./_openapi_client/resources/runs.js";
|
|
8
|
+
import { Sandboxes } from "./_openapi_client/resources/sandboxes/sandboxes.js";
|
|
9
|
+
import { Datasets } from "./_openapi_client/resources/datasets/datasets.js";
|
|
10
|
+
import { Sessions } from "./_openapi_client/resources/sessions.js";
|
|
8
11
|
import { PromptCache } from "./utils/prompt_cache/index.js";
|
|
9
12
|
import { ProfileAuth } from "./utils/profiles.js";
|
|
10
13
|
export interface ClientConfig {
|
|
@@ -13,6 +16,14 @@ export interface ClientConfig {
|
|
|
13
16
|
callerOptions?: AsyncCallerParams;
|
|
14
17
|
timeout_ms?: number;
|
|
15
18
|
webUrl?: string;
|
|
19
|
+
/**
|
|
20
|
+
* A function applied for masking serialized run inputs and outputs,
|
|
21
|
+
* before sending to the API. Can be called with raw inputs, raw
|
|
22
|
+
* outputs, or a nested `{ error: string }` object for errors.
|
|
23
|
+
*
|
|
24
|
+
* If a `hideInputs` or `hideOutputs` function is present,
|
|
25
|
+
* the client will call it instead of the anonymizer as appropriate.
|
|
26
|
+
*/
|
|
16
27
|
anonymizer?: (values: KVMap) => KVMap | Promise<KVMap>;
|
|
17
28
|
hideInputs?: boolean | ((inputs: KVMap) => KVMap | Promise<KVMap>);
|
|
18
29
|
hideOutputs?: boolean | ((outputs: KVMap) => KVMap | Promise<KVMap>);
|
|
@@ -429,6 +440,7 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
429
440
|
private hideInputs?;
|
|
430
441
|
private hideOutputs?;
|
|
431
442
|
private hideMetadata?;
|
|
443
|
+
private anonymizer?;
|
|
432
444
|
private omitTracedRuntimeInfo?;
|
|
433
445
|
private tracingSampleRate?;
|
|
434
446
|
private filteredPostUuids;
|
|
@@ -504,9 +516,28 @@ export declare class Client implements LangSmithTracingClientInterface {
|
|
|
504
516
|
private _getPlatformEndpointPath;
|
|
505
517
|
get onlineEvaluators(): OnlineEvaluators;
|
|
506
518
|
get runs(): OpenAPIRuns;
|
|
519
|
+
/** Access the v2 sandboxes resource (registries, snapshots, boxes). */
|
|
520
|
+
get sandboxes(): Sandboxes;
|
|
521
|
+
/** Access the projects resource. */
|
|
522
|
+
get projects(): Sessions;
|
|
523
|
+
/** Access the v2 datasets resource (experimentRuns, etc.). */
|
|
524
|
+
get datasets(): Datasets;
|
|
507
525
|
private processInputs;
|
|
508
526
|
private processOutputs;
|
|
509
527
|
private processMetadata;
|
|
528
|
+
/**
|
|
529
|
+
* Apply the configured anonymizer to a run's error string.
|
|
530
|
+
*
|
|
531
|
+
* Unlike inputs/outputs, `error` is a plain string (an exception message or
|
|
532
|
+
* traceback) that can carry credentials the user never explicitly logged --
|
|
533
|
+
* e.g. an HTTP-client error whose message embeds an `Authorization` header.
|
|
534
|
+
* The anonymizer is typed `(KVMap) => KVMap`, so the string is wrapped as
|
|
535
|
+
* `{ error }`, scrubbed, and unwrapped. Mirrors the Python SDK's
|
|
536
|
+
* `Client._hide_run_error`.
|
|
537
|
+
*
|
|
538
|
+
* TODO: Update anonymizer to always nest inputs/outputs/error for consistency
|
|
539
|
+
*/
|
|
540
|
+
private processError;
|
|
510
541
|
/**
|
|
511
542
|
* Filter content from new_token events to prevent streaming LLM output
|
|
512
543
|
* from being uploaded via events.
|
package/dist/client.js
CHANGED
|
@@ -504,6 +504,12 @@ export class Client {
|
|
|
504
504
|
writable: true,
|
|
505
505
|
value: void 0
|
|
506
506
|
});
|
|
507
|
+
Object.defineProperty(this, "anonymizer", {
|
|
508
|
+
enumerable: true,
|
|
509
|
+
configurable: true,
|
|
510
|
+
writable: true,
|
|
511
|
+
value: void 0
|
|
512
|
+
});
|
|
507
513
|
Object.defineProperty(this, "omitTracedRuntimeInfo", {
|
|
508
514
|
enumerable: true,
|
|
509
515
|
configurable: true,
|
|
@@ -755,6 +761,7 @@ export class Client {
|
|
|
755
761
|
this.hideOutputs =
|
|
756
762
|
config.hideOutputs ?? config.anonymizer ?? defaultConfig.hideOutputs;
|
|
757
763
|
this.hideMetadata = config.hideMetadata ?? defaultConfig.hideMetadata;
|
|
764
|
+
this.anonymizer = config.anonymizer;
|
|
758
765
|
this.omitTracedRuntimeInfo = config.omitTracedRuntimeInfo ?? false;
|
|
759
766
|
this.autoBatchTracing = config.autoBatchTracing ?? this.autoBatchTracing;
|
|
760
767
|
this.autoBatchQueue = new AutoBatchQueue(maxMemory);
|
|
@@ -932,6 +939,18 @@ export class Client {
|
|
|
932
939
|
get runs() {
|
|
933
940
|
return this.openAPIClient.runs;
|
|
934
941
|
}
|
|
942
|
+
/** Access the v2 sandboxes resource (registries, snapshots, boxes). */
|
|
943
|
+
get sandboxes() {
|
|
944
|
+
return this.openAPIClient.sandboxes;
|
|
945
|
+
}
|
|
946
|
+
/** Access the projects resource. */
|
|
947
|
+
get projects() {
|
|
948
|
+
return this.openAPIClient.sessions;
|
|
949
|
+
}
|
|
950
|
+
/** Access the v2 datasets resource (experimentRuns, etc.). */
|
|
951
|
+
get datasets() {
|
|
952
|
+
return this.openAPIClient.datasets;
|
|
953
|
+
}
|
|
935
954
|
async processInputs(inputs) {
|
|
936
955
|
if (this.hideInputs === false) {
|
|
937
956
|
return inputs;
|
|
@@ -968,6 +987,25 @@ export class Client {
|
|
|
968
987
|
}
|
|
969
988
|
return metadata;
|
|
970
989
|
}
|
|
990
|
+
/**
|
|
991
|
+
* Apply the configured anonymizer to a run's error string.
|
|
992
|
+
*
|
|
993
|
+
* Unlike inputs/outputs, `error` is a plain string (an exception message or
|
|
994
|
+
* traceback) that can carry credentials the user never explicitly logged --
|
|
995
|
+
* e.g. an HTTP-client error whose message embeds an `Authorization` header.
|
|
996
|
+
* The anonymizer is typed `(KVMap) => KVMap`, so the string is wrapped as
|
|
997
|
+
* `{ error }`, scrubbed, and unwrapped. Mirrors the Python SDK's
|
|
998
|
+
* `Client._hide_run_error`.
|
|
999
|
+
*
|
|
1000
|
+
* TODO: Update anonymizer to always nest inputs/outputs/error for consistency
|
|
1001
|
+
*/
|
|
1002
|
+
async processError(error) {
|
|
1003
|
+
if (this.anonymizer == null) {
|
|
1004
|
+
return error;
|
|
1005
|
+
}
|
|
1006
|
+
const result = await this.anonymizer({ error });
|
|
1007
|
+
return typeof result?.error === "string" ? result.error : error;
|
|
1008
|
+
}
|
|
971
1009
|
/**
|
|
972
1010
|
* Filter content from new_token events to prevent streaming LLM output
|
|
973
1011
|
* from being uploaded via events.
|
|
@@ -994,6 +1032,9 @@ export class Client {
|
|
|
994
1032
|
if (runParams.outputs !== undefined) {
|
|
995
1033
|
runParams.outputs = await this.processOutputs(runParams.outputs);
|
|
996
1034
|
}
|
|
1035
|
+
if (runParams.error !== undefined) {
|
|
1036
|
+
runParams.error = await this.processError(runParams.error);
|
|
1037
|
+
}
|
|
997
1038
|
if (runParams.extra != null && "metadata" in runParams.extra) {
|
|
998
1039
|
runParams.extra = {
|
|
999
1040
|
...runParams.extra,
|
|
@@ -1850,6 +1891,9 @@ export class Client {
|
|
|
1850
1891
|
if (run.outputs) {
|
|
1851
1892
|
run.outputs = await this.processOutputs(run.outputs);
|
|
1852
1893
|
}
|
|
1894
|
+
if (run.error) {
|
|
1895
|
+
run.error = await this.processError(run.error);
|
|
1896
|
+
}
|
|
1853
1897
|
if (run.extra != null && "metadata" in run.extra) {
|
|
1854
1898
|
run.extra = {
|
|
1855
1899
|
...run.extra,
|
|
@@ -136,7 +136,11 @@ class StreamManager {
|
|
|
136
136
|
}
|
|
137
137
|
this.namespaces["root"].extra ??= {};
|
|
138
138
|
this.namespaces["root"].extra.metadata ??= {};
|
|
139
|
-
|
|
139
|
+
// Keep the SDK's final aggregate usage available for inspection, but do not
|
|
140
|
+
// store it as `usage_metadata` on the parent chain. LangSmith rollups
|
|
141
|
+
// already aggregate child LLM usage, so parent `usage_metadata` would be
|
|
142
|
+
// counted again (notably doubling Anthropic cache-read/cache-write tokens).
|
|
143
|
+
this.namespaces["root"].extra.metadata.ls_aggregated_usage = usage;
|
|
140
144
|
this.namespaces["root"].extra.metadata.is_error = message.is_error;
|
|
141
145
|
this.namespaces["root"].extra.metadata.num_turns = message.num_turns;
|
|
142
146
|
this.namespaces["root"].extra.metadata.session_id = message.session_id;
|
|
@@ -133,7 +133,11 @@ export class StreamManager {
|
|
|
133
133
|
}
|
|
134
134
|
this.namespaces["root"].extra ??= {};
|
|
135
135
|
this.namespaces["root"].extra.metadata ??= {};
|
|
136
|
-
|
|
136
|
+
// Keep the SDK's final aggregate usage available for inspection, but do not
|
|
137
|
+
// store it as `usage_metadata` on the parent chain. LangSmith rollups
|
|
138
|
+
// already aggregate child LLM usage, so parent `usage_metadata` would be
|
|
139
|
+
// counted again (notably doubling Anthropic cache-read/cache-write tokens).
|
|
140
|
+
this.namespaces["root"].extra.metadata.ls_aggregated_usage = usage;
|
|
137
141
|
this.namespaces["root"].extra.metadata.is_error = message.is_error;
|
|
138
142
|
this.namespaces["root"].extra.metadata.num_turns = message.num_turns;
|
|
139
143
|
this.namespaces["root"].extra.metadata.session_id = message.session_id;
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,6 @@ Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function
|
|
|
20
20
|
Object.defineProperty(exports, "configureGlobalPromptCache", { enumerable: true, get: function () { return index_js_1.configureGlobalPromptCache; } });
|
|
21
21
|
Object.defineProperty(exports, "promptCacheSingleton", { enumerable: true, get: function () { return index_js_1.promptCacheSingleton; } });
|
|
22
22
|
// Update using pnpm bump-version
|
|
23
|
-
exports.__version__ = "0.7.
|
|
23
|
+
exports.__version__ = "0.7.14";
|
|
24
24
|
// Metadata key to hide a traced run from LangSmith's Messages View.
|
|
25
25
|
exports.LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export { getDefaultProjectName } from "./utils/project.js";
|
|
|
6
6
|
export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
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
|
-
export declare const __version__ = "0.7.
|
|
9
|
+
export declare const __version__ = "0.7.14";
|
|
10
10
|
export declare const LS_MESSAGE_VIEW_EXCLUDE: "ls_message_view_exclude";
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,6 @@ export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
|
6
6
|
export { isTracingEnabled } from "./utils/guard.js";
|
|
7
7
|
export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
8
8
|
// Update using pnpm bump-version
|
|
9
|
-
export const __version__ = "0.7.
|
|
9
|
+
export const __version__ = "0.7.14";
|
|
10
10
|
// Metadata key to hide a traced run from LangSmith's Messages View.
|
|
11
11
|
export const LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
|
package/dist/sandbox/client.cjs
CHANGED
|
@@ -7,11 +7,12 @@ exports.SandboxClient = void 0;
|
|
|
7
7
|
const env_js_1 = require("../utils/env.cjs");
|
|
8
8
|
const fetch_js_1 = require("../singletons/fetch.cjs");
|
|
9
9
|
const async_caller_js_1 = require("../utils/async_caller.cjs");
|
|
10
|
+
const index_js_1 = require("../_openapi_client/index.cjs");
|
|
10
11
|
const sandbox_js_1 = require("./sandbox.cjs");
|
|
11
12
|
const errors_js_1 = require("./errors.cjs");
|
|
12
13
|
const helpers_js_1 = require("./helpers.cjs");
|
|
13
14
|
const mounts_js_1 = require("./mounts.cjs");
|
|
14
|
-
const
|
|
15
|
+
const index_js_2 = require("../utils/uuid/src/index.cjs");
|
|
15
16
|
/**
|
|
16
17
|
* Sleep that can be interrupted by an AbortSignal.
|
|
17
18
|
* Resolves after `ms` milliseconds or rejects immediately if the signal fires.
|
|
@@ -296,6 +297,12 @@ class SandboxClient {
|
|
|
296
297
|
writable: true,
|
|
297
298
|
value: void 0
|
|
298
299
|
});
|
|
300
|
+
Object.defineProperty(this, "_registriesClient", {
|
|
301
|
+
enumerable: true,
|
|
302
|
+
configurable: true,
|
|
303
|
+
writable: true,
|
|
304
|
+
value: void 0
|
|
305
|
+
});
|
|
299
306
|
this._baseUrl = (config.apiEndpoint ?? getDefaultApiEndpoint()).replace(/\/$/, "");
|
|
300
307
|
this._apiKey = config.apiKey ?? getDefaultApiKey();
|
|
301
308
|
this._defaultHeaders = { ...(config.headers ?? {}) };
|
|
@@ -305,6 +312,51 @@ class SandboxClient {
|
|
|
305
312
|
maxConcurrency: config.maxConcurrency ?? Infinity,
|
|
306
313
|
});
|
|
307
314
|
}
|
|
315
|
+
_apiRoot() {
|
|
316
|
+
const suffix = "/v2/sandboxes";
|
|
317
|
+
return this._baseUrl.endsWith(suffix)
|
|
318
|
+
? this._baseUrl.slice(0, -suffix.length)
|
|
319
|
+
: this._baseUrl;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Manage sandbox image registries: create, list, retrieve, update, delete.
|
|
323
|
+
*
|
|
324
|
+
* A registry stores credentials for pulling private images. Create one, then
|
|
325
|
+
* pass its `id` as `registryId` when building a snapshot.
|
|
326
|
+
*
|
|
327
|
+
* @example
|
|
328
|
+
* ```typescript
|
|
329
|
+
* const registry = await client.registries.create({
|
|
330
|
+
* name: "internal",
|
|
331
|
+
* url: "registry.example.com",
|
|
332
|
+
* username: "robot",
|
|
333
|
+
* password: process.env.REGISTRY_PASSWORD,
|
|
334
|
+
* });
|
|
335
|
+
* const snapshot = await client.createSnapshot(
|
|
336
|
+
* "internal-python",
|
|
337
|
+
* "registry.example.com/internal/python:3.12",
|
|
338
|
+
* 2_147_483_648,
|
|
339
|
+
* { registryId: registry.id },
|
|
340
|
+
* );
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
get registries() {
|
|
344
|
+
if (!this._registriesClient) {
|
|
345
|
+
const defaultHeaders = {
|
|
346
|
+
...this._defaultHeaders,
|
|
347
|
+
};
|
|
348
|
+
if (this._apiKey === undefined) {
|
|
349
|
+
defaultHeaders["X-API-Key"] = null;
|
|
350
|
+
}
|
|
351
|
+
this._registriesClient = new index_js_1.Langsmith({
|
|
352
|
+
apiKey: this._apiKey,
|
|
353
|
+
baseURL: this._apiRoot(),
|
|
354
|
+
defaultHeaders,
|
|
355
|
+
fetch: this._fetchImpl,
|
|
356
|
+
});
|
|
357
|
+
}
|
|
358
|
+
return this._registriesClient.sandboxes.registries;
|
|
359
|
+
}
|
|
308
360
|
/**
|
|
309
361
|
* Internal fetch method that adds authentication headers.
|
|
310
362
|
*
|
|
@@ -619,11 +671,11 @@ class SandboxClient {
|
|
|
619
671
|
* @param name - Snapshot name.
|
|
620
672
|
* @param dockerImage - Docker image to build from (e.g., "python:3.12-slim").
|
|
621
673
|
* @param fsCapacityBytes - Filesystem capacity in bytes.
|
|
622
|
-
* @param options - Additional options (registry
|
|
674
|
+
* @param options - Additional options (registry ID, timeout).
|
|
623
675
|
* @returns Snapshot in "ready" status.
|
|
624
676
|
*/
|
|
625
677
|
async createSnapshot(name, dockerImage, fsCapacityBytes, options = {}) {
|
|
626
|
-
const { registryId,
|
|
678
|
+
const { registryId, timeout = 60, signal } = options;
|
|
627
679
|
const url = `${this._baseUrl}/snapshots`;
|
|
628
680
|
const payload = {
|
|
629
681
|
name,
|
|
@@ -633,15 +685,6 @@ class SandboxClient {
|
|
|
633
685
|
if (registryId !== undefined) {
|
|
634
686
|
payload.registry_id = registryId;
|
|
635
687
|
}
|
|
636
|
-
if (registryUrl !== undefined) {
|
|
637
|
-
payload.registry_url = registryUrl;
|
|
638
|
-
}
|
|
639
|
-
if (registryUsername !== undefined) {
|
|
640
|
-
payload.registry_username = registryUsername;
|
|
641
|
-
}
|
|
642
|
-
if (registryPassword !== undefined) {
|
|
643
|
-
payload.registry_password = registryPassword;
|
|
644
|
-
}
|
|
645
688
|
const response = await this._postJson(url, payload, { signal });
|
|
646
689
|
const snapshot = (await response.json());
|
|
647
690
|
return this.waitForSnapshot(snapshot.id, { timeout, signal });
|
|
@@ -663,18 +706,18 @@ class SandboxClient {
|
|
|
663
706
|
async createSnapshotFromDockerfile(name, dockerfile, fsCapacityBytes, options = {}) {
|
|
664
707
|
const { context = ".", buildArgs, target, onBuildLog, vCpus, memBytes, timeout = 60, } = options;
|
|
665
708
|
const { contextPath, dockerfileRel } = await resolveDockerfileContext(dockerfile, context);
|
|
666
|
-
const builderName = `snapshot-builder-${(0,
|
|
709
|
+
const builderName = `snapshot-builder-${(0, index_js_2.v4)().replace(/-/g, "").slice(0, 12)}`;
|
|
667
710
|
// Stage the build on the capacity-backed root filesystem, not /tmp.
|
|
668
711
|
// Inside the sandbox /tmp is a RAM-backed tmpfs that fsCapacityBytes does
|
|
669
712
|
// not size, and BuildKit's native snapshotter writes a full copy of every
|
|
670
713
|
// layer under its root, so a /tmp build exhausts guest RAM and fails with
|
|
671
714
|
// "No space left on device".
|
|
672
|
-
const buildRoot = `/var/lib/langsmith-build/${(0,
|
|
715
|
+
const buildRoot = `/var/lib/langsmith-build/${(0, index_js_2.v4)()
|
|
673
716
|
.replace(/-/g, "")
|
|
674
717
|
.slice(0, 12)}`;
|
|
675
718
|
const remoteContext = `${buildRoot}/context`;
|
|
676
719
|
const remoteTar = `${buildRoot}/context.tar`;
|
|
677
|
-
const imageRef = `langsmith-snapshot-build:${(0,
|
|
720
|
+
const imageRef = `langsmith-snapshot-build:${(0, index_js_2.v4)().replace(/-/g, "")}`;
|
|
678
721
|
const buildkitRoot = `${buildRoot}/buildkit-root`;
|
|
679
722
|
const buildkitRun = `${buildRoot}/buildkit-run`;
|
|
680
723
|
const builder = await this.createSandbox({
|
package/dist/sandbox/client.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Main SandboxClient class for interacting with the sandbox server API.
|
|
3
3
|
*/
|
|
4
|
+
import { Registries } from "../_openapi_client/resources/sandboxes/registries.js";
|
|
4
5
|
import type { CaptureSnapshotOptions, CreateDockerfileSnapshotOptions, CreateSandboxOptions, CreateSnapshotOptions, ListSnapshotsOptions, ResourceStatus, SandboxClientConfig, Snapshot, StartSandboxOptions, UpdateSandboxOptions, WaitForSandboxOptions, WaitForSnapshotOptions } from "./types.js";
|
|
5
6
|
import { Sandbox } from "./sandbox.js";
|
|
6
7
|
/**
|
|
@@ -37,7 +38,32 @@ export declare class SandboxClient {
|
|
|
37
38
|
private _defaultHeaders;
|
|
38
39
|
private _fetchImpl;
|
|
39
40
|
private _caller;
|
|
41
|
+
private _registriesClient?;
|
|
40
42
|
constructor(config?: SandboxClientConfig);
|
|
43
|
+
private _apiRoot;
|
|
44
|
+
/**
|
|
45
|
+
* Manage sandbox image registries: create, list, retrieve, update, delete.
|
|
46
|
+
*
|
|
47
|
+
* A registry stores credentials for pulling private images. Create one, then
|
|
48
|
+
* pass its `id` as `registryId` when building a snapshot.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* const registry = await client.registries.create({
|
|
53
|
+
* name: "internal",
|
|
54
|
+
* url: "registry.example.com",
|
|
55
|
+
* username: "robot",
|
|
56
|
+
* password: process.env.REGISTRY_PASSWORD,
|
|
57
|
+
* });
|
|
58
|
+
* const snapshot = await client.createSnapshot(
|
|
59
|
+
* "internal-python",
|
|
60
|
+
* "registry.example.com/internal/python:3.12",
|
|
61
|
+
* 2_147_483_648,
|
|
62
|
+
* { registryId: registry.id },
|
|
63
|
+
* );
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
get registries(): Registries;
|
|
41
67
|
/**
|
|
42
68
|
* Create a new Sandbox.
|
|
43
69
|
*
|
|
@@ -169,7 +195,7 @@ export declare class SandboxClient {
|
|
|
169
195
|
* @param name - Snapshot name.
|
|
170
196
|
* @param dockerImage - Docker image to build from (e.g., "python:3.12-slim").
|
|
171
197
|
* @param fsCapacityBytes - Filesystem capacity in bytes.
|
|
172
|
-
* @param options - Additional options (registry
|
|
198
|
+
* @param options - Additional options (registry ID, timeout).
|
|
173
199
|
* @returns Snapshot in "ready" status.
|
|
174
200
|
*/
|
|
175
201
|
createSnapshot(name: string, dockerImage: string, fsCapacityBytes: number, options?: CreateSnapshotOptions): Promise<Snapshot>;
|