langsmith 0.10.8 → 0.10.9
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 +26 -2
- package/dist/_openapi_client/client.d.ts +15 -6
- package/dist/_openapi_client/client.js +27 -3
- package/dist/_openapi_client/internal/detect-platform.cjs +1 -1
- package/dist/_openapi_client/internal/detect-platform.js +1 -1
- package/dist/_openapi_client/resources/annotation-queues/items.cjs +13 -6
- package/dist/_openapi_client/resources/annotation-queues/items.d.ts +33 -8
- package/dist/_openapi_client/resources/annotation-queues/items.js +13 -6
- package/dist/_openapi_client/resources/datasets/datasets.cjs +9 -0
- package/dist/_openapi_client/resources/datasets/datasets.d.ts +4 -0
- package/dist/_openapi_client/resources/datasets/datasets.js +9 -0
- package/dist/_openapi_client/resources/datasets/examples.cjs +26 -0
- package/dist/_openapi_client/resources/datasets/examples.d.ts +23 -0
- package/dist/_openapi_client/resources/datasets/examples.js +22 -0
- package/dist/_openapi_client/resources/fleet/fleet.cjs +54 -0
- package/dist/_openapi_client/resources/fleet/fleet.d.ts +9 -0
- package/dist/_openapi_client/resources/fleet/fleet.js +17 -0
- package/dist/_openapi_client/resources/fleet/threads.cjs +18 -0
- package/dist/_openapi_client/resources/fleet/threads.d.ts +19 -0
- package/dist/_openapi_client/resources/fleet/threads.js +14 -0
- package/dist/_openapi_client/resources/index.cjs +8 -2
- package/dist/_openapi_client/resources/index.d.ts +6 -3
- package/dist/_openapi_client/resources/index.js +5 -2
- package/dist/_openapi_client/resources/info.d.ts +6 -0
- package/dist/_openapi_client/resources/issues.cjs +2 -2
- package/dist/_openapi_client/resources/issues.d.ts +188 -4
- package/dist/_openapi_client/resources/issues.js +2 -2
- package/dist/_openapi_client/resources/online-evaluators.cjs +7 -4
- package/dist/_openapi_client/resources/online-evaluators.d.ts +63 -4
- package/dist/_openapi_client/resources/online-evaluators.js +7 -4
- package/dist/_openapi_client/resources/product-feedback.cjs +33 -0
- package/dist/_openapi_client/resources/product-feedback.d.ts +77 -0
- package/dist/_openapi_client/resources/product-feedback.js +29 -0
- package/dist/_openapi_client/resources/runs/runs.d.ts +26 -16
- package/dist/_openapi_client/resources/sandboxes/boxes.cjs +44 -4
- package/dist/_openapi_client/resources/sandboxes/boxes.d.ts +256 -21
- package/dist/_openapi_client/resources/sandboxes/boxes.js +44 -4
- package/dist/_openapi_client/resources/sandboxes/registries.d.ts +10 -2
- package/dist/_openapi_client/resources/sandboxes/sandboxes.cjs +13 -0
- package/dist/_openapi_client/resources/sandboxes/sandboxes.d.ts +169 -14
- package/dist/_openapi_client/resources/sandboxes/sandboxes.js +13 -0
- package/dist/_openapi_client/resources/sandboxes/snapshots.cjs +10 -6
- package/dist/_openapi_client/resources/sandboxes/snapshots.d.ts +37 -6
- package/dist/_openapi_client/resources/sandboxes/snapshots.js +10 -6
- package/dist/_openapi_client/resources/sessions.cjs +23 -0
- package/dist/_openapi_client/resources/sessions.d.ts +732 -0
- package/dist/_openapi_client/resources/sessions.js +19 -0
- package/dist/_openapi_client/resources/threads/index.cjs +9 -0
- package/dist/_openapi_client/resources/threads/index.d.ts +2 -0
- package/dist/_openapi_client/resources/threads/index.js +4 -0
- package/dist/_openapi_client/resources/threads/share.cjs +61 -0
- package/dist/_openapi_client/resources/threads/share.d.ts +71 -0
- package/dist/_openapi_client/resources/threads/share.js +57 -0
- package/dist/_openapi_client/resources/threads/threads.cjs +143 -0
- package/dist/_openapi_client/resources/threads/threads.d.ts +973 -0
- package/dist/_openapi_client/resources/threads/threads.js +106 -0
- package/dist/_openapi_client/resources/threads.cjs +15 -67
- package/dist/_openapi_client/resources/threads.d.ts +1 -709
- package/dist/_openapi_client/resources/threads.js +1 -65
- package/dist/_openapi_client/resources/traces.d.ts +7 -1
- package/dist/_openapi_client/version.cjs +1 -1
- package/dist/_openapi_client/version.js +1 -1
- package/dist/address.cjs +160 -59
- package/dist/address.d.ts +59 -26
- package/dist/address.js +154 -55
- package/dist/anonymizer/index.cjs +1 -1
- package/dist/anonymizer/index.js +1 -1
- package/dist/client.cjs +39 -19
- package/dist/client.d.ts +20 -4
- package/dist/client.js +34 -14
- package/dist/index.cjs +5 -3
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/run_trees.cjs +18 -21
- package/dist/run_trees.d.ts +4 -4
- package/dist/run_trees.js +15 -18
- package/dist/sandbox/client.cjs +33 -4
- package/dist/sandbox/client.d.ts +4 -0
- package/dist/sandbox/client.js +34 -5
- package/dist/sandbox/command_handle.cjs +8 -0
- package/dist/sandbox/command_handle.js +8 -0
- package/dist/sandbox/sandbox.cjs +7 -0
- package/dist/sandbox/sandbox.js +7 -0
- package/dist/sandbox/service_url.cjs +9 -1
- package/dist/sandbox/service_url.d.ts +2 -1
- package/dist/sandbox/service_url.js +9 -1
- package/dist/sandbox/tracing.cjs +13 -0
- package/dist/sandbox/tracing.d.ts +1 -0
- package/dist/sandbox/tracing.js +10 -0
- package/dist/schemas.d.ts +3 -3
- package/dist/traceable.cjs +5 -4
- package/dist/traceable.js +4 -3
- package/dist/utils/{agent_addressing.cjs → addressing.cjs} +20 -11
- package/dist/utils/{agent_addressing.d.ts → addressing.d.ts} +4 -6
- package/dist/utils/{agent_addressing.js → addressing.js} +21 -11
- package/dist/utils/env.cjs +6 -4
- package/dist/utils/env.js +6 -4
- package/package.json +1 -1
package/dist/sandbox/sandbox.cjs
CHANGED
|
@@ -8,6 +8,7 @@ const uuid_js_1 = require("../uuid.cjs");
|
|
|
8
8
|
const errors_js_1 = require("./errors.cjs");
|
|
9
9
|
const helpers_js_1 = require("./helpers.cjs");
|
|
10
10
|
const command_handle_js_1 = require("./command_handle.cjs");
|
|
11
|
+
const tracing_js_1 = require("./tracing.cjs");
|
|
11
12
|
const ws_execute_js_1 = require("./ws_execute.cjs");
|
|
12
13
|
/**
|
|
13
14
|
* Represents an active sandbox for running commands and file operations.
|
|
@@ -195,6 +196,7 @@ class Sandbox {
|
|
|
195
196
|
* @throws LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.
|
|
196
197
|
*/
|
|
197
198
|
requireDataplaneUrl() {
|
|
199
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
198
200
|
if (!this.dataplane_url) {
|
|
199
201
|
throw new errors_js_1.LangSmithDataplaneNotConfiguredError(`Sandbox '${this.name}' does not have a dataplane_url configured. ` +
|
|
200
202
|
"Runtime operations require a dataplane URL.");
|
|
@@ -593,6 +595,7 @@ class Sandbox {
|
|
|
593
595
|
* ```
|
|
594
596
|
*/
|
|
595
597
|
async generateDownloadURL(path, options = {}) {
|
|
598
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
596
599
|
return this._client.generateDownloadURL(this.name, path, options);
|
|
597
600
|
}
|
|
598
601
|
/**
|
|
@@ -609,6 +612,7 @@ class Sandbox {
|
|
|
609
612
|
* ```
|
|
610
613
|
*/
|
|
611
614
|
async delete() {
|
|
615
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
612
616
|
await this._client.deleteSandbox(this.name);
|
|
613
617
|
}
|
|
614
618
|
/**
|
|
@@ -619,6 +623,7 @@ class Sandbox {
|
|
|
619
623
|
* @param timeout - Timeout in seconds when waiting for ready. Default: 120.
|
|
620
624
|
*/
|
|
621
625
|
async start(options = {}) {
|
|
626
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
622
627
|
const refreshed = await this._client.startSandbox(this.name, options);
|
|
623
628
|
this.status = refreshed.status;
|
|
624
629
|
this.dataplane_url = refreshed.dataplane_url;
|
|
@@ -627,6 +632,7 @@ class Sandbox {
|
|
|
627
632
|
* Stop a running sandbox (preserves sandbox files for later restart).
|
|
628
633
|
*/
|
|
629
634
|
async stop() {
|
|
635
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
630
636
|
await this._client.stopSandbox(this.name);
|
|
631
637
|
// dataplane_url stays set: it is stable across stop/start and a request on
|
|
632
638
|
// it resumes the sandbox.
|
|
@@ -640,6 +646,7 @@ class Sandbox {
|
|
|
640
646
|
* @returns Snapshot in "ready" status.
|
|
641
647
|
*/
|
|
642
648
|
async captureSnapshot(name, options = {}) {
|
|
649
|
+
(0, tracing_js_1.addSandboxMetadata)(this.id);
|
|
643
650
|
return this._client.captureSnapshot(this.name, name, options);
|
|
644
651
|
}
|
|
645
652
|
}
|
package/dist/sandbox/sandbox.js
CHANGED
|
@@ -5,6 +5,7 @@ import { uuid7 } from "../uuid.js";
|
|
|
5
5
|
import { LangSmithDataplaneNotConfiguredError, LangSmithSandboxRetryableConnectionError, LangSmithStreamEndedBeforeStartedError, } from "./errors.js";
|
|
6
6
|
import { assertRunConfigNotCombined, buildRangeHeader, fileChunkFromResponse, fileStatFromResponse, handleFileHttpError, handleSandboxHttpError, resolveCloseInput, } from "./helpers.js";
|
|
7
7
|
import { CommandHandle } from "./command_handle.js";
|
|
8
|
+
import { addSandboxMetadata } from "./tracing.js";
|
|
8
9
|
import { connectDeadline, isWsAvailable, openTimeoutFor, reconnectWsStream, remainingBudget, runWsStream, } from "./ws_execute.js";
|
|
9
10
|
/**
|
|
10
11
|
* Represents an active sandbox for running commands and file operations.
|
|
@@ -192,6 +193,7 @@ export class Sandbox {
|
|
|
192
193
|
* @throws LangSmithDataplaneNotConfiguredError if dataplane_url is not configured.
|
|
193
194
|
*/
|
|
194
195
|
requireDataplaneUrl() {
|
|
196
|
+
addSandboxMetadata(this.id);
|
|
195
197
|
if (!this.dataplane_url) {
|
|
196
198
|
throw new LangSmithDataplaneNotConfiguredError(`Sandbox '${this.name}' does not have a dataplane_url configured. ` +
|
|
197
199
|
"Runtime operations require a dataplane URL.");
|
|
@@ -590,6 +592,7 @@ export class Sandbox {
|
|
|
590
592
|
* ```
|
|
591
593
|
*/
|
|
592
594
|
async generateDownloadURL(path, options = {}) {
|
|
595
|
+
addSandboxMetadata(this.id);
|
|
593
596
|
return this._client.generateDownloadURL(this.name, path, options);
|
|
594
597
|
}
|
|
595
598
|
/**
|
|
@@ -606,6 +609,7 @@ export class Sandbox {
|
|
|
606
609
|
* ```
|
|
607
610
|
*/
|
|
608
611
|
async delete() {
|
|
612
|
+
addSandboxMetadata(this.id);
|
|
609
613
|
await this._client.deleteSandbox(this.name);
|
|
610
614
|
}
|
|
611
615
|
/**
|
|
@@ -616,6 +620,7 @@ export class Sandbox {
|
|
|
616
620
|
* @param timeout - Timeout in seconds when waiting for ready. Default: 120.
|
|
617
621
|
*/
|
|
618
622
|
async start(options = {}) {
|
|
623
|
+
addSandboxMetadata(this.id);
|
|
619
624
|
const refreshed = await this._client.startSandbox(this.name, options);
|
|
620
625
|
this.status = refreshed.status;
|
|
621
626
|
this.dataplane_url = refreshed.dataplane_url;
|
|
@@ -624,6 +629,7 @@ export class Sandbox {
|
|
|
624
629
|
* Stop a running sandbox (preserves sandbox files for later restart).
|
|
625
630
|
*/
|
|
626
631
|
async stop() {
|
|
632
|
+
addSandboxMetadata(this.id);
|
|
627
633
|
await this._client.stopSandbox(this.name);
|
|
628
634
|
// dataplane_url stays set: it is stable across stop/start and a request on
|
|
629
635
|
// it resumes the sandbox.
|
|
@@ -637,6 +643,7 @@ export class Sandbox {
|
|
|
637
643
|
* @returns Snapshot in "ready" status.
|
|
638
644
|
*/
|
|
639
645
|
async captureSnapshot(name, options = {}) {
|
|
646
|
+
addSandboxMetadata(this.id);
|
|
640
647
|
return this._client.captureSnapshot(this.name, name, options);
|
|
641
648
|
}
|
|
642
649
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.ServiceLoginUrl = exports.ServiceUrl = exports.SERVICE_TOKEN_HEADER = void 0;
|
|
4
|
+
const tracing_js_1 = require("./tracing.cjs");
|
|
4
5
|
/** Header the sandbox router reads the minted service token from. */
|
|
5
6
|
exports.SERVICE_TOKEN_HEADER = "X-Langsmith-Sandbox-Service-Token";
|
|
6
7
|
/** Refresh this many seconds before the token actually expires. */
|
|
@@ -11,7 +12,13 @@ const REFRESH_MARGIN_SECONDS = 60;
|
|
|
11
12
|
* Accessors are async because a refresh is a network call.
|
|
12
13
|
*/
|
|
13
14
|
class ServiceUrl {
|
|
14
|
-
constructor(data, refresher) {
|
|
15
|
+
constructor(data, refresher, _sandboxId) {
|
|
16
|
+
Object.defineProperty(this, "_sandboxId", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
configurable: true,
|
|
19
|
+
writable: true,
|
|
20
|
+
value: _sandboxId
|
|
21
|
+
});
|
|
15
22
|
Object.defineProperty(this, "_browserUrl", {
|
|
16
23
|
enumerable: true,
|
|
17
24
|
configurable: true,
|
|
@@ -87,6 +94,7 @@ class ServiceUrl {
|
|
|
87
94
|
}
|
|
88
95
|
/** Fetch a path on the service with the token header injected. */
|
|
89
96
|
async fetch(path = "/", init = {}) {
|
|
97
|
+
(0, tracing_js_1.addSandboxMetadata)(this._sandboxId);
|
|
90
98
|
const base = (await this.serviceUrl()).replace(/\/+$/, "");
|
|
91
99
|
const url = `${base}/${path.replace(/^\/+/, "")}`;
|
|
92
100
|
const headers = new Headers(init.headers);
|
|
@@ -15,12 +15,13 @@ export interface ServiceUrlData {
|
|
|
15
15
|
* Accessors are async because a refresh is a network call.
|
|
16
16
|
*/
|
|
17
17
|
export declare class ServiceUrl {
|
|
18
|
+
private readonly _sandboxId?;
|
|
18
19
|
private _browserUrl;
|
|
19
20
|
private _serviceUrl;
|
|
20
21
|
private _token;
|
|
21
22
|
private _expiresAt;
|
|
22
23
|
private readonly _refresher?;
|
|
23
|
-
constructor(data: ServiceUrlData, refresher?: () => Promise<ServiceUrl
|
|
24
|
+
constructor(data: ServiceUrlData, refresher?: () => Promise<ServiceUrl>, _sandboxId?: string | undefined);
|
|
24
25
|
private _shouldRefresh;
|
|
25
26
|
private _maybeRefresh;
|
|
26
27
|
/** The signed token, refreshed if near expiry. */
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { addSandboxMetadata } from "./tracing.js";
|
|
1
2
|
/** Header the sandbox router reads the minted service token from. */
|
|
2
3
|
export const SERVICE_TOKEN_HEADER = "X-Langsmith-Sandbox-Service-Token";
|
|
3
4
|
/** Refresh this many seconds before the token actually expires. */
|
|
@@ -8,7 +9,13 @@ const REFRESH_MARGIN_SECONDS = 60;
|
|
|
8
9
|
* Accessors are async because a refresh is a network call.
|
|
9
10
|
*/
|
|
10
11
|
export class ServiceUrl {
|
|
11
|
-
constructor(data, refresher) {
|
|
12
|
+
constructor(data, refresher, _sandboxId) {
|
|
13
|
+
Object.defineProperty(this, "_sandboxId", {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
configurable: true,
|
|
16
|
+
writable: true,
|
|
17
|
+
value: _sandboxId
|
|
18
|
+
});
|
|
12
19
|
Object.defineProperty(this, "_browserUrl", {
|
|
13
20
|
enumerable: true,
|
|
14
21
|
configurable: true,
|
|
@@ -84,6 +91,7 @@ export class ServiceUrl {
|
|
|
84
91
|
}
|
|
85
92
|
/** Fetch a path on the service with the token header injected. */
|
|
86
93
|
async fetch(path = "/", init = {}) {
|
|
94
|
+
addSandboxMetadata(this._sandboxId);
|
|
87
95
|
const base = (await this.serviceUrl()).replace(/\/+$/, "");
|
|
88
96
|
const url = `${base}/${path.replace(/^\/+/, "")}`;
|
|
89
97
|
const headers = new Headers(init.headers);
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.addSandboxMetadata = addSandboxMetadata;
|
|
4
|
+
const run_trees_js_1 = require("../run_trees.cjs");
|
|
5
|
+
const traceable_js_1 = require("../singletons/traceable.cjs");
|
|
6
|
+
function addSandboxMetadata(sandboxId) {
|
|
7
|
+
if (!sandboxId)
|
|
8
|
+
return;
|
|
9
|
+
const run = (0, traceable_js_1.getCurrentRunTree)(true);
|
|
10
|
+
if ((0, run_trees_js_1.isRunTree)(run)) {
|
|
11
|
+
run.metadata = { sandbox_id: sandboxId };
|
|
12
|
+
}
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function addSandboxMetadata(sandboxId?: string): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { isRunTree } from "../run_trees.js";
|
|
2
|
+
import { getCurrentRunTree } from "../singletons/traceable.js";
|
|
3
|
+
export function addSandboxMetadata(sandboxId) {
|
|
4
|
+
if (!sandboxId)
|
|
5
|
+
return;
|
|
6
|
+
const run = getCurrentRunTree(true);
|
|
7
|
+
if (isRunTree(run)) {
|
|
8
|
+
run.metadata = { sandbox_id: sandboxId };
|
|
9
|
+
}
|
|
10
|
+
}
|
package/dist/schemas.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AgentAddress } from "./address.js";
|
|
2
2
|
export interface TracerSession {
|
|
3
3
|
tenant_id: string;
|
|
4
4
|
id: string;
|
|
@@ -150,7 +150,7 @@ export interface RunCreate extends BaseRun {
|
|
|
150
150
|
revision_id?: string;
|
|
151
151
|
child_runs?: this[];
|
|
152
152
|
session_name?: string;
|
|
153
|
-
address?:
|
|
153
|
+
address?: AgentAddress;
|
|
154
154
|
}
|
|
155
155
|
export interface RunUpdate {
|
|
156
156
|
id?: string;
|
|
@@ -169,7 +169,7 @@ export interface RunUpdate {
|
|
|
169
169
|
events?: KVMap[];
|
|
170
170
|
session_id?: string;
|
|
171
171
|
session_name?: string;
|
|
172
|
-
address?:
|
|
172
|
+
address?: AgentAddress;
|
|
173
173
|
/** Unique ID assigned to every run within this nested trace. **/
|
|
174
174
|
trace_id?: string;
|
|
175
175
|
/**
|
package/dist/traceable.cjs
CHANGED
|
@@ -9,7 +9,8 @@ const traceable_js_1 = require("./singletons/traceable.cjs");
|
|
|
9
9
|
const constants_js_1 = require("./singletons/constants.cjs");
|
|
10
10
|
const asserts_js_1 = require("./utils/asserts.cjs");
|
|
11
11
|
const index_js_1 = require("./index.cjs");
|
|
12
|
-
const
|
|
12
|
+
const address_js_1 = require("./address.cjs");
|
|
13
|
+
const addressing_js_1 = require("./utils/addressing.cjs");
|
|
13
14
|
const otel_js_1 = require("./singletons/otel.cjs");
|
|
14
15
|
const utils_js_1 = require("./experimental/otel/utils.cjs");
|
|
15
16
|
const constants_js_2 = require("./experimental/otel/constants.cjs");
|
|
@@ -473,8 +474,8 @@ const convertSerializableArg = (arg, options) => {
|
|
|
473
474
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
474
475
|
function traceable(wrappedFunc, config) {
|
|
475
476
|
const { aggregator, argsConfigPath, __finalTracedIteratorKey, processInputs, processOutputs, extractAttachments, on_start, ...runTreeConfig } = config ?? {};
|
|
476
|
-
runTreeConfig.address = (0,
|
|
477
|
-
(0,
|
|
477
|
+
runTreeConfig.address = (0, address_js_1.ensureAgent)(runTreeConfig.address);
|
|
478
|
+
(0, addressing_js_1.rejectConflicting)(runTreeConfig.project_name, runTreeConfig.address);
|
|
478
479
|
const processInputsFn = processInputs ?? ((x) => x);
|
|
479
480
|
const processOutputsFn = processOutputs ?? ((x) => x);
|
|
480
481
|
const extractAttachmentsFn = extractAttachments ?? ((...x) => [undefined, runInputsToMap(x)]);
|
|
@@ -526,7 +527,7 @@ function traceable(wrappedFunc, config) {
|
|
|
526
527
|
runtimeConfig = undefined;
|
|
527
528
|
}
|
|
528
529
|
// Runtime config outranks decorator config, whichever mode each names.
|
|
529
|
-
[ensuredConfig.project_name, ensuredConfig.address] = (0,
|
|
530
|
+
[ensuredConfig.project_name, ensuredConfig.address] = (0, addressing_js_1.firstNamed)([runtimeConfig?.project_name, (0, address_js_1.ensureAgent)(runtimeConfig?.address)], [runTreeConfig.project_name, (0, address_js_1.ensureAgent)(runTreeConfig.address)]);
|
|
530
531
|
let runEndedPromiseResolver;
|
|
531
532
|
const runEndedPromise = new Promise((resolve) => {
|
|
532
533
|
runEndedPromiseResolver = resolve;
|
package/dist/traceable.js
CHANGED
|
@@ -5,7 +5,8 @@ import { ROOT, AsyncLocalStorageProviderSingleton, getCurrentRunTree, } from "./
|
|
|
5
5
|
import { _LC_CHILD_RUN_END_PROMISES_KEY, _LC_CONTEXT_VARIABLES_KEY, _PROCESSING_FAILED_KEY, _processingFailed, } from "./singletons/constants.js";
|
|
6
6
|
import { isKVMap, isReadableStream, isAsyncIterable, isIteratorLike, isThenable, isGenerator, isPromiseMethod, } from "./utils/asserts.js";
|
|
7
7
|
import { __version__ } from "./index.js";
|
|
8
|
-
import {
|
|
8
|
+
import { ensureAgent } from "./address.js";
|
|
9
|
+
import { firstNamed, rejectConflicting } from "./utils/addressing.js";
|
|
9
10
|
import { getOTELTrace, getOTELContext } from "./singletons/otel.js";
|
|
10
11
|
import { getUuidFromOtelSpanId } from "./experimental/otel/utils.js";
|
|
11
12
|
import { LANGSMITH_REFERENCE_EXAMPLE_ID, LANGSMITH_SESSION_NAME, LANGSMITH_TRACEABLE, } from "./experimental/otel/constants.js";
|
|
@@ -469,7 +470,7 @@ const convertSerializableArg = (arg, options) => {
|
|
|
469
470
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
470
471
|
export function traceable(wrappedFunc, config) {
|
|
471
472
|
const { aggregator, argsConfigPath, __finalTracedIteratorKey, processInputs, processOutputs, extractAttachments, on_start, ...runTreeConfig } = config ?? {};
|
|
472
|
-
runTreeConfig.address =
|
|
473
|
+
runTreeConfig.address = ensureAgent(runTreeConfig.address);
|
|
473
474
|
rejectConflicting(runTreeConfig.project_name, runTreeConfig.address);
|
|
474
475
|
const processInputsFn = processInputs ?? ((x) => x);
|
|
475
476
|
const processOutputsFn = processOutputs ?? ((x) => x);
|
|
@@ -522,7 +523,7 @@ export function traceable(wrappedFunc, config) {
|
|
|
522
523
|
runtimeConfig = undefined;
|
|
523
524
|
}
|
|
524
525
|
// Runtime config outranks decorator config, whichever mode each names.
|
|
525
|
-
[ensuredConfig.project_name, ensuredConfig.address] = firstNamed([runtimeConfig?.project_name,
|
|
526
|
+
[ensuredConfig.project_name, ensuredConfig.address] = firstNamed([runtimeConfig?.project_name, ensureAgent(runtimeConfig?.address)], [runTreeConfig.project_name, ensureAgent(runTreeConfig.address)]);
|
|
526
527
|
let runEndedPromiseResolver;
|
|
527
528
|
const runEndedPromise = new Promise((resolve) => {
|
|
528
529
|
runEndedPromiseResolver = resolve;
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.checkAddress = checkAddress;
|
|
4
3
|
exports.rejectConflicting = rejectConflicting;
|
|
5
4
|
exports.firstNamed = firstNamed;
|
|
6
5
|
exports.resolveFromEnv = resolveFromEnv;
|
|
@@ -10,14 +9,10 @@ exports.applyToPayload = applyToPayload;
|
|
|
10
9
|
const address_js_1 = require("../address.cjs");
|
|
11
10
|
const env_js_1 = require("./env.cjs");
|
|
12
11
|
const warn_js_1 = require("./warn.cjs");
|
|
13
|
-
/** Validate and normalise an address at an entry point; the SDK carries the result. */
|
|
14
|
-
function checkAddress(address) {
|
|
15
|
-
return address == null ? undefined : (0, address_js_1.parse)(address);
|
|
16
|
-
}
|
|
17
12
|
function rejectConflicting(project, address) {
|
|
18
13
|
if (project && address) {
|
|
19
14
|
throw new Error(`A run is sent to a project (${JSON.stringify(project)}) or to an ` +
|
|
20
|
-
|
|
15
|
+
"address, not both.");
|
|
21
16
|
}
|
|
22
17
|
}
|
|
23
18
|
/** The highest level naming a project or an address, whichever it names. */
|
|
@@ -41,7 +36,7 @@ function getEnvProject() {
|
|
|
41
36
|
*/
|
|
42
37
|
function resolveFromEnv() {
|
|
43
38
|
const project = getEnvProject();
|
|
44
|
-
const address =
|
|
39
|
+
const address = address_js_1.AgentAddress.fromEnv();
|
|
45
40
|
if (project && address) {
|
|
46
41
|
throw new address_js_1.EnvAddressError("LANGSMITH_AGENT_* and a project are both set in the environment.");
|
|
47
42
|
}
|
|
@@ -64,25 +59,39 @@ function warnOnEnv() {
|
|
|
64
59
|
}
|
|
65
60
|
}
|
|
66
61
|
/**
|
|
67
|
-
* Put the run's address in its payload field,
|
|
62
|
+
* Put the run's address in its payload field, in its wire form.
|
|
68
63
|
* Without one, a create naming no project takes the env address.
|
|
69
64
|
*
|
|
70
65
|
* @throws {EnvAddressError} If the env names half an address.
|
|
71
66
|
*/
|
|
72
67
|
function applyToPayload(run, { update = false } = {}) {
|
|
73
68
|
const payload = run;
|
|
74
|
-
let address
|
|
69
|
+
let address;
|
|
70
|
+
if (typeof payload.address === "string") {
|
|
71
|
+
// Wire data already applied: a queued run is applied again when its batch
|
|
72
|
+
// is sent. It is parsed again, so a malformed one cannot fail the whole
|
|
73
|
+
// batch in the backend.
|
|
74
|
+
try {
|
|
75
|
+
address = address_js_1.AgentAddress._fromLrn(payload.address);
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
throw new Error("The run's `address` is not a valid agent address.");
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
else {
|
|
82
|
+
address = (0, address_js_1.ensureAgent)(payload.address);
|
|
83
|
+
}
|
|
75
84
|
delete payload.address;
|
|
76
85
|
const namedProject = payload.session_id != null || payload.session_name != null;
|
|
77
86
|
if (!address && !update && !namedProject) {
|
|
78
|
-
address =
|
|
87
|
+
address = address_js_1.AgentAddress.fromEnv();
|
|
79
88
|
}
|
|
80
89
|
if (!address) {
|
|
81
90
|
return;
|
|
82
91
|
}
|
|
83
92
|
(0, warn_js_1.warnOnce)("Sending runs to an `address` is in beta and enabled per workspace; a " +
|
|
84
93
|
"workspace without it rejects the runs.");
|
|
85
|
-
payload.address = address;
|
|
94
|
+
payload.address = address._toLrn();
|
|
86
95
|
if (!namedProject) {
|
|
87
96
|
delete payload.session_name;
|
|
88
97
|
delete payload.session_id;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentAddress, EnvAddressError } from "../address.js";
|
|
2
2
|
/** One precedence level: the `[project, address]` it names. */
|
|
3
|
-
export type Tier = [string | undefined,
|
|
4
|
-
/** Validate and normalise an address at an entry point; the SDK carries the result. */
|
|
5
|
-
export declare function checkAddress(address: unknown): Address | undefined;
|
|
3
|
+
export type Tier = [string | undefined, AgentAddress | undefined];
|
|
6
4
|
export declare function rejectConflicting(project: unknown, address: unknown): void;
|
|
7
5
|
/** The highest level naming a project or an address, whichever it names. */
|
|
8
6
|
export declare function firstNamed(...tiers: Tier[]): Tier;
|
|
@@ -15,13 +13,13 @@ export declare function logUntraced(error: EnvAddressError): void;
|
|
|
15
13
|
/** Warn once, at client construction, if the env can't address runs. */
|
|
16
14
|
export declare function warnOnEnv(): void;
|
|
17
15
|
/**
|
|
18
|
-
* Put the run's address in its payload field,
|
|
16
|
+
* Put the run's address in its payload field, in its wire form.
|
|
19
17
|
* Without one, a create naming no project takes the env address.
|
|
20
18
|
*
|
|
21
19
|
* @throws {EnvAddressError} If the env names half an address.
|
|
22
20
|
*/
|
|
23
21
|
export declare function applyToPayload(run: {
|
|
24
|
-
address?:
|
|
22
|
+
address?: AgentAddress;
|
|
25
23
|
session_id?: string;
|
|
26
24
|
session_name?: string;
|
|
27
25
|
}, { update }?: {
|
|
@@ -1,14 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AgentAddress, EnvAddressError, ensureAgent, envNames, } from "../address.js";
|
|
2
2
|
import { getEnvironmentVariable, getLangSmithEnvironmentVariable, } from "./env.js";
|
|
3
3
|
import { warnOnce } from "./warn.js";
|
|
4
|
-
/** Validate and normalise an address at an entry point; the SDK carries the result. */
|
|
5
|
-
export function checkAddress(address) {
|
|
6
|
-
return address == null ? undefined : parse(address);
|
|
7
|
-
}
|
|
8
4
|
export function rejectConflicting(project, address) {
|
|
9
5
|
if (project && address) {
|
|
10
6
|
throw new Error(`A run is sent to a project (${JSON.stringify(project)}) or to an ` +
|
|
11
|
-
|
|
7
|
+
"address, not both.");
|
|
12
8
|
}
|
|
13
9
|
}
|
|
14
10
|
/** The highest level naming a project or an address, whichever it names. */
|
|
@@ -32,7 +28,7 @@ function getEnvProject() {
|
|
|
32
28
|
*/
|
|
33
29
|
export function resolveFromEnv() {
|
|
34
30
|
const project = getEnvProject();
|
|
35
|
-
const address =
|
|
31
|
+
const address = AgentAddress.fromEnv();
|
|
36
32
|
if (project && address) {
|
|
37
33
|
throw new EnvAddressError("LANGSMITH_AGENT_* and a project are both set in the environment.");
|
|
38
34
|
}
|
|
@@ -55,25 +51,39 @@ export function warnOnEnv() {
|
|
|
55
51
|
}
|
|
56
52
|
}
|
|
57
53
|
/**
|
|
58
|
-
* Put the run's address in its payload field,
|
|
54
|
+
* Put the run's address in its payload field, in its wire form.
|
|
59
55
|
* Without one, a create naming no project takes the env address.
|
|
60
56
|
*
|
|
61
57
|
* @throws {EnvAddressError} If the env names half an address.
|
|
62
58
|
*/
|
|
63
59
|
export function applyToPayload(run, { update = false } = {}) {
|
|
64
60
|
const payload = run;
|
|
65
|
-
let address
|
|
61
|
+
let address;
|
|
62
|
+
if (typeof payload.address === "string") {
|
|
63
|
+
// Wire data already applied: a queued run is applied again when its batch
|
|
64
|
+
// is sent. It is parsed again, so a malformed one cannot fail the whole
|
|
65
|
+
// batch in the backend.
|
|
66
|
+
try {
|
|
67
|
+
address = AgentAddress._fromLrn(payload.address);
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
throw new Error("The run's `address` is not a valid agent address.");
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
address = ensureAgent(payload.address);
|
|
75
|
+
}
|
|
66
76
|
delete payload.address;
|
|
67
77
|
const namedProject = payload.session_id != null || payload.session_name != null;
|
|
68
78
|
if (!address && !update && !namedProject) {
|
|
69
|
-
address =
|
|
79
|
+
address = AgentAddress.fromEnv();
|
|
70
80
|
}
|
|
71
81
|
if (!address) {
|
|
72
82
|
return;
|
|
73
83
|
}
|
|
74
84
|
warnOnce("Sending runs to an `address` is in beta and enabled per workspace; a " +
|
|
75
85
|
"workspace without it rejects the runs.");
|
|
76
|
-
payload.address = address;
|
|
86
|
+
payload.address = address._toLrn();
|
|
77
87
|
if (!namedProject) {
|
|
78
88
|
delete payload.session_name;
|
|
79
89
|
delete payload.session_id;
|
package/dist/utils/env.cjs
CHANGED
|
@@ -120,14 +120,16 @@ function getLangSmithEnvVarsMetadata() {
|
|
|
120
120
|
if (typeof value === "string" &&
|
|
121
121
|
!excluded.includes(key) &&
|
|
122
122
|
!isSensitiveEnvVarName(key)) {
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
else {
|
|
123
|
+
// LANGCHAIN_REVISION_ID is the legacy name for LANGSMITH_REVISION_ID.
|
|
124
|
+
if (key !== "LANGSMITH_REVISION_ID" && key !== "LANGCHAIN_REVISION_ID") {
|
|
127
125
|
envVars[key] = value;
|
|
128
126
|
}
|
|
129
127
|
}
|
|
130
128
|
}
|
|
129
|
+
const revisionId = allEnvVars.LANGSMITH_REVISION_ID || allEnvVars.LANGCHAIN_REVISION_ID;
|
|
130
|
+
if (revisionId) {
|
|
131
|
+
envVars["revision_id"] = revisionId;
|
|
132
|
+
}
|
|
131
133
|
return envVars;
|
|
132
134
|
}
|
|
133
135
|
/**
|
package/dist/utils/env.js
CHANGED
|
@@ -102,14 +102,16 @@ export function getLangSmithEnvVarsMetadata() {
|
|
|
102
102
|
if (typeof value === "string" &&
|
|
103
103
|
!excluded.includes(key) &&
|
|
104
104
|
!isSensitiveEnvVarName(key)) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
else {
|
|
105
|
+
// LANGCHAIN_REVISION_ID is the legacy name for LANGSMITH_REVISION_ID.
|
|
106
|
+
if (key !== "LANGSMITH_REVISION_ID" && key !== "LANGCHAIN_REVISION_ID") {
|
|
109
107
|
envVars[key] = value;
|
|
110
108
|
}
|
|
111
109
|
}
|
|
112
110
|
}
|
|
111
|
+
const revisionId = allEnvVars.LANGSMITH_REVISION_ID || allEnvVars.LANGCHAIN_REVISION_ID;
|
|
112
|
+
if (revisionId) {
|
|
113
|
+
envVars["revision_id"] = revisionId;
|
|
114
|
+
}
|
|
113
115
|
return envVars;
|
|
114
116
|
}
|
|
115
117
|
/**
|