langsmith 0.10.4 → 0.10.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (68) hide show
  1. package/dist/address.cjs +119 -0
  2. package/dist/address.d.ts +13 -0
  3. package/dist/address.js +107 -0
  4. package/dist/client.cjs +68 -22
  5. package/dist/client.d.ts +13 -0
  6. package/dist/client.js +68 -22
  7. package/dist/evaluation/_runner.cjs +47 -5
  8. package/dist/evaluation/_runner.d.ts +12 -0
  9. package/dist/evaluation/_runner.js +47 -5
  10. package/dist/experimental/otel/constants.cjs +5 -1
  11. package/dist/experimental/otel/constants.d.ts +3 -0
  12. package/dist/experimental/otel/constants.js +3 -0
  13. package/dist/experimental/otel/translator.cjs +14 -0
  14. package/dist/experimental/otel/translator.js +14 -0
  15. package/dist/index.cjs +4 -2
  16. package/dist/index.d.ts +2 -1
  17. package/dist/index.js +2 -1
  18. package/dist/run_trees.cjs +154 -24
  19. package/dist/run_trees.d.ts +13 -1
  20. package/dist/run_trees.js +154 -24
  21. package/dist/sandbox/access_delegation.cjs +24 -0
  22. package/dist/sandbox/access_delegation.d.ts +15 -0
  23. package/dist/sandbox/access_delegation.js +21 -0
  24. package/dist/sandbox/client.cjs +70 -5
  25. package/dist/sandbox/client.d.ts +18 -0
  26. package/dist/sandbox/client.js +70 -5
  27. package/dist/sandbox/command_handle.cjs +34 -0
  28. package/dist/sandbox/command_handle.d.ts +10 -0
  29. package/dist/sandbox/command_handle.js +34 -0
  30. package/dist/sandbox/errors.cjs +12 -1
  31. package/dist/sandbox/errors.d.ts +7 -0
  32. package/dist/sandbox/errors.js +10 -0
  33. package/dist/sandbox/helpers.cjs +129 -0
  34. package/dist/sandbox/helpers.d.ts +29 -0
  35. package/dist/sandbox/helpers.js +123 -0
  36. package/dist/sandbox/index.cjs +12 -1
  37. package/dist/sandbox/index.d.ts +8 -2
  38. package/dist/sandbox/index.js +4 -1
  39. package/dist/sandbox/mounts.cjs +21 -3
  40. package/dist/sandbox/mounts.d.ts +7 -1
  41. package/dist/sandbox/mounts.js +21 -3
  42. package/dist/sandbox/proxy_config.cjs +41 -10
  43. package/dist/sandbox/proxy_config.d.ts +33 -6
  44. package/dist/sandbox/proxy_config.js +40 -10
  45. package/dist/sandbox/sandbox.cjs +160 -4
  46. package/dist/sandbox/sandbox.d.ts +71 -1
  47. package/dist/sandbox/sandbox.js +161 -5
  48. package/dist/sandbox/service_url.cjs +125 -0
  49. package/dist/sandbox/service_url.d.ts +50 -0
  50. package/dist/sandbox/service_url.js +120 -0
  51. package/dist/sandbox/types.d.ts +251 -8
  52. package/dist/sandbox/verify.cjs +300 -0
  53. package/dist/sandbox/verify.d.ts +122 -0
  54. package/dist/sandbox/verify.js +296 -0
  55. package/dist/sandbox/ws_execute.cjs +31 -1
  56. package/dist/sandbox/ws_execute.d.ts +9 -0
  57. package/dist/sandbox/ws_execute.js +31 -1
  58. package/dist/schemas.d.ts +5 -0
  59. package/dist/traceable.cjs +7 -1
  60. package/dist/traceable.js +7 -1
  61. package/dist/utils/agent_addressing.cjs +92 -0
  62. package/dist/utils/agent_addressing.d.ts +30 -0
  63. package/dist/utils/agent_addressing.js +83 -0
  64. package/dist/utils/env.cjs +2 -0
  65. package/dist/utils/env.js +2 -0
  66. package/dist/utils/error.cjs +17 -22
  67. package/dist/utils/error.js +17 -22
  68. package/package.json +5 -5
