langwatch 0.2.0 → 0.3.0-prerelease.1

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 (235) hide show
  1. package/.editorconfig +16 -0
  2. package/LICENSE +7 -0
  3. package/README.md +268 -1
  4. package/copy-types.sh +19 -8
  5. package/examples/langchain/.env.example +2 -0
  6. package/examples/langchain/README.md +42 -0
  7. package/examples/langchain/package-lock.json +2930 -0
  8. package/examples/langchain/package.json +27 -0
  9. package/examples/langchain/src/cli-markdown.d.ts +137 -0
  10. package/examples/langchain/src/index.ts +109 -0
  11. package/examples/langchain/tsconfig.json +25 -0
  12. package/examples/langgraph/.env.example +2 -0
  13. package/examples/langgraph/README.md +42 -0
  14. package/examples/langgraph/package-lock.json +3031 -0
  15. package/examples/langgraph/package.json +28 -0
  16. package/examples/langgraph/src/cli-markdown.d.ts +137 -0
  17. package/examples/langgraph/src/index.ts +196 -0
  18. package/examples/langgraph/tsconfig.json +25 -0
  19. package/examples/mastra/.env.example +2 -0
  20. package/examples/mastra/README.md +57 -0
  21. package/examples/mastra/package-lock.json +5296 -0
  22. package/examples/mastra/package.json +32 -0
  23. package/examples/mastra/src/cli-markdown.d.ts +137 -0
  24. package/examples/mastra/src/index.ts +120 -0
  25. package/examples/mastra/src/mastra/agents/weather-agent.ts +30 -0
  26. package/examples/mastra/src/mastra/index.ts +21 -0
  27. package/examples/mastra/src/mastra/tools/weather-tool.ts +102 -0
  28. package/examples/mastra/tsconfig.json +25 -0
  29. package/examples/vercel-ai/.env.example +2 -0
  30. package/examples/vercel-ai/README.md +38 -0
  31. package/examples/vercel-ai/package-lock.json +2571 -0
  32. package/examples/vercel-ai/package.json +27 -0
  33. package/examples/vercel-ai/src/cli-markdown.d.ts +137 -0
  34. package/examples/vercel-ai/src/index.ts +110 -0
  35. package/examples/vercel-ai/src/instrumentation.ts +9 -0
  36. package/examples/vercel-ai/tsconfig.json +25 -0
  37. package/package.json +78 -34
  38. package/src/__tests__/client-browser.test.ts +92 -0
  39. package/src/__tests__/client-node.test.ts +76 -0
  40. package/src/__tests__/client.test.ts +71 -0
  41. package/src/__tests__/integration/client-browser.test.ts +46 -0
  42. package/src/__tests__/integration/client-node.test.ts +46 -0
  43. package/src/client-browser.ts +70 -0
  44. package/src/client-node.ts +82 -0
  45. package/src/client-shared.ts +72 -0
  46. package/src/client.ts +119 -0
  47. package/src/evaluation/__tests__/record-evaluation.test.ts +112 -0
  48. package/src/evaluation/__tests__/run-evaluation.test.ts +171 -0
  49. package/src/evaluation/index.ts +2 -0
  50. package/src/evaluation/record-evaluation.ts +101 -0
  51. package/src/evaluation/run-evaluation.ts +133 -0
  52. package/src/evaluation/tracer.ts +3 -0
  53. package/src/evaluation/types.ts +23 -0
  54. package/src/index.ts +10 -593
  55. package/src/internal/api/__tests__/errors.test.ts +98 -0
  56. package/src/internal/api/client.ts +30 -0
  57. package/src/internal/api/errors.ts +32 -0
  58. package/src/internal/generated/types/.gitkeep +0 -0
  59. package/src/observability/__tests__/integration/base.test.ts +74 -0
  60. package/src/observability/__tests__/integration/browser-setup-ordering.test.ts +60 -0
  61. package/src/observability/__tests__/integration/complex-nested-spans.test.ts +29 -0
  62. package/src/observability/__tests__/integration/error-handling.test.ts +24 -0
  63. package/src/observability/__tests__/integration/langwatch-disabled-otel.test.ts +24 -0
  64. package/src/observability/__tests__/integration/langwatch-first-then-vercel.test.ts +24 -0
  65. package/src/observability/__tests__/integration/multiple-setup-attempts.test.ts +27 -0
  66. package/src/observability/__tests__/integration/otel-ordering.test.ts +27 -0
  67. package/src/observability/__tests__/integration/vercel-configurations.test.ts +20 -0
  68. package/src/observability/__tests__/integration/vercel-first-then-langwatch.test.ts +27 -0
  69. package/src/observability/__tests__/span.test.ts +214 -0
  70. package/src/observability/__tests__/trace.test.ts +180 -0
  71. package/src/observability/exporters/index.ts +1 -0
  72. package/src/observability/exporters/langwatch-exporter.ts +53 -0
  73. package/src/observability/index.ts +4 -0
  74. package/src/observability/instrumentation/langchain/__tests__/integration/langchain-chatbot.test.ts +112 -0
  75. package/src/observability/instrumentation/langchain/__tests__/langchain.test.ts +284 -0
  76. package/src/observability/instrumentation/langchain/index.ts +624 -0
  77. package/src/observability/processors/__tests__/filterable-batch-span-exporter.test.ts +98 -0
  78. package/src/observability/processors/filterable-batch-span-processor.ts +99 -0
  79. package/src/observability/processors/index.ts +1 -0
  80. package/src/observability/semconv/attributes.ts +185 -0
  81. package/src/observability/semconv/events.ts +42 -0
  82. package/src/observability/semconv/index.ts +16 -0
  83. package/src/observability/semconv/values.ts +159 -0
  84. package/src/observability/span.ts +728 -0
  85. package/src/observability/trace.ts +301 -0
  86. package/src/prompt/__tests__/prompt.test.ts +139 -0
  87. package/src/prompt/get-prompt-version.ts +49 -0
  88. package/src/prompt/get-prompt.ts +44 -0
  89. package/src/prompt/index.ts +3 -0
  90. package/src/prompt/prompt.ts +133 -0
  91. package/src/prompt/service.ts +221 -0
  92. package/src/prompt/tracer.ts +3 -0
  93. package/src/prompt/types.ts +0 -0
  94. package/ts-to-zod.config.js +11 -0
  95. package/tsconfig.json +3 -9
  96. package/tsup.config.ts +11 -1
  97. package/vitest.config.ts +1 -0
  98. package/dist/chunk-LKD2K67J.mjs +0 -717
  99. package/dist/chunk-LKD2K67J.mjs.map +0 -1
  100. package/dist/index.d.mts +0 -1030
  101. package/dist/index.d.ts +0 -1030
  102. package/dist/index.js +0 -27310
  103. package/dist/index.js.map +0 -1
  104. package/dist/index.mjs +0 -963
  105. package/dist/index.mjs.map +0 -1
  106. package/dist/utils-Cv-rUjJ1.d.mts +0 -313
  107. package/dist/utils-Cv-rUjJ1.d.ts +0 -313
  108. package/dist/utils.d.mts +0 -2
  109. package/dist/utils.d.ts +0 -2
  110. package/dist/utils.js +0 -709
  111. package/dist/utils.js.map +0 -1
  112. package/dist/utils.mjs +0 -11
  113. package/dist/utils.mjs.map +0 -1
  114. package/example/.env.example +0 -12
  115. package/example/.eslintrc.json +0 -26
  116. package/example/LICENSE +0 -13
  117. package/example/README.md +0 -12
  118. package/example/app/(chat)/chat/[id]/page.tsx +0 -60
  119. package/example/app/(chat)/layout.tsx +0 -14
  120. package/example/app/(chat)/page.tsx +0 -27
  121. package/example/app/actions.ts +0 -156
  122. package/example/app/globals.css +0 -76
  123. package/example/app/guardrails/page.tsx +0 -26
  124. package/example/app/langchain/page.tsx +0 -27
  125. package/example/app/langchain-rag/page.tsx +0 -28
  126. package/example/app/late-update/page.tsx +0 -27
  127. package/example/app/layout.tsx +0 -64
  128. package/example/app/login/actions.ts +0 -71
  129. package/example/app/login/page.tsx +0 -18
  130. package/example/app/manual/page.tsx +0 -27
  131. package/example/app/new/page.tsx +0 -5
  132. package/example/app/opengraph-image.png +0 -0
  133. package/example/app/share/[id]/page.tsx +0 -58
  134. package/example/app/signup/actions.ts +0 -111
  135. package/example/app/signup/page.tsx +0 -18
  136. package/example/app/twitter-image.png +0 -0
  137. package/example/auth.config.ts +0 -42
  138. package/example/auth.ts +0 -45
  139. package/example/components/button-scroll-to-bottom.tsx +0 -36
  140. package/example/components/chat-history.tsx +0 -49
  141. package/example/components/chat-list.tsx +0 -52
  142. package/example/components/chat-message-actions.tsx +0 -40
  143. package/example/components/chat-message.tsx +0 -80
  144. package/example/components/chat-panel.tsx +0 -139
  145. package/example/components/chat-share-dialog.tsx +0 -95
  146. package/example/components/chat.tsx +0 -84
  147. package/example/components/clear-history.tsx +0 -75
  148. package/example/components/empty-screen.tsx +0 -38
  149. package/example/components/external-link.tsx +0 -29
  150. package/example/components/footer.tsx +0 -19
  151. package/example/components/header.tsx +0 -114
  152. package/example/components/login-button.tsx +0 -42
  153. package/example/components/login-form.tsx +0 -97
  154. package/example/components/markdown.tsx +0 -9
  155. package/example/components/prompt-form.tsx +0 -115
  156. package/example/components/providers.tsx +0 -17
  157. package/example/components/sidebar-actions.tsx +0 -125
  158. package/example/components/sidebar-desktop.tsx +0 -19
  159. package/example/components/sidebar-footer.tsx +0 -16
  160. package/example/components/sidebar-item.tsx +0 -124
  161. package/example/components/sidebar-items.tsx +0 -42
  162. package/example/components/sidebar-list.tsx +0 -38
  163. package/example/components/sidebar-mobile.tsx +0 -31
  164. package/example/components/sidebar-toggle.tsx +0 -24
  165. package/example/components/sidebar.tsx +0 -21
  166. package/example/components/signup-form.tsx +0 -95
  167. package/example/components/stocks/events-skeleton.tsx +0 -31
  168. package/example/components/stocks/events.tsx +0 -30
  169. package/example/components/stocks/index.tsx +0 -36
  170. package/example/components/stocks/message.tsx +0 -134
  171. package/example/components/stocks/spinner.tsx +0 -16
  172. package/example/components/stocks/stock-purchase.tsx +0 -146
  173. package/example/components/stocks/stock-skeleton.tsx +0 -22
  174. package/example/components/stocks/stock.tsx +0 -210
  175. package/example/components/stocks/stocks-skeleton.tsx +0 -9
  176. package/example/components/stocks/stocks.tsx +0 -67
  177. package/example/components/tailwind-indicator.tsx +0 -14
  178. package/example/components/theme-toggle.tsx +0 -31
  179. package/example/components/ui/alert-dialog.tsx +0 -141
  180. package/example/components/ui/badge.tsx +0 -36
  181. package/example/components/ui/button.tsx +0 -57
  182. package/example/components/ui/codeblock.tsx +0 -148
  183. package/example/components/ui/dialog.tsx +0 -122
  184. package/example/components/ui/dropdown-menu.tsx +0 -205
  185. package/example/components/ui/icons.tsx +0 -507
  186. package/example/components/ui/input.tsx +0 -25
  187. package/example/components/ui/label.tsx +0 -26
  188. package/example/components/ui/select.tsx +0 -164
  189. package/example/components/ui/separator.tsx +0 -31
  190. package/example/components/ui/sheet.tsx +0 -140
  191. package/example/components/ui/sonner.tsx +0 -31
  192. package/example/components/ui/switch.tsx +0 -29
  193. package/example/components/ui/textarea.tsx +0 -24
  194. package/example/components/ui/tooltip.tsx +0 -30
  195. package/example/components/user-menu.tsx +0 -53
  196. package/example/components.json +0 -17
  197. package/example/instrumentation.ts +0 -11
  198. package/example/lib/chat/guardrails.tsx +0 -181
  199. package/example/lib/chat/langchain-rag.tsx +0 -191
  200. package/example/lib/chat/langchain.tsx +0 -112
  201. package/example/lib/chat/late-update.tsx +0 -208
  202. package/example/lib/chat/manual.tsx +0 -605
  203. package/example/lib/chat/vercel-ai.tsx +0 -576
  204. package/example/lib/hooks/use-copy-to-clipboard.tsx +0 -33
  205. package/example/lib/hooks/use-enter-submit.tsx +0 -23
  206. package/example/lib/hooks/use-local-storage.ts +0 -24
  207. package/example/lib/hooks/use-scroll-anchor.tsx +0 -86
  208. package/example/lib/hooks/use-sidebar.tsx +0 -60
  209. package/example/lib/hooks/use-streamable-text.ts +0 -25
  210. package/example/lib/types.ts +0 -41
  211. package/example/lib/utils.ts +0 -89
  212. package/example/middleware.ts +0 -8
  213. package/example/next-env.d.ts +0 -5
  214. package/example/next.config.js +0 -16
  215. package/example/package-lock.json +0 -10917
  216. package/example/package.json +0 -84
  217. package/example/pnpm-lock.yaml +0 -5712
  218. package/example/postcss.config.js +0 -6
  219. package/example/prettier.config.cjs +0 -34
  220. package/example/public/apple-touch-icon.png +0 -0
  221. package/example/public/favicon-16x16.png +0 -0
  222. package/example/public/favicon.ico +0 -0
  223. package/example/public/next.svg +0 -1
  224. package/example/public/thirteen.svg +0 -1
  225. package/example/public/vercel.svg +0 -1
  226. package/example/tailwind.config.ts +0 -81
  227. package/example/tsconfig.json +0 -35
  228. package/src/LangWatchExporter.ts +0 -96
  229. package/src/evaluations.ts +0 -219
  230. package/src/index.test.ts +0 -402
  231. package/src/langchain.ts +0 -557
  232. package/src/typeUtils.ts +0 -89
  233. package/src/types.ts +0 -82
  234. package/src/utils.ts +0 -205
  235. /package/src/{server/types → internal/generated/openapi}/.gitkeep +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