diff --git a/.dockerignore b/.dockerignore index b0d3527..7e9c39e 100644 --- a/.dockerignore +++ b/.dockerignore @@ -1,40 +1,14 @@ -# Include any files or directories that you don't want to be copied to your -# container here (e.g., local build artifacts, temporary files, etc.). -# -# For more help, visit the .dockerignore file reference guide at -# https://docs.docker.com/engine/reference/builder/#dockerignore-file +# 排除全部文件 +**/* + +# 只保留相关构建文件 +!src +!prisma +!app.js +!package.json +!pnpm-lock.yaml +!tsconfig.json +!tsup.config.ts + + -**/.classpath -**/.dockerignore -**/.env* -**/.git -**/.gitignore -**/.project -**/.settings -**/.toolstarget -**/.vs -**/.vscode -**/.next -**/.cache -**/*.*proj.user -**/*.dbmdl -**/*.jfm -**/charts -**/docker-compose* -**/compose* -**/Dockerfile* -**/node_modules -**/npm-debug.log -**/obj -**/secrets.dev.yaml -**/values.dev.yaml -**/build -**/dist -LICENSE -TODO.md -README.md -CHANGELOG.md -**/.bot.json -**/.mi.json -**/.migpt.js* -**/*.db* diff --git a/.vscode/launch.json b/.vscode/launch.json index d05e252..db0118d 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -2,24 +2,20 @@ "version": "0.2.0", "configurations": [ { - "name": "Test.ts", + "name": "Test", "type": "node", "request": "launch", "args": ["${workspaceFolder}/tests/index.ts"], - "runtimeArgs": [ - "--no-warnings", - "--experimental-specifier-resolution=node", - "--loader", - "./scripts/esm-loader.js" - ], + "runtimeExecutable": "${workspaceFolder}/node_modules/.bin/tsx", "cwd": "${workspaceRoot}", + "envFile": "${workspaceFolder}/.env", "internalConsoleOptions": "openOnSessionStart" }, { "name": "Runner", "type": "node", "request": "launch", - "args": ["${workspaceFolder}/scripts/runner.js"], + "args": ["${workspaceFolder}/app.js"], "cwd": "${workspaceRoot}", "envFile": "${workspaceFolder}/.env", "internalConsoleOptions": "openOnSessionStart" diff --git a/Dockerfile.armv7 b/Dockerfile.armv7 deleted file mode 100644 index e001a54..0000000 --- a/Dockerfile.armv7 +++ /dev/null @@ -1,40 +0,0 @@ -# syntax=docker/dockerfile:1 - -# base -FROM arm32v7/node:18 as base - -WORKDIR /app - -COPY prisma/engines ./prisma/engines - -RUN chmod +x ./prisma/engines/query-engine -RUN chmod +x ./prisma/engines/libquery_engine.so.node -RUN chmod +x ./prisma/engines/schema-engine - -ENV PRISMA_ENGINES_CHECKSUM_IGNORE_MISSING=1 -ENV PRISMA_QUERY_ENGINE_BINARY=./prisma/engines/query-engine -ENV PRISMA_QUERY_ENGINE_LIBRARY=./prisma/engines/libquery_engine.so.node -ENV PRISMA_SCHEMA_ENGINE_BINARY=./prisma/engines/schema-engine - -# build -FROM base as build - -RUN --mount=type=cache,target=/root/.npm \ - npm install -g pnpm@9.1.1 - -COPY . . - -RUN --mount=type=cache,target=/root/.local/share/pnpm/store \ - pnpm install && pnpm build && npx prisma -v - -# run -FROM base - -COPY package.json . -COPY --from=build /app/dist ./dist -COPY --from=build /app/scripts ./scripts -COPY --from=build /app/prisma ./prisma -COPY --from=build /app/node_modules ./node_modules - -# Run the application. -CMD npm run start diff --git a/scripts/runner.js b/app.js similarity index 55% rename from scripts/runner.js rename to app.js index d59aaaa..c07fe7d 100644 --- a/scripts/runner.js +++ b/app.js @@ -1,5 +1,5 @@ -import config from "../.migpt.js"; -import { MiGPT } from "../dist/index.cjs"; +import config from "./.migpt.js"; +import { MiGPT } from "./dist/index.cjs"; async function main() { const client = MiGPT.create(config); diff --git a/package.json b/package.json index 1ef2ae3..2b3591d 100644 --- a/package.json +++ b/package.json @@ -17,14 +17,13 @@ "home-assistant" ], "scripts": { - "start": "node ./scripts/runner.js", + "start": "node ./app.js", "build": "npx -y prisma generate && tsup", "db:gen": "npx -y prisma migrate dev --name init", "db:reset": "rm -f .mi.json .bot.json prisma/app.db prisma/app.db-journal" }, "dependencies": { "@prisma/client": "^5.8.1", - "axios": "^1.6.5", "fs-extra": "^11.2.0", "https-proxy-agent": "^7.0.4", "mi-service-lite": "^2.3.0", @@ -34,9 +33,8 @@ "devDependencies": { "@types/fs-extra": "^11.0.4", "@types/node": "^20.4.9", - "dotenv": "^16.3.2", - "ts-node": "^10.9.2", "tsup": "^8.0.1", + "tsx": "^4.11.0", "typescript": "^5.3.3" }, "engines": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 1d7faee..01f49a4 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -11,9 +11,6 @@ importers: '@prisma/client': specifier: ^5.8.1 version: 5.14.0(prisma@5.14.0) - axios: - specifier: ^1.6.5 - version: 1.6.8 fs-extra: specifier: ^11.2.0 version: 11.2.0 @@ -36,15 +33,12 @@ importers: '@types/node': specifier: ^20.4.9 version: 20.12.12 - dotenv: - specifier: ^16.3.2 - version: 16.4.5 - ts-node: - specifier: ^10.9.2 - version: 10.9.2(@types/node@20.12.12)(typescript@5.4.5) tsup: specifier: ^8.0.1 version: 8.0.2(ts-node@10.9.2(@types/node@20.12.12)(typescript@5.4.5))(typescript@5.4.5) + tsx: + specifier: ^4.11.0 + version: 4.11.0 typescript: specifier: ^5.3.3 version: 5.4.5 @@ -61,138 +55,276 @@ packages: cpu: [ppc64] os: [aix] + '@esbuild/aix-ppc64@0.20.2': + resolution: {integrity: sha512-D+EBOJHXdNZcLJRBkhENNG8Wji2kgc9AZ9KiPr1JuZjsNtyHzrsfLRrY0tk2H2aoFu6RANO1y1iPPUCDYWkb5g==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [aix] + '@esbuild/android-arm64@0.19.12': resolution: {integrity: sha512-P0UVNGIienjZv3f5zq0DP3Nt2IE/3plFzuaS96vihvD0Hd6H/q4WXUGpCxD/E8YrSXfNyRPbpTq+T8ZQioSuPA==} engines: {node: '>=12'} cpu: [arm64] os: [android] + '@esbuild/android-arm64@0.20.2': + resolution: {integrity: sha512-mRzjLacRtl/tWU0SvD8lUEwb61yP9cqQo6noDZP/O8VkwafSYwZ4yWy24kan8jE/IMERpYncRt2dw438LP3Xmg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + '@esbuild/android-arm@0.19.12': resolution: {integrity: sha512-qg/Lj1mu3CdQlDEEiWrlC4eaPZ1KztwGJ9B6J+/6G+/4ewxJg7gqj8eVYWvao1bXrqGiW2rsBZFSX3q2lcW05w==} engines: {node: '>=12'} cpu: [arm] os: [android] + '@esbuild/android-arm@0.20.2': + resolution: {integrity: sha512-t98Ra6pw2VaDhqNWO2Oph2LXbz/EJcnLmKLGBJwEwXX/JAN83Fym1rU8l0JUWK6HkIbWONCSSatf4sf2NBRx/w==} + engines: {node: '>=12'} + cpu: [arm] + os: [android] + '@esbuild/android-x64@0.19.12': resolution: {integrity: sha512-3k7ZoUW6Q6YqhdhIaq/WZ7HwBpnFBlW905Fa4s4qWJyiNOgT1dOqDiVAQFwBH7gBRZr17gLrlFCRzF6jFh7Kew==} engines: {node: '>=12'} cpu: [x64] os: [android] + '@esbuild/android-x64@0.20.2': + resolution: {integrity: sha512-btzExgV+/lMGDDa194CcUQm53ncxzeBrWJcncOBxuC6ndBkKxnHdFJn86mCIgTELsooUmwUm9FkhSp5HYu00Rg==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + '@esbuild/darwin-arm64@0.19.12': resolution: {integrity: sha512-B6IeSgZgtEzGC42jsI+YYu9Z3HKRxp8ZT3cqhvliEHovq8HSX2YX8lNocDn79gCKJXOSaEot9MVYky7AKjCs8g==} engines: {node: '>=12'} cpu: [arm64] os: [darwin] + '@esbuild/darwin-arm64@0.20.2': + resolution: {integrity: sha512-4J6IRT+10J3aJH3l1yzEg9y3wkTDgDk7TSDFX+wKFiWjqWp/iCfLIYzGyasx9l0SAFPT1HwSCR+0w/h1ES/MjA==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + '@esbuild/darwin-x64@0.19.12': resolution: {integrity: sha512-hKoVkKzFiToTgn+41qGhsUJXFlIjxI/jSYeZf3ugemDYZldIXIxhvwN6erJGlX4t5h417iFuheZ7l+YVn05N3A==} engines: {node: '>=12'} cpu: [x64] os: [darwin] + '@esbuild/darwin-x64@0.20.2': + resolution: {integrity: sha512-tBcXp9KNphnNH0dfhv8KYkZhjc+H3XBkF5DKtswJblV7KlT9EI2+jeA8DgBjp908WEuYll6pF+UStUCfEpdysA==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + '@esbuild/freebsd-arm64@0.19.12': resolution: {integrity: sha512-4aRvFIXmwAcDBw9AueDQ2YnGmz5L6obe5kmPT8Vd+/+x/JMVKCgdcRwH6APrbpNXsPz+K653Qg8HB/oXvXVukA==} engines: {node: '>=12'} cpu: [arm64] os: [freebsd] + '@esbuild/freebsd-arm64@0.20.2': + resolution: {integrity: sha512-d3qI41G4SuLiCGCFGUrKsSeTXyWG6yem1KcGZVS+3FYlYhtNoNgYrWcvkOoaqMhwXSMrZRl69ArHsGJ9mYdbbw==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + '@esbuild/freebsd-x64@0.19.12': resolution: {integrity: sha512-EYoXZ4d8xtBoVN7CEwWY2IN4ho76xjYXqSXMNccFSx2lgqOG/1TBPW0yPx1bJZk94qu3tX0fycJeeQsKovA8gg==} engines: {node: '>=12'} cpu: [x64] os: [freebsd] + '@esbuild/freebsd-x64@0.20.2': + resolution: {integrity: sha512-d+DipyvHRuqEeM5zDivKV1KuXn9WeRX6vqSqIDgwIfPQtwMP4jaDsQsDncjTDDsExT4lR/91OLjRo8bmC1e+Cw==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + '@esbuild/linux-arm64@0.19.12': resolution: {integrity: sha512-EoTjyYyLuVPfdPLsGVVVC8a0p1BFFvtpQDB/YLEhaXyf/5bczaGeN15QkR+O4S5LeJ92Tqotve7i1jn35qwvdA==} engines: {node: '>=12'} cpu: [arm64] os: [linux] + '@esbuild/linux-arm64@0.20.2': + resolution: {integrity: sha512-9pb6rBjGvTFNira2FLIWqDk/uaf42sSyLE8j1rnUpuzsODBq7FvpwHYZxQ/It/8b+QOS1RYfqgGFNLRI+qlq2A==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + '@esbuild/linux-arm@0.19.12': resolution: {integrity: sha512-J5jPms//KhSNv+LO1S1TX1UWp1ucM6N6XuL6ITdKWElCu8wXP72l9MM0zDTzzeikVyqFE6U8YAV9/tFyj0ti+w==} engines: {node: '>=12'} cpu: [arm] os: [linux] + '@esbuild/linux-arm@0.20.2': + resolution: {integrity: sha512-VhLPeR8HTMPccbuWWcEUD1Az68TqaTYyj6nfE4QByZIQEQVWBB8vup8PpR7y1QHL3CpcF6xd5WVBU/+SBEvGTg==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + '@esbuild/linux-ia32@0.19.12': resolution: {integrity: sha512-Thsa42rrP1+UIGaWz47uydHSBOgTUnwBwNq59khgIwktK6x60Hivfbux9iNR0eHCHzOLjLMLfUMLCypBkZXMHA==} engines: {node: '>=12'} cpu: [ia32] os: [linux] + '@esbuild/linux-ia32@0.20.2': + resolution: {integrity: sha512-o10utieEkNPFDZFQm9CoP7Tvb33UutoJqg3qKf1PWVeeJhJw0Q347PxMvBgVVFgouYLGIhFYG0UGdBumROyiig==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + '@esbuild/linux-loong64@0.19.12': resolution: {integrity: sha512-LiXdXA0s3IqRRjm6rV6XaWATScKAXjI4R4LoDlvO7+yQqFdlr1Bax62sRwkVvRIrwXxvtYEHHI4dm50jAXkuAA==} engines: {node: '>=12'} cpu: [loong64] os: [linux] + '@esbuild/linux-loong64@0.20.2': + resolution: {integrity: sha512-PR7sp6R/UC4CFVomVINKJ80pMFlfDfMQMYynX7t1tNTeivQ6XdX5r2XovMmha/VjR1YN/HgHWsVcTRIMkymrgQ==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + '@esbuild/linux-mips64el@0.19.12': resolution: {integrity: sha512-fEnAuj5VGTanfJ07ff0gOA6IPsvrVHLVb6Lyd1g2/ed67oU1eFzL0r9WL7ZzscD+/N6i3dWumGE1Un4f7Amf+w==} engines: {node: '>=12'} cpu: [mips64el] os: [linux] + '@esbuild/linux-mips64el@0.20.2': + resolution: {integrity: sha512-4BlTqeutE/KnOiTG5Y6Sb/Hw6hsBOZapOVF6njAESHInhlQAghVVZL1ZpIctBOoTFbQyGW+LsVYZ8lSSB3wkjA==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + '@esbuild/linux-ppc64@0.19.12': resolution: {integrity: sha512-nYJA2/QPimDQOh1rKWedNOe3Gfc8PabU7HT3iXWtNUbRzXS9+vgB0Fjaqr//XNbd82mCxHzik2qotuI89cfixg==} engines: {node: '>=12'} cpu: [ppc64] os: [linux] + '@esbuild/linux-ppc64@0.20.2': + resolution: {integrity: sha512-rD3KsaDprDcfajSKdn25ooz5J5/fWBylaaXkuotBDGnMnDP1Uv5DLAN/45qfnf3JDYyJv/ytGHQaziHUdyzaAg==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + '@esbuild/linux-riscv64@0.19.12': resolution: {integrity: sha512-2MueBrlPQCw5dVJJpQdUYgeqIzDQgw3QtiAHUC4RBz9FXPrskyyU3VI1hw7C0BSKB9OduwSJ79FTCqtGMWqJHg==} engines: {node: '>=12'} cpu: [riscv64] os: [linux] + '@esbuild/linux-riscv64@0.20.2': + resolution: {integrity: sha512-snwmBKacKmwTMmhLlz/3aH1Q9T8v45bKYGE3j26TsaOVtjIag4wLfWSiZykXzXuE1kbCE+zJRmwp+ZbIHinnVg==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + '@esbuild/linux-s390x@0.19.12': resolution: {integrity: sha512-+Pil1Nv3Umes4m3AZKqA2anfhJiVmNCYkPchwFJNEJN5QxmTs1uzyy4TvmDrCRNT2ApwSari7ZIgrPeUx4UZDg==} engines: {node: '>=12'} cpu: [s390x] os: [linux] + '@esbuild/linux-s390x@0.20.2': + resolution: {integrity: sha512-wcWISOobRWNm3cezm5HOZcYz1sKoHLd8VL1dl309DiixxVFoFe/o8HnwuIwn6sXre88Nwj+VwZUvJf4AFxkyrQ==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + '@esbuild/linux-x64@0.19.12': resolution: {integrity: sha512-B71g1QpxfwBvNrfyJdVDexenDIt1CiDN1TIXLbhOw0KhJzE78KIFGX6OJ9MrtC0oOqMWf+0xop4qEU8JrJTwCg==} engines: {node: '>=12'} cpu: [x64] os: [linux] + '@esbuild/linux-x64@0.20.2': + resolution: {integrity: sha512-1MdwI6OOTsfQfek8sLwgyjOXAu+wKhLEoaOLTjbijk6E2WONYpH9ZU2mNtR+lZ2B4uwr+usqGuVfFT9tMtGvGw==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + '@esbuild/netbsd-x64@0.19.12': resolution: {integrity: sha512-3ltjQ7n1owJgFbuC61Oj++XhtzmymoCihNFgT84UAmJnxJfm4sYCiSLTXZtE00VWYpPMYc+ZQmB6xbSdVh0JWA==} engines: {node: '>=12'} cpu: [x64] os: [netbsd] + '@esbuild/netbsd-x64@0.20.2': + resolution: {integrity: sha512-K8/DhBxcVQkzYc43yJXDSyjlFeHQJBiowJ0uVL6Tor3jGQfSGHNNJcWxNbOI8v5k82prYqzPuwkzHt3J1T1iZQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + '@esbuild/openbsd-x64@0.19.12': resolution: {integrity: sha512-RbrfTB9SWsr0kWmb9srfF+L933uMDdu9BIzdA7os2t0TXhCRjrQyCeOt6wVxr79CKD4c+p+YhCj31HBkYcXebw==} engines: {node: '>=12'} cpu: [x64] os: [openbsd] + '@esbuild/openbsd-x64@0.20.2': + resolution: {integrity: sha512-eMpKlV0SThJmmJgiVyN9jTPJ2VBPquf6Kt/nAoo6DgHAoN57K15ZghiHaMvqjCye/uU4X5u3YSMgVBI1h3vKrQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + '@esbuild/sunos-x64@0.19.12': resolution: {integrity: sha512-HKjJwRrW8uWtCQnQOz9qcU3mUZhTUQvi56Q8DPTLLB+DawoiQdjsYq+j+D3s9I8VFtDr+F9CjgXKKC4ss89IeA==} engines: {node: '>=12'} cpu: [x64] os: [sunos] + '@esbuild/sunos-x64@0.20.2': + resolution: {integrity: sha512-2UyFtRC6cXLyejf/YEld4Hajo7UHILetzE1vsRcGL3earZEW77JxrFjH4Ez2qaTiEfMgAXxfAZCm1fvM/G/o8w==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + '@esbuild/win32-arm64@0.19.12': resolution: {integrity: sha512-URgtR1dJnmGvX864pn1B2YUYNzjmXkuJOIqG2HdU62MVS4EHpU2946OZoTMnRUHklGtJdJZ33QfzdjGACXhn1A==} engines: {node: '>=12'} cpu: [arm64] os: [win32] + '@esbuild/win32-arm64@0.20.2': + resolution: {integrity: sha512-GRibxoawM9ZCnDxnP3usoUDO9vUkpAxIIZ6GQI+IlVmr5kP3zUq+l17xELTHMWTWzjxa2guPNyrpq1GWmPvcGQ==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + '@esbuild/win32-ia32@0.19.12': resolution: {integrity: sha512-+ZOE6pUkMOJfmxmBZElNOx72NKpIa/HFOMGzu8fqzQJ5kgf6aTGrcJaFsNiVMH4JKpMipyK+7k0n2UXN7a8YKQ==} engines: {node: '>=12'} cpu: [ia32] os: [win32] + '@esbuild/win32-ia32@0.20.2': + resolution: {integrity: sha512-HfLOfn9YWmkSKRQqovpnITazdtquEW8/SoHW7pWpuEeguaZI4QnCRW6b+oZTztdBnZOS2hqJ6im/D5cPzBTTlQ==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + '@esbuild/win32-x64@0.19.12': resolution: {integrity: sha512-T1QyPSDCyMXaO3pzBkF96E8xMkiRYbUEZADd29SyPGabqxMViNoii+NcK7eWJAEoU6RZyEm5lVSIjTmcdoB9HA==} engines: {node: '>=12'} cpu: [x64] os: [win32] + '@esbuild/win32-x64@0.20.2': + resolution: {integrity: sha512-N49X4lJX27+l9jbLKSqZ6bKNjzQvHaT8IIFUy+YIqmXQdjYCToGWwOItDrfby14c78aDd5NHQl29xingXfCdLQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + '@isaacs/cliui@8.0.2': resolution: {integrity: sha512-O8jcjabXaleOG9DQ0+ARXWZBTfnP4WNAqzuiJK7ll44AmxGKv/J2M4TPjxjY3znBCfvBXFzucm1twdyFybFqEA==} engines: {node: '>=12'} @@ -496,10 +628,6 @@ packages: resolution: {integrity: sha512-WkrWp9GR4KXfKGYzOLmTuGVi1UWFfws377n9cc55/tb6DuqyF6pcQ5AbiHEshaDpY9v6oaSr2XCDidGmMwdzIA==} engines: {node: '>=8'} - dotenv@16.4.5: - resolution: {integrity: sha512-ZmdL2rui+eB2YwhsWzjInR8LldtZHGDoQ1ugH85ppHKwpUHL7j7rN0Ti9NCnGiQbhaZ11FpR+7ao1dNsmduNUg==} - engines: {node: '>=12'} - eastasianwidth@0.2.0: resolution: {integrity: sha512-I88TYZWc9XiYHRQ4/3c5rjjfgkjhLyW2luGIheGERbNQ6OY7yTybanSpDXZa8y7VUP9YmDcYa+eyq4ca7iLqWA==} @@ -514,6 +642,11 @@ packages: engines: {node: '>=12'} hasBin: true + esbuild@0.20.2: + resolution: {integrity: sha512-WdOOppmUNU+IbZ0PaDiTst80zjnrOkyJNHoKupIcVyU8Lvla3Ugx94VzkQ32Ijqd7UhHJy75gNWDMUekcrSJ6g==} + engines: {node: '>=12'} + hasBin: true + event-target-shim@5.0.1: resolution: {integrity: sha512-i/2XbnSz/uxRCU6+NdVJgKWDTM427+MqYbkQzD321DuCQJUqOuJKIA0IM2+W2xtYHdKOmZ4dR6fExsd4SXL+WQ==} engines: {node: '>=6'} @@ -570,6 +703,9 @@ packages: resolution: {integrity: sha512-ts6Wi+2j3jQjqi70w5AlN8DFnkSwC+MqmxEzdEALB2qXZYV3X/b1CTfgPLGJNMeAWxdPfU8FO1ms3NUfaHCPYg==} engines: {node: '>=10'} + get-tsconfig@4.7.5: + resolution: {integrity: sha512-ZCuZCnlqNzjb4QprAzXKdpp/gh6KTxSJuw3IBsPnV/7fV4NxC9ckB+vPTt8w7fJA0TaSD7c55BR47JD6MEDyDw==} + glob-parent@5.1.2: resolution: {integrity: sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==} engines: {node: '>= 6'} @@ -795,6 +931,9 @@ packages: resolution: {integrity: sha512-qYg9KP24dD5qka9J47d0aVky0N+b4fTU89LN9iDnjB5waksiC49rvMB0PrUJQGoTmH50XPiqOvAjDfaijGxYZw==} engines: {node: '>=8'} + resolve-pkg-maps@1.0.0: + resolution: {integrity: sha512-seS2Tj26TBVOC2NIc2rOe2y2ZO7efxITtLZcGSOnHHNOQ7CkiUBfw0Iw2ck6xkIhPwLhKNLS8BO+hEpngQlqzw==} + reusify@1.0.4: resolution: {integrity: sha512-U9nH88a3fc/ekCF1l0/UP1IosiuIjyTh7hBvXVMHYgVcfGvt897Xguj2UOLDeI5BG2m7/uwyaLVT6fbtCwTyzw==} engines: {iojs: '>=1.0.0', node: '>=0.10.0'} @@ -912,6 +1051,11 @@ packages: typescript: optional: true + tsx@4.11.0: + resolution: {integrity: sha512-vzGGELOgAupsNVssAmZjbUDfdm/pWP4R+Kg8TVdsonxbXk0bEpE1qh0yV6/QxUVXaVlNemgcPajGdJJ82n3stg==} + engines: {node: '>=18.0.0'} + hasBin: true + typescript@5.4.5: resolution: {integrity: sha512-vcI4UpRgg81oIRUFwR0WSIHKt11nJ7SAVlYNIu+QpqeyXP+gpQJy/Z4+F0aGxSE4MqwjyXvW/TzgkLAx2AGHwQ==} engines: {node: '>=14.17'} @@ -974,76 +1118,146 @@ snapshots: '@cspotcode/source-map-support@0.8.1': dependencies: '@jridgewell/trace-mapping': 0.3.9 + optional: true '@esbuild/aix-ppc64@0.19.12': optional: true + '@esbuild/aix-ppc64@0.20.2': + optional: true + '@esbuild/android-arm64@0.19.12': optional: true + '@esbuild/android-arm64@0.20.2': + optional: true + '@esbuild/android-arm@0.19.12': optional: true + '@esbuild/android-arm@0.20.2': + optional: true + '@esbuild/android-x64@0.19.12': optional: true + '@esbuild/android-x64@0.20.2': + optional: true + '@esbuild/darwin-arm64@0.19.12': optional: true + '@esbuild/darwin-arm64@0.20.2': + optional: true + '@esbuild/darwin-x64@0.19.12': optional: true + '@esbuild/darwin-x64@0.20.2': + optional: true + '@esbuild/freebsd-arm64@0.19.12': optional: true + '@esbuild/freebsd-arm64@0.20.2': + optional: true + '@esbuild/freebsd-x64@0.19.12': optional: true + '@esbuild/freebsd-x64@0.20.2': + optional: true + '@esbuild/linux-arm64@0.19.12': optional: true + '@esbuild/linux-arm64@0.20.2': + optional: true + '@esbuild/linux-arm@0.19.12': optional: true + '@esbuild/linux-arm@0.20.2': + optional: true + '@esbuild/linux-ia32@0.19.12': optional: true + '@esbuild/linux-ia32@0.20.2': + optional: true + '@esbuild/linux-loong64@0.19.12': optional: true + '@esbuild/linux-loong64@0.20.2': + optional: true + '@esbuild/linux-mips64el@0.19.12': optional: true + '@esbuild/linux-mips64el@0.20.2': + optional: true + '@esbuild/linux-ppc64@0.19.12': optional: true + '@esbuild/linux-ppc64@0.20.2': + optional: true + '@esbuild/linux-riscv64@0.19.12': optional: true + '@esbuild/linux-riscv64@0.20.2': + optional: true + '@esbuild/linux-s390x@0.19.12': optional: true + '@esbuild/linux-s390x@0.20.2': + optional: true + '@esbuild/linux-x64@0.19.12': optional: true + '@esbuild/linux-x64@0.20.2': + optional: true + '@esbuild/netbsd-x64@0.19.12': optional: true + '@esbuild/netbsd-x64@0.20.2': + optional: true + '@esbuild/openbsd-x64@0.19.12': optional: true + '@esbuild/openbsd-x64@0.20.2': + optional: true + '@esbuild/sunos-x64@0.19.12': optional: true + '@esbuild/sunos-x64@0.20.2': + optional: true + '@esbuild/win32-arm64@0.19.12': optional: true + '@esbuild/win32-arm64@0.20.2': + optional: true + '@esbuild/win32-ia32@0.19.12': optional: true + '@esbuild/win32-ia32@0.20.2': + optional: true + '@esbuild/win32-x64@0.19.12': optional: true + '@esbuild/win32-x64@0.20.2': + optional: true + '@isaacs/cliui@8.0.2': dependencies: string-width: 5.1.2 @@ -1074,6 +1288,7 @@ snapshots: dependencies: '@jridgewell/resolve-uri': 3.1.2 '@jridgewell/sourcemap-codec': 1.4.15 + optional: true '@nodelib/fs.scandir@2.1.5': dependencies: @@ -1163,13 +1378,17 @@ snapshots: '@rollup/rollup-win32-x64-msvc@4.17.2': optional: true - '@tsconfig/node10@1.0.11': {} + '@tsconfig/node10@1.0.11': + optional: true - '@tsconfig/node12@1.0.11': {} + '@tsconfig/node12@1.0.11': + optional: true - '@tsconfig/node14@1.0.3': {} + '@tsconfig/node14@1.0.3': + optional: true - '@tsconfig/node16@1.0.4': {} + '@tsconfig/node16@1.0.4': + optional: true '@types/estree@1.0.5': {} @@ -1199,9 +1418,11 @@ snapshots: dependencies: event-target-shim: 5.0.1 - acorn-walk@8.3.2: {} + acorn-walk@8.3.2: + optional: true - acorn@8.11.3: {} + acorn@8.11.3: + optional: true agent-base@7.1.1: dependencies: @@ -1230,7 +1451,8 @@ snapshots: normalize-path: 3.0.0 picomatch: 2.3.1 - arg@4.1.3: {} + arg@4.1.3: + optional: true array-union@2.1.0: {} @@ -1287,7 +1509,8 @@ snapshots: commander@4.1.1: {} - create-require@1.1.1: {} + create-require@1.1.1: + optional: true cross-spawn@7.0.3: dependencies: @@ -1301,14 +1524,13 @@ snapshots: delayed-stream@1.0.0: {} - diff@4.0.2: {} + diff@4.0.2: + optional: true dir-glob@3.0.1: dependencies: path-type: 4.0.0 - dotenv@16.4.5: {} - eastasianwidth@0.2.0: {} emoji-regex@8.0.0: {} @@ -1341,6 +1563,32 @@ snapshots: '@esbuild/win32-ia32': 0.19.12 '@esbuild/win32-x64': 0.19.12 + esbuild@0.20.2: + optionalDependencies: + '@esbuild/aix-ppc64': 0.20.2 + '@esbuild/android-arm': 0.20.2 + '@esbuild/android-arm64': 0.20.2 + '@esbuild/android-x64': 0.20.2 + '@esbuild/darwin-arm64': 0.20.2 + '@esbuild/darwin-x64': 0.20.2 + '@esbuild/freebsd-arm64': 0.20.2 + '@esbuild/freebsd-x64': 0.20.2 + '@esbuild/linux-arm': 0.20.2 + '@esbuild/linux-arm64': 0.20.2 + '@esbuild/linux-ia32': 0.20.2 + '@esbuild/linux-loong64': 0.20.2 + '@esbuild/linux-mips64el': 0.20.2 + '@esbuild/linux-ppc64': 0.20.2 + '@esbuild/linux-riscv64': 0.20.2 + '@esbuild/linux-s390x': 0.20.2 + '@esbuild/linux-x64': 0.20.2 + '@esbuild/netbsd-x64': 0.20.2 + '@esbuild/openbsd-x64': 0.20.2 + '@esbuild/sunos-x64': 0.20.2 + '@esbuild/win32-arm64': 0.20.2 + '@esbuild/win32-ia32': 0.20.2 + '@esbuild/win32-x64': 0.20.2 + event-target-shim@5.0.1: {} execa@5.1.1: @@ -1402,6 +1650,10 @@ snapshots: get-stream@6.0.1: {} + get-tsconfig@4.7.5: + dependencies: + resolve-pkg-maps: 1.0.0 + glob-parent@5.1.2: dependencies: is-glob: 4.0.3 @@ -1482,7 +1734,8 @@ snapshots: lru-cache@10.2.2: {} - make-error@1.3.6: {} + make-error@1.3.6: + optional: true merge-stream@2.0.0: {} @@ -1593,6 +1846,8 @@ snapshots: resolve-from@5.0.0: {} + resolve-pkg-maps@1.0.0: {} + reusify@1.0.4: {} rollup@4.17.2: @@ -1708,6 +1963,7 @@ snapshots: typescript: 5.4.5 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + optional: true tsup@8.0.2(ts-node@10.9.2(@types/node@20.12.12)(typescript@5.4.5))(typescript@5.4.5): dependencies: @@ -1731,13 +1987,21 @@ snapshots: - supports-color - ts-node + tsx@4.11.0: + dependencies: + esbuild: 0.20.2 + get-tsconfig: 4.7.5 + optionalDependencies: + fsevents: 2.3.3 + typescript@5.4.5: {} undici-types@5.26.5: {} universalify@2.0.1: {} - v8-compile-cache-lib@3.0.1: {} + v8-compile-cache-lib@3.0.1: + optional: true web-streams-polyfill@3.3.3: {} @@ -1776,4 +2040,5 @@ snapshots: yaml@2.4.2: {} - yn@3.1.1: {} + yn@3.1.1: + optional: true diff --git a/scripts/esm-loader.js b/scripts/esm-loader.js deleted file mode 100644 index c23dd07..0000000 --- a/scripts/esm-loader.js +++ /dev/null @@ -1,8 +0,0 @@ -// https://github.com/TypeStrong/ts-node/discussions/1450#discussioncomment-1806115 -import { resolve as resolveTs } from 'ts-node/esm'; - -export function resolve(specifier, ctx, defaultResolve) { - return resolveTs(specifier, ctx, defaultResolve); -} - -export { load, transformSource } from 'ts-node/esm'; diff --git a/src/services/http.ts b/src/services/http.ts deleted file mode 100644 index 9d1cf40..0000000 --- a/src/services/http.ts +++ /dev/null @@ -1,111 +0,0 @@ -import axios, { AxiosRequestConfig, CreateAxiosDefaults } from "axios"; -import { HttpsProxyAgent } from "https-proxy-agent"; -import { isNotEmpty } from "../utils/is"; -import { Logger } from "../utils/log"; - -export const kProxyAgent = process.env.HTTP_PROXY - ? new HttpsProxyAgent(process.env.HTTP_PROXY) - : null; - -const _baseConfig: CreateAxiosDefaults = { - timeout: 10 * 1000, - headers: { - "Content-Type": "application/json", - "User-Agent": - "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:107.0) Gecko/20100101 Firefox/107.0", - }, -}; - -const _http = axios.create(_baseConfig); - -interface HttpError { - isError: true; - error: any; - code: string; - message: string; -} - -type RequestConfig = AxiosRequestConfig & { - rawResponse?: boolean; - cookies?: Record; -}; - -const _logger = Logger.create({ tag: "Http" }); -_http.interceptors.response.use( - (res) => { - const config: any = res.config; - if (config.rawResponse) { - return res; - } - return res.data; - }, - (err) => { - const error = err.response?.data?.error ?? err.response?.data ?? err; - const apiError: HttpError = { - error: err, - isError: true, - code: error.code ?? "UNKNOWN CODE", - message: error.message ?? "UNKNOWN ERROR", - }; - _logger.error( - "Network request failed:", - apiError.code, - apiError.message, - error - ); - return apiError; - } -); - -class HTTPClient { - async get( - url: string, - query?: - | Record - | RequestConfig, - config?: RequestConfig - ): Promise { - if (config === undefined) { - config = query; - query = undefined; - } - return _http.get( - HTTPClient._buildURL(url, query), - HTTPClient._buildConfig(config) - ) as any; - } - - async post( - url: string, - data?: any, - config?: RequestConfig - ): Promise { - return _http.post(url, data, HTTPClient._buildConfig(config)) as any; - } - - private static _buildURL = (url: string, query?: Record) => { - const _url = new URL(url); - for (const [key, value] of Object.entries(query ?? {})) { - if (isNotEmpty(value)) { - _url.searchParams.append(key, value.toString()); - } - } - return _url.href; - }; - - private static _buildConfig = (config?: RequestConfig) => { - if (config?.cookies) { - config.headers = { - ...config.headers, - Cookie: Object.entries(config.cookies) - .map( - ([key, value]) => `${key}=${value == null ? "" : value.toString()};` - ) - .join(" "), - }; - } - return config; - }; -} - -export const Http = new HTTPClient(); diff --git a/src/services/openai.ts b/src/services/openai.ts index b7a8250..c6dee08 100644 --- a/src/services/openai.ts +++ b/src/services/openai.ts @@ -5,10 +5,10 @@ import { } from "openai/resources"; import { kEnvs } from "../utils/env"; -import { kProxyAgent } from "./http"; import { withDefault } from "../utils/base"; import { ChatCompletionCreateParamsBase } from "openai/resources/chat/completions"; import { Logger } from "../utils/log"; +import { kProxyAgent } from "./proxy"; export interface ChatOptions { user: string; diff --git a/src/services/proxy.ts b/src/services/proxy.ts new file mode 100644 index 0000000..f7c70f9 --- /dev/null +++ b/src/services/proxy.ts @@ -0,0 +1,4 @@ +import { HttpsProxyAgent } from "https-proxy-agent"; +export const kProxyAgent = process.env.HTTP_PROXY + ? new HttpsProxyAgent(process.env.HTTP_PROXY) + : null; diff --git a/src/services/speaker/base.ts b/src/services/speaker/base.ts index af13fca..e2d08c8 100644 --- a/src/services/speaker/base.ts +++ b/src/services/speaker/base.ts @@ -7,7 +7,6 @@ import { } from "mi-service-lite"; import { clamp, jsonEncode, sleep } from "../../utils/base"; import { Logger } from "../../utils/log"; -import { Http } from "../http"; import { StreamResponse } from "./stream"; import { kAreYouOK } from "../../utils/string"; @@ -279,9 +278,9 @@ export class BaseSpeaker { private _doubaoSpeakers?: Speaker[]; private _defaultSpeaker = "zh_female_maomao_conversation_wvae_bigtts"; async switchDefaultSpeaker(speaker: string) { - if (!this._doubaoSpeakers) { - const doubaoSpeakers = process.env.SPEAKERS_DOUBAO; - const res = await Http.get(doubaoSpeakers ?? "/"); + const speakersAPI = process.env.SPEAKERS_DOUBAO; + if (!this._doubaoSpeakers && speakersAPI) { + const res = await (await fetch(speakersAPI)).json(); if (Array.isArray(res)) { this._doubaoSpeakers = res; } diff --git a/tests/index.ts b/tests/index.ts index 8fa8db0..ea6ab66 100644 --- a/tests/index.ts +++ b/tests/index.ts @@ -1,4 +1,3 @@ -import dotenv from "dotenv"; import { println } from "../src/utils/base"; import { kBannerASCII } from "../src/utils/string"; import { testDB } from "./db"; @@ -8,8 +7,6 @@ import { testMyBot } from "./bot"; import { testLog } from "./log"; import { testMiGPT } from "./migpt"; -dotenv.config(); - async function main() { // println(kBannerASCII); // testDB(); diff --git a/tsconfig.json b/tsconfig.json index c54da35..6c9d638 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -8,6 +8,6 @@ "esModuleInterop": true, "moduleResolution": "node" }, - "include": ["src", "tests", "scripts"], + "include": ["src", "tests"], "exclude": ["node_modules", "dist"] }