fix(gpt-runner-cli): fix readableStream polyfill not working
This commit is contained in:
@@ -48,7 +48,7 @@
|
||||
"dependencies": {
|
||||
"@nicepkg/gpt-runner-shared": "workspace:*",
|
||||
"ignore": "^5.2.4",
|
||||
"langchain": "^0.0.122",
|
||||
"langchain": "^0.0.123",
|
||||
"unconfig": "^0.3.10",
|
||||
"uuid": "^9.0.0",
|
||||
"zod": "^3.21.4"
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
import { addNodejsPolyfill } from '@nicepkg/gpt-runner-shared/node'
|
||||
|
||||
addNodejsPolyfill()
|
||||
|
||||
export * from './core'
|
||||
export * from './langchain'
|
||||
|
||||
|
||||
@@ -89,6 +89,8 @@
|
||||
"minimatch": "*",
|
||||
"socket.io": "*",
|
||||
"socket.io-client": "*",
|
||||
"undici": "*",
|
||||
"web-streams-polyfill": "*",
|
||||
"zod": "*",
|
||||
"zod-to-json-schema": "*"
|
||||
},
|
||||
@@ -108,6 +110,8 @@
|
||||
"open": "^8.4.2",
|
||||
"socket.io": "^4.7.2",
|
||||
"socket.io-client": "^4.7.2",
|
||||
"undici": "^5.23.0",
|
||||
"web-streams-polyfill": "^3.2.1",
|
||||
"zod": "^3.21.4",
|
||||
"zod-to-json-schema": "^3.21.4"
|
||||
},
|
||||
|
||||
@@ -6,5 +6,6 @@ export * from './get-cache-dir'
|
||||
export * from './get-storage'
|
||||
export * from './network'
|
||||
export * from './path-utils'
|
||||
export * from './polyfill'
|
||||
export * from './proxy'
|
||||
export * from './request'
|
||||
|
||||
15
packages/gpt-runner-shared/src/node/helpers/polyfill.ts
Normal file
15
packages/gpt-runner-shared/src/node/helpers/polyfill.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { Headers, Request, Response, fetch } from 'undici'
|
||||
import { ReadableStream } from 'web-streams-polyfill'
|
||||
import { canUseNodeFetchWithoutCliFlag } from './check-node-version'
|
||||
|
||||
export function addNodejsPolyfill() {
|
||||
if (!canUseNodeFetchWithoutCliFlag()) {
|
||||
console.log('GPT Runner: add polyfill for fetch', process.version)
|
||||
// polyfill for nodejs < 18.0.0
|
||||
globalThis.fetch = fetch as any
|
||||
globalThis.Headers = Headers as any
|
||||
globalThis.Request = Request as any
|
||||
globalThis.Response = Response as any
|
||||
globalThis.ReadableStream = ReadableStream as any
|
||||
}
|
||||
}
|
||||
@@ -25,7 +25,7 @@
|
||||
"notificationConfig": {
|
||||
"createAt": "2023-08-06 18:37:06",
|
||||
"title": "GPT Runner 通知",
|
||||
"message": "\n### 🚀 新版 v1.2.2 (2023-08-06)\n\n> vscode 用户重启 vscode 后即可在扩展处更新。\n>\n> cli 用户执行 `npm i -g gptr` 即可更新。\n\n1. 针对语言为简体中文的用户提供 OpenAI API key 第三方供应商,也就是你可以白嫖了。\n2. 点击左上角设置,切换供应商即可。\n3. 本次 API Key 由慷慨大方的 `朝云云` 提供,让我们把掌声送给他。\n\n### 💬 交流\n\n1. 想进群交流的加 wechat: `qq2214962083`\n2. 所有捐赠 API Key 的朋友,都可以在这里免费展示 50 字以内的广告直到 API Key 失效,如果你也想捐赠 API Key,可以联系我。\n3. 此处广告仅供展示,与 GPT-Runner 无关,**若有财产交易,请自行承担风险**\n\n### 📢 YunAI - AI驱动的WEB对话应用 (朝云云供应商广告)\n\n🔵 [**点击进入**](https://faschat.zyai.online/)注册即送大量3.5使用次数\n\n如需适配 GPT-Runner 的 4.0-32k 或 Claude 接口服务,可 VX 联系:`YunAi0101`\n\n "
|
||||
"message": "\n### 🚀 新版 v1.2.2 (2023-08-06)\n\n> vscode 用户重启 vscode 后即可在扩展处更新。\n>\n> cli 用户执行 `npm update -g gptr` 即可更新。\n\n1. 针对语言为简体中文的用户提供 OpenAI API key 第三方供应商,也就是你可以白嫖了。\n2. 点击左上角设置,切换供应商即可。\n3. 本次 API Key 由慷慨大方的 `朝云云` 提供,让我们把掌声送给他。\n\n### 💬 交流\n\n1. 想进群交流的加 wechat: `qq2214962083`\n2. 所有捐赠 API Key 的朋友,都可以在这里免费展示 50 字以内的广告直到 API Key 失效,如果你也想捐赠 API Key,可以联系我。\n3. 此处广告仅供展示,与 GPT-Runner 无关,**若有财产交易,请自行承担风险**\n\n### 📢 YunAI - AI驱动的WEB对话应用 (朝云云供应商广告)\n\n🔵 [**点击进入**](https://faschat.zyai.online/)注册即送大量3.5使用次数\n\n如需适配 GPT-Runner 的 4.0-32k 或 Claude 接口服务,可 VX 联系:`YunAi0101`\n\n "
|
||||
},
|
||||
"vendorsConfig": {
|
||||
"createAt": "2023-08-06 18:37:22",
|
||||
@@ -41,4 +41,4 @@
|
||||
"anthropic": []
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,11 +3,13 @@ import type { Express } from 'express'
|
||||
import express from 'express'
|
||||
import cors from 'cors'
|
||||
import history from 'connect-history-api-fallback'
|
||||
import { PathUtils, getPort } from '@nicepkg/gpt-runner-shared/node'
|
||||
import { PathUtils, addNodejsPolyfill, getPort } from '@nicepkg/gpt-runner-shared/node'
|
||||
import { setProxyUrl } from './src/proxy'
|
||||
import { processControllers } from './src/controllers'
|
||||
import { errorHandlerMiddleware, safeCheckMiddleware } from './src/middleware'
|
||||
|
||||
addNodejsPolyfill()
|
||||
|
||||
export * from './src/helpers/app-config'
|
||||
|
||||
const dirname = PathUtils.getCurrentDirName(import.meta.url, () => __dirname)
|
||||
|
||||
@@ -14,7 +14,7 @@ export const cnNotificationConfig: NotificationConfig = {
|
||||
|
||||
> vscode 用户重启 vscode 后即可在扩展处更新。
|
||||
>
|
||||
> cli 用户执行 \`npm i -g gptr\` 即可更新。
|
||||
> cli 用户执行 \`npm update -g gptr\` 即可更新。
|
||||
|
||||
1. 针对语言为简体中文的用户提供 OpenAI API key 第三方供应商,也就是你可以白嫖了。
|
||||
2. 点击左上角设置,切换供应商即可。
|
||||
|
||||
@@ -1,17 +1,6 @@
|
||||
import { canUseNodeFetchWithoutCliFlag, getDefaultProxyUrl } from '@nicepkg/gpt-runner-shared/node'
|
||||
import { getDefaultProxyUrl } from '@nicepkg/gpt-runner-shared/node'
|
||||
import { bootstrap } from 'global-agent'
|
||||
import { Headers, ProxyAgent, Request, Response, fetch, setGlobalDispatcher } from 'undici'
|
||||
import { ReadableStream } from 'web-streams-polyfill/ponyfill'
|
||||
|
||||
if (!canUseNodeFetchWithoutCliFlag()) {
|
||||
console.log('GPT Runner: add polyfill for fetch', process.version)
|
||||
// polyfill for nodejs < 18.0.0
|
||||
globalThis.fetch = fetch as any
|
||||
globalThis.Headers = Headers as any
|
||||
globalThis.Request = Request as any
|
||||
globalThis.Response = Response as any
|
||||
globalThis.ReadableStream = ReadableStream as any
|
||||
}
|
||||
import { ProxyAgent, setGlobalDispatcher } from 'undici'
|
||||
|
||||
// global proxy
|
||||
async function startProxy() {
|
||||
|
||||
39
pnpm-lock.yaml
generated
39
pnpm-lock.yaml
generated
@@ -165,8 +165,8 @@ importers:
|
||||
specifier: ^5.2.4
|
||||
version: 5.2.4
|
||||
langchain:
|
||||
specifier: ^0.0.122
|
||||
version: 0.0.122(ignore@5.2.4)
|
||||
specifier: ^0.0.123
|
||||
version: 0.0.123(ignore@5.2.4)
|
||||
unconfig:
|
||||
specifier: ^0.3.10
|
||||
version: 0.3.10
|
||||
@@ -231,6 +231,12 @@ importers:
|
||||
socket.io-client:
|
||||
specifier: ^4.7.2
|
||||
version: 4.7.2
|
||||
undici:
|
||||
specifier: ^5.23.0
|
||||
version: 5.23.0
|
||||
web-streams-polyfill:
|
||||
specifier: ^3.2.1
|
||||
version: 3.2.1
|
||||
zod:
|
||||
specifier: ^3.21.4
|
||||
version: 3.21.4
|
||||
@@ -915,7 +921,7 @@ packages:
|
||||
gensync: 1.0.0-beta.2
|
||||
json5: 2.2.3
|
||||
lodash: 4.17.21
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
semver: 5.7.1
|
||||
source-map: 0.5.6
|
||||
transitivePeerDependencies:
|
||||
@@ -1309,7 +1315,7 @@ packages:
|
||||
'@babel/helper-plugin-utils': 7.22.5
|
||||
debug: 4.3.4
|
||||
lodash.debounce: 4.0.8
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
semver: 6.3.1
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
@@ -1325,7 +1331,7 @@ packages:
|
||||
'@babel/helper-plugin-utils': 7.22.5
|
||||
debug: 4.3.4
|
||||
lodash.debounce: 4.0.8
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
@@ -1340,7 +1346,7 @@ packages:
|
||||
'@babel/helper-plugin-utils': 7.22.5
|
||||
debug: 4.3.4
|
||||
lodash.debounce: 4.0.8
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: false
|
||||
@@ -1355,7 +1361,7 @@ packages:
|
||||
'@babel/helper-plugin-utils': 7.22.5
|
||||
debug: 4.3.4
|
||||
lodash.debounce: 4.0.8
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
@@ -7021,7 +7027,7 @@ packages:
|
||||
glob: 7.2.3
|
||||
is-reference: 1.2.1
|
||||
magic-string: 0.30.0
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
rollup: 2.79.1
|
||||
dev: true
|
||||
|
||||
@@ -7045,7 +7051,7 @@ packages:
|
||||
builtin-modules: 3.3.0
|
||||
deepmerge: 4.3.1
|
||||
is-module: 1.0.0
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
rollup: 2.79.1
|
||||
dev: false
|
||||
|
||||
@@ -7060,7 +7066,7 @@ packages:
|
||||
deepmerge: 4.3.1
|
||||
is-builtin-module: 3.2.1
|
||||
is-module: 1.0.0
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
rollup: 2.79.1
|
||||
dev: true
|
||||
|
||||
@@ -9281,7 +9287,6 @@ packages:
|
||||
engines: {node: '>=10.16.0'}
|
||||
dependencies:
|
||||
streamsearch: 1.1.0
|
||||
dev: true
|
||||
|
||||
/bytes@3.0.0:
|
||||
resolution: {integrity: sha512-pMhOfFDPiv9t5jjIXkHosWmkSyQbvsgEVNkz0ERHbuLh2T/7j4Mqqpz523Fe8MVY89KC6Sh/QfS2sM+SjgFDcw==}
|
||||
@@ -11694,7 +11699,7 @@ packages:
|
||||
dependencies:
|
||||
debug: 3.2.7
|
||||
is-core-module: 2.12.1
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
transitivePeerDependencies:
|
||||
- supports-color
|
||||
dev: true
|
||||
@@ -14199,8 +14204,8 @@ packages:
|
||||
engines: {node: '>= 8'}
|
||||
dev: false
|
||||
|
||||
/langchain@0.0.122(ignore@5.2.4):
|
||||
resolution: {integrity: sha512-M/w6CZH+Y12jrts5ENFLpQF3ZzwI6bluubeL0wjyqz/btd8puXsHyyyt58bKg8bIMZF02Y2Tjr1qyqKQKTaJ0Q==}
|
||||
/langchain@0.0.123(ignore@5.2.4):
|
||||
resolution: {integrity: sha512-dMncy/yttMqch11tQUNdygQJlqlKampl8BULFWqZGG1uopzXC1ljqohWpdeLkwAYdKZ7uKcpdaYEXMvhxZsIJQ==}
|
||||
engines: {node: '>=18'}
|
||||
peerDependencies:
|
||||
'@aws-sdk/client-dynamodb': ^3.310.0
|
||||
@@ -15777,7 +15782,7 @@ packages:
|
||||
resolution: {integrity: sha512-/5CMN3T0R4XTj4DcGaexo+roZSdSFW/0AOOTROrjxzCG1wrWXEsGbRKevjlIL+ZDE4sZlJr5ED4YW0yqmkK+eA==}
|
||||
dependencies:
|
||||
hosted-git-info: 2.8.9
|
||||
resolve: 1.22.2
|
||||
resolve: 1.22.3
|
||||
semver: 5.7.1
|
||||
validate-npm-package-license: 3.0.4
|
||||
dev: true
|
||||
@@ -18119,7 +18124,6 @@ packages:
|
||||
is-core-module: 2.12.1
|
||||
path-parse: 1.0.7
|
||||
supports-preserve-symlinks-flag: 1.0.0
|
||||
dev: true
|
||||
|
||||
/responselike@1.0.2:
|
||||
resolution: {integrity: sha512-/Fpe5guzJk1gPqdJLJR5u7eG/gNY4nImjbRDaVWVMRhne55TCmj2i9Q+54PBRfatRC8v/rIiv9BN0pMd9OV5EQ==}
|
||||
@@ -18982,7 +18986,6 @@ packages:
|
||||
/streamsearch@1.1.0:
|
||||
resolution: {integrity: sha512-Mcc5wHehp9aXz1ax6bZUyY5afg9u2rv5cqQI3mRrYkGC8rW2hM02jWuwjtL++LS5qinSyhj2QfLyNsuc+VsExg==}
|
||||
engines: {node: '>=10.0.0'}
|
||||
dev: true
|
||||
|
||||
/strict-event-emitter@0.2.8:
|
||||
resolution: {integrity: sha512-KDf/ujU8Zud3YaLtMCcTI4xkZlZVIYxTLr+XIULexP+77EEVWixeXroLUXQXiVtH4XH2W7jr/3PT1v3zBuvc3A==}
|
||||
@@ -19848,7 +19851,6 @@ packages:
|
||||
engines: {node: '>=14.0'}
|
||||
dependencies:
|
||||
busboy: 1.6.0
|
||||
dev: true
|
||||
|
||||
/unherit@1.1.3:
|
||||
resolution: {integrity: sha512-Ft16BJcnapDKp0+J/rqFC3Rrk6Y/Ng4nzsC028k2jdDII/rdZ7Wd3pPT/6+vIIxRagwRc9K0IUX0Ra4fKvw+WQ==}
|
||||
@@ -20713,7 +20715,6 @@ packages:
|
||||
/web-streams-polyfill@3.2.1:
|
||||
resolution: {integrity: sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==}
|
||||
engines: {node: '>= 8'}
|
||||
dev: true
|
||||
|
||||
/web-streams-polyfill@4.0.0-beta.3:
|
||||
resolution: {integrity: sha512-QW95TCTaHmsYfHDybGMwO5IJIM93I/6vTRk+daHTWFPhwh+C8Cg7j7XyKrwrj8Ib6vYXe0ocYNrmzY4xAAN6ug==}
|
||||
|
||||
Reference in New Issue
Block a user