langwatch 0.3.2 → 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 (202) hide show
  1. package/dist/{add-LBBS4I3H.js → add-35QACTIV.js} +34 -28
  2. package/dist/add-35QACTIV.js.map +1 -0
  3. package/dist/{add-RD3ZKFAT.mjs → add-TRJAXM4D.mjs} +22 -16
  4. package/dist/add-TRJAXM4D.mjs.map +1 -0
  5. package/dist/chunk-4ZSSHX6F.js +636 -0
  6. package/dist/chunk-4ZSSHX6F.js.map +1 -0
  7. package/dist/chunk-5EVBOHJY.js +155 -0
  8. package/dist/chunk-5EVBOHJY.js.map +1 -0
  9. package/dist/{chunk-YN4436PK.mjs → chunk-CU3443HD.mjs} +14 -9
  10. package/dist/{chunk-2JU376G7.js → chunk-D2CSG4SJ.js} +4 -4
  11. package/dist/chunk-D2CSG4SJ.js.map +1 -0
  12. package/dist/chunk-DISMHYXC.js +184 -0
  13. package/dist/chunk-DISMHYXC.js.map +1 -0
  14. package/dist/{chunk-E7UE2MPD.mjs → chunk-ECUXLXFT.mjs} +2 -2
  15. package/dist/chunk-EJWJXTPU.mjs +626 -0
  16. package/dist/chunk-EJWJXTPU.mjs.map +1 -0
  17. package/dist/chunk-GQMDZ4GY.mjs +155 -0
  18. package/dist/chunk-GQMDZ4GY.mjs.map +1 -0
  19. package/dist/{chunk-3GKPQB4R.mjs → chunk-HUI45ULC.mjs} +4 -4
  20. package/dist/chunk-HUI45ULC.mjs.map +1 -0
  21. package/dist/{chunk-HJU67C7H.js → chunk-K64Y6YUG.js} +10 -10
  22. package/dist/{chunk-HJU67C7H.js.map → chunk-K64Y6YUG.js.map} +1 -1
  23. package/dist/chunk-LP76VXI3.mjs +636 -0
  24. package/dist/chunk-LP76VXI3.mjs.map +1 -0
  25. package/dist/chunk-M4VUHTT2.js +626 -0
  26. package/dist/chunk-M4VUHTT2.js.map +1 -0
  27. package/dist/{chunk-PR3JDWC3.mjs → chunk-N2V6J3U2.mjs} +28 -3
  28. package/dist/chunk-N2V6J3U2.mjs.map +1 -0
  29. package/dist/chunk-OUCVXP4G.js +258 -0
  30. package/dist/chunk-OUCVXP4G.js.map +1 -0
  31. package/dist/{chunk-FJLK5CFL.js → chunk-OXBO24RB.js} +13 -8
  32. package/dist/chunk-OXBO24RB.js.map +1 -0
  33. package/dist/chunk-PGWR3OQY.mjs +258 -0
  34. package/dist/chunk-PGWR3OQY.mjs.map +1 -0
  35. package/dist/{chunk-SMXXAVMB.js → chunk-SGNJDRCT.js} +2 -2
  36. package/dist/chunk-SGNJDRCT.js.map +1 -0
  37. package/dist/{chunk-W5ZEP3CI.mjs → chunk-SYMZPWZE.mjs} +2 -2
  38. package/dist/chunk-SYMZPWZE.mjs.map +1 -0
  39. package/dist/{chunk-KGDAENGD.js → chunk-YH5TIVK2.js} +28 -3
  40. package/dist/chunk-YH5TIVK2.js.map +1 -0
  41. package/dist/chunk-YNQ44U6D.mjs +184 -0
  42. package/dist/chunk-YNQ44U6D.mjs.map +1 -0
  43. package/dist/cli/index.js +8 -8
  44. package/dist/cli/index.mjs +8 -8
  45. package/dist/{create-G5MTGOOH.js → create-7K2CC4KQ.js} +11 -11
  46. package/dist/{create-G5MTGOOH.js.map → create-7K2CC4KQ.js.map} +1 -1
  47. package/dist/{create-QUZYBMQB.mjs → create-MK7NEGCM.mjs} +8 -8
  48. package/dist/implementation-C4lvooSg.d.mts +576 -0
  49. package/dist/implementation-CzemP9jY.d.ts +576 -0
  50. package/dist/index-DTEZr0Jn.d.mts +34 -0
  51. package/dist/index-DTEZr0Jn.d.ts +34 -0
  52. package/dist/index.d.mts +121 -47
  53. package/dist/index.d.ts +121 -47
  54. package/dist/index.js +16 -12
  55. package/dist/index.js.map +1 -1
  56. package/dist/index.mjs +27 -23
  57. package/dist/index.mjs.map +1 -1
  58. package/dist/init-GDKJICSS.js +16 -0
  59. package/dist/{init-XU2JFY6N.js.map → init-GDKJICSS.js.map} +1 -1
  60. package/dist/{init-H67RW22E.mjs → init-RINSTP4L.mjs} +5 -5
  61. package/dist/{list-7NPSX2E4.mjs → list-7L23G5DY.mjs} +28 -16
  62. package/dist/list-7L23G5DY.mjs.map +1 -0
  63. package/dist/{list-ZXFLAF52.js → list-OLLQ7XKZ.js} +29 -17
  64. package/dist/list-OLLQ7XKZ.js.map +1 -0
  65. package/dist/{login-EK4WVOI2.mjs → login-RCNKL5AM.mjs} +6 -5
  66. package/dist/login-RCNKL5AM.mjs.map +1 -0
  67. package/dist/{login-76NQIHKR.js → login-XF3BQQPV.js} +7 -6
  68. package/dist/login-XF3BQQPV.js.map +1 -0
  69. package/dist/observability-sdk/index.d.mts +134 -0
  70. package/dist/observability-sdk/index.d.ts +134 -0
  71. package/dist/observability-sdk/index.js +41 -0
  72. package/dist/observability-sdk/index.js.map +1 -0
  73. package/dist/observability-sdk/index.mjs +41 -0
  74. package/dist/observability-sdk/instrumentation/langchain/index.d.mts +69 -0
  75. package/dist/observability-sdk/instrumentation/langchain/index.d.ts +69 -0
  76. package/dist/observability-sdk/instrumentation/langchain/index.js +518 -0
  77. package/dist/observability-sdk/instrumentation/langchain/index.js.map +1 -0
  78. package/dist/observability-sdk/instrumentation/langchain/index.mjs +518 -0
  79. package/dist/observability-sdk/instrumentation/langchain/index.mjs.map +1 -0
  80. package/dist/observability-sdk/setup/node/index.d.mts +368 -0
  81. package/dist/observability-sdk/setup/node/index.d.ts +368 -0
  82. package/dist/observability-sdk/setup/node/index.js +276 -0
  83. package/dist/observability-sdk/setup/node/index.js.map +1 -0
  84. package/dist/observability-sdk/setup/node/index.mjs +276 -0
  85. package/dist/observability-sdk/setup/node/index.mjs.map +1 -0
  86. package/dist/{remove-SDJYEPAY.mjs → remove-3VLQNVHN.mjs} +11 -8
  87. package/dist/remove-3VLQNVHN.mjs.map +1 -0
  88. package/dist/{remove-XBNGIVMR.js → remove-L6JVJBWY.js} +18 -15
  89. package/dist/remove-L6JVJBWY.js.map +1 -0
  90. package/dist/{sync-ST2IWXSB.mjs → sync-DPMTUTVL.mjs} +39 -33
  91. package/dist/sync-DPMTUTVL.mjs.map +1 -0
  92. package/dist/{sync-EISKGPTL.js → sync-PSU3F5Z4.js} +52 -46
  93. package/dist/sync-PSU3F5Z4.js.map +1 -0
  94. package/dist/{prompt-D-jpMrLS.d.mts → types-1q5wIYP5.d.mts} +628 -14
  95. package/dist/{prompt-D-jpMrLS.d.ts → types-C9k5gGhU.d.ts} +628 -14
  96. package/dist/types-DRiQaKFG.d.mts +254 -0
  97. package/dist/types-DRiQaKFG.d.ts +254 -0
  98. package/dist/types-Dmazk5Bk.d.mts +44 -0
  99. package/dist/types-Dmazk5Bk.d.ts +44 -0
  100. package/package.json +39 -39
  101. package/dist/add-LBBS4I3H.js.map +0 -1
  102. package/dist/add-RD3ZKFAT.mjs.map +0 -1
  103. package/dist/chunk-2JU376G7.js.map +0 -1
  104. package/dist/chunk-2ODBGSBI.js +0 -4
  105. package/dist/chunk-2ODBGSBI.js.map +0 -1
  106. package/dist/chunk-3GKPQB4R.mjs.map +0 -1
  107. package/dist/chunk-52GXX3MA.js +0 -426
  108. package/dist/chunk-52GXX3MA.js.map +0 -1
  109. package/dist/chunk-5NC5ILKA.js +0 -94
  110. package/dist/chunk-5NC5ILKA.js.map +0 -1
  111. package/dist/chunk-AAROJADR.mjs +0 -49
  112. package/dist/chunk-AAROJADR.mjs.map +0 -1
  113. package/dist/chunk-DTEKFQ4U.js +0 -159
  114. package/dist/chunk-DTEKFQ4U.js.map +0 -1
  115. package/dist/chunk-F63YKTXA.mjs +0 -47
  116. package/dist/chunk-F63YKTXA.mjs.map +0 -1
  117. package/dist/chunk-FJLK5CFL.js.map +0 -1
  118. package/dist/chunk-GJSEBQXF.mjs +0 -392
  119. package/dist/chunk-GJSEBQXF.mjs.map +0 -1
  120. package/dist/chunk-IGHXIIIK.js +0 -49
  121. package/dist/chunk-IGHXIIIK.js.map +0 -1
  122. package/dist/chunk-J7ICRUU4.mjs +0 -426
  123. package/dist/chunk-J7ICRUU4.mjs.map +0 -1
  124. package/dist/chunk-KGDAENGD.js.map +0 -1
  125. package/dist/chunk-LD74LVRU.js +0 -47
  126. package/dist/chunk-LD74LVRU.js.map +0 -1
  127. package/dist/chunk-PCQVQ7SB.js +0 -45
  128. package/dist/chunk-PCQVQ7SB.js.map +0 -1
  129. package/dist/chunk-PR3JDWC3.mjs.map +0 -1
  130. package/dist/chunk-PWZBLTHR.js +0 -118
  131. package/dist/chunk-PWZBLTHR.js.map +0 -1
  132. package/dist/chunk-QEWDG5QE.mjs +0 -45
  133. package/dist/chunk-QEWDG5QE.mjs.map +0 -1
  134. package/dist/chunk-SMXXAVMB.js.map +0 -1
  135. package/dist/chunk-STV4ZVNA.mjs +0 -118
  136. package/dist/chunk-STV4ZVNA.mjs.map +0 -1
  137. package/dist/chunk-T5AZMMVS.mjs +0 -94
  138. package/dist/chunk-T5AZMMVS.mjs.map +0 -1
  139. package/dist/chunk-UU33HCCZ.mjs +0 -159
  140. package/dist/chunk-UU33HCCZ.mjs.map +0 -1
  141. package/dist/chunk-VGHLQXKB.js +0 -392
  142. package/dist/chunk-VGHLQXKB.js.map +0 -1
  143. package/dist/chunk-W5ZEP3CI.mjs.map +0 -1
  144. package/dist/chunk-Y666BJA5.mjs +0 -4
  145. package/dist/chunk-YN4436PK.mjs.map +0 -1
  146. package/dist/client-B2HqIKg6.d.ts +0 -51
  147. package/dist/client-XyCqclCi.d.mts +0 -51
  148. package/dist/client-browser.d.mts +0 -8
  149. package/dist/client-browser.d.ts +0 -8
  150. package/dist/client-browser.js +0 -88
  151. package/dist/client-browser.js.map +0 -1
  152. package/dist/client-browser.mjs +0 -88
  153. package/dist/client-browser.mjs.map +0 -1
  154. package/dist/client-node.d.mts +0 -8
  155. package/dist/client-node.d.ts +0 -8
  156. package/dist/client-node.js +0 -95
  157. package/dist/client-node.js.map +0 -1
  158. package/dist/client-node.mjs +0 -95
  159. package/dist/client-node.mjs.map +0 -1
  160. package/dist/evaluation/index.d.mts +0 -897
  161. package/dist/evaluation/index.d.ts +0 -897
  162. package/dist/evaluation/index.js +0 -14
  163. package/dist/evaluation/index.js.map +0 -1
  164. package/dist/evaluation/index.mjs +0 -14
  165. package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +0 -64
  166. package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +0 -64
  167. package/dist/init-XU2JFY6N.js +0 -16
  168. package/dist/list-7NPSX2E4.mjs.map +0 -1
  169. package/dist/list-ZXFLAF52.js.map +0 -1
  170. package/dist/login-76NQIHKR.js.map +0 -1
  171. package/dist/login-EK4WVOI2.mjs.map +0 -1
  172. package/dist/observability/index.d.mts +0 -260
  173. package/dist/observability/index.d.ts +0 -260
  174. package/dist/observability/index.js +0 -21
  175. package/dist/observability/index.js.map +0 -1
  176. package/dist/observability/index.mjs +0 -21
  177. package/dist/observability/index.mjs.map +0 -1
  178. package/dist/observability/instrumentation/langchain/index.d.mts +0 -40
  179. package/dist/observability/instrumentation/langchain/index.d.ts +0 -40
  180. package/dist/observability/instrumentation/langchain/index.js +0 -668
  181. package/dist/observability/instrumentation/langchain/index.js.map +0 -1
  182. package/dist/observability/instrumentation/langchain/index.mjs +0 -668
  183. package/dist/observability/instrumentation/langchain/index.mjs.map +0 -1
  184. package/dist/prompt/index.d.mts +0 -10
  185. package/dist/prompt/index.d.ts +0 -10
  186. package/dist/prompt/index.js +0 -22
  187. package/dist/prompt/index.js.map +0 -1
  188. package/dist/prompt/index.mjs +0 -22
  189. package/dist/prompt/index.mjs.map +0 -1
  190. package/dist/record-evaluation-CmxMXa-3.d.mts +0 -25
  191. package/dist/record-evaluation-CmxMXa-3.d.ts +0 -25
  192. package/dist/remove-SDJYEPAY.mjs.map +0 -1
  193. package/dist/remove-XBNGIVMR.js.map +0 -1
  194. package/dist/sync-EISKGPTL.js.map +0 -1
  195. package/dist/sync-ST2IWXSB.mjs.map +0 -1
  196. package/dist/trace-CqaKo0kZ.d.ts +0 -622
  197. package/dist/trace-DtVc5GhF.d.mts +0 -622
  198. /package/dist/{chunk-Y666BJA5.mjs.map → chunk-CU3443HD.mjs.map} +0 -0
  199. /package/dist/{chunk-E7UE2MPD.mjs.map → chunk-ECUXLXFT.mjs.map} +0 -0
  200. /package/dist/{create-QUZYBMQB.mjs.map → create-MK7NEGCM.mjs.map} +0 -0
  201. /package/dist/{init-H67RW22E.mjs.map → init-RINSTP4L.mjs.map} +0 -0
  202. /package/dist/{evaluation → observability-sdk}/index.mjs.map +0 -0
