├── .gitignore ├── .prettierrc ├── LICENSE ├── README.md ├── examples ├── calculator.ts ├── file.txt ├── file2.txt ├── files.ts ├── modules.ts └── website.ts ├── package-lock.json ├── package.json ├── src ├── backends │ └── node.ts └── index.ts ├── tsconfig.json └── warning.png /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | .pnpm-debug.log* 9 | 10 | # Diagnostic reports (https://nodejs.org/api/report.html) 11 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 12 | 13 | # Runtime data 14 | pids 15 | *.pid 16 | *.seed 17 | *.pid.lock 18 | 19 | # Directory for instrumented libs generated by jscoverage/JSCover 20 | lib-cov 21 | 22 | # Coverage directory used by tools like istanbul 23 | coverage 24 | *.lcov 25 | 26 | # nyc test coverage 27 | .nyc_output 28 | 29 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 30 | .grunt 31 | 32 | # Bower dependency directory (https://bower.io/) 33 | bower_components 34 | 35 | # node-waf configuration 36 | .lock-wscript 37 | 38 | # Compiled binary addons (https://nodejs.org/api/addons.html) 39 | build/Release 40 | 41 | # Dependency directories 42 | node_modules/ 43 | jspm_packages/ 44 | 45 | # Snowpack dependency directory (https://snowpack.dev/) 46 | web_modules/ 47 | 48 | # TypeScript cache 49 | *.tsbuildinfo 50 | 51 | # Optional npm cache directory 52 | .npm 53 | 54 | # Optional eslint cache 55 | .eslintcache 56 | 57 | # Optional stylelint cache 58 | .stylelintcache 59 | 60 | # Microbundle cache 61 | .rpt2_cache/ 62 | .rts2_cache_cjs/ 63 | .rts2_cache_es/ 64 | .rts2_cache_umd/ 65 | 66 | # Optional REPL history 67 | .node_repl_history 68 | 69 | # Output of 'npm pack' 70 | *.tgz 71 | 72 | # Yarn Integrity file 73 | .yarn-integrity 74 | 75 | # dotenv environment variable files 76 | .env 77 | .env.development.local 78 | .env.test.local 79 | .env.production.local 80 | .env.local 81 | 82 | # parcel-bundler cache (https://parceljs.org/) 83 | .cache 84 | .parcel-cache 85 | 86 | # Next.js build output 87 | .next 88 | out 89 | 90 | # Nuxt.js build / generate output 91 | .nuxt 92 | dist 93 | 94 | # Gatsby files 95 | .cache/ 96 | # Comment in the public line in if your project uses Gatsby and not Next.js 97 | # https://nextjs.org/blog/next-9-1#public-directory-support 98 | # public 99 | 100 | # vuepress build output 101 | .vuepress/dist 102 | 103 | # vuepress v2.x temp and cache directory 104 | .temp 105 | .cache 106 | 107 | # Docusaurus cache and generated files 108 | .docusaurus 109 | 110 | # Serverless directories 111 | .serverless/ 112 | 113 | # FuseBox cache 114 | .fusebox/ 115 | 116 | # DynamoDB Local files 117 | .dynamodb/ 118 | 119 | # TernJS port file 120 | .tern-port 121 | 122 | # Stores VSCode versions used for testing VSCode extensions 123 | .vscode-test 124 | 125 | # yarn v2 126 | .yarn/cache 127 | .yarn/unplugged 128 | .yarn/build-state.yml 129 | .yarn/install-state.gz 130 | .pnp.* 131 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "trailingComma": "es5", 3 | "singleQuote": true, 4 | "semi": false 5 | } 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Mish Ushakov 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ai-fun 2 | 3 | ai-fun is an experimental LLM-powered function library. It lets you define the function purpose, the parameters and the output schema and generates and executes the code for you in the background. Think Cursor/GitHub Copilot but as a pluggable library. 4 | 5 | ``` 6 | npm i ai-fun 7 | ``` 8 | 9 | Complete example: 10 | 11 | `example.ts` 12 | 13 | ```ts 14 | import { z } from 'zod' 15 | import AIFunctionBuilder from 'ai-fun' 16 | import NodeExec from 'ai-fun/src/backends/node' 17 | import { anthropic } from '@ai-sdk/anthropic' 18 | 19 | // Provide a LLM model 20 | const llm = anthropic.chat('claude-3-5-sonnet-20240620') 21 | 22 | // Create a new AI Function Builder using Node/exec backend 23 | const backend = new NodeExec() 24 | const ai = new AIFunctionBuilder(llm, backend) 25 | 26 | // Define the input parameters and output parameters of the function 27 | const parameters = z.object({ a: z.number(), b: z.number() }) 28 | const output = z.number() 29 | 30 | // Generate the function 31 | const f = await ai.function('add values provided', parameters, output) 32 | 33 | // Call the function and log the result 34 | const result = await f({ a: 1, b: 2 }) 35 | console.log(result) 36 | ``` 37 | 38 | Output: 39 | 40 | ```sh 41 | > bun example.ts 42 | 3 43 | ``` 44 | 45 | More examples found under [examples/](examples/) 46 | 47 | ### DANGER ZONE 48 | 49 | Read this Reddit comment before you continue: 50 | 51 | ![](./warning.png) 52 | 53 | ## Caching 54 | 55 | Function caching is enabled by default for cost-saving measures. By default, the functions are stored in a file named `.ai-fun.json`. 56 | 57 | Options you can provide to `AIFunctionBuilder`: 58 | 59 | ```ts 60 | { 61 | debug?: boolean 62 | esModules?: boolean 63 | cache?: boolean 64 | cacheFile?: string 65 | } 66 | ``` 67 | 68 | ## Backends 69 | 70 | You can create your own backends by implementing the `AIFunctionBackend` class: 71 | 72 | ```ts 73 | export abstract class AIFunctionBackend { 74 | abstract init(codeContent: CodeContent): Promise 75 | abstract exec(params: any): Promise 76 | } 77 | ``` 78 | 79 | See [src/backends/node](src/backends/node) for example. 80 | 81 | ### Node (exec) backend 82 | 83 | Executes the AI-generated functions using `node:vm` exec function. 84 | 85 | Options: 86 | 87 | ```ts 88 | { 89 | debug?: boolean 90 | packageFile?: string 91 | installPackages?: boolean 92 | } 93 | ``` 94 | 95 | ## Contribute 96 | 97 | As an open-source project, we welcome contributions from the community. If you are experiencing any bugs or want to add some improvements, please feel free to open an issue or pull request. 98 | -------------------------------------------------------------------------------- /examples/calculator.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod' 2 | import AIFunctionBuilder from '../src' 3 | import NodeExec from '../src/backends/node' 4 | import { anthropic } from '@ai-sdk/anthropic' 5 | 6 | // Provide a LLM model 7 | const llm = anthropic.chat('claude-3-5-sonnet-20240620') 8 | 9 | // Create a new AI Function Executor 10 | const backend = new NodeExec({ debug: true }) 11 | const ai = new AIFunctionBuilder(llm, backend) 12 | 13 | // Define the input parameters and output parameters of the function 14 | const parameters = z.object({ a: z.number(), b: z.number() }) 15 | const output = z.number() 16 | 17 | // Generate the function 18 | const f = await ai.function('add values provided', parameters, output) 19 | 20 | // Call the function and log the result 21 | // const result = await f({ a: 1, b: 2 }) 22 | // console.log(result) 23 | 24 | // Call the function 10 times 25 | for (let i = 0; i < 10; i++) { 26 | const result = await f({ a: i, b: i + 1 }) 27 | console.log(result) 28 | } 29 | -------------------------------------------------------------------------------- /examples/file.txt: -------------------------------------------------------------------------------- 1 | Servus, AI Tinkerers Vienna 2 | -------------------------------------------------------------------------------- /examples/file2.txt: -------------------------------------------------------------------------------- 1 | Follow me on Twitter: @mishushakov 2 | -------------------------------------------------------------------------------- /examples/files.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod' 2 | import AIFunctionBuilder from '../src' 3 | import NodeExec from '../src/backends/node' 4 | import { anthropic } from '@ai-sdk/anthropic' 5 | 6 | // Provide a LLM model 7 | const llm = anthropic.chat('claude-3-5-sonnet-20240620') 8 | 9 | // Create a new AI Function Executor 10 | const backend = new NodeExec() 11 | const ai = new AIFunctionBuilder(llm, backend) 12 | 13 | // Define the input parameters and output parameters of the function 14 | const parameters = z.string() 15 | const output = z.string() 16 | 17 | // Generate the function 18 | const f = await ai.function('read the contents of a file', parameters, output) 19 | 20 | // Call the function and log the result 21 | const result = await f('./examples/file2.txt') 22 | console.log(result) 23 | -------------------------------------------------------------------------------- /examples/modules.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod' 2 | import AIFunctionBuilder from '../src' 3 | import NodeExec from '../src/backends/node' 4 | import { anthropic } from '@ai-sdk/anthropic' 5 | 6 | // Provide a LLM model 7 | const llm = anthropic.chat('claude-3-5-sonnet-20240620') 8 | 9 | const backend = new NodeExec({ 10 | debug: true, 11 | packageFile: 'package.json', 12 | installPackages: true, 13 | }) 14 | 15 | // Create a new AI Function Executor 16 | const ai = new AIFunctionBuilder(llm, backend, { 17 | debug: true, 18 | cache: true, 19 | cacheFile: '.ai-fun.json', 20 | }) 21 | 22 | // Define the input parameters of the function 23 | const parameters = z.object({ a: z.number(), b: z.number() }) 24 | 25 | // Generate the function 26 | const f = await ai.function('log the values provided using pino', parameters) 27 | 28 | // Call the function to log the result 29 | await f({ a: 1, b: 2 }) 30 | -------------------------------------------------------------------------------- /examples/website.ts: -------------------------------------------------------------------------------- 1 | import { z } from 'zod' 2 | import AIFunctionBuilder from '../src' 3 | import NodeExec from '../src/backends/node' 4 | import { anthropic } from '@ai-sdk/anthropic' 5 | 6 | // Provide a LLM model 7 | const llm = anthropic.chat('claude-3-5-sonnet-20240620') 8 | 9 | const backend = new NodeExec({ 10 | debug: true, 11 | packageFile: 'package.json', 12 | installPackages: true, 13 | }) 14 | 15 | // Create a new AI Function Executor 16 | const ai = new AIFunctionBuilder(llm, backend, { 17 | debug: true, 18 | esModules: false, 19 | cache: true, 20 | cacheFile: '.ai-fun.json', 21 | }) 22 | 23 | // Define the input parameters of the function 24 | const parameters = z.string() 25 | const output = z.string() 26 | 27 | // Generate the function 28 | const f = await ai.function( 29 | 'use fetch to grab the website and return its contents', 30 | parameters, 31 | output 32 | ) 33 | 34 | // Call the function to log the result 35 | console.log(await f('https://kubernetes.io')) 36 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ai-fun", 3 | "version": "1.0.1", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "ai-fun", 9 | "version": "1.0.1", 10 | "license": "MIT", 11 | "dependencies": { 12 | "ai": "^3.2.32", 13 | "superjson": "^2.2.1", 14 | "zod": "^3.23.8", 15 | "zod-to-json-schema": "^3.23.1" 16 | }, 17 | "devDependencies": { 18 | "@ai-sdk/anthropic": "^0.0.30", 19 | "@types/node": "^20.14.11" 20 | } 21 | }, 22 | "node_modules/@ai-sdk/anthropic": { 23 | "version": "0.0.30", 24 | "resolved": "https://registry.npmjs.org/@ai-sdk/anthropic/-/anthropic-0.0.30.tgz", 25 | "integrity": "sha512-iPJjKtIH8yk2cf5BNXLN6sn6TTghOh8puWothX4pPVBM/OKC4RWVjYTEELwUv2VDPIw918KBg2j/T0RfTgu+bw==", 26 | "dev": true, 27 | "dependencies": { 28 | "@ai-sdk/provider": "0.0.12", 29 | "@ai-sdk/provider-utils": "1.0.2" 30 | }, 31 | "engines": { 32 | "node": ">=18" 33 | }, 34 | "peerDependencies": { 35 | "zod": "^3.0.0" 36 | } 37 | }, 38 | "node_modules/@ai-sdk/provider": { 39 | "version": "0.0.12", 40 | "resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-0.0.12.tgz", 41 | "integrity": "sha512-oOwPQD8i2Ynpn22cur4sk26FW3mSy6t6/X/K1Ay2yGBKYiSpRyLfObhOrZEGsXDx+3euKy4nEZ193R36NM+tpQ==", 42 | "dependencies": { 43 | "json-schema": "0.4.0" 44 | }, 45 | "engines": { 46 | "node": ">=18" 47 | } 48 | }, 49 | "node_modules/@ai-sdk/provider-utils": { 50 | "version": "1.0.2", 51 | "resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-1.0.2.tgz", 52 | "integrity": "sha512-57f6O4OFVNEpI8Z8o+K40tIB3YQiTw+VCql/qrAO9Utq7Ti1o6+X9tvm177DlZJL7ft0Rwzvgy48S9YhrEKgmA==", 53 | "dependencies": { 54 | "@ai-sdk/provider": "0.0.12", 55 | "eventsource-parser": "1.1.2", 56 | "nanoid": "3.3.6", 57 | "secure-json-parse": "2.7.0" 58 | }, 59 | "engines": { 60 | "node": ">=18" 61 | }, 62 | "peerDependencies": { 63 | "zod": "^3.0.0" 64 | }, 65 | "peerDependenciesMeta": { 66 | "zod": { 67 | "optional": true 68 | } 69 | } 70 | }, 71 | "node_modules/@ai-sdk/react": { 72 | "version": "0.0.25", 73 | "resolved": "https://registry.npmjs.org/@ai-sdk/react/-/react-0.0.25.tgz", 74 | "integrity": "sha512-79jFOpFRJs0vn9vOTlq0+jSFW8ztTJEXfUYTk+EwCymuGaSdbQQEKEMIDuRpaeOicNjVXZzbkKlQl9bv2l1R/w==", 75 | "dependencies": { 76 | "@ai-sdk/provider-utils": "1.0.2", 77 | "@ai-sdk/ui-utils": "0.0.16", 78 | "swr": "2.2.5" 79 | }, 80 | "engines": { 81 | "node": ">=18" 82 | }, 83 | "peerDependencies": { 84 | "react": "^18 || ^19", 85 | "zod": "^3.0.0" 86 | }, 87 | "peerDependenciesMeta": { 88 | "react": { 89 | "optional": true 90 | }, 91 | "zod": { 92 | "optional": true 93 | } 94 | } 95 | }, 96 | "node_modules/@ai-sdk/solid": { 97 | "version": "0.0.18", 98 | "resolved": "https://registry.npmjs.org/@ai-sdk/solid/-/solid-0.0.18.tgz", 99 | "integrity": "sha512-XHPegleEdbTnb+B1dKsYB8E2oauHr3WP4W4VJ/8xYe7gaJK6Tl88Z8dcIo4szSYgAjJGzOsm0Air3vExTEtO6A==", 100 | "dependencies": { 101 | "@ai-sdk/ui-utils": "0.0.16" 102 | }, 103 | "engines": { 104 | "node": ">=18" 105 | }, 106 | "peerDependencies": { 107 | "solid-js": "^1.7.7" 108 | }, 109 | "peerDependenciesMeta": { 110 | "solid-js": { 111 | "optional": true 112 | } 113 | } 114 | }, 115 | "node_modules/@ai-sdk/svelte": { 116 | "version": "0.0.19", 117 | "resolved": "https://registry.npmjs.org/@ai-sdk/svelte/-/svelte-0.0.19.tgz", 118 | "integrity": "sha512-eRBNXUshfwzYm3iaPCIZeV+XHZ0Hkrgj+V0Jy3bGvVzDX0cAs0EAxGPqYFArLFhuEBqiTQrW3QYL540GWYPl6g==", 119 | "dependencies": { 120 | "@ai-sdk/provider-utils": "1.0.2", 121 | "@ai-sdk/ui-utils": "0.0.16", 122 | "sswr": "2.1.0" 123 | }, 124 | "engines": { 125 | "node": ">=18" 126 | }, 127 | "peerDependencies": { 128 | "svelte": "^3.0.0 || ^4.0.0" 129 | }, 130 | "peerDependenciesMeta": { 131 | "svelte": { 132 | "optional": true 133 | } 134 | } 135 | }, 136 | "node_modules/@ai-sdk/ui-utils": { 137 | "version": "0.0.16", 138 | "resolved": "https://registry.npmjs.org/@ai-sdk/ui-utils/-/ui-utils-0.0.16.tgz", 139 | "integrity": "sha512-DWPj2gPtY+MfEwxPeUZ/pLlKzfvL2u0p2fZLCYDJhJJgFWkvjvKUejRYH9M5uj8zTkZlwi92Gy+vZ20jto5zwQ==", 140 | "dependencies": { 141 | "@ai-sdk/provider-utils": "1.0.2", 142 | "secure-json-parse": "2.7.0" 143 | }, 144 | "engines": { 145 | "node": ">=18" 146 | }, 147 | "peerDependencies": { 148 | "zod": "^3.0.0" 149 | }, 150 | "peerDependenciesMeta": { 151 | "zod": { 152 | "optional": true 153 | } 154 | } 155 | }, 156 | "node_modules/@ai-sdk/vue": { 157 | "version": "0.0.20", 158 | "resolved": "https://registry.npmjs.org/@ai-sdk/vue/-/vue-0.0.20.tgz", 159 | "integrity": "sha512-yI1fIy2hjDy2vCTVcs4vatJ/Pn7UDFUynE6RLOH+K1FRwGEOYLmGO7s3Z59YHe4ZJuPQqWZEjG3dYSGyUJUJYg==", 160 | "dependencies": { 161 | "@ai-sdk/provider-utils": "0.0.14", 162 | "@ai-sdk/ui-utils": "0.0.16", 163 | "swrv": "1.0.4" 164 | }, 165 | "engines": { 166 | "node": ">=18" 167 | }, 168 | "peerDependencies": { 169 | "vue": "^3.3.4" 170 | }, 171 | "peerDependenciesMeta": { 172 | "vue": { 173 | "optional": true 174 | } 175 | } 176 | }, 177 | "node_modules/@ai-sdk/vue/node_modules/@ai-sdk/provider": { 178 | "version": "0.0.10", 179 | "resolved": "https://registry.npmjs.org/@ai-sdk/provider/-/provider-0.0.10.tgz", 180 | "integrity": "sha512-NzkrtREQpHID1cTqY/C4CI30PVOaXWKYytDR2EcytmFgnP7Z6+CrGIA/YCnNhYAuUm6Nx+nGpRL/Hmyrv7NYzg==", 181 | "dependencies": { 182 | "json-schema": "0.4.0" 183 | }, 184 | "engines": { 185 | "node": ">=18" 186 | } 187 | }, 188 | "node_modules/@ai-sdk/vue/node_modules/@ai-sdk/provider-utils": { 189 | "version": "0.0.14", 190 | "resolved": "https://registry.npmjs.org/@ai-sdk/provider-utils/-/provider-utils-0.0.14.tgz", 191 | "integrity": "sha512-PCQFN3MlC6DShS/81IFU9NVvt9OekQGiZTEowRc2AwAwWrDsv7er3UkcMswFAL/Z7xZKjgu0dZTNH1z9oUlo7A==", 192 | "dependencies": { 193 | "@ai-sdk/provider": "0.0.10", 194 | "eventsource-parser": "1.1.2", 195 | "nanoid": "3.3.6", 196 | "secure-json-parse": "2.7.0" 197 | }, 198 | "engines": { 199 | "node": ">=18" 200 | }, 201 | "peerDependencies": { 202 | "zod": "^3.0.0" 203 | }, 204 | "peerDependenciesMeta": { 205 | "zod": { 206 | "optional": true 207 | } 208 | } 209 | }, 210 | "node_modules/@ampproject/remapping": { 211 | "version": "2.3.0", 212 | "resolved": "https://registry.npmjs.org/@ampproject/remapping/-/remapping-2.3.0.tgz", 213 | "integrity": "sha512-30iZtAPgz+LTIYoeivqYo853f02jBYSd5uGnGpkFV0M3xOt9aN73erkgYAmZU43x4VfqcnLxW9Kpg3R5LC4YYw==", 214 | "peer": true, 215 | "dependencies": { 216 | "@jridgewell/gen-mapping": "^0.3.5", 217 | "@jridgewell/trace-mapping": "^0.3.24" 218 | }, 219 | "engines": { 220 | "node": ">=6.0.0" 221 | } 222 | }, 223 | "node_modules/@babel/parser": { 224 | "version": "7.24.8", 225 | "resolved": "https://registry.npmjs.org/@babel/parser/-/parser-7.24.8.tgz", 226 | "integrity": "sha512-WzfbgXOkGzZiXXCqk43kKwZjzwx4oulxZi3nq2TYL9mOjQv6kYwul9mz6ID36njuL7Xkp6nJEfok848Zj10j/w==", 227 | "peer": true, 228 | "bin": { 229 | "parser": "bin/babel-parser.js" 230 | }, 231 | "engines": { 232 | "node": ">=6.0.0" 233 | } 234 | }, 235 | "node_modules/@jridgewell/gen-mapping": { 236 | "version": "0.3.5", 237 | "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.5.tgz", 238 | "integrity": "sha512-IzL8ZoEDIBRWEzlCcRhOaCupYyN5gdIK+Q6fbFdPDg6HqX6jpkItn7DFIpW9LQzXG6Df9sA7+OKnq0qlz/GaQg==", 239 | "peer": true, 240 | "dependencies": { 241 | "@jridgewell/set-array": "^1.2.1", 242 | "@jridgewell/sourcemap-codec": "^1.4.10", 243 | "@jridgewell/trace-mapping": "^0.3.24" 244 | }, 245 | "engines": { 246 | "node": ">=6.0.0" 247 | } 248 | }, 249 | "node_modules/@jridgewell/resolve-uri": { 250 | "version": "3.1.2", 251 | "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.1.2.tgz", 252 | "integrity": "sha512-bRISgCIjP20/tbWSPWMEi54QVPRZExkuD9lJL+UIxUKtwVJA8wW1Trb1jMs1RFXo1CBTNZ/5hpC9QvmKWdopKw==", 253 | "peer": true, 254 | "engines": { 255 | "node": ">=6.0.0" 256 | } 257 | }, 258 | "node_modules/@jridgewell/set-array": { 259 | "version": "1.2.1", 260 | "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.2.1.tgz", 261 | "integrity": "sha512-R8gLRTZeyp03ymzP/6Lil/28tGeGEzhx1q2k703KGWRAI1VdvPIXdG70VJc2pAMw3NA6JKL5hhFu1sJX0Mnn/A==", 262 | "peer": true, 263 | "engines": { 264 | "node": ">=6.0.0" 265 | } 266 | }, 267 | "node_modules/@jridgewell/sourcemap-codec": { 268 | "version": "1.5.0", 269 | "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.5.0.tgz", 270 | "integrity": "sha512-gv3ZRaISU3fjPAgNsriBRqGWQL6quFx04YMPW/zD8XMLsU32mhCCbfbO6KZFLjvYpCZ8zyDEgqsgf+PwPaM7GQ==", 271 | "peer": true 272 | }, 273 | "node_modules/@jridgewell/trace-mapping": { 274 | "version": "0.3.25", 275 | "resolved": "https://registry.npmjs.org/@jridgewell/trace-mapping/-/trace-mapping-0.3.25.tgz", 276 | "integrity": "sha512-vNk6aEwybGtawWmy/PzwnGDOjCkLWSD2wqvjGGAgOAwCGWySYXfYoxt00IJkTF+8Lb57DwOb3Aa0o9CApepiYQ==", 277 | "peer": true, 278 | "dependencies": { 279 | "@jridgewell/resolve-uri": "^3.1.0", 280 | "@jridgewell/sourcemap-codec": "^1.4.14" 281 | } 282 | }, 283 | "node_modules/@opentelemetry/api": { 284 | "version": "1.9.0", 285 | "resolved": "https://registry.npmjs.org/@opentelemetry/api/-/api-1.9.0.tgz", 286 | "integrity": "sha512-3giAOQvZiH5F9bMlMiv8+GSPMeqg0dbaeo58/0SlA9sxSqZhnUtxzX9/2FzyhS9sWQf5S0GJE0AKBrFqjpeYcg==", 287 | "engines": { 288 | "node": ">=8.0.0" 289 | } 290 | }, 291 | "node_modules/@types/diff-match-patch": { 292 | "version": "1.0.36", 293 | "resolved": "https://registry.npmjs.org/@types/diff-match-patch/-/diff-match-patch-1.0.36.tgz", 294 | "integrity": "sha512-xFdR6tkm0MWvBfO8xXCSsinYxHcqkQUlcHeSpMC2ukzOb6lwQAfDmW+Qt0AvlGd8HpsS28qKsB+oPeJn9I39jg==" 295 | }, 296 | "node_modules/@types/estree": { 297 | "version": "1.0.5", 298 | "resolved": "https://registry.npmjs.org/@types/estree/-/estree-1.0.5.tgz", 299 | "integrity": "sha512-/kYRxGDLWzHOB7q+wtSUQlFrtcdUccpfy+X+9iMBpHK8QLLhx2wIPYuS5DYtR9Wa/YlZAbIovy7qVdB1Aq6Lyw==", 300 | "peer": true 301 | }, 302 | "node_modules/@types/node": { 303 | "version": "20.14.11", 304 | "resolved": "https://registry.npmjs.org/@types/node/-/node-20.14.11.tgz", 305 | "integrity": "sha512-kprQpL8MMeszbz6ojB5/tU8PLN4kesnN8Gjzw349rDlNgsSzg90lAVj3llK99Dh7JON+t9AuscPPFW6mPbTnSA==", 306 | "dev": true, 307 | "dependencies": { 308 | "undici-types": "~5.26.4" 309 | } 310 | }, 311 | "node_modules/@vue/compiler-core": { 312 | "version": "3.4.33", 313 | "resolved": "https://registry.npmjs.org/@vue/compiler-core/-/compiler-core-3.4.33.tgz", 314 | "integrity": "sha512-MoIREbkdPQlnGfSKDMgzTqzqx5nmEjIc0ydLVYlTACGBsfvOJ4tHSbZXKVF536n6fB+0eZaGEOqsGThPpdvF5A==", 315 | "peer": true, 316 | "dependencies": { 317 | "@babel/parser": "^7.24.7", 318 | "@vue/shared": "3.4.33", 319 | "entities": "^4.5.0", 320 | "estree-walker": "^2.0.2", 321 | "source-map-js": "^1.2.0" 322 | } 323 | }, 324 | "node_modules/@vue/compiler-core/node_modules/estree-walker": { 325 | "version": "2.0.2", 326 | "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", 327 | "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", 328 | "peer": true 329 | }, 330 | "node_modules/@vue/compiler-dom": { 331 | "version": "3.4.33", 332 | "resolved": "https://registry.npmjs.org/@vue/compiler-dom/-/compiler-dom-3.4.33.tgz", 333 | "integrity": "sha512-GzB8fxEHKw0gGet5BKlpfXEqoBnzSVWwMnT+dc25wE7pFEfrU/QsvjZMP9rD4iVXHBBoemTct8mN0GJEI6ZX5A==", 334 | "peer": true, 335 | "dependencies": { 336 | "@vue/compiler-core": "3.4.33", 337 | "@vue/shared": "3.4.33" 338 | } 339 | }, 340 | "node_modules/@vue/compiler-sfc": { 341 | "version": "3.4.33", 342 | "resolved": "https://registry.npmjs.org/@vue/compiler-sfc/-/compiler-sfc-3.4.33.tgz", 343 | "integrity": "sha512-7rk7Vbkn21xMwIUpHQR4hCVejwE6nvhBOiDgoBcR03qvGqRKA7dCBSsHZhwhYUsmjlbJ7OtD5UFIyhP6BY+c8A==", 344 | "peer": true, 345 | "dependencies": { 346 | "@babel/parser": "^7.24.7", 347 | "@vue/compiler-core": "3.4.33", 348 | "@vue/compiler-dom": "3.4.33", 349 | "@vue/compiler-ssr": "3.4.33", 350 | "@vue/shared": "3.4.33", 351 | "estree-walker": "^2.0.2", 352 | "magic-string": "^0.30.10", 353 | "postcss": "^8.4.39", 354 | "source-map-js": "^1.2.0" 355 | } 356 | }, 357 | "node_modules/@vue/compiler-sfc/node_modules/estree-walker": { 358 | "version": "2.0.2", 359 | "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-2.0.2.tgz", 360 | "integrity": "sha512-Rfkk/Mp/DL7JVje3u18FxFujQlTNR2q6QfMSMB7AvCBx91NGj/ba3kCfza0f6dVDbw7YlRf/nDrn7pQrCCyQ/w==", 361 | "peer": true 362 | }, 363 | "node_modules/@vue/compiler-ssr": { 364 | "version": "3.4.33", 365 | "resolved": "https://registry.npmjs.org/@vue/compiler-ssr/-/compiler-ssr-3.4.33.tgz", 366 | "integrity": "sha512-0WveC9Ai+eT/1b6LCV5IfsufBZ0HP7pSSTdDjcuW302tTEgoBw8rHVHKPbGUtzGReUFCRXbv6zQDDgucnV2WzQ==", 367 | "peer": true, 368 | "dependencies": { 369 | "@vue/compiler-dom": "3.4.33", 370 | "@vue/shared": "3.4.33" 371 | } 372 | }, 373 | "node_modules/@vue/reactivity": { 374 | "version": "3.4.33", 375 | "resolved": "https://registry.npmjs.org/@vue/reactivity/-/reactivity-3.4.33.tgz", 376 | "integrity": "sha512-B24QIelahDbyHipBgbUItQblbd4w5HpG3KccL+YkGyo3maXyS253FzcTR3pSz739OTphmzlxP7JxEMWBpewilA==", 377 | "peer": true, 378 | "dependencies": { 379 | "@vue/shared": "3.4.33" 380 | } 381 | }, 382 | "node_modules/@vue/runtime-core": { 383 | "version": "3.4.33", 384 | "resolved": "https://registry.npmjs.org/@vue/runtime-core/-/runtime-core-3.4.33.tgz", 385 | "integrity": "sha512-6wavthExzT4iAxpe8q37/rDmf44nyOJGISJPxCi9YsQO+8w9v0gLCFLfH5TzD1V1AYrTAdiF4Y1cgUmP68jP6w==", 386 | "peer": true, 387 | "dependencies": { 388 | "@vue/reactivity": "3.4.33", 389 | "@vue/shared": "3.4.33" 390 | } 391 | }, 392 | "node_modules/@vue/runtime-dom": { 393 | "version": "3.4.33", 394 | "resolved": "https://registry.npmjs.org/@vue/runtime-dom/-/runtime-dom-3.4.33.tgz", 395 | "integrity": "sha512-iHsMCUSFJ+4z432Bn9kZzHX+zOXa6+iw36DaVRmKYZpPt9jW9riF32SxNwB124i61kp9+AZtheQ/mKoJLerAaQ==", 396 | "peer": true, 397 | "dependencies": { 398 | "@vue/reactivity": "3.4.33", 399 | "@vue/runtime-core": "3.4.33", 400 | "@vue/shared": "3.4.33", 401 | "csstype": "^3.1.3" 402 | } 403 | }, 404 | "node_modules/@vue/server-renderer": { 405 | "version": "3.4.33", 406 | "resolved": "https://registry.npmjs.org/@vue/server-renderer/-/server-renderer-3.4.33.tgz", 407 | "integrity": "sha512-jTH0d6gQcaYideFP/k0WdEu8PpRS9MF8d0b6SfZzNi+ap972pZ0TNIeTaESwdOtdY0XPVj54XEJ6K0wXxir4fw==", 408 | "peer": true, 409 | "dependencies": { 410 | "@vue/compiler-ssr": "3.4.33", 411 | "@vue/shared": "3.4.33" 412 | }, 413 | "peerDependencies": { 414 | "vue": "3.4.33" 415 | } 416 | }, 417 | "node_modules/@vue/shared": { 418 | "version": "3.4.33", 419 | "resolved": "https://registry.npmjs.org/@vue/shared/-/shared-3.4.33.tgz", 420 | "integrity": "sha512-aoRY0jQk3A/cuvdkodTrM4NMfxco8n55eG4H7ML/CRy7OryHfiqvug4xrCBBMbbN+dvXAetDDwZW9DXWWjBntA==", 421 | "peer": true 422 | }, 423 | "node_modules/acorn": { 424 | "version": "8.12.1", 425 | "resolved": "https://registry.npmjs.org/acorn/-/acorn-8.12.1.tgz", 426 | "integrity": "sha512-tcpGyI9zbizT9JbV6oYE477V6mTlXvvi0T0G3SNIYE2apm/G5huBa1+K89VGeovbg+jycCrfhl3ADxErOuO6Jg==", 427 | "peer": true, 428 | "bin": { 429 | "acorn": "bin/acorn" 430 | }, 431 | "engines": { 432 | "node": ">=0.4.0" 433 | } 434 | }, 435 | "node_modules/ai": { 436 | "version": "3.2.32", 437 | "resolved": "https://registry.npmjs.org/ai/-/ai-3.2.32.tgz", 438 | "integrity": "sha512-1TmEY6jkgouP/OYLdt4rBZAUg6mFSfwLPUEwk0D7pLKy3tYB3OYz/XvZ5X8NShG3wNTv7pMzE8znM0vg5RIdoA==", 439 | "dependencies": { 440 | "@ai-sdk/provider": "0.0.12", 441 | "@ai-sdk/provider-utils": "1.0.2", 442 | "@ai-sdk/react": "0.0.25", 443 | "@ai-sdk/solid": "0.0.18", 444 | "@ai-sdk/svelte": "0.0.19", 445 | "@ai-sdk/ui-utils": "0.0.16", 446 | "@ai-sdk/vue": "0.0.20", 447 | "@opentelemetry/api": "1.9.0", 448 | "eventsource-parser": "1.1.2", 449 | "json-schema": "0.4.0", 450 | "jsondiffpatch": "0.6.0", 451 | "nanoid": "3.3.6", 452 | "secure-json-parse": "2.7.0", 453 | "sswr": "2.1.0", 454 | "zod-to-json-schema": "3.22.5" 455 | }, 456 | "engines": { 457 | "node": ">=18" 458 | }, 459 | "peerDependencies": { 460 | "openai": "^4.42.0", 461 | "react": "^18 || ^19", 462 | "svelte": "^3.0.0 || ^4.0.0", 463 | "zod": "^3.0.0" 464 | }, 465 | "peerDependenciesMeta": { 466 | "openai": { 467 | "optional": true 468 | }, 469 | "react": { 470 | "optional": true 471 | }, 472 | "svelte": { 473 | "optional": true 474 | }, 475 | "zod": { 476 | "optional": true 477 | } 478 | } 479 | }, 480 | "node_modules/ai/node_modules/zod-to-json-schema": { 481 | "version": "3.22.5", 482 | "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.22.5.tgz", 483 | "integrity": "sha512-+akaPo6a0zpVCCseDed504KBJUQpEW5QZw7RMneNmKw+fGaML1Z9tUNLnHHAC8x6dzVRO1eB2oEMyZRnuBZg7Q==", 484 | "peerDependencies": { 485 | "zod": "^3.22.4" 486 | } 487 | }, 488 | "node_modules/aria-query": { 489 | "version": "5.3.0", 490 | "resolved": "https://registry.npmjs.org/aria-query/-/aria-query-5.3.0.tgz", 491 | "integrity": "sha512-b0P0sZPKtyu8HkeRAfCq0IfURZK+SuwMjY1UXGBU27wpAiTwQAIlq56IbIO+ytk/JjS1fMR14ee5WBBfKi5J6A==", 492 | "peer": true, 493 | "dependencies": { 494 | "dequal": "^2.0.3" 495 | } 496 | }, 497 | "node_modules/axobject-query": { 498 | "version": "4.1.0", 499 | "resolved": "https://registry.npmjs.org/axobject-query/-/axobject-query-4.1.0.tgz", 500 | "integrity": "sha512-qIj0G9wZbMGNLjLmg1PT6v2mE9AH2zlnADJD/2tC6E00hgmhUOfEB6greHPAfLRSufHqROIUTkw6E+M3lH0PTQ==", 501 | "peer": true, 502 | "engines": { 503 | "node": ">= 0.4" 504 | } 505 | }, 506 | "node_modules/chalk": { 507 | "version": "5.3.0", 508 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", 509 | "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", 510 | "engines": { 511 | "node": "^12.17.0 || ^14.13 || >=16.0.0" 512 | }, 513 | "funding": { 514 | "url": "https://github.com/chalk/chalk?sponsor=1" 515 | } 516 | }, 517 | "node_modules/client-only": { 518 | "version": "0.0.1", 519 | "resolved": "https://registry.npmjs.org/client-only/-/client-only-0.0.1.tgz", 520 | "integrity": "sha512-IV3Ou0jSMzZrd3pZ48nLkT9DA7Ag1pnPzaiQhpW7c3RbcqqzvzzVu+L8gfqMp/8IM2MQtSiqaCxrrcfu8I8rMA==" 521 | }, 522 | "node_modules/code-red": { 523 | "version": "1.0.4", 524 | "resolved": "https://registry.npmjs.org/code-red/-/code-red-1.0.4.tgz", 525 | "integrity": "sha512-7qJWqItLA8/VPVlKJlFXU+NBlo/qyfs39aJcuMT/2ere32ZqvF5OSxgdM5xOfJJ7O429gg2HM47y8v9P+9wrNw==", 526 | "peer": true, 527 | "dependencies": { 528 | "@jridgewell/sourcemap-codec": "^1.4.15", 529 | "@types/estree": "^1.0.1", 530 | "acorn": "^8.10.0", 531 | "estree-walker": "^3.0.3", 532 | "periscopic": "^3.1.0" 533 | } 534 | }, 535 | "node_modules/copy-anything": { 536 | "version": "3.0.5", 537 | "resolved": "https://registry.npmjs.org/copy-anything/-/copy-anything-3.0.5.tgz", 538 | "integrity": "sha512-yCEafptTtb4bk7GLEQoM8KVJpxAfdBJYaXyzQEgQQQgYrZiDp8SJmGKlYza6CYjEDNstAdNdKA3UuoULlEbS6w==", 539 | "dependencies": { 540 | "is-what": "^4.1.8" 541 | }, 542 | "engines": { 543 | "node": ">=12.13" 544 | }, 545 | "funding": { 546 | "url": "https://github.com/sponsors/mesqueeb" 547 | } 548 | }, 549 | "node_modules/css-tree": { 550 | "version": "2.3.1", 551 | "resolved": "https://registry.npmjs.org/css-tree/-/css-tree-2.3.1.tgz", 552 | "integrity": "sha512-6Fv1DV/TYw//QF5IzQdqsNDjx/wc8TrMBZsqjL9eW01tWb7R7k/mq+/VXfJCl7SoD5emsJop9cOByJZfs8hYIw==", 553 | "peer": true, 554 | "dependencies": { 555 | "mdn-data": "2.0.30", 556 | "source-map-js": "^1.0.1" 557 | }, 558 | "engines": { 559 | "node": "^10 || ^12.20.0 || ^14.13.0 || >=15.0.0" 560 | } 561 | }, 562 | "node_modules/csstype": { 563 | "version": "3.1.3", 564 | "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.3.tgz", 565 | "integrity": "sha512-M1uQkMl8rQK/szD0LNhtqxIPLpimGm8sOBwU7lLnCpSbTyY3yeU1Vc7l4KT5zT4s/yOxHH5O7tIuuLOCnLADRw==", 566 | "peer": true 567 | }, 568 | "node_modules/dequal": { 569 | "version": "2.0.3", 570 | "resolved": "https://registry.npmjs.org/dequal/-/dequal-2.0.3.tgz", 571 | "integrity": "sha512-0je+qPKHEMohvfRTCEo3CrPG6cAzAYgmzKyxRiYSSDkS6eGJdyVJm7WaYA5ECaAD9wLB2T4EEeymA5aFVcYXCA==", 572 | "peer": true, 573 | "engines": { 574 | "node": ">=6" 575 | } 576 | }, 577 | "node_modules/diff-match-patch": { 578 | "version": "1.0.5", 579 | "resolved": "https://registry.npmjs.org/diff-match-patch/-/diff-match-patch-1.0.5.tgz", 580 | "integrity": "sha512-IayShXAgj/QMXgB0IWmKx+rOPuGMhqm5w6jvFxmVenXKIzRqTAAsbBPT3kWQeGANj3jGgvcvv4yK6SxqYmikgw==" 581 | }, 582 | "node_modules/entities": { 583 | "version": "4.5.0", 584 | "resolved": "https://registry.npmjs.org/entities/-/entities-4.5.0.tgz", 585 | "integrity": "sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==", 586 | "peer": true, 587 | "engines": { 588 | "node": ">=0.12" 589 | }, 590 | "funding": { 591 | "url": "https://github.com/fb55/entities?sponsor=1" 592 | } 593 | }, 594 | "node_modules/estree-walker": { 595 | "version": "3.0.3", 596 | "resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-3.0.3.tgz", 597 | "integrity": "sha512-7RUKfXgSMMkzt6ZuXmqapOurLGPPfgj6l9uRZ7lRGolvk0y2yocc35LdcxKC5PQZdn2DMqioAQ2NoWcrTKmm6g==", 598 | "peer": true, 599 | "dependencies": { 600 | "@types/estree": "^1.0.0" 601 | } 602 | }, 603 | "node_modules/eventsource-parser": { 604 | "version": "1.1.2", 605 | "resolved": "https://registry.npmjs.org/eventsource-parser/-/eventsource-parser-1.1.2.tgz", 606 | "integrity": "sha512-v0eOBUbiaFojBu2s2NPBfYUoRR9GjcDNvCXVaqEf5vVfpIAh9f8RCo4vXTP8c63QRKCFwoLpMpTdPwwhEKVgzA==", 607 | "engines": { 608 | "node": ">=14.18" 609 | } 610 | }, 611 | "node_modules/is-reference": { 612 | "version": "3.0.2", 613 | "resolved": "https://registry.npmjs.org/is-reference/-/is-reference-3.0.2.tgz", 614 | "integrity": "sha512-v3rht/LgVcsdZa3O2Nqs+NMowLOxeOm7Ay9+/ARQ2F+qEoANRcqrjAZKGN0v8ymUetZGgkp26LTnGT7H0Qo9Pg==", 615 | "peer": true, 616 | "dependencies": { 617 | "@types/estree": "*" 618 | } 619 | }, 620 | "node_modules/is-what": { 621 | "version": "4.1.16", 622 | "resolved": "https://registry.npmjs.org/is-what/-/is-what-4.1.16.tgz", 623 | "integrity": "sha512-ZhMwEosbFJkA0YhFnNDgTM4ZxDRsS6HqTo7qsZM08fehyRYIYa0yHu5R6mgo1n/8MgaPBXiPimPD77baVFYg+A==", 624 | "engines": { 625 | "node": ">=12.13" 626 | }, 627 | "funding": { 628 | "url": "https://github.com/sponsors/mesqueeb" 629 | } 630 | }, 631 | "node_modules/js-tokens": { 632 | "version": "4.0.0", 633 | "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", 634 | "integrity": "sha512-RdJUflcE3cUzKiMqQgsCu06FPu9UdIJO0beYbPhHN4k6apgJtifcoCtT9bcxOpYBtpD2kCM6Sbzg4CausW/PKQ==", 635 | "peer": true 636 | }, 637 | "node_modules/json-schema": { 638 | "version": "0.4.0", 639 | "resolved": "https://registry.npmjs.org/json-schema/-/json-schema-0.4.0.tgz", 640 | "integrity": "sha512-es94M3nTIfsEPisRafak+HDLfHXnKBhV3vU5eqPcS3flIWqcxJWgXHXiey3YrpaNsanY5ei1VoYEbOzijuq9BA==" 641 | }, 642 | "node_modules/jsondiffpatch": { 643 | "version": "0.6.0", 644 | "resolved": "https://registry.npmjs.org/jsondiffpatch/-/jsondiffpatch-0.6.0.tgz", 645 | "integrity": "sha512-3QItJOXp2AP1uv7waBkao5nCvhEv+QmJAd38Ybq7wNI74Q+BBmnLn4EDKz6yI9xGAIQoUF87qHt+kc1IVxB4zQ==", 646 | "dependencies": { 647 | "@types/diff-match-patch": "^1.0.36", 648 | "chalk": "^5.3.0", 649 | "diff-match-patch": "^1.0.5" 650 | }, 651 | "bin": { 652 | "jsondiffpatch": "bin/jsondiffpatch.js" 653 | }, 654 | "engines": { 655 | "node": "^18.0.0 || >=20.0.0" 656 | } 657 | }, 658 | "node_modules/locate-character": { 659 | "version": "3.0.0", 660 | "resolved": "https://registry.npmjs.org/locate-character/-/locate-character-3.0.0.tgz", 661 | "integrity": "sha512-SW13ws7BjaeJ6p7Q6CO2nchbYEc3X3J6WrmTTDto7yMPqVSZTUyY5Tjbid+Ab8gLnATtygYtiDIJGQRRn2ZOiA==", 662 | "peer": true 663 | }, 664 | "node_modules/loose-envify": { 665 | "version": "1.4.0", 666 | "resolved": "https://registry.npmjs.org/loose-envify/-/loose-envify-1.4.0.tgz", 667 | "integrity": "sha512-lyuxPGr/Wfhrlem2CL/UcnUc1zcqKAImBDzukY7Y5F/yQiNdko6+fRLevlw1HgMySw7f611UIY408EtxRSoK3Q==", 668 | "peer": true, 669 | "dependencies": { 670 | "js-tokens": "^3.0.0 || ^4.0.0" 671 | }, 672 | "bin": { 673 | "loose-envify": "cli.js" 674 | } 675 | }, 676 | "node_modules/magic-string": { 677 | "version": "0.30.10", 678 | "resolved": "https://registry.npmjs.org/magic-string/-/magic-string-0.30.10.tgz", 679 | "integrity": "sha512-iIRwTIf0QKV3UAnYK4PU8uiEc4SRh5jX0mwpIwETPpHdhVM4f53RSwS/vXvN1JhGX+Cs7B8qIq3d6AH49O5fAQ==", 680 | "peer": true, 681 | "dependencies": { 682 | "@jridgewell/sourcemap-codec": "^1.4.15" 683 | } 684 | }, 685 | "node_modules/mdn-data": { 686 | "version": "2.0.30", 687 | "resolved": "https://registry.npmjs.org/mdn-data/-/mdn-data-2.0.30.tgz", 688 | "integrity": "sha512-GaqWWShW4kv/G9IEucWScBx9G1/vsFZZJUO+tD26M8J8z3Kw5RDQjaoZe03YAClgeS/SWPOcb4nkFBTEi5DUEA==", 689 | "peer": true 690 | }, 691 | "node_modules/nanoid": { 692 | "version": "3.3.6", 693 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.6.tgz", 694 | "integrity": "sha512-BGcqMMJuToF7i1rt+2PWSNVnWIkGCU78jBG3RxO/bZlnZPK2Cmi2QaffxGO/2RvWi9sL+FAiRiXMgsyxQ1DIDA==", 695 | "funding": [ 696 | { 697 | "type": "github", 698 | "url": "https://github.com/sponsors/ai" 699 | } 700 | ], 701 | "bin": { 702 | "nanoid": "bin/nanoid.cjs" 703 | }, 704 | "engines": { 705 | "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" 706 | } 707 | }, 708 | "node_modules/periscopic": { 709 | "version": "3.1.0", 710 | "resolved": "https://registry.npmjs.org/periscopic/-/periscopic-3.1.0.tgz", 711 | "integrity": "sha512-vKiQ8RRtkl9P+r/+oefh25C3fhybptkHKCZSPlcXiJux2tJF55GnEj3BVn4A5gKfq9NWWXXrxkHBwVPUfH0opw==", 712 | "peer": true, 713 | "dependencies": { 714 | "@types/estree": "^1.0.0", 715 | "estree-walker": "^3.0.0", 716 | "is-reference": "^3.0.0" 717 | } 718 | }, 719 | "node_modules/picocolors": { 720 | "version": "1.0.1", 721 | "resolved": "https://registry.npmjs.org/picocolors/-/picocolors-1.0.1.tgz", 722 | "integrity": "sha512-anP1Z8qwhkbmu7MFP5iTt+wQKXgwzf7zTyGlcdzabySa9vd0Xt392U0rVmz9poOaBj0uHJKyyo9/upk0HrEQew==", 723 | "peer": true 724 | }, 725 | "node_modules/postcss": { 726 | "version": "8.4.39", 727 | "resolved": "https://registry.npmjs.org/postcss/-/postcss-8.4.39.tgz", 728 | "integrity": "sha512-0vzE+lAiG7hZl1/9I8yzKLx3aR9Xbof3fBHKunvMfOCYAtMhrsnccJY2iTURb9EZd5+pLuiNV9/c/GZJOHsgIw==", 729 | "funding": [ 730 | { 731 | "type": "opencollective", 732 | "url": "https://opencollective.com/postcss/" 733 | }, 734 | { 735 | "type": "tidelift", 736 | "url": "https://tidelift.com/funding/github/npm/postcss" 737 | }, 738 | { 739 | "type": "github", 740 | "url": "https://github.com/sponsors/ai" 741 | } 742 | ], 743 | "peer": true, 744 | "dependencies": { 745 | "nanoid": "^3.3.7", 746 | "picocolors": "^1.0.1", 747 | "source-map-js": "^1.2.0" 748 | }, 749 | "engines": { 750 | "node": "^10 || ^12 || >=14" 751 | } 752 | }, 753 | "node_modules/postcss/node_modules/nanoid": { 754 | "version": "3.3.7", 755 | "resolved": "https://registry.npmjs.org/nanoid/-/nanoid-3.3.7.tgz", 756 | "integrity": "sha512-eSRppjcPIatRIMC1U6UngP8XFcz8MQWGQdt1MTBQ7NaAmvXDfvNxbvWV3x2y6CdEUciCSsDHDQZbhYaB8QEo2g==", 757 | "funding": [ 758 | { 759 | "type": "github", 760 | "url": "https://github.com/sponsors/ai" 761 | } 762 | ], 763 | "peer": true, 764 | "bin": { 765 | "nanoid": "bin/nanoid.cjs" 766 | }, 767 | "engines": { 768 | "node": "^10 || ^12 || ^13.7 || ^14 || >=15.0.1" 769 | } 770 | }, 771 | "node_modules/react": { 772 | "version": "18.3.1", 773 | "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", 774 | "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", 775 | "peer": true, 776 | "dependencies": { 777 | "loose-envify": "^1.1.0" 778 | }, 779 | "engines": { 780 | "node": ">=0.10.0" 781 | } 782 | }, 783 | "node_modules/secure-json-parse": { 784 | "version": "2.7.0", 785 | "resolved": "https://registry.npmjs.org/secure-json-parse/-/secure-json-parse-2.7.0.tgz", 786 | "integrity": "sha512-6aU+Rwsezw7VR8/nyvKTx8QpWH9FrcYiXXlqC4z5d5XQBDRqtbfsRjnwGyqbi3gddNtWHuEk9OANUotL26qKUw==" 787 | }, 788 | "node_modules/source-map-js": { 789 | "version": "1.2.0", 790 | "resolved": "https://registry.npmjs.org/source-map-js/-/source-map-js-1.2.0.tgz", 791 | "integrity": "sha512-itJW8lvSA0TXEphiRoawsCksnlf8SyvmFzIhltqAHluXd88pkCd+cXJVHTDwdCr0IzwptSm035IHQktUu1QUMg==", 792 | "peer": true, 793 | "engines": { 794 | "node": ">=0.10.0" 795 | } 796 | }, 797 | "node_modules/sswr": { 798 | "version": "2.1.0", 799 | "resolved": "https://registry.npmjs.org/sswr/-/sswr-2.1.0.tgz", 800 | "integrity": "sha512-Cqc355SYlTAaUt8iDPaC/4DPPXK925PePLMxyBKuWd5kKc5mwsG3nT9+Mq2tyguL5s7b4Jg+IRMpTRsNTAfpSQ==", 801 | "dependencies": { 802 | "swrev": "^4.0.0" 803 | }, 804 | "peerDependencies": { 805 | "svelte": "^4.0.0 || ^5.0.0-next.0" 806 | } 807 | }, 808 | "node_modules/superjson": { 809 | "version": "2.2.1", 810 | "resolved": "https://registry.npmjs.org/superjson/-/superjson-2.2.1.tgz", 811 | "integrity": "sha512-8iGv75BYOa0xRJHK5vRLEjE2H/i4lulTjzpUXic3Eg8akftYjkmQDa8JARQ42rlczXyFR3IeRoeFCc7RxHsYZA==", 812 | "dependencies": { 813 | "copy-anything": "^3.0.2" 814 | }, 815 | "engines": { 816 | "node": ">=16" 817 | } 818 | }, 819 | "node_modules/svelte": { 820 | "version": "4.2.18", 821 | "resolved": "https://registry.npmjs.org/svelte/-/svelte-4.2.18.tgz", 822 | "integrity": "sha512-d0FdzYIiAePqRJEb90WlJDkjUEx42xhivxN8muUBmfZnP+tzUgz12DJ2hRJi8sIHCME7jeK1PTMgKPSfTd8JrA==", 823 | "peer": true, 824 | "dependencies": { 825 | "@ampproject/remapping": "^2.2.1", 826 | "@jridgewell/sourcemap-codec": "^1.4.15", 827 | "@jridgewell/trace-mapping": "^0.3.18", 828 | "@types/estree": "^1.0.1", 829 | "acorn": "^8.9.0", 830 | "aria-query": "^5.3.0", 831 | "axobject-query": "^4.0.0", 832 | "code-red": "^1.0.3", 833 | "css-tree": "^2.3.1", 834 | "estree-walker": "^3.0.3", 835 | "is-reference": "^3.0.1", 836 | "locate-character": "^3.0.0", 837 | "magic-string": "^0.30.4", 838 | "periscopic": "^3.1.0" 839 | }, 840 | "engines": { 841 | "node": ">=16" 842 | } 843 | }, 844 | "node_modules/swr": { 845 | "version": "2.2.5", 846 | "resolved": "https://registry.npmjs.org/swr/-/swr-2.2.5.tgz", 847 | "integrity": "sha512-QtxqyclFeAsxEUeZIYmsaQ0UjimSq1RZ9Un7I68/0ClKK/U3LoyQunwkQfJZr2fc22DfIXLNDc2wFyTEikCUpg==", 848 | "dependencies": { 849 | "client-only": "^0.0.1", 850 | "use-sync-external-store": "^1.2.0" 851 | }, 852 | "peerDependencies": { 853 | "react": "^16.11.0 || ^17.0.0 || ^18.0.0" 854 | } 855 | }, 856 | "node_modules/swrev": { 857 | "version": "4.0.0", 858 | "resolved": "https://registry.npmjs.org/swrev/-/swrev-4.0.0.tgz", 859 | "integrity": "sha512-LqVcOHSB4cPGgitD1riJ1Hh4vdmITOp+BkmfmXRh4hSF/t7EnS4iD+SOTmq7w5pPm/SiPeto4ADbKS6dHUDWFA==" 860 | }, 861 | "node_modules/swrv": { 862 | "version": "1.0.4", 863 | "resolved": "https://registry.npmjs.org/swrv/-/swrv-1.0.4.tgz", 864 | "integrity": "sha512-zjEkcP8Ywmj+xOJW3lIT65ciY/4AL4e/Or7Gj0MzU3zBJNMdJiT8geVZhINavnlHRMMCcJLHhraLTAiDOTmQ9g==", 865 | "peerDependencies": { 866 | "vue": ">=3.2.26 < 4" 867 | } 868 | }, 869 | "node_modules/typescript": { 870 | "version": "5.5.3", 871 | "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.5.3.tgz", 872 | "integrity": "sha512-/hreyEujaB0w76zKo6717l3L0o/qEUtRgdvUBvlkhoWeOVMjMuHNHk0BRBzikzuGDqNmPQbg5ifMEqsHLiIUcQ==", 873 | "optional": true, 874 | "peer": true, 875 | "bin": { 876 | "tsc": "bin/tsc", 877 | "tsserver": "bin/tsserver" 878 | }, 879 | "engines": { 880 | "node": ">=14.17" 881 | } 882 | }, 883 | "node_modules/undici-types": { 884 | "version": "5.26.5", 885 | "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-5.26.5.tgz", 886 | "integrity": "sha512-JlCMO+ehdEIKqlFxk6IfVoAUVmgz7cU7zD/h9XZ0qzeosSHmUJVOzSQvvYSYWXkFXC+IfLKSIffhv0sVZup6pA==", 887 | "dev": true 888 | }, 889 | "node_modules/use-sync-external-store": { 890 | "version": "1.2.2", 891 | "resolved": "https://registry.npmjs.org/use-sync-external-store/-/use-sync-external-store-1.2.2.tgz", 892 | "integrity": "sha512-PElTlVMwpblvbNqQ82d2n6RjStvdSoNe9FG28kNfz3WiXilJm4DdNkEzRhCZuIDwY8U08WVihhGR5iRqAwfDiw==", 893 | "peerDependencies": { 894 | "react": "^16.8.0 || ^17.0.0 || ^18.0.0" 895 | } 896 | }, 897 | "node_modules/vue": { 898 | "version": "3.4.33", 899 | "resolved": "https://registry.npmjs.org/vue/-/vue-3.4.33.tgz", 900 | "integrity": "sha512-VdMCWQOummbhctl4QFMcW6eNtXHsFyDlX60O/tsSQuCcuDOnJ1qPOhhVla65Niece7xq/P2zyZReIO5mP+LGTQ==", 901 | "peer": true, 902 | "dependencies": { 903 | "@vue/compiler-dom": "3.4.33", 904 | "@vue/compiler-sfc": "3.4.33", 905 | "@vue/runtime-dom": "3.4.33", 906 | "@vue/server-renderer": "3.4.33", 907 | "@vue/shared": "3.4.33" 908 | }, 909 | "peerDependencies": { 910 | "typescript": "*" 911 | }, 912 | "peerDependenciesMeta": { 913 | "typescript": { 914 | "optional": true 915 | } 916 | } 917 | }, 918 | "node_modules/zod": { 919 | "version": "3.23.8", 920 | "resolved": "https://registry.npmjs.org/zod/-/zod-3.23.8.tgz", 921 | "integrity": "sha512-XBx9AXhXktjUqnepgTiE5flcKIYWi/rme0Eaj+5Y0lftuGBq+jyRu/md4WnuxqgP1ubdpNCsYEYPxrzVHD8d6g==", 922 | "funding": { 923 | "url": "https://github.com/sponsors/colinhacks" 924 | } 925 | }, 926 | "node_modules/zod-to-json-schema": { 927 | "version": "3.23.1", 928 | "resolved": "https://registry.npmjs.org/zod-to-json-schema/-/zod-to-json-schema-3.23.1.tgz", 929 | "integrity": "sha512-oT9INvydob1XV0v1d2IadrR74rLtDInLvDFfAa1CG0Pmg/vxATk7I2gSelfj271mbzeM4Da0uuDQE/Nkj3DWNw==", 930 | "peerDependencies": { 931 | "zod": "^3.23.3" 932 | } 933 | } 934 | } 935 | } 936 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "name": "ai-fun", 4 | "version": "1.0.1", 5 | "description": "ai-fun is an experimental LLM-powered function library", 6 | "main": "src/index.ts", 7 | "repository": { 8 | "type": "git", 9 | "url": "git+https://github.com/mishushakov/ai-fun.git" 10 | }, 11 | "author": "Mish Ushakov ", 12 | "license": "MIT", 13 | "bugs": { 14 | "url": "https://github.com/mishushakov/ai-fun/issues" 15 | }, 16 | "homepage": "https://github.com/mishushakov/ai-fun#readme", 17 | "dependencies": { 18 | "ai": "^3.2.32", 19 | "superjson": "^2.2.1", 20 | "zod": "^3.23.8", 21 | "zod-to-json-schema": "^3.23.1" 22 | }, 23 | "devDependencies": { 24 | "@ai-sdk/anthropic": "^0.0.30", 25 | "@types/node": "^20.14.11" 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/backends/node.ts: -------------------------------------------------------------------------------- 1 | import vm from 'node:vm' 2 | import superjson from 'superjson' 3 | import { exec } from 'node:child_process' 4 | import path from 'node:path' 5 | import fs from 'fs/promises' 6 | import { AIFunctionBackend, CodeContent } from '../index.js' 7 | 8 | type NodeExecOptions = { 9 | debug?: boolean 10 | packageFile?: string 11 | installPackages?: boolean 12 | } 13 | 14 | async function installPackages( 15 | npmModules: string[], 16 | packageFile: string, 17 | debug: boolean 18 | ) { 19 | let packageJsonObject = { 20 | dependencies: {}, 21 | } 22 | 23 | const packageJsonDir = path.dirname(packageFile || '.') 24 | 25 | if (packageFile) { 26 | const packageJson = await fs.readFile(packageFile, 'utf-8') 27 | packageJsonObject = JSON.parse(packageJson) 28 | } 29 | 30 | for (const packageName of npmModules) { 31 | if (!packageJsonObject.dependencies[packageName]) { 32 | if (debug) console.log('installing package', packageName) 33 | exec( 34 | `npm install ${packageName}`, 35 | { cwd: packageJsonDir }, 36 | (err, stdout) => { 37 | if (err) throw err 38 | if (debug) console.log(stdout) 39 | } 40 | ) 41 | } 42 | } 43 | } 44 | 45 | global.require = require 46 | 47 | export default class NodeExec implements AIFunctionBackend { 48 | // private ctx: vm.Context 49 | constructor( 50 | private options: NodeExecOptions = { 51 | packageFile: 'package.json', 52 | installPackages: true, 53 | } 54 | ) { 55 | this.options = options 56 | } 57 | 58 | async init(codeContent: CodeContent) { 59 | if (codeContent.npmModules.length > 0 && this.options.installPackages) { 60 | await installPackages( 61 | codeContent.npmModules, 62 | this.options.packageFile, 63 | this.options.debug 64 | ) 65 | } 66 | 67 | // this.ctx = vm.createContext({ 68 | // require: require, 69 | // console: console, 70 | // }) 71 | 72 | vm.runInThisContext(codeContent.code.trim()) 73 | } 74 | 75 | async exec(params: any) { 76 | const serialized = superjson.serialize(params) 77 | if (this.options.debug) 78 | console.log('Running with parameters:', JSON.stringify(serialized.json)) 79 | return vm.runInThisContext(`f(${JSON.stringify(serialized.json)})`) 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { LanguageModelV1 } from '@ai-sdk/provider' 2 | import { generateObject } from 'ai' 3 | import { z } from 'zod' 4 | import { zodToJsonSchema } from 'zod-to-json-schema' 5 | import fs from 'fs/promises' 6 | 7 | type AIFunctionBuilderOptions = { 8 | debug?: boolean 9 | esModules?: boolean 10 | cache?: boolean 11 | cacheFile?: string 12 | } 13 | 14 | export type CodeContent = { 15 | code: string 16 | npmModules: string[] 17 | } 18 | 19 | type CacheContent = { 20 | [key: string]: CodeContent 21 | } 22 | 23 | async function generateCode( 24 | model: LanguageModelV1, 25 | description: string, 26 | parameters: z.ZodTypeAny, 27 | output: z.ZodTypeAny, 28 | options: AIFunctionBuilderOptions 29 | ) { 30 | const parametersSchema = zodToJsonSchema(parameters || z.null()) 31 | const outputSchema = zodToJsonSchema(output || z.null()) 32 | 33 | const systemSchema = z.object({ 34 | code: z.string(), 35 | npmModules: z.array(z.string().describe('only for list non built-in modules')), 36 | }) 37 | 38 | const { object } = await generateObject({ 39 | model: model, 40 | system: `Generate a Node.js function according to the given function signature. 41 | No comments, external packages are supported, use function syntax, no exports, syntax: "${ 42 | options.esModules ? 'import' : 'commonjs' 43 | }". Your can only respond with code.`, 44 | prompt: ` 45 | // ${description} 46 | f(params: ${JSON.stringify(parametersSchema)}): ${JSON.stringify( 47 | outputSchema 48 | )} 49 | `, 50 | schema: systemSchema, 51 | }) 52 | 53 | // mock 54 | // const object = { 55 | // code: `function f(params) { return params }`, 56 | // npmModules: ['pino'], 57 | // } 58 | 59 | return object 60 | } 61 | 62 | export abstract class AIFunctionBackend { 63 | abstract init(codeContent: CodeContent): Promise 64 | abstract exec(params: any): Promise 65 | } 66 | 67 | export default class AIFunctionBuilder { 68 | constructor( 69 | private model: LanguageModelV1, 70 | private backend: AIFunctionBackend, 71 | private options: AIFunctionBuilderOptions = { 72 | debug: false, 73 | esModules: false, 74 | cache: true, 75 | cacheFile: '.ai-fun.json', 76 | } 77 | ) { 78 | this.model = model 79 | this.options = options 80 | this.backend = backend 81 | } 82 | 83 | async function( 84 | description: string, 85 | parameters?: T, 86 | output?: O 87 | ) { 88 | let codeContent 89 | 90 | if (this.options.cache) { 91 | try { 92 | const cache = await fs.readFile(this.options.cacheFile, 'utf-8') 93 | const cacheObject = JSON.parse(cache) 94 | codeContent = cacheObject[description] 95 | } catch (e) { 96 | // console.log('cache not found') 97 | } 98 | } 99 | 100 | if (!codeContent) { 101 | codeContent = await generateCode( 102 | this.model, 103 | description, 104 | parameters, 105 | output, 106 | this.options 107 | ) 108 | 109 | if (this.options.cache) { 110 | let cacheObject = {} 111 | try { 112 | const cache = await fs.readFile(this.options.cacheFile, 'utf-8') 113 | cacheObject = JSON.parse(cache) 114 | } catch (e) { 115 | // console.log('cache file not found') 116 | } 117 | 118 | cacheObject[description] = codeContent 119 | await fs.writeFile(this.options.cacheFile, JSON.stringify(cacheObject)) 120 | } 121 | } 122 | 123 | if (this.options.debug === true) { 124 | console.log('code', codeContent.code) 125 | console.log('packages', codeContent.npmModules) 126 | } 127 | 128 | await this.backend.init(codeContent) 129 | 130 | return async (params?: z.infer): Promise> => { 131 | return this.backend.exec(params) 132 | } 133 | } 134 | } 135 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "dist", 4 | "declaration": true, 5 | "lib": ["ESNext", "DOM"], 6 | "module": "NodeNext", 7 | "target": "ESNext", 8 | "moduleResolution": "NodeNext" 9 | }, 10 | "include": ["src/**/*.ts"] 11 | } 12 | -------------------------------------------------------------------------------- /warning.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mishushakov/ai-fun/113cc066db391279280f11b79737a74a854b8d50/warning.png --------------------------------------------------------------------------------