@@ -0,0 +1,83 @@
1
+ import { EnvAddressError, addressFromEnv, envNames, normalizeAddress, toWire, wireKeys, } from "../address.js";
2
+ import { getEnvironmentVariable, getLangSmithEnvironmentVariable, } from "./env.js";
3
+ import { warnOnce } from "./warn.js";
4
+ /** Validate an address at an entry point; the SDK carries the frozen copy. */
5
+ export function checkAddress(address) {
6
+ return address == null ? undefined : normalizeAddress(address);
7
+ }
8
+ export function rejectConflicting(project, address) {
9
+ if (project && address) {
10
+ throw new Error(`A run is sent to a project (${JSON.stringify(project)}) or to an ` +
11
+ `address (${JSON.stringify(address)}), not both.`);
12
+ }
13
+ }
14
+ /** The highest level naming a project or an address, whichever it names. */
15
+ export function firstNamed(...tiers) {
16
+ for (const [project, address] of tiers) {
17
+ rejectConflicting(project, address);
18
+ if (project || address) {
19
+ return [project || undefined, address];
20
+ }
21
+ }
22
+ return [undefined, undefined];
23
+ }
24
+ function getEnvProject() {
25
+ return (getLangSmithEnvironmentVariable("PROJECT") ||
26
+ getEnvironmentVariable("LANGCHAIN_SESSION") ||
27
+ undefined);
28
+ }
29
+ /**
30
+ * The env's destination: its address, else its project, else "default".
31
+ * @throws {EnvAddressError} For half an address, or an address and a project.
32
+ */
33
+ export function resolveFromEnv() {
34
+ const project = getEnvProject();
35
+ const address = addressFromEnv();
36
+ if (project && address) {
37
+ throw new EnvAddressError("LANGSMITH_AGENT_* and a project are both set in the environment.");
38
+ }
39
+ return address ? [undefined, address] : [project ?? "default", undefined];
40
+ }
41
+ export function logUntraced(error) {
42
+ warnOnce(`LangSmith is not tracing this call: ${error.message}`);
43
+ }
44
+ /** Warn once, at client construction, if the env can't address runs. */
45
+ export function warnOnEnv() {
46
+ if (!envNames().some((name) => getEnvironmentVariable(name))) {
47
+ return;
48
+ }
49
+ try {
50
+ resolveFromEnv();
51
+ }
52
+ catch (e) {
53
+ warnOnce(`${e.message} Runs that name no destination in code are ` +
54
+ "not traced.");
55
+ }
56
+ }
57
+ /**
58
+ * Render `address` into its wire fields, in place. Without one, a create
59
+ * naming no project takes the env address. Already-rendered payloads (runs
60
+ * re-prepared when batched) are left alone.
61
+ *
62
+ * @throws {EnvAddressError} If the env names half an address.
63
+ */
64
+ export function applyToPayload(run, { update = false } = {}) {
65
+ const payload = run;
66
+ let address = checkAddress(payload.address);
67
+ delete payload.address;
68
+ const namedProject = payload.session_id != null || payload.session_name != null;
69
+ const rendered = wireKeys().some((key) => payload[key] != null);
70
+ if (!address && !update && !namedProject && !rendered) {
71
+ address = addressFromEnv();
72
+ }
73
+ if (!address) {
74
+ return;
75
+ }
76
+ warnOnce("Sending runs to an `address` is in beta and enabled per workspace; a " +
77
+ "workspace without it rejects the runs.");
78
+ Object.assign(payload, toWire(address));
79
+ if (!namedProject) {
80
+ delete payload.session_name;
81
+ delete payload.session_id;
82
+ }
83
+ }
@@ -113,6 +113,8 @@ function getLangSmithEnvVarsMetadata() {
113
113
  "LANGSMITH_CONFIG_FILE",
114
114
  "LANGSMITH_PROJECT",
115
115
  "LANGSMITH_SESSION",
116
+ "LANGSMITH_AGENT_ID",
117
+ "LANGSMITH_AGENT_ENVIRONMENT",
116
118
  ];
