langwatch 0.3.1 → 0.4.0

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.
Files changed (203) hide show
  1. package/README.md +5 -2
  2. package/dist/{add-LBBS4I3H.js → add-35QACTIV.js} +34 -28
  3. package/dist/add-35QACTIV.js.map +1 -0
  4. package/dist/{add-RD3ZKFAT.mjs → add-TRJAXM4D.mjs} +22 -16
  5. package/dist/add-TRJAXM4D.mjs.map +1 -0
  6. package/dist/chunk-4ZSSHX6F.js +636 -0
  7. package/dist/chunk-4ZSSHX6F.js.map +1 -0
  8. package/dist/chunk-5EVBOHJY.js +155 -0
  9. package/dist/chunk-5EVBOHJY.js.map +1 -0
  10. package/dist/{chunk-YN4436PK.mjs → chunk-CU3443HD.mjs} +14 -9
  11. package/dist/{chunk-2JU376G7.js → chunk-D2CSG4SJ.js} +4 -4
  12. package/dist/chunk-D2CSG4SJ.js.map +1 -0
  13. package/dist/chunk-DISMHYXC.js +184 -0
  14. package/dist/chunk-DISMHYXC.js.map +1 -0
  15. package/dist/{chunk-E7UE2MPD.mjs → chunk-ECUXLXFT.mjs} +2 -2
  16. package/dist/chunk-EJWJXTPU.mjs +626 -0
  17. package/dist/chunk-EJWJXTPU.mjs.map +1 -0
  18. package/dist/chunk-GQMDZ4GY.mjs +155 -0
  19. package/dist/chunk-GQMDZ4GY.mjs.map +1 -0
  20. package/dist/{chunk-3GKPQB4R.mjs → chunk-HUI45ULC.mjs} +4 -4
  21. package/dist/chunk-HUI45ULC.mjs.map +1 -0
  22. package/dist/{chunk-HJU67C7H.js → chunk-K64Y6YUG.js} +10 -10
  23. package/dist/{chunk-HJU67C7H.js.map → chunk-K64Y6YUG.js.map} +1 -1
  24. package/dist/chunk-LP76VXI3.mjs +636 -0
  25. package/dist/chunk-LP76VXI3.mjs.map +1 -0
  26. package/dist/chunk-M4VUHTT2.js +626 -0
  27. package/dist/chunk-M4VUHTT2.js.map +1 -0
  28. package/dist/{chunk-PR3JDWC3.mjs → chunk-N2V6J3U2.mjs} +28 -3
  29. package/dist/chunk-N2V6J3U2.mjs.map +1 -0
  30. package/dist/chunk-OUCVXP4G.js +258 -0
  31. package/dist/chunk-OUCVXP4G.js.map +1 -0
  32. package/dist/{chunk-FJLK5CFL.js → chunk-OXBO24RB.js} +13 -8
  33. package/dist/chunk-OXBO24RB.js.map +1 -0
  34. package/dist/chunk-PGWR3OQY.mjs +258 -0
  35. package/dist/chunk-PGWR3OQY.mjs.map +1 -0
  36. package/dist/{chunk-SMXXAVMB.js → chunk-SGNJDRCT.js} +2 -2
  37. package/dist/chunk-SGNJDRCT.js.map +1 -0
  38. package/dist/{chunk-W5ZEP3CI.mjs → chunk-SYMZPWZE.mjs} +2 -2
  39. package/dist/chunk-SYMZPWZE.mjs.map +1 -0
  40. package/dist/{chunk-KGDAENGD.js → chunk-YH5TIVK2.js} +28 -3
  41. package/dist/chunk-YH5TIVK2.js.map +1 -0
  42. package/dist/chunk-YNQ44U6D.mjs +184 -0
  43. package/dist/chunk-YNQ44U6D.mjs.map +1 -0
  44. package/dist/cli/index.js +8 -8
  45. package/dist/cli/index.mjs +8 -8
  46. package/dist/{create-G5MTGOOH.js → create-7K2CC4KQ.js} +11 -11
  47. package/dist/{create-G5MTGOOH.js.map → create-7K2CC4KQ.js.map} +1 -1
  48. package/dist/{create-QUZYBMQB.mjs → create-MK7NEGCM.mjs} +8 -8
  49. package/dist/implementation-C4lvooSg.d.mts +576 -0
  50. package/dist/implementation-CzemP9jY.d.ts +576 -0
  51. package/dist/index-DTEZr0Jn.d.mts +34 -0
  52. package/dist/index-DTEZr0Jn.d.ts +34 -0
  53. package/dist/index.d.mts +122 -41
  54. package/dist/index.d.ts +122 -41
  55. package/dist/index.js +16 -12
  56. package/dist/index.js.map +1 -1
  57. package/dist/index.mjs +27 -23
  58. package/dist/index.mjs.map +1 -1
  59. package/dist/init-GDKJICSS.js +16 -0
  60. package/dist/{init-XU2JFY6N.js.map → init-GDKJICSS.js.map} +1 -1
  61. package/dist/{init-H67RW22E.mjs → init-RINSTP4L.mjs} +5 -5
  62. package/dist/{list-7NPSX2E4.mjs → list-7L23G5DY.mjs} +28 -16
  63. package/dist/list-7L23G5DY.mjs.map +1 -0
  64. package/dist/{list-ZXFLAF52.js → list-OLLQ7XKZ.js} +29 -17
  65. package/dist/list-OLLQ7XKZ.js.map +1 -0
  66. package/dist/{login-EK4WVOI2.mjs → login-RCNKL5AM.mjs} +6 -5
  67. package/dist/login-RCNKL5AM.mjs.map +1 -0
  68. package/dist/{login-76NQIHKR.js → login-XF3BQQPV.js} +7 -6
  69. package/dist/login-XF3BQQPV.js.map +1 -0
  70. package/dist/observability-sdk/index.d.mts +134 -0
  71. package/dist/observability-sdk/index.d.ts +134 -0
  72. package/dist/observability-sdk/index.js +41 -0
  73. package/dist/observability-sdk/index.js.map +1 -0
  74. package/dist/observability-sdk/index.mjs +41 -0
  75. package/dist/observability-sdk/instrumentation/langchain/index.d.mts +69 -0
  76. package/dist/observability-sdk/instrumentation/langchain/index.d.ts +69 -0
  77. package/dist/observability-sdk/instrumentation/langchain/index.js +518 -0
  78. package/dist/observability-sdk/instrumentation/langchain/index.js.map +1 -0
  79. package/dist/observability-sdk/instrumentation/langchain/index.mjs +518 -0
  80. package/dist/observability-sdk/instrumentation/langchain/index.mjs.map +1 -0
  81. package/dist/observability-sdk/setup/node/index.d.mts +368 -0
  82. package/dist/observability-sdk/setup/node/index.d.ts +368 -0
  83. package/dist/observability-sdk/setup/node/index.js +276 -0
  84. package/dist/observability-sdk/setup/node/index.js.map +1 -0
  85. package/dist/observability-sdk/setup/node/index.mjs +276 -0
  86. package/dist/observability-sdk/setup/node/index.mjs.map +1 -0
  87. package/dist/{remove-SDJYEPAY.mjs → remove-3VLQNVHN.mjs} +11 -8
  88. package/dist/remove-3VLQNVHN.mjs.map +1 -0
  89. package/dist/{remove-XBNGIVMR.js → remove-L6JVJBWY.js} +18 -15
  90. package/dist/remove-L6JVJBWY.js.map +1 -0
  91. package/dist/{sync-ST2IWXSB.mjs → sync-DPMTUTVL.mjs} +39 -33
  92. package/dist/sync-DPMTUTVL.mjs.map +1 -0
  93. package/dist/{sync-EISKGPTL.js → sync-PSU3F5Z4.js} +52 -46
  94. package/dist/sync-PSU3F5Z4.js.map +1 -0
  95. package/dist/{prompt-D-jpMrLS.d.mts → types-1q5wIYP5.d.mts} +628 -14
  96. package/dist/{prompt-D-jpMrLS.d.ts → types-C9k5gGhU.d.ts} +628 -14
  97. package/dist/types-DRiQaKFG.d.mts +254 -0
  98. package/dist/types-DRiQaKFG.d.ts +254 -0
  99. package/dist/types-Dmazk5Bk.d.mts +44 -0
  100. package/dist/types-Dmazk5Bk.d.ts +44 -0
  101. package/package.json +40 -40
  102. package/dist/add-LBBS4I3H.js.map +0 -1
  103. package/dist/add-RD3ZKFAT.mjs.map +0 -1
  104. package/dist/chunk-2JU376G7.js.map +0 -1
  105. package/dist/chunk-2ODBGSBI.js +0 -4
  106. package/dist/chunk-2ODBGSBI.js.map +0 -1
  107. package/dist/chunk-3GKPQB4R.mjs.map +0 -1
  108. package/dist/chunk-52GXX3MA.js +0 -426
  109. package/dist/chunk-52GXX3MA.js.map +0 -1
  110. package/dist/chunk-5NC5ILKA.js +0 -94
  111. package/dist/chunk-5NC5ILKA.js.map +0 -1
  112. package/dist/chunk-6I4EA43Y.js +0 -39
  113. package/dist/chunk-6I4EA43Y.js.map +0 -1
  114. package/dist/chunk-DTEKFQ4U.js +0 -159
  115. package/dist/chunk-DTEKFQ4U.js.map +0 -1
  116. package/dist/chunk-F63YKTXA.mjs +0 -47
  117. package/dist/chunk-F63YKTXA.mjs.map +0 -1
  118. package/dist/chunk-FJLK5CFL.js.map +0 -1
  119. package/dist/chunk-GJSEBQXF.mjs +0 -392
  120. package/dist/chunk-GJSEBQXF.mjs.map +0 -1
  121. package/dist/chunk-J7ICRUU4.mjs +0 -426
  122. package/dist/chunk-J7ICRUU4.mjs.map +0 -1
  123. package/dist/chunk-KGDAENGD.js.map +0 -1
  124. package/dist/chunk-LD74LVRU.js +0 -47
  125. package/dist/chunk-LD74LVRU.js.map +0 -1
  126. package/dist/chunk-PCQVQ7SB.js +0 -45
  127. package/dist/chunk-PCQVQ7SB.js.map +0 -1
  128. package/dist/chunk-PR3JDWC3.mjs.map +0 -1
  129. package/dist/chunk-PWZBLTHR.js +0 -118
  130. package/dist/chunk-PWZBLTHR.js.map +0 -1
  131. package/dist/chunk-QEWDG5QE.mjs +0 -45
  132. package/dist/chunk-QEWDG5QE.mjs.map +0 -1
  133. package/dist/chunk-SMXXAVMB.js.map +0 -1
  134. package/dist/chunk-STV4ZVNA.mjs +0 -118
  135. package/dist/chunk-STV4ZVNA.mjs.map +0 -1
  136. package/dist/chunk-T5AZMMVS.mjs +0 -94
  137. package/dist/chunk-T5AZMMVS.mjs.map +0 -1
  138. package/dist/chunk-UU33HCCZ.mjs +0 -159
  139. package/dist/chunk-UU33HCCZ.mjs.map +0 -1
  140. package/dist/chunk-VGHLQXKB.js +0 -392
  141. package/dist/chunk-VGHLQXKB.js.map +0 -1
  142. package/dist/chunk-W5ZEP3CI.mjs.map +0 -1
  143. package/dist/chunk-Y666BJA5.mjs +0 -4
  144. package/dist/chunk-YFUZF7JM.mjs +0 -39
  145. package/dist/chunk-YFUZF7JM.mjs.map +0 -1
  146. package/dist/chunk-YN4436PK.mjs.map +0 -1
  147. package/dist/client-B2HqIKg6.d.ts +0 -51
  148. package/dist/client-XyCqclCi.d.mts +0 -51
  149. package/dist/client-browser.d.mts +0 -8
  150. package/dist/client-browser.d.ts +0 -8
  151. package/dist/client-browser.js +0 -85
  152. package/dist/client-browser.js.map +0 -1
  153. package/dist/client-browser.mjs +0 -85
  154. package/dist/client-browser.mjs.map +0 -1
  155. package/dist/client-node.d.mts +0 -8
  156. package/dist/client-node.d.ts +0 -8
  157. package/dist/client-node.js +0 -92
  158. package/dist/client-node.js.map +0 -1
  159. package/dist/client-node.mjs +0 -92
  160. package/dist/client-node.mjs.map +0 -1
  161. package/dist/evaluation/index.d.mts +0 -897
  162. package/dist/evaluation/index.d.ts +0 -897
  163. package/dist/evaluation/index.js +0 -14
  164. package/dist/evaluation/index.js.map +0 -1
  165. package/dist/evaluation/index.mjs +0 -14
  166. package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +0 -64
  167. package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +0 -64
  168. package/dist/init-XU2JFY6N.js +0 -16
  169. package/dist/list-7NPSX2E4.mjs.map +0 -1
  170. package/dist/list-ZXFLAF52.js.map +0 -1
  171. package/dist/login-76NQIHKR.js.map +0 -1
  172. package/dist/login-EK4WVOI2.mjs.map +0 -1
  173. package/dist/observability/index.d.mts +0 -260
  174. package/dist/observability/index.d.ts +0 -260
  175. package/dist/observability/index.js +0 -21
  176. package/dist/observability/index.js.map +0 -1
  177. package/dist/observability/index.mjs +0 -21
  178. package/dist/observability/index.mjs.map +0 -1
  179. package/dist/observability/instrumentation/langchain/index.d.mts +0 -40
  180. package/dist/observability/instrumentation/langchain/index.d.ts +0 -40
  181. package/dist/observability/instrumentation/langchain/index.js +0 -668
  182. package/dist/observability/instrumentation/langchain/index.js.map +0 -1
  183. package/dist/observability/instrumentation/langchain/index.mjs +0 -668
  184. package/dist/observability/instrumentation/langchain/index.mjs.map +0 -1
  185. package/dist/prompt/index.d.mts +0 -10
  186. package/dist/prompt/index.d.ts +0 -10
  187. package/dist/prompt/index.js +0 -22
  188. package/dist/prompt/index.js.map +0 -1
  189. package/dist/prompt/index.mjs +0 -22
  190. package/dist/prompt/index.mjs.map +0 -1
  191. package/dist/record-evaluation-CmxMXa-3.d.mts +0 -25
  192. package/dist/record-evaluation-CmxMXa-3.d.ts +0 -25
  193. package/dist/remove-SDJYEPAY.mjs.map +0 -1
  194. package/dist/remove-XBNGIVMR.js.map +0 -1
  195. package/dist/sync-EISKGPTL.js.map +0 -1
  196. package/dist/sync-ST2IWXSB.mjs.map +0 -1
  197. package/dist/trace-CqaKo0kZ.d.ts +0 -622
  198. package/dist/trace-DtVc5GhF.d.mts +0 -622
  199. /package/dist/{chunk-Y666BJA5.mjs.map → chunk-CU3443HD.mjs.map} +0 -0
  200. /package/dist/{chunk-E7UE2MPD.mjs.map → chunk-ECUXLXFT.mjs.map} +0 -0
  201. /package/dist/{create-QUZYBMQB.mjs.map → create-MK7NEGCM.mjs.map} +0 -0
  202. /package/dist/{init-H67RW22E.mjs.map → init-RINSTP4L.mjs.map} +0 -0
  203. /package/dist/{evaluation → observability-sdk}/index.mjs.map +0 -0
