langsmith 0.10.7 → 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 +176 -99
- package/dist/address.d.ts +63 -8
- package/dist/address.js +170 -90
- 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/experimental/otel/exporter.cjs +21 -4
- package/dist/experimental/otel/exporter.d.ts +4 -2
- package/dist/experimental/otel/exporter.js +21 -4
- package/dist/index.cjs +5 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/run_trees.cjs +26 -43
- package/dist/run_trees.d.ts +4 -4
- package/dist/run_trees.js +23 -40
- 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} +22 -23
- package/dist/utils/{agent_addressing.d.ts → addressing.d.ts} +5 -8
- package/dist/utils/{agent_addressing.js → addressing.js} +23 -23
- package/dist/utils/env.cjs +6 -4
- package/dist/utils/env.js +6 -4
- package/package.json +1 -1
|
@@ -1,67 +1,3 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
2
|
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
-
|
|
4
|
-
import { ItemsCursorGetPagination, ItemsCursorPostPagination, } from '../core/pagination.js';
|
|
5
|
-
import { path } from '../internal/utils/path.js';
|
|
6
|
-
export class Threads extends APIResource {
|
|
7
|
-
/**
|
|
8
|
-
* Retrieve all traces belonging to a specific thread within a project.
|
|
9
|
-
*
|
|
10
|
-
* Self-hosted deployments require LangSmith `v0.16` or later.
|
|
11
|
-
*
|
|
12
|
-
* @example
|
|
13
|
-
* ```ts
|
|
14
|
-
* // Automatically fetches more pages as needed.
|
|
15
|
-
* for await (const threadTrace of client.threads.listTraces(
|
|
16
|
-
* 'thread_id',
|
|
17
|
-
* { project_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' },
|
|
18
|
-
* )) {
|
|
19
|
-
* // ...
|
|
20
|
-
* }
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
listTraces(threadID, query, options) {
|
|
24
|
-
return this._client.getAPIList(path `/api/v2/threads/${threadID}/traces`, (ItemsCursorGetPagination), { query, ...options });
|
|
25
|
-
}
|
|
26
|
-
/**
|
|
27
|
-
* Query threads within a project (session), with cursor-based pagination. Returns
|
|
28
|
-
* threads matching the given time range and optional filters.
|
|
29
|
-
*
|
|
30
|
-
* Self-hosted deployments require LangSmith `v0.16` or later.
|
|
31
|
-
*
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* // Automatically fetches more pages as needed.
|
|
35
|
-
* for await (const thread of client.threads.query()) {
|
|
36
|
-
* // ...
|
|
37
|
-
* }
|
|
38
|
-
* ```
|
|
39
|
-
*/
|
|
40
|
-
query(body, options) {
|
|
41
|
-
return this._client.getAPIList('/api/v2/threads/query', (ItemsCursorPostPagination), {
|
|
42
|
-
body,
|
|
43
|
-
method: 'post',
|
|
44
|
-
...options,
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
/**
|
|
48
|
-
* Compute aggregate stats for a single thread (turn count, latency percentiles,
|
|
49
|
-
* token/cost sums, and detail breakdowns) within a project.
|
|
50
|
-
*
|
|
51
|
-
* Self-hosted deployments require LangSmith `v0.16` or later.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```ts
|
|
55
|
-
* const threadStats = await client.threads.stats(
|
|
56
|
-
* 'thread_id',
|
|
57
|
-
* {
|
|
58
|
-
* selects: ['TURNS'],
|
|
59
|
-
* session_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
|
|
60
|
-
* },
|
|
61
|
-
* );
|
|
62
|
-
* ```
|
|
63
|
-
*/
|
|
64
|
-
stats(threadID, query, options) {
|
|
65
|
-
return this._client.get(path `/api/v2/threads/${threadID}/stats`, { query, ...options });
|
|
66
|
-
}
|
|
67
|
-
}
|
|
3
|
+
export * from './threads/index.js';
|
|
@@ -46,6 +46,12 @@ export declare class Traces extends APIResource {
|
|
|
46
46
|
}
|
|
47
47
|
export type TracesItemsCursorPostPagination = ItemsCursorPostPagination<Trace>;
|
|
48
48
|
export interface Trace {
|
|
49
|
+
/**
|
|
50
|
+
* `query_metadata` describes why this trace matched the query, including
|
|
51
|
+
* `sem_filter_score` when a semantic filter is used. Returned automatically, or
|
|
52
|
+
* null when unavailable.
|
|
53
|
+
*/
|
|
54
|
+
query_metadata?: unknown | null;
|
|
49
55
|
/**
|
|
50
56
|
* `root_run` is the trace's root run. Which properties are populated is controlled
|
|
51
57
|
* by `selects` in the request.
|
|
@@ -111,7 +117,7 @@ export interface TraceListRunsParams {
|
|
|
111
117
|
* (repeatable query parameter). Accepts any value of the `RunSelectField` enum. If
|
|
112
118
|
* omitted, only `id` is returned.
|
|
113
119
|
*/
|
|
114
|
-
selects?: Array<'ID' | 'NAME' | 'RUN_TYPE' | 'STATUS' | 'START_TIME' | 'END_TIME' | 'LATENCY_SECONDS' | 'FIRST_TOKEN_TIME' | 'ERROR' | 'ERROR_PREVIEW' | 'EXTRA' | 'METADATA' | 'EVENTS' | 'INPUTS' | 'INPUTS_PREVIEW' | 'OUTPUTS' | 'OUTPUTS_PREVIEW' | 'MANIFEST' | 'PARENT_RUN_IDS' | 'PROJECT_ID' | 'TRACE_ID' | 'THREAD_ID' | 'DOTTED_ORDER' | 'IS_ROOT' | 'REFERENCE_EXAMPLE_ID' | 'REFERENCE_DATASET_ID' | 'TOTAL_TOKENS' | 'PROMPT_TOKENS' | 'COMPLETION_TOKENS' | 'TOTAL_COST' | 'PROMPT_COST' | 'COMPLETION_COST' | 'PROMPT_TOKEN_DETAILS' | 'COMPLETION_TOKEN_DETAILS' | 'PROMPT_COST_DETAILS' | 'COMPLETION_COST_DETAILS' | 'PRICE_MODEL_ID' | 'TAGS' | 'APP_PATH' | 'ATTACHMENTS' | 'THREAD_EVALUATION_TIME' | 'IS_IN_DATASET' | 'LAST_QUEUED_AT' | 'SHARE_URL' | 'FEEDBACK_STATS'>;
|
|
120
|
+
selects?: Array<'ID' | 'NAME' | 'RUN_TYPE' | 'STATUS' | 'START_TIME' | 'END_TIME' | 'LATENCY_SECONDS' | 'FIRST_TOKEN_TIME' | 'ERROR' | 'ERROR_PREVIEW' | 'EXTRA' | 'METADATA' | 'EVENTS' | 'INPUTS' | 'INPUTS_PREVIEW' | 'OUTPUTS' | 'OUTPUTS_PREVIEW' | 'MANIFEST' | 'PARENT_RUN_IDS' | 'PROJECT_ID' | 'TRACE_ID' | 'THREAD_ID' | 'DOTTED_ORDER' | 'IS_ROOT' | 'REFERENCE_EXAMPLE_ID' | 'REFERENCE_DATASET_ID' | 'TOTAL_TOKENS' | 'PROMPT_TOKENS' | 'COMPLETION_TOKENS' | 'TOTAL_COST' | 'PROMPT_COST' | 'COMPLETION_COST' | 'PROMPT_TOKEN_DETAILS' | 'COMPLETION_TOKEN_DETAILS' | 'PROMPT_COST_DETAILS' | 'COMPLETION_COST_DETAILS' | 'PRICE_MODEL_ID' | 'TAGS' | 'APP_PATH' | 'ATTACHMENTS' | 'THREAD_EVALUATION_TIME' | 'IS_IN_DATASET' | 'LAST_QUEUED_AT' | 'SHARE_URL' | 'FEEDBACK_STATS' | 'LS_USER_ID'>;
|
|
115
121
|
/**
|
|
116
122
|
* Header param: application/json
|
|
117
123
|
*/
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
export const VERSION = '0.0.1';
|
|
2
|
+
export const VERSION = '0.0.1'; // x-release-please-version
|
package/dist/address.cjs
CHANGED
|
@@ -1,33 +1,40 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.EnvAddressError = void 0;
|
|
4
|
-
exports.
|
|
5
|
-
exports.
|
|
3
|
+
exports.EvaluatorAddress = exports.ExperimentAddress = exports.AgentAddress = exports.EnvAddressError = void 0;
|
|
4
|
+
exports.ensureAgent = ensureAgent;
|
|
5
|
+
exports.ensureAddress = ensureAddress;
|
|
6
6
|
exports.envNames = envNames;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
7
|
+
/**
|
|
8
|
+
* (beta) Addresses that name where runs are sent instead of a project.
|
|
9
|
+
* Enabled per workspace; a workspace without it rejects the runs.
|
|
10
|
+
*
|
|
11
|
+
* An `Address` names a tracing project held by a feature: an `AgentAddress`, an
|
|
12
|
+
* `ExperimentAddress` or the workspace's `EvaluatorAddress`. Any of them can be resolved to
|
|
13
|
+
* its project. Only an `AgentAddress` can receive traces, and ingestion rejects the
|
|
14
|
+
* others at its entry points.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* import { AgentAddress, traceable } from "langsmith";
|
|
19
|
+
*
|
|
20
|
+
* const support = new AgentAddress("customer-support", "production");
|
|
21
|
+
* const handle = traceable(fn, { address: support });
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
const env_js_1 = require("./utils/env.cjs");
|
|
25
|
+
const UUID_PATTERN = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
|
|
18
26
|
// The server's agent id rule: a DNS label, so a hostname can carry the id.
|
|
19
27
|
const AGENT_ID_PATTERN = /^[a-z]([a-z0-9-]{0,61}[a-z0-9])?$/;
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
/** The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
28
|
+
const ENVIRONMENTS = [
|
|
29
|
+
"local",
|
|
30
|
+
"development",
|
|
31
|
+
"staging",
|
|
32
|
+
"production",
|
|
33
|
+
];
|
|
34
|
+
// The wire form of an agent address. The parts are validated by `AgentAddress`.
|
|
35
|
+
const LRN_PATTERN = /^lrn:agents\/([^/]+)\/environments\/([^/]+)$/;
|
|
36
|
+
const ENV_NAMES = ["LANGSMITH_AGENT_ID", "LANGSMITH_AGENT_ENVIRONMENT"];
|
|
37
|
+
/** (beta) The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
31
38
|
class EnvAddressError extends Error {
|
|
32
39
|
constructor(message) {
|
|
33
40
|
super(message);
|
|
@@ -36,98 +43,168 @@ class EnvAddressError extends Error {
|
|
|
36
43
|
}
|
|
37
44
|
exports.EnvAddressError = EnvAddressError;
|
|
38
45
|
/**
|
|
39
|
-
*
|
|
40
|
-
*
|
|
46
|
+
* (beta) The address of an agent's environment.
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* new AgentAddress("customer-support", "production");
|
|
51
|
+
* ```
|
|
41
52
|
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
+
};
|
|
45
96
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
throw new Error(`Unknown address fields: ${unknown.join(", ")}.`);
|
|
97
|
+
/** @internal */
|
|
98
|
+
_toLrn() {
|
|
99
|
+
return `lrn:agents/${this.id}/environments/${this.environment}`;
|
|
50
100
|
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
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.");
|
|
55
110
|
}
|
|
111
|
+
return new AgentAddress(match[1], match[2]);
|
|
56
112
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
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
|
+
}
|
|
62
134
|
}
|
|
63
|
-
return Object.freeze({ agentId, agentEnvironment });
|
|
64
135
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
136
|
+
exports.AgentAddress = AgentAddress;
|
|
137
|
+
/** (beta) The address of an experiment's tracing project. */
|
|
138
|
+
class ExperimentAddress {
|
|
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
|
+
});
|
|
151
|
+
if (typeof id !== "string" || !UUID_PATTERN.test(id)) {
|
|
152
|
+
throw new Error(`Experiment id must be a UUID, got ${JSON.stringify(id)}.`);
|
|
153
|
+
}
|
|
154
|
+
this.id = id.toLowerCase();
|
|
155
|
+
Object.freeze(this);
|
|
156
|
+
}
|
|
157
|
+
toApiAddress() {
|
|
158
|
+
return { kind: "EXPERIMENT", id: this.id };
|
|
159
|
+
}
|
|
68
160
|
}
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
161
|
+
exports.ExperimentAddress = ExperimentAddress;
|
|
162
|
+
/** (beta) The address of the workspace's shared evaluators project. */
|
|
163
|
+
class EvaluatorAddress {
|
|
164
|
+
constructor() {
|
|
165
|
+
Object.freeze(this);
|
|
166
|
+
}
|
|
167
|
+
toApiAddress() {
|
|
168
|
+
return { kind: "EVALUATOR" };
|
|
169
|
+
}
|
|
72
170
|
}
|
|
171
|
+
exports.EvaluatorAddress = EvaluatorAddress;
|
|
73
172
|
/**
|
|
74
|
-
* @internal The
|
|
75
|
-
*
|
|
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`.
|
|
76
176
|
*/
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
address: {
|
|
80
|
-
kind: "AGENT",
|
|
81
|
-
id: address.agentId,
|
|
82
|
-
environment: address.agentEnvironment.toUpperCase(),
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
/** @internal Header / replica fields. */
|
|
87
|
-
function toWire(address) {
|
|
88
|
-
return {
|
|
89
|
-
[FIELDS.agentId]: address.agentId,
|
|
90
|
-
[FIELDS.agentEnvironment]: address.agentEnvironment,
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
/** @internal `undefined` if no field is set; throws if only some are. */
|
|
94
|
-
function fromWire(values) {
|
|
95
|
-
const fields = Object.fromEntries(Object.entries(FIELDS).map(([name, key]) => [
|
|
96
|
-
name,
|
|
97
|
-
values[key] ?? undefined,
|
|
98
|
-
]));
|
|
99
|
-
const missing = Object.entries(FIELDS)
|
|
100
|
-
.filter(([name]) => fields[name] === undefined)
|
|
101
|
-
.map(([, key]) => key);
|
|
102
|
-
if (missing.length === Object.keys(FIELDS).length) {
|
|
177
|
+
function ensureAgent(value) {
|
|
178
|
+
if (value == null) {
|
|
103
179
|
return undefined;
|
|
104
180
|
}
|
|
105
|
-
if (
|
|
106
|
-
|
|
181
|
+
if (value instanceof AgentAddress) {
|
|
182
|
+
return value;
|
|
183
|
+
}
|
|
184
|
+
if (typeof value === "object" &&
|
|
185
|
+
typeof value.toApiAddress === "function") {
|
|
186
|
+
throw new Error(`Only an AgentAddress can receive traces, got ${value.constructor?.name ?? "an unknown address"}.`);
|
|
107
187
|
}
|
|
108
|
-
|
|
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}.`);
|
|
109
190
|
}
|
|
110
191
|
/**
|
|
111
|
-
*
|
|
112
|
-
*
|
|
192
|
+
* Return `value` if it is an `Address` of any kind, as a lookup takes it.
|
|
193
|
+
* For the calls that only resolve an address to its project, such as
|
|
194
|
+
* `getRunUrl`. Whatever receives traces takes `ensureAgent`.
|
|
113
195
|
*/
|
|
114
|
-
function
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
return fromWire(values);
|
|
196
|
+
function ensureAddress(value) {
|
|
197
|
+
if (value == null) {
|
|
198
|
+
return undefined;
|
|
118
199
|
}
|
|
119
|
-
|
|
120
|
-
|
|
200
|
+
if (typeof value === "object" &&
|
|
201
|
+
typeof value.toApiAddress === "function") {
|
|
202
|
+
return value;
|
|
121
203
|
}
|
|
204
|
+
throw new Error("address must be an AgentAddress, ExperimentAddress or EvaluatorAddress, got " +
|
|
205
|
+
`${typeof value === "string" ? JSON.stringify(value) : typeof value}.`);
|
|
122
206
|
}
|
|
123
|
-
/** @internal
|
|
124
|
-
function
|
|
125
|
-
return
|
|
126
|
-
}
|
|
127
|
-
/** @internal */
|
|
128
|
-
function sameAddress(a, b) {
|
|
129
|
-
if (!a || !b) {
|
|
130
|
-
return a === b;
|
|
131
|
-
}
|
|
132
|
-
return a.agentId === b.agentId && a.agentEnvironment === b.agentEnvironment;
|
|
207
|
+
/** @internal The `LANGSMITH_AGENT_*` env var names an address reads. */
|
|
208
|
+
function envNames() {
|
|
209
|
+
return ENV_NAMES;
|
|
133
210
|
}
|
package/dist/address.d.ts
CHANGED
|
@@ -1,13 +1,68 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
/** (beta) An agent environment. */
|
|
2
|
+
export type Environment = "local" | "development" | "staging" | "production";
|
|
3
|
+
/** (beta) The backend's form of an address, as the resolve endpoint takes it. */
|
|
4
|
+
export type ApiAddress = {
|
|
5
|
+
kind: "AGENT" | "EXPERIMENT" | "EVALUATOR";
|
|
6
|
+
id?: string;
|
|
7
|
+
environment?: Uppercase<Environment>;
|
|
8
|
+
};
|
|
9
|
+
/** (beta) A feature that holds traces in a tracing project. */
|
|
5
10
|
export interface Address {
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
agentEnvironment: string;
|
|
11
|
+
/** The address in the backend's form. */
|
|
12
|
+
toApiAddress(): ApiAddress;
|
|
9
13
|
}
|
|
10
|
-
/** The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
14
|
+
/** (beta) The `LANGSMITH_AGENT_*` / project env vars name half an address, or both. */
|
|
11
15
|
export declare class EnvAddressError extends Error {
|
|
12
16
|
constructor(message: string);
|
|
13
17
|
}
|
|
18
|
+
/**
|
|
19
|
+
* (beta) The address of an agent's environment.
|
|
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
|
+
*/
|
|
38
|
+
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
|
+
}
|
|
47
|
+
/** (beta) The address of an experiment's tracing project. */
|
|
48
|
+
export declare class ExperimentAddress implements Address {
|
|
49
|
+
/** Always lowercase. */
|
|
50
|
+
readonly id: string;
|
|
51
|
+
/**
|
|
52
|
+
* @param id The experiment's UUID.
|
|
53
|
+
* @throws If `id` is not a UUID.
|
|
54
|
+
*/
|
|
55
|
+
constructor(id: string);
|
|
56
|
+
toApiAddress(): ApiAddress;
|
|
57
|
+
}
|
|
58
|
+
/** (beta) The address of the workspace's shared evaluators project. */
|
|
59
|
+
export declare class EvaluatorAddress implements Address {
|
|
60
|
+
constructor();
|
|
61
|
+
toApiAddress(): ApiAddress;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Return `value` if it is an `Address` of any kind, as a lookup takes it.
|
|
65
|
+
* For the calls that only resolve an address to its project, such as
|
|
66
|
+
* `getRunUrl`. Whatever receives traces takes `ensureAgent`.
|
|
67
|
+
*/
|
|
68
|
+
export declare function ensureAddress(value: unknown): Address | undefined;
|