langsmith 0.3.76 → 0.3.78

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.
@@ -1,8 +1,9 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.wrapAISDK = exports.createLangSmithProviderOptions = void 0;
3
+ exports.convertMessageToTracedFormat = exports.wrapAISDK = exports.createLangSmithProviderOptions = void 0;
4
4
  const middleware_js_1 = require("./middleware.cjs");
5
5
  const utils_js_1 = require("./utils.cjs");
6
+ Object.defineProperty(exports, "convertMessageToTracedFormat", { enumerable: true, get: function () { return utils_js_1.convertMessageToTracedFormat; } });
6
7
  const traceable_js_1 = require("../../traceable.cjs");
7
8
  const _wrapTools = (tools, lsConfig) => {
8
9
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -49,10 +50,16 @@ const _getModelId = (model) => {
49
50
  const _formatTracedInputs = (params) => {
50
51
  const { prompt, messages, model, tools, ...rest } = params;
51
52
  if (Array.isArray(prompt)) {
52
- return { ...rest, messages: prompt.map(utils_js_1.convertMessageToTracedFormat) };
53
+ return {
54
+ ...rest,
55
+ messages: prompt.map((message) => (0, utils_js_1.convertMessageToTracedFormat)(message)),
56
+ };
53
57
  }
54
58
  else if (Array.isArray(messages)) {
55
- return { ...rest, messages: messages.map(utils_js_1.convertMessageToTracedFormat) };
59
+ return {
60
+ ...rest,
61
+ messages: messages.map((message) => (0, utils_js_1.convertMessageToTracedFormat)(message)),
62
+ };
56
63
  }
57
64
  else {
58
65
  return { ...rest, prompt, messages };
@@ -75,6 +82,8 @@ const _extractChildRunConfig = (lsConfig) => {
75
82
  childConfig.processInputs = processChildLLMRunInputs;
76
83
  }
77
84
  if (processChildLLMRunOutputs) {
85
+ // TODO: Fix this typing on minor bump
86
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
78
87
  childConfig.processOutputs = processChildLLMRunOutputs;
79
88
  }
80
89
  return childConfig;
@@ -168,6 +177,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
168
177
  middleware: (0, middleware_js_1.LangSmithMiddleware)({
169
178
  name: _getModelDisplayName(params.model),
170
179
  modelId: _getModelId(params.model),
180
+ // TODO: Fix this typing on minor bump
171
181
  lsConfig: resolvedChildLLMRunConfig,
172
182
  }),
173
183
  });
@@ -190,7 +200,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
190
200
  },
191
201
  processOutputs: async (outputs) => {
192
202
  if (resolvedLsConfig?.processOutputs) {
193
- const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
203
+ const processedOutputs = await resolvedLsConfig.processOutputs(
204
+ // TODO: Fix this typing on minor bump
205
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
206
+ outputs);
194
207
  return processedOutputs;
195
208
  }
196
209
  if (outputs.outputs == null || typeof outputs.outputs !== "object") {
@@ -206,7 +219,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
206
219
  return (0, utils_js_1.convertMessageToTracedFormat)({
207
220
  content: content ?? outputs.outputs.text,
208
221
  role: "assistant",
209
- });
222
+ }, resolvedLsConfig?.traceResponseMetadata ? { steps } : undefined);
210
223
  }
211
224
  else {
212
225
  return outputs;
@@ -244,6 +257,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
244
257
  middleware: (0, middleware_js_1.LangSmithMiddleware)({
245
258
  name: _getModelDisplayName(params.model),
246
259
  modelId: _getModelId(params.model),
260
+ // TODO: Fix this typing on minor bump
247
261
  lsConfig: resolvedChildLLMRunConfig,
248
262
  }),
249
263
  });
@@ -265,7 +279,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
265
279
  },
266
280
  processOutputs: async (outputs) => {
267
281
  if (resolvedLsConfig?.processOutputs) {
268
- const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
282
+ const processedOutputs = await resolvedLsConfig.processOutputs(
283
+ // TODO: Fix this typing on minor bump
284
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
285
+ outputs);
269
286
  return processedOutputs;
270
287
  }
271
288
  if (outputs.outputs == null || typeof outputs.outputs !== "object") {
@@ -306,6 +323,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
306
323
  middleware: (0, middleware_js_1.LangSmithMiddleware)({
307
324
  name: _getModelDisplayName(params.model),
308
325
  modelId: _getModelId(params.model),
326
+ // TODO: Fix this typing on minor bump
309
327
  lsConfig: resolvedChildLLMRunConfig,
310
328
  }),
311
329
  });
