langwatch 0.0.3 → 0.1.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 (40) hide show
  1. package/dist/{chunk-AP23NJ57.mjs → chunk-OVS4NSDE.mjs} +373 -2
  2. package/dist/chunk-OVS4NSDE.mjs.map +1 -0
  3. package/dist/index.d.mts +47 -5
  4. package/dist/index.d.ts +47 -5
  5. package/dist/index.js +6275 -485
  6. package/dist/index.js.map +1 -1
  7. package/dist/index.mjs +329 -349
  8. package/dist/index.mjs.map +1 -1
  9. package/dist/{utils-Dg5eWsAz.d.mts → utils-K-jSEpnZ.d.mts} +11 -7
  10. package/dist/{utils-Dg5eWsAz.d.ts → utils-K-jSEpnZ.d.ts} +11 -7
  11. package/dist/utils.d.mts +1 -1
  12. package/dist/utils.d.ts +1 -1
  13. package/dist/utils.js +370 -0
  14. package/dist/utils.js.map +1 -1
  15. package/dist/utils.mjs +3 -1
  16. package/example/README.md +3 -1
  17. package/example/app/(chat)/chat/[id]/page.tsx +1 -1
  18. package/example/app/(chat)/page.tsx +10 -5
  19. package/example/app/langchain/page.tsx +27 -0
  20. package/example/app/langchain-rag/page.tsx +28 -0
  21. package/example/app/share/[id]/page.tsx +1 -1
  22. package/example/components/chat-list.tsx +1 -1
  23. package/example/components/chat-panel.tsx +1 -1
  24. package/example/components/header.tsx +35 -13
  25. package/example/components/prompt-form.tsx +1 -1
  26. package/example/components/stocks/stock-purchase.tsx +1 -1
  27. package/example/components/stocks/stocks.tsx +1 -1
  28. package/example/lib/chat/langchain-rag.tsx +191 -0
  29. package/example/lib/chat/langchain.tsx +112 -0
  30. package/example/lib/chat/{actions.tsx → vercel-ai.tsx} +4 -6
  31. package/example/package-lock.json +287 -4
  32. package/example/package.json +1 -0
  33. package/package.json +12 -2
  34. package/src/index.test.ts +96 -28
  35. package/src/index.ts +18 -9
  36. package/src/langchain.ts +557 -0
  37. package/src/types.ts +4 -4
  38. package/src/utils.ts +28 -1
  39. package/dist/chunk-AP23NJ57.mjs.map +0 -1
  40. /package/src/{helpers.ts → typeUtils.ts} +0 -0
