langsmith 0.10.12 → 0.10.13
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/CHANGELOG.md +8 -0
- package/lib/address.d.mts +35 -56
- package/lib/address.d.mts.map +1 -1
- package/lib/address.d.ts +35 -56
- package/lib/address.d.ts.map +1 -1
- package/lib/address.js +91 -156
- package/lib/address.js.map +1 -1
- package/lib/address.mjs +83 -151
- package/lib/address.mjs.map +1 -1
- package/lib/client.d.mts +1 -1
- package/lib/client.d.mts.map +1 -1
- package/lib/client.d.ts +1 -1
- package/lib/client.d.ts.map +1 -1
- package/lib/client.js +11 -10
- package/lib/client.js.map +1 -1
- package/lib/client.mjs +4 -3
- package/lib/client.mjs.map +1 -1
- package/lib/run_trees.d.mts +1 -1
- package/lib/run_trees.d.mts.map +1 -1
- package/lib/run_trees.d.ts +1 -1
- package/lib/run_trees.d.ts.map +1 -1
- package/lib/run_trees.js +11 -9
- package/lib/run_trees.js.map +1 -1
- package/lib/run_trees.mjs +7 -5
- package/lib/run_trees.mjs.map +1 -1
- package/lib/utils/addressing.d.mts +1 -1
- package/lib/utils/addressing.d.mts.map +1 -1
- package/lib/utils/addressing.d.ts +1 -1
- package/lib/utils/addressing.d.ts.map +1 -1
- package/lib/utils/addressing.js +4 -4
- package/lib/utils/addressing.js.map +1 -1
- package/lib/utils/addressing.mjs +5 -5
- package/lib/utils/addressing.mjs.map +1 -1
- package/package.json +10 -7
- package/src/lib/address.ts +138 -180
- package/src/lib/client.ts +4 -5
- package/src/lib/run_trees.ts +8 -5
- package/src/lib/utils/addressing.ts +8 -5
- package/src/version.ts +1 -1
- package/version.d.mts +1 -1
- package/version.d.ts +1 -1
- package/version.js +1 -1
- package/version.mjs +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.10.13](https://github.com/langchain-ai/langsmith-javascript/compare/v0.10.12...v0.10.13) (2026-10-13)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Bug Fixes
|
|
7
|
+
|
|
8
|
+
* cover all brace-expansion security patch lines ([#45](https://github.com/langchain-ai/langsmith-javascript/issues/45)) ([2c36f4e](https://github.com/langchain-ai/langsmith-javascript/commit/2c36f4e3ecbefc84632cb1a1fd7947a97cce36eb))
|
|
9
|
+
* **sdk:** merge AddressApi with Address to ensure easier serialization ([#47](https://github.com/langchain-ai/langsmith-javascript/issues/47)) ([7a46bea](https://github.com/langchain-ai/langsmith-javascript/commit/7a46bea0378aecbe01249a156e12477027897b9a))
|
|
10
|
+
|
|
3
11
|
## [0.10.12](https://github.com/langchain-ai/langsmith-javascript/compare/v0.10.11...v0.10.12) (2026-10-13)
|
|
4
12
|
|
|
5
13
|
|
package/lib/address.d.mts
CHANGED
|
@@ -1,69 +1,48 @@
|
|
|
1
1
|
/** (beta) An agent environment. */
|
|
2
2
|
export type Environment = "local" | "development" | "staging" | "production";
|
|
3
|
-
/** (beta) The
|
|
4
|
-
export
|
|
5
|
-
kind: "AGENT"
|
|
6
|
-
id
|
|
7
|
-
environment
|
|
8
|
-
};
|
|
9
|
-
/** (beta) A feature that holds traces in a tracing project. */
|
|
10
|
-
export interface Address {
|
|
11
|
-
/** The address in the backend's form. */
|
|
12
|
-
toApiAddress(): ApiAddress;
|
|
13
|
-
}
|
|
14
|
-
/** (beta) The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
15
|
-
export declare class EnvAddressError extends Error {
|
|
16
|
-
constructor(message: string);
|
|
3
|
+
/** (beta) The address of an agent's environment. */
|
|
4
|
+
export interface AgentAddress {
|
|
5
|
+
kind: "AGENT";
|
|
6
|
+
id: string;
|
|
7
|
+
environment: Uppercase<Environment>;
|
|
17
8
|
}
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* new AgentAddress("customer-support", "production");
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare class AgentAddress implements Address {
|
|
27
|
-
readonly id: string;
|
|
28
|
-
/** Always lowercase. */
|
|
29
|
-
readonly environment: Environment;
|
|
30
|
-
/**
|
|
31
|
-
* @param id 1 to 63 lowercase ASCII letters, digits or hyphens, starting
|
|
32
|
-
* with a letter and ending with a letter or digit. The server creates the
|
|
33
|
-
* agent on first use.
|
|
34
|
-
* @param environment One of `local`, `development`, `staging` or `production`, in
|
|
35
|
-
* any case.
|
|
36
|
-
* @throws If a value is invalid.
|
|
37
|
-
*/
|
|
9
|
+
/** (beta) Construct and validate an agent address; plain objects are also accepted. */
|
|
10
|
+
export declare class AgentAddress {
|
|
38
11
|
constructor(id: string, environment: Environment | (string & {}));
|
|
39
|
-
toApiAddress(): ApiAddress;
|
|
40
|
-
/**
|
|
41
|
-
* Read the agent named by `LANGSMITH_AGENT_ID` and
|
|
42
|
-
* `LANGSMITH_AGENT_ENVIRONMENT`; `undefined` if neither is set.
|
|
43
|
-
* @throws {EnvAddressError} If only one is set, or a value is invalid.
|
|
44
|
-
*/
|
|
45
|
-
static fromEnv(): AgentAddress | undefined;
|
|
46
12
|
}
|
|
47
13
|
/** (beta) The address of an experiment's tracing project. */
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
14
|
+
export interface ExperimentAddress {
|
|
15
|
+
kind: "EXPERIMENT";
|
|
16
|
+
id: string;
|
|
17
|
+
}
|
|
18
|
+
/** (beta) Construct and validate an experiment address. */
|
|
19
|
+
export declare class ExperimentAddress {
|
|
55
20
|
constructor(id: string);
|
|
56
|
-
toApiAddress(): ApiAddress;
|
|
57
21
|
}
|
|
58
22
|
/** (beta) The address of the workspace's shared evaluators project. */
|
|
59
|
-
export
|
|
23
|
+
export interface EvaluatorAddress {
|
|
24
|
+
kind: "EVALUATOR";
|
|
25
|
+
}
|
|
26
|
+
/** (beta) Construct the workspace's evaluators address. */
|
|
27
|
+
export declare class EvaluatorAddress {
|
|
60
28
|
constructor();
|
|
61
|
-
toApiAddress(): ApiAddress;
|
|
62
29
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*/
|
|
30
|
+
/** (beta) A feature that holds traces in a tracing project. */
|
|
31
|
+
export type Address = AgentAddress | ExperimentAddress | EvaluatorAddress;
|
|
32
|
+
/** (beta) An address as the resolve endpoint takes it. */
|
|
33
|
+
export type ApiAddress = Address;
|
|
34
|
+
/** (beta) The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
35
|
+
export declare class EnvAddressError extends Error {
|
|
36
|
+
constructor(message: string);
|
|
37
|
+
}
|
|
38
|
+
/** Validate an address at an SDK entrypoint and return a normalized copy. */
|
|
39
|
+
export declare function ensureAddress<K extends Address["kind"]>(value: {
|
|
40
|
+
kind: K;
|
|
41
|
+
id?: unknown;
|
|
42
|
+
environment?: unknown;
|
|
43
|
+
}): Extract<Address, {
|
|
44
|
+
kind: K;
|
|
45
|
+
}>;
|
|
68
46
|
export declare function ensureAddress(value: unknown): Address | undefined;
|
|
47
|
+
export declare function ensureAgent(value: unknown): AgentAddress | undefined;
|
|
69
48
|
//# sourceMappingURL=address.d.mts.map
|
package/lib/address.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.mts","sourceRoot":"","sources":["../src/lib/address.ts"],"names":[],"mappings":"AAmBA,mCAAmC;AACnC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC;AAQ7E,
|
|
1
|
+
{"version":3,"file":"address.d.mts","sourceRoot":"","sources":["../src/lib/address.ts"],"names":[],"mappings":"AAmBA,mCAAmC;AACnC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC;AAQ7E,oDAAoD;AACpD,MAAM,WAAW,YAA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69 +1,48 @@
|
|
|
1
1
|
/** (beta) An agent environment. */
|
|
2
2
|
export type Environment = "local" | "development" | "staging" | "production";
|
|
3
|
-
/** (beta) The
|
|
4
|
-
export
|
|
5
|
-
kind: "AGENT"
|
|
6
|
-
id
|
|
7
|
-
environment
|
|
8
|
-
};
|
|
9
|
-
/** (beta) A feature that holds traces in a tracing project. */
|
|
10
|
-
export interface Address {
|
|
11
|
-
/** The address in the backend's form. */
|
|
12
|
-
toApiAddress(): ApiAddress;
|
|
13
|
-
}
|
|
14
|
-
/** (beta) The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
15
|
-
export declare class EnvAddressError extends Error {
|
|
16
|
-
constructor(message: string);
|
|
3
|
+
/** (beta) The address of an agent's environment. */
|
|
4
|
+
export interface AgentAddress {
|
|
5
|
+
kind: "AGENT";
|
|
6
|
+
id: string;
|
|
7
|
+
environment: Uppercase<Environment>;
|
|
17
8
|
}
|
|
18
|
-
/**
|
|
19
|
-
|
|
20
|
-
*
|
|
21
|
-
* @example
|
|
22
|
-
* ```ts
|
|
23
|
-
* new AgentAddress("customer-support", "production");
|
|
24
|
-
* ```
|
|
25
|
-
*/
|
|
26
|
-
export declare class AgentAddress implements Address {
|
|
27
|
-
readonly id: string;
|
|
28
|
-
/** Always lowercase. */
|
|
29
|
-
readonly environment: Environment;
|
|
30
|
-
/**
|
|
31
|
-
* @param id 1 to 63 lowercase ASCII letters, digits or hyphens, starting
|
|
32
|
-
* with a letter and ending with a letter or digit. The server creates the
|
|
33
|
-
* agent on first use.
|
|
34
|
-
* @param environment One of `local`, `development`, `staging` or `production`, in
|
|
35
|
-
* any case.
|
|
36
|
-
* @throws If a value is invalid.
|
|
37
|
-
*/
|
|
9
|
+
/** (beta) Construct and validate an agent address; plain objects are also accepted. */
|
|
10
|
+
export declare class AgentAddress {
|
|
38
11
|
constructor(id: string, environment: Environment | (string & {}));
|
|
39
|
-
toApiAddress(): ApiAddress;
|
|
40
|
-
/**
|
|
41
|
-
* Read the agent named by `LANGSMITH_AGENT_ID` and
|
|
42
|
-
* `LANGSMITH_AGENT_ENVIRONMENT`; `undefined` if neither is set.
|
|
43
|
-
* @throws {EnvAddressError} If only one is set, or a value is invalid.
|
|
44
|
-
*/
|
|
45
|
-
static fromEnv(): AgentAddress | undefined;
|
|
46
12
|
}
|
|
47
13
|
/** (beta) The address of an experiment's tracing project. */
|
|
48
|
-
export
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
*/
|
|
14
|
+
export interface ExperimentAddress {
|
|
15
|
+
kind: "EXPERIMENT";
|
|
16
|
+
id: string;
|
|
17
|
+
}
|
|
18
|
+
/** (beta) Construct and validate an experiment address. */
|
|
19
|
+
export declare class ExperimentAddress {
|
|
55
20
|
constructor(id: string);
|
|
56
|
-
toApiAddress(): ApiAddress;
|
|
57
21
|
}
|
|
58
22
|
/** (beta) The address of the workspace's shared evaluators project. */
|
|
59
|
-
export
|
|
23
|
+
export interface EvaluatorAddress {
|
|
24
|
+
kind: "EVALUATOR";
|
|
25
|
+
}
|
|
26
|
+
/** (beta) Construct the workspace's evaluators address. */
|
|
27
|
+
export declare class EvaluatorAddress {
|
|
60
28
|
constructor();
|
|
61
|
-
toApiAddress(): ApiAddress;
|
|
62
29
|
}
|
|
63
|
-
/**
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
*/
|
|
30
|
+
/** (beta) A feature that holds traces in a tracing project. */
|
|
31
|
+
export type Address = AgentAddress | ExperimentAddress | EvaluatorAddress;
|
|
32
|
+
/** (beta) An address as the resolve endpoint takes it. */
|
|
33
|
+
export type ApiAddress = Address;
|
|
34
|
+
/** (beta) The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
35
|
+
export declare class EnvAddressError extends Error {
|
|
36
|
+
constructor(message: string);
|
|
37
|
+
}
|
|
38
|
+
/** Validate an address at an SDK entrypoint and return a normalized copy. */
|
|
39
|
+
export declare function ensureAddress<K extends Address["kind"]>(value: {
|
|
40
|
+
kind: K;
|
|
41
|
+
id?: unknown;
|
|
42
|
+
environment?: unknown;
|
|
43
|
+
}): Extract<Address, {
|
|
44
|
+
kind: K;
|
|
45
|
+
}>;
|
|
68
46
|
export declare function ensureAddress(value: unknown): Address | undefined;
|
|
47
|
+
export declare function ensureAgent(value: unknown): AgentAddress | undefined;
|
|
69
48
|
//# sourceMappingURL=address.d.ts.map
|
package/lib/address.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/lib/address.ts"],"names":[],"mappings":"AAmBA,mCAAmC;AACnC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC;AAQ7E,
|
|
1
|
+
{"version":3,"file":"address.d.ts","sourceRoot":"","sources":["../src/lib/address.ts"],"names":[],"mappings":"AAmBA,mCAAmC;AACnC,MAAM,MAAM,WAAW,GAAG,OAAO,GAAG,aAAa,GAAG,SAAS,GAAG,YAAY,CAAC;AAQ7E,oDAAoD;AACpD,MAAM,WAAW,YAAY;IAC3B,IAAI,EAAE,OAAO,CAAC;IACd,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,SAAS,CAAC,WAAW,CAAC,CAAC;CACrC;AAED,uFAAuF;AACvF,qBAAa,YAAY;gBACX,EAAE,EAAE,MAAM,EAAE,WAAW,EAAE,WAAW,GAAG,CAAC,MAAM,GAAG,EAAE,CAAC;CAOjE;AAED,6DAA6D;AAC7D,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,YAAY,CAAC;IACnB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED,2DAA2D;AAC3D,qBAAa,iBAAiB;gBAChB,EAAE,EAAE,MAAM;CAMvB;AAED,uEAAuE;AACvE,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,WAAW,CAAC;CACnB;AAED,2DAA2D;AAC3D,qBAAa,gBAAgB;;CAK5B;AAED,+DAA+D;AAC/D,MAAM,MAAM,OAAO,GAAG,YAAY,GAAG,iBAAiB,GAAG,gBAAgB,CAAC;AAE1E,0DAA0D;AAC1D,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC;AAcjC,uFAAuF;AACvF,qBAAa,eAAgB,SAAQ,KAAK;gBAC5B,OAAO,EAAE,MAAM;CAI5B;AAED,6EAA6E;AAC7E,wBAAgB,aAAa,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,EAAE,KAAK,EAAE;IAC9D,IAAI,EAAE,CAAC,CAAC;IACR,EAAE,CAAC,EAAE,OAAO,CAAC;IACb,WAAW,CAAC,EAAE,OAAO,CAAC;CACvB,GAAG,OAAO,CAAC,OAAO,EAAE;IAAE,IAAI,EAAE,CAAC,CAAA;CAAE,CAAC,CAAC;AAClC,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,GAAG,SAAS,CAAC;AAoDnE,wBAAgB,WAAW,CAAC,KAAK,EAAE,OAAO,GAAG,YAAY,GAAG,SAAS,CAAC"}
|
package/lib/address.js
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
exports.ensureAgent = ensureAgent;
|
|
3
|
+
exports.EnvAddressError = exports.EvaluatorAddress = exports.ExperimentAddress = exports.AgentAddress = void 0;
|
|
5
4
|
exports.ensureAddress = ensureAddress;
|
|
5
|
+
exports.ensureAgent = ensureAgent;
|
|
6
|
+
exports.addressToLrn = addressToLrn;
|
|
7
|
+
exports.addressFromLrn = addressFromLrn;
|
|
8
|
+
exports.addressFromEnv = addressFromEnv;
|
|
6
9
|
exports.envNames = envNames;
|
|
7
10
|
/**
|
|
8
11
|
* (beta) Addresses that name where runs are sent instead of a project.
|
|
@@ -22,16 +25,40 @@ exports.envNames = envNames;
|
|
|
22
25
|
* ```
|
|
23
26
|
*/
|
|
24
27
|
const env_js_1 = require("./utils/env.js");
|
|
28
|
+
/** (beta) Construct and validate an agent address; plain objects are also accepted. */
|
|
29
|
+
class AgentAddress {
|
|
30
|
+
constructor(id, environment) {
|
|
31
|
+
const address = ensureAgent({ kind: "AGENT", id, environment });
|
|
32
|
+
this.kind = address.kind;
|
|
33
|
+
this.id = address.id;
|
|
34
|
+
this.environment = address.environment;
|
|
35
|
+
Object.freeze(this);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
exports.AgentAddress = AgentAddress;
|
|
39
|
+
/** (beta) Construct and validate an experiment address. */
|
|
40
|
+
class ExperimentAddress {
|
|
41
|
+
constructor(id) {
|
|
42
|
+
const address = ensureAddress({ kind: "EXPERIMENT", id });
|
|
43
|
+
this.kind = address.kind;
|
|
44
|
+
this.id = address.id;
|
|
45
|
+
Object.freeze(this);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
exports.ExperimentAddress = ExperimentAddress;
|
|
49
|
+
/** (beta) Construct the workspace's evaluators address. */
|
|
50
|
+
class EvaluatorAddress {
|
|
51
|
+
constructor() {
|
|
52
|
+
this.kind = "EVALUATOR";
|
|
53
|
+
Object.freeze(this);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.EvaluatorAddress = EvaluatorAddress;
|
|
25
57
|
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
26
58
|
// The server's agent id rule: a DNS label, so a hostname can carry the id.
|
|
27
59
|
const AGENT_ID_PATTERN = /^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
28
|
-
const ENVIRONMENTS = [
|
|
29
|
-
|
|
30
|
-
"development",
|
|
31
|
-
"staging",
|
|
32
|
-
"production",
|
|
33
|
-
];
|
|
34
|
-
// The wire form of an agent address. The parts are validated by `AgentAddress`.
|
|
60
|
+
const ENVIRONMENTS = ["local", "development", "staging", "production"];
|
|
61
|
+
// The wire form of an agent address. The parts are validated at entrypoints.
|
|
35
62
|
const LRN_PATTERN = /^lrn:agents\/([^/]+)\/environments\/([^/]+)$/;
|
|
36
63
|
const ENV_NAMES = ["LANGSMITH_AGENT_ID", "LANGSMITH_AGENT_ENVIRONMENT"];
|
|
37
64
|
/** (beta) The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
@@ -42,169 +69,77 @@ class EnvAddressError extends Error {
|
|
|
42
69
|
}
|
|
43
70
|
}
|
|
44
71
|
exports.EnvAddressError = EnvAddressError;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
* new AgentAddress("customer-support", "production");
|
|
51
|
-
* ```
|
|
52
|
-
*/
|
|
53
|
-
class AgentAddress {
|
|
54
|
-
/**
|
|
55
|
-
* @param id 1 to 63 lowercase ASCII letters, digits or hyphens, starting
|
|
56
|
-
* with a letter and ending with a letter or digit. The server creates the
|
|
57
|
-
* agent on first use.
|
|
58
|
-
* @param environment One of `local`, `development`, `staging` or `production`, in
|
|
59
|
-
* any case.
|
|
60
|
-
* @throws If a value is invalid.
|
|
61
|
-
*/
|
|
62
|
-
constructor(id, environment) {
|
|
63
|
-
Object.defineProperty(this, "id", {
|
|
64
|
-
enumerable: true,
|
|
65
|
-
configurable: true,
|
|
66
|
-
writable: true,
|
|
67
|
-
value: void 0
|
|
68
|
-
});
|
|
69
|
-
/** Always lowercase. */
|
|
70
|
-
Object.defineProperty(this, "environment", {
|
|
71
|
-
enumerable: true,
|
|
72
|
-
configurable: true,
|
|
73
|
-
writable: true,
|
|
74
|
-
value: void 0
|
|
75
|
-
});
|
|
76
|
-
if (typeof id !== "string" || !AGENT_ID_PATTERN.test(id)) {
|
|
77
|
-
throw new Error("Address agent id must be 1 to 63 lowercase ASCII letters, digits, or " +
|
|
78
|
-
"hyphens, start with a letter, and end with a letter or digit, got " +
|
|
79
|
-
`${JSON.stringify(id)}. Use an id such as "support-agent".`);
|
|
80
|
-
}
|
|
81
|
-
const normalized = typeof environment === "string" ? environment.toLowerCase() : undefined;
|
|
82
|
-
if (normalized === undefined || !ENVIRONMENTS.includes(normalized)) {
|
|
83
|
-
throw new Error(`Address environment must be one of ${ENVIRONMENTS.join(", ")}, got ` +
|
|
84
|
-
`${JSON.stringify(environment)}.`);
|
|
85
|
-
}
|
|
86
|
-
this.id = id;
|
|
87
|
-
this.environment = normalized;
|
|
88
|
-
Object.freeze(this);
|
|
89
|
-
}
|
|
90
|
-
toApiAddress() {
|
|
91
|
-
return {
|
|
92
|
-
kind: "AGENT",
|
|
93
|
-
id: this.id,
|
|
94
|
-
environment: this.environment.toUpperCase(),
|
|
95
|
-
};
|
|
96
|
-
}
|
|
97
|
-
/** @internal */
|
|
98
|
-
_toLrn() {
|
|
99
|
-
return `lrn:agents/${this.id}/environments/${this.environment}`;
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* @internal Parse an LRN read from the wire, such as a `baggage` header. The
|
|
103
|
-
* value is untrusted, so it is not echoed in the error.
|
|
104
|
-
* @throws If `value` is not an agent LRN, or names an invalid id or environment.
|
|
105
|
-
*/
|
|
106
|
-
static _fromLrn(value) {
|
|
107
|
-
const match = typeof value === "string" ? LRN_PATTERN.exec(value) : null;
|
|
108
|
-
if (match === null) {
|
|
109
|
-
throw new Error("Not an agent address.");
|
|
110
|
-
}
|
|
111
|
-
return new AgentAddress(match[1], match[2]);
|
|
112
|
-
}
|
|
113
|
-
/**
|
|
114
|
-
* Read the agent named by `LANGSMITH_AGENT_ID` and
|
|
115
|
-
* `LANGSMITH_AGENT_ENVIRONMENT`; `undefined` if neither is set.
|
|
116
|
-
* @throws {EnvAddressError} If only one is set, or a value is invalid.
|
|
117
|
-
*/
|
|
118
|
-
static fromEnv() {
|
|
119
|
-
const values = ENV_NAMES.map((name) => (0, env_js_1.getEnvironmentVariable)(name));
|
|
120
|
-
if (!values.some(Boolean)) {
|
|
121
|
-
return undefined;
|
|
122
|
-
}
|
|
123
|
-
try {
|
|
124
|
-
const missing = ENV_NAMES.filter((_, i) => !values[i]);
|
|
125
|
-
if (missing.length > 0) {
|
|
126
|
-
throw new Error(`An address needs ${missing.join(" and ")} as well.`);
|
|
127
|
-
}
|
|
128
|
-
return new AgentAddress(values[0], values[1]);
|
|
129
|
-
}
|
|
130
|
-
catch (e) {
|
|
131
|
-
const present = ENV_NAMES.flatMap((name, i) => values[i] ? [`${name}=${JSON.stringify(values[i])}`] : []).join(", ");
|
|
132
|
-
throw new EnvAddressError(`The LANGSMITH_AGENT_* env vars can't address a run (${present}): ${e.message}`);
|
|
133
|
-
}
|
|
72
|
+
function ensureAddress(value) {
|
|
73
|
+
if (value == null)
|
|
74
|
+
return undefined;
|
|
75
|
+
if (typeof value !== "object") {
|
|
76
|
+
throw new Error("address must be an AgentAddress, ExperimentAddress or EvaluatorAddress object.");
|
|
134
77
|
}
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* @param id The experiment's UUID.
|
|
141
|
-
* @throws If `id` is not a UUID.
|
|
142
|
-
*/
|
|
143
|
-
constructor(id) {
|
|
144
|
-
/** Always lowercase. */
|
|
145
|
-
Object.defineProperty(this, "id", {
|
|
146
|
-
enumerable: true,
|
|
147
|
-
configurable: true,
|
|
148
|
-
writable: true,
|
|
149
|
-
value: void 0
|
|
150
|
-
});
|
|
78
|
+
const { kind, id, environment } = value;
|
|
79
|
+
if (kind === "EVALUATOR")
|
|
80
|
+
return { kind };
|
|
81
|
+
if (kind === "EXPERIMENT") {
|
|
151
82
|
if (typeof id !== "string" || !UUID_PATTERN.test(id)) {
|
|
152
83
|
throw new Error(`Experiment id must be a UUID, got ${JSON.stringify(id)}.`);
|
|
153
84
|
}
|
|
154
|
-
|
|
155
|
-
Object.freeze(this);
|
|
85
|
+
return { kind, id: id.toLowerCase() };
|
|
156
86
|
}
|
|
157
|
-
|
|
158
|
-
|
|
87
|
+
if (kind !== "AGENT") {
|
|
88
|
+
throw new Error("address must be an AgentAddress, ExperimentAddress or EvaluatorAddress object.");
|
|
159
89
|
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
constructor() {
|
|
165
|
-
Object.freeze(this);
|
|
90
|
+
if (typeof id !== "string" || !AGENT_ID_PATTERN.test(id)) {
|
|
91
|
+
throw new Error("Address agent id must be 1 to 63 lowercase ASCII letters, digits, or " +
|
|
92
|
+
"hyphens, start with a letter, and end with a letter or digit, got " +
|
|
93
|
+
`${JSON.stringify(id)}. Use an id such as "support-agent".`);
|
|
166
94
|
}
|
|
167
|
-
|
|
168
|
-
|
|
95
|
+
const normalized = typeof environment === "string" ? environment.toLowerCase() : undefined;
|
|
96
|
+
if (normalized === undefined || !ENVIRONMENTS.includes(normalized)) {
|
|
97
|
+
throw new Error(`Address environment must be one of ${ENVIRONMENTS.join(", ")}, got ${JSON.stringify(environment)}.`);
|
|
169
98
|
}
|
|
99
|
+
return {
|
|
100
|
+
kind,
|
|
101
|
+
id,
|
|
102
|
+
environment: normalized.toUpperCase(),
|
|
103
|
+
};
|
|
170
104
|
}
|
|
171
|
-
exports.EvaluatorAddress = EvaluatorAddress;
|
|
172
|
-
/**
|
|
173
|
-
* @internal The ingestion entry-point guard: `value` must be an `AgentAddress` (or
|
|
174
|
-
* absent), and is returned as is. Other addresses and strings are rejected.
|
|
175
|
-
* @throws If `value` is not an `AgentAddress`.
|
|
176
|
-
*/
|
|
177
105
|
function ensureAgent(value) {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
if (value instanceof AgentAddress) {
|
|
182
|
-
return value;
|
|
106
|
+
const address = ensureAddress(value);
|
|
107
|
+
if (address && address.kind !== "AGENT") {
|
|
108
|
+
throw new Error(`Only an AgentAddress can receive traces, got ${address.kind}.`);
|
|
183
109
|
}
|
|
184
|
-
|
|
185
|
-
typeof value.toApiAddress === "function") {
|
|
186
|
-
throw new Error(`Only an AgentAddress can receive traces, got ${value.constructor?.name ?? "an unknown address"}.`);
|
|
187
|
-
}
|
|
188
|
-
throw new Error("address must be an AgentAddress such as `new AgentAddress(id, environment)`, got " +
|
|
189
|
-
`${typeof value === "string" ? JSON.stringify(value) : typeof value}.`);
|
|
110
|
+
return address;
|
|
190
111
|
}
|
|
191
|
-
/**
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
*/
|
|
196
|
-
function
|
|
197
|
-
|
|
112
|
+
/** @internal Convert a validated address to the ingestion wire format. */
|
|
113
|
+
function addressToLrn(address) {
|
|
114
|
+
return `lrn:agents/${address.id}/environments/${address.environment.toLowerCase()}`;
|
|
115
|
+
}
|
|
116
|
+
/** @internal Parse and validate an address from untrusted wire data. */
|
|
117
|
+
function addressFromLrn(value) {
|
|
118
|
+
const match = typeof value === "string" ? LRN_PATTERN.exec(value) : null;
|
|
119
|
+
if (!match)
|
|
120
|
+
throw new Error("Not an agent address.");
|
|
121
|
+
return ensureAgent({ kind: "AGENT", id: match[1], environment: match[2] });
|
|
122
|
+
}
|
|
123
|
+
/** @internal Read and validate the address named by environment variables. */
|
|
124
|
+
function addressFromEnv() {
|
|
125
|
+
const values = ENV_NAMES.map((name) => (0, env_js_1.getEnvironmentVariable)(name));
|
|
126
|
+
if (!values.some(Boolean))
|
|
198
127
|
return undefined;
|
|
128
|
+
try {
|
|
129
|
+
const missing = ENV_NAMES.filter((_, i) => !values[i]);
|
|
130
|
+
if (missing.length)
|
|
131
|
+
throw new Error(`An address needs ${missing.join(" and ")} as well.`);
|
|
132
|
+
return ensureAgent({
|
|
133
|
+
kind: "AGENT",
|
|
134
|
+
id: values[0],
|
|
135
|
+
environment: values[1],
|
|
136
|
+
});
|
|
199
137
|
}
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
return value;
|
|
138
|
+
catch (e) {
|
|
139
|
+
throw new EnvAddressError(`The LANGSMITH_AGENT_* env vars can't address a run: ${e.message}`);
|
|
203
140
|
}
|
|
204
|
-
throw new Error("address must be an AgentAddress, ExperimentAddress or EvaluatorAddress, got " +
|
|
205
|
-
`${typeof value === "string" ? JSON.stringify(value) : typeof value}.`);
|
|
206
141
|
}
|
|
207
|
-
/** @internal The
|
|
142
|
+
/** @internal The environment variable names an address reads. */
|
|
208
143
|
function envNames() {
|
|
209
144
|
return ENV_NAMES;
|
|
210
145
|
}
|
package/lib/address.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/lib/address.ts"],"names":[],"mappings":";;;
|
|
1
|
+
{"version":3,"file":"address.js","sourceRoot":"","sources":["../src/lib/address.ts"],"names":[],"mappings":";;;AA4GA,sCA2CC;AASD,kCAQC;AAGD,oCAIC;AAGD,wCAIC;AAGD,wCAmBC;AAGD,4BAEC;AAjND;;;;;;;;;;;;;;;;GAgBG;AACH,2CAAwD;AAkBxD,uFAAuF;AACvF,MAAa,YAAY;IACvB,YAAY,EAAU,EAAE,WAAwC;QAC9D,MAAM,OAAO,GAAG,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,EAAE,EAAE,WAAW,EAAE,CAAC,CAAC;QAChE,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;QACrB,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,CAAC;QACvC,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;IACtB,CAAC;CACF;AARD,oCAQC;AAQD,2DAA2D;AAC3D,MAAa,iBAAiB;IAC5B,YAAY,EAAU;QACpB,MAAM,OAAO,GAAG,aAAa,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,CAAC,CAAC;QAC1D,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;QACzB,IAAI,CAAC,EAAE,GAAG,OAAO,CAAC,EAAE,CAAC;QACrB,MAAM,CAAC,MAAM,CAAC,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