langsmith 0.7.1 → 0.7.2
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 +1 -1
- package/dist/client.js +1 -1
- package/dist/experimental/vercel/index.cjs +18 -637
- package/dist/experimental/vercel/index.d.ts +3 -257
- package/dist/experimental/vercel/index.js +2 -635
- package/dist/experimental/vercel/middleware.cjs +2 -78
- package/dist/experimental/vercel/middleware.js +1 -77
- package/dist/experimental/vercel/telemetry.cjs +462 -0
- package/dist/experimental/vercel/telemetry.d.ts +89 -0
- package/dist/experimental/vercel/telemetry.js +459 -0
- package/dist/experimental/vercel/utils.cjs +142 -35
- package/dist/experimental/vercel/utils.d.ts +28 -3
- package/dist/experimental/vercel/utils.js +140 -34
- package/dist/experimental/vercel/wrap.cjs +639 -0
- package/dist/experimental/vercel/wrap.d.ts +257 -0
- package/dist/experimental/vercel/wrap.js +635 -0
- package/dist/index.cjs +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/sandbox/client.cjs +21 -0
- package/dist/sandbox/client.d.ts +1 -0
- package/dist/sandbox/client.js +21 -0
- package/dist/sandbox/sandbox.cjs +12 -1
- package/dist/sandbox/sandbox.js +12 -1
- package/dist/sandbox/types.d.ts +12 -0
- package/dist/sandbox/ws_execute.cjs +11 -7
- package/dist/sandbox/ws_execute.d.ts +2 -1
- package/dist/sandbox/ws_execute.js +11 -7
- package/dist/utils/types.cjs +13 -0
- package/dist/utils/types.d.ts +2 -0
- package/dist/utils/types.js +8 -0
- package/dist/utils/vercel.cjs +68 -10
- package/dist/utils/vercel.d.ts +17 -2
- package/dist/utils/vercel.js +68 -10
- package/package.json +9 -7
|
@@ -1,257 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { convertMessageToTracedFormat } from "./utils.js";
|
|
5
|
-
import { RunTreeConfig } from "../../run_trees.js";
|
|
6
|
-
export type { AggregatedDoStreamOutput };
|
|
7
|
-
export type WrapAISDKConfig<T extends (...args: any[]) => any = (...args: any[]) => any> = Partial<Omit<RunTreeConfig, "inputs" | "outputs" | "run_type" | "child_runs" | "parent_run" | "error" | "serialized">> & {
|
|
8
|
-
/**
|
|
9
|
-
* Apply transformations to AI SDK inputs before logging.
|
|
10
|
-
* This function should NOT mutate the inputs.
|
|
11
|
-
* Receives both "raw" and LangSmith-suggested "formatted" inputs,
|
|
12
|
-
* and should combine them into a single LangSmith-formatted input.
|
|
13
|
-
*
|
|
14
|
-
* ```ts
|
|
15
|
-
* import {
|
|
16
|
-
* wrapAISDK,
|
|
17
|
-
* createLangSmithProviderOptions,
|
|
18
|
-
* } from "langsmith/experimental/vercel";
|
|
19
|
-
* import * as ai from "ai";
|
|
20
|
-
* import { openai } from "@ai-sdk/openai";
|
|
21
|
-
*
|
|
22
|
-
* const { generateText } = wrapAISDK(ai);
|
|
23
|
-
*
|
|
24
|
-
* const lsConfig = createLangSmithProviderOptions<typeof ai.generateText>({
|
|
25
|
-
* processInputs: (inputs) => {
|
|
26
|
-
* const { messages } = inputs;
|
|
27
|
-
* return {
|
|
28
|
-
* messages: messages?.map((message) => ({
|
|
29
|
-
* providerMetadata: message.providerOptions,
|
|
30
|
-
* role: "assistant",
|
|
31
|
-
* content: "REDACTED",
|
|
32
|
-
* })),
|
|
33
|
-
* prompt: "REDACTED",
|
|
34
|
-
* };
|
|
35
|
-
* },
|
|
36
|
-
* });
|
|
37
|
-
* const { text } = await generateText({
|
|
38
|
-
* model: openai("gpt-5-nano"),
|
|
39
|
-
* prompt: "What is the capital of France?",
|
|
40
|
-
* providerOptions: {
|
|
41
|
-
* langsmith: lsConfig,
|
|
42
|
-
* },
|
|
43
|
-
* });
|
|
44
|
-
* ```
|
|
45
|
-
*
|
|
46
|
-
* This function is not inherited by nested LLM runs or tool calls.
|
|
47
|
-
* Pass `processChildLLMRunInputs` to override child LLM run
|
|
48
|
-
* input processing or wrap your tool's `execute` method in a
|
|
49
|
-
* separate `traceable` for tool calls.
|
|
50
|
-
*
|
|
51
|
-
* @param inputs Key-value map of the function inputs.
|
|
52
|
-
* @param inputs.formatted - Inputs formatted for LangSmith.
|
|
53
|
-
* @param inputs.raw - Raw inputs from the AI SDK.
|
|
54
|
-
* @returns A single combined key-value map of processed inputs.
|
|
55
|
-
*/
|
|
56
|
-
processInputs?: (inputs: Parameters<T>[0]) => Record<string, unknown>;
|
|
57
|
-
/**
|
|
58
|
-
* Apply transformations to AI SDK outputs before logging.
|
|
59
|
-
* This function should NOT mutate the outputs.
|
|
60
|
-
* Receives both "raw" and LangSmith-suggested "formatted" outputs,
|
|
61
|
-
* and should combine them into a single LangSmith-formatted output.
|
|
62
|
-
*
|
|
63
|
-
* ```ts
|
|
64
|
-
* import {
|
|
65
|
-
* wrapAISDK,
|
|
66
|
-
* createLangSmithProviderOptions,
|
|
67
|
-
* } from "langsmith/experimental/vercel";
|
|
68
|
-
* import * as ai from "ai";
|
|
69
|
-
* import { openai } from "@ai-sdk/openai";
|
|
70
|
-
*
|
|
71
|
-
* const { generateText } = wrapAISDK(ai);
|
|
72
|
-
*
|
|
73
|
-
* const lsConfig = createLangSmithProviderOptions<typeof ai.generateText>({
|
|
74
|
-
* processOutputs: (outputs) => {
|
|
75
|
-
* return {
|
|
76
|
-
* providerMetadata: outputs.providerMetadata,
|
|
77
|
-
* role: "assistant",
|
|
78
|
-
* content: "REDACTED",
|
|
79
|
-
* };
|
|
80
|
-
* },
|
|
81
|
-
* });
|
|
82
|
-
* const { text } = await generateText({
|
|
83
|
-
* model: openai("gpt-5-nano"),
|
|
84
|
-
* prompt: "What is the capital of France?",
|
|
85
|
-
* providerOptions: {
|
|
86
|
-
* langsmith: lsConfig,
|
|
87
|
-
* },
|
|
88
|
-
* });
|
|
89
|
-
* ```
|
|
90
|
-
*
|
|
91
|
-
* This function is not inherited by nested LLM runs or tool calls.
|
|
92
|
-
* Pass `processChildLLMRunOutputs` to override child LLM run
|
|
93
|
-
* output processing or wrap your tool's `execute` method in a
|
|
94
|
-
* separate `traceable` for tool calls.
|
|
95
|
-
*
|
|
96
|
-
* @param outputs Key-value map of the function inputs.
|
|
97
|
-
* @param outputs.formatted - Outputs formatted for LangSmith.
|
|
98
|
-
* @param outputs.raw - Raw outputs from the AI SDK.
|
|
99
|
-
* @returns A single combined key-value map of processed outputs.
|
|
100
|
-
*/
|
|
101
|
-
processOutputs?: (outputs: {
|
|
102
|
-
outputs: Awaited<ReturnType<T>>;
|
|
103
|
-
}) => Record<string, unknown> | Promise<Record<string, unknown>>;
|
|
104
|
-
/**
|
|
105
|
-
* Apply transformations to AI SDK child LLM run inputs before logging.
|
|
106
|
-
* This function should NOT mutate the inputs.
|
|
107
|
-
* Receives both "raw" and LangSmith-suggested "formatted" inputs,
|
|
108
|
-
* and should combine them into a single LangSmith-formatted input.
|
|
109
|
-
*
|
|
110
|
-
* ```ts
|
|
111
|
-
* import {
|
|
112
|
-
* wrapAISDK,
|
|
113
|
-
* createLangSmithProviderOptions,
|
|
114
|
-
* } from "langsmith/experimental/vercel";
|
|
115
|
-
* import * as ai from "ai";
|
|
116
|
-
* import { openai } from "@ai-sdk/openai";
|
|
117
|
-
*
|
|
118
|
-
* const { generateText } = wrapAISDK(ai);
|
|
119
|
-
*
|
|
120
|
-
* const lsConfig = createLangSmithProviderOptions<typeof ai.generateText>({
|
|
121
|
-
* processChildLLMRunInputs: (inputs) => {
|
|
122
|
-
* const { prompt } = inputs;
|
|
123
|
-
* return {
|
|
124
|
-
* messages: prompt.map((message) => ({
|
|
125
|
-
* ...message,
|
|
126
|
-
* content: "REDACTED CHILD INPUTS",
|
|
127
|
-
* })),
|
|
128
|
-
* };
|
|
129
|
-
* },
|
|
130
|
-
* });
|
|
131
|
-
* const { text } = await generateText({
|
|
132
|
-
* model: openai("gpt-5-nano"),
|
|
133
|
-
* prompt: "What is the capital of France?",
|
|
134
|
-
* providerOptions: {
|
|
135
|
-
* langsmith: lsConfig,
|
|
136
|
-
* },
|
|
137
|
-
* });
|
|
138
|
-
* ```
|
|
139
|
-
*
|
|
140
|
-
* @param inputs Key-value map of the function inputs.
|
|
141
|
-
* @param inputs.formatted - Inputs formatted for LangSmith.
|
|
142
|
-
* @param inputs.raw - Raw inputs from the AI SDK.
|
|
143
|
-
* @returns A single combined key-value map of processed inputs.
|
|
144
|
-
*/
|
|
145
|
-
processChildLLMRunInputs?: (inputs: LanguageModelV2CallOptions) => Record<string, unknown>;
|
|
146
|
-
/**
|
|
147
|
-
* Apply transformations to AI SDK child LLM run outputs before logging.
|
|
148
|
-
* This function should NOT mutate the outputs.
|
|
149
|
-
* Receives both "raw" and LangSmith-suggested "formatted" outputs,
|
|
150
|
-
* and should combine them into a single LangSmith-formatted output.
|
|
151
|
-
*
|
|
152
|
-
* ```ts
|
|
153
|
-
* import {
|
|
154
|
-
* wrapAISDK,
|
|
155
|
-
* createLangSmithProviderOptions,
|
|
156
|
-
* } from "langsmith/experimental/vercel";
|
|
157
|
-
* import * as ai from "ai";
|
|
158
|
-
* import { openai } from "@ai-sdk/openai";
|
|
159
|
-
*
|
|
160
|
-
* const { generateText } = wrapAISDK(ai);
|
|
161
|
-
*
|
|
162
|
-
* const lsConfig = createLangSmithProviderOptions<typeof ai.generateText>({
|
|
163
|
-
* processChildLLMRunOutputs: (outputs) => {
|
|
164
|
-
* return {
|
|
165
|
-
* providerMetadata: outputs.providerMetadata,
|
|
166
|
-
* content: "REDACTED CHILD OUTPUTS",
|
|
167
|
-
* role: "assistant",
|
|
168
|
-
* };
|
|
169
|
-
* },
|
|
170
|
-
* });
|
|
171
|
-
* const { text } = await generateText({
|
|
172
|
-
* model: openai("gpt-5-nano"),
|
|
173
|
-
* prompt: "What is the capital of France?",
|
|
174
|
-
* providerOptions: {
|
|
175
|
-
* langsmith: lsConfig,
|
|
176
|
-
* },
|
|
177
|
-
* });
|
|
178
|
-
* ```
|
|
179
|
-
*
|
|
180
|
-
* @param outputs Key-value map of the function inputs.
|
|
181
|
-
* @param outputs.formatted - Outputs formatted for LangSmith.
|
|
182
|
-
* @param outputs.raw - Raw outputs from the AI SDK.
|
|
183
|
-
* @returns A single combined key-value map of processed outputs.
|
|
184
|
-
*/
|
|
185
|
-
processChildLLMRunOutputs?: (outputs: "fullStream" extends keyof Awaited<ReturnType<T>> ? AggregatedDoStreamOutput : Awaited<ReturnType<LanguageModelV2["doGenerate"]>>) => Record<string, unknown>;
|
|
186
|
-
/**
|
|
187
|
-
* Whether to include additional fields such as intermediate steps in traced
|
|
188
|
-
* output messages.
|
|
189
|
-
* @default false
|
|
190
|
-
*/
|
|
191
|
-
traceResponseMetadata?: boolean;
|
|
192
|
-
/**
|
|
193
|
-
* Whether to include raw HTTP request and response details in traces from the
|
|
194
|
-
* underlying model calls (doGenerate/doStream).
|
|
195
|
-
*
|
|
196
|
-
* When enabled, traces will include the full HTTP request body, response body,
|
|
197
|
-
* headers, and other low-level details. This can be useful for debugging provider
|
|
198
|
-
* issues but creates very verbose traces.
|
|
199
|
-
*
|
|
200
|
-
* @default false
|
|
201
|
-
*/
|
|
202
|
-
traceRawHttp?: boolean;
|
|
203
|
-
};
|
|
204
|
-
/**
|
|
205
|
-
* Wraps LangSmith config in a way that matches AI SDK provider types.
|
|
206
|
-
*
|
|
207
|
-
* ```ts
|
|
208
|
-
* import { createLangSmithProviderOptions } from "langsmith/experimental/vercel";
|
|
209
|
-
* import * as ai from "ai";
|
|
210
|
-
*
|
|
211
|
-
* const lsConfig = createLangSmithProviderOptions<typeof ai.generateText>({
|
|
212
|
-
* // Will have appropriate typing
|
|
213
|
-
* processInputs: (inputs) => {
|
|
214
|
-
* const { messages } = inputs;
|
|
215
|
-
* return {
|
|
216
|
-
* messages: messages?.map((message) => ({
|
|
217
|
-
* ...message,
|
|
218
|
-
* content: "REDACTED",
|
|
219
|
-
* })),
|
|
220
|
-
* prompt: "REDACTED",
|
|
221
|
-
* };
|
|
222
|
-
* },
|
|
223
|
-
* });
|
|
224
|
-
* ```
|
|
225
|
-
*
|
|
226
|
-
* Note: AI SDK expects only JSON values in an object for
|
|
227
|
-
* provider options, but LangSmith's config may contain non-JSON values.
|
|
228
|
-
* These are not passed to the underlying AI SDK model, so it is safe to
|
|
229
|
-
* cast the typing here.
|
|
230
|
-
*/
|
|
231
|
-
export declare const createLangSmithProviderOptions: <T extends (...args: any[]) => any>(lsConfig?: WrapAISDKConfig<T>) => Record<string, JSONValue>;
|
|
232
|
-
/**
|
|
233
|
-
* Wraps Vercel AI SDK 6 or AI SDK 5 functions with LangSmith tracing capabilities.
|
|
234
|
-
*
|
|
235
|
-
* @param methods - Object containing AI SDK methods to wrap
|
|
236
|
-
* @param methods.wrapLanguageModel - AI SDK's wrapLanguageModel function
|
|
237
|
-
* @param methods.generateText - AI SDK's generateText function
|
|
238
|
-
* @param methods.streamText - AI SDK's streamText function
|
|
239
|
-
* @param methods.streamObject - AI SDK's streamObject function
|
|
240
|
-
* @param methods.generateObject - AI SDK's generateObject function
|
|
241
|
-
*
|
|
242
|
-
* @returns Object containing wrapped versions of the AI SDK functions with LangSmith tracing
|
|
243
|
-
* @returns returns.generateText - Wrapped generateText function that traces calls to LangSmith
|
|
244
|
-
* @returns returns.generateObject - Wrapped generateObject function that traces calls to LangSmith
|
|
245
|
-
* @returns returns.streamText - Wrapped streamText function that traces calls to LangSmith
|
|
246
|
-
* @returns returns.streamObject - Wrapped streamObject function that traces calls to LangSmith
|
|
247
|
-
*/
|
|
248
|
-
declare const wrapAISDK: <T extends {
|
|
249
|
-
wrapLanguageModel: (...args: any[]) => any;
|
|
250
|
-
generateText: (...args: any[]) => any;
|
|
251
|
-
streamText: (...args: any[]) => any;
|
|
252
|
-
streamObject?: (...args: any[]) => any;
|
|
253
|
-
generateObject?: (...args: any[]) => any;
|
|
254
|
-
ToolLoopAgent?: any;
|
|
255
|
-
}>(ai: T, baseLsConfig?: WrapAISDKConfig) => T;
|
|
256
|
-
export { wrapAISDK };
|
|
257
|
-
export { convertMessageToTracedFormat };
|
|
1
|
+
export * from "./wrap.js";
|
|
2
|
+
export { LangSmithTelemetry } from "./telemetry.js";
|
|
3
|
+
export type { LangSmithTelemetryConfig } from "./telemetry.js";
|