langsmith 0.10.3 → 0.10.4
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/client.cjs +9 -4
- package/dist/client.d.ts +1 -1
- package/dist/client.js +9 -4
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/wrappers/openai_agents.cjs +37 -28
- package/dist/wrappers/openai_agents.d.ts +0 -1
- package/dist/wrappers/openai_agents.js +37 -28
- package/package.json +2 -2
package/dist/client.cjs
CHANGED
|
@@ -82,7 +82,7 @@ function _normalizeRunTimestamps(run) {
|
|
|
82
82
|
end_time: _ensureUTCTimestamp(run.end_time),
|
|
83
83
|
};
|
|
84
84
|
}
|
|
85
|
-
function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo) {
|
|
85
|
+
function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo, tracingSampleRate) {
|
|
86
86
|
if (omitTracedRuntimeInfo) {
|
|
87
87
|
return run;
|
|
88
88
|
}
|
|
@@ -105,6 +105,9 @@ function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo) {
|
|
|
105
105
|
}
|
|
106
106
|
: {}),
|
|
107
107
|
...metadata,
|
|
108
|
+
...(tracingSampleRate !== undefined
|
|
109
|
+
? { ls_tracing_sample_rate: tracingSampleRate }
|
|
110
|
+
: {}),
|
|
108
111
|
},
|
|
109
112
|
};
|
|
110
113
|
return run;
|
|
@@ -1617,7 +1620,7 @@ class Client {
|
|
|
1617
1620
|
};
|
|
1618
1621
|
}
|
|
1619
1622
|
async _mergeRuntimeEnvAndMaskMetadata(run) {
|
|
1620
|
-
const merged = mergeRuntimeEnvIntoRun(run, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo);
|
|
1623
|
+
const merged = mergeRuntimeEnvIntoRun(run, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo, this.tracingSampleRate);
|
|
1621
1624
|
if (this.omitTracedRuntimeInfo) {
|
|
1622
1625
|
return merged;
|
|
1623
1626
|
}
|
|
@@ -1626,7 +1629,7 @@ class Client {
|
|
|
1626
1629
|
async processRunOperation(item) {
|
|
1627
1630
|
clearTimeout(this.autoBatchTimeout);
|
|
1628
1631
|
this.autoBatchTimeout = undefined;
|
|
1629
|
-
item.item = mergeRuntimeEnvIntoRun(item.item, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo);
|
|
1632
|
+
item.item = mergeRuntimeEnvIntoRun(item.item, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo, this.tracingSampleRate);
|
|
1630
1633
|
const itemPromise = this.autoBatchQueue.push(item);
|
|
1631
1634
|
if (this.manualFlushMode) {
|
|
1632
1635
|
// Rely on manual flushing in serverless environments
|
|
@@ -2227,7 +2230,9 @@ class Client {
|
|
|
2227
2230
|
if (options?.workspaceId !== undefined) {
|
|
2228
2231
|
headers["x-tenant-id"] = options.workspaceId;
|
|
2229
2232
|
}
|
|
2230
|
-
const body = (0, index_js_4.serialize)(run
|
|
2233
|
+
const body = (0, index_js_4.serialize)(run.extra
|
|
2234
|
+
? mergeRuntimeEnvIntoRun(run, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo, this.tracingSampleRate)
|
|
2235
|
+
: run, `Serializing payload to update run with id: ${runId}`);
|
|
2231
2236
|
await this.caller.call(async () => {
|
|
2232
2237
|
const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/${runId}`, {
|
|
2233
2238
|
method: "PATCH",
|
package/dist/client.d.ts
CHANGED
|
@@ -445,7 +445,7 @@ type Thread = {
|
|
|
445
445
|
export interface ListThreadsItem extends Thread {
|
|
446
446
|
runs: Run[];
|
|
447
447
|
}
|
|
448
|
-
export declare function mergeRuntimeEnvIntoRun<T extends RunCreate | RunUpdate>(run: T, cachedEnvVars?: Record<string, string>, omitTracedRuntimeInfo?: boolean): T;
|
|
448
|
+
export declare function mergeRuntimeEnvIntoRun<T extends RunCreate | RunUpdate>(run: T, cachedEnvVars?: Record<string, string>, omitTracedRuntimeInfo?: boolean, tracingSampleRate?: number): T;
|
|
449
449
|
export declare function _checkBackendVersion(backendVersion: string, minVersion: string): void;
|
|
450
450
|
export declare const DEFAULT_UNCOMPRESSED_BATCH_SIZE_LIMIT_BYTES: number;
|
|
451
451
|
/** Default maximum memory (1GB) for queue size limits. */
|
package/dist/client.js
CHANGED
|
@@ -44,7 +44,7 @@ function _normalizeRunTimestamps(run) {
|
|
|
44
44
|
end_time: _ensureUTCTimestamp(run.end_time),
|
|
45
45
|
};
|
|
46
46
|
}
|
|
47
|
-
export function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo) {
|
|
47
|
+
export function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo, tracingSampleRate) {
|
|
48
48
|
if (omitTracedRuntimeInfo) {
|
|
49
49
|
return run;
|
|
50
50
|
}
|
|
@@ -67,6 +67,9 @@ export function mergeRuntimeEnvIntoRun(run, cachedEnvVars, omitTracedRuntimeInfo
|
|
|
67
67
|
}
|
|
68
68
|
: {}),
|
|
69
69
|
...metadata,
|
|
70
|
+
...(tracingSampleRate !== undefined
|
|
71
|
+
? { ls_tracing_sample_rate: tracingSampleRate }
|
|
72
|
+
: {}),
|
|
70
73
|
},
|
|
71
74
|
};
|
|
72
75
|
return run;
|
|
@@ -1578,7 +1581,7 @@ export class Client {
|
|
|
1578
1581
|
};
|
|
1579
1582
|
}
|
|
1580
1583
|
async _mergeRuntimeEnvAndMaskMetadata(run) {
|
|
1581
|
-
const merged = mergeRuntimeEnvIntoRun(run, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo);
|
|
1584
|
+
const merged = mergeRuntimeEnvIntoRun(run, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo, this.tracingSampleRate);
|
|
1582
1585
|
if (this.omitTracedRuntimeInfo) {
|
|
1583
1586
|
return merged;
|
|
1584
1587
|
}
|
|
@@ -1587,7 +1590,7 @@ export class Client {
|
|
|
1587
1590
|
async processRunOperation(item) {
|
|
1588
1591
|
clearTimeout(this.autoBatchTimeout);
|
|
1589
1592
|
this.autoBatchTimeout = undefined;
|
|
1590
|
-
item.item = mergeRuntimeEnvIntoRun(item.item, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo);
|
|
1593
|
+
item.item = mergeRuntimeEnvIntoRun(item.item, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo, this.tracingSampleRate);
|
|
1591
1594
|
const itemPromise = this.autoBatchQueue.push(item);
|
|
1592
1595
|
if (this.manualFlushMode) {
|
|
1593
1596
|
// Rely on manual flushing in serverless environments
|
|
@@ -2188,7 +2191,9 @@ export class Client {
|
|
|
2188
2191
|
if (options?.workspaceId !== undefined) {
|
|
2189
2192
|
headers["x-tenant-id"] = options.workspaceId;
|
|
2190
2193
|
}
|
|
2191
|
-
const body = serializePayloadForTracing(run
|
|
2194
|
+
const body = serializePayloadForTracing(run.extra
|
|
2195
|
+
? mergeRuntimeEnvIntoRun(run, this.cachedLSEnvVarsForMetadata, this.omitTracedRuntimeInfo, this.tracingSampleRate)
|
|
2196
|
+
: run, `Serializing payload to update run with id: ${runId}`);
|
|
2192
2197
|
await this.caller.call(async () => {
|
|
2193
2198
|
const res = await this._fetch(`${options?.apiUrl ?? this.apiUrl}/runs/${runId}`, {
|
|
2194
2199
|
method: "PATCH",
|
package/dist/index.cjs
CHANGED
|
@@ -35,6 +35,6 @@ Object.defineProperty(exports, "UnprocessableEntityError", { enumerable: true, g
|
|
|
35
35
|
Object.defineProperty(exports, "RateLimitError", { enumerable: true, get: function () { return error_js_1.RateLimitError; } });
|
|
36
36
|
Object.defineProperty(exports, "InternalServerError", { enumerable: true, get: function () { return error_js_1.InternalServerError; } });
|
|
37
37
|
// Update using pnpm bump-version
|
|
38
|
-
exports.__version__ = "0.10.
|
|
38
|
+
exports.__version__ = "0.10.4";
|
|
39
39
|
// Metadata key to hide a traced run from LangSmith's Messages View.
|
|
40
40
|
exports.LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
|
package/dist/index.d.ts
CHANGED
|
@@ -7,5 +7,5 @@ export { computeRunIdForSecondaryReplica, uuid7, uuid7FromTime, } from "./uuid.j
|
|
|
7
7
|
export { isTracingEnabled } from "./utils/guard.js";
|
|
8
8
|
export { Cache, PromptCache, type CacheConfig, type CacheMetrics, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
9
9
|
export { LangsmithError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./_openapi_client/core/error.js";
|
|
10
|
-
export declare const __version__ = "0.10.
|
|
10
|
+
export declare const __version__ = "0.10.4";
|
|
11
11
|
export declare const LS_MESSAGE_VIEW_EXCLUDE: "ls_message_view_exclude";
|
package/dist/index.js
CHANGED
|
@@ -7,6 +7,6 @@ export { isTracingEnabled } from "./utils/guard.js";
|
|
|
7
7
|
export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
8
8
|
export { LangsmithError, APIError, APIUserAbortError, APIConnectionError, APIConnectionTimeoutError, BadRequestError, AuthenticationError, PermissionDeniedError, NotFoundError, ConflictError, UnprocessableEntityError, RateLimitError, InternalServerError, } from "./_openapi_client/core/error.js";
|
|
9
9
|
// Update using pnpm bump-version
|
|
10
|
-
export const __version__ = "0.10.
|
|
10
|
+
export const __version__ = "0.10.4";
|
|
11
11
|
// Metadata key to hide a traced run from LangSmith's Messages View.
|
|
12
12
|
export const LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
|
|
@@ -369,6 +369,33 @@ function createResponsesUsageMetadata(usage) {
|
|
|
369
369
|
}
|
|
370
370
|
return result;
|
|
371
371
|
}
|
|
372
|
+
/**
|
|
373
|
+
* Return an ls_agent_type for the span, or undefined to leave it alone.
|
|
374
|
+
*
|
|
375
|
+
* If the run already has middleware/subagent/compaction, keep it. Otherwise
|
|
376
|
+
* guardrails become middleware and agents under any tool become subagents.
|
|
377
|
+
*
|
|
378
|
+
* Openai-agents structural counterpart to resolveVercelLsAgentType.
|
|
379
|
+
*/
|
|
380
|
+
function _resolveOpenAIAgentsLsAgentType(spanData, parentRun, existingTag) {
|
|
381
|
+
if (typeof existingTag === "string" &&
|
|
382
|
+
ls_agent_type_js_1.NON_ROOT_LS_AGENT_TYPES.has(existingTag)) {
|
|
383
|
+
return undefined;
|
|
384
|
+
}
|
|
385
|
+
if (spanData.type === "guardrail")
|
|
386
|
+
return "middleware";
|
|
387
|
+
// Walk the full parent chain, not just the direct parent: asTool inserts
|
|
388
|
+
// a chain run between the tool and the inner agent span.
|
|
389
|
+
if (spanData.type === "agent") {
|
|
390
|
+
let cursor = parentRun;
|
|
391
|
+
while (cursor !== undefined) {
|
|
392
|
+
if (cursor.run_type === "tool")
|
|
393
|
+
return "subagent";
|
|
394
|
+
cursor = cursor.parent_run;
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return undefined;
|
|
398
|
+
}
|
|
372
399
|
/**
|
|
373
400
|
* Tracing processor for the [OpenAI Agents SDK](https://openai.github.io/openai-agents-js/).
|
|
374
401
|
*
|
|
@@ -463,12 +490,6 @@ class OpenAIAgentsTracingProcessor {
|
|
|
463
490
|
writable: true,
|
|
464
491
|
value: new Map()
|
|
465
492
|
});
|
|
466
|
-
Object.defineProperty(this, "_spanDataTypes", {
|
|
467
|
-
enumerable: true,
|
|
468
|
-
configurable: true,
|
|
469
|
-
writable: true,
|
|
470
|
-
value: new Map()
|
|
471
|
-
});
|
|
472
493
|
Object.defineProperty(this, "_unpostedTraces", {
|
|
473
494
|
enumerable: true,
|
|
474
495
|
configurable: true,
|
|
@@ -684,28 +705,17 @@ class OpenAIAgentsTracingProcessor {
|
|
|
684
705
|
console.error("Error creating span run:", e);
|
|
685
706
|
return;
|
|
686
707
|
}
|
|
687
|
-
//
|
|
688
|
-
//
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
}
|
|
698
|
-
if (!childRun.extra.metadata) {
|
|
699
|
-
childRun.extra.metadata = {};
|
|
700
|
-
}
|
|
701
|
-
const meta = childRun.extra.metadata;
|
|
702
|
-
if (!ls_agent_type_js_1.NON_ROOT_LS_AGENT_TYPES.has(meta.ls_agent_type)) {
|
|
703
|
-
meta.ls_agent_type = "subagent";
|
|
704
|
-
}
|
|
705
|
-
}
|
|
708
|
+
// Handoffs replace the caller rather than run as a tool, so a handoff
|
|
709
|
+
// agent has no tool ancestor and correctly stays untagged here.
|
|
710
|
+
if (!childRun.extra)
|
|
711
|
+
childRun.extra = {};
|
|
712
|
+
if (!childRun.extra.metadata)
|
|
713
|
+
childRun.extra.metadata = {};
|
|
714
|
+
const meta = childRun.extra.metadata;
|
|
715
|
+
const structuralTag = _resolveOpenAIAgentsLsAgentType(spanData, parentRun, meta.ls_agent_type);
|
|
716
|
+
if (structuralTag !== undefined) {
|
|
717
|
+
meta.ls_agent_type = structuralTag;
|
|
706
718
|
}
|
|
707
|
-
// Track span data type for parent lookups
|
|
708
|
-
this._spanDataTypes.set(span.spanId, spanData.type);
|
|
709
719
|
this._runs.set(span.spanId, childRun);
|
|
710
720
|
// Enter AsyncLocalStorage context synchronously so nested traceable()
|
|
711
721
|
// calls inside the span's body nest under this run. Remember the
|
|
@@ -741,7 +751,6 @@ class OpenAIAgentsTracingProcessor {
|
|
|
741
751
|
enterRunTreeContext(previousStore);
|
|
742
752
|
}
|
|
743
753
|
const run = this._runs.get(span.spanId);
|
|
744
|
-
this._spanDataTypes.delete(span.spanId);
|
|
745
754
|
if (!run) {
|
|
746
755
|
return;
|
|
747
756
|
}
|
|
@@ -69,7 +69,6 @@ export declare class OpenAIAgentsTracingProcessor implements TracingProcessor {
|
|
|
69
69
|
private _firstResponseInputs;
|
|
70
70
|
private _lastResponseOutputs;
|
|
71
71
|
private _runs;
|
|
72
|
-
private _spanDataTypes;
|
|
73
72
|
private _unpostedTraces;
|
|
74
73
|
private _unpostedSpans;
|
|
75
74
|
private _previousStoreByTrace;
|
|
@@ -366,6 +366,33 @@ function createResponsesUsageMetadata(usage) {
|
|
|
366
366
|
}
|
|
367
367
|
return result;
|
|
368
368
|
}
|
|
369
|
+
/**
|
|
370
|
+
* Return an ls_agent_type for the span, or undefined to leave it alone.
|
|
371
|
+
*
|
|
372
|
+
* If the run already has middleware/subagent/compaction, keep it. Otherwise
|
|
373
|
+
* guardrails become middleware and agents under any tool become subagents.
|
|
374
|
+
*
|
|
375
|
+
* Openai-agents structural counterpart to resolveVercelLsAgentType.
|
|
376
|
+
*/
|
|
377
|
+
function _resolveOpenAIAgentsLsAgentType(spanData, parentRun, existingTag) {
|
|
378
|
+
if (typeof existingTag === "string" &&
|
|
379
|
+
NON_ROOT_LS_AGENT_TYPES.has(existingTag)) {
|
|
380
|
+
return undefined;
|
|
381
|
+
}
|
|
382
|
+
if (spanData.type === "guardrail")
|
|
383
|
+
return "middleware";
|
|
384
|
+
// Walk the full parent chain, not just the direct parent: asTool inserts
|
|
385
|
+
// a chain run between the tool and the inner agent span.
|
|
386
|
+
if (spanData.type === "agent") {
|
|
387
|
+
let cursor = parentRun;
|
|
388
|
+
while (cursor !== undefined) {
|
|
389
|
+
if (cursor.run_type === "tool")
|
|
390
|
+
return "subagent";
|
|
391
|
+
cursor = cursor.parent_run;
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
return undefined;
|
|
395
|
+
}
|
|
369
396
|
/**
|
|
370
397
|
* Tracing processor for the [OpenAI Agents SDK](https://openai.github.io/openai-agents-js/).
|
|
371
398
|
*
|
|
@@ -460,12 +487,6 @@ export class OpenAIAgentsTracingProcessor {
|
|
|
460
487
|
writable: true,
|
|
461
488
|
value: new Map()
|
|
462
489
|
});
|
|
463
|
-
Object.defineProperty(this, "_spanDataTypes", {
|
|
464
|
-
enumerable: true,
|
|
465
|
-
configurable: true,
|
|
466
|
-
writable: true,
|
|
467
|
-
value: new Map()
|
|
468
|
-
});
|
|
469
490
|
Object.defineProperty(this, "_unpostedTraces", {
|
|
470
491
|
enumerable: true,
|
|
471
492
|
configurable: true,
|
|
@@ -681,28 +702,17 @@ export class OpenAIAgentsTracingProcessor {
|
|
|
681
702
|
console.error("Error creating span run:", e);
|
|
682
703
|
return;
|
|
683
704
|
}
|
|
684
|
-
//
|
|
685
|
-
//
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
}
|
|
695
|
-
if (!childRun.extra.metadata) {
|
|
696
|
-
childRun.extra.metadata = {};
|
|
697
|
-
}
|
|
698
|
-
const meta = childRun.extra.metadata;
|
|
699
|
-
if (!NON_ROOT_LS_AGENT_TYPES.has(meta.ls_agent_type)) {
|
|
700
|
-
meta.ls_agent_type = "subagent";
|
|
701
|
-
}
|
|
702
|
-
}
|
|
705
|
+
// Handoffs replace the caller rather than run as a tool, so a handoff
|
|
706
|
+
// agent has no tool ancestor and correctly stays untagged here.
|
|
707
|
+
if (!childRun.extra)
|
|
708
|
+
childRun.extra = {};
|
|
709
|
+
if (!childRun.extra.metadata)
|
|
710
|
+
childRun.extra.metadata = {};
|
|
711
|
+
const meta = childRun.extra.metadata;
|
|
712
|
+
const structuralTag = _resolveOpenAIAgentsLsAgentType(spanData, parentRun, meta.ls_agent_type);
|
|
713
|
+
if (structuralTag !== undefined) {
|
|
714
|
+
meta.ls_agent_type = structuralTag;
|
|
703
715
|
}
|
|
704
|
-
// Track span data type for parent lookups
|
|
705
|
-
this._spanDataTypes.set(span.spanId, spanData.type);
|
|
706
716
|
this._runs.set(span.spanId, childRun);
|
|
707
717
|
// Enter AsyncLocalStorage context synchronously so nested traceable()
|
|
708
718
|
// calls inside the span's body nest under this run. Remember the
|
|
@@ -738,7 +748,6 @@ export class OpenAIAgentsTracingProcessor {
|
|
|
738
748
|
enterRunTreeContext(previousStore);
|
|
739
749
|
}
|
|
740
750
|
const run = this._runs.get(span.spanId);
|
|
741
|
-
this._spanDataTypes.delete(span.spanId);
|
|
742
751
|
if (!run) {
|
|
743
752
|
return;
|
|
744
753
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "langsmith",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.4",
|
|
4
4
|
"description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
|
|
5
5
|
"packageManager": "pnpm@10.33.0",
|
|
6
6
|
"files": [
|
|
@@ -488,7 +488,7 @@
|
|
|
488
488
|
"brace-expansion@>=3.0.0 <5.0.7": "5.0.7",
|
|
489
489
|
"fast-uri": "3.1.6",
|
|
490
490
|
"postcss": "8.5.23",
|
|
491
|
-
"js-yaml": "4.3.
|
|
491
|
+
"js-yaml": "4.3.2",
|
|
492
492
|
"hono": "4.13.5",
|
|
493
493
|
"ip-address": "10.3.1",
|
|
494
494
|
"undici@>=7.0.0 <8.0.0": "7.29.0",
|