@@ -329,7 +347,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
329
347
  processOutputs: async (outputs) => {
330
348
  try {
331
349
  if (resolvedLsConfig?.processOutputs) {
332
- const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
350
+ const processedOutputs = await resolvedLsConfig.processOutputs(
351
+ // TODO: Fix this typing on minor bump
352
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
353
+ outputs);
333
354
  return processedOutputs;
334
355
  }
335
356
  if (outputs.outputs == null ||
@@ -347,10 +368,20 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
347
368
  !["object", "string"].includes(typeof content)) {
348
369
  return outputs;
349
370
  }
371
+ let responseMetadata = undefined;
372
+ if (resolvedLsConfig?.traceResponseMetadata) {
373
+ try {
374
+ const steps = await outputs.outputs.steps;
375
+ responseMetadata = { steps };
376
+ }
377
+ catch (e) {
378
+ // Do nothing if step parsing fails
379
+ }
380
+ }
350
381
  return (0, utils_js_1.convertMessageToTracedFormat)({
351
382
  content,
352
383
  role: "assistant",
353
- });
384
+ }, responseMetadata);
354
385
  }
355
386
  catch (e) {
356
387
  // Handle parsing failures without a log
@@ -390,6 +421,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
390
421
  middleware: (0, middleware_js_1.LangSmithMiddleware)({
391
422
  name: _getModelDisplayName(params.model),
392
423
  modelId: _getModelId(params.model),
424
+ // TODO: Fix this typing on minor bump
393
425
  lsConfig: resolvedChildLLMRunConfig,
394
426
  }),
395
427
  });