@@ -1,3 +1,88 @@
1
+ import { SpanOptions, Span, AttributeValue, Tracer, Context } from '@opentelemetry/api';
2
+ import { S as SemConvAttributes } from './types-DRiQaKFG.mjs';
3
+
4
+ type ChatRole = "system" | "user" | "assistant" | "function" | "tool" | "unknown";
5
+ interface FunctionCall {
6
+ name?: string;
7
+ arguments?: string;
8
+ }
9
+ interface ToolCall {
10
+ id: string;
11
+ type: string;
12
+ function: FunctionCall;
13
+ }
14
+ interface ChatMessage {
15
+ role?: ChatRole;
16
+ content?: string | ChatRichContent[] | null;
17
+ function_call?: FunctionCall | null;
18
+ tool_calls?: ToolCall[] | null;
19
+ tool_call_id?: string | null;
20
+ name?: string | null;
21
+ }
22
+ type ChatRichContent = {
23
+ type: "text";
24
+ text?: string;
25
+ } | {
26
+ text: string;
27
+ } | {
28
+ type: "image_url";
29
+ image_url?: {
30
+ url: string;
31
+ detail?: "auto" | "low" | "high";
32
+ };
33
+ } | {
34
+ type: "tool_call";
35
+ toolName?: string;
36
+ toolCallId?: string;
37
+ args?: string;
38
+ } | {
39
+ type: "tool_result";
40
+ toolName?: string;
41
+ toolCallId?: string;
42
+ result?: any;
43
+ };
44
+ interface TypedValueChatMessages {
45
+ type: "chat_messages";
46
+ value: ChatMessage[];
47
+ }
48
+ interface TypedValueText {
49
+ type: "text";
50
+ value: string;
51
+ }
52
+ interface TypedValueRaw {
53
+ type: "raw";
54
+ value: string;
55
+ }
56
+ type JSONSerializable = string | number | boolean | null | Record<string, any> | any[];
57
+ interface TypedValueJson {
58
+ type: "json";
59
+ value: JSONSerializable;
60
+ }
61
+ type Money = {
62
+ currency: string;
63
+ amount: number;
64
+ };
65
+ interface EvaluationResult {
66
+ status: "processed" | "skipped" | "error";
67
+ passed?: boolean | null;
68
+ score?: number | null;
69
+ label?: string | null;
70
+ details?: string | null;
71
+ cost?: Money | null;
72
+ }
73
+ interface TypedValueGuardrailResult {
74
+ type: "guardrail_result";
75
+ value: EvaluationResult;
76
+ }
77
+ interface TypedValueEvaluationResult {
78
+ type: "evaluation_result";
79
+ value: EvaluationResult;
80
+ }
81
+ type SpanInputOutput = TypedValueText | TypedValueChatMessages | TypedValueGuardrailResult | TypedValueEvaluationResult | TypedValueJson | TypedValueRaw | {
82
+ type: "list";
83
+ value: SpanInputOutput[];
84
+ };
85
+
1
86
  /**
2
87
  * This file was auto-generated by openapi-typescript.
3
88
  * Do not make direct changes to the file.
@@ -923,6 +1008,8 @@ interface operations {
923
1008
  handle: string | null;
924
1009
  /** @enum {string} */