@@ -6,6 +6,7 @@
6
6
  "": {
7
7
  "dependencies": {
8
8
  "@ai-sdk/openai": "^0.0.9",
9
+ "@langchain/openai": "^0.1.3",
9
10
  "@radix-ui/react-alert-dialog": "^1.0.5",
10
11
  "@radix-ui/react-dialog": "^1.0.5",
11
12
  "@radix-ui/react-dropdown-menu": "^2.0.6",
@@ -69,9 +70,10 @@
69
70
  },
70
71
  "..": {
71
72
  "name": "langwatch",
72
- "version": "0.0.2",
73
+ "version": "0.1.0",
73
74
  "license": "Apache-2.0",
74
75
  "dependencies": {
76
+ "@langchain/core": "^0.2.7",
75
77
  "ai": "^3.1.23",
76
78
  "llm-cost": "^1.0.4",
77
79
  "nanoid": "^5.0.7",
@@ -85,6 +87,7 @@
85
87
  "@types/debug": "^4.1.12",
86
88
  "@types/eslint__js": "^8.42.3",
87
89
  "@types/node": "^16.0.0",
90
+ "dotenv": "^16.4.5",
88
91
  "eslint": "^8.57.0",
89
92
  "ts-to-zod": "^3.4.1",
90
93
  "tsup": "^8.1.0",
@@ -504,6 +507,90 @@
504
507
  "@jridgewell/sourcemap-codec": "^1.4.14"
505
508
  }
506
509
  },
510
+ "node_modules/@langchain/core": {
511
+ "version": "0.2.7",
512
+ "resolved": "https://registry.npmjs.org/@langchain/core/-/core-0.2.7.tgz",
513
+ "integrity": "sha512-FdFiNWhszFuUyAhYdY+l5DtPnAnWCAjXMnkLmUJ1J54NeUiUm7gy26Hnd4bkvaOQJ8ddHH/EX03ZwdoYfLv1jw==",
514
+ "dependencies": {
515
+ "ansi-styles": "^5.0.0",
516
+ "camelcase": "6",
517
+ "decamelize": "1.2.0",
518
+ "js-tiktoken": "^1.0.12",
519
+ "langsmith": "~0.1.30",
520
+ "ml-distance": "^4.0.0",
521
+ "mustache": "^4.2.0",
522
+ "p-queue": "^6.6.2",
523
+ "p-retry": "4",
524
+ "uuid": "^9.0.0",
525
+ "zod": "^3.22.4",
526
+ "zod-to-json-schema": "^3.22.3"
527
+ },
528
+ "engines": {
529
+ "node": ">=18"
530
+ }
531
+ },
532
+ "node_modules/@langchain/core/node_modules/ansi-styles": {
533
+ "version": "5.2.0",
534
+ "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-5.2.0.tgz",
535
+ "integrity": "sha512-Cxwpt2SfTzTtXcfOlzGEee8O+c+MmUgGrNiBcXnuWxuFJHe6a5Hz7qwhwe5OgaSYI0IJvkLqWX1ASG+cJOkEiA==",
536
+ "engines": {
537
+ "node": ">=10"
538
+ },
539
+ "funding": {
540
+ "url": "https://github.com/chalk/ansi-styles?sponsor=1"
541
+ }
542
+ },
543
+ "node_modules/@langchain/core/node_modules/commander": {
544
+ "version": "10.0.1",
545
+ "resolved": "https://registry.npmjs.org/commander/-/commander-10.0.1.tgz",
546
+ "integrity": "sha512-y4Mg2tXshplEbSGzx7amzPwKKOCGuoSRP/CjEdwwk0FOGlUbq6lKuoyDZTNZkmxHdJtp54hdfY/JUrdL7Xfdug==",
547
+ "engines": {
548
+ "node": ">=14"
549
+ }
550
+ },
551
+ "node_modules/@langchain/core/node_modules/langsmith": {
552
+ "version": "0.1.32",
553
+ "resolved": "https://registry.npmjs.org/langsmith/-/langsmith-0.1.32.tgz",
554
+ "integrity": "sha512-EUWHIH6fiOCGRYdzgwGoXwJxCMyUrL+bmUcxoVmkXoXoAGDOVinz8bqJLKbxotsQWqM64NKKsW85OTIutgNaMQ==",
555
+ "dependencies": {
556
+ "@types/uuid": "^9.0.1",
557
+ "commander": "^10.0.1",
558
+ "p-queue": "^6.6.2",
559
+ "p-retry": "4",
560
+ "uuid": "^9.0.0"
561
+ },
562
+ "peerDependencies": {
563
+ "@langchain/core": "*",
564
+ "langchain": "*",
565
+ "openai": "*"
566
+ },
567
+ "peerDependenciesMeta": {
568
+ "@langchain/core": {
569
+ "optional": true
570
+ },
571
+ "langchain": {
572
+ "optional": true
573
+ },
574
+ "openai": {
575
+ "optional": true
576
+ }
577
+ }
578
+ },
579
+ "node_modules/@langchain/openai": {
580
+ "version": "0.1.3",
581
+ "resolved": "https://registry.npmjs.org/@langchain/openai/-/openai-0.1.3.tgz",
582
+ "integrity": "sha512-riv/JC9x2A8b7GcHu8sx+mlZJ8KAwSSi231IPTlcciYnKozmrQ5H0vrtiD31fxiDbaRsk7tyCpkSBIOQEo7CyQ==",
583
+ "dependencies": {
584
+ "@langchain/core": ">=0.2.5 <0.3.0",
585
+ "js-tiktoken": "^1.0.12",
586
+ "openai": "^4.49.1",
587
+ "zod": "^3.22.4",
588
+ "zod-to-json-schema": "^3.22.3"
589
+ },
590
+ "engines": {
591
+ "node": ">=18"
592
+ }
593
+ },
507
594
  "node_modules/@next/env": {
508
595
  "version": "14.2.3",
509
596
  "resolved": "https://registry.npmjs.org/@next/env/-/env-14.2.3.tgz",
@@ -1680,11 +1767,21 @@
1680
1767
  "@types/react": "*"
1681
1768
  }
1682
1769
  },
