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.
- package/.editorconfig +16 -0
- package/LICENSE +7 -0
- package/README.md +268 -1
- package/copy-types.sh +19 -8
- package/examples/langchain/.env.example +2 -0
- package/examples/langchain/README.md +42 -0
- package/examples/langchain/package-lock.json +2930 -0
- package/examples/langchain/package.json +27 -0
- package/examples/langchain/src/cli-markdown.d.ts +137 -0
- package/examples/langchain/src/index.ts +109 -0
- package/examples/langchain/tsconfig.json +25 -0
- package/examples/langgraph/.env.example +2 -0
- package/examples/langgraph/README.md +42 -0
- package/examples/langgraph/package-lock.json +3031 -0
- package/examples/langgraph/package.json +28 -0
- package/examples/langgraph/src/cli-markdown.d.ts +137 -0
- package/examples/langgraph/src/index.ts +196 -0
- package/examples/langgraph/tsconfig.json +25 -0
- package/examples/mastra/.env.example +2 -0
- package/examples/mastra/README.md +57 -0
- package/examples/mastra/package-lock.json +5296 -0
- package/examples/mastra/package.json +32 -0
- package/examples/mastra/src/cli-markdown.d.ts +137 -0
- package/examples/mastra/src/index.ts +120 -0
- package/examples/mastra/src/mastra/agents/weather-agent.ts +30 -0
- package/examples/mastra/src/mastra/index.ts +21 -0
- package/examples/mastra/src/mastra/tools/weather-tool.ts +102 -0
- package/examples/mastra/tsconfig.json +25 -0
- package/examples/vercel-ai/.env.example +2 -0
- package/examples/vercel-ai/README.md +38 -0
- package/examples/vercel-ai/package-lock.json +2571 -0
- package/examples/vercel-ai/package.json +27 -0
- package/examples/vercel-ai/src/cli-markdown.d.ts +137 -0
- package/examples/vercel-ai/src/index.ts +110 -0
- package/examples/vercel-ai/src/instrumentation.ts +9 -0
- package/examples/vercel-ai/tsconfig.json +25 -0
- package/package.json +80 -33
- package/src/__tests__/client-browser.test.ts +92 -0
- package/src/__tests__/client-node.test.ts +76 -0
- package/src/__tests__/client.test.ts +71 -0
- package/src/__tests__/integration/client-browser.test.ts +46 -0
- package/src/__tests__/integration/client-node.test.ts +46 -0
- package/src/client-browser.ts +70 -0
- package/src/client-node.ts +82 -0
- package/src/client-shared.ts +72 -0
- package/src/client.ts +119 -0
- package/src/evaluation/__tests__/record-evaluation.test.ts +112 -0
- package/src/evaluation/__tests__/run-evaluation.test.ts +171 -0
- package/src/evaluation/index.ts +2 -0
- package/src/evaluation/record-evaluation.ts +101 -0
- package/src/evaluation/run-evaluation.ts +133 -0
- package/src/evaluation/tracer.ts +3 -0
- package/src/evaluation/types.ts +23 -0
- package/src/index.ts +10 -591
- package/src/internal/api/__tests__/errors.test.ts +98 -0
- package/src/internal/api/client.ts +30 -0
- package/src/internal/api/errors.ts +32 -0
- package/src/internal/generated/types/.gitkeep +0 -0
- package/src/observability/__tests__/integration/base.test.ts +74 -0
- package/src/observability/__tests__/integration/browser-setup-ordering.test.ts +60 -0
- package/src/observability/__tests__/integration/complex-nested-spans.test.ts +29 -0
- package/src/observability/__tests__/integration/error-handling.test.ts +24 -0
- package/src/observability/__tests__/integration/langwatch-disabled-otel.test.ts +24 -0
- package/src/observability/__tests__/integration/langwatch-first-then-vercel.test.ts +24 -0
- package/src/observability/__tests__/integration/multiple-setup-attempts.test.ts +27 -0
- package/src/observability/__tests__/integration/otel-ordering.test.ts +27 -0
- package/src/observability/__tests__/integration/vercel-configurations.test.ts +20 -0
- package/src/observability/__tests__/integration/vercel-first-then-langwatch.test.ts +27 -0
- package/src/observability/__tests__/span.test.ts +214 -0
- package/src/observability/__tests__/trace.test.ts +180 -0
- package/src/observability/exporters/index.ts +1 -0
- package/src/observability/exporters/langwatch-exporter.ts +53 -0
- package/src/observability/index.ts +4 -0
- package/src/observability/instrumentation/langchain/__tests__/integration/langchain-chatbot.test.ts +112 -0
- package/src/observability/instrumentation/langchain/__tests__/langchain.test.ts +284 -0
- package/src/observability/instrumentation/langchain/index.ts +624 -0
- package/src/observability/processors/__tests__/filterable-batch-span-exporter.test.ts +98 -0
- package/src/observability/processors/filterable-batch-span-processor.ts +99 -0
- package/src/observability/processors/index.ts +1 -0
- package/src/observability/semconv/attributes.ts +185 -0
- package/src/observability/semconv/events.ts +42 -0
- package/src/observability/semconv/index.ts +16 -0
- package/src/observability/semconv/values.ts +159 -0
- package/src/observability/span.ts +728 -0
- package/src/observability/trace.ts +301 -0
- package/src/prompt/__tests__/prompt.test.ts +139 -0
- package/src/prompt/get-prompt-version.ts +49 -0
- package/src/prompt/get-prompt.ts +44 -0
- package/src/prompt/index.ts +3 -0
- package/src/prompt/prompt.ts +133 -0
- package/src/prompt/service.ts +221 -0
- package/src/prompt/tracer.ts +3 -0
- package/src/prompt/types.ts +0 -0
- package/ts-to-zod.config.js +11 -0
- package/tsconfig.json +3 -9
- package/tsup.config.ts +11 -1
- package/vitest.config.ts +1 -0
- package/dist/chunk-FWBCQQYZ.mjs +0 -711
- package/dist/chunk-FWBCQQYZ.mjs.map +0 -1
- package/dist/index.d.mts +0 -1010
- package/dist/index.d.ts +0 -1010
- package/dist/index.js +0 -27294
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -959
- package/dist/index.mjs.map +0 -1
- package/dist/utils-B0pgWcps.d.mts +0 -303
- package/dist/utils-B0pgWcps.d.ts +0 -303
- package/dist/utils.d.mts +0 -2
- package/dist/utils.d.ts +0 -2
- package/dist/utils.js +0 -703
- package/dist/utils.js.map +0 -1
- package/dist/utils.mjs +0 -11
- package/dist/utils.mjs.map +0 -1
- package/example/.env.example +0 -12
- package/example/.eslintrc.json +0 -26
- package/example/LICENSE +0 -13
- package/example/README.md +0 -12
- package/example/app/(chat)/chat/[id]/page.tsx +0 -60
- package/example/app/(chat)/layout.tsx +0 -14
- package/example/app/(chat)/page.tsx +0 -27
- package/example/app/actions.ts +0 -156
- package/example/app/globals.css +0 -76
- package/example/app/guardrails/page.tsx +0 -26
- package/example/app/langchain/page.tsx +0 -27
- package/example/app/langchain-rag/page.tsx +0 -28
- package/example/app/late-update/page.tsx +0 -27
- package/example/app/layout.tsx +0 -64
- package/example/app/login/actions.ts +0 -71
- package/example/app/login/page.tsx +0 -18
- package/example/app/manual/page.tsx +0 -27
- package/example/app/new/page.tsx +0 -5
- package/example/app/opengraph-image.png +0 -0
- package/example/app/share/[id]/page.tsx +0 -58
- package/example/app/signup/actions.ts +0 -111
- package/example/app/signup/page.tsx +0 -18
- package/example/app/twitter-image.png +0 -0
- package/example/auth.config.ts +0 -42
- package/example/auth.ts +0 -45
- package/example/components/button-scroll-to-bottom.tsx +0 -36
- package/example/components/chat-history.tsx +0 -49
- package/example/components/chat-list.tsx +0 -52
- package/example/components/chat-message-actions.tsx +0 -40
- package/example/components/chat-message.tsx +0 -80
- package/example/components/chat-panel.tsx +0 -139
- package/example/components/chat-share-dialog.tsx +0 -95
- package/example/components/chat.tsx +0 -84
- package/example/components/clear-history.tsx +0 -75
- package/example/components/empty-screen.tsx +0 -38
- package/example/components/external-link.tsx +0 -29
- package/example/components/footer.tsx +0 -19
- package/example/components/header.tsx +0 -114
- package/example/components/login-button.tsx +0 -42
- package/example/components/login-form.tsx +0 -97
- package/example/components/markdown.tsx +0 -9
- package/example/components/prompt-form.tsx +0 -115
- package/example/components/providers.tsx +0 -17
- package/example/components/sidebar-actions.tsx +0 -125
- package/example/components/sidebar-desktop.tsx +0 -19
- package/example/components/sidebar-footer.tsx +0 -16
- package/example/components/sidebar-item.tsx +0 -124
- package/example/components/sidebar-items.tsx +0 -42
- package/example/components/sidebar-list.tsx +0 -38
- package/example/components/sidebar-mobile.tsx +0 -31
- package/example/components/sidebar-toggle.tsx +0 -24
- package/example/components/sidebar.tsx +0 -21
- package/example/components/signup-form.tsx +0 -95
- package/example/components/stocks/events-skeleton.tsx +0 -31
- package/example/components/stocks/events.tsx +0 -30
- package/example/components/stocks/index.tsx +0 -36
- package/example/components/stocks/message.tsx +0 -134
- package/example/components/stocks/spinner.tsx +0 -16
- package/example/components/stocks/stock-purchase.tsx +0 -146
- package/example/components/stocks/stock-skeleton.tsx +0 -22
- package/example/components/stocks/stock.tsx +0 -210
- package/example/components/stocks/stocks-skeleton.tsx +0 -9
- package/example/components/stocks/stocks.tsx +0 -67
- package/example/components/tailwind-indicator.tsx +0 -14
- package/example/components/theme-toggle.tsx +0 -31
- package/example/components/ui/alert-dialog.tsx +0 -141
- package/example/components/ui/badge.tsx +0 -36
- package/example/components/ui/button.tsx +0 -57
- package/example/components/ui/codeblock.tsx +0 -148
- package/example/components/ui/dialog.tsx +0 -122
- package/example/components/ui/dropdown-menu.tsx +0 -205
- package/example/components/ui/icons.tsx +0 -507
- package/example/components/ui/input.tsx +0 -25
- package/example/components/ui/label.tsx +0 -26
- package/example/components/ui/select.tsx +0 -164
- package/example/components/ui/separator.tsx +0 -31
- package/example/components/ui/sheet.tsx +0 -140
- package/example/components/ui/sonner.tsx +0 -31
- package/example/components/ui/switch.tsx +0 -29
- package/example/components/ui/textarea.tsx +0 -24
- package/example/components/ui/tooltip.tsx +0 -30
- package/example/components/user-menu.tsx +0 -53
- package/example/components.json +0 -17
- package/example/instrumentation.ts +0 -11
- package/example/lib/chat/guardrails.tsx +0 -181
- package/example/lib/chat/langchain-rag.tsx +0 -191
- package/example/lib/chat/langchain.tsx +0 -112
- package/example/lib/chat/late-update.tsx +0 -208
- package/example/lib/chat/manual.tsx +0 -605
- package/example/lib/chat/vercel-ai.tsx +0 -576
- package/example/lib/hooks/use-copy-to-clipboard.tsx +0 -33
- package/example/lib/hooks/use-enter-submit.tsx +0 -23
- package/example/lib/hooks/use-local-storage.ts +0 -24
- package/example/lib/hooks/use-scroll-anchor.tsx +0 -86
- package/example/lib/hooks/use-sidebar.tsx +0 -60
- package/example/lib/hooks/use-streamable-text.ts +0 -25
- package/example/lib/types.ts +0 -41
- package/example/lib/utils.ts +0 -89
- package/example/middleware.ts +0 -8
- package/example/next-env.d.ts +0 -5
- package/example/next.config.js +0 -16
- package/example/package-lock.json +0 -9990
- package/example/package.json +0 -84
- package/example/pnpm-lock.yaml +0 -5712
- package/example/postcss.config.js +0 -6
- package/example/prettier.config.cjs +0 -34
- package/example/public/apple-touch-icon.png +0 -0
- package/example/public/favicon-16x16.png +0 -0
- package/example/public/favicon.ico +0 -0
- package/example/public/next.svg +0 -1
- package/example/public/thirteen.svg +0 -1
- package/example/public/vercel.svg +0 -1
- package/example/tailwind.config.ts +0 -81
- package/example/tsconfig.json +0 -35
- package/src/LangWatchExporter.ts +0 -91
- package/src/evaluations.ts +0 -219
- package/src/index.test.ts +0 -402
- package/src/langchain.ts +0 -557
- package/src/typeUtils.ts +0 -89
- package/src/types.ts +0 -79
- package/src/utils.ts +0 -205
- /package/src/{server/types → internal/generated/openapi}/.gitkeep +0 -0
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
/** @type {import('prettier').Config} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
endOfLine: 'lf',
|
|
4
|
-
semi: false,
|
|
5
|
-
useTabs: false,
|
|
6
|
-
singleQuote: true,
|
|
7
|
-
arrowParens: 'avoid',
|
|
8
|
-
tabWidth: 2,
|
|
9
|
-
trailingComma: 'none',
|
|
10
|
-
importOrder: [
|
|
11
|
-
'^(react/(.*)$)|^(react$)',
|
|
12
|
-
'^(next/(.*)$)|^(next$)',
|
|
13
|
-
'<THIRD_PARTY_MODULES>',
|
|
14
|
-
'',
|
|
15
|
-
'^types$',
|
|
16
|
-
'^@/types/(.*)$',
|
|
17
|
-
'^@/config/(.*)$',
|
|
18
|
-
'^@/lib/(.*)$',
|
|
19
|
-
'^@/hooks/(.*)$',
|
|
20
|
-
'^@/components/ui/(.*)$',
|
|
21
|
-
'^@/components/(.*)$',
|
|
22
|
-
'^@/registry/(.*)$',
|
|
23
|
-
'^@/styles/(.*)$',
|
|
24
|
-
'^@/app/(.*)$',
|
|
25
|
-
'',
|
|
26
|
-
'^[./]'
|
|
27
|
-
],
|
|
28
|
-
importOrderSeparation: false,
|
|
29
|
-
importOrderSortSpecifiers: true,
|
|
30
|
-
importOrderBuiltinModulesToTop: true,
|
|
31
|
-
importOrderParserPlugins: ['typescript', 'jsx', 'decorators-legacy'],
|
|
32
|
-
importOrderMergeDuplicateImports: true,
|
|
33
|
-
importOrderCombineTypeAndValueImports: true
|
|
34
|
-
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/example/public/next.svg
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" width="40" height="31" fill="none"><g opacity=".9"><path fill="url(#a)" d="M13 .4v29.3H7V6.3h-.2L0 10.5V5L7.2.4H13Z"/><path fill="url(#b)" d="M28.8 30.1c-2.2 0-4-.3-5.7-1-1.7-.8-3-1.8-4-3.1a7.7 7.7 0 0 1-1.4-4.6h6.2c0 .8.3 1.4.7 2 .4.5 1 .9 1.7 1.2.7.3 1.6.4 2.5.4 1 0 1.7-.2 2.5-.5.7-.3 1.3-.8 1.7-1.4.4-.6.6-1.2.6-2s-.2-1.5-.7-2.1c-.4-.6-1-1-1.8-1.4-.8-.4-1.8-.5-2.9-.5h-2.7v-4.6h2.7a6 6 0 0 0 2.5-.5 4 4 0 0 0 1.7-1.3c.4-.6.6-1.3.6-2a3.5 3.5 0 0 0-2-3.3 5.6 5.6 0 0 0-4.5 0 4 4 0 0 0-1.7 1.2c-.4.6-.6 1.2-.6 2h-6c0-1.7.6-3.2 1.5-4.5 1-1.3 2.2-2.3 3.8-3C25 .4 26.8 0 28.8 0s3.8.4 5.3 1.1c1.5.7 2.7 1.7 3.6 3a7.2 7.2 0 0 1 1.2 4.2c0 1.6-.5 3-1.5 4a7 7 0 0 1-4 2.2v.2c2.2.3 3.8 1 5 2.2a6.4 6.4 0 0 1 1.6 4.6c0 1.7-.5 3.1-1.4 4.4a9.7 9.7 0 0 1-4 3.1c-1.7.8-3.7 1.1-5.8 1.1Z"/></g><defs><linearGradient id="a" x1="20" x2="20" y1="0" y2="30.1" gradientUnits="userSpaceOnUse"><stop/><stop offset="1" stop-color="#3D3D3D"/></linearGradient><linearGradient id="b" x1="20" x2="20" y1="0" y2="30.1" gradientUnits="userSpaceOnUse"><stop/><stop offset="1" stop-color="#3D3D3D"/></linearGradient></defs></svg>
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>
|
|
@@ -1,81 +0,0 @@
|
|
|
1
|
-
/** @type {import('tailwindcss').Config} */
|
|
2
|
-
module.exports = {
|
|
3
|
-
darkMode: ['class'],
|
|
4
|
-
content: [
|
|
5
|
-
'./pages/**/*.{ts,tsx}',
|
|
6
|
-
'./components/**/*.{ts,tsx}',
|
|
7
|
-
'./app/**/*.{ts,tsx}',
|
|
8
|
-
'./src/**/*.{ts,tsx}'
|
|
9
|
-
],
|
|
10
|
-
prefix: '',
|
|
11
|
-
theme: {
|
|
12
|
-
container: {
|
|
13
|
-
center: true,
|
|
14
|
-
padding: '2rem',
|
|
15
|
-
screens: {
|
|
16
|
-
'2xl': '1400px'
|
|
17
|
-
}
|
|
18
|
-
},
|
|
19
|
-
extend: {
|
|
20
|
-
fontFamily: {
|
|
21
|
-
sans: ['var(--font-geist-sans)'],
|
|
22
|
-
mono: ['var(--font-geist-mono)']
|
|
23
|
-
},
|
|
24
|
-
colors: {
|
|
25
|
-
border: 'hsl(var(--border))',
|
|
26
|
-
input: 'hsl(var(--input))',
|
|
27
|
-
ring: 'hsl(var(--ring))',
|
|
28
|
-
background: 'hsl(var(--background))',
|
|
29
|
-
foreground: 'hsl(var(--foreground))',
|
|
30
|
-
primary: {
|
|
31
|
-
DEFAULT: 'hsl(var(--primary))',
|
|
32
|
-
foreground: 'hsl(var(--primary-foreground))'
|
|
33
|
-
},
|
|
34
|
-
secondary: {
|
|
35
|
-
DEFAULT: 'hsl(var(--secondary))',
|
|
36
|
-
foreground: 'hsl(var(--secondary-foreground))'
|
|
37
|
-
},
|
|
38
|
-
destructive: {
|
|
39
|
-
DEFAULT: 'hsl(var(--destructive))',
|
|
40
|
-
foreground: 'hsl(var(--destructive-foreground))'
|
|
41
|
-
},
|
|
42
|
-
muted: {
|
|
43
|
-
DEFAULT: 'hsl(var(--muted))',
|
|
44
|
-
foreground: 'hsl(var(--muted-foreground))'
|
|
45
|
-
},
|
|
46
|
-
accent: {
|
|
47
|
-
DEFAULT: 'hsl(var(--accent))',
|
|
48
|
-
foreground: 'hsl(var(--accent-foreground))'
|
|
49
|
-
},
|
|
50
|
-
popover: {
|
|
51
|
-
DEFAULT: 'hsl(var(--popover))',
|
|
52
|
-
foreground: 'hsl(var(--popover-foreground))'
|
|
53
|
-
},
|
|
54
|
-
card: {
|
|
55
|
-
DEFAULT: 'hsl(var(--card))',
|
|
56
|
-
foreground: 'hsl(var(--card-foreground))'
|
|
57
|
-
}
|
|
58
|
-
},
|
|
59
|
-
borderRadius: {
|
|
60
|
-
lg: 'var(--radius)',
|
|
61
|
-
md: 'calc(var(--radius) - 2px)',
|
|
62
|
-
sm: 'calc(var(--radius) - 4px)'
|
|
63
|
-
},
|
|
64
|
-
keyframes: {
|
|
65
|
-
'accordion-down': {
|
|
66
|
-
from: { height: '0' },
|
|
67
|
-
to: { height: 'var(--radix-accordion-content-height)' }
|
|
68
|
-
},
|
|
69
|
-
'accordion-up': {
|
|
70
|
-
from: { height: 'var(--radix-accordion-content-height)' },
|
|
71
|
-
to: { height: '0' }
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
animation: {
|
|
75
|
-
'accordion-down': 'accordion-down 0.2s ease-out',
|
|
76
|
-
'accordion-up': 'accordion-up 0.2s ease-out'
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
},
|
|
80
|
-
plugins: [require('tailwindcss-animate'), require('@tailwindcss/typography')]
|
|
81
|
-
}
|
package/example/tsconfig.json
DELETED
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"lib": ["dom", "dom.iterable", "esnext"],
|
|
4
|
-
"allowJs": true,
|
|
5
|
-
"skipLibCheck": true,
|
|
6
|
-
"strict": true,
|
|
7
|
-
"forceConsistentCasingInFileNames": true,
|
|
8
|
-
"noEmit": true,
|
|
9
|
-
"incremental": true,
|
|
10
|
-
"esModuleInterop": true,
|
|
11
|
-
"module": "esnext",
|
|
12
|
-
"moduleResolution": "node",
|
|
13
|
-
"resolveJsonModule": true,
|
|
14
|
-
"isolatedModules": true,
|
|
15
|
-
"jsx": "preserve",
|
|
16
|
-
"baseUrl": ".",
|
|
17
|
-
"paths": {
|
|
18
|
-
"@/*": ["./*"]
|
|
19
|
-
},
|
|
20
|
-
"plugins": [
|
|
21
|
-
{
|
|
22
|
-
"name": "next"
|
|
23
|
-
}
|
|
24
|
-
],
|
|
25
|
-
"strictNullChecks": true
|
|
26
|
-
},
|
|
27
|
-
"include": [
|
|
28
|
-
"next-env.d.ts",
|
|
29
|
-
"next-auth.d.ts",
|
|
30
|
-
"**/*.ts",
|
|
31
|
-
"**/*.tsx",
|
|
32
|
-
".next/types/**/*.ts"
|
|
33
|
-
],
|
|
34
|
-
"exclude": ["node_modules"]
|
|
35
|
-
}
|
package/src/LangWatchExporter.ts
DELETED
|
@@ -1,91 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type ReadableSpan,
|
|
3
|
-
type SpanExporter,
|
|
4
|
-
} from "@opentelemetry/sdk-trace-base";
|
|
5
|
-
import { createExportTraceServiceRequest } from "@opentelemetry/otlp-transformer";
|
|
6
|
-
|
|
7
|
-
import { type ExportResult, ExportResultCode } from "@opentelemetry/core";
|
|
8
|
-
|
|
9
|
-
export class LangWatchExporter implements SpanExporter {
|
|
10
|
-
private endpoint: string;
|
|
11
|
-
private apiKey: string;
|
|
12
|
-
private includeAllSpans: boolean;
|
|
13
|
-
private debug: boolean;
|
|
14
|
-
|
|
15
|
-
constructor(
|
|
16
|
-
params: {
|
|
17
|
-
endpoint?: string;
|
|
18
|
-
apiKey?: string;
|
|
19
|
-
includeAllSpans?: boolean;
|
|
20
|
-
debug?: boolean;
|
|
21
|
-
} = {}
|
|
22
|
-
) {
|
|
23
|
-
this.endpoint =
|
|
24
|
-
params.endpoint ??
|
|
25
|
-
process.env.LANGWATCH_ENDPOINT ??
|
|
26
|
-
"https://app.langwatch.ai";
|
|
27
|
-
this.apiKey = params.apiKey ?? process.env.LANGWATCH_API_KEY ?? "";
|
|
28
|
-
this.includeAllSpans = params.includeAllSpans ?? false;
|
|
29
|
-
this.debug = params.debug ?? false;
|
|
30
|
-
|
|
31
|
-
if (!this.apiKey) {
|
|
32
|
-
throw new Error("LANGWATCH_API_KEY is not set");
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
export(
|
|
37
|
-
allSpans: ReadableSpan[],
|
|
38
|
-
resultCallback: (result: ExportResult) => void
|
|
39
|
-
): void {
|
|
40
|
-
const spans = allSpans.filter(
|
|
41
|
-
(span) => this.includeAllSpans || this.isAiSdkSpan(span)
|
|
42
|
-
);
|
|
43
|
-
if (spans.length === 0) {
|
|
44
|
-
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
if (this.debug) {
|
|
48
|
-
console.log("[LangWatchExporter] Exporting spans:", spans);
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
let body;
|
|
52
|
-
try {
|
|
53
|
-
body = JSON.stringify(createExportTraceServiceRequest(spans));
|
|
54
|
-
} catch (error) {
|
|
55
|
-
console.error("[LangWatchExporter] Failed to serialize spans:", error);
|
|
56
|
-
resultCallback({ code: ExportResultCode.FAILED });
|
|
57
|
-
return;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
fetch(`${this.endpoint}/api/otel/v1/traces`, {
|
|
61
|
-
method: "POST",
|
|
62
|
-
headers: {
|
|
63
|
-
"Content-Type": "application/json",
|
|
64
|
-
Authorization: `Bearer ${this.apiKey}`,
|
|
65
|
-
},
|
|
66
|
-
body,
|
|
67
|
-
})
|
|
68
|
-
.then((response) => {
|
|
69
|
-
if (!response.ok) {
|
|
70
|
-
resultCallback({ code: ExportResultCode.FAILED });
|
|
71
|
-
return;
|
|
72
|
-
}
|
|
73
|
-
resultCallback({ code: ExportResultCode.SUCCESS });
|
|
74
|
-
})
|
|
75
|
-
.catch((error) => {
|
|
76
|
-
console.error("[LangWatchExporter] Failed to export spans:", error);
|
|
77
|
-
resultCallback({
|
|
78
|
-
code: ExportResultCode.FAILED,
|
|
79
|
-
error: error instanceof Error ? error : new Error("Unknown error"),
|
|
80
|
-
});
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
private isAiSdkSpan(span: ReadableSpan): boolean {
|
|
85
|
-
return span.instrumentationLibrary.name === "ai";
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
shutdown(): Promise<void> {
|
|
89
|
-
return Promise.resolve();
|
|
90
|
-
}
|
|
91
|
-
}
|
package/src/evaluations.ts
DELETED
|
@@ -1,219 +0,0 @@
|
|
|
1
|
-
import { type LangWatchSpan, type LangWatchTrace } from "./index";
|
|
2
|
-
import { type Conversation } from "./server/types/evaluations";
|
|
3
|
-
import {
|
|
4
|
-
type Evaluators,
|
|
5
|
-
type EvaluatorTypes,
|
|
6
|
-
} from "./server/types/evaluators.generated";
|
|
7
|
-
import {
|
|
8
|
-
type RAGChunk,
|
|
9
|
-
type SpanTypes,
|
|
10
|
-
type TypedValueEvaluationResult,
|
|
11
|
-
type TypedValueGuardrailResult,
|
|
12
|
-
type TypedValueJson,
|
|
13
|
-
} from "./server/types/tracer";
|
|
14
|
-
|
|
15
|
-
type Money = {
|
|
16
|
-
currency: string;
|
|
17
|
-
amount: number;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
export type EvaluationResultModel = {
|
|
21
|
-
status: "processed" | "skipped" | "error";
|
|
22
|
-
passed?: boolean;
|
|
23
|
-
score?: number;
|
|
24
|
-
details?: string;
|
|
25
|
-
label?: string;
|
|
26
|
-
cost?: Money;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type CommonEvaluationParams = {
|
|
30
|
-
name?: string;
|
|
31
|
-
input?: string;
|
|
32
|
-
output?: string;
|
|
33
|
-
expectedOutput?: string;
|
|
34
|
-
contexts?: RAGChunk[] | string[];
|
|
35
|
-
conversation?: Conversation;
|
|
36
|
-
asGuardrail?: boolean;
|
|
37
|
-
trace?: LangWatchTrace;
|
|
38
|
-
span?: LangWatchSpan;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
export type SavedEvaluationParams = {
|
|
42
|
-
slug: string;
|
|
43
|
-
settings?: Record<string, unknown>;
|
|
44
|
-
} & CommonEvaluationParams;
|
|
45
|
-
|
|
46
|
-
export type LangEvalsEvaluationParams<T extends EvaluatorTypes> = {
|
|
47
|
-
evaluator: T;
|
|
48
|
-
settings?: Evaluators[T]["settings"];
|
|
49
|
-
} & CommonEvaluationParams;
|
|
50
|
-
|
|
51
|
-
export type EvaluationParams =
|
|
52
|
-
| SavedEvaluationParams
|
|
53
|
-
| LangEvalsEvaluationParams<EvaluatorTypes>;
|
|
54
|
-
|
|
55
|
-
export const evaluate = async (
|
|
56
|
-
params: EvaluationParams
|
|
57
|
-
): Promise<EvaluationResultModel> => {
|
|
58
|
-
const slug = "slug" in params ? params.slug : params.evaluator;
|
|
59
|
-
const span = optionalCreateSpan({
|
|
60
|
-
trace: params.trace,
|
|
61
|
-
span: params.span,
|
|
62
|
-
name: params.name ? params.name : slug,
|
|
63
|
-
type: params.asGuardrail ? "guardrail" : "evaluation",
|
|
64
|
-
});
|
|
65
|
-
|
|
66
|
-
try {
|
|
67
|
-
const requestParams = prepareData({
|
|
68
|
-
...params,
|
|
69
|
-
slug,
|
|
70
|
-
traceId: span?.trace.traceId,
|
|
71
|
-
spanId: span?.spanId,
|
|
72
|
-
span,
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
const response = await fetch(requestParams.url, {
|
|
76
|
-
method: "POST",
|
|
77
|
-
headers: requestParams.headers,
|
|
78
|
-
body: JSON.stringify(requestParams.json),
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
if (!response.ok) {
|
|
82
|
-
throw new Error(`HTTP error! status: ${response.status}`);
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
const result = await response.json();
|
|
86
|
-
return handleResponse(result, span, params.asGuardrail);
|
|
87
|
-
} catch (e) {
|
|
88
|
-
return handleException(e as Error, span, params.asGuardrail);
|
|
89
|
-
}
|
|
90
|
-
};
|
|
91
|
-
|
|
92
|
-
const optionalCreateSpan = ({
|
|
93
|
-
trace,
|
|
94
|
-
span,
|
|
95
|
-
name,
|
|
96
|
-
type,
|
|
97
|
-
}: {
|
|
98
|
-
trace?: LangWatchTrace;
|
|
99
|
-
span?: LangWatchSpan;
|
|
100
|
-
name: string;
|
|
101
|
-
type: SpanTypes;
|
|
102
|
-
}): LangWatchSpan | undefined => {
|
|
103
|
-
if (span) {
|
|
104
|
-
return span.startSpan({ name, type });
|
|
105
|
-
} else if (trace) {
|
|
106
|
-
return trace.startSpan({ name, type });
|
|
107
|
-
}
|
|
108
|
-
return undefined;
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
const prepareData = (params: {
|
|
112
|
-
slug: string;
|
|
113
|
-
name?: string;
|
|
114
|
-
input?: string;
|
|
115
|
-
output?: string;
|
|
116
|
-
expectedOutput?: string;
|
|
117
|
-
contexts?: RAGChunk[] | string[];
|
|
118
|
-
conversation?: Conversation;
|
|
119
|
-
settings?: Record<string, unknown>;
|
|
120
|
-
traceId?: string;
|
|
121
|
-
spanId?: string;
|
|
122
|
-
span?: LangWatchSpan;
|
|
123
|
-
asGuardrail?: boolean;
|
|
124
|
-
}) => {
|
|
125
|
-
const data: Record<string, unknown> = {};
|
|
126
|
-
if (params.input) data.input = params.input;
|
|
127
|
-
if (params.output) data.output = params.output;
|
|
128
|
-
if (params.expectedOutput) data.expected_output = params.expectedOutput;
|
|
129
|
-
if (params.contexts && params.contexts.length > 0)
|
|
130
|
-
data.contexts = params.contexts;
|
|
131
|
-
if (params.conversation && params.conversation.length > 0)
|
|
132
|
-
data.conversation = params.conversation;
|
|
133
|
-
|
|
134
|
-
if (params.span) {
|
|
135
|
-
params.span.update({
|
|
136
|
-
input: { type: "json", value: data } as TypedValueJson,
|
|
137
|
-
params: params.settings,
|
|
138
|
-
});
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
return {
|
|
142
|
-
url: `${process.env.LANGWATCH_ENDPOINT}/api/evaluations/${params.slug}/evaluate`,
|
|
143
|
-
json: {
|
|
144
|
-
trace_id: params.traceId,
|
|
145
|
-
span_id: params.spanId,
|
|
146
|
-
name: params.name,
|
|
147
|
-
data,
|
|
148
|
-
settings: params.settings,
|
|
149
|
-
as_guardrail: params.asGuardrail,
|
|
150
|
-
},
|
|
151
|
-
headers: {
|
|
152
|
-
"X-Auth-Token": process.env.LANGWATCH_API_KEY ?? "",
|
|
153
|
-
"Content-Type": "application/json",
|
|
154
|
-
},
|
|
155
|
-
};
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const handleResponse = (
|
|
159
|
-
response: EvaluationResultModel,
|
|
160
|
-
span?: LangWatchSpan,
|
|
161
|
-
asGuardrail = false
|
|
162
|
-
): EvaluationResultModel => {
|
|
163
|
-
if (response.status === "error") {
|
|
164
|
-
response.details = response.details ?? "";
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
for (const key of Object.keys(response)) {
|
|
168
|
-
if (
|
|
169
|
-
response[key as keyof EvaluationResultModel] === null ||
|
|
170
|
-
response[key as keyof EvaluationResultModel] === undefined
|
|
171
|
-
) {
|
|
172
|
-
delete response[key as keyof EvaluationResultModel];
|
|
173
|
-
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (span) {
|
|
177
|
-
const output: TypedValueGuardrailResult | TypedValueEvaluationResult =
|
|
178
|
-
asGuardrail
|
|
179
|
-
? {
|
|
180
|
-
type: "guardrail_result",
|
|
181
|
-
value: response,
|
|
182
|
-
}
|
|
183
|
-
: {
|
|
184
|
-
type: "evaluation_result",
|
|
185
|
-
value: response,
|
|
186
|
-
};
|
|
187
|
-
|
|
188
|
-
span.update({ output });
|
|
189
|
-
|
|
190
|
-
if (response.cost) {
|
|
191
|
-
span.update({
|
|
192
|
-
metrics: {
|
|
193
|
-
cost: response.cost.amount,
|
|
194
|
-
},
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
|
|
198
|
-
span.end();
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
return response;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
const handleException = (
|
|
205
|
-
e: Error,
|
|
206
|
-
span?: LangWatchSpan,
|
|
207
|
-
asGuardrail = false
|
|
208
|
-
): EvaluationResultModel => {
|
|
209
|
-
const response: EvaluationResultModel = {
|
|
210
|
-
status: "error",
|
|
211
|
-
details: e.toString(),
|
|
212
|
-
};
|
|
213
|
-
|
|
214
|
-
if (asGuardrail) {
|
|
215
|
-
response.passed = true;
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return handleResponse(response, span, asGuardrail);
|
|
219
|
-
};
|