925
1010
  scope: "ORGANIZATION" | "PROJECT";
1011
+ projectId: string;
1012
+ organizationId: string;
926
1013
  }[];
927
1014
  };
928
1015
  };
@@ -973,13 +1060,35 @@ interface operations {
973
1060
  requestBody?: {
974
1061
  content: {
975
1062
  "application/json": {
976
- name: string;
977
- handle?: string;
1063
+ name?: string;
1064
+ handle: string;
978
1065
  /**
979
1066
  * @default PROJECT
980
1067
  * @enum {string}
981
1068
  */
982
1069
  scope?: "ORGANIZATION" | "PROJECT";
1070
+ authorId?: string;
1071
+ prompt?: string;
1072
+ messages?: {
1073
+ /** @enum {string} */
1074
+ role: "user" | "assistant" | "system";
1075
+ content: string;
1076
+ }[];
1077
+ inputs?: {
1078
+ identifier: string;
1079
+ /** @enum {string} */
1080
+ type: "str" | "float" | "bool" | "image" | "list[str]" | "list[float]" | "list[int]" | "list[bool]" | "dict";
1081
+ }[];
1082
+ outputs?: {
1083
+ identifier: string;
1084
+ /** @enum {string} */
1085
+ type: "str" | "float" | "bool" | "json_schema";
1086
+ json_schema?: {
1087
+ type: string;
1088
+ } & {
1089
+ [key: string]: unknown;
1090
+ };
1091
+ }[];
983
1092
  };
984
1093
  };
985
1094
  };
@@ -1017,6 +1126,8 @@ interface operations {
1017
1126
  handle: string | null;
1018
1127
  /** @enum {string} */
1019
1128
  scope: "ORGANIZATION" | "PROJECT";
1129
+ projectId: string;
1130
+ organizationId: string;
1020
1131
  };
1021
1132
  };
