langwatch 0.2.0 → 0.3.0-prerelease.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (229) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +268 -1
  3. package/dist/chunk-4BZATFKJ.mjs +181 -0
  4. package/dist/chunk-4BZATFKJ.mjs.map +1 -0
  5. package/dist/chunk-CSC3CMIT.mjs +118 -0
  6. package/dist/chunk-CSC3CMIT.mjs.map +1 -0
  7. package/dist/chunk-F63YKTXA.mjs +47 -0
  8. package/dist/chunk-F63YKTXA.mjs.map +1 -0
  9. package/dist/chunk-G3AUABT7.js +4 -0
  10. package/dist/chunk-G3AUABT7.js.map +1 -0
  11. package/dist/chunk-HPC6Z7J4.js +118 -0
  12. package/dist/chunk-HPC6Z7J4.js.map +1 -0
  13. package/dist/chunk-KGDAENGD.js +50 -0
  14. package/dist/chunk-KGDAENGD.js.map +1 -0
  15. package/dist/chunk-LD74LVRU.js +47 -0
  16. package/dist/chunk-LD74LVRU.js.map +1 -0
  17. package/dist/chunk-OM7VY3XT.mjs +4 -0
  18. package/dist/chunk-PCQVQ7SB.js +45 -0
  19. package/dist/chunk-PCQVQ7SB.js.map +1 -0
  20. package/dist/chunk-PMBEK6YE.mjs +424 -0
  21. package/dist/chunk-PMBEK6YE.mjs.map +1 -0
  22. package/dist/chunk-PR3JDWC3.mjs +50 -0
  23. package/dist/chunk-PR3JDWC3.mjs.map +1 -0
  24. package/dist/chunk-PTJ6AAI7.js +360 -0
  25. package/dist/chunk-PTJ6AAI7.js.map +1 -0
  26. package/dist/chunk-QEWDG5QE.mjs +45 -0
  27. package/dist/chunk-QEWDG5QE.mjs.map +1 -0
  28. package/dist/chunk-REUCVT7A.mjs +39 -0
  29. package/dist/chunk-REUCVT7A.mjs.map +1 -0
  30. package/dist/chunk-SVJ7SCGB.js +424 -0
  31. package/dist/chunk-SVJ7SCGB.js.map +1 -0
  32. package/dist/chunk-VJSOCNPA.js +181 -0
  33. package/dist/chunk-VJSOCNPA.js.map +1 -0
  34. package/dist/chunk-WM2GRSRW.js +39 -0
  35. package/dist/chunk-WM2GRSRW.js.map +1 -0
  36. package/dist/chunk-Z5J5UI5E.mjs +360 -0
  37. package/dist/chunk-Z5J5UI5E.mjs.map +1 -0
  38. package/dist/client-B2HqIKg6.d.ts +51 -0
  39. package/dist/client-XyCqclCi.d.mts +51 -0
  40. package/dist/client-browser.d.mts +8 -0
  41. package/dist/client-browser.d.ts +8 -0
  42. package/dist/client-browser.js +83 -0
  43. package/dist/client-browser.js.map +1 -0
  44. package/dist/client-browser.mjs +83 -0
  45. package/dist/client-browser.mjs.map +1 -0
  46. package/dist/client-node.d.mts +8 -0
  47. package/dist/client-node.d.ts +8 -0
  48. package/dist/client-node.js +90 -0
  49. package/dist/client-node.js.map +1 -0
  50. package/dist/client-node.mjs +90 -0
  51. package/dist/client-node.mjs.map +1 -0
  52. package/dist/evaluation/index.d.mts +897 -0
  53. package/dist/evaluation/index.d.ts +897 -0
  54. package/dist/evaluation/index.js +13 -0
  55. package/dist/evaluation/index.js.map +1 -0
  56. package/dist/evaluation/index.mjs +13 -0
  57. package/dist/evaluation/index.mjs.map +1 -0
  58. package/dist/filterable-batch-span-processor-zO5kcjBY.d.mts +64 -0
  59. package/dist/filterable-batch-span-processor-zO5kcjBY.d.ts +64 -0
  60. package/dist/index.d.mts +45 -1027
  61. package/dist/index.d.ts +45 -1027
  62. package/dist/index.js +11 -27291
  63. package/dist/index.js.map +1 -1
  64. package/dist/index.mjs +23 -956
  65. package/dist/index.mjs.map +1 -1
  66. package/dist/observability/index.d.mts +260 -0
  67. package/dist/observability/index.d.ts +260 -0
  68. package/dist/observability/index.js +20 -0
  69. package/dist/observability/index.js.map +1 -0
  70. package/dist/observability/index.mjs +20 -0
  71. package/dist/observability/index.mjs.map +1 -0
  72. package/dist/observability/instrumentation/langchain/index.d.mts +40 -0
  73. package/dist/observability/instrumentation/langchain/index.d.ts +40 -0
  74. package/dist/observability/instrumentation/langchain/index.js +666 -0
  75. package/dist/observability/instrumentation/langchain/index.js.map +1 -0
  76. package/dist/observability/instrumentation/langchain/index.mjs +666 -0
  77. package/dist/observability/instrumentation/langchain/index.mjs.map +1 -0
  78. package/dist/prompt/index.d.mts +10 -0
  79. package/dist/prompt/index.d.ts +10 -0
  80. package/dist/prompt/index.js +18 -0
  81. package/dist/prompt/index.js.map +1 -0
  82. package/dist/prompt/index.mjs +18 -0
  83. package/dist/prompt/index.mjs.map +1 -0
  84. package/dist/prompt-BXJWdbQp.d.mts +1967 -0
  85. package/dist/prompt-BXJWdbQp.d.ts +1967 -0
  86. package/dist/record-evaluation-CmxMXa-3.d.mts +25 -0
  87. package/dist/record-evaluation-CmxMXa-3.d.ts +25 -0
  88. package/dist/trace-D-bZOuqb.d.mts +622 -0
  89. package/dist/trace-G2312klE.d.ts +622 -0
  90. package/package.json +86 -37
  91. package/.eslintrc.cjs +0 -37
  92. package/copy-types.sh +0 -17
  93. package/dist/chunk-LKD2K67J.mjs +0 -717
  94. package/dist/chunk-LKD2K67J.mjs.map +0 -1
  95. package/dist/utils-Cv-rUjJ1.d.mts +0 -313
  96. package/dist/utils-Cv-rUjJ1.d.ts +0 -313
  97. package/dist/utils.d.mts +0 -2
  98. package/dist/utils.d.ts +0 -2
  99. package/dist/utils.js +0 -709
  100. package/dist/utils.js.map +0 -1
  101. package/dist/utils.mjs +0 -11
  102. package/example/.env.example +0 -12
  103. package/example/.eslintrc.json +0 -26
  104. package/example/LICENSE +0 -13
  105. package/example/README.md +0 -12
  106. package/example/app/(chat)/chat/[id]/page.tsx +0 -60
  107. package/example/app/(chat)/layout.tsx +0 -14
  108. package/example/app/(chat)/page.tsx +0 -27
  109. package/example/app/actions.ts +0 -156
  110. package/example/app/globals.css +0 -76
  111. package/example/app/guardrails/page.tsx +0 -26
  112. package/example/app/langchain/page.tsx +0 -27
  113. package/example/app/langchain-rag/page.tsx +0 -28
  114. package/example/app/late-update/page.tsx +0 -27
  115. package/example/app/layout.tsx +0 -64
  116. package/example/app/login/actions.ts +0 -71
  117. package/example/app/login/page.tsx +0 -18
  118. package/example/app/manual/page.tsx +0 -27
  119. package/example/app/new/page.tsx +0 -5
  120. package/example/app/opengraph-image.png +0 -0
  121. package/example/app/share/[id]/page.tsx +0 -58
  122. package/example/app/signup/actions.ts +0 -111
  123. package/example/app/signup/page.tsx +0 -18
  124. package/example/app/twitter-image.png +0 -0
  125. package/example/auth.config.ts +0 -42
  126. package/example/auth.ts +0 -45
  127. package/example/components/button-scroll-to-bottom.tsx +0 -36
  128. package/example/components/chat-history.tsx +0 -49
  129. package/example/components/chat-list.tsx +0 -52
  130. package/example/components/chat-message-actions.tsx +0 -40
  131. package/example/components/chat-message.tsx +0 -80
  132. package/example/components/chat-panel.tsx +0 -139
  133. package/example/components/chat-share-dialog.tsx +0 -95
  134. package/example/components/chat.tsx +0 -84
  135. package/example/components/clear-history.tsx +0 -75
  136. package/example/components/empty-screen.tsx +0 -38
  137. package/example/components/external-link.tsx +0 -29
  138. package/example/components/footer.tsx +0 -19
  139. package/example/components/header.tsx +0 -114
  140. package/example/components/login-button.tsx +0 -42
  141. package/example/components/login-form.tsx +0 -97
  142. package/example/components/markdown.tsx +0 -9
  143. package/example/components/prompt-form.tsx +0 -115
  144. package/example/components/providers.tsx +0 -17
  145. package/example/components/sidebar-actions.tsx +0 -125
  146. package/example/components/sidebar-desktop.tsx +0 -19
  147. package/example/components/sidebar-footer.tsx +0 -16
  148. package/example/components/sidebar-item.tsx +0 -124
  149. package/example/components/sidebar-items.tsx +0 -42
  150. package/example/components/sidebar-list.tsx +0 -38
  151. package/example/components/sidebar-mobile.tsx +0 -31
  152. package/example/components/sidebar-toggle.tsx +0 -24
  153. package/example/components/sidebar.tsx +0 -21
  154. package/example/components/signup-form.tsx +0 -95
  155. package/example/components/stocks/events-skeleton.tsx +0 -31
  156. package/example/components/stocks/events.tsx +0 -30
  157. package/example/components/stocks/index.tsx +0 -36
  158. package/example/components/stocks/message.tsx +0 -134
  159. package/example/components/stocks/spinner.tsx +0 -16
  160. package/example/components/stocks/stock-purchase.tsx +0 -146
  161. package/example/components/stocks/stock-skeleton.tsx +0 -22
  162. package/example/components/stocks/stock.tsx +0 -210
  163. package/example/components/stocks/stocks-skeleton.tsx +0 -9
  164. package/example/components/stocks/stocks.tsx +0 -67
  165. package/example/components/tailwind-indicator.tsx +0 -14
  166. package/example/components/theme-toggle.tsx +0 -31
  167. package/example/components/ui/alert-dialog.tsx +0 -141
  168. package/example/components/ui/badge.tsx +0 -36
  169. package/example/components/ui/button.tsx +0 -57
  170. package/example/components/ui/codeblock.tsx +0 -148
  171. package/example/components/ui/dialog.tsx +0 -122
  172. package/example/components/ui/dropdown-menu.tsx +0 -205
  173. package/example/components/ui/icons.tsx +0 -507
  174. package/example/components/ui/input.tsx +0 -25
  175. package/example/components/ui/label.tsx +0 -26
  176. package/example/components/ui/select.tsx +0 -164
  177. package/example/components/ui/separator.tsx +0 -31
  178. package/example/components/ui/sheet.tsx +0 -140
  179. package/example/components/ui/sonner.tsx +0 -31
  180. package/example/components/ui/switch.tsx +0 -29
  181. package/example/components/ui/textarea.tsx +0 -24
  182. package/example/components/ui/tooltip.tsx +0 -30
  183. package/example/components/user-menu.tsx +0 -53
  184. package/example/components.json +0 -17
  185. package/example/instrumentation.ts +0 -11
  186. package/example/lib/chat/guardrails.tsx +0 -181
  187. package/example/lib/chat/langchain-rag.tsx +0 -191
  188. package/example/lib/chat/langchain.tsx +0 -112
  189. package/example/lib/chat/late-update.tsx +0 -208
  190. package/example/lib/chat/manual.tsx +0 -605
  191. package/example/lib/chat/vercel-ai.tsx +0 -576
  192. package/example/lib/hooks/use-copy-to-clipboard.tsx +0 -33
  193. package/example/lib/hooks/use-enter-submit.tsx +0 -23
  194. package/example/lib/hooks/use-local-storage.ts +0 -24
  195. package/example/lib/hooks/use-scroll-anchor.tsx +0 -86
  196. package/example/lib/hooks/use-sidebar.tsx +0 -60
  197. package/example/lib/hooks/use-streamable-text.ts +0 -25
  198. package/example/lib/types.ts +0 -41
  199. package/example/lib/utils.ts +0 -89
  200. package/example/middleware.ts +0 -8
  201. package/example/next-env.d.ts +0 -5
  202. package/example/next.config.js +0 -16
  203. package/example/package-lock.json +0 -10917
  204. package/example/package.json +0 -84
  205. package/example/pnpm-lock.yaml +0 -5712
  206. package/example/postcss.config.js +0 -6
  207. package/example/prettier.config.cjs +0 -34
  208. package/example/public/apple-touch-icon.png +0 -0
  209. package/example/public/favicon-16x16.png +0 -0
  210. package/example/public/favicon.ico +0 -0
  211. package/example/public/next.svg +0 -1
  212. package/example/public/thirteen.svg +0 -1
  213. package/example/public/vercel.svg +0 -1
  214. package/example/tailwind.config.ts +0 -81
  215. package/example/tsconfig.json +0 -35
  216. package/src/LangWatchExporter.ts +0 -96
  217. package/src/evaluations.ts +0 -219
  218. package/src/index.test.ts +0 -402
  219. package/src/index.ts +0 -596
  220. package/src/langchain.ts +0 -557
  221. package/src/server/types/.gitkeep +0 -0
  222. package/src/typeUtils.ts +0 -89
  223. package/src/types.ts +0 -82
  224. package/src/utils.ts +0 -205
  225. package/ts-to-zod.config.js +0 -24
  226. package/tsconfig.json +0 -32
  227. package/tsup.config.ts +0 -10
  228. package/vitest.config.ts +0 -8
  229. /package/dist/{utils.mjs.map → chunk-OM7VY3XT.mjs.map} +0 -0