@@ -1,622 +0,0 @@
1
- import { Span, Attributes, AttributeValue, Tracer, SpanOptions, Context } from '@opentelemetry/api';
2
- import { R as RecordedEvaluationDetails } from './record-evaluation-CmxMXa-3.mjs';
3
- import { P as Prompt } from './prompt-D-jpMrLS.mjs';
4
-
5
- /**
6
- * Anthropic AI system identifier
7
- * Used to identify Anthropic's Claude models
8
- */
9
- declare const VAL_GEN_AI_SYSTEM_ANTHROPIC = "anthropic";
10
- /**
11
- * AWS Bedrock system identifier
12
- * Used to identify AWS Bedrock AI services
13
- */
14
- declare const VAL_GEN_AI_SYSTEM_AWS_BEDROCK = "aws.bedrock";
15
- /**
16
- * Azure AI Inference system identifier
17
- * Used to identify Azure AI Inference services
18
- */
19
- declare const VAL_GEN_AI_SYSTEM_AZURE_AI_INFERENCE = "azure.ai.inference";
20
- /**
21
- * Azure AI OpenAI system identifier
22
- * Used to identify Azure OpenAI services
23
- */
24
- declare const VAL_GEN_AI_SYSTEM_AZURE_AI_OPENAI = "azure.ai.openai";
25
- /**
26
- * Cohere system identifier
27
- * Used to identify Cohere AI models
28
- */
29
- declare const VAL_GEN_AI_SYSTEM_COHERE = "cohere";
30
- /**
31
- * DeepSeek system identifier
32
- * Used to identify DeepSeek AI models
33
- */
34
- declare const VAL_GEN_AI_SYSTEM_DEEPSEEK = "deepseek";
35
- /**
36
- * GCP Gemini system identifier
37
- * Used to identify Google Cloud Gemini models
38
- */
39
- declare const VAL_GEN_AI_SYSTEM_GCP_GEMINI = "gcp.gemini";
40
- /**
41
- * GCP Gen AI system identifier
42
- * Used to identify Google Cloud Generative AI services
43
- */
44
- declare const VAL_GEN_AI_SYSTEM_GCP_GEN_AI = "gcp.gen_ai";
45
- /**
46
- * GCP Vertex AI system identifier
47
- * Used to identify Google Cloud Vertex AI services
48
- */
49
- declare const VAL_GEN_AI_SYSTEM_GCP_VERTEX_AI = "gcp.vertex_ai";
50
- /**
51
- * Groq system identifier
52
- * Used to identify Groq AI models
53
- */
54
- declare const VAL_GEN_AI_SYSTEM_GROQ = "groq";
55
- /**
56
- * IBM WatsonX AI system identifier
57
- * Used to identify IBM WatsonX AI services
58
- */
59
- declare const VAL_GEN_AI_SYSTEM_IBM_WATSONX_AI = "ibm.watsonx.ai";
60
- /**
61
- * Mistral AI system identifier
62
- * Used to identify Mistral AI models
63
- */
64
- declare const VAL_GEN_AI_SYSTEM_MISTRAL_AI = "mistral_ai";
65
- /**
66
- * OpenAI system identifier
67
- * Used to identify OpenAI models and services
68
- */
69
- declare const VAL_GEN_AI_SYSTEM_OPENAI = "openai";
70
- /**
71
- * Perplexity system identifier
72
- * Used to identify Perplexity AI models
73
- */
74
- declare const VAL_GEN_AI_SYSTEM_PERPLEXITY = "perplexity";
75
- /**
76
- * XAI system identifier
77
- * Used to identify XAI models and services
78
- */
79
- declare const VAL_GEN_AI_SYSTEM_XAI = "xai";
80
- /**
81
- * Content filter finish reason
82
- * Used when generation stops due to content filtering
83
- */
84
- declare const VAL_GEN_AI_FINISH_REASON_CONTENT_FILTER = "content_filter";
85
- /**
86
- * Error finish reason
87
- * Used when generation stops due to an error
88
- */
89
- declare const VAL_GEN_AI_FINISH_REASON_ERROR = "error";
90
- /**
91
- * Length finish reason
92
- * Used when generation stops due to length limits
93
- */
94
- declare const VAL_GEN_AI_FINISH_REASON_LENGTH = "length";
95
- /**
96
- * Stop finish reason
97
- * Used when generation stops due to stop tokens
98
- */
99
- declare const VAL_GEN_AI_FINISH_REASON_STOP = "stop";
100
- /**
101
- * Tool calls finish reason
102
- * Used when generation stops due to tool calls
103
- */
104
- declare const VAL_GEN_AI_FINISH_REASON_TOOL_CALLS = "tool_calls";
105
- /**
106
- * Union type of all supported GenAI system identifiers
107
- * Used for type safety when working with system identification
108
- */
109
- type VAL_GEN_AI_SYSTEMS = typeof VAL_GEN_AI_SYSTEM_ANTHROPIC | typeof VAL_GEN_AI_SYSTEM_AWS_BEDROCK | typeof VAL_GEN_AI_SYSTEM_AZURE_AI_INFERENCE | typeof VAL_GEN_AI_SYSTEM_AZURE_AI_OPENAI | typeof VAL_GEN_AI_SYSTEM_COHERE | typeof VAL_GEN_AI_SYSTEM_DEEPSEEK | typeof VAL_GEN_AI_SYSTEM_GCP_GEMINI | typeof VAL_GEN_AI_SYSTEM_GCP_GEN_AI | typeof VAL_GEN_AI_SYSTEM_GCP_VERTEX_AI | typeof VAL_GEN_AI_SYSTEM_GROQ | typeof VAL_GEN_AI_SYSTEM_IBM_WATSONX_AI | typeof VAL_GEN_AI_SYSTEM_MISTRAL_AI | typeof VAL_GEN_AI_SYSTEM_OPENAI | typeof VAL_GEN_AI_SYSTEM_PERPLEXITY | typeof VAL_GEN_AI_SYSTEM_XAI;
110
- /**
111
- * Union type of all supported GenAI finish reasons
112
- * Used for type safety when working with generation completion reasons
113
- */
114
- type VAL_GEN_AI_FINISH_REASONS = typeof VAL_GEN_AI_FINISH_REASON_CONTENT_FILTER | typeof VAL_GEN_AI_FINISH_REASON_ERROR | typeof VAL_GEN_AI_FINISH_REASON_LENGTH | typeof VAL_GEN_AI_FINISH_REASON_STOP | typeof VAL_GEN_AI_FINISH_REASON_TOOL_CALLS;
115
-
116
- interface EvaluationResultModel {
117
- status: "processed" | "skipped" | "error";
118
- passed?: boolean;
119
- score?: number;
120
- details?: string;
121
- label?: string;
122
- cost?: {
123
- currency: string;
124
- amount: number;
125
- };
126
- }
127
-
128
- /**
129
- * Supported types of spans for LangWatch observability. These types categorize the nature of the span for downstream analysis and visualization.
130
- *
131
- * @example
132
- * import { spanTypes, SpanType } from './span';
133
- * const myType: SpanType = 'llm';
134
- */
135
- declare const spanTypes: readonly ["span", "llm", "chain", "tool", "agent", "guardrail", "evaluation", "rag", "prompt", "workflow", "component", "module", "server", "client", "producer", "consumer", "task", "unknown"];
136
- type SpanType = (typeof spanTypes)[number];
137
- /**
138
- * Context for a RAG (Retrieval-Augmented Generation) span.
139
- *
140
- * This structure is used to record which document and chunk were retrieved and used as context for a generation.
141
- *
142
- * @property document_id - Unique identifier for the source document.
143
- * @property chunk_id - Unique identifier for the chunk within the document.
144
- * @property content - The actual content of the chunk provided to the model.
145
- *
146
- * @example
147
- * const ragContext: LangWatchSpanRAGContext = {
148
- * document_id: 'doc-123',
149
- * chunk_id: 'chunk-456',
150
- * content: 'Relevant passage from the document.'
151
- * };
152
- */
153
- interface LangWatchSpanRAGContext {
154
- document_id: string;
155
- chunk_id: string;
156
- content: string;
157
- }
158
- /**
159
- * Metrics for a LangWatch span.
160
- *
161
- * @property promptTokens - The number of prompt tokens used.
162
- * @property completionTokens - The number of completion tokens used.
163
- * @property cost - The cost of the span.
164
- */
165
- interface LangWatchSpanMetrics {
166
- /** The number of prompt tokens used */
167
- promptTokens?: number;
168
- /** The number of completion tokens used */
169
- completionTokens?: number;
170
- /** The cost of the span */
171
- cost?: number;
172
- }
173
- /**
174
- * Body for a system message event in a GenAI span.
175
- *
176
- * Used to log system/instruction messages sent to the model.
177
- *
178
- * @property content - The message content.
179
- * @property role - The role of the message, typically 'system' or 'instruction'.
180
- *
181
- * @example
182
- * span.addGenAISystemMessageEvent({ content: 'You are a helpful assistant.' });
183
- */
184
- interface LangWatchSpanGenAISystemMessageEventBody {
185
- /** Content of the system message */
186
- content?: string;
187
- /** Role of the message (system or instruction) */
188
- role?: "system" | "instruction";
189
- }
190
- /**
191
- * Body for a user message event in a GenAI span.
192
- *
193
- * Used to log user/customer messages sent to the model.
194
- *
195
- * @property content - The message content.
196
- * @property role - The role of the message, typically 'user' or 'customer'.
197
- *
198
- * @example
199
- * span.addGenAIUserMessageEvent({ content: 'What is the weather today?' });
200
- */
201
- interface LangWatchSpanGenAIUserMessageEventBody {
202
- /** Content of the user message */
203
- content?: string;
204
- /** Role of the message (user or customer) */
205
- role?: "user" | "customer";
206
- }
207
- /**
208
- * Body for an assistant message event in a GenAI span.
209
- *
210
- * Used to log assistant/bot responses, including tool calls.
211
- *
212
- * @property content - The message content.
213
- * @property role - The role of the message, typically 'assistant' or 'bot'.
214
- * @property tool_calls - Array of tool call objects, if the assistant invoked tools/functions.
215
- *
216
- * @example
217
- * span.addGenAIAssistantMessageEvent({ content: 'The weather is sunny.', role: 'assistant' });
218
- */
219
- interface LangWatchSpanGenAIAssistantMessageEventBody {
220
- /** Content of the assistant message */
221
- content?: string;
222
- /** Role of the message (assistant or bot) */
223
- role?: "assistant" | "bot";
224
- /** Tool calls made by the assistant */
225
- tool_calls?: {
226
- function: {
227
- /** Name of the function called */
228
- name: string;
229
- /** Arguments passed to the function */
230
- arguments?: string;
231
- };
232
- /** Tool call identifier */
233
- id: string;
234
- /** Type of tool call */
235
- type: "function";
236
- }[];
237
- }
238
- /**
239
- * Body for a tool message event in a GenAI span.
240
- *
241
- * Used to log messages from tools/functions invoked by the assistant.
242
- *
243
- * @property content - The message content.
244
- * @property id - Unique identifier for the tool call.
245
- * @property role - The role, typically 'tool' or 'function'.
246
- *
247
- * @example
248
- * span.addGenAIToolMessageEvent({ content: 'Result from tool', id: 'tool-1', role: 'tool' });
249
- */
250
- interface LangWatchSpanGenAIToolMessageEventBody {
251
- /** Content of the tool message */
252
- content?: string;
253
- /** Tool call identifier */
254
- id: string;
255
- /** Role of the message (tool or function) */
256
- role?: "tool" | "function";
257
- }
258
- /**
259
- * Body for a choice event in a GenAI span.
260
- *
261
- * Used to log the model's output choices, including finish reason and message content.
262
- *
263
- * @property finish_reason - Why the generation finished (e.g., 'stop', 'length').
264
- * @property index - Index of the choice (for multi-choice outputs).
265
- * @property message - The message content and tool calls for this choice.
266
- *
267
- * @example
268
- * span.addGenAIChoiceEvent({ finish_reason: 'stop', index: 0, message: { content: 'Hello!' } });
269
- */
270
- interface LangWatchSpanGenAIChoiceEventBody {
271
- /** Reason the generation finished */
272
- finish_reason: VAL_GEN_AI_FINISH_REASONS | (string & {});
273
- /** Index of the choice */
274
- index: number;
275
- /** Message content for the choice */
276
- message?: {
277
- /** Content of the message */
278
- content?: string;
279
- /** Role of the message (assistant or bot) */
280
- role?: "assistant" | "bot";
281
- /** Tool calls made by the assistant */
282
- tool_calls?: {
283
- function: {
284
- /** Name of the function called */
285
- name: string;
286
- /** Arguments passed to the function */
287
- arguments?: string;
288
- };
289
- /** Tool call identifier */
290
- id: string;
291
- /** Type of tool call */
292
- type: "function";
293
- }[];
294
- };
295
- }
296
- /**
297
- * Extension of OpenTelemetry's Span with LangWatch-specific helpers for LLM, RAG, and GenAI tracing.
298
- *
299
- * This interface provides ergonomic methods for recording structured LLM/GenAI data, such as inputs, outputs, RAG contexts, and message events.
300
- *
301
- * All methods return `this` for chaining.
302
- *
303
- * @example
304
- * const span = createLangWatchSpan(otelSpan);
305
- * span
306
- * .setType('llm')
307
- * .setInput({ prompt: 'Hello' })
308
- * .setOutput('Hi!')
309
- * .addGenAIUserMessageEvent({ content: 'Hello' })
310
- * .addGenAIAssistantMessageEvent({ content: 'Hi!' });
311
- */
312
- interface LangWatchSpan extends Span {
313
- /**
314
- * Record the evaluation result for the span.
315
- *
316
- * @param details - The evaluation details
317
- * @param attributes - Additional attributes to add to the evaluation span.
318
- * @returns this
319
- */
320
- recordEvaluation(details: RecordedEvaluationDetails, attributes?: Attributes): this;
321
- /**
322
- * Add a GenAI system message event to the span.
323
- *
324
- * This logs a system/instruction message sent to the model.
325
- *
326
- * @param body - The event body (content and role)
327
- * @param system - The GenAI system (optional, e.g., 'openai', 'anthropic')
328
- * @param attributes - Additional OpenTelemetry attributes (optional)
329
- * @returns this
330
- */
331
- addGenAISystemMessageEvent(body: LangWatchSpanGenAISystemMessageEventBody, system?: VAL_GEN_AI_SYSTEMS | (string & {}), attributes?: Record<string, AttributeValue>): this;
332
- /**
333
- * Add a GenAI user message event to the span.
334
- *
335
- * This logs a user/customer message sent to the model.
336
- *
337
- * @param body - The event body (content and role)
338
- * @param system - The GenAI system (optional)
339
- * @param attributes - Additional OpenTelemetry attributes (optional)
340
- * @returns this
341
- */
342
- addGenAIUserMessageEvent(body: LangWatchSpanGenAIUserMessageEventBody, system?: VAL_GEN_AI_SYSTEMS | (string & {}), attributes?: Record<string, AttributeValue>): this;
343
- /**
344
- * Add a GenAI assistant message event to the span.
345
- *
346
- * This logs an assistant/bot response, including tool calls if present.
347
- *
348
- * @param body - The event body (content, role, tool_calls)
349
- * @param system - The GenAI system (optional)
350
- * @param attributes - Additional OpenTelemetry attributes (optional)
351
- * @returns this
352
- */
353
- addGenAIAssistantMessageEvent(body: LangWatchSpanGenAIAssistantMessageEventBody, system?: VAL_GEN_AI_SYSTEMS | (string & {}), attributes?: Record<string, AttributeValue>): this;
354
- /**
355
- * Add a GenAI tool message event to the span.
356
- *
357
- * This logs a message from a tool/function invoked by the assistant.
358
- *
359
- * @param body - The event body (content, id, role)
360
- * @param system - The GenAI system (optional)
361
- * @param attributes - Additional OpenTelemetry attributes (optional)
362
- * @returns this
363
- */
364
- addGenAIToolMessageEvent(body: LangWatchSpanGenAIToolMessageEventBody, system?: VAL_GEN_AI_SYSTEMS | (string & {}), attributes?: Record<string, AttributeValue>): this;
365
- /**
366
- * Add a GenAI choice event to the span.
367
- *
368
- * This logs a model output choice, including finish reason and message content.
369
- *
370
- * @param body - The event body (finish_reason, index, message)
371
- * @param system - The GenAI system (optional)
372
- * @param attributes - Additional OpenTelemetry attributes (optional)
373
- * @returns this
374
- */
375
- addGenAIChoiceEvent(body: LangWatchSpanGenAIChoiceEventBody, system?: VAL_GEN_AI_SYSTEMS | (string & {}), attributes?: Record<string, AttributeValue>): this;
376
- /**
377
- * Set the type of the span (e.g., 'llm', 'rag', 'tool', etc).
378
- *
379
- * This is used for downstream filtering and analytics.
380
- *
381
- * @param type - The span type (see SpanType)
382
- * @returns this
383
- */
384
- setType(type: SpanType): this;
385
- /**
386
- * Set the request model name for the span.
387
- *
388
- * This is typically the model name sent in the API request (e.g., 'gpt-4', 'claude-3').
389
- *
390
- * @param model - The request model name
391
- * @returns this
392
- */
393
- setRequestModel(model: string): this;
394
- /**
395
- * Set the response model name for the span.
396
- *
397
- * This is the model name returned in the API response, if different from the request.
398
- *
399
- * @param model - The response model name
400
- * @returns this
401
- */
402
- setResponseModel(model: string): this;
403
- /**
404
- * Set multiple RAG contexts for the span.
405
- *
406
- * Use this to record all retrieved documents/chunks used as context for a generation.
407
- *
408
- * @param ragContexts - Array of RAG context objects
409
- * @returns this
410
- */
411
- setRAGContexts(ragContexts: LangWatchSpanRAGContext[]): this;
412
- /**
413
- * Set a single RAG context for the span.
414
- *
415
- * Use this if only one context was retrieved.
416
- *
417
- * @param ragContext - The RAG context object
418
- * @returns this
419
- */
420
- setRAGContext(ragContext: LangWatchSpanRAGContext): this;
421
- /**
422
- * Set the metrics for the span.
423
- *
424
- * @param metrics - The metrics object
425
- * @returns this
426
- */
427
- setMetrics(metrics: LangWatchSpanMetrics): this;
428
- /**
429
- * Set the selected prompt for the span. This will attach this prompt to the trace. If
430
- * this is set on multiple spans, the last one will be used.
431
- *
432
- * @param prompt - The prompt object
433
- * @returns this
434
- */
435
- setSelectedPrompt(prompt: Prompt): this;
436
- /**
437
- * Record the input to the span as a JSON-serializable value.
438
- *
439
- * The input is stringified and stored as a span attribute for later analysis.
440
- *
441
- * @param input - The input value (any type, will be JSON.stringified)
442
- * @returns this
443
- */
444
- setInput(input: unknown): this;
445
- /**
446
- * Record the input to the span as a plain string.
447
- *
448
- * Use this for raw text prompts or queries.
449
- *
450
- * @param input - The input string
451
- * @returns this
452
- */
453
- setInputString(input: string): this;
454
- /**
455
- * Record the output from the span as a JSON-serializable value.
456
- *
457
- * The output is stringified and stored as a span attribute for later analysis.
458
- *
459
- * @param output - The output value (any type, will be JSON.stringified)
460
- * @returns this
461
- */
462
- setOutput(output: unknown): this;
463
- /**
464
- * Record the output from the span as a plain string.
465
- *
466
- * Use this for raw text completions or responses.
467
- *
468
- * @param output - The output string
469
- * @returns this
470
- */
471
- setOutputString(output: string): this;
472
- /**
473
- * Set the evaluation output for the span.
474
- *
475
- * @param guardrail - Whether the evaluation is a guardrail
476
- * @param output - The evaluation result
477
- * @returns this
478
- */
479
- setOutputEvaluation(guardrail: boolean, output: EvaluationResultModel): this;
480
- }
481
- /**
482
- * Creates a LangWatchSpan wrapper around an OpenTelemetry Span.
483
- *
484
- * @param span - The OpenTelemetry Span to wrap
485
- * @returns A LangWatchSpan with additional methods for LLM/GenAI observability
486
- *
487
- * @example
488
- * import { createLangWatchSpan } from './span';
489
- * const otelSpan = tracer.startSpan('llm-call');
490
- * const span = createLangWatchSpan(otelSpan);
491
- * span.setType('llm').setInput('Prompt').setOutput('Completion');
492
- */
493
- declare function createLangWatchSpan(span: Span): LangWatchSpan;
494
-
495
- /**
496
- * LangWatch OpenTelemetry Tracing Extensions
497
- *
498
- * This module provides wrappers and helpers for OpenTelemetry Tracer and Span objects,
499
- * adding ergonomic methods for LLM/GenAI observability and structured tracing.
500
- *
501
- * @module trace
502
- */
503
- interface LangWatchTracer extends Tracer {
504
- /**
505
- * Starts a new {@link LangWatchSpan}. Start the span without setting it on context.
506
- *
507
- * This method does NOT modify the current Context.
508
- *
509
- * @param name The name of the span
510
- * @param [options] SpanOptions used for span creation
511
- * @param [context] Context to use to extract parent
512
- * @returns LangWatchSpan The newly created span
513
- *
514
- * @example
515
- * const span = tracer.startSpan('op');
516
- * span.setAttribute('key', 'value');
517
- * span.end();
518
- */
519
- startSpan(name: string, options?: SpanOptions, context?: Context): LangWatchSpan;
520
- /**
521
- * Starts a new {@link LangWatchSpan} and calls the given function passing it the
522
- * created span as first argument.
523
- * Additionally the new span gets set in context and this context is activated
524
- * for the duration of the function call.
525
- *
526
- * @param name The name of the span
527
- * @param [options] SpanOptions used for span creation
528
- * @param [context] Context to use to extract parent
529
- * @param fn function called in the context of the span and receives the newly created span as an argument
530
- * @returns return value of fn
531
- *
532
- * @example
533
- * const result = tracer.startActiveSpan('op', span => {
534
- * try {
535
- * // do some work
536
- * span.setStatus({code: SpanStatusCode.OK});
537
- * return something;
538
- * } catch (err) {
539
- * span.setStatus({
540
- * code: SpanStatusCode.ERROR,
541
- * message: err.message,
542
- * });
543
- * throw err;
544
- * } finally {
545
- * span.end();
546
- * }
547
- * });
548
- *
549
- * @example
550
- * const span = tracer.startActiveSpan('op', span => {
551
- * try {
552
- * do some work
553
- * return span;
554
- * } catch (err) {
555
- * span.setStatus({
556
- * code: SpanStatusCode.ERROR,
557
- * message: err.message,
558
- * });
559
- * throw err;
560
- * }
561
- * });
562
- * do some more work
563
- * span.end();
564
- */
565
- startActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, fn: F): ReturnType<F>;
566
- startActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, options: SpanOptions, fn: F): ReturnType<F>;
567
- startActiveSpan<F extends (span: LangWatchSpan) => unknown>(name: string, options: SpanOptions, context: Context, fn: F): ReturnType<F>;
568
- /**
569
- * Starts a new {@link LangWatchSpan}, runs the provided async function, and automatically handles
570
- * error recording, status setting, and span ending. This is a safer and more ergonomic alternative
571
- * to manually using try/catch/finally blocks with startActiveSpan.
572
- *
573
- * Overloads:
574
- * - withActiveSpan(name, fn)
575
- * - withActiveSpan(name, options, fn)
576
- * - withActiveSpan(name, options, context, fn)
577
- *
578
- * @param name The name of the span
579
- * @param options Optional SpanOptions for span creation
580
- * @param context Optional Context to use to extract parent
581
- * @param fn The async function to execute within the span context. Receives the span as its first argument.
582
- * @returns The return value of the provided function
583
- *
584
- * @example
585
- * await tracer.withActiveSpan('my-operation', async (span) => {
586
- * // ... your code ...
587
- * });
588
- *
589
- * await tracer.withActiveSpan('my-operation', { attributes: { foo: 'bar' } }, async (span) => {
590
- * // ... your code ...
591
- * });
592
- *
593
- * await tracer.withActiveSpan('my-operation', { attributes: { foo: 'bar' } }, myContext, async (span) => {
594
- * // ... your code ...
595
- * });
596
- */
597
- withActiveSpan<T>(name: string, fn: (span: LangWatchSpan) => Promise<T> | T): Promise<T>;
598
- withActiveSpan<T>(name: string, options: SpanOptions, fn: (span: LangWatchSpan) => Promise<T> | T): Promise<T>;
599
- withActiveSpan<T>(name: string, options: SpanOptions, context: Context, fn: (span: LangWatchSpan) => Promise<T> | T): Promise<T>;
600
- }
601
- /**
602
- * Extension of OpenTelemetry's Tracer with LangWatch-specific helpers.
603
- *
604
- * This interface provides methods for starting spans and active spans that return LangWatchSpan objects,
605
- * which include ergonomic helpers for LLM/GenAI tracing.
606
- *
607
- * @example
608
- * import { getLangWatchTracer } from 'langwatch';
609
- * const tracer = getLangWatchTracer('my-service');
610
- * const span = tracer.startSpan('llm-call');
611
- * span.setType('llm').setInput('Prompt').setOutput('Completion');
612
- * span.end();
613
- *
614
- * tracer.startActiveSpan('llm-call', (span) => {
615
- * span.setType('llm');
616
- * // ...
617
- * span.end();
618
- * });
619
- */
620
- declare function getLangWatchTracer(name: string, version?: string): LangWatchTracer;
621
-
622
- export { type LangWatchSpanGenAISystemMessageEventBody as A, type LangWatchSpanGenAIUserMessageEventBody as B, type LangWatchSpanGenAIAssistantMessageEventBody as C, type LangWatchSpanGenAIToolMessageEventBody as D, type LangWatchSpanGenAIChoiceEventBody as E, createLangWatchSpan as F, type LangWatchSpan as L, type SpanType as S, type VAL_GEN_AI_FINISH_REASONS as V, type LangWatchTracer as a, VAL_GEN_AI_FINISH_REASON_CONTENT_FILTER as b, VAL_GEN_AI_FINISH_REASON_ERROR as c, VAL_GEN_AI_FINISH_REASON_LENGTH as d, VAL_GEN_AI_FINISH_REASON_STOP as e, VAL_GEN_AI_FINISH_REASON_TOOL_CALLS as f, getLangWatchTracer as g, type VAL_GEN_AI_SYSTEMS as h, VAL_GEN_AI_SYSTEM_ANTHROPIC as i, VAL_GEN_AI_SYSTEM_AWS_BEDROCK as j, VAL_GEN_AI_SYSTEM_AZURE_AI_INFERENCE as k, VAL_GEN_AI_SYSTEM_AZURE_AI_OPENAI as l, VAL_GEN_AI_SYSTEM_COHERE as m, VAL_GEN_AI_SYSTEM_DEEPSEEK as n, VAL_GEN_AI_SYSTEM_GCP_GEMINI as o, VAL_GEN_AI_SYSTEM_GCP_GEN_AI as p, VAL_GEN_AI_SYSTEM_GCP_VERTEX_AI as q, VAL_GEN_AI_SYSTEM_GROQ as r, VAL_GEN_AI_SYSTEM_IBM_WATSONX_AI as s, VAL_GEN_AI_SYSTEM_MISTRAL_AI as t, VAL_GEN_AI_SYSTEM_OPENAI as u, VAL_GEN_AI_SYSTEM_PERPLEXITY as v, VAL_GEN_AI_SYSTEM_XAI as w, spanTypes as x, type LangWatchSpanRAGContext as y, type LangWatchSpanMetrics as z };