teralomaniac
commited on
Commit
•
fbec572
1
Parent(s):
ff5d17e
12
Browse files- clewd.js +25 -31
- lib/clewd-stream.js +2 -2
- lib/clewd-superfetch.js +2 -2
- lib/clewd-utils.js +3 -3
clewd.js
CHANGED
@@ -23,12 +23,13 @@ CookieChanger.on('ChangeCookie', () => {
|
|
23 |
});
|
24 |
|
25 |
const convertToType = value => {
|
26 |
-
if (value ===
|
27 |
-
if (value ===
|
28 |
if (/^\d+$/.test(value)) return parseInt(value);
|
29 |
return value;
|
30 |
}, CookieCleaner = () => {
|
31 |
-
Config.CookieArray
|
|
|
32 |
writeSettings(Config);
|
33 |
currentIndex = (currentIndex - 1 + Config.CookieArray.length) % Config.CookieArray.length;
|
34 |
}, padtxt = content => {
|
@@ -39,24 +40,24 @@ const convertToType = value => {
|
|
39 |
content = content.includes('<|padtxt|>') ? content.replace(/<\|padtxt\|>/, padding) : !apiKey ? padding + '\n\n\n' + content.trim() : content;
|
40 |
return content;
|
41 |
}, xmlPlot = (content, nonsys = false) => {
|
42 |
-
const card = content.includes('<card>');
|
43 |
//role合并
|
44 |
-
const MergeDisable = content.includes('
|
45 |
-
const MergeHumanDisable = content.includes('
|
46 |
-
const MergeAssistantDisable = content.includes('
|
47 |
if (!MergeDisable) {
|
48 |
-
if (content.includes('
|
49 |
content = content.replace(/(\n\n|^\s*)xmlPlot:\s*/gm, '$1');
|
50 |
}
|
51 |
if (!MergeHumanDisable) {
|
52 |
-
nonsys ? content = content.replace(/(\n\n|^\s*)xmlPlot:/g, '\n\nHuman:') : content = content.replace(/(?<!\n\n(Human|Assistant):.*?)(\n\n|^\s*)xmlPlot
|
53 |
content = content.replace(/(?:\n\n|^\s*)Human:(.*?(?:\n\nAssistant:|$))/gs, function(match, p1) {return '\n\nHuman:' + p1.replace(/\n\nHuman:\s*/g, '\n\n')});
|
54 |
}
|
55 |
if (!MergeAssistantDisable) {
|
56 |
content = content.replace(/\n\nAssistant:(.*?(?:\n\nHuman:|$))/gs, function(match, p1) {return '\n\nAssistant:' + p1.replace(/\n\nAssistant:\s*/g, '\n\n')});
|
57 |
}
|
58 |
}
|
59 |
-
content = content.replace(/(\n\n|^\s*)xmlPlot:\s*/gm, '$1')
|
60 |
//自定义插入
|
61 |
content = content.replace(/(<\/?)PrevAssistant>/gm, '$1@1>').replace(/(<\/?)PrevHuman>/gm, '$1@2>');
|
62 |
let splitContent = content.split(/\n\n(?=Assistant:|Human:)/g);
|
@@ -90,39 +91,30 @@ const convertToType = value => {
|
|
90 |
//Plain Prompt
|
91 |
let segcontentHuman = content.split('\n\nHuman:');
|
92 |
let segcontentlastIndex = segcontentHuman.length - 1;
|
93 |
-
if (!apiKey && segcontentlastIndex >= 2 && segcontentHuman[segcontentlastIndex].includes('
|
94 |
content = segcontentHuman.slice(0, segcontentlastIndex).join('\n\nHuman:') + '\n\nPlainPrompt:' + segcontentHuman.slice(segcontentlastIndex).join('\n\nHuman:').replace(/\n\nHuman: *PlainPrompt:/, '\n\nPlainPrompt:');
|
95 |
}
|
96 |
-
content = content.replace(/<\!-- Plain Prompt Enable -->/gm, '');
|
97 |
//<card>群组
|
98 |
if (!card) {
|
99 |
return content.replace(/(<reply>\n|\n<\/reply>)/g, '').replace(/<customname>(.*?)<\/customname>/gm, '$1');
|
100 |
} else {
|
101 |
content = content.replace(/(<reply>\n|\n<\/reply>)\1*/g, '$1').replace(/<customname>(.*?)<\/customname>:/gm, '$1:\n');
|
102 |
}
|
103 |
-
//<card>在第一个"[Start a new"前面加上"<example>",在最后一个"[Start a new"前面加上"</example>\n\n<plot>\n\n"
|
104 |
-
const cardtag = content.match(/(?=\n\n<\/card>)/) || '</card>';
|
105 |
-
const exampletag = content.match(/(?=\n\n<\/example>)/) || '</example>';
|
106 |
-
const plot = content.includes('</plot>') ? '<plot>' : '';
|
107 |
-
const firstChatStart = content.indexOf('\n\n[Start a new');
|
108 |
-
const lastChatStart = content.lastIndexOf('\n\n[Start a new');
|
109 |
-
firstChatStart != -1 && firstChatStart === lastChatStart && (content = content.slice(0, firstChatStart) + `\n\n${cardtag}` + content.slice(firstChatStart));
|
110 |
-
firstChatStart != lastChatStart && (content = content.slice(0, firstChatStart) + `\n\n${cardtag}\n<example>` + content.slice(firstChatStart, lastChatStart) + `\n\n${exampletag}\n\n${plot}` + content.slice(lastChatStart));
|
111 |
//<card>消除空XML tags、两端空白符和多余的\n
|
112 |
content = content.replace(/\s*<\|curtail\|>\s*/g, '\n')
|
113 |
.replace(/\n<\/(card|hidden|META)>\s+?<\1>\n/g, '\n')
|
114 |
.replace(/\n<(\/?card|example|hidden|plot|META)>\s+?<\1>/g, '\n<$1>')
|
115 |
-
.replace(
|
116 |
.replace(/(?<=(: |\n)<(card|hidden|example|plot|META|EOT)>\n)\s*/g, '')
|
117 |
.replace(/\s*(?=\n<\/(card|hidden|example|plot|META|EOT)>(\n|$))/g, '')
|
118 |
.replace(/(?<=\n)\n(?=\n)/g, '');
|
119 |
//确保格式正确
|
120 |
if (apiKey) {
|
121 |
content = content.replace(/\n\n(Assistant|Human):(?!.*?\n\n(Assistant|Human):).*$/s, function(match, p1) {return p1 === 'Assistant' ? match : match + '\n\nAssistant: '}).replace(/\s*<\|noAssistant\|>\s*(.*?)(?:\n\nAssistant:\s*)?$/s, '\n\n$1');
|
122 |
-
content.includes('<|reverseHA|>') && (content = content.replace(/\s*<\|reverseHA\|>\s*/g, '\n\n').replace(/\n
|
123 |
-
return content.trim().replace(/^(Human|Assistant):/, '\n\n$&').replace(/\n\n(Human|Assistant):$/, '$& ');
|
124 |
} else {
|
125 |
-
return content.trim().replace(/^Human:|\n\nAssistant:$/g, '');
|
126 |
}
|
127 |
};
|
128 |
/******************************************************* */
|
@@ -253,7 +245,7 @@ const updateParams = res => {
|
|
253 |
try {
|
254 |
/***************************** */
|
255 |
if ('SET YOUR COOKIE HERE' === Config.Cookie || Config.Cookie?.length < 1) {
|
256 |
-
throw Error('Set your cookie inside config.js');
|
257 |
}
|
258 |
updateCookies(Config.Cookie.replace(/^(sessionKey=)?/, 'sessionKey=')); //updateCookies(Config.Cookie);
|
259 |
//console.log(`[2m${Main}[0m\n[33mhttp://${Config.Ip}:${Config.Port}/v1[0m\n\n${Object.keys(Config.Settings).map((setting => UnknownSettings.includes(setting) ? `??? [31m${setting}: ${Config.Settings[setting]}[0m` : `[1m${setting}:[0m ${ChangedSettings.includes(setting) ? '[33m' : '[36m'}${Config.Settings[setting]}[0m`)).sort().join('\n')}\n`);
|
@@ -437,12 +429,14 @@ const updateParams = res => {
|
|
437 |
const body = JSON.parse(Buffer.concat(buffer).toString()), temperature = Math.max(.1, Math.min(1, body.temperature));
|
438 |
let {messages} = body;
|
439 |
/************************* */
|
440 |
-
apiKey = /
|
441 |
let api_max_tokens, api_model;
|
442 |
if (apiKey) {
|
443 |
-
apiKey = apiKey[0];
|
444 |
api_max_tokens = body.max_tokens;
|
445 |
api_model = body.model;
|
|
|
|
|
|
|
446 |
} else if (Config.ProxyPassword != '' && req.headers.authorization != 'Bearer ' + Config.ProxyPassword) {
|
447 |
throw Error('ProxyPassword Wrong');
|
448 |
}
|
@@ -682,7 +676,7 @@ const updateParams = res => {
|
|
682 |
signal,
|
683 |
headers: {
|
684 |
'Content-Type': 'application/json',
|
685 |
-
'x-api-key': apiKey,
|
686 |
'anthropic-version': '2023-06-01'
|
687 |
},
|
688 |
body: JSON.stringify({
|
@@ -857,14 +851,14 @@ const updateParams = res => {
|
|
857 |
for (let key in Config) {
|
858 |
if (key === 'Settings') {
|
859 |
for (let setting in Config.Settings) {
|
860 |
-
Config.Settings[setting] = convertToType(process.env[setting])
|
861 |
}
|
862 |
} else {
|
863 |
-
Config[key] =
|
864 |
}
|
865 |
}
|
866 |
Config.rProxy = Config.rProxy ? Config.rProxy.replace(/\/$/, '') : AI.end();
|
867 |
-
Config.CookieArray = [...new Set(Config.CookieArray)];
|
868 |
writeSettings(Config);
|
869 |
currentIndex = Config.CookieIndex > 0 ? Config.CookieIndex - 1 : Config.Cookiecounter >= 0 ? Math.floor(Math.random() * Config.CookieArray.length) : 0;
|
870 |
/***************************** */
|
|
|
23 |
});
|
24 |
|
25 |
const convertToType = value => {
|
26 |
+
if (value === 'true') return true;
|
27 |
+
if (value === 'false') return false;
|
28 |
if (/^\d+$/.test(value)) return parseInt(value);
|
29 |
return value;
|
30 |
}, CookieCleaner = () => {
|
31 |
+
Config.CookieArray.splice(Config.CookieArray.indexOf(Config.Cookie), 1);
|
32 |
+
Config.Cookie = '';
|
33 |
writeSettings(Config);
|
34 |
currentIndex = (currentIndex - 1 + Config.CookieArray.length) % Config.CookieArray.length;
|
35 |
}, padtxt = content => {
|
|
|
40 |
content = content.includes('<|padtxt|>') ? content.replace(/<\|padtxt\|>/, padding) : !apiKey ? padding + '\n\n\n' + content.trim() : content;
|
41 |
return content;
|
42 |
}, xmlPlot = (content, nonsys = false) => {
|
43 |
+
const card = content.includes('<card>') || content.includes('<|card|>');
|
44 |
//role合并
|
45 |
+
const MergeDisable = content.includes('<|Merge Disable|>');
|
46 |
+
const MergeHumanDisable = content.includes('<|Merge Human Disable|>');
|
47 |
+
const MergeAssistantDisable = content.includes('<|Merge Assistant Disable|>');
|
48 |
if (!MergeDisable) {
|
49 |
+
if (content.includes('<|Merge System Disable|>')) {
|
50 |
content = content.replace(/(\n\n|^\s*)xmlPlot:\s*/gm, '$1');
|
51 |
}
|
52 |
if (!MergeHumanDisable) {
|
53 |
+
nonsys ? content = content.replace(/(\n\n|^\s*)xmlPlot:/g, '\n\nHuman:') : content = content.replace(/(\n\n|^\s*)(?<!\n\n(Human|Assistant):.*?)xmlPlot:\s*/gs, '$1').replace(/(\n\n|^\s*)xmlPlot:/g, '\n\nHuman:');
|
54 |
content = content.replace(/(?:\n\n|^\s*)Human:(.*?(?:\n\nAssistant:|$))/gs, function(match, p1) {return '\n\nHuman:' + p1.replace(/\n\nHuman:\s*/g, '\n\n')});
|
55 |
}
|
56 |
if (!MergeAssistantDisable) {
|
57 |
content = content.replace(/\n\nAssistant:(.*?(?:\n\nHuman:|$))/gs, function(match, p1) {return '\n\nAssistant:' + p1.replace(/\n\nAssistant:\s*/g, '\n\n')});
|
58 |
}
|
59 |
}
|
60 |
+
content = content.replace(/(\n\n|^\s*)xmlPlot:\s*/gm, '$1');
|
61 |
//自定义插入
|
62 |
content = content.replace(/(<\/?)PrevAssistant>/gm, '$1@1>').replace(/(<\/?)PrevHuman>/gm, '$1@2>');
|
63 |
let splitContent = content.split(/\n\n(?=Assistant:|Human:)/g);
|
|
|
91 |
//Plain Prompt
|
92 |
let segcontentHuman = content.split('\n\nHuman:');
|
93 |
let segcontentlastIndex = segcontentHuman.length - 1;
|
94 |
+
if (!apiKey && segcontentlastIndex >= 2 && segcontentHuman[segcontentlastIndex].includes('<|Plain Prompt Enable|>') && !content.includes('\n\nPlainPrompt:')) {
|
95 |
content = segcontentHuman.slice(0, segcontentlastIndex).join('\n\nHuman:') + '\n\nPlainPrompt:' + segcontentHuman.slice(segcontentlastIndex).join('\n\nHuman:').replace(/\n\nHuman: *PlainPrompt:/, '\n\nPlainPrompt:');
|
96 |
}
|
|
|
97 |
//<card>群组
|
98 |
if (!card) {
|
99 |
return content.replace(/(<reply>\n|\n<\/reply>)/g, '').replace(/<customname>(.*?)<\/customname>/gm, '$1');
|
100 |
} else {
|
101 |
content = content.replace(/(<reply>\n|\n<\/reply>)\1*/g, '$1').replace(/<customname>(.*?)<\/customname>:/gm, '$1:\n');
|
102 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
103 |
//<card>消除空XML tags、两端空白符和多余的\n
|
104 |
content = content.replace(/\s*<\|curtail\|>\s*/g, '\n')
|
105 |
.replace(/\n<\/(card|hidden|META)>\s+?<\1>\n/g, '\n')
|
106 |
.replace(/\n<(\/?card|example|hidden|plot|META)>\s+?<\1>/g, '\n<$1>')
|
107 |
+
.replace(/\n(?:<!--.*?-->|Here.*?:)?\n<(card|example|hidden|plot|META)>\s+?<\/\1>/g, '')
|
108 |
.replace(/(?<=(: |\n)<(card|hidden|example|plot|META|EOT)>\n)\s*/g, '')
|
109 |
.replace(/\s*(?=\n<\/(card|hidden|example|plot|META|EOT)>(\n|$))/g, '')
|
110 |
.replace(/(?<=\n)\n(?=\n)/g, '');
|
111 |
//确保格式正确
|
112 |
if (apiKey) {
|
113 |
content = content.replace(/\n\n(Assistant|Human):(?!.*?\n\n(Assistant|Human):).*$/s, function(match, p1) {return p1 === 'Assistant' ? match : match + '\n\nAssistant: '}).replace(/\s*<\|noAssistant\|>\s*(.*?)(?:\n\nAssistant:\s*)?$/s, '\n\n$1');
|
114 |
+
content.includes('<|reverseHA|>') && (content = content.replace(/\s*<\|reverseHA\|>\s*/g, '\n\n').replace(/Assistant|Human/g, function(match) {return match === 'Human' ? 'Assistant' : 'Human'}).replace(/\n(A|H): /g, function(match, p1) {return p1 === 'A' ? '\nH: ' : '\nA: '}));
|
115 |
+
return content.replace(Config.Settings.padtxt ? /\s*<\|(?!padtxt).*?\|>\s*/g : /\s*<\|.*?\|>\s*/g, '\n\n').trim().replace(/^(Human|Assistant):/, '\n\n$&').replace(/\n\n(Human|Assistant):$/, '$& ');
|
116 |
} else {
|
117 |
+
return content.replace(Config.Settings.padtxt ? /\s*<\|(?!padtxt).*?\|>\s*/g : /\s*<\|.*?\|>\s*/g, '\n\n').trim().replace(/^Human:|\n\nAssistant:$/g, '');
|
118 |
}
|
119 |
};
|
120 |
/******************************************************* */
|
|
|
245 |
try {
|
246 |
/***************************** */
|
247 |
if ('SET YOUR COOKIE HERE' === Config.Cookie || Config.Cookie?.length < 1) {
|
248 |
+
return console.log(`[33mNo cookie available, apiKey-Only mode enabled.[0m\n`); //throw Error('Set your cookie inside config.js');
|
249 |
}
|
250 |
updateCookies(Config.Cookie.replace(/^(sessionKey=)?/, 'sessionKey=')); //updateCookies(Config.Cookie);
|
251 |
//console.log(`[2m${Main}[0m\n[33mhttp://${Config.Ip}:${Config.Port}/v1[0m\n\n${Object.keys(Config.Settings).map((setting => UnknownSettings.includes(setting) ? `??? [31m${setting}: ${Config.Settings[setting]}[0m` : `[1m${setting}:[0m ${ChangedSettings.includes(setting) ? '[33m' : '[36m'}${Config.Settings[setting]}[0m`)).sort().join('\n')}\n`);
|
|
|
429 |
const body = JSON.parse(Buffer.concat(buffer).toString()), temperature = Math.max(.1, Math.min(1, body.temperature));
|
430 |
let {messages} = body;
|
431 |
/************************* */
|
432 |
+
apiKey = req.headers.authorization.match(/sk-ant-api\d\d-[\w-]{86}-[\w-]{6}AA/g);
|
433 |
let api_max_tokens, api_model;
|
434 |
if (apiKey) {
|
|
|
435 |
api_max_tokens = body.max_tokens;
|
436 |
api_model = body.model;
|
437 |
+
if (!api_model.includes('claude')) throw Error('Please change to claude model in "External"');
|
438 |
+
} else if (req.headers.authorization.includes('sk-ant-api')) {
|
439 |
+
throw Error('apiKey Wrong');
|
440 |
} else if (Config.ProxyPassword != '' && req.headers.authorization != 'Bearer ' + Config.ProxyPassword) {
|
441 |
throw Error('ProxyPassword Wrong');
|
442 |
}
|
|
|
676 |
signal,
|
677 |
headers: {
|
678 |
'Content-Type': 'application/json',
|
679 |
+
'x-api-key': apiKey[Math.floor(Math.random() * apiKey.length)],
|
680 |
'anthropic-version': '2023-06-01'
|
681 |
},
|
682 |
body: JSON.stringify({
|
|
|
851 |
for (let key in Config) {
|
852 |
if (key === 'Settings') {
|
853 |
for (let setting in Config.Settings) {
|
854 |
+
Config.Settings[setting] = process.env[setting] ? convertToType(process.env[setting]) : Config.Settings[setting];
|
855 |
}
|
856 |
} else {
|
857 |
+
Config[key] = process.env[key] ? convertToType(process.env[key]) : Config[key];
|
858 |
}
|
859 |
}
|
860 |
Config.rProxy = Config.rProxy ? Config.rProxy.replace(/\/$/, '') : AI.end();
|
861 |
+
Config.CookieArray = [...new Set([Config.CookieArray].join('').match(/(sessionKey=)?sk-ant-sid01-[\w-]{86}-[\w-]{6}AA/g))];
|
862 |
writeSettings(Config);
|
863 |
currentIndex = Config.CookieIndex > 0 ? Config.CookieIndex - 1 : Config.Cookiecounter >= 0 ? Math.floor(Math.random() * Config.CookieArray.length) : 0;
|
864 |
/***************************** */
|
lib/clewd-stream.js
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
/*
|
2 |
-
* https://
|
3 |
-
* https://github.com/
|
4 |
*/
|
5 |
'use strict';
|
6 |
|
|
|
1 |
/*
|
2 |
+
* https://rentry.org/teralomaniac_clewd
|
3 |
+
* https://github.com/teralomaniac/clewd
|
4 |
*/
|
5 |
'use strict';
|
6 |
|
lib/clewd-superfetch.js
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
/*
|
2 |
-
* https://
|
3 |
-
* https://github.com/
|
4 |
*/"use strict";const{spawn:e}=require("node:child_process"),{relative:r,resolve:t,join:s,normalize:n,basename:o}=require("node:path"),{writeFileSync:a,unlinkSync:d,existsSync:i}=require("node:fs"),{ReadableStream:c}=require("node:stream/web"),l=e=>"win32"===process.platform?".\\"+e:e,m=e=>"win32"===process.platform||e.indexOf(" ")>-1?`"${e}"`:e,u={win32:{x64:"clewd-superfetch-win-amd64.exe"},darwin:{x64:"clewd-superfetch-mac-amd64",arm64:"clewd-superfetch-linux-arm64"},linux:{x64:"clewd-superfetch-linux-amd64",arm64:"clewd-superfetch-linux-arm64"},android:{x64:"clewd-superfetch-linux-amd64",arm64:"clewd-superfetch-linux-arm64",arm:"clewd-superfetch-android-arm"}}[process.platform]?.[process.arch],f=""+n(r("./","./bin/"+u)),p=n(t(__dirname,f,"../","../")),h=t(p,f);let b=[123,34,115,101,99,45,99,104,45,117,97,34,58,34,92,34,67,104,114,111,109,105,117,109,92,34,59,118,61,92,34,49,49,48,92,34,44,32,92,34,78,111,116,32,65,40,66,114,97,110,100,92,34,59,118,61,92,34,50,52,92,34,44,32,92,34,71,111,111,103,108,101,32,67,104,114,111,109,101,92,34,59,118,61,92,34,49,49,48,92,34,34,44,34,115,101,99,45,99,104,45,117,97,45,109,111,98,105,108,101,34,58,34,63,48,34,44,34,115,101,99,45,99,104,45,117,97,45,112,108,97,116,102,111,114,109,34,58,34,92,34,87,105,110,100,111,119,115,92,34,34,44,34,85,112,103,114,97,100,101,45,73,110,115,101,99,117,114,101,45,82,101,113,117,101,115,116,115,34,58,34,49,34,44,34,85,115,101,114,45,65,103,101,110,116,34,58,34,77,111,122,105,108,108,97,47,53,46,48,32,40,87,105,110,100,111,119,115,32,78,84,32,49,48,46,48,59,32,87,105,110,54,52,59,32,120,54,52,41,32,65,112,112,108,101,87,101,98,75,105,116,47,53,51,55,46,51,54,32,40,75,72,84,77,76,44,32,108,105,107,101,32,71,101,99,107,111,41,32,67,104,114,111,109,101,47,49,49,48,46,48,46,48,46,48,32,83,97,102,97,114,105,47,53,51,55,46,51,54,34,44,34,65,99,99,101,112,116,34,58,34,116,101,120,116,47,104,116,109,108,44,97,112,112,108,105,99,97,116,105,111,110,47,120,104,116,109,108,43,120,109,108,44,97,112,112,108,105,99,97,116,105,111,110,47,120,109,108,59,113,61,48,46,57,44,105,109,97,103,101,47,97,118,105,102,44,105,109,97,103,101,47,119,101,98,112,44,105,109,97,103,101,47,97,112,110,103,44,42,47,42,59,113,61,48,46,56,44,97,112,112,108,105,99,97,116,105,111,110,47,115,105,103,110,101,100,45,101,120,99,104,97,110,103,101,59,118,61,98,51,59,113,61,48,46,55,34,44,34,83,101,99,45,70,101,116,99,104,45,83,105,116,101,34,58,34,110,111,110,101,34,44,34,83,101,99,45,70,101,116,99,104,45,77,111,100,101,34,58,34,110,97,118,105,103,97,116,101,34,44,34,83,101,99,45,70,101,116,99,104,45,85,115,101,114,34,58,34,63,49,34,44,34,83,101,99,45,70,101,116,99,104,45,68,101,115,116,34,58,34,100,111,99,117,109,101,110,116,34,44,34,65,99,99,101,112,116,45,69,110,99,111,100,105,110,103,34,58,34,103,122,105,112,44,32,100,101,102,108,97,116,101,44,32,98,114,34,44,34,65,99,99,101,112,116,45,76,97,110,103,117,97,103,101,34,58,34,101,110,45,85,83,44,101,110,59,113,61,48,46,57,34,125],w=[91,34,45,45,99,105,112,104,101,114,115,32,84,76,83,95,65,69,83,95,49,50,56,95,71,67,77,95,83,72,65,50,53,54,44,84,76,83,95,65,69,83,95,50,53,54,95,71,67,77,95,83,72,65,51,56,52,44,84,76,83,95,67,72,65,67,72,65,50,48,95,80,79,76,89,49,51,48,53,95,83,72,65,50,53,54,44,69,67,68,72,69,45,69,67,68,83,65,45,65,69,83,49,50,56,45,71,67,77,45,83,72,65,50,53,54,44,69,67,68,72,69,45,82,83,65,45,65,69,83,49,50,56,45,71,67,77,45,83,72,65,50,53,54,44,69,67,68,72,69,45,69,67,68,83,65,45,65,69,83,50,53,54,45,71,67,77,45,83,72,65,51,56,52,44,69,67,68,72,69,45,82,83,65,45,65,69,83,50,53,54,45,71,67,77,45,83,72,65,51,56,52,44,69,67,68,72,69,45,69,67,68,83,65,45,67,72,65,67,72,65,50,48,45,80,79,76,89,49,51,48,53,44,69,67,68,72,69,45,82,83,65,45,67,72,65,67,72,65,50,48,45,80,79,76,89,49,51,48,53,44,69,67,68,72,69,45,82,83,65,45,65,69,83,49,50,56,45,83,72,65,44,69,67,68,72,69,45,82,83,65,45,65,69,83,50,53,54,45,83,72,65,44,65,69,83,49,50,56,45,71,67,77,45,83,72,65,50,53,54,44,65,69,83,50,53,54,45,71,67,77,45,83,72,65,51,56,52,44,65,69,83,49,50,56,45,83,72,65,44,65,69,83,50,53,54,45,83,72,65,34,44,34,34,44,34,45,45,104,116,116,112,50,34,44,34,45,45,104,116,116,112,50,45,110,111,45,115,101,114,118,101,114,45,112,117,115,104,34,44,34,45,45,102,97,108,115,101,45,115,116,97,114,116,34,44,34,45,45,99,111,109,112,114,101,115,115,101,100,34,44,34,45,45,116,108,115,118,49,46,50,34,44,34,45,45,110,111,45,110,112,110,34,44,34,45,45,97,108,112,115,34,44,34,45,45,116,108,115,45,112,101,114,109,117,116,101,45,101,120,116,101,110,115,105,111,110,115,34,44,34,45,45,99,101,114,116,45,99,111,109,112,114,101,115,115,105,111,110,32,98,114,111,116,108,105,34,44,34,45,45,108,111,99,97,116,105,111,110,34,93];const y=(e=false)=>{if(!u||!i(h)){e&&console.warn(`superfetch [[31merr[0m] unavailable for ${process.platform}-${process.arch}, use 3.8.5 for the time being\n`);return false}e&&console.log(`superfetch [[32mfound[0m] ${r(__dirname,h)}\n`);return true},x=(t,n)=>{n.headers||(n.headers={});"string"!=typeof n.body&&(n.body=n.body?JSON.stringify(n.body):"");if(!y())return;const o=r("./","bin/cfg"),i=r("./","bin/pyld"),c=r("./","bin/hdr"),u=r("./","bin/ca");let x={...JSON.parse(Buffer.from(b).toString()),...n.headers};const S=Object.values(x);x=Object.keys(x).map(((e,r)=>`${e}: ${S[r]}`));const _=m(l(o)),g=m(l(c)),v=m(l(i)),O=["-v","--cacert",""+m(l(u)),"--config",""+_,"--header","@"+g];if("POST"===n.method){O.push("--data");O.push("@"+v)}const j=[...JSON.parse(Buffer.from(w).toString()),"-X "+(n.method||"GET")];a(s(__dirname,o),j.join("\n"));a(s(__dirname,c),x.join("\n"));n.body&&a(s(__dirname,i),n.body);return new Promise((r=>{const a=e("android"===process.platform?h:f,[...O,""+t],{cwd:p,windowsHide:true,killSignal:"SIGKILL",windowsVerbatimArguments:true,detached:"win32"!==process.platform});a.superfetch=true;a.rape=function(){this.stdout?.end();this.stderr?.end()}.bind(a);a.once("spawn",(()=>{a.stream=n.stream||false;if(a.stream){Object.defineProperty(a,"body",{get:()=>a.stdout});return r(a)}a.body="";a.stdout.on("data",(e=>a.body+=e.toString()));a.json=async()=>JSON.parse(a.body);a.text=async()=>a.body;a.stdout.on("end",(()=>{a.stdout.removeAllListeners();return r(a)}))}));a.once("error",(e=>{console.warn("superfetch [[31merr[0m]",e)}));a.once("close",(()=>{try{d(s(__dirname,o));d(s(__dirname,c));n.body&&d(s(__dirname,i))}catch(e){}a.stdout.removeAllListeners();a.stderr.removeAllListeners();this.body?.removeAllListeners()}));a.stderr.on("data",(e=>{const r=/HTTP\/2 (\d{3})+/g,t=(e=e.toString().trim()).match(r);if(!a.status&&t){const t=r.exec(e);a.status=+t[1]}const s=/(?:< )(.+?)(?:: )(.+)/g,n=e.match(s);if(n){const e={};n.forEach((r=>{const t=r.split(s);e[t?.[1]]=t?.[2]}));a.headers=e}}))}))};module.exports.ClewdSuperfetch=x;module.exports.SuperfetchAvailable=y;module.exports.Binary=f;
|
|
|
1 |
/*
|
2 |
+
* https://rentry.org/teralomaniac_clewd
|
3 |
+
* https://github.com/teralomaniac/clewd
|
4 |
*/"use strict";const{spawn:e}=require("node:child_process"),{relative:r,resolve:t,join:s,normalize:n,basename:o}=require("node:path"),{writeFileSync:a,unlinkSync:d,existsSync:i}=require("node:fs"),{ReadableStream:c}=require("node:stream/web"),l=e=>"win32"===process.platform?".\\"+e:e,m=e=>"win32"===process.platform||e.indexOf(" ")>-1?`"${e}"`:e,u={win32:{x64:"clewd-superfetch-win-amd64.exe"},darwin:{x64:"clewd-superfetch-mac-amd64",arm64:"clewd-superfetch-linux-arm64"},linux:{x64:"clewd-superfetch-linux-amd64",arm64:"clewd-superfetch-linux-arm64"},android:{x64:"clewd-superfetch-linux-amd64",arm64:"clewd-superfetch-linux-arm64",arm:"clewd-superfetch-android-arm"}}[process.platform]?.[process.arch],f=""+n(r("./","./bin/"+u)),p=n(t(__dirname,f,"../","../")),h=t(p,f);let b=[123,34,115,101,99,45,99,104,45,117,97,34,58,34,92,34,67,104,114,111,109,105,117,109,92,34,59,118,61,92,34,49,49,48,92,34,44,32,92,34,78,111,116,32,65,40,66,114,97,110,100,92,34,59,118,61,92,34,50,52,92,34,44,32,92,34,71,111,111,103,108,101,32,67,104,114,111,109,101,92,34,59,118,61,92,34,49,49,48,92,34,34,44,34,115,101,99,45,99,104,45,117,97,45,109,111,98,105,108,101,34,58,34,63,48,34,44,34,115,101,99,45,99,104,45,117,97,45,112,108,97,116,102,111,114,109,34,58,34,92,34,87,105,110,100,111,119,115,92,34,34,44,34,85,112,103,114,97,100,101,45,73,110,115,101,99,117,114,101,45,82,101,113,117,101,115,116,115,34,58,34,49,34,44,34,85,115,101,114,45,65,103,101,110,116,34,58,34,77,111,122,105,108,108,97,47,53,46,48,32,40,87,105,110,100,111,119,115,32,78,84,32,49,48,46,48,59,32,87,105,110,54,52,59,32,120,54,52,41,32,65,112,112,108,101,87,101,98,75,105,116,47,53,51,55,46,51,54,32,40,75,72,84,77,76,44,32,108,105,107,101,32,71,101,99,107,111,41,32,67,104,114,111,109,101,47,49,49,48,46,48,46,48,46,48,32,83,97,102,97,114,105,47,53,51,55,46,51,54,34,44,34,65,99,99,101,112,116,34,58,34,116,101,120,116,47,104,116,109,108,44,97,112,112,108,105,99,97,116,105,111,110,47,120,104,116,109,108,43,120,109,108,44,97,112,112,108,105,99,97,116,105,111,110,47,120,109,108,59,113,61,48,46,57,44,105,109,97,103,101,47,97,118,105,102,44,105,109,97,103,101,47,119,101,98,112,44,105,109,97,103,101,47,97,112,110,103,44,42,47,42,59,113,61,48,46,56,44,97,112,112,108,105,99,97,116,105,111,110,47,115,105,103,110,101,100,45,101,120,99,104,97,110,103,101,59,118,61,98,51,59,113,61,48,46,55,34,44,34,83,101,99,45,70,101,116,99,104,45,83,105,116,101,34,58,34,110,111,110,101,34,44,34,83,101,99,45,70,101,116,99,104,45,77,111,100,101,34,58,34,110,97,118,105,103,97,116,101,34,44,34,83,101,99,45,70,101,116,99,104,45,85,115,101,114,34,58,34,63,49,34,44,34,83,101,99,45,70,101,116,99,104,45,68,101,115,116,34,58,34,100,111,99,117,109,101,110,116,34,44,34,65,99,99,101,112,116,45,69,110,99,111,100,105,110,103,34,58,34,103,122,105,112,44,32,100,101,102,108,97,116,101,44,32,98,114,34,44,34,65,99,99,101,112,116,45,76,97,110,103,117,97,103,101,34,58,34,101,110,45,85,83,44,101,110,59,113,61,48,46,57,34,125],w=[91,34,45,45,99,105,112,104,101,114,115,32,84,76,83,95,65,69,83,95,49,50,56,95,71,67,77,95,83,72,65,50,53,54,44,84,76,83,95,65,69,83,95,50,53,54,95,71,67,77,95,83,72,65,51,56,52,44,84,76,83,95,67,72,65,67,72,65,50,48,95,80,79,76,89,49,51,48,53,95,83,72,65,50,53,54,44,69,67,68,72,69,45,69,67,68,83,65,45,65,69,83,49,50,56,45,71,67,77,45,83,72,65,50,53,54,44,69,67,68,72,69,45,82,83,65,45,65,69,83,49,50,56,45,71,67,77,45,83,72,65,50,53,54,44,69,67,68,72,69,45,69,67,68,83,65,45,65,69,83,50,53,54,45,71,67,77,45,83,72,65,51,56,52,44,69,67,68,72,69,45,82,83,65,45,65,69,83,50,53,54,45,71,67,77,45,83,72,65,51,56,52,44,69,67,68,72,69,45,69,67,68,83,65,45,67,72,65,67,72,65,50,48,45,80,79,76,89,49,51,48,53,44,69,67,68,72,69,45,82,83,65,45,67,72,65,67,72,65,50,48,45,80,79,76,89,49,51,48,53,44,69,67,68,72,69,45,82,83,65,45,65,69,83,49,50,56,45,83,72,65,44,69,67,68,72,69,45,82,83,65,45,65,69,83,50,53,54,45,83,72,65,44,65,69,83,49,50,56,45,71,67,77,45,83,72,65,50,53,54,44,65,69,83,50,53,54,45,71,67,77,45,83,72,65,51,56,52,44,65,69,83,49,50,56,45,83,72,65,44,65,69,83,50,53,54,45,83,72,65,34,44,34,34,44,34,45,45,104,116,116,112,50,34,44,34,45,45,104,116,116,112,50,45,110,111,45,115,101,114,118,101,114,45,112,117,115,104,34,44,34,45,45,102,97,108,115,101,45,115,116,97,114,116,34,44,34,45,45,99,111,109,112,114,101,115,115,101,100,34,44,34,45,45,116,108,115,118,49,46,50,34,44,34,45,45,110,111,45,110,112,110,34,44,34,45,45,97,108,112,115,34,44,34,45,45,116,108,115,45,112,101,114,109,117,116,101,45,101,120,116,101,110,115,105,111,110,115,34,44,34,45,45,99,101,114,116,45,99,111,109,112,114,101,115,115,105,111,110,32,98,114,111,116,108,105,34,44,34,45,45,108,111,99,97,116,105,111,110,34,93];const y=(e=false)=>{if(!u||!i(h)){e&&console.warn(`superfetch [[31merr[0m] unavailable for ${process.platform}-${process.arch}, use 3.8.5 for the time being\n`);return false}e&&console.log(`superfetch [[32mfound[0m] ${r(__dirname,h)}\n`);return true},x=(t,n)=>{n.headers||(n.headers={});"string"!=typeof n.body&&(n.body=n.body?JSON.stringify(n.body):"");if(!y())return;const o=r("./","bin/cfg"),i=r("./","bin/pyld"),c=r("./","bin/hdr"),u=r("./","bin/ca");let x={...JSON.parse(Buffer.from(b).toString()),...n.headers};const S=Object.values(x);x=Object.keys(x).map(((e,r)=>`${e}: ${S[r]}`));const _=m(l(o)),g=m(l(c)),v=m(l(i)),O=["-v","--cacert",""+m(l(u)),"--config",""+_,"--header","@"+g];if("POST"===n.method){O.push("--data");O.push("@"+v)}const j=[...JSON.parse(Buffer.from(w).toString()),"-X "+(n.method||"GET")];a(s(__dirname,o),j.join("\n"));a(s(__dirname,c),x.join("\n"));n.body&&a(s(__dirname,i),n.body);return new Promise((r=>{const a=e("android"===process.platform?h:f,[...O,""+t],{cwd:p,windowsHide:true,killSignal:"SIGKILL",windowsVerbatimArguments:true,detached:"win32"!==process.platform});a.superfetch=true;a.rape=function(){this.stdout?.end();this.stderr?.end()}.bind(a);a.once("spawn",(()=>{a.stream=n.stream||false;if(a.stream){Object.defineProperty(a,"body",{get:()=>a.stdout});return r(a)}a.body="";a.stdout.on("data",(e=>a.body+=e.toString()));a.json=async()=>JSON.parse(a.body);a.text=async()=>a.body;a.stdout.on("end",(()=>{a.stdout.removeAllListeners();return r(a)}))}));a.once("error",(e=>{console.warn("superfetch [[31merr[0m]",e)}));a.once("close",(()=>{try{d(s(__dirname,o));d(s(__dirname,c));n.body&&d(s(__dirname,i))}catch(e){}a.stdout.removeAllListeners();a.stderr.removeAllListeners();this.body?.removeAllListeners()}));a.stderr.on("data",(e=>{const r=/HTTP\/2 (\d{3})+/g,t=(e=e.toString().trim()).match(r);if(!a.status&&t){const t=r.exec(e);a.status=+t[1]}const s=/(?:< )(.+?)(?:: )(.+)/g,n=e.match(s);if(n){const e={};n.forEach((r=>{const t=r.split(s);e[t?.[1]]=t?.[2]}));a.headers=e}}))}))};module.exports.ClewdSuperfetch=x;module.exports.SuperfetchAvailable=y;module.exports.Binary=f;
|
lib/clewd-utils.js
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
/*
|
2 |
-
* https://
|
3 |
-
* https://github.com/
|
4 |
*/
|
5 |
'use strict';
|
6 |
|
7 |
const {randomInt, randomBytes} = require('node:crypto'), {version: Version} = require('../package.json'), Encoder = (new TextDecoder,
|
8 |
-
new TextEncoder), Main = 'clewd修改版 v' + Version + '(
|
9 |
user: 'Human',
|
10 |
assistant: 'Assistant',
|
11 |
system: '',
|
|
|
1 |
/*
|
2 |
+
* https://rentry.org/teralomaniac_clewd
|
3 |
+
* https://github.com/teralomaniac/clewd
|
4 |
*/
|
5 |
'use strict';
|
6 |
|
7 |
const {randomInt, randomBytes} = require('node:crypto'), {version: Version} = require('../package.json'), Encoder = (new TextDecoder,
|
8 |
+
new TextEncoder), Main = 'clewd修改版 v' + Version + '(12) by tera', Replacements = {
|
9 |
user: 'Human',
|
10 |
assistant: 'Assistant',
|
11 |
system: '',
|