From 1419b32cbe74da0c8f29b75353f3ece1ed7a711a Mon Sep 17 00:00:00 2001 From: Travis Fischer Date: Sat, 29 Jun 2024 14:57:14 -0700 Subject: [PATCH] fix: resolve AIFunctionSet bug --- package.json | 2 +- pnpm-lock.yaml | 296 ++++++------------------------------ src/ai-function-set.test.ts | 44 ++++++ src/ai-function-set.ts | 55 ++++++- src/utils.ts | 12 ++ 5 files changed, 148 insertions(+), 261 deletions(-) create mode 100644 src/ai-function-set.test.ts diff --git a/package.json b/package.json index ea51a9330..9fb47bc1a 100644 --- a/package.json +++ b/package.json @@ -180,7 +180,7 @@ }, "pnpm": { "overrides": { - "esbuild": "~0.21.4" + "esbuild": "~0.21.5" } } } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index feb3aa957..93af1c183 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -5,7 +5,7 @@ settings: excludeLinksFromLockfile: false overrides: - esbuild: ~0.21.4 + esbuild: ~0.21.5 importers: @@ -458,276 +458,138 @@ packages: resolution: {integrity: sha512-cKDFY9js9l3MfL71x0IDvaz0mAhvHIurVFnimtFRXNzuV0TxhuFqsauKabet0TMOrcDF3H3trC7pct6mNgRYTA==} engines: {node: '>=18'} - '@esbuild/aix-ppc64@0.21.4': - resolution: {integrity: sha512-Zrm+B33R4LWPLjDEVnEqt2+SLTATlru1q/xYKVn8oVTbiRBGmK2VIMoIYGJDGyftnGaC788IuzGFAlb7IQ0Y8A==} - engines: {node: '>=12'} - cpu: [ppc64] - os: [aix] - '@esbuild/aix-ppc64@0.21.5': resolution: {integrity: sha512-1SDgH6ZSPTlggy1yI6+Dbkiz8xzpHJEVAlF/AM1tHPLsf5STom9rwtjE4hKAF20FfXXNTFqEYXyJNWh1GiZedQ==} engines: {node: '>=12'} cpu: [ppc64] os: [aix] - '@esbuild/android-arm64@0.21.4': - resolution: {integrity: sha512-fYFnz+ObClJ3dNiITySBUx+oNalYUT18/AryMxfovLkYWbutXsct3Wz2ZWAcGGppp+RVVX5FiXeLYGi97umisA==} - engines: {node: '>=12'} - cpu: [arm64] - os: [android] - '@esbuild/android-arm64@0.21.5': resolution: {integrity: sha512-c0uX9VAUBQ7dTDCjq+wdyGLowMdtR/GoC2U5IYk/7D1H1JYC0qseD7+11iMP2mRLN9RcCMRcjC4YMclCzGwS/A==} engines: {node: '>=12'} cpu: [arm64] os: [android] - '@esbuild/android-arm@0.21.4': - resolution: {integrity: sha512-E7H/yTd8kGQfY4z9t3nRPk/hrhaCajfA3YSQSBrst8B+3uTcgsi8N+ZWYCaeIDsiVs6m65JPCaQN/DxBRclF3A==} - engines: {node: '>=12'} - cpu: [arm] - os: [android] - '@esbuild/android-arm@0.21.5': resolution: {integrity: sha512-vCPvzSjpPHEi1siZdlvAlsPxXl7WbOVUBBAowWug4rJHb68Ox8KualB+1ocNvT5fjv6wpkX6o/iEpbDrf68zcg==} engines: {node: '>=12'} cpu: [arm] os: [android] - '@esbuild/android-x64@0.21.4': - resolution: {integrity: sha512-mDqmlge3hFbEPbCWxp4fM6hqq7aZfLEHZAKGP9viq9wMUBVQx202aDIfc3l+d2cKhUJM741VrCXEzRFhPDKH3Q==} - engines: {node: '>=12'} - cpu: [x64] - os: [android] - '@esbuild/android-x64@0.21.5': resolution: {integrity: sha512-D7aPRUUNHRBwHxzxRvp856rjUHRFW1SdQATKXH2hqA0kAZb1hKmi02OpYRacl0TxIGz/ZmXWlbZgjwWYaCakTA==} engines: {node: '>=12'} cpu: [x64] os: [android] - '@esbuild/darwin-arm64@0.21.4': - resolution: {integrity: sha512-72eaIrDZDSiWqpmCzVaBD58c8ea8cw/U0fq/PPOTqE3c53D0xVMRt2ooIABZ6/wj99Y+h4ksT/+I+srCDLU9TA==} - engines: {node: '>=12'} - cpu: [arm64] - os: [darwin] - '@esbuild/darwin-arm64@0.21.5': resolution: {integrity: sha512-DwqXqZyuk5AiWWf3UfLiRDJ5EDd49zg6O9wclZ7kUMv2WRFr4HKjXp/5t8JZ11QbQfUS6/cRCKGwYhtNAY88kQ==} engines: {node: '>=12'} cpu: [arm64] os: [darwin] - '@esbuild/darwin-x64@0.21.4': - resolution: {integrity: sha512-uBsuwRMehGmw1JC7Vecu/upOjTsMhgahmDkWhGLWxIgUn2x/Y4tIwUZngsmVb6XyPSTXJYS4YiASKPcm9Zitag==} - engines: {node: '>=12'} - cpu: [x64] - os: [darwin] - '@esbuild/darwin-x64@0.21.5': resolution: {integrity: sha512-se/JjF8NlmKVG4kNIuyWMV/22ZaerB+qaSi5MdrXtd6R08kvs2qCN4C09miupktDitvh8jRFflwGFBQcxZRjbw==} engines: {node: '>=12'} cpu: [x64] os: [darwin] - '@esbuild/freebsd-arm64@0.21.4': - resolution: {integrity: sha512-8JfuSC6YMSAEIZIWNL3GtdUT5NhUA/CMUCpZdDRolUXNAXEE/Vbpe6qlGLpfThtY5NwXq8Hi4nJy4YfPh+TwAg==} - engines: {node: '>=12'} - cpu: [arm64] - os: [freebsd] - '@esbuild/freebsd-arm64@0.21.5': resolution: {integrity: sha512-5JcRxxRDUJLX8JXp/wcBCy3pENnCgBR9bN6JsY4OmhfUtIHe3ZW0mawA7+RDAcMLrMIZaf03NlQiX9DGyB8h4g==} engines: {node: '>=12'} cpu: [arm64] os: [freebsd] - '@esbuild/freebsd-x64@0.21.4': - resolution: {integrity: sha512-8d9y9eQhxv4ef7JmXny7591P/PYsDFc4+STaxC1GBv0tMyCdyWfXu2jBuqRsyhY8uL2HU8uPyscgE2KxCY9imQ==} - engines: {node: '>=12'} - cpu: [x64] - os: [freebsd] - '@esbuild/freebsd-x64@0.21.5': resolution: {integrity: sha512-J95kNBj1zkbMXtHVH29bBriQygMXqoVQOQYA+ISs0/2l3T9/kj42ow2mpqerRBxDJnmkUDCaQT/dfNXWX/ZZCQ==} engines: {node: '>=12'} cpu: [x64] os: [freebsd] - '@esbuild/linux-arm64@0.21.4': - resolution: {integrity: sha512-/GLD2orjNU50v9PcxNpYZi+y8dJ7e7/LhQukN3S4jNDXCKkyyiyAz9zDw3siZ7Eh1tRcnCHAo/WcqKMzmi4eMQ==} - engines: {node: '>=12'} - cpu: [arm64] - os: [linux] - '@esbuild/linux-arm64@0.21.5': resolution: {integrity: sha512-ibKvmyYzKsBeX8d8I7MH/TMfWDXBF3db4qM6sy+7re0YXya+K1cem3on9XgdT2EQGMu4hQyZhan7TeQ8XkGp4Q==} engines: {node: '>=12'} cpu: [arm64] os: [linux] - '@esbuild/linux-arm@0.21.4': - resolution: {integrity: sha512-2rqFFefpYmpMs+FWjkzSgXg5vViocqpq5a1PSRgT0AvSgxoXmGF17qfGAzKedg6wAwyM7UltrKVo9kxaJLMF/g==} - engines: {node: '>=12'} - cpu: [arm] - os: [linux] - '@esbuild/linux-arm@0.21.5': resolution: {integrity: sha512-bPb5AHZtbeNGjCKVZ9UGqGwo8EUu4cLq68E95A53KlxAPRmUyYv2D6F0uUI65XisGOL1hBP5mTronbgo+0bFcA==} engines: {node: '>=12'} cpu: [arm] os: [linux] - '@esbuild/linux-ia32@0.21.4': - resolution: {integrity: sha512-pNftBl7m/tFG3t2m/tSjuYeWIffzwAZT9m08+9DPLizxVOsUl8DdFzn9HvJrTQwe3wvJnwTdl92AonY36w/25g==} - engines: {node: '>=12'} - cpu: [ia32] - os: [linux] - '@esbuild/linux-ia32@0.21.5': resolution: {integrity: sha512-YvjXDqLRqPDl2dvRODYmmhz4rPeVKYvppfGYKSNGdyZkA01046pLWyRKKI3ax8fbJoK5QbxblURkwK/MWY18Tg==} engines: {node: '>=12'} cpu: [ia32] os: [linux] - '@esbuild/linux-loong64@0.21.4': - resolution: {integrity: sha512-cSD2gzCK5LuVX+hszzXQzlWya6c7hilO71L9h4KHwqI4qeqZ57bAtkgcC2YioXjsbfAv4lPn3qe3b00Zt+jIfQ==} - engines: {node: '>=12'} - cpu: [loong64] - os: [linux] - '@esbuild/linux-loong64@0.21.5': resolution: {integrity: sha512-uHf1BmMG8qEvzdrzAqg2SIG/02+4/DHB6a9Kbya0XDvwDEKCoC8ZRWI5JJvNdUjtciBGFQ5PuBlpEOXQj+JQSg==} engines: {node: '>=12'} cpu: [loong64] os: [linux] - '@esbuild/linux-mips64el@0.21.4': - resolution: {integrity: sha512-qtzAd3BJh7UdbiXCrg6npWLYU0YpufsV9XlufKhMhYMJGJCdfX/G6+PNd0+v877X1JG5VmjBLUiFB0o8EUSicA==} - engines: {node: '>=12'} - cpu: [mips64el] - os: [linux] - '@esbuild/linux-mips64el@0.21.5': resolution: {integrity: sha512-IajOmO+KJK23bj52dFSNCMsz1QP1DqM6cwLUv3W1QwyxkyIWecfafnI555fvSGqEKwjMXVLokcV5ygHW5b3Jbg==} engines: {node: '>=12'} cpu: [mips64el] os: [linux] - '@esbuild/linux-ppc64@0.21.4': - resolution: {integrity: sha512-yB8AYzOTaL0D5+2a4xEy7OVvbcypvDR05MsB/VVPVA7nL4hc5w5Dyd/ddnayStDgJE59fAgNEOdLhBxjfx5+dg==} - engines: {node: '>=12'} - cpu: [ppc64] - os: [linux] - '@esbuild/linux-ppc64@0.21.5': resolution: {integrity: sha512-1hHV/Z4OEfMwpLO8rp7CvlhBDnjsC3CttJXIhBi+5Aj5r+MBvy4egg7wCbe//hSsT+RvDAG7s81tAvpL2XAE4w==} engines: {node: '>=12'} cpu: [ppc64] os: [linux] - '@esbuild/linux-riscv64@0.21.4': - resolution: {integrity: sha512-Y5AgOuVzPjQdgU59ramLoqSSiXddu7F3F+LI5hYy/d1UHN7K5oLzYBDZe23QmQJ9PIVUXwOdKJ/jZahPdxzm9w==} - engines: {node: '>=12'} - cpu: [riscv64] - os: [linux] - '@esbuild/linux-riscv64@0.21.5': resolution: {integrity: sha512-2HdXDMd9GMgTGrPWnJzP2ALSokE/0O5HhTUvWIbD3YdjME8JwvSCnNGBnTThKGEB91OZhzrJ4qIIxk/SBmyDDA==} engines: {node: '>=12'} cpu: [riscv64] os: [linux] - '@esbuild/linux-s390x@0.21.4': - resolution: {integrity: sha512-Iqc/l/FFwtt8FoTK9riYv9zQNms7B8u+vAI/rxKuN10HgQIXaPzKZc479lZ0x6+vKVQbu55GdpYpeNWzjOhgbA==} - engines: {node: '>=12'} - cpu: [s390x] - os: [linux] - '@esbuild/linux-s390x@0.21.5': resolution: {integrity: sha512-zus5sxzqBJD3eXxwvjN1yQkRepANgxE9lgOW2qLnmr8ikMTphkjgXu1HR01K4FJg8h1kEEDAqDcZQtbrRnB41A==} engines: {node: '>=12'} cpu: [s390x] os: [linux] - '@esbuild/linux-x64@0.21.4': - resolution: {integrity: sha512-Td9jv782UMAFsuLZINfUpoF5mZIbAj+jv1YVtE58rFtfvoKRiKSkRGQfHTgKamLVT/fO7203bHa3wU122V/Bdg==} - engines: {node: '>=12'} - cpu: [x64] - os: [linux] - '@esbuild/linux-x64@0.21.5': resolution: {integrity: sha512-1rYdTpyv03iycF1+BhzrzQJCdOuAOtaqHTWJZCWvijKD2N5Xu0TtVC8/+1faWqcP9iBCWOmjmhoH94dH82BxPQ==} engines: {node: '>=12'} cpu: [x64] os: [linux] - '@esbuild/netbsd-x64@0.21.4': - resolution: {integrity: sha512-Awn38oSXxsPMQxaV0Ipb7W/gxZtk5Tx3+W+rAPdZkyEhQ6968r9NvtkjhnhbEgWXYbgV+JEONJ6PcdBS+nlcpA==} - engines: {node: '>=12'} - cpu: [x64] - os: [netbsd] - '@esbuild/netbsd-x64@0.21.5': resolution: {integrity: sha512-Woi2MXzXjMULccIwMnLciyZH4nCIMpWQAs049KEeMvOcNADVxo0UBIQPfSmxB3CWKedngg7sWZdLvLczpe0tLg==} engines: {node: '>=12'} cpu: [x64] os: [netbsd] - '@esbuild/openbsd-x64@0.21.4': - resolution: {integrity: sha512-IsUmQeCY0aU374R82fxIPu6vkOybWIMc3hVGZ3ChRwL9hA1TwY+tS0lgFWV5+F1+1ssuvvXt3HFqe8roCip8Hg==} - engines: {node: '>=12'} - cpu: [x64] - os: [openbsd] - '@esbuild/openbsd-x64@0.21.5': resolution: {integrity: sha512-HLNNw99xsvx12lFBUwoT8EVCsSvRNDVxNpjZ7bPn947b8gJPzeHWyNVhFsaerc0n3TsbOINvRP2byTZ5LKezow==} engines: {node: '>=12'} cpu: [x64] os: [openbsd] - '@esbuild/sunos-x64@0.21.4': - resolution: {integrity: sha512-hsKhgZ4teLUaDA6FG/QIu2q0rI6I36tZVfM4DBZv3BG0mkMIdEnMbhc4xwLvLJSS22uWmaVkFkqWgIS0gPIm+A==} - engines: {node: '>=12'} - cpu: [x64] - os: [sunos] - '@esbuild/sunos-x64@0.21.5': resolution: {integrity: sha512-6+gjmFpfy0BHU5Tpptkuh8+uw3mnrvgs+dSPQXQOv3ekbordwnzTVEb4qnIvQcYXq6gzkyTnoZ9dZG+D4garKg==} engines: {node: '>=12'} cpu: [x64] os: [sunos] - '@esbuild/win32-arm64@0.21.4': - resolution: {integrity: sha512-UUfMgMoXPoA/bvGUNfUBFLCh0gt9dxZYIx9W4rfJr7+hKe5jxxHmfOK8YSH4qsHLLN4Ck8JZ+v7Q5fIm1huErg==} - engines: {node: '>=12'} - cpu: [arm64] - os: [win32] - '@esbuild/win32-arm64@0.21.5': resolution: {integrity: sha512-Z0gOTd75VvXqyq7nsl93zwahcTROgqvuAcYDUr+vOv8uHhNSKROyU961kgtCD1e95IqPKSQKH7tBTslnS3tA8A==} engines: {node: '>=12'} cpu: [arm64] os: [win32] - '@esbuild/win32-ia32@0.21.4': - resolution: {integrity: sha512-yIxbspZb5kGCAHWm8dexALQ9en1IYDfErzjSEq1KzXFniHv019VT3mNtTK7t8qdy4TwT6QYHI9sEZabONHg+aw==} - engines: {node: '>=12'} - cpu: [ia32] - os: [win32] - '@esbuild/win32-ia32@0.21.5': resolution: {integrity: sha512-SWXFF1CL2RVNMaVs+BBClwtfZSvDgtL//G/smwAc5oVK/UPu2Gu9tIaRgFmYFFKrmg3SyAjSrElf0TiJ1v8fYA==} engines: {node: '>=12'} cpu: [ia32] os: [win32] - '@esbuild/win32-x64@0.21.4': - resolution: {integrity: sha512-sywLRD3UK/qRJt0oBwdpYLBibk7KiRfbswmWRDabuncQYSlf8aLEEUor/oP6KRz8KEG+HoiVLBhPRD5JWjS8Sg==} - engines: {node: '>=12'} - cpu: [x64] - os: [win32] - '@esbuild/win32-x64@0.21.5': resolution: {integrity: sha512-tQd/1efJuzPC6rCFwEvLtci/xNFcTZknmXs98FYDfGE4wP9ClFV98nyKrzJKVPMhdDnjzLhdUyMX4PsQAPjwIw==} engines: {node: '>=12'} @@ -872,10 +734,6 @@ packages: resolution: {integrity: sha512-giydNZyEzUBrjZrmQRfnc2SI0+TyAjaVMd8wMKq8O4X/Y3BJd0LFlfD+3MM6Lyu/qaphZ1Ycfr7XR5hY0EcGqQ==} engines: {node: '>=18'} - '@langchain/openai@0.2.0': - resolution: {integrity: sha512-gZd+0IOxpiKuh1m6KTT5vtUoOO72GEYyoU4+c6qAUucOEqQS0Vvz3lMGyNWLjK4x4Xpd+r8GAF5mj/jvghwP1A==} - engines: {node: '>=18'} - '@langchain/textsplitters@0.0.3': resolution: {integrity: sha512-cXWgKE3sdWLSqAa8ykbCcUsUF1Kyr5J3HOWYGuobhPEycXW4WI++d5DhzdpL238mzoEXTi90VqfSCra37l5YqA==} engines: {node: '>=18'} @@ -2072,7 +1930,7 @@ packages: resolution: {integrity: sha512-7Q/6vkyYAwOmQNRw75x+4yRtZCZJXUDmHHlFdkiV0wgv/reNjtJwpu1jPJ0w2kbEpIM0uoKI3S4/f39dU7AjSA==} engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0} peerDependencies: - esbuild: ~0.21.4 + esbuild: ~0.21.5 bytes@3.1.2: resolution: {integrity: sha512-/Nf7TyzTx6S3yRJObOAV7956r8cr2+Oj8AC5dt8wSP3BQAoeX58NoHyCU8P8zGkNXStjTSi6fzO6F0pBdcYbEg==} @@ -2678,11 +2536,6 @@ packages: resolution: {integrity: sha512-QCOllgZJtaUo9miYBcLChTUaHNjJF3PYs1VidD7AwiEj1kYxKeQTctLAezAOH5ZKRH0g2IgPn6KwB4IT8iRpvA==} engines: {node: '>= 0.4'} - esbuild@0.21.4: - resolution: {integrity: sha512-sFMcNNrj+Q0ZDolrp5pDhH0nRPN9hLIM3fRPwgbLYJeSHHgnXSnbV3xYgSVuOeLWH9c73VwmEverVzupIv5xuA==} - engines: {node: '>=12'} - hasBin: true - esbuild@0.21.5: resolution: {integrity: sha512-mg3OPMV4hXywwpoDxu3Qda5xCKQi+vCTZq8S9J/EpkhB2HzKXq4SNFZE3+NK93JYxc8VMSep+lOUSC/RVKaBqw==} engines: {node: '>=12'} @@ -7203,141 +7056,72 @@ snapshots: - bufferutil - utf-8-validate - '@esbuild/aix-ppc64@0.21.4': - optional: true - '@esbuild/aix-ppc64@0.21.5': optional: true - '@esbuild/android-arm64@0.21.4': - optional: true - '@esbuild/android-arm64@0.21.5': optional: true - '@esbuild/android-arm@0.21.4': - optional: true - '@esbuild/android-arm@0.21.5': optional: true - '@esbuild/android-x64@0.21.4': - optional: true - '@esbuild/android-x64@0.21.5': optional: true - '@esbuild/darwin-arm64@0.21.4': - optional: true - '@esbuild/darwin-arm64@0.21.5': optional: true - '@esbuild/darwin-x64@0.21.4': - optional: true - '@esbuild/darwin-x64@0.21.5': optional: true - '@esbuild/freebsd-arm64@0.21.4': - optional: true - '@esbuild/freebsd-arm64@0.21.5': optional: true - '@esbuild/freebsd-x64@0.21.4': - optional: true - '@esbuild/freebsd-x64@0.21.5': optional: true - '@esbuild/linux-arm64@0.21.4': - optional: true - '@esbuild/linux-arm64@0.21.5': optional: true - '@esbuild/linux-arm@0.21.4': - optional: true - '@esbuild/linux-arm@0.21.5': optional: true - '@esbuild/linux-ia32@0.21.4': - optional: true - '@esbuild/linux-ia32@0.21.5': optional: true - '@esbuild/linux-loong64@0.21.4': - optional: true - '@esbuild/linux-loong64@0.21.5': optional: true - '@esbuild/linux-mips64el@0.21.4': - optional: true - '@esbuild/linux-mips64el@0.21.5': optional: true - '@esbuild/linux-ppc64@0.21.4': - optional: true - '@esbuild/linux-ppc64@0.21.5': optional: true - '@esbuild/linux-riscv64@0.21.4': - optional: true - '@esbuild/linux-riscv64@0.21.5': optional: true - '@esbuild/linux-s390x@0.21.4': - optional: true - '@esbuild/linux-s390x@0.21.5': optional: true - '@esbuild/linux-x64@0.21.4': - optional: true - '@esbuild/linux-x64@0.21.5': optional: true - '@esbuild/netbsd-x64@0.21.4': - optional: true - '@esbuild/netbsd-x64@0.21.5': optional: true - '@esbuild/openbsd-x64@0.21.4': - optional: true - '@esbuild/openbsd-x64@0.21.5': optional: true - '@esbuild/sunos-x64@0.21.4': - optional: true - '@esbuild/sunos-x64@0.21.5': optional: true - '@esbuild/win32-arm64@0.21.4': - optional: true - '@esbuild/win32-arm64@0.21.5': optional: true - '@esbuild/win32-ia32@0.21.4': - optional: true - '@esbuild/win32-ia32@0.21.5': optional: true - '@esbuild/win32-x64@0.21.4': - optional: true - '@esbuild/win32-x64@0.21.5': optional: true @@ -7580,6 +7364,25 @@ snapshots: - langchain - openai + '@langchain/core@0.2.6(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.49.0(encoding@0.1.13))': + dependencies: + ansi-styles: 5.2.0 + camelcase: 6.3.0 + decamelize: 1.2.0 + js-tiktoken: 1.0.12 + langsmith: 0.1.30(@langchain/core@0.2.6(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.49.0(encoding@0.1.13)))(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.49.0(encoding@0.1.13)) + ml-distance: 4.0.1 + mustache: 4.2.0 + p-queue: 6.6.2 + p-retry: 4.6.2 + uuid: 9.0.1 + zod: 3.23.8 + zod-to-json-schema: 3.23.1(zod@3.23.8) + transitivePeerDependencies: + - langchain + - openai + optional: true + '@langchain/core@0.2.6(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.52.1(encoding@0.1.13))': dependencies: ansi-styles: 5.2.0 @@ -7610,11 +7413,11 @@ snapshots: - encoding - langchain - '@langchain/openai@0.2.0(encoding@0.1.13)(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))': + '@langchain/openai@0.1.2(encoding@0.1.13)(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))': dependencies: - '@langchain/core': 0.2.10(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.52.1(encoding@0.1.13)) + '@langchain/core': 0.2.6(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.49.0(encoding@0.1.13)) js-tiktoken: 1.0.12 - openai: 4.52.1(encoding@0.1.13) + openai: 4.49.0(encoding@0.1.13) zod: 3.23.8 zod-to-json-schema: 3.23.1(zod@3.23.8) transitivePeerDependencies: @@ -9054,9 +8857,9 @@ snapshots: dependencies: run-applescript: 7.0.0 - bundle-require@4.2.1(esbuild@0.21.4): + bundle-require@4.2.1(esbuild@0.21.5): dependencies: - esbuild: 0.21.4 + esbuild: 0.21.5 load-tsconfig: 0.2.5 bytes@3.1.2: {} @@ -9703,32 +9506,6 @@ snapshots: is-date-object: 1.0.5 is-symbol: 1.0.4 - esbuild@0.21.4: - optionalDependencies: - '@esbuild/aix-ppc64': 0.21.4 - '@esbuild/android-arm': 0.21.4 - '@esbuild/android-arm64': 0.21.4 - '@esbuild/android-x64': 0.21.4 - '@esbuild/darwin-arm64': 0.21.4 - '@esbuild/darwin-x64': 0.21.4 - '@esbuild/freebsd-arm64': 0.21.4 - '@esbuild/freebsd-x64': 0.21.4 - '@esbuild/linux-arm': 0.21.4 - '@esbuild/linux-arm64': 0.21.4 - '@esbuild/linux-ia32': 0.21.4 - '@esbuild/linux-loong64': 0.21.4 - '@esbuild/linux-mips64el': 0.21.4 - '@esbuild/linux-ppc64': 0.21.4 - '@esbuild/linux-riscv64': 0.21.4 - '@esbuild/linux-s390x': 0.21.4 - '@esbuild/linux-x64': 0.21.4 - '@esbuild/netbsd-x64': 0.21.4 - '@esbuild/openbsd-x64': 0.21.4 - '@esbuild/sunos-x64': 0.21.4 - '@esbuild/win32-arm64': 0.21.4 - '@esbuild/win32-ia32': 0.21.4 - '@esbuild/win32-x64': 0.21.4 - esbuild@0.21.5: optionalDependencies: '@esbuild/aix-ppc64': 0.21.5 @@ -11104,7 +10881,7 @@ snapshots: langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)): dependencies: '@langchain/core': 0.2.10(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.52.1(encoding@0.1.13)) - '@langchain/openai': 0.2.0(encoding@0.1.13)(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4))) + '@langchain/openai': 0.1.2(encoding@0.1.13)(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4))) '@langchain/textsplitters': 0.0.3(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.52.1(encoding@0.1.13)) binary-extensions: 2.3.0 js-tiktoken: 1.0.12 @@ -11130,6 +10907,19 @@ snapshots: langchainhub@0.0.11: {} + langsmith@0.1.30(@langchain/core@0.2.6(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.49.0(encoding@0.1.13)))(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.49.0(encoding@0.1.13)): + dependencies: + '@types/uuid': 9.0.8 + commander: 10.0.1 + p-queue: 6.6.2 + p-retry: 4.6.2 + uuid: 9.0.1 + optionalDependencies: + '@langchain/core': 0.2.6(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.49.0(encoding@0.1.13)) + langchain: 0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)) + openai: 4.49.0(encoding@0.1.13) + optional: true + langsmith@0.1.30(@langchain/core@0.2.6(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.52.1(encoding@0.1.13)))(langchain@0.2.7(@browserbasehq/sdk@1.4.2(bufferutil@4.0.8)(utf-8-validate@6.0.4))(@notionhq/client@2.2.15(encoding@0.1.13))(encoding@0.1.13)(openai@4.52.1(encoding@0.1.13))(ws@8.17.1(bufferutil@4.0.8)(utf-8-validate@6.0.4)))(openai@4.52.1(encoding@0.1.13)): dependencies: '@types/uuid': 9.0.8 @@ -13326,11 +13116,11 @@ snapshots: tsup@8.1.0(postcss@8.4.38)(ts-node@10.9.2(@types/node@20.14.9)(typescript@5.5.2))(typescript@5.5.2): dependencies: - bundle-require: 4.2.1(esbuild@0.21.4) + bundle-require: 4.2.1(esbuild@0.21.5) cac: 6.7.14 chokidar: 3.6.0 debug: 4.3.5 - esbuild: 0.21.4 + esbuild: 0.21.5 execa: 5.1.1 globby: 11.1.0 joycon: 3.1.1 @@ -13554,7 +13344,7 @@ snapshots: vite@5.2.12(@types/node@20.14.9): dependencies: - esbuild: 0.21.4 + esbuild: 0.21.5 postcss: 8.4.38 rollup: 4.18.0 optionalDependencies: diff --git a/src/ai-function-set.test.ts b/src/ai-function-set.test.ts new file mode 100644 index 000000000..32a394618 --- /dev/null +++ b/src/ai-function-set.test.ts @@ -0,0 +1,44 @@ +import { expect, test } from 'vitest' +import { z } from 'zod' + +import { AIFunctionSet } from './ai-function-set.js' +import { aiFunction, AIFunctionsProvider } from './fns.js' +import { calculator } from './tools/calculator.js' + +class MockAITool extends AIFunctionsProvider { + @aiFunction({ + name: 'echo', + description: 'Echoes the input.', + inputSchema: z.object({ + query: z.string().describe('input query to echo') + }) + }) + async echo({ query }: { query: string }) { + return query + } +} + +test('AIFunctionSet constructor', () => { + const mockAITool = new MockAITool() + const s0 = new AIFunctionSet([mockAITool, calculator]) + + expect(s0.size).toEqual(2) + expect(s0.get('echo')).toBeDefined() + expect(s0.get('calculator')).toBeDefined() + expect([...s0].length).toEqual(2) + + const s1 = new AIFunctionSet([s0, mockAITool, calculator, calculator]) + expect(s0.size).toEqual(2) + expect(s1.size).toEqual(2) + expect(s1.get('echo')).toBeDefined() + expect(s1.get('calculator')).toBeDefined() + expect([...s1].length).toEqual(2) +}) + +test('AIFunctionSet constructor invalid function', () => { + const mockAITool = new MockAITool() + + expect( + () => new AIFunctionSet([mockAITool, calculator, { spec: {} } as any]) + ).toThrowError('Invalid AIFunctionLike: [object Object]') +}) diff --git a/src/ai-function-set.ts b/src/ai-function-set.ts index 1c3d21867..d28607d6f 100644 --- a/src/ai-function-set.ts +++ b/src/ai-function-set.ts @@ -1,5 +1,6 @@ import type * as types from './types.ts' import { AIFunctionsProvider } from './fns.js' +import { isAIFunction } from './utils.js' /** * A set of AI functions intended to make it easier to work with large sets of @@ -15,13 +16,53 @@ export class AIFunctionSet implements Iterable { protected readonly _map: Map constructor(aiFunctionLikeObjects?: types.AIFunctionLike[]) { - const fns = aiFunctionLikeObjects?.flatMap((fn) => - fn instanceof AIFunctionsProvider - ? [...fn.functions] - : fn instanceof AIFunctionSet - ? [...fn] - : [fn] - ) + // TODO: these `instanceof` checks seem to be failing on some platforms, + // so for now we're using an uglier, but more reliable approach to parsing + // the AIFunctionLike objects. + const fns = aiFunctionLikeObjects?.flatMap((fn) => { + if (fn instanceof AIFunctionsProvider) { + return [...fn.functions] + } + + if (fn instanceof AIFunctionSet) { + return [...fn] + } + + if (isAIFunction(fn)) { + return fn + } + + const f = fn as any + const fa = (f.functions ?? f) as AIFunctionSet + if (fa) { + try { + const fns = [...fa] + if (fns.every(isAIFunction)) { + return fns + } + } catch {} + } + + throw new Error(`Invalid AIFunctionLike: ${fn}`) + }) + + // TODO: This is the cleaner approach which should work in theory, but is + // not working in practice due to the `instanceof` checks failing. + // const fns = aiFunctionLikeObjects?.flatMap((fn) => + // fn instanceof AIFunctionsProvider + // ? [...fn.functions] + // : fn instanceof AIFunctionSet + // ? [...fn] + // : [fn] + // ) + + if (fns) { + for (const fn of fns) { + if (!isAIFunction(fn)) { + throw new Error(`Invalid AIFunctionLike: ${fn}`) + } + } + } this._map = new Map( fns ? fns.map((fn) => [transformName(fn.spec.name), fn]) : null diff --git a/src/utils.ts b/src/utils.ts index e5270c419..c159498a6 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -183,3 +183,15 @@ export function hashObject( ): string { return hashObjectImpl(object, { algorithm: 'sha256', ...options }) } + +export function isAIFunction(obj: any): obj is types.AIFunction { + if (!obj) return false + if (typeof obj !== 'function') return false + if (!obj.inputSchema) return false + if (!obj.parseInput) return false + if (!obj.spec) return false + if (!obj.impl) return false + if (!obj.spec.name || typeof obj.spec.name !== 'string') return false + + return true +}