1770
+ "node_modules/@types/retry": {
1771
+ "version": "0.12.0",
1772
+ "resolved": "https://registry.npmjs.org/@types/retry/-/retry-0.12.0.tgz",
1773
+ "integrity": "sha512-wWKOClTTiizcZhXnPY4wikVAwmdYHp8q6DmC+EJUzAMsycb7HB32Kh9RN4+0gExjmPmZSAQjgURXIGATPegAvA=="
1774
+ },
1683
1775
  "node_modules/@types/unist": {
1684
1776
  "version": "2.0.10",
1685
1777
  "resolved": "https://registry.npmjs.org/@types/unist/-/unist-2.0.10.tgz",
1686
1778
  "integrity": "sha512-IfYcSBWE3hLpBg8+X2SEa8LVkJdJEkT2Ese2aaLs3ptGdVtABxndrMaxuFlQ1qdFf9Q5rDvDpxI3WwgvKFAsQA=="
1687
1779
  },
1780
+ "node_modules/@types/uuid": {
1781
+ "version": "9.0.8",
1782
+ "resolved": "https://registry.npmjs.org/@types/uuid/-/uuid-9.0.8.tgz",
1783
+ "integrity": "sha512-jg+97EGIcY9AGHJJRaaPVgetKDsrTgbRjQ5Msgjh/DQKEFl0DtyRr/VCOyD1T2R1MNeWPK/u7JoGhlDZnKBAfA=="
1784
+ },
1688
1785
  "node_modules/@typescript-eslint/parser": {
1689
1786
  "version": "6.21.0",
1690
1787
  "resolved": "https://registry.npmjs.org/@typescript-eslint/parser/-/parser-6.21.0.tgz",
@@ -2477,6 +2574,11 @@
2477
2574
  "url": "https://github.com/sponsors/sindresorhus"
2478
2575
  }
2479
2576
  },
2577
+ "node_modules/binary-search": {
2578
+ "version": "1.3.6",
2579
+ "resolved": "https://registry.npmjs.org/binary-search/-/binary-search-1.3.6.tgz",
2580
+ "integrity": "sha512-nbE1WxOTTrUWIfsfZ4aHGYu5DOuNkbxGokjV6Z2kxfJK3uaAb8zNK1muzOeipoLHZjInT4Br88BHpzevc681xA=="
2581
+ },
2480
2582
  "node_modules/brace-expansion": {
2481
2583
  "version": "2.0.1",
2482
2584
  "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-2.0.1.tgz",
@@ -2569,6 +2671,17 @@
2569
2671
  "node": ">=6"
2570
2672
  }
2571
2673
  },
2674
+ "node_modules/camelcase": {
2675
+ "version": "6.3.0",
2676
+ "resolved": "https://registry.npmjs.org/camelcase/-/camelcase-6.3.0.tgz",
2677
+ "integrity": "sha512-Gmy6FhYlCY7uOElZUSbxo2UCDH8owEk996gkbrpsgGtrJLM3J7jGxl9Ic7Qwwj4ivOE5AWZWRMecDdF7hqGjFA==",
2678
+ "engines": {
2679
+ "node": ">=10"
2680
+ },
2681
+ "funding": {
2682
+ "url": "https://github.com/sponsors/sindresorhus"
2683
+ }
2684
+ },
2572
2685
  "node_modules/camelcase-css": {
2573
2686
  "version": "2.0.1",
2574
2687
  "resolved": "https://registry.npmjs.org/camelcase-css/-/camelcase-css-2.0.1.tgz",
@@ -3031,6 +3144,14 @@
3031
3144
  }
3032
3145
  }
3033
3146
  },
3147
+ "node_modules/decamelize": {
3148
+ "version": "1.2.0",
3149
+ "resolved": "https://registry.npmjs.org/decamelize/-/decamelize-1.2.0.tgz",
3150
+ "integrity": "sha512-z2S+W9X73hAUUki+N+9Za2lBlun89zigOyGrsax+KUQ6wKW4ZoWpEYBkGhQjwAjjDCkWxhY0VKEhk8wzY7F5cA==",
3151
+ "engines": {
3152
+ "node": ">=0.10.0"
3153
+ }
3154
+ },
3034
3155
  "node_modules/decode-named-character-reference": {
3035
3156
  "version": "1.0.2",
3036
3157
  "resolved": "https://registry.npmjs.org/decode-named-character-reference/-/decode-named-character-reference-1.0.2.tgz",
@@ -3946,6 +4067,11 @@
3946
4067
  "node": ">=6"
3947
4068
  }
3948
4069
  },
