From 11b49f29ea6ac0d171a4e4aeaec0cc4374de6a7b Mon Sep 17 00:00:00 2001 From: TBXark Date: Sun, 12 Mar 2023 17:43:55 +0800 Subject: [PATCH 01/24] =?UTF-8?q?fix:=20[BUG]SYSTEM=5FINIT=5FMESSAGE=5FROL?= =?UTF-8?q?E=E4=B8=8D=E6=98=AFsystem=E6=97=B6=E5=87=BA=E9=94=99=20#101?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 13 +++++++------ dist/timestamp | 2 +- src/message.js | 21 ++++++++++++++++++--- src/openai.js | 2 +- 5 files changed, 28 insertions(+), 12 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 18a4d4fa..2c558e23 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "94c81f1", "timestamp": 1678546663} +{"sha": "595dca3", "timestamp": 1678614202} diff --git a/dist/index.js b/dist/index.js index 2401a347..d6a93106 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,9 +36,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678546663, + BUILD_TIMESTAMP: 1678614202, // 当前版本 commit id - BUILD_VERSION: "94c81f1", + BUILD_VERSION: "595dca3", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, @@ -388,7 +388,8 @@ async function requestCompletionsFromChatGPT(message, history) { }).then((res) => res.json()); if (resp.error?.message) { throw new Error(`OpenAI API \u9519\u8BEF -> ${resp.error.message}`); +> ${resp.error.message} +\u53C2\u6570: ${JSON.stringify(body)}`); } setTimeout(() => updateBotUsage(resp.usage).catch(console.error), 0); return resp.choices[0].message.content; @@ -1045,11 +1046,11 @@ async function msgChatWithOpenAI(message) { setTimeout(() => sendChatActionToTelegram("typing").catch(console.error), 0); const historyKey = SHARE_CONTEXT.chatHistoryKey; let { real: history, fake: fakeHistory, original } = await loadHistory(historyKey); - history = JSON.parse(JSON.stringify(history)); - history.map((item) => { + const requesthistory = JSON.parse(JSON.stringify(fakeHistory || history)); + requesthistory.map((item) => { item.cosplay = void 0; }); - const answer = await requestCompletionsFromChatGPT(message.text, fakeHistory || history); + const answer = await requestCompletionsFromChatGPT(message.text, requesthistory); if (!historyDisable) { original.push({ role: "user", content: message.text || "", cosplay: SHARE_CONTEXT.ROLE || "" }); original.push({ role: "assistant", content: answer, cosplay: SHARE_CONTEXT.ROLE || "" }); diff --git a/dist/timestamp b/dist/timestamp index 690d0679..b856fae3 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678546663 +1678614202 diff --git a/src/message.js b/src/message.js index 10a45d6e..c9cc7688 100644 --- a/src/message.js +++ b/src/message.js @@ -198,12 +198,12 @@ async function msgChatWithOpenAI(message) { const historyKey = SHARE_CONTEXT.chatHistoryKey; let {real: history, fake: fakeHistory, original: original} = await loadHistory(historyKey); - history = JSON.parse(JSON.stringify(history)); - history.map((item)=>{ + const requesthistory = JSON.parse(JSON.stringify(fakeHistory || history)); + requesthistory.map((item)=>{ item.cosplay=undefined; }); - const answer = await requestCompletionsFromChatGPT(message.text, fakeHistory || history); + const answer = await requestCompletionsFromChatGPT(message.text, requesthistory); if (!historyDisable) { original.push({role: 'user', content: message.text || '', cosplay: SHARE_CONTEXT.ROLE || ''}); original.push({role: 'assistant', content: answer, cosplay: SHARE_CONTEXT.ROLE || ''}); @@ -309,11 +309,16 @@ async function loadMessage(request) { // { real: [], fake: [] } async function loadHistory(key) { + const initMessage = {role: 'system', content: USER_CONFIG.SYSTEM_INIT_MESSAGE}; const historyDisable = ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH <= 0; + + // 判断是否禁用历史记录 if (historyDisable) { return {real: [initMessage], original: [initMessage]}; } + + // 加载历史记录 let history = []; try { history = JSON.parse(await DATABASE.get(key)); @@ -323,12 +328,17 @@ async function loadHistory(key) { if (!history || !Array.isArray(history) || history.length === 0) { history = []; } + + const original = history; + // 按身份过滤 if (SHARE_CONTEXT.ROLE) { history = history.filter((chat) => SHARE_CONTEXT.ROLE === chat.cosplay); } + + // 裁剪 if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { // 历史记录超出长度需要裁剪 if (history.length > ENV.MAX_HISTORY_LENGTH) { @@ -352,6 +362,8 @@ async function loadHistory(key) { } } } + + // 插入init switch (history.length > 0 ? history[0].role : '') { case 'assistant': // 第一条为机器人,替换成init case 'system': // 第一条为system,用新的init替换 @@ -360,6 +372,8 @@ async function loadHistory(key) { default:// 默认给第一条插入init history.unshift(initMessage); } + + // 如果第一条是system,替换role为SYSTEM_INIT_MESSAGE_ROLE if (ENV.SYSTEM_INIT_MESSAGE_ROLE !== 'system' && history.length > 0 && history[0].role === 'system') { const fake = [ ...history, @@ -370,6 +384,7 @@ async function loadHistory(key) { }; return {real: history, fake, original: original}; } + return {real: history, original: original}; } diff --git a/src/openai.js b/src/openai.js index 50121ea7..ae2ca356 100644 --- a/src/openai.js +++ b/src/openai.js @@ -17,7 +17,7 @@ export async function requestCompletionsFromChatGPT(message, history) { body: JSON.stringify(body), }).then((res) => res.json()); if (resp.error?.message) { - throw new Error(`OpenAI API 错误\n> ${resp.error.message}`); + throw new Error(`OpenAI API 错误\n> ${resp.error.message}\n参数: ${JSON.stringify(body)}`); } setTimeout(() => updateBotUsage(resp.usage).catch(console.error), 0); return resp.choices[0].message.content; From a2799e5ff9edc01bd82623266e1ec921b2d06803 Mon Sep 17 00:00:00 2001 From: TBXark Date: Sun, 12 Mar 2023 19:06:31 +0800 Subject: [PATCH 02/24] =?UTF-8?q?fix=EF=BC=9A=20=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=AE=B0=E5=BD=95=E5=8A=A0=E8=BD=BD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 28 +++++++++-------------- dist/timestamp | 2 +- src/message.js | 55 +++++++-------------------------------------- 4 files changed, 20 insertions(+), 67 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 2c558e23..5c02e1ac 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "595dca3", "timestamp": 1678614202} +{"sha": "11b49f2", "timestamp": 1678619122} diff --git a/dist/index.js b/dist/index.js index d6a93106..24aac679 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,9 +36,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678614202, + BUILD_TIMESTAMP: 1678619122, // 当前版本 commit id - BUILD_VERSION: "595dca3", + BUILD_VERSION: "11b49f2", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, @@ -1045,12 +1045,8 @@ async function msgChatWithOpenAI(message) { const historyDisable = ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH <= 0; setTimeout(() => sendChatActionToTelegram("typing").catch(console.error), 0); const historyKey = SHARE_CONTEXT.chatHistoryKey; - let { real: history, fake: fakeHistory, original } = await loadHistory(historyKey); - const requesthistory = JSON.parse(JSON.stringify(fakeHistory || history)); - requesthistory.map((item) => { - item.cosplay = void 0; - }); - const answer = await requestCompletionsFromChatGPT(message.text, requesthistory); + let { real: history, original } = await loadHistory(historyKey); + const answer = await requestCompletionsFromChatGPT(message.text, history); if (!historyDisable) { original.push({ role: "user", content: message.text || "", cosplay: SHARE_CONTEXT.ROLE || "" }); original.push({ role: "assistant", content: answer, cosplay: SHARE_CONTEXT.ROLE || "" }); @@ -1131,13 +1127,16 @@ async function loadHistory(key) { } catch (e) { console.error(e); } - if (!history || !Array.isArray(history) || history.length === 0) { + if (!history || !Array.isArray(history)) { history = []; } - const original = history; + const original = JSON.parse(JSON.stringify(history)); if (SHARE_CONTEXT.ROLE) { history = history.filter((chat) => SHARE_CONTEXT.ROLE === chat.cosplay); } + history.forEach((item) => { + delete item.cosplay; + }); if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { if (history.length > ENV.MAX_HISTORY_LENGTH) { history = history.splice(history.length - ENV.MAX_HISTORY_LENGTH); @@ -1167,14 +1166,7 @@ async function loadHistory(key) { history.unshift(initMessage); } if (ENV.SYSTEM_INIT_MESSAGE_ROLE !== "system" && history.length > 0 && history[0].role === "system") { - const fake = [ - ...history - ]; - fake[0] = { - ...fake[0], - role: ENV.SYSTEM_INIT_MESSAGE_ROLE - }; - return { real: history, fake, original }; + history[0].role = ENV.SYSTEM_INIT_MESSAGE_ROLE; } return { real: history, original }; } diff --git a/dist/timestamp b/dist/timestamp index b856fae3..d4bee376 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678614202 +1678619122 diff --git a/src/message.js b/src/message.js index c9cc7688..1f655401 100644 --- a/src/message.js +++ b/src/message.js @@ -196,34 +196,14 @@ async function msgChatWithOpenAI(message) { const historyDisable = ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH <= 0; setTimeout(() => sendChatActionToTelegram('typing').catch(console.error), 0); const historyKey = SHARE_CONTEXT.chatHistoryKey; - let {real: history, fake: fakeHistory, original: original} = await loadHistory(historyKey); + let {real: history, original: original} = await loadHistory(historyKey); - const requesthistory = JSON.parse(JSON.stringify(fakeHistory || history)); - requesthistory.map((item)=>{ - item.cosplay=undefined; - }); - - const answer = await requestCompletionsFromChatGPT(message.text, requesthistory); + const answer = await requestCompletionsFromChatGPT(message.text, history); if (!historyDisable) { original.push({role: 'user', content: message.text || '', cosplay: SHARE_CONTEXT.ROLE || ''}); original.push({role: 'assistant', content: answer, cosplay: SHARE_CONTEXT.ROLE || ''}); await DATABASE.put(historyKey, JSON.stringify(original)).catch(console.error); } - /* inline keyboard 实验性代码 */ - // if (SHARE_CONTEXT.chatType && ENV.INLINE_KEYBOARD_ENABLE.includes(SHARE_CONTEXT.chatType)) { - // const replyMarkup = { }; - // replyMarkup.inline_keyboard = [[ - // { - // text: '继续', - // callback_data: `#continue`, - // }, - // { - // text: '结束', - // callback_data: `#end`, - // }, - // ]]; - // CURRENT_CHAT_CONTEXT.reply_markup = replyMarkup; - // } return sendMessageToTelegram(answer); } catch (e) { return sendMessageToTelegram(`ERROR:CHAT: ${e.message}`); @@ -287,21 +267,6 @@ async function loadMessage(request) { return raw.message; } else if (raw.callback_query && raw.callback_query.message) { return null; - /* inline keyboard 实验性代码 */ - // const messageId = raw.callback_query.message?.message_id; - // const chatId = raw.callback_query.message?.chat?.id; - // const data = raw.callback_query.data; - - // if (data.startsWith('#continue')) { - // raw.callback_query.message.text = '继续'; - // } else if (data.startsWith('#end')) { - // raw.callback_query.message.text = '/new'; - // } - // if (messageId && chatId) { - // setTimeout(() => deleteMessageInlineKeyboard(chatId, messageId).catch(console.error), 0); - // } - // SHARE_CONTEXT.fromInlineKeyboard = true; - // return raw.callback_query.message; } else { throw new Error('Invalid message'); } @@ -325,18 +290,21 @@ async function loadHistory(key) { } catch (e) { console.error(e); } - if (!history || !Array.isArray(history) || history.length === 0) { + if (!history || !Array.isArray(history)) { history = []; } - const original = history; + const original = JSON.parse(JSON.stringify(history)); // 按身份过滤 if (SHARE_CONTEXT.ROLE) { history = history.filter((chat) => SHARE_CONTEXT.ROLE === chat.cosplay); } + history.forEach((item)=>{ + delete item.cosplay; + }); // 裁剪 if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { @@ -375,14 +343,7 @@ async function loadHistory(key) { // 如果第一条是system,替换role为SYSTEM_INIT_MESSAGE_ROLE if (ENV.SYSTEM_INIT_MESSAGE_ROLE !== 'system' && history.length > 0 && history[0].role === 'system') { - const fake = [ - ...history, - ]; - fake[0] = { - ...fake[0], - role: ENV.SYSTEM_INIT_MESSAGE_ROLE, - }; - return {real: history, fake, original: original}; + history[0].role = ENV.SYSTEM_INIT_MESSAGE_ROLE; } return {real: history, original: original}; From ab351db856f84f3fd1486f1d34d5c4b5bc082cfc Mon Sep 17 00:00:00 2001 From: TBXark Date: Sun, 12 Mar 2023 12:33:16 +0000 Subject: [PATCH 03/24] =?UTF-8?q?fix:=20original=20=E5=8E=86=E5=8F=B2?= =?UTF-8?q?=E8=A3=81=E5=89=AA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 29 ++++++++++++++++++----------- dist/timestamp | 2 +- src/message.js | 30 +++++++++++++++++++----------- 4 files changed, 39 insertions(+), 24 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 5c02e1ac..a9a61d57 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "11b49f2", "timestamp": 1678619122} +{"sha": "a2799e5", "timestamp": 1678624357} diff --git a/dist/index.js b/dist/index.js index 24aac679..03968022 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,9 +36,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678619122, + BUILD_TIMESTAMP: 1678624357, // 当前版本 commit id - BUILD_VERSION: "11b49f2", + BUILD_VERSION: "a2799e5", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, @@ -1130,20 +1130,20 @@ async function loadHistory(key) { if (!history || !Array.isArray(history)) { history = []; } - const original = JSON.parse(JSON.stringify(history)); + let original = JSON.parse(JSON.stringify(history)); if (SHARE_CONTEXT.ROLE) { history = history.filter((chat) => SHARE_CONTEXT.ROLE === chat.cosplay); } history.forEach((item) => { delete item.cosplay; }); - if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { - if (history.length > ENV.MAX_HISTORY_LENGTH) { - history = history.splice(history.length - ENV.MAX_HISTORY_LENGTH); + const trimHistory = (list, initLength, maxLength, maxToken) => { + if (list.length > maxLength) { + list = list.splice(list.length - maxLength); } - let tokenLength = Array.from(initMessage.content).length; - for (let i = history.length - 1; i >= 0; i--) { - const historyItem = history[i]; + let tokenLength = initLength; + for (let i = list.length - 1; i >= 0; i--) { + const historyItem = list[i]; let length = 0; if (historyItem.content) { length = Array.from(historyItem.content).length; @@ -1151,11 +1151,18 @@ async function loadHistory(key) { historyItem.content = ""; } tokenLength += length; - if (tokenLength > MAX_TOKEN_LENGTH) { - history = history.splice(i + 1); + if (tokenLength > maxToken) { + list = list.splice(i + 1); break; } } + return list; + }; + if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { + let initLength = Array.from(initMessage.content).length; + const roleCount = Math.max(Object.keys(USER_CONFIG.ROLES).length, 1); + history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, MAX_TOKEN_LENGTH); + original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, MAX_TOKEN_LENGTH * roleCount); } switch (history.length > 0 ? history[0].role : "") { case "assistant": diff --git a/dist/timestamp b/dist/timestamp index d4bee376..3cbf1c80 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678619122 +1678624357 diff --git a/src/message.js b/src/message.js index 1f655401..49c5fd3b 100644 --- a/src/message.js +++ b/src/message.js @@ -295,27 +295,26 @@ async function loadHistory(key) { } - const original = JSON.parse(JSON.stringify(history)); + let original = JSON.parse(JSON.stringify(history)); // 按身份过滤 if (SHARE_CONTEXT.ROLE) { history = history.filter((chat) => SHARE_CONTEXT.ROLE === chat.cosplay); } - history.forEach((item)=>{ delete item.cosplay; }); - // 裁剪 - if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { + + const trimHistory = (list, initLength, maxLength, maxToken) => { // 历史记录超出长度需要裁剪 - if (history.length > ENV.MAX_HISTORY_LENGTH) { - history = history.splice(history.length - ENV.MAX_HISTORY_LENGTH); + if (list.length > maxLength) { + list = list.splice(list.length - maxLength); } // 处理token长度问题 - let tokenLength = Array.from(initMessage.content).length; - for (let i = history.length - 1; i >= 0; i--) { - const historyItem = history[i]; + let tokenLength = initLength + for (let i = list.length - 1; i >= 0; i--) { + const historyItem = list[i]; let length = 0; if (historyItem.content) { length = Array.from(historyItem.content).length; @@ -324,11 +323,20 @@ async function loadHistory(key) { } // 如果最大长度超过maxToken,裁剪history tokenLength += length; - if (tokenLength > MAX_TOKEN_LENGTH) { - history = history.splice(i + 1); + if (tokenLength > maxToken) { + list = list.splice(i + 1); break; } } + return list; + } + + // 裁剪 + if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { + let initLength = Array.from(initMessage.content).length; + const roleCount = Math.max(Object.keys(USER_CONFIG.ROLES).length, 1); + history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, MAX_TOKEN_LENGTH); + original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, MAX_TOKEN_LENGTH* roleCount); } // 插入init From 8294a60bb0fadb7f69695bbd6be8b3da3ddf20fa Mon Sep 17 00:00:00 2001 From: cheivin Date: Sun, 12 Mar 2023 20:50:45 +0800 Subject: [PATCH 04/24] =?UTF-8?q?fix:=20roleCount=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/message.js | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/message.js b/src/message.js index 49c5fd3b..eb2c5113 100644 --- a/src/message.js +++ b/src/message.js @@ -196,7 +196,7 @@ async function msgChatWithOpenAI(message) { const historyDisable = ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH <= 0; setTimeout(() => sendChatActionToTelegram('typing').catch(console.error), 0); const historyKey = SHARE_CONTEXT.chatHistoryKey; - let {real: history, original: original} = await loadHistory(historyKey); + const {real: history, original: original} = await loadHistory(historyKey); const answer = await requestCompletionsFromChatGPT(message.text, history); if (!historyDisable) { @@ -274,10 +274,9 @@ async function loadMessage(request) { // { real: [], fake: [] } async function loadHistory(key) { - const initMessage = {role: 'system', content: USER_CONFIG.SYSTEM_INIT_MESSAGE}; const historyDisable = ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH <= 0; - + // 判断是否禁用历史记录 if (historyDisable) { return {real: [initMessage], original: [initMessage]}; @@ -312,7 +311,7 @@ async function loadHistory(key) { list = list.splice(list.length - maxLength); } // 处理token长度问题 - let tokenLength = initLength + let tokenLength = initLength; for (let i = list.length - 1; i >= 0; i--) { const historyItem = list[i]; let length = 0; @@ -329,12 +328,12 @@ async function loadHistory(key) { } } return list; - } + }; // 裁剪 if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { - let initLength = Array.from(initMessage.content).length; - const roleCount = Math.max(Object.keys(USER_CONFIG.ROLES).length, 1); + const initLength = Array.from(initMessage.content).length; + const roleCount = Math.max(Object.keys(USER_DEFINE.ROLE).length, 1); history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, MAX_TOKEN_LENGTH); original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, MAX_TOKEN_LENGTH* roleCount); } From 102dd427fca753289bb9b58845659a394541c8d9 Mon Sep 17 00:00:00 2001 From: cheivin Date: Sun, 12 Mar 2023 23:10:32 +0800 Subject: [PATCH 05/24] =?UTF-8?q?fix:=20=E4=BB=A5=E4=B8=80=E7=A7=8D?= =?UTF-8?q?=E7=AE=80=E5=8D=95=E7=B2=97=E6=9A=B4=E7=9A=84=E6=96=B9=E5=BC=8F?= =?UTF-8?q?=E4=BF=AE=E5=A4=8Dedit=E6=B6=88=E6=81=AF=E7=9A=84bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 16 +++++++++------- dist/timestamp | 2 +- src/message.js | 6 ++++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index a9a61d57..7335293c 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "a2799e5", "timestamp": 1678624357} +{"sha": "8294a60", "timestamp": 1678633795} diff --git a/dist/index.js b/dist/index.js index 03968022..b92c35fc 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,9 +36,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678624357, + BUILD_TIMESTAMP: 1678633795, // 当前版本 commit id - BUILD_VERSION: "a2799e5", + BUILD_VERSION: "8294a60", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, @@ -1045,7 +1045,7 @@ async function msgChatWithOpenAI(message) { const historyDisable = ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH <= 0; setTimeout(() => sendChatActionToTelegram("typing").catch(console.error), 0); const historyKey = SHARE_CONTEXT.chatHistoryKey; - let { real: history, original } = await loadHistory(historyKey); + const { real: history, original } = await loadHistory(historyKey); const answer = await requestCompletionsFromChatGPT(message.text, history); if (!historyDisable) { original.push({ role: "user", content: message.text || "", cosplay: SHARE_CONTEXT.ROLE || "" }); @@ -1107,10 +1107,12 @@ async function loadMessage(request) { DATABASE.put(`log:${(/* @__PURE__ */ new Date()).toISOString()}`, JSON.stringify(raw), { expirationTtl: 600 }).catch(console.error); }); } + if (raw.edited_message) { + raw.message = raw.edited_message; + SHARE_CONTEXT.editChat = true; + } if (raw.message) { return raw.message; - } else if (raw.callback_query && raw.callback_query.message) { - return null; } else { throw new Error("Invalid message"); } @@ -1159,8 +1161,8 @@ async function loadHistory(key) { return list; }; if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { - let initLength = Array.from(initMessage.content).length; - const roleCount = Math.max(Object.keys(USER_CONFIG.ROLES).length, 1); + const initLength = Array.from(initMessage.content).length; + const roleCount = Math.max(Object.keys(USER_DEFINE.ROLE).length, 1); history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, MAX_TOKEN_LENGTH); original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, MAX_TOKEN_LENGTH * roleCount); } diff --git a/dist/timestamp b/dist/timestamp index 3cbf1c80..f4616895 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678624357 +1678633795 diff --git a/src/message.js b/src/message.js index eb2c5113..acef7315 100644 --- a/src/message.js +++ b/src/message.js @@ -263,10 +263,12 @@ async function loadMessage(request) { DATABASE.put(`log:${new Date().toISOString()}`, JSON.stringify(raw), {expirationTtl: 600}).catch(console.error); }); } + if (raw.edited_message) { + raw.message = raw.edited_message; + SHARE_CONTEXT.editChat = true; + } if (raw.message) { return raw.message; - } else if (raw.callback_query && raw.callback_query.message) { - return null; } else { throw new Error('Invalid message'); } From 4c7043cb82f6dd4b456ab2dadacae0a7ced1e6ac Mon Sep 17 00:00:00 2001 From: TBXark Date: Mon, 13 Mar 2023 12:19:00 +0800 Subject: [PATCH 06/24] =?UTF-8?q?feat:=20=E4=BD=BF=E7=94=A8=20latitudegame?= =?UTF-8?q?s/GPT-3-Encoder=20=E7=AE=97=E6=B3=95=E8=AE=A1=E7=AE=97=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E4=B8=B2token=E6=95=B0=E9=87=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 230 ++++++++++++++++++++++++++++++++++++++++++-- dist/timestamp | 2 +- src/command.js | 2 +- src/env.js | 2 + src/gpt3.js | 230 ++++++++++++++++++++++++++++++++++++++++++++ src/message.js | 5 +- src/router.js | 21 +++- src/utils.js | 15 ++- 9 files changed, 496 insertions(+), 13 deletions(-) create mode 100644 src/gpt3.js diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 7335293c..b30bfbaf 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "8294a60", "timestamp": 1678633795} +{"sha": "102dd42", "timestamp": 1678680858} diff --git a/dist/index.js b/dist/index.js index b92c35fc..3b228be3 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,14 +36,15 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678633795, + BUILD_TIMESTAMP: 1678680858, // 当前版本 commit id - BUILD_VERSION: "8294a60", + BUILD_VERSION: "102dd42", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, // 开发模式 DEV_MODE: false, + GPT3_TOKENS_COUNT: false, // Inline keyboard: 实验性功能请勿开启 INLINE_KEYBOARD_ENABLE: [], TELEGRAM_API_DOMAIN: "https://api.telegram.org", @@ -51,7 +52,8 @@ var ENV = { }; var CONST = { PASSWORD_KEY: "chat_history_password", - GROUP_TYPES: ["group", "supergroup"] + GROUP_TYPES: ["group", "supergroup"], + USER_AGENT: "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Safari/605.1.15" }; var DATABASE = null; function initEnv(env) { @@ -730,7 +732,7 @@ async function commandUpdateUserConfig(message, command, subcommand) { async function commandFetchUpdate(message, command, subcommand) { const config = { headers: { - "User-Agent": "TBXark/ChatGPT-Telegram-Workers" + "User-Agent": CONST.USER_AGENT } }; const current = { @@ -896,6 +898,198 @@ function commandsDocument() { }); } +// src/gpt3.js +async function encoderLoader() { + const key = "encoder_raw_file"; + try { + const raw = await DATABASE.get(key); + if (raw && raw !== "") { + return JSON.parse(raw); + } + } catch (e) { + console.error(e); + } + try { + const encoder = await fetch("https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master/encoder.json", { + headers: { + "User-Agent": CONST.USER_AGENT + } + }).then((x) => x.json()); + await DATABASE.put(key, JSON.stringify(encoder)); + return encoder; + } catch (e) { + console.error(e); + } + return null; +} +async function bpeFileLoader() { + const key = "bpe_raw_file"; + try { + const raw = await DATABASE.get(key); + if (raw && raw !== "") { + return raw; + } + } catch (e) { + console.error(e); + } + try { + const bpe = await fetch("https://raw.githubusercontent.com/latitudegames/GPT-3-Encoder/master/vocab.bpe", { + headers: { + "User-Agent": CONST.USER_AGENT + } + }).then((x) => x.text()); + await DATABASE.put(key, bpe); + return bpe; + } catch (e) { + console.error(e); + } + return null; +} +async function gpt3TokensCounter() { + console.log("gpt3TokensCounter loading..."); + const encoder = await encoderLoader(); + const bpe_file = await bpeFileLoader(); + if (encoder === null || bpe_file === null) { + return (text) => { + return Array.from(text).length; + }; + } + const range = (x, y) => { + const res = Array.from(Array(y).keys()).slice(x); + return res; + }; + const ord = (x) => { + return x.charCodeAt(0); + }; + const chr = (x) => { + return String.fromCharCode(x); + }; + const textEncoder = new TextEncoder("utf-8"); + const encodeStr = (str) => { + return Array.from(textEncoder.encode(str)).map((x) => x.toString()); + }; + const dictZip = (x, y) => { + const result = {}; + x.map((_, i) => { + result[x[i]] = y[i]; + }); + return result; + }; + function bytes_to_unicode() { + const bs = range(ord("!"), ord("~") + 1).concat(range(ord("\xA1"), ord("\xAC") + 1), range(ord("\xAE"), ord("\xFF") + 1)); + let cs = bs.slice(); + let n = 0; + for (let b = 0; b < 2 ** 8; b++) { + if (!bs.includes(b)) { + bs.push(b); + cs.push(2 ** 8 + n); + n = n + 1; + } + } + cs = cs.map((x) => chr(x)); + const result = {}; + bs.map((_, i) => { + result[bs[i]] = cs[i]; + }); + return result; + } + function get_pairs(word) { + const pairs = /* @__PURE__ */ new Set(); + let prev_char = word[0]; + for (let i = 1; i < word.length; i++) { + const char = word[i]; + pairs.add([prev_char, char]); + prev_char = char; + } + return pairs; + } + const pat = /'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu; + const decoder = {}; + Object.keys(encoder).map((x) => { + decoder[encoder[x]] = x; + }); + const lines = bpe_file.split("\n"); + const bpe_merges = lines.slice(1, lines.length - 1).map((x) => { + return x.split(/(\s+)/).filter(function(e) { + return e.trim().length > 0; + }); + }); + const byte_encoder = bytes_to_unicode(); + const byte_decoder = {}; + Object.keys(byte_encoder).map((x) => { + byte_decoder[byte_encoder[x]] = x; + }); + const bpe_ranks = dictZip(bpe_merges, range(0, bpe_merges.length)); + const cache = /* @__PURE__ */ new Map(); + function bpe(token) { + if (cache.has(token)) { + return cache.get(token); + } + ``; + let word = token.split(""); + let pairs = get_pairs(word); + if (!pairs) { + return token; + } + while (true) { + const minPairs = {}; + Array.from(pairs).map((pair) => { + const rank = bpe_ranks[pair]; + minPairs[isNaN(rank) ? 1e11 : rank] = pair; + }); + const bigram = minPairs[Math.min(...Object.keys(minPairs).map( + (x) => { + return parseInt(x); + } + ))]; + if (!(bigram in bpe_ranks)) { + break; + } + const first = bigram[0]; + const second = bigram[1]; + let new_word = []; + let i = 0; + while (i < word.length) { + const j = word.indexOf(first, i); + if (j === -1) { + new_word = new_word.concat(word.slice(i)); + break; + } + new_word = new_word.concat(word.slice(i, j)); + i = j; + if (word[i] === first && i < word.length - 1 && word[i + 1] === second) { + new_word.push(first + second); + i = i + 2; + } else { + new_word.push(word[i]); + i = i + 1; + } + } + word = new_word; + if (word.length === 1) { + break; + } else { + pairs = get_pairs(word); + } + } + word = word.join(" "); + cache.set(token, word); + return word; + } + return function tokenCount(text) { + let tokensCount = 0; + const matches = Array.from(text.matchAll(pat)).map((x) => x[0]); + for (let token of matches) { + token = encodeStr(token).map((x) => { + return byte_encoder[x]; + }).join(""); + const new_tokens = bpe(token).split(" ").map((x) => encoder[x]); + tokensCount += new_tokens.length; + } + return tokensCount; + }; +} + // src/message.js var MAX_TOKEN_LENGTH = 2048; async function msgInitChatContext(message) { @@ -1139,6 +1333,14 @@ async function loadHistory(key) { history.forEach((item) => { delete item.cosplay; }); + let counter = (text) => Array.from(text).length; + try { + if (ENV.GPT3_TOKENS_COUNT) { + counter = await gpt3TokensCounter(); + } + } catch (e) { + console.error(e); + } const trimHistory = (list, initLength, maxLength, maxToken) => { if (list.length > maxLength) { list = list.splice(list.length - maxLength); @@ -1148,7 +1350,7 @@ async function loadHistory(key) { const historyItem = list[i]; let length = 0; if (historyItem.content) { - length = Array.from(historyItem.content).length; + length = counter(historyItem.content); } else { historyItem.content = ""; } @@ -1254,7 +1456,7 @@ async function loadChatHistory(request) { if (passwordParam !== password) { return new Response("Password Error", { status: 401 }); } - const history = await DATABASE.get(historyKey).then((res) => JSON.parse(res)); + const history = JSON.parse(await DATABASE.get(historyKey)); const HTML = renderHTML(`
${history.map((item) => ` @@ -1290,6 +1492,19 @@ async function defaultIndexAction() { `); return new Response(HTML, { status: 200, headers: { "Content-Type": "text/html" } }); } +async function gpt3TokenTest(request) { + const text = new URL(request.url).searchParams.get("text") || "Hello World"; + const counter = await gpt3TokensCounter(); + const HTML = renderHTML(` +

ChatGPT-Telegram-Workers

+
+

Token Counter:

+

source text: ${text}

+

token count: ${counter(text)}

+
+ `); + return new Response(HTML, { status: 200, headers: { "Content-Type": "text/html" } }); +} async function loadBotInfo() { const result = []; for (const token of ENV.TELEGRAM_AVAILABLE_TOKENS) { @@ -1320,6 +1535,9 @@ async function handleRequest(request) { if (pathname.startsWith(`/init`)) { return bindWebHookAction(request); } + if (pathname.startsWith(`/gpt3/tokens/test`)) { + return gpt3TokenTest(request); + } if (pathname.startsWith(`/telegram`) && pathname.endsWith(`/history`)) { return loadChatHistory(request); } diff --git a/dist/timestamp b/dist/timestamp index f4616895..bf7330e2 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678633795 +1678680858 diff --git a/src/command.js b/src/command.js index b79dfa78..57253d57 100644 --- a/src/command.js +++ b/src/command.js @@ -230,7 +230,7 @@ async function commandUpdateUserConfig(message, command, subcommand) { async function commandFetchUpdate(message, command, subcommand) { const config = { headers: { - 'User-Agent': 'TBXark/ChatGPT-Telegram-Workers', + 'User-Agent': CONST.USER_AGENT, }, }; const current = { diff --git a/src/env.js b/src/env.js index e5436348..c447aa25 100644 --- a/src/env.js +++ b/src/env.js @@ -51,6 +51,7 @@ export const ENV = { DEBUG_MODE: false, // 开发模式 DEV_MODE: false, + GPT3_TOKENS_COUNT: false, // Inline keyboard: 实验性功能请勿开启 INLINE_KEYBOARD_ENABLE: [], TELEGRAM_API_DOMAIN: 'https://api.telegram.org', @@ -60,6 +61,7 @@ export const ENV = { export const CONST = { PASSWORD_KEY: 'chat_history_password', GROUP_TYPES: ['group', 'supergroup'], + USER_AGENT: 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/16.2 Safari/605.1.15', }; export let DATABASE = null; diff --git a/src/gpt3.js b/src/gpt3.js new file mode 100644 index 00000000..c485b90d --- /dev/null +++ b/src/gpt3.js @@ -0,0 +1,230 @@ +/* eslint-disable camelcase */ +// https://github.com/latitudegames/GPT-3-Encoder + +import {CONST, DATABASE} from './env'; + +async function encoderLoader() { + const key = 'encoder_raw_file'; + try { + const raw = await DATABASE.get(key); + if (raw && raw !== '') { + return JSON.parse(raw); + } + } catch (e) { + console.error(e); + } + try { + const encoder = await fetch('https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master/encoder.json', { + headers: { + 'User-Agent': CONST.USER_AGENT, + }, + }).then((x) => x.json()); + await DATABASE.put(key, JSON.stringify(encoder)); + return encoder; + } catch (e) { + console.error(e); + } + return null; +} + +async function bpeFileLoader() { + const key = 'bpe_raw_file'; + try { + const raw = await DATABASE.get(key); + if (raw && raw !== '') { + return raw; + } + } catch (e) { + console.error(e); + } + try { + const bpe = await fetch('https://raw.githubusercontent.com/latitudegames/GPT-3-Encoder/master/vocab.bpe', { + headers: { + 'User-Agent': CONST.USER_AGENT, + }, + }).then((x) => x.text()); + await DATABASE.put(key, bpe); + return bpe; + } catch (e) { + console.error(e); + } + return null; +} + +export async function gpt3TokensCounter() { + console.log('gpt3TokensCounter loading...'); + const encoder = await encoderLoader(); + const bpe_file = await bpeFileLoader(); + + if (encoder === null || bpe_file === null) { + return (text) => { + return Array.from(text).length; + }; + } + + const range = (x, y) => { + const res = Array.from(Array(y).keys()).slice(x); + return res; + }; + + const ord = (x) => { + return x.charCodeAt(0); + }; + + const chr = (x) => { + return String.fromCharCode(x); + }; + + const textEncoder = new TextEncoder('utf-8'); + const encodeStr = (str) => { + return Array.from(textEncoder.encode(str)).map((x) => x.toString()); + }; + + const dictZip = (x, y) => { + const result = {}; + x.map((_, i) => { + result[x[i]] = y[i]; + }); + return result; + }; + + function bytes_to_unicode() { + const bs = range(ord('!'), ord('~') + 1).concat(range(ord('¡'), ord('¬') + 1), range(ord('®'), ord('ÿ') + 1)); + + let cs = bs.slice(); + let n = 0; + for (let b = 0; b < 2 ** 8; b++) { + if (!bs.includes(b)) { + bs.push(b); + cs.push(2 ** 8 + n); + n = n + 1; + } + } + + cs = cs.map((x) => chr(x)); + + const result = {}; + bs.map((_, i) => { + result[bs[i]] = cs[i]; + }); + return result; + } + + function get_pairs(word) { + const pairs = new Set(); + let prev_char = word[0]; + for (let i = 1; i < word.length; i++) { + const char = word[i]; + pairs.add([prev_char, char]); + prev_char = char; + } + return pairs; + } + + const pat = /'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu; + + const decoder = {}; + Object.keys(encoder).map((x) => { + decoder[encoder[x]] = x; + }); + + const lines = bpe_file.split('\n'); + + // bpe_merges = [tuple(merge_str.split()) for merge_str in bpe_data.split("\n")[1:-1]] + const bpe_merges = lines.slice(1, lines.length - 1).map((x) => { + return x.split(/(\s+)/).filter(function(e) { + return e.trim().length > 0; + }); + }); + + const byte_encoder = bytes_to_unicode(); + const byte_decoder = {}; + Object.keys(byte_encoder).map((x) => { + byte_decoder[byte_encoder[x]] = x; + }); + + const bpe_ranks = dictZip(bpe_merges, range(0, bpe_merges.length)); + const cache = new Map; + + function bpe(token) { + if (cache.has(token)) { + return cache.get(token); + }``; + + let word = token.split(''); + + let pairs = get_pairs(word); + + if (!pairs) { + return token; + } + + while (true) { + const minPairs = {}; + Array.from(pairs).map((pair) => { + const rank = bpe_ranks[pair]; + minPairs[(isNaN(rank) ? 10e10 : rank)] = pair; + }); + + + const bigram = minPairs[Math.min(...Object.keys(minPairs).map((x) => { + return parseInt(x); + }, + ))]; + + if (!(bigram in bpe_ranks)) { + break; + } + + const first = bigram[0]; + const second = bigram[1]; + let new_word = []; + let i = 0; + + while (i < word.length) { + const j = word.indexOf(first, i); + if (j === -1) { + new_word = new_word.concat(word.slice(i)); + break; + } + new_word = new_word.concat(word.slice(i, j)); + i = j; + + if (word[i] === first && i < word.length - 1 && word[i + 1] === second) { + new_word.push(first + second); + i = i + 2; + } else { + new_word.push(word[i]); + i = i + 1; + } + } + + word = new_word; + if (word.length === 1) { + break; + } else { + pairs = get_pairs(word); + } + } + + word = word.join(' '); + cache.set(token, word); + + return word; + } + + + return function tokenCount(text) { + let tokensCount = 0; + const matches = Array.from(text.matchAll(pat)).map((x) => x[0]); + for (let token of matches) { + token = encodeStr(token).map((x) => { + return byte_encoder[x]; + }).join(''); + + const new_tokens = bpe(token).split(' ').map((x) => encoder[x]); + tokensCount += new_tokens.length; + } + return tokensCount; + }; +} diff --git a/src/message.js b/src/message.js index acef7315..590c2007 100644 --- a/src/message.js +++ b/src/message.js @@ -3,7 +3,7 @@ import {SHARE_CONTEXT, USER_CONFIG, USER_DEFINE, CURRENT_CHAT_CONTEXT, initConte import {sendMessageToTelegram, sendChatActionToTelegram} from './telegram.js'; import {requestCompletionsFromChatGPT} from './openai.js'; import {handleCommandMessage} from './command.js'; -import {errorToString} from './utils.js'; +import {errorToString, tokensCounter} from './utils.js'; const MAX_TOKEN_LENGTH = 2048; @@ -306,6 +306,7 @@ async function loadHistory(key) { delete item.cosplay; }); + const counter = await tokensCounter(); const trimHistory = (list, initLength, maxLength, maxToken) => { // 历史记录超出长度需要裁剪 @@ -318,7 +319,7 @@ async function loadHistory(key) { const historyItem = list[i]; let length = 0; if (historyItem.content) { - length = Array.from(historyItem.content).length; + length = counter(historyItem.content); } else { historyItem.content = ''; } diff --git a/src/router.js b/src/router.js index 6ae207e5..679b2d36 100644 --- a/src/router.js +++ b/src/router.js @@ -3,6 +3,7 @@ import {DATABASE, ENV} from './env.js'; import {bindCommandForTelegram, commandsDocument} from './command.js'; import {bindTelegramWebHook, getBot} from './telegram.js'; import {errorToString, historyPassword, renderHTML} from './utils.js'; +import {gpt3TokensCounter} from './gpt3.js'; const helpLink = 'https://github.com/TBXark/ChatGPT-Telegram-Workers/blob/master/DEPLOY.md'; @@ -60,7 +61,7 @@ async function loadChatHistory(request) { if (passwordParam !== password) { return new Response('Password Error', {status: 401}); } - const history = await DATABASE.get(historyKey).then((res) => JSON.parse(res)); + const history = JSON.parse(await DATABASE.get(historyKey)); const HTML = renderHTML(`
${history.map((item) => ` @@ -104,6 +105,21 @@ async function defaultIndexAction() { return new Response(HTML, {status: 200, headers: {'Content-Type': 'text/html'}}); } +async function gpt3TokenTest(request) { + // from query + const text = new URL(request.url).searchParams.get('text') || 'Hello World'; + const counter = await gpt3TokensCounter(); + const HTML = renderHTML(` +

ChatGPT-Telegram-Workers

+
+

Token Counter:

+

source text: ${text}

+

token count: ${counter((text))}

+
+ `); + return new Response(HTML, {status: 200, headers: {'Content-Type': 'text/html'}}); +} + async function loadBotInfo() { const result = []; for (const token of ENV.TELEGRAM_AVAILABLE_TOKENS) { @@ -137,6 +153,9 @@ export async function handleRequest(request) { if (pathname.startsWith(`/init`)) { return bindWebHookAction(request); } + if (pathname.startsWith(`/gpt3/tokens/test`)) { + return gpt3TokenTest(request); + } if (pathname.startsWith(`/telegram`) && pathname.endsWith(`/history`)) { return loadChatHistory(request); } diff --git a/src/utils.js b/src/utils.js index c90ef293..10b65fed 100644 --- a/src/utils.js +++ b/src/utils.js @@ -1,4 +1,5 @@ -import {CONST, DATABASE} from './env.js'; +import {CONST, DATABASE, ENV} from './env.js'; +import {gpt3TokensCounter} from './gpt3.js'; export function randomString(length) { const chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; @@ -95,3 +96,15 @@ export function mergeConfig(config, key, value) { throw new Error('不支持的配置项或数据类型错误'); } } + +export async function tokensCounter() { + let counter = (text) => Array.from(text).length; + try { + if (ENV.GPT3_TOKENS_COUNT) { + counter = await gpt3TokensCounter(); + } + } catch (e) { + console.error(e); + } + return counter; +} From 318ad8e9504123c8d8dc888d0583756410dec2cc Mon Sep 17 00:00:00 2001 From: TBXark Date: Mon, 13 Mar 2023 12:27:50 +0800 Subject: [PATCH 07/24] =?UTF-8?q?feat:=20=E5=A2=9E=E5=8A=A0tokensCounter?= =?UTF-8?q?=20=E5=AE=89=E5=85=A8=E6=80=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 410 ++++++++++++++++++++++---------------------- dist/timestamp | 2 +- src/gpt3.js | 6 - src/utils.js | 9 +- 5 files changed, 218 insertions(+), 211 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index b30bfbaf..30a0512a 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "102dd42", "timestamp": 1678680858} +{"sha": "4c7043c", "timestamp": 1678681547} diff --git a/dist/index.js b/dist/index.js index 3b228be3..c7db122f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -36,9 +36,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678680858, + BUILD_TIMESTAMP: 1678681547, // 当前版本 commit id - BUILD_VERSION: "102dd42", + BUILD_VERSION: "4c7043c", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, @@ -438,6 +438,193 @@ async function updateBotUsage(usage) { await DATABASE.put(SHARE_CONTEXT.usageKey, JSON.stringify(dbValue)); } +// src/gpt3.js +async function encoderLoader() { + const key = "encoder_raw_file"; + try { + const raw = await DATABASE.get(key); + if (raw && raw !== "") { + return JSON.parse(raw); + } + } catch (e) { + console.error(e); + } + try { + const encoder = await fetch("https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master/encoder.json", { + headers: { + "User-Agent": CONST.USER_AGENT + } + }).then((x) => x.json()); + await DATABASE.put(key, JSON.stringify(encoder)); + return encoder; + } catch (e) { + console.error(e); + } + return null; +} +async function bpeFileLoader() { + const key = "bpe_raw_file"; + try { + const raw = await DATABASE.get(key); + if (raw && raw !== "") { + return raw; + } + } catch (e) { + console.error(e); + } + try { + const bpe = await fetch("https://raw.githubusercontent.com/latitudegames/GPT-3-Encoder/master/vocab.bpe", { + headers: { + "User-Agent": CONST.USER_AGENT + } + }).then((x) => x.text()); + await DATABASE.put(key, bpe); + return bpe; + } catch (e) { + console.error(e); + } + return null; +} +async function gpt3TokensCounter() { + console.log("gpt3TokensCounter loading..."); + const encoder = await encoderLoader(); + const bpe_file = await bpeFileLoader(); + const range = (x, y) => { + const res = Array.from(Array(y).keys()).slice(x); + return res; + }; + const ord = (x) => { + return x.charCodeAt(0); + }; + const chr = (x) => { + return String.fromCharCode(x); + }; + const textEncoder = new TextEncoder("utf-8"); + const encodeStr = (str) => { + return Array.from(textEncoder.encode(str)).map((x) => x.toString()); + }; + const dictZip = (x, y) => { + const result = {}; + x.map((_, i) => { + result[x[i]] = y[i]; + }); + return result; + }; + function bytes_to_unicode() { + const bs = range(ord("!"), ord("~") + 1).concat(range(ord("\xA1"), ord("\xAC") + 1), range(ord("\xAE"), ord("\xFF") + 1)); + let cs = bs.slice(); + let n = 0; + for (let b = 0; b < 2 ** 8; b++) { + if (!bs.includes(b)) { + bs.push(b); + cs.push(2 ** 8 + n); + n = n + 1; + } + } + cs = cs.map((x) => chr(x)); + const result = {}; + bs.map((_, i) => { + result[bs[i]] = cs[i]; + }); + return result; + } + function get_pairs(word) { + const pairs = /* @__PURE__ */ new Set(); + let prev_char = word[0]; + for (let i = 1; i < word.length; i++) { + const char = word[i]; + pairs.add([prev_char, char]); + prev_char = char; + } + return pairs; + } + const pat = /'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu; + const decoder = {}; + Object.keys(encoder).map((x) => { + decoder[encoder[x]] = x; + }); + const lines = bpe_file.split("\n"); + const bpe_merges = lines.slice(1, lines.length - 1).map((x) => { + return x.split(/(\s+)/).filter(function(e) { + return e.trim().length > 0; + }); + }); + const byte_encoder = bytes_to_unicode(); + const byte_decoder = {}; + Object.keys(byte_encoder).map((x) => { + byte_decoder[byte_encoder[x]] = x; + }); + const bpe_ranks = dictZip(bpe_merges, range(0, bpe_merges.length)); + const cache = /* @__PURE__ */ new Map(); + function bpe(token) { + if (cache.has(token)) { + return cache.get(token); + } + ``; + let word = token.split(""); + let pairs = get_pairs(word); + if (!pairs) { + return token; + } + while (true) { + const minPairs = {}; + Array.from(pairs).map((pair) => { + const rank = bpe_ranks[pair]; + minPairs[isNaN(rank) ? 1e11 : rank] = pair; + }); + const bigram = minPairs[Math.min(...Object.keys(minPairs).map( + (x) => { + return parseInt(x); + } + ))]; + if (!(bigram in bpe_ranks)) { + break; + } + const first = bigram[0]; + const second = bigram[1]; + let new_word = []; + let i = 0; + while (i < word.length) { + const j = word.indexOf(first, i); + if (j === -1) { + new_word = new_word.concat(word.slice(i)); + break; + } + new_word = new_word.concat(word.slice(i, j)); + i = j; + if (word[i] === first && i < word.length - 1 && word[i + 1] === second) { + new_word.push(first + second); + i = i + 2; + } else { + new_word.push(word[i]); + i = i + 1; + } + } + word = new_word; + if (word.length === 1) { + break; + } else { + pairs = get_pairs(word); + } + } + word = word.join(" "); + cache.set(token, word); + return word; + } + return function tokenCount(text) { + let tokensCount = 0; + const matches = Array.from(text.matchAll(pat)).map((x) => x[0]); + for (let token of matches) { + token = encodeStr(token).map((x) => { + return byte_encoder[x]; + }).join(""); + const new_tokens = bpe(token).split(" ").map((x) => encoder[x]); + tokensCount += new_tokens.length; + } + return tokensCount; + }; +} + // src/utils.js function randomString(length) { const chars = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; @@ -529,6 +716,24 @@ function mergeConfig(config, key, value) { throw new Error("\u4E0D\u652F\u6301\u7684\u914D\u7F6E\u9879\u6216\u6570\u636E\u7C7B\u578B\u9519\u8BEF"); } } +async function tokensCounter() { + let counter = (text) => Array.from(text).length; + try { + if (ENV.GPT3_TOKENS_COUNT) { + counter = await gpt3TokensCounter(); + } + } catch (e) { + console.error(e); + } + return (text) => { + try { + return counter(text); + } catch (e) { + console.error(e); + return Array.from(text).length; + } + }; +} // src/command.js var commandAuthCheck = { @@ -898,198 +1103,6 @@ function commandsDocument() { }); } -// src/gpt3.js -async function encoderLoader() { - const key = "encoder_raw_file"; - try { - const raw = await DATABASE.get(key); - if (raw && raw !== "") { - return JSON.parse(raw); - } - } catch (e) { - console.error(e); - } - try { - const encoder = await fetch("https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master/encoder.json", { - headers: { - "User-Agent": CONST.USER_AGENT - } - }).then((x) => x.json()); - await DATABASE.put(key, JSON.stringify(encoder)); - return encoder; - } catch (e) { - console.error(e); - } - return null; -} -async function bpeFileLoader() { - const key = "bpe_raw_file"; - try { - const raw = await DATABASE.get(key); - if (raw && raw !== "") { - return raw; - } - } catch (e) { - console.error(e); - } - try { - const bpe = await fetch("https://raw.githubusercontent.com/latitudegames/GPT-3-Encoder/master/vocab.bpe", { - headers: { - "User-Agent": CONST.USER_AGENT - } - }).then((x) => x.text()); - await DATABASE.put(key, bpe); - return bpe; - } catch (e) { - console.error(e); - } - return null; -} -async function gpt3TokensCounter() { - console.log("gpt3TokensCounter loading..."); - const encoder = await encoderLoader(); - const bpe_file = await bpeFileLoader(); - if (encoder === null || bpe_file === null) { - return (text) => { - return Array.from(text).length; - }; - } - const range = (x, y) => { - const res = Array.from(Array(y).keys()).slice(x); - return res; - }; - const ord = (x) => { - return x.charCodeAt(0); - }; - const chr = (x) => { - return String.fromCharCode(x); - }; - const textEncoder = new TextEncoder("utf-8"); - const encodeStr = (str) => { - return Array.from(textEncoder.encode(str)).map((x) => x.toString()); - }; - const dictZip = (x, y) => { - const result = {}; - x.map((_, i) => { - result[x[i]] = y[i]; - }); - return result; - }; - function bytes_to_unicode() { - const bs = range(ord("!"), ord("~") + 1).concat(range(ord("\xA1"), ord("\xAC") + 1), range(ord("\xAE"), ord("\xFF") + 1)); - let cs = bs.slice(); - let n = 0; - for (let b = 0; b < 2 ** 8; b++) { - if (!bs.includes(b)) { - bs.push(b); - cs.push(2 ** 8 + n); - n = n + 1; - } - } - cs = cs.map((x) => chr(x)); - const result = {}; - bs.map((_, i) => { - result[bs[i]] = cs[i]; - }); - return result; - } - function get_pairs(word) { - const pairs = /* @__PURE__ */ new Set(); - let prev_char = word[0]; - for (let i = 1; i < word.length; i++) { - const char = word[i]; - pairs.add([prev_char, char]); - prev_char = char; - } - return pairs; - } - const pat = /'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+/gu; - const decoder = {}; - Object.keys(encoder).map((x) => { - decoder[encoder[x]] = x; - }); - const lines = bpe_file.split("\n"); - const bpe_merges = lines.slice(1, lines.length - 1).map((x) => { - return x.split(/(\s+)/).filter(function(e) { - return e.trim().length > 0; - }); - }); - const byte_encoder = bytes_to_unicode(); - const byte_decoder = {}; - Object.keys(byte_encoder).map((x) => { - byte_decoder[byte_encoder[x]] = x; - }); - const bpe_ranks = dictZip(bpe_merges, range(0, bpe_merges.length)); - const cache = /* @__PURE__ */ new Map(); - function bpe(token) { - if (cache.has(token)) { - return cache.get(token); - } - ``; - let word = token.split(""); - let pairs = get_pairs(word); - if (!pairs) { - return token; - } - while (true) { - const minPairs = {}; - Array.from(pairs).map((pair) => { - const rank = bpe_ranks[pair]; - minPairs[isNaN(rank) ? 1e11 : rank] = pair; - }); - const bigram = minPairs[Math.min(...Object.keys(minPairs).map( - (x) => { - return parseInt(x); - } - ))]; - if (!(bigram in bpe_ranks)) { - break; - } - const first = bigram[0]; - const second = bigram[1]; - let new_word = []; - let i = 0; - while (i < word.length) { - const j = word.indexOf(first, i); - if (j === -1) { - new_word = new_word.concat(word.slice(i)); - break; - } - new_word = new_word.concat(word.slice(i, j)); - i = j; - if (word[i] === first && i < word.length - 1 && word[i + 1] === second) { - new_word.push(first + second); - i = i + 2; - } else { - new_word.push(word[i]); - i = i + 1; - } - } - word = new_word; - if (word.length === 1) { - break; - } else { - pairs = get_pairs(word); - } - } - word = word.join(" "); - cache.set(token, word); - return word; - } - return function tokenCount(text) { - let tokensCount = 0; - const matches = Array.from(text.matchAll(pat)).map((x) => x[0]); - for (let token of matches) { - token = encodeStr(token).map((x) => { - return byte_encoder[x]; - }).join(""); - const new_tokens = bpe(token).split(" ").map((x) => encoder[x]); - tokensCount += new_tokens.length; - } - return tokensCount; - }; -} - // src/message.js var MAX_TOKEN_LENGTH = 2048; async function msgInitChatContext(message) { @@ -1333,14 +1346,7 @@ async function loadHistory(key) { history.forEach((item) => { delete item.cosplay; }); - let counter = (text) => Array.from(text).length; - try { - if (ENV.GPT3_TOKENS_COUNT) { - counter = await gpt3TokensCounter(); - } - } catch (e) { - console.error(e); - } + const counter = await tokensCounter(); const trimHistory = (list, initLength, maxLength, maxToken) => { if (list.length > maxLength) { list = list.splice(list.length - maxLength); diff --git a/dist/timestamp b/dist/timestamp index bf7330e2..5c2b672d 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678680858 +1678681547 diff --git a/src/gpt3.js b/src/gpt3.js index c485b90d..b1bd6034 100644 --- a/src/gpt3.js +++ b/src/gpt3.js @@ -56,12 +56,6 @@ export async function gpt3TokensCounter() { const encoder = await encoderLoader(); const bpe_file = await bpeFileLoader(); - if (encoder === null || bpe_file === null) { - return (text) => { - return Array.from(text).length; - }; - } - const range = (x, y) => { const res = Array.from(Array(y).keys()).slice(x); return res; diff --git a/src/utils.js b/src/utils.js index 10b65fed..e9cb6a72 100644 --- a/src/utils.js +++ b/src/utils.js @@ -106,5 +106,12 @@ export async function tokensCounter() { } catch (e) { console.error(e); } - return counter; + return (text) => { + try { + return counter(text); + } catch (e) { + console.error(e); + return Array.from(text).length; + } + }; } From 348cde19c50477d5eed37e140e9dd009e7dd474f Mon Sep 17 00:00:00 2001 From: TBXark Date: Mon, 13 Mar 2023 13:19:39 +0800 Subject: [PATCH 08/24] =?UTF-8?q?feat:=20=E5=88=86=E7=A6=BB`resourceLoader?= =?UTF-8?q?`=E5=87=BD=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 15 ++++---------- dist/buildinfo.json | 2 +- dist/index.js | 50 +++++++++++++-------------------------------- dist/timestamp | 2 +- src/env.js | 8 +++++--- src/gpt3.js | 34 +++++------------------------- src/message.js | 6 ++---- 7 files changed, 32 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index b144813d..022dd0a6 100644 --- a/README.md +++ b/README.md @@ -33,16 +33,9 @@ - ~~长消息被Telegram截断~~ ## 更新日志 -- v1.3.0 - - 添加token使用统计指令`/usage` - - 添加系统信息指令`/system` - - 添加command菜单显示范围 - - 添加`SYSTEM_INIT_MESSAGE`环境变量 - - 添加`CHAT_MODEL`环境变量 - - 添加`Github Action`自动更新部署脚本 - - 优化`/init`页面 显示更多错误信息 - - 修复`USER_CONFIG`加载异常BUG - - 修复把错误信息存入历史记录BUG - - 修复历史记录裁剪BUG +- v1.3.1 + - 优化历史记录裁剪逻辑 + - 优化token计算逻辑 + - 修复edit消息的bug 其他更新日志见[CHANGELOG.md](./doc/CHANGELOG.md) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 30a0512a..b760fbcf 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "4c7043c", "timestamp": 1678681547} +{"sha": "318ad8e", "timestamp": 1678684580} diff --git a/dist/index.js b/dist/index.js index c7db122f..8c1057c8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -25,6 +25,10 @@ var ENV = { AUTO_TRIM_HISTORY: true, // 最大历史记录长度 MAX_HISTORY_LENGTH: 20, + // 最大消息长度 + MAX_TOKEN_LENGTH: 2048, + // 使用GPT3的TOKEN计数 + GPT3_TOKENS_COUNT: false, // 全局默认初始化消息 SYSTEM_INIT_MESSAGE: "\u4F60\u662F\u4E00\u4E2A\u5F97\u529B\u7684\u52A9\u624B", // 全局默认初始化消息角色 @@ -36,17 +40,15 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678681547, + BUILD_TIMESTAMP: 1678684580, // 当前版本 commit id - BUILD_VERSION: "4c7043c", + BUILD_VERSION: "318ad8e", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, // 开发模式 DEV_MODE: false, - GPT3_TOKENS_COUNT: false, - // Inline keyboard: 实验性功能请勿开启 - INLINE_KEYBOARD_ENABLE: [], + // 本地调试专用 TELEGRAM_API_DOMAIN: "https://api.telegram.org", OPENAI_API_DOMAIN: "https://api.openai.com" }; @@ -439,31 +441,7 @@ async function updateBotUsage(usage) { } // src/gpt3.js -async function encoderLoader() { - const key = "encoder_raw_file"; - try { - const raw = await DATABASE.get(key); - if (raw && raw !== "") { - return JSON.parse(raw); - } - } catch (e) { - console.error(e); - } - try { - const encoder = await fetch("https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master/encoder.json", { - headers: { - "User-Agent": CONST.USER_AGENT - } - }).then((x) => x.json()); - await DATABASE.put(key, JSON.stringify(encoder)); - return encoder; - } catch (e) { - console.error(e); - } - return null; -} -async function bpeFileLoader() { - const key = "bpe_raw_file"; +async function resourceLoader(key, url) { try { const raw = await DATABASE.get(key); if (raw && raw !== "") { @@ -473,7 +451,7 @@ async function bpeFileLoader() { console.error(e); } try { - const bpe = await fetch("https://raw.githubusercontent.com/latitudegames/GPT-3-Encoder/master/vocab.bpe", { + const bpe = await fetch(url, { headers: { "User-Agent": CONST.USER_AGENT } @@ -487,8 +465,9 @@ async function bpeFileLoader() { } async function gpt3TokensCounter() { console.log("gpt3TokensCounter loading..."); - const encoder = await encoderLoader(); - const bpe_file = await bpeFileLoader(); + const repo = "https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master"; + const encoder = await resourceLoader("encoder_raw_file", `${repo}/encoder.json`).then((x) => JSON.parse(x)); + const bpe_file = await resourceLoader("bpe_raw_file", `${repo}/vocab.bpe`); const range = (x, y) => { const res = Array.from(Array(y).keys()).slice(x); return res; @@ -1104,7 +1083,6 @@ function commandsDocument() { } // src/message.js -var MAX_TOKEN_LENGTH = 2048; async function msgInitChatContext(message) { try { await initContext(message); @@ -1371,8 +1349,8 @@ async function loadHistory(key) { if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { const initLength = Array.from(initMessage.content).length; const roleCount = Math.max(Object.keys(USER_DEFINE.ROLE).length, 1); - history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, MAX_TOKEN_LENGTH); - original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, MAX_TOKEN_LENGTH * roleCount); + history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, ENV.MAX_TOKEN_LENGTH); + original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, ENV.MAX_TOKEN_LENGTH * roleCount); } switch (history.length > 0 ? history[0].role : "") { case "assistant": diff --git a/dist/timestamp b/dist/timestamp index 5c2b672d..b35245da 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678681547 +1678684580 diff --git a/src/env.js b/src/env.js index c447aa25..2768a90c 100644 --- a/src/env.js +++ b/src/env.js @@ -29,6 +29,10 @@ export const ENV = { AUTO_TRIM_HISTORY: true, // 最大历史记录长度 MAX_HISTORY_LENGTH: 20, + // 最大消息长度 + MAX_TOKEN_LENGTH: 2048, + // 使用GPT3的TOKEN计数 + GPT3_TOKENS_COUNT: false, // 全局默认初始化消息 SYSTEM_INIT_MESSAGE: '你是一个得力的助手', @@ -51,9 +55,7 @@ export const ENV = { DEBUG_MODE: false, // 开发模式 DEV_MODE: false, - GPT3_TOKENS_COUNT: false, - // Inline keyboard: 实验性功能请勿开启 - INLINE_KEYBOARD_ENABLE: [], + // 本地调试专用 TELEGRAM_API_DOMAIN: 'https://api.telegram.org', OPENAI_API_DOMAIN: 'https://api.openai.com', }; diff --git a/src/gpt3.js b/src/gpt3.js index b1bd6034..6def3693 100644 --- a/src/gpt3.js +++ b/src/gpt3.js @@ -3,32 +3,7 @@ import {CONST, DATABASE} from './env'; -async function encoderLoader() { - const key = 'encoder_raw_file'; - try { - const raw = await DATABASE.get(key); - if (raw && raw !== '') { - return JSON.parse(raw); - } - } catch (e) { - console.error(e); - } - try { - const encoder = await fetch('https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master/encoder.json', { - headers: { - 'User-Agent': CONST.USER_AGENT, - }, - }).then((x) => x.json()); - await DATABASE.put(key, JSON.stringify(encoder)); - return encoder; - } catch (e) { - console.error(e); - } - return null; -} - -async function bpeFileLoader() { - const key = 'bpe_raw_file'; +async function resourceLoader(key, url) { try { const raw = await DATABASE.get(key); if (raw && raw !== '') { @@ -38,7 +13,7 @@ async function bpeFileLoader() { console.error(e); } try { - const bpe = await fetch('https://raw.githubusercontent.com/latitudegames/GPT-3-Encoder/master/vocab.bpe', { + const bpe = await fetch(url, { headers: { 'User-Agent': CONST.USER_AGENT, }, @@ -53,8 +28,9 @@ async function bpeFileLoader() { export async function gpt3TokensCounter() { console.log('gpt3TokensCounter loading...'); - const encoder = await encoderLoader(); - const bpe_file = await bpeFileLoader(); + const repo = 'https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master'; + const encoder = await resourceLoader('encoder_raw_file', `${repo}/encoder.json`).then((x) => JSON.parse(x)); + const bpe_file = await resourceLoader('bpe_raw_file', `${repo}/vocab.bpe`); const range = (x, y) => { const res = Array.from(Array(y).keys()).slice(x); diff --git a/src/message.js b/src/message.js index 590c2007..0738d074 100644 --- a/src/message.js +++ b/src/message.js @@ -5,8 +5,6 @@ import {requestCompletionsFromChatGPT} from './openai.js'; import {handleCommandMessage} from './command.js'; import {errorToString, tokensCounter} from './utils.js'; -const MAX_TOKEN_LENGTH = 2048; - // Middleware // 初始化聊天上下文 @@ -337,8 +335,8 @@ async function loadHistory(key) { if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { const initLength = Array.from(initMessage.content).length; const roleCount = Math.max(Object.keys(USER_DEFINE.ROLE).length, 1); - history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, MAX_TOKEN_LENGTH); - original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, MAX_TOKEN_LENGTH* roleCount); + history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, ENV.MAX_TOKEN_LENGTH); + original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, ENV.MAX_TOKEN_LENGTH * roleCount); } // 插入init From 91ec3bcd698a33c16cc2f2c4a16e9803c6024d58 Mon Sep 17 00:00:00 2001 From: TBXark Date: Mon, 13 Mar 2023 13:24:17 +0800 Subject: [PATCH 09/24] =?UTF-8?q?fix:=20initMessage=E7=9A=84token=E8=AE=A1?= =?UTF-8?q?=E7=AE=97=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 6 +++--- dist/timestamp | 2 +- src/message.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index b760fbcf..9b71e8d7 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "318ad8e", "timestamp": 1678684580} +{"sha": "348cde1", "timestamp": 1678685006} diff --git a/dist/index.js b/dist/index.js index 8c1057c8..e9a8be57 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40,9 +40,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678684580, + BUILD_TIMESTAMP: 1678685006, // 当前版本 commit id - BUILD_VERSION: "318ad8e", + BUILD_VERSION: "348cde1", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, @@ -1347,7 +1347,7 @@ async function loadHistory(key) { return list; }; if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { - const initLength = Array.from(initMessage.content).length; + const initLength = counter(initMessage.content); const roleCount = Math.max(Object.keys(USER_DEFINE.ROLE).length, 1); history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, ENV.MAX_TOKEN_LENGTH); original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, ENV.MAX_TOKEN_LENGTH * roleCount); diff --git a/dist/timestamp b/dist/timestamp index b35245da..9b164ed8 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678684580 +1678685006 diff --git a/src/message.js b/src/message.js index 0738d074..51f54d6d 100644 --- a/src/message.js +++ b/src/message.js @@ -333,7 +333,7 @@ async function loadHistory(key) { // 裁剪 if (ENV.AUTO_TRIM_HISTORY && ENV.MAX_HISTORY_LENGTH > 0) { - const initLength = Array.from(initMessage.content).length; + const initLength = counter(initMessage.content); const roleCount = Math.max(Object.keys(USER_DEFINE.ROLE).length, 1); history = trimHistory(history, initLength, ENV.MAX_HISTORY_LENGTH, ENV.MAX_TOKEN_LENGTH); original = trimHistory(original, initLength, ENV.MAX_HISTORY_LENGTH * roleCount, ENV.MAX_TOKEN_LENGTH * roleCount); From d51b1cc7c08b2bc707ef8921bcb30ded3d0cee5f Mon Sep 17 00:00:00 2001 From: TBXark Date: Mon, 13 Mar 2023 14:11:42 +0800 Subject: [PATCH 10/24] =?UTF-8?q?fix:=20=E6=B7=BB=E5=8A=A0=E6=97=B6?= =?UTF-8?q?=E9=97=B4=E6=88=B3=E7=9A=84User-Agent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/command.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/command.js b/src/command.js index 57253d57..917fb7ad 100644 --- a/src/command.js +++ b/src/command.js @@ -237,13 +237,16 @@ async function commandFetchUpdate(message, command, subcommand) { ts: ENV.BUILD_TIMESTAMP, sha: ENV.BUILD_VERSION, }; - const ts = `https://raw.githubusercontent.com/TBXark/ChatGPT-Telegram-Workers/${ENV.UPDATE_BRANCH}/dist/timestamp`; - const info = `https://raw.githubusercontent.com/TBXark/ChatGPT-Telegram-Workers/${ENV.UPDATE_BRANCH}/dist/buildinfo.json`; + + const repo = `https://raw.githubusercontent.com/TBXark/ChatGPT-Telegram-Workers/${ENV.UPDATE_BRANCH}`; + const ts = `${repo}/dist/timestamp`; + const info = `${repo}/dist/buildinfo.json`; + let online = await fetch(info, config) .then((r) => r.json()) .catch(() => null); if (!online) { - online = await fetch(ts).then((r) => r.text()) + online = await fetch(ts, config).then((r) => r.text()) .then((ts) => ({ts: Number(ts.trim()), sha: 'unknown'})) .catch(() => ({ts: 0, sha: 'unknown'})); } From 4e2d04731610edd35c76ddfc79a153ee56cf9ab3 Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 10:26:48 +0800 Subject: [PATCH 11/24] =?UTF-8?q?feat:=20=E5=85=A8=E6=96=B0=E6=9C=AC?= =?UTF-8?q?=E5=9C=B0=E6=B5=8B=E8=AF=95=E6=A1=86=E6=9E=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/kv.js | 0 proxy/openai.js | 8 - proxy/telegram.js | 8 - src/gpt3.js | 2 +- test/.gitignore | 2 + test/index.js | 19 ++ test/package-lock.json | 487 +++++++++++++++++++++++++++++++++++++++++ test/package.json | 18 ++ 8 files changed, 527 insertions(+), 17 deletions(-) delete mode 100644 proxy/kv.js delete mode 100644 proxy/openai.js delete mode 100644 proxy/telegram.js create mode 100644 test/.gitignore create mode 100644 test/index.js create mode 100644 test/package-lock.json create mode 100644 test/package.json diff --git a/proxy/kv.js b/proxy/kv.js deleted file mode 100644 index e69de29b..00000000 diff --git a/proxy/openai.js b/proxy/openai.js deleted file mode 100644 index 4dd244a7..00000000 --- a/proxy/openai.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - async fetch(request, env) { - const url = new URL(request.url); - url.hostname = "api.openai.com"; - const newRequest = new Request(url, request); - return await fetch(newRequest); - }, -}; diff --git a/proxy/telegram.js b/proxy/telegram.js deleted file mode 100644 index d5bc5045..00000000 --- a/proxy/telegram.js +++ /dev/null @@ -1,8 +0,0 @@ -export default { - async fetch(request, env) { - const url = new URL(request.url); - url.hostname = "api.telegram.org"; - const newRequest = new Request(url, request); - return await fetch(newRequest); - }, -}; diff --git a/src/gpt3.js b/src/gpt3.js index 6def3693..5e947e3e 100644 --- a/src/gpt3.js +++ b/src/gpt3.js @@ -1,7 +1,7 @@ /* eslint-disable camelcase */ // https://github.com/latitudegames/GPT-3-Encoder -import {CONST, DATABASE} from './env'; +import {CONST, DATABASE} from './env.js'; async function resourceLoader(key, url) { try { diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 00000000..e248a727 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1,2 @@ +/config.json +/database.json \ No newline at end of file diff --git a/test/index.js b/test/index.js new file mode 100644 index 00000000..0d797597 --- /dev/null +++ b/test/index.js @@ -0,0 +1,19 @@ +import adapter, { bindGlobal } from 'cloudflare-worker-adapter' +import worker from '../main.js' +import { LocalCache } from 'cloudflare-worker-adapter/cache/local.js' +import fs from 'fs' +import HttpsProxyAgent from 'https-proxy-agent' +import fetch from 'node-fetch' + +const agent = new HttpsProxyAgent('http://127.0.0.1:8888') +const proxyFetch = async (url, init) => { + return fetch(url, {agent, ...init}) +} +bindGlobal({ + fetch: proxyFetch +}) + +const config = JSON.parse(fs.readFileSync('./config.json', 'utf-8')) +const cache = new LocalCache(config.database) + +adapter.startServer(config.port, config.host, '../wrangler.toml', {DATABASE: cache}, {server: config.server}, worker.fetch) diff --git a/test/package-lock.json b/test/package-lock.json new file mode 100644 index 00000000..7cbc27fc --- /dev/null +++ b/test/package-lock.json @@ -0,0 +1,487 @@ +{ + "name": "test", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "test", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "cloudflare-worker-adapter": "github:TBXark/cloudflare-worker-adapter", + "https-proxy-agent": "^5.0.1", + "nodemon": "^2.0.21" + } + }, + "node_modules/abbrev": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/abbrev/-/abbrev-1.1.1.tgz", + "integrity": "sha512-nne9/IiQ/hzIhY6pdDnbBtz7DjPTKrY00P/zvPSm5pOFkl6xuGrGnXn/VtTNNfNtAfZ9/1RtehkszU9qcTii0Q==" + }, + "node_modules/agent-base": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/agent-base/-/agent-base-6.0.2.tgz", + "integrity": "sha512-RZNwNclF7+MS/8bDg70amg32dyeZGZxiDuQmZxKLAlQjr3jGyLx+4Kkk58UO7D2QdgFIQCovuSuZESne6RG6XQ==", + "dependencies": { + "debug": "4" + }, + "engines": { + "node": ">= 6.0.0" + } + }, + "node_modules/anymatch": { + "version": "3.1.3", + "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", + "integrity": "sha512-KMReFUr0B4t+D+OBkjR3KYqvocp2XaSzO55UcB6mgQMd3KbcE+mWTyvVV7D/zsdEbNnV6acZUutkiHQXvTr1Rw==", + "dependencies": { + "normalize-path": "^3.0.0", + "picomatch": "^2.0.4" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/balanced-match": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", + "integrity": "sha512-3oSeUO0TMV67hN1AmbXsK4yaqU7tjiHlbxRDZOpH0KW9+CeX4bRAaX0Anxt0tx2MrpRpWwQaPwIlISEJhYU5Pw==" + }, + "node_modules/binary-extensions": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/binary-extensions/-/binary-extensions-2.2.0.tgz", + "integrity": "sha512-jDctJ/IVQbZoJykoeHbhXpOlNBqGNcwXJKJog42E5HDPUwQTSdjCHdihjj0DlnheQ7blbT6dHOafNAiS8ooQKA==", + "engines": { + "node": ">=8" + } + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/braces": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/braces/-/braces-3.0.2.tgz", + "integrity": "sha512-b8um+L1RzM3WDSzvhm6gIz1yfTbBt6YTlcEKAvsmqCZZFw46z626lVj9j1yEPW33H5H+lBQpZMP1k8l+78Ha0A==", + "dependencies": { + "fill-range": "^7.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/chokidar": { + "version": "3.5.3", + "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", + "integrity": "sha512-Dr3sfKRP6oTcjf2JmUmFJfeVMvXBdegxB0iVQ5eb2V10uFJUCAS8OByZdVAyVb8xXNz3GjjTgj9kLWsZTqE6kw==", + "funding": [ + { + "type": "individual", + "url": "https://paulmillr.com/funding/" + } + ], + "dependencies": { + "anymatch": "~3.1.2", + "braces": "~3.0.2", + "glob-parent": "~5.1.2", + "is-binary-path": "~2.1.0", + "is-glob": "~4.0.1", + "normalize-path": "~3.0.0", + "readdirp": "~3.6.0" + }, + "engines": { + "node": ">= 8.10.0" + }, + "optionalDependencies": { + "fsevents": "~2.3.2" + } + }, + "node_modules/cloudflare-worker-adapter": { + "version": "1.0.0", + "resolved": "git+ssh://git@github.com/TBXark/cloudflare-worker-adapter.git#b64cb0a606c84de11338de6bac7a5611c181adfb", + "license": "MIT", + "dependencies": { + "node-fetch": "^3.2.3", + "toml": "^3.0.0" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" + }, + "node_modules/data-uri-to-buffer": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", + "integrity": "sha512-0R9ikRb668HB7QDxT1vkpuUBtqc53YyAwMwGeUFKRojY/NWKvdZ+9UYtRfGmhqNbRkTSVpMbmyhXipFFv2cb/A==", + "engines": { + "node": ">= 12" + } + }, + "node_modules/debug": { + "version": "4.3.4", + "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", + "integrity": "sha512-PRWFHuSU3eDtQJPvnNY7Jcket1j0t5OuOsFzPPzsekD52Zl8qUfFIPEiswXqIvHWGVHOgX+7G/vCNNhehwxfkQ==", + "dependencies": { + "ms": "2.1.2" + }, + "engines": { + "node": ">=6.0" + }, + "peerDependenciesMeta": { + "supports-color": { + "optional": true + } + } + }, + "node_modules/fetch-blob": { + "version": "3.2.0", + "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", + "integrity": "sha512-7yAQpD2UMJzLi1Dqv7qFYnPbaPx7ZfFK6PiIxQ4PfkGPyNyl2Ugx+a/umUonmKqjhM4DnfbMvdX6otXq83soQQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "paypal", + "url": "https://paypal.me/jimmywarting" + } + ], + "dependencies": { + "node-domexception": "^1.0.0", + "web-streams-polyfill": "^3.0.3" + }, + "engines": { + "node": "^12.20 || >= 14.13" + } + }, + "node_modules/fill-range": { + "version": "7.0.1", + "resolved": "https://registry.npmjs.org/fill-range/-/fill-range-7.0.1.tgz", + "integrity": "sha512-qOo9F+dMUmC2Lcb4BbVvnKJxTPjCm+RRpe4gDuGrzkL7mEVl/djYSu2OdQ2Pa302N4oqkSg9ir6jaLWJ2USVpQ==", + "dependencies": { + "to-regex-range": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/formdata-polyfill": { + "version": "4.0.10", + "resolved": "https://registry.npmjs.org/formdata-polyfill/-/formdata-polyfill-4.0.10.tgz", + "integrity": "sha512-buewHzMvYL29jdeQTVILecSaZKnt/RJWjoZCF5OW60Z67/GmSLBkOFM7qh1PI3zFNtJbaZL5eQu1vLfazOwj4g==", + "dependencies": { + "fetch-blob": "^3.1.2" + }, + "engines": { + "node": ">=12.20.0" + } + }, + "node_modules/fsevents": { + "version": "2.3.2", + "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", + "integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==", + "hasInstallScript": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": "^8.16.0 || ^10.6.0 || >=11.0.0" + } + }, + "node_modules/glob-parent": { + "version": "5.1.2", + "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", + "integrity": "sha512-AOIgSQCepiJYwP3ARnGx+5VnTu2HBYdzbGP45eLw1vr3zB3vZLeyed1sC9hnbcOc9/SrMyM5RPQrkGz4aS9Zow==", + "dependencies": { + "is-glob": "^4.0.1" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/has-flag": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", + "integrity": "sha512-sKJf1+ceQBr4SMkvQnBDNDtf4TXpVhVGateu0t918bl30FnbE2m4vNLX+VWe/dpjlb+HugGYzW7uQXH98HPEYw==", + "engines": { + "node": ">=4" + } + }, + "node_modules/https-proxy-agent": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", + "integrity": "sha512-dFcAjpTQFgoLMzC2VwU+C/CbS7uRL0lWmxDITmqm7C+7F0Odmj6s9l6alZc6AELXhrnggM2CeWSXHGOdX2YtwA==", + "dependencies": { + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, + "node_modules/ignore-by-default": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", + "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==" + }, + "node_modules/is-binary-path": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", + "integrity": "sha512-ZMERYes6pDydyuGidse7OsHxtbI7WVeUEozgR/g7rd0xUimYNlvZRE/K2MgZTjWy725IfelLeVcEM97mmtRGXw==", + "dependencies": { + "binary-extensions": "^2.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/is-extglob": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/is-extglob/-/is-extglob-2.1.1.tgz", + "integrity": "sha512-SbKbANkN603Vi4jEZv49LeVJMn4yGwsbzZworEoyEiutsN3nJYdbO36zfhGJ6QEDpOZIFkDtnq5JRxmvl3jsoQ==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-glob": { + "version": "4.0.3", + "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", + "integrity": "sha512-xelSayHH36ZgE7ZWhli7pW34hNbNl8Ojv5KVmkJD4hBdD3th8Tfk9vYasLM+mXWOZhFkgZfxhLSnrwRr4elSSg==", + "dependencies": { + "is-extglob": "^2.1.1" + }, + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/is-number": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", + "integrity": "sha512-41Cifkg6e8TylSpdtTpeLVMqvSBEVzTttHvERD741+pnZ8ANv0004MRL43QKPDlK9cGvNp6NZWZUBlbGXYxxng==", + "engines": { + "node": ">=0.12.0" + } + }, + "node_modules/minimatch": { + "version": "3.1.2", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", + "integrity": "sha512-J7p63hRiAjw1NDEww1W7i37+ByIrOWO5XQQAzZ3VOcL0PNybwpfmV/N05zFAzwQ9USyEcX6t3UO+K5aqBQOIHw==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/ms": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", + "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" + }, + "node_modules/node-domexception": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", + "integrity": "sha512-/jKZoMpw0F8GRwl4/eLROPA3cfcXtLApP0QzLmUT/HuPCZWyB7IY9ZrMeKw2O/nFIqPQB3PVM9aYm0F312AXDQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/jimmywarting" + }, + { + "type": "github", + "url": "https://paypal.me/jimmywarting" + } + ], + "engines": { + "node": ">=10.5.0" + } + }, + "node_modules/node-fetch": { + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-3.3.1.tgz", + "integrity": "sha512-cRVc/kyto/7E5shrWca1Wsea4y6tL9iYJE5FBCius3JQfb/4P4I295PfhgbJQBLTx6lATE4z+wK0rPM4VS2uow==", + "dependencies": { + "data-uri-to-buffer": "^4.0.0", + "fetch-blob": "^3.1.4", + "formdata-polyfill": "^4.0.10" + }, + "engines": { + "node": "^12.20.0 || ^14.13.1 || >=16.0.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/node-fetch" + } + }, + "node_modules/nodemon": { + "version": "2.0.21", + "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.21.tgz", + "integrity": "sha512-djN/n2549DUtY33S7o1djRCd7dEm0kBnj9c7S9XVXqRUbuggN1MZH/Nqa+5RFQr63Fbefq37nFXAE9VU86yL1A==", + "dependencies": { + "chokidar": "^3.5.2", + "debug": "^3.2.7", + "ignore-by-default": "^1.0.1", + "minimatch": "^3.1.2", + "pstree.remy": "^1.1.8", + "semver": "^5.7.1", + "simple-update-notifier": "^1.0.7", + "supports-color": "^5.5.0", + "touch": "^3.1.0", + "undefsafe": "^2.0.5" + }, + "bin": { + "nodemon": "bin/nodemon.js" + }, + "engines": { + "node": ">=8.10.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/nodemon" + } + }, + "node_modules/nodemon/node_modules/debug": { + "version": "3.2.7", + "resolved": "https://registry.npmjs.org/debug/-/debug-3.2.7.tgz", + "integrity": "sha512-CFjzYYAi4ThfiQvizrFQevTTXHtnCqWfe7x1AhgEscTz6ZbLbfoLRLPugTQyBth6f8ZERVUSyWHFD/7Wu4t1XQ==", + "dependencies": { + "ms": "^2.1.1" + } + }, + "node_modules/nopt": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-1.0.10.tgz", + "integrity": "sha512-NWmpvLSqUrgrAC9HCuxEvb+PSloHpqVu+FqcO4eeF2h5qYRhA7ev6KvelyQAKtegUbC6RypJnlEOhd8vloNKYg==", + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": "*" + } + }, + "node_modules/normalize-path": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/normalize-path/-/normalize-path-3.0.0.tgz", + "integrity": "sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/picomatch": { + "version": "2.3.1", + "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", + "integrity": "sha512-JU3teHTNjmE2VCGFzuY8EXzCDVwEqB2a8fsIvwaStHhAWJEeVd1o1QD80CU6+ZdEXXSLbSsuLwJjkCBWqRQUVA==", + "engines": { + "node": ">=8.6" + }, + "funding": { + "url": "https://github.com/sponsors/jonschlinkert" + } + }, + "node_modules/pstree.remy": { + "version": "1.1.8", + "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", + "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" + }, + "node_modules/readdirp": { + "version": "3.6.0", + "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", + "integrity": "sha512-hOS089on8RduqdbhvQ5Z37A0ESjsqz6qnRcffsMU3495FuTdqSm+7bhJ29JvIOsBDEEnan5DPu9t3To9VRlMzA==", + "dependencies": { + "picomatch": "^2.2.1" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/semver": { + "version": "5.7.1", + "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", + "integrity": "sha512-sauaDf/PZdVgrLTNYHRtpXa1iRiKcaebiKQ1BJdpQlWH2lCvexQdX55snPFyK7QzpudqbCI0qXFfOasHdyNDGQ==", + "bin": { + "semver": "bin/semver" + } + }, + "node_modules/simple-update-notifier": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz", + "integrity": "sha512-VpsrsJSUcJEseSbMHkrsrAVSdvVS5I96Qo1QAQ4FxQ9wXFcB+pjj7FB7/us9+GcgfW4ziHtYMc1J0PLczb55mg==", + "dependencies": { + "semver": "~7.0.0" + }, + "engines": { + "node": ">=8.10.0" + } + }, + "node_modules/simple-update-notifier/node_modules/semver": { + "version": "7.0.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.0.0.tgz", + "integrity": "sha512-+GB6zVA9LWh6zovYQLALHwv5rb2PHGlJi3lfiqIHxR0uuwCgefcOJc59v9fv1w8GbStwxuuqqAjI9NMAOOgq1A==", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/supports-color": { + "version": "5.5.0", + "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", + "integrity": "sha512-QjVjwdXIt408MIiAqCX4oUKsgU2EqAGzs2Ppkm4aQYbjm+ZEWEcW4SfFNTr4uMNZma0ey4f5lgLrkB0aX0QMow==", + "dependencies": { + "has-flag": "^3.0.0" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/to-regex-range": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", + "integrity": "sha512-65P7iz6X5yEr1cwcgvQxbbIw7Uk3gOy5dIdtZ4rDveLqhrdJP+Li/Hx6tyK0NEb+2GCyneCMJiGqrADCSNk8sQ==", + "dependencies": { + "is-number": "^7.0.0" + }, + "engines": { + "node": ">=8.0" + } + }, + "node_modules/toml": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/toml/-/toml-3.0.0.tgz", + "integrity": "sha512-y/mWCZinnvxjTKYhJ+pYxwD0mRLVvOtdS2Awbgxln6iEnt4rk0yBxeSBHkGJcPucRiG0e55mwWp+g/05rsrd6w==" + }, + "node_modules/touch": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/touch/-/touch-3.1.0.tgz", + "integrity": "sha512-WBx8Uy5TLtOSRtIq+M03/sKDrXCLHxwDcquSP2c43Le03/9serjQBIztjRz6FkJez9D/hleyAXTBGLwwZUw9lA==", + "dependencies": { + "nopt": "~1.0.10" + }, + "bin": { + "nodetouch": "bin/nodetouch.js" + } + }, + "node_modules/undefsafe": { + "version": "2.0.5", + "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", + "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==" + }, + "node_modules/web-streams-polyfill": { + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", + "integrity": "sha512-e0MO3wdXWKrLbL0DgGnUV7WHVuw9OUvL4hjgnPkIeEvESk74gAITi5G606JtZPp39cd8HA9VQzCIvA49LpPN5Q==", + "engines": { + "node": ">= 8" + } + } + } +} diff --git a/test/package.json b/test/package.json new file mode 100644 index 00000000..5d6aff80 --- /dev/null +++ b/test/package.json @@ -0,0 +1,18 @@ +{ + "name": "test", + "version": "1.0.0", + "description": "", + "type": "module", + "main": "index.js", + "scripts": { + "start": "node index.js", + "debug": "nodemon index.js" + }, + "author": "TBXark", + "license": "ISC", + "dependencies": { + "cloudflare-worker-adapter": "github:TBXark/cloudflare-worker-adapter", + "https-proxy-agent": "^5.0.1", + "nodemon": "^2.0.21" + } +} From a4d09c33a06ddfe836ac32f38bcfa9b103d0f992 Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 10:56:30 +0800 Subject: [PATCH 12/24] =?UTF-8?q?doc:=20=E6=9B=B4=E6=96=B0=E6=96=87?= =?UTF-8?q?=E6=A1=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LICENSE | 21 +++++++++++++++++++++ README.md | 9 +++++++++ doc/en/README.md | 24 ++++++++++++++++++------ doc/en/doc/ACTION.md | 2 +- doc/en/doc/DEPLOY.md | 2 +- test/README.md | 39 +++++++++++++++++++++++++++++++++++++++ 6 files changed, 89 insertions(+), 8 deletions(-) create mode 100644 LICENSE create mode 100644 test/README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 00000000..9b302971 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2023 TBXark + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md index 022dd0a6..0f8dca0f 100644 --- a/README.md +++ b/README.md @@ -39,3 +39,12 @@ - 修复edit消息的bug 其他更新日志见[CHANGELOG.md](./doc/CHANGELOG.md) + + +## 贡献者 + +这个项目存在是因为所有贡献者的帮助。[贡献](https://github.com/tbxark/ChatGPT-Telegram-Workers/graphs/contributors). + +## 许可证 + +**ChatGPT-Telegram-Workers** 以 MIT 许可证的形式发布。[查看许可证](./LICENSE) 获取更多细节。 \ No newline at end of file diff --git a/doc/en/README.md b/doc/en/README.md index d24a5f13..1b83021d 100644 --- a/doc/en/README.md +++ b/doc/en/README.md @@ -17,15 +17,27 @@ For more information, see [Deployment Process](./doc/DEPLOY.md). ## Automatic Update Automatically update using Github Action, for more information, see [Automatic Update](./doc/ACTION.md). + ## Best Practices -Create multiple bots bound to the same workers, set `TELEGRAM_AVAILABLE_TOKENS`, and assign each bot a different `SYSTEM_INIT_MESSAGE`. For example, translation experts, copywriting experts, code experts. Then chat with different bots according to your needs, so you don't have to switch configuration properties frequently. +~~Create multiple robots bound to the same workers, set `TELEGRAM_AVAILABLE_TOKENS`, and assign each robot a different `SYSTEM_INIT_MESSAGE`.~~ Enable group chat mode, create multiple group chats, each with its own robot, and give each robot a different `SYSTEM_INIT_MESSAGE`, such as translation expert, copywriting expert, and code expert. Then, chat with the robots in different groups according to your needs, so you don't have to switch configuration properties frequently. ## Known Issues - ~~Group messages can only be called by administrators of the bot~~ -- Long messages are truncated by Telegram +- ~~Long messages are truncated by Telegram~~ -## Changelog -- v1.2.0 - - Fix critical vulnerabilities, must be updated +## Update Log +- v1.3.1 + - Optimize the logic of trimming the history record + - Optimize the calculation logic of tokens + - Fix the bug of editing messages -For other update logs, see [CHANGELOG.md](./doc/CHANGELOG.md). \ No newline at end of file +For other update logs, see [CHANGELOG.md](./doc/CHANGELOG.md). + + +## Contributors + +This project exists thanks to all the people who contribute. [Contribute](https://github.com/tbxark/ChatGPT-Telegram-Workers/graphs/contributors). + +## License + +**ChatGPT-Telegram-Workers** is released under the MIT license. [See LICENSE](../../LICENSE) for details. diff --git a/doc/en/doc/ACTION.md b/doc/en/doc/ACTION.md index 1c9af262..5e38c70a 100644 --- a/doc/en/doc/ACTION.md +++ b/doc/en/doc/ACTION.md @@ -25,7 +25,7 @@ To create a Cloudflare API Token with Workers permissions, follow these steps: 1. Add the following Secrets to the Github repository's Settings -> Secrets - CF_API_TOKEN: Your Cloudflare API TOKEN - - WRANGLER_TOML: The full content of the wrangler.toml file. Refer to [wrangler-example.toml](../wrangler-example.toml) for an example. + - WRANGLER_TOML: The full content of the wrangler.toml file. Refer to [wrangler-example.toml](../../../wrangler-example.toml) for an example. - CF_WORKERS_DOMAIN (optional): Your Cloudflare Workers route (the value of your *.workers.dev in the Workers route, without https://) 2. Enable Actions in the Github repository's Settings -> Actions diff --git a/doc/en/doc/DEPLOY.md b/doc/en/doc/DEPLOY.md index fe1e591c..3a428426 100644 --- a/doc/en/doc/DEPLOY.md +++ b/doc/en/doc/DEPLOY.md @@ -33,7 +33,7 @@ Thanks to [**lipeng0820**](https://www.youtube.com/@lipeng0820) for providing th 1. Open [Cloudflare Workers](https://dash.cloudflare.com/?to=/:account/workers) and register an account. 2. Click on `Create a Service` in the upper right corner. -3. Enter the newly created Workers, select `Quick Edit`, copy the [`../dist/index.js`](https://github.com/TBXark/ChatGPT-Telegram-Workers/blob/master/dist/index.js) code into the editor, and save. +3. Enter the newly created Workers, select `Quick Edit`, copy the [`../dist/index.js`](../../../dist/index.js) code into the editor, and save. ### Step 4. Configure Environment Variables diff --git a/test/README.md b/test/README.md new file mode 100644 index 00000000..2f1d5747 --- /dev/null +++ b/test/README.md @@ -0,0 +1,39 @@ +# 调试指南 + + +### 说明 + +由于国内糟糕的网络环境, 导致使用`wrangler dev`调试基本不太可能。使用cloudflare workers网页面板调试也比较复杂。所以这里提供一个简单的适配器[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter),可以在本地调试。 + +可以使用vscode断点调试,加上`nodemon`可以实现热更新。 + +### 使用步骤 + +1. 创建`config.json` + +为了隐私安全,这里把本地的一些配置写在了`config.json`。请自行实现。 +```json +{ + "port": 8787, + "host": "0.0.0.0", + "server": "https://workers.example.cn", + "database": "./database.json" +} +``` + +2. 端口映射 + +为了让telegram的webhook可以访问到本地的服务,需要进行端口映射。可以使用`ngrok`或者`frp`等工具。只时候把你的`server`配置成`https://xxxxx.ngrok.io`即可。 + + +3. 启动 + +```bash +npm run start +``` +重新调用`/init`接口即可。 + +4. 数据库 + +我这里一共写了三张实现`LocalCache`, `MemoryCache`, `RemoteCache`. +这里推荐使用本地数据库存储,如果使用内存数据库可能导致数据丢失。当然你也可以使用远程数据库,但是这个可能比较慢,还需要你单独部署一个workers来实现。详情你可以到[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter)查看源代码 From d75550fe3e16a40b452b2d641f0f2c986e75a190 Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 10:59:18 +0800 Subject: [PATCH 13/24] doc: update test readme --- test/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index 2f1d5747..7bd7cab2 100644 --- a/test/README.md +++ b/test/README.md @@ -31,9 +31,9 @@ ```bash npm run start ``` -重新调用`/init`接口即可。 +重新调用`https://xxxxx.ngrok.io/init`接口即可。 4. 数据库 -我这里一共写了三张实现`LocalCache`, `MemoryCache`, `RemoteCache`. +我这里一共写了三种KV的实现`LocalCache`, `MemoryCache`, `RemoteCache`. 这里推荐使用本地数据库存储,如果使用内存数据库可能导致数据丢失。当然你也可以使用远程数据库,但是这个可能比较慢,还需要你单独部署一个workers来实现。详情你可以到[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter)查看源代码 From c2e32840390237399d021243412f48246bf083e0 Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 11:07:41 +0800 Subject: [PATCH 14/24] =?UTF-8?q?pref:=20=E4=BB=A3=E7=90=86=E5=9C=B0?= =?UTF-8?q?=E5=9D=80=E7=94=B1=E9=85=8D=E7=BD=AE=E6=88=96=E8=80=85=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E5=8F=98=E9=87=8F=E5=86=B3=E5=AE=9A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/test/index.js b/test/index.js index 0d797597..f1715a9e 100644 --- a/test/index.js +++ b/test/index.js @@ -5,15 +5,20 @@ import fs from 'fs' import HttpsProxyAgent from 'https-proxy-agent' import fetch from 'node-fetch' -const agent = new HttpsProxyAgent('http://127.0.0.1:8888') -const proxyFetch = async (url, init) => { - return fetch(url, {agent, ...init}) -} -bindGlobal({ - fetch: proxyFetch -}) const config = JSON.parse(fs.readFileSync('./config.json', 'utf-8')) const cache = new LocalCache(config.database) +const proxy = config.https_proxy || process.env.https_proxy || process.env.HTTPS_PROXY +if (proxy) { + console.log(`https proxy: ${proxy}`) + const agent = new HttpsProxyAgent(proxy) + const proxyFetch = async (url, init) => { + return fetch(url, {agent, ...init}) + } + bindGlobal({ + fetch: proxyFetch + }) +} + adapter.startServer(config.port, config.host, '../wrangler.toml', {DATABASE: cache}, {server: config.server}, worker.fetch) From 4780f3cdd382da04ccbe5f488bdce25e41ed9577 Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 13:20:14 +0800 Subject: [PATCH 15/24] =?UTF-8?q?feat:=20=E8=B0=83=E8=AF=95=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E6=B7=BB=E5=8A=A0sqlite3=E6=95=B0=E6=8D=AE=E5=BA=93?= =?UTF-8?q?=E6=94=AF=E6=8C=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/.gitignore | 3 +- test/index.js | 4 +- test/package-lock.json | 1072 +++++++++++++++++++++++++++++++++++++++- test/package.json | 3 +- test/sqlite.js | 55 +++ 5 files changed, 1132 insertions(+), 5 deletions(-) create mode 100644 test/sqlite.js diff --git a/test/.gitignore b/test/.gitignore index e248a727..462a2b5f 100644 --- a/test/.gitignore +++ b/test/.gitignore @@ -1,2 +1,3 @@ /config.json -/database.json \ No newline at end of file +/database.json +/database.sqlite3 \ No newline at end of file diff --git a/test/index.js b/test/index.js index f1715a9e..eb22c10c 100644 --- a/test/index.js +++ b/test/index.js @@ -1,13 +1,13 @@ import adapter, { bindGlobal } from 'cloudflare-worker-adapter' import worker from '../main.js' -import { LocalCache } from 'cloudflare-worker-adapter/cache/local.js' +import { SqliteCache } from './sqlite.js' import fs from 'fs' import HttpsProxyAgent from 'https-proxy-agent' import fetch from 'node-fetch' const config = JSON.parse(fs.readFileSync('./config.json', 'utf-8')) -const cache = new LocalCache(config.database) +const cache = new SqliteCache(config.database) const proxy = config.https_proxy || process.env.https_proxy || process.env.HTTPS_PROXY if (proxy) { diff --git a/test/package-lock.json b/test/package-lock.json index 7cbc27fc..2aa63073 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -11,7 +11,128 @@ "dependencies": { "cloudflare-worker-adapter": "github:TBXark/cloudflare-worker-adapter", "https-proxy-agent": "^5.0.1", - "nodemon": "^2.0.21" + "nodemon": "^2.0.21", + "sqlite3": "^5.1.5" + } + }, + "node_modules/@gar/promisify": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@gar/promisify/-/promisify-1.1.3.tgz", + "integrity": "sha512-k2Ty1JcVojjJFwrg/ThKi2ujJ7XNLYaFGNB/bWT9wGR+oSMJHMa5w+CUq6p/pVrKeNNgA7pCqEcjSnHVoqJQFw==", + "optional": true + }, + "node_modules/@mapbox/node-pre-gyp": { + "version": "1.0.10", + "resolved": "https://registry.npmjs.org/@mapbox/node-pre-gyp/-/node-pre-gyp-1.0.10.tgz", + "integrity": "sha512-4ySo4CjzStuprMwk35H5pPbkymjv1SF3jGLj6rAHp/xT/RF7TL7bd9CTm1xDY49K2qF7jmR/g7k+SkLETP6opA==", + "dependencies": { + "detect-libc": "^2.0.0", + "https-proxy-agent": "^5.0.0", + "make-dir": "^3.1.0", + "node-fetch": "^2.6.7", + "nopt": "^5.0.0", + "npmlog": "^5.0.1", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.11" + }, + "bin": { + "node-pre-gyp": "bin/node-pre-gyp" + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/node-fetch": { + "version": "2.6.9", + "resolved": "https://registry.npmjs.org/node-fetch/-/node-fetch-2.6.9.tgz", + "integrity": "sha512-DJm/CJkZkRjKKj4Zi4BsKVZh3ValV5IR5s7LVZnW+6YMh0W1BfNA8XSs6DLMGYlId5F3KnA70uu2qepcR08Qqg==", + "dependencies": { + "whatwg-url": "^5.0.0" + }, + "engines": { + "node": "4.x || >=6.0.0" + }, + "peerDependencies": { + "encoding": "^0.1.0" + }, + "peerDependenciesMeta": { + "encoding": { + "optional": true + } + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/@mapbox/node-pre-gyp/node_modules/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@npmcli/fs": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@npmcli/fs/-/fs-1.1.1.tgz", + "integrity": "sha512-8KG5RD0GVP4ydEzRn/I4BNDuxDtqVbOdm8675T49OIG/NGhaK0pjPX7ZcDlvKYbA+ulvVK3ztfcF4uBdOxuJbQ==", + "optional": true, + "dependencies": { + "@gar/promisify": "^1.0.1", + "semver": "^7.3.5" + } + }, + "node_modules/@npmcli/fs/node_modules/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "optional": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@npmcli/move-file": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@npmcli/move-file/-/move-file-1.1.2.tgz", + "integrity": "sha512-1SUf/Cg2GzGDyaf15aR9St9TWlb+XvbZXWpDx8YKs7MLzMH/BCeopv+y9vzrzgkfykCGuWOlSu3mZhj2+FQcrg==", + "deprecated": "This functionality has been moved to @npmcli/fs", + "optional": true, + "dependencies": { + "mkdirp": "^1.0.4", + "rimraf": "^3.0.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/@tootallnate/once": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/@tootallnate/once/-/once-1.1.2.tgz", + "integrity": "sha512-RbzJvlNzmRq5c3O09UipeuXno4tA1FE6ikOjxZK0tuxVv3412l64l5t1W5pj4+rJq9vpkm/kwiR07aZXnsKPxw==", + "optional": true, + "engines": { + "node": ">= 6" } }, "node_modules/abbrev": { @@ -30,6 +151,41 @@ "node": ">= 6.0.0" } }, + "node_modules/agentkeepalive": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/agentkeepalive/-/agentkeepalive-4.3.0.tgz", + "integrity": "sha512-7Epl1Blf4Sy37j4v9f9FjICCh4+KAQOyXgHEwlyBiAQLbhKdq/i2QQU3amQalS/wPhdPzDXPL5DMR5bkn+YeWg==", + "optional": true, + "dependencies": { + "debug": "^4.1.0", + "depd": "^2.0.0", + "humanize-ms": "^1.2.1" + }, + "engines": { + "node": ">= 8.0.0" + } + }, + "node_modules/aggregate-error": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/aggregate-error/-/aggregate-error-3.1.0.tgz", + "integrity": "sha512-4I7Td01quW/RpocfNayFdFVk1qSuoh0E7JrbRJ16nH01HhKFQ88INq9Sd+nd72zqRySlr9BmDA8xlEJ6vJMrYA==", + "optional": true, + "dependencies": { + "clean-stack": "^2.0.0", + "indent-string": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/ansi-regex": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/ansi-regex/-/ansi-regex-5.0.1.tgz", + "integrity": "sha512-quJQXlTSUGL2LH9SUXo8VwsY4soanhgo6LNSm84E1LBcE8s3O0wpdiRzyR9z/ZZJMlMWv37qOOb9pdJlMUEKFQ==", + "engines": { + "node": ">=8" + } + }, "node_modules/anymatch": { "version": "3.1.3", "resolved": "https://registry.npmjs.org/anymatch/-/anymatch-3.1.3.tgz", @@ -42,6 +198,23 @@ "node": ">= 8" } }, + "node_modules/aproba": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/aproba/-/aproba-2.0.0.tgz", + "integrity": "sha512-lYe4Gx7QT+MKGbDsA+Z+he/Wtef0BiwDOlK/XkBrdfsh9J/jPPXbX0tE9x9cl27Tmu5gg3QUbUrQYa/y+KOHPQ==" + }, + "node_modules/are-we-there-yet": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-2.0.0.tgz", + "integrity": "sha512-Ci/qENmwHnsYo9xKIcUJN5LeDKdJ6R1Z1j9V/J5wyq8nh/mYPEpIKJbBZXtZjG04HiK7zV/p6Vs9952MrMeUIw==", + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^3.6.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/balanced-match": { "version": "1.0.2", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.2.tgz", @@ -75,6 +248,35 @@ "node": ">=8" } }, + "node_modules/cacache": { + "version": "15.3.0", + "resolved": "https://registry.npmjs.org/cacache/-/cacache-15.3.0.tgz", + "integrity": "sha512-VVdYzXEn+cnbXpFgWs5hTT7OScegHVmLhJIR8Ufqk3iFD6A6j5iSX1KuBTfNEv4tdJWE2PzA6IVFtcLC7fN9wQ==", + "optional": true, + "dependencies": { + "@npmcli/fs": "^1.0.0", + "@npmcli/move-file": "^1.0.1", + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "glob": "^7.1.4", + "infer-owner": "^1.0.4", + "lru-cache": "^6.0.0", + "minipass": "^3.1.1", + "minipass-collect": "^1.0.2", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.2", + "mkdirp": "^1.0.3", + "p-map": "^4.0.0", + "promise-inflight": "^1.0.1", + "rimraf": "^3.0.2", + "ssri": "^8.0.1", + "tar": "^6.0.2", + "unique-filename": "^1.1.1" + }, + "engines": { + "node": ">= 10" + } + }, "node_modules/chokidar": { "version": "3.5.3", "resolved": "https://registry.npmjs.org/chokidar/-/chokidar-3.5.3.tgz", @@ -101,6 +303,23 @@ "fsevents": "~2.3.2" } }, + "node_modules/chownr": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/chownr/-/chownr-2.0.0.tgz", + "integrity": "sha512-bIomtDF5KGpdogkLd9VspvFzk9KfpyyGlS8YFVZl7TGPBHL5snIOnxeshwVgPteQ9b4Eydl+pVbIyE1DcvCWgQ==", + "engines": { + "node": ">=10" + } + }, + "node_modules/clean-stack": { + "version": "2.2.0", + "resolved": "https://registry.npmjs.org/clean-stack/-/clean-stack-2.2.0.tgz", + "integrity": "sha512-4diC9HaTE+KRAMWhDhrGOECgWZxoevMc5TlkObMqNSsVU62PYzXZ/SMTjzyGAFF1YusgxGcSWTEXBhp0CPwQ1A==", + "optional": true, + "engines": { + "node": ">=6" + } + }, "node_modules/cloudflare-worker-adapter": { "version": "1.0.0", "resolved": "git+ssh://git@github.com/TBXark/cloudflare-worker-adapter.git#b64cb0a606c84de11338de6bac7a5611c181adfb", @@ -110,11 +329,24 @@ "toml": "^3.0.0" } }, + "node_modules/color-support": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/color-support/-/color-support-1.1.3.tgz", + "integrity": "sha512-qiBjkpbMLO/HL68y+lh4q0/O1MZFj2RX6X/KmMa3+gJD3z+WwI1ZzDHysvqHGS3mP6mznPckpXmw1nI9cJjyRg==", + "bin": { + "color-support": "bin.js" + } + }, "node_modules/concat-map": { "version": "0.0.1", "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "node_modules/console-control-strings": { + "version": "1.1.0", + "resolved": "https://registry.npmjs.org/console-control-strings/-/console-control-strings-1.1.0.tgz", + "integrity": "sha512-ty/fTekppD2fIwRvnZAVdeOiGd1c7YXEixbgJTNzqcxJWKQnjJ/V1bNEEE6hygpM3WjwHFUVK6HTjWSzV4a8sQ==" + }, "node_modules/data-uri-to-buffer": { "version": "4.0.1", "resolved": "https://registry.npmjs.org/data-uri-to-buffer/-/data-uri-to-buffer-4.0.1.tgz", @@ -139,6 +371,57 @@ } } }, + "node_modules/delegates": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/delegates/-/delegates-1.0.0.tgz", + "integrity": "sha512-bd2L678uiWATM6m5Z1VzNCErI3jiGzt6HGY8OVICs40JQq/HALfbyNJmp0UDakEY4pMMaN0Ly5om/B1VI/+xfQ==" + }, + "node_modules/depd": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/depd/-/depd-2.0.0.tgz", + "integrity": "sha512-g7nH6P6dyDioJogAAGprGpCtVImJhpPk/roCzdb3fIh61/s/nPsfR6onyMwkCAR/OlC3yBC0lESvUoQEAssIrw==", + "optional": true, + "engines": { + "node": ">= 0.8" + } + }, + "node_modules/detect-libc": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/detect-libc/-/detect-libc-2.0.1.tgz", + "integrity": "sha512-463v3ZeIrcWtdgIg6vI6XUncguvr2TnGl4SzDXinkt9mSLpBJKXT3mW6xT3VQdDN11+WVs29pgvivTc4Lp8v+w==", + "engines": { + "node": ">=8" + } + }, + "node_modules/emoji-regex": { + "version": "8.0.0", + "resolved": "https://registry.npmjs.org/emoji-regex/-/emoji-regex-8.0.0.tgz", + "integrity": "sha512-MSjYzcWNOA0ewAHpz0MxpYFvwg6yjy1NG3xteoqz644VCo/RPgnr1/GGt+ic3iJTzQ8Eu3TdM14SawnVUmGE6A==" + }, + "node_modules/encoding": { + "version": "0.1.13", + "resolved": "https://registry.npmjs.org/encoding/-/encoding-0.1.13.tgz", + "integrity": "sha512-ETBauow1T35Y/WZMkio9jiM0Z5xjHHmJ4XmjZOq1l/dXz3lr2sRn87nJy20RupqSh1F2m3HHPSp8ShIPQJrJ3A==", + "optional": true, + "dependencies": { + "iconv-lite": "^0.6.2" + } + }, + "node_modules/env-paths": { + "version": "2.2.1", + "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-2.2.1.tgz", + "integrity": "sha512-+h1lkLKhZMTYjog1VEpJNG7NZJWcuc2DDk/qsqSTRRCOXiLjeQ1d1/udrUGhqMxUgAlwKNZ0cf2uqan5GLuS2A==", + "optional": true, + "engines": { + "node": ">=6" + } + }, + "node_modules/err-code": { + "version": "2.0.3", + "resolved": "https://registry.npmjs.org/err-code/-/err-code-2.0.3.tgz", + "integrity": "sha512-2bmlRpNKBxT/CRmPOlyISQpNj+qSeYvcym/uT0Jx2bMOlKLtSy1ZmLuVxSEKKyor/N5yhvp/ZiG1oE3DEYMSFA==", + "optional": true + }, "node_modules/fetch-blob": { "version": "3.2.0", "resolved": "https://registry.npmjs.org/fetch-blob/-/fetch-blob-3.2.0.tgz", @@ -183,6 +466,22 @@ "node": ">=12.20.0" } }, + "node_modules/fs-minipass": { + "version": "2.1.0", + "resolved": "https://registry.npmjs.org/fs-minipass/-/fs-minipass-2.1.0.tgz", + "integrity": "sha512-V/JgOLFCS+R6Vcq0slCuaeWEdNC3ouDlJMNIsacH2VtALiu9mV4LPrHc5cDl8k5aw6J8jwgWWpiTo5RYhmIzvg==", + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha512-OO0pH2lK6a0hZnAdau5ItzHPI6pUlvI7jMVnxUQRtw4owF2wk8lOSabtGDCTP4Ggrg2MbGnWO9X8K1t4+fGMDw==" + }, "node_modules/fsevents": { "version": "2.3.2", "resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz", @@ -196,6 +495,44 @@ "node": "^8.16.0 || ^10.6.0 || >=11.0.0" } }, + "node_modules/gauge": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-3.0.2.tgz", + "integrity": "sha512-+5J6MS/5XksCuXq++uFRsnUd7Ovu1XenbeuIuNRJxYWjgQbPuFhT14lAvsWfqfAmnwluf1OwMjz39HjfLPci0Q==", + "dependencies": { + "aproba": "^1.0.3 || ^2.0.0", + "color-support": "^1.1.2", + "console-control-strings": "^1.0.0", + "has-unicode": "^2.0.1", + "object-assign": "^4.1.1", + "signal-exit": "^3.0.0", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "wide-align": "^1.1.2" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/glob": { + "version": "7.2.3", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.2.3.tgz", + "integrity": "sha512-nFR0zLpU2YCaRxwoCJvL6UvCH2JFyFVIvwTLsIf21AuHlMskA1hhTdk+LlYJtOlYt9v6dvszD2BGRqBL+iQK9Q==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.1.1", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, "node_modules/glob-parent": { "version": "5.1.2", "resolved": "https://registry.npmjs.org/glob-parent/-/glob-parent-5.1.2.tgz", @@ -207,6 +544,12 @@ "node": ">= 6" } }, + "node_modules/graceful-fs": { + "version": "4.2.10", + "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.10.tgz", + "integrity": "sha512-9ByhssR2fPVsNZj478qUUbKfmL0+t5BDVyjShtyZZLiK7ZDAArFFfopyOTj0M05wE2tJPisA4iTnnXl2YoPvOA==", + "optional": true + }, "node_modules/has-flag": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-3.0.0.tgz", @@ -215,6 +558,31 @@ "node": ">=4" } }, + "node_modules/has-unicode": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/has-unicode/-/has-unicode-2.0.1.tgz", + "integrity": "sha512-8Rf9Y83NBReMnx0gFzA8JImQACstCYWUplepDa9xprwwtmgEZUF0h/i5xSA625zB/I37EtrswSST6OXxwaaIJQ==" + }, + "node_modules/http-cache-semantics": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/http-cache-semantics/-/http-cache-semantics-4.1.1.tgz", + "integrity": "sha512-er295DKPVsV82j5kw1Gjt+ADA/XYHsajl82cGNQG2eyoPkvgUhX+nDIyelzhIWbbsXP39EHcI6l5tYs2FYqYXQ==", + "optional": true + }, + "node_modules/http-proxy-agent": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/http-proxy-agent/-/http-proxy-agent-4.0.1.tgz", + "integrity": "sha512-k0zdNgqWTGA6aeIRVpvfVob4fL52dTfaehylg0Y4UvSySvOq/Y+BOyPrgpUrA7HylqvU8vIZGsRuXmspskV0Tg==", + "optional": true, + "dependencies": { + "@tootallnate/once": "1", + "agent-base": "6", + "debug": "4" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/https-proxy-agent": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/https-proxy-agent/-/https-proxy-agent-5.0.1.tgz", @@ -227,11 +595,76 @@ "node": ">= 6" } }, + "node_modules/humanize-ms": { + "version": "1.2.1", + "resolved": "https://registry.npmjs.org/humanize-ms/-/humanize-ms-1.2.1.tgz", + "integrity": "sha512-Fl70vYtsAFb/C06PTS9dZBo7ihau+Tu/DNCk/OyHhea07S+aeMWpFFkUaXRa8fI+ScZbEI8dfSxwY7gxZ9SAVQ==", + "optional": true, + "dependencies": { + "ms": "^2.0.0" + } + }, + "node_modules/iconv-lite": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/iconv-lite/-/iconv-lite-0.6.3.tgz", + "integrity": "sha512-4fCk79wshMdzMp2rH06qWrJE4iolqLhCUH+OiuIgU++RB0+94NlDL81atO7GX55uUKueo0txHNtvEyI6D7WdMw==", + "optional": true, + "dependencies": { + "safer-buffer": ">= 2.1.2 < 3.0.0" + }, + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/ignore-by-default": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/ignore-by-default/-/ignore-by-default-1.0.1.tgz", "integrity": "sha512-Ius2VYcGNk7T90CppJqcIkS5ooHUZyIQK+ClZfMfMNFEF9VSE73Fq+906u/CWu92x4gzZMWOwfFYckPObzdEbA==" }, + "node_modules/imurmurhash": { + "version": "0.1.4", + "resolved": "https://registry.npmjs.org/imurmurhash/-/imurmurhash-0.1.4.tgz", + "integrity": "sha512-JmXMZ6wuvDmLiHEml9ykzqO6lwFbof0GG4IkcGaENdCRDDmMVnny7s5HsIgHCbaq0w2MyPhDqkhTUgS2LU2PHA==", + "optional": true, + "engines": { + "node": ">=0.8.19" + } + }, + "node_modules/indent-string": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/indent-string/-/indent-string-4.0.0.tgz", + "integrity": "sha512-EdDDZu4A2OyIK7Lr/2zG+w5jmbuk1DVBnEwREQvBzspBJkCEbRa8GxU1lghYcaGJCnRWibjDXlq779X1/y5xwg==", + "optional": true, + "engines": { + "node": ">=8" + } + }, + "node_modules/infer-owner": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/infer-owner/-/infer-owner-1.0.4.tgz", + "integrity": "sha512-IClj+Xz94+d7irH5qRyfJonOdfTzuDaifE6ZPWfx0N0+/ATZCbuTPq2prFl526urkQd90WyUKIh1DfBQ2hMz9A==", + "optional": true + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha512-k92I/b08q4wvFscXCLvqfsHCrjrF7yiXsQuIVvVE7N82W3+aqpzuUdBbfhWcy/FZR3/4IgflMgKLOsvPDrGCJA==", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/ip": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/ip/-/ip-2.0.0.tgz", + "integrity": "sha512-WKa+XuLG1A1R0UWhl2+1XQSi+fZWMsYKffMZTTYsiZaUD8k2yDAj5atimTUD2TZkyCkNEeYE5NhFZmupOGtjYQ==", + "optional": true + }, "node_modules/is-binary-path": { "version": "2.1.0", "resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-2.1.0.tgz", @@ -251,6 +684,14 @@ "node": ">=0.10.0" } }, + "node_modules/is-fullwidth-code-point": { + "version": "3.0.0", + "resolved": "https://registry.npmjs.org/is-fullwidth-code-point/-/is-fullwidth-code-point-3.0.0.tgz", + "integrity": "sha512-zymm5+u+sCsSWyD9qNaejV3DFvhCKclKdizYaJUuHA83RLjb7nSuGnddCHGv0hk+KY7BMAlsWeK4Ueg6EV6XQg==", + "engines": { + "node": ">=8" + } + }, "node_modules/is-glob": { "version": "4.0.3", "resolved": "https://registry.npmjs.org/is-glob/-/is-glob-4.0.3.tgz", @@ -262,6 +703,12 @@ "node": ">=0.10.0" } }, + "node_modules/is-lambda": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/is-lambda/-/is-lambda-1.0.1.tgz", + "integrity": "sha512-z7CMFGNrENq5iFB9Bqo64Xk6Y9sg+epq1myIcdHaGnbMTYOxvzsEtdYqQUylB7LxfkvgrrjP32T6Ywciio9UIQ==", + "optional": true + }, "node_modules/is-number": { "version": "7.0.0", "resolved": "https://registry.npmjs.org/is-number/-/is-number-7.0.0.tgz", @@ -270,6 +717,72 @@ "node": ">=0.12.0" } }, + "node_modules/isexe": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/isexe/-/isexe-2.0.0.tgz", + "integrity": "sha512-RHxMLp9lnKHGHRng9QFhRCMbYAcVpn69smSGcq3f36xjgVVWThj4qqLbTLlq7Ssj8B+fIQ1EuCEGI2lKsyQeIw==", + "optional": true + }, + "node_modules/lru-cache": { + "version": "6.0.0", + "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", + "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/make-dir": { + "version": "3.1.0", + "resolved": "https://registry.npmjs.org/make-dir/-/make-dir-3.1.0.tgz", + "integrity": "sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==", + "dependencies": { + "semver": "^6.0.0" + }, + "engines": { + "node": ">=8" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/make-dir/node_modules/semver": { + "version": "6.3.0", + "resolved": "https://registry.npmjs.org/semver/-/semver-6.3.0.tgz", + "integrity": "sha512-b39TBaTSfV6yBrapU89p5fKekE2m/NwnDocOVruQFS1/veMgdzuPcnOM34M6CwxW8jH/lxEa5rBoDeUwu5HHTw==", + "bin": { + "semver": "bin/semver.js" + } + }, + "node_modules/make-fetch-happen": { + "version": "9.1.0", + "resolved": "https://registry.npmjs.org/make-fetch-happen/-/make-fetch-happen-9.1.0.tgz", + "integrity": "sha512-+zopwDy7DNknmwPQplem5lAZX/eCOzSvSNNcSKm5eVwTkOBzoktEfXsa9L23J/GIRhxRsaxzkPEhrJEpE2F4Gg==", + "optional": true, + "dependencies": { + "agentkeepalive": "^4.1.3", + "cacache": "^15.2.0", + "http-cache-semantics": "^4.1.0", + "http-proxy-agent": "^4.0.1", + "https-proxy-agent": "^5.0.0", + "is-lambda": "^1.0.1", + "lru-cache": "^6.0.0", + "minipass": "^3.1.3", + "minipass-collect": "^1.0.2", + "minipass-fetch": "^1.3.2", + "minipass-flush": "^1.0.5", + "minipass-pipeline": "^1.2.4", + "negotiator": "^0.6.2", + "promise-retry": "^2.0.1", + "socks-proxy-agent": "^6.0.0", + "ssri": "^8.0.0" + }, + "engines": { + "node": ">= 10" + } + }, "node_modules/minimatch": { "version": "3.1.2", "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.1.2.tgz", @@ -281,11 +794,124 @@ "node": "*" } }, + "node_modules/minipass": { + "version": "3.3.6", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-3.3.6.tgz", + "integrity": "sha512-DxiNidxSEK+tHG6zOIklvNOwm3hvCrbUrdtzY74U6HKTJxvIDfOUL5W5P2Ghd3DTkhhKPYGqeNUIh5qcM4YBfw==", + "dependencies": { + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minipass-collect": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/minipass-collect/-/minipass-collect-1.0.2.tgz", + "integrity": "sha512-6T6lH0H8OG9kITm/Jm6tdooIbogG9e0tLgpY6mphXSm/A9u8Nq1ryBG+Qspiub9LjWlBPsPS3tWQ/Botq4FdxA==", + "optional": true, + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minipass-fetch": { + "version": "1.4.1", + "resolved": "https://registry.npmjs.org/minipass-fetch/-/minipass-fetch-1.4.1.tgz", + "integrity": "sha512-CGH1eblLq26Y15+Azk7ey4xh0J/XfJfrCox5LDJiKqI2Q2iwOLOKrlmIaODiSQS8d18jalF6y2K2ePUm0CmShw==", + "optional": true, + "dependencies": { + "minipass": "^3.1.0", + "minipass-sized": "^1.0.3", + "minizlib": "^2.0.0" + }, + "engines": { + "node": ">=8" + }, + "optionalDependencies": { + "encoding": "^0.1.12" + } + }, + "node_modules/minipass-flush": { + "version": "1.0.5", + "resolved": "https://registry.npmjs.org/minipass-flush/-/minipass-flush-1.0.5.tgz", + "integrity": "sha512-JmQSYYpPUqX5Jyn1mXaRwOda1uQ8HP5KAT/oDSLCzt1BYRhQU0/hDtsB1ufZfEEzMZ9aAVmsBw8+FWsIXlClWw==", + "optional": true, + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/minipass-pipeline": { + "version": "1.2.4", + "resolved": "https://registry.npmjs.org/minipass-pipeline/-/minipass-pipeline-1.2.4.tgz", + "integrity": "sha512-xuIq7cIOt09RPRJ19gdi4b+RiNvDFYe5JH+ggNvBqGqpQXcru3PcRmOZuHBKWK1Txf9+cQ+HMVN4d6z46LZP7A==", + "optional": true, + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minipass-sized": { + "version": "1.0.3", + "resolved": "https://registry.npmjs.org/minipass-sized/-/minipass-sized-1.0.3.tgz", + "integrity": "sha512-MbkQQ2CTiBMlA2Dm/5cY+9SWFEN8pzzOXi6rlM5Xxq0Yqbda5ZQy9sU75a673FE9ZK0Zsbr6Y5iP6u9nktfg2g==", + "optional": true, + "dependencies": { + "minipass": "^3.0.0" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/minizlib": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/minizlib/-/minizlib-2.1.2.tgz", + "integrity": "sha512-bAxsR8BVfj60DWXHE3u30oHzfl4G7khkSuPW+qvpd7jFRHm7dLxOjUk1EHACJ/hxLY8phGJ0YhYHZo7jil7Qdg==", + "dependencies": { + "minipass": "^3.0.0", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/mkdirp": { + "version": "1.0.4", + "resolved": "https://registry.npmjs.org/mkdirp/-/mkdirp-1.0.4.tgz", + "integrity": "sha512-vVqVZQyf3WLx2Shd0qJ9xuvqgAyKPLAiqITEtqW0oIUjzo3PePDd6fW9iFz30ef7Ysp/oiWqbhszeGWW2T6Gzw==", + "bin": { + "mkdirp": "bin/cmd.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/ms": { "version": "2.1.2", "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.2.tgz", "integrity": "sha512-sGkPx+VjMtmA6MX27oA4FBFELFCZZ4S4XqeGOXCv68tT+jb3vk/RyaKWP0PTKyWtmLSM0b+adUTEvbs1PEaH2w==" }, + "node_modules/negotiator": { + "version": "0.6.3", + "resolved": "https://registry.npmjs.org/negotiator/-/negotiator-0.6.3.tgz", + "integrity": "sha512-+EUsqGPLsM+j/zdChZjsnX51g4XrHFOIXwfnCVPGlQk/k5giakcKsuxCObBRu6DSm9opw/O6slWbJdghQM4bBg==", + "optional": true, + "engines": { + "node": ">= 0.6" + } + }, + "node_modules/node-addon-api": { + "version": "4.3.0", + "resolved": "https://registry.npmjs.org/node-addon-api/-/node-addon-api-4.3.0.tgz", + "integrity": "sha512-73sE9+3UaLYYFmDsFZnqCInzPyh3MqIwZO9cw58yIqAZhONrrabrYyYe3TuIqtIiOuTXVhsGau8hcrhhwSsDIQ==" + }, "node_modules/node-domexception": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/node-domexception/-/node-domexception-1.0.0.tgz", @@ -321,6 +947,107 @@ "url": "https://opencollective.com/node-fetch" } }, + "node_modules/node-gyp": { + "version": "8.4.1", + "resolved": "https://registry.npmjs.org/node-gyp/-/node-gyp-8.4.1.tgz", + "integrity": "sha512-olTJRgUtAb/hOXG0E93wZDs5YiJlgbXxTwQAFHyNlRsXQnYzUaF2aGgujZbw+hR8aF4ZG/rST57bWMWD16jr9w==", + "optional": true, + "dependencies": { + "env-paths": "^2.2.0", + "glob": "^7.1.4", + "graceful-fs": "^4.2.6", + "make-fetch-happen": "^9.1.0", + "nopt": "^5.0.0", + "npmlog": "^6.0.0", + "rimraf": "^3.0.2", + "semver": "^7.3.5", + "tar": "^6.1.2", + "which": "^2.0.2" + }, + "bin": { + "node-gyp": "bin/node-gyp.js" + }, + "engines": { + "node": ">= 10.12.0" + } + }, + "node_modules/node-gyp/node_modules/are-we-there-yet": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/are-we-there-yet/-/are-we-there-yet-3.0.1.tgz", + "integrity": "sha512-QZW4EDmGwlYur0Yyf/b2uGucHQMa8aFUP7eu9ddR73vvhFyt4V0Vl3QHPcTNJ8l6qYOBdxgXdnBXQrHilfRQBg==", + "optional": true, + "dependencies": { + "delegates": "^1.0.0", + "readable-stream": "^3.6.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/node-gyp/node_modules/gauge": { + "version": "4.0.4", + "resolved": "https://registry.npmjs.org/gauge/-/gauge-4.0.4.tgz", + "integrity": "sha512-f9m+BEN5jkg6a0fZjleidjN51VE1X+mPFQ2DJ0uv1V39oCLCbsGe6yjbBnp7eK7z/+GAon99a3nHuqbuuthyPg==", + "optional": true, + "dependencies": { + "aproba": "^1.0.3 || ^2.0.0", + "color-support": "^1.1.3", + "console-control-strings": "^1.1.0", + "has-unicode": "^2.0.1", + "signal-exit": "^3.0.7", + "string-width": "^4.2.3", + "strip-ansi": "^6.0.1", + "wide-align": "^1.1.5" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/node-gyp/node_modules/nopt": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", + "integrity": "sha512-Tbj67rffqceeLpcRXrT7vKAN8CwfPeIBgM7E6iBkmKLV7bEMwpGgYLGv0jACUsECaa/vuxP0IjEont6umdMgtQ==", + "optional": true, + "dependencies": { + "abbrev": "1" + }, + "bin": { + "nopt": "bin/nopt.js" + }, + "engines": { + "node": ">=6" + } + }, + "node_modules/node-gyp/node_modules/npmlog": { + "version": "6.0.2", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-6.0.2.tgz", + "integrity": "sha512-/vBvz5Jfr9dT/aFWd0FIRf+T/Q2WBsLENygUaFUqstqsycmZAP/t5BvFJTK0viFmSUxiUKTUplWy5vt+rvKIxg==", + "optional": true, + "dependencies": { + "are-we-there-yet": "^3.0.0", + "console-control-strings": "^1.1.0", + "gauge": "^4.0.3", + "set-blocking": "^2.0.0" + }, + "engines": { + "node": "^12.13.0 || ^14.15.0 || >=16.0.0" + } + }, + "node_modules/node-gyp/node_modules/semver": { + "version": "7.3.8", + "resolved": "https://registry.npmjs.org/semver/-/semver-7.3.8.tgz", + "integrity": "sha512-NB1ctGL5rlHrPJtFDVIVzTyQylMLu9N9VICA6HSFJo8MCGVTMW6gfpicwKmmK/dAjTOrqu5l63JJOpDSrAis3A==", + "optional": true, + "dependencies": { + "lru-cache": "^6.0.0" + }, + "bin": { + "semver": "bin/semver.js" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/nodemon": { "version": "2.0.21", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-2.0.21.tgz", @@ -378,6 +1105,56 @@ "node": ">=0.10.0" } }, + "node_modules/npmlog": { + "version": "5.0.1", + "resolved": "https://registry.npmjs.org/npmlog/-/npmlog-5.0.1.tgz", + "integrity": "sha512-AqZtDUWOMKs1G/8lwylVjrdYgqA4d9nu8hc+0gzRxlDb1I10+FHBGMXs6aiQHFdCUUlqH99MUMuLfzWDNDtfxw==", + "dependencies": { + "are-we-there-yet": "^2.0.0", + "console-control-strings": "^1.1.0", + "gauge": "^3.0.0", + "set-blocking": "^2.0.0" + } + }, + "node_modules/object-assign": { + "version": "4.1.1", + "resolved": "https://registry.npmjs.org/object-assign/-/object-assign-4.1.1.tgz", + "integrity": "sha512-rJgTQnkUnH1sFw8yT6VSU3zD3sWmu6sZhIseY8VX+GRu3P6F7Fu+JNDoXfklElbLJSnc3FUQHVe4cU5hj+BcUg==", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha512-lNaJgI+2Q5URQBkccEKHTQOPaXdUxnZZElQTZY0MFUAuaEqe1E+Nyvgdz/aIyNi6Z9MzO5dv1H8n58/GELp3+w==", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/p-map": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/p-map/-/p-map-4.0.0.tgz", + "integrity": "sha512-/bjOqmgETBYB5BoEeGVea8dmvHb2m9GLy1E9W43yeyfP6QQCZGFNa+XRceJEuDB6zqr+gKpIAmlLebMpykw/MQ==", + "optional": true, + "dependencies": { + "aggregate-error": "^3.0.0" + }, + "engines": { + "node": ">=10" + }, + "funding": { + "url": "https://github.com/sponsors/sindresorhus" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha512-AVbw3UJ2e9bq64vSaS9Am0fje1Pa8pbGqTTsmXfaIiMpnr5DlDhfJOuLj9Sf95ZPVDAUerDfEk88MPmPe7UCQg==", + "engines": { + "node": ">=0.10.0" + } + }, "node_modules/picomatch": { "version": "2.3.1", "resolved": "https://registry.npmjs.org/picomatch/-/picomatch-2.3.1.tgz", @@ -389,11 +1166,43 @@ "url": "https://github.com/sponsors/jonschlinkert" } }, + "node_modules/promise-inflight": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/promise-inflight/-/promise-inflight-1.0.1.tgz", + "integrity": "sha512-6zWPyEOFaQBJYcGMHBKTKJ3u6TBsnMFOIZSa6ce1e/ZrrsOlnHRHbabMjLiBYKp+n44X9eUI6VUPaukCXHuG4g==", + "optional": true + }, + "node_modules/promise-retry": { + "version": "2.0.1", + "resolved": "https://registry.npmjs.org/promise-retry/-/promise-retry-2.0.1.tgz", + "integrity": "sha512-y+WKFlBR8BGXnsNlIHFGPZmyDf3DFMoLhaflAnyZgV6rG6xu+JwesTo2Q9R6XwYmtmwAFCkAk3e35jEdoeh/3g==", + "optional": true, + "dependencies": { + "err-code": "^2.0.2", + "retry": "^0.12.0" + }, + "engines": { + "node": ">=10" + } + }, "node_modules/pstree.remy": { "version": "1.1.8", "resolved": "https://registry.npmjs.org/pstree.remy/-/pstree.remy-1.1.8.tgz", "integrity": "sha512-77DZwxQmxKnu3aR542U+X8FypNzbfJ+C5XQDk3uWjWxn6151aIMGthWYRXTqT1E5oJvg+ljaa2OJi+VfvCOQ8w==" }, + "node_modules/readable-stream": { + "version": "3.6.2", + "resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-3.6.2.tgz", + "integrity": "sha512-9u/sniCrY3D5WdsERHzHE4G2YCXqoG5FTHUiCC4SIbr6XcLZBY05ya9EKjYek9O5xOAwjGq+1JdGBAS7Q9ScoA==", + "dependencies": { + "inherits": "^2.0.3", + "string_decoder": "^1.1.1", + "util-deprecate": "^1.0.1" + }, + "engines": { + "node": ">= 6" + } + }, "node_modules/readdirp": { "version": "3.6.0", "resolved": "https://registry.npmjs.org/readdirp/-/readdirp-3.6.0.tgz", @@ -405,6 +1214,54 @@ "node": ">=8.10.0" } }, + "node_modules/retry": { + "version": "0.12.0", + "resolved": "https://registry.npmjs.org/retry/-/retry-0.12.0.tgz", + "integrity": "sha512-9LkiTwjUh6rT555DtE9rTX+BKByPfrMzEAtnlEtdEwr3Nkffwiihqe2bWADg+OQRjt9gl6ICdmB/ZFDCGAtSow==", + "optional": true, + "engines": { + "node": ">= 4" + } + }, + "node_modules/rimraf": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/rimraf/-/rimraf-3.0.2.tgz", + "integrity": "sha512-JZkJMZkAGFFPP2YqXZXPbMlMBgsxzE8ILs4lMIX/2o0L9UBw9O/Y3o6wFw/i9YLapcUJWwqbi3kdxIPdC62TIA==", + "dependencies": { + "glob": "^7.1.3" + }, + "bin": { + "rimraf": "bin.js" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/safe-buffer": { + "version": "5.2.1", + "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz", + "integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==", + "funding": [ + { + "type": "github", + "url": "https://github.com/sponsors/feross" + }, + { + "type": "patreon", + "url": "https://www.patreon.com/feross" + }, + { + "type": "consulting", + "url": "https://feross.org/support" + } + ] + }, + "node_modules/safer-buffer": { + "version": "2.1.2", + "resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz", + "integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==", + "optional": true + }, "node_modules/semver": { "version": "5.7.1", "resolved": "https://registry.npmjs.org/semver/-/semver-5.7.1.tgz", @@ -413,6 +1270,16 @@ "semver": "bin/semver" } }, + "node_modules/set-blocking": { + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/set-blocking/-/set-blocking-2.0.0.tgz", + "integrity": "sha512-KiKBS8AnWGEyLzofFfmvKwpdPzqiy16LvQfK3yv/fVH7Bj13/wl3JSR1J+rfgRE9q7xUJK4qvgS8raSOeLUehw==" + }, + "node_modules/signal-exit": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/signal-exit/-/signal-exit-3.0.7.tgz", + "integrity": "sha512-wnD2ZE+l+SPC/uoS0vXeE9L1+0wuaMqKlfz9AMUo38JsyLSBWSFcHR1Rri62LZc12vLr1gb3jl7iwQhgwpAbGQ==" + }, "node_modules/simple-update-notifier": { "version": "1.1.0", "resolved": "https://registry.npmjs.org/simple-update-notifier/-/simple-update-notifier-1.1.0.tgz", @@ -432,6 +1299,110 @@ "semver": "bin/semver.js" } }, + "node_modules/smart-buffer": { + "version": "4.2.0", + "resolved": "https://registry.npmjs.org/smart-buffer/-/smart-buffer-4.2.0.tgz", + "integrity": "sha512-94hK0Hh8rPqQl2xXc3HsaBoOXKV20MToPkcXvwbISWLEs+64sBq5kFgn2kJDHb1Pry9yrP0dxrCI9RRci7RXKg==", + "optional": true, + "engines": { + "node": ">= 6.0.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks": { + "version": "2.7.1", + "resolved": "https://registry.npmjs.org/socks/-/socks-2.7.1.tgz", + "integrity": "sha512-7maUZy1N7uo6+WVEX6psASxtNlKaNVMlGQKkG/63nEDdLOWNbiUMoLK7X4uYoLhQstau72mLgfEWcXcwsaHbYQ==", + "optional": true, + "dependencies": { + "ip": "^2.0.0", + "smart-buffer": "^4.2.0" + }, + "engines": { + "node": ">= 10.13.0", + "npm": ">= 3.0.0" + } + }, + "node_modules/socks-proxy-agent": { + "version": "6.2.1", + "resolved": "https://registry.npmjs.org/socks-proxy-agent/-/socks-proxy-agent-6.2.1.tgz", + "integrity": "sha512-a6KW9G+6B3nWZ1yB8G7pJwL3ggLy1uTzKAgCb7ttblwqdz9fMGJUuTy3uFzEP48FAs9FLILlmzDlE2JJhVQaXQ==", + "optional": true, + "dependencies": { + "agent-base": "^6.0.2", + "debug": "^4.3.3", + "socks": "^2.6.2" + }, + "engines": { + "node": ">= 10" + } + }, + "node_modules/sqlite3": { + "version": "5.1.5", + "resolved": "https://registry.npmjs.org/sqlite3/-/sqlite3-5.1.5.tgz", + "integrity": "sha512-7sP16i4wI+yKnGOO2q2ijze7EjQ9US+Vw7DYYwxfFtqNZDGgBcEw0oeDaDvUTq66uJOzVd/z6MkIg+c9erSJKg==", + "hasInstallScript": true, + "dependencies": { + "@mapbox/node-pre-gyp": "^1.0.0", + "node-addon-api": "^4.2.0", + "tar": "^6.1.11" + }, + "optionalDependencies": { + "node-gyp": "8.x" + }, + "peerDependencies": { + "node-gyp": "8.x" + }, + "peerDependenciesMeta": { + "node-gyp": { + "optional": true + } + } + }, + "node_modules/ssri": { + "version": "8.0.1", + "resolved": "https://registry.npmjs.org/ssri/-/ssri-8.0.1.tgz", + "integrity": "sha512-97qShzy1AiyxvPNIkLWoGua7xoQzzPjQ0HAH4B0rWKo7SZ6USuPcrUiAFrws0UH8RrbWmgq3LMTObhPIHbbBeQ==", + "optional": true, + "dependencies": { + "minipass": "^3.1.1" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/string_decoder": { + "version": "1.3.0", + "resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-1.3.0.tgz", + "integrity": "sha512-hkRX8U1WjJFd8LsDJ2yQ/wWWxaopEsABU1XfkM8A+j0+85JAGppt16cr1Whg6KIbb4okU6Mql6BOj+uup/wKeA==", + "dependencies": { + "safe-buffer": "~5.2.0" + } + }, + "node_modules/string-width": { + "version": "4.2.3", + "resolved": "https://registry.npmjs.org/string-width/-/string-width-4.2.3.tgz", + "integrity": "sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==", + "dependencies": { + "emoji-regex": "^8.0.0", + "is-fullwidth-code-point": "^3.0.0", + "strip-ansi": "^6.0.1" + }, + "engines": { + "node": ">=8" + } + }, + "node_modules/strip-ansi": { + "version": "6.0.1", + "resolved": "https://registry.npmjs.org/strip-ansi/-/strip-ansi-6.0.1.tgz", + "integrity": "sha512-Y38VPSHcqkFrCpFnQ9vuSXmquuv5oXOKpGeT6aGrr3o3Gc9AlVa6JBfUSOCnbxGGZF+/0ooI7KrPuUSztUdU5A==", + "dependencies": { + "ansi-regex": "^5.0.1" + }, + "engines": { + "node": ">=8" + } + }, "node_modules/supports-color": { "version": "5.5.0", "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-5.5.0.tgz", @@ -443,6 +1414,30 @@ "node": ">=4" } }, + "node_modules/tar": { + "version": "6.1.13", + "resolved": "https://registry.npmjs.org/tar/-/tar-6.1.13.tgz", + "integrity": "sha512-jdIBIN6LTIe2jqzay/2vtYLlBHa3JF42ot3h1dW8Q0PaAG4v8rm0cvpVePtau5C6OKXGGcgO9q2AMNSWxiLqKw==", + "dependencies": { + "chownr": "^2.0.0", + "fs-minipass": "^2.0.0", + "minipass": "^4.0.0", + "minizlib": "^2.1.1", + "mkdirp": "^1.0.3", + "yallist": "^4.0.0" + }, + "engines": { + "node": ">=10" + } + }, + "node_modules/tar/node_modules/minipass": { + "version": "4.2.5", + "resolved": "https://registry.npmjs.org/minipass/-/minipass-4.2.5.tgz", + "integrity": "sha512-+yQl7SX3bIT83Lhb4BVorMAHVuqsskxRdlmO9kTpyukp8vsm2Sn/fUOV9xlnG8/a5JsypJzap21lz/y3FBMJ8Q==", + "engines": { + "node": ">=8" + } + }, "node_modules/to-regex-range": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/to-regex-range/-/to-regex-range-5.0.1.tgz", @@ -470,11 +1465,39 @@ "nodetouch": "bin/nodetouch.js" } }, + "node_modules/tr46": { + "version": "0.0.3", + "resolved": "https://registry.npmjs.org/tr46/-/tr46-0.0.3.tgz", + "integrity": "sha512-N3WMsuqV66lT30CrXNbEjx4GEwlow3v6rr4mCcv6prnfwhS01rkgyFdjPNBYd9br7LpXV1+Emh01fHnq2Gdgrw==" + }, "node_modules/undefsafe": { "version": "2.0.5", "resolved": "https://registry.npmjs.org/undefsafe/-/undefsafe-2.0.5.tgz", "integrity": "sha512-WxONCrssBM8TSPRqN5EmsjVrsv4A8X12J4ArBiiayv3DyyG3ZlIg6yysuuSYdZsVz3TKcTg2fd//Ujd4CHV1iA==" }, + "node_modules/unique-filename": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/unique-filename/-/unique-filename-1.1.1.tgz", + "integrity": "sha512-Vmp0jIp2ln35UTXuryvjzkjGdRyf9b2lTXuSYUiPmzRcl3FDtYqAwOnTJkAngD9SWhnoJzDbTKwaOrZ+STtxNQ==", + "optional": true, + "dependencies": { + "unique-slug": "^2.0.0" + } + }, + "node_modules/unique-slug": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/unique-slug/-/unique-slug-2.0.2.tgz", + "integrity": "sha512-zoWr9ObaxALD3DOPfjPSqxt4fnZiWblxHIgeWqW8x7UqDzEtHEQLzji2cuJYQFCU6KmoJikOYAZlrTHHebjx2w==", + "optional": true, + "dependencies": { + "imurmurhash": "^0.1.4" + } + }, + "node_modules/util-deprecate": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/util-deprecate/-/util-deprecate-1.0.2.tgz", + "integrity": "sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==" + }, "node_modules/web-streams-polyfill": { "version": "3.2.1", "resolved": "https://registry.npmjs.org/web-streams-polyfill/-/web-streams-polyfill-3.2.1.tgz", @@ -482,6 +1505,53 @@ "engines": { "node": ">= 8" } + }, + "node_modules/webidl-conversions": { + "version": "3.0.1", + "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-3.0.1.tgz", + "integrity": "sha512-2JAn3z8AR6rjK8Sm8orRC0h/bcl/DqL7tRPdGZ4I1CjdF+EaMLmYxBHyXuKL849eucPFhvBoxMsflfOb8kxaeQ==" + }, + "node_modules/whatwg-url": { + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-5.0.0.tgz", + "integrity": "sha512-saE57nupxk6v3HY35+jzBwYa0rKSy0XR8JSxZPwgLr7ys0IBzhGviA1/TUGJLmSVqs8pb9AnvICXEuOHLprYTw==", + "dependencies": { + "tr46": "~0.0.3", + "webidl-conversions": "^3.0.0" + } + }, + "node_modules/which": { + "version": "2.0.2", + "resolved": "https://registry.npmjs.org/which/-/which-2.0.2.tgz", + "integrity": "sha512-BLI3Tl1TW3Pvl70l3yq3Y64i+awpwXqsGBYWkkqMtnbXgrMD+yj7rhW0kuEDxzJaYXGjEW5ogapKNMEKNMjibA==", + "optional": true, + "dependencies": { + "isexe": "^2.0.0" + }, + "bin": { + "node-which": "bin/node-which" + }, + "engines": { + "node": ">= 8" + } + }, + "node_modules/wide-align": { + "version": "1.1.5", + "resolved": "https://registry.npmjs.org/wide-align/-/wide-align-1.1.5.tgz", + "integrity": "sha512-eDMORYaPNZ4sQIuuYPDHdQvf4gyCF9rEEV/yPxGfwPkRodwEgiMUUXTx/dex+Me0wxx53S+NgUHaP7y3MGlDmg==", + "dependencies": { + "string-width": "^1.0.2 || 2 || 3 || 4" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha512-l4Sp/DRseor9wL6EvV2+TuQn63dMkPjZ/sp9XkghTEbV9KlPS1xUsZ3u7/IQO4wxtcFB4bgpQPRcR3QCvezPcQ==" + }, + "node_modules/yallist": { + "version": "4.0.0", + "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", + "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==" } } } diff --git a/test/package.json b/test/package.json index 5d6aff80..3bab3f87 100644 --- a/test/package.json +++ b/test/package.json @@ -13,6 +13,7 @@ "dependencies": { "cloudflare-worker-adapter": "github:TBXark/cloudflare-worker-adapter", "https-proxy-agent": "^5.0.1", - "nodemon": "^2.0.21" + "nodemon": "^2.0.21", + "sqlite3": "^5.1.5" } } diff --git a/test/sqlite.js b/test/sqlite.js new file mode 100644 index 00000000..13c00ab3 --- /dev/null +++ b/test/sqlite.js @@ -0,0 +1,55 @@ +import sqlite3 from "sqlite3"; + +export class SqliteCache { + constructor(path) { + this.db = new sqlite3.Database(path); + this.db.run("CREATE TABLE IF NOT EXISTS cache (key TEXT PRIMARY KEY, value TEXT, expiration INTEGER)"); + } + + async get(key, info) { + return new Promise((resolve, reject) => { + this.db.get("SELECT value FROM cache WHERE key = ?", key, (err, row) => { + if (err) { + reject(err); + } else { + if (row && row.expiration && row.expiration > 0 && row.expiration < Date.now()) { + this.delete(key); + resolve(null); + } else { + resolve(row?.value); + } + } + }); + }); + } + + async put(key, value, info) { + let expiration = -1 + if (info && info.expiration) { + expiration = Math.round(info.expiration); + } else if (info && info.expirationTtl) { + expiration = Math.round(Date.now() + info.expirationTtl * 1000); + } + return new Promise((resolve, reject) => { + this.db.run("INSERT OR REPLACE INTO cache (key, value, expiration) VALUES (?, ?, ?)", key, value, expiration, (err) => { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }) + } + + async delete(key) { + return new Promise((resolve, reject) => { + this.db.run("DELETE FROM cache WHERE key = ?", key, (err) => { + if (err) { + reject(err); + } else { + resolve(); + } + }); + }) + } +} \ No newline at end of file From 95720b1717374bd711e364da319c4ec5baf805b6 Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 13:30:43 +0800 Subject: [PATCH 16/24] doc: update test readme --- test/README.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index 7bd7cab2..7f66d218 100644 --- a/test/README.md +++ b/test/README.md @@ -35,5 +35,11 @@ npm run start 4. 数据库 -我这里一共写了三种KV的实现`LocalCache`, `MemoryCache`, `RemoteCache`. -这里推荐使用本地数据库存储,如果使用内存数据库可能导致数据丢失。当然你也可以使用远程数据库,但是这个可能比较慢,还需要你单独部署一个workers来实现。详情你可以到[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter)查看源代码 +在[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter)一共写了三种KV的实现`LocalCache`, `MemoryCache`, `RemoteCache`. +这里推荐使用本地数据库存储,如果使用内存数据库可能导致数据丢失。当然你也可以使用远程数据库,但是这个可能比较慢,还需要你单独部署一个workers来实现。详情你可以到[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter)查看源代码。 + +这个测试例子里我用sqlite3来实现的。你可以自行实现自己的存储逻辑。 + +5. 代理环境 + +由于调用了telegram的api,所以必须要给`fetch`代理环境。默认会读取`config.json`里的`https_proxy`字段。如果没有配置这个字段则会读取环境变量`https_proxy`。如果都没有配置则不会代理。但是这样可能会导致请求telegram的api失败。 From fe8feefa7d720ccad98561272e314894f3fc0546 Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 13:37:07 +0800 Subject: [PATCH 17/24] =?UTF-8?q?pref:=20sqlite3=E7=BC=93=E5=AD=98?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E8=BD=AC=E7=A7=BB=E8=87=B3cloudflare-worker-?= =?UTF-8?q?adapter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/index.js | 2 +- test/package-lock.json | 6 ++--- test/package.json | 3 +-- test/sqlite.js | 55 ------------------------------------------ 4 files changed, 5 insertions(+), 61 deletions(-) delete mode 100644 test/sqlite.js diff --git a/test/index.js b/test/index.js index eb22c10c..404990c3 100644 --- a/test/index.js +++ b/test/index.js @@ -1,6 +1,6 @@ import adapter, { bindGlobal } from 'cloudflare-worker-adapter' import worker from '../main.js' -import { SqliteCache } from './sqlite.js' +import { SqliteCache } from 'cloudflare-worker-adapter/cache/sqlite.js' import fs from 'fs' import HttpsProxyAgent from 'https-proxy-agent' import fetch from 'node-fetch' diff --git a/test/package-lock.json b/test/package-lock.json index 2aa63073..630804fd 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -11,8 +11,7 @@ "dependencies": { "cloudflare-worker-adapter": "github:TBXark/cloudflare-worker-adapter", "https-proxy-agent": "^5.0.1", - "nodemon": "^2.0.21", - "sqlite3": "^5.1.5" + "nodemon": "^2.0.21" } }, "node_modules/@gar/promisify": { @@ -322,10 +321,11 @@ }, "node_modules/cloudflare-worker-adapter": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/TBXark/cloudflare-worker-adapter.git#b64cb0a606c84de11338de6bac7a5611c181adfb", + "resolved": "git+ssh://git@github.com/TBXark/cloudflare-worker-adapter.git#8150c8d6fef57e84dfc4375d0c35dbabf2729169", "license": "MIT", "dependencies": { "node-fetch": "^3.2.3", + "sqlite3": "^5.1.5", "toml": "^3.0.0" } }, diff --git a/test/package.json b/test/package.json index 3bab3f87..5d6aff80 100644 --- a/test/package.json +++ b/test/package.json @@ -13,7 +13,6 @@ "dependencies": { "cloudflare-worker-adapter": "github:TBXark/cloudflare-worker-adapter", "https-proxy-agent": "^5.0.1", - "nodemon": "^2.0.21", - "sqlite3": "^5.1.5" + "nodemon": "^2.0.21" } } diff --git a/test/sqlite.js b/test/sqlite.js deleted file mode 100644 index 13c00ab3..00000000 --- a/test/sqlite.js +++ /dev/null @@ -1,55 +0,0 @@ -import sqlite3 from "sqlite3"; - -export class SqliteCache { - constructor(path) { - this.db = new sqlite3.Database(path); - this.db.run("CREATE TABLE IF NOT EXISTS cache (key TEXT PRIMARY KEY, value TEXT, expiration INTEGER)"); - } - - async get(key, info) { - return new Promise((resolve, reject) => { - this.db.get("SELECT value FROM cache WHERE key = ?", key, (err, row) => { - if (err) { - reject(err); - } else { - if (row && row.expiration && row.expiration > 0 && row.expiration < Date.now()) { - this.delete(key); - resolve(null); - } else { - resolve(row?.value); - } - } - }); - }); - } - - async put(key, value, info) { - let expiration = -1 - if (info && info.expiration) { - expiration = Math.round(info.expiration); - } else if (info && info.expirationTtl) { - expiration = Math.round(Date.now() + info.expirationTtl * 1000); - } - return new Promise((resolve, reject) => { - this.db.run("INSERT OR REPLACE INTO cache (key, value, expiration) VALUES (?, ?, ?)", key, value, expiration, (err) => { - if (err) { - reject(err); - } else { - resolve(); - } - }); - }) - } - - async delete(key) { - return new Promise((resolve, reject) => { - this.db.run("DELETE FROM cache WHERE key = ?", key, (err) => { - if (err) { - reject(err); - } else { - resolve(); - } - }); - }) - } -} \ No newline at end of file From a6e347bc7b135244382e2645cc7de5ebce6d5629 Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 13:44:20 +0800 Subject: [PATCH 18/24] =?UTF-8?q?pref:=20wrangler.toml=20=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E6=94=B9=E4=B8=BA=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6?= =?UTF-8?q?=E4=BC=A0=E5=85=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/README.md | 2 +- test/index.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/test/README.md b/test/README.md index 7f66d218..4948f408 100644 --- a/test/README.md +++ b/test/README.md @@ -35,7 +35,7 @@ npm run start 4. 数据库 -在[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter)一共写了三种KV的实现`LocalCache`, `MemoryCache`, `RemoteCache`. +在[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter)一共写了4种KV的实现`LocalCache`, `MemoryCache`, `RemoteCache`, `SqliteCache`。 这里推荐使用本地数据库存储,如果使用内存数据库可能导致数据丢失。当然你也可以使用远程数据库,但是这个可能比较慢,还需要你单独部署一个workers来实现。详情你可以到[cloudflare-worker-adapter](https://github.com/tbxark/cloudflare-worker-adapter)查看源代码。 这个测试例子里我用sqlite3来实现的。你可以自行实现自己的存储逻辑。 diff --git a/test/index.js b/test/index.js index 404990c3..ada66439 100644 --- a/test/index.js +++ b/test/index.js @@ -21,4 +21,4 @@ if (proxy) { }) } -adapter.startServer(config.port, config.host, '../wrangler.toml', {DATABASE: cache}, {server: config.server}, worker.fetch) +adapter.startServer(config.port, config.host, config.toml, {DATABASE: cache}, {server: config.server}, worker.fetch) From 9df7117ea3da16c3ea8c094e2e9245535bc7121b Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 14:59:59 +0800 Subject: [PATCH 19/24] =?UTF-8?q?pref:=20=E6=B5=8B=E8=AF=95=E8=84=9A?= =?UTF-8?q?=E6=9C=AC=E5=8A=A0=E8=BD=BD=E6=9C=AC=E5=9C=B0=E7=89=88=E6=9C=AC?= =?UTF-8?q?=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/README.md | 5 +++++ test/index.js | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/test/README.md b/test/README.md index 4948f408..2cce7ff0 100644 --- a/test/README.md +++ b/test/README.md @@ -43,3 +43,8 @@ npm run start 5. 代理环境 由于调用了telegram的api,所以必须要给`fetch`代理环境。默认会读取`config.json`里的`https_proxy`字段。如果没有配置这个字段则会读取环境变量`https_proxy`。如果都没有配置则不会代理。但是这样可能会导致请求telegram的api失败。 + + +6. 调试 + +使用vscode调试的时候,要在`package.json`里按`debug`按钮,并选择对于脚本才能进行调试。 \ No newline at end of file diff --git a/test/index.js b/test/index.js index ada66439..52d30808 100644 --- a/test/index.js +++ b/test/index.js @@ -1,5 +1,4 @@ import adapter, { bindGlobal } from 'cloudflare-worker-adapter' -import worker from '../main.js' import { SqliteCache } from 'cloudflare-worker-adapter/cache/sqlite.js' import fs from 'fs' import HttpsProxyAgent from 'https-proxy-agent' @@ -21,4 +20,15 @@ if (proxy) { }) } +try { + const buildInfo = JSON.parse(fs.readFileSync('../dist/buildinfo.json', 'utf-8')) + process.env.BUILD_TIMESTAMP = buildInfo.timestamp + process.env.BUILD_VERSION = buildInfo.sha + console.log(buildInfo) +} catch (e) { + console.log(e) +} + +// 延迟加载 ../main.js, 防止ENV过早初始化 +const { default: worker } = await import('../main.js') adapter.startServer(config.port, config.host, config.toml, {DATABASE: cache}, {server: config.server}, worker.fetch) From 39428bc59e9b5ee7d9efb32370497735a0fab49e Mon Sep 17 00:00:00 2001 From: TBXark Date: Tue, 14 Mar 2023 15:21:46 +0800 Subject: [PATCH 20/24] =?UTF-8?q?doc:=20=E8=B0=83=E8=AF=95=E6=8C=87?= =?UTF-8?q?=E5=8D=97=E6=B7=BB=E5=8A=A0=E5=B7=B2=E7=9F=A5BUG=E8=AF=B4?= =?UTF-8?q?=E6=98=8E?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/gpt3.js | 1 - test/README.md | 5 +++++ test/package-lock.json | 2 +- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/gpt3.js b/src/gpt3.js index 5e947e3e..d1bfe558 100644 --- a/src/gpt3.js +++ b/src/gpt3.js @@ -27,7 +27,6 @@ async function resourceLoader(key, url) { } export async function gpt3TokensCounter() { - console.log('gpt3TokensCounter loading...'); const repo = 'https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master'; const encoder = await resourceLoader('encoder_raw_file', `${repo}/encoder.json`).then((x) => JSON.parse(x)); const bpe_file = await resourceLoader('bpe_raw_file', `${repo}/vocab.bpe`); diff --git a/test/README.md b/test/README.md index 2cce7ff0..f3ea2050 100644 --- a/test/README.md +++ b/test/README.md @@ -7,6 +7,11 @@ 可以使用vscode断点调试,加上`nodemon`可以实现热更新。 +### 已知BUG + +当前项目使用较多全局变量,在测试环境,这些全局变量只会初始化一次,这就导致每个新的会话可能使用上一个会话的上下文数据。这并不会像cloudflare一样,每次会话都是一个独立的环境。这在多个角色聊天的时候会产生BUG。所以请勿将此用于生产环境。 + + ### 使用步骤 1. 创建`config.json` diff --git a/test/package-lock.json b/test/package-lock.json index 630804fd..fb4123ed 100644 --- a/test/package-lock.json +++ b/test/package-lock.json @@ -321,7 +321,7 @@ }, "node_modules/cloudflare-worker-adapter": { "version": "1.0.0", - "resolved": "git+ssh://git@github.com/TBXark/cloudflare-worker-adapter.git#8150c8d6fef57e84dfc4375d0c35dbabf2729169", + "resolved": "git+ssh://git@github.com/TBXark/cloudflare-worker-adapter.git#c752e98be9957949ba8bf571c4cb7a796a1d311b", "license": "MIT", "dependencies": { "node-fetch": "^3.2.3", From ac085ab54d336132b3603c0ca70c1179927a7e1e Mon Sep 17 00:00:00 2001 From: TBXark Date: Thu, 16 Mar 2023 13:32:27 +0800 Subject: [PATCH 21/24] =?UTF-8?q?pref:=20=E4=BC=98=E5=8C=96makefile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index b832b866..41c4dfb7 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ OUTPUT_FILE := ./dist/index.js ENTRY_FILE := main.js -ifeq (,$(wildcard ./node_modules/.bin)) +ifneq ($(shell test -e ./node_modules/.bin && echo -n yes),yes) PATH := ./node_modules/.bin:$(PATH) endif From b2971166ebc28d30ef696dbd6b3fe9fbf0ecf680 Mon Sep 17 00:00:00 2001 From: TBXark Date: Thu, 16 Mar 2023 13:33:30 +0800 Subject: [PATCH 22/24] build 1.3.1 (39428bc) --- .eslintrc.cjs | 1 - dist/buildinfo.json | 2 +- dist/index.js | 12 ++++++------ dist/timestamp | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.eslintrc.cjs b/.eslintrc.cjs index 24e543bf..9beec18b 100644 --- a/.eslintrc.cjs +++ b/.eslintrc.cjs @@ -1,4 +1,3 @@ -// ignore require-jsdoc module.exports = { 'env': { 'es2021': true, diff --git a/dist/buildinfo.json b/dist/buildinfo.json index 9b71e8d7..f60fe275 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "348cde1", "timestamp": 1678685006} +{"sha": "39428bc", "timestamp": 1678944669} diff --git a/dist/index.js b/dist/index.js index e9a8be57..29dd1f9f 100644 --- a/dist/index.js +++ b/dist/index.js @@ -40,9 +40,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678685006, + BUILD_TIMESTAMP: 1678944669, // 当前版本 commit id - BUILD_VERSION: "348cde1", + BUILD_VERSION: "39428bc", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, @@ -464,7 +464,6 @@ async function resourceLoader(key, url) { return null; } async function gpt3TokensCounter() { - console.log("gpt3TokensCounter loading..."); const repo = "https://raw.githubusercontent.com/tbxark-archive/GPT-3-Encoder/master"; const encoder = await resourceLoader("encoder_raw_file", `${repo}/encoder.json`).then((x) => JSON.parse(x)); const bpe_file = await resourceLoader("bpe_raw_file", `${repo}/vocab.bpe`); @@ -923,11 +922,12 @@ async function commandFetchUpdate(message, command, subcommand) { ts: ENV.BUILD_TIMESTAMP, sha: ENV.BUILD_VERSION }; - const ts = `https://raw.githubusercontent.com/TBXark/ChatGPT-Telegram-Workers/${ENV.UPDATE_BRANCH}/dist/timestamp`; - const info = `https://raw.githubusercontent.com/TBXark/ChatGPT-Telegram-Workers/${ENV.UPDATE_BRANCH}/dist/buildinfo.json`; + const repo = `https://raw.githubusercontent.com/TBXark/ChatGPT-Telegram-Workers/${ENV.UPDATE_BRANCH}`; + const ts = `${repo}/dist/timestamp`; + const info = `${repo}/dist/buildinfo.json`; let online = await fetch(info, config).then((r) => r.json()).catch(() => null); if (!online) { - online = await fetch(ts).then((r) => r.text()).then((ts2) => ({ ts: Number(ts2.trim()), sha: "unknown" })).catch(() => ({ ts: 0, sha: "unknown" })); + online = await fetch(ts, config).then((r) => r.text()).then((ts2) => ({ ts: Number(ts2.trim()), sha: "unknown" })).catch(() => ({ ts: 0, sha: "unknown" })); } if (current.ts < online.ts) { return sendMessageToTelegram( diff --git a/dist/timestamp b/dist/timestamp index 9b164ed8..daba44de 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678685006 +1678944669 From 9e238460ccce89c1bfbf30e0fc80e0e994c6dbf6 Mon Sep 17 00:00:00 2001 From: TBXark Date: Thu, 16 Mar 2023 13:46:39 +0800 Subject: [PATCH 23/24] fix: makefile --- Makefile | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 41c4dfb7..0a856a86 100644 --- a/Makefile +++ b/Makefile @@ -3,9 +3,8 @@ BUILD_INFO_JSON := ./dist/buildinfo.json OUTPUT_FILE := ./dist/index.js ENTRY_FILE := main.js - -ifneq ($(shell test -e ./node_modules/.bin && echo -n yes),yes) - PATH := ./node_modules/.bin:$(PATH) +ifeq ($(shell if [ -d "./node_modules/.bin" ]; then echo "yes"; else echo "no"; fi),yes) + PATH := ./node_modules/.bin:$(PATH) endif .PHONY: build From 68467c0077fd3a789b9a1e71a46484f02de80c95 Mon Sep 17 00:00:00 2001 From: TBXark Date: Thu, 16 Mar 2023 13:49:12 +0800 Subject: [PATCH 24/24] =?UTF-8?q?pref:=20=E9=BB=98=E8=AE=A4=E5=BC=80?= =?UTF-8?q?=E5=90=AFGPT3=E7=9A=84TOKEN=E8=AE=A1=E6=95=B0=E6=A8=A1=E5=BC=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- dist/buildinfo.json | 2 +- dist/index.js | 6 +++--- dist/timestamp | 2 +- src/env.js | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/dist/buildinfo.json b/dist/buildinfo.json index f60fe275..9511973e 100644 --- a/dist/buildinfo.json +++ b/dist/buildinfo.json @@ -1 +1 @@ -{"sha": "39428bc", "timestamp": 1678944669} +{"sha": "9e23846", "timestamp": 1678945730} diff --git a/dist/index.js b/dist/index.js index 29dd1f9f..f3ee0ad8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -28,7 +28,7 @@ var ENV = { // 最大消息长度 MAX_TOKEN_LENGTH: 2048, // 使用GPT3的TOKEN计数 - GPT3_TOKENS_COUNT: false, + GPT3_TOKENS_COUNT: true, // 全局默认初始化消息 SYSTEM_INIT_MESSAGE: "\u4F60\u662F\u4E00\u4E2A\u5F97\u529B\u7684\u52A9\u624B", // 全局默认初始化消息角色 @@ -40,9 +40,9 @@ var ENV = { // 检查更新的分支 UPDATE_BRANCH: "master", // 当前版本 - BUILD_TIMESTAMP: 1678944669, + BUILD_TIMESTAMP: 1678945730, // 当前版本 commit id - BUILD_VERSION: "39428bc", + BUILD_VERSION: "9e23846", // DEBUG 专用 // 调试模式 DEBUG_MODE: false, diff --git a/dist/timestamp b/dist/timestamp index daba44de..c1c0ba7b 100644 --- a/dist/timestamp +++ b/dist/timestamp @@ -1 +1 @@ -1678944669 +1678945730 diff --git a/src/env.js b/src/env.js index 2768a90c..344ff79e 100644 --- a/src/env.js +++ b/src/env.js @@ -32,7 +32,7 @@ export const ENV = { // 最大消息长度 MAX_TOKEN_LENGTH: 2048, // 使用GPT3的TOKEN计数 - GPT3_TOKENS_COUNT: false, + GPT3_TOKENS_COUNT: true, // 全局默认初始化消息 SYSTEM_INIT_MESSAGE: '你是一个得力的助手',