@@ -412,7 +444,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
412
444
  processOutputs: async (outputs) => {
413
445
  try {
414
446
  if (resolvedLsConfig?.processOutputs) {
415
- const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
447
+ const processedOutputs = await resolvedLsConfig.processOutputs(
448
+ // TODO: Fix this typing on minor bump
449
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
450
+ outputs);
416
451
  return processedOutputs;
417
452
  }
418
453
  if (outputs.outputs == null ||
@@ -1,6 +1,7 @@
1
1
  import type { JSONValue } from "ai";
2
2
  import type { LanguageModelV2, LanguageModelV2CallOptions } from "@ai-sdk/provider";
3
3
  import { type AggregatedDoStreamOutput } from "./middleware.js";
4
+ import { convertMessageToTracedFormat } from "./utils.js";
4
5
  import { RunTreeConfig } from "../../run_trees.js";
5
6
  export type { AggregatedDoStreamOutput };
6
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">> & {
@@ -97,7 +98,9 @@ export type WrapAISDKConfig<T extends (...args: any[]) => any = (...args: any[])
97
98
  * @param outputs.raw - Raw outputs from the AI SDK.
98
99
  * @returns A single combined key-value map of processed outputs.
99
100
  */
100
- processOutputs?: (outputs: Awaited<ReturnType<T>>) => Record<string, unknown> | Promise<Record<string, unknown>>;
101
+ processOutputs?: (outputs: {
102
+ outputs: Awaited<ReturnType<T>>;
103
+ }) => Record<string, unknown> | Promise<Record<string, unknown>>;
101
104
  /**
102
105
  * Apply transformations to AI SDK child LLM run inputs before logging.
103
106
  * This function should NOT mutate the inputs.
@@ -180,6 +183,12 @@ export type WrapAISDKConfig<T extends (...args: any[]) => any = (...args: any[])
180
183
  * @returns A single combined key-value map of processed outputs.
181
184
  */
182
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;
183
192
  };
184
193
  /**
185
194
  * Wraps LangSmith config in a way that matches AI SDK provider types.
@@ -238,3 +247,4 @@ declare const wrapAISDK: <GenerateTextType extends (...args: any[]) => any, Stre
238
247
  streamObject: StreamObjectType;
239
248
  };
240
249
  export { wrapAISDK };
250
+ export { convertMessageToTracedFormat };
@@ -46,10 +46,16 @@ const _getModelId = (model) => {
46
46
  const _formatTracedInputs = (params) => {
47
47
  const { prompt, messages, model, tools, ...rest } = params;
48
48
  if (Array.isArray(prompt)) {
49
- return { ...rest, messages: prompt.map(convertMessageToTracedFormat) };
49
+ return {
50
+ ...rest,
51
+ messages: prompt.map((message) => convertMessageToTracedFormat(message)),
52
+ };
50
53
  }
51
54
  else if (Array.isArray(messages)) {
52
- return { ...rest, messages: messages.map(convertMessageToTracedFormat) };
55
+ return {
56
+ ...rest,
57
+ messages: messages.map((message) => convertMessageToTracedFormat(message)),
58
+ };
53
59
  }
54
60
  else {
55
61
  return { ...rest, prompt, messages };
@@ -72,6 +78,8 @@ const _extractChildRunConfig = (lsConfig) => {
72
78
  childConfig.processInputs = processChildLLMRunInputs;
73
79
  }
74
80
  if (processChildLLMRunOutputs) {
81
+ // TODO: Fix this typing on minor bump
82
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
75
83
  childConfig.processOutputs = processChildLLMRunOutputs;
76
84
  }
77
85
  return childConfig;
@@ -164,6 +172,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
164
172
  middleware: LangSmithMiddleware({
165
173
  name: _getModelDisplayName(params.model),
166
174
  modelId: _getModelId(params.model),
175
+ // TODO: Fix this typing on minor bump
167
176
  lsConfig: resolvedChildLLMRunConfig,
168
177
  }),
169
178
  });
@@ -186,7 +195,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
186
195
  },
187
196
  processOutputs: async (outputs) => {
188
197
  if (resolvedLsConfig?.processOutputs) {
189
- const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
198
+ const processedOutputs = await resolvedLsConfig.processOutputs(
199
+ // TODO: Fix this typing on minor bump
200
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
201
+ outputs);
190
202
  return processedOutputs;
191
203
  }
192
204
  if (outputs.outputs == null || typeof outputs.outputs !== "object") {
@@ -202,7 +214,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
202
214
  return convertMessageToTracedFormat({
203
215
  content: content ?? outputs.outputs.text,
204
216
  role: "assistant",
205
- });
217
+ }, resolvedLsConfig?.traceResponseMetadata ? { steps } : undefined);
206
218
  }
207
219
  else {
208
220
  return outputs;
@@ -240,6 +252,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
240
252
  middleware: LangSmithMiddleware({
241
253
  name: _getModelDisplayName(params.model),
242
254
  modelId: _getModelId(params.model),
255
+ // TODO: Fix this typing on minor bump
243
256
  lsConfig: resolvedChildLLMRunConfig,
244
257
  }),
245
258
  });
@@ -261,7 +274,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
261
274
  },
262
275
  processOutputs: async (outputs) => {
263
276
  if (resolvedLsConfig?.processOutputs) {
264
- const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
277
+ const processedOutputs = await resolvedLsConfig.processOutputs(
278
+ // TODO: Fix this typing on minor bump
279
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
280
+ outputs);
265
281
  return processedOutputs;
266
282
  }
267
283
  if (outputs.outputs == null || typeof outputs.outputs !== "object") {
@@ -302,6 +318,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
302
318
  middleware: LangSmithMiddleware({
303
319
  name: _getModelDisplayName(params.model),
304
320
  modelId: _getModelId(params.model),
321
+ // TODO: Fix this typing on minor bump
305
322
  lsConfig: resolvedChildLLMRunConfig,
306
323
  }),
307
324
  });
@@ -325,7 +342,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
325
342
  processOutputs: async (outputs) => {
326
343
  try {
327
344
  if (resolvedLsConfig?.processOutputs) {
328
- const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
345
+ const processedOutputs = await resolvedLsConfig.processOutputs(
346
+ // TODO: Fix this typing on minor bump
347
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
348
+ outputs);
329
349
  return processedOutputs;
330
350
  }
331
351
  if (outputs.outputs == null ||
@@ -343,10 +363,20 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
343
363
  !["object", "string"].includes(typeof content)) {
344
364
  return outputs;
345
365
  }
366
+ let responseMetadata = undefined;
367
+ if (resolvedLsConfig?.traceResponseMetadata) {
368
+ try {
369
+ const steps = await outputs.outputs.steps;
370
+ responseMetadata = { steps };
371
+ }
372
+ catch (e) {
373
+ // Do nothing if step parsing fails
374
+ }
375
+ }
346
376
  return convertMessageToTracedFormat({
347
377
  content,
348
378
  role: "assistant",
349
- });
379
+ }, responseMetadata);
350
380
  }
351
381
  catch (e) {
352
382
  // Handle parsing failures without a log
@@ -386,6 +416,7 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
386
416
  middleware: LangSmithMiddleware({
387
417
  name: _getModelDisplayName(params.model),
388
418
  modelId: _getModelId(params.model),
419
+ // TODO: Fix this typing on minor bump
389
420
  lsConfig: resolvedChildLLMRunConfig,
390
421
  }),
391
422
  });
@@ -408,7 +439,10 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
408
439
  processOutputs: async (outputs) => {
409
440
  try {
410
441
  if (resolvedLsConfig?.processOutputs) {
411
- const processedOutputs = await resolvedLsConfig.processOutputs(outputs);
442
+ const processedOutputs = await resolvedLsConfig.processOutputs(
443
+ // TODO: Fix this typing on minor bump
444
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
445
+ outputs);
412
446
  return processedOutputs;
413
447
  }
414
448
  if (outputs.outputs == null ||
@@ -437,3 +471,4 @@ const wrapAISDK = ({ wrapLanguageModel, generateText, streamText, streamObject,
437
471
  };
438
472
  };
439
473
  export { wrapAISDK };
474
+ export { convertMessageToTracedFormat };
@@ -11,7 +11,10 @@ const _formatTracedInputs = (params) => {
11
11
  return params;
12
12
  }
13
13
  if (Array.isArray(prompt)) {
14
- return { ...rest, messages: prompt.map(utils_js_1.convertMessageToTracedFormat) };
14
+ return {
15
+ ...rest,
16
+ messages: prompt.map((message) => (0, utils_js_1.convertMessageToTracedFormat)(message)),
17
+ };
15
18
  }
16
19
  return rest;
17
20
  };
@@ -8,7 +8,10 @@ const _formatTracedInputs = (params) => {
8
8
  return params;
9
9
  }
10
10
  if (Array.isArray(prompt)) {
11
- return { ...rest, messages: prompt.map(convertMessageToTracedFormat) };
11
+ return {
12
+ ...rest,
13
+ messages: prompt.map((message) => convertMessageToTracedFormat(message)),
14
+ };
12
15
  }
13
16
  return rest;
14
17
  };
@@ -97,7 +97,7 @@ const normalizeFileDataAsDataURL = (fileData, mimeType) => {
97
97
  return normalizedFileData;
98
98
  };
99
99
  exports.normalizeFileDataAsDataURL = normalizeFileDataAsDataURL;
100
- const convertMessageToTracedFormat = (message) => {
100
+ const convertMessageToTracedFormat = (message, responseMetadata) => {
101
101
  const formattedMessage = {
102
102
  ...message,
103
103
  };
@@ -165,6 +165,9 @@ const convertMessageToTracedFormat = (message) => {
165
165
  });
166
166
  }
167
167
  }
168
+ if (responseMetadata != null) {
169
+ formattedMessage.response_metadata = responseMetadata;
170
+ }
168
171
  return formattedMessage;
169
172
  };
170
173
  exports.convertMessageToTracedFormat = convertMessageToTracedFormat;
@@ -1,4 +1,4 @@
1
1
  import type { LanguageModelV2DataContent, LanguageModelV2Message } from "@ai-sdk/provider";
2
2
  import type { ModelMessage } from "ai";
3
3
  export declare const normalizeFileDataAsDataURL: (fileData: LanguageModelV2DataContent | ArrayBuffer, mimeType?: string) => string;
4
- export declare const convertMessageToTracedFormat: (message: LanguageModelV2Message | ModelMessage) => Record<string, unknown>;
4
+ export declare const convertMessageToTracedFormat: (message: LanguageModelV2Message | ModelMessage, responseMetadata?: Record<string, unknown>) => Record<string, unknown>;
@@ -93,7 +93,7 @@ export const normalizeFileDataAsDataURL = (fileData, mimeType) => {
93
93
  }
94
94
  return normalizedFileData;
95
95
  };
96
- export const convertMessageToTracedFormat = (message) => {
96
+ export const convertMessageToTracedFormat = (message, responseMetadata) => {
97
97
  const formattedMessage = {
98
98
  ...message,
99
99
  };
@@ -161,5 +161,8 @@ export const convertMessageToTracedFormat = (message) => {
161
161
  });
162
162
  }
163
163
  }
164
+ if (responseMetadata != null) {
165
+ formattedMessage.response_metadata = responseMetadata;
166
+ }
164
167
  return formattedMessage;
165
168
  };
package/dist/index.cjs CHANGED
@@ -10,4 +10,4 @@ Object.defineProperty(exports, "overrideFetchImplementation", { enumerable: true
10
10
  var project_js_1 = require("./utils/project.cjs");
11
11
  Object.defineProperty(exports, "getDefaultProjectName", { enumerable: true, get: function () { return project_js_1.getDefaultProjectName; } });
12
12
  // Update using yarn bump-version
13
- exports.__version__ = "0.3.76";
13
+ exports.__version__ = "0.3.78";
package/dist/index.d.ts CHANGED
@@ -3,4 +3,4 @@ export type { Dataset, Example, TracerSession, Run, Feedback, RetrieverOutput, }
3
3
  export { RunTree, type RunTreeConfig } from "./run_trees.js";
4
4
  export { overrideFetchImplementation } from "./singletons/fetch.js";
5
5
  export { getDefaultProjectName } from "./utils/project.js";
6
- export declare const __version__ = "0.3.76";
6
+ export declare const __version__ = "0.3.78";
package/dist/index.js CHANGED
@@ -3,4 +3,4 @@ export { RunTree } from "./run_trees.js";
3
3
  export { overrideFetchImplementation } from "./singletons/fetch.js";
4
4
  export { getDefaultProjectName } from "./utils/project.js";
5
5
  // Update using yarn bump-version
6
- export const __version__ = "0.3.76";
6
+ export const __version__ = "0.3.78";
@@ -311,6 +311,9 @@ class RunTree {
311
311
  ...config?.extra?.metadata,
312
312
  };
313
313
  config.extra = { ...config.extra, metadata: dedupedMetadata };
314
+ if ("id" in config && config.id == null) {
315
+ delete config.id;
316
+ }
314
317
  Object.assign(this, { ...defaultConfig, ...config, client });
315
318
  if (!this.trace_id) {
316
319
  if (this.parent_run) {
package/dist/run_trees.js CHANGED
@@ -272,6 +272,9 @@ export class RunTree {
272
272
  ...config?.extra?.metadata,
273
273
  };
274
274
  config.extra = { ...config.extra, metadata: dedupedMetadata };
275
+ if ("id" in config && config.id == null) {
276
+ delete config.id;
277
+ }
275
278
  Object.assign(this, { ...defaultConfig, ...config, client });
276
279
  if (!this.trace_id) {
277
280
  if (this.parent_run) {
@@ -2,6 +2,29 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.wrapOpenAI = void 0;
4
4
  const traceable_js_1 = require("../traceable.cjs");
5
+ const TRACED_INVOCATION_KEYS = [
6
+ "frequency_penalty",
7
+ "n",
8
+ "logit_bias",
9
+ "logprobs",
10
+ "modalities",
11
+ "parallel_tool_calls",
12
+ "prediction",
13
+ "presence_penalty",
14
+ "prompt_cache_key",
15
+ "reasoning",
16
+ "reasoning_effort",
17
+ "response_format",
18
+ "seed",
19
+ "service_tier",
20
+ "stream_options",
21
+ "top_logprobs",
22
+ "top_p",
23
+ "truncation",
24
+ "user",
25
+ "verbosity",
26
+ "web_search_options",
27
+ ];
5
28
  function _combineChatCompletionChoices(choices
6
29
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
7
30
  ) {
@@ -263,6 +286,12 @@ const wrapOpenAI = (openai, options) => {
263
286
  const params = payload;
264
287
  const ls_stop = (typeof params.stop === "string" ? [params.stop] : params.stop) ??
265
288
  undefined;
289
+ const ls_invocation_params = {};
290
+ for (const [key, value] of Object.entries(params)) {
291
+ if (TRACED_INVOCATION_KEYS.includes(key)) {
292
+ ls_invocation_params[key] = value;
293
+ }
294
+ }
266
295
  return {
267
296
  ls_provider: provider,
268
297
  ls_model_type: "chat",
@@ -270,6 +299,7 @@ const wrapOpenAI = (openai, options) => {
270
299
  ls_max_tokens: params.max_completion_tokens ?? params.max_tokens ?? undefined,
271
300
  ls_temperature: params.temperature ?? undefined,
272
301
  ls_stop,
302
+ ls_invocation_params,
273
303
  };
274
304
  },
275
305
  processOutputs: processChatCompletion,
@@ -309,6 +339,12 @@ const wrapOpenAI = (openai, options) => {
309
339
  const params = payload;
310
340
  const ls_stop = (typeof params.stop === "string" ? [params.stop] : params.stop) ??
311
341
  undefined;
342
+ const ls_invocation_params = {};
343
+ for (const [key, value] of Object.entries(params)) {
344
+ if (TRACED_INVOCATION_KEYS.includes(key)) {
345
+ ls_invocation_params[key] = value;
346
+ }
347
+ }
312
348
  return {
313
349
  ls_provider: provider,
314
350
  ls_model_type: "llm",
@@ -316,6 +352,7 @@ const wrapOpenAI = (openai, options) => {
316
352
  ls_max_tokens: params.max_tokens ?? undefined,
317
353
  ls_temperature: params.temperature ?? undefined,
318
354
  ls_stop,
355
+ ls_invocation_params,
319
356
  };
320
357
  },
321
358
  ...options,
@@ -344,7 +381,51 @@ const wrapOpenAI = (openai, options) => {
344
381
  const params = payload;
345
382
  return {
346
383
  ls_provider: provider,
347
- ls_model_type: "llm",
384
+ ls_model_type: "chat",
385
+ ls_model_name: params.model || "unknown",
386
+ };
387
+ },
388
+ processOutputs: processChatCompletion,
389
+ ...options,
390
+ });
391
+ }
392
+ if (tracedOpenAIClient.responses &&
393
+ typeof tracedOpenAIClient.responses.parse === "function") {
394
+ tracedOpenAIClient.responses.parse = (0, traceable_js_1.traceable)(openai.responses.parse.bind(openai.responses), {
395
+ name: chatName,
396
+ run_type: "llm",
397
+ aggregator: responsesAggregator,
398
+ argsConfigPath: [1, "langsmithExtra"],
399
+ getInvocationParams: (payload) => {
400
+ if (typeof payload !== "object" || payload == null)
401
+ return undefined;
402
+ // Handle responses API parameters
403
+ const params = payload;
404
+ return {
405
+ ls_provider: provider,
406
+ ls_model_type: "chat",
407
+ ls_model_name: params.model || "unknown",
408
+ };
409
+ },
410
+ processOutputs: processChatCompletion,
411
+ ...options,
412
+ });
413
+ }
414
+ if (tracedOpenAIClient.responses &&
415
+ typeof tracedOpenAIClient.responses.stream === "function") {
416
+ tracedOpenAIClient.responses.stream = (0, traceable_js_1.traceable)(openai.responses.stream.bind(openai.responses), {
417
+ name: chatName,
418
+ run_type: "llm",
419
+ aggregator: responsesAggregator,
420
+ argsConfigPath: [1, "langsmithExtra"],
421
+ getInvocationParams: (payload) => {
422
+ if (typeof payload !== "object" || payload == null)
423
+ return undefined;
424
+ // Handle responses API parameters
425
+ const params = payload;
426
+ return {
427
+ ls_provider: provider,
428
+ ls_model_type: "chat",
348
429
  ls_model_name: params.model || "unknown",
349
430
  };
350
431
  },
@@ -15,6 +15,8 @@ type OpenAIType = {
15
15
  responses?: {
16
16
  create: (...args: any[]) => any;
17
17
  retrieve: (...args: any[]) => any;
18
+ parse: (...args: any[]) => any;
19
+ stream: (...args: any[]) => any;
18
20
  };
19
21
  };
20
22
  type ExtraRunTreeConfig = Pick<Partial<RunTreeConfig>, "name" | "metadata" | "tags">;
@@ -1,4 +1,27 @@
1
1
  import { isTraceableFunction, traceable, } from "../traceable.js";
2
+ const TRACED_INVOCATION_KEYS = [
3
+ "frequency_penalty",
4
+ "n",
5
+ "logit_bias",
6
+ "logprobs",
7
+ "modalities",
8
+ "parallel_tool_calls",
9
+ "prediction",
10
+ "presence_penalty",
11
+ "prompt_cache_key",
12
+ "reasoning",
13
+ "reasoning_effort",
14
+ "response_format",
15
+ "seed",
16
+ "service_tier",
17
+ "stream_options",
18
+ "top_logprobs",
19
+ "top_p",
20
+ "truncation",
21
+ "user",
22
+ "verbosity",
23
+ "web_search_options",
24
+ ];
2
25
  function _combineChatCompletionChoices(choices
3
26
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
4
27
  ) {
@@ -260,6 +283,12 @@ export const wrapOpenAI = (openai, options) => {
260
283
  const params = payload;
261
284
  const ls_stop = (typeof params.stop === "string" ? [params.stop] : params.stop) ??
262
285
  undefined;
286
+ const ls_invocation_params = {};
287
+ for (const [key, value] of Object.entries(params)) {
288
+ if (TRACED_INVOCATION_KEYS.includes(key)) {
289
+ ls_invocation_params[key] = value;
290
+ }
291
+ }
263
292
  return {
264
293
  ls_provider: provider,
265
294
  ls_model_type: "chat",
@@ -267,6 +296,7 @@ export const wrapOpenAI = (openai, options) => {
267
296
  ls_max_tokens: params.max_completion_tokens ?? params.max_tokens ?? undefined,
268
297
  ls_temperature: params.temperature ?? undefined,
269
298
  ls_stop,
299
+ ls_invocation_params,
270
300
  };
271
301
  },
272
302
  processOutputs: processChatCompletion,
@@ -306,6 +336,12 @@ export const wrapOpenAI = (openai, options) => {
306
336
  const params = payload;
307
337
  const ls_stop = (typeof params.stop === "string" ? [params.stop] : params.stop) ??
308
338
  undefined;
339
+ const ls_invocation_params = {};
340
+ for (const [key, value] of Object.entries(params)) {
341
+ if (TRACED_INVOCATION_KEYS.includes(key)) {
342
+ ls_invocation_params[key] = value;
343
+ }
344
+ }
309
345
  return {
310
346
  ls_provider: provider,
311
347
  ls_model_type: "llm",
@@ -313,6 +349,7 @@ export const wrapOpenAI = (openai, options) => {
313
349
  ls_max_tokens: params.max_tokens ?? undefined,
314
350
  ls_temperature: params.temperature ?? undefined,
315
351
  ls_stop,
352
+ ls_invocation_params,
316
353
  };
317
354
  },
318
355
  ...options,
@@ -341,7 +378,51 @@ export const wrapOpenAI = (openai, options) => {
341
378
  const params = payload;
342
379
  return {
343
380
  ls_provider: provider,
344
- ls_model_type: "llm",
381
+ ls_model_type: "chat",
382
+ ls_model_name: params.model || "unknown",
383
+ };
384
+ },
385
+ processOutputs: processChatCompletion,
386
+ ...options,
387
+ });
388
+ }
389
+ if (tracedOpenAIClient.responses &&
390
+ typeof tracedOpenAIClient.responses.parse === "function") {
391
+ tracedOpenAIClient.responses.parse = traceable(openai.responses.parse.bind(openai.responses), {
392
+ name: chatName,
393
+ run_type: "llm",
394
+ aggregator: responsesAggregator,
395
+ argsConfigPath: [1, "langsmithExtra"],
396
+ getInvocationParams: (payload) => {
397
+ if (typeof payload !== "object" || payload == null)
398
+ return undefined;
399
+ // Handle responses API parameters
400
+ const params = payload;
401
+ return {
402
+ ls_provider: provider,
403
+ ls_model_type: "chat",
404
+ ls_model_name: params.model || "unknown",
405
+ };
406
+ },
407
+ processOutputs: processChatCompletion,
408
+ ...options,
409
+ });
410
+ }
411
+ if (tracedOpenAIClient.responses &&
412
+ typeof tracedOpenAIClient.responses.stream === "function") {
413
+ tracedOpenAIClient.responses.stream = traceable(openai.responses.stream.bind(openai.responses), {
414
+ name: chatName,
415
+ run_type: "llm",
416
+ aggregator: responsesAggregator,
417
+ argsConfigPath: [1, "langsmithExtra"],
418
+ getInvocationParams: (payload) => {
419
+ if (typeof payload !== "object" || payload == null)
420
+ return undefined;
421
+ // Handle responses API parameters
422
+ const params = payload;
423
+ return {
424
+ ls_provider: provider,
425
+ ls_model_type: "chat",
345
426
  ls_model_name: params.model || "unknown",
346
427
  };
347
428
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "langsmith",
3
- "version": "0.3.76",
3
+ "version": "0.3.78",
4
4
  "description": "Client library to connect to the LangSmith Observability and Evaluation Platform.",
5
5
  "packageManager": "yarn@1.22.19",
6
6
  "files": [