langwatch 0.1.7 → 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 +80 -33
  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 -591
  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-FWBCQQYZ.mjs +0 -711
  99. package/dist/chunk-FWBCQQYZ.mjs.map +0 -1
  100. package/dist/index.d.mts +0 -1010
  101. package/dist/index.d.ts +0 -1010
  102. package/dist/index.js +0 -27294
  103. package/dist/index.js.map +0 -1
  104. package/dist/index.mjs +0 -959
  105. package/dist/index.mjs.map +0 -1
  106. package/dist/utils-B0pgWcps.d.mts +0 -303
  107. package/dist/utils-B0pgWcps.d.ts +0 -303
  108. package/dist/utils.d.mts +0 -2
  109. package/dist/utils.d.ts +0 -2
  110. package/dist/utils.js +0 -703
  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 -9990
  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 -91
  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 -79
  234. package/src/utils.ts +0 -205
  235. /package/src/{server/types → internal/generated/openapi}/.gitkeep +0 -0
@@ -1,711 +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
- type: z.literal("image_url"),
197
- image_url: z.object({
198
- url: z.string(),
199
- detail: z.union([z.literal("auto"), z.literal("low"), z.literal("high")]).optional()
200
- }).optional()
201
- }),
202
- z.object({
203
- type: z.literal("tool_call"),
204
- toolName: z.string().optional(),
205
- toolCallId: z.string().optional(),
206
- args: z.string().optional()
207
- }),
208
- z.object({
209
- type: z.literal("tool_result"),
210
- toolName: z.string().optional(),
211
- toolCallId: z.string().optional(),
212
- result: z.any().optional()
213
- })
214
- ]);
215
- var typedValueTextSchema = z.object({
216
- type: z.literal("text"),
217
- value: z.string()
218
- });
219
- var typedValueRawSchema = z.object({
220
- type: z.literal("raw"),
221
- value: z.string()
222
- });
223
- var jSONSerializableSchema = z.union([
224
- z.string(),
225
- z.number(),
226
- z.boolean(),
227
- z.record(z.any()),
228
- z.array(z.any())
229
- ]).nullable();
230
- var typedValueJsonSchema = z.object({
231
- type: z.literal("json"),
232
- value: jSONSerializableSchema
233
- });
234
- var moneySchema = z.object({
235
- currency: z.string(),
236
- amount: z.number()
237
- });
238
- var evaluationResultSchema = z.object({
239
- status: z.union([
240
- z.literal("processed"),
241
- z.literal("skipped"),
242
- z.literal("error")
243
- ]),
244
- passed: z.boolean().optional().nullable(),
245
- score: z.number().optional().nullable(),
246
- label: z.string().optional().nullable(),
247
- details: z.string().optional().nullable(),
248
- cost: moneySchema.optional().nullable()
249
- });
250
- var typedValueGuardrailResultSchema = z.object({
251
- type: z.literal("guardrail_result"),
252
- value: evaluationResultSchema
253
- });
254
- var typedValueEvaluationResultSchema = z.object({
255
- type: z.literal("evaluation_result"),
256
- value: evaluationResultSchema
257
- });
258
- var errorCaptureSchema = z.object({
259
- has_error: z.literal(true),
260
- message: z.string(),
261
- stacktrace: z.array(z.string())
262
- });
263
- var spanMetricsSchema = z.object({
264
- prompt_tokens: z.number().optional().nullable(),
265
- completion_tokens: z.number().optional().nullable(),
266
- tokens_estimated: z.boolean().optional().nullable(),
267
- cost: z.number().optional().nullable()
268
- });
269
- var reservedSpanParamsSchema = z.object({
270
- frequency_penalty: z.number().optional().nullable(),
271
- logit_bias: z.record(z.number()).optional().nullable(),
272
- logprobs: z.boolean().optional().nullable(),
273
- top_logprobs: z.number().optional().nullable(),
274
- max_tokens: z.number().optional().nullable(),
275
- n: z.number().optional().nullable(),
276
- presence_penalty: z.number().optional().nullable(),
277
- seed: z.number().optional().nullable(),
278
- stop: z.union([z.string(), z.array(z.string())]).optional().nullable(),
279
- stream: z.boolean().optional().nullable(),
280
- temperature: z.number().optional().nullable(),
281
- top_p: z.number().optional().nullable(),
282
- tools: z.array(z.record(z.any())).optional().nullable(),
283
- tool_choice: z.union([z.record(z.any()), z.string()]).optional().nullable(),
284
- parallel_tool_calls: z.boolean().optional().nullable(),
285
- functions: z.array(z.record(z.any())).optional().nullable(),
286
- user: z.string().optional().nullable()
287
- });
288
- var spanParamsSchema = reservedSpanParamsSchema.and(z.record(z.any()));
289
- var spanTimestampsSchema = z.object({
290
- started_at: z.number(),
291
- first_token_at: z.number().optional().nullable(),
292
- finished_at: z.number()
293
- });
294
- var spanTypesSchema = z.union([
295
- z.literal("span"),
296
- z.literal("llm"),
297
- z.literal("chain"),
298
- z.literal("tool"),
299
- z.literal("agent"),
300
- z.literal("rag"),
301
- z.literal("guardrail"),
302
- z.literal("evaluation"),
303
- z.literal("workflow"),
304
- z.literal("component"),
305
- z.literal("module"),
306
- z.literal("server"),
307
- z.literal("client"),
308
- z.literal("producer"),
309
- z.literal("consumer"),
310
- z.literal("task"),
311
- z.literal("unknown")
312
- ]);
313
- var traceInputSchema = z.object({
314
- value: z.string(),
315
- satisfaction_score: z.number().optional()
316
- });
317
- var traceOutputSchema = z.object({
318
- value: z.string()
319
- });
320
- var primitiveTypeSchema = z.union([z.string(), z.number(), z.boolean(), z.undefined()]).nullable();
321
- var reservedTraceMetadataSchema = z.object({
322
- thread_id: z.string().optional().nullable(),
323
- user_id: z.string().optional().nullable(),
324
- customer_id: z.string().optional().nullable(),
325
- labels: z.array(z.string()).optional().nullable(),
326
- topic_id: z.string().optional().nullable(),
327
- subtopic_id: z.string().optional().nullable(),
328
- sdk_version: z.string().optional().nullable(),
329
- sdk_language: z.string().optional().nullable()
330
- });
331
- var customMetadataSchema = z.record(
332
- z.union([
333
- primitiveTypeSchema,
334
- z.array(primitiveTypeSchema),
335
- z.record(primitiveTypeSchema),
336
- z.record(z.record(primitiveTypeSchema))
337
- ])
338
- );
339
- var traceMetadataSchema = reservedTraceMetadataSchema.and(customMetadataSchema);
340
- var eventSchema = z.object({
341
- event_id: z.string(),
342
- event_type: z.string(),
343
- project_id: z.string(),
344
- metrics: z.record(z.number()),
345
- event_details: z.record(z.string()),
346
- trace_id: z.string(),
347
- timestamps: z.object({
348
- started_at: z.number(),
349
- inserted_at: z.number(),
350
- updated_at: z.number()
351
- })
352
- });
353
- var elasticSearchEventSchema = eventSchema.omit({ metrics: true, event_details: true }).and(
354
- z.object({
355
- metrics: z.array(
356
- z.object({
357
- key: z.string(),
358
- value: z.number()
359
- })
360
- ),
361
- event_details: z.array(
362
- z.object({
363
- key: z.string(),
364
- value: z.string()
365
- })
366
- )
367
- })
368
- );
369
- var evaluationStatusSchema = z.union([
370
- z.literal("scheduled"),
371
- z.literal("in_progress"),
372
- z.literal("error"),
373
- z.literal("skipped"),
374
- z.literal("processed")
375
- ]);
376
- var trackEventRESTParamsValidatorSchema = eventSchema.omit({
377
- event_id: true,
378
- project_id: true,
379
- timestamps: true,
380
- event_details: true
381
- }).and(
382
- z.object({
383
- event_id: z.string().optional(),
384
- event_details: z.record(z.string()).optional(),
385
- timestamp: z.number().optional()
386
- })
387
- );
388
- var contextsSchema = z.object({
389
- traceId: z.string(),
390
- contexts: z.array(rAGChunkSchema)
391
- });
392
- var chatMessageSchema = z.object({
393
- role: chatRoleSchema.optional(),
394
- content: z.union([z.string(), z.array(chatRichContentSchema)]).optional().nullable(),
395
- function_call: functionCallSchema.optional().nullable(),
396
- tool_calls: z.array(toolCallSchema).optional().nullable(),
397
- tool_call_id: z.string().optional().nullable(),
398
- name: z.string().optional().nullable()
399
- });
400
- var typedValueChatMessagesSchema = z.object({
401
- type: z.literal("chat_messages"),
402
- value: z.array(chatMessageSchema)
403
- });
404
- var spanInputOutputSchema = z.lazy(
405
- () => z.union([
406
- typedValueTextSchema,
407
- typedValueChatMessagesSchema,
408
- typedValueGuardrailResultSchema,
409
- typedValueEvaluationResultSchema,
410
- typedValueJsonSchema,
411
- typedValueRawSchema,
412
- z.object({
413
- type: z.literal("list"),
414
- value: z.array(spanInputOutputSchema)
415
- })
416
- ])
417
- );
418
- var baseSpanSchema = z.object({
419
- span_id: z.string(),
420
- parent_id: z.string().optional().nullable(),
421
- trace_id: z.string(),
422
- type: spanTypesSchema,
423
- name: z.string().optional().nullable(),
424
- input: spanInputOutputSchema.optional().nullable(),
425
- output: spanInputOutputSchema.optional().nullable(),
426
- error: errorCaptureSchema.optional().nullable(),
427
- timestamps: spanTimestampsSchema,
428
- metrics: spanMetricsSchema.optional().nullable(),
429
- params: spanParamsSchema.optional().nullable()
430
- });
431
- var lLMSpanSchema = baseSpanSchema.extend({
432
- type: z.literal("llm"),
433
- vendor: z.string().optional().nullable(),
434
- model: z.string().optional().nullable()
435
- });
436
- var rAGSpanSchema = baseSpanSchema.extend({
437
- type: z.literal("rag"),
438
- contexts: z.array(rAGChunkSchema)
439
- });
440
- var spanSchema = z.union([
441
- lLMSpanSchema,
442
- rAGSpanSchema,
443
- baseSpanSchema
444
- ]);
445
- var spanInputOutputValidatorSchema = spanInputOutputSchema.and(
446
- z.object({
447
- value: z.any()
448
- })
449
- );
450
- var spanValidatorSchema = z.union([
451
- lLMSpanSchema.omit({ input: true, output: true, params: true }),
452
- rAGSpanSchema.omit({ input: true, output: true, params: true }),
453
- baseSpanSchema.omit({ input: true, output: true, params: true })
454
- ]).and(
455
- z.object({
456
- input: spanInputOutputValidatorSchema.optional().nullable(),
457
- output: spanInputOutputValidatorSchema.optional().nullable(),
458
- params: z.record(z.any()).optional().nullable()
459
- })
460
- );
461
- var evaluationSchema = z.object({
462
- evaluation_id: z.string(),
463
- evaluator_id: z.string(),
464
- span_id: z.string().optional().nullable(),
465
- name: z.string(),
466
- type: z.string().optional().nullable(),
467
- is_guardrail: z.boolean().optional().nullable(),
468
- status: evaluationStatusSchema,
469
- passed: z.boolean().optional().nullable(),
470
- score: z.number().optional().nullable(),
471
- label: z.string().optional().nullable(),
472
- details: z.string().optional().nullable(),
473
- error: errorCaptureSchema.optional().nullable(),
474
- retries: z.number().optional().nullable(),
475
- timestamps: z.object({
476
- inserted_at: z.number().optional().nullable(),
477
- started_at: z.number().optional().nullable(),
478
- finished_at: z.number().optional().nullable(),
479
- updated_at: z.number().optional().nullable()
480
- })
481
- });
482
- var rESTEvaluationSchema = evaluationSchema.omit({
483
- evaluation_id: true,
484
- evaluator_id: true,
485
- status: true,
486
- timestamps: true,
487
- retries: true
488
- }).and(
489
- z.object({
490
- evaluation_id: z.string().optional().nullable(),
491
- evaluator_id: z.string().optional().nullable(),
492
- status: z.union([
493
- z.literal("processed"),
494
- z.literal("skipped"),
495
- z.literal("error")
496
- ]).optional().nullable(),
497
- timestamps: z.object({
498
- started_at: z.number().optional().nullable(),
499
- finished_at: z.number().optional().nullable()
500
- }).optional().nullable()
501
- })
502
- );
503
- var collectorRESTParamsSchema = z.object({
504
- trace_id: z.union([z.string(), z.undefined()]).optional().nullable(),
505
- spans: z.array(spanSchema),
506
- metadata: z.object({
507
- user_id: z.union([z.string(), z.undefined()]).optional().nullable(),
508
- thread_id: z.union([z.string(), z.undefined()]).optional().nullable(),
509
- customer_id: z.union([z.string(), z.undefined()]).optional().nullable(),
510
- labels: z.union([z.array(z.string()), z.undefined()]).optional().nullable(),
511
- sdk_version: z.union([z.string(), z.undefined()]).optional().nullable(),
512
- sdk_language: z.union([z.string(), z.undefined()]).optional().nullable()
513
- }).and(customMetadataSchema).optional(),
514
- expected_output: z.string().optional().nullable(),
515
- evaluations: z.array(rESTEvaluationSchema).optional()
516
- });
517
- var collectorRESTParamsValidatorSchema = collectorRESTParamsSchema.omit({ spans: true });
518
- var traceSchema = z.object({
519
- trace_id: z.string(),
520
- project_id: z.string(),
521
- metadata: traceMetadataSchema,
522
- timestamps: z.object({
523
- started_at: z.number(),
524
- inserted_at: z.number(),
525
- updated_at: z.number()
526
- }),
527
- input: traceInputSchema.optional(),
528
- output: traceOutputSchema.optional(),
529
- contexts: z.array(rAGChunkSchema).optional(),
530
- expected_output: z.object({
531
- value: z.string()
532
- }).optional(),
533
- metrics: z.object({
534
- first_token_ms: z.number().optional().nullable(),
535
- total_time_ms: z.number().optional().nullable(),
536
- prompt_tokens: z.number().optional().nullable(),
537
- completion_tokens: z.number().optional().nullable(),
538
- total_cost: z.number().optional().nullable(),
539
- tokens_estimated: z.boolean().optional().nullable()
540
- }).optional(),
541
- error: errorCaptureSchema.optional().nullable(),
542
- indexing_md5s: z.array(z.string()).optional(),
543
- events: z.array(eventSchema).optional(),
544
- evaluations: z.array(evaluationSchema).optional()
545
- });
546
- var traceWithSpansSchema = traceSchema.and(
547
- z.object({
548
- spans: z.array(spanSchema)
549
- })
550
- );
551
-
552
- // src/utils.ts
553
- var convertImageToUrl = (image, mimeType) => {
554
- try {
555
- return image instanceof URL ? image.toString() : typeof image === "string" ? image : `data:${mimeType != null ? mimeType : "image/jpeg"};base64,${convertUint8ArrayToBase64(
556
- image
557
- )}`;
558
- } catch (e) {
559
- console.error("[LangWatch] error converting vercel ui image to url:", e);
560
- return "";
561
- }
562
- };
563
- function convertFromVercelAIMessages(messages) {
564
- var _a;
565
- const lwMessages = [];
566
- for (const { role, content } of messages) {
567
- switch (role) {
568
- case "system": {
569
- lwMessages.push({ role: "system", content });
570
- break;
571
- }
572
- case "user": {
573
- if (Array.isArray(content) && content.length === 1 && ((_a = content[0]) == null ? void 0 : _a.type) === "text") {
574
- lwMessages.push({ role: "user", content: content[0].text });
575
- break;
576
- }
577
- lwMessages.push({
578
- role: "user",
579
- content: Array.isArray(content) ? content.map((part) => {
580
- switch (part.type) {
581
- case "text": {
582
- return { type: "text", text: part.text };
583
- }
584
- case "image": {
585
- return {
586
- type: "image_url",
587
- image_url: {
588
- url: convertImageToUrl(part.image, part.mimeType)
589
- }
590
- };
591
- }
592
- default: {
593
- return part;
594
- }
595
- }
596
- }) : content
597
- });
598
- break;
599
- }
600
- case "assistant": {
601
- let text = "";
602
- const toolCalls = [];
603
- if (Array.isArray(content)) {
604
- for (const part of content) {
605
- switch (part.type) {
606
- case "text": {
607
- text += part.text;
608
- break;
609
- }
610
- case "tool-call": {
611
- toolCalls.push({
612
- id: part.toolCallId,
613
- type: "function",
614
- function: {
615
- name: part.toolName,
616
- arguments: JSON.stringify(part.args)
617
- }
618
- });
619
- break;
620
- }
621
- default: {
622
- const _exhaustiveCheck = part;
623
- throw new Error(`Unsupported part: ${_exhaustiveCheck}`);
624
- }
625
- }
626
- }
627
- } else {
628
- text = content;
629
- }
630
- lwMessages.push({
631
- role: "assistant",
632
- content: text,
633
- tool_calls: toolCalls.length > 0 ? toolCalls : void 0
634
- });
635
- break;
636
- }
637
- case "tool": {
638
- for (const toolResponse of content) {
639
- lwMessages.push({
640
- role: "tool",
641
- tool_call_id: toolResponse.toolCallId,
642
- content: JSON.stringify(toolResponse.result)
643
- });
644
- }
645
- break;
646
- }
647
- default: {
648
- const _exhaustiveCheck = role;
649
- throw new Error(`Unsupported role: ${_exhaustiveCheck}`);
650
- }
651
- }
652
- }
653
- return lwMessages;
654
- }
655
- var captureError = (error) => {
656
- if (error && typeof error === "object" && "has_error" in error && "message" in error && "stacktrace" in error) {
657
- return error;
658
- } else if (error instanceof Error) {
659
- return {
660
- has_error: true,
661
- message: error.message,
662
- stacktrace: error.stack ? error.stack.split("\n") : []
663
- };
664
- } else if (typeof error === "object" && error !== null) {
665
- const err = error;
666
- const message = typeof err.message === "string" ? err.message : "An unknown error occurred";
667
- 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"];
668
- return {
669
- has_error: true,
670
- message,
671
- stacktrace
672
- };
673
- } else {
674
- return {
675
- has_error: true,
676
- message: String(error),
677
- stacktrace: []
678
- };
679
- }
680
- };
681
- var autoconvertTypedValues = (value) => {
682
- if (typeof value === "string") {
683
- return { type: "text", value };
684
- }
685
- const chatMessages = z2.array(chatMessageSchema).safeParse(value);
686
- if (Array.isArray(value) && chatMessages.success) {
687
- return {
688
- type: "chat_messages",
689
- value: chatMessages.data
690
- };
691
- }
692
- try {
693
- JSON.stringify(value);
694
- return { type: "json", value };
695
- } catch (e) {
696
- return { type: "raw", value };
697
- }
698
- };
699
-
700
- export {
701
- __spreadValues,
702
- __spreadProps,
703
- reservedSpanParamsSchema,
704
- reservedTraceMetadataSchema,
705
- spanSchema,
706
- collectorRESTParamsSchema,
707
- convertFromVercelAIMessages,
708
- captureError,
709
- autoconvertTypedValues
710
- };
711
- //# sourceMappingURL=chunk-FWBCQQYZ.mjs.map