langsmith 0.7.16 → 0.7.17
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 +16 -8
- package/dist/_openapi_client/client.d.ts +6 -3
- package/dist/_openapi_client/client.js +16 -8
- package/dist/_openapi_client/resources/index.cjs +5 -3
- package/dist/_openapi_client/resources/index.d.ts +2 -1
- package/dist/_openapi_client/resources/index.js +2 -1
- package/dist/_openapi_client/resources/runs.d.ts +11 -2
- package/dist/_openapi_client/resources/threads.cjs +65 -0
- package/dist/_openapi_client/resources/threads.d.ts +654 -0
- package/dist/_openapi_client/resources/threads.js +61 -0
- package/dist/_openapi_client/resources/traces.cjs +61 -0
- package/dist/_openapi_client/resources/traces.d.ts +162 -0
- package/dist/_openapi_client/resources/traces.js +57 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/wrappers/anthropic.cjs +38 -25
- package/dist/wrappers/anthropic.d.ts +10 -1
- package/dist/wrappers/anthropic.js +38 -25
- package/dist/wrappers/utils/anthropic_managed.cjs +648 -0
- package/dist/wrappers/utils/anthropic_managed.d.ts +7 -0
- package/dist/wrappers/utils/anthropic_managed.js +645 -0
- package/package.json +1 -1
- package/dist/_openapi_client/resources/sessions.cjs +0 -53
- package/dist/_openapi_client/resources/sessions.d.ts +0 -636
- package/dist/_openapi_client/resources/sessions.js +0 -49
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
import { APIResource } from '../core/resource.js';
|
|
4
|
+
import { ItemsCursorGetPagination, ItemsCursorPostPagination, } from '../core/pagination.js';
|
|
5
|
+
import { path } from '../internal/utils/path.js';
|
|
6
|
+
export class Threads extends APIResource {
|
|
7
|
+
/**
|
|
8
|
+
* **Alpha:** The request and response contract may change; Retrieve all traces
|
|
9
|
+
* belonging to a specific thread within a project.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```ts
|
|
13
|
+
* // Automatically fetches more pages as needed.
|
|
14
|
+
* for await (const threadTraceListItem of client.threads.listTraces(
|
|
15
|
+
* 'thread_id',
|
|
16
|
+
* { project_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' },
|
|
17
|
+
* )) {
|
|
18
|
+
* // ...
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
*/
|
|
22
|
+
listTraces(threadID, query, options) {
|
|
23
|
+
return this._client.getAPIList(path `/v2/threads/${threadID}/traces`, (ItemsCursorGetPagination), { query, ...options });
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* **Alpha:** The request and response contract may change; Query threads within a
|
|
27
|
+
* project (session), with cursor-based pagination. Returns threads matching the
|
|
28
|
+
* given time range and optional filter.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* // Automatically fetches more pages as needed.
|
|
33
|
+
* for await (const threadListItem of client.threads.query()) {
|
|
34
|
+
* // ...
|
|
35
|
+
* }
|
|
36
|
+
* ```
|
|
37
|
+
*/
|
|
38
|
+
query(body, options) {
|
|
39
|
+
return this._client.getAPIList('/v2/threads/query', (ItemsCursorPostPagination), {
|
|
40
|
+
body,
|
|
41
|
+
method: 'post',
|
|
42
|
+
...options,
|
|
43
|
+
});
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* **Alpha:** The request and response contract may change; Compute aggregate stats
|
|
47
|
+
* for a single thread (turn count, latency percentiles, token/cost sums, and
|
|
48
|
+
* detail breakdowns) within a project.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```ts
|
|
52
|
+
* const response = await client.threads.stats('thread_id', {
|
|
53
|
+
* selects: ['TURNS'],
|
|
54
|
+
* session_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
|
|
55
|
+
* });
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
stats(threadID, query, options) {
|
|
59
|
+
return this._client.get(path `/v2/threads/${threadID}/stats`, { query, ...options });
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// @ts-nocheck
|
|
3
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
4
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
5
|
+
exports.Traces = void 0;
|
|
6
|
+
const resource_js_1 = require("../core/resource.cjs");
|
|
7
|
+
const pagination_js_1 = require("../core/pagination.cjs");
|
|
8
|
+
const headers_js_1 = require("../internal/headers.cjs");
|
|
9
|
+
const path_js_1 = require("../internal/utils/path.cjs");
|
|
10
|
+
class Traces extends resource_js_1.APIResource {
|
|
11
|
+
/**
|
|
12
|
+
* **Alpha:** The request and response contract may change; Returns runs for a
|
|
13
|
+
* trace ID within min/max start time. Optional `filter`; repeatable `selects` to
|
|
14
|
+
* select fields to return.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```ts
|
|
18
|
+
* const response = await client.traces.listRuns(
|
|
19
|
+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
|
|
20
|
+
* { project_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' },
|
|
21
|
+
* );
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
listRuns(traceID, params, options) {
|
|
25
|
+
const { Accept, ...query } = params;
|
|
26
|
+
return this._client.get((0, path_js_1.path) `/v2/traces/${traceID}/runs`, {
|
|
27
|
+
query,
|
|
28
|
+
...options,
|
|
29
|
+
headers: (0, headers_js_1.buildHeaders)([{ ...(Accept != null ? { Accept: Accept } : undefined) }, options?.headers]),
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Returns a paginated list of traces (root runs) for a single tracing project.
|
|
34
|
+
* Each item carries the trace's root run plus optional trace-wide aggregates
|
|
35
|
+
* (`total_tokens`, `total_cost`, `first_token_time`) under `trace_aggregates`, so
|
|
36
|
+
* clients never have to merge by `trace_id`.
|
|
37
|
+
*
|
|
38
|
+
* Traces are scanned within a `start_time` window: `min_start_time` defaults to 24
|
|
39
|
+
* hours before the request, `max_start_time` defaults to the request time. Set
|
|
40
|
+
* either explicitly to widen or narrow the window.
|
|
41
|
+
*
|
|
42
|
+
* Supports filters (`trace_filter`, `tree_filter`), cursor pagination (`cursor`),
|
|
43
|
+
* and field projection (`selects`).
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* ```ts
|
|
47
|
+
* // Automatically fetches more pages as needed.
|
|
48
|
+
* for await (const trace of client.traces.query()) {
|
|
49
|
+
* // ...
|
|
50
|
+
* }
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
query(body, options) {
|
|
54
|
+
return this._client.getAPIList('/v2/traces/query', (pagination_js_1.ItemsCursorPostPagination), {
|
|
55
|
+
body,
|
|
56
|
+
method: 'post',
|
|
57
|
+
...options,
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
exports.Traces = Traces;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import { APIResource } from '../core/resource.js';
|
|
2
|
+
import * as RunsAPI from './runs.js';
|
|
3
|
+
import { APIPromise } from '../core/api-promise.js';
|
|
4
|
+
import { ItemsCursorPostPagination, type ItemsCursorPostPaginationParams, PagePromise } from '../core/pagination.js';
|
|
5
|
+
import { RequestOptions } from '../internal/request-options.js';
|
|
6
|
+
export declare class Traces extends APIResource {
|
|
7
|
+
/**
|
|
8
|
+
* **Alpha:** The request and response contract may change; Returns runs for a
|
|
9
|
+
* trace ID within min/max start time. Optional `filter`; repeatable `selects` to
|
|
10
|
+
* select fields to return.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```ts
|
|
14
|
+
* const response = await client.traces.listRuns(
|
|
15
|
+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
|
|
16
|
+
* { project_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' },
|
|
17
|
+
* );
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
listRuns(traceID: string, params: TraceListRunsParams, options?: RequestOptions): APIPromise<TraceListRunsResponse>;
|
|
21
|
+
/**
|
|
22
|
+
* Returns a paginated list of traces (root runs) for a single tracing project.
|
|
23
|
+
* Each item carries the trace's root run plus optional trace-wide aggregates
|
|
24
|
+
* (`total_tokens`, `total_cost`, `first_token_time`) under `trace_aggregates`, so
|
|
25
|
+
* clients never have to merge by `trace_id`.
|
|
26
|
+
*
|
|
27
|
+
* Traces are scanned within a `start_time` window: `min_start_time` defaults to 24
|
|
28
|
+
* hours before the request, `max_start_time` defaults to the request time. Set
|
|
29
|
+
* either explicitly to widen or narrow the window.
|
|
30
|
+
*
|
|
31
|
+
* Supports filters (`trace_filter`, `tree_filter`), cursor pagination (`cursor`),
|
|
32
|
+
* and field projection (`selects`).
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* // Automatically fetches more pages as needed.
|
|
37
|
+
* for await (const trace of client.traces.query()) {
|
|
38
|
+
* // ...
|
|
39
|
+
* }
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
query(body: TraceQueryParams, options?: RequestOptions): PagePromise<TracesItemsCursorPostPagination, Trace>;
|
|
43
|
+
}
|
|
44
|
+
export type TracesItemsCursorPostPagination = ItemsCursorPostPagination<Trace>;
|
|
45
|
+
export interface Trace {
|
|
46
|
+
/**
|
|
47
|
+
* `root_run` is the trace's root run. Which properties are populated is controlled
|
|
48
|
+
* by `selects` in the request.
|
|
49
|
+
*/
|
|
50
|
+
root_run?: RunsAPI.Run;
|
|
51
|
+
/**
|
|
52
|
+
* `trace_aggregates` carries trace-wide aggregate metrics. Omitted when no
|
|
53
|
+
* aggregate field was selected, or `null` (then later filled) on the streaming
|
|
54
|
+
* wire while the aggregate values are still being computed.
|
|
55
|
+
*/
|
|
56
|
+
trace_aggregates?: TraceAggregates;
|
|
57
|
+
}
|
|
58
|
+
export interface TraceAggregates {
|
|
59
|
+
/**
|
|
60
|
+
* `first_token_time` is when the first output token was produced anywhere in the
|
|
61
|
+
* trace (RFC3339), when recorded.
|
|
62
|
+
*/
|
|
63
|
+
first_token_time?: string;
|
|
64
|
+
/**
|
|
65
|
+
* `total_cost` is total estimated USD cost across every run in the trace.
|
|
66
|
+
*/
|
|
67
|
+
total_cost?: number;
|
|
68
|
+
/**
|
|
69
|
+
* `total_tokens` is prompt plus completion tokens summed across every run in the
|
|
70
|
+
* trace.
|
|
71
|
+
*/
|
|
72
|
+
total_tokens?: number;
|
|
73
|
+
}
|
|
74
|
+
export interface TraceListRunsResponse {
|
|
75
|
+
/**
|
|
76
|
+
* `items` lists runs in the trace for the requested time window, in `start_time`
|
|
77
|
+
* order.
|
|
78
|
+
*/
|
|
79
|
+
items?: Array<RunsAPI.Run>;
|
|
80
|
+
}
|
|
81
|
+
export interface TraceListRunsParams {
|
|
82
|
+
/**
|
|
83
|
+
* Query param: `project_id` is the UUID of the tracing project that owns the
|
|
84
|
+
* trace.
|
|
85
|
+
*/
|
|
86
|
+
project_id: string;
|
|
87
|
+
/**
|
|
88
|
+
* Query param: `filter` narrows which runs within this trace are returned, using a
|
|
89
|
+
* LangSmith filter expression evaluated against each run. For example:
|
|
90
|
+
* `eq(run_type, "llm")` for LLM runs only, or `eq(status, "error")` for failed
|
|
91
|
+
* runs. See
|
|
92
|
+
* https://docs.langchain.com/langsmith/trace-query-syntax#filter-query-language
|
|
93
|
+
* for syntax.
|
|
94
|
+
*/
|
|
95
|
+
filter?: string;
|
|
96
|
+
/**
|
|
97
|
+
* Query param: `max_start_time` is the optional inclusive upper bound for run
|
|
98
|
+
* `start_time` (RFC3339 date-time). Required together with `min_start_time`.
|
|
99
|
+
*/
|
|
100
|
+
max_start_time?: string;
|
|
101
|
+
/**
|
|
102
|
+
* Query param: `min_start_time` is the optional inclusive lower bound for run
|
|
103
|
+
* `start_time` (RFC3339 date-time). Required together with `max_start_time`.
|
|
104
|
+
*/
|
|
105
|
+
min_start_time?: string;
|
|
106
|
+
/**
|
|
107
|
+
* Query param: `selects` lists which properties to include on each returned run
|
|
108
|
+
* (repeatable query parameter). Accepts any value of the `RunSelectField` enum. If
|
|
109
|
+
* omitted, only `id` is returned.
|
|
110
|
+
*/
|
|
111
|
+
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' | 'SHARE_URL' | 'FEEDBACK_STATS'>;
|
|
112
|
+
/**
|
|
113
|
+
* Header param: application/json
|
|
114
|
+
*/
|
|
115
|
+
Accept?: string;
|
|
116
|
+
}
|
|
117
|
+
export interface TraceQueryParams extends ItemsCursorPostPaginationParams {
|
|
118
|
+
/**
|
|
119
|
+
* `max_start_time` is the exclusive upper bound for the root-run start time scan
|
|
120
|
+
* (RFC3339). Defaults to the request time when omitted.
|
|
121
|
+
*/
|
|
122
|
+
max_start_time?: string;
|
|
123
|
+
/**
|
|
124
|
+
* `min_start_time` is the inclusive lower bound for the root-run start time scan
|
|
125
|
+
* (RFC3339). Defaults to 24 hours before the request when omitted.
|
|
126
|
+
*/
|
|
127
|
+
min_start_time?: string;
|
|
128
|
+
/**
|
|
129
|
+
* `project_id` is the UUID of the tracing project that owns the traces. Required.
|
|
130
|
+
*/
|
|
131
|
+
project_id?: string;
|
|
132
|
+
/**
|
|
133
|
+
* `selects` lists which properties to include on each returned trace. Properties
|
|
134
|
+
* listed here are routed to the appropriate sub-object on each item:
|
|
135
|
+
* `total_tokens`, `total_cost`, and `first_token_time` appear under
|
|
136
|
+
* `trace_aggregates`; everything else appears under `root_run`. If omitted, only
|
|
137
|
+
* `id` is returned on `root_run`.
|
|
138
|
+
*/
|
|
139
|
+
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' | 'SHARE_URL' | 'FEEDBACK_STATS'>;
|
|
140
|
+
/**
|
|
141
|
+
* `trace_filter` narrows results to traces whose root run matches this LangSmith
|
|
142
|
+
* filter expression. This filter targets root runs only — `is_root = true` is
|
|
143
|
+
* implied. See
|
|
144
|
+
* https://docs.langchain.com/langsmith/trace-query-syntax#filter-query-language
|
|
145
|
+
* for syntax.
|
|
146
|
+
*/
|
|
147
|
+
trace_filter?: string;
|
|
148
|
+
/**
|
|
149
|
+
* `trace_ids` is an optional fast-path restriction to a known set of trace UUIDs.
|
|
150
|
+
* Equivalent in result to including each UUID in a `trace_filter`, but more
|
|
151
|
+
* efficient at scale.
|
|
152
|
+
*/
|
|
153
|
+
trace_ids?: Array<string>;
|
|
154
|
+
/**
|
|
155
|
+
* `tree_filter` narrows results to traces containing at least one run anywhere in
|
|
156
|
+
* the run tree (root or descendant) that matches this LangSmith filter expression.
|
|
157
|
+
*/
|
|
158
|
+
tree_filter?: string;
|
|
159
|
+
}
|
|
160
|
+
export declare namespace Traces {
|
|
161
|
+
export { type Trace as Trace, type TraceAggregates as TraceAggregates, type TraceListRunsResponse as TraceListRunsResponse, type TracesItemsCursorPostPagination as TracesItemsCursorPostPagination, type TraceListRunsParams as TraceListRunsParams, type TraceQueryParams as TraceQueryParams, };
|
|
162
|
+
}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
// File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
|
|
3
|
+
import { APIResource } from '../core/resource.js';
|
|
4
|
+
import { ItemsCursorPostPagination, } from '../core/pagination.js';
|
|
5
|
+
import { buildHeaders } from '../internal/headers.js';
|
|
6
|
+
import { path } from '../internal/utils/path.js';
|
|
7
|
+
export class Traces extends APIResource {
|
|
8
|
+
/**
|
|
9
|
+
* **Alpha:** The request and response contract may change; Returns runs for a
|
|
10
|
+
* trace ID within min/max start time. Optional `filter`; repeatable `selects` to
|
|
11
|
+
* select fields to return.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```ts
|
|
15
|
+
* const response = await client.traces.listRuns(
|
|
16
|
+
* '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
|
|
17
|
+
* { project_id: '182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e' },
|
|
18
|
+
* );
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
listRuns(traceID, params, options) {
|
|
22
|
+
const { Accept, ...query } = params;
|
|
23
|
+
return this._client.get(path `/v2/traces/${traceID}/runs`, {
|
|
24
|
+
query,
|
|
25
|
+
...options,
|
|
26
|
+
headers: buildHeaders([{ ...(Accept != null ? { Accept: Accept } : undefined) }, options?.headers]),
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Returns a paginated list of traces (root runs) for a single tracing project.
|
|
31
|
+
* Each item carries the trace's root run plus optional trace-wide aggregates
|
|
32
|
+
* (`total_tokens`, `total_cost`, `first_token_time`) under `trace_aggregates`, so
|
|
33
|
+
* clients never have to merge by `trace_id`.
|
|
34
|
+
*
|
|
35
|
+
* Traces are scanned within a `start_time` window: `min_start_time` defaults to 24
|
|
36
|
+
* hours before the request, `max_start_time` defaults to the request time. Set
|
|
37
|
+
* either explicitly to widen or narrow the window.
|
|
38
|
+
*
|
|
39
|
+
* Supports filters (`trace_filter`, `tree_filter`), cursor pagination (`cursor`),
|
|
40
|
+
* and field projection (`selects`).
|
|
41
|
+
*
|
|
42
|
+
* @example
|
|
43
|
+
* ```ts
|
|
44
|
+
* // Automatically fetches more pages as needed.
|
|
45
|
+
* for await (const trace of client.traces.query()) {
|
|
46
|
+
* // ...
|
|
47
|
+
* }
|
|
48
|
+
* ```
|
|
49
|
+
*/
|
|
50
|
+
query(body, options) {
|
|
51
|
+
return this._client.getAPIList('/v2/traces/query', (ItemsCursorPostPagination), {
|
|
52
|
+
body,
|
|
53
|
+
method: 'post',
|
|
54
|
+
...options,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
package/dist/index.cjs
CHANGED
|
@@ -20,6 +20,6 @@ Object.defineProperty(exports, "PromptCache", { enumerable: true, get: function
|
|
|
20
20
|
Object.defineProperty(exports, "configureGlobalPromptCache", { enumerable: true, get: function () { return index_js_1.configureGlobalPromptCache; } });
|
|
21
21
|
Object.defineProperty(exports, "promptCacheSingleton", { enumerable: true, get: function () { return index_js_1.promptCacheSingleton; } });
|
|
22
22
|
// Update using pnpm bump-version
|
|
23
|
-
exports.__version__ = "0.7.
|
|
23
|
+
exports.__version__ = "0.7.17";
|
|
24
24
|
// Metadata key to hide a traced run from LangSmith's Messages View.
|
|
25
25
|
exports.LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
|
package/dist/index.d.ts
CHANGED
|
@@ -6,5 +6,5 @@ export { getDefaultProjectName } from "./utils/project.js";
|
|
|
6
6
|
export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
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
|
-
export declare const __version__ = "0.7.
|
|
9
|
+
export declare const __version__ = "0.7.17";
|
|
10
10
|
export declare const LS_MESSAGE_VIEW_EXCLUDE: "ls_message_view_exclude";
|
package/dist/index.js
CHANGED
|
@@ -6,6 +6,6 @@ export { uuid7, uuid7FromTime } from "./uuid.js";
|
|
|
6
6
|
export { isTracingEnabled } from "./utils/guard.js";
|
|
7
7
|
export { Cache, PromptCache, configureGlobalPromptCache, promptCacheSingleton, } from "./utils/prompt_cache/index.js";
|
|
8
8
|
// Update using pnpm bump-version
|
|
9
|
-
export const __version__ = "0.7.
|
|
9
|
+
export const __version__ = "0.7.17";
|
|
10
10
|
// Metadata key to hide a traced run from LangSmith's Messages View.
|
|
11
11
|
export const LS_MESSAGE_VIEW_EXCLUDE = "ls_message_view_exclude";
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.wrapAnthropic = void 0;
|
|
4
4
|
exports.createUsageMetadata = createUsageMetadata;
|
|
5
|
+
const anthropic_managed_js_1 = require("./utils/anthropic_managed.cjs");
|
|
5
6
|
const traceable_js_1 = require("../traceable.cjs");
|
|
6
7
|
const usage_js_1 = require("../utils/usage.cjs");
|
|
7
8
|
const TRACED_INVOCATION_KEYS = ["top_k", "top_p", "stream", "thinking"];
|
|
@@ -198,7 +199,11 @@ const messageAggregator = (chunks) => {
|
|
|
198
199
|
*/
|
|
199
200
|
const wrapAnthropic = (anthropic, options) => {
|
|
200
201
|
if ((0, traceable_js_1.isTraceableFunction)(anthropic.messages.create) ||
|
|
201
|
-
(0, traceable_js_1.isTraceableFunction)(anthropic.messages.stream)
|
|
202
|
+
(0, traceable_js_1.isTraceableFunction)(anthropic.messages.stream) ||
|
|
203
|
+
(anthropic.beta?.sessions?.events?.stream &&
|
|
204
|
+
(0, traceable_js_1.isTraceableFunction)(anthropic.beta.sessions.events.stream)) ||
|
|
205
|
+
(anthropic.beta?.sessions?.events?.send &&
|
|
206
|
+
(0, traceable_js_1.isTraceableFunction)(anthropic.beta.sessions.events.send))) {
|
|
202
207
|
throw new Error("This instance of Anthropic client has been already wrapped once.");
|
|
203
208
|
}
|
|
204
209
|
const tracedAnthropicClient = { ...anthropic };
|
|
@@ -315,33 +320,41 @@ const wrapAnthropic = (anthropic, options) => {
|
|
|
315
320
|
processOutputs: processMessageOutput,
|
|
316
321
|
...cleanedOptions,
|
|
317
322
|
});
|
|
318
|
-
|
|
319
|
-
if (anthropic.beta &&
|
|
320
|
-
anthropic.beta.messages &&
|
|
321
|
-
typeof anthropic.beta.messages.create === "function") {
|
|
323
|
+
if (anthropic.beta) {
|
|
322
324
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
323
325
|
const tracedBeta = { ...anthropic.beta };
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
tracedBeta.messages.
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
326
|
+
// Wrap beta.messages if it exists
|
|
327
|
+
if (anthropic.beta.messages &&
|
|
328
|
+
typeof anthropic.beta.messages.create === "function") {
|
|
329
|
+
tracedBeta.messages = Object.create(Object.getPrototypeOf(anthropic.beta.messages));
|
|
330
|
+
Object.assign(tracedBeta.messages, anthropic.beta.messages);
|
|
331
|
+
// Wrap beta.messages.create
|
|
332
|
+
tracedBeta.messages.create = (0, traceable_js_1.traceable)(anthropic.beta.messages.create.bind(anthropic.beta.messages), messagesCreateConfig);
|
|
333
|
+
// Wrap beta.messages.parse if it exists
|
|
334
|
+
if (typeof anthropic.beta.messages.parse === "function") {
|
|
335
|
+
tracedBeta.messages.parse = (0, traceable_js_1.traceable)(anthropic.beta.messages.parse.bind(anthropic.beta.messages), messagesCreateConfig);
|
|
336
|
+
}
|
|
337
|
+
// Wrap beta.messages.stream if it exists
|
|
338
|
+
if (typeof anthropic.beta.messages.stream === "function") {
|
|
339
|
+
tracedBeta.messages.stream = (0, traceable_js_1.traceable)(wrapStreamMethod(anthropic.beta.messages.stream.bind(anthropic.beta.messages)), {
|
|
340
|
+
name: "ChatAnthropic",
|
|
341
|
+
run_type: "llm",
|
|
342
|
+
aggregator: messageAggregator,
|
|
343
|
+
argsConfigPath: [1, "langsmithExtra"],
|
|
344
|
+
processInputs: processSystemMessage,
|
|
345
|
+
getInvocationParams: messagesCreateConfig.getInvocationParams,
|
|
346
|
+
processOutputs: processMessageOutput,
|
|
347
|
+
...cleanedOptions,
|
|
348
|
+
});
|
|
349
|
+
}
|
|
344
350
|
}
|
|
351
|
+
// Wrap Claude Managed Agents session events if they exist
|
|
352
|
+
(0, anthropic_managed_js_1.wrapManagedAgentSessionEvents)({
|
|
353
|
+
originalBeta: anthropic.beta,
|
|
354
|
+
tracedBeta,
|
|
355
|
+
cleanedOptions,
|
|
356
|
+
prepopulatedInvocationParams,
|
|
357
|
+
});
|
|
345
358
|
tracedAnthropicClient.beta = tracedBeta;
|
|
346
359
|
}
|
|
347
360
|
return tracedAnthropicClient;
|
|
@@ -9,10 +9,19 @@ type MessagesNamespace = {
|
|
|
9
9
|
parse?: (...args: any[]) => any;
|
|
10
10
|
stream: (...args: any[]) => any;
|
|
11
11
|
};
|
|
12
|
+
type ManagedAgentsEventsNamespace = {
|
|
13
|
+
stream: (...args: any[]) => any;
|
|
14
|
+
send: (...args: any[]) => any;
|
|
15
|
+
list?: (...args: any[]) => any;
|
|
16
|
+
};
|
|
12
17
|
type AnthropicType = {
|
|
13
18
|
messages: MessagesNamespace;
|
|
14
19
|
beta?: {
|
|
15
20
|
messages?: MessagesNamespace;
|
|
21
|
+
sessions?: {
|
|
22
|
+
retrieve?: (...args: any[]) => any;
|
|
23
|
+
events?: ManagedAgentsEventsNamespace;
|
|
24
|
+
};
|
|
16
25
|
};
|
|
17
26
|
};
|
|
18
27
|
type PatchedAnthropicClient<T extends AnthropicType> = T & {
|
|
@@ -36,7 +45,7 @@ type PatchedAnthropicClient<T extends AnthropicType> = T & {
|
|
|
36
45
|
/**
|
|
37
46
|
* Create usage metadata from Anthropic's token usage format.
|
|
38
47
|
*/
|
|
39
|
-
export declare function createUsageMetadata(anthropicUsage: Partial<Anthropic.Messages.Usage>): KVMap | undefined;
|
|
48
|
+
export declare function createUsageMetadata(anthropicUsage: Partial<Anthropic.Messages.Usage> | undefined): KVMap | undefined;
|
|
40
49
|
/**
|
|
41
50
|
* Wraps an Anthropic client's completion methods, enabling automatic LangSmith
|
|
42
51
|
* tracing. Method signatures are unchanged, with the exception that you can pass
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { wrapManagedAgentSessionEvents } from "./utils/anthropic_managed.js";
|
|
1
2
|
import { isTraceableFunction, traceable, } from "../traceable.js";
|
|
2
3
|
import { convertAnthropicUsageToInputTokenDetails } from "../utils/usage.js";
|
|
3
4
|
const TRACED_INVOCATION_KEYS = ["top_k", "top_p", "stream", "thinking"];
|
|
@@ -194,7 +195,11 @@ const messageAggregator = (chunks) => {
|
|
|
194
195
|
*/
|
|
195
196
|
export const wrapAnthropic = (anthropic, options) => {
|
|
196
197
|
if (isTraceableFunction(anthropic.messages.create) ||
|
|
197
|
-
isTraceableFunction(anthropic.messages.stream)
|
|
198
|
+
isTraceableFunction(anthropic.messages.stream) ||
|
|
199
|
+
(anthropic.beta?.sessions?.events?.stream &&
|
|
200
|
+
isTraceableFunction(anthropic.beta.sessions.events.stream)) ||
|
|
201
|
+
(anthropic.beta?.sessions?.events?.send &&
|
|
202
|
+
isTraceableFunction(anthropic.beta.sessions.events.send))) {
|
|
198
203
|
throw new Error("This instance of Anthropic client has been already wrapped once.");
|
|
199
204
|
}
|
|
200
205
|
const tracedAnthropicClient = { ...anthropic };
|
|
@@ -311,33 +316,41 @@ export const wrapAnthropic = (anthropic, options) => {
|
|
|
311
316
|
processOutputs: processMessageOutput,
|
|
312
317
|
...cleanedOptions,
|
|
313
318
|
});
|
|
314
|
-
|
|
315
|
-
if (anthropic.beta &&
|
|
316
|
-
anthropic.beta.messages &&
|
|
317
|
-
typeof anthropic.beta.messages.create === "function") {
|
|
319
|
+
if (anthropic.beta) {
|
|
318
320
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
319
321
|
const tracedBeta = { ...anthropic.beta };
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
tracedBeta.messages.
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
322
|
+
// Wrap beta.messages if it exists
|
|
323
|
+
if (anthropic.beta.messages &&
|
|
324
|
+
typeof anthropic.beta.messages.create === "function") {
|
|
325
|
+
tracedBeta.messages = Object.create(Object.getPrototypeOf(anthropic.beta.messages));
|
|
326
|
+
Object.assign(tracedBeta.messages, anthropic.beta.messages);
|
|
327
|
+
// Wrap beta.messages.create
|
|
328
|
+
tracedBeta.messages.create = traceable(anthropic.beta.messages.create.bind(anthropic.beta.messages), messagesCreateConfig);
|
|
329
|
+
// Wrap beta.messages.parse if it exists
|
|
330
|
+
if (typeof anthropic.beta.messages.parse === "function") {
|
|
331
|
+
tracedBeta.messages.parse = traceable(anthropic.beta.messages.parse.bind(anthropic.beta.messages), messagesCreateConfig);
|
|
332
|
+
}
|
|
333
|
+
// Wrap beta.messages.stream if it exists
|
|
334
|
+
if (typeof anthropic.beta.messages.stream === "function") {
|
|
335
|
+
tracedBeta.messages.stream = traceable(wrapStreamMethod(anthropic.beta.messages.stream.bind(anthropic.beta.messages)), {
|
|
336
|
+
name: "ChatAnthropic",
|
|
337
|
+
run_type: "llm",
|
|
338
|
+
aggregator: messageAggregator,
|
|
339
|
+
argsConfigPath: [1, "langsmithExtra"],
|
|
340
|
+
processInputs: processSystemMessage,
|
|
341
|
+
getInvocationParams: messagesCreateConfig.getInvocationParams,
|
|
342
|
+
processOutputs: processMessageOutput,
|
|
343
|
+
...cleanedOptions,
|
|
344
|
+
});
|
|
345
|
+
}
|
|
340
346
|
}
|
|
347
|
+
// Wrap Claude Managed Agents session events if they exist
|
|
348
|
+
wrapManagedAgentSessionEvents({
|
|
349
|
+
originalBeta: anthropic.beta,
|
|
350
|
+
tracedBeta,
|
|
351
|
+
cleanedOptions,
|
|
352
|
+
prepopulatedInvocationParams,
|
|
353
|
+
});
|
|
341
354
|
tracedAnthropicClient.beta = tracedBeta;
|
|
342
355
|
}
|
|
343
356
|
return tracedAnthropicClient;
|