4070
+ "node_modules/eventemitter3": {
4071
+ "version": "4.0.7",
4072
+ "resolved": "https://registry.npmjs.org/eventemitter3/-/eventemitter3-4.0.7.tgz",
4073
+ "integrity": "sha512-8guHBZCwKnFhYdHr2ysuRWErTwhoN2X8XELRlrRwpmfeY2jjuUN4taQMsULKUVo1K4DvZl+0pgfyoysHxvmvEw=="
4074
+ },
3949
4075
  "node_modules/eventsource-parser": {
3950
4076
  "version": "1.1.2",
3951
4077
  "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-1.1.2.tgz",
@@ -4728,6 +4854,11 @@
4728
4854
  "url": "https://github.com/sponsors/wooorm"
4729
4855
  }
4730
4856
  },
4857
+ "node_modules/is-any-array": {
4858
+ "version": "2.0.1",
4859
+ "resolved": "https://registry.npmjs.org/is-any-array/-/is-any-array-2.0.1.tgz",
4860
+ "integrity": "sha512-UtilS7hLRu++wb/WBAw9bNuP1Eg04Ivn1vERJck8zJthEvXCBEBpGR/33u/xLKWEQf95803oalHrVDptcAvFdQ=="
4861
+ },
4731
4862
  "node_modules/is-array-buffer": {
4732
4863
  "version": "3.0.4",
4733
4864
  "resolved": "https://registry.npmjs.org/is-array-buffer/-/is-array-buffer-3.0.4.tgz",
@@ -5215,6 +5346,33 @@
5215
5346
  "url": "https://github.com/sponsors/panva"
5216
5347
  }
5217
5348
  },
5349
+ "node_modules/js-tiktoken": {
5350
+ "version": "1.0.12",
5351
+ "resolved": "https://registry.npmjs.org/js-tiktoken/-/js-tiktoken-1.0.12.tgz",
5352
+ "integrity": "sha512-L7wURW1fH9Qaext0VzaUDpFGVQgjkdE3Dgsy9/+yXyGEpBKnylTd0mU0bfbNkKDlXRb6TEsZkwuflu1B8uQbJQ==",
5353
+ "dependencies": {
5354
+ "base64-js": "^1.5.1"
5355
+ }
5356
+ },
5357
+ "node_modules/js-tiktoken/node_modules/base64-js": {
5358
+ "version": "1.5.1",
5359
+ "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
5360
+ "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
5361
+ "funding": [
5362
+ {
5363
+ "type": "github",
5364
+ "url": "https://github.com/sponsors/feross"
5365
+ },
5366
+ {
5367
+ "type": "patreon",
5368
+ "url": "https://www.patreon.com/feross"
5369
+ },
5370
+ {
5371
+ "type": "consulting",
5372
+ "url": "https://feross.org/support"
5373
+ }
5374
+ ]
5375
+ },
5218
5376
  "node_modules/js-tokens": {
5219
5377
  "version": "4.0.0",
5220
5378
  "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz",
@@ -6365,6 +6523,46 @@
6365
6523
  "node": ">=16 || 14 >=14.17"
6366
6524
  }
6367
6525
  },
