├── .gitignore ├── README.md ├── cookie.txt ├── index.js ├── node_modules └── .package-lock.json ├── package-lock.json ├── package.json └── src ├── Bard.js ├── cookies.js └── main.js /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | node_modules/package-lock.json 3 | .npmignore 4 | package-lock.json 5 | ``` 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # wgpt 2 | 3 | ![npm](https://img.shields.io/npm/v/wgpt) ![npm](https://img.shields.io/npm/dt/wgpt) ![NPM](https://img.shields.io/npm/l/wgpt) 4 | 5 | `wgpt` is an npm package that allows you to interact with BardAI right from your terminal. With `wgpt`, you can easily send messages to the AI chat, get responses, and even perform rephrasing or add code snippets to your messages. It's a convenient tool for experimenting with AI and generating creative responses. 6 | 7 | ## Installation 8 | 9 | To install `wgpt`, make sure you have [Node.js](https://nodejs.org/) and [npm](https://www.npmjs.com/) installed on your system. Then, run the following command: 10 | 11 | ```bash 12 | npm install -g wgpt 13 | ``` 14 | 15 | The `-g` flag ensures that `wgpt` is installed globally on your system, making it accessible from any directory. 16 | 17 | 18 | ## Usage 19 | To get started with the CLI tool, you'll be asked to provide a cookie from `https://bard.google.com/`. First, log in to the website and copy the `value` of the `__Secure-1PSID` cookie, which you'll then use as your initial input. After this setup, the tool will operate normally, and you can interact with it directly from your terminal. Below are some usage examples: 20 | 21 | ```bash 22 | wgpt Hello, AI! 23 | ``` 24 | 25 | 26 | https://github.com/muhiris/wgpt/assets/80543033/117b5332-2c76-4692-9ad8-ee30f7fa5425 27 | 28 | 29 | 30 | 31 | 32 | 33 | ## Helping And Contributing 34 | 35 | Help `wgpt` by giving it stars on [GitHub repository](https://github.com/muhiris/wgpt). 36 | 37 | Also contributions to `wgpt` are welcome! If you find any issues or have ideas for improvements, feel free to open an issue or submit a pull request on the [GitHub repository](https://github.com/muhiris/wgpt). 38 | 39 | -------------------------------------------------------------------------------- /cookie.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/muhiris/wgpt/ded8d163b0ba662dbd1d39ccd6d51b462a0b0075/cookie.txt -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | import main from "./src/main.js"; 3 | 4 | main(); 5 | -------------------------------------------------------------------------------- /node_modules/.package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wgpt", 3 | "version": "1.1.8", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "node_modules/ansi-regex": { 8 | "version": "6.0.1", 9 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", 10 | "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", 11 | "engines": { 12 | "node": ">=12" 13 | }, 14 | "funding": { 15 | "url": "https://github.com/chalk/ansi-regex?sponsor=1" 16 | } 17 | }, 18 | "node_modules/base64-js": { 19 | "version": "1.5.1", 20 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", 21 | "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", 22 | "funding": [ 23 | { 24 | "type": "github", 25 | "url": "https://github.com/sponsors/feross" 26 | }, 27 | { 28 | "type": "patreon", 29 | "url": "https://www.patreon.com/feross" 30 | }, 31 | { 32 | "type": "consulting", 33 | "url": "https://feross.org/support" 34 | } 35 | ] 36 | }, 37 | "node_modules/bl": { 38 | "version": "5.1.0", 39 | "resolved": "https://registry.npmjs.org/bl/-/bl-5.1.0.tgz", 40 | "integrity": "sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==", 41 | "dependencies": { 42 | "buffer": "^6.0.3", 43 | "inherits": "^2.0.4", 44 | "readable-stream": "^3.4.0" 45 | } 46 | }, 47 | "node_modules/buffer": { 48 | "version": "6.0.3", 49 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", 50 | "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", 51 | "funding": [ 52 | { 53 | "type": "github", 54 | "url": "https://github.com/sponsors/feross" 55 | }, 56 | { 57 | "type": "patreon", 58 | "url": "https://www.patreon.com/feross" 59 | }, 60 | { 61 | "type": "consulting", 62 | "url": "https://feross.org/support" 63 | } 64 | ], 65 | "dependencies": { 66 | "base64-js": "^1.3.1", 67 | "ieee754": "^1.2.1" 68 | } 69 | }, 70 | "node_modules/chalk": { 71 | "version": "5.3.0", 72 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", 73 | "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", 74 | "engines": { 75 | "node": "^12.17.0 || ^14.13 || >=16.0.0" 76 | }, 77 | "funding": { 78 | "url": "https://github.com/chalk/chalk?sponsor=1" 79 | } 80 | }, 81 | "node_modules/cli-cursor": { 82 | "version": "4.0.0", 83 | "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", 84 | "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", 85 | "dependencies": { 86 | "restore-cursor": "^4.0.0" 87 | }, 88 | "engines": { 89 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 90 | }, 91 | "funding": { 92 | "url": "https://github.com/sponsors/sindresorhus" 93 | } 94 | }, 95 | "node_modules/cli-spinners": { 96 | "version": "2.9.0", 97 | "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.0.tgz", 98 | "integrity": "sha512-4/aL9X3Wh0yiMQlE+eeRhWP6vclO3QRtw1JHKIT0FFUs5FjpFmESqtMvYZ0+lbzBw900b95mS0hohy+qn2VK/g==", 99 | "engines": { 100 | "node": ">=6" 101 | }, 102 | "funding": { 103 | "url": "https://github.com/sponsors/sindresorhus" 104 | } 105 | }, 106 | "node_modules/eastasianwidth": { 107 | "version": "0.2.0", 108 | "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", 109 | "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" 110 | }, 111 | "node_modules/emoji-regex": { 112 | "version": "10.2.1", 113 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.2.1.tgz", 114 | "integrity": "sha512-97g6QgOk8zlDRdgq1WxwgTMgEWGVAQvB5Fdpgc1MkNy56la5SKP9GsMXKDOdqwn90/41a8yPwIGk1Y6WVbeMQA==" 115 | }, 116 | "node_modules/ieee754": { 117 | "version": "1.2.1", 118 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", 119 | "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", 120 | "funding": [ 121 | { 122 | "type": "github", 123 | "url": "https://github.com/sponsors/feross" 124 | }, 125 | { 126 | "type": "patreon", 127 | "url": "https://www.patreon.com/feross" 128 | }, 129 | { 130 | "type": "consulting", 131 | "url": "https://feross.org/support" 132 | } 133 | ] 134 | }, 135 | "node_modules/inherits": { 136 | "version": "2.0.4", 137 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 138 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 139 | }, 140 | "node_modules/is-interactive": { 141 | "version": "2.0.0", 142 | "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", 143 | "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", 144 | "engines": { 145 | "node": ">=12" 146 | }, 147 | "funding": { 148 | "url": "https://github.com/sponsors/sindresorhus" 149 | } 150 | }, 151 | "node_modules/is-unicode-supported": { 152 | "version": "1.3.0", 153 | "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", 154 | "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", 155 | "engines": { 156 | "node": ">=12" 157 | }, 158 | "funding": { 159 | "url": "https://github.com/sponsors/sindresorhus" 160 | } 161 | }, 162 | "node_modules/log-symbols": { 163 | "version": "5.1.0", 164 | "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-5.1.0.tgz", 165 | "integrity": "sha512-l0x2DvrW294C9uDCoQe1VSU4gf529FkSZ6leBl4TiqZH/e+0R7hSfHQBNut2mNygDgHwvYHfFLn6Oxb3VWj2rA==", 166 | "dependencies": { 167 | "chalk": "^5.0.0", 168 | "is-unicode-supported": "^1.1.0" 169 | }, 170 | "engines": { 171 | "node": ">=12" 172 | }, 173 | "funding": { 174 | "url": "https://github.com/sponsors/sindresorhus" 175 | } 176 | }, 177 | "node_modules/mimic-fn": { 178 | "version": "2.1.0", 179 | "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", 180 | "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", 181 | "engines": { 182 | "node": ">=6" 183 | } 184 | }, 185 | "node_modules/onetime": { 186 | "version": "5.1.2", 187 | "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", 188 | "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", 189 | "dependencies": { 190 | "mimic-fn": "^2.1.0" 191 | }, 192 | "engines": { 193 | "node": ">=6" 194 | }, 195 | "funding": { 196 | "url": "https://github.com/sponsors/sindresorhus" 197 | } 198 | }, 199 | "node_modules/ora": { 200 | "version": "7.0.1", 201 | "resolved": "https://registry.npmjs.org/ora/-/ora-7.0.1.tgz", 202 | "integrity": "sha512-0TUxTiFJWv+JnjWm4o9yvuskpEJLXTcng8MJuKd+SzAzp2o+OP3HWqNhB4OdJRt1Vsd9/mR0oyaEYlOnL7XIRw==", 203 | "dependencies": { 204 | "chalk": "^5.3.0", 205 | "cli-cursor": "^4.0.0", 206 | "cli-spinners": "^2.9.0", 207 | "is-interactive": "^2.0.0", 208 | "is-unicode-supported": "^1.3.0", 209 | "log-symbols": "^5.1.0", 210 | "stdin-discarder": "^0.1.0", 211 | "string-width": "^6.1.0", 212 | "strip-ansi": "^7.1.0" 213 | }, 214 | "engines": { 215 | "node": ">=16" 216 | }, 217 | "funding": { 218 | "url": "https://github.com/sponsors/sindresorhus" 219 | } 220 | }, 221 | "node_modules/readable-stream": { 222 | "version": "3.6.2", 223 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", 224 | "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", 225 | "dependencies": { 226 | "inherits": "^2.0.3", 227 | "string_decoder": "^1.1.1", 228 | "util-deprecate": "^1.0.1" 229 | }, 230 | "engines": { 231 | "node": ">= 6" 232 | } 233 | }, 234 | "node_modules/restore-cursor": { 235 | "version": "4.0.0", 236 | "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", 237 | "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", 238 | "dependencies": { 239 | "onetime": "^5.1.0", 240 | "signal-exit": "^3.0.2" 241 | }, 242 | "engines": { 243 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 244 | }, 245 | "funding": { 246 | "url": "https://github.com/sponsors/sindresorhus" 247 | } 248 | }, 249 | "node_modules/safe-buffer": { 250 | "version": "5.2.1", 251 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 252 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", 253 | "funding": [ 254 | { 255 | "type": "github", 256 | "url": "https://github.com/sponsors/feross" 257 | }, 258 | { 259 | "type": "patreon", 260 | "url": "https://www.patreon.com/feross" 261 | }, 262 | { 263 | "type": "consulting", 264 | "url": "https://feross.org/support" 265 | } 266 | ] 267 | }, 268 | "node_modules/signal-exit": { 269 | "version": "3.0.7", 270 | "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", 271 | "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" 272 | }, 273 | "node_modules/stdin-discarder": { 274 | "version": "0.1.0", 275 | "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.1.0.tgz", 276 | "integrity": "sha512-xhV7w8S+bUwlPTb4bAOUQhv8/cSS5offJuX8GQGq32ONF0ZtDWKfkdomM3HMRA+LhX6um/FZ0COqlwsjD53LeQ==", 277 | "dependencies": { 278 | "bl": "^5.0.0" 279 | }, 280 | "engines": { 281 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 282 | }, 283 | "funding": { 284 | "url": "https://github.com/sponsors/sindresorhus" 285 | } 286 | }, 287 | "node_modules/string_decoder": { 288 | "version": "1.3.0", 289 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", 290 | "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", 291 | "dependencies": { 292 | "safe-buffer": "~5.2.0" 293 | } 294 | }, 295 | "node_modules/string-width": { 296 | "version": "6.1.0", 297 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-6.1.0.tgz", 298 | "integrity": "sha512-k01swCJAgQmuADB0YIc+7TuatfNvTBVOoaUWJjTB9R4VJzR5vNWzf5t42ESVZFPS8xTySF7CAdV4t/aaIm3UnQ==", 299 | "dependencies": { 300 | "eastasianwidth": "^0.2.0", 301 | "emoji-regex": "^10.2.1", 302 | "strip-ansi": "^7.0.1" 303 | }, 304 | "engines": { 305 | "node": ">=16" 306 | }, 307 | "funding": { 308 | "url": "https://github.com/sponsors/sindresorhus" 309 | } 310 | }, 311 | "node_modules/strip-ansi": { 312 | "version": "7.1.0", 313 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", 314 | "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", 315 | "dependencies": { 316 | "ansi-regex": "^6.0.1" 317 | }, 318 | "engines": { 319 | "node": ">=12" 320 | }, 321 | "funding": { 322 | "url": "https://github.com/chalk/strip-ansi?sponsor=1" 323 | } 324 | }, 325 | "node_modules/util-deprecate": { 326 | "version": "1.0.2", 327 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 328 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" 329 | } 330 | } 331 | } 332 | -------------------------------------------------------------------------------- /package-lock.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wgpt", 3 | "version": "1.1.8", 4 | "lockfileVersion": 3, 5 | "requires": true, 6 | "packages": { 7 | "": { 8 | "name": "wgpt", 9 | "version": "1.1.8", 10 | "license": "ISC", 11 | "dependencies": { 12 | "ora": "^7.0.1" 13 | }, 14 | "bin": { 15 | "wgpt": "index.js" 16 | } 17 | }, 18 | "node_modules/ansi-regex": { 19 | "version": "6.0.1", 20 | "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-6.0.1.tgz", 21 | "integrity": "sha512-n5M855fKb2SsfMIiFFoVrABHJC8QtHwVx+mHWP3QcEqBHYienj5dHSgjbxtC0WEZXYt4wcD6zrQElDPhFuZgfA==", 22 | "engines": { 23 | "node": ">=12" 24 | }, 25 | "funding": { 26 | "url": "https://github.com/chalk/ansi-regex?sponsor=1" 27 | } 28 | }, 29 | "node_modules/base64-js": { 30 | "version": "1.5.1", 31 | "resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz", 32 | "integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==", 33 | "funding": [ 34 | { 35 | "type": "github", 36 | "url": "https://github.com/sponsors/feross" 37 | }, 38 | { 39 | "type": "patreon", 40 | "url": "https://www.patreon.com/feross" 41 | }, 42 | { 43 | "type": "consulting", 44 | "url": "https://feross.org/support" 45 | } 46 | ] 47 | }, 48 | "node_modules/bl": { 49 | "version": "5.1.0", 50 | "resolved": "https://registry.npmjs.org/bl/-/bl-5.1.0.tgz", 51 | "integrity": "sha512-tv1ZJHLfTDnXE6tMHv73YgSJaWR2AFuPwMntBe7XL/GBFHnT0CLnsHMogfk5+GzCDC5ZWarSCYaIGATZt9dNsQ==", 52 | "dependencies": { 53 | "buffer": "^6.0.3", 54 | "inherits": "^2.0.4", 55 | "readable-stream": "^3.4.0" 56 | } 57 | }, 58 | "node_modules/buffer": { 59 | "version": "6.0.3", 60 | "resolved": "https://registry.npmjs.org/buffer/-/buffer-6.0.3.tgz", 61 | "integrity": "sha512-FTiCpNxtwiZZHEZbcbTIcZjERVICn9yq/pDFkTl95/AxzD1naBctN7YO68riM/gLSDY7sdrMby8hofADYuuqOA==", 62 | "funding": [ 63 | { 64 | "type": "github", 65 | "url": "https://github.com/sponsors/feross" 66 | }, 67 | { 68 | "type": "patreon", 69 | "url": "https://www.patreon.com/feross" 70 | }, 71 | { 72 | "type": "consulting", 73 | "url": "https://feross.org/support" 74 | } 75 | ], 76 | "dependencies": { 77 | "base64-js": "^1.3.1", 78 | "ieee754": "^1.2.1" 79 | } 80 | }, 81 | "node_modules/chalk": { 82 | "version": "5.3.0", 83 | "resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz", 84 | "integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==", 85 | "engines": { 86 | "node": "^12.17.0 || ^14.13 || >=16.0.0" 87 | }, 88 | "funding": { 89 | "url": "https://github.com/chalk/chalk?sponsor=1" 90 | } 91 | }, 92 | "node_modules/cli-cursor": { 93 | "version": "4.0.0", 94 | "resolved": "https://registry.npmjs.org/cli-cursor/-/cli-cursor-4.0.0.tgz", 95 | "integrity": "sha512-VGtlMu3x/4DOtIUwEkRezxUZ2lBacNJCHash0N0WeZDBS+7Ux1dm3XWAgWYxLJFMMdOeXMHXorshEFhbMSGelg==", 96 | "dependencies": { 97 | "restore-cursor": "^4.0.0" 98 | }, 99 | "engines": { 100 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 101 | }, 102 | "funding": { 103 | "url": "https://github.com/sponsors/sindresorhus" 104 | } 105 | }, 106 | "node_modules/cli-spinners": { 107 | "version": "2.9.0", 108 | "resolved": "https://registry.npmjs.org/cli-spinners/-/cli-spinners-2.9.0.tgz", 109 | "integrity": "sha512-4/aL9X3Wh0yiMQlE+eeRhWP6vclO3QRtw1JHKIT0FFUs5FjpFmESqtMvYZ0+lbzBw900b95mS0hohy+qn2VK/g==", 110 | "engines": { 111 | "node": ">=6" 112 | }, 113 | "funding": { 114 | "url": "https://github.com/sponsors/sindresorhus" 115 | } 116 | }, 117 | "node_modules/eastasianwidth": { 118 | "version": "0.2.0", 119 | "resolved": "https://registry.npmjs.org/eastasianwidth/-/eastasianwidth-0.2.0.tgz", 120 | "integrity": "sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==" 121 | }, 122 | "node_modules/emoji-regex": { 123 | "version": "10.2.1", 124 | "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.2.1.tgz", 125 | "integrity": "sha512-97g6QgOk8zlDRdgq1WxwgTMgEWGVAQvB5Fdpgc1MkNy56la5SKP9GsMXKDOdqwn90/41a8yPwIGk1Y6WVbeMQA==" 126 | }, 127 | "node_modules/ieee754": { 128 | "version": "1.2.1", 129 | "resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz", 130 | "integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA==", 131 | "funding": [ 132 | { 133 | "type": "github", 134 | "url": "https://github.com/sponsors/feross" 135 | }, 136 | { 137 | "type": "patreon", 138 | "url": "https://www.patreon.com/feross" 139 | }, 140 | { 141 | "type": "consulting", 142 | "url": "https://feross.org/support" 143 | } 144 | ] 145 | }, 146 | "node_modules/inherits": { 147 | "version": "2.0.4", 148 | "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", 149 | "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" 150 | }, 151 | "node_modules/is-interactive": { 152 | "version": "2.0.0", 153 | "resolved": "https://registry.npmjs.org/is-interactive/-/is-interactive-2.0.0.tgz", 154 | "integrity": "sha512-qP1vozQRI+BMOPcjFzrjXuQvdak2pHNUMZoeG2eRbiSqyvbEf/wQtEOTOX1guk6E3t36RkaqiSt8A/6YElNxLQ==", 155 | "engines": { 156 | "node": ">=12" 157 | }, 158 | "funding": { 159 | "url": "https://github.com/sponsors/sindresorhus" 160 | } 161 | }, 162 | "node_modules/is-unicode-supported": { 163 | "version": "1.3.0", 164 | "resolved": "https://registry.npmjs.org/is-unicode-supported/-/is-unicode-supported-1.3.0.tgz", 165 | "integrity": "sha512-43r2mRvz+8JRIKnWJ+3j8JtjRKZ6GmjzfaE/qiBJnikNnYv/6bagRJ1kUhNk8R5EX/GkobD+r+sfxCPJsiKBLQ==", 166 | "engines": { 167 | "node": ">=12" 168 | }, 169 | "funding": { 170 | "url": "https://github.com/sponsors/sindresorhus" 171 | } 172 | }, 173 | "node_modules/log-symbols": { 174 | "version": "5.1.0", 175 | "resolved": "https://registry.npmjs.org/log-symbols/-/log-symbols-5.1.0.tgz", 176 | "integrity": "sha512-l0x2DvrW294C9uDCoQe1VSU4gf529FkSZ6leBl4TiqZH/e+0R7hSfHQBNut2mNygDgHwvYHfFLn6Oxb3VWj2rA==", 177 | "dependencies": { 178 | "chalk": "^5.0.0", 179 | "is-unicode-supported": "^1.1.0" 180 | }, 181 | "engines": { 182 | "node": ">=12" 183 | }, 184 | "funding": { 185 | "url": "https://github.com/sponsors/sindresorhus" 186 | } 187 | }, 188 | "node_modules/mimic-fn": { 189 | "version": "2.1.0", 190 | "resolved": "https://registry.npmjs.org/mimic-fn/-/mimic-fn-2.1.0.tgz", 191 | "integrity": "sha512-OqbOk5oEQeAZ8WXWydlu9HJjz9WVdEIvamMCcXmuqUYjTknH/sqsWvhQ3vgwKFRR1HpjvNBKQ37nbJgYzGqGcg==", 192 | "engines": { 193 | "node": ">=6" 194 | } 195 | }, 196 | "node_modules/onetime": { 197 | "version": "5.1.2", 198 | "resolved": "https://registry.npmjs.org/onetime/-/onetime-5.1.2.tgz", 199 | "integrity": "sha512-kbpaSSGJTWdAY5KPVeMOKXSrPtr8C8C7wodJbcsd51jRnmD+GZu8Y0VoU6Dm5Z4vWr0Ig/1NKuWRKf7j5aaYSg==", 200 | "dependencies": { 201 | "mimic-fn": "^2.1.0" 202 | }, 203 | "engines": { 204 | "node": ">=6" 205 | }, 206 | "funding": { 207 | "url": "https://github.com/sponsors/sindresorhus" 208 | } 209 | }, 210 | "node_modules/ora": { 211 | "version": "7.0.1", 212 | "resolved": "https://registry.npmjs.org/ora/-/ora-7.0.1.tgz", 213 | "integrity": "sha512-0TUxTiFJWv+JnjWm4o9yvuskpEJLXTcng8MJuKd+SzAzp2o+OP3HWqNhB4OdJRt1Vsd9/mR0oyaEYlOnL7XIRw==", 214 | "dependencies": { 215 | "chalk": "^5.3.0", 216 | "cli-cursor": "^4.0.0", 217 | "cli-spinners": "^2.9.0", 218 | "is-interactive": "^2.0.0", 219 | "is-unicode-supported": "^1.3.0", 220 | "log-symbols": "^5.1.0", 221 | "stdin-discarder": "^0.1.0", 222 | "string-width": "^6.1.0", 223 | "strip-ansi": "^7.1.0" 224 | }, 225 | "engines": { 226 | "node": ">=16" 227 | }, 228 | "funding": { 229 | "url": "https://github.com/sponsors/sindresorhus" 230 | } 231 | }, 232 | "node_modules/readable-stream": { 233 | "version": "3.6.2", 234 | "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", 235 | "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", 236 | "dependencies": { 237 | "inherits": "^2.0.3", 238 | "string_decoder": "^1.1.1", 239 | "util-deprecate": "^1.0.1" 240 | }, 241 | "engines": { 242 | "node": ">= 6" 243 | } 244 | }, 245 | "node_modules/restore-cursor": { 246 | "version": "4.0.0", 247 | "resolved": "https://registry.npmjs.org/restore-cursor/-/restore-cursor-4.0.0.tgz", 248 | "integrity": "sha512-I9fPXU9geO9bHOt9pHHOhOkYerIMsmVaWB0rA2AI9ERh/+x/i7MV5HKBNrg+ljO5eoPVgCcnFuRjJ9uH6I/3eg==", 249 | "dependencies": { 250 | "onetime": "^5.1.0", 251 | "signal-exit": "^3.0.2" 252 | }, 253 | "engines": { 254 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 255 | }, 256 | "funding": { 257 | "url": "https://github.com/sponsors/sindresorhus" 258 | } 259 | }, 260 | "node_modules/safe-buffer": { 261 | "version": "5.2.1", 262 | "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", 263 | "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", 264 | "funding": [ 265 | { 266 | "type": "github", 267 | "url": "https://github.com/sponsors/feross" 268 | }, 269 | { 270 | "type": "patreon", 271 | "url": "https://www.patreon.com/feross" 272 | }, 273 | { 274 | "type": "consulting", 275 | "url": "https://feross.org/support" 276 | } 277 | ] 278 | }, 279 | "node_modules/signal-exit": { 280 | "version": "3.0.7", 281 | "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", 282 | "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" 283 | }, 284 | "node_modules/stdin-discarder": { 285 | "version": "0.1.0", 286 | "resolved": "https://registry.npmjs.org/stdin-discarder/-/stdin-discarder-0.1.0.tgz", 287 | "integrity": "sha512-xhV7w8S+bUwlPTb4bAOUQhv8/cSS5offJuX8GQGq32ONF0ZtDWKfkdomM3HMRA+LhX6um/FZ0COqlwsjD53LeQ==", 288 | "dependencies": { 289 | "bl": "^5.0.0" 290 | }, 291 | "engines": { 292 | "node": "^12.20.0 || ^14.13.1 || >=16.0.0" 293 | }, 294 | "funding": { 295 | "url": "https://github.com/sponsors/sindresorhus" 296 | } 297 | }, 298 | "node_modules/string_decoder": { 299 | "version": "1.3.0", 300 | "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", 301 | "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", 302 | "dependencies": { 303 | "safe-buffer": "~5.2.0" 304 | } 305 | }, 306 | "node_modules/string-width": { 307 | "version": "6.1.0", 308 | "resolved": "https://registry.npmjs.org/string-width/-/string-width-6.1.0.tgz", 309 | "integrity": "sha512-k01swCJAgQmuADB0YIc+7TuatfNvTBVOoaUWJjTB9R4VJzR5vNWzf5t42ESVZFPS8xTySF7CAdV4t/aaIm3UnQ==", 310 | "dependencies": { 311 | "eastasianwidth": "^0.2.0", 312 | "emoji-regex": "^10.2.1", 313 | "strip-ansi": "^7.0.1" 314 | }, 315 | "engines": { 316 | "node": ">=16" 317 | }, 318 | "funding": { 319 | "url": "https://github.com/sponsors/sindresorhus" 320 | } 321 | }, 322 | "node_modules/strip-ansi": { 323 | "version": "7.1.0", 324 | "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-7.1.0.tgz", 325 | "integrity": "sha512-iq6eVVI64nQQTRYq2KtEg2d2uU7LElhTJwsH4YzIHZshxlgZms/wIc4VoDQTlG/IvVIrBKG06CrZnp0qv7hkcQ==", 326 | "dependencies": { 327 | "ansi-regex": "^6.0.1" 328 | }, 329 | "engines": { 330 | "node": ">=12" 331 | }, 332 | "funding": { 333 | "url": "https://github.com/chalk/strip-ansi?sponsor=1" 334 | } 335 | }, 336 | "node_modules/util-deprecate": { 337 | "version": "1.0.2", 338 | "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", 339 | "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" 340 | } 341 | } 342 | } 343 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "wgpt", 3 | "version": "1.1.8", 4 | "type": "module", 5 | "description": "A simple CLI Application for chatgpt without API key", 6 | "main": "index.js", 7 | "author": { 8 | "name": "Muhammad Haris", 9 | "email": "muhammadharis786@protonmail.com", 10 | "url": "https://github.com/muhiris" 11 | }, 12 | "bin": { 13 | "wgpt": "./index.js" 14 | }, 15 | "scripts": { 16 | "test": "echo \"Error: no test specified\" && exit 1" 17 | }, 18 | "keywords": [ 19 | "chatgpt", 20 | "chat", 21 | "gpt", 22 | "gpt3", 23 | "openai", 24 | "ai", 25 | "artificial intelligence", 26 | "chatbot", 27 | "chatbots", 28 | "chatbot api", 29 | "chatbot api free", 30 | "chatbot api without api key", 31 | "chatbot api without api key free", 32 | "chatbot api free without api key" 33 | ], 34 | "license": "ISC", 35 | "dependencies": { 36 | "ora": "^7.0.1" 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/Bard.js: -------------------------------------------------------------------------------- 1 | class Bard { 2 | static JSON = "json"; 3 | static MD = "markdown"; 4 | 5 | // ID derived from Cookie 6 | SNlM0e; 7 | 8 | // HTTPS Headers 9 | #headers; 10 | 11 | // Resolution status of initialization call 12 | #initPromise; 13 | 14 | #bardURL = "https://bard.google.com"; 15 | 16 | // Wether or not to log events to console 17 | #verbose = false; 18 | 19 | // Fetch function 20 | #fetch = fetch; 21 | 22 | constructor(cookie, config) { 23 | // Register some settings 24 | if (config?.verbose == true) this.#verbose = true; 25 | if (config?.fetch) this.#fetch = config.fetch; 26 | 27 | // If a Cookie is provided, initialize 28 | if (cookie) { 29 | this.#initPromise = this.#init(cookie); 30 | } else { 31 | throw new Error("Please provide a Cookie when initializing Bard."); 32 | } 33 | this.cookie = cookie; 34 | } 35 | 36 | // You can also choose to initialize manually 37 | async #init(cookie) { 38 | this.#verbose && console.log("🚀 Starting intialization"); 39 | 40 | // Assign headers 41 | this.#headers = { 42 | Host: "bard.google.com", 43 | "X-Same-Domain": "1", 44 | "User-Agent": 45 | "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36", 46 | "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8", 47 | Origin: this.#bardURL, 48 | Referer: this.#bardURL, 49 | Cookie: (typeof cookie === "object") ? (Object.entries(cookie).map(([key, val]) => `${key}=${val};`).join("")) : ("__Secure-1PSID=" + cookie), 50 | }; 51 | 52 | let responseText; 53 | // Attempt to retrieve SNlM0e 54 | try { 55 | this.#verbose && 56 | console.log("🔒 Authenticating your Google account"); 57 | responseText = await this.#fetch(this.#bardURL, { 58 | method: "GET", 59 | headers: this.#headers, 60 | credentials: "include", 61 | }) 62 | .then((response) => response.text()) 63 | } catch (e) { 64 | // Failure to get server 65 | throw new Error( 66 | "Could not fetch Google Bard. You may be disconnected from internet: " + 67 | e 68 | ); 69 | } 70 | 71 | try { 72 | const SNlM0e = responseText.match(/SNlM0e":"(.*?)"/)[1]; 73 | // Assign SNlM0e and return it 74 | this.SNlM0e = SNlM0e; 75 | this.#verbose && console.log("✅ Initialization finished\n"); 76 | return SNlM0e; 77 | } catch { 78 | throw new Error( 79 | "Could not use your Cookie. Make sure that you copied correctly the Cookie with name __Secure-1PSID exactly. If you are sure your cookie is correct, you may also have reached your rate limit." 80 | ); 81 | } 82 | } 83 | 84 | async #uploadImage(name, buffer) { 85 | this.#verbose && console.log("🖼️ Starting image processing"); 86 | let size = buffer.byteLength; 87 | let formBody = [ 88 | `${encodeURIComponent("File name")}=${encodeURIComponent([name])}`, 89 | ]; 90 | 91 | try { 92 | this.#verbose && 93 | console.log("💻 Finding Google server destination"); 94 | let response = await this.#fetch( 95 | "https://content-push.googleapis.com/upload/", 96 | { 97 | method: "POST", 98 | headers: { 99 | "X-Goog-Upload-Command": "start", 100 | "X-Goog-Upload-Protocol": "resumable", 101 | "X-Goog-Upload-Header-Content-Length": size, 102 | "X-Tenant-Id": "bard-storage", 103 | "Push-Id": "feeds/mcudyrk2a4khkz", 104 | }, 105 | body: formBody, 106 | credentials: "include", 107 | } 108 | ); 109 | 110 | const uploadUrl = response.headers.get("X-Goog-Upload-URL"); 111 | this.#verbose && console.log("📤 Sending your image"); 112 | response = await this.#fetch(uploadUrl, { 113 | method: "POST", 114 | headers: { 115 | "X-Goog-Upload-Command": "upload, finalize", 116 | "X-Goog-Upload-Offset": 0, 117 | "X-Tenant-Id": "bard-storage", 118 | }, 119 | body: buffer, 120 | credentials: "include", 121 | }); 122 | 123 | const imageFileLocation = await response.text(); 124 | 125 | this.#verbose && console.log("✅ Image finished working\n"); 126 | return imageFileLocation; 127 | } catch (e) { 128 | throw new Error( 129 | "Could not fetch Google Bard. You may be disconnected from internet: " + 130 | e 131 | ); 132 | } 133 | } 134 | 135 | // Query Bard 136 | async #query(message, config) { 137 | let formatMarkdown = (text, images) => { 138 | if (!images) return text; 139 | 140 | for (let imageData of images) { 141 | const formattedTag = `!${imageData.tag}(${imageData.url})`; 142 | text = text.replace( 143 | new RegExp(`(?!\\!)\\[${imageData.tag.slice(1, -1)}\\]`), 144 | formattedTag 145 | ); 146 | } 147 | 148 | return text; 149 | } 150 | 151 | let { ids, imageBuffer } = config; 152 | 153 | // Wait until after init 154 | await this.#initPromise; 155 | 156 | this.#verbose && console.log("🔎 Starting Bard Query"); 157 | 158 | // If user has not run init 159 | if (!this.SNlM0e) { 160 | throw new Error( 161 | "Please initialize Bard first. If you haven't passed in your Cookie into the class, run Bard.init(cookie)." 162 | ); 163 | } 164 | 165 | this.#verbose && console.log("🏗️ Building Request"); 166 | // HTTPS parameters 167 | const params = { 168 | bl: "boq_assistant-bard-web-server_20230711.08_p0", 169 | _reqID: ids?._reqID ?? "0", 170 | rt: "c", 171 | }; 172 | 173 | // If IDs are provided, but doesn't have every one of the expected IDs, error 174 | const messageStruct = [ 175 | [message], 176 | null, 177 | [null, null, null], 178 | ]; 179 | 180 | if (imageBuffer) { 181 | let imageLocation = await this.#uploadImage( 182 | `bard-ai_upload`, 183 | imageBuffer 184 | ); 185 | messageStruct[0].push(0, null, [ 186 | [[imageLocation, 1], "bard-ai_upload"], 187 | ]); 188 | } 189 | 190 | if (ids) { 191 | const { conversationID, responseID, choiceID } = ids; 192 | messageStruct[2] = [conversationID, responseID, choiceID]; 193 | } 194 | 195 | // HTTPs data 196 | const data = { 197 | "f.req": JSON.stringify([null, JSON.stringify(messageStruct)]), 198 | at: this.SNlM0e, 199 | }; 200 | 201 | // URL that we are submitting to 202 | const url = new URL( 203 | "/_/BardChatUi/data/assistant.lamda.BardFrontendService/StreamGenerate", 204 | this.#bardURL 205 | ); 206 | 207 | // Append parameters to the URL 208 | for (const key in params) { 209 | url.searchParams.append(key, params[key]); 210 | } 211 | 212 | // Encode the data 213 | const formBody = Object.entries(data) 214 | .map( 215 | ([property, value]) => 216 | `${encodeURIComponent(property)}=${encodeURIComponent( 217 | value 218 | )}` 219 | ) 220 | .join("&"); 221 | 222 | this.#verbose && console.log("💭 Sending message to Bard"); 223 | // Send the fetch request 224 | const chatData = await this.#fetch(url.toString(), { 225 | method: "POST", 226 | headers: this.#headers, 227 | body: formBody, 228 | credentials: "include", 229 | }) 230 | .then((response) => { 231 | return response.text(); 232 | }) 233 | .then((text) => { 234 | return JSON.parse(text.split("\n")[3])[0][2]; 235 | }) 236 | .then((rawData) => JSON.parse(rawData)); 237 | 238 | this.#verbose && console.log("🧩 Parsing output"); 239 | // Get first Bard-recommended answer 240 | const answer = chatData[4][0]; 241 | 242 | // Text of that answer 243 | const text = answer[1][0]; 244 | 245 | // Get data about images in that answer 246 | const images = 247 | answer[4]?.map((x) => ({ 248 | tag: x[2], 249 | url: x[3][0][0], 250 | info: { 251 | raw: x[0][0][0], 252 | source: x[1][0][0], 253 | alt: x[0][4], 254 | website: x[1][1], 255 | favicon: x[1][3], 256 | }, 257 | })) ?? []; 258 | 259 | this.#verbose && console.log("✅ All done!\n"); 260 | // Put everything together and return 261 | return { 262 | content: formatMarkdown(text, images), 263 | images: images, 264 | ids: { 265 | conversationID: chatData[1][0], 266 | responseID: chatData[1][1], 267 | choiceID: answer[0], 268 | _reqID: String(parseInt(ids?._reqID ?? 0) + 100000), 269 | }, 270 | }; 271 | } 272 | 273 | async #parseConfig(config) { 274 | let result = { 275 | useJSON: false, 276 | imageBuffer: undefined, // Returns as {extension, filename} 277 | ids: undefined, 278 | }; 279 | 280 | // Verify that format is one of the two types 281 | if (config?.format) { 282 | switch (config.format) { 283 | case Bard.JSON: 284 | result.useJSON = true; 285 | break; 286 | case Bard.MD: 287 | result.useJSON = false; 288 | break; 289 | default: 290 | throw new Error( 291 | "Format can obly be Bard.JSON for JSON output or Bard.MD for Markdown output." 292 | ); 293 | } 294 | } 295 | 296 | // Verify that the image passed in is either a path to a jpeg, jpg, png, or webp, or that it is a Buffer 297 | if (config?.image) { 298 | if ( 299 | config.image instanceof ArrayBuffer 300 | ) { 301 | result.imageBuffer = config.image; 302 | } else if ( 303 | typeof config.image === "string" && 304 | /\.(jpeg|jpg|png|webp)$/.test(config.image) 305 | ) { 306 | let fs; 307 | 308 | try { 309 | fs = await import("fs") 310 | } catch { 311 | throw new Error( 312 | "Loading from an image file path is not supported in a browser environment.", 313 | ); 314 | } 315 | 316 | result.imageBuffer = fs.readFileSync( 317 | config.image, 318 | ).buffer; 319 | } else { 320 | throw new Error( 321 | "Provide your image as a file path to a .jpeg, .jpg, .png, or .webp, or a Buffer." 322 | ); 323 | } 324 | } 325 | 326 | // Verify that all values in IDs exist 327 | if (config?.ids) { 328 | if (config.ids.conversationID && config.ids.responseID && config.ids.choiceID && config.ids._reqID) { 329 | result.ids = config.ids; 330 | } else { 331 | throw new Error( 332 | "Please provide the IDs exported exactly as given." 333 | ); 334 | } 335 | } 336 | return result; 337 | } 338 | 339 | // Ask Bard a question! 340 | async ask(message, config) { 341 | let { useJSON, imageBuffer, ids } = await this.#parseConfig(config); 342 | let response = await this.#query(message, { imageBuffer, ids }); 343 | return useJSON ? response : response.content; 344 | } 345 | 346 | createChat(ids) { 347 | let bard = this; 348 | class Chat { 349 | ids = ids; 350 | 351 | async ask(message, config) { 352 | let { useJSON, imageBuffer } = await bard.#parseConfig(config); 353 | let response = await bard.#query(message, { 354 | imageBuffer, 355 | ids: this.ids, 356 | }); 357 | this.ids = response.ids; 358 | return useJSON ? response : response.content; 359 | } 360 | 361 | export() { 362 | return this.ids; 363 | } 364 | } 365 | 366 | return new Chat(); 367 | } 368 | } 369 | 370 | export default Bard; 371 | -------------------------------------------------------------------------------- /src/cookies.js: -------------------------------------------------------------------------------- 1 | import fs from 'fs'; 2 | 3 | export default { 4 | getCookie: () => { 5 | try { 6 | const cookie = fs.readFileSync('./cookie.txt', 'utf8'); 7 | return cookie; 8 | } catch (err) { 9 | return null; 10 | } 11 | }, 12 | setCookie: (cookie) => { 13 | fs.writeFileSync('./cookie.txt', cookie); 14 | }, 15 | }; 16 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | import cookies from './cookies.js'; 2 | import readline from 'readline'; 3 | import Bard from './Bard.js'; 4 | import ora from 'ora'; 5 | 6 | const main = async () => { 7 | try { 8 | // Get the cookie 9 | const cookie = cookies.getCookie(); 10 | const rl = readline.createInterface({ 11 | input: process.stdin, 12 | output: process.stdout, 13 | }); 14 | // If the cookie doesn't exist, prompt the user to enter it 15 | if (!cookie) { 16 | const userCookie = await new Promise((resolve) => { 17 | rl.question('Please enter your cookie: ', resolve); 18 | }); 19 | 20 | // Set the cookie 21 | cookies.setCookie(userCookie); 22 | rl.close(); 23 | } 24 | 25 | const myBard = new Bard(cookie); 26 | const input = process.argv.slice(2).join(' '); 27 | if (!input) { 28 | throw new Error('Please enter a question.'); 29 | } 30 | const spinner = ora('Thinking...').start(); 31 | const result = await myBard.ask(input); 32 | if (spinner) { 33 | spinner.stop(); 34 | } 35 | console.log(result); 36 | process.exit(0); 37 | } catch (err) { 38 | // console.log(err); 39 | console.log('Please run again.\n\nType "node index.js "'); 40 | } 41 | }; 42 | 43 | export default main; 44 | --------------------------------------------------------------------------------