traceable.d.ts 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import { RunTreeConfig } from "./run_trees.js";
  2. import { Attachments, InvocationParamsSchema, KVMap } from "./schemas.js";
  3. import { TraceableFunction } from "./singletons/types.js";
  4. /**
  5. * Higher-order function that takes function as input and returns a
  6. * "TraceableFunction" - a wrapped version of the input that
  7. * automatically handles tracing. If the returned traceable function calls any
  8. * traceable functions, those are automatically traced as well.
  9. *
  10. * The returned TraceableFunction can accept a run tree or run tree config as
  11. * its first argument. If omitted, it will default to the caller's run tree,
  12. * or will be treated as a root run.
  13. *
  14. * @param wrappedFunc Targeted function to be traced
  15. * @param config Additional metadata such as name, tags or providing
  16. * a custom LangSmith client instance
  17. */
  18. export declare function traceable<Func extends (...args: any[]) => any>(wrappedFunc: Func, config?: Partial<Omit<RunTreeConfig, "inputs" | "outputs">> & {
  19. aggregator?: (args: any[]) => any;
  20. argsConfigPath?: [number] | [number, string];
  21. __finalTracedIteratorKey?: string;
  22. /**
  23. * Extract attachments from args and return remaining args.
  24. * @param args Arguments of the traced function
  25. * @returns Tuple of [Attachments, remaining args]
  26. */
  27. extractAttachments?: (...args: Parameters<Func>) => [Attachments | undefined, KVMap];
  28. /**
  29. * Extract invocation parameters from the arguments of the traced function.
  30. * This is useful for LangSmith to properly track common metadata like
  31. * provider, model name and temperature.
  32. *
  33. * @param args Arguments of the traced function
  34. * @returns Key-value map of the invocation parameters, which will be merged with the existing metadata
  35. */
  36. getInvocationParams?: (...args: Parameters<Func>) => InvocationParamsSchema | undefined;
  37. /**
  38. * Apply transformations to the inputs before logging.
  39. * This function should NOT mutate the inputs.
  40. * `processInputs` is not inherited by nested traceable functions.
  41. *
  42. * @param inputs Key-value map of the function inputs.
  43. * @returns Transformed key-value map
  44. */
  45. processInputs?: (inputs: Readonly<KVMap>) => KVMap;
  46. /**
  47. * Apply transformations to the outputs before logging.
  48. * This function should NOT mutate the outputs.
  49. * `processOutputs` is not inherited by nested traceable functions.
  50. *
  51. * @param outputs Key-value map of the function outputs
  52. * @returns Transformed key-value map
  53. */
  54. processOutputs?: (outputs: Readonly<KVMap>) => KVMap;
  55. }): TraceableFunction<Func>;
  56. export { getCurrentRunTree, isTraceableFunction, withRunTree, ROOT, } from "./singletons/traceable.js";
  57. export type { RunTreeLike, TraceableFunction } from "./singletons/types.js";