6526
+ "node_modules/ml-array-mean": {
6527
+ "version": "1.1.6",
6528
+ "resolved": "https://registry.npmjs.org/ml-array-mean/-/ml-array-mean-1.1.6.tgz",
6529
+ "integrity": "sha512-MIdf7Zc8HznwIisyiJGRH9tRigg3Yf4FldW8DxKxpCCv/g5CafTw0RRu51nojVEOXuCQC7DRVVu5c7XXO/5joQ==",
6530
+ "dependencies": {
6531
+ "ml-array-sum": "^1.1.6"
6532
+ }
6533
+ },
6534
+ "node_modules/ml-array-sum": {
6535
+ "version": "1.1.6",
6536
+ "resolved": "https://registry.npmjs.org/ml-array-sum/-/ml-array-sum-1.1.6.tgz",
6537
+ "integrity": "sha512-29mAh2GwH7ZmiRnup4UyibQZB9+ZLyMShvt4cH4eTK+cL2oEMIZFnSyB3SS8MlsTh6q/w/yh48KmqLxmovN4Dw==",
6538
+ "dependencies": {
6539
+ "is-any-array": "^2.0.0"
6540
+ }
6541
+ },
6542
+ "node_modules/ml-distance": {
6543
+ "version": "4.0.1",
6544
+ "resolved": "https://registry.npmjs.org/ml-distance/-/ml-distance-4.0.1.tgz",
6545
+ "integrity": "sha512-feZ5ziXs01zhyFUUUeZV5hwc0f5JW0Sh0ckU1koZe/wdVkJdGxcP06KNQuF0WBTj8FttQUzcvQcpcrOp/XrlEw==",
6546
+ "dependencies": {
6547
+ "ml-array-mean": "^1.1.6",
6548
+ "ml-distance-euclidean": "^2.0.0",
6549
+ "ml-tree-similarity": "^1.0.0"
6550
+ }
6551
+ },
6552
+ "node_modules/ml-distance-euclidean": {
6553
+ "version": "2.0.0",
6554
+ "resolved": "https://registry.npmjs.org/ml-distance-euclidean/-/ml-distance-euclidean-2.0.0.tgz",
6555
+ "integrity": "sha512-yC9/2o8QF0A3m/0IXqCTXCzz2pNEzvmcE/9HFKOZGnTjatvBbsn4lWYJkxENkA4Ug2fnYl7PXQxnPi21sgMy/Q=="
6556
+ },
6557
+ "node_modules/ml-tree-similarity": {
6558
+ "version": "1.0.0",
6559
+ "resolved": "https://registry.npmjs.org/ml-tree-similarity/-/ml-tree-similarity-1.0.0.tgz",
6560
+ "integrity": "sha512-XJUyYqjSuUQkNQHMscr6tcjldsOoAekxADTplt40QKfwW6nd++1wHWV9AArl0Zvw/TIHgNaZZNvr8QGvE8wLRg==",
6561
+ "dependencies": {
6562
+ "binary-search": "^1.3.5",
6563
+ "num-sort": "^2.0.0"
6564
+ }
6565
+ },
6368
6566
  "node_modules/mri": {
6369
6567
  "version": "1.2.0",
6370
6568
  "resolved": "https://registry.npmjs.org/mri/-/mri-1.2.0.tgz",
@@ -6378,6 +6576,14 @@
6378
6576
  "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz",
6379
6577
  "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w=="
6380
6578
  },
6579
+ "node_modules/mustache": {
6580
+ "version": "4.2.0",
6581
+ "resolved": "https://registry.npmjs.org/mustache/-/mustache-4.2.0.tgz",
6582
+ "integrity": "sha512-71ippSywq5Yb7/tVYyGbkBggbU8H3u5Rz56fH60jGFgr8uHwxs+aSKeqmluIVzM0m0kB7xQjKS6qPfd0b2ZoqQ==",
6583
+ "bin": {
6584
+ "mustache": "bin/mustache"
6585
+ }
6586
+ },
6381
6587
  "node_modules/mz": {
6382
6588
  "version": "2.7.0",
6383
6589
  "resolved": "https://registry.npmjs.org/mz/-/mz-2.7.0.tgz",
@@ -6594,6 +6800,17 @@
6594
6800
  "node": ">=0.10.0"
6595
6801
  }
6596
6802
  },
6803
+ "node_modules/num-sort": {
6804
+ "version": "2.1.0",
6805
+ "resolved": "https://registry.npmjs.org/num-sort/-/num-sort-2.1.0.tgz",
6806
+ "integrity": "sha512-1MQz1Ed8z2yckoBeSfkQHHO9K1yDRxxtotKSJ9yvcTUUxSvfvzEq5GwBrjjHEpMlq/k5gvXdmJ1SbYxWtpNoVg==",
6807
+ "engines": {
6808
+ "node": ">=8"
6809
+ },
6810
+ "funding": {
6811
+ "url": "https://github.com/sponsors/sindresorhus"
6812
+ }
6813
+ },
6597
6814
  "node_modules/oauth4webapi": {
6598
6815
  "version": "2.10.4",
6599
6816
  "resolved": "https://registry.npmjs.org/oauth4webapi/-/oauth4webapi-2.10.4.tgz",
@@ -6745,9 +6962,9 @@
6745
6962
  }
6746
6963
  },
6747
6964
  "node_modules/openai": {
6748
- "version": "4.47.3",
6749
- "resolved": "https://registry.npmjs.org/openai/-/openai-4.47.3.tgz",
6750
- "integrity": "sha512-470d4ibH5kizXflCzgur22GpM4nOjrg7WQ9jTOa3dNKEn248oBy4+pjOyfcFR4V4YUn/YlDNjp6h83PbviCCKQ==",
6965
+ "version": "4.51.0",
6966
+ "resolved": "https://registry.npmjs.org/openai/-/openai-4.51.0.tgz",
6967
+ "integrity": "sha512-UKuWc3/qQyklqhHM8CbdXCv0Z0obap6T0ECdcO5oATQxAbKE5Ky3YCXFQY207z+eGG6ez4U9wvAcuMygxhmStg==",
6751
6968
  "dependencies": {
6752
6969
  "@types/node": "^18.11.18",
6753
6970
  "@types/node-fetch": "^2.6.4",
@@ -6787,6 +7004,14 @@
6787
7004
  "node": ">= 0.8.0"
6788
7005
  }
6789
7006
  },