1022
1133
  };
@@ -2161,15 +2272,8 @@ interface operations {
2161
2272
 
2162
2273
  type PromptResponse = NonNullable<paths["/api/prompts/{id}"]["get"]["responses"]["200"]["content"]["application/json"]>;
2163
2274
  type TemplateVariables = Record<string, string | number | boolean | object | null>;
2164
- /**
2165
- * Error class for template compilation issues
2166
- */
2167
- declare class PromptCompilationError extends Error {
2168
- readonly template: string;
2169
- readonly originalError?: any | undefined;
2170
- constructor(message: string, template: string, originalError?: any | undefined);
2171
- }
2172
2275
  declare class Prompt implements PromptResponse {
2276
+ private readonly promptData;
2173
2277
  readonly id: string;
2174
2278
  readonly handle: string | null;
2175
2279
  readonly scope: "ORGANIZATION" | "PROJECT";
@@ -2201,12 +2305,522 @@ declare class Prompt implements PromptResponse {
2201
2305
  */
2202
2306
  compileStrict(variables: TemplateVariables): CompiledPrompt;
2203
2307
  }
2204
- /**
2205
- * Represents a compiled prompt that extends Prompt with reference to the original template
2206
- */
2207
2308
  declare class CompiledPrompt extends Prompt {
2208
2309
  readonly original: Prompt;
2209
2310
  constructor(compiledData: PromptResponse, original: Prompt);
2210
2311
  }
2211
2312
 
2212
- export { CompiledPrompt as C, Prompt as P, type TemplateVariables as T, PromptCompilationError as a };
2313
+ /**
2314
+ * Simple chat message type with just role and content
2315
+ */
2316
+ interface SimpleChatMessage {
2317
+ role: string;
2318
+ content: unknown;
2319
+ }
2320
+ /**
2321
+ * Valid input/output types for span data
2322
+ */
2323
+ declare const INPUT_OUTPUT_TYPES: readonly ["text", "raw", "chat_messages", "list", "json", "guardrail_result", "evaluation_result"];
2324
+ type InputOutputType = typeof INPUT_OUTPUT_TYPES[number];
2325
+ type JsonSerializable = string | number | boolean | null | JsonSerializable[] | Record<string, any>;
2326
+
2327
+ /**
2328
+ * Supported types of spans for LangWatch observability. These types categorize the nature of the span for downstream analysis and visualization.
2329
+ *
2330
+ * @example
2331
+ * import { spanTypes, SpanType } from './span';
2332
+ * const myType: SpanType = 'llm';
2333
+ */
2334
+ declare const spanTypes: readonly ["span", "llm", "chain", "tool", "agent", "guardrail", "evaluation", "rag", "prompt", "workflow", "component", "module", "server", "client", "producer", "consumer", "task", "unknown"];
2335
+ type SpanType = (typeof spanTypes)[number];
2336
+ /**
2337
+ * Context for a RAG (Retrieval-Augmented Generation) span.
2338
+ *
2339
+ * This structure is used to record which document and chunk were retrieved and used as context for a generation.
2340
+ *
2341
+ * @property document_id - Unique identifier for the source document.
2342
+ * @property chunk_id - Unique identifier for the chunk within the document.
2343
+ * @property content - The actual content of the chunk provided to the model.
2344
+ *
2345
+ * @example
2346
+ * const ragContext: LangWatchSpanRAGContext = {
2347
+ * document_id: 'doc-123',
2348
+ * chunk_id: 'chunk-456',
2349
+ * content: 'Relevant passage from the document.'
2350
+ * };
2351
+ */
2352
+ interface LangWatchSpanRAGContext {
2353
+ document_id: string;
2354
+ chunk_id: string;
2355
+ content: string;
2356
+ }
2357
+ /**
2358
+ * Metrics for a LangWatch span.
2359
+ *
2360
+ * @property promptTokens - The number of prompt tokens used.
2361
+ * @property completionTokens - The number of completion tokens used.
2362
+ * @property cost - The cost of the span.
2363
+ */
2364
+ interface LangWatchSpanMetrics {
2365
+ /** The number of prompt tokens used */
2366
+ promptTokens?: number;
2367
+ /** The number of completion tokens used */
2368
+ completionTokens?: number;
2369
+ /** The cost of the span */
2370
+ cost?: number;
2371
+ }
2372
+ /**
2373
+ * Options for creating a LangWatch span.
2374
+ *
2375
+ * @param attributes - Additional attributes to add to the span.
2376
+ */
2377
+ interface LangWatchSpanOptions extends SpanOptions {
2378
+ /** Additional attributes to add to the span. */
2379
+ attributes?: SemConvAttributes;
2380
+ }
2381
+ /**
2382
+ * Extension of OpenTelemetry's Span with LangWatch-specific helpers for LLM, RAG, and GenAI tracing.
2383
+ *
2384
+ * This interface provides ergonomic methods for recording structured LLM/GenAI data, such as inputs, outputs, RAG contexts, and message events.
2385
+ *
2386
+ * All methods return `this` for chaining.
2387
+ *
2388
+ * @example
2389
+ * const span = createLangWatchSpan(otelSpan);
2390
+ * span
2391
+ * .setType('llm')
2392
+ * .setInput({ prompt: 'Hello' })
2393
+ * .setOutput('Hi!')
2394
+ * .addGenAIUserMessageEvent({ content: 'Hello' })
2395
+ * .addGenAIAssistantMessageEvent({ content: 'Hi!' });
2396
+ */
2397
+ interface LangWatchSpan extends Span {
2398
+ /**
2399
+ * Set multiple attributes for the span.
2400
+ *
2401
+ * @param attributes - The attributes object
2402
+ * @returns this
2403
+ */
2404
+ setAttributes(attributes: SemConvAttributes): this;
2405
+ /**
2406
+ * Set a single attribute for the span.
2407
+ *
2408
+ * @param key - The attribute key
2409
+ * @param value - The attribute value
2410
+ * @returns this
2411
+ */
2412
+ setAttribute(key: keyof SemConvAttributes, value: AttributeValue): this;
2413
+ /**
2414
+ * Set the type of the span (e.g., 'llm', 'rag', 'tool', etc).
2415
+ *
2416
+ * This is used for downstream filtering and analytics.
2417
+ *
2418
+ * @param type - The span type (see SpanType)
2419
+ * @returns this
2420
+ */
2421
+ setType(type: SpanType): this;
2422
+ /**
2423
+ * Set the request model name for the span.
2424
+ *
2425
+ * This is typically the model name sent in the API request (e.g., 'gpt-4', 'claude-3').
2426
+ *
2427
+ * @param model - The request model name
2428
+ * @returns this
2429
+ */
2430
+ setRequestModel(model: string): this;
2431
+ /**
2432
+ * Set the response model name for the span.
2433
+ *
2434
+ * This is the model name returned in the API response, if different from the request.
2435
+ *
2436
+ * @param model - The response model name
2437
+ * @returns this
2438
+ */
2439
+ setResponseModel(model: string): this;
2440
+ /**
2441
+ * Set multiple RAG contexts for the span.
2442
+ *
2443
+ * Use this to record all retrieved documents/chunks used as context for a generation.
2444
+ *
2445
+ * @param ragContexts - Array of RAG context objects
2446
+ * @returns this
2447
+ */
2448
+ setRAGContexts(ragContexts: LangWatchSpanRAGContext[]): this;
2449
+ /**
2450
+ * Set a single RAG context for the span.
2451
+ *
2452
+ * Use this if only one context was retrieved.
2453
+ *
2454
+ * @param ragContext - The RAG context object
2455
+ * @returns this
2456
+ */
2457
+ setRAGContext(ragContext: LangWatchSpanRAGContext): this;
2458
+ /**
2459
+ * Set the metrics for the span.
2460
+ *
2461
+ * @param metrics - The metrics object
2462
+ * @returns this
2463
+ */
2464
+ setMetrics(metrics: LangWatchSpanMetrics): this;
2465
+ /**
2466
+ * Set the selected prompt for the span. This will attach this prompt to the trace. If
2467
+ * this is set on multiple spans, the last one will be used.
2468
+ *
2469
+ * @param prompt - The prompt object
2470
+ * @returns this
2471
+ */
2472
+ setSelectedPrompt(prompt: Prompt): this;
2473
+ /**
2474
+ * Record the input to the span with explicit type control.
2475
+ *
2476
+ * @param type - Force as "text" type
2477
+ * @param input - String input value
2478
+ * @returns this
2479
+ */
2480
+ setInput(type: "text", input: string): this;
2481
+ /**
2482
+ * Record the input to the span with explicit type control.
2483
+ *
2484
+ * @param type - Force as "raw" type
2485
+ * @param input - Any input value
2486
+ * @returns this
2487
+ */
2488
+ setInput(type: "raw", input: unknown): this;
2489
+ /**
2490
+ * Record the input to the span with explicit type control.
2491
+ *
2492
+ * @param type - Force as "chat_messages" type
2493
+ * @param input - Chat messages array (supports both ChatMessage[] and SimpleChatMessage[])
2494
+ * @returns this
2495
+ */
2496
+ setInput(type: "chat_messages", input: ChatMessage[] | SimpleChatMessage[]): this;
2497
+ /**
2498
+ * Record the input to the span with explicit type control.
2499
+ *
2500
+ * @param type - Force as "list" type
2501
+ * @param input - SpanInputOutput array
2502
+ * @returns this
2503
+ */
2504
+ setInput(type: "list", input: SpanInputOutput[]): this;
2505
+ /**
2506
+ * Record the input to the span with explicit type control.
2507
+ *
2508
+ * @param type - Force as "json" type
2509
+ * @param input - Any JSON-serializable value
2510
+ * @returns this
2511
+ */
2512
+ setInput(type: "json", input: unknown): this;
2513
+ /**
2514
+ * Record the input to the span with explicit type control.
2515
+ *
2516
+ * @param type - Force as "guardrail_result" type
2517
+ * @param input - Guardrail result value
2518
+ * @returns this
2519
+ */
2520
+ setInput(type: "guardrail_result", input: unknown): this;
2521
+ /**
2522
+ * Record the input to the span with explicit type control.
2523
+ *
2524
+ * @param type - Force as "evaluation_result" type
2525
+ * @param input - Evaluation result value
2526
+ * @returns this
2527
+ */
2528
+ setInput(type: "evaluation_result", input: unknown): this;
2529
+ /**
2530
+ * Record the input to the span with automatic type detection.
2531
+ *
2532
+ * Automatically detects: strings → text, ChatMessage[] → chat_messages,
2533
+ * arrays → list, objects → json.
2534
+ *
2535
+ * @param input - The input value (auto-detected type)
2536
+ * @returns this
2537
+ */
2538
+ setInput(input: unknown): this;
2539
+ /**
2540
+ * Record the output from the span with explicit type control.
2541
+ *
2542
+ * @param type - Force as "text" type
2543
+ * @param output - String output value
2544
+ * @returns this
2545
+ */
2546
+ setOutput(type: "text", output: string): this;
2547
+ /**
2548
+ * Record the output from the span with explicit type control.
2549
+ *
2550
+ * @param type - Force as "raw" type
2551
+ * @param output - Any output value
2552
+ * @returns this
2553
+ */
2554
+ setOutput(type: "raw", output: unknown): this;
2555
+ /**
2556
+ * Record the output from the span with explicit type control.
2557
+ *
2558
+ * @param type - Force as "chat_messages" type
2559
+ * @param output - Chat messages array (supports both ChatMessage[] and SimpleChatMessage[])
2560
+ * @returns this
2561
+ */
2562
+ setOutput(type: "chat_messages", output: ChatMessage[] | SimpleChatMessage[]): this;
2563
+ /**
2564
+ * Record the output from the span with explicit type control.
2565
+ *
2566
+ * @param type - Force as "list" type
2567
+ * @param output - SpanInputOutput array
2568
+ * @returns this
2569
+ */
2570
+ setOutput(type: "list", output: SpanInputOutput[]): this;
2571
+ /**
2572
+ * Record the output from the span with explicit type control.
2573
+ *
2574
+ * @param type - Force as "json" type
2575
+ * @param output - Any JSON-serializable value
2576
+ * @returns this
2577
+ */
2578
+ setOutput(type: "json", output: unknown): this;
2579
+ /**
2580
+ * Record the output from the span with explicit type control.
2581
+ *
2582
+ * @param type - Force as "guardrail_result" type
2583
+ * @param output - Guardrail result value
2584
+ * @returns this
2585
+ */
2586
+ setOutput(type: "guardrail_result", output: unknown): this;
2587
+ /**
2588
+ * Record the output from the span with explicit type control.
2589
+ *
2590
+ * @param type - Force as "evaluation_result" type
2591
+ * @param output - Evaluation result value
2592
+ * @returns this
2593
+ */
2594
+ setOutput(type: "evaluation_result", output: unknown): this;
2595
+ /**
2596
+ * Record the output from the span with automatic type detection.
2597
+ *
2598
+ * Automatically detects: strings → text, ChatMessage[] → chat_messages,
2599
+ * arrays → list, objects → json.
2600
+ *
2601
+ * @param output - The output value (auto-detected type)
2602
+ * @returns this
2603
+ */
2604
+ setOutput(output: unknown): this;
2605
+ }
2606
+
2607
+ /**
2608
+ * Enhanced LangWatch tracer interface that extends OpenTelemetry's Tracer.
2609
+ *
2610
+ * This tracer provides additional functionality beyond the standard OpenTelemetry tracer:
2611
+ * - Returns LangWatchSpan instances instead of standard OpenTelemetry Spans
2612
+ * - Includes a custom `withActiveSpan` method for simplified span lifecycle management
2613
+ * - Automatic error handling and span status management in `withActiveSpan`
2614
+ * - Enhanced type safety with strongly-typed callback functions
2615
+ *
2616
+ * @example Basic usage
2617
+ * ```typescript
2618
+ * const tracer = getLangWatchTracer('my-service', '1.0.0');
2619
+ *
2620
+ * // Create and manage spans manually
2621
+ * const span = tracer.startSpan('operation');
2622
+ * span.setAttributes({ key: 'value' });
2623
+ * span.end();
2624
+ *
2625
+ * // Use active span with automatic lifecycle management
2626
+ * const result = await tracer.startActiveSpan('async-operation', async (span) => {
2627
+ * span.setAttributes({ userId: '123' });
2628
+ * return await someAsyncWork();
2629
+ * });
2630
+ *
2631
+ * // Use withActiveSpan for automatic error handling and span cleanup
2632
+ * const result = await tracer.withActiveSpan('safe-operation', async (span) => {
2633
+ * // Span is automatically ended and errors are properly recorded
2634
+ * return await riskyOperation();
2635
+ * });
2636
+ * ```
2637
+ */
2638
+ interface LangWatchTracer extends Tracer {
2639
+ /**
2640
+ * Starts a new LangWatchSpan without setting it as the active span.
2641
+ *
2642
+ * **Enhanced from OpenTelemetry**: Returns a LangWatchSpan instead of a standard Span,
2643
+ * providing additional LangWatch-specific functionality like structured input/output
2644
+ * recording and enhanced attribute management.
2645
+ *
2646
+ * @param name - The name of the span
2647
+ * @param options - Optional span configuration options
2648
+ * @param context - Optional context to use for extracting parent span information
2649
+ * @returns A new LangWatchSpan instance
2650
+ *
2651
+ * @example
2652
+ * ```typescript
2653
+ * const span = tracer.startSpan('database-query');
2654
+ * span.setAttributes({
2655
+ * 'db.statement': 'SELECT * FROM users',
2656
+ * 'db.operation': 'select'
2657
+ * });
2658
+ *
2659
+ * try {
2660
+ * const result = await database.query('SELECT * FROM users');
2661
+ * span.setStatus({ code: SpanStatusCode.OK });
2662
+ * return result;
2663
+ * } catch (error) {
2664
+ * span.setStatus({
2665
+ * code: SpanStatusCode.ERROR,
2666
+ * message: error.message
2667
+ * });
2668
+ * span.recordException(error);
2669
+ * throw error;
2670
+ * } finally {
2671
+ * span.end();
2672
+ * }
2673
+ * ```
2674
+ */
2675
+ startSpan(name: string, options?: LangWatchSpanOptions, context?: Context): LangWatchSpan;
2676
+ /**
2677
+ * Starts a new active LangWatchSpan and executes the provided function within its context.
2678
+ *
2679
+ * **Same as OpenTelemetry** but with LangWatchSpan: The span is automatically set as active
2680
+ * in the current context for the duration of the function execution. The span must be
2681
+ * manually ended within the callback function.
2682
+ *
2683
+ * @param name - The name of the span
2684
+ * @param fn - Function to execute with the active span
2685
+ * @returns The return value of the provided function
2686
+ *
2687
+ * @example
2688
+ * ```typescript
2689
+ * const result = tracer.startActiveSpan('user-operation', (span) => {
2690
+ * span.setAttributes({ userId: '123' });
2691
+ *
2692
+ * try {
2693
+ * const userData = fetchUserData();
2694
+ * span.setStatus({ code: SpanStatusCode.OK });
2695
+ * return userData;
2696
+ * } catch (error) {
2697
+ * span.setStatus({
2698
+ * code: SpanStatusCode.ERROR,
2699
+ * message: error.message
2700
+ * });
2701
+ * throw error;
2702
+ * } finally {
2703
+ * span.end(); // Must manually end the span
2704
+ * }
2705
+ * });
2706
+ * ```
2707
+ */
2708
+ startActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, fn: F): ReturnType<F>;
2709
+ /**
2710
+ * Starts a new active LangWatchSpan with options and executes the provided function.
2711
+ *
2712
+ * @param name - The name of the span
2713
+ * @param options - Span configuration options
2714
+ * @param fn - Function to execute with the active span
2715
+ * @returns The return value of the provided function
2716
+ */
2717
+ startActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, options: LangWatchSpanOptions, fn: F): ReturnType<F>;
2718
+ /**
2719
+ * Starts a new active LangWatchSpan with options and context, then executes the function.
2720
+ *
2721
+ * @param name - The name of the span
2722
+ * @param options - Span configuration options
2723
+ * @param context - Context to use for extracting parent span information
2724
+ * @param fn - Function to execute with the active span
2725
+ * @returns The return value of the provided function
2726
+ */
2727
+ startActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, options: LangWatchSpanOptions, context: Context, fn: F): ReturnType<F>;
2728
+ /**
2729
+ * **LangWatch Enhancement**: Creates and manages a span with **automatic lifecycle and error handling**.
2730
+ *
2731
+ * 🚀 **Automatic span management, batteries included**:
2732
+ * - ✅ **Span automatically ends** when your function completes (success or failure)
2733
+ * - ✅ **Errors automatically handled** - exceptions are caught, recorded, and span marked as ERROR
2734
+ * - ✅ **No need to call `span.end()`** - completely managed for you
2735
+ * - ✅ **No try/catch needed** - error recording is automatic
2736
+ *
2737
+ * **Key differences from OpenTelemetry's startActiveSpan**:
2738
+ * - Automatically ends the span when the function completes
2739
+ * - Automatically sets span status to ERROR and records exceptions on thrown errors
2740
+ * - Handles both synchronous and asynchronous functions seamlessly
2741
+ * - Provides a safer, more convenient API for span management
2742
+ *
2743
+ * **Perfect for**: Operations where you want zero boilerplate span management.
2744
+ * Just focus on your business logic - span lifecycle is handled automatically.
2745
+ *
2746
+ * @param name - The name of the span
2747
+ * @param fn - Function to execute with the managed span (can be sync or async)
2748
+ * @returns A promise that resolves to the return value of the provided function
2749
+ *
2750
+ * @example ✅ Clean code - NO manual span management needed
2751
+ * ```typescript
2752
+ * // ✅ AUTOMATIC span ending and error handling
2753
+ * const result = await tracer.withActiveSpan('risky-operation', async (span) => {
2754
+ * span.setAttributes({ operation: 'data-processing' });
2755
+ *
2756
+ * if (Math.random() > 0.5) {
2757
+ * throw new Error('Random failure'); // ✅ Automatically recorded, span marked as ERROR
2758
+ * }
2759
+ *
2760
+ * return 'success';
2761
+ * // ✅ NO span.end() needed - automatically handled!
2762
+ * // ✅ NO try/catch needed - errors automatically recorded!
2763
+ * });
2764
+ * ```
2765
+ *
2766
+ * @example ❌ vs ✅ Compare with manual span management
2767
+ * ```typescript
2768
+ * // ❌ Manual span management (what you DON'T need to do)
2769
+ * const span = tracer.startSpan('operation');
2770
+ * try {
2771
+ * span.setAttributes({ key: 'value' });
2772
+ * const result = await doWork();
2773
+ * span.setStatus({ code: SpanStatusCode.OK });
2774
+ * return result;
2775
+ * } catch (error) {
2776
+ * span.setStatus({ code: SpanStatusCode.ERROR, message: error.message });
2777
+ * span.recordException(error);
2778
+ * throw error;
2779
+ * } finally {
2780
+ * span.end(); // Must remember to end!
2781
+ * }
2782
+ *
2783
+ * // ✅ With withActiveSpan (clean and automatic)
2784
+ * const result = await tracer.withActiveSpan('operation', async (span) => {
2785
+ * span.setAttributes({ key: 'value' });
2786
+ * return await doWork(); // That's it! Everything else is automatic
2787
+ * });
2788
+ * ```
2789
+ *
2790
+ * @example ✅ Synchronous operations (no async/await needed)
2791
+ * ```typescript
2792
+ * const result = await tracer.withActiveSpan('sync-calc', (span) => {
2793
+ * span.setAttributes({ calculation: 'fibonacci' });
2794
+ * return fibonacci(10); // ✅ Synchronous function - span ends automatically
2795
+ * });
2796
+ *
2797
+ * // ✅ Even with operations that might throw
2798
+ * const data = await tracer.withActiveSpan('read-config', (span) => {
2799
+ * span.setAttributes({ file: 'config.json' });
2800
+ * return JSON.parse(fs.readFileSync('config.json', 'utf8')); // ✅ Errors auto-handled
2801
+ * });
2802
+ * ```
2803
+ */
2804
+ withActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, fn: F): ReturnType<F>;
2805
+ /**
2806
+ * Creates and manages a span with options and automatic lifecycle management.
2807
+ *
2808
+ * @param name - The name of the span
2809
+ * @param options - Span configuration options
2810
+ * @param fn - Function to execute with the managed span (can be sync or async)
2811
+ * @returns A promise that resolves to the return value of the provided function
2812
+ */
2813
+ withActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, options: LangWatchSpanOptions, fn: F): ReturnType<F>;
2814
+ /**
2815
+ * Creates and manages a span with options, context, and automatic lifecycle management.
2816
+ *
2817
+ * @param name - The name of the span
2818
+ * @param options - Span configuration options
2819
+ * @param context - Context to use for extracting parent span information
2820
+ * @param fn - Function to execute with the managed span (can be sync or async)
2821
+ * @returns A promise that resolves to the return value of the provided function
2822
+ */
2823
+ withActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, options: LangWatchSpanOptions, context: Context, fn: F): ReturnType<F>;
2824
+ }
2825
+
2826
+ export { type ChatMessage as C, type InputOutputType as I, type JsonSerializable as J, type LangWatchSpan as L, type PromptResponse as P, type SpanType as S, type LangWatchTracer as a, type LangWatchSpanMetrics as b, type LangWatchSpanRAGContext as c, type LangWatchSpanOptions as d, type SimpleChatMessage as e, INPUT_OUTPUT_TYPES as f, Prompt as g, type paths as p, spanTypes as s };