diff --git a/packages/tools/package-lock.json b/packages/tools/package-lock.json index b0caf7b4..a588b381 100644 --- a/packages/tools/package-lock.json +++ b/packages/tools/package-lock.json @@ -28,7 +28,6 @@ "@rollup/plugin-node-resolve": "^15.3.0", "@rollup/plugin-replace": "^6.0.1", "@rollup/plugin-terser": "^0.4.4", - "@rollup/plugin-typescript": "^12.1.2", "@storybook/addon-essentials": "^8.3.6", "@storybook/addon-interactions": "^8.3.6", "@storybook/addon-links": "^8.3.6", @@ -37,7 +36,6 @@ "@storybook/react": "^8.3.6", "@storybook/react-vite": "^8.3.6", "@storybook/test": "^8.3.6", - "@types/node": "^22.13.4", "babel-jest": "^29.7.0", "eslint": "^8.4.1", "eslint-plugin-storybook": "^0.10.1", @@ -46,12 +44,7 @@ "react-monaco-editor": "^0.56.2", "rollup": "^4.24.0", "rollup-plugin-node-polyfills": "^0.2.1", - "rollup-plugin-typescript2": "^0.36.0", "storybook": "^8.3.6", - "ts-node": "^10.9.2", - "tslib": "^2.8.1", - "tsx": "^4.19.2", - "typescript": "^5.7.3", "undici": "^6.20.1" } }, @@ -1835,30 +1828,6 @@ "yarn": ">=1.22.18" } }, - "node_modules/@cspotcode/source-map-support": { - "version": "0.8.1", - "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", - "integrity": "sha512-IchNf6dN4tHoMFIn/7OE8LWZ19Y6q/67Bmf6vnGREv8RSbBVb9LPJxEcnwrcwX6ixSvaiGoomAUvu4YSxXrVgw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@jridgewell/trace-mapping": "0.3.9" - }, - "engines": { - "node": ">=12" - } - }, - "node_modules/@cspotcode/source-map-support/node_modules/@jridgewell/trace-mapping": { - "version": "0.3.9", - "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.9.tgz", - "integrity": "sha512-3Belt6tdc8bPgAtbcmdtNJlirVoTmEb5e2gC94PnkwEW9jI6CAHUeoG85tjWP5WquqfavoMtMwiG4P926ZKKuQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@jridgewell/resolve-uri": "^3.0.3", - "@jridgewell/sourcemap-codec": "^1.4.10" - } - }, "node_modules/@esbuild/aix-ppc64": { "version": "0.24.0", "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.24.0.tgz", @@ -4334,33 +4303,6 @@ } } }, - "node_modules/@rollup/plugin-typescript": { - "version": "12.1.2", - "resolved": "https://registry.npmjs.org/@rollup/plugin-typescript/-/plugin-typescript-12.1.2.tgz", - "integrity": "sha512-cdtSp154H5sv637uMr1a8OTWB0L1SWDSm1rDGiyfcGcvQ6cuTs4MDk2BVEBGysUWago4OJN4EQZqOTl/QY3Jgg==", - "dev": true, - "license": "MIT", - "dependencies": { - "@rollup/pluginutils": "^5.1.0", - "resolve": "^1.22.1" - }, - "engines": { - "node": ">=14.0.0" - }, - "peerDependencies": { - "rollup": "^2.14.0||^3.0.0||^4.0.0", - "tslib": "*", - "typescript": ">=3.7.0" - }, - "peerDependenciesMeta": { - "rollup": { - "optional": true - }, - "tslib": { - "optional": true - } - } - }, "node_modules/@rollup/pluginutils": { "version": "5.1.3", "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-5.1.3.tgz", @@ -5358,34 +5300,6 @@ "node": ">= 6" } }, - "node_modules/@tsconfig/node10": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/@tsconfig/node10/-/node10-1.0.11.tgz", - "integrity": "sha512-DcRjDCujK/kCk/cUe8Xz8ZSpm8mS3mNNpta+jGCA6USEDfktlNvm1+IuZ9eTcDbNk41BHwpHHeW+N1lKCz4zOw==", - "dev": true, - "license": "MIT" - }, - "node_modules/@tsconfig/node12": { - "version": "1.0.11", - "resolved": "https://registry.npmjs.org/@tsconfig/node12/-/node12-1.0.11.tgz", - "integrity": "sha512-cqefuRsh12pWyGsIoBKJA9luFu3mRxCA+ORZvA4ktLSzIuCUtWVxGIuXigEwO5/ywWFMZ2QEGKWvkZG1zDMTag==", - "dev": true, - "license": "MIT" - }, - "node_modules/@tsconfig/node14": { - "version": "1.0.3", - "resolved": "https://registry.npmjs.org/@tsconfig/node14/-/node14-1.0.3.tgz", - "integrity": "sha512-ysT8mhdixWK6Hw3i1V2AeRqZ5WfXg1G43mqoYlM2nc6388Fq5jcXyr5mRsqViLx/GJYdoL0bfXD8nmF+Zn/Iow==", - "dev": true, - "license": "MIT" - }, - "node_modules/@tsconfig/node16": { - "version": "1.0.4", - "resolved": "https://registry.npmjs.org/@tsconfig/node16/-/node16-1.0.4.tgz", - "integrity": "sha512-vxhUy4J8lyeyinH7Azl1pdd43GJhZH/tP2weN8TntQblOY+A0XbT8DJk1/oCPuOOyg/Ja757rG0CgHcWC8OfMA==", - "dev": true, - "license": "MIT" - }, "node_modules/@types/aria-query": { "version": "5.0.4", "resolved": "https://registry.npmjs.org/@types/aria-query/-/aria-query-5.0.4.tgz", @@ -5497,9 +5411,9 @@ "license": "MIT" }, "node_modules/@types/node": { - "version": "22.13.4", - "resolved": "https://registry.npmjs.org/@types/node/-/node-22.13.4.tgz", - "integrity": "sha512-ywP2X0DYtX3y08eFVx5fNIw7/uIv8hYUKgXoK8oayJlLnKcRfEYCxWMVE1XagUdVtCJlZT1AU4LXEABW+L1Peg==", + "version": "22.10.1", + "resolved": "https://registry.npmjs.org/@types/node/-/node-22.10.1.tgz", + "integrity": "sha512-qKgsUwfHZV2WCWLAnVP1JqnpE6Im6h3Y0+fYgMTasNQ7V++CBX5OT1as0g0f+OyubbFqhf6XVNIsmN4IIhEgGQ==", "license": "MIT", "dependencies": { "undici-types": "~6.20.0" @@ -6094,13 +6008,6 @@ "node": ">=10" } }, - "node_modules/arg": { - "version": "4.1.3", - "resolved": "https://registry.npmjs.org/arg/-/arg-4.1.3.tgz", - "integrity": "sha512-58S9QDqG0Xx27YwPSt9fJxivjYl432YCwfDMfZ+71RAqUrZef7LrKQZ3LHLOwCS4FLNBplP533Zx895SeOCHvA==", - "dev": true, - "license": "MIT" - }, "node_modules/argparse": { "version": "2.0.1", "resolved": "https://registry.npmjs.org/argparse/-/argparse-2.0.1.tgz", @@ -6883,13 +6790,6 @@ "url": "https://opencollective.com/core-js" } }, - "node_modules/create-require": { - "version": "1.1.1", - "resolved": "https://registry.npmjs.org/create-require/-/create-require-1.1.1.tgz", - "integrity": "sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==", - "dev": true, - "license": "MIT" - }, "node_modules/cross-spawn": { "version": "7.0.6", "resolved": "https://registry.npmjs.org/cross-spawn/-/cross-spawn-7.0.6.tgz", @@ -7164,16 +7064,6 @@ "node": ">=8" } }, - "node_modules/diff": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/diff/-/diff-4.0.2.tgz", - "integrity": "sha512-58lmxKSA4BNyLz+HHMUzlOEpg09FV+ev6ZMe3vJihgdxzgcwZ8VoEEPmALCZG9LmqfVoNMMKpttIYTVG6uDY7A==", - "dev": true, - "license": "BSD-3-Clause", - "engines": { - "node": ">=0.3.1" - } - }, "node_modules/diff-sequences": { "version": "27.5.1", "resolved": "https://registry.npmjs.org/diff-sequences/-/diff-sequences-27.5.1.tgz", @@ -7922,40 +7812,6 @@ "node": ">=8" } }, - "node_modules/find-cache-dir": { - "version": "3.3.2", - "resolved": "https://registry.npmjs.org/find-cache-dir/-/find-cache-dir-3.3.2.tgz", - "integrity": "sha512-wXZV5emFEjrridIgED11OoUKLxiYjAcqot/NJdAkOhlJ+vGzwhOAfcG5OX1jP+S0PcjEn8bdMJv+g2jwQ3Onig==", - "dev": true, - "license": "MIT", - "dependencies": { - "commondir": "^1.0.1", - "make-dir": "^3.0.2", - "pkg-dir": "^4.1.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/avajs/find-cache-dir?sponsor=1" - } - }, - "node_modules/find-cache-dir/node_modules/make-dir": { - "version": "3.1.0", - "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", - "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", - "dev": true, - "license": "MIT", - "dependencies": { - "semver": "^6.0.0" - }, - "engines": { - "node": ">=8" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" - } - }, "node_modules/find-up": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/find-up/-/find-up-5.0.0.tgz", @@ -8055,21 +7911,6 @@ "license": "MIT", "optional": true }, - "node_modules/fs-extra": { - "version": "10.1.0", - "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-10.1.0.tgz", - "integrity": "sha512-oRXApq54ETRj4eMiFzGnHWGy+zo5raudjuxN0b8H7s/RU2oW0Wvsx9O0ACRN/kRq9E8Vu/ReskGB5o3ji+FzHQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "graceful-fs": "^4.2.0", - "jsonfile": "^6.0.1", - "universalify": "^2.0.0" - }, - "engines": { - "node": ">=12" - } - }, "node_modules/fs-minipass": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", @@ -8243,19 +8084,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/get-tsconfig": { - "version": "4.10.0", - "resolved": "https://registry.npmjs.org/get-tsconfig/-/get-tsconfig-4.10.0.tgz", - "integrity": "sha512-kGzZ3LWWQcGIAmg6iWvXn0ei6WDtV26wzHRMwDSzmAbcXrTEXxHy6IehI6/4eT6VRKyMP1eF1VqwrVUmE/LR7A==", - "dev": true, - "license": "MIT", - "dependencies": { - "resolve-pkg-maps": "^1.0.0" - }, - "funding": { - "url": "https://github.com/privatenumber/get-tsconfig?sponsor=1" - } - }, "node_modules/github-from-package": { "version": "0.0.0", "resolved": "https://registry.npmjs.org/github-from-package/-/github-from-package-0.0.0.tgz", @@ -11724,13 +11552,6 @@ "node": ">=10" } }, - "node_modules/make-error": { - "version": "1.3.6", - "resolved": "https://registry.npmjs.org/make-error/-/make-error-1.3.6.tgz", - "integrity": "sha512-s8UhlNe7vPKomQhC1qFelMokr/Sc3AgNbso3n74mVPA5LTZwkB9NlXf4XPamLxJE8h0gh73rM94xvwRT2CVInw==", - "dev": true, - "license": "ISC" - }, "node_modules/makeerror": { "version": "1.0.12", "resolved": "https://registry.npmjs.org/makeerror/-/makeerror-1.0.12.tgz", @@ -13343,16 +13164,6 @@ "node": ">=8" } }, - "node_modules/resolve-pkg-maps": { - "version": "1.0.0", - "resolved": "https://registry.npmjs.org/resolve-pkg-maps/-/resolve-pkg-maps-1.0.0.tgz", - "integrity": "sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==", - "dev": true, - "license": "MIT", - "funding": { - "url": "https://github.com/privatenumber/resolve-pkg-maps?sponsor=1" - } - }, "node_modules/resolve.exports": { "version": "1.1.1", "resolved": "https://registry.npmjs.org/resolve.exports/-/resolve.exports-1.1.1.tgz", @@ -13500,64 +13311,6 @@ "rollup-plugin-inject": "^3.0.0" } }, - "node_modules/rollup-plugin-typescript2": { - "version": "0.36.0", - "resolved": "https://registry.npmjs.org/rollup-plugin-typescript2/-/rollup-plugin-typescript2-0.36.0.tgz", - "integrity": "sha512-NB2CSQDxSe9+Oe2ahZbf+B4bh7pHwjV5L+RSYpCu7Q5ROuN94F9b6ioWwKfz3ueL3KTtmX4o2MUH2cgHDIEUsw==", - "dev": true, - "license": "MIT", - "dependencies": { - "@rollup/pluginutils": "^4.1.2", - "find-cache-dir": "^3.3.2", - "fs-extra": "^10.0.0", - "semver": "^7.5.4", - "tslib": "^2.6.2" - }, - "peerDependencies": { - "rollup": ">=1.26.3", - "typescript": ">=2.4.0" - } - }, - "node_modules/rollup-plugin-typescript2/node_modules/@rollup/pluginutils": { - "version": "4.2.1", - "resolved": "https://registry.npmjs.org/@rollup/pluginutils/-/pluginutils-4.2.1.tgz", - "integrity": "sha512-iKnFXr7NkdZAIHiIWE+BX5ULi/ucVFYWD6TbAV+rZctiRTY2PL6tsIKhoIOaoskiWAkgu+VsbXgUVDNLHf+InQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "estree-walker": "^2.0.1", - "picomatch": "^2.2.2" - }, - "engines": { - "node": ">= 8.0.0" - } - }, - "node_modules/rollup-plugin-typescript2/node_modules/picomatch": { - "version": "2.3.1", - "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", - "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=8.6" - }, - "funding": { - "url": "https://github.com/sponsors/jonschlinkert" - } - }, - "node_modules/rollup-plugin-typescript2/node_modules/semver": { - "version": "7.7.1", - "resolved": "https://registry.npmjs.org/semver/-/semver-7.7.1.tgz", - "integrity": "sha512-hlq8tAfn0m/61p4BVRcPzIGr6LKiMwo4VM6dGi6pt4qcRkmNzTcWq6eCEjEh+qXjkMDvPlOFFSGwQjoEa6gyMA==", - "dev": true, - "license": "ISC", - "bin": { - "semver": "bin/semver.js" - }, - "engines": { - "node": ">=10" - } - }, "node_modules/rollup-pluginutils": { "version": "2.8.2", "resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz", @@ -14339,63 +14092,6 @@ "node": ">=6.10" } }, - "node_modules/ts-node": { - "version": "10.9.2", - "resolved": "https://registry.npmjs.org/ts-node/-/ts-node-10.9.2.tgz", - "integrity": "sha512-f0FFpIdcHgn8zcPSbf1dRevwt047YMnaiJM3u2w2RewrB+fob/zePZcrOyQoLMMO7aBIddLcQIEK5dYjkLnGrQ==", - "dev": true, - "license": "MIT", - "dependencies": { - "@cspotcode/source-map-support": "^0.8.0", - "@tsconfig/node10": "^1.0.7", - "@tsconfig/node12": "^1.0.7", - "@tsconfig/node14": "^1.0.0", - "@tsconfig/node16": "^1.0.2", - "acorn": "^8.4.1", - "acorn-walk": "^8.1.1", - "arg": "^4.1.0", - "create-require": "^1.1.0", - "diff": "^4.0.1", - "make-error": "^1.1.1", - "v8-compile-cache-lib": "^3.0.1", - "yn": "3.1.1" - }, - "bin": { - "ts-node": "dist/bin.js", - "ts-node-cwd": "dist/bin-cwd.js", - "ts-node-esm": "dist/bin-esm.js", - "ts-node-script": "dist/bin-script.js", - "ts-node-transpile-only": "dist/bin-transpile.js", - "ts-script": "dist/bin-script-deprecated.js" - }, - "peerDependencies": { - "@swc/core": ">=1.2.50", - "@swc/wasm": ">=1.2.50", - "@types/node": "*", - "typescript": ">=2.7" - }, - "peerDependenciesMeta": { - "@swc/core": { - "optional": true - }, - "@swc/wasm": { - "optional": true - } - } - }, - "node_modules/ts-node/node_modules/acorn-walk": { - "version": "8.3.4", - "resolved": "https://registry.npmjs.org/acorn-walk/-/acorn-walk-8.3.4.tgz", - "integrity": "sha512-ueEepnujpqee2o5aIYnvHU6C0A42MNdsIDeqy5BydrkuC5R1ZuUFnm27EeFJGoEHJQgn3uleRvmTXaJgfXbt4g==", - "dev": true, - "license": "MIT", - "dependencies": { - "acorn": "^8.11.0" - }, - "engines": { - "node": ">=0.4.0" - } - }, "node_modules/tsconfig-paths": { "version": "4.2.0", "resolved": "https://registry.npmjs.org/tsconfig-paths/-/tsconfig-paths-4.2.0.tgz", @@ -14428,528 +14124,60 @@ "dev": true, "license": "0BSD" }, - "node_modules/tsx": { - "version": "4.19.2", - "resolved": "https://registry.npmjs.org/tsx/-/tsx-4.19.2.tgz", - "integrity": "sha512-pOUl6Vo2LUq/bSa8S5q7b91cgNSjctn9ugq/+Mvow99qW6x/UZYwzxy/3NmqoT66eHYfCVvFvACC58UBPFf28g==", - "dev": true, - "license": "MIT", + "node_modules/tunnel-agent": { + "version": "0.6.0", + "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", + "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", + "license": "Apache-2.0", + "optional": true, "dependencies": { - "esbuild": "~0.23.0", - "get-tsconfig": "^4.7.5" - }, - "bin": { - "tsx": "dist/cli.mjs" + "safe-buffer": "^5.0.1" }, "engines": { - "node": ">=18.0.0" - }, - "optionalDependencies": { - "fsevents": "~2.3.3" + "node": "*" } }, - "node_modules/tsx/node_modules/@esbuild/aix-ppc64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/aix-ppc64/-/aix-ppc64-0.23.1.tgz", - "integrity": "sha512-6VhYk1diRqrhBAqpJEdjASR/+WVRtfjpqKuNw11cLiaWpAT/Uu+nokB+UJnevzy/P9C/ty6AOe0dwueMrGh/iQ==", - "cpu": [ - "ppc64" - ], + "node_modules/tween-functions": { + "version": "1.2.0", + "resolved": "https://registry.npmjs.org/tween-functions/-/tween-functions-1.2.0.tgz", + "integrity": "sha512-PZBtLYcCLtEcjL14Fzb1gSxPBeL7nWvGhO5ZFPGqziCcr8uvHp0NDmdjBchp6KHL+tExcg0m3NISmKxhU394dA==", "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "aix" - ], - "engines": { - "node": ">=18" - } + "license": "BSD" }, - "node_modules/tsx/node_modules/@esbuild/android-arm": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm/-/android-arm-0.23.1.tgz", - "integrity": "sha512-uz6/tEy2IFm9RYOyvKl88zdzZfwEfKZmnX9Cj1BHjeSGNuGLuMD1kR8y5bteYmwqKm1tj8m4cb/aKEorr6fHWQ==", - "cpu": [ - "arm" - ], + "node_modules/type-check": { + "version": "0.4.0", + "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", + "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "android" - ], + "dependencies": { + "prelude-ls": "^1.2.1" + }, "engines": { - "node": ">=18" + "node": ">= 0.8.0" } }, - "node_modules/tsx/node_modules/@esbuild/android-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-arm64/-/android-arm64-0.23.1.tgz", - "integrity": "sha512-xw50ipykXcLstLeWH7WRdQuysJqejuAGPd30vd1i5zSyKK3WE+ijzHmLKxdiCMtH1pHz78rOg0BKSYOSB/2Khw==", - "cpu": [ - "arm64" - ], + "node_modules/type-detect": { + "version": "4.0.8", + "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", + "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", "dev": true, "license": "MIT", - "optional": true, - "os": [ - "android" - ], "engines": { - "node": ">=18" + "node": ">=4" } }, - "node_modules/tsx/node_modules/@esbuild/android-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/android-x64/-/android-x64-0.23.1.tgz", - "integrity": "sha512-nlN9B69St9BwUoB+jkyU090bru8L0NA3yFvAd7k8dNsVH8bi9a8cUAUSEcEEgTp2z3dbEDGJGfP6VUnkQnlReg==", - "cpu": [ - "x64" - ], + "node_modules/type-fest": { + "version": "2.19.0", + "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", + "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "android" - ], + "license": "(MIT OR CC0-1.0)", "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/darwin-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-arm64/-/darwin-arm64-0.23.1.tgz", - "integrity": "sha512-YsS2e3Wtgnw7Wq53XXBLcV6JhRsEq8hkfg91ESVadIrzr9wO6jJDMZnCQbHm1Guc5t/CdDiFSSfWP58FNuvT3Q==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/darwin-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/darwin-x64/-/darwin-x64-0.23.1.tgz", - "integrity": "sha512-aClqdgTDVPSEGgoCS8QDG37Gu8yc9lTHNAQlsztQ6ENetKEO//b8y31MMu2ZaPbn4kVsIABzVLXYLhCGekGDqw==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "darwin" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/freebsd-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-arm64/-/freebsd-arm64-0.23.1.tgz", - "integrity": "sha512-h1k6yS8/pN/NHlMl5+v4XPfikhJulk4G+tKGFIOwURBSFzE8bixw1ebjluLOjfwtLqY0kewfjLSrO6tN2MgIhA==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/freebsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/freebsd-x64/-/freebsd-x64-0.23.1.tgz", - "integrity": "sha512-lK1eJeyk1ZX8UklqFd/3A60UuZ/6UVfGT2LuGo3Wp4/z7eRTRYY+0xOu2kpClP+vMTi9wKOfXi2vjUpO1Ro76g==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "freebsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-arm": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm/-/linux-arm-0.23.1.tgz", - "integrity": "sha512-CXXkzgn+dXAPs3WBwE+Kvnrf4WECwBdfjfeYHpMeVxWE0EceB6vhWGShs6wi0IYEqMSIzdOF1XjQ/Mkm5d7ZdQ==", - "cpu": [ - "arm" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-arm64/-/linux-arm64-0.23.1.tgz", - "integrity": "sha512-/93bf2yxencYDnItMYV/v116zff6UyTjo4EtEQjUBeGiVpMmffDNUyD9UN2zV+V3LRV3/on4xdZ26NKzn6754g==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-ia32": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ia32/-/linux-ia32-0.23.1.tgz", - "integrity": "sha512-VTN4EuOHwXEkXzX5nTvVY4s7E/Krz7COC8xkftbbKRYAl96vPiUssGkeMELQMOnLOJ8k3BY1+ZY52tttZnHcXQ==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-loong64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-loong64/-/linux-loong64-0.23.1.tgz", - "integrity": "sha512-Vx09LzEoBa5zDnieH8LSMRToj7ir/Jeq0Gu6qJ/1GcBq9GkfoEAoXvLiW1U9J1qE/Y/Oyaq33w5p2ZWrNNHNEw==", - "cpu": [ - "loong64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-mips64el": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-mips64el/-/linux-mips64el-0.23.1.tgz", - "integrity": "sha512-nrFzzMQ7W4WRLNUOU5dlWAqa6yVeI0P78WKGUo7lg2HShq/yx+UYkeNSE0SSfSure0SqgnsxPvmAUu/vu0E+3Q==", - "cpu": [ - "mips64el" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-ppc64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-ppc64/-/linux-ppc64-0.23.1.tgz", - "integrity": "sha512-dKN8fgVqd0vUIjxuJI6P/9SSSe/mB9rvA98CSH2sJnlZ/OCZWO1DJvxj8jvKTfYUdGfcq2dDxoKaC6bHuTlgcw==", - "cpu": [ - "ppc64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-riscv64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-riscv64/-/linux-riscv64-0.23.1.tgz", - "integrity": "sha512-5AV4Pzp80fhHL83JM6LoA6pTQVWgB1HovMBsLQ9OZWLDqVY8MVobBXNSmAJi//Csh6tcY7e7Lny2Hg1tElMjIA==", - "cpu": [ - "riscv64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-s390x": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-s390x/-/linux-s390x-0.23.1.tgz", - "integrity": "sha512-9ygs73tuFCe6f6m/Tb+9LtYxWR4c9yg7zjt2cYkjDbDpV/xVn+68cQxMXCjUpYwEkze2RcU/rMnfIXNRFmSoDw==", - "cpu": [ - "s390x" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/linux-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/linux-x64/-/linux-x64-0.23.1.tgz", - "integrity": "sha512-EV6+ovTsEXCPAp58g2dD68LxoP/wK5pRvgy0J/HxPGB009omFPv3Yet0HiaqvrIrgPTBuC6wCH1LTOY91EO5hQ==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "linux" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/netbsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/netbsd-x64/-/netbsd-x64-0.23.1.tgz", - "integrity": "sha512-aevEkCNu7KlPRpYLjwmdcuNz6bDFiE7Z8XC4CPqExjTvrHugh28QzUXVOZtiYghciKUacNktqxdpymplil1beA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "netbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/openbsd-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-arm64/-/openbsd-arm64-0.23.1.tgz", - "integrity": "sha512-3x37szhLexNA4bXhLrCC/LImN/YtWis6WXr1VESlfVtVeoFJBRINPJ3f0a/6LV8zpikqoUg4hyXw0sFBt5Cr+Q==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/openbsd-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/openbsd-x64/-/openbsd-x64-0.23.1.tgz", - "integrity": "sha512-aY2gMmKmPhxfU+0EdnN+XNtGbjfQgwZj43k8G3fyrDM/UdZww6xrWxmDkuz2eCZchqVeABjV5BpildOrUbBTqA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "openbsd" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/sunos-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/sunos-x64/-/sunos-x64-0.23.1.tgz", - "integrity": "sha512-RBRT2gqEl0IKQABT4XTj78tpk9v7ehp+mazn2HbUeZl1YMdaGAQqhapjGTCe7uw7y0frDi4gS0uHzhvpFuI1sA==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "sunos" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/win32-arm64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-arm64/-/win32-arm64-0.23.1.tgz", - "integrity": "sha512-4O+gPR5rEBe2FpKOVyiJ7wNDPA8nGzDuJ6gN4okSA1gEOYZ67N8JPk58tkWtdtPeLz7lBnY6I5L3jdsr3S+A6A==", - "cpu": [ - "arm64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/win32-ia32": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-ia32/-/win32-ia32-0.23.1.tgz", - "integrity": "sha512-BcaL0Vn6QwCwre3Y717nVHZbAa4UBEigzFm6VdsVdT/MbZ38xoj1X9HPkZhbmaBGUD1W8vxAfffbDe8bA6AKnQ==", - "cpu": [ - "ia32" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/@esbuild/win32-x64": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/@esbuild/win32-x64/-/win32-x64-0.23.1.tgz", - "integrity": "sha512-BHpFFeslkWrXWyUPnbKm+xYYVYruCinGcftSBaa8zoF9hZO4BcSCFUvHVTtzpIY6YzUnYtuEhZ+C9iEXjxnasg==", - "cpu": [ - "x64" - ], - "dev": true, - "license": "MIT", - "optional": true, - "os": [ - "win32" - ], - "engines": { - "node": ">=18" - } - }, - "node_modules/tsx/node_modules/esbuild": { - "version": "0.23.1", - "resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.23.1.tgz", - "integrity": "sha512-VVNz/9Sa0bs5SELtn3f7qhJCDPCF5oMEl5cO9/SSinpE9hbPVvxbd572HH5AKiP7WD8INO53GgfDDhRjkylHEg==", - "dev": true, - "hasInstallScript": true, - "license": "MIT", - "bin": { - "esbuild": "bin/esbuild" - }, - "engines": { - "node": ">=18" - }, - "optionalDependencies": { - "@esbuild/aix-ppc64": "0.23.1", - "@esbuild/android-arm": "0.23.1", - "@esbuild/android-arm64": "0.23.1", - "@esbuild/android-x64": "0.23.1", - "@esbuild/darwin-arm64": "0.23.1", - "@esbuild/darwin-x64": "0.23.1", - "@esbuild/freebsd-arm64": "0.23.1", - "@esbuild/freebsd-x64": "0.23.1", - "@esbuild/linux-arm": "0.23.1", - "@esbuild/linux-arm64": "0.23.1", - "@esbuild/linux-ia32": "0.23.1", - "@esbuild/linux-loong64": "0.23.1", - "@esbuild/linux-mips64el": "0.23.1", - "@esbuild/linux-ppc64": "0.23.1", - "@esbuild/linux-riscv64": "0.23.1", - "@esbuild/linux-s390x": "0.23.1", - "@esbuild/linux-x64": "0.23.1", - "@esbuild/netbsd-x64": "0.23.1", - "@esbuild/openbsd-arm64": "0.23.1", - "@esbuild/openbsd-x64": "0.23.1", - "@esbuild/sunos-x64": "0.23.1", - "@esbuild/win32-arm64": "0.23.1", - "@esbuild/win32-ia32": "0.23.1", - "@esbuild/win32-x64": "0.23.1" - } - }, - "node_modules/tunnel-agent": { - "version": "0.6.0", - "resolved": "https://registry.npmjs.org/tunnel-agent/-/tunnel-agent-0.6.0.tgz", - "integrity": "sha512-McnNiV1l8RYeY8tBgEpuodCC1mLUdbSN+CYBL7kJsJNInOP8UjDDEwdk6Mw60vdLLrr5NHKZhMAOSrR2NZuQ+w==", - "license": "Apache-2.0", - "optional": true, - "dependencies": { - "safe-buffer": "^5.0.1" - }, - "engines": { - "node": "*" - } - }, - "node_modules/tween-functions": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/tween-functions/-/tween-functions-1.2.0.tgz", - "integrity": "sha512-PZBtLYcCLtEcjL14Fzb1gSxPBeL7nWvGhO5ZFPGqziCcr8uvHp0NDmdjBchp6KHL+tExcg0m3NISmKxhU394dA==", - "dev": true, - "license": "BSD" - }, - "node_modules/type-check": { - "version": "0.4.0", - "resolved": "https://registry.npmjs.org/type-check/-/type-check-0.4.0.tgz", - "integrity": "sha512-XleUoc9uwGXqjWwXaUTZAmzMcFZ5858QA2vvx1Ur5xIcixXIP+8LnFDgRplU30us6teqdlskFfu+ae4K79Ooew==", - "dev": true, - "license": "MIT", - "dependencies": { - "prelude-ls": "^1.2.1" - }, - "engines": { - "node": ">= 0.8.0" - } - }, - "node_modules/type-detect": { - "version": "4.0.8", - "resolved": "https://registry.npmjs.org/type-detect/-/type-detect-4.0.8.tgz", - "integrity": "sha512-0fr/mIH1dlO+x7TlcMy+bIDqKPsw/70tVyeHW787goQjhmqaZe10uwLujubK9q9Lg6Fiho1KUKDYz0Z7k7g5/g==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=4" - } - }, - "node_modules/type-fest": { - "version": "2.19.0", - "resolved": "https://registry.npmjs.org/type-fest/-/type-fest-2.19.0.tgz", - "integrity": "sha512-RAH822pAdBgcNMAfWnCBU3CFZcfZ/i1eZjwFU/dsLKumyuuP3niueg2UAukXYF0E2AAoc82ZSSf9J0WQBinzHA==", - "dev": true, - "license": "(MIT OR CC0-1.0)", - "engines": { - "node": ">=12.20" - }, - "funding": { - "url": "https://github.com/sponsors/sindresorhus" + "node": ">=12.20" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" } }, "node_modules/typedarray-to-buffer": { @@ -14963,11 +14191,12 @@ } }, "node_modules/typescript": { - "version": "5.7.3", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.3.tgz", - "integrity": "sha512-84MVSjMEHP+FQRPy3pX9sTVV/INIex71s9TL2Gm5FG/WG1SqXeKyZ0k7/blY/4FdOzI12CBy1vGc4og/eus0fw==", + "version": "5.7.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.7.2.tgz", + "integrity": "sha512-i5t66RHxDvVN40HfDd1PsEThGNnlMCMT3jMUuoh9/0TaqWevNontacunWyN02LA9/fIbEWlcHZcgTKb9QoaLfg==", "dev": true, "license": "Apache-2.0", + "peer": true, "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" @@ -15145,13 +14374,6 @@ "uuid": "dist/bin/uuid" } }, - "node_modules/v8-compile-cache-lib": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/v8-compile-cache-lib/-/v8-compile-cache-lib-3.0.1.tgz", - "integrity": "sha512-wa7YjyUGfNZngI/vtK0UHAN+lgDCxBPCylVXGp0zu59Fz5aiGtNXaq3DhIov063MorB+VfufLh3JlF2KdTK3xg==", - "dev": true, - "license": "MIT" - }, "node_modules/v8-to-istanbul": { "version": "8.1.1", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-8.1.1.tgz", @@ -15573,16 +14795,6 @@ "node": ">=10" } }, - "node_modules/yn": { - "version": "3.1.1", - "resolved": "https://registry.npmjs.org/yn/-/yn-3.1.1.tgz", - "integrity": "sha512-Ux4ygGWsu2c7isFWe8Yu1YluJmqVhxqK2cLXNQA5AcC3QfbGNpM7fu0Y8b/z16pXLnFxZYvWhd3fhBY9DLmC6Q==", - "dev": true, - "license": "MIT", - "engines": { - "node": ">=6" - } - }, "node_modules/yocto-queue": { "version": "0.1.0", "resolved": "https://registry.npmjs.org/yocto-queue/-/yocto-queue-0.1.0.tgz", diff --git a/packages/tools/package.json b/packages/tools/package.json index c3e6cebd..24adad83 100644 --- a/packages/tools/package.json +++ b/packages/tools/package.json @@ -5,72 +5,58 @@ "private": false, "main": "dist/index.cjs.js", "module": "dist/index.esm.js", - "types": "dist/index.d.ts", "exports": { ".": { "import": "./dist/index.esm.js", - "require": "./dist/index.cjs.js", - "types": "./dist/index.d.ts" + "require": "./dist/index.cjs.js" }, "./firecrawl": { "import": "./dist/firecrawl/index.esm.js", - "require": "./dist/firecrawl/index.cjs.js", - "types": "./dist/firecrawl/index.d.ts" + "require": "./dist/firecrawl/index.cjs.js" }, "./tavily": { "import": "./dist/tavily/index.esm.js", - "require": "./dist/tavily/index.cjs.js", - "types": "./dist/tavily/index.d.ts" + "require": "./dist/tavily/index.cjs.js" }, "./serper": { "import": "./dist/serper/index.esm.js", - "require": "./dist/serper/index.cjs.js", - "types": "./dist/serper/index.d.ts" + "require": "./dist/serper/index.cjs.js" }, "./exa": { "import": "./dist/exa/index.esm.js", - "require": "./dist/exa/index.cjs.js", - "types": "./dist/exa/index.d.ts" + "require": "./dist/exa/index.cjs.js" }, "./wolframalpha": { "import": "./dist/wolframalpha/index.esm.js", - "require": "./dist/wolframalpha/index.cjs.js", - "types": "./dist/wolframalpha/index.d.ts" + "require": "./dist/wolframalpha/index.cjs.js" }, "./simple-rag": { "import": "./dist/simple-rag/index.esm.js", - "require": "./dist/simple-rag/index.cjs.js", - "types": "./dist/simple-rag/index.d.ts" + "require": "./dist/simple-rag/index.cjs.js" }, "./website-search": { "import": "./dist/website-search/index.esm.js", - "require": "./dist/website-search/index.cjs.js", - "types": "./dist/website-search/index.d.ts" + "require": "./dist/website-search/index.cjs.js" }, "./pdf-search": { "import": "./dist/pdf-search/index.esm.js", - "require": "./dist/pdf-search/index.cjs.js", - "types": "./dist/pdf-search/index.d.ts" + "require": "./dist/pdf-search/index.cjs.js" }, "./textfile-search": { "import": "./dist/textfile-search/index.esm.js", - "require": "./dist/textfile-search/index.cjs.js", - "types": "./dist/textfile-search/index.d.ts" + "require": "./dist/textfile-search/index.cjs.js" }, "./zapier-webhook": { "import": "./dist/zapier-webhook/index.esm.js", - "require": "./dist/zapier-webhook/index.cjs.js", - "types": "./dist/zapier-webhook/index.d.ts" + "require": "./dist/zapier-webhook/index.cjs.js" }, "./make-webhook": { "import": "./dist/make-webhook/index.esm.js", - "require": "./dist/make-webhook/index.cjs.js", - "types": "./dist/make-webhook/index.d.ts" + "require": "./dist/make-webhook/index.cjs.js" }, "./jina-url-to-markdown": { "import": "./dist/jina-url-to-markdown/index.esm.js", - "require": "./dist/jina-url-to-markdown/index.cjs.js", - "types": "./dist/jina-url-to-markdown/index.d.ts" + "require": "./dist/jina-url-to-markdown/index.cjs.js" } }, "files": [ @@ -133,7 +119,6 @@ "@rollup/plugin-node-resolve": "^15.3.0", "@rollup/plugin-replace": "^6.0.1", "@rollup/plugin-terser": "^0.4.4", - "@rollup/plugin-typescript": "^12.1.2", "@storybook/addon-essentials": "^8.3.6", "@storybook/addon-interactions": "^8.3.6", "@storybook/addon-links": "^8.3.6", @@ -142,7 +127,6 @@ "@storybook/react": "^8.3.6", "@storybook/react-vite": "^8.3.6", "@storybook/test": "^8.3.6", - "@types/node": "^22.13.4", "babel-jest": "^29.7.0", "eslint": "^8.4.1", "eslint-plugin-storybook": "^0.10.1", @@ -152,8 +136,6 @@ "rollup": "^4.24.0", "rollup-plugin-node-polyfills": "^0.2.1", "storybook": "^8.3.6", - "tslib": "^2.8.1", - "typescript": "^5.7.3", "undici": "^6.20.1" }, "eslintConfig": { diff --git a/packages/tools/rollup.config.mjs b/packages/tools/rollup.config.mjs index ea916d0a..3e90a620 100644 --- a/packages/tools/rollup.config.mjs +++ b/packages/tools/rollup.config.mjs @@ -5,7 +5,6 @@ import terser from '@rollup/plugin-terser'; import json from '@rollup/plugin-json'; import nodePolyfills from 'rollup-plugin-node-polyfills'; // Correct plugin name import replace from '@rollup/plugin-replace'; -import typescript from '@rollup/plugin-typescript'; // Array of tool folder names const toolFolders = [ @@ -25,7 +24,7 @@ const toolFolders = [ ]; // Add more folder names as needed const toolConfigs = toolFolders.map((tool) => { - const inputPath = `src/${tool}/index.ts`; + const inputPath = `src/${tool}/index.js`; // Adjusted for plain JavaScript return defineConfig({ input: inputPath, @@ -49,19 +48,9 @@ const toolConfigs = toolFolders.map((tool) => { 'pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js', ], plugins: [ - typescript({ - tsconfig: './tsconfig.json', - declaration: true, - declarationDir: `dist/${tool}/`, - outDir: `./dist/${tool}`, - rootDir: `./src/${tool}/`, - }), nodeResolve({ browser: true, preferBuiltins: false, // Use polyfills for Node built-in modules - extensions: ['.ts', '.js', '.json'], - moduleDirectories: ['node_modules', 'src'], - preserveSymlinks: true, }), commonjs(), json(), @@ -81,7 +70,7 @@ const toolConfigs = toolFolders.map((tool) => { // Main index config const mainConfig = defineConfig({ - input: 'src/index.ts', + input: 'src/index.js', output: [ { file: 'dist/index.cjs.js', @@ -102,12 +91,6 @@ const mainConfig = defineConfig({ 'pdf-parse/lib/pdf.js/v1.10.100/build/pdf.js', ], plugins: [ - typescript({ - tsconfig: './tsconfig.json', - declaration: true, - declarationDir: `./dist/`, - rootDir: './src/', - }), nodeResolve({ browser: true, preferBuiltins: false, @@ -126,9 +109,8 @@ const mainConfig = defineConfig({ }), ], }); - const ragToolkitConfig = defineConfig({ - input: 'src/_utils/rag/ragToolkit.ts', + input: 'src/_utils/rag/ragToolkit.js', output: [ { file: 'dist/rag-toolkit/index.cjs.js', @@ -144,12 +126,6 @@ const ragToolkitConfig = defineConfig({ }, ], plugins: [ - typescript({ - tsconfig: './tsconfig.json', - declaration: true, - declarationDir: './dist/rag-toolkit/', - rootDir: './src/_utils/rag/', - }), nodeResolve({ browser: true, preferBuiltins: false, @@ -158,15 +134,6 @@ const ragToolkitConfig = defineConfig({ json(), nodePolyfills(), terser(), - replace({ - preventAssignment: true, - values: { - 'node:fs/promises': 'fs/promises', - 'Promise.withResolvers': - '(() => ({ promise: new Promise(() => {}), resolve: () => {}, reject: () => {} }))', - }, - }), ], }); - export default [ragToolkitConfig, ...toolConfigs, mainConfig]; diff --git a/packages/tools/src/_utils/rag/loaders/browserPDFLoader/index.ts b/packages/tools/src/_utils/rag/loaders/browserPDFLoader.js similarity index 59% rename from packages/tools/src/_utils/rag/loaders/browserPDFLoader/index.ts rename to packages/tools/src/_utils/rag/loaders/browserPDFLoader.js index 7020c807..4d19fad8 100644 --- a/packages/tools/src/_utils/rag/loaders/browserPDFLoader/index.ts +++ b/packages/tools/src/_utils/rag/loaders/browserPDFLoader.js @@ -1,46 +1,15 @@ import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; import { Document as BaseDocument } from 'langchain/document'; +// import { getDocument, GlobalWorkerOptions } from 'pdfjs-dist'; -interface PDFMetadata { - [key: string]: any; -} - -interface PDFTextItem { - str?: string; - [key: string]: any; -} - -interface PDFPage { - getTextContent(): Promise<{ items: PDFTextItem[] }>; -} - -interface PDFDocument { - numPages: number; - getPage(pageNum: number): Promise; -} - -interface PDFDocumentProxy { - promise: Promise; -} - -interface PDFLib { - getDocument(data: Uint8Array): PDFDocumentProxy; - GlobalWorkerOptions: { - workerSrc: string; - }; -} - -export class BrowserPDFLoader extends BaseDocumentLoader { - private file: string | File; - private metadata: PDFMetadata; - - constructor(file: string | File, metadata: PDFMetadata = {}) { +class BrowserPDFLoader extends BaseDocumentLoader { + constructor(file, metadata = {}) { super(); this.file = file; this.metadata = metadata; } - async load(): Promise { + async load() { if (!this.file) { console.log('No file selected.'); return []; @@ -53,28 +22,26 @@ export class BrowserPDFLoader extends BaseDocumentLoader { } try { - const { getDocument, GlobalWorkerOptions } = (await import( - 'pdfjs-dist' - )) as PDFLib; + const { getDocument, GlobalWorkerOptions } = await import('pdfjs-dist'); GlobalWorkerOptions.workerSrc = 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.8.69/pdf.worker.min.mjs'; const fileReader = new FileReader(); - const fileReaderPromise = new Promise((resolve, reject) => { + const fileReaderPromise = new Promise((resolve, reject) => { fileReader.onload = () => { - resolve(new Uint8Array(fileReader.result as ArrayBuffer)); + resolve(new Uint8Array(fileReader.result)); }; fileReader.onerror = (error) => { reject(error); }; }); - fileReader.readAsArrayBuffer(this.file as File); + fileReader.readAsArrayBuffer(this.file); const typedArray = await fileReaderPromise; const pdf = await getDocument(typedArray).promise; - const pagesContent: string[] = []; + const pagesContent = []; for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) { const page = await pdf.getPage(pageNum); @@ -94,8 +61,11 @@ export class BrowserPDFLoader extends BaseDocumentLoader { ); return documents; - } catch (_error) { + } catch { + // console.log('Error loading PDF:', error); throw new Error('Error loading PDF.'); } } } + +export { BrowserPDFLoader }; diff --git a/packages/tools/src/textfile-search/rag/loaders/textInputLoader/index.ts b/packages/tools/src/_utils/rag/loaders/textInputLoader.js similarity index 55% rename from packages/tools/src/textfile-search/rag/loaders/textInputLoader/index.ts rename to packages/tools/src/_utils/rag/loaders/textInputLoader.js index c71933b4..c6b8b156 100644 --- a/packages/tools/src/textfile-search/rag/loaders/textInputLoader/index.ts +++ b/packages/tools/src/_utils/rag/loaders/textInputLoader.js @@ -1,21 +1,14 @@ import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; import { Document as BaseDocument } from 'langchain/document'; -interface TextInputMetadata { - [key: string]: any; -} - -export class TextInputLoader extends BaseDocumentLoader { - private text: string; - private metadata: TextInputMetadata; - - constructor(text: string, metadata: TextInputMetadata = {}) { +class TextInputLoader extends BaseDocumentLoader { + constructor(text, metadata = {}) { super(); this.text = text; this.metadata = metadata; } - async load(): Promise { + async load() { const document = new BaseDocument({ pageContent: this.text, metadata: this.metadata, @@ -23,3 +16,5 @@ export class TextInputLoader extends BaseDocumentLoader { return [document]; } } + +export { TextInputLoader }; diff --git a/packages/tools/src/_utils/rag/loaders/textInputLoader/index.ts b/packages/tools/src/_utils/rag/loaders/textInputLoader/index.ts deleted file mode 100644 index c71933b4..00000000 --- a/packages/tools/src/_utils/rag/loaders/textInputLoader/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document as BaseDocument } from 'langchain/document'; - -interface TextInputMetadata { - [key: string]: any; -} - -export class TextInputLoader extends BaseDocumentLoader { - private text: string; - private metadata: TextInputMetadata; - - constructor(text: string, metadata: TextInputMetadata = {}) { - super(); - this.text = text; - this.metadata = metadata; - } - - async load(): Promise { - const document = new BaseDocument({ - pageContent: this.text, - metadata: this.metadata, - }); - return [document]; - } -} diff --git a/packages/tools/src/textfile-search/rag/ragToolkit.ts b/packages/tools/src/_utils/rag/ragToolkit.js similarity index 57% rename from packages/tools/src/textfile-search/rag/ragToolkit.ts rename to packages/tools/src/_utils/rag/ragToolkit.js index e05e53e6..cd7c9c5e 100644 --- a/packages/tools/src/textfile-search/rag/ragToolkit.ts +++ b/packages/tools/src/_utils/rag/ragToolkit.js @@ -1,43 +1,17 @@ +// import { TextLoader } from "langchain/document_loaders/fs/text"; +// import { PDFLoader } from "@langchain/community/document_loaders/fs/pdf"; +// import { CheerioWebBaseLoader } from "@langchain/community/document_loaders/web/cheerio"; import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter'; import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai'; import { MemoryVectorStore } from 'langchain/vectorstores/memory'; import { PromptTemplate } from '@langchain/core/prompts'; import { createStuffDocumentsChain } from 'langchain/chains/combine_documents'; import { StringOutputParser } from '@langchain/core/output_parsers'; -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document } from 'langchain/document'; +// import { BrowserPDFLoader } from "./utils/loaders/BrowserPDFLoader"; import { TextInputLoader } from './loaders/textInputLoader'; -interface RAGToolkitOptions { - embeddings?: OpenAIEmbeddings; - vectorStore?: MemoryVectorStore; - llmInstance?: ChatOpenAI; - promptQuestionTemplate?: string; - chunkOptions?: { - chunkSize: number; - chunkOverlap: number; - }; - env?: { - OPENAI_API_KEY: string; - }; -} - -interface DocumentSource { - source: string | File; - type: string; -} - -type LoaderFunction = (source: string | File) => BaseDocumentLoader; - -export class RAGToolkit { - private embeddings: OpenAIEmbeddings; - private vectorStore: MemoryVectorStore; - private llmInstance: ChatOpenAI; - private promptQuestionTemplate: string; - private chunkOptions: { chunkSize: number; chunkOverlap: number }; - private loaders: Record; - - constructor(options: RAGToolkitOptions = {}) { +class RAGToolkit { + constructor(options = {}) { this.embeddings = options.embeddings || new OpenAIEmbeddings({ apiKey: options?.env?.OPENAI_API_KEY }); @@ -64,31 +38,24 @@ export class RAGToolkit { }; this.loaders = { - string: (source: string | File) => new TextInputLoader(source as string), + string: (source) => new TextInputLoader(source), }; } - registerLoader(type: string, loaderFunction: LoaderFunction): void { + registerLoader(type, loaderFunction) { if (this.loaders[type]) { throw new Error(`Loader type '${type}' is already registered.`); } this.loaders[type] = loaderFunction; } - async addDocuments(sources: DocumentSource[]): Promise { + async addDocuments(sources) { const documents = await this.loadDocuments(sources); const chunks = await this.chunkDocuments(documents); - if (this.vectorStore instanceof MemoryVectorStore) { - await this.vectorStore.addDocuments(chunks); - } else { - // Used for vector stores like Pinecone or Supabase - // Convert to vector store type - const vectorStore = this.vectorStore as any; - await vectorStore.addDocuments(chunks, this.embeddings); - } + await this.vectorStore.addDocuments(chunks, this.embeddings); } - async loadDocuments(sources: DocumentSource[]): Promise { + async loadDocuments(sources) { const promises = sources.map(({ source, type }) => { const loaderFn = this.loaders[type]; if (!loaderFn) { @@ -100,17 +67,17 @@ export class RAGToolkit { return results.flat(); } - async chunkDocuments(documents: Document[]): Promise { + async chunkDocuments(documents) { const splitter = new RecursiveCharacterTextSplitter(this.chunkOptions); return splitter.splitDocuments(documents); } - async search(query: string): Promise { + async search(query) { const retriever = this.vectorStore.asRetriever(); return retriever.invoke(query); } - async askQuestion(query: string): Promise { + async askQuestion(query) { const retriever = this.vectorStore.asRetriever(); const context = await retriever.invoke(query); @@ -120,10 +87,12 @@ export class RAGToolkit { const chain = await createStuffDocumentsChain({ llm: this.llmInstance, - prompt: promptTemplate as any, - outputParser: new StringOutputParser() as any, + prompt: promptTemplate, + outputParser: new StringOutputParser(), }); return chain.invoke({ question: query, context }); } } + +export default RAGToolkit; diff --git a/packages/tools/src/_utils/rag/ragToolkit.ts b/packages/tools/src/_utils/rag/ragToolkit.ts deleted file mode 100644 index e05e53e6..00000000 --- a/packages/tools/src/_utils/rag/ragToolkit.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter'; -import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai'; -import { MemoryVectorStore } from 'langchain/vectorstores/memory'; -import { PromptTemplate } from '@langchain/core/prompts'; -import { createStuffDocumentsChain } from 'langchain/chains/combine_documents'; -import { StringOutputParser } from '@langchain/core/output_parsers'; -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document } from 'langchain/document'; -import { TextInputLoader } from './loaders/textInputLoader'; - -interface RAGToolkitOptions { - embeddings?: OpenAIEmbeddings; - vectorStore?: MemoryVectorStore; - llmInstance?: ChatOpenAI; - promptQuestionTemplate?: string; - chunkOptions?: { - chunkSize: number; - chunkOverlap: number; - }; - env?: { - OPENAI_API_KEY: string; - }; -} - -interface DocumentSource { - source: string | File; - type: string; -} - -type LoaderFunction = (source: string | File) => BaseDocumentLoader; - -export class RAGToolkit { - private embeddings: OpenAIEmbeddings; - private vectorStore: MemoryVectorStore; - private llmInstance: ChatOpenAI; - private promptQuestionTemplate: string; - private chunkOptions: { chunkSize: number; chunkOverlap: number }; - private loaders: Record; - - constructor(options: RAGToolkitOptions = {}) { - this.embeddings = - options.embeddings || - new OpenAIEmbeddings({ apiKey: options?.env?.OPENAI_API_KEY }); - this.vectorStore = - options.vectorStore || new MemoryVectorStore(this.embeddings); - this.llmInstance = - options.llmInstance || - new ChatOpenAI({ - model: 'gpt-4o-mini', - temperature: 0, - apiKey: options?.env?.OPENAI_API_KEY, - }); - this.promptQuestionTemplate = - options.promptQuestionTemplate || - ` - Use the following pieces of context to answer the question at the end. - If you don't know the answer, just say that you don't know. - Context: {context} - Question: {question} - `; - this.chunkOptions = options.chunkOptions || { - chunkSize: 1000, - chunkOverlap: 200, - }; - - this.loaders = { - string: (source: string | File) => new TextInputLoader(source as string), - }; - } - - registerLoader(type: string, loaderFunction: LoaderFunction): void { - if (this.loaders[type]) { - throw new Error(`Loader type '${type}' is already registered.`); - } - this.loaders[type] = loaderFunction; - } - - async addDocuments(sources: DocumentSource[]): Promise { - const documents = await this.loadDocuments(sources); - const chunks = await this.chunkDocuments(documents); - if (this.vectorStore instanceof MemoryVectorStore) { - await this.vectorStore.addDocuments(chunks); - } else { - // Used for vector stores like Pinecone or Supabase - // Convert to vector store type - const vectorStore = this.vectorStore as any; - await vectorStore.addDocuments(chunks, this.embeddings); - } - } - - async loadDocuments(sources: DocumentSource[]): Promise { - const promises = sources.map(({ source, type }) => { - const loaderFn = this.loaders[type]; - if (!loaderFn) { - throw new Error(`Unsupported loader type: ${type}`); - } - return loaderFn(source).load(); - }); - const results = await Promise.all(promises); - return results.flat(); - } - - async chunkDocuments(documents: Document[]): Promise { - const splitter = new RecursiveCharacterTextSplitter(this.chunkOptions); - return splitter.splitDocuments(documents); - } - - async search(query: string): Promise { - const retriever = this.vectorStore.asRetriever(); - return retriever.invoke(query); - } - - async askQuestion(query: string): Promise { - const retriever = this.vectorStore.asRetriever(); - const context = await retriever.invoke(query); - - const promptTemplate = PromptTemplate.fromTemplate( - this.promptQuestionTemplate - ); - - const chain = await createStuffDocumentsChain({ - llm: this.llmInstance, - prompt: promptTemplate as any, - outputParser: new StringOutputParser() as any, - }); - - return chain.invoke({ question: query, context }); - } -} diff --git a/packages/tools/src/exa/index.ts b/packages/tools/src/exa/index.ts deleted file mode 100644 index 9911b2c5..00000000 --- a/packages/tools/src/exa/index.ts +++ /dev/null @@ -1,202 +0,0 @@ -/** - * Exa Search Tool - * - * This tool integrates with Exa (https://exa.ai/), a search engine for AI that organizes - * the web using embeddings. It provides high-quality web data specifically optimized - * for AI applications. - * - * Key features: - * - Neural Search: Meaning-based search using embeddings - * - Keyword Search: Traditional search capabilities - * - Auto Search: Dynamically chooses between neural and keyword - * - Category-focused search - * - Domain filtering - * - Date filtering - * - Text filtering - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -const API_BASE_URL = 'https://api.exa.ai'; - -type SearchType = 'neural' | 'keyword' | 'auto'; -type Category = - | 'company' - | 'research paper' - | 'news' - | 'github' - | 'tweet' - | 'movie' - | 'song' - | 'personal site' - | 'pdf'; -type LiveCrawl = 'never' | 'fallback' | 'always'; - -interface ContentConfig { - text?: { - maxCharacters: number; - includeHtmlTags: boolean; - }; - highlights?: { - numSentences: number; - highlightsPerUrl: number; - query: string; - }; - summary?: { - query: string; - }; - subpages?: number; - subpageTarget?: number; - livecrawl?: LiveCrawl; - livecrawlTimeout?: number; -} - -interface ExaSearchFields { - apiKey: string; - type?: SearchType; - useAutoprompt?: boolean; - numResults?: number; - category?: Category; - startPublishedDate?: string; - endPublishedDate?: string; - includeDomains?: string[]; - excludeDomains?: string[]; - includeText?: string[]; - excludeText?: string[]; - startCrawlDate?: string; - endCrawlDate?: string; - contents?: ContentConfig; -} - -interface SearchParams { - query: string; - type: SearchType; - useAutoprompt: boolean; - category?: Category; - numResults: number; - includeDomains?: string[]; - excludeDomains?: string[]; - startCrawlDate?: string; - endCrawlDate?: string; - startPublishedDate?: string; - endPublishedDate?: string; - includeText?: string[]; - excludeText?: string[]; - contents?: ContentConfig; -} - -export class ExaSearch extends StructuredTool { - private apiKey: string; - private type: SearchType; - private useAutoprompt: boolean; - private category?: Category; - private numResults: number; - private includeDomains: string[]; - private excludeDomains: string[]; - private startCrawlDate?: string; - private endCrawlDate?: string; - private startPublishedDate?: string; - private endPublishedDate?: string; - private includeText: string[]; - private excludeText: string[]; - private contents?: ContentConfig; - private httpClient: typeof ky; - name = 'exa-search'; - description = - 'A powerful AI-optimized search engine that provides high-quality web data using embeddings-based search.'; - - schema = z.object({ - query: z.string().describe('The search query to look up'), - }); - constructor(fields: ExaSearchFields) { - super(); - - if (fields.type && !['neural', 'keyword', 'auto'].includes(fields.type)) { - throw new Error( - 'Invalid search type. Must be one of: neural, keyword, auto' - ); - } - - this.apiKey = fields.apiKey; - - // Configuration parameters in order of API documentation - this.type = fields.type || 'neural'; - this.useAutoprompt = fields.useAutoprompt || false; - this.category = fields.category; - this.numResults = fields.numResults || 10; - this.includeDomains = fields.includeDomains || []; - this.excludeDomains = fields.excludeDomains || []; - this.startCrawlDate = fields.startCrawlDate; - this.endCrawlDate = fields.endCrawlDate; - this.startPublishedDate = fields.startPublishedDate; - this.endPublishedDate = fields.endPublishedDate; - this.includeText = fields.includeText || []; - this.excludeText = fields.excludeText || []; - this.contents = fields.contents; - - this.httpClient = ky.extend({ - prefixUrl: API_BASE_URL, - headers: { - 'x-api-key': this.apiKey, - 'Content-Type': 'application/json', - }, - }); - } - - async _call(input: { query: string }): Promise { - try { - const searchParams: SearchParams = { - query: input.query, - type: this.type, - useAutoprompt: this.useAutoprompt, - category: this.category, - numResults: this.numResults, - includeDomains: this.includeDomains, - excludeDomains: this.excludeDomains, - startCrawlDate: this.startCrawlDate, - endCrawlDate: this.endCrawlDate, - startPublishedDate: this.startPublishedDate, - endPublishedDate: this.endPublishedDate, - includeText: this.includeText, - excludeText: this.excludeText, - contents: this.contents, - }; - - // Remove undefined and empty values - Object.keys(searchParams).forEach((key) => { - if ( - searchParams[key as keyof SearchParams] === undefined || - (Array.isArray(searchParams[key as keyof SearchParams]) && - (searchParams[key as keyof SearchParams] as unknown[]).length === 0) - ) { - delete searchParams[key as keyof SearchParams]; - } - }); - - const response = await this.httpClient - .post('search', { - json: searchParams, - }) - .json(); - - return response; - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${ - error instanceof Error ? error.message : String(error) - }`; - } - } - } -} diff --git a/packages/tools/src/exa/tool.stories.jsx b/packages/tools/src/exa/tool.stories.jsx index 96f226bc..9625455f 100644 --- a/packages/tools/src/exa/tool.stories.jsx +++ b/packages/tools/src/exa/tool.stories.jsx @@ -1,5 +1,5 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; -import { ExaSearch } from './index.ts'; +import { ExaSearch } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; diff --git a/packages/tools/src/firecrawl/index.ts b/packages/tools/src/firecrawl/index.ts deleted file mode 100644 index 7f7d6673..00000000 --- a/packages/tools/src/firecrawl/index.ts +++ /dev/null @@ -1,84 +0,0 @@ -/** - * Firecrawl - * - * This tool integrates with Firecrawl (https://www.firecrawl.dev/), a web scraping - * and crawling service designed to turn websites into LLM-ready data. - * - * Firecrawl allows you to extract clean, well-formatted markdown or structured data - * from websites, making it ideal for AI applications, particularly those using - * Large Language Models (LLMs). - * - * Key features of Firecrawl: - * - Scrapes and crawls websites, even those with dynamic content - * - Converts web content into clean, LLM-ready markdown - * - Handles challenges like rate limits, JavaScript rendering, and anti-bot mechanisms - * - Offers flexible pricing plans, including a free tier for small-scale use - * - * For more information about Firecrawl, visit: https://www.firecrawl.dev/ - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -interface FirecrawlFields { - apiKey: string; - format?: string; -} - -export class Firecrawl extends StructuredTool { - private apiKey: string; - private format: string; - private mode: string; - private httpClient: typeof ky; - name = 'firecrawl'; - description: string; - schema = z.object({ - url: z.string().describe('The URL to scrape and retrieve content from.'), - }); - - constructor(fields: FirecrawlFields) { - super(); - - this.apiKey = fields.apiKey; - this.format = fields.format || 'markdown'; - this.mode = 'scrape'; - this.description = `Fetches web content from a specified URL and returns it in ${this.format} format. Input should be a JSON object with a "url".`; - this.httpClient = ky; - } - - async _call(input: { url: string }): Promise { - try { - const response = await this.httpClient - .post('https://api.firecrawl.dev/v1/scrape', { - json: { - url: input.url, - formats: [this.format], - }, - headers: { - Authorization: `Bearer ${this.apiKey}`, - }, - }) - .json<{ data?: { [key: string]: string } }>(); - - return ( - response?.data?.[this.format] || 'The API returned an empty response.' - ); - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${ - error instanceof Error ? error.message : String(error) - }`; - } - } - } -} diff --git a/packages/tools/src/firecrawl/tool.stories.jsx b/packages/tools/src/firecrawl/tool.stories.jsx index 27d485ff..b402e89a 100644 --- a/packages/tools/src/firecrawl/tool.stories.jsx +++ b/packages/tools/src/firecrawl/tool.stories.jsx @@ -1,6 +1,6 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { Firecrawl } from './index.ts'; +import { Firecrawl } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/src/github-issues/index.ts b/packages/tools/src/github-issues/index.ts deleted file mode 100644 index e67a854f..00000000 --- a/packages/tools/src/github-issues/index.ts +++ /dev/null @@ -1,198 +0,0 @@ -/** - * GitHub Issues - * - * This tool integrates with GitHub's API to fetch issues from specified repositories. - * It provides a clean, structured way to retrieve open issues, making it ideal for - * monitoring and analysis purposes. - * - * Key features: - * - Fetches open issues from any public GitHub repository - * - Handles pagination automatically - * - Returns structured data with issue details - * - Includes metadata like issue numbers, titles, labels, and descriptions - * - * Authentication: - * - Works without authentication for public repositories (60 requests/hour limit) - * - Optional GitHub token for higher rate limits (5,000 requests/hour) - * - * Rate Limits: - * - Authenticated: 5,000 requests per hour - * - Unauthenticated: 60 requests per hour - * - * For more information about GitHub's API, visit: https://docs.github.com/en/rest - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -interface GithubIssuesFields { - token?: string; - limit?: number; -} - -interface RepoInfo { - owner: string; - repo: string; -} - -interface GitHubIssue { - number: number; - title: string; - html_url: string; - labels: Array<{ name: string }>; - body?: string; -} - -interface FormattedResponse { - repository: { - name: string; - url: string; - owner: string; - }; - metadata: { - totalIssues: number; - lastUpdated: string; - limit: number; - }; - issues: Array<{ - number: number; - title: string; - url: string; - labels: string[]; - description: string; - }>; -} - -export class GithubIssues extends StructuredTool { - private token?: string; - private limit: number; - private httpClient: typeof ky; - name = 'github-issues'; - description = - 'Fetches open issues from a specified GitHub repository. Input should include the repository URL.'; - schema = z.object({ - repoUrl: z - .string() - .url() - .describe( - 'The GitHub repository URL (e.g., https://github.com/owner/repo)' - ), - }); - - constructor(fields: GithubIssuesFields = {}) { - super(); - this.token = fields.token; - this.limit = fields.limit || 10; - this.httpClient = ky; - } - - async _call(input: { repoUrl: string }): Promise { - try { - const { owner, repo } = this._parseRepoUrl(input.repoUrl); - const issues = await this._fetchIssues({ owner, repo }); - return this._formatResponse(issues, { owner, repo }); - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${ - error instanceof Error ? error.message : String(error) - }`; - } - } - } - - private async _fetchIssues({ - owner, - repo, - }: RepoInfo): Promise { - let page = 1; - let allIssues: GitHubIssue[] = []; - const headers: Record = { - Accept: 'application/vnd.github.v3+json', - }; - - if (this.token) { - headers.Authorization = `Bearer ${this.token}`; - } - - let hasMorePages = true; - while (hasMorePages) { - const issues = await this.httpClient - .get(`https://api.github.com/repos/${owner}/${repo}/issues`, { - searchParams: { - page: String(page), - per_page: '100', - state: 'open', - }, - headers, - timeout: 10000, - }) - .json(); - - if (!Array.isArray(issues) || issues.length === 0) { - hasMorePages = false; - break; - } - - allIssues = allIssues.concat(issues); - if (allIssues.length >= this.limit) { - allIssues = allIssues.slice(0, this.limit); - hasMorePages = false; - break; - } - page++; - } - - return allIssues; - } - - private _formatResponse( - issues: GitHubIssue[], - input: RepoInfo - ): FormattedResponse { - const { owner, repo } = input; - const repoUrl = `https://github.com/${owner}/${repo}`; - const today = new Date().toISOString().split('T')[0]; - - return { - repository: { - name: repo, - url: repoUrl, - owner: owner, - }, - metadata: { - totalIssues: issues.length, - lastUpdated: today, - limit: this.limit, - }, - issues: issues.map((issue) => ({ - number: issue.number, - title: issue.title, - url: issue.html_url, - labels: issue.labels.map((label) => label.name), - description: issue.body || 'No description provided', - })), - }; - } - - private _parseRepoUrl(url: string): RepoInfo { - try { - const path = new URL(url).pathname.split('/').filter(Boolean); - if (path.length < 2) { - throw new Error('Invalid GitHub repository URL'); - } - return { owner: path[0], repo: path[1] }; - } catch (_error) { - throw new Error('Invalid GitHub repository URL'); - } - } -} diff --git a/packages/tools/src/github-issues/tool.stories.jsx b/packages/tools/src/github-issues/tool.stories.jsx index 39d72696..3911bd0c 100644 --- a/packages/tools/src/github-issues/tool.stories.jsx +++ b/packages/tools/src/github-issues/tool.stories.jsx @@ -1,6 +1,6 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { GithubIssues } from './index.ts'; +import { GithubIssues } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/src/index.js b/packages/tools/src/index.js new file mode 100644 index 00000000..2f9acf09 --- /dev/null +++ b/packages/tools/src/index.js @@ -0,0 +1,13 @@ +export * from './firecrawl/index.js'; +export * from './tavily/index.js'; +export * from './github-issues/index.js'; +export * from './serper/index.js'; +export * from './wolfram-alpha/index.js'; +export * from './exa/index.js'; +export * from './simple-rag/index.js'; +export * from './website-search/index.js'; +export * from './pdf-search/index.js'; +export * from './textfile-search/index.js'; +export * from './zapier-webhook/index.js'; +export * from './make-webhook/index.js'; +export * from './jina-url-to-markdown/index.js'; diff --git a/packages/tools/src/index.ts b/packages/tools/src/index.ts deleted file mode 100644 index 30d887d9..00000000 --- a/packages/tools/src/index.ts +++ /dev/null @@ -1,17 +0,0 @@ -/** - * Export all tools from this package - */ - -export { JinaUrlToMarkdown } from './jina-url-to-markdown'; -export { SimpleRAG } from './simple-rag'; -export { TextFileSearch } from './textfile-search'; -export { WebsiteSearch } from './website-search'; -export { PdfSearch } from './pdf-search'; -export { ZapierWebhook } from './zapier-webhook'; -export { MakeWebhook } from './make-webhook'; -export { Firecrawl } from './firecrawl'; -export { TavilySearchResults } from './tavily'; -export { GithubIssues } from './github-issues'; -export { Serper } from './serper'; -export { WolframAlphaTool } from './wolfram-alpha'; -export { ExaSearch } from './exa'; diff --git a/packages/tools/src/jina-url-to-markdown/index.ts b/packages/tools/src/jina-url-to-markdown/index.ts deleted file mode 100644 index 9e510f19..00000000 --- a/packages/tools/src/jina-url-to-markdown/index.ts +++ /dev/null @@ -1,92 +0,0 @@ -/** - * Jina URL to Markdown - * - * This tool integrates with Jina (https://jina.ai/), a web scraping - * and crawling service designed to turn websites into LLM-ready data. - * - * Jina allows you to extract clean, well-formatted markdown or structured data - * from websites, making it ideal for AI applications, particularly those using - * Large Language Models (LLMs). - * - * Key features of Jina: - * - Scrapes and crawls websites, even those with dynamic content - * - Converts web content into clean, LLM-ready markdown - * - Handles challenges like rate limits, JavaScript rendering, and anti-bot mechanisms - * - Offers flexible pricing plans, including a free tier for small-scale use - * - * Usage: - * const tool = new JinaUrlToMarkdown(); - * const result = await tool._call({ url: 'https://example.com' }); - * or - * const tool = new JinaUrlToMarkdown({ apiKey: 'your-api-key', options: { 'targetSelector': ['body', '.class', '#id'], 'retainImages': 'none' } }); - * const result = await tool._call({ url: 'https://example.com' }); - * - * For more information about Jina, visit: https://jina.ai/, https://r.jina.ai/docs - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -interface JinaUrlToMarkdownFields { - apiKey?: string; - options?: Record; -} - -interface JinaUrlToMarkdownInput { - url: string; -} - -export class JinaUrlToMarkdown extends StructuredTool { - name = 'jina-url-to-markdown'; - description = `Fetches web content from a specified URL and returns it in Markdown format. Input should be a JSON object with a "url".`; - apiKey?: string; - options: Record; - headers: Record; - schema = z.object({ - url: z.string().describe('The URL to scrape and retrieve content from.'), - }); - httpClient: typeof ky; - - constructor(fields?: JinaUrlToMarkdownFields) { - super(); - this.apiKey = fields?.apiKey; - this.options = fields?.options || {}; - this.headers = { 'Content-Type': 'application/json' }; - - if (this.apiKey) { - this.headers.Authorization = `Bearer ${this.apiKey}`; - } - - this.httpClient = ky; - } - - async _call(input: JinaUrlToMarkdownInput): Promise { - try { - const response = await this.httpClient - .post(`https://r.jina.ai/`, { - json: { - url: input.url, - ...this.options, - }, - headers: this.headers, - }) - .json<{ data?: string }>(); - - return response?.data || 'The API returned an empty response.'; - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${(error as Error).message}`; - } - } - } -} diff --git a/packages/tools/src/jina-url-to-markdown/tool.stories.jsx b/packages/tools/src/jina-url-to-markdown/tool.stories.jsx index 6e0e76ee..1579637b 100644 --- a/packages/tools/src/jina-url-to-markdown/tool.stories.jsx +++ b/packages/tools/src/jina-url-to-markdown/tool.stories.jsx @@ -1,6 +1,6 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { JinaUrlToMarkdown } from './index.ts'; +import { JinaUrlToMarkdown } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/src/make-webhook/index.ts b/packages/tools/src/make-webhook/index.ts deleted file mode 100644 index 47a7262b..00000000 --- a/packages/tools/src/make-webhook/index.ts +++ /dev/null @@ -1,83 +0,0 @@ -/** - * Make Webhook Tool - * - * This tool allows integration with Make's webhook service, enabling seamless - * interaction with thousands of apps and services supported by Make. It is - * designed to trigger workflows and automate tasks across various applications - * using Make's webhook functionality. - * - * Key features of Make Webhook Tool: - * - Easy integration with Make's webhook service - * - Trigger workflows and automate tasks across thousands of apps - * - Configurable options for webhook events and payloads - * - * For more information about Make, visit: https://Make.com/ - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -interface MakeWebhookFields { - url: string; - schema: z.ZodObject; -} - -export class MakeWebhook extends StructuredTool { - private url: string; - private httpClient: typeof ky; - name = 'make_webhook'; - description = - 'A tool for triggering Make webhooks to integrate with various services. Input should be a JSON object with the necessary data for the webhook.'; - schema: z.ZodObject; - - /** - * Create a MakeWebhook tool. - * @param fields - The configuration fields for the tool. - * @param fields.url - The Make webhook URL. - * @param fields.schema - The schema for the input data using Zod. - */ - constructor(fields: MakeWebhookFields) { - super(); - this.url = fields.url; - this.schema = fields.schema; - this.httpClient = ky; - } - - /** - * Call the Make webhook with the provided input data. - * @param input - The input data for the webhook. - * @returns The response from the webhook. - */ - async _call(input: z.infer): Promise { - try { - const response = await this.httpClient.post(this.url, { - json: input, - headers: { - 'Content-Type': 'application/json', - }, - }); - - if (!response.ok) { - return 'Could not parse Make webhook response. Please try again.'; - } - - return 'Webhook response success'; - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${ - error instanceof Error ? error.message : String(error) - }`; - } - } - } -} diff --git a/packages/tools/src/make-webhook/tool.stories.jsx b/packages/tools/src/make-webhook/tool.stories.jsx index a0595581..41a5d9bf 100644 --- a/packages/tools/src/make-webhook/tool.stories.jsx +++ b/packages/tools/src/make-webhook/tool.stories.jsx @@ -1,8 +1,8 @@ import { z } from 'zod'; import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { GithubIssues } from '../github-issues/index.ts'; -import { MakeWebhook } from './index.ts'; +import { GithubIssues } from '../github-issues/index.js'; +import { MakeWebhook } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/src/pdf-search/index.ts b/packages/tools/src/pdf-search/index.ts deleted file mode 100644 index 1c75e572..00000000 --- a/packages/tools/src/pdf-search/index.ts +++ /dev/null @@ -1,127 +0,0 @@ -/** - * Pdf Search Tool - * - * This tool is used to perform a RAG (Retrieval-Augmented Generation) search within the content of a text file. - * It allows for semantic searching of a query within a specified text file's content, making it an invaluable resource - * for quickly extracting information or finding specific sections of text based on the query provided. - * - * The tool uses the following components: - * - A Chunker options, which chunks and processes text for the RAG model - * - An Embeddings instance, which handles embeddings for the RAG model - * - A VectorStore instance, which stores vectors for the RAG model - * - An LLM instance, which handles the language model for the RAG model - * - A promptQuestionTemplate, which defines the template for asking questions - * - An OpenAI API key, which is used for interacting with the OpenAI API - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { PDFLoader } from '@langchain/community/document_loaders/fs/pdf'; -import { RAGToolkit } from './rag/ragToolkit'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; -import { BrowserPDFLoader } from './rag/loaders/browserPDFLoader'; - -interface PdfSearchFields { - OPENAI_API_KEY: string; - file?: string | File; - chunkOptions?: any; - embeddings?: any; - vectorStore?: any; - llmInstance?: any; - promptQuestionTemplate?: string; -} - -export class PdfSearch extends StructuredTool { - private OPENAI_API_KEY: string; - private file?: string | File; - private chunkOptions: any; - private embeddings: any; - private vectorStore: any; - private llmInstance: any; - private promptQuestionTemplate: string; - private ragToolkit: any; // typeof RAGToolkit; - private httpClient: typeof ky; - name = 'pdf-search'; - description = - 'A tool that can be used to semantic search a query from a pdf file content.'; - schema = z.object({ - file: z.string().describe('The pdf file path to process.'), - query: z.string().describe('The question to ask.'), - }); - - constructor(fields: PdfSearchFields) { - super(); - this.OPENAI_API_KEY = fields.OPENAI_API_KEY; - this.file = fields.file; - this.chunkOptions = fields.chunkOptions; - this.embeddings = fields.embeddings; - this.vectorStore = fields.vectorStore; - this.llmInstance = fields.llmInstance; - this.promptQuestionTemplate = fields.promptQuestionTemplate || ''; - - this.ragToolkit = new RAGToolkit({ - chunkOptions: this.chunkOptions, - embeddings: this.embeddings, - vectorStore: this.vectorStore, - llmInstance: this.llmInstance, - promptQuestionTemplate: this.promptQuestionTemplate, - env: { OPENAI_API_KEY: this.OPENAI_API_KEY }, - }); - - this.ragToolkit.registerLoader('pdf', (source: string | File) => - typeof window !== 'undefined' - ? new BrowserPDFLoader(source) - : new PDFLoader(source) - ); - - this.httpClient = ky; - } - - async _call(input: z.infer): Promise { - const { file, query } = input; - if (file && file !== '') { - this.file = file; - } - if (!this.file || this.file === '') { - return "ERROR_MISSING_FILE: No pdf file was provided for analysis. Agent should provide valid pdf file in the 'file' field."; - } - if (!query || query === '') { - return "ERROR_MISSING_QUERY: No question was provided. Agent should provide a question in the 'query' field."; - } - - try { - const ragToolkit = this.ragToolkit; - - if (typeof this.file === 'string' && typeof window !== 'undefined') { - const response = await this.httpClient.get(this.file); - const blob = await response.blob(); - this.file = new File([blob], 'file.pdf', { type: 'application/pdf' }); - } - - await ragToolkit.addDocuments([ - { - source: this.file, - type: 'pdf', - }, - ]); - - const response = await ragToolkit.askQuestion(query); - return response; - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `Fetch file failed: ${errorType} (${statusCode})`; - } else { - return `ERROR_PDF_SEARCH_PROCESSING: An unexpected error occurred: in PDFSearch tool. Details: ${ - error instanceof Error ? error.message : String(error) - }. Agent should verify content format and query validity.`; - } - } - } -} diff --git a/packages/tools/src/pdf-search/rag/loaders/browserPDFLoader/index.ts b/packages/tools/src/pdf-search/rag/loaders/browserPDFLoader/index.ts deleted file mode 100644 index 7020c807..00000000 --- a/packages/tools/src/pdf-search/rag/loaders/browserPDFLoader/index.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document as BaseDocument } from 'langchain/document'; - -interface PDFMetadata { - [key: string]: any; -} - -interface PDFTextItem { - str?: string; - [key: string]: any; -} - -interface PDFPage { - getTextContent(): Promise<{ items: PDFTextItem[] }>; -} - -interface PDFDocument { - numPages: number; - getPage(pageNum: number): Promise; -} - -interface PDFDocumentProxy { - promise: Promise; -} - -interface PDFLib { - getDocument(data: Uint8Array): PDFDocumentProxy; - GlobalWorkerOptions: { - workerSrc: string; - }; -} - -export class BrowserPDFLoader extends BaseDocumentLoader { - private file: string | File; - private metadata: PDFMetadata; - - constructor(file: string | File, metadata: PDFMetadata = {}) { - super(); - this.file = file; - this.metadata = metadata; - } - - async load(): Promise { - if (!this.file) { - console.log('No file selected.'); - return []; - } - - if (typeof this.file === 'string') { - const response = await fetch(this.file); - const blob = await response.blob(); - this.file = new File([blob], 'file.pdf', { type: 'application/pdf' }); - } - - try { - const { getDocument, GlobalWorkerOptions } = (await import( - 'pdfjs-dist' - )) as PDFLib; - GlobalWorkerOptions.workerSrc = - 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.8.69/pdf.worker.min.mjs'; - - const fileReader = new FileReader(); - - const fileReaderPromise = new Promise((resolve, reject) => { - fileReader.onload = () => { - resolve(new Uint8Array(fileReader.result as ArrayBuffer)); - }; - fileReader.onerror = (error) => { - reject(error); - }; - }); - - fileReader.readAsArrayBuffer(this.file as File); - - const typedArray = await fileReaderPromise; - const pdf = await getDocument(typedArray).promise; - const pagesContent: string[] = []; - - for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) { - const page = await pdf.getPage(pageNum); - const textContent = await page.getTextContent(); - const pageText = textContent.items - .map((item) => ('str' in item ? item.str : '')) - .join(' '); - pagesContent.push(pageText); - } - - const documents = pagesContent.map( - (content, index) => - new BaseDocument({ - pageContent: content, - metadata: { ...this.metadata, page: index + 1 }, - }) - ); - - return documents; - } catch (_error) { - throw new Error('Error loading PDF.'); - } - } -} diff --git a/packages/tools/src/pdf-search/rag/loaders/textInputLoader/index.ts b/packages/tools/src/pdf-search/rag/loaders/textInputLoader/index.ts deleted file mode 100644 index c71933b4..00000000 --- a/packages/tools/src/pdf-search/rag/loaders/textInputLoader/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document as BaseDocument } from 'langchain/document'; - -interface TextInputMetadata { - [key: string]: any; -} - -export class TextInputLoader extends BaseDocumentLoader { - private text: string; - private metadata: TextInputMetadata; - - constructor(text: string, metadata: TextInputMetadata = {}) { - super(); - this.text = text; - this.metadata = metadata; - } - - async load(): Promise { - const document = new BaseDocument({ - pageContent: this.text, - metadata: this.metadata, - }); - return [document]; - } -} diff --git a/packages/tools/src/pdf-search/rag/ragToolkit.ts b/packages/tools/src/pdf-search/rag/ragToolkit.ts deleted file mode 100644 index e05e53e6..00000000 --- a/packages/tools/src/pdf-search/rag/ragToolkit.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter'; -import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai'; -import { MemoryVectorStore } from 'langchain/vectorstores/memory'; -import { PromptTemplate } from '@langchain/core/prompts'; -import { createStuffDocumentsChain } from 'langchain/chains/combine_documents'; -import { StringOutputParser } from '@langchain/core/output_parsers'; -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document } from 'langchain/document'; -import { TextInputLoader } from './loaders/textInputLoader'; - -interface RAGToolkitOptions { - embeddings?: OpenAIEmbeddings; - vectorStore?: MemoryVectorStore; - llmInstance?: ChatOpenAI; - promptQuestionTemplate?: string; - chunkOptions?: { - chunkSize: number; - chunkOverlap: number; - }; - env?: { - OPENAI_API_KEY: string; - }; -} - -interface DocumentSource { - source: string | File; - type: string; -} - -type LoaderFunction = (source: string | File) => BaseDocumentLoader; - -export class RAGToolkit { - private embeddings: OpenAIEmbeddings; - private vectorStore: MemoryVectorStore; - private llmInstance: ChatOpenAI; - private promptQuestionTemplate: string; - private chunkOptions: { chunkSize: number; chunkOverlap: number }; - private loaders: Record; - - constructor(options: RAGToolkitOptions = {}) { - this.embeddings = - options.embeddings || - new OpenAIEmbeddings({ apiKey: options?.env?.OPENAI_API_KEY }); - this.vectorStore = - options.vectorStore || new MemoryVectorStore(this.embeddings); - this.llmInstance = - options.llmInstance || - new ChatOpenAI({ - model: 'gpt-4o-mini', - temperature: 0, - apiKey: options?.env?.OPENAI_API_KEY, - }); - this.promptQuestionTemplate = - options.promptQuestionTemplate || - ` - Use the following pieces of context to answer the question at the end. - If you don't know the answer, just say that you don't know. - Context: {context} - Question: {question} - `; - this.chunkOptions = options.chunkOptions || { - chunkSize: 1000, - chunkOverlap: 200, - }; - - this.loaders = { - string: (source: string | File) => new TextInputLoader(source as string), - }; - } - - registerLoader(type: string, loaderFunction: LoaderFunction): void { - if (this.loaders[type]) { - throw new Error(`Loader type '${type}' is already registered.`); - } - this.loaders[type] = loaderFunction; - } - - async addDocuments(sources: DocumentSource[]): Promise { - const documents = await this.loadDocuments(sources); - const chunks = await this.chunkDocuments(documents); - if (this.vectorStore instanceof MemoryVectorStore) { - await this.vectorStore.addDocuments(chunks); - } else { - // Used for vector stores like Pinecone or Supabase - // Convert to vector store type - const vectorStore = this.vectorStore as any; - await vectorStore.addDocuments(chunks, this.embeddings); - } - } - - async loadDocuments(sources: DocumentSource[]): Promise { - const promises = sources.map(({ source, type }) => { - const loaderFn = this.loaders[type]; - if (!loaderFn) { - throw new Error(`Unsupported loader type: ${type}`); - } - return loaderFn(source).load(); - }); - const results = await Promise.all(promises); - return results.flat(); - } - - async chunkDocuments(documents: Document[]): Promise { - const splitter = new RecursiveCharacterTextSplitter(this.chunkOptions); - return splitter.splitDocuments(documents); - } - - async search(query: string): Promise { - const retriever = this.vectorStore.asRetriever(); - return retriever.invoke(query); - } - - async askQuestion(query: string): Promise { - const retriever = this.vectorStore.asRetriever(); - const context = await retriever.invoke(query); - - const promptTemplate = PromptTemplate.fromTemplate( - this.promptQuestionTemplate - ); - - const chain = await createStuffDocumentsChain({ - llm: this.llmInstance, - prompt: promptTemplate as any, - outputParser: new StringOutputParser() as any, - }); - - return chain.invoke({ question: query, context }); - } -} diff --git a/packages/tools/src/pdf-search/tool.stories.jsx b/packages/tools/src/pdf-search/tool.stories.jsx index f8361789..057f1ae6 100644 --- a/packages/tools/src/pdf-search/tool.stories.jsx +++ b/packages/tools/src/pdf-search/tool.stories.jsx @@ -1,6 +1,6 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { PdfSearch } from './index.ts'; +import { PdfSearch } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/src/serper/index.ts b/packages/tools/src/serper/index.ts deleted file mode 100644 index 0127e68f..00000000 --- a/packages/tools/src/serper/index.ts +++ /dev/null @@ -1,155 +0,0 @@ -/** - * Serper - * - * This tool integrates with Serper (https://serper.dev/), a Google Search API service - * that provides access to Google Search results programmatically. - * - * Serper allows you to perform various types of Google searches including web search, - * image search, news search, and more, making it ideal for AI applications that need - * real-time information from the web. - * - * Available search types: - * - "search" (default): For general search queries - * - "images": For image search - * - "videos": For video search - * - "places": For location-based search - * - "maps": For map search - * - "news": For news search - * - "shopping": For shopping search - * - "scholar": For academic publications search - * - "patents": For patents search - * - "webpage": For scraping webpages - * Note: The Scraper option is in Beta and may be subject to changes - * - * Key features: - * - Multiple search types - * - Clean, structured JSON responses - * - High-performance API with good uptime - * - Webpage scraping capability (Beta) - * - * For more information about Serper, visit: https://serper.dev/ - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -type SearchType = - | 'search' - | 'images' - | 'videos' - | 'places' - | 'maps' - | 'news' - | 'shopping' - | 'scholar' - | 'patents' - | 'webpage'; - -// Pre-defined types for Serper -const VALID_TYPES: readonly SearchType[] = [ - 'search', - 'images', - 'videos', - 'places', - 'maps', - 'news', - 'shopping', - 'scholar', - 'patents', - 'webpage', -] as const; - -interface SerperFields { - apiKey: string; - type?: SearchType; - params?: Record; -} - -export class Serper extends StructuredTool { - private apiKey: string; - private params: Record; - private type: SearchType; - private httpClient: typeof ky; - name = 'serper'; - description: string; - schema: z.ZodObject; - - constructor(fields: SerperFields) { - super(); - - if (fields.type && !VALID_TYPES.includes(fields.type)) { - throw new Error( - `Invalid search type: ${ - fields.type - }. Valid types are: ${VALID_TYPES.join(', ')}` - ); - } - - this.apiKey = fields.apiKey; - this.params = fields.params || {}; - this.type = fields.type || 'search'; - this.httpClient = ky; - - this.description = `A powerful search engine tool for retrieving real-time information using ${ - this.type - } search type. ${ - this.type === 'webpage' - ? 'Provide a URL to scrape.' - : 'Provide a search query to look up information.' - }`; - - // Define the input schema using Zod based on search type - this.schema = - this.type === 'webpage' - ? z.object({ - url: z.string().describe('The URL to scrape'), - }) - : z.object({ - query: z.string().describe('The search query to look up'), - }); - } - - async _call( - input: z.infer - ): Promise | string> { - try { - const url = - this.type === 'webpage' - ? 'https://scrape.serper.dev' - : `https://google.serper.dev/${this.type}`; - - const bodyData = - this.type === 'webpage' - ? { url: (input as { url: string }).url } - : { q: (input as { query: string }).query, ...this.params }; - - const response = await this.httpClient - .post(url, { - json: bodyData, - headers: { - 'X-API-KEY': this.apiKey, - 'Content-Type': 'application/json', - }, - }) - .json>(); - - return response; - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${ - error instanceof Error ? error.message : String(error) - }`; - } - } - } -} diff --git a/packages/tools/src/serper/tool.stories.jsx b/packages/tools/src/serper/tool.stories.jsx index b2f92418..3d9a4875 100644 --- a/packages/tools/src/serper/tool.stories.jsx +++ b/packages/tools/src/serper/tool.stories.jsx @@ -1,5 +1,5 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; -import { Serper } from './index.ts'; +import { Serper } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; diff --git a/packages/tools/src/simple-rag/index.ts b/packages/tools/src/simple-rag/index.ts deleted file mode 100644 index 8eb02ce0..00000000 --- a/packages/tools/src/simple-rag/index.ts +++ /dev/null @@ -1,105 +0,0 @@ -/** - * Simple RAG Tool - * - * This tool integrates with various components from the langchain library to provide - * a simple interface for asking questions and retrieving answers using the Retrieval-Augmented Generation (RAG) approach. - * - * The tool uses the following components: - * - A RAG Toolkit instance, which handles the RAG process - * - A Loader instance, which loads and processes documents for the RAG model - * - A Chunker instance, which chunks and processes text for the RAG model - * - An Embeddings instance, which handles embeddings for the RAG model - * - A VectorStore instance, which stores vectors for the RAG model - * - An LLM instance, which handles the language model for the RAG model - * - A promptQuestionTemplate, which defines the template for asking questions - * - An OpenAI API key, which is used for interacting with the OpenAI API - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import { OpenAIEmbeddings } from '@langchain/openai'; -import { MemoryVectorStore } from 'langchain/vectorstores/memory'; -import { ChatOpenAI } from '@langchain/openai'; -import { RAGToolkit } from './rag/ragToolkit'; - -interface SimpleRAGFields { - OPENAI_API_KEY: string; - content?: string; - // loaderOptions?: any; - chunkOptions?: { - chunkSize: number; - chunkOverlap: number; - }; - embeddings?: OpenAIEmbeddings; - vectorStore?: MemoryVectorStore; - llmInstance?: ChatOpenAI; - promptQuestionTemplate?: string; -} - -export class SimpleRAG extends StructuredTool { - private OPENAI_API_KEY: string; - private content?: string; - // private loaderOptions: any; - private chunkOptions?: any; - private embeddings?: OpenAIEmbeddings; - private vectorStore?: MemoryVectorStore; - private llmInstance?: ChatOpenAI; - private promptQuestionTemplate?: string; - private ragToolkit: RAGToolkit; - name = 'simple-rag'; - description = - 'A simple tool for asking questions using the RAG approach. Input should be a string text content such as a knowledge base and a question string.'; - schema = z.object({ - content: z.string().describe('The content text to process.'), - query: z.string().describe('The question to ask.'), - }); - - constructor(fields: SimpleRAGFields) { - super(); - this.OPENAI_API_KEY = fields.OPENAI_API_KEY; - this.content = fields.content; - // this.loaderOptions = fields.loaderOptions; - this.chunkOptions = fields.chunkOptions; - this.embeddings = fields.embeddings; - this.vectorStore = fields.vectorStore; - this.llmInstance = fields.llmInstance; - this.promptQuestionTemplate = fields.promptQuestionTemplate; - - this.ragToolkit = new RAGToolkit({ - // loaderOptions: this.loaderOptions, - chunkOptions: this.chunkOptions, - embeddings: this.embeddings, - vectorStore: this.vectorStore, - llmInstance: this.llmInstance, - promptQuestionTemplate: this.promptQuestionTemplate, - env: { OPENAI_API_KEY: this.OPENAI_API_KEY }, - }); - } - - async _call(input: z.infer): Promise { - console.log('from ts'); - - const { content, query } = input; - if (content && content !== '') { - this.content = content; - } - if (!this.content || this.content === '') { - return "ERROR_MISSING_CONTENT: No text content was provided for analysis. Agent should provide content in the 'content' field."; - } - if (!query || query === '') { - return "ERROR_MISSING_QUERY: No question was provided. Agent should provide a question in the 'query' field."; - } - - try { - await this.ragToolkit.addDocuments([ - { source: this.content, type: 'string' }, - ]); - const response = await this.ragToolkit.askQuestion(query); - return response; - } catch (error) { - return `ERROR_RAG_PROCESSING: RAG processing failed. Details: ${ - error instanceof Error ? error.message : String(error) - }. Agent should verify content format and query validity.`; - } - } -} diff --git a/packages/tools/src/simple-rag/rag/loaders/browserPDFLoader/index.ts b/packages/tools/src/simple-rag/rag/loaders/browserPDFLoader/index.ts deleted file mode 100644 index 7020c807..00000000 --- a/packages/tools/src/simple-rag/rag/loaders/browserPDFLoader/index.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document as BaseDocument } from 'langchain/document'; - -interface PDFMetadata { - [key: string]: any; -} - -interface PDFTextItem { - str?: string; - [key: string]: any; -} - -interface PDFPage { - getTextContent(): Promise<{ items: PDFTextItem[] }>; -} - -interface PDFDocument { - numPages: number; - getPage(pageNum: number): Promise; -} - -interface PDFDocumentProxy { - promise: Promise; -} - -interface PDFLib { - getDocument(data: Uint8Array): PDFDocumentProxy; - GlobalWorkerOptions: { - workerSrc: string; - }; -} - -export class BrowserPDFLoader extends BaseDocumentLoader { - private file: string | File; - private metadata: PDFMetadata; - - constructor(file: string | File, metadata: PDFMetadata = {}) { - super(); - this.file = file; - this.metadata = metadata; - } - - async load(): Promise { - if (!this.file) { - console.log('No file selected.'); - return []; - } - - if (typeof this.file === 'string') { - const response = await fetch(this.file); - const blob = await response.blob(); - this.file = new File([blob], 'file.pdf', { type: 'application/pdf' }); - } - - try { - const { getDocument, GlobalWorkerOptions } = (await import( - 'pdfjs-dist' - )) as PDFLib; - GlobalWorkerOptions.workerSrc = - 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.8.69/pdf.worker.min.mjs'; - - const fileReader = new FileReader(); - - const fileReaderPromise = new Promise((resolve, reject) => { - fileReader.onload = () => { - resolve(new Uint8Array(fileReader.result as ArrayBuffer)); - }; - fileReader.onerror = (error) => { - reject(error); - }; - }); - - fileReader.readAsArrayBuffer(this.file as File); - - const typedArray = await fileReaderPromise; - const pdf = await getDocument(typedArray).promise; - const pagesContent: string[] = []; - - for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) { - const page = await pdf.getPage(pageNum); - const textContent = await page.getTextContent(); - const pageText = textContent.items - .map((item) => ('str' in item ? item.str : '')) - .join(' '); - pagesContent.push(pageText); - } - - const documents = pagesContent.map( - (content, index) => - new BaseDocument({ - pageContent: content, - metadata: { ...this.metadata, page: index + 1 }, - }) - ); - - return documents; - } catch (_error) { - throw new Error('Error loading PDF.'); - } - } -} diff --git a/packages/tools/src/simple-rag/rag/loaders/textInputLoader/index.ts b/packages/tools/src/simple-rag/rag/loaders/textInputLoader/index.ts deleted file mode 100644 index c71933b4..00000000 --- a/packages/tools/src/simple-rag/rag/loaders/textInputLoader/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document as BaseDocument } from 'langchain/document'; - -interface TextInputMetadata { - [key: string]: any; -} - -export class TextInputLoader extends BaseDocumentLoader { - private text: string; - private metadata: TextInputMetadata; - - constructor(text: string, metadata: TextInputMetadata = {}) { - super(); - this.text = text; - this.metadata = metadata; - } - - async load(): Promise { - const document = new BaseDocument({ - pageContent: this.text, - metadata: this.metadata, - }); - return [document]; - } -} diff --git a/packages/tools/src/simple-rag/rag/ragToolkit.ts b/packages/tools/src/simple-rag/rag/ragToolkit.ts deleted file mode 100644 index e05e53e6..00000000 --- a/packages/tools/src/simple-rag/rag/ragToolkit.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter'; -import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai'; -import { MemoryVectorStore } from 'langchain/vectorstores/memory'; -import { PromptTemplate } from '@langchain/core/prompts'; -import { createStuffDocumentsChain } from 'langchain/chains/combine_documents'; -import { StringOutputParser } from '@langchain/core/output_parsers'; -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document } from 'langchain/document'; -import { TextInputLoader } from './loaders/textInputLoader'; - -interface RAGToolkitOptions { - embeddings?: OpenAIEmbeddings; - vectorStore?: MemoryVectorStore; - llmInstance?: ChatOpenAI; - promptQuestionTemplate?: string; - chunkOptions?: { - chunkSize: number; - chunkOverlap: number; - }; - env?: { - OPENAI_API_KEY: string; - }; -} - -interface DocumentSource { - source: string | File; - type: string; -} - -type LoaderFunction = (source: string | File) => BaseDocumentLoader; - -export class RAGToolkit { - private embeddings: OpenAIEmbeddings; - private vectorStore: MemoryVectorStore; - private llmInstance: ChatOpenAI; - private promptQuestionTemplate: string; - private chunkOptions: { chunkSize: number; chunkOverlap: number }; - private loaders: Record; - - constructor(options: RAGToolkitOptions = {}) { - this.embeddings = - options.embeddings || - new OpenAIEmbeddings({ apiKey: options?.env?.OPENAI_API_KEY }); - this.vectorStore = - options.vectorStore || new MemoryVectorStore(this.embeddings); - this.llmInstance = - options.llmInstance || - new ChatOpenAI({ - model: 'gpt-4o-mini', - temperature: 0, - apiKey: options?.env?.OPENAI_API_KEY, - }); - this.promptQuestionTemplate = - options.promptQuestionTemplate || - ` - Use the following pieces of context to answer the question at the end. - If you don't know the answer, just say that you don't know. - Context: {context} - Question: {question} - `; - this.chunkOptions = options.chunkOptions || { - chunkSize: 1000, - chunkOverlap: 200, - }; - - this.loaders = { - string: (source: string | File) => new TextInputLoader(source as string), - }; - } - - registerLoader(type: string, loaderFunction: LoaderFunction): void { - if (this.loaders[type]) { - throw new Error(`Loader type '${type}' is already registered.`); - } - this.loaders[type] = loaderFunction; - } - - async addDocuments(sources: DocumentSource[]): Promise { - const documents = await this.loadDocuments(sources); - const chunks = await this.chunkDocuments(documents); - if (this.vectorStore instanceof MemoryVectorStore) { - await this.vectorStore.addDocuments(chunks); - } else { - // Used for vector stores like Pinecone or Supabase - // Convert to vector store type - const vectorStore = this.vectorStore as any; - await vectorStore.addDocuments(chunks, this.embeddings); - } - } - - async loadDocuments(sources: DocumentSource[]): Promise { - const promises = sources.map(({ source, type }) => { - const loaderFn = this.loaders[type]; - if (!loaderFn) { - throw new Error(`Unsupported loader type: ${type}`); - } - return loaderFn(source).load(); - }); - const results = await Promise.all(promises); - return results.flat(); - } - - async chunkDocuments(documents: Document[]): Promise { - const splitter = new RecursiveCharacterTextSplitter(this.chunkOptions); - return splitter.splitDocuments(documents); - } - - async search(query: string): Promise { - const retriever = this.vectorStore.asRetriever(); - return retriever.invoke(query); - } - - async askQuestion(query: string): Promise { - const retriever = this.vectorStore.asRetriever(); - const context = await retriever.invoke(query); - - const promptTemplate = PromptTemplate.fromTemplate( - this.promptQuestionTemplate - ); - - const chain = await createStuffDocumentsChain({ - llm: this.llmInstance, - prompt: promptTemplate as any, - outputParser: new StringOutputParser() as any, - }); - - return chain.invoke({ question: query, context }); - } -} diff --git a/packages/tools/src/simple-rag/tool.stories.jsx b/packages/tools/src/simple-rag/tool.stories.jsx index 9a9ef541..39e1bfcf 100644 --- a/packages/tools/src/simple-rag/tool.stories.jsx +++ b/packages/tools/src/simple-rag/tool.stories.jsx @@ -1,6 +1,6 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { SimpleRAG } from './index.ts'; +import { SimpleRAG } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/src/tavily/index.ts b/packages/tools/src/tavily/index.ts deleted file mode 100644 index 779cbb52..00000000 --- a/packages/tools/src/tavily/index.ts +++ /dev/null @@ -1,97 +0,0 @@ -/** - * Tavily Search Results - * - * This tool integrates with Tavily (https://tavily.com/), an advanced search engine - * optimized for comprehensive, accurate, and trusted results. It's particularly - * useful for retrieving current information and answering questions about recent events. - * - * Tavily provides AI-optimized search capabilities that deliver high-quality, - * relevant results, making it ideal for AI applications and Large Language - * Models (LLMs). - * - * Key features of Tavily: - * - Delivers accurate and trusted search results - * - Optimized for current events and real-time information - * - Returns well-structured JSON data ready for LLM consumption - * - Includes content relevance scoring and filtering - * - * For more information about Tavily, visit: https://tavily.com/ - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -interface TavilySearchFields { - apiKey: string; - maxResults?: number; -} - -interface TavilyResult { - title: string; - url: string; - content: string; - score: number; - [key: string]: any; -} - -export class TavilySearchResults extends StructuredTool { - private apiKey: string; - private maxResults: number; - private httpClient: typeof ky; - name = 'tavily_search_results_json'; - description = - 'A search engine optimized for comprehensive, accurate, and trusted results. Useful for when you need to answer questions about current events. Input should be a search query.'; - schema = z.object({ - searchQuery: z - .string() - .describe('The search query to find relevant information.'), - }); - - constructor(fields: TavilySearchFields) { - super(); - this.apiKey = fields.apiKey; - this.maxResults = fields.maxResults ?? 5; - this.httpClient = ky; - } - - async _call(input: z.infer): Promise { - try { - const jsonData = await this.httpClient - .post('https://api.tavily.com/search', { - json: { - query: input.searchQuery, - max_results: this.maxResults, - api_key: this.apiKey, - }, - headers: { - 'Content-Type': 'application/json', - }, - }) - .json<{ results?: TavilyResult[] }>(); - - // Extract and validate the results from the response - const results = jsonData?.results; - if (!Array.isArray(results)) { - return 'Could not parse Tavily results. Please try again.'; - } - - return JSON.stringify(results); - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${ - error instanceof Error ? error.message : String(error) - }`; - } - } - } -} diff --git a/packages/tools/src/tavily/tool.stories.jsx b/packages/tools/src/tavily/tool.stories.jsx index d0752085..30779592 100644 --- a/packages/tools/src/tavily/tool.stories.jsx +++ b/packages/tools/src/tavily/tool.stories.jsx @@ -1,5 +1,5 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; -import { TavilySearchResults } from './index.ts'; +import { TavilySearchResults } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; diff --git a/packages/tools/src/textfile-search/index.ts b/packages/tools/src/textfile-search/index.ts deleted file mode 100644 index 602d677a..00000000 --- a/packages/tools/src/textfile-search/index.ts +++ /dev/null @@ -1,122 +0,0 @@ -/** - * Text File (txt) Search Tool - * - * This tool is used to perform a RAG (Retrieval-Augmented Generation) search within the content of a text file. - * It allows for semantic searching of a query within a specified text file's content, making it an invaluable resource - * for quickly extracting information or finding specific sections of text based on the query provided. - * - * The tool uses the following components: - * - A Chunker options, which chunks and processes text for the RAG model - * - An Embeddings instance, which handles embeddings for the RAG model - * - A VectorStore instance, which stores vectors for the RAG model - * - An LLM instance, which handles the language model for the RAG model - * - A promptQuestionTemplate, which defines the template for asking questions - * - An OpenAI API key, which is used for interacting with the OpenAI API - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { TextLoader } from 'langchain/document_loaders/fs/text'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; -import { OpenAIEmbeddings } from '@langchain/openai'; -import { MemoryVectorStore } from 'langchain/vectorstores/memory'; -import { ChatOpenAI } from '@langchain/openai'; -import { RAGToolkit } from './rag/ragToolkit'; - -interface TextFileSearchFields { - OPENAI_API_KEY: string; - file?: string | File; - chunkOptions?: { - chunkSize: number; - chunkOverlap: number; - }; - embeddings?: OpenAIEmbeddings; - vectorStore?: MemoryVectorStore; - llmInstance?: ChatOpenAI; - promptQuestionTemplate?: string; -} - -export class TextFileSearch extends StructuredTool { - private OPENAI_API_KEY: string; - private file?: string | File; - private chunkOptions?: any; - private embeddings?: OpenAIEmbeddings; - private vectorStore?: MemoryVectorStore; - private llmInstance?: ChatOpenAI; - private promptQuestionTemplate?: string; - private ragToolkit: RAGToolkit; - private httpClient: typeof ky; - name = 'textfile-search'; - description = - 'A tool that can be used to semantic search a query from a (txt) file content.'; - schema = z.object({ - file: z.string().describe('The text file (txt) path to process.'), - query: z.string().describe('The question to ask.'), - }); - - constructor(fields: TextFileSearchFields) { - super(); - this.OPENAI_API_KEY = fields.OPENAI_API_KEY; - this.file = fields.file; - this.chunkOptions = fields.chunkOptions; - this.embeddings = fields.embeddings; - this.vectorStore = fields.vectorStore; - this.llmInstance = fields.llmInstance; - this.promptQuestionTemplate = fields.promptQuestionTemplate; - - this.ragToolkit = new RAGToolkit({ - chunkOptions: this.chunkOptions, - embeddings: this.embeddings, - vectorStore: this.vectorStore, - llmInstance: this.llmInstance, - promptQuestionTemplate: this.promptQuestionTemplate, - env: { OPENAI_API_KEY: this.OPENAI_API_KEY }, - }); - - this.ragToolkit.registerLoader( - 'text', - (source: string | File) => new TextLoader(source as string) as any - ); - this.httpClient = ky; - } - - async _call(input: z.infer): Promise { - const { file, query } = input; - if (file && file !== '') { - this.file = file; - } - if (!this.file || this.file === '') { - return "ERROR_MISSING_FILE: No file was provided for analysis. Agent should provide valid file in the 'file' field."; - } - if (!query || query === '') { - return "ERROR_MISSING_QUERY: No question was provided. Agent should provide a question in the 'query' field."; - } - - try { - if (typeof this.file === 'string' && typeof window !== 'undefined') { - const response = await this.httpClient.get(this.file); - const blob = await response.blob(); - this.file = new File([blob], 'file.txt', { type: 'text/plain' }); - } - - await this.ragToolkit.addDocuments([{ source: this.file, type: 'text' }]); - const response = await this.ragToolkit.askQuestion(query); - return response; - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `Fetch file failed: ${errorType} (${statusCode})`; - } else { - return `ERROR_TEXTFILE_SEARCH_PROCESSING: An unexpected error occurred: in TextFileSearch tool. Details: ${ - error instanceof Error ? error.message : String(error) - }. Agent should verify content format and query validity.`; - } - } - } -} diff --git a/packages/tools/src/textfile-search/rag/loaders/browserPDFLoader/index.ts b/packages/tools/src/textfile-search/rag/loaders/browserPDFLoader/index.ts deleted file mode 100644 index 7020c807..00000000 --- a/packages/tools/src/textfile-search/rag/loaders/browserPDFLoader/index.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document as BaseDocument } from 'langchain/document'; - -interface PDFMetadata { - [key: string]: any; -} - -interface PDFTextItem { - str?: string; - [key: string]: any; -} - -interface PDFPage { - getTextContent(): Promise<{ items: PDFTextItem[] }>; -} - -interface PDFDocument { - numPages: number; - getPage(pageNum: number): Promise; -} - -interface PDFDocumentProxy { - promise: Promise; -} - -interface PDFLib { - getDocument(data: Uint8Array): PDFDocumentProxy; - GlobalWorkerOptions: { - workerSrc: string; - }; -} - -export class BrowserPDFLoader extends BaseDocumentLoader { - private file: string | File; - private metadata: PDFMetadata; - - constructor(file: string | File, metadata: PDFMetadata = {}) { - super(); - this.file = file; - this.metadata = metadata; - } - - async load(): Promise { - if (!this.file) { - console.log('No file selected.'); - return []; - } - - if (typeof this.file === 'string') { - const response = await fetch(this.file); - const blob = await response.blob(); - this.file = new File([blob], 'file.pdf', { type: 'application/pdf' }); - } - - try { - const { getDocument, GlobalWorkerOptions } = (await import( - 'pdfjs-dist' - )) as PDFLib; - GlobalWorkerOptions.workerSrc = - 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.8.69/pdf.worker.min.mjs'; - - const fileReader = new FileReader(); - - const fileReaderPromise = new Promise((resolve, reject) => { - fileReader.onload = () => { - resolve(new Uint8Array(fileReader.result as ArrayBuffer)); - }; - fileReader.onerror = (error) => { - reject(error); - }; - }); - - fileReader.readAsArrayBuffer(this.file as File); - - const typedArray = await fileReaderPromise; - const pdf = await getDocument(typedArray).promise; - const pagesContent: string[] = []; - - for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) { - const page = await pdf.getPage(pageNum); - const textContent = await page.getTextContent(); - const pageText = textContent.items - .map((item) => ('str' in item ? item.str : '')) - .join(' '); - pagesContent.push(pageText); - } - - const documents = pagesContent.map( - (content, index) => - new BaseDocument({ - pageContent: content, - metadata: { ...this.metadata, page: index + 1 }, - }) - ); - - return documents; - } catch (_error) { - throw new Error('Error loading PDF.'); - } - } -} diff --git a/packages/tools/src/textfile-search/tool.stories.jsx b/packages/tools/src/textfile-search/tool.stories.jsx index a78c5188..6e66395b 100644 --- a/packages/tools/src/textfile-search/tool.stories.jsx +++ b/packages/tools/src/textfile-search/tool.stories.jsx @@ -1,6 +1,6 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { TextFileSearch } from './index.ts'; +import { TextFileSearch } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/src/website-search/index.ts b/packages/tools/src/website-search/index.ts deleted file mode 100644 index b28ba125..00000000 --- a/packages/tools/src/website-search/index.ts +++ /dev/null @@ -1,104 +0,0 @@ -/** - * Website Search Tool - * - * This tool is specifically crafted for conducting semantic searches within the content of a particular website. - * Leveraging a Retrieval-Augmented Generation (RAG) model, it navigates through the information provided on a given URL. - * Users have the flexibility to either initiate a search across any website known or discovered during its usage or to - * concentrate the search on a predefined, specific website. - * - * The tool uses the following components: - * - A RAG Toolkit instance, which handles the RAG process - * - A Chunker instance, which chunks and processes text for the RAG model - * - An Embeddings instance, which handles embeddings for the RAG model - * - A VectorStore instance, which stores vectors for the RAG model - * - An LLM instance, which handles the language model for the RAG model - * - A promptQuestionTemplate, which defines the template for asking questions - * - An OpenAI API key, which is used for interacting with the OpenAI API - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { CheerioWebBaseLoader } from '@langchain/community/document_loaders/web/cheerio'; -import { z } from 'zod'; -import { OpenAIEmbeddings } from '@langchain/openai'; -import { MemoryVectorStore } from 'langchain/vectorstores/memory'; -import { ChatOpenAI } from '@langchain/openai'; -import { RAGToolkit } from './rag/ragToolkit'; -interface WebsiteSearchFields { - OPENAI_API_KEY: string; - url?: string; - chunkOptions?: { - chunkSize: number; - chunkOverlap: number; - }; - embeddings?: OpenAIEmbeddings; - vectorStore?: MemoryVectorStore; - llmInstance?: ChatOpenAI; - promptQuestionTemplate?: string; -} - -export class WebsiteSearch extends StructuredTool { - private OPENAI_API_KEY: string; - private url?: string; - private chunkOptions?: any; - private embeddings?: OpenAIEmbeddings; - private vectorStore?: MemoryVectorStore; - private llmInstance?: ChatOpenAI; - private promptQuestionTemplate?: string; - private ragToolkit: RAGToolkit; - name = 'website-search'; - description = - 'A tool for conducting semantic searches within the content of a particular website using the RAG approach. Input should be a URL and a question string.'; - schema = z.object({ - url: z.string().describe('The URL to process.'), - query: z.string().describe('The question to ask.'), - }); - - constructor(fields: WebsiteSearchFields) { - super(); - this.OPENAI_API_KEY = fields.OPENAI_API_KEY; - this.url = fields.url; - this.chunkOptions = fields.chunkOptions; - this.embeddings = fields.embeddings; - this.vectorStore = fields.vectorStore; - this.llmInstance = fields.llmInstance; - this.promptQuestionTemplate = fields.promptQuestionTemplate; - - this.ragToolkit = new RAGToolkit({ - chunkOptions: this.chunkOptions, - embeddings: this.embeddings, - vectorStore: this.vectorStore, - llmInstance: this.llmInstance, - promptQuestionTemplate: this.promptQuestionTemplate, - env: { OPENAI_API_KEY: this.OPENAI_API_KEY }, - }); - - this.ragToolkit.registerLoader( - 'web', - (source: string | File) => - new CheerioWebBaseLoader(source as string) as any - ); - } - - async _call(input: z.infer): Promise { - const { url, query } = input; - if (url && url !== '') { - this.url = url; - } - if (!this.url || this.url === '') { - return "ERROR_MISSING_URL: No url was provided for analysis. Agent should provide valid url in the 'url' field."; - } - if (!query || query === '') { - return "ERROR_MISSING_QUERY: No question was provided. Agent should provide a question in the 'query' field."; - } - - try { - await this.ragToolkit.addDocuments([{ source: this.url, type: 'web' }]); - const response = await this.ragToolkit.askQuestion(query); - return response; - } catch (error) { - return `ERROR_WEBSITE_SEARCH_PROCESSING: An unexpected error occurred: in WebsiteSearch tool. Details: ${ - error instanceof Error ? error.message : String(error) - }. Agent should verify content format and query validity.`; - } - } -} diff --git a/packages/tools/src/website-search/rag/loaders/browserPDFLoader/index.ts b/packages/tools/src/website-search/rag/loaders/browserPDFLoader/index.ts deleted file mode 100644 index 7020c807..00000000 --- a/packages/tools/src/website-search/rag/loaders/browserPDFLoader/index.ts +++ /dev/null @@ -1,101 +0,0 @@ -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document as BaseDocument } from 'langchain/document'; - -interface PDFMetadata { - [key: string]: any; -} - -interface PDFTextItem { - str?: string; - [key: string]: any; -} - -interface PDFPage { - getTextContent(): Promise<{ items: PDFTextItem[] }>; -} - -interface PDFDocument { - numPages: number; - getPage(pageNum: number): Promise; -} - -interface PDFDocumentProxy { - promise: Promise; -} - -interface PDFLib { - getDocument(data: Uint8Array): PDFDocumentProxy; - GlobalWorkerOptions: { - workerSrc: string; - }; -} - -export class BrowserPDFLoader extends BaseDocumentLoader { - private file: string | File; - private metadata: PDFMetadata; - - constructor(file: string | File, metadata: PDFMetadata = {}) { - super(); - this.file = file; - this.metadata = metadata; - } - - async load(): Promise { - if (!this.file) { - console.log('No file selected.'); - return []; - } - - if (typeof this.file === 'string') { - const response = await fetch(this.file); - const blob = await response.blob(); - this.file = new File([blob], 'file.pdf', { type: 'application/pdf' }); - } - - try { - const { getDocument, GlobalWorkerOptions } = (await import( - 'pdfjs-dist' - )) as PDFLib; - GlobalWorkerOptions.workerSrc = - 'https://cdnjs.cloudflare.com/ajax/libs/pdf.js/4.8.69/pdf.worker.min.mjs'; - - const fileReader = new FileReader(); - - const fileReaderPromise = new Promise((resolve, reject) => { - fileReader.onload = () => { - resolve(new Uint8Array(fileReader.result as ArrayBuffer)); - }; - fileReader.onerror = (error) => { - reject(error); - }; - }); - - fileReader.readAsArrayBuffer(this.file as File); - - const typedArray = await fileReaderPromise; - const pdf = await getDocument(typedArray).promise; - const pagesContent: string[] = []; - - for (let pageNum = 1; pageNum <= pdf.numPages; pageNum++) { - const page = await pdf.getPage(pageNum); - const textContent = await page.getTextContent(); - const pageText = textContent.items - .map((item) => ('str' in item ? item.str : '')) - .join(' '); - pagesContent.push(pageText); - } - - const documents = pagesContent.map( - (content, index) => - new BaseDocument({ - pageContent: content, - metadata: { ...this.metadata, page: index + 1 }, - }) - ); - - return documents; - } catch (_error) { - throw new Error('Error loading PDF.'); - } - } -} diff --git a/packages/tools/src/website-search/rag/loaders/textInputLoader/index.ts b/packages/tools/src/website-search/rag/loaders/textInputLoader/index.ts deleted file mode 100644 index c71933b4..00000000 --- a/packages/tools/src/website-search/rag/loaders/textInputLoader/index.ts +++ /dev/null @@ -1,25 +0,0 @@ -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document as BaseDocument } from 'langchain/document'; - -interface TextInputMetadata { - [key: string]: any; -} - -export class TextInputLoader extends BaseDocumentLoader { - private text: string; - private metadata: TextInputMetadata; - - constructor(text: string, metadata: TextInputMetadata = {}) { - super(); - this.text = text; - this.metadata = metadata; - } - - async load(): Promise { - const document = new BaseDocument({ - pageContent: this.text, - metadata: this.metadata, - }); - return [document]; - } -} diff --git a/packages/tools/src/website-search/rag/ragToolkit.ts b/packages/tools/src/website-search/rag/ragToolkit.ts deleted file mode 100644 index e05e53e6..00000000 --- a/packages/tools/src/website-search/rag/ragToolkit.ts +++ /dev/null @@ -1,129 +0,0 @@ -import { RecursiveCharacterTextSplitter } from 'langchain/text_splitter'; -import { ChatOpenAI, OpenAIEmbeddings } from '@langchain/openai'; -import { MemoryVectorStore } from 'langchain/vectorstores/memory'; -import { PromptTemplate } from '@langchain/core/prompts'; -import { createStuffDocumentsChain } from 'langchain/chains/combine_documents'; -import { StringOutputParser } from '@langchain/core/output_parsers'; -import { BaseDocumentLoader } from '@langchain/core/document_loaders/base'; -import { Document } from 'langchain/document'; -import { TextInputLoader } from './loaders/textInputLoader'; - -interface RAGToolkitOptions { - embeddings?: OpenAIEmbeddings; - vectorStore?: MemoryVectorStore; - llmInstance?: ChatOpenAI; - promptQuestionTemplate?: string; - chunkOptions?: { - chunkSize: number; - chunkOverlap: number; - }; - env?: { - OPENAI_API_KEY: string; - }; -} - -interface DocumentSource { - source: string | File; - type: string; -} - -type LoaderFunction = (source: string | File) => BaseDocumentLoader; - -export class RAGToolkit { - private embeddings: OpenAIEmbeddings; - private vectorStore: MemoryVectorStore; - private llmInstance: ChatOpenAI; - private promptQuestionTemplate: string; - private chunkOptions: { chunkSize: number; chunkOverlap: number }; - private loaders: Record; - - constructor(options: RAGToolkitOptions = {}) { - this.embeddings = - options.embeddings || - new OpenAIEmbeddings({ apiKey: options?.env?.OPENAI_API_KEY }); - this.vectorStore = - options.vectorStore || new MemoryVectorStore(this.embeddings); - this.llmInstance = - options.llmInstance || - new ChatOpenAI({ - model: 'gpt-4o-mini', - temperature: 0, - apiKey: options?.env?.OPENAI_API_KEY, - }); - this.promptQuestionTemplate = - options.promptQuestionTemplate || - ` - Use the following pieces of context to answer the question at the end. - If you don't know the answer, just say that you don't know. - Context: {context} - Question: {question} - `; - this.chunkOptions = options.chunkOptions || { - chunkSize: 1000, - chunkOverlap: 200, - }; - - this.loaders = { - string: (source: string | File) => new TextInputLoader(source as string), - }; - } - - registerLoader(type: string, loaderFunction: LoaderFunction): void { - if (this.loaders[type]) { - throw new Error(`Loader type '${type}' is already registered.`); - } - this.loaders[type] = loaderFunction; - } - - async addDocuments(sources: DocumentSource[]): Promise { - const documents = await this.loadDocuments(sources); - const chunks = await this.chunkDocuments(documents); - if (this.vectorStore instanceof MemoryVectorStore) { - await this.vectorStore.addDocuments(chunks); - } else { - // Used for vector stores like Pinecone or Supabase - // Convert to vector store type - const vectorStore = this.vectorStore as any; - await vectorStore.addDocuments(chunks, this.embeddings); - } - } - - async loadDocuments(sources: DocumentSource[]): Promise { - const promises = sources.map(({ source, type }) => { - const loaderFn = this.loaders[type]; - if (!loaderFn) { - throw new Error(`Unsupported loader type: ${type}`); - } - return loaderFn(source).load(); - }); - const results = await Promise.all(promises); - return results.flat(); - } - - async chunkDocuments(documents: Document[]): Promise { - const splitter = new RecursiveCharacterTextSplitter(this.chunkOptions); - return splitter.splitDocuments(documents); - } - - async search(query: string): Promise { - const retriever = this.vectorStore.asRetriever(); - return retriever.invoke(query); - } - - async askQuestion(query: string): Promise { - const retriever = this.vectorStore.asRetriever(); - const context = await retriever.invoke(query); - - const promptTemplate = PromptTemplate.fromTemplate( - this.promptQuestionTemplate - ); - - const chain = await createStuffDocumentsChain({ - llm: this.llmInstance, - prompt: promptTemplate as any, - outputParser: new StringOutputParser() as any, - }); - - return chain.invoke({ question: query, context }); - } -} diff --git a/packages/tools/src/website-search/tool.stories.jsx b/packages/tools/src/website-search/tool.stories.jsx index f1cd0aeb..122fd559 100644 --- a/packages/tools/src/website-search/tool.stories.jsx +++ b/packages/tools/src/website-search/tool.stories.jsx @@ -1,6 +1,6 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { WebsiteSearch } from './index.ts'; +import { WebsiteSearch } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/src/wolfram-alpha/index.ts b/packages/tools/src/wolfram-alpha/index.ts deleted file mode 100644 index 4f2039a4..00000000 --- a/packages/tools/src/wolfram-alpha/index.ts +++ /dev/null @@ -1,92 +0,0 @@ -/** - * WolframAlpha Tool - * - * This tool integrates with WolframAlpha (https://www.wolframalpha.com/), a computational - * intelligence engine that provides robust and detailed answers to complex queries across - * various domains. - * - * Key features: - * - Advanced computations and data analysis - * - Scientific and mathematical calculations - * - Real-time data processing - * - Domain-specific knowledge in: - * - Mathematics - * - Physics - * - Chemistry - * - Engineering - * - Earth Sciences - * - Life Sciences - * - Units & Measures - * - Financial calculations - * - And more - * - * For more information about WolframAlpha, visit: https://www.wolframalpha.com/ - * To get an API key, sign up at: https://developer.wolframalpha.com/ - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -interface WolframAlphaFields { - appId: string; -} - -export class WolframAlphaTool extends StructuredTool { - private appId: string; - private httpClient: typeof ky; - name = 'wolfram_alpha'; - description = - 'The WolframAlpha tool integrates the power of WolframAlpha, a computational intelligence engine, to provide detailed answers to complex queries across various domains. It offers advanced computation and data analysis capabilities, including mathematics, physics, chemistry, engineering, and life sciences. Ideal for educational tasks, research, and professional applications, it allows users to perform precise calculations and obtain scientific information in real-time, thereby enhancing the capabilities of any system that requires computational intelligence.'; - schema = z.object({ - query: z - .string() - .min(1, 'The query cannot be empty') - .describe('The query to send to WolframAlpha'), - }); - - constructor(fields: WolframAlphaFields) { - super(); - this.appId = fields.appId; - this.httpClient = ky; - } - - async _call( - input: z.infer - ): Promise | string> { - try { - const url = 'https://www.kaibanjs.com/proxy/wolframalpha'; - - const bodyData = { - query: input.query, - }; - - const response = await this.httpClient - .post(url, { - json: bodyData, - headers: { - 'X-APP-ID': this.appId, - 'Content-Type': 'application/json', - }, - }) - .json>(); - - return response; - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${ - error instanceof Error ? error.message : String(error) - }`; - } - } - } -} diff --git a/packages/tools/src/wolfram-alpha/tool.stories.jsx b/packages/tools/src/wolfram-alpha/tool.stories.jsx index fe2fce65..e376266b 100644 --- a/packages/tools/src/wolfram-alpha/tool.stories.jsx +++ b/packages/tools/src/wolfram-alpha/tool.stories.jsx @@ -1,5 +1,5 @@ import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; -import { WolframAlphaTool } from './index.ts'; +import { WolframAlphaTool } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; diff --git a/packages/tools/src/zapier-webhook/index.ts b/packages/tools/src/zapier-webhook/index.ts deleted file mode 100644 index 3f0b818a..00000000 --- a/packages/tools/src/zapier-webhook/index.ts +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Zapier Webhook Tool - * - * This tool allows integration with Zapier's webhook service, enabling seamless - * interaction with thousands of apps and services supported by Zapier. It is - * designed to trigger workflows and automate tasks across various applications - * using Zapier's webhook functionality. - * - * Key features of Zapier Webhook Tool: - * - Easy integration with Zapier's webhook service - * - Trigger workflows and automate tasks across thousands of apps - * - Configurable options for webhook events and payloads - * - * For more information about Zapier, visit: https://zapier.com/ - */ - -import { StructuredTool } from '@langchain/core/tools'; -import { z } from 'zod'; -import ky, { HTTPError } from 'ky'; - -interface ZapierWebhookFields { - url: string; - schema: z.ZodObject; -} - -export class ZapierWebhook extends StructuredTool { - private url: string; - private httpClient: typeof ky; - name = 'zapier_webhook'; - description = - 'A tool for triggering Zapier webhooks to integrate with various services. Input should be a JSON object with the necessary data for the webhook.'; - schema: z.ZodObject; - - /** - * Create a ZapierWebhook tool. - * @param fields - The configuration fields for the tool. - * @param fields.url - The Zapier webhook URL. - * @param fields.schema - The schema for the input data using Zod. - */ - constructor(fields: ZapierWebhookFields) { - super(); - this.url = fields.url; - this.schema = fields.schema; - this.httpClient = ky; - } - - /** - * Call the Zapier webhook with the provided input data. - * @param input - The input data for the webhook. - * @returns The response from the webhook as a JSON string. - */ - async _call(input: z.infer): Promise { - try { - const jsonData = await this.httpClient - .post(this.url, { - body: JSON.stringify(input), - }) - .json>(); - - if (!jsonData || typeof jsonData !== 'object') { - return 'Could not parse Zapier webhook response. Please try again.'; - } - - return JSON.stringify(jsonData); - } catch (error) { - if (error instanceof HTTPError) { - const statusCode = error.response.status; - let errorType = 'Unknown'; - if (statusCode >= 400 && statusCode < 500) { - errorType = 'Client Error'; - } else if (statusCode >= 500) { - errorType = 'Server Error'; - } - return `API request failed: ${errorType} (${statusCode})`; - } else { - return `An unexpected error occurred: ${ - error instanceof Error ? error.message : String(error) - }`; - } - } - } -} diff --git a/packages/tools/src/zapier-webhook/tool.stories.jsx b/packages/tools/src/zapier-webhook/tool.stories.jsx index 1a2f03b6..0792a659 100644 --- a/packages/tools/src/zapier-webhook/tool.stories.jsx +++ b/packages/tools/src/zapier-webhook/tool.stories.jsx @@ -1,8 +1,8 @@ import { z } from 'zod'; import { ToolPreviewer } from '../_utils/ToolPreviewer.jsx'; import { AgentWithToolPreviewer } from '../_utils/AgentWithToolPreviewer.jsx'; -import { GithubIssues } from '../github-issues/index.ts'; -import { ZapierWebhook } from './index.ts'; +import { GithubIssues } from '../github-issues/index.js'; +import { ZapierWebhook } from './index.js'; import { Agent, Task, Team } from '../../../../src/index'; import React from 'react'; diff --git a/packages/tools/tsconfig.json b/packages/tools/tsconfig.json deleted file mode 100644 index 12566e40..00000000 --- a/packages/tools/tsconfig.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "compilerOptions": { - "target": "ES2020", - "module": "ESNext", - "lib": ["ES2020", "DOM"], - "moduleResolution": "bundler", - "esModuleInterop": true, - "strict": true, - "strictNullChecks": true, - "resolveJsonModule": true, - "skipLibCheck": true, - "skipDefaultLibCheck": true, - "declaration": true, - "declarationDir": "./dist/types", - "outDir": "./dist", - "rootDir": "src", - "baseUrl": ".", - "paths": { - "*": ["node_modules/*"] - } - }, - "include": ["src/**/*", "src/server.ts"], - "exclude": ["node_modules", "dist", "**/*.test.ts"] -} diff --git a/types/index.d.ts b/types/index.d.ts index 88bc33f9..64bbf745 100644 --- a/types/index.d.ts +++ b/types/index.d.ts @@ -3,7 +3,7 @@ // Author: @darielnoel // Definitions by: @alienkarma -import { StructuredTool } from 'langchain/tools'; +import { Tool } from 'langchain/tools'; import type { AGENT_STATUS_enum, TASK_STATUS_enum, @@ -112,9 +112,9 @@ export class Agent { /** * Returns the tools available to the agent. - * @returns {StructuredTool[]} The list of tools. + * @returns {Tool[]} The list of tools. */ - get tools(): StructuredTool[]; + get tools(): Tool[]; /** * Returns the status of the agent. diff --git a/types/types.d.ts b/types/types.d.ts index 89abb327..78ea8f97 100644 --- a/types/types.d.ts +++ b/types/types.d.ts @@ -1,4 +1,4 @@ -import { StructuredTool } from 'langchain/tools'; +import { Tool } from 'langchain/tools'; import type { AGENT_STATUS_enum } from './enums.d.ts'; /** @@ -21,7 +21,7 @@ export type TAgentTypes = 'ReactChampionAgent'; * @property {string} role - The role of the agent. * @property {string} goal - The goal of the agent. * @property {string} background - The background of the agent. - * @property {StructuredTool []} [tools] - The tools available to the agent. + * @property {Tool[]} [tools] - The tools available to the agent. * @property {ILLMConfig} [llmConfig] - The language model configuration. * @property {number} [maxIterations] - The maximum number of iterations. * @property {boolean} [forceFinalAnswer] - Whether to force the final answer. @@ -31,7 +31,7 @@ export interface IBaseAgentParams { role: string; goal: string; background: string; - tools?: StructuredTool[]; + tools?: Tool[]; llmConfig?: ILLMConfig; maxIterations?: number; forceFinalAnswer?: boolean; @@ -51,7 +51,7 @@ export interface IBaseAgentParams { * @property {string} role - The agent's role. * @property {string} goal - The agent's goal. * @property {string} background - The agent's background. - * @property {StructuredTool[]} tools - The tools available to the agent. + * @property {Tool[]} tools - The tools available to the agent. * @property {ILLMConfig} llmConfig - The language model configuration. * @property {number} maxIterations - The maximum number of iterations. * @property {boolean} forceFinalAnswer - Whether to force the final answer. @@ -67,7 +67,7 @@ export declare class BaseAgent { role: string; goal: string; background: string; - tools: StructuredTool[]; + tools: Tool[]; llmConfig: ILLMConfig; maxIterations: number; forceFinalAnswer: boolean;