7007
+ "node_modules/p-finally": {
7008
+ "version": "1.0.0",
7009
+ "resolved": "https://registry.npmjs.org/p-finally/-/p-finally-1.0.0.tgz",
7010
+ "integrity": "sha512-LICb2p9CB7FS+0eR1oqWnHhp0FljGLZCWBE9aix0Uye9W8LTQPwMTYVGWQWIw9RdQiDg4+epXQODwIYJtSJaow==",
7011
+ "engines": {
7012
+ "node": ">=4"
7013
+ }
7014
+ },
6790
7015
  "node_modules/p-limit": {
6791
7016
  "version": "3.1.0",
6792
7017
  "resolved": "https://registry.npmjs.org/p-limit/-/p-limit-3.1.0.tgz",
@@ -6817,6 +7042,44 @@
6817
7042
  "url": "https://github.com/sponsors/sindresorhus"
6818
7043
  }
6819
7044
  },
7045
+ "node_modules/p-queue": {
7046
+ "version": "6.6.2",
7047
+ "resolved": "https://registry.npmjs.org/p-queue/-/p-queue-6.6.2.tgz",
7048
+ "integrity": "sha512-RwFpb72c/BhQLEXIZ5K2e+AhgNVmIejGlTgiB9MzZ0e93GRvqZ7uSi0dvRF7/XIXDeNkra2fNHBxTyPDGySpjQ==",
7049
+ "dependencies": {
7050
+ "eventemitter3": "^4.0.4",
7051
+ "p-timeout": "^3.2.0"
7052
+ },
7053
+ "engines": {
7054
+ "node": ">=8"
7055
+ },
7056
+ "funding": {
7057
+ "url": "https://github.com/sponsors/sindresorhus"
7058
+ }
7059
+ },
7060
+ "node_modules/p-retry": {
7061
+ "version": "4.6.2",
7062
+ "resolved": "https://registry.npmjs.org/p-retry/-/p-retry-4.6.2.tgz",
7063
+ "integrity": "sha512-312Id396EbJdvRONlngUx0NydfrIQ5lsYu0znKVUzVvArzEIt08V1qhtyESbGVd1FGX7UKtiFp5uwKZdM8wIuQ==",
7064
+ "dependencies": {
7065
+ "@types/retry": "0.12.0",
7066
+ "retry": "^0.13.1"
7067
+ },
7068
+ "engines": {
7069
+ "node": ">=8"
7070
+ }
7071
+ },
7072
+ "node_modules/p-timeout": {
7073
+ "version": "3.2.0",
7074
+ "resolved": "https://registry.npmjs.org/p-timeout/-/p-timeout-3.2.0.tgz",
7075
+ "integrity": "sha512-rhIwUycgwwKcP9yTOOFK/AKsAopjjCakVqLHePO3CC6Mir1Z99xT+R63jZxAT5lFZLa2inS5h+ZS2GvR99/FBg==",
7076
+ "dependencies": {
7077
+ "p-finally": "^1.0.0"
7078
+ },
7079
+ "engines": {
7080
+ "node": ">=8"
7081
+ }
7082
+ },
6820
7083
  "node_modules/pako": {
6821
7084
  "version": "0.2.9",
6822
7085
  "resolved": "https://registry.npmjs.org/pako/-/pako-0.2.9.tgz",
@@ -7611,6 +7874,14 @@
7611
7874
  "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1"
7612
7875
  }
7613
7876
  },
7877
+ "node_modules/retry": {
7878
+ "version": "0.13.1",
7879
+ "resolved": "https://registry.npmjs.org/retry/-/retry-0.13.1.tgz",
7880
+ "integrity": "sha512-XQBQ3I8W1Cge0Seh+6gjj03LbmRFWuoszgK9ooCpwYIrhhoO80pfq4cUkU5DkknwfOfFteRwlZ56PYOGYyFWdg==",
7881
+ "engines": {
7882
+ "node": ">= 4"
7883
+ }
7884
+ },
7614
7885
  "node_modules/reusify": {
7615
7886
  "version": "1.0.4",
7616
7887
  "resolved": "https://registry.npmjs.org/reusify/-/reusify-1.0.4.tgz",
@@ -8892,6 +9163,18 @@
8892
9163
  "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==",
8893
9164
  "dev": true
8894
9165
  },