@@ -1,717 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __defProps = Object.defineProperties;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
8
- var __getProtoOf = Object.getPrototypeOf;
9
- var __hasOwnProp = Object.prototype.hasOwnProperty;
10
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
11
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
12
- var __spreadValues = (a, b) => {
13
- for (var prop in b || (b = {}))
14
- if (__hasOwnProp.call(b, prop))
15
- __defNormalProp(a, prop, b[prop]);
16
- if (__getOwnPropSymbols)
17
- for (var prop of __getOwnPropSymbols(b)) {
18
- if (__propIsEnum.call(b, prop))
19
- __defNormalProp(a, prop, b[prop]);
20
- }
21
- return a;
22
- };
23
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
24
- var __commonJS = (cb, mod) => function __require() {
25
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
26
- };
27
- var __copyProps = (to, from, except, desc) => {
28
- if (from && typeof from === "object" || typeof from === "function") {
29
- for (let key of __getOwnPropNames(from))
30
- if (!__hasOwnProp.call(to, key) && key !== except)
31
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
32
- }
33
- return to;
34
- };
35
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
36
- // If the importer is in node compatibility mode or this is not an ESM
37
- // file that has been converted to a CommonJS file using a Babel-
38
- // compatible transform (i.e. "__esModule" has not been set), then set
39
- // "default" to the CommonJS "module.exports" for node compatibility.
40
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
41
- mod
42
- ));
43
-
44
- // node_modules/secure-json-parse/index.js
45
- var require_secure_json_parse = __commonJS({
46
- "node_modules/secure-json-parse/index.js"(exports, module) {
47
- "use strict";
48
- var hasBuffer = typeof Buffer !== "undefined";
49
- var suspectProtoRx = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/;
50
- var suspectConstructorRx = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
51
- function _parse(text, reviver, options) {
52
- if (options == null) {
53
- if (reviver !== null && typeof reviver === "object") {
54
- options = reviver;
55
- reviver = void 0;
56
- }
57
- }
58
- if (hasBuffer && Buffer.isBuffer(text)) {
59
- text = text.toString();
60
- }
61
- if (text && text.charCodeAt(0) === 65279) {
62
- text = text.slice(1);
63
- }
64
- const obj = JSON.parse(text, reviver);
65
- if (obj === null || typeof obj !== "object") {
66
- return obj;
67
- }
68
- const protoAction = options && options.protoAction || "error";
69
- const constructorAction = options && options.constructorAction || "error";
70
- if (protoAction === "ignore" && constructorAction === "ignore") {
71
- return obj;
72
- }
73
- if (protoAction !== "ignore" && constructorAction !== "ignore") {
74
- if (suspectProtoRx.test(text) === false && suspectConstructorRx.test(text) === false) {
75
- return obj;
76
- }
77
- } else if (protoAction !== "ignore" && constructorAction === "ignore") {
78
- if (suspectProtoRx.test(text) === false) {
79
- return obj;
80
- }
81
- } else {
82
- if (suspectConstructorRx.test(text) === false) {
83
- return obj;
84
- }
85
- }
86
- return filter(obj, { protoAction, constructorAction, safe: options && options.safe });
87
- }
88
- function filter(obj, { protoAction = "error", constructorAction = "error", safe } = {}) {
89
- let next = [obj];
90
- while (next.length) {
91
- const nodes = next;
92
- next = [];
93
- for (const node of nodes) {
94
- if (protoAction !== "ignore" && Object.prototype.hasOwnProperty.call(node, "__proto__")) {
95
- if (safe === true) {
96
- return null;
97
- } else if (protoAction === "error") {
98
- throw new SyntaxError("Object contains forbidden prototype property");
99
- }
100
- delete node.__proto__;
101
- }
102
- if (constructorAction !== "ignore" && Object.prototype.hasOwnProperty.call(node, "constructor") && Object.prototype.hasOwnProperty.call(node.constructor, "prototype")) {
103
- if (safe === true) {
104
- return null;
105
- } else if (constructorAction === "error") {
106
- throw new SyntaxError("Object contains forbidden prototype property");
107
- }
108
- delete node.constructor;
109
- }
110
- for (const key in node) {
111
- const value = node[key];
112
- if (value && typeof value === "object") {
113
- next.push(value);
114
- }
115
- }
116
- }
117
- }
118
- return obj;
119
- }
120
- function parse(text, reviver, options) {
121
- const stackTraceLimit = Error.stackTraceLimit;
122
- Error.stackTraceLimit = 0;
123
- try {
124
- return _parse(text, reviver, options);
125
- } finally {
126
- Error.stackTraceLimit = stackTraceLimit;
127
- }
128
- }
129
- function safeParse(text, reviver) {
130
- const stackTraceLimit = Error.stackTraceLimit;
131
- Error.stackTraceLimit = 0;
132
- try {
133
- return _parse(text, reviver, { safe: true });
134
- } catch (_e) {
135
- return null;
136
- } finally {
137
- Error.stackTraceLimit = stackTraceLimit;
138
- }
139
- }
140
- module.exports = parse;
141
- module.exports.default = parse;
142
- module.exports.parse = parse;
143
- module.exports.safeParse = safeParse;
144
- module.exports.scan = filter;
145
- }
146
- });
147
-
148
- // node_modules/@ai-sdk/provider-utils/dist/index.mjs
149
- import { customAlphabet } from "nanoid/non-secure";
150
- var import_secure_json_parse = __toESM(require_secure_json_parse(), 1);
151
- var generateId = customAlphabet(
152
- "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz",
153
- 7
154
- );
155
- function convertUint8ArrayToBase64(array) {
156
- let latin1string = "";
157
- for (let i = 0; i < array.length; i++) {
158
- latin1string += String.fromCodePoint(array[i]);
159
- }
160
- return globalThis.btoa(latin1string);
161
- }
162
-
163
- // src/utils.ts
164
- import { z as z2 } from "zod";
165
-
166
- // src/server/types/tracer.generated.ts
167
- import { z } from "zod";
168
- var chatRoleSchema = z.union([
169
- z.literal("system"),
170
- z.literal("user"),
171
- z.literal("assistant"),
172
- z.literal("function"),
173
- z.literal("tool"),
174
- z.literal("unknown")
175
- ]);
176
- var functionCallSchema = z.object({
177
- name: z.string().optional(),
178
- arguments: z.string().optional()
179
- });
180
- var toolCallSchema = z.object({
181
- id: z.string(),
182
- type: z.string(),
183
- function: functionCallSchema
184
- });
185
- var rAGChunkSchema = z.object({
186
- document_id: z.string().optional().nullable(),
187
- chunk_id: z.string().optional().nullable(),
188
- content: z.union([z.string(), z.record(z.any()), z.array(z.any())])
189
- });
190
- var chatRichContentSchema = z.union([
191
- z.object({
192
- type: z.literal("text"),
193
- text: z.string().optional()
194
- }),
195
- z.object({
196
- text: z.string()
197
- }),
198
- z.object({
199
- type: z.literal("image_url"),
200
- image_url: z.object({
201
- url: z.string(),
202
- detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
203
- }).optional()
204
- }),
205
- z.object({
206
- type: z.literal("tool_call"),
207
- toolName: z.string().optional(),
208
- toolCallId: z.string().optional(),
209
- args: z.string().optional()
210
- }),
211
- z.object({
212
- type: z.literal("tool_result"),
213
- toolName: z.string().optional(),
214
- toolCallId: z.string().optional(),
215
- result: z.any().optional()
216
- })
217
- ]);
218
- var typedValueTextSchema = z.object({
219
- type: z.literal("text"),
220
- value: z.string()
221
- });
222
- var typedValueRawSchema = z.object({
223
- type: z.literal("raw"),
224
- value: z.string()
225
- });
226
- var jSONSerializableSchema = z.union([
227
- z.string(),
228
- z.number(),
229
- z.boolean(),
230
- z.record(z.any()),
231
- z.array(z.any())
232
- ]).nullable();
233
- var typedValueJsonSchema = z.object({
234
- type: z.literal("json"),
235
- value: jSONSerializableSchema
236
- });
237
- var moneySchema = z.object({
238
- currency: z.string(),
239
- amount: z.number()
240
- });
241
- var evaluationResultSchema = z.object({
242
- status: z.union([
243
- z.literal("processed"),
244
- z.literal("skipped"),
245
- z.literal("error")
246
- ]),
247
- passed: z.boolean().optional().nullable(),
248
- score: z.number().optional().nullable(),
249
- label: z.string().optional().nullable(),
250
- details: z.string().optional().nullable(),
251
- cost: moneySchema.optional().nullable()
252
- });
253
- var typedValueGuardrailResultSchema = z.object({
254
- type: z.literal("guardrail_result"),
255
- value: evaluationResultSchema
256
- });
257
- var typedValueEvaluationResultSchema = z.object({
258
- type: z.literal("evaluation_result"),
259
- value: evaluationResultSchema
260
- });
261
- var errorCaptureSchema = z.object({
262
- has_error: z.literal(true),
263
- message: z.string(),
264
- stacktrace: z.array(z.string())
265
- });
266
- var spanMetricsSchema = z.object({
267
- prompt_tokens: z.number().optional().nullable(),
268
- completion_tokens: z.number().optional().nullable(),
269
- tokens_estimated: z.boolean().optional().nullable(),
270
- cost: z.number().optional().nullable()
271
- });
272
- var reservedSpanParamsSchema = z.object({
273
- frequency_penalty: z.number().optional().nullable(),
274
- logit_bias: z.record(z.number()).optional().nullable(),
275
- logprobs: z.boolean().optional().nullable(),
276
- top_logprobs: z.number().optional().nullable(),
277
- max_tokens: z.number().optional().nullable(),
278
- n: z.number().optional().nullable(),
279
- presence_penalty: z.number().optional().nullable(),
280
- seed: z.number().optional().nullable(),
281
- stop: z.union([z.string(), z.array(z.string())]).optional().nullable(),
282
- stream: z.boolean().optional().nullable(),
283
- temperature: z.number().optional().nullable(),
284
- top_p: z.number().optional().nullable(),
285
- tools: z.array(z.record(z.any())).optional().nullable(),
286
- tool_choice: z.union([z.record(z.any()), z.string()]).optional().nullable(),
287
- parallel_tool_calls: z.boolean().optional().nullable(),
288
- functions: z.array(z.record(z.any())).optional().nullable(),
289
- user: z.string().optional().nullable()
290
- });
291
- var spanParamsSchema = reservedSpanParamsSchema.and(z.record(z.any()));
292
- var spanTimestampsSchema = z.object({
293
- started_at: z.number(),
294
- first_token_at: z.number().optional().nullable(),
295
- finished_at: z.number()
296
- });
297
- var spanTypesSchema = z.union([
298
- z.literal("span"),
299
- z.literal("llm"),
300
- z.literal("chain"),
301
- z.literal("tool"),
302
- z.literal("agent"),
303
- z.literal("rag"),
304
- z.literal("guardrail"),
305
- z.literal("evaluation"),
306
- z.literal("workflow"),
307
- z.literal("component"),
308
- z.literal("module"),
309
- z.literal("server"),
310
- z.literal("client"),
311
- z.literal("producer"),
312
- z.literal("consumer"),
313
- z.literal("task"),
314
- z.literal("unknown")
315
- ]);
316
- var traceInputSchema = z.object({
317
- value: z.string(),
318
- satisfaction_score: z.number().optional()
319
- });
320
- var traceOutputSchema = z.object({
321
- value: z.string()
322
- });
323
- var primitiveTypeSchema = z.union([z.string(), z.number(), z.boolean(), z.undefined()]).nullable();
324
- var reservedTraceMetadataSchema = z.object({
325
- thread_id: z.string().optional().nullable(),
326
- user_id: z.string().optional().nullable(),
327
- customer_id: z.string().optional().nullable(),
328
- labels: z.array(z.string()).optional().nullable(),
329
- topic_id: z.string().optional().nullable(),
330
- subtopic_id: z.string().optional().nullable(),
331
- sdk_name: z.string().optional().nullable(),
332
- sdk_version: z.string().optional().nullable(),
333
- sdk_language: z.string().optional().nullable(),
334
- telemetry_sdk_language: z.string().optional().nullable(),
335
- telemetry_sdk_name: z.string().optional().nullable(),
336
- telemetry_sdk_version: z.string().optional().nullable(),
337
- prompt_ids: z.array(z.string()).optional().nullable(),
338
- prompt_version_ids: z.array(z.string()).optional().nullable()
339
- });
340
- var reservedTraceMetadataMappingSchema = z.record(z.any());
341
- var customMetadataSchema = z.record(
342
- z.union([
343
- primitiveTypeSchema,
344
- z.array(primitiveTypeSchema),
345
- z.record(primitiveTypeSchema),
346
- z.record(z.record(primitiveTypeSchema))
347
- ])
348
- );
349
- var traceMetadataSchema = reservedTraceMetadataSchema.and(customMetadataSchema);
350
- var eventSchema = z.object({
351
- event_id: z.string(),
352
- event_type: z.string(),
353
- project_id: z.string(),
354
- metrics: z.record(z.number()),
355
- event_details: z.record(z.string()),
356
- trace_id: z.string(),
357
- timestamps: z.object({
358
- started_at: z.number(),
359
- inserted_at: z.number(),
360
- updated_at: z.number()
361
- })
362
- });
363
- var elasticSearchEventSchema = eventSchema.omit({ metrics: true, event_details: true }).and(
364
- z.object({
365
- metrics: z.array(
366
- z.object({
367
- key: z.string(),
368
- value: z.number()
369
- })
370
- ),
371
- event_details: z.array(
372
- z.object({
373
- key: z.string(),
374
- value: z.string()
375
- })
376
- )
377
- })
378
- );
379
- var evaluationStatusSchema = z.union([
380
- z.literal("scheduled"),
381
- z.literal("in_progress"),
382
- z.literal("error"),
383
- z.literal("skipped"),
384
- z.literal("processed")
385
- ]);
386
- var trackEventRESTParamsValidatorSchema = eventSchema.omit({
387
- event_id: true,
388
- project_id: true,
389
- timestamps: true,
390
- event_details: true
391
- }).and(
392
- z.object({
393
- event_id: z.string().optional(),
394
- event_details: z.record(z.string()).optional(),
395
- timestamp: z.number().optional()
396
- })
397
- );
398
- var contextsSchema = z.object({
399
- traceId: z.string(),
400
- contexts: z.array(rAGChunkSchema)
401
- });
402
- var chatMessageSchema = z.object({
403
- role: chatRoleSchema.optional(),
404
- content: z.union([z.string(), z.array(chatRichContentSchema)]).optional().nullable(),
405
- function_call: functionCallSchema.optional().nullable(),
406
- tool_calls: z.array(toolCallSchema).optional().nullable(),
407
- tool_call_id: z.string().optional().nullable(),
408
- name: z.string().optional().nullable()
409
- });
410
- var typedValueChatMessagesSchema = z.object({
411
- type: z.literal("chat_messages"),
412
- value: z.array(chatMessageSchema)
413
- });
414
- var spanInputOutputSchema = z.lazy(
415
- () => z.union([
416
- typedValueTextSchema,
417
- typedValueChatMessagesSchema,
418
- typedValueGuardrailResultSchema,
419
- typedValueEvaluationResultSchema,
420
- typedValueJsonSchema,
421
- typedValueRawSchema,
422
- z.object({
423
- type: z.literal("list"),
424
- value: z.array(spanInputOutputSchema)
425
- })
426
- ])
427
- );
428
- var baseSpanSchema = z.object({
429
- span_id: z.string(),
430
- parent_id: z.string().optional().nullable(),
431
- trace_id: z.string(),
432
- type: spanTypesSchema,
433
- name: z.string().optional().nullable(),
434
- input: spanInputOutputSchema.optional().nullable(),
435
- output: spanInputOutputSchema.optional().nullable(),
436
- error: errorCaptureSchema.optional().nullable(),
437
- timestamps: spanTimestampsSchema,
438
- metrics: spanMetricsSchema.optional().nullable(),
439
- params: spanParamsSchema.optional().nullable()
440
- });
441
- var lLMSpanSchema = baseSpanSchema.extend({
442
- type: z.literal("llm"),
443
- vendor: z.string().optional().nullable(),
444
- model: z.string().optional().nullable()
445
- });
446
- var rAGSpanSchema = baseSpanSchema.extend({
447
- type: z.literal("rag"),
448
- contexts: z.array(rAGChunkSchema)
449
- });
450
- var spanSchema = z.union([
451
- lLMSpanSchema,
452
- rAGSpanSchema,
453
- baseSpanSchema
454
- ]);
455
- var spanInputOutputValidatorSchema = spanInputOutputSchema.and(
456
- z.object({
457
- value: z.any()
458
- })
459
- );
460
- var spanValidatorSchema = z.union([
461
- lLMSpanSchema.omit({ input: true, output: true, params: true }),
462
- rAGSpanSchema.omit({ input: true, output: true, params: true }),
463
- baseSpanSchema.omit({ input: true, output: true, params: true })
464
- ]).and(
465
- z.object({
466
- input: spanInputOutputValidatorSchema.optional().nullable(),
467
- output: spanInputOutputValidatorSchema.optional().nullable(),
468
- params: z.record(z.any()).optional().nullable()
469
- })
470
- );
471
- var evaluationSchema = z.object({
472
- evaluation_id: z.string(),
473
- evaluator_id: z.string(),
474
- span_id: z.string().optional().nullable(),
475
- name: z.string(),
476
- type: z.string().optional().nullable(),
477
- is_guardrail: z.boolean().optional().nullable(),
478
- status: evaluationStatusSchema,
479
- passed: z.boolean().optional().nullable(),
480
- score: z.number().optional().nullable(),
481
- label: z.string().optional().nullable(),
482
- details: z.string().optional().nullable(),
483
- error: errorCaptureSchema.optional().nullable(),
484
- retries: z.number().optional().nullable(),
485
- timestamps: z.object({
486
- inserted_at: z.number().optional().nullable(),
487
- started_at: z.number().optional().nullable(),
488
- finished_at: z.number().optional().nullable(),
489
- updated_at: z.number().optional().nullable()
490
- })
491
- });
492
- var rESTEvaluationSchema = evaluationSchema.omit({
493
- evaluation_id: true,
494
- evaluator_id: true,
495
- status: true,
496
- timestamps: true,
497
- retries: true
498
- }).and(
499
- z.object({
500
- evaluation_id: z.string().optional().nullable(),
501
- evaluator_id: z.string().optional().nullable(),
502
- status: z.union([
503
- z.literal("processed"),
504
- z.literal("skipped"),
505
- z.literal("error")
506
- ]).optional().nullable(),
507
- timestamps: z.object({
508
- started_at: z.number().optional().nullable(),
509
- finished_at: z.number().optional().nullable()
510
- }).optional().nullable()
511
- })
512
- );
513
- var collectorRESTParamsSchema = z.object({
514
- trace_id: z.union([z.string(), z.undefined()]).optional().nullable(),
515
- spans: z.array(spanSchema),
516
- metadata: z.object({
517
- user_id: z.union([z.string(), z.undefined()]).optional().nullable(),
518
- thread_id: z.union([z.string(), z.undefined()]).optional().nullable(),
519
- customer_id: z.union([z.string(), z.undefined()]).optional().nullable(),
520
- labels: z.union([z.array(z.string()), z.undefined()]).optional().nullable(),
521
- sdk_version: z.union([z.string(), z.undefined()]).optional().nullable(),
522
- sdk_language: z.union([z.string(), z.undefined()]).optional().nullable()
523
- }).and(customMetadataSchema).optional(),
524
- expected_output: z.string().optional().nullable(),
525
- evaluations: z.array(rESTEvaluationSchema).optional()
526
- });
527
- var collectorRESTParamsValidatorSchema = collectorRESTParamsSchema.omit({ spans: true });
528
- var traceSchema = z.object({
529
- trace_id: z.string(),
530
- project_id: z.string(),
531
- metadata: traceMetadataSchema,
532
- timestamps: z.object({
533
- started_at: z.number(),
534
- inserted_at: z.number(),
535
- updated_at: z.number()
536
- }),
537
- input: traceInputSchema.optional(),
538
- output: traceOutputSchema.optional(),
539
- contexts: z.array(rAGChunkSchema).optional(),
540
- expected_output: z.object({
541
- value: z.string()
542
- }).optional(),
543
- metrics: z.object({
544
- first_token_ms: z.number().optional().nullable(),
545
- total_time_ms: z.number().optional().nullable(),
546
- prompt_tokens: z.number().optional().nullable(),
547
- completion_tokens: z.number().optional().nullable(),
548
- total_cost: z.number().optional().nullable(),
549
- tokens_estimated: z.boolean().optional().nullable()
550
- }).optional(),
551
- error: errorCaptureSchema.optional().nullable(),
552
- indexing_md5s: z.array(z.string()).optional(),
553
- events: z.array(eventSchema).optional(),
554
- evaluations: z.array(evaluationSchema).optional(),
555
- spans: z.array(spanSchema)
556
- });
557
-
558
- // src/utils.ts
559
- var convertImageToUrl = (image, mimeType) => {
560
- try {
561
- return image instanceof URL ? image.toString() : typeof image === "string" ? image : `data:${mimeType != null ? mimeType : "image/jpeg"};base64,${convertUint8ArrayToBase64(
562
- image
563
- )}`;
564
- } catch (e) {
565
- console.error("[LangWatch] error converting vercel ui image to url:", e);
566
- return "";
567
- }
568
- };
569
- function convertFromVercelAIMessages(messages) {
570
- var _a;
571
- const lwMessages = [];
572
- for (const { role, content } of messages) {
573
- switch (role) {
574
- case "system": {
575
- lwMessages.push({ role: "system", content });
576
- break;
577
- }
578
- case "user": {
579
- if (Array.isArray(content) && content.length === 1 && ((_a = content[0]) == null ? void 0 : _a.type) === "text") {
580
- lwMessages.push({ role: "user", content: content[0].text });
581
- break;
582
- }
583
- lwMessages.push({
584
- role: "user",
585
- content: Array.isArray(content) ? content.map((part) => {
586
- switch (part.type) {
587
- case "text": {
588
- return { type: "text", text: part.text };
589
- }
590
- case "image": {
591
- return {
592
- type: "image_url",
593
- image_url: {
594
- url: convertImageToUrl(part.image, part.mimeType)
595
- }
596
- };
597
- }
598
- default: {
599
- return part;
600
- }
601
- }
602
- }) : content
603
- });
604
- break;
605
- }
606
- case "assistant": {
607
- let text = "";
608
- const toolCalls = [];
609
- if (Array.isArray(content)) {
610
- for (const part of content) {
611
- switch (part.type) {
612
- case "text": {
613
- text += part.text;
614
- break;
615
- }
616
- case "tool-call": {
617
- toolCalls.push({
618
- id: part.toolCallId,
619
- type: "function",
620
- function: {
621
- name: part.toolName,
622
- arguments: JSON.stringify(part.args)
623
- }
624
- });
625
- break;
626
- }
627
- default: {
628
- const _exhaustiveCheck = part;
629
- throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
630
- }
631
- }
632
- }
633
- } else {
634
- text = content;
635
- }
636
- lwMessages.push({
637
- role: "assistant",
638
- content: text,
639
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
640
- });
641
- break;
642
- }
643
- case "tool": {
644
- for (const toolResponse of content) {
645
- lwMessages.push({
646
- role: "tool",
647
- tool_call_id: toolResponse.toolCallId,
648
- content: JSON.stringify(toolResponse.result)
649
- });
650
- }
651
- break;
652
- }
653
- default: {
654
- const _exhaustiveCheck = role;
655
- throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
656
- }
657
- }
658
- }
659
- return lwMessages;
660
- }
661
- var captureError = (error) => {
662
- if (error && typeof error === "object" && "has_error" in error && "message" in error && "stacktrace" in error) {
663
- return error;
664
- } else if (error instanceof Error) {
665
- return {
666
- has_error: true,
667
- message: error.message,
668
- stacktrace: error.stack ? error.stack.split("\n") : []
669
- };
670
- } else if (typeof error === "object" && error !== null) {
671
- const err = error;
672
- const message = typeof err.message === "string" ? err.message : "An unknown error occurred";
673
- const stacktrace = typeof err.stack === "string" ? err.stack.split("\n") : Array.isArray(err.stack) && err.stack.length > 0 && typeof err.stack[0] === "string" ? err.stack : ["No stack trace available"];
674
- return {
675
- has_error: true,
676
- message,
677
- stacktrace
678
- };
679
- } else {
680
- return {
681
- has_error: true,
682
- message: String(error),
683
- stacktrace: []
684
- };
685
- }
686
- };
687
- var autoconvertTypedValues = (value) => {
688
- if (typeof value === "string") {
689
- return { type: "text", value };
690
- }
691
- const chatMessages = z2.array(chatMessageSchema).safeParse(value);
692
- if (Array.isArray(value) && chatMessages.success) {
693
- return {
694
- type: "chat_messages",
695
- value: chatMessages.data
696
- };
697
- }
698
- try {
699
- JSON.stringify(value);
700
- return { type: "json", value };
701
- } catch (e) {
702
- return { type: "raw", value };
703
- }
704
- };
705
-
706
- export {
707
- __spreadValues,
708
- __spreadProps,
709
- reservedSpanParamsSchema,
710
- reservedTraceMetadataSchema,
711
- spanSchema,
712
- collectorRESTParamsSchema,
713
- convertFromVercelAIMessages,
714
- captureError,
715
- autoconvertTypedValues
716
- };
717
- //# sourceMappingURL=chunk-LKD2K67J.mjs.map