117
119
  for (const [key, value] of Object.entries(allEnvVars)) {
118
120
  if (typeof value === "string" &&
package/dist/utils/env.js CHANGED
@@ -95,6 +95,8 @@ export function getLangSmithEnvVarsMetadata() {
95
95
  "LANGSMITH_CONFIG_FILE",
96
96
  "LANGSMITH_PROJECT",
97
97
  "LANGSMITH_SESSION",
98
+ "LANGSMITH_AGENT_ID",
99
+ "LANGSMITH_AGENT_ENVIRONMENT",
98
100
  ];
99
101
  for (const [key, value] of Object.entries(allEnvVars)) {
100
102
  if (typeof value === "string" &&
@@ -140,32 +140,27 @@ async function raiseForStatus(response, context, consumeOnSuccess) {
140
140
  }
141
141
  return;
142
142
  }
143
+ try {
144
+ errorBody = await response.text();
145
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
146
+ }
147
+ catch (_e) {
148
+ errorBody = "";
149
+ }
143
150
  if (response.status === 403) {
151
+ let errorData;
144
152
  try {
145
- const errorData = await response.json();
146
- const errorCode = errorData?.error;
147
- if (errorCode === "org_scoped_key_requires_workspace") {
148
- errorBody =
149
- "This API key is org-scoped and requires workspace specification. " +
150
- "Please provide 'workspaceId' parameter, " +
151
- "or set LANGSMITH_WORKSPACE_ID environment variable.";
152
- }
153
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
154
- }
155
- catch (_e) {
156
- const errorWithStatus = new Error(`${response.status} ${response.statusText}`);
157
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
158
- errorWithStatus.status = response?.status;
159
- throw errorWithStatus;
153
+ errorData = JSON.parse(errorBody);
160
154
  }
161
- }
162
- if (errorBody === undefined) {
163
- try {
164
- errorBody = await response.text();
165
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
155
+ catch {
156
+ // Non-JSON body (e.g. a proxy in front of a self-hosted instance):
157
+ // fall through and surface the raw body like every other status.
166
158
  }
167
- catch (_e) {
168
- errorBody = "";
159
+ if (errorData?.error === "org_scoped_key_requires_workspace") {
160
+ errorBody =
161
+ "This API key is org-scoped and requires workspace specification. " +
162
+ "Please provide 'workspaceId' parameter, " +
163
+ "or set LANGSMITH_WORKSPACE_ID environment variable.";
169
164
  }
170
165
  }
171
166
  const fullMessage = `Failed to ${context}. Received status [${response.status}]: ${response.statusText}. Message: ${errorBody}`;
@@ -129,32 +129,27 @@ export async function raiseForStatus(response, context, consumeOnSuccess) {
129
129
  }
130
130
  return;
131
131
  }
132
+ try {
133
+ errorBody = await response.text();
134
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
135
+ }
136
+ catch (_e) {
137
+ errorBody = "";
138
+ }
132
139
  if (response.status === 403) {
140
+ let errorData;
133
141
  try {
134
- const errorData = await response.json();
135
- const errorCode = errorData?.error;
136
- if (errorCode === "org_scoped_key_requires_workspace") {
137
- errorBody =
138
- "This API key is org-scoped and requires workspace specification. " +
139
- "Please provide 'workspaceId' parameter, " +
140
- "or set LANGSMITH_WORKSPACE_ID environment variable.";
141
- }
142
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
143
- }
144
- catch (_e) {
145
- const errorWithStatus = new Error(`${response.status} ${response.statusText}`);
146
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
147
- errorWithStatus.status = response?.status;
148
- throw errorWithStatus;
142
+ errorData = JSON.parse(errorBody);
149
143
  }
150
- }
151
- if (errorBody === undefined) {
152
- try {
153
- errorBody = await response.text();
154
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
144
+ catch {
145
+ // Non-JSON body (e.g. a proxy in front of a self-hosted instance):
146
+ // fall through and surface the raw body like every other status.
155
147
  }
156
- catch (_e) {
157
- errorBody = "";
148
+ if (errorData?.error === "org_scoped_key_requires_workspace") {
149
+ errorBody =
150
+ "This API key is org-scoped and requires workspace specification. " +
151
+ "Please provide 'workspaceId' parameter, " +
152
+ "or set LANGSMITH_WORKSPACE_ID environment variable.";
158
153
  }
159
154
  }
160
155
  const fullMessage = `Failed to ${context}. Received status [${response.status}]: ${response.statusText}. Message: ${errorBody}`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.10.4",
3
+ "version": "0.10.6",
4
4
  "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "pnpm@10.33.0",
6
6
  "files": [
@@ -486,13 +486,13 @@
486
486
  "brace-expansion@<1.1.16": "1.1.16",
487
487
  "brace-expansion@>=2.0.0 <2.1.2": "2.1.2",
488
488
  "brace-expansion@>=3.0.0 <5.0.7": "5.0.7",
489
- "fast-uri": "3.1.6",
489
+ "fast-uri": "3.1.8",
490
490
  "postcss": "8.5.23",
491
491
  "js-yaml": "4.3.2",
492
492
  "hono": "4.13.5",
493
- "ip-address": "10.3.1",
494
- "undici@>=7.0.0 <8.0.0": "7.29.0",
495
- "undici@>=8.0.0 <9.0.0": "8.9.0",
493
+ "ip-address": "10.7.1",
494
+ "undici@>=7.0.0 <8.0.0": "7.29.1",
495
+ "undici@>=8.0.0 <9.0.0": "8.10.2",
496
496
  "vite": "^7.3.2",
497
497
  "form-data": "4.0.6",
498
498
  "langsmith": "0.6.0",