9166
+ "node_modules/uuid": {
9167
+ "version": "9.0.1",
9168
+ "resolved": "https://registry.npmjs.org/uuid/-/uuid-9.0.1.tgz",
9169
+ "integrity": "sha512-b+1eJOlsR9K8HJpow9Ok3fiWOWSIcIzXodvv0rQjVoOVNpWMpxf1wZNpt4y9h10odCNrqnYp1OBzRktckBe3sA==",
9170
+ "funding": [
9171
+ "https://github.com/sponsors/broofa",
9172
+ "https://github.com/sponsors/ctavan"
9173
+ ],
9174
+ "bin": {
9175
+ "uuid": "dist/bin/uuid"
9176
+ }
9177
+ },
8895
9178
  "node_modules/uvu": {
8896
9179
  "version": "0.5.6",
8897
9180
  "resolved": "https://registry.npmjs.org/uvu/-/uvu-0.5.6.tgz",
@@ -14,6 +14,7 @@
14
14
  },
15
15
  "dependencies": {
16
16
  "@ai-sdk/openai": "^0.0.9",
17
+ "@langchain/openai": "^0.1.3",
17
18
  "@radix-ui/react-alert-dialog": "^1.0.5",
18
19
  "@radix-ui/react-dialog": "^1.0.5",
19
20
  "@radix-ui/react-dropdown-menu": "^2.0.6",
package/package.json CHANGED
@@ -1,10 +1,16 @@
1
1
  {
2
2
  "name": "langwatch",
3
- "version": "0.0.3",
3
+ "version": "0.1.1",
4
4
  "description": "",
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/index.mjs",
7
7
  "types": "./dist/index.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": "./dist/index.mjs",
11
+ "require": "./dist/index.js"
12
+ }
13
+ },
8
14
  "repository": {
9
15
  "type": "git",
10
16
  "url": "https://github.com/langwatch/langwatch.git",
@@ -13,7 +19,7 @@
13
19
  "scripts": {
14
20
  "prepare": "cp ../langwatch/src/server/tracer/types.ts src/server/types/tracer.ts && ts-to-zod src/server/types/tracer.ts src/server/types/tracer.generated.ts",
15
21
  "test": "vitest",
16
- "build": "npm run prepare && tsup",
22
+ "build": "npm run prepare && tsup && esbuild src/index.ts --bundle --platform=node --outfile=dist/index.js",
17
23
  "prepublish": "npm run build"
18
24
  },
19
25
  "author": "",
@@ -27,6 +33,8 @@
27
33
  "@types/debug": "^4.1.12",
28
34
  "@types/eslint__js": "^8.42.3",
29
35
  "@types/node": "^16.0.0",
36
+ "dotenv": "^16.4.5",
37
+ "esbuild": "^0.21.5",
30
38
  "eslint": "^8.57.0",
31
39
  "ts-to-zod": "^3.4.1",
32
40
  "tsup": "^8.1.0",
@@ -35,7 +43,9 @@
35
43
  "vitest": "^0.5.0"
36
44
  },
