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