37
45
  "dependencies": {
46
+ "@langchain/core": "^0.2.7",
38
47
  "ai": "^3.1.23",
48
+ "javascript-stringify": "^2.1.0",
39
49
  "llm-cost": "^1.0.4",
40
50
  "nanoid": "^5.0.7",
41
51
  "openai": "^4.47.3",
package/src/index.test.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { OpenAI } from "openai";
1
+ import { AzureOpenAI, OpenAI } from "openai";
2
2
  import { LangWatch, convertFromVercelAIMessages } from "./index";
3
3
  import {
4
4
  describe,
@@ -10,6 +10,7 @@ import {
10
10
  } from "vitest";
11
11
  import { openai } from "@ai-sdk/openai";
12
12
  import { generateText, type CoreMessage } from "ai";
13
+ import "dotenv/config";
13
14
 
14
15
  describe("LangWatch tracer", () => {
15
16
  let mockFetch: SpyInstanceFn;
@@ -52,14 +53,12 @@ describe("LangWatch tracer", () => {
52
53
  },
53
54
  });
54
55
  span.end({
55
- outputs: [
56
- {
57
- type: "json",
58
- value: {
59
- weather: "sunny",
60
- },
56
+ output: {
57
+ type: "json",
58
+ value: {
59
+ weather: "sunny",
61
60
  },
62
- ],
61
+ },
63
62
  });
64
63
 
65
64
  expect(trace.metadata).toEqual({
@@ -99,17 +98,15 @@ describe("LangWatch tracer", () => {
99
98
  },
100
99
  });
101
100
  llmSpan.end({
102
- outputs: [
103
- {
104
- type: "chat_messages",
105
- value: [
106
- {
107
- role: "assistant",
108
- content: "It's cloudy in Tokyo.",
109
- },
110
- ],
111
- },
112
- ],
101
+ output: {
102
+ type: "chat_messages",
103
+ value: [
104
+ {
105
+ role: "assistant",
106
+ content: "It's cloudy in Tokyo.",
107
+ },
108
+ ],
109
+ },
113
110
  });
114
111
 
115
112
  ragSpan.end();
@@ -216,10 +213,79 @@ describe("LangWatch tracer", () => {
216
213
  });
217
214
 
218
215
  span.end({
219
- outputs: chatCompletion.choices.map((choice) => ({
216
+ output: {
217
+ type: "chat_messages",
218
+ value: [chatCompletion.choices[0]!.message],
219
+ },
220
+ metrics: {
221
+ promptTokens: chatCompletion.usage?.prompt_tokens,
222
+ completionTokens: chatCompletion.usage?.completion_tokens,
223
+ },
224
+ });
225
+
226
+ await trace.sendSpans();
227
+
228
+ expect(mockFetch).toHaveBeenCalled();
229
+ expect(mockFetch).toHaveBeenCalledWith(
230
+ "http://localhost.test/api/collector",
231
+ expect.objectContaining({
232
+ method: "POST",
233
+ headers: {
234
+ "X-Auth-Token": "test",
235
+ "Content-Type": "application/json",
236
+ },
237
+ body: expect.any(String),
238
+ })
239
+ );
240
+ });
241
+
242
+ it.skip("captures azure openai llm call", async () => {
243
+ const langwatch = new LangWatch({
244
+ apiKey: "test",
245
+ endpoint: "http://localhost.test",
246
+ });
247
+ const trace = langwatch.getTrace();
248
+
249
+ // Model to be used and messages that will be sent to the LLM
250
+ const model = "gpt-4-turbo-2024-04-09";
251
+ const messages: OpenAI.Chat.ChatCompletionMessageParam[] = [
252
+ { role: "system", content: "You are a helpful assistant." },
253
+ {
254
+ role: "user",
255
+ content: "Write a tweet-size vegetarian lasagna recipe for 4 people.",
256
+ },
257
+ ];
258
+
259
+ // Capture the llm call with a span
260
+ const span = trace.startLLMSpan({
261
+ name: "llm",
262
+ model: model,
263
+ input: {
264
+ type: "chat_messages",
265
+ value: messages,
266
+ },
267
+ });
268
+
269
+ // Continue with the LLM call normally
270
+ const openai = new AzureOpenAI({
271
+ apiKey: process.env.AZURE_OPENAI_API_KEY,
272
+ apiVersion: "2024-02-01",
273
+ endpoint: process.env.AZURE_OPENAI_ENDPOINT,
274
+ });
275
+ const chatCompletion = await openai.chat.completions.create({
276
+ messages: messages,
277
+ model: model,
278
+ });
279
+
280
+ span.end({
281
+ output: {
220
282
  type: "chat_messages",
221
- value: [choice.message],
222
- })),
283
+ value: [chatCompletion.choices[0]!.message],
284
+ },
285
+ metrics: {
286
+ promptTokens: chatCompletion.usage?.prompt_tokens,
287
+ completionTokens: chatCompletion.usage?.completion_tokens,
288
+ },
223
289
  });
224
290
 
225
291
  await trace.sendSpans();
@@ -270,12 +336,14 @@ describe("LangWatch tracer", () => {
270
336
  });
271
337
 
272
338
  span.end({
273
- outputs: [
274
- {
275
- type: "chat_messages",
276
- value: convertFromVercelAIMessages(response.responseMessages),
277
- },
278
- ],
339
+ output: {
340
+ type: "chat_messages",
341
+ value: convertFromVercelAIMessages(response.responseMessages),
342
+ },
343
+ metrics: {
344
+ promptTokens: response.usage?.promptTokens,
345
+ completionTokens: response.usage?.completionTokens,
346
+ },
279
347
  });
280
348
 
281
349
